Skip to content

Commit

Permalink
Merge pull request #73 from danielhundhausen/validation
Browse files Browse the repository at this point in the history
Validation
  • Loading branch information
artlbv authored Apr 22, 2024
2 parents 828fdf8 + cc7663c commit 45f4010
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 39 deletions.
28 changes: 18 additions & 10 deletions configs/scaling_thresholds.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
### General Values
# Jet: {50, 100, 150}
Jet: {25, 30, 35, 40, 45, 50, 55, 60, 70, 75, 80, 85, 90, 100, 120, 125, 130, 140, 150, 175}
# Jet: {100, 120, 150, 175, 200, 250, 300} # Scalings for SC8, as min jet pt in nano is 100 GeV
Muon: {7, 9, 10, 12, 14, 15, 17, 20, 26, 25, 27, 30}
Tau: {27, 30, 40, 50, 60, 70}
EG: {7, 9, 12, 14, 15, 17, 20, 26, 25, 27, 30, 40, 50}
MET: {70, 80, 90, 100, 125, 150, 175, 200}
MHT: {70, 80, 90, 100, 125, 150, 175}
HT: {50, 100, 150, 200, 250, 300, 350, 400, 450, 500}
# Jet: [50, 100, 150]
Jet: [25, 30, 35, 40, 45, 50, 55, 60, 70, 75, 80, 85, 90, 100, 120, 125, 130, 140, 150, 175]
Muon: [7, 9, 10, 12, 14, 15, 17, 20, 26, 25, 27, 30]
Tau: [27, 30, 40, 50, 60, 70]
EG: [7, 9, 12, 14, 15, 17, 20, 26, 25, 27, 30, 40, 50]
MET: [30, 40, 50, 60, 70, 80, 90, 100]
MHT: [70, 80, 90, 100, 125]
HT: [50, 100, 150, 200, 250, 300]

### Specific values:
L1TrackHT:HT:inclusive: {50, 100, 150, 200, 250}
L1TrackHT:HT:inclusive: [50, 100, 150, 200, 250]
# Jets
L1TrackJet:default:endcap: [5, 7.5, 10, 12.5, 15]
L1TrackJet:default:barrel: [10, 15, 20, 30, 35, 40]
L1caloJet:default:endcap: [100, 115, 130, 145, 160, 180, 200]
L1caloJet:default:forward: [100, 115, 130, 145, 160, 180, 200]
# Sums
L1TrackMHT:default:inclusive: [40, 50, 60, 70, 80, 90, 100, 125]
L1puppiMET:default:inclusive: [30, 40, 50, 60, 70, 80, 90, 100]
L1TrackMET:default:inclusive: [10, 15, 20, 25, 30, 35]
19 changes: 13 additions & 6 deletions menu_tools/object_performance/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ def plot(self):
self._make_output_dirs(self.version)

fig, ax = self._create_new_plot()
_xlim_upper = 0
_ylim_upper = 0
for obj_key, points in self.scalings.items():
obj = Object(obj_key, self.version)
x_points = np.array(list(points.keys()))
Expand All @@ -378,6 +380,9 @@ def plot(self):
y = utils.scaling_func(x, a, b)
ax.plot(x, y, color=pts[0].get_color(), label=label)

_xlim_upper = max(_xlim_upper, np.max(x_points) * 1.1)
_ylim_upper = max(_ylim_upper, np.max(y_points) * 1.1)

ax.legend(loc="lower right")
ax.set_xlabel("L1 threshold [GeV]")
ax.set_ylabel(f"{int(self.scaling_pct * 100)}% Location (gen, GeV)")
Expand All @@ -392,8 +397,8 @@ def plot(self):
transform=ax.transAxes,
)
fig.tight_layout()
ax.set_xlim(0, np.max(x_points))
ax.set_ylim(0, np.max(y_points))
ax.set_xlim(0, _xlim_upper)
ax.set_ylim(0, _ylim_upper)

