ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/kiesel/plotTree/ewkFakeRate.py
Revision: 1.2
Committed: Wed May 15 14:20:17 2013 UTC (11 years, 11 months ago) by kiesel
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +74 -23 lines
Log Message:
nicer plot routines

File Contents

# User Rev Content
1 kiesel 1.1 #! /usr/bin/env python2
2     # -*- coding: utf-8 -*-
3     import ROOT
4     ROOT.gSystem.Load("libTreeObjects.so")
5     import argparse
6     from multiplot import *
7     from treeFunctions import *
8     import Styles
9 kiesel 1.2 style = Styles.tdrStyle()
10     style.SetOptLogy(0)
11     ROOT.TGaxis.SetMaxDigits(3)
12     import os
13 kiesel 1.1
14     import ConfigParser
15     axisConf = ConfigParser.SafeConfigParser()
16     axisConf.read("axis.cfg")
17    
18     def divideDatasets( d1, d2, label, unit ):
19     # d1, d2 are multiplot.Datasets (own definition)
20     ratioHists = []
21     for dataset in [d1, d2]:
22     if dataset.label == "e_{gen}":
23     try:
24     plot = opts.plot.replace("photon","genElectron")
25     except:
26     plot = opts.plot
27     else:
28     plot = opts.plot
29    
30     yutarosBinning = [ 25, 35, 40, 50, 60, 80, 100 ]
31     hist = createHistoFromTree( dataset.tree, plot, "weight*(%s)"%(dataset.additionalCut), nBins=yutarosBinning)
32     hist.SetTitle(";%s%s;Entries"%(label,unit))
33     hist.SetLineColor( dataset.color )
34     hist.SetLineWidth(2)
35     ratioHists.append( hist )
36    
37 kiesel 1.2 #ratioHists[0].Divide( ratioHists[1] ) # normal division
38     ratioHists[0].Divide( ratioHists[0], ratioHists[1], 1, 1, "B" ) # division using bayes theorem
39 kiesel 1.1 ratioHists[0].SetTitle(";%s%s;%s/%s"%(label,unit,d1.label,d2.label))
40     return ratioHists[0]
41    
42    
43 kiesel 1.2 if __name__ == "__main__":
44 kiesel 1.1 arguments = argparse.ArgumentParser( description="Simple EWK" )
45     arguments.add_argument( "--plot", default="photon.pt" )
46 kiesel 1.2 arguments.add_argument( "--input", default="EWK_V01.12_tree.root" )
47     arguments.add_argument( "--savePrefix", default="new" )
48 kiesel 1.1 opts = arguments.parse_args()
49    
50 kiesel 1.2 ROOT.gROOT.SetBatch()
51     import re
52     # dataset name is from beginning till first '_'
53     slimFileName = opts.input.replace( os.path.basename(opts.input), "slim"+os.path.basename(opts.input))
54     dataset = re.match("slim([^_]*)_.*", slimFileName ).groups()[0]
55 kiesel 1.1
56 kiesel 1.2
57     genE = Dataset( slimFileName, "genElectronTree", "1", "e_{gen}", 3 )
58     genE_with_match = Dataset( slimFileName, "genElectronTree", "genElectron.phi > 4", "e_{gen, match}", 1 )
59     gamma = Dataset( slimFileName, "photonTree", "1", "#gamma", 1 )
60     gamma_with_match = Dataset( slimFileName, "photonTree", "photon.genInformation == 1", "#gamma_{match}", 1 )
61 kiesel 1.1
62     label, unit = readAxisConf( opts.plot, axisConf )
63 kiesel 1.2 e_match_e_reco = divideDatasets( gamma_with_match, genE, label, unit )
64     e_match = divideDatasets( genE_with_match, gamma, label, unit )
65 kiesel 1.1
66    
67     can = ROOT.TCanvas()
68     can.cd()
69     can.SetLogy(0)
70    
71 kiesel 1.2 datasetLabel = ROOT.TPaveText(.4,.9,.6,.98, "ndc")
72     datasetLabel.SetFillColor(0)
73     datasetLabel.SetBorderSize(0)
74     datasetLabel.AddText( dataset )
75    
76    
77     e_match_e_reco.GetYaxis().SetTitle("#varepsilon_{match}#upointf_{e_{gen}#rightarrow#gamma}")
78     e_match_e_reco.Draw("e")
79     datasetLabel.Draw()
80     can.SaveAs("plots/%sEfficiencyFakeRate.pdf"%dataset)
81     e_match.GetYaxis().SetTitle("#varepsilon_{match}")
82     e_match.Draw("e")
83     datasetLabel.Draw()
84     can.SaveAs("plots/%sEfficiency.pdf"%dataset)
85    
86     h = e_match_e_reco.Clone("fakerate")
87     h.GetYaxis().SetTitle("f_{e_{gen}#rightarrow #gamma}")
88    
89     h.Divide( e_match )
90     #h = divideDatasets( gamma, recE, label, unit )
91    
92    
93 kiesel 1.1 yutaro = h.Clone("yutaro")
94 kiesel 1.2 yutaro.SetBinContent(1,0.0131)
95     yutaro.SetBinError (1,0.0004)
96     yutaro.SetBinContent(2,0.0146)
97     yutaro.SetBinError (2,0.0002)
98     yutaro.SetBinContent(3,0.0148)
99     yutaro.SetBinError (3,0.0001)
100     yutaro.SetBinContent(4,0.0111)
101     yutaro.SetBinError (4,0.0002)
102     yutaro.SetBinContent(5,0.0111)
103     yutaro.SetBinError (5,0.0004)
104     yutaro.SetBinContent(6,0.0085)
105     yutaro.SetBinError (6,0.0005)
106 kiesel 1.1 yutaro.SetLineColor(2)
107     yutaro.SetMarkerColor(2)
108    
109     h.SetMaximum(max(h.GetMaximum(),yutaro.GetMaximum())+0.002)
110     h.SetMinimum(min(h.GetMinimum(),yutaro.GetMinimum())-0.002)
111     h.Draw("e")
112     yutaro.Draw("same e0")
113    
114 kiesel 1.2 leg = myLegend(.5,.70,.95,.92)
115     leg.AddEntry( h, h.GetYaxis().GetTitle(), "lp")
116     leg.AddEntry( yutaro, "Yutaro's f_{e#rightarrow#gamma}", "lp" )
117     leg.SetBorderSize(1)
118     leg.Draw()
119    
120     datasetLabel.Draw()
121    
122    
123     saveName = "%s_%s_%s_%s"%(h.GetYaxis().GetTitle(),dataset,opts.plot,opts.savePrefix)
124     saveName = saveName.replace("/","VS")
125     saveName = saveName.replace(" ","_")
126     unallowedCharacters = ["{","}","(",")","#","|","."]
127     for char in unallowedCharacters:
128     saveName = saveName.replace( char, "" )
129    
130     can.SaveAs("plots/%s.pdf"%saveName)
131    
132