ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCell2ClusterMapper.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//-----------------------------------------------------------------------
6// File and Version Information:
7// $Id: CaloCell2ClusterMapper.cxx,v 1.6 2009-04-18 02:56:18 ssnyder Exp $
8//
9// Description: see CaloCell2ClusterMapper.h
10//
11// Environment:
12// Software developed for the ATLAS Detector at CERN LHC
13//
14// Author List:
15// Sven Menke
16//
17//-----------------------------------------------------------------------
18
19//-----------------------
20// This Class's Header --
21//-----------------------
23
24//----------------------------
25// This Class's Base Header --
26//----------------------------
27
28//---------------
29// C++ Headers --
30//---------------
31#include <list>
32#include <iterator>
33#include <sstream>
36#include "CaloEvent/CaloClusterContainer.h"
39
40
41//###############################################################################
43 ISvcLocator* pSvcLocator)
44 : AthReentrantAlgorithm(name, pSvcLocator),
46 m_clusterKey("")
47{
48
49 // Name of Cell2Cluster Map to be registered in TDS
50 declareProperty("MapOutputName",m_mapOutputKey);
51
52 // Name of CaloClusterContainer to use as input
53 declareProperty("ClustersName",m_clusterKey);
54}
55
56//###############################################################################
57
59= default;
60
61//###############################################################################
62
64 return StatusCode::SUCCESS;
65}
66
67//###############################################################################
68
70{
71 return StatusCode::SUCCESS;
72}
73
74//###############################################################################
75
76StatusCode CaloCell2ClusterMapper::execute(const EventContext& ctx) const {
77
78 // make a DataVector of Navigable CaloClusterContainer
79 ATH_MSG_DEBUG(" Recording Cell2Cluster Map " << m_mapOutputKey.key());
80
82 ATH_CHECK( cell2ClusterMap.record(std::make_unique<CaloCell2ClusterMap>
84
85 const CaloCell_ID* calo_id = nullptr;
86 ATH_CHECK(detStore()->retrieve(calo_id,"CaloCell_ID"));
87
88 // resize it to total range of IdentifierHash for all calos
89 Identifier::size_type maxRange = calo_id->calo_cell_hash_max();
90 cell2ClusterMap->resize(maxRange);
91
93
94
95 ATH_MSG_DEBUG("CaloCluster container: " << clusColl.name()
96 <<" contains " << clusColl->size() << " clusters");
97
98 std::vector<double> weightedESum;
99 weightedESum.resize(clusColl->size());
100
101 std::vector<int> numberOfCells;
102 numberOfCells.resize(clusColl->size());
103
105
106 // loop over cluster collection and add each cluster to the map for
107 // each member cell
108 unsigned int iClus = 0;
109 for (const CaloCluster* clus : *clusColl) {
110 // loop over its cell members
111 CaloCluster::cell_iterator cellIter = clus->cell_begin();
112 CaloCluster::cell_iterator cellIterEnd = clus->cell_end();
113 for (; cellIter != cellIterEnd; cellIter++) {
114 // look up the IdentifierHash for the current cell
115 IdentifierHash myHashId = calo_id->calo_cell_hash((*cellIter)->ID());
116 // get the existing? Navigable for this cell
117 Navigable<CaloClusterContainer> *theNav = (*cell2ClusterMap)[myHashId];
118 if (!theNav) {
119 // create a new Navigable if it doesn't exist
120 theNav = navPool.nextElementPtr();
121 theNav->removeAll();
122 // and store it in the vector
123 (*cell2ClusterMap)[myHashId] = theNav;
124 }
125 // add the current cluster to the list of clusters for this cell
126 theNav->putElement(clusColl.cptr(), clus);
127 // add the energy*weight for this cell to the weightedESum
128 //if ( messageService()->outputLevel(name()) <= MSG::DEBUG) {
129 if (msgLvl(MSG::DEBUG)) {
130 weightedESum[iClus] += (clus->getCellWeight(*cellIter))
131 * ((*cellIter)->energy());
132 numberOfCells[iClus]++;
133 }
134 }
135 }
136
137 // compare weighted sums per cluster from the map with cluster energies
138 if (msgLvl(MSG::DEBUG)) {
139 double epsilon = 0.001;
140 unsigned int iClus = 0;
141 for (const CaloCluster* clus : *clusColl) {
142 if (fabs(weightedESum[iClus] - clus->e())
143 > epsilon * fabs(clus->e()))
144 {
145 //FIXME: WARNING printed only if msglevel <=
146 ATH_MSG_WARNING( "CaloCluster has E = " << clus->e()
147 << " MeV, while weighted sum of cells gives E = "
148 << weightedESum[iClus]
149 << " MeV! Complain with the creator of the CaloClusterContainer named "
150 << m_clusterKey.key() );
151 } else {
152 ATH_MSG_DEBUG( "CaloCluster and weighted sum of cell members have E = "
153 << clus->e() << " MeV, good!" );
154 }
155 if (numberOfCells[iClus] != static_cast<int>(clus->getNumberOfCells())) {
156 //FIXME: WARNING printed only if msglevel <=
157 ATH_MSG_WARNING( "CaloCluster has N = "
158 << clus->getNumberOfCells() << " cells, while N = "
159 << numberOfCells[iClus]
160 << " cells are in the map! Something is wrong with the creation of the Map!" );
161 } else {
162 ATH_MSG_DEBUG( "CaloCluster with N = "
163 << clus->getNumberOfCells() << " cells is in the map, good!" );
164 }
165 } //end loop over clusters
166 } //end if DEBUG
167
168 // print the Map
169 if (msgLvl(MSG::VERBOSE)) {
170 for (unsigned int iHash = 0; iHash < maxRange; iHash++) {
171 // get the existing? Navigable for this cell
172 Navigable<CaloClusterContainer> *theNav = (*cell2ClusterMap)[iHash];
173 if (theNav) {
174 msg(MSG::VERBOSE) << "CaloCell with hashID " << iHash << " belongs to";
175 for (const CaloCluster* pClus : *theNav) {
176 // the next line assumes all cells of the cluster belong to the same
177 // cell container ...
178 const CaloCellContainer *cellColl = pClus->getCellContainer(
179 *(pClus->cell_begin()));
180 const CaloCell* pCell = cellColl->findCell(iHash);
181 if (!pCell) {
182 // need to find the cell in clusters member list because the
183 // cluster is made of more than one cell container
184 CaloCluster::cell_iterator cellIter = pClus->cell_begin();
185 CaloCluster::cell_iterator cellIterEnd = pClus->cell_end();
186 for (; cellIter != cellIterEnd; cellIter++) {
187 pCell = (*cellIter);
188 // look up the IdentifierHash for the current cell
189 IdentifierHash myHashId = calo_id->calo_cell_hash(pCell->ID());
190 if (((unsigned int) myHashId) == iHash)
191 break;
192 else
193 pCell = nullptr;
194 }
195 }
196 if (pCell)
197 msg() << " Cluster with E_clus = " << pClus->e()
198 << " MeV with weight w_cell = " << pClus->getCellWeight(pCell)
199 << " ";
200 }
201 msg() << endmsg;
202 }
203 }
204 }
205
206 return StatusCode::SUCCESS;
207}
208
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< CaloClusterContainer > m_clusterKey
Name of the CaloClusterContainer to use.
virtual ~CaloCell2ClusterMapper()
virtual StatusCode execute(const EventContext &ctx) const override
CaloCell2ClusterMapper(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
SG::WriteHandleKey< CaloCell2ClusterMap > m_mapOutputKey
Name of the CaloCell2ClusterMap in StoreGate.
virtual StatusCode finalize() override
Container class for CaloCell.
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
size_type calo_cell_hash_max() const
cell 'global' hash table max size
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
Principal data class for CaloCell clusters.
CaloCompositeCellBase< CaloClusterNavigable >::cell_iterator cell_iterator
Iterator on CaloCell s.
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
This is a "hash" representation of an Identifier.
Navigable template generalization to handle navigation.
Definition Navigable.h:93
bool removeAll()
Definition Navigable.h:237
void putElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
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.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts