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 using namespace std;
29 
30 //-------------------
31 // Initializations --
32 //-------------------
33 
34 //----------------
35 // Constructors --
36 //----------------
37 BPHRecoBuilder::BPHRecoBuilder(const edm::EventSetup& es) : evSetup(&es), minPDiff(-1.0) {
38  msList.reserve(5);
39  vsList.reserve(5);
40 }
41 
42 //--------------
43 // Destructor --
44 //--------------
46  int n = sourceList.size();
47  while (n--) {
48  delete sourceList[n]->collection;
49  delete sourceList[n];
50  }
51  int m = srCompList.size();
52  while (m--)
53  delete srCompList[m];
54  while (!compCollectList.empty()) {
55  const vector<BPHRecoConstCandPtr>* cCollection = *compCollectList.begin();
56  delete cCollection;
57  compCollectList.erase(cCollection);
58  }
59 }
60 
61 //--------------
62 // Operations --
63 //--------------
64 BPHRecoBuilder::BPHGenericCollection* BPHRecoBuilder::createCollection(const vector<const reco::Candidate*>& candList,
65  const string& list) {
66  return new BPHSpecificCollection<vector<const reco::Candidate*>>(candList, list);
67 }
68 
69 void BPHRecoBuilder::add(const string& name, const BPHGenericCollection* collection, double mass, double msig) {
70  BPHRecoSource* rs;
71  if (sourceId.find(name) != sourceId.end()) {
72  edm::LogPrint("TooManyParticles") << "BPHRecoBuilder::add: "
73  << "Decay product already inserted with name " << name << " , skipped";
74  return;
75  }
76  rs = new BPHRecoSource;
77  rs->name = &sourceId.insert(make_pair(name, sourceList.size())).first->first;
78  rs->collection = collection;
79  rs->selector.reserve(5);
80  rs->mass = mass;
81  rs->msig = msig;
82  sourceList.push_back(rs);
83  return;
84 }
85 
86 void BPHRecoBuilder::add(const string& name, const vector<BPHRecoConstCandPtr>& collection) {
87  BPHCompSource* cs;
88  if (srCompId.find(name) != srCompId.end()) {
89  edm::LogPrint("TooManyParticles") << "BPHRecoBuilder::add: "
90  << "Decay product already inserted with name " << name << " , skipped";
91  return;
92  }
93  cs = new BPHCompSource;
94  cs->name = &srCompId.insert(make_pair(name, srCompList.size())).first->first;
95  cs->collection = &collection;
96  srCompList.push_back(cs);
97  return;
98 }
99 
100 void BPHRecoBuilder::filter(const string& name, const BPHRecoSelect& sel) const {
101  map<string, int>::const_iterator iter = sourceId.find(name);
102  if (iter == sourceId.end())
103  return;
104  BPHRecoSource* rs = sourceList[iter->second];
105  rs->selector.push_back(&sel);
106  return;
107 }
108 
109 void BPHRecoBuilder::filter(const string& name, const BPHMomentumSelect& sel) const {
110  map<string, int>::const_iterator iter = srCompId.find(name);
111  if (iter == sourceId.end())
112  return;
113  BPHCompSource* cs = srCompList[iter->second];
114  cs->momSelector.push_back(&sel);
115  return;
116 }
117 
118 void BPHRecoBuilder::filter(const string& name, const BPHVertexSelect& sel) const {
119  map<string, int>::const_iterator iter = srCompId.find(name);
120  if (iter == sourceId.end())
121  return;
122  BPHCompSource* cs = srCompList[iter->second];
123  cs->vtxSelector.push_back(&sel);
124  return;
125 }
126 
127 void BPHRecoBuilder::filter(const string& name, const BPHFitSelect& sel) const {
128  map<string, int>::const_iterator iter = srCompId.find(name);
129  if (iter == sourceId.end())
130  return;
131  BPHCompSource* cs = srCompList[iter->second];
132  cs->fitSelector.push_back(&sel);
133  return;
134 }
135 
137  msList.push_back(&sel);
138  return;
139 }
140 
142  vsList.push_back(&sel);
143  return;
144 }
145 
147  fsList.push_back(&sel);
148  return;
149 }
150 
152  int i;
153  int n;
154  n = msList.size();
155  for (i = 0; i < n; ++i) {
156  if (!msList[i]->accept(cand))
157  return false;
158  }
159  n = vsList.size();
160  for (i = 0; i < n; ++i) {
161  if (!vsList[i]->accept(cand))
162  return false;
163  }
164  n = fsList.size();
165  for (i = 0; i < n; ++i) {
166  if (!fsList[i]->accept(cand))
167  return false;
168  }
169  return true;
170 }
171 
173  minPDiff = pMin;
174  return;
175 }
176 
177 vector<BPHRecoBuilder::ComponentSet> BPHRecoBuilder::build() const {
178  daugMap.clear();
179  compMap.clear();
180  vector<ComponentSet> candList;
181  ComponentSet compSet;
182  build(candList, compSet, sourceList.begin(), sourceList.end(), srCompList.begin(), srCompList.end());
183  return candList;
184 }
185 
187 
188 bool BPHRecoBuilder::sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand, double minPDifference) {
189  const reco::Track* lrcTrack = BPHTrackReference::getFromRC(*lCand);
190  const reco::Track* rrcTrack = BPHTrackReference::getFromRC(*rCand);
191  const reco::Track* lpfTrack = BPHTrackReference::getFromPF(*lCand);
192  const reco::Track* rpfTrack = BPHTrackReference::getFromPF(*rCand);
193  if ((lrcTrack != nullptr) && ((lrcTrack == rrcTrack) || (lrcTrack == rpfTrack)))
194  return true;
195  if ((lpfTrack != nullptr) && ((lpfTrack == rrcTrack) || (lpfTrack == rpfTrack)))
196  return true;
197  reco::Candidate::Vector pDiff = (lCand->momentum() - rCand->momentum());
198  reco::Candidate::Vector pMean = (lCand->momentum() + rCand->momentum());
199  double pDMod = pDiff.mag2();
200  double pMMod = pMean.mag2();
201  if (((pDMod / pMMod) < minPDifference) && (lCand->charge() == rCand->charge()))
202  return true;
203  return false;
204 }
205 
206 void BPHRecoBuilder::build(vector<ComponentSet>& compList,
207  ComponentSet& compSet,
208  vector<BPHRecoSource*>::const_iterator r_iter,
209  vector<BPHRecoSource*>::const_iterator r_iend,
210  vector<BPHCompSource*>::const_iterator c_iter,
211  vector<BPHCompSource*>::const_iterator c_iend) const {
212  if (r_iter == r_iend) {
213  if (c_iter == c_iend) {
214  compSet.compMap = compMap;
215  compList.push_back(compSet);
216  return;
217  }
218  BPHCompSource* source = *c_iter++;
219  const vector<BPHRecoConstCandPtr>* collection = source->collection;
220  vector<const BPHMomentumSelect*> momSelector = source->momSelector;
221  vector<const BPHVertexSelect*> vtxSelector = source->vtxSelector;
222  vector<const BPHFitSelect*> fitSelector = source->fitSelector;
223  int i;
224  int j;
225  int n = collection->size();
226  int m;
227  bool skip;
228  for (i = 0; i < n; ++i) {
229  skip = false;
231  if (contained(compSet, cand))
232  continue;
233  m = momSelector.size();
234  for (j = 0; j < m; ++j) {
235  if (!momSelector[j]->accept(*cand)) {
236  skip = true;
237  break;
238  }
239  }
240  if (skip)
241  continue;
242  m = vtxSelector.size();
243  for (j = 0; j < m; ++j) {
244  if (!vtxSelector[j]->accept(*cand)) {
245  skip = true;
246  break;
247  }
248  }
249  if (skip)
250  continue;
251  m = fitSelector.size();
252  for (j = 0; j < m; ++j) {
253  if (!fitSelector[j]->accept(*cand)) {
254  skip = true;
255  break;
256  }
257  }
258  if (skip)
259  continue;
260  compMap[*source->name] = cand;
261  build(compList, compSet, r_iter, r_iend, c_iter, c_iend);
262  compMap.erase(*source->name);
263  }
264  return;
265  }
266  BPHRecoSource* source = *r_iter++;
267  const BPHGenericCollection* collection = source->collection;
268  vector<const BPHRecoSelect*>& selector = source->selector;
269  int i;
270  int j;
271  int n = collection->size();
272  int m = selector.size();
273  bool skip;
274  for (i = 0; i < n; ++i) {
275  const reco::Candidate& cand = collection->get(i);
276  if (contained(compSet, &cand))
277  continue;
278  skip = false;
279  for (j = 0; j < m; ++j) {
280  if (!selector[j]->accept(cand, this)) {
281  skip = true;
282  break;
283  }
284  }
285  if (skip)
286  continue;
288  comp.cand = &cand;
289  comp.mass = source->mass;
290  comp.msig = source->msig;
291  comp.searchList = collection->searchList();
292  compSet.daugMap[*source->name] = comp;
293  daugMap[*source->name] = &cand;
294  build(compList, compSet, r_iter, r_iend, c_iter, c_iend);
295  daugMap.erase(*source->name);
296  compSet.daugMap.erase(*source->name);
297  }
298  return;
299 }
300 
302  map<string, BPHDecayMomentum::Component>& dMap = compSet.daugMap;
303  map<string, BPHDecayMomentum::Component>::const_iterator d_iter;
304  map<string, BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
305  for (d_iter = dMap.begin(); d_iter != d_iend; ++d_iter) {
306  const reco::Candidate* cChk = d_iter->second.cand;
307  if (cand == cChk)
308  return true;
309  if (sameTrack(cand, cChk))
310  return true;
311  }
312  return false;
313 }
314 
316  map<string, BPHRecoConstCandPtr>::const_iterator c_iter;
317  map<string, BPHRecoConstCandPtr>::const_iterator c_iend = compMap.end();
318  const vector<const reco::Candidate*>& dCand = cCand->daughFull();
319  int j;
320  int m = dCand.size();
321  int k;
322  int l;
323  for (j = 0; j < m; ++j) {
324  const reco::Candidate* cand = cCand->originalReco(dCand[j]);
325  map<string, BPHDecayMomentum::Component>& dMap = compSet.daugMap;
326  map<string, BPHDecayMomentum::Component>::const_iterator d_iter;
327  map<string, BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
328  for (d_iter = dMap.begin(); d_iter != d_iend; ++d_iter) {
329  const reco::Candidate* cChk = d_iter->second.cand;
330  if (cand == cChk)
331  return true;
332  if (sameTrack(cand, cChk))
333  return true;
334  }
335 
336  for (c_iter = compMap.begin(); c_iter != c_iend; ++c_iter) {
337  const pair<string, BPHRecoConstCandPtr>& entry = *c_iter;
338  BPHRecoConstCandPtr cCChk = entry.second;
339  const vector<const reco::Candidate*>& dCChk = cCChk->daughFull();
340  l = dCChk.size();
341  for (k = 0; k < l; ++k) {
342  const reco::Candidate* cChk = cCChk->originalReco(dCChk[k]);
343  if (cand == cChk)
344  return true;
345  if (sameTrack(cand, cChk))
346  return true;
347  }
348  }
349  }
350 
351  return false;
352 }
353 
354 bool BPHRecoBuilder::sameTrack(const reco::Candidate* lCand, const reco::Candidate* rCand) const {
355  return sameTrack(lCand, rCand, minPDiff);
356 }
BPHRecoBuilder::filter
void filter(const std::string &name, const BPHRecoSelect &sel) const
BPHFitSelect.h
BPHFitSelect
Definition: BPHFitSelect.h:29
BPHTrackReference.h
reco::Candidate::Vector
math::XYZVector Vector
point in the space
Definition: Candidate.h:42
mps_fire.i
i
Definition: mps_fire.py:428
BPHRecoSelect
Definition: BPHRecoSelect.h:35
MessageLogger.h
BPHRecoBuilder::srCompList
std::vector< BPHCompSource * > srCompList
Definition: BPHRecoBuilder.h:193
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
BPHRecoBuilder::evSetup
const edm::EventSetup * evSetup
Definition: BPHRecoBuilder.h:188
BPHRecoBuilder::BPHRecoBuilder
BPHRecoBuilder(const edm::EventSetup &es)
Definition: BPHRecoBuilder.cc:37
mps_splice.entry
entry
Definition: mps_splice.py:68
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
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
BPHRecoBuilder::sameTrack
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
Definition: BPHRecoBuilder.cc:188
BPHRecoSelect.h
BPHMomentumSelect
Definition: BPHMomentumSelect.h:29
BPHRecoBuilder::~BPHRecoBuilder
virtual ~BPHRecoBuilder()
Definition: BPHRecoBuilder.cc:45
BPHRecoBuilder::createCollection
static BPHGenericCollection * createCollection(const edm::Handle< T > &collection, const std::string &list="cfhpmig")
Definition: BPHRecoBuilder.h:228
BPHRecoBuilder::sourceId
std::map< std::string, int > sourceId
Definition: BPHRecoBuilder.h:205
RecoCandidate.h
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
BPHRecoBuilder::build
std::vector< ComponentSet > build() const
build a set of combinations of particles fulfilling the selections
Definition: BPHRecoBuilder.cc:177
optionsL1T.skip
skip
Definition: optionsL1T.py:30
reco::Candidate::charge
virtual int charge() const =0
electric charge
BPHRecoBuilder::msList
std::vector< const BPHMomentumSelect * > msList
Definition: BPHRecoBuilder.h:200
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
BPHRecoBuilder::minPDiff
double minPDiff
Definition: BPHRecoBuilder.h:189
BPHTrackReference::getFromRC
static const reco::Track * getFromRC(const reco::Candidate &rc)
Definition: BPHTrackReference.h:126
source
static const std::string source
Definition: EdmProvDump.cc:47
reco::Track
Definition: Track.h:27
BPHRecoBuilder::daugMap
std::map< std::string, const reco::Candidate * > daugMap
Definition: BPHRecoBuilder.h:185
dqmdumpme.k
k
Definition: dqmdumpme.py:60
BPHRecoBuilder::setMinPDiffererence
void setMinPDiffererence(double pMin)
Definition: BPHRecoBuilder.cc:172
BPHRecoBuilder::ComponentSet
Definition: BPHRecoBuilder.h:127
BPHRecoBuilder::eventSetup
const edm::EventSetup * eventSetup() const
get the EventSetup set in the constructor
Definition: BPHRecoBuilder.cc:186
reco::Candidate::momentum
virtual Vector momentum() const =0
spatial momentum vector
ALCARECOTkAlMinBias_cff.pMin
pMin
GeV.
Definition: ALCARECOTkAlMinBias_cff.py:35
BPHMomentumSelect.h
cand
Definition: decayParser.h:32
BPHRecoBuilder::fsList
std::vector< const BPHFitSelect * > fsList
Definition: BPHRecoBuilder.h:202
BPHDecayMomentum::Component
Definition: BPHDecayMomentum.h:101
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
edm::EventSetup
Definition: EventSetup.h:58
BPHRecoBuilder.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
reco::Candidate
Definition: Candidate.h:27
BPHVertexSelect.h
BPHRecoBuilder::ComponentSet::compMap
std::map< std::string, BPHRecoConstCandPtr > compMap
Definition: BPHRecoBuilder.h:129
BPHRecoBuilder::BPHGenericCollection
Definition: BPHRecoBuilder.h:70
std
Definition: JetResolutionObject.h:76
BPHRecoBuilder::compMap
std::map< std::string, BPHRecoConstCandPtr > compMap
Definition: BPHRecoBuilder.h:186
BPHRecoBuilder::BPHRecoSource
Definition: BPHRecoBuilder.h:165
BPHRecoCandidate.h
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
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
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
BPHRecoCandidate
Definition: BPHRecoCandidate.h:46
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
BPHRecoBuilder::srCompId
std::map< std::string, int > srCompId
Definition: BPHRecoBuilder.h:206
BPHRecoConstCandPtr
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
Definition: BPHRecoCandidatePtr.h:9
BPHTrackReference::getFromPF
static const reco::Track * getFromPF(const reco::Candidate &rc)
Definition: BPHTrackReference.h:135