ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
ISF
ISF_HepMC
ISF_HepMC_Tools
src
TruthPreselectionTool.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
// ISF_Algs includes
6
#include "
TruthPreselectionTool.h
"
7
#include "
AtlasHepMC/HeavyIon.h
"
8
10
// Public methods:
12
13
// Constructors
15
ISF::TruthPreselectionTool::TruthPreselectionTool
(
const
std::string& t,
const
std::string& n,
const
IInterface* p ) :
16
base_class( t, n, p )
17
{
18
}
19
20
// Athena Algorithm's Hooks
22
StatusCode
ISF::TruthPreselectionTool::initialize
()
23
{
24
ATH_MSG_VERBOSE
(
"Initializing TruthPreselectionTool Algorithm"
);
25
26
if
(!
m_genParticleFilters
.empty())
ATH_CHECK
(
m_genParticleFilters
.retrieve());
27
ATH_CHECK
(
m_quasiStableFilter
.retrieve());
28
29
// intialziation successful
30
return
StatusCode::SUCCESS;
31
}
32
34
bool
ISF::TruthPreselectionTool::passesFilters
(
HepMC::ConstGenParticlePtr
& part,
const
ToolHandleArray<IGenParticleFilter>& filters)
const
35
{
36
// TODO: implement this as a std::find_if with a lambda function
37
for
(
const
auto
& filter : filters ) {
38
// determine if the particle passes current filter
39
bool
passFilter = filter->pass(part);
40
ATH_MSG_VERBOSE
(
"Filter '"
<< filter.typeAndName() <<
"' returned: "
41
<< (passFilter ?
"true, will keep particle."
42
:
"false, will remove particle."
));
43
44
if
(!passFilter)
return
false
;
45
}
46
47
return
true
;
48
}
49
50
bool
ISF::TruthPreselectionTool::identifiedQuasiStableParticleForSim
(
HepMC::ConstGenParticlePtr
& part)
const
51
{
52
bool
b_sim =
false
;
53
if
(
m_quasiStableFilter
->pass(part)) {
54
b_sim =
passesFilters
(part,
m_genParticleFilters
);
55
}
56
return
b_sim;
57
}
58
59
bool
ISF::TruthPreselectionTool::hasQuasiStableAncestorParticle
(
HepMC::ConstGenParticlePtr
& part)
const
60
{
61
// TODO: investigate making this more efficient
62
// Recursively loop over ancestral particles looking for a quasi-stable particle
63
if
(!part->production_vertex() || part->production_vertex()->particles_in().empty()) {
return
false
; }
64
for
(
auto
ancestor: part->production_vertex()->particles_in() ) {
65
// Check ancestor particle for Attribute
66
if
( ancestor->attribute<HepMC3::IntAttribute>(HepMCStr::ShadowParticleId) ) {
return
true
; }
67
if
(
hasQuasiStableAncestorParticle
(ancestor)) {
return
true
; }
68
}
69
return
false
;
70
}
71
72
bool
ISF::TruthPreselectionTool::isPostQuasiStableParticleVertex
(
HepMC::ConstGenVertexPtr
& vtx)
const
73
{
74
// All outgoing particles have already been removed.
75
if
( vtx->particles_out().empty() ) {
return
true
; }
76
return
false
;
77
}
78
79
std::unique_ptr<HepMC::GenEvent>
ISF::TruthPreselectionTool::filterGenEvent
(
const
HepMC::GenEvent
& inputEvent)
const
{
82
std::unique_ptr<HepMC::GenEvent> outputEvent = std::make_unique<HepMC::GenEvent>(inputEvent);
83
if
(inputEvent.run_info()) {
84
outputEvent->set_run_info(std::make_shared<HepMC3::GenRunInfo>(*(inputEvent.run_info().get())));
85
}
86
if
(inputEvent.heavy_ion()) {
87
outputEvent->set_heavy_ion(std::make_shared<HepMC::GenHeavyIon>(*(inputEvent.heavy_ion())));
88
}
89
HepMC::fillBarcodesAttribute
(outputEvent.get());
90
91
// First loop: flag the particles which should be passed to simulation
92
for
(
auto
& particle: outputEvent->particles()) {
93
HepMC::ConstGenParticlePtr
cparticle = particle;
94
if
(
passesFilters
(cparticle,
m_genParticleFilters
)) {
95
// Particle to be simulated
96
const
int
shadowId = particle->id();
97
// Version 1 Use the Id
98
particle->add_attribute(HepMCStr::ShadowParticleId,
99
std::make_shared<HepMC3::IntAttribute>(shadowId));
100
// Version 2 Directly save the ConstGenParticlePtr - needs to link to a version of the GenEvent after zero-lifetime positioner as been applied.
101
// HepMC::ConstGenParticlePtr& shadow = inputEvent.particles().at(shadowId);
102
// particle->add_attribute(HepMCStr::ShadowParticle,
103
// std::make_shared<HepMC::ShadowParticle>(particle));
104
}
105
}
106
// Second loop(s): flag particles (and vertices) to be removed (i.e. those
107
// with ancestor particle flagged to be passed to simulation).
108
for
(;;) {
109
std::vector<HepMC::GenParticlePtr> p_to_remove;
110
std::vector<HepMC::GenVertexPtr> v_to_remove;
111
for
(
auto
& particle: outputEvent->particles()) {
112
HepMC::ConstGenParticlePtr
cparticle = particle;
113
if
(
hasQuasiStableAncestorParticle
(cparticle)) {
114
p_to_remove.push_back(particle);
115
}
116
}
117
for
(
auto
& particle: p_to_remove) outputEvent->remove_particle(particle);
118
for
(
auto
& vertex: outputEvent->vertices()) {
119
HepMC::ConstGenVertexPtr
cvertex = vertex;
120
if
(
isPostQuasiStableParticleVertex
(cvertex)) {
121
v_to_remove.push_back(vertex);
122
}
123
}
124
for
(
auto
& vertex: v_to_remove) outputEvent->remove_vertex(vertex);
125
if
(p_to_remove.empty() && v_to_remove.empty())
break
;
126
}
127
128
return
outputEvent;
129
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
HeavyIon.h
TruthPreselectionTool.h
ISF::TruthPreselectionTool::TruthPreselectionTool
TruthPreselectionTool(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition
TruthPreselectionTool.cxx:15
ISF::TruthPreselectionTool::m_genParticleFilters
ToolHandleArray< IGenParticleFilter > m_genParticleFilters
Filter passes if a difference between the decision of m_genParticleOldFilters and m_genParticleNewFil...
Definition
TruthPreselectionTool.h:44
ISF::TruthPreselectionTool::m_quasiStableFilter
ToolHandle< IGenParticleFilter > m_quasiStableFilter
Definition
TruthPreselectionTool.h:45
ISF::TruthPreselectionTool::filterGenEvent
virtual std::unique_ptr< HepMC::GenEvent > filterGenEvent(const HepMC::GenEvent &inputEvent) const override final
IGenEventFilter interface.
Definition
TruthPreselectionTool.cxx:79
ISF::TruthPreselectionTool::hasQuasiStableAncestorParticle
bool hasQuasiStableAncestorParticle(HepMC::ConstGenParticlePtr &part) const
Definition
TruthPreselectionTool.cxx:59
ISF::TruthPreselectionTool::initialize
virtual StatusCode initialize() override final
Athena algorithm's interface method initialize().
Definition
TruthPreselectionTool.cxx:22
ISF::TruthPreselectionTool::passesFilters
bool passesFilters(HepMC::ConstGenParticlePtr &part, const ToolHandleArray< IGenParticleFilter > &filters) const
check if the given particle passes all filters
Definition
TruthPreselectionTool.cxx:34
ISF::TruthPreselectionTool::identifiedQuasiStableParticleForSim
bool identifiedQuasiStableParticleForSim(HepMC::ConstGenParticlePtr &part) const
Definition
TruthPreselectionTool.cxx:50
ISF::TruthPreselectionTool::isPostQuasiStableParticleVertex
bool isPostQuasiStableParticleVertex(HepMC::ConstGenVertexPtr &vtx) const
Definition
TruthPreselectionTool.cxx:72
HepMC::fillBarcodesAttribute
void fillBarcodesAttribute(GenEvent *e)
Definition
GenEvent.h:393
HepMC::ConstGenParticlePtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition
GenParticle.h:20
HepMC::ConstGenVertexPtr
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition
GenVertex.h:24
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
Generated on
for ATLAS Offline Software by
1.17.0