CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //------------------------------------
25 class BPHRecoSelect;
26 class BPHMomentumSelect;
27 class BPHVertexSelect;
28 class BPHFitSelect;
29 
30 namespace edm {
31  class EventSetup;
32 }
33 
34 namespace reco {
35  class RecoCandidate;
36 }
37 
38 //---------------
39 // C++ Headers --
40 //---------------
41 #include <string>
42 #include <vector>
43 #include <map>
44 #include <set>
45 
46 // ---------------------
47 // -- Class Interface --
48 // ---------------------
49 
51  friend class BPHRecoSelect;
52 
53 public:
57 
58  // deleted copy constructor and assignment operator
59  BPHRecoBuilder(const BPHRecoBuilder& x) = delete;
60  BPHRecoBuilder& operator=(const BPHRecoBuilder& x) = delete;
61 
64  virtual ~BPHRecoBuilder();
65 
69  // common object to interface with edm collections
71  public:
72  BPHGenericCollection(const std::string& list) : sList(list) {}
73  virtual ~BPHGenericCollection() {}
74  virtual const reco::Candidate& get(int i) const = 0;
75  virtual int size() const = 0;
76  const std::string& searchList() const { return sList; }
77 
78  private:
80  };
81  template <class T>
82  static BPHGenericCollection* createCollection(const edm::Handle<T>& collection, const std::string& list = "cfhpmig");
83  static BPHGenericCollection* createCollection(const std::vector<const reco::Candidate*>& candList,
84  const std::string& list = "cfhpmig");
85 
94  void add(const std::string& name, const BPHGenericCollection* collection, double mass = -1.0, double msig = -1.0);
95  template <class T>
96  void add(const std::string& name, const edm::Handle<T>& collection, double mass = -1.0, double msig = -1.0);
97  void add(const std::string& name, const std::vector<BPHRecoConstCandPtr>& collection);
98  template <class T>
99  void add(const std::string& name, const std::vector<T>& collection);
100 
103  void filter(const std::string& name, const BPHRecoSelect& sel) const;
105  void filter(const std::string& name, const BPHMomentumSelect& sel) const;
107  void filter(const std::string& name, const BPHVertexSelect& sel) const;
109  void filter(const std::string& name, const BPHFitSelect& sel) const;
110 
113  void filter(const BPHMomentumSelect& sel);
115  void filter(const BPHVertexSelect& sel);
117  void filter(const BPHFitSelect& sel);
118  // apply selection to reconstructed candidate
119  bool accept(const BPHRecoCandidate& cand) const;
120 
123  void setMinPDiffererence(double pMin);
124 
127  struct ComponentSet {
128  std::map<std::string, BPHDecayMomentum::Component> daugMap;
129  std::map<std::string, BPHRecoConstCandPtr> compMap;
130  };
131 
133  std::vector<ComponentSet> build() const;
134 
136  const edm::EventSetup* eventSetup() const;
137 
138  // compare two particles with their track reference and return
139  // true or false for same or different particles, including a
140  // check with momentum difference
141  static bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand, double minPDifference);
142 
143 private:
144  // object to interface with a specific edm collection
145  typedef std::vector<const reco::Candidate*> rcpV;
146  template <class T>
148  public:
149  BPHInterfaceCollection(const T& c, const std::string& list) : BPHGenericCollection(list), cPtr(&c) {}
151  int size() const override { return cPtr->size(); }
152 
153  protected:
154  const T* cPtr;
155  };
156  template <class T>
158  public:
159  BPHSpecificCollection(const T& c, const std::string& list) : BPHInterfaceCollection<T>(c, list) {}
160  const reco::Candidate& get(int i) const override { return (*this->cPtr)[i]; }
161  };
162 
163  // object to contain a list of simple particles
164  // with their names, selections, masses and sigma
165  struct BPHRecoSource {
168  std::vector<const BPHRecoSelect*> selector;
169  double mass;
170  double msig;
171  };
172 
173  // object to contain a list of previously reconstructed particles
174  // with their names and selections
175  struct BPHCompSource {
177  const std::vector<BPHRecoConstCandPtr>* collection;
178  std::vector<const BPHMomentumSelect*> momSelector;
179  std::vector<const BPHVertexSelect*> vtxSelector;
180  std::vector<const BPHFitSelect*> fitSelector;
181  };
182 
183  // map of names to simple or previously recontructed particles
184  // for currently tested combination
185  mutable std::map<std::string, const reco::Candidate*> daugMap;
186  mutable std::map<std::string, BPHRecoConstCandPtr> compMap;
187 
189  double minPDiff;
190 
191  // list of simple and previously recontructed particles in the decay
192  std::vector<BPHRecoSource*> sourceList;
193  std::vector<BPHCompSource*> srCompList;
194 
195  // set of copies of previously reconstructed particles list
196  // for bookkeeping and cleanup
197  std::set<const std::vector<BPHRecoConstCandPtr>*> compCollectList;
198 
199  // list fo selections to reconstructed particle
200  std::vector<const BPHMomentumSelect*> msList;
201  std::vector<const BPHVertexSelect*> vsList;
202  std::vector<const BPHFitSelect*> fsList;
203 
204  // map linking particles names to position in list position
205  std::map<std::string, int> sourceId;
206  std::map<std::string, int> srCompId;
207 
208  // recursive function to build particles combinations
209  void build(std::vector<ComponentSet>& compList,
210  ComponentSet& compSet,
211  std::vector<BPHRecoSource*>::const_iterator r_iter,
212  std::vector<BPHRecoSource*>::const_iterator r_iend,
213  std::vector<BPHCompSource*>::const_iterator c_iter,
214  std::vector<BPHCompSource*>::const_iterator c_iend) const;
215 
216  // check for already used particles in a combination
217  // previously recontructed particles are assumed to be included
218  // after simple particles
219  bool contained(ComponentSet& compSet, const reco::Candidate* cand) const;
220  bool contained(ComponentSet& compSet, BPHRecoConstCandPtr cand) const;
221  // compare two particles with their track reference and return
222  // true or false for same or different particles, including a
223  // check with momentum difference
224  bool sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand) const;
225 };
226 
227 template <class T>
229  const std::string& list) {
230  return new BPHSpecificCollection<T>(*collection, list);
231 }
232 
233 template <class T>
234 void BPHRecoBuilder::add(const std::string& name, const edm::Handle<T>& collection, double mass, double msig) {
235  // forward call after creating an interface to the collection
236  add(name, new BPHSpecificCollection<T>(*collection, "cfhpmig"), mass, msig);
237  return;
238 }
239 
240 template <class T>
241 void BPHRecoBuilder::add(const std::string& name, const std::vector<T>& collection) {
242  // forward call after converting the list of pointer to a list
243  // of pointer to base objects
244  int i;
245  int n = collection.size();
246  std::vector<BPHRecoConstCandPtr>* compCandList = new std::vector<BPHRecoConstCandPtr>(n);
247  for (i = 0; i < n; ++i)
248  (*compCandList)[i] = collection[i];
249  // save the converted list for cleanup
250  compCollectList.insert(compCandList);
251  add(name, *compCandList);
252  return;
253 }
254 
255 template <>
257  : public BPHRecoBuilder::BPHInterfaceCollection<BPHRecoBuilder::rcpV> {
258 public:
261  const reco::Candidate& get(int i) const override { return *(*this->cPtr)[i]; }
262 };
263 
264 #endif
std::vector< const BPHRecoSelect * > selector
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
void setMinPDiffererence(double pMin)
const edm::EventSetup & c
std::map< std::string, BPHRecoConstCandPtr > compMap
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
virtual ~BPHRecoBuilder()
std::vector< ComponentSet > build() const
build a set of combinations of particles fulfilling the selections
std::vector< const BPHFitSelect * > fsList
const std::vector< BPHRecoConstCandPtr > * collection
std::map< std::string, BPHDecayMomentum::Component > daugMap
const edm::EventSetup * evSetup
BPHSpecificCollection(const T &c, const std::string &list)
BPHGenericCollection(const std::string &list)
bool accept(const BPHRecoCandidate &cand) const
std::vector< BPHCompSource * > srCompList
const BPHGenericCollection * collection
const edm::EventSetup * eventSetup() const
get the EventSetup set in the constructor
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
std::vector< const BPHFitSelect * > fitSelector
std::vector< BPHRecoSource * > sourceList
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)
const std::string & searchList() const
std::vector< const reco::Candidate * > rcpV
std::vector< const BPHMomentumSelect * > momSelector
BPHInterfaceCollection(const T &c, const std::string &list)
void filter(const std::string &name, const BPHRecoSelect &sel) const
std::map< std::string, BPHRecoConstCandPtr > compMap
std::vector< const BPHMomentumSelect * > msList
std::vector< const BPHVertexSelect * > vtxSelector
bool contained(ComponentSet &compSet, const reco::Candidate *cand) const
std::set< const std::vector< BPHRecoConstCandPtr > * > compCollectList
BPHRecoBuilder(const edm::EventSetup &es)
BPHRecoBuilder & operator=(const BPHRecoBuilder &x)=delete
long double T
std::map< std::string, int > srCompId
std::map< std::string, int > sourceId