Belle II Software development
caf_ecl_E.py
1
8
9"""ECL single crystal energy calibration using three control samples."""
10
11from prompt import CalibrationSettings, INPUT_DATA_FILTERS
12
13# --------------------------------------------------------------
14# ..Tell the automated script some required details
15settings = CalibrationSettings(
16 name="ecl_energy",
17 expert_username="hearty",
18 subsystem="ecl",
19 description=__doc__,
20 input_data_formats=["cdst"],
21 input_data_names=[
22 "bhabha_all_calib",
23 "gamma_gamma_calib",
24 "mumu_tight_or_highm_calib"],
25 input_data_filters={
26 "bhabha_all_calib": [
27 INPUT_DATA_FILTERS["Data Tag"]["bhabha_all_calib"],
28 INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
29 INPUT_DATA_FILTERS["Beam Energy"]["4S"],
30 INPUT_DATA_FILTERS["Run Type"]["physics"],
31 INPUT_DATA_FILTERS["Magnet"]["On"]],
32 "gamma_gamma_calib": [
33 INPUT_DATA_FILTERS["Data Tag"]["gamma_gamma_calib"],
34 INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
35 INPUT_DATA_FILTERS["Beam Energy"]["4S"],
36 INPUT_DATA_FILTERS["Run Type"]["physics"],
37 INPUT_DATA_FILTERS["Magnet"]["On"]],
38 "mumu_tight_or_highm_calib": [
39 INPUT_DATA_FILTERS["Data Tag"]["mumu_tight_or_highm_calib"],
40 INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
41 INPUT_DATA_FILTERS["Beam Energy"]["4S"],
42 INPUT_DATA_FILTERS["Run Type"]["physics"],
43 INPUT_DATA_FILTERS["Magnet"]["On"]]},
44 depends_on=[],
45 expert_config={"eCmsScale": 1.0, # Ecms/10.58, typically 0.9943 for offpeak
46 "ee5x5_min_entries": 100},
47 produced_payloads=["ECLCrystalEnergy", "ECLCrystalEnergyMuMu", "ECLCrystalEnergyGammaGamma", "ECLCrystalEnergyee5x5"])
48
49# --------------------------------------------------------------
50# ..Raise clustering seed threshold in ECLCRFinder
51
52
53def touch_CRFinder(path, new_seed):
54 import basf2
55 """
56 Speed up ECL clustering by increasing seed threshold
57 """
58 new_path = basf2.create_path()
59 found = False
60 for m in path.modules():
61 if str(m) != "ECLCRFinder": # search module by name
62 new_path.add_module(m)
63 else:
64 crfinder = basf2.register_module('ECLCRFinder')
65 crfinder.param('energyCut0', new_seed)
66 basf2.print_params(crfinder)
67 new_path.add_module(crfinder)
68 found = True
69 if not found:
70 raise KeyError("Could not find ECLCRFinder in path")
71 return new_path
72
73# --------------------------------------------------------------
74# ..Raise threshold in ECLWaveformFit
75
76
77def touch_WaveformFit(path, energy_threshold):
78 import basf2
79 """
80 Speed up ECL reconstruction by increasing energy threshold
81 """
82 new_path = basf2.create_path()
83 found = False
84 for m in path.modules():
85 if str(m) != "ECLWaveformFit": # search module by name
86 new_path.add_module(m)
87 else:
88 waveformfit = basf2.register_module('ECLWaveformFit')
89 waveformfit.param('EnergyThreshold', energy_threshold)
90 basf2.print_params(waveformfit)
91 new_path.add_module(waveformfit)
92 found = True
93 if not found:
94 raise KeyError("Could not find ECLWaveformFit in path")
95 return new_path
96
97# --------------------------------------------------------------
98# ..The calibration functions
99
100
101def get_calibrations(input_data, **kwargs):
102 import basf2
103 from ROOT import Belle2
104 from caf.utils import IoV
105 from caf.framework import Calibration
106 from reconstruction import prepare_cdst_analysis
107
108 # --------------------------------------------------------------
109 # ..Bhabha
110
111 # ..Input data
112 file_to_iov_bhabha = input_data["bhabha_all_calib"]
113 input_files_bhabha = list(file_to_iov_bhabha.keys())
114
115 # ..Algorithm
116 algo_ee5x5 = Belle2.ECL.eclee5x5Algorithm()
117 expert_config = kwargs.get("expert_config")
118 ee5x5minEntries = expert_config["ee5x5_min_entries"]
119 algo_ee5x5.setMinEntries(ee5x5minEntries)
120 algo_ee5x5.setPayloadName("ECLCrystalEnergy5x5")
121 algo_ee5x5.setStoreConst(True)
122
123 # ..The calibration
124 eclee5x5_collector = basf2.register_module("eclee5x5Collector")
125 eclee5x5_collector.param("thetaLabMinDeg", 17.)
126 eclee5x5_collector.param("thetaLabMaxDeg", 150.)
127 eclee5x5_collector.param("minE0", 0.45)
128 eclee5x5_collector.param("minE1", 0.40)
129 eclee5x5_collector.param("maxdThetaSum", 2.)
130 eclee5x5_collector.param("dPhiScale", 1.)
131 eclee5x5_collector.param("maxTime", 10.)
132 eclee5x5_collector.param("useCalDigits", False)
133 eclee5x5_collector.param("requireL1", False)
134 eclee5x5_collector.param("granularity", "all")
135
136 # ..Adjust the expected energies for offpeak calibration
137 eCmsScale = expert_config["eCmsScale"]
138 eclee5x5_collector.param("expectedEnergyScale", eCmsScale)
139
140 cal_ecl_ee5x5 = Calibration("ecl_ee5x5",
141 collector=eclee5x5_collector,
142 algorithms=[algo_ee5x5],
143 input_files=input_files_bhabha
144 )
145 cal_ecl_ee5x5.backend_args = {"request_memory": "4 GB"}
146
147 # ..Add prepare_cdst_analysis to pre_collector_path
148 ee5x5_pre_path = basf2.create_path()
149 prepare_cdst_analysis(ee5x5_pre_path, components=['ECL'])
150 new_threshold = 1.0 # GeV
151 ee5x5_pre_path = touch_CRFinder(ee5x5_pre_path, new_threshold)
152 waveform_threshold = 99. # GeV
153 ee5x5_pre_path = touch_WaveformFit(ee5x5_pre_path, waveform_threshold)
154 cal_ecl_ee5x5.pre_collector_path = ee5x5_pre_path
155
156 # --------------------------------------------------------------
157 # ..gamma gamma
158
159 # ..Input data
160 file_to_iov_gamma_gamma = input_data["gamma_gamma_calib"]
161 input_files_gamma_gamma = list(file_to_iov_gamma_gamma.keys())
162
163 # ..Algorithm
164 algo_gamma_gamma = Belle2.ECL.eclGammaGammaEAlgorithm()
165 algo_gamma_gamma.setOutputName("eclGammaGammaE_algorithm.root")
166 algo_gamma_gamma.setCellIDLo(1)
167 algo_gamma_gamma.setCellIDHi(8736)
168 algo_gamma_gamma.setMinEntries(150)
169 algo_gamma_gamma.setMaxIterations(10)
170 algo_gamma_gamma.setTRatioMin(0.45)
171 algo_gamma_gamma.setTRatioMax(0.70)
172 algo_gamma_gamma.setTRatioMinHiStat(0.70)
173 algo_gamma_gamma.setTRatioMaxHiStat(0.95)
174 algo_gamma_gamma.setUpperEdgeThresh(0.02)
175 algo_gamma_gamma.setPerformFits(True)
176 algo_gamma_gamma.setFindExpValues(False)
177 algo_gamma_gamma.setStoreConst(0)
178
179 # ..The calibration
180 eclGammaGamma_collector = basf2.register_module("eclGammaGammaECollector")
181 eclGammaGamma_collector.param("granularity", "all")
182 eclGammaGamma_collector.param("thetaLabMinDeg", 0.)
183 eclGammaGamma_collector.param("thetaLabMaxDeg", 180.)
184 eclGammaGamma_collector.param("minPairMass", 9.)
185 eclGammaGamma_collector.param("mindPhi", 179.)
186 eclGammaGamma_collector.param("maxTime", 999.)
187 eclGammaGamma_collector.param("measureTrueEnergy", False)
188 eclGammaGamma_collector.param("requireL1", False)
189
190 # ..Adjust the expected energies for offpeak calibration
191 eclGammaGamma_collector.param("expectedEnergyScale", eCmsScale)
192
193 cal_ecl_gamma_gamma = Calibration("ecl_gamma_gamma",
194 collector=eclGammaGamma_collector,
195 algorithms=[algo_gamma_gamma],
196 input_files=input_files_gamma_gamma
197 )
198
199 # ..Add prepare_cdst_analysis to pre_collector_path
200 gamma_gamma_pre_path = basf2.create_path()
201 prepare_cdst_analysis(gamma_gamma_pre_path, components=['ECL'])
202 new_threshold = 1.0 # GeV
203 gamma_gamma_pre_path = touch_CRFinder(gamma_gamma_pre_path, new_threshold)
204 waveform_threshold = 99. # GeV
205 gamma_gamma_pre_path = touch_WaveformFit(gamma_gamma_pre_path, waveform_threshold)
206 cal_ecl_gamma_gamma.pre_collector_path = gamma_gamma_pre_path
207
208 # --------------------------------------------------------------
209 # ..muon pair
210
211 # ..Input data
212 file_to_iov_mu_mu = input_data["mumu_tight_or_highm_calib"]
213 input_files_mu_mu = list(file_to_iov_mu_mu.keys())
214
215 # ..Algorithm
216 algo_mu_mu = Belle2.ECL.eclMuMuEAlgorithm()
217 algo_mu_mu.cellIDLo = 1
218 algo_mu_mu.cellIDHi = 8736
219 algo_mu_mu.minEntries = 150
220 algo_mu_mu.nToRebin = 1000
221 algo_mu_mu.tRatioMin = 0.05
222 algo_mu_mu.tRatioMax = 0.40
223 algo_mu_mu.lowerEdgeThresh = 0.10
224 algo_mu_mu.performFits = True
225 algo_mu_mu.findExpValues = False
226 algo_mu_mu.storeConst = 0
227
228 # ..The calibration
229 eclmumu_collector = basf2.register_module("eclMuMuECollector")
230 eclmumu_collector.param("granularity", "all")
231 eclmumu_collector.param("minPairMass", 9.0)
232 eclmumu_collector.param("minTrackLength", 30.)
233 eclmumu_collector.param("MaxNeighbourE", 0.010)
234 eclmumu_collector.param("thetaLabMinDeg", 17.)
235 eclmumu_collector.param("thetaLabMaxDeg", 150.)
236 eclmumu_collector.param("measureTrueEnergy", False)
237 eclmumu_collector.param("requireL1", False)
238 cal_ecl_mu_mu = Calibration(name="ecl_mu_mu", collector=eclmumu_collector, algorithms=algo_mu_mu, input_files=input_files_mu_mu)
239
240 # ..Need to include track extrapolation in the path before collector
241 ext_path = basf2.create_path()
242 prepare_cdst_analysis(ext_path, components=['ECL'])
243 ext_path.add_module("Ext", pdgCodes=[13])
244 new_threshold = 0.1 # GeV
245 ext_path = touch_CRFinder(ext_path, new_threshold)
246 waveform_threshold = 99. # GeV
247 ext_path = touch_WaveformFit(ext_path, waveform_threshold)
248 cal_ecl_mu_mu.pre_collector_path = ext_path
249
250 # --------------------------------------------------------------
251 # Include a merging Calibration that doesn't require input data but instead creates the final
252 # payload from the previous calibration payloads.
253
254 # We use a dummy collector that barely outputs any data and we set the input files to a single file so
255 # we spawn only one very fast job.
256 # It doesn't matter which input file we choose as the output is never used.
257
259 cal_ecl_merge = Calibration(name="ecl_merge", collector="DummyCollector", algorithms=[merging_alg],
260 input_files=input_files_mu_mu[:1])
261
262 # The important part is that we depend on all 3 previous calibrations
263 cal_ecl_merge.depends_on(cal_ecl_ee5x5)
264 cal_ecl_merge.depends_on(cal_ecl_gamma_gamma)
265 cal_ecl_merge.depends_on(cal_ecl_mu_mu)
266
267 # ..Uses cdst data so it requires prepare_cdst_analysis
268 ecl_merge_pre_path = basf2.create_path()
269 prepare_cdst_analysis(ecl_merge_pre_path, components=['ECL'])
270 new_threshold = 0.15 # GeV
271 ecl_merge_pre_path = touch_CRFinder(ecl_merge_pre_path, new_threshold)
272 waveform_threshold = 99. # GeV
273 ecl_merge_pre_path = touch_WaveformFit(ecl_merge_pre_path, waveform_threshold)
274 ecl_merge_pre_path.pre_collector_path = ecl_merge_pre_path
275
276 # --------------------------------------------------------------
277 # ..Force the output iovs to be open
278 requested_iov = kwargs.get("requested_iov", None)
279 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
280 for algorithm in cal_ecl_ee5x5.algorithms:
281 algorithm.params = {"apply_iov": output_iov}
282 for algorithm in cal_ecl_gamma_gamma.algorithms:
283 algorithm.params = {"apply_iov": output_iov}
284 for algorithm in cal_ecl_mu_mu.algorithms:
285 algorithm.params = {"apply_iov": output_iov}
286 for algorithm in cal_ecl_merge.algorithms:
287 algorithm.params = {"apply_iov": output_iov}
288
289 # --------------------------------------------------------------
290 # ..Return the calibrations
291 return [cal_ecl_ee5x5, cal_ecl_gamma_gamma, cal_ecl_mu_mu, cal_ecl_merge]
Calibrate ecl crystals using gamma pair events.
Calibrate ecl crystals using previously created payloads.
Calibrate ecl crystals using muon pair events.
Calibrate ecl crystals using Bhabha events.