Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef Candidate_CompositeRefCandidateT_h
0002 #define Candidate_CompositeRefCandidateT_h
0003 /** \class reco::CompositeRefCandidateT<D>
0004  *
0005  * a reco::Candidate composed of daughters. 
0006  * The daughters has persistent references (edm::Ref <...>) 
0007  * to reco::Candidate stored in a separate collection.
0008  *
0009  * \author Luca Lista, INFN
0010  *
0011  *
0012  */
0013 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0014 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0015 
0016 namespace reco {
0017 
0018   template <typename D>
0019   class CompositeRefCandidateT : public LeafCandidate {
0020   public:
0021     /// collection of references to daughters
0022     typedef D daughters;
0023     /// collection of references to daughters
0024     typedef D mothers;
0025     /// default constructor
0026     CompositeRefCandidateT() : LeafCandidate() {}
0027     /// constructor from values
0028     CompositeRefCandidateT(Charge q,
0029                            const LorentzVector& p4,
0030                            const Point& vtx = Point(0, 0, 0),
0031                            int pdgId = 0,
0032                            int status = 0,
0033                            bool integerCharge = true)
0034         : LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
0035     /// constructor from values
0036     CompositeRefCandidateT(Charge q,
0037                            const PolarLorentzVector& p4,
0038                            const Point& vtx = Point(0, 0, 0),
0039                            int pdgId = 0,
0040                            int status = 0,
0041                            bool integerCharge = true)
0042         : LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
0043     /// constructor from a particle
0044     explicit CompositeRefCandidateT(const LeafCandidate& c) : LeafCandidate(c) {}
0045     /// destructor
0046     ~CompositeRefCandidateT() override;
0047     /// returns a clone of the candidate
0048     CompositeRefCandidateT<D>* clone() const override;
0049     /// number of daughters
0050     size_t numberOfDaughters() const override;
0051     /// number of mothers
0052     size_t numberOfMothers() const override;
0053     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
0054     const Candidate* daughter(size_type) const override;
0055     using ::reco::LeafCandidate::daughter;  // avoid hiding the base
0056     /// return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode)
0057     const Candidate* mother(size_type = 0) const override;
0058     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1
0059     Candidate* daughter(size_type) override;
0060     /// add a daughter via a reference
0061     void addDaughter(const typename daughters::value_type&);
0062     /// add a daughter via a reference
0063     void addMother(const typename mothers::value_type&);
0064     /// clear daughter references
0065     void clearDaughters() { dau.clear(); }
0066     /// clear mother references
0067     void clearMothers() { mom.clear(); }
0068     /// reference to daughter at given position
0069     typename daughters::value_type daughterRef(size_type i) const { return dau[i]; }
0070     /// references to daughtes
0071     const daughters& daughterRefVector() const { return dau; }
0072     /// reference to mother at given position
0073     typename daughters::value_type motherRef(size_type i = 0) const { return mom[i]; }
0074     /// references to mothers
0075     const mothers& motherRefVector() const { return mom; }
0076     /// set daughters product ID
0077     void resetDaughters(const edm::ProductID& id) { dau = daughters(id); }
0078     /// set mother product ID
0079     void resetMothers(const edm::ProductID& id) { mom = mothers(id); }
0080 
0081     CMS_CLASS_VERSION(13)
0082 
0083   private:
0084     /// collection of references to daughters
0085     daughters dau;
0086     /// collection of references to mothers
0087     daughters mom;
0088     /// check overlap with another candidate
0089     bool overlap(const Candidate&) const override;
0090   };
0091 
0092   template <typename D>
0093   inline void CompositeRefCandidateT<D>::addDaughter(const typename daughters::value_type& cand) {
0094     dau.push_back(cand);
0095   }
0096 
0097   template <typename D>
0098   inline void CompositeRefCandidateT<D>::addMother(const typename daughters::value_type& cand) {
0099     mom.push_back(cand);
0100   }
0101 
0102   template <typename D>
0103   CompositeRefCandidateT<D>::~CompositeRefCandidateT() {}
0104 
0105   template <typename D>
0106   CompositeRefCandidateT<D>* CompositeRefCandidateT<D>::clone() const {
0107     return new CompositeRefCandidateT(*this);
0108   }
0109 
0110   template <typename D>
0111   const Candidate* CompositeRefCandidateT<D>::daughter(size_type i) const {
0112     return (i < numberOfDaughters()) ? &*dau[i] : nullptr;
0113   }
0114 
0115   template <typename D>
0116   const Candidate* CompositeRefCandidateT<D>::mother(size_type i) const {
0117     return (i < numberOfMothers()) ? &*mom[i] : nullptr;
0118   }
0119 
0120   template <typename D>
0121   Candidate* CompositeRefCandidateT<D>::daughter(size_type i) {
0122     return nullptr;
0123   }
0124 
0125   template <typename D>
0126   size_t CompositeRefCandidateT<D>::numberOfDaughters() const {
0127     return dau.size();
0128   }
0129 
0130   template <typename D>
0131   size_t CompositeRefCandidateT<D>::numberOfMothers() const {
0132     return mom.size();
0133   }
0134 
0135   template <typename D>
0136   bool CompositeRefCandidateT<D>::overlap(const Candidate& c2) const {
0137     throw cms::Exception("Error") << "can't check overlap internally for CompositeRefCanddate";
0138   }
0139 }  // namespace reco
0140 
0141 #endif