Skip to content

Commit

Permalink
Black formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
artlbv committed Mar 4, 2024
1 parent b1ee39f commit 4f07f07
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ menu_tools.egg-info
dist
ph2-menu-tools
prod_ph2-menu-tools
dev_ph2-menu-tools
5 changes: 3 additions & 2 deletions menu_tools/caching/cache_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,13 @@ def _concat_array_from_ntuples(self):
self._final_ak_array = ak.zip({**all_arrays})
# sums -> add local index
if "sums" in self._object.lower():
self._final_ak_array[f"{self._object}_sumType"] = ak.local_index(self._final_ak_array)
self._final_ak_array[f"{self._object}_sumType"] = ak.local_index(
self._final_ak_array
)
self._branches += [f"{self._object}_sumType"]
else:
self._final_ak_array = ak.Array(all_arrays)


def _cache_file_exists(self):
"""
Checks if there is parquet file in cache
Expand Down
10 changes: 5 additions & 5 deletions menu_tools/caching/merge_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
sample = "MinBias"
# sample = "Hgg"
pattern = f"cache/{version}/{version}_{sample}_%s.parquet"
objects = ["L1EGbarrel","L1EGendcap"]
objects = ["L1EGbarrel", "L1EGendcap"]
target_object = "L1EG"

print(f"Reading files as {pattern} for {objects}")
arrs = []

for obj in objects:
arr = ak.from_parquet(pattern%obj)
arr = ak.Array({f.replace(obj,target_object):arr[f] for f in arr.fields})
# apply 5 gev cut
arr = ak.from_parquet(pattern % obj)
arr = ak.Array({f.replace(obj, target_object): arr[f] for f in arr.fields})
# apply 5 gev cut
arr = arr[arr[f"{target_object}_pt"] > 5]
print(obj, arr.fields)
arrs.append(arr)
Expand All @@ -22,4 +22,4 @@
merge_arr = ak.concatenate(arrs, axis=1)
print(merge_arr)
print(f"Writing merged array to: {pattern%target_object}")
ak.to_parquet(merge_arr, pattern%target_object)
ak.to_parquet(merge_arr, pattern % target_object)
2 changes: 1 addition & 1 deletion menu_tools/object_performance/turnon_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _skim_to_hists(self) -> None:
for test_obj, x_arg in self.test_objects:
sel = self.ak_arrays[str(test_obj)][x_arg] > self.threshold
if (self.ak_arrays["ref"].ndim == 1) and (sel.ndim == 2):
sel = sel[:,0]
sel = sel[:, 0]
ak_array = self._flatten_array(self.ak_arrays["ref"][ref_field][sel])
self.hists[str(test_obj)] = np.histogram(ak_array, bins=self.bins)

Expand Down
8 changes: 5 additions & 3 deletions menu_tools/rate_plots/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(self, cfg, data, offline_pt: bool):
self.offline_pt = offline_pt

## Overwrite outdir
self._outdir = os.path.join("outputs", self.cfg.version, "object_performance", "rates")
self._outdir = os.path.join(
"outputs", self.cfg.version, "object_performance", "rates"
)

@property
def _online_offline(self):
Expand Down Expand Up @@ -92,7 +94,7 @@ def _plot_single_version_rate_curves(self):
self._outdir,
f"{version}_{self._online_offline}_{self.cfg.plot_name}",
)
print ('Saving to ',fname)
print("Saving to ", fname)
plt.savefig(fname + ".png")
plt.savefig(fname + ".pdf")

Expand Down Expand Up @@ -189,7 +191,7 @@ def _transform_key(self, raw_key: str) -> str:
transformed to quality
"""
## nano
if ("_" in raw_key):
if "_" in raw_key:
key = raw_key.removeprefix(self.object.nano_obj_name).split("_")[-1]
## menu ntuples
else:
Expand Down
2 changes: 1 addition & 1 deletion menu_tools/utils/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def compute_selection_mask_for_object_cuts(obj: Object, ak_array: ak.Array) -> a
if not obj.cuts:
return sel

## add fake eta
## add fake eta
if "eta" not in ak_array["eta"].fields:
ak_array["eta"] = 0

Expand Down
6 changes: 5 additions & 1 deletion menu_tools/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def get_branches(ntuple_path: str, tree: str, obj: str):
obj_branches = [x.split("_")[-1] for x in all_branches if x.startswith(obj)]
## no nano
else:
obj_branches = [x.removeprefix(prefix + obj) for x in all_branches if x.startswith(prefix+obj)]
obj_branches = [
x.removeprefix(prefix + obj)
for x in all_branches
if x.startswith(prefix + obj)
]

return obj_branches

Expand Down

0 comments on commit 4f07f07

Please sign in to comment.