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