ATLAS Offline Software
Loading...
Searching...
No Matches
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"
9
12#include "xAODTau/TauDefs.h"
15
17
20
22
23//-----------------------------------------------------------------------------
24// Constructor
25//-----------------------------------------------------------------------------
26TauRunnerAlg::TauRunnerAlg(const std::string &name,
27 ISvcLocator * pSvcLocator) :
28 AthReentrantAlgorithm(name, pSvcLocator) {
29}
30
31//-----------------------------------------------------------------------------
32// Destructor
33//-----------------------------------------------------------------------------
35
36//-----------------------------------------------------------------------------
37// Initializer
38//-----------------------------------------------------------------------------
40
41 //-------------------------------------------------------------------------
42 // No tools allocated!
43 //-------------------------------------------------------------------------
44 if (m_tools.empty()) {
45 ATH_MSG_ERROR("no tools given!");
46 return StatusCode::FAILURE;
47 }
48
49 ATH_CHECK( m_tauInputContainer.initialize() );
51
52 ATH_CHECK( m_tauOutputContainer.initialize() );
55 ATH_CHECK( m_vertexOutputContainer.initialize() );
57 ATH_CHECK( m_pi0Container.initialize() );
58
62
63 //-------------------------------------------------------------------------
64 // Allocate tools
65 //-------------------------------------------------------------------------
66 ATH_CHECK( m_tools.retrieve() );
67
68 ATH_MSG_INFO("List of tools in execution sequence:");
69 ATH_MSG_INFO("------------------------------------");
70 unsigned int tool_count = 0;
71 for (ToolHandle<ITauToolBase>& tool : m_tools) {
72 ++tool_count;
73 ATH_MSG_INFO(tool->type() << " - " << tool->name());
74 }
75 ATH_MSG_INFO(" ");
76 ATH_MSG_INFO("------------------------------------");
77
78 if (tool_count == 0) {
79 ATH_MSG_ERROR("could not allocate any tool!");
80 return StatusCode::FAILURE;
81 }
82
83 return StatusCode::SUCCESS;
84}
85
86
87//-----------------------------------------------------------------------------
88// Execution
89//-----------------------------------------------------------------------------
90StatusCode TauRunnerAlg::execute(const EventContext& ctx) const {
91
92 // write neutral PFO container
94 ATH_CHECK(neutralPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
95 xAOD::PFOContainer* neutralPFOContainer = neutralPFOHandle.ptr();
96
97 // write hadronic cluster PFO container
99 ATH_CHECK(hadronicPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
100 xAOD::PFOContainer* hadronicClusterPFOContainer = hadronicPFOHandle.ptr();
101
102 // write secondary vertices
104 ATH_CHECK(vertOutHandle.record(std::make_unique<xAOD::VertexContainer>(), std::make_unique<xAOD::VertexAuxContainer>()));
105 xAOD::VertexContainer* pSecVtxContainer = vertOutHandle.ptr();
106
107 // write charged PFO container
109 ATH_CHECK(chargedPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
110 xAOD::PFOContainer* chargedPFOContainer = chargedPFOHandle.ptr();
111
112 // write pi0 container
114 ATH_CHECK(pi0Handle.record(std::make_unique<xAOD::ParticleContainer>(), std::make_unique<xAOD::ParticleAuxContainer>()));
115 xAOD::ParticleContainer* pi0Container = pi0Handle.ptr();
116
118 ATH_CHECK(tauShotClusHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()));
119 xAOD::CaloClusterContainer* tauShotClusContainer = tauShotClusHandle.ptr();
120
122 ATH_CHECK(tauShotPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
123 xAOD::PFOContainer* tauShotPFOContainer = tauShotPFOHandle.ptr();
124
125 // Read the CaloClusterContainer created by the CaloClusterMaker
127 if (!pi0ClusterInHandle.isValid()) {
128 ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << pi0ClusterInHandle.key());
129 return StatusCode::FAILURE;
130 }
131 const xAOD::CaloClusterContainer * pi0ClusterContainer = pi0ClusterInHandle.cptr();
132
133 // Read in temporary tau jets
135 if (!tauInputHandle.isValid()) {
136 ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << tauInputHandle.key());
137 return StatusCode::FAILURE;
138 }
139 const xAOD::TauJetContainer* pTauContainer = tauInputHandle.cptr();
140
141 // Write the output tau jets, which is a deep copy of the input ones
143 ATH_CHECK(outputTauHandle.record(std::make_unique<xAOD::TauJetContainer>(), std::make_unique<xAOD::TauJetAuxContainer>()));
144 xAOD::TauJetContainer* newTauCon = outputTauHandle.ptr();
145
146 for (const xAOD::TauJet* tau : *pTauContainer) {
147 xAOD::TauJet* newTau = new xAOD::TauJet();
148 newTauCon->push_back(newTau);
149 *newTau = *tau;
150 }
151
152 // iterate over the copy
153 for (xAOD::TauJet* pTau : *newTauCon) {
154 //-----------------------------------------------------------------
155 // Loop stops when Failure indicated by one of the tools
156 //-----------------------------------------------------------------
157 StatusCode sc;
158
159 for (const ToolHandle<ITauToolBase>& tool : m_tools) {
160 ATH_MSG_DEBUG("RunnerAlg Invoking tool " << tool->name());
161 if ( tool->type() == "TauPi0ClusterCreator"){
162 sc = tool->executePi0ClusterCreator(*pTau, *neutralPFOContainer, *hadronicClusterPFOContainer, *pi0ClusterContainer);
163 }
164 else if ( tool->type() == "TauVertexVariables"){
165 sc = tool->executeVertexVariables(*pTau, *pSecVtxContainer);
166 }
167 else if (tool->type() == "TauShotFinder") {
168 sc = tool->executeShotFinder(*pTau, *tauShotClusContainer,
169 *tauShotPFOContainer);
170 }
171 else if ( tool->type() == "TauPi0ClusterScaler"){
172 sc = tool->executePi0ClusterScaler(*pTau, *neutralPFOContainer, *chargedPFOContainer);
173 }
174 else if ( tool->type() == "TauPi0ScoreCalculator"){
175 sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
176 }
177 else if ( tool->type() == "TauPi0Selector"){
178 sc = tool->executePi0nPFO(*pTau, *neutralPFOContainer);
179 }
180 else if ( tool->type() == "PanTau::PanTauProcessor"){
181 sc = tool->executePanTau(*pTau, *pi0Container, *neutralPFOContainer);
182 }
183 else {
184 sc = tool->execute(*pTau);
185 }
186 if (sc.isFailure()) break;
187 }
188 if (sc.isSuccess()) {
189 ATH_MSG_VERBOSE("The tau candidate has been modified successfully by all the invoked tools.");
190 }
191 } // end iterator over shallow copy
192
193 // build cell link container for shot clusters
195 ATH_CHECK(CaloClusterStoreHelper::finalizeClusters (tauShotClusLinkHandle, tauShotClusContainer));
196
197 // sort taus by decreasing pt
198 auto sortByPt = [](const xAOD::TauJet* tau1, const xAOD::TauJet* tau2 ) { return tau1->pt() > tau2->pt(); };
199 newTauCon->sort( sortByPt );
200
201 ATH_MSG_VERBOSE("The tau container has been processed");
202
203 return StatusCode::SUCCESS;
204}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
An algorithm that can be simultaneously executed in multiple threads.
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
void sort()
Sort the container.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_pi0ClusterInputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_neutralPFOOutputContainer
virtual StatusCode initialize() override
TauRunnerAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKey< xAOD::ParticleContainer > m_pi0Container
SG::WriteHandleKey< xAOD::VertexContainer > m_vertexOutputContainer
SG::WriteHandleKey< xAOD::TauJetContainer > m_tauOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_tauShotPFOOutputContainer
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< xAOD::PFOContainer > m_hadronicPFOOutputContainer
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauInputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_chargedPFOOutputContainer
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_tauShotClusLinkContainer
ToolHandleArray< ITauToolBase > m_tools
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_tauShotClusOutputContainer
virtual double pt() const
The transverse momentum ( ) of the particle.
PFOContainer_v1 PFOContainer
Definition of the current "pfo container version".
ParticleContainer_v1 ParticleContainer
Define the latest version of the particle class.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
TauJet_v3 TauJet
Definition of the current "tau version".
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".