12 import multiprocessing
15 from ROOT
import Belle2
16 from ROOT.Belle2
import MillepedeAlgorithm
18 from caf.framework
import CAF, Calibration, CentralDatabase
19 from caf
import backends
20 from caf
import strategies
22 import reconstruction
as reco
24 from generators
import add_kkmc_generator
25 from simulation
import add_simulation
27 b2.set_log_level(b2.LogLevel.INFO)
29 runList = [4, 5, 6, 7]
31 expList = [0, 0, 0, 0]
33 evtNumList = [20, 60, 20, 40]
41 params = [1, 2, 3, 4, 5, 6]
46 for shell
in [ying, yang]:
49 pxd_labels.append(label.label())
52 timedep = [(pxd_labels, [(0, run, 0)
for run
in runList] + [(20, 5, 0), (40, 5, 0)] + [(20, 7, 0)])]
54 db_components = [
'VXDAlignment']
55 components = [
'PXD',
'SVD',
'CDC']
58 def PXDHalfShellsAlignment(files, tags):
61 path = b2.create_path()
63 path.add_module(
'Progress')
66 path.add_module(
'Gearbox')
67 path.add_module(
'Geometry')
71 reco.add_mc_reconstruction(path, pruneTracks=
False, components=components)
72 path.add_module(
'DAFRecoFitter')
74 collector = b2.register_module(
'MillepedeCollector',
75 tracks=[
'RecoTracks'],
77 calibrateVertex=
True, components=db_components,
84 algorithm = MillepedeAlgorithm()
85 algorithm.invertSign(
True)
86 algorithm.ignoreUndeterminedParams(
False)
88 std_components = ROOT.vector(
'string')()
89 for component
in db_components:
90 std_components.push_back(component)
91 algorithm.setComponents(std_components)
93 algorithm.steering().command(
'method diagonalization 3 0.1')
94 algorithm.steering().command(
'skipemptycons')
95 algorithm.steering().command(
'threads 4 4')
96 algorithm.steering().command(
'matiter 1')
97 algorithm.steering().command(
'scaleerrors 1. 1.')
99 algorithm.steering().command(
'printcounts 1')
101 algorithm.steering().command(
'monitorresiduals')
102 algorithm.steering().command(
'closeandreopen')
103 algorithm.steering().command(
'hugecut 50.')
109 algorithm.steering().command(
'Parameters')
111 def fix_vxd_id(vxd_id, params=None):
113 params = [1, 2, 3, 4, 5, 6]
117 algorithm.steering().command(
'{} 0.0 -1. ! {}'.format(str(label.label()), str(vxd_id)))
125 ladders = [8, 12, 7, 10, 12, 16]
126 sensors = [2, 2, 2, 3, 4, 5]
128 for layer
in range(1, 7):
129 for ladder
in range(1, ladders[layer - 1] + 1):
130 fix_vxd_id(
Belle2.VxdID(layer, ladder, 0), params=[1, 2, 3, 4, 5, 6])
131 for sensor
in range(1, sensors[layer - 1] + 1):
159 algorithm.setTimedepConfig(timedep)
161 calibration =
Calibration(
'PXDHalfShellsAlignment',
163 algorithms=algorithm,
165 pre_collector_path=path,
166 database_chain=[CentralDatabase(tag)
for tag
in tags],
167 output_patterns=
None,
168 max_files_per_collector_job=1,
172 calibration.strategies = strategies.SingleIOV
178 main = b2.create_path()
180 main.add_module(
"EventInfoSetter", evtNumList=evtNumList, runList=runList, expList=expList)
182 main.add_module(
'Gearbox')
183 main.add_module(
'Geometry')
185 add_kkmc_generator(main,
'mu-mu+')
189 main.add_module(
"RootOutput", outputFileName=filename)
190 main.add_module(
"Progress")
194 return os.path.abspath(filename)
197 if __name__ ==
"__main__":
200 if not len(input_files):
203 outfile =
'TimeDepCalibration_TestData.root'
204 print(
"No input file provided. This will now generate test data into {} and run over it.".format(outfile))
205 print(
"It will take couple of minutes.")
206 print(
"You can set this file as input next time using -i option of basf2")
210 tags = b2.conditions.default_globaltags
211 mp2_beamspot = PXDHalfShellsAlignment(input_files, tags)
212 mp2_beamspot.max_iterations = 1
215 cal_fw.add_calibration(mp2_beamspot)
216 cal_fw.backend = backends.LSF()
219 if multiprocessing.cpu_count() < 10:
220 cal_fw.backend = backends.Local(1)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Class to convert to/from global labels for Millepede II to/from detector & parameter identificators.
static unsigned short getGlobalUniqueID()
Get global unique id.
Class to uniquely identify a any structure of the PXD and SVD.