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