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

#include <XrayFluoPrimaryGeneratorAction.hh>

Inheritance diagram for XrayFluoPrimaryGeneratorAction:
Collaboration diagram for XrayFluoPrimaryGeneratorAction:

Public Member Functions

 XrayFluoPrimaryGeneratorAction (const XrayFluoDetectorConstruction *)
 
 ~XrayFluoPrimaryGeneratorAction ()
 
void GeneratePrimaries (G4Event *)
 
void SetRndmFlag (G4String val)
 
void SetRndmVert (G4String val)
 
void SetSpectrum (G4String val)
 
void SetIsoVert (G4String val)
 
void ActivatePhaseSpace (G4String)
 
void SetRayleighFlag (G4bool)
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 56 of file XrayFluoPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

XrayFluoPrimaryGeneratorAction::XrayFluoPrimaryGeneratorAction ( const XrayFluoDetectorConstruction XrayFluoDC)

Definition at line 56 of file XrayFluoPrimaryGeneratorAction.cc.

58  :rndmFlag("off"),beam("off"),spectrum("off"),isoVert("off"),phaseSpaceGunFlag(false),
59  rayleighFlag(true), detectorPosition(0)
60 {
61  runAction = 0;
62  XrayFluoDetector = XrayFluoDC;
63 
64  G4int n_particle = 1;
65  particleGun = new G4ParticleGun(n_particle);
66 
67  //create a messenger for this class
68  gunMessenger = new XrayFluoPrimaryGeneratorMessenger(this);
69 
70  // default particle kinematic
71  G4ParticleDefinition* particle
73  particleGun->SetParticleDefinition(particle);
74  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
75  particleGun->SetParticleEnergy(10. * keV);
76 
77  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
78  particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
79 
80  G4cout << "XrayFluoPrimaryGeneratorAction created" << G4endl;
81 
82 }
CLHEP::Hep3Vector G4ThreeVector
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
void SetParticlePosition(G4ThreeVector aPosition)
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
void SetParticleEnergy(G4double aKineticEnergy)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static constexpr double keV
Definition: G4SIunits.hh:216
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
static G4Gamma * Definition()
Definition: G4Gamma.cc:49

Here is the call graph for this function:

XrayFluoPrimaryGeneratorAction::~XrayFluoPrimaryGeneratorAction ( )

Definition at line 111 of file XrayFluoPrimaryGeneratorAction.cc.

112 {
113  delete particleGun;
114  delete gunMessenger;
115 }

Member Function Documentation

void XrayFluoPrimaryGeneratorAction::ActivatePhaseSpace ( G4String  fileName)

Definition at line 86 of file XrayFluoPrimaryGeneratorAction.cc.

86  {
87 
88  // load phase-space
89  phaseSpaceGunFlag = true;
90 
91  // reads the data stored on disk form previous runs
92  // and get these data to data members
93 
95  analysis->LoadGunData(fileName, rayleighFlag);
96  detectorPosition = XrayFluoDetector->GetDetectorPosition();
97  detectorPosition.setR(detectorPosition.r()-(5.*cm)); // 5 cm before the detector, so in front of it.
98 
99 }
void setR(double s)
void LoadGunData(G4String, G4bool)
static XrayFluoAnalysisManager * getInstance()
static constexpr double cm
Definition: G4SIunits.hh:119
double r() const

Here is the call graph for this function:

Here is the caller graph for this function:

void XrayFluoPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 119 of file XrayFluoPrimaryGeneratorAction.cc.

