11 """CDC tracking calibration. Performs the T0 determination using HLT skimmed raw data."""
13 from prompt
import CalibrationSettings
16 from random
import choice
20 settings = CalibrationSettings(name=
"CDC T0 Calibration with MP2",
21 expert_username=
"uchida",
23 input_data_formats=[
"raw"],
24 input_data_names=[
"hlt_mumu",
"hlt_hadron"],
29 from ROOT
import Belle2
31 bad_boards = [0, 35, 37, 77, 97, 115, 133, 193, 204, 218, 247]
36 result.append(label0.label())
39 result.append(label1.label())
43 def select_files(all_input_files, min_events, max_processed_events_per_file):
44 basf2.B2INFO(
"Attempting to choose a good subset of files")
48 while total_events < min_events:
51 if not all_input_files:
54 new_file_choice = choice(all_input_files)
56 all_input_files.remove(new_file_choice)
58 total_events_in_file = events_in_basf2_file(new_file_choice)
59 if not total_events_in_file:
62 events_contributed = 0
63 if total_events_in_file < max_processed_events_per_file:
65 events_contributed = total_events_in_file
67 events_contributed = max_processed_events_per_file
68 chosen_files.append(new_file_choice)
69 total_events += events_contributed
71 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
72 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
73 if total_events < min_events:
75 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
84 def get_calibrations(input_data, **kwargs):
90 file_to_iov_mumu = input_data[
"hlt_mumu"]
91 file_to_iov_hadron = input_data[
"hlt_hadron"]
94 max_files_per_run = 10
95 min_events_per_file = 1000
97 max_events_per_calibration = 50000
98 max_events_per_calibration_xt = 1000000
99 max_events_per_file = 2000
100 max_events_per_file_had = 1000
102 reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, max_files_per_run, min_events_per_file)
103 input_files_mumu = list(reduced_file_to_iov_mumu.keys())
104 chosen_files_mumu = select_files(input_files_mumu[:], max_events_per_calibration, max_events_per_file)
105 chosen_files_mumu_xt = select_files(input_files_mumu[:], max_events_per_calibration_xt, max_events_per_file)
106 basf2.B2INFO(f
"Total number of hlt_mumu files actually used as input = {len(input_files_mumu)}")
108 reduced_file_to_iov_hadron = filter_by_max_files_per_run(file_to_iov_hadron, max_files_per_run, min_events_per_file)
109 input_files_hadron = list(reduced_file_to_iov_hadron.keys())
110 chosen_files_hadron = select_files(input_files_hadron[:], max_events_per_calibration, max_events_per_file_had)
111 chosen_files_hadron_xt = select_files(input_files_hadron[:], max_events_per_calibration_xt, max_events_per_file_had)
112 basf2.B2INFO(f
"Total number of hlt_hadron files actually used as input = {len(input_files_hadron)}")
115 requested_iov = kwargs.get(
"requested_iov",
None)
117 from caf.utils
import IoV
119 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
120 import millepede_calibration
as mp2
124 dbobjects=[
'CDCTimeZeros',
'CDCTimeWalks'],
126 mp2.make_collection(
'hlt_mumu', path=pre_collector(), tracks=[
'RecoTracks']),
127 mp2.make_collection(
'hlt_hadron', path=pre_collector(), tracks=[
'RecoTracks'])],
128 files=dict(hlt_mumu=chosen_files_mumu, hlt_hadron=chosen_files_hadron),
132 fixed=fix_tw_param(),
133 commands=[
'method inversion 1 0.1',
137 'scaleerrors 1. 1.'],
138 params=dict(minPValue=0., externalIterations=0),
141 basf2.set_module_parameters(cal1.collections[
'hlt_mumu'].pre_collector_path,
142 'RootInput', entrySequences=[f
'0:{max_events_per_file}'])
143 basf2.set_module_parameters(cal1.collections[
'hlt_hadron'].pre_collector_path,
144 'RootInput', entrySequences=[f
'0:{max_events_per_file_had}'])
145 cal1.max_iterations = 5
150 dbobjects=[
'CDCXtRelations'],
152 mp2.make_collection(
'hlt_mumu', path=pre_collector(), tracks=[
'RecoTracks']),
153 mp2.make_collection(
'hlt_hadron', path=pre_collector(), tracks=[
'RecoTracks'])],
154 files=dict(hlt_mumu=chosen_files_mumu_xt, hlt_hadron=chosen_files_hadron_xt),
159 commands=[
'method sparseMINRES-QLP 3 0.01',
163 'scaleerrors 1. 1.'],
164 params=dict(minPValue=0., externalIterations=0),
167 basf2.set_module_parameters(cal2.collections[
'hlt_mumu'].pre_collector_path,
168 'RootInput', entrySequences=[f
'0:{max_events_per_file}'])
169 basf2.set_module_parameters(cal2.collections[
'hlt_hadron'].pre_collector_path,
170 'RootInput', entrySequences=[f
'0:{max_events_per_file_had}'])
171 cal2.max_iterations = 2
174 for algorithm
in cal1.algorithms:
175 algorithm.params = {
"apply_iov": output_iov}
176 for algorithm
in cal2.algorithms:
177 algorithm.params = {
"apply_iov": output_iov}
184 def pre_collector(max_events=None):
186 Define pre collection (reconstruction in our purpose).
187 Probably, we need only CDC and ECL data.
189 max_events [int] : number of events to be processed.
190 All events by Default.
192 path : path for pre collection
194 from basf2
import create_path, register_module
195 import modularAnalysis
as ana
196 reco_path = create_path()
197 if max_events
is None:
198 root_input = register_module(
'RootInput')
200 root_input = register_module(
'RootInput',
201 entrySequences=[
'0:{}'.format(max_events)]
203 reco_path.add_module(root_input)
205 gearbox = register_module(
'Gearbox')
206 reco_path.add_module(gearbox)
207 reco_path.add_module(
'Geometry', useDB=
True)
209 from rawdata
import add_unpackers
211 add_unpackers(reco_path)
213 from reconstruction
import add_reconstruction
214 add_reconstruction(reco_path,
215 components=[
'PXD',
'SVD',
'CDC',
'ECL'],
216 add_trigger_calculation=
False,
217 trackFitHypotheses=[211, 13],
220 ana.fillParticleList(
'mu+:qed',
'muonID > 0.1 and useCMSFrame(p) > 2.', writeOut=
True, path=reco_path)
221 ana.reconstructDecay(
'Z0:mumu -> mu-:qed mu+:qed',
'', writeOut=
True, path=reco_path)
225 def pre_collector_cr(max_events=None):
227 Define pre collection (reconstruction in our purpose).
228 Probably, we need only CDC and ECL data.
230 max_events [int] : number of events to be processed.
231 All events by Default.
233 path : path for pre collection
235 from basf2
import create_path, register_module
236 reco_path = create_path()
237 if max_events
is None:
238 root_input = register_module(
'RootInput')
240 root_input = register_module(
'RootInput',
241 entrySequences=[
'0:{}'.format(max_events)]
243 reco_path.add_module(root_input)
245 gearbox = register_module(
'Gearbox')
246 reco_path.add_module(gearbox)
247 reco_path.add_module(
'Geometry', useDB=
True)
249 from rawdata
import add_unpackers
251 add_unpackers(reco_path)
253 from reconstruction
import add_cosmics_reconstruction
254 add_cosmics_reconstruction(reco_path,
255 components=[
'CDC',
'ECL'],
262 def collector(bField=True, is_cosmic=False):
264 Create a cdc calibration collector
266 bField [bool] : True if B field is on, else False
267 isCosmic [bool] : True if cosmic events,
268 else (collision) False.
270 collector : collector module
272 from basf2
import register_module
273 col = register_module(
'CDCCalibrationCollector',
275 calExpectedDriftTime=
True,
276 eventT0Extraction=
True,
285 Create a T0 calibration algorithm.
289 from ROOT
import Belle2
291 algo.storeHisto(
True)
292 algo.setMaxMeanDt(0.5)
293 algo.setMaxRMSDt(0.1)
294 algo.setMinimumNDF(20)
300 Create a time walk calibration algorithm.
304 from ROOT
import Belle2
306 algo.setStoreHisto(
True)
313 Create a XT calibration algorithm.
315 prefix : prefixed name for algorithm,
316 which should be consistent with one of collector..
320 from ROOT
import Belle2
322 algo.setStoreHisto(
True)
323 algo.setLRSeparate(
True)
324 algo.setThreshold(0.55)
330 Create a Spacial resolution calibration algorithm.
332 prefix : prefixed name for algorithm,
333 which should be consistent with one of collector..
335 algo : Spacial algorithm
337 from ROOT
import Belle2
339 algo.setStoreHisto(
True)
340 algo.setThreshold(0.4)
static unsigned short getGlobalUniqueID()
Get global unique id.
Class for Space resolution calibration.
Class for T0 Correction .
Class for Time walk calibration.
Class to perform xt calibration for drift chamber.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.