9"""Implements 1D correction"""
12import matplotlib.pyplot
as plt
13from matplotlib.backends.backend_pdf
import PdfPages
15from ROOT.Belle2
import CDCDedxValidationAlgorithm
16import process_cosgain
as cg
17ROOT.gROOT.SetBatch(
True)
20def process_onedgain(onedpath, gt):
21 """Main function to process 1D cell gain data and generate plots."""
23 os.makedirs(
'plots/constant', exist_ok=
True)
25 database_file = f
'{onedpath}/database.txt'
28 exp_run_dict = cg.parse_database(database_file,
'dbstore/CDCDedx1DCell')
31 for exp, run_list
in exp_run_dict.items():
33 print(f
"[INFO] Processing exp={exp}, run={run}")
34 cal = CDCDedxValidationAlgorithm()
36 prev_data = cal.getonedgain(exp, run)
38 cal.setTestingPayload(database_file)
39 new_data = cal.getonedgain(exp, run)
40 cal.setTestingPayload(
"")
43 prev_inner = prev_data.inner1D
if prev_data
else []
44 new_inner = new_data.inner1D
if new_data
else []
45 prev_outer = prev_data.outer1D
if prev_data
else []
46 new_outer = new_data.outer1D
if new_data
else []
47 enta = new_data.Enta
if new_data
else []
50 df_prev_in = pd.DataFrame([[x]
for x
in prev_inner], columns=[
'oned'])
51 df_new_in = pd.DataFrame([[x]
for x
in new_inner], columns=[
'oned'])
52 df_prev_out = pd.DataFrame([[x]
for x
in prev_outer], columns=[
'oned'])
53 df_new_out = pd.DataFrame([[x]
for x
in new_outer], columns=[
'oned'])
54 df_enta = pd.DataFrame([[x]
for x
in enta], columns=[
'enta'])
57 pdf_path = f
'plots/constant/onedgain_e{exp}_r{run}.pdf'
58 with PdfPages(pdf_path)
as pdf:
60 fig, ax = plt.subplots(2, 2, figsize=(20, 12))
63 cg.hist(0.85, 1.12, xlabel=
"entrance angle", ylabel=
"Inner 1D constants", ax=ax[0, 0])
64 ax[0, 0].
plot(df_enta[
'enta'], df_new_in[
'oned'],
'-', rasterized=
True, label=
"inner 1D (new)")
65 ax[0, 0].
plot(df_enta[
'enta'], df_prev_in[
'oned'],
'-', rasterized=
True, label=
"inner 1D (prev)")
66 ax[0, 0].legend(fontsize=15)
69 cg.hist(0.7, 1.12, xlabel=
"entrance angle", ylabel=
"Outer 1D constants", ax=ax[0, 1])
70 ax[0, 1].
plot(df_enta[
'enta'], df_new_out[
'oned'],
'-', rasterized=
True, label=
"outer 1D (new)")
71 ax[0, 1].
plot(df_enta[
'enta'], df_prev_out[
'oned'],
'-', rasterized=
True, label=
"outer 1D (prev)")
72 ax[0, 1].legend(fontsize=15)
75 cg.hist(0.94, 1.06, xlabel=
"entrance angle", ylabel=
"Ratio (new/prev)", ax=ax[1, 0])
76 ratio_inner = df_new_in[
'oned'] / df_prev_in[
'oned']
77 ax[1, 0].
plot(df_enta[
'enta'], ratio_inner,
'-', rasterized=
True, label=
"inner ratio")
78 ax[1, 0].legend(fontsize=15)
81 cg.hist(0.96, 1.04, xlabel=
"entrance angle", ylabel=
"Ratio (new/prev)", ax=ax[1, 1])
82 ratio_outer = df_new_out[
'oned'] / df_prev_out[
'oned']
83 ax[1, 1].
plot(df_enta[
'enta'], ratio_outer,
'-', rasterized=
True, label=
"outer ratio")
84 ax[1, 1].legend(fontsize=15)
86 fig.suptitle(f
"OneD Gain Calibration - Experiment {exp}", fontsize=20)