Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Hadrontherapy advanced example for Geant4 << 26 // $Id: HadrontherapyDetectorMessenger.cc; 27 // See more at: https://twiki.cern.ch/twiki/bi << 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy >> 28 28 29 29 #include "HadrontherapyDetectorMessenger.hh" 30 #include "HadrontherapyDetectorMessenger.hh" 30 #include "HadrontherapyDetectorConstruction.hh 31 #include "HadrontherapyDetectorConstruction.hh" 31 #include "G4UIdirectory.hh" 32 #include "G4UIdirectory.hh" 32 #include "G4UIcmdWith3VectorAndUnit.hh" << 33 #include "G4UIcmdWithADoubleAndUnit.hh" 33 #include "G4UIcmdWithoutParameter.hh" << 34 #include "G4UIcmdWithAString.hh" 34 #include "G4UIcmdWithAString.hh" 35 #include "G4SystemOfUnits.hh" << 35 #include "G4UIcmdWith3VectorAndUnit.hh" 36 #include "G4UIcmdWithABool.hh" << 37 36 38 ////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////// 39 HadrontherapyDetectorMessenger::HadrontherapyD 38 HadrontherapyDetectorMessenger::HadrontherapyDetectorMessenger(HadrontherapyDetectorConstruction* detector) 40 :hadrontherapyDetector(detector) << 39 :hadrontherapyDetector(detector) 41 { 40 { 42 // Change Phantom size 41 // Change Phantom size 43 changeThePhantomDir = new G4UIdirectory("/ 42 changeThePhantomDir = new G4UIdirectory("/changePhantom/"); 44 changeThePhantomDir -> SetGuidance("Comman 43 changeThePhantomDir -> SetGuidance("Command to change the Phantom Size/position"); 45 changeThePhantomSizeCmd = new G4UIcmdWith3 44 changeThePhantomSizeCmd = new G4UIcmdWith3VectorAndUnit("/changePhantom/size", this); 46 changeThePhantomSizeCmd -> SetGuidance("In 45 changeThePhantomSizeCmd -> SetGuidance("Insert sizes X Y and Z" 47 "\n << 46 "\n 0 or negative values mean <<Don't change it!>>"); 48 changeThePhantomSizeCmd -> SetParameterNam << 47 changeThePhantomSizeCmd -> SetParameterName("PhantomSizeAlongX", 49 << 48 "PhantomSizeAlongY", 50 << 49 "PhantomSizeAlongZ", false); 51 changeThePhantomSizeCmd -> SetDefaultUnit( 50 changeThePhantomSizeCmd -> SetDefaultUnit("mm"); 52 changeThePhantomSizeCmd -> SetUnitCandidat << 51 changeThePhantomSizeCmd -> SetUnitCandidates("um mm cm"); 53 changeThePhantomSizeCmd -> AvailableForSta 52 changeThePhantomSizeCmd -> AvailableForStates(G4State_Idle); 54 << 53 55 << 54 56 // Change Phantom material << 57 changeThePhantomMaterialCmd = new G4UIcmdW << 58 changeThePhantomMaterialCmd -> SetGuidance << 59 changeThePhantomMaterialCmd -> SetParamete << 60 changeThePhantomMaterialCmd -> SetDefaultV << 61 changeThePhantomMaterialCmd -> AvailableFo << 62 << 63 // Change Phantom position 55 // Change Phantom position 64 changeThePhantomPositionCmd = new G4UIcmdW 56 changeThePhantomPositionCmd = new G4UIcmdWith3VectorAndUnit("/changePhantom/position", this); 65 changeThePhantomPositionCmd -> SetGuidance 57 changeThePhantomPositionCmd -> SetGuidance("Insert X Y and Z dimensions for the position of the center of the Phantom" 66 << 58 " respect to that of the \"World\""); 67 changeThePhantomPositionCmd -> SetParamete << 59 changeThePhantomPositionCmd -> SetParameterName("PositionAlongX", 68 << 60 "PositionAlongY", 69 << 61 "PositionAlongZ", false); 70 changeThePhantomPositionCmd -> SetDefaultU 62 changeThePhantomPositionCmd -> SetDefaultUnit("mm"); 71 changeThePhantomPositionCmd -> SetUnitCand << 63 changeThePhantomPositionCmd -> SetUnitCandidates("mm cm m"); 72 changeThePhantomPositionCmd -> AvailableFo 64 changeThePhantomPositionCmd -> AvailableForStates(G4State_Idle); 73 << 65 74 << 66 75 updateCmd = new G4UIcmdWithoutParameter("/ << 76 updateCmd->SetGuidance("Update Phantom/Det << 77 updateCmd->SetGuidance("This command MUST << 78 updateCmd->SetGuidance("if you changed geo << 79 updateCmd->AvailableForStates(G4State_Idle << 80 << 81 // Change detector size 67 // Change detector size 82 changeTheDetectorDir = new G4UIdirectory(" 68 changeTheDetectorDir = new G4UIdirectory("/changeDetector/"); 83 changeTheDetectorDir -> SetGuidance("Comma 69 changeTheDetectorDir -> SetGuidance("Command to change the Detector's Size/position/Voxels"); 84 70 85 changeTheDetectorSizeCmd = new G4UIcmdWith 71 changeTheDetectorSizeCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/size",this); 86 changeTheDetectorSizeCmd -> SetGuidance("I 72 changeTheDetectorSizeCmd -> SetGuidance("Insert sizes for X Y and Z dimensions of the Detector" 87 "\ << 73 "\n 0 or negative values mean <<Don't change it>>"); 88 changeTheDetectorSizeCmd -> SetParameterNa 74 changeTheDetectorSizeCmd -> SetParameterName("DetectorSizeAlongX", "DetectorSizeAlongY", "DetectorSizeAlongZ", false); 89 changeTheDetectorSizeCmd -> SetDefaultUnit 75 changeTheDetectorSizeCmd -> SetDefaultUnit("mm"); 90 changeTheDetectorSizeCmd -> SetUnitCandida << 76 changeTheDetectorSizeCmd -> SetUnitCandidates("um mm cm"); 91 changeTheDetectorSizeCmd -> AvailableForSt 77 changeTheDetectorSizeCmd -> AvailableForStates(G4State_Idle); 92 << 78 93 // Change the detector to phantom displac 79 // Change the detector to phantom displacement 94 changeTheDetectorToPhantomPositionCmd = ne 80 changeTheDetectorToPhantomPositionCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/displacement",this); 95 changeTheDetectorToPhantomPositionCmd -> S 81 changeTheDetectorToPhantomPositionCmd -> SetGuidance("Insert X Y and Z displacements between Detector and Phantom" 96 << 82 "\nNegative values mean <<Don't change it!>>"); 97 changeTheDetectorToPhantomPositionCmd -> S 83 changeTheDetectorToPhantomPositionCmd -> SetParameterName("DisplacementAlongX", 98 << 84 "DisplacementAlongY", 99 << 85 "DisplacementAlongZ", false); 100 changeTheDetectorToPhantomPositionCmd -> S 86 changeTheDetectorToPhantomPositionCmd -> SetDefaultUnit("mm"); 101 changeTheDetectorToPhantomPositionCmd -> S << 87 changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates("um mm cm"); 102 changeTheDetectorToPhantomPositionCmd -> A 88 changeTheDetectorToPhantomPositionCmd -> AvailableForStates(G4State_Idle); 103 89 104 // Change voxels by its size 90 // Change voxels by its size 105 changeTheDetectorVoxelCmd = new G4UIcmdWit 91 changeTheDetectorVoxelCmd = new G4UIcmdWith3VectorAndUnit("/changeDetector/voxelSize",this); 106 changeTheDetectorVoxelCmd -> SetGuidance(" 92 changeTheDetectorVoxelCmd -> SetGuidance("Insert Voxel sizes for X Y and Z dimensions" 107 " << 93 "\n 0 or negative values mean <<Don't change it!>>"); 108 changeTheDetectorVoxelCmd -> SetParameterN 94 changeTheDetectorVoxelCmd -> SetParameterName("VoxelSizeAlongX", "VoxelSizeAlongY", "VoxelSizeAlongZ", false); 109 changeTheDetectorVoxelCmd -> SetDefaultUni 95 changeTheDetectorVoxelCmd -> SetDefaultUnit("mm"); 110 changeTheDetectorVoxelCmd -> SetUnitCandid << 96 changeTheDetectorVoxelCmd -> SetUnitCandidates("um mm cm"); 111 changeTheDetectorVoxelCmd -> AvailableForS 97 changeTheDetectorVoxelCmd -> AvailableForStates(G4State_Idle); 112 << 98 } 113 << 114 changeTheSource = new G4UIdirectory("/chan << 115 changeTheSource -> SetGuidance("Command to << 116 << 117 << 118 << 119 << 120 ////////////////////////////////////////// << 121 << 122 VirtualLayer = new G4UIcmdWithABool("/chan << 123 VirtualLayer -> SetParameterName("VirtualL << 124 VirtualLayer -> SetDefaultValue("false"); << 125 VirtualLayer -> SetGuidance("Set if you wa << 126 "\n[usage]: /c << 127 VirtualLayer -> AvailableForStates(G4State << 128 << 129 << 130 VirtualLayerPosition = new G4UIcmdWith3Vec << 131 VirtualLayerPosition -> SetGuidance("Inser << 132 " resp << 133 VirtualLayerPosition -> SetParameterName(" << 134 " << 135 " << 136 << 137 VirtualLayerPosition -> SetDefaultUnit("cm << 138 VirtualLayerPosition -> SetUnitCandidates( << 139 VirtualLayerPosition -> AvailableForStates << 140 << 141 << 142 << 143 } << 144 99 145 ////////////////////////////////////////////// 100 ///////////////////////////////////////////////////////////////////////////// 146 HadrontherapyDetectorMessenger::~Hadrontherapy 101 HadrontherapyDetectorMessenger::~HadrontherapyDetectorMessenger() 147 { 102 { 148 delete changeThePhantomDir; << 103 delete changeThePhantomDir; 149 delete changeThePhantomSizeCmd; << 104 delete changeThePhantomSizeCmd; 150 delete changeThePhantomPositionCmd; << 105 delete changeThePhantomPositionCmd; 151 delete changeThePhantomMaterialCmd; << 106 delete changeTheDetectorDir; 152 delete updateCmd; << 107 delete changeTheDetectorSizeCmd; 153 delete changeTheDetectorDir; << 108 delete changeTheDetectorToPhantomPositionCmd; 154 delete changeTheDetectorSizeCmd; << 109 delete changeTheDetectorVoxelCmd; 155 delete changeTheDetectorToPhantomPositionC << 156 delete changeTheDetectorVoxelCmd; << 157 delete VirtualLayer; << 158 delete VirtualLayerPosition; << 159 } 110 } 160 111 161 ////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////// 162 void HadrontherapyDetectorMessenger::SetNewVal 113 void HadrontherapyDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 163 { 114 { 164 << 115 165 if( command == changeThePhantomSizeCmd) << 116 if( command == changeThePhantomSizeCmd) 166 { << 167 G4ThreeVector size = changeThePhantomS << 168 hadrontherapyDetector -> SetPhantomSiz << 169 } << 170 else if (command == changeThePhantomPositi << 171 { << 172 << 173 G4ThreeVector size = changeThePhantomP << 174 hadrontherapyDetector -> SetPhantomPos << 175 } << 176 else if (command == changeThePhantomMateri << 177 { 117 { 178 hadrontherapyDetector -> SetPhantomMat << 118 G4ThreeVector size = changeThePhantomSizeCmd -> GetNew3VectorValue(newValue); >> 119 hadrontherapyDetector -> SetPhantomSize(size.getX(),size.getY(),size.getZ()); 179 } 120 } 180 else if (command == changeTheDetectorSizeC << 121 else if (command == changeThePhantomPositionCmd ) 181 { << 122 { 182 G4ThreeVector size = changeTheDetector << 123 G4ThreeVector size = changeThePhantomPositionCmd -> GetNew3VectorValue(newValue); >> 124 hadrontherapyDetector -> SetPhantomPosition(size); >> 125 } >> 126 else if (command == changeTheDetectorSizeCmd) >> 127 { >> 128 G4ThreeVector size = changeTheDetectorSizeCmd -> GetNew3VectorValue(newValue); 183 hadrontherapyDetector -> SetDetectorSi 129 hadrontherapyDetector -> SetDetectorSize(size.getX(),size.getY(),size.getZ()); 184 } << 130 } 185 else if (command == changeTheDetectorToPha << 131 else if (command == changeTheDetectorToPhantomPositionCmd) 186 { << 132 { 187 G4ThreeVector size = changeTheDetector << 133 G4ThreeVector size = changeTheDetectorToPhantomPositionCmd-> GetNew3VectorValue(newValue); 188 hadrontherapyDetector -> SetDetectorTo 134 hadrontherapyDetector -> SetDetectorToPhantomPosition(size); 189 << 135 } 190 } << 136 else if (command == changeTheDetectorVoxelCmd) 191 else if (command == changeTheDetectorVoxel << 137 { 192 { << 138 G4ThreeVector size = changeTheDetectorVoxelCmd -> GetNew3VectorValue(newValue); 193 G4ThreeVector size = changeTheDetector << 139 hadrontherapyDetector -> SetNumberOfVoxelBySize(size.getX(),size.getY(),size.getZ()); 194 hadrontherapyDetector -> SetVoxelSize( << 140 } 195 } << 196 else if (command == updateCmd) << 197 { << 198 hadrontherapyDetector -> UpdateGeometr << 199 } << 200 << 201 else if(command == VirtualLayer) << 202 { << 203 hadrontherapyDetector->VirtualLayer(Vi << 204 } << 205 else if(command == VirtualLayerPosition) << 206 { << 207 G4ThreeVector size = VirtualLayerPosit << 208 << 209 hadrontherapyDetector -> SetVirtualLay << 210 } << 211 << 212 } 141 } 213 142