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