Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimaryGeneratorAction2 Class Reference

#include <PrimaryGeneratorAction2.hh>

Public Member Functions

 PrimaryGeneratorAction2 (G4ParticleGun *)
 
 ~PrimaryGeneratorAction2 ()
 
void GeneratePrimaries (G4Event *)
 
G4double RejectAccept ()
 
G4double InverseCumul ()
 

Detailed Description

Definition at line 47 of file PrimaryGeneratorAction2.hh.

Constructor & Destructor Documentation

PrimaryGeneratorAction2::PrimaryGeneratorAction2 ( G4ParticleGun gun)

Definition at line 48 of file PrimaryGeneratorAction2.cc.

49 : fParticleGun(gun)
50 {
51  // energy distribution
52  //
53  InitFunction();
54 }
PrimaryGeneratorAction2::~PrimaryGeneratorAction2 ( )

Definition at line 58 of file PrimaryGeneratorAction2.cc.

59 { }

Member Function Documentation

void PrimaryGeneratorAction2::GeneratePrimaries ( G4Event anEvent)

Definition at line 63 of file PrimaryGeneratorAction2.cc.

64 {
65  //cosAlpha uniform in [cos(0), cos(pi)]
66  G4double cosAlpha = 1. - 2*G4UniformRand();
67  G4double sinAlpha = std::sqrt(1. - cosAlpha*cosAlpha);
68  G4double psi = twopi*G4UniformRand(); //psi uniform in [0, 2*pi]
69  G4ThreeVector dir(sinAlpha*std::cos(psi),sinAlpha*std::sin(psi),cosAlpha);
70 
71  fParticleGun->SetParticleMomentumDirection(dir);
72 
73  //set energy from a tabulated distribution
74  //
75  //G4double energy = RejectAccept();
77  fParticleGun->SetParticleEnergy(energy);
78 
79  //create vertex
80  //
81  fParticleGun->GeneratePrimaryVertex(anEvent);
82 }
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
static constexpr double twopi
Definition: G4SIunits.hh:76
#define G4UniformRand()
Definition: Randomize.hh:97
void SetParticleEnergy(G4double aKineticEnergy)
G4double energy(const ThreeVector &p, const G4double m)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4double PrimaryGeneratorAction2::InverseCumul ( )

Definition at line 148 of file PrimaryGeneratorAction2.cc.

149 {
150  // tabulated function
151  // Y is assumed positive, linear per segment, continuous
152  // --> cumulative function is second order polynomial
153 
154  //choose y randomly
155  G4double Yrndm = G4UniformRand()*fYC[fNPoints-1];
156  //find bin
157  G4int j = fNPoints-2;
158  while ((fYC[j] > Yrndm) && (j > 0)) j--;
159  //y_rndm --> x_rndm : fYC(x) is second order polynomial
160  G4double Xrndm = fX[j];
161  G4double a = fSlp[j];
162  if (a != 0.) {
163  G4double b = fY[j]/a, c = 2*(Yrndm - fYC[j])/a;
164  G4double delta = b*b + c;
165  G4int sign = 1; if (a < 0.) sign = -1;
166  Xrndm += sign*std::sqrt(delta) - b;
167  } else if (fY[j] > 0.) {
168  Xrndm += (Yrndm - fYC[j])/fY[j];
169  };
170  return Xrndm;
171 }
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
int G4int
Definition: G4Types.hh:78
tuple b
Definition: test.py:12
#define G4UniformRand()
Definition: Randomize.hh:97
double G4double
Definition: G4Types.hh:76
tuple c
Definition: test.py:13
G4int sign(const T t)

Here is the call graph for this function:

Here is the caller graph for this function:

G4double PrimaryGeneratorAction2::RejectAccept ( )

Definition at line 126 of file PrimaryGeneratorAction2.cc.

127 {
128  // tabulated function
129  // Y is assumed positive, linear per segment, continuous
130  //
131  G4double Xrndm = 0., Yrndm = 0., Yinter = -1.;
132 
133  while (Yrndm > Yinter) {
134  //choose a point randomly
135  Xrndm = fX[0] + G4UniformRand()*(fX[fNPoints-1] - fX[0]);
136  Yrndm = G4UniformRand()*fYmax;
137  //find bin
138  G4int j = fNPoints-2;
139  while ((fX[j] > Xrndm) && (j > 0)) j--;
140  //compute Y(x_rndm) by linear interpolation
141  Yinter = fY[j] + fSlp[j]*(Xrndm - fX[j]);
142  };
143  return Xrndm;
144 }
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:97
double G4double
Definition: G4Types.hh:76

The documentation for this class was generated from the following files: