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