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=
"tadeas.bilka",
65 subsystem=
"alignment",
67 input_data_formats=[
"raw"],
68 input_data_names=collection_names,
70 "cosmic": [INPUT_DATA_FILTERS[
"Data Tag"][
"cosmic_calib"]] + quality_flags,
71 "mumu": [INPUT_DATA_FILTERS[
"Data Tag"][
"mumu_tight_or_highm_calib"]] + quality_flags,
72 "hadron": [INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"]] + quality_flags,
73 "offip": [INPUT_DATA_FILTERS[
"Data Tag"][
"offip_calib"]] + quality_flags
76 expert_config=default_config,
77 depends_on=[cdc_calibration, svd_time_calibration],
78 produced_payloads=[
"VXDAlignment",
"CDCAlignment"])
81def select_files(all_input_files, min_events, max_processed_events_per_file):
87 all_input_files : list(str)
88 List of all input file names
90 Minimum number of events to select from files
91 max_processed_events_per_file : int
92 Maximum number of events to consider per file
94 all_input_files = all_input_files[:]
98 while total_events < min_events:
101 if not all_input_files:
104 new_file_choice = choice(all_input_files)
106 all_input_files.remove(new_file_choice)
108 total_events_in_file = events_in_basf2_file(new_file_choice)
109 if not total_events_in_file:
113 events_contributed = min(total_events_in_file, max_processed_events_per_file)
115 chosen_files.append(new_file_choice)
116 total_events += events_contributed
118 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
119 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
120 if total_events < min_events:
122 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
126def create_std_path():
128 Returns default path for collections
with standard reconstruction
130 path = basf2.create_path()
131 path.add_module('Progress')
132 path.add_module(
'RootInput')
133 path.add_module(
'Gearbox')
134 path.add_module(
'Geometry')
135 raw.add_unpackers(path)
136 path.add_module(
'SetupGenfitExtrapolation')
137 reco.add_reconstruction(
140 skipGeometryAdding=
True,
142 path.add_module(
'DAFRecoFitter')
146def create_cosmics_path():
148 Returns default path for cosmic collection
150 path = basf2.create_path()
151 path.add_module('Progress')
152 path.add_module(
'RootInput')
153 path.add_module(
'Gearbox')
154 path.add_module(
'Geometry')
156 raw.add_unpackers(path)
157 path.add_module(
'SetupGenfitExtrapolation')
158 reco.add_cosmics_reconstruction(
161 skipGeometryAdding=
True,
162 addClusterExpertModules=
False,
166 path.add_module(
'SetRecoTrackMomentum', automatic=
True)
167 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
169 ana.fillParticleList(
170 'mu+:goodForVXDCDCAlignment',
171 '[z0 <= 57. or abs(d0) >= 26.5] and abs(dz) > 0.4 and nTracks == 1',
173 path.add_module(
'SkimFilter', particleLists=[
'mu+:goodForVXDCDCAlignment']).if_false(basf2.create_path())
178def make_mumu_collection(
181 muon_cut='p > 1.0 and abs(dz) < 2.0
and dr < 0.5
and nTracks==2
', dimuon_cut='9.5 < M and M < 11.',
184 Di-muons with vertex+beam constraint collection
191 List of input data files
193 Cut string to select daughter muons
195 Cut string to apply
for reconstructed di-muon decay
197 Process only
'prescale' fraction of events
199 path = basf2.create_path()
200 path.add_module('Progress')
201 path.add_module(
'RootInput')
203 path.add_module(
'Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
205 path.add_module(
'Gearbox')
206 path.add_module(
'Geometry')
208 raw.add_unpackers(path)
210 reco.add_reconstruction(path, pruneTracks=
False)
212 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
214 ana.fillParticleList(f
"mu+:{name}", muon_cut, path=path)
215 ana.reconstructDecay(f
"Upsilon(4S):{name} -> mu+:{name} mu-:{name}", dimuon_cut, path=path)
217 vtx.raveFit(f
"Upsilon(4S):{name}", 0.001, daughtersUpdate=
True, silence_warning=
True, path=path, constraint=
"ipprofile")
223 primaryVertices=[f
"Upsilon(4S):{name}"])
226def create_prompt(files, cfg):
228 Returns configured (original) prompt stage alignment
233 Dictionary with all input files by category (name)
235 Expert config dictionary
237 mumu = select_files(files["mumu"], 0.2e6, cfg[
"mumu.max_processed_events_per_file"])
238 cosmic = select_files(files[
"cosmic"], 1e6, cfg[
"cosmic.max_processed_events_per_file"])
239 hadron = select_files(files[
"hadron"], 0.5e5, cfg[
"hadron.max_processed_events_per_file"])
240 offip = select_files(files[
"offip"], 0.2e6, cfg[
"offip.max_processed_events_per_file"])
243 name=
'VXDCDCalignment_prompt',
244 dbobjects=[
'VXDAlignment',
'CDCAlignment'],
246 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
247 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
248 mpc.make_collection(
"mumu", path=create_std_path(), tracks=[
"RecoTracks"]),
249 mpc.make_collection(
"offip", path=create_std_path(), tracks=[
"RecoTracks"])
252 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron, offip=offip),
260 "method diagonalization 3 0.1",
263 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
266 cal.max_iterations = 5
271def create_beamspot(files, cfg):
273 Returns configured beamspot calibration
278 Dictionary with all input files by category (name)
280 Expert config dictionary
283 mumu = select_files(files["mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
288 from ROOT.Belle2
import BeamSpotAlgorithm
289 from basf2
import create_path, register_module
294 from caf.framework
import Calibration, Collection
295 from caf.strategies
import SingleIOV
300 path.add_module(
'Progress')
301 path.add_module(
'RootInput')
302 path.add_module(
'Gearbox')
303 path.add_module(
'Geometry')
304 raw.add_unpackers(path)
305 path.add_module(
'SetupGenfitExtrapolation')
306 reco.add_reconstruction(path, skipGeometryAdding=
True)
308 muSelection =
'[p>1.0]'
309 muSelection +=
' and abs(dz)<2.0 and abs(dr)<0.5'
310 muSelection += f
' and nPXDHits >= {cfg["beamspot.min_pxd_hits"]} and nSVDHits >= 8 and nCDCHits >= 20'
311 ana.fillParticleList(
'mu+:BS', muSelection, path=path)
312 ana.reconstructDecay(
'Upsilon(4S):BS -> mu+:BS mu-:BS',
'9.5<M<11.5', path=path)
314 collector_bs = register_module(
'BeamSpotCollector', Y4SPListName=
'Upsilon(4S):BS')
315 algorithm_bs = BeamSpotAlgorithm()
319 collection_bs =
Collection(collector=collector_bs,
321 pre_collector_path=path)
323 calibration_bs =
Calibration(
'VXDCDCalignment_beamspot', algorithms=algorithm_bs)
324 calibration_bs.add_collection(
"mumu", collection_bs)
326 calibration_bs.strategies = SingleIOV
328 return calibration_bs
331def create_stage1(files, cfg):
333 Returns configured stage1 alignment (full constant alignment with wires, beamspot fixed)
338 Dictionary
with all input files by category (name)
340 Expert config dictionary
343 mumu = select_files(files["mumu"], 1.5e6, cfg[
"mumu.max_processed_events_per_file"])
344 cosmic = select_files(files[
"cosmic"], 0.7e6, cfg[
"cosmic.max_processed_events_per_file"])
345 hadron_and_offip = select_files(files[
"hadron"] + files[
"offip"], int(4.0e6 / 10.), cfg[
"hadron.max_processed_events_per_file"])
348 name=
'VXDCDCalignment_stage1',
349 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
351 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
352 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
353 make_mumu_collection(name=
"mumu")
356 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron_and_offip),
366 f
"method {cfg['stage1.method']} 6 0.001",
369 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
373 std_components = ROOT.vector(
'string')()
374 for component
in [
'VXDAlignment',
'CDCAlignment']:
375 std_components.push_back(component)
376 cal.algorithms[0].algorithm.setComponents(std_components)
378 cal.max_iterations = 0
383def create_stage2(files, cfg):
385 Returns configured stage2 alignment (run-dependent alignment)
390 Dictionary with all input files by category (name)
392 Expert config dictionary
394 mumu = select_files(files["mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
395 cosmic = select_files(files[
"cosmic"], 2e6, cfg[
"cosmic.max_processed_events_per_file"])
398 name=
'VXDCDCalignment_stage2',
399 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
401 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
402 make_mumu_collection(name=
"mumu")],
404 files=dict(mumu=mumu, cosmic=cosmic),
411 commands=[
"method inversion 6 0.001",
"entries 1000",
"threads 10 10"],
412 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
416 std_components = ROOT.vector(
'string')()
417 for component
in [
'VXDAlignment',
'CDCAlignment']:
418 std_components.push_back(component)
419 cal.algorithms[0].algorithm.setComponents(std_components)
422 cal.max_iterations = 0
423 cal.algorithms[0].strategy = strategies.SequentialRunByRun
432def get_calibrations(input_data, **kwargs):
434 Required function called by b2caf-prompt-run.
435 Returns full configured 4-stage final alignment for prompt
440 cfg = kwargs['expert_config']
443 for colname
in collection_names:
444 file_to_iov = input_data[colname]
445 input_files = list(file_to_iov.keys())
446 files[colname] = input_files
448 prompt = create_prompt(files, cfg)
449 beamspot = create_beamspot(files, cfg)
450 stage1 = create_stage1(files, cfg)
451 stage2 = create_stage2(files, cfg)
453 requested_iov = kwargs.get(
"requested_iov",
None)
454 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
456 for cal
in [prompt, beamspot, stage1, stage2]:
457 for colname
in collection_names:
458 if colname
not in cal.collections.keys():
460 max_processed_events_per_file = cfg[f
'{colname}.max_processed_events_per_file']
461 basf2.set_module_parameters(
462 cal.collections[colname].pre_collector_path,
464 entrySequences=[f
'0:{max_processed_events_per_file}'], branchNames=HLT_INPUT_OBJECTS)
466 for algorithm
in cal.algorithms:
467 algorithm.params = {
"apply_iov": output_iov}
470 for cal
in [prompt, stage1, stage2]:
472 fix_mille_paths_for_algo(cal.algorithms[0])
474 beamspot.depends_on(prompt)
475 stage1.depends_on(beamspot)
476 stage2.depends_on(stage1)
480 beamspot.save_payloads =
False
482 if cfg[
"only_prompt"]:
485 return [prompt, beamspot, stage1, stage2]
488if __name__ ==
'__main__':
489 get_calibrations(dict(cosmic=dict(), mumu=dict(), hadron=dict(), offip=dict()),
490 requested_iov=IoV(0, 0, -1, -1), expert_config=default_config)
def make_collection(name, files=None, path=None, **argk)
def vxd_sensors(layers=None, rigid=True, surface=True, surface2=True, surface3=True, surface4=True, parameters=None)