CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PatternRecognition Class Reference

#include <PatternRecognition.h>

Public Types

typedef std::array< int, 3 > pattern_ref_t
 

Public Member Functions

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 configure_details ()
 
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 make_zone_image (int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, PhiMemoryImage &image) const
 
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 process_single_zone (int zone, PhiMemoryImage cloned_image, std::map< pattern_ref_t, int > &patt_lifetime_map, EMTFRoadCollection &roads) const
 
void sort_single_zone (EMTFRoadCollection &roads) const
 

Private Attributes

int bx_
 
int bxWindow_
 
int endcap_
 
int maxRoadsPerZone_
 
std::vector< std::string > pattDefinitions_
 
std::vector< PhiMemoryImagepatterns_
 
int sector_
 
std::vector< std::string > symPattDefinitions_
 
bool useSecondEarliest_
 
bool useSymPatterns_
 
int verbose_
 

Detailed Description

Definition at line 7 of file PatternRecognition.h.

Member Typedef Documentation

◆ pattern_ref_t

typedef std::array<int, 3> PatternRecognition::pattern_ref_t

Definition at line 10 of file PatternRecognition.h.

Member Function Documentation

◆ configure()

void PatternRecognition::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 
)

Definition at line 11 of file PatternRecognition.cc.

20  {
21  verbose_ = verbose;
22  endcap_ = endcap;
23  sector_ = sector;
24  bx_ = bx;
25 
26  bxWindow_ = bxWindow;
27  pattDefinitions_ = pattDefinitions;
28  symPattDefinitions_ = symPattDefinitions;
29  useSymPatterns_ = useSymPatterns;
30  maxRoadsPerZone_ = maxRoadsPerZone;
31  useSecondEarliest_ = useSecondEarliest;
32 
34 }

References simKBmtfDigis_cfi::bx, bx_, bxWindow_, configure_details(), makeMuonMisalignmentScenario::endcap, endcap_, maxRoadsPerZone_, pattDefinitions_, sector_, symPattDefinitions_, useSecondEarliest_, useSymPatterns_, verbose, and verbose_.

Referenced by SectorProcessor::process_single_bx().

◆ configure_details()

void PatternRecognition::configure_details ( )

Definition at line 36 of file PatternRecognition.cc.

