ATLAS Offline Software
EmulatedDefects.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef INDET_EMULATEDDEFECTS_H
5 #define INDET_EMULATEDDEFECTS_H
6 
7 #include <vector>
8 #include <algorithm>
9 #include <utility>
10 
12 
13 namespace InDet {
23  template <class T_ModuleHelper>
24  class EmulatedDefects : public std::vector<std::vector< typename T_ModuleHelper::KEY_TYPE> >
25  {
26  public:
27  static constexpr bool s_needMasking = T_ModuleHelper::RANGE_FLAG_MASK != 0;
28  static constexpr unsigned int MASK_FOR_COMPARISON = T_ModuleHelper::CHIP_MASK | T_ModuleHelper::ROW_MASK | T_ModuleHelper::COL_MASK;
29  using KEY_TYPE = typename T_ModuleHelper::KEY_TYPE;
30 
32  : m_detectorElements(&detector_elements)
33  {
35  }
36 
39  class greater {
40  public:
41  /*static (c++23) */ bool operator()(KEY_TYPE key_a, KEY_TYPE key_b) {
42  if constexpr(s_needMasking) {
43  return (key_a & MASK_FOR_COMPARISON)
44  > (key_b & MASK_FOR_COMPARISON);
45  }
46  else {
47  return key_a
48  > key_b;
49  }
50  }
51  };
59  typename std::vector<KEY_TYPE>::iterator> lower_bound(std::vector<KEY_TYPE> &module_defects,
60  KEY_TYPE key) {
61  return std::make_pair( std::lower_bound( module_defects.begin(),module_defects.end(), key, greater()),
62  module_defects.end());
63  }
64 
71  static std::pair< typename std::vector<KEY_TYPE>::const_iterator,
72  typename std::vector<KEY_TYPE>::const_iterator> lower_bound(const std::vector<KEY_TYPE> &module_defects,
73  KEY_TYPE key) {
74  return std::make_pair( std::lower_bound( module_defects.begin(),module_defects.end(), key, greater()),
75  module_defects.end());
76  }
77 
85  std::pair< typename std::vector<KEY_TYPE>::const_iterator,
86  typename std::vector<KEY_TYPE>::const_iterator> lower_bound(unsigned int id_hash, KEY_TYPE key) const {
87  const std::vector<KEY_TYPE> &module_defects = this->at(id_hash);
88  return std::make_pair( std::lower_bound( module_defects.begin(),module_defects.end(), key, greater()),
89  module_defects.end());
90  }
91 
98  static std::pair<KEY_TYPE,KEY_TYPE> getRange(typename std::vector<KEY_TYPE>::const_iterator key_iter) {
99  if (T_ModuleHelper::isRangeKey(*key_iter)) {
100  auto prev = key_iter;
101  --prev;
102  return std::make_pair(*key_iter,*prev);
103  }
104  else {
105  return std::make_pair(*key_iter,*key_iter);
106  }
107  }
108 
116  bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, KEY_TYPE key) const {
117  auto [defect_iter, end_iter] =lower_bound(id_hash, key);
118  return (defect_iter != end_iter) && helper.isMatchingDefect(*defect_iter,key);
119  }
120 
129  bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, unsigned int row_idx_aka_phi, unsigned int col_idx_aka_eta) const {
130  return isDefect(helper, id_hash, helper.hardwareCoordinates(row_idx_aka_phi, col_idx_aka_eta) );
131  }
132 
136  bool isModuleDefect(unsigned int id_hash) const {
137  return m_moduleIsDefect.at(id_hash);
138  }
139 
142  void setModuleDefect(unsigned int id_hash) {
143  m_moduleIsDefect.at(id_hash)=true;
144  }
145 
149  const InDetDD::SiDetectorElement &getDetectorElement(unsigned int id_hash) const {
150  return *(m_detectorElements->at(id_hash));
151  }
155  return *m_detectorElements;
156  }
157  protected:
160  void resize( std::size_t n_modules) {
161  std::vector<std::vector< typename T_ModuleHelper::KEY_TYPE> >::resize(n_modules);
162  m_moduleIsDefect.resize(n_modules,false);
163  }
164  std::vector<bool> m_moduleIsDefect;
165  const InDetDD::SiDetectorElementCollection *m_detectorElements; // pointer to the detector element collection these defects are for
166  };
167 }
168 
169 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
InDet::EmulatedDefects::setModuleDefect
void setModuleDefect(unsigned int id_hash)
Mark the specified module as defect.
Definition: EmulatedDefects.h:142
InDet::EmulatedDefects::greater
Special greater operator which ignores the column group flag in the comparison.
Definition: EmulatedDefects.h:39
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:27
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::EmulatedDefects::greater::operator()
bool operator()(KEY_TYPE key_a, KEY_TYPE key_b)
Definition: EmulatedDefects.h:41
InDet::EmulatedDefects::s_needMasking
static constexpr bool s_needMasking
Definition: EmulatedDefects.h:27
CxxUtils::fpcompare::greater
bool greater(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:140
InDet::EmulatedDefects< StripModuleHelper >::KEY_TYPE
typename T_ModuleHelper::KEY_TYPE KEY_TYPE
Definition: EmulatedDefects.h:29
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:115
InDet::EmulatedDefects::resize
void resize(std::size_t n_modules)
Resize data structures for this number of modules.
Definition: EmulatedDefects.h:160
InDet::EmulatedDefects::getDetectorElement
const InDetDD::SiDetectorElement & getDetectorElement(unsigned int id_hash) const
Return the detector element for the given ID hash.
Definition: EmulatedDefects.h:149
InDet::EmulatedDefects::lower_bound
std::pair< typename std::vector< KEY_TYPE >::const_iterator, typename std::vector< KEY_TYPE >::const_iterator > lower_bound(unsigned int id_hash, KEY_TYPE key) const
Convenience method to find the preceding defect.
Definition: EmulatedDefects.h:86
InDet::EmulatedDefects::MASK_FOR_COMPARISON
static constexpr unsigned int MASK_FOR_COMPARISON
Definition: EmulatedDefects.h:28
InDet::EmulatedDefects::lower_bound
static std::pair< typename std::vector< KEY_TYPE >::iterator, typename std::vector< KEY_TYPE >::iterator > lower_bound(std::vector< KEY_TYPE > &module_defects, KEY_TYPE key)
Convenience method to find the preceding defect.
Definition: EmulatedDefects.h:59
InDet::EmulatedDefects::isModuleDefect
bool isModuleDefect(unsigned int id_hash) const
Return true if the module defined by the given ID hash is defect.
Definition: EmulatedDefects.h:136
InDet::EmulatedDefects::isDefect
bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, unsigned int row_idx_aka_phi, unsigned int col_idx_aka_eta) const
Test whether a pixel on a certain module is marked as defect.
Definition: EmulatedDefects.h:129
InDet::EmulatedDefects::getDetectorElementCollection
const InDetDD::SiDetectorElementCollection & getDetectorElementCollection() const
Return the detector element collection.
Definition: EmulatedDefects.h:154
InDet::EmulatedDefects
Data structure do mark e.g.
Definition: EmulatedDefects.h:25
InDet::EmulatedDefects::lower_bound
static std::pair< typename std::vector< KEY_TYPE >::const_iterator, typename std::vector< KEY_TYPE >::const_iterator > lower_bound(const std::vector< KEY_TYPE > &module_defects, KEY_TYPE key)
Convenience method to find the preceding defect (read only).
Definition: EmulatedDefects.h:72
InDet::EmulatedDefects::EmulatedDefects
EmulatedDefects(const InDetDD::SiDetectorElementCollection &detector_elements)
Definition: EmulatedDefects.h:31
InDet::EmulatedDefects::getRange
static std::pair< KEY_TYPE, KEY_TYPE > getRange(typename std::vector< KEY_TYPE >::const_iterator key_iter)
Convenience method to get a range of keys.
Definition: EmulatedDefects.h:98
InDet::EmulatedDefects::m_detectorElements
const InDetDD::SiDetectorElementCollection * m_detectorElements
Definition: EmulatedDefects.h:165
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SiDetectorElementCollection.h
InDet::EmulatedDefects::isDefect
bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, KEY_TYPE key) const
Test whether a pixel or strip on a certain module is marked as defect.
Definition: EmulatedDefects.h:116
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDet::EmulatedDefects::m_moduleIsDefect
std::vector< bool > m_moduleIsDefect
Definition: EmulatedDefects.h:164
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37