Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 unsigned int MASK_FOR_COMPARISON = T_ModuleHelper::CHIP_MASK | T_ModuleHelper::ROW_MASK | T_ModuleHelper::COL_MASK;
28  static constexpr bool s_needMasking = T_ModuleHelper::N_MASKS>0;
29  using KEY_TYPE = typename T_ModuleHelper::KEY_TYPE;
30 
32  : m_detectorElements(&detector_elements)
33  {
34  resize( m_detectorElements->size() );
35  }
36 
37 
40  class greater {
41  public:
42  /*static (c++23) */ bool operator()(KEY_TYPE key_a, KEY_TYPE key_b) {
43  if constexpr(s_needMasking) {
44  return (key_a & MASK_FOR_COMPARISON)
45  > (key_b & MASK_FOR_COMPARISON);
46  }
47  else {
48  return key_a
49  > key_b;
50  }
51  }
52  };
60  typename std::vector<KEY_TYPE>::iterator> lower_bound(std::vector<KEY_TYPE> &module_defects,
61  KEY_TYPE key) {
62  return std::make_pair( std::lower_bound( module_defects.begin(),module_defects.end(), key, greater()),
63  module_defects.end());
64  }
65 
73  std::pair< typename std::vector<KEY_TYPE>::const_iterator,
74  typename std::vector<KEY_TYPE>::const_iterator> lower_bound(unsigned int id_hash, KEY_TYPE key) const {
75  const std::vector<KEY_TYPE> &module_defects = this->at(id_hash);
76  return std::make_pair( std::lower_bound( module_defects.begin(),module_defects.end(), key, greater()),
77  module_defects.end());
78  }
79 
87  bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, KEY_TYPE key) const {
88  auto [defect_iter, end_iter] =lower_bound(id_hash, key);
89  return (defect_iter != end_iter && helper.isMatchingDefect( *defect_iter, key) );
90  }
91 
100  bool isDefect(const T_ModuleHelper &helper, unsigned int id_hash, unsigned int row_idx_aka_phi, unsigned int col_idx_aka_eta) const {
101  return isDefect(helper, id_hash, helper.hardwareCoordinates(row_idx_aka_phi, col_idx_aka_eta) );
102  }
103 
107  bool isModuleDefect(unsigned int id_hash) const {
108  return m_moduleIsDefect.at(id_hash);
109  }
110 
113  void setModuleDefect(unsigned int id_hash) {
114  m_moduleIsDefect.at(id_hash)=true;
115  }
116 
120  const InDetDD::SiDetectorElement &getDetectorElement(unsigned int id_hash) const {
121  return *(m_detectorElements->at(id_hash));
122  }
126  return *m_detectorElements;
127  }
128  protected:
131  void resize( std::size_t n_modules) {
132  std::vector<std::vector< typename T_ModuleHelper::KEY_TYPE> >::resize(n_modules);
133  m_moduleIsDefect.resize(n_modules,false);
134  }
135  std::vector<bool> m_moduleIsDefect;
136  const InDetDD::SiDetectorElementCollection *m_detectorElements; // pointer to the detector element collection these defects are for
137  };
138 }
139 
140 #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:113
InDet::EmulatedDefects::greater
Special greater operator which ignores the column group flag in the comparison.
Definition: EmulatedDefects.h:40
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
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:42
InDet::EmulatedDefects::s_needMasking
static constexpr bool s_needMasking
Definition: EmulatedDefects.h:28
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:112
InDet::EmulatedDefects::resize
void resize(std::size_t n_modules)
Resize data structures for this number of modules.
Definition: EmulatedDefects.h:131
InDet::EmulatedDefects::getDetectorElement
const InDetDD::SiDetectorElement & getDetectorElement(unsigned int id_hash) const
Return the detector element for the given ID hash.
Definition: EmulatedDefects.h:120
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:74
InDet::EmulatedDefects::MASK_FOR_COMPARISON
static constexpr unsigned int MASK_FOR_COMPARISON
Definition: EmulatedDefects.h:27
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:60
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:107
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:100
InDet::EmulatedDefects::getDetectorElementCollection
const InDetDD::SiDetectorElementCollection & getDetectorElementCollection() const
Return the detector element collection.
Definition: EmulatedDefects.h:125
InDet::EmulatedDefects
Data structure do mark e.g.
Definition: EmulatedDefects.h:25
InDet::EmulatedDefects::EmulatedDefects
EmulatedDefects(const InDetDD::SiDetectorElementCollection &detector_elements)
Definition: EmulatedDefects.h:31
InDet::EmulatedDefects::m_detectorElements
const InDetDD::SiDetectorElementCollection * m_detectorElements
Definition: EmulatedDefects.h:136
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:87
InDet::EmulatedDefects::m_moduleIsDefect
std::vector< bool > m_moduleIsDefect
Definition: EmulatedDefects.h:135
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37