Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
GammaRayTelPrimaryGeneratorAction.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 // $Id: GammaRayTelPrimaryGeneratorAction.cc 110939 2018-06-27 12:02:21Z gunter $
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  rndmFlag = "off";
69  nSourceType = 0;
70  nSpectrumType = 0;
71  sourceGun = false;
72  dVertexRadius = 15.*cm;
73 
74  G4int n_particle = 1;
75 
76  particleGun = new G4ParticleGun(n_particle);
77  // default particle kinematic
78 
80  G4String particleName;
81  G4ParticleDefinition* particle
82  = particleTable->FindParticle(particleName="e-");
89 
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93 
95 {
96 
97  delete particleGun;
98  delete particleSource;
99  delete gunMessenger;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
103 
105 {
106  if (sourceGun)
107  {
108 
109  G4cout << "Using G4ParticleGun ... " << G4endl;
110 
111  //this function is called at the begining of event
112  //
114  G4double x0 = 0.*cm, y0 = 0.*cm;
115 
116  G4ThreeVector pos0;
117  G4ThreeVector vertex0 = G4ThreeVector(x0,y0,z0);
118  G4ThreeVector dir0 = G4ThreeVector(0.,0.,-1.);
119 
120  G4double theta, phi;
121  G4double y = 0.;
122  G4double f = 0.;
123  G4double theta0=0.;
124  G4double phi0=0.;
125 
126  switch(nSourceType) {
127  case 0:
130  break;
131  case 1:
132  // GS: Generate random position on the 4PIsphere to create a unif. distrib.
133  // GS: on the sphere
134  phi = G4UniformRand() * twopi;
135  do {
136  y = G4UniformRand()*1.0;
137  theta = G4UniformRand() * pi;
138  f = std::sin(theta);
139  } while (y > f);
140  vertex0 = G4ThreeVector(1.,0.,0.);
141  vertex0.setMag(dVertexRadius);
142  vertex0.setTheta(theta);
143  vertex0.setPhi(phi);
145 
146  dir0 = G4ThreeVector(1.,0.,0.);
147  do {
148  phi = G4UniformRand() * twopi;
149  do {
150  y = G4UniformRand()*1.0;
151  theta = G4UniformRand() * pi;
152  f = std::sin(theta);
153  } while (y > f);
154  dir0.setPhi(phi);
155  dir0.setTheta(theta);
156  } while (vertex0.dot(dir0) >= -0.7 * vertex0.mag());
158 
159  break;
160  case 2:
161  // GS: Generate random position on the upper semi-sphere z>0 to create a unif. distrib.
162  // GS: on a plane
163  phi = G4UniformRand() * twopi;
164  do {
165  y = G4UniformRand()*1.0;
166  theta = G4UniformRand() * halfpi;
167  f = std::sin(theta) * std::cos(theta);
168  } while (y > f);
169  vertex0 = G4ThreeVector(1.,0.,0.);
170 
173 
174  if (dVertexRadius > xy*0.5)
175  {
176  G4cout << "vertexRadius too big " << G4endl;
177  G4cout << "vertexRadius setted to " << xy*0.45 << G4endl;
178  dVertexRadius = xy*0.45;
179  }
180 
181  if (dVertexRadius > z*0.5)
182  {
183  G4cout << "vertexRadius too high " << G4endl;
184  G4cout << "vertexRadius setted to " << z*0.45 << G4endl;
185  dVertexRadius = z*0.45;
186  }
187 
188 
189  vertex0.setMag(dVertexRadius);
190  vertex0.setTheta(theta);
191  vertex0.setPhi(phi);
192 
193  // GS: Get the user defined direction for the primaries and
194  // GS: Rotate the random position according to the user defined direction for the particle
195 
197  if (dir0.mag() > 0.001)
198  {
199  theta0 = dir0.theta();
200  phi0 = dir0.phi();
201  }
202 
203  if (theta0!=0.)
204  {
205  G4ThreeVector rotationAxis(1.,0.,0.);
206  rotationAxis.setPhi(phi0+halfpi);
207  vertex0.rotate(theta0+pi,rotationAxis);
208  }
210  break;
211  }
212 
213 
214  G4double pEnergy = 100*MeV;
215 
216  switch(nSpectrumType) {
217  case 0: // Uniform energy (1-10 GeV)
218  y = G4UniformRand();
219  pEnergy = y*9.0*GeV + 1.0*GeV;
220  G4cout << pEnergy/GeV << " LIN" << G4endl;
221  break;
222  case 1: // Logaritmic energy
223  y = G4UniformRand();
224  pEnergy = std::pow(10,y)*GeV;
225  G4cout << pEnergy/GeV << " LOG" << G4endl;
226  break;
227  case 2: // Power Law (-4)
228  do {
229  y = G4UniformRand()*100000.0;
230  pEnergy = G4UniformRand() * 10. * GeV;
231  f = std::pow(pEnergy * (1/GeV), -4.);
232  } while (y > f);
233  // particleGun->SetParticleEnergy(pEnergy);
234  break;
235  case 3: // Monochromatic
236  pEnergy = particleGun->GetParticleEnergy();
237  //100 * MeV;
238  G4cout << pEnergy << " MONO" << G4endl;
239  break;
240  }
241  particleGun->SetParticleEnergy(pEnergy);
244  }
245  else
246  {
248  }
249 
250 }
251 
252 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
253 
254 
255 
256 
257 
258 
259 
260 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
CLHEP::Hep3Vector G4ThreeVector
void setMag(double)
Definition: ThreeVector.cc:25
static G4ParticleTable * GetParticleTable()
static constexpr double MeV
Definition: G4SIunits.hh:214
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
Double_t z
const G4String & GetParticleName() const
const GammaRayTelDetectorConstruction * GammaRayTelDetector
double dot(const Hep3Vector &) const
void setTheta(double)
void SetParticlePosition(G4ThreeVector aPosition)
double theta() const
GammaRayTelPrimaryGeneratorMessenger * gunMessenger
double G4double
Definition: G4Types.hh:76
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
#define G4UniformRand()
Definition: Randomize.hh:53
static constexpr double twopi
Definition: G4SIunits.hh:76
static constexpr double halfpi
Definition: G4SIunits.hh:77
Hep3Vector & rotate(double, const Hep3Vector &)
Definition: ThreeVectorR.cc:28
void setPhi(double)
double mag() const
int G4int
Definition: G4Types.hh:78
double phi() const
G4double GetParticleEnergy() const
virtual void GeneratePrimaryVertex(G4Event *evt)
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
void SetParticleEnergy(G4double aKineticEnergy)
static constexpr double pi
Definition: G4SIunits.hh:75
G4ParticleDefinition * GetParticleDefinition() const
G4ParticleMomentum GetParticleMomentumDirection() const
static constexpr double GeV
Definition: G4SIunits.hh:217
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const