GGS(GenericGEANT4Simulation)Software  2.6.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(
149  "Position of the center of the spherical cap particle generator with respect to 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(
157  "Angular half-width of the spherical cap particle generator with respect to the 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 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
166 
168  delete _checkAcceptance;
169  delete _positionCmd;
170  delete _minPositionCmd;
171  delete _maxPositionCmd;
172  delete _energyCmd;
173  delete _minEnergyCmd;
174  delete _maxEnergyCmd;
175  delete _spectralIndexCmd;
176  delete _thetaCmd;
177  delete _minThetaCmd;
178  delete _maxThetaCmd;
179  delete _phiCmd;
180  delete _minPhiCmd;
181  delete _maxPhiCmd;
182  delete _gunDir;
183  delete _gunParticleCmd;
184  delete _sphereCenterCmd;
185  delete _sphereCapPositionCmd;
186  delete _sphereCapExtensionCmd;
187 }
188 
189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
190 
191 void GGSGunGeneratorActionMessenger::SetNewValue(G4UIcommand* command, G4String newValue) {
192 
193  if (command == _checkAcceptance) {
194  if (newValue == "true") {
195  _gunGenerator->SetAcceptanceFlag(1);
196  }
197  else {
198  _gunGenerator->SetAcceptanceFlag(0);
199  }
200  }
201 
202  if (command == _positionCmd) {
203  _gunGenerator->SetPosition(_positionCmd->GetNew3VectorValue(newValue));
204  }
205 
206  if (command == _minPositionCmd) {
207  _gunGenerator->SetMinPosition(_minPositionCmd->GetNew3VectorValue(newValue));
208 
209  }
210 
211  if (command == _maxPositionCmd) {
212  _gunGenerator->SetMaxPosition(_maxPositionCmd->GetNew3VectorValue(newValue));
213  }
214 
215  if (command == _sphereCenterCmd) {
216  _gunGenerator->SetSphereCenter(_sphereCenterCmd->GetNew3VectorValue(newValue));
217  }
218 
219  if (command == _sphereCapPositionCmd) {
220  _gunGenerator->SetSphereCapPosition(_sphereCapPositionCmd->GetNew3VectorValue(newValue));
221  }
222 
223  if (command == _sphereCapExtensionCmd) {
224  _gunGenerator->SetSphereCapExtension(_sphereCapExtensionCmd->GetNewDoubleValue(newValue) * rad);
225  }
226 
227  if (command == _energyCmd) {
228  _gunGenerator->SetEnergy(_energyCmd->GetNewDoubleValue(newValue));
229  }
230 
231  if (command == _minEnergyCmd) {
232  _gunGenerator->SetMinEnergy(_minEnergyCmd->GetNewDoubleValue(newValue));
233  _gunGenerator->SetRndmMinEnergyFlag(true);
234  }
235 
236  if (command == _maxEnergyCmd) {
237  _gunGenerator->SetMaxEnergy(_maxEnergyCmd->GetNewDoubleValue(newValue));
238  _gunGenerator->SetRndmMaxEnergyFlag(true);
239  }
240 
241  if (command == _spectralIndexCmd) {
242  _gunGenerator->SetSpectralIndex(_spectralIndexCmd->GetNewDoubleValue(newValue));
243  _gunGenerator->SetSpectralIndexFlag(true);
244  }
245 
246  if (command == _thetaCmd) {
247  _gunGenerator->SetTheta(_thetaCmd->GetNewDoubleValue(newValue) * rad);
248  }
249 
250  if (command == _minThetaCmd) {
251  _gunGenerator->SetMinTheta(_minThetaCmd->GetNewDoubleValue(newValue) * rad);
252  }
253 
254  if (command == _maxThetaCmd) {
255  _gunGenerator->SetMaxTheta(_maxThetaCmd->GetNewDoubleValue(newValue) * rad);
256  }
257 
258  if (command == _phiCmd) {
259  _gunGenerator->SetPhi(_phiCmd->GetNewDoubleValue(newValue) * rad);
260  }
261 
262  if (command == _minPhiCmd) {
263  _gunGenerator->SetMinPhi(_minPhiCmd->GetNewDoubleValue(newValue) * rad);
264  }
265 
266  if (command == _maxPhiCmd) {
267  _gunGenerator->SetMaxPhi(_maxPhiCmd->GetNewDoubleValue(newValue) * rad);
268  }
269 
270  if (command == _gunParticleCmd) {
271  _gunGenerator->SetGunParticle(newValue);
272  }
273 
274 }
275 
276 //....oooOO0OOooo........oooOO0OOooo........oooO0OOooo........oooOO0OOooo......
277 
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.