ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTopoTowerAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7#include "CaloEvent/CaloTowerContainer.h"
9#include "CaloEvent/CaloClusterContainer.h"
12
13#include <string>
14#include <vector>
15#include <iomanip>
16
18 ISvcLocator* pSvcLocator)
19 : AthReentrantAlgorithm(name,pSvcLocator)
20 , m_genericLink(true)
21 , m_ptools( this )
22 , m_cellContainerKey("AllCalo")
23 , m_clusterKey("CaloTopoClusters")
24 , m_cellToClusterMapKey("CaloCell2TopoCluster")
25 , m_towerContainerKey("CmbTower")
26 , m_newTowerContainerKey("TopoTower")
27 , m_caloSelection(false)
28{
29 // tool names
30 //declareProperty("TowerBuilderTools",m_toolNames);
31 declareProperty("TowerBuilderTools",m_ptools);
32 // output data
33 //declareProperty("TowerContainerName",m_towerContainerName);
34 // linkable
35 declareProperty("GenericLinked",m_genericLink);
36
38 //Item From CaloTopoTowerAlg
39 declareProperty("Cell2ClusterMapName", m_cellToClusterMapKey);
40 declareProperty("CellContainerName" , m_cellContainerKey);
41 declareProperty("ClusterContainerName", m_clusterKey);
42 declareProperty("InputTowerContainerName" , m_towerContainerKey);
43 declareProperty("OutputTowerContainerName", m_newTowerContainerKey);
44
45 // Declare configurable properties of the algorithm
46 declareProperty("MinimumCellEnergy", m_minimumCellEnergy = -1000000000.0);
47 declareProperty("MinimumClusterEnergy", m_minimumClusterEnergy = -1000000000.0);
48
49 // Noise Tool stuff
50 declareProperty("DefaultNoiseSigma", m_noiseSigma = 10.0);
51 declareProperty("CellEnergySignificance", m_cellESignificanceThreshold = -1);
52
53 // Calo from which to use cells
54 declareProperty("IncludedCalos", m_includedCalos);
55 declareProperty("useCellWeight", m_useCellWeights=true);
56
57 //END Item From CaloTopoTowerAlg
59
60}
61
63= default;
64
66// Initialize //
68
70{
71 ATH_CHECK(m_cellContainerKey.initialize());
72 ATH_CHECK(m_clusterKey.initialize());
73 ATH_CHECK(m_cellToClusterMapKey.initialize());
74 ATH_CHECK(m_towerContainerKey.initialize());
76
77 m_caloIndices.clear();
78 for ( unsigned int iCalos=0; iCalos< m_includedCalos.size(); iCalos++ )
79 {
80 if ( m_includedCalos[iCalos] == "LAREM" )
81 {
83 }
84 else if ( m_includedCalos[iCalos] == "LARHEC")
85 {
87 }
88 else if ( m_includedCalos[iCalos] == "LARFCAL" )
89 {
91 }
92 else if ( m_includedCalos[iCalos] == "TILE" )
93 {
95 }
96 }
97
98 m_caloSelection=false;
99 unsigned int nSubCalo=static_cast<int>(CaloCell_ID::NSUBCALO) ;
100 if (!m_caloIndices.empty() && m_caloIndices.size()<nSubCalo) m_caloSelection=true;
101
102 ATH_MSG_INFO( " Calo selection applied ? " << m_caloSelection );
103 if (m_caloSelection) {
104 msg() << MSG::INFO << " subcalo selected ";
105 for (unsigned int iCalos=0;iCalos< m_includedCalos.size(); iCalos++ )
106 msg() << MSG::INFO << " " << m_includedCalos[iCalos];
107 msg() << MSG::INFO << " " << endmsg;
108 }
109
110
112 // Allocate Tools //
114
115 // check tool names
116 if ( m_ptools.empty() )
117 {
118 ATH_MSG_ERROR( "no tools given for this algorithm." );
119 return StatusCode::FAILURE;
120 }
121
122 // find tools
123
124 unsigned int toolCtr = 0;
125 ATH_MSG_INFO( " " );
126 ATH_MSG_INFO( "List of tools in execution sequence:" );
127 ATH_MSG_INFO( "------------------------------------" );
128
129 StatusCode checkOut = m_ptools.retrieve();
130 if ( checkOut.isFailure() )
131 {
132 ATH_MSG_WARNING( "Cannot retrieve tool array " << m_ptools );
133 return StatusCode::FAILURE;
134 }
135
136 for (ToolHandle<ICaloTopoTowerBuilderToolBase>& tool : m_ptools)
137 {
138 toolCtr++;
139 /* ATH_MSG_INFO( "retrieving tool" );
140
141 if ( checkOut.isFailure() ) {
142 ATH_MSG_WARNING( "Cannot retrieve tool at ToolArray[" << toolCtr-1 << "]" );
143 ATH_MSG_WARNING( "This tool won't be used" );
144 }
145 else {
146 ATH_MSG_INFO( "retrieved tool" );
147 // print the list of tools
148 */
149
150
151 ATH_MSG_INFO( std::setw(2) << toolCtr << ".) "
152 << tool->type()
153 << "::name() = \042"
154 << tool->name()
155 << "\042" );
156
157 ATH_MSG_INFO( "------------------------------------" );
158 ATH_MSG_INFO( " " );
159
160 /*if ( tool->initializeTool().isFailure() ) {
161
162 ATH_MSG_WARNING( " Tool failed to initialize" );
163 }*/
164
165 } //close iteration over tools
166 return StatusCode::SUCCESS;
167}
168
170// Execute //
172
173StatusCode CaloTopoTowerAlgorithm::execute (const EventContext& ctx) const
174{
175
177 // Re-allocate Services //
179
180 //timing
181 IChronoStatSvc* theTicker = chronoSvc();
182
184 // Tool Processing //
188 if ( !towerContainer.isValid() ) {
189 ATH_MSG_WARNING( " cannot retrieve tower container with key " << towerContainer.name() );
190 return StatusCode::SUCCESS;
191 }
192
195 if ( !theCells.isValid()) {
196 ATH_MSG_WARNING( " cannot retrieve cell container with key " << theCells.name() );
197 return StatusCode::SUCCESS;
198 }
199 ATH_MSG_DEBUG( "CaloTopoTowerAlgorithm::execute " << theCells.name() << " size= " << theCells->size() );
200
203
204 if ( !clusters.isValid() )
205 {
206 ATH_MSG_WARNING( "cannot retrieve CaloClusterContainer with key <"
207 << clusters.name() << ">" );
208 return StatusCode::SUCCESS;
209 }
210
213 if ( !cellToClusterMap.isValid() ){
214 ATH_MSG_WARNING( "cannot retrieve CaloCell2ClusterMap with key <"
215 << cellToClusterMap.name() << ">" );
216 return StatusCode::SUCCESS;
217 }
218
219 ATH_MSG_DEBUG( "Successfully retrieved CaloCell2ClusterMap <"<< cellToClusterMap.name() << ">" );
220
222 ATH_CHECK( theTowers.record (std::make_unique<CaloTopoTowerContainer>(towerContainer->towerseg())) );
223
225 //Starting to save variable to CaloTopoTowerContainer
226 //
227
228 theTowers->SetTowers(towerContainer.cptr());
229 theTowers->SetClusters(clusters.ptr());
230 theTowers->SetCells(theCells.cptr());
231 theTowers->SetCellToClusterMap(cellToClusterMap.cptr());
232
233 theTowers->SetMinimumCellEnergy(m_minimumCellEnergy);
234 theTowers->SetMinimumClusterEnergy(m_minimumClusterEnergy);
235 theTowers->SetUseCellWeights(m_useCellWeights);
236
237 // Noise tool stuff
238 theTowers->SetNoiseSigma(m_noiseSigma);
239 theTowers->SetCellESignificanceThreshold(m_cellESignificanceThreshold);
240
241 // List of calorimeters from which to use cells
242 theTowers->SetCaloIndices(m_caloIndices);
243 theTowers->SetCaloSelection(m_caloSelection);
244
245 //
246 //Finished saving variable to CaloTopoTowerContainer
248
249 ToolHandleArray<ICaloTopoTowerBuilderToolBase>::const_iterator firstITool = m_ptools.begin();
250 ToolHandleArray<ICaloTopoTowerBuilderToolBase>::const_iterator lastITool = m_ptools.end();
251 StatusCode processStatus = StatusCode::SUCCESS;
252 //
253 // loop stops only when Failure indicated by one of the tools
254 //
255
256 ATH_MSG_DEBUG( "In execute() " );
257
258 while ( ! processStatus.isFailure() && firstITool != lastITool )
259 {
260 // CaloTopoTowerBuilderToolBase* pTool = *firstTool;
261 //sc = (*firstITool).retrieve();
262 //if ( sc.isFailure() ) { log << MSG::INFO << "error retrieving tool " << endmsg; }
263
264 //if ( (*firstITool).empty() ) { log << MSG::INFO << "tool is empty " << endmsg; }
265
266 //ATH_MSG_INFO( "tool retrieved, going to start " );
267 if ( theTicker != nullptr )
268 {
269 // ATH_MSG_INFO( "Chrono start " );
270 theTicker->chronoStart((*firstITool)->name());
271 }
272 /* ATH_MSG_INFO( "executing tool: " << (*firstITool)->name() );
273 ATH_MSG_INFO( "this is &(firstITool): " << &(firstITool) );
274 ATH_MSG_INFO( "this is (*firstITool): " << (*firstITool) );
275 ATH_MSG_INFO( "this is &(*firstITool): " << &(*firstITool) );
276 ATH_MSG_INFO( "this is &(*(*firstITool)): " << &(*(*firstITool)) );
277 ATH_MSG_INFO( "this is theTowers: " << theTowers );
278 */
279
280 processStatus = (*firstITool)->execute(ctx, theTowers.ptr());
281
282 // ATH_MSG_INFO( "processStatus is: " << processStatus );
283
284
285 if ( theTicker != nullptr )
286 {
287 // ATH_MSG_INFO( "Chrono stop " );
288 theTicker->chronoStop((*firstITool)->name());
289 }
290 if ( ! processStatus.isFailure() )
291 {
292 ATH_MSG_DEBUG( (*firstITool)->name()
293 << ": CaloTopoTowerContainer::size() = "
294 << theTowers->size() );
295 ++firstITool;
296 }
297 else
298 {
299 // some problem - but do not skip event loop!
300 ATH_MSG_ERROR( "problems while or after processing tool \042"
301 << (*firstITool)->name()
302 << "\042 - cross-check CaloTopoTowerContainer::size() = "
303 << theTowers->size() );
304 ++firstITool;
305 }
306 }
307
308 return StatusCode::SUCCESS;
309}
310
312// Finalize //
314
316{
317 return StatusCode::SUCCESS;
318}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< CaloTowerContainer > m_towerContainerKey
virtual StatusCode initialize() override
inherited from Algorithm
SG::ReadHandleKey< CaloClusterContainer > m_clusterKey
std::vector< CaloCell_ID::SUBCALO > m_caloIndices
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
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
std::vector< std::string > m_includedCalos
SG::WriteHandleKey< CaloTopoTowerContainer > m_newTowerContainerKey
virtual ~CaloTopoTowerAlgorithm()
virtual StatusCode finalize() override
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.