CMS 3D CMS Logo

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