9 int maxRoadsPerZone,
int maxTracks,
bool useSecondEarliest,
25 const std::deque<EMTFTrackCollection>& extended_best_track_cands,
29 for (
const auto&
cands : extended_best_track_cands) {
31 if (
cand.Rank() > 0) {
36 bool early_exit = (num_cands == 0);
49 for (
const auto&
track : best_tracks) {
51 <<
" ph_deltas: " << array_as_string(
track.PtLUT().delta_ph)
52 <<
" th_deltas: " << array_as_string(
track.PtLUT().delta_th)
53 <<
" phi: " <<
track.Phi_fp() <<
" theta: " <<
track.Theta_fp()
54 <<
" cpat: " << array_as_string(
track.PtLUT().cpattern)
55 <<
" bx: " <<
track.BX()
58 if (
track.PtLUT().bt_vi[
i] != 0)
60 <<
" v: " <<
track.PtLUT().bt_vi[
i]
61 <<
" h: " <<
track.PtLUT().bt_hi[
i]
62 <<
" c: " <<
track.PtLUT().bt_ci[
i]
63 <<
" s: " <<
track.PtLUT().bt_si[
i]
72 const std::deque<EMTFTrackCollection>& extended_best_track_cands,
77 const int max_zn = max_z * max_n;
82 typedef std::array<int, 3> segment_ref_t;
83 std::vector<std::vector<segment_ref_t> > segments(max_zn, std::vector<segment_ref_t>());
85 std::vector<std::vector<bool> > larger(max_zn, std::vector<bool>(max_zn,
false));
86 std::vector<std::vector<bool> > winner(max_zn, std::vector<bool>(max_zn,
false));
88 std::vector<bool> exists (max_zn,
false);
89 std::vector<bool>
killed (max_zn,
false);
90 std::vector<int> rank (max_zn, 0);
94 for (
int z = 0;
z < max_z; ++
z) {
96 const int ntracks = tracks.size();
97 if (not (ntracks <= max_n))
98 {
edm::LogError(
"L1T") <<
"ntracks = " << ntracks <<
", max_n = " << max_n;
return; }
101 const int zn = (
n * max_z) +
z;
104 rank.at(zn) = track.
Rank();
106 for (
const auto& conv_hit : track.
Hits()) {
107 if (not (conv_hit.Valid()))
108 {
edm::LogError(
"L1T") <<
"conv_hit.Valid() = " << conv_hit.Valid();
return; }
111 const segment_ref_t segment = {{conv_hit.PC_station()*9 + conv_hit.PC_chamber(), (conv_hit.PC_segment() % 2), 0}};
116 segments.at(zn).push_back(segment);
122 int i=0, j=0, ri=0, rj=0, gt=0,
eq=0, sum=0;
124 for (i = 0; i < max_zn; ++
i) {
125 for (j = 0; j < max_zn; ++j) {
126 larger[
i][j] =
false;
132 for (j = 0; j < max_zn; ++j) {
140 if ((i < j && (gt ||
eq)) || (i > j && gt))
146 exists[
i] = (ri != 0);
150 for (i = 0; i < max_zn-1; ++
i) {
151 for (j = i+1; j < max_zn; ++j) {
155 for (
const auto& isegment : segments.at(i)) {
156 for (
const auto& jsegment : segments.at(j)) {
157 if (isegment == jsegment) {
163 if (shared_segs > 0) {
175 for (i = 0; i < max_zn; ++
i) {
176 exists[
i] = exists[
i] & (!killed[
i]);
179 bool anything_exists = (
std::find(exists.begin(), exists.end(), 1) != exists.end());
180 if (!anything_exists)
184 for (i = 0; i < max_zn; ++
i) {
185 for (j = 0; j < max_zn; ++j) {
189 larger[
i][j] = larger[
i][j] | (!exists[j]);
191 larger[
i][j] =
false;
197 for (i = max_zn-1; i >= 0; --
i) {
202 for (i = max_zn-1; i >= 0; --
i) {
206 for (j = 0; j < max_zn; ++j) {
208 for (i = max_zn-1; i >= 0; --
i) {
217 for (i = 0; i < max_zn; ++
i) {
219 for (j = 0; j < max_zn; ++j) {
220 if (larger[i][j] == 0)
225 winner[sum][
i] =
true;
228 if (sum < maxTracks_ && bugSameSectorPt0_ && sum > 0) {
230 winner[sum][
i] =
false;
239 for (i = 0; i < max_zn; ++
i) {
246 best_tracks.push_back(track);
249 best_tracks.back().set_track_num ( best_tracks.size() - 1 );
250 best_tracks.back().set_winner (
o );
251 best_tracks.back().set_bx ( best_tracks.back().First_BX() );
258 const std::deque<EMTFTrackCollection>& extended_best_track_cands,
264 const int max_zn = max_z * max_n;
265 const int max_hzn = max_h * max_zn;
270 const int num_h = extended_best_track_cands.size() / max_z;
273 typedef std::array<int, 3> segment_ref_t;
274 std::vector<std::vector<segment_ref_t> > segments(max_hzn, std::vector<segment_ref_t>());
276 std::vector<std::vector<bool> > larger(max_hzn, std::vector<bool>(max_hzn,
false));
277 std::vector<std::vector<bool> > winner(max_hzn, std::vector<bool>(max_hzn,
false));
279 std::vector<bool> exists (max_hzn,
false);
280 std::vector<bool>
killed (max_hzn,
false);
281 std::vector<int> rank (max_hzn, 0);
282 std::vector<int> good_bx(max_hzn, 0);
285 for (
int h = 0;
h < num_h; ++
h) {
290 for (
int z = 0;
z < max_z; ++
z) {
292 const int ntracks = tracks.size();
293 if (not (ntracks <= max_n))
294 {
edm::LogError(
"L1T") <<
"ntracks = " << ntracks <<
", max_n = " << max_n;
return; }
297 const int hzn = (
h * max_z * max_n) + (
n * max_z) +
z;
300 cand_bx -= (
bx_ - delayBX);
302 rank.at(hzn) = track.
Rank();
306 for (
const auto& conv_hit : track.
Hits()) {
307 if (not (conv_hit.Valid()))
308 {
edm::LogError(
"L1T") <<
"conv_hit.Valid() = " << conv_hit.Valid();
return; }
321 const segment_ref_t segment = {{conv_hit.PC_station()*9 + conv_hit.PC_chamber(), (conv_hit.PC_segment() % 2), conv_hit.BX()}};
326 segments.at(hzn).push_back(segment);
333 int i=0, j=0, ri=0, rj=0, sum=0;
335 for (i = 0; i < max_hzn; ++
i) {
343 for (j = i+1; j < max_hzn; ++j) {
355 exists[
i] = (ri != 0);
359 for (i = 0; i < max_hzn-1; ++
i) {
360 for (j = i+1; j < max_hzn; ++j) {
364 for (
const auto& isegment : segments.at(i)) {
365 for (
const auto& jsegment : segments.at(j)) {
366 if (isegment == jsegment) {
372 if (shared_segs > 0) {
384 for (i = 0; i < max_hzn; ++
i) {
385 exists[
i] = exists[
i] & (!killed[
i]);
390 for (i = 0; i < max_hzn; ++
i) {
391 exists[
i] = exists[
i] & good_bx[
i];
394 bool anything_exists = (
std::find(exists.begin(), exists.end(), 1) != exists.end());
395 if (!anything_exists)
399 for (i = 0; i < max_hzn; ++
i) {
400 for (j = 0; j < max_hzn; ++j) {
404 larger[
i][j] = larger[
i][j] | (!exists[j]);
406 larger[
i][j] =
false;
412 for (i = max_hzn-1; i >= 0; --
i) {
414 if ((i%max_zn) == 0 && i != 0)
std::cout <<
"_";
418 for (i = max_hzn-1; i >= 0; --
i) {
420 if ((i%max_zn) == 0 && i != 0)
std::cout <<
"_";
423 for (j = 0; j < max_hzn; ++j) {
425 for (i = max_hzn-1; i >= 0; --
i) {
427 if ((i%max_zn) == 0 && i != 0)
std::cout <<
"_";
434 for (i = 0; i < max_hzn; ++
i) {
436 for (j = 0; j < max_hzn; ++j) {
437 if (larger[i][j] == 0)
442 winner[sum][
i] =
true;
445 if (sum < maxTracks_ && bugSameSectorPt0_ && sum > 0) {
447 winner[sum][
i] =
false;
455 int h = 0,
n = 0,
z = 0;
456 for (i = 0; i < max_hzn; ++
i) {
458 h = (i / max_z / max_n);
459 n = (i / max_z) % max_n;
464 best_tracks.push_back(track);
467 best_tracks.back().set_track_num ( best_tracks.size() - 1 );
468 best_tracks.back().set_winner (
o );
469 best_tracks.back().set_bx ( best_tracks.back().Second_BX() );
static char to_hex(unsigned int i)
void process(const std::deque< EMTFTrackCollection > &extended_best_track_cands, EMTFTrackCollection &best_tracks) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void cancel_multi_bx(const std::deque< EMTFTrackCollection > &extended_best_track_cands, EMTFTrackCollection &best_tracks) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
l1t::EMTFTrackCollection EMTFTrackCollection
void configure(int verbose, int endcap, int sector, int bx, int bxWindow, int maxRoadsPerZone, int maxTracks, bool useSecondEarliest, bool bugSameSectorPt0)
EMTFHitCollection Hits() const
void cancel_one_bx(const std::deque< EMTFTrackCollection > &extended_best_track_cands, EMTFTrackCollection &best_tracks) const