ATLAS Offline Software
CalibHitIDCheck.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 // Filename : CalibHitIDCheck.cxx
7 //
8 // Author : Gia gia@mail.cern.ch
9 // Created : April, 2005
10 //
11 // DESCRIPTION:
12 //
13 // Helper tool for CalibHits Identifiers checking
14 //
15 //*************************************************************************************
16 
17 //Gaudi Includes
18 #include "GaudiKernel/Bootstrap.h"
19 #include "GaudiKernel/ISvcLocator.h"
20 #include "GaudiKernel/IMessageSvc.h"
21 #include "GaudiKernel/IDataProviderSvc.h"
22 
23 // Calo include
26 
28 
29 #include <iostream>
30 
31 
32 // Constructor & destructor
33 CalibHitIDCheck::CalibHitIDCheck(const std::string& name, ISvcLocator* pSvcLocator)
34  :AthAlgorithm(name, pSvcLocator),
35  m_Merge(false),
36  m_LArDMHitCnt(nullptr),
37  m_ActiveHitCnt(nullptr),
38  m_InactiveHitCnt(nullptr),
39  m_TileActiveHitCnt(nullptr),
40  m_TileInactiveHitCnt(nullptr),
41  m_TileDMHitCnt(nullptr),
42  m_id_helper(nullptr)
43 {
44  declareProperty("InactiveCalibHitCnt", m_larInactiveHitContainer = "LArCalibrationHitInactive");
45  declareProperty("ActiveCalibHitCnt", m_larActiveHitContainer = "LArCalibrationHitActive");
46  declareProperty("LArDMCalibHitCnt", m_larDMHitContainer = "LArCalibrationHitDeadMaterial");
47  declareProperty("TileActiveHitCnt", m_tileActiveHitContainer = "TileCalibHitActiveCell");
48  declareProperty("TileInactiveHitCnt", m_tileInactiveHitContainer = "TileCalibHitInactiveCell");
49  declareProperty("TileDMCalibHitCnt", m_tiledmHitContainer = "TileCalibHitDeadMaterial");
50 
51  declareProperty("Check", m_Check = true);
52  declareProperty("ShowAll", m_ShowAll = false);
53  declareProperty("CheckAll", m_CheckAll = false);
54 
55 }
56 
58 
59 
60 
63 {
65  ATH_MSG_INFO("initialisation completed" );
66  return StatusCode::SUCCESS;
67 }
68 
69 
70 
71 
74 {
81 
82  //We need merge only Inactive and Active
83  //LAr CalibHit Containers only once
84  m_Merge=false;
85 
86 
87  //check containers separately
88  if(m_Check) {
89  if(m_InactiveHitCnt) { check(0); }
90  if(m_ActiveHitCnt) { check(1); }
91  if(m_TileInactiveHitCnt){ check(2); }
92  if(m_TileActiveHitCnt) { check(3); }
93  if(m_LArDMHitCnt) { check(4); }
94  if(m_TileDMHitCnt) { check(5); }
95  }
96 
97 
98  //show all IDs from all containers
99  if(m_ShowAll) show_all();
100 
101 
102  //check all containers
104 
105 
106  //reset member 'm_id_vec'
107  reset();
108 
109 
110  ATH_MSG_DEBUG("execute() completed successfully" );
111  return StatusCode::SUCCESS;
112 }
113 
114 
115 
116 
119 {
120  ATH_MSG_INFO("finalize() successfully" );
121  return StatusCode::SUCCESS;
122 }
123 
124 
125 
126 
127 
128 //**********************************************************
129 // ------------------------ METHODS ------------------------
130 //**********************************************************
131 
132 //This method checks separately all the presented CalibHit
133 //containers for not valid, container not respected
134 //('alien') and repeated Identifiers
135 void CalibHitIDCheck::check(int l_cnt) {
136 
137  std::vector<Identifier> id_vec;
138  std::map<Identifier, int> id_map;
141 
142  bool no_invalid = true;
143  bool no_alien = true;
144 
145  //define appropriate iterator over the container
146  switch(l_cnt) {
147  case 0:
148 
149  if((m_InactiveHitCnt->Size()) != 0 )
150  {
151  ATH_MSG_INFO(" " );
152  ATH_MSG_INFO("*************************************************************" );
153  ATH_MSG_INFO("Investigate CalibHit IDs from LAr Inactive CalibHit Container" );
154  ATH_MSG_INFO("*************************************************************" );
155 
157  end = m_InactiveHitCnt->end();
158  }
159  else
160  {
161  return;
162  }
163  break;
164 
165 
166  case 1:
167 
168  if((m_ActiveHitCnt->Size()) != 0 )
169  {
170  ATH_MSG_INFO(" " );
171  ATH_MSG_INFO("***********************************************************" );
172  ATH_MSG_INFO("Investigate CalibHit IDs from LAr Active CalibHit Container" );
173  ATH_MSG_INFO("***********************************************************" );
174 
175  it = m_ActiveHitCnt->begin();
176  end = m_ActiveHitCnt->end();
177 
178  m_Merge=true;
179  }
180  else
181  {
182  return;
183  }
184  break;
185 
186 
187  case 2:
188 
189  if((m_TileInactiveHitCnt->Size()) != 0 )
190  {
191  ATH_MSG_INFO(" " );
192  ATH_MSG_INFO("**************************************************************" );
193  ATH_MSG_INFO("Investigate CalibHit IDs from Tile Inactive CalibHit container" );
194  ATH_MSG_INFO("**************************************************************" );
195 
198  }
199  else
200  {
201  return;
202  }
203  break;
204 
205 
206  case 3:
207 
208  if((m_TileActiveHitCnt->Size()) != 0 )
209  {
210  ATH_MSG_INFO(" " );
211  ATH_MSG_INFO("************************************************************" );
212  ATH_MSG_INFO("Investigate CalibHit IDs from Tile Active CalibHit container" );
213  ATH_MSG_INFO("************************************************************" );
214 
217 
218  m_Merge=true;
219  }
220  else
221  {
222  return;
223  }
224  break;
225 
226 
227  case 4:
228 
229  if((m_LArDMHitCnt->Size()) != 0 )
230  {
231  ATH_MSG_INFO(" " );
232  ATH_MSG_INFO("*******************************************************" );
233  ATH_MSG_INFO("Investigate CalibHit IDs from LAr DM CalibHit Container" );
234  ATH_MSG_INFO("*******************************************************" );
235 
236  it = m_LArDMHitCnt->begin();
237  end = m_LArDMHitCnt->end();
238  }
239  else
240  {
241  return;
242  }
243  break;
244 
245 
246  case 5:
247 
248  if((m_TileDMHitCnt->Size()) != 0 )
249  {
250  ATH_MSG_INFO(" " );
251  ATH_MSG_INFO("********************************************************" );
252  ATH_MSG_INFO("Investigate CalibHit IDs from Tile DM CalibHit Container" );
253  ATH_MSG_INFO("********************************************************" );
254 
255  it = m_TileDMHitCnt->begin();
256  end = m_TileDMHitCnt->end();
257  }
258  else
259  {
260  return;
261  }
262  break;
263 
264  default:
265  return;
266  }
267 
268 
269  //Now, iterate over the container to find
270  //not valid, 'alien' and repeated IDs
271  for(; it != end; ++it) {
272 
273  Identifier id=(*it)->cellID();
274 
275 
276  //Check ID whether is it valid or not
277  if(!id.is_valid()) {
278 
279  ATH_MSG_ERROR("Invalid Identifier of CalibHit is found! "
280  <<m_id_helper->show_to_string(id) );
281 
282  no_invalid=false;
283  }
284 
285 
286 
287  //Check for 'alien' IDs in the container
288  switch(l_cnt) {
289  case 0:
290  case 1:
291  if( !(m_id_helper->is_lar(id)) ) {
292  ATH_MSG_INFO("Found CalibHit with NO LAr ID "
293  <<m_id_helper->show_to_string(id) );
294  no_alien=false;
295  }
296  break;
297 
298  case 2:
299  case 3:
300  if( !(m_id_helper->is_tile(id)) ) {
301  ATH_MSG_INFO("Found CalibHit with NO Tile ID "
302  <<m_id_helper->show_to_string(id) );
303  no_alien=false;
304  }
305  break;
306 
307  case 4:
308  if( !(m_id_helper->is_lar_dm(id)) &&
309  //It's normal to find Tile DM ID
310  //recorded by Default Calculator
311  !(m_id_helper->is_tile_dm(id)) ) {
312  ATH_MSG_INFO("Found CalibHit with NO LAr DM ID "
313  <<m_id_helper->show_to_string(id) );
314  no_alien=false;
315  }
316  break;
317 
318  case 5:
319  if( !(m_id_helper->is_tile_dm(id)) ) {
320  ATH_MSG_INFO("Found CalibHit with NO Tile DM ID "
321  <<m_id_helper->show_to_string(id) );
322  no_alien=false;
323  }
324  break;
325 
326  }
327 
328 
329  bool no_rep = true;
330 
331  //Fill id_map with IDs, which are repeted more then once in the container
332  for (int iter=0; iter<static_cast<int>(id_vec.size()); iter++) {
333  if(id == id_vec[iter]) {
334 
335  if(id_map.find(id)==id_map.end()) {
336  id_map.insert(std::make_pair(id,2));
337  }
338  else {
339  map_it=id_map.find(id);
340  (map_it->second)++ ;
341  }
342 
343  no_rep = false;
344  break;
345  }
346  }
347 
348  if(no_rep) {
349  id_vec.push_back(id);
350 
351  //store id in the vector for all containers and
352  //don't forget merge Inactive & Active CalibHit IDs
353  if(m_Merge) merge(id);
354  else m_id_vec.push_back(id);
355  }
356  else {
357  //repeated ID should not be stored because
358  //its first pattern was already stored &
359  //should not be merged still the same reason
360  //as above.
361  }
362 
363  }//End of looping over the CalibHits inside the container
364 
365 
366  //reset merge flag anyway.
367  //It is needed 'true' only twice
368  m_Merge=false;
369 
370 
371  //tell if no invalid IDs were eppeared
372  if(no_invalid) {
373 
374  ATH_MSG_INFO("------------------------------------- " );
375  ATH_MSG_INFO("No invalid Identifiers has been found " );
376  ATH_MSG_INFO("------------------------------------- " );
377 
378  }
379 
380 
381  //tell if no 'alien' IDs were eppeared
382  if(no_alien) {
383 
384  ATH_MSG_INFO("------------------------------------------------------" );
385  ATH_MSG_INFO("No container not-respective Identifiers has been found" );
386  ATH_MSG_INFO("------------------------------------------------------" );
387 
388  }
389 
390 
391  //Print the result of looking for repeated IDs
392  if(!id_map.empty()) {
393 
394  ATH_MSG_INFO("----------------------------------------------- " );
395  ATH_MSG_INFO("Found repeated Identifiers | how many times " );
396  ATH_MSG_INFO("----------------------------------------------- " );
397 
398  for (const std::pair<const Identifier, int>& p : id_map) {
400  <<" "<< p.second );
401  }
402 
403  }
404  else {
405  ATH_MSG_INFO("----------------------------------------------- " );
406  ATH_MSG_INFO("No repeated CalibHit Identifiers has been found " );
407  ATH_MSG_INFO("----------------------------------------------- " );
408  }
409 
410 }
411 
412 
413 
414 //This method merges CalibHits from Inactive & Active
415 //containers in case they have the same Identifiers,
416 //what is the normal situation if that happens
417 //only once for the given Identifier
419 
420  bool new_id = false;
421 
422  if(!m_id_vec.empty()) {
423 
424  for (int iter=0; iter != static_cast<int>(m_id_vec.size()); iter++) {
425  if(id == m_id_vec[iter]) {
426  new_id = false;
427  break;
428  }
429  else {
430  new_id = true;
431  }
432  }
433 
434  if(new_id) m_id_vec.push_back(id);
435  }
436  else {
437  //nothing to merge.
438  //push all IDs in the vector
439  m_id_vec.push_back(id) ;
440  }
441 
442 }
443 
444 
445 
446 
447 //This method shows all IDs into the string format
449 
450  ATH_MSG_INFO("=================================================" );
451  ATH_MSG_INFO("Show all CalibHits Identifiers for current events" );
452  ATH_MSG_INFO("=================================================" );
453 
454  for (int iter=0; iter != static_cast<int>(m_id_vec.size()); iter++) {
455 
457 
458  }
459 
460 }
461 
462 
463 
464 
465 //This method is useful to find those IDs, which are
466 //probably not repeated inside the same CalibHits
467 //container but in the different ones.
468 //
469 //If there aren't repeated IDs in the different
470 //CalibHit containers then this method must tell
471 //that it did not find any of them.
472 //
473 //This is claimed because 'm_id_vec' keeps only
474 //one pattern of those IDs, which were repeated
475 //inside the one particular container.
476 //
477 //Otherwise, if this method found a repeated ID
478 //it means that this ID belongs to the CalibHits
479 //contained inside the different containers!
481 
482  ATH_MSG_INFO("======================================================" );
483  ATH_MSG_INFO("Check for the CalibHits Identifiers has been repeated " );
484  ATH_MSG_INFO(" inside the different CalibHit containers " );
485  ATH_MSG_INFO("======================================================" );
486 
487 
488  bool no_rep=true;
489 
490  for (size_t i=0; i < m_id_vec.size(); i++) {
491 
492  ID::iterator it_end = std::remove (m_id_vec.begin()+i+1,
493  m_id_vec.end(),
494  m_id_vec[i]);
495  int same = m_id_vec.end() - it_end;
496  m_id_vec.erase (it_end, m_id_vec.end());
497 
498  if(same!=0) {
499  ATH_MSG_INFO("Identifier "
501  <<" is repeated "<<(same+1)<<" times"
502  <<" inside different containers " );
503 
504  no_rep=false;
505  }
506  } //end looping
507 
508 
509  if(no_rep) {
510  ATH_MSG_INFO("*** No repeated CalibHit Identifier "
511  <<"in the different containers was found ***" );
512  }
513 
514 }
515 
516 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CalibHitIDCheck::execute
StatusCode execute()
Definition: CalibHitIDCheck.cxx:73
CalibHitIDCheck::initialize
StatusCode initialize()
Definition: CalibHitIDCheck.cxx:62
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CalibHitIDCheck::m_CheckAll
bool m_CheckAll
Definition: CalibHitIDCheck.h:65
AtlasDetectorID::is_lar
bool is_lar(Identifier id) const
Definition: AtlasDetectorID.h:689
CalibHitIDCheck::m_id_vec
ID m_id_vec
Definition: CalibHitIDCheck.h:69
CalibHitIDCheck::merge
void merge(Identifier)
Definition: CalibHitIDCheck.cxx:418
CalibHitIDCheck::m_TileInactiveHitCnt
const CaloCalibrationHitContainer * m_TileInactiveHitCnt
Definition: CalibHitIDCheck.h:60
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CalibHitIDCheck.h
CalibHitIDCheck::show_all
void show_all()
Definition: CalibHitIDCheck.cxx:448
CalibHitIDCheck::m_tileInactiveHitContainer
std::string m_tileInactiveHitContainer
Definition: CalibHitIDCheck.h:53
skel.it
it
Definition: skel.GENtoEVGEN.py:396
python.TrigEgammaFastCaloHypoTool.same
def same(val, tool)
Definition: TrigEgammaFastCaloHypoTool.py:12
CaloCalibrationHitContainer.h
CalibHitIDCheck::m_InactiveHitCnt
const CaloCalibrationHitContainer * m_InactiveHitCnt
Definition: CalibHitIDCheck.h:58
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CalibHitIDCheck::CalibHitIDCheck
CalibHitIDCheck(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CalibHitIDCheck.cxx:33
AthenaHitsVector< CaloCalibrationHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
CalibHitIDCheck::check_all_cnts
void check_all_cnts()
Definition: CalibHitIDCheck.cxx:480
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AtlasDetectorID::is_tile_dm
bool is_tile_dm(Identifier id) const
Definition: AtlasDetectorID.h:748
CalibHitIDCheck::m_ShowAll
bool m_ShowAll
Definition: CalibHitIDCheck.h:64
CalibHitIDCheck::finalize
StatusCode finalize()
Definition: CalibHitIDCheck.cxx:118
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CalibHitIDCheck::m_ActiveHitCnt
const CaloCalibrationHitContainer * m_ActiveHitCnt
Definition: CalibHitIDCheck.h:57
AtlasDetectorID::is_tile
bool is_tile(Identifier id) const
Definition: AtlasDetectorID.h:695
CalibHitIDCheck::m_LArDMHitCnt
const CaloCalibrationHitContainer * m_LArDMHitCnt
Definition: CalibHitIDCheck.h:56
CalibHitIDCheck::m_tileActiveHitContainer
std::string m_tileActiveHitContainer
Definition: CalibHitIDCheck.h:52
CalibHitIDCheck::m_tiledmHitContainer
std::string m_tiledmHitContainer
Definition: CalibHitIDCheck.h:54
AthAlgorithm
Definition: AthAlgorithm.h:47
CalibHitIDCheck::check
void check(int)
Definition: CalibHitIDCheck.cxx:135
CalibHitIDCheck::~CalibHitIDCheck
virtual ~CalibHitIDCheck()
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CalibHitIDCheck::reset
void reset()
Definition: CalibHitIDCheck.h:43
AtlasDetectorID::is_lar_dm
bool is_lar_dm(Identifier id) const
LAr/Tile dead material:
Definition: AtlasDetectorID.h:736
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
AthenaHitsVector::Size
int Size() const
Definition: AthenaHitsVector.h:96
CalibHitIDCheck::m_Merge
bool m_Merge
Definition: CalibHitIDCheck.h:45
CalibHitIDCheck::m_TileDMHitCnt
const CaloCalibrationHitContainer * m_TileDMHitCnt
Definition: CalibHitIDCheck.h:61
CalibHitIDCheck::m_Check
bool m_Check
Definition: CalibHitIDCheck.h:63
CalibHitIDCheck::m_id_helper
const AtlasDetectorID * m_id_helper
Definition: CalibHitIDCheck.h:67
CalibHitIDCheck::m_larActiveHitContainer
std::string m_larActiveHitContainer
Definition: CalibHitIDCheck.h:50
CalibHitIDCheck::m_TileActiveHitCnt
const CaloCalibrationHitContainer * m_TileActiveHitCnt
Definition: CalibHitIDCheck.h:59
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
CalibHitIDCheck::m_larDMHitContainer
std::string m_larDMHitContainer
Definition: CalibHitIDCheck.h:49
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139
CalibHitIDCheck::m_larInactiveHitContainer
std::string m_larInactiveHitContainer
Definition: CalibHitIDCheck.h:51
Identifier
Definition: IdentifierFieldParser.cxx:14