13 TauTruthMatchingTool::TauTruthMatchingTool(
const std::string&
name )
15 , m_accPtVis(
"pt_vis")
16 , m_accEtaVis(
"eta_vis")
17 , m_accPhiVis(
"phi_vis")
27 TauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
32 return StatusCode::FAILURE;
34 return StatusCode::SUCCESS;
38 std::unique_ptr<TauTruthMatchingTool::ITruthTausEvent> TauTruthMatchingTool::getEvent()
const
40 const EventContext& ctx = Gaudi::Hive::currentContext();
41 auto truthTausEvent = std::make_unique<TruthTausEvent>();
42 if (retrieveTruthTaus(*truthTausEvent, ctx).isFailure()) {
43 truthTausEvent.reset();
45 return truthTausEvent;
51 return getTruth (xTau, m_truthTausEvent);
58 TruthTausEvent& truthTausEvent =
dynamic_cast<TruthTausEvent&
> (itruthTausEvent);
59 const EventContext& ctx = Gaudi::Hive::currentContext();
60 if (retrieveTruthTaus(truthTausEvent, ctx).isFailure())
63 if (findTruthTau(xTau, truthTausEvent).isFailure())
64 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
70 if ( !(*m_bIsTruthMatchedAvailable.ptr()) && (*m_bIsTruthParticleLinkAvailable.ptr())) {
71 ATH_MSG_DEBUG(
"TauJetContainer has truthParticleLink available while IsTruthMatched not available. Re-evaluate IsTruthMatched");
73 if (accTruthParticleLink(xTau)) {
74 decIsTruthMatched(xTau) = (
char)
true;
76 decIsTruthMatched(xTau) = (
char)
false;
81 if (
static_cast<bool>(accIsTruthMatched(xTau)))
83 if (accTruthParticleLink(xTau).isValid())
85 return *accTruthParticleLink(xTau);
100 std::vector<const xAOD::TruthParticle*> vTruths;
101 for (
auto xTau : vTaus)
111 TLorentzVector TauTruthMatchingTool::getTruthTauP4Vis(
const xAOD::TauJet& xTau)
115 if (xTruthTau ==
nullptr)
117 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
119 vTLV = getTruthTauP4Vis(*xTruthTau);
129 if (!
acc.isAvailable(xTruthTau))
132 m_accPtVis(xTruthTau),
133 m_accEtaVis(xTruthTau),
134 m_accPhiVis(xTruthTau),
135 m_accMVis(xTruthTau));
140 TLorentzVector TauTruthMatchingTool::getTruthTauP4Invis(
const xAOD::TauJet& xTau)
144 if (xTruthTau ==
nullptr)
146 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
148 vTLV = getTruthTauP4Invis(*xTruthTau);
166 accPtInvis(xTruthTau),
167 accEtaInvis(xTruthTau),
168 accPhiInvis(xTruthTau),
169 accMInvis(xTruthTau));
182 if (xTruthTau ==
nullptr)
190 ATH_MSG_INFO(
"found truth particle is not a truth tau, return 0");
207 for(
auto iPdgId2 : accDecayModeVector(xTruthTau))
208 if (!bCompareAbsoluteValues)
210 if (iPdgId2 == iPdgId) iNum++;
214 if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
223 if (xTruthTau ==
nullptr)
225 ATH_MSG_DEBUG(
"no truth particle was found, return Mode_Error");
231 ATH_MSG_INFO(
"found truth particle is not a truth tau, return Mode_Error");
234 return getDecayMode(*xTruthTau);
243 ATH_MSG_WARNING(
"passed truth particle is not a truth tau, return Mode_Error");
255 else if (iCharged == 3)
261 if (iCharged == 2 or iCharged == 4 or iCharged == 5)
263 if (iCharged == 0 or iCharged >=6)
276 TruthTausEvent& truthTausEvent)
const
279 if (!m_bIsTruthMatchedAvailable.isValid()) {
281 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xTau));
284 if (!m_bIsTruthParticleLinkAvailable.isValid()) {
286 accTruthParticleLink(
"truthParticleLink");
287 m_bIsTruthParticleLinkAvailable.set (accTruthParticleLink.
isAvailable(xTau));
290 if (*m_bIsTruthMatchedAvailable.ptr() || *m_bIsTruthParticleLinkAvailable.ptr()) {
291 return StatusCode::SUCCESS;
298 if (m_bTruthTauAvailable)
299 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainerConst, truthTausEvent);
301 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainer, truthTausEvent);
308 const xAOD::Jet* xTruthJetMatch =
nullptr;
313 for (
auto xTruthTauIt : xTruthTauContainer)
315 TLorentzVector vTruthVisTLV;
316 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
317 m_accEtaVis(*xTruthTauIt),
318 m_accPhiVis(*xTruthTauIt),
319 m_accMVis(*xTruthTauIt));
320 if (xTau.
p4().DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
323 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
328 xTruthMatch = xTruthTauIt;
334 if (!xTruthMatch and truthTausEvent.m_xTruthMuonContainerConst)
337 for (
auto xTruthMuonIt : *truthTausEvent.m_xTruthMuonContainerConst)
339 if (xTau.
p4().DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
341 if (xTruthMuonIt->pt()<dPtMax)
344 xTruthMatch = xTruthMuonIt;
345 dPtMax = xTruthMuonIt->
pt();
350 if (!xTruthMatch and truthTausEvent.m_xTruthElectronContainerConst)
353 for (
auto xTruthElectronIt : *truthTausEvent.m_xTruthElectronContainerConst)
355 if (xTau.
p4().DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
357 if (xTruthElectronIt->pt()<dPtMax)
360 xTruthMatch = xTruthElectronIt;
361 dPtMax = xTruthElectronIt->
pt();
366 if (truthTausEvent.m_xTruthJetContainerConst)
369 for (
auto xTruthJetIt : *truthTausEvent.m_xTruthJetContainerConst)
371 if (xTau.
p4().DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
373 if (xTruthJetIt->pt()<dPtMax)
375 xTruthJetMatch = xTruthJetIt;
376 dPtMax = xTruthJetIt->
pt();
382 decIsTruthMatched(xTau) = (
char)
true;
384 decIsTruthMatched(xTau) = (
char)
false;
389 decTruthJetLink(xTau) = lTruthParticleLink;
394 decTruthJetLink(xTau) = lTruthParticleLink;
405 decTruthParticleLink(xTau) = lTruthParticleLink;
407 else if (eTruthMatchedParticleType ==
TruthMuon)
410 decTruthParticleLink(xTau) = lTruthParticleLink;
415 decTruthParticleLink(xTau) = lTruthParticleLink;
421 decTruthParticleLink(xTau) = lTruthParticleLink;
424 return StatusCode::SUCCESS;
442 taus_nc.lockDecoration (decIsTruthMatched.
auxid());
443 taus_nc.lockDecoration (decTruthJetLink.
auxid());
444 taus_nc.lockDecoration (decTruthParticleLink.
auxid());
445 return StatusCode::SUCCESS;