9 const int invalid_ph_diff = 0x1ff;
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);
52 for (
const auto& roads : zone_roads)
53 num_roads += roads.size();
54 bool early_exit = (num_roads == 0);
60 for (
const auto& roads : zone_roads) {
61 for (
const auto& road : roads) {
62 std::cout <<
"pattern on match input: z: " << road.Zone() - 1 <<
" r: " << road.Winner()
63 <<
" ph_num: " << road.Key_zhit() <<
" ph_q: " <<
to_hex(road.Quality_code())
64 <<
" ly: " << to_binary(road.Layer_code(), 3) <<
" str: " << to_binary(road.Straightness(), 3)
71 std::array<EMTFHitCollection, emtf::NUM_ZONES * emtf::NUM_STATIONS> zs_conv_hits;
73 bool use_fs_zone_code =
true;
75 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
76 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
78 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
79 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
80 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
82 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
83 int istation = conv_hits_it->Station() - 1;
84 int zone_code = conv_hits_it->Zone_code();
86 zone_code = conv_hits_it->FS_zone_code();
90 if (!zone_roads.at(izone).empty()) {
91 if (zone_code & (1 << izone)) {
93 zs_conv_hits.at(zs).push_back(*conv_hits_it);
97 EMTFHit& conv_hit = zs_conv_hits.at(zs).back();
99 int new_fs_segment = update_fs_history(old_fs_segment,
bx_, conv_hit.
BX());
103 int new_bt_segment = update_bt_history(old_bt_segment,
bx_, conv_hit.
BX());
116 for (
const auto& conv_hit : zs_conv_hits.at(zs)) {
117 std::cout <<
"z: " << izone <<
" st: " << istation + 1 <<
" cscid: " << conv_hit.CSC_ID()
118 <<
" ph_zone_phi: " << conv_hit.Zone_hit() <<
" ph_low_prec: " << (conv_hit.Zone_hit() << 5)
119 <<
" ph_high_prec: " << conv_hit.Phi_fp()
120 <<
" ph_high_low_diff: " << (conv_hit.Phi_fp() - (conv_hit.Zone_hit() << 5)) << std::endl;
139 izone + 1, istation + 1, zone_roads.at(izone), zs_conv_hits.at(zs), zs_phi_differences.at(zs));
140 emtf_assert(zone_roads.at(izone).size() == zs_phi_differences.at(zs).size());
146 const auto& roads = zone_roads.at(izone);
147 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
148 const auto& road = roads.at(iroad);
151 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
152 std::cout <<
"find seg: z: " << road.Zone() - 1 <<
" r: " << road.Winner() <<
" st: " << istation
153 <<
" ph_diff: " << ph_diff << std::endl;
163 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
164 const EMTFRoad& road = roads.at(iroad);
185 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
186 hit_ptr_t conv_hit_ptr = zs_phi_differences.at(zs).at(iroad).second;
188 if (ph_diff != invalid_ph_diff) {
200 zone_tracks.at(izone).push_back(
track);
206 for (
const auto&
tracks : zone_tracks) {
208 for (
const auto&
hit :
track.Hits()) {
209 std::cout <<
"match seg: z: " <<
track.Zone() - 1 <<
" pat: " <<
track.Winner() <<
" st: " <<
hit.Station()
210 <<
" vi: " << to_binary(0
b1, 2) <<
" hi: " << ((
hit.FS_segment() >> 4) & 0x3)
211 <<
" ci: " << ((
hit.FS_segment() >> 1) & 0x7) <<
" si: " << (
hit.FS_segment() & 0x1)
212 <<
" ph: " <<
hit.Phi_fp() <<
" th: " <<
hit.Theta_fp() << std::endl;
223 std::vector<hit_sort_pair_t>& phi_differences)
const {
226 int max_ph_diff = (
station == 1) ? 15 : 7;
249 auto abs_diff = [](
int a,
int b) {
return std::abs(
a -
b); };
254 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.first <= rhs.first; }
301 EMTFRoadCollection::const_iterator roads_it = roads.begin();
302 EMTFRoadCollection::const_iterator roads_end = roads.end();
304 for (; roads_it != roads_end; ++roads_it) {
305 int ph_pat = roads_it->Key_zhit();
306 int ph_q = roads_it->Quality_code();
313 std::vector<hit_sort_pair_t> tmp_phi_differences;
315 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
316 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
318 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
319 int ph_seg = conv_hits_it->Phi_fp();
320 int ph_seg_red = ph_seg >> (bw_fph - bpow - 1);
328 int ph_diff = abs_diff(ph_pat, ph_seg_red);
329 if (ph_diff > max_ph_diff)
330 ph_diff = invalid_ph_diff;
332 if (ph_diff != invalid_ph_diff)
333 tmp_phi_differences.push_back(std::make_pair(ph_diff, conv_hits_it));
339 if (!tmp_phi_differences.empty()) {
343 bool use_fw_sorting =
true;
346 use_fw_sorting =
false;
348 if (use_fw_sorting) {
351 const int max_drift = 3;
352 const int zone_cham = ((zone == 1 && (2 <=
station &&
station <= 4)) || (zone == 2 &&
station == 2)) ? 4 : 7;
353 const int seg_ch = 2;
355 (max_drift * zone_cham * seg_ch) + ((zone_cham == 4) ? 3 : 12);
357 std::vector<hit_sort_pair_t> fw_sort_array(tot_diff, std::make_pair(invalid_ph_diff, conv_hits_end));
360 std::vector<hit_sort_pair_t>::const_iterator phdiffs_it = tmp_phi_differences.begin();
361 std::vector<hit_sort_pair_t>::const_iterator phdiffs_end = tmp_phi_differences.end();
363 for (; phdiffs_it != phdiffs_end; ++phdiffs_it) {
365 int fs_segment = phdiffs_it->second->FS_segment();
368 int fs_history = ((fs_segment >> 4) & 0x3);
369 int fs_chamber = ((fs_segment >> 1) & 0x7);
370 fs_segment = (fs_segment & 0x1);
371 unsigned fw_sort_array_index = (fs_history * zone_cham * seg_ch) + (fs_chamber * seg_ch) + fs_segment;
373 emtf_assert(fs_history < max_drift && fs_chamber < zone_cham && fs_segment < seg_ch);
374 emtf_assert(fw_sort_array_index < fw_sort_array.size());
375 fw_sort_array.at(fw_sort_array_index) = *phdiffs_it;
392 merge_sort3_with_hint(fw_sort_array.begin(),
396 ((tot_diff == 54) ? tot_diff / 2 : tot_diff / 3));
399 phi_differences.push_back(fw_sort_array.front());
412 if (lhs.second->Subsystem() != rhs.second->Subsystem())
415 return lhs.first <= rhs.first;
417 } tmp_less_ph_diff_cmp;
420 std::stable_sort(tmp_phi_differences.begin(), tmp_phi_differences.end(), tmp_less_ph_diff_cmp);
423 phi_differences.push_back(tmp_phi_differences.front());
428 phi_differences.push_back(std::make_pair(invalid_ph_diff, conv_hits_end));
437 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
438 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
440 const bool is_csc_me11 = (conv_hit_ptr->Subsystem() ==
L1TMuon::kCSC) && (conv_hit_ptr->Station() == 1) &&
441 (conv_hit_ptr->Ring() == 1 || conv_hit_ptr->Ring() == 4);
444 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
445 const EMTFHit& conv_hit_i = *conv_hits_it;
446 const EMTFHit& conv_hit_j = *conv_hit_ptr;
451 (conv_hit_i.
Ring() == conv_hit_j.
Ring()) &&
454 (conv_hit_i.
Pattern() == conv_hit_j.
Pattern()) && (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
455 ((conv_hit_i.
Is_RPC() ==
false) ||
463 track.push_Hit(conv_hit_i);
474 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
482 track.push_Hit(tmp_hit);
489 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.Station() < rhs.Station(); }
493 std::stable_sort(tmp_hits.begin(), tmp_hits.end(), less_station_cmp);
494 track.set_Hits(tmp_hits);
void process(const std::deque< EMTFHitCollection > &extended_conv_hits, const emtf::zone_array< EMTFRoadCollection > &zone_roads, emtf::zone_array< EMTFTrackCollection > &zone_tracks) const
static char to_hex(unsigned int i)
std::pair< int, hit_ptr_t > hit_sort_pair_t
l1t::EMTFHitCollection EMTFHitCollection
void set_theta_fp(int bits)
Container::value_type value_type
void set_bt_segment(int bits)
l1t::EMTFRoadCollection EMTFRoadCollection
std::array< T, NUM_ZONES > zone_array
Abs< T >::type abs(const T &t)
EMTFHitCollection::const_iterator hit_ptr_t
void set_fs_segment(int bits)
auto const & tracks
cannot be loose
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
constexpr int NUM_STATIONS
void insert_hits(hit_ptr_t conv_hit_ptr, const EMTFHitCollection &conv_hits, EMTFTrack &track) const
void configure(int verbose, int endcap, int sector, int bx, bool fixZonePhi, bool useNewZones, bool bugSt2PhDiff, bool bugME11Dupes)
static constexpr float b1