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"
12 #include <boost/dynamic_bitset.hpp>
13 
14 using Gaudi::Units::GeV;
15 
16 //-----------------------------------------------------------------------------
17 // Constructor
18 //-----------------------------------------------------------------------------
20  ISvcLocator * pSvcLocator) :
21  AthReentrantAlgorithm(name, pSvcLocator) {
22 }
23 
24 //-----------------------------------------------------------------------------
25 // Destructor
26 //-----------------------------------------------------------------------------
28 
29 //-----------------------------------------------------------------------------
30 // Initializer
31 //-----------------------------------------------------------------------------
33 
34  ATH_CHECK( m_jetInputContainer.initialize() );
35  ATH_CHECK( m_tauOutputContainer.initialize() );
36  ATH_CHECK( m_tauTrackOutputContainer.initialize() );
39  ATH_CHECK( m_tauShotPFOOutputContainer.initialize() );
41 
45 
48  ATH_CHECK( m_cellMakerTool.retrieve() );
49  }
50 
51  //-------------------------------------------------------------------------
52  // No tools allocated!
53  //-------------------------------------------------------------------------
54  if (m_tools.empty()) {
55  ATH_MSG_ERROR("no tools given!");
56  return StatusCode::FAILURE;
57  }
58 
59  //-------------------------------------------------------------------------
60  // Allocate tools
61  //-------------------------------------------------------------------------
62  ATH_MSG_INFO("List of tools in execution sequence:");
63  ATH_MSG_INFO("------------------------------------");
64 
65  for (const ToolHandle<ITauToolBase>& tool : m_tools) {
66  ATH_CHECK( tool.retrieve() );
67  ATH_MSG_INFO(tool->type() << " - " << tool->name());
68  }
69 
70  ATH_MSG_INFO(" ");
71  ATH_MSG_INFO("------------------------------------");
72 
73  return StatusCode::SUCCESS;
74 }
75 
76 //-----------------------------------------------------------------------------
77 // Execution
78 //-----------------------------------------------------------------------------
79 StatusCode TauProcessorAlg::execute(const EventContext& ctx) const {
80 
83  ATH_CHECK(tauHandle.record(std::make_unique<xAOD::TauJetContainer>(), std::make_unique<xAOD::TauJetAuxContainer>()));
84  xAOD::TauJetContainer* pContainer = tauHandle.ptr();
85 
87  ATH_CHECK(tauTrackHandle.record(std::make_unique<xAOD::TauTrackContainer>(), std::make_unique<xAOD::TauTrackAuxContainer>()));
88  xAOD::TauTrackContainer* pTauTrackCont = tauTrackHandle.ptr();
89 
91  ATH_CHECK(tauShotClusHandle.record(std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterAuxContainer>()));
92  xAOD::CaloClusterContainer* tauShotClusContainer = tauShotClusHandle.ptr();
93 
95  ATH_CHECK(tauShotPFOHandle.record(std::make_unique<xAOD::PFOContainer>(), std::make_unique<xAOD::PFOAuxContainer>()));
96  xAOD::PFOContainer* tauShotPFOContainer = tauShotPFOHandle.ptr();
97 
98  CaloConstCellContainer* Pi0CellContainer = nullptr;
99  boost::dynamic_bitset<> addedCellsMap;
100 
103  ATH_CHECK(tauPi0CellHandle.record(std::make_unique<CaloConstCellContainer>(SG::VIEW_ELEMENTS )));
104  Pi0CellContainer = tauPi0CellHandle.ptr();
105 
106  // Initialize the cell map per event, used to avoid dumplicate cell in TauPi0CreateROI
108  ATH_MSG_DEBUG("CaloCell Hash Max: " << hashMax);
109  addedCellsMap.resize(hashMax,false);
110  }
111 
112  // retrieve the input jet seed container
114  if (!jetHandle.isValid()) {
115  ATH_MSG_ERROR ("Could not retrieve HiveDataObj with key " << jetHandle.key());
116  return StatusCode::FAILURE;
117  }
118  const xAOD::JetContainer *pSeedContainer = jetHandle.cptr();
119 
120  //---------------------------------------------------------------------
121  // Loop over seeds
122  //---------------------------------------------------------------------
123  ATH_MSG_VERBOSE("Number of seeds in the container: " << pSeedContainer->size());
124 
125  for (const xAOD::Jet* pSeed : *pSeedContainer) {
126  ATH_MSG_VERBOSE("Seeds eta:" << pSeed->eta() << ", pt:" << pSeed->pt());
127 
128  if (std::abs(pSeed->eta()) > m_maxEta) {
129  ATH_MSG_VERBOSE("--> Seed rejected, eta out of range!");
130  continue;
131  }
132 
133  if (pSeed->pt() < m_minPt) {
134  ATH_MSG_VERBOSE("--> Seed rejected, pt out of range!");
135  continue;
136  }
137 
138  //-----------------------------------------------------------------
139  // Seed passed cuts --> create tau candidate
140  //-----------------------------------------------------------------
141  xAOD::TauJet* pTau = new xAOD::TauJet();
142  pContainer->push_back( pTau );
143  pTau->setJet(pSeedContainer, pSeed);
144 
145  //-----------------------------------------------------------------
146  // Loop stops when Failure indicated by one of the tools
147  //-----------------------------------------------------------------
148  StatusCode sc;
149  for (const ToolHandle<ITauToolBase>& tool : m_tools) {
150  ATH_MSG_DEBUG("ProcessorAlg Invoking tool " << tool->name());
151 
152  if (tool->type() == "TauVertexFinder") {
153  sc = tool->executeVertexFinder(*pTau);
154  } else if (tool->type() == "TauTrackFinder") {
155  sc = tool->executeTrackFinder(*pTau, *pTauTrackCont);
156  } else if (tool->type() == "tauRecTools::TauTrackRNNClassifier") {
157  sc = tool->executeTrackClassifier(*pTau, *pTauTrackCont);
158 
159  // skip candidate if it has too many classifiedCharged tracks, if
160  // skimming is required
161  if (m_maxNTracks > 0 &&
162  static_cast<int>(pTau->nTracks()) > m_maxNTracks) {
163  sc = StatusCode::FAILURE;
164  break;
165  }
166  } else if (tool->type() == "TauShotFinder") {
167  sc = tool->executeShotFinder(*pTau, *tauShotClusContainer,
168  *tauShotPFOContainer);
169  } else if (tool->type() == "TauPi0CreateROI") {
170  sc = tool->executePi0CreateROI(*pTau, *Pi0CellContainer, addedCellsMap);
171  } else {
172  sc = tool->execute(*pTau);
173  }
174  if (sc.isFailure())
175  break;
176  }
177 
178  if (sc.isSuccess()) {
179  ATH_MSG_VERBOSE("The tau candidate has been registered");
180  }
181  else {
182  //remove orphaned tracks before tau is deleted via pop_back
183  xAOD::TauJet* bad_tau = pContainer->back();
184  ATH_MSG_DEBUG("Deleting " << bad_tau->nAllTracks() << "Tracks associated with tau: ");
185  pTauTrackCont->erase(pTauTrackCont->end()-bad_tau->nAllTracks(), pTauTrackCont->end());
186 
187  pContainer->pop_back();
188  }
189  }// loop through seeds
190 
191  // build cell link container for shot clusters
193  ATH_CHECK(CaloClusterStoreHelper::finalizeClusters (tauShotClusLinkHandle, tauShotClusContainer));
194 
195  if(Pi0CellContainer) {
196  // sort the cell container by hash
197  // basically call the finalizer
198  ATH_CHECK( m_cellMakerTool->process(Pi0CellContainer, ctx) );
199  //Since this is recorded we can retrieve it later as const DV
200  //do it here due to symlink below
201  const CaloCellContainer* cellPtrs = Pi0CellContainer->asDataVector();
202  // Check this is needed for the cell container?
203  // symlink as INavigable4MomentumCollection (as in CaloRec/CaloCellMaker)
204  ATH_CHECK(evtStore()->symLink(cellPtrs, static_cast<INavigable4MomentumCollection*> (nullptr)));
205  }
206 
207  ATH_MSG_VERBOSE("The tau candidate container has been modified");
208 
209  return StatusCode::SUCCESS;
210 }
211 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
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:554
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:70
TauProcessorAlg::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: TauProcessorAlg.h:73
TauTrackAuxContainer.h
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
TauProcessorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const
Definition: TauProcessorAlg.cxx:79
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:83
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
TauProcessorAlg::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: TauProcessorAlg.h:72
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:69
TauProcessorAlg::m_tauShotPFOOutputContainer
SG::WriteHandleKey< xAOD::PFOContainer > m_tauShotPFOOutputContainer
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:74
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
TauProcessorAlg::m_tauShotClusLinkContainer
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_tauShotClusLinkContainer
Definition: TauProcessorAlg.h:65
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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:683
TauProcessorAlg::TauProcessorAlg
TauProcessorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TauProcessorAlg.cxx:19
TauProcessorAlg::m_jetInputContainer
SG::ReadHandleKey< xAOD::JetContainer > m_jetInputContainer
Definition: TauProcessorAlg.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TauProcessorAlg::initialize
virtual StatusCode initialize()
Definition: TauProcessorAlg.cxx:32
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::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
CaloClusterStoreHelper.h
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:76
TauProcessorAlg::m_tauPi0CellOutputContainer
SG::WriteHandleKey< CaloConstCellContainer > m_tauPi0CellOutputContainer
Definition: TauProcessorAlg.h:67
TauProcessorAlg::m_tauShotClusOutputContainer
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_tauShotClusOutputContainer
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
Definition: IdentifierHash.h:38
DataVector::erase
iterator erase(iterator position)
Remove element at a given position.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
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
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size