Geant4  10.01.p02
XrayFluoPrimaryGeneratorAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: XrayFluoPrimaryGeneratorAction.cc
28 // GEANT4 tag $Name: xray_fluo-V03-02-00
29 //
30 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
31 //
32 // History:
33 // -----------
34 // 28 Nov 2001 Elena Guardincerri Created
35 //
36 // -------------------------------------------------------------------
37 
41 #include "XrayFluoRunAction.hh"
42 #include "G4Event.hh"
43 #include "G4Gamma.hh"
44 #include "G4ParticleGun.hh"
45 #include "G4ParticleTable.hh"
46 #include "G4ParticleDefinition.hh"
47 #include "G4MTRunManager.hh"
48 #include "Randomize.hh"
50 #include "XrayFluoDataSet.hh"
51 #include "G4PhysicalConstants.hh"
52 #include "G4SystemOfUnits.hh"
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55 
57  XrayFluoDetectorConstruction* XrayFluoDC)
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
69 
70  // default particle kinematic
71  G4ParticleDefinition* particle
76 
79 
80  G4cout << "XrayFluoPrimaryGeneratorAction created" << G4endl;
81 
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85 
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);
97  detectorPosition.setR(detectorPosition.r()-(5.*cm)); // 5 cm before the detector, so in front of it.
98 
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
102 
104 {
105  rayleighFlag = value;
106 }
107 
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
110 
112 {
113  delete particleGun;
114  delete gunMessenger;
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
118 
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  //
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  }
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;
154 
155  G4double y = rho * std::sin(theta);
156  G4double x = rho * std::cos(theta);
157 
159  }
160  //shoot particles according to a certain spectrum
161  if (spectrum =="on")
162  {
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));
225 
228 
229  G4double Dx = Xdim*(G4UniformRand()-0.5);
230 
231  G4double Dy = Ydim*(G4UniformRand()-0.5);
232 
234 
235  }
236 
237  // using prevoiously genereated emissions from sample.....
238 
239  if (phaseSpaceGunFlag){
240 
243 
245 
246  const std::pair<G4double,G4String> kine =
248 
249  G4double energy = kine.first;
250  G4ParticleDefinition* particle = particleTable->FindParticle(kine.second);
251 
254 
255 
256  }
257 
258  G4double partEnergy = particleGun->GetParticleEnergy();
260  analysis->analysePrimaryGenerator(partEnergy/keV);
261 
262 
264 }
265 
266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
267 
268 
269 
270 
271 
272 
273 
274 
275 
static const double cm
Definition: G4SIunits.hh:106
XrayFluoPrimaryGeneratorAction(const XrayFluoDetectorConstruction *)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
const G4double pi
const std::pair< G4double, G4String > GetEmittedParticleEnergyAndType()
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
const G4String & GetParticleName() const
XrayFluoPrimaryGeneratorMessenger * gunMessenger
void LoadGunData(G4String, G4bool)
void analysePrimaryGenerator(G4double energy)
void SetParticlePosition(G4ThreeVector aPosition)
G4DataVector * GetEnergies() const
#define position
Definition: xmlparse.cc:605
#define G4UniformRand()
Definition: Randomize.hh:93
G4GLOB_DLL std::ostream G4cout
static XrayFluoAnalysisManager * getInstance()
bool G4bool
Definition: G4Types.hh:79
static G4MTRunManager * GetMasterRunManager()
const XrayFluoDataSet * GetGammaSet() const
static const double rad
Definition: G4SIunits.hh:130
G4DataVector * GetData() const
const XrayFluoDetectorConstruction * XrayFluoDetector
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
G4double GetDataSum() const
#define G4endl
Definition: G4ios.hh:61
static const double m
Definition: G4SIunits.hh:110
static const double keV
Definition: G4SIunits.hh:195
const G4UserRunAction * GetUserRunAction() const
double G4double
Definition: G4Types.hh:76
static const double mm
Definition: G4SIunits.hh:102
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4double GetParticleEnergy() const
static G4Gamma * Definition()
Definition: G4Gamma.cc:49