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
', dimuon_cut='9.5 < M and M < 11.',
182 Di-muons with vertex+beam constraint collection
189 List of input data files
191 Cut string to select daughter muons
193 Cut string to apply
for reconstructed di-muon decay
195 Process only
'prescale' fraction of events
197 path = basf2.create_path()
198 path.add_module('Progress')
199 path.add_module(
'RootInput')
201 path.add_module(
'Prescale', prescale=prescale).if_false(basf2.Path(), basf2.AfterConditionPath.END)
203 path.add_module(
'Gearbox')
204 path.add_module(
'Geometry')
206 raw.add_unpackers(path)
208 reco.add_reconstruction(path, pruneTracks=
False)
210 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
212 ana.fillParticleList(f
"mu+:{name}", muon_cut, path=path)
213 ana.reconstructDecay(f
"Upsilon(4S):{name} -> mu+:{name} mu-:{name}", dimuon_cut, path=path)
215 vtx.raveFit(f
"Upsilon(4S):{name}", 0.001, daughtersUpdate=
True, silence_warning=
True, path=path, constraint=
"ipprofile")
221 primaryVertices=[f
"Upsilon(4S):{name}"])
224def create_prompt(files, cfg):
226 Returns configured (original) prompt stage alignment
231 Dictionary with all input files by category (name)
233 Expert config dictionary
235 mumu = select_files(files["mumu"], 0.2e6, cfg[
"mumu.max_processed_events_per_file"])
236 cosmic = select_files(files[
"cosmic"], 1e6, cfg[
"cosmic.max_processed_events_per_file"])
237 hadron = select_files(files[
"hadron"], 0.5e5, cfg[
"hadron.max_processed_events_per_file"])
238 offip = select_files(files[
"offip"], 0.2e6, cfg[
"offip.max_processed_events_per_file"])
241 name=
'VXDCDCalignment_prompt',
242 dbobjects=[
'VXDAlignment',
'CDCAlignment'],
244 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
245 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
246 mpc.make_collection(
"mumu", path=create_std_path(), tracks=[
"RecoTracks"]),
247 mpc.make_collection(
"offip", path=create_std_path(), tracks=[
"RecoTracks"])
250 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron, offip=offip),
258 "method diagonalization 3 0.1",
261 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
264 cal.max_iterations = 5
269def create_beamspot(files, cfg):
271 Returns configured beamspot calibration
276 Dictionary with all input files by category (name)
278 Expert config dictionary
281 mumu = select_files(files["mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
286 from ROOT.Belle2
import BeamSpotAlgorithm
287 from basf2
import create_path, register_module
292 from caf.framework
import Calibration, Collection
293 from caf.strategies
import SingleIOV
298 path.add_module(
'Progress')
299 path.add_module(
'RootInput')
300 path.add_module(
'Gearbox')
301 path.add_module(
'Geometry')
302 raw.add_unpackers(path)
303 path.add_module(
'SetupGenfitExtrapolation')
304 reco.add_reconstruction(path, skipGeometryAdding=
True)
306 muSelection =
'[p>1.0]'
307 muSelection +=
' and abs(dz)<2.0 and abs(dr)<0.5'
308 muSelection += f
' and nPXDHits >= {cfg["beamspot.min_pxd_hits"]} and nSVDHits >= 8 and nCDCHits >= 20'
309 ana.fillParticleList(
'mu+:BS', muSelection, path=path)
310 ana.reconstructDecay(
'Upsilon(4S):BS -> mu+:BS mu-:BS',
'9.5<M<11.5', path=path)
312 collector_bs = register_module(
'BeamSpotCollector', Y4SPListName=
'Upsilon(4S):BS')
313 algorithm_bs = BeamSpotAlgorithm()
317 collection_bs =
Collection(collector=collector_bs,
319 pre_collector_path=path)
321 calibration_bs =
Calibration(
'VXDCDCalignment_beamspot', algorithms=algorithm_bs)
322 calibration_bs.add_collection(
"mumu", collection_bs)
324 calibration_bs.strategies = SingleIOV
326 return calibration_bs
329def create_stage1(files, cfg):
331 Returns configured stage1 alignment (full constant alignment with wires, beamspot fixed)
336 Dictionary
with all input files by category (name)
338 Expert config dictionary
341 mumu = select_files(files["mumu"], 1.5e6, cfg[
"mumu.max_processed_events_per_file"])
342 cosmic = select_files(files[
"cosmic"], 0.7e6, cfg[
"cosmic.max_processed_events_per_file"])
343 hadron_and_offip = select_files(files[
"hadron"] + files[
"offip"], int(4.0e6 / 10.), cfg[
"hadron.max_processed_events_per_file"])
346 name=
'VXDCDCalignment_stage1',
347 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
349 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
350 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
351 make_mumu_collection(name=
"mumu")
354 files=dict(mumu=mumu, cosmic=cosmic, hadron=hadron_and_offip),
364 f
"method {cfg['stage1.method']} 6 0.001",
367 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
371 std_components = ROOT.vector(
'string')()
372 for component
in [
'VXDAlignment',
'CDCAlignment']:
373 std_components.push_back(component)
374 cal.algorithms[0].algorithm.setComponents(std_components)
376 cal.max_iterations = 0
381def create_stage2(files, cfg):
383 Returns configured stage2 alignment (run-dependent alignment)
388 Dictionary with all input files by category (name)
390 Expert config dictionary
392 mumu = select_files(files["mumu"], 10e6, cfg[
"mumu.max_processed_events_per_file"])
393 cosmic = select_files(files[
"cosmic"], 2e6, cfg[
"cosmic.max_processed_events_per_file"])
396 name=
'VXDCDCalignment_stage2',
397 dbobjects=[
'VXDAlignment',
'CDCAlignment',
'BeamSpot'],
399 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
400 make_mumu_collection(name=
"mumu")],
402 files=dict(mumu=mumu, cosmic=cosmic),
409 commands=[
"method inversion 6 0.001",
"entries 1000",
"threads 10 10"],
410 params=dict(minPValue=0.00001, externalIterations=0, granularity=
"run"),
414 std_components = ROOT.vector(
'string')()
415 for component
in [
'VXDAlignment',
'CDCAlignment']:
416 std_components.push_back(component)
417 cal.algorithms[0].algorithm.setComponents(std_components)
420 cal.max_iterations = 0
421 cal.algorithms[0].strategy = strategies.SequentialRunByRun
430def get_calibrations(input_data, **kwargs):
432 Required function called by b2caf-prompt-run.
433 Returns full configured 4-stage final alignment for prompt
438 cfg = kwargs['expert_config']
441 for colname
in collection_names:
442 file_to_iov = input_data[colname]
443 input_files = list(file_to_iov.keys())
444 files[colname] = input_files
446 prompt = create_prompt(files, cfg)
447 beamspot = create_beamspot(files, cfg)
448 stage1 = create_stage1(files, cfg)
449 stage2 = create_stage2(files, cfg)
451 requested_iov = kwargs.get(
"requested_iov",
None)
452 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
454 for cal
in [prompt, beamspot, stage1, stage2]:
455 for colname
in collection_names:
456 if colname
not in cal.collections.keys():
458 max_processed_events_per_file = cfg[f
'{colname}.max_processed_events_per_file']
459 basf2.set_module_parameters(
460 cal.collections[colname].pre_collector_path,
462 entrySequences=[f
'0:{max_processed_events_per_file}'], branchNames=HLT_INPUT_OBJECTS)
464 for algorithm
in cal.algorithms:
465 algorithm.params = {
"apply_iov": output_iov}
468 for cal
in [prompt, stage1, stage2]:
470 fix_mille_paths_for_algo(cal.algorithms[0])
472 beamspot.depends_on(prompt)
473 stage1.depends_on(beamspot)
474 stage2.depends_on(stage1)
478 beamspot.save_payloads =
False
480 if cfg[
"only_prompt"]:
483 return [prompt, beamspot, stage1, stage2]
486if __name__ ==
'__main__':
487 get_calibrations(dict(cosmic=dict(), mumu=dict(), hadron=dict(), offip=dict()),
488 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)