17from ROOT
import PyConfig
18PyConfig.StartGuiThread =
False
21from ROOT
import Belle2
22from ROOT
import TH1F, TCanvas, TGraph
28 Simple event display of waveforms with feature extraction points
32 hist = [TH1F('h' + str(i),
'wf', 64 * 4, 0.0, 64.0 * 4)
for i
in range(4)]
34 hist[i].SetXTitle(
"sample number")
35 hist[i].SetYTitle(
"sample value [ADC counts]")
36 hist[i].SetLabelSize(0.06,
"XY")
37 hist[i].SetTitleSize(0.07,
"XY")
38 hist[i].SetTitleOffset(0.7,
"XY")
40 gpaint = [TGraph()
for i
in range(4)]
42 graphs = [[TGraph(5)]
for i
in range(4)]
44 tlpfgraphs = [[TGraph(2)]
for i
in range(4)]
46 c1 = TCanvas(
'c1',
'WF event display', 800, 800)
51 ''' Initialize the Module: open the canvas. '''
55 print(
'WARNING: Template Fit is still under development and currently returns wrong position for rising edge!.')
58 ''' wait for user respond '''
60 user_input = input(
"Press Enter to continue, P to print, or Q to quit ").lower().strip()
63 self.
c1.SaveAs(filename)
64 print(
'Canvas saved to file:', filename)
66 elif user_input ==
"q":
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)
189 tlpfgraph.SetPoint(0, tlpfResult.getRisingEdge(),
190 tlpfResult.getAmplitude() / 2 + tlpfResult.getBackgroundOffset())
191 tlpfgraph.SetPoint(1, tlpfResult.getRisingEdge(), tlpfResult.getBackgroundOffset())
192 print(
'Template Fit Chisquare: ', tlpfResult.getChisquare())
197 stat = self.
draw(k, event, run)
204 self.
draw(k, event, run)
207b2.set_log_level(b2.LogLevel.INFO)
210b2.conditions.override_globaltags()
211b2.conditions.append_globaltag(
'online')
214main = b2.create_path()
218roinput = b2.register_module(
'RootInput')
219main.add_module(roinput)
222rawconverter = b2.register_module(
'Convert2RawDet')
223main.add_module(rawconverter)
226main.add_module(
'TOPGeometryParInitializer')
229unpack = b2.register_module(
'TOPUnpacker')
230main.add_module(unpack)
233featureExtractor = b2.register_module(
'TOPWaveformFeatureExtractor')
234main.add_module(featureExtractor)
237converter = b2.register_module(
'TOPRawDigitConverter')
238converter.param(
'useSampleTimeCalibration',
False)
239converter.param(
'useChannelT0Calibration',
False)
240converter.param(
'useModuleT0Calibration',
False)
241converter.param(
'useCommonT0Calibration',
False)
242main.add_module(converter)
248progress = b2.register_module(
'Progress')
249main.add_module(progress)
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.