ATLAS Offline Software
TauAODRunnerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TauAODRunnerAlg.h"
6 
7 TauAODRunnerAlg::TauAODRunnerAlg(const std::string &name, ISvcLocator *pSvcLocator) :
8  AthReentrantAlgorithm(name, pSvcLocator) {}
9 
10 
12  if (m_modificationTools.empty()) {
13  ATH_MSG_ERROR("no mod tools given!");
14  return StatusCode::FAILURE;
15  }
16  ATH_CHECK(m_tauContainer.initialize());
18  ATH_CHECK(m_tauOutContainer.initialize());
19  ATH_CHECK(m_pi0Container.initialize());
24  ATH_CHECK(m_vertexOutputContainer.initialize());
25 
26  ATH_CHECK(m_modificationTools.retrieve());
27  ATH_CHECK(m_officialTools.retrieve());
28 
29  ATH_MSG_INFO("List of modification tools in execution sequence:");
30  ATH_MSG_INFO("------------------------------------");
31  uint tool_count = 0;
32  for (const auto &tool : m_modificationTools) {
33  ++tool_count;
34  ATH_MSG_INFO(tool->type() << " - " << tool->name());
35  }
36  ATH_MSG_INFO("List of official tools in execution sequence:");
37  ATH_MSG_INFO("------------------------------------");
38  for (const auto &tool : m_officialTools) {
39  ++tool_count;
40  ATH_MSG_INFO(tool->type() << " - " << tool->name());
41  }
42  ATH_MSG_INFO("------------------------------------");
43  if (tool_count == 0) {
44  ATH_MSG_ERROR("could not allocate any tool!");
45  return StatusCode::FAILURE;
46  }
47  return StatusCode::SUCCESS;
48 }
49 
50 
51 StatusCode TauAODRunnerAlg::execute (const EventContext& ctx) const {
52  // Read in tau jets
54  if (!tauInputHandle.isValid()) {
55  ATH_MSG_ERROR("Could not retrieve HiveDataObj with key " << tauInputHandle.key());
56  return StatusCode::FAILURE;
57  }
58  const xAOD::TauJetContainer *pTauContainer = tauInputHandle.cptr();
59 
61  ATH_CHECK(outputTauTrackHandle.record(std::make_unique<xAOD::TauTrackContainer>(), std::make_unique<xAOD::TauTrackAuxContainer>()));
62  xAOD::TauTrackContainer *newTauTrkCon = outputTauTrackHandle.ptr();
63 
65  ATH_CHECK(outputTauHandle.record(std::make_unique<xAOD::TauJetContainer>(), std::make_unique<xAOD::TauJetAuxContainer>()));
66  xAOD::TauJetContainer *newTauCon = outputTauHandle.ptr();
67 
68  static const SG::Accessor<ElementLink<xAOD::TauJetContainer>> acc_ori_tau_link("originalTauJet");
69  static const SG::Accessor<char> acc_modified("ModifiedInAOD");
70 
71  for (const xAOD::TauJet *tau : *pTauContainer) {
72  // deep copy the tau container
73  xAOD::TauJet *newTau = new xAOD::TauJet();
74  newTauCon->push_back(newTau);
75  *newTau = *tau;
76  //link the original tau to the deepcopy
77  ElementLink<xAOD::TauJetContainer> link_to_ori_tau;
78  link_to_ori_tau.toContainedElement(*pTauContainer, tau);
79  acc_ori_tau_link(*newTau) = link_to_ori_tau;
80  //clear the tautrack links to allow relinking.
81  newTau->clearTauTrackLinks();
82  for (const auto *tauTrk : tau->allTracks()) {
83  xAOD::TauTrack *newTauTrk = new xAOD::TauTrack();
84  // deep copy the tau track
85  newTauTrkCon->push_back(newTauTrk);
86  *newTauTrk = *tauTrk;
88  // relink the tautrack
89  linkToTauTrack.toContainedElement(*newTauTrkCon, newTauTrk);
90  newTau->addTauTrackLink(linkToTauTrack);
91  }
92 
93  // 'ModifiedInAOD' will be overriden by modification tools for relevant candidates
94  acc_modified(*newTau) = static_cast<char>(false);
95 
96  StatusCode sc;
97  for (const ToolHandle<ITauToolBase> &tool : m_modificationTools) {
98  ATH_MSG_DEBUG("RunnerAlg Invoking tool " << tool->name());
99  sc = tool->execute(*newTau);
100  if (sc.isFailure()) break;
101  }
102 
103  // if tau candidate was not modified, remove it from container, track cleanup performed by thinning algorithm downstream
104  if (!acc_modified(*newTau)) {
105  newTauCon->pop_back();
106  }
107  }
108 
109  // Read the CaloClusterContainer
111  if (!pi0ClusterInHandle.isValid()) {
112  ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << pi0ClusterInHandle.key());
113  return StatusCode::FAILURE;
114  }
115  const xAOD::CaloClusterContainer * pi0ClusterContainer = pi0ClusterInHandle.cptr();
116 
117  // write charged PFO container
119  ATH_CHECK(chargedPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
120  xAOD::PFOContainer* chargedPFOContainer = chargedPFOHandle.ptr();
121 
122  // write neutral PFO container
124  ATH_CHECK(neutralPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
125  xAOD::PFOContainer* neutralPFOContainer = neutralPFOHandle.ptr();
126 
127  // write pi0 container
129  ATH_CHECK(pi0Handle.record(std::make_unique<xAOD::ParticleContainer>(), std::make_unique<xAOD::ParticleAuxContainer>()));
130  xAOD::ParticleContainer *pi0Container = pi0Handle.ptr();
131 
132  // write hadronic cluster PFO container
134  ATH_CHECK(hadronicPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
135  xAOD::PFOContainer* hadronicClusterPFOContainer = hadronicPFOHandle.ptr();
136 
137  // write secondary vertices
139  ATH_CHECK(vertOutHandle.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
140  xAOD::VertexContainer* pSecVtxContainer = vertOutHandle.ptr();
141 
142  for (xAOD::TauJet *pTau : *newTauCon) {
143  StatusCode sc;
144  for (const ToolHandle<ITauToolBase> &tool : m_officialTools) {
145  ATH_MSG_DEBUG("RunnerAlg Invoking tool " << tool->name());
146  if (tool->type() == "TauPi0ClusterCreator")
147  sc = tool->executePi0ClusterCreator(*pTau, *neutralPFOContainer, *hadronicClusterPFOContainer, *pi0ClusterContainer);
148  else if (tool->type() == "TauVertexVariables")
149  sc = tool->executeVertexVariables(*pTau, *pSecVtxContainer);
150  else if (tool->type() == "TauPi0ClusterScaler")
151  sc = tool->executePi0ClusterScaler(*pTau, *neutralPFOContainer, *chargedPFOContainer);
152  else if (tool->type() == "TauPi0ScoreCalculator")
153  sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
154  else if (tool->type() == "TauPi0Selector")
155  sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
156  else if (tool->type() == "PanTau::PanTauProcessor")
157  sc = tool->executePanTau(*pTau, *pi0Container, *neutralPFOContainer);
158  else if (tool->type() == "tauRecTools::TauTrackRNNClassifier")
159  sc = tool->executeTrackClassifier(*pTau, *newTauTrkCon);
160  else
161  sc = tool->execute(*pTau);
162  if (sc.isFailure()) break;
163  }
164  if (sc.isSuccess()) ATH_MSG_VERBOSE("The tau candidate has been modified successfully by the invoked official tools.");
165  }
166 
167  ATH_MSG_VERBOSE("The tau candidate container has been modified by the rest of the tools");
168  ATH_MSG_DEBUG(newTauCon->size() << " / " << pTauContainer->size() <<" taus were modified");
169 
170  return StatusCode::SUCCESS;
171 }
172 
173 
174 //helper
176  static const SG::ConstAccessor<char> acc_modified("ModifiedInAOD");
177  return acc_modified(*newtau);
178 }
TauAODRunnerAlg::m_neutralPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_neutralPFOOutputContainer
Definition: TauAODRunnerAlg.h:56
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TauAODRunnerAlg::m_chargedPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_chargedPFOOutputContainer
Definition: TauAODRunnerAlg.h:57
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TauAODRunnerAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TauAODRunnerAlg.cxx:51
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::TauJet_v3::clearTauTrackLinks
void clearTauTrackLinks()
Remove all tracks from the tau.
Definition: TauJet_v3.cxx:567
SG::ConstAccessor< char >
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TauAODRunnerAlg::m_modificationTools
ToolHandleArray< ITauToolBase > m_modificationTools
Definition: TauAODRunnerAlg.h:49
TauAODRunnerAlg::m_hadronicPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_hadronicPFOOutputContainer
Definition: TauAODRunnerAlg.h:58
TauAODRunnerAlg::m_vertexOutputContainer
SG::WriteHandleKey< xAOD::VertexContainer > m_vertexOutputContainer
Definition: TauAODRunnerAlg.h:60
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
TauAODRunnerAlg::m_tauTrackOutputContainer
SG::WriteHandleKey< xAOD::TauTrackContainer > m_tauTrackOutputContainer
Definition: TauAODRunnerAlg.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TauAODRunnerAlg::isTauModified
static bool isTauModified(const xAOD::TauJet *newtau)
Definition: TauAODRunnerAlg.cxx:175
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauAODRunnerAlg::m_pi0ClusterInputContainer
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_pi0ClusterInputContainer
Definition: TauAODRunnerAlg.h:53
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
xAOD::TauJet_v3::addTauTrackLink
void addTauTrackLink(const ElementLink< TauTrackContainer > &tr)
add a TauTrack to the tau
Definition: TauJet_v3.cxx:563
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TauJet
TauJet_v3 TauJet
Definition of the current "tau version".
Definition: Event/xAOD/xAODTau/xAODTau/TauJet.h:17
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TauAODRunnerAlg::m_tauOutContainer
SG::WriteHandleKey< xAOD::TauJetContainer > m_tauOutContainer
Definition: TauAODRunnerAlg.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
TauAODRunnerAlg.h
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
TauAODRunnerAlg::m_officialTools
ToolHandleArray< ITauToolBase > m_officialTools
Definition: TauAODRunnerAlg.h:50
xAOD::TauTrack
TauTrack_v1 TauTrack
Definition of the current version.
Definition: TauTrack.h:16
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TauAODRunnerAlg::m_tauContainer
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContainer
Definition: TauAODRunnerAlg.h:52
TauAODRunnerAlg::initialize
virtual StatusCode initialize() override
Definition: TauAODRunnerAlg.cxx:11
TauAODRunnerAlg::m_pi0Container
SG::WriteHandleKey< xAOD::ParticleContainer > m_pi0Container
Definition: TauAODRunnerAlg.h:55
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
DataVector::pop_back
void pop_back()
Remove the last element from the collection.
TauAODRunnerAlg::TauAODRunnerAlg
TauAODRunnerAlg(const std::string &name, ISvcLocator *)
Definition: TauAODRunnerAlg.cxx:7