ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/lucieg/macros/effPlots.py
Revision: 1.1
Committed: Thu Jul 7 11:43:03 2011 UTC (13 years, 9 months ago) by lucieg
Content type: text/x-python
Branch: MAIN
CVS Tags: logger_lucieg_11Jul11-14h37m27s
Log Message:
added directory to store macros. bad habit with rm -rf :)

File Contents

# User Rev Content
1 lucieg 1.1 #! /usr/bin/env python
2    
3     import ROOT, sys
4     from DataFormats.FWLite import Events, Handle
5     from aux import *
6     from array import array
7     from makeEffPlots import makeEffPlots
8     from bookHisto import bookHisto
9    
10     #input file(s)
11     #files = ["/data/lucieg/SingleEle/tree_CMG_1k.root"]
12     files = ["/data/lucieg/RelValZEE423/tree_CMG_0.root","/data/lucieg/RelValZEE423/tree_CMG_1.root","/data/lucieg/RelValZEE423/tree_CMG_2.root"]
13     #files = ["/data/lucieg/RelValWE423/tree_CMG_0.root","/data/lucieg/RelValWE423/tree_CMG_1.root","/data/lucieg/RelValWE423/tree_CMG_2.root"]
14    
15     #get objects
16     events = Events (files)
17    
18     handleGenLeptons = Handle ('std::vector<reco::GenParticle>')
19     handleCmgElectrons = Handle ('std::vector<cmg::Electron>')
20    
21     cmgElectrons = ("cmgElectronSel")
22     genLeptons = ("genParticles")
23     pdgId = 11 #for electrons
24    
25     #output file
26     histo = ROOT.TFile("effPlots.root", "RECREATE")
27    
28     #matching
29     dR = ROOT.TH1F("dR", "dR", 100, 0., 10.)
30     dPtRel = ROOT.TH1F("dPtRel", "dPtRel", 100, 0., 1.)
31    
32     ####################
33     ##efficiency plots##
34     ####################
35     #binning
36     binsLowEdges = array('d',[0., 5., 10., 15., 20., 25., 30., 35., 40., 45., 50., 60.])
37    
38     #denominator histo
39     genLeptonPt = ROOT.TH1F("genLeptonPt", "pt", len(binsLowEdges)-1, binsLowEdges )
40    
41     #reference = no cut
42     genLeptonPtMatched = ROOT.TH1F("genLeptonPtMatched", "pt", len(binsLowEdges)-1, binsLowEdges)
43    
44     #cuts & histos lists
45     #vbtf ID
46     cutsVBTFID = ["","cuts_vbtf95ID", "cuts_vbtf90ID", "cuts_vbtf80ID", "cuts_vbtf70ID", "cuts_vbtf60ID"]
47     histosToCompareVBTFID = [genLeptonPtMatched]
48     bookHisto(cutsVBTFID, binsLowEdges, histosToCompareVBTFID)
49    
50     #vbtf ID + CR
51     cutsVBTFCR = ["","cuts_vbtf95CR", "cuts_vbtf90CR", "cuts_vbtf80CR", "cuts_vbtf70CR", "cuts_vbtf60CR"]
52     histosToCompareVBTFIDandCR = [genLeptonPtMatched]
53     bookHisto(cutsVBTFCR, binsLowEdges, histosToCompareVBTFIDandCR)
54    
55     #cic ID
56     cutsCiCID = ["", "cuts_veryLooseID", "cuts_looseID", "cuts_mediumID", "cuts_tightID", "cuts_superTightID"]
57     histosToCompareCiCID = [genLeptonPtMatched]
58     bookHisto(cutsCiCID, binsLowEdges, histosToCompareCiCID)
59    
60     #cic ID + CR
61     cutsCiCCR = ["", "cuts_veryLooseCR", "cuts_looseCR", "cuts_mediumCR", "cuts_tightCR", "cuts_superTightCR"]
62     histosToCompareCiCIDandCR = [genLeptonPtMatched]
63     bookHisto(cutsCiCCR, binsLowEdges, histosToCompareCiCIDandCR)
64    
65     #versus RA2 cut
66     ## cutsVBTFID += "cut_RA2"
67     ## cutsVBTFCR += "cut_RA2"
68     ## cutsCiCID += "cut_RA2"
69     ## cutsCiCCR += "cut_RA2"
70     RA2LeptonPtMatched = ROOT.TH1F("RA2LeptonPtMatched", "pt", len(binsLowEdges)-1, binsLowEdges)
71    
72    
73     ####################
74     ##loop over events##
75     ####################
76     i = 0
77     for event in events:
78     i = i + 1
79     if (i > 1000) :
80     break
81    
82     event.getByLabel (cmgElectrons, handleCmgElectrons)
83     event.getByLabel (genLeptons, handleGenLeptons)
84    
85     cmgEles = handleCmgElectrons.product()
86     genLeptons = handleGenLeptons.product()
87    
88     for genLepton in genLeptons :
89     if (genLepton.status() != 1 or abs(genLepton.pdgId()) != 11 or abs(genLepton.eta()) > 2.5 or (abs(genLepton.eta()) > 1.44 and abs(genLepton.eta()) < 1.57) or genLepton.pt() < 5.):
90     continue
91    
92     else :
93     genLeptonPt.Fill(genLepton.pt())
94    
95     (dRmin, dPt, index) = deltaRmin(genLepton, cmgEles)
96     dR.Fill(dRmin)
97     dPtRel.Fill(dPt)
98    
99     if (index == -1) :
100     continue
101    
102     RA2IDCut = (cmgElectrons[index].sourcePtr().gsfTrack().trackerExpectedHitsInner().numberOfLostHits() < 2)
103    
104     ## RA2VtxCut = (vertices.size() >0) && (cmgLeptons[index].sourcePtr().gsfTrack().dxy(vtxpos) < maxEleD0) && (cmgLeptons[index].vz() - vtxpos.z() >=1))
105    
106     ## if (RA2IDCut && RA2VtxCut) :
107     ## RA2LeptonPtMatched.Fill(genLepton.pt())
108    
109     if (matched(dRmin, dPt, 0.11, 1.)):
110     genLeptonPtMatched.Fill(genLepton.pt())
111     cut = 1
112     while (cut < len( histosToCompareVBTFID ) ):
113     if (cmgLeptons[index].getSelection(cutsVBTFID[cut])):
114     histosToCompareVBTFID[cut].Fill(genLepton.pt())
115     cut +=1
116     cut = 1
117     while (cut < len( histosToCompareVBTFIDandCR ) ):
118     if (cmgLeptons[index].getSelection(cutsVBTFID[cut]) and cmgLeptons[index].getSelection(cutsVBTFCR[cut])):
119     histosToCompareVBTFIDandCR[cut].Fill(genLepton.pt())
120     cut +=1
121     cut = 1
122     while (cut < len( histosToCompareCiCID ) ):
123     if (cmgLeptons[index].getSelection(cutsCiCID[cut])):
124     histosToCompareCiCID[cut].Fill(genLepton.pt())
125     cut +=1
126     cut = 1
127     while (cut < len( histosToCompareCiCIDandCR ) ):
128     if (cmgLeptons[index].getSelection(cutsCiCID[cut]) and cmgLeptons[index].getSelection(cutsCiCCR[cut])):
129     histosToCompareCiCIDandCR[cut].Fill(genLepton.pt())
130     cut +=1
131    
132     #plots
133     genLeptonPt.Sumw2()
134    
135     genLeptonPtMatched.Sumw2()
136     genLeptonPtMatched.Divide(genLeptonPt)
137    
138     cEfficiencies = ROOT.TCanvas("efficiencies")
139     cEfficiencies.Divide(2,2)
140    
141     cEfficiencies.cd(1)
142     leg1 = ROOT.TLegend(0.6,0.1,0.9,0.5)
143     makeEffPlots(histosToCompareVBTFID, genLeptonPt, cutsVBTFID, "pt(GeV)", "efficiency (#matched/total)", "reconstruction efficiency vs pt, vbtfID", leg1 )
144    
145     cEfficiencies.cd(2)
146     leg2 = ROOT.TLegend(0.6,0.1,0.9,0.5)
147     makeEffPlots(histosToCompareVBTFIDandCR, genLeptonPt, cutsVBTFCR, "pt(GeV)", "efficiency (#matched/total)", "reconstruction efficiency vs pt, vbtfIDandCR", leg2 )
148    
149     cEfficiencies.cd(3)
150     leg3 = ROOT.TLegend(0.6,0.1,0.9,0.5)
151     makeEffPlots(histosToCompareCiCID, genLeptonPt, cutsCiCID, "pt(GeV)", "efficiency (#matched/total)", "reconstruction efficiency vs pt, CiCID", leg3 )
152    
153     cEfficiencies.cd(4)
154     leg4 = ROOT.TLegend(0.6,0.1,0.9,0.5)
155     makeEffPlots(histosToCompareCiCIDandCR, genLeptonPt, cutsCiCCR, "pt(GeV)", "efficiency (#matched/total)", "reconstruction efficiency vs pt, CiC ID and CR", leg4 )
156    
157    
158     #matching
159     cMatching = ROOT.TCanvas("matching")
160     cMatching.Divide(2,1)
161    
162     cMatching.cd(1)
163     dR.Draw()
164    
165     cMatching.cd(2)
166     dPtRel.Draw()
167    
168     histo.cd()
169     histo.Write()
170     #histo.Close()