CMS 3D CMS Logo

L1TrackJetEmulationProducer.cc
Go to the documentation of this file.
1 /* Software to emulate the hardware 2-layer jet-finding algorithm (fixed-point). *Layers 1 and 2*
2  *
3  * 2021
4  *
5  * Created based on Rishi Patel's L1TrackJetProducer.cc file.
6  * Authors: Samuel Edwin Leigh, Tyler Wu
7  * Rutgers, the State University of New Jersey
8  * Revolutionary for 250 years
9  */
10 
11 //Holds data from tracks, converted from their integer versions.
12 
13 // system include files
14 
23 // user include files
35 
37 
38 #include <memory>
39 #include <iostream>
40 #include <fstream>
41 #include <cmath>
42 #include <cstdlib>
43 #include <string>
44 #include <cstdlib>
45 #include "TH1D.h"
46 #include "TH2D.h"
47 #include <TMath.h>
48 #include <ap_int.h>
50 
51 using namespace std;
52 using namespace edm;
54 public:
55  explicit L1TrackJetEmulationProducer(const ParameterSet &);
56  ~L1TrackJetEmulationProducer() override;
58  typedef vector<L1TTTrackType> L1TTTrackCollectionType;
59 
60  static void fillDescriptions(ConfigurationDescriptions &descriptions);
61  bool trackQualityCuts(int trk_nstub, float trk_chi2, float trk_bendchi2);
62  void L2_cluster(vector<Ptr<L1TTTrackType>> L1TrkPtrs_, TrackJetEmulationMaxZBin &mzb);
63  virtual TrackJetEmulationEtaPhiBin *L1_cluster(TrackJetEmulationEtaPhiBin *phislice);
64 
65 private:
66  void beginStream(StreamID) override;
67  void produce(Event &, const EventSetup &) override;
68  void endStream() override;
69 
70  // ----------member data ---------------------------
71 
72  vector<Ptr<L1TTTrackType>> L1TrkPtrs_;
73  vector<int> zBinCount_;
74  vector<int> tdtrk_;
75  const float MaxDzTrackPV;
76  const float trkZMax_;
77  const float trkPtMax_;
78  const float trkPtMin_;
79  const float trkEtaMax_;
80  const float trkChi2dofMax_;
81  const float trkBendChi2Max_;
82  const int trkNPSStubMin_;
83  const double minTrkJetpT_;
84  int etaBins_;
85  int phiBins_;
86  int zBins_;
93  bool displaced_;
99 
100  float PVz;
104 
108 };
109 
111  : MaxDzTrackPV((float)iConfig.getParameter<double>("MaxDzTrackPV")),
112  trkZMax_((float)iConfig.getParameter<double>("trk_zMax")),
113  trkPtMax_((float)iConfig.getParameter<double>("trk_ptMax")),
114  trkPtMin_((float)iConfig.getParameter<double>("trk_ptMin")),
115  trkEtaMax_((float)iConfig.getParameter<double>("trk_etaMax")),
116  trkChi2dofMax_((float)iConfig.getParameter<double>("trk_chi2dofMax")),
117  trkBendChi2Max_((float)iConfig.getParameter<double>("trk_bendChi2Max")),
118  trkNPSStubMin_((int)iConfig.getParameter<int>("trk_nPSStubMin")),
119  minTrkJetpT_(iConfig.getParameter<double>("minTrkJetpT")),
120  etaBins_((int)iConfig.getParameter<int>("etaBins")),
121  phiBins_((int)iConfig.getParameter<int>("phiBins")),
122  zBins_((int)iConfig.getParameter<int>("zBins")),
123  d0CutNStubs4_((float)iConfig.getParameter<double>("d0_cutNStubs4")),
124  d0CutNStubs5_((float)iConfig.getParameter<double>("d0_cutNStubs5")),
125  lowpTJetMinTrackMultiplicity_((int)iConfig.getParameter<int>("lowpTJetMinTrackMultiplicity")),
126  lowpTJetMinpT_((float)iConfig.getParameter<double>("lowpTJetMinpT")),
127  highpTJetMinTrackMultiplicity_((int)iConfig.getParameter<int>("highpTJetMinTrackMultiplicity")),
128  highpTJetMinpT_((float)iConfig.getParameter<double>("highpTJetMinpT")),
129  displaced_(iConfig.getParameter<bool>("displaced")),
130  nStubs4DisplacedChi2_((float)iConfig.getParameter<double>("nStubs4DisplacedChi2")),
131  nStubs5DisplacedChi2_((float)iConfig.getParameter<double>("nStubs5DisplacedChi2")),
132  nStubs4DisplacedBend_((float)iConfig.getParameter<double>("nStubs4Displacedbend")),
133  nStubs5DisplacedBend_((float)iConfig.getParameter<double>("nStubs5Displacedbend")),
134  nDisplacedTracks_((int)iConfig.getParameter<int>("nDisplacedTracks")),
135  trackToken_(consumes<vector<TTTrack<Ref_Phase2TrackerDigi_>>>(iConfig.getParameter<InputTag>("L1TrackInputTag"))),
136  PVtxToken_(consumes<l1t::VertexWordCollection>(iConfig.getParameter<InputTag>("VertexInputTag"))),
137  tTopoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>(edm::ESInputTag("", ""))) {
138  zStep_ = convert::makeZ0(2.0 * trkZMax_ / (zBins_ + 1));
139  etaStep_ = convert::makeGlbEta(2.0 * trkEtaMax_ / etaBins_); //etaStep is the width of an etabin
141 
142  if (displaced_)
143  produces<l1t::TkJetWordCollection>("L1TrackJetsExtended");
144  else
145  produces<l1t::TkJetWordCollection>("L1TrackJets");
146 }
147 
149 
151  unique_ptr<l1t::TkJetWordCollection> L1L1TrackJetProducer(new l1t::TkJetWordCollection);
152 
153  // For TTStubs
154  const TrackerTopology &tTopo = iSetup.getData(tTopoToken_);
155 
157  iEvent.getByToken(trackToken_, TTTrackHandle);
158  vector<TTTrack<Ref_Phase2TrackerDigi_>>::const_iterator iterL1Track;
159 
161  iEvent.getByToken(PVtxToken_, PVtx);
162  float PVz = (PVtx->at(0)).z0();
163 
164  L1TrkPtrs_.clear();
165  zBinCount_.clear();
166  tdtrk_.clear();
167  unsigned int this_l1track = 0;
168  for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) {
169  edm::Ptr<L1TTTrackType> trkPtr(TTTrackHandle, this_l1track);
170  this_l1track++;
171  float trk_pt = trkPtr->momentum().perp();
172  int trk_nstubs = (int)trkPtr->getStubRefs().size();
173  float trk_chi2dof = trkPtr->chi2Red();
174  float trk_d0 = trkPtr->d0();
175  float trk_bendchi2 = trkPtr->stubPtConsistency();
176  float trk_z0 = trkPtr->z0();
177 
178  int trk_nPS = 0;
179  for (int istub = 0; istub < trk_nstubs; istub++) { // loop over the stubs
180  DetId detId(trkPtr->getStubRefs().at(istub)->getDetId());
181  if (detId.det() == DetId::Detector::Tracker) {
182  if ((detId.subdetId() == StripSubdetector::TOB && tTopo.tobLayer(detId) <= 3) ||
183  (detId.subdetId() == StripSubdetector::TID && tTopo.tidRing(detId) <= 9))
184  trk_nPS++;
185  }
186  }
187 
188  if (trk_nPS < trkNPSStubMin_)
189  continue;
190  if (!trackQualityCuts(trk_nstubs, trk_chi2dof, trk_bendchi2))
191  continue;
192  if (std::abs(trk_z0 - PVz) > MaxDzTrackPV)
193  continue;
194  if (std::abs(trk_z0) > trkZMax_)
195  continue;
196  if (std::abs(trkPtr->momentum().eta()) > trkEtaMax_)
197  continue;
198  if (trk_pt < trkPtMin_)
199  continue;
200  L1TrkPtrs_.push_back(trkPtr);
201  zBinCount_.push_back(0);
202 
203  if ((std::abs(trk_d0) > d0CutNStubs5_ && trk_nstubs >= 5 && d0CutNStubs5_ >= 0) ||
204  (trk_nstubs == 4 && std::abs(trk_d0) > d0CutNStubs4_ && d0CutNStubs4_ >= 0))
205  tdtrk_.push_back(1); //displaced track
206  else
207  tdtrk_.push_back(0); // not displaced track
208  }
209 
210  if (!L1TrkPtrs_.empty()) {
212 
213  L2_cluster(L1TrkPtrs_, mzb);
214  if (mzb.clusters != nullptr) {
215  for (int j = 0; j < mzb.nclust; ++j) {
216  //FILL Two Layer Jets for Jet Collection
218  continue; //protects against reading bad memory
219  if (mzb.clusters[j].ntracks < 1)
220  continue;
221  if (mzb.clusters[j].ntracks > 5000)
222  continue;
227  l1t::TkJetWord::nt_t totalntracks_ = mzb.clusters[j].ntracks;
228  l1t::TkJetWord::nx_t totalxtracks_ = mzb.clusters[j].nxtracks;
229  l1t::TkJetWord::tkjetunassigned_t unassigned_ = 0;
230 
231  l1t::TkJetWord trkJet(jetPt, jetEta, jetPhi, jetZ0, totalntracks_, totalxtracks_, unassigned_);
232  //trkJet.setDispCounters(DispCounters);
233  L1L1TrackJetProducer->push_back(trkJet);
234  }
235  } else if (mzb.clusters == nullptr) {
236  edm::LogWarning("L1TrackJetEmulationProducer") << "mzb.clusters Not Assigned!\n";
237  }
238 
239  if (displaced_)
240  iEvent.put(std::move(L1L1TrackJetProducer), "L1TrackJetsExtended");
241  else
242  iEvent.put(std::move(L1L1TrackJetProducer), "L1TrackJets");
243  delete[] mzb.clusters;
244  } else if (L1TrkPtrs_.empty()) {
245  edm::LogWarning("L1TrackJetEmulationProducer") << "L1TrkPtrs Not Assigned!\n";
246  }
247 }
248 
250  enum TrackBitWidths {
251  kEtaSize = 16, // Width of z-position (40cm / 0.1)
252  kEtaMagSize = 3, // Width of z-position magnitude (signed)
253  kPtSize = 14, // Width of pt
254  kPtMagSize = 9, // Width of pt magnitude (unsigned)
255  kPhiSize = 12,
256  kPhiMagSize = 1,
257  };
258 
259  const int nz = zBins_ + 1;
260  TrackJetEmulationMaxZBin all_zBins[nz];
261  static TrackJetEmulationMaxZBin mzbtemp;
262  for (int z = 0; z < nz; ++z)
263  all_zBins[z] = mzbtemp;
264 
266  z0_intern zmax = zmin + 2 * zStep_;
267 
268  TrackJetEmulationEtaPhiBin epbins[phiBins_][etaBins_]; // create grid of phiBins
272  for (int i = 0; i < phiBins_; ++i) {
274  for (int j = 0; j < etaBins_; ++j) {
275  phimin = phi;
276  phimax = phi + phiStep_;
277  etamin = eta;
278  eta = eta + etaStep_;
279  etamax = eta;
280  epbins[i][j].phi = (phimin + phimax) / 2;
281  epbins[i][j].eta = (etamin + etamax) / 2;
282  epbins[i][j].pTtot = 0;
283  epbins[i][j].ntracks = 0;
284  epbins[i][j].nxtracks = 0;
285  } // for each etabin
286  phi = phi + phiStep_;
287  } // for each phibin (finished creating epbins)
288 
289  mzb = all_zBins[0];
290  mzb.ht = 0;
291  int ntracks = L1TrkPtrs_.size();
292  // uninitalized arrays
295 
296  for (int zbin = 0; zbin < zBins_; ++zbin) {
297  for (int i = 0; i < phiBins_; ++i) { //First initialize pT, numtracks, used to 0 (or false)
298  for (int j = 0; j < etaBins_; ++j) {
299  epbins[i][j].pTtot = 0;
300  epbins[i][j].used = false;
301  epbins[i][j].ntracks = 0;
302  epbins[i][j].nxtracks = 0;
303  } //for each etabin
304  L1clusters[i] = epbins[i];
305  } //for each phibin
306 
307  for (unsigned int k = 0; k < L1TrkPtrs_.size(); ++k) {
308  ap_ufixed<TrackBitWidths::kPtSize, TrackBitWidths::kPtMagSize, AP_RND_CONV, AP_SAT> inputTrkPt = 0;
309  inputTrkPt.V = L1TrkPtrs_[k]->getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1,
310  TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
311  pt_intern trkpt = inputTrkPt;
312 
313  ap_fixed<TrackBitWidths::kEtaSize, TrackBitWidths::kEtaMagSize, AP_RND_CONV, AP_SAT> trketainput = 0;
314  trketainput.V = L1TrkPtrs_[k]->getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kTanlMSB,
315  TTTrack_TrackWord::TrackBitLocations::kTanlLSB);
316  ap_ufixed<64 + ETA_EXTRABITS, 32 + ETA_EXTRABITS> eta_conv =
317  1.0 / convert::ETA_LSB; //conversion factor from input eta format to internal format
318  glbeta_intern trketa = eta_conv * trketainput;
319 
320  int Sector = L1TrkPtrs_[k]->phiSector();
321  glbphi_intern trkphiSector = 0;
322  if (Sector < 5) {
323  trkphiSector = Sector * convert::makeGlbPhi(2.0 * M_PI / 9.0);
324  } else {
325  trkphiSector =
326  convert::makeGlbPhi(-1.0 * M_PI + M_PI / 9.0) + (Sector - 5) * convert::makeGlbPhi(2.0 * M_PI / 9.0);
327  }
328 
329  ap_fixed<TrackBitWidths::kPhiSize, TrackBitWidths::kPhiMagSize, AP_RND_CONV, AP_SAT> trkphiinput = 0;
330  trkphiinput.V = L1TrkPtrs_[k]->getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kPhiMSB,
331  TTTrack_TrackWord::TrackBitLocations::kPhiLSB);
332  ap_ufixed<64 + PHI_EXTRABITS, 32 + PHI_EXTRABITS> phi_conv =
334  (1 << (TrackBitWidths::kPhiSize - TrackBitWidths::kPhiMagSize));
335  //phi_conv is a conversion factor from input phi format to the internal format
336  glbeta_intern localphi = phi_conv * trkphiinput;
337  glbeta_intern trkphi = localphi + trkphiSector;
338 
339  ap_int<TTTrack_TrackWord::TrackBitWidths::kZ0Size> inputTrkZ0 = L1TrkPtrs_[k]->getTrackWord()(
340  TTTrack_TrackWord::TrackBitLocations::kZ0MSB, TTTrack_TrackWord::TrackBitLocations::kZ0LSB);
341  ap_ufixed<32 + Z0_EXTRABITS, 1 + Z0_EXTRABITS> z0_conv =
342  TTTrack_TrackWord::stepZ0 / convert::Z0_LSB; //conversion factor from input z format to internal format
343  z0_intern trkZ = z0_conv * inputTrkZ0;
344 
345  for (int i = 0; i < phiBins_; ++i) {
346  for (int j = 0; j < etaBins_; ++j) {
347  L2cluster[k] = epbins[i][j];
348  if ((zmin <= trkZ && zmax >= trkZ) &&
349  ((epbins[i][j].eta - etaStep_ / 2 < trketa && epbins[i][j].eta + etaStep_ / 2 >= trketa) &&
350  epbins[i][j].phi - phiStep_ / 2 < trkphi && epbins[i][j].phi + phiStep_ / 2 >= trkphi &&
351  (zBinCount_[k] != 2))) {
352  zBinCount_.at(k) = zBinCount_.at(k) + 1;
353 
354  if (trkpt < convert::makePtFromFloat(trkPtMax_))
355  epbins[i][j].pTtot += trkpt;
356  else
358  ++epbins[i][j].ntracks;
359  //x-bit is currently not used in firmware, so we leave nxtracks = 0 for now
360  } // if right bin
361  } // for each phibin: j loop
362  } // for each phibin: i loop
363  } // end loop over tracks
364 
365  for (int phislice = 0; phislice < phiBins_; ++phislice) {
366  L1clusters[phislice] = L1_cluster(epbins[phislice]);
367  for (int ind = 0; L1clusters[phislice][ind].pTtot != 0; ++ind) {
368  L1clusters[phislice][ind].used = false;
369  }
370  }
371 
372  //Create clusters array to hold output cluster data for Layer2; can't have more clusters than tracks.
373  //Find eta-phibin with maxpT, make center of cluster, add neighbors if not already used.
374  pt_intern hipT = 0;
375  int nclust = 0;
376  int phibin = 0;
377  int imax = -1;
378  int index1; //index of clusters array for each phislice
379  pt_intern E1 = 0;
380  pt_intern E0 = 0;
381  pt_intern E2 = 0;
382  l1t::TkJetWord::nt_t ntrk1, ntrk2;
383  l1t::TkJetWord::nx_t nxtrk1, nxtrk2;
384  int used1, used2, used3, used4;
385 
386  for (phibin = 0; phibin < phiBins_; ++phibin) { //Find eta-phibin with highest pT
387  while (true) {
388  hipT = 0;
389  for (index1 = 0; L1clusters[phibin][index1].pTtot > 0; ++index1) {
390  if (!L1clusters[phibin][index1].used && L1clusters[phibin][index1].pTtot >= hipT) {
391  hipT = L1clusters[phibin][index1].pTtot;
392  imax = index1;
393  }
394  } // for each index within the phibin
395 
396  if (hipT == 0)
397  break; // If highest pT is 0, all bins are used
398  E0 = hipT; // E0 is pT of first phibin of the cluster
399  E1 = 0;
400  E2 = 0;
401  ntrk1 = 0;
402  ntrk2 = 0;
403  nxtrk1 = 0;
404  nxtrk2 = 0;
405  L2cluster[nclust] = L1clusters[phibin][imax];
406 
407  L1clusters[phibin][imax].used = true;
408  // Add pT of upper neighbor
409  // E1 is pT of the middle phibin (should be highest pT)
410  if (phibin != phiBins_ - 1) {
411  used1 = -1;
412  used2 = -1;
413  for (index1 = 0; L1clusters[phibin + 1][index1].pTtot != 0; ++index1) {
414  if (L1clusters[phibin + 1][index1].used)
415  continue;
416  if (L1clusters[phibin + 1][index1].eta - L1clusters[phibin][imax].eta <= 3 * etaStep_ / 2 &&
417  L1clusters[phibin][imax].eta - L1clusters[phibin + 1][index1].eta <= 3 * etaStep_ / 2) {
418  E1 += L1clusters[phibin + 1][index1].pTtot;
419  ntrk1 += L1clusters[phibin + 1][index1].ntracks;
420  nxtrk1 += L1clusters[phibin + 1][index1].nxtracks;
421  if (used1 < 0)
422  used1 = index1;
423  else
424  used2 = index1;
425  } // if cluster is within one phibin
426  } // for each cluster in above phibin
427 
428  if (E1 < E0) { // if E1 isn't higher, E0 and E1 are their own cluster
429  L2cluster[nclust].pTtot += E1;
430  L2cluster[nclust].ntracks += ntrk1;
431  L2cluster[nclust].nxtracks += nxtrk1;
432  if (used1 >= 0)
433  L1clusters[phibin + 1][used1].used = true;
434  if (used2 >= 0)
435  L1clusters[phibin + 1][used2].used = true;
436  nclust++;
437  continue;
438  }
439 
440  if (phibin != phiBins_ - 2) { // E2 will be the pT of the third phibin (should be lower than E1)
441  used3 = -1;
442  used4 = -1;
443  for (index1 = 0; L1clusters[phibin + 2][index1].pTtot != 0; ++index1) {
444  if (L1clusters[phibin + 2][index1].used)
445  continue;
446  if (L1clusters[phibin + 2][index1].eta - L1clusters[phibin][imax].eta <= 3 * etaStep_ / 2 &&
447  L1clusters[phibin][imax].eta - L1clusters[phibin + 2][index1].eta <= 3 * etaStep_ / 2) {
448  E2 += L1clusters[phibin + 2][index1].pTtot;
449  ntrk2 += L1clusters[phibin + 2][index1].ntracks;
450  nxtrk2 += L1clusters[phibin + 2][index1].nxtracks;
451  if (used3 < 0)
452  used3 = index1;
453  else
454  used4 = index1;
455  }
456  }
457  // if indeed E2 < E1, add E1 and E2 to E0, they're all a cluster together
458  // otherwise, E0 is its own cluster
459  if (E2 < E1) {
460  L2cluster[nclust].pTtot += E1 + E2;
461  L2cluster[nclust].ntracks += ntrk1 + ntrk2;
462  L2cluster[nclust].nxtracks += nxtrk1 + nxtrk2;
463  L2cluster[nclust].phi = L1clusters[phibin + 1][used1].phi;
464  if (used1 >= 0)
465  L1clusters[phibin + 1][used1].used = true;
466  if (used2 >= 0)
467  L1clusters[phibin + 1][used2].used = true;
468  if (used3 >= 0)
469  L1clusters[phibin + 2][used3].used = true;
470  if (used4 >= 0)
471  L1clusters[phibin + 2][used4].used = true;
472  }
473  nclust++;
474  continue;
475  } // end Not phiBins-2
476  else {
477  L2cluster[nclust].pTtot += E1;
478  L2cluster[nclust].ntracks += ntrk1;
479  L2cluster[nclust].nxtracks += nxtrk1;
480  L2cluster[nclust].phi = L1clusters[phibin + 1][used1].phi;
481  if (used1 >= 0)
482  L1clusters[phibin + 1][used1].used = true;
483  if (used2 >= 0)
484  L1clusters[phibin + 1][used2].used = true;
485  nclust++;
486  continue;
487  }
488  } //End not last phibin(23)
489  else { //if it is phibin 23
490  L1clusters[phibin][imax].used = true;
491  nclust++;
492  }
493  } // while hipT not 0
494  } // for each phibin
495 
496  for (phibin = 0; phibin < phiBins_; ++phibin)
497  delete[] L1clusters[phibin];
498 
499  // Now merge clusters, if necessary
500  for (int m = 0; m < nclust - 1; ++m) {
501  for (int n = m + 1; n < nclust; ++n) {
502  if (L2cluster[n].eta == L2cluster[m].eta &&
503  ((L2cluster[n].phi - L2cluster[m].phi < 3 * phiStep_ / 2 &&
504  L2cluster[m].phi - L2cluster[n].phi < 3 * phiStep_ / 2) ||
505  (L2cluster[n].phi - L2cluster[m].phi > 2 * convert::makeGlbPhi(M_PI) - phiStep_ ||
506  L2cluster[m].phi - L2cluster[n].phi > 2 * convert::makeGlbPhi(M_PI) - phiStep_))) {
507  if (L2cluster[n].pTtot > L2cluster[m].pTtot) {
508  L2cluster[m].phi = L2cluster[n].phi;
509  }
510  L2cluster[m].pTtot += L2cluster[n].pTtot;
511  L2cluster[m].ntracks += L2cluster[n].ntracks;
512  L2cluster[m].nxtracks += L2cluster[n].nxtracks;
513  for (int m1 = n; m1 < nclust - 1; ++m1) {
514  L2cluster[m1] = L2cluster[m1 + 1];
515  }
516  nclust--;
517  m = -1;
518  break; //?????
519  } // end if clusters neighbor in eta
520  }
521  } // end for (m) loop
522  // sum up all pTs in this zbin to find ht
523 
524  pt_intern ht = 0;
525  for (int k = 0; k < nclust; ++k) {
526  if (L2cluster[k].pTtot > convert::makePtFromFloat(lowpTJetMinpT_) &&
528  continue;
529  if (L2cluster[k].pTtot > convert::makePtFromFloat(highpTJetMinpT_) &&
531  continue;
532  if (L2cluster[k].pTtot > convert::makePtFromFloat(minTrkJetpT_))
533  ht += L2cluster[k].pTtot;
534  }
535  // if ht is larger than previous max, this is the new vertex zbin
536  all_zBins[zbin].znum = zbin;
537  all_zBins[zbin].clusters = new TrackJetEmulationEtaPhiBin[nclust];
538  all_zBins[zbin].nclust = nclust;
539  all_zBins[zbin].zbincenter = (zmin + zmax) / 2;
540  for (int k = 0; k < nclust; ++k) {
541  all_zBins[zbin].clusters[k].phi = L2cluster[k].phi;
542  all_zBins[zbin].clusters[k].eta = L2cluster[k].eta;
543  all_zBins[zbin].clusters[k].pTtot = L2cluster[k].pTtot;
544  all_zBins[zbin].clusters[k].ntracks = L2cluster[k].ntracks;
545  all_zBins[zbin].clusters[k].nxtracks = L2cluster[k].nxtracks;
546  }
547  all_zBins[zbin].ht = ht;
548  if (ht >= mzb.ht) {
549  mzb = all_zBins[zbin];
550  mzb.zbincenter = (zmin + zmax) / 2;
551  }
552  // Prepare for next zbin!
553  zmin = zmin + zStep_;
554  zmax = zmax + zStep_;
555  } // for each zbin
556 
557  for (int zbin = 0; zbin < zBins_; ++zbin) {
558  if (zbin == mzb.znum) {
559  continue;
560  }
561  delete[] all_zBins[zbin].clusters;
562  }
563 }
564 
567  for (int etabin = 0; etabin < etaBins_ / 2; ++etabin) {
568  clusters[etabin].pTtot = 0;
569  clusters[etabin].ntracks = 0;
570  clusters[etabin].nxtracks = 0;
571  clusters[etabin].phi = 0;
572  clusters[etabin].eta = 0;
573  clusters[etabin].used = false;
574  }
575 
576  if (clusters == nullptr)
577  edm::LogWarning("L1TrackJetEmulationProducer") << "Clusters memory not assigned!\n";
578 
579  // Find eta-phibin with maxpT, make center of cluster, add neighbors if not already used
580  pt_intern my_pt, left_pt, right_pt, right2pt;
581  int nclust = 0;
582  right2pt = 0;
583  for (int etabin = 0; etabin < etaBins_; ++etabin) {
584  // assign values for my pT and neighbors' pT
585  if (phislice[etabin].used)
586  continue;
587  my_pt = phislice[etabin].pTtot;
588  if (etabin > 0 && !phislice[etabin - 1].used) {
589  left_pt = phislice[etabin - 1].pTtot;
590  } else
591  left_pt = 0;
592  if (etabin < etaBins_ - 1 && !phislice[etabin + 1].used) {
593  right_pt = phislice[etabin + 1].pTtot;
594  if (etabin < etaBins_ - 2 && !phislice[etabin + 2].used) {
595  right2pt = phislice[etabin + 2].pTtot;
596  } else
597  right2pt = 0;
598  } else
599  right_pt = 0;
600 
601  // if I'm not a cluster, move on
602  if (my_pt < left_pt || my_pt <= right_pt) {
603  // if unused pT in the left neighbor, spit it out as a cluster
604  if (left_pt > 0) {
605  clusters[nclust] = phislice[etabin - 1];
606  phislice[etabin - 1].used = true;
607  nclust++;
608  }
609  continue;
610  }
611 
612  // I guess I'm a cluster-- should I use my right neighbor?
613  // Note: left neighbor will definitely be used because if it
614  // didn't belong to me it would have been used already
615  clusters[nclust] = phislice[etabin];
616  phislice[etabin].used = true;
617  if (left_pt > 0) {
618  clusters[nclust].pTtot += left_pt;
619  clusters[nclust].ntracks += phislice[etabin - 1].ntracks;
620  clusters[nclust].nxtracks += phislice[etabin - 1].nxtracks;
621  }
622  if (my_pt >= right2pt && right_pt > 0) {
623  clusters[nclust].pTtot += right_pt;
624  clusters[nclust].ntracks += phislice[etabin + 1].ntracks;
625  clusters[nclust].nxtracks += phislice[etabin + 1].nxtracks;
626  phislice[etabin + 1].used = true;
627  }
628  nclust++;
629  } // for each etabin
630 
631  // Now merge clusters, if necessary
632  for (int m = 0; m < nclust - 1; ++m) {
633  if (clusters[m + 1].eta - clusters[m].eta < 3 * etaStep_ / 2 &&
634  clusters[m].eta - clusters[m + 1].eta < 3 * etaStep_ / 2) {
635  if (clusters[m + 1].pTtot > clusters[m].pTtot) {
636  clusters[m].eta = clusters[m + 1].eta;
637  }
638  clusters[m].pTtot += clusters[m + 1].pTtot;
639  clusters[m].ntracks += clusters[m + 1].ntracks; // Previous version didn't add tracks when merging
640  clusters[m].nxtracks += clusters[m + 1].nxtracks;
641  for (int m1 = m + 1; m1 < nclust - 1; ++m1)
642  clusters[m1] = clusters[m1 + 1];
643  nclust--;
644  m = -1;
645  } // end if clusters neighbor in eta
646  } // end for (m) loop
647 
648  for (int i = nclust; i < etaBins_ / 2; ++i) // zero out remaining unused clusters
649  clusters[i].pTtot = 0;
650  return clusters;
651 }
652 
654 
656 
657 bool L1TrackJetEmulationProducer::trackQualityCuts(int trk_nstub, float trk_chi2, float trk_bendchi2) {
658  bool PassQuality = false;
659  if (trk_bendchi2 < trkBendChi2Max_ && trk_chi2 < trkChi2dofMax_ && trk_nstub >= 4 && !displaced_)
660  PassQuality = true;
661  if (displaced_ && trk_bendchi2 < nStubs4DisplacedBend_ && trk_chi2 < nStubs4DisplacedChi2_ && trk_nstub == 4)
662  PassQuality = true;
663  if (displaced_ && trk_bendchi2 < nStubs5DisplacedBend_ && trk_chi2 < nStubs5DisplacedChi2_ && trk_nstub > 4)
664  PassQuality = true;
665  return PassQuality;
666 }
667 
669  //The following says we do not know what parameters are allowed so do no validation
670  // Please change this to state exactly what you do use, even if it is no parameters
672  desc.setUnknown();
673  descriptions.addDefault(desc);
674 }
675 
676 //define this as a plug-in
static const float ETA_LSB_POW
pt_intern makePtFromFloat(float pt)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int tobLayer(const DetId &id) const
std::vector< l1t::TkJetWord > TkJetWordCollection
Definition: TkJetWord.h:174
static const float Z0_LSB_POW
T perp() const
Definition: PV3DBase.h:69
ap_int< kGlbEtaSize > glbeta_t
Definition: TkJetWord.h:52
ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
glbeta_intern makeGlbEta(float eta)
ap_int< 14+PHI_EXTRABITS > glbphi_intern
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T eta() const
Definition: PV3DBase.h:73
static const float ETA_LSB
z0_intern makeZ0(float z0)
vector< L1TTTrackType > L1TTTrackCollectionType
ap_int< kGlbPhiSize > glbphi_t
Definition: TkJetWord.h:53
delete x;
Definition: CaloConfig.h:22
void L2_cluster(vector< Ptr< L1TTTrackType >> L1TrkPtrs_, TrackJetEmulationMaxZBin &mzb)
bool trackQualityCuts(int trk_nstub, float trk_chi2, float trk_bendchi2)
ap_ufixed< kPtSize, kPtMagSize, AP_TRN, AP_SAT > pt_t
Definition: TkJetWord.h:51
static const float PHI_LSB_POW
ap_uint< TkJetBitWidths::kUnassignedSize > tkjetunassigned_t
Definition: TkJetWord.h:57
ap_int< kZ0Size > z0_t
Definition: TkJetWord.h:54
static void fillDescriptions(ConfigurationDescriptions &descriptions)
GlobalVector momentum() const
Track momentum.
Definition: TTTrack.h:295
ap_ufixed< 16+PT_EXTRABITS, 11, AP_TRN, AP_SAT > pt_intern
ap_int< 10+Z0_EXTRABITS > z0_intern
ap_int< 14+ETA_EXTRABITS > glbeta_intern
glbphi_intern makeGlbPhi(float phi)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
static const float PHI_LSB
void produce(Event &, const EventSetup &) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< VertexWord > VertexWordCollection
Definition: VertexWord.h:195
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static constexpr auto TOB
const EDGetTokenT< l1t::VertexWordCollection > PVtxToken_
ap_uint< kXtSize > nx_t
Definition: TkJetWord.h:56
std::vector< edm::Ref< edmNew::DetSetVector< TTStub< T > >, TTStub< T > > > getStubRefs() const
Track components.
Definition: TTTrack.h:93
#define M_PI
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
double stubPtConsistency() const
StubPtConsistency.
Definition: TTTrack.h:417
static constexpr double stepPhi0
double d0() const
Track d0.
Definition: TTTrack.h:325
vector< Ptr< L1TTTrackType > > L1TrkPtrs_
HLT enums.
double chi2Red() const
Chi2 reduced.
Definition: TTTrack.h:359
ap_uint< kNtSize > nt_t
Definition: TkJetWord.h:55
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
double z0() const
Track z0.
Definition: TTTrack.h:330
TrackJetEmulationEtaPhiBin * clusters
unsigned int tidRing(const DetId &id) const
const EDGetTokenT< vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Log< level::Warning, false > LogWarning
static constexpr double stepZ0
static constexpr auto TID
static const float Z0_LSB
def move(src, dest)
Definition: eostools.py:511
L1TrackJetEmulationProducer(const ParameterSet &)
virtual TrackJetEmulationEtaPhiBin * L1_cluster(TrackJetEmulationEtaPhiBin *phislice)