15 using namespace boost;
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>();
32 if(iConfig.
exists(
"maxDPtOPt"))
37 if(iConfig.
exists(
"minTrackerHits"))
38 minTrackerHits_ = iConfig.
getParameter<
int>(
"minTrackerHits");
42 if(iConfig.
exists(
"minPixelHits"))
43 minPixelHits_ = iConfig.
getParameter<
int>(
"minPixelHits");
47 if(iConfig.
exists(
"trackQuality"))
52 if(iConfig.
exists(
"ptErrorScale"))
53 errorCompScale_ = iConfig.
getParameter<
double>(
"ptErrorScale");
57 if(iConfig.
exists(
"eventFractionForCleaning"))
58 eventFractionCleaning_ = iConfig.
getParameter<
double>(
"eventFractionForCleaning");
60 eventFractionCleaning_ = 0.75;
67 if(iConfig.
exists(
"postMuonCleaning"))
68 postCleaning_ = iConfig.
getParameter<
bool>(
"postMuonCleaning");
70 postCleaning_ =
false;
72 if(iConfig.
exists(
"minPtForPostCleaning"))
73 minPostCleaningPt_ = iConfig.
getParameter<
double>(
"minPtForPostCleaning");
75 minPostCleaningPt_ = 20.;
77 if(iConfig.
exists(
"eventFactorForCosmics"))
78 eventFactorCosmics_ = iConfig.
getParameter<
double>(
"eventFactorForCosmics");
80 eventFactorCosmics_ = 10.;
83 if(iConfig.
exists(
"metSignificanceForCleaning"))
84 metSigForCleaning_ = iConfig.
getParameter<
double>(
"metSignificanceForCleaning");
86 metSigForCleaning_ = 3.;
88 if(iConfig.
exists(
"metSignificanceForRejection"))
89 metSigForRejection_ = iConfig.
getParameter<
double>(
"metSignificanceForRejection");
91 metSigForRejection_ = 4.;
93 if(iConfig.
exists(
"metFactorForCleaning"))
94 metFactorCleaning_ = iConfig.
getParameter<
double>(
"metFactorForCleaning");
96 metFactorCleaning_ = 4.;
98 if(iConfig.
exists(
"eventFractionForRejection"))
99 eventFractionRejection_ = iConfig.
getParameter<
double>(
"eventFractionForRejection");
101 eventFractionRejection_ = 0.75;
103 if(iConfig.
exists(
"metFactorForRejection"))
104 metFactorRejection_ = iConfig.
getParameter<
double>(
"metFactorForRejection");
106 metFactorRejection_ =4.;
108 if(iConfig.
exists(
"metFactorForHighEta"))
109 metFactorHighEta_ = iConfig.
getParameter<
double>(
"metFactorForHighEta");
113 if(iConfig.
exists(
"ptFactorForHighEta"))
114 ptFactorHighEta_ = iConfig.
getParameter<
double>(
"ptFactorForHighEta");
116 ptFactorHighEta_ = 2.;
118 if(iConfig.
exists(
"metFactorForFakes"))
119 metFactorFake_ = iConfig.
getParameter<
double>(
"metFactorForFakes");
123 if(iConfig.
exists(
"minMomentumForPunchThrough"))
124 minPunchThroughMomentum_ = iConfig.
getParameter<
double>(
"minMomentumForPunchThrough");
126 minPunchThroughMomentum_=100.;
128 if(iConfig.
exists(
"minEnergyForPunchThrough"))
129 minPunchThroughEnergy_ = iConfig.
getParameter<
double>(
"minEnergyForPunchThrough");
131 minPunchThroughEnergy_ = 100.;
133 if(iConfig.
exists(
"punchThroughFactor"))
134 punchThroughFactor_ = iConfig.
getParameter<
double>(
"punchThroughFactor");
136 punchThroughFactor_ = 3.;
138 if(iConfig.
exists(
"punchThroughMETFactor"))
139 punchThroughMETFactor_ = iConfig.
getParameter<
double>(
"punchThroughMETFactor");
141 punchThroughMETFactor_ = 4.;
143 if(iConfig.
exists(
"cosmicRejectionDistance"))
144 cosmicRejDistance_ = iConfig.
getParameter<
double>(
"cosmicRejectionDistance");
146 cosmicRejDistance_ = 1.0;
196 return isGlobalTightMuon(muonRef);
209 return isGlobalLooseMuon(muonRef);
222 return isTrackerTightMuon(muonRef);
235 return isIsolatedMuon(muonRef);
242 return isGlobalTightMuon(muonRef) || isTrackerTightMuon(muonRef) || isIsolatedMuon(muonRef);
248 return (isGlobalLooseMuon(muonRef) || isTrackerLooseMuon(muonRef));
255 if ( !muonRef.
isNonnull() )
return false;
257 if ( !muonRef->isGlobalMuon() )
return false;
258 if ( !muonRef->isStandAloneMuon() )
return false;
261 if ( muonRef->isTrackerMuon() ) {
266 int nMatches = muonRef->numberOfMatches();
267 bool quality = nMatches > 2 || isTM2DCompatibilityTight;
280 if ( ( standAloneMu->hitPattern().numberOfValidMuonDTHits() < 22 &&
281 standAloneMu->hitPattern().numberOfValidMuonCSCHits() < 15 ) ||
282 standAloneMu->normalizedChi2() > 10. ||
283 standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
291 if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
298 result = standAloneMu->pt() > trackerMu->pt() ;
303 combinedMu->ptError()/combinedMu->pt() <
304 std::min(0.20,standAloneMu->ptError()/standAloneMu->pt());
318 if ( !muonRef.
isNonnull() )
return false;
320 if(!muonRef->isTrackerMuon())
return false;
327 if(nTrackerHits<=12)
return false;
333 if(!isAllArbitrated || !isTM2DCompatibilityTight)
return false;
335 if((trackerMu->ptError()/trackerMu->pt() > 0.10)){
346 if ( !muonRef.
isNonnull() )
return false;
347 if ( !muonRef->isGlobalMuon() )
return false;
348 if ( !muonRef->isStandAloneMuon() )
return false;
355 standAloneMu->hitPattern().numberOfValidMuonDTHits() +
356 2*standAloneMu->hitPattern().numberOfValidMuonCSCHits();
360 if ( muonRef->isTrackerMuon() ){
362 bool result = combinedMu->normalizedChi2() < 100.;
367 int nMatches = muonRef->numberOfMatches();
369 quality = laststation && nMuonHits > 12 && nMatches > 1;
378 if ( nMuonHits <=15 ||
379 standAloneMu->normalizedChi2() > 10. ||
380 standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
385 if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
394 if(standAloneMu->pt() > trackerMu->pt() || combinedMu->normalizedChi2()<5.) quality =
true;
399 if(combinedMu->ptError()/combinedMu->pt() <
std::min(0.20,standAloneMu->ptError()/standAloneMu->pt()))
415 if ( !muonRef.
isNonnull() )
return false;
416 if(!muonRef->isTrackerMuon())
return false;
420 if(trackerMu->ptError()/trackerMu->pt() > 0.20)
return false;
423 if(trackerMu->pt()>20.)
return false;
428 bool quality = isAllArbitrated && isTMLastStationAngTight;
438 if ( !muonRef.
isNonnull() )
return false;
439 if ( !muonRef->isIsolationValid() )
return false;
442 if ( !muonRef->isGlobalMuon() )
return false;
448 if ( !muonRef->isTrackerMuon() ){
449 if(standAloneMu->hitPattern().numberOfValidMuonDTHits() == 0 &&
450 standAloneMu->hitPattern().numberOfValidMuonCSCHits() ==0)
return false;
456 double smallestMuPt = combinedMu->pt();
458 if(standAloneMu->pt()<smallestMuPt) smallestMuPt = standAloneMu->pt();
460 if(muonRef->isTrackerMuon())
463 if(trackerMu->pt() < smallestMuPt) smallestMuPt= trackerMu->pt();
467 double sumPtR03 = muonRef->isolationR03().sumPt;
469 double relIso = sumPtR03/smallestMuPt;
474 if(relIso<0.1)
return true;
483 if(!muonRef->isTrackerMuon())
return false;
485 if(muonRef->numberOfMatches()<2)
return false;
490 if(combinedMuon->hitPattern().numberOfValidTrackerHits()<11)
return false;
492 if(combinedMuon->hitPattern().numberOfValidPixelHits()==0)
return false;
494 if(combinedMuon->hitPattern().numberOfValidMuonHits()==0)
return false;
504 return !muonTracks(muonRef).empty();
506 return !goodMuonTracks(muonRef).empty();
516 bool isGL = muonRef->isGlobalMuon();
517 bool isTR = muonRef->isTrackerMuon();
518 bool isST = muonRef->isStandAloneMuon();
520 std::cout<<
" GL: "<<isGL<<
" TR: "<<isTR<<
" ST: "<<isST<<std::endl;
521 std::cout<<
" nMatches "<<muonRef->numberOfMatches()<<std::endl;
523 if ( muonRef->isGlobalMuon() ){
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;
537 std::cout<<
" # of Valid Tracker Hits "<<combinedMu->hitPattern().numberOfValidTrackerHits()<<std::endl;
538 std::cout<<
" # of Valid Pixel Hits "<<combinedMu->hitPattern().numberOfValidPixelHits()<<std::endl;
540 if ( muonRef->isStandAloneMuon() ){
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;
555 if ( muonRef->isTrackerMuon() ){
558 std::cout<<
" TR, pt: " << trackerMu->pt()
559 <<
" +/- " << trackerMu->ptError()/trackerMu->pt()
560 <<
" chi**2 TR : " << trackerMu->normalizedChi2()<<std::endl;
564 <<
"TMLastStationAngTight " 566 <<
"TMLastStationLoose " 568 <<
"TMLastStationTight " 570 <<
"TMOneStationLoose " 572 <<
"TMOneStationTight " 574 <<
"TMLastStationOptimizedLowPtLoose " 576 <<
"TMLastStationOptimizedLowPtTight " 578 <<
"TMLastStationOptimizedBarrelLowPtLoose " 580 <<
"TMLastStationOptimizedBarrelLowPtTight " 588 <<
"TM2DCompatibilityTight " 593 if ( muonRef->isGlobalMuon() && muonRef->isTrackerMuon() && muonRef->isStandAloneMuon() ){
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());
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;
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.;
617 standAloneMu->hitPattern().numberOfValidMuonDTHits()+
618 standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0 ?
621 std::cout <<
"delta = " << delta <<
" delta1 "<<delta1<<
" delta2 "<<delta2<<
" delta3 "<<delta3<<std::endl;
624 combinedMu->ptError()/combinedMu->pt()
625 / (trackerMu->ptError()/trackerMu->pt());
627 std::cout<<
" ratio "<<ratio<<
" combined mu pt "<<combinedMu->pt()<<std::endl;
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;
650 return muonTracks(muon,includeSA,maxDPtOPt_);
659 std::vector<reco::Muon::MuonTrackTypePair>
out;
662 if(muon->globalTrack().
isNonnull() && muon->globalTrack()->pt()>0)
663 if(muon->globalTrack()->ptError()/muon->globalTrack()->pt()<dpt)
666 if(muon->innerTrack().
isNonnull() && muon->innerTrack()->pt()>0)
667 if(muon->innerTrack()->ptError()/muon->innerTrack()->pt()<dpt)
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();
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();
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) ) &&
700 if(includeSA && muon->outerTrack().
isNonnull())
701 if(muon->outerTrack()->ptError()/muon->outerTrack()->pt()<dpt)
719 using namespace reco;
746 std::vector<reco::Muon::MuonTrackTypePair> validTracks = goodMuonTracks(muon);
748 validTracks = goodMuonTracks(muon);
750 validTracks = muonTracks(muon);
752 if( validTracks.empty())
761 TrackRef bestTrack = bestTrackPair.first;
766 MuonTrackTypePair trackPairWithSmallestError = getTrackWithSmallestError(validTracks);
767 TrackRef trackWithSmallestError = trackPairWithSmallestError.first;
770 (!bestTrack->quality(trackQuality_) ||
771 bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt() )) {
772 bestTrack = trackWithSmallestError;
773 trackType = trackPairWithSmallestError.second;
776 bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt()) {
777 bestTrack = trackWithSmallestError;
778 trackType = trackPairWithSmallestError.second;
783 changeTrack(candidate,std::make_pair(bestTrack,trackType));
793 using namespace reco;
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);
802 candidate.
setCharge(bestTrack->charge()>0 ? 1 : -1);
823 return *std::min_element(tracks.begin(),tracks.end(),
sorter);
837 for(reco::PFCandidateCollection::const_iterator
i = pfc->begin();
i!=pfc->end();++
i) {
851 using namespace reco;
857 if(pfCosmicsMuonCleanedCandidates_.get() )
858 pfCosmicsMuonCleanedCandidates_->clear();
862 if(pfCleanedTrackerAndGlobalMuonCandidates_.get() )
863 pfCleanedTrackerAndGlobalMuonCandidates_->clear();
867 if( pfFakeMuonCleanedCandidates_.get() )
868 pfFakeMuonCleanedCandidates_->clear();
873 if( pfPunchThroughMuonCleanedCandidates_.get() )
874 pfPunchThroughMuonCleanedCandidates_->clear();
878 if( pfPunchThroughHadronCleanedCandidates_.get() )
879 pfPunchThroughHadronCleanedCandidates_->clear();
885 pfPunchThroughHadronCleanedCandidates_->clear();
887 maskedIndices_.clear();
891 estimateEventQuantities(cands);
894 std::vector<int>
muons;
897 for(
unsigned int i=0;
i<cands->size();++
i) {
906 std::sort(muons.begin(),muons.end(),comparator);
910 double METXCosmics=0;
911 double METYCosmics=0;
912 double SUMETCosmics=0.0;
914 for(
unsigned int i=0;
i<muons.size();++
i) {
917 if(!vertices_->empty()&& vertices_->at(0).isValid() && ! vertices_->at(0).isFake())
918 origin = pfc.
muonRef()->muonBestTrack()->dxy(vertices_->at(0).position());
920 if( origin> cosmicRejDistance_) {
921 cosmics.push_back(muons[i]);
922 METXCosmics +=pfc.
px();
923 METYCosmics +=pfc.
py();
924 SUMETCosmics +=pfc.
pt();
927 double MET2Cosmics = METXCosmics*METXCosmics+METYCosmics*METYCosmics;
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]));
936 for(
unsigned int i=0;
i<muons.size();++
i) {
937 if( cleanMismeasured(cands->at(muons[
i]),muons[
i]))
939 cleanPunchThroughAndFakes(cands->at(muons[i]),
cands,muons[
i]);
946 removeDeadCandidates(cands,maskedIndices_);
958 if( pfAddedMuonCandidates_.get() )
959 pfAddedMuonCandidates_->clear();
965 for (
unsigned imu = 0; imu < muons->size(); ++imu ) {
969 for(
unsigned i=0;
i<cands->size();
i++) {
976 if ( pfc.
muonRef()->innerTrack() == muonRef->innerTrack())
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);
994 if ( used ||hadron||(!muonRef.
isNonnull()) )
continue;
1000 std::vector<reco::Muon::MuonTrackTypePair>
tracks = goodMuonTracks(muonRef,
true);
1002 if(!tracks.empty()) {
1005 std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksPointingAtMET(tracks);
1007 if (!tracksThatChangeMET.empty()) {
1011 if((vertices_->empty()) ||bestTrackType.first->dz(vertices_->at(0).position())<cosmicRejDistance_){
1014 int charge = bestTrackType.first->charge()>0 ? 1 : -1;
1016 bestTrackType.first->py(),
1017 bestTrackType.first->pz(),
1018 sqrt(bestTrackType.first->p()*bestTrackType.first->p()+0.1057*0.1057));
1024 changeTrack(cands->back(),bestTrackType);
1027 cands->back().setTrackRef( muonRef->track() );
1029 cands->back().setMuonRef(muonRef);
1032 pfAddedMuonCandidates_->push_back(cands->back());
1040 std::pair<double,double>
1042 std::vector<reco::Muon::MuonTrackTypePair>
tracks = goodMuonTracks((pfc.
muonRef()),
true);
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));
1055 return std::make_pair(*std::min_element(met2.begin(),met2.end()),*std::max_element(met2.begin(),met2.end()));
1057 return std::make_pair(0,0);
1062 using namespace std;
1063 using namespace reco;
1067 double METNOX = METX_ - pfc.
px();
1068 double METNOY = METY_ - pfc.
py();
1069 double SUMETNO = sumet_ -pfc.
pt();
1073 if (pfc.
pt()<minPostCleaningPt_)
1075 std::vector<reco::Muon::MuonTrackTypePair>
tracks = goodMuonTracks(pfc.
muonRef(),
false);
1080 if(tracks.size()>1) {
1082 std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksWithBetterMET(tracks,pfc);
1084 if (!tracksThatChangeMET.empty()) {
1086 changeTrack(pfc,bestTrackType);
1088 pfCleanedTrackerAndGlobalMuonCandidates_->push_back(pfc);
1090 METX_ = METNOX+pfc.
px();
1091 METY_ = METNOY+pfc.
py();
1092 sumet_=SUMETNO+pfc.
pt();
1098 if (!(pfc.
muonRef()->isGlobalMuon() && pfc.
muonRef()->isTrackerMuon())) {
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);
1119 std::vector<reco::Muon::MuonTrackTypePair>
1121 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
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_;
1128 double newSUMET=0.0;
1129 double METSIG =
sqrt(MET2)/
sqrt(sumet_-sumetPU_);
1132 if(METSIG>metSigForCleaning_)
1133 for(
unsigned int i=0;
i<tracks.size();++
i) {
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);
1138 if(newSUMET/(sumet_-sumetPU_)>eventFractionCleaning_ && newMET2<MET2/metFactorCleaning_)
1139 outputTracks.push_back(tracks.at(
i));
1143 return outputTracks;
1147 std::vector<reco::Muon::MuonTrackTypePair>
1149 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
1154 for(
unsigned int i=0;
i<tracks.size();++
i) {
1156 newMET2 =
pow(METX_+tracks.at(
i).first->px(),2)+
pow(METY_+tracks.at(
i).first->py(),2);
1158 if(newMET2<(METX_*METX_+METY_*METY_)/metFactorCleaning_)
1159 outputTracks.push_back(tracks.at(
i));
1163 return outputTracks;
1173 using namespace reco;
1177 if (pfc.
pt()<minPostCleaningPt_)
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_;
1187 std::pair<double,double> met2 = getMinMaxMET2(pfc);
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_;
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 );
1199 bool punchthrough =pfc.
p() > minPunchThroughMomentum_ &&
1202 !isIsolatedMuon(pfc.
muonRef()) && MET2NO < MET2/punchThroughMETFactor_;
1205 if(fake1 || fake2||punchthrough) {
1208 if ( !eleInBlocks.empty() ) {
1209 PFBlockRef blockRefMuon = eleInBlocks[0].first;
1210 unsigned indexMuon = eleInBlocks[0].second;
1211 if (eleInBlocks.size()>1)
1212 indexMuon = eleInBlocks[1].
second;
1216 bool hadron =
false;
1217 for (
unsigned i = imu+1;
i < cands->size(); ++
i ) {
1220 if ( ele.empty() ) {
1224 unsigned indexHadron = ele[0].second;
1226 if ( blockRefHadron.
key() != blockRefMuon.
key() )
break;
1228 if ( indexHadron == indexMuon &&
1233 if ( hadron )
break;
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));
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();
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));
1267 size_t N = indices.size();
1268 size_t collSize = obj->size();
1270 for (
size_t i = 0 ;
i <
N ; ++
i)
1271 obj->at(indices.at(
i)) = obj->at(collSize-
i-1);
1273 obj->resize(collSize - indices.size());
T getParameter(std::string const &) const
Abstract base class for a PFBlock element (track, cluster...)
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
bool cleanMismeasured(reco::PFCandidate &, unsigned int)
static bool isTightMuonPOG(const reco::MuonRef &muonRef)
void removeDeadCandidates(reco::PFCandidateCollection *, const std::vector< unsigned int > &)
bool isNonnull() const
Checks for non-null.
double eta() const final
momentum pseudorapidity
double rawEcalEnergy() const
return corrected Ecal energy
void addMissingMuons(edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
bool isMuon(const Candidate &part)
static bool isMuon(const reco::PFBlockElement &elt)
static bool isTrackerLooseMuon(const reco::PFBlockElement &elt)
void setParameters(const edm::ParameterSet &)
double px() const final
x coordinate of momentum vector
static bool isGlobalLooseMuon(const reco::PFBlockElement &elt)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool cleanPunchThroughAndFakes(reco::PFCandidate &, reco::PFCandidateCollection *, unsigned int)
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
reco::Muon::MuonTrackTypePair MuonTrackTypePair
key_type key() const
Accessor for product key.
static void printMuonProperties(const reco::MuonRef &muonRef)
std::vector< MuonTrackTypePair > tracksPointingAtMET(const std::vector< MuonTrackTypePair > &)
bool hasValidTrack(const reco::MuonRef &muonRef, bool loose=false)
static bool isGlobalTightMuon(const reco::PFBlockElement &elt)
std::vector< ElementInBlock > ElementsInBlocks
bool isLooseMuon(const reco::Muon &)
reco::TrackRef trackRef() const
MuonTrackTypePair getTrackWithSmallestError(const std::vector< MuonTrackTypePair > &)
U second(std::pair< T, U > const &p)
void setCharge(Charge q) final
set electric charge
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
void setVertexSource(PFVertexType vt)
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)
void setMuonTrackType(const reco::Muon::MuonTrackType &type)
set the Best Muon Track Ref
void setParticleType(ParticleType type)
set Particle Type
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
void estimateEventQuantities(const reco::PFCandidateCollection *)
void changeTrack(reco::PFCandidate &, const MuonTrackTypePair &)
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
reco::MuonRef muonRef() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double p() const final
magnitude of momentum vector
static TrackQuality qualityByName(const std::string &name)
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
static bool isLooseMuon(const reco::PFBlockElement &elt)
double py() const final
y coordinate of momentum vector
std::pair< double, double > getMinMaxMET2(const reco::PFCandidate &)
int numberOfValidTrackerHits() const
Particle reconstructed by the particle flow algorithm.
void setMuonRef(const reco::MuonRef &ref)
set muon reference
MuonTrackType
map for Global Muon refitters
const reco::MuonRef & muonRef() const override
virtual ParticleType particleId() const
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
std::vector< MuonTrackTypePair > tracksWithBetterMET(const std::vector< MuonTrackTypePair > &, const reco::PFCandidate &)
void postClean(reco::PFCandidateCollection *)
const ElementsInBlocks & elementsInBlocks() const
void setInputsForCleaning(const reco::VertexCollection *)
std::vector< reco::Muon::MuonTrackTypePair > muonTracks(const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
void setP4(const LorentzVector &p4) final
set 4-momentum
Power< A, B >::type pow(const A &a, const B &b)
static bool isTrackerTightMuon(const reco::PFBlockElement &elt)
double rawHcalEnergy() const
return raw Hcal energy
bool reconstructMuon(reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)