Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHMultiSelect_h
0002 #define HeavyFlavorAnalysis_RecoDecay_BPHMultiSelect_h
0003 /** \class BPHMultiSelect
0004  *
0005  *  Description: 
0006  *     Class to combine multiple selection (OR mode)
0007  *
0008  *  \author Paolo Ronchese INFN Padova
0009  *
0010  */
0011 
0012 //----------------------
0013 // Base Class Headers --
0014 //----------------------
0015 
0016 //------------------------------------
0017 // Collaborating Class Declarations --
0018 //------------------------------------
0019 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHRecoSelect.h"
0020 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHMomentumSelect.h"
0021 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHVertexSelect.h"
0022 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHFitSelect.h"
0023 class BPHRecoBuilder;
0024 class BPHDecayMomentum;
0025 class BPHDecayVertex;
0026 
0027 namespace reco {
0028   class Candidate;
0029 }
0030 
0031 //---------------
0032 // C++ Headers --
0033 //---------------
0034 #include <vector>
0035 
0036 //              ---------------------
0037 //              -- Class Interface --
0038 //              ---------------------
0039 
0040 class BPHSelectOperation {
0041 public:
0042   enum mode { or_mode, and_mode };
0043 };
0044 
0045 template <class T>
0046 class BPHMultiSelectBase : public T {
0047 public:
0048   /** Constructor
0049    */
0050   BPHMultiSelectBase(BPHSelectOperation::mode op) {
0051     switch (op) {
0052       case BPHSelectOperation::or_mode:
0053         breakValue = true;
0054         finalValue = false;
0055         break;
0056       case BPHSelectOperation::and_mode:
0057         breakValue = false;
0058         finalValue = true;
0059         break;
0060     }
0061   }
0062 
0063   // deleted copy constructor and assignment operator
0064   BPHMultiSelectBase(const BPHMultiSelectBase<T>& x) = delete;
0065   BPHMultiSelectBase& operator=(const BPHMultiSelectBase<T>& x) = delete;
0066 
0067   /** Destructor
0068    */
0069   ~BPHMultiSelectBase() override {}
0070 
0071   /** Operations
0072    */
0073   /// include selection
0074   void include(T& s, bool m = true) {
0075     SelectElement e;
0076     e.selector = &s;
0077     e.mode = m;
0078     selectList.push_back(e);
0079     return;
0080   }
0081 
0082   /// component count
0083   unsigned int count() { return selectList.size(); }
0084 
0085 protected:
0086   using Obj = typename T::AcceptArg;
0087   bool select(const Obj& cand) const {
0088     int i;
0089     int n = selectList.size();
0090     for (i = 0; i < n; ++i) {
0091       const SelectElement& e = selectList[i];
0092       if ((e.selector->accept(cand) == e.mode) == breakValue)
0093         return breakValue;
0094     }
0095     return finalValue;
0096   }
0097   bool select(const Obj& cand, const BPHRecoBuilder* build) const {
0098     int i;
0099     int n = selectList.size();
0100     for (i = 0; i < n; ++i) {
0101       const SelectElement& e = selectList[i];
0102       if ((e.selector->accept(cand, build) == e.mode) == breakValue)
0103         return breakValue;
0104     }
0105     return finalValue;
0106   }
0107 
0108 private:
0109   struct SelectElement {
0110     T* selector;
0111     bool mode;
0112   };
0113 
0114   bool breakValue;
0115   bool finalValue;
0116   std::vector<SelectElement> selectList;
0117 };
0118 
0119 template <class T>
0120 class BPHSlimSelect : public BPHMultiSelectBase<T> {
0121 public:
0122   using Base = BPHMultiSelectBase<T>;
0123 
0124   /** Constructor
0125    */
0126   BPHSlimSelect(BPHSelectOperation::mode op) : Base(op) {}
0127 
0128   // deleted copy constructor and assignment operator
0129   BPHSlimSelect(const BPHSlimSelect<T>& x) = delete;
0130   BPHSlimSelect& operator=(const BPHSlimSelect<T>& x) = delete;
0131 
0132   /** Destructor
0133    */
0134   ~BPHSlimSelect() override {}
0135 
0136   /** Operations
0137    */
0138   /// accept function
0139   bool accept(const typename T::AcceptArg& cand) const override { return Base::select(cand); }
0140 };
0141 
0142 template <class T>
0143 class BPHFullSelect : public BPHSlimSelect<T> {
0144 public:
0145   using Base = BPHSlimSelect<T>;
0146 
0147   /** Constructor
0148    */
0149   BPHFullSelect(BPHSelectOperation::mode op) : Base(op) {}
0150 
0151   // deleted copy constructor and assignment operator
0152   BPHFullSelect(const BPHFullSelect<T>& x);
0153   BPHFullSelect& operator=(const BPHFullSelect<T>& x);
0154 
0155   /** Destructor
0156    */
0157   ~BPHFullSelect() override {}
0158 
0159   /** Operations
0160    */
0161   /// accept function
0162   bool accept(const typename T::AcceptArg& cand, const BPHRecoBuilder* build) const override {
0163     return Base::select(cand, build);
0164   }
0165 };
0166 
0167 template <class T = BPHFullSelect<BPHRecoSelect>>
0168 class BPHMultiSelect : public T {
0169 public:
0170   /** Constructor
0171    */
0172   BPHMultiSelect(BPHSelectOperation::mode op) : T(op) {}
0173 
0174   // deleted copy constructor and assignment operator
0175   BPHMultiSelect(const BPHMultiSelect<T>& x) = delete;
0176   BPHMultiSelect& operator=(const BPHMultiSelect<T>& x) = delete;
0177 
0178   /** Destructor
0179    */
0180   ~BPHMultiSelect() override {}
0181 
0182   /** Operations
0183    */
0184   /// no override or new function, everything taken from base
0185 };
0186 
0187 #endif