36  {
37  emtf_assert(1 <= bxWindow_ && bxWindow_ <= 3); // only work for BX windows <= 3
38 
39  patterns_.clear();
40 
41  // Parse pattern definitions
42  if (!useSymPatterns_) {
43  // Normal patterns
44  for (const auto& s : pattDefinitions_) {
45  const std::vector<std::string>& tokens = split_string(s, ',', ':'); // split by comma or colon
46  emtf_assert(tokens.size() == 9); // want to find 9 numbers
47 
48  std::vector<std::string>::const_iterator tokens_it = tokens.begin();
49 
50  // Get the 9 integers
51  // straightness, hits in ME1, hits in ME2, hits in ME3, hits in ME4
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++);
61 
62  // There can only be one zone hit in the key station in the pattern
63  // and it has to be this magic number
64  emtf_assert(st2_max == padding_w_st3 && st2_min == padding_w_st3);
65 
66  // There is extra "padding" in st1 w.r.t st2,3,4
67  // Add the extra padding to st2,3,4
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;
74 
75  // Create a pattern
77  pattern.set_straightness(straightness);
78  int i = 0;
79 
80  for (i = st1_min; i <= st1_max; i++)
81  pattern.set_bit(0, i);
82  for (i = st2_min; i <= st2_max; i++)
83  pattern.set_bit(1, i);
84  for (i = st3_min; i <= st3_max; i++)
85  pattern.set_bit(2, i);
86  for (i = st4_min; i <= st4_max; i++)
87  pattern.set_bit(3, i);
88 
89  // Remove the extra padding
90  pattern.rotr(padding_extra_w_st1);
91  patterns_.push_back(pattern);
92  }
93  emtf_assert(patterns_.size() == pattDefinitions_.size());
94 
95  } else {
96  // Symmetrical patterns
97  for (const auto& s : symPattDefinitions_) {
98  const std::vector<std::string>& tokens = split_string(s, ',', ':'); // split by comma or colon
99  emtf_assert(tokens.size() == 17); // want to find 17 numbers
100 
101  std::vector<std::string>::const_iterator tokens_it = tokens.begin();
102 
103  // Get the 17 integers
104  // straightness, hits in ME1, hits in ME2, hits in ME3, hits in ME4
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++);
122 
123  // There can only be one zone hit in the key station in the pattern
124  // and it has to be this magic number
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);
127 
128  // There is extra "padding" in st1 w.r.t st2,3,4
129  // Add the extra padding to st2,3,4
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;
142 
143  // Create a pattern
145  pattern.set_straightness(straightness);
146  int i = 0;
147 
148  for (i = st1_min1; i <= st1_max1; i++)
149  pattern.set_bit(0, i);
150  for (i = st1_min2; i <= st1_max2; i++)
151  pattern.set_bit(0, i);
152  for (i = st2_min1; i <= st2_max1; i++)
153  pattern.set_bit(1, i);
154  for (i = st2_min2; i <= st2_max2; i++)
155  pattern.set_bit(1, i);
156  for (i = st3_min1; i <= st3_max1; i++)
157  pattern.set_bit(2, i);
158  for (i = st3_min2; i <= st3_max2; i++)
159  pattern.set_bit(2, i);
160  for (i = st4_min1; i <= st4_max1; i++)
161  pattern.set_bit(3, i);
162  for (i = st4_min2; i <= st4_max2; i++)
163  pattern.set_bit(3, i);
164 
165  // Remove the extra padding
166  pattern.rotr(padding_extra_w_st1);
167  patterns_.push_back(pattern);
168  }
169  emtf_assert(patterns_.size() == symPattDefinitions_.size());
170  }
171 
172  if (verbose_ > 2) { // debug
173  for (const auto& pattern : patterns_) {
174  std::cout << "Pattern straightness: " << pattern.get_straightness() << " image: " << std::endl;
175  std::cout << pattern << std::endl;
176  }
177  }
178 }

References bxWindow_, gather_cfg::cout, emtf_assert, mps_fire::i, pattDefinitions_, topSingleLeptonDQM_PU_cfi::pattern, patterns_, alignCSCRings::s, symPattDefinitions_, useSymPatterns_, and verbose_.

Referenced by configure().

◆ is_zone_empty()

bool PatternRecognition::is_zone_empty ( int  zone,
const std::deque< EMTFHitCollection > &  extended_conv_hits,
const std::map< pattern_ref_t, int > &  patt_lifetime_map 
) const

Definition at line 269 of file PatternRecognition.cc.

271  {
272  int izone = zone - 1;
273  int num_conv_hits = 0;
274  int num_patts = 0;
275 
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();
278 
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();
282 
283  for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
284  emtf_assert(conv_hits_it->PC_segment() <=
285  4); // With 2 unique LCTs per chamber, 4 possible strip/wire combinations
286 
287  if (conv_hits_it->Subsystem() == TriggerPrimitive::kRPC)
288  continue; // Don't use RPC hits for pattern formation
289 
290  if (conv_hits_it->Subsystem() == TriggerPrimitive::kGEM)
291  continue; // Don't use GEM hits for pattern formation
292 
293  if (conv_hits_it->Zone_code() & (1 << izone)) { // hit belongs to this zone
294  num_conv_hits += 1;
295  }
296  } // end loop over conv_hits
297  } // end loop over extended_conv_hits
298 
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();
301 
302  for (; patt_lifetime_map_it != patt_lifetime_map_end; ++patt_lifetime_map_it) {
303  if (patt_lifetime_map_it->first.at(0) == zone) {
304  num_patts += 1;
305  }
306  } // end loop over patt_lifetime_map
307 
308  return (num_conv_hits == 0) && (num_patts == 0);
309 }

