Belle II Software development
WFDisplay Class Reference
Inheritance diagram for WFDisplay:

Public Member Functions

def initialize (self)
 
def wait (self)
 
def draw (self, k, event, run)
 
def set_gpaint (self, waveform, k)
 
def event (self)
 

Public Attributes

 pdfFile
 output file name
 

Static Public Attributes

list hist = [TH1F('h' + str(i), 'wf', 64 * 4, 0.0, 64.0 * 4) for i in range(4)]
 1D histograms
 
list gpaint = [TGraph() for i in range(4)]
 graphs for painting waveforms after the gap in window number
 
list graphs = [[TGraph(5)] for i in range(4)]
 graphs for FE points
 
list tlpfgraphs = [[TGraph(2)] for i in range(4)]
 graphs for template fit points
 
TCanvas c1 = TCanvas('c1', 'WF event display', 800, 800)
 canvas
 
str pdfFile = 'waveforms'
 output file name
 

Detailed Description

Simple event display of waveforms with feature extraction points

Definition at line 25 of file showFEWaveforms.py.

Member Function Documentation

◆ draw()

def draw (   self,
  k,
  event,
  run 
)
 Draw histograms and wait for user respond 

Definition at line 73 of file showFEWaveforms.py.

73 def draw(self, k, event, run):
74 ''' Draw histograms and wait for user respond '''
75
76 self.c1.Clear()
77 self.c1.Divide(1, 4)
78 title = 'WF event display:' + ' run ' + str(run) + ' event ' \
79 + str(event)
80 self.c1.SetTitle(title)
81 for i in range(k):
82 self.c1.cd(i + 1)
83 self.hist[i].Draw()
84 if self.gpaint[i].GetN() > 0:
85 self.gpaint[i].Draw("same")
86 for graph in self.graphs[i]:
87 graph.Draw("sameP")
88 for tlpfgraph in self.tlpfgraphs[i]:
89 tlpfgraph.Draw("sameP")
90 self.c1.Update()
91 stat = self.wait()
92 return stat
93

◆ event()

def event (   self)
Event processor: fill the histograms, display them,
wait for user respond.

Definition at line 120 of file showFEWaveforms.py.

120 def event(self):
121 '''
122 Event processor: fill the histograms, display them,
123 wait for user respond.
124 '''
125
126 evtMetaData = Belle2.PyStoreObj('EventMetaData')
127 event = evtMetaData.obj().getEvent()
128 run = evtMetaData.obj().getRun()
129
130 waveforms = Belle2.PyStoreArray('TOPRawWaveforms')
131
132 k = 0
133 # nHits = 0
134 fname = 'waveforms_run' + str(run) + '_event' + str(event) + '_chan'
135
136 self.pdfFile = fname
137 for waveform in waveforms:
138 slot = waveform.getModuleID()
139 chan = waveform.getChannel()
140 self.pdfFile = self.pdfFile + '-S' + str(slot) + '_' + str(chan)
141 wf = waveform.getWaveform()
142 self.hist[k].Reset()
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())
149 else:
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)
155
156 i = 0
157 for sample in wf:
158 i = i + 1
159 self.hist[k].SetBinContent(i, sample)
160
161 self.gpaint[k].SetLineColor(9)
162 self.set_gpaint(waveform, k)
163
164 rawDigits = waveform.getRelationsWith("TOPRawDigits")
165 self.graphs[k].clear()
166 self.tlpfgraphs[k].clear()
167 for raw in rawDigits:
168 graph = TGraph(5)
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)
181 else:
182 graph.SetMarkerColor(4)
183 self.graphs[k].append(graph)
184
185 tlpfResult = raw.getRelated("TOPTemplateFitResults")
186 if tlpfResult:
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())
193 self.tlpfgraphs[k].append(tlpfgraph)
194
195 k = k + 1
196 if k == 4:
197 stat = self.draw(k, event, run)
198 if stat:
199 return
200 k = 0
201 self.pdfFile = fname
202
203 if k > 0:
204 self.draw(k, event, run)
205
206
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67

◆ initialize()

def initialize (   self)
 Initialize the Module: open the canvas. 

Definition at line 50 of file showFEWaveforms.py.

50 def initialize(self):
51 ''' Initialize the Module: open the canvas. '''
52
53 self.c1.Divide(1, 4)
54 self.c1.Show()
55 print('WARNING: Template Fit is still under development and currently returns wrong position for rising edge!.')
56

◆ set_gpaint()

def set_gpaint (   self,
  waveform,
  k 
)
 construct a graph to paint waveform differently after window discontinuity 

Definition at line 94 of file showFEWaveforms.py.

94 def set_gpaint(self, waveform, k):
95 ''' construct a graph to paint waveform differently after window discontinuity '''
96
97 if waveform.areWindowsInOrder():
98 self.gpaint[k].Set(0)
99
100 windows = waveform.getStorageWindows()
101 i0 = windows.size()
102 for i in range(1, windows.size()):
103 diff = windows[i] - windows[i - 1]
104 if diff < 0:
105 diff += 512
106 if diff != 1:
107 i0 = i
108 break
109 n = (windows.size() - i0) * 64 * 2
110 self.gpaint[k].Set(n)
111 low = i0 * 64
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)
116 ii = (i - low) * 2
117 self.gpaint[k].SetPoint(ii, x - dx, y)
118 self.gpaint[k].SetPoint(ii + 1, x + dx, y)
119

◆ wait()

def wait (   self)
 wait for user respond 

Definition at line 57 of file showFEWaveforms.py.

57 def wait(self):
58 ''' wait for user respond '''
59
60 user_input = input("Press Enter to continue, P to print, or Q to quit ").lower().strip()
61 if user_input == "p":
62 filename = self.pdfFile + '.pdf'
63 self.c1.SaveAs(filename)
64 print('Canvas saved to file:', filename)
65 return False
66 elif user_input == "q":
67 evtMetaData = Belle2.PyStoreObj('EventMetaData')
68 evtMetaData.obj().setEndOfData()
69 return True
70 else:
71 return False
72

Member Data Documentation

◆ c1

TCanvas c1 = TCanvas('c1', 'WF event display', 800, 800)
static

canvas

Definition at line 46 of file showFEWaveforms.py.

◆ gpaint

list gpaint = [TGraph() for i in range(4)]
static

graphs for painting waveforms after the gap in window number

Definition at line 40 of file showFEWaveforms.py.

◆ graphs

list graphs = [[TGraph(5)] for i in range(4)]
static

graphs for FE points

Definition at line 42 of file showFEWaveforms.py.

◆ hist

list hist = [TH1F('h' + str(i), 'wf', 64 * 4, 0.0, 64.0 * 4) for i in range(4)]
static

1D histograms

Definition at line 32 of file showFEWaveforms.py.

◆ pdfFile [1/2]

str pdfFile = 'waveforms'
static

output file name

Definition at line 48 of file showFEWaveforms.py.

◆ pdfFile [2/2]

pdfFile

output file name

Definition at line 136 of file showFEWaveforms.py.

◆ tlpfgraphs

list tlpfgraphs = [[TGraph(2)] for i in range(4)]
static

graphs for template fit points

Definition at line 44 of file showFEWaveforms.py.


The documentation for this class was generated from the following file: