9 const int invalid_dtheta = (1<<bw_th) - 1;
10 const int invalid_dphi = (1<<bw_fph) - 1;
17 int thetaWindow,
int thetaWindowZone0,
18 bool bugME11Dupes,
bool bugAmbigThetaWin,
bool twoStationSameBX
40 EMTFTrackCollection::iterator tracks_it = tracks.begin();
41 EMTFTrackCollection::iterator tracks_end = tracks.end();
44 for (; tracks_it != tracks_end; ++tracks_it) {
53 tracks_it = tracks.begin();
54 tracks_end = tracks.end();
58 for (; tracks_it != tracks_end; ++tracks_it) {
64 for (
const auto&
tracks : zone_tracks) {
67 <<
" delta_ph: " << array_as_string(
track.PtLUT().delta_ph)
68 <<
" delta_th: " << array_as_string(
track.PtLUT().delta_th)
69 <<
" sign_ph: " << array_as_string(
track.PtLUT().sign_ph)
70 <<
" sign_th: " << array_as_string(
track.PtLUT().sign_th)
71 <<
" phi: " <<
track.Phi_fp()
72 <<
" theta: " <<
track.Theta_fp()
73 <<
" cpat: " << array_as_string(
track.PtLUT().cpattern)
74 <<
" v: " << array_as_string(
track.PtLUT().bt_vi)
75 <<
" h: " << array_as_string(
track.PtLUT().bt_hi)
76 <<
" c: " << array_as_string(
track.PtLUT().bt_ci)
77 <<
" s: " << array_as_string(
track.PtLUT().bt_si)
87 std::array<EMTFHitCollection, emtf::NUM_STATIONS> st_conv_hits;
90 for (
const auto& conv_hit : track.
Hits()) {
91 if ((conv_hit.Station() - 1) == istation) {
92 st_conv_hits.at(istation).push_back(conv_hit);
97 if (not(st_conv_hits.at(istation).size() <= 4))
98 {
edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
return; }
100 if (not(st_conv_hits.at(istation).size() <= 2))
101 {
edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
return; }
110 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_arr;
111 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_sign_arr;
112 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_arr;
113 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_sign_arr;
118 std::array<int, emtf::NUM_STATION_PAIRS> best_theta_arr;
119 std::array<int, emtf::NUM_STATION_PAIRS> best_phi_arr;
122 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr;
126 best_dtheta_arr .fill(invalid_dtheta);
127 best_dtheta_sign_arr .fill(1);
128 best_dphi_arr .fill(invalid_dphi);
129 best_dphi_sign_arr .fill(1);
130 best_phi_arr .fill(0);
131 best_theta_arr .fill(0);
132 best_dtheta_valid_arr.fill(
false);
135 auto abs_diff = [](
int a,
int b) {
return std::abs(a-
b); };
146 for (
const auto& conv_hitA : conv_hitsA) {
147 for (
const auto& conv_hitB : conv_hitsB) {
151 int thA = conv_hitA.Theta_fp();
152 int thB = conv_hitB.Theta_fp();
153 int dth = abs_diff(thA, thB);
154 int dth_sign = (thA <= thB);
155 if (not(thA != 0 && thB != 0))
156 {
edm::LogError(
"L1T") <<
"thA = " << thA <<
", thB = " << thB;
return; }
157 if (not(dth < invalid_dtheta))
158 {
edm::LogError(
"L1T") <<
"dth = " << dth <<
", invalid_dtheta = " << invalid_dtheta;
return; }
160 if (best_dtheta_arr.at(ipair) >= dth) {
161 best_dtheta_arr.at(ipair) = dth;
162 best_dtheta_sign_arr.at(ipair) = dth_sign;
163 best_dtheta_valid_arr.at(ipair) =
true;
168 best_theta_arr.at(ipair) = (ipair < 3) ? thB : thA;
172 int phA = conv_hitA.Phi_fp();
173 int phB = conv_hitB.Phi_fp();
174 int dph = abs_diff(phA, phB);
175 int dph_sign = (phA <= phB);
177 if (best_dphi_arr.at(ipair) >= dph) {
178 best_dphi_arr.at(ipair) = dph;
179 best_dphi_sign_arr.at(ipair) = dph_sign;
183 best_phi_arr.at(ipair) = (ipair < 3) ? phB : phA;
200 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr_1;
204 best_dtheta_valid_arr_1.at(ipair) = best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindowZone0_);
206 best_dtheta_valid_arr_1.at(ipair) = best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindow_);
211 int vmask1 = 0, vmask2 = 0, vmask3 = 0;
213 if (best_dtheta_valid_arr_1.at(0)) {
216 if (best_dtheta_valid_arr_1.at(1)) {
219 if (best_dtheta_valid_arr_1.at(2)) {
222 if (best_dtheta_valid_arr_1.at(3)) {
225 if (best_dtheta_valid_arr_1.at(4)) {
228 if (best_dtheta_valid_arr_1.at(5)) {
242 if ((vstat & vmask2) != 0 || vstat == 0)
244 if ((vstat & vmask3) != 0 || vstat == 0)
250 static const int trk_bld[64] = {
251 0b1111, 0b0111, 0b0111, 0b0111, 0b1011, 0b0011, 0b1110, 0b0011,
252 0b0111, 0b0111, 0b0111, 0b0111, 0b1011, 0b0011, 0b0011, 0b0011,
253 0b1011, 0b1101, 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011,
254 0b1011, 0b0011, 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011,
255 0b1101, 0b1101, 0b1110, 0b0101, 0b1110, 0b1001, 0b1110, 0b0110,
256 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b0110, 0b0110,
257 0b1101, 0b1101, 0b0101, 0b0101, 0b1001, 0b1001, 0b1010, 0b1100,
258 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b1010, 0b0000
264 unsigned dth_bad = 0b111111;
265 if (best_dtheta_valid_arr_1.at(0)) {
266 dth_bad &= (~(1 << 5));
268 if (best_dtheta_valid_arr_1.at(1)) {
269 dth_bad &= (~(1 << 2));
271 if (best_dtheta_valid_arr_1.at(2)) {
272 dth_bad &= (~(1 << 1));
274 if (best_dtheta_valid_arr_1.at(3)) {
275 dth_bad &= (~(1 << 4));
277 if (best_dtheta_valid_arr_1.at(4)) {
278 dth_bad &= (~(1 << 0));
280 if (best_dtheta_valid_arr_1.at(5)) {
281 dth_bad &= (~(1 << 3));
283 assert(dth_bad < 64);
286 vstat = trk_bld[dth_bad];
292 if ((vstat & (1 << istation)) == 0) {
293 st_conv_hits.at(istation).clear();
302 if ((vstat & (1<<1)) != 0) {
303 if (best_dtheta_valid_arr.at(0))
305 else if (best_dtheta_valid_arr.at(3))
307 else if (best_dtheta_valid_arr.at(4))
309 }
else if ((vstat & (1<<2)) != 0) {
310 if (best_dtheta_valid_arr.at(1))
312 else if (best_dtheta_valid_arr.at(5))
314 }
else if ((vstat & (1<<3)) != 0) {
315 if (best_dtheta_valid_arr.at(2))
347 if (best_pair != -1) {
348 phi_fp = best_phi_arr.at(best_pair);
349 theta_fp = best_theta_arr.at(best_pair);
350 if (not(theta_fp != 0))
351 {
edm::LogError(
"L1T") <<
"theta_fp = " << theta_fp;
return; }
358 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
363 less_dtheta_cmp.theta = theta_fp;
366 std::stable_sort(st_conv_hits.at(istation).begin(), st_conv_hits.at(istation).end(), less_dtheta_cmp);
367 if (st_conv_hits.at(istation).size() > 1)
368 st_conv_hits.at(istation).resize(1);
374 int old_rank = (track.
Rank() << 1);
376 (((old_rank >> 6) & 1) << 6) |
377 (((old_rank >> 4) & 1) << 4) |
378 (((old_rank >> 2) & 1) << 2) |
379 (((vstat >> 0) & 1) << 5) |
380 (((vstat >> 1) & 1) << 3) |
381 (((vstat >> 2) & 1) << 1) |
382 (((vstat >> 3) & 1) << 0)
386 (((vstat >> 0) & 1) << 3) |
387 (((vstat >> 1) & 1) << 2) |
388 (((vstat >> 2) & 1) << 1) |
389 (((vstat >> 3) & 1) << 0)
392 int mode_inv = vstat;
395 if (vstat == 0b0001 || vstat == 0b0010 || vstat == 0b0100 || vstat == 0b1000 || vstat == 0)
413 bool isOverlapping = !(station == 1 && ring == 3);
417 bool isEven = (chamber % 2 == 0);
420 result = (station < 3) ? isEven : !isEven;
429 ptlut_data.
sign_ph[
i] = best_dphi_sign_arr.at(
i);
430 ptlut_data.
delta_th[
i] = best_dtheta_arr.at(
i);
431 ptlut_data.
sign_th[
i] = best_dtheta_sign_arr.at(
i);
435 const auto&
v = st_conv_hits.at(
i);
436 ptlut_data.
cpattern[
i] =
v.empty() ? 0 :
v.front().Pattern();
437 ptlut_data.
fr[
i] =
v.empty() ? 0 : isFront(
v.front().Station(),
v.front().Ring(),
v.front().Chamber(),
v.front().Subsystem());
439 ptlut_data.
st1_ring2 =
v.empty() ? 0 : (
v.front().Station() == 1 && (
v.front().Ring() == 2 ||
v.front().Ring() == 3));
442 for (
int i = 0;
i < emtf::NUM_STATIONS+1; ++
i) {
450 const auto&
v = st_conv_hits.at(
i);
452 int bt_station =
v.front().BT_station();
453 if (not(0 <= bt_station && bt_station <= 4))
454 {
edm::LogError(
"L1T") <<
"bt_station = " << bt_station;
return; }
456 int bt_segment =
v.front().BT_segment();
457 ptlut_data.
bt_vi[bt_station] = 1;
458 ptlut_data.
bt_hi[bt_station] = (bt_segment >> 5) & 0x3;
459 ptlut_data.
bt_ci[bt_station] = (bt_segment >> 1) & 0xf;
460 ptlut_data.
bt_si[bt_station] = (bt_segment >> 0) & 0
x1;
483 flatten_container(st_conv_hits, tmp_hits);
490 if (not(delayBX >= 0))
492 std::vector<int>
counter(delayBX+1, 0);
494 for (
const auto& conv_hit : track.
Hits()) {
495 for (
int i = delayBX;
i >= 0;
i--) {
496 if (conv_hit.BX() <=
bx_ -
i)
501 int first_bx =
bx_ - delayBX;
503 for (
int i = delayBX;
i >= 0;
i--) {
504 if (counter.at(
i) >= 2) {
509 if (not(second_bx != 99))
510 {
edm::LogError(
"L1T") <<
"second_bx = " << second_bx;
return; }
524 bool operator()(
const value_type&
x)
const {
525 return (x.Rank() == 0);
532 bool operator()(
const value_type&
x)
const {
533 return (x.NumHits() == 2 && x.Hits().at(0).BX() != x.Hits().at(1).BX());
535 } two_station_mistime;
537 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), rank_zero_pred), tracks.end());
540 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), two_station_mistime), tracks.end());
543 for (
const auto&
track : tracks) {
544 if (not(!
track.Hits().empty()))
545 {
edm::LogError(
"L1T") <<
"track.Hits().empty() = " <<
track.Hits().empty();
return; }
static char to_hex(unsigned int i)
void calculate_bx(EMTFTrack &track) const
void set_second_bx(int bits)
void set_phi_fp(int bits)
void process(emtf::zone_array< EMTFTrackCollection > &zone_tracks) const
void set_first_bx(int bits)
Geom::Theta< T > theta() const
double calc_phi_loc_deg(int bits)
void calculate_angles(EMTFTrack &track, const int izone) const
void set_PtLUT(EMTFPtLUT bits)
l1t::EMTFTrackCollection EMTFTrackCollection
double calc_theta_deg_from_int(int theta_int)
Container::value_type value_type
void configure(int verbose, int endcap, int sector, int bx, int bxWindow, int thetaWindow, int thetaWindowZone0, bool bugME11Dupes, bool bugAmbigThetaWin, bool twoStationSameBX)
std::array< T, NUM_ZONES > zone_array
Abs< T >::type abs(const T &t)
l1t::EMTFHitCollection EMTFHitCollection
double calc_phi_glob_deg(double loc, int sector)
void set_theta_fp(int bits)
EMTFHitCollection Hits() const
void set_theta(float val)
double calc_eta_from_theta_deg(double theta_deg, int endcap)
static std::atomic< unsigned int > counter
void set_Hits(const EMTFHitCollection &hits)
void set_phi_loc(float val)
void set_phi_glob(float val)
void set_mode_inv(int bits)
void erase_tracks(EMTFTrackCollection &tracks) const