Skip to content
Snippets Groups Projects
Commit 6c10caea authored by Patrick Ecker's avatar Patrick Ecker
Browse files

Some housekeeping

parent 265d39a4
Branches
No related tags found
1 merge request!63Low level cut study
"""
This file generates usefull dictionaries for the low level cut study.
Patrick Ecker 2020
"""
from rdstar.studies.low_level_cut_study.final_state_particles_cut_study import fsp_collection as fsp_collection_loose
from rdstar.studies.low_level_cut_study.final_state_particles_cut_study import fsp_cut_sets as fsp_cut_sets_loose
......@@ -11,8 +15,7 @@ from rdstar.online_analysis.decay_channels import D_decay_label_to_cut_info_list
D_decay_label_to_decay_id, Dstar_decay_label_to_decay_id, Dstar_decay_channels, D_decay_channels
ntuple_labels_dict = {
fsp_ntuple_labels_dict = {
"e_ntuple": "e",
"mu_ntuple": "mu",
"piCharged_ntuple": "pi+",
......@@ -23,13 +26,13 @@ ntuple_labels_dict = {
}
fsp_cut_dict = {}
for n_tuple in ntuple_labels_dict.keys():
fsps = [fsp for fsp in fsp_collection.all_fsps if fsp.label == ntuple_labels_dict[n_tuple]]
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
fsp = fsps[0]
cut_infos = fsp_cut_sets[fsp.label]
fsps_loose = [fsp for fsp in fsp_collection_loose.all_fsps if fsp.label == ntuple_labels_dict[n_tuple]]
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
fsp = fsps_loose[0]
cut_infos_loose = fsp_cut_sets_loose[fsp.label]
......
import matplotlib.pyplot as plt
"""
This file contains the plotting tools for the low level cut study.
Patrick Ecker 2020
"""
from typing import Any, Union, Optional, List, Tuple, Dict, Generator
import matplotlib.pyplot as plt
from typing import List, Tuple, Dict
import pandas as pd
import copy
import os
from rdstar.offline_analysis.selection.selection_info_containers import CutInfo
from templatefitter.plotter.plot_style import set_matplotlibrc_params, KITColors
from rdstar.offline_analysis.selection.selection_info_containers import CutInfo
from rdstar.studies.low_level_cut_study.low_level_cut_defintions import fsp_cut_dict, D_cut_dict, \
combined_decay_mode_id_dict, combined_channel_dict
__all__ = [
"LowLevelCutPlotter"
]
class LowLevelCutPlotter:
......@@ -26,6 +34,7 @@ class LowLevelCutPlotter:
self.df = df
def apply_cuts(self, pivot: CutInfo, cut_infos: List[CutInfo]) -> pd.DataFrame:
assert isinstance(self.df, pd.DataFrame), "You need to get a Dataframe first!"
df_temp = copy.copy(self.df)
cut_infos = [cut_info.make_root_compatible() for cut_info in cut_infos if cut_info != pivot]
cut_strings = [cut_info.cut_str for cut_info in cut_infos]
......@@ -47,15 +56,17 @@ class LowLevelCutPlotter:
def plot_on(self, save: bool = True) -> Dict[str, os.fspath]:
output = {}
relevant_keys = [key for key in self.cut_dicts if key.startswith(self.n_tuple)]
for key in relevant_keys:
channel = self.cut_dicts[key]["channel"]
channel_cut = f"extraInfo__bodecayModeID__bc == {combined_decay_mode_id_dict[channel]}" if channel else None
for cut_info in self.cut_dicts[key]["cuts"]:
set_matplotlibrc_params()
temp_cut_infos = copy.copy(self.cut_dicts[key]["cuts"])
new_cut_info = cut_info.make_root_compatible()
cut_var = new_cut_info.cut_var
df = self.apply_cuts(pivot=cut_info, cut_infos=temp_cut_infos)
if channel_cut:
df.query(channel_cut, inplace=True)
......@@ -71,9 +82,14 @@ class LowLevelCutPlotter:
continue
fig, ax = plt.subplots()
cuts = list(new_cut_info.cut_limits) if isinstance(new_cut_info.cut_limits, Tuple) else [new_cut_info.cut_limits]
if isinstance(new_cut_info.cut_limits, Tuple):
cuts = list(new_cut_info.cut_limits)
else:
cuts = [new_cut_info.cut_limits]
for cut in cuts:
ax.axvline(cut, color=KITColors.kit_red)
df_bkg = df.query("isSignal == 0")
bkg_data = df_bkg[cut_var].abs() if new_cut_info.cut_abs else df_bkg[cut_var]
df_sig = df.query("isSignal == 1")
......@@ -94,6 +110,7 @@ class LowLevelCutPlotter:
plt.ylabel("Entries")
plt.title(combined_channel_dict[channel], loc="right")
plt.legend(loc="best")
save_path = os.path.join(self.target_path, f"{key}_{new_cut_info.cut_name}_evaluation.pdf")
output.update({f"{key}_{new_cut_info.cut_name}_evaluation": save_path})
if save:
......@@ -104,10 +121,8 @@ class LowLevelCutPlotter:
return output
if __name__ == '__main__':
#df = pd.read_hdf("/ceph/pecker/rdstar/low_level_cut_study/prod_4thAug/CombinedNTuples/e_ntuple_total.h5")
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.apply_cuts(pivot=fsp_cut_dict["e_ntuple"]["cuts"][0], cut_infos=fsp_cut_dict["e_ntuple"]["cuts"])
llcp.plot_on(save=False)
\ No newline at end of file
"""
Steering file for the n-tuple production for the fsp low level cut study.
Patrick Ecker 2020
"""
import basf2
import b2biiConversion
......@@ -6,7 +12,7 @@ from modularAnalysis import *
from analysistools.processing import path_utilities
from rdstar.online_analysis.decay_utilities import Reconstructor
from rdstar.online_analysis import observables, decay_utilities, decay_channels
from rdstar.online_analysis import decay_channels
from rdstar.studies.low_level_cut_study.final_state_particles_cut_study import fsp_collection
input_files, input_sequences, output_dict, config = path_utilities.get_commandline_args()
......
"""
Steering file for the n-tuple production for the D/D* low level cut study.
Patrick Ecker 2020
"""
import basf2
import b2biiConversion
......@@ -5,10 +10,9 @@ import b2biiConversion
from modularAnalysis import *
from analysistools.processing import path_utilities
from analysistools.processing import reco_utilities
from analysistools.processing import skim_cuts_utils
from rdstar.online_analysis import observables, decay_utilities, skim_cuts
from rdstar.online_analysis import decay_utilities, skim_cuts
from rdstar.studies.low_level_cut_study import decay_channels_cut_study
from rdstar.online_analysis.decay_utilities import Reconstructor
......@@ -30,7 +34,6 @@ b2biiConversion.convertBelleMdstToBelleIIMdst(
setAnalysisConfigParams({'mcMatchingVersion': 'Belle'}, main_path)
# Get Final State Particles
main_path.add_module('CurlerCloneMarker')
decay_utilities.fsp.fsp_collection.get_final_state_particles(path=main_path, use_mc_info=config['use_mc_info'])
......@@ -38,12 +41,10 @@ skim_cuts_utils.apply_skim_from_dict(main_path, skim_cuts.pre_skim_cuts)
reconstructor = Reconstructor(path=main_path, config=config, decay_channels_module=decay_channels_cut_study)
# Build intermediate D mesons
reconstructor.reconstruct_D()
reconstructor.reconstruct_Dstar()
###########
# D meson #
###########
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment