14 using namespace boost;
34 maxDPtOPt_(getParameter<double>(iConfig,
"maxDPtOPt", 1.0)),
35 trackQuality_(
reco::
TrackBase::qualityByName(getParameter<
std::
string>(iConfig,
"trackQuality",
"highPurity"))),
36 errorCompScale_(getParameter<double>(iConfig,
"ptErrorScale", 8.0)),
39 eventFractionCleaning_(getParameter<double>(iConfig,
"eventFractionForCleaning", 0.5)),
40 minPostCleaningPt_(getParameter<double>(iConfig,
"minPtForPostCleaning", 20.)),
41 eventFactorCosmics_(getParameter<double>(iConfig,
"eventFactorForCosmics", 10.)),
42 metSigForCleaning_(getParameter<double>(iConfig,
"metSignificanceForCleaning", 3.)),
43 metSigForRejection_(getParameter<double>(iConfig,
"metSignificanceForRejection", 4.)),
44 metFactorCleaning_(getParameter<double>(iConfig,
"metFactorForCleaning", 4.)),
45 eventFractionRejection_(getParameter<double>(iConfig,
"eventFractionForRejection", 0.8)),
46 metFactorRejection_(getParameter<double>(iConfig,
"metFactorForRejection", 4.)),
47 metFactorHighEta_(getParameter<double>(iConfig,
"metFactorForHighEta", 25.)),
48 ptFactorHighEta_(getParameter<double>(iConfig,
"ptFactorForHighEta", 2.)),
49 metFactorFake_(getParameter<double>(iConfig,
"metFactorForFakes", 4.)),
50 minPunchThroughMomentum_(getParameter<double>(iConfig,
"minMomentumForPunchThrough", 100.)),
51 minPunchThroughEnergy_(getParameter<double>(iConfig,
"minEnergyForPunchThrough", 100.)),
52 punchThroughFactor_(getParameter<double>(iConfig,
"punchThroughFactor", 3.)),
53 punchThroughMETFactor_(getParameter<double>(iConfig,
"punchThroughMETFactor", 4.)),
54 cosmicRejDistance_(getParameter<double>(iConfig,
"cosmicRejectionDistance", 1.)) {}
57 const auto* eltTrack = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
123 if (!muonRef->isGlobalMuon())
125 if (!muonRef->isStandAloneMuon())
128 if (muonRef->isTrackerMuon()) {
132 int nMatches = muonRef->numberOfMatches();
133 bool quality = nMatches > 2 || isTM2DCompatibilityTight;
145 if ((standAloneMu->hitPattern().numberOfValidMuonDTHits() < 22 &&
146 standAloneMu->hitPattern().numberOfValidMuonCSCHits() < 15) ||
147 standAloneMu->normalizedChi2() > 10. || standAloneMu->ptError() / standAloneMu->pt() > 0.20) {
154 if (combinedMu->normalizedChi2() > standAloneMu->normalizedChi2()) {
161 result = standAloneMu->pt() > trackerMu->pt();
166 combinedMu->ptError() / combinedMu->pt() <
std::min(0.20, standAloneMu->ptError() / standAloneMu->pt());
180 if (!muonRef->isTrackerMuon())
186 unsigned nTrackerHits =
track.hitPattern().numberOfValidTrackerHits();
188 if (nTrackerHits <= 12)
195 if (!isAllArbitrated || !isTM2DCompatibilityTight)
198 if ((trackerMu->ptError() / trackerMu->pt() > 0.10)) {
208 if (!muonRef->isGlobalMuon())
210 if (!muonRef->isStandAloneMuon())
218 standAloneMu->hitPattern().numberOfValidMuonDTHits() + 2 * standAloneMu->hitPattern().numberOfValidMuonCSCHits();
222 if (muonRef->isTrackerMuon()) {
223 bool result = combinedMu->normalizedChi2() < 100.;
227 int nMatches = muonRef->numberOfMatches();
229 quality = laststation && nMuonHits > 12 && nMatches > 1;
237 standAloneMu->ptError() / standAloneMu->pt() > 0.20) {
241 if (combinedMu->normalizedChi2() > standAloneMu->normalizedChi2()) {
250 if (standAloneMu->pt() > trackerMu->pt() || combinedMu->normalizedChi2() < 5.)
255 if (combinedMu->ptError() / combinedMu->pt() <
std::min(0.20, standAloneMu->ptError() / standAloneMu->pt()))
267 if (!muonRef->isTrackerMuon())
272 if (trackerMu->ptError() / trackerMu->pt() > 0.20)
276 if (trackerMu->pt() > 20.)
282 bool quality = isAllArbitrated && isTMLastStationAngTight;
290 if (!muonRef->isIsolationValid())
294 if (!muonRef->isGlobalMuon())
301 if (!muonRef->isTrackerMuon()) {
302 if (standAloneMu->hitPattern().numberOfValidMuonDTHits() == 0 &&
303 standAloneMu->hitPattern().numberOfValidMuonCSCHits() == 0)
310 double smallestMuPt = combinedMu->pt();
312 if (standAloneMu->pt() < smallestMuPt)
313 smallestMuPt = standAloneMu->pt();
315 if (muonRef->isTrackerMuon()) {
317 if (trackerMu->pt() < smallestMuPt)
318 smallestMuPt = trackerMu->pt();
321 double sumPtR03 = muonRef->isolationR03().sumPt;
323 double relIso = sumPtR03 / smallestMuPt;
335 if (!muonRef->isTrackerMuon())
338 if (muonRef->numberOfMatches() < 2)
344 if (combinedMuon->hitPattern().numberOfValidTrackerHits() < 11)
347 if (combinedMuon->hitPattern().numberOfValidPixelHits() == 0)
350 if (combinedMuon->hitPattern().numberOfValidMuonHits() == 0)
367 bool isGL = muonRef->isGlobalMuon();
368 bool isTR = muonRef->isTrackerMuon();
369 bool isST = muonRef->isStandAloneMuon();
371 std::cout <<
" GL: " << isGL <<
" TR: " << isTR <<
" ST: " << isST << std::endl;
372 std::cout <<
" nMatches " << muonRef->numberOfMatches() << std::endl;
374 if (muonRef->isGlobalMuon()) {
376 std::cout <<
" GL, pt: " << combinedMu->pt() <<
" +/- " << combinedMu->ptError() / combinedMu->pt()
377 <<
" chi**2 GBL : " << combinedMu->normalizedChi2() << std::endl;
378 std::cout <<
" Total Muon Hits : " << combinedMu->hitPattern().numberOfValidMuonHits() <<
"/"
379 << combinedMu->hitPattern().numberOfLostMuonHits()
380 <<
" DT Hits : " << combinedMu->hitPattern().numberOfValidMuonDTHits() <<
"/"
381 << combinedMu->hitPattern().numberOfLostMuonDTHits()
382 <<
" CSC Hits : " << combinedMu->hitPattern().numberOfValidMuonCSCHits() <<
"/"
383 << combinedMu->hitPattern().numberOfLostMuonCSCHits()
384 <<
" RPC Hits : " << combinedMu->hitPattern().numberOfValidMuonRPCHits() <<
"/"
385 << combinedMu->hitPattern().numberOfLostMuonRPCHits() << std::endl;
387 std::cout <<
" # of Valid Tracker Hits " << combinedMu->hitPattern().numberOfValidTrackerHits() << std::endl;
388 std::cout <<
" # of Valid Pixel Hits " << combinedMu->hitPattern().numberOfValidPixelHits() << std::endl;
390 if (muonRef->isStandAloneMuon()) {
392 std::cout <<
" ST, pt: " << standAloneMu->pt() <<
" +/- " << standAloneMu->ptError() / standAloneMu->pt()
393 <<
" eta : " << standAloneMu->eta()
394 <<
" DT Hits : " << standAloneMu->hitPattern().numberOfValidMuonDTHits() <<
"/"
395 << standAloneMu->hitPattern().numberOfLostMuonDTHits()
396 <<
" CSC Hits : " << standAloneMu->hitPattern().numberOfValidMuonCSCHits() <<
"/"
397 << standAloneMu->hitPattern().numberOfLostMuonCSCHits()
398 <<
" RPC Hits : " << standAloneMu->hitPattern().numberOfValidMuonRPCHits() <<
"/"
399 << standAloneMu->hitPattern().numberOfLostMuonRPCHits()
400 <<
" chi**2 STA : " << standAloneMu->normalizedChi2() << std::endl;
403 if (muonRef->isTrackerMuon()) {
406 std::cout <<
" TR, pt: " << trackerMu->pt() <<
" +/- " << trackerMu->ptError() / trackerMu->pt()
407 <<
" chi**2 TR : " << trackerMu->normalizedChi2() << std::endl;
408 std::cout <<
" nTrackerHits " <<
track.hitPattern().numberOfValidTrackerHits() << std::endl;
419 <<
"TMLastStationOptimizedLowPtLoose "
421 <<
"TMLastStationOptimizedLowPtTight "
423 <<
"TMLastStationOptimizedBarrelLowPtLoose "
425 <<
"TMLastStationOptimizedBarrelLowPtTight "
435 if (muonRef->isGlobalMuon() && muonRef->isTrackerMuon() && muonRef->isStandAloneMuon()) {
440 double sigmaCombined = combinedMu->ptError() / (combinedMu->pt() * combinedMu->pt());
441 double sigmaTracker = trackerMu->ptError() / (trackerMu->pt() * trackerMu->pt());
442 double sigmaStandAlone = standAloneMu->ptError() / (standAloneMu->pt() * standAloneMu->pt());
444 bool combined = combinedMu->ptError() / combinedMu->pt() < 0.20;
445 bool tracker = trackerMu->ptError() / trackerMu->pt() < 0.20;
446 bool standAlone = standAloneMu->ptError() / standAloneMu->pt() < 0.20;
448 double delta1 = combined &&
tracker ? fabs(1. / combinedMu->pt() - 1. / trackerMu->pt()) /
449 sqrt(sigmaCombined * sigmaCombined + sigmaTracker * sigmaTracker)
451 double delta2 = combined &&
standAlone ? fabs(1. / combinedMu->pt() - 1. / standAloneMu->pt()) /
452 sqrt(sigmaCombined * sigmaCombined + sigmaStandAlone * sigmaStandAlone)
454 double delta3 =
standAlone &&
tracker ? fabs(1. / standAloneMu->pt() - 1. / trackerMu->pt()) /
455 sqrt(sigmaStandAlone * sigmaStandAlone + sigmaTracker * sigmaTracker)
459 standAloneMu->hitPattern().numberOfValidMuonDTHits() + standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0
463 std::cout <<
"delta = " <<
delta <<
" delta1 " << delta1 <<
" delta2 " << delta2 <<
" delta3 " << delta3
466 double ratio = combinedMu->ptError() / combinedMu->pt() / (trackerMu->ptError() / trackerMu->pt());
468 std::cout <<
" ratio " <<
ratio <<
" combined mu pt " << combinedMu->pt() << std::endl;
472 double sumPtR03 = muonRef->isolationR03().sumPt;
473 double emEtR03 = muonRef->isolationR03().emEt;
474 double hadEtR03 = muonRef->isolationR03().hadEt;
475 double relIsoR03 = (sumPtR03 + emEtR03 + hadEtR03) / muonRef->pt();
476 double sumPtR05 = muonRef->isolationR05().sumPt;
477 double emEtR05 = muonRef->isolationR05().emEt;
478 double hadEtR05 = muonRef->isolationR05().hadEt;
479 double relIsoR05 = (sumPtR05 + emEtR05 + hadEtR05) / muonRef->pt();
480 std::cout <<
" 0.3 Radion Rel Iso: " << relIsoR03 <<
" sumPt " << sumPtR03 <<
" emEt " << emEtR03 <<
" hadEt "
481 << hadEtR03 << std::endl;
482 std::cout <<
" 0.5 Radion Rel Iso: " << relIsoR05 <<
" sumPt " << sumPtR05 <<
" emEt " << emEtR05 <<
" hadEt "
483 << hadEtR05 << std::endl;
494 std::vector<reco::Muon::MuonTrackTypePair>
out;
496 if (
muon->globalTrack().isNonnull() &&
muon->globalTrack()->pt() > 0)
497 if (
muon->globalTrack()->ptError() /
muon->globalTrack()->pt() < dpt)
500 if (
muon->innerTrack().isNonnull() &&
muon->innerTrack()->pt() > 0)
501 if (
muon->innerTrack()->ptError() /
muon->innerTrack()->pt() < dpt)
504 bool pickyExists =
false;
505 double pickyDpt = 99999.;
506 if (
muon->pickyTrack().isNonnull() &&
muon->pickyTrack()->pt() > 0) {
507 pickyDpt =
muon->pickyTrack()->ptError() /
muon->pickyTrack()->pt();
513 bool dytExists =
false;
514 double dytDpt = 99999.;
515 if (
muon->dytTrack().isNonnull() &&
muon->dytTrack()->pt() > 0) {
516 dytDpt =
muon->dytTrack()->ptError() /
muon->dytTrack()->pt();
526 if (
muon->tpfmsTrack().isNonnull() &&
muon->tpfmsTrack()->pt() > 0) {
527 double tpfmsDpt =
muon->tpfmsTrack()->ptError() /
muon->tpfmsTrack()->pt();
528 if (((pickyExists && tpfmsDpt < pickyDpt) || (!pickyExists)) &&
529 ((dytExists && tpfmsDpt < dytDpt) || (!dytExists)) && tpfmsDpt < dpt)
533 if (includeSA &&
muon->outerTrack().isNonnull())
534 if (
muon->outerTrack()->ptError() /
muon->outerTrack()->pt() < dpt)
544 using namespace reco;
546 if (!
muon.isNonnull())
570 if (validTracks.empty())
576 TrackRef bestTrack = bestTrackPair.first;
580 TrackRef trackWithSmallestError = trackPairWithSmallestError.first;
584 bestTrack->ptError() / bestTrack->pt() >
585 errorCompScale_ * trackWithSmallestError->ptError() / trackWithSmallestError->pt())) {
586 bestTrack = trackWithSmallestError;
587 trackType = trackPairWithSmallestError.second;
589 bestTrack->ptError() / bestTrack->pt() >
590 errorCompScale_ * trackWithSmallestError->ptError() / trackWithSmallestError->pt()) {
591 bestTrack = trackWithSmallestError;
592 trackType = trackPairWithSmallestError.second;
602 using namespace reco;
606 double px = bestTrack->px();
607 double py = bestTrack->py();
608 double pz = bestTrack->pz();
609 double energy =
sqrt(bestTrack->p() * bestTrack->p() + 0.1057 * 0.1057);
611 candidate.
setCharge(bestTrack->charge() > 0 ? 1 : -1);
629 const std::vector<reco::Muon::MuonTrackTypePair>&
tracks) {
640 for (reco::PFCandidateCollection::const_iterator
i = pfc->begin();
i != pfc->end(); ++
i) {
649 using namespace reco;
688 std::vector<int>
muons;
691 for (
unsigned int i = 0;
i <
cands->size(); ++
i) {
699 std::sort(
muons.begin(),
muons.end(), comparator);
702 double METXCosmics = 0;
703 double METYCosmics = 0;
704 double SUMETCosmics = 0.0;
706 for (
unsigned int i = 0;
i <
muons.size(); ++
i) {
714 METXCosmics += pfc.
px();
715 METYCosmics += pfc.
py();
716 SUMETCosmics += pfc.
pt();
719 double MET2Cosmics = METXCosmics * METXCosmics + METYCosmics * METYCosmics;
722 for (
unsigned int i = 0;
i <
cosmics.size(); ++
i) {
728 for (
unsigned int i = 0;
i <
muons.size(); ++
i) {
747 for (
unsigned imu = 0; imu <
muons->size(); ++imu) {
751 for (
unsigned i = 0;
i <
cands->size();
i++) {
760 if (pfc.
muonRef()->innerTrack() == muonRef->innerTrack())
765 if (pfc.
muonRef()->isStandAloneMuon() && muonRef->isStandAloneMuon()) {
766 double dEta = pfc.
muonRef()->standAloneMuon()->eta() - muonRef->standAloneMuon()->eta();
767 double dPhi = pfc.
muonRef()->standAloneMuon()->phi() - muonRef->standAloneMuon()->phi();
779 if (used || hadron || (!muonRef.
isNonnull()))
791 if (!tracksThatChangeMET.empty()) {
793 *std::min_element(tracksThatChangeMET.begin(), tracksThatChangeMET.end(), comparator);
798 int charge = bestTrackType.first->charge() > 0 ? 1 : -1;
800 bestTrackType.first->py(),
801 bestTrackType.first->pz(),
802 sqrt(bestTrackType.first->p() * bestTrackType.first->p() + 0.1057 * 0.1057));
809 cands->back().setTrackRef(muonRef->track());
811 cands->back().setMuonRef(muonRef);
823 double METXNO =
METX_ - pfc.
px();
824 double METYNO =
METY_ - pfc.
py();
825 std::vector<double> met2;
826 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
827 met2.push_back(
pow(METXNO +
tracks.at(
i).first->px(), 2) +
pow(METYNO +
tracks.at(
i).first->py(), 2));
834 return std::make_pair(*std::min_element(met2.begin(), met2.end()), *std::max_element(met2.begin(), met2.end()));
836 return std::make_pair(0, 0);
841 using namespace reco;
842 bool cleaned =
false;
845 double METNOX =
METX_ - pfc.
px();
846 double METNOY =
METY_ - pfc.
py();
860 if (!tracksThatChangeMET.empty()) {
862 *std::min_element(tracksThatChangeMET.begin(), tracksThatChangeMET.end(), comparator);
874 if (!(pfc.
muonRef()->isGlobalMuon() && pfc.
muonRef()->isTrackerMuon())) {
877 double newMET2 = METNOX * METNOX + METNOY * METNOY;
895 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
897 double METNOX =
METX_ - pfc.
px();
898 double METNOY =
METY_ - pfc.
py();
901 double newMET2 = 0.0;
902 double newSUMET = 0.0;
906 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
909 newMET2 =
pow(METNOX +
tracks.at(
i).first->px(), 2) +
pow(METNOY +
tracks.at(
i).first->py(), 2);
912 outputTracks.push_back(
tracks.at(
i));
919 const std::vector<reco::Muon::MuonTrackTypePair>&
tracks) {
920 std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
922 double newMET2 = 0.0;
924 for (
unsigned int i = 0;
i <
tracks.size(); ++
i) {
929 outputTracks.push_back(
tracks.at(
i));
940 using namespace reco;
942 bool cleaned =
false;
947 double METXNO =
METX_ - pfc.
pt();
948 double METYNO =
METY_ - pfc.
pt();
949 double MET2NO = METXNO * METXNO + METYNO * METYNO;
957 fake1 = fabs(pfc.
eta()) > 2.15 && met2.first < met2.second / 2 && MET2NO < MET2 /
metFactorHighEta_ &&
968 if (fake1 || fake2 || punchthrough) {
971 if (!eleInBlocks.empty()) {
972 PFBlockRef blockRefMuon = eleInBlocks[0].first;
973 unsigned indexMuon = eleInBlocks[0].second;
974 if (eleInBlocks.size() > 1)
975 indexMuon = eleInBlocks[1].
second;
980 for (
unsigned i = imu + 1;
i <
cands->size(); ++
i) {
987 unsigned indexHadron = ele[0].second;
989 if (blockRefHadron.
key() != blockRefMuon.
key())
1001 double rescaleFactor =
cands->at(iHad).p() /
cands->at(imu).p();
1005 cands->at(imu).rescaleMomentum(rescaleFactor);
1014 }
else if (fake1 || fake2) {
1029 size_t collSize =
obj->size();
1031 for (
size_t i = 0;
i <
N; ++
i)
1039 iDesc.
add<
double>(
"maxDPtOPt", 1.0);
1041 iDesc.
add<
double>(
"ptErrorScale", 8.0);
1043 iDesc.
add<
double>(
"eventFractionForCleaning", 0.5);
1044 iDesc.
add<
double>(
"minPtForPostCleaning", 20.0);
1045 iDesc.
add<
double>(
"eventFactorForCosmics", 10.0);
1046 iDesc.
add<
double>(
"metSignificanceForCleaning", 3.0);
1047 iDesc.
add<
double>(
"metSignificanceForRejection", 4.0);
1048 iDesc.
add<
double>(
"metFactorForCleaning", 4.0);
1049 iDesc.
add<
double>(
"eventFractionForRejection", 0.8);
1050 iDesc.
add<
double>(
"metFactorForRejection", 4.0);
1051 iDesc.
add<
double>(
"metFactorForHighEta", 25.0);
1052 iDesc.
add<
double>(
"ptFactorForHighEta", 2.0);
1053 iDesc.
add<
double>(
"metFactorForFakes", 4.0);
1054 iDesc.
add<
double>(
"minMomentumForPunchThrough", 100.0);
1055 iDesc.
add<
double>(
"minEnergyForPunchThrough", 100.0);
1056 iDesc.
add<
double>(
"punchThroughFactor", 3.0);
1057 iDesc.
add<
double>(
"punchThroughMETFactor", 4.0);
1058 iDesc.
add<
double>(
"cosmicRejectionDistance", 1.0);