Skip to content

Commit

Permalink
update example making it use stackplots and create Petroff colors obj…
Browse files Browse the repository at this point in the history
…ects (#40)

* update example making it use stackplots

* fix

* fix

* add handles to easily use Petroff colors

* fix ratio plot
  • Loading branch information
ttedeschi authored Apr 17, 2024
1 parent 67584d6 commit b513641
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 11 deletions.
30 changes: 30 additions & 0 deletions src/cmsstyle/cmsstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ def AppendAdditionalInfo(text):
petroff_8 = ["#1845fb", "#ff5e02", "#c91f16", "#c849a9", "#adad7d", "#86c8dd", "#578dff", "#656364"]
petroff_10 = ["#3f90da", "#ffa90e", "#bd1f01", "#94a4a2", "#832db6", "#a96b59", "#e76300", "#b9ac70", "#717581", "#92dadd"]

class p6:
kBlue = rt.TColor.GetColor("#5790fc")
kYellow = rt.TColor.GetColor("#f89c20")
kRed = rt.TColor.GetColor("#e42536")
kGrape = rt.TColor.GetColor("#964a8b")
kGray = rt.TColor.GetColor("#9c9ca1")
kViolet = rt.TColor.GetColor("#7a21dd")

class p8:
kBlue = rt.TColor.GetColor("#1845fb")
kOrange = rt.TColor.GetColor("#ff5e02")
kRed = rt.TColor.GetColor("#c91f16")
kPink = rt.TColor.GetColor("#c849a9")
kGreen = rt.TColor.GetColor("#adad7d")
kCyan = rt.TColor.GetColor("#86c8dd")
kAzure = rt.TColor.GetColor("#578dff")
kGray = rt.TColor.GetColor("#656364")

class p10:
kBlue = rt.TColor.GetColor("#3f90da")
kYellow = rt.TColor.GetColor("#ffa90e")
kRed = rt.TColor.GetColor("#bd1f01")
kGray = rt.TColor.GetColor("#94a4a2")
kViolet = rt.TColor.GetColor("#832db6")
kBrown = rt.TColor.GetColor("#a96b59")
kOrange = rt.TColor.GetColor("#e76300")
kGreen = rt.TColor.GetColor("#b9ac70")
kAsh = rt.TColor.GetColor("#717581")
kCyan = rt.TColor.GetColor("#92dadd")

# Define an alternative color palette and a function to set it
MyPalette = None

Expand Down
17 changes: 6 additions & 11 deletions tests/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ def Plot(self, square, iPos):
leg = CMS.cmsLeg(0.60, 0.89 - 0.04 * 4, 0.89, 0.89, textSize=0.04)

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

leg.AddEntry(self.data, "Data", "lp")
leg.AddEntry(self.bkg, "Background", "f")
leg.AddEntry(self.signal, "Signal", "f")

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

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

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

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

CMS.fixOverlay()

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

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


def main():
plotter = Plotter()
plotter.Plot(square=CMS.kSquare, iPos=0)
Expand Down
Binary file modified tests/pdfs/example_2D_rectangle_pos0.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_2D_square_pos0.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_rectangle_pos0.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_rectangle_pos0_ratio.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_rectangle_pos11.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_rectangle_pos11_ratio.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_square_pos0.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_square_pos0_ratio.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_square_pos11.pdf
Binary file not shown.
Binary file modified tests/pdfs/example_square_pos11_ratio.pdf
Binary file not shown.

0 comments on commit b513641

Please sign in to comment.