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