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