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();
53 tracks_end = tracks.end();
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);
341 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
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)
393 bool isOverlapping = !(station == 1 && ring == 3);
396 bool isEven = (chamber % 2 == 0);
399 result = (station < 3) ? isEven : !isEven;
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();
416 ptlut_data.
csign[
i] =
v.empty() ? 0 :
v.front().Bend();
417 ptlut_data.
slope[
i] =
v.empty() ? 0 :
v.front().Slope();
419 v.empty() ? 0 : isFront(
v.front().Station(),
v.front().Ring(),
v.front().Chamber(),
v.front().Subsystem());
422 v.empty() ? 0 : (
v.front().Station() == 1 && (
v.front().Ring() == 2 ||
v.front().Ring() == 3));
425 for (
int i = 0;
i < emtf::NUM_STATIONS + 1; ++
i) {
433 const auto&
v = st_conv_hits.at(
i);
435 int bt_station =
v.front().BT_station();
438 int bt_segment =
v.front().BT_segment();
439 ptlut_data.
bt_vi[bt_station] = 1;
440 ptlut_data.
bt_hi[bt_station] = (bt_segment >> 5) & 0x3;
441 ptlut_data.
bt_ci[bt_station] = (bt_segment >> 1) & 0xf;
442 ptlut_data.
bt_si[bt_station] = (bt_segment >> 0) & 0x1;
465 flatten_container(st_conv_hits, tmp_hits);
472 std::vector<int>
counter(delayBX + 1, 0);
474 for (
const auto& conv_hit : track.
Hits()) {
475 for (
int i = delayBX;
i >= 0;
i--) {
476 if (conv_hit.BX() <=
bx_ -
i)
481 int first_bx =
bx_ - delayBX;
483 for (
int i = delayBX;
i >= 0;
i--) {
484 if (counter.at(
i) >= 2) {
503 bool operator()(
const value_type&
x)
const {
return (x.Rank() == 0); }
509 bool operator()(
const value_type&
x)
const {
510 return (x.NumHits() == 2 && x.Hits().at(0).BX() != x.Hits().at(1).BX());
512 } two_station_mistime;
514 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), rank_zero_pred), tracks.end());
517 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), two_station_mistime), tracks.end());
520 for (
const auto&
track : tracks) {
static char to_hex(unsigned int i)
l1t::EMTFTrackCollection EMTFTrackCollection
void calculate_bx(EMTFTrack &track) const
void set_second_bx(int bits)
constexpr int NUM_STATION_PAIRS
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)
auto const & tracks
cannot be loose
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
static constexpr int verbose
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)
constexpr int NUM_STATIONS
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