Geant4  10.01.p03
GammaRayTelPrimaryGeneratorAction.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: GammaRayTelPrimaryGeneratorAction.cc 82630 2014-07-01 09:43:00Z gcosmo $
28 // ------------------------------------------------------------
29 // GEANT 4 class implementation file
30 // CERN Geneva Switzerland
31 //
32 //
33 // ------------ GammaRayTelPrimaryGeneratorAction ------
34 // by G.Santin, F.Longo & R.Giannitrapani (13 nov 2000)
35 //
36 // ************************************************************
37 
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
40 
41 #include "G4RunManager.hh"
43 
46 
47 #include "G4PhysicalConstants.hh"
48 #include "G4SystemOfUnits.hh"
49 #include "G4Event.hh"
50 #include "G4ParticleGun.hh"
52 #include "G4ParticleTable.hh"
53 #include "G4ParticleDefinition.hh"
54 #include "Randomize.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59  :rndmFlag("off"),nSourceType(0),nSpectrumType(0),sourceGun(false)
60 {
63 
64  //create a messenger for this class
65 
67 
68  G4int n_particle = 1;
69 
70  particleGun = new G4ParticleGun(n_particle);
71  // default particle kinematic
72 
74  G4String particleName;
75  G4ParticleDefinition* particle
76  = particleTable->FindParticle(particleName="e-");
83 
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
87 
89 {
90 
91  delete particleGun;
92  delete particleSource;
93 
94  delete gunMessenger;
95 }
96 
97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
98 
100 {
101  if (sourceGun)
102  {
103 
104  //this function is called at the begining of event
105  //
107  G4double x0 = 0.*cm, y0 = 0.*cm;
108 
109  G4ThreeVector pos0;
110  G4ThreeVector dir0;
111  G4ThreeVector vertex0 = G4ThreeVector(x0,y0,z0);
112 
113  dir0 = G4ThreeVector(0.,0.,-1.);
114 
115  G4double theta, phi, y, f;
116  G4double theta0=0.;
117  G4double phi0=0.;
118 
119  switch(nSourceType) {
120  case 0:
123  break;
124  case 1:
125  // GS: Generate random position on the 4PIsphere to create a unif. distrib.
126  // GS: on the sphere
127  phi = G4UniformRand() * twopi;
128  do {
129  y = G4UniformRand()*1.0;
130  theta = G4UniformRand() * pi;
131  f = std::sin(theta);
132  } while (y > f);
133  vertex0 = G4ThreeVector(1.,0.,0.);
134  vertex0.setMag(dVertexRadius);
135  vertex0.setTheta(theta);
136  vertex0.setPhi(phi);
138 
139  dir0 = G4ThreeVector(1.,0.,0.);
140  do {
141  phi = G4UniformRand() * twopi;
142  do {
143  y = G4UniformRand()*1.0;
144  theta = G4UniformRand() * pi;
145  f = std::sin(theta);
146  } while (y > f);
147  dir0.setPhi(phi);
148  dir0.setTheta(theta);
149  } while (vertex0.dot(dir0) >= -0.7 * vertex0.mag());
151 
152  break;
153  case 2:
154  // GS: Generate random position on the upper semi-sphere z>0 to create a unif. distrib.
155  // GS: on a plane
156  phi = G4UniformRand() * twopi;
157  do {
158  y = G4UniformRand()*1.0;
159  theta = G4UniformRand() * halfpi;
160  f = std::sin(theta) * std::cos(theta);
161  } while (y > f);
162  vertex0 = G4ThreeVector(1.,0.,0.);
163 
166 
167  if (dVertexRadius > xy*0.5)
168  {
169  G4cout << "vertexRadius too big " << G4endl;
170  G4cout << "vertexRadius setted to " << xy*0.45 << G4endl;
171  dVertexRadius = xy*0.45;
172  }
173 
174  if (dVertexRadius > z*0.5)
175  {
176  G4cout << "vertexRadius too high " << G4endl;
177  G4cout << "vertexRadius setted to " << z*0.45 << G4endl;
178  dVertexRadius = z*0.45;
179  }
180 
181 
182  vertex0.setMag(dVertexRadius);
183  vertex0.setTheta(theta);
184  vertex0.setPhi(phi);
185 
186  // GS: Get the user defined direction for the primaries and
187  // GS: Rotate the random position according to the user defined direction for the particle
188 
190  if (dir0.mag() > 0.001)
191  {
192  theta0 = dir0.theta();
193  phi0 = dir0.phi();
194  }
195 
196  if (theta0!=0.)
197  {
198  G4ThreeVector rotationAxis(1.,0.,0.);
199  rotationAxis.setPhi(phi0+halfpi);
200  vertex0.rotate(theta0+pi,rotationAxis);
201  }
203  break;
204  }
205 
206 
207  G4double pEnergy;
208 
209  switch(nSpectrumType) {
210  case 0:
211  break;
212  case 1:
213  break;
214  case 2:
215  do {
216  y = G4UniformRand()*100000.0;
217  pEnergy = G4UniformRand() * 10. * GeV;
218  f = std::pow(pEnergy * (1/GeV), -4.);
219  } while (y > f);
220 
221  particleGun->SetParticleEnergy(pEnergy);
222 
223  break;
224  case 3:
225  break;
226  }
227 
229  }
230  else
231  {
233  }
234 
235 }
236 
237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
238 
239 
240 
241 
242 
243 
244 
245 
static const double cm
Definition: G4SIunits.hh:106
static const double MeV
Definition: G4SIunits.hh:193
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
Andrea Dotti Feb 2015 GPS messenger design requires some explanation for what distributions parameter...
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
const G4double pi
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
G4ParticleMomentum GetParticleMomentumDirection() const
void SetParticlePosition(G4ThreeVector aPosition)
#define position
Definition: xmlparse.cc:605
#define G4UniformRand()
Definition: Randomize.hh:93
G4GLOB_DLL std::ostream G4cout
GammaRayTelPrimaryGeneratorMessenger * gunMessenger
static const double GeV
Definition: G4SIunits.hh:196
const GammaRayTelDetectorConstruction * GammaRayTelDetector
void SetParticleEnergy(G4double aKineticEnergy)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4ParticleTable * GetParticleTable()
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4ThreeVector G4ParticleMomentum
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)