References emtf_assert, L1TMuon::TriggerPrimitive::kGEM, and L1TMuon::TriggerPrimitive::kRPC.

Referenced by process().

◆ make_zone_image()

void PatternRecognition::make_zone_image ( int  zone,
const std::deque< EMTFHitCollection > &  extended_conv_hits,
PhiMemoryImage image 
) const

Definition at line 311 of file PatternRecognition.cc.

313  {
314  int izone = zone - 1;
315 
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();
318 
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();
322 
323  for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
324  if (conv_hits_it->Subsystem() == TriggerPrimitive::kRPC)
325  continue; // Don't use RPC hits for pattern formation
326 
327  if (conv_hits_it->Subsystem() == TriggerPrimitive::kGEM)
328  continue; // Don't use GEM hits for pattern formation
329 
330  if (conv_hits_it->Zone_code() & (1 << izone)) { // hit belongs to this zone
331  unsigned int layer = conv_hits_it->Station() - 1;
332  unsigned int bit = conv_hits_it->Zone_hit();
333  image.set_bit(layer, bit);
334  }
335  } // end loop over conv_hits
336  } // end loop over extended_conv_hits
337 }

References L1TMuon::TriggerPrimitive::kGEM, L1TMuon::TriggerPrimitive::kRPC, and PhiMemoryImage::set_bit().

Referenced by process().

◆ process()

void PatternRecognition::process ( const std::deque< EMTFHitCollection > &  extended_conv_hits,
std::map< pattern_ref_t, int > &  patt_lifetime_map,
emtf::zone_array< EMTFRoadCollection > &  zone_roads 
) const

Definition at line 180 of file PatternRecognition.cc.

182  {
183  // Exit if no hits
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());
188 
189  if (early_exit)
190  return;
191 
192  if (verbose_ > 0) { // debug
193  for (const auto& conv_hits : extended_conv_hits) {
194  for (const auto& conv_hit : conv_hits) {
195  if (conv_hit.Subsystem() == TriggerPrimitive::kCSC) {
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;
201  }
202  }
203  }
204 
205  for (const auto& conv_hits : extended_conv_hits) {
206  for (const auto& conv_hit : conv_hits) {
207  if (conv_hit.Subsystem() == TriggerPrimitive::kRPC) {
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;
212  }
213  }
214  }
215 
216  for (const auto& conv_hits : extended_conv_hits) {
217  for (const auto& conv_hit : conv_hits) {
218  if (conv_hit.Subsystem() == TriggerPrimitive::kGEM) {
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()
222  << std::endl;
223  }
224  }
225  }
226  } // end debug
227 
228  // Perform pattern recognition in each zone
230 
231  for (int izone = 0; izone < emtf::NUM_ZONES; ++izone) {
232  // Skip the zone if no hits and no patterns
233  if (is_zone_empty(izone + 1, extended_conv_hits, patt_lifetime_map))
234  continue;
235 
236  // Make zone images
237  make_zone_image(izone + 1, extended_conv_hits, zone_images.at(izone));
238 
239  // Detect patterns
240  process_single_zone(izone + 1, zone_images.at(izone), patt_lifetime_map, zone_roads.at(izone));
241  }
242 
243  if (verbose_ > 2) { // debug
244  for (int izone = emtf::NUM_ZONES; izone >= 1; --izone) {
245  std::cout << "zone: " << izone << std::endl;
246  std::cout << zone_images.at(izone - 1) << std::endl;
247  }
248  //for (const auto& kv : patt_lifetime_map) {
249  // std::cout << "zone: " << kv.first.at(0) << " izhit: " << kv.first.at(1) << " ipatt: " << kv.first.at(2) << " lifetime: " << kv.second << std::endl;
250  //}
251  }
252 
253  if (verbose_ > 0) { // debug
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;
259  }
260  }
261  }
262 
263  // Sort patterns and select best three patterns in each zone
264  for (int izone = 0; izone < emtf::NUM_ZONES; ++izone) {
265  sort_single_zone(zone_roads.at(izone));
266  }
267 }

