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