18 from ROOT
import PyConfig
19 PyConfig.StartGuiThread =
False
22 from ROOT
import Belle2
23 from ROOT
import TH1F, TCanvas, TGraph
29 Simple event display of waveforms with feature extraction points
33 hist = [TH1F(
'h' + str(i),
'wf', 64 * 4, 0.0, 64.0 * 4)
for i
in range(4)]
35 hist[i].SetXTitle(
"sample number")
36 hist[i].SetYTitle(
"sample value [ADC counts]")
37 hist[i].SetLabelSize(0.06,
"XY")
38 hist[i].SetTitleSize(0.07,
"XY")
39 hist[i].SetTitleOffset(0.7,
"XY")
41 gpaint = [TGraph()
for i
in range(4)]
43 graphs = [[TGraph(5)]
for i
in range(4)]
45 tlpfgraphs = [[TGraph(2)]
for i
in range(4)]
47 c1 = TCanvas(
'c1',
'WF event display', 800, 800)
52 ''' Initialize the Module: open the canvas. '''
54 self.
c1c1.Divide(1, 4)
56 print(
'WARNING: Template Fit is still under development and currently returns wrong position for rising edge!.')
59 ''' wait for user respond '''
61 user_input = input(
"Press Enter to continue, P to print, or Q to quit ").lower().strip()
64 self.
c1c1.SaveAs(filename)
65 print(
'Canvas saved to file:', filename)
67 elif user_input ==
"q":
69 evtMetaData.obj().setEndOfData()
74 def draw(self, k, event, run):
75 ''' Draw histograms and wait for user respond '''
78 self.
c1c1.Divide(1, 4)
79 title =
'WF event display:' +
' run ' + str(run) +
' event ' \
81 self.
c1c1.SetTitle(title)
84 self.
histhist[i].Draw()
85 if self.
gpaintgpaint[i].GetN() > 0:
86 self.
gpaintgpaint[i].Draw(
"same")
87 for graph
in self.
graphsgraphs[i]:
90 tlpfgraph.Draw(
"sameP")
92 stat = self.
waitwait()
96 ''' construct a graph to paint waveform differently after window discontinuity '''
98 if waveform.areWindowsInOrder():
99 self.
gpaintgpaint[k].Set(0)
101 windows = waveform.getStorageWindows()
103 for i
in range(1, windows.size()):
104 diff = windows[i] - windows[i - 1]
110 n = (windows.size() - i0) * 64 * 2
111 self.
gpaintgpaint[k].Set(n)
113 for i
in range(low, self.
histhist[k].GetNbinsX()):
114 x = self.
histhist[k].GetBinCenter(i + 1)
115 dx = self.
histhist[k].GetBinWidth(i + 1) / 2
116 y = self.
histhist[k].GetBinContent(i + 1)
118 self.
gpaintgpaint[k].SetPoint(ii, x - dx, y)
119 self.
gpaintgpaint[k].SetPoint(ii + 1, x + dx, y)
123 Event processor: fill the histograms, display them,
124 wait for user respond.
128 event = evtMetaData.obj().getEvent()
129 run = evtMetaData.obj().
getRun()
135 fname =
'waveforms_run' + str(run) +
'_event' + str(event) +
'_chan'
138 for waveform
in waveforms:
139 slot = waveform.getModuleID()
140 chan = waveform.getChannel()
142 wf = waveform.getWaveform()
143 self.
histhist[k].Reset()
144 numSamples = waveform.getSize()
145 startSample = waveform.getStartSample()
146 self.
histhist[k].SetBins(numSamples, float(startSample), float(startSample + numSamples))
147 title =
'S' + str(slot) +
' chan ' + str(chan) +
' win'
148 if waveform.getStorageWindows().empty():
149 title +=
' ' + str(waveform.getStorageWindow())
151 for window
in waveform.getStorageWindows():
152 title +=
' ' + str(window)
153 self.
histhist[k].SetTitle(title)
154 self.
histhist[k].SetStats(
False)
155 self.
histhist[k].SetLineColor(8)
160 self.
histhist[k].SetBinContent(i, sample)
162 self.
gpaintgpaint[k].SetLineColor(9)
165 rawDigits = waveform.getRelationsWith(
"TOPRawDigits")
166 self.
graphsgraphs[k].clear()
168 for raw
in rawDigits:
170 graph.SetMarkerStyle(24)
171 graph.SetPoint(0, raw.getSampleRise() + 0.5, raw.getValueRise0())
172 graph.SetPoint(1, raw.getSampleRise() + 1.5, raw.getValueRise1())
173 graph.SetPoint(2, raw.getSamplePeak() + 0.5, raw.getValuePeak())
174 graph.SetPoint(3, raw.getSampleFall() + 0.5, raw.getValueFall0())
175 graph.SetPoint(4, raw.getSampleFall() + 1.5, raw.getValueFall1())
176 if raw.isMadeOffline():
177 graph.SetMarkerStyle(5)
178 if raw.isFEValid()
and not raw.isAtWindowDiscontinuity():
179 graph.SetMarkerColor(2)
180 if raw.isPedestalJump():
181 graph.SetMarkerColor(3)
183 graph.SetMarkerColor(4)
184 self.
graphsgraphs[k].append(graph)
186 tlpfResult = raw.getRelated(
"TOPTemplateFitResults")
188 tlpfgraph = TGraph(2)
189 tlpfgraph.SetMarkerStyle(25)
190 tlpfgraph.SetPoint(0, tlpfResult.getRisingEdge(),
191 tlpfResult.getAmplitude() / 2 + tlpfResult.getBackgroundOffset())
192 tlpfgraph.SetPoint(1, tlpfResult.getRisingEdge(), tlpfResult.getBackgroundOffset())
193 print(
'Template Fit Chisquare: ', tlpfResult.getChisquare())
194 self.
tlpfgraphstlpfgraphs[k].append(tlpfgraph)
198 stat = self.
drawdraw(k, event, run)
205 self.
drawdraw(k, event, run)
208 b2.set_log_level(b2.LogLevel.INFO)
211 b2.conditions.override_globaltags()
212 b2.conditions.append_globaltag(
'online')
215 main = b2.create_path()
219 roinput = b2.register_module(
'RootInput')
220 main.add_module(roinput)
223 rawconverter = b2.register_module(
'Convert2RawDet')
224 main.add_module(rawconverter)
227 main.add_module(
'TOPGeometryParInitializer')
230 unpack = b2.register_module(
'TOPUnpacker')
231 main.add_module(unpack)
234 featureExtractor = b2.register_module(
'TOPWaveformFeatureExtractor')
235 main.add_module(featureExtractor)
238 converter = b2.register_module(
'TOPRawDigitConverter')
239 converter.param(
'useSampleTimeCalibration',
False)
240 converter.param(
'useChannelT0Calibration',
False)
241 converter.param(
'useModuleT0Calibration',
False)
242 converter.param(
'useCommonT0Calibration',
False)
243 main.add_module(converter)
249 progress = b2.register_module(
'Progress')
250 main.add_module(progress)
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.