Belle II Software  release-08-01-10
caf_ecl_time_validate_bhabha.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """ECL timing self-consistency check (not orthogonal events so not a great validation) with an bhabha event selection."""
12 
13 from prompt import CalibrationSettings
14 from reconstruction import prepare_user_cdst_analysis
15 
16 
17 
24 
25 
28 settings = CalibrationSettings(
29  name="ECL time validations - bhabha",
30  expert_username="ehill",
31  description=__doc__,
32  input_data_formats=["cdst"],
33  input_data_names=["bhabha_all_calib"],
34  input_data_filters={
35  "bhabha_all_calib": [
36  "bhabha_all_calib",
37  "4S",
38  "Continuum",
39  "Scan",
40  "Good",
41  "physics",
42  "On"]},
43  depends_on=[])
44 
45 
46 
47 
56 
57 
58 def get_calibrations(input_data, **kwargs):
59  """
60  Parameters:
61  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
62  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
63  assigning to calibration.files_to_iov
64 
65  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
66  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
67  release explicitly if you want to.
68 
69  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
70  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
71 
72  Returns:
73  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
74  """
75  import basf2
76  # Set up config options
77 
78  # In this script we want to use one sources of input data.
79  # Get the input files from the input_data variable
80  # The input data should be the bhabha skim
81  file_to_iov_physics = input_data["bhabha_all_calib"]
82 
83  max_events_per_run = 3000
84 
85  # We filter addition files if there are more than [max_events_per_run] files per run.
86  # The input data files are sorted alphabetically by b2caf-prompt-run
87  # already. This procedure respects that ordering
88  from prompt.utils import filter_by_max_events_per_run
89 
90  reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics, max_events_per_run)
91  input_files_physics = list(reduced_file_to_iov_physics.keys())
92  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
93 
94 
95  from basf2 import register_module, create_path
96  from ROOT import Belle2
97  from caf.framework import Collection
98 
99 
101  root_input = register_module('RootInput')
102  rec_path_bhabha = create_path()
103  rec_path_bhabha.add_module(root_input)
104  if 'Gearbox' not in rec_path_bhabha:
105  rec_path_bhabha.add_module('Gearbox')
106  if 'Geometry' not in rec_path_bhabha:
107  rec_path_bhabha.add_module('Geometry', useDB=True)
108 
109  prepare_user_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
110 
111  col_bhabha = register_module('eclBhabhaTimeCalibrationValidationCollector')
112  col_bhabha.param('timeAbsMax', 70)
113  col_bhabha.param('saveTree', False)
114 
115  eclValTCol = Collection(collector=col_bhabha,
116  input_files=input_files_physics,
117  pre_collector_path=rec_path_bhabha)
118 
119 
121 
122  # Give the collector name to the algorithm since one algorithm
123  # is used to analyse the results from several possible collectors
124  eclValTAlgBhabha = Belle2.ECL.eclTValidationAlgorithm("eclBhabhaTimeCalibrationValidationCollector")
125 
126  # Define the CAF algorithm arguments
127  # eclValTAlgBhabha.cellIDLo= 3
128  # eclValTAlgBhabha.cellIDHi = 2
129  eclValTAlgBhabha.meanCleanRebinFactor = 3
130  eclValTAlgBhabha.meanCleanCutMinFactor = 0.4
131  eclValTAlgBhabha.debugFilenameBase = "eclBhabhaTValidationAlgorithm"
132 
133 
135 
136  from caf.framework import Calibration
137 
138  valid_cal_bhabha = Calibration("ECLcrystalTimeCalValidation_bhabhaPhysics")
139  valid_cal_bhabha.add_collection(name="bhabha", collection=eclValTCol)
140  valid_cal_bhabha.algorithms = [eclValTAlgBhabha]
141 
142  # Here we set the AlgorithmStrategy for our algorithm
143  from caf.strategies import SingleIOV
144 
145  # The default value is SingleIOV, you don't have to set this, it is done automatically.
146  # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
147  # You can use granularity='run' or granularity='all' for the collector when using this strategy.
148 
149  valid_cal_bhabha.strategies = SingleIOV
150 
151 
153 
154  # You must return all calibrations you want to run in the prompt process, even if it's only one
155  return [valid_cal_bhabha]
Validate the ecl timing calibrations using a hadronic event selection.