References gather_cfg::cout, is_zone_empty(), L1TMuon::TriggerPrimitive::kCSC, L1TMuon::TriggerPrimitive::kGEM, L1TMuon::TriggerPrimitive::kRPC, make_zone_image(), emtf::NUM_ZONES, process_single_zone(), sort_single_zone(), to_hex(), and verbose_.

Referenced by SectorProcessor::process_single_bx().

◆ process_single_zone()

void PatternRecognition::process_single_zone ( int  zone,
PhiMemoryImage  cloned_image,
std::map< pattern_ref_t, int > &  patt_lifetime_map,
EMTFRoadCollection roads 
) const

Definition at line 339 of file PatternRecognition.cc.

342  {
343  roads.clear();
344 
345  const int drift_time = bxWindow_ - 1;
346  const int npatterns = patterns_.size();
347 
348  // The zone hit image is rotated/shifted before comparing with patterns
349  // First, rotate left/shift up to the zone hit in the key station
350  cloned_image.rotl(padding_w_st3);
351 
352  for (int izhit = 0; izhit < emtf::NUM_ZONE_HITS; ++izhit) {
353  // The zone hit image is rotated/shift before comparing with patterns
354  // For every zone hit, rotate right/shift down by one
355  if (izhit > 0)
356  cloned_image.rotr(1);
357 
358  int max_quality_code = -1;
359  EMTFRoad tmp_road;
360 
361  // Compare with patterns
362  for (int ipatt = 0; ipatt < npatterns; ++ipatt) {
363  const PhiMemoryImage& patt = patterns_.at(ipatt);
364  const pattern_ref_t patt_ref = {{zone, izhit, ipatt}}; // due to GCC bug, use {{}} instead of {}
365  int straightness = patt.get_straightness();
366 
367  bool is_lifetime_up = false;
368 
369  int layer_code = patt.op_and(cloned_image); // kind of like AND operator
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);
372 
373  if (more_than_zero) {
374  // Insert this pattern
375  auto ins = patt_lifetime_map.insert({patt_ref, 0});
376 
377  if (!useSecondEarliest_) {
378  // Use earliest
379  auto patt_ins = ins.first; // iterator of patt_lifetime_map pointing to this pattern
380  bool patt_exists = !ins.second;
381 
382  if (patt_exists) { // if exists
383  if (patt_ins->second == drift_time) { // is lifetime up?
384  is_lifetime_up = true;
385  }
386  }
387  patt_ins->second += 1; // bx starts counting at any hit in the pattern, even single
388 
389  } else {
390  // Use 2nd earliest
391  auto patt_ins = ins.first; // iterator of patt_lifetime_map pointing to this pattern
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));
396 
397  // is lifetime up?
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;
404  }
405 
406  bx2 = bx1;
407  bx1 = bx0;
408  bx0 = more_than_zero; // put 1 in shifter when one layer is hit
409  bx_shifter = (bx2 << 2) | (bx1 << 1) | bx0;
410  patt_ins->second = bx_shifter;
411  }
412 
413  } else {
414  // Zero hit
415  patt_lifetime_map.erase(patt_ref); // erase if exists
416  }
417 
418  // If lifetime is up, and not single-layer hit patterns (stations 3&4 considered
419  // as a single layer), find quality of this pattern
420  if (is_lifetime_up && more_than_one) {
421  // This quality code scheme is giving almost-equal priority to
422  // more stations and better straightness
423  // Station 1 has higher weight, station 2 lower, stations 3&4 lowest
424  int quality_code =
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));
427 
428  // Create a road (fired pattern)
429  EMTFRoad road;
430  road.set_endcap((endcap_ == 1) ? 1 : -1);
431  road.set_sector(sector_);
432  road.set_sector_idx((endcap_ == 1) ? sector_ - 1 : sector_ + 5);
433  road.set_bx(bx_ - drift_time);
434 
435  road.set_zone(patt_ref.at(0));
436  road.set_key_zhit(patt_ref.at(1));
437  road.set_pattern(patt_ref.at(2));
438 
439  road.set_straightness(straightness);
440  road.set_layer_code(layer_code);
441  road.set_quality_code(quality_code);
442 
443  // Find max quality code in a given key_zhit
444  if (max_quality_code < quality_code) {
445  max_quality_code = quality_code;
446  tmp_road = std::move(road);
447  }
448  } // end if is_lifetime_up
449 
450  } // end loop over patterns
451 
452  // Output road
453  if (max_quality_code != -1) {
454  roads.push_back(tmp_road);
455  }
456 
457  } // end loop over zone hits
458 
459  // Ghost cancellation logic by considering neighbor patterns
460 
461  if (!roads.empty()) {
462  std::array<int, emtf::NUM_ZONE_HITS> quality_codes;
463  quality_codes.fill(0);
464 
465  EMTFRoadCollection::iterator roads_it = roads.begin();
466  EMTFRoadCollection::iterator roads_end = roads.end();
467 
468  for (; roads_it != roads_end; ++roads_it) {
469  quality_codes.at(roads_it->Key_zhit()) = roads_it->Quality_code();
470  }
471 
472  roads_it = roads.begin();
473  roads_end = roads.end();
474 
475  for (; roads_it != roads_end; ++roads_it) {
476  int izhit = roads_it->Key_zhit();
477 
478  // Center quality is the current one
479  int qc = quality_codes.at(izhit);
480 
481  // Left and right qualities are the neighbors
482  // Protect against the right end and left end special cases
483  int ql = (izhit == emtf::NUM_ZONE_HITS - 1) ? 0 : quality_codes.at(izhit + 1);
484  int qr = (izhit == 0) ? 0 : quality_codes.at(izhit - 1);
485 
486  // Cancellation conditions
487  if (qc <= ql || qc < qr) { // this pattern is lower quality than neighbors
488  roads_it->set_quality_code(0); // cancel
489  }
490  }
491  }
492 
493  // Erase roads with quality_code == 0
494  // using erase-remove idiom
495  struct {
496  typedef EMTFRoad value_type;
497  bool operator()(const value_type& x) const { return (x.Quality_code() == 0); }
498  } quality_code_zero_pred;
499 
500  roads.erase(std::remove_if(roads.begin(), roads.end(), quality_code_zero_pred), roads.end());
501 }

