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