Skip to content

Commit

Permalink
Updates and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryDayHall committed Nov 3, 2023
1 parent 839e60b commit 21a092f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
18 changes: 4 additions & 14 deletions jet_tools/CompareClusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
from jet_tools import TrueTag, InputTools, JetQuality, PlottingTools, RemovePileup
import pandas as pd

SCORE_COLS = ["QualityWidth", "QualityFraction",
"AveSignalMassRatio", "AveBGMassRatio",
"AveDistancePT", "AveDistancePhi", "AveDistanceRapidity",
"AvePercentFound",
"AveDistanceBG", "AveDistanceSignal", "AveSeperateJets",
"SeperateAveSignalMassRatio", "SeperateAveBGMassRatio",
"SeperateAveDistancePT", "SeperateAveDistancePhi",
"SeperateAveDistanceRapidity",
"SeperateAveDistanceBG", "SeperateAveDistanceSignal"]

def get_best(eventWise, jet_class):
"""
Expand Down Expand Up @@ -660,7 +651,7 @@ def remove_scores(eventWise):
"""
suffixes_to_remove = ["DistancePT", "DistancePhi", "DistanceRapidity",
"PercentFound", "BGMassRatio", "SignalMassRatio"]
suffixes_to_remove += SCORE_COLS
suffixes_to_remove += Constants.SCORE_COLS
if isinstance(eventWise, str):
eventWise = Components.EventWise.from_file(eventWise)
remove_cols = [name for name in
Expand Down Expand Up @@ -783,7 +774,7 @@ def append_scores(eventWise, dijet_mass=None, end_time=None, duration=np.inf,
new_hyperparameters[name + "_QualityWidth"] = best_width
new_hyperparameters[name + "_QualityFraction"] = best_fraction
# check if it has already been scored asside from quality scores
found = [name + '_' + col in eventWise.columns for col in SCORE_COLS
found = [name + '_' + col in eventWise.columns for col in Constants.SCORE_COLS
if "Quality" not in col]
if not np.all(found) or overwrite:
if not silent:
Expand Down Expand Up @@ -879,7 +870,7 @@ def tabulate_scores(eventWise_paths, variable_cols=None, score_cols=None):
if variable_cols is None:
variable_cols = sorted(FormJets.get_jet_input_params())
if score_cols is None:
score_cols = SCORE_COLS
score_cols = Constants.SCORE_COLS
# also record jet class, eventWise.svae_name and jet_name
all_cols = ["jet_name", "jet_class", "eventWise_name"] + variable_cols + score_cols
table = []
Expand All @@ -893,7 +884,7 @@ def tabulate_scores(eventWise_paths, variable_cols=None, score_cols=None):
# there may be "score only" jets too;
jet_names += [name.split('_', 1)[0]
for name in eventWise.hyperparameter_columns
if "Jet_" in name and name.endswith(SCORE_COLS[0])]
if "Jet_" in name and name.endswith(Constants.SCORE_COLS[0])]
for name in sorted(set(jet_names)):
row = [name, name.split("Jet", 1)[0], eventWise_name]
for part in variable_cols + score_cols:
Expand Down Expand Up @@ -1691,7 +1682,6 @@ def project_2d(show_params, best_slice, all_cols, variable_cols, score_cols,
mult_col = "AveSeperateJets"
# if we are taking the best slice remove all other table rows
if best_slice:
import ipdb; ipdb.set_trace()
bg_values = table[bg_col].values
sg_values = table[sg_col].values
combined = np.sqrt(0.53 * np.square(bg_values) + np.square(sg_values))
Expand Down
22 changes: 12 additions & 10 deletions jet_tools/MassPeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def get_data_for_correct_pairs(eventWise, jet_names, hard_event_pids,
elif isinstance(eventWise, str):
import os
if Components.EventWise.pottential_file(eventWise):
Components.EventWise.from_file(eventWise)
eventWise = Components.EventWise.from_file(eventWise)
return get_data_for_correct_pairs(eventWise, jet_names, hard_event_pids,
additional_decay_pid, jet_pt_cut,
signal_background)
Expand All @@ -879,26 +879,28 @@ def get_data_for_correct_pairs(eventWise, jet_names, hard_event_pids,
else:
raise ValueError("eventWise should be a path to an eventWise or directory")
elif hasattr(eventWise, '__iter__'):
descendants_masses = {}
masses = []
descendants_mass = {}
masses = {}
# assume it is a list of eventWises
for item in eventWise:
print(item)
desc_mass, mass = get_data_for_correct_pairs(item, jet_names, hard_event_pids,
additional_decay_pid, jet_pt_cut,
signal_background)
for key in desc_mass:
if key not in descendants_masses:
descendants_masses[key] = desc_mass[key]
if key not in descendants_mass:
descendants_mass[key] = desc_mass[key]
else:
descendants_masses[key] = \
ak.concatenate([descendants_masses[key], desc_mass[key]])
descendants_mass[key] = \
ak.concatenate([descendants_mass[key], desc_mass[key]])
for key in mass:
if key not in masses:
masses[key] = mass[key]
else:
masses[key] = ak.concatenate([masses[key], mass[key]])
return descendants_masses, masses
for jet_key in mass[key]:
existing = masses[key][jet_key]
masses[key][jet_key] = ak.concatenate([existing, mass[key][jet_key]])
return descendants_mass, masses
else:
raise TypeError(f"eventWise type {type(eventWise)} not understood")

Expand Down Expand Up @@ -929,7 +931,7 @@ def plt_correct_pairs(eventWise, jet_names, hard_event_pids,
ax_function = plot_correct_scatter_axis
else:
ax_function = plot_correct_means_axis
masses, descendants_mass = get_data_for_correct_pairs(eventWise, jet_names, hard_event_pids,
descendants_mass, masses = get_data_for_correct_pairs(eventWise, jet_names, hard_event_pids,
additional_decay_pid, jet_pt_cut,
signal_background)
# work out the maximum counts for each pid in the data
Expand Down
10 changes: 10 additions & 0 deletions jet_tools/ParallelFormJets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,19 @@ def run_list(eventWise_path, end_time, class_list, param_list, name_list):

fix_CALEv2_1 = {'SeedGenerator': 'PtCenter',
'WeightExponent': 0.}

fix_CALEv2_2 = {'SeedGenerator': 'PtCenter',
'WeightExponent': 1.}

scan_CALEv2_1 = {'Sigma': [0.1, 0.5, 1., 1.5, 2., 2.5, 3.],
'Cutoff': [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]}

scan_CALEv2_2 = {'Sigma': [0.5, 1., 1.5, 2., 2.5, 3.],
'Cutoff': [0.2, 0.3, 0.4, 0.5, 0.6, 0.7]}

scan_CALEv2_3 = {'Sigma': [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1.],
'Cutoff': [0.1, 0.15, 0.2, 0.25, 0.3]}

def tabulate_fragments(eventWise_paths):
""" Makes the assumption that jets with the same name are the same jet"""
if isinstance(eventWise_paths, Components.EventWise):
Expand Down
2 changes: 1 addition & 1 deletion jet_tools/spectraljet

0 comments on commit 21a092f

Please sign in to comment.