Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 #include "Par04DetectorMessenger.hh" 27 28 #include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction 29 30 #include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit 31 #include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger 32 #include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter 33 #include "G4UIdirectory.hh" // for G4UIdirectory 34 35 #include <CLHEP/Units/SystemOfUnits.h> // for pi 36 #include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle 37 #include <G4ThreeVector.hh> // for G4ThreeVector 38 #include <G4Types.hh> // for G4bool, G4double, G4int 39 #include <G4UIcommand.hh> // for G4UIcommand 40 #include <G4UImessenger.hh> // for G4UImessenger 41 #include <G4UIparameter.hh> // for G4UIparameter 42 #include <istream> // for basic_istream, basic_istream... 43 #include <string> // for operator>> 44 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 47 Par04DetectorMessenger::Par04DetectorMessenger(Par04DetectorConstruction* aDetector) 48 : G4UImessenger(), fDetector(aDetector) 49 { 50 fExampleDir = new G4UIdirectory("/Par04/"); 51 fExampleDir->SetGuidance("UI commands specific to this example"); 52 53 fDetectorDir = new G4UIdirectory("/Par04/detector/"); 54 fDetectorDir->SetGuidance("Detector construction UI commands"); 55 56 fPrintCmd = new G4UIcmdWithoutParameter("/Par04/detector/print", this); 57 fPrintCmd->SetGuidance("Print current settings."); 58 59 fDetectorInnerRadiusCmd = 60 new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorInnerRadius", this); 61 fDetectorInnerRadiusCmd->SetGuidance("Set cylindrical detector inner radius"); 62 fDetectorInnerRadiusCmd->SetParameterName("Size", false); 63 fDetectorInnerRadiusCmd->SetRange("Size>0."); 64 fDetectorInnerRadiusCmd->SetUnitCategory("Length"); 65 fDetectorInnerRadiusCmd->AvailableForStates(G4State_PreInit); 66 fDetectorInnerRadiusCmd->SetToBeBroadcasted(false); 67 68 fDetectorLengthCmd = new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorLength", this); 69 fDetectorLengthCmd->SetGuidance("Set length of the detector (cylinder length)"); 70 fDetectorLengthCmd->SetParameterName("Size", false); 71 fDetectorLengthCmd->SetRange("Size>0."); 72 fDetectorLengthCmd->SetUnitCategory("Length"); 73 fDetectorLengthCmd->AvailableForStates(G4State_PreInit); 74 fDetectorLengthCmd->SetToBeBroadcasted(false); 75 76 fNbLayersCmd = new G4UIcmdWithAnInteger("/Par04/detector/setNbOfLayers", this); 77 fNbLayersCmd->SetGuidance("Set number of layers."); 78 fNbLayersCmd->SetParameterName("NbLayers", false); 79 fNbLayersCmd->SetRange("NbLayers>0"); 80 fNbLayersCmd->AvailableForStates(G4State_PreInit); 81 fNbLayersCmd->SetToBeBroadcasted(false); 82 83 fAbsorCmd = new G4UIcommand("/Par04/detector/setAbsorber", this); 84 fAbsorCmd->SetGuidance("Set the absorber id, the material, the thickness."); 85 fAbsorCmd->SetGuidance(" absorber number : from 0 to 1"); 86 fAbsorCmd->SetGuidance(" material name"); 87 fAbsorCmd->SetGuidance(" thickness (with unit) : t>0"); 88 fAbsorCmd->SetGuidance(" if sensitive : true/false."); 89 auto absNbPrm = new G4UIparameter("AbsorNb", 'i', false); 90 absNbPrm->SetGuidance("absor number : from 0 to 1"); 91 absNbPrm->SetParameterRange("AbsorNb>-1&AbsoNb<2"); 92 fAbsorCmd->SetParameter(absNbPrm); 93 auto matPrm = new G4UIparameter("material", 's', false); 94 matPrm->SetGuidance("material name"); 95 fAbsorCmd->SetParameter(matPrm); 96 auto thickPrm = new G4UIparameter("thickness", 'd', false); 97 thickPrm->SetGuidance("thickness of absorber"); 98 thickPrm->SetParameterRange("thickness>0."); 99 fAbsorCmd->SetParameter(thickPrm); 100 auto unitPrm = new G4UIparameter("unit", 's', false); 101 unitPrm->SetGuidance("unit of thickness"); 102 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm")); 103 unitPrm->SetParameterCandidates(unitList); 104 fAbsorCmd->SetParameter(unitPrm); 105 auto sensitivePrm = new G4UIparameter("sensitive", 'b', false); 106 sensitivePrm->SetGuidance("if absorber is sensitive (registers energy deposits)"); 107 fAbsorCmd->SetParameter(sensitivePrm); 108 109 fAbsorCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 110 fAbsorCmd->SetToBeBroadcasted(false); 111 112 fMeshDir = new G4UIdirectory("/Par04/mesh/"); 113 fMeshDir->SetGuidance("Mesh UI commands"); 114 115 fMeshNbRhoCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfRhoCells", this); 116 fMeshNbRhoCellsCmd->SetGuidance("Set number of rho cells in the cylindrical mesh readout."); 117 fMeshNbRhoCellsCmd->SetParameterName("NbRhoCells", false); 118 fMeshNbRhoCellsCmd->SetRange("NbRhoCells>0"); 119 fMeshNbRhoCellsCmd->AvailableForStates(G4State_PreInit); 120 fMeshNbRhoCellsCmd->SetToBeBroadcasted(false); 121 122 fMeshNbPhiCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfPhiCells", this); 123 fMeshNbPhiCellsCmd->SetGuidance("Set number of phi cells in the cylindrical mesh readout."); 124 fMeshNbPhiCellsCmd->SetParameterName("NbPhiCells", false); 125 fMeshNbPhiCellsCmd->SetRange("NbPhiCells>0"); 126 fMeshNbPhiCellsCmd->AvailableForStates(G4State_PreInit); 127 fMeshNbPhiCellsCmd->SetToBeBroadcasted(false); 128 129 fMeshNbZCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfZCells", this); 130 fMeshNbZCellsCmd->SetGuidance("Set number of z cells in the cylindrical mesh readout."); 131 fMeshNbZCellsCmd->SetParameterName("NbZCells", false); 132 fMeshNbZCellsCmd->SetRange("NbZCells>0"); 133 fMeshNbZCellsCmd->AvailableForStates(G4State_PreInit); 134 fMeshNbZCellsCmd->SetToBeBroadcasted(false); 135 136 fMeshSizeRhoCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfRhoCells", this); 137 fMeshSizeRhoCellsCmd->SetGuidance("Set size of rho cells in the cylindrical readout mesh"); 138 fMeshSizeRhoCellsCmd->SetParameterName("Size", false); 139 fMeshSizeRhoCellsCmd->SetRange("Size>0."); 140 fMeshSizeRhoCellsCmd->SetUnitCategory("Length"); 141 fMeshSizeRhoCellsCmd->AvailableForStates(G4State_PreInit); 142 fMeshSizeRhoCellsCmd->SetToBeBroadcasted(false); 143 144 fMeshSizeZCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfZCells", this); 145 fMeshSizeZCellsCmd->SetGuidance("Set size of z cells in the cylindrical readout mesh"); 146 fMeshSizeZCellsCmd->SetParameterName("Size", false); 147 fMeshSizeZCellsCmd->SetRange("Size>0."); 148 fMeshSizeZCellsCmd->SetUnitCategory("Length"); 149 fMeshSizeZCellsCmd->AvailableForStates(G4State_PreInit); 150 fMeshSizeZCellsCmd->SetToBeBroadcasted(false); 151 } 152 153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 154 155 Par04DetectorMessenger::~Par04DetectorMessenger() 156 { 157 delete fPrintCmd; 158 delete fDetectorInnerRadiusCmd; 159 delete fDetectorLengthCmd; 160 delete fNbLayersCmd; 161 delete fAbsorCmd; 162 delete fDetectorDir; 163 delete fMeshNbRhoCellsCmd; 164 delete fMeshNbPhiCellsCmd; 165 delete fMeshNbZCellsCmd; 166 delete fMeshSizeRhoCellsCmd; 167 delete fMeshSizeZCellsCmd; 168 delete fMeshDir; 169 delete fExampleDir; 170 } 171 172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 173 174 void Par04DetectorMessenger::SetNewValue(G4UIcommand* aCommand, G4String aNewValue) 175 { 176 if (aCommand == fPrintCmd) { 177 fDetector->Print(); 178 } 179 else if (aCommand == fDetectorInnerRadiusCmd) { 180 fDetector->SetInnerRadius(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue)); 181 } 182 else if (aCommand == fDetectorLengthCmd) { 183 fDetector->SetLength(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue)); 184 } 185 else if (aCommand == fNbLayersCmd) { 186 fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(aNewValue)); 187 } 188 else if (aCommand == fAbsorCmd) { 189 G4int num; 190 G4double thick; 191 G4String unt, mat; 192 G4bool sensitive; 193 std::istringstream is(aNewValue); 194 is >> num >> mat >> thick >> unt >> std::boolalpha >> sensitive; 195 G4String material = mat; 196 thick *= G4UIcommand::ValueOf(unt); 197 fDetector->SetAbsorberMaterial(num, material); 198 fDetector->SetAbsorberThickness(num, thick); 199 fDetector->SetAbsorberSensitivity(num, sensitive); 200 } 201 else if (aCommand == fMeshNbRhoCellsCmd) { 202 fDetector->SetMeshNbOfCells(0, fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue)); 203 } 204 else if (aCommand == fMeshNbPhiCellsCmd) { 205 fDetector->SetMeshNbOfCells(1, fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue)); 206 fDetector->SetMeshSizeOfCells(1, 207 2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue)); 208 } 209 else if (aCommand == fMeshNbZCellsCmd) { 210 fDetector->SetMeshNbOfCells(2, fMeshNbZCellsCmd->GetNewIntValue(aNewValue)); 211 } 212 else if (aCommand == fMeshSizeRhoCellsCmd) { 213 fDetector->SetMeshSizeOfCells(0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue)); 214 } 215 else if (aCommand == fMeshSizeZCellsCmd) { 216 fDetector->SetMeshSizeOfCells(2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue)); 217 } 218 } 219 220 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 221 222 G4String Par04DetectorMessenger::GetCurrentValue(G4UIcommand* aCommand) 223 { 224 G4String cv; 225 226 if (aCommand == fDetectorInnerRadiusCmd) { 227 cv = fDetectorInnerRadiusCmd->ConvertToString(fDetector->GetInnerRadius(), "mm"); 228 } 229 else if (aCommand == fDetectorLengthCmd) { 230 cv = fDetectorLengthCmd->ConvertToString(fDetector->GetLength(), "mm"); 231 } 232 else if (aCommand == fNbLayersCmd) { 233 cv = fNbLayersCmd->ConvertToString(fDetector->GetNbOfLayers()); 234 } 235 else if (aCommand == fMeshNbRhoCellsCmd) { 236 cv = fMeshNbRhoCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[0]); 237 } 238 else if (aCommand == fMeshNbPhiCellsCmd) { 239 cv = fMeshNbPhiCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[1]); 240 } 241 else if (aCommand == fMeshNbZCellsCmd) { 242 cv = fMeshNbZCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[2]); 243 } 244 else if (aCommand == fMeshSizeRhoCellsCmd) { 245 cv = fMeshSizeRhoCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[0]); 246 } 247 else if (aCommand == fMeshSizeZCellsCmd) { 248 cv = fMeshSizeZCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[2]); 249 } 250 return cv; 251 } 252