ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
PMGTools
Root
PMGDecayProductsSelectionTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
9
//
10
// includes
11
//
12
13
#include <
PMGTools/PMGDecayProductsSelectionTool.h
>
14
15
#include <
xAODTruth/xAODTruthHelpers.h
>
16
#include <
xAODBase/IParticle.h
>
17
18
#include <sstream>
19
20
//
21
// method implementations
22
//
23
24
namespace
PMGTools
25
{
26
PMGDecayProductsSelectionTool ::
27
PMGDecayProductsSelectionTool (
const
std::string& name)
28
:
AsgTool
(name)
29
{
30
declareProperty
(
"requiredParentPDGIDs"
,
m_requiredParentPDGIDs
,
"required parent particle PDG IDs (positive only)"
);
31
declareProperty
(
"allowedIntermediatePDGIDs"
,
m_allowedIntermediatePDGIDs
,
"allowed intermediate particles PDG IDs (positive only)"
);
32
}
33
34
35
36
StatusCode PMGDecayProductsSelectionTool ::
37
initialize ()
38
{
39
if
(
m_requiredParentPDGIDs
.empty())
40
{
41
ATH_MSG_ERROR
(
"required parent particles need to be set"
);
42
return
StatusCode::FAILURE;
43
}
44
45
m_truthParticleIndex
=
m_accept
.addCut (
"truthParticle"
,
"has truth particle cut"
);
46
47
std::ostringstream particles;
48
for
(
int
pdgId :
m_requiredParentPDGIDs
)
49
{
50
particles <<
" "
<< pdgId;
51
}
52
ATH_MSG_DEBUG
(
"Performing required parent particle selection with parent PDG IDs:"
<< particles.str());
53
m_requiredParentIndex
=
m_accept
.addCut (
"requiredParents"
,
"required parent particles cut"
);
54
55
if
(!
m_allowedIntermediatePDGIDs
.empty())
56
{
57
std::ostringstream particles;
58
for
(
int
pdgId :
m_allowedIntermediatePDGIDs
)
59
{
60
particles <<
" "
<< pdgId;
61
}
62
ATH_MSG_DEBUG
(
"Performing allowed intermediate particle selection with allowed PDG IDs:"
<< particles.str());
63
}
64
65
m_parentsAccessor
= std::make_unique<const SG::AuxElement::Accessor<std::vector<ElementLink<xAOD::TruthParticleContainer>>>>(
"parentLinks"
);
66
67
return
StatusCode::SUCCESS;
68
}
69
70
71
72
const
asg::AcceptInfo
& PMGDecayProductsSelectionTool ::
73
getAcceptInfo ()
const
74
{
75
return
m_accept
;
76
}
77
78
79
80
asg::AcceptData
PMGDecayProductsSelectionTool ::
81
accept (
const
xAOD::IParticle
*particle)
const
82
{
83
asg::AcceptData
acceptData (&
m_accept
);
84
85
// Check if xAOD::TruthParticle or if not if it has the TruthParticleLink
86
const
xAOD::TruthParticle
*truthParticle
87
=
dynamic_cast<
const
xAOD::TruthParticle
*
>
(particle);
88
if
(truthParticle ==
nullptr
)
89
{
90
// need to find the truth particle
91
truthParticle =
xAOD::TruthHelpers::getTruthParticle
(*particle);
92
if
(truthParticle ==
nullptr
)
93
{
94
acceptData.
setCutResult
(
m_truthParticleIndex
,
false
);
95
return
acceptData;
96
}
97
}
98
acceptData.
setCutResult
(
m_truthParticleIndex
,
true
);
99
100
return
hasRequiredInitialParent
(truthParticle, acceptData);
101
}
102
103
104
105
asg::AcceptData
PMGDecayProductsSelectionTool ::
106
hasRequiredInitialParent (
const
xAOD::TruthParticle
*truthParticle,
asg::AcceptData
& acceptData)
const
{
107
const
int
i = 0;
108
const
xAOD::TruthParticle
*parent =
getParent
(truthParticle, i);
109
if
(parent) {
110
if
(std::find(
m_requiredParentPDGIDs
.begin(),
m_requiredParentPDGIDs
.end(), std::abs(parent->pdgId())) !=
m_requiredParentPDGIDs
.end()){
111
acceptData.
setCutResult
(
m_requiredParentIndex
,
true
);
112
return
acceptData;
113
}
else
if
(
m_allowedIntermediatePDGIDs
.empty() || std::find(
m_allowedIntermediatePDGIDs
.begin(),
m_allowedIntermediatePDGIDs
.end(), std::abs(parent->pdgId())) !=
m_allowedIntermediatePDGIDs
.end()){
114
return
hasRequiredInitialParent
(parent, acceptData);
115
}
else
{
116
ATH_MSG_VERBOSE
(
"Removing particle as parent is not allowed: "
<< parent->pdgId());
117
return
acceptData;
118
}
119
}
120
ATH_MSG_WARNING
(
"Particle parent is not valid"
);
121
return
acceptData;
122
}
123
124
125
126
size_t
PMGDecayProductsSelectionTool ::
127
getNParents (
const
xAOD::TruthParticle
*truthParticle)
const
128
{
129
if
(
m_parentsAccessor
->isAvailable (*truthParticle))
130
{
131
return
(*
m_parentsAccessor
)(*truthParticle).size();
132
}
133
else
134
{
135
return
truthParticle->
nParents
();
136
}
137
}
138
139
140
141
const
xAOD::TruthParticle
* PMGDecayProductsSelectionTool ::
142
getParent (
const
xAOD::TruthParticle
*truthParticle,
143
size_t
index
)
const
144
{
145
if
(
m_parentsAccessor
->isAvailable (*truthParticle))
146
{
147
ElementLink<xAOD::TruthParticleContainer>
parentElementLink
148
= (*m_parentsAccessor)(*truthParticle).at(
index
);
149
return
parentElementLink.
isValid
() ? *parentElementLink :
nullptr
;
150
}
151
else
152
{
153
return
truthParticle->
parent
(
index
);
154
}
155
}
156
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
IParticle.h
PMGDecayProductsSelectionTool.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
ElementLink::isValid
bool isValid() const
Check if the element can be found.
PMGTools::PMGDecayProductsSelectionTool::m_parentsAccessor
std::unique_ptr< const SG::AuxElement::Accessor< std::vector< ElementLink< xAOD::TruthParticleContainer > > > > m_parentsAccessor
common parents accessor
Definition
PMGDecayProductsSelectionTool.h:87
PMGTools::PMGDecayProductsSelectionTool::getParent
const xAOD::TruthParticle * getParent(const xAOD::TruthParticle *truthParticle, size_t index) const
Helper function get a parent by index.
Definition
PMGDecayProductsSelectionTool.cxx:142
PMGTools::PMGDecayProductsSelectionTool::m_requiredParentPDGIDs
std::vector< int > m_requiredParentPDGIDs
tool properties
Definition
PMGDecayProductsSelectionTool.h:70
PMGTools::PMGDecayProductsSelectionTool::m_requiredParentIndex
int m_requiredParentIndex
Index for the required parent particles.
Definition
PMGDecayProductsSelectionTool.h:79
PMGTools::PMGDecayProductsSelectionTool::m_truthParticleIndex
int m_truthParticleIndex
Index for the truth particle link.
Definition
PMGDecayProductsSelectionTool.h:77
PMGTools::PMGDecayProductsSelectionTool::m_accept
asg::AcceptInfo m_accept
the AcceptInfo we are using
Definition
PMGDecayProductsSelectionTool.h:83
PMGTools::PMGDecayProductsSelectionTool::hasRequiredInitialParent
asg::AcceptData hasRequiredInitialParent(const xAOD::TruthParticle *truthParticle, asg::AcceptData &acceptData) const
Helper function to check for required parent particles.
Definition
PMGDecayProductsSelectionTool.cxx:106
PMGTools::PMGDecayProductsSelectionTool::m_allowedIntermediatePDGIDs
std::vector< int > m_allowedIntermediatePDGIDs
Definition
PMGDecayProductsSelectionTool.h:71
asg::AcceptData
Definition
AcceptData.h:31
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer).
Definition
AcceptData.h:135
asg::AcceptInfo
Definition
AcceptInfo.h:28
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::TruthParticle_v1::parent
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition
TruthParticle_v1.cxx:126
xAOD::TruthParticle_v1::nParents
size_t nParents() const
Number of parents of this particle.
Definition
TruthParticle_v1.cxx:117
PMGTools
Tool providing sample cross-sections and k-factors etc.
Definition
AnalysisCommon/PMGTools/PMGTools/IPMGSherpaVjetsSysTool.h:16
index
Definition
index.py:1
xAOD::TruthHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
Definition
xAODTruthHelpers.cxx:25
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAODTruthHelpers.h
Generated on
for ATLAS Offline Software by
1.17.0