ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PrimaryGeneratorAction.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 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // and papers
31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // -------------------------------------------------------------------
36 // November 2016
37 // -------------------------------------------------------------------
38 //
41 
42 #include "PrimaryGeneratorAction.hh"
43 #include "G4SystemOfUnits.hh"
44 //
45 #include "CommandLineParser.hh"
46 #include "G4ParticleTable.hh"
47 #include "G4ParticleGun.hh"
48 #include "G4ParticleDefinition.hh"
49 #include "G4PhysicalConstants.hh"
50 #include "Randomize.hh"
51 #include "G4Event.hh"
52 #include "G4Box.hh"
53 #include "G4Orb.hh"
54 #include "G4LogicalVolume.hh"
55 #include "G4LogicalVolumeStore.hh"
56 #include "G4VPhysicalVolume.hh"
57 #include "G4PhysicalVolumeStore.hh"
58 
59 using namespace G4DNAPARSER ;
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
65 {
66  G4int n_particle = 1;
67  fpParticleGun = new G4ParticleGun(n_particle);
68  //
70  G4ParticleDefinition* particle = particleTable->FindParticle("proton");
72  // default gun parameters
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82  delete fpParticleGun;
83 }
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
88 {
89 
90  // Initial kinetic energy of particles beam as Gaussion distribution!
91 
92  // G4double Ekin = 10.*MeV;
93  // G4double deltaEkin = 9.0955e-5*MeV;
94  // fpParticleGun->SetParticleEnergy(G4RandGauss::shoot(Ekin,deltaEkin));
95 
96  // In order to avoid dependence of PrimaryGeneratorAction
97  // on DetectorConstruction class we get world volume
98  // from G4LogicalVolumeStore
99 
100  // We included three options for particles direction:
101 
102  G4double mediumRadius = 0.;
103  G4double boundingXHalfLength = 0.;
104  G4double boundingYHalfLength = 0.;
105  G4double boundingZHalfLength = 0.;
106  G4LogicalVolume* mediumLV
108  G4LogicalVolume* boundingLV
109  = G4LogicalVolumeStore::GetInstance()->GetVolume("BoundingSlice");
110  G4Orb* mediumSphere = 0;
111  G4Box* boundingSlice = 0;
112  if ( mediumLV && boundingLV)
113  {
114  mediumSphere = dynamic_cast< G4Orb*>(mediumLV->GetSolid());
115  boundingSlice = dynamic_cast< G4Box*>(boundingLV->GetSolid());
116  }
117  if ( mediumSphere && boundingSlice)
118  {
119  mediumRadius = mediumSphere->GetRadius();
120  boundingXHalfLength = boundingSlice->GetXHalfLength();
121  boundingYHalfLength = boundingSlice->GetYHalfLength();
122  boundingZHalfLength = boundingSlice->GetZHalfLength();
123 
126 
127  if ( CommandLineParser::GetParser()->GetCommandIfActive("-sXY"))
128  {
129  //G4cerr << " Initial beam position uniformly spread on a square! "
130  // << G4endl;
131  // INITIAL BEAM DIVERGENCE
133  // // INITIAL BEAM POSITION
135  CLHEP::RandFlat::shoot(-boundingXHalfLength,boundingXHalfLength),
136  CLHEP::RandFlat::shoot(-boundingYHalfLength,boundingYHalfLength),
137  -mediumRadius));
138  // Surface area of a square
139  // fGunArea = 4*boundingXHalfLength*boundingYHalfLength ;
140  //G4cerr << " Particle Fluence Area on a Square (um2) = "
141  // <<fGunArea / (um*um)<< G4endl;
142  }
143 
146 
147  else if ( CommandLineParser::GetParser()->GetCommandIfActive("-dXY"))
148  {
149  //G4cerr << " Initial beam position uniformly spread on a disk! "
150  // << G4endl;
152  G4double x0,y0,z0;
153  x0 = 100.*mm;
154  y0 = 100.*mm;
155  z0 = -mediumRadius; // mediumRadius;
156  while (! (std::sqrt(x0*x0+y0*y0)<= mediumRadius) )
157  {
158  x0 = CLHEP::RandFlat::shoot(-mediumRadius,mediumRadius);
159  y0 = CLHEP::RandFlat::shoot(-mediumRadius,mediumRadius);
160  }
162  // Surface area of a disk
163  // fGunArea = pi*mediumRadius*mediumRadius ;
164  // G4cerr << " Particle Fluence Area on a Disk (um2) = "
165  // <<fGunArea / (um*um)<< G4endl;
166 
167  }
168 
170  // Select a starting position on a sphere including the
171  // target volume and neuron morphology
172  else
173  {
174  //G4cerr << " Initial beam position uniformly spread on a sphere! "<< G4endl;
175  G4double cosTheta = 2.*G4UniformRand()-1;
176  G4double sinTheta = std::sqrt(1.-cosTheta*cosTheta);
178  G4ThreeVector positionStart(mediumRadius*sinTheta*std::cos(phi),
179  mediumRadius*sinTheta*std::sin(phi),
180  mediumRadius*cosTheta);
181  fpParticleGun->SetParticlePosition(positionStart);
182  // To compute the direction, select a point inside the target volume
183  G4ThreeVector positionDir(
184  boundingXHalfLength*(2.*G4UniformRand()-1),
185  boundingYHalfLength*(2.*G4UniformRand()-1),
186  boundingZHalfLength*(2.*G4UniformRand()-1));
188  (positionDir-positionStart).unit());
189  // Surface area of sphere
190  fGunArea = 4.*pi*mediumRadius*mediumRadius ;
191  // G4cerr << " Particle Fluence Area on sphere (um2) = "
192  // <<fGunArea / (um*um)<< G4endl;
193  }
194 
195  }
196  else
197  {
198  G4cerr << "Bounding slice volume not found!" << G4endl;
199  G4cerr << "Default particle kinematic used" << G4endl;
200  }
201 
203 }