Loading...
Searching...
No Matches
F04PrimaryGeneratorAction.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//
27/// \file field/field04/src/F04PrimaryGeneratorAction.cc
28/// \brief Implementation of the F04PrimaryGeneratorAction class
29//
30
31#include "G4ios.hh"
32#include "G4Event.hh"
33#include "G4ParticleGun.hh"
34#include "G4ParticleTable.hh"
35#include "G4ParticleDefinition.hh"
36#include "G4TouchableHandle.hh"
37
38#include "G4GeometryManager.hh"
39
40#include "Randomize.hh"
41#include "G4PhysicalConstants.hh"
42#include "G4SystemOfUnits.hh"
43
45
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
53 : fDetector(detectorConstruction)
54{
55 G4int n_particle = 1;
56 fParticleGun = new G4ParticleGun(n_particle);
57
59
60 G4String particleName;
61 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
62
63 fParticleGun->SetParticleDefinition(particleTable->
64 FindParticle(particleName="proton"));
65 fParticleGun->SetParticleEnergy(500.*MeV);
66 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
67
69 fParticleGun->SetParticlePosition(G4ThreeVector(fXvertex,fYvertex,fZvertex));
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
79
80//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81
83{
84
85 if (!fFirst) {
86
87 fFirst = true;
88 G4ThreeVector direction(0.0,0.0,1.0);
89
90 G4Navigator* theNavigator =
91 G4TransportationManager::GetTransportationManager()->
92 GetNavigatorForTracking();
93 if ( theNavigator->GetWorldVolume() )
94 {
95 auto aNavigator = new G4Navigator();
96 aNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
97
98 G4ThreeVector center(0.,0.,0.);
99 aNavigator->LocateGlobalPointAndSetup(center,nullptr,false);
100
101 G4TouchableHandle touchable = aNavigator->CreateTouchableHistoryHandle();
102
103 // set Global2local transform
104 fGlobal2local = touchable->GetHistory()->GetTopTransform();
105
106 direction = fGlobal2local.Inverse().TransformAxis(direction);
107 delete aNavigator;
108 }
109
110 fParticleGun->SetParticleMomentumDirection(direction);
111 }
112
113 G4double x0,y0,z0 ;
114
116 {
117 x0 = fXvertex ;
118 y0 = fYvertex ;
119 z0 = fZvertex ;
120 }
121 else
122 {
123 x0 = 0. ;
124 y0 = 0. ;
125 z0 = -0.5*(fDetector->GetTargetThickness());
126 }
127
128 G4double r0, phi0;
129
130 if (fRndmFlag == "on")
131 {
132 r0 = (fDetector->GetTargetRadius())*std::sqrt(G4UniformRand());
133 phi0 = twopi*G4UniformRand();
134 x0 = r0*std::cos(phi0);
135 y0 = r0*std::sin(phi0);
136 }
137
138 G4ThreeVector localPosition(x0,y0,z0);
139 G4ThreeVector globalPosition =
140 fGlobal2local.Inverse().TransformPoint(localPosition);
141
142 fParticleGun->SetParticlePosition(globalPosition);
143 fParticleGun->GeneratePrimaryVertex(anEvent);
144}
145
146//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147
149{
150 fVertexDefined = true;
151 fXvertex = x;
152 G4cout << " X coordinate of the primary vertex = " << fXvertex/mm <<
153 " mm." << G4endl;
154}
155
156//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
157
159{
160 fVertexDefined = true;
161 fYvertex = y;
162 G4cout << " Y coordinate of the primary vertex = " << fYvertex/mm <<
163 " mm." << G4endl;
164}
165
166//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
167
169{
170 fVertexDefined = true;
171 fZvertex = z;
172 G4cout << " Z coordinate of the primary vertex = " << fZvertex/mm <<
173 " mm." << G4endl;
174}
Definition of the F04DetectorConstruction class.
Definition of the F04PrimaryGeneratorAction class.
Definition of the F04PrimaryGeneratorMessenger class.
F04DetectorConstruction * fDetector
F04PrimaryGeneratorMessenger * fGunMessenger
F04PrimaryGeneratorAction(F04DetectorConstruction *)
void GeneratePrimaries(G4Event *) override

Applications | User Support | Publications | Collaboration