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 namespace pat {
18  public:
29 
30  typedef unsigned int index;
31 
34  : p4_(0,0,0,0), p4c_(0,0,0,0), vertex_(0,0,0), pdgId_(0), charge_(0), unpacked_(false) { }
36  : p4_(c.pt(), c.eta(), c.phi(), c.mass()), p4c_(p4_), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(c.motherRef(0)), unpacked_(true) { pack(); }
38  : p4_(c.pt(), c.eta(), c.phi(), c.mass()), p4c_(p4_), vertex_(0,0,0), pdgId_(c.pdgId()), charge_(c.charge()), mother_(mother), unpacked_(true) { pack(); }
39 
40 
42  virtual ~PackedGenParticle();
44  virtual const_iterator begin() const;
46  virtual const_iterator end() const;
48  virtual iterator begin();
50  virtual iterator end();
52  virtual size_t numberOfDaughters() const;
54  virtual const reco::Candidate * daughter( size_type ) const;
56  virtual size_t numberOfMothers() const;
58  virtual const reco::Candidate * mother( size_type ) const;
60  const reco::GenParticleRef & motherRef() const { return mother_; }
61 
63  virtual reco::Candidate * daughter( size_type );
65  virtual reco::Candidate * daughter(const std::string& s );
67  virtual const reco::Candidate * daughter(const std::string& s ) const;
70  virtual size_t numberOfSourceCandidatePtrs() const {return 0;}
74  return reco::CandidatePtr();
75  }
76 
78  virtual int charge() const {
79  return charge_;
80  }
82  virtual void setCharge( int charge) {charge_=charge;}
84  virtual int threeCharge() const {return charge()*3;}
86  virtual void setThreeCharge( int threecharge) {}
88  virtual const LorentzVector & p4() const { if (!unpacked_) unpack(); return p4c_; }
90  virtual const PolarLorentzVector & polarP4() const { if (!unpacked_) unpack(); return p4_; }
92  virtual Vector momentum() const { if (!unpacked_) unpack(); return p4c_.Vect(); }
95  virtual Vector boostToCM() const { if (!unpacked_) unpack(); return p4c_.BoostToCM(); }
97  virtual double p() const { if (!unpacked_) unpack(); return p4c_.P(); }
99  virtual double energy() const { if (!unpacked_) unpack(); return p4c_.E(); }
101  virtual double et() const { if (!unpacked_) unpack(); return p4_.Et(); }
103  virtual float mass() const { if (!unpacked_) unpack(); return p4_.M(); }
105  virtual float massSqr() const { if (!unpacked_) unpack(); return p4_.M()*p4_.M(); }
106 
108  virtual double mt() const { if (!unpacked_) unpack(); return p4_.Mt(); }
110  virtual double mtSqr() const { if (!unpacked_) unpack(); return p4_.Mt2(); }
112  virtual double px() const { if (!unpacked_) unpack(); return p4c_.Px(); }
114  virtual double py() const { if (!unpacked_) unpack(); return p4c_.Py(); }
116  virtual double pz() const { if (!unpacked_) unpack(); return p4c_.Pz(); }
118  virtual float pt() const { if (!unpacked_) unpack(); return p4_.Pt();}
120  virtual float phi() const { if (!unpacked_) unpack(); return p4_.Phi(); }
122  virtual double theta() const { if (!unpacked_) unpack(); return p4_.Theta(); }
124  virtual float eta() const { if (!unpacked_) unpack(); return p4_.Eta(); }
126  virtual double rapidity() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
128  virtual double y() const { if (!unpacked_) unpack(); return p4_.Rapidity(); }
130  virtual void setP4( const LorentzVector & p4 ) {
131  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
132  p4_ = PolarLorentzVector(p4.Pt(), p4.Eta(), p4.Phi(), p4.M());
133  pack();
134  }
136  virtual void setP4( const PolarLorentzVector & p4 ) {
137  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
138  p4_ = p4;
139  pack();
140  }
142  virtual void setMass( double m ) {
143  if (!unpacked_) unpack();
144  p4_ = PolarLorentzVector(p4_.Pt(), p4_.Eta(), p4_.Phi(), m);
145  pack();
146  }
147  virtual void setPz( double pz ) {
148  unpack(); // changing px,py,pz changes also mapping between dxy,dz and x,y,z
149  p4c_ = LorentzVector(p4c_.Px(), p4c_.Py(), pz, p4c_.E());
150  p4_ = PolarLorentzVector(p4c_.Pt(), p4c_.Eta(), p4c_.Phi(), p4c_.M());
151  pack();
152  }
154  virtual const Point & vertex() const { return vertex_; }//{ if (fromPV_) return Point(0,0,0); else return Point(0,0,100); }
156  virtual double vx() const { return vertex_.X(); }//{ return 0; }
158  virtual double vy() const { return vertex_.Y(); }//{ return 0; }
160  virtual double vz() const { return vertex_.Z(); }//{ if (fromPV_) return 0; else return 100; }
162  virtual void setVertex( const Point & vertex ) { vertex_ = vertex; }
163 
164  enum PVAssoc { NoPV=0, PVLoose=1, PVTight=2, PVUsedInFit=3 } ;
165 
166 
168  virtual float dxy() const { unpack(); return dxy_; }
170  virtual float dz() const { unpack(); return dz_; }
172  virtual float dxy(const Point &p) const ;
174  virtual float dz(const Point &p) const ;
175 
176 
178  virtual int pdgId() const { return pdgId_; }
179  // set PDG identifier
180  virtual void setPdgId( int pdgId ) { pdgId_ = pdgId; }
182  virtual int status() const { return 1; } /*FIXME*/
184  virtual void setStatus( int status ) {} /*FIXME*/
186  static const unsigned int longLivedTag = 0; /*FIXME*/
188  virtual void setLongLived() {} /*FIXME*/
190  virtual bool longLived() const;
192  static const unsigned int massConstraintTag = 0; /*FIXME*/
194  virtual void setMassConstraint() {} /*FIXME*/
196  virtual bool massConstraint() const;
197 
199  virtual PackedGenParticle * clone() const {
200  return new PackedGenParticle( *this );
201  }
202 
204  virtual double vertexChi2() const;
211  virtual double vertexNdof() const;
213  virtual double vertexNormalizedChi2() const;
215  virtual double vertexCovariance(int i, int j) const;
219  virtual void fillVertexCovariance(CovarianceMatrix & v) const;
222  virtual bool hasMasterClone() const;
225  virtual const reco::CandidateBaseRef & masterClone() const;
228  virtual bool hasMasterClonePtr() const;
231 
232  virtual const reco::CandidatePtr & masterClonePtr() const;
233 
235  template<typename Ref>
236  Ref masterRef() const { return masterClone().template castTo<Ref>(); }
238 
239  /* template<typename T> T get() const { */
240  /* if ( hasMasterClone() ) return masterClone()->get<T>(); */
241  /* else return reco::get<T>( * this ); */
242  /* } */
243  /* /// get a component */
244  /* template<typename T, typename Tag> T get() const { */
245  /* if ( hasMasterClone() ) return masterClone()->get<T, Tag>(); */
246  /* else return reco::get<T, Tag>( * this ); */
247  /* } */
248  /* /// get a component */
249  /* template<typename T> T get( size_type i ) const { */
250  /* if ( hasMasterClone() ) return masterClone()->get<T>( i ); */
251  /* else return reco::get<T>( * this, i ); */
252  /* } */
253  /* /// get a component */
254  /* template<typename T, typename Tag> T get( size_type i ) const { */
255  /* if ( hasMasterClone() ) return masterClone()->get<T, Tag>( i ); */
256  /* else return reco::get<T, Tag>( * this, i ); */
257  /* } */
258  /* /// number of components */
259  /* template<typename T> size_type numberOf() const { */
260  /* if ( hasMasterClone() ) return masterClone()->numberOf<T>(); */
261  /* else return reco::numberOf<T>( * this ); */
262  /* } */
263  /* /// number of components */
264  /* template<typename T, typename Tag> size_type numberOf() const { */
265  /* if ( hasMasterClone() ) return masterClone()->numberOf<T, Tag>(); */
266  /* else return reco::numberOf<T, Tag>( * this ); */
267  /* } */
268 
269  /* template<typename S> */
270  /* struct daughter_iterator { */
271  /* typedef boost::filter_iterator<S, const_iterator> type; */
272  /* }; */
273 
274  /* template<typename S> */
275  /* typename daughter_iterator<S>::type beginFilter( const S & s ) const { */
276  /* return boost::make_filter_iterator(s, begin(), end()); */
277  /* } */
278  /* template<typename S> */
279  /* typename daughter_iterator<S>::type endFilter( const S & s ) const { */
280  /* return boost::make_filter_iterator(s, end(), end()); */
281  /* } */
282 
283 
284  virtual bool isElectron() const;
285  virtual bool isMuon() const;
286  virtual bool isStandAloneMuon() const;
287  virtual bool isGlobalMuon() const;
288  virtual bool isTrackerMuon() const;
289  virtual bool isCaloMuon() const;
290  virtual bool isPhoton() const;
291  virtual bool isConvertedPhoton() const;
292  virtual bool isJet() const;
293 
294  protected:
296  void pack(bool unpackAfterwards=true) ;
297  void unpack() const ;
298 
303  mutable Point vertex_;
304  mutable float dxy_, dz_, dphi_;
306  int pdgId_;
308  int8_t charge_;
311  // is the momentum p4 unpacked
312  mutable bool unpacked_;
313 
315  virtual bool overlap( const reco::Candidate & ) const;
316  template<typename, typename, typename> friend struct component;
317  friend class ::OverlapChecker;
318  friend class ShallowCloneCandidate;
320 
321  private:
322  // const iterator implementation
324  // iterator implementation
326  };
327 
328  typedef std::vector<pat::PackedGenParticle> PackedGenParticleCollection;
331 }
332 
333 #endif
virtual PackedGenParticle * clone() const
returns a clone of the Candidate object
virtual double vx() const
x coordinate of vertex position
reco::candidate::iterator_imp_specific< daughters > iterator_imp_specific
virtual void setStatus(int status)
set status word
int i
Definition: DBlmapReader.cc:9
virtual double pz() const
z coordinate of momentum vector
Point vertex_
vertex position
virtual Vector boostToCM() const
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:47
friend class ShallowCloneCandidate
size_t size_type
Definition: Candidate.h:34
virtual void setVertex(const Point &vertex)
set vertex
virtual double et() const
transverse energy
candidate::const_iterator const_iterator
Definition: Candidate.h:35
virtual double vertexNdof() const
virtual int threeCharge() const
electric charge
int pdgId_
PDG identifier.
virtual void setP4(const PolarLorentzVector &p4)
set 4-momentum
virtual void setP4(const LorentzVector &p4)
set 4-momentum
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
virtual bool isJet() const
virtual ~PackedGenParticle()
destructor
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
virtual bool isElectron() const
get a component
virtual double theta() const
momentum polar angle
virtual bool isPhoton() const
PolarLorentzVector p4_
the four vector
void pack(bool unpackAfterwards=true)
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 void setPz(double pz)
reco::GenParticleRef mother_
Ref to first mother.
virtual void setMassConstraint()
set mass constraint flag
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 float mass() const
mass
virtual size_t numberOfDaughters() const
number of daughters
math::XYZPoint Point
virtual const LorentzVector & p4() const
four-momentum Lorentz vecto r
virtual bool isStandAloneMuon() const
int j
Definition: DBlmapReader.cc:9
virtual const reco::CandidatePtr & masterClonePtr() const
virtual const_iterator end() const
last daughter const_iterator
virtual float massSqr() const
mass squared
virtual double mt() const
transverse mass
virtual bool hasMasterClonePtr() const
const reco::GenParticleRef & motherRef() const
direct access to the mother reference (may be null)
virtual float eta() const
momentum pseudorapidity
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
candidate::iterator iterator
Definition: Candidate.h:36
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
std::vector< pat::PackedGenParticle > PackedGenParticleCollection
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
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 int charge() const
electric charge
virtual bool isConvertedPhoton() const
virtual float pt() const
transverse momentum
virtual const_iterator begin() const
first daughter const_iterator
math::XYZPoint Point
point in the space
Definition: Candidate.h:45
virtual bool massConstraint() const
do mass constraint?
virtual void setCharge(int charge)
set electric charge
virtual double py() const
y coordinate of momentum vector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
volatile std::atomic< bool > shutdown_flag false
virtual void setMass(double m)
set particle mass
reco::candidate::const_iterator_imp_specific< daughters > const_iterator_imp_specific
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 phi() const
momentum azimuthal angle
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:43