GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSGunGeneratorActionMessenger.cpp
Go to the documentation of this file.
1 /*
2  * GGSGunGeneratorActionMessenger.cpp
3  *
4  * Created on: 10 Oct 2013
5  * Author: Nicola Mori
6  */
7 
11 
12 #include "G4SystemOfUnits.hh"
13 
14 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
15 
17  : _gunGenerator(gunGenerator) {
18 
19  G4String gunDir("/GGS/generatorActions/gun/");
20 
21  // Gun generator commands
22  _gunDir = new G4UIdirectory(gunDir.data());
23  _gunDir->SetGuidance("Gun primary generator control");
24  //
25  _checkAcceptance = new G4UIcmdWithAString((gunDir + "checkAcceptance").data(), this);
26  _checkAcceptance->SetGuidance(
27  "When random ON, shoot randomly inside detector volume (true) or in all random directions (false)");
28  _checkAcceptance->SetGuidance(" Choice : true (default), false");
29  _checkAcceptance->SetParameterName("insideAcceptance", true);
30  _checkAcceptance->SetDefaultValue("true");
31  _checkAcceptance->SetCandidates("true false");
32  _checkAcceptance->AvailableForStates(G4State_PreInit, G4State_Idle);
33  //
34  _positionCmd = new G4UIcmdWith3VectorAndUnit((gunDir + "position").data(), this);
35  _positionCmd->SetGuidance("If rndm off, starting position of the particle. Default units:[cm]");
36  _positionCmd->SetParameterName("x0", "y0", "z0", false);
37  _positionCmd->SetUnitCategory("Length");
38  _positionCmd->SetDefaultUnit("cm");
39  _positionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
40  //
41  _minPositionCmd = new G4UIcmdWith3VectorAndUnit((gunDir + "minPosition").data(), this);
42  _minPositionCmd->SetGuidance(
43  "If rndm on, Minimum range for uniform generation in [xmin,xmax] [ymin,ymax] [zmin,zmax] Def. units:[cm]");
44  _minPositionCmd->SetParameterName("xmin", "ymin", "zmin", false);
45  _minPositionCmd->SetUnitCategory("Length");
46  _minPositionCmd->SetDefaultUnit("cm");
47  _minPositionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
48  //
49  _maxPositionCmd = new G4UIcmdWith3VectorAndUnit((gunDir + "maxPosition").data(), this);
50  _maxPositionCmd->SetGuidance(
51  "If rndm on, Maximum range for uniform generation in [xmin,xmax] [ymin,ymax] [zmin,zmax] Def. units:[cm]");
52  _maxPositionCmd->SetParameterName("xmax", "ymax", "zmax", false);
53  _maxPositionCmd->SetUnitCategory("Length");
54  _maxPositionCmd->SetDefaultUnit("cm");
55  _maxPositionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
56  //
57  _energyCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "energy").data(), this);
58  _energyCmd->SetGuidance("If rndm off, set beam energy [GeV]");
59  _energyCmd->SetParameterName("energy", false);
60  _energyCmd->SetRange("energy>=0.");
61  _energyCmd->SetUnitCategory("Energy");
62  _energyCmd->SetDefaultUnit("GeV");
63  _energyCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
64  //
65  _minEnergyCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "minEnergy").data(), this);
66  _minEnergyCmd->SetGuidance("If rndm on, set minimum simulated energy [GeV]");
67  _minEnergyCmd->SetParameterName("minEnergy", false);
68  _minEnergyCmd->SetRange("minEnergy>=0.");
69  _minEnergyCmd->SetUnitCategory("Energy");
70  _minEnergyCmd->SetDefaultUnit("GeV");
71  _minEnergyCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
72  //
73  _maxEnergyCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "maxEnergy").data(), this);
74  _maxEnergyCmd->SetGuidance("If rndm on, set maximum simulated energy [GeV]");
75  _maxEnergyCmd->SetParameterName("maxEnergy", false);
76  _maxEnergyCmd->SetRange("maxEnergy>=0.");
77  _maxEnergyCmd->SetUnitCategory("Energy");
78  _maxEnergyCmd->SetDefaultUnit("GeV");
79  _maxEnergyCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
80  //
81  _spectralIndexCmd = new G4UIcmdWithADouble((gunDir + "spectralIndex").data(), this);
82  _spectralIndexCmd->SetGuidance(
83  "If rndm on, set spectral index for energy power law. If not defined then uniform simulation!");
84  _spectralIndexCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
85  //
86  _thetaCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "theta").data(), this);
87  _thetaCmd->SetGuidance("If rndm off, set theta angle [deg]");
88  _thetaCmd->SetParameterName("theta", false);
89  _thetaCmd->SetRange("theta>=0. && theta<=90.");
90  _thetaCmd->SetUnitCategory("Angle");
91  _thetaCmd->SetDefaultUnit("deg");
92  _thetaCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
93  //
94  _minThetaCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "minTheta").data(), this);
95  _minThetaCmd->SetGuidance(
96  "If rndm 'on', set min theta angle for uniform simulation in [minTheta,maxTheta]. Default unit: deg");
97  _minThetaCmd->SetParameterName("minTheta", false);
98  _minThetaCmd->SetUnitCategory("Angle");
99  _minThetaCmd->SetDefaultUnit("deg");
100  _minThetaCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
101  //
102  _maxThetaCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "maxTheta").data(), this);
103  _maxThetaCmd->SetGuidance(
104  "If rndm 'on', set max theta angle for uniform simulation in [minTheta,maxTheta]. Default unit: deg");
105  _maxThetaCmd->SetParameterName("maxTheta", false);
106  _maxThetaCmd->SetUnitCategory("Angle");
107  _maxThetaCmd->SetDefaultUnit("deg");
108  _maxThetaCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
109  //
110  _phiCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "phi").data(), this);
111  _phiCmd->SetGuidance("If rndm off, set phi angle [deg]");
112  _phiCmd->SetParameterName("Phi", false);
113  //_phiCmd ->SetRange("0.-360.");
114  _phiCmd->SetUnitCategory("Angle");
115  _phiCmd->SetDefaultUnit("deg");
116  _phiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
117  //
118  _minPhiCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "minPhi").data(), this);
119  _minPhiCmd->SetGuidance(
120  "If rndm 'on', set min Phi angle for uniform simulation in [minPhi,maxPhi]. Default unit: deg");
121  _minPhiCmd->SetParameterName("minPhi", false);
122  _minPhiCmd->SetUnitCategory("Angle");
123  _minPhiCmd->SetDefaultUnit("deg");
124  _minPhiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
125  //
126  _maxPhiCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "maxPhi").data(), this);
127  _maxPhiCmd->SetGuidance(
128  "If rndm 'on', set max Phi angle for uniform simulation in [minPhi,maxPhi]. Default unit: deg");
129  _maxPhiCmd->SetParameterName("maxPhi", false);
130  _maxPhiCmd->SetUnitCategory("Angle");
131  _maxPhiCmd->SetDefaultUnit("deg");
132  _maxPhiCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
133  //
134  _gunParticleCmd = new G4UIcmdWithAString((gunDir + "particle").data(), this);
135  _gunParticleCmd->SetGuidance("Particle to shoot.");
136  _gunParticleCmd->SetGuidance(" Eg. e+, proton, mu-");
137  _gunParticleCmd->SetParameterName("GunParticle", false);
138  _gunParticleCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
139  //
140  _sphereCenterCmd = new G4UIcmdWith3VectorAndUnit((gunDir + "sphereCenter").data(), this);
141  _sphereCenterCmd->SetGuidance("Center of generation sphere. Default unit: cm");
142  _sphereCenterCmd->SetParameterName("sphereCenterX", "sphereCenterY", "sphereCenterZ", false);
143  _sphereCenterCmd->SetUnitCategory("Length");
144  _sphereCenterCmd->SetDefaultUnit("cm");
145  _sphereCenterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
146  //
147  _sphereCapPositionCmd = new G4UIcmdWith3VectorAndUnit((gunDir + "sphereCapPosition").data(), this);
148  _sphereCapPositionCmd->SetGuidance("Position of the center of the spherical cap particle generator with respect to "
149  "the sphere center. Default unit: cm");
150  _sphereCapPositionCmd->SetParameterName("sphereCapPositionX", "sphereCapPositionY", "sphereCapPositionZ", false);
151  _sphereCapPositionCmd->SetUnitCategory("Length");
152  _sphereCapPositionCmd->SetDefaultUnit("cm");
153  _sphereCapPositionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
154 
155  _sphereCapExtensionCmd = new G4UIcmdWithADoubleAndUnit((gunDir + "sphereCapExtension").data(), this);
156  _sphereCapExtensionCmd->SetGuidance("Angular half-width of the spherical cap particle generator with respect to the "
157  "sphere center. Default unit: deg");
158  _sphereCapExtensionCmd->SetParameterName("sphereCapExtension", false);
159  _sphereCapExtensionCmd->SetUnitCategory("Angle");
160  _sphereCapExtensionCmd->SetDefaultUnit("deg");
161  _sphereCapExtensionCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
162 }
163 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
165 
167  delete _checkAcceptance;
168  delete _positionCmd;
169  delete _minPositionCmd;
170  delete _maxPositionCmd;
171  delete _energyCmd;
172  delete _minEnergyCmd;
173  delete _maxEnergyCmd;
174  delete _spectralIndexCmd;
175  delete _thetaCmd;
176  delete _minThetaCmd;
177  delete _maxThetaCmd;
178  delete _phiCmd;
179  delete _minPhiCmd;
180  delete _maxPhiCmd;
181  delete _gunDir;
182  delete _gunParticleCmd;
183  delete _sphereCenterCmd;
184  delete _sphereCapPositionCmd;
185  delete _sphereCapExtensionCmd;
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 
190 void GGSGunGeneratorActionMessenger::SetNewValue(G4UIcommand *command, G4String newValue) {
191 
192  if (command == _checkAcceptance) {
193  if (newValue == "true") {
194  _gunGenerator->SetAcceptanceFlag(1);
195  } else {
196  _gunGenerator->SetAcceptanceFlag(0);
197  }
198  }
199 
200  if (command == _positionCmd) {
201  _gunGenerator->SetPosition(_positionCmd->GetNew3VectorValue(newValue));
202  }
203 
204  if (command == _minPositionCmd) {
205  _gunGenerator->SetMinPosition(_minPositionCmd->GetNew3VectorValue(newValue));
206  }
207 
208  if (command == _maxPositionCmd) {
209  _gunGenerator->SetMaxPosition(_maxPositionCmd->GetNew3VectorValue(newValue));
210  }
211 
212  if (command == _sphereCenterCmd) {
213  _gunGenerator->SetSphereCenter(_sphereCenterCmd->GetNew3VectorValue(newValue));
214  }
215 
216  if (command == _sphereCapPositionCmd) {
217  _gunGenerator->SetSphereCapPosition(_sphereCapPositionCmd->GetNew3VectorValue(newValue));
218  }
219 
220  if (command == _sphereCapExtensionCmd) {
221  _gunGenerator->SetSphereCapExtension(_sphereCapExtensionCmd->GetNewDoubleValue(newValue) * rad);
222  }
223 
224  if (command == _energyCmd) {
225  _gunGenerator->SetEnergy(_energyCmd->GetNewDoubleValue(newValue));
226  }
227 
228  if (command == _minEnergyCmd) {
229  _gunGenerator->SetMinEnergy(_minEnergyCmd->GetNewDoubleValue(newValue));
230  _gunGenerator->SetRndmMinEnergyFlag(true);
231  }
232 
233  if (command == _maxEnergyCmd) {
234  _gunGenerator->SetMaxEnergy(_maxEnergyCmd->GetNewDoubleValue(newValue));
235  _gunGenerator->SetRndmMaxEnergyFlag(true);
236  }
237 
238  if (command == _spectralIndexCmd) {
239  _gunGenerator->SetSpectralIndex(_spectralIndexCmd->GetNewDoubleValue(newValue));
240  _gunGenerator->SetSpectralIndexFlag(true);
241  }
242 
243  if (command == _thetaCmd) {
244  _gunGenerator->SetTheta(_thetaCmd->GetNewDoubleValue(newValue) * rad);
245  }
246 
247  if (command == _minThetaCmd) {
248  _gunGenerator->SetMinTheta(_minThetaCmd->GetNewDoubleValue(newValue) * rad);
249  }
250 
251  if (command == _maxThetaCmd) {
252  _gunGenerator->SetMaxTheta(_maxThetaCmd->GetNewDoubleValue(newValue) * rad);
253  }
254 
255  if (command == _phiCmd) {
256  _gunGenerator->SetPhi(_phiCmd->GetNewDoubleValue(newValue) * rad);
257  }
258 
259  if (command == _minPhiCmd) {
260  _gunGenerator->SetMinPhi(_minPhiCmd->GetNewDoubleValue(newValue) * rad);
261  }
262 
263  if (command == _maxPhiCmd) {
264  _gunGenerator->SetMaxPhi(_maxPhiCmd->GetNewDoubleValue(newValue) * rad);
265  }
266 
267  if (command == _gunParticleCmd) {
268  _gunGenerator->SetGunParticle(newValue);
269  }
270 }
271 
272 //....oooOO0OOooo........oooOO0OOooo........oooO0OOooo........oooOO0OOooo......
void SetEnergy(G4double val)
Sets the particle&#39;s kinetic energy.
void SetMinTheta(G4double val)
Sets the minimum random value for theta.
void SetPosition(const G4ThreeVector &val)
Sets the particle&#39;s generation position.
void SetMinEnergy(G4double val)
Sets the particle&#39;s min kinetic energy.
void SetRndmMaxEnergyFlag(G4bool val)
Sets the max energy flag.
void SetNewValue(G4UIcommand *command, G4String newValue)
Concrete implementation of the SetNewValue methd of base class.
void SetRndmMinEnergyFlag(G4bool val)
Sets the min energy flag.
void SetSpectralIndex(G4double val)
Sets the spectral index.
void SetSphereCenter(const G4ThreeVector &val)
Sets the center of the spherical surface.
void SetAcceptanceFlag(G4bool val)
Set the acceptance control.
void SetPhi(G4double val)
Sets the value for phi.
void SetMaxPhi(G4double val)
Sets the maximum value for phi.
A single-particle generator.
void SetMaxTheta(G4double val)
Sets the maximum random value for theta.
void SetGunParticle(const G4String &particle)
Sets the particle to be used by G4ParticleGun.
void SetMinPosition(const G4ThreeVector &val)
Sets the particle&#39;s minimum generation position.
void SetTheta(G4double val)
Sets the value for theta.
void SetSphereCapPosition(const G4ThreeVector &val)
Sets the position of the spherical cap on the sphere.
void SetMaxPosition(const G4ThreeVector &val)
Sets the particle&#39;s maximum generation position.
void SetSphereCapExtension(G4double val)
Sets the extension of the spherical cap.
void SetMaxEnergy(G4double val)
Sets the particle&#39;s max kinetic energy.
GGSGunGeneratorActionMessenger(GGSGunGeneratorAction *gunGenerator)
Constructor.
void SetSpectralIndexFlag(G4bool val)
Sets the spectral index geeration.
void SetMinPhi(G4double val)
Sets the minimum value for phi.