10Full Simultaneous Global and Local VXD and CDC alignment with Millepede II
12The input collections are:
13- cosmics (hlt skim) - mandatorry
14- hadron - for "low" momentum tracks from IP
15- mumu - mumu_2trk or mumu_tight - for high momentum tracks from IP
16- offip - tracks from outside IP (beam background, beam-gas)
23from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
24from prompt.calibrations.caf_cdc
import settings
as cdc_calibration
25from prompt.calibrations.caf_svd_time
import settings
as svd_time_calibration
28from caf.utils
import IoV
29from caf
import strategies
33import reconstruction
as reco
34import modularAnalysis
as ana
37from random
import choice
38from random
import seed
40import millepede_calibration
as mpc
45collection_names = [
"cosmic",
"hadron",
"mumu",
"offip"]
49 "cosmic.max_processed_events_per_file": 4000,
50 "hadron.max_processed_events_per_file": 1000,
51 "mumu.max_processed_events_per_file": 5000,
52 "offip.max_processed_events_per_file": 2000,
53 "beamspot.min_pxd_hits": 0,
54 "stage1.method":
"decomposition",
55 "stage1.z_offset":
True
58quality_flags = [INPUT_DATA_FILTERS[
"Run Type"][
"physics"],
59 INPUT_DATA_FILTERS[
"Data Quality Tag"][
"Good Or Recoverable"],
60 INPUT_DATA_FILTERS[
"Magnet"][
"On"]]
63settings = CalibrationSettings(name=
"Full VXD and CDC Alignment",
64 expert_username=
"bilkat",
66 input_data_formats=[
"raw"],
67 input_data_names=collection_names,
69 "cosmic": [INPUT_DATA_FILTERS[
"Data Tag"][
"cosmic_calib"]] + quality_flags,
70 "mumu": [INPUT_DATA_FILTERS[
"Data Tag"][
"mumu_tight_or_highm_calib"]] + quality_flags,
71 "hadron": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"]] + quality_flags,
72 "offip": [INPUT_DATA_FILTERS[
"Data Tag"][
"offip_calib"]] + quality_flags
75 expert_config=default_config,
76 depends_on=[cdc_calibration, svd_time_calibration])
79def select_files(all_input_files, min_events, max_processed_events_per_file):
85 all_input_files : list(str)
86 List of all input file names
88 Minimum number of events to select from files
89 max_processed_events_per_file : int
90 Maximum number of events to consider per file
92 all_input_files = all_input_files[:]
96 while total_events < min_events:
99 if not all_input_files:
102 new_file_choice = choice(all_input_files)
104 all_input_files.remove(new_file_choice)
106 total_events_in_file = events_in_basf2_file(new_file_choice)
107 if not total_events_in_file:
111 events_contributed = min(total_events_in_file, max_processed_events_per_file)
113 chosen_files.append(new_file_choice)
114 total_events += events_contributed
116 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
117 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
118 if total_events < min_events:
120 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
124def create_std_path():
126 Returns default path for collections with standard reconstruction
128 path = basf2.create_path()
129 path.add_module(
'Progress')
130 path.add_module(
'RootInput')
131 path.add_module(
'Gearbox')
132 path.add_module(
'Geometry')
133 raw.add_unpackers(path)
134 path.add_module(
'SetupGenfitExtrapolation')
135 reco.add_reconstruction(
138 skipGeometryAdding=
True,
140 path.add_module(
'DAFRecoFitter')
144def create_cosmics_path():
146 Returns default path for cosmic collection
148 path = basf2.create_path()
149 path.add_module(
'Progress')
150 path.add_module(
'RootInput')
151 path.add_module(
'Gearbox')
152 path.add_module(
'Geometry')
154 raw.add_unpackers(path)
155 path.add_module(
'SetupGenfitExtrapolation')
156 reco.add_cosmics_reconstruction(
159 skipGeometryAdding=
True,
160 addClusterExpertModules=
False,
164 path.add_module(
'SetRecoTrackMomentum', automatic=
True)
165 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
167 ana.fillParticleList(
168 'mu+:goodForVXDCDCAlignment',
169 '[z0 <= 57. or abs(d0) >= 26.5] and abs(dz) > 0.4 and nTracks == 1',
171 path.add_module(
'SkimFilter', particleLists=[
'mu+:goodForVXDCDCAlignment']).if_false(basf2.create_path())
176def make_mumu_collection(
179 muon_cut='p > 1.0 and abs(dz) < 2.0
and dr < 0.5
and nTracks==2
',
180 dimuon_cut='9.5 < M and M < 11.',
183 Di-muons with vertex+beam constraint collection
190 List of input data files
192 Cut string to select daughter muons
194 Cut string to apply for reconstructed di-muon decay
196 Process only 'prescale' fraction of events
198 path = basf2.create_path()
199 path.add_module(
'Progress')
200 path.add_module(
'RootInput')
202 path.add_module(
'Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
204 path.add_module(
'Gearbox')
205 path.add_module(
'Geometry')
207 raw.add_unpackers(path)
209 reco.add_reconstruction(path, pruneTracks=
False)
211 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
213 ana.fillParticleList(f
"mu+:{name}", muon_cut, path=path)
214 ana.reconstructDecay(f
"Upsilon(4S):{name} -> mu+:{name} mu-:{name}", dimuon_cut, path=path)
216 vtx.raveFit(f
"Upsilon(4S):{name}", 0.001, daughtersUpdate=
True, silence_warning=
True, path=path, constraint=
"ipprofile")
222 primaryVertices=[f
"Upsilon(4S):{name}"])
225def create_prompt(files, cfg):
227 Returns configured (original) prompt stage alignment
232 Dictionary with all input files by category (name)
234 Expert config dictionary
236 mumu = select_files(files[
"mumu"], 0.2e6, cfg[
"mumu.max_processed_events_per_file"])
237 cosmic = select_files(files[
"cosmic"], 1e6, cfg[
"cosmic.max_processed_events_per_file"])
238 hadron = select_files(files[
"hadron"], 0.5e5, cfg[
"hadron.max_processed_events_per_file"])
239 offip = select_files(files[
"offip"], 0.2e6, cfg[
"offip.max_processed_events_per_file"])
242 name=
'VXDCDCalignment_prompt',
243 dbobjects=[
'VXDAlignment',
'CDCAlignment'],
245 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
246 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
247 mpc.make_collection(
"mumu", path=create_std_path(), tracks=[
"RecoTracks"]),
248 mpc.make_collection(
"offip", path=create_std_path(), tracks=[
"RecoTracks"])
251 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron, offip=offip),
259 "method diagonalization 3 0.1",
262 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
265 cal.max_iterations = 5
270def create_beamspot(files, cfg):
272 Returns configured beamspot calibration
277 Dictionary with all input files by category (name)
279 Expert config dictionary
282 mumu = select_files(files[
"mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
287 from ROOT.Belle2
import BeamSpotAlgorithm
288 from basf2
import create_path, register_module
293 from caf.framework
import Calibration, Collection
294 from caf.strategies
import SingleIOV
299 path.add_module(
'Progress')
300 path.add_module(
'RootInput')
301 path.add_module(
'Gearbox')
302 path.add_module(
'Geometry')
303 raw.add_unpackers(path)
304 path.add_module(
'SetupGenfitExtrapolation')
305 reco.add_reconstruction(path, skipGeometryAdding=
True)
307 muSelection =
'[p>1.0]'
308 muSelection +=
' and abs(dz)<2.0 and abs(dr)<0.5'
309 muSelection += f
' and nPXDHits >= {cfg["beamspot.min_pxd_hits"]} and nSVDHits >= 8 and nCDCHits >= 20'
310 ana.fillParticleList(
'mu+:BS', muSelection, path=path)
311 ana.reconstructDecay(
'Upsilon(4S):BS -> mu+:BS mu-:BS',
'9.5<M<11.5', path=path)
313 collector_bs = register_module(
'BeamSpotCollector', Y4SPListName=
'Upsilon(4S):BS')
314 algorithm_bs = BeamSpotAlgorithm()
318 collection_bs =
Collection(collector=collector_bs,
320 pre_collector_path=path)
322 calibration_bs = Calibration(
'VXDCDCalignment_beamspot', algorithms=algorithm_bs)
323 calibration_bs.add_collection(
"mumu", collection_bs)
325 calibration_bs.strategies = SingleIOV
327 return calibration_bs
330def create_stage1(files, cfg):
332 Returns configured stage1 alignment (full constant alignment with wires, beamspot fixed)
337 Dictionary with all input files by category (name)
339 Expert config dictionary
342 mumu = select_files(files[
"mumu"], 1.5e6, cfg[
"mumu.max_processed_events_per_file"])
343 cosmic = select_files(files[
"cosmic"], 0.7e6, cfg[
"cosmic.max_processed_events_per_file"])
344 hadron_and_offip = select_files(files[
"hadron"] + files[
"offip"], int(4.0e6 / 10.), cfg[
"hadron.max_processed_events_per_file"])
347 name=
'VXDCDCalignment_stage1',
348 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
350 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
351 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
352 make_mumu_collection(name=
"mumu")
355 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron_and_offip),
365 f
"method {cfg['stage1.method']} 6 0.001",
368 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
372 std_components = ROOT.vector(
'string')()
373 for component
in [
'VXDAlignment',
'CDCAlignment']:
374 std_components.push_back(component)
375 cal.algorithms[0].algorithm.setComponents(std_components)
377 cal.max_iterations = 0
382def create_stage2(files, cfg):
384 Returns configured stage2 alignment (run-dependent alignment)
389 Dictionary with all input files by category (name)
391 Expert config dictionary
393 mumu = select_files(files[
"mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
394 cosmic = select_files(files[
"cosmic"], 2e6, cfg[
"cosmic.max_processed_events_per_file"])
397 name=
'VXDCDCalignment_stage2',
398 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
400 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
401 make_mumu_collection(name=
"mumu")],
403 files=dict(mumu=mumu, cosmic=cosmic),
410 commands=[
"method inversion 6 0.001",
"entries 1000",
"threads 10 10"],
411 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
415 std_components = ROOT.vector(
'string')()
416 for component
in [
'VXDAlignment',
'CDCAlignment']:
417 std_components.push_back(component)
418 cal.algorithms[0].algorithm.setComponents(std_components)
421 cal.max_iterations = 0
422 cal.algorithms[0].strategy = strategies.SequentialRunByRun
431def get_calibrations(input_data, **kwargs):
433 Required function called by b2caf-prompt-run.
434 Returns full configured 4-stage final alignment for prompt
439 cfg = kwargs[
'expert_config']
442 for colname
in collection_names:
443 file_to_iov = input_data[colname]
444 input_files = list(file_to_iov.keys())
445 files[colname] = input_files
447 prompt = create_prompt(files, cfg)
448 beamspot = create_beamspot(files, cfg)
449 stage1 = create_stage1(files, cfg)
450 stage2 = create_stage2(files, cfg)
452 requested_iov = kwargs.get(
"requested_iov",
None)
453 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
455 for cal
in [prompt, beamspot, stage1, stage2]:
456 for colname
in collection_names:
457 if colname
not in cal.collections.keys():
459 max_processed_events_per_file = cfg[f
'{colname}.max_processed_events_per_file']
460 basf2.set_module_parameters(
461 cal.collections[colname].pre_collector_path,
463 entrySequences=[f
'0:{max_processed_events_per_file}'], branchNames=HLT_INPUT_OBJECTS)
465 for algorithm
in cal.algorithms:
466 algorithm.params = {
"apply_iov": output_iov}
469 for cal
in [prompt, stage1, stage2]:
471 fix_mille_paths_for_algo(cal.algorithms[0])
473 beamspot.depends_on(prompt)
474 stage1.depends_on(beamspot)
475 stage2.depends_on(stage1)
479 beamspot.save_payloads =
False
481 if cfg[
"only_prompt"]:
484 return [prompt, beamspot, stage1, stage2]
487if __name__ ==
'__main__':
488 get_calibrations(dict(cosmic=dict(), mumu=dict(), hadron=dict(), offip=dict()),
489 requested_iov=IoV(0, 0, -1, -1), expert_config=default_config)
make_collection(name, files=None, path=None, **argk)
vxd_sensors(layers=None, rigid=True, surface=True, surface2=True, surface3=True, surface4=True, parameters=None)