21 from ROOT
import Belle2
25 """Analyze RPC lookback-window parameter settings, fill histograms"""
42 BKLM_MAXSTRIP_BIT = 15
44 BKLM_STRIP_MASK = 0x3f
46 BKLM_PLANE_MASK = (1 << BKLM_PLANE_BIT)
48 BKLM_LAYER_MASK = (15 << BKLM_LAYER_BIT)
50 BKLM_SECTOR_MASK = (7 << BKLM_SECTOR_BIT)
52 BKLM_SECTION_MASK = (1 << BKLM_SECTION_BIT)
54 BKLM_MAXSTRIP_MASK = (63 << BKLM_MAXSTRIP_BIT)
56 BKLM_MODULEID_MASK = (BKLM_SECTION_MASK | BKLM_SECTOR_MASK | BKLM_LAYER_MASK)
58 def __init__(self, exp, run, histName, pdfName, mode, window):
62 exp (str): formatted experiment number
63 run (str): formatter run number
64 histName (str): path name of the output histogram ROOT file
65 pdfName (str): path name of the output histogram PDF file
66 mode (int): specifies the lookback-window mode
67 0: coarse window start values
68 1: coarse window width values
69 2: fine window start values
70 3: fine window width values
71 window (int, int, int): specifies the lookback-window min, max and step values
83 windowModes = {0:
"coarse start", 1:
"coarse width", 2:
"fine start", 3:
"fine width"}
92 print(
"Mode = {0} start = {1} end = {2} step = {3}".format(mode, window[0], window[1], window[2]))
95 """Handle job initialization: fill the mapping database, create histograms"""
97 expRun =
'e{0:02d}r{1}: '.format(int(self.
expexp), int(self.
runrun))
102 self.
sectorFBToDCsectorFBToDC = [11, 15, 2, 6, 10, 14, 3, 7, 9, 13, 0, 4, 8, 12, 1, 5]
104 self.
dcToSectorFBdcToSectorFB = [10, 14, 2, 6, 11, 15, 3, 7, 12, 8, 4, 0, 13, 9, 5, 1]
108 ROOT.gStyle.SetOptStat(10)
114 'mappedRPCTimeCal', expRun +
'RPC time distribution;t - t(trigger) (ns)', 256, -0.5, 1023.5)
120 label =
"mappedRPCTimeCalByWindow{0:04x}".format(window)
121 title =
"{0}RPC time distribution for lookback-window {1} = {2:04x}".format(
122 expRun, self.
windowModewindowMode, window) +
";t - t(trigger) (ns)"
132 expRun +
'Forward xy occupancy;x(cm);y(cm)',
133 230, -345.0, 345.0, 230, -345.0, 345.0)
136 expRun +
'Backward xy occupancy;x(cm);y(cm)',
137 230, -345.0, 345.0, 230, -345.0, 345.0)
146 label =
"occupancyXYByWindow{0:04x}".format(window)
147 title =
"{0}Forward xy occupancy for lookback-window {1} = {2:04x};x(cm);y(cm)".format(expRun, self.
windowModewindowMode, window)
148 self.
dict_occupancyXYByWindowdict_occupancyXYByWindow[window] = ROOT.TH2F(label, title, 230, -345.0, 345.0, 230, -345.0, 345.0)
160 """Handle job termination: draw histograms, close output files"""
162 canvas = ROOT.TCanvas(
"canvas", self.
pdfNamepdfName, 1600, 1600)
163 title =
'{0}['.format(self.
pdfNamepdfName)
167 canvas.GetPad(0).SetGrid(1, 1)
168 canvas.GetPad(0).Update()
170 hist_nEvents = ROOT.TH1F(
'nEvents',
171 'Number of events;Lookback-window {0} value'.format(self.
windowModewindowMode),
173 hist_nEvents.SetStats(
False)
174 hist_nEvents.SetMinimum(0)
175 values = array.array(
'd', [0])
179 hist_nEvents.SetContent(values)
180 hist_nEvents.Draw(
"HIST")
181 canvas.Print(self.
pdfNamepdfName,
"Title:{0}".format(hist_nEvents.GetName()))
182 hist_nRawKLMs = ROOT.TH1F(
'nRawKLMs',
183 'Mean number of RawKLM hits per event;Lookback-window {0} value'.format(self.
windowModewindowMode),
185 hist_nRawKLMs.SetStats(
False)
186 hist_nRawKLMs.SetMinimum(0)
187 ratios = array.array(
'd', [0])
188 errors = array.array(
'd', [0])
193 ratio = numerator / denominator
195 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
201 hist_nRawKLMs.SetContent(ratios)
202 hist_nRawKLMs.SetError(errors)
203 hist_nRawKLMs.Draw(
"E0 X0 L")
204 hist_nRawKLMs.Draw(
"HIST SAME")
205 canvas.Print(self.
pdfNamepdfName,
"Title:{0}".format(hist_nRawKLMs.GetName()))
206 hist_nHit2ds = ROOT.TH1F(
'nBKLMHit2ds',
207 'Mean number of BKLMHit2ds per event;Lookback-window {0} value'.format(self.
windowModewindowMode),
209 hist_nHit2ds.SetStats(
False)
210 hist_nHit2ds.SetMinimum(0)
211 ratios = array.array(
'd', [0])
212 errors = array.array(
'd', [0])
217 ratio = numerator / denominator
219 errors.append(math.sqrt(ratio * (ratio + 1.0) / denominator))
225 hist_nHit2ds.SetContent(ratios)
226 hist_nHit2ds.SetError(errors)
227 hist_nHit2ds.Draw(
"E0 X0 L")
228 hist_nHit2ds.Draw(
"HIST SAME")
229 canvas.Print(self.
pdfNamepdfName,
"Title:{0}".format(hist_nHit2ds.GetName()))
236 canvas.Print(self.
pdfNamepdfName,
"Title:{0}".format(theHist.GetName()))
245 lastTitle =
"Title:{0}".format(theHist.GetName())
246 canvas.Print(self.
pdfNamepdfName, lastTitle)
247 pdfNameLast =
'{0}]'.format(self.
pdfNamepdfName)
248 canvas.Print(pdfNameLast, lastTitle)
254 """Handle begin of run: print diagnostic message"""
256 print(
'beginRun', EventMetaData.getRun())
259 """Handle end of run: print diagnostic message"""
261 print(
'endRun', EventMetaData.getRun())
264 """Process one event: fill histograms"""
267 event = EventMetaData.getEvent()
273 for copper
in range(0, len(rawklms)):
274 rawklm = rawklms[copper]
275 if rawklm.GetNumEntries() != 1:
276 print(
'##0 Event', event,
'copper', copper,
' getNumEntries=', rawklm.GetNumEntries())
278 nodeID = rawklm.GetNodeID(0) - self.
BKLM_IDBKLM_ID
281 if (nodeID < 0)
or (nodeID > 4):
283 trigCtime = (rawklm.GetTTCtime(0) & 0x7ffffff) << 3
284 for finesse
in range(0, 4):
285 dc = (finesse << 2) + (copper & 0x3)
287 nWords = rawklm.GetDetectorNwords(0, finesse)
290 bufSlot = rawklm.GetDetectorBuffer(0, finesse)
291 lastWord = bufSlot[nWords - 1]
292 windowValue = (lastWord >> 16) & 0xffff
300 if lastWord & 0xffff != 0:
301 print(
"##1 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'lastWord=', hex(lastWord))
302 if (nWords % 2) == 0:
303 print(
"##2 Event", event,
'copper', copper,
'finesse', finesse,
'n=', nWords,
'should be odd -- skipping')
308 for j
in range(0, n):
309 word0 = bufSlot[j * 2]
310 word1 = bufSlot[j * 2 + 1]
311 ctime = word0 & 0xffff
312 channel = (word0 >> 16) & 0x7f
313 axis = (word0 >> 23) & 0x01
314 lane = (word0 >> 24) & 0x1f
315 flag = (word0 >> 30) & 0x03
316 tdc = (word1 >> 16) & 0x07ff
318 electId = (channel << 12) | (axis << 11) | (lane << 6) | (finesse << 4) | nodeID
321 tCal = int(tdc - trigCtime) & 0x03ff
333 key = hit2d.getModuleID()
335 x = hit2d.getGlobalPositionX()
336 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 BKLMHit2ds for each lookback-window value
hist_mappedRPCTimeCal
histogram of RPC TDC - trigger value
hist_occupancyBackwardXY
scatterplot of end view of backward BKLM for all BKLMHit2ds
windowMaxValue
highest observed lookback-window value
hist_occupancyForwardXY
scatterplot of end view of forward BKLM for all BKLMHit2ds
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