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 // 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 << 37 #include "G4UIcmdWithADoubleAndUnit.hh" << 38 #include "G4UIcmdWithAString.hh" << 39 #include "G4UIcmdWithoutParameter.hh" << 40 #include "G4UIcommand.hh" << 41 #include "G4UIdirectory.hh" 36 #include "G4UIdirectory.hh" >> 37 #include "G4UIcommand.hh" 42 #include "G4UIparameter.hh" 38 #include "G4UIparameter.hh" >> 39 #include "G4UIcmdWithAString.hh" >> 40 #include "G4UIcmdWithADoubleAndUnit.hh" >> 41 #include "G4UIcmdWithoutParameter.hh" 43 42 44 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 44 46 DetectorMessenger::DetectorMessenger(DetectorC << 45 DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) >> 46 :G4UImessenger(), >> 47 fDetector(Det), fTestemDir(nullptr), fDetDir(nullptr), fMaterCmd(nullptr), >> 48 fThickCmd(nullptr), fSizeYZCmd(nullptr), fIsotopeCmd(nullptr) 47 { 49 { 48 fTestemDir = new G4UIdirectory("/testhadr/") 50 fTestemDir = new G4UIdirectory("/testhadr/"); 49 fTestemDir->SetGuidance("commands specific t 51 fTestemDir->SetGuidance("commands specific to this example"); 50 52 51 G4bool broadcast = false; 53 G4bool broadcast = false; 52 fDetDir = new G4UIdirectory("/testhadr/det/" << 54 fDetDir = new G4UIdirectory("/testhadr/det/",broadcast); 53 fDetDir->SetGuidance("detector construction 55 fDetDir->SetGuidance("detector construction commands"); 54 56 55 fMaterCmd = new G4UIcmdWithAString("/testhad << 57 fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat",this); 56 fMaterCmd->SetGuidance("Select material of t 58 fMaterCmd->SetGuidance("Select material of the box."); 57 fMaterCmd->SetParameterName("choice", false) << 59 fMaterCmd->SetParameterName("choice",false); 58 fMaterCmd->AvailableForStates(G4State_PreIni << 60 fMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 59 61 60 fThickCmd = new G4UIcmdWithADoubleAndUnit("/ << 62 fThickCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setThickness",this); 61 fThickCmd->SetGuidance("Set thickness of the 63 fThickCmd->SetGuidance("Set thickness of the absor"); 62 fThickCmd->SetParameterName("Thickness", fal << 64 fThickCmd->SetParameterName("Thickness",false); 63 fThickCmd->SetRange("Thickness>0."); 65 fThickCmd->SetRange("Thickness>0."); 64 fThickCmd->SetUnitCategory("Length"); 66 fThickCmd->SetUnitCategory("Length"); 65 fThickCmd->AvailableForStates(G4State_PreIni << 67 fThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 66 << 68 67 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit(" << 69 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ",this); 68 fSizeYZCmd->SetGuidance("Set transverse size 70 fSizeYZCmd->SetGuidance("Set transverse size of the absor"); 69 fSizeYZCmd->SetParameterName("Size", false); << 71 fSizeYZCmd->SetParameterName("Size",false); 70 fSizeYZCmd->SetRange("Size>0."); 72 fSizeYZCmd->SetRange("Size>0."); 71 fSizeYZCmd->SetUnitCategory("Length"); 73 fSizeYZCmd->SetUnitCategory("Length"); 72 fSizeYZCmd->AvailableForStates(G4State_PreIn << 74 fSizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 73 75 74 fIsotopeCmd = new G4UIcommand("/testhadr/det << 76 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat",this); 75 fIsotopeCmd->SetGuidance("Build and select a 77 fIsotopeCmd->SetGuidance("Build and select a material with single isotope"); 76 fIsotopeCmd->SetGuidance(" symbol of isotop 78 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material"); 77 // 79 // 78 G4UIparameter* symbPrm = new G4UIparameter(" << 80 G4UIparameter* symbPrm = new G4UIparameter("isotope",'s',false); 79 symbPrm->SetGuidance("isotope symbol"); 81 symbPrm->SetGuidance("isotope symbol"); 80 fIsotopeCmd->SetParameter(symbPrm); 82 fIsotopeCmd->SetParameter(symbPrm); 81 // << 83 // 82 G4UIparameter* ZPrm = new G4UIparameter("Z", << 84 G4UIparameter* ZPrm = new G4UIparameter("Z",'i',false); 83 ZPrm->SetGuidance("Z"); 85 ZPrm->SetGuidance("Z"); 84 ZPrm->SetParameterRange("Z>0"); 86 ZPrm->SetParameterRange("Z>0"); 85 fIsotopeCmd->SetParameter(ZPrm); 87 fIsotopeCmd->SetParameter(ZPrm); 86 // << 88 // 87 G4UIparameter* APrm = new G4UIparameter("A", << 89 G4UIparameter* APrm = new G4UIparameter("A",'i',false); 88 APrm->SetGuidance("A"); 90 APrm->SetGuidance("A"); 89 APrm->SetParameterRange("A>0"); 91 APrm->SetParameterRange("A>0"); 90 fIsotopeCmd->SetParameter(APrm); << 92 fIsotopeCmd->SetParameter(APrm); 91 // << 93 // 92 G4UIparameter* densityPrm = new G4UIparamete << 94 G4UIparameter* densityPrm = new G4UIparameter("density",'d',false); 93 densityPrm->SetGuidance("density of material 95 densityPrm->SetGuidance("density of material"); 94 densityPrm->SetParameterRange("density>0."); 96 densityPrm->SetParameterRange("density>0."); 95 fIsotopeCmd->SetParameter(densityPrm); 97 fIsotopeCmd->SetParameter(densityPrm); 96 // 98 // 97 G4UIparameter* unitPrm = new G4UIparameter(" << 99 G4UIparameter* unitPrm = new G4UIparameter("unit",'s',false); 98 unitPrm->SetGuidance("unit of density"); 100 unitPrm->SetGuidance("unit of density"); 99 G4String unitList = G4UIcommand::UnitsList(G 101 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3")); 100 unitPrm->SetParameterCandidates(unitList); 102 unitPrm->SetParameterCandidates(unitList); 101 fIsotopeCmd->SetParameter(unitPrm); 103 fIsotopeCmd->SetParameter(unitPrm); 102 // 104 // 103 fIsotopeCmd->AvailableForStates(G4State_PreI << 105 fIsotopeCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 104 } 106 } 105 107 106 //....oooOO0OOooo........oooOO0OOooo........oo 108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 107 109 108 DetectorMessenger::~DetectorMessenger() 110 DetectorMessenger::~DetectorMessenger() 109 { 111 { 110 delete fMaterCmd; 112 delete fMaterCmd; 111 delete fThickCmd; 113 delete fThickCmd; 112 delete fSizeYZCmd; 114 delete fSizeYZCmd; 113 delete fIsotopeCmd; 115 delete fIsotopeCmd; 114 delete fDetDir; 116 delete fDetDir; 115 delete fTestemDir; 117 delete fTestemDir; 116 } 118 } 117 119 118 //....oooOO0OOooo........oooOO0OOooo........oo 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 121 120 void DetectorMessenger::SetNewValue(G4UIcomman << 122 void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) 121 { << 123 { 122 if (command == fMaterCmd) { << 124 if( command == fMaterCmd ) 123 fDetector->SetAbsorMaterial(newValue); << 125 { fDetector->SetAbsorMaterial(newValue);} 124 } << 126 125 << 127 if( command == fThickCmd ) 126 if (command == fThickCmd) { << 128 { fDetector->SetAbsorThickness(fThickCmd->GetNewDoubleValue(newValue));} 127 fDetector->SetAbsorThickness(fThickCmd->Ge << 129 128 } << 130 if( command == fSizeYZCmd ) 129 << 131 { fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));} 130 if (command == fSizeYZCmd) { << 132 131 fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetN << 133 if (command == fIsotopeCmd) 132 } << 134 { 133 << 135 G4int Z; G4int A; G4double dens; 134 if (command == fIsotopeCmd) { << 136 G4String name, unt; 135 G4int Z; << 137 std::istringstream is(newValue); 136 G4int A; << 138 is >> name >> Z >> A >> dens >> unt; 137 G4double dens; << 139 dens *= G4UIcommand::ValueOf(unt); 138 G4String name, unt; << 140 fDetector->MaterialWithSingleIsotope (name,name,dens,Z,A); 139 std::istringstream is(newValue); << 141 fDetector->SetAbsorMaterial(name); 140 is >> name >> Z >> A >> dens >> unt; << 142 } 141 dens *= G4UIcommand::ValueOf(unt); << 142 fDetector->MaterialWithSingleIsotope(name, << 143 fDetector->SetAbsorMaterial(name); << 144 } << 145 } 143 } 146 144 147 //....oooOO0OOooo........oooOO0OOooo........oo 145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 148 146