1 #ifndef L1Trigger_L1TTrackMatch_L1TrackJetClustering_HH 2 #define L1Trigger_L1TTrackMatch_L1TrackJetClustering_HH 37 typedef ap_fixed<TTTrack_TrackWord::TrackBitWidths::kTanlSize, ETA_INTPART_BITS, AP_TRN, AP_SAT>
glbeta_intern;
38 typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kExtraGlobalPhiBit>
glbphi_intern;
39 typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kZ0Size>
z0_intern;
40 typedef ap_uint<TTTrack_TrackWord::TrackBitWidths::kD0Size>
d0_intern;
44 unsigned int digitized_maximum = (1 << (maxBits - 1)) - 1;
45 if (digitized_value > digitized_maximum)
46 digitized_value = digitized_maximum;
48 digitized_value = (1 << maxBits) - digitized_value;
49 return digitized_value;
53 unsigned int digitized_maximum = (1 << maxBits) - 1;
54 if (
bits & (1 << (maxBits - 1))) {
58 return (
double(
bits & digitized_maximum) + 0.5) *
step * isign;
96 std::vector<TrackJetEmulationEtaPhiBin>
clusters;
104 double nStubs4PromptBend_,
105 double nStubs5PromptBend_,
106 double nStubs4PromptChi2_,
107 double nStubs5PromptChi2_,
108 double nStubs4DisplacedBend_,
109 double nStubs5DisplacedBend_,
110 double nStubs4DisplacedChi2_,
111 double nStubs5DisplacedChi2_,
113 bool PassQuality =
false;
115 if (trk_nstub == 4 && trk_bendchi2 < nStubs4PromptBend_ &&
118 if (trk_nstub > 4 && trk_bendchi2 < nStubs5PromptBend_ &&
122 if (trk_nstub == 4 && trk_bendchi2 < nStubs4DisplacedBend_ &&
125 if (trk_nstub > 4 && trk_bendchi2 < nStubs5DisplacedBend_ &&
162 int eta_ = (eta_coarse + eta_fine) - 8;
172 int phi_coarse = 3 * phi_sector_raw;
204 template <
typename T,
typename Pt,
typename Eta,
typename Phi>
211 for (
int etabin = 0; etabin < etaBins_; ++etabin) {
213 Pt previousbin_pt = 0;
218 if (phislice[etabin].used)
221 my_pt = phislice[etabin].pTtot;
226 if (etabin > 0 && !phislice[etabin - 1].used)
227 previousbin_pt = phislice[etabin - 1].pTtot;
230 if (etabin < etaBins_ - 1 && !phislice[etabin + 1].used) {
231 nextbin_pt = phislice[etabin + 1].pTtot;
232 if (etabin < etaBins_ - 2 && !phislice[etabin + 2].used) {
233 nextbin2_pt = phislice[etabin + 2].pTtot;
237 if (my_pt < previousbin_pt || my_pt <= nextbin_pt) {
239 if (previousbin_pt > 0) {
240 clusters.push_back(phislice[etabin - 1]);
241 phislice[etabin - 1].used =
true;
247 clusters.push_back(phislice[etabin]);
248 phislice[etabin].used =
true;
249 if (previousbin_pt > 0) {
253 for (
unsigned int itrk = 0; itrk < phislice[etabin - 1].trackidx.size(); itrk++)
254 clusters[
nclust].trackidx.push_back(phislice[etabin - 1].trackidx[itrk]);
257 if (my_pt >= nextbin2_pt && nextbin_pt > 0) {
261 for (
unsigned int itrk = 0; itrk < phislice[etabin + 1].trackidx.size(); itrk++)
262 clusters[
nclust].trackidx.push_back(phislice[etabin + 1].trackidx[itrk]);
263 phislice[etabin + 1].used =
true;
280 for (
unsigned int itrk = 0; itrk <
clusters[
m + 1].trackidx.size(); itrk++)
284 for (
int m1 =
m + 1; m1 <
nclust - 1; ++m1)
296 template <
typename T,
typename Pt>
300 bin.nxtracks += ndtrk;
301 for (
unsigned int itrk = 0; itrk < trkidx.size(); itrk++)
302 bin.trackidx.push_back(trkidx[itrk]);
319 inline float DPhi(
float phi1,
float phi2) {
320 float x = phi1 - phi2;
329 template <
typename T,
typename Pt,
typename Eta,
typename Phi>
335 for (
int phibin = 0; phibin < phiBins_; ++phibin) {
336 if (L1clusters[phibin].
empty())
340 sort(L1clusters[phibin].begin(), L1clusters[phibin].end(), [](
T &
a,
T &
b) {
return a.pTtot >
b.pTtot; });
342 for (
unsigned int imax = 0; imax < L1clusters[phibin].size(); ++imax) {
343 if (L1clusters[phibin][imax].used)
345 Pt pt_current = L1clusters[phibin][imax].pTtot;
352 std::vector<unsigned int> trkidx1;
353 std::vector<unsigned int> trkidx2;
354 clusters.push_back(L1clusters[phibin][imax]);
356 L1clusters[phibin][imax].used =
true;
359 if (phibin == phiBins_ - 1)
362 std::vector<unsigned int> used_already;
363 for (
unsigned int icluster = 0; icluster < L1clusters[phibin + 1].size(); ++icluster) {
364 if (L1clusters[phibin + 1][icluster].used)
367 if (((L1clusters[phibin + 1][icluster].
eta - L1clusters[phibin][imax].
eta) > (3 * etaStep_) / 2) ||
368 ((L1clusters[phibin + 1][icluster].eta - L1clusters[phibin][imax].eta) < -(3 * etaStep_) / 2))
371 pt_next += L1clusters[phibin + 1][icluster].pTtot;
372 trk1 += L1clusters[phibin + 1][icluster].ntracks;
373 tdtrk1 += L1clusters[phibin + 1][icluster].nxtracks;
375 for (
unsigned int itrk = 0; itrk < L1clusters[phibin + 1][icluster].trackidx.size(); itrk++)
376 trkidx1.push_back(L1clusters[phibin + 1][icluster].trackidx[itrk]);
377 used_already.push_back(icluster);
380 if (pt_next < pt_current) {
381 Fill_L2Cluster<T, Pt>(
clusters[
clusters.size() - 1], pt_next, trk1, tdtrk1, trkidx1);
382 for (
unsigned int iused : used_already)
383 L1clusters[phibin + 1][iused].used =
true;
387 if (phibin == phiBins_ - 2) {
388 Fill_L2Cluster<T, Pt>(
clusters[
clusters.size() - 1], pt_next, trk1, tdtrk1, trkidx1);
389 clusters[
clusters.size() - 1].phi = L1clusters[phibin + 1][used_already[0]].phi;
390 for (
unsigned int iused : used_already)
391 L1clusters[phibin + 1][iused].used =
true;
394 std::vector<int> used_already2;
395 for (
unsigned int icluster = 0; icluster < L1clusters[phibin + 2].size(); ++icluster) {
396 if (L1clusters[phibin + 2][icluster].used)
398 if (((L1clusters[phibin + 2][icluster].
eta - L1clusters[phibin][imax].
eta) > (3 * etaStep_) / 2) ||
399 ((L1clusters[phibin + 2][icluster].eta - L1clusters[phibin][imax].eta) < -(3 * etaStep_) / 2))
401 pt_next2 += L1clusters[phibin + 2][icluster].pTtot;
402 trk2 += L1clusters[phibin + 2][icluster].ntracks;
403 tdtrk2 += L1clusters[phibin + 2][icluster].nxtracks;
405 for (
unsigned int itrk = 0; itrk < L1clusters[phibin + 2][icluster].trackidx.size(); itrk++)
406 trkidx2.push_back(L1clusters[phibin + 2][icluster].trackidx[itrk]);
407 used_already2.push_back(icluster);
409 if (pt_next2 < pt_next) {
410 std::vector<unsigned int> trkidx_both;
411 trkidx_both.reserve(trkidx1.size() + trkidx2.size());
412 trkidx_both.insert(trkidx_both.end(), trkidx1.begin(), trkidx1.end());
413 trkidx_both.insert(trkidx_both.end(), trkidx2.begin(), trkidx2.end());
414 Fill_L2Cluster<T, Pt>(
415 clusters[
clusters.size() - 1], pt_next + pt_next2, trk1 + trk2, tdtrk1 + tdtrk2, trkidx_both);
416 clusters[
clusters.size() - 1].phi = L1clusters[phibin + 1][used_already[0]].phi;
417 for (
unsigned int iused : used_already)
418 L1clusters[phibin + 1][iused].used =
true;
419 for (
unsigned int iused : used_already2)
420 L1clusters[phibin + 2][iused].used =
true;
440 for (
unsigned int itrk = 0; itrk <
clusters[
n].trackidx.size(); itrk++)
442 for (
int m1 =
n; m1 <
nclust - 1; ++m1)
l1t::TkJetWord::nx_t nxtracks
ap_uint< TTTrack_TrackWord::TrackBitWidths::kD0Size > d0_intern
std::vector< unsigned int > trackidx
const unsigned int kExtraGlobalPhiBit
bool TrackQualitySelection(int trk_nstub, double trk_chi2, double trk_bendchi2, double nStubs4PromptBend_, double nStubs5PromptBend_, double nStubs4PromptChi2_, double nStubs5PromptChi2_, double nStubs4DisplacedBend_, double nStubs5DisplacedBend_, double nStubs4DisplacedChi2_, double nStubs5DisplacedChi2_, bool displaced_)
const unsigned int DoubleToBit(double value, unsigned int maxBits, double step)
static constexpr int kPhiBinZeroOffset
std::vector< unsigned int > trackidx
const unsigned int ETA_INTPART_BITS
static constexpr int kEtaFineBinEdge4
const unsigned int PT_INTPART_BITS
static constexpr int kPhiBinHalfWidth
static constexpr int kNumPhiBins
const double BitToDouble(unsigned int bits, unsigned int maxBits, double step)
ap_fixed< TTTrack_TrackWord::TrackBitWidths::kTanlSize, ETA_INTPART_BITS, AP_TRN, AP_SAT > glbeta_intern
ap_ufixed< TTTrack_TrackWord::TrackBitWidths::kRinvSize - 1, PT_INTPART_BITS, AP_TRN, AP_SAT > pt_intern
l1t::TkJetWord::nt_t ntracks
static constexpr int kEtaFineBinEdge3
std::vector< EtaPhiBin > clusters
Abs< T >::type abs(const T &t)
static constexpr int kThirteenBitMask
ap_int< TTTrack_TrackWord::TrackBitWidths::kZ0Size > z0_intern
unsigned int eta_bin_firmwareStyle(int eta_word)
std::vector< TrackJetEmulationEtaPhiBin > clusters
unsigned int phi_bin_firmwareStyle(int phi_sector_raw, int phi_word)
glbphi_intern DPhi(glbphi_intern phi1, glbphi_intern phi2)
void Fill_L2Cluster(T &bin, Pt pt, int ntrk, int ndtrk, std::vector< unsigned int > trkidx)
static constexpr int kEtaFineBinEdge2
ap_int< TTTrack_TrackWord::TrackBitWidths::kPhiSize+kExtraGlobalPhiBit > glbphi_intern
static constexpr int kEtaFineBinEdge1
static constexpr double stepPhi0
static constexpr int kEtaWordLength
static constexpr int kTwelveBitMask
std::vector< T > L2_clustering(std::vector< std::vector< T > > &L1clusters, int phiBins_, Phi phiStep_, Eta etaStep_)
static constexpr int kPhiWordLength
std::vector< T > L1_clustering(T *phislice, int etaBins_, Eta etaStep_)