From b047beac6ab133da8c8976adcebcbedb68432d36 Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Wed, 21 Feb 2024 14:59:09 +0100 Subject: [PATCH 1/5] add dpg_trigger/.../cache as symlink to repo --- cache | 1 + 1 file changed, 1 insertion(+) create mode 120000 cache diff --git a/cache b/cache new file mode 120000 index 00000000..5a2aa4fe --- /dev/null +++ b/cache @@ -0,0 +1 @@ +/eos/cms/store/group/dpg_trigger/comm_trigger/L1Trigger/alobanov/phase2/menu/ntuples/cache \ No newline at end of file From 9a5032651437620a00a842303af508840d3d3d13 Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Wed, 21 Feb 2024 15:07:30 +0100 Subject: [PATCH 2/5] remove quality cut <25GeV for tkElectrons --- configs/V29/objects/electrons.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/configs/V29/objects/electrons.yaml b/configs/V29/objects/electrons.yaml index c26f5220..9875c7af 100644 --- a/configs/V29/objects/electrons.yaml +++ b/configs/V29/objects/electrons.yaml @@ -20,7 +20,6 @@ tkElectron: cuts: inclusive: - "abs({eta}) < 2.4" - - "({passeseleid} == 1) | ({pt} < 25)" NoIsoForIso: # This id is exclusively used for the # isoloation wp derivation @@ -28,8 +27,6 @@ tkElectron: cuts: inclusive: - "abs({eta}) < 2.7" - barrel: - - "({passeseleid} == 1) | ({pt} < 25)" Iso: label: "TkIsoElectron" cuts: @@ -37,7 +34,6 @@ tkElectron: - "abs({eta}) < 2.4" barrel: - "abs({trkiso}) < 0.13" - - "({passeseleid} == 1) | ({pt} < 25)" endcap: - "abs({trkiso}) < 0.28" From 236b4a888d4e21982144604ad56f5648b924563f Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Mon, 26 Feb 2024 14:11:37 +0100 Subject: [PATCH 3/5] add NoIsoLowPt id for tkElectron --- configs/V29/object_performance/electron_matching.yaml | 2 ++ .../V29/object_performance/electron_matching_eta.yaml | 2 ++ configs/V29/object_performance/electron_trigger.yaml | 2 ++ configs/V29/objects/electrons.yaml | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/configs/V29/object_performance/electron_matching.yaml b/configs/V29/object_performance/electron_matching.yaml index 94877ba3..68ed26f2 100644 --- a/configs/V29/object_performance/electron_matching.yaml +++ b/configs/V29/object_performance/electron_matching.yaml @@ -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)" @@ -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)" diff --git a/configs/V29/object_performance/electron_matching_eta.yaml b/configs/V29/object_performance/electron_matching_eta.yaml index 5584d0a2..4e470d51 100644 --- a/configs/V29/object_performance/electron_matching_eta.yaml +++ b/configs/V29/object_performance/electron_matching_eta.yaml @@ -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)" @@ -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)" diff --git a/configs/V29/object_performance/electron_trigger.yaml b/configs/V29/object_performance/electron_trigger.yaml index 476ceb39..18bc8f3d 100644 --- a/configs/V29/object_performance/electron_trigger.yaml +++ b/configs/V29/object_performance/electron_trigger.yaml @@ -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: @@ -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: diff --git a/configs/V29/objects/electrons.yaml b/configs/V29/objects/electrons.yaml index 9875c7af..efb65634 100644 --- a/configs/V29/objects/electrons.yaml +++ b/configs/V29/objects/electrons.yaml @@ -20,6 +20,7 @@ tkElectron: cuts: inclusive: - "abs({eta}) < 2.4" + - "({passeseleid} == 1)" NoIsoForIso: # This id is exclusively used for the # isoloation wp derivation @@ -27,6 +28,8 @@ tkElectron: cuts: inclusive: - "abs({eta}) < 2.7" + barrel: + - "({passeseleid} == 1)" Iso: label: "TkIsoElectron" cuts: @@ -34,8 +37,15 @@ tkElectron: - "abs({eta}) < 2.4" barrel: - "abs({trkiso}) < 0.13" + - "({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 From 862382ed681a044cce6240dbb736afd73369bfc7 Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Mon, 26 Feb 2024 14:14:31 +0100 Subject: [PATCH 4/5] remove xerr from efficiency plots --- menu_tools/object_performance/plotter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menu_tools/object_performance/plotter.py b/menu_tools/object_performance/plotter.py index cf4b4b40..974b650b 100755 --- a/menu_tools/object_performance/plotter.py +++ b/menu_tools/object_performance/plotter.py @@ -155,7 +155,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, From d495a1453dce608fe5c2bb6af917a099c6ab0638 Mon Sep 17 00:00:00 2001 From: Daniel Hundhausen Date: Mon, 26 Feb 2024 16:03:20 +0100 Subject: [PATCH 5/5] create warning when scalings already exist and dump to different file; add warning comments to tau config; fix tests after tkeleID change --- .gitignore | 1 + .../V29/object_performance/met_ht_mht.yaml | 8 +- .../V29/object_performance/tau_trigger.yaml | 8 + menu_tools/object_performance/plotter.py | 22 +- .../ElectronsIsolation_Barrel_-999_V29.json | 204 +++++++++--------- .../ElectronsIsolation_Barrel_-999_V29.yaml | 2 +- .../rate_plots/tests/test_rate_plots_v29.py | 13 +- 7 files changed, 145 insertions(+), 113 deletions(-) diff --git a/.gitignore b/.gitignore index 484f9076..0c32cf82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.pyc pyenv/* **/*.png +**/*.pdf **/.DS_Store **/*.parquet **/*.root diff --git a/configs/V29/object_performance/met_ht_mht.yaml b/configs/V29/object_performance/met_ht_mht.yaml index 68dc5a98..709bebb4 100644 --- a/configs/V29/object_performance/met_ht_mht.yaml +++ b/configs/V29/object_performance/met_ht_mht.yaml @@ -52,7 +52,7 @@ HT_50perc: max: 750 step: 20 -MHT_50perc: +MHT_90perc: sample: TT version: V29 reference_object: @@ -71,7 +71,7 @@ MHT_50perc: thresholds: [70, 150] scalings: method: "naive" - threshold: 0.50 + threshold: 0.90 xlabel: "Gen. MHT30 (GeV)" ylabel: "Trigger Efficiency ( GeV)" binning: @@ -79,7 +79,7 @@ MHT_50perc: max: 500 step: 20 -MHT_90perc: +MHT_50perc: sample: TT version: V29 reference_object: @@ -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 ( GeV)" binning: diff --git a/configs/V29/object_performance/tau_trigger.yaml b/configs/V29/object_performance/tau_trigger.yaml index 084cdd11..2bd6456d 100644 --- a/configs/V29/object_performance/tau_trigger.yaml +++ b/configs/V29/object_performance/tau_trigger.yaml @@ -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 @@ -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 diff --git a/menu_tools/object_performance/plotter.py b/menu_tools/object_performance/plotter.py index 974b650b..955f559a 100755 --- a/menu_tools/object_performance/plotter.py +++ b/menu_tools/object_performance/plotter.py @@ -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 @@ -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 @@ -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): @@ -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, diff --git a/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.json b/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.json index 76626ecc..fe51f03f 100644 --- a/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.json +++ b/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.json @@ -2,108 +2,108 @@ "xlabel": "Isolation", "ylabel": "Efficiency (Barrel)", "watermark": "V29_ElectronsIsolation_Barrel_-999", - "tkElectron:NoIso:inclusive": { - "label": "TkElectron", + "tkElectron:NoIsoLowPt:inclusive": { + "label": "TkElectron, no ID for $p_T<25$", "efficiency": [ - 0.9405951546885947, - 0.9405951546885947, - 0.9405951546885947, - 0.9407426527526827, - 0.9408901508167705, - 0.9415170175891442, - 0.9424388804896936, - 0.9435451159703528, - 0.9458682104797375, - 0.9487075482134297, - 0.9522106272355175, - 0.9551237140012537, - 0.9584792949592537, - 0.9614292562410118, - 0.9640104723625502, - 0.9662966923559129, - 0.9684354142851875, - 0.9704266381503742, - 0.9721228658873853, - 0.9735240974962204, - 0.975662819425495, - 0.977322172646484, - 0.9786865297392972, - 0.9800877613481324, - 0.9810464987647037, - 0.9820421106972971, - 0.9828533500497806, - 0.9838489619823739, - 0.9851026955271212, - 0.9859508093956267, - 0.9865039271359564, - 0.987093919392308, - 0.9879051587447915, - 0.9884951510011432, - 0.9889007706773849, - 0.9895645119657804, - 0.9900807551900881, - 0.9906338729304178, - 0.9912238651867694, - 0.9915926103469892, - 0.9922932261514068, - 0.9924407242154947, - 0.9928463438917364, - 0.9932888380840001, - 0.993546959696154, - 0.9938419558243298, - 0.9941369519525056, - 0.9944319480806815, - 0.9945794461447693, - 0.9946163206607913, - 0.9948006932409013, - 0.995058814853055, - 0.995243187433165, - 0.9953538109812309, - 0.9954644345292968, - 0.9957963051734946, - 0.9959069287215605, - 0.9960544267856485, - 0.9963494229138242, - 0.9964600464618902, - 0.9965337954939342, - 0.9966075445259781, - 0.9968287916221099, - 0.9969762896861979, - 0.9971606622663077, - 0.9973081603303957, - 0.9973450348464177, - 0.9975294074265275, - 0.9976400309745934, - 0.9977506545226594, - 0.9978244035547034, - 0.9979719016187912, - 0.9980456506508352, - 0.9981193996828792, - 0.9982668977469671, - 0.9984512703270769, - 0.9985987683911649, - 0.9987093919392308, - 0.9987831409712747, - 0.9988568900033187, - 0.9989306390353626, - 0.9990781370994506, - 0.9991887606475165, - 0.9991887606475165, - 0.9992993841955824, - 0.9993362587116044, - 0.9994100077436484, - 0.9994100077436484, - 0.9994837567756923, - 0.9994837567756923, - 0.9994837567756923, - 0.9995575058077363, - 0.9995575058077363, - 0.9996312548397802, - 0.9996312548397802, - 0.9997787529038681, - 0.9998525019359121, - 0.999963125483978, - 0.999963125483978, + 0.9455413650661311, + 0.9455413650661311, + 0.9455413650661311, + 0.9456929548641376, + 0.9458445446621443, + 0.9464888013036723, + 0.9474362375412134, + 0.9485731610262629, + 0.9509607003448668, + 0.9538030090574904, + 0.9572895744116421, + 0.9601697805737673, + 0.9636184484784174, + 0.966574449539546, + 0.9691514761056581, + 0.9713874256262554, + 0.9734338878993444, + 0.9752908629249252, + 0.9766930685564862, + 0.9779815818395422, + 0.9798006594156213, + 0.981240762496684, + 0.982415583431235, + 0.9836661992647895, + 0.984575738052829, + 0.9854852768408686, + 0.986091636032895, + 0.9868116875734263, + 0.9878349187099709, + 0.9884791753514989, + 0.9889339447455187, + 0.9893508166900368, + 0.9899192784325614, + 0.9904119452760829, + 0.9907909197710995, + 0.9913214840641225, + 0.9917762534581422, + 0.9922689203016637, + 0.9927994845946868, + 0.9931026641906999, + 0.993746920832228, + 0.9938606131807329, + 0.9942395876757494, + 0.9945048698222609, + 0.9947322545192708, + 0.9950354341152841, + 0.9951870239132906, + 0.9954144086103005, + 0.9955281009588055, + 0.9955659984083072, + 0.9957175882063137, + 0.9959828703528253, + 0.9961723576003335, + 0.9962481524993368, + 0.9963239473983401, + 0.996665024443855, + 0.9967408193428582, + 0.9968166142418615, + 0.9970439989388714, + 0.9971576912873764, + 0.9972334861863796, + 0.9972713836358813, + 0.9974229734338879, + 0.9974987683328912, + 0.9976882555803994, + 0.9978398453784061, + 0.9978777428279076, + 0.9980293326259143, + 0.9981430249744192, + 0.9982188198734225, + 0.9982567173229242, + 0.9983704096714291, + 0.9984462045704324, + 0.9985219994694358, + 0.9986356918179407, + 0.9987872816159472, + 0.9989388714139539, + 0.9989767688634555, + 0.9990525637624588, + 0.9991283586614621, + 0.9992041535604654, + 0.999355743358472, + 0.9994694357069769, + 0.9994694357069769, + 0.9995452306059802, + 0.9995831280554819, + 0.9996589229544852, + 0.9996589229544852, + 0.9996968204039868, + 0.9996968204039868, + 0.9996968204039868, + 0.9997347178534884, + 0.9997347178534884, + 0.9998105127524918, + 0.9998105127524918, + 0.9998863076514951, + 0.9998863076514951, + 0.9999621025504983, + 0.9999621025504983, 1.0 ], "efficiency_err": [ @@ -522,4 +522,4 @@ "markersize": 8 } } -} +} \ No newline at end of file diff --git a/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.yaml b/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.yaml index 7ad771c0..bf6e1ea4 100644 --- a/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.yaml +++ b/menu_tools/object_performance/tests/reference_data/ElectronsIsolation_Barrel_-999_V29.yaml @@ -17,7 +17,7 @@ ElectronsIsolation_Barrel: x_arg: Pt sample: DYLL_M50 test_objects: - tkElectron:NoIso: trkiso + tkElectron:NoIsoLowPt: trkiso version: V29 xlabel: Isolation ylabel: Efficiency (Barrel) diff --git a/menu_tools/rate_plots/tests/test_rate_plots_v29.py b/menu_tools/rate_plots/tests/test_rate_plots_v29.py index 63e150bb..bc6d920d 100644 --- a/menu_tools/rate_plots/tests/test_rate_plots_v29.py +++ b/menu_tools/rate_plots/tests/test_rate_plots_v29.py @@ -3,6 +3,7 @@ """ import json from unittest.mock import patch +import re import sys import numpy as np @@ -27,6 +28,7 @@ def test_matching_plots_reproduced(test_name): # Run Plotting with patch.object(sys, "argv", testargs): plotter.main() + pass # Load result and assert correct outcome (Offline) for online_offline in ["Online", "Offline"]: @@ -42,13 +44,20 @@ def test_matching_plots_reproduced(test_name): reference_data = json.load(f) for key, val in reference_data.items(): + print(key) if isinstance(val, dict): efficiencies_test = np.array( test_result[key]["y_values"], dtype=np.float64 ) efficiencies_reference = np.array(val["y_values"], dtype=np.float64) - print(efficiencies_reference) differences = efficiencies_test - efficiencies_reference - assert not np.any(abs(differences) > 1e-4) + print(differences) + try: + assert not np.any(abs(differences) > 1e-4) + except Exception as e: + print(online_offline) + print(efficiencies_test) + print(efficiencies_reference) + raise e else: assert val == test_result[key]