ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XrayFluoPlanePrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file XrayFluoPlanePrimaryGeneratorAction.cc
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 //
28 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
29 //
30 // History:
31 // -----------
32 // 02 Sep 2003 Alfonso Mantero created
33 //
34 // -------------------------------------------------------------------
35 
39 #include "XrayFluoRunAction.hh"
41 #include "XrayFluoDataSet.hh"
42 #include "G4PhysicalConstants.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "G4UnitsTable.hh"
45 #include "G4DataVector.hh"
46 #include "G4Event.hh"
47 #include "G4ParticleGun.hh"
48 #include "G4ParticleTable.hh"
49 #include "G4ParticleDefinition.hh"
50 #include "Randomize.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
53 
55  :rndmFlag("on"),beam("off"),spectrum("off"),isoVert("off")
56 {
57 
58  XrayFluoDetector = XrayFluoDC;
59 
60  G4int n_particle = 1;
61  particleGun = new G4ParticleGun(n_particle);
62 
63  //create a messenger for this class
66 
67  // default particle kinematic
68 
70  G4String particleName;
72  = particleTable->FindParticle(particleName="gamma");
75 
76 
80 
81  G4cout << "XrayFluoPlanePrimaryGeneratorAction created UUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAaa" << G4endl;
82 
83 }
84 
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
87 
89 {
90  delete particleGun;
91  delete gunMessenger;
92  delete runManager;
93 
94  G4cout << "XrayFluoPlanePrimaryGeneratorAction deleted" << G4endl;
95 
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
99 
101 {
102  //this function is called at the begining of event
103  //
105  G4double y0 = 0.*m, x0 = 0.*m;
107  if (rndmFlag == "on")
108 
109  {y0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5);
110  x0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5) + dX;
111  }
112 
113  z0 = -1 * dX;
114 
116 
118 
119  //randomize starting point
120  if (beam == "on")
121  {
122  G4double radius = 0.5 * mm;
123  G4double rho = radius*std::sqrt(G4UniformRand());
126 
127  G4double y = rho * std::sin(theta);
128  G4double x = rho * std::cos(theta);
129 
131  }
132  //shoot particles according to a certain spectrum
133  if (spectrum =="on")
134  {
136  ->GetParticleName();
137  if(particle == "proton"|| particle == "alpha")
138  {
139  G4DataVector* energies = runManager->GetEnergies();
141 
143  G4double partSum = 0;
144  G4int j = 0;
145  G4double random= sum*G4UniformRand();
146  while (partSum<random)
147  {
148  partSum += (*data)[j];
149  j++;
150  }
151 
152  particleGun->SetParticleEnergy((*energies)[j]);
153 
154  }
155  else if (particle == "gamma")
156  {
157  const XrayFluoDataSet* dataSet = runManager->GetGammaSet();
158 
159  G4int i = 0;
160  G4int id = 0;
161  G4double minEnergy = 0. * keV;
162  G4double particleEnergy= 0.;
163  G4double maxEnergy = 10. * keV;
164  G4double energyRange = maxEnergy - minEnergy;
165 
166  while ( i == 0)
167  {
168  G4double random = G4UniformRand();
169 
170  G4double randomNum = G4UniformRand(); //*5.0E6;
171 
172  particleEnergy = (random*energyRange) + minEnergy;
173 
174  if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
175  {
176  i = 1;
177 
178  }
179  }
180  particleGun->SetParticleEnergy(particleEnergy);
181  }
182  }
183 
184  if (isoVert == "on")
185  {
186  G4double rho = 1. *m;
187  //theta in [0;pi/2]
188  G4double theta = (pi/2)*G4UniformRand();
189  //phi in [-pi;pi]
190  G4double phi = (G4UniformRand()*2*pi)- pi;
191  G4double x = rho*std::sin(theta)*std::sin(phi);
192  G4double y = rho*std::sin(theta)*std::cos(phi);
193  G4double z = -(rho*std::cos(theta));
195 
198 
199  G4double Dx = Xdim*(G4UniformRand()-0.5);
200 
201  G4double Dy = Ydim*(G4UniformRand()-0.5);
202 
204 
205  }
206 #ifdef G4ANALYSIS_USE
207 
208  G4double partEnergy = particleGun->GetParticleEnergy();
210  analysis->analysePrimaryGenerator(partEnergy/keV);
211 
212 #endif
213 
215 }
216 
217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
218 
219 
220 
221 
222 
223 
224 
225 
226