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 DetectorMessenger.cc 26 /// \file DetectorMessenger.cc 27 /// \brief Implementation of the DetectorMesse 27 /// \brief Implementation of the DetectorMessenger class 28 // 28 // >> 29 // $Id: DetectorMessenger.cc 77288 2013-11-22 10:52:58Z 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 <sstream> 36 37 37 #include "G4UIcmdWithADoubleAndUnit.hh" << 38 #include "DetectorConstruction.hh" 38 #include "G4UIcmdWithAnInteger.hh" << 39 #include "G4UIcmdWithoutParameter.hh" << 40 #include "G4UIcommand.hh" << 41 #include "G4UIdirectory.hh" 39 #include "G4UIdirectory.hh" >> 40 #include "G4UIcommand.hh" 42 #include "G4UIparameter.hh" 41 #include "G4UIparameter.hh" 43 << 42 #include "G4UIcmdWithAnInteger.hh" 44 #include <sstream> << 43 #include "G4UIcmdWithADoubleAndUnit.hh" >> 44 #include "G4UIcmdWithoutParameter.hh" 45 45 46 //....oooOO0OOooo........oooOO0OOooo........oo 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 47 48 DetectorMessenger::DetectorMessenger(DetectorC << 48 DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) 49 { << 49 :G4UImessenger(),fDetector(Det), >> 50 fTestemDir(0), >> 51 fDetDir(0), >> 52 fNbAbsorCmd(0), >> 53 fAbsorCmd(0), >> 54 fSizeYZCmd(0), >> 55 fIsotopeCmd(0) >> 56 { 50 fTestemDir = new G4UIdirectory("/testhadr/") 57 fTestemDir = new G4UIdirectory("/testhadr/"); 51 fTestemDir->SetGuidance(" detector control." 58 fTestemDir->SetGuidance(" detector control."); 52 << 59 53 fDetDir = new G4UIdirectory("/testhadr/det/" 60 fDetDir = new G4UIdirectory("/testhadr/det/"); 54 fDetDir->SetGuidance("detector construction 61 fDetDir->SetGuidance("detector construction commands"); 55 << 62 56 fNbAbsorCmd = new G4UIcmdWithAnInteger("/tes << 63 fNbAbsorCmd = new G4UIcmdWithAnInteger("/testhadr/det/setNbOfAbsor",this); 57 fNbAbsorCmd->SetGuidance("Set number of Abso 64 fNbAbsorCmd->SetGuidance("Set number of Absorbers."); 58 fNbAbsorCmd->SetParameterName("NbAbsor", fal << 65 fNbAbsorCmd->SetParameterName("NbAbsor",false); 59 fNbAbsorCmd->SetRange("NbAbsor>0"); 66 fNbAbsorCmd->SetRange("NbAbsor>0"); 60 fNbAbsorCmd->AvailableForStates(G4State_PreI << 67 fNbAbsorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 61 fNbAbsorCmd->SetToBeBroadcasted(false); 68 fNbAbsorCmd->SetToBeBroadcasted(false); 62 << 69 63 fAbsorCmd = new G4UIcommand("/testhadr/det/s << 70 fAbsorCmd = new G4UIcommand("/testhadr/det/setAbsor",this); 64 fAbsorCmd->SetGuidance("Set the absor nb, th 71 fAbsorCmd->SetGuidance("Set the absor nb, the material, the thickness."); 65 fAbsorCmd->SetGuidance(" absor number : fro 72 fAbsorCmd->SetGuidance(" absor number : from 1 to NbOfAbsor"); 66 fAbsorCmd->SetGuidance(" material name"); 73 fAbsorCmd->SetGuidance(" material name"); 67 fAbsorCmd->SetGuidance(" thickness (with un 74 fAbsorCmd->SetGuidance(" thickness (with unit) : t>0."); 68 // 75 // 69 G4UIparameter* AbsNbPrm = new G4UIparameter( << 76 G4UIparameter* AbsNbPrm = new G4UIparameter("AbsorNb",'i',false); 70 AbsNbPrm->SetGuidance("absor number : from 1 77 AbsNbPrm->SetGuidance("absor number : from 1 to NbOfAbsor"); 71 AbsNbPrm->SetParameterRange("AbsorNb>0"); 78 AbsNbPrm->SetParameterRange("AbsorNb>0"); 72 fAbsorCmd->SetParameter(AbsNbPrm); 79 fAbsorCmd->SetParameter(AbsNbPrm); 73 // 80 // 74 G4UIparameter* MatPrm = new G4UIparameter("m << 81 G4UIparameter* MatPrm = new G4UIparameter("material",'s',false); 75 MatPrm->SetGuidance("material name"); 82 MatPrm->SetGuidance("material name"); 76 fAbsorCmd->SetParameter(MatPrm); 83 fAbsorCmd->SetParameter(MatPrm); 77 // << 84 // 78 G4UIparameter* ThickPrm = new G4UIparameter( << 85 G4UIparameter* ThickPrm = new G4UIparameter("thickness",'d',false); 79 ThickPrm->SetGuidance("thickness of absorber 86 ThickPrm->SetGuidance("thickness of absorber"); 80 ThickPrm->SetParameterRange("thickness>0."); 87 ThickPrm->SetParameterRange("thickness>0."); 81 fAbsorCmd->SetParameter(ThickPrm); 88 fAbsorCmd->SetParameter(ThickPrm); 82 // 89 // 83 G4UIparameter* unitPrm = new G4UIparameter(" << 90 G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false); 84 unitPrm->SetGuidance("unit of thickness"); 91 unitPrm->SetGuidance("unit of thickness"); 85 G4String unitList = G4UIcommand::UnitsList(G 92 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm")); 86 unitPrm->SetParameterCandidates(unitList); 93 unitPrm->SetParameterCandidates(unitList); 87 fAbsorCmd->SetParameter(unitPrm); 94 fAbsorCmd->SetParameter(unitPrm); 88 // 95 // 89 fAbsorCmd->AvailableForStates(G4State_PreIni << 96 fAbsorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 90 fAbsorCmd->SetToBeBroadcasted(false); 97 fAbsorCmd->SetToBeBroadcasted(false); 91 << 98 92 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit(" << 99 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ",this); 93 fSizeYZCmd->SetGuidance("Set sizeYZ of the a 100 fSizeYZCmd->SetGuidance("Set sizeYZ of the absorber"); 94 fSizeYZCmd->SetParameterName("SizeYZ", false << 101 fSizeYZCmd->SetParameterName("SizeYZ",false); 95 fSizeYZCmd->SetRange("SizeYZ>0."); 102 fSizeYZCmd->SetRange("SizeYZ>0."); 96 fSizeYZCmd->SetUnitCategory("Length"); 103 fSizeYZCmd->SetUnitCategory("Length"); 97 fSizeYZCmd->AvailableForStates(G4State_PreIn << 104 fSizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 98 fSizeYZCmd->SetToBeBroadcasted(false); 105 fSizeYZCmd->SetToBeBroadcasted(false); 99 106 100 fIsotopeCmd = new G4UIcommand("/testhadr/det << 107 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this); 101 fIsotopeCmd->SetGuidance("Build and select a 108 fIsotopeCmd->SetGuidance("Build and select a material with single isotope"); 102 fIsotopeCmd->SetGuidance(" symbol of isotop 109 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material"); 103 // 110 // 104 G4UIparameter* symbPrm = new G4UIparameter(" << 111 G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false); 105 symbPrm->SetGuidance("isotope symbol"); 112 symbPrm->SetGuidance("isotope symbol"); 106 fIsotopeCmd->SetParameter(symbPrm); 113 fIsotopeCmd->SetParameter(symbPrm); 107 // << 114 // 108 G4UIparameter* ZPrm = new G4UIparameter("Z", << 115 G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false); 109 ZPrm->SetGuidance("Z"); 116 ZPrm->SetGuidance("Z"); 110 ZPrm->SetParameterRange("Z>0"); 117 ZPrm->SetParameterRange("Z>0"); 111 fIsotopeCmd->SetParameter(ZPrm); 118 fIsotopeCmd->SetParameter(ZPrm); 112 // << 119 // 113 G4UIparameter* APrm = new G4UIparameter("A", << 120 G4UIparameter* APrm = new G4UIparameter("A",'i',false); 114 APrm->SetGuidance("A"); 121 APrm->SetGuidance("A"); 115 APrm->SetParameterRange("A>0"); 122 APrm->SetParameterRange("A>0"); 116 fIsotopeCmd->SetParameter(APrm); << 123 fIsotopeCmd->SetParameter(APrm); 117 // << 124 // 118 G4UIparameter* densityPrm = new G4UIparamete << 125 G4UIparameter* densityPrm = new G4UIparameter("density",'d',false); 119 densityPrm->SetGuidance("density of material 126 densityPrm->SetGuidance("density of material"); 120 densityPrm->SetParameterRange("density>0."); 127 densityPrm->SetParameterRange("density>0."); 121 fIsotopeCmd->SetParameter(densityPrm); 128 fIsotopeCmd->SetParameter(densityPrm); 122 // 129 // 123 G4UIparameter* unitPrm1 = new G4UIparameter( << 130 G4UIparameter* unitPrm1 = new G4UIparameter("unit",'s',false); 124 unitPrm1->SetGuidance("unit of density"); 131 unitPrm1->SetGuidance("unit of density"); 125 G4String unitList1 = G4UIcommand::UnitsList( 132 G4String unitList1 = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3")); 126 unitPrm1->SetParameterCandidates(unitList1); 133 unitPrm1->SetParameterCandidates(unitList1); 127 fIsotopeCmd->SetParameter(unitPrm1); 134 fIsotopeCmd->SetParameter(unitPrm1); 128 // 135 // 129 fIsotopeCmd->AvailableForStates(G4State_PreI << 136 fIsotopeCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 130 } 137 } 131 138 132 //....oooOO0OOooo........oooOO0OOooo........oo 139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 133 140 134 DetectorMessenger::~DetectorMessenger() 141 DetectorMessenger::~DetectorMessenger() 135 { 142 { 136 delete fNbAbsorCmd; 143 delete fNbAbsorCmd; 137 delete fAbsorCmd; 144 delete fAbsorCmd; 138 delete fSizeYZCmd; 145 delete fSizeYZCmd; 139 delete fIsotopeCmd; 146 delete fIsotopeCmd; 140 delete fDetDir; 147 delete fDetDir; 141 delete fTestemDir; 148 delete fTestemDir; 142 } 149 } 143 150 144 //....oooOO0OOooo........oooOO0OOooo........oo 151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 145 152 146 void DetectorMessenger::SetNewValue(G4UIcomman << 153 void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 147 { << 154 { 148 if (command == fNbAbsorCmd) { << 155 if( command == fNbAbsorCmd ) 149 fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNe << 156 { fDetector->SetNbOfAbsor(fNbAbsorCmd->GetNewIntValue(newValue));} 150 } << 157 151 << 158 if (command == fAbsorCmd) 152 if (command == fAbsorCmd) { << 159 { 153 G4int num; << 160 G4int num; G4double tick; 154 G4double tick; << 161 G4String unt, mat; 155 G4String unt, mat; << 162 std::istringstream is(newValue); 156 std::istringstream is(newValue); << 163 is >> num >> mat >> tick >> unt; 157 is >> num >> mat >> tick >> unt; << 164 G4String material=mat; 158 G4String material = mat; << 165 tick *= G4UIcommand::ValueOf(unt); 159 tick *= G4UIcommand::ValueOf(unt); << 166 fDetector->SetAbsorMaterial (num,material); 160 fDetector->SetAbsorMaterial(num, material) << 167 fDetector->SetAbsorThickness(num,tick); 161 fDetector->SetAbsorThickness(num, tick); << 168 } 162 } << 169 163 << 170 if( command == fSizeYZCmd ) 164 if (command == fSizeYZCmd) { << 171 { fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));} 165 fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetN << 172 166 } << 173 if (command == fIsotopeCmd) 167 << 174 { 168 if (command == fIsotopeCmd) { << 175 G4int Z; G4int A; G4double dens; 169 G4int Z; << 176 G4String name, unt; 170 G4int A; << 177 std::istringstream is(newValue); 171 G4double dens; << 178 is >> name >> Z >> A >> dens >> unt; 172 G4String name, unt; << 179 dens *= G4UIcommand::ValueOf(unt); 173 std::istringstream is(newValue); << 180 fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A); 174 is >> name >> Z >> A >> dens >> unt; << 181 } 175 dens *= G4UIcommand::ValueOf(unt); << 176 fDetector->MaterialWithSingleIsotope(name, << 177 } << 178 } 182 } 179 183 180 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 181 185