Belle II Software  release-05-01-25
caf_beamspot.py
1 # -*- coding: utf-8 -*-
2 
3 """
4 Airflow script to perform BeamSpot calibration.
5 """
6 
7 from prompt import CalibrationSettings
8 
9 
10 settings = CalibrationSettings(
11  name="BeamSpot Calibrations",
12  expert_username="zlebcr",
13  description=__doc__,
14  input_data_formats=["cdst"],
15  input_data_names=["mumutight_calib"],
16  expert_config={
17  "outerLoss": "pow(rawTime - 2.0, 2) + 10 * pow(maxGap, 2)",
18  "innerLoss": "pow(rawTime - 0.5, 2) + 10 * pow(maxGap, 2)"},
19  depends_on=[])
20 
21 
22 
23 
24 def get_calibrations(input_data, **kwargs):
25  """
26  Parameters:
27  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
28  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
29  assigning to calibration.files_to_iov
30 
31  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
32  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
33  release explicitly if you want to.
34 
35  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
36  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
37 
38  Returns:
39  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
40  """
41  import basf2
42  # Set up config options
43 
44  # In this script we want to use one sources of input data.
45  # Get the input files from the input_data variable
46  file_to_iov_physics = input_data["mumutight_calib"]
47 
48  # We might have requested an enormous amount of data across a run range.
49  # There's a LOT more files than runs!
50  # Lets set some limits because this calibration doesn't need that much to run.
51  max_files_per_run = 1000000
52 
53  # We filter out any more than 100 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
54  # already. This procedure respects that ordering
55  from prompt.utils import filter_by_max_files_per_run
56 
57  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
58  input_files_physics = list(reduced_file_to_iov_physics.keys())
59  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
60 
61  # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
62  # IoV should be open ended. We could also use this as part of the input data selection in some way.
63  requested_iov = kwargs.get("requested_iov", None)
64 
65  from caf.utils import IoV
66  # The actual value our output IoV payload should have. Notice that we've set it open ended.
67  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
68 
69 
71 
72  from ROOT.Belle2 import BeamSpotAlgorithm
73  from basf2 import create_path, register_module
74  import modularAnalysis as ana
75 
76 
78 
79  from caf.framework import Calibration
80  from caf.strategies import SingleIOV
81 
82  # module to be run prior the collector
83  rec_path_1 = create_path()
84 
85  muSelection = '[p>1.0]'
86  muSelection += ' and abs(dz)<2.0 and abs(dr)<0.5'
87  muSelection += ' and nPXDHits >=1 and nSVDHits >= 8 and nCDCHits >= 20'
88  ana.fillParticleList('mu+:BS', muSelection, path=rec_path_1)
89  ana.reconstructDecay('Upsilon(4S):BS -> mu+:BS mu-:BS', '9.5<M<11.5', path=rec_path_1)
90 
91  collector_bs = register_module('BeamSpotCollector', Y4SPListName='Upsilon(4S):BS')
92  algorithm_bs = BeamSpotAlgorithm()
93  algorithm_bs.setOuterLoss(kwargs['expert_config']['outerLoss'])
94  algorithm_bs.setInnerLoss(kwargs['expert_config']['innerLoss'])
95 
96  calibration_bs = Calibration('BeamSpot',
97  collector=collector_bs,
98  algorithms=algorithm_bs,
99  input_files=input_files_physics,
100  pre_collector_path=rec_path_1)
101 
102  calibration_bs.strategies = SingleIOV
103 
104  # Do this for the default AlgorithmStrategy to force the output payload IoV
105  # It may be different if you are using another strategy like SequentialRunByRun
106  for algorithm in calibration_bs.algorithms:
107  algorithm.params = {"iov_coverage": output_iov}
108 
109  # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
110  # So we don't bother setting them.
111 
112  # You must return all calibrations you want to run in the prompt process, even if it's only one
113  return [calibration_bs]
114 
115 
prompt.utils
Definition: utils.py:1
Calibration
Definition: Calibration.py:1