ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/MetLeptonTools.cc
Revision: 1.4
Committed: Sat Jan 12 11:49:50 2013 UTC (12 years, 3 months ago) by pharris
Content type: text/plain
Branch: MAIN
Changes since 1.3: +8 -0 lines
Log Message:
Updated MVA Met and Jet ID

File Contents

# User Rev Content
1 pharris 1.1 #include "MitPhysics/Utils/interface/MetLeptonTools.h"
2     #include <algorithm>
3     #include <vector>
4 pharris 1.3 #include "TString.h"
5 pharris 1.1
6     using namespace mithep;
7    
8     ClassImp(mithep::MetLeptonTools)
9    
10 pharris 1.3 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 pharris 1.1 return true;
24     }
25     bool MetLeptonTools::looseEleId(const Electron *iElectron,const PileupEnergyDensityCol* iPUEnergyDensity,
26     const PFCandidateCol *iCands,const Vertex *iPV,const VertexCol *iVertices) {
27 pharris 1.2 if(iElectron->SCluster() == 0) return false;
28 pharris 1.1 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 pharris 1.2 //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 pharris 1.1 //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 pharris 1.4 bool MetLeptonTools::loosePhotonId(const Photon *iPhoton) {
84     if(iPhoton->Pt() < 20) return false;
85     if(fabs(iPhoton->Eta()) > 1.45) return false;
86     if(iPhoton->HadOverEm() > 0.05) return false;
87     if(iPhoton->CoviEtaiEta() > 0.01) return false;
88     if(iPhoton->HollowConeTrkIsoDr04() > (2.+0.002*iPhoton->Pt())) return false;
89     return true;
90     }
91 pharris 1.1 double MetLeptonTools::vis(const PFTau *iTau) {
92     double lPtTot = 0.;
93     double lChargedPtTot = 0.;
94     for(unsigned int i0 = 0; i0 < iTau->NSignalPFCands(); i0++) {
95     lPtTot += iTau->SignalPFCand(i0)->Pt();
96     if(iTau->SignalPFCand(i0)->BestTrk() == 0) continue;
97     lChargedPtTot += iTau->SignalPFCand(i0)->Pt();
98     }
99     return lChargedPtTot/lPtTot;
100     }
101     Float_t MetLeptonTools::PFIsolation(const ChargedParticle *iLep,const PFCandidateCol *iCands) {
102     Double_t lPtSum = 0.;
103     for(UInt_t i0 = 0; i0 < iCands->GetEntries(); i0++) {
104     const PFCandidate *pCand = iCands->At(i0);
105     if(pCand->PFType() != PFCandidate::eHadron) continue;
106     Double_t pDR = MathUtils::DeltaR(iLep->Mom(), pCand->Mom());
107     if(pCand->Pt() < 0.5) continue;
108     if(pDR < 0.015 && fabs(iLep->Eta()) > 1.56) continue;
109     if(pDR > 0.3) continue;
110     lPtSum += pCand->Pt();
111     }
112     return lPtSum;
113     }
114     Float_t MetLeptonTools::isoPV(const ChargedParticle *iLep,const PFCandidateCol *iCands,
115     const Vertex *iPV,const VertexCol *iVertices,bool iEle) {
116     Float_t lPtSumCharge = 0.;
117     for(UInt_t i0 = 0; i0 < iCands->GetEntries(); i0++) {
118     const PFCandidate *pCand = iCands->At(i0);
119     Double_t pDR = MathUtils::DeltaR(iLep->Mom(), pCand->Mom());
120     if(pCand->PFType() != PFCandidate::eHadron) continue;
121     if(pDR > 0.3) continue;
122     if(pDR < 0.0001) continue;
123     if(iEle && pDR < 0.015 && fabs(iLep->Eta()) > 1.56) continue;
124     if(iEle && pDR < 0.01 && fabs(iLep->Eta()) < 1.56) continue;
125     if(pCand->HasTrackerTrk() && iPV !=0) {
126     if( iPV->HasTrack(pCand->TrackerTrk())) lPtSumCharge += pCand->Pt();
127     //if( iPV->HasTrack(pCand->TrackerTrk())) std::cout << "===> Adding ===> " << pCand->Pt() << " --" << pDR << " -- " << pCand->BestTrk()->DzCorrected(*iPV) << std::endl;
128     if( iPV->HasTrack(pCand->TrackerTrk())) continue;
129     }
130     Double_t pDzMin = 10000;
131     Bool_t pVertexFound = kFALSE;
132     const Vertex *pClosestVtx = 0;
133     for(UInt_t i1 = 0; i1 < iVertices->GetEntries(); i1++) {
134     const Vertex *pVtx = iVertices->At(i1);
135     if(pVtx->HasTrack(pCand->TrackerTrk())) {
136     pClosestVtx = pVtx; pVertexFound = kTRUE; break;
137     }
138     Double_t pDz = fabs(pCand->SourceVertex().Z() - pVtx->Z());
139     if(pDz < pDzMin) {
140     pClosestVtx = pVtx;
141     pDzMin = pDz;
142     }
143     }
144     if(pVertexFound || pClosestVtx != iPV) continue;
145     //std::cout << "===> Adding NV ===> " << pCand->Pt() << " --" << pDR << " -- " << pCand->BestTrk()->DzCorrected(*iPV) << std::endl;
146     lPtSumCharge += pCand->Pt();
147     }
148     return lPtSumCharge;// + TMath::Max(lPtSumNeut-lPtSumPU*0.5,0.))/iLep->Pt();
149     }