CMS 3D CMS Logo

PFMuonAlgo.cc
Go to the documentation of this file.
10 #include <iostream>
11 
12 
13 using namespace std;
14 using namespace reco;
15 using namespace boost;
16 
18  pfCosmicsMuonCleanedCandidates_ = std::make_unique<reco::PFCandidateCollection>();
19  pfCleanedTrackerAndGlobalMuonCandidates_= std::make_unique<reco::PFCandidateCollection>();
20  pfFakeMuonCleanedCandidates_= std::make_unique<reco::PFCandidateCollection>();
21  pfPunchThroughMuonCleanedCandidates_= std::make_unique<reco::PFCandidateCollection>();
22  pfPunchThroughHadronCleanedCandidates_= std::make_unique<reco::PFCandidateCollection>();
23  pfAddedMuonCandidates_ = std::make_unique<reco::PFCandidateCollection>();
24 
25 }
26 
27 
28 
30 {
31 
32  if(iConfig.exists("maxDPtOPt"))
33  maxDPtOPt_ = iConfig.getParameter<double>("maxDPtOPt");
34  else
35  maxDPtOPt_=1.0;
36 
37  if(iConfig.exists("minTrackerHits"))
38  minTrackerHits_ = iConfig.getParameter<int>("minTrackerHits");
39  else
40  minTrackerHits_ = 8;
41 
42  if(iConfig.exists("minPixelHits"))
43  minPixelHits_ = iConfig.getParameter<int>("minPixelHits");
44  else
45  minPixelHits_ = 1;
46 
47  if(iConfig.exists("trackQuality"))
48  trackQuality_ = reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("trackQuality"));
49  else
50  trackQuality_ = reco::TrackBase::qualityByName("highPurity");
51 
52  if(iConfig.exists("ptErrorScale"))
53  errorCompScale_ = iConfig.getParameter<double>("ptErrorScale");
54  else
55  errorCompScale_ = 4.;
56 
57  if(iConfig.exists("eventFractionForCleaning"))
58  eventFractionCleaning_ = iConfig.getParameter<double>("eventFractionForCleaning");
59  else
60  eventFractionCleaning_ = 0.75;
61 
62  if(iConfig.exists("dzPV"))
63  dzPV_ = iConfig.getParameter<double>("dzPV");
64  else
65  dzPV_ = 0.2;
66 
67  if(iConfig.exists("postMuonCleaning"))
68  postCleaning_ = iConfig.getParameter<bool>("postMuonCleaning");
69  else
70  postCleaning_ = false; //Disable by default (for HLT)
71 
72  if(iConfig.exists("minPtForPostCleaning"))
73  minPostCleaningPt_ = iConfig.getParameter<double>("minPtForPostCleaning");
74  else
75  minPostCleaningPt_ = 20.;
76 
77  if(iConfig.exists("eventFactorForCosmics"))
78  eventFactorCosmics_ = iConfig.getParameter<double>("eventFactorForCosmics");
79  else
80  eventFactorCosmics_ = 10.;
81 
82 
83  if(iConfig.exists("metSignificanceForCleaning"))
84  metSigForCleaning_ = iConfig.getParameter<double>("metSignificanceForCleaning");
85  else
86  metSigForCleaning_ = 3.;
87 
88  if(iConfig.exists("metSignificanceForRejection"))
89  metSigForRejection_ = iConfig.getParameter<double>("metSignificanceForRejection");
90  else
91  metSigForRejection_ = 4.;
92 
93  if(iConfig.exists("metFactorForCleaning"))
94  metFactorCleaning_ = iConfig.getParameter<double>("metFactorForCleaning");
95  else
96  metFactorCleaning_ = 4.;
97 
98  if(iConfig.exists("eventFractionForRejection"))
99  eventFractionRejection_ = iConfig.getParameter<double>("eventFractionForRejection");
100  else
101  eventFractionRejection_ = 0.75;
102 
103  if(iConfig.exists("metFactorForRejection"))
104  metFactorRejection_ = iConfig.getParameter<double>("metFactorForRejection");
105  else
106  metFactorRejection_ =4.;
107 
108  if(iConfig.exists("metFactorForHighEta"))
109  metFactorHighEta_ = iConfig.getParameter<double>("metFactorForHighEta");
110  else
111  metFactorHighEta_=4;
112 
113  if(iConfig.exists("ptFactorForHighEta"))
114  ptFactorHighEta_ = iConfig.getParameter<double>("ptFactorForHighEta");
115  else
116  ptFactorHighEta_ = 2.;
117 
118  if(iConfig.exists("metFactorForFakes"))
119  metFactorFake_ = iConfig.getParameter<double>("metFactorForFakes");
120  else
121  metFactorFake_ = 4.;
122 
123  if(iConfig.exists("minMomentumForPunchThrough"))
124  minPunchThroughMomentum_ = iConfig.getParameter<double>("minMomentumForPunchThrough");
125  else
126  minPunchThroughMomentum_=100.;
127 
128  if(iConfig.exists("minEnergyForPunchThrough"))
129  minPunchThroughEnergy_ = iConfig.getParameter<double>("minEnergyForPunchThrough");
130  else
131  minPunchThroughEnergy_ = 100.;
132 
133  if(iConfig.exists("punchThroughFactor"))
134  punchThroughFactor_ = iConfig.getParameter<double>("punchThroughFactor");
135  else
136  punchThroughFactor_ = 3.;
137 
138  if(iConfig.exists("punchThroughMETFactor"))
139  punchThroughMETFactor_ = iConfig.getParameter<double>("punchThroughMETFactor");
140  else
141  punchThroughMETFactor_ = 4.;
142 
143  if(iConfig.exists("cosmicRejectionDistance"))
144  cosmicRejDistance_ = iConfig.getParameter<double>("cosmicRejectionDistance");
145  else
146  cosmicRejDistance_ = 1.0;
147 }
148 
149 
150 
151 
152 
153 
154 bool
156 
157  const reco::PFBlockElementTrack* eltTrack
158  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
159 
160  assert ( eltTrack );
161  reco::MuonRef muonRef = eltTrack->muonRef();
162 
163  return isMuon(muonRef);
164 
165 }
166 
167 bool
169 
170 
171  const reco::PFBlockElementTrack* eltTrack
172  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
173 
174 
175 
176  assert ( eltTrack );
177 
178 
179  reco::MuonRef muonRef = eltTrack->muonRef();
180 
181 
182  return isLooseMuon(muonRef);
183 
184 }
185 
186 
187 bool
189 
190  const reco::PFBlockElementTrack* eltTrack
191  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
192 
193  assert ( eltTrack );
194  reco::MuonRef muonRef = eltTrack->muonRef();
195 
196  return isGlobalTightMuon(muonRef);
197 
198 }
199 
200 bool
202 
203  const reco::PFBlockElementTrack* eltTrack
204  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
205 
206  assert ( eltTrack );
207  reco::MuonRef muonRef = eltTrack->muonRef();
208 
209  return isGlobalLooseMuon(muonRef);
210 
211 }
212 
213 bool
215 
216  const reco::PFBlockElementTrack* eltTrack
217  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
218 
219  assert ( eltTrack );
220  reco::MuonRef muonRef = eltTrack->muonRef();
221 
222  return isTrackerTightMuon(muonRef);
223 
224 }
225 
226 bool
228 
229  const reco::PFBlockElementTrack* eltTrack
230  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
231 
232  assert ( eltTrack );
233  reco::MuonRef muonRef = eltTrack->muonRef();
234 
235  return isIsolatedMuon(muonRef);
236 
237 }
238 
239 bool
241 
242  return isGlobalTightMuon(muonRef) || isTrackerTightMuon(muonRef) || isIsolatedMuon(muonRef);
243 }
244 
245 bool
247 
248  return (isGlobalLooseMuon(muonRef) || isTrackerLooseMuon(muonRef));
249 
250 }
251 
252 bool
254 
255  if ( !muonRef.isNonnull() ) return false;
256 
257  if ( !muonRef->isGlobalMuon() ) return false;
258  if ( !muonRef->isStandAloneMuon() ) return false;
259 
260 
261  if ( muonRef->isTrackerMuon() ) {
262 
264 
265  bool isTM2DCompatibilityTight = muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight);
266  int nMatches = muonRef->numberOfMatches();
267  bool quality = nMatches > 2 || isTM2DCompatibilityTight;
268 
269  return result && quality;
270 
271  } else {
272 
273  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
274 
275  // No tracker muon -> Request a perfect stand-alone muon, or an even better global muon
276  bool result = false;
277 
278  // Check the quality of the stand-alone muon :
279  // good chi**2 and large number of hits and good pt error
280  if ( ( standAloneMu->hitPattern().numberOfValidMuonDTHits() < 22 &&
281  standAloneMu->hitPattern().numberOfValidMuonCSCHits() < 15 ) ||
282  standAloneMu->normalizedChi2() > 10. ||
283  standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
284  result = false;
285  } else {
286 
287  reco::TrackRef combinedMu = muonRef->combinedMuon();
288  reco::TrackRef trackerMu = muonRef->track();
289 
290  // If the stand-alone muon is good, check the global muon
291  if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
292  // If the combined muon is worse than the stand-alone, it
293  // means that either the corresponding tracker track was not
294  // reconstructed, or that the sta muon comes from a late
295  // pion decay (hence with a momentum smaller than the track)
296  // Take the stand-alone muon only if its momentum is larger
297  // than that of the track
298  result = standAloneMu->pt() > trackerMu->pt() ;
299  } else {
300  // If the combined muon is better (and good enough), take the
301  // global muon
302  result =
303  combinedMu->ptError()/combinedMu->pt() <
304  std::min(0.20,standAloneMu->ptError()/standAloneMu->pt());
305  }
306  }
307 
308  return result;
309  }
310 
311  return false;
312 
313 }
314 
315 bool
317 
318  if ( !muonRef.isNonnull() ) return false;
319 
320  if(!muonRef->isTrackerMuon()) return false;
321 
322  reco::TrackRef trackerMu = muonRef->track();
323  const reco::Track& track = *trackerMu;
324 
325  unsigned nTrackerHits = track.hitPattern().numberOfValidTrackerHits();
326 
327  if(nTrackerHits<=12) return false;
328 
329  bool isAllArbitrated = muon::isGoodMuon(*muonRef,muon::AllArbitrated);
330 
331  bool isTM2DCompatibilityTight = muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight);
332 
333  if(!isAllArbitrated || !isTM2DCompatibilityTight) return false;
334 
335  if((trackerMu->ptError()/trackerMu->pt() > 0.10)){
336  //std::cout<<" PT ERROR > 10 % "<< trackerMu->pt() <<std::endl;
337  return false;
338  }
339  return true;
340 
341 }
342 
343 bool
345 
346  if ( !muonRef.isNonnull() ) return false;
347  if ( !muonRef->isGlobalMuon() ) return false;
348  if ( !muonRef->isStandAloneMuon() ) return false;
349 
350  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
351  reco::TrackRef combinedMu = muonRef->combinedMuon();
352  reco::TrackRef trackerMu = muonRef->track();
353 
354  unsigned nMuonHits =
355  standAloneMu->hitPattern().numberOfValidMuonDTHits() +
356  2*standAloneMu->hitPattern().numberOfValidMuonCSCHits();
357 
358  bool quality = false;
359 
360  if ( muonRef->isTrackerMuon() ){
361 
362  bool result = combinedMu->normalizedChi2() < 100.;
363 
364  bool laststation =
366 
367  int nMatches = muonRef->numberOfMatches();
368 
369  quality = laststation && nMuonHits > 12 && nMatches > 1;
370 
371  return result && quality;
372 
373  }
374  else{
375 
376  // Check the quality of the stand-alone muon :
377  // good chi**2 and large number of hits and good pt error
378  if ( nMuonHits <=15 ||
379  standAloneMu->normalizedChi2() > 10. ||
380  standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
381  quality = false;
382  }
383  else {
384  // If the stand-alone muon is good, check the global muon
385  if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
386  // If the combined muon is worse than the stand-alone, it
387  // means that either the corresponding tracker track was not
388  // reconstructed, or that the sta muon comes from a late
389  // pion decay (hence with a momentum smaller than the track)
390  // Take the stand-alone muon only if its momentum is larger
391  // than that of the track
392 
393  // Note that here we even take the standAlone if it has a smaller pT, in contrast to GlobalTight
394  if(standAloneMu->pt() > trackerMu->pt() || combinedMu->normalizedChi2()<5.) quality = true;
395  }
396  else {
397  // If the combined muon is better (and good enough), take the
398  // global muon
399  if(combinedMu->ptError()/combinedMu->pt() < std::min(0.20,standAloneMu->ptError()/standAloneMu->pt()))
400  quality = true;
401 
402  }
403  }
404  }
405 
406 
407  return quality;
408 
409 }
410 
411 
412 bool
414 
415  if ( !muonRef.isNonnull() ) return false;
416  if(!muonRef->isTrackerMuon()) return false;
417 
418  reco::TrackRef trackerMu = muonRef->track();
419 
420  if(trackerMu->ptError()/trackerMu->pt() > 0.20) return false;
421 
422  // this doesn't seem to be necessary on the small samples looked at, but keep it around as insurance
423  if(trackerMu->pt()>20.) return false;
424 
425  bool isAllArbitrated = muon::isGoodMuon(*muonRef,muon::AllArbitrated);
426  bool isTMLastStationAngTight = muon::isGoodMuon(*muonRef,muon::TMLastStationAngTight);
427 
428  bool quality = isAllArbitrated && isTMLastStationAngTight;
429 
430  return quality;
431 
432 }
433 
434 bool
436 
437 
438  if ( !muonRef.isNonnull() ) return false;
439  if ( !muonRef->isIsolationValid() ) return false;
440 
441  // Isolated Muons which are missed by standard cuts are nearly always global+tracker
442  if ( !muonRef->isGlobalMuon() ) return false;
443 
444  // If it's not a tracker muon, only take it if there are valid muon hits
445 
446  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
447 
448  if ( !muonRef->isTrackerMuon() ){
449  if(standAloneMu->hitPattern().numberOfValidMuonDTHits() == 0 &&
450  standAloneMu->hitPattern().numberOfValidMuonCSCHits() ==0) return false;
451  }
452 
453  // for isolation, take the smallest pt available to reject fakes
454 
455  reco::TrackRef combinedMu = muonRef->combinedMuon();
456  double smallestMuPt = combinedMu->pt();
457 
458  if(standAloneMu->pt()<smallestMuPt) smallestMuPt = standAloneMu->pt();
459 
460  if(muonRef->isTrackerMuon())
461  {
462  reco::TrackRef trackerMu = muonRef->track();
463  if(trackerMu->pt() < smallestMuPt) smallestMuPt= trackerMu->pt();
464  }
465 
466 
467  double sumPtR03 = muonRef->isolationR03().sumPt;
468 
469  double relIso = sumPtR03/smallestMuPt;
470 
471 
472 
473 
474  if(relIso<0.1) return true;
475  else return false;
476 }
477 
478 bool
480 
481  if(!muon::isGoodMuon(*muonRef,muon::GlobalMuonPromptTight)) return false;
482 
483  if(!muonRef->isTrackerMuon()) return false;
484 
485  if(muonRef->numberOfMatches()<2) return false;
486 
487  //const reco::TrackRef& combinedMuon = muonRef->combinedMuon();
488  const reco::TrackRef& combinedMuon = muonRef->globalTrack();
489 
490  if(combinedMuon->hitPattern().numberOfValidTrackerHits()<11) return false;
491 
492  if(combinedMuon->hitPattern().numberOfValidPixelHits()==0) return false;
493 
494  if(combinedMuon->hitPattern().numberOfValidMuonHits()==0) return false;
495 
496  return true;
497 
498 }
499 
500 
501 bool
502 PFMuonAlgo::hasValidTrack(const reco::MuonRef& muonRef,bool loose) {
503  if(loose)
504  return muonTracks(muonRef).size()>0;
505  else
506  return goodMuonTracks(muonRef).size()>0;
507 
508 }
509 
510 
511 void
513 
514  if ( !muonRef.isNonnull() ) return;
515 
516  bool isGL = muonRef->isGlobalMuon();
517  bool isTR = muonRef->isTrackerMuon();
518  bool isST = muonRef->isStandAloneMuon();
519 
520  std::cout<<" GL: "<<isGL<<" TR: "<<isTR<<" ST: "<<isST<<std::endl;
521  std::cout<<" nMatches "<<muonRef->numberOfMatches()<<std::endl;
522 
523  if ( muonRef->isGlobalMuon() ){
524  reco::TrackRef combinedMu = muonRef->combinedMuon();
525  std::cout<<" GL, pt: " << combinedMu->pt()
526  << " +/- " << combinedMu->ptError()/combinedMu->pt()
527  << " chi**2 GBL : " << combinedMu->normalizedChi2()<<std::endl;
528  std::cout<< " Total Muon Hits : " << combinedMu->hitPattern().numberOfValidMuonHits()
529  << "/" << combinedMu->hitPattern().numberOfLostMuonHits()
530  << " DT Hits : " << combinedMu->hitPattern().numberOfValidMuonDTHits()
531  << "/" << combinedMu->hitPattern().numberOfLostMuonDTHits()
532  << " CSC Hits : " << combinedMu->hitPattern().numberOfValidMuonCSCHits()
533  << "/" << combinedMu->hitPattern().numberOfLostMuonCSCHits()
534  << " RPC Hits : " << combinedMu->hitPattern().numberOfValidMuonRPCHits()
535  << "/" << combinedMu->hitPattern().numberOfLostMuonRPCHits()<<std::endl;
536 
537  std::cout<<" # of Valid Tracker Hits "<<combinedMu->hitPattern().numberOfValidTrackerHits()<<std::endl;
538  std::cout<<" # of Valid Pixel Hits "<<combinedMu->hitPattern().numberOfValidPixelHits()<<std::endl;
539  }
540  if ( muonRef->isStandAloneMuon() ){
541  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
542  std::cout<<" ST, pt: " << standAloneMu->pt()
543  << " +/- " << standAloneMu->ptError()/standAloneMu->pt()
544  << " eta : " << standAloneMu->eta()
545  << " DT Hits : " << standAloneMu->hitPattern().numberOfValidMuonDTHits()
546  << "/" << standAloneMu->hitPattern().numberOfLostMuonDTHits()
547  << " CSC Hits : " << standAloneMu->hitPattern().numberOfValidMuonCSCHits()
548  << "/" << standAloneMu->hitPattern().numberOfLostMuonCSCHits()
549  << " RPC Hits : " << standAloneMu->hitPattern().numberOfValidMuonRPCHits()
550  << "/" << standAloneMu->hitPattern().numberOfLostMuonRPCHits()
551  << " chi**2 STA : " << standAloneMu->normalizedChi2()<<std::endl;
552  }
553 
554 
555  if ( muonRef->isTrackerMuon() ){
556  reco::TrackRef trackerMu = muonRef->track();
557  const reco::Track& track = *trackerMu;
558  std::cout<<" TR, pt: " << trackerMu->pt()
559  << " +/- " << trackerMu->ptError()/trackerMu->pt()
560  << " chi**2 TR : " << trackerMu->normalizedChi2()<<std::endl;
561  std::cout<<" nTrackerHits "<<track.hitPattern().numberOfValidTrackerHits()<<std::endl;
562  std::cout<< "TMLastStationAngLoose "
563  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngLoose) << std::endl
564  << "TMLastStationAngTight "
565  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngTight) << std::endl
566  << "TMLastStationLoose "
567  << muon::isGoodMuon(*muonRef,muon::TMLastStationLoose) << std::endl
568  << "TMLastStationTight "
569  << muon::isGoodMuon(*muonRef,muon::TMLastStationTight) << std::endl
570  << "TMOneStationLoose "
571  << muon::isGoodMuon(*muonRef,muon::TMOneStationLoose) << std::endl
572  << "TMOneStationTight "
573  << muon::isGoodMuon(*muonRef,muon::TMOneStationTight) << std::endl
574  << "TMLastStationOptimizedLowPtLoose "
576  << "TMLastStationOptimizedLowPtTight "
578  << "TMLastStationOptimizedBarrelLowPtLoose "
580  << "TMLastStationOptimizedBarrelLowPtTight "
582  << std::endl;
583 
584  }
585 
586  std::cout<< "TM2DCompatibilityLoose "
587  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityLoose) << std::endl
588  << "TM2DCompatibilityTight "
589  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight) << std::endl;
590 
591 
592 
593  if ( muonRef->isGlobalMuon() && muonRef->isTrackerMuon() && muonRef->isStandAloneMuon() ){
594  reco::TrackRef combinedMu = muonRef->combinedMuon();
595  reco::TrackRef trackerMu = muonRef->track();
596  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
597 
598  double sigmaCombined = combinedMu->ptError()/(combinedMu->pt()*combinedMu->pt());
599  double sigmaTracker = trackerMu->ptError()/(trackerMu->pt()*trackerMu->pt());
600  double sigmaStandAlone = standAloneMu->ptError()/(standAloneMu->pt()*standAloneMu->pt());
601 
602  bool combined = combinedMu->ptError()/combinedMu->pt() < 0.20;
603  bool tracker = trackerMu->ptError()/trackerMu->pt() < 0.20;
604  bool standAlone = standAloneMu->ptError()/standAloneMu->pt() < 0.20;
605 
606  double delta1 = combined && tracker ?
607  fabs(1./combinedMu->pt() -1./trackerMu->pt())
608  /sqrt(sigmaCombined*sigmaCombined + sigmaTracker*sigmaTracker) : 100.;
609  double delta2 = combined && standAlone ?
610  fabs(1./combinedMu->pt() -1./standAloneMu->pt())
611  /sqrt(sigmaCombined*sigmaCombined + sigmaStandAlone*sigmaStandAlone) : 100.;
612  double delta3 = standAlone && tracker ?
613  fabs(1./standAloneMu->pt() -1./trackerMu->pt())
614  /sqrt(sigmaStandAlone*sigmaStandAlone + sigmaTracker*sigmaTracker) : 100.;
615 
616  double delta =
617  standAloneMu->hitPattern().numberOfValidMuonDTHits()+
618  standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0 ?
619  std::min(delta3,std::min(delta1,delta2)) : std::max(delta3,std::max(delta1,delta2));
620 
621  std::cout << "delta = " << delta << " delta1 "<<delta1<<" delta2 "<<delta2<<" delta3 "<<delta3<<std::endl;
622 
623  double ratio =
624  combinedMu->ptError()/combinedMu->pt()
625  / (trackerMu->ptError()/trackerMu->pt());
626  //if ( ratio > 2. && delta < 3. ) std::cout << "ALARM ! " << ratio << ", " << delta << std::endl;
627  std::cout<<" ratio "<<ratio<<" combined mu pt "<<combinedMu->pt()<<std::endl;
628  //bool quality3 = ( combinedMu->pt() < 50. || ratio < 2. ) && delta < 3.;
629 
630 
631  }
632 
633  double sumPtR03 = muonRef->isolationR03().sumPt;
634  double emEtR03 = muonRef->isolationR03().emEt;
635  double hadEtR03 = muonRef->isolationR03().hadEt;
636  double relIsoR03 = (sumPtR03 + emEtR03 + hadEtR03)/muonRef->pt();
637  double sumPtR05 = muonRef->isolationR05().sumPt;
638  double emEtR05 = muonRef->isolationR05().emEt;
639  double hadEtR05 = muonRef->isolationR05().hadEt;
640  double relIsoR05 = (sumPtR05 + emEtR05 + hadEtR05)/muonRef->pt();
641  std::cout<<" 0.3 Radion Rel Iso: "<<relIsoR03<<" sumPt "<<sumPtR03<<" emEt "<<emEtR03<<" hadEt "<<hadEtR03<<std::endl;
642  std::cout<<" 0.5 Radion Rel Iso: "<<relIsoR05<<" sumPt "<<sumPtR05<<" emEt "<<emEtR05<<" hadEt "<<hadEtR05<<std::endl;
643  return;
644 
645 }
646 
647 
648 
649 std::vector<reco::Muon::MuonTrackTypePair> PFMuonAlgo::goodMuonTracks(const reco::MuonRef& muon,bool includeSA) {
650  return muonTracks(muon,includeSA,maxDPtOPt_);
651 }
652 
653 
654 
655 std::vector<reco::Muon::MuonTrackTypePair> PFMuonAlgo::muonTracks(const reco::MuonRef& muon,bool includeSA,double dpt) {
656 
657 
658 
659  std::vector<reco::Muon::MuonTrackTypePair> out;
660 
661 
662  if(muon->globalTrack().isNonnull() && muon->globalTrack()->pt()>0)
663  if(muon->globalTrack()->ptError()/muon->globalTrack()->pt()<dpt)
664  out.push_back(std::make_pair(muon->globalTrack(),reco::Muon::CombinedTrack));
665 
666  if(muon->innerTrack().isNonnull() && muon->innerTrack()->pt()>0)
667  if(muon->innerTrack()->ptError()/muon->innerTrack()->pt()<dpt)//Here Loose!@
668  out.push_back(std::make_pair(muon->innerTrack(),reco::Muon::InnerTrack));
669 
670  bool pickyExists=false;
671  double pickyDpt=99999.;
672  if(muon->pickyTrack().isNonnull() && muon->pickyTrack()->pt()>0) {
673  pickyDpt = muon->pickyTrack()->ptError()/muon->pickyTrack()->pt();
674  if(pickyDpt<dpt)
675  out.push_back(std::make_pair(muon->pickyTrack(),reco::Muon::Picky));
676  pickyExists=true;
677  }
678 
679  bool dytExists=false;
680  double dytDpt=99999.;
681  if(muon->dytTrack().isNonnull() && muon->dytTrack()->pt()>0) {
682  dytDpt = muon->dytTrack()->ptError()/muon->dytTrack()->pt();
683  if(dytDpt<dpt)
684  out.push_back(std::make_pair(muon->dytTrack(),reco::Muon::DYT));
685  dytExists=true;
686  }
687 
688  //Magic: TPFMS is not a really good track especially under misalignment
689  //IT is kind of crap because if mu system is displaced it can make a change
690  //So allow TPFMS if there is no picky or the error of tpfms is better than picky
691  //AND if there is no DYT or the error of tpfms is better than DYT
692  if(muon->tpfmsTrack().isNonnull() && muon->tpfmsTrack()->pt()>0) {
693  double tpfmsDpt = muon->tpfmsTrack()->ptError()/muon->tpfmsTrack()->pt();
694  if( ( (pickyExists && tpfmsDpt<pickyDpt) || (!pickyExists) ) &&
695  ( (dytExists && tpfmsDpt<dytDpt) || (!dytExists) ) &&
696  tpfmsDpt<dpt )
697  out.push_back(std::make_pair(muon->tpfmsTrack(),reco::Muon::TPFMS));
698  }
699 
700  if(includeSA && muon->outerTrack().isNonnull())
701  if(muon->outerTrack()->ptError()/muon->outerTrack()->pt()<dpt)
702  out.push_back(std::make_pair(muon->outerTrack(),reco::Muon::OuterTrack));
703 
704  return out;
705 
706 }
707 
708 
709 
710 
711 
713 
714 
715 
716 
717 bool PFMuonAlgo::reconstructMuon(reco::PFCandidate& candidate, const reco::MuonRef& muon, bool allowLoose) {
718  using namespace std;
719  using namespace reco;
720 
721  if (!muon.isNonnull())
722  return false;
723 
724 
725 
726 
727  bool isMu=false;
728 
729  if(allowLoose)
730  isMu = isMuon(muon) || isLooseMuon(muon);
731  else
732  isMu = isMuon(muon);
733 
734  if( !isMu)
735  return false;
736 
737 
738 
739 
740 
741  //get the valid tracks(without standalone except we allow loose muons)
742  //MIKE: Here we need to be careful. If we have a muon inside a dense
743  //jet environment often the track is badly measured. In this case
744  //we should not apply Dpt/Pt<1
745 
746  std::vector<reco::Muon::MuonTrackTypePair> validTracks = goodMuonTracks(muon);
747  if (!allowLoose)
748  validTracks = goodMuonTracks(muon);
749  else
750  validTracks = muonTracks(muon);
751 
752  if( validTracks.size() ==0)
753  return false;
754 
755 
756 
757 
758  //check what is the track used.Rerun TuneP
759  reco::Muon::MuonTrackTypePair bestTrackPair = muon::tevOptimized(*muon);
760 
761  TrackRef bestTrack = bestTrackPair.first;
762  MuonTrackType trackType = bestTrackPair.second;
763 
764 
765 
766  MuonTrackTypePair trackPairWithSmallestError = getTrackWithSmallestError(validTracks);
767  TrackRef trackWithSmallestError = trackPairWithSmallestError.first;
768 
769  if( trackType == reco::Muon::InnerTrack &&
770  (!bestTrack->quality(trackQuality_) ||
771  bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt() )) {
772  bestTrack = trackWithSmallestError;
773  trackType = trackPairWithSmallestError.second;
774  }
775  else if (trackType != reco::Muon::InnerTrack &&
776  bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt()) {
777  bestTrack = trackWithSmallestError;
778  trackType = trackPairWithSmallestError.second;
779 
780  }
781 
782 
783  changeTrack(candidate,std::make_pair(bestTrack,trackType));
784  candidate.setMuonRef( muon );
785 
786  return true;
787 }
788 
789 
790 
791 
793  using namespace reco;
794  reco::TrackRef bestTrack = track.first;
795  MuonTrackType trackType = track.second;
796  //OK Now redefine the canddiate with that track
797  double px = bestTrack->px();
798  double py = bestTrack->py();
799  double pz = bestTrack->pz();
800  double energy = sqrt(bestTrack->p()*bestTrack->p() + 0.1057*0.1057);
801 
802  candidate.setCharge(bestTrack->charge()>0 ? 1 : -1);
803  candidate.setP4(math::XYZTLorentzVector(px,py,pz,energy));
805  // candidate.setTrackRef( bestTrack );
806  candidate.setMuonTrackType(trackType);
807  if(trackType == reco::Muon::InnerTrack)
808  candidate.setVertexSource( PFCandidate::kTrkMuonVertex );
809  else if(trackType == reco::Muon::CombinedTrack)
810  candidate.setVertexSource( PFCandidate::kComMuonVertex );
811  else if(trackType == reco::Muon::TPFMS)
812  candidate.setVertexSource( PFCandidate::kTPFMSMuonVertex );
813  else if(trackType == reco::Muon::Picky)
814  candidate.setVertexSource( PFCandidate::kPickyMuonVertex );
815  else if(trackType == reco::Muon::DYT)
816  candidate.setVertexSource( PFCandidate::kDYTMuonVertex );
817  }
818 
819 
821 PFMuonAlgo::getTrackWithSmallestError(const std::vector<reco::Muon::MuonTrackTypePair>& tracks) {
823  return *std::min_element(tracks.begin(),tracks.end(),sorter);
824 }
825 
826 
827 
828 
829 
831 {
832  //SUM ET
833  sumetPU_ = 0.0;
834  METX_=0.;
835  METY_=0.;
836  sumet_=0.0;
837  for(reco::PFCandidateCollection::const_iterator i = pfc->begin();i!=pfc->end();++i) {
838  sumet_+=i->pt();
839  METX_+=i->px();
840  METY_+=i->py();
841  }
842 
843 }
844 
845 
846 
847 
848 
850  using namespace std;
851  using namespace reco;
852  if (!postCleaning_)
853  return;
854 
855  //Initialize vectors
856 
857  if(pfCosmicsMuonCleanedCandidates_.get() )
858  pfCosmicsMuonCleanedCandidates_->clear();
859  else
860  pfCosmicsMuonCleanedCandidates_.reset( new reco::PFCandidateCollection );
861 
862  if(pfCleanedTrackerAndGlobalMuonCandidates_.get() )
863  pfCleanedTrackerAndGlobalMuonCandidates_->clear();
864  else
865  pfCleanedTrackerAndGlobalMuonCandidates_.reset( new reco::PFCandidateCollection );
866 
867  if( pfFakeMuonCleanedCandidates_.get() )
868  pfFakeMuonCleanedCandidates_->clear();
869  else
870  pfFakeMuonCleanedCandidates_.reset( new reco::PFCandidateCollection );
871 
872 
873  if( pfPunchThroughMuonCleanedCandidates_.get() )
874  pfPunchThroughMuonCleanedCandidates_->clear();
875  else
876  pfPunchThroughMuonCleanedCandidates_.reset( new reco::PFCandidateCollection );
877 
878  if( pfPunchThroughHadronCleanedCandidates_.get() )
879  pfPunchThroughHadronCleanedCandidates_->clear();
880  else
881  pfPunchThroughHadronCleanedCandidates_.reset( new reco::PFCandidateCollection );
882 
883 
884 
885  pfPunchThroughHadronCleanedCandidates_->clear();
886 
887  maskedIndices_.clear();
888 
889  //Estimate MET and SumET
890 
891  estimateEventQuantities(cands);
892 
893 
894  std::vector<int> muons;
895  std::vector<int> cosmics;
896  //get the muons
897  for(unsigned int i=0;i<cands->size();++i) {
898  const reco::PFCandidate& cand = (*cands)[i];
899  if ( cand.particleId() == reco::PFCandidate::mu )
900  muons.push_back(i);
901 
902  }
903  //Then sort the muon indicess by decsending pt
904 
905  IndexPtComparator comparator(cands);
906  std::sort(muons.begin(),muons.end(),comparator);
907 
908 
909  //first kill cosmics
910  double METXCosmics=0;
911  double METYCosmics=0;
912  double SUMETCosmics=0.0;
913 
914  for(unsigned int i=0;i<muons.size();++i) {
915  const PFCandidate& pfc = cands->at(muons[i]);
916  double origin=0.0;
917  if(vertices_->size()>0&& vertices_->at(0).isValid() && ! vertices_->at(0).isFake())
918  origin = pfc.muonRef()->muonBestTrack()->dxy(vertices_->at(0).position());
919 
920  if( origin> cosmicRejDistance_) {
921  cosmics.push_back(muons[i]);
922  METXCosmics +=pfc.px();
923  METYCosmics +=pfc.py();
924  SUMETCosmics +=pfc.pt();
925  }
926  }
927  double MET2Cosmics = METXCosmics*METXCosmics+METYCosmics*METYCosmics;
928 
929  if ( SUMETCosmics > (sumet_-sumetPU_)/eventFactorCosmics_ && MET2Cosmics < METX_*METX_+ METY_*METY_)
930  for(unsigned int i=0;i<cosmics.size();++i) {
931  maskedIndices_.push_back(cosmics[i]);
932  pfCosmicsMuonCleanedCandidates_->push_back(cands->at(cosmics[i]));
933  }
934 
935  //Loop on the muons candidates and clean
936  for(unsigned int i=0;i<muons.size();++i) {
937  if( cleanMismeasured(cands->at(muons[i]),muons[i]))
938  continue;
939  cleanPunchThroughAndFakes(cands->at(muons[i]),cands,muons[i]);
940 
941  }
942 
943 
944 
945  //OK Now do the hard job ->remove the candidates that were cleaned
946  removeDeadCandidates(cands,maskedIndices_);
947 
948 
949 
950 
951 }
952 
954  if(!postCleaning_)
955  return;
956 
957 
958  if( pfAddedMuonCandidates_.get() )
959  pfAddedMuonCandidates_->clear();
960  else
961  pfAddedMuonCandidates_.reset( new reco::PFCandidateCollection );
962 
963 
964 
965  for ( unsigned imu = 0; imu < muons->size(); ++imu ) {
966  reco::MuonRef muonRef( muons, imu );
967  bool used = false;
968  bool hadron = false;
969  for(unsigned i=0; i<cands->size(); i++) {
970  const PFCandidate& pfc = cands->at(i);
971  if ( !pfc.trackRef().isNonnull() ) continue;
972  if ( pfc.trackRef().isNonnull() && pfc.trackRef() == muonRef->track() )
973  hadron = true;
974  if ( !pfc.muonRef().isNonnull() ) continue;
975 
976  if ( pfc.muonRef()->innerTrack() == muonRef->innerTrack())
977  used = true;
978  else {
979  // Check if the stand-alone muon is not a spurious copy of an existing muon
980  // (Protection needed for HLT)
981  if ( pfc.muonRef()->isStandAloneMuon() && muonRef->isStandAloneMuon() ) {
982  double dEta = pfc.muonRef()->standAloneMuon()->eta() - muonRef->standAloneMuon()->eta();
983  double dPhi = pfc.muonRef()->standAloneMuon()->phi() - muonRef->standAloneMuon()->phi();
984  double dR = sqrt(dEta*dEta + dPhi*dPhi);
985  if ( dR < 0.005 ) {
986  used = true;
987  }
988  }
989  }
990 
991  if ( used ) break;
992  }
993 
994  if ( used ||hadron||(!muonRef.isNonnull()) ) continue;
995 
996 
997  TrackMETComparator comparator(METX_,METY_);
998  //Low pt dont need to be cleaned
999 
1000  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks(muonRef,true);
1001  //If there is at least 1 track choice try to change the track
1002  if(tracks.size()>0) {
1003 
1004  //Find tracks that change dramatically MET or Pt
1005  std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksPointingAtMET(tracks);
1006  //From those tracks get the one with smallest MET
1007  if (tracksThatChangeMET.size()>0) {
1008  reco::Muon::MuonTrackTypePair bestTrackType = *std::min_element(tracksThatChangeMET.begin(),tracksThatChangeMET.end(),comparator);
1009 
1010  //Make sure it is not cosmic
1011  if((vertices_->size()==0) ||bestTrackType.first->dz(vertices_->at(0).position())<cosmicRejDistance_){
1012 
1013  //make a pfcandidate
1014  int charge = bestTrackType.first->charge()>0 ? 1 : -1;
1015  math::XYZTLorentzVector momentum(bestTrackType.first->px(),
1016  bestTrackType.first->py(),
1017  bestTrackType.first->pz(),
1018  sqrt(bestTrackType.first->p()*bestTrackType.first->p()+0.1057*0.1057));
1019 
1020  cands->push_back( PFCandidate( charge,
1021  momentum,
1023 
1024  changeTrack(cands->back(),bestTrackType);
1025 
1026  if (muonRef->track().isNonnull() )
1027  cands->back().setTrackRef( muonRef->track() );
1028 
1029  cands->back().setMuonRef(muonRef);
1030 
1031 
1032  pfAddedMuonCandidates_->push_back(cands->back());
1033 
1034  }
1035  }
1036  }
1037  }
1038 }
1039 
1040 std::pair<double,double>
1042  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks((pfc.muonRef()),true);
1043 
1044  double METXNO = METX_-pfc.px();
1045  double METYNO = METY_-pfc.py();
1046  std::vector<double> met2;
1047  for (unsigned int i=0;i<tracks.size();++i) {
1048  met2.push_back(pow(METXNO+tracks.at(i).first->px(),2)+pow(METYNO+tracks.at(i).first->py(),2));
1049  }
1050 
1051  //PROTECT for cases of only one track. If there is only one track it will crash .
1052  //Has never happened but could likely happen!
1053 
1054  if(tracks.size()>1)
1055  return std::make_pair(*std::min_element(met2.begin(),met2.end()),*std::max_element(met2.begin(),met2.end()));
1056  else
1057  return std::make_pair(0,0);
1058 }
1059 
1060 
1062  using namespace std;
1063  using namespace reco;
1064  bool cleaned=false;
1065 
1066  //First define the MET without this guy
1067  double METNOX = METX_ - pfc.px();
1068  double METNOY = METY_ - pfc.py();
1069  double SUMETNO = sumet_ -pfc.pt();
1070 
1071  TrackMETComparator comparator(METNOX,METNOY);
1072  //Low pt dont need to be cleaned
1073  if (pfc.pt()<minPostCleaningPt_)
1074  return false;
1075  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks(pfc.muonRef(),false);
1076 
1077 
1078 
1079  //If there is more than 1 track choice try to change the track
1080  if(tracks.size()>1) {
1081  //Find tracks that change dramatically MET or Pt
1082  std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksWithBetterMET(tracks,pfc);
1083  //From those tracks get the one with smallest MET
1084  if (tracksThatChangeMET.size()>0) {
1085  reco::Muon::MuonTrackTypePair bestTrackType = *std::min_element(tracksThatChangeMET.begin(),tracksThatChangeMET.end(),comparator);
1086  changeTrack(pfc,bestTrackType);
1087 
1088  pfCleanedTrackerAndGlobalMuonCandidates_->push_back(pfc);
1089  //update eventquantities
1090  METX_ = METNOX+pfc.px();
1091  METY_ = METNOY+pfc.py();
1092  sumet_=SUMETNO+pfc.pt();
1093 
1094  }
1095  }
1096 
1097  //Now attempt to kill it
1098  if (!(pfc.muonRef()->isGlobalMuon() && pfc.muonRef()->isTrackerMuon())) {
1099  //define MET significance and SUM ET
1100  double MET2 = METX_*METX_+METY_*METY_;
1101  double newMET2 = METNOX*METNOX+METNOY*METNOY;
1102  double METSig = sqrt(MET2)/sqrt(sumet_-sumetPU_);
1103  if( METSig>metSigForRejection_)
1104  if((newMET2 < MET2/metFactorRejection_) &&
1105  ((SUMETNO-sumetPU_)/(sumet_-sumetPU_)<eventFractionRejection_)) {
1106  pfFakeMuonCleanedCandidates_->push_back(pfc);
1107  maskedIndices_.push_back(i);
1108  METX_ = METNOX;
1109  METY_ = METNOY;
1110  sumet_=SUMETNO;
1111  cleaned=true;
1112  }
1113 
1114  }
1115  return cleaned;
1116 
1117 }
1118 
1119 std::vector<reco::Muon::MuonTrackTypePair>
1120 PFMuonAlgo::tracksWithBetterMET(const std::vector<reco::Muon::MuonTrackTypePair>& tracks ,const reco::PFCandidate& pfc) {
1121  std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
1122 
1123  double METNOX = METX_ - pfc.px();
1124  double METNOY = METY_ - pfc.py();
1125  double SUMETNO = sumet_ -pfc.pt();
1126  double MET2 = METX_*METX_+METY_*METY_;
1127  double newMET2=0.0;
1128  double newSUMET=0.0;
1129  double METSIG = sqrt(MET2)/sqrt(sumet_-sumetPU_);
1130 
1131 
1132  if(METSIG>metSigForCleaning_)
1133  for( unsigned int i=0;i<tracks.size();++i) {
1134  //calculate new SUM ET and MET2
1135  newSUMET = SUMETNO+tracks.at(i).first->pt()-sumetPU_;
1136  newMET2 = pow(METNOX+tracks.at(i).first->px(),2)+pow(METNOY+tracks.at(i).first->py(),2);
1137 
1138  if(newSUMET/(sumet_-sumetPU_)>eventFractionCleaning_ && newMET2<MET2/metFactorCleaning_)
1139  outputTracks.push_back(tracks.at(i));
1140  }
1141 
1142 
1143  return outputTracks;
1144 }
1145 
1146 
1147 std::vector<reco::Muon::MuonTrackTypePair>
1148 PFMuonAlgo::tracksPointingAtMET(const std::vector<reco::Muon::MuonTrackTypePair>& tracks) {
1149  std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
1150 
1151 
1152  double newMET2=0.0;
1153 
1154  for( unsigned int i=0;i<tracks.size();++i) {
1155  //calculate new SUM ET and MET2
1156  newMET2 = pow(METX_+tracks.at(i).first->px(),2)+pow(METY_+tracks.at(i).first->py(),2);
1157 
1158  if(newMET2<(METX_*METX_+METY_*METY_)/metFactorCleaning_)
1159  outputTracks.push_back(tracks.at(i));
1160  }
1161 
1162 
1163  return outputTracks;
1164 }
1165 
1166 
1167 
1169  vertices_ = vertices;
1170 }
1171 
1173  using namespace reco;
1174 
1175  bool cleaned=false;
1176 
1177  if (pfc.pt()<minPostCleaningPt_)
1178  return false;
1179 
1180 
1181  double METXNO = METX_-pfc.pt();
1182  double METYNO = METY_-pfc.pt();
1183  double MET2NO = METXNO*METXNO+METYNO*METYNO;
1184  double MET2 = METX_*METX_+METY_*METY_;
1185  bool fake1=false;
1186 
1187  std::pair<double,double> met2 = getMinMaxMET2(pfc);
1188 
1189  //Check for Fakes at high pseudorapidity
1190  if(pfc.muonRef()->standAloneMuon().isNonnull())
1191  fake1 =fabs ( pfc.eta() ) > 2.15 &&
1192  met2.first<met2.second/2 &&
1193  MET2NO < MET2/metFactorHighEta_ &&
1194  pfc.muonRef()->standAloneMuon()->pt() < pfc.pt()/ptFactorHighEta_;
1195 
1196  double factor = std::max(2.,2000./(sumet_-pfc.pt()-sumetPU_));
1197  bool fake2 = ( pfc.pt()/(sumet_-sumetPU_) < 0.25 && MET2NO < MET2/metFactorFake_ && met2.first<met2.second/factor );
1198 
1199  bool punchthrough =pfc.p() > minPunchThroughMomentum_ &&
1200  pfc.rawHcalEnergy() > minPunchThroughEnergy_ &&
1201  pfc.rawEcalEnergy()+pfc.rawHcalEnergy() > pfc.p()/punchThroughFactor_ &&
1202  !isIsolatedMuon(pfc.muonRef()) && MET2NO < MET2/punchThroughMETFactor_;
1203 
1204 
1205  if(fake1 || fake2||punchthrough) {
1206  // Find the block of the muon
1207  const PFCandidate::ElementsInBlocks& eleInBlocks = pfc.elementsInBlocks();
1208  if ( eleInBlocks.size() ) {
1209  PFBlockRef blockRefMuon = eleInBlocks[0].first;
1210  unsigned indexMuon = eleInBlocks[0].second;
1211  if (eleInBlocks.size()>1)
1212  indexMuon = eleInBlocks[1].second;
1213 
1214  // Check if the muon gave rise to a neutral hadron
1215  double iHad = 1E9;
1216  bool hadron = false;
1217  for ( unsigned i = imu+1; i < cands->size(); ++i ) {
1218  const PFCandidate& pfcn = cands->at(i);
1219  const PFCandidate::ElementsInBlocks& ele = pfcn.elementsInBlocks();
1220  if ( !ele.size() ) {
1221  continue;
1222  }
1223  PFBlockRef blockRefHadron = ele[0].first;
1224  unsigned indexHadron = ele[0].second;
1225  // We are out of the block -> exit the loop
1226  if ( blockRefHadron.key() != blockRefMuon.key() ) break;
1227  // Check that this particle is a neutral hadron
1228  if ( indexHadron == indexMuon &&
1229  pfcn.particleId() == reco::PFCandidate::h0 ) {
1230  iHad = i;
1231  hadron = true;
1232  }
1233  if ( hadron ) break;
1234  }
1235 
1236  if ( hadron ) {
1237 
1238  double rescaleFactor = cands->at(iHad).p()/cands->at(imu).p();
1239  METX_ -= cands->at(imu).px() + cands->at(iHad).px();
1240  METY_ -= cands->at(imu).py() + cands->at(iHad).py();
1241  sumet_ -=cands->at(imu).pt();
1242  cands->at(imu).rescaleMomentum(rescaleFactor);
1243  maskedIndices_.push_back(iHad);
1244  pfPunchThroughHadronCleanedCandidates_->push_back(cands->at(iHad));
1245  cands->at(imu).setParticleType(reco::PFCandidate::h);
1246  pfPunchThroughMuonCleanedCandidates_->push_back(cands->at(imu));
1247  METX_ += cands->at(imu).px();
1248  METY_ += cands->at(imu).py();
1249  sumet_ += cands->at(imu).pt();
1250 
1251  } else if ( fake1 || fake2 ) {
1252  METX_ -= cands->at(imu).px();
1253  METY_ -= cands->at(imu).py();
1254  sumet_ -= cands->at(imu).pt();
1255  maskedIndices_.push_back(imu);
1256  pfFakeMuonCleanedCandidates_->push_back(cands->at(imu));
1257  cleaned=true;
1258  }
1259  }
1260  }
1261  return cleaned;
1262 }
1263 
1264 
1265 void PFMuonAlgo::removeDeadCandidates(reco::PFCandidateCollection* obj, const std::vector<unsigned int>& indices)
1266 {
1267  size_t N = indices.size();
1268  size_t collSize = obj->size();
1269 
1270  for (size_t i = 0 ; i < N ; ++i)
1271  obj->at(indices.at(i)) = obj->at(collSize-i-1);
1272 
1273  obj->resize(collSize - indices.size());
1274 }
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
Abstract base class for a PFBlock element (track, cluster...)
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:227
bool cleanMismeasured(reco::PFCandidate &, unsigned int)
Definition: PFMuonAlgo.cc:1061
static bool isTightMuonPOG(const reco::MuonRef &muonRef)
Definition: PFMuonAlgo.cc:479
void removeDeadCandidates(reco::PFCandidateCollection *, const std::vector< unsigned int > &)
Definition: PFMuonAlgo.cc:1265
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:224
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
Definition: PFMuonAlgo.cc:953
Definition: CLHEP.h:16
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:155
virtual double eta() const final
momentum pseudorapidity
static bool isTrackerLooseMuon(const reco::PFBlockElement &elt)
void setParameters(const edm::ParameterSet &)
Definition: PFMuonAlgo.cc:29
static bool isGlobalLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:201
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool cleanPunchThroughAndFakes(reco::PFCandidate &, reco::PFCandidateCollection *, unsigned int)
Definition: PFMuonAlgo.cc:1172
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
reco::Muon::MuonTrackTypePair MuonTrackTypePair
Definition: PFMuonAlgo.h:14
key_type key() const
Accessor for product key.
Definition: Ref.h:265
static void printMuonProperties(const reco::MuonRef &muonRef)
Definition: PFMuonAlgo.cc:512
std::vector< MuonTrackTypePair > tracksPointingAtMET(const std::vector< MuonTrackTypePair > &)
Definition: PFMuonAlgo.cc:1148
bool hasValidTrack(const reco::MuonRef &muonRef, bool loose=false)
Definition: PFMuonAlgo.cc:502
static bool isGlobalTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:188
std::vector< ElementInBlock > ElementsInBlocks
Definition: PFCandidate.h:386
bool isLooseMuon(const reco::Muon &)
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:438
MuonTrackTypePair getTrackWithSmallestError(const std::vector< MuonTrackTypePair > &)
Definition: PFMuonAlgo.cc:821
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void setVertexSource(PFVertexType vt)
Definition: PFCandidate.h:406
reco::Muon::MuonTrackTypePair tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackRef &tpfmsTrack, const reco::TrackRef &pickyTrack, const reco::TrackRef &dytTrack, const double ptThreshold=200., const double tune1=17., const double tune2=40., const double dptcut=0.25)
Definition: MuonCocktails.cc:9
virtual double px() const final
x coordinate of momentum vector
void setMuonTrackType(const reco::Muon::MuonTrackType &type)
set the Best Muon Track Ref
Definition: PFCandidate.h:356
void setParticleType(ParticleType type)
set Particle Type
Definition: PFCandidate.cc:261
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:649
virtual void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
virtual double p() const final
magnitude of momentum vector
T min(T a, T b)
Definition: MathUtil.h:58
void estimateEventQuantities(const reco::PFCandidateCollection *)
Definition: PFMuonAlgo.cc:830
void changeTrack(reco::PFCandidate &, const MuonTrackTypePair &)
Definition: PFMuonAlgo.cc:792
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:455
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
#define N
Definition: blowfish.cc:9
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:168
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
std::pair< double, double > getMinMaxMET2(const reco::PFCandidate &)
Definition: PFMuonAlgo.cc:1041
int numberOfValidTrackerHits() const
Definition: HitPattern.h:828
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
fixed size matrix
void setMuonRef(const reco::MuonRef &ref)
set muon reference
Definition: PFCandidate.cc:441
PFMuonAlgo()
constructor
Definition: PFMuonAlgo.cc:17
MuonTrackType
map for Global Muon refitters
Definition: Muon.h:38
const reco::MuonRef & muonRef() const
virtual ParticleType particleId() const
Definition: PFCandidate.h:373
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
std::vector< MuonTrackTypePair > tracksWithBetterMET(const std::vector< MuonTrackTypePair > &, const reco::PFCandidate &)
Definition: PFMuonAlgo.cc:1120
void postClean(reco::PFCandidateCollection *)
Definition: PFMuonAlgo.cc:849
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:687
void setInputsForCleaning(const reco::VertexCollection *)
Definition: PFMuonAlgo.cc:1168
std::vector< reco::Muon::MuonTrackTypePair > muonTracks(const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
Definition: PFMuonAlgo.cc:655
virtual double py() const final
y coordinate of momentum vector
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static bool isTrackerTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:214
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:234
bool reconstructMuon(reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)
Definition: PFMuonAlgo.cc:717