--- UserCode/kiesel/plotTree/ewkFakeRate.py 2013/05/03 08:56:35 1.1 +++ UserCode/kiesel/plotTree/ewkFakeRate.py 2013/05/15 14:20:17 1.2 @@ -6,7 +6,10 @@ import argparse from multiplot import * from treeFunctions import * import Styles -Styles.tdrStyle() +style = Styles.tdrStyle() +style.SetOptLogy(0) +ROOT.TGaxis.SetMaxDigits(3) +import os import ConfigParser axisConf = ConfigParser.SafeConfigParser() @@ -31,45 +34,75 @@ def divideDatasets( d1, d2, label, unit hist.SetLineWidth(2) ratioHists.append( hist ) - ratioHists[0].Divide( ratioHists[1] ) + #ratioHists[0].Divide( ratioHists[1] ) # normal division + ratioHists[0].Divide( ratioHists[0], ratioHists[1], 1, 1, "B" ) # division using bayes theorem ratioHists[0].SetTitle(";%s%s;%s/%s"%(label,unit,d1.label,d2.label)) return ratioHists[0] -if True: +if __name__ == "__main__": arguments = argparse.ArgumentParser( description="Simple EWK" ) arguments.add_argument( "--plot", default="photon.pt" ) - arguments.add_argument( "--dataset", default="EWK" ) + arguments.add_argument( "--input", default="EWK_V01.12_tree.root" ) + arguments.add_argument( "--savePrefix", default="new" ) opts = arguments.parse_args() - version = "07" - fileName = "slim%s_V01.%s_tree.root"%(opts.dataset, version ) + ROOT.gROOT.SetBatch() + import re + # dataset name is from beginning till first '_' + slimFileName = opts.input.replace( os.path.basename(opts.input), "slim"+os.path.basename(opts.input)) + dataset = re.match("slim([^_]*)_.*", slimFileName ).groups()[0] - genE = Dataset( fileName, "genElectronTree", "abs(genElectron.eta) < 1.479", "e_{gen}", 3 ) - recE = Dataset( fileName, "photonElectronTree", "@genElectron.size()>0 && photon[0].pixelseed < 0", "e", 2 ) - gamma = Dataset( fileName, "photonTree", "@genElectron.size()>0 && photon[0].pixelseed < 0", "#gamma", 1 ) + + genE = Dataset( slimFileName, "genElectronTree", "1", "e_{gen}", 3 ) + genE_with_match = Dataset( slimFileName, "genElectronTree", "genElectron.phi > 4", "e_{gen, match}", 1 ) + gamma = Dataset( slimFileName, "photonTree", "1", "#gamma", 1 ) + gamma_with_match = Dataset( slimFileName, "photonTree", "photon.genInformation == 1", "#gamma_{match}", 1 ) label, unit = readAxisConf( opts.plot, axisConf ) - h = divideDatasets( gamma, recE, label, unit ) + e_match_e_reco = divideDatasets( gamma_with_match, genE, label, unit ) + e_match = divideDatasets( genE_with_match, gamma, label, unit ) can = ROOT.TCanvas() can.cd() can.SetLogy(0) + datasetLabel = ROOT.TPaveText(.4,.9,.6,.98, "ndc") + datasetLabel.SetFillColor(0) + datasetLabel.SetBorderSize(0) + datasetLabel.AddText( dataset ) + + + e_match_e_reco.GetYaxis().SetTitle("#varepsilon_{match}#upointf_{e_{gen}#rightarrow#gamma}") + e_match_e_reco.Draw("e") + datasetLabel.Draw() + can.SaveAs("plots/%sEfficiencyFakeRate.pdf"%dataset) + e_match.GetYaxis().SetTitle("#varepsilon_{match}") + e_match.Draw("e") + datasetLabel.Draw() + can.SaveAs("plots/%sEfficiency.pdf"%dataset) + + h = e_match_e_reco.Clone("fakerate") + h.GetYaxis().SetTitle("f_{e_{gen}#rightarrow #gamma}") + + h.Divide( e_match ) + #h = divideDatasets( gamma, recE, label, unit ) + + yutaro = h.Clone("yutaro") - yutaro.SetBinContent(1,0.0196) - yutaro.SetBinError(1,0.0004) - yutaro.SetBinContent(2,0.0198) - yutaro.SetBinError(2,0.0006) - yutaro.SetBinContent(3,0.0202) - yutaro.SetBinError(3,0.0002) - yutaro.SetBinContent(4,0.0180) - yutaro.SetBinError(4,0.0004) - yutaro.SetBinContent(5,0.0162) - yutaro.SetBinError(5,0.0006) - yutaro.SetBinContent(6,0.0148) - yutaro.SetBinError(6,0.0010) + yutaro.SetBinContent(1,0.0131) + yutaro.SetBinError (1,0.0004) + yutaro.SetBinContent(2,0.0146) + yutaro.SetBinError (2,0.0002) + yutaro.SetBinContent(3,0.0148) + yutaro.SetBinError (3,0.0001) + yutaro.SetBinContent(4,0.0111) + yutaro.SetBinError (4,0.0002) + yutaro.SetBinContent(5,0.0111) + yutaro.SetBinError (5,0.0004) + yutaro.SetBinContent(6,0.0085) + yutaro.SetBinError (6,0.0005) yutaro.SetLineColor(2) yutaro.SetMarkerColor(2) @@ -78,4 +111,22 @@ if True: h.Draw("e") yutaro.Draw("same e0") - can.SaveAs("pt_fake_new.pdf") + leg = myLegend(.5,.70,.95,.92) + leg.AddEntry( h, h.GetYaxis().GetTitle(), "lp") + leg.AddEntry( yutaro, "Yutaro's f_{e#rightarrow#gamma}", "lp" ) + leg.SetBorderSize(1) + leg.Draw() + + datasetLabel.Draw() + + + saveName = "%s_%s_%s_%s"%(h.GetYaxis().GetTitle(),dataset,opts.plot,opts.savePrefix) + saveName = saveName.replace("/","VS") + saveName = saveName.replace(" ","_") + unallowedCharacters = ["{","}","(",")","#","|","."] + for char in unallowedCharacters: + saveName = saveName.replace( char, "" ) + + can.SaveAs("plots/%s.pdf"%saveName) + +