Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:55

0001 #ifndef CandUtils_CandCombiner_h
0002 #define CandUtils_CandCombiner_h
0003 /** \class CandCombiner
0004  *
0005  * \author Luca Lista, INFN
0006  *
0007  */
0008 #include "CommonTools/CandUtils/interface/CandCombinerBase.h"
0009 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0010 #include "CommonTools/CandUtils/interface/CandSelector.h"
0011 #include "CommonTools/UtilAlgos/interface/AnyPairSelector.h"
0012 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0013 #include "DataFormats/Candidate/interface/NamedCompositeCandidate.h"
0014 #include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
0015 #include "DataFormats/Candidate/interface/ShallowClonePtrCandidate.h"
0016 
0017 namespace combiner {
0018   namespace helpers {
0019     struct NormalClone {
0020       typedef reco::CandidateBaseRef CandPtr;
0021       template <typename Ref>
0022       static void addDaughter(reco::CompositeCandidate& cmp, const Ref& c, const std::string name = "") {
0023         cmp.addDaughter(*c, name);
0024       }
0025     };
0026 
0027     struct ShallowClone {
0028       typedef reco::CandidateBaseRef CandPtr;
0029       static void addDaughter(reco::CompositeCandidate& cmp,
0030                               const reco::CandidateBaseRef& c,
0031                               const std::string name = "") {
0032         cmp.addDaughter(reco::ShallowCloneCandidate(c), name);
0033       }
0034     };
0035     struct ShallowClonePtr {
0036       typedef reco::CandidatePtr CandPtr;
0037       static void addDaughter(reco::CompositeCandidate& cmp, const reco::CandidatePtr& c, const std::string name = "") {
0038         cmp.addDaughter(reco::ShallowClonePtrCandidate(c), name);
0039       }
0040     };
0041   }  // namespace helpers
0042 }  // namespace combiner
0043 
0044 template <typename Selector,
0045           typename PairSelector = AnyPairSelector,
0046           typename Cloner = combiner::helpers::NormalClone,
0047           typename OutputCollection = reco::CompositeCandidateCollection,
0048           typename Setup = AddFourMomenta>
0049 class CandCombiner : public CandCombinerBase<OutputCollection, typename Cloner::CandPtr> {
0050 public:
0051   typedef typename Cloner::CandPtr CandPtr;
0052   typedef CandCombinerBase<OutputCollection, CandPtr> base;
0053   /// default constructor
0054   CandCombiner() : base(), select_(), selectPair_(), setup_() {}
0055   /// constructor from a selector and two charges
0056   CandCombiner(int q1, int q2) : base(q1, q2), select_(), selectPair_(), setup_() {}
0057   /// constructor from a selector and three charges
0058   CandCombiner(int q1, int q2, int q3) : base(q1, q2, q3), select_(), selectPair_(), setup_() {}
0059   /// constructor from a selector and four charges
0060   CandCombiner(int q1, int q2, int q3, int q4) : base(q1, q2, q3, q4), select_(), selectPair_(), setup_() {}
0061   /// default constructor
0062   CandCombiner(const Selector& select) : base(), select_(select), selectPair_(), setup_() {}
0063   /// constructor from a selector and two charges
0064   CandCombiner(const Selector& select, int q1, int q2) : base(q1, q2), select_(select), selectPair_(), setup_() {}
0065   /// constructor from a selector and three charges
0066   CandCombiner(const Selector& select, int q1, int q2, int q3)
0067       : base(q1, q2, q3), select_(select), selectPair_(), setup_() {}
0068   /// constructor from a selector and four charges
0069   CandCombiner(const Selector& select, int q1, int q2, int q3, int q4)
0070       : base(q1, q2, q3, q4), select_(select), selectPair_(), setup_() {}
0071   /// constructor from selector
0072   CandCombiner(const Selector& select, const PairSelector& selectPair)
0073       : base(), select_(select), selectPair_(selectPair), setup_() {}
0074   /// constructor from a selector and two charges
0075   CandCombiner(const Selector& select, const PairSelector& selectPair, int q1, int q2)
0076       : base(q1, q2), select_(select), selectPair_(selectPair), setup_() {}
0077   /// constructor from a selector and three charges
0078   CandCombiner(const Selector& select, const PairSelector& selectPair, int q1, int q2, int q3)
0079       : base(q1, q2, q3), select_(select), selectPair_(selectPair), setup_() {}
0080   /// constructor from a selector and four charges
0081   CandCombiner(const Selector& select, const PairSelector& selectPair, int q1, int q2, int q3, int q4)
0082       : base(q1, q2, q3, q4), select_(select), selectPair_(selectPair), setup_() {}
0083   CandCombiner(const Selector& select, const PairSelector& selectPair, const Setup& setup)
0084       : base(), select_(select), selectPair_(selectPair), setup_(setup) {}
0085   /// constructor from a selector and two charges
0086   CandCombiner(const Selector& select, const PairSelector& selectPair, const Setup& setup, int q1, int q2)
0087       : base(q1, q2), select_(select), selectPair_(selectPair), setup_(setup) {}
0088   /// constructor from a selector and three charges
0089   CandCombiner(const Selector& select, const PairSelector& selectPair, const Setup& setup, int q1, int q2, int q3)
0090       : base(q1, q2, q3), select_(select), selectPair_(selectPair), setup_(setup) {}
0091   /// constructor from a selector and four charges
0092   CandCombiner(
0093       const Selector& select, const PairSelector& selectPair, const Setup& setup, int q1, int q2, int q3, int q4)
0094       : base(q1, q2, q3, q4), select_(select), selectPair_(selectPair), setup_(setup) {}
0095   /// constructor from a selector, specifying to check for charge
0096   CandCombiner(const Selector& select,
0097                const PairSelector& selectPair,
0098                const Setup& setup,
0099                const std::vector<int>& dauCharge)
0100       : base(true, dauCharge), select_(select), selectPair_(selectPair), setup_(setup) {}
0101   /// constructor from a selector, specifying to check for charge
0102   CandCombiner(const Selector& select, const PairSelector& selectPair, const std::vector<int>& dauCharge)
0103       : base(true, dauCharge), select_(select), selectPair_(selectPair), setup_() {}
0104   /// constructor from a selector, specifying to check for charge
0105   CandCombiner(const std::vector<int>& dauCharge) : base(true, dauCharge), select_(), selectPair_(), setup_() {}
0106   /// constructor from a selector, specifying optionally to check for charge
0107   CandCombiner(const Selector& select,
0108                const PairSelector& selectPair,
0109                const Setup& setup,
0110                bool checkCharge,
0111                bool checkOverlap,
0112                const std::vector<int>& dauCharge)
0113       : base(checkCharge, checkOverlap, dauCharge), select_(select), selectPair_(selectPair), setup_(setup) {}
0114   /// return reference to setup object to allow its initialization
0115   Setup& setup() { return setup_; }
0116 
0117 private:
0118   /// select a candidate
0119   bool select(const reco::Candidate& c) const override { return select_(c); }
0120   /// select a candidate
0121   bool selectPair(const reco::Candidate& c1, const reco::Candidate& c2) const override { return selectPair_(c1, c2); }
0122   /// set kinematics to reconstructed composite
0123   void setup(typename OutputCollection::value_type& c) const override { setup_.set(c); }
0124   /// add candidate daughter
0125   void addDaughter(typename OutputCollection::value_type& cmp,
0126                    const CandPtr& c,
0127                    const std::string name = "") const override {
0128     Cloner::addDaughter(cmp, c, name);
0129   }
0130   /// candidate selector
0131   Selector select_;
0132   /// candidate pair selector
0133   PairSelector selectPair_;
0134   /// utility to setup composite candidate kinematics from daughters
0135   Setup setup_;
0136 };
0137 
0138 #endif