20from ROOT
import Belle2
24 """Analyze RPC lookback-window parameter settings, fill histograms"""
41 BKLM_MAXSTRIP_BIT = 15
43 BKLM_STRIP_MASK = 0x3f
45 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
47 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
49 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
51 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
53 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
55 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
57 def __init__(self, exp, run, histName, pdfName, mode, window):
61 exp (str): formatted experiment number
62 run (str): formatter run number
63 histName (str): path name of the output histogram ROOT file
64 pdfName (str): path name of the output histogram PDF file
65 mode (int): specifies the lookback-window mode
66 0: coarse window start values
67 1: coarse window width values
68 2: fine window start values
69 3: fine window width values
70 window (int, int, int): specifies the lookback-window min, max and step values
82 windowModes = {0: "coarse start", 1:
"coarse width", 2:
"fine start", 3:
"fine width"}
91 print(f
"Mode = {mode} start = {window[0]} end = {window[1]} step = {window[2]}")
94 """Handle job initialization: fill the mapping database, create histograms"""
96 expRun = f
'e{int(self.exp):02d}r{int(self.run)}: '
101 self.
sectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
103 self.
dcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
107 ROOT.gStyle.SetOptStat(10)
113 'mappedRPCTimeCal', expRun +
'RPC time distribution;t - t(trigger) (ns)', 256, -0.5, 1023.5)
119 label = f
"mappedRPCTimeCalByWindow{window:04x}"
120 title = f
"{expRun}RPC time distribution for lookback-window {self.windowMode} = {window:04x}" + \
121 ";t - t(trigger) (ns)"
131 expRun +
'Forward xy occupancy;x(cm);y(cm)',
132 230, -345.0, 345.0, 230, -345.0, 345.0)
135 expRun +
'Backward xy occupancy;x(cm);y(cm)',
136 230, -345.0, 345.0, 230, -345.0, 345.0)
145 label = f
"occupancyXYByWindow{window:04x}"
146 title = f
"{expRun}Forward xy occupancy for lookback-window {self.windowMode} = {window:04x};x(cm);y(cm)"
159 """Handle job termination: draw histograms, close output files"""
161 canvas = ROOT.TCanvas(
"canvas", self.
pdfName, 1600, 1600)
162 title = f
'{self.pdfName}['
166 canvas.GetPad(0).SetGrid(1, 1)
167 canvas.GetPad(0).Update()
169 hist_nEvents = ROOT.TH1F(
'nEvents',
170 f
'Number of events;Lookback-window {self.windowMode} value',
172 hist_nEvents.SetStats(
False)
173 hist_nEvents.SetMinimum(0)
174 values = array.array(
'd', [0])
178 hist_nEvents.SetContent(values)
179 hist_nEvents.Draw(
"HIST")
180 canvas.Print(self.
pdfName, f
"Title:{hist_nEvents.GetName()}")
181 hist_nRawKLMs = ROOT.TH1F(
'nRawKLMs',
182 f
'Mean number of RawKLM hits per event;Lookback-window {self.windowMode} value',
184 hist_nRawKLMs.SetStats(
False)
185 hist_nRawKLMs.SetMinimum(0)
186 ratios = array.array(
'd', [0])
187 errors = array.array(
'd', [0])
192 ratio = numerator / denominator
194 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
200 hist_nRawKLMs.SetContent(ratios)
201 hist_nRawKLMs.SetError(errors)
202 hist_nRawKLMs.Draw(
"E0 X0 L")
203 hist_nRawKLMs.Draw(
"HIST SAME")
204 canvas.Print(self.
pdfName, f
"Title:{hist_nRawKLMs.GetName()}")
205 hist_nHit2ds = ROOT.TH1F(
'nKLMHit2ds',
206 f
'Mean number of KLMHit2ds per event;Lookback-window {self.windowMode} value',
208 hist_nHit2ds.SetStats(
False)
209 hist_nHit2ds.SetMinimum(0)
210 ratios = array.array(
'd', [0])
211 errors = array.array(
'd', [0])
216 ratio = numerator / denominator
218 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
224 hist_nHit2ds.SetContent(ratios)
225 hist_nHit2ds.SetError(errors)
226 hist_nHit2ds.Draw(
"E0 X0 L")
227 hist_nHit2ds.Draw(
"HIST SAME")
228 canvas.Print(self.
pdfName, f
"Title:{hist_nHit2ds.GetName()}")
231 canvas.Print(self.
pdfName, f
"Title:{self.hist_mappedRPCTimeCal.GetName()}")
235 canvas.Print(self.
pdfName, f
"Title:{theHist.GetName()}")
238 canvas.Print(self.
pdfName, f
"Title:{self.hist_occupancyBackwardXY.GetName()}")
240 canvas.Print(self.
pdfName, f
"Title:{self.hist_occupancyForwardXY.GetName()}")
244 lastTitle = f
"Title:{theHist.GetName()}"
245 canvas.Print(self.
pdfName, lastTitle)
246 pdfNameLast = f
'{self.pdfName}]'
247 canvas.Print(pdfNameLast, lastTitle)
253 """Handle begin of run: print diagnostic message"""
255 print(
'beginRun', EventMetaData.getRun())
258 """Handle end of run: print diagnostic message"""
260 print(
'endRun', EventMetaData.getRun())
263 """Process one event: fill histograms"""
266 event = EventMetaData.getEvent()
272 for copper
in range(0, len(rawklms)):
273 rawklm = rawklms[copper]
274 if rawklm.GetNumEntries() != 1:
275 print(
'##0 Event', event,
'copper', copper,
' getNumEntries=', rawklm.GetNumEntries())
277 nodeID = rawklm.GetNodeID(0) - self.
BKLM_ID
280 if (nodeID < 0)
or (nodeID > 4):
282 trigCtime = (rawklm.GetTTCtime(0) & 0x7ffffff) << 3
283 for finesse
in range(0, 4):
284 dc = (finesse << 2) + (copper & 0x3)
286 nWords = rawklm.GetDetectorNwords(0, finesse)
289 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
290 lastWord = bufSlot[nWords - 1]
291 windowValue = (lastWord >> 16) & 0xffff
299 if lastWord & 0xffff != 0:
300 print(
"##1 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'lastWord=', hex(lastWord))
301 if (nWords % 2) == 0:
302 print(
"##2 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'should be odd -- skipping')
307 for j
in range(0, n):
308 word0 = bufSlot[j * 2]
309 word1 = bufSlot[j * 2 + 1]
310 ctime = word0 & 0xffff
311 channel = (word0 >> 16) & 0x7f
312 axis = (word0 >> 23) & 0x01
313 lane = (word0 >> 24) & 0x1f
314 flag = (word0 >> 30) & 0x03
315 tdc = (word1 >> 16) & 0x07ff
317 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
320 tCal = int(tdc - trigCtime) & 0x03ff
332 key = hit2d.getModuleID()
334 x = hit2d.getGlobalPositionX()
335 y = hit2d.getGlobalPositionY()
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
int EKLM_ID
COPPER base identifier for EKLM readout.
hist_mappedRPCTimeCalByWindow
reference to the RPC-time histogram for the currevent value of the lookback window parameter
hist_occupancyXYByWindow
reference to the xy scatterplot for the currevent value of the lookback window parameter
run
internal copy of run number
dict_nHit2ds
dictionary of the number of KLMHit2ds for each lookback-window value
hist_mappedRPCTimeCal
histogram of RPC TDC - trigger value
hist_occupancyBackwardXY
scatterplot of end view of backward BKLM for all KLMHit2ds
windowMaxValue
highest observed lookback-window value
hist_occupancyForwardXY
scatterplot of end view of forward BKLM for all KLMHit2ds
tuple BKLM_SECTION_MASK
bit mask for section [0..1]; forward is 0
dict_mappedRPCTimeCalByWindow
dictionary of histograms of RPC TDC - trigger value, keyed by lookback-window value
def __init__(self, exp, run, histName, pdfName, mode, window)
windowStepValue
lookback-window value step
dcToSectorFB
map for data concentrator -> sectorFB
int BKLM_ID
COPPER base identifier for BKLM readout.
dict_occupancyXYByWindow
dictionary of scatterplots of end view of forward BKLM, keyed by lookback-window value
exp
internal copy of experiment number
dict_nRawKLMs
dictionary of the number of RawKLM hits for each lookback-window value
windowMinValue
highest observed lookback-window value
int BKLM_SECTION_BIT
bit position for section [0..1]; forward is 0
pdfName
internal copy of the pathname of the output histogram PDF file
histogramFile
Output ROOT TFile that will contain the histograms/scatterplots.
histName
internal copy of the pathname of the output histogram ROOT file
dict_nEvents
dictionary of the number of events for each lookback-window value, for normalization
electIdToModuleId
readout <-> detector map (from the information retrieved from the conditions database)
windowMode
window mode as a string for histogram labels/titles
windowValue
cached value of the lookback-window value, to avoid unnecessary reassignments-to-same-value in event(...
sectorFBToDC
map for sectorFB -> data concentrator