6 const int padding_w_st1 = 15;
7 const int padding_w_st3 = 7;
8 const int padding_extra_w_st1 = padding_w_st1 - padding_w_st3;
16 const std::vector<std::string>& pattDefinitions,
17 const std::vector<std::string>& symPattDefinitions,
20 bool useSecondEarliest) {
45 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
48 std::vector<std::string>::const_iterator tokens_it = tokens.begin();
52 int straightness = std::stoi(*tokens_it++);
53 int st1_max = std::stoi(*tokens_it++);
54 int st1_min = std::stoi(*tokens_it++);
55 int st2_max = std::stoi(*tokens_it++);
56 int st2_min = std::stoi(*tokens_it++);
57 int st3_max = std::stoi(*tokens_it++);
58 int st3_min = std::stoi(*tokens_it++);
59 int st4_max = std::stoi(*tokens_it++);
60 int st4_min = std::stoi(*tokens_it++);
64 emtf_assert(st2_max == padding_w_st3 && st2_min == padding_w_st3);
68 st2_max += padding_extra_w_st1;
69 st2_min += padding_extra_w_st1;
70 st3_max += padding_extra_w_st1;
71 st3_min += padding_extra_w_st1;
72 st4_max += padding_extra_w_st1;
73 st4_min += padding_extra_w_st1;
77 pattern.set_straightness(straightness);
80 for (
i = st1_min;
i <= st1_max;
i++)
82 for (
i = st2_min;
i <= st2_max;
i++)
84 for (
i = st3_min;
i <= st3_max;
i++)
86 for (
i = st4_min;
i <= st4_max;
i++)
90 pattern.rotr(padding_extra_w_st1);
98 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
101 std::vector<std::string>::const_iterator tokens_it = tokens.begin();
105 int straightness = std::stoi(*tokens_it++);
106 int st1_max1 = std::stoi(*tokens_it++);
107 int st1_min1 = std::stoi(*tokens_it++);
108 int st1_max2 = std::stoi(*tokens_it++);
109 int st1_min2 = std::stoi(*tokens_it++);
110 int st2_max1 = std::stoi(*tokens_it++);
111 int st2_min1 = std::stoi(*tokens_it++);
112 int st2_max2 = std::stoi(*tokens_it++);
113 int st2_min2 = std::stoi(*tokens_it++);
114 int st3_max1 = std::stoi(*tokens_it++);
115 int st3_min1 = std::stoi(*tokens_it++);
116 int st3_max2 = std::stoi(*tokens_it++);
117 int st3_min2 = std::stoi(*tokens_it++);
118 int st4_max1 = std::stoi(*tokens_it++);
119 int st4_min1 = std::stoi(*tokens_it++);
120 int st4_max2 = std::stoi(*tokens_it++);
121 int st4_min2 = std::stoi(*tokens_it++);
125 emtf_assert(st2_max1 == padding_w_st3 && st2_min1 == padding_w_st3);
126 emtf_assert(st2_max2 == padding_w_st3 && st2_min2 == padding_w_st3);
130 st2_max1 += padding_extra_w_st1;
131 st2_min1 += padding_extra_w_st1;
132 st2_max2 += padding_extra_w_st1;
133 st2_min2 += padding_extra_w_st1;
134 st3_max1 += padding_extra_w_st1;
135 st3_min1 += padding_extra_w_st1;
136 st3_max2 += padding_extra_w_st1;
137 st3_min2 += padding_extra_w_st1;
138 st4_max1 += padding_extra_w_st1;
139 st4_min1 += padding_extra_w_st1;
140 st4_max2 += padding_extra_w_st1;
141 st4_min2 += padding_extra_w_st1;
145 pattern.set_straightness(straightness);
148 for (
i = st1_min1;
i <= st1_max1;
i++)
150 for (
i = st1_min2;
i <= st1_max2;
i++)
152 for (
i = st2_min1;
i <= st2_max1;
i++)
154 for (
i = st2_min2;
i <= st2_max2;
i++)
156 for (
i = st3_min1;
i <= st3_max1;
i++)
158 for (
i = st3_min2;
i <= st3_max2;
i++)
160 for (
i = st4_min1;
i <= st4_max1;
i++)
162 for (
i = st4_min2;
i <= st4_max2;
i++)
166 pattern.rotr(padding_extra_w_st1);
174 std::cout <<
"Pattern straightness: " <<
pattern.get_straightness() <<
" image: " << std::endl;
181 std::map<pattern_ref_t, int>& patt_lifetime_map,
184 int num_conv_hits = 0;
185 for (
const auto& conv_hits : extended_conv_hits)
186 num_conv_hits += conv_hits.size();
187 bool early_exit = (num_conv_hits == 0) && (patt_lifetime_map.empty());
193 for (
const auto& conv_hits : extended_conv_hits) {
194 for (
const auto& conv_hit : conv_hits) {
196 std::cout <<
"CSC hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
197 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp() <<
" strip: " << conv_hit.Strip()
198 <<
" wire: " << conv_hit.Wire() <<
" cpat: " << conv_hit.Pattern()
199 <<
" zone_hit: " << conv_hit.Zone_hit() <<
" zone_code: " << conv_hit.Zone_code()
200 <<
" bx: " << conv_hit.BX() << std::endl;
205 for (
const auto& conv_hits : extended_conv_hits) {
206 for (
const auto& conv_hit : conv_hits) {
208 std::cout <<
"RPC hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
209 <<
" ph>>2: " << (conv_hit.Phi_fp() >> 2) <<
" th>>2: " << (conv_hit.Theta_fp() >> 2)
210 <<
" strip: " << conv_hit.Strip() <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern()
211 <<
" bx: " << conv_hit.BX() << std::endl;
216 for (
const auto& conv_hits : extended_conv_hits) {
217 for (
const auto& conv_hit : conv_hits) {
219 std::cout <<
"GEM hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
220 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp() <<
" strip: " << conv_hit.Strip()
221 <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern() <<
" bx: " << conv_hit.BX()
233 if (
is_zone_empty(izone + 1, extended_conv_hits, patt_lifetime_map))
240 process_single_zone(izone + 1, zone_images.at(izone), patt_lifetime_map, zone_roads.at(izone));
245 std::cout <<
"zone: " << izone << std::endl;
246 std::cout << zone_images.at(izone - 1) << std::endl;
254 for (
const auto& roads : zone_roads) {
255 for (
const auto& road : reversed(roads)) {
256 std::cout <<
"pattern: z: " << road.Zone() - 1 <<
" ph: " << road.Key_zhit()
257 <<
" q: " <<
to_hex(road.Quality_code()) <<
" ly: " << to_binary(road.Layer_code(), 3)
258 <<
" str: " << to_binary(road.Straightness(), 3) <<
" bx: " << road.BX() << std::endl;
270 const std::deque<EMTFHitCollection>& extended_conv_hits,
271 const std::map<pattern_ref_t, int>& patt_lifetime_map)
const {
272 int izone = zone - 1;
273 int num_conv_hits = 0;
276 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
277 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
279 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
280 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
281 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
283 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
293 if (conv_hits_it->Zone_code() & (1 << izone)) {
299 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_it = patt_lifetime_map.begin();
300 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_end = patt_lifetime_map.end();
302 for (; patt_lifetime_map_it != patt_lifetime_map_end; ++patt_lifetime_map_it) {
303 if (patt_lifetime_map_it->first.at(0) == zone) {
308 return (num_conv_hits == 0) && (num_patts == 0);
312 const std::deque<EMTFHitCollection>& extended_conv_hits,
314 int izone = zone - 1;
316 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
317 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
319 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
320 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
321 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
323 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
330 if (conv_hits_it->Zone_code() & (1 << izone)) {
331 unsigned int layer = conv_hits_it->Station() - 1;
332 unsigned int bit = conv_hits_it->Zone_hit();
341 std::map<pattern_ref_t, int>& patt_lifetime_map,
350 cloned_image.
rotl(padding_w_st3);
356 cloned_image.
rotr(1);
358 int max_quality_code = -1;
362 for (
int ipatt = 0; ipatt < npatterns; ++ipatt) {
365 int straightness =
patt.get_straightness();
367 bool is_lifetime_up =
false;
369 int layer_code =
patt.op_and(cloned_image);
370 bool more_than_one = (layer_code != 0) && (layer_code != 1) && (layer_code != 2) && (layer_code != 4);
371 bool more_than_zero = (layer_code != 0);
373 if (more_than_zero) {
375 auto ins = patt_lifetime_map.insert({patt_ref, 0});
379 auto patt_ins =
ins.first;
380 bool patt_exists = !
ins.second;
383 if (patt_ins->second == drift_time) {
384 is_lifetime_up =
true;
387 patt_ins->second += 1;
391 auto patt_ins =
ins.first;
392 int bx_shifter = patt_ins->second;
393 int bx2 =
bool(bx_shifter & (1 << 2));
394 int bx1 =
bool(bx_shifter & (1 << 1));
395 int bx0 =
bool(bx_shifter & (1 << 0));
398 if (drift_time == 2 && bx2 == 0 && bx1 == 1) {
399 is_lifetime_up =
true;
400 }
else if (drift_time == 1 && bx1 == 0 && bx0 == 1) {
401 is_lifetime_up =
true;
402 }
else if (drift_time == 0) {
403 is_lifetime_up =
true;
408 bx0 = more_than_zero;
409 bx_shifter = (bx2 << 2) | (bx1 << 1) | bx0;
410 patt_ins->second = bx_shifter;
415 patt_lifetime_map.erase(patt_ref);
420 if (is_lifetime_up && more_than_one) {
425 ((((straightness >> 2) & 1) << 5) | (((straightness >> 1) & 1) << 3) | (((straightness >> 0) & 1) << 1) |
426 (((layer_code >> 2) & 1) << 4) | (((layer_code >> 1) & 1) << 2) | (((layer_code >> 0) & 1) << 0));
444 if (max_quality_code < quality_code) {
445 max_quality_code = quality_code;
453 if (max_quality_code != -1) {
454 roads.push_back(tmp_road);
461 if (!roads.empty()) {
462 std::array<int, emtf::NUM_ZONE_HITS> quality_codes;
463 quality_codes.fill(0);
465 EMTFRoadCollection::iterator roads_it = roads.begin();
466 EMTFRoadCollection::iterator roads_end = roads.end();
468 for (; roads_it != roads_end; ++roads_it) {
469 quality_codes.at(roads_it->Key_zhit()) = roads_it->Quality_code();
472 roads_it = roads.begin();
473 roads_end = roads.end();
475 for (; roads_it != roads_end; ++roads_it) {
476 int izhit = roads_it->Key_zhit();
479 int qc = quality_codes.at(izhit);
484 int qr = (izhit == 0) ? 0 : quality_codes.at(izhit - 1);
487 if (qc <= ql || qc < qr) {
488 roads_it->set_quality_code(0);
497 bool operator()(
const value_type&
x)
const {
return (
x.Quality_code() == 0); }
498 } quality_code_zero_pred;
500 roads.erase(std::remove_if(roads.begin(), roads.end(), quality_code_zero_pred), roads.end());
507 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.Key_zhit() > rhs.Key_zhit(); }
510 std::sort(roads.begin(), roads.end(), greater_zhit_cmp);
516 return lhs.Quality_code() > rhs.Quality_code();
518 } greater_quality_cmp;
520 std::stable_sort(roads.begin(), roads.end(), greater_quality_cmp);
524 if (roads.size() >
n) {
525 roads.erase(roads.begin() +
n, roads.end());
530 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
531 roads.at(iroad).set_winner(iroad);