ATLAS Offline Software
TauRunnerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TauRunnerAlg.h"
6 
7 #include "xAODJet/Jet.h"
8 #include "xAODJet/JetContainer.h"
9 
12 #include "xAODTau/TauDefs.h"
15 
16 #include "xAODCore/ShallowCopy.h"
17 
18 #include "StoreGate/ReadHandle.h"
19 #include "StoreGate/WriteHandle.h"
20 
21 //-----------------------------------------------------------------------------
22 // Constructor
23 //-----------------------------------------------------------------------------
24 TauRunnerAlg::TauRunnerAlg(const std::string &name,
25  ISvcLocator * pSvcLocator) :
26  AthReentrantAlgorithm(name, pSvcLocator) {
27 }
28 
29 //-----------------------------------------------------------------------------
30 // Destructor
31 //-----------------------------------------------------------------------------
32 TauRunnerAlg::~TauRunnerAlg() = default;
33 
34 //-----------------------------------------------------------------------------
35 // Initializer
36 //-----------------------------------------------------------------------------
38 
39  //-------------------------------------------------------------------------
40  // No tools allocated!
41  //-------------------------------------------------------------------------
42  if (m_tools.empty()) {
43  ATH_MSG_ERROR("no tools given!");
44  return StatusCode::FAILURE;
45  }
46 
47  ATH_CHECK( m_tauInputContainer.initialize() );
49 
50  ATH_CHECK( m_tauOutputContainer.initialize() );
51  ATH_CHECK( m_neutralPFOOutputContainer.initialize() );
53  ATH_CHECK( m_vertexOutputContainer.initialize() );
54  ATH_CHECK( m_chargedPFOOutputContainer.initialize() );
55  ATH_CHECK( m_pi0Container.initialize() );
56 
57  //-------------------------------------------------------------------------
58  // Allocate tools
59  //-------------------------------------------------------------------------
60  ATH_CHECK( m_tools.retrieve() );
61 
62  ATH_MSG_INFO("List of tools in execution sequence:");
63  ATH_MSG_INFO("------------------------------------");
64  unsigned int tool_count = 0;
65  for (ToolHandle<ITauToolBase>& tool : m_tools) {
66  ++tool_count;
67  ATH_MSG_INFO(tool->type() << " - " << tool->name());
68  }
69  ATH_MSG_INFO(" ");
70  ATH_MSG_INFO("------------------------------------");
71 
72  if (tool_count == 0) {
73  ATH_MSG_ERROR("could not allocate any tool!");
74  return StatusCode::FAILURE;
75  }
76 
77  return StatusCode::SUCCESS;
78 }
79 
80 
81 //-----------------------------------------------------------------------------
82 // Execution
83 //-----------------------------------------------------------------------------
84 StatusCode TauRunnerAlg::execute(const EventContext& ctx) const {
85 
86  // write neutral PFO container
88  ATH_CHECK(neutralPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
89  xAOD::PFOContainer* neutralPFOContainer = neutralPFOHandle.ptr();
90 
91  // write hadronic cluster PFO container
93  ATH_CHECK(hadronicPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
94  xAOD::PFOContainer* hadronicClusterPFOContainer = hadronicPFOHandle.ptr();
95 
96  // write secondary vertices
98  ATH_CHECK(vertOutHandle.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
99  xAOD::VertexContainer* pSecVtxContainer = vertOutHandle.ptr();
100 
101  // write charged PFO container
103  ATH_CHECK(chargedPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
104  xAOD::PFOContainer* chargedPFOContainer = chargedPFOHandle.ptr();
105 
106  // write pi0 container
108  ATH_CHECK(pi0Handle.record(std::make_unique<xAOD::ParticleContainer>(), std::make_unique<xAOD::ParticleAuxContainer>()));
109  xAOD::ParticleContainer* pi0Container = pi0Handle.ptr();
110 
111  // Read the CaloClusterContainer created by the CaloClusterMaker
113  if (!pi0ClusterInHandle.isValid()) {
114  ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << pi0ClusterInHandle.key());
115  return StatusCode::FAILURE;
116  }
117  const xAOD::CaloClusterContainer * pi0ClusterContainer = pi0ClusterInHandle.cptr();
118 
119  // Read in temporary tau jets
121  if (!tauInputHandle.isValid()) {
122  ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << tauInputHandle.key());
123  return StatusCode::FAILURE;
124  }
125  const xAOD::TauJetContainer* pTauContainer = tauInputHandle.cptr();
126 
127  // Write the output tau jets, which is a deep copy of the input ones
129  ATH_CHECK(outputTauHandle.record(std::make_unique<xAOD::TauJetContainer>(), std::make_unique<xAOD::TauJetAuxContainer>()));
130  xAOD::TauJetContainer* newTauCon = outputTauHandle.ptr();
131 
132  for (const xAOD::TauJet* tau : *pTauContainer) {
133  xAOD::TauJet* newTau = new xAOD::TauJet();
134  newTauCon->push_back(newTau);
135  *newTau = *tau;
136  }
137 
138  // iterate over the copy
139  for (xAOD::TauJet* pTau : *newTauCon) {
140  //-----------------------------------------------------------------
141  // Loop stops when Failure indicated by one of the tools
142  //-----------------------------------------------------------------
143  StatusCode sc;
144 
145  for (const ToolHandle<ITauToolBase>& tool : m_tools) {
146  ATH_MSG_DEBUG("RunnerAlg Invoking tool " << tool->name());
147  if ( tool->type() == "TauPi0ClusterCreator"){
148  sc = tool->executePi0ClusterCreator(*pTau, *neutralPFOContainer, *hadronicClusterPFOContainer, *pi0ClusterContainer);
149  }
150  else if ( tool->type() == "TauVertexVariables"){
151  sc = tool->executeVertexVariables(*pTau, *pSecVtxContainer);
152  }
153  else if ( tool->type() == "TauPi0ClusterScaler"){
154  sc = tool->executePi0ClusterScaler(*pTau, *neutralPFOContainer, *chargedPFOContainer);
155  }
156  else if ( tool->type() == "TauPi0ScoreCalculator"){
157  sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
158  }
159  else if ( tool->type() == "TauPi0Selector"){
160  sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
161  }
162  else if ( tool->type() == "PanTau::PanTauProcessor"){
163  sc = tool->executePanTau(*pTau, *pi0Container, *neutralPFOContainer);
164  }
165  else {
166  sc = tool->execute(*pTau);
167  }
168  if (sc.isFailure()) break;
169  }
170  if (sc.isSuccess()) {
171  ATH_MSG_VERBOSE("The tau candidate has been modified successfully by all the invoked tools.");
172  }
173  } // end iterator over shallow copy
174 
175  // sort taus by decreasing pt
176  auto sortByPt = [](const xAOD::TauJet* tau1, const xAOD::TauJet* tau2 ) { return tau1->pt() > tau2->pt(); };
177  newTauCon->sort( sortByPt );
178 
179  ATH_MSG_VERBOSE("The tau container has been processed");
180 
181  return StatusCode::SUCCESS;
182 }
ShallowCopy.h
TauRunnerAlg::m_pi0ClusterInputContainer
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_pi0ClusterInputContainer
Definition: TauRunnerAlg.h:50
Jet.h
TauRunnerAlg::TauRunnerAlg
TauRunnerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TauRunnerAlg.cxx:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TauTrackAuxContainer.h
TauRunnerAlg::m_tools
ToolHandleArray< ITauToolBase > m_tools
Definition: TauRunnerAlg.h:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TauTrackContainer.h
TauRunnerAlg::~TauRunnerAlg
~TauRunnerAlg()
TauRunnerAlg::m_tauOutputContainer
SG::WriteHandleKey< xAOD::TauJetContainer > m_tauOutputContainer
Definition: TauRunnerAlg.h:52
TauJetAuxContainer.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TauRunnerAlg::m_chargedPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_chargedPFOOutputContainer
Definition: TauRunnerAlg.h:56
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TauRunnerAlg::m_tauInputContainer
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauInputContainer
Definition: TauRunnerAlg.h:49
xAOD::TauJet_v3::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
WriteHandle.h
Handle class for recording to StoreGate.
TauDefs.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TauRunnerAlg::m_neutralPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_neutralPFOOutputContainer
Definition: TauRunnerAlg.h:53
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
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
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
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TauRunnerAlg::initialize
virtual StatusCode initialize() override
Definition: TauRunnerAlg.cxx:37
TauRunnerAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TauRunnerAlg.cxx:84
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TauRunnerAlg.h
TauRunnerAlg::m_vertexOutputContainer
SG::WriteHandleKey< xAOD::VertexContainer > m_vertexOutputContainer
Definition: TauRunnerAlg.h:55
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.
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
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
JetContainer.h
TauRunnerAlg::m_hadronicPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_hadronicPFOOutputContainer
Definition: TauRunnerAlg.h:54
TauRunnerAlg::m_pi0Container
SG::WriteHandleKey< xAOD::ParticleContainer > m_pi0Container
Definition: TauRunnerAlg.h:57
ReadHandle.h
Handle class for reading from StoreGate.