14TauTruthMatchingTool::TauTruthMatchingTool(
const std::string& name )
15 : BuildTruthTaus(
name)
16 , m_accPtVis(
"pt_vis")
17 , m_accEtaVis(
"eta_vis")
18 , m_accPhiVis(
"phi_vis")
23StatusCode TauTruthMatchingTool::initialize()
28 TauTruthMatchingTool::BuildTruthTaus::setTruthMatchingMode();
30 if (TauTruthMatchingTool::BuildTruthTaus::initialize().isFailure())
33 return StatusCode::FAILURE;
35 return StatusCode::SUCCESS;
39std::unique_ptr<TauTruthMatchingTool::ITruthTausEvent> TauTruthMatchingTool::getEvent()
const
41 const EventContext& ctx = Gaudi::Hive::currentContext();
42 auto truthTausEvent = std::make_unique<TruthTausEvent>();
43 if (retrieveTruthTaus(*truthTausEvent, ctx).isFailure()) {
44 truthTausEvent.reset();
46 return truthTausEvent;
52 return getTruth (xTau, m_truthTausEvent);
57 ITruthTausEvent& itruthTausEvent)
const
59 TruthTausEvent& truthTausEvent =
dynamic_cast<TruthTausEvent&
> (itruthTausEvent);
60 const EventContext& ctx = Gaudi::Hive::currentContext();
61 if (retrieveTruthTaus(truthTausEvent, ctx).isFailure())
64 if (findTruthTau(xTau, truthTausEvent).isFailure())
65 ATH_MSG_WARNING(
"There was a failure in finding the matched truth tau");
71 if ( !(*m_bIsTruthMatchedAvailable.ptr()) && (*m_bIsTruthParticleLinkAvailable.ptr())) {
72 ATH_MSG_DEBUG(
"TauJetContainer has truthParticleLink available while IsTruthMatched not available. Re-evaluate IsTruthMatched");
74 if (accTruthParticleLink(xTau)) {
75 decIsTruthMatched(xTau) = (
char)
true;
77 decIsTruthMatched(xTau) = (
char)
false;
82 if (
static_cast<bool>(accIsTruthMatched(xTau)))
84 if (accTruthParticleLink(xTau).
isValid())
86 return *accTruthParticleLink(xTau);
99std::vector<const xAOD::TruthParticle*> TauTruthMatchingTool::getTruth(
const std::vector<const xAOD::TauJet*>& vTaus)
101 std::vector<const xAOD::TruthParticle*> vTruths;
102 for (
auto xTau : vTaus)
103 vTruths.push_back(getTruth(*xTau));
112TLorentzVector TauTruthMatchingTool::getTruthTauP4Vis(
const xAOD::TauJet& xTau)
116 if (xTruthTau ==
nullptr)
118 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
120 vTLV = getTruthTauP4Vis(*xTruthTau);
126TLorentzVector TauTruthMatchingTool::getTruthTauP4Vis(
const xAOD::TruthParticle& xTruthTau)
const
130 if (!
acc.isAvailable(xTruthTau))
133 m_accPtVis(xTruthTau),
134 m_accEtaVis(xTruthTau),
135 m_accPhiVis(xTruthTau),
136 m_accMVis(xTruthTau));
141TLorentzVector TauTruthMatchingTool::getTruthTauP4Invis(
const xAOD::TauJet& xTau)
145 if (xTruthTau ==
nullptr)
147 ATH_MSG_INFO(
"no truth particle was found, returning TLorentzVector with all values equal to 0");
149 vTLV = getTruthTauP4Invis(*xTruthTau);
155TLorentzVector TauTruthMatchingTool::getTruthTauP4Invis(
const xAOD::TruthParticle& xTruthTau)
const
164 if (!accPtInvis.isAvailable(xTruthTau))
167 accPtInvis(xTruthTau),
168 accEtaInvis(xTruthTau),
169 accPhiInvis(xTruthTau),
170 accMInvis(xTruthTau));
188 for (
auto truth_tau : *truth_taus) {
189 if (!truth_tau->isTau()) {
193 if( accIsHadronicTau(*truth_tau)){
198 if (accDecayModeVector.isAvailable(*truth_tau))
200 std::vector<int> vDecayMode = accDecayModeVector(*truth_tau);
201 for (
auto decayMode : vDecayMode) {
203 if (fabs(decayMode) != 11)
206 if (fabs(decayMode) != 13)
209 TLorentzVector vis = getTruthTauP4Vis(*truth_tau);
210 if (vis.DeltaR(
p->p4()) < 0.2) {
221int TauTruthMatchingTool::getNTauDecayParticles(
const xAOD::TauJet& xTau,
int iPdgId,
bool bCompareAbsoluteValues)
224 if (xTruthTau ==
nullptr)
230 if (!accDecayModeVector.isAvailable(*xTruthTau))
232 ATH_MSG_INFO(
"found truth particle is not a truth tau, return 0");
235 return getNTauDecayParticles(*xTruthTau,iPdgId, bCompareAbsoluteValues);
239int TauTruthMatchingTool::getNTauDecayParticles(
const xAOD::TruthParticle& xTruthTau,
int iPdgId,
bool bCompareAbsoluteValues)
const
243 if (!accDecayModeVector.isAvailable(xTruthTau))
249 for(
auto iPdgId2 : accDecayModeVector(xTruthTau))
250 if (!bCompareAbsoluteValues)
252 if (iPdgId2 == iPdgId) iNum++;
256 if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
265 if (xTruthTau ==
nullptr)
267 ATH_MSG_DEBUG(
"no truth particle was found, return Mode_Error");
271 if (!accNumCharged.isAvailable(*xTruthTau))
273 ATH_MSG_INFO(
"found truth particle is not a truth tau, return Mode_Error");
276 return getDecayMode(*xTruthTau);
283 if (!accNumCharged.isAvailable(xTruthTau))
285 ATH_MSG_WARNING(
"passed truth particle is not a truth tau, return Mode_Error");
289 int iCharged = getNTauDecayParticles(xTruthTau,
MC::PIPLUS,
true) + getNTauDecayParticles(xTruthTau,
MC::KPLUS,
true);
290 int iNeutral = getNTauDecayParticles(xTruthTau,
MC::PI0,
true);
297 else if (iCharged == 3)
303 if (iCharged == 2 or iCharged == 4 or iCharged == 5)
305 if (iCharged == 0 or iCharged >=6)
317StatusCode TauTruthMatchingTool::findTruthTau(
const xAOD::TauJet& xTau,
318 TruthTausEvent& truthTausEvent)
const
321 if (!m_bIsTruthMatchedAvailable.isValid()) {
323 m_bIsTruthMatchedAvailable.set (accIsTruthMatched.isAvailable(xTau));
326 if (!m_bIsTruthParticleLinkAvailable.isValid()) {
328 accTruthParticleLink(
"truthParticleLink");
329 m_bIsTruthParticleLinkAvailable.set (accTruthParticleLink.isAvailable(xTau));
332 if (*m_bIsTruthMatchedAvailable.ptr() || *m_bIsTruthParticleLinkAvailable.ptr()) {
333 if (!m_bForceCheckTruthMatch)
return StatusCode::SUCCESS;
340 if (m_bTruthTauAvailable)
341 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainerConst, truthTausEvent);
343 return checkTruthMatch(xTau, *truthTausEvent.m_xTruthTauContainer, truthTausEvent);
350 const xAOD::Jet* xTruthJetMatch =
nullptr;
355 for (
auto xTruthTauIt : xTruthTauContainer)
357 TLorentzVector vTruthVisTLV;
358 vTruthVisTLV.SetPtEtaPhiM(m_accPtVis(*xTruthTauIt),
359 m_accEtaVis(*xTruthTauIt),
360 m_accPhiVis(*xTruthTauIt),
361 m_accMVis(*xTruthTauIt));
362 if (xTau.
p4().DeltaR(vTruthVisTLV) <= m_dMaxDeltaR)
365 if (
static_cast<bool>(accIsHadronicTau(*xTruthTauIt)))
370 xTruthMatch = xTruthTauIt;
376 if (!xTruthMatch and truthTausEvent.m_xTruthMuonContainerConst)
379 for (
auto xTruthMuonIt : *truthTausEvent.m_xTruthMuonContainerConst)
381 if (xTau.
p4().DeltaR(xTruthMuonIt->p4()) <= m_dMaxDeltaR)
383 if (xTruthMuonIt->pt()<dPtMax)
386 xTruthMatch = xTruthMuonIt;
387 dPtMax = xTruthMuonIt->
pt();
392 if (!xTruthMatch and truthTausEvent.m_xTruthElectronContainerConst)
395 for (
auto xTruthElectronIt : *truthTausEvent.m_xTruthElectronContainerConst)
397 if (xTau.
p4().DeltaR(xTruthElectronIt->p4()) <= m_dMaxDeltaR)
399 if (xTruthElectronIt->pt()<dPtMax)
402 xTruthMatch = xTruthElectronIt;
403 dPtMax = xTruthElectronIt->
pt();
408 if (truthTausEvent.m_xTruthJetContainerConst)
411 for (
auto xTruthJetIt : *truthTausEvent.m_xTruthJetContainerConst)
413 if (xTau.
p4().DeltaR(xTruthJetIt->p4()) <= m_dMaxDeltaR)
415 if (xTruthJetIt->pt()<dPtMax)
417 xTruthJetMatch = xTruthJetIt;
418 dPtMax = xTruthJetIt->
pt();
424 decIsTruthMatched(xTau) = (
char)
true;
426 decIsTruthMatched(xTau) = (
char)
false;
430 ElementLink < xAOD::JetContainer > lTruthParticleLink(xTruthJetMatch, *truthTausEvent.m_xTruthJetContainerConst);
431 decTruthJetLink(xTau) = lTruthParticleLink;
435 ElementLink < xAOD::JetContainer > lTruthParticleLink;
436 decTruthJetLink(xTau) = lTruthParticleLink;
446 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink(xTruthMatch, xTruthTauContainer);
447 decTruthParticleLink(xTau) = lTruthParticleLink;
449 else if (eTruthMatchedParticleType ==
TruthMuon)
451 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink(xTruthMatch, *truthTausEvent.m_xTruthMuonContainerConst);
452 decTruthParticleLink(xTau) = lTruthParticleLink;
456 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink(xTruthMatch, *truthTausEvent.m_xTruthElectronContainerConst);
457 decTruthParticleLink(xTau) = lTruthParticleLink;
462 ElementLink < xAOD::TruthParticleContainer > lTruthParticleLink;
463 decTruthParticleLink(xTau) = lTruthParticleLink;
466 return StatusCode::SUCCESS;
484 taus_nc.lockDecoration (decIsTruthMatched.auxid());
485 taus_nc.lockDecoration (decTruthJetLink.auxid());
486 taus_nc.lockDecoration (decTruthParticleLink.auxid());
487 return StatusCode::SUCCESS;
bool isValid() const
Test to see if the link can be dereferenced.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
#define ATLAS_THREAD_SAFE
Helper class to provide constant type-safe access to aux data.
Class providing the definition of the 4-vector interface.
virtual double pt() const
The transverse momentum ( ) of the particle.
virtual FourMom_t p4() const
The full 4-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.
@ Muon
The object is a muon.
@ Electron
The object is an electron.
Jet_v1 Jet
Definition of the current "jet version".
TauJet_v3 TauJet
Definition of the current "tau version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.