ATLAS Offline Software
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 
13 using Gaudi::Units::GeV;
14 
15 //-----------------------------------------------------------------------------
16 // Constructor
17 //-----------------------------------------------------------------------------
19  ISvcLocator * pSvcLocator) :
20  AthReentrantAlgorithm(name, pSvcLocator) {
21 }
22 
23 //-----------------------------------------------------------------------------
24 // Destructor
25 //-----------------------------------------------------------------------------
27 
28 //-----------------------------------------------------------------------------
29 // Initializer
30 //-----------------------------------------------------------------------------
32 
34  ATH_CHECK( m_tauOutputContainer.initialize() );
35  ATH_CHECK( m_tauTrackOutputContainer.initialize() );
37 
41 
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 //-----------------------------------------------------------------------------
75 StatusCode 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 
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
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
xAOD::TauJet_v3::nAllTracks
size_t nAllTracks() const
Definition: TauJet_v3.cxx:516
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TauProcessorAlg::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: TauProcessorAlg.h:70
TauTrackAuxContainer.h
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:488
TauProcessorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const
Definition: TauProcessorAlg.cxx:75
TauProcessorAlg::~TauProcessorAlg
~TauProcessorAlg()
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CaloClusterAuxContainer.h
TauJetAuxContainer.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
TauProcessorAlg::m_tauOutputContainer
SG::WriteHandleKey< xAOD::TauJetContainer > m_tauOutputContainer
Definition: TauProcessorAlg.h:62
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PFOAuxContainer.h
TauProcessorAlg::m_maxNTracks
Gaudi::Property< int > m_maxNTracks
Definition: TauProcessorAlg.h:55
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max() const
cell 'global' hash table max size
TauProcessorAlg::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: TauProcessorAlg.h:69
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
TauProcessorAlg::m_cellID
const CaloCell_ID * m_cellID
Definition: TauProcessorAlg.h:66
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
INavigable4MomentumCollection.h
TauProcessorAlg::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition: TauProcessorAlg.h:71
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauProcessorAlg::m_tauTrackOutputContainer
SG::WriteHandleKey< xAOD::TauTrackContainer > m_tauTrackOutputContainer
Definition: TauProcessorAlg.h:63
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::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::TauJet_v3::setJet
void setJet(const xAOD::JetContainer *cont, const xAOD::Jet *jet)
Definition: TauJet_v3.cxx:643
TauProcessorAlg::TauProcessorAlg
TauProcessorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TauProcessorAlg.cxx:18
TauProcessorAlg::m_jetInputContainer
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputContainer
Definition: TauProcessorAlg.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TauProcessorAlg::initialize
virtual StatusCode initialize()
Definition: TauProcessorAlg.cxx:31
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
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
TauProcessorAlg::m_tools
const ToolHandleArray< ITauToolBase > m_tools
Definition: TauProcessorAlg.h:57
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TauProcessorAlg::m_cellMakerTool
const ToolHandle< ICaloConstCellMakerTool > m_cellMakerTool
Definition: TauProcessorAlg.h:58
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
TauProcessorAlg::m_tauPi0CellOutputContainer
SG::WriteHandleKey< CaloConstCellContainer > m_tauPi0CellOutputContainer
Definition: TauProcessorAlg.h:64
TauProcessorAlg::m_minPt
Gaudi::Property< double > m_minPt
Definition: TauProcessorAlg.h:54
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CaloConstCellContainer
CaloCellContainer that can accept const cell pointers.
Definition: CaloConstCellContainer.h:45
DataVector::pop_back
void pop_back()
Remove the last element from the collection.
TauProcessorAlg.h
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
DataVector::erase
iterator erase(iterator position)
Remove element at a given position.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TauProcessorAlg::m_maxEta
Gaudi::Property< double > m_maxEta
Definition: TauProcessorAlg.h:53