ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F04PrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file F04PrimaryGeneratorAction.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 //
29 //
30 
31 #include "G4ios.hh"
32 #include "G4Event.hh"
33 #include "G4ParticleGun.hh"
34 #include "G4ParticleTable.hh"
35 #include "G4ParticleDefinition.hh"
36 
37 #include "G4GeometryManager.hh"
38 
39 #include "Randomize.hh"
40 #include "G4PhysicalConstants.hh"
41 #include "G4SystemOfUnits.hh"
42 
44 
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
52  : fDetector(detectorConstruction), fRndmFlag("off"), fFirst(false),
53  fXvertex(0.), fYvertex(0.), fZvertex(0.),
54  fVertexdefined(false)
55 {
56  G4int n_particle = 1;
57  fParticleGun = new G4ParticleGun(n_particle);
58 
60 
61  G4String particleName;
63 
64  fParticleGun->SetParticleDefinition(particleTable->
65  FindParticle(particleName="proton"));
68 
71 
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  delete fParticleGun;
79  delete fGunMessenger;
80 }
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83 
85 {
86 
87  if (!fFirst) {
88 
89  fFirst = true;
90  G4ThreeVector direction(0.0,0.0,1.0);
91 
92  G4Navigator* theNavigator =
94  GetNavigatorForTracking();
95  if ( theNavigator->GetWorldVolume() )
96  {
97  G4Navigator* aNavigator = new G4Navigator();
98  aNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
99 
100  G4ThreeVector center(0.,0.,0.);
101  aNavigator->LocateGlobalPointAndSetup(center,0,false);
102 
103  G4TouchableHistoryHandle touchable = aNavigator->
104  CreateTouchableHistoryHandle();
105 
106  // set Global2local transform
107  fGlobal2local = touchable->GetHistory()->GetTopTransform();
108 
109  direction = fGlobal2local.Inverse().TransformAxis(direction);
110  delete aNavigator;
111  }
112 
114  }
115 
116  G4double x0,y0,z0 ;
117 
118  if(fVertexdefined)
119  {
120  x0 = fXvertex ;
121  y0 = fYvertex ;
122  z0 = fZvertex ;
123  }
124  else
125  {
126  x0 = 0. ;
127  y0 = 0. ;
128  z0 = -0.5*(fDetector->GetTargetThickness());
129  }
130 
131  G4double r0, phi0;
132 
133  if (fRndmFlag == "on")
134  {
135  r0 = (fDetector->GetTargetRadius())*std::sqrt(G4UniformRand());
136  phi0 = twopi*G4UniformRand();
137  x0 = r0*std::cos(phi0);
138  y0 = r0*std::sin(phi0);
139  }
140 
141  G4ThreeVector localPosition(x0,y0,z0);
142  G4ThreeVector globalPosition =
143  fGlobal2local.Inverse().TransformPoint(localPosition);
144 
145  fParticleGun->SetParticlePosition(globalPosition);
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150 
152 {
153  fVertexdefined = true;
154  fXvertex = x;
155  G4cout << " X coordinate of the primary vertex = " << fXvertex/mm <<
156  " mm." << G4endl;
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160 
162 {
163  fVertexdefined = true;
164  fYvertex = y;
165  G4cout << " Y coordinate of the primary vertex = " << fYvertex/mm <<
166  " mm." << G4endl;
167 }
168 
169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170 
172 {
173  fVertexdefined = true;
174  fZvertex = z;
175  G4cout << " Z coordinate of the primary vertex = " << fZvertex/mm <<
176  " mm." << G4endl;
177 }