Loading...
Searching...
No Matches
Par04DetectorMessenger.cc
Go to the documentation of this file.
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//
27#include <CLHEP/Units/SystemOfUnits.h> // for pi
28#include <G4ApplicationState.hh> // for G4State_PreInit, G4State_Idle
29#include <G4ThreeVector.hh> // for G4ThreeVector
30#include <G4Types.hh> // for G4bool, G4double, G4int
31#include <G4UIcommand.hh> // for G4UIcommand
32#include <G4UImessenger.hh> // for G4UImessenger
33#include <G4UIparameter.hh> // for G4UIparameter
34#include <istream> // for basic_istream, basic_istream...
35#include <string> // for operator>>
36#include "G4UIcmdWithADoubleAndUnit.hh" // for G4UIcmdWithADoubleAndUnit
37#include "G4UIcmdWithAnInteger.hh" // for G4UIcmdWithAnInteger
38#include "G4UIcmdWithoutParameter.hh" // for G4UIcmdWithoutParameter
39#include "G4UIdirectory.hh" // for G4UIdirectory
40#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
41
42//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43
46 , fDetector(aDetector)
47{
48 fExampleDir = new G4UIdirectory("/Par04/");
49 fExampleDir->SetGuidance("UI commands specific to this example");
50
51 fDetectorDir = new G4UIdirectory("/Par04/detector/");
52 fDetectorDir->SetGuidance("Detector construction UI commands");
53
54 fPrintCmd = new G4UIcmdWithoutParameter("/Par04/detector/print", this);
55 fPrintCmd->SetGuidance("Print current settings.");
56
58 new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorInnerRadius", this);
59 fDetectorInnerRadiusCmd->SetGuidance("Set cylindrical detector inner radius");
60 fDetectorInnerRadiusCmd->SetParameterName("Size", false);
61 fDetectorInnerRadiusCmd->SetRange("Size>0.");
62 fDetectorInnerRadiusCmd->SetUnitCategory("Length");
63 fDetectorInnerRadiusCmd->AvailableForStates(G4State_PreInit);
64 fDetectorInnerRadiusCmd->SetToBeBroadcasted(false);
65
66 fDetectorLengthCmd = new G4UIcmdWithADoubleAndUnit("/Par04/detector/setDetectorLength", this);
67 fDetectorLengthCmd->SetGuidance("Set length of the detector (cylinder length)");
68 fDetectorLengthCmd->SetParameterName("Size", false);
69 fDetectorLengthCmd->SetRange("Size>0.");
70 fDetectorLengthCmd->SetUnitCategory("Length");
71 fDetectorLengthCmd->AvailableForStates(G4State_PreInit);
72 fDetectorLengthCmd->SetToBeBroadcasted(false);
73
74 fNbLayersCmd = new G4UIcmdWithAnInteger("/Par04/detector/setNbOfLayers", this);
75 fNbLayersCmd->SetGuidance("Set number of layers.");
76 fNbLayersCmd->SetParameterName("NbLayers", false);
77 fNbLayersCmd->SetRange("NbLayers>0");
78 fNbLayersCmd->AvailableForStates(G4State_PreInit);
79 fNbLayersCmd->SetToBeBroadcasted(false);
80
81 fAbsorCmd = new G4UIcommand("/Par04/detector/setAbsorber", this);
82 fAbsorCmd->SetGuidance("Set the absorber id, the material, the thickness.");
83 fAbsorCmd->SetGuidance(" absorber number : from 0 to 1");
84 fAbsorCmd->SetGuidance(" material name");
85 fAbsorCmd->SetGuidance(" thickness (with unit) : t>0");
86 fAbsorCmd->SetGuidance(" if sensitive : true/false.");
87 auto absNbPrm = new G4UIparameter("AbsorNb", 'i', false);
88 absNbPrm->SetGuidance("absor number : from 0 to 1");
89 absNbPrm->SetParameterRange("AbsorNb>-1&AbsoNb<2");
90 fAbsorCmd->SetParameter(absNbPrm);
91 auto matPrm = new G4UIparameter("material", 's', false);
92 matPrm->SetGuidance("material name");
93 fAbsorCmd->SetParameter(matPrm);
94 auto thickPrm = new G4UIparameter("thickness", 'd', false);
95 thickPrm->SetGuidance("thickness of absorber");
96 thickPrm->SetParameterRange("thickness>0.");
97 fAbsorCmd->SetParameter(thickPrm);
98 auto unitPrm = new G4UIparameter("unit", 's', false);
99 unitPrm->SetGuidance("unit of thickness");
100 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("mm"));
101 unitPrm->SetParameterCandidates(unitList);
102 fAbsorCmd->SetParameter(unitPrm);
103 auto sensitivePrm = new G4UIparameter("sensitive", 'b', false);
104 sensitivePrm->SetGuidance("if absorber is sensitive (registers energy deposits)");
105 fAbsorCmd->SetParameter(sensitivePrm);
106
107 fAbsorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
108 fAbsorCmd->SetToBeBroadcasted(false);
109
110 fMeshDir = new G4UIdirectory("/Par04/mesh/");
111 fMeshDir->SetGuidance("Mesh UI commands");
112
113 fMeshNbRhoCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfRhoCells", this);
114 fMeshNbRhoCellsCmd->SetGuidance("Set number of rho cells in the cylindrical mesh readout.");
115 fMeshNbRhoCellsCmd->SetParameterName("NbRhoCells", false);
116 fMeshNbRhoCellsCmd->SetRange("NbRhoCells>0");
117 fMeshNbRhoCellsCmd->AvailableForStates(G4State_PreInit);
118 fMeshNbRhoCellsCmd->SetToBeBroadcasted(false);
119
120 fMeshNbPhiCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfPhiCells", this);
121 fMeshNbPhiCellsCmd->SetGuidance("Set number of phi cells in the cylindrical mesh readout.");
122 fMeshNbPhiCellsCmd->SetParameterName("NbPhiCells", false);
123 fMeshNbPhiCellsCmd->SetRange("NbPhiCells>0");
124 fMeshNbPhiCellsCmd->AvailableForStates(G4State_PreInit);
125 fMeshNbPhiCellsCmd->SetToBeBroadcasted(false);
126
127 fMeshNbZCellsCmd = new G4UIcmdWithAnInteger("/Par04/mesh/setNbOfZCells", this);
128 fMeshNbZCellsCmd->SetGuidance("Set number of z cells in the cylindrical mesh readout.");
129 fMeshNbZCellsCmd->SetParameterName("NbZCells", false);
130 fMeshNbZCellsCmd->SetRange("NbZCells>0");
131 fMeshNbZCellsCmd->AvailableForStates(G4State_PreInit);
132 fMeshNbZCellsCmd->SetToBeBroadcasted(false);
133
134 fMeshSizeRhoCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfRhoCells", this);
135 fMeshSizeRhoCellsCmd->SetGuidance("Set size of rho cells in the cylindrical readout mesh");
136 fMeshSizeRhoCellsCmd->SetParameterName("Size", false);
137 fMeshSizeRhoCellsCmd->SetRange("Size>0.");
138 fMeshSizeRhoCellsCmd->SetUnitCategory("Length");
139 fMeshSizeRhoCellsCmd->AvailableForStates(G4State_PreInit);
140 fMeshSizeRhoCellsCmd->SetToBeBroadcasted(false);
141
142 fMeshSizeZCellsCmd = new G4UIcmdWithADoubleAndUnit("/Par04/mesh/setSizeOfZCells", this);
143 fMeshSizeZCellsCmd->SetGuidance("Set size of z cells in the cylindrical readout mesh");
144 fMeshSizeZCellsCmd->SetParameterName("Size", false);
145 fMeshSizeZCellsCmd->SetRange("Size>0.");
146 fMeshSizeZCellsCmd->SetUnitCategory("Length");
147 fMeshSizeZCellsCmd->AvailableForStates(G4State_PreInit);
148 fMeshSizeZCellsCmd->SetToBeBroadcasted(false);
149}
150
151//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
152
154{
155 delete fPrintCmd;
157 delete fDetectorLengthCmd;
158 delete fNbLayersCmd;
159 delete fAbsorCmd;
160 delete fDetectorDir;
161 delete fMeshNbRhoCellsCmd;
162 delete fMeshNbPhiCellsCmd;
163 delete fMeshNbZCellsCmd;
165 delete fMeshSizeZCellsCmd;
166 delete fMeshDir;
167 delete fExampleDir;
168}
169
170//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171
173{
174 if(aCommand == fPrintCmd)
175 {
176 fDetector->Print();
177 }
178 else if(aCommand == fDetectorInnerRadiusCmd)
179 {
180 fDetector->SetInnerRadius(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
181 }
182 else if(aCommand == fDetectorLengthCmd)
183 {
184 fDetector->SetLength(fDetectorInnerRadiusCmd->GetNewDoubleValue(aNewValue));
185 }
186 else if(aCommand == fNbLayersCmd)
187 {
188 fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(aNewValue));
189 }
190 else if(aCommand == fAbsorCmd)
191 {
192 G4int num;
193 G4double thick;
194 G4String unt, mat;
195 G4bool sensitive;
196 std::istringstream is(aNewValue);
197 is >> num >> mat >> thick >> unt >> std::boolalpha >> sensitive;
198 G4String material = mat;
199 thick *= G4UIcommand::ValueOf(unt);
200 fDetector->SetAbsorberMaterial(num, material);
201 fDetector->SetAbsorberThickness(num, thick);
202 fDetector->SetAbsorberSensitivity(num, sensitive);
203 }
204 else if(aCommand == fMeshNbRhoCellsCmd)
205 {
206 fDetector->SetMeshNbOfCells(0, fMeshNbRhoCellsCmd->GetNewIntValue(aNewValue));
207 }
208 else if(aCommand == fMeshNbPhiCellsCmd)
209 {
210 fDetector->SetMeshNbOfCells(1, fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
212 2. * CLHEP::pi / fMeshNbPhiCellsCmd->GetNewIntValue(aNewValue));
213 }
214 else if(aCommand == fMeshNbZCellsCmd)
215 {
216 fDetector->SetMeshNbOfCells(2, fMeshNbZCellsCmd->GetNewIntValue(aNewValue));
217 }
218 else if(aCommand == fMeshSizeRhoCellsCmd)
219 {
220 fDetector->SetMeshSizeOfCells(0, fMeshSizeRhoCellsCmd->GetNewDoubleValue(aNewValue));
221 }
222 else if(aCommand == fMeshSizeZCellsCmd)
223 {
224 fDetector->SetMeshSizeOfCells(2, fMeshSizeZCellsCmd->GetNewDoubleValue(aNewValue));
225 }
226}
227
228//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
229
231{
232 G4String cv;
233
234 if(aCommand == fDetectorInnerRadiusCmd)
235 {
236 cv = fDetectorInnerRadiusCmd->ConvertToString(fDetector->GetInnerRadius(), "mm");
237 }
238 else if(aCommand == fDetectorLengthCmd)
239 {
240 cv = fDetectorLengthCmd->ConvertToString(fDetector->GetLength(), "mm");
241 }
242 else if(aCommand == fNbLayersCmd)
243 {
244 cv = fNbLayersCmd->ConvertToString(fDetector->GetNbOfLayers());
245 }
246 else if(aCommand == fMeshNbRhoCellsCmd)
247 {
248 cv = fMeshNbRhoCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[0]);
249 }
250 else if(aCommand == fMeshNbPhiCellsCmd)
251 {
252 cv = fMeshNbPhiCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[1]);
253 }
254 else if(aCommand == fMeshNbZCellsCmd)
255 {
256 cv = fMeshNbZCellsCmd->ConvertToString(fDetector->GetMeshNbOfCells()[2]);
257 }
258 else if(aCommand == fMeshSizeRhoCellsCmd)
259 {
260 cv = fMeshSizeRhoCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[0]);
261 }
262 else if(aCommand == fMeshSizeZCellsCmd)
263 {
264 cv = fMeshSizeZCellsCmd->ConvertToString(fDetector->GetMeshSizeOfCells()[2]);
265 }
266 return cv;
267}
void SetMeshSizeOfCells(G4ThreeVector aNb)
Set size of Mesh cells in cylindrical coordinates (r, phi, z)
G4double GetLength() const
Get length of the cylindrical detector (along z-axis)
void SetAbsorberSensitivity(const std::size_t aLayer, const G4bool aSensitivity)
Set sensitivity of the layer.
void SetLength(G4double aLength)
Set length radius of the cylindrical detector.
G4ThreeVector GetMeshSizeOfCells() const
Get size of Mesh cells in cylindrical coordinates (r, phi, z)
G4ThreeVector GetMeshNbOfCells() const
Get number of Mesh cells in cylindrical coordinates (r, phi, z)
void SetMeshNbOfCells(G4ThreeVector aNb)
Set number of Mesh cells in cylindrical coordinates (r, phi, z)
void SetAbsorberMaterial(const std::size_t aLayer, const G4String &aMaterial)
Set material of the layer (from NIST materials)
void Print() const
Print detector information.
void SetInnerRadius(G4double aInnerRadius)
Set inner radius of the cylindrical detector.
G4int GetNbOfLayers() const
Get number of layers.
void SetNbOfLayers(G4int aNumber)
Set number of layers.
G4double GetInnerRadius() const
Get inner radius of the cylindrical detector.
void SetAbsorberThickness(const std::size_t aLayer, const G4double aThickness)
Set thickness of the layer.
G4UIcmdWithAnInteger * fMeshNbPhiCellsCmd
Command to set the number of cells in the cylindrical readout mesh (along phi axis)
G4UIcmdWithADoubleAndUnit * fMeshSizeRhoCellsCmd
Command to the size of cells in the cylindrical readout mesh (along rho axis)
G4UIcmdWithoutParameter * fPrintCmd
Command printing current settings.
G4UIcommand * fAbsorCmd
Commanbd to set the absorbers within layers (material, thickness, sensitivity)
G4UIcmdWithADoubleAndUnit * fDetectorLengthCmd
Command to set the detector length.
G4UIcmdWithADoubleAndUnit * fDetectorInnerRadiusCmd
Command to set the detector inner radius.
Par04DetectorConstruction * fDetector
Detector construction to setup.
G4UIcmdWithAnInteger * fNbLayersCmd
Command to set the number of layers.
virtual G4String GetCurrentValue(G4UIcommand *) final
Retrieves the current settings.
virtual void SetNewValue(G4UIcommand *, G4String) final
Invokes appropriate methods based on the typed command.
G4UIdirectory * fExampleDir
Command to set the directory common to all messengers in this example /Par04.
Par04DetectorMessenger(Par04DetectorConstruction *)
G4UIcmdWithADoubleAndUnit * fMeshSizeZCellsCmd
Command to the size of cells in the cylindrical readout mesh (along z axis)
G4UIcmdWithAnInteger * fMeshNbZCellsCmd
Command to set the number of cells in the cylindrical readout mesh (along z axis)
G4UIdirectory * fDetectorDir
Command to set the directory for detector settings /Par04/detector.
G4UIdirectory * fMeshDir
Command to set the directory for sensitive detector settings /Par04/mesh.
G4UIcmdWithAnInteger * fMeshNbRhoCellsCmd
Command to set the number of cells in the cylindrical readout mesh (along rho axis)

Applications | User Support | Publications | Collaboration