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