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
TrackingAction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file TrackingAction.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
//
28
//
29
//
30
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33
#include "TrackingAction.hh"
34
35
#include "HistoManager.hh"
36
#include "Run.hh"
37
#include "EventAction.hh"
38
#include "
TrackingMessenger.hh
"
39
40
#include "
G4Track.hh
"
41
#include "
G4ParticleTypes.hh
"
42
#include "
G4IonTable.hh
"
43
#include "
G4RunManager.hh
"
44
45
#include "
G4SystemOfUnits.hh
"
46
#include "
G4UnitsTable.hh
"
47
48
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49
50
TrackingAction::TrackingAction
(
EventAction
* EA)
51
:
G4UserTrackingAction
(),
52
fEvent(EA),fTrackMessenger(0),
53
fFullChain(
true
)
54
55
{
56
fTrackMessenger
=
new
TrackingMessenger
(
this
);
57
58
fTimeWindow1
=
fTimeWindow2
= 0.;
59
}
60
61
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62
63
TrackingAction::~TrackingAction
()
64
{
65
delete
fTrackMessenger
;
66
}
67
68
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69
70
void
TrackingAction::SetTimeWindow
(
G4double
t1
,
G4double
dt)
71
{
72
fTimeWindow1
=
t1
;
73
fTimeWindow2
=
fTimeWindow1
+ dt;
74
}
75
76
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77
78
void
TrackingAction::PreUserTrackingAction
(
const
G4Track
*
track
)
79
{
80
Run
* run
81
=
static_cast<
Run
*
>
(
G4RunManager::GetRunManager
()->
GetNonConstCurrentRun
());
82
83
G4ParticleDefinition
*
particle
= track->
GetDefinition
();
84
G4String
name
= particle->
GetParticleName
();
85
fCharge
= particle->
GetPDGCharge
();
86
fMass
= particle->
GetPDGMass
();
87
88
G4double
Ekin = track->
GetKineticEnergy
();
89
G4int
ID = track->
GetTrackID
();
90
91
G4bool
condition
=
false
;
92
93
// check LifeTime
94
//
95
G4double
meanLife = particle->
GetPDGLifeTime
();
96
97
//count particles
98
//
99
run->
ParticleCount
(name, Ekin, meanLife);
100
101
//energy spectrum
102
//
103
G4int
ih = 0;
104
if
(particle ==
G4Electron::Electron
()||
105
particle ==
G4Positron::Positron
()) ih = 1;
106
else
if
(particle ==
G4NeutrinoE::NeutrinoE
()||
107
particle ==
G4AntiNeutrinoE::AntiNeutrinoE
()) ih = 2;
108
else
if
(particle ==
G4Gamma::Gamma
()) ih = 3;
109
else
if
(particle ==
G4Alpha::Alpha
()) ih = 4;
110
else
if
(
fCharge
> 2.) ih = 5;
111
if
(ih)
G4AnalysisManager::Instance
()->
FillH1
(ih, Ekin);
112
113
//Ion
114
//
115
if
(
fCharge
> 2.) {
116
//build decay chain
117
if
(ID == 1)
fEvent
->
AddDecayChain
(name);
118
else
fEvent
->
AddDecayChain
(
" ---> "
+ name);
119
//
120
//full chain: put at rest; if not: kill secondary
121
G4Track
* tr = (
G4Track
*) track;
122
if
(
fFullChain
) { tr->
SetKineticEnergy
(0.);
123
tr->
SetTrackStatus
(
fStopButAlive
);}
124
else
if
(ID>1) tr->
SetTrackStatus
(
fStopAndKill
);
125
//
126
fTime_birth
= track->
GetGlobalTime
();
127
}
128
129
//example of saving random number seed of this fEvent, under condition
130
//
132
if
(condition)
G4RunManager::GetRunManager
()->
rndmSaveThisEvent
();
133
}
134
135
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136
137
void
TrackingAction::PostUserTrackingAction
(
const
G4Track
* track)
138
{
139
//keep only ions
140
//
141
if
(
fCharge
< 3. )
return
;
142
143
Run
* run
144
=
static_cast<
Run
*
>
(
G4RunManager::GetRunManager
()->
GetNonConstCurrentRun
());
145
146
G4AnalysisManager
*
analysis
=
G4AnalysisManager::Instance
();
147
148
//get time
149
//
150
G4double
time
= track->
GetGlobalTime
();
151
G4int
ID = track->
GetTrackID
();
152
if
(ID == 1) run->
PrimaryTiming
(time);
//time of life of primary ion
153
fTime_end
=
time
;
154
155
//energy and momentum balance (from secondaries)
156
//
157
const
std::vector<const G4Track*>* secondaries
158
= track->
GetStep
()->
GetSecondaryInCurrentStep
();
159
size_t
nbtrk = (*secondaries).size();
160
if
(nbtrk) {
161
//there are secondaries --> it is a decay
162
//
163
//balance
164
G4double
EkinTot = 0., EkinVis = 0.;
165
G4ThreeVector
Pbalance = - track->
GetMomentum
();
166
for
(
size_t
itr=0; itr<nbtrk; itr++) {
167
const
G4Track
* trk = (*secondaries)[itr];
168
G4ParticleDefinition
* particle = trk->
GetDefinition
();
169
G4double
Ekin = trk->
GetKineticEnergy
();
170
EkinTot += Ekin;
171
G4bool
visible
= !((particle ==
G4NeutrinoE::NeutrinoE
())||
172
(particle ==
G4AntiNeutrinoE::AntiNeutrinoE
()));
173
if
(visible) EkinVis += Ekin;
174
//exclude gamma desexcitation from momentum balance
175
if
(particle !=
G4Gamma::Gamma
()) Pbalance += trk->
GetMomentum
();
176
}
177
G4double
Pbal = Pbalance.
mag
();
178
run->
Balance
(EkinTot,Pbal);
179
analysis->
FillH1
(6,EkinTot);
180
analysis->
FillH1
(7,Pbal);
181
fEvent
->
AddEvisible
(EkinVis);
182
}
183
184
//no secondaries --> end of chain
185
//
186
if
(!nbtrk) {
187
run->
EventTiming
(time);
//total time of life
188
G4double
weight
= track->
GetWeight
();
189
analysis->
FillH1
(8,time,weight);
191
fTime_end
=
DBL_MAX
;
192
}
193
194
//count activity in time window
195
//
196
run->
SetTimeWindow
(
fTimeWindow1
,
fTimeWindow2
);
197
198
G4String
name = track->
GetDefinition
()->
GetParticleName
();
199
G4bool
life1(
false
), life2(
false
),
decay
(
false
);
200
if
((
fTime_birth
<=
fTimeWindow1
)&&(
fTime_end
>
fTimeWindow1
)) life1 =
true
;
201
if
((
fTime_birth
<=
fTimeWindow2
)&&(
fTime_end
>
fTimeWindow2
)) life2 =
true
;
202
if
((
fTime_end
>
fTimeWindow1
)&&(
fTime_end
<
fTimeWindow2
))
decay
=
true
;
203
if
(life1||life2||
decay
) run->
CountInTimeWindow
(name,life1,life2,
decay
);
204
}
205
206
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
207
geant4
tree
geant4-10.6-release
examples
extended
radioactivedecay
rdecay01
src
TrackingAction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:55
using
1.8.2 with
ECCE GitHub integration