Skip to content

Commit

Permalink
Merge pull request #63 from danielhundhausen/validation_fixes
Browse files Browse the repository at this point in the history
Add symlink to central cache directory
  • Loading branch information
danielhundhausen authored Feb 26, 2024
2 parents 8b60bcf + d495a14 commit 07ce06d
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.pyc
pyenv/*
**/*.png
**/*.pdf
**/.DS_Store
**/*.parquet
**/*.root
Expand Down
1 change: 1 addition & 0 deletions cache
2 changes: 2 additions & 0 deletions configs/V29/object_performance/electron_matching.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ElectronsMatchingBarrel:
test_objects:
EG:default: "Pt"
tkElectron:NoIso: "Pt"
tkElectron:NoIsoLowPt: "Pt"
tkElectron:Iso: "Pt"
xlabel: "Gen. $p_T$ (GeV)"
ylabel: "Matching Efficiency (Barrel)"
Expand All @@ -40,6 +41,7 @@ ElectronsMatchingEndcap:
test_objects:
EG:default: "Pt"
tkElectron:NoIso: "Pt"
tkElectron:NoIsoLowPt: "Pt"
tkElectron:Iso: "Pt"
xlabel: "Gen. $p_T$ (GeV)"
ylabel: "Matching Efficiency (Endcap)"
Expand Down
2 changes: 2 additions & 0 deletions configs/V29/object_performance/electron_matching_eta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ElectronsMatching_Eta_Pt10to25:
test_objects:
EG:default: "Eta"
tkElectron:NoIso: "Eta"
tkElectron:NoIsoLowPt: "Eta"
tkElectron:Iso: "Eta"
xlabel: "Gen. $\\eta$"
ylabel: "Matching Efficiency ($10 < p_T < 25$ GeV)"
Expand All @@ -41,6 +42,7 @@ ElectronsMatching_Eta_Pt25toInf:
test_objects:
EG:default: "Eta"
tkElectron:NoIso: "Eta"
tkElectron:NoIsoLowPt: "Eta"
tkElectron:Iso: "Eta"
xlabel: "Gen. $\\eta$"
ylabel: "Matching Efficiency ($p_T > 25$ GeV)"
Expand Down
2 changes: 2 additions & 0 deletions configs/V29/object_performance/electron_trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ElectronsTriggerBarrel:
test_objects:
EG:default:barrel: "Pt"
tkElectron:NoIso:barrel: "Pt"
tkElectron:NoIsoLowPt:barrel: "Pt"
tkElectron:Iso:barrel: "Pt"
thresholds: [10, 20, 30, 40]
scalings:
Expand Down Expand Up @@ -44,6 +45,7 @@ ElectronsTriggerEndcap:
test_objects:
EG:default:endcap: "Pt"
tkElectron:NoIso:endcap: "Pt"
tkElectron:NoIsoLowPt:endcap: "Pt"
tkElectron:Iso:endcap: "Pt"
thresholds: [10, 20, 30, 40]
scalings:
Expand Down
8 changes: 4 additions & 4 deletions configs/V29/object_performance/met_ht_mht.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ HT_50perc:
max: 750
step: 20

MHT_50perc:
MHT_90perc:
sample: TT
version: V29
reference_object:
Expand All @@ -71,15 +71,15 @@ MHT_50perc:
thresholds: [70, 150]
scalings:
method: "naive"
threshold: 0.50
threshold: 0.90
xlabel: "Gen. MHT30 (GeV)"
ylabel: "Trigger Efficiency (<threshold> GeV)"
binning:
min: 0
max: 500
step: 20

MHT_90perc:
MHT_50perc:
sample: TT
version: V29
reference_object:
Expand All @@ -98,7 +98,7 @@ MHT_90perc:
thresholds: [70, 150]
scalings:
method: "naive"
threshold: 0.90
threshold: 0.50
xlabel: "Gen. MHT30 (GeV)"
ylabel: "Trigger Efficiency (<threshold> GeV)"
binning:
Expand Down
8 changes: 8 additions & 0 deletions configs/V29/object_performance/tau_trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ TauTriggerEndcap_90perc:
max: 150
step: 6

