Belle II Software development
getModuleT0Histo.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12import sys
13from ROOT import Belle2
14from ROOT import TFile, TH1F
15
16# ------------------------------------------------------------------------
17# Save module T0 constants as a histogram into a root file
18#
19# usage: basf2 getModuleT0Histo.py expNo runNo globalTag/localDB
20# -------------------------------------------------------------------------
21
22argvs = sys.argv
23if len(argvs) < 4:
24 print("usage: basf2", argvs[0], "expNo runNo globalTag/localDB")
25 sys.exit()
26
27expNo = int(argvs[1])
28runNo = int(argvs[2])
29tag = argvs[3]
30
31
32class SaveModuleT0(b2.Module):
33 ''' Save module T0 from database into a root file as histogram '''
34
35 def initialize(self):
36 ''' initialize '''
37
38
39 self.db = Belle2.PyDBObj('TOPCalModuleT0')
40
41 file_name = 'moduleT0_DB-' + 'e' + f'{expNo:04d}' + '-r' + f'{runNo:05d}' + '.root'
42
43 self.file = TFile.Open(file_name, 'recreate')
44
45 self.h = TH1F('moduleT0', tag + '; slot number; module T0 [ns]', 16, 0.5, 16.5)
46
47 def event(self):
48 ''' event processing '''
49
50 for slot in range(1, 17):
51 self.h.SetBinContent(slot, self.db.getT0(slot))
52 self.h.SetBinError(slot, self.db.getT0Error(slot))
53 if self.db.isCalibrated(slot):
54 print('slot', slot, 'status = calibrated')
55 elif self.db.isUnusable(slot):
56 print('slot', slot, 'status = unusable')
57 else:
58 print('slot', slot, 'status = default')
59
60 def terminate(self):
61 ''' terminate '''
62
63 self.file.Write()
64 self.file.Close()
65
66
67# Database
68if '.txt' in tag:
69 b2.conditions.append_testing_payloads(tag)
70else:
71 b2.conditions.append_globaltag(tag)
72
73# Create path
74main = b2.create_path()
75
76# Set number of events to generate
77evtList = [1]
78runList = [runNo]
79expList = [expNo]
80
81# Event info setter
82eventinfosetter = b2.register_module('EventInfoSetter')
83eventinfosetter.param({'evtNumList': evtList, 'runList': runList, 'expList': expList})
84main.add_module(eventinfosetter)
85
86# Save module T0 from database into a root file as histogram
87main.add_module(SaveModuleT0())
88
89# Process events
90b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50