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 /// \file electromagnetic/TestEm7/src/Detector 26 /// \file electromagnetic/TestEm7/src/DetectorMessenger.cc 27 /// \brief Implementation of the DetectorMesse 27 /// \brief Implementation of the DetectorMessenger class 28 // 28 // 29 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 32 33 #include "DetectorMessenger.hh" 33 #include "DetectorMessenger.hh" 34 34 35 #include "DetectorConstruction.hh" 35 #include "DetectorConstruction.hh" 36 << 36 #include "G4UIdirectory.hh" 37 #include "G4UIcmdWithADoubleAndUnit.hh" << 37 #include "G4UIcommand.hh" >> 38 #include "G4UIparameter.hh" 38 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithAnInteger.hh" 40 #include "G4UIcmdWithAnInteger.hh" >> 41 #include "G4UIcmdWithADoubleAndUnit.hh" 40 #include "G4UIcmdWithoutParameter.hh" 42 #include "G4UIcmdWithoutParameter.hh" 41 #include "G4UIcommand.hh" << 42 #include "G4UIdirectory.hh" << 43 #include "G4UIparameter.hh" << 44 43 45 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 45 47 DetectorMessenger::DetectorMessenger(DetectorC << 46 DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) 48 : G4UImessenger(), << 47 :G4UImessenger(),fDetector(Det), 49 fDetector(Det), << 48 fTestemDir(nullptr), 50 fTestemDir(nullptr), << 49 fDetDir(nullptr), 51 fDetDir(nullptr), << 50 fMaterCmd(nullptr), 52 fMaterCmd(nullptr), << 51 fWMaterCmd(nullptr), 53 fWMaterCmd(nullptr), << 52 fSizeXCmd(nullptr), 54 fSizeXCmd(nullptr), << 53 fSizeYZCmd(nullptr), 55 fSizeYZCmd(nullptr), << 54 fMagFieldCmd(nullptr), 56 fMagFieldCmd(nullptr), << 55 fTalNbCmd(nullptr), 57 fTalNbCmd(nullptr), << 56 fTalDefCmd(nullptr), 58 fTalDefCmd(nullptr), << 57 fTalPosiCmd(nullptr) 59 fTalPosiCmd(nullptr) << 58 { 60 { << 61 fTestemDir = new G4UIdirectory("/testem/"); 59 fTestemDir = new G4UIdirectory("/testem/"); 62 fTestemDir->SetGuidance(" detector control." 60 fTestemDir->SetGuidance(" detector control."); 63 << 61 64 fDetDir = new G4UIdirectory("/testem/det/"); 62 fDetDir = new G4UIdirectory("/testem/det/"); 65 fDetDir->SetGuidance("detector construction 63 fDetDir->SetGuidance("detector construction commands"); 66 << 64 67 fMaterCmd = new G4UIcmdWithAString("/testem/ << 65 fMaterCmd = new G4UIcmdWithAString("/testem/det/setMat",this); 68 fMaterCmd->SetGuidance("Select material of t 66 fMaterCmd->SetGuidance("Select material of the box."); 69 fMaterCmd->SetParameterName("choice", false) << 67 fMaterCmd->SetParameterName("choice",false); 70 fMaterCmd->AvailableForStates(G4State_PreIni << 68 fMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 71 << 69 72 fWMaterCmd = new G4UIcmdWithAString("/testem << 70 fWMaterCmd = new G4UIcmdWithAString("/testem/det/setWorldMat",this); 73 fWMaterCmd->SetGuidance("Select material of 71 fWMaterCmd->SetGuidance("Select material of the world."); 74 fWMaterCmd->SetParameterName("choice", false << 72 fWMaterCmd->SetParameterName("choice",false); 75 fWMaterCmd->AvailableForStates(G4State_PreIn << 73 fWMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 76 << 74 77 fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/ << 75 fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeX",this); 78 fSizeXCmd->SetGuidance("Set sizeX of the abs 76 fSizeXCmd->SetGuidance("Set sizeX of the absorber"); 79 fSizeXCmd->SetParameterName("SizeX", false); << 77 fSizeXCmd->SetParameterName("SizeX",false); 80 fSizeXCmd->SetRange("SizeX>0."); 78 fSizeXCmd->SetRange("SizeX>0."); 81 fSizeXCmd->SetUnitCategory("Length"); 79 fSizeXCmd->SetUnitCategory("Length"); 82 fSizeXCmd->AvailableForStates(G4State_PreIni 80 fSizeXCmd->AvailableForStates(G4State_PreInit); 83 << 81 84 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit(" << 82 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this); 85 fSizeYZCmd->SetGuidance("Set sizeYZ of the a 83 fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber"); 86 fSizeYZCmd->SetParameterName("SizeYZ", false << 84 fSizeYZCmd->SetParameterName("SizeYZ",false); 87 fSizeYZCmd->SetRange("SizeYZ>0."); 85 fSizeYZCmd->SetRange("SizeYZ>0."); 88 fSizeYZCmd->SetUnitCategory("Length"); 86 fSizeYZCmd->SetUnitCategory("Length"); 89 fSizeYZCmd->AvailableForStates(G4State_PreIn 87 fSizeYZCmd->AvailableForStates(G4State_PreInit); 90 << 88 91 fMagFieldCmd = new G4UIcmdWithADoubleAndUnit << 89 fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField",this); 92 fMagFieldCmd->SetGuidance("Define magnetic f 90 fMagFieldCmd->SetGuidance("Define magnetic field."); 93 fMagFieldCmd->SetGuidance("Magnetic field wi 91 fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction."); 94 fMagFieldCmd->SetParameterName("Bz", false); << 92 fMagFieldCmd->SetParameterName("Bz",false); 95 fMagFieldCmd->SetUnitCategory("Magnetic flux 93 fMagFieldCmd->SetUnitCategory("Magnetic flux density"); 96 fMagFieldCmd->AvailableForStates(G4State_Pre << 94 fMagFieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 97 << 95 98 fTalNbCmd = new G4UIcmdWithAnInteger("/teste << 96 fTalNbCmd = new G4UIcmdWithAnInteger("/testem/det/tallyNumber",this); 99 fTalNbCmd->SetGuidance("Set number of fTalli 97 fTalNbCmd->SetGuidance("Set number of fTallies."); 100 fTalNbCmd->SetParameterName("tallyNb", false << 98 fTalNbCmd->SetParameterName("tallyNb",false); 101 fTalNbCmd->SetRange("tallyNb>=0"); 99 fTalNbCmd->SetRange("tallyNb>=0"); 102 fTalNbCmd->AvailableForStates(G4State_PreIni << 100 fTalNbCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 103 101 104 fTalDefCmd = new G4UIcommand("/testem/det/ta << 102 fTalDefCmd = new G4UIcommand("/testem/det/tallyDefinition",this); 105 fTalDefCmd->SetGuidance("Set tally nb, box d 103 fTalDefCmd->SetGuidance("Set tally nb, box dimensions."); 106 fTalDefCmd->SetGuidance(" tally number : fr 104 fTalDefCmd->SetGuidance(" tally number : from 0 to tallyNumber"); 107 fTalDefCmd->SetGuidance(" material name"); 105 fTalDefCmd->SetGuidance(" material name"); 108 fTalDefCmd->SetGuidance(" dimensions (3-vec 106 fTalDefCmd->SetGuidance(" dimensions (3-vector with unit)"); 109 // 107 // 110 G4UIparameter* fTalNbPrm = new G4UIparameter << 108 G4UIparameter* fTalNbPrm = new G4UIparameter("tallyNb",'i',false); 111 fTalNbPrm->SetGuidance("tally number : from 109 fTalNbPrm->SetGuidance("tally number : from 0 to tallyNumber"); 112 fTalNbPrm->SetParameterRange("tallyNb>=0"); 110 fTalNbPrm->SetParameterRange("tallyNb>=0"); 113 fTalDefCmd->SetParameter(fTalNbPrm); 111 fTalDefCmd->SetParameter(fTalNbPrm); 114 // 112 // 115 G4UIparameter* SizeXPrm = new G4UIparameter( << 113 G4UIparameter* SizeXPrm = new G4UIparameter("sizeX",'d',false); 116 SizeXPrm->SetGuidance("sizeX"); 114 SizeXPrm->SetGuidance("sizeX"); 117 SizeXPrm->SetParameterRange("sizeX>0."); 115 SizeXPrm->SetParameterRange("sizeX>0."); 118 fTalDefCmd->SetParameter(SizeXPrm); 116 fTalDefCmd->SetParameter(SizeXPrm); 119 // << 117 // 120 G4UIparameter* SizeYPrm = new G4UIparameter( << 118 G4UIparameter* SizeYPrm = new G4UIparameter("sizeY",'d',false); 121 SizeYPrm->SetGuidance("sizeY"); 119 SizeYPrm->SetGuidance("sizeY"); 122 SizeYPrm->SetParameterRange("sizeY>0."); 120 SizeYPrm->SetParameterRange("sizeY>0."); 123 fTalDefCmd->SetParameter(SizeYPrm); 121 fTalDefCmd->SetParameter(SizeYPrm); 124 // << 122 // 125 G4UIparameter* SizeZPrm = new G4UIparameter( << 123 G4UIparameter* SizeZPrm = new G4UIparameter("sizeZ",'d',false); 126 SizeZPrm->SetGuidance("sizeZ"); 124 SizeZPrm->SetGuidance("sizeZ"); 127 SizeZPrm->SetParameterRange("sizeZ>0."); 125 SizeZPrm->SetParameterRange("sizeZ>0."); 128 fTalDefCmd->SetParameter(SizeZPrm); << 126 fTalDefCmd->SetParameter(SizeZPrm); 129 // 127 // 130 G4UIparameter* unitPrm = new G4UIparameter(" << 128 G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false); 131 unitPrm->SetGuidance("unit of dimensions"); 129 unitPrm->SetGuidance("unit of dimensions"); 132 G4String unitList = G4UIcommand::UnitsList(G 130 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm")); 133 unitPrm->SetParameterCandidates(unitList); 131 unitPrm->SetParameterCandidates(unitList); 134 fTalDefCmd->SetParameter(unitPrm); 132 fTalDefCmd->SetParameter(unitPrm); 135 // 133 // 136 fTalDefCmd->AvailableForStates(G4State_PreIn 134 fTalDefCmd->AvailableForStates(G4State_PreInit); 137 135 138 fTalPosiCmd = new G4UIcommand("/testem/det/t << 136 fTalPosiCmd = new G4UIcommand("/testem/det/tallyPosition",this); 139 fTalPosiCmd->SetGuidance("Set tally nb, posi 137 fTalPosiCmd->SetGuidance("Set tally nb, position"); 140 fTalPosiCmd->SetGuidance(" tally number : f 138 fTalPosiCmd->SetGuidance(" tally number : from 0 to tallyNumber"); 141 fTalPosiCmd->SetGuidance(" position (3-vect 139 fTalPosiCmd->SetGuidance(" position (3-vector with unit)"); 142 // 140 // 143 G4UIparameter* fTalNumPrm = new G4UIparamete << 141 G4UIparameter* fTalNumPrm = new G4UIparameter("tallyNum",'i',false); 144 fTalNumPrm->SetGuidance("tally number : from 142 fTalNumPrm->SetGuidance("tally number : from 0 to tallyNumber"); 145 fTalNumPrm->SetParameterRange("tallyNum>=0") 143 fTalNumPrm->SetParameterRange("tallyNum>=0"); 146 fTalPosiCmd->SetParameter(fTalNumPrm); 144 fTalPosiCmd->SetParameter(fTalNumPrm); 147 // << 145 // 148 G4UIparameter* PosiXPrm = new G4UIparameter( << 146 G4UIparameter* PosiXPrm = new G4UIparameter("posiX",'d',false); 149 PosiXPrm->SetGuidance("position X"); 147 PosiXPrm->SetGuidance("position X"); 150 fTalPosiCmd->SetParameter(PosiXPrm); 148 fTalPosiCmd->SetParameter(PosiXPrm); 151 // << 149 // 152 G4UIparameter* PosiYPrm = new G4UIparameter( << 150 G4UIparameter* PosiYPrm = new G4UIparameter("posiY",'d',false); 153 PosiYPrm->SetGuidance("position Y"); 151 PosiYPrm->SetGuidance("position Y"); 154 fTalPosiCmd->SetParameter(PosiYPrm); 152 fTalPosiCmd->SetParameter(PosiYPrm); 155 // 153 // 156 G4UIparameter* PosiZPrm = new G4UIparameter( << 154 G4UIparameter* PosiZPrm = new G4UIparameter("posiZ",'d',false); 157 PosiZPrm->SetGuidance("position Z"); 155 PosiZPrm->SetGuidance("position Z"); 158 fTalPosiCmd->SetParameter(PosiZPrm); << 156 fTalPosiCmd->SetParameter(PosiZPrm); 159 // 157 // 160 G4UIparameter* unitPr = new G4UIparameter("u << 158 G4UIparameter* unitPr = new G4UIparameter("unit",'s',false); 161 unitPr->SetGuidance("unit of position"); 159 unitPr->SetGuidance("unit of position"); 162 unitPr->SetParameterCandidates(unitList); 160 unitPr->SetParameterCandidates(unitList); 163 fTalPosiCmd->SetParameter(unitPr); 161 fTalPosiCmd->SetParameter(unitPr); 164 // 162 // 165 fTalPosiCmd->AvailableForStates(G4State_PreI 163 fTalPosiCmd->AvailableForStates(G4State_PreInit); >> 164 166 } 165 } 167 166 168 //....oooOO0OOooo........oooOO0OOooo........oo 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 169 168 170 DetectorMessenger::~DetectorMessenger() 169 DetectorMessenger::~DetectorMessenger() 171 { 170 { 172 delete fMaterCmd; 171 delete fMaterCmd; 173 delete fWMaterCmd; 172 delete fWMaterCmd; 174 delete fSizeXCmd; 173 delete fSizeXCmd; 175 delete fSizeYZCmd; << 174 delete fSizeYZCmd; 176 delete fMagFieldCmd; 175 delete fMagFieldCmd; 177 delete fTalNbCmd; 176 delete fTalNbCmd; 178 delete fTalDefCmd; 177 delete fTalDefCmd; 179 delete fTalPosiCmd; 178 delete fTalPosiCmd; 180 delete fDetDir; << 179 delete fDetDir; 181 delete fTestemDir; 180 delete fTestemDir; 182 } 181 } 183 182 184 //....oooOO0OOooo........oooOO0OOooo........oo 183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 185 184 186 void DetectorMessenger::SetNewValue(G4UIcomman << 185 void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 187 { << 186 { 188 if (command == fMaterCmd) { << 187 if( command == fMaterCmd ) 189 fDetector->SetMaterial(newValue); << 188 { fDetector->SetMaterial(newValue);} 190 } << 189 191 << 190 if( command == fWMaterCmd ) 192 if (command == fWMaterCmd) { << 191 { fDetector->SetWorldMaterial(newValue);} 193 fDetector->SetWorldMaterial(newValue); << 192 194 } << 193 if( command == fSizeXCmd ) 195 << 194 { fDetector->SetSizeX(fSizeXCmd->GetNewDoubleValue(newValue));} 196 if (command == fSizeXCmd) { << 195 197 fDetector->SetSizeX(fSizeXCmd->GetNewDoubl << 196 if( command == fSizeYZCmd ) 198 } << 197 { fDetector->SetSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));} 199 << 198 200 if (command == fSizeYZCmd) { << 199 if( command == fMagFieldCmd ) 201 fDetector->SetSizeYZ(fSizeYZCmd->GetNewDou << 200 { fDetector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));} 202 } << 201 203 << 202 if( command == fTalNbCmd ) 204 if (command == fMagFieldCmd) { << 203 { fDetector->SetTallyNumber(fTalNbCmd->GetNewIntValue(newValue));} 205 fDetector->SetMagField(fMagFieldCmd->GetNe << 204 206 } << 205 if (command == fTalDefCmd) 207 << 206 { 208 if (command == fTalNbCmd) { << 207 G4int num; G4double v1, v2, v3; 209 fDetector->SetTallyNumber(fTalNbCmd->GetNe << 208 G4String unt; 210 } << 209 std::istringstream is(newValue); 211 << 210 is >> num >> v1 >> v2 >> v3 >> unt; 212 if (command == fTalDefCmd) { << 211 G4ThreeVector vec(v1,v2,v3); 213 G4int num; << 212 vec *= G4UIcommand::ValueOf(unt); 214 G4double v1, v2, v3; << 213 fDetector->SetTallySize(num,vec); 215 G4String unt; << 214 } 216 std::istringstream is(newValue); << 215 217 is >> num >> v1 >> v2 >> v3 >> unt; << 216 if (command == fTalPosiCmd) 218 G4ThreeVector vec(v1, v2, v3); << 217 { 219 vec *= G4UIcommand::ValueOf(unt); << 218 G4int num; G4double v1, v2, v3; 220 fDetector->SetTallySize(num, vec); << 219 G4String unt; 221 } << 220 std::istringstream is(newValue); 222 << 221 is >> num >> v1 >> v2 >> v3 >> unt; 223 if (command == fTalPosiCmd) { << 222 G4ThreeVector vec(v1,v2,v3); 224 G4int num; << 223 vec *= G4UIcommand::ValueOf(unt); 225 G4double v1, v2, v3; << 224 fDetector->SetTallyPosition(num,vec); 226 G4String unt; << 225 } 227 std::istringstream is(newValue); << 228 is >> num >> v1 >> v2 >> v3 >> unt; << 229 G4ThreeVector vec(v1, v2, v3); << 230 vec *= G4UIcommand::ValueOf(unt); << 231 fDetector->SetTallyPosition(num, vec); << 232 } << 233 } 226 } 234 227 235 //....oooOO0OOooo........oooOO0OOooo........oo 228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 236 229