GGS(GenericGEANT4Simulation)Software  2.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSGunGeneratorAction.h
Go to the documentation of this file.
1 /*
2  * GGSGunGeneratorAction.h
3  *
4  * Created on: 09 Oct 2013
5  * Author: Nicola Mori
6  */
7 
10 #ifndef GGSGUNGENERATORACTION_H_
11 #define GGSGUNGENERATORACTION_H_
12 
14 
15 #include "globals.hh"
16 #include "G4ThreeVector.hh"
17 #include "G4RotationMatrix.hh"
18 
19 class G4ParticleGun;
21 
27 public:
28 
31 
34 
40  void GeneratePrimaries(G4Event*);
41 
52  void SetAcceptanceFlag(G4bool val) {
53  _acceptanceFlag = val;
54  }
55 
65  void SetRndmMinEnergyFlag(G4bool val) {
66  _rndmMinEnergyFlag = val;
67  }
68 
78  void SetRndmMaxEnergyFlag(G4bool val) {
79  _rndmMaxEnergyFlag = val;
80  }
81 
91  void SetSpectralIndexFlag(G4bool val) {
92  _spectralIndexFlag = val;
93  }
94 
102  void SetEnergy(G4double val) {
103  _energy = val;
104  }
105 
114  void SetMinEnergy(G4double val) {
115  _minEnergy = val;
116  }
117 
126  void SetMaxEnergy(G4double val) {
127  _maxEnergy = val;
128  }
129 
139  void SetSpectralIndex(G4double val) {
140  _spectralIndex = val;
141  }
142 
150  void SetPosition(const G4ThreeVector &val) {
151  _position = val;
152  // Reset random position generation
153  _rndmMinPositionFlag = _rndmMaxPositionFlag = false;
154  _SetRndmPosFlag();
155  _SetRndmFromSurface(0);
156  }
157 
167  void SetMinPosition(const G4ThreeVector &val) {
168  _minPosition = val;
169  _rndmMinPositionFlag = true;
170  _SetRndmPosFlag();
171  _SetRndmFromSurface(1);
172  }
173 
183  void SetMaxPosition(const G4ThreeVector &val) {
184  _maxPosition = val;
185  _rndmMaxPositionFlag = true;
186  _SetRndmPosFlag();
187  _SetRndmFromSurface(1);
188  }
189 
199  void SetSphereCenter(const G4ThreeVector &val) {
200  _rndmSphereCenter = val;
201  _SetRndmFromSurface(2);
202  }
203 
215  void SetSphereCapPosition(const G4ThreeVector &val) {
216  _rndmSphereRadius = val.mag();
217  _rndmSphereCapAlpha = acos(val[2] / _rndmSphereRadius);
218  _rndmSphereCapBeta = atan2(val[1], val[0]);
219  _SetRndmFromSurface(2);
220  }
221 
231  void SetSphereCapExtension(G4double val) {
232  _rndmSphereCapExtRand = (1. - cos(val)) / 2.;
233  _SetRndmFromSurface(2);
234  }
235 
245  void SetTheta(G4double val) {
246  _sinTheta = sin(val);
247  _cosTheta = cos(val);
248  _rndmMinThetaFlag = _rndmMaxThetaFlag = false;
249  _SetRndmDirFlag();
250  _SetShootingDir();
251 
252  }
253 
264  void SetMinTheta(G4double val) {
265  _minThetaRand = (1. - cos(val)) / 2.;
266  _maxCos2ThetaRand = cos(val);
267  _maxCos2ThetaRand *= _maxCos2ThetaRand;
268  _rndmMinThetaFlag = true;
269  _SetRndmDirFlag();
270  }
271 
280  void SetMaxTheta(G4double val) {
281  _maxThetaRand = (1. - cos(val)) / 2.;
282  _minCos2ThetaRand = cos(val);
283  _minCos2ThetaRand *= _minCos2ThetaRand;
284  _rndmMaxThetaFlag = true;
285  _SetRndmDirFlag();
286  }
287 
297  void SetPhi(G4double val) {
298  _sinPhi = sin(val);
299  _cosPhi = cos(val);
300  _rndmMinPhiFlag = _rndmMaxPhiFlag = false;
301  _SetRndmDirFlag();
302  _SetShootingDir();
303  }
304 
313  void SetMinPhi(G4double val) {
314  _minPhi = val;
315  _rndmMinPhiFlag = true;
316  _SetRndmDirFlag();
317  }
318 
327  void SetMaxPhi(G4double val) {
328  _maxPhi = val;
329  _rndmMaxPhiFlag = true;
330  _SetRndmDirFlag();
331  }
332 
337  void SetGunParticle(const G4String &particle);
338 
339 private:
340 
341  // Methods
342 
351  void _SetRndmFromSurface(int surfType);
352 
353  // These functions reset (ie., disable) the random generation on surfaces
354  void _ResetFlat();
355  void _ResetSphere();
356 
370  G4RotationMatrix& _ComputeRotMatrix(double cosAlpha, double sinAlpha, double cosBeta, double sinBeta);
371 
373  void _SetRndmDirFlag();
374 
376  void _SetRndmPosFlag();
377 
382  void _SetShootingDir() {
383  _direction[0] = -_sinTheta * _cosPhi; // momentum direction (unit vectors)
384  _direction[1] = -_sinTheta * _sinPhi;
385  _direction[2] = -_cosTheta; // along -z
386  }
387 
398  G4double _GenSpectrumPowerLaw(G4double Emin, G4double Emax, G4double gamma);
399 
400  // Members
401 
402  GGSGunGeneratorActionMessenger* _messenger; //messenger of this class
403 
404  G4ParticleGun *_gunGenerator; // The wrapped standard gun generator
405 
406  G4ThreeVector _shootAxis;
407  G4bool _acceptanceFlag; // if true, acceptance check will be performed
408  G4bool _rndmMinPositionFlag;
409  G4bool _rndmMaxPositionFlag;
410  G4bool _rndmFromFlat;
411  G4bool _rndmFromSphere;
412  G4ThreeVector _rndmSphereCenter;
413  G4double _rndmSphereCapExtRand; // Minimum value for random sampling of polar angle for position std::vector on the spherical cap
414  G4double _rndmSphereCapAlpha; // Polar angle of _rndmSphereCapPos
415  G4double _rndmSphereCapBeta; // Azimuth angle of _rndmSphereCapPos
416  G4RotationMatrix _rndmSphereCapRotMat; // Rotation from cap frame to absolute frame
417  G4double _rndmSphereRadius;
418  G4bool _rndmMinEnergyFlag;
419  G4bool _rndmMaxEnergyFlag;
420  G4bool _spectralIndexFlag;
421  G4bool _rndmMinThetaFlag;
422  G4bool _rndmMaxThetaFlag;
423  G4bool _rndmMinPhiFlag;
424  G4bool _rndmMaxPhiFlag;
425  G4bool _rndmPosFlag; // Flag for random generation point
426  G4bool _rndmDirFlag; // Flag for random generation direction
427 
428  G4ThreeVector _position;
429  G4ThreeVector _minPosition;
430  G4ThreeVector _maxPosition;
431  G4double _energy;
432  G4double _minEnergy;
433  G4double _maxEnergy;
434  G4double _spectralIndex;
435  G4double _sinTheta, _cosTheta;
436  G4double _minThetaRand, _maxThetaRand;
437  G4double _minCos2ThetaRand, _maxCos2ThetaRand;
438  G4double _sinPhi, _cosPhi;
439  G4double _minPhi;
440  G4double _maxPhi;
441  G4ThreeVector _direction; // Computed automatically given theta and phi
442 };
443 
444 #endif /* GGSGUNGENERATORACTION_H_ */
void SetEnergy(G4double val)
Sets the particle's kinetic energy.
void SetMinTheta(G4double val)
Sets the minimum random value for theta.
void SetPosition(const G4ThreeVector &val)
Sets the particle's generation position.
GGSGunGeneratorAction()
Constructor.
void SetMinEnergy(G4double val)
Sets the particle's min kinetic energy.
void SetRndmMaxEnergyFlag(G4bool val)
Sets the max energy flag.
Base class for GGS generator actions.
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.
Messenger class for gun generator action.
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'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's maximum generation position.
void SetSphereCapExtension(G4double val)
Sets the extension of the spherical cap.
void GeneratePrimaries(G4Event *)
GeneratePrimaries.
void SetMaxEnergy(G4double val)
Sets the particle's max kinetic energy.
void SetSpectralIndexFlag(G4bool val)
Sets the spectral index geeration.
void SetMinPhi(G4double val)
Sets the minimum value for phi.