14 from ROOT
import Belle2, TH1F, TH2F, TCanvas, THistPainter, TPad
18 """Analyze RPC lookback-window parameter settings, fill histograms"""
35 BKLM_MAXSTRIP_BIT = 15
37 BKLM_STRIP_MASK = 0x3f
39 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
41 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
43 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
45 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
47 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
49 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
51 def __init__(self, exp, run, histName, pdfName, mode, window):
55 exp (str): formatted experiment number
56 run (str): formatter run number
57 histName (str): path name of the output histogram ROOT file
58 pdfName (str): path name of the output histogram PDF file
59 mode (int): specifies the lookback-window mode
60 0: coarse window start values
61 1: coarse window width values
62 2: fine window start values
63 3: fine window width values
64 window (int, int, int): specifies the lookback-window min, max and step values
76 windowModes = {0:
"coarse start", 1:
"coarse width", 2:
"fine start", 3:
"fine width"}
85 print(
"Mode = {0} start = {1} end = {2} step = {3}".format(mode, window[0], window[1], window[2]))
88 """Handle job initialization: fill the mapping database, create histograms"""
90 expRun =
'e{0:02d}r{1}: '.format(int(self.
exp), int(self.
run))
95 self.
sectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
97 self.
dcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
101 ROOT.gStyle.SetOptStat(10)
107 'mappedRPCTimeCal', expRun +
'RPC time distribution;t - t(trigger) (ns)', 256, -0.5, 1023.5)
113 label =
"mappedRPCTimeCalByWindow{0:04x}".format(window)
114 title =
"{0}RPC time distribution for lookback-window {1} = {2:04x}".format(
115 expRun, self.
windowMode, window) +
";t - t(trigger) (ns)"
125 expRun +
'Forward xy occupancy;x(cm);y(cm)',
126 230, -345.0, 345.0, 230, -345.0, 345.0)
129 expRun +
'Backward xy occupancy;x(cm);y(cm)',
130 230, -345.0, 345.0, 230, -345.0, 345.0)
139 label =
"occupancyXYByWindow{0:04x}".format(window)
140 title =
"{0}Forward xy occupancy for lookback-window {1} = {2:04x};x(cm);y(cm)".format(expRun, self.
windowMode, window)
153 """Handle job termination: draw histograms, close output files"""
155 canvas = ROOT.TCanvas(
"canvas", self.
pdfName, 1600, 1600)
156 title =
'{0}['.format(self.
pdfName)
160 canvas.GetPad(0).SetGrid(1, 1)
161 canvas.GetPad(0).Update()
163 hist_nEvents = ROOT.TH1F(
'nEvents',
164 'Number of events;Lookback-window {0} value'.format(self.
windowMode),
166 hist_nEvents.SetStats(
False)
167 hist_nEvents.SetMinimum(0)
168 values = array.array(
'd', [0])
172 hist_nEvents.SetContent(values)
173 hist_nEvents.Draw(
"HIST")
174 canvas.Print(self.
pdfName,
"Title:{0}".format(hist_nEvents.GetName()))
175 hist_nRawKLMs = ROOT.TH1F(
'nRawKLMs',
176 'Mean number of RawKLM hits per event;Lookback-window {0} value'.format(self.
windowMode),
178 hist_nRawKLMs.SetStats(
False)
179 hist_nRawKLMs.SetMinimum(0)
180 ratios = array.array(
'd', [0])
181 errors = array.array(
'd', [0])
186 ratio = numerator / denominator
188 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
194 hist_nRawKLMs.SetContent(ratios)
195 hist_nRawKLMs.SetError(errors)
196 hist_nRawKLMs.Draw(
"E0 X0 L")
197 hist_nRawKLMs.Draw(
"HIST SAME")
198 canvas.Print(self.
pdfName,
"Title:{0}".format(hist_nRawKLMs.GetName()))
199 hist_nHit2ds = ROOT.TH1F(
'nBKLMHit2ds',
200 'Mean number of BKLMHit2ds per event;Lookback-window {0} value'.format(self.
windowMode),
202 hist_nHit2ds.SetStats(
False)
203 hist_nHit2ds.SetMinimum(0)
204 ratios = array.array(
'd', [0])
205 errors = array.array(
'd', [0])
210 ratio = numerator / denominator
212 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
218 hist_nHit2ds.SetContent(ratios)
219 hist_nHit2ds.SetError(errors)
220 hist_nHit2ds.Draw(
"E0 X0 L")
221 hist_nHit2ds.Draw(
"HIST SAME")
222 canvas.Print(self.
pdfName,
"Title:{0}".format(hist_nHit2ds.GetName()))
229 canvas.Print(self.
pdfName,
"Title:{0}".format(theHist.GetName()))
238 lastTitle =
"Title:{0}".format(theHist.GetName())
239 canvas.Print(self.
pdfName, lastTitle)
240 pdfNameLast =
'{0}]'.format(self.
pdfName)
241 canvas.Print(pdfNameLast, lastTitle)
247 """Handle begin of run: print diagnostic message"""
249 print(
'beginRun', EventMetaData.getRun())
252 """Handle end of run: print diagnostic message"""
254 print(
'endRun', EventMetaData.getRun())
257 """Process one event: fill histograms"""
260 event = EventMetaData.getEvent()
266 for copper
in range(0, len(rawklms)):
267 rawklm = rawklms[copper]
268 if rawklm.GetNumEntries() != 1:
269 print(
'##0 Event', event,
'copper', copper,
' getNumEntries=', rawklm.GetNumEntries())
271 nodeID = rawklm.GetNodeID(0) - self.
BKLM_ID
274 if (nodeID < 0)
or (nodeID > 4):
276 trigCtime = (rawklm.GetTTCtime(0) & 0x7ffffff) << 3
277 for finesse
in range(0, 4):
278 dc = (finesse << 2) + (copper & 0x3)
280 nWords = rawklm.GetDetectorNwords(0, finesse)
283 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
284 lastWord = bufSlot[nWords - 1]
285 windowValue = (lastWord >> 16) & 0xffff
293 if lastWord & 0xffff != 0:
294 print(
"##1 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'lastWord=', hex(lastWord))
295 if (nWords % 2) == 0:
296 print(
"##2 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'should be odd -- skipping')
301 for j
in range(0, n):
302 word0 = bufSlot[j * 2]
303 word1 = bufSlot[j * 2 + 1]
304 ctime = word0 & 0xffff
305 channel = (word0 >> 16) & 0x7f
306 axis = (word0 >> 23) & 0x01
307 lane = (word0 >> 24) & 0x1f
308 flag = (word0 >> 30) & 0x03
309 tdc = (word1 >> 16) & 0x07ff
311 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
314 tCal = int(tdc - trigCtime) & 0x03ff
326 key = hit2d.getModuleID()
328 x = hit2d.getGlobalPositionX()
329 y = hit2d.getGlobalPositionY()