Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:48

0001 #ifndef Candidate_CompositeRefCandidate_h
0002 #define Candidate_CompositeRefCandidate_h
0003 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0004 /** \class reco::CompositeRefCandidate
0005  *
0006  * a reco::Candidate composed of daughters. 
0007  * The daughters has persistent references (edm::Ref <...>) 
0008  * to reco::Candidate stored in a separate collection.
0009  *
0010  * \author Luca Lista, INFN
0011  *
0012  *
0013  */
0014 
0015 namespace reco {
0016 
0017   class CompositeRefCandidate : public LeafCandidate {
0018   public:
0019     /// collection of references to daughters
0020     typedef CandidateRefVector daughters;
0021     /// collection of references to daughters
0022     typedef CandidateRefVector mothers;
0023     /// default constructor
0024     CompositeRefCandidate() : LeafCandidate() {}
0025     /// constructor from values
0026     CompositeRefCandidate(Charge q,
0027                           const LorentzVector& p4,
0028                           const Point& vtx = Point(0, 0, 0),
0029                           int pdgId = 0,
0030                           int status = 0,
0031                           bool integerCharge = true)
0032         : LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
0033     /// constructor from values
0034     CompositeRefCandidate(Charge q,
0035                           const PolarLorentzVector& p4,
0036                           const Point& vtx = Point(0, 0, 0),
0037                           int pdgId = 0,
0038                           int status = 0,
0039                           bool integerCharge = true)
0040         : LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
0041     /// constructor from a candidate
0042     explicit CompositeRefCandidate(const Candidate& p) : LeafCandidate(p) {}
0043     /// destructor
0044     ~CompositeRefCandidate() override;
0045     /// returns a clone of the candidate
0046     CompositeRefCandidate* clone() const override;
0047     /// number of daughters
0048     size_t numberOfDaughters() const override;
0049     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
0050     const Candidate* daughter(size_type) const override;
0051     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1
0052     Candidate* daughter(size_type) override;
0053     using reco::LeafCandidate::daughter;  // avoid hiding the base
0054     /// add a daughter via a reference
0055     void addDaughter(const CandidateRef&);
0056     /// add a daughter via a reference
0057     void addMother(const CandidateRef&);
0058     /// clear daughter references
0059     void clearDaughters() { dau.clear(); }
0060     /// reference to daughter at given position
0061     CandidateRef daughterRef(size_type i) const { return dau[i]; }
0062     /// references to daughtes
0063     const daughters& daughterRefVector() const { return dau; }
0064     /// reference to mother at given position
0065     CandidateRef motherRef(size_type i = 0) const { return mom[i]; }
0066     /// references to mothers
0067     const mothers& motherRefVector() const { return mom; }
0068     /// set daughters product ID
0069     void resetDaughters(const edm::ProductID& id) { dau = daughters(id); }
0070     /// number of mothers (zero or one in most of but not all the cases)
0071     size_t numberOfMothers() const override;
0072     /// return pointer to mother
0073     const Candidate* mother(size_t i = 0) const override;
0074 
0075   private:
0076     /// collection of references to daughters
0077     daughters dau;
0078     /// collection of references to mothers
0079     daughters mom;
0080     /// check overlap with another candidate
0081     bool overlap(const Candidate&) const override;
0082   };
0083 
0084   inline void CompositeRefCandidate::addDaughter(const CandidateRef& cand) { dau.push_back(cand); }
0085 
0086   inline void CompositeRefCandidate::addMother(const CandidateRef& cand) { mom.push_back(cand); }
0087 }  // namespace reco
0088 
0089 #endif