Belle II Software development
Plotter Class Reference

Public Member Functions

 __init__ (self, location)
 
 plotEcmsComparison (self, limits=None, tag='')
 
 plotSpreadComparison (self, limits=None)
 
 plotShift (self, limits=None)
 
 plotEcms (self, limits=None, tag='')
 
 plotPulls (self, limits=None)
 

Static Public Member Functions

 plotLine (df, var, color, label)
 
 plotCurve (df, var, label, withBand=True, withCurve=True)
 

Public Attributes

 dfB = pd.read_csv(f'{location}/BonlyEcmsCalib.txt', delim_whitespace=True)
 read B-only calibration
 
 dfC = pd.read_csv(f'{location}/finalEcmsCalib.txt', delim_whitespace=True)
 read combined calibration
 
 dfM = pd.read_csv(f'{location}/mumuEcalib.txt', delim_whitespace=True)
 read mumu calibration
 

Detailed Description

Plotting class

Definition at line 126 of file ecms.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
location )
Data are loaded from text files to pandas

Definition at line 129 of file ecms.py.

129 def __init__(self, location):
130 """
131 Data are loaded from text files to pandas
132 """
133
134
135 self.dfB = pd.read_csv(f'{location}/BonlyEcmsCalib.txt', delim_whitespace=True)
136
137
138 self.dfC = pd.read_csv(f'{location}/finalEcmsCalib.txt', delim_whitespace=True)
139
140
141 self.dfM = pd.read_csv(f'{location}/mumuEcalib.txt', delim_whitespace=True)
142
143 # add the state
144 dfM = self.dfM
145 dfC = self.dfC
146 state = -1
147 dfM['type'] = 1
148 dfC['type'] = 1
149 for i in range(len(dfM)):
150 if (dfM['id'][i]) == 0:
151 state *= -1
152
153 dfM.at[i, 'type'] = state
154 dfC.at[i, 'type'] = state
155

Member Function Documentation

◆ plotCurve()

plotCurve ( df,
var,
label,
withBand = True,
withCurve = True )
static
Plot curve with possible error band where large intervals are distinguished by color

Definition at line 235 of file ecms.py.

235 def plotCurve(df, var, label, withBand=True, withCurve=True):
236 """
237 Plot curve with possible error band where large intervals are distinguished by color
238 """
239
240 def plotBands(df, var, color, withBand=True, withCurve=True):
241 varUnc = var + 'Unc'
242 nan = np.full(len(df), np.nan)
243 avg = (df['t1']+df['t2']).to_numpy()/2
244 times = np.c_[df[['t1', 't2']].to_numpy(), avg].ravel()
245 eCMS = np.c_[df[[var, var]].to_numpy(), nan].ravel()
246 times = toJST(times)
247
248 if withBand:
249 eCMSu = np.c_[df[[varUnc, varUnc]].to_numpy(), nan].ravel()
250 plt.fill_between(times, eCMS-eCMSu, eCMS+eCMSu, alpha=0.15, color=color)
251 if withCurve:
252 plt.plot(times, eCMS, linewidth=2, color=color)
253
254 nan = np.full(len(df), np.nan)
255 avg = (df['t1']+df['t2']).to_numpy()/2
256 timesg = np.c_[df['t1'].to_numpy(), avg, df['t2'].to_numpy()].ravel()
257 eCMSg = np.c_[df[var].to_numpy(), nan, df[var].to_numpy()].ravel()
258 timesg = toJST(timesg)
259
260 if withCurve:
261 plt.plot(timesg, eCMSg, linewidth=2, color='gray', alpha=0.35)
262
263 plotBands(df[df['type'] == 1], var, 'red', withBand, withCurve)
264 plotBands(df[df['type'] == -1], var, 'blue', withBand, withCurve)
265

◆ plotEcms()

plotEcms ( self,
limits = None,
tag = '' )
Plot Ecms of the combined fit, 'tag' can be '4S' means that y-axis is zoomed to 4S mass region, 'Off' to off-resonance

Definition at line 288 of file ecms.py.

288 def plotEcms(self, limits=None, tag=''):
289 """
290 Plot Ecms of the combined fit, 'tag' can be '4S' means that y-axis is zoomed to 4S mass region, 'Off' to off-resonance
291 """
292
293 Plotter.plotCurve(self.dfC, 'Ecms', label='Combined method')
294
295 plotSplitLines(self.dfC)
296
297 plt.xlabel('time')
298 plt.ylabel('Ecms [MeV]')
299
300 setPlotRange(self.dfC, tag)
301
302 loc = 'plots/allData'
303 if limits is not None:
304 plt.xlim(datetime.strptime(limits[0], '%Y-%m-%d'), datetime.strptime(limits[1], '%Y-%m-%d'))
305 loc = 'plots/' + limits[0] + 'to' + limits[1]
306
307 os.makedirs(loc, exist_ok=True)
308 plt.savefig(f'{loc}/Ecms{tag}.png')
309 plt.clf()
310

◆ plotEcmsComparison()

plotEcmsComparison ( self,
limits = None,
tag = '' )
Plot Ecms obtained from combined, hadB and mumu method

Definition at line 179 of file ecms.py.

