8 const int invalid_ph_diff = 0x1ff;
34 auto update_fs_history = [](
int fs_segment,
int this_bx,
int hit_bx) {
36 int fs_history = this_bx - hit_bx;
37 fs_segment |= ((fs_history & 0x3) << 4);
42 auto update_bt_history = [](
int bt_segment,
int this_bx,
int hit_bx) {
44 int bt_history = this_bx - hit_bx;
45 bt_segment |= ((bt_history & 0x3) << 5);
51 for (
const auto& roads : zone_roads)
52 num_roads += roads.size();
53 bool early_exit = (num_roads == 0);
59 for (
const auto& roads : zone_roads) {
60 for (
const auto& road : roads) {
61 std::cout <<
"pattern on match input: z: " << road.Zone() - 1 <<
" r: " << road.Winner()
62 <<
" ph_num: " << road.Key_zhit() <<
" ph_q: " <<
to_hex(road.Quality_code())
63 <<
" ly: " << to_binary(road.Layer_code(), 3) <<
" str: " << to_binary(road.Straightness(), 3)
70 std::array<EMTFHitCollection, emtf::NUM_ZONES * emtf::NUM_STATIONS> zs_conv_hits;
72 bool use_fs_zone_code =
true;
74 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_it = extended_conv_hits.begin();
75 std::deque<EMTFHitCollection>::const_iterator ext_conv_hits_end = extended_conv_hits.end();
77 for (; ext_conv_hits_it != ext_conv_hits_end; ++ext_conv_hits_it) {
78 EMTFHitCollection::const_iterator conv_hits_it = ext_conv_hits_it->begin();
79 EMTFHitCollection::const_iterator conv_hits_end = ext_conv_hits_it->end();
81 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
82 int istation = conv_hits_it->Station() - 1;
83 int zone_code = conv_hits_it->Zone_code();
85 zone_code = conv_hits_it->FS_zone_code();
89 if (!zone_roads.at(izone).empty()) {
90 if (zone_code & (1 << izone)) {
92 zs_conv_hits.at(zs).push_back(*conv_hits_it);
96 EMTFHit& conv_hit = zs_conv_hits.at(zs).back();
98 int new_fs_segment = update_fs_history(old_fs_segment,
bx_, conv_hit.
BX());
102 int new_bt_segment = update_bt_history(old_bt_segment,
bx_, conv_hit.
BX());
115 for (
const auto& conv_hit : zs_conv_hits.at(zs)) {
116 std::cout <<
"z: " << izone <<
" st: " << istation + 1 <<
" cscid: " << conv_hit.CSC_ID()
117 <<
" ph_zone_phi: " << conv_hit.Zone_hit() <<
" ph_low_prec: " << (conv_hit.Zone_hit() << 5)
118 <<
" ph_high_prec: " << conv_hit.Phi_fp()
119 <<
" ph_high_low_diff: " << (conv_hit.Phi_fp() - (conv_hit.Zone_hit() << 5)) << std::endl;
138 izone + 1, istation + 1, zone_roads.at(izone), zs_conv_hits.at(zs), zs_phi_differences.at(zs));
139 emtf_assert(zone_roads.at(izone).size() == zs_phi_differences.at(zs).size());
145 const auto& roads = zone_roads.at(izone);
146 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
147 const auto& road = roads.at(iroad);
150 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
151 std::cout <<
"find seg: z: " << road.Zone() - 1 <<
" r: " << road.Winner() <<
" st: " << istation
152 <<
" ph_diff: " << ph_diff << std::endl;
162 for (
unsigned iroad = 0; iroad < roads.size(); ++iroad) {
163 const EMTFRoad& road = roads.at(iroad);
184 int ph_diff = zs_phi_differences.at(zs).at(iroad).first;
185 hit_ptr_t conv_hit_ptr = zs_phi_differences.at(zs).at(iroad).second;
187 if (ph_diff != invalid_ph_diff) {
199 zone_tracks.at(izone).push_back(
track);
205 for (
const auto&
tracks : zone_tracks) {
207 for (
const auto&
hit :
track.Hits()) {
208 std::cout <<
"match seg: z: " <<
track.Zone() - 1 <<
" pat: " <<
track.Winner() <<
" st: " <<
hit.Station()
209 <<
" vi: " << to_binary(0
b1, 2) <<
" hi: " << ((
hit.FS_segment() >> 4) & 0x3)
210 <<
" ci: " << ((
hit.FS_segment() >> 1) & 0x7) <<
" si: " << (
hit.FS_segment() & 0x1)
211 <<
" ph: " <<
hit.Phi_fp() <<
" th: " <<
hit.Theta_fp() << std::endl;
222 std::vector<hit_sort_pair_t>& phi_differences)
const {
225 int max_ph_diff = (
station == 1) ? 15 : 7;
248 auto abs_diff = [](
int a,
int b) {
return std::abs(
a -
b); };
253 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.first <= rhs.first; }
300 EMTFRoadCollection::const_iterator roads_it = roads.begin();
301 EMTFRoadCollection::const_iterator roads_end = roads.end();
303 for (; roads_it != roads_end; ++roads_it) {
304 int ph_pat = roads_it->Key_zhit();
305 int ph_q = roads_it->Quality_code();
312 std::vector<hit_sort_pair_t> tmp_phi_differences;
314 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
315 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
317 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
318 int ph_seg = conv_hits_it->Phi_fp();
319 int ph_seg_red = ph_seg >> (bw_fph - bpow - 1);
327 int ph_diff = abs_diff(ph_pat, ph_seg_red);
328 if (ph_diff > max_ph_diff)
329 ph_diff = invalid_ph_diff;
331 if (ph_diff != invalid_ph_diff)
332 tmp_phi_differences.push_back(std::make_pair(ph_diff, conv_hits_it));
338 if (!tmp_phi_differences.empty()) {
342 bool use_fw_sorting =
true;
345 use_fw_sorting =
false;
347 if (use_fw_sorting) {
350 const int max_drift = 3;
351 const int zone_cham = ((zone == 1 && (2 <=
station &&
station <= 4)) || (zone == 2 &&
station == 2)) ? 4 : 7;
352 const int seg_ch = 2;
354 (max_drift * zone_cham * seg_ch) + ((zone_cham == 4) ? 3 : 12);
356 std::vector<hit_sort_pair_t> fw_sort_array(tot_diff, std::make_pair(invalid_ph_diff, conv_hits_end));
359 std::vector<hit_sort_pair_t>::const_iterator phdiffs_it = tmp_phi_differences.begin();
360 std::vector<hit_sort_pair_t>::const_iterator phdiffs_end = tmp_phi_differences.end();
362 for (; phdiffs_it != phdiffs_end; ++phdiffs_it) {
364 int fs_segment = phdiffs_it->second->FS_segment();
367 int fs_history = ((fs_segment >> 4) & 0x3);
368 int fs_chamber = ((fs_segment >> 1) & 0x7);
369 fs_segment = (fs_segment & 0x1);
370 unsigned fw_sort_array_index = (fs_history * zone_cham * seg_ch) + (fs_chamber * seg_ch) + fs_segment;
372 emtf_assert(fs_history < max_drift && fs_chamber < zone_cham && fs_segment < seg_ch);
373 emtf_assert(fw_sort_array_index < fw_sort_array.size());
374 fw_sort_array.at(fw_sort_array_index) = *phdiffs_it;
391 merge_sort3_with_hint(fw_sort_array.begin(),
395 ((tot_diff == 54) ? tot_diff / 2 : tot_diff / 3));
398 phi_differences.push_back(fw_sort_array.front());
411 if (lhs.second->Subsystem() != rhs.second->Subsystem())
414 return lhs.first <= rhs.first;
416 } tmp_less_ph_diff_cmp;
419 std::stable_sort(tmp_phi_differences.begin(), tmp_phi_differences.end(), tmp_less_ph_diff_cmp);
422 phi_differences.push_back(tmp_phi_differences.front());
427 phi_differences.push_back(std::make_pair(invalid_ph_diff, conv_hits_end));
436 EMTFHitCollection::const_iterator conv_hits_it = conv_hits.begin();
437 EMTFHitCollection::const_iterator conv_hits_end = conv_hits.end();
439 const bool is_csc_me11 = (conv_hit_ptr->Subsystem() ==
TriggerPrimitive::kCSC) && (conv_hit_ptr->Station() == 1) &&
440 (conv_hit_ptr->Ring() == 1 || conv_hit_ptr->Ring() == 4);
443 for (; conv_hits_it != conv_hits_end; ++conv_hits_it) {
444 const EMTFHit& conv_hit_i = *conv_hits_it;
445 const EMTFHit& conv_hit_j = *conv_hit_ptr;
450 (conv_hit_i.
Ring() == conv_hit_j.
Ring()) &&
453 (conv_hit_i.
Pattern() == conv_hit_j.
Pattern()) && (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
454 ((conv_hit_i.
Is_RPC() ==
false) ||
462 track.push_Hit(conv_hit_i);
473 (conv_hit_i.
BX() == conv_hit_j.
BX()) &&
481 track.push_Hit(tmp_hit);
488 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
return lhs.Station() < rhs.Station(); }
492 std::stable_sort(tmp_hits.begin(), tmp_hits.end(), less_station_cmp);
493 track.set_Hits(tmp_hits);