CMS 3D CMS Logo

MuonSeedOrcaPatternRecognition.cc
Go to the documentation of this file.
1 
12 
20 
23 
24 // Geometry
27 
28 // Framework
34 
35 // C++
36 #include <vector>
37 
38 using namespace std;
39 
40 const std::string metname = "Muon|RecoMuon|MuonSeedOrcaPatternRecognition";
41 
42 // Constructor
46  theCrackEtas(pset.getParameter<std::vector<double> >("crackEtas")),
47  theCrackWindow(pset.getParameter<double>("crackWindow")),
48  theDeltaPhiWindow(
49  pset.existsAs<double>("deltaPhiSearchWindow") ? pset.getParameter<double>("deltaPhiSearchWindow") : 0.25),
50  theDeltaEtaWindow(
51  pset.existsAs<double>("deltaEtaSearchWindow") ? pset.getParameter<double>("deltaEtaSearchWindow") : 0.2),
52  theDeltaCrackWindow(pset.existsAs<double>("deltaEtaCrackSearchWindow")
53  ? pset.getParameter<double>("deltaEtaCrackSearchWindow")
54  : 0.25),
58  edm::InputTag(),
59  edm::InputTag(),
61  iC,
64  false,
65  false,
67 }
68 
69 // reconstruct muon's seeds
71  const edm::EventSetup& eSetup,
72  std::vector<MuonRecHitContainer>& result) {
73  // divide the RecHits by DetLayer, in order to fill the
74  // RecHitContainer like it was in ORCA
75 
76  // Muon Geometry - DT, CSC, RPC and ME0
78 
79  // get the DT layers
80  vector<const DetLayer*> dtLayers = muonLayers->allDTLayers();
81 
82  // get the CSC layers
83  vector<const DetLayer*> cscForwardLayers = muonLayers->forwardCSCLayers();
84  vector<const DetLayer*> cscBackwardLayers = muonLayers->backwardCSCLayers();
85 
86  // get the ME0 layers
87  vector<const DetLayer*> me0ForwardLayers = muonLayers->forwardME0Layers();
88  vector<const DetLayer*> me0BackwardLayers = muonLayers->backwardME0Layers();
89 
90  // Backward (z<0) EndCap disk
91  const DetLayer* ME4Bwd = cscBackwardLayers[4];
92  const DetLayer* ME3Bwd = cscBackwardLayers[3];
93  const DetLayer* ME2Bwd = cscBackwardLayers[2];
94  const DetLayer* ME12Bwd = cscBackwardLayers[1];
95  const DetLayer* ME11Bwd = cscBackwardLayers[0];
96 
97  // Forward (z>0) EndCap disk
98  const DetLayer* ME11Fwd = cscForwardLayers[0];
99  const DetLayer* ME12Fwd = cscForwardLayers[1];
100  const DetLayer* ME2Fwd = cscForwardLayers[2];
101  const DetLayer* ME3Fwd = cscForwardLayers[3];
102  const DetLayer* ME4Fwd = cscForwardLayers[4];
103 
104  // barrel
105  const DetLayer* MB4DL = dtLayers[3];
106  const DetLayer* MB3DL = dtLayers[2];
107  const DetLayer* MB2DL = dtLayers[1];
108  const DetLayer* MB1DL = dtLayers[0];
109 
110  // instantiate the accessor
111  // Don not use RPC for seeding
112 
113  double barreldThetaCut = 0.2;
114  // still lose good muons to a tighter cut
115  double endcapdThetaCut = 1.0;
116 
117  MuonRecHitContainer list9 = filterSegments(muonMeasurements->recHits(MB4DL, event), barreldThetaCut);
118  MuonRecHitContainer list6 = filterSegments(muonMeasurements->recHits(MB3DL, event), barreldThetaCut);
119  MuonRecHitContainer list7 = filterSegments(muonMeasurements->recHits(MB2DL, event), barreldThetaCut);
120  MuonRecHitContainer list8 = filterSegments(muonMeasurements->recHits(MB1DL, event), barreldThetaCut);
121 
122  dumpLayer("MB4 ", list9);
123  dumpLayer("MB3 ", list6);
124  dumpLayer("MB2 ", list7);
125  dumpLayer("MB1 ", list8);
126 
127  bool* MB1 = zero(list8.size());
128  bool* MB2 = zero(list7.size());
129  bool* MB3 = zero(list6.size());
130 
131  MuonRecHitContainer muRH_ME0Fwd, muRH_ME0Bwd;
132 
133  if (!me0ForwardLayers.empty()) { // Forward (z>0) EndCap disk
134  const DetLayer* ME0Fwd = me0ForwardLayers[0];
135  muRH_ME0Fwd = filterSegments(muonMeasurements->recHits(ME0Fwd, event), endcapdThetaCut);
136  }
137  if (!me0BackwardLayers.empty()) { // Backward (z<0) EndCap disk
138  const DetLayer* ME0Bwd = me0BackwardLayers[0];
139  muRH_ME0Bwd = filterSegments(muonMeasurements->recHits(ME0Bwd, event), endcapdThetaCut);
140  }
141 
142  endcapPatterns(filterSegments(muonMeasurements->recHits(ME11Bwd, event), endcapdThetaCut),
143  filterSegments(muonMeasurements->recHits(ME12Bwd, event), endcapdThetaCut),
144  filterSegments(muonMeasurements->recHits(ME2Bwd, event), endcapdThetaCut),
145  filterSegments(muonMeasurements->recHits(ME3Bwd, event), endcapdThetaCut),
146  filterSegments(muonMeasurements->recHits(ME4Bwd, event), endcapdThetaCut),
147  muRH_ME0Bwd,
148  list8,
149  list7,
150  list6,
151  MB1,
152  MB2,
153  MB3,
154  result);
155 
156  endcapPatterns(filterSegments(muonMeasurements->recHits(ME11Fwd, event), endcapdThetaCut),
157  filterSegments(muonMeasurements->recHits(ME12Fwd, event), endcapdThetaCut),
158  filterSegments(muonMeasurements->recHits(ME2Fwd, event), endcapdThetaCut),
159  filterSegments(muonMeasurements->recHits(ME3Fwd, event), endcapdThetaCut),
160  filterSegments(muonMeasurements->recHits(ME4Fwd, event), endcapdThetaCut),
161  muRH_ME0Fwd,
162  list8,
163  list7,
164  list6,
165  MB1,
166  MB2,
167  MB3,
168  result);
169 
170  // ---------- Barrel only
171 
172  unsigned int counter = 0;
173  if (list9.size() < 100) { // +v
174  for (MuonRecHitContainer::iterator iter = list9.begin(); iter != list9.end(); iter++) {
175  MuonRecHitContainer seedSegments;
176  seedSegments.push_back(*iter);
177  complete(seedSegments, list6, MB3);
178  complete(seedSegments, list7, MB2);
179  complete(seedSegments, list8, MB1);
180  if (check(seedSegments))
181  result.push_back(seedSegments);
182  }
183  }
184 
185  if (list6.size() < 100) { // +v
186  for (counter = 0; counter < list6.size(); counter++) {
187  if (!MB3[counter]) {
188  MuonRecHitContainer seedSegments;
189  seedSegments.push_back(list6[counter]);
190  complete(seedSegments, list7, MB2);
191  complete(seedSegments, list8, MB1);
192  complete(seedSegments, list9);
193  if (check(seedSegments))
194  result.push_back(seedSegments);
195  }
196  }
197  }
198 
199  if (list7.size() < 100) { // +v
200  for (counter = 0; counter < list7.size(); counter++) {
201  if (!MB2[counter]) {
202  MuonRecHitContainer seedSegments;
203  seedSegments.push_back(list7[counter]);
204  complete(seedSegments, list8, MB1);
205  complete(seedSegments, list9);
206  complete(seedSegments, list6, MB3);
207  if (seedSegments.size() > 1 || (seedSegments.size() == 1 && seedSegments[0]->dimension() == 4)) {
208  result.push_back(seedSegments);
209  }
210  }
211  }
212  }
213 
214  if (list8.size() < 100) { // +v
215  for (counter = 0; counter < list8.size(); counter++) {
216  if (!MB1[counter]) {
217  MuonRecHitContainer seedSegments;
218  seedSegments.push_back(list8[counter]);
219  complete(seedSegments, list9);
220  complete(seedSegments, list6, MB3);
221  complete(seedSegments, list7, MB2);
222  if (seedSegments.size() > 1 || (seedSegments.size() == 1 && seedSegments[0]->dimension() == 4)) {
223  result.push_back(seedSegments);
224  }
225  }
226  }
227  }
228 
229  if (MB3)
230  delete[] MB3;
231  if (MB2)
232  delete[] MB2;
233  if (MB1)
234  delete[] MB1;
235 
236  if (result.empty()) {
237  // be a little stricter with single segment seeds
238  barreldThetaCut = 0.2;
239  endcapdThetaCut = 0.2;
240 
242  MuonRecHitContainer tmp = filterSegments(muonMeasurements->recHits(ME3Bwd, event), endcapdThetaCut);
243  copy(tmp.begin(), tmp.end(), back_inserter(all));
244 
245  tmp = filterSegments(muonMeasurements->recHits(ME2Bwd, event), endcapdThetaCut);
246  copy(tmp.begin(), tmp.end(), back_inserter(all));
247 
248  tmp = filterSegments(muonMeasurements->recHits(ME12Bwd, event), endcapdThetaCut);
249  copy(tmp.begin(), tmp.end(), back_inserter(all));
250 
251  tmp = filterSegments(muonMeasurements->recHits(ME11Bwd, event), endcapdThetaCut);
252  copy(tmp.begin(), tmp.end(), back_inserter(all));
253 
254  if (!me0BackwardLayers.empty()) {
255  const DetLayer* ME0Bwd = me0BackwardLayers[0];
256  tmp = filterSegments(muonMeasurements->recHits(ME0Bwd, event), endcapdThetaCut);
257  copy(tmp.begin(), tmp.end(), back_inserter(all));
258  }
259  if (!me0ForwardLayers.empty()) {
260  const DetLayer* ME0Fwd = me0ForwardLayers[0];
261  tmp = filterSegments(muonMeasurements->recHits(ME0Fwd, event), endcapdThetaCut);
262  copy(tmp.begin(), tmp.end(), back_inserter(all));
263  }
264 
265  tmp = filterSegments(muonMeasurements->recHits(ME11Fwd, event), endcapdThetaCut);
266  copy(tmp.begin(), tmp.end(), back_inserter(all));
267 
268  tmp = filterSegments(muonMeasurements->recHits(ME12Fwd, event), endcapdThetaCut);
269  copy(tmp.begin(), tmp.end(), back_inserter(all));
270 
271  tmp = filterSegments(muonMeasurements->recHits(ME2Fwd, event), endcapdThetaCut);
272  copy(tmp.begin(), tmp.end(), back_inserter(all));
273 
274  tmp = filterSegments(muonMeasurements->recHits(ME3Fwd, event), endcapdThetaCut);
275  copy(tmp.begin(), tmp.end(), back_inserter(all));
276 
277  tmp = filterSegments(muonMeasurements->recHits(ME4Fwd, event), endcapdThetaCut);
278  copy(tmp.begin(), tmp.end(), back_inserter(all));
279 
280  tmp = filterSegments(muonMeasurements->recHits(MB4DL, event), barreldThetaCut);
281  copy(tmp.begin(), tmp.end(), back_inserter(all));
282 
283  tmp = filterSegments(muonMeasurements->recHits(MB3DL, event), barreldThetaCut);
284  copy(tmp.begin(), tmp.end(), back_inserter(all));
285 
286  tmp = filterSegments(muonMeasurements->recHits(MB2DL, event), barreldThetaCut);
287  copy(tmp.begin(), tmp.end(), back_inserter(all));
288 
289  tmp = filterSegments(muonMeasurements->recHits(MB1DL, event), barreldThetaCut);
290  copy(tmp.begin(), tmp.end(), back_inserter(all));
291 
292  LogTrace(metname) << "Number of segments: " << all.size();
293 
294  for (MuonRecHitContainer::const_iterator segmentItr = all.begin(); segmentItr != all.end(); ++segmentItr) {
295  MuonRecHitContainer singleSegmentContainer;
296  singleSegmentContainer.push_back(*segmentItr);
297  result.push_back(singleSegmentContainer);
298  }
299  }
300 }
301 
302 bool* MuonSeedOrcaPatternRecognition::zero(unsigned listSize) {
303  bool* result = nullptr;
304  if (listSize) {
305  result = new bool[listSize];
306  for (size_t i = 0; i < listSize; i++)
307  result[i] = false;
308  }
309  return result;
310 }
311 
313  const MuonRecHitContainer& me12,
314  const MuonRecHitContainer& me2,
315  const MuonRecHitContainer& me3,
316  const MuonRecHitContainer& me4,
317  const MuonRecHitContainer& me0,
318  const MuonRecHitContainer& mb1,
319  const MuonRecHitContainer& mb2,
320  const MuonRecHitContainer& mb3,
321  bool* MB1,
322  bool* MB2,
323  bool* MB3,
324  std::vector<MuonRecHitContainer>& result) {
325  dumpLayer("ME4 ", me4);
326  dumpLayer("ME3 ", me3);
327  dumpLayer("ME2 ", me2);
328  dumpLayer("ME12 ", me12);
329  dumpLayer("ME11 ", me11);
330  dumpLayer("ME0 ", me0);
331 
332  std::vector<MuonRecHitContainer> patterns;
333  MuonRecHitContainer crackSegments;
334  rememberCrackSegments(me11, crackSegments);
335  rememberCrackSegments(me12, crackSegments);
336  rememberCrackSegments(me2, crackSegments);
337  rememberCrackSegments(me3, crackSegments);
338  rememberCrackSegments(me4, crackSegments);
339  rememberCrackSegments(me0, crackSegments);
340 
341  const MuonRecHitContainer& list24 = me4;
342  const MuonRecHitContainer& list23 = me3;
343 
344  const MuonRecHitContainer& list12 = me2;
345 
346  const MuonRecHitContainer& list22 = me12;
347  MuonRecHitContainer list21 = me11;
348  // add ME0 to ME1
349  list21.reserve(list21.size() + me0.size());
350  copy(me0.begin(), me0.end(), back_inserter(list21));
351 
352  MuonRecHitContainer list11 = list21;
353  MuonRecHitContainer list5 = list22;
354  MuonRecHitContainer list13 = list23;
355  MuonRecHitContainer list4 = list24;
356 
357  if (list21.empty()) {
358  list11 = list22;
359  list5 = list21;
360  }
361 
362  if (list24.size() < list23.size() && !list24.empty()) {
363  list13 = list24;
364  list4 = list23;
365  }
366 
367  if (list23.empty()) {
368  list13 = list24;
369  list4 = list23;
370  }
371 
372  MuonRecHitContainer list1 = list11;
373  MuonRecHitContainer list2 = list12;
374  MuonRecHitContainer list3 = list13;
375 
376  if (list12.empty()) {
377  list3 = list12;
378  if (list11.size() <= list13.size() && !list11.empty()) {
379  list1 = list11;
380  list2 = list13;
381  } else {
382  list1 = list13;
383  list2 = list11;
384  }
385  }
386 
387  if (list13.empty()) {
388  if (list11.size() <= list12.size() && !list11.empty()) {
389  list1 = list11;
390  list2 = list12;
391  } else {
392  list1 = list12;
393  list2 = list11;
394  }
395  }
396 
397  if (!list12.empty() && !list13.empty()) {
398  if (list11.size() <= list12.size() && list11.size() <= list13.size() && !list11.empty()) { // ME 1
399  if (list12.size() > list13.size()) {
400  list2 = list13;
401  list3 = list12;
402  }
403  } else if (list12.size() <= list13.size()) { // start with ME 2
404  list1 = list12;
405  if (list11.size() <= list13.size() && !list11.empty()) {
406  list2 = list11;
407  list3 = list13;
408  } else {
409  list2 = list13;
410  list3 = list11;
411  }
412  } else { // start with ME 3
413  list1 = list13;
414  if (list11.size() <= list12.size() && !list11.empty()) {
415  list2 = list11;
416  list3 = list12;
417  } else {
418  list2 = list12;
419  list3 = list11;
420  }
421  }
422  }
423 
424  bool* ME2 = zero(list2.size());
425  bool* ME3 = zero(list3.size());
426  bool* ME4 = zero(list4.size());
427  bool* ME5 = zero(list5.size());
428 
429  // creates list of compatible track segments
430  for (MuonRecHitContainer::iterator iter = list1.begin(); iter != list1.end(); iter++) {
431  if ((*iter)->recHits().size() < 4 && !list3.empty())
432  continue; // 3p.tr-seg. are not so good for starting
433 
434  MuonRecHitContainer seedSegments;
435  seedSegments.push_back(*iter);
436  complete(seedSegments, list2, ME2);
437  complete(seedSegments, list3, ME3);
438  complete(seedSegments, list4, ME4);
439  complete(seedSegments, list5, ME5);
440  complete(seedSegments, mb3, MB3);
441  complete(seedSegments, mb2, MB2);
442  complete(seedSegments, mb1, MB1);
443  if (check(seedSegments))
444  patterns.push_back(seedSegments);
445  }
446 
447  unsigned int counter;
448 
449  for (counter = 0; counter < list2.size(); counter++) {
450  if (!ME2[counter]) {
451  MuonRecHitContainer seedSegments;
452  seedSegments.push_back(list2[counter]);
453  complete(seedSegments, list3, ME3);
454  complete(seedSegments, list4, ME4);
455  complete(seedSegments, list5, ME5);
456  complete(seedSegments, mb3, MB3);
457  complete(seedSegments, mb2, MB2);
458  complete(seedSegments, mb1, MB1);
459  if (check(seedSegments))
460  patterns.push_back(seedSegments);
461  }
462  }
463 
464  if (list3.size() < 20) { // +v
465  for (counter = 0; counter < list3.size(); counter++) {
466  if (!ME3[counter]) {
467  MuonRecHitContainer seedSegments;
468  seedSegments.push_back(list3[counter]);
469  complete(seedSegments, list4, ME4);
470  complete(seedSegments, list5, ME5);
471  complete(seedSegments, mb3, MB3);
472  complete(seedSegments, mb2, MB2);
473  complete(seedSegments, mb1, MB1);
474  if (check(seedSegments))
475  patterns.push_back(seedSegments);
476  }
477  }
478  }
479 
480  if (list4.size() < 20) { // +v
481  for (counter = 0; counter < list4.size(); counter++) {
482  if (!ME4[counter]) {
483  MuonRecHitContainer seedSegments;
484  seedSegments.push_back(list4[counter]);
485  complete(seedSegments, list5, ME5);
486  complete(seedSegments, mb3, MB3);
487  complete(seedSegments, mb2, MB2);
488  complete(seedSegments, mb1, MB1);
489  if (check(seedSegments))
490  patterns.push_back(seedSegments);
491  }
492  }
493  }
494 
495  if (ME5)
496  delete[] ME5;
497  if (ME4)
498  delete[] ME4;
499  if (ME3)
500  delete[] ME3;
501  if (ME2)
502  delete[] ME2;
503 
504  if (!patterns.empty()) {
505  result.insert(result.end(), patterns.begin(), patterns.end());
506  } else {
507  if (!crackSegments.empty()) {
508  // make some single-segment seeds
509  for (MuonRecHitContainer::const_iterator crackSegmentItr = crackSegments.begin();
510  crackSegmentItr != crackSegments.end();
511  ++crackSegmentItr) {
512  MuonRecHitContainer singleSegmentPattern;
513  singleSegmentPattern.push_back(*crackSegmentItr);
514  result.push_back(singleSegmentPattern);
515  }
516  }
517  }
518 }
519 
522  bool* used) const {
523  MuonRecHitContainer good_rhit;
524  MuonPatternRecoDumper theDumper;
525  //+v get all rhits compatible with the seed on dEta/dPhi Glob.
526  ConstMuonRecHitPointer first = seedSegments[0]; // first rechit of seed
527  GlobalPoint ptg2 = first->globalPosition(); // its global pos +v
528  for (unsigned nr = 0; nr < recHits.size(); ++nr) {
530  GlobalPoint ptg1(recHit->globalPosition());
531  float deta = fabs(ptg1.eta() - ptg2.eta());
532  // Geom::Phi should keep it in the range [-pi, pi]
533  float dphi = fabs(deltaPhi(ptg1.barePhi(), ptg2.barePhi()));
534  // be a little more lenient in cracks
535  bool crack = isCrack(recHit) || isCrack(first);
536  //float detaWindow = 0.3;
537  float detaWindow = crack ? theDeltaCrackWindow : theDeltaEtaWindow;
538  if (deta > detaWindow || dphi > theDeltaPhiWindow) {
539  continue;
540  } // +vvp!!!
541 
542  good_rhit.push_back(recHit);
543  if (used)
544  markAsUsed(nr, recHits, used);
545  } // recHits iter
546 
547  // select the best rhit among the compatible ones (based on Dphi Glob & Dir)
548  MuonRecHitPointer best = bestMatch(first, good_rhit);
549  if (best && best->isValid())
550  seedSegments.push_back(best);
551 }
552 
554  const ConstMuonRecHitPointer& first, MuonRecHitContainer& good_rhit) const {
555  MuonRecHitPointer best = nullptr;
556  if (good_rhit.size() == 1)
557  return good_rhit[0];
558  double bestDiscrim = 10000.;
559  for (MuonRecHitContainer::iterator iter = good_rhit.begin(); iter != good_rhit.end(); iter++) {
560  double discrim = discriminator(first, *iter);
561  if (discrim < bestDiscrim) {
562  bestDiscrim = discrim;
563  best = *iter;
564  }
565  }
566  return best;
567 }
568 
570  MuonRecHitPointer& other) const {
571  GlobalPoint gp1 = first->globalPosition();
572  GlobalPoint gp2 = other->globalPosition();
573  GlobalVector gd1 = first->globalDirection();
574  GlobalVector gd2 = other->globalDirection();
575  if (first->isDT() || other->isDT()) {
576  return fabs(deltaPhi(gd1.barePhi(), gd2.barePhi()));
577  }
578 
579  // penalize those 3-hit segments
580  int nhits = other->recHits().size();
581  int penalty = std::max(nhits - 2, 1);
582  float dphig = deltaPhi(gp1.barePhi(), gp2.barePhi());
583  // ME1A has slanted wires, so matching theta position doesn't work well.
584  if (isME1A(first) || isME1A(other)) {
585  return fabs(dphig / penalty);
586  }
587 
588  float dthetag = gp1.theta() - gp2.theta();
589  float dphid2 = fabs(deltaPhi(gd2.barePhi(), gp2.barePhi()));
590  if (dphid2 > M_PI * .5)
591  dphid2 = M_PI - dphid2; //+v
592  float dthetad2 = gp2.theta() - gd2.theta();
593  // for CSC, make a big chi-squared of relevant variables
594  // FIXME for 100 GeV mnd above muons, this doesn't perform as well as
595  // previous methods. needs investigation.
596  float chisq = ((dphig / 0.02) * (dphig / 0.02) + (dthetag / 0.003) * (dthetag / 0.003) +
597  (dphid2 / 0.06) * (dphid2 / 0.06) + (dthetad2 / 0.08) * (dthetad2 / 0.08));
598  return chisq / penalty;
599 }
600 
601 bool MuonSeedOrcaPatternRecognition::check(const MuonRecHitContainer& segments) { return (segments.size() > 1); }
602 
604  used[nr] = true;
605  // if it's ME1A with two other segments in the container, mark the ghosts as used, too.
606  if (recHits[nr]->isCSC()) {
607  CSCDetId detId(recHits[nr]->geographicalId().rawId());
608  if (detId.ring() == 4) {
609  std::vector<unsigned> chamberHitNs;
610  for (unsigned i = 0; i < recHits.size(); ++i) {
611  if (recHits[i]->geographicalId().rawId() == detId.rawId()) {
612  chamberHitNs.push_back(i);
613  }
614  }
615  if (chamberHitNs.size() == 3) {
616  for (unsigned i = 0; i < 3; ++i) {
617  used[chamberHitNs[i]] = true;
618  }
619  }
620  }
621  }
622 }
623 
625  bool result = false;
626  double absEta = fabs(segment->globalPosition().eta());
627  for (std::vector<double>::const_iterator crackItr = theCrackEtas.begin(); crackItr != theCrackEtas.end();
628  ++crackItr) {
629  if (fabs(absEta - *crackItr) < theCrackWindow) {
630  result = true;
631  }
632  }
633  return result;
634 }
635 
637  MuonRecHitContainer& crackSegments) const {
638  for (MuonRecHitContainer::const_iterator segmentItr = segments.begin(); segmentItr != segments.end(); ++segmentItr) {
639  if ((**segmentItr).hit()->dimension() == 4 && isCrack(*segmentItr)) {
640  crackSegments.push_back(*segmentItr);
641  }
642  // save ME0 segments if eta > 2.4, no other detectors
643  if ((*segmentItr)->isME0() && std::abs((*segmentItr)->globalPosition().eta()) > 2.4) {
644  crackSegments.push_back(*segmentItr);
645  }
646  }
647 }
648 
649 void MuonSeedOrcaPatternRecognition::dumpLayer(const char* name, const MuonRecHitContainer& segments) const {
650  MuonPatternRecoDumper theDumper;
651 
652  LogTrace(metname) << name << std::endl;
653  for (MuonRecHitContainer::const_iterator segmentItr = segments.begin(); segmentItr != segments.end(); ++segmentItr) {
654  LogTrace(metname) << theDumper.dumpMuonId((**segmentItr).geographicalId());
655  }
656 }
657 
659  const MuonRecHitContainer& segments, double dThetaCut) const {
660  MuonPatternRecoDumper theDumper;
662  for (MuonRecHitContainer::const_iterator segmentItr = segments.begin(); segmentItr != segments.end(); ++segmentItr) {
663  double dtheta = (*segmentItr)->globalDirection().theta() - (*segmentItr)->globalPosition().theta();
664  if ((*segmentItr)->isDT()) {
665  // only apply the cut to 4D segments
666  if ((*segmentItr)->dimension() == 2 || fabs(dtheta) < dThetaCut) {
667  result.push_back(*segmentItr);
668  } else {
669  LogTrace(metname) << "Cutting segment " << theDumper.dumpMuonId((**segmentItr).geographicalId())
670  << " because dtheta = " << dtheta;
671  }
672 
673  } else if ((*segmentItr)->isCSC()) {
674  if (fabs(dtheta) < dThetaCut) {
675  result.push_back(*segmentItr);
676  } else {
677  LogTrace(metname) << "Cutting segment " << theDumper.dumpMuonId((**segmentItr).geographicalId())
678  << " because dtheta = " << dtheta;
679  }
680  } else if ((*segmentItr)->isME0()) {
681  if (fabs(dtheta) < dThetaCut) {
682  result.push_back(*segmentItr);
683  } else {
684  LogTrace(metname) << "Cutting segment " << theDumper.dumpMuonId((**segmentItr).geographicalId())
685  << " because dtheta = " << dtheta;
686  }
687  }
688  }
690  return result;
691 }
692 
694  if (segments.empty())
695  return;
696  MuonPatternRecoDumper theDumper;
697  // need to optimize cuts
698  double dphiCut = 0.05;
699  double detaCut = 0.05;
700  std::vector<unsigned> toKill;
701  std::vector<unsigned> me1aOverlaps;
702  // loop over all segment pairs to see if there are two that match up in eta and phi
703  // but from different chambers
704  unsigned nseg = segments.size();
705  for (unsigned i = 0; i < nseg - 1; ++i) {
706  GlobalPoint pg1 = segments[i]->globalPosition();
707  for (unsigned j = i + 1; j < nseg; ++j) {
708  GlobalPoint pg2 = segments[j]->globalPosition();
709  if (segments[i]->geographicalId().rawId() != segments[j]->geographicalId().rawId() &&
710  fabs(deltaPhi(pg1.barePhi(), pg2.barePhi())) < dphiCut && fabs(pg1.eta() - pg2.eta()) < detaCut) {
711  LogTrace(metname) << "OVERLAP " << theDumper.dumpMuonId(segments[i]->geographicalId()) << " "
712  << theDumper.dumpMuonId(segments[j]->geographicalId());
713  // see which one is best
714  toKill.push_back((countHits(segments[i]) < countHits(segments[j])) ? i : j);
715  if (isME1A(segments[i])) {
716  me1aOverlaps.push_back(i);
717  me1aOverlaps.push_back(j);
718  }
719  }
720  }
721  }
722 
723  if (toKill.empty())
724  return;
725 
726  // try to kill ghosts assigned to overlaps
727  for (unsigned i = 0; i < me1aOverlaps.size(); ++i) {
728  DetId detId(segments[me1aOverlaps[i]]->geographicalId());
729  vector<unsigned> inSameChamber;
730  for (unsigned j = 0; j < nseg; ++j) {
731  if (i != j && segments[j]->geographicalId() == detId) {
732  inSameChamber.push_back(j);
733  }
734  }
735  if (inSameChamber.size() == 2) {
736  toKill.push_back(inSameChamber[0]);
737  toKill.push_back(inSameChamber[1]);
738  }
739  }
740  // now kill the killable
742  for (unsigned i = 0; i < nseg; ++i) {
743  if (std::find(toKill.begin(), toKill.end(), i) == toKill.end()) {
744  result.push_back(segments[i]);
745  }
746  }
747  segments.swap(result);
748 }
749 
751  return segment->isCSC() && CSCDetId(segment->geographicalId()).ring() == 4;
752 }
753 
755  int count = 0;
756  vector<TrackingRecHit*> components = (*segment).recHits();
757  for (vector<TrackingRecHit*>::const_iterator component = components.begin(); component != components.end();
758  ++component) {
759  int componentSize = (**component).recHits().size();
760  count += (componentSize == 0) ? 1 : componentSize;
761  }
762  return count;
763 }
const std::vector< const DetLayer * > & forwardCSCLayers() const
return the forward (+Z) CSC DetLayers, inside-out
std::string dumpMuonId(const DetId &id) const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
double discriminator(const ConstMuonRecHitPointer &first, MuonRecHitPointer &other) const
bool enableME0Measurement
Enable the ME0 measurement.
const std::vector< const DetLayer * > & backwardME0Layers() const
return the backward (-Z) ME0 DetLayers, inside-out
MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer
const std::string metname
T eta() const
Definition: PV3DBase.h:73
bool check(const MuonRecHitContainer &segments)
std::string const & label() const
Definition: InputTag.h:36
const std::vector< const DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
const std::vector< const DetLayer * > & forwardME0Layers() const
return the forward (+Z) ME0 DetLayers, inside-out
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
MuonRecHitPointer bestMatch(const ConstMuonRecHitPointer &first, MuonRecHitContainer &good_rhit) const
bool isME1A(const ConstMuonRecHitPointer &segment) const
#define LogTrace(id)
T barePhi() const
Definition: PV3DBase.h:65
bool enableCSCMeasurement
Enable the CSC measurement.
void complete(MuonRecHitContainer &seedSegments, const MuonRecHitContainer &recHits, bool *used=nullptr) const
void endcapPatterns(const MuonRecHitContainer &me11, const MuonRecHitContainer &me12, const MuonRecHitContainer &me2, const MuonRecHitContainer &me3, const MuonRecHitContainer &me4, const MuonRecHitContainer &me0, const MuonRecHitContainer &mb1, const MuonRecHitContainer &mb2, const MuonRecHitContainer &mb3, bool *MB1, bool *MB2, bool *MB3, std::vector< MuonRecHitContainer > &result)
MuonRecHitContainer recHits(const DetLayer *layer, const edm::Event &iEvent)
returns the rechits which are on the layer
void rememberCrackSegments(const MuonRecHitContainer &segments, MuonRecHitContainer &crackSegments) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void filterOverlappingChambers(MuonRecHitContainer &segments) const
edm::ESGetToken< MuonDetLayerGeometry, MuonRecoGeometryRecord > muonLayersToken
bool isCrack(const ConstMuonRecHitPointer &segment) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
#define M_PI
Definition: DetId.h:17
MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer
const std::vector< const DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void markAsUsed(int nr, const MuonRecHitContainer &recHits, bool *used) const
edm::InputTag theME0RecSegmentLabel
the name of the ME0 rec hits collection
MuonRecHitContainer filterSegments(const MuonRecHitContainer &segments, double dThetaCut) const
apply some cuts to segments before using them
MuonSeedOrcaPatternRecognition(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
static std::atomic< unsigned int > counter
bool isCSC(GeomDetEnumerators::SubDetector m)
bool enableDTMeasurement
Enable the DT measurement.
int ring() const
Definition: CSCDetId.h:68
void produce(const edm::Event &event, const edm::EventSetup &eSetup, std::vector< MuonRecHitContainer > &result) override
tmp
align.sh
Definition: createJobs.py:716
edm::InputTag theCSCRecSegmentLabel
the name of the CSC rec hits collection
Definition: event.py:1
void dumpLayer(const char *name, const MuonRecHitContainer &segments) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
int countHits(const MuonRecHitPointer &segment) const
edm::InputTag theDTRecSegmentLabel
the name of the DT rec hits collection