Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:50

0001 #ifndef Candidate_Candidate_h
0002 #define Candidate_Candidate_h
0003 /** \class reco::Candidate
0004  *
0005  * abstract interface for physics objects
0006  *
0007  * \author Luca Lista (INFN), Benedikt Hegner (CERN)
0008  *
0009  *
0010  */
0011 #include "DataFormats/Candidate/interface/component.h"
0012 #include "DataFormats/Candidate/interface/const_iterator.h"
0013 #include "DataFormats/Math/interface/Error.h"
0014 
0015 #include "DataFormats/Math/interface/Point3D.h"
0016 #include "DataFormats/Math/interface/Vector3D.h"
0017 #include "DataFormats/Math/interface/LorentzVector.h"
0018 
0019 #include "DataFormats/Candidate/interface/Particle.h"
0020 
0021 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0022 
0023 class OverlapChecker;
0024 
0025 namespace reco {
0026   class Track;
0027   class Candidate {
0028   public:
0029     typedef size_t size_type;
0030     typedef candidate::const_iterator const_iterator;
0031     typedef candidate::iterator iterator;
0032 
0033     /// electric charge type
0034     typedef int Charge;
0035     /// Lorentz vector
0036     typedef math::XYZTLorentzVector LorentzVector;
0037     /// Lorentz vector
0038     typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
0039     /// point in the space
0040     typedef math::XYZPoint Point;
0041     /// point in the space
0042     typedef math::XYZVector Vector;
0043 
0044     enum { dimension = 3 };
0045     /// covariance error matrix (3x3)
0046     typedef math::Error<dimension>::type CovarianceMatrix;
0047     /// matix size
0048     enum { size = dimension * (dimension + 1) / 2 };
0049     /// index type
0050     typedef unsigned int index;
0051 
0052     /// default constructor
0053     Candidate() {}
0054     /// destructor
0055     virtual ~Candidate();
0056     /// electric charge
0057     virtual int charge() const = 0;
0058     /// set electric charge
0059     virtual void setCharge(Charge q) = 0;
0060     /// electric charge
0061     virtual int threeCharge() const = 0;
0062     /// set electric charge
0063     virtual void setThreeCharge(Charge qx3) = 0;
0064     /// four-momentum Lorentz vector
0065     virtual const LorentzVector& p4() const = 0;
0066     /// four-momentum Lorentz vector
0067     virtual const PolarLorentzVector& polarP4() const = 0;
0068     /// spatial momentum vector
0069     virtual Vector momentum() const = 0;
0070     /// boost vector to boost a Lorentz vector
0071     /// to the particle center of mass system
0072     virtual Vector boostToCM() const = 0;
0073     /// magnitude of momentum vector
0074     virtual double p() const = 0;
0075     /// energy
0076     virtual double energy() const = 0;
0077     /// transverse energy
0078     virtual double et() const = 0;
0079     /// transverse energy squared (use this for cut!)
0080     virtual double et2() const = 0;
0081     /// mass
0082     virtual double mass() const = 0;
0083     /// mass squared
0084     virtual double massSqr() const = 0;
0085     /// transverse mass
0086     virtual double mt() const = 0;
0087     /// transverse mass squared
0088     virtual double mtSqr() const = 0;
0089     /// x coordinate of momentum vector
0090     virtual double px() const = 0;
0091     /// y coordinate of momentum vector
0092     virtual double py() const = 0;
0093     /// z coordinate of momentum vector
0094     virtual double pz() const = 0;
0095     /// transverse momentum
0096     virtual double pt() const = 0;
0097     /// momentum azimuthal angle
0098     virtual double phi() const = 0;
0099     /// momentum polar angle
0100     virtual double theta() const = 0;
0101     /// momentum pseudorapidity
0102     virtual double eta() const = 0;
0103     /// rapidity
0104     virtual double rapidity() const = 0;
0105     /// rapidity
0106     virtual double y() const = 0;
0107     /// set 4-momentum
0108     virtual void setP4(const LorentzVector& p4) = 0;
0109     /// set 4-momentum
0110     virtual void setP4(const PolarLorentzVector& p4) = 0;
0111     /// set particle mass
0112     virtual void setMass(double m) = 0;
0113     virtual void setPz(double pz) = 0;
0114     /// vertex position
0115     virtual const Point& vertex() const = 0;
0116     /// x coordinate of vertex position
0117     virtual double vx() const = 0;
0118     /// y coordinate of vertex position
0119     virtual double vy() const = 0;
0120     /// z coordinate of vertex position
0121     virtual double vz() const = 0;
0122     /// set vertex
0123     virtual void setVertex(const Point& vertex) = 0;
0124     /// PDG identifier
0125     virtual int pdgId() const = 0;
0126     // set PDG identifier
0127     virtual void setPdgId(int pdgId) = 0;
0128     /// status word
0129     virtual int status() const = 0;
0130     /// set status word
0131     virtual void setStatus(int status) = 0;
0132     /// set long lived flag
0133     virtual void setLongLived() = 0;
0134     /// is long lived?
0135     virtual bool longLived() const = 0;
0136     /// set mass constraint flag
0137     virtual void setMassConstraint() = 0;
0138     /// do mass constraint?
0139     virtual bool massConstraint() const = 0;
0140     /// returns a clone of the Candidate object
0141     virtual Candidate* clone() const = 0;
0142     /// first daughter const_iterator
0143     const_iterator begin() const { return const_iterator(this, 0); }
0144     /// last daughter const_iterator
0145     const_iterator end() const { return const_iterator(this, numberOfDaughters()); }
0146     /// first daughter iterator
0147     iterator begin() { return iterator(this, 0); }
0148     /// last daughter iterator
0149     iterator end() { return iterator(this, numberOfDaughters()); }
0150     /// number of daughters
0151     virtual size_type numberOfDaughters() const = 0;
0152     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
0153     virtual const Candidate* daughter(size_type i) const = 0;
0154     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1
0155     virtual Candidate* daughter(size_type i) = 0;
0156     /// return daughter with a specified role name
0157     virtual Candidate* daughter(const std::string& s) = 0;
0158     /// return daughter with a specified role name
0159     virtual const Candidate* daughter(const std::string& s) const = 0;
0160     /// number of mothers (zero or one in most of but not all the cases)
0161     virtual size_type numberOfMothers() const = 0;
0162     /// return pointer to mother
0163     virtual const Candidate* mother(size_type i = 0) const = 0;
0164     /// return the number of source Candidates
0165     /// ( the candidates used to construct this Candidate)
0166     virtual size_t numberOfSourceCandidatePtrs() const = 0;
0167     /// return a Ptr to one of the source Candidates
0168     /// ( the candidates used to construct this Candidate)
0169     virtual CandidatePtr sourceCandidatePtr(size_type i) const { return CandidatePtr(); }
0170     /// \brief Set the ptr to the source Candidate.
0171     ///
0172     /// necessary, to allow a parallel treatment of all candidates
0173     /// in PF2PAT. Does nothing for most Candidate classes, including
0174     /// CompositePtrCandidates, where the source information is in fact
0175     /// the collection of ptrs to daughters. For non-Composite Candidates,
0176     /// this function can be used to set the ptr to the source of the
0177     /// Candidate, which will allow to keep track
0178     /// of the reconstruction history.
0179     virtual void setSourceCandidatePtr(const CandidatePtr& ptr) {}
0180 
0181     /// chi-squares
0182     virtual double vertexChi2() const = 0;
0183     /** Number of degrees of freedom
0184      *  Meant to be Double32_t for soft-assignment fitters: 
0185      *  tracks may contribute to the vertex with fractional weights.
0186      *  The ndof is then = to the sum of the track weights.
0187      *  see e.g. CMS NOTE-2006/032, CMS NOTE-2004/002
0188      */
0189     virtual double vertexNdof() const = 0;
0190     /// chi-squared divided by n.d.o.f.
0191     virtual double vertexNormalizedChi2() const = 0;
0192     /// (i, j)-th element of error matrix, i, j = 0, ... 2
0193     virtual double vertexCovariance(int i, int j) const = 0;
0194     /// fill SMatrix
0195     virtual CovarianceMatrix vertexCovariance() const {
0196       CovarianceMatrix m;
0197       fillVertexCovariance(m);
0198       return m;
0199     }  //TODO
0200     virtual void fillVertexCovariance(CovarianceMatrix& v) const = 0;
0201     /// returns true if this candidate has a reference to a master clone.
0202     /// This only happens if the concrete Candidate type is ShallowCloneCandidate
0203     virtual bool hasMasterClone() const = 0;
0204     /// returns ptr to master clone, if existing.
0205     /// Throws an exception unless the concrete Candidate type is ShallowCloneCandidate
0206     virtual const CandidateBaseRef& masterClone() const = 0;
0207     /// returns true if this candidate has a ptr to a master clone.
0208     /// This only happens if the concrete Candidate type is ShallowClonePtrCandidate
0209     virtual bool hasMasterClonePtr() const = 0;
0210     /// returns ptr to master clone, if existing.
0211     /// Throws an exception unless the concrete Candidate type is ShallowClonePtrCandidate
0212     virtual const CandidatePtr& masterClonePtr() const = 0;
0213     /// cast master clone reference to a concrete type
0214     template <typename Ref>
0215     Ref masterRef() const {
0216       return masterClone().template castTo<Ref>();
0217     }
0218     /// get a component
0219 
0220     template <typename T>
0221     T get() const {
0222       if (hasMasterClone())
0223         return masterClone()->get<T>();
0224       else
0225         return reco::get<T>(*this);
0226     }
0227     /// get a component
0228     template <typename T, typename Tag>
0229     T get() const {
0230       if (hasMasterClone())
0231         return masterClone()->get<T, Tag>();
0232       else
0233         return reco::get<T, Tag>(*this);
0234     }
0235     /// get a component
0236     template <typename T>
0237     T get(size_type i) const {
0238       if (hasMasterClone())
0239         return masterClone()->get<T>(i);
0240       else
0241         return reco::get<T>(*this, i);
0242     }
0243     /// get a component
0244     template <typename T, typename Tag>
0245     T get(size_type i) const {
0246       if (hasMasterClone())
0247         return masterClone()->get<T, Tag>(i);
0248       else
0249         return reco::get<T, Tag>(*this, i);
0250     }
0251     /// number of components
0252     template <typename T>
0253     size_type numberOf() const {
0254       if (hasMasterClone())
0255         return masterClone()->numberOf<T>();
0256       else
0257         return reco::numberOf<T>(*this);
0258     }
0259     /// number of components
0260     template <typename T, typename Tag>
0261     size_type numberOf() const {
0262       if (hasMasterClone())
0263         return masterClone()->numberOf<T, Tag>();
0264       else
0265         return reco::numberOf<T, Tag>(*this);
0266     }
0267 
0268     virtual const Track* bestTrack() const { return nullptr; }
0269 
0270     /// uncertainty on dz
0271     virtual float dzError() const {
0272       return 0;
0273     }  // { const Track * tr=bestTrack(); if(tr!=nullptr) return tr->dzError(); else return 0; }
0274     /// uncertainty on dxy
0275     virtual float dxyError() const {
0276       return 0;
0277     }  // { const Track * tr=bestTrack(); if(tr!=nullptr) return tr->dxyError(); else return 0; }
0278 
0279     virtual bool isElectron() const = 0;
0280     virtual bool isMuon() const = 0;
0281     virtual bool isStandAloneMuon() const = 0;
0282     virtual bool isGlobalMuon() const = 0;
0283     virtual bool isTrackerMuon() const = 0;
0284     virtual bool isCaloMuon() const = 0;
0285     virtual bool isPhoton() const = 0;
0286     virtual bool isConvertedPhoton() const = 0;
0287     virtual bool isJet() const = 0;
0288 
0289   protected:
0290     /// check overlap with another Candidate
0291     virtual bool overlap(const Candidate&) const = 0;
0292     template <typename, typename, typename>
0293     friend struct component;
0294     friend class ::OverlapChecker;
0295     friend class ShallowCloneCandidate;
0296     friend class ShallowClonePtrCandidate;
0297   };
0298 
0299   namespace candidate {
0300 
0301     const_iterator::reference const_iterator::operator*() const { return *(me->daughter(i)); }
0302     iterator::reference iterator::operator*() const { return *(me->daughter(i)); }
0303 
0304   }  // namespace candidate
0305 
0306 }  // namespace reco
0307 
0308 #endif