9 const int invalid_dtheta = (1 << bw_th) - 1;
10 const int invalid_dphi = (1 << bw_fph) - 1;
21 bool bugAmbigThetaWin,
22 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 <<
" rank: " <<
to_hex(
track.Rank()) <<
" 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) <<
" phi: " <<
track.Phi_fp()
71 <<
" theta: " <<
track.Theta_fp() <<
" cpat: " << array_as_string(
track.PtLUT().cpattern)
72 <<
" v: " << array_as_string(
track.PtLUT().bt_vi) <<
" h: " << array_as_string(
track.PtLUT().bt_hi)
73 <<
" c: " << array_as_string(
track.PtLUT().bt_ci) <<
" s: " << array_as_string(
track.PtLUT().bt_si)
82 std::array<EMTFHitCollection, emtf::NUM_STATIONS> st_conv_hits;
85 for (
const auto& conv_hit : track.
Hits()) {
86 if ((conv_hit.Station() - 1) == istation) {
87 st_conv_hits.at(istation).push_back(conv_hit);
92 if (not(st_conv_hits.at(istation).size() <= 4))
94 edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
98 if (not(st_conv_hits.at(istation).size() <= 2))
100 edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
106 edm::LogError(
"L1T") <<
"st_conv_hits.size() = " << st_conv_hits.size()
113 std::array<int, emtf::NUM_STATION_PAIRS>
115 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_sign_arr;
116 std::array<int, emtf::NUM_STATION_PAIRS>
118 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_sign_arr;
123 std::array<int, emtf::NUM_STATION_PAIRS> best_theta_arr;
124 std::array<int, emtf::NUM_STATION_PAIRS> best_phi_arr;
127 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr;
131 best_dtheta_arr.fill(invalid_dtheta);
132 best_dtheta_sign_arr.fill(1);
133 best_dphi_arr.fill(invalid_dphi);
134 best_dphi_sign_arr.fill(1);
135 best_phi_arr.fill(0);
136 best_theta_arr.fill(0);
137 best_dtheta_valid_arr.fill(
false);
140 auto abs_diff = [](
int a,
int b) {
return std::abs(a -
b); };
151 for (
const auto& conv_hitA : conv_hitsA) {
152 for (
const auto& conv_hitB : conv_hitsB) {
156 int thA = conv_hitA.Theta_fp();
157 int thB = conv_hitB.Theta_fp();
158 int dth = abs_diff(thA, thB);
159 int dth_sign = (thA <= thB);
160 if (not(thA != 0 && thB != 0)) {
161 edm::LogError(
"L1T") <<
"thA = " << thA <<
", thB = " << thB;
164 if (not(dth < invalid_dtheta)) {
165 edm::LogError(
"L1T") <<
"dth = " << dth <<
", invalid_dtheta = " << invalid_dtheta;
169 if (best_dtheta_arr.at(ipair) >= dth) {
170 best_dtheta_arr.at(ipair) = dth;
171 best_dtheta_sign_arr.at(ipair) = dth_sign;
172 best_dtheta_valid_arr.at(ipair) =
true;
177 best_theta_arr.at(ipair) = (ipair < 3) ? thB : thA;
181 int phA = conv_hitA.Phi_fp();
182 int phB = conv_hitB.Phi_fp();
183 int dph = abs_diff(phA, phB);
184 int dph_sign = (phA <= phB);
186 if (best_dphi_arr.at(ipair) >= dph) {
187 best_dphi_arr.at(ipair) = dph;
188 best_dphi_sign_arr.at(ipair) = dph_sign;
192 best_phi_arr.at(ipair) = (ipair < 3) ? phB : phA;
210 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr_1;
214 best_dtheta_valid_arr_1.at(ipair) =
215 best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindowZone0_);
217 best_dtheta_valid_arr_1.at(ipair) =
218 best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindow_);
223 int vmask1 = 0, vmask2 = 0, vmask3 = 0;
225 if (best_dtheta_valid_arr_1.at(0)) {
228 if (best_dtheta_valid_arr_1.at(1)) {
231 if (best_dtheta_valid_arr_1.at(2)) {
234 if (best_dtheta_valid_arr_1.at(3)) {
237 if (best_dtheta_valid_arr_1.at(4)) {
240 if (best_dtheta_valid_arr_1.at(5)) {
254 if ((vstat & vmask2) != 0 || vstat == 0)
256 if ((vstat & vmask3) != 0 || vstat == 0)
261 static const int trk_bld[64] = {
262 0b1111, 0b0111, 0b0111, 0b0111, 0b1011, 0b0011, 0b1110, 0b0011, 0b0111, 0b0111, 0b0111, 0b0111, 0b1011,
263 0b0011, 0b0011, 0b0011, 0b1011, 0b1101, 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011, 0b1011, 0b0011,
264 0b0011, 0b0011, 0b1011, 0b0011, 0b0011, 0b0011, 0b1101, 0b1101, 0b1110, 0b0101, 0b1110, 0b1001, 0b1110,
265 0b0110, 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b0110, 0b0110, 0b1101, 0b1101, 0b0101, 0b0101,
266 0b1001, 0b1001, 0b1010, 0b1100, 0b0101, 0b0101, 0b0101, 0b0101, 0b1001, 0b1001, 0b1010, 0b0000};
271 unsigned dth_bad = 0b111111;
272 if (best_dtheta_valid_arr_1.at(0)) {
273 dth_bad &= (~(1 << 5));
275 if (best_dtheta_valid_arr_1.at(1)) {
276 dth_bad &= (~(1 << 2));
278 if (best_dtheta_valid_arr_1.at(2)) {
279 dth_bad &= (~(1 << 1));
281 if (best_dtheta_valid_arr_1.at(3)) {
282 dth_bad &= (~(1 << 4));
284 if (best_dtheta_valid_arr_1.at(4)) {
285 dth_bad &= (~(1 << 0));
287 if (best_dtheta_valid_arr_1.at(5)) {
288 dth_bad &= (~(1 << 3));
290 assert(dth_bad < 64);
293 vstat = trk_bld[dth_bad];
298 if ((vstat & (1 << istation)) == 0) {
299 st_conv_hits.at(istation).clear();
308 if ((vstat & (1 << 1)) != 0) {
309 if (best_dtheta_valid_arr.at(0))
311 else if (best_dtheta_valid_arr.at(3))
313 else if (best_dtheta_valid_arr.at(4))
315 }
else if ((vstat & (1 << 2)) != 0) {
316 if (best_dtheta_valid_arr.at(1))
318 else if (best_dtheta_valid_arr.at(5))
320 }
else if ((vstat & (1 << 3)) != 0) {
321 if (best_dtheta_valid_arr.at(2))
353 if (best_pair != -1) {
354 phi_fp = best_phi_arr.at(best_pair);
355 theta_fp = best_theta_arr.at(best_pair);
356 if (not(theta_fp != 0)) {
366 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
371 less_dtheta_cmp.theta = theta_fp;
374 std::stable_sort(st_conv_hits.at(istation).begin(), st_conv_hits.at(istation).end(), less_dtheta_cmp);
375 if (st_conv_hits.at(istation).size() > 1)
376 st_conv_hits.at(istation).resize(1);
382 int old_rank = (track.
Rank() << 1);
383 int rank = ((((old_rank >> 6) & 1) << 6) |
384 (((old_rank >> 4) & 1) << 4) |
385 (((old_rank >> 2) & 1) << 2) |
386 (((vstat >> 0) & 1) << 5) |
387 (((vstat >> 1) & 1) << 3) |
388 (((vstat >> 2) & 1) << 1) |
389 (((vstat >> 3) & 1) << 0)
392 int mode = ((((vstat >> 0) & 1) << 3) |
393 (((vstat >> 1) & 1) << 2) |
394 (((vstat >> 2) & 1) << 1) |
395 (((vstat >> 3) & 1) << 0)
398 int mode_inv = vstat;
401 if (vstat == 0b0001 || vstat == 0b0010 || vstat == 0b0100 || vstat == 0b1000 || vstat == 0)
418 bool isOverlapping = !(station == 1 && ring == 3);
421 bool isEven = (chamber % 2 == 0);
424 result = (station < 3) ? isEven : !isEven;
433 ptlut_data.
sign_ph[
i] = best_dphi_sign_arr.at(
i);
434 ptlut_data.
delta_th[
i] = best_dtheta_arr.at(
i);
435 ptlut_data.
sign_th[
i] = best_dtheta_sign_arr.at(
i);
439 const auto&
v = st_conv_hits.at(
i);
440 ptlut_data.
cpattern[
i] =
v.empty() ? 0 :
v.front().Pattern();
442 v.empty() ? 0 : isFront(
v.front().Station(),
v.front().Ring(),
v.front().Chamber(),
v.front().Subsystem());
445 v.empty() ? 0 : (
v.front().Station() == 1 && (
v.front().Ring() == 2 ||
v.front().Ring() == 3));
448 for (
int i = 0;
i < emtf::NUM_STATIONS + 1; ++
i) {
456 const auto&
v = st_conv_hits.at(
i);
458 int bt_station =
v.front().BT_station();
459 if (not(0 <= bt_station && bt_station <= 4)) {
464 int bt_segment =
v.front().BT_segment();
465 ptlut_data.
bt_vi[bt_station] = 1;
466 ptlut_data.
bt_hi[bt_station] = (bt_segment >> 5) & 0x3;
467 ptlut_data.
bt_ci[bt_station] = (bt_segment >> 1) & 0xf;
468 ptlut_data.
bt_si[bt_station] = (bt_segment >> 0) & 0
x1;
491 flatten_container(st_conv_hits, tmp_hits);
497 if (not(delayBX >= 0)) {
501 std::vector<int>
counter(delayBX + 1, 0);
503 for (
const auto& conv_hit : track.
Hits()) {
504 for (
int i = delayBX;
i >= 0;
i--) {
505 if (conv_hit.BX() <=
bx_ -
i)
510 int first_bx =
bx_ - delayBX;
512 for (
int i = delayBX;
i >= 0;
i--) {
513 if (counter.at(
i) >= 2) {
518 if (not(second_bx != 99)) {
535 bool operator()(
const value_type&
x)
const {
return (x.Rank() == 0); }
541 bool operator()(
const value_type&
x)
const {
542 return (x.NumHits() == 2 && x.Hits().at(0).BX() != x.Hits().at(1).BX());
544 } two_station_mistime;
546 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), rank_zero_pred), tracks.end());
549 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), two_station_mistime), tracks.end());
552 for (
const auto&
track : tracks) {
553 if (not(!
track.Hits().empty())) {
static char to_hex(unsigned int i)
l1t::EMTFTrackCollection EMTFTrackCollection
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)
l1t::EMTFHitCollection EMTFHitCollection
void calculate_angles(EMTFTrack &track, const int izone) const
void set_PtLUT(EMTFPtLUT bits)
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)
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