CMS 3D CMS Logo

Muon.cc
Go to the documentation of this file.
6 
7 using namespace reco;
8 
9 Muon::Muon(Charge q, const LorentzVector& p4, const Point& vtx) : RecoCandidate(q, p4, vtx, -13 * q) {
10  energyValid_ = false;
11  matchesValid_ = false;
12  isolationValid_ = false;
13  pfIsolationValid_ = false;
14  qualityValid_ = false;
15  caloCompatibility_ = -9999.;
16  type_ = 0;
17  bestTunePTrackType_ = reco::Muon::None;
18  bestTrackType_ = reco::Muon::None;
19  selectors_ = 0;
20 }
21 
22 Muon::Muon() {
23  energyValid_ = false;
24  matchesValid_ = false;
25  isolationValid_ = false;
26  pfIsolationValid_ = false;
27  qualityValid_ = false;
28  caloCompatibility_ = -9999.;
29  type_ = 0;
30  bestTrackType_ = reco::Muon::None;
31  bestTunePTrackType_ = reco::Muon::None;
32  selectors_ = 0;
33 }
34 
35 bool Muon::overlap(const Candidate& c) const {
36  const RecoCandidate* o = dynamic_cast<const RecoCandidate*>(&c);
37  return (o != nullptr && (checkOverlap(track(), o->track()) || checkOverlap(standAloneMuon(), o->standAloneMuon()) ||
38  checkOverlap(combinedMuon(), o->combinedMuon()) ||
39  checkOverlap(standAloneMuon(), o->track()) || checkOverlap(combinedMuon(), o->track())));
40 }
41 
42 Muon* Muon::clone() const { return new Muon(*this); }
43 
44 int Muon::numberOfChambersCSCorDT() const {
45  int total = 0;
46  int nAll = numberOfChambers();
47  for (int iC = 0; iC < nAll; ++iC) {
49  total++;
50  }
51 
52  return total;
53 }
54 
55 int Muon::numberOfMatches(ArbitrationType type) const {
56  int matches(0);
57  for (auto& chamberMatch : muMatches_) {
58  if (type == RPCHitAndTrackArbitration) {
59  if (chamberMatch.rpcMatches.empty())
60  continue;
61  matches += chamberMatch.rpcMatches.size();
62  continue;
63  }
64  if (type == ME0SegmentAndTrackArbitration) {
65  if (chamberMatch.me0Matches.empty())
66  continue;
67  matches += chamberMatch.me0Matches.size();
68  continue;
69  }
70  if (type == GEMSegmentAndTrackArbitration) {
71  for (auto& segmentMatch : chamberMatch.gemMatches) {
72  if (segmentMatch.isMask(MuonSegmentMatch::BestInChamberByDR) &&
73  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
74  matches++;
75  break;
76  }
77  }
78  continue;
79  }
80 
81  if (type == GEMHitAndTrackArbitration) {
82  if (chamberMatch.gemHitMatches.empty())
83  continue;
84  matches += chamberMatch.gemHitMatches.size();
85  continue;
86  }
87 
88  if (chamberMatch.gemMatches.empty() and chamberMatch.segmentMatches.empty())
89  continue;
90  if (type == NoArbitration) {
91  matches++;
92  continue;
93  }
94 
95  if (chamberMatch.segmentMatches.empty())
96  continue;
97  for (auto& segmentMatch : chamberMatch.segmentMatches) {
98  if (type == SegmentArbitration)
99  if (segmentMatch.isMask(MuonSegmentMatch::BestInChamberByDR)) {
100  matches++;
101  break;
102  }
103  if (type == SegmentAndTrackArbitration)
104  if (segmentMatch.isMask(MuonSegmentMatch::BestInChamberByDR) &&
105  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
106  matches++;
107  break;
108  }
109  if (type == SegmentAndTrackArbitrationCleaned)
110  if (segmentMatch.isMask(MuonSegmentMatch::BestInChamberByDR) &&
111  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
112  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
113  matches++;
114  break;
115  }
116  }
117  }
118 
119  return matches;
120 }
121 
122 int Muon::numberOfMatchedStations(ArbitrationType type) const {
123  int stations(0);
124 
125  unsigned int theStationMask = stationMask(type);
126  // eight stations, eight bits
127  for (int it = 0; it < 8; ++it)
128  if (theStationMask & 1 << it)
129  ++stations;
130 
131  return stations;
132 }
133 
134 unsigned int Muon::expectedNnumberOfMatchedStations(float minDistanceFromEdge) const {
135  unsigned int stationMask = 0;
136  minDistanceFromEdge = std::abs(minDistanceFromEdge);
137  for (auto& chamberMatch : muMatches_) {
138  if (chamberMatch.detector() != MuonSubdetId::DT && chamberMatch.detector() != MuonSubdetId::CSC)
139  continue;
140  float edgeX = chamberMatch.edgeX;
141  float edgeY = chamberMatch.edgeY;
142  // check we if the trajectory is well within the acceptance
143  if (edgeX < 0 && -edgeX > minDistanceFromEdge && edgeY < 0 && -edgeY > minDistanceFromEdge)
144  stationMask |= 1 << ((chamberMatch.station() - 1) + 4 * (chamberMatch.detector() - 1));
145  }
146  unsigned int n = 0;
147  for (unsigned int i = 0; i < 8; ++i)
148  if (stationMask & (1 << i))
149  n++;
150  return n;
151 }
152 
153 unsigned int Muon::stationMask(ArbitrationType type) const {
154  unsigned int totMask(0);
155  unsigned int curMask(0);
156 
157  for (auto& chamberMatch : muMatches_) {
158  if (type == RPCHitAndTrackArbitration) {
159  if (chamberMatch.rpcMatches.empty())
160  continue;
161  RPCDetId rollId = chamberMatch.id.rawId();
162  int rpcIndex = rollId.region() == 0 ? 1 : 2;
163  curMask = 1 << ((chamberMatch.station() - 1) + 4 * (rpcIndex - 1));
164  // do not double count
165  if (!(totMask & curMask))
166  totMask += curMask;
167  continue;
168  }
169 
170  if (chamberMatch.segmentMatches.empty())
171  continue;
172  if (type == NoArbitration) {
173  curMask = 1 << ((chamberMatch.station() - 1) + 4 * (chamberMatch.detector() - 1));
174  // do not double count
175  if (!(totMask & curMask))
176  totMask += curMask;
177  continue;
178  }
179 
180  for (auto& segmentMatch : chamberMatch.segmentMatches) {
181  if (type == SegmentArbitration)
182  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR)) {
183  curMask = 1 << ((chamberMatch.station() - 1) + 4 * (chamberMatch.detector() - 1));
184  // do not double count
185  if (!(totMask & curMask))
186  totMask += curMask;
187  break;
188  }
189  if (type == SegmentAndTrackArbitration)
190  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR) &&
191  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
192  curMask = 1 << ((chamberMatch.station() - 1) + 4 * (chamberMatch.detector() - 1));
193  // do not double count
194  if (!(totMask & curMask))
195  totMask += curMask;
196  break;
197  }
198  if (type == SegmentAndTrackArbitrationCleaned)
199  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR) &&
200  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
201  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
202  curMask = 1 << ((chamberMatch.station() - 1) + 4 * (chamberMatch.detector() - 1));
203  // do not double count
204  if (!(totMask & curMask))
205  totMask += curMask;
206  break;
207  }
208  }
209  }
210 
211  return totMask;
212 }
213 
214 int Muon::numberOfMatchedRPCLayers(ArbitrationType type) const {
215  int layers(0);
216 
217  unsigned int theRPCLayerMask = RPClayerMask(type);
218  // maximum ten layers because of 6 layers in barrel and 3 (4) layers in each endcap before (after) upscope
219  for (int it = 0; it < 10; ++it)
220  if (theRPCLayerMask & 1 << it)
221  ++layers;
222 
223  return layers;
224 }
225 
226 unsigned int Muon::RPClayerMask(ArbitrationType type) const {
227  unsigned int totMask(0);
228  unsigned int curMask(0);
229  for (auto& chamberMatch : muMatches_) {
230  if (chamberMatch.rpcMatches.empty())
231  continue;
232 
233  RPCDetId rollId = chamberMatch.id.rawId();
234  const int region = rollId.region();
235  const int stationIndex = chamberMatch.station();
236  int rpcLayer = stationIndex;
237  if (region == 0) {
238  const int layer = rollId.layer();
239  rpcLayer = stationIndex - 1 + stationIndex * layer;
240  if ((stationIndex == 2 && layer == 2) || (stationIndex == 4 && layer == 1))
241  rpcLayer -= 1;
242  } else
243  rpcLayer += 6;
244 
245  curMask = 1 << (rpcLayer - 1);
246  // do not double count
247  if (!(totMask & curMask))
248  totMask += curMask;
249  }
250 
251  return totMask;
252 }
253 
254 unsigned int Muon::stationGapMaskDistance(float distanceCut) const {
255  unsigned int totMask(0);
256  distanceCut = std::abs(distanceCut);
257  for (auto& chamberMatch : muMatches_) {
258  unsigned int curMask(0);
259  const int detectorIndex = chamberMatch.detector();
260  if (detectorIndex < 1 || detectorIndex >= 4)
261  continue;
262  const int stationIndex = chamberMatch.station();
263  if (stationIndex < 1 || stationIndex >= 5)
264  continue;
265 
266  float edgeX = chamberMatch.edgeX;
267  float edgeY = chamberMatch.edgeY;
268  if (edgeX < 0 && -edgeX > distanceCut && edgeY < 0 &&
269  -edgeY > distanceCut) // inside the chamber so negates all gaps for this station
270  continue;
271 
272  if ((std::abs(edgeX) < distanceCut && edgeY < distanceCut) ||
273  (std::abs(edgeY) < distanceCut && edgeX < distanceCut)) // inside gap
274  curMask = 1 << ((stationIndex - 1) + 4 * (detectorIndex - 1));
275  totMask += curMask; // add to total mask
276  }
277 
278  return totMask;
279 }
280 
281 unsigned int Muon::stationGapMaskPull(float sigmaCut) const {
282  sigmaCut = std::abs(sigmaCut);
283  unsigned int totMask(0);
284  for (auto& chamberMatch : muMatches_) {
285  unsigned int curMask(0);
286  const int detectorIndex = chamberMatch.detector();
287  if (detectorIndex < 1 || detectorIndex >= 4)
288  continue;
289  const int stationIndex = chamberMatch.station();
290  if (stationIndex < 1 || stationIndex >= 5)
291  continue;
292 
293  float edgeX = chamberMatch.edgeX;
294  float edgeY = chamberMatch.edgeY;
295  float xErr = chamberMatch.xErr + 0.000001; // protect against division by zero later
296  float yErr = chamberMatch.yErr + 0.000001; // protect against division by zero later
297  if (edgeX < 0 && std::abs(edgeX / xErr) > sigmaCut && edgeY < 0 &&
298  std::abs(edgeY / yErr) > sigmaCut) // inside the chamber so negates all gaps for this station
299  continue;
300 
301  if ((std::abs(edgeX / xErr) < sigmaCut && edgeY < sigmaCut * yErr) ||
302  (std::abs(edgeY / yErr) < sigmaCut && edgeX < sigmaCut * xErr)) // inside gap
303  curMask = 1 << ((stationIndex - 1) + 4 * (detectorIndex - 1));
304  totMask += curMask; // add to total mask
305  }
306 
307  return totMask;
308 }
309 
310 int Muon::nDigisInStation(int station, int muonSubdetId) const {
311  int nDigis(0);
312  std::map<int, int> me11DigisPerCh;
313 
314  if (muonSubdetId != MuonSubdetId::CSC && muonSubdetId != MuonSubdetId::DT)
315  return 0;
316 
317  for (auto& match : muMatches_) {
318  if (match.detector() != muonSubdetId || match.station() != station)
319  continue;
320 
321  int nDigisInCh = match.nDigisInRange;
322 
323  if (muonSubdetId == MuonSubdetId::CSC && station == 1) {
324  CSCDetId id(match.id.rawId());
325 
326  int chamber = id.chamber();
327  int ring = id.ring();
328 
329  if (ring == 1 || ring == 4) // merge ME1/1a and ME1/1b digis
330  {
331  if (me11DigisPerCh.find(chamber) == me11DigisPerCh.end())
332  me11DigisPerCh[chamber] = 0;
333 
334  me11DigisPerCh[chamber] += nDigisInCh;
335 
336  continue;
337  }
338  }
339 
340  if (nDigisInCh > nDigis)
341  nDigis = nDigisInCh;
342  }
343 
344  for (const auto& me11DigisInCh : me11DigisPerCh) {
345  int nMe11DigisInCh = me11DigisInCh.second;
346  if (nMe11DigisInCh > nDigis)
347  nDigis = nMe11DigisInCh;
348  }
349 
350  return nDigis;
351 }
352 
353 bool Muon::hasShowerInStation(int station, int muonSubdetId, int nDtDigisCut, int nCscDigisCut) const {
354  if (muonSubdetId != MuonSubdetId::DT && muonSubdetId != MuonSubdetId::CSC)
355  return false;
356  auto nDigisCut = muonSubdetId == MuonSubdetId::DT ? nDtDigisCut : nCscDigisCut;
357 
358  return nDigisInStation(station, muonSubdetId) >= nDigisCut;
359 }
360 
361 int Muon::numberOfShowers(int nDtDigisCut, int nCscDigisCut) const {
362  int nShowers = 0;
363  for (int station = 1; station < 5; ++station) {
364  if (hasShowerInStation(station, MuonSubdetId::DT, nDtDigisCut, nCscDigisCut))
365  nShowers++;
366  if (hasShowerInStation(station, MuonSubdetId::CSC, nDtDigisCut, nCscDigisCut))
367  nShowers++;
368  }
369 
370  return nShowers;
371 }
372 
373 int Muon::numberOfSegments(int station, int muonSubdetId, ArbitrationType type) const {
374  int segments(0);
375  for (auto& chamberMatch : muMatches_) {
376  if (chamberMatch.segmentMatches.empty())
377  continue;
378  if (chamberMatch.detector() != muonSubdetId || chamberMatch.station() != station)
379  continue;
380 
381  if (type == NoArbitration) {
382  segments += chamberMatch.segmentMatches.size();
383  continue;
384  }
385 
386  for (auto& segmentMatch : chamberMatch.segmentMatches) {
387  if (type == SegmentArbitration)
388  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR)) {
389  segments++;
390  break;
391  }
392  if (type == SegmentAndTrackArbitration)
393  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR) &&
394  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR)) {
395  segments++;
396  break;
397  }
398  if (type == SegmentAndTrackArbitrationCleaned)
399  if (segmentMatch.isMask(MuonSegmentMatch::BestInStationByDR) &&
400  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
401  segmentMatch.isMask(MuonSegmentMatch::BelongsToTrackByCleaning)) {
402  segments++;
403  break;
404  }
405  }
406  }
407 
408  return segments;
409 }
410 
411 const std::vector<const MuonChamberMatch*> Muon::chambers(int station, int muonSubdetId) const {
412  std::vector<const MuonChamberMatch*> chambers;
413  for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muMatches_.begin();
414  chamberMatch != muMatches_.end();
415  chamberMatch++)
416  if (chamberMatch->detector() == muonSubdetId && chamberMatch->station() == station)
417  chambers.push_back(&(*chamberMatch));
418  return chambers;
419 }
420 
421 std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> Muon::pair(
422  const std::vector<const MuonChamberMatch*>& chambers, ArbitrationType type) const {
423  MuonChamberMatch* m = nullptr;
424  MuonSegmentMatch* s = nullptr;
425  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair(m, s);
426 
427  if (chambers.empty())
428  return chamberSegmentPair;
429  for (std::vector<const MuonChamberMatch*>::const_iterator chamberMatch = chambers.begin();
430  chamberMatch != chambers.end();
431  chamberMatch++) {
432  if ((*chamberMatch)->segmentMatches.empty())
433  continue;
434  if (type == NoArbitration)
435  return std::make_pair(*chamberMatch, &((*chamberMatch)->segmentMatches.front()));
436 
437  for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = (*chamberMatch)->segmentMatches.begin();
438  segmentMatch != (*chamberMatch)->segmentMatches.end();
439  segmentMatch++) {
440  if (type == SegmentArbitration)
441  if (segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR))
442  return std::make_pair(*chamberMatch, &(*segmentMatch));
443  if (type == SegmentAndTrackArbitration)
444  if (segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
445  segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR))
446  return std::make_pair(*chamberMatch, &(*segmentMatch));
447  if (type == SegmentAndTrackArbitrationCleaned)
448  if (segmentMatch->isMask(MuonSegmentMatch::BestInStationByDR) &&
449  segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByDR) &&
450  segmentMatch->isMask(MuonSegmentMatch::BelongsToTrackByCleaning))
451  return std::make_pair(*chamberMatch, &(*segmentMatch));
452  }
453  }
454 
455  return chamberSegmentPair;
456 }
457 
458 float Muon::dX(int station, int muonSubdetId, ArbitrationType type) const {
459  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
460  pair(chambers(station, muonSubdetId), type);
461  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
462  return 999999;
463  if (!chamberSegmentPair.second->hasPhi())
464  return 999999;
465  return chamberSegmentPair.first->x - chamberSegmentPair.second->x;
466 }
467 
468 float Muon::dY(int station, int muonSubdetId, ArbitrationType type) const {
469  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
470  return 999999; // no y information
471  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
472  pair(chambers(station, muonSubdetId), type);
473  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
474  return 999999;
475  if (!chamberSegmentPair.second->hasZed())
476  return 999999;
477  return chamberSegmentPair.first->y - chamberSegmentPair.second->y;
478 }
479 
480 float Muon::dDxDz(int station, int muonSubdetId, ArbitrationType type) const {
481  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
482  pair(chambers(station, muonSubdetId), type);
483  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
484  return 999999;
485  if (!chamberSegmentPair.second->hasPhi())
486  return 999999;
487  return chamberSegmentPair.first->dXdZ - chamberSegmentPair.second->dXdZ;
488 }
489 
490 float Muon::dDyDz(int station, int muonSubdetId, ArbitrationType type) const {
491  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
492  return 999999; // no y information
493  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
494  pair(chambers(station, muonSubdetId), type);
495  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
496  return 999999;
497  if (!chamberSegmentPair.second->hasZed())
498  return 999999;
499  return chamberSegmentPair.first->dYdZ - chamberSegmentPair.second->dYdZ;
500 }
501 
502 float Muon::pullX(int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError) const {
503  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
504  pair(chambers(station, muonSubdetId), type);
505  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
506  return 999999;
507  if (!chamberSegmentPair.second->hasPhi())
508  return 999999;
509  if (includeSegmentError)
510  return (chamberSegmentPair.first->x - chamberSegmentPair.second->x) /
511  sqrt(std::pow(chamberSegmentPair.first->xErr, 2) + std::pow(chamberSegmentPair.second->xErr, 2));
512  return (chamberSegmentPair.first->x - chamberSegmentPair.second->x) / chamberSegmentPair.first->xErr;
513 }
514 
515 float Muon::pullY(int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError) const {
516  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
517  return 999999; // no y information
518  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
519  pair(chambers(station, muonSubdetId), type);
520  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
521  return 999999;
522  if (!chamberSegmentPair.second->hasZed())
523  return 999999;
524  if (includeSegmentError)
525  return (chamberSegmentPair.first->y - chamberSegmentPair.second->y) /
526  sqrt(std::pow(chamberSegmentPair.first->yErr, 2) + std::pow(chamberSegmentPair.second->yErr, 2));
527  return (chamberSegmentPair.first->y - chamberSegmentPair.second->y) / chamberSegmentPair.first->yErr;
528 }
529 
530 float Muon::pullDxDz(int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError) const {
531  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
532  pair(chambers(station, muonSubdetId), type);
533  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
534  return 999999;
535  if (!chamberSegmentPair.second->hasPhi())
536  return 999999;
537  if (includeSegmentError)
538  return (chamberSegmentPair.first->dXdZ - chamberSegmentPair.second->dXdZ) /
539  sqrt(std::pow(chamberSegmentPair.first->dXdZErr, 2) + std::pow(chamberSegmentPair.second->dXdZErr, 2));
540  return (chamberSegmentPair.first->dXdZ - chamberSegmentPair.second->dXdZ) / chamberSegmentPair.first->dXdZErr;
541 }
542 
543 float Muon::pullDyDz(int station, int muonSubdetId, ArbitrationType type, bool includeSegmentError) const {
544  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
545  return 999999; // no y information
546  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
547  pair(chambers(station, muonSubdetId), type);
548  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
549  return 999999;
550  if (!chamberSegmentPair.second->hasZed())
551  return 999999;
552  if (includeSegmentError)
553  return (chamberSegmentPair.first->dYdZ - chamberSegmentPair.second->dYdZ) /
554  sqrt(std::pow(chamberSegmentPair.first->dYdZErr, 2) + std::pow(chamberSegmentPair.second->dYdZErr, 2));
555  return (chamberSegmentPair.first->dYdZ - chamberSegmentPair.second->dYdZ) / chamberSegmentPair.first->dYdZErr;
556 }
557 
558 float Muon::segmentX(int station, int muonSubdetId, ArbitrationType type) const {
559  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
560  pair(chambers(station, muonSubdetId), type);
561  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
562  return 999999;
563  if (!chamberSegmentPair.second->hasPhi())
564  return 999999;
565  return chamberSegmentPair.second->x;
566 }
567 
568 float Muon::segmentY(int station, int muonSubdetId, ArbitrationType type) const {
569  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
570  return 999999; // no y information
571  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
572  pair(chambers(station, muonSubdetId), type);
573  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
574  return 999999;
575  if (!chamberSegmentPair.second->hasZed())
576  return 999999;
577  return chamberSegmentPair.second->y;
578 }
579 
580 float Muon::segmentDxDz(int station, int muonSubdetId, ArbitrationType type) const {
581  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
582  pair(chambers(station, muonSubdetId), type);
583  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
584  return 999999;
585  if (!chamberSegmentPair.second->hasPhi())
586  return 999999;
587  return chamberSegmentPair.second->dXdZ;
588 }
589 
590 float Muon::segmentDyDz(int station, int muonSubdetId, ArbitrationType type) const {
591  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
592  return 999999; // no y information
593  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
594  pair(chambers(station, muonSubdetId), type);
595  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
596  return 999999;
597  if (!chamberSegmentPair.second->hasZed())
598  return 999999;
599  return chamberSegmentPair.second->dYdZ;
600 }
601 
602 float Muon::segmentXErr(int station, int muonSubdetId, ArbitrationType type) const {
603  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
604  pair(chambers(station, muonSubdetId), type);
605  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
606  return 999999;
607  if (!chamberSegmentPair.second->hasPhi())
608  return 999999;
609  return chamberSegmentPair.second->xErr;
610 }
611 
612 float Muon::segmentYErr(int station, int muonSubdetId, ArbitrationType type) const {
613  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
614  return 999999; // no y information
615  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
616  pair(chambers(station, muonSubdetId), type);
617  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
618  return 999999;
619  if (!chamberSegmentPair.second->hasZed())
620  return 999999;
621  return chamberSegmentPair.second->yErr;
622 }
623 
624 float Muon::segmentDxDzErr(int station, int muonSubdetId, ArbitrationType type) const {
625  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
626  pair(chambers(station, muonSubdetId), type);
627  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
628  return 999999;
629  if (!chamberSegmentPair.second->hasPhi())
630  return 999999;
631  return chamberSegmentPair.second->dXdZErr;
632 }
633 
634 float Muon::segmentDyDzErr(int station, int muonSubdetId, ArbitrationType type) const {
635  if (station == 4 && muonSubdetId == MuonSubdetId::DT)
636  return 999999; // no y information
637  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair =
638  pair(chambers(station, muonSubdetId), type);
639  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr)
640  return 999999;
641  if (!chamberSegmentPair.second->hasZed())
642  return 999999;
643  return chamberSegmentPair.second->dYdZErr;
644 }
645 
646 float Muon::trackEdgeX(int station, int muonSubdetId, ArbitrationType type) const {
647  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
648  if (muonChambers.empty())
649  return 999999;
650 
651  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
652  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
653  float dist = 999999;
654  float supVar = 999999;
655  for (const MuonChamberMatch* muonChamber : muonChambers) {
656  float currDist = muonChamber->dist();
657  if (currDist < dist) {
658  dist = currDist;
659  supVar = muonChamber->edgeX;
660  }
661  }
662  return supVar;
663  } else
664  return chamberSegmentPair.first->edgeX;
665 }
666 
667 float Muon::trackEdgeY(int station, int muonSubdetId, ArbitrationType type) const {
668  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
669  if (muonChambers.empty())
670  return 999999;
671 
672  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
673  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
674  float dist = 999999;
675  float supVar = 999999;
676  for (const MuonChamberMatch* muonChamber : muonChambers) {
677  float currDist = muonChamber->dist();
678  if (currDist < dist) {
679  dist = currDist;
680  supVar = muonChamber->edgeY;
681  }
682  }
683  return supVar;
684  } else
685  return chamberSegmentPair.first->edgeY;
686 }
687 
688 float Muon::trackX(int station, int muonSubdetId, ArbitrationType type) const {
689  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
690  if (muonChambers.empty())
691  return 999999;
692 
693  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
694  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
695  float dist = 999999;
696  float supVar = 999999;
697  for (const MuonChamberMatch* muonChamber : muonChambers) {
698  float currDist = muonChamber->dist();
699  if (currDist < dist) {
700  dist = currDist;
701  supVar = muonChamber->x;
702  }
703  }
704  return supVar;
705  } else
706  return chamberSegmentPair.first->x;
707 }
708 
709 float Muon::trackY(int station, int muonSubdetId, ArbitrationType type) const {
710  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
711  if (muonChambers.empty())
712  return 999999;
713 
714  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
715  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
716  float dist = 999999;
717  float supVar = 999999;
718  for (const MuonChamberMatch* muonChamber : muonChambers) {
719  float currDist = muonChamber->dist();
720  if (currDist < dist) {
721  dist = currDist;
722  supVar = muonChamber->y;
723  }
724  }
725  return supVar;
726  } else
727  return chamberSegmentPair.first->y;
728 }
729 
730 float Muon::trackDxDz(int station, int muonSubdetId, ArbitrationType type) const {
731  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
732  if (muonChambers.empty())
733  return 999999;
734 
735  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
736  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
737  float dist = 999999;
738  float supVar = 999999;
739  for (const MuonChamberMatch* muonChamber : muonChambers) {
740  float currDist = muonChamber->dist();
741  if (currDist < dist) {
742  dist = currDist;
743  supVar = muonChamber->dXdZ;
744  }
745  }
746  return supVar;
747  } else
748  return chamberSegmentPair.first->dXdZ;
749 }
750 
751 float Muon::trackDyDz(int station, int muonSubdetId, ArbitrationType type) const {
752  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
753  if (muonChambers.empty())
754  return 999999;
755 
756  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
757  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
758  float dist = 999999;
759  float supVar = 999999;
760  for (const MuonChamberMatch* muonChamber : muonChambers) {
761  float currDist = muonChamber->dist();
762  if (currDist < dist) {
763  dist = currDist;
764  supVar = muonChamber->dYdZ;
765  }
766  }
767  return supVar;
768  } else
769  return chamberSegmentPair.first->dYdZ;
770 }
771 
772 float Muon::trackXErr(int station, int muonSubdetId, ArbitrationType type) const {
773  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
774  if (muonChambers.empty())
775  return 999999;
776 
777  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
778  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
779  float dist = 999999;
780  float supVar = 999999;
781  for (const MuonChamberMatch* muonChamber : muonChambers) {
782  float currDist = muonChamber->dist();
783  if (currDist < dist) {
784  dist = currDist;
785  supVar = muonChamber->xErr;
786  }
787  }
788  return supVar;
789  } else
790  return chamberSegmentPair.first->xErr;
791 }
792 
793 float Muon::trackYErr(int station, int muonSubdetId, ArbitrationType type) const {
794  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
795  if (muonChambers.empty())
796  return 999999;
797 
798  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
799  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
800  float dist = 999999;
801  float supVar = 999999;
802  for (const MuonChamberMatch* muonChamber : muonChambers) {
803  float currDist = muonChamber->dist();
804  if (currDist < dist) {
805  dist = currDist;
806  supVar = muonChamber->yErr;
807  }
808  }
809  return supVar;
810  } else
811  return chamberSegmentPair.first->yErr;
812 }
813 
814 float Muon::trackDxDzErr(int station, int muonSubdetId, ArbitrationType type) const {
815  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
816  if (muonChambers.empty())
817  return 999999;
818 
819  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
820  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
821  float dist = 999999;
822  float supVar = 999999;
823  for (const MuonChamberMatch* muonChamber : muonChambers) {
824  float currDist = muonChamber->dist();
825  if (currDist < dist) {
826  dist = currDist;
827  supVar = muonChamber->dXdZErr;
828  }
829  }
830  return supVar;
831  } else
832  return chamberSegmentPair.first->dXdZErr;
833 }
834 
835 float Muon::trackDyDzErr(int station, int muonSubdetId, ArbitrationType type) const {
836  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
837  if (muonChambers.empty())
838  return 999999;
839 
840  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
841  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
842  float dist = 999999;
843  float supVar = 999999;
844  for (const MuonChamberMatch* muonChamber : muonChambers) {
845  float currDist = muonChamber->dist();
846  if (currDist < dist) {
847  dist = currDist;
848  supVar = muonChamber->dYdZErr;
849  }
850  }
851  return supVar;
852  } else
853  return chamberSegmentPair.first->dYdZErr;
854 }
855 
856 float Muon::trackDist(int station, int muonSubdetId, ArbitrationType type) const {
857  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
858  if (muonChambers.empty())
859  return 999999;
860 
861  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
862  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
863  float dist = 999999;
864  for (const MuonChamberMatch* muonChamber : muonChambers) {
865  float currDist = muonChamber->dist();
866  if (currDist < dist)
867  dist = currDist;
868  }
869  return dist;
870  } else
871  return chamberSegmentPair.first->dist();
872 }
873 
874 float Muon::trackDistErr(int station, int muonSubdetId, ArbitrationType type) const {
875  const std::vector<const MuonChamberMatch*> muonChambers = chambers(station, muonSubdetId);
876  if (muonChambers.empty())
877  return 999999;
878 
879  std::pair<const MuonChamberMatch*, const MuonSegmentMatch*> chamberSegmentPair = pair(muonChambers, type);
880  if (chamberSegmentPair.first == nullptr || chamberSegmentPair.second == nullptr) {
881  float dist = 999999;
882  float supVar = 999999;
883  for (const MuonChamberMatch* muonChamber : muonChambers) {
884  float currDist = muonChamber->dist();
885  if (currDist < dist) {
886  dist = currDist;
887  supVar = muonChamber->distErr();
888  }
889  }
890  return supVar;
891  } else
892  return chamberSegmentPair.first->distErr();
893 }
894 
895 void Muon::setIsolation(const MuonIsolation& isoR03, const MuonIsolation& isoR05) {
896  isolationR03_ = isoR03;
897  isolationR05_ = isoR05;
898  isolationValid_ = true;
899 }
900 
901 void Muon::setPFIsolation(const std::string& label, const MuonPFIsolation& deposit) {
902  if (label == "pfIsolationR03")
903  pfIsolationR03_ = deposit;
904 
905  if (label == "pfIsolationR04")
906  pfIsolationR04_ = deposit;
907 
908  if (label == "pfIsoMeanDRProfileR03")
909  pfIsoMeanDRR03_ = deposit;
910 
911  if (label == "pfIsoMeanDRProfileR04")
912  pfIsoMeanDRR04_ = deposit;
913 
914  if (label == "pfIsoSumDRProfileR03")
915  pfIsoSumDRR03_ = deposit;
916 
917  if (label == "pfIsoSumDRProfileR04")
918  pfIsoSumDRR04_ = deposit;
919 
920  pfIsolationValid_ = true;
921 }
922 
923 void Muon::setPFP4(const reco::Candidate::LorentzVector& p4) {
924  pfP4_ = p4;
925  type_ = type_ | PFMuon;
926 }
927 
928 void Muon::setOuterTrack(const TrackRef& t) { outerTrack_ = t; }
929 void Muon::setInnerTrack(const TrackRef& t) { innerTrack_ = t; }
930 void Muon::setTrack(const TrackRef& t) { setInnerTrack(t); }
931 void Muon::setStandAlone(const TrackRef& t) { setOuterTrack(t); }
932 void Muon::setGlobalTrack(const TrackRef& t) { globalTrack_ = t; }
933 void Muon::setCombined(const TrackRef& t) { setGlobalTrack(t); }
934 
935 bool Muon::isAValidMuonTrack(const MuonTrackType& type) const { return muonTrack(type).isNonnull(); }
936 
937 TrackRef Muon::muonTrack(const MuonTrackType& type) const {
938  switch (type) {
939  case InnerTrack:
940  return innerTrack();
941  case OuterTrack:
942  return standAloneMuon();
943  case CombinedTrack:
944  return globalTrack();
945  case TPFMS:
946  return tpfmsTrack();
947  case Picky:
948  return pickyTrack();
949  case DYT:
950  return dytTrack();
951  default:
952  return muonTrackFromMap(type);
953  }
954 }
955 
956 void Muon::setMuonTrack(const MuonTrackType& type, const TrackRef& t) {
957  switch (type) {
958  case InnerTrack:
959  setInnerTrack(t);
960  break;
961  case OuterTrack:
962  setStandAlone(t);
963  break;
964  case CombinedTrack:
965  setGlobalTrack(t);
966  break;
967  default:
968  refittedTrackMap_[type] = t;
969  break;
970  }
971 }
const LorentzVector & p4() const final
four-momentum Lorentz vector
char const * label
float pullDyDz(const MatchPair &match)
Definition: Muon.py:1
float pullDxDz(const MatchPair &match)
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
math::XYZTLorentzVector LorentzVector
def stationIndex(name)
Definition: plotscripts.py:355
bool overlap(const Candidate &) const override
check overlap with another Candidate
float dX(const MatchPair &match)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
def checkOverlap(process)
fixed size matrix
Structure Point Contains parameters of Gaussian fits to DMRs.
int layer() const
Definition: RPCDetId.h:85
LeafCandidate * clone() const override
returns a clone of the Candidate object
static constexpr int DT
Definition: MuonSubdetId.h:11
MuonTrackType
Definition: MuonTrackType.h:28
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
float pullY(const MatchPair &match)
static constexpr int CSC
Definition: MuonSubdetId.h:12
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float pullX(const MatchPair &match)
float dY(const MatchPair &match)
Muon()
Definition: Muon.cc:3