Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: correctionlib(jsonpog-integration) implementation & fixes on actions #50

Merged
merged 13 commits into from
Mar 15, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ctag_DY_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9","3.10"]
demuller marked this conversation as resolved.
Show resolved Hide resolved

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ctag_Wc_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9","3.10"]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ttbar_SL_DL_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9","3.10"]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ttbar_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9","3.10"]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [ "3.10", "3.8","3.9"]
python-version: ["3.9","3.10"]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ e.g. python -m BTVNanoCommissioning.utils.compile_jec Winter22Run3 jec_compiled

You can specify `-v all` to plot all the variables in the `coffea` file, or use wildcard options (e.g. `-v "*DeepJet*"` for the input variables containing `DeepJet`)

:new: non-uniform rebinning is possible, specify the bins with list of edges `--rebin 50,80,81,82,83,100.5`
:new: non-uniform rebinning is possible, specify the bins with list of edges `--autorebin 50,80,81,82,83,100.5`

```
python plotdataMC.py -i a.coffea,b.coffea --lumi 41500 -p dilep_sf -v z_mass,z_pt
Expand Down
71 changes: 54 additions & 17 deletions plotting/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
"--phase",
required=True,
choices=[
"dilep_sf",
"ttdilep_sf",
"ttsemilep_sf",
"ctag_Wc_sf",
"ctag_DY_sf",
"ctag_ttsemilep_sf",
"ctag_ttdilep_sf",
"ectag_Wc_sf",
"ectag_DY_sf",
"ectag_ttsemilep_sf",
"ectag_ttdilep_sf",
"emctag_ttdilep_sf",
],
dest="phase",
help="which phase space",
Expand Down Expand Up @@ -93,6 +98,15 @@
type=str,
help="rename the label of variables to plot, splitted by ,. Wildcard option * NOT available here",
)
parser.add_argument(
"--ylabel", type=str, default=None, help="Modify y-axis label of plot"
)
parser.add_argument(
"--splitOSSS",
type=int,
default=None,
help="Only for W+c phase space, split opposite sign(1) and same sign events(-1), if not specified, the combined OS-SS phase space is used",
)
args = parser.parse_args()
output = {}
if len(args.input.split(",")) > 1:
Expand Down Expand Up @@ -130,8 +144,15 @@
hist_type = "step"
label = "Simulation Preliminary"
nj = 1
if "Wc" in argparse.phase:
### input text settings
if "Wc" in args.phase:
input_txt = "W+c"
if args.splitOSSS == 1:
input_txt = input_txt + " OS"
elif args.splitOSSS == -1:
input_txt = input_txt + " SS"
else:
input_txt = input_txt + " OS-SS"
elif "DY" in args.phase:
input_txt = "DY+jets"
elif "semilep" in args.phase:
Expand Down Expand Up @@ -173,19 +194,27 @@
if "syst" in collated[args.ref][discr].axes.name:
allaxis["syst"] = sum
if "osss" in collated[args.ref][discr].axes.name: ## do dominal OS-SS
collated[args.ref][discr] = (
collated[args.ref][discr][{"osss": 0}]
+ collated[args.ref][discr][{"osss": 1}] * -1
)
for c in args.compared.split(","):
collated[c][discr] = (
collated[c][discr][{"osss": 0}] + collated[c][discr][{"osss": 1}] * -1
if args.splitOSSS is None: # OS-SS
collated[args.ref][discr] = (
collated[args.ref][discr][{"osss": 0}]
+ collated[args.ref][discr][{"osss": 1}] * -1
)
for c in args.compared.split(","):
collated[c][discr] = (
collated[c][discr][{"osss": 0}]
+ collated[c][discr][{"osss": 1}] * -1
)
elif args.splitOSSS == 1:
allaxis["osss"] = 0 # opposite sign
elif args.splitOSSS == -1:
allaxis["osss"] = 1 # same sign
do_xerr = False
if args.autorebin is not None:
if args.autorebin.isdigit():
rebin = int(args.autorebin)
else:
rebin = np.array([float(i) for i in args.autorebin.split(",")])
do_xerr = True
collated["mc"][discr] = rebin_hist(
collated["mc"][discr], collated["mc"][discr].axes[-1].name, rebin
)
Expand Down Expand Up @@ -251,7 +280,8 @@
histtype=hist_type,
yerr=True,
ax=ax,
# #flow=args.flow,
xerr=do_xerr
# flow=args.flow,
)
hep.histplot(
collated[args.ref][discr][caxis],
Expand All @@ -260,6 +290,7 @@
histtype=hist_type,
yerr=True,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
hep.histplot(
Expand All @@ -269,6 +300,7 @@
color="r",
histtype=hist_type,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)

Expand All @@ -283,6 +315,7 @@
histtype="errorbar",
yerr=True,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
hep.histplot(
Expand All @@ -293,6 +326,7 @@
histtype="errorbar",
yerr=True,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
hep.histplot(
Expand All @@ -303,6 +337,7 @@
marker=markers[mindex + 1],
histtype="errorbar",
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
# comparison splitted by flavor
Expand All @@ -313,6 +348,7 @@
denom_fill_opts=None,
error_opts={"color": "b", "marker": markers[mindex + 1]},
clear=False,
xerr=do_xerr
# flow=args.flow,
)
rax2 = plotratio(
Expand All @@ -322,6 +358,7 @@
denom_fill_opts=None,
error_opts={"color": "g", "marker": markers[mindex + 1]},
clear=False,
xerr=do_xerr
# flow=args.flow,
)
rax3 = plotratio(
Expand All @@ -331,6 +368,7 @@
denom_fill_opts=None,
error_opts={"color": "r", "marker": markers[mindex + 1]},
clear=False,
xerr=do_xerr
# flow=args.flow,
)
mindex += 1
Expand All @@ -347,9 +385,7 @@
rax3.set_xlabel(xlabel)
ax.legend()

at = AnchoredText(
input_txt + "\n" + "BTV Commissioning" + "\n" + text, loc=2, frameon=False
)
at = AnchoredText(input_txt + "\n" + text, loc=2, frameon=False)
ax.add_artist(at)
hep.mpl_magic(ax=ax)
if args.log:
Expand All @@ -374,6 +410,7 @@
histtype=hist_type,
yerr=True,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
for c, s in zip(args.compared.split(","), args.shortcomp.split(",")):
Expand All @@ -383,6 +420,7 @@
histtype=hist_type,
yerr=True,
ax=ax,
xerr=do_xerr
# flow=args.flow,
)
for i, c in enumerate(args.compared.split(",")):
Expand All @@ -393,6 +431,7 @@
denom_fill_opts=None,
error_opts={"color": ax.get_lines()[i + 1].get_color()},
clear=False,
xerr=do_xerr
# flow=args.flow,
) ## No error band used
alls = collated[args.ref][discr][allaxis]
Expand All @@ -406,14 +445,12 @@
)
rax.set_xlabel(xlabel)
ax.set_xlabel(None)
ax.set_ylabel("Events")
ax.set_ylabel(args.ylabel)
rax.set_ylabel("Other/Ref")
ax.legend(loc=1)
rax.set_ylim(0.0, 2.0)

at = AnchoredText(
input_txt + "\n" + "BTV Commissioning" + "\n" + text, loc=2, frameon=False
)
at = AnchoredText(input_txt + "\n" + args.ext, loc=2, frameon=False)
ax.add_artist(at)
hep.mpl_magic(ax=ax)
ax.set_ylim(bottom=0)
Expand Down
22 changes: 10 additions & 12 deletions plotting/plotdataMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
type=str,
help="rename the label of variables to plot, splitted by ,. Wildcard option * NOT available here",
)

parser.add_argument(
"--ylabel", type=str, default=None, help="Modify y-axis label of plot"
)
parser.add_argument(
"--SF", action="store_true", default=False, help="make w/, w/o SF comparisons"
)
Expand All @@ -86,16 +88,12 @@
default=None,
help="str, optional {None, 'show', 'sum'} Whether plot the under/overflow bin. If 'show', add additional under/overflow bin. If 'sum', add the under/overflow bin content to first/last bin.",
)

parser.add_argument(
"--splitOSSS",
type=int,
default=None,
help="Only for W+c phase space, split opposite sign(1) and same sign events(-1), if not specified, the combined OS-SS phase space is used",
)
parser.add_argument(
"--ylabel", type=str, default=None, help="Modify y-axis label of plot"
)


arg = parser.parse_args()
Expand Down Expand Up @@ -123,8 +121,15 @@
mergemap["mc"] = mclist
mergemap["data"] = datalist
collated = collate(output, mergemap)
### input text settings
if "Wc" in arg.phase:
input_txt = "W+c"
if arg.splitOSSS == 1:
input_txt = input_txt + " OS"
elif arg.splitOSSS == -1:
input_txt = input_txt + " SS"
else:
input_txt = input_txt + " OS-SS"
elif "DY" in arg.phase:
input_txt = "DY+jets"
elif "semilep" in arg.phase:
Expand All @@ -139,13 +144,6 @@
or "mu" in arg.variable.split(",")
):
nj = 1
if "Wc" in arg.phase:
if arg.splitOSSS == 1:
input_txt = input_txt + " OS"
elif arg.splitOSSS == -1:
input_txt = input_txt + " SS"
else:
input_txt = input_txt + " OS-SS"
if "emctag" in arg.phase:
input_txt = input_txt + " (e$\mu$)"
elif "ectag" in arg.phase:
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Ming-Yan marked this conversation as resolved.
Show resolved Hide resolved
Topic :: Scientific/Engineering
Expand Down
9 changes: 7 additions & 2 deletions src/BTVNanoCommissioning/workflows/ctag_dileptt_valid_sf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def process(self, events):
events = missing_branch(events)

if self.isJERC:
add_jec(events, self._campaign, self._jet_factory)
events = add_jec(events, self._campaign, self._jet_factory)
if isRealData:
output["sumw"] = len(events)
else:
Expand Down Expand Up @@ -97,7 +97,12 @@ def process(self, events):
req_muon = (ak.count(iso_muon.pt, axis=1) == 2) & (iso_muon[:, 0].pt > 20)

## Jet cuts
event_jet = events.Jet[jet_id(events, self._campaign)]
event_jet = events.Jet[
jet_id(events, self._campaign)
& ak.all(
events.Jet.metric_table(iso_muon) > 0.4, axis=2, mask_identity=True
)
]
req_jets = ak.count(event_jet.pt, axis=1) >= 2

## Soft Muon cuts
Expand Down