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 //------------------------------------
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
BPHRecoBuilder::BPHSpecificCollection::BPHSpecificCollection
BPHSpecificCollection(const T &c, const std::string &list)
Definition: BPHRecoBuilder.h:159
BPHRecoBuilder::BPHInterfaceCollection::cPtr
const T * cPtr
Definition: BPHRecoBuilder.h:154
BPHRecoBuilder::filter
void filter(const std::string &name, const BPHRecoSelect &sel) const
BPHFitSelect
Definition: BPHFitSelect.h:29
BPHGenericPtr.h
mps_fire.i
i
Definition: mps_fire.py:428
BPHRecoSelect
Definition: BPHRecoSelect.h:35
BPHRecoBuilder::srCompList
std::vector< BPHCompSource * > srCompList
Definition: BPHRecoBuilder.h:193
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
BPHRecoBuilder::BPHInterfaceCollection::size
int size() const override
Definition: BPHRecoBuilder.h:151
BPHRecoBuilder::evSetup
const edm::EventSetup * evSetup
Definition: BPHRecoBuilder.h:188
BPHRecoBuilder::BPHRecoBuilder
BPHRecoBuilder(const edm::EventSetup &es)
Definition: BPHRecoBuilder.cc:37
edm
HLT enums.
Definition: AlignableModifier.h:19
BPHRecoBuilder::contained
bool contained(ComponentSet &compSet, const reco::Candidate *cand) const
Definition: BPHRecoBuilder.cc:301
BPHRecoBuilder::sourceList
std::vector< BPHRecoSource * > sourceList
Definition: BPHRecoBuilder.h:192
BPHRecoBuilder::sameTrack
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
Definition: BPHRecoBuilder.cc:188
BPHRecoBuilder::BPHGenericCollection::get
virtual const reco::Candidate & get(int i) const =0
BPHRecoBuilder::BPHSpecificCollection
Definition: BPHRecoBuilder.h:157
BPHMomentumSelect
Definition: BPHMomentumSelect.h:29
BPHRecoBuilder::~BPHRecoBuilder
virtual ~BPHRecoBuilder()
Definition: BPHRecoBuilder.cc:45
BPHDecayMomentum.h
BPHRecoBuilder::createCollection
static BPHGenericCollection * createCollection(const edm::Handle< T > &collection, const std::string &list="cfhpmig")
Definition: BPHRecoBuilder.h:228
DDAxes::x
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
BPHRecoBuilder::BPHSpecificCollection::get
const reco::Candidate & get(int i) const override
Definition: BPHRecoBuilder.h:160
BPHRecoBuilder::sourceId
std::map< std::string, int > sourceId
Definition: BPHRecoBuilder.h:205
edm::Handle
Definition: AssociativeIterator.h:50
BPHRecoBuilder::BPHCompSource::vtxSelector
std::vector< const BPHVertexSelect * > vtxSelector
Definition: BPHRecoBuilder.h:179
BPHRecoBuilder::build
std::vector< ComponentSet > build() const
build a set of combinations of particles fulfilling the selections
Definition: BPHRecoBuilder.cc:177
BPHRecoBuilder::BPHInterfaceCollection::BPHInterfaceCollection
BPHInterfaceCollection(const T &c, const std::string &list)
Definition: BPHRecoBuilder.h:149
BPHRecoBuilder::BPHSpecificCollection< BPHRecoBuilder::rcpV >::BPHSpecificCollection
BPHSpecificCollection(const BPHRecoBuilder::rcpV &c, const std::string &list)
Definition: BPHRecoBuilder.h:259
BPHRecoBuilder::msList
std::vector< const BPHMomentumSelect * > msList
Definition: BPHRecoBuilder.h:200
BPHRecoBuilder
Definition: BPHRecoBuilder.h:50
BPHRecoBuilder::minPDiff
double minPDiff
Definition: BPHRecoBuilder.h:189
BPHRecoBuilder::BPHInterfaceCollection::~BPHInterfaceCollection
~BPHInterfaceCollection() override
Definition: BPHRecoBuilder.h:150
BPHRecoBuilder::daugMap
std::map< std::string, const reco::Candidate * > daugMap
Definition: BPHRecoBuilder.h:185
BPHRecoBuilder::BPHRecoSource::selector
std::vector< const BPHRecoSelect * > selector
Definition: BPHRecoBuilder.h:168
BPHRecoBuilder::BPHCompSource::fitSelector
std::vector< const BPHFitSelect * > fitSelector
Definition: BPHRecoBuilder.h:180
BPHRecoBuilder::setMinPDiffererence
void setMinPDiffererence(double pMin)
Definition: BPHRecoBuilder.cc:172
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BPHRecoBuilder::ComponentSet
Definition: BPHRecoBuilder.h:127
BPHRecoBuilder::eventSetup
const edm::EventSetup * eventSetup() const
get the EventSetup set in the constructor
Definition: BPHRecoBuilder.cc:186
BPHRecoBuilder::BPHGenericCollection::~BPHGenericCollection
virtual ~BPHGenericCollection()
Definition: BPHRecoBuilder.h:73
ALCARECOTkAlMinBias_cff.pMin
pMin
GeV.
Definition: ALCARECOTkAlMinBias_cff.py:35
cand
Definition: decayParser.h:32
BPHRecoBuilder::fsList
std::vector< const BPHFitSelect * > fsList
Definition: BPHRecoBuilder.h:202
BPHRecoBuilder::BPHGenericCollection::searchList
const std::string & searchList() const
Definition: BPHRecoBuilder.h:76
universalConfigTemplate.collection
collection
Definition: universalConfigTemplate.py:81
BPHRecoBuilder::ComponentSet::daugMap
std::map< std::string, BPHDecayMomentum::Component > daugMap
Definition: BPHRecoBuilder.h:128
BPHVertexSelect
Definition: BPHVertexSelect.h:29
BPHRecoBuilder::BPHGenericCollection::size
virtual int size() const =0
BPHRecoBuilder::BPHRecoSource::collection
const BPHGenericCollection * collection
Definition: BPHRecoBuilder.h:167
edm::EventSetup
Definition: EventSetup.h:58
BPHRecoBuilder::BPHCompSource::collection
const std::vector< BPHRecoConstCandPtr > * collection
Definition: BPHRecoBuilder.h:177
BPHRecoBuilder::BPHSpecificCollection< BPHRecoBuilder::rcpV >::get
const reco::Candidate & get(int i) const override
Definition: BPHRecoBuilder.h:261
reco::Candidate
Definition: Candidate.h:27
BPHRecoBuilder::BPHGenericCollection::sList
std::string sList
Definition: BPHRecoBuilder.h:79
BPHRecoBuilder::BPHRecoSource::mass
double mass
Definition: BPHRecoBuilder.h:169
BPHRecoBuilder::ComponentSet::compMap
std::map< std::string, BPHRecoConstCandPtr > compMap
Definition: BPHRecoBuilder.h:129
BPHRecoBuilder::BPHGenericCollection
Definition: BPHRecoBuilder.h:70
BPHRecoBuilder::BPHRecoSource::name
const std::string * name
Definition: BPHRecoBuilder.h:166
BPHRecoBuilder::compMap
std::map< std::string, BPHRecoConstCandPtr > compMap
Definition: BPHRecoBuilder.h:186
BPHRecoBuilder::BPHRecoSource
Definition: BPHRecoBuilder.h:165
BPHRecoBuilder::BPHInterfaceCollection
Definition: BPHRecoBuilder.h:147
BPHKinematicFit.h
T
long double T
Definition: Basic3DVectorLD.h:48
BPHRecoBuilder::rcpV
std::vector< const reco::Candidate * > rcpV
Definition: BPHRecoBuilder.h:145
BPHRecoBuilder::BPHRecoSource::msig
double msig
Definition: BPHRecoBuilder.h:170
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
BPHRecoBuilder::add
void add(const std::string &name, const BPHGenericCollection *collection, double mass=-1.0, double msig=-1.0)
BPHRecoBuilder::BPHCompSource
Definition: BPHRecoBuilder.h:175
BPHRecoBuilder::vsList
std::vector< const BPHVertexSelect * > vsList
Definition: BPHRecoBuilder.h:201
BPHDecayVertex.h
EventSetup
BPHRecoBuilder::compCollectList
std::set< const std::vector< BPHRecoConstCandPtr > * > compCollectList
Definition: BPHRecoBuilder.h:197
BPHRecoBuilder::accept
bool accept(const BPHRecoCandidate &cand) const
Definition: BPHRecoBuilder.cc:151
BPHRecoBuilder::BPHCompSource::momSelector
std::vector< const BPHMomentumSelect * > momSelector
Definition: BPHRecoBuilder.h:178
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
BPHRecoCandidate
Definition: BPHRecoCandidate.h:46
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
BPHRecoBuilder::operator=
BPHRecoBuilder & operator=(const BPHRecoBuilder &x)=delete
BPHRecoBuilder::BPHCompSource::name
const std::string * name
Definition: BPHRecoBuilder.h:176
BPHRecoBuilder::BPHGenericCollection::BPHGenericCollection
BPHGenericCollection(const std::string &list)
Definition: BPHRecoBuilder.h:72
BPHRecoBuilder::srCompId
std::map< std::string, int > srCompId
Definition: BPHRecoBuilder.h:206
BPHRecoConstCandPtr
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
Definition: BPHRecoCandidatePtr.h:9