References electrons_cff::bool, bx_, bxWindow_, endcap_, cuy::ins, eostools::move(), emtf::NUM_ZONE_HITS, patt, patterns_, PhiMemoryImage::rotl(), PhiMemoryImage::rotr(), sector_, l1t::EMTFRoad::set_bx(), l1t::EMTFRoad::set_endcap(), l1t::EMTFRoad::set_key_zhit(), l1t::EMTFRoad::set_layer_code(), l1t::EMTFRoad::set_pattern(), l1t::EMTFRoad::set_quality_code(), l1t::EMTFRoad::set_sector(), l1t::EMTFRoad::set_sector_idx(), l1t::EMTFRoad::set_straightness(), l1t::EMTFRoad::set_zone(), useSecondEarliest_, and x.

Referenced by process().

◆ sort_single_zone()

void PatternRecognition::sort_single_zone ( EMTFRoadCollection roads) const

Definition at line 503 of file PatternRecognition.cc.

503  {
504  // First, order by key_zhit (highest to lowest)
505  struct {
506  typedef EMTFRoad value_type;
507  bool operator()(const value_type& lhs, const value_type& rhs) const { return lhs.Key_zhit() > rhs.Key_zhit(); }
508  } greater_zhit_cmp;
509 
510  std::sort(roads.begin(), roads.end(), greater_zhit_cmp);
511 
512  // Second, sort by quality_code (highest to lowest), but preserving the original order if qualities are equal
513  struct {
514  typedef EMTFRoad value_type;
515  bool operator()(const value_type& lhs, const value_type& rhs) const {
516  return lhs.Quality_code() > rhs.Quality_code();
517  }
518  } greater_quality_cmp;
519 
520  std::stable_sort(roads.begin(), roads.end(), greater_quality_cmp);
521 
522  // Finally, select 3 best
523  const size_t n = maxRoadsPerZone_;
524  if (roads.size() > n) {
525  roads.erase(roads.begin() + n, roads.end());
526  }
527  emtf_assert(roads.size() <= n);
528 
529  // Assign the winner variable
530  for (unsigned iroad = 0; iroad < roads.size(); ++iroad) {
531  roads.at(iroad).set_winner(iroad);
532  }
533 }

