Belle II Software  release-08-01-10
caf_ecl_autocovariance.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """ECL Autocovariance."""
12 
13 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
14 from caf import strategies
15 
16 # --------------------------------------------------------------
17 # ..Tell the automated script some required details
18 settings = CalibrationSettings(
19  name="ecl_autocovariance",
20  expert_username="longos",
21  description=__doc__,
22  input_data_formats=["raw"],
23  input_data_names=["delayedbhabha_calib"],
24  input_data_filters={
25  "delayedbhabha_calib": [
26  INPUT_DATA_FILTERS["Data Tag"]["delayedbhabha_calib"],
27  INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
28  INPUT_DATA_FILTERS["Run Type"]["physics"],
29  INPUT_DATA_FILTERS["Magnet"]["On"]]},
30  depends_on=[],
31  expert_config={
32  "C1_lowestEnergyFraction": 0.75,
33  "C1_TotalCountsThreshold": 10000
34  })
35 
36 
37 # --------------------------------------------------------------
38 # ..The calibration functions
39 
40 
41 def get_calibrations(input_data, **kwargs):
42  import basf2
43  from ROOT import Belle2
44  from caf.utils import IoV
45  from caf.framework import Calibration
46 
47  # --------------------------------------------------------------
48  # ..delayed Bhabha
49 
50  # ..Input data
51  file_to_iov_delayed_Bhabha = input_data["delayedbhabha_calib"]
52  input_files = list(file_to_iov_delayed_Bhabha.keys())
53 
54  # ..Algorithm
56  expert_config = kwargs.get("expert_config")
57  algo_C1.setLowestEnergyFraction(expert_config["C1_lowestEnergyFraction"])
58  algo_C1.setTotalCountsThreshold(expert_config["C1_TotalCountsThreshold"])
59 
60  # ..The calibration
61  collector_C1 = basf2.register_module("eclAutocovarianceCalibrationC1Collector")
62 
63  cal_ecl_Auto_C1 = Calibration("ecl_Auto_C1",
64  collector=collector_C1,
65  algorithms=[algo_C1],
66  input_files=input_files, max_files_per_collector_job=4)
67  cal_ecl_Auto_C1.strategies = strategies.SequentialRunByRun
68 
69  # ..Add prepare_cdst_analysis to pre_collector_path
70  delayed_Bhabha_pre_path = basf2.create_path()
71  delayed_Bhabha_pre_path.add_module("RootInput", branchNames=["EventMetaData", "RawECLs"])
72  delayed_Bhabha_pre_path.add_module('ECLUnpacker')
73 
74  cal_ecl_Auto_C1.pre_collector_path = delayed_Bhabha_pre_path
75 
76  # ..Algorithm
78 
79  # ..The calibration
80  collector_C3 = basf2.register_module("eclAutocovarianceCalibrationC3Collector")
81 
82  cal_ecl_Auto_C3 = Calibration("ecl_Auto_C3",
83  collector=collector_C3,
84  algorithms=[algo_C3],
85  input_files=input_files, max_files_per_collector_job=4)
86  cal_ecl_Auto_C3.strategies = strategies.SequentialRunByRun
87 
88  cal_ecl_Auto_C3.pre_collector_path = delayed_Bhabha_pre_path
89 
90  cal_ecl_Auto_C3.depends_on(cal_ecl_Auto_C1)
91 
92  # ..Algorithm
94 
95  # ..The calibration
96  collector_C4 = basf2.register_module("eclAutocovarianceCalibrationC4Collector")
97 
98  cal_ecl_Auto_C4 = Calibration("ecl_Auto_C4",
99  collector=collector_C4,
100  algorithms=[algo_C4],
101  input_files=input_files, max_files_per_collector_job=4)
102  cal_ecl_Auto_C4.strategies = strategies.SequentialRunByRun
103 
104  cal_ecl_Auto_C4.pre_collector_path = delayed_Bhabha_pre_path
105 
106  cal_ecl_Auto_C4.depends_on(cal_ecl_Auto_C3)
107 
108  # --------------------------------------------------------------
109  # ..Force the output iovs to be open
110  requested_iov = kwargs.get("requested_iov", None)
111  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
112  for algorithm in cal_ecl_Auto_C1.algorithms:
113  algorithm.params = {"apply_iov": output_iov}
114  for algorithm in cal_ecl_Auto_C3.algorithms:
115  algorithm.params = {"apply_iov": output_iov}
116  for algorithm in cal_ecl_Auto_C4.algorithms:
117  algorithm.params = {"apply_iov": output_iov}
118 
119  # --------------------------------------------------------------
120  # ..Return the calibrations
121  return [cal_ecl_Auto_C1, cal_ecl_Auto_C3, cal_ecl_Auto_C4]
Calibrate covariance matrix for crystals using delayed Bhabha events.
Calibrate covariance matrix for crystals using delayed Bhabha events.
Calibrate covariance matrix for crystals using delayed Bhabha events.