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