13from ROOT
import Belle2, TFile, TCanvas, gDirectory, TH1F, gROOT
24 print(
"usage: basf2", sys.argv[0],
"expNo runNo [globalTag/localDB]")
27expNo = int(sys.argv[1])
28runNo = int(sys.argv[2])
29globalTag =
"data_reprocessing_prompt"
31 globalTag = sys.argv[3]
35 ''' Extract pulse height distributions from TOPCalPhotonYields and save canvases into a root file '''
39 Makes a plot of pulse-height distributions of pixels of a single PMT and saves the canvas
40 :param h: a 2D histogram of pulse-height vs. pixel
41 :param slot: slot number
42 :param pmt: PMT number
45 name = 's' + f
'{slot:02d}' +
'_pmt' + f
'{pmt:02d}'
46 canvas = TCanvas(name,
"slot " + str(slot) +
" pmt " + str(pmt), 1000, 1000)
50 for pmtPix
in range(16):
51 col = ((pmt - 1) % 16) * 4 + pmtPix % 4
52 row = int((pmt - 1) / 16) * 4 + int(pmtPix / 4)
53 pix = row * 64 + col + 1
54 py = h.ProjectionY(
"px_" + str(slot) +
"_" + str(pix), pix, pix)
55 py.SetTitle(
"PMT pixel " + str(pmtPix + 1))
56 irow = int(pmtPix / 4)
58 canvas.cd(icol + (3 - irow) * 4 + 1)
60 if py.GetEntries() > 0:
62 meanPH += py.GetMean() * n
70 ''' initialize: implementation '''
78 fileName =
"pmtPulseHeights-" + time.strftime(
"%Y-%m-%d", time.localtime(db.getTimeStamp())) +
".root"
79 f = TFile.Open(fileName,
"recreate")
81 print(
"- global tag:", globalTag)
82 print(
"- time of measurement:",
83 time.strftime(
"%d %b %Y %H:%M:%S", time.localtime(db.getTimeStamp())),
"(mean), ",
84 round(db.getTimeStampStd() / 3600 / 24, 2),
"days (rms)")
87 for slot
in range(1, 17):
88 oldDir.mkdir(
"slot" + f
'{slot:02d}').cd()
89 h = db.getPulseHeights(slot)
92 hmean = TH1F(
'meanPH',
'slot ' + str(slot) +
'; PMT number; mean pulse-height', 32, 0.5, 32.5)
93 for pmt
in range(1, 33):
95 hmean.SetBinContent(pmt, meanPH)
99 canvas = TCanvas(
"meanPH",
"Mean pulse-heights", 1000, 1000)
101 for i, h
in enumerate(histos):
106 print(
"--> canvases saved to:", fileName)
109b2.set_log_level(b2.LogLevel.ERROR)
111if '.txt' in globalTag:
112 b2.conditions.append_testing_payloads(globalTag)
114 b2.conditions.append_globaltag(globalTag)
116main = b2.create_path()
117main.add_module(
'EventInfoSetter', evtNumList=[1], runList=[runNo], expList=[expNo])
Class to access a DBObjPtr from Python.
def makePlot(self, h, slot, pmt)