# ATTENTION: The scalings from this config are in conflict with the 90prec
# configurations above and will be written to a file with the plot name as
# prefix. To use these scalings in the rate plots/table, overwrite the standard
# scalings yaml files in outputs!
TauTriggerBarrel_50perc:
sample: VBFHToTauTau
version: V29
Expand Down Expand Up @@ -82,6 +86,10 @@ TauTriggerBarrel_50perc:
max: 150
step: 6

# ATTENTION: The scalings from this config are in conflict with the 90prec
# configurations above and will be written to a file with the plot name as
# prefix. To use these scalings in the rate plots/table, overwrite the standard
# scalings yaml files in outputs!
TauTriggerEndcap_50perc:
sample: VBFHToTauTau
version: V29
Expand Down
12 changes: 9 additions & 3 deletions configs/V29/objects/electrons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tkElectron:
cuts:
inclusive:
- "abs({eta}) < 2.4"
- "({passeseleid} == 1) | ({pt} < 25)"
- "({passeseleid} == 1)"
NoIsoForIso:
# This id is exclusively used for the
# isoloation wp derivation
Expand All @@ -29,17 +29,23 @@ tkElectron:
inclusive:
- "abs({eta}) < 2.7"
barrel:
- "({passeseleid} == 1) | ({pt} < 25)"
- "({passeseleid} == 1)"
Iso:
label: "TkIsoElectron"
cuts:
inclusive:
- "abs({eta}) < 2.4"
barrel:
- "abs({trkiso}) < 0.13"
- "({passeseleid} == 1) | ({pt} < 25)"
- "({passeseleid} == 1)"
endcap:
- "abs({trkiso}) < 0.28"
NoIsoLowPt:
label: "TkElectron, no ID for $p_T<25$"
cuts:
inclusive:
- "abs({eta}) < 2.4"
- "({passeseleid} == 1) | ({pt} < 25)"

EG:
match_dR: 0.2
Expand Down
24 changes: 19 additions & 5 deletions menu_tools/object_performance/plotter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
import json
import os
import yaml
from typing import Any
import warnings
import yaml

import matplotlib.pyplot as plt
import mplhep as hep
Expand Down Expand Up @@ -155,7 +156,7 @@ def _plot_efficiency_curve(self):
)

err_kwargs = {
"xerr": self.turnon_collection.xerr(obj_key),
# "xerr": self.turnon_collection.xerr(obj_key),
"capsize": 3,
"marker": "o",
"markersize": 8,
Expand Down Expand Up @@ -443,7 +444,9 @@ def _get_scaling_thresholds(self, cfg_plot, test_obj) -> list[int]:
return self.scaling_thresholds["Jet"]
raise RuntimeError("Failed to find thresholds in cfg_scaling_thresholds!")

def _write_scalings_to_file(self, obj: Object, params: np.ndarray) -> None:
def _write_scalings_to_file(
self, obj: Object, params: np.ndarray, plot_name: str
) -> None:
"""Dumps the scaling parameters to a file.
Writes the offset and slope params of the linear scaling function to
Expand All @@ -460,7 +463,18 @@ def _write_scalings_to_file(self, obj: Object, params: np.ndarray) -> None:
)
os.makedirs(fpath, exist_ok=True)
a, b = params
with open(os.path.join(fpath, str(obj) + ".yaml"), "w") as f:

out_path = os.path.join(fpath, str(obj) + ".yaml")
if os.path.exists(out_path):
warnings.warn(
(
f"A file already exists at the scaling destination `{out_path}`."
f"Will dump the scalings with `{plot_name}` prefix."
),
UserWarning,
)
out_path = out_path.replace(str(obj), plot_name + "_" + str(obj))
with open(out_path, "w") as f:
yaml.dump({"slope": float(a), "offset": float(b)}, f)

def run(self):
Expand Down Expand Up @@ -496,7 +510,7 @@ def run(self):
params = scaling_collection.fit_linear_function(scalings[str(test_obj)])
scaling_function_params[str(test_obj)] = params
# Write scalings for test_obj to file for usage in rate part
self._write_scalings_to_file(test_obj, params)
self._write_scalings_to_file(test_obj, params, plot_name)

plotter = ScalingPlotter(
plot_name,
Expand Down
Loading

0 comments on commit 07ce06d

Please sign in to comment.