Belle II Software  release-08-01-10
caf_ecl_time_shifts.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """Plot the crate time jumps"""
12 
13 from prompt import CalibrationSettings
14 from reconstruction import prepare_cdst_analysis
15 
16 
17 
24 
25 
28 settings = CalibrationSettings(name="ECL crystal time calibrations",
29  expert_username="ehill",
30  description=__doc__,
31  input_data_formats=["cdst", "mdst"],
32  input_data_names=["bhabha_all_calib"],
33  input_data_filters={"bhabha_all_calib": ["bhabha_all_calib"]},
34  depends_on=[])
35 
36 
37 
38 
39 
48 
49 
50 def get_calibrations(input_data, **kwargs):
51  """
52  Parameters:
53  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
54  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
55  assigning to calibration.files_to_iov
56 
57  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
58  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
59  release explicitly if you want to.
60 
61  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
62  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
63 
64  Returns:
65  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
66  """
67  # Set up config options
68 
69  # In this script we want to use one sources of input data.
70  # Get the input files from the input_data variable
71  # The input data should be the bhabha skim
72  file_to_iov_physics = input_data["bhabha_all_calib"]
73 
74  # Could remove this limit on the number of files per run but will just
75  # set to a large number in case we want to introduce it later.
76  # Also, keeping it allows the crystal calibrations code to look like the
77  # crates calibration code.
78  max_events_per_run = 1
79 
80  # We filter addition files if there are more than [max_events_per_run] events per run.
81  # I'm not sure but I hope this will speed up the collector stage.
82  # The input data files are sorted alphabetically by b2caf-prompt-run
83  # already. This procedure respects that ordering.
84  from prompt.utils import filter_by_max_events_per_run
85 
86  reduced_file_to_iov_physics = filter_by_max_events_per_run(file_to_iov_physics, max_events_per_run)
87  input_files_physics = list(reduced_file_to_iov_physics.keys())
88 
89 
90  from basf2 import register_module, create_path
91  from ROOT import Belle2
92  from caf.framework import Collection
93 
94 
96 
97  # Set up the collector but with only one event per file
98  root_input = register_module('RootInput', entrySequences=['0:{}'.format(1)])
99 
100  rec_path_bhabha = create_path()
101  rec_path_bhabha.add_module(root_input)
102  if 'Gearbox' not in rec_path_bhabha:
103  rec_path_bhabha.add_module('Gearbox')
104  if 'Geometry' not in rec_path_bhabha:
105  rec_path_bhabha.add_module('Geometry', useDB=True)
106 
107  prepare_cdst_analysis(rec_path_bhabha) # for new 2020 cdst format
108 
109  col_bhabha = register_module('eclTimeShiftsPlottingCollector')
110  eclTCol = Collection(collector=col_bhabha,
111  # input_files=input_files_first_last,
112  input_files=input_files_physics,
113  pre_collector_path=rec_path_bhabha,
114  )
115 
116 
119 
120  from caf.framework import Calibration
121 
122  tShifts_alg = Belle2.ECL.eclTimeShiftsAlgorithm()
123  tShifts_alg.debugFilenameBase = "eclTimeShiftsAlgorithm"
124 
125  # Define offsets so that the crysta+crate time plots are centred close to zero.
126  # tShifts_alg.timeShiftForPlotStyle = arr.array('d', [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
127  # 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \
128  # 0,0,0,0,0,0,0,0,0,0,0,0,0])
129  # tShifts_alg.timeShiftForPlotStyle = arr.array('d', [-29, -40, -9., -13, -35, -39, \
130  # -42, -24, -20, -22, -16, -23, -35, -31, -10, \
131  # -23, -47, -23, -21, -7., -31, -22, -30, -30, \
132  # -33, 5., 9., 12., -11, -19, -30, -29, -37, -19, \
133  # -20, -23, 37., 37., 57., 27., 53., 26., 69., 27., \
134  # 66., 73., 52., 42., 55., 71., 110, 52.])
135 
136  # +-17ns range allows for four 8ns crate time jumps in one direction
137  # +-10ns range allows for two 8ns crate time jumps in one direction
138 
139  tShifts_alg.crysCrateShift_min = -30 # in ns
140  tShifts_alg.crysCrateShift_max = 30 # in ns
141 
142  # Make the algorithm loop over the runs, not just the collector
143  # tShifts_alg.algorithmReadPayloads = True
144 
145 
148 
149  cal_ecl_timeShifts = Calibration(name="ecl_t_shifts", algorithms=[tShifts_alg],
150  input_files=input_files_physics)
151  cal_ecl_timeShifts.add_collection(name="bhabha", collection=eclTCol)
152  cal_ecl_timeShifts.save_payloads = False
153 
154 
156  return [cal_ecl_timeShifts]
Calibrate ecl crystals using previously created payloads.