13 from ROOT
import Belle2, gROOT
14 from ROOT
import TNtuple, TFile, TH1F, TCanvas, TGraph, gStyle
17 parser = argparse.ArgumentParser(description=
'Extracts information about the FE parameters',
18 usage=
'%(prog)s [options]')
19 parser.add_argument(
'filename', help=
'name of data file')
23 help=
'whether to print out suspicious waveforms'
27 help=
'name of the ntuple file',
31 args = parser.parse_args()
33 b2.set_log_level(b2.LogLevel.INFO)
37 def wf_display(waveform, run, event, suffix=""):
42 Simple event display of waveforms with feature extraction points
45 hist = TH1F(
'h',
'wf', 64 * 4, 0.0, 64.0 * 4)
47 c1 = TCanvas(
'c1',
'WF event display', 800, 800)
50 hist.SetXTitle(
"sample number")
51 hist.SetYTitle(
"sample value [ADC counts]")
52 hist.SetLabelSize(0.06,
"XY")
53 hist.SetTitleSize(0.07,
"XY")
54 gStyle.SetTitleSize(0.07,
"t")
56 c1.SetBottomMargin(0.16)
57 c1.SetRightMargin(0.04)
58 hist.SetTitleOffset(1.3,
"Y")
59 hist.SetTitleOffset(1.0,
"X")
64 fname =
'waveforms_run' + str(run) +
'_event' + str(event) +
'_chan'
66 chan = waveform.getChannel()
67 asic = waveform.getASICNumber()
68 carr = waveform.getCarrierNumber()
69 bstk = (chan // 8 // 4 // 4) % 4
70 pdfFile = pdfFile +
'-' + str(chan)
72 wf = waveform.getWaveform()
74 numSamples = waveform.getSize()
75 hist.SetBins(numSamples, 0.0, float(numSamples))
76 title =
'channel: ' + str(chan % 8) +
' asic: ' + str(asic) \
77 +
' carrier: ' + str(carr) +
' BS: ' + str(bstk) +
' win:'
78 for window
in waveform.getStorageWindows():
79 title +=
' ' + str(window)
83 if not waveform.areWindowsInOrder():
88 hist.SetBinContent(i, sample)
90 rawDigits = waveform.getRelationsWith(
"TOPRawDigits")
93 graph.SetPoint(i, raw.getSampleRise() + 0.5, raw.getValueRise0())
95 graph.SetPoint(i, raw.getSampleRise() + 1.5, raw.getValueRise1())
97 graph.SetPoint(i, raw.getSamplePeak() + 0.5, raw.getValuePeak())
99 graph.SetPoint(i, raw.getSampleFall() + 0.5, raw.getValueFall0())
101 graph.SetPoint(i, raw.getSampleFall() + 1.5, raw.getValueFall1())
104 graph.SetMarkerColor(2)
105 if raw.isPedestalJump():
106 graph.SetMarkerColor(3)
108 graph.SetMarkerColor(4)
111 title =
'WF event display:' +
' run ' + str(run) +
' event ' \
115 graph.SetMarkerStyle(24)
118 c1.SaveAs(pdfFile + suffix +
'.pdf')
123 Analyzes waveform and FE data
127 ''' Initialize the Module: open the canvas. '''
134 ":fePeak1Ht:fePeak1TDC:fePeak1Wd"
135 ":fePeakHt:fePeakTDC:fePeakWd:fePeakIntegral"
136 ":nTOPRawDigits:ch:nNarrowPeaks:nInFirstWindow:nHeight150:nOscillations")
145 self.
ff = TFile.Open(args.output,
"RECREATE")
152 Event processor: get data and print to screen
155 event = evtMetaData.obj().getEvent()
156 run = evtMetaData.obj().
getRun()
158 for waveform
in waveforms:
159 chan = waveform.getChannel()
162 nInFirstWindow, nNarrowPeaks, nHeight150, nOscillations = 0, 0, 0, 0
165 wins = np.array(waveform.getStorageWindows())
166 if not np.all(wins[:-1] <= wins[1:]):
168 if False and args.plotWaveforms:
169 wf_display(waveform, run, event,
"windowOrder")
172 wf = np.array(waveform.getWaveform())
173 if False and args.plotWaveforms:
174 wf_display(waveform, run, event,
"general")
179 rawDigits = waveform.getRelationsWith(
"TOPRawDigits")
180 nTOPRawDigits = len(rawDigits)
182 if False and args.plotWaveforms
and nTOPRawDigits > 2:
184 wf_display(waveform, run, event,
"manyPeaks")
186 if False and args.plotWaveforms
and nTOPRawDigits > 3:
188 wf_display(waveform, run, event,
"tooManyPeaks")
191 fePeakHt = raw.getValuePeak()
192 fePeakTDC = raw.getSamplePeak()
193 fePeakWd = raw.getSampleFall() - raw.getSampleRise()
194 fePeakIntegral = raw.getIntegral()
198 if 0 < fePeakTDC < 65
and chan % 8 == 0:
201 if False and args.plotWaveforms:
202 wf_display(waveform, run, event,
"calPuls_firstWin")
206 if (140 < fePeakHt < 220)
and chan % 8 == 0:
207 if False and args.plotWaveforms:
208 wf_display(waveform, run, event,
"strangeADCBump_1")
210 if (300 < fePeakHt < 410)
and chan % 8 == 0:
211 if False and args.plotWaveforms:
212 wf_display(waveform, run, event,
"strangeADCBump_2")
219 if nTOPRawDigits > 1:
221 fePeak1Ht = rawDigits[1].getValuePeak()
222 fePeak1TDC = rawDigits[1].getSamplePeak()
223 fePeak1Wd = rawDigits[1].getSampleFall() - rawDigits[1].getSampleRise()
226 if nTOPRawDigits > 1
and fePeak1TDC < 64:
228 if False and args.plotWaveforms:
229 wf_display(waveform, run, event,
"secondPeakInFirstWindow")
232 if fePeakWd < 5
or nTOPRawDigits > 1
and fePeak1Wd < 5:
235 if False and args.plotWaveforms:
236 wf_display(waveform, run, event,
"thinpeak")
239 if 145 < fePeak1Ht < 155
and chan % 8 == 0:
242 if False and args.plotWaveforms:
243 wf_display(waveform, run, event,
"peak1Ht_is_150")
246 if nTOPRawDigits > 5
and (fePeakHt - fePeak1Ht) < 5:
251 if False and args.plotWaveforms:
252 wf_display(waveform, run, event,
"oscillations")
274 if args.plotWaveforms
and self.
plotCounterplotCounter >= 10:
275 evtMetaData.obj().setEndOfData()
279 self.
ff.WriteTObject(self.
fePropsfeProps)
281 print(
"# Waveforms:", self.
nWaveFormsnWaveForms)
289 b2.conditions.override_globaltags()
290 b2.conditions.append_globaltag(
'online')
293 main = b2.create_path()
295 reader = b2.register_module(
'RootInput')
297 reader.param(
'inputFileName', args.filename)
298 main.add_module(reader)
301 converter = b2.register_module(
'Convert2RawDet')
302 main.add_module(converter)
305 main.add_module(
'TOPGeometryParInitializer')
308 unpack = b2.register_module(
'TOPUnpacker')
309 main.add_module(unpack)
312 topfe = b2.register_module(
'TOPWaveformFeatureExtractor')
314 main.add_module(topfe)
318 main.add_module(drdh)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
static ExpRun getRun(std::map< ExpRun, std::pair< double, double >> runs, double t)
Get exp number + run number from time.