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