diff --git a/rdstar/studies/low_level_cut_study/low_level_cut_study.py b/rdstar/studies/low_level_cut_study/low_level_cut_study.py index 3032770f93fc88e135da5d86200abbb02856d1ae..f5a09dce2ea3c72d62b7e6cf383f5d1f19af9e04 100644 --- a/rdstar/studies/low_level_cut_study/low_level_cut_study.py +++ b/rdstar/studies/low_level_cut_study/low_level_cut_study.py @@ -1,5 +1,3 @@ - - import os import yaml import logging @@ -30,7 +28,6 @@ __all__ = [ class MergeNTuplesTask(utilities.BaseOfflineTask): - config_path = luigi.Parameter(positional=False) ntuple_samples_combination = luigi.TupleParameter(positional=False) @@ -46,7 +43,7 @@ class MergeNTuplesTask(utilities.BaseOfflineTask): self.input_dict = {k: v.path for d in self.input() if isinstance(d, dict) for k, v in d.items()} @staticmethod - def get_sample_ntuple_combinations(configs) -> Dict[str,List[str]]: + def get_sample_ntuple_combinations(configs) -> Dict[str, List[str]]: config_files = [os.path.join(get_config_base_path(), file) for file in configs] configs = [load_json_config(c) for c in config_files] @@ -55,11 +52,11 @@ class MergeNTuplesTask(utilities.BaseOfflineTask): samples = config["data"].keys() n_tuples = config["output"] for tuple in n_tuples: - combinations.update({tuple : [str(s) for s in samples]}) + combinations.update({tuple: [str(s) for s in samples]}) return combinations - def run_merging(self, dry_run: bool=False) -> Dict[str, os.fspath]: + def run_merging(self, dry_run: bool = False) -> Dict[str, os.fspath]: n_tuple_dir = os.path.join(self.working_dir, "CombinedNTuples") output_key = f"{self.ntuple_samples_combination[0]}_total" output_path = os.path.join(n_tuple_dir, f"{self.ntuple_samples_combination[0]}_total.h5") @@ -70,7 +67,8 @@ class MergeNTuplesTask(utilities.BaseOfflineTask): number_of_events = 0 for combo in combos: assert os.path.isfile(path=self.input_dict[combo]), self.input_dict[combo] - assert os.path.splitext(p=self.input_dict[combo])[1] == ".root", os.path.splitext(p=self.input_dict[combo]) + assert os.path.splitext(p=self.input_dict[combo])[1] == ".root", os.path.splitext( + p=self.input_dict[combo]) data_file = uproot.open(self.input_dict[combo]) tree = data_file[data_file.keys()[0]] df = tree.pandas.df() @@ -101,7 +99,6 @@ class MergeNTuplesTask(utilities.BaseOfflineTask): class LowLevelCutsEvaluationTask(utilities.BaseOfflineTask): - config_path = luigi.Parameter(positional=False) n_tuple = luigi.Parameter(positional=False) # type: str @@ -118,7 +115,7 @@ class LowLevelCutsEvaluationTask(utilities.BaseOfflineTask): self.input_dict = {k: v.path for d in self.input() if isinstance(d, dict) for k, v in d.items()} - def run_evaluation(self, dry_run: bool=False) -> Dict[str, os.fspath]: + def run_evaluation(self, dry_run: bool = False) -> Dict[str, os.fspath]: output_dir = os.path.join(self.cut_evaluation_dir, self.n_tuple) llcp = LowLevelCutPlotter( n_tuple=self.n_tuple, @@ -153,7 +150,6 @@ class LowLevelCutsEvaluationTask(utilities.BaseOfflineTask): class LowLevelCutStudyMaster(luigi.WrapperTask): - config_path = luigi.Parameter(positional=False) def __init__(self, *args, **kwargs) -> None: @@ -173,10 +169,10 @@ class LowLevelCutStudyMaster(luigi.WrapperTask): if __name__ == "__main__": config_base_path = get_config_base_path() - offline_config_path = os.path.join(config_base_path, "low_level_cut_study_conf.yaml") # type: os.fspath + offline_config_path = os.path.join(config_base_path, "low_level_cut_study_conf.yaml") # type: os.fspath num_workers = 10 luigi.process( LowLevelCutStudyMaster(config_path=offline_config_path), workers=num_workers - ) \ No newline at end of file + ) diff --git a/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_fsp_low_level_cut_study.py b/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_fsp_low_level_cut_study.py index 6a359ea0595b5c53d193983fca8d8603c22fb3dd..63fea6309df105bf1fb5e28159304336127e913d 100644 --- a/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_fsp_low_level_cut_study.py +++ b/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_fsp_low_level_cut_study.py @@ -321,4 +321,4 @@ main_path.add_module( basf2.print_path(main_path) basf2.process(main_path) -print(statistics) \ No newline at end of file +print(statistics) diff --git a/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_low_level_cut_study.py b/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_low_level_cut_study.py index 5263d58266de05cd96d9ffa0fe3174898ee9f746..3d514027e1902400a592995faf8ee54ddaadcd16 100644 --- a/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_low_level_cut_study.py +++ b/rdstar/studies/low_level_cut_study/reconstruction/reconstruction_low_level_cut_study.py @@ -168,4 +168,4 @@ main_path.add_module( basf2.print_path(main_path) basf2.process(main_path) -print(statistics) \ No newline at end of file +print(statistics) diff --git a/rdstar/studies/low_level_cut_study/utilities/decay_channels_cut_study.py b/rdstar/studies/low_level_cut_study/utilities/decay_channels_cut_study.py index ae4ed91a90c5b5a6c6dbf540b6ceda499033e9e6..7c34508583a657b7ec80dd9d6391da5b12b50d9b 100644 --- a/rdstar/studies/low_level_cut_study/utilities/decay_channels_cut_study.py +++ b/rdstar/studies/low_level_cut_study/utilities/decay_channels_cut_study.py @@ -3,11 +3,14 @@ This file updates the decay channels cut infos for the low level cut study. Patrick Ecker 2020 """ + import copy from rdstar.online_analysis.decay_channels import * -from rdstar.online_analysis.decay_channels import D_decay_label_to_cut_info_list as _original_D_decay_label_to_cut_info_list -from rdstar.online_analysis.decay_channels import Dstar_decay_label_to_cut_info_list as _original_Dstar_decay_label_to_cut_info_list +from rdstar.online_analysis.decay_channels import \ + D_decay_label_to_cut_info_list as _original_D_decay_label_to_cut_info_list +from rdstar.online_analysis.decay_channels import \ + Dstar_decay_label_to_cut_info_list as _original_Dstar_decay_label_to_cut_info_list from rdstar.online_analysis.decay_channels import decay_channels_utils, channels_with_neutrinos, \ generator_level_only_channels @@ -19,13 +22,11 @@ __all__ = [ "Dstar_decay_label_to_cut_list" ] - - # Update the D cuts D_decay_label_to_cut_info_list = copy.copy(_original_D_decay_label_to_cut_info_list) for channel, cut_infos in D_decay_label_to_cut_info_list.items(): D_decay_label_to_cut_info_list[channel] = [cut_info.scale_cut(percentage=1.) for cut_info in cut_infos] - #D_decay_label_to_cut_info_list[channel] = [] + # D_decay_label_to_cut_info_list[channel] = [] D_decay_label_to_cut_list = {} for channel, cut_infos in D_decay_label_to_cut_info_list.items(): @@ -35,13 +36,12 @@ for channel, cut_infos in D_decay_label_to_cut_info_list.items(): Dstar_decay_label_to_cut_info_list = copy.copy(_original_Dstar_decay_label_to_cut_info_list) for channel, cut_infos in Dstar_decay_label_to_cut_info_list.items(): Dstar_decay_label_to_cut_info_list[channel] = [cut_info.scale_cut(percentage=1.) for cut_info in cut_infos] - #Dstar_decay_label_to_cut_info_list[channel] = [] + # Dstar_decay_label_to_cut_info_list[channel] = [] Dstar_decay_label_to_cut_list = {} for channel, cut_infos in Dstar_decay_label_to_cut_info_list.items(): Dstar_decay_label_to_cut_list[channel] = [cut_info.cut_str for cut_info in cut_infos] - decay_channel_dict = decay_channels_utils.prepare_decay_channel_dict( local_vars=locals(), channels_with_neutrinos=channels_with_neutrinos, @@ -49,4 +49,4 @@ decay_channel_dict = decay_channels_utils.prepare_decay_channel_dict( ) if __name__ == '__main__': - decay_channels_utils.print_decay_channels_table(decay_channel_dict) \ No newline at end of file + decay_channels_utils.print_decay_channels_table(decay_channel_dict) diff --git a/rdstar/studies/low_level_cut_study/utilities/final_state_particles_cut_study.py b/rdstar/studies/low_level_cut_study/utilities/final_state_particles_cut_study.py index b1517d8a0fadb1b66d5f05e418eb22011aabcb92..30f1a7aa79327abadba2749db3e700050b291cf3 100644 --- a/rdstar/studies/low_level_cut_study/utilities/final_state_particles_cut_study.py +++ b/rdstar/studies/low_level_cut_study/utilities/final_state_particles_cut_study.py @@ -8,12 +8,14 @@ from rdstar.online_analysis.final_state_particles import * scale_factor = 1. + def scale_cut_list(cut_list: List[CutInfo], scale_factor: float) -> List[CutInfo]: return [ cut_info.scale_cut(percentage=scale_factor) for cut_info in cut_list if cut_info.scale_cut(percentage=scale_factor).cut_str ] + electron_cuts = scale_cut_list(cut_list=electron_cuts, scale_factor=scale_factor) muon_cuts = scale_cut_list(cut_list=muon_cuts, scale_factor=scale_factor) tau_cuts = scale_cut_list(cut_list=tau_cuts, scale_factor=scale_factor) @@ -23,15 +25,15 @@ photon_cuts = scale_cut_list(cut_list=photon_cuts, scale_factor=scale_factor) charged_kaon_cuts = scale_cut_list(cut_list=charged_kaon_cuts, scale_factor=scale_factor) neutral_kaon_cuts = scale_cut_list(cut_list=neutral_kaon_cuts, scale_factor=scale_factor) neutrino_cuts = scale_cut_list(cut_list=neutrino_cuts, scale_factor=scale_factor) -#electron_cuts = [] -#muon_cuts = [] -#tau_cuts = [] -#charged_pion_cuts = [] -#neutral_pion_cuts = [] -#photon_cuts = [] -#charged_kaon_cuts = [] -#neutral_kaon_cuts = [] -#neutrino_cuts = [] +# electron_cuts = [] +# muon_cuts = [] +# tau_cuts = [] +# charged_pion_cuts = [] +# neutral_pion_cuts = [] +# photon_cuts = [] +# charged_kaon_cuts = [] +# neutral_kaon_cuts = [] +# neutrino_cuts = [] # Particle Definition electron = generate_fsp( @@ -117,7 +119,7 @@ fsp_collection = FinalStateParticleCollection() fsp_collection.add_fsps( electron=electron, muon=muon, - #tau=tau, + # tau=tau, charged_pion=charged_pion, neutral_pion=neutral_pion, photon=photon, @@ -129,18 +131,18 @@ fsp_collection.add_fsps( ) fsp_cut_sets = { - electron.label : electron_cuts, - muon.label : muon_cuts, - tau.label : tau_cuts, - charged_pion.label : charged_pion_cuts, - neutral_pion.label : neutral_pion_cuts, - photon.label : photon_cuts, - charged_kaon.label : charged_kaon_cuts, - neutral_kaon.label : neutral_kaon_cuts, - e_neutrino.label : neutrino_cuts, - mu_neutrino.label : neutrino_cuts, - tau_neutrino.label : neutrino_cuts, + electron.label: electron_cuts, + muon.label: muon_cuts, + tau.label: tau_cuts, + charged_pion.label: charged_pion_cuts, + neutral_pion.label: neutral_pion_cuts, + photon.label: photon_cuts, + charged_kaon.label: charged_kaon_cuts, + neutral_kaon.label: neutral_kaon_cuts, + e_neutrino.label: neutrino_cuts, + mu_neutrino.label: neutrino_cuts, + tau_neutrino.label: neutrino_cuts, } if __name__ == '__main__': - print(fsp_collection) \ No newline at end of file + print(fsp_collection) diff --git a/rdstar/studies/low_level_cut_study/utilities/low_level_cut_defintions.py b/rdstar/studies/low_level_cut_study/utilities/low_level_cut_defintions.py index 8f991555280d49fff44f822ce9b9d5abe5cca0aa..99797819096897e27590dcd6b7919ad1a7ae9103 100644 --- a/rdstar/studies/low_level_cut_study/utilities/low_level_cut_defintions.py +++ b/rdstar/studies/low_level_cut_study/utilities/low_level_cut_defintions.py @@ -1,20 +1,22 @@ """ -This file generates usefull dictionaries for the low level cut study. +This file generates useful dictionaries for the low level cut study. Patrick Ecker 2020 """ -from rdstar.studies.low_level_cut_study.utilities.final_state_particles_cut_study import fsp_collection as fsp_collection_loose -from rdstar.studies.low_level_cut_study.utilities.final_state_particles_cut_study import fsp_cut_sets as fsp_cut_sets_loose +from rdstar.studies.low_level_cut_study.utilities.final_state_particles_cut_study import \ + fsp_collection as fsp_collection_loose +from rdstar.studies.low_level_cut_study.utilities.final_state_particles_cut_study import \ + fsp_cut_sets as fsp_cut_sets_loose from rdstar.online_analysis.final_state_particles import fsp_collection from rdstar.online_analysis.final_state_particles import fsp_cut_sets -from rdstar.studies.low_level_cut_study.utilities.decay_channels_cut_study import D_decay_label_to_cut_info_list as D_loose_dict, \ +from rdstar.studies.low_level_cut_study.utilities.decay_channels_cut_study import \ + D_decay_label_to_cut_info_list as D_loose_dict, \ Dstar_decay_label_to_cut_info_list as Dstar_loose_dict from rdstar.online_analysis.decay_channels import D_decay_label_to_cut_info_list, Dstar_decay_label_to_cut_info_list, \ D_decay_label_to_decay_id, Dstar_decay_label_to_decay_id, Dstar_decay_channels, D_decay_channels - fsp_ntuple_labels_dict = { "e_ntuple": "e", "mu_ntuple": "mu", @@ -28,12 +30,12 @@ fsp_ntuple_labels_dict = { fsp_cut_dict = {} for n_tuple in fsp_ntuple_labels_dict.keys(): fsps = [fsp for fsp in fsp_collection.all_fsps if fsp.label == fsp_ntuple_labels_dict[n_tuple]] - assert len(fsps)==1 + assert len(fsps) == 1 fsp = fsps[0] cut_infos = fsp_cut_sets[fsp.label] fsps_loose = [fsp for fsp in fsp_collection_loose.all_fsps if fsp.label == fsp_ntuple_labels_dict[n_tuple]] - assert len(fsps_loose)==1 + assert len(fsps_loose) == 1 fsp = fsps_loose[0] cut_infos_loose = fsp_cut_sets_loose[fsp.label] @@ -77,13 +79,13 @@ for n_tuple, cut_lists in ntuple_d_dict.items(): if channel.startswith(cut_lists["label"]): D_cut_dict.update( { - f"{n_tuple}{channel}" : { + f"{n_tuple}{channel}": { "cuts": cut_lists["cuts"][channel], "cuts_loose": cut_lists["cuts_loose"][channel], "channel": channel } } - ) + ) combined_decay_mode_id_dict = {} combined_decay_mode_id_dict.update(D_decay_label_to_decay_id) @@ -92,7 +94,7 @@ combined_decay_mode_id_dict.update(Dstar_decay_label_to_decay_id) combined_channel_dict = {} combined_channel_dict.update(D_decay_channels) combined_channel_dict.update(Dstar_decay_channels) -combined_channel_dict.update({"":""}) +combined_channel_dict.update({"": ""}) if __name__ == '__main__': for channel, item in Dstar_decay_label_to_cut_info_list.items(): @@ -109,4 +111,4 @@ if __name__ == '__main__': print(fsp_cut_dict) print(D_cut_dict) - print(combined_decay_mode_id_dict) \ No newline at end of file + print(combined_decay_mode_id_dict) diff --git a/rdstar/studies/low_level_cut_study/utilities/plotting.py b/rdstar/studies/low_level_cut_study/utilities/plotting.py index a84d6a3710f1ac370cbb8746651656d6334400c7..9de0860c3235d5e6446082cfdafcb7b8c4704c00 100644 --- a/rdstar/studies/low_level_cut_study/utilities/plotting.py +++ b/rdstar/studies/low_level_cut_study/utilities/plotting.py @@ -120,9 +120,10 @@ class LowLevelCutPlotter: return output + if __name__ == '__main__': df = pd.read_hdf("/ceph/pecker/rdstar/low_level_cut_study/CombinedNTuples/dcharged_ntuple_total.h5") llcp = LowLevelCutPlotter(n_tuple="dcharged_ntuple", target_path="") print(llcp.generate_output_dict()) llcp.get_df(df=df) - llcp.plot_on(save=False) \ No newline at end of file + llcp.plot_on(save=False) diff --git a/rdstar/studies/low_level_cut_study/utilities/utilities.py b/rdstar/studies/low_level_cut_study/utilities/utilities.py index de14480d9c0a1648be71fcf811809908c9f229c8..7876171a784b0d50fd8f34a016f94d891a1045b3 100644 --- a/rdstar/studies/low_level_cut_study/utilities/utilities.py +++ b/rdstar/studies/low_level_cut_study/utilities/utilities.py @@ -2,5 +2,6 @@ import os import inspect import rdstar + def get_config_base_path(): - return os.path.join(os.path.dirname(inspect.getfile(rdstar)), "studies/low_level_cut_study") \ No newline at end of file + return os.path.join(os.path.dirname(inspect.getfile(rdstar)), "studies/low_level_cut_study")