Belle II Software development
alphaRatioPlots.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12import sys
13from ROOT import Belle2, TCanvas, gStyle, gROOT
14import time
15
16# --------------------------------------------------------------------------------------------
17# Make a plot of alpha-ratio histograms saved in database which shows optically decoupled PMTs
18#
19# Usage: basf2 alphaRatioPlots.py expNo runNo [globalTag/localDB]
20# (default globalTag = data_reprocessing_prompt)
21# --------------------------------------------------------------------------------------------
22
23if len(sys.argv) < 3:
24 print("usage: basf2", sys.argv[0], "expNo runNo [globalTag/localDB]")
25 sys.exit()
26
27expNo = int(sys.argv[1])
28runNo = int(sys.argv[2])
29globalTag = "data_reprocessing_prompt"
30if len(sys.argv) > 3:
31 globalTag = sys.argv[3]
32
33
34class MakePlots(b2.Module):
35 ''' Makes a plot of alpha-ratio histograms '''
36
37 def initialize(self):
38 ''' initialize: implementation'''
39
40 gROOT.SetBatch(True)
41
42 db = Belle2.PyDBObj("TOPCalPhotonYields")
43 if not db:
44 return
45
46 print("- global tag:", globalTag)
47 print("- time of measurement:",
48 time.strftime("%d %b %Y %H:%M:%S", time.localtime(db.getTimeStamp())), "(mean), ",
49 round(db.getTimeStampStd() / 3600 / 24, 2), "days (rms)")
50
51 canvas = TCanvas("c1", "alpha ratio", 2000, 1500)
52 canvas.Divide(2, 8)
53 gStyle.SetOptStat(0)
54 gStyle.SetTitleFontSize(0.18)
55 for slot in range(1, 17):
56 canvas.cd(slot)
57 pad = canvas.GetPad(slot)
58 pad.SetLeftMargin(0.02)
59 pad.SetRightMargin(0.02)
60 pad.SetTopMargin(0.17)
61 pad.SetBottomMargin(0.03)
62 h = db.getAlphaRatio(slot)
63 if not h:
64 continue
65 h.SetTitle("slot " + str(slot))
66 h.SetMinimum(0)
67 h.SetMaximum(1.2)
68 h.Draw("col a")
69 fileName = 'alphaRatio-' + time.strftime("%Y-%m-%d", time.localtime(db.getTimeStamp())) + '.png'
70 canvas.SaveAs(fileName)
71 print("--> plot saved as:", fileName)
72
73
74b2.set_log_level(b2.LogLevel.ERROR)
75
76if '.txt' in globalTag:
77 b2.conditions.append_testing_payloads(globalTag)
78else:
79 b2.conditions.append_globaltag(globalTag)
80
81main = b2.create_path()
82main.add_module('EventInfoSetter', evtNumList=[1], runList=[runNo], expList=[expNo])
83main.add_module(MakePlots())
84b2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:50