8 const int invalid_dtheta = (1 << bw_th) - 1;
9 const int invalid_dphi = (1 << bw_fph) - 1;
20 bool bugAmbigThetaWin,
21 bool twoStationSameBX) {
39 EMTFTrackCollection::iterator tracks_it =
tracks.begin();
40 EMTFTrackCollection::iterator tracks_end =
tracks.end();
43 for (; tracks_it != tracks_end; ++tracks_it) {
52 tracks_it =
tracks.begin();
57 for (; tracks_it != tracks_end; ++tracks_it) {
63 for (
const auto&
tracks : zone_tracks) {
66 <<
" rank: " <<
to_hex(
track.Rank()) <<
" delta_ph: " << array_as_string(
track.PtLUT().delta_ph)
67 <<
" delta_th: " << array_as_string(
track.PtLUT().delta_th)
68 <<
" sign_ph: " << array_as_string(
track.PtLUT().sign_ph)
69 <<
" sign_th: " << array_as_string(
track.PtLUT().sign_th) <<
" phi: " <<
track.Phi_fp()
70 <<
" theta: " <<
track.Theta_fp() <<
" cpat: " << array_as_string(
track.PtLUT().cpattern)
71 <<
" v: " << array_as_string(
track.PtLUT().bt_vi) <<
" h: " << array_as_string(
track.PtLUT().bt_hi)
72 <<
" c: " << array_as_string(
track.PtLUT().bt_ci) <<
" s: " << array_as_string(
track.PtLUT().bt_si)
81 std::array<EMTFHitCollection, emtf::NUM_STATIONS> st_conv_hits;
84 for (
const auto& conv_hit :
track.Hits()) {
85 if ((conv_hit.Station() - 1) == istation) {
86 st_conv_hits.at(istation).push_back(conv_hit);
100 std::array<int, emtf::NUM_STATION_PAIRS>
102 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_sign_arr;
103 std::array<int, emtf::NUM_STATION_PAIRS>
105 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_sign_arr;
110 std::array<int, emtf::NUM_STATION_PAIRS> best_theta_arr;
111 std::array<int, emtf::NUM_STATION_PAIRS> best_phi_arr;
114 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr;
118 best_dtheta_arr.fill(invalid_dtheta);
119 best_dtheta_sign_arr.fill(1);
120 best_dphi_arr.fill(invalid_dphi);
121 best_dphi_sign_arr.fill(1);
122 best_phi_arr.fill(0);
123 best_theta_arr.fill(0);
124 best_dtheta_valid_arr.fill(
false);
127 auto abs_diff = [](
int a,
int b) {
return std::abs(
a -
b); };
138 for (
const auto& conv_hitA : conv_hitsA) {
139 for (
const auto& conv_hitB : conv_hitsB) {
143 int thA = conv_hitA.Theta_fp();
144 int thB = conv_hitB.Theta_fp();
145 int dth = abs_diff(thA, thB);
146 int dth_sign = (thA <= thB);
150 if (best_dtheta_arr.at(ipair) >= dth) {
151 best_dtheta_arr.at(ipair) = dth;
152 best_dtheta_sign_arr.at(ipair) = dth_sign;
153 best_dtheta_valid_arr.at(ipair) =
true;
158 best_theta_arr.at(ipair) = (ipair < 3) ? thB : thA;
162 int phA = conv_hitA.Phi_fp();
163 int phB = conv_hitB.Phi_fp();
164 int dph = abs_diff(phA, phB);
165 int dph_sign = (phA <= phB);
167 if (best_dphi_arr.at(ipair) >= dph) {
168 best_dphi_arr.at(ipair) = dph;
169 best_dphi_sign_arr.at(ipair) = dph_sign;
173 best_phi_arr.at(ipair) = (ipair < 3) ? phB : phA;
188 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr_1;
192 best_dtheta_valid_arr_1.at(ipair) =
193 best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindowZone0_);
195 best_dtheta_valid_arr_1.at(ipair) =
196 best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindow_);
201 int vmask1 = 0, vmask2 = 0, vmask3 = 0;
203 if (best_dtheta_valid_arr_1.at(0)) {
206 if (best_dtheta_valid_arr_1.at(1)) {
209 if (best_dtheta_valid_arr_1.at(2)) {
212 if (best_dtheta_valid_arr_1.at(3)) {
215 if (best_dtheta_valid_arr_1.at(4)) {
218 if (best_dtheta_valid_arr_1.at(5)) {
232 if ((vstat & vmask2) != 0 || vstat == 0)
234 if ((vstat & vmask3) != 0 || vstat == 0)
239 static const int trk_bld[64] = {
240 0b1111, 0b0111, 0b0111, 0b0111, 0b1011, 0b0011, 0b1110, 0b0011, 0b0111, 0b0111, 0b0111, 0b0111, 0b1011,
241 0b0011, 0b0011, 0b0011, 0b1011, 0b1101, 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011, 0b1011, 0b0011,
242 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011, 0b1101, 0b1101, 0b1110, 0b0101, 0b1110, 0b1001, 0b1110,
243 0b0110, 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b0110, 0b0110, 0b1101, 0b1101, 0b0101, 0b0101,
244 0b1001, 0b1001, 0b1010, 0b1100, 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b1010, 0b0000};
249 unsigned dth_bad = 0b111111;
250 if (best_dtheta_valid_arr_1.at(0)) {
251 dth_bad &= (~(1 << 5));
253 if (best_dtheta_valid_arr_1.at(1)) {
254 dth_bad &= (~(1 << 2));
256 if (best_dtheta_valid_arr_1.at(2)) {
257 dth_bad &= (~(1 << 1));
259 if (best_dtheta_valid_arr_1.at(3)) {
260 dth_bad &= (~(1 << 4));
262 if (best_dtheta_valid_arr_1.at(4)) {
263 dth_bad &= (~(1 << 0));
265 if (best_dtheta_valid_arr_1.at(5)) {
266 dth_bad &= (~(1 << 3));
271 vstat = trk_bld[dth_bad];
276 if ((vstat & (1 << istation)) == 0) {
277 st_conv_hits.at(istation).clear();
286 if ((vstat & (1 << 1)) != 0) {
287 if (best_dtheta_valid_arr.at(0))
289 else if (best_dtheta_valid_arr.at(3))
291 else if (best_dtheta_valid_arr.at(4))
293 }
else if ((vstat & (1 << 2)) != 0) {
294 if (best_dtheta_valid_arr.at(1))
296 else if (best_dtheta_valid_arr.at(5))
298 }
else if ((vstat & (1 << 3)) != 0) {
299 if (best_dtheta_valid_arr.at(2))
331 if (best_pair != -1) {
332 phi_fp = best_phi_arr.at(best_pair);
333 theta_fp = best_theta_arr.at(best_pair);
346 less_dtheta_cmp.theta = theta_fp;
349 std::stable_sort(st_conv_hits.at(istation).begin(), st_conv_hits.at(istation).end(), less_dtheta_cmp);
350 if (st_conv_hits.at(istation).size() > 1)
351 st_conv_hits.at(istation).resize(1);
357 int old_rank = (
track.Rank() << 1);
358 int rank = ((((old_rank >> 6) & 1) << 6) |
359 (((old_rank >> 4) & 1) << 4) |
360 (((old_rank >> 2) & 1) << 2) |
361 (((vstat >> 0) & 1) << 5) |
362 (((vstat >> 1) & 1) << 3) |
363 (((vstat >> 2) & 1) << 1) |
364 (((vstat >> 3) & 1) << 0)
367 int mode = ((((vstat >> 0) & 1) << 3) |
368 (((vstat >> 1) & 1) << 2) |
369 (((vstat >> 2) & 1) << 1) |
370 (((vstat >> 3) & 1) << 0)
373 int mode_inv = vstat;
376 if (vstat == 0b0001 || vstat == 0b0010 || vstat == 0b0100 || vstat == 0b1000 || vstat == 0)
396 bool isEven = (
chamber % 2 == 0);
408 ptlut_data.
sign_ph[
i] = best_dphi_sign_arr.at(
i);
409 ptlut_data.
delta_th[
i] = best_dtheta_arr.at(
i);
410 ptlut_data.
sign_th[
i] = best_dtheta_sign_arr.at(
i);
414 const auto&
v = st_conv_hits.at(
i);
415 ptlut_data.
cpattern[
i] =
v.empty() ? 0 :
v.front().Pattern();
417 v.empty() ? 0 : isFront(
v.front().Station(),
v.front().Ring(),
v.front().Chamber(),
v.front().Subsystem());
420 v.empty() ? 0 : (
v.front().Station() == 1 && (
v.front().Ring() == 2 ||
v.front().Ring() == 3));
431 const auto&
v = st_conv_hits.at(
i);
433 int bt_station =
v.front().BT_station();
436 int bt_segment =
v.front().BT_segment();
437 ptlut_data.
bt_vi[bt_station] = 1;
438 ptlut_data.
bt_hi[bt_station] = (bt_segment >> 5) & 0x3;
439 ptlut_data.
bt_ci[bt_station] = (bt_segment >> 1) & 0xf;
440 ptlut_data.
bt_si[bt_station] = (bt_segment >> 0) & 0
x1;
447 track.set_rank(rank);
449 track.set_mode_inv(mode_inv);
450 track.set_phi_fp(phi_fp);
451 track.set_theta_fp(theta_fp);
452 track.set_PtLUT(ptlut_data);
463 flatten_container(st_conv_hits, tmp_hits);
464 track.set_Hits(tmp_hits);
470 std::vector<int>
counter(delayBX + 1, 0);
472 for (
const auto& conv_hit :
track.Hits()) {
473 for (
int i = delayBX;
i >= 0;
i--) {
474 if (conv_hit.BX() <=
bx_ -
i)
479 int first_bx =
bx_ - delayBX;
481 for (
int i = delayBX;
i >= 0;
i--) {
492 track.set_first_bx(first_bx);
493 track.set_second_bx(second_bx);
501 bool operator()(
const value_type&
x)
const {
return (
x.Rank() == 0); }
508 return (
x.NumHits() == 2 &&
x.Hits().at(0).BX() !=
x.Hits().at(1).BX());
510 } two_station_mistime;