CMS 3D CMS Logo

BPHRecoBuilder.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
24 
25 //---------------
26 // C++ Headers --
27 //---------------
28 #include <iostream>
29 #include <map>
30 
31 using namespace std;
32 
33 //-------------------
34 // Initializations --
35 //-------------------
36 
37 //----------------
38 // Constructors --
39 //----------------
40 BPHRecoBuilder::BPHRecoBuilder(const edm::EventSetup& es) : evSetup(&es), minPDiff(-1.0) {
41  msList.reserve(5);
42  vsList.reserve(5);
43 }
44 
45 //--------------
46 // Destructor --
47 //--------------
49  int n = sourceList.size();
50  while (n--) {
51  delete sourceList[n]->collection;
52  delete sourceList[n];
53  }
54  int m = srCompList.size();
55  while (m--)
56  delete srCompList[m];
57  while (!compCollectList.empty()) {
58  const vector<BPHRecoConstCandPtr>* cCollection = *compCollectList.begin();
59  delete cCollection;
60  compCollectList.erase(cCollection);
61  }
62 }
63 
64 //--------------
65 // Operations --
66 //--------------
67 BPHRecoBuilder::BPHGenericCollection* BPHRecoBuilder::createCollection(const vector<const reco::Candidate*>& candList,
68  const string& list) {
70 }
71 
72 template <>
74  return *(*cPtr)[i];
75 }
76 
77 void BPHRecoBuilder::filter(const string& name, const BPHRecoSelect& sel) const {
78  map<string, int>::const_iterator iter = sourceId.find(name);
79  if (iter == sourceId.end())
80  return;
81  BPHRecoSource* rs = sourceList[iter->second];
82  rs->selector.push_back(&sel);
83  return;
84 }
85 
86 void BPHRecoBuilder::filter(const string& name, const BPHMomentumSelect& sel) const {
87  map<string, int>::const_iterator iter = srCompId.find(name);
88  if (iter == sourceId.end())
89  return;
90  BPHCompSource* cs = srCompList[iter->second];
91  cs->momSelector.push_back(&sel);
92  return;
93 }
94 
95 void BPHRecoBuilder::filter(const string& name, const BPHVertexSelect& sel) const {
96  map<string, int>::const_iterator iter = srCompId.find(name);
97  if (iter == sourceId.end())
98  return;
99  BPHCompSource* cs = srCompList[iter->second];
100  cs->vtxSelector.push_back(&sel);
101  return;
102 }
103 
104 void BPHRecoBuilder::filter(const string& name, const BPHFitSelect& sel) const {
105  map<string, int>::const_iterator iter = srCompId.find(name);
106  if (iter == sourceId.end())
107  return;
108  BPHCompSource* cs = srCompList[iter->second];
109  cs->fitSelector.push_back(&sel);
110  return;
111 }
112 
114  msList.push_back(&sel);
115  return;
116 }
117 
119  vsList.push_back(&sel);
120  return;
121 }
122 
124  fsList.push_back(&sel);
125  return;
126 }
127 
129  int i;
130  int n;
131  n = msList.size();
132  for (i = 0; i < n; ++i) {
133  if (!msList[i]->accept(cand))
134  return false;
135  }
136  n = vsList.size();
137  for (i = 0; i < n; ++i) {
138  if (!vsList[i]->accept(cand))
139  return false;
140  }
141  n = fsList.size();
142  for (i = 0; i < n; ++i) {
143  if (!fsList[i]->accept(cand))
144  return false;
145  }
146  return true;
147 }
148 
150  minPDiff = pMin;
151  return;
152 }
153 
154 vector<BPHRecoBuilder::ComponentSet> BPHRecoBuilder::build() const {
155  daugMap.clear();
156  compMap.clear();
157  vector<ComponentSet> candList;
158  ComponentSet compSet;
159  build(candList, compSet, sourceList.begin(), sourceList.end(), srCompList.begin(), srCompList.end());
160  return candList;
161 }
162 
164 
165 bool BPHRecoBuilder::sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand, double minPDifference) {
166  const reco::Track* lrcTrack = BPHTrackReference::getFromRC(*lCand);
167  const reco::Track* rrcTrack = BPHTrackReference::getFromRC(*rCand);
168  const reco::Track* lpfTrack = BPHTrackReference::getFromPF(*lCand);
169  const reco::Track* rpfTrack = BPHTrackReference::getFromPF(*rCand);
170  if ((lrcTrack != nullptr) && ((lrcTrack == rrcTrack) || (lrcTrack == rpfTrack)))
171  return true;
172  if ((lpfTrack != nullptr) && ((lpfTrack == rrcTrack) || (lpfTrack == rpfTrack)))
173  return true;
174  reco::Candidate::Vector pDiff = (lCand->momentum() - rCand->momentum());
175  reco::Candidate::Vector pMean = (lCand->momentum() + rCand->momentum());
176  double pDMod = pDiff.mag2();
177  double pMMod = pMean.mag2();
178  if (((pDMod / pMMod) < minPDifference) && (lCand->charge() == rCand->charge()))
179  return true;
180  return false;
181 }
182 
183 void BPHRecoBuilder::add(const string& name, const BPHGenericCollection* collection, double mass, double msig) {
184  BPHRecoSource* rs;
185  if (sourceId.find(name) != sourceId.end()) {
186  edm::LogPrint("TooManyParticles") << "BPHRecoBuilder::add: "
187  << "Decay product already inserted with name " << name << " , skipped";
188  return;
189  }
190  rs = new BPHRecoSource;
191  rs->name = &sourceId.insert(make_pair(name, sourceList.size())).first->first;
192  rs->collection = collection;
193  rs->selector.reserve(5);
194  rs->mass = mass;
195  rs->msig = msig;
196  sourceList.push_back(rs);
197  return;
198 }
199 
200 void BPHRecoBuilder::add(const string& name, const vector<BPHRecoConstCandPtr>& collection) {
201  BPHCompSource* cs;
202  if (srCompId.find(name) != srCompId.end()) {
203  edm::LogPrint("TooManyParticles") << "BPHRecoBuilder::add: "
204  << "Decay product already inserted with name " << name << " , skipped";
205  return;
206  }
207  cs = new BPHCompSource;
208  cs->name = &srCompId.insert(make_pair(name, srCompList.size())).first->first;
209  cs->collection = &collection;
210  srCompList.push_back(cs);
211  return;
212 }
213 
214 void BPHRecoBuilder::build(vector<ComponentSet>& compList,
215  ComponentSet& compSet,
216  vector<BPHRecoSource*>::const_iterator r_iter,
217  vector<BPHRecoSource*>::const_iterator r_iend,
218  vector<BPHCompSource*>::const_iterator c_iter,
219  vector<BPHCompSource*>::const_iterator c_iend) const {
220  if (r_iter == r_iend) {
221  if (c_iter == c_iend) {
222  compSet.compMap = compMap;
223  compList.push_back(compSet);
224  return;
225  }
226  BPHCompSource* source = *c_iter++;
227  const vector<BPHRecoConstCandPtr>* collection = source->collection;
228  vector<const BPHMomentumSelect*> momSelector = source->momSelector;
229  vector<const BPHVertexSelect*> vtxSelector = source->vtxSelector;
230  vector<const BPHFitSelect*> fitSelector = source->fitSelector;
231  int i;
232  int j;
233  int n = collection->size();
234  int m;
235  bool skip;
236  for (i = 0; i < n; ++i) {
237  skip = false;
238  BPHRecoConstCandPtr cand = collection->at(i);
239  if (contained(compSet, cand))
240  continue;
241  m = momSelector.size();
242  for (j = 0; j < m; ++j) {
243  if (!momSelector[j]->accept(*cand))
244  skip = true;
245  }
246  m = vtxSelector.size();
247  for (j = 0; j < m; ++j) {
248  if (!vtxSelector[j]->accept(*cand))
249  skip = true;
250  }
251  m = fitSelector.size();
252  for (j = 0; j < m; ++j) {
253  if (!fitSelector[j]->accept(*cand))
254  skip = true;
255  }
256  if (skip)
257  continue;
258  compMap[*source->name] = cand;
259  build(compList, compSet, r_iter, r_iend, c_iter, c_iend);
260  compMap.erase(*source->name);
261  }
262  return;
263  }
264  BPHRecoSource* source = *r_iter++;
265  const BPHGenericCollection* collection = source->collection;
266  vector<const BPHRecoSelect*>& selector = source->selector;
267  int i;
268  int j;
269  int n = collection->size();
270  int m = selector.size();
271  bool skip;
272  for (i = 0; i < n; ++i) {
273  const reco::Candidate& cand = collection->get(i);
274  if (contained(compSet, &cand))
275  continue;
276  skip = false;
277  for (j = 0; j < m; ++j) {
278  if (!selector[j]->accept(cand, this))
279  skip = true;
280  }
281  if (skip)
282  continue;
284  comp.cand = &cand;
285  comp.mass = source->mass;
286  comp.msig = source->msig;
287  comp.searchList = collection->searchList();
288  compSet.daugMap[*source->name] = comp;
289  daugMap[*source->name] = &cand;
290  build(compList, compSet, r_iter, r_iend, c_iter, c_iend);
291  daugMap.erase(*source->name);
292  compSet.daugMap.erase(*source->name);
293  }
294  return;
295 }
296 
298  map<string, BPHDecayMomentum::Component>& dMap = compSet.daugMap;
299  map<string, BPHDecayMomentum::Component>::const_iterator d_iter;
300  map<string, BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
301  for (d_iter = dMap.begin(); d_iter != d_iend; ++d_iter) {
302  const reco::Candidate* cChk = d_iter->second.cand;
303  if (cand == cChk)
304  return true;
305  if (sameTrack(cand, cChk))
306  return true;
307  }
308  return false;
309 }
310 
312  map<string, BPHRecoConstCandPtr>::const_iterator c_iter;
313  map<string, BPHRecoConstCandPtr>::const_iterator c_iend = compMap.end();
314  const vector<const reco::Candidate*>& dCand = cCand->daughFull();
315  int j;
316  int m = dCand.size();
317  int k;
318  int l;
319  for (j = 0; j < m; ++j) {
320  const reco::Candidate* cand = cCand->originalReco(dCand[j]);
321  map<string, BPHDecayMomentum::Component>& dMap = compSet.daugMap;
322  map<string, BPHDecayMomentum::Component>::const_iterator d_iter;
323  map<string, BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
324  for (d_iter = dMap.begin(); d_iter != d_iend; ++d_iter) {
325  const reco::Candidate* cChk = d_iter->second.cand;
326  if (cand == cChk)
327  return true;
328  if (sameTrack(cand, cChk))
329  return true;
330  }
331 
332  for (c_iter = compMap.begin(); c_iter != c_iend; ++c_iter) {
333  const pair<string, BPHRecoConstCandPtr>& entry = *c_iter;
334  BPHRecoConstCandPtr cCChk = entry.second;
335  const vector<const reco::Candidate*>& dCChk = cCChk->daughFull();
336  l = dCChk.size();
337  for (k = 0; k < l; ++k) {
338  const reco::Candidate* cChk = cCChk->originalReco(dCChk[k]);
339  if (cand == cChk)
340  return true;
341  if (sameTrack(cand, cChk))
342  return true;
343  }
344  }
345  }
346 
347  return false;
348 }
349 
350 bool BPHRecoBuilder::sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand) const {
351  return sameTrack(lCand, rCand, minPDiff);
352 }
std::vector< const BPHRecoSelect * > selector
const reco::Candidate * cand
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
void setMinPDiffererence(double pMin)
static const reco::Track * getFromPF(const reco::Candidate &rc)
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
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
unique_ptr< ClusterSequence > cs
std::vector< const BPHFitSelect * > fsList
const std::vector< BPHRecoConstCandPtr > * collection
std::map< std::string, BPHDecayMomentum::Component > daugMap
const edm::EventSetup * evSetup
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
static const reco::Track * getFromRC(const reco::Candidate &rc)
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)
const std::string & searchList() const
std::vector< const BPHMomentumSelect * > momSelector
virtual Vector momentum() const =0
spatial momentum vector
virtual const reco::Candidate & get(int i) const =0
virtual int charge() const =0
electric charge
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)
std::map< std::string, int > srCompId
static std::string const source
Definition: EdmProvDump.cc:47
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
std::map< std::string, int > sourceId