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 // $Id: DetectorMessenger.cc 67268 2013-02-13 11:38:40Z ihrivnac $ 29 // 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "DetectorMessenger.hh" 34 #include "DetectorMessenger.hh" 34 35 35 #include "DetectorConstruction.hh" 36 #include "DetectorConstruction.hh" 36 << 37 #include "G4UIdirectory.hh" 37 #include "G4UIcmdWithADoubleAndUnit.hh" << 38 #include "G4UIcommand.hh" >> 39 #include "G4UIparameter.hh" 38 #include "G4UIcmdWithAString.hh" 40 #include "G4UIcmdWithAString.hh" 39 #include "G4UIcmdWithAnInteger.hh" 41 #include "G4UIcmdWithAnInteger.hh" >> 42 #include "G4UIcmdWithADoubleAndUnit.hh" 40 #include "G4UIcmdWithoutParameter.hh" 43 #include "G4UIcmdWithoutParameter.hh" 41 #include "G4UIcommand.hh" << 42 #include "G4UIdirectory.hh" << 43 #include "G4UIparameter.hh" << 44 44 45 //....oooOO0OOooo........oooOO0OOooo........oo 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 46 47 DetectorMessenger::DetectorMessenger(DetectorC << 47 DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) 48 : G4UImessenger(), << 48 :G4UImessenger(),fDetector(Det), 49 fDetector(Det), << 49 fTestemDir(0), 50 fTestemDir(nullptr), << 50 fDetDir(0), 51 fDetDir(nullptr), << 51 fMaterCmd(0), 52 fMaterCmd(nullptr), << 52 fSizeXCmd(0), 53 fWMaterCmd(nullptr), << 53 fSizeYZCmd(0), 54 fSizeXCmd(nullptr), << 54 fMagFieldCmd(0), 55 fSizeYZCmd(nullptr), << 55 fTalNbCmd(0), 56 fMagFieldCmd(nullptr), << 56 fTalDefCmd(0), 57 fTalNbCmd(nullptr), << 57 fTalPosiCmd(0), 58 fTalDefCmd(nullptr), << 58 fUpdateCmd(0) 59 fTalPosiCmd(nullptr) << 59 { 60 { << 61 fTestemDir = new G4UIdirectory("/testem/"); 60 fTestemDir = new G4UIdirectory("/testem/"); 62 fTestemDir->SetGuidance(" detector control." 61 fTestemDir->SetGuidance(" detector control."); 63 << 62 64 fDetDir = new G4UIdirectory("/testem/det/"); 63 fDetDir = new G4UIdirectory("/testem/det/"); 65 fDetDir->SetGuidance("detector construction 64 fDetDir->SetGuidance("detector construction commands"); 66 << 65 67 fMaterCmd = new G4UIcmdWithAString("/testem/ << 66 fMaterCmd = new G4UIcmdWithAString("/testem/det/setMat",this); 68 fMaterCmd->SetGuidance("Select material of t 67 fMaterCmd->SetGuidance("Select material of the box."); 69 fMaterCmd->SetParameterName("choice", false) << 68 fMaterCmd->SetParameterName("choice",false); 70 fMaterCmd->AvailableForStates(G4State_PreIni << 69 fMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 71 << 70 72 fWMaterCmd = new G4UIcmdWithAString("/testem << 71 fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeX",this); 73 fWMaterCmd->SetGuidance("Select material of << 74 fWMaterCmd->SetParameterName("choice", false << 75 fWMaterCmd->AvailableForStates(G4State_PreIn << 76 << 77 fSizeXCmd = new G4UIcmdWithADoubleAndUnit("/ << 78 fSizeXCmd->SetGuidance("Set sizeX of the abs 72 fSizeXCmd->SetGuidance("Set sizeX of the absorber"); 79 fSizeXCmd->SetParameterName("SizeX", false); << 73 fSizeXCmd->SetParameterName("SizeX",false); 80 fSizeXCmd->SetRange("SizeX>0."); 74 fSizeXCmd->SetRange("SizeX>0."); 81 fSizeXCmd->SetUnitCategory("Length"); 75 fSizeXCmd->SetUnitCategory("Length"); 82 fSizeXCmd->AvailableForStates(G4State_PreIni << 76 fSizeXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 83 << 77 84 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit(" << 78 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setSizeYZ",this); 85 fSizeYZCmd->SetGuidance("Set sizeYZ of the a 79 fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber"); 86 fSizeYZCmd->SetParameterName("SizeYZ", false << 80 fSizeYZCmd->SetParameterName("SizeYZ",false); 87 fSizeYZCmd->SetRange("SizeYZ>0."); 81 fSizeYZCmd->SetRange("SizeYZ>0."); 88 fSizeYZCmd->SetUnitCategory("Length"); 82 fSizeYZCmd->SetUnitCategory("Length"); 89 fSizeYZCmd->AvailableForStates(G4State_PreIn << 83 fSizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 90 << 84 91 fMagFieldCmd = new G4UIcmdWithADoubleAndUnit << 85 fMagFieldCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/setField",this); 92 fMagFieldCmd->SetGuidance("Define magnetic f 86 fMagFieldCmd->SetGuidance("Define magnetic field."); 93 fMagFieldCmd->SetGuidance("Magnetic field wi 87 fMagFieldCmd->SetGuidance("Magnetic field will be in Z direction."); 94 fMagFieldCmd->SetParameterName("Bz", false); << 88 fMagFieldCmd->SetParameterName("Bz",false); 95 fMagFieldCmd->SetUnitCategory("Magnetic flux 89 fMagFieldCmd->SetUnitCategory("Magnetic flux density"); 96 fMagFieldCmd->AvailableForStates(G4State_Pre << 90 fMagFieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 97 << 91 98 fTalNbCmd = new G4UIcmdWithAnInteger("/teste << 92 fTalNbCmd = new G4UIcmdWithAnInteger("/testem/det/tallyNumber",this); 99 fTalNbCmd->SetGuidance("Set number of fTalli 93 fTalNbCmd->SetGuidance("Set number of fTallies."); 100 fTalNbCmd->SetParameterName("tallyNb", false << 94 fTalNbCmd->SetParameterName("tallyNb",false); 101 fTalNbCmd->SetRange("tallyNb>=0"); 95 fTalNbCmd->SetRange("tallyNb>=0"); 102 fTalNbCmd->AvailableForStates(G4State_PreIni << 96 fTalNbCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 103 97 104 fTalDefCmd = new G4UIcommand("/testem/det/ta << 98 fTalDefCmd = new G4UIcommand("/testem/det/tallyDefinition",this); 105 fTalDefCmd->SetGuidance("Set tally nb, box d << 99 fTalDefCmd->SetGuidance("Set tally nb, material, box dimensions."); 106 fTalDefCmd->SetGuidance(" tally number : fr << 100 fTalDefCmd->SetGuidance(" tally number : from 1 to tallyNumber"); 107 fTalDefCmd->SetGuidance(" material name"); 101 fTalDefCmd->SetGuidance(" material name"); 108 fTalDefCmd->SetGuidance(" dimensions (3-vec 102 fTalDefCmd->SetGuidance(" dimensions (3-vector with unit)"); 109 // 103 // 110 G4UIparameter* fTalNbPrm = new G4UIparameter << 104 G4UIparameter* fTalNbPrm = new G4UIparameter("tallyNb",'i',false); 111 fTalNbPrm->SetGuidance("tally number : from << 105 fTalNbPrm->SetGuidance("tally number : from 1 to tallyNumber"); 112 fTalNbPrm->SetParameterRange("tallyNb>=0"); << 106 fTalNbPrm->SetParameterRange("tallyNb>0"); 113 fTalDefCmd->SetParameter(fTalNbPrm); 107 fTalDefCmd->SetParameter(fTalNbPrm); 114 // 108 // 115 G4UIparameter* SizeXPrm = new G4UIparameter( << 109 G4UIparameter* MatPrm = new G4UIparameter("material",'s',false); >> 110 MatPrm->SetGuidance("material name"); >> 111 fTalDefCmd->SetParameter(MatPrm); >> 112 // >> 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,G4State_Idle); 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 1 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 1 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,G4State_Idle); >> 164 >> 165 fUpdateCmd = new G4UIcmdWithoutParameter("/testem/det/update",this); >> 166 fUpdateCmd->SetGuidance("Update calorimeter geometry."); >> 167 fUpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" "); >> 168 fUpdateCmd->SetGuidance("if you changed geometrical value(s)."); >> 169 fUpdateCmd->AvailableForStates(G4State_Idle); 166 } 170 } 167 171 168 //....oooOO0OOooo........oooOO0OOooo........oo 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 169 173 170 DetectorMessenger::~DetectorMessenger() 174 DetectorMessenger::~DetectorMessenger() 171 { 175 { 172 delete fMaterCmd; 176 delete fMaterCmd; 173 delete fWMaterCmd; << 174 delete fSizeXCmd; 177 delete fSizeXCmd; 175 delete fSizeYZCmd; << 178 delete fSizeYZCmd; 176 delete fMagFieldCmd; 179 delete fMagFieldCmd; 177 delete fTalNbCmd; 180 delete fTalNbCmd; 178 delete fTalDefCmd; 181 delete fTalDefCmd; 179 delete fTalPosiCmd; 182 delete fTalPosiCmd; 180 delete fDetDir; << 183 delete fUpdateCmd; >> 184 delete fDetDir; 181 delete fTestemDir; 185 delete fTestemDir; 182 } 186 } 183 187 184 //....oooOO0OOooo........oooOO0OOooo........oo 188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 185 189 186 void DetectorMessenger::SetNewValue(G4UIcomman << 190 void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 187 { << 191 { 188 if (command == fMaterCmd) { << 192 if( command == fMaterCmd ) 189 fDetector->SetMaterial(newValue); << 193 { fDetector->SetMaterial(newValue);} 190 } << 194 191 << 195 if( command == fSizeXCmd ) 192 if (command == fWMaterCmd) { << 196 { fDetector->SetSizeX(fSizeXCmd->GetNewDoubleValue(newValue));} 193 fDetector->SetWorldMaterial(newValue); << 197 194 } << 198 if( command == fSizeYZCmd ) 195 << 199 { fDetector->SetSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));} 196 if (command == fSizeXCmd) { << 200 197 fDetector->SetSizeX(fSizeXCmd->GetNewDoubl << 201 if( command == fMagFieldCmd ) 198 } << 202 { fDetector->SetMagField(fMagFieldCmd->GetNewDoubleValue(newValue));} 199 << 203 200 if (command == fSizeYZCmd) { << 204 if( command == fTalNbCmd ) 201 fDetector->SetSizeYZ(fSizeYZCmd->GetNewDou << 205 { fDetector->SetTallyNumber(fTalNbCmd->GetNewIntValue(newValue));} 202 } << 206 203 << 207 if (command == fTalDefCmd) 204 if (command == fMagFieldCmd) { << 208 { 205 fDetector->SetMagField(fMagFieldCmd->GetNe << 209 G4int num; G4double v1, v2, v3; 206 } << 210 G4String unt, mat; 207 << 211 std::istringstream is(newValue); 208 if (command == fTalNbCmd) { << 212 is >> num >> mat >> v1 >> v2 >> v3 >> unt; 209 fDetector->SetTallyNumber(fTalNbCmd->GetNe << 213 G4String material=mat; 210 } << 214 v1 *= G4UIcommand::ValueOf(unt); 211 << 215 v2 *= G4UIcommand::ValueOf(unt); 212 if (command == fTalDefCmd) { << 216 v3 *= G4UIcommand::ValueOf(unt); 213 G4int num; << 217 fDetector->SetTallyMaterial (num,material); 214 G4double v1, v2, v3; << 218 fDetector->SetTallySize(num,G4ThreeVector(v1,v2,v3)); 215 G4String unt; << 219 } 216 std::istringstream is(newValue); << 220 217 is >> num >> v1 >> v2 >> v3 >> unt; << 221 if (command == fTalPosiCmd) 218 G4ThreeVector vec(v1, v2, v3); << 222 { 219 vec *= G4UIcommand::ValueOf(unt); << 223 G4int num; G4double v1, v2, v3; 220 fDetector->SetTallySize(num, vec); << 224 G4String unt; 221 } << 225 std::istringstream is(newValue); 222 << 226 is >> num >> v1 >> v2 >> v3 >> unt; 223 if (command == fTalPosiCmd) { << 227 v1 *= G4UIcommand::ValueOf(unt); 224 G4int num; << 228 v2 *= G4UIcommand::ValueOf(unt); 225 G4double v1, v2, v3; << 229 v3 *= G4UIcommand::ValueOf(unt); 226 G4String unt; << 230 fDetector->SetTallyPosition(num,G4ThreeVector(v1,v2,v3)); 227 std::istringstream is(newValue); << 231 } 228 is >> num >> v1 >> v2 >> v3 >> unt; << 232 229 G4ThreeVector vec(v1, v2, v3); << 233 if( command == fUpdateCmd ) 230 vec *= G4UIcommand::ValueOf(unt); << 234 { fDetector->UpdateGeometry();} 231 fDetector->SetTallyPosition(num, vec); << 232 } << 233 } 235 } 234 236 235 //....oooOO0OOooo........oooOO0OOooo........oo 237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 236 238