15 using namespace boost;
26 maxDPtOPt_(iConfig.getParameter<double>(
"maxDPtOPt")),
28 errorCompScale_(iConfig.getParameter<double>(
"ptErrorScale")),
31 eventFractionCleaning_(iConfig.getParameter<double>(
"eventFractionForCleaning")),
32 minPostCleaningPt_(iConfig.getParameter<double>(
"minPtForPostCleaning")),
33 eventFactorCosmics_(iConfig.getParameter<double>(
"eventFactorForCosmics")),
34 metSigForCleaning_(iConfig.getParameter<double>(
"metSignificanceForCleaning")),
35 metSigForRejection_(iConfig.getParameter<double>(
"metSignificanceForRejection")),
36 metFactorCleaning_(iConfig.getParameter<double>(
"metFactorForCleaning")),
37 eventFractionRejection_(iConfig.getParameter<double>(
"eventFractionForRejection")),
38 metFactorRejection_(iConfig.getParameter<double>(
"metFactorForRejection")),
39 metFactorHighEta_(iConfig.getParameter<double>(
"metFactorForHighEta")),
40 ptFactorHighEta_(iConfig.getParameter<double>(
"ptFactorForHighEta")),
41 metFactorFake_(iConfig.getParameter<double>(
"metFactorForFakes")),
42 minPunchThroughMomentum_(iConfig.getParameter<double>(
"minMomentumForPunchThrough")),
43 minPunchThroughEnergy_(iConfig.getParameter<double>(
"minEnergyForPunchThrough")),
44 punchThroughFactor_(iConfig.getParameter<double>(
"punchThroughFactor")),
45 punchThroughMETFactor_(iConfig.getParameter<double>(
"punchThroughMETFactor")),
46 cosmicRejDistance_(iConfig.getParameter<double>(
"cosmicRejectionDistance")) {}
49 const auto* eltTrack = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
115 if (!muonRef->isGlobalMuon())
117 if (!muonRef->isStandAloneMuon())
120 if (muonRef->isTrackerMuon()) {
124 int nMatches = muonRef->numberOfMatches();
125 bool quality = nMatches > 2 || isTM2DCompatibilityTight;
137 if ((standAloneMu->hitPattern().numberOfValidMuonDTHits() < 22 &&
138 standAloneMu->hitPattern().numberOfValidMuonCSCHits() < 15) ||
139 standAloneMu->normalizedChi2() > 10. || standAloneMu->ptError() / standAloneMu->pt() > 0.20) {
146 if (combinedMu->normalizedChi2() > standAloneMu->normalizedChi2()) {
153 result = standAloneMu->pt() > trackerMu->pt();
158 combinedMu->ptError() / combinedMu->pt() <
std::min(0.20, standAloneMu->ptError() / standAloneMu->pt());
172 if (!muonRef->isTrackerMuon())
178 unsigned nTrackerHits =
track.hitPattern().numberOfValidTrackerHits();
180 if (nTrackerHits <= 12)
187 if (!isAllArbitrated || !isTM2DCompatibilityTight)
190 if ((trackerMu->ptError() / trackerMu->pt() > 0.10)) {
200 if (!muonRef->isGlobalMuon())
202 if (!muonRef->isStandAloneMuon())
210 standAloneMu->hitPattern().numberOfValidMuonDTHits() + 2 * standAloneMu->hitPattern().numberOfValidMuonCSCHits();
214 if (muonRef->isTrackerMuon()) {
215 bool result = combinedMu->normalizedChi2() < 100.;
219 int nMatches = muonRef->numberOfMatches();
221 quality = laststation && nMuonHits > 12 && nMatches > 1;
229 standAloneMu->ptError() / standAloneMu->pt() > 0.20) {
233 if (combinedMu->normalizedChi2() > standAloneMu->normalizedChi2()) {
242 if (standAloneMu->pt() > trackerMu->pt() || combinedMu->normalizedChi2() < 5.)
247 if (combinedMu->ptError() / combinedMu->pt() <
std::min(0.20, standAloneMu->ptError() / standAloneMu->pt()))
259 if (!muonRef->isTrackerMuon())
264 if (trackerMu->ptError() / trackerMu->pt() > 0.20)
268 if (trackerMu->pt() > 20.)
274 bool quality = isAllArbitrated && isTMLastStationAngTight;
282 if (!muonRef->isIsolationValid())
286 if (!muonRef->isGlobalMuon())
293 if (!muonRef->isTrackerMuon()) {
294 if (standAloneMu->hitPattern().numberOfValidMuonDTHits() == 0 &&
295 standAloneMu->hitPattern().numberOfValidMuonCSCHits() == 0)
302 double smallestMuPt = combinedMu->pt();
304 if (standAloneMu->pt() < smallestMuPt)
305 smallestMuPt = standAloneMu->pt();
307 if (muonRef->isTrackerMuon()) {
309 if (trackerMu->pt() < smallestMuPt)
310 smallestMuPt = trackerMu->pt();
313 double sumPtR03 = muonRef->isolationR03().sumPt;
315 double relIso = sumPtR03 / smallestMuPt;
327 if (!muonRef->isTrackerMuon())
330 if (muonRef->numberOfMatches() < 2)
336 if (combinedMuon->hitPattern().numberOfValidTrackerHits() < 11)
339 if (combinedMuon->hitPattern().numberOfValidPixelHits() == 0)
342 if (combinedMuon->hitPattern().numberOfValidMuonHits() == 0)
352 return !
muonTracks(muonRef, maxDPtOPt).empty();
359 bool isGL = muonRef->isGlobalMuon();
360 bool isTR = muonRef->isTrackerMuon();
361 bool isST = muonRef->isStandAloneMuon();
363 std::cout <<
" GL: " << isGL <<
" TR: " << isTR <<
" ST: " << isST << std::endl;
364 std::cout <<
" nMatches " << muonRef->numberOfMatches() << std::endl;
366 if (muonRef->isGlobalMuon()) {
368 std::cout <<
" GL, pt: " << combinedMu->pt() <<
" +/- " << combinedMu->ptError() / combinedMu->pt()
369 <<
" chi**2 GBL : " << combinedMu->normalizedChi2() << std::endl;
370 std::cout <<
" Total Muon Hits : " << combinedMu->hitPattern().numberOfValidMuonHits() <<
"/"
371 << combinedMu->hitPattern().numberOfLostMuonHits()
372 <<
" DT Hits : " << combinedMu->hitPattern().numberOfValidMuonDTHits() <<
"/"
373 << combinedMu->hitPattern().numberOfLostMuonDTHits()
374 <<
" CSC Hits : " << combinedMu->hitPattern().numberOfValidMuonCSCHits() <<
"/"
375 << combinedMu->hitPattern().numberOfLostMuonCSCHits()
376 <<
" RPC Hits : " << combinedMu->hitPattern().numberOfValidMuonRPCHits() <<
"/"
377 << combinedMu->hitPattern().numberOfLostMuonRPCHits() << std::endl;
379 std::cout <<
" # of Valid Tracker Hits " << combinedMu->hitPattern().numberOfValidTrackerHits() << std::endl;
380 std::cout <<
" # of Valid Pixel Hits " << combinedMu->hitPattern().numberOfValidPixelHits() << std::endl;
382 if (muonRef->isStandAloneMuon()) {
384 std::cout <<
" ST, pt: " << standAloneMu->pt() <<
" +/- " << standAloneMu->ptError() / standAloneMu->pt()
385 <<
" eta : " << standAloneMu->eta()
386 <<
" DT Hits : " << standAloneMu->hitPattern().numberOfValidMuonDTHits() <<
"/"
387 << standAloneMu->hitPattern().numberOfLostMuonDTHits()
388 <<
" CSC Hits : " << standAloneMu->hitPattern().numberOfValidMuonCSCHits() <<
"/"
389 << standAloneMu->hitPattern().numberOfLostMuonCSCHits()
390 <<
" RPC Hits : " << standAloneMu->hitPattern().numberOfValidMuonRPCHits() <<
"/"
391 << standAloneMu->hitPattern().numberOfLostMuonRPCHits()
392 <<
" chi**2 STA : " << standAloneMu->normalizedChi2() << std::endl;
395 if (muonRef->isTrackerMuon()) {
398 std::cout <<
" TR, pt: " << trackerMu->pt() <<
" +/- " << trackerMu->ptError() / trackerMu->pt()
399 <<
" chi**2 TR : " << trackerMu->normalizedChi2() << std::endl;
400 std::cout <<
" nTrackerHits " <<
track.hitPattern().numberOfValidTrackerHits() << std::endl;
411 <<
"TMLastStationOptimizedLowPtLoose "
413 <<
"TMLastStationOptimizedLowPtTight "
415 <<
"TMLastStationOptimizedBarrelLowPtLoose "
417 <<
"TMLastStationOptimizedBarrelLowPtTight "
427 if (muonRef->isGlobalMuon() && muonRef->isTrackerMuon() && muonRef->isStandAloneMuon()) {
432 double sigmaCombined = combinedMu->ptError() / (combinedMu->pt() * combinedMu->pt());
433 double sigmaTracker = trackerMu->ptError() / (trackerMu->pt() * trackerMu->pt());
434 double sigmaStandAlone = standAloneMu->ptError() / (standAloneMu->pt() * standAloneMu->pt());
436 bool combined = combinedMu->ptError() / combinedMu->pt() < 0.20;
437 bool tracker = trackerMu->ptError() / trackerMu->pt() < 0.20;
438 bool standAlone = standAloneMu->ptError() / standAloneMu->pt() < 0.20;
440 double delta1 = combined &&
tracker ? fabs(1. / combinedMu->pt() - 1. / trackerMu->pt()) /
441 sqrt(sigmaCombined * sigmaCombined + sigmaTracker * sigmaTracker)
443 double delta2 = combined &&
standAlone ? fabs(1. / combinedMu->pt() - 1. / standAloneMu->pt()) /
444 sqrt(sigmaCombined * sigmaCombined + sigmaStandAlone * sigmaStandAlone)
446 double delta3 =
standAlone &&
tracker ? fabs(1. / standAloneMu->pt() - 1. / trackerMu->pt()) /
447 sqrt(sigmaStandAlone * sigmaStandAlone + sigmaTracker * sigmaTracker)
451 standAloneMu->hitPattern().numberOfValidMuonDTHits() + standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0
455 std::cout <<
"delta = " <<
delta <<
" delta1 " << delta1 <<
" delta2 " << delta2 <<
" delta3 " << delta3
458 double ratio = combinedMu->ptError() / combinedMu->pt() / (trackerMu->ptError() / trackerMu->pt());
460 std::cout <<
" ratio " <<
ratio <<
" combined mu pt " << combinedMu->pt() << std::endl;
464 double sumPtR03 = muonRef->isolationR03().sumPt;
465 double emEtR03 = muonRef->isolationR03().emEt;
466 double hadEtR03 = muonRef->isolationR03().hadEt;
467 double relIsoR03 = (sumPtR03 + emEtR03 + hadEtR03) / muonRef->pt();
468 double sumPtR05 = muonRef->isolationR05().sumPt;
469 double emEtR05 = muonRef->isolationR05().emEt;
470 double hadEtR05 = muonRef->isolationR05().hadEt;
471 double relIsoR05 = (sumPtR05 + emEtR05 + hadEtR05) / muonRef->pt();
472 std::cout <<
" 0.3 Radion Rel Iso: " << relIsoR03 <<
" sumPt " << sumPtR03 <<
" emEt " << emEtR03 <<
" hadEt "
473 << hadEtR03 << std::endl;
474 std::cout <<
" 0.5 Radion Rel Iso: " << relIsoR05 <<
" sumPt " << sumPtR05 <<
" emEt " << emEtR05 <<
" hadEt "
475 << hadEtR05 << std::endl;
481 return (
m.track().isNonnull() &&
m.track() == trackref);
489 std::vector<reco::Muon::MuonTrackTypePair>
out;
491 if (
muon->globalTrack().isNonnull() &&
muon->globalTrack()->pt() > 0)
492 if (
muon->globalTrack()->ptError() /
muon->globalTrack()->pt() < maxDPtOPt)
495 if (
muon->innerTrack().isNonnull() &&
muon->innerTrack()->pt() > 0)
496 if (
muon->innerTrack()->ptError() /
muon->innerTrack()->pt() < maxDPtOPt)
499 bool pickyExists =
false;
500 double pickyDpt = 99999.;
501 if (
muon->pickyTrack().isNonnull() &&
muon->pickyTrack()->pt() > 0) {
502 pickyDpt =
muon->pickyTrack()->ptError() /
muon->pickyTrack()->pt();
503 if (pickyDpt < maxDPtOPt)
508 bool dytExists =
false;
509 double dytDpt = 99999.;
510 if (
muon->dytTrack().isNonnull() &&
muon->dytTrack()->pt() > 0) {
511 dytDpt =
muon->dytTrack()->ptError() /
muon->dytTrack()->pt();
512 if (dytDpt < maxDPtOPt)
521 if (
muon->tpfmsTrack().isNonnull() &&
muon->tpfmsTrack()->pt() > 0) {
522 double tpfmsDpt =
muon->tpfmsTrack()->ptError() /
muon->tpfmsTrack()->pt();
523 if (((pickyExists && tpfmsDpt < pickyDpt) || (!pickyExists)) &&
524 ((dytExists && tpfmsDpt < dytDpt) || (!dytExists)) && tpfmsDpt < maxDPtOPt)
528 if (includeSA &&
muon->outerTrack().isNonnull())
529 if (
muon->outerTrack()->ptError() /
muon->outerTrack()->pt() < maxDPtOPt)
539 using namespace reco;
541 if (!
muon.isNonnull())
565 if (validTracks.empty())
571 TrackRef bestTrack = bestTrackPair.first;
575 TrackRef trackWithSmallestError = trackPairWithSmallestError.first;
579 bestTrack->ptError() / bestTrack->pt() >
580 errorCompScale_ * trackWithSmallestError->ptError() / trackWithSmallestError->pt())) {
581 bestTrack = trackWithSmallestError;
582 trackType = trackPairWithSmallestError.second;
584 bestTrack->ptError() / bestTrack->pt() >
585 errorCompScale_ * trackWithSmallestError->ptError() / trackWithSmallestError->pt()) {
586 bestTrack = trackWithSmallestError;
587 trackType = trackPairWithSmallestError.second;
597 using namespace reco;
601 double px = bestTrack->px();
602 double py = bestTrack->py();
603 double pz = bestTrack->pz();
604 double energy =
sqrt(bestTrack->p() * bestTrack->p() + 0.1057 * 0.1057);
606 candidate.
setCharge(bestTrack->charge() > 0 ? 1 : -1);
611 candidate.
setVertex(bestTrack->vertex());
615 const std::vector<reco::Muon::MuonTrackTypePair>&
tracks) {
626 for (reco::PFCandidateCollection::const_iterator
i = pfc->begin();
i != pfc->end(); ++
i) {
635 using namespace reco;
674 std::vector<int>
muons;
677 for (
unsigned int i = 0;
i <
cands->size(); ++
i) {
688 double METXCosmics = 0;
689 double METYCosmics = 0;
690 double SUMETCosmics = 0.0;
692 for (
unsigned int i = 0;
i <
muons.size(); ++
i) {
700 METXCosmics += pfc.
px();
701 METYCosmics += pfc.
py();
702 SUMETCosmics += pfc.
pt();
705 double MET2Cosmics = METXCosmics * METXCosmics + METYCosmics * METYCosmics;
708 for (
unsigned int i = 0;
i <
cosmics.size(); ++
i) {
714 for (
unsigned int i = 0;
i <
muons.size(); ++
i) {
734 typedef std::pair<edm::ProductID, unsigned> TrackProdIDKey;
735 std::vector<TrackProdIDKey> vetoed;
738 if (
veto.trackRef().isNull())
740 vetoed.emplace_back(
veto.trackRef().id(),
veto.trackRef().key());
745 for (
unsigned imu = 0; imu <
muons->size(); ++imu) {
749 for (
unsigned i = 0;
i <
cands->size();
i++) {
758 if (pfc.
muonRef()->innerTrack() == muonRef->innerTrack())
763 if (pfc.
muonRef()->isStandAloneMuon() && muonRef->isStandAloneMuon()) {
764 double dEta = pfc.
muonRef()->standAloneMuon()->eta() - muonRef->standAloneMuon()->eta();
765 double dPhi = pfc.
muonRef()->standAloneMuon()->phi() - muonRef->standAloneMuon()->phi();
777 if (!vetoed.empty()) {
778 TrackProdIDKey trk = std::make_pair(muonRef->track().
id(), muonRef->track().
key());
780 bool inVetoList = (lower != vetoed.end() && *lower == trk);
785 if (used || hadron || (!muonRef.
isNonnull()))
797 if (!tracksThatChangeMET.empty()) {
799 *std::min_element(tracksThatChangeMET.begin(), tracksThatChangeMET.end(), comparator);
804 int charge = bestTrackType.first->charge() > 0 ? 1 : -1;
806 bestTrackType.first->py(),
807 bestTrackType.first->pz(),
808 sqrt(bestTrackType.first->p() * bestTrackType.first->p() + 0.1057 * 0.1057));
815 cands->back().setTrackRef(muonRef->track());
817 cands->back().setMuonRef(muonRef);
829 double METXNO =
METX_ - pfc.
px();
830 double METYNO =
METY_ - pfc.
py();
831 std::vector<double> met2;
832 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
833 met2.push_back(
pow(METXNO +
tracks.at(
i).first->px(), 2) +
pow(METYNO +
tracks.at(
i).first->py(), 2));
840 return std::make_pair(*std::min_element(met2.begin(), met2.end()), *std::max_element(met2.begin(), met2.end()));
842 return std::make_pair(0, 0);
847 using namespace reco;
848 bool cleaned =
false;
851 double METNOX =
METX_ - pfc.
px();
852 double METNOY =
METY_ - pfc.
py();
866 if (!tracksThatChangeMET.empty()) {
868 *std::min_element(tracksThatChangeMET.begin(), tracksThatChangeMET.end(), comparator);
880 if (!(pfc.
muonRef()->isGlobalMuon() && pfc.
muonRef()->isTrackerMuon())) {
883 double newMET2 = METNOX * METNOX + METNOY * METNOY;
901 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
903 double METNOX =
METX_ - pfc.
px();
904 double METNOY =
METY_ - pfc.
py();
907 double newMET2 = 0.0;
908 double newSUMET = 0.0;
912 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
915 newMET2 =
pow(METNOX +
tracks.at(
i).first->px(), 2) +
pow(METNOY +
tracks.at(
i).first->py(), 2);
918 outputTracks.push_back(
tracks.at(
i));
925 const std::vector<reco::Muon::MuonTrackTypePair>&
tracks) {
926 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
928 double newMET2 = 0.0;
930 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
935 outputTracks.push_back(
tracks.at(
i));
946 using namespace reco;
948 bool cleaned =
false;
953 double METXNO =
METX_ - pfc.
pt();
954 double METYNO =
METY_ - pfc.
pt();
955 double MET2NO = METXNO * METXNO + METYNO * METYNO;
963 fake1 = fabs(pfc.
eta()) > 2.15 && met2.first < met2.second / 2 && MET2NO < MET2 /
metFactorHighEta_ &&
974 if (fake1 || fake2 || punchthrough) {
977 if (!eleInBlocks.empty()) {
978 PFBlockRef blockRefMuon = eleInBlocks[0].first;
979 unsigned indexMuon = eleInBlocks[0].second;
980 if (eleInBlocks.size() > 1)
981 indexMuon = eleInBlocks[1].
second;
986 for (
unsigned i = imu + 1;
i <
cands->size(); ++
i) {
993 unsigned indexHadron = ele[0].second;
995 if (blockRefHadron.
key() != blockRefMuon.
key())
1007 double rescaleFactor =
cands->at(iHad).p() /
cands->at(imu).p();
1011 cands->at(imu).rescaleMomentum(rescaleFactor);
1020 }
else if (fake1 || fake2) {
1035 size_t collSize =
obj->size();
1037 for (
size_t i = 0;
i <
N; ++
i)
1045 iDesc.
add<
double>(
"maxDPtOPt", 1.0);
1047 iDesc.
add<
double>(
"ptErrorScale", 8.0);
1049 iDesc.
add<
double>(
"eventFractionForCleaning", 0.5);
1050 iDesc.
add<
double>(
"minPtForPostCleaning", 20.0);
1051 iDesc.
add<
double>(
"eventFactorForCosmics", 10.0);
1052 iDesc.
add<
double>(
"metSignificanceForCleaning", 3.0);
1053 iDesc.
add<
double>(
"metSignificanceForRejection", 4.0);
1054 iDesc.
add<
double>(
"metFactorForCleaning", 4.0);
1055 iDesc.
add<
double>(
"eventFractionForRejection", 0.8);
1056 iDesc.
add<
double>(
"metFactorForRejection", 4.0);
1057 iDesc.
add<
double>(
"metFactorForHighEta", 25.0);
1058 iDesc.
add<
double>(
"ptFactorForHighEta", 2.0);
1059 iDesc.
add<
double>(
"metFactorForFakes", 4.0);
1060 iDesc.
add<
double>(
"minMomentumForPunchThrough", 100.0);
1061 iDesc.
add<
double>(
"minEnergyForPunchThrough", 100.0);
1062 iDesc.
add<
double>(
"punchThroughFactor", 3.0);
1063 iDesc.
add<
double>(
"punchThroughMETFactor", 4.0);
1064 iDesc.
add<
double>(
"cosmicRejectionDistance", 1.0);