Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef Candidate_CandidateWithRef_h
0002 #define Candidate_CandidateWithRef_h
0003 /** \class reco::CandidateWithRef
0004  *
0005  * Reco Candidates with a generic reference as component
0006  *
0007  * \author Luca Lista, INFN
0008  *
0009  *
0010  */
0011 #include "DataFormats/Candidate/interface/Candidate.h"
0012 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0013 #include "DataFormats/Common/interface/RefToBase.h"
0014 
0015 namespace reco {
0016 
0017   template <typename Ref>
0018   class CandidateWithRef : public LeafCandidate {
0019   public:
0020     typedef Ref reference;
0021     /// default constructor
0022     CandidateWithRef() : LeafCandidate() {}
0023     /// constructor from values
0024     CandidateWithRef(const LorentzVector &p4, Charge q = 0, const Point &vtx = Point(0, 0, 0))
0025         : LeafCandidate(q, p4, vtx) {}
0026     /// destructor
0027     ~CandidateWithRef() override;
0028     /// returns a clone of the candidate
0029     CandidateWithRef *clone() const override;
0030     /// set reference
0031     void setRef(const Ref &r) { ref_ = r; }
0032     /// reference
0033     reference ref() const { return ref_; }
0034 
0035     CMS_CLASS_VERSION(13)
0036 
0037   private:
0038     /// check overlap with another candidate
0039     bool overlap(const Candidate &) const override;
0040     /// reference to a CaloRecHit
0041     reference ref_;
0042   };
0043 
0044   // the following has to be added for any single Ref type
0045   // GET_DEFAULT_CANDIDATE_COMPONENT( CandidateWithRef<Ref>, CandidateWithRef<Ref>::reference, ref )
0046 
0047   template <typename Ref>
0048   CandidateWithRef<Ref>::~CandidateWithRef() {}
0049 
0050   template <typename Ref>
0051   CandidateWithRef<Ref> *CandidateWithRef<Ref>::clone() const {
0052     return new CandidateWithRef<Ref>(*this);
0053   }
0054 
0055   template <typename Ref>
0056   bool CandidateWithRef<Ref>::overlap(const Candidate &c) const {
0057     const CandidateWithRef *o = dynamic_cast<const CandidateWithRef *>(&c);
0058     if (o == nullptr)
0059       return false;
0060     if (ref().isNull())
0061       return false;
0062     if (o->ref().isNull())
0063       return false;
0064     return (ref() != o->ref());
0065   }
0066 
0067 }  // namespace reco
0068 
0069 #endif