ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
DerivationFramework::TauIDDecoratorWrapper Class Reference

#include <TauIDDecoratorWrapper.h>

Inheritance diagram for DerivationFramework::TauIDDecoratorWrapper:
Collaboration diagram for DerivationFramework::TauIDDecoratorWrapper:

Public Member Functions

 TauIDDecoratorWrapper (const std::string &t, const std::string &n, const IInterface *p)
 
virtual StatusCode initialize () override
 
virtual StatusCode finalize () override
 
virtual StatusCode addBranches () const override
 

Private Attributes

SG::ReadHandleKey< xAOD::TauJetContainerm_tauContainerKey { this, "TauContainerName", "TauJets", "Input tau container key" }
 
SG::ReadHandleKey< xAOD::MuonContainerm_muonContainerKey { this, "MuonContainerName", "Muons", "Input muon container key" }
 
SG::ReadHandleKey< xAOD::VertexContainerm_vtxContainerKey { this, "VertexContainerName", "PrimaryVertices", "Input PV container key" }
 
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainerm_scoreDecorKeys { this, "ScoreDecorationKeys", {}, "List of score decorations added to the tau"}
 
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainerm_WPDecorKeys { this, "WPDecorationKeys", {}, "List of WP decorations added to the tau"}
 
SG::WriteDecorHandleKey< xAOD::TauJetContainerm_trackWidthKey { this, "TrackWidthKey", m_tauContainerKey, "trackWidth", "Track width decoration name"}
 
SG::WriteDecorHandleKey< xAOD::TauJetContainerm_passTATTauMuonOLRKey { this, "PassTATTauMuonOLRKey", m_tauContainerKey, "passTATTauMuonOLR", "Decoration name"}
 
ToolHandleArray< TauRecToolBasem_tauIDTools { this, "TauIDTools", {}, "" }
 
bool m_doEvetoWP = false
 
std::vector< std::string > m_scores
 
std::vector< std::string > m_WPs
 

Detailed Description

Definition at line 27 of file TauIDDecoratorWrapper.h.

Constructor & Destructor Documentation

◆ TauIDDecoratorWrapper()

DerivationFramework::TauIDDecoratorWrapper::TauIDDecoratorWrapper ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Definition at line 12 of file TauIDDecoratorWrapper.cxx.

12  :
13  base_class(t,n,p)
14  {
15  }

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::TauIDDecoratorWrapper::addBranches ( ) const
overridevirtual

Definition at line 75 of file TauIDDecoratorWrapper.cxx.