plot_fname = os.path.join(
"outputs",
Expand Down Expand Up @@ -423,8 +428,8 @@ def __init__(self, cfg_plots_path: str) -> None:
self.scaling_thresholds = yaml.safe_load(f)

def _get_scaling_thresholds(self, cfg_plot, test_obj) -> list[int]:
if test_obj in self.scaling_thresholds:
return self.scaling_thresholds[test_obj]
if str(test_obj) in self.scaling_thresholds:
return self.scaling_thresholds[str(test_obj)]
if any("Muon" in x for x in cfg_plot["test_objects"]):
return self.scaling_thresholds["Muon"]
if any(
Expand Down Expand Up @@ -531,11 +536,13 @@ def main():
type=str,
help="Path of YAML configuration file specifying the desired plots.",
)
parser.add_argument("-s", "--scalings_only", action="store_true")
args = parser.parse_args()

for path_cfg_plot in args.cfg_plots:
plotter = EfficiencyCentral(path_cfg_plot)
plotter.run()
if not args.scalings_only:
plotter = EfficiencyCentral(path_cfg_plot)
plotter.run()

scalings = ScalingCentral(path_cfg_plot)
scalings.run()
Expand Down
30 changes: 16 additions & 14 deletions menu_tools/rate_table/menu_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _transform_key(self, raw_key: str, obj: objects.Object) -> str:
transformed to quality
"""
if raw_key.startswith("L1"):
key = raw_key.removeprefix(obj.nano_obj_name+"_")
key = raw_key.removeprefix(obj.nano_obj_name + "_")
else:
key = raw_key.removeprefix(obj.nano_obj_name).lower()

Expand Down Expand Up @@ -107,11 +107,12 @@ def _load_cached_arrays(self, object_name: str) -> ak.Array:
arr = ak.zip({self._transform_key(var, obj): arr[var] for var in arr.fields})

# Apply scalings, except for PV variable, which has no scalings
if ("PV" not in object_name) and (
"disp" not in object_name.lower()) and (
"TrackTripletWord" not in object_name) and (
"ExtTrackHT" not in object_name
):
if (
("PV" not in object_name)
and ("disp" not in object_name.lower())
and ("TrackTripletWord" not in object_name)
and ("ExtTrackHT" not in object_name)
):
print("adding scalings")
arr = scalings.add_offline_pt(arr, obj)

Expand Down Expand Up @@ -156,7 +157,7 @@ def get_legs_arrays_for_seed(

if leg["obj"] not in self.arr_cache:
print(f"Caching {leg['obj']}")
self.arr_cache[leg["obj"]] = self._load_cached_arrays(leg["obj"])
self.arr_cache[leg["obj"]] = self._load_cached_arrays(leg["obj"])
else:
print(f"Using cached {leg['obj']}")
# raw_object_arrays[leg["obj"]] = self._load_cached_arrays(leg["obj"])
Expand Down Expand Up @@ -326,20 +327,22 @@ def print_table(self) -> None:
print(df_table)

def compute_tot_and_pure(self) -> pd.DataFrame:

df_masks = ak.to_dataframe(self._seed_masks)
counts = {}

for seed in df_masks.columns:
counts[seed] = {
"total": df_masks[seed].sum(),
"pure" : ((df_masks[seed]==True)&~(df_masks.drop(seed, axis=1).any(axis=1))).sum()
}

"pure": (
(df_masks[seed] == True)
& ~(df_masks.drop(seed, axis=1).any(axis=1))
).sum(),
}

counts["total"] = {
"total": np.sum(np.any(df_masks, axis = 1)),
"total": np.sum(np.any(df_masks, axis=1)),
"pure": 0,
}
}

df_counts = pd.DataFrame(counts).T
df_counts.index.name = "seed"
Expand Down Expand Up @@ -369,7 +372,6 @@ def make_table(self) -> None:
print("Making table")

table: list[dict[str, Union[str, float]]] = []
ntot = len(list(self._seed_masks.values())[0])
all_seeds_or_mask = ak.zeros_like(list(self._seed_masks.values())[0])

for seed, mask in self._seed_masks.items():
Expand Down
1 change: 1 addition & 0 deletions menu_tools/rate_table/rate_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ def main():

menu_table.compute_tot_and_pure()


if __name__ == "__main__":
main()
14 changes: 7 additions & 7 deletions menu_tools/utils/compare_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ def comp_plots(
diff.plot(
ax=axs[1], color=color, label=label
) # , marker = ".", color = color)
# axs[1].errorbar(
# p1["xbins"],df_p1 - df_p2,
# yerr = np.hypot(plots[0]["efficiency_err"], plots[1]["efficiency_err"]),
# # label = label, marker = ".", color = color,
# label = label, ls = lss[i], color = color, mfc="none" if i == 1 else color,
# **(p1["err_kwargs"])
# )
# axs[1].errorbar(
# p1["xbins"],df_p1 - df_p2,
# yerr = np.hypot(plots[0]["efficiency_err"], plots[1]["efficiency_err"]),
# # label = label, marker = ".", color = color,
# label = label, ls = lss[i], color = color, mfc="none" if i == 1 else color,
# **(p1["err_kwargs"])
# )
if ptype == "turnon":
if len(plots[0]["efficiency_err"][0]) != len(
plots[1]["efficiency_err"][0]
Expand Down
9 changes: 9 additions & 0 deletions menu_tools/utils/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def match_dR(self) -> float:
def plot_label(self) -> str:
return self._object_params["label"]

def get_scaling_object(self, eta_range: str) -> str:
"""
This enables the definition of an object/id which uses
the scalings from a different object.
"""
if "use_scalings_from_object" in self._object_params:
return self._object_params["use_scalings_from_object"]
return str(self).replace("inclusive", eta_range)

@property
def eta_ranges(self) -> dict[str, tuple[float, float]]:
_eta_ranges = {}
Expand Down
7 changes: 5 additions & 2 deletions menu_tools/utils/scalings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ def load_scaling_params(obj: Object, eta_range: str) -> tuple[float, float]:
scaling_params: parameters computed in object_performance
for the online-offline scaling
"""
fname = str(obj).replace("inclusive", eta_range)
fpath = os.path.join(
"outputs", obj.version, "object_performance", "scalings", fname + ".yaml"
"outputs",
obj.version,
"object_performance",
"scalings",
obj.get_scaling_object(eta_range) + ".yaml",
)
try:
with open(fpath, "r") as f:
Expand Down

0 comments on commit 45f4010

Please sign in to comment.