Geant4_10
XrayFluoPlanePrimaryGeneratorAction.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: XrayFluoPlanePrimaryGeneratorAction.cc
28 // GEANT4 tag $Name:
29 //
30 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
31 //
32 // History:
33 // -----------
34 // 02 Sep 2003 Alfonso Mantero created
35 //
36 // -------------------------------------------------------------------
37 
41 #include "XrayFluoRunAction.hh"
43 #include "XrayFluoDataSet.hh"
44 #include "G4PhysicalConstants.hh"
45 #include "G4SystemOfUnits.hh"
46 #include "G4UnitsTable.hh"
47 #include "G4DataVector.hh"
48 #include "G4Event.hh"
49 #include "G4ParticleGun.hh"
50 #include "G4ParticleTable.hh"
51 #include "G4ParticleDefinition.hh"
52 #include "Randomize.hh"
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55 
57  :rndmFlag("on"),beam("off"),spectrum("off"),isoVert("off")
58 {
59 
60  XrayFluoDetector = XrayFluoDC;
61 
62  G4int n_particle = 1;
63  particleGun = new G4ParticleGun(n_particle);
64 
65  //create a messenger for this class
66  gunMessenger = new XrayFluoPlanePrimaryGeneratorMessenger(this);
67  runManager = new XrayFluoRunAction();
68 
69  // default particle kinematic
70 
72  G4String particleName;
73  G4ParticleDefinition* particle
74  = particleTable->FindParticle(particleName="gamma");
75  particleGun->SetParticleDefinition(particle);
76  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
77 
78 
79  particleGun->SetParticleEnergy(10.*keV);
80  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
81  particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
82 
83  G4cout << "XrayFluoPlanePrimaryGeneratorAction created UUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAaa" << G4endl;
84 
85 }
86 
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
89 
91 {
92  delete particleGun;
93  delete gunMessenger;
94  delete runManager;
95 
96  G4cout << "XrayFluoPlanePrimaryGeneratorAction deleted" << G4endl;
97 
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
103 {
104  //this function is called at the begining of event
105  //
106  G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ());
107  G4double y0 = 0.*m, x0 = 0.*m;
108  G4double dX = 0.5*(XrayFluoDetector->GetWorldSizeXY())-(XrayFluoDetector->GetPlaneSizeXY());
109  if (rndmFlag == "on")
110 
111  {y0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5);
112  x0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5) + dX;
113  }
114 
115  z0 = -1 * dX;
116 
117  particleGun->SetParticleMomentumDirection(G4ThreeVector(-1.,0.,1.));
118 
119  particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
120 
121  //randomize starting point
122  if (beam == "on")
123  {
124  G4double radius = 0.5 * mm;
125  G4double rho = radius*std::sqrt(G4UniformRand());
126  G4double theta = 2*pi*G4UniformRand()*rad;
127  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
128 
129  G4double y = rho * std::sin(theta);
130  G4double x = rho * std::cos(theta);
131 
132  particleGun->SetParticlePosition(G4ThreeVector(x,y,position));
133  }
134  //shoot particles according to a certain spectrum
135  if (spectrum =="on")
136  {
137  G4String particle = particleGun->GetParticleDefinition()
138  ->GetParticleName();
139  if(particle == "proton"|| particle == "alpha")
140  {
141  G4DataVector* energies = runManager->GetEnergies();
142  G4DataVector* data = runManager->GetData();
143 
144  G4double sum = runManager->GetDataSum();
145  G4double partSum = 0;
146  G4int j = 0;
147  G4double random= sum*G4UniformRand();
148  while (partSum<random)
149  {
150  partSum += (*data)[j];
151  j++;
152  }
153 
154  particleGun->SetParticleEnergy((*energies)[j]);
155 
156  }
157  else if (particle == "gamma")
158  {
159  const XrayFluoDataSet* dataSet = runManager->GetGammaSet();
160 
161  G4int i = 0;
162  G4int id = 0;
163  G4double minEnergy = 0. * keV;
164  G4double particleEnergy= 0.;
165  G4double maxEnergy = 10. * keV;
166  G4double energyRange = maxEnergy - minEnergy;
167 
168  while ( i == 0)
169  {
170  G4double random = G4UniformRand();
171 
172  G4double randomNum = G4UniformRand(); //*5.0E6;
173 
174  particleEnergy = (random*energyRange) + minEnergy;
175 
176  if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
177  {
178  i = 1;
179 
180  }
181  }
182  particleGun->SetParticleEnergy(particleEnergy);
183  }
184  }
185 
186  if (isoVert == "on")
187  {
188  G4double rho = 1. *m;
189  //theta in [0;pi/2]
190  G4double theta = (pi/2)*G4UniformRand();
191  //phi in [-pi;pi]
192  G4double phi = (G4UniformRand()*2*pi)- pi;
193  G4double x = rho*std::sin(theta)*std::sin(phi);
194  G4double y = rho*std::sin(theta)*std::cos(phi);
195  G4double z = -(rho*std::cos(theta));
196  particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
197 
198  G4double Xdim = XrayFluoDetector->GetPlaneSizeXY();
199  G4double Ydim = XrayFluoDetector->GetPlaneSizeXY();
200 
201  G4double Dx = Xdim*(G4UniformRand()-0.5);
202 
203  G4double Dy = Ydim*(G4UniformRand()-0.5);
204 
205  particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z));
206 
207  }
208 #ifdef G4ANALYSIS_USE
209 
210  G4double partEnergy = particleGun->GetParticleEnergy();
211  XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance();
212  analysis->analysePrimaryGenerator(partEnergy/keV);
213 
214 #endif
215 
216  particleGun->GeneratePrimaryVertex(anEvent);
217 }
218 
219 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
220 
221 
222 
223 
224 
225 
226 
227 
228 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
const XrayFluoDataSet * GetGammaSet()
tuple x
Definition: test.py:50
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
const G4String & GetParticleName() const
Double_t y
Definition: plot.C:279
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:87
G4GLOB_DLL std::ostream G4cout
void SetParticleEnergy(G4double aKineticEnergy)
G4DataVector * GetData()
static G4ParticleTable * GetParticleTable()
G4double FindValue(G4double e, G4int) const
G4ParticleDefinition * GetParticleDefinition() const
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4DataVector * GetEnergies()
const XML_Char const XML_Char * data
Definition: expat.h:268
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4double GetParticleEnergy() const
XrayFluoPlanePrimaryGeneratorAction(XrayFluoPlaneDetectorConstruction *)