76  {
77  const EventContext& ctx = Gaudi::Hive::currentContext();
78 
79  // retrieve tau container
81  if (!tauJetsReadHandle.isValid()) {
82  ATH_MSG_ERROR ("Could not retrieve TauJetContainer with key " << tauJetsReadHandle.key());
83  return StatusCode::FAILURE;
84  }
85  const xAOD::TauJetContainer* tauContainer = tauJetsReadHandle.cptr();
86 
87  // retrieve PrimaryVertices container
89  if (!vtxReadHandle.isValid()) {
90  ATH_MSG_ERROR ("Could not retrieve VertexContainer with key " << vtxReadHandle.key());
91  return StatusCode::FAILURE;
92  }
93  const xAOD::VertexContainer* vtxContainer = vtxReadHandle.cptr();
94  const xAOD::Vertex* pVtx = nullptr;
95  float sumpt_PV0 = 0., sumpt2_PV0 = 0.;
96 
97  // Check that PV container exists and is non-empty, find the PV if possible
98  if (vtxContainer != nullptr && !vtxContainer->empty()) {
99  auto itrVtx = std::find_if(vtxContainer->begin(), vtxContainer->end(),
100  [](const xAOD::Vertex* vtx) {
101  return vtx->vertexType() == xAOD::VxType::PriVtx;
102  });
103  pVtx = (itrVtx == vtxContainer->end() ? nullptr : *itrVtx);
104  if (pVtx == nullptr){
105  ATH_MSG_DEBUG("No PV found, using the first element instead!");
106  pVtx = vtxContainer->at(0);
107  }
108 
110  sumpt_PV0 += (*trk)->pt();
111  sumpt2_PV0 += std::pow((*trk)->pt(), 2.);
112  }
113  }
114 
115  //Create accessors
116  static const SG::Accessor<float> acc_absEtaLead("ABS_ETA_LEAD_TRACK");
117  static const SG::Accessor<float> acc_dz0_TV_PV0("dz0_TV_PV0");
118  static const SG::Accessor<float> acc_log_sumpt_TV("log_sumpt_TV");
119  static const SG::Accessor<float> acc_log_sumpt2_TV("log_sumpt2_TV");
120  static const SG::Accessor<float> acc_log_sumpt_PV0("log_sumpt_PV0");
121  static const SG::Accessor<float> acc_log_sumpt2_PV0("log_sumpt2_PV0");
122 
123  std::vector<SG::WriteDecorHandle<xAOD::TauJetContainer, float> > scoreDecors;
124  scoreDecors.reserve (m_scores.size());
126  scoreDecors.emplace_back (k, ctx);
127  }
128  std::vector<SG::WriteDecorHandle<xAOD::TauJetContainer, char> > WPDecors;
129  WPDecors.reserve (m_WPs.size());
131  WPDecors.emplace_back (k, ctx);
132  }
133 
136  for (const auto tau : *tauContainer) {
137  float tauTrackBasedWidth = 0.;
138  // equivalent to tracks(xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
139  std::vector<const xAOD::TauTrack *> tauTracks = tau->tracks();
141  tauTracks.push_back(trk);
142  }
143  double sumWeightedDR = 0.;
144  double ptSum = 0.;
145  for (const xAOD::TauTrack *track : tauTracks) {
146  double deltaR = tau->p4().DeltaR(track->p4());
147  sumWeightedDR += deltaR * track->pt();
148  ptSum += track->pt();
149  }
150  if (ptSum > 0.) {
151  tauTrackBasedWidth = sumWeightedDR / ptSum;
152  }
153 
154  dec_trackWidth(*tau) = tauTrackBasedWidth;
155  }
156 
157  // create shallow copy
158  auto shallowCopy = xAOD::shallowCopyContainer (*tauContainer);
159 
160  for (auto tau : *shallowCopy.first) {
161 
162  //Add in the TV/PV0 vertex variables needed for some calculators in TauGNNUtils.cxx (for GNTau)
163  float dz0_TV_PV0 = -999., sumpt_TV = 0., sumpt2_TV = 0.;
164  if (pVtx!=nullptr) {
165  dz0_TV_PV0 = tau->vertex()->z() - pVtx->z();
166  for (const ElementLink<xAOD::TrackParticleContainer>& trk : tau->vertex()->trackParticleLinks()) {
167  sumpt_TV += (*trk)->pt();
168  sumpt2_TV += std::pow((*trk)->pt(), 2.);
169  }
170  }
171  acc_dz0_TV_PV0(*tau) = dz0_TV_PV0;
172  acc_log_sumpt_TV(*tau) = (sumpt_TV>0.) ? std::log(sumpt_TV) : 0.;
173  acc_log_sumpt2_TV(*tau) = (sumpt2_TV>0.) ? std::log(sumpt2_TV) : 0.;
174  acc_log_sumpt_PV0(*tau) = (sumpt_PV0>0.) ? std::log(sumpt_PV0) : 0.;
175  acc_log_sumpt2_PV0(*tau) = (sumpt2_PV0>0.) ? std::log(sumpt2_PV0) : 0.;
176 
177  // ABS_ETA_LEAD_TRACK is removed from the AOD content and must be redecorated when computing eVeto WPs
178  // note: this redecoration is not robust against charged track thinning, but charged tracks should never be thinned
179  if (m_doEvetoWP) {
180  float absEtaLead = -1111.;
181  if(tau->nTracks() > 0) {
182  const xAOD::TrackParticle* track = tau->track(0)->track();
183  absEtaLead = std::abs( track->eta() );
184  }
185  acc_absEtaLead(*tau) = absEtaLead;
186  }
187 
188  // pass the shallow copy to the tools
189  for (const auto& tool : m_tauIDTools) {
190  ATH_CHECK( tool->execute(*tau) );
191  }
192 
193  // copy over the relevant decorations (scores and working points)
194  const xAOD::TauJet* xTau = tauContainer->at(tau->index());
195  for (SG::WriteDecorHandle<xAOD::TauJetContainer, float>& dec : scoreDecors) {
196  SG::ConstAccessor<float> scoreAcc (dec.auxid());
197  dec(*xTau) = scoreAcc(*tau);
198  }
200  SG::ConstAccessor<char> WPAcc (dec.auxid());
201  dec(*xTau) = WPAcc(*tau);
202  }
203  }
204 
205  delete shallowCopy.first;
206  delete shallowCopy.second;
207 
208  // add TauAnalysisTool MuonOLR
210  if (!muonReadHandle.isValid()) {
211  ATH_MSG_DEBUG ("Could not retrieve MuonContainer with key " << muonReadHandle.key() << " so won't add TAT MuonOLR flag");
212  return StatusCode::SUCCESS;
213  }
214  const xAOD::MuonContainer* muonContainer = muonReadHandle.cptr();
215 
216  for (const auto tau : *tauContainer) {
217  bool bTauMuonOLR = true;
218  for (auto muon : *muonContainer){
219  if(muon->pt() < 2000.) continue; // pt > 2 GeV
220  if(muon->muonType() == xAOD::Muon::CaloTagged) continue; // not calo-tagged
221  if(muon->p4().DeltaR( tau->p4() ) > 0.2 ) continue; // delta R < 0.2
222  bTauMuonOLR = false; // muon-tau overlapped
223  break;
224  }
225  dec_passTATTauMuonOLR(*tau) = bTauMuonOLR;
226  }
227 
228  return StatusCode::SUCCESS;
229  }

