8 const int invalid_ph_diff = 0x1ff;
14 bool fixZonePhi,
bool useNewZones,
15 bool bugSt2PhDiff,
bool bugME11Dupes
29 const std::deque<EMTFHitCollection>& extended_conv_hits,
35 auto update_fs_history = [](
int fs_segment,
int this_bx,
int hit_bx) {
37 int fs_history = this_bx - hit_bx;
38 fs_segment |= ((fs_history & 0x3)<<4);
43 auto update_bt_history = [](
int bt_segment,
int this_bx,
int hit_bx) {
45 int bt_history = this_bx - hit_bx;
46 bt_segment |= ((bt_history & 0x3)<<5);
53 for (
const auto& roads : zone_roads)
54 num_roads += roads.size();
55 bool early_exit = (num_roads == 0);
62 for (
const auto& roads : zone_roads) {
63 for (
const auto& road : roads) {
64 std::cout <<
"pattern on match input: z: " << road.Zone()-1 <<
" r: " << road.Winner()
65 <<
" ph_num: " << road.Key_zhit() <<
" ph_q: " <<
to_hex(road.Quality_code())
66 <<
" ly: " << to_binary(road.Layer_code(), 3) <<
" str: " << to_binary(road.Straightness(), 3)
73 std::array<EMTFHitCollection, emtf::NUM_ZONES*emtf::NUM_STATIONS> zs_conv_hits;
75 bool use_fs_zone_code =
true;
77 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
78 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
80 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
81 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
82 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
84 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
85 int istation = conv_hits_it->Station()-1;
86 int zone_code = conv_hits_it->Zone_code();
88 zone_code = conv_hits_it->FS_zone_code();
92 if (!zone_roads.at(izone).empty()) {
94 if (zone_code & (1<<izone)) {
96 zs_conv_hits.at(zs).push_back(*conv_hits_it);
100 EMTFHit& conv_hit = zs_conv_hits.at(zs).back();
102 int new_fs_segment = update_fs_history(old_fs_segment,
bx_, conv_hit.
BX());
106 int new_bt_segment = update_bt_history(old_bt_segment,
bx_, conv_hit.
BX());
119 for (
const auto& conv_hit : zs_conv_hits.at(zs)) {
120 std::cout <<
"z: " << izone <<
" st: " << istation+1 <<
" cscid: " << conv_hit.CSC_ID()
121 <<
" ph_zone_phi: " << conv_hit.Zone_hit() <<
" ph_low_prec: " << (conv_hit.Zone_hit()<<5)
122 <<
" ph_high_prec: " << conv_hit.Phi_fp() <<
" ph_high_low_diff: " << (conv_hit.Phi_fp() - (conv_hit.Zone_hit()<<5))
143 zone_roads.at(izone),
145 zs_phi_differences.at(zs)
148 if (not(zone_roads.at(izone).size() == zs_phi_differences.at(zs).size()))
149 {
edm::LogError(
"L1T") <<
"zone_roads.at(izone).size() = " << zone_roads.at(izone).size()
150 <<
", zs_phi_differences.at(zs).size() = " << zs_phi_differences.at(zs).size();
return; }
156 const auto& roads = zone_roads.at(izone);
157 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
158 const auto& road = roads.at(iroad);
161 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
162 std::cout <<
"find seg: z: " << road.Zone()-1 <<
" r: " << road.Winner()
163 <<
" st: " << istation <<
" ph_diff: " << ph_diff
175 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
176 const EMTFRoad& road = roads.at(iroad);
197 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
198 hit_ptr_t conv_hit_ptr = zs_phi_differences.at(zs).at(iroad).second;
200 if (ph_diff != invalid_ph_diff) {
208 if (not(!track.
Hits().empty()))
209 {
edm::LogError(
"L1T") <<
"track.Hits().empty() = " << track.
Hits().empty();
return; }
213 zone_tracks.at(izone).push_back(track);
219 for (
const auto&
tracks : zone_tracks) {
221 for (
const auto&
hit :
track.Hits()) {
223 <<
" vi: " << to_binary(0b1, 2) <<
" hi: " << ((
hit.FS_segment()>>4) & 0x3)
224 <<
" ci: " << ((
hit.FS_segment()>>1) & 0x7) <<
" si: " << (
hit.FS_segment() & 0x1)
225 <<
" ph: " <<
hit.Phi_fp() <<
" th: " <<
hit.Theta_fp()
238 std::vector<hit_sort_pair_t>& phi_differences
242 int max_ph_diff = (station == 1) ? 15 : 7;
251 }
else if (station == 2) {
265 auto abs_diff = [](
int a,
int b) {
return std::abs(a-
b); };
270 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
271 return lhs.first <= rhs.first;
278 int operator()(
const value_type& a,
const value_type&
b,
const value_type&
c)
const {
280 r |=
bool(a.first <= b.first);
282 r |=
bool(b.first <= c.first);
284 r |=
bool(c.first <= a.first);
289 case 0b001 : rr = 2;
break;
290 case 0b010 : rr = 1;
break;
291 case 0b011 : rr = 1;
break;
292 case 0b100 : rr = 0;
break;
293 case 0b101 : rr = 2;
break;
294 case 0b110 : rr = 0;
break;
296 default : rr = 0;
break;
306 EMTFRoadCollection::const_iterator roads_it = roads.begin();
307 EMTFRoadCollection::const_iterator roads_end = roads.end();
309 for (; roads_it != roads_end; ++roads_it) {
310 int ph_pat = roads_it->Key_zhit();
311 int ph_q = roads_it->Quality_code();
312 if (not(ph_pat >= 0 && ph_q > 0))
313 {
edm::LogError(
"L1T") <<
"ph_pat = " << ph_pat <<
", ph_q = " << ph_q;
return; }
319 std::vector<hit_sort_pair_t> tmp_phi_differences;
321 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
322 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
324 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
325 int ph_seg = conv_hits_it->Phi_fp();
326 int ph_seg_red = ph_seg >> (bw_fph-bpow-1);
327 if (not(ph_seg >= 0))
335 int ph_diff = abs_diff(ph_pat, ph_seg_red);
336 if (ph_diff > max_ph_diff)
337 ph_diff = invalid_ph_diff;
339 if (ph_diff != invalid_ph_diff)
340 tmp_phi_differences.push_back(std::make_pair(ph_diff, conv_hits_it));
346 if (!tmp_phi_differences.empty()) {
350 bool use_fw_sorting =
true;
354 if (use_fw_sorting) {
357 const int max_drift = 3;
358 const int zone_cham = ((zone == 1 && (2 <= station && station <= 4)) || (zone == 2 && station == 2)) ? 4 : 7;
359 const int seg_ch = 2;
360 const int tot_diff = (max_drift*zone_cham*seg_ch) + ((zone_cham == 4) ? 3 : 12);
362 std::vector<hit_sort_pair_t> fw_sort_array(tot_diff, std::make_pair(invalid_ph_diff, conv_hits_end));
365 std::vector<hit_sort_pair_t>::const_iterator phdiffs_it = tmp_phi_differences.begin();
366 std::vector<hit_sort_pair_t>::const_iterator phdiffs_end = tmp_phi_differences.end();
368 for (; phdiffs_it != phdiffs_end; ++phdiffs_it) {
370 int fs_segment = phdiffs_it->second->FS_segment();
373 int fs_history = ((fs_segment>>4) & 0x3);
374 int fs_chamber = ((fs_segment>>1) & 0x7);
375 fs_segment = (fs_segment & 0x1);
376 unsigned fw_sort_array_index = (fs_history * zone_cham * seg_ch) + (fs_chamber * seg_ch) + fs_segment;
378 if (not(fs_history < max_drift && fs_chamber < zone_cham && fs_segment < seg_ch))
379 {
edm::LogError(
"L1T") <<
"fs_history = " << fs_history <<
", max_drift = " << max_drift
380 <<
", fs_chamber = " << fs_chamber <<
", zone_cham = " << zone_cham
381 <<
", fs_segment = " << fs_segment <<
", seg_ch = " << seg_ch;
return; }
382 if (not(fw_sort_array_index < fw_sort_array.size()))
383 {
edm::LogError(
"L1T") <<
"fw_sort_array_index = " << fw_sort_array_index
384 <<
", fw_sort_array.size() = " << fw_sort_array.size();
return; }
385 fw_sort_array.at(fw_sort_array_index) = *phdiffs_it;
402 merge_sort3_with_hint(fw_sort_array.begin(), fw_sort_array.end(), less_ph_diff_cmp, less_ph_diff_cmp3, ((tot_diff == 54) ? tot_diff/2 : tot_diff/3));
405 phi_differences.push_back(fw_sort_array.front());
416 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
418 if (lhs.second->Subsystem() != rhs.second->Subsystem())
421 return lhs.first <= rhs.first;
423 } tmp_less_ph_diff_cmp;
426 std::stable_sort(tmp_phi_differences.begin(), tmp_phi_differences.end(), tmp_less_ph_diff_cmp);
429 phi_differences.push_back(tmp_phi_differences.front());
434 phi_differences.push_back(std::make_pair(invalid_ph_diff, conv_hits_end));
444 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
445 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
448 (conv_hit_ptr->Station() == 1) && (conv_hit_ptr->Ring() == 1 || conv_hit_ptr->Ring() == 4);
451 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
452 const EMTFHit& conv_hit_i = *conv_hits_it;
453 const EMTFHit& conv_hit_j = *conv_hit_ptr;
460 (conv_hit_i.
Ring() == conv_hit_j.
Ring()) &&
464 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
467 (conv_hit_i.
Roll() == conv_hit_j.
Roll()) &&
473 <<
", conv_hit_j.Phi_fp() = " << conv_hit_j.
Phi_fp();
return; }
486 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
502 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
503 return lhs.Station() < rhs.Station();
508 std::stable_sort(tmp_hits.begin(), tmp_hits.end(), less_station_cmp);
static char to_hex(unsigned int i)
void set_sector(int bits)
l1t::EMTFRoadCollection EMTFRoadCollection
std::pair< int, hit_ptr_t > hit_sort_pair_t
void set_ph_num(int bits)
void set_theta_fp(int bits)
void set_sector_idx(int bits)
void insert_hits(hit_ptr_t conv_hit_ptr, const EMTFHitCollection &conv_hits, EMTFTrack &track) const
Container::value_type value_type
void set_bt_segment(int bits)
std::array< T, NUM_ZONES > zone_array
Abs< T >::type abs(const T &t)
l1t::EMTFHitCollection EMTFHitCollection
EMTFHitCollection::const_iterator hit_ptr_t
void set_fs_segment(int bits)
void set_winner(int bits)
EMTFHitCollection Hits() const
void process_single_zone_station(int zone, int station, const EMTFRoadCollection &roads, const EMTFHitCollection &conv_hits, std::vector< hit_sort_pair_t > &phi_differences) const
void set_endcap(int bits)
void push_Hit(const EMTFHit &hit)
void set_Hits(const EMTFHitCollection &hits)
void process(const std::deque< EMTFHitCollection > &extended_conv_hits, const emtf::zone_array< EMTFRoadCollection > &zone_roads, emtf::zone_array< EMTFTrackCollection > &zone_tracks) const
void configure(int verbose, int endcap, int sector, int bx, bool fixZonePhi, bool useNewZones, bool bugSt2PhDiff, bool bugME11Dupes)