11 from ROOT
import PyConfig
12 PyConfig.StartGuiThread =
False
16 from ROOT
import Belle2
17 from ROOT
import TH1F, TCanvas, TGraph
23 Simple event display of waveforms with feature extraction points
27 hist = [TH1F(
'h' + str(i),
'wf', 64 * 4, 0.0, 64.0 * 4)
for i
in range(4)]
29 hist[i].SetXTitle(
"sample number")
30 hist[i].SetYTitle(
"sample value [ADC counts]")
31 hist[i].SetLabelSize(0.06,
"XY")
32 hist[i].SetTitleSize(0.07,
"XY")
33 hist[i].SetTitleOffset(0.7,
"XY")
35 gpaint = [TGraph()
for i
in range(4)]
37 graphs = [[TGraph(5)]
for i
in range(4)]
39 tlpfgraphs = [[TGraph(2)]
for i
in range(4)]
41 c1 = TCanvas(
'c1',
'WF event display', 800, 800)
46 ''' Initialize the Module: open the canvas. '''
50 print(
'WARNING: Template Fit is still under development and currently returns wrong position for rising edge!.')
53 ''' wait for user respond '''
60 abc =
eval(input(
'Type <CR> to continue, P to print or Q to quit '))
62 filename = self.
pdfFile +
'.pdf'
63 self.
c1.SaveAs(filename)
64 print(
'Canvas saved to file:', filename)
68 evtMetaData.obj().setEndOfData()
73 def draw(self, k, event, run):
74 ''' Draw histograms and wait for user respond '''
78 title =
'WF event display:' +
' run ' + str(run) +
' event ' \
80 self.
c1.SetTitle(title)
84 if self.
gpaint[i].GetN() > 0:
85 self.
gpaint[i].Draw(
"same")
86 for graph
in self.
graphs[i]:
89 tlpfgraph.Draw(
"sameP")
95 ''' construct a graph to paint waveform differently after window discontinuity '''
97 if waveform.areWindowsInOrder():
100 windows = waveform.getStorageWindows()
102 for i
in range(1, windows.size()):
103 diff = windows[i] - windows[i - 1]
109 n = (windows.size() - i0) * 64 * 2
112 for i
in range(low, self.
hist[k].GetNbinsX()):
113 x = self.
hist[k].GetBinCenter(i + 1)
114 dx = self.
hist[k].GetBinWidth(i + 1) / 2
115 y = self.
hist[k].GetBinContent(i + 1)
117 self.
gpaint[k].SetPoint(ii, x - dx, y)
118 self.
gpaint[k].SetPoint(ii + 1, x + dx, y)
122 Event processor: fill the histograms, display them,
123 wait for user respond.
127 event = evtMetaData.obj().getEvent()
128 run = evtMetaData.obj().
getRun()
134 fname =
'waveforms_run' + str(run) +
'_event' + str(event) +
'_chan'
137 for waveform
in waveforms:
138 slot = waveform.getModuleID()
139 chan = waveform.getChannel()
141 wf = waveform.getWaveform()
143 numSamples = waveform.getSize()
144 startSample = waveform.getStartSample()
145 self.
hist[k].SetBins(numSamples, float(startSample), float(startSample + numSamples))
146 title =
'S' + str(slot) +
' chan ' + str(chan) +
' win'
147 if waveform.getStorageWindows().empty():
148 title +=
' ' + str(waveform.getStorageWindow())
150 for window
in waveform.getStorageWindows():
151 title +=
' ' + str(window)
152 self.
hist[k].SetTitle(title)
153 self.
hist[k].SetStats(
False)
154 self.
hist[k].SetLineColor(8)
159 self.
hist[k].SetBinContent(i, sample)
161 self.
gpaint[k].SetLineColor(9)
164 rawDigits = waveform.getRelationsWith(
"TOPRawDigits")
167 for raw
in rawDigits:
169 graph.SetMarkerStyle(24)
170 graph.SetPoint(0, raw.getSampleRise() + 0.5, raw.getValueRise0())
171 graph.SetPoint(1, raw.getSampleRise() + 1.5, raw.getValueRise1())
172 graph.SetPoint(2, raw.getSamplePeak() + 0.5, raw.getValuePeak())
173 graph.SetPoint(3, raw.getSampleFall() + 0.5, raw.getValueFall0())
174 graph.SetPoint(4, raw.getSampleFall() + 1.5, raw.getValueFall1())
175 if raw.isMadeOffline():
176 graph.SetMarkerStyle(5)
177 if raw.isFEValid()
and not raw.isAtWindowDiscontinuity():
178 graph.SetMarkerColor(2)
179 if raw.isPedestalJump():
180 graph.SetMarkerColor(3)
182 graph.SetMarkerColor(4)
183 self.
graphs[k].append(graph)
185 tlpfResult = raw.getRelated(
"TOPTemplateFitResults")
187 tlpfgraph = TGraph(2)
188 tlpfgraph.SetMarkerStyle(25)
191 print(
'Template Fit Chisquare: ', tlpfResult.getChisquare())
196 stat = self.
draw(k, event, run)
203 self.
draw(k, event, run)
206 set_log_level(LogLevel.INFO)
209 use_central_database(
'data_reprocessing_proc8')
215 roinput = register_module(
'SeqRootInput')
217 main.add_module(roinput)
220 rawconverter = register_module(
'Convert2RawDet')
221 main.add_module(rawconverter)
224 main.add_module(
'TOPGeometryParInitializer')
227 unpack = register_module(
'TOPUnpacker')
228 main.add_module(unpack)
231 featureExtractor = register_module(
'TOPWaveformFeatureExtractor')
232 main.add_module(featureExtractor)
235 converter = register_module(
'TOPRawDigitConverter')
236 converter.param(
'useSampleTimeCalibration',
False)
237 converter.param(
'useChannelT0Calibration',
False)
238 converter.param(
'useModuleT0Calibration',
False)
239 converter.param(
'useCommonT0Calibration',
False)
240 main.add_module(converter)
246 progress = register_module(
'Progress')
247 main.add_module(progress)