ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
HadrontherapyPrimaryGeneratorAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file HadrontherapyPrimaryGeneratorAction.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
// Hadrontherapy advanced example for Geant4
27
// See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
28
29
#include "
HadrontherapyPrimaryGeneratorAction.hh
"
30
#include "
HadrontherapyPrimaryGeneratorMessenger.hh
"
31
32
#include "
HadrontherapyMatrix.hh
"
33
#include "
HadrontherapyDetectorSD.hh
"
34
#include "
G4SystemOfUnits.hh
"
35
#include "
G4Event.hh
"
36
#include "
G4ParticleGun.hh
"
37
#include "
G4GeneralParticleSource.hh
"
38
#include "
G4ParticleTable.hh
"
39
#include "
G4ParticleDefinition.hh
"
40
#include "
Randomize.hh
"
41
#include "
G4IonTable.hh
"
42
43
44
#include "
G4VUserPrimaryGeneratorAction.hh
"
45
#include "
G4ParticleTable.hh
"
46
47
#include "
G4Event.hh
"
48
#include "
G4Timer.hh
"
49
50
#include "
G4RunManager.hh
"
51
52
53
55
HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction
()
56
{
57
PrimaryGeneratorMessenger
=
new
HadrontherapyPrimaryGeneratorMessenger
(
this
);
58
SetDefaultPrimaryParticle
();
59
particleGun
=
new
G4GeneralParticleSource
();
60
61
}
62
64
HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction
()
65
{
66
delete
PrimaryGeneratorMessenger
;
67
delete
particleGun
;
68
}
69
71
void
HadrontherapyPrimaryGeneratorAction::SetDefaultPrimaryParticle
()
72
{
73
74
}
75
77
void
HadrontherapyPrimaryGeneratorAction::GeneratePrimaries
(
G4Event
* anEvent)
78
{
79
80
if
(
NewSource
==
true
)
81
{
82
std::ifstream
in
(
calculatedPhaseSpaceFileIN
);
83
G4double
e
, xpos, ypos,
zpos
,dirx,diry,dirz;
84
G4int
PDG;
85
G4ThreeVector
pos
,
dir
;
86
87
if
(in.eof())
88
{
89
G4Exception
(
"HadrontherapyPrimaryGeneratorAction"
,
"NoParticles"
,
FatalException
,
"No more particles in the file"
);
90
}
91
92
while
(!in.eof())
93
{
94
95
in >> e >> xpos >> ypos >>zpos >>dirx>>diry>>dirz >> PDG;
96
dir=
G4ThreeVector
(dirx,diry,dirz);
97
particleGun
->
GetCurrentSource
()->
GetEneDist
()->
SetMonoEnergy
(e);
98
99
particleGun
->
GetCurrentSource
()->
GetParticlePosition
().
setX
(xpos);
100
particleGun
->
GetCurrentSource
()->
GetParticlePosition
().
setY
(ypos);
101
particleGun
->
GetCurrentSource
()->
GetParticlePosition
().
setZ
(zpos);
102
particleGun
->
GetCurrentSource
()->
GetAngDist
()->
SetParticleMomentumDirection
(dir);
103
104
G4ParticleDefinition
* particleDef =
nullptr
;
105
if
(PDG > 1000000000)
106
{
107
int
a
=(PDG-1000000000)-(((PDG-1000000000)/10)*10);
108
if
(a>0)
109
{
110
PDG=PDG-
a
;
111
particleDef =
G4IonTable::GetIonTable
()->
GetIon
(PDG);
112
G4String
Nome = particleDef->
GetParticleName
();
113
}
114
115
else
116
{
117
particleDef =
G4IonTable::GetIonTable
()->
GetIon
(PDG);
118
G4String
Nome = particleDef->
GetParticleName
();
119
}
120
}
121
122
else
123
{
124
particleDef =
G4ParticleTable::GetParticleTable
()->
FindParticle
(PDG);
125
}
126
127
particleGun
->
GetCurrentSource
()->
SetParticleDefinition
(particleDef);
128
particleGun
->
GeneratePrimaryVertex
(anEvent);
129
130
}
131
132
in.close();
133
134
}
135
else
136
{
137
particleGun
->
GeneratePrimaryVertex
(anEvent);
138
}
139
140
}
141
142
geant4
tree
geant4-10.6-release
examples
advanced
hadrontherapy
src
HadrontherapyPrimaryGeneratorAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:58
using
1.8.2 with
ECCE GitHub integration