ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellContainerCheckerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5/********************************************************************
6
7NAME: CaloCellContainerCheckerTool
8PACKAGE: offline/Calorimeter/CaloRec
9
10AUTHORS: David Rousseau
11CREATED: May 12,2004
12
13PURPOSE: check integrity of CaloCellContainer find and iterators
14
15********************************************************************/
16
18
22
23#include "CLHEP/Units/SystemOfUnits.h"
24
26#include "FourMom/P4PxPyPzE.h"
27
28using CLHEP::MeV;
29
30
32// INITIALIZE:
33// The initialize method will create all the required algorithm objects
35
37
38 ATH_CHECK(detStore()->retrieve(m_theCaloCCIDM,"CaloCell_ID"));
39 return StatusCode::SUCCESS;
40}
41
42
43StatusCode
45 const EventContext& ctx) const
46{
47 return doProcess (theCont, ctx);
48}
49
50
51StatusCode
53 const EventContext& ctx) const
54{
55 return doProcess (theCont->asDataVector(), ctx);
56}
57
58
59StatusCode
61 const EventContext& ctx) const
62{
63 if (ctx.evt() >= m_eventsToCheck) {
64 return StatusCode::SUCCESS;
65 }
66
67 StatusCode returnSc = StatusCode::SUCCESS ;
68
69 double eSum = 0;
70 unsigned int index = 0;
71 std::vector<double> eSumCalos;
72 std::vector<unsigned int> nCellCalos;
73 for (int iCalo=CaloCell_ID::LAREM; iCalo<CaloCell_ID::NSUBCALO ; ++iCalo) {
74 eSumCalos.push_back(0.);
75 nCellCalos.push_back(0);
76 }
77
78
79 for (const CaloCell* aCell : *theCont) {
80 const CaloDetDescrElement * theDDE=aCell->caloDDE();
81 int iCalo = static_cast<int>(theDDE->getSubCalo());
82 eSum+=aCell->e();
83 eSumCalos[iCalo]+=aCell->e();
84 ++(nCellCalos[iCalo]);
85 ++index ;
86 P4PxPyPzE aP(aCell);
87 const double aPeta=aP.e() != 0 ? aP.eta() : 0;
88 const double aPphi=aP.phi() ;
89
90 // not needed anymore : now implemented in FOurMom
91 // if (aCell->e()<0) {
92 // aPeta=-aPeta;
93 // aPphi=aCaloPhiRange.fix(aPphi+aCaloPhiRange.twopi()/2.);
94 //}
95
96 if (aCell->e()!=0 && std::abs(aCell->eta()-aPeta)>0.0001) {
97 msg(MSG::WARNING) << "Cell " << index << " eta inconsistency : " << aCell->eta()
98 << " vs recalculated " << aPeta << endmsg ;
99 }
100 if (aCell->e()!=0 && std::abs(CaloPhiRange::diff(aCell->phi(),aPphi))>0.0001) {
101 msg(MSG::WARNING) << "Cell " << index << " phi inconsistency : " << aCell->phi()
102 << " vs recalculated " << aPphi << endmsg ;
103 }
104 }
105 index =0;
106 if (msgLvl(MSG::VERBOSE)) {
107 for (const CaloCell* aCell : *theCont) {
108 const CaloDetDescrElement * theDDE=aCell->caloDDE();
109 msg(MSG::VERBOSE) << index << " " << " " << aCell
110 << " hash id " << theDDE->calo_hash()
111 << " eta " << theDDE->eta()
112 << " phi " << theDDE->phi()
113 << " e " << aCell->e() << endmsg ;
114 ++index;
115 }
116 }
117
118 //check hasCalo() flags
119 for (int iCalo=CaloCell_ID::LAREM; iCalo<CaloCell_ID::NSUBCALO ; ++iCalo) {
120 if (nCellCalos[iCalo]>0 && !theCont->hasCalo(static_cast<CaloCell_ID::SUBCALO>(iCalo) ) )
121 {
122 msg(MSG::WARNING) << " There are cells for calo "
123 << iCalo << " but hasCalo is not set. " << endmsg ;
124 }
125 }
126
127 ATH_MSG_DEBUG(" eSum " << eSum);
128
129 //check now the sub calo iterators
130 for (int iCalo=CaloCell_ID::LAREM; iCalo<CaloCell_ID::NSUBCALO ; ++iCalo) {
131 CaloCell_ID::SUBCALO enumCalo=static_cast<CaloCell_ID::SUBCALO>(iCalo);
132 double theESumCalo=0;
133 unsigned int theNCellCalo=0;
134
135 CaloCellContainer::const_iterator itrCell=theCont->beginConstCalo(enumCalo);
136 CaloCellContainer::const_iterator endCell=theCont->endConstCalo(enumCalo);
137 for (;itrCell!=endCell;++itrCell){
138 theESumCalo+=(*itrCell)->e();
139 ++theNCellCalo;
140 }
141
142
143 ATH_MSG_DEBUG(" theNCellCalo="<<theNCellCalo
144 <<" nCellCalos[iCalo]=" <<nCellCalos[iCalo]
145 <<" theCont->nCellsCalo(enumCalo)=" << theCont->nCellsCalo(enumCalo) );
146
147 if (theNCellCalo!=nCellCalos[iCalo] ||
148 static_cast<int>(theNCellCalo)!=theCont->nCellsCalo(enumCalo) ) {
149 msg(MSG::ERROR) << " Iterators: ncell do not match"
150 << " theNCellCalo="<<theNCellCalo
151 <<" nCellCalos[iCalo]=" <<nCellCalos[iCalo]
152 <<" theCont->nCellsCalo(enumCalo)=" << theCont->nCellsCalo(enumCalo)
153 << endmsg;
154 returnSc = StatusCode::FAILURE;
155 }
156
157
158
159 ATH_MSG_DEBUG("theESumCalo eSumCalos[iCalo] "<< theESumCalo << " " << eSumCalos[iCalo]);
160 const double epsilon=1e-5;
161 if (fabs(theESumCalo-eSumCalos[iCalo])>epsilon) {
162 msg(MSG::ERROR) << " Non const iterators: E sum do not match"
163 << " subcalo " << iCalo
164 << " should be " << eSumCalos[iCalo]
165 << " is " << theESumCalo <<" (" << theESumCalo-eSumCalos[iCalo] << ")" << endmsg ;
166 returnSc = StatusCode::FAILURE;
167 }
168
169
170 }
171
172 // check find methods
173
174 // count number of holes
175 const unsigned int hashMax=m_theCaloCCIDM->calo_cell_hash_max();
176 unsigned int nHoles =0;
177
178 ATH_MSG_DEBUG("Now check all hashes give meaningful answer");
179 for (unsigned int theHash=0;theHash<hashMax;++theHash){
180 const CaloCell * theCell = theCont->findCell(theHash) ;
181 if (theCell==nullptr) {
182 ++nHoles;
183 if (msgLvl(MSG::VERBOSE)) {
184 //const CaloDetDescrElement* theCaloDDM->dde=get_element(theHash);
185 const Identifier id=m_theCaloCCIDM->cell_id(theHash);
186 const int subcalo=m_theCaloCCIDM->sub_calo(theHash);
187 const int sampling=m_theCaloCCIDM->calo_sample(theHash);
188 const int pos_neg=m_theCaloCCIDM->pos_neg(id);
189 const int region=m_theCaloCCIDM->region(id);
190 const int sample=m_theCaloCCIDM->sample(id);
191 msg(MSG::VERBOSE) << "Cell not found: id=0x" << std::hex << id << std::dec
192 << ", SubCalo=" <<subcalo <<", sampling="<< sampling << ", pos_neg="
193 << pos_neg << ", region=" << region << ", sample=" << sample << endmsg;
194 }//end if verbose
195 }//end if cell==0
196 }//end loop over hashes
197 ATH_MSG_DEBUG("Number of hash with no cells: " << nHoles << " out of " << hashMax);
198
199 std::vector<IdentifierHash> hashes ;
200 hashes.clear();
201 double eSumFound=0;
202
203 index =0;
204
205 for ( CaloCellContainer::const_iterator itrCell=theCont->begin();itrCell!=theCont->end();++itrCell){
206 IdentifierHash theHash = (*itrCell)->caloDDE()->calo_hash();
207 if ((*itrCell)->et()>2000 * MeV ) {
208 hashes.push_back(theHash);
209 eSumFound+=(*itrCell)->energy();
210 }
211 const CaloCell * reCell=theCont->findCell(theHash);
212 if (reCell!=*itrCell){
213
214 const CaloDetDescrElement * reCaloDDE=nullptr ;
215 unsigned int reHash=0 ;
216
217
218 if (reCell!=nullptr) reCaloDDE=reCell->caloDDE();
219 if (reCaloDDE!=nullptr) reHash = reCaloDDE->calo_hash();
220
221
222 msg(MSG::ERROR) << index << "Cell " << theHash << " " << *itrCell
223 << " not found back " << reCell
224 << " reCaloDDE " << reCaloDDE
225 << " rehash " << reHash << endmsg ;
226 returnSc = StatusCode::FAILURE;
227 }
228 ++index;
229 }
230
231 ATH_MSG_DEBUG("number of cells to be refound " << hashes.size() << " total energy " << eSumFound);
232
234 foundCells.clear();
235
236 theCont->findCellVector(hashes,foundCells);
237
238 if (hashes.size()!=foundCells.size()){
239 msg(MSG::ERROR) << "number of cells to be found " << hashes.size() << "number found: " << foundCells.size() << endmsg ;
240 returnSc = StatusCode::FAILURE;
241 }
242
243
244 double reSumFound=0;
245
246 for (CaloCellContainer::CellVector::const_iterator itrCell=foundCells.begin();itrCell!=foundCells.end(); ++itrCell)
247 if (*itrCell!=0) reSumFound+=(*itrCell)->e();
248
249
250 if (std::abs(reSumFound-eSumFound)>10 * MeV ){
251 msg(MSG::ERROR) << "Found cells wrong E sum " << reSumFound << " instead of " << eSumFound << endmsg ;
252 returnSc = StatusCode::FAILURE;
253 }
254
255 return returnSc ;
256}
257
258
259
260
261
262
263
264
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
CaloCellContainer that can accept const cell pointers.
CaloPhiRange class declaration.
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
virtual StatusCode initialize() override
Gaudi::Property< unsigned > m_eventsToCheck
StatusCode doProcess(const CaloCellContainer *theCellContainer, const EventContext &ctx) const
Container class for CaloCell.
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
std::vector< const CaloCell * > CellVector
type to be used for the internal lookup table, and to return list of cells
void findCellVector(const std::vector< IdentifierHash > &theVectorHash, CellVector &theCellVector) const
fast find method given vector of identifier hash.
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
bool hasCalo(const CaloCell_ID::SUBCALO caloNum) const
tell wether it has been filled with cells (maybe none) of a given calo
int nCellsCalo(const CaloCell_ID::SUBCALO caloNum) const
get number of cels of given calorimeter
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
CaloCellContainer that can accept const cell pointers.
This class groups all DetDescr information related to a CaloCell.
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This is a "hash" representation of an Identifier.
virtual double phi() const
phi in [-pi,pi[
virtual double eta() const
pseudo rapidity
P4PxPyPzE is a class with 4-momentum behavior, for which Px, Py, Pz and M are data members.
Definition P4PxPyPzE.h:29
virtual double e() const
get energy data member
Definition P4PxPyPzE.h:132
Definition index.py:1
MsgStream & msg
Definition testRead.cxx:32