3 """CDC tracking calibration. Performs the T0 determination using HLT skimmed raw data."""
5 from prompt
import CalibrationSettings
8 from random
import choice
12 settings = CalibrationSettings(name=
"CDC T0 Calibration with MP2",
13 expert_username=
"uchida",
15 input_data_formats=[
"raw"],
16 input_data_names=[
"hlt_mumu",
"hlt_hadron"],
21 from ROOT
import Belle2
23 bad_boards = [0, 35, 37, 77, 97, 115, 133, 193, 204, 218, 247]
28 result.append(label0.label())
31 result.append(label1.label())
35 def select_files(all_input_files, min_events, max_processed_events_per_file):
36 basf2.B2INFO(
"Attempting to choose a good subset of files")
40 while total_events < min_events:
43 if not all_input_files:
46 new_file_choice = choice(all_input_files)
48 all_input_files.remove(new_file_choice)
50 total_events_in_file = events_in_basf2_file(new_file_choice)
51 if not total_events_in_file:
54 events_contributed = 0
55 if total_events_in_file < max_processed_events_per_file:
57 events_contributed = total_events_in_file
59 events_contributed = max_processed_events_per_file
60 chosen_files.append(new_file_choice)
61 total_events += events_contributed
63 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
64 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
65 if total_events < min_events:
67 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
76 def get_calibrations(input_data, **kwargs):
82 file_to_iov_mumu = input_data[
"hlt_mumu"]
83 file_to_iov_hadron = input_data[
"hlt_hadron"]
84 file_to_iov_Bcosmics = input_data[
"Bcosmics"]
86 max_files_per_run = 10
87 min_events_per_file = 1000
89 max_events_per_calibration = 50000
90 max_events_per_calibration_xt = 1000000
91 max_events_per_file = 2000
92 max_events_per_file_had = 1000
94 reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, max_files_per_run, min_events_per_file)
95 input_files_mumu = list(reduced_file_to_iov_mumu.keys())
96 chosen_files_mumu = select_files(input_files_mumu[:], max_events_per_calibration, max_events_per_file)
97 chosen_files_mumu_xt = select_files(input_files_mumu[:], max_events_per_calibration_xt, max_events_per_file)
98 basf2.B2INFO(f
"Total number of hlt_mumu files actually used as input = {len(input_files_mumu)}")
100 reduced_file_to_iov_hadron = filter_by_max_files_per_run(file_to_iov_hadron, max_files_per_run, min_events_per_file)
101 input_files_hadron = list(reduced_file_to_iov_hadron.keys())
102 chosen_files_hadron = select_files(input_files_hadron[:], max_events_per_calibration, max_events_per_file_had)
103 chosen_files_hadron_xt = select_files(input_files_hadron[:], max_events_per_calibration_xt, max_events_per_file_had)
104 basf2.B2INFO(f
"Total number of hlt_hadron files actually used as input = {len(input_files_hadron)}")
107 requested_iov = kwargs.get(
"requested_iov",
None)
109 from caf.utils
import IoV
111 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
112 import millepede_calibration
as mp2
116 dbobjects=[
'CDCTimeZeros',
'CDCTimeWalks'],
118 mp2.make_collection(
'hlt_mumu', path=pre_collector(), tracks=[
'RecoTracks']),
119 mp2.make_collection(
'hlt_hadron', path=pre_collector(), tracks=[
'RecoTracks'])],
120 files=dict(hlt_mumu=chosen_files_mumu, hlt_hadron=chosen_files_hadron),
124 fixed=fix_tw_param(),
125 commands=[
'method inversion 1 0.1',
129 'scaleerrors 1. 1.'],
130 params=dict(minPValue=0., externalIterations=0),
133 basf2.set_module_parameters(cal1.collections[
'hlt_mumu'].pre_collector_path,
134 'RootInput', entrySequences=[f
'0:{max_events_per_file}'])
135 basf2.set_module_parameters(cal1.collections[
'hlt_hadron'].pre_collector_path,
136 'RootInput', entrySequences=[f
'0:{max_events_per_file_had}'])
137 cal1.max_iterations = 5
142 dbobjects=[
'CDCXtRelations'],
144 mp2.make_collection(
'hlt_mumu', path=pre_collector(), tracks=[
'RecoTracks']),
145 mp2.make_collection(
'hlt_hadron', path=pre_collector(), tracks=[
'RecoTracks'])],
146 files=dict(hlt_mumu=chosen_files_mumu_xt, hlt_hadron=chosen_files_hadron_xt),
151 commands=[
'method sparseMINRES-QLP 3 0.01',
155 'scaleerrors 1. 1.'],
156 params=dict(minPValue=0., externalIterations=0),
159 basf2.set_module_parameters(cal2.collections[
'hlt_mumu'].pre_collector_path,
160 'RootInput', entrySequences=[f
'0:{max_events_per_file}'])
161 basf2.set_module_parameters(cal2.collections[
'hlt_hadron'].pre_collector_path,
162 'RootInput', entrySequences=[f
'0:{max_events_per_file_had}'])
163 cal2.max_iterations = 2
166 for algorithm
in cal1.algorithms:
167 algorithm.params = {
"apply_iov": output_iov}
168 for algorithm
in cal2.algorithms:
169 algorithm.params = {
"apply_iov": output_iov}
176 def pre_collector(max_events=None):
178 Define pre collection (reconstruction in our purpose).
179 Probably, we need only CDC and ECL data.
181 max_events [int] : number of events to be processed.
182 All events by Default.
184 path : path for pre collection
186 from basf2
import create_path, register_module
187 import modularAnalysis
as ana
188 reco_path = create_path()
189 if max_events
is None:
190 root_input = register_module(
'RootInput')
192 root_input = register_module(
'RootInput',
193 entrySequences=[
'0:{}'.format(max_events)]
195 reco_path.add_module(root_input)
197 gearbox = register_module(
'Gearbox')
198 reco_path.add_module(gearbox)
199 reco_path.add_module(
'Geometry', useDB=
True)
201 from rawdata
import add_unpackers
203 add_unpackers(reco_path)
205 from reconstruction
import add_reconstruction
206 add_reconstruction(reco_path,
207 components=[
'PXD',
'SVD',
'CDC',
'ECL'],
208 add_trigger_calculation=
False,
209 trackFitHypotheses=[211, 13],
212 ana.fillParticleList(
'mu+:qed',
'muonID > 0.1 and useCMSFrame(p) > 2.', writeOut=
True, path=reco_path)
213 ana.reconstructDecay(
'Z0:mumu -> mu-:qed mu+:qed',
'', writeOut=
True, path=reco_path)
217 def pre_collector_cr(max_events=None):
219 Define pre collection (reconstruction in our purpose).
220 Probably, we need only CDC and ECL data.
222 max_events [int] : number of events to be processed.
223 All events by Default.
225 path : path for pre collection
227 from basf2
import create_path, register_module
228 reco_path = create_path()
229 if max_events
is None:
230 root_input = register_module(
'RootInput')
232 root_input = register_module(
'RootInput',
233 entrySequences=[
'0:{}'.format(max_events)]
235 reco_path.add_module(root_input)
237 gearbox = register_module(
'Gearbox')
238 reco_path.add_module(gearbox)
239 reco_path.add_module(
'Geometry', useDB=
True)
241 from rawdata
import add_unpackers
243 add_unpackers(reco_path)
245 from reconstruction
import add_cosmics_reconstruction
246 add_cosmics_reconstruction(reco_path,
247 components=[
'CDC',
'ECL'],
250 data_taking_period=
'normal'
255 def collector(bField=True, is_cosmic=False):
257 Create a cdc calibration collector
259 bField [bool] : True if B field is on, else False
260 isCosmic [bool] : True if cosmic events,
261 else (collision) False.
263 collector : collector module
265 from basf2
import register_module
266 col = register_module(
'CDCCalibrationCollector',
268 calExpectedDriftTime=
True,
269 eventT0Extraction=
True,
278 Create a T0 calibration algorithm.
282 from ROOT
import Belle2
284 algo.storeHisto(
True)
285 algo.setMaxMeanDt(0.5)
286 algo.setMaxRMSDt(0.1)
287 algo.setMinimumNDF(20)
293 Create a time walk calibration algorithm.
297 from ROOT
import Belle2
299 algo.setStoreHisto(
True)
306 Create a XT calibration algorithm.
308 prefix : prefixed name for algorithm,
309 which should be consistent with one of collector..
313 from ROOT
import Belle2
315 algo.setStoreHisto(
True)
316 algo.setLRSeparate(
True)
317 algo.setThreshold(0.55)
323 Create a Spacial resolution calibration algorithm.
325 prefix : prefixed name for algorithm,
326 which should be consistent with one of collector..
328 algo : Spacial algorithm
330 from ROOT
import Belle2
332 algo.setStoreHisto(
True)
333 algo.setThreshold(0.4)