◆ finalize()

StatusCode DerivationFramework::TauIDDecoratorWrapper::finalize ( )
overridevirtual

Definition at line 70 of file TauIDDecoratorWrapper.cxx.

71  {
72  return StatusCode::SUCCESS;
73  }

◆ initialize()

StatusCode DerivationFramework::TauIDDecoratorWrapper::initialize ( )
overridevirtual

Definition at line 17 of file TauIDDecoratorWrapper.cxx.

18  {
19  // initialize tauRecTools tools
20  ATH_CHECK( m_tauIDTools.retrieve() );
21 
22  // parse the properties of TauWPDecorator tools
23  for (const auto& tool : m_tauIDTools) {
24  if (tool->type() != "TauWPDecorator") continue;
25 
26  // check whether we must compute eVeto WPs, as this requires the recalculation of a variable
27  BooleanProperty useAbsEta("UseAbsEta", false);
28  ATH_CHECK( tool->getProperty(&useAbsEta) );
29  if (useAbsEta.value()) {
30  m_doEvetoWP = true;
31  }
32 
33  // retrieve the names of ID scores and WPs
34  StringProperty scoreName("ScoreName", "");
35  ATH_CHECK( tool->getProperty(&scoreName) );
36  // the original RNNEleScore should not be overriden
37  if (scoreName.value() != "RNNEleScore") {
38  m_scores.push_back(scoreName.value());
39  }
40 
41  StringProperty newScoreName("NewScoreName", "");
42  ATH_CHECK( tool->getProperty(&newScoreName) );
43  m_scores.push_back(newScoreName.value());
44 
45  StringArrayProperty decorWPNames("DecorWPNames", {});
46  ATH_CHECK( tool->getProperty(&decorWPNames) );
47  for (const auto& WP : decorWPNames.value()) m_WPs.push_back(WP);
48  }
49 
50  // declare decorations to the scheduler
51  for (const std::string& score : m_scores) {
52  m_scoreDecorKeys.emplace_back(m_tauContainerKey.key() + "." + score);
53  }
54  for (const std::string& WP : m_WPs) {
55  m_WPDecorKeys.emplace_back(m_tauContainerKey.key() + "." + WP);
56  }
57 
58  // initialize read/write handle keys
59  ATH_CHECK( m_tauContainerKey.initialize() );
61  ATH_CHECK( m_vtxContainerKey.initialize() );
62  ATH_CHECK( m_scoreDecorKeys.initialize() );
63  ATH_CHECK( m_WPDecorKeys.initialize() );
64  ATH_CHECK( m_trackWidthKey.initialize() );
65  ATH_CHECK( m_passTATTauMuonOLRKey.initialize() );
66 
67  return StatusCode::SUCCESS;
68  }

Member Data Documentation

◆ m_doEvetoWP

bool DerivationFramework::TauIDDecoratorWrapper::m_doEvetoWP = false
private

Definition at line 45 of file TauIDDecoratorWrapper.h.

◆ m_muonContainerKey

SG::ReadHandleKey<xAOD::MuonContainer> DerivationFramework::TauIDDecoratorWrapper::m_muonContainerKey { this, "MuonContainerName", "Muons", "Input muon container key" }
private

Definition at line 37 of file TauIDDecoratorWrapper.h.

◆ m_passTATTauMuonOLRKey

SG::WriteDecorHandleKey<xAOD::TauJetContainer> DerivationFramework::TauIDDecoratorWrapper::m_passTATTauMuonOLRKey { this, "PassTATTauMuonOLRKey", m_tauContainerKey, "passTATTauMuonOLR", "Decoration name"}
private

Definition at line 42 of file TauIDDecoratorWrapper.h.

◆ m_scoreDecorKeys

SG::WriteDecorHandleKeyArray<xAOD::TauJetContainer> DerivationFramework::TauIDDecoratorWrapper::m_scoreDecorKeys { this, "ScoreDecorationKeys", {}, "List of score decorations added to the tau"}
private

