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 
4 #include <atomic>
5 #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), packedEta_(0),
39  packedPhi_(0), packedM_(0),
45  hcalFraction_(0),
46  packedTime_(0),
49  p4_(new PolarLorentzVector(0,0,0,0)), p4c_( new LorentzVector(0,0,0,0)),
50  vertex_(new Point(0,0,0)), dphi_(0), deta_(0), dtrkpt_(0),track_(nullptr), pdgId_(0),
51  qualityFlags_(0), pvRefKey_(reco::VertexRef::invalidKey()),
53 
54  explicit PackedCandidate( const reco::Candidate & c,
55  const reco::VertexRefProd &pvRefProd,
56  reco::VertexRef::key_type pvRefKey) :
59  p4_( new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())),
60  p4c_( new LorentzVector(*p4_)), vertex_( new Point(c.vertex())),
61  dphi_(0), deta_(0), dtrkpt_(0),
62  track_(nullptr), pdgId_(c.pdgId()), qualityFlags_(0), pvRefProd_(pvRefProd),
63  pvRefKey_(pvRefKey),m_(nullptr), packedHits_(0), packedLayers_(0),
65  packBoth();
66  }
67 
68  explicit PackedCandidate( const PolarLorentzVector &p4, const Point &vtx,
69  float trkPt,float etaAtVtx,float phiAtVtx,int pdgId,
70  const reco::VertexRefProd &pvRefProd,
71  reco::VertexRef::key_type pvRefKey) :
74  p4_( new PolarLorentzVector(p4) ), p4c_( new LorentzVector(*p4_)),
75  vertex_( new Point(vtx) ),
76  dphi_(reco::deltaPhi(phiAtVtx,p4_.load()->phi())),
77  deta_(std::abs(etaAtVtx-p4_.load()->eta())>=kMinDEtaToStore_ ? etaAtVtx-p4_.load()->eta() : 0.),
78  dtrkpt_(std::abs(trkPt-p4_.load()->pt())>=kMinDTrkPtToStore_ ? trkPt-p4_.load()->pt() : 0.),
79  track_(nullptr), pdgId_(pdgId),
80  qualityFlags_(0), pvRefProd_(pvRefProd), pvRefKey_(pvRefKey),
82  packBoth();
83  }
84 
85  explicit PackedCandidate( const LorentzVector &p4, const Point &vtx,
86  float trkPt, float etaAtVtx, float phiAtVtx, int pdgId,
87  const reco::VertexRefProd &pvRefProd,
88  reco::VertexRef::key_type pvRefKey) :
91  p4_(new PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M())),
92  p4c_( new LorentzVector(p4)), vertex_( new Point(vtx) ) ,
93  dphi_(reco::deltaPhi(phiAtVtx,p4_.load()->phi())),
94  deta_(std::abs(etaAtVtx-p4_.load()->eta())>=kMinDEtaToStore_ ? etaAtVtx-p4_.load()->eta() : 0.),
95  dtrkpt_(std::abs(trkPt-p4_.load()->pt())>=kMinDTrkPtToStore_ ? trkPt-p4_.load()->pt() : 0.),
96  track_(nullptr), pdgId_(pdgId), qualityFlags_(0),
97  pvRefProd_(pvRefProd), pvRefKey_(pvRefKey),
99  packBoth();
100  }
101 
103  packedPt_(iOther.packedPt_), packedEta_(iOther.packedEta_),
104  packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
105  packedDxy_(iOther.packedDxy_), packedDz_(iOther.packedDz_),
112  packedTime_(iOther.packedTime_),
115  //Need to trigger unpacking in iOther
116  p4_( new PolarLorentzVector(iOther.polarP4() ) ),
117  p4c_( new LorentzVector(iOther.p4())), vertex_( new Point(iOther.vertex())),
118  dxy_(iOther.dxy_), dz_(iOther.dz_),
119  dphi_(iOther.dphi_), deta_(iOther.deta_), dtrkpt_(iOther.dtrkpt_),
120  track_( iOther.track_ ? new reco::Track(*iOther.track_) : nullptr),
121  pdgId_(iOther.pdgId_), qualityFlags_(iOther.qualityFlags_),
122  pvRefProd_(iOther.pvRefProd_),pvRefKey_(iOther.pvRefKey_),
123  m_(iOther.m_? new reco::TrackBase::CovarianceMatrix(*iOther.m_) : nullptr),
126  }
127 
129  packedPt_(iOther.packedPt_), packedEta_(iOther.packedEta_),
130  packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
131  packedDxy_(iOther.packedDxy_), packedDz_(iOther.packedDz_),
138  packedTime_(iOther.packedTime_),
141  p4_( iOther.p4_.exchange(nullptr) ) ,
142  p4c_( iOther.p4c_.exchange(nullptr)), vertex_(iOther.vertex_.exchange(nullptr)),
143  dxy_(iOther.dxy_), dz_(iOther.dz_),
144  dphi_(iOther.dphi_), deta_(iOther.deta_), dtrkpt_(iOther.dtrkpt_),
145  track_( iOther.track_.exchange(nullptr) ),
146  pdgId_(iOther.pdgId_), qualityFlags_(iOther.qualityFlags_),
147  pvRefProd_(std::move(iOther.pvRefProd_)),pvRefKey_(iOther.pvRefKey_),
148  m_( iOther.m_.exchange(nullptr)),
151  }
152 
153 
155  if(this == &iOther) {
156  return *this;
157  }
158  packedPt_ =iOther.packedPt_;
159  packedEta_=iOther.packedEta_;
160  packedPhi_=iOther.packedPhi_;
161  packedM_=iOther.packedM_;
162  packedDxy_=iOther.packedDxy_;
163  packedDz_=iOther.packedDz_;
164  packedDPhi_=iOther.packedDPhi_;
165  packedDEta_=iOther.packedDEta_;
172  packedTime_=iOther.packedTime_;
175  //Need to trigger unpacking in iOther
176  if(p4_) {
177  *p4_ = iOther.polarP4();
178  } else {
179  p4_.store( new PolarLorentzVector(iOther.polarP4() ) ) ;
180  }
181  if(p4c_) {
182  *p4c_ = iOther.p4();
183  } else {
184  p4c_.store( new LorentzVector(iOther.p4()));
185  }
186  if(vertex_) {
187  *vertex_ = iOther.vertex();
188  } else {
189  vertex_.store( new Point(iOther.vertex()));
190  }
191  dxy_=iOther.dxy_;
192  dz_ = iOther.dz_;
193  dphi_=iOther.dphi_;
194  deta_=iOther.deta_;
195  dtrkpt_=iOther.dtrkpt_;
196 
197  if(!iOther.track_) {
198  delete track_.exchange(nullptr);
199  } else {
200  if(!track_) {
201  track_.store( new reco::Track(*iOther.track_));
202  } else {
203  *track_ = *(iOther.track_);
204  }
205  }
206 
207  pdgId_=iOther.pdgId_;
209  pvRefProd_=iOther.pvRefProd_;
210  pvRefKey_=iOther.pvRefKey_;
211  if(!iOther.m_) {
212  delete m_.exchange(nullptr);
213  } else {
214  if(!m_) {
215  m_.store( new reco::Track::CovarianceMatrix(*iOther.m_));
216  } else {
217  *m_ = *(iOther.m_);
218  }
219  }
220 
221 
222  packedHits_=iOther.packedHits_;
227  firstHit_=iOther.firstHit_;
228  return *this;
229  }
230 
232  if(this == &iOther) {
233  return *this;
234  }
235  packedPt_ =iOther.packedPt_;
236  packedEta_=iOther.packedEta_;
237  packedPhi_=iOther.packedPhi_;
238  packedM_=iOther.packedM_;
239  packedDxy_=iOther.packedDxy_;
240  packedDz_=iOther.packedDz_;
241  packedDPhi_=iOther.packedDPhi_;
242  packedDEta_=iOther.packedDEta_;
243  packedDTrkPt_=iOther.packedDTrkPt_;
244  packedCovariance_=iOther.packedCovariance_;
245  packedPuppiweight_=iOther.packedPuppiweight_;
246  packedPuppiweightNoLepDiff_=iOther.packedPuppiweightNoLepDiff_;
247  rawCaloFraction_=iOther.rawCaloFraction_;
248  hcalFraction_=iOther.hcalFraction_;
249  packedTime_=iOther.packedTime_;
250  packedTimeError_=iOther.packedTimeError_;
251  isIsolatedChargedHadron_=iOther.isIsolatedChargedHadron_;
252  delete p4_.exchange(iOther.p4_.exchange(nullptr));
253  delete p4c_.exchange(iOther.p4c_.exchange(nullptr));
254  delete vertex_.exchange(iOther.vertex_.exchange(nullptr));
255  dxy_=iOther.dxy_;
256  dz_ = iOther.dz_;
257  dphi_=iOther.dphi_;
258  deta_=iOther.deta_;
259  dtrkpt_=iOther.dtrkpt_;
260  delete track_.exchange(iOther.track_.exchange( nullptr));
261  pdgId_=iOther.pdgId_;
262  qualityFlags_=iOther.qualityFlags_;
263  pvRefProd_=iOther.pvRefProd_;
264  pvRefKey_=iOther.pvRefKey_;
265  delete m_.exchange(iOther.m_.exchange(nullptr));
266  packedHits_=iOther.packedHits_;
267  packedLayers_=iOther.packedLayers_;
268  normalizedChi2_=iOther.normalizedChi2_;
269  covarianceVersion_=iOther.covarianceVersion_;
270  covarianceSchema_=iOther.covarianceSchema_;
271  firstHit_=iOther.firstHit_;
272  return *this;
273  }
274 
276  ~PackedCandidate() override;
278  size_t numberOfDaughters() const override;
280  const reco::Candidate * daughter( size_type ) const override;
282  size_t numberOfMothers() const override;
284  const reco::Candidate * mother( size_type ) const override;
286  reco::Candidate * daughter( size_type ) override;
288  reco::Candidate * daughter(const std::string& s ) override;
290  const reco::Candidate * daughter(const std::string& s ) const override;
293  size_t numberOfSourceCandidatePtrs() const override {return 0;}
297  return reco::CandidatePtr();
298  }
299 
301  int charge() const override {
302  switch (abs(pdgId_)) {
303  case 211: return (pdgId_>0)-(pdgId_<0);
304  case 11: return (-1)*(pdgId_>0)+(pdgId_<0); //e
305  case 13: return (-1)*(pdgId_>0)+(pdgId_<0); //mu
306  case 15: return (-1)*(pdgId_>0)+(pdgId_<0); //tau
307  case 24: return (pdgId_>0)-(pdgId_<0); //W
308  default: return 0; //FIXME: charge is not defined
309  }
310  }
312  void setCharge( int charge) override {}
314  int threeCharge() const override {return charge()*3;}
316  void setThreeCharge( int threecharge) override {}
318  const LorentzVector & p4() const override { if (!p4c_) unpack(); return *p4c_; }
320  const PolarLorentzVector & polarP4() const override { if (!p4c_) unpack(); return *p4_; }
322  Vector momentum() const override { if (!p4c_) unpack(); return p4c_.load()->Vect(); }
325  Vector boostToCM() const override { if (!p4c_) unpack(); return p4c_.load()->BoostToCM(); }
327  double p() const override { if (!p4c_) unpack(); return p4c_.load()->P(); }
329  double energy() const override { if (!p4c_) unpack(); return p4c_.load()->E(); }
331  double et() const override { return (pt()<=0) ? 0 : p4c_.load()->Et(); }
333  double et2() const override { return (pt()<=0) ? 0 : p4c_.load()->Et2(); }
335  double mass() const override { if (!p4c_) unpack(); return p4_.load()->M(); }
337  double massSqr() const override { if (!p4c_) unpack(); auto m = p4_.load()->M(); return m*m;}
338 
340  double mt() const override { if (!p4c_) unpack(); return p4_.load()->Mt(); }
342  double mtSqr() const override { if (!p4c_) unpack(); return p4_.load()->Mt2(); }
344  double px() const override { if (!p4c_) unpack(); return p4c_.load()->Px(); }
346  double py() const override { if (!p4c_) unpack(); return p4c_.load()->Py(); }
348  double pz() const override { if (!p4c_) unpack(); return p4c_.load()->Pz(); }
350  double pt() const override { if (!p4c_) unpack(); return p4_.load()->Pt();}
352  double phi() const override { if (!p4c_) unpack(); return p4_.load()->Phi(); }
353 
355  virtual double ptTrk() const {
356  maybeUnpackBoth();
357  return p4_.load()->pt() + dtrkpt_;
358  }
360  virtual float phiAtVtx() const {
361  maybeUnpackBoth();
362  float ret = p4_.load()->Phi() + dphi_;
363  while (ret > float(M_PI)) ret -= 2*float(M_PI);
364  while (ret < -float(M_PI)) ret += 2*float(M_PI);
365  return ret;
366  }
368  virtual float etaAtVtx() const {
369  maybeUnpackBoth();
370  return p4_.load()->eta() + deta_;
371  }
372 
374  double theta() const override { if (!p4c_) unpack(); return p4_.load()->Theta(); }
376  double eta() const override { if (!p4c_) unpack(); return p4_.load()->Eta(); }
378  double rapidity() const override { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
380  double y() const override { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
382  void setP4( const LorentzVector & p4 ) override {
383  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
384  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
385  packBoth();
386  }
388  void setP4( const PolarLorentzVector & p4 ) override {
389  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
390  *p4_ = p4;
391  packBoth();
392  }
394  void setMass( double m ) override {
395  if (!p4c_) unpack();
396  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
397  pack();
398  }
399  void setPz( double pz ) override {
400  maybeUnpackBoth(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
401  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
402  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
403  packBoth();
404  }
406 
407  // Note: mask is also the maximum value
411  };
412 
413  // set number of tracker hits and layers
414  virtual void setHits( const reco::Track & tk) {
415  // first we count the number of layers with hits
416  int numberOfPixelLayers_ = tk.hitPattern().pixelLayersWithMeasurement();
417  if (numberOfPixelLayers_ > trackPixelHitsMask) numberOfPixelLayers_ = trackPixelHitsMask;
418  int numberOfStripLayers_ = tk.hitPattern().stripLayersWithMeasurement();
419  if (numberOfStripLayers_ > trackStripHitsMask) numberOfStripLayers_ = trackStripHitsMask;
420  packedLayers_ = (numberOfPixelLayers_&trackPixelHitsMask) | (numberOfStripLayers_ << trackStripHitsShift);
421  // now we count number of additional hits, beyond the one-per-layer implied by packedLayers_
422  int numberOfPixelHits_ = tk.hitPattern().numberOfValidPixelHits() - numberOfPixelLayers_;
423  if (numberOfPixelHits_ > trackPixelHitsMask) numberOfPixelHits_ = trackPixelHitsMask;
424  int numberOfStripHits_ = tk.hitPattern().numberOfValidHits() - numberOfPixelHits_ - numberOfPixelLayers_ - numberOfStripLayers_;
425  if (numberOfStripHits_ > trackStripHitsMask) numberOfStripHits_ = trackStripHitsMask;
426 
427  packedHits_ = (numberOfPixelHits_&trackPixelHitsMask) | (numberOfStripHits_ << trackStripHitsShift);
428  }
429 
430  virtual void setTrackProperties( const reco::Track & tk, const reco::Track::CovarianceMatrix & covariance,int quality,int covarianceVersion) {
434  setHits(tk);
435  packBoth();
436  packCovariance(covariance,false);
437  }
438 
439  // set track properties using quality and covarianceVersion to define the level of details in the cov. matrix
440  virtual void setTrackProperties( const reco::Track & tk,int quality,int covarianceVersion ) {
442  }
443 
450  int covarianceVersion() const { return covarianceVersion_;}
451  int covarianceSchema() const { return covarianceSchema_;}
452 
453 
455  const Point & vertex() const override { maybeUnpackBoth(); return *vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
457  double vx() const override { maybeUnpackBoth(); return vertex_.load()->X(); }//{ return 0; }
459  double vy() const override { maybeUnpackBoth(); return vertex_.load()->Y(); }//{ return 0; }
461  double vz() const override { maybeUnpackBoth(); return vertex_.load()->Z(); }//{ if (fromPV_) return 0; else return 100; }
463  void setVertex( const Point & vertex ) override { maybeUnpackBoth(); *vertex_ = vertex; packVtx(); }
464 
466  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
467  const PVAssoc fromPV(size_t ipv=0) const {
468  reco::VertexRef pvRef = vertexRef();
469  if(pvAssociationQuality()==UsedInFitTight and pvRef.key()==ipv) return PVUsedInFit;
470  if(pvRef.key()==ipv or abs(pdgId())==13 or abs(pdgId())==11 ) return PVTight;
471  if(pvAssociationQuality() == CompatibilityBTag and std::abs(dzAssociatedPV()) > std::abs(dz(ipv))) return PVTight; // it is not closest, but at least prevents the B assignment stealing
472  if(pvAssociationQuality() < UsedInFitLoose or pvRef->ndof() < 4.0 ) return PVLoose;
473  return NoPV;
474  }
475 
481 
483 
485  virtual float dxy() const { maybeUnpackBoth(); return dxy_; }
487  virtual float dz(size_t ipv=0) const { maybeUnpackBoth(); return dz_ + (*pvRefProd_)[pvRefKey_].position().z()-(*pvRefProd_)[ipv].position().z(); }
489  virtual float dzAssociatedPV() const { maybeUnpackBoth(); return dz_; }
491  virtual float dxy(const Point &p) const ;
493  virtual float dz(const Point &p) const ;
494 
496  float dzError() const override { maybeUnpackCovariance(); return sqrt((*m_.load())(4,4)); }
498  float dxyError() const override { maybeUnpackCovariance(); return sqrt((*m_.load())(3,3)); }
499 
500 
502  virtual const reco::Track & pseudoTrack() const { if (!track_) unpackTrk(); return *track_; }
503 
505  const reco::Track * bestTrack() const override {
506  if (packedHits_!=0 || packedLayers_ !=0) {
508  return track_.load();
509  }
510  else
511  return nullptr;
512  }
514  bool hasTrackDetails() const {return (packedHits_!=0 || packedLayers_ !=0); }
515 
516 
521 
525  noLostInnerHits=0, // it could still not have a hit in the first layer, e.g. if it crosses an inactive sensor
528  };
531  }
533  int lost = hits; if (lost > 2) lost = 2; // protection against misuse
534  lost++; // shift so it's 0 .. 3 instead of (-1) .. 2
536  }
537 
539  void setFirstHit(uint16_t pattern) {
541  }
543  uint16_t firstHit() const { return firstHit_;}
544 
545  void setMuonID(bool isStandAlone, bool isGlobal) {
546  int16_t muonFlags = isStandAlone | (2*isGlobal);
548  }
549 
551  int pdgId() const override { return pdgId_; }
552  // set PDG identifier
553  void setPdgId( int pdgId ) override { pdgId_ = pdgId; }
555  int status() const override { return qualityFlags_; } /*FIXME*/
557  void setStatus( int status ) override {} /*FIXME*/
559  static const unsigned int longLivedTag = 0; /*FIXME*/
561  void setLongLived() override {} /*FIXME*/
563  bool longLived() const override;
565  static const unsigned int massConstraintTag = 0; /*FIXME*/
567  void setMassConstraint() override {} /*FIXME*/
569  bool massConstraint() const override;
570 
572  PackedCandidate * clone() const override {
573  return new PackedCandidate( *this );
574  }
575 
577  double vertexChi2() const override;
584  double vertexNdof() const override;
586  double vertexNormalizedChi2() const override;
588  double vertexCovariance(int i, int j) const override;
592  void fillVertexCovariance(CovarianceMatrix & v) const override;
595  bool hasMasterClone() const override;
598  const reco::CandidateBaseRef & masterClone() const override;
601  bool hasMasterClonePtr() const override;
604 
605  const reco::CandidatePtr & masterClonePtr() const override;
606 
608  template<typename Ref>
609  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
610 
611  bool isElectron() const override { return false; }
612  bool isMuon() const override { return false; }
613  bool isStandAloneMuon() const override { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 1; }
614  bool isGlobalMuon() const override { return ((qualityFlags_ & muonFlagsMask) >> muonFlagsShift) & 2; }
615  bool isTrackerMuon() const override { return false; }
616  bool isCaloMuon() const override { return false; }
617  bool isPhoton() const override { return false; }
618  bool isConvertedPhoton() const override { return false; }
619  bool isJet() const override { return false; }
620 
621  // puppiweights
622  void setPuppiWeight(float p, float p_nolep = 0.0);
623  float puppiWeight() const;
624  float puppiWeightNoLep() const;
625 
626  // for the neutral fractions
627  void setRawCaloFraction(float p);
628  float rawCaloFraction() const { return (rawCaloFraction_/100.); }
629  void setHcalFraction(float p);
630  float hcalFraction() const { return (hcalFraction_/100.); }
631 
632  // isolated charged hadrons
633  void setIsIsolatedChargedHadron(bool p);
635 
638  //3D IP covariance
639  uint16_t dxydxy;
640  uint16_t dxydz;
641  uint16_t dzdz;
642  //other IP relevant elements
643  uint16_t dlambdadz;
644  uint16_t dphidxy;
645  //other diag elements
646  uint16_t dptdpt;
647  uint16_t detadeta;
648  uint16_t dphidphi;
649  };
650 
652  virtual float time() const { return vertexRef()->t() + dtimeAssociatedPV(); }
654  virtual float dtime(size_t ipv=0) const { return dtimeAssociatedPV() + (*pvRefProd_)[pvRefKey_].t()-(*pvRefProd_)[ipv].t(); }
656  virtual float dtimeAssociatedPV() const {
657  if (packedTime_ == 0) return 0.f;
659  else return unpackTimeNoError(packedTime_);
660  }
662  virtual float timeError() const { return unpackTimeError(packedTimeError_); }
664  void setDTimeAssociatedPV(float aTime, float aTimeError=0) ;
666  void setTime(float aTime, float aTimeError=0) { setDTimeAssociatedPV(aTime - vertexRef()->t(), aTimeError); }
667 
668  private:
669  void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix & m, uint16_t packed, int i,int j) const {
671  }
672  uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m,int i,int j) const {
674  }
675 
676  protected:
677  friend class ::testPackedCandidate;
678  static constexpr float kMinDEtaToStore_=0.001;
679  static constexpr float kMinDTrkPtToStore_=0.001;
680 
681 
685 
686  void pack(bool unpackAfterwards=true) ;
687  void unpack() const ;
688  void packVtx(bool unpackAfterwards=true) ;
689  void unpackVtx() const ;
690  void packCovariance(const reco::TrackBase::CovarianceMatrix & m,bool unpackAfterwards=true) ;
691  void unpackCovariance() const;
692  void maybeUnpackBoth() const { if (!p4c_) unpack(); if (!vertex_) unpackVtx(); }
693  void maybeUnpackTrack() const { if (!track_) unpackTrk(); }
694  void maybeUnpackCovariance() const { if (!m_) unpackCovariance(); }
695  void packBoth() { pack(false); packVtx(false); delete p4_.exchange(nullptr); delete p4c_.exchange(nullptr); delete vertex_.exchange(nullptr); unpack(); unpackVtx(); } // do it this way, so that we don't loose precision on the angles before computing dxy,dz
696  void unpackTrk() const ;
697 
699  int8_t packedPuppiweightNoLepDiff_; // storing the DIFFERENCE of (all - "no lep") for compression optimization
702  int16_t packedTime_;
704 
706 
708  mutable std::atomic<PolarLorentzVector*> p4_;
709  mutable std::atomic<LorentzVector*> p4c_;
711  mutable std::atomic<Point*> vertex_;
712  CMS_THREAD_GUARD(vertex_) mutable float dxy_, dz_, dphi_, deta_, dtrkpt_;
714  mutable std::atomic<reco::Track*> track_;
716  int pdgId_;
717  uint16_t qualityFlags_;
721 
723  mutable std::atomic<reco::TrackBase::CovarianceMatrix *> m_;
724  uint8_t packedHits_, packedLayers_; // packedLayers_ -> layers with valid hits; packedHits_ -> extra hits beyond the one-per-layer implied by packedLayers_
725 
727  uint8_t normalizedChi2_;
731  //static std::atomic<CovarianceParameterization*> covarianceParameterization_;
732  static std::once_flag covariance_load_flag;
734  if (!hasTrackDetails()) throw edm::Exception(edm::errors::InvalidReference, "Trying to access covariance matrix for a PackedCandidate for which it's not available. Check hasTrackDetails() before!\n");
735  std::call_once(covariance_load_flag,[](int v) { covarianceParameterization_.load(v); } ,covarianceVersion_ );
736  if(covarianceParameterization_.loadedVersion() != covarianceVersion_ )
737  {
739  << "Attempting to load multiple covariance version in same process. This is not supported.";
740  }
742  }
743 
745  bool overlap( const reco::Candidate & ) const override;
746  template<typename, typename, typename> friend struct component;
747  friend class ::OverlapChecker;
748  friend class ShallowCloneCandidate;
750 
756  };
757 
759  static uint8_t packTimeError(float timeError) ;
760  static float unpackTimeError(uint8_t timeError) ;
761  static float unpackTimeNoError(int16_t time) ;
762  static int16_t packTimeNoError(float time) ;
763  static float unpackTimeWithError(int16_t time, uint8_t timeError) ;
764  static int16_t packTimeWithError(float time, float timeError) ;
765  static constexpr float MIN_TIMEERROR = 0.002f; // 2 ps, smallest storable non-zero uncertainty
766  static constexpr float MIN_TIME_NOERROR = 0.0002f; // 0.2 ps, smallest non-zero time that can be stored by packTimeNoError
767  static constexpr int EXPO_TIMEERROR = 5; // power of 2 used in encoding timeError
768  static constexpr int EXPO_TIME_NOERROR = 6; // power of 2 used in encoding time without timeError
769  static constexpr int EXPO_TIME_WITHERROR = -6; // power of 2 used in encoding time with timeError
770  public:
771  uint16_t firstHit_;
772 
773  };
774 
775  typedef std::vector<pat::PackedCandidate> PackedCandidateCollection;
778 }
779 
780 #endif
float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
static float MIN_TIME_NOERROR
void setMuonID(bool isStandAlone, bool isGlobal)
void setStatus(int status) override
set status word
double theta() const override
momentum polar angle
static int EXPO_TIME_NOERROR
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:169
float dxyError() const override
uncertainty on dxy
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
double px() const override
x coordinate of momentum vector
virtual float etaAtVtx() const
eta from the track (normally identical to eta())
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
bool isTrackerMuon() const override
int covarianceSchema() const
float puppiWeightNoLep() const
Weight from full PUPPI.
void setPuppiWeight(float p, float p_nolep=0.0)
void setThreeCharge(int threecharge) override
set electric charge
std::atomic< Point * > vertex_
vertex position
int numberOfHits() const
size_t size_type
Definition: Candidate.h:30
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
CovarianceMatrix vertexCovariance() const override
return SMatrix
int pdgId() const override
PDG identifier.
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:561
uint16_t packCovarianceElement(const reco::TrackBase::CovarianceMatrix &m, int i, int j) const
float hcalFraction() const
Set the fraction of Hcal needed for HF and neutral hadrons and isolated charged hadrons.
bool hasMasterClonePtr() const override
reco::VertexRef::key_type pvRefKey_
int pixelLayersWithMeasurement() const
void maybeUnpackBoth() const
static const unsigned int longLivedTag
long lived flag
int numberOfValidHits() const
Definition: HitPattern.h:823
PackedCandidate & operator=(const PackedCandidate &iOther)
static const unsigned int massConstraintTag
do mass constraint flag
double vertexChi2() const override
chi-squares
bool isMuon() const override
bool longLived() const override
is long lived?
static float unpackTimeNoError(int16_t time)
double vertexNdof() const override
std::vector< pat::PackedCandidate > PackedCandidateCollection
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
math::XYZPoint Point
point in the space
virtual void setCovarianceVersion(int v)
void setRawCaloFraction(float p)
Weight from PUPPI removing leptons.
const reco::CandidatePtr & masterClonePtr() const override
float dzError() const override
uncertainty on dz
static int16_t packTimeNoError(float time)
PackedCandidate(const PackedCandidate &iOther)
double massSqr() const override
mass squared
bool isPhoton() const override
virtual float time() const
time (wrt nominal zero of the collision)
void unpackCovarianceElement(reco::TrackBase::CovarianceMatrix &m, uint16_t packed, int i, int j) const
PackedCovariance packedCovariance_
key_type key() const
Accessor for product key.
Definition: Ref.h:265
virtual float dtime(size_t ipv=0) const
dtime with respect to the PV[ipv]
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:493
static int16_t packTimeWithError(float time, float timeError)
Vector momentum() const override
spatial momentum vector
#define nullptr
double vz() const override
z coordinate of vertex position
bool isConvertedPhoton() const override
bool isGlobalMuon() const override
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
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)
double pz() const override
z coordinate of momentum vector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
#define constexpr
PackedCandidate(const reco::Candidate &c, 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
double py() const override
y coordinate of momentum vector
Ref masterRef() const
cast master clone reference to a concrete type
Definition: HeavyIon.h:7
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
reco::CandidateCollection daughters
collection of daughter candidates
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
bool massConstraint() const override
do mass constraint?
static float MIN_TIMEERROR
int status() const override
status word
int charge() const override
electric charge
void setP4(const LorentzVector &p4) override
set 4-momentum
size_t numberOfMothers() const override
number of mothers
double vy() const override
y coordinate of vertex position
friend struct component
Vector boostToCM() const override
std::atomic< reco::Track * > track_
reco::Track
double rapidity() const override
rapidity
const PVAssociationQuality pvAssociationQuality() const
void setHcalFraction(float p)
Raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
virtual float timeError() const
time measurement uncertainty (-1 if not available)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual void setTrackProperties(const reco::Track &tk, int quality, int covarianceVersion)
void maybeUnpackCovariance() const
const PVAssoc fromPV(size_t ipv=0) const
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:731
T sqrt(T t)
Definition: SSEVec.h:18
void setMass(double m) override
set particle mass
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
bool trackHighPurity() const
true if the track had the highPurity quality bit
const Point & vertex() const override
vertex position
void setPz(double pz) override
LostInnerHits lostInnerHits() const
void setLongLived() override
set long lived flag
PackedCandidate()
default constructor
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
friend class ShallowCloneCandidate
void setP4(const PolarLorentzVector &p4) override
set 4-momentum
double mtSqr() const override
transverse mass squared
static CovarianceParameterization covarianceParameterization_
virtual double ptTrk() const
pt from the track (normally identical to pt())
#define CMS_THREAD_GUARD(_var_)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int stripLayersWithMeasurement() const
double energy() const override
energy
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
virtual const reco::Track & pseudoTrack() const
Return reference to a pseudo track made with candidate kinematics, parameterized error for eta...
std::atomic< PolarLorentzVector * > p4_
the four vector
#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)
double pt() const override
transverse momentum
virtual float dtimeAssociatedPV() const
dtime with respect to the PV ref
double p() const override
magnitude of momentum vector
double et() const override
transverse energy
int threeCharge() const override
electric charge
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
virtual float dzAssociatedPV() const
dz with respect to the PV ref
int numberOfPixelHits() const
static int EXPO_TIME_WITHERROR
int trackerLayersWithMeasurement() const
std::atomic< LorentzVector * > p4c_
#define M_PI
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
bool isJet() const override
std::atomic< reco::TrackBase::CovarianceMatrix * > m_
IP covariance.
LostInnerHits
Enumerator specifying the.
double eta() const override
momentum pseudorapidity
bool isCaloMuon() const override
double phi() const override
momentum azimuthal angle
uint8_t normalizedChi2_
track quality information
PVAssoc
This refers to the association to PV=ipv. >=PVLoose corresponds to JME definition, >=PVTight to isolation definition.
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
bool isStandAloneMuon() const override
void setTime(float aTime, float aTimeError=0)
set time measurement
size_t numberOfSourceCandidatePtrs() const override
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::RefVector< pat::PackedCandidateCollection > PackedCandidateRefVector
def load(fileName)
Definition: svgfig.py:546
int stripLayersWithMeasurement() const
Definition: HitPattern.h:1035
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
static std::once_flag covariance_load_flag
void setPdgId(int pdgId) override
int covarianceVersion() const
static float kMinDEtaToStore_
virtual float phiAtVtx() const
momentum azimuthal angle from the track (normally identical to phi())
void setFirstHit(uint16_t pattern)
Set first hit from HitPattern.
int pdgId_
PDG identifier.
double et2() const override
transverse energy squared (use this for cuts)!
edm::RefProd< VertexCollection > VertexRefProd
persistent reference to a Vertex
Definition: VertexFwd.h:15
double mass() const override
mass
float rawCaloFraction() const
Set the raw ECAL+HCAL energy over candidate energy for isolated charged hadrons.
void unpackCovariance() const
void setDTimeAssociatedPV(float aTime, float aTimeError=0)
set time measurement
friend class ShallowClonePtrCandidate
uint16_t firstHit() const
Return first hit from HitPattern for tracks with high level details.
fixed size matrix
Flag isolation (as in particle flow, i.e. at calorimeter surface rather than at PV) flag for charged ...
PackedCandidate * clone() const override
returns a clone of the Candidate object
PackedCandidate & operator=(PackedCandidate &&iOther)
size_t numberOfDaughters() const override
number of daughters
void packVtx(bool unpackAfterwards=true)
void setLostInnerHits(LostInnerHits hits)
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
PackedCandidate(const LorentzVector &p4, const Point &vtx, float trkPt, float etaAtVtx, float phiAtVtx, int pdgId, const reco::VertexRefProd &pvRefProd, reco::VertexRef::key_type pvRefKey)
trackHitShiftsAndMasks
set impact parameters covariance
void setVertex(const Point &vertex) override
set vertex
int numberOfValidPixelHits() const
Definition: HitPattern.h:838
void setIsIsolatedChargedHadron(bool p)
Fraction of Ecal and Hcal for HF and neutral hadrons and isolated charged hadrons.
double mt() const override
transverse mass
void pack(bool unpackAfterwards=true)
double y() const override
rapidity
void packCovariance(const reco::TrackBase::CovarianceMatrix &m, bool unpackAfterwards=true)
const reco::CandidateBaseRef & masterClone() const override
virtual float dxy() const
dxy with respect to the PV ref
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
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)
void maybeUnpackTrack() const
virtual void setHits(const reco::Track &tk)
bool isIsolatedChargedHadron() const
Set isolation (as in particle flow, i.e. at calorimeter surface rather than at PV) flat for charged h...
const CovarianceParameterization & covarianceParameterization() const
bool isElectron() const override
bool hasMasterClone() const override
void setCharge(int charge) override
set electric charge
math::XYZVector Vector
point in the space
const PolarLorentzVector & polarP4() const override
four-momentum Lorentz vector
def move(src, dest)
Definition: eostools.py:510
static float unpackTimeError(uint8_t timeError)
double vx() const override
x coordinate of vertex position
static float kMinDTrkPtToStore_
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
reco::VertexRefProd pvRefProd_
Use these to build a Ref to primary vertex.
void setAssociationQuality(PVAssociationQuality q)