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