Geant4  10.02.p03
PrimaryGeneratorAction2 Class Reference

#include <PrimaryGeneratorAction2.hh>

Collaboration diagram for PrimaryGeneratorAction2:

Public Member Functions

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

Private Member Functions

void InitFunction ()
 

Private Attributes

G4ParticleGunparticleGun
 
G4int nPoints
 
std::vector< G4doublex
 
std::vector< G4doublef
 
std::vector< G4doublea
 
std::vector< G4doubleFc
 
G4double fMax
 

Detailed Description

Definition at line 47 of file PrimaryGeneratorAction2.hh.

Constructor & Destructor Documentation

◆ PrimaryGeneratorAction2()

PrimaryGeneratorAction2::PrimaryGeneratorAction2 ( G4ParticleGun gun)

Definition at line 48 of file PrimaryGeneratorAction2.cc.

49 : particleGun(gun)
50 {
51  // energy distribution
52  //
53  InitFunction();
54 }
Here is the call graph for this function:

◆ ~PrimaryGeneratorAction2()

PrimaryGeneratorAction2::~PrimaryGeneratorAction2 ( )

Definition at line 58 of file PrimaryGeneratorAction2.cc.

59 { }

Member Function Documentation

◆ GeneratePrimaries()

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 
72 
73  //set energy from a tabulated distribution
74  //
75  //G4double energy = RejectAccept();
78 
79  //create vertex
80  //
82 }
TDirectory * dir
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
#define G4UniformRand()
Definition: Randomize.hh:97
double energy
Definition: plottest35.C:25
static const double twopi
Definition: G4SIunits.hh:75
void SetParticleEnergy(G4double aKineticEnergy)
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:

◆ InitFunction()

void PrimaryGeneratorAction2::InitFunction ( )
private

Definition at line 85 of file PrimaryGeneratorAction2.cc.

86 {
87  // tabulated function
88  // f is assumed positive, linear per segment, continuous
89  //
90  nPoints = 16;
91  const G4double xx[] =
92  { 37*keV, 39*keV, 45*keV, 51*keV, 57*keV, 69*keV, 71*keV, 75*keV,
93  83*keV, 91*keV, 97*keV, 107*keV, 125*keV, 145*keV, 159*keV, 160*keV };
94 
95  const G4double ff[] =
96  { 0.000, 0.077, 0.380, 2.044, 5.535, 15.077, 12.443, 14.766,
97  17.644, 18.518, 17.772, 14.776, 8.372, 3.217, 0.194, 0.000 };
98 
99  //copy arrays in std::vector and compute fMax
100  //
101  x.resize(nPoints); f.resize(nPoints);
102  fMax = 0.;
103  for (G4int j=0; j<nPoints; j++) {
104  x[j] = xx[j]; f[j] = ff[j];
105  if (fMax < f[j]) fMax = f[j];
106  };
107 
108  //compute slopes
109  //
110  a.resize(nPoints);
111  for (G4int j=0; j<nPoints-1; j++) {
112  a[j] = (f[j+1] - f[j])/(x[j+1] - x[j]);
113  };
114 
115  //compute cumulative function
116  //
117  Fc.resize(nPoints);
118  Fc[0] = 0.;
119  for (G4int j=1; j<nPoints; j++) {
120  Fc[j] = Fc[j-1] + 0.5*(f[j] + f[j-1])*(x[j] - x[j-1]);
121  };
122 }
TFile ff[ntarg]
Double_t xx
std::vector< G4double > a
int G4int
Definition: G4Types.hh:78
std::vector< G4double > x
std::vector< G4double > Fc
std::vector< G4double > f
static const double keV
Definition: G4SIunits.hh:213
double G4double
Definition: G4Types.hh:76
Here is the caller graph for this function:

◆ InverseCumul()

G4double PrimaryGeneratorAction2::InverseCumul ( )

Definition at line 148 of file PrimaryGeneratorAction2.cc.

149 {
150  // tabulated function
151  // f is assumed positive, linear per segment, continuous
152  // --> cumulative function is second order polynomial
153 
154  //choose y randomly
155  G4double y_rndm = G4UniformRand()*Fc[nPoints-1];
156  //find bin
157  G4int j = nPoints-2;
158  while ((Fc[j] > y_rndm) && (j > 0)) j--;
159  //y_rndm --> x_rndm : Fc(x) is second order polynomial
160  G4double x_rndm = x[j];
161  G4double aa = a[j];
162  if (aa != 0.) {
163  G4double b = f[j]/aa, c = 2*(y_rndm - Fc[j])/aa;
164  G4double delta = b*b + c;
165  G4int sign = 1; if (aa < 0.) sign = -1;
166  x_rndm += sign*std::sqrt(delta) - b;
167  } else if (f[j] > 0.) {
168  x_rndm += (y_rndm - Fc[j])/f[j];
169  };
170  return x_rndm;
171 }
std::vector< G4double > a
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:97
std::vector< G4double > x
std::vector< G4double > Fc
std::vector< G4double > f
double G4double
Definition: G4Types.hh:76
G4int sign(const T t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RejectAccept()

G4double PrimaryGeneratorAction2::RejectAccept ( )

Definition at line 126 of file PrimaryGeneratorAction2.cc.

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

Member Data Documentation

◆ a

std::vector<G4double> PrimaryGeneratorAction2::a
private

Definition at line 66 of file PrimaryGeneratorAction2.hh.

◆ f

std::vector<G4double> PrimaryGeneratorAction2::f
private

Definition at line 65 of file PrimaryGeneratorAction2.hh.

◆ Fc

std::vector<G4double> PrimaryGeneratorAction2::Fc
private

Definition at line 67 of file PrimaryGeneratorAction2.hh.

◆ fMax

G4double PrimaryGeneratorAction2::fMax
private

Definition at line 68 of file PrimaryGeneratorAction2.hh.

◆ nPoints

G4int PrimaryGeneratorAction2::nPoints
private

Definition at line 63 of file PrimaryGeneratorAction2.hh.

◆ particleGun

G4ParticleGun* PrimaryGeneratorAction2::particleGun
private

Definition at line 61 of file PrimaryGeneratorAction2.hh.

◆ x

std::vector<G4double> PrimaryGeneratorAction2::x
private

Definition at line 64 of file PrimaryGeneratorAction2.hh.


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