ATLAS Offline Software
Loading...
Searching...
No Matches
TauIDDecoratorWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10namespace DerivationFramework {
11
13 {
14 // initialize tauRecTools tools
15 ATH_CHECK( m_tauIDTools.retrieve() );
16
17 // initialize read/write handle keys
18 ATH_CHECK( m_tauContainerKey.initialize() );
19 ATH_CHECK( m_muonContainerKey.initialize() );
20 ATH_CHECK( m_scoreDecorKeys.initialize() );
21 ATH_CHECK( m_WPDecorKeys.initialize() );
22 ATH_CHECK( m_trackWidthKey.initialize() );
23 ATH_CHECK( m_passTATTauMuonOLRKey.initialize() );
24
25 return StatusCode::SUCCESS;
26 }
27
28
29 StatusCode TauIDDecoratorWrapper::addBranches(const EventContext& ctx) const
30 {
31
32 // retrieve tau container
34 if (!tauJetsReadHandle.isValid()) {
35 ATH_MSG_ERROR ("Could not retrieve TauJetContainer with key " << tauJetsReadHandle.key());
36 return StatusCode::FAILURE;
37 }
38 const xAOD::TauJetContainer* tauContainer = tauJetsReadHandle.cptr();
39
40 //Create accessors
41 static const SG::Accessor<float> acc_absEtaLead("ABS_ETA_LEAD_TRACK");
42
43 std::vector<SG::WriteDecorHandle<xAOD::TauJetContainer, float> > scoreDecors;
44 scoreDecors.reserve (m_scoreDecorKeys.size());
46 scoreDecors.emplace_back (k, ctx);
47 }
48 std::vector<SG::WriteDecorHandle<xAOD::TauJetContainer, char> > WPDecors;
49 WPDecors.reserve (m_WPDecorKeys.size());
51 WPDecors.emplace_back (k, ctx);
52 }
53
56 for (const auto tau : *tauContainer) {
57 float tauTrackBasedWidth = 0.;
58 // equivalent to tracks(xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
59 std::vector<const xAOD::TauTrack *> tauTracks = tau->tracks();
61 tauTracks.push_back(trk);
62 }
63 double sumWeightedDR = 0.;
64 double ptSum = 0.;
65 for (const xAOD::TauTrack *track : tauTracks) {
66 double deltaR = tau->p4().DeltaR(track->p4());
67 sumWeightedDR += deltaR * track->pt();
68 ptSum += track->pt();
69 }
70 if (ptSum > 0.) {
71 tauTrackBasedWidth = sumWeightedDR / ptSum;
72 }
73
74 dec_trackWidth(*tau) = tauTrackBasedWidth;
75 }
76
77 // create shallow copy
78 auto shallowCopy = xAOD::shallowCopyContainer (*tauContainer);
79
80 for (auto tau : *shallowCopy.first) {
81
82 // ABS_ETA_LEAD_TRACK is removed from the AOD content and must be redecorated when computing eVeto WPs
83 // note: this redecoration is not robust against charged track thinning, but charged tracks should never be thinned
84 if (m_doEvetoWP) {
85 float absEtaLead = -1111.;
86 if(tau->nTracks() > 0) {
87 const xAOD::TrackParticle* track = tau->track(0)->track();
88 absEtaLead = std::abs( track->eta() );
89 }
90 acc_absEtaLead(*tau) = absEtaLead;
91 }
92
93 // pass the shallow copy to the tools
94 for (const auto& tool : m_tauIDTools) {
95 ATH_CHECK( tool->execute(*tau) );
96 }
97
98 // copy over the relevant decorations (scores and working points)
99 const xAOD::TauJet* xTau = tauContainer->at(tau->index());
101 SG::ConstAccessor<float> scoreAcc (dec.auxid());
102 dec(*xTau) = scoreAcc(*tau);
103 }
105 SG::ConstAccessor<char> WPAcc (dec.auxid());
106 dec(*xTau) = WPAcc(*tau);
107 }
108 }
109
110 delete shallowCopy.first;
111 delete shallowCopy.second;
112
113 // add TauAnalysisTool MuonOLR
115 if (!muonReadHandle.isValid()) {
116 ATH_MSG_DEBUG ("Could not retrieve MuonContainer with key " << muonReadHandle.key() << " so won't add TAT MuonOLR flag");
117 return StatusCode::SUCCESS;
118 }
119 const xAOD::MuonContainer* muonContainer = muonReadHandle.cptr();
120
121 for (const auto tau : *tauContainer) {
122 bool bTauMuonOLR = true;
123 for (auto muon : *muonContainer){
124 if(muon->pt() < 2000.) continue; // pt > 2 GeV
125 if(muon->muonType() == xAOD::Muon::CaloTagged) continue; // not calo-tagged
126 if(muon->p4().DeltaR( tau->p4() ) > 0.2 ) continue; // delta R < 0.2
127 bTauMuonOLR = false; // muon-tau overlapped
128 break;
129 }
130 dec_passTATTauMuonOLR(*tau) = bTauMuonOLR;
131 }
132
133 return StatusCode::SUCCESS;
134 }
135}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide type-safe access to aux data.
Handle class for reading from StoreGate.
xAOD::MuonContainer * muonContainer
const T * at(size_type n) const
Access an element, as an rvalue.
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContainerKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_trackWidthKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_passTATTauMuonOLRKey
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_WPDecorKeys
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
virtual StatusCode initialize() override final
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_scoreDecorKeys
ToolHandleArray< TauRecToolBase > m_tauIDTools
Helper class to provide type-safe access to aux data.
Helper class to provide constant type-safe access to aux data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
THE reconstruction tool.
double deltaR(double eta1, double eta2, double phi1, double phi2)
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TauTrack_v1 TauTrack
Definition of the current version.
Definition TauTrack.h:16
TauJet_v3 TauJet
Definition of the current "tau version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".