Belle II Software  release-08-01-10
calculateModuleT0FromLaser.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # ---------------------------------------------------------------------------------------
13 # Script to exctract an approximate ModuleT0 constant using the laser data.
14 # The input of the file is the root file containing the tree with all the
15 # localT0 constants produced by the TOPLaserCalibratorModule
16 # Usage: basf2 checkCalibrationOnCalpulseRun.py <reference slot (1-16)>
17 # <reference channel (0-511)> <input_file.root> <output_file.root>
18 #
19 # ---------------------------------------------------------------------------------------
20 
21 from ROOT import TFile, TTree
22 import sys
23 import math
24 from array import array
25 
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>')
28  sys.exit()
29 
30 refSlot = int(sys.argv[1]) - 1 # 1-based to 0-based
31 refChan = int(sys.argv[2])
32 
33 laserT0 = [0.] * 16
34 laserT0Err = [0.] * 16
35 
36 inputFile = TFile(str(sys.argv[3]))
37 inputTree = inputFile.Get('chT0')
38 
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)
43 inputFile.Close()
44 
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')
51 
52 print('------------------------------------------------------------------')
53 print('Results of TOP module-by-module sychronization using the Laser data')
54 print(' ')
55 for iSlot in range(0, 16):
56  moduleT0LaserConst = 0.
57  moduleT0LaserErr = 0.
58  if laserT0[iSlot] != 0:
59  moduleT0LaserConst = laserT0[iSlot] - laserT0[refSlot]
60  moduleT0LaserErr = math.sqrt(
61  laserT0Err[iSlot] *
62  laserT0Err[iSlot] +
63  laserT0Err[refSlot] *
64  laserT0Err[refSlot] +
65  0.055 *
66  0.055 +
67  0.025 *
68  0.025)
69  print('Slot ' + "%02d" % (iSlot + 1) + ': constant = ' + "%+06.3f" % (round(moduleT0LaserConst, 3)) +
70  ' ns; Error = ' + "%05.3f" % (round(moduleT0LaserErr, 3)) + ' ns')
71  outTree.Fill()
72 print(' ')
73 print('------------------------------------------------------------------')
74 
75 outTree.Write()
76 outFile.Close()