ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/kiesel/plotTree/multiplot.py
Revision: 1.1
Committed: Fri May 3 08:56:35 2013 UTC (12 years ago) by kiesel
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Log Message:
added plotting helpers (ugly now, but only for saving)

File Contents

# Content
1 import ROOT
2 import ConfigParser
3 import os.path
4 from treeFunctions import *
5
6 datasetConf = ConfigParser.SafeConfigParser()
7 datasetConf.read( "dataset.cfg" )
8
9 integratedLumi = 19300 #pb
10
11 class Dataset:
12 def __init__( self, filename, treeName, cut="1", label=None, color=None ):
13 self.tree = readTree( filename, treeName )
14 self.additionalCut = cut
15 self.label = label
16
17 for configName in datasetConf.sections():
18 if filename.count( configName ):
19 self.datasetLabel = datasetConf.get( configName, "label" )
20 self.color = datasetConf.get( configName, "color" )
21
22 if color:
23 self.color = color
24
25 class Plot:
26 def __init__( self ):
27 pass
28 # binning, etc
29
30 class SingleHisto:
31 def __init__( self, name, histo, label=False ):
32 self.histo = histo
33 self.label = label
34 self.name = name
35
36
37 class Multihisto:
38 def __init__( self ):
39 self.histos = []
40 self.stack = []
41 self.drawRatio = True
42 self.leg = myLegend(.7,.7,.95,.92)
43
44 def addHisto( self, singleHisto, label=None, toStack=False ):
45 if toStack:
46 self.stack.append( singleHisto )
47 else:
48 self.histos.append( singleHisto )
49 self.leg.AddEntry( singleHisto, label, "l" )
50
51 def stackHistos( self ):
52 if self.stack:
53 stack = ROOT.THStack()
54 for h in self.stack:
55 stack.Add( h )
56 #self.histo.append( stack )
57
58 def GetMinimum( self ):
59 mini = 100000
60 for hist in self.histos:
61 if hist.GetMinimum() < mini:
62 mini = hist.GetMinimum(0)
63 if ROOT.gROOT.GetStyle("tdrStyle").GetOptLogy():
64 return 1
65 else:
66 return mini
67
68 def GetMaximum( self ):
69 maxi = -100000
70 for hist in self.histos:
71 if hist.GetMaximum() > maxi:
72 maxi = hist.GetMaximum()
73 if ROOT.gROOT.GetStyle("tdrStyle").GetOptLogy():
74 return maxi*5
75 else:
76 return maxi*1.2
77
78 def Draw( self, option ):
79 self.stackHistos()
80
81 if self.histos:
82 self.histos[0].SetMaximum( self.GetMaximum() )
83 self.histos[0].SetMinimum( self.GetMinimum() )
84
85 self.histos[0].Draw( option )
86 for hist in self.histos[1:]:
87 hist.Draw("same %s"%option)
88 else:
89 print "No histogram added"
90
91 if self.leg.GetListOfPrimitives().GetSize():
92 self.leg.Draw()