Belle II Software development
runIPVXD_CAF.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from ROOT import Belle2
13
14import generators as gen
15import simulation as sim
16import rawdata as raw
17import reconstruction as reco
18import modularAnalysis as ana
19import vertex as vtx
20
23
24import os
25
26import millepede_calibration as mpc
27from caf.framework import CAF
28from caf import backends
29
30
31def generate_test_data(filename):
32 main = basf2.create_path()
33
34 main.add_module("EventInfoSetter", evtNumList=[200])
35 # add_beamparameters(main, "Y4S")
36 main.add_module('Gearbox')
37 main.add_module('Geometry')
38
39 gen.add_kkmc_generator(main, 'mu-mu+')
40
41 sim.add_simulation(main)
42
43 main.add_module("RootOutput", outputFileName=filename)
44 main.add_module("Progress")
45
46 basf2.process(main)
47 print(basf2.statistics)
48 return os.path.abspath(filename)
49
50
51def diMuonCollection(name="diMuonCollection", add_unpackers=True):
52 path = basf2.create_path()
53
54 path.add_module('Progress')
55 # Remove all non-raw data to run the full reco again
56 path.add_module('RootInput') # , branchNames=input_branches, entrySequences=['0:5000'])
57 path.add_module('Gearbox')
58 path.add_module('Geometry')
59
60 if add_unpackers:
61 raw.add_unpackers(path)
62
63 reco.add_reconstruction(path, pruneTracks=False)
64
65 tmp = basf2.create_path()
66 for m in path.modules():
67 if m.name() == "PXDPostErrorChecker":
68 m.param('CriticalErrorMask', 0)
69 if m.name() in ["PXDUnpacker", "CDCHitBasedT0Extraction", "TFCDC_WireHitPreparer"]:
70 m.set_log_level(basf2.LogLevel.ERROR)
71 if m.name() == "SVDSpacePointCreator":
72 m.param("MinClusterTime", -999)
73 tmp.add_module(m)
74 path = tmp
75 path.add_module('DAFRecoFitter')
76
77 ana.fillParticleList('mu+:mu_dimuon', 'abs(formula(z0)) < 0.5 and abs(d0) < 0.5 and nTracks == 2', writeOut=True, path=path)
78 ana.reconstructDecay('Z0:mumu -> mu-:mu_dimuon mu+:mu_dimuon', '', writeOut=True, path=path)
79 vtx.raveFit('Z0:mumu', 0.001, daughtersUpdate=True, silence_warning=True, path=path)
80
81 return mpc.make_collection(name, path=path, primaryVertices=['Z0:mumu'])
82
83
84def get_calibration(files, tags):
85
86 cal = mpc.create(
87 name='alignment',
88 dbobjects=['VXDAlignment', 'BeamSpot'],
89 collections=[
90 diMuonCollection(name="dimuon_skim", add_unpackers=False)
91 ],
92 constraints=[
94 ],
96 commands=[
97 'method diagonalization 3 0.1',
98 'scaleerrors 1. 1.',
99 ('printcounts', None)
100
101 ],
102
103 tags=tags,
104 files=files,
105
106 timedep=[([], [(0, 0, 0)])],
107 params=dict(minPValue=0.001, externalIterations=0))
108
109 return cal
110
111
112if __name__ == '__main__':
113 input_files = [os.path.abspath(file) for file in Belle2.Environment.Instance().getInputFilesOverride()]
114
115 if not len(input_files):
116 outfile = Belle2.Environment.Instance().getOutputFileOverride()
117 if not outfile:
118 outfile = 'cafBeamSpotVXDHalfShells_TestData.root'
119 print("No input file provided. This will now generate test data into {} and run over it.".format(outfile))
120 print("It will take couple of minutes.")
121 print("You can set this file as input next time using -i option of basf2")
122
123 input_files = [generate_test_data(outfile)]
124
125 cal = get_calibration(
126 files={'dimuon_skim': input_files},
127 tags=[tag for tag in basf2.conditions.default_globaltags])
128
129 cal.max_iterations = 0
130
131 cal_fw = CAF()
132 cal_fw.add_calibration(cal)
133 cal_fw.backend = backends.Local(1)
134
135 cal_fw.run()
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
def vxd_sensors(layers=None, rigid=True, surface=True, surface2=True, surface3=True, surface4=True, parameters=None)
Definition: parameters.py:157
def vxd_ladders(layers=None, parameters=None)
Definition: parameters.py:137