19 from ROOT
import PyConfig
20 PyConfig.StartGuiThread =
False
23 from ROOT
import Belle2
24 from ROOT
import TH1F, TCanvas, TGraph
30 Simple event display of waveforms with feature extraction points
34 hist = [TH1F(
'h' + str(i),
'wf', 64 * 4, 0.0, 64.0 * 4)
for i
in range(4)]
36 hist[i].SetXTitle(
"sample number")
37 hist[i].SetYTitle(
"sample value [ADC counts]")
38 hist[i].SetLabelSize(0.06,
"XY")
39 hist[i].SetTitleSize(0.07,
"XY")
40 hist[i].SetTitleOffset(0.7,
"XY")
42 gpaint = [TGraph()
for i
in range(4)]
44 graphs = [[TGraph(5)]
for i
in range(4)]
46 tlpfgraphs = [[TGraph(2)]
for i
in range(4)]
48 c1 = TCanvas(
'c1',
'WF event display', 800, 800)
53 ''' Initialize the Module: open the canvas. '''
55 self.
c1c1.Divide(1, 4)
57 print(
'WARNING: Template Fit is still under development and currently returns wrong position for rising edge!.')
60 ''' wait for user respond '''
62 user_input = input(
"Press Enter to continue, P to print, or Q to quit ").lower().strip()
65 self.
c1c1.SaveAs(filename)
66 print(
'Canvas saved to file:', filename)
68 elif user_input ==
"q":
70 evtMetaData.obj().setEndOfData()
75 def draw(self, k, event, run):
76 ''' Draw histograms and wait for user respond '''
79 self.
c1c1.Divide(1, 4)
80 title =
'WF event display:' +
' run ' + str(run) +
' event ' \
82 self.
c1c1.SetTitle(title)
85 self.
histhist[i].Draw()
86 if self.
gpaintgpaint[i].GetN() > 0:
87 self.
gpaintgpaint[i].Draw(
"same")
88 for graph
in self.
graphsgraphs[i]:
91 tlpfgraph.Draw(
"sameP")
93 stat = self.
waitwait()
97 ''' construct a graph to paint waveform differently after window discontinuity '''
99 if waveform.areWindowsInOrder():
100 self.
gpaintgpaint[k].Set(0)
102 windows = waveform.getStorageWindows()
104 for i
in range(1, windows.size()):
105 diff = windows[i] - windows[i - 1]
111 n = (windows.size() - i0) * 64 * 2
112 self.
gpaintgpaint[k].Set(n)
114 for i
in range(low, self.
histhist[k].GetNbinsX()):
115 x = self.
histhist[k].GetBinCenter(i + 1)
116 dx = self.
histhist[k].GetBinWidth(i + 1) / 2
117 y = self.
histhist[k].GetBinContent(i + 1)
119 self.
gpaintgpaint[k].SetPoint(ii, x - dx, y)
120 self.
gpaintgpaint[k].SetPoint(ii + 1, x + dx, y)
124 Event processor: fill the histograms, display them,
125 wait for user respond.
129 event = evtMetaData.obj().getEvent()
130 run = evtMetaData.obj().
getRun()
136 fname =
'waveforms_run' + str(run) +
'_event' + str(event) +
'_chan'
139 for waveform
in waveforms:
140 slot = waveform.getModuleID()
141 chan = waveform.getChannel()
143 wf = waveform.getWaveform()
144 self.
histhist[k].Reset()
145 numSamples = waveform.getSize()
146 startSample = waveform.getStartSample()
147 self.
histhist[k].SetBins(numSamples, float(startSample), float(startSample + numSamples))
148 title =
'S' + str(slot) +
' chan ' + str(chan) +
' win'
149 if waveform.getStorageWindows().empty():
150 title +=
' ' + str(waveform.getStorageWindow())
152 for window
in waveform.getStorageWindows():
153 title +=
' ' + str(window)
154 self.
histhist[k].SetTitle(title)
155 self.
histhist[k].SetStats(
False)
156 self.
histhist[k].SetLineColor(8)
161 self.
histhist[k].SetBinContent(i, sample)
163 self.
gpaintgpaint[k].SetLineColor(9)
166 rawDigits = waveform.getRelationsWith(
"TOPRawDigits")
167 self.
graphsgraphs[k].clear()
169 for raw
in rawDigits:
171 graph.SetMarkerStyle(24)
172 graph.SetPoint(0, raw.getSampleRise() + 0.5, raw.getValueRise0())
173 graph.SetPoint(1, raw.getSampleRise() + 1.5, raw.getValueRise1())
174 graph.SetPoint(2, raw.getSamplePeak() + 0.5, raw.getValuePeak())
175 graph.SetPoint(3, raw.getSampleFall() + 0.5, raw.getValueFall0())
176 graph.SetPoint(4, raw.getSampleFall() + 1.5, raw.getValueFall1())
177 if raw.isMadeOffline():
178 graph.SetMarkerStyle(5)
179 if raw.isFEValid()
and not raw.isAtWindowDiscontinuity():
180 graph.SetMarkerColor(2)
181 if raw.isPedestalJump():
182 graph.SetMarkerColor(3)
184 graph.SetMarkerColor(4)
185 self.
graphsgraphs[k].append(graph)
187 tlpfResult = raw.getRelated(
"TOPTemplateFitResults")
189 tlpfgraph = TGraph(2)
190 tlpfgraph.SetMarkerStyle(25)
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.use_central_database(
'data_reprocessing_proc8')
214 main = b2.create_path()
217 roinput = b2.register_module(
'SeqRootInput')
219 main.add_module(roinput)
222 rawconverter = b2.register_module(
'Convert2RawDet')
223 main.add_module(rawconverter)
226 main.add_module(
'TOPGeometryParInitializer')
229 unpack = b2.register_module(
'TOPUnpacker')
230 main.add_module(unpack)
233 featureExtractor = b2.register_module(
'TOPWaveformFeatureExtractor')
234 main.add_module(featureExtractor)
237 converter = b2.register_module(
'TOPRawDigitConverter')
238 converter.param(
'useSampleTimeCalibration',
False)
239 converter.param(
'useChannelT0Calibration',
False)
240 converter.param(
'useModuleT0Calibration',
False)
241 converter.param(
'useCommonT0Calibration',
False)
242 main.add_module(converter)
248 progress = b2.register_module(
'Progress')
249 main.add_module(progress)
a (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
static ExpRun getRun(map< ExpRun, pair< double, double >> runs, double t)
Get exp number + run number from time.