CMS 3D CMS Logo

BPHRecoBuilder.h
Go to the documentation of this file.
1 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHRecoBuilder_h
2 #define HeavyFlavorAnalysis_RecoDecay_BPHRecoBuilder_h
3 
14 //----------------------
15 // Base Class Headers --
16 //----------------------
17 
18 //------------------------------------
19 // Collaborating Class Declarations --
20 //------------------------------------
26 class BPHRecoSelect;
27 class BPHMomentumSelect;
28 class BPHVertexSelect;
29 class BPHFitSelect;
30 
31 namespace reco {
32  class RecoCandidate;
33 }
34 
35 //---------------
36 // C++ Headers --
37 //---------------
38 #include <string>
39 #include <vector>
40 #include <map>
41 #include <set>
42 
43 // ---------------------
44 // -- Class Interface --
45 // ---------------------
46 
48 public:
52 
53  // deleted copy constructor and assignment operator
54  BPHRecoBuilder(const BPHRecoBuilder& x) = delete;
55  BPHRecoBuilder& operator=(const BPHRecoBuilder& x) = delete;
56 
59  virtual ~BPHRecoBuilder();
60 
63  class BPHGenericCollection {
65  public:
66  BPHGenericCollection(const std::string& list) : sList(list) {}
67  virtual ~BPHGenericCollection() {}
68  virtual const reco::Candidate& get(int i) const = 0;
69  virtual int size() const = 0;
70  const std::string& searchList() const { return sList; }
71 
72  private:
74  };
75  template <class T>
76  static BPHGenericCollection* createCollection(const edm::Handle<T>& collection, const std::string& list = "cfhpmig");
77  static BPHGenericCollection* createCollection(const std::vector<const reco::Candidate*>& candList,
78  const std::string& list = "cfhpmig");
79 
88  void add(const std::string& name, const BPHGenericCollection* collection, double mass = -1.0, double msig = -1.0);
89  template <class T>
90  void add(const std::string& name, const edm::Handle<T>& collection, double mass = -1.0, double msig = -1.0);
91  void add(const std::string& name, const std::vector<BPHRecoConstCandPtr>& collection);
92  template <class T>
93  void add(const std::string& name, const std::vector<T>& collection);
94 
97  void filter(const std::string& name, const BPHRecoSelect& sel) const;
99  void filter(const std::string& name, const BPHMomentumSelect& sel) const;
101  void filter(const std::string& name, const BPHVertexSelect& sel) const;
103  void filter(const std::string& name, const BPHFitSelect& sel) const;
104 
107  void filter(const BPHMomentumSelect& sel);
109  void filter(const BPHVertexSelect& sel);
111  void filter(const BPHFitSelect& sel);
112  // apply selection to reconstructed candidate
113  bool accept(const BPHRecoCandidate& cand) const;
114 
117  void setMinPDiffererence(double pMin);
118 
121  struct ComponentSet {
122  std::map<std::string, BPHDecayMomentum::Component> daugMap;
123  std::map<std::string, BPHRecoConstCandPtr> compMap;
124  };
125 
127  std::vector<ComponentSet> build() const;
128 
130  const BPHEventSetupWrapper* eventSetup() const;
131 
133  const reco::Candidate* getDaug(const std::string& name) const;
135 
139  static bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand, double minPDifference);
140 
141 private:
142  // object to interface with a specific edm collection
143  typedef std::vector<const reco::Candidate*> rcpV;
144  template <class T>
146  public:
147  BPHInterfaceCollection(const T& c, const std::string& list) : BPHGenericCollection(list), cPtr(&c) {}
149  int size() const override { return cPtr->size(); }
150 
151  protected:
152  const T* cPtr;
153  };
154  template <class T>
156  public:
157  BPHSpecificCollection(const T& c, const std::string& list) : BPHInterfaceCollection<T>(c, list) {}
158  const reco::Candidate& get(int i) const override { return (*this->cPtr)[i]; }
159  };
160 
161  // object to contain a list of simple particles
162  // with their names, selections, masses and sigma
163  struct BPHRecoSource {
166  std::vector<const BPHRecoSelect*> selector;
167  double mass;
168  double msig;
169  };
170 
171  // object to contain a list of previously reconstructed particles
172  // with their names and selections
173  struct BPHCompSource {
175  const std::vector<BPHRecoConstCandPtr>* collection;
176  std::vector<const BPHMomentumSelect*> momSelector;
177  std::vector<const BPHVertexSelect*> vtxSelector;
178  std::vector<const BPHFitSelect*> fitSelector;
179  };
180 
181  // map of names to simple or previously recontructed particles
182  // for currently tested combination
183  mutable std::map<std::string, const reco::Candidate*> daugMap;
184  mutable std::map<std::string, BPHRecoConstCandPtr> compMap;
185 
187  double minPDiff;
188 
189  // list of simple and previously recontructed particles in the decay
190  std::vector<BPHRecoSource*> sourceList;
191  std::vector<BPHCompSource*> srCompList;
192 
193  // set of copies of previously reconstructed particles list
194  // for bookkeeping and cleanup
195  std::set<const std::vector<BPHRecoConstCandPtr>*> compCollectList;
196 
197  // list fo selections to reconstructed particle
198  std::vector<const BPHMomentumSelect*> msList;
199  std::vector<const BPHVertexSelect*> vsList;
200  std::vector<const BPHFitSelect*> fsList;
201 
202  // map linking particles names to position in list position
203  std::map<std::string, int> sourceId;
204  std::map<std::string, int> srCompId;
205 
206  // recursive function to build particles combinations
207  void build(std::vector<ComponentSet>& compList,
208  ComponentSet& compSet,
209  std::vector<BPHRecoSource*>::const_iterator r_iter,
210  std::vector<BPHRecoSource*>::const_iterator r_iend,
211  std::vector<BPHCompSource*>::const_iterator c_iter,
212  std::vector<BPHCompSource*>::const_iterator c_iend) const;
213 
214  // check for already used particles in a combination
215  // previously recontructed particles are assumed to be included
216  // after simple particles
217  bool contained(ComponentSet& compSet, const reco::Candidate* cand) const;
218  bool contained(ComponentSet& compSet, BPHRecoConstCandPtr cand) const;
219  // compare two particles with their track reference and return
220  // true or false for same or different particles, including a
221  // check with momentum difference
222  bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand) const;
223 };
224 
225 template <class T>
227  const std::string& list) {
228  return new BPHSpecificCollection<T>(*collection, list);
229 }
230 
231 template <class T>
232 void BPHRecoBuilder::add(const std::string& name, const edm::Handle<T>& collection, double mass, double msig) {
233  // forward call after creating an interface to the collection
234  add(name, new BPHSpecificCollection<T>(*collection, "cfhpmig"), mass, msig);
235  return;
236 }
237 
238 template <class T>
239 void BPHRecoBuilder::add(const std::string& name, const std::vector<T>& collection) {
240  // forward call after converting the list of pointer to a list
241  // of pointer to base objects
242  int i;
243  int n = collection.size();
244  std::vector<BPHRecoConstCandPtr>* compCandList = new std::vector<BPHRecoConstCandPtr>(n);
245  for (i = 0; i < n; ++i)
246  (*compCandList)[i] = collection[i];
247  // save the converted list for cleanup
248  compCollectList.insert(compCandList);
249  add(name, *compCandList);
250  return;
251 }
252 
253 template <>
255  : public BPHRecoBuilder::BPHInterfaceCollection<BPHRecoBuilder::rcpV> {
256 public:
259  const reco::Candidate& get(int i) const override { return *(*this->cPtr)[i]; }
260 };
261 
262 #endif
std::vector< const BPHRecoSelect * > selector
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
void setMinPDiffererence(double pMin)
std::map< std::string, BPHRecoConstCandPtr > compMap
bool accept(const BPHRecoCandidate &cand) const
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
virtual ~BPHRecoBuilder()
std::vector< const BPHFitSelect * > fsList
BPHRecoBuilder(const BPHEventSetupWrapper &es)
const std::vector< BPHRecoConstCandPtr > * collection
std::map< std::string, BPHDecayMomentum::Component > daugMap
const BPHEventSetupWrapper * evSetup
BPHSpecificCollection(const T &c, const std::string &list)
BPHGenericCollection(const std::string &list)
std::vector< BPHCompSource * > srCompList
const BPHGenericCollection * collection
static BPHGenericCollection * createCollection(const edm::Handle< T > &collection, const std::string &list="cfhpmig")
std::vector< const BPHVertexSelect * > vsList
std::map< std::string, const reco::Candidate * > daugMap
const std::string & searchList() const
std::vector< const BPHFitSelect * > fitSelector
bool contained(ComponentSet &compSet, const reco::Candidate *cand) const
BPHRecoConstCandPtr getComp(const std::string &name) const
void filter(const std::string &name, const BPHRecoSelect &sel) const
std::vector< BPHRecoSource * > sourceList
std::vector< ComponentSet > build() const
build a set of combinations of particles fulfilling the selections
void add(const std::string &name, const BPHGenericCollection *collection, double mass=-1.0, double msig=-1.0)
BPHSpecificCollection(const BPHRecoBuilder::rcpV &c, const std::string &list)
std::vector< const reco::Candidate * > rcpV
const reco::Candidate * getDaug(const std::string &name) const
get simple or previously recontructed particle in current combination
std::vector< const BPHMomentumSelect * > momSelector
common object to interface with edm collections
const BPHEventSetupWrapper * eventSetup() const
get the EventSetup set in the constructor
BPHInterfaceCollection(const T &c, const std::string &list)
std::map< std::string, BPHRecoConstCandPtr > compMap
fixed size matrix
std::vector< const BPHMomentumSelect * > msList
std::vector< const BPHVertexSelect * > vtxSelector
std::set< const std::vector< BPHRecoConstCandPtr > * > compCollectList
BPHRecoBuilder & operator=(const BPHRecoBuilder &x)=delete
long double T
std::map< std::string, int > srCompId
std::map< std::string, int > sourceId