9 const int invalid_dtheta = (1<<bw_th) - 1;
10 const int invalid_dphi = (1<<bw_fph) - 1;
17 int thetaWindow,
int thetaWindowRPC,
38 EMTFTrackCollection::iterator tracks_it = tracks.begin();
39 EMTFTrackCollection::iterator tracks_end = tracks.end();
42 for (; tracks_it != tracks_end; ++tracks_it) {
50 tracks_it = tracks.begin();
51 tracks_end = tracks.end();
55 for (; tracks_it != tracks_end; ++tracks_it) {
61 for (
const auto&
tracks : zone_tracks) {
64 <<
" delta_ph: " << array_as_string(
track.PtLUT().delta_ph)
65 <<
" delta_th: " << array_as_string(
track.PtLUT().delta_th)
66 <<
" sign_ph: " << array_as_string(
track.PtLUT().sign_ph)
67 <<
" sign_th: " << array_as_string(
track.PtLUT().sign_th)
68 <<
" phi: " <<
track.Phi_fp()
69 <<
" theta: " <<
track.Theta_fp()
70 <<
" cpat: " << array_as_string(
track.PtLUT().cpattern)
71 <<
" v: " << array_as_string(
track.PtLUT().bt_vi)
72 <<
" h: " << array_as_string(
track.PtLUT().bt_hi)
73 <<
" c: " << array_as_string(
track.PtLUT().bt_ci)
74 <<
" s: " << array_as_string(
track.PtLUT().bt_si)
84 std::array<EMTFHitCollection, emtf::NUM_STATIONS> st_conv_hits;
87 for (
const auto& conv_hit : track.
Hits()) {
88 if ((conv_hit.Station() - 1) == istation) {
89 st_conv_hits.at(istation).push_back(conv_hit);
94 if (not (st_conv_hits.at(istation).size() <= 4))
95 {
edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
return; }
97 if (not (st_conv_hits.at(istation).size() <= 2))
98 {
edm::LogError(
"L1T") <<
"st_conv_hits.at(istation).size() = " << st_conv_hits.at(istation).size();
return; }
107 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_arr;
108 std::array<int, emtf::NUM_STATION_PAIRS> best_dtheta_sign_arr;
109 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_arr;
110 std::array<int, emtf::NUM_STATION_PAIRS> best_dphi_sign_arr;
115 std::array<int, emtf::NUM_STATION_PAIRS> best_theta_arr;
116 std::array<int, emtf::NUM_STATION_PAIRS> best_phi_arr;
119 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr;
120 std::array<bool, emtf::NUM_STATION_PAIRS> best_has_rpc_arr;
123 best_dtheta_arr .fill(invalid_dtheta);
124 best_dtheta_sign_arr .fill(1);
125 best_dphi_arr .fill(invalid_dphi);
126 best_dphi_sign_arr .fill(1);
127 best_phi_arr .fill(0);
128 best_theta_arr .fill(0);
129 best_dtheta_valid_arr.fill(
false);
130 best_has_rpc_arr .fill(
false);
132 auto abs_diff = [](
int a,
int b) {
return std::abs(a-
b); };
143 for (
const auto& conv_hitA : conv_hitsA) {
144 for (
const auto& conv_hitB : conv_hitsB) {
149 int thA = conv_hitA.Theta_fp();
150 int thB = conv_hitB.Theta_fp();
151 int dth = abs_diff(thA, thB);
152 int dth_sign = (thA <= thB);
153 if (not(thA != 0 && thB != 0))
154 {
edm::LogError(
"L1T") <<
"thA = " << thA <<
", thB = " << thB;
return; }
155 if (not(dth < invalid_dtheta))
156 {
edm::LogError(
"L1T") <<
"dth = " << dth <<
", invalid_dtheta = " << invalid_dtheta;
return; }
158 if (best_dtheta_arr.at(ipair) >= dth) {
159 best_dtheta_arr.at(ipair) = dth;
160 best_dtheta_sign_arr.at(ipair) = dth_sign;
161 best_dtheta_valid_arr.at(ipair) =
true;
166 best_theta_arr.at(ipair) = (ipair < 3) ? thB : thA;
170 int phA = conv_hitA.Phi_fp();
171 int phB = conv_hitB.Phi_fp();
172 int dph = abs_diff(phA, phB);
173 int dph_sign = (phA <= phB);
175 if (best_dphi_arr.at(ipair) >= dph) {
176 best_dphi_arr.at(ipair) = dph;
177 best_dphi_sign_arr.at(ipair) = dph_sign;
181 best_phi_arr.at(ipair) = (ipair < 3) ? phB : phA;
198 std::array<bool, emtf::NUM_STATION_PAIRS> best_dtheta_valid_arr_1;
201 if (best_has_rpc_arr.at(ipair))
202 best_dtheta_valid_arr_1.at(ipair) = best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindowRPC_);
204 best_dtheta_valid_arr_1.at(ipair) = best_dtheta_valid_arr.at(ipair) && (best_dtheta_arr.at(ipair) <=
thetaWindow_);
209 int vmask1 = 0, vmask2 = 0, vmask3 = 0;
211 if (best_dtheta_valid_arr_1.at(0)) {
214 if (best_dtheta_valid_arr_1.at(1)) {
217 if (best_dtheta_valid_arr_1.at(2)) {
220 if (best_dtheta_valid_arr_1.at(3)) {
223 if (best_dtheta_valid_arr_1.at(4)) {
226 if (best_dtheta_valid_arr_1.at(5)) {
240 if ((vstat & vmask2) != 0 || vstat == 0)
242 if ((vstat & vmask3) != 0 || vstat == 0)
247 if ((vstat & (1 << istation)) == 0) {
248 st_conv_hits.at(istation).clear();
257 if ((vstat & (1<<1)) != 0) {
258 if (!best_has_rpc_arr.at(0) && best_dtheta_valid_arr.at(0))
260 else if (!best_has_rpc_arr.at(3) && best_dtheta_valid_arr.at(3))
262 else if (!best_has_rpc_arr.at(4) && best_dtheta_valid_arr.at(4))
264 else if (best_dtheta_valid_arr.at(0))
266 else if (best_dtheta_valid_arr.at(3))
268 else if (best_dtheta_valid_arr.at(4))
270 }
else if ((vstat & (1<<2)) != 0) {
271 if (!best_has_rpc_arr.at(1) && best_dtheta_valid_arr.at(1))
273 else if (!best_has_rpc_arr.at(5) && best_dtheta_valid_arr.at(5))
275 else if (best_dtheta_valid_arr.at(1))
277 else if (best_dtheta_valid_arr.at(5))
279 }
else if ((vstat & (1<<3)) != 0) {
280 if (best_dtheta_valid_arr.at(2))
284 if (best_pair != -1) {
285 phi_fp = best_phi_arr.at(best_pair);
286 theta_fp = best_theta_arr.at(best_pair);
287 if (not(theta_fp != 0))
288 {
edm::LogError(
"L1T") <<
"theta_fp = " << theta_fp;
return; }
295 bool operator()(
const value_type& lhs,
const value_type& rhs)
const {
300 less_dtheta_cmp.theta = theta_fp;
303 std::stable_sort(st_conv_hits.at(istation).begin(), st_conv_hits.at(istation).end(), less_dtheta_cmp);
304 if (st_conv_hits.at(istation).size() > 1)
305 st_conv_hits.at(istation).resize(1);
311 int old_rank = (track.
Rank() << 1);
313 (((old_rank >> 6) & 1) << 6) |
314 (((old_rank >> 4) & 1) << 4) |
315 (((old_rank >> 2) & 1) << 2) |
316 (((vstat >> 0) & 1) << 5) |
317 (((vstat >> 1) & 1) << 3) |
318 (((vstat >> 2) & 1) << 1) |
319 (((vstat >> 3) & 1) << 0)
323 (((vstat >> 0) & 1) << 3) |
324 (((vstat >> 1) & 1) << 2) |
325 (((vstat >> 2) & 1) << 1) |
326 (((vstat >> 3) & 1) << 0)
329 int mode_inv = vstat;
332 if (vstat == 0b0001 || vstat == 0b0010 || vstat == 0b0100 || vstat == 0b1000 || vstat == 0)
350 bool isOverlapping = !(station == 1 && ring == 3);
354 bool isEven = (chamber % 2 == 0);
357 result = (station < 3) ? isEven : !isEven;
366 ptlut_data.
sign_ph[
i] = best_dphi_sign_arr.at(
i);
367 ptlut_data.
delta_th[
i] = best_dtheta_arr.at(
i);
368 ptlut_data.
sign_th[
i] = best_dtheta_sign_arr.at(
i);
372 const auto&
v = st_conv_hits.at(
i);
373 ptlut_data.
cpattern[
i] =
v.empty() ? 0 :
v.front().Pattern();
374 ptlut_data.
fr[
i] =
v.empty() ? 0 : isFront(
v.front().Station(),
v.front().Ring(),
v.front().Chamber(),
v.front().Subsystem());
376 ptlut_data.
st1_ring2 =
v.empty() ? 0 : (
v.front().Station() == 1 && (
v.front().Ring() == 2 ||
v.front().Ring() == 3));
379 for (
int i = 0;
i < emtf::NUM_STATIONS+1; ++
i) {
387 const auto&
v = st_conv_hits.at(
i);
389 int bt_station =
v.front().BT_station();
390 if (not(0 <= bt_station && bt_station <= 4))
391 {
edm::LogError(
"L1T") <<
"bt_station = " << bt_station;
return; }
393 int bt_segment =
v.front().BT_segment();
394 ptlut_data.
bt_vi[bt_station] = 1;
395 ptlut_data.
bt_hi[bt_station] = (bt_segment >> 5) & 0x3;
396 ptlut_data.
bt_ci[bt_station] = (bt_segment >> 1) & 0xf;
397 ptlut_data.
bt_si[bt_station] = (bt_segment >> 0) & 0
x1;
420 flatten_container(st_conv_hits, tmp_hits);
427 if (not(delayBX >= 0))
429 std::vector<int>
counter(delayBX+1, 0);
431 for (
const auto& conv_hit : track.
Hits()) {
432 for (
int i = delayBX;
i >= 0;
i--) {
433 if (conv_hit.BX() <=
bx_ -
i)
438 int first_bx =
bx_ - delayBX;
440 for (
int i = delayBX;
i >= 0;
i--) {
441 if (counter.at(
i) >= 2) {
446 if (not(second_bx != 99))
447 {
edm::LogError(
"L1T") <<
"second_bx = " << second_bx;
return; }
461 bool operator()(
const value_type&
x)
const {
462 return (x.Rank() == 0);
466 tracks.erase(std::remove_if(tracks.begin(), tracks.end(), rank_zero_pred), tracks.end());
468 for (
const auto&
track : tracks) {
469 if (not(!
track.Hits().empty()))
470 {
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 configure(int verbose, int endcap, int sector, int bx, int bxWindow, int thetaWindow, int thetaWindowRPC, bool bugME11Dupes)
void set_PtLUT(EMTFPtLUT bits)
l1t::EMTFTrackCollection EMTFTrackCollection
double calc_theta_deg_from_int(int theta_int)
Container::value_type value_type
void calculate_angles(EMTFTrack &track) const
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