Skip to content

Commit b513641

Browse files
authored
update example making it use stackplots and create Petroff colors objects (#40)
* update example making it use stackplots * fix * fix * add handles to easily use Petroff colors * fix ratio plot
1 parent 67584d6 commit b513641

12 files changed

+36
-11
lines changed

src/cmsstyle/cmsstyle.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,36 @@ def AppendAdditionalInfo(text):
6868
petroff_8 = ["#1845fb", "#ff5e02", "#c91f16", "#c849a9", "#adad7d", "#86c8dd", "#578dff", "#656364"]
6969
petroff_10 = ["#3f90da", "#ffa90e", "#bd1f01", "#94a4a2", "#832db6", "#a96b59", "#e76300", "#b9ac70", "#717581", "#92dadd"]
7070

71+
class p6:
72+
kBlue = rt.TColor.GetColor("#5790fc")
73+
kYellow = rt.TColor.GetColor("#f89c20")
74+
kRed = rt.TColor.GetColor("#e42536")
75+
kGrape = rt.TColor.GetColor("#964a8b")
76+
kGray = rt.TColor.GetColor("#9c9ca1")
77+
kViolet = rt.TColor.GetColor("#7a21dd")
78+
79+
class p8:
80+
kBlue = rt.TColor.GetColor("#1845fb")
81+
kOrange = rt.TColor.GetColor("#ff5e02")
82+
kRed = rt.TColor.GetColor("#c91f16")
83+
kPink = rt.TColor.GetColor("#c849a9")
84+
kGreen = rt.TColor.GetColor("#adad7d")
85+
kCyan = rt.TColor.GetColor("#86c8dd")
86+
kAzure = rt.TColor.GetColor("#578dff")
87+
kGray = rt.TColor.GetColor("#656364")
88+
89+
class p10:
90+
kBlue = rt.TColor.GetColor("#3f90da")
91+
kYellow = rt.TColor.GetColor("#ffa90e")
92+
kRed = rt.TColor.GetColor("#bd1f01")
93+
kGray = rt.TColor.GetColor("#94a4a2")
94+
kViolet = rt.TColor.GetColor("#832db6")
95+
kBrown = rt.TColor.GetColor("#a96b59")
96+
kOrange = rt.TColor.GetColor("#e76300")
97+
kGreen = rt.TColor.GetColor("#b9ac70")
98+
kAsh = rt.TColor.GetColor("#717581")
99+
kCyan = rt.TColor.GetColor("#92dadd")
100+
71101
# Define an alternative color palette and a function to set it
72102
MyPalette = None
73103

tests/example.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ def Plot(self, square, iPos):
6767
leg = CMS.cmsLeg(0.60, 0.89 - 0.04 * 4, 0.89, 0.89, textSize=0.04)
6868

6969
# Draw objects in one line
70-
CMS.cmsDraw(self.bkg, "hist", fcolor=ROOT.kAzure + 2, alpha=0.5)
71-
CMS.cmsDraw(self.signal, "hist", fcolor=ROOT.kRed + 1, alpha=0.5)
70+
stack = ROOT.THStack("stack", "Stacked")
71+
leg.AddEntry(self.data, "Data", "lp")
72+
CMS.cmsDrawStack(stack, leg, {"Background": self.bkg, "Signal": self.signal})
7273
CMS.cmsDraw(self.data, "P", mcolor=ROOT.kBlack)
7374

74-
leg.AddEntry(self.data, "Data", "lp")
75-
leg.AddEntry(self.bkg, "Background", "f")
76-
leg.AddEntry(self.signal, "Signal", "f")
7775

7876
# Takes care of fixing overlay and closing object
7977
CMS.SaveCanvas(canv, os.path.join(self.outputPath, canv_name + ".pdf"))
@@ -98,20 +96,18 @@ def Plot(self, square, iPos):
9896

9997
leg = CMS.cmsLeg(0.60, 0.89 - 0.05 * 5, 0.89, 0.89, textSize=0.05)
10098
leg.AddEntry(self.data, "Data", "lp")
101-
leg.AddEntry(self.bkg, "Background", "f")
102-
leg.AddEntry(self.signal, "Signal", "f")
10399

104100
CMS.cmsHeader(leg, "With title", textSize=0.05)
105101

106-
CMS.cmsDraw(self.bkg_tot, "hist", fcolor=ROOT.kRed + 1, alpha=0.5)
107-
CMS.cmsDraw(self.bkg, "hist", fcolor=ROOT.kAzure + 2, alpha=0.9)
102+
stack = ROOT.THStack("stack", "Stacked")
103+
CMS.cmsDrawStack(stack, leg, {"Background": self.bkg, "Signal": self.signal})
108104
CMS.cmsDraw(self.data, "P", mcolor=ROOT.kBlack)
109105

110106
CMS.fixOverlay()
111107

112108
dicanv.cd(2)
113109
leg_ratio = CMS.cmsLeg(
114-
0.17, 0.97 - 0.05 * 5, 0.35, 0.97, textSize=0.05, columns=2
110+
0.67, 0.97 - 0.05 * 5, 0.85, 0.97, textSize=0.05, columns=2
115111
)
116112
# how alternative way to pass style options
117113
style = {"style": "hist", "lcolor": ROOT.kAzure + 2, "lwidth": 2, "fstyle": 0}
@@ -156,7 +152,6 @@ def Plot2D(self, square, iPos):
156152

157153
CMS.SaveCanvas(canv, os.path.join(self.outputPath, canv_name + ".pdf"))
158154

159-
160155
def main():
161156
plotter = Plotter()
162157
plotter.Plot(square=CMS.kSquare, iPos=0)
24.2 KB
Binary file not shown.
24.2 KB
Binary file not shown.
18.5 KB
Binary file not shown.
22.3 KB
Binary file not shown.
18.5 KB
Binary file not shown.
22.4 KB
Binary file not shown.

tests/pdfs/example_square_pos0.pdf

18.5 KB
Binary file not shown.
22.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)