References emtf_assert, maxRoadsPerZone_, and dqmiodumpmetadata::n.

Referenced by process().

Member Data Documentation

◆ bx_

int PatternRecognition::bx_
private

Definition at line 43 of file PatternRecognition.h.

Referenced by configure(), and process_single_zone().

◆ bxWindow_

int PatternRecognition::bxWindow_
private

Definition at line 45 of file PatternRecognition.h.

Referenced by configure(), configure_details(), and process_single_zone().

◆ endcap_

int PatternRecognition::endcap_
private

Definition at line 43 of file PatternRecognition.h.

Referenced by configure(), and process_single_zone().

◆ maxRoadsPerZone_

int PatternRecognition::maxRoadsPerZone_
private

Definition at line 48 of file PatternRecognition.h.

Referenced by configure(), and sort_single_zone().

◆ pattDefinitions_

std::vector<std::string> PatternRecognition::pattDefinitions_
private

Definition at line 46 of file PatternRecognition.h.

Referenced by configure(), and configure_details().

◆ patterns_

std::vector<PhiMemoryImage> PatternRecognition::patterns_
private

Definition at line 51 of file PatternRecognition.h.

Referenced by configure_details(), and process_single_zone().

◆ sector_

int PatternRecognition::sector_
private

Definition at line 43 of file PatternRecognition.h.

Referenced by configure(), and process_single_zone().

◆ symPattDefinitions_

std::vector<std::string> PatternRecognition::symPattDefinitions_
private

Definition at line 46 of file PatternRecognition.h.

Referenced by configure(), and configure_details().

◆ useSecondEarliest_

bool PatternRecognition::useSecondEarliest_
private

Definition at line 49 of file PatternRecognition.h.

Referenced by configure(), and process_single_zone().

◆ useSymPatterns_

bool PatternRecognition::useSymPatterns_
private

Definition at line 47 of file PatternRecognition.h.

Referenced by configure(), and configure_details().

◆ verbose_

int PatternRecognition::verbose_
private

Definition at line 43 of file PatternRecognition.h.

Referenced by configure(), configure_details(), and process().

