ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_Geant4
ISF_Geant4Tools
src
ISFTrajectory.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// class header
6
#include "
ISFTrajectory.h
"
7
8
// ISF includes
9
#include "
ISF_Event/ISFParticle.h
"
10
#include "
ISF_Event/TruthBinding.h
"
11
#include "
ISF_Interfaces/ITruthSvc.h
"
12
13
// ISF Geant4 includes
14
#include "
ISF_Geant4Event/ISFG4Helper.h
"
15
#include "
ISF_Geant4Event/Geant4TruthIncident.h
"
16
17
// Athena includes
18
//#include "FadsActions/TrackingAction.h"
19
20
// MCTruth includes
21
#include "
MCTruth/TrackInformation.h
"
22
#include "
MCTruth/TrackHelper.h
"
23
24
//HepMC includes
25
#include "
AtlasHepMC/GenParticle.h
"
26
27
#undef _ISFTRAJECTORY_DEBUG_
28
29
iGeant4::ISFTrajectory::ISFTrajectory
()
30
: G4Trajectory()
31
,
m_truthRecordSvcQuick
(nullptr)
32
{
33
}
34
35
iGeant4::ISFTrajectory::ISFTrajectory
(
const
G4Track* aTrack,
36
ISF::ITruthSvc
* truthSvc)
37
: G4Trajectory(aTrack)
38
,
m_truthRecordSvcQuick
(truthSvc)
39
{
40
}
41
42
iGeant4::ISFTrajectory::~ISFTrajectory
()
43
{
44
45
}
46
47
void
iGeant4::ISFTrajectory::AppendStep
(
const
G4Step* aStep)
48
{
49
50
// only use truth service if there are new any secondaries
51
const
int
numSecondaries = aStep->GetSecondaryInCurrentStep()->size();
52
//const int numSecondaries = aStep->GetNumberOfSecondariesInCurrentStep(); //Once we switch to G4 10.2 or later
53
54
if
(numSecondaries) {
55
56
G4Track* track=aStep->GetTrack();
57
#ifdef _ISFTRAJECTORY_DEBUG_
58
std::cout <<
"A new track "
59
<<
" (trackID "
<< track->GetTrackID()
60
<<
"), track pos: "
<<track->GetPosition()
61
<<
", mom: "
<<track->GetMomentum()
62
<<
", parentID "
<< track->GetParentID()
63
<<
", numSec="
<<numSecondaries<<
" is in AppendStep."
<< std::endl;
64
#endif
65
// OK, there was an interaction. look at the track, if it
66
// is not a secondary (i.e. we have a connected tree) we
67
// apply the MC truth machinery...
68
TrackHelper
tHelper(track);
69
if
(tHelper.
IsSecondary
()) {
70
#ifdef _ISFTRAJECTORY_DEBUG_
71
std::cout<<
"is secondary, returning"
<<std::endl;
72
#endif
73
return
;
74
}
75
76
// get base ISFParticle
77
auto
*
trackInfo
=
ISFG4Helper::getISFTrackInfo
(*track);
78
if
(!
trackInfo
) {
79
G4ExceptionDescription
description
;
80
description
<< G4String(
"AppendStep: "
) +
"No VTrackInformation associated with G4Track (trackID: "
81
<< track->GetTrackID() <<
", track pos: "
<<track->GetPosition() <<
", mom: "
<<track->GetMomentum()
82
<<
", parentID "
<< track->GetParentID() <<
")"
;
83
G4Exception(
"iGeant4::ISFTrajectory"
,
"NoVTrackInformation"
, FatalException,
description
);
84
return
;
//The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
85
}
86
87
ISF::ISFParticle
* baseIsp =
trackInfo
->GetBaseISFParticle();
88
if
(!baseIsp) {
89
G4ExceptionDescription
description
;
90
description
<< G4String(
"AppendStep: "
) +
"NULL ISFParticle pointer for current G4Step (trackID "
91
<< track->GetTrackID() <<
", track pos: "
<<track->GetPosition() <<
", mom: "
<<track->GetMomentum()
92
<<
", parentID "
<< track->GetParentID() <<
", numSec="
<<numSecondaries <<
")"
;
93
G4Exception(
"iGeant4::ISFTrajectory"
,
"NoISFParticle"
, FatalException,
description
);
94
return
;
//The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
95
}
96
97
AtlasDetDescr::AtlasRegion
geoID = baseIsp->
nextGeoID
();
98
99
HepMC::GenParticlePtr
currentGenParticle =
trackInfo
->GetCurrentGenParticle();
100
if
(currentGenParticle && currentGenParticle->end_vertex()) {
101
G4ExceptionDescription
description
;
102
description
<< G4String(
"AppendStep: "
) +
"Currently Traced Particle has an end vertex!\n"
;
103
description
<<
"G4Track Properties: trackID = "
<< track->GetTrackID()<<
", Step Number = "
<<track->GetCurrentStepNumber() <<
", parentID = "
<< track->GetParentID() <<
", TrackStatus = "
<< track->GetTrackStatus() <<
"\n"
;
104
description
<<
"G4Step Properties: number of secondaries in the current step: "
<< aStep->GetSecondaryInCurrentStep()->size() <<
"\n"
;
105
description
<<
"currentGenParticle : "
<< currentGenParticle <<
", barcode: "
<<
HepMC::barcode
(currentGenParticle) <<
"\n"
;
106
description
<<
"currentGenParticle->end_vertex(): "
<< currentGenParticle->end_vertex() <<
", barcode: "
<<
HepMC::barcode
(currentGenParticle->end_vertex()) <<
"\n"
;
107
description
<<
"ISFParticle (from TrackInformation): "
<< *baseIsp;
108
HepMC::GenParticlePtr
currentTrackInfoGenParticle =
trackInfo
->GetCurrentGenParticle();
109
if
(currentTrackInfoGenParticle) {
110
description
<<
"currentTrackInfoGenParticle : "
<< currentTrackInfoGenParticle <<
", barcode: "
<<
HepMC::barcode
(currentTrackInfoGenParticle) <<
"\n"
;
111
if
(currentTrackInfoGenParticle->end_vertex()) {
112
description
<<
"currentTrackInfoGenParticle->end_vertex(): "
<< currentTrackInfoGenParticle->end_vertex() <<
", barcode: "
<<
HepMC::barcode
(currentTrackInfoGenParticle->end_vertex()) <<
"\n"
;
113
}
114
else
{
115
description
<<
"currentTrackInfoGenParticle has no end_vertex!\n"
;
116
}
117
}
118
else
{
119
description
<<
" trackInfo->GetHepMCParticle() == nullptr \n"
;
120
}
121
G4Exception(
"iGeant4::ISFTrajectory"
,
"EndVertexExists"
, FatalException,
description
);
122
}
123
iGeant4::Geant4TruthIncident
truth(aStep, geoID);
124
125
if
(
m_truthRecordSvcQuick
) {
126
m_truthRecordSvcQuick
->registerTruthIncident(truth);
127
128
// read the TrackInformation to determine whether the G4Track was
129
// returned to the ISF in this step
130
if
(
trackInfo
->GetReturnedToISF()==
true
) {
131
// make sure that the TruthBinding of the ISFParticle points to the newest
132
// HepMC::GenParticle instance in case it got updated by the
133
// ITruthSvc::registerTruthIncident call above
134
auto
currentGenPart =
trackInfo
->GetCurrentGenParticle();
135
baseIsp->
getTruthBinding
()->
setCurrentGenParticle
( currentGenPart );
136
int
newBarcode =
HepMC::barcode
(currentGenPart);
// FIXME barcode-based
137
baseIsp->
setBarcode
( newBarcode );
// FIXME barcode-based
138
baseIsp->
setStatus
( currentGenPart->status() );
139
int
id
=
HepMC::uniqueID
(currentGenPart);
140
baseIsp->
setId
(
id
);
141
}
142
}
143
else
{
144
G4ExceptionDescription
description
;
145
description
<< G4String(
"AppendStep: "
) +
"m_truthRecordSvcQuick is NULL!"
;
146
G4Exception(
"iGeant4::ISFTrajectory"
,
"NoTruthRecordSvc"
, FatalException,
description
);
147
}
148
}
149
150
G4Trajectory::AppendStep(aStep);
151
}
Geant4TruthIncident.h
GenParticle.h
ISFG4Helper.h
ISFParticle.h
ISFTrajectory.h
ITruthSvc.h
TrackHelper.h
TrackInformation.h
TruthBinding.h
ISF::ISFParticle
The generic ISF particle definition,.
Definition
ISFParticle.h:42
ISF::ISFParticle::getTruthBinding
const TruthBinding * getTruthBinding() const
pointer to the simulation truth - optional, can be 0
ISF::ISFParticle::setBarcode
void setBarcode(int bc)
set a new barcode
ISF::ISFParticle::setId
void setId(int id)
set a new unique ID
ISF::ISFParticle::setStatus
void setStatus(int a)
Definition
ISFParticle.h:188
ISF::ISFParticle::nextGeoID
AtlasDetDescr::AtlasRegion nextGeoID() const
next geoID the particle will be simulated in
ISF::ITruthSvc
@ class ITruthSvc
Definition
ITruthSvc.h:29
ISF::TruthBinding::setCurrentGenParticle
void setCurrentGenParticle(HepMC::GenParticlePtr p)
TrackHelper
Definition
TrackHelper.h:20
TrackHelper::IsSecondary
bool IsSecondary() const
Definition
TrackHelper.cxx:52
iGeant4::Geant4TruthIncident
ISF_Geant4 specific implementation of the ISF::ITruthIncident.
Definition
Geant4TruthIncident.h:42
iGeant4::ISFG4Helper::getISFTrackInfo
static VTrackInformation * getISFTrackInfo(const G4Track &aTrack)
return a valid UserInformation object of the G4Track for use within the ISF
Definition
ISFG4Helper.cxx:66
iGeant4::ISFTrajectory::ISFTrajectory
ISFTrajectory()
Definition
ISFTrajectory.cxx:29
iGeant4::ISFTrajectory::AppendStep
void AppendStep(const G4Step *aStep)
Definition
ISFTrajectory.cxx:47
iGeant4::ISFTrajectory::m_truthRecordSvcQuick
ISF::ITruthSvc * m_truthRecordSvcQuick
Definition
ISFTrajectory.h:26
iGeant4::ISFTrajectory::~ISFTrajectory
~ISFTrajectory()
Definition
ISFTrajectory.cxx:42
description
std::string description
glabal timer - how long have I taken so far?
Definition
hcg.cxx:93
AtlasDetDescr::AtlasRegion
AtlasRegion
A simple enum of ATLAS regions and sub-detectors.
Definition
AtlasRegion.h:21
HepMC::barcode
int barcode(const T *p)
Definition
Barcode.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::GenParticlePtr
HepMC3::GenParticlePtr GenParticlePtr
Definition
GenParticle.h:19
trackInfo
Definition
TrigInDetUtils.h:13
Generated on
for ATLAS Offline Software by
1.17.0