ATLAS Offline Software
Loading...
Searching...
No Matches
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
9#include <cmath> // std::fabs
10
11
13 asg::AsgTool(name) {
14 declareInterface<IAsgSelectionTool>(this);
15}
16
18
19StatusCode
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
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
70const asg::AcceptInfo&
74
76TrackTruthSelectionTool::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
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 }
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 }
134 if (acceptData) {
136 }
137
138 return acceptData;
139}
140
141StatusCode
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 }
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
std::vector< std::pair< std::string, std::string > > m_cuts
TrackTruthSelectionTool(const std::string &name)
virtual ~TrackTruthSelectionTool()
virtual StatusCode finalize() override
virtual asg::AcceptData accept(const xAOD::IParticle *p) const override
The main accept method: the actual cuts are applied here.
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
std::atomic< ULong64_t > m_numTruthProcessed
std::atomic< ULong64_t > m_numTruthPassed
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
unsigned int getCutPosition(const std::string &cutName) const
Get the bit position of a cut.
Definition AcceptData.h:71
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition AcceptData.h:98
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition AsgTool.h:133
Class providing the definition of the 4-vector interface.
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...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
@ TruthParticle
The object is a truth particle.
Definition ObjectType.h:67
TruthParticle_v1 TruthParticle
Typedef to implementation.