PhiMemoryImage::set_bit
void set_bit(unsigned int layer, unsigned int bit)
Definition: PhiMemoryImage.cc:40
l1t::EMTFRoad::set_sector
void set_sector(int bits)
Definition: EMTFRoad.h:27
electrons_cff.bool
bool
Definition: electrons_cff.py:372
PatternRecognition::pattDefinitions_
std::vector< std::string > pattDefinitions_
Definition: PatternRecognition.h:46
mps_fire.i
i
Definition: mps_fire.py:355
patt
float patt[4][130000]
Definition: HijingWrapper.h:48
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PatternRecognition::process_single_zone
void process_single_zone(int zone, PhiMemoryImage cloned_image, std::map< pattern_ref_t, int > &patt_lifetime_map, EMTFRoadCollection &roads) const
Definition: PatternRecognition.cc:339
PatternRecognition::patterns_
std::vector< PhiMemoryImage > patterns_
Definition: PatternRecognition.h:51
PatternRecognition::useSecondEarliest_
bool useSecondEarliest_
Definition: PatternRecognition.h:49
gather_cfg.cout
cout
Definition: gather_cfg.py:144
l1t::EMTFRoad
Definition: EMTFRoad.h:9
PatternRecognition::useSymPatterns_
bool useSymPatterns_
Definition: PatternRecognition.h:47
DDAxes::x
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
L1TMuon::TriggerPrimitive::kCSC
Definition: MuonTriggerPrimitive.h:59
PatternRecognition::maxRoadsPerZone_
int maxRoadsPerZone_
Definition: PatternRecognition.h:48
l1t::EMTFRoad::set_quality_code
void set_quality_code(int bits)
Definition: EMTFRoad.h:35
simKBmtfDigis_cfi.bx
bx
Definition: simKBmtfDigis_cfi.py:55
l1t::EMTFRoad::set_endcap
void set_endcap(int bits)
Definition: EMTFRoad.h:26
alignCSCRings.s
s
Definition: alignCSCRings.py:92
l1t::EMTFRoad::set_layer_code
void set_layer_code(int bits)
Definition: EMTFRoad.h:34
l1t::EMTFRoad::set_straightness
void set_straightness(int bits)
Definition: EMTFRoad.h:33
L1TMuon::TriggerPrimitive::kGEM
Definition: MuonTriggerPrimitive.h:59
emtf::NUM_ZONE_HITS
constexpr int NUM_ZONE_HITS
Definition: Common.h:55
PatternRecognition::sector_
int sector_
Definition: PatternRecognition.h:43
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
l1t::EMTFRoad::set_sector_idx
void set_sector_idx(int bits)
Definition: EMTFRoad.h:28
PatternRecognition::sort_single_zone
void sort_single_zone(EMTFRoadCollection &roads) const
Definition: PatternRecognition.cc:503
cuy.ins
ins
Definition: cuy.py:314
PatternRecognition::bxWindow_
int bxWindow_
Definition: PatternRecognition.h:45
l1t::EMTFRoad::set_pattern
void set_pattern(int bits)
Definition: EMTFRoad.h:32
to_hex
static char to_hex(unsigned int i)
Definition: types.cc:27
l1t::EMTFRoad::set_bx
void set_bx(int bits)
Definition: EMTFRoad.h:29
PatternRecognition::symPattDefinitions_
std::vector< std::string > symPattDefinitions_
Definition: PatternRecognition.h:46
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
PatternRecognition::is_zone_empty
bool is_zone_empty(int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, const std::map< pattern_ref_t, int > &patt_lifetime_map) const
Definition: PatternRecognition.cc:269
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
PatternRecognition::verbose_
int verbose_
Definition: PatternRecognition.h:43
l1t::EMTFRoad::set_key_zhit
void set_key_zhit(int bits)
Definition: EMTFRoad.h:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
PhiMemoryImage
Definition: PhiMemoryImage.h:9
PatternRecognition::make_zone_image
void make_zone_image(int zone, const std::deque< EMTFHitCollection > &extended_conv_hits, PhiMemoryImage &image) const
Definition: PatternRecognition.cc:311
PatternRecognition::bx_
int bx_
Definition: PatternRecognition.h:43
emtf::NUM_ZONES
constexpr int NUM_ZONES
Definition: Common.h:54
emtf_assert
#define emtf_assert(expr)
Definition: DebugTools.h:18
PhiMemoryImage::rotl
void rotl(unsigned int n)
Definition: PhiMemoryImage.cc:88
emtf::zone_array
std::array< T, NUM_ZONES > zone_array
Definition: Common.h:65
l1t::EMTFRoad::set_zone
void set_zone(int bits)
Definition: EMTFRoad.h:30
PatternRecognition::endcap_
int endcap_
Definition: PatternRecognition.h:43
PatternRecognition::configure_details
void configure_details()
Definition: PatternRecognition.cc:36
PhiMemoryImage::rotr
void rotr(unsigned int n)
Definition: PhiMemoryImage.cc:116
PatternRecognition::pattern_ref_t
std::array< int, 3 > pattern_ref_t
Definition: PatternRecognition.h:10
L1TMuon::TriggerPrimitive::kRPC
Definition: MuonTriggerPrimitive.h:59