ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellContainerCheckerTool Class Reference

#include <CaloCellContainerCheckerTool.h>

Inheritance diagram for CaloCellContainerCheckerTool:
Collaboration diagram for CaloCellContainerCheckerTool:

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode process (CaloCellContainer *theCellContainer, const EventContext &ctx) const override
virtual StatusCode process (CaloConstCellContainer *theCellContainer, const EventContext &ctx) const override

Private Member Functions

StatusCode doProcess (const CaloCellContainer *theCellContainer, const EventContext &ctx) const

Private Attributes

Gaudi::Property< unsigned > m_eventsToCheck {this,"EventsToCheck",5}
const CaloCell_IDm_theCaloCCIDM = nullptr

Detailed Description

Definition at line 16 of file CaloCellContainerCheckerTool.h.

Member Function Documentation

◆ doProcess()

StatusCode CaloCellContainerCheckerTool::doProcess ( const CaloCellContainer * theCellContainer,
const EventContext & ctx ) const
private

Definition at line 60 of file CaloCellContainerCheckerTool.cxx.

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}
#define endmsg
#define ATH_MSG_DEBUG(x)
Gaudi::Property< unsigned > m_eventsToCheck
std::vector< const CaloCell * > CellVector
type to be used for the internal lookup table, and to return list of cells
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
str index
Definition DeMoScan.py:362
::StatusCode StatusCode
StatusCode definition for legacy code.
MsgStream & msg
Definition testRead.cxx:32

◆ initialize()

StatusCode CaloCellContainerCheckerTool::initialize ( )
overridevirtual

Definition at line 36 of file CaloCellContainerCheckerTool.cxx.

36 {
37
38 ATH_CHECK(detStore()->retrieve(m_theCaloCCIDM,"CaloCell_ID"));
39 return StatusCode::SUCCESS;
40}
#define ATH_CHECK
Evaluate an expression and check for errors.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ process() [1/2]

StatusCode CaloCellContainerCheckerTool::process ( CaloCellContainer * theCellContainer,
const EventContext & ctx ) const
overridevirtual

Definition at line 44 of file CaloCellContainerCheckerTool.cxx.

46{
47 return doProcess (theCont, ctx);
48}
StatusCode doProcess(const CaloCellContainer *theCellContainer, const EventContext &ctx) const

◆ process() [2/2]

StatusCode CaloCellContainerCheckerTool::process ( CaloConstCellContainer * theCellContainer,
const EventContext & ctx ) const
overridevirtual

Definition at line 52 of file CaloCellContainerCheckerTool.cxx.

54{
55 return doProcess (theCont->asDataVector(), ctx);
56}

Member Data Documentation

◆ m_eventsToCheck

Gaudi::Property<unsigned> CaloCellContainerCheckerTool::m_eventsToCheck {this,"EventsToCheck",5}
private

Definition at line 34 of file CaloCellContainerCheckerTool.h.

34{this,"EventsToCheck",5};

◆ m_theCaloCCIDM

const CaloCell_ID* CaloCellContainerCheckerTool::m_theCaloCCIDM = nullptr
private

Definition at line 35 of file CaloCellContainerCheckerTool.h.


The documentation for this class was generated from the following files: