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")
37 TauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
42 return StatusCode::FAILURE;
44 return StatusCode::SUCCESS;
48 std::unique_ptr<TauTruthMatchingTool::ITruthTausEvent> TauTruthMatchingTool::getEvent()
const
50 auto truthTausEvent = std::make_unique<TruthTausEvent>();
51 if (retrieveTruthTaus(*truthTausEvent).isFailure()) {
52 truthTausEvent.reset();
54 return truthTausEvent;
60 return getTruth (xTau, m_truthTausEvent);
67 TruthTausEvent& truthTausEvent =
dynamic_cast<TruthTausEvent&
> (itruthTausEvent);
69 if (retrieveTruthTaus(truthTausEvent).isFailure())
72 if (findTruthTau(xTau, truthTausEvent).isFailure())
73 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
79 if ( !(*m_bIsTruthMatchedAvailable.ptr()) && (*m_bIsTruthParticleLinkAvailable.ptr())) {
80 ATH_MSG_DEBUG(
"TauJetContainer has truthParticleLink available while IsTruthMatched not available. Re-evaluate IsTruthMatched");
82 if (accTruthParticleLink(xTau)) {
83 decIsTruthMatched(xTau) = (
char)
true;
85 decIsTruthMatched(xTau) = (
char)
false;
90 if (
static_cast<bool>(accIsTruthMatched(xTau)))
92 if (accTruthParticleLink(xTau).isValid())
94 return *accTruthParticleLink(xTau);
109 std::vector<const xAOD::TruthParticle*> vTruths;
110 for (
auto xTau : vTaus)
120 TLorentzVector TauTruthMatchingTool::getTruthTauP4Vis(
const xAOD::TauJet& xTau)
124 if (xTruthTau ==
nullptr)
126 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
128 vTLV = getTruthTauP4Vis(*xTruthTau);
138 if (!
acc.isAvailable(xTruthTau))
141 m_accPtVis(xTruthTau),
142 m_accEtaVis(xTruthTau),
143 m_accPhiVis(xTruthTau),
144 m_accMVis(xTruthTau));
149 TLorentzVector TauTruthMatchingTool::getTruthTauP4Invis(
const xAOD::TauJet& xTau)
153 if (xTruthTau ==
nullptr)
155 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
157 vTLV = getTruthTauP4Invis(*xTruthTau);
175 accPtInvis(xTruthTau),
176 accEtaInvis(xTruthTau),
177 accPhiInvis(xTruthTau),
178 accMInvis(xTruthTau));
191 if (xTruthTau ==
nullptr)
199 ATH_MSG_INFO(
"found truth particle is not a truth tau, return 0");
216 for(
auto iPdgId2 : accDecayModeVector(xTruthTau))
217 if (!bCompareAbsoluteValues)
219 if (iPdgId2 == iPdgId) iNum++;
223 if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
232 if (xTruthTau ==
nullptr)
234 ATH_MSG_DEBUG(
"no truth particle was found, return Mode_Error");
240 ATH_MSG_INFO(
"found truth particle is not a truth tau, return Mode_Error");
243 return getDecayMode(*xTruthTau);
252 ATH_MSG_WARNING(
"passed truth particle is not a truth tau, return Mode_Error");
264 else if (iCharged == 3)
270 if (iCharged == 2 or iCharged == 4 or iCharged == 5)
272 if (iCharged == 0 or iCharged >=6)
285 TruthTausEvent& truthTausEvent)
const
288 if (!m_bIsTruthMatchedAvailable.isValid()) {
290 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.
isAvailable(xTau));
293 if (!m_bIsTruthParticleLinkAvailable.isValid()) {
295 accTruthParticleLink(
"truthParticleLink");
296 m_bIsTruthParticleLinkAvailable.set (accTruthParticleLink.
isAvailable(xTau));
299 if (*m_bIsTruthMatchedAvailable.ptr() || *m_bIsTruthParticleLinkAvailable.ptr()) {
300 return StatusCode::SUCCESS;
307 if (m_bTruthTauAvailable)
308 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainerConst, truthTausEvent);
310 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainer, truthTausEvent);
317 const xAOD::Jet* xTruthJetMatch =
nullptr;
322 for (
auto xTruthTauIt : xTruthTauContainer)
324 TLorentzVector vTruthVisTLV;
325 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
326 m_accEtaVis(*xTruthTauIt),
327 m_accPhiVis(*xTruthTauIt),
328 m_accMVis(*xTruthTauIt));
329 if (xTau.
p4().DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
332 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
337 xTruthMatch = xTruthTauIt;
343 if (!xTruthMatch and truthTausEvent.m_xTruthMuonContainerConst)
346 for (
auto xTruthMuonIt : *truthTausEvent.m_xTruthMuonContainerConst)
348 if (xTau.
p4().DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
350 if (xTruthMuonIt->pt()<dPtMax)
353 xTruthMatch = xTruthMuonIt;
354 dPtMax = xTruthMuonIt->
pt();
359 if (!xTruthMatch and truthTausEvent.m_xTruthElectronContainerConst)
362 for (
auto xTruthElectronIt : *truthTausEvent.m_xTruthElectronContainerConst)
364 if (xTau.
p4().DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
366 if (xTruthElectronIt->pt()<dPtMax)
369 xTruthMatch = xTruthElectronIt;
370 dPtMax = xTruthElectronIt->
pt();
375 if (truthTausEvent.m_xTruthJetContainerConst)
378 for (
auto xTruthJetIt : *truthTausEvent.m_xTruthJetContainerConst)
380 if (xTau.
p4().DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
382 if (xTruthJetIt->pt()<dPtMax)
384 xTruthJetMatch = xTruthJetIt;
385 dPtMax = xTruthJetIt->
pt();
391 decIsTruthMatched(xTau) = (
char)
true;
393 decIsTruthMatched(xTau) = (
char)
false;
398 decTruthJetLink(xTau) = lTruthParticleLink;
403 decTruthJetLink(xTau) = lTruthParticleLink;
414 decTruthParticleLink(xTau) = lTruthParticleLink;
416 else if (eTruthMatchedParticleType ==
TruthMuon)
419 decTruthParticleLink(xTau) = lTruthParticleLink;
424 decTruthParticleLink(xTau) = lTruthParticleLink;
430 decTruthParticleLink(xTau) = lTruthParticleLink;
433 return StatusCode::SUCCESS;
451 taus_nc.lockDecoration (decIsTruthMatched.
auxid());
452 taus_nc.lockDecoration (decTruthJetLink.
auxid());
453 taus_nc.lockDecoration (decTruthParticleLink.
auxid());
454 return StatusCode::SUCCESS;