ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTopoTowerAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
9#include <string>
10#include <vector>
11#include <iomanip>
12
14 ISvcLocator* pSvcLocator)
15 : AthReentrantAlgorithm(name,pSvcLocator)
16{
17}
18
20= default;
21
23// Initialize //
25
27{
28 ATH_CHECK(m_cellContainerKey.initialize());
29 ATH_CHECK(m_clusterKey.initialize());
30 ATH_CHECK(m_cellToClusterMapKey.initialize());
31 ATH_CHECK(m_towerContainerKey.initialize());
33
34 m_caloIndices.clear();
35 for ( unsigned int iCalos=0; iCalos< m_includedCalos.size(); iCalos++ )
36 {
37 if ( m_includedCalos[iCalos] == "LAREM" )
38 {
40 }
41 else if ( m_includedCalos[iCalos] == "LARHEC")
42 {
44 }
45 else if ( m_includedCalos[iCalos] == "LARFCAL" )
46 {
48 }
49 else if ( m_includedCalos[iCalos] == "TILE" )
50 {
52 }
53 }
54
55 m_caloSelection=false;
56 unsigned int nSubCalo=static_cast<int>(CaloCell_ID::NSUBCALO) ;
57 if (!m_caloIndices.empty() && m_caloIndices.size()<nSubCalo) m_caloSelection=true;
58
59 ATH_MSG_INFO( " Calo selection applied ? " << m_caloSelection );
60 if (m_caloSelection) {
61 msg() << MSG::INFO << " subcalo selected ";
62 for (unsigned int iCalos=0;iCalos< m_includedCalos.size(); iCalos++ )
63 msg() << MSG::INFO << " " << m_includedCalos[iCalos];
64 msg() << MSG::INFO << " " << endmsg;
65 }
66
67
69 // Allocate Tools //
71
72 // check tool names
73 if ( m_ptools.empty() )
74 {
75 ATH_MSG_ERROR( "no tools given for this algorithm." );
76 return StatusCode::FAILURE;
77 }
78
79 // find tools
80
81 unsigned int toolCtr = 0;
82 ATH_MSG_INFO( " " );
83 ATH_MSG_INFO( "List of tools in execution sequence:" );
84 ATH_MSG_INFO( "------------------------------------" );
85
86 StatusCode checkOut = m_ptools.retrieve();
87 if ( checkOut.isFailure() )
88 {
89 ATH_MSG_WARNING( "Cannot retrieve tool array " << m_ptools );
90 return StatusCode::FAILURE;
91 }
92
93 for (ToolHandle<ICaloTopoTowerBuilderToolBase>& tool : m_ptools)
94 {
95 toolCtr++;
96 /* ATH_MSG_INFO( "retrieving tool" );
97
98 if ( checkOut.isFailure() ) {
99 ATH_MSG_WARNING( "Cannot retrieve tool at ToolArray[" << toolCtr-1 << "]" );
100 ATH_MSG_WARNING( "This tool won't be used" );
101 }
102 else {
103 ATH_MSG_INFO( "retrieved tool" );
104 // print the list of tools
105 */
106
107
108 ATH_MSG_INFO( std::setw(2) << toolCtr << ".) "
109 << tool->type()
110 << "::name() = \042"
111 << tool->name()
112 << "\042" );
113
114 ATH_MSG_INFO( "------------------------------------" );
115 ATH_MSG_INFO( " " );
116
117 /*if ( tool->initializeTool().isFailure() ) {
118
119 ATH_MSG_WARNING( " Tool failed to initialize" );
120 }*/
121
122 } //close iteration over tools
123 return StatusCode::SUCCESS;
124}
125
127// Execute //
129
130StatusCode CaloTopoTowerAlgorithm::execute (const EventContext& ctx) const
131{
132
134 // Re-allocate Services //
136
137 //timing
138 IChronoStatSvc* theTicker = chronoSvc();
139
141 // Tool Processing //
145 if ( !towerContainer.isValid() ) {
146 ATH_MSG_WARNING( " cannot retrieve tower container with key " << towerContainer.name() );
147 return StatusCode::SUCCESS;
148 }
149
152 if ( !theCells.isValid()) {
153 ATH_MSG_WARNING( " cannot retrieve cell container with key " << theCells.name() );
154 return StatusCode::SUCCESS;
155 }
156 ATH_MSG_DEBUG( "CaloTopoTowerAlgorithm::execute " << theCells.name() << " size= " << theCells->size() );
157
160
161 if ( !clusters.isValid() )
162 {
163 ATH_MSG_WARNING( "cannot retrieve CaloClusterContainer with key <"
164 << clusters.name() << ">" );
165 return StatusCode::SUCCESS;
166 }
167
170 if ( !cellToClusterMap.isValid() ){
171 ATH_MSG_WARNING( "cannot retrieve CaloCell2ClusterMap with key <"
172 << cellToClusterMap.name() << ">" );
173 return StatusCode::SUCCESS;
174 }
175
176 ATH_MSG_DEBUG( "Successfully retrieved CaloCell2ClusterMap <"<< cellToClusterMap.name() << ">" );
177
179 ATH_CHECK( theTowers.record (std::make_unique<CaloTopoTowerContainer>(towerContainer->towerseg())) );
180
182 //Starting to save variable to CaloTopoTowerContainer
183 //
184
185 theTowers->SetTowers(towerContainer.cptr());
186 theTowers->SetClusters(clusters.ptr());
187 theTowers->SetCells(theCells.cptr());
188 theTowers->SetCellToClusterMap(cellToClusterMap.cptr());
189
190 theTowers->SetMinimumCellEnergy(m_minimumCellEnergy);
191 theTowers->SetMinimumClusterEnergy(m_minimumClusterEnergy);
192 theTowers->SetUseCellWeights(m_useCellWeights);
193
194 // Noise tool stuff
195 theTowers->SetNoiseSigma(m_noiseSigma);
196 theTowers->SetCellESignificanceThreshold(m_cellESignificanceThreshold);
197
198 // List of calorimeters from which to use cells
199 theTowers->SetCaloIndices(m_caloIndices);
200 theTowers->SetCaloSelection(m_caloSelection);
201
202 //
203 //Finished saving variable to CaloTopoTowerContainer
205
206 ToolHandleArray<ICaloTopoTowerBuilderToolBase>::const_iterator firstITool = m_ptools.begin();
207 ToolHandleArray<ICaloTopoTowerBuilderToolBase>::const_iterator lastITool = m_ptools.end();
208 StatusCode processStatus = StatusCode::SUCCESS;
209 //
210 // loop stops only when Failure indicated by one of the tools
211 //
212
213 ATH_MSG_DEBUG( "In execute() " );
214
215 while ( ! processStatus.isFailure() && firstITool != lastITool )
216 {
217 // CaloTopoTowerBuilderToolBase* pTool = *firstTool;
218 //sc = (*firstITool).retrieve();
219 //if ( sc.isFailure() ) { log << MSG::INFO << "error retrieving tool " << endmsg; }
220
221 //if ( (*firstITool).empty() ) { log << MSG::INFO << "tool is empty " << endmsg; }
222
223 //ATH_MSG_INFO( "tool retrieved, going to start " );
224 if ( theTicker != nullptr )
225 {
226 // ATH_MSG_INFO( "Chrono start " );
227 theTicker->chronoStart((*firstITool)->name());
228 }
229 /* ATH_MSG_INFO( "executing tool: " << (*firstITool)->name() );
230 ATH_MSG_INFO( "this is &(firstITool): " << &(firstITool) );
231 ATH_MSG_INFO( "this is (*firstITool): " << (*firstITool) );
232 ATH_MSG_INFO( "this is &(*firstITool): " << &(*firstITool) );
233 ATH_MSG_INFO( "this is &(*(*firstITool)): " << &(*(*firstITool)) );
234 ATH_MSG_INFO( "this is theTowers: " << theTowers );
235 */
236
237 processStatus = (*firstITool)->execute(ctx, theTowers.ptr());
238
239 // ATH_MSG_INFO( "processStatus is: " << processStatus );
240
241
242 if ( theTicker != nullptr )
243 {
244 // ATH_MSG_INFO( "Chrono stop " );
245 theTicker->chronoStop((*firstITool)->name());
246 }
247 if ( ! processStatus.isFailure() )
248 {
249 ATH_MSG_DEBUG( (*firstITool)->name()
250 << ": CaloTopoTowerContainer::size() = "
251 << theTowers->size() );
252 ++firstITool;
253 }
254 else
255 {
256 // some problem - but do not skip event loop!
257 ATH_MSG_ERROR( "problems while or after processing tool \042"
258 << (*firstITool)->name()
259 << "\042 - cross-check CaloTopoTowerContainer::size() = "
260 << theTowers->size() );
261 ++firstITool;
262 }
263 }
264
265 return StatusCode::SUCCESS;
266}
267
269// Finalize //
271
273{
274 return StatusCode::SUCCESS;
275}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< CaloTowerContainer > m_towerContainerKey
Gaudi::Property< std::vector< std::string > > m_includedCalos
Gaudi::Property< double > m_minimumCellEnergy
virtual StatusCode initialize() override
inherited from Algorithm
Gaudi::Property< bool > m_useCellWeights
Gaudi::Property< double > m_minimumClusterEnergy
SG::ReadHandleKey< CaloClusterContainer > m_clusterKey
std::vector< CaloCell_ID::SUBCALO > m_caloIndices
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Gaudi::Property< float > m_noiseSigma
CaloTopoTowerAlgorithm(const std::string &name, ISvcLocator *pService)
Algorithm constructor.
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandleArray< ICaloTopoTowerBuilderToolBase > m_ptools
SG::ReadHandleKey< CaloCell2ClusterMap > m_cellToClusterMapKey
SG::WriteHandleKey< CaloTopoTowerContainer > m_newTowerContainerKey
virtual ~CaloTopoTowerAlgorithm()
virtual StatusCode finalize() override
Gaudi::Property< float > m_cellESignificanceThreshold
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const std::string & name() const
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.