15from ROOT
import Belle2
16from ROOT.Belle2
import MillepedeAlgorithm
18from caf.framework
import CAF, Calibration, CentralDatabase
19from caf
import backends
20from caf
import strategies
22import reconstruction
as reco
24from generators
import add_kkmc_generator
25from simulation
import add_simulation
27b2.set_log_level(b2.LogLevel.INFO)
33evtNumList = [20, 60, 20, 40]
41params = [1, 2, 3, 4, 5, 6]
46for shell
in [ying, yang]:
49 pxd_labels.append(label.label())
52timedep = [(pxd_labels, [(0, run, 0)
for run
in runList] + [(20, 5, 0), (40, 5, 0)] + [(20, 7, 0)])]
54db_components = [
'VXDAlignment']
55components = [
'PXD',
'SVD',
'CDC']
58def 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_reconstruction(path, pruneTracks=
False, components=components)
73 collector = b2.register_module(
'MillepedeCollector',
74 tracks=[
'RecoTracks'],
76 calibrateVertex=
True, components=db_components,
83 algorithm = MillepedeAlgorithm()
84 algorithm.invertSign(
True)
85 algorithm.ignoreUndeterminedParams(
False)
87 std_components = ROOT.vector(
'string')()
88 for component
in db_components:
89 std_components.push_back(component)
90 algorithm.setComponents(std_components)
92 algorithm.steering().command(
'method diagonalization 3 0.1')
93 algorithm.steering().command(
'skipemptycons')
94 algorithm.steering().command(
'threads 4 4')
95 algorithm.steering().command(
'matiter 1')
96 algorithm.steering().command(
'scaleerrors 1. 1.')
98 algorithm.steering().command(
'printcounts 1')
100 algorithm.steering().command(
'monitorresiduals')
101 algorithm.steering().command(
'closeandreopen')
102 algorithm.steering().command(
'hugecut 50.')
108 algorithm.steering().command(
'Parameters')
110 def fix_vxd_id(vxd_id, params=None):
112 params = [1, 2, 3, 4, 5, 6]
116 algorithm.steering().command(
'{} 0.0 -1. ! {}'.format(str(label.label()), str(vxd_id)))
124 ladders = [8, 12, 7, 10, 12, 16]
125 sensors = [2, 2, 2, 3, 4, 5]
127 for layer
in range(1, 7):
128 for ladder
in range(1, ladders[layer - 1] + 1):
129 fix_vxd_id(
Belle2.VxdID(layer, ladder, 0), params=[1, 2, 3, 4, 5, 6])
130 for sensor
in range(1, sensors[layer - 1] + 1):
158 algorithm.setTimedepConfig(timedep)
160 calibration = Calibration(
'PXDHalfShellsAlignment',
162 algorithms=algorithm,
164 pre_collector_path=path,
165 database_chain=[CentralDatabase(tag)
for tag
in tags],
166 output_patterns=
None,
167 max_files_per_collector_job=1,
177 main = b2.create_path()
179 main.add_module(
"EventInfoSetter", evtNumList=evtNumList, runList=runList, expList=expList)
181 main.add_module(
'Gearbox')
182 main.add_module(
'Geometry')
184 add_kkmc_generator(main,
'mu-mu+')
188 main.add_module(
"RootOutput", outputFileName=filename)
189 main.add_module(
"Progress")
191 b2.process(main, calculateStatistics=
True)
193 return os.path.abspath(filename)
196if __name__ ==
"__main__":
199 if not len(input_files):
202 outfile =
'TimeDepCalibration_TestData.root'
203 print(
"No input file provided. This will now generate test data into {} and run over it.".format(outfile))
204 print(
"It will take couple of minutes.")
205 print(
"You can set this file as input next time using -i option of basf2")
209 tags = b2.conditions.default_globaltags
210 mp2_beamspot = PXDHalfShellsAlignment(input_files, tags)
211 mp2_beamspot.max_iterations = 1
214 cal_fw.add_calibration(mp2_beamspot)
218 if multiprocessing.cpu_count() < 10:
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.