179 def plotEcmsComparison(self, limits=None, tag=''):
180 """
181 Plot Ecms obtained from combined, hadB and mumu method
182 """
183
184 Plotter.plotLine(self.dfB, 'Ecms', 'green', label='B decay method')
185 Plotter.plotLine(self.dfC, 'Ecms', 'red', label='Combined method')
186
187 d = np.nanmedian(self.dfC['Ecms']-self.dfM['Ecms'])
188
189 dfMc = self.dfM.copy()
190 dfMc['Ecms'] += d
191 Plotter.plotLine(dfMc, 'Ecms', 'blue', label=f'mumu method (+{round(d,1)} MeV)')
192
193 plotSplitLines(self.dfC)
194 setPlotRange(self.dfC, tag)
195
196 plt.xlabel('time')
197 plt.ylabel('Ecms [MeV]')
198
199 plt.legend()
200
201 loc = 'plots/allData'
202 if limits is not None:
203 plt.xlim(datetime.strptime(limits[0], '%Y-%m-%d'), datetime.strptime(limits[1], '%Y-%m-%d'))
204 loc = 'plots/' + limits[0] + 'to' + limits[1]
205
206 os.makedirs(loc, exist_ok=True)
207 plt.savefig(f'{loc}/EcmsComparison{tag}.png')
208 plt.clf()
209

◆ plotLine()

plotLine ( df,
var,
color,
label )
static
Plot single line with error band

Definition at line 157 of file ecms.py.

157 def plotLine(df, var, color, label):
158 """
159 Plot single line with error band
160 """
161
162 varUnc = var + 'Unc'
163 nan = np.full(len(df), np.nan)
164 avg = (df['t1']+df['t2']).to_numpy()/2
165 times = np.c_[df[['t1', 't2']].to_numpy(), avg].ravel()
166 eCMS = np.c_[df[[var, var]].to_numpy(), nan].ravel()
167 eCMSu = np.c_[df[[varUnc, varUnc]].to_numpy(), nan].ravel()
168
169 timesg = np.c_[df['t1'].to_numpy(), avg, df['t2'].to_numpy()].ravel()
170 eCMSg = np.c_[df[var].to_numpy(), nan, df[var].to_numpy()].ravel()
171
172 times = toJST(times)
173 timesg = toJST(timesg)
174
175 plt.fill_between(times, eCMS-eCMSu, eCMS+eCMSu, alpha=0.2, color=color)
176 plt.plot(times, eCMS, linewidth=2, color=color, label=label)
177 plt.plot(timesg, eCMSg, linewidth=2, color=color, alpha=0.35)
178

◆ plotPulls()

plotPulls ( self,
limits = None )
Plot pulls of the combined fit.

Definition at line 311 of file ecms.py.

311 def plotPulls(self, limits=None):
312 """
313 Plot pulls of the combined fit.
314 """
315
316 dfC = self.dfC.copy()
317 dfC['ref'] = 0
318 dfC['refUnc'] = 1
319 Plotter.plotCurve(dfC, 'pull', label='Combined method', withBand=False)
320 Plotter.plotCurve(dfC, 'ref', label='Combined method', withCurve=False)
321
322 plotSplitLines(self.dfC)
323
324 plt.ylim(-1.5, 1.5)
325 plt.xlabel('time')
326 plt.ylabel('pull')
327
328 loc = 'plots/allData'
329 if limits is not None:
330 plt.xlim(datetime.strptime(limits[0], '%Y-%m-%d'), datetime.strptime(limits[1], '%Y-%m-%d'))
331 loc = 'plots/' + limits[0] + 'to' + limits[1]
332
333 os.makedirs(loc, exist_ok=True)
334 plt.savefig(f'{loc}/Pull.png')
335 plt.clf()
336
337
338# Get the results from the combined calibration

◆ plotShift()

plotShift ( self,
limits = None )
Plot shift between Bhad and mumu method

Definition at line 266 of file ecms.py.

266 def plotShift(self, limits=None):
267 """
268 Plot shift between Bhad and mumu method
269 """
270
271 Plotter.plotCurve(self.dfC, 'shift', label='Combined method')
272
273 plotSplitLines(self.dfC)
274
275 plt.xlabel('time')
276 plt.ylabel('shift [MeV]')
277
278 loc = 'plots/allData'
279 if limits is not None:
280 plt.xlim(datetime.strptime(limits[0], '%Y-%m-%d'), datetime.strptime(limits[1], '%Y-%m-%d'))
281 loc = 'plots/' + limits[0] + 'to' + limits[1]
282
283 os.makedirs(loc, exist_ok=True)
284 plt.savefig(f'{loc}/Shift.png')
285
286 plt.clf()
287

◆ plotSpreadComparison()

plotSpreadComparison ( self,
limits = None )
Plot Ecms spread estimated from the combined method and B-decay method

Definition at line 210 of file ecms.py.

210 def plotSpreadComparison(self, limits=None):
211 """
212 Plot Ecms spread estimated from the combined method and B-decay method
213 """
214
215 Plotter.plotLine(self.dfB, 'spread', 'green', label='B decay method')
216 Plotter.plotLine(self.dfC, 'spread', 'red', label='Combined method')
217
218 plotSplitLines(self.dfC)
219
220 plt.legend()
221
222 plt.xlabel('time')
223 plt.ylabel('spread [MeV]')
224
225 loc = 'plots/allData'
226 if limits is not None:
227 plt.xlim(datetime.strptime(limits[0], '%Y-%m-%d'), datetime.strptime(limits[1], '%Y-%m-%d'))
228 loc = 'plots/' + limits[0] + 'to' + limits[1]
229
230 os.makedirs(loc, exist_ok=True)
231 plt.savefig(f'{loc}/SpreadComparison.png')
232 plt.clf()
233

Member Data Documentation

◆ dfB

dfB = pd.read_csv(f'{location}/BonlyEcmsCalib.txt', delim_whitespace=True)

read B-only calibration

Definition at line 135 of file ecms.py.

◆ dfC

dfC = pd.read_csv(f'{location}/finalEcmsCalib.txt', delim_whitespace=True)

read combined calibration

Definition at line 138 of file ecms.py.

◆ dfM

dfM = pd.read_csv(f'{location}/mumuEcalib.txt', delim_whitespace=True)

read mumu calibration

Definition at line 141 of file ecms.py.


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