120 {
121  //retrieve runAction, if not done
122  if (!runAction)
123  {
124  //Sequential runaction
125  if (G4RunManager::GetRunManager()->GetRunManagerType() ==
127  runAction = static_cast<const XrayFluoRunAction*>
129  else //MT master runaction
130  runAction = static_cast<const XrayFluoRunAction*>
132  if (!runAction)
133  G4cout << "Something wrong here!" << G4endl;
134  }
135 
136  //this function is called at the begining of event
137  //
138  G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ());
139  G4double y0 = 0.*cm, x0 = 0.*cm;
140  if (rndmFlag == "on")
141  {
142  y0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // it was GetSampleSizeXY(),
143  x0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // not divided by std::sqrt(2.)
144  }
145  particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
146 
147  //randomize starting point
148  if (beam == "on")
149  {
150  G4double radius = 0.5 * mm;
151  G4double rho = radius*std::sqrt(G4UniformRand());
152  G4double theta = 2*pi*G4UniformRand()*rad;
153  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
154 
155  G4double y = rho * std::sin(theta);
156  G4double x = rho * std::cos(theta);
157 
158  particleGun->SetParticlePosition(G4ThreeVector(x,y,position));
159  }
160  //shoot particles according to a certain spectrum
161  if (spectrum =="on")
162  {
163  G4String particle = particleGun->GetParticleDefinition()
164  ->GetParticleName();
165  if(particle == "proton"|| particle == "alpha")
166  {
167  G4DataVector* energies = runAction->GetEnergies();
168  G4DataVector* data = runAction->GetData();
169 
170  G4double sum = runAction->GetDataSum();
171  G4double partSum = 0;
172  G4int j = 0;
173  G4double random= sum*G4UniformRand();
174  while (partSum<random)
175  {
176  partSum += (*data)[j];
177  j++;
178  }
179 
180  particleGun->SetParticleEnergy((*energies)[j]);
181 
182  }
183  else if (particle == "gamma")
184  {
185  const XrayFluoDataSet* dataSet = runAction->GetGammaSet();
186 
187  G4int i = 0;
188  G4int id = 0;
189  G4double minEnergy = 0. * keV;
190  G4double particleEnergy= 0.;
191  G4double maxEnergy = 10. * keV;
192  G4double energyRange = maxEnergy - minEnergy;
193 
194  while ( i == 0)
195  {
196  G4double random = G4UniformRand();
197 
198  G4double randomNum = G4UniformRand(); //*5.0E6;
199 
200  particleEnergy = (random*energyRange) + minEnergy;
201 
202  if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
203  {
204  i = 1;
205 
206  }
207  }
208  particleGun->SetParticleEnergy(particleEnergy);
209  }
210  }
211 
212  // Randomize starting point and direction
213 
214  if (isoVert == "on")
215  {
216  G4double rho = 1. *m;
217  //theta in [0;pi/2]
218  G4double theta = (pi/2)*G4UniformRand();
219  //phi in [-pi;pi]
220  G4double phi = (G4UniformRand()*2*pi)- pi;
221  G4double x = rho*std::sin(theta)*std::sin(phi);
222  G4double y = rho*std::sin(theta)*std::cos(phi);
223  G4double z = -(rho*std::cos(theta));
224  particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
225 
226  G4double Xdim = XrayFluoDetector->GetSampleSizeXY();
227  G4double Ydim = XrayFluoDetector->GetSampleSizeXY();
228 
229  G4double Dx = Xdim*(G4UniformRand()-0.5);
230 
231  G4double Dy = Ydim*(G4UniformRand()-0.5);
232 
233  particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z));
234 
235  }
236 
237  // using prevoiously genereated emissions from sample.....
238 
239  if (phaseSpaceGunFlag){
240 
241  particleGun->SetParticlePosition(detectorPosition);
242  particleGun->SetParticleMomentumDirection(detectorPosition);
243 
245 
246  const std::pair<G4double,G4String> kine =
248 
249  G4double energy = kine.first;
250  G4ParticleDefinition* particle = particleTable->FindParticle(kine.second);
251 
252  particleGun->SetParticleEnergy(energy);
253  particleGun->SetParticleDefinition(particle);
254 
255 
256  }
257 
258  G4double partEnergy = particleGun->GetParticleEnergy();
260  analysis->analysePrimaryGenerator(partEnergy/keV);
261 
262 
263  particleGun->GeneratePrimaryVertex(anEvent);
264 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static constexpr double mm
Definition: G4SIunits.hh:115
CLHEP::Hep3Vector G4ThreeVector
tuple x
Definition: test.py:50
const std::pair< G4double, G4String > GetEmittedParticleEnergyAndType()
static constexpr double rad
Definition: G4SIunits.hh:149
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
const G4String & GetParticleName() const
const XML_Char const XML_Char * data
Definition: expat.h:268
void analysePrimaryGenerator(G4double energy)
void SetParticlePosition(G4ThreeVector aPosition)
G4DataVector * GetEnergies() const
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
static constexpr double m
Definition: G4SIunits.hh:129
static XrayFluoAnalysisManager * getInstance()
static G4MTRunManager * GetMasterRunManager()
static constexpr double cm
Definition: G4SIunits.hh:119
const XrayFluoDataSet * GetGammaSet() const
G4DataVector * GetData() const
void SetParticleEnergy(G4double aKineticEnergy)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4ParticleTable * GetParticleTable()
G4double energy(const ThreeVector &p, const G4double m)
G4double FindValue(G4double e, G4int) const
G4ParticleDefinition * GetParticleDefinition() const
tuple z
Definition: test.py:28
G4double GetDataSum() const
#define G4endl
Definition: G4ios.hh:61
static constexpr double pi
Definition: G4SIunits.hh:75
const G4UserRunAction * GetUserRunAction() const
double G4double
Definition: G4Types.hh:76
static constexpr double keV
Definition: G4SIunits.hh:216
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4double GetParticleEnergy() const

Here is the call graph for this function:

void XrayFluoPrimaryGeneratorAction::SetIsoVert ( G4String  val)
inline

Definition at line 77 of file XrayFluoPrimaryGeneratorAction.hh.

77 { isoVert = val ;}

Here is the caller graph for this function:

void XrayFluoPrimaryGeneratorAction::SetRayleighFlag ( G4bool  value)

Definition at line 103 of file XrayFluoPrimaryGeneratorAction.cc.

104 {
105  rayleighFlag = value;
106 }
const XML_Char int const XML_Char * value
Definition: expat.h:331

Here is the caller graph for this function:

void XrayFluoPrimaryGeneratorAction::SetRndmFlag ( G4String  val)
inline

Definition at line 68 of file XrayFluoPrimaryGeneratorAction.hh.

68 { rndmFlag = val;}

Here is the caller graph for this function:

void XrayFluoPrimaryGeneratorAction::SetRndmVert ( G4String  val)
inline

Definition at line 71 of file XrayFluoPrimaryGeneratorAction.hh.

71 { beam = val;}

Here is the caller graph for this function:

void XrayFluoPrimaryGeneratorAction::SetSpectrum ( G4String  val)
inline

Definition at line 74 of file XrayFluoPrimaryGeneratorAction.hh.

74 { spectrum= val ;}

Here is the caller graph for this function:


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