1 |
#include "MitPhysics/Utils/interface/MetLeptonTools.h"
|
2 |
#include <algorithm>
|
3 |
#include <vector>
|
4 |
#include "TString.h"
|
5 |
|
6 |
using namespace mithep;
|
7 |
|
8 |
ClassImp(mithep::MetLeptonTools)
|
9 |
|
10 |
MetLeptonTools::MetLeptonTools() {
|
11 |
//fTauIsoMVA = new TauIsoMVA();
|
12 |
//fTauIsoMVA->Initialize(TString(getenv("CMSSW_BASE")+std::string("/src/MitPhysics/data/SXIsoMVA_BDTG.weights.xml")));
|
13 |
fTauIsoMVA = new TauIsoMVA();
|
14 |
fTauIsoMVA->InitializeGBR(TString(getenv("CMSSW_BASE")+std::string("/src/MitPhysics/data/gbrfTauIso_v2.root")));
|
15 |
}
|
16 |
|
17 |
bool MetLeptonTools::looseTauId(const PFTau *iTau,const PileupEnergyDensityCol* iPUEnergyDensity) {
|
18 |
if(iTau->Pt() < 19) return false;
|
19 |
if(fabs(iTau->Eta()) > fabs(2.3) ) return false;
|
20 |
if(!iTau->DiscriminationByDecayModeFinding()) return false;
|
21 |
if(!iTau->DiscriminationByLooseElectronRejection()) return false;
|
22 |
if(!iTau->LooseMuonRejection2()) return false;
|
23 |
//if(!iTau->DiscriminationByVLooseIsolation() ) return false;
|
24 |
if(fTauIsoMVA->MVAValue(iTau,iPUEnergyDensity->At(0)->Rho()) < 0.8) return false;
|
25 |
return true;
|
26 |
}
|
27 |
bool MetLeptonTools::looseEleId(const Electron *iElectron,const PileupEnergyDensityCol* iPUEnergyDensity,
|
28 |
const PFCandidateCol *iCands,const Vertex *iPV,const VertexCol *iVertices) {
|
29 |
if(iElectron->SCluster() == 0) return false;
|
30 |
if(iElectron->Pt() < 9.5) return false;
|
31 |
if(fabs(iElectron->Eta()) > 2.5) return false;
|
32 |
if(fabs(iElectron->Eta()) > 1.4442 && fabs(iElectron->Eta()) < 1.566) return false;
|
33 |
//if(!fEleTools->PassSpikeRemovalFilter(iElectron)) return false;
|
34 |
//if(isConversion(iElectron)) return false;
|
35 |
//if(iElectron->BestTrk()->D0Corrected(*iPV) > 0.04 ) return false;
|
36 |
//if(iElectron->BestTrk()->DzCorrected(*iPV) > 0.2 ) return false;
|
37 |
//if(!passEleMVA(iElectron ,iPUEnergyDensity,iCands,iPV) ) return false;
|
38 |
//if(isoDeltaBeta(iElectron, iCands,iPV,iVertices) > 0.30) return false;
|
39 |
//return true;
|
40 |
|
41 |
if(iElectron->GsfTrk() == 0) return false;
|
42 |
if(iElectron->GsfTrk()) if(iElectron->GsfTrk()->NExpectedHitsInner() > 0) return false;
|
43 |
//double lIso = isoPV(iElectron,iCands,iPV,iVertices,true)/iElectron->Et();
|
44 |
//if(!iElectron->IsTrackerDriven()) return false;
|
45 |
//if(lIso > 0.2) return false;
|
46 |
|
47 |
if(iElectron->TrackIsolationDr03()/iElectron->Et() > 0.2) return false;
|
48 |
//Electron Veto Id
|
49 |
if(fabs(iElectron->Eta()) < 1.5) {
|
50 |
if(fabs(iElectron->DeltaEtaSuperClusterTrackAtVtx()) > 0.007) return false;
|
51 |
if(fabs(iElectron->DeltaPhiSuperClusterTrackAtVtx()) > 0.8) return false;
|
52 |
if(iElectron->CoviEtaiEta() > 0.01) return false;
|
53 |
if(iElectron->HadronicOverEm() > 0.15) return false;
|
54 |
double lE = iElectron->SCluster()->Energy();
|
55 |
double lP = iElectron->P();
|
56 |
if(fabs(1./lE-1./lP) > 0.05 ) return false;
|
57 |
} else {
|
58 |
if(fabs(iElectron->DeltaEtaSuperClusterTrackAtVtx()) > 0.009) return false;
|
59 |
if(fabs(iElectron->DeltaPhiSuperClusterTrackAtVtx()) > 0.10) return false;
|
60 |
if(iElectron->CoviEtaiEta() > 0.03) return false;
|
61 |
if(iElectron->HadronicOverEm() > 0.10) return false;
|
62 |
double lE = iElectron->SCluster()->Energy();
|
63 |
double lP = iElectron->P();
|
64 |
if(fabs(1./lE-1./lP) > 0.05 ) return false;
|
65 |
}
|
66 |
return true;
|
67 |
}
|
68 |
bool MetLeptonTools::looseMuId(const Muon *iMu,const PFCandidateCol *iCands,const Vertex *iPV,const VertexCol *iVertices) {
|
69 |
if(iMu->TrackerTrk() == 0) return false;
|
70 |
if(iMu->Pt() < 9.5 ) return false;
|
71 |
if(fabs(iMu->BestTrk()->Eta()) > 2.5) return false;
|
72 |
//if(fabs(iMu->BestTrk()->DzCorrected(*iPV)) > 0.2) return false;
|
73 |
//if(iMu->BestTrk()->D0Corrected(*iPV) > 2.0) return false;
|
74 |
if(iMu->BestTrk()->D0() > 2.0) return false;
|
75 |
if(iMu->BestTrk()->RChi2() > 10 ) return false;
|
76 |
if(iMu->TrackerTrk()->NPixelHits() < 1 ) return false;
|
77 |
if(iMu->TrackerTrk()->NHits() < 6 ) return false;
|
78 |
if(iMu->NValidHits() < 1 ) return false;
|
79 |
if(iMu->NMatches() < 1 ) return false;
|
80 |
if(PFIsolation(iMu,iCands) > 0.3) return false;
|
81 |
//if(isoPV(iMu,iCands,iPV,iVertices)/iMu->Pt() > 0.2) return false;
|
82 |
//if(iMu->IsoR03SumPt()/iMu->Pt() > 0.2) return false;
|
83 |
return true;
|
84 |
}
|
85 |
bool MetLeptonTools::loosePhotonId(const Photon *iPhoton) {
|
86 |
if(iPhoton->Pt() < 20) return false;
|
87 |
if(fabs(iPhoton->Eta()) > 1.45) return false;
|
88 |
if(iPhoton->HadOverEm() > 0.05) return false;
|
89 |
if(iPhoton->CoviEtaiEta() > 0.01) return false;
|
90 |
if(iPhoton->HollowConeTrkIsoDr04() > (2.+0.002*iPhoton->Pt())) return false;
|
91 |
return true;
|
92 |
}
|
93 |
double MetLeptonTools::vis(const PFTau *iTau) {
|
94 |
double lPtTot = 0.;
|
95 |
double lChargedPtTot = 0.;
|
96 |
for(unsigned int i0 = 0; i0 < iTau->NSignalPFCands(); i0++) {
|
97 |
lPtTot += iTau->SignalPFCand(i0)->Pt();
|
98 |
if(iTau->SignalPFCand(i0)->BestTrk() == 0) continue;
|
99 |
lChargedPtTot += iTau->SignalPFCand(i0)->Pt();
|
100 |
}
|
101 |
return lChargedPtTot/lPtTot;
|
102 |
}
|
103 |
Float_t MetLeptonTools::PFIsolation(const ChargedParticle *iLep,const PFCandidateCol *iCands) {
|
104 |
Double_t lPtSum = 0.;
|
105 |
for(UInt_t i0 = 0; i0 < iCands->GetEntries(); i0++) {
|
106 |
const PFCandidate *pCand = iCands->At(i0);
|
107 |
Double_t pDR = MathUtils::DeltaR(iLep->Mom(), pCand->Mom());
|
108 |
if(pDR < 0.0001) continue;
|
109 |
if(pDR < 0.01 && (pCand->PFType() != PFCandidate::eNeutralHadron || pCand->PFType() != PFCandidate::eGamma)) continue;
|
110 |
if(pCand->Pt() < 0.5 && (pCand->PFType() != PFCandidate::eNeutralHadron || pCand->PFType() != PFCandidate::eGamma)) continue;
|
111 |
if(pCand->PFType() != PFCandidate::eNeutralHadron && pCand->PFType() != PFCandidate::eGamma && pCand->PFType() != PFCandidate::eHadron ) continue;
|
112 |
//if(pCand->PFType() != PFCandidate::eHadron) continue;
|
113 |
//if(pCand->Pt() < 0.5) continue;
|
114 |
//if(pDR < 0.0001 && fabs(iLep->Eta()) > 1.56) continue;
|
115 |
if(pDR > 0.3) continue;
|
116 |
lPtSum += pCand->Pt();
|
117 |
}
|
118 |
return lPtSum/iLep->Pt();
|
119 |
}
|
120 |
Float_t MetLeptonTools::isoPV(const ChargedParticle *iLep,const PFCandidateCol *iCands,
|
121 |
const Vertex *iPV,const VertexCol *iVertices,bool iEle) {
|
122 |
Float_t lPtSumCharge = 0.;
|
123 |
for(UInt_t i0 = 0; i0 < iCands->GetEntries(); i0++) {
|
124 |
const PFCandidate *pCand = iCands->At(i0);
|
125 |
Double_t pDR = MathUtils::DeltaR(iLep->Mom(), pCand->Mom());
|
126 |
if(pCand->PFType() != PFCandidate::eHadron) continue;
|
127 |
if(pDR > 0.3) continue;
|
128 |
if(pDR < 0.0001) continue;
|
129 |
if(iEle && pDR < 0.015 && fabs(iLep->Eta()) > 1.56) continue;
|
130 |
if(iEle && pDR < 0.01 && fabs(iLep->Eta()) < 1.56) continue;
|
131 |
if(pCand->HasTrackerTrk() && iPV !=0) {
|
132 |
if( iPV->HasTrack(pCand->TrackerTrk())) lPtSumCharge += pCand->Pt();
|
133 |
//if( iPV->HasTrack(pCand->TrackerTrk())) std::cout << "===> Adding ===> " << pCand->Pt() << " --" << pDR << " -- " << pCand->BestTrk()->DzCorrected(*iPV) << std::endl;
|
134 |
if( iPV->HasTrack(pCand->TrackerTrk())) continue;
|
135 |
}
|
136 |
Double_t pDzMin = 10000;
|
137 |
Bool_t pVertexFound = kFALSE;
|
138 |
const Vertex *pClosestVtx = 0;
|
139 |
for(UInt_t i1 = 0; i1 < iVertices->GetEntries(); i1++) {
|
140 |
const Vertex *pVtx = iVertices->At(i1);
|
141 |
if(pVtx->HasTrack(pCand->TrackerTrk())) {
|
142 |
pClosestVtx = pVtx; pVertexFound = kTRUE; break;
|
143 |
}
|
144 |
Double_t pDz = fabs(pCand->SourceVertex().Z() - pVtx->Z());
|
145 |
if(pDz < pDzMin) {
|
146 |
pClosestVtx = pVtx;
|
147 |
pDzMin = pDz;
|
148 |
}
|
149 |
}
|
150 |
if(pVertexFound || pClosestVtx != iPV) continue;
|
151 |
//std::cout << "===> Adding NV ===> " << pCand->Pt() << " --" << pDR << " -- " << pCand->BestTrk()->DzCorrected(*iPV) << std::endl;
|
152 |
lPtSumCharge += pCand->Pt();
|
153 |
}
|
154 |
return lPtSumCharge;// + TMath::Max(lPtSumNeut-lPtSumPU*0.5,0.))/iLep->Pt();
|
155 |
}
|