ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/kiesel/plotTree/ewkPlots.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: +31 -9 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 import ratios
10 kiesel 1.1 Styles.tdrStyle()
11 kiesel 1.2 import os
12 kiesel 1.1
13     import ConfigParser
14     axisConf = ConfigParser.SafeConfigParser()
15     axisConf.read("axis.cfg")
16    
17     if __name__ == "__main__":
18     arguments = argparse.ArgumentParser( description="Simple EWK" )
19 kiesel 1.2 arguments.add_argument( "--plot", default="photon.pt" )
20     arguments.add_argument( "--input", default="slimEWK_V01.12_tree.root" )
21     arguments.add_argument( "--savePrefix", default="new" )
22 kiesel 1.1 opts = arguments.parse_args()
23    
24 kiesel 1.2 ROOT.gROOT.SetBatch()
25 kiesel 1.1
26 kiesel 1.2 slimFileName = opts.input.replace( os.path.basename(opts.input), "slim"+os.path.basename(opts.input))
27    
28     genE = Dataset( opts.input, "susyTree", "Max$(abs(genElectron.eta)) < 1.4442 && @genElectron.size() > 0", "e_{gen}", 1 )
29     recE = Dataset( slimFileName, "photonElectronTree", "photon.genInformation==1", "e", 2 )
30     gamma = Dataset( slimFileName, "photonTree", "photon.genInformation==1", "#gamma", 3 )
31 kiesel 1.1
32     multihisto = Multihisto()
33    
34     label, unit = readAxisConf( opts.plot, axisConf)
35    
36 kiesel 1.2 histForRatio = {}
37    
38 kiesel 1.1 for dataset in [genE, recE, gamma]:
39     if dataset.label == "e_{gen}":
40     try:
41     plot = opts.plot.replace("photon","genElectron")
42     except:
43     plot = opts.plot
44     else:
45     plot = opts.plot
46    
47     hist = createHistoFromTree( dataset.tree, plot, "weight*(%s)"%(dataset.additionalCut), firstBin=10, lastBin=200 )
48     hist.SetTitle(";%s%s;Entries"%(label,unit))
49     hist.SetLineColor( dataset.color )
50     hist.SetLineWidth(2)
51     multihisto.addHisto( hist, dataset.label )
52 kiesel 1.2 histForRatio[dataset.label] = hist
53 kiesel 1.1
54     can = ROOT.TCanvas()
55 kiesel 1.2
56     hPad = ROOT.TPad("hPad", "Histogram", 0, 0, 1, 1)
57     #hPad = ROOT.TPad("hPad", "Histogram", 0, 0.2, 1, 1)
58     hPad.cd()
59 kiesel 1.1 multihisto.Draw("hist")
60    
61 kiesel 1.2 ratioPad = ROOT.TPad("ratioPad", "Ratio", 0, 0, 1, 0.2)
62     ratioPad.cd()
63     ratioPad.SetLogy(0)
64     ratioGraph = ratios.RatioGraph(histForRatio["e"], histForRatio["e_{gen}"])
65     ratioGraph.draw(ROOT.gPad, yMin=0.5, yMax=1.5, adaptiveBinning=False, errors="x")
66     ratioGraph.hAxis.SetYTitle( "e/e_{gen}")
67     ratioGraph.graph.Draw("same p")
68    
69     can.cd()
70     hPad.Draw()
71     #ratioPad.Draw()
72     can.SaveAs("plots/%s_%s_%s.pdf"%(opts.input[0:5],opts.plot.replace(".",""),opts.savePrefix))
73     del can
74 kiesel 1.1