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) {
86 int istation = conv_hits_it->Station()-1;
87 int zone_code = conv_hits_it->Zone_code();
89 zone_code = conv_hits_it->FS_zone_code();
93 if (!zone_roads.at(izone).empty()) {
95 if (zone_code & (1<<izone)) {
97 zs_conv_hits.at(zs).push_back(*conv_hits_it);
101 EMTFHit& conv_hit = zs_conv_hits.at(zs).back();
103 int new_fs_segment = update_fs_history(old_fs_segment,
bx_, conv_hit.
BX());
107 int new_bt_segment = update_bt_history(old_bt_segment,
bx_, conv_hit.
BX());
120 for (
const auto& conv_hit : zs_conv_hits.at(zs)) {
121 std::cout <<
"z: " << izone <<
" st: " << istation+1 <<
" cscid: " << conv_hit.CSC_ID()
122 <<
" ph_zone_phi: " << conv_hit.Zone_hit() <<
" ph_low_prec: " << (conv_hit.Zone_hit()<<5)
123 <<
" ph_high_prec: " << conv_hit.Phi_fp() <<
" ph_high_low_diff: " << (conv_hit.Phi_fp() - (conv_hit.Zone_hit()<<5))
144 zone_roads.at(izone),
146 zs_phi_differences.at(zs)
149 if (not(zone_roads.at(izone).size() == zs_phi_differences.at(zs).size()))
150 {
edm::LogError(
"L1T") <<
"zone_roads.at(izone).size() = " << zone_roads.at(izone).size()
151 <<
", zs_phi_differences.at(zs).size() = " << zs_phi_differences.at(zs).size();
return; }
157 const auto& roads = zone_roads.at(izone);
158 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
159 const auto& road = roads.at(iroad);
162 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
163 std::cout <<
"find seg: z: " << road.Zone()-1 <<
" r: " << road.Winner()
164 <<
" st: " << istation <<
" ph_diff: " << ph_diff
176 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
177 const EMTFRoad& road = roads.at(iroad);
198 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
199 hit_ptr_t conv_hit_ptr = zs_phi_differences.at(zs).at(iroad).second;
201 if (ph_diff != invalid_ph_diff) {
209 if (not(!track.
Hits().empty()))
210 {
edm::LogError(
"L1T") <<
"track.Hits().empty() = " << track.
Hits().empty();
return; }
214 zone_tracks.at(izone).push_back(track);
220 for (
const auto&
tracks : zone_tracks) {
222 for (
const auto&
hit :
track.Hits()) {
224 <<
" vi: " << to_binary(0b1, 2) <<
" hi: " << ((
hit.FS_segment()>>4) & 0x3)
225 <<
" ci: " << ((
hit.FS_segment()>>1) & 0x7) <<
" si: " << (
hit.FS_segment() & 0x1)
226 <<
" ph: " <<
hit.Phi_fp() <<
" th: " <<
hit.Theta_fp()
239 std::vector<hit_sort_pair_t>& phi_differences
243 int max_ph_diff = (station == 1) ? 15 : 7;
252 }
else if (station == 2) {
266 auto abs_diff = [](
int a,
int b) {
return std::abs(a-
b); };
271 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
272 return lhs.first <= rhs.first;
279 int operator()(
const value_type& a,
const value_type&
b,
const value_type&
c)
const {
281 r |=
bool(a.first <= b.first);
283 r |=
bool(b.first <= c.first);
285 r |=
bool(c.first <= a.first);
290 case 0b001 : rr = 2;
break;
291 case 0b010 : rr = 1;
break;
292 case 0b011 : rr = 1;
break;
293 case 0b100 : rr = 0;
break;
294 case 0b101 : rr = 2;
break;
295 case 0b110 : rr = 0;
break;
297 default : rr = 0;
break;
307 EMTFRoadCollection::const_iterator roads_it = roads.begin();
308 EMTFRoadCollection::const_iterator roads_end = roads.end();
310 for (; roads_it != roads_end; ++roads_it) {
311 int ph_pat = roads_it->Key_zhit();
312 int ph_q = roads_it->Quality_code();
313 if (not(ph_pat >= 0 && ph_q > 0))
314 {
edm::LogError(
"L1T") <<
"ph_pat = " << ph_pat <<
", ph_q = " << ph_q;
return; }
320 std::vector<hit_sort_pair_t> tmp_phi_differences;
322 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
323 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
325 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
326 int ph_seg = conv_hits_it->Phi_fp();
327 int ph_seg_red = ph_seg >> (bw_fph-bpow-1);
328 if (not(ph_seg >= 0))
336 int ph_diff = abs_diff(ph_pat, ph_seg_red);
337 if (ph_diff > max_ph_diff)
338 ph_diff = invalid_ph_diff;
340 if (ph_diff != invalid_ph_diff)
341 tmp_phi_differences.push_back(std::make_pair(ph_diff, conv_hits_it));
347 if (!tmp_phi_differences.empty()) {
351 bool use_fw_sorting =
true;
355 if (use_fw_sorting) {
358 const int max_drift = 3;
359 const int zone_cham = ((zone == 1 && (2 <= station && station <= 4)) || (zone == 2 && station == 2)) ? 4 : 7;
360 const int seg_ch = 2;
361 const int tot_diff = (max_drift*zone_cham*seg_ch) + ((zone_cham == 4) ? 3 : 12);
363 std::vector<hit_sort_pair_t> fw_sort_array(tot_diff, std::make_pair(invalid_ph_diff, conv_hits_end));
366 std::vector<hit_sort_pair_t>::const_iterator phdiffs_it = tmp_phi_differences.begin();
367 std::vector<hit_sort_pair_t>::const_iterator phdiffs_end = tmp_phi_differences.end();
369 for (; phdiffs_it != phdiffs_end; ++phdiffs_it) {
371 int fs_segment = phdiffs_it->second->FS_segment();
374 int fs_history = ((fs_segment>>4) & 0x3);
375 int fs_chamber = ((fs_segment>>1) & 0x7);
376 fs_segment = (fs_segment & 0x1);
377 unsigned fw_sort_array_index = (fs_history * zone_cham * seg_ch) + (fs_chamber * seg_ch) + fs_segment;
379 if (not(fs_history < max_drift && fs_chamber < zone_cham && fs_segment < seg_ch))
380 {
edm::LogError(
"L1T") <<
"fs_history = " << fs_history <<
", max_drift = " << max_drift
381 <<
", fs_chamber = " << fs_chamber <<
", zone_cham = " << zone_cham
382 <<
", fs_segment = " << fs_segment <<
", seg_ch = " << seg_ch;
return; }
383 if (not(fw_sort_array_index < fw_sort_array.size()))
384 {
edm::LogError(
"L1T") <<
"fw_sort_array_index = " << fw_sort_array_index
385 <<
", fw_sort_array.size() = " << fw_sort_array.size();
return; }
386 fw_sort_array.at(fw_sort_array_index) = *phdiffs_it;
403 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));
406 phi_differences.push_back(fw_sort_array.front());
417 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
419 if (lhs.second->Subsystem() != rhs.second->Subsystem())
422 return lhs.first <= rhs.first;
424 } tmp_less_ph_diff_cmp;
427 std::stable_sort(tmp_phi_differences.begin(), tmp_phi_differences.end(), tmp_less_ph_diff_cmp);
430 phi_differences.push_back(tmp_phi_differences.front());
435 phi_differences.push_back(std::make_pair(invalid_ph_diff, conv_hits_end));
445 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
446 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
449 (conv_hit_ptr->Station() == 1) && (conv_hit_ptr->Ring() == 1 || conv_hit_ptr->Ring() == 4);
452 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
453 const EMTFHit& conv_hit_i = *conv_hits_it;
454 const EMTFHit& conv_hit_j = *conv_hit_ptr;
461 (conv_hit_i.
Ring() == conv_hit_j.
Ring()) &&
465 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
474 <<
", conv_hit_j.Phi_fp() = " << conv_hit_j.
Phi_fp();
return; }
487 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
510 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
511 return lhs.Station() < rhs.Station();
516 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)