CMS 3D CMS Logo

PackedGenParticle.h
Go to the documentation of this file.
1 #ifndef __AnalysisDataFormats_PackedGenParticle_h__
2 #define __AnalysisDataFormats_PackedGenParticle_h__
3 
14 /* #include "DataFormats/Math/interface/PtEtaPhiMass.h" */
15 
16 class testPackedGenParticle;
17 
18 namespace pat {
20  public:
21  friend class ::testPackedGenParticle;
22 
33 
34  typedef unsigned int index;
35 
38  : packedPt_(0),
39  packedY_(0),
40  packedPhi_(0),
41  packedM_(0),
42  p4_(nullptr),
43  p4c_(nullptr),
44  vertex_(0, 0, 0),
45  pdgId_(0),
46  charge_(0) {}
48  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())),
49  p4c_(new LorentzVector(*p4_)),
50  vertex_(0, 0, 0),
51  pdgId_(c.pdgId()),
52  charge_(c.charge()),
53  mother_(c.motherRef(0)),
55  pack();
56  }
58  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())),
59  p4c_(new LorentzVector(*p4_)),
60  vertex_(0, 0, 0),
61  pdgId_(c.pdgId()),
62  charge_(c.charge()),
63  mother_(mother),
65  pack();
66  }
67 
69  : packedPt_(iOther.packedPt_),
70  packedY_(iOther.packedY_),
71  packedPhi_(iOther.packedPhi_),
72  packedM_(iOther.packedM_),
73  p4_(nullptr),
74  p4c_(nullptr),
75  vertex_(iOther.vertex_),
76  dxy_(iOther.dxy_),
77  dz_(iOther.dz_),
78  dphi_(iOther.dphi_),
79  pdgId_(iOther.pdgId_),
80  charge_(iOther.charge_),
81  mother_(iOther.mother_),
82  statusFlags_(iOther.statusFlags_) {
83  if (iOther.p4c_) {
84  p4_.store(new PolarLorentzVector(*iOther.p4_));
85  p4c_.store(new LorentzVector(*iOther.p4c_));
86  }
87  }
88 
90  : packedPt_(iOther.packedPt_),
91  packedY_(iOther.packedY_),
92  packedPhi_(iOther.packedPhi_),
93  packedM_(iOther.packedM_),
94  p4_(nullptr),
95  p4c_(nullptr),
96  vertex_(std::move(iOther.vertex_)),
97  dxy_(iOther.dxy_),
98  dz_(iOther.dz_),
99  dphi_(iOther.dphi_),
100  pdgId_(iOther.pdgId_),
101  charge_(iOther.charge_),
102  mother_(iOther.mother_),
103  statusFlags_(iOther.statusFlags_) {
104  if (iOther.p4c_) {
105  p4_.store(p4_.exchange(nullptr));
106  p4c_.store(p4c_.exchange(nullptr));
107  }
108  }
109 
111  if (this != &iOther) {
112  packedPt_ = iOther.packedPt_;
113  packedY_ = iOther.packedY_;
114  packedPhi_ = iOther.packedPhi_;
115  packedM_ = iOther.packedM_;
116  if (p4c_) {
117  delete p4_.exchange(iOther.p4_.exchange(nullptr));
118  delete p4c_.exchange(iOther.p4c_.exchange(nullptr));
119  } else {
120  delete p4_.exchange(nullptr);
121  delete p4c_.exchange(nullptr);
122  }
123  vertex_ = std::move(iOther.vertex_);
124  dxy_ = iOther.dxy_;
125  dz_ = iOther.dz_;
126  dphi_ = iOther.dphi_;
127  pdgId_ = iOther.pdgId_;
128  charge_ = iOther.charge_;
129  mother_ = iOther.mother_;
130  statusFlags_ = iOther.statusFlags_;
131  }
132  return *this;
133  }
134 
136  PackedGenParticle c(iOther);
137  *this = std::move(c);
138  return *this;
139  }
140 
142  ~PackedGenParticle() override;
144  size_t numberOfDaughters() const override;
146  const reco::Candidate* daughter(size_type) const override;
148  size_t numberOfMothers() const override;
150  const reco::Candidate* mother(size_type) const override;
153  if (mother_.isNonnull() && mother_.isAvailable() &&
154  mother_->status() == 1) { //if pointing to the pruned version of myself
155  if (mother_->numberOfMothers() > 0)
156  return mother_->motherRef(0); // return my mother's (that is actually myself) mother
157  else
158  return edm::Ref<reco::GenParticleCollection>(); // return null ref
159  } else {
160  return mother_; //the stored ref is really my mother, or null, return that
161  }
162  }
164  const reco::GenParticleRef& lastPrunedRef() const { return mother_; }
165 
169  reco::Candidate* daughter(const std::string& s) override;
171  const reco::Candidate* daughter(const std::string& s) const override;
174  size_t numberOfSourceCandidatePtrs() const override { return 0; }
178 
180  int charge() const override { return charge_; }
182  void setCharge(int charge) override { charge_ = charge; }
184  int threeCharge() const override { return charge() * 3; }
186  void setThreeCharge(int threecharge) override {}
188  const LorentzVector& p4() const override {
189  if (!p4c_)
190  unpack();
191  return *p4c_;
192  }
194  const PolarLorentzVector& polarP4() const override {
195  if (!p4c_)
196  unpack();
197  return *p4_;
198  }
200  Vector momentum() const override {
201  if (!p4c_)
202  unpack();
203  return p4c_.load()->Vect();
204  }
207  Vector boostToCM() const override {
208  if (!p4c_)
209  unpack();
210  return p4c_.load()->BoostToCM();
211  }
213  double p() const override {
214  if (!p4c_)
215  unpack();
216  return p4c_.load()->P();
217  }
219  double energy() const override {
220  if (!p4c_)
221  unpack();
222  return p4c_.load()->E();
223  }
225  double et() const override { return (pt() <= 0) ? 0 : p4c_.load()->Et(); }
227  double et2() const override { return (pt() <= 0) ? 0 : p4c_.load()->Et2(); }
229  double mass() const override {
230  if (!p4c_)
231  unpack();
232  return p4_.load()->M();
233  }
235  double massSqr() const override {
236  if (!p4c_)
237  unpack();
238  return p4_.load()->M() * p4_.load()->M();
239  }
240 
242  double mt() const override {
243  if (!p4c_)
244  unpack();
245  return p4_.load()->Mt();
246  }
248  double mtSqr() const override {
249  if (!p4c_)
250  unpack();
251  return p4_.load()->Mt2();
252  }
254  double px() const override {
255  if (!p4c_)
256  unpack();
257  return p4c_.load()->Px();
258  }
260  double py() const override {
261  if (!p4c_)
262  unpack();
263  return p4c_.load()->Py();
264  }
266  double pz() const override {
267  if (!p4c_)
268  unpack();
269  return p4c_.load()->Pz();
270  }
272  double pt() const override {
273  if (!p4c_)
274  unpack();
275  return p4_.load()->Pt();
276  }
278  double phi() const override {
279  if (!p4c_)
280  unpack();
281  return p4_.load()->Phi();
282  }
284  double theta() const override {
285  if (!p4c_)
286  unpack();
287  return p4_.load()->Theta();
288  }
290  double eta() const override {
291  if (!p4c_)
292  unpack();
293  return p4_.load()->Eta();
294  }
296  double rapidity() const override {
297  if (!p4c_)
298  unpack();
299  return p4_.load()->Rapidity();
300  }
302  double y() const override {
303  if (!p4c_)
304  unpack();
305  return p4_.load()->Rapidity();
306  }
308  void setP4(const LorentzVector& p4) override {
309  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
310  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
311  pack();
312  }
314  void setP4(const PolarLorentzVector& p4) override {
315  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
316  *p4_ = p4;
317  pack();
318  }
320  void setMass(double m) override {
321  if (!p4c_)
322  unpack();
323  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
324  pack();
325  }
326  void setPz(double pz) override {
327  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
328  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
329  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
330  pack();
331  }
333  const Point& vertex() const override {
334  return vertex_;
335  } //{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
337  double vx() const override { return vertex_.X(); } //{ return 0; }
339  double vy() const override { return vertex_.Y(); } //{ return 0; }
341  double vz() const override { return vertex_.Z(); } //{ if (fromPV_) return 0; else return 100; }
343  void setVertex(const Point& vertex) override { vertex_ = vertex; }
344 
345  enum PVAssoc { NoPV = 0, PVLoose = 1, PVTight = 2, PVUsedInFit = 3 };
346 
348  virtual float dxy() const {
349  unpack();
350  return dxy_;
351  }
353  virtual float dz() const {
354  unpack();
355  return dz_;
356  }
358  virtual float dxy(const Point& p) const;
360  virtual float dz(const Point& p) const;
361 
363  int pdgId() const override { return pdgId_; }
364  // set PDG identifier
365  void setPdgId(int pdgId) override { pdgId_ = pdgId; }
367  int status() const override { return 1; } /*FIXME*/
369  void setStatus(int status) override {} /*FIXME*/
371  static const unsigned int longLivedTag = 0; /*FIXME*/
373  void setLongLived() override {} /*FIXME*/
375  bool longLived() const override;
377  static const unsigned int massConstraintTag = 0; /*FIXME*/
379  void setMassConstraint() override {} /*FIXME*/
381  bool massConstraint() const override;
382 
384  PackedGenParticle* clone() const override { return new PackedGenParticle(*this); }
385 
387  double vertexChi2() const override;
394  double vertexNdof() const override;
396  double vertexNormalizedChi2() const override;
398  double vertexCovariance(int i, int j) const override;
403  return m;
404  }
406  void fillVertexCovariance(CovarianceMatrix& v) const override;
409  bool hasMasterClone() const override;
412  const reco::CandidateBaseRef& masterClone() const override;
415  bool hasMasterClonePtr() const override;
418 
419  const reco::CandidatePtr& masterClonePtr() const override;
420 
422  template <typename Ref>
423  Ref masterRef() const {
424  return masterClone().template castTo<Ref>();
425  }
427 
428  bool isElectron() const override;
429  bool isMuon() const override;
430  bool isStandAloneMuon() const override;
431  bool isGlobalMuon() const override;
432  bool isTrackerMuon() const override;
433  bool isCaloMuon() const override;
434  bool isPhoton() const override;
435  bool isConvertedPhoton() const override;
436  bool isJet() const override;
437 
438  const reco::GenStatusFlags& statusFlags() const { return statusFlags_; }
440 
442  //basic set of gen status flags accessible directly here
443  //the rest accessible through statusFlags()
444  //(see GenStatusFlags.h for their meaning)
445 
447  //these are robust, generator-independent functions for categorizing
448  //mainly final state particles, but also intermediate hadrons/taus
449 
450  //is particle prompt (not from hadron, muon, or tau decay) and final state
451  bool isPromptFinalState() const { return status() == 1 && statusFlags_.isPrompt(); }
452 
453  //this particle is a direct decay product of a prompt tau and is final state
454  //(eg an electron or muon from a leptonic decay of a prompt tau)
457  }
458 
460  //these are generator history-dependent functions for tagging particles
461  //associated with the hard process
462  //Currently implemented for Pythia 6 and Pythia 8 status codes and history
463  //and may not have 100% consistent meaning across all types of processes
464  //Users are strongly encouraged to stick to the more robust flags above,
465  //as well as the expanded set available in GenStatusFlags.h
466 
467  //this particle is the final state direct descendant of a hard process particle
468  bool fromHardProcessFinalState() const { return status() == 1 && statusFlags_.fromHardProcess(); }
469 
470  //this particle is a direct decay product of a hardprocess tau and is final state
471  //(eg an electron or muon from a leptonic decay of a tau from the hard process)
474  }
475 
476  protected:
478  void pack(bool unpackAfterwards = true);
479  void unpack() const;
480 
482  mutable std::atomic<PolarLorentzVector*> p4_;
483  mutable std::atomic<LorentzVector*> p4c_;
486  float dxy_, dz_, dphi_;
488  int pdgId_;
490  int8_t charge_;
493  //status flags
495 
497  bool overlap(const reco::Candidate&) const override;
498  template <typename, typename, typename>
499  friend struct component;
500  friend class ::OverlapChecker;
501  friend class ShallowCloneCandidate;
503  };
504 
505  typedef std::vector<pat::PackedGenParticle> PackedGenParticleCollection;
508 } // namespace pat
509 
510 #endif
bool hasMasterClone() const override
bool fromHardProcess() const
const Point & vertex() const override
vertex position
bool isDirectHardProcessTauDecayProduct() const
bool isStandAloneMuon() const override
Point vertex_
vertex position
reco::GenStatusFlags & statusFlags()
edm::Ref< pat::PackedGenParticleCollection > PackedGenParticleRef
static const unsigned int longLivedTag
long lived flag
reco::GenParticleRef motherRef() const
direct access to the mother reference (may be null)
math::XYZVector Vector
point in the space
Definition: Candidate.h:42
friend class ShallowCloneCandidate
const reco::GenParticleRef & lastPrunedRef() const
last surviving in pruned
bool fromHardProcessFinalState() const
size_t size_type
Definition: Candidate.h:29
void setMassConstraint() override
set mass constraint flag
double et() const override
transverse energy
bool isCaloMuon() const override
bool longLived() const override
is long lived?
Vector boostToCM() const override
int pdgId_
PDG identifier.
int charge() const override
electric charge
virtual float dz() const
dz with respect to the PV ref
double vertexNdof() const override
size_t numberOfDaughters() const override
number of daughters
bool isDirectHardProcessTauDecayProductFinalState() const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double vy() const override
y coordinate of vertex position
PackedGenParticle(const PackedGenParticle &iOther)
int status() const override
status word
friend class ShallowClonePtrCandidate
bool isDirectPromptTauDecayProduct() const
PackedGenParticle()
default constructor
Ref masterRef() const
cast master clone reference to a concrete type
bool isJet() const override
void setCharge(int charge) override
set electric charge
PackedGenParticle & operator=(PackedGenParticle const &iOther)
std::atomic< LorentzVector * > p4c_
void setMass(double m) override
set particle mass
void pack(bool unpackAfterwards=true)
Vector momentum() const override
spatial momentum vector
Definition: HeavyIon.h:7
math::XYZPoint Point
point in the space
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
virtual float dxy() const
dxy with respect to the PV ref
void setVertex(const Point &vertex) override
set vertex
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
PackedGenParticle(const reco::GenParticle &c)
const LorentzVector & p4() const override
four-momentum Lorentz vecto r
double vertexNormalizedChi2() const override
chi-squared divided by n.d.o.f.
bool hasMasterClonePtr() const override
double pz() const override
z coordinate of momentum vector
void fillVertexCovariance(CovarianceMatrix &v) const override
fill SMatrix
const PolarLorentzVector & polarP4() const override
four-momentum Lorentz vector
double rapidity() const override
rapidity
size_t numberOfMothers() const override
number of mothers
reco::GenParticleRef mother_
Ref to first mother.
math::XYZVector Vector
point in the space
size_t numberOfSourceCandidatePtrs() const override
double vertexChi2() const override
chi-squares
void setPz(double pz) override
bool isAvailable() const
Definition: Ref.h:537
bool overlap(const reco::Candidate &) const override
check overlap with another Candidate
double massSqr() const override
mass squared
double et2() const override
transverse energy squared (use this for cuts)!
PackedGenParticle & operator=(PackedGenParticle &&iOther)
int pdgId() const override
PDG identifier.
~PackedGenParticle() override
destructor
void setThreeCharge(int threecharge) override
set electric charge
bool isPrompt() const
void setPdgId(int pdgId) override
bool isElectron() const override
get a component
int threeCharge() const override
electric charge
double phi() const override
momentum azimuthal angle
PackedGenParticle(const reco::GenParticle &c, const edm::Ref< reco::GenParticleCollection > &mother)
const reco::CandidatePtr & masterClonePtr() const override
void setLongLived() override
set long lived flag
bool massConstraint() const override
do mass constraint?
const reco::CandidateBaseRef & masterClone() const override
double mtSqr() const override
transverse mass squared
double px() const override
x coordinate of momentum vector
static const unsigned int massConstraintTag
do mass constraint flag
reco::CandidateCollection daughters
collection of daughter candidates
bool isDirectPromptTauDecayProductFinalState() const
std::atomic< PolarLorentzVector * > p4_
the four vector
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
bool isConvertedPhoton() const override
void setP4(const PolarLorentzVector &p4) override
set 4-momentum
double py() const override
y coordinate of momentum vector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
double vx() const override
x coordinate of vertex position
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const reco::Candidate * daughter(size_type) const override
return daughter at a given position (throws an exception)
double vz() const override
z coordinate of vertex position
double y() const override
rapidity
PackedGenParticle(PackedGenParticle &&iOther)
PackedGenParticle * clone() const override
returns a clone of the Candidate object
double mass() const override
mass
std::vector< pat::PackedGenParticle > PackedGenParticleCollection
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
reco::CandidatePtr sourceCandidatePtr(size_type i) const override
void setStatus(int status) override
set status word
const reco::Candidate * mother(size_type) const override
return mother at a given position (throws an exception)
Structure Point Contains parameters of Gaussian fits to DMRs.
Definition: DMRtrends.cc:57
bool isGlobalMuon() const override
double eta() const override
momentum pseudorapidity
reco::GenStatusFlags statusFlags_
bool isTrackerMuon() const override
double pt() const override
transverse momentum
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
bool isPhoton() const override
void setP4(const LorentzVector &p4) override
set 4-momentum
double energy() const override
energy
edm::RefVector< pat::PackedGenParticleCollection > PackedGenParticleRefVector
double theta() const override
momentum polar angle
CovarianceMatrix vertexCovariance() const override
return SMatrix
double p() const override
magnitude of momentum vector
bool isMuon() const override
def move(src, dest)
Definition: eostools.py:511
math::XYZTLorentzVector LorentzVector
Lorentz vector.
double mt() const override
transverse mass
const reco::GenStatusFlags & statusFlags() const
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:38