CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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), packedY_(0), packedPhi_(0), packedM_(0),
39  p4_(nullptr), p4c_(nullptr), vertex_(0,0,0), pdgId_(0), charge_(0) { }
41  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())), p4c_( new LorentzVector(*p4_)), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(c.motherRef(0)),
42  statusFlags_(c.statusFlags()) { pack(); }
44  : p4_(new PolarLorentzVector(c.pt(), c.eta(), c.phi(), c.mass())), p4c_(new LorentzVector(*p4_)), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(mother),
45  statusFlags_(c.statusFlags()) { pack(); }
46 
48  : packedPt_(iOther.packedPt_), packedY_(iOther.packedY_), packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
50  vertex_(iOther.vertex_), dxy_(iOther.dxy_), dz_(iOther.dz_),dphi_(iOther.dphi_),
51  pdgId_(iOther.pdgId_),charge_(iOther.charge_),mother_(iOther.mother_),
52  statusFlags_(iOther.statusFlags_) {
53  if(iOther.p4c_) {
54  p4_.store( new PolarLorentzVector(*iOther.p4_) );
55  p4c_.store( new LorentzVector(*iOther.p4c_) );
56  }
57  }
58 
60  : packedPt_(iOther.packedPt_), packedY_(iOther.packedY_), packedPhi_(iOther.packedPhi_), packedM_(iOther.packedM_),
62  vertex_(std::move(iOther.vertex_)), dxy_(iOther.dxy_), dz_(iOther.dz_),dphi_(iOther.dphi_),
63  pdgId_(iOther.pdgId_),charge_(iOther.charge_),mother_(std::move(iOther.mother_)),
64  statusFlags_(iOther.statusFlags_) {
65  if(iOther.p4c_) {
66  p4_.store( p4_.exchange(nullptr) );
67  p4c_.store( p4c_.exchange(nullptr) );
68  }
69  }
70 
72  if(this != &iOther) {
73  packedPt_ = iOther.packedPt_;
74  packedY_ = iOther.packedY_;
75  packedPhi_ = iOther.packedPhi_;
76  packedM_ = iOther.packedM_;
77  if(p4c_) {
78  delete p4_.exchange(iOther.p4_.exchange(nullptr));
79  delete p4c_.exchange(iOther.p4c_.exchange(nullptr)) ;
80  } else {
81  delete p4_.exchange(nullptr);
82  delete p4c_.exchange(nullptr);
83  }
84  vertex_=std::move(iOther.vertex_);
85  dxy_ = iOther.dxy_;
86  dz_ = iOther.dz_;
87  dphi_ = iOther.dphi_;
88  pdgId_ = iOther.pdgId_;
89  charge_ = iOther.charge_;
90  mother_ = std::move(iOther.mother_);
91  statusFlags_ = iOther.statusFlags_;
92  }
93  return *this;
94  }
95 
97  PackedGenParticle c(iOther);
98  *this = std::move(c);
99  return *this;
100  }
101 
103  virtual ~PackedGenParticle();
105  virtual size_t numberOfDaughters() const;
107  virtual const reco::Candidate * daughter( size_type ) const;
109  virtual size_t numberOfMothers() const;
111  virtual const reco::Candidate * mother( size_type ) const;
113  const reco::GenParticleRef & motherRef() const { return mother_; }
114 
116  virtual reco::Candidate * daughter( size_type );
118  virtual reco::Candidate * daughter(const std::string& s );
120  virtual const reco::Candidate * daughter(const std::string& s ) const;
123  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
127  return reco::CandidatePtr();
128  }
129 
131  virtual int charge() const {
132  return charge_;
133  }
135  virtual void setCharge( int charge) {charge_=charge;}
137  virtual int threeCharge() const {return charge()*3;}
139  virtual void setThreeCharge( int threecharge) {}
141  virtual const LorentzVector & p4() const { if (!p4c_) unpack(); return *p4c_; }
143  virtual const PolarLorentzVector & polarP4() const { if (!p4c_) unpack(); return *p4_; }
145  virtual Vector momentum() const { if (!p4c_) unpack(); return p4c_.load()->Vect(); }
148  virtual Vector boostToCM() const { if (!p4c_) unpack(); return p4c_.load()->BoostToCM(); }
150  virtual double p() const { if (!p4c_) unpack(); return p4c_.load()->P(); }
152  virtual double energy() const { if (!p4c_) unpack(); return p4c_.load()->E(); }
154  double et() const { return (pt()<=0) ? 0 : p4c_.load()->Et(); }
156  double et2() const { return (pt()<=0) ? 0 : p4c_.load()->Et2(); }
158  virtual double mass() const { if (!p4c_) unpack(); return p4_.load()->M(); }
160  virtual double massSqr() const { if (!p4c_) unpack(); return p4_.load()->M()*p4_.load()->M(); }
161 
163  virtual double mt() const { if (!p4c_) unpack(); return p4_.load()->Mt(); }
165  virtual double mtSqr() const { if (!p4c_) unpack(); return p4_.load()->Mt2(); }
167  virtual double px() const { if (!p4c_) unpack(); return p4c_.load()->Px(); }
169  virtual double py() const { if (!p4c_) unpack(); return p4c_.load()->Py(); }
171  virtual double pz() const { if (!p4c_) unpack(); return p4c_.load()->Pz(); }
173  virtual double pt() const { if (!p4c_) unpack(); return p4_.load()->Pt();}
175  virtual double phi() const { if (!p4c_) unpack(); return p4_.load()->Phi(); }
177  virtual double theta() const { if (!p4c_) unpack(); return p4_.load()->Theta(); }
179  virtual double eta() const { if (!p4c_) unpack(); return p4_.load()->Eta(); }
181  virtual double rapidity() const { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
183  virtual double y() const { if (!p4c_) unpack(); return p4_.load()->Rapidity(); }
185  virtual void setP4( const LorentzVector & p4 ) {
186  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
187  *p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
188  pack();
189  }
191  virtual void setP4( const PolarLorentzVector & p4 ) {
192  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
193  *p4_ = p4;
194  pack();
195  }
197  virtual void setMass( double m ) {
198  if (!p4c_) unpack();
199  *p4_ = PolarLorentzVector(p4_.load()->Pt(), p4_.load()->Eta(), p4_.load()->Phi(), m);
200  pack();
201  }
202  virtual void setPz( double pz ) {
203  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
204  *p4c_ = LorentzVector(p4c_.load()->Px(), p4c_.load()->Py(), pz, p4c_.load()->E());
205  *p4_ = PolarLorentzVector(p4c_.load()->Pt(), p4c_.load()->Eta(), p4c_.load()->Phi(), p4c_.load()->M());
206  pack();
207  }
209  virtual const Point & vertex() const { return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
211  virtual double vx() const { return vertex_.X(); }//{ return 0; }
213  virtual double vy() const { return vertex_.Y(); }//{ return 0; }
215  virtual double vz() const { return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
217  virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
218 
219  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
220 
221 
223  virtual float dxy() const { unpack(); return dxy_; }
225  virtual float dz() const { unpack(); return dz_; }
227  virtual float dxy(const Point &p) const ;
229  virtual float dz(const Point &p) const ;
230 
231 
233  virtual int pdgId() const { return pdgId_; }
234  // set PDG identifier
235  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
237  virtual int status() const { return 1; } /*FIXME*/
239  virtual void setStatus( int status ) {} /*FIXME*/
241  static const unsigned int longLivedTag = 0; /*FIXME*/
243  virtual void setLongLived() {} /*FIXME*/
245  virtual bool longLived() const;
247  static const unsigned int massConstraintTag = 0; /*FIXME*/
249  virtual void setMassConstraint() {} /*FIXME*/
251  virtual bool massConstraint() const;
252 
254  virtual PackedGenParticle * clone() const {
255  return new PackedGenParticle( *this );
256  }
257 
259  virtual double vertexChi2() const;
266  virtual double vertexNdof() const;
268  virtual double vertexNormalizedChi2() const;
270  virtual double vertexCovariance(int i, int j) const;
274  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
277  virtual bool hasMasterClone() const;
280  virtual const reco::CandidateBaseRef & masterClone() const;
283  virtual bool hasMasterClonePtr() const;
286 
287  virtual const reco::CandidatePtr & masterClonePtr() const;
288 
290  template<typename Ref>
291  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
293 
294  virtual bool isElectron() const;
295  virtual bool isMuon() const;
296  virtual bool isStandAloneMuon() const;
297  virtual bool isGlobalMuon() const;
298  virtual bool isTrackerMuon() const;
299  virtual bool isCaloMuon() const;
300  virtual bool isPhoton() const;
301  virtual bool isConvertedPhoton() const;
302  virtual bool isJet() const;
303 
304  const reco::GenStatusFlags &statusFlags() const { return statusFlags_; }
306 
308  //basic set of gen status flags accessible directly here
309  //the rest accessible through statusFlags()
310  //(see GenStatusFlags.h for their meaning)
311 
313  //these are robust, generator-independent functions for categorizing
314  //mainly final state particles, but also intermediate hadrons/taus
315 
316  //is particle prompt (not from hadron, muon, or tau decay) and final state
317  bool isPromptFinalState() const { return status()==1 && statusFlags_.isPrompt(); }
318 
319  //this particle is a direct decay product of a prompt tau and is final state
320  //(eg an electron or muon from a leptonic decay of a prompt tau)
322 
324  //these are generator history-dependent functions for tagging particles
325  //associated with the hard process
326  //Currently implemented for Pythia 6 and Pythia 8 status codes and history
327  //and may not have 100% consistent meaning across all types of processes
328  //Users are strongly encouraged to stick to the more robust flags above,
329  //as well as the expanded set available in GenStatusFlags.h
330 
331  //this particle is the final state direct descendant of a hard process particle
333 
334  //this particle is a direct decay product of a hardprocess tau and is final state
335  //(eg an electron or muon from a leptonic decay of a tau from the hard process)
337 
338 
339  protected:
341  void pack(bool unpackAfterwards=true) ;
342  void unpack() const ;
343 
345  mutable std::atomic<PolarLorentzVector*> p4_;
346  mutable std::atomic<LorentzVector*> p4c_;
349  float dxy_, dz_, dphi_;
351  int pdgId_;
353  int8_t charge_;
356  //status flags
358 
360  virtual bool overlap( const reco::Candidate & ) const;
361  template<typename, typename, typename> friend struct component;
362  friend class ::OverlapChecker;
363  friend class ShallowCloneCandidate;
365 
366  };
367 
368  typedef std::vector<pat::PackedGenParticle> PackedGenParticleCollection;
371 }
372 
373 #endif
virtual PackedGenParticle * clone() const
returns a clone of the Candidate object
virtual double vx() const
x coordinate of vertex position
virtual void setStatus(int status)
set status word
int i
Definition: DBlmapReader.cc:9
virtual double pz() const
z coordinate of momentum vector
bool isPrompt() const
Point vertex_
vertex position
virtual Vector boostToCM() const
reco::GenStatusFlags & statusFlags()
edm::Ref< pat::PackedGenParticleCollection > PackedGenParticleRef
virtual void fillVertexCovariance(CovarianceMatrix &v) const
fill SMatrix
static const unsigned int longLivedTag
long lived flag
CovarianceMatrix vertexCovariance() const
return SMatrix
virtual size_t numberOfMothers() const
number of mothers
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
friend class ShallowCloneCandidate
size_t size_type
Definition: Candidate.h:30
virtual void setVertex(const Point &vertex)
set vertex
virtual double vertexNdof() const
virtual int threeCharge() const
electric charge
int pdgId_
PDG identifier.
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
bool isDirectPromptTauDecayProduct() const
virtual void setP4(const LorentzVector &p4)
set 4-momentum
bool fromHardProcessFinalState() const
virtual double vy() const
y coordinate of vertex position
virtual int status() const
status word
virtual bool isTrackerMuon() const
virtual reco::CandidatePtr sourceCandidatePtr(size_type i) const
bool isDirectHardProcessTauDecayProduct() const
virtual bool isJet() const
virtual ~PackedGenParticle()
destructor
PackedGenParticle(const PackedGenParticle &iOther)
virtual double pt() const
transverse momentum
virtual const reco::Candidate * daughter(size_type) const
return daughter at a given position (throws an exception)
friend class ShallowClonePtrCandidate
virtual double mtSqr() const
transverse mass squared
virtual size_t numberOfSourceCandidatePtrs() const
PackedGenParticle()
default constructor
#define nullptr
virtual bool isElectron() const
get a component
virtual double theta() const
momentum polar angle
virtual bool isPhoton() const
PackedGenParticle & operator=(PackedGenParticle const &iOther)
std::atomic< LorentzVector * > p4c_
void pack(bool unpackAfterwards=true)
virtual double phi() const
momentum azimuthal angle
bool fromHardProcess() const
virtual Vector momentum() const
spatial momentum vector
math::XYZPoint Point
point in the space
virtual double vertexNormalizedChi2() const
chi-squared divided by n.d.o.f.
virtual double p() const
magnitude of momentum vector
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setLongLived()
set long lived flag
PackedGenParticle(const reco::GenParticle &c)
virtual void setThreeCharge(int threecharge)
set electric charge
virtual double massSqr() const
mass squared
bool isDirectPromptTauDecayProductFinalState() const
virtual void setPz(double pz)
reco::GenParticleRef mother_
Ref to first mother.
virtual void setMassConstraint()
set mass constraint flag
virtual double eta() const
momentum pseudorapidity
bool isDirectHardProcessTauDecayProductFinalState() const
virtual bool isMuon() const
virtual const Point & vertex() const
vertex position
virtual bool longLived() const
is long lived?
math::XYZVector Vector
point in the space
virtual const reco::CandidateBaseRef & masterClone() const
virtual double vertexChi2() const
chi-squares
virtual size_t numberOfDaughters() const
number of daughters
def move
Definition: eostools.py:510
math::XYZPoint Point
virtual const LorentzVector & p4() const
four-momentum Lorentz vecto r
virtual bool isStandAloneMuon() const
int j
Definition: DBlmapReader.cc:9
bool isPromptFinalState() const
virtual const reco::CandidatePtr & masterClonePtr() const
PackedGenParticle & operator=(PackedGenParticle &&iOther)
virtual double mt() const
transverse mass
virtual bool hasMasterClonePtr() const
const reco::GenParticleRef & motherRef() const
direct access to the mother reference (may be null)
PackedGenParticle(const reco::GenParticle &c, const edm::Ref< reco::GenParticleCollection > &mother)
virtual void setPdgId(int pdgId)
virtual double y() const
rapidity
static const unsigned int massConstraintTag
do mass constraint flag
virtual int pdgId() const
PDG identifier.
reco::CandidateCollection daughters
collection of daughter candidates
virtual bool overlap(const reco::Candidate &) const
check overlap with another Candidate
virtual const PolarLorentzVector & polarP4() const
four-momentum Lorentz vector
std::atomic< PolarLorentzVector * > p4_
the four vector
virtual bool hasMasterClone() const
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
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
PackedGenParticle(PackedGenParticle &&iOther)
std::vector< pat::PackedGenParticle > PackedGenParticleCollection
const reco::GenStatusFlags & statusFlags() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
virtual double energy() const
energy
virtual bool isCaloMuon() const
virtual bool isGlobalMuon() const
virtual const reco::Candidate * mother(size_type) const
return mother at a given position (throws an exception)
virtual double rapidity() const
rapidity
virtual double mass() const
mass
virtual int charge() const
electric charge
virtual bool isConvertedPhoton() const
reco::GenStatusFlags statusFlags_
math::XYZPoint Point
point in the space
Definition: Candidate.h:41
virtual bool massConstraint() const
do mass constraint?
double et2() const
transverse energy squared (use this for cuts)!
virtual void setCharge(int charge)
set electric charge
virtual double py() const
y coordinate of momentum vector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
double et() const
transverse energy
virtual void setMass(double m)
set particle mass
virtual double px() const
x coordinate of momentum vector
Ref masterRef() const
cast master clone reference to a concrete type
edm::RefVector< pat::PackedGenParticleCollection > PackedGenParticleRefVector
virtual float dz() const
dz with respect to the PV ref
virtual float dxy() const
dxy with respect to the PV ref
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual double vz() const
z coordinate of vertex position
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39