CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TrackJetProducer.cc
Go to the documentation of this file.
1 // Original Author: Rishi Patel
2 // Created: Wed, 01 Aug 2018 14:01:41 GMT
3 //
4 // Track jets are clustered in a two-layer process, first by clustering in phi,
5 // then by clustering in eta
6 // Introduction to object (p10-13):
7 // https://indico.cern.ch/event/791517/contributions/3341650/attachments/1818736/2973771/TrackBasedAlgos_L1TMadrid_MacDonald.pdf
8 
9 // system include files
10 
16 // user include files
28 
30 #include "TH1D.h"
31 #include "TH2D.h"
32 #include <TMath.h>
33 #include <cmath>
34 #include <cstdlib>
35 #include <fstream>
36 #include <iostream>
37 #include <memory>
38 #include <string>
39 
40 using namespace std;
41 using namespace edm;
42 using namespace l1t;
44 public:
45  explicit L1TrackJetProducer(const ParameterSet &);
46  ~L1TrackJetProducer() override;
48  typedef vector<L1TTTrackType> L1TTTrackCollectionType;
49 
50  static void fillDescriptions(ConfigurationDescriptions &descriptions);
51  bool trackQualityCuts(float trk_pt, int trk_nstub, float trk_chi2, float trk_bendchi2, float trk_d0);
52  void L2_cluster(
53  vector<Ptr<L1TTTrackType> > L1TrkPtrs_, vector<int> ttrk_, vector<int> tdtrk_, vector<int> ttdtrk_, MaxZBin &mzb);
54  virtual EtaPhiBin *L1_cluster(EtaPhiBin *phislice);
55 
56 private:
57  void beginStream(StreamID) override;
58  void produce(Event &, const EventSetup &) override;
59  void endStream() override;
60 
61  // ----------member data ---------------------------
62 
65 
66  vector<Ptr<L1TTTrackType> > L1TrkPtrs_;
67  vector<int> zBinCount_;
68  vector<int> ttrk_;
69  vector<int> tdtrk_;
70  vector<int> ttdtrk_;
71  float trkZMax_;
72  float trkPtMax_;
73  float trkPtMin_;
74  float trkEtaMax_;
80  int zBins_;
81  int etaBins_;
82  int phiBins_;
83  double minTrkJetpT_;
86  float zStep_;
87  float etaStep_;
88  float phiStep_;
89  bool displaced_;
100 };
101 
103  : trackToken_(
104  consumes<vector<TTTrack<Ref_Phase2TrackerDigi_> > >(iConfig.getParameter<InputTag>("L1TrackInputTag"))),
106  trkZMax_ = (float)iConfig.getParameter<double>("trk_zMax");
107  trkPtMax_ = (float)iConfig.getParameter<double>("trk_ptMax");
108  trkPtMin_ = (float)iConfig.getParameter<double>("trk_ptMin");
109  trkEtaMax_ = (float)iConfig.getParameter<double>("trk_etaMax");
110  trkChi2dofMax_ = (float)iConfig.getParameter<double>("trk_chi2dofMax");
111  trkBendChi2Max_ = (float)iConfig.getParameter<double>("trk_bendChi2Max");
112  trkNPSStubMin_ = (int)iConfig.getParameter<int>("trk_nPSStubMin");
113  minTrkJetpT_ = iConfig.getParameter<double>("minTrkJetpT");
114  minJetEtLowPt_ = iConfig.getParameter<double>("minJetEtLowPt");
115  minJetEtHighPt_ = iConfig.getParameter<double>("minJetEtHighPt");
116  etaBins_ = (int)iConfig.getParameter<int>("etaBins");
117  phiBins_ = (int)iConfig.getParameter<int>("phiBins");
118  zBins_ = (int)iConfig.getParameter<int>("zBins");
119  d0CutNStubs4_ = (float)iConfig.getParameter<double>("d0_cutNStubs4");
120  d0CutNStubs5_ = (float)iConfig.getParameter<double>("d0_cutNStubs5");
121  lowpTJetMinTrackMultiplicity_ = (int)iConfig.getParameter<int>("lowpTJetMinTrackMultiplicity");
122  highpTJetMinTrackMultiplicity_ = (int)iConfig.getParameter<int>("highpTJetMinTrackMultiplicity");
123  displaced_ = iConfig.getParameter<bool>("displaced");
124  nStubs4DisplacedChi2Loose_ = (float)iConfig.getParameter<double>("nStubs4DisplacedChi2_Loose");
125  nStubs5DisplacedChi2Loose_ = (float)iConfig.getParameter<double>("nStubs5DisplacedChi2_Loose");
126  nStubs4DisplacedBendLoose_ = (float)iConfig.getParameter<double>("nStubs4Displacedbend_Loose");
127  nStubs5DisplacedBendLoose_ = (float)iConfig.getParameter<double>("nStubs5Displacedbend_Loose");
128  nStubs4DisplacedChi2Tight_ = (float)iConfig.getParameter<double>("nStubs4DisplacedChi2_Tight");
129  nStubs5DisplacedChi2Tight_ = (float)iConfig.getParameter<double>("nStubs5DisplacedChi2_Tight");
130  nStubs4DisplacedBendTight_ = (float)iConfig.getParameter<double>("nStubs4Displacedbend_Tight");
131  nStubs5DisplacedBendTight_ = (float)iConfig.getParameter<double>("nStubs5Displacedbend_Tight");
132 
133  zStep_ = 2.0 * trkZMax_ / zBins_;
134  etaStep_ = 2.0 * trkEtaMax_ / etaBins_; //etaStep is the width of an etabin
135  phiStep_ = 2 * M_PI / phiBins_;
136 
137  if (displaced_)
138  produces<TkJetCollection>("L1TrackJetsExtended");
139  else
140  produces<TkJetCollection>("L1TrackJets");
141 }
142 
144 
146  unique_ptr<TkJetCollection> L1L1TrackJetProducer(new TkJetCollection);
147 
148  // For TTStubs
149  const TrackerTopology &tTopo = iSetup.getData(tTopoToken_);
150 
152  iEvent.getByToken(trackToken_, TTTrackHandle);
153  vector<TTTrack<Ref_Phase2TrackerDigi_> >::const_iterator iterL1Track;
154 
155  L1TrkPtrs_.clear();
156  zBinCount_.clear();
157  ttrk_.clear();
158  tdtrk_.clear();
159  ttdtrk_.clear();
160 
161  unsigned int this_l1track = 0;
162  for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) {
163  edm::Ptr<L1TTTrackType> trkPtr(TTTrackHandle, this_l1track);
164  this_l1track++;
165  float trk_pt = trkPtr->momentum().perp();
166  int trk_nstubs = (int)trkPtr->getStubRefs().size();
167  float trk_chi2dof = trkPtr->chi2Red();
168  float trk_d0 = trkPtr->d0();
169  float trk_bendchi2 = trkPtr->stubPtConsistency();
170 
171  int trk_nPS = 0;
172  for (int istub = 0; istub < trk_nstubs; istub++) { // loop over the stubs
173  DetId detId(trkPtr->getStubRefs().at(istub)->getDetId());
174  if (detId.det() == DetId::Detector::Tracker) {
175  if ((detId.subdetId() == StripSubdetector::TOB && tTopo.tobLayer(detId) <= 3) ||
176  (detId.subdetId() == StripSubdetector::TID && tTopo.tidRing(detId) <= 9))
177  trk_nPS++;
178  }
179  }
180 
181  if (trk_nPS < trkNPSStubMin_)
182  continue;
183  if (!trackQualityCuts(trk_pt, trk_nstubs, trk_chi2dof, trk_bendchi2, fabs(trk_d0)))
184  continue;
185  if (fabs(iterL1Track->z0()) > trkZMax_)
186  continue;
187  if (fabs(iterL1Track->momentum().eta()) > trkEtaMax_)
188  continue;
189  if (trk_pt < trkPtMin_)
190  continue;
191  L1TrkPtrs_.push_back(trkPtr);
192  zBinCount_.push_back(0);
193 
194  if ((fabs(trk_d0) > d0CutNStubs5_ && trk_nstubs >= 5) || (trk_nstubs == 4 && fabs(trk_d0) > d0CutNStubs4_))
195  tdtrk_.push_back(1);
196  else
197  tdtrk_.push_back(0); //displaced track
198  if ((trk_nstubs >= 5 && trk_chi2dof < nStubs5DisplacedChi2Tight_ && trk_bendchi2 < nStubs5DisplacedBendTight_) ||
199  (trk_nstubs == 4 && trk_chi2dof < nStubs4DisplacedChi2Tight_ && trk_bendchi2 < nStubs4DisplacedBendTight_))
200  ttrk_.push_back(1);
201  else
202  ttrk_.push_back(0);
203  if ((trk_nstubs >= 5 && trk_chi2dof < nStubs5DisplacedChi2Tight_ && trk_bendchi2 < nStubs5DisplacedBendTight_ &&
204  fabs(trk_d0) > d0CutNStubs5_) ||
205  (trk_nstubs == 4 && trk_chi2dof < nStubs4DisplacedChi2Tight_ && trk_bendchi2 < nStubs4DisplacedBendTight_ &&
206  fabs(trk_d0) > d0CutNStubs4_))
207  ttdtrk_.push_back(1);
208  else
209  ttdtrk_.push_back(0);
210  }
211 
212  if (!L1TrkPtrs_.empty()) {
213  MaxZBin mzb;
214 
216  edm::Ref<JetBxCollection> jetRef; //null, no Calo Jet Ref
217  vector<Ptr<L1TTTrackType> > L1TrackAssocJet;
218  if (mzb.clusters != nullptr) {
219  for (int j = 0; j < mzb.nclust; ++j) {
220  //FILL Two Layer Jets for Jet Collection
221  if (mzb.clusters[j].pTtot <= trkPtMin_)
222  continue; //protects against reading bad memory
223  if (mzb.clusters[j].numtracks < 1)
224  continue;
225  if (mzb.clusters[j].numtracks > 5000)
226  continue;
227  float jetEta = mzb.clusters[j].eta;
228  float jetPhi = mzb.clusters[j].phi;
229  float jetPt = mzb.clusters[j].pTtot;
230  float jetPx = jetPt * cos(jetPhi);
231  float jetPy = jetPt * sin(jetPhi);
232  float jetPz = jetPt * sinh(jetEta);
233  float jetP = jetPt * cosh(jetEta);
234  int totalTighttrk_ = mzb.clusters[j].numttrks;
235  int totalDisptrk = mzb.clusters[j].numtdtrks;
236  int totalTightDisptrk = mzb.clusters[j].numttdtrks;
237 
238  math::XYZTLorentzVector jetP4(jetPx, jetPy, jetPz, jetP);
239  L1TrackAssocJet.clear();
240  for (unsigned int t = 0; t < L1TrkPtrs_.size(); ++t) {
241  if (L1TrackAssocJet.size() == (unsigned int)mzb.clusters[j].numtracks)
242  break;
243  float deta = L1TrkPtrs_[t]->momentum().eta() - jetEta;
244  float dphi = L1TrkPtrs_[t]->momentum().phi() - jetPhi;
245  float dZ = fabs(mzb.zbincenter - L1TrkPtrs_[t]->z0());
246  if (dZ < zStep_ && fabs(deta) < etaStep_ * 2.0 && fabs(dphi) < phiStep_ * 2.0) {
247  L1TrackAssocJet.push_back(L1TrkPtrs_[t]);
248  }
249  }
250  TkJet trkJet(jetP4,
251  L1TrackAssocJet,
252  mzb.zbincenter,
253  mzb.clusters[j].numtracks,
254  totalTighttrk_,
255  totalDisptrk,
256  totalTightDisptrk);
257  //trkJet.setDispCounters(DispCounters);
258  if (!L1TrackAssocJet.empty())
259  L1L1TrackJetProducer->push_back(trkJet);
260  }
261  }
262  //free(mzb.clusters);
263  if (displaced_)
264  iEvent.put(std::move(L1L1TrackJetProducer), "L1TrackJetsExtended");
265  else
266  iEvent.put(std::move(L1L1TrackJetProducer), "L1TrackJets");
267  delete[] mzb.clusters;
268  }
269 }
270 
272  vector<Ptr<L1TTTrackType> > L1TrkPtrs_, vector<int> ttrk_, vector<int> tdtrk_, vector<int> ttdtrk_, MaxZBin &mzb) {
273  const int nz = zBins_;
274  MaxZBin all_zBins[nz];
275  for (int z = 0; z < nz; ++z)
276  all_zBins[z] = MaxZBin{0, 0, 0, nullptr, 0};
277 
278  float zmin = -1.0 * trkZMax_;
279  float zmax = zmin + 2 * zStep_;
280 
281  EtaPhiBin epbins[phiBins_][etaBins_]; // create grid of phiBins
282  float phi = -1.0 * M_PI;
283  float eta;
284  float etamin, etamax, phimin, phimax;
285  for (int i = 0; i < phiBins_; ++i) {
286  eta = -1.0 * trkEtaMax_;
287  for (int j = 0; j < etaBins_; ++j) {
288  phimin = phi;
289  phimax = phi + phiStep_;
290  etamin = eta;
291  eta = eta + etaStep_;
292  etamax = eta;
293  epbins[i][j].phi = (phimin + phimax) / 2.0;
294  epbins[i][j].eta = (etamin + etamax) / 2.0;
295  } // for each etabin
296  phi = phi + phiStep_;
297  } // for each phibin (finished creating epbins)
298  mzb = all_zBins[0];
299  int ntracks = L1TrkPtrs_.size();
300  // uninitalized arrays
301  EtaPhiBin *L1clusters[phiBins_];
302  EtaPhiBin L2cluster[ntracks];
303 
304  for (int zbin = 0; zbin < zBins_ - 1; ++zbin) {
305  for (int i = 0; i < phiBins_; ++i) { //First initialize pT, numtracks, used to 0 (or false)
306  for (int j = 0; j < etaBins_; ++j) {
307  epbins[i][j].pTtot = 0;
308  epbins[i][j].used = false;
309  epbins[i][j].numtracks = 0;
310  epbins[i][j].numttrks = 0;
311  epbins[i][j].numtdtrks = 0;
312  epbins[i][j].numttdtrks = 0;
313  } //for each etabin
314  L1clusters[i] = epbins[i];
315  } //for each phibin
316 
317  for (unsigned int k = 0; k < L1TrkPtrs_.size(); ++k) {
318  float trkpt = L1TrkPtrs_[k]->momentum().perp();
319  float trketa = L1TrkPtrs_[k]->momentum().eta();
320  float trkphi = L1TrkPtrs_[k]->momentum().phi();
321  float trkZ = L1TrkPtrs_[k]->z0();
322 
323  for (int i = 0; i < phiBins_; ++i) {
324  for (int j = 0; j < etaBins_; ++j) {
325  L2cluster[k] = epbins[i][j];
326  if ((zmin <= trkZ && zmax >= trkZ) &&
327  ((epbins[i][j].eta - etaStep_ / 2.0 <= trketa && epbins[i][j].eta + etaStep_ / 2.0 >= trketa) &&
328  epbins[i][j].phi - phiStep_ / 2.0 <= trkphi && epbins[i][j].phi + phiStep_ / 2.0 >= trkphi &&
329  (zBinCount_[k] != 2))) {
330  zBinCount_.at(k) = zBinCount_.at(k) + 1;
331  if (trkpt < trkPtMax_)
332  epbins[i][j].pTtot += trkpt;
333  else
334  epbins[i][j].pTtot += trkPtMax_;
335  epbins[i][j].numttrks += ttrk_[k];
336  epbins[i][j].numtdtrks += tdtrk_[k];
337  epbins[i][j].numttdtrks += ttdtrk_[k];
338  ++epbins[i][j].numtracks;
339  } // if right bin
340  } // for each phibin: j loop
341  } // for each phibin: i loop
342  } // end loop over tracks
343 
344  for (int phislice = 0; phislice < phiBins_; ++phislice) {
345  L1clusters[phislice] = L1_cluster(epbins[phislice]);
346  if (L1clusters[phislice] != nullptr) {
347  for (int ind = 0; L1clusters[phislice][ind].pTtot != 0; ++ind) {
348  L1clusters[phislice][ind].used = false;
349  }
350  }
351  }
352 
353  //Create clusters array to hold output cluster data for Layer2; can't have more clusters than tracks.
354  //Find eta-phibin with maxpT, make center of cluster, add neighbors if not already used.
355  float hipT = 0;
356  int nclust = 0;
357  int phibin = 0;
358  int imax = -1;
359  int index1; //index of clusters array for each phislice
360  float E1 = 0;
361  float E0 = 0;
362  float E2 = 0;
363  int trx1, trx2;
364  int ttrk1, ttrk2;
365  int tdtrk1, tdtrk2;
366  int ttdtrk1, ttdtrk2;
367  int used1, used2, used3, used4;
368 
369  for (phibin = 0; phibin < phiBins_; ++phibin) { //Find eta-phibin with highest pT
370  while (true) {
371  hipT = 0;
372  for (index1 = 0; L1clusters[phibin][index1].pTtot > 0; ++index1) {
373  if (!L1clusters[phibin][index1].used && L1clusters[phibin][index1].pTtot >= hipT) {
374  hipT = L1clusters[phibin][index1].pTtot;
375  imax = index1;
376  }
377  } // for each index within the phibin
378 
379  if (hipT == 0)
380  break; // If highest pT is 0, all bins are used
381  E0 = hipT; // E0 is pT of first phibin of the cluster
382  E1 = 0;
383  E2 = 0;
384  trx1 = 0;
385  trx2 = 0;
386  ttrk1 = 0;
387  ttrk2 = 0;
388  tdtrk1 = 0;
389  tdtrk2 = 0;
390  ttdtrk1 = 0;
391  ttdtrk2 = 0;
392  L2cluster[nclust] = L1clusters[phibin][imax];
393  L1clusters[phibin][imax].used = true;
394  // Add pT of upper neighbor
395  // E1 is pT of the middle phibin (should be highest pT)
396  if (phibin != phiBins_ - 1) {
397  used1 = -1;
398  used2 = -1;
399  for (index1 = 0; L1clusters[phibin + 1][index1].pTtot != 0; ++index1) {
400  if (L1clusters[phibin + 1][index1].used)
401  continue;
402  if (fabs(L1clusters[phibin + 1][index1].eta - L1clusters[phibin][imax].eta) <= 1.5 * etaStep_) {
403  E1 += L1clusters[phibin + 1][index1].pTtot;
404  trx1 += L1clusters[phibin + 1][index1].numtracks;
405  ttrk1 += L1clusters[phibin + 1][index1].numttrks;
406  tdtrk1 += L1clusters[phibin + 1][index1].numtdtrks;
407  ttdtrk1 += L1clusters[phibin + 1][index1].numttdtrks;
408  if (used1 < 0)
409  used1 = index1;
410  else
411  used2 = index1;
412  } // if cluster is within one phibin
413  } // for each cluster in above phibin
414 
415  if (E1 < E0) { // if E1 isn't higher, E0 and E1 are their own cluster
416  L2cluster[nclust].pTtot += E1;
417  L2cluster[nclust].numtracks += trx1;
418  L2cluster[nclust].numttrks += ttrk1;
419  L2cluster[nclust].numtdtrks += tdtrk1;
420  L2cluster[nclust].numttdtrks += ttdtrk1;
421  if (used1 >= 0)
422  L1clusters[phibin + 1][used1].used = true;
423  if (used2 >= 0)
424  L1clusters[phibin + 1][used2].used = true;
425  nclust++;
426  continue;
427  }
428 
429  if (phibin != phiBins_ - 2) { // E2 will be the pT of the third phibin (should be lower than E1)
430  used3 = -1;
431  used4 = -1;
432  for (index1 = 0; L1clusters[phibin + 2][index1].pTtot != 0; ++index1) {
433  if (L1clusters[phibin + 2][index1].used)
434  continue;
435  if (fabs(L1clusters[phibin + 2][index1].eta - L1clusters[phibin][imax].eta) <= 1.5 * etaStep_) {
436  E2 += L1clusters[phibin + 2][index1].pTtot;
437  trx2 += L1clusters[phibin + 2][index1].numtracks;
438  ttrk2 += L1clusters[phibin + 2][index1].numttrks;
439  tdtrk2 += L1clusters[phibin + 2][index1].numtdtrks;
440  ttdtrk2 += L1clusters[phibin + 2][index1].numttdtrks;
441  if (used3 < 0)
442  used3 = index1;
443  else
444  used4 = index1;
445  }
446  }
447  // if indeed E2 < E1, add E1 and E2 to E0, they're all a cluster together
448  // otherwise, E0 is its own cluster
449  if (E2 < E1) {
450  L2cluster[nclust].pTtot += E1 + E2;
451  L2cluster[nclust].numtracks += trx1 + trx2;
452  L2cluster[nclust].numttrks += ttrk1 + ttrk2;
453  L2cluster[nclust].numtdtrks += tdtrk1 + tdtrk2;
454  L2cluster[nclust].numttdtrks += ttdtrk1 + ttdtrk2;
455  L2cluster[nclust].phi = L1clusters[phibin + 1][used1].phi;
456  if (used1 >= 0)
457  L1clusters[phibin + 1][used1].used = true;
458  if (used2 >= 0)
459  L1clusters[phibin + 1][used2].used = true;
460  if (used3 >= 0)
461  L1clusters[phibin + 2][used3].used = true;
462  if (used4 >= 0)
463  L1clusters[phibin + 2][used4].used = true;
464  }
465  nclust++;
466  continue;
467  } // end Not phiBins-2
468  else {
469  L2cluster[nclust].pTtot += E1;
470  L2cluster[nclust].numtracks += trx1;
471  L2cluster[nclust].numttrks += ttrk1;
472  L2cluster[nclust].numtdtrks += tdtrk1;
473  L2cluster[nclust].numttdtrks += ttdtrk1;
474  L2cluster[nclust].phi = L1clusters[phibin + 1][used1].phi;
475  if (used1 >= 0)
476  L1clusters[phibin + 1][used1].used = true;
477  if (used2 >= 0)
478  L1clusters[phibin + 1][used2].used = true;
479  nclust++;
480  continue;
481  }
482  } //End not last phibin(23)
483  else { //if it is phibin 23
484  L1clusters[phibin][imax].used = true;
485  nclust++;
486  }
487  } // while hipT not 0
488  } // for each phibin
489 
490  for (phibin = 0; phibin < phiBins_; ++phibin)
491  delete[] L1clusters[phibin];
492 
493  // Now merge clusters, if necessary
494  for (int m = 0; m < nclust - 1; ++m) {
495  for (int n = m + 1; n < nclust; ++n)
496  if (L2cluster[n].eta == L2cluster[m].eta && (fabs(L2cluster[n].phi - L2cluster[m].phi) < 1.5 * phiStep_ ||
497  fabs(L2cluster[n].phi - L2cluster[m].phi) > 6.0)) {
498  if (L2cluster[n].pTtot > L2cluster[m].pTtot)
499  L2cluster[m].phi = L2cluster[n].phi;
500  L2cluster[m].pTtot += L2cluster[n].pTtot;
501  L2cluster[m].numtracks += L2cluster[n].numtracks;
502  L2cluster[m].numttrks += L2cluster[n].numttrks;
503  L2cluster[m].numtdtrks += L2cluster[n].numtdtrks;
504  L2cluster[m].numttdtrks += L2cluster[n].numttdtrks;
505  for (int m1 = n; m1 < nclust - 1; ++m1)
506  L2cluster[m1] = L2cluster[m1 + 1];
507  nclust--;
508  m = -1;
509  break; //?????
510  } // end if clusters neighbor in eta
511  } // end for (m) loop
512 
513  // sum up all pTs in this zbin to find ht
514  float ht = 0;
515  for (int k = 0; k < nclust; ++k) {
516  if (L2cluster[k].pTtot > minJetEtLowPt_ && L2cluster[k].numtracks < lowpTJetMinTrackMultiplicity_)
517  continue;
518  if (L2cluster[k].pTtot > minJetEtHighPt_ && L2cluster[k].numtracks < highpTJetMinTrackMultiplicity_)
519  continue;
520  if (L2cluster[k].pTtot > minTrkJetpT_)
521  ht += L2cluster[k].pTtot;
522  }
523 
524  // if ht is larger than previous max, this is the new vertex zbin
525  all_zBins[zbin].znum = zbin;
526  all_zBins[zbin].clusters = new EtaPhiBin[nclust];
527  all_zBins[zbin].nclust = nclust;
528  all_zBins[zbin].zbincenter = (zmin + zmax) / 2.0;
529  for (int k = 0; k < nclust; ++k) {
530  all_zBins[zbin].clusters[k].phi = L2cluster[k].phi;
531  all_zBins[zbin].clusters[k].eta = L2cluster[k].eta;
532  all_zBins[zbin].clusters[k].pTtot = L2cluster[k].pTtot;
533  all_zBins[zbin].clusters[k].numtracks = L2cluster[k].numtracks;
534  all_zBins[zbin].clusters[k].numttrks = L2cluster[k].numttrks;
535  all_zBins[zbin].clusters[k].numtdtrks = L2cluster[k].numtdtrks;
536  all_zBins[zbin].clusters[k].numttdtrks = L2cluster[k].numttdtrks;
537  }
538  all_zBins[zbin].ht = ht;
539  if (ht >= mzb.ht) {
540  mzb = all_zBins[zbin];
541  mzb.zbincenter = (zmin + zmax) / 2.0;
542  }
543  // Prepare for next zbin!
544  zmin = zmin + zStep_;
545  zmax = zmax + zStep_;
546  } // for each zbin
547  for (int zbin = 0; zbin < zBins_ - 1; ++zbin) {
548  if (zbin == mzb.znum)
549  continue;
550  delete[] all_zBins[zbin].clusters;
551  }
552 }
553 
555  EtaPhiBin *clusters = new EtaPhiBin[etaBins_ / 2];
556  if (clusters == nullptr)
557  edm::LogWarning("L1TrackJetProducer") << "Clusters memory not assigned!\n";
558 
559  // Find eta-phibin with maxpT, make center of cluster, add neighbors if not already used
560  float my_pt, left_pt, right_pt, right2pt;
561  int nclust = 0;
562  right2pt = 0;
563  for (int etabin = 0; etabin < etaBins_; ++etabin) {
564  // assign values for my pT and neighbors' pT
565  if (phislice[etabin].used)
566  continue;
567  my_pt = phislice[etabin].pTtot;
568  if (etabin > 0 && !phislice[etabin - 1].used) {
569  left_pt = phislice[etabin - 1].pTtot;
570  } else
571  left_pt = 0;
572  if (etabin < etaBins_ - 1 && !phislice[etabin + 1].used) {
573  right_pt = phislice[etabin + 1].pTtot;
574  if (etabin < etaBins_ - 2 && !phislice[etabin + 2].used) {
575  right2pt = phislice[etabin + 2].pTtot;
576  } else
577  right2pt = 0;
578  } else
579  right_pt = 0;
580 
581  // if I'm not a cluster, move on
582  if (my_pt < left_pt || my_pt <= right_pt) {
583  // if unused pT in the left neighbor, spit it out as a cluster
584  if (left_pt > 0) {
585  clusters[nclust] = phislice[etabin - 1];
586  phislice[etabin - 1].used = true;
587  nclust++;
588  }
589  continue;
590  }
591 
592  // I guess I'm a cluster-- should I use my right neighbor?
593  // Note: left neighbor will definitely be used because if it
594  // didn't belong to me it would have been used already
595  clusters[nclust] = phislice[etabin];
596  phislice[etabin].used = true;
597  if (left_pt > 0) {
598  if (clusters != nullptr) {
599  clusters[nclust].pTtot += left_pt;
600  clusters[nclust].numtracks += phislice[etabin - 1].numtracks;
601  clusters[nclust].numttrks += phislice[etabin - 1].numttrks;
602  clusters[nclust].numtdtrks += phislice[etabin - 1].numtdtrks;
603  clusters[nclust].numttdtrks += phislice[etabin - 1].numttdtrks;
604  }
605  }
606  if (my_pt >= right2pt && right_pt > 0) {
607  if (clusters != nullptr) {
608  clusters[nclust].pTtot += right_pt;
609  clusters[nclust].numtracks += phislice[etabin + 1].numtracks;
610  clusters[nclust].numttrks += phislice[etabin + 1].numttrks;
611  clusters[nclust].numtdtrks += phislice[etabin + 1].numtdtrks;
612  clusters[nclust].numttdtrks += phislice[etabin + 1].numttdtrks;
613  phislice[etabin + 1].used = true;
614  }
615  }
616  nclust++;
617  } // for each etabin
618 
619  // Now merge clusters, if necessary
620  for (int m = 0; m < nclust - 1; ++m) {
621  if (fabs(clusters[m + 1].eta - clusters[m].eta) < 1.5 * etaStep_) {
622  if (clusters[m + 1].pTtot > clusters[m].pTtot) {
623  clusters[m].eta = clusters[m + 1].eta;
624  }
625  clusters[m].pTtot += clusters[m + 1].pTtot;
626  clusters[m].numtracks += clusters[m + 1].numtracks; // Previous version didn't add tracks when merging
627  clusters[m].numttrks += clusters[m + 1].numttrks;
628  clusters[m].numtdtrks += clusters[m + 1].numtdtrks;
629  clusters[m].numttdtrks += clusters[m + 1].numttdtrks;
630  for (int m1 = m + 1; m1 < nclust - 1; ++m1)
631  clusters[m1] = clusters[m1 + 1];
632  nclust--;
633  m = -1;
634  } // end if clusters neighbor in eta
635  } // end for (m) loop
636 
637  for (int i = nclust; i < etaBins_ / 2; ++i) // zero out remaining unused clusters
638  clusters[i].pTtot = 0;
639  return clusters;
640 }
641 
643 
645 
647  float trk_pt, int trk_nstub, float trk_chi2, float trk_bendchi2, float trk_d0) {
648  bool PassQuality = false;
649  if (trk_bendchi2 < trkBendChi2Max_ && trk_chi2 < trkChi2dofMax_ && trk_nstub >= 4 && !displaced_)
650  PassQuality = true;
651  if (displaced_ && trk_bendchi2 < nStubs4DisplacedBendTight_ && trk_chi2 < nStubs4DisplacedChi2Tight_ &&
652  trk_nstub == 4 && trk_d0 <= d0CutNStubs4_)
653  PassQuality = true;
654  if (displaced_ && trk_bendchi2 < nStubs4DisplacedBendLoose_ && trk_chi2 < nStubs4DisplacedChi2Loose_ &&
655  trk_nstub == 4 && trk_d0 > d0CutNStubs4_)
656  PassQuality = true;
657  if (displaced_ && trk_bendchi2 < nStubs5DisplacedBendLoose_ && trk_chi2 < nStubs5DisplacedChi2Loose_ && trk_nstub > 4)
658  PassQuality = true;
659  return PassQuality;
660 }
661 
663  //The following says we do not know what parameters are allowed so do no validation
664  // Please change this to state exactly what you do use, even if it is no parameters
666  desc.setUnknown();
667  descriptions.addDefault(desc);
668 }
669 
670 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
unsigned int tidRing(const DetId &id) const
bool trackQualityCuts(float trk_pt, int trk_nstub, float trk_chi2, float trk_bendchi2, float trk_d0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
L1TrackJetProducer(const ParameterSet &)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
EtaPhiBin * clusters
void L2_cluster(vector< Ptr< L1TTTrackType > > L1TrkPtrs_, vector< int > ttrk_, vector< int > tdtrk_, vector< int > ttdtrk_, MaxZBin &mzb)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
vector< L1TTTrackType > L1TTTrackCollectionType
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
float zbincenter
vector< Ptr< L1TTTrackType > > L1TrkPtrs_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
virtual EtaPhiBin * L1_cluster(EtaPhiBin *phislice)
def move
Definition: eostools.py:511
vector< int > zBinCount_
void endStream() override
static constexpr auto TOB
#define M_PI
void beginStream(StreamID) override
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(Event &, const EventSetup &) override
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
const EDGetTokenT< vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Log< level::Warning, false > LogWarning
std::vector< TkJet > TkJetCollection
Definition: TkJetFwd.h:20
tuple trackQualityCuts
static constexpr auto TID
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tTopoToken_
unsigned int tobLayer(const DetId &id) const