Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Em10PrimaryGeneratorAction.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 //
28 //
29 //
30 // $Id$
31 //
32 //
33 
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
36 
38 
41 
42 #include "G4Event.hh"
43 #include "G4ParticleGun.hh"
44 #include "G4ParticleTable.hh"
45 #include "G4ParticleDefinition.hh"
46 #include "Randomize.hh"
47 #include "G4ios.hh"
48 #include "G4PhysicalConstants.hh"
49 #include "G4SystemOfUnits.hh"
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52 
53  G4String Em10PrimaryGeneratorAction::thePrimaryParticleName="proton" ;
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
56 
59 :Em10Detector(Em10DC),rndmFlag("off"),xvertex(0.),yvertex(0.),zvertex(0.),
60  vertexdefined(false)
61 {
62  G4int n_particle = 1;
63  particleGun = new G4ParticleGun(n_particle);
64 
65  //create a messenger for this class
66  gunMessenger = new Em10PrimaryGeneratorMessenger(this);
67 
68  // default particle kinematic
69 
71  G4String particleName;
72  G4ParticleDefinition* particle
73  = particleTable->FindParticle(particleName="proton");
74  particleGun->SetParticleDefinition(particle);
75 
76  thePrimaryParticleName = particle->GetParticleName() ;
77 
78  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
79  particleGun->SetParticleEnergy(100.*GeV);
80 
81  zvertex = 0.0 ; // -0.5*(Em10Detector->GetAbsorberThickness());
82  particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex));
83 
84 }
85 
86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
87 
89 {
90  delete particleGun;
91  delete gunMessenger;
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
95 
97 {
98  //this function is called at the begining of event
99  //
100  thePrimaryParticleName = particleGun->GetParticleDefinition()->
101  GetParticleName() ;
102  /* ****************************************************
103  G4double x0,y0,z0 ;
104  if(vertexdefined)
105  {
106  x0 = xvertex ;
107  y0 = yvertex ;
108  z0 = zvertex ;
109  }
110  else
111  {
112  x0 = 0. ;
113  y0 = 0. ;
114  z0 = 0. ; // -0.5*(Em10Detector->GetWorldSizeZ()) ;
115  }
116  G4double r0,phi0 ;
117  if (rndmFlag == "on")
118  {
119  r0 = (Em10Detector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
120  phi0 = twopi*G4UniformRand();
121  x0 = r0*std::cos(phi0);
122  y0 = r0*std::sin(phi0);
123  }
124  ********************************************* */
125  // particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
126  particleGun->SetParticlePosition(G4ThreeVector(0.,0.,0.));
127  particleGun->GeneratePrimaryVertex(anEvent);
128 }
129 
131 //
132 //
133 
135 {
136  return thePrimaryParticleName ;
137 }
138 
140 {
141  vertexdefined = true ;
142  zvertex = z ;
143  G4cout << " Z coordinate of the primary vertex = " << zvertex/mm <<
144  " mm." << G4endl;
145 }
147 {
148  vertexdefined = true ;
149  xvertex = x ;
150  G4cout << " X coordinate of the primary vertex = " << xvertex/mm <<
151  " mm." << G4endl;
152 }
153 
155 {
156  vertexdefined = true ;
157  yvertex = y ;
158  G4cout << " Y coordinate of the primary vertex = " << yvertex/mm <<
159  " mm." << G4endl;
160 }