ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetValidation
InDetPhysValMonitoring
src
TrackTruthSelectionTool.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
// InDetPhysValMonitoring includes
6
#include "
TrackTruthSelectionTool.h
"
7
#include "
TruthUtils/HepMCHelpers.h
"
8
#include "
xAODTruth/TruthVertex.h
"
9
#include <cmath>
// std::fabs
10
11
12
TrackTruthSelectionTool::TrackTruthSelectionTool
(
const
std::string& name) :
13
asg
::
AsgTool
(name) {
14
declareInterface<IAsgSelectionTool>(
this
);
15
}
16
17
TrackTruthSelectionTool::~TrackTruthSelectionTool
() =
default
;
18
19
StatusCode
20
TrackTruthSelectionTool::initialize
() {
21
if
(
asg::AsgTool::initialize
().isFailure()) {
22
return
StatusCode::FAILURE;
23
}
24
ATH_MSG_DEBUG
(
"Initializing "
<< name() <<
"..."
);
25
26
// Define cut names and descriptions
27
m_cuts
.clear();
28
if
(
m_maxEta
> -1) {
29
m_cuts
.emplace_back(
"eta"
,
"Cut on (absolute) particle eta"
);
30
}
31
if
(
m_minPt
> -1) {
32
m_cuts
.emplace_back(
"min_pt"
,
"Cut on minimum particle pT"
);
33
}
34
if
(
m_maxPt
> -1) {
35
m_cuts
.emplace_back(
"max_pt"
,
"Cut on maximum particle pT"
);
36
}
37
38
if
(
m_requireOnlyPrimary
) {
39
m_cuts
.emplace_back(
"OnlyPrimary"
,
"Cut on origin"
);
40
}
41
42
if
(
m_requireCharged
) {
43
m_cuts
.emplace_back(
"charged"
,
"Require charged particle"
);
44
}
45
if
(
m_requireStable
) {
46
m_cuts
.emplace_back(
"stable"
,
"Particle stable"
);
47
}
48
49
if
(
m_maxProdVertRadius
> 0.) {
50
m_cuts
.emplace_back(
"decay_before_pixel"
,
"Decays before first pixel layer"
);
51
}
52
53
if
(
m_pdgId
> -1) {
54
m_cuts
.emplace_back(
"pdgId"
,
"Pdg Id cut"
);
// 3-18-16 normally enabled, disabled for testing
55
}
56
// Add cuts to the AcceptInfo
57
for
(
const
auto
& cut :
m_cuts
) {
58
if
(
m_accept
.addCut(cut.first, cut.second) < 0) {
59
ATH_MSG_ERROR
(
"Failed to add cut "
<< cut.first <<
" because the AcceptInfo object is full."
);
60
return
StatusCode::FAILURE;
61
}
62
}
63
64
// Initialise counters
65
m_numTruthPassedCuts.resize(
m_accept
.getNCuts(), 0);
66
67
return
StatusCode::SUCCESS;
68
}
69
70
const
asg::AcceptInfo
&
71
TrackTruthSelectionTool::getAcceptInfo
( )
const
{
72
return
m_accept
;
73
}
74
75
asg::AcceptData
76
TrackTruthSelectionTool::accept
(
const
xAOD::IParticle
* p)
const
// Is this perhaps supposed to be xAOD::TruthParticle?
77
{
78
// Check if this is a track:
79
if
(!p) {
80
ATH_MSG_ERROR
(
"accept(...) Function received a null pointer"
);
81
return
asg::AcceptData
(&
m_accept
);
82
}
83
if
(p->type() !=
xAOD::Type::TruthParticle
) {
84
ATH_MSG_ERROR
(
"accept(...) Function received a non-TruthParticle"
);
85
return
asg::AcceptData
(&
m_accept
);
86
}
87
88
// Cast it to a track (we have already checked its type so we do not have to dynamic_cast):
89
const
xAOD::TruthParticle
* truth =
static_cast<
const
xAOD::TruthParticle
*
>
(p);
90
91
// Let the specific function do the work:
92
return
accept
(truth);
93
}
94
95
asg::AcceptData
96
TrackTruthSelectionTool::accept
(
const
xAOD::TruthParticle
* p)
const
{
97
asg::AcceptData
acceptData (&
m_accept
);
98
99
// Check cuts
100
if
(
m_maxEta
> -1) {
101
acceptData.
setCutResult
(
"eta"
, (p->pt() > 1e-7 ? (std::fabs(p->eta()) <
m_maxEta
) :
false
));
102
}
103
if
(
m_minPt
> -1) {
104
acceptData.
setCutResult
(
"min_pt"
, (p->pt() >
m_minPt
));
105
}
106
if
(
m_maxPt
> -1) {
107
acceptData.
setCutResult
(
"max_pt"
, (p->pt() <
m_maxPt
));
108
}
109
if
(
m_requireOnlyPrimary
) {
110
acceptData.
setCutResult
(
"OnlyPrimary"
, (!
HepMC::is_simulation_particle
(p)));
111
}
112
113
if
(
m_requireCharged
) {
114
acceptData.
setCutResult
(
"charged"
, (not (p->isNeutral())));
115
}
116
if
(
m_requireStable
) {
117
acceptData.
setCutResult
(
"stable"
, (
MC::isStable
(p)));
118
}
119
if
(
m_maxProdVertRadius
> 0.) {
120
acceptData.
setCutResult
(
"decay_before_pixel"
, (!p->hasProdVtx() || p->prodVtx()->perp() <
m_maxProdVertRadius
));
121
}
122
if
(
m_pdgId
> -1) {
123
acceptData.
setCutResult
(
"pdgId"
, (std::fabs(p->pdgId()) ==
m_pdgId
));
// 3-18-16 normally on, disabled for testing
124
}
125
std::lock_guard<std::mutex>
lock
{
m_mutex
};
// To guard m_numTruthPassedCuts
126
// Book keep cuts
127
for
(
const
auto
& cut :
m_cuts
) {
128
unsigned
int
pos = acceptData.
getCutPosition
(cut.first);
129
if
(acceptData.
getCutResult
(pos)) {
130
m_numTruthPassedCuts[pos]++;
131
}
132
}
133
m_numTruthProcessed
++;
134
if
(acceptData) {
135
m_numTruthPassed
++;
136
}
137
138
return
acceptData;
139
}
140
141
StatusCode
142
TrackTruthSelectionTool::finalize
() {
143
ATH_MSG_INFO
(
"Finalizing "
<< name() <<
"..."
);
144
145
if
(
m_numTruthProcessed
== 0) {
146
ATH_MSG_INFO
(
"No tracks processed in selection tool."
);
147
return
StatusCode::SUCCESS;
148
}
149
ATH_MSG_INFO
(
m_numTruthPassed
<<
" / "
<<
m_numTruthProcessed
<<
" = "
150
<<
m_numTruthPassed
* 100. /
m_numTruthProcessed
<<
"% passed all cuts."
);
151
for
(
const
auto
& cut :
m_cuts
) {
152
ULong64_t numPassed = m_numTruthPassedCuts.at(
m_accept
.getCutPosition(cut.first));
153
ATH_MSG_INFO
(numPassed <<
" = "
<< numPassed * 100. /
m_numTruthProcessed
<<
"% passed "
154
<< cut.first <<
" cut."
);
155
}
156
157
return
StatusCode::SUCCESS;
158
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
HepMCHelpers.h
ATLAS-specific HepMC functions.
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
TrackTruthSelectionTool.h
TruthVertex.h
TrackTruthSelectionTool::m_cuts
std::vector< std::pair< std::string, std::string > > m_cuts
Definition
TrackTruthSelectionTool.h:33
TrackTruthSelectionTool::TrackTruthSelectionTool
TrackTruthSelectionTool(const std::string &name)
Definition
TrackTruthSelectionTool.cxx:12
TrackTruthSelectionTool::~TrackTruthSelectionTool
virtual ~TrackTruthSelectionTool()
TrackTruthSelectionTool::finalize
virtual StatusCode finalize() override
Definition
TrackTruthSelectionTool.cxx:142
TrackTruthSelectionTool::m_pdgId
IntegerProperty m_pdgId
Definition
TrackTruthSelectionTool.h:49
TrackTruthSelectionTool::m_maxEta
FloatProperty m_maxEta
Definition
TrackTruthSelectionTool.h:40
TrackTruthSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *p) const override
The main accept method: the actual cuts are applied here.
Definition
TrackTruthSelectionTool.cxx:76
TrackTruthSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
Definition
TrackTruthSelectionTool.cxx:71
TrackTruthSelectionTool::m_accept
asg::AcceptInfo m_accept
Definition
TrackTruthSelectionTool.h:32
TrackTruthSelectionTool::m_numTruthProcessed
std::atomic< ULong64_t > m_numTruthProcessed
Definition
TrackTruthSelectionTool.h:34
TrackTruthSelectionTool::m_numTruthPassed
std::atomic< ULong64_t > m_numTruthPassed
Definition
TrackTruthSelectionTool.h:35
TrackTruthSelectionTool::m_requireCharged
BooleanProperty m_requireCharged
Definition
TrackTruthSelectionTool.h:44
TrackTruthSelectionTool::m_maxPt
FloatProperty m_maxPt
Definition
TrackTruthSelectionTool.h:41
TrackTruthSelectionTool::m_maxProdVertRadius
FloatProperty m_maxProdVertRadius
Definition
TrackTruthSelectionTool.h:48
TrackTruthSelectionTool::m_requireStable
BooleanProperty m_requireStable
Definition
TrackTruthSelectionTool.h:45
TrackTruthSelectionTool::m_requireOnlyPrimary
BooleanProperty m_requireOnlyPrimary
Definition
TrackTruthSelectionTool.h:43
TrackTruthSelectionTool::m_mutex
std::mutex m_mutex
Definition
TrackTruthSelectionTool.h:37
TrackTruthSelectionTool::m_minPt
FloatProperty m_minPt
Definition
TrackTruthSelectionTool.h:42
TrackTruthSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition
TrackTruthSelectionTool.cxx:20
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::AcceptData::getCutPosition
unsigned int getCutPosition(std::string_view cutName) const
Get the bit position of a cut.
Definition
AcceptData.h:72
asg::AcceptData::getCutResult
bool getCutResult(std::string_view cutName) const
Get the result of a cut, based on the cut name (safer).
Definition
AcceptData.h:99
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
asg::AsgTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition
AsgTool.h:133
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
HepMC::is_simulation_particle
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
Definition
MagicNumbers.h:322
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition
HepMCHelpers.h:46
asg
Definition
DataHandleTestTool.h:28
xAODType::TruthParticle
@ TruthParticle
The object is a truth particle.
Definition
ObjectType.h:67
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
Generated on
for ATLAS Offline Software by
1.17.0