Belle II Software  release-05-01-25
caf_ecl_time_crystal.py
1 # -*- coding: utf-8 -*-
2 
3 """ECL timing calibration that performs the crystal calibrations, one for the whole set of runs."""
4 
5 from prompt import CalibrationSettings
6 from reconstruction import *
7 
8 
9 
16 
17 
20 settings = CalibrationSettings(name="ECL crystal time calibrations",
21  expert_username="ehill",
22  description=__doc__,
23  input_data_formats=["cdst"],
24  input_data_names=["hlt_bhabha"],
25  depends_on=[])
26 
27 
28 
29 
38 
39 
40 def get_calibrations(input_data, **kwargs):
41  """
42  Parameters:
43  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
44  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
45  assigning to calibration.files_to_iov
46 
47  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
48  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
49  release explicitly if you want to.
50 
51  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
52  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
53 
54  Returns:
55  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
56  """
57  import basf2
58  # Set up config options
59 
60  # In this script we want to use one sources of input data.
61  # Get the input files from the input_data variable
62  # The input data should be the hlt bhabha skim
63  file_to_iov_physics = input_data["hlt_bhabha"]
64 
65  # Could remove this limit on the number of files per run but will just
66  # set to a large number in case we want to introduce it later.
67  # Also, keeping it allows the crystal calibrations code to look like the
68  # crates calibration code.
69  max_files_per_run = 1000
70 
71  # We filter addition files if there are more than [max_files_per_run] files per run.
72  # The input data files are sorted alphabetically by b2caf-prompt-run
73  # already. This procedure respects that ordering
74  from prompt.utils import filter_by_max_files_per_run
75 
76  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
77  input_files_physics = list(reduced_file_to_iov_physics.keys())
78  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
79 
80 
81  import basf2
82  from basf2 import register_module, create_path
83  import ROOT
84  from ROOT import Belle2
85  from ROOT.Belle2 import TestCalibrationAlgorithm
86  from caf.framework import Collection
87 
88 
90  root_input = register_module('RootInput')
91  rec_path_bhabha = create_path()
92  rec_path_bhabha.add_module(root_input)
93  if 'Gearbox' not in rec_path_bhabha:
94  rec_path_bhabha.add_module('Gearbox')
95  if 'Geometry' not in rec_path_bhabha:
96  rec_path_bhabha.add_module('Geometry', useDB=True)
97 
98  prepare_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
99 
100  col_bhabha = register_module('ECLBhabhaTCollector')
101  col_bhabha.param('timeAbsMax', 250)
102  col_bhabha.param('minCrystal', 1)
103  col_bhabha.param('maxCrystal', 8736)
104  col_bhabha.param('saveTree', False)
105 
106  eclTCol = Collection(collector=col_bhabha,
107  input_files=input_files_physics,
108  pre_collector_path=rec_path_bhabha,
109  )
110 
111 
113 
114  eclTAlgCrystals = Belle2.ECL.eclBhabhaTAlgorithm()
115 
116  # Define the CAF algorithm arguments
117  # Set the crateIDLo to be larger than crateIDHi so that no crate
118  # calibrations will be performed.
119  eclTAlgCrystals.crateIDLo = 3
120  eclTAlgCrystals.crateIDHi = 2
121  eclTAlgCrystals.debugOutput = True
122  eclTAlgCrystals.meanCleanRebinFactor = 3
123  eclTAlgCrystals.meanCleanCutMinFactor = 0.3
124  eclTAlgCrystals.debugFilenameBase = "eclBhabhaTAlgorithm"
125 
126 
128 
129  from caf.framework import Calibration
130 
131  cal_crystals = Calibration("ECLcrystalTimeCalibration_physics")
132  cal_crystals.add_collection(name="bhabha", collection=eclTCol)
133  cal_crystals.algorithms = [eclTAlgCrystals]
134 
135  # Here we set the AlgorithmStrategy for our algorithm
136  from caf.strategies import SingleIOV
137 
138  # The default value is SingleIOV, you don't have to set this, it is done automatically.
139  # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
140  # You can use granularity='run' or granularity='all' for the collector when using this strategy.
141 
142  cal_crystals.strategies = SingleIOV
143 
144 
146 
147  # You must return all calibrations you want to run in the prompt process, even if it's only one
148  return [cal_crystals]
149 
150 
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