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