21 from ROOT
import TFile, TTree
24 from array
import array
26 if len(sys.argv) != 4:
27 print(
'usage: basf2', sys.argv[0],
' <reference slot (1-16)> <reference channel (0-511)> <input_file.root> <output_file.root>')
30 refSlot = int(sys.argv[1]) - 1
31 refChan = int(sys.argv[2])
34 laserT0Err = [0.] * 16
36 inputFile = TFile(str(sys.argv[3]))
37 inputTree = inputFile.Get(
'chT0')
39 for entry
in inputTree:
40 if int(entry.channel) == refChan:
41 laserT0[int(entry.slot) - 1] = float(entry.fittedTime)
42 laserT0Err[int(entry.slot) - 1] = float(entry.fittedTimeError)
45 outFile = TFile(str(sys.argv[4]),
'recreate')
46 outTree = TTree(
'moduleT0laser',
'Module T0 constants using the laser')
47 moduleT0LaserConst = array(
'f', [0.])
48 moduleT0LaserErr = array(
'f', [0.])
49 outTree.Branch(
'moduleT0LaserConst', moduleT0LaserConst,
' moduleT0LaserConst/F')
50 outTree.Branch(
'moduleT0LaserErr', moduleT0LaserErr,
' moduleT0LaserErr/F')
52 print(
'------------------------------------------------------------------')
53 print(
'Results of TOP module-by-module sychronization using the Laser data')
55 for iSlot
in range(0, 16):
56 moduleT0LaserConst = 0.
58 if laserT0[iSlot] != 0:
59 moduleT0LaserConst = laserT0[iSlot] - laserT0[refSlot]
60 moduleT0LaserErr = math.sqrt(
69 print(
'Slot ' +
"%02d" % (iSlot + 1) +
': constant = ' +
"%+06.3f" % (round(moduleT0LaserConst, 3)) +
70 ' ns; Error = ' +
"%05.3f" % (round(moduleT0LaserErr, 3)) +
' ns')
73 print(
'------------------------------------------------------------------')