ATLAS Offline Software
Loading...
Searching...
No Matches
D3PDMCTruthClassifier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
12
13
19
21#include "xAODEgamma/Electron.h"
22#include "xAODEgamma/Photon.h"
23#include "xAODMuon/Muon.h"
24#include "xAODJet/Jet.h"
26
27#include <vector>
28
29
30namespace D3PD {
31
32
40 const std::string& name,
41 const IInterface* parent)
42 : MCTruthClassifier (type, name, parent),
43 m_sg ("StoreGateSvc", name)
44{
45}
46
47
52{
54 CHECK( m_sg.retrieve() );
55 return StatusCode::SUCCESS;
56}
57
58
66{
67 // Try to find the name of the truth map container,
68 // given the name of the TrackParticleContainer.
69 bool got_names = false;
70 std::string tp_truth_name, tp_name;
71 if (el->trackParticleLink().isValid()) {
72 tp_name = el->trackParticleLink().dataID();
73 got_names = get_tptruth_name (tp_name, tp_truth_name);
74 }
75
76 // If we found the truth map container, diddle the properties
77 // for the base tool (remembering the original values).
78 std::string old_tp_truth_name, old_tp_name;
79 if (got_names) {
80 getProperty1 ("TrackParticleTruthCollection", old_tp_truth_name);
81 getProperty1 ("TrackParticleContainerName", old_tp_name);
82 setProperty1 ("TrackParticleTruthCollection", tp_truth_name);
83 setProperty1 ("TrackParticleContainerName", tp_name);
84 }
85
86 // Call the base tool.
90
91 // Restore original properties, if we changed them.
92 if (got_names) {
93 setProperty1 ("TrackParticleTruthCollection", old_tp_truth_name);
94 setProperty1 ("TrackParticleContainerName", old_tp_name);
95 }
96
97 return ret;
98}
99
100
108{
109 // Try to find the name of the truth map container,
110 // given the name of the TrackParticleContainer.
111 bool got_names = false;
112 std::string tp_truth_name, tp_name;
113 const xAOD::Vertex* vx = ph->vertex();
114 if (vx) {
116 for (auto trklink : links) {
117 if (trklink.isValid()) {
118 tp_name = trklink.dataID();
119 got_names = get_tptruth_name (tp_name, tp_truth_name);
120 if (got_names) break;
121 }
122 }
123 }
124
125 // If we found the truth map container, diddle the properties
126 // for the base tool (remembering the original values).
127 std::string old_tp_truth_name, old_tp_name;
128 if (got_names) {
129 getProperty1 ("TrackParticleTruthCollection", old_tp_truth_name);
130 getProperty1 ("TrackParticleContainerName", old_tp_name);
131 setProperty1 ("TrackParticleTruthCollection", tp_truth_name);
132 setProperty1 ("TrackParticleContainerName", tp_name);
133 }
134
135 // Call the base tool.
139
140 // Restore original properties, if we changed them.
141 if (got_names) {
142 setProperty1 ("TrackParticleTruthCollection", old_tp_truth_name);
143 setProperty1 ("TrackParticleContainerName", old_tp_name);
144 }
145
146 return ret;
147}
148
149
156{
157 // Avoid using forward muons that have a tracklet associated to them:
158 if( mu->muonType() == xAOD::Muon::SiliconAssociatedForwardMuon ) {
160 }
161
162 // For all other muons just use the base class's function:
164}
165
166
174bool D3PDMCTruthClassifier::get_tptruth_name (const std::string& tp_name,
175 std::string& tptruth_name)
176{
177 // Check all TrackParticleTruthCollections to try to find one
178 // pointing at the desired TrackParticle container.
179 std::vector<std::string> keys;
181
182 for (size_t i = 0; i < keys.size(); i++) {
183 const TrackParticleTruthCollection* tptc = 0;
184 if (m_sg->retrieve (tptc, keys[i]).isFailure() || !tptc)
185 {
186 ATH_MSG_WARNING( "Can't retrieve TrackParticleTruthCollection/"
187 << keys[i] );
188 continue;
189 }
190 tptruth_name = keys[i];
191
192 std::string target_tp_name;
194 // Older files didn't have this link. Hardcode this case.
195 target_tp_name = "TrackParticleCandidate";
196 }
197 else if (!tptc->trackParticleContainerLink().isValid())
198 continue;
199 else
200 target_tp_name = tptc->trackParticleContainerLink().dataID();
201
202 if (tp_name == target_tp_name)
203 return true;
204 }
205 return false;
206}
207
208
214void D3PDMCTruthClassifier::getProperty1 (const std::string& pname,
215 std::string& value)
216{
217 StatusCode sc = getProperty (pname, value);
218 if (sc.isFailure())
219 REPORT_ERROR (sc) << "Can't get property " << pname << "\n";
220}
221
222
228void D3PDMCTruthClassifier::setProperty1 (const std::string& pname,
229 const std::string& value)
230{
231 StatusCode sc = setProperty (pname, value);
232 if (sc.isFailure())
233 REPORT_ERROR (sc) << "Can't set property " << pname << "\n";
234}
235
236
237} // namespace D3PD
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
#define REPORT_ERROR(SC)
Report an error.
#define CHECK(...)
Evaluate an expression and check for errors.
Work around MCTruthClassifier brain-damage.
static Double_t sc
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
D3PDMCTruthClassifier(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
bool get_tptruth_name(const std::string &tp_name, std::string &tptruth_name)
Try to find a TrackParticleTruthCollection pointing at TP_NAME.
void setProperty1(const std::string &pname, const std::string &value)
Helper to set the value of a Gaudi property.
virtual StatusCode initialize()
Standard Gaudi initialize method.
ServiceHandle< StoreGateSvc > m_sg
The StoreGate service.
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::Electron *el)
Run the classifier for an electron.
void getProperty1(const std::string &pname, std::string &value)
Helper to retrieve the value of a Gaudi property.
bool isDefault() const
Test to see if we're in the default state.
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual std::pair< MCTruthPartClassifier::ParticleType, MCTruthPartClassifier::ParticleOrigin > particleTruthClassifier(const xAOD::TruthParticle *, MCTruthPartClassifier::Info *info=nullptr) const override final
MCTruthClassifier(const std::string &type)
DataLink< Rec::TrackParticleContainer > trackParticleContainerLink() const
const T * getProperty(const std::string &name) const
Get one of the tool's properties.
const xAOD::Vertex * vertex(size_t index=0) const
Pointer to the xAOD::Vertex/es that match the photon candidate.
Definition Photon_v1.cxx:61
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
std::vector< ElementLink< xAOD::TrackParticleContainer > > TrackParticleLinks_t
Type for the associated track particles.
Definition Vertex_v1.h:128
Block filler tool for noisy FEB information.
Vertex_v1 Vertex
Define the latest version of the vertex class.
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".