Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "G4PhysicalConstants.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "G4Event.hh"
45 #include "G4ParticleGun.hh"
46 #include "G4ParticleTable.hh"
47 #include "G4ParticleDefinition.hh"
48 #include "Randomize.hh"
50 #include "XrayFluoDataSet.hh"
51 #ifdef G4ANALYSIS_USE
52 #include "AIDA/AIDA.h"
53 #endif
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55 
57  :rndmFlag("off"),beam("off"),spectrum("off"),isoVert("off"),phaseSpaceGunFlag(false),
58  rayleighFlag(true), particleEnergies(0), particleTypes(0), detectorPosition(0)
59 {
60 
61  XrayFluoDetector = XrayFluoDC;
62 
63  G4int n_particle = 1;
64  particleGun = new G4ParticleGun(n_particle);
65 
66  //create a messenger for this class
67  gunMessenger = new XrayFluoPrimaryGeneratorMessenger(this);
68  runManager = new XrayFluoRunAction();
69 
70  // default particle kinematic
71 
73  G4String particleName;
74  G4ParticleDefinition* particle
75  = particleTable->FindParticle(particleName="gamma");
76  particleGun->SetParticleDefinition(particle);
77  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
78  particleGun->SetParticleEnergy(10. * keV);
79 
80  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
81  particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
82 
83 
84 
85  G4cout << "XrayFluoPrimaryGeneratorAction created" << G4endl;
86 
87 }
88 
89 
90 #ifdef G4ANALYSIS_USE
92 
93  // load phase-space
94  phaseSpaceGunFlag = true;
95 
96  // reads the data stored on disk form previous runs
97  // and get these data to data members
98 
99  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
100  analysis->LoadGunData(fileName, rayleighFlag);
101  particleEnergies = analysis->GetEmittedParticleEnergies();
102  particleTypes = analysis->GetEmittedParticleTypes();
103  detectorPosition = XrayFluoDetector->GetDetectorPosition();
104  detectorPosition.setR(detectorPosition.r()-(5.*cm)); // 5 cm before the detector, so in front of it.
105 #else
107 #endif
108 
109 }
110 
111 
113 {
114 
115  G4cout << "value: " << value << G4endl;
116  rayleighFlag = value;
117 
118 }
119 
120 
121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
122 
124 {
125  delete particleGun;
126  delete gunMessenger;
127  delete runManager;
128 
129  G4cout << "XrayFluoPrimaryGeneratorAction deleted" << G4endl;
130 
131 }
132 
133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
134 
136 {
137  //this function is called at the begining of event
138  //
139  G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ());
140  G4double y0 = 0.*cm, x0 = 0.*cm;
141  if (rndmFlag == "on")
142  {
143  y0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // it was GetSampleSizeXY(),
144  x0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // not divided by std::sqrt(2.)
145  }
146  particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
147 
148  //randomize starting point
149  if (beam == "on")
150  {
151  G4double radius = 0.5 * mm;
152  G4double rho = radius*std::sqrt(G4UniformRand());
153  G4double theta = 2*pi*G4UniformRand()*rad;
154  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
155 
156  G4double y = rho * std::sin(theta);
157  G4double x = rho * std::cos(theta);
158 
159  particleGun->SetParticlePosition(G4ThreeVector(x,y,position));
160  }
161  //shoot particles according to a certain spectrum
162  if (spectrum =="on")
163  {
164  G4String particle = particleGun->GetParticleDefinition()
165  ->GetParticleName();
166  if(particle == "proton"|| particle == "alpha")
167  {
168  G4DataVector* energies = runManager->GetEnergies();
169  G4DataVector* data = runManager->GetData();
170 
171  G4double sum = runManager->GetDataSum();
172  G4double partSum = 0;
173  G4int j = 0;
174  G4double random= sum*G4UniformRand();
175  while (partSum<random)
176  {
177  partSum += (*data)[j];
178  j++;
179  }
180 
181  particleGun->SetParticleEnergy((*energies)[j]);
182 
183  }
184  else if (particle == "gamma")
185  {
186  const XrayFluoDataSet* dataSet = runManager->GetGammaSet();
187 
188  G4int i = 0;
189  G4int id = 0;
190  G4double minEnergy = 0. * keV;
191  G4double particleEnergy= 0.;
192  G4double maxEnergy = 10. * keV;
193  G4double energyRange = maxEnergy - minEnergy;
194 
195  while ( i == 0)
196  {
197  G4double random = G4UniformRand();
198 
199  G4double randomNum = G4UniformRand(); //*5.0E6;
200 
201  particleEnergy = (random*energyRange) + minEnergy;
202 
203  if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
204  {
205  i = 1;
206 
207  }
208  }
209  particleGun->SetParticleEnergy(particleEnergy);
210  }
211  }
212 
213  // Randomize starting point and direction
214 
215  if (isoVert == "on")
216  {
217  G4double rho = 1. *m;
218  //theta in [0;pi/2]
219  G4double theta = (pi/2)*G4UniformRand();
220  //phi in [-pi;pi]
221  G4double phi = (G4UniformRand()*2*pi)- pi;
222  G4double x = rho*std::sin(theta)*std::sin(phi);
223  G4double y = rho*std::sin(theta)*std::cos(phi);
224  G4double z = -(rho*std::cos(theta));
225  particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
226 
227  G4double Xdim = XrayFluoDetector->GetSampleSizeXY();
228  G4double Ydim = XrayFluoDetector->GetSampleSizeXY();
229 
230  G4double Dx = Xdim*(G4UniformRand()-0.5);
231 
232  G4double Dy = Ydim*(G4UniformRand()-0.5);
233 
234  particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z));
235 
236  }
237 
238  // using prevoiously genereated emissions from sample.....
239 
240  if (phaseSpaceGunFlag){
241 
242  size_t i = anEvent->GetEventID();
243 
244  particleGun->SetParticlePosition(detectorPosition);
245  particleGun->SetParticleMomentumDirection(detectorPosition);
248  G4ParticleDefinition* particle;
249  if (i < particleEnergies->size()) {
250  energy = (*particleEnergies)[i];
251  particle = particleTable->FindParticle((*particleTypes)[i]);
252  }
253 
254  else {
255  energy = 0.;
256  particle = particleTable->FindParticle("gamma");
257  }
258 
259  particleGun->SetParticleEnergy(energy);
260  particleGun->SetParticleDefinition(particle);
261 
262 
263  }
264 
265 #ifdef G4ANALYSIS_USE
266 
267  G4double partEnergy = particleGun->GetParticleEnergy();
268  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
269  analysis->analysePrimaryGenerator(partEnergy/keV);
270 
271 #endif
272 
273  particleGun->GeneratePrimaryVertex(anEvent);
274 }
275 
276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
277 
278 
279 
280 
281 
282 
283 
284 
285 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
const XrayFluoDataSet * GetGammaSet()
void setR(double s)
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
const G4String & GetParticleName() const
XrayFluoPrimaryGeneratorAction(XrayFluoDetectorConstruction *)
G4int GetEventID() const
Definition: G4Event.hh:140
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:87
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void SetParticleEnergy(G4double aKineticEnergy)
G4DataVector * GetData()
static G4ParticleTable * GetParticleTable()
G4double FindValue(G4double e, G4int) const
G4ParticleDefinition * GetParticleDefinition() const
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4DataVector * GetEnergies()
double r() const
const XML_Char const XML_Char * data
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4double GetParticleEnergy() const