ATLAS Offline Software
Loading...
Searching...
No Matches
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
13namespace 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 {
34 resize( m_detectorElements->size() );
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 };
52
58 static std::pair< typename std::vector<KEY_TYPE>::iterator,
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 }
152
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
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
Special greater operator which ignores the column group flag in the comparison.
bool operator()(KEY_TYPE key_a, KEY_TYPE key_b)
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.
void setModuleDefect(unsigned int id_hash)
Mark the specified module as defect.
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.
EmulatedDefects(const InDetDD::SiDetectorElementCollection &detector_elements)
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.
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).
const InDetDD::SiDetectorElementCollection & getDetectorElementCollection() const
Return the detector element collection.
static constexpr unsigned int MASK_FOR_COMPARISON
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.
static constexpr bool s_needMasking
std::vector< bool > m_moduleIsDefect
const InDetDD::SiDetectorElementCollection * m_detectorElements
typename T_ModuleHelper::KEY_TYPE KEY_TYPE
const InDetDD::SiDetectorElement & getDetectorElement(unsigned int id_hash) const
Return the detector element for the given ID hash.
bool isModuleDefect(unsigned int id_hash) const
Return true if the module defined by the given ID hash is defect.
void resize(std::size_t n_modules)
Resize data structures for this number of modules.
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.
Primary Vertex Finder.