Belle II Software  release-08-00-09
caf_ecl_WaveformTemplates.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """ECL waveform template calibration"""
12 
13 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
14 
15 # --------------------------------------------------------------
16 # ..Tell the automated script some required details
17 settings = CalibrationSettings(
18  name="ecl_WaveformTemplateShapeCalibration",
19  expert_username="longos",
20  description=__doc__,
21  input_data_formats=["cdst"],
22  input_data_names=["gamma_gamma_calib"],
23  input_data_filters={
24  "gamma_gamma_calib": [
25  INPUT_DATA_FILTERS["Data Tag"]["gamma_gamma_calib"],
26  INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
27  INPUT_DATA_FILTERS["Run Type"]["physics"],
28  INPUT_DATA_FILTERS["Magnet"]["On"]]},
29  depends_on=[],
30  expert_config={})
31 
32 
33 # --------------------------------------------------------------
34 # ..The calibration functions
35 
36 def get_calibrations(input_data, **kwargs):
37  import basf2
38  from ROOT import Belle2
39  from caf.utils import IoV
40  from caf.framework import Calibration
41 
42  # --------------------------------------------------------------
43  # ..gamma gamma
44 
45  # ..Input data
46  file_to_iov_gamma_gamma = input_data["gamma_gamma_calib"]
47  input_files = list(file_to_iov_gamma_gamma.keys())
48 
49  # ..Algorithm
51 
52  # ..The calibration
53  collector_C1 = basf2.register_module("eclWaveformTemplateCalibrationC1Collector")
54 
55  cal_ecl_Wave_C1 = Calibration(
56  "ecl_Wave_C1",
57  collector=collector_C1,
58  algorithms=[algo_C1],
59  input_files=input_files,
60  max_files_per_collector_job=4)
61 
62  # ..Add prepare_cdst_analysis to pre_collector_path
63  gamma_gamma_pre_path = basf2.create_path()
64  gamma_gamma_pre_path.add_module("RootInput", inputFileNames="", branchNames=["EventMetaData", "RawECLs"])
65  eclunpacker = basf2.register_module('ECLUnpacker')
66  gamma_gamma_pre_path.add_module(eclunpacker)
67 
68  cal_ecl_Wave_C1.pre_collector_path = gamma_gamma_pre_path
69 
70  calibrations_C2 = []
71  algos_C2 = []
72  algos_C3 = []
73  collectors_C2 = []
74 
75  batchsize = 100
76  nbatches = 88
77 
78  # keep option to run in parallel
79  for i in range(0, nbatches):
80 
81  lowLimit = (batchsize*i)+1
82 
83  highLimit = (batchsize*(i+1))
84 
85  if(highLimit > 8736):
86  highLimit = 8736
87 
88  print("lowLimit,highLimit", lowLimit, highLimit)
89 
90  # ..Algorithm
92  algos_C2[-1].setFirstCellID(lowLimit)
93  algos_C2[-1].setLastCellID(highLimit)
94 
96  algos_C3[-1].setFirstCellID(lowLimit)
97  algos_C3[-1].setLastCellID(highLimit)
98 
99  collectors_C2.append(basf2.register_module("eclWaveformTemplateCalibrationC2Collector"))
100  collectors_C2[-1].pre_collector_path = gamma_gamma_pre_path
101  collectors_C2[-1].param('MinCellID', lowLimit)
102  collectors_C2[-1].param('MaxCellID', highLimit)
103 
104  # ..The calibration
105  calibrations_C2.append(Calibration("ecl_Wave_C2_"+str(lowLimit)+"_"+str(highLimit),
106  collector=collectors_C2[-1],
107  algorithms=[algos_C2[-1],
108  algos_C3[-1]],
109  input_files=input_files,
110  max_files_per_collector_job=4))
111  calibrations_C2[-1].pre_collector_path = gamma_gamma_pre_path
112  calibrations_C2[-1].depends_on(cal_ecl_Wave_C1)
113 
114  # ..Algorithm
116  algo_C4.setFirstCellID(1)
117  algo_C4.setLastCellID(8736)
118 
119  # ..The calibration
120  cal_ecl_Wave_C4 = Calibration("ecl_Wave_C4",
121  collector="DummyCollector",
122  algorithms=[algo_C4],
123  input_files=input_files[:1],
124  )
125 
126  cal_ecl_Wave_C4.depends_on(cal_ecl_Wave_C1)
127  for cal in calibrations_C2:
128  cal_ecl_Wave_C4.depends_on(cal)
129 
130  # --------------------------------------------------------------
131  # ..Force the output iovs to be open
132  requested_iov = kwargs.get("requested_iov", None)
133  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
134  for algorithm in cal_ecl_Wave_C1.algorithms:
135  algorithm.params = {"apply_iov": output_iov}
136  for C2 in calibrations_C2:
137  for algorithm in C2.algorithms:
138  algorithm.params = {"apply_iov": output_iov}
139  for algorithm in cal_ecl_Wave_C4.algorithms:
140  algorithm.params = {"apply_iov": output_iov}
141 
142  # --------------------------------------------------------------
143  # ..Return the calibrations
144  calList = [cal_ecl_Wave_C1] + calibrations_C2 + [cal_ecl_Wave_C4]
145  return calList