17 from ROOT.Belle2
import TOPDatabaseImporter
18 from ROOT
import TFile
24 main = b2.create_path()
27 eventinfosetter = b2.register_module(
'EventInfoSetter')
28 eventinfosetter.param(
'evtNumList', [1])
29 main.add_module(eventinfosetter)
32 gearbox = b2.register_module(
'Gearbox')
33 main.add_module(gearbox)
36 main.add_module(
'TOPGeometryParInitializer', useDB=
False)
42 b2.use_local_database(
"localDB/localDB.txt",
"localDB",
False)
45 dbImporter = TOPDatabaseImporter()
51 allFileNames = sorted(glob.glob(pathToFiles +
'/commonT0_r*.root'))
53 for fileName
in allFileNames:
54 file = TFile.Open(fileName)
55 h = file.Get(
'commonT0')
57 b2.B2ERROR(
'no histogram with name commonT0')
60 tree = file.Get(
'tree')
62 b2.B2ERROR(
'no TTree with name tree')
65 if tree.GetEntries() > 10:
66 fileNames.append(fileName)
69 numFiles = len(fileNames)
71 print(
'No files found')
76 bunchTimeSep = 47.163878 / 24
77 for i, fileName
in enumerate(fileNames):
78 runFirst = int((fileName.split(
'commonT0_r')[1]).split(
'.')[0])
81 if k < len(fileNames):
82 nextName = fileNames[k]
83 runLast = int((nextName.split(
'commonT0_r')[1]).split(
'.')[0]) - 1
84 if runLast < runFirst:
85 b2.B2ERROR(
"first run:", runFirst,
"last run:", runLast)
86 b2.B2ERROR(
"Last run is less than the first one: exiting!")
89 file = TFile.Open(fileName)
90 h = file.Get(
'commonT0')
91 t0 = h.GetBinContent(1)
92 t0 -= round(t0 / bunchTimeSep, 0) * bunchTimeSep
93 err = h.GetBinError(1)
94 dbImporter.importCommonT0(t0, err, expNo, runFirst, runLast)