10 #include "AthLinks/ElementLink.h"
22 TauTruthMatchingTool::TauTruthMatchingTool(
const std::string&
name )
24 , m_accPtVis(
"pt_vis")
25 , m_accEtaVis(
"eta_vis")
26 , m_accPhiVis(
"phi_vis")
38 TauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
43 return StatusCode::FAILURE;
45 return StatusCode::SUCCESS;
49 std::unique_ptr<TauTruthMatchingTool::ITruthTausEvent> TauTruthMatchingTool::getEvent()
const
51 auto truthTausEvent = std::make_unique<TruthTausEvent>();
52 if (retrieveTruthTaus(*truthTausEvent).isFailure()) {
53 truthTausEvent.reset();
55 return truthTausEvent;
61 return getTruth (xTau, m_truthTausEvent);
68 TruthTausEvent& truthTausEvent =
dynamic_cast<TruthTausEvent&
> (itruthTausEvent);
70 if (retrieveTruthTaus(truthTausEvent).isFailure())
73 if (findTruthTau(xTau, truthTausEvent).isFailure())
74 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
80 if ( !(*m_bIsTruthMatchedAvailable.ptr()) && (*m_bIsTruthParticleLinkAvailable.ptr())) {
81 ATH_MSG_DEBUG(
"TauJetContainer has truthParticleLink available while IsTruthMatched not available. Re-evaluate IsTruthMatched");
83 if (accTruthParticleLink(xTau)) {
84 decIsTruthMatched(xTau) = (
char)
true;
86 decIsTruthMatched(xTau) = (
char)
false;
91 if ((
bool)accIsTruthMatched(xTau))
93 if (accTruthParticleLink(xTau).isValid())
95 return *accTruthParticleLink(xTau);
110 std::vector<const xAOD::TruthParticle*> vTruths;
111 for (
auto xTau : vTaus)
121 TLorentzVector TauTruthMatchingTool::getTruthTauP4Vis(
const xAOD::TauJet& xTau)
125 if (xTruthTau ==
nullptr)
127 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
132 m_accPtVis(*xTruthTau),
133 m_accEtaVis(*xTruthTau),
134 m_accPhiVis(*xTruthTau),
135 m_accMVis(*xTruthTau));
144 if (!
acc.isAvailable(xTruthTau))
147 m_accPtVis(xTruthTau),
148 m_accEtaVis(xTruthTau),
149 m_accPhiVis(xTruthTau),
150 m_accMVis(xTruthTau));
155 TLorentzVector TauTruthMatchingTool::getTruthTauP4Invis(
const xAOD::TauJet& xTau)
159 if (xTruthTau ==
nullptr)
161 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
170 accPtInvis(*xTruthTau),
171 accEtaInvis(*xTruthTau),
172 accPhiInvis(*xTruthTau),
173 accMInvis(*xTruthTau));
190 accPtInvis(xTruthTau),
191 accEtaInvis(xTruthTau),
192 accPhiInvis(xTruthTau),
193 accMInvis(xTruthTau));
206 if (xTruthTau ==
nullptr)
214 ATH_MSG_INFO(
"found truth particle is not a truth tau, return 0");
231 for(
auto iPdgId2 : accDecayModeVector(xTruthTau))
232 if (!bCompareAbsoluteValues)
234 if (iPdgId2 == iPdgId) iNum++;
238 if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
247 if (xTruthTau ==
nullptr)
249 ATH_MSG_DEBUG(
"no truth particle was found, return Mode_Error");
255 ATH_MSG_INFO(
"found truth particle is not a truth tau, return Mode_Error");
258 return getDecayMode(*xTruthTau);
267 ATH_MSG_WARNING(
"passed truth particle is not a truth tau, return Mode_Error");
279 else if (iCharged == 3)
285 if (iCharged == 2 or iCharged == 4 or iCharged == 5)
287 if (iCharged == 0 or iCharged >=6)
300 TruthTausEvent& truthTausEvent)
const
303 if (!m_bIsTruthMatchedAvailable.isValid()) {
305 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xTau));
308 if (!m_bIsTruthParticleLinkAvailable.isValid()) {
310 accTruthParticleLink(
"truthParticleLink");
311 m_bIsTruthParticleLinkAvailable.set (accTruthParticleLink.
isAvailable(xTau));
314 if (*m_bIsTruthMatchedAvailable.ptr() || *m_bIsTruthParticleLinkAvailable.ptr()) {
315 return StatusCode::SUCCESS;
322 if (m_bTruthTauAvailable)
323 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainerConst, truthTausEvent);
325 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainer, truthTausEvent);
332 const xAOD::Jet* xTruthJetMatch =
nullptr;
337 for (
auto xTruthTauIt : xTruthTauContainer)
339 TLorentzVector vTruthVisTLV;
340 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
341 m_accEtaVis(*xTruthTauIt),
342 m_accPhiVis(*xTruthTauIt),
343 m_accMVis(*xTruthTauIt));
344 if (xTau.
p4().DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
347 if ((
bool)accIsHadronicTau(*xTruthTauIt))
352 xTruthMatch = xTruthTauIt;
358 if (!xTruthMatch and truthTausEvent.m_xTruthMuonContainerConst)
361 for (
auto xTruthMuonIt : *truthTausEvent.m_xTruthMuonContainerConst)
363 if (xTau.
p4().DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
365 if (xTruthMuonIt->pt()<dPtMax)
368 xTruthMatch = xTruthMuonIt;
369 dPtMax = xTruthMuonIt->
pt();
374 if (!xTruthMatch and truthTausEvent.m_xTruthElectronContainerConst)
377 for (
auto xTruthElectronIt : *truthTausEvent.m_xTruthElectronContainerConst)
379 if (xTau.
p4().DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
381 if (xTruthElectronIt->pt()<dPtMax)
384 xTruthMatch = xTruthElectronIt;
385 dPtMax = xTruthElectronIt->
pt();
390 if (truthTausEvent.m_xTruthJetContainerConst)
393 for (
auto xTruthJetIt : *truthTausEvent.m_xTruthJetContainerConst)
395 if (xTau.
p4().DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
397 if (xTruthJetIt->pt()<dPtMax)
399 xTruthJetMatch = xTruthJetIt;
400 dPtMax = xTruthJetIt->
pt();
406 decIsTruthMatched(xTau) = (
char)
true;
408 decIsTruthMatched(xTau) = (
char)
false;
413 decTruthJetLink(xTau) = lTruthParticleLink;
418 decTruthJetLink(xTau) = lTruthParticleLink;
429 decTruthParticleLink(xTau) = lTruthParticleLink;
431 else if (eTruthMatchedParticleType ==
TruthMuon)
434 decTruthParticleLink(xTau) = lTruthParticleLink;
439 decTruthParticleLink(xTau) = lTruthParticleLink;
445 decTruthParticleLink(xTau) = lTruthParticleLink;
448 return StatusCode::SUCCESS;
466 taus_nc.lockDecoration (decIsTruthMatched.
auxid());
467 taus_nc.lockDecoration (decTruthJetLink.
auxid());
468 taus_nc.lockDecoration (decTruthParticleLink.
auxid());
469 return StatusCode::SUCCESS;