18DiTauTruthMatchingTool::DiTauTruthMatchingTool(
const std::string& name )
19 : BuildTruthTaus(
name)
20 , m_accPtVis(
"pt_vis")
21 , m_accEtaVis(
"eta_vis")
22 , m_accPhiVis(
"phi_vis")
28DiTauTruthMatchingTool::~DiTauTruthMatchingTool( )
34StatusCode DiTauTruthMatchingTool::initialize()
39 DiTauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
41 if (DiTauTruthMatchingTool::BuildTruthTaus::initialize().isFailure())
44 return StatusCode::FAILURE;
46 return StatusCode::SUCCESS;
52 if (retrieveTruthTaus().isFailure())
55 if (findTruthTau(xDiTau).isFailure())
56 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
62void DiTauTruthMatchingTool::getTruth(
const std::vector<const xAOD::DiTauJet*>& vDiTaus)
64 for (
auto xDiTau : vDiTaus)
75StatusCode DiTauTruthMatchingTool::findTruthTau(
const xAOD::DiTauJet& xDiTau)
78 if (!m_bIsTruthMatchedAvailable.isValid()) {
80 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.isAvailable(xDiTau));
82 if (*m_bIsTruthMatchedAvailable.ptr())
83 return StatusCode::SUCCESS;
85 if (m_bTruthTauAvailable)
86 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainerConst);
88 return checkTruthMatch(xDiTau, *m_truthTausEvent.m_xTruthTauContainer);
94 std::vector<const xAOD::TruthParticle*> vTruthMatch;
95 std::vector<TruthMatchedParticleType> vTruthMatchedParticleType;
96 std::vector<const xAOD::Jet*> vTruthJetMatch;
107 if(!(accNSubjets.isAvailable(xDiTau))){
109 while (xDiTau.
subjetPt(n_subjets) > 0. )
114 n_subjets = accNSubjets(xDiTau);
118 for (
int i = 0;
i < n_subjets; ++
i)
123 vTruthMatch.push_back(xTruthMatch);
124 vTruthMatchedParticleType.push_back(eTruthMatchedParticleType);
126 const xAOD::Jet* xTruthJetMatch =
nullptr;
127 vTruthJetMatch.push_back(xTruthJetMatch);
131 for (
int i = 0;
i < n_subjets; ++
i)
133 TLorentzVector vSubjetTLV;
134 vSubjetTLV.SetPtEtaPhiE(xDiTau.
subjetPt(i),
138 if ( truthMatch(vSubjetTLV,
141 vTruthJetMatch.at(i),
142 vTruthMatchedParticleType.at(i)).isFailure() )
144 ATH_MSG_WARNING(
"There was a failure in matching truth taus with subjet " << i);
145 return StatusCode::FAILURE;
147 if (vTruthMatch.at(i) && vTruthMatchedParticleType.at(i) ==
TruthHadronicTau)
149 xRemainingTruthTaus.
erase( std::find(xRemainingTruthTaus.
begin(),
150 xRemainingTruthTaus.
end(),
151 vTruthMatch.at(i)) );
156 std::vector< ElementLink < xAOD::JetContainer > > vTruthJetLinks;
157 for (
int i = 0;
i < n_subjets; ++
i)
159 const xAOD::Jet* xTruthJetMatch = vTruthJetMatch.at(i);
161 ElementLink < xAOD::JetContainer > lTruthParticleLink(xTruthJetMatch, *m_truthTausEvent.m_xTruthJetContainerConst);
162 vTruthJetLinks.push_back(lTruthParticleLink);
166 ElementLink < xAOD::JetContainer > lTruthParticleLink;
167 vTruthJetLinks.push_back(lTruthParticleLink);
171 decTruthJetLinks (
"truthJetLinks");
172 decTruthJetLinks(xDiTau) = std::move(vTruthJetLinks);
175 bool bTruthMatched =
true;
178 std::vector< ElementLink < xAOD::TruthParticleContainer > > vTruthLinks;
179 for (
int i = 0;
i < n_subjets; ++
i)
187 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink(xTruthMatch, xTruthTauContainer);
188 vTruthLinks.push_back(lTruthParticleLink);
190 else if (eTruthMatchedParticleType ==
TruthMuon)
192 ElementLink <xAOD::TruthParticleContainer> lTruthParticleLink(xTruthMatch, *m_truthTausEvent.m_xTruthMuonContainerConst);
193 vTruthLinks.push_back(lTruthParticleLink);
197 ElementLink <xAOD::TruthParticleContainer> lTruthParticleLink(xTruthMatch, *m_truthTausEvent.m_xTruthElectronContainerConst);
198 vTruthLinks.push_back(lTruthParticleLink);
203 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink;
204 vTruthLinks.push_back(lTruthParticleLink);
207 if (i == 0 || i == 1) bTruthMatched =
false;
212 decTruthParticleLinks (
"truthParticleLinks");
213 decTruthParticleLinks(xDiTau) = vTruthLinks;
214 if (!m_bTruthTauAvailable)
217 decTruthTaus (
"TruthTaus");
218 decTruthTaus(xDiTau) = vTruthLinks;
235 if ( n_subjets < 2) {
236 decIsTruthMatched(xDiTau) = (
char)
false;
237 decIsTruthHadronic(xDiTau) = (
char)
false;
238 decTruthLeadPt(xDiTau) = -1234.;
239 decTruthLeadEta(xDiTau) = -1234.;
240 decTruthLeadPhi(xDiTau) = -1234.;
241 decTruthLeadM(xDiTau) = -1234.;
242 decTruthLeadPdgID(xDiTau) = -1234.;
243 decTruthSubleadPt(xDiTau) = -1234.;
244 decTruthSubleadEta(xDiTau) = -1234.;
245 decTruthSubleadPhi(xDiTau) = -1234.;
246 decTruthSubleadM(xDiTau) = -1234.;
247 decTruthSubleadPdgID(xDiTau) = -1234.;
248 decTruthDeltaR(xDiTau) = -1234.;
249 decTruthMass(xDiTau) = -1234.;
250 return StatusCode::SUCCESS;
253 decIsTruthMatched(xDiTau) = (
char)bTruthMatched;
261 decIsTruthHadronic(xDiTau) = (
char)
false;
263 if (accIsTruthHadronic(xDiTau))
265 TLorentzVector tlvTruthTau1;
266 TLorentzVector tlvTruthTau2;
267 tlvTruthTau1.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(0))),
268 m_accEtaVis(*(*vTruthLinks.at(0))),
269 m_accPhiVis(*(*vTruthLinks.at(0))),
270 m_accMVis(*(*vTruthLinks.at(0))));
271 tlvTruthTau2.SetPtEtaPhiM(m_accPtVis(*(*vTruthLinks.at(1))),
272 m_accEtaVis(*(*vTruthLinks.at(1))),
273 m_accPhiVis(*(*vTruthLinks.at(1))),
274 m_accMVis(*(*vTruthLinks.at(1))));
276 decTruthLeadPt(xDiTau) = std::max(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
277 decTruthLeadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Eta() : tlvTruthTau2.Eta();
278 decTruthLeadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.Phi() : tlvTruthTau2.Phi();
279 decTruthLeadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau1.M() : tlvTruthTau2.M();
280 decTruthLeadPdgID(xDiTau) = (*vTruthLinks.at(0))->pdgId();
281 decTruthSubleadPt(xDiTau) = std::min(tlvTruthTau1.Pt(), tlvTruthTau2.Pt());
282 decTruthSubleadEta(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Eta() : tlvTruthTau1.Eta();
283 decTruthSubleadPhi(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.Phi() : tlvTruthTau1.Phi();
284 decTruthSubleadM(xDiTau) = (tlvTruthTau1.Pt() > tlvTruthTau2.Pt()) ? tlvTruthTau2.M() : tlvTruthTau1.M();
285 decTruthSubleadPdgID(xDiTau) = (*vTruthLinks.at(1))->pdgId();
286 decTruthDeltaR(xDiTau) = tlvTruthTau1.DeltaR(tlvTruthTau2);
287 decTruthMass(xDiTau) = (tlvTruthTau1 + tlvTruthTau2).M();
291 decTruthLeadPt(xDiTau) = -1234.;
292 decTruthLeadEta(xDiTau) = -1234.;
293 decTruthLeadPhi(xDiTau) = -1234.;
294 decTruthLeadM(xDiTau) = -1234.;
295 decTruthLeadPdgID(xDiTau) = -1234.;
296 decTruthSubleadPt(xDiTau) = -1234.;
297 decTruthSubleadEta(xDiTau) = -1234.;
298 decTruthSubleadPhi(xDiTau) = -1234.;
299 decTruthSubleadM(xDiTau) = -1234.;
300 decTruthSubleadPdgID(xDiTau) = -1234.;
301 decTruthDeltaR(xDiTau) = -1234.;
302 decTruthMass(xDiTau) = -1234.;
305 return StatusCode::SUCCESS;
308StatusCode DiTauTruthMatchingTool::truthMatch(
const TLorentzVector& vSubjetTLV,
314 for (
auto xTruthTauIt : xTruthTauContainer)
316 TLorentzVector vTruthVisTLV;
317 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
318 m_accEtaVis(*xTruthTauIt),
319 m_accPhiVis(*xTruthTauIt),
320 m_accMVis(*xTruthTauIt));
321 if (vSubjetTLV.DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
324 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
329 xTruthMatch = xTruthTauIt;
334 if (!xTruthMatch and m_truthTausEvent.m_xTruthMuonContainerConst)
337 for (
auto xTruthMuonIt : *m_truthTausEvent.m_xTruthMuonContainerConst)
339 if (vSubjetTLV.DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
341 if (xTruthMuonIt->pt()<dPtMax)
345 xTruthMatch = xTruthMuonIt;
346 dPtMax = xTruthMuonIt->
pt();
351 if (!xTruthMatch and m_truthTausEvent.m_xTruthElectronContainerConst)
354 for (
auto xTruthElectronIt : *m_truthTausEvent.m_xTruthElectronContainerConst)
356 if (vSubjetTLV.DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
358 if (xTruthElectronIt->pt()<dPtMax)
361 xTruthMatch = xTruthElectronIt;
362 dPtMax = xTruthElectronIt->
pt();
367 if (m_truthTausEvent.m_xTruthJetContainerConst)
370 for (
auto xTruthJetIt : *m_truthTausEvent.m_xTruthJetContainerConst)
372 if (vSubjetTLV.DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
374 if (xTruthJetIt->pt()<dPtMax)
376 xTruthJetMatch = xTruthJetIt;
377 dPtMax = xTruthJetIt->
pt();
382 return StatusCode::SUCCESS;
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
iterator erase(iterator position)
Remove element at a given position.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Helper class to provide constant type-safe access to aux data.
float subjetEta(unsigned int numSubjet) const
float subjetE(unsigned int numSubjet) const
float subjetPt(unsigned int numSubjet) const
float subjetPhi(unsigned int numSubjet) const
virtual double pt() const
The transverse momentum ( ) of the particle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Jet_v1 Jet
Definition of the current "jet version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
DiTauJet_v1 DiTauJet
Definition of the current version.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.