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