legend-dataflow-scripts 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {legend_dataflow_scripts-0.1.2/src/legend_dataflow_scripts.egg-info → legend_dataflow_scripts-0.1.4}/PKG-INFO +2 -2
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/pyproject.toml +1 -1
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4/src/legend_dataflow_scripts.egg-info}/PKG-INFO +2 -2
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/SOURCES.txt +1 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/requires.txt +1 -1
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/_version.py +2 -2
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/pz.py +2 -2
- legend_dataflow_scripts-0.1.4/src/legenddataflowscripts/par/geds/hit/aoe.py +326 -0
- legend_dataflow_scripts-0.1.4/src/legenddataflowscripts/par/geds/hit/lq.py +335 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/hit/qc.py +149 -102
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/__init__.py +2 -0
- legend_dataflow_scripts-0.1.4/src/legenddataflowscripts/utils/plot_dict.py +13 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/workflow/__init__.py +2 -0
- legend_dataflow_scripts-0.1.2/src/legenddataflowscripts/par/geds/hit/aoe.py +0 -245
- legend_dataflow_scripts-0.1.2/src/legenddataflowscripts/par/geds/hit/lq.py +0 -213
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/LICENSE +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/README.md +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/setup.cfg +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/dependency_links.txt +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/entry_points.txt +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/not-zip-safe +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legend_dataflow_scripts.egg-info/top_level.txt +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/dplms.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/eopt.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/evtsel.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/nopt.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/svm.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/dsp/svm_build.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/hit/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/par/geds/hit/ecal.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/tier/__init__.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/tier/dsp.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/tier/hit.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/alias_table.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/cfgtools.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/convert_np.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/log.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/utils/pulser_removal.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/workflow/execenv.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/workflow/filedb.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/workflow/pre_compile_catalog.py +0 -0
- {legend_dataflow_scripts-0.1.2 → legend_dataflow_scripts-0.1.4}/src/legenddataflowscripts/workflow/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: legend-dataflow-scripts
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Python package for the processing scripts for LEGEND-200 data
|
|
5
5
|
Author-email: George Marshall <ggmarsh@uw.edu>, Luigi Pertoldi <gipert@pm.me>
|
|
6
6
|
Maintainer: The LEGEND Collaboration
|
|
@@ -23,7 +23,7 @@ Requires-Dist: pygama>=2.1
|
|
|
23
23
|
Requires-Dist: dspeed>=1.6
|
|
24
24
|
Requires-Dist: pylegendmeta>=1.2.5
|
|
25
25
|
Requires-Dist: legend-pydataobj>=1.11
|
|
26
|
-
Requires-Dist: legend-daq2lh5>=1.
|
|
26
|
+
Requires-Dist: legend-daq2lh5>=1.6.1
|
|
27
27
|
Requires-Dist: pip
|
|
28
28
|
Provides-Extra: test
|
|
29
29
|
Requires-Dist: legend-dataflow-scripts; extra == "test"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: legend-dataflow-scripts
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Python package for the processing scripts for LEGEND-200 data
|
|
5
5
|
Author-email: George Marshall <ggmarsh@uw.edu>, Luigi Pertoldi <gipert@pm.me>
|
|
6
6
|
Maintainer: The LEGEND Collaboration
|
|
@@ -23,7 +23,7 @@ Requires-Dist: pygama>=2.1
|
|
|
23
23
|
Requires-Dist: dspeed>=1.6
|
|
24
24
|
Requires-Dist: pylegendmeta>=1.2.5
|
|
25
25
|
Requires-Dist: legend-pydataobj>=1.11
|
|
26
|
-
Requires-Dist: legend-daq2lh5>=1.
|
|
26
|
+
Requires-Dist: legend-daq2lh5>=1.6.1
|
|
27
27
|
Requires-Dist: pip
|
|
28
28
|
Provides-Extra: test
|
|
29
29
|
Requires-Dist: legend-dataflow-scripts; extra == "test"
|
|
@@ -33,6 +33,7 @@ src/legenddataflowscripts/utils/alias_table.py
|
|
|
33
33
|
src/legenddataflowscripts/utils/cfgtools.py
|
|
34
34
|
src/legenddataflowscripts/utils/convert_np.py
|
|
35
35
|
src/legenddataflowscripts/utils/log.py
|
|
36
|
+
src/legenddataflowscripts/utils/plot_dict.py
|
|
36
37
|
src/legenddataflowscripts/utils/pulser_removal.py
|
|
37
38
|
src/legenddataflowscripts/workflow/__init__.py
|
|
38
39
|
src/legenddataflowscripts/workflow/execenv.py
|
|
@@ -181,14 +181,14 @@ def par_geds_dsp_pz() -> None:
|
|
|
181
181
|
|
|
182
182
|
plot_dict = tau.plot_waveforms_after_correction(
|
|
183
183
|
tb_data,
|
|
184
|
-
kwarg_dict("wf_pz_field", "wf_pz"),
|
|
184
|
+
kwarg_dict.get("wf_pz_field", "wf_pz"),
|
|
185
185
|
norm_param=kwarg_dict.get("norm_param", "pz_mean"),
|
|
186
186
|
xlim=[0, len(tb_data[kwarg_dict["wf_field"]]["values"].nda[0])],
|
|
187
187
|
)
|
|
188
188
|
|
|
189
189
|
zoomed = tau.plot_waveforms_after_correction(
|
|
190
190
|
tb_data,
|
|
191
|
-
kwarg_dict("wf_pz_field", "wf_pz"),
|
|
191
|
+
kwarg_dict.get("wf_pz_field", "wf_pz"),
|
|
192
192
|
norm_param=kwarg_dict.get("norm_param", "pz_mean"),
|
|
193
193
|
xlim=[400, len(tb_data[kwarg_dict["wf_field"]]["values"].nda[0])],
|
|
194
194
|
ylim=[0.8, 1.1],
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import copy
|
|
5
|
+
import logging
|
|
6
|
+
import pickle as pkl
|
|
7
|
+
import re
|
|
8
|
+
import time
|
|
9
|
+
import warnings
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from dbetto import TextDB
|
|
14
|
+
from dbetto.catalog import Props
|
|
15
|
+
from pygama.pargen.AoE_cal import * # noqa: F403
|
|
16
|
+
from pygama.pargen.AoE_cal import CalAoE
|
|
17
|
+
from pygama.pargen.utils import load_data
|
|
18
|
+
|
|
19
|
+
from ....utils import (
|
|
20
|
+
build_log,
|
|
21
|
+
convert_dict_np_to_float,
|
|
22
|
+
fill_plot_dict,
|
|
23
|
+
get_pulser_mask,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
log = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
warnings.filterwarnings(action="ignore", category=RuntimeWarning)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_results_dict(aoe_class):
|
|
32
|
+
result_dict = {}
|
|
33
|
+
for tstamp in aoe_class.low_side_sfs_by_run:
|
|
34
|
+
result_dict[tstamp] = {
|
|
35
|
+
"cal_energy_param": aoe_class.cal_energy_param,
|
|
36
|
+
"dt_param": aoe_class.dt_param,
|
|
37
|
+
"rt_correction": aoe_class.dt_corr,
|
|
38
|
+
"1000-1300keV": aoe_class.timecorr_df.to_dict("index"),
|
|
39
|
+
"correction_fit_results": aoe_class.energy_corr_res_dict,
|
|
40
|
+
"low_cut": aoe_class.low_cut_val,
|
|
41
|
+
"high_cut": aoe_class.high_cut_val,
|
|
42
|
+
"low_side_sfs": aoe_class.low_side_sfs.to_dict("index"),
|
|
43
|
+
"2_side_sfs": aoe_class.two_side_sfs.to_dict("index"),
|
|
44
|
+
"low_side_sfs_by_run": aoe_class.low_side_sfs_by_run[tstamp].to_dict(
|
|
45
|
+
"index"
|
|
46
|
+
),
|
|
47
|
+
"2_side_sfs_by_run": aoe_class.two_side_sfs_by_run[tstamp].to_dict("index"),
|
|
48
|
+
}
|
|
49
|
+
return result_dict
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def run_aoe_calibration(
|
|
53
|
+
data,
|
|
54
|
+
cal_dicts,
|
|
55
|
+
results_dicts,
|
|
56
|
+
object_dicts,
|
|
57
|
+
plot_dicts,
|
|
58
|
+
config,
|
|
59
|
+
debug_mode=False,
|
|
60
|
+
):
|
|
61
|
+
if isinstance(config, str | list):
|
|
62
|
+
config = Props.read_from(config)
|
|
63
|
+
|
|
64
|
+
if config.get("run_aoe", True) is True:
|
|
65
|
+
if "plot_options" in config:
|
|
66
|
+
for field, item in config["plot_options"].items():
|
|
67
|
+
config["plot_options"][field]["function"] = eval(item["function"])
|
|
68
|
+
|
|
69
|
+
if "dt_cut" in config and config["dt_cut"] is not None:
|
|
70
|
+
cut_dict = config["dt_cut"]["cut"]
|
|
71
|
+
for tstamp in cal_dicts:
|
|
72
|
+
cal_dicts[tstamp].update(cut_dict)
|
|
73
|
+
|
|
74
|
+
exp = cut_dict[next(iter(cut_dict))]["expression"]
|
|
75
|
+
for key in cut_dict[next(iter(cut_dict))]["parameters"]:
|
|
76
|
+
exp = re.sub(f"(?<![a-zA-Z0-9]){key}(?![a-zA-Z0-9])", f"@{key}", exp)
|
|
77
|
+
data[next(iter(cut_dict))] = data.eval(
|
|
78
|
+
exp, local_dict=cut_dict[next(iter(cut_dict))]["parameters"]
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
eres = copy.deepcopy(
|
|
83
|
+
results_dicts[next(iter(results_dicts))]["partition_ecal"][
|
|
84
|
+
config["cal_energy_param"]
|
|
85
|
+
]["eres_linear"]
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def eres_func(x):
|
|
89
|
+
return eval(eres["expression"], dict(x=x, **eres["parameters"]))
|
|
90
|
+
|
|
91
|
+
if np.isnan(eres_func(2000)):
|
|
92
|
+
raise RuntimeError
|
|
93
|
+
except (KeyError, RuntimeError):
|
|
94
|
+
try:
|
|
95
|
+
eres = copy.deepcopy(
|
|
96
|
+
results_dicts[next(iter(results_dicts))]["ecal"][
|
|
97
|
+
config["cal_energy_param"]
|
|
98
|
+
]["eres_linear"]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def eres_func(x):
|
|
102
|
+
return eval(eres["expression"], dict(x=x, **eres["parameters"]))
|
|
103
|
+
|
|
104
|
+
except KeyError:
|
|
105
|
+
|
|
106
|
+
def eres_func(x):
|
|
107
|
+
return x * np.nan
|
|
108
|
+
|
|
109
|
+
data["AoE_Uncorr"] = (
|
|
110
|
+
data[config["current_param"]] / data[config["energy_param"]]
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
start = time.time()
|
|
114
|
+
log.info("calibrating A/E")
|
|
115
|
+
|
|
116
|
+
aoe = CalAoE(
|
|
117
|
+
cal_dicts=cal_dicts,
|
|
118
|
+
cal_energy_param=config["cal_energy_param"],
|
|
119
|
+
eres_func=eres_func,
|
|
120
|
+
pdf=eval(config.get("pdf", "aoe_peak")),
|
|
121
|
+
mean_func=eval(config.get("mean_func", "Pol1")),
|
|
122
|
+
sigma_func=eval(config.get("sigma_func", "SigmaFit")),
|
|
123
|
+
selection_string=f"{config['cut_field']}&(~is_pulser)",
|
|
124
|
+
dt_corr=config.get("dt_corr", False),
|
|
125
|
+
dep_correct=config.get("dep_correct", False),
|
|
126
|
+
dt_cut=config.get("dt_cut", None),
|
|
127
|
+
dt_param=config.get("dt_param", 3),
|
|
128
|
+
high_cut_val=config.get("high_cut_val", 3),
|
|
129
|
+
compt_bands_width=config.get("debug_mode", 20),
|
|
130
|
+
debug_mode=debug_mode | config.get("debug_mode", False),
|
|
131
|
+
)
|
|
132
|
+
aoe.update_cal_dicts(
|
|
133
|
+
{
|
|
134
|
+
"AoE_Uncorr": {
|
|
135
|
+
"expression": f"{config['current_param']}/{config['energy_param']}",
|
|
136
|
+
"parameters": {},
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
aoe.calibrate(data, "AoE_Uncorr")
|
|
141
|
+
|
|
142
|
+
msg = f"A/E calibration completed in {time.time() - start:.2f} seconds"
|
|
143
|
+
log.info(msg)
|
|
144
|
+
|
|
145
|
+
out_dict = get_results_dict(aoe)
|
|
146
|
+
aoe_plot_dict = fill_plot_dict(aoe, data, config.get("plot_options", None))
|
|
147
|
+
|
|
148
|
+
aoe.pdf = aoe.pdf.name
|
|
149
|
+
# need to change eres func as can't pickle lambdas
|
|
150
|
+
try:
|
|
151
|
+
aoe.eres_func = results_dicts[next(iter(results_dicts))]["partition_ecal"][
|
|
152
|
+
config["cal_energy_param"]
|
|
153
|
+
]["eres_linear"]
|
|
154
|
+
except KeyError:
|
|
155
|
+
aoe.eres_func = {}
|
|
156
|
+
else:
|
|
157
|
+
out_dict = dict.fromkeys(cal_dicts)
|
|
158
|
+
aoe_plot_dict = {}
|
|
159
|
+
aoe = None
|
|
160
|
+
|
|
161
|
+
out_result_dicts = {}
|
|
162
|
+
for tstamp, result_dict in results_dicts.items():
|
|
163
|
+
out_result_dicts[tstamp] = dict(**result_dict, aoe=out_dict[tstamp])
|
|
164
|
+
|
|
165
|
+
out_object_dicts = {}
|
|
166
|
+
for tstamp, object_dict in object_dicts.items():
|
|
167
|
+
out_object_dicts[tstamp] = dict(**object_dict, aoe=aoe)
|
|
168
|
+
|
|
169
|
+
common_dict = (
|
|
170
|
+
aoe_plot_dict.pop("common") if "common" in list(aoe_plot_dict) else None
|
|
171
|
+
)
|
|
172
|
+
out_plot_dicts = {}
|
|
173
|
+
for tstamp, plot_dict in plot_dicts.items():
|
|
174
|
+
if "common" in list(plot_dict) and common_dict is not None:
|
|
175
|
+
plot_dict["common"].update(common_dict)
|
|
176
|
+
elif common_dict is not None:
|
|
177
|
+
plot_dict["common"] = common_dict
|
|
178
|
+
plot_dict.update({"aoe": aoe_plot_dict})
|
|
179
|
+
out_plot_dicts[tstamp] = plot_dict
|
|
180
|
+
|
|
181
|
+
return cal_dicts, out_result_dicts, out_object_dicts, out_plot_dicts
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def par_geds_hit_aoe() -> None:
|
|
185
|
+
argparser = argparse.ArgumentParser()
|
|
186
|
+
argparser.add_argument("files", help="files", nargs="*", type=str)
|
|
187
|
+
argparser.add_argument(
|
|
188
|
+
"--pulser-file", help="pulser_file", type=str, required=False
|
|
189
|
+
)
|
|
190
|
+
argparser.add_argument(
|
|
191
|
+
"--tcm-filelist", help="tcm_filelist", type=str, required=False
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
argparser.add_argument("--ecal-file", help="ecal_file", type=str, required=True)
|
|
195
|
+
argparser.add_argument("--eres-file", help="eres_file", type=str, required=True)
|
|
196
|
+
argparser.add_argument("--inplots", help="in_plot_path", type=str, required=False)
|
|
197
|
+
|
|
198
|
+
argparser.add_argument("--configs", help="configs", type=str, required=True)
|
|
199
|
+
argparser.add_argument("--log", help="log_file", type=str)
|
|
200
|
+
|
|
201
|
+
argparser.add_argument("--datatype", help="Datatype", type=str, required=True)
|
|
202
|
+
argparser.add_argument("--timestamp", help="Timestamp", type=str, required=True)
|
|
203
|
+
argparser.add_argument("--channel", help="Channel", type=str, required=True)
|
|
204
|
+
argparser.add_argument("--table-name", help="table name", type=str, required=True)
|
|
205
|
+
|
|
206
|
+
argparser.add_argument("--plot-file", help="plot_file", type=str, required=False)
|
|
207
|
+
argparser.add_argument("--hit-pars", help="hit_pars", type=str)
|
|
208
|
+
argparser.add_argument("--aoe-results", help="aoe_results", type=str)
|
|
209
|
+
|
|
210
|
+
argparser.add_argument("-d", "--debug", help="debug_mode", action="store_true")
|
|
211
|
+
args = argparser.parse_args()
|
|
212
|
+
|
|
213
|
+
configs = TextDB(args.configs, lazy=True).on(args.timestamp, system=args.datatype)
|
|
214
|
+
config_dict = configs["snakemake_rules"]["pars_hit_aoecal"]
|
|
215
|
+
|
|
216
|
+
build_log(config_dict, args.log)
|
|
217
|
+
|
|
218
|
+
channel_dict = config_dict["inputs"]["aoecal_config"][args.channel]
|
|
219
|
+
kwarg_dict = Props.read_from(channel_dict)
|
|
220
|
+
|
|
221
|
+
ecal_dict = Props.read_from(args.ecal_file)
|
|
222
|
+
cal_dict = ecal_dict["pars"]
|
|
223
|
+
eres_dict = ecal_dict["results"]["ecal"]
|
|
224
|
+
|
|
225
|
+
with Path(args.eres_file).open("rb") as o:
|
|
226
|
+
object_dict = pkl.load(o)
|
|
227
|
+
|
|
228
|
+
if args.inplots:
|
|
229
|
+
with Path(args.inplots).open("rb") as r:
|
|
230
|
+
out_plot_dict = pkl.load(r)
|
|
231
|
+
else:
|
|
232
|
+
out_plot_dict = {}
|
|
233
|
+
|
|
234
|
+
with Path(args.files[0]).open() as f:
|
|
235
|
+
files = sorted(f.read().splitlines())
|
|
236
|
+
|
|
237
|
+
if kwarg_dict["run_aoe"] is True:
|
|
238
|
+
params = [
|
|
239
|
+
kwarg_dict["current_param"],
|
|
240
|
+
"tp_0_est",
|
|
241
|
+
"tp_99",
|
|
242
|
+
kwarg_dict["energy_param"],
|
|
243
|
+
kwarg_dict["cal_energy_param"],
|
|
244
|
+
kwarg_dict["cut_field"],
|
|
245
|
+
"timestamp",
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
if "dt_param" in kwarg_dict:
|
|
249
|
+
params += kwarg_dict["dt_param"]
|
|
250
|
+
else:
|
|
251
|
+
params.append("dt_eff")
|
|
252
|
+
|
|
253
|
+
if "dt_cut" in kwarg_dict and kwarg_dict["dt_cut"] is not None:
|
|
254
|
+
cal_dict.update(kwarg_dict["dt_cut"]["cut"])
|
|
255
|
+
params.append(kwarg_dict["dt_cut"]["out_param"])
|
|
256
|
+
|
|
257
|
+
# load data in
|
|
258
|
+
data, threshold_mask = load_data(
|
|
259
|
+
files,
|
|
260
|
+
args.table_name,
|
|
261
|
+
cal_dict,
|
|
262
|
+
params=params,
|
|
263
|
+
threshold=kwarg_dict["threshold"],
|
|
264
|
+
return_selection_mask=True,
|
|
265
|
+
)
|
|
266
|
+
msg = f"Loaded {len(data)} events"
|
|
267
|
+
log.info(msg)
|
|
268
|
+
|
|
269
|
+
mask = get_pulser_mask(
|
|
270
|
+
pulser_file=args.pulser_file,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
data["is_pulser"] = mask[threshold_mask]
|
|
274
|
+
|
|
275
|
+
msg = f"{len(data.query('~is_pulser'))} non pulser events"
|
|
276
|
+
log.info(msg)
|
|
277
|
+
|
|
278
|
+
with Path(args.files[0]).open() as f:
|
|
279
|
+
files = f.read().splitlines()
|
|
280
|
+
files = sorted(files)
|
|
281
|
+
|
|
282
|
+
data["run_timestamp"] = args.timestamp
|
|
283
|
+
|
|
284
|
+
cal_dict, results_dicts, object_dicts, plot_dicts = run_aoe_calibration(
|
|
285
|
+
data,
|
|
286
|
+
{args.timestamp: cal_dict},
|
|
287
|
+
{args.timestamp: eres_dict},
|
|
288
|
+
{args.timestamp: object_dict},
|
|
289
|
+
{args.timestamp: out_plot_dict},
|
|
290
|
+
kwarg_dict,
|
|
291
|
+
debug_mode=args.debug,
|
|
292
|
+
)
|
|
293
|
+
cal_dict = cal_dict[args.timestamp]
|
|
294
|
+
results_dict = results_dicts[args.timestamp]
|
|
295
|
+
aoe = object_dicts[args.timestamp]
|
|
296
|
+
plot_dict = plot_dicts[args.timestamp]
|
|
297
|
+
else:
|
|
298
|
+
aoe = None
|
|
299
|
+
plot_dict = out_plot_dict
|
|
300
|
+
|
|
301
|
+
if args.plot_file:
|
|
302
|
+
common_dict = plot_dict.pop("common") if "common" in list(plot_dict) else None
|
|
303
|
+
out_plot_dict.update({"aoe": plot_dict})
|
|
304
|
+
|
|
305
|
+
if "common" in list(out_plot_dict) and common_dict is not None:
|
|
306
|
+
out_plot_dict["common"].update(common_dict)
|
|
307
|
+
elif common_dict is not None:
|
|
308
|
+
out_plot_dict["common"] = common_dict
|
|
309
|
+
|
|
310
|
+
Path(args.plot_file).parent.mkdir(parents=True, exist_ok=True)
|
|
311
|
+
with Path(args.plot_file).open("wb") as w:
|
|
312
|
+
pkl.dump(out_plot_dict, w, protocol=pkl.HIGHEST_PROTOCOL)
|
|
313
|
+
|
|
314
|
+
Path(args.hit_pars).parent.mkdir(parents=True, exist_ok=True)
|
|
315
|
+
final_hit_dict = {
|
|
316
|
+
"pars": {"operations": cal_dict},
|
|
317
|
+
"results": dict(**ecal_dict["results"], aoe=results_dict),
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
final_hit_dict = convert_dict_np_to_float(final_hit_dict)
|
|
321
|
+
|
|
322
|
+
Props.write_to(args.hit_pars, final_hit_dict)
|
|
323
|
+
|
|
324
|
+
Path(args.aoe_results).parent.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
with Path(args.aoe_results).open("wb") as w:
|
|
326
|
+
pkl.dump(dict(**object_dict, aoe=aoe), w, protocol=pkl.HIGHEST_PROTOCOL)
|