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