ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetValidation
InDetDefectsEmulation
src
ModuleIdentifierMatchUtil.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_MODULEIDENTIFIERMATCHUTIL_H
5
#define INDET_MODULEIDENTIFIERMATCHUTIL_H
6
7
#include "Identifier/Identifier.h"
8
9
namespace
InDet
{
10
11
namespace
ModuleIdentifierMatchUtil
{
12
namespace
detail
{
13
template
<
typename
T_ID>
14
concept
IdentifierHelperWithSideConecpt
=
requires
(T_ID id_helper,
Identifier
id) { id_helper.side(
id
); };
15
16
// helper to to return the side part of an identifier if available or zero
17
template
<
class
T_ID>
18
inline
int
getZeroOrSide
(
const
T_ID &id_helper,
const
Identifier
&
id
) {
19
if
constexpr
(
IdentifierHelperWithSideConecpt
<
decltype
(id_helper)>) {
20
return
id_helper.side(
id
);
21
}
22
else
{
23
return
0;
24
}
25
}
26
}
27
28
// helper templates to detect whether a type has the method columns or cells
29
template
<
typename
T_ModuleDesign>
30
concept
HasColumns
=
requires
(T_ModuleDesign design) { design.columns(); };
31
template
<
typename
T_ModuleDesign>
32
concept
HasCells
=
requires
(T_ModuleDesign design) { design.cells(); };
33
34
template
<
typename
T_ModuleDesign>
35
concept
ModuleDesignConcept
=
HasColumns<T_ModuleDesign>
||
HasCells<T_ModuleDesign>
;
36
37
// Get a unique module type identifier which is either based on the number of
38
// columns (for pixel) or number of cells (or strips; for strips)
39
template
<ModuleDesignConcept T_ModuleDesign>
40
int
getColumnsOrCells
(
const
T_ModuleDesign &moduleDesign) {
41
if
constexpr
(
HasColumns<T_ModuleDesign>
) {
42
return
moduleDesign.columns();
43
}
44
else
{
45
return
moduleDesign.cells();
46
}
47
}
48
49
55
enum
EModulePatternPart
{
56
kBarrelEndcapSelectRange
=0,
57
kLayerRange
=2,
58
kEtaRange
=4,
59
kPhiRange
=6,
60
kColumnStripRange
=8,
61
kLength
=10,
62
kSideRange
=12,
63
kAllRows
=14,
64
kNParts
=15
65
};
66
67
using
ModuleData_t
= std::array< int,
ModuleIdentifierMatchUtil::kAllRows
/2 >;
68
80
template
<
bool
test_order,
typename
T>
81
inline
bool
verifyElementCountAndOrder
(
const
std::vector<std::vector<T> > &arr, std::size_t n_expected, [[maybe_unused]] std::size_t test_n=0) {
82
for
(
const
auto
&sub_arr : arr) {
83
if
(sub_arr.size() != n_expected)
return
false
;
84
if
(test_n%2 != 0 || test_n>=n_expected)
return
false
;
85
if
constexpr
(test_order) {
86
for
(
unsigned
int
i=0; i<test_n; i+=2) {
87
if
(sub_arr.at(i)>sub_arr.at(i+1)) {
88
if
(sub_arr.at(i+1)!=-2 || (sub_arr.at(i)!=0 && sub_arr.at(i)!=1)) {
89
return
false
;
90
}
91
}
92
}
93
}
94
}
95
return
true
;
96
}
97
103
inline
bool
verifyModulePatternList
(
const
std::vector<std::vector<int> > &arr) {
104
return
verifyElementCountAndOrder<true,int>
(arr,
kNParts
,
kAllRows
);
105
}
106
110
template
<
typename
T>
111
inline
bool
verifyElementCount
(
const
std::vector<std::vector<T> > &arr, std::size_t n_expected) {
112
return
verifyElementCountAndOrder<false,T>
(arr,n_expected, 0);
113
}
114
120
inline
void
setModuleData
(
EModulePatternPart
part,
int
value, std::array< int, kAllRows/2 > &dest) {
121
assert( part%2==0 &&
static_cast<
unsigned
int
>
(part/2)<dest.size());
122
dest[part/2] = value;
123
}
124
132
template
<
class
T_ID,
class
T_ModuleDesign>
133
inline
void
setModuleData
(
const
T_ID &id_helper,
134
const
Identifier
&identifier,
135
const
T_ModuleDesign &module_design,
136
ModuleData_t
&module_data) {
137
setModuleData
(
kBarrelEndcapSelectRange
, id_helper.barrel_ec(identifier), module_data);
138
setModuleData
(
kLayerRange
, id_helper.layer_disk(identifier), module_data);
139
setModuleData
(
kEtaRange
, id_helper.eta_module(identifier), module_data);
140
setModuleData
(
kPhiRange
, id_helper.phi_module(identifier), module_data);
141
setModuleData
(
kColumnStripRange
,
getColumnsOrCells
(module_design), module_data);
142
setModuleData
(
kLength
,
static_cast<
int
>
(module_design.length()*1e3), module_data);
143
setModuleData
(
kSideRange
,
detail::getZeroOrSide
(id_helper,identifier),module_data);
144
}
145
154
inline
void
moduleMatches
(
const
std::vector<std::vector<int> > &module_pattern,
155
const
ModuleData_t
&module_data,
156
std::vector<unsigned int> &module_pattern_idx) {
157
module_pattern_idx.clear();
158
for
(
unsigned
int
pattern_i=0u; pattern_i<module_pattern.size(); ++pattern_i) {
159
const
std::vector<int> &pattern = module_pattern[pattern_i];
160
unsigned
int
range_i=0;
161
bool
match
=
true
;
162
for
(
int
module_value : module_data) {
163
assert( range_i+1 < pattern.size());
164
if
(module_value<pattern[range_i] || module_value>pattern[range_i+1]) {
165
// test if even/odd filter and continue if it is and that filter passes
166
if
(pattern[range_i+1]>=pattern[range_i] || pattern[range_i+1]!=-2 || (module_value & 1) != (pattern[range_i] & 1)) {
167
match
=
false
;
168
break
;
169
}
170
}
171
range_i+=2;
172
}
173
if
(
match
) {
174
module_pattern_idx.push_back(pattern_i);
175
}
176
}
177
}
178
186
inline
bool
matchesBothSides
(
const
std::vector<int> &a_module_pattern) {
187
assert(
ModuleIdentifierMatchUtil::kSideRange
+1 < a_module_pattern.size() );
188
return
a_module_pattern[
ModuleIdentifierMatchUtil::kSideRange
]
189
!= a_module_pattern[
ModuleIdentifierMatchUtil::kSideRange
+1];
190
}
191
193
inline
bool
isSideMatching
(
const
std::vector<int> &a_module_pattern,
int
side) {
194
assert(
ModuleIdentifierMatchUtil::kSideRange
+1 < a_module_pattern.size() );
195
return
side >= a_module_pattern[
ModuleIdentifierMatchUtil::kSideRange
]
196
&& side <= a_module_pattern[
ModuleIdentifierMatchUtil::kSideRange
+1];
197
}
198
206
inline
bool
matchesAllModuleRowsOfSensor
(
const
std::vector<int> &a_module_pattern) {
207
assert(
ModuleIdentifierMatchUtil::kAllRows
< a_module_pattern.size());
208
return
a_module_pattern[
ModuleIdentifierMatchUtil::kAllRows
] != 0;
209
}
210
}
211
}
212
#endif
InDet::ModuleIdentifierMatchUtil::HasCells
Definition
ModuleIdentifierMatchUtil.h:32
InDet::ModuleIdentifierMatchUtil::HasColumns
Definition
ModuleIdentifierMatchUtil.h:30
InDet::ModuleIdentifierMatchUtil::ModuleDesignConcept
Definition
ModuleIdentifierMatchUtil.h:35
InDet::ModuleIdentifierMatchUtil::detail::IdentifierHelperWithSideConecpt
Definition
ModuleIdentifierMatchUtil.h:14
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition
hcg.cxx:359
Identifier
Definition
IdentifierFieldParser.cxx:14
InDet::ModuleIdentifierMatchUtil::detail::getZeroOrSide
int getZeroOrSide(const T_ID &id_helper, const Identifier &id)
Definition
ModuleIdentifierMatchUtil.h:18
InDet::ModuleIdentifierMatchUtil
Definition
ModuleIdentifierMatchUtil.h:11
InDet::ModuleIdentifierMatchUtil::matchesAllModuleRowsOfSensor
bool matchesAllModuleRowsOfSensor(const std::vector< int > &a_module_pattern)
Test whether a pattern matches all module rows of a sensor or just a single row.
Definition
ModuleIdentifierMatchUtil.h:206
InDet::ModuleIdentifierMatchUtil::ModuleData_t
std::array< int, ModuleIdentifierMatchUtil::kAllRows/2 > ModuleData_t
Definition
ModuleIdentifierMatchUtil.h:67
InDet::ModuleIdentifierMatchUtil::verifyElementCount
bool verifyElementCount(const std::vector< std::vector< T > > &arr, std::size_t n_expected)
test whether the 2D vector arr has the expected number of elements.
Definition
ModuleIdentifierMatchUtil.h:111
InDet::ModuleIdentifierMatchUtil::matchesBothSides
bool matchesBothSides(const std::vector< int > &a_module_pattern)
Test whether the given pattern matches identifiers which refer to either side of a sensor.
Definition
ModuleIdentifierMatchUtil.h:186
InDet::ModuleIdentifierMatchUtil::EModulePatternPart
EModulePatternPart
The identifier parts used for identifier matching kAllRows denotes the element which contains a flag ...
Definition
ModuleIdentifierMatchUtil.h:55
InDet::ModuleIdentifierMatchUtil::kBarrelEndcapSelectRange
@ kBarrelEndcapSelectRange
Definition
ModuleIdentifierMatchUtil.h:56
InDet::ModuleIdentifierMatchUtil::kPhiRange
@ kPhiRange
Definition
ModuleIdentifierMatchUtil.h:59
InDet::ModuleIdentifierMatchUtil::kNParts
@ kNParts
Definition
ModuleIdentifierMatchUtil.h:64
InDet::ModuleIdentifierMatchUtil::kLength
@ kLength
Definition
ModuleIdentifierMatchUtil.h:61
InDet::ModuleIdentifierMatchUtil::kEtaRange
@ kEtaRange
Definition
ModuleIdentifierMatchUtil.h:58
InDet::ModuleIdentifierMatchUtil::kColumnStripRange
@ kColumnStripRange
Definition
ModuleIdentifierMatchUtil.h:60
InDet::ModuleIdentifierMatchUtil::kSideRange
@ kSideRange
Definition
ModuleIdentifierMatchUtil.h:62
InDet::ModuleIdentifierMatchUtil::kLayerRange
@ kLayerRange
Definition
ModuleIdentifierMatchUtil.h:57
InDet::ModuleIdentifierMatchUtil::kAllRows
@ kAllRows
Definition
ModuleIdentifierMatchUtil.h:63
InDet::ModuleIdentifierMatchUtil::verifyModulePatternList
bool verifyModulePatternList(const std::vector< std::vector< int > > &arr)
Verify whether a list of module identifier patterns is consistent.
Definition
ModuleIdentifierMatchUtil.h:103
InDet::ModuleIdentifierMatchUtil::getColumnsOrCells
int getColumnsOrCells(const T_ModuleDesign &moduleDesign)
Definition
ModuleIdentifierMatchUtil.h:40
InDet::ModuleIdentifierMatchUtil::verifyElementCountAndOrder
bool verifyElementCountAndOrder(const std::vector< std::vector< T > > &arr, std::size_t n_expected, std::size_t test_n=0)
Test whether the given 2D vector has the expected number of elements, and correct ordering.
Definition
ModuleIdentifierMatchUtil.h:81
InDet::ModuleIdentifierMatchUtil::setModuleData
void setModuleData(EModulePatternPart part, int value, std::array< int, kAllRows/2 > &dest)
Convenience function to set the specified element in the given array.
Definition
ModuleIdentifierMatchUtil.h:120
InDet::ModuleIdentifierMatchUtil::moduleMatches
void moduleMatches(const std::vector< std::vector< int > > &module_pattern, const ModuleData_t &module_data, std::vector< unsigned int > &module_pattern_idx)
Test whether an identifier, which is split into various parts, matches some of the given patterns.
Definition
ModuleIdentifierMatchUtil.h:154
InDet::ModuleIdentifierMatchUtil::isSideMatching
bool isSideMatching(const std::vector< int > &a_module_pattern, int side)
Test whether the given pattern matches the given side.
Definition
ModuleIdentifierMatchUtil.h:193
InDet
Primary Vertex Finder.
Definition
VP1ErrorUtils.h:36
detail
Definition
extract_histogram_tag.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0