14 auto i_last = thetas.size() - 1;
19 return lower_index_value > larger_index_value ? 1 : 0;
27 bool any_invalid = thetas[i_last] == invalid_theta;
43 const std::vector<road_t>& roads,
44 const bool& displaced_en,
45 std::vector<track_t>&
tracks)
const {
47 for (
unsigned int i_road = 0; i_road < roads.size(); ++i_road) {
49 const auto& road = roads[i_road];
58 track.site_segs[site_id] = 0;
59 track.site_mask[site_id] = 0;
60 track.site_rm_mask[site_id] = 0;
64 track.features[i_feature] = 0;
68 if (road.quality == 0) {
76 edm::LogInfo(
"L1TEMTFpp") <<
"===========================================================================" 78 edm::LogInfo(
"L1TEMTFpp") <<
"BEGIN TRACK BUILDING" << std::endl;
79 edm::LogInfo(
"L1TEMTFpp") <<
"---------------------------------------------------------------------------" 83 edm::LogInfo(
"L1TEMTFpp") <<
"***************************************************************************" 85 edm::LogInfo(
"L1TEMTFpp") <<
"Begin building track " << i_road << std::endl;
93 edm::LogInfo(
"L1TEMTFpp") <<
"End building track " << i_road << std::endl;
95 if (i_road == (roads.size() - 1)) {
96 edm::LogInfo(
"L1TEMTFpp") <<
"---------------------------------------------------------------------------" 98 edm::LogInfo(
"L1TEMTFpp") <<
"END TRACK BUILDING" << std::endl;
99 edm::LogInfo(
"L1TEMTFpp") <<
"===========================================================================" 108 const bool& displaced_en,
122 const auto trk_zone = road.
zone;
123 const auto trk_pattern = road.
pattern;
124 const auto trk_quality = road.
quality;
126 int bit_sel_zone = (1u << trk_zone);
134 std::array<seg_phi_t, v3::kNumTrackSites> trk_seg_phi_diff;
135 std::array<seg_theta_t, v3::kNumTrackSites> trk_seg_theta;
138 trk_seg_phi_diff[site_id] = 0;
139 trk_seg_theta[site_id] = 0;
146 const auto& model_hm =
model.zones_[trk_zone].hitmap;
147 const auto& model_ftc =
model.features_;
149 auto* model_pat = &(
model.zones_[trk_zone].prompt_patterns[trk_pattern]);
152 model_pat = &(
model.zones_[trk_zone].disp_patterns[trk_pattern]);
172 std::array<trk_col_t, v3::kHitmapNRows> trk_pat_begin;
173 std::array<trk_col_t, v3::kHitmapNRows> trk_pat_center;
174 std::array<trk_col_t, v3::kHitmapNRows> trk_pat_end;
175 std::array<seg_phi_t, v3::kHitmapNRows> trk_pat_phi;
179 const auto& model_pat_row = (*model_pat)[i_row];
182 trk_pat_begin[i_row] = trk_col + model_pat_row.begin;
183 trk_pat_center[i_row] = trk_col + model_pat_row.center;
184 trk_pat_end[i_row] = trk_col + model_pat_row.end;
185 trk_pat_phi[i_row] = 0;
209 std::vector<std::vector<unsigned int>> site_chambers = {
210 { 0, 1, 2, 9, 10, 11, 45},
211 { 3, 4, 5, 12, 13, 14, 46},
212 { 18, 19, 20, 48, 21, 22, 23, 24, 25, 26, 49},
213 { 27, 28, 29, 50, 30, 31, 32, 33, 34, 35, 51},
214 { 36, 37, 38, 52, 39, 40, 41, 42, 43, 44, 53},
215 { 57, 58, 59, 66, 67, 68, 100},
216 { 75, 76, 77, 78, 79, 80, 103},
217 { 81, 82, 83, 104, 84, 85, 86, 87, 88, 89, 105},
218 { 90, 91, 92, 106, 93, 94, 95, 96, 97, 98, 107},
219 { 54, 55, 56, 63, 64, 65, 99},
221 {108, 109, 110, 111, 112, 113, 114}
224 std::vector<unsigned int> site_chamber_orders = {
225 0, 0, 2, 2, 2, 0, 0, 2, 2, 0, 1, 0
228 std::vector<std::vector<int>> chamber_orders = {
229 {-1, -1, 6, -1, 0, 1, -1, 2, 3, -1, 4, 5},
230 { 3, -1, -1, 0, -1, -1, 1, -1, -1, 2, -1, -1},
231 { 3, -1, 10, 0, 4, 5, 1, 6, 7, 2, 8, 9}
235 auto n_rows = model_hm.size();
237 for (
unsigned int i_row = 0; i_row < n_rows; ++i_row) {
239 const auto& model_hm_row = model_hm[i_row];
241 const auto& trk_pat_row_begin = trk_pat_begin[i_row];
242 const auto& trk_pat_row_end = trk_pat_end[i_row];
243 const auto& trk_pat_row_phi = trk_pat_phi[i_row];
247 <<
" row " << i_row <<
" begin " << trk_pat_row_begin <<
" end " << trk_pat_row_end
248 <<
" phi " << trk_pat_row_phi << std::endl;
251 for (
const auto& model_hm_site : model_hm_row) {
253 const int site_id =
static_cast<int>(model_hm_site.id);
255 auto& site_seg_id =
track.site_segs[site_id];
256 auto& site_bit =
track.site_mask[site_id];
257 auto& site_min_phi_diff = trk_seg_phi_diff[site_id];
259 const auto& s_chambers = site_chambers[site_id];
260 const auto& s_chamber_order_id = site_chamber_orders[site_id];
261 const auto& s_chamber_order = chamber_orders[s_chamber_order_id];
263 for (
const auto& chamber_idx : s_chamber_order) {
265 if (chamber_idx == -1)
268 int chamber_id = s_chambers[chamber_idx];
273 const auto& seg = segments[seg_id];
281 if ((seg.zones & bit_sel_zone) != bit_sel_zone) {
288 if (!(trk_pat_row_begin <= seg_col && seg_col <= trk_pat_row_end)) {
295 if (trk_pat_row_phi > seg.phi) {
296 diff = trk_pat_row_phi - seg.phi;
298 diff = seg.phi - trk_pat_row_phi;
303 <<
" site_id " << site_id <<
" seg_id " << seg_id <<
" seg_phi " << seg.phi
304 <<
" seg_theta1 " << seg.theta1 <<
" seg_theta2 " << seg.theta2 <<
" seg_bend " 305 << seg.bend << std::endl;
309 if (site_bit == 1 && site_min_phi_diff <=
diff)
313 site_seg_id = seg_id;
315 site_min_phi_diff =
diff;
323 <<
" site_id " << site_id <<
" seg_id " << site_seg_id <<
" seg_phi " 324 << segments[site_seg_id].phi <<
" seg_theta1 " << segments[site_seg_id].theta1
325 <<
" seg_theta2 " << segments[site_seg_id].theta2 <<
" seg_bend " 326 << segments[site_seg_id].bend << std::endl;
335 const auto& model_thmc =
model.theta_medians_;
337 std::vector<seg_theta_t> theta_medians;
339 for (
const auto& model_thm : model_thmc) {
341 std::vector<seg_theta_t> group_medians;
343 for (
const auto& model_thm_group : model_thm) {
345 std::vector<seg_theta_t>
group;
347 for (
const auto& model_thm_site : model_thm_group) {
348 int site_id =
static_cast<int>(model_thm_site.id);
350 const auto& site_bit =
track.site_mask[site_id];
353 auto&
theta =
group.emplace_back(invalid_theta);
360 const auto& site_seg_id =
track.site_segs[site_id];
361 const auto& site_seg = segments[site_seg_id];
364 theta = site_seg.theta1;
366 theta = site_seg.theta2;
371 theta = invalid_theta;
377 for (
const auto&
theta : group) {
383 group_medians.push_back(group_median);
386 edm::LogInfo(
"L1TEMTFpp") <<
"group_median " << group_median << std::endl;
392 theta_medians.push_back(theta_median);
395 edm::LogInfo(
"L1TEMTFpp") <<
"theta_median " << theta_median << std::endl;
405 trk_abs_theta = theta_medians[0];
407 trk_abs_theta = theta_medians[1];
411 if (trk_abs_theta == invalid_theta) {
412 trk_abs_theta = theta_medians[2];
416 if (trk_abs_theta == invalid_theta) {
427 std::vector<std::vector<seg_theta_t>> site_theta_window = {
428 {5, 0, 2, 2, 2, 34, 0, 3, 3, 5, 6, 5},
429 {5, 9, 5, 4, 5, 14, 7, 7, 7, 7, 7, 4},
430 {11, 6, 5, 6, 6, 10, 8, 8, 9, 8, 0, 0}
436 site_theta_window = {
437 {14, 40, 4, 3, 3, 45, 0, 4, 4, 15, 8, 13},
438 {16, 18, 7, 5, 5, 22, 7, 7, 8, 17, 9, 14},
439 {26, 15, 8, 9, 9, 17, 11, 9, 10, 26, 21, 0}
445 auto& site_bit =
track.site_mask[site_id];
446 auto& site_rm_bit =
track.site_rm_mask[site_id];
449 const auto& theta_window = site_theta_window[trk_zone][site_id];
455 const auto& site_seg_id =
track.site_segs[site_id];
456 const auto& site_seg = segments[site_seg_id];
463 if (site_seg.theta1 != 0) {
464 if (site_seg.theta1 < trk_abs_theta) {
465 diff_1 = trk_abs_theta - site_seg.theta1;
467 diff_1 = site_seg.theta1 - trk_abs_theta;
472 if (site_seg.theta2 != 0) {
473 if (site_seg.theta2 < trk_abs_theta) {
474 diff_2 = trk_abs_theta - site_seg.theta2;
476 diff_2 = site_seg.theta2 - trk_abs_theta;
481 if (diff_1 <= diff_2 && diff_1 < theta_window) {
483 trk_seg_theta[site_id] = site_seg.theta1;
484 }
else if (diff_2 < theta_window) {
486 trk_seg_theta[site_id] = site_seg.theta2;
494 edm::LogInfo(
"L1TEMTFpp") <<
"Segment outside of theta window; detatched:" 495 <<
" site_id " << site_id <<
" seg_id " << site_seg_id <<
" seg_phi " << site_seg.phi
496 <<
" seg_theta1 " << site_seg.theta1 <<
" seg_theta2 " << site_seg.theta2
505 track.zone = trk_zone;
507 track.pattern = trk_pattern;
508 track.quality = trk_quality;
509 track.phi = trk_abs_phi;
510 track.theta = trk_abs_theta;
518 for (
auto& model_ft : model_ftc) {
519 for (
auto& model_ft_site : model_ft.sites) {
520 int site_id =
static_cast<int>(model_ft_site);
522 const auto& site_seg_id =
track.site_segs[site_id];
523 const auto& site_bit =
track.site_mask[site_id];
524 const auto& site_seg = segments[site_seg_id];
526 auto& trk_feature =
track.features[i_feature++];
536 trk_feature =
static_cast<trk_feature_t>(site_seg.phi) - static_cast<trk_feature_t>(trk_abs_phi);
539 trk_feature =
static_cast<trk_feature_t>(trk_seg_theta[site_id]) - static_cast<trk_feature_t>(trk_abs_theta);
541 trk_feature = site_seg.bend;
543 trk_feature = site_seg.qual1;
549 track.features[i_feature++] = trk_quality > 0 ? trk_rel_phi : decltype(trk_rel_phi)(0);
550 track.features[i_feature++] = trk_quality > 0 ? trk_abs_theta : decltype(trk_abs_theta)(0);
551 track.features[i_feature++] = trk_quality;
552 track.features[i_feature++] = 0;
557 <<
" zone " << track.
zone <<
" col " <<
track.col <<
" pat " <<
track.pattern <<
" qual " 558 <<
track.quality <<
" sector_abs_phi " << sector_abs_phi <<
" abs_phi " <<
track.phi
559 <<
" rel_phi " << trk_rel_phi <<
" abs_theta " <<
track.theta <<
" features "
T getMedianOfSorted(T arr[], const unsigned int &arr_size)
constexpr int kHitmapNRows
static seg_theta_t calc_theta_median(std::vector< seg_theta_t >)
constexpr int kHitmapNCols
void attachSegments(const segment_collection_t &, const road_t &, const bool &, track_t &) const
constexpr int kPatternMatchingPadding
constexpr int kNumTrackFeatures
TrackBuildingLayer(const EMTFContext &)
constexpr int kHitmapCropColStart
Log< level::Info, false > LogInfo
constexpr int kChamberSegments
void apply(const segment_collection_t &, const std::vector< road_t > &, const bool &, std::vector< track_t > &) const
constexpr int kNumTrackSites
const EMTFContext & context_
constexpr int kHitmapColFactorLog2
void mergesort(T arr[], const unsigned int &arr_size, const unsigned int &first_n, const C &comparator)
Geom::Theta< T > theta() const
ap_int< 13 > trk_feature_t
EMTFConfiguration config_
std::array< segment_t, v3::kNumSegments > segment_collection_t