ATLAS Offline Software
Loading...
Searching...
No Matches
TauProcessorAlg.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 "TauProcessorAlg.h"
11#include <boost/dynamic_bitset.hpp>
12
13using Gaudi::Units::GeV;
14
15//-----------------------------------------------------------------------------
16// Constructor
17//-----------------------------------------------------------------------------
18TauProcessorAlg::TauProcessorAlg(const std::string &name,
19 ISvcLocator * pSvcLocator) :
20 AthReentrantAlgorithm(name, pSvcLocator) {
21}
22
23//-----------------------------------------------------------------------------
24// Destructor
25//-----------------------------------------------------------------------------
27
28//-----------------------------------------------------------------------------
29// Initializer
30//-----------------------------------------------------------------------------
32
33 ATH_CHECK( m_jetInputContainer.initialize() );
34 ATH_CHECK( m_tauOutputContainer.initialize() );
37
41
42 if(!m_tauPi0CellOutputContainer.empty()) {
43 ATH_CHECK( detStore()->retrieve(m_cellID) );
44 ATH_CHECK( m_cellMakerTool.retrieve() );
45 }
46
47 //-------------------------------------------------------------------------
48 // No tools allocated!
49 //-------------------------------------------------------------------------
50 if (m_tools.empty()) {
51 ATH_MSG_ERROR("no tools given!");
52 return StatusCode::FAILURE;
53 }
54
55 //-------------------------------------------------------------------------
56 // Allocate tools
57 //-------------------------------------------------------------------------
58 ATH_MSG_INFO("List of tools in execution sequence:");
59 ATH_MSG_INFO("------------------------------------");
60
61 for (const ToolHandle<ITauToolBase>& tool : m_tools) {
62 ATH_CHECK( tool.retrieve() );
63 ATH_MSG_INFO(tool->type() << " - " << tool->name());
64 }
65
66 ATH_MSG_INFO(" ");
67 ATH_MSG_INFO("------------------------------------");
68
69 return StatusCode::SUCCESS;
70}
71
72//-----------------------------------------------------------------------------
73// Execution
74//-----------------------------------------------------------------------------
75StatusCode TauProcessorAlg::execute(const EventContext& ctx) const {
76
79 ATH_CHECK(tauHandle.record(std::make_unique<xAOD::TauJetContainer>(), std::make_unique<xAOD::TauJetAuxContainer>()));
80 xAOD::TauJetContainer* pContainer = tauHandle.ptr();
81
83 ATH_CHECK(tauTrackHandle.record(std::make_unique<xAOD::TauTrackContainer>(), std::make_unique<xAOD::TauTrackAuxContainer>()));
84 xAOD::TauTrackContainer* pTauTrackCont = tauTrackHandle.ptr();
85
86 CaloConstCellContainer* Pi0CellContainer = nullptr;
87 boost::dynamic_bitset<> addedCellsMap;
88
89 if(!m_tauPi0CellOutputContainer.empty()) {
91 ATH_CHECK(tauPi0CellHandle.record(std::make_unique<CaloConstCellContainer>(SG::VIEW_ELEMENTS )));
92 Pi0CellContainer = tauPi0CellHandle.ptr();
93
94 // Initialize the cell map per event, used to avoid dumplicate cell in TauPi0CreateROI
95 IdentifierHash hashMax = m_cellID->calo_cell_hash_max();
96 ATH_MSG_DEBUG("CaloCell Hash Max: " << hashMax);
97 addedCellsMap.resize(hashMax,false);
98 }
99
100 // retrieve the input jet seed container
102 if (!jetHandle.isValid()) {
103 ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << jetHandle.key());
104 return StatusCode::FAILURE;
105 }
106 const xAOD::JetContainer *pSeedContainer = jetHandle.cptr();
107
108 //---------------------------------------------------------------------
109 // Loop over seeds
110 //---------------------------------------------------------------------
111 ATH_MSG_VERBOSE("Number of seeds in the container: " << pSeedContainer->size());
112
113 for (const xAOD::Jet* pSeed : *pSeedContainer) {
114 ATH_MSG_VERBOSE("Seeds eta:" << pSeed->eta() << ", pt:" << pSeed->pt());
115
116 if (std::abs(pSeed->eta()) > m_maxEta) {
117 ATH_MSG_VERBOSE("--> Seed rejected, eta out of range!");
118 continue;
119 }
120
121 if (pSeed->pt() < m_minPt) {
122 ATH_MSG_VERBOSE("--> Seed rejected, pt out of range!");
123 continue;
124 }
125
126 //-----------------------------------------------------------------
127 // Seed passed cuts --> create tau candidate
128 //-----------------------------------------------------------------
129 xAOD::TauJet* pTau = new xAOD::TauJet();
130 pContainer->push_back( pTau );
131 pTau->setJet(pSeedContainer, pSeed);
132
133 //-----------------------------------------------------------------
134 // Loop stops when Failure indicated by one of the tools
135 //-----------------------------------------------------------------
136 StatusCode sc;
137 for (const ToolHandle<ITauToolBase>& tool : m_tools) {
138 ATH_MSG_DEBUG("ProcessorAlg Invoking tool " << tool->name());
139
140 if (tool->type() == "TauVertexFinder") {
141 sc = tool->executeVertexFinder(*pTau);
142 } else if (tool->type() == "TauTrackFinder") {
143 sc = tool->executeTrackFinder(*pTau, *pTauTrackCont);
144 } else if (tool->type() == "tauRecTools::TauTrackRNNClassifier") {
145 sc = tool->executeTrackClassifier(*pTau, *pTauTrackCont);
146
147 // skip candidate if it has too many classifiedCharged tracks, if
148 // skimming is required
149 if (m_maxNTracks > 0 &&
150 static_cast<int>(pTau->nTracks()) > m_maxNTracks) {
151 sc = StatusCode::FAILURE;
152 break;
153 }
154 } else if (tool->type() == "TauPi0CreateROI") {
155 sc = tool->executePi0CreateROI(*pTau, *Pi0CellContainer, addedCellsMap);
156 } else {
157 sc = tool->execute(*pTau);
158 }
159 if (sc.isFailure())
160 break;
161 }
162
163 if (sc.isSuccess()) {
164 ATH_MSG_VERBOSE("The tau candidate has been registered");
165 }
166 else {
167 //remove orphaned tracks before tau is deleted via pop_back
168 xAOD::TauJet* bad_tau = pContainer->back();
169 ATH_MSG_DEBUG("Deleting " << bad_tau->nAllTracks() << "Tracks associated with tau: ");
170 pTauTrackCont->erase(pTauTrackCont->end()-bad_tau->nAllTracks(), pTauTrackCont->end());
171
172 pContainer->pop_back();
173 }
174 }// loop through seeds
175
176 if(Pi0CellContainer) {
177 // sort the cell container by hash
178 // basically call the finalizer
179 ATH_CHECK( m_cellMakerTool->process(Pi0CellContainer, ctx) );
180 //Since this is recorded we can retrieve it later as const DV
181 //do it here due to symlink below
182 const CaloCellContainer* cellPtrs = Pi0CellContainer->asDataVector();
183 // Check this is needed for the cell container?
184 // symlink as INavigable4MomentumCollection (as in CaloRec/CaloCellMaker)
185 ATH_CHECK(evtStore()->symLink(cellPtrs, static_cast<INavigable4MomentumCollection*> (nullptr)));
186 }
187
188 ATH_MSG_VERBOSE("The tau candidate container has been modified");
189
190 return StatusCode::SUCCESS;
191}
192
#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)
DataVector< INavigable4Momentum > INavigable4MomentumCollection
static Double_t sc
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
Container class for CaloCell.
CaloCellContainer that can accept const cell pointers.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
const T * back() const
Access the last element in the collection as an rvalue.
void pop_back()
Remove the last element from the collection.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
iterator erase(iterator position)
Remove element at a given position.
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
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.
virtual StatusCode initialize()
Gaudi::Property< double > m_minPt
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Gaudi::Property< int > m_maxNTracks
const ToolHandle< ICaloConstCellMakerTool > m_cellMakerTool
SG::WriteHandleKey< CaloConstCellContainer > m_tauPi0CellOutputContainer
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
const ToolHandleArray< ITauToolBase > m_tools
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputContainer
SG::WriteHandleKey< xAOD::TauTrackContainer > m_tauTrackOutputContainer
virtual StatusCode execute(const EventContext &ctx) const
SG::WriteHandleKey< xAOD::TauJetContainer > m_tauOutputContainer
const CaloCell_ID * m_cellID
TauProcessorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< double > m_maxEta
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
void setJet(const xAOD::JetContainer *cont, const xAOD::Jet *jet)
size_t nAllTracks() const
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Jet_v1 Jet
Definition of the current "jet version".
TauJet_v3 TauJet
Definition of the current "tau version".
TauTrackContainer_v1 TauTrackContainer
Definition of the current TauTrack container version.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".