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;
15 const std::vector<std::string>& pattDefinitions,
const std::vector<std::string>& symPattDefinitions,
bool useSymPatterns,
16 int maxRoadsPerZone,
bool useSecondEarliest
40 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
41 if (not(tokens.size() == 9))
42 {
edm::LogError(
"L1T") <<
"tokens.size() = " << tokens.size();
return; }
44 std::vector<std::string>::const_iterator tokens_it = tokens.begin();
48 int straightness = std::stoi(*tokens_it++);
49 int st1_max = std::stoi(*tokens_it++);
50 int st1_min = std::stoi(*tokens_it++);
51 int st2_max = std::stoi(*tokens_it++);
52 int st2_min = std::stoi(*tokens_it++);
53 int st3_max = std::stoi(*tokens_it++);
54 int st3_min = std::stoi(*tokens_it++);
55 int st4_max = std::stoi(*tokens_it++);
56 int st4_min = std::stoi(*tokens_it++);
60 if (not(st2_max == padding_w_st3 && st2_min == padding_w_st3))
61 {
edm::LogError(
"L1T") <<
"st2_max = " << st2_max <<
", padding_w_st3 = " << padding_w_st3
62 <<
", st2_min = " << st2_min <<
", padding_w_st3 = " << padding_w_st3;
return; }
66 st2_max += padding_extra_w_st1;
67 st2_min += padding_extra_w_st1;
68 st3_max += padding_extra_w_st1;
69 st3_min += padding_extra_w_st1;
70 st4_max += padding_extra_w_st1;
71 st4_min += padding_extra_w_st1;
78 for (i = st1_min; i <= st1_max; i++)
80 for (i = st2_min; i <= st2_max; i++)
82 for (i = st3_min; i <= st3_max; i++)
84 for (i = st4_min; i <= st4_max; i++)
88 pattern.
rotr(padding_extra_w_st1);
91 if (not(
patterns_.size() == pattDefinitions_.size()))
93 <<
", pattDefinitions_.size() = " << pattDefinitions_.size();
return; }
98 const std::vector<std::string>& tokens = split_string(
s,
',',
':');
99 if (not(tokens.size() == 17))
100 {
edm::LogError(
"L1T") <<
"tokens.size() = " << tokens.size();
return; }
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 if (not(st2_max1 == padding_w_st3 && st2_min1 == padding_w_st3))
127 {
edm::LogError(
"L1T") <<
"st2_max1 = " << st2_max1 <<
", padding_w_st3 = " << padding_w_st3
128 <<
", st2_min1 = " << st2_min1 <<
", padding_w_st3 = " << padding_w_st3;
return; }
129 if (not(st2_max2 == padding_w_st3 && st2_min2 == padding_w_st3))
130 {
edm::LogError(
"L1T") <<
"st2_max2 = " << st2_max2 <<
", padding_w_st3 = " << padding_w_st3
131 <<
", st2_min2 = " << st2_min2 <<
", padding_w_st3 = " << padding_w_st3;
return; }
135 st2_max1 += padding_extra_w_st1;
136 st2_min1 += padding_extra_w_st1;
137 st2_max2 += padding_extra_w_st1;
138 st2_min2 += padding_extra_w_st1;
139 st3_max1 += padding_extra_w_st1;
140 st3_min1 += padding_extra_w_st1;
141 st3_max2 += padding_extra_w_st1;
142 st3_min2 += padding_extra_w_st1;
143 st4_max1 += padding_extra_w_st1;
144 st4_min1 += padding_extra_w_st1;
145 st4_max2 += padding_extra_w_st1;
146 st4_min2 += padding_extra_w_st1;
153 for (i = st1_min1; i <= st1_max1; i++)
155 for (i = st1_min2; i <= st1_max2; i++)
157 for (i = st2_min1; i <= st2_max1; i++)
159 for (i = st2_min2; i <= st2_max2; i++)
161 for (i = st3_min1; i <= st3_max1; i++)
163 for (i = st3_min2; i <= st3_max2; i++)
165 for (i = st4_min1; i <= st4_max1; i++)
167 for (i = st4_min2; i <= st4_max2; i++)
171 pattern.
rotr(padding_extra_w_st1);
174 if (not(
patterns_.size() == symPattDefinitions_.size()))
176 <<
", symPattDefinitions_.size() = " << symPattDefinitions_.size();
return; }
181 std::cout <<
"Pattern straightness: " <<
pattern.get_straightness() <<
" image: " << std::endl;
188 const std::deque<EMTFHitCollection>& extended_conv_hits,
189 std::map<pattern_ref_t, int>& patt_lifetime_map,
193 int num_conv_hits = 0;
194 for (
const auto& conv_hits : extended_conv_hits)
195 num_conv_hits += conv_hits.size();
196 bool early_exit = (num_conv_hits == 0) && (patt_lifetime_map.empty());
203 for (
const auto& conv_hits : extended_conv_hits) {
204 for (
const auto& conv_hit : conv_hits) {
206 std::cout <<
"st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
207 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp()
208 <<
" ph_hit: " << (1ul<<conv_hit.Ph_hit()) <<
" phzvl: " << conv_hit.Phzvl()
209 <<
" strip: " << conv_hit.Strip() <<
" wire: " << conv_hit.Wire() <<
" cpat: " << conv_hit.Pattern()
210 <<
" zone_hit: " << conv_hit.Zone_hit() <<
" zone_code: " << conv_hit.Zone_code()
211 <<
" bx: " << conv_hit.BX()
217 for (
const auto& conv_hits : extended_conv_hits) {
218 for (
const auto& conv_hit : conv_hits) {
220 std::cout <<
"RPC hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
221 <<
" ph>>2: " << (conv_hit.Phi_fp()>>2) <<
" th>>2: " << (conv_hit.Theta_fp()>>2)
222 <<
" strip: " << conv_hit.Strip() <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern()
223 <<
" bx: " << conv_hit.BX()
229 for (
const auto& conv_hits : extended_conv_hits) {
230 for (
const auto& conv_hit : conv_hits) {
232 std::cout <<
"GEM hit st: " << conv_hit.PC_station() <<
" ch: " << conv_hit.PC_chamber()
233 <<
" ph: " << conv_hit.Phi_fp() <<
" th: " << conv_hit.Theta_fp()
234 <<
" strip: " << conv_hit.Strip() <<
" roll: " << conv_hit.Roll() <<
" cpat: " << conv_hit.Pattern()
235 <<
" bx: " << conv_hit.BX()
247 if (
is_zone_empty(izone+1, extended_conv_hits, patt_lifetime_map))
254 process_single_zone(izone+1, zone_images.at(izone), patt_lifetime_map, zone_roads.at(izone));
258 for (
int izone = emtf::NUM_ZONES; izone >= 1; --izone) {
259 std::cout <<
"zone: " << izone << std::endl;
260 std::cout << zone_images.at(izone-1) << std::endl;
268 for (
const auto& roads : zone_roads) {
269 for (
const auto& road : reversed(roads)) {
270 std::cout <<
"pattern: z: " << road.Zone()-1 <<
" ph: " << road.Key_zhit()
271 <<
" q: " <<
to_hex(road.Quality_code()) <<
" ly: " << to_binary(road.Layer_code(), 3)
272 <<
" str: " << to_binary(road.Straightness(), 3) <<
" bx: " << road.BX()
287 const std::deque<EMTFHitCollection>& extended_conv_hits,
288 const std::map<pattern_ref_t, int>& patt_lifetime_map
291 int num_conv_hits = 0;
294 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
295 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
297 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
298 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
299 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
301 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
302 if (not(conv_hits_it->PC_segment() <= 4))
303 {
edm::LogError(
"L1T") <<
"conv_hits_it->PC_segment() = " << conv_hits_it->PC_segment();
return true; }
311 if (conv_hits_it->Zone_code() & (1 << izone)) {
317 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_it = patt_lifetime_map.begin();
318 std::map<pattern_ref_t, int>::const_iterator patt_lifetime_map_end = patt_lifetime_map.end();
320 for (; patt_lifetime_map_it != patt_lifetime_map_end; ++patt_lifetime_map_it) {
321 if (patt_lifetime_map_it->first.at(0) == zone) {
326 return (num_conv_hits == 0) && (num_patts == 0);
331 const std::deque<EMTFHitCollection>& extended_conv_hits,
336 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
337 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
339 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
340 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
341 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
343 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
350 if (conv_hits_it->Zone_code() & (1 << izone)) {
351 unsigned int layer = conv_hits_it->Station() - 1;
352 unsigned int bit = conv_hits_it->Zone_hit();
362 std::map<pattern_ref_t, int>& patt_lifetime_map,
372 cloned_image.
rotl(padding_w_st3);
378 cloned_image.
rotr(1);
380 int max_quality_code = -1;
384 for (
int ipatt = 0; ipatt < npatterns; ++ipatt) {
389 bool is_lifetime_up =
false;
391 int layer_code = patt.
op_and(cloned_image);
392 bool more_than_one = (layer_code != 0) && (layer_code != 1) && (layer_code != 2) && (layer_code != 4);
393 bool more_than_zero = (layer_code != 0);
395 if (more_than_zero) {
397 auto ins = patt_lifetime_map.insert({patt_ref, 0});
401 auto patt_ins =
ins.first;
402 bool patt_exists = !
ins.second;
405 if (patt_ins->second == drift_time) {
406 is_lifetime_up =
true;
409 patt_ins->second += 1;
413 auto patt_ins =
ins.first;
414 int bx_shifter = patt_ins->second;
415 int bx2 =
bool(bx_shifter & (1<<2));
416 int bx1 =
bool(bx_shifter & (1<<1));
417 int bx0 =
bool(bx_shifter & (1<<0));
419 if (bx2 == 0 && bx1 == 1) {
420 is_lifetime_up =
true;
425 bx0 = more_than_zero;
426 bx_shifter = (bx2 << 2) | (bx1 << 1) | bx0;
427 patt_ins->second = bx_shifter;
432 patt_lifetime_map.erase(patt_ref);
437 if (is_lifetime_up && more_than_one) {
442 (((straightness>>2) & 1) << 5) |
443 (((straightness>>1) & 1) << 3) |
444 (((straightness>>0) & 1) << 1) |
445 (((layer_code>>2) & 1) << 4) |
446 (((layer_code>>1) & 1) << 2) |
447 (((layer_code>>0) & 1) << 0)
466 if (max_quality_code < quality_code) {
467 max_quality_code = quality_code;
475 if (max_quality_code != -1) {
476 roads.push_back(tmp_road);
484 if (!roads.empty()) {
485 std::array<int, emtf::NUM_ZONE_HITS> quality_codes;
486 quality_codes.fill(0);
488 EMTFRoadCollection::iterator roads_it = roads.begin();
489 EMTFRoadCollection::iterator roads_end = roads.end();
491 for (; roads_it != roads_end; ++roads_it) {
492 quality_codes.at(roads_it->Key_zhit()) = roads_it->Quality_code();
495 roads_it = roads.begin();
496 roads_end = roads.end();
498 for (; roads_it != roads_end; ++roads_it) {
499 int izhit = roads_it->Key_zhit();
502 int qc = quality_codes.at(izhit);
506 int ql = (izhit == emtf::NUM_ZONE_HITS-1) ? 0 : quality_codes.at(izhit+1);
507 int qr = (izhit == 0) ? 0 : quality_codes.at(izhit-1);
510 if (qc <= ql || qc < qr) {
511 roads_it->set_quality_code( 0 );
520 bool operator()(
const value_type&
x)
const {
521 return (x.Quality_code() == 0);
523 } quality_code_zero_pred;
525 roads.erase(std::remove_if(roads.begin(), roads.end(), quality_code_zero_pred), roads.end());
532 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
533 return lhs.Key_zhit() > rhs.Key_zhit();
537 std::sort(roads.begin(), roads.end(), greater_zhit_cmp);
542 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
543 return lhs.Quality_code() > rhs.Quality_code();
545 } greater_quality_cmp;
547 std::stable_sort(roads.begin(), roads.end(), greater_quality_cmp);
551 if (roads.size() >
n) {
552 roads.erase(roads.begin() +
n, roads.end());
554 if (not(roads.size() <=
n))
555 {
edm::LogError(
"L1T") <<
"roads.size() = " << roads.size() <<
", n = " <<
n;
return; }
558 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
559 roads.at(iroad).set_winner( iroad );
unsigned int op_and(const PhiMemoryImage &other) const
static char to_hex(unsigned int i)
void set_straightness(int s)
l1t::EMTFRoadCollection EMTFRoadCollection
void set_bit(unsigned int layer, unsigned int bit)
std::vector< PhiMemoryImage > patterns_
void set_pattern(int bits)
void set_quality_code(int bits)
std::vector< std::string > pattDefinitions_
void sort_single_zone(EMTFRoadCollection &roads) const
void set_key_zhit(int bits)
void process_single_zone(int zone, PhiMemoryImage cloned_image, std::map< pattern_ref_t, int > &patt_lifetime_map, EMTFRoadCollection &roads) const
void set_sector(int bits)
void make_zone_image(int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, PhiMemoryImage &image) const
Container::value_type value_type
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 set_straightness(int bits)
int get_straightness() const
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)
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