Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:54

0001 #ifndef Candidate_LeafRefCandidateT_h
0002 #define Candidate_LeafRefCandidateT_h
0003 /** \class reco::LeafRefCandidateT
0004  *
0005  * particle candidate with no constituent nor daughters, that takes the 3-vector
0006  * from a constituent T (where T satisfies T->pt(), etc, like a TrackRef), and the mass is set
0007  *
0008  * \author Luca Lista, INFN
0009  *
0010  */
0011 
0012 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0013 #include "DataFormats/Common/interface/RefCoreWithIndex.h"
0014 
0015 namespace reco {
0016 
0017   class LeafRefCandidateT : public LeafCandidate {
0018   public:
0019     /// collection of daughter candidates
0020     typedef CandidateCollection daughters;
0021     /// electric charge type
0022     typedef int Charge;
0023     /// Lorentz vector
0024     typedef math::XYZTLorentzVector LorentzVector;
0025     /// Lorentz vector
0026     typedef math::PtEtaPhiMLorentzVector PolarLorentzVector;
0027     /// point in the space
0028     typedef math::XYZPoint Point;
0029     /// point in the space
0030     typedef math::XYZVector Vector;
0031 
0032     typedef unsigned int index;
0033 
0034     /// default constructor
0035     LeafRefCandidateT() {}
0036     // constructor from T
0037     template <class REF>
0038     LeafRefCandidateT(const REF& c, float m)
0039         : LeafCandidate(c->charge(), PolarLorentzVector(c->pt(), c->eta(), c->phi(), m), c->vertex()),
0040           ref_(c.refCore(), c.key()) {}
0041     /// destructor
0042     ~LeafRefCandidateT() override {}
0043 
0044   protected:
0045     // get the ref (better be the correct ref!)
0046     template <typename REF>
0047     REF getRef() const {
0048       return REF(ref_.toRefCore(), ref_.index());
0049     }
0050 
0051   public:
0052     /// number of daughters
0053     size_t numberOfDaughters() const final { return 0; }
0054     /// return daughter at a given position (throws an exception)
0055     const Candidate* daughter(size_type) const final { return nullptr; }
0056     /// number of mothers
0057     size_t numberOfMothers() const final { return 0; }
0058     /// return mother at a given position (throws an exception)
0059     const Candidate* mother(size_type) const final { return nullptr; }
0060     /// return daughter at a given position (throws an exception)
0061     Candidate* daughter(size_type) final { return nullptr; }
0062     /// return daughter with a specified role name
0063     Candidate* daughter(const std::string& s) final { return nullptr; }
0064     /// return daughter with a specified role name
0065     const Candidate* daughter(const std::string& s) const final { return nullptr; }
0066     /// return the number of source Candidates
0067     /// ( the candidates used to construct this Candidate)
0068     size_t numberOfSourceCandidatePtrs() const final { return 0; }
0069     /// return a Ptr to one of the source Candidates
0070     /// ( the candidates used to construct this Candidate)
0071     CandidatePtr sourceCandidatePtr(size_type i) const final {
0072       static const CandidatePtr dummyPtr;
0073       return dummyPtr;
0074     }
0075 
0076     /// This only happens if the concrete Candidate type is ShallowCloneCandidate
0077     bool hasMasterClone() const final { return false; }
0078     /// returns ptr to master clone, if existing.
0079     /// Throws an exception unless the concrete Candidate type is ShallowCloneCandidate
0080     const CandidateBaseRef& masterClone() const final {
0081       static const CandidateBaseRef dummyRef;
0082       return dummyRef;
0083     }
0084     /// returns true if this candidate has a ptr to a master clone.
0085     /// This only happens if the concrete Candidate type is ShallowClonePtrCandidate
0086     bool hasMasterClonePtr() const final { return false; }
0087     /// returns ptr to master clone, if existing.
0088     /// Throws an exception unless the concrete Candidate type is ShallowClonePtrCandidate
0089     const CandidatePtr& masterClonePtr() const final {
0090       static const CandidatePtr dummyPtr;
0091       return dummyPtr;
0092     }
0093 
0094     /// cast master clone reference to a concrete type
0095     template <typename Ref>
0096     Ref masterRef() const {
0097       Ref dummyRef;
0098       return dummyRef;
0099     }
0100     /// get a component
0101 
0102     template <typename C>
0103     C get() const {
0104       if (hasMasterClone())
0105         return masterClone()->template get<C>();
0106       else
0107         return reco::get<C>(*this);
0108     }
0109     /// get a component
0110     template <typename C, typename Tag>
0111     C get() const {
0112       if (hasMasterClone())
0113         return masterClone()->template get<C, Tag>();
0114       else
0115         return reco::get<C, Tag>(*this);
0116     }
0117     /// get a component
0118     template <typename C>
0119     C get(size_type i) const {
0120       if (hasMasterClone())
0121         return masterClone()->template get<C>(i);
0122       else
0123         return reco::get<C>(*this, i);
0124     }
0125     /// get a component
0126     template <typename C, typename Tag>
0127     C get(size_type i) const {
0128       if (hasMasterClone())
0129         return masterClone()->template get<C, Tag>(i);
0130       else
0131         return reco::get<C, Tag>(*this, i);
0132     }
0133     /// number of components
0134     template <typename C>
0135     size_type numberOf() const {
0136       if (hasMasterClone())
0137         return masterClone()->template numberOf<C>();
0138       else
0139         return reco::numberOf<C>(*this);
0140     }
0141     /// number of components
0142     template <typename C, typename Tag>
0143     size_type numberOf() const {
0144       if (hasMasterClone())
0145         return masterClone()->template numberOf<C, Tag>();
0146       else
0147         return reco::numberOf<C, Tag>(*this);
0148     }
0149 
0150     bool isElectron() const final { return false; }
0151     bool isMuon() const final { return false; }
0152     bool isStandAloneMuon() const final { return false; }
0153     bool isGlobalMuon() const final { return false; }
0154     bool isTrackerMuon() const final { return false; }
0155     bool isCaloMuon() const final { return false; }
0156     bool isPhoton() const final { return false; }
0157     bool isConvertedPhoton() const final { return false; }
0158     bool isJet() const final { return false; }
0159 
0160     CMS_CLASS_VERSION(13)
0161 
0162   protected:
0163     /// check overlap with another Candidate
0164     bool overlap(const Candidate&) const override;
0165     virtual bool overlap(const LeafRefCandidateT&) const;
0166     template <typename, typename, typename>
0167     friend struct component;
0168     friend class ::OverlapChecker;
0169     friend class ShallowCloneCandidate;
0170     friend class ShallowClonePtrCandidate;
0171 
0172   protected:
0173     edm::RefCoreWithIndex ref_;
0174 
0175   private:
0176     ///
0177     /// Hide these from all users:
0178     ///
0179     /*                                    
0180     virtual void setCharge( Charge q ) final  {}                                         
0181     virtual void setThreeCharge( Charge qx3 ) final  {}
0182     virtual void setP4( const LorentzVector & p4 ) final  {}
0183     virtual void setP4( const PolarLorentzVector & p4 ) final  {}
0184     virtual void setPz( double pz ) final  {}                            
0185     virtual void setVertex( const Point & vertex ) final  {}
0186     virtual void setPdgId( int pdgId ) final  {}                                              
0187     virtual void setStatus( int status ) final  {}
0188     virtual void setLongLived() final  {}                                      
0189     virtual void setMassConstraint() final  {}
0190 
0191     virtual double vertexChi2() const final  { return 0.; }
0192     virtual double vertexNdof() const final  { return 0.; }
0193     virtual double vertexNormalizedChi2() const final  { return 0.; }
0194     virtual double vertexCovariance(int i, int j) const final  { return 0.; }
0195     virtual void fillVertexCovariance(CovarianceMatrix & v) const final  {}
0196     */
0197   };
0198 
0199   inline bool LeafRefCandidateT::overlap(const Candidate& o) const {
0200     return p4() == o.p4() && vertex() == o.vertex() && charge() == o.charge();
0201   }
0202 
0203   inline bool LeafRefCandidateT::overlap(const LeafRefCandidateT& o) const {
0204     return (ref_.id() == o.ref_.id()) & (ref_.index() == o.ref_.index());
0205   }
0206 
0207 }  // namespace reco
0208 
0209 #endif