Loading...
Searching...
No Matches
F03PrimaryGeneratorAction.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/// \file field/field03/src/F03PrimaryGeneratorAction.cc
27/// \brief Implementation of the F03PrimaryGeneratorAction class
28//
29//
30//
31//
32//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34
36
39
40#include "G4Event.hh"
41#include "G4ParticleGun.hh"
42#include "G4ParticleTable.hh"
43#include "G4ParticleDefinition.hh"
44
45#include "Randomize.hh"
46#include "G4SystemOfUnits.hh"
47#include "G4PhysicalConstants.hh"
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
52
53//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54
57 : fDetector(det)
58{
59 G4int n_particle = 1;
60 fParticleGun = new G4ParticleGun(n_particle);
61
62 // create a messenger for this class
64
65 // default particle kinematic
66
67 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
68 G4String particleName;
69 G4ParticleDefinition* particle
70 = particleTable->FindParticle(particleName="e-");
71 fParticleGun->SetParticleDefinition(particle);
72
73 fgPrimaryParticle = particle;
74
75 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
76 fParticleGun->SetParticleEnergy(1.*GeV);
77
79 fParticleGun->SetParticlePosition(G4ThreeVector(fXVertex,fYVertex,fZVertex));
80
81}
82
83//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84
90
91//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92
94{
95 // this function is called at the begining of event
96 //
97 fgPrimaryParticle = fParticleGun->GetParticleDefinition();
98
99 G4double x0,y0,z0;
100 if (fVertexDefined)
101 {
102 x0 = fXVertex;
103 y0 = fYVertex;
104 z0 = fZVertex;
105 }
106 else
107 {
108 x0 = 0.;
109 y0 = 0.;
111 }
112
113 G4double r0,phi0;
114 if (fRndmFlag == "on")
115 {
116 r0 = (fDetector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
117 phi0 = twopi*G4UniformRand();
118 x0 = r0*std::cos(phi0);
119 y0 = r0*std::sin(phi0);
120 }
121
122 fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
123 fParticleGun->GeneratePrimaryVertex(anEvent);
124}
125
126//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127
132
133//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134
136{
137 fVertexDefined = true;
138 fXVertex = x;
139 G4cout << " X coordinate of the primary vertex = " << fXVertex/mm <<
140 " mm." << G4endl;
141}
142
143//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
144
146{
147 fVertexDefined = true;
148 fYVertex = y;
149 G4cout << " Y coordinate of the primary vertex = " << fYVertex/mm <<
150 " mm." << G4endl;
151}
152
153//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154
156{
157 fVertexDefined = true;
158 fZVertex = z;
159 G4cout << " Z coordinate of the primary vertex = " << fZVertex/mm <<
160 " mm." << G4endl;
161}
162
163//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the F03DetectorConstruction class.
Definition of the F03PrimaryGeneratorAction class.
Definition of the F03PrimaryGeneratorMessenger class.
static G4ParticleDefinition * fgPrimaryParticle
F03DetectorConstruction * fDetector
F03PrimaryGeneratorMessenger * fGunMessenger
void GeneratePrimaries(G4Event *) override
F03PrimaryGeneratorAction(F03DetectorConstruction *)

Applications | User Support | Publications | Collaboration