Loading...
Searching...
No Matches
F01PrimaryGeneratorAction.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/field01/src/F01PrimaryGeneratorAction.cc
27/// \brief Implementation of the F01PrimaryGeneratorAction 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(0.5*GeV);
77
80 fParticleGun->SetParticlePosition(G4ThreeVector(fXVertex,fYVertex,fZVertex));
81
82}
83
84//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93
95{
96 // this function is called at the begining of event
97 //
98 fgPrimaryParticle = fParticleGun->GetParticleDefinition();
99
100 G4double x0,y0,z0;
101 if (fVertexDefined)
102 {
103 x0 = fXVertex;
104 y0 = fYVertex;
105 z0 = fZVertex;
106 }
107 else
108 {
109 x0 = 0.;
110 y0 = 0.;
112 }
113
114 G4double r0,phi0;
115 if (fRndmFlag == "on")
116 {
117 r0 = (fDetector->GetAbsorberRadius())*std::sqrt(G4UniformRand());
118 phi0 = twopi*G4UniformRand();
119 x0 = r0*std::cos(phi0);
120 y0 = r0*std::sin(phi0);
121 }
122
123 fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
124 fParticleGun->GeneratePrimaryVertex(anEvent);
125}
126
127//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128
133
134//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135
137{
138 fVertexDefined = true;
139 fZVertex = z;
140 G4cout << " Z coordinate of the primary vertex = " << fZVertex/mm <<
141 " mm." << G4endl;
142}
143
144//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
145
147{
148 fVertexDefined = true;
149 fXVertex = x;
150 G4cout << " X coordinate of the primary vertex = " << fXVertex/mm <<
151 " mm." << G4endl;
152}
153
154//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155
157{
158 fVertexDefined = true;
159 fYVertex = y;
160 G4cout << " Y coordinate of the primary vertex = " << fYVertex/mm <<
161 " mm." << G4endl;
162}
163
164//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Definition of the F01DetectorConstruction class.
Definition of the F01PrimaryGeneratorAction class.
Definition of the F01PrimaryGeneratorMessenger class.
static G4ParticleDefinition * fgPrimaryParticle
F01PrimaryGeneratorAction(F01DetectorConstruction *)
void GeneratePrimaries(G4Event *) override
F01DetectorConstruction * fDetector
F01PrimaryGeneratorMessenger * fGunMessenger

Applications | User Support | Publications | Collaboration