-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotstyle.py
More file actions
147 lines (101 loc) · 4.41 KB
/
Copy pathplotstyle.py
File metadata and controls
147 lines (101 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from ROOT import gROOT, gPad, TPad, TGaxis
import CMS_lumi
import tdrstyle
gROOT.SetBatch() # don't pop up canvases
class Plotstyle:
def __init__(self, text="13 TeV", extratext="Preliminary", cmstext="CMS", H_ref=600, W_ref=800, iPos=11):
# self.text = "13 TeV"
# self.extratext = "Preliminary"
# self.H_ref = 600
# self.W_ref = 800
self.text = text
self.extratext = extratext
self.cmstext = cmstext
self.H_ref = H_ref
self.W_ref = W_ref
self.iPos = iPos
if( self.iPos==0 ): CMS_lumi.relPosX = 0.12
self.iPeriod = 0
self.W = self.W_ref
self.H = self.H_ref
self.T = 0.08*self.H_ref
self.B = 0.12*self.H_ref
self.L = 0.12*self.W_ref
self.R = 0.04*self.W_ref
self.lowerPadFraction = 0.3
def setStyle(self):
mystyle = tdrstyle.setTDRStyle()
TGaxis.SetMaxDigits(4)
#change the CMS_lumi variables (see CMS_lumi.py)
CMS_lumi.lumi_7TeV = "4.8 fb^{-1}"
CMS_lumi.lumi_8TeV = "18.3 fb^{-1}"
CMS_lumi.writeExtraText = 1
CMS_lumi.extraText = self.extratext
CMS_lumi.cmsText = self.cmstext
CMS_lumi.lumi_sqrtS = self.text # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)
return mystyle
def preparePad(self):
gPad.SetFillColor(0)
gPad.SetBorderMode(0)
gPad.SetFrameFillStyle(0)
gPad.SetFrameBorderMode(0)
# gPad.SetFrameLineWidth(1)
gPad.SetLeftMargin( self.L/self.W )
gPad.SetRightMargin( self.R/self.W )
gPad.SetTopMargin( self.T/self.H )
gPad.SetBottomMargin( 1.1 * self.B/self.H )
gPad.SetTickx(1)
gPad.SetTicky(1)
def postparePad(self):
CMS_lumi.CMS_lumi(gPad, self.iPeriod, self.iPos)
gPad.cd()
gPad.Update()
gPad.RedrawAxis()
frame = gPad.GetFrame()
frame.Draw()
def addLowerPads(self, canvas):
# adjusted from https://root.cern/doc/master/ratioplot_8py.html
subpads = {}
for ipad, pad in enumerate(list(canvas.GetListOfPrimitives())):
ipad += 1
pad.cd()
subpads[str(ipad) + '_1'] = TPad(pad.GetName() + '_1', pad.GetName() + '_1', 0., self.lowerPadFraction, 1., 1.0)
subpads[str(ipad) + '_1'].SetFillColor(0)
subpads[str(ipad) + '_1'].SetBorderMode(0)
subpads[str(ipad) + '_1'].SetFrameFillStyle(0)
subpads[str(ipad) + '_1'].SetFrameBorderMode(0)
subpads[str(ipad) + '_1'].SetFrameLineWidth(1)
subpads[str(ipad) + '_1'].SetLeftMargin( self.L/self.W )
subpads[str(ipad) + '_1'].SetRightMargin( self.R/self.W )
subpads[str(ipad) + '_1'].SetTopMargin( self.T/self.H )
subpads[str(ipad) + '_1'].SetBottomMargin(0.02)
subpads[str(ipad) + '_1'].SetTickx(1)
subpads[str(ipad) + '_1'].SetTicky(1)
subpads[str(ipad) + '_1'].Draw()
pad.cd()
subpads[str(ipad) + '_2'] = TPad(pad.GetName() + '_2', pad.GetName() + '_2', 0., 0., 1., self.lowerPadFraction)
subpads[str(ipad) + '_2'].SetFillColor(0)
subpads[str(ipad) + '_2'].SetBorderMode(0)
subpads[str(ipad) + '_2'].SetFrameFillStyle(0)
subpads[str(ipad) + '_2'].SetFrameBorderMode(0)
subpads[str(ipad) + '_2'].SetFrameLineWidth(1)
subpads[str(ipad) + '_2'].SetLeftMargin( self.L/self.W )
subpads[str(ipad) + '_2'].SetRightMargin( self.R/self.W )
subpads[str(ipad) + '_2'].SetTopMargin(0)
# subpads[str(ipad) + '_2'].SetBottomMargin( self.B/self.H )
subpads[str(ipad) + '_2'].SetBottomMargin( 0.3 )
subpads[str(ipad) + '_2'].SetTickx(1)
subpads[str(ipad) + '_2'].SetTicky(1)
subpads[str(ipad) + '_2'].Draw()
return subpads
def adjustLowerHisto(self, h):
factor = (1 - self.lowerPadFraction) / self.lowerPadFraction
x = h.GetXaxis()
x.SetLabelSize(factor * 0.05)
x.SetTitleSize(factor * 0.06)
y = h.GetYaxis()
y.SetLabelSize(factor * 0.05)
y.SetTitleSize(factor * 0.06)
y.SetTitleOffset(0.9 / factor)
y.CenterTitle()
y.SetNdivisions(505)