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