7 const int padding_w_st1 = 15;
8 const int padding_w_st3 = 7;
9 const int padding_extra_w_st1 = padding_w_st1 - padding_w_st3;
17 const std::vector<std::string>& pattDefinitions,
18 const std::vector<std::string>& symPattDefinitions,
21 bool useSecondEarliest) {
46 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
49 std::vector<std::string>::const_iterator tokens_it = tokens.begin();
53 int straightness = std::stoi(*tokens_it++);
54 int st1_max = std::stoi(*tokens_it++);
55 int st1_min = std::stoi(*tokens_it++);
56 int st2_max = std::stoi(*tokens_it++);
57 int st2_min = std::stoi(*tokens_it++);
58 int st3_max = std::stoi(*tokens_it++);
59 int st3_min = std::stoi(*tokens_it++);
60 int st4_max = std::stoi(*tokens_it++);
61 int st4_min = std::stoi(*tokens_it++);
65 emtf_assert(st2_max == padding_w_st3 && st2_min == padding_w_st3);
69 st2_max += padding_extra_w_st1;
70 st2_min += padding_extra_w_st1;
71 st3_max += padding_extra_w_st1;
72 st3_min += padding_extra_w_st1;
73 st4_max += padding_extra_w_st1;
74 st4_min += padding_extra_w_st1;
78 pattern.set_straightness(straightness);
81 for (
i = st1_min;
i <= st1_max;
i++)
83 for (
i = st2_min;
i <= st2_max;
i++)
85 for (
i = st3_min;
i <= st3_max;
i++)
87 for (
i = st4_min;
i <= st4_max;
i++)
91 pattern.rotr(padding_extra_w_st1);
99 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
102 std::vector<std::string>::const_iterator tokens_it = tokens.begin();
106 int straightness = std::stoi(*tokens_it++);
107 int st1_max1 = std::stoi(*tokens_it++);
108 int st1_min1 = std::stoi(*tokens_it++);
109 int st1_max2 = std::stoi(*tokens_it++);
110 int st1_min2 = std::stoi(*tokens_it++);
111 int st2_max1 = std::stoi(*tokens_it++);
112 int st2_min1 = std::stoi(*tokens_it++);
113 int st2_max2 = std::stoi(*tokens_it++);
114 int st2_min2 = std::stoi(*tokens_it++);
115 int st3_max1 = std::stoi(*tokens_it++);
116 int st3_min1 = std::stoi(*tokens_it++);
117 int st3_max2 = std::stoi(*tokens_it++);
118 int st3_min2 = std::stoi(*tokens_it++);
119 int st4_max1 = std::stoi(*tokens_it++);
120 int st4_min1 = std::stoi(*tokens_it++);
121 int st4_max2 = std::stoi(*tokens_it++);
122 int st4_min2 = std::stoi(*tokens_it++);
126 emtf_assert(st2_max1 == padding_w_st3 && st2_min1 == padding_w_st3);
127 emtf_assert(st2_max2 == padding_w_st3 && st2_min2 == padding_w_st3);
131 st2_max1 += padding_extra_w_st1;
132 st2_min1 += padding_extra_w_st1;
133 st2_max2 += padding_extra_w_st1;
134 st2_min2 += padding_extra_w_st1;
135 st3_max1 += padding_extra_w_st1;
136 st3_min1 += padding_extra_w_st1;
137 st3_max2 += padding_extra_w_st1;
138 st3_min2 += padding_extra_w_st1;
139 st4_max1 += padding_extra_w_st1;
140 st4_min1 += padding_extra_w_st1;
141 st4_max2 += padding_extra_w_st1;
142 st4_min2 += padding_extra_w_st1;
146 pattern.set_straightness(straightness);
149 for (
i = st1_min1;
i <= st1_max1;
i++)
151 for (
i = st1_min2;
i <= st1_max2;
i++)
153 for (
i = st2_min1;
i <= st2_max1;
i++)
155 for (
i = st2_min2;
i <= st2_max2;
i++)
157 for (
i = st3_min1;
i <= st3_max1;
i++)
159 for (
i = st3_min2;
i <= st3_max2;
i++)
161 for (
i = st4_min1;
i <= st4_max1;
i++)
163 for (
i = st4_min2;
i <= st4_max2;
i++)
167 pattern.rotr(padding_extra_w_st1);
175 std::cout <<
"Pattern straightness: " <<
pattern.get_straightness() <<
" image: " << std::endl;
182 std::map<pattern_ref_t, int>& patt_lifetime_map,
185 int num_conv_hits = 0;
186 for (
const auto& conv_hits : extended_conv_hits)
187 num_conv_hits += conv_hits.size();
188 bool early_exit = (num_conv_hits == 0) && (patt_lifetime_map.empty());
194 for (
const auto& conv_hits : extended_conv_hits) {
195 for (
const auto& conv_hit : conv_hits) {
197 std::cout <<
"CSC hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
198 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp() <<
" strip: " << conv_hit.Strip()
199 <<
" wire: " << conv_hit.Wire() <<
" cpat: " << conv_hit.Pattern()
200 <<
" zone_hit: " << conv_hit.Zone_hit() <<
" zone_code: " << conv_hit.Zone_code()
201 <<
" bx: " << conv_hit.BX() << std::endl;
206 for (
const auto& conv_hits : extended_conv_hits) {
207 for (
const auto& conv_hit : conv_hits) {
209 std::cout <<
"RPC hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
210 <<
" ph>>2: " << (conv_hit.Phi_fp() >> 2) <<
" th>>2: " << (conv_hit.Theta_fp() >> 2)
211 <<
" strip: " << conv_hit.Strip() <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern()
212 <<
" bx: " << conv_hit.BX() << std::endl;
217 for (
const auto& conv_hits : extended_conv_hits) {
218 for (
const auto& conv_hit : conv_hits) {
220 std::cout <<
"GEM hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
221 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp() <<
" strip: " << conv_hit.Strip()
222 <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern() <<
" bx: " << conv_hit.BX()
234 if (
is_zone_empty(izone + 1, extended_conv_hits, patt_lifetime_map))
241 process_single_zone(izone + 1, zone_images.at(izone), patt_lifetime_map, zone_roads.at(izone));
246 std::cout <<
"zone: " << izone << std::endl;
247 std::cout << zone_images.at(izone - 1) << std::endl;
255 for (
const auto& roads : zone_roads) {
256 for (
const auto& road : reversed(roads)) {
257 std::cout <<
"pattern: z: " << road.Zone() - 1 <<
" ph: " << road.Key_zhit()
258 <<
" q: " <<
to_hex(road.Quality_code()) <<
" ly: " << to_binary(road.Layer_code(), 3)
259 <<
" str: " << to_binary(road.Straightness(), 3) <<
" bx: " << road.BX() << std::endl;
271 const std::deque<EMTFHitCollection>& extended_conv_hits,
272 const std::map<pattern_ref_t, int>& patt_lifetime_map)
const {
273 int izone = zone - 1;
274 int num_conv_hits = 0;
277 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
278 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
280 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
281 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
282 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
284 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
294 if (conv_hits_it->Zone_code() & (1 << izone)) {
300 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_it = patt_lifetime_map.begin();
301 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_end = patt_lifetime_map.end();
303 for (; patt_lifetime_map_it != patt_lifetime_map_end; ++patt_lifetime_map_it) {
304 if (patt_lifetime_map_it->first.at(0) == zone) {
309 return (num_conv_hits == 0) && (num_patts == 0);
313 const std::deque<EMTFHitCollection>& extended_conv_hits,
315 int izone = zone - 1;
317 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
318 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
320 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
321 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
322 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
324 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
331 if (conv_hits_it->Zone_code() & (1 << izone)) {
332 unsigned int layer = conv_hits_it->Station() - 1;
333 unsigned int bit = conv_hits_it->Zone_hit();
342 std::map<pattern_ref_t, int>& patt_lifetime_map,
351 cloned_image.
rotl(padding_w_st3);
357 cloned_image.
rotr(1);
359 int max_quality_code = -1;
363 for (
int ipatt = 0; ipatt < npatterns; ++ipatt) {
366 int straightness =
patt.get_straightness();
368 bool is_lifetime_up =
false;
370 int layer_code =
patt.op_and(cloned_image);
371 bool more_than_one = (layer_code != 0) && (layer_code != 1) && (layer_code != 2) && (layer_code != 4);
372 bool more_than_zero = (layer_code != 0);
374 if (more_than_zero) {
376 auto ins = patt_lifetime_map.insert({patt_ref, 0});
380 auto patt_ins =
ins.first;
381 bool patt_exists = !
ins.second;
384 if (patt_ins->second == drift_time) {
385 is_lifetime_up =
true;
388 patt_ins->second += 1;
392 auto patt_ins =
ins.first;
393 int bx_shifter = patt_ins->second;
394 int bx2 =
bool(bx_shifter & (1 << 2));
395 int bx1 =
bool(bx_shifter & (1 << 1));
396 int bx0 =
bool(bx_shifter & (1 << 0));
399 if (drift_time == 2 && bx2 == 0 && bx1 == 1) {
400 is_lifetime_up =
true;
401 }
else if (drift_time == 1 && bx1 == 0 && bx0 == 1) {
402 is_lifetime_up =
true;
403 }
else if (drift_time == 0) {
404 is_lifetime_up =
true;
409 bx0 = more_than_zero;
410 bx_shifter = (bx2 << 2) | (bx1 << 1) | bx0;
411 patt_ins->second = bx_shifter;
416 patt_lifetime_map.erase(patt_ref);
421 if (is_lifetime_up && more_than_one) {
426 ((((straightness >> 2) & 1) << 5) | (((straightness >> 1) & 1) << 3) | (((straightness >> 0) & 1) << 1) |
427 (((layer_code >> 2) & 1) << 4) | (((layer_code >> 1) & 1) << 2) | (((layer_code >> 0) & 1) << 0));
445 if (max_quality_code < quality_code) {
446 max_quality_code = quality_code;
454 if (max_quality_code != -1) {
455 roads.push_back(tmp_road);
462 if (!roads.empty()) {
463 std::array<int, emtf::NUM_ZONE_HITS> quality_codes;
464 quality_codes.fill(0);
466 EMTFRoadCollection::iterator roads_it = roads.begin();
467 EMTFRoadCollection::iterator roads_end = roads.end();
469 for (; roads_it != roads_end; ++roads_it) {
470 quality_codes.at(roads_it->Key_zhit()) = roads_it->
Quality_code();
473 roads_it = roads.begin();
474 roads_end = roads.end();
476 for (; roads_it != roads_end; ++roads_it) {
477 int izhit = roads_it->Key_zhit();
480 int qc = quality_codes.at(izhit);
485 int qr = (izhit == 0) ? 0 : quality_codes.at(izhit - 1);
488 if (qc <= ql || qc < qr) {
489 roads_it->set_quality_code(0);
498 bool operator()(
const value_type&
x)
const {
return (
x.Quality_code() == 0); }
499 } quality_code_zero_pred;
501 roads.erase(std::remove_if(roads.begin(), roads.end(), quality_code_zero_pred), roads.end());
508 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.Key_zhit() > rhs.Key_zhit(); }
511 std::sort(roads.begin(), roads.end(), greater_zhit_cmp);
517 return lhs.Quality_code() > rhs.Quality_code();
519 } greater_quality_cmp;
521 std::stable_sort(roads.begin(), roads.end(), greater_quality_cmp);
525 if (roads.size() >
n) {
526 roads.erase(roads.begin() +
n, roads.end());
531 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
532 roads.at(iroad).set_winner(iroad);
static char to_hex(unsigned int i)
constexpr int NUM_ZONE_HITS
void set_bit(unsigned int layer, unsigned int bit)
std::vector< PhiMemoryImage > patterns_
void set_pattern(int bits)
void sort_single_zone(EMTFRoadCollection &roads) const
void set_quality_code(int bits)
std::vector< std::string > pattDefinitions_
void process_single_zone(int zone, PhiMemoryImage cloned_image, std::map< pattern_ref_t, int > &patt_lifetime_map, EMTFRoadCollection &roads) const
void set_key_zhit(int bits)
void set_sector(int bits)
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
Container::value_type value_type
void set_straightness(int bits)
l1t::EMTFRoadCollection EMTFRoadCollection
std::vector< std::string > symPattDefinitions_
std::array< T, NUM_ZONES > zone_array
void rotr(unsigned int n)
void rotl(unsigned int n)
void set_endcap(int bits)
void configure(int verbose, int endcap, int sector, int bx, int bxWindow, const std::vector< std::string > &pattDefinitions, const std::vector< std::string > &symPattDefinitions, bool useSymPatterns, int maxRoadsPerZone, bool useSecondEarliest)
void process(const std::deque< EMTFHitCollection > &extended_conv_hits, std::map< pattern_ref_t, int > &patt_lifetime_map, emtf::zone_array< EMTFRoadCollection > &zone_roads) const
void make_zone_image(int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, PhiMemoryImage &image) const
bool is_zone_empty(int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, const std::map< pattern_ref_t, int > &patt_lifetime_map) const
void set_layer_code(int bits)
void set_sector_idx(int bits)
std::array< int, 3 > pattern_ref_t