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