ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace InDet {
10
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>
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
66
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) {
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
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
int getZeroOrSide(const T_ID &id_helper, const Identifier &id)
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.
std::array< int, ModuleIdentifierMatchUtil::kAllRows/2 > ModuleData_t
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.
bool matchesBothSides(const std::vector< int > &a_module_pattern)
Test whether the given pattern matches identifiers which refer to either side of a sensor.
EModulePatternPart
The identifier parts used for identifier matching kAllRows denotes the element which contains a flag ...
bool verifyModulePatternList(const std::vector< std::vector< int > > &arr)
Verify whether a list of module identifier patterns is consistent.
int getColumnsOrCells(const T_ModuleDesign &moduleDesign)
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.
void setModuleData(EModulePatternPart part, int value, std::array< int, kAllRows/2 > &dest)
Convenience function to set the specified element in the given array.
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.
bool isSideMatching(const std::vector< int > &a_module_pattern, int side)
Test whether the given pattern matches the given side.
Primary Vertex Finder.