Belle II Software development
checkDB-commonT0.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12import sys
13from ROOT import Belle2
14
15# ------------------------------------------------------------------------
16# useful tool for checking the status of common T0 calibration in DB
17#
18# usage: basf2 checkDB-commonT0.py expNo runFirst runLast globalTag/localDB
19# -------------------------------------------------------------------------
20
21argvs = sys.argv
22if len(argvs) < 5:
23 print("usage: basf2", argvs[0], "expNo runFirst runLast globalTag/localDB")
24 sys.exit()
25
26expNo = int(argvs[1])
27runFirst = int(argvs[2])
28runLast = int(argvs[3])
29tag = argvs[4]
30
31
32class CheckCalibDB(b2.Module):
33 ''' print content of TOPCalCommonT0 '''
34
35 def initialize(self):
36 ''' initialize '''
37
38
39 self.db = Belle2.PyDBObj('TOPCalCommonT0')
40
41 self.lastRun = None
42
43 self.bunchTimeSep = 47.163878 / 24
44
45 print()
46 print('Common T0 calibration status of GT =', tag)
47 print('Experiment =', expNo, 'Runs =', runFirst, 'to', runLast)
48 print()
49
50 def event(self):
51 ''' event processing '''
52
53 evtMetaData = Belle2.PyStoreObj('EventMetaData')
54 runNo = 'r' + f'{evtMetaData.getRun():05d}'
55
56 if not self.db:
57 b2.B2ERROR(runNo + ': payload not found')
58 return
59 if not self.db.hasChanged():
60 self.lastRun = runNo
61 return
62 if self.lastRun:
63 print('... to ' + self.lastRun)
64 self.lastRun = None
65
66 if self.db.isCalibrated():
67 status = 'calibrated'
68 elif self.db.isUnusable():
69 status = 'unusable'
70 elif self.db.isRoughlyCalibrated():
71 status = 'roughly calibrated'
72 else:
73 status = 'default'
74 n = round(self.db.getT0() / self.bunchTimeSep, 0)
75 if n == 0:
76 print(runNo + ': T0 =',
77 round(self.db.getT0(), 4), '+/-', round(self.db.getT0Error(), 4),
78 status)
79 else:
80 print(runNo + ': T0 =',
81 round(self.db.getT0(), 4), '+/-', round(self.db.getT0Error(), 4),
82 status, '-- out of range')
83
84 def terminate(self):
85 ''' terminate '''
86
87 if self.lastRun:
88 print('... to ' + self.lastRun)
89 self.lastRun = None
90
91
92# Database
93if '.txt' in tag:
94 b2.conditions.append_testing_payloads(tag)
95else:
96 b2.conditions.append_globaltag(tag)
97
98# Create path
99main = b2.create_path()
100
101# Set number of events to generate
102evtList = [1 for run in range(runFirst, runLast + 1)]
103runList = [run for run in range(runFirst, runLast + 1)]
104expList = [expNo for run in range(runFirst, runLast + 1)]
105
106# Event info setter
107eventinfosetter = b2.register_module('EventInfoSetter')
108eventinfosetter.param({'evtNumList': evtList, 'runList': runList, 'expList': expList})
109main.add_module(eventinfosetter)
110
111# Run checker
112main.add_module(CheckCalibDB())
113
114# Process events
115b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
bunchTimeSep
bunch time separation