ATLAS Offline Software
Loading...
Searching...
No Matches
TruthTauDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <cmath>
10#include <limits>
11
12
13namespace {
14 const SG::AuxElement::ConstAccessor<double> acc_pt_vis("pt_vis");
15 const SG::AuxElement::ConstAccessor<double> acc_eta_vis("eta_vis");
16 const SG::AuxElement::ConstAccessor<double> acc_phi_vis("phi_vis");
17 const SG::AuxElement::ConstAccessor<double> acc_m_vis("m_vis");
18 const SG::AuxElement::ConstAccessor<unsigned int> acc_classifierType(
19 "classifierParticleType");
20 const SG::AuxElement::ConstAccessor<unsigned int> acc_classifierOutcome(
21 "classifierParticleOutCome");
22}
23
24
25namespace FlavorTagDiscriminants {
26
28 const std::string& name, ISvcLocator* loc)
29 : AthReentrantAlgorithm(name, loc)
30 {
31 }
32
34 ATH_CHECK(m_jetKey.initialize());
35 ATH_CHECK(m_truthTauKey.initialize());
36 ATH_CHECK(m_tauTruthTool.retrieve());
37
38 ATH_CHECK(m_dec_matched.initialize());
39 ATH_CHECK(m_dec_isHadTau.initialize());
40 ATH_CHECK(m_dec_decayMode.initialize());
41 ATH_CHECK(m_dec_deltaPt.initialize());
42 ATH_CHECK(m_dec_ptVis.initialize());
44
45 return StatusCode::SUCCESS;
46 }
47
48 StatusCode TruthTauDecoratorAlg::execute(const EventContext& ctx) const {
50 SG::ReadHandle<TPC> truthTaus(m_truthTauKey, ctx);
51
58
59 const float maxDR = m_maxDeltaR.value();
60
61 for (const xAOD::Jet* jet : *jets) {
62 const xAOD::TruthParticle* best = nullptr;
63 float bestDR = maxDR;
64
65 for (const xAOD::TruthParticle* tau : *truthTaus) {
66 if (acc_classifierType(*tau) != IsoTau) continue;
67
68 TLorentzVector tauVis;
69 tauVis.SetPtEtaPhiM(
70 acc_pt_vis(*tau), acc_eta_vis(*tau),
71 acc_phi_vis(*tau), acc_m_vis(*tau));
72
73 float dR = jet->p4().DeltaR(tauVis);
74 if (dR < bestDR) {
75 bestDR = dR;
76 best = tau;
77 }
78 }
79
80 if (best) {
81 matched(*jet) = 1;
82 deltaPt(*jet) = static_cast<float>(jet->pt() - acc_pt_vis(*best));
83 ptVis(*jet) = acc_pt_vis(*best);
84 outcome(*jet) = acc_classifierOutcome(*best);
85
86 unsigned int prong = acc_classifierOutcome(*best);
87 if (prong == OneProng || prong == ThreeProng || prong == FiveProng) {
88 isHadTau(*jet) = 1;
89 decayMode(*jet) = static_cast<int>(
90 m_tauTruthTool->getDecayMode(*best));
91 } else {
92 isHadTau(*jet) = 0;
93 decayMode(*jet) = -1;
94 }
95 } else {
96 matched(*jet) = 0;
97 deltaPt(*jet) = std::numeric_limits<float>::quiet_NaN();
98 ptVis(*jet) = std::numeric_limits<double>::quiet_NaN();
99 outcome(*jet) = 0;
100 isHadTau(*jet) = -1;
101 decayMode(*jet) = -1;
102 }
103 }
104
105 return StatusCode::SUCCESS;
106 }
107
108}
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for adding a decoration to an object.
@ OneProng
@ FiveProng
@ ThreeProng
@ IsoTau
An algorithm that can be simultaneously executed in multiple threads.
ToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_tauTruthTool
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteDecorHandleKey< JC > m_dec_classifierOutcome
TruthTauDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:570
Handle class for adding a decoration to an object.
Jet_v1 Jet
Definition of the current "jet version".
TruthParticle_v1 TruthParticle
Typedef to implementation.