GGS(GenericGEANT4Simulation)Software  2.7.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 "G4RotationMatrix.hh"
16 #include "G4ThreeVector.hh"
17 #include "globals.hh"
18 
19 class G4ParticleGun;
21 
27 public:
30 
33 
39  void GeneratePrimaries(G4Event *);
40 
51  void SetAcceptanceFlag(G4bool val) { _acceptanceFlag = val; }
52 
62  void SetRndmMinEnergyFlag(G4bool val) { _rndmMinEnergyFlag = val; }
63 
73  void SetRndmMaxEnergyFlag(G4bool val) { _rndmMaxEnergyFlag = val; }
74 
84  void SetSpectralIndexFlag(G4bool val) { _spectralIndexFlag = val; }
85 
93  void SetEnergy(G4double val) { _energy = val; }
94 
103  void SetMinEnergy(G4double val) { _minEnergy = val; }
104 
113  void SetMaxEnergy(G4double val) { _maxEnergy = val; }
114 
124  void SetSpectralIndex(G4double val) { _spectralIndex = val; }
125 
133  void SetPosition(const G4ThreeVector &val) {
134  _position = val;
135  // Reset random position generation
136  _rndmMinPositionFlag = _rndmMaxPositionFlag = false;
137  _SetRndmPosFlag();
138  _SetRndmFromSurface(0);
139  }
140 
150  void SetMinPosition(const G4ThreeVector &val) {
151  _minPosition = val;
152  _rndmMinPositionFlag = true;
153  _SetRndmPosFlag();
154  _SetRndmFromSurface(1);
155  }
156 
166  void SetMaxPosition(const G4ThreeVector &val) {
167  _maxPosition = val;
168  _rndmMaxPositionFlag = true;
169  _SetRndmPosFlag();
170  _SetRndmFromSurface(1);
171  }
172 
182  void SetSphereCenter(const G4ThreeVector &val) {
183  _rndmSphereCenter = val;
184  _SetRndmFromSurface(2);
185  }
186 
198  void SetSphereCapPosition(const G4ThreeVector &val) {
199  _rndmSphereCapPosition = val;
200  _rndmSphereRadius = val.mag();
201  _rndmSphereCapAlpha = acos(val[2] / _rndmSphereRadius);
202  _rndmSphereCapBeta = atan2(val[1], val[0]);
203  _SetRndmFromSurface(2);
204  }
205 
215  void SetSphereCapExtension(G4double val) {
216  _rndmSphereCapExtRand = (1. - cos(val)) / 2.;
217  _SetRndmFromSurface(2);
218  }
219 
229  void SetTheta(G4double val) {
230  _sinTheta = sin(val);
231  _cosTheta = cos(val);
232  _rndmMinThetaFlag = _rndmMaxThetaFlag = false;
233  _SetRndmDirFlag();
234  _SetShootingDir();
235  }
236 
247  void SetMinTheta(G4double val) {
248  _minThetaRand = (1. - cos(val)) / 2.;
249  _maxCos2ThetaRand = cos(val);
250  _maxCos2ThetaRand *= _maxCos2ThetaRand;
251  _rndmMinThetaFlag = true;
252  _SetRndmDirFlag();
253  }
254 
263  void SetMaxTheta(G4double val) {
264  _maxThetaRand = (1. - cos(val)) / 2.;
265  _minCos2ThetaRand = cos(val);
266  _minCos2ThetaRand *= _minCos2ThetaRand;
267  _rndmMaxThetaFlag = true;
268  _SetRndmDirFlag();
269  }
270 
280  void SetPhi(G4double val) {
281  _sinPhi = sin(val);
282  _cosPhi = cos(val);
283  _rndmMinPhiFlag = _rndmMaxPhiFlag = false;
284  _SetRndmDirFlag();
285  _SetShootingDir();
286  }
287 
296  void SetMinPhi(G4double val) {
297  _minPhi = val;
298  _rndmMinPhiFlag = true;
299  _SetRndmDirFlag();
300  }
301 
310  void SetMaxPhi(G4double val) {
311  _maxPhi = val;
312  _rndmMaxPhiFlag = true;
313  _SetRndmDirFlag();
314  }
315 
320  void SetGunParticle(const G4String &particle);
321 
375 
376 private:
377  // Methods
378 
387  void _SetRndmFromSurface(int surfType);
388 
389  // These functions reset (ie., disable) the random generation on surfaces
390  void _ResetFlat();
391  void _ResetSphere();
392 
406  G4RotationMatrix &_ComputeRotMatrix(double cosAlpha, double sinAlpha, double cosBeta, double sinBeta);
407 
409  void _SetRndmDirFlag();
410 
412  void _SetRndmPosFlag();
413 
418  void _SetShootingDir() {
419  _direction[0] = -_sinTheta * _cosPhi; // momentum direction (unit vectors)
420  _direction[1] = -_sinTheta * _sinPhi;
421  _direction[2] = -_cosTheta; // along -z
422  }
423 
434  G4double _GenSpectrumPowerLaw(G4double Emin, G4double Emax, G4double gamma);
435 
436  // Members
437 
438  GGSGunGeneratorActionMessenger *_messenger; // messenger of this class
439 
440  G4ParticleGun *_gunGenerator; // The wrapped standard gun generator
441 
442  G4ThreeVector _shootAxis;
443  G4bool _acceptanceFlag; // if true, acceptance check will be performed
444  G4bool _rndmMinPositionFlag;
445  G4bool _rndmMaxPositionFlag;
446  G4bool _rndmFromFlat;
447  G4bool _rndmFromSphere;
448  G4ThreeVector _rndmSphereCenter;
449  G4ThreeVector _rndmSphereCapPosition;
450  G4double _rndmSphereCapExtRand; // Minimum value for random sampling of polar angle for position std::vector on the
451  // spherical cap
452  G4double _rndmSphereCapAlpha; // Polar angle of _rndmSphereCapPos
453  G4double _rndmSphereCapBeta; // Azimuth angle of _rndmSphereCapPos
454  G4RotationMatrix _rndmSphereCapRotMat; // Rotation from cap frame to absolute frame
455  G4double _rndmSphereRadius;
456  G4bool _rndmMinEnergyFlag;
457  G4bool _rndmMaxEnergyFlag;
458  G4bool _spectralIndexFlag;
459  G4bool _rndmMinThetaFlag;
460  G4bool _rndmMaxThetaFlag;
461  G4bool _rndmMinPhiFlag;
462  G4bool _rndmMaxPhiFlag;
463  G4bool _rndmPosFlag; // Flag for random generation point
464  G4bool _rndmDirFlag; // Flag for random generation direction
465 
466  G4ThreeVector _position;
467  G4ThreeVector _minPosition;
468  G4ThreeVector _maxPosition;
469  G4double _energy;
470  G4double _minEnergy;
471  G4double _maxEnergy;
472  G4double _spectralIndex;
473  G4double _sinTheta, _cosTheta;
474  G4double _minThetaRand, _maxThetaRand;
475  G4double _minCos2ThetaRand, _maxCos2ThetaRand;
476  G4double _sinPhi, _cosPhi;
477  G4double _minPhi;
478  G4double _maxPhi;
479  G4ThreeVector _direction; // Computed automatically given theta and phi
480 };
481 
482 #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.
Class for storing parameters.
Definition: GGSParameters.h:29
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.
GGSParameters GetParameters() const
Gets the generation parameters.
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.