CMS 3D CMS Logo

PackedCandidate.h
Go to the documentation of this file.
1 #ifndef __DataFormats_PatCandidates_PackedCandidate_h__
2 #define __DataFormats_PatCandidates_PackedCandidate_h__
3 
13 #include <atomic>
14 #include <mutex>
15 
16 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
17 
18 // forward declare testing structure
19 class testPackedCandidate;
20 
21 namespace pat {
23  public:
34 
35  typedef unsigned int index;
38  : packedPt_(0),
39  packedEta_(0),
40  packedPhi_(0),
41  packedM_(0),
42  packedDxy_(0),
43  packedDz_(0),
44  packedDPhi_(0),
45  packedDEta_(0),
46  packedDTrkPt_(0),
52  caloFraction_(0),
53  hcalFraction_(0),
54  packedTime_(0),
57  p4_(new PolarLorentzVector(0, 0, 0, 0)),
58  p4c_(new LorentzVector(0, 0, 0, 0)),
59  vertex_(new Point(0, 0, 0)),
60  dphi_(0),
61  deta_(0),
62  dtrkpt_(0),
63  track_(nullptr),
64  pdgId_(0),
65  qualityFlags_(0),
66  pvRefKey_(reco::VertexRef::invalidKey()),
67  m_(nullptr),
68  packedHits_(0),
69  packedLayers_(0),
70  normalizedChi2_(0),
73  firstHit_(0) {}
74 
76  const reco::VertexRefProd &pvRefProd,
78  : packedPuppiweight_(0),
82  caloFraction_(0),
83  hcalFraction_(0),
84  packedTime_(0),
87  p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())),
88  p4c_(new LorentzVector(*p4_)),
89  vertex_(new Point(c.vertex())),
90  dphi_(0),
91  deta_(0),
92  dtrkpt_(0),
93  track_(nullptr),
94  pdgId_(c.pdgId()),
95  qualityFlags_(0),
96  pvRefProd_(pvRefProd),
97  pvRefKey_(pvRefKey),
98  m_(nullptr),
99  packedHits_(0),
100  packedLayers_(0),
101  normalizedChi2_(0),
104  firstHit_(0) {
105  packBoth();
106  }
107 
109  const Point &vtx,
110  float trkPt,
111  float etaAtVtx,
112  float phiAtVtx,
113  int pdgId,
114  const reco::VertexRefProd &pvRefProd,
115  reco::VertexRef::key_type pvRefKey)
116  : packedPuppiweight_(0),
118  rawCaloFraction_(0),
119  rawHcalFraction_(0),
120  caloFraction_(0),
121  hcalFraction_(0),
122  packedTime_(0),
123  packedTimeError_(0),
125  p4_(new PolarLorentzVector(p4)),
126  p4c_(new LorentzVector(*p4_)),
127  vertex_(new Point(vtx)),
129  deta_(std::abs(etaAtVtx - p4_.load()->eta()) >= kMinDEtaToStore_ ? etaAtVtx - p4_.load()->eta() : 0.),
130  dtrkpt_(std::abs(trkPt - p4_.load()->pt()) >= kMinDTrkPtToStore_ ? trkPt - p4_.load()->pt() : 0.),
131  track_(nullptr),
132  pdgId_(pdgId),
133  qualityFlags_(0),
134  pvRefProd_(pvRefProd),
135  pvRefKey_(pvRefKey),
136  m_(nullptr),
137  packedHits_(0),
138  packedLayers_(0),
139  normalizedChi2_(0),
142  firstHit_(0) {
143  packBoth();
144  }
145 
147  const Point &vtx,
148  float trkPt,
149  float etaAtVtx,
150  float phiAtVtx,
151  int pdgId,
152  const reco::VertexRefProd &pvRefProd,
153  reco::VertexRef::key_type pvRefKey)
154  : packedPuppiweight_(0),
156  rawCaloFraction_(0),
157  rawHcalFraction_(0),
158  caloFraction_(0),
159  hcalFraction_(0),
160  packedTime_(0),
161  packedTimeError_(0),
163  p4_(new PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M())),
164  p4c_(new LorentzVector(p4)),
165  vertex_(new Point(vtx)),
167  deta_(std::abs(etaAtVtx - p4_.load()->eta()) >= kMinDEtaToStore_ ? etaAtVtx - p4_.load()->eta() : 0.),
168  dtrkpt_(std::abs(trkPt - p4_.load()->pt()) >= kMinDTrkPtToStore_ ? trkPt - p4_.load()->pt() : 0.),
169  track_(nullptr),
170  pdgId_(pdgId),
171  qualityFlags_(0),
172  pvRefProd_(pvRefProd),
173  pvRefKey_(pvRefKey),
174  m_(nullptr),
175  packedHits_(0),
176  packedLayers_(0),
177  normalizedChi2_(0),
180  firstHit_(0) {
181  packBoth();
182  }
183 
185  : packedPt_(iOther.packedPt_),
186  packedEta_(iOther.packedEta_),
187  packedPhi_(iOther.packedPhi_),
188  packedM_(iOther.packedM_),
189  packedDxy_(iOther.packedDxy_),
190  packedDz_(iOther.packedDz_),
191  packedDPhi_(iOther.packedDPhi_),
192  packedDEta_(iOther.packedDEta_),
201  packedTime_(iOther.packedTime_),
204  // Need to trigger unpacking in iOther
205  p4_(new PolarLorentzVector(iOther.polarP4())),
206  p4c_(new LorentzVector(iOther.p4())),
207  vertex_((iOther.vertex_ ? new Point(iOther.vertex()) : nullptr)),
208  dxy_(vertex_ ? iOther.dxy_ : 0),
209  dz_(vertex_ ? iOther.dz_ : 0),
210  dphi_(vertex_ ? iOther.dphi_ : 0),
211  deta_(vertex_ ? iOther.deta_ : 0),
212  dtrkpt_(vertex_ ? iOther.dtrkpt_ : 0),
213  track_(iOther.track_ ? new reco::Track(*iOther.track_) : nullptr),
214  pdgId_(iOther.pdgId_),
216  pvRefProd_(iOther.pvRefProd_),
217  pvRefKey_(iOther.pvRefKey_),
218  m_(iOther.m_ ? new reco::TrackBase::CovarianceMatrix(*iOther.m_) : nullptr),
219  packedHits_(iOther.packedHits_),
224  firstHit_(iOther.firstHit_) {}
225 
227  : packedPt_(iOther.packedPt_),
228  packedEta_(iOther.packedEta_),
229  packedPhi_(iOther.packedPhi_),
230  packedM_(iOther.packedM_),
231  packedDxy_(iOther.packedDxy_),
232  packedDz_(iOther.packedDz_),
233  packedDPhi_(iOther.packedDPhi_),
234  packedDEta_(iOther.packedDEta_),
243  packedTime_(iOther.packedTime_),
246  p4_(iOther.p4_.exchange(nullptr)),
247  p4c_(iOther.p4c_.exchange(nullptr)),
248  vertex_(iOther.vertex_.exchange(nullptr)),
249  dxy_(iOther.dxy_),
250  dz_(iOther.dz_),
251  dphi_(iOther.dphi_),
252  deta_(iOther.deta_),
253  dtrkpt_(iOther.dtrkpt_),
254  track_(iOther.track_.exchange(nullptr)),
255  pdgId_(iOther.pdgId_),
257  pvRefProd_(iOther.pvRefProd_),
258  pvRefKey_(iOther.pvRefKey_),
259  m_(iOther.m_.exchange(nullptr)),
260  packedHits_(iOther.packedHits_),
265  firstHit_(iOther.firstHit_) {}
266 
268  if (this == &iOther) {
269  return *this;
270  }
271  packedPt_ = iOther.packedPt_;
272  packedEta_ = iOther.packedEta_;
273  packedPhi_ = iOther.packedPhi_;
274  packedM_ = iOther.packedM_;
275  packedDxy_ = iOther.packedDxy_;
276  packedDz_ = iOther.packedDz_;
277  packedDPhi_ = iOther.packedDPhi_;
278  packedDEta_ = iOther.packedDEta_;
279  packedDTrkPt_ = iOther.packedDTrkPt_;
285  caloFraction_ = iOther.caloFraction_;
286  hcalFraction_ = iOther.hcalFraction_;
287  packedTime_ = iOther.packedTime_;
290  // Need to trigger unpacking in iOther
291  if (p4_) {
292  *p4_ = iOther.polarP4();
293  } else {
294  p4_.store(new PolarLorentzVector(iOther.polarP4()));
295  }
296  if (p4c_) {
297  *p4c_ = iOther.p4();
298  } else {
299  p4c_.store(new LorentzVector(iOther.p4()));
300  }
301  if (vertex_) {
302  *vertex_ = iOther.vertex();
303  } else {
304  vertex_.store(new Point(iOther.vertex()));
305  }
306  dxy_ = iOther.dxy_;
307  dz_ = iOther.dz_;
308  dphi_ = iOther.dphi_;
309  deta_ = iOther.deta_;
310  dtrkpt_ = iOther.dtrkpt_;
311 
312  if (!iOther.track_) {
313  delete track_.exchange(nullptr);
314  } else {
315  if (!track_) {
316  track_.store(new reco::Track(*iOther.track_));
317  } else {
318  *track_ = *(iOther.track_);
319  }
320  }
321 
322  pdgId_ = iOther.pdgId_;
323  qualityFlags_ = iOther.qualityFlags_;
324  pvRefProd_ = iOther.pvRefProd_;
325  pvRefKey_ = iOther.pvRefKey_;
326  if (!iOther.m_) {
327  delete m_.exchange(nullptr);
328  } else {
329  if (!m_) {
330  m_.store(new reco::Track::CovarianceMatrix(*iOther.m_));
331  } else {
332  *m_ = *(iOther.m_);
333  }
334  }
335 
336  packedHits_ = iOther.packedHits_;
337  packedLayers_ = iOther.packedLayers_;
341  firstHit_ = iOther.firstHit_;
342  return *this;
343  }
344 
346  if (this == &iOther) {
347  return *this;
348  }
349  packedPt_ = iOther.packedPt_;
350  packedEta_ = iOther.packedEta_;
351  packedPhi_ = iOther.packedPhi_;
352  packedM_ = iOther.packedM_;
353  packedDxy_ = iOther.packedDxy_;
354  packedDz_ = iOther.packedDz_;
355  packedDPhi_ = iOther.packedDPhi_;
356  packedDEta_ = iOther.packedDEta_;
357  packedDTrkPt_ = iOther.packedDTrkPt_;
358  packedCovariance_ = iOther.packedCovariance_;
359  packedPuppiweight_ = iOther.packedPuppiweight_;
360  packedPuppiweightNoLepDiff_ = iOther.packedPuppiweightNoLepDiff_;
361  rawCaloFraction_ = iOther.rawCaloFraction_;
362  rawHcalFraction_ = iOther.rawHcalFraction_;
363  caloFraction_ = iOther.caloFraction_;
364  hcalFraction_ = iOther.hcalFraction_;
365  packedTime_ = iOther.packedTime_;
366  packedTimeError_ = iOther.packedTimeError_;
367  isIsolatedChargedHadron_ = iOther.isIsolatedChargedHadron_;
368  delete p4_.exchange(iOther.p4_.exchange(nullptr));
369  delete p4c_.exchange(iOther.p4c_.exchange(nullptr));
370  delete vertex_.exchange(iOther.vertex_.exchange(nullptr));
371  dxy_ = iOther.dxy_;
372  dz_ = iOther.dz_;
373  dphi_ = iOther.dphi_;
374  deta_ = iOther.deta_;
375  dtrkpt_ = iOther.dtrkpt_;
376  delete track_.exchange(iOther.track_.exchange(nullptr));
377  pdgId_ = iOther.pdgId_;
378  qualityFlags_ = iOther.qualityFlags_;
379  pvRefProd_ = iOther.pvRefProd_;
380  pvRefKey_ = iOther.pvRefKey_;
381  delete m_.exchange(iOther.m_.exchange(nullptr));
382  packedHits_ = iOther.packedHits_;
383  packedLayers_ = iOther.packedLayers_;
384  normalizedChi2_ = iOther.normalizedChi2_;
385  covarianceVersion_ = iOther.covarianceVersion_;
386  covarianceSchema_ = iOther.covarianceSchema_;
387  firstHit_ = iOther.firstHit_;
388  return *this;
389  }
390 
392  ~PackedCandidate() override;
394  size_t numberOfDaughters() const override;
396  const reco::Candidate *daughter(size_type) const override;
398  size_t numberOfMothers() const override;
400  const reco::Candidate *mother(size_type) const override;
404  reco::Candidate *daughter(const std::string &s) override;
406  const reco::Candidate *daughter(const std::string &s) const override;
409  size_t numberOfSourceCandidatePtrs() const override { return 0; }
413 
415  int charge() const override {
416  switch (abs(pdgId_)) {
417  case 211:
418  return (pdgId_ > 0) - (pdgId_ < 0);
419  case 11:
420  return (-1) * (pdgId_ > 0) + (pdgId_ < 0); // e
421  case 13:
422  return (-1) * (pdgId_ > 0) + (pdgId_ < 0); // mu
423  case 15:
424  return (-1) * (pdgId_ > 0) + (pdgId_ < 0); // tau
425  case 24:
426  return (pdgId_ > 0) - (pdgId_ < 0); // W
427  default:
428  return 0; // FIXME: charge is not defined
429  }
430  }
432  void setCharge(int charge) override {}
434  int threeCharge() const override { return charge() * 3; }
436  void setThreeCharge(int threecharge) override {}
438  const LorentzVector &p4() const override {
439  if (!p4c_)
440  unpack();
441  return *p4c_;
442  }
444  const PolarLorentzVector &polarP4() const override {
445  if (!p4c_)
446  unpack();
447  return *p4_;
448  }
450  Vector momentum() const override {
451  if (!p4c_)
452  unpack();
453  return p4c_.load()->Vect();
454  }
457  Vector boostToCM() const override {
458  if (!p4c_)
459  unpack();
460  return p4c_.load()->BoostToCM();
461  }
463  double p() const override {
464  if (!p4c_)
465  unpack();
466  return p4c_.load()->P();
467  }
469  double energy() const override {
470  if (!p4c_)
471  unpack();
472  return p4c_.load()->E();
473  }
475  double et() const override { return (pt() <= 0) ? 0 : p4c_.load()->Et(); }
477  double et2() const override { return (pt() <= 0) ? 0 : p4c_.load()->Et2(); }
479  double mass() const override {
480  if (!p4c_)
481  unpack();
482  return p4_.load()->M();
483  }
485  double massSqr() const override {
486  if (!p4c_)
487  unpack();
488  auto m = p4_.load()->M();
489  return m * m;
490  }
491 
493  double mt() const override {
494  if (!p4c_)
495  unpack();
496  return p4_.load()->Mt();
497  }
499  double mtSqr() const override {
500  if (!p4c_)
501  unpack();
502  return p4_.load()->Mt2();
503  }
505  double px() const override {
506  if (!p4c_)
507  unpack();
508  return p4c_.load()->Px();
509  }
511  double py() const override {
512  if (!p4c_)
513  unpack();
514  return p4c_.load()->Py();
515  }
517  double pz() const override {
518  if (!p4c_)
519  unpack();
520  return p4c_.load()->Pz();
521  }
523  double pt() const override {
524  if (!p4c_)
525  unpack();
526  return p4_.load()->Pt();
527  }
529  double phi() const override {
530  if (!p4c_)
531  unpack();
532  return p4_.load()->Phi();
533  }
534 
536  virtual double ptTrk() const {
537  maybeUnpackBoth();
538  return p4_.load()->pt() + dtrkpt_;
539  }
541  virtual float phiAtVtx() const {
542  maybeUnpackBoth();
543  float ret = p4_.load()->Phi() + dphi_;
544  while (ret > float(M_PI))
545  ret -= 2 * float(M_PI);
546  while (ret < -float(M_PI))
547  ret += 2 * float(M_PI);
548  return ret;
549  }
551  virtual float etaAtVtx() const {
552  maybeUnpackBoth();
553  return p4_.load()->eta() + deta_;
554  }
555 
557  double theta() const override {
558  if (!p4c_)
559  unpack();
560  return p4_.load()->Theta();
561  }
563  double eta() const override {
564  if (!p4c_)
565  unpack();
566  return p4_.load()->Eta();
567  }
569  double rapidity() const override {
570  if (!p4c_)
571  unpack();
572  return p4_.load()->Rapidity();
573  }
575  double y() const override {
576  if (!p4c_)
577  unpack();
578  return p4_.load()->Rapidity();
579  }
581  void setP4(const LorentzVector &p4) override {
582  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz
583  // and x,y,z
584  dphi_ += polarP4().Phi() - p4.Phi();
585  deta_ += polarP4().Eta() - p4.Eta();
586  dtrkpt_ += polarP4().Pt() - p4.Pt();
587  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
588  packBoth();
589  }
591  void setP4(const PolarLorentzVector &p4) override {
592  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz
593  // and x,y,z
594  dphi_ += polarP4().Phi() - p4.Phi();
595  deta_ += polarP4().Eta() - p4.Eta();
596  dtrkpt_ += polarP4().Pt() - p4.Pt();
597  *p4_ = p4;
598  packBoth();
599  }
601  void setMass(double m) override {
602  if (!p4c_)
603  unpack();
604  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
605  pack();
606  }
607  void setPz(double pz) override {
608  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz
609  // and x,y,z
610  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
611  dphi_ += polarP4().Phi() - p4c_.load()->Phi();
612  deta_ += polarP4().Eta() - p4c_.load()->Eta();
613  dtrkpt_ += polarP4().Pt() - p4c_.load()->Pt();
614  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
615  packBoth();
616  }
618 
619  // Note: mask is also the maximum value
621 
622  // set number of tracker hits and layers
623  virtual void setHits(const reco::Track &tk) {
624  // first we count the number of layers with hits
625  int numberOfPixelLayers_ = tk.hitPattern().pixelLayersWithMeasurement();
626  if (numberOfPixelLayers_ > trackPixelHitsMask)
627  numberOfPixelLayers_ = trackPixelHitsMask;
628  int numberOfStripLayers_ = tk.hitPattern().stripLayersWithMeasurement();
629  if (numberOfStripLayers_ > trackStripHitsMask)
630  numberOfStripLayers_ = trackStripHitsMask;
631  packedLayers_ = (numberOfPixelLayers_ & trackPixelHitsMask) | (numberOfStripLayers_ << trackStripHitsShift);
632  // now we count number of additional hits, beyond the one-per-layer implied
633  // by packedLayers_
634  int numberOfPixelHits_ = tk.hitPattern().numberOfValidPixelHits() - numberOfPixelLayers_;
635  if (numberOfPixelHits_ > trackPixelHitsMask)
636  numberOfPixelHits_ = trackPixelHitsMask;
637  int numberOfStripHits_ =
638  tk.hitPattern().numberOfValidHits() - numberOfPixelHits_ - numberOfPixelLayers_ - numberOfStripLayers_;
639  if (numberOfStripHits_ > trackStripHitsMask)
640  numberOfStripHits_ = trackStripHitsMask;
641 
642  packedHits_ = (numberOfPixelHits_ & trackPixelHitsMask) | (numberOfStripHits_ << trackStripHitsShift);
643  }
644 
645  virtual void setTrackProperties(const reco::Track &tk,
646  const reco::Track::CovarianceMatrix &covariance,
647  int quality,
648  int covarianceVersion) {
652  setHits(tk);
653  maybeUnpackBoth();
654  packBoth();
655  packCovariance(covariance, false);
656  }
657 
658  // set track properties using quality and covarianceVersion to define the
659  // level of details in the cov. matrix
660  virtual void setTrackProperties(const reco::Track &tk, int quality, int covarianceVersion) {
662  }
663 
664  void setTrackPropertiesLite(unsigned int covSchema,
665  unsigned int covarianceVersion,
666  unsigned int nHits,
667  unsigned int nPixelHits) {
669  covarianceSchema_ = covSchema;
670  packedHits_ =
671  (nPixelHits & trackPixelHitsMask) | (((nHits - nPixelHits) & trackStripHitsMask) << trackStripHitsShift);
672  }
673 
675  int numberOfHits() const {
677  }
681  virtual void setCovarianceVersion(int v) { covarianceVersion_ = v; }
682  int covarianceVersion() const { return covarianceVersion_; }
683  int covarianceSchema() const { return covarianceSchema_; }
684 
686  const Point &vertex() const override {
687  maybeUnpackBoth();
688  return *vertex_;
689  } //{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
691  double vx() const override {
692  maybeUnpackBoth();
693  return vertex_.load()->X();
694  } //{ return 0; }
696  double vy() const override {
697  maybeUnpackBoth();
698  return vertex_.load()->Y();
699  } //{ return 0; }
701  double vz() const override {
702  maybeUnpackBoth();
703  return vertex_.load()->Z();
704  } //{ if (fromPV_) return 0; else return 100; }
706  void setVertex(const Point &vertex) override {
707  maybeUnpackBoth();
708  *vertex_ = vertex;
709  packVtx();
710  }
711 
714  enum PVAssoc { NoPV = 0, PVLoose = 1, PVTight = 2, PVUsedInFit = 3 };
715  const PVAssoc fromPV(size_t ipv = 0) const {
716  reco::VertexRef pvRef = vertexRef();
717  if (pvAssociationQuality() == UsedInFitTight and pvRef.key() == ipv)
718  return PVUsedInFit;
719  if (pvRef.key() == ipv or abs(pdgId()) == 13 or abs(pdgId()) == 11)
720  return PVTight;
722  return PVTight; // it is not closest, but at least prevents the B
723  // assignment stealing
724  if (pvAssociationQuality() < UsedInFitLoose or pvRef->ndof() < 4.0)
725  return PVLoose;
726  return NoPV;
727  }
728 
739  };
742  }
744  qualityFlags_ =
746  }
747 
749 
751  virtual float dxy() const {
752  maybeUnpackBoth();
753  return dxy_;
754  }
755 
757  virtual float dz(size_t ipv = 0) const {
758  maybeUnpackBoth();
759  return dz_ + (*pvRefProd_)[pvRefKey_].position().z() - (*pvRefProd_)[ipv].position().z();
760  }
762  virtual float dzAssociatedPV() const {
763  maybeUnpackBoth();
764  return dz_;
765  }
766 
768  virtual float dxy(const Point &p) const;
770  virtual float dz(const Point &p) const;
771 
773  float dzError() const override {
775  return sqrt((*m_.load())(4, 4));
776  }
778  float dxyError() const override {
780  return sqrt((*m_.load())(3, 3));
781  }
782 
785  virtual const reco::Track &pseudoTrack() const {
786  if (!track_)
787  unpackTrk();
788  return *track_;
789  }
793  virtual const reco::Track pseudoPosDefTrack() const;
794 
796  const reco::Track *bestTrack() const override {
797  if (packedHits_ != 0 || packedLayers_ != 0) {
799  return track_.load();
800  } else
801  return nullptr;
802  }
804  bool hasTrackDetails() const { return (packedHits_ != 0 || packedLayers_ != 0); }
807  bool fromTrackCandidate() const { return (packedDz_ != 0 || (packedDxy_ != 0 && packedDxy_ != 32768)); }
811  void setTrackHighPurity(bool highPurity) {
812  qualityFlags_ =
814  }
815 
819  noLostInnerHits = 0, // it could still not have a hit in the first layer,
820  // e.g. if it crosses an inactive sensor
823  };
826  }
828  int lost = hits;
829  if (lost > 2)
830  lost = 2; // protection against misuse
831  lost++; // shift so it's 0 .. 3 instead of (-1) .. 2
833  }
834 
836  void setFirstHit(uint16_t pattern) { firstHit_ = pattern; }
838  uint16_t firstHit() const { return firstHit_; }
839 
840  void setMuonID(bool isStandAlone, bool isGlobal) {
841  int16_t muonFlags = isStandAlone | (2 * isGlobal);
843  }
844 
845  void setGoodEgamma(bool isGoodEgamma = true) {
846  int16_t egFlags = (isGoodEgamma << egammaFlagsShift) & egammaFlagsMask;
848  }
849 
851  int pdgId() const override { return pdgId_; }
852  // set PDG identifier
853  void setPdgId(int pdgId) override { pdgId_ = pdgId; }
855  int status() const override { return qualityFlags_; } /*FIXME*/
857  void setStatus(int status) override {} /*FIXME*/
859  static const unsigned int longLivedTag = 0; /*FIXME*/
861  void setLongLived() override {} /*FIXME*/
863  bool longLived() const override;
865  static const unsigned int massConstraintTag = 0; /*FIXME*/
867  void setMassConstraint() override {} /*FIXME*/
869  bool massConstraint() const override;
870 
872  PackedCandidate *clone() const override { return new PackedCandidate(*this); }
873 
875  double vertexChi2() const override;
882  double vertexNdof() const override;
884  double vertexNormalizedChi2() const override;
886  double vertexCovariance(int i, int j) const override;
891  return m;
892  }
894  void fillVertexCovariance(CovarianceMatrix &v) const override;
897  bool hasMasterClone() const override;
901  const reco::CandidateBaseRef &masterClone() const override;
905  bool hasMasterClonePtr() const override;
909 
910  const reco::CandidatePtr &masterClonePtr() const override;
911 
913  template <typename Ref>
914  Ref masterRef() const {
915  return masterClone().template castTo<Ref>();
916  }
917 
918  bool isElectron() const override { return false; }
919  bool isMuon() const override { return false; }
920  bool isStandAloneMuon() const override { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 1; }
921  bool isGlobalMuon() const override { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 2; }
922  bool isTrackerMuon() const override { return false; }
923  bool isCaloMuon() const override { return false; }
924  bool isPhoton() const override { return false; }
925  bool isConvertedPhoton() const override { return false; }
926  bool isJet() const override { return false; }
927  bool isGoodEgamma() const { return (qualityFlags_ & egammaFlagsMask) != 0; }
928 
929  // puppiweights
930  void setPuppiWeight(float p,
931  float p_nolep = 0.0);
932  float puppiWeight() const;
934  float puppiWeightNoLep() const;
935 
936  // for the neutral fractions
937  void setRawCaloFraction(float p);
938  float rawCaloFraction() const {
940  return (rawCaloFraction_ / 100.);
941  }
942  void setRawHcalFraction(float p);
943  float rawHcalFraction() const {
944  return (rawHcalFraction_ / 100.);
945  }
946  void setCaloFraction(float p);
947  float caloFraction() const {
948  return (caloFraction_ / 100.);
949  }
950  void setHcalFraction(float p);
951  float hcalFraction() const {
953  return (hcalFraction_ / 100.);
954  }
955 
956  // isolated charged hadrons
957  void setIsIsolatedChargedHadron(bool p);
958  bool isIsolatedChargedHadron() const {
961  }
962 
966  : dxydxy(0), dxydz(0), dzdz(0), dlambdadz(0), dphidxy(0), dptdpt(0), detadeta(0), dphidphi(0) {}
967  // 3D IP covariance
968  uint16_t dxydxy;
969  uint16_t dxydz;
970  uint16_t dzdz;
971  // other IP relevant elements
972  uint16_t dlambdadz;
973  uint16_t dphidxy;
974  // other diag elements
975  uint16_t dptdpt;
976  uint16_t detadeta;
977  uint16_t dphidphi;
978  };
979 
981  virtual float time() const { return vertexRef()->t() + dtimeAssociatedPV(); }
983  virtual float dtime(size_t ipv = 0) const {
984  return dtimeAssociatedPV() + (*pvRefProd_)[pvRefKey_].t() - (*pvRefProd_)[ipv].t();
985  }
987  virtual float dtimeAssociatedPV() const {
988  if (packedTime_ == 0)
989  return 0.f;
990  if (packedTimeError_ > 0)
992  else
994  }
996  virtual float timeError() const { return unpackTimeError(packedTimeError_); }
998  void setDTimeAssociatedPV(float aTime, float aTimeError = 0);
1000  void setTime(float aTime, float aTimeError = 0) { setDTimeAssociatedPV(aTime - vertexRef()->t(), aTimeError); }
1001 
1002  private:
1003  void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix &m, uint16_t packed, int i, int j) const {
1005  packed, covarianceSchema_, i, j, pt(), eta(), numberOfHits(), numberOfPixelHits());
1006  }
1007  uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m, int i, int j) const {
1010  }
1011 
1012  protected:
1013  friend class ::testPackedCandidate;
1014  static constexpr float kMinDEtaToStore_ = 0.001;
1015  static constexpr float kMinDTrkPtToStore_ = 0.001;
1016 
1020 
1021  void pack(bool unpackAfterwards = true);
1022  void unpack() const;
1023  void packVtx(bool unpackAfterwards = true);
1024  void unpackVtx() const;
1025  void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards = true);
1026  void unpackCovariance() const;
1027  void maybeUnpackBoth() const {
1028  if (!p4c_)
1029  unpack();
1030  if (!vertex_)
1031  unpackVtx();
1032  }
1033  void maybeUnpackTrack() const {
1034  if (!track_)
1035  unpackTrk();
1036  }
1037  void maybeUnpackCovariance() const {
1038  if (!m_)
1039  unpackCovariance();
1040  }
1041  void packBoth() {
1042  pack(false);
1043  packVtx(false);
1044  delete p4_.exchange(nullptr);
1045  delete p4c_.exchange(nullptr);
1046  delete vertex_.exchange(nullptr);
1047  unpack();
1048  unpackVtx();
1049  } // do it this way, so that we don't loose precision on the angles before
1050  // computing dxy,dz
1051  void unpackTrk() const;
1052 
1054  int8_t packedPuppiweightNoLepDiff_; // storing the DIFFERENCE of (all - "no
1055  // lep") for compression optimization
1058  uint8_t caloFraction_;
1060  int16_t packedTime_;
1062 
1064 
1066  mutable std::atomic<PolarLorentzVector *> p4_;
1067  mutable std::atomic<LorentzVector *> p4c_;
1069  mutable std::atomic<Point *> vertex_;
1072  mutable std::atomic<reco::Track *> track_;
1074  int pdgId_;
1075  uint16_t qualityFlags_;
1079 
1081  mutable std::atomic<reco::TrackBase::CovarianceMatrix *> m_;
1082  uint8_t packedHits_,
1083  packedLayers_; // packedLayers_ -> layers with valid hits; packedHits_ ->
1084  // extra hits beyond the one-per-layer implied by
1085  // packedLayers_
1086 
1092  // static std::atomic<CovarianceParameterization*>
1093  // covarianceParameterization_;
1094  static std::once_flag covariance_load_flag;
1096  if (!hasTrackDetails())
1098  "Trying to access covariance matrix for a "
1099  "PackedCandidate for which it's not available. "
1100  "Check hasTrackDetails() before!\n");
1101  std::call_once(
1105  << "Attempting to load multiple covariance version in same process. "
1106  "This is not supported.";
1107  }
1109  }
1110 
1112  bool overlap(const reco::Candidate &) const override;
1113  template <typename, typename, typename>
1114  friend struct component;
1115  friend class ::OverlapChecker;
1118 
1126  muonFlagsMask = 0x0600,
1130  };
1131 
1133  static uint8_t packTimeError(float timeError);
1134  static float unpackTimeError(uint8_t timeError);
1135  static float unpackTimeNoError(int16_t time);
1136  static int16_t packTimeNoError(float time);
1137  static float unpackTimeWithError(int16_t time, uint8_t timeError);
1138  static int16_t packTimeWithError(float time, float timeError);
1139  static constexpr float MIN_TIMEERROR = 0.002f; // 2 ps, smallest storable non-zero uncertainty
1140  static constexpr float MIN_TIME_NOERROR = 0.0002f; // 0.2 ps, smallest non-zero time that can be stored by
1141  // packTimeNoError
1142  static constexpr int EXPO_TIMEERROR = 5; // power of 2 used in encoding timeError
1143  static constexpr int EXPO_TIME_NOERROR = 6; // power of 2 used in encoding time without timeError
1144  static constexpr int EXPO_TIME_WITHERROR = -6; // power of 2 used in encoding time with timeError
1145  public:
1146  uint16_t firstHit_;
1147  };
1148 
1149  typedef std::vector<pat::PackedCandidate> PackedCandidateCollection;
1152 } // namespace pat
1153 
1154 #endif
float puppiWeight() const
bool isGoodEgamma() const
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
void setMuonID(bool isStandAlone, bool isGlobal)
static constexpr int EXPO_TIME_WITHERROR
int covarianceVersion() const
void setStatus(int status) override
set status word
bool massConstraint() const override
do mass constraint?
const Point & vertex() const override
vertex position
float puppiWeightNoLep() const
Weight from full PUPPI.
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
double vertexNdof() const override
int numberOfValidHits() const
Definition: HitPattern.h:817
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
double mtSqr() const override
transverse mass squared
void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix &m, uint16_t packed, int i, int j) const
math::XYZVector Vector
point in the space
Definition: Candidate.h:42
void setPuppiWeight(float p, float p_nolep=0.0)
void setThreeCharge(int threecharge) override
set electric charge
int charge() const override
electric charge
size_t size_type
Definition: Candidate.h:29
double et() const override
transverse energy
void setTrackPropertiesLite(unsigned int covSchema, unsigned int covarianceVersion, unsigned int nHits, unsigned int nPixelHits)
int numberOfPixelHits() const
reco::VertexRef::key_type pvRefKey_
bool isGlobalMuon() const override
ret
prodAgent to be discontinued
bool hasMasterClonePtr() const override
bool isStandAloneMuon() const override
static const unsigned int longLivedTag
long lived flag
PackedCandidate & operator=(const PackedCandidate &iOther)
double px() const override
x coordinate of momentum vector
static const unsigned int massConstraintTag
do mass constraint flag
std::atomic< LorentzVector * > p4c_
virtual float etaAtVtx() const
eta from the track (normally identical to eta())
static float unpackTimeNoError(int16_t time)
std::vector< pat::PackedCandidate > PackedCandidateCollection
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1005
math::XYZPoint Point
point in the space
virtual void setCovarianceVersion(int v)
void setRawCaloFraction(float p)
Weight from PUPPI removing leptons.
static int16_t packTimeNoError(float time)
void maybeUnpackCovariance() const
PackedCandidate(const PackedCandidate &iOther)
bool fromTrackCandidate() const
const PVAssoc fromPV(size_t ipv=0) const
Ref masterRef() const
cast master clone reference to a concrete type
double pz() const override
z coordinate of momentum vector
Vector boostToCM() const override
const PolarLorentzVector & polarP4() const override
four-momentum Lorentz vector
bool isJet() const override
PackedCovariance packedCovariance_
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
float rawCaloFraction() const
static int16_t packTimeWithError(float time, float timeError)
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
int pdgId() const override
PDG identifier.
float rawHcalFraction() const
Set the fraction of Hcal needed isolated charged hadrons.
static uint8_t packTimeError(float timeError)
static to allow unit testing
const reco::VertexRef vertexRef() const
void setMassConstraint() override
set mass constraint flag
PackedCandidate(PackedCandidate &&iOther)
size_t numberOfMothers() const override
number of mothers
const reco::CandidateBaseRef & masterClone() const override
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
double rapidity() const override
rapidity
key_type key() const
Accessor for product key.
Definition: Ref.h:250
uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m, int i, int j) const
PackedCandidate(const reco::Candidate &c, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
double vy() const override
y coordinate of vertex position
virtual float dtime(size_t ipv=0) const
dtime with respect to the PV[ipv]
bool trackHighPurity() const
true if the track had the highPurity quality bit
Definition: HeavyIon.h:7
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
reco::CandidateCollection daughters
collection of daughter candidates
void maybeUnpackBoth() const
double p() const override
magnitude of momentum vector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int pixelLayersWithMeasurement() const
const PVAssociationQuality pvAssociationQuality() const
void setP4(const LorentzVector &p4) override
set 4-momentum
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:716
const reco::CandidatePtr & masterClonePtr() const override
void unpackCovariance() const
int covarianceSchema() const
virtual float timeError() const
time measurement uncertainty (-1 if not available)
double eta() const override
momentum pseudorapidity
virtual const reco::Track pseudoPosDefTrack() const
bool isPhoton() const override
void setHcalFraction(float p)
Fraction of ECAL+HCAL energy over candidate energy.
virtual float dtimeAssociatedPV() const
dtime with respect to the PV ref
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual void setTrackProperties(const reco::Track &tk, int quality, int covarianceVersion)
std::atomic< PolarLorentzVector * > p4_
the four vector
T sqrt(T t)
Definition: SSEVec.h:19
void setMass(double m) override
set particle mass
float dzError() const override
uncertainty on dz
static constexpr float kMinDTrkPtToStore_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::atomic< Point * > vertex_
vertex position
void setPz(double pz) override
void setLongLived() override
set long lived flag
PackedCandidate()
default constructor
float unpack(uint16_t packed, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
uint16_t firstHit() const
Return first hit from HitPattern for tracks with high level details.
friend class ShallowCloneCandidate
void setP4(const PolarLorentzVector &p4) override
set 4-momentum
size_t numberOfDaughters() const override
number of daughters
static CovarianceParameterization covarianceParameterization_
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
#define CMS_THREAD_GUARD(_var_)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual double ptTrk() const
pt from the track (normally identical to pt())
#define CMS_THREAD_SAFE
~PackedCandidate() override
destructor
PackedCandidate(const PolarLorentzVector &p4, const Point &vtx, float trkPt, float etaAtVtx, float phiAtVtx, int pdgId, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
float pack(float value, int schema, int i, int j, float pt, float eta, int nHits, int pixelHits, float cii=1., float cjj=1.) const
float dxyError() const override
uncertainty on dxy
double vz() const override
z coordinate of vertex position
double massSqr() const override
mass squared
bool isElectron() const override
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
Vector momentum() const override
spatial momentum vector
std::atomic< reco::Track * > track_
reco::Track
void maybeUnpackTrack() const
double mt() const override
transverse mass
#define M_PI
static constexpr int EXPO_TIME_NOERROR
int status() const override
status word
PackedCandidate * clone() const override
returns a clone of the Candidate object
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
int stripLayersWithMeasurement() const
std::atomic< reco::TrackBase::CovarianceMatrix * > m_
IP covariance.
LostInnerHits
Enumerator specifying the.
bool isConvertedPhoton() const override
void setGoodEgamma(bool isGoodEgamma=true)
uint8_t normalizedChi2_
track quality information
void setRawHcalFraction(float p)
Raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
double mass() const override
mass
void setTime(float aTime, float aTimeError=0)
set time measurement
double pt() const override
transverse momentum
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:504
static constexpr int EXPO_TIMEERROR
virtual float phiAtVtx() const
momentum azimuthal angle from the track (normally identical to phi())
double py() const override
y coordinate of momentum vector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::RefVector< pat::PackedCandidateCollection > PackedCandidateRefVector
def load(fileName)
Definition: svgfig.py:547
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:593
static std::once_flag covariance_load_flag
void setPdgId(int pdgId) override
int trackerLayersWithMeasurement() const
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
void setFirstHit(uint16_t pattern)
Set first hit from HitPattern.
int pdgId_
PDG identifier.
bool isIsolatedChargedHadron() const
void setDTimeAssociatedPV(float aTime, float aTimeError=0)
set time measurement
friend class ShallowClonePtrCandidate
float hcalFraction() const
fixed size matrix
than at PV) flag for charged hadrons
PackedCandidate & operator=(PackedCandidate &&iOther)
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
double vx() const override
x coordinate of vertex position
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
LostInnerHits lostInnerHits() const
double energy() const override
energy
bool isCaloMuon() const override
void packVtx(bool unpackAfterwards=true)
void setLostInnerHits(LostInnerHits hits)
PackedCandidate(const LorentzVector &p4, const Point &vtx, float trkPt, float etaAtVtx, float phiAtVtx, int pdgId, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
trackHitShiftsAndMasks
set impact parameters covariance
void setVertex(const Point &vertex) override
set vertex
void setIsIsolatedChargedHadron(bool p)
Fraction of Hcal for HF, neutral hadrons, and charged particles.
static constexpr float kMinDEtaToStore_
double vertexChi2() const override
chi-squares
int threeCharge() const override
electric charge
size_t numberOfSourceCandidatePtrs() const override
CovarianceMatrix vertexCovariance() const override
return SMatrix
virtual float dxy() const
dxy with respect to the PV ref
void pack(bool unpackAfterwards=true)
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:513
double y() const override
rapidity
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards=true)
string quality
virtual float time() const
time (wrt nominal zero of the collision)
void setTrackHighPurity(bool highPurity)
set to true if the track had the highPurity quality bit
virtual void setTrackProperties(const reco::Track &tk, const reco::Track::CovarianceMatrix &covariance, int quality, int covarianceVersion)
static float unpackTimeWithError(int16_t time, uint8_t timeError)
double theta() const override
momentum polar angle
double et2() const override
transverse energy squared (use this for cuts)!
virtual void setHits(const reco::Track &tk)
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
bool hasMasterClone() const override
bool isTrackerMuon() const override
void setCharge(int charge) override
set electric charge
const CovarianceParameterization & covarianceParameterization() const
virtual float dzAssociatedPV() const
dz with respect to the PV ref
math::XYZVector Vector
point in the space
static constexpr float MIN_TIMEERROR
static float unpackTimeError(uint8_t timeError)
double phi() const override
momentum azimuthal angle
bool isMuon() const override
virtual const reco::Track & pseudoTrack() const
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
void setCaloFraction(float p)
Fraction of Hcal for isolated charged hadrons.
bool longLived() const override
is long lived?
reco::VertexRefProd pvRefProd_
Use these to build a Ref to primary vertex.
static constexpr float MIN_TIME_NOERROR
void setAssociationQuality(PVAssociationQuality q)
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38