Definition at line 39 of file TauIDDecoratorWrapper.h.

◆ m_scores

std::vector<std::string> DerivationFramework::TauIDDecoratorWrapper::m_scores
private

Definition at line 46 of file TauIDDecoratorWrapper.h.

◆ m_tauContainerKey

SG::ReadHandleKey<xAOD::TauJetContainer> DerivationFramework::TauIDDecoratorWrapper::m_tauContainerKey { this, "TauContainerName", "TauJets", "Input tau container key" }
private

Definition at line 36 of file TauIDDecoratorWrapper.h.

◆ m_tauIDTools

ToolHandleArray<TauRecToolBase> DerivationFramework::TauIDDecoratorWrapper::m_tauIDTools { this, "TauIDTools", {}, "" }
private

Definition at line 44 of file TauIDDecoratorWrapper.h.

◆ m_trackWidthKey

SG::WriteDecorHandleKey<xAOD::TauJetContainer> DerivationFramework::TauIDDecoratorWrapper::m_trackWidthKey { this, "TrackWidthKey", m_tauContainerKey, "trackWidth", "Track width decoration name"}
private

Definition at line 41 of file TauIDDecoratorWrapper.h.

◆ m_vtxContainerKey

SG::ReadHandleKey<xAOD::VertexContainer> DerivationFramework::TauIDDecoratorWrapper::m_vtxContainerKey { this, "VertexContainerName", "PrimaryVertices", "Input PV container key" }
private

Definition at line 38 of file TauIDDecoratorWrapper.h.

◆ m_WPDecorKeys

SG::WriteDecorHandleKeyArray<xAOD::TauJetContainer> DerivationFramework::TauIDDecoratorWrapper::m_WPDecorKeys { this, "WPDecorationKeys", {}, "List of WP decorations added to the tau"}
private

Definition at line 40 of file TauIDDecoratorWrapper.h.

◆ m_WPs

std::vector<std::string> DerivationFramework::TauIDDecoratorWrapper::m_WPs
private

Definition at line 47 of file TauIDDecoratorWrapper.h.


The documentation for this class was generated from the following files:
muonContainer
xAOD::MuonContainer * muonContainer
Definition: TrigGlobEffCorrValidation.cxx:188
DerivationFramework::TauIDDecoratorWrapper::m_WPDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_WPDecorKeys
Definition: TauIDDecoratorWrapper.h:40
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
SG::Accessor< float >
DerivationFramework::TauIDDecoratorWrapper::m_tauIDTools
ToolHandleArray< TauRecToolBase > m_tauIDTools
Definition: TauIDDecoratorWrapper.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::TauIDDecoratorWrapper::m_WPs
std::vector< std::string > m_WPs
Definition: TauIDDecoratorWrapper.h:47
IsoCloseByCorrectionTest.WP
WP
Definition: IsoCloseByCorrectionTest.py:56
xAOD::Vertex_v1::trackParticleLinks
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
TauGNNUtils::Variables::Track::dz0_TV_PV0
bool dz0_TV_PV0(const xAOD::TauJet &tau, const xAOD::TauTrack &, double &out)
Definition: TauGNNUtils.cxx:779
SG::ConstAccessor< float >
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TauIDDecoratorWrapper::m_doEvetoWP
bool m_doEvetoWP
Definition: TauIDDecoratorWrapper.h:45
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
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:42
beamspotman.n
n
Definition: beamspotman.py:731
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
DerivationFramework::TauIDDecoratorWrapper::m_vtxContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxContainerKey
Definition: TauIDDecoratorWrapper.h:38
DerivationFramework::TauIDDecoratorWrapper::m_scores
std::vector< std::string > m_scores
Definition: TauIDDecoratorWrapper.h:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Vertex_v1::z
float z() const
Returns the z position.
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:794
DerivationFramework::TauIDDecoratorWrapper::m_tauContainerKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContainerKey
Definition: TauIDDecoratorWrapper.h:36
xAOD::TauJetParameters::classifiedIsolation
@ classifiedIsolation
Definition: TauDefs.h:407
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
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
xAOD::score
@ score
Definition: TrackingPrimitives.h:514
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DerivationFramework::TauIDDecoratorWrapper::m_scoreDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TauJetContainer > m_scoreDecorKeys
Definition: TauIDDecoratorWrapper.h:39
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DerivationFramework::TauIDDecoratorWrapper::m_muonContainerKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
Definition: TauIDDecoratorWrapper.h:37
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528
DerivationFramework::TauIDDecoratorWrapper::m_trackWidthKey
SG::WriteDecorHandleKey< xAOD::TauJetContainer > m_trackWidthKey
Definition: TauIDDecoratorWrapper.h:41