ATLAS Offline Software
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"
11 #include "CaloTopoTowerAlgorithm.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 {
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 
173 StatusCode 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 
236 
237  // Noise tool stuff
238  theTowers->SetNoiseSigma(m_noiseSigma);
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 }
CaloTopoTowerAlgorithm::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: CaloTopoTowerAlgorithm.h:77
CaloTopoTowerAlgorithm::m_caloSelection
bool m_caloSelection
Definition: CaloTopoTowerAlgorithm.h:98
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
CaloTopoTowerContainer::SetClusters
void SetClusters(const CaloClusterContainer *c)
Definition: CaloTopoTowerContainer.h:189
CaloTopoTowerContainer::SetNoiseSigma
void SetNoiseSigma(float c)
Definition: CaloTopoTowerContainer.h:200
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
CaloTopoTowerAlgorithm::m_clusterKey
SG::ReadHandleKey< CaloClusterContainer > m_clusterKey
Definition: CaloTopoTowerAlgorithm.h:78
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
CaloTopoTowerAlgorithm::m_caloIndices
std::vector< CaloCell_ID::SUBCALO > m_caloIndices
Definition: CaloTopoTowerAlgorithm.h:97
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
CaloTopoTowerAlgorithm::m_genericLink
bool m_genericLink
Definition: CaloTopoTowerAlgorithm.h:61
CaloTowerSeg.h
CaloTopoTowerAlgorithm::m_includedCalos
std::vector< std::string > m_includedCalos
Definition: CaloTopoTowerAlgorithm.h:96
CaloTopoTowerContainer::SetCellToClusterMap
void SetCellToClusterMap(const CaloCell2ClusterMap *c)
Definition: CaloTopoTowerContainer.h:192
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloTopoTowerContainer::SetMinimumCellEnergy
void SetMinimumCellEnergy(double c)
Definition: CaloTopoTowerContainer.h:195
CaloTopoTowerAlgorithm::~CaloTopoTowerAlgorithm
virtual ~CaloTopoTowerAlgorithm()
CaloTopoTowerAlgorithm::m_minimumCellEnergy
double m_minimumCellEnergy
Definition: CaloTopoTowerAlgorithm.h:84
CaloTopoTowerAlgorithm.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloTopoTowerContainer::SetCellESignificanceThreshold
void SetCellESignificanceThreshold(float c)
Definition: CaloTopoTowerContainer.h:201
CaloTopoTowerContainer::SetCaloSelection
void SetCaloSelection(bool c)
Definition: CaloTopoTowerContainer.h:205
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
CaloTopoTowerAlgorithm::CaloTopoTowerAlgorithm
CaloTopoTowerAlgorithm(const std::string &name, ISvcLocator *pService)
Algorithm constructor.
Definition: CaloTopoTowerAlgorithm.cxx:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
CaloTopoTowerContainer::SetMinimumClusterEnergy
void SetMinimumClusterEnergy(double c)
Definition: CaloTopoTowerContainer.h:196
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
CaloTopoTowerAlgorithm::m_towerContainerKey
SG::ReadHandleKey< CaloTowerContainer > m_towerContainerKey
Definition: CaloTopoTowerAlgorithm.h:80
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloTopoTowerAlgorithm::m_cellESignificanceThreshold
float m_cellESignificanceThreshold
Definition: CaloTopoTowerAlgorithm.h:90
CaloTowerContainer::towerseg
const CaloTowerSeg & towerseg() const
Return a copy of the attached CaloTowerSeg.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:591
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloTopoTowerContainer.h
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
CaloTopoTowerAlgorithm::m_cellToClusterMapKey
SG::ReadHandleKey< CaloCell2ClusterMap > m_cellToClusterMapKey
Definition: CaloTopoTowerAlgorithm.h:79
CaloTopoTowerAlgorithm::initialize
virtual StatusCode initialize() override
inherited from Algorithm
Definition: CaloTopoTowerAlgorithm.cxx:69
CaloCellContainer.h
CaloTopoTowerAlgorithm::m_newTowerContainerKey
SG::WriteHandleKey< CaloTopoTowerContainer > m_newTowerContainerKey
Definition: CaloTopoTowerAlgorithm.h:81
CaloTopoTowerAlgorithm::m_minimumClusterEnergy
double m_minimumClusterEnergy
Definition: CaloTopoTowerAlgorithm.h:85
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloTopoTowerContainer::SetCells
void SetCells(const CaloCellContainer *c)
Definition: CaloTopoTowerContainer.h:191
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
CaloTopoTowerContainer::SetCaloIndices
void SetCaloIndices(const std::vector< CaloCell_ID::SUBCALO > &c)
Definition: CaloTopoTowerContainer.h:204
CaloTopoTowerContainer::SetUseCellWeights
void SetUseCellWeights(bool c)
Definition: CaloTopoTowerContainer.h:197
CaloCell_Base_ID::NSUBCALO
@ NSUBCALO
Definition: CaloCell_Base_ID.h:46
CaloTopoTowerAlgorithm::finalize
virtual StatusCode finalize() override
Definition: CaloTopoTowerAlgorithm.cxx:315
CaloTopoTowerAlgorithm::m_ptools
ToolHandleArray< ICaloTopoTowerBuilderToolBase > m_ptools
Definition: CaloTopoTowerAlgorithm.h:65
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
CaloTopoTowerAlgorithm::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloTopoTowerAlgorithm.cxx:173
CaloTopoTowerAlgorithm::m_noiseSigma
float m_noiseSigma
Definition: CaloTopoTowerAlgorithm.h:89
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloTopoTowerAlgorithm::m_useCellWeights
bool m_useCellWeights
Definition: CaloTopoTowerAlgorithm.h:86
CaloTopoTowerContainer::SetTowers
void SetTowers(const CaloTowerContainer *c)
Definition: CaloTopoTowerContainer.h:190