File indexing completed on 2021-02-14 12:49:20
0001 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHRecoBuilder_h
0002 #define HeavyFlavorAnalysis_RecoDecay_BPHRecoBuilder_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHDecayMomentum.h"
0022 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHDecayVertex.h"
0023 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHKinematicFit.h"
0024 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHGenericPtr.h"
0025 class BPHRecoSelect;
0026 class BPHMomentumSelect;
0027 class BPHVertexSelect;
0028 class BPHFitSelect;
0029
0030 namespace edm {
0031 class EventSetup;
0032 }
0033
0034 namespace reco {
0035 class RecoCandidate;
0036 }
0037
0038
0039
0040
0041 #include <string>
0042 #include <vector>
0043 #include <map>
0044 #include <set>
0045
0046
0047
0048
0049
0050 class BPHRecoBuilder {
0051 friend class BPHRecoSelect;
0052
0053 public:
0054
0055
0056 BPHRecoBuilder(const edm::EventSetup& es);
0057
0058
0059 BPHRecoBuilder(const BPHRecoBuilder& x) = delete;
0060 BPHRecoBuilder& operator=(const BPHRecoBuilder& x) = delete;
0061
0062
0063
0064 virtual ~BPHRecoBuilder();
0065
0066
0067
0068
0069
0070 class BPHGenericCollection {
0071 public:
0072 BPHGenericCollection(const std::string& list) : sList(list) {}
0073 virtual ~BPHGenericCollection() {}
0074 virtual const reco::Candidate& get(int i) const = 0;
0075 virtual int size() const = 0;
0076 const std::string& searchList() const { return sList; }
0077
0078 private:
0079 std::string sList;
0080 };
0081 template <class T>
0082 static BPHGenericCollection* createCollection(const edm::Handle<T>& collection, const std::string& list = "cfhpmig");
0083 static BPHGenericCollection* createCollection(const std::vector<const reco::Candidate*>& candList,
0084 const std::string& list = "cfhpmig");
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 void add(const std::string& name, const BPHGenericCollection* collection, double mass = -1.0, double msig = -1.0);
0095 template <class T>
0096 void add(const std::string& name, const edm::Handle<T>& collection, double mass = -1.0, double msig = -1.0);
0097 void add(const std::string& name, const std::vector<BPHRecoConstCandPtr>& collection);
0098 template <class T>
0099 void add(const std::string& name, const std::vector<T>& collection);
0100
0101
0102
0103 void filter(const std::string& name, const BPHRecoSelect& sel) const;
0104
0105 void filter(const std::string& name, const BPHMomentumSelect& sel) const;
0106
0107 void filter(const std::string& name, const BPHVertexSelect& sel) const;
0108
0109 void filter(const std::string& name, const BPHFitSelect& sel) const;
0110
0111
0112
0113 void filter(const BPHMomentumSelect& sel);
0114
0115 void filter(const BPHVertexSelect& sel);
0116
0117 void filter(const BPHFitSelect& sel);
0118
0119 bool accept(const BPHRecoCandidate& cand) const;
0120
0121
0122
0123 void setMinPDiffererence(double pMin);
0124
0125
0126
0127 struct ComponentSet {
0128 std::map<std::string, BPHDecayMomentum::Component> daugMap;
0129 std::map<std::string, BPHRecoConstCandPtr> compMap;
0130 };
0131
0132
0133 std::vector<ComponentSet> build() const;
0134
0135
0136 const edm::EventSetup* eventSetup() const;
0137
0138
0139
0140
0141 static bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand, double minPDifference);
0142
0143 private:
0144
0145 typedef std::vector<const reco::Candidate*> rcpV;
0146 template <class T>
0147 class BPHInterfaceCollection : public BPHGenericCollection {
0148 public:
0149 BPHInterfaceCollection(const T& c, const std::string& list) : BPHGenericCollection(list), cPtr(&c) {}
0150 ~BPHInterfaceCollection() override {}
0151 int size() const override { return cPtr->size(); }
0152
0153 protected:
0154 const T* cPtr;
0155 };
0156 template <class T>
0157 class BPHSpecificCollection : public BPHInterfaceCollection<T> {
0158 public:
0159 BPHSpecificCollection(const T& c, const std::string& list) : BPHInterfaceCollection<T>(c, list) {}
0160 const reco::Candidate& get(int i) const override { return (*this->cPtr)[i]; }
0161 };
0162
0163
0164
0165 struct BPHRecoSource {
0166 const std::string* name;
0167 const BPHGenericCollection* collection;
0168 std::vector<const BPHRecoSelect*> selector;
0169 double mass;
0170 double msig;
0171 };
0172
0173
0174
0175 struct BPHCompSource {
0176 const std::string* name;
0177 const std::vector<BPHRecoConstCandPtr>* collection;
0178 std::vector<const BPHMomentumSelect*> momSelector;
0179 std::vector<const BPHVertexSelect*> vtxSelector;
0180 std::vector<const BPHFitSelect*> fitSelector;
0181 };
0182
0183
0184
0185 mutable std::map<std::string, const reco::Candidate*> daugMap;
0186 mutable std::map<std::string, BPHRecoConstCandPtr> compMap;
0187
0188 const edm::EventSetup* evSetup;
0189 double minPDiff;
0190
0191
0192 std::vector<BPHRecoSource*> sourceList;
0193 std::vector<BPHCompSource*> srCompList;
0194
0195
0196
0197 std::set<const std::vector<BPHRecoConstCandPtr>*> compCollectList;
0198
0199
0200 std::vector<const BPHMomentumSelect*> msList;
0201 std::vector<const BPHVertexSelect*> vsList;
0202 std::vector<const BPHFitSelect*> fsList;
0203
0204
0205 std::map<std::string, int> sourceId;
0206 std::map<std::string, int> srCompId;
0207
0208
0209 void build(std::vector<ComponentSet>& compList,
0210 ComponentSet& compSet,
0211 std::vector<BPHRecoSource*>::const_iterator r_iter,
0212 std::vector<BPHRecoSource*>::const_iterator r_iend,
0213 std::vector<BPHCompSource*>::const_iterator c_iter,
0214 std::vector<BPHCompSource*>::const_iterator c_iend) const;
0215
0216
0217
0218
0219 bool contained(ComponentSet& compSet, const reco::Candidate* cand) const;
0220 bool contained(ComponentSet& compSet, BPHRecoConstCandPtr cand) const;
0221
0222
0223
0224 bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand) const;
0225 };
0226
0227 template <class T>
0228 BPHRecoBuilder::BPHGenericCollection* BPHRecoBuilder::createCollection(const edm::Handle<T>& collection,
0229 const std::string& list) {
0230 return new BPHSpecificCollection<T>(*collection, list);
0231 }
0232
0233 template <class T>
0234 void BPHRecoBuilder::add(const std::string& name, const edm::Handle<T>& collection, double mass, double msig) {
0235
0236 add(name, new BPHSpecificCollection<T>(*collection, "cfhpmig"), mass, msig);
0237 return;
0238 }
0239
0240 template <class T>
0241 void BPHRecoBuilder::add(const std::string& name, const std::vector<T>& collection) {
0242
0243
0244 int i;
0245 int n = collection.size();
0246 std::vector<BPHRecoConstCandPtr>* compCandList = new std::vector<BPHRecoConstCandPtr>(n);
0247 for (i = 0; i < n; ++i)
0248 (*compCandList)[i] = collection[i];
0249
0250 compCollectList.insert(compCandList);
0251 add(name, *compCandList);
0252 return;
0253 }
0254
0255 template <>
0256 class BPHRecoBuilder::BPHSpecificCollection<BPHRecoBuilder::rcpV>
0257 : public BPHRecoBuilder::BPHInterfaceCollection<BPHRecoBuilder::rcpV> {
0258 public:
0259 BPHSpecificCollection(const BPHRecoBuilder::rcpV& c, const std::string& list)
0260 : BPHInterfaceCollection<BPHRecoBuilder::rcpV>(c, list) {}
0261 const reco::Candidate& get(int i) const override { return *(*this->cPtr)[i]; }
0262 };
0263
0264 #endif