Belle II Software  release-06-01-15
caf_boostvector.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """
12 Airflow script to perform BoostVector calibration.
13 """
14 
15 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
16 from prompt.calibrations.caf_beamspot import settings as beamspot
17 
18 
19 settings = CalibrationSettings(
20  name="BoostVector Calibrations",
21  expert_username="zlebcr",
22  description=__doc__,
23  input_data_formats=["cdst"],
24  input_data_names=["mumu_tight_or_highm_calib"],
25  input_data_filters={
26  "mumu_tight_or_highm_calib": [
27  INPUT_DATA_FILTERS["Data Tag"]["mumu_tight_or_highm_calib"],
28  INPUT_DATA_FILTERS["Run Type"]["physics"],
29  INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"],
30  INPUT_DATA_FILTERS["Magnet"]["On"]]},
31  expert_config={
32  "outerLoss": "pow(rawTime - 8.0, 2) + 10 * pow(maxGap, 2)",
33  "innerLoss": "pow(rawTime - 8.0, 2) + 10 * pow(maxGap, 2)"},
34  depends_on=[beamspot])
35 
36 
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  file_to_iov_physics = input_data["mumu_tight_or_highm_calib"]
62 
63  # We might have requested an enormous amount of data across a run range.
64  # There's a LOT more files than runs!
65  # Lets set some limits because this calibration doesn't need that much to run.
66  max_files_per_run = 1000000
67 
68  # We filter out any more than 100 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
69  # already. This procedure respects that ordering
70  from prompt.utils import filter_by_max_files_per_run
71 
72  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
73  input_files_physics = list(reduced_file_to_iov_physics.keys())
74  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
75 
76  # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
77  # IoV should be open ended. We could also use this as part of the input data selection in some way.
78  requested_iov = kwargs.get("requested_iov", None)
79 
80  from caf.utils import IoV
81  # The actual value our output IoV payload should have. Notice that we've set it open ended.
82  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
83 
84 
86 
87  from ROOT.Belle2 import BoostVectorAlgorithm
88  from basf2 import create_path, register_module
89  import modularAnalysis as ana
90  import vertex
91 
92 
94 
95  from caf.framework import Calibration
96  from caf.strategies import SingleIOV
97  from reconstruction import prepare_cdst_analysis
98 
99  # module to be run prior the collector
100  rec_path_1 = create_path()
101  prepare_cdst_analysis(path=rec_path_1, components=['CDC', 'ECL', 'KLM'])
102 
103  muSelection = '[p>1.0]'
104  muSelection += ' and abs(dz)<2.0 and abs(dr)<0.5'
105  muSelection += ' and nPXDHits >=1 and nSVDHits >= 8 and nCDCHits >= 20'
106  ana.fillParticleList('mu+:BV', muSelection, path=rec_path_1)
107  ana.reconstructDecay('Upsilon(4S):BV -> mu+:BV mu-:BV', '9.5<M<11.5', path=rec_path_1)
108  vertex.treeFit('Upsilon(4S):BV', updateAllDaughters=True, ipConstraint=True, path=rec_path_1)
109 
110  collector_bv = register_module('BoostVectorCollector', Y4SPListName='Upsilon(4S):BV')
111  algorithm_bv = BoostVectorAlgorithm()
112  algorithm_bv.setOuterLoss(kwargs['expert_config']['outerLoss'])
113  algorithm_bv.setInnerLoss(kwargs['expert_config']['innerLoss'])
114 
115  calibration_bv = Calibration('BoostVector',
116  collector=collector_bv,
117  algorithms=algorithm_bv,
118  input_files=input_files_physics,
119  pre_collector_path=rec_path_1)
120 
121  calibration_bv.strategies = SingleIOV
122 
123  # Do this for the default AlgorithmStrategy to force the output payload IoV
124  # It may be different if you are using another strategy like SequentialRunByRun
125  for algorithm in calibration_bv.algorithms:
126  algorithm.params = {"iov_coverage": output_iov}
127 
128  # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
129  # So we don't bother setting them.
130 
131  # You must return all calibrations you want to run in the prompt process, even if it's only one
132  return [calibration_bv]
133 
134 
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:223