1 #ifndef L1Trigger_L1TTrackMatch_L1TrackJetClustering_HH 2 #define L1Trigger_L1TTrackMatch_L1TrackJetClustering_HH 21 typedef ap_fixed<TTTrack_TrackWord::TrackBitWidths::kTanlSize, ETA_INTPART_BITS, AP_TRN, AP_SAT>
glbeta_intern;
22 typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kExtraGlobalPhiBit>
glbphi_intern;
23 typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kZ0Size>
z0_intern;
24 typedef ap_uint<TTTrack_TrackWord::TrackBitWidths::kD0Size>
d0_intern;
28 unsigned int digitized_maximum = (1 << (maxBits - 1)) - 1;
29 if (digitized_value > digitized_maximum)
30 digitized_value = digitized_maximum;
32 digitized_value = (1 << maxBits) - digitized_value;
33 return digitized_value;
37 unsigned int digitized_maximum = (1 << maxBits) - 1;
38 if (
bits & (1 << (maxBits - 1))) {
42 return (
double(
bits & digitized_maximum) + 0.5) *
step * isign;
80 std::vector<TrackJetEmulationEtaPhiBin>
clusters;
88 double nStubs4PromptBend_,
89 double nStubs5PromptBend_,
90 double nStubs4PromptChi2_,
91 double nStubs5PromptChi2_,
92 double nStubs4DisplacedBend_,
93 double nStubs5DisplacedBend_,
94 double nStubs4DisplacedChi2_,
95 double nStubs5DisplacedChi2_,
97 bool PassQuality =
false;
99 if (trk_nstub == 4 && trk_bendchi2 < nStubs4PromptBend_ &&
100 trk_chi2 < nStubs4PromptChi2_)
102 if (trk_nstub > 4 && trk_bendchi2 < nStubs5PromptBend_ &&
103 trk_chi2 < nStubs5PromptChi2_)
106 if (trk_nstub == 4 && trk_bendchi2 < nStubs4DisplacedBend_ &&
107 trk_chi2 < nStubs4DisplacedChi2_)
109 if (trk_nstub > 4 && trk_bendchi2 < nStubs5DisplacedBend_ &&
110 trk_chi2 < nStubs5DisplacedChi2_)
117 template <
typename T,
typename Pt,
typename Eta,
typename Phi>
124 for (
int etabin = 0; etabin < etaBins_; ++etabin) {
126 Pt previousbin_pt = 0;
131 if (phislice[etabin].used)
134 my_pt = phislice[etabin].pTtot;
139 if (etabin > 0 && !phislice[etabin - 1].used)
140 previousbin_pt = phislice[etabin - 1].pTtot;
143 if (etabin < etaBins_ - 1 && !phislice[etabin + 1].used) {
144 nextbin_pt = phislice[etabin + 1].pTtot;
145 if (etabin < etaBins_ - 2 && !phislice[etabin + 2].used) {
146 nextbin2_pt = phislice[etabin + 2].pTtot;
150 if (my_pt < previousbin_pt || my_pt <= nextbin_pt) {
152 if (previousbin_pt > 0) {
153 clusters.push_back(phislice[etabin - 1]);
154 phislice[etabin - 1].used =
true;
160 clusters.push_back(phislice[etabin]);
161 phislice[etabin].used =
true;
162 if (previousbin_pt > 0) {
166 for (
unsigned int itrk = 0; itrk < phislice[etabin - 1].trackidx.size(); itrk++)
167 clusters[
nclust].trackidx.push_back(phislice[etabin - 1].trackidx[itrk]);
170 if (my_pt >= nextbin2_pt && nextbin_pt > 0) {
174 for (
unsigned int itrk = 0; itrk < phislice[etabin + 1].trackidx.size(); itrk++)
175 clusters[
nclust].trackidx.push_back(phislice[etabin + 1].trackidx[itrk]);
176 phislice[etabin + 1].used =
true;
193 for (
unsigned int itrk = 0; itrk <
clusters[
m + 1].trackidx.size(); itrk++)
197 for (
int m1 =
m + 1; m1 <
nclust - 1; ++m1)
209 template <
typename T,
typename Pt>
213 bin.nxtracks += ndtrk;
214 for (
unsigned int itrk = 0; itrk < trkidx.size(); itrk++)
215 bin.trackidx.push_back(trkidx[itrk]);
232 inline float DPhi(
float phi1,
float phi2) {
233 float x = phi1 - phi2;
242 template <
typename T,
typename Pt,
typename Eta,
typename Phi>
248 for (
int phibin = 0; phibin < phiBins_; ++phibin) {
249 if (L1clusters[phibin].
empty())
253 sort(L1clusters[phibin].begin(), L1clusters[phibin].end(), [](
T &
a,
T &
b) {
return a.pTtot >
b.pTtot; });
255 for (
unsigned int imax = 0; imax < L1clusters[phibin].size(); ++imax) {
256 if (L1clusters[phibin][imax].used)
258 Pt pt_current = L1clusters[phibin][imax].pTtot;
265 std::vector<unsigned int> trkidx1;
266 std::vector<unsigned int> trkidx2;
267 clusters.push_back(L1clusters[phibin][imax]);
269 L1clusters[phibin][imax].used =
true;
272 if (phibin == phiBins_ - 1)
275 std::vector<unsigned int> used_already;
276 for (
unsigned int icluster = 0; icluster < L1clusters[phibin + 1].size(); ++icluster) {
277 if (L1clusters[phibin + 1][icluster].used)
280 if (((L1clusters[phibin + 1][icluster].
eta - L1clusters[phibin][imax].
eta) > (3 * etaStep_) / 2) ||
281 ((L1clusters[phibin + 1][icluster].eta - L1clusters[phibin][imax].eta) < -(3 * etaStep_) / 2))
284 pt_next += L1clusters[phibin + 1][icluster].pTtot;
285 trk1 += L1clusters[phibin + 1][icluster].ntracks;
286 tdtrk1 += L1clusters[phibin + 1][icluster].nxtracks;
288 for (
unsigned int itrk = 0; itrk < L1clusters[phibin + 1][icluster].trackidx.size(); itrk++)
289 trkidx1.push_back(L1clusters[phibin + 1][icluster].trackidx[itrk]);
290 used_already.push_back(icluster);
293 if (pt_next < pt_current) {
294 Fill_L2Cluster<T, Pt>(
clusters[
clusters.size() - 1], pt_next, trk1, tdtrk1, trkidx1);
295 for (
unsigned int iused : used_already)
296 L1clusters[phibin + 1][iused].used =
true;
300 if (phibin == phiBins_ - 2) {
301 Fill_L2Cluster<T, Pt>(
clusters[
clusters.size() - 1], pt_next, trk1, tdtrk1, trkidx1);
302 clusters[
clusters.size() - 1].phi = L1clusters[phibin + 1][used_already[0]].phi;
303 for (
unsigned int iused : used_already)
304 L1clusters[phibin + 1][iused].used =
true;
307 std::vector<int> used_already2;
308 for (
unsigned int icluster = 0; icluster < L1clusters[phibin + 2].size(); ++icluster) {
309 if (L1clusters[phibin + 2][icluster].used)
311 if (((L1clusters[phibin + 2][icluster].
eta - L1clusters[phibin][imax].
eta) > (3 * etaStep_) / 2) ||
312 ((L1clusters[phibin + 2][icluster].eta - L1clusters[phibin][imax].eta) < -(3 * etaStep_) / 2))
314 pt_next2 += L1clusters[phibin + 2][icluster].pTtot;
315 trk2 += L1clusters[phibin + 2][icluster].ntracks;
316 tdtrk2 += L1clusters[phibin + 2][icluster].nxtracks;
318 for (
unsigned int itrk = 0; itrk < L1clusters[phibin + 2][icluster].trackidx.size(); itrk++)
319 trkidx2.push_back(L1clusters[phibin + 2][icluster].trackidx[itrk]);
320 used_already2.push_back(icluster);
322 if (pt_next2 < pt_next) {
323 std::vector<unsigned int> trkidx_both;
324 trkidx_both.reserve(trkidx1.size() + trkidx2.size());
325 trkidx_both.insert(trkidx_both.end(), trkidx1.begin(), trkidx1.end());
326 trkidx_both.insert(trkidx_both.end(), trkidx2.begin(), trkidx2.end());
327 Fill_L2Cluster<T, Pt>(
328 clusters[
clusters.size() - 1], pt_next + pt_next2, trk1 + trk2, tdtrk1 + tdtrk2, trkidx_both);
329 clusters[
clusters.size() - 1].phi = L1clusters[phibin + 1][used_already[0]].phi;
330 for (
unsigned int iused : used_already)
331 L1clusters[phibin + 1][iused].used =
true;
332 for (
unsigned int iused : used_already2)
333 L1clusters[phibin + 2][iused].used =
true;
353 for (
unsigned int itrk = 0; itrk <
clusters[
n].trackidx.size(); itrk++)
355 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)
std::vector< unsigned int > trackidx
const unsigned int ETA_INTPART_BITS
const unsigned int PT_INTPART_BITS
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
std::vector< EtaPhiBin > clusters
Abs< T >::type abs(const T &t)
ap_int< TTTrack_TrackWord::TrackBitWidths::kZ0Size > z0_intern
std::vector< TrackJetEmulationEtaPhiBin > clusters
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)
ap_int< TTTrack_TrackWord::TrackBitWidths::kPhiSize+kExtraGlobalPhiBit > glbphi_intern
static constexpr double stepPhi0
std::vector< T > L2_clustering(std::vector< std::vector< T > > &L1clusters, int phiBins_, Phi phiStep_, Eta etaStep_)
std::vector< T > L1_clustering(T *phislice, int etaBins_, Eta etaStep_)