Skip to content

Commit

Permalink
Merge pull request #22 from KIT-CMS/black
Browse files Browse the repository at this point in the history
add black CI check
  • Loading branch information
a-monsch authored Apr 12, 2024
2 parents 6ee7abf + bdd5d6c commit 485d75e
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 188 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Black Code Formatter

on: [push, pull_request]

jobs:
black:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install Black
run: pip install black==23.3.0

- name: Run Black
run: black --check .
9 changes: 8 additions & 1 deletion Dumbledraw/dumbledraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@ def DrawChannelCategoryLabel(
begin_left = 0.145
latex2.DrawLatex(begin_left, 0.960, text)

def DrawCMS(self, position=0, preliminary=True, subtext="", own_work=False, thesisstyle=False):
def DrawCMS(
self,
position=0,
preliminary=True,
subtext="",
own_work=False,
thesisstyle=False,
):
additional_string = ""
if subtext != "":
additional_string = subtext
Expand Down
1 change: 0 additions & 1 deletion Dumbledraw/rootfile_parser_inputshapes_wh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class Rootfile_parser(object):

_dataset_map = {
"data": "data",
"ggZZ": "ggZZ",
Expand Down
1 change: 0 additions & 1 deletion Dumbledraw/rootfile_parser_ntuple_processor_inputshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class Rootfile_parser(object):

_dataset_map = {
"data": "data",
"ZTT": "DY",
Expand Down
44 changes: 25 additions & 19 deletions Dumbledraw/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def CreateTransparentColor(color, alpha):
return new_idx



legend_label_dict = yaml.load(open(labels_path))["legend_label"]
x_label_dict = yaml.load(open(labels_path))["x_label"]

Expand All @@ -44,14 +43,14 @@ def CreateTransparentColor(color, alpha):
"WH": R.TColor.GetColor("#001EFF"),
"ZH": R.TColor.GetColor("#001EFF"),
"ttH": R.TColor.GetColor("#FF00FF"),
# "HWW": R.TColor.GetColor("#FF8C00"),
# "ggH_hww": R.TColor.GetColor("#FF8C00"),
# "qqH_hww": R.TColor.GetColor("#FF8C00"),
# "HWW": R.TColor.GetColor("#FF8C00"),
# "ggH_hww": R.TColor.GetColor("#FF8C00"),
# "qqH_hww": R.TColor.GetColor("#FF8C00"),
"HWW": R.TColor.GetColor("#006106"),
"ggH_hww": R.TColor.GetColor("#006106"),
"qqH_hww": R.TColor.GetColor("#006106"),
"dummy": R.TColor.GetColor(254, 74, 73),
# "inclusive": R.TColor.GetColor(254, 74, 73),
# "inclusive": R.TColor.GetColor(254, 74, 73),
"ZTT": R.TColor.GetColor(248, 206, 104),
"ZTT_NLO": R.TColor.GetColor(248, 206, 104),
"EMB": R.TColor.GetColor(248, 206, 104),
Expand Down Expand Up @@ -390,18 +389,21 @@ def DrawText(pad, text, scale_text_size, pos, angle, custom_pos=None):
latex.SetTextSize(0.04 * scale_text_size)
latex.DrawLatex(x_pos, y_pos, text)

def DrawCMSLogo(pad,
cmsText,
extraText,
iPosX,
relPosX,
relPosY,
relExtraDY,
extraText2='',
extraOverCmsTextSize=0.76,
extraTextFont=52,
cmsTextSize=0.8,
thesisstyle=False):

def DrawCMSLogo(
pad,
cmsText,
extraText,
iPosX,
relPosX,
relPosY,
relExtraDY,
extraText2="",
extraOverCmsTextSize=0.76,
extraTextFont=52,
cmsTextSize=0.8,
thesisstyle=False,
):
"""Blah
Args:
Expand Down Expand Up @@ -495,9 +497,13 @@ def DrawCMSLogo(pad,
latex.SetTextAlign(align_)
latex.SetTextSize(extraTextSize * t * pad_ratio)
if pad_ratio_raw > 0.8:
latex.DrawLatex(l + (relPosX + 0.081) * (1 - l - r), posY_ - 0.007 , "data")
latex.DrawLatex(
l + (relPosX + 0.081) * (1 - l - r), posY_ - 0.007, "data"
)
if pad_ratio_raw < 0.8:
latex.DrawLatex(l + (relPosX + 0.065) * (1 - l - r), posY_ - 0.007 , "data")
latex.DrawLatex(
l + (relPosX + 0.065) * (1 - l - r), posY_ - 0.007, "data"
)
else:
latex.SetTextFont(cmsTextFont)
latex.SetTextSize(cmsTextSize * t * pad_ratio)
Expand Down
75 changes: 36 additions & 39 deletions example_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from copy import deepcopy

import logging

logger = logging.getLogger("")


Expand All @@ -31,8 +32,7 @@ def main():
# create canvas:
# First argument defines subplot structure: List of splits from top to bottom (max. 1.0 to min. 0.0). A split can be a single position or a pair resulting in gap.
# Further arguments set general style.
plot = dd.Plot(
[0.65, [0.47, 0.45], [0.22, 0.20]], "ModTDR", r=0.04, l=0.14)
plot = dd.Plot([0.65, [0.47, 0.45], [0.22, 0.20]], "ModTDR", r=0.04, l=0.14)

bkg_processes = ["EWK", "QCD", "VV", "W", "TTT", "TTJ", "ZJ", "ZL", "ZTT"]

Expand All @@ -41,33 +41,29 @@ def main():
plot.add_hist(
rootfile.get("mt", "qqh", process), process, "bkg"
) # get(channel, category, process) and assign specific name and group name to histogram. The group name is optional.
plot.setGraphStyle(
process, "hist", fillcolor=styles.color_dict[process])
plot.setGraphStyle(process, "hist", fillcolor=styles.color_dict[process])
for i in range(2):
plot.subplot(i + 1).add_hist(
rootfile.get("mt", "qqh", "ggH"), "ggH"
) # signal histograms are used twice in order to realize a two color line style
plot.subplot(i + 1).add_hist(
rootfile.get("mt", "qqh", "ggH"), "ggH_top")
plot.subplot(i + 1).add_hist(rootfile.get("mt", "qqh", "ggH"), "ggH_top")
plot.subplot(i + 1).add_hist(rootfile.get("mt", "qqh", "qqH"), "qqH")
plot.subplot(i + 1).add_hist(
rootfile.get("mt", "qqh", "qqH"), "qqH_top")
plot.subplot(i + 1).add_hist(rootfile.get("mt", "qqh", "qqH"), "qqH_top")
plot.add_hist(rootfile.get("mt", "qqh", "data_obs"), "data_obs")
plot.add_hist(rootfile.get("mt", "qqh", "TotalBkg"), "unc_band")

# set some graph styles
plot.subplot(1).setGraphStyle(
"ggH", "hist", linecolor=styles.color_dict["ggH"], linewidth=3)
"ggH", "hist", linecolor=styles.color_dict["ggH"], linewidth=3
)
plot.subplot(1).setGraphStyle("ggH_top", "hist", linecolor=0)
plot.subplot(1).setGraphStyle(
"qqH", "hist", linecolor=styles.color_dict["qqH"], linewidth=3)
"qqH", "hist", linecolor=styles.color_dict["qqH"], linewidth=3
)
plot.subplot(1).setGraphStyle("qqH_top", "hist", linecolor=0)
plot.setGraphStyle(
"unc_band",
"e2",
markersize=0,
fillcolor=styles.color_dict["unc"],
linecolor=0)
"unc_band", "e2", markersize=0, fillcolor=styles.color_dict["unc"], linecolor=0
)

# in order to show S+B in the ratio plot, add total background to signal hists (get_hist returns a copy) and register the results
bkg_ggH = plot.subplot(2).get_hist("ggH")
Expand All @@ -79,20 +75,22 @@ def main():
plot.subplot(2).add_hist(bkg_qqH, "bkg_qqH")
plot.subplot(2).add_hist(bkg_qqH, "bkg_qqH_top")
plot.subplot(2).setGraphStyle(
"bkg_ggH", "hist", linecolor=styles.color_dict["ggH"], linewidth=3)
"bkg_ggH", "hist", linecolor=styles.color_dict["ggH"], linewidth=3
)
plot.subplot(2).setGraphStyle("bkg_ggH_top", "hist", linecolor=0)
plot.subplot(2).setGraphStyle(
"bkg_qqH", "hist", linecolor=styles.color_dict["qqH"], linewidth=3)
"bkg_qqH", "hist", linecolor=styles.color_dict["qqH"], linewidth=3
)
plot.subplot(2).setGraphStyle("bkg_qqH_top", "hist", linecolor=0)

# apply normalizations for the ratio and the background fractions plot:
# First argument: Name of a single histogram or list of names / group names that shall be normalized
# Second argument: Name of a single histogram or list of names / group names that shall be contained in the denominator
plot.subplot(2).normalize([
"unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top",
"data_obs"
], "unc_band")
#plot.subplot(2).normalize(["unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top", "data_obs"], "bkg") # would also work but add up the single bkg histograms in the background
plot.subplot(2).normalize(
["unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top", "data_obs"],
"unc_band",
)
# plot.subplot(2).normalize(["unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top", "data_obs"], "bkg") # would also work but add up the single bkg histograms in the background
plot.subplot(3).normalize("bkg", "bkg")

# stack background histograms for all subplots and assign a name
Expand All @@ -106,8 +104,7 @@ def main():
plot.subplot(1).setLogY()
plot.subplot(3).setXlabel("NN score")
plot.subplot(0).setYlabel("N_{events}")
plot.subplot(1).setYlabel(
"") # otherwise number labels are not drawn on axis
plot.subplot(1).setYlabel("") # otherwise number labels are not drawn on axis
plot.subplot(2).setYlabel("ratio to bkg")
plot.subplot(3).setYlabel("bkg frac.")

Expand All @@ -123,11 +120,11 @@ def main():
# draw subplots. Argument contains names of objects to be drawn in corresponding order.
plot.subplot(0).Draw(["stack", "unc_band", "data_obs"])
plot.subplot(1).Draw(
["stack", "unc_band", "ggH", "ggH_top", "qqH", "qqH_top", "data_obs"])
plot.subplot(2).Draw([
"unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top",
"data_obs"
])
["stack", "unc_band", "ggH", "ggH_top", "qqH", "qqH_top", "data_obs"]
)
plot.subplot(2).Draw(
["unc_band", "bkg_ggH", "bkg_ggH_top", "bkg_qqH", "bkg_qqH_top", "data_obs"]
)
plot.subplot(3).Draw("stack")

# create legends
Expand All @@ -136,23 +133,23 @@ def main():
for i in range(2):
plot.add_legend(width=0.48, height=0.15)
for process in bkg_processes:
plot.legend(i).add_entry(0, process,
styles.label_dict[process.replace(
"EWK", "EWKZ")], 'f')
plot.legend(i).add_entry(0, "unc_band", "Bkg. unc.", 'f')
plot.legend(i).add_entry(1, "ggH%s" % suffix[i], "ggH", 'l')
plot.legend(i).add_entry(1, "qqH%s" % suffix[i], "qqH", 'l')
plot.legend(i).add_entry(0, "data_obs", "Data", 'PE')
plot.legend(i).add_entry(
0, process, styles.label_dict[process.replace("EWK", "EWKZ")], "f"
)
plot.legend(i).add_entry(0, "unc_band", "Bkg. unc.", "f")
plot.legend(i).add_entry(1, "ggH%s" % suffix[i], "ggH", "l")
plot.legend(i).add_entry(1, "qqH%s" % suffix[i], "qqH", "l")
plot.legend(i).add_entry(0, "data_obs", "Data", "PE")
plot.legend(i).setNColumns(3)
plot.legend(0).Draw()
plot.legend(1).setAlpha(0.0)
plot.legend(1).Draw()

for i in range(2):
plot.add_legend(reference_subplot=2, pos=1, width=0.4, height=0.03)
plot.legend(i + 2).add_entry(0, "data_obs", "Data", 'PE')
plot.legend(i + 2).add_entry(1, "ggH%s" % suffix[i], "ggH+bkg.", 'l')
plot.legend(i + 2).add_entry(1, "qqH%s" % suffix[i], "qqH+bkg.", 'l')
plot.legend(i + 2).add_entry(0, "data_obs", "Data", "PE")
plot.legend(i + 2).add_entry(1, "ggH%s" % suffix[i], "ggH+bkg.", "l")
plot.legend(i + 2).add_entry(1, "qqH%s" % suffix[i], "qqH+bkg.", "l")
plot.legend(i + 2).setNColumns(3)
plot.legend(2).Draw()
plot.legend(3).setAlpha(0.0)
Expand Down
Loading

0 comments on commit 485d75e

Please sign in to comment.