ATLAS Offline Software
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 
6 #include "StoreGate/ReadHandle.h"
7 #include "xAODCore/ShallowCopy.h"
9 
10 namespace 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() );
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());
100  for (SG::WriteDecorHandle<xAOD::TauJetContainer, float>& dec : scoreDecors) {
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 }
muonContainer
xAOD::MuonContainer * muonContainer
Definition: TrigGlobEffCorrValidation.cxx:188
ShallowCopy.h
DerivationFramework::TauIDDecoratorWrapper::m_WPDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_WPDecorKeys
Definition: TauIDDecoratorWrapper.h:38
TauIDDecoratorWrapper.h
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
DerivationFramework::TauIDDecoratorWrapper::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: TauIDDecoratorWrapper.cxx:29
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::Accessor< float >
DerivationFramework::TauIDDecoratorWrapper::m_tauIDTools
ToolHandleArray< TauRecToolBase > m_tauIDTools
Definition: TauIDDecoratorWrapper.h:42
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
SG::ConstAccessor< float >
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::TauIDDecoratorWrapper::m_passTATTauMuonOLRKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_passTATTauMuonOLRKey
Definition: TauIDDecoratorWrapper.h:40
DerivationFramework::TauIDDecoratorWrapper::m_doEvetoWP
Gaudi::Property< bool > m_doEvetoWP
Definition: TauIDDecoratorWrapper.h:43
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DerivationFramework::TauIDDecoratorWrapper::m_tauContainerKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContainerKey
Definition: TauIDDecoratorWrapper.h:35
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::TauJetParameters::classifiedIsolation
@ classifiedIsolation
Definition: TauDefs.h:407
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
DerivationFramework::TauIDDecoratorWrapper::m_scoreDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_scoreDecorKeys
Definition: TauIDDecoratorWrapper.h:37
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:44
ReadHandle.h
Handle class for reading from StoreGate.
DerivationFramework::TauIDDecoratorWrapper::initialize
virtual StatusCode initialize() override final
Definition: TauIDDecoratorWrapper.cxx:12
Decorator.h
Helper class to provide type-safe access to aux data.
DerivationFramework::TauIDDecoratorWrapper::m_muonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
Definition: TauIDDecoratorWrapper.h:36
fitman.k
k
Definition: fitman.py:528
DerivationFramework::TauIDDecoratorWrapper::m_trackWidthKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_trackWidthKey
Definition: TauIDDecoratorWrapper.h:39
DerivationFramework::deltaR
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: HIJetAugmentationTool.cxx:47