ATLAS Offline Software
DiTauBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 DiTauBuilder::DiTauBuilder( const std::string& name, ISvcLocator* pSvcLocator ) :
8  AthReentrantAlgorithm( name, pSvcLocator ),
9  m_minPt(10000),
10  m_maxEta(2.5),
11  m_Rjet(1.0),
12  m_Rsubjet(0.2),
13  m_Rcore(0.1),
14  m_tools(this)
15 {
16  declareProperty("minPt", m_minPt);
17  declareProperty("maxEta", m_maxEta);
18  declareProperty("Rjet", m_Rjet);
19  declareProperty("Rsubjet", m_Rsubjet);
20  declareProperty("Rcore", m_Rcore);
21  declareProperty("Tools", m_tools );
22 
23 }
24 
25 
26 DiTauBuilder::~DiTauBuilder() = default;
27 
28 
30  ATH_MSG_INFO ("Initializing " << name() << "...");
31 
32  // no tools allocated
33  if (m_tools.empty()) {
34  ATH_MSG_ERROR("no tools given!");
35  return StatusCode::FAILURE;
36  }
37 
38  // list allocated tools
39  ATH_CHECK( m_tools.retrieve() );
40  ToolHandleArray<DiTauToolBase> ::iterator itT = m_tools.begin();
41  ToolHandleArray<DiTauToolBase> ::iterator itTE = m_tools.end();
42  ATH_MSG_INFO("List of tools in execution sequence:");
43  ATH_MSG_INFO("------------------------------------");
44 
45  unsigned int tool_count = 0;
46 
47  for (; itT != itTE; ++itT) {
48  if (itT->retrieve().isFailure()) {
49  ATH_MSG_WARNING("Cannot find tool named <" << *itT << ">");
50  } else {
51  ++tool_count;
52  ATH_MSG_INFO((*itT)->type() << " - " << (*itT)->name());
53  }
54  }
55  ATH_MSG_INFO(" ");
56  ATH_MSG_INFO("------------------------------------");
57 
58  if (tool_count == 0) {
59  ATH_MSG_ERROR("could not allocate any tool!");
60  return StatusCode::FAILURE;
61  }
62 
63  ATH_CHECK( m_diTauContainerName.initialize() );
64  ATH_CHECK( m_seedJetName.initialize() );
65 
66  return StatusCode::SUCCESS;
67 }
68 
69 
71  ATH_MSG_INFO ("Finalizing " << name() << "...");
72 
73  return StatusCode::SUCCESS;
74 }
75 
76 
77 StatusCode DiTauBuilder::execute(const EventContext& ctx) const {
78  ATH_MSG_DEBUG ("Executing " << name() << "...");
79 
80  // preparing DiTau Candidate Container and storage in DiTauData
81 
82  DiTauCandidateData rDiTauData;
83 
84  auto pContainer = std::make_unique<xAOD::DiTauJetContainer>();
85  auto pAuxContainer = std::make_unique<xAOD::DiTauJetAuxContainer>();
86  pContainer->setStore(pAuxContainer.get());
87 
88  // set properties of DiTau Candidate
89  rDiTauData.xAODDiTau = nullptr;
90  rDiTauData.xAODDiTauContainer = pContainer.get();
91  rDiTauData.diTauAuxContainer = pAuxContainer.get();
92  rDiTauData.seed = nullptr;
93  rDiTauData.seedContainer = nullptr;
94 
95  rDiTauData.Rjet = m_Rjet;
96  rDiTauData.Rsubjet = m_Rsubjet;
97  rDiTauData.Rcore = m_Rcore;
98 
100  ATH_CHECK( diTauContainerH.record (std::move (pContainer),
101  std::move (pAuxContainer)) );
102 
103  // retrieve di-tau seed jets and loop over seeds
104 
106 
107  rDiTauData.seedContainer = pSeedContainer.get();
108 
109  for (const auto* seed: *pSeedContainer) {
110  ATH_MSG_DEBUG("Seed pt: "<< seed->pt() << " eta: "<< seed->eta());
111 
112  // seed cuts
113  if (std::abs(seed->pt()) < m_minPt) continue;
114  if (std::abs(seed->eta()) > m_maxEta) continue;
115 
116  // cuts passed
117  rDiTauData.seed = seed;
118 
119  // create new di-tau candidate
120  rDiTauData.xAODDiTau = new xAOD::DiTauJet();
121  rDiTauData.xAODDiTauContainer->push_back(rDiTauData.xAODDiTau);
122 
123  // handle di-tau candidate
124  StatusCode sc = StatusCode::SUCCESS;
125  for (const auto& tool: m_tools) {
126  sc = tool->execute(&rDiTauData, ctx);
127  if (sc.isFailure()) break;
128  }
129 
130  if (sc.isSuccess()) {
131  ATH_MSG_DEBUG("all tools executed successfully. Di-Tau candidate registered.");
132  }
133  else {
134  ATH_MSG_DEBUG("seed failed a di-tau criterion. Thrown away.");
135  rDiTauData.xAODDiTauContainer->pop_back();
136  }
137  }
138 
139  // // TODO: tool finalizers needed here
140  // sc = StatusCode::SUCCESS;
141 
142  rDiTauData.xAODDiTau = nullptr;
143 
144  ATH_MSG_DEBUG("end execute()");
145  return StatusCode::SUCCESS;
146 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DiTauCandidateData::seedContainer
const xAOD::JetContainer * seedContainer
Definition: DiTauCandidateData.h:22
DiTauBuilder::execute
virtual StatusCode execute(const EventContext &) const override
Definition: DiTauBuilder.cxx:77
DiTauBuilder::m_seedJetName
SG::ReadHandleKey< xAOD::JetContainer > m_seedJetName
Definition: DiTauBuilder.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DiTauCandidateData::diTauAuxContainer
xAOD::DiTauJetAuxContainer * diTauAuxContainer
Definition: DiTauCandidateData.h:19
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::DiTauJet
DiTauJet_v1 DiTauJet
Definition of the current version.
Definition: DiTauJet.h:17
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DiTauBuilder::~DiTauBuilder
virtual ~DiTauBuilder()
DiTauBuilder::m_tools
ToolHandleArray< DiTauToolBase > m_tools
Definition: DiTauBuilder.h:40
DiTauBuilder.h
DiTauBuilder::initialize
virtual StatusCode initialize() override
Definition: DiTauBuilder.cxx:29
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
DiTauCandidateData::Rsubjet
float Rsubjet
Definition: DiTauCandidateData.h:27
DiTauCandidateData::xAODDiTau
xAOD::DiTauJet * xAODDiTau
Definition: DiTauCandidateData.h:17
DiTauBuilder::m_diTauContainerName
SG::WriteHandleKey< xAOD::DiTauJetContainer > m_diTauContainerName
Definition: DiTauBuilder.h:31
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DiTauBuilder::m_Rsubjet
float m_Rsubjet
Definition: DiTauBuilder.h:38
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DiTauCandidateData::Rcore
float Rcore
Definition: DiTauCandidateData.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DiTauCandidateData::xAODDiTauContainer
xAOD::DiTauJetContainer * xAODDiTauContainer
Definition: DiTauCandidateData.h:18
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::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
DiTauBuilder::m_maxEta
float m_maxEta
Definition: DiTauBuilder.h:36
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
DiTauBuilder::finalize
virtual StatusCode finalize() override
Definition: DiTauBuilder.cxx:70
DiTauBuilder::m_minPt
float m_minPt
Definition: DiTauBuilder.h:35
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataVector::pop_back
void pop_back()
Remove the last element from the collection.
DiTauCandidateData::seed
const xAOD::Jet * seed
Definition: DiTauCandidateData.h:21
DiTauBuilder::m_Rjet
float m_Rjet
Definition: DiTauBuilder.h:37
DiTauCandidateData::Rjet
float Rjet
Definition: DiTauCandidateData.h:26
DiTauCandidateData
Definition: DiTauCandidateData.h:15
DiTauBuilder::m_Rcore
float m_Rcore
Definition: DiTauBuilder.h:39
DiTauBuilder::DiTauBuilder
DiTauBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DiTauBuilder.cxx:7