Belle II Software development
caf_ecl_time_crate.py
1
8
9"""ECL timing calibration that performs the crate calibrations, one for each physics run."""
10
11from prompt import CalibrationSettings
12from reconstruction import prepare_cdst_analysis
13
14
21
22
24settings = CalibrationSettings(
25 name="ECL crate time calibrations",
26 expert_username="ehill",
27 description=__doc__,
28 input_data_formats=["cdst"],
29 input_data_names=["bhabha_combined_calib"],
30 # input_data_filters={
31 # "bhabha_combined_calib": [
32 # input_data_filters["Data Tag"]["bhabha_combined_calib"],
33 # input_data_filters["Beam Energy"]["4S"],
34 # input_data_filters["Beam Energy"]["Continuum"],
35 # input_data_filters["Beam Energy"]["Scan"],
36 # input_data_filters["Data Quality Tag"]["Good"],
37 # input_data_filters["Run Type"]["physics"],
38 # input_data_filters["Magnet"]["On"],
39 # ]
40 # },
41 depends_on=[],
42)
43
44
45
46
47
56
57
58def get_calibrations(input_data, **kwargs):
59 """
60 Parameters:
61 input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
62 Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
63 assigning to calibration.files_to_iov
64
65 **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
66 backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
67 release explicitly if you want to.
68
69 Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
70 correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
71
72 Returns:
73 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
74 """
75 import basf2
76 # Set up config options
77
78 # In this script we want to use one sources of input data.
79 # Get the input files from the input_data variable
80 # The input data should be the bhabha skim
81 file_to_iov_physics = input_data["bhabha_combined_calib"]
82
83 # We might have requested an enormous amount of data across a run range.
84 # There's a LOT more files than runs!
85 # Lets set some limits because this calibration doesn't need that much to run.
86 max_files_per_run = 26
87
88 # We filter addition files if there are more than [max_files_per_run] files per run.
89 # The input data files are sorted alphabetically by b2caf-prompt-run
90 # already. This procedure respects that ordering
91 from prompt.utils import filter_by_max_files_per_run
92
93 reduced_file_to_iov_physics = filter_by_max_files_per_run(
94 file_to_iov_physics, max_files_per_run
95 )
96 input_files_physics = list(reduced_file_to_iov_physics.keys())
97 basf2.B2INFO(
98 f"Total number of files actually used as input = {len(input_files_physics)}"
99 )
100
101
102 from basf2 import register_module, create_path
103 from ROOT import Belle2
104 from caf.framework import Collection
105
106
108 root_input = register_module("RootInput")
109 rec_path_bhabha = create_path()
110 rec_path_bhabha.add_module(root_input)
111 if "Gearbox" not in rec_path_bhabha:
112 rec_path_bhabha.add_module("Gearbox")
113 if "Geometry" not in rec_path_bhabha:
114 rec_path_bhabha.add_module("Geometry", useDB=True)
115
116 prepare_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
117
118 # ====================================================
119 t0BiasCorrection = -0.9 # Correct for the CDC t0 bias
120 # ====================================================
121
122 col_bhabha = register_module("ECLBhabhaTCollector")
123 col_bhabha.param("timeAbsMax", 250)
124 col_bhabha.param("minCrystal", 1)
125 col_bhabha.param("maxCrystal", 8736)
126 col_bhabha.param("saveTree", False)
127 col_bhabha.param("hadronEventT0_TO_bhabhaEventT0_correction", t0BiasCorrection)
128
129 eclTCol = Collection(
130 collector=col_bhabha,
131 input_files=input_files_physics,
132 pre_collector_path=rec_path_bhabha,
133 )
134
135
137
139
140 # Define the CAF algorithm arguments
141 # Set the cellIDLo to be larger than cellIDHi so that no crystal
142 # calibrations will be performed.
143 eclTAlg.cellIDLo = 3
144 eclTAlg.cellIDHi = 2
145 eclTAlg.debugOutput = True
146 eclTAlg.meanCleanRebinFactor = 3
147 eclTAlg.meanCleanCutMinFactor = 0.3
148 eclTAlg.debugFilenameBase = "eclBhabhaTAlgorithm"
149
150
152
153 from caf.framework import Calibration
154
155 cal_test = Calibration("ECLcrateTimeCalibration_physics")
156 cal_test.add_collection(name="bhabha", collection=eclTCol)
157 cal_test.algorithms = [eclTAlg]
158
159 # Here we set the AlgorithmStrategy for our algorithm
160 from caf.strategies import SimpleRunByRun
161
162 # The SimpleRunByRun strategy executes your algorithm over runs
163 # individually to give you payloads for each one (if successful)
164 # It will not do any merging of runs which didn't contain enough data.
165 # So failure is expected if your algorithm requires a large amount of data compared to run length.
166 # You should only use granularity='run' for the collector when using this strategy.
167
168 cal_test.strategies = SimpleRunByRun
169
170 # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
171 # So we don't bother setting them.
172
173 # You must return all calibrations you want to run in the prompt process, even if it's only one
174 return [cal_test]
175
176
177
Calibrate ecl crystals using bhabha events.