Warning, file /jana2/src/examples/misc/InteractiveStreamingExample/jupyter/monitoringObjects.py was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006 import random
0007 import numpy as np
0008 import matplotlib.pyplot as plt
0009 from IPython.display import display, clear_output, set_matplotlib_close
0010
0011
0012 numChans = 80
0013
0014
0015 class OccupancyFig:
0016 """Class to create figure for occupancy plots"""
0017
0018
0019 def __init__(self):
0020 self.fig = plt.figure()
0021
0022
0023
0024 class OccupancyPlot:
0025 """Class to plot streaming occupancy data"""
0026
0027 def __init__(self, data_dict, thresh, fig, hit_cntr):
0028 self.thresh = thresh
0029 self.fig = fig
0030 self.hit_cntr = hit_cntr
0031 self.chan_list = np.arange(1, numChans + 1, 1)
0032 for chan in range(1, numChans + 1):
0033 if len(np.where(data_dict['adcSamplesChan_%d' % chan] > self.thresh)[0]) != 0:
0034 self.hit_cntr[chan-1] += 1
0035
0036 data_dict.pop('adcSamplesChan_%s' % str(chan), None)
0037 data_dict.pop('tdcSamplesChan_%s' % str(chan), None)
0038 plt.bar(self.chan_list, self.hit_cntr, align = 'center', color = 'tab:blue')
0039 plt.xlabel('Channel Number')
0040 plt.ylabel('Number of ADC Hits > %d Channels' % self.thresh)
0041 plt.title('ADC Occupancy')
0042
0043 clear_output(wait = True)
0044 plt.pause(0.005)
0045
0046 def get_hit_cntr(self):
0047 return self.hit_cntr
0048
0049
0050 class WaveformFig:
0051 """Class to create a figure and subplots based on user input for viewing waveforms"""
0052
0053
0054 def __init__(self, nrows, ncols):
0055 self.nrows = nrows
0056 self.ncols = ncols
0057 self.fig, self.axs = plt.subplots(self.nrows, self.ncols)
0058
0059
0060 self.chans = random.sample(range(1, numChans + 1), self.nrows * self.ncols)
0061 self.chans.sort()
0062
0063 def get_num_rows(self):
0064 return self.nrows
0065
0066 def get_num_cols(self):
0067 return self.ncols
0068
0069 def get_fig_obj(self):
0070 return self.fig
0071
0072 def get_axs_obj(self):
0073 return self.axs
0074
0075 def get_chan_list(self):
0076 return self.chans
0077
0078
0079 class WaveformPlot:
0080 """Class to plot streaming ADC vs. TDC data"""
0081
0082
0083 def __init__(self, data_dict, thresh, nrows, ncols, fig, axs, chans):
0084
0085 self.thresh = thresh
0086 self.nrows = nrows
0087 self.ncols = ncols
0088 self.fig = fig
0089 self.axs = axs
0090 self.chans = chans
0091
0092 self.cl = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple',
0093 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan']
0094 self.ml = ['o', '^', 's', 'p', 'P', '*', 'X', 'd']
0095 self.ic = 0
0096 if self.nrows == 1 and self.ncols == 1:
0097 self.axs.cla()
0098 self.axs.plot(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]],
0099 data_dict['adcSamplesChan_%d' % self.chans[self.ic]],
0100 color = self.cl[self.ic % len(self.cl)],
0101 marker = self.ml[self.ic % len(self.ml)],
0102 ls = '', label = 'Channel %d' % self.chans[self.ic])
0103 hit_loc = np.where(data_dict['adcSamplesChan_%d' % self.chans[self.ic]] > self.thresh)[0] + \
0104 np.min(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]])
0105 if len(hit_loc) != 0: self.axs.set_xlim(np.min(hit_loc) - 10, np.max(hit_loc) + 20)
0106 self.axs.set_ylim(0, 1024)
0107 self.axs.set_ylabel('ADC Value')
0108 self.axs.set_xlabel('TDC Sample Number')
0109 self.axs.legend(loc = 'best', markerscale = 0, handletextpad = 0, handlelength = 0)
0110 self.ic += 1
0111 if (self.nrows == 1 and self.ncols == 2) or (self.nrows == 2 and self.ncols == 1):
0112 for index in range(2):
0113 self.axs[index].cla()
0114 self.axs[index].plot(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]],
0115 data_dict['adcSamplesChan_%d' % self.chans[self.ic]],
0116 color = self.cl[self.ic % len(self.cl)],
0117 marker = self.ml[self.ic % len(self.ml)],
0118 ls = '', label = 'Channel %d' % self.chans[self.ic])
0119 hit_loc = np.where(data_dict['adcSamplesChan_%d' % self.chans[self.ic]] > self.thresh)[0] + \
0120 np.min(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]])
0121 if len(hit_loc) != 0: self.axs[index].set_xlim(np.min(hit_loc) - 10, np.max(hit_loc) + 20)
0122 self.axs[index].set_ylim(0, 1024)
0123 self.axs[index].set_ylabel('ADC Value')
0124 self.axs[index].set_xlabel('TDC Sample Number')
0125 self.axs[index].legend(loc = 'best', markerscale = 0, handletextpad = 0, handlelength = 0)
0126 self.ic += 1
0127 if self.nrows >= 2 and self.ncols >=2:
0128 for row in range(self.nrows):
0129 for column in range(self.ncols):
0130 self.axs[row, column].cla()
0131 self.axs[row, column].plot(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]],
0132 data_dict['adcSamplesChan_%d' % self.chans[self.ic]],
0133 color = self.cl[self.ic % len(self.cl)],
0134 marker = self.ml[self.ic % len(self.ml)],
0135 ls = '', label = 'Channel %d' % self.chans[self.ic])
0136 hit_loc = np.where(data_dict['adcSamplesChan_%d' % self.chans[self.ic]] > self.thresh)[0] + \
0137 np.min(data_dict['tdcSamplesChan_%d' % self.chans[self.ic]])
0138 if len(hit_loc) != 0: self.axs[row, column].set_xlim(np.min(hit_loc) - 10, np.max(hit_loc) + 20)
0139 self.axs[row, column].set_ylim(0, 1024)
0140 if column == 0:
0141 self.axs[row, column].set_ylabel('ADC Value')
0142 if row == self.nrows - 1:
0143 self.axs[row, column].set_xlabel('TDC Sample Number')
0144 self.axs[row, column].legend(loc = 'best', markerscale = 0, handletextpad = 0, handlelength = 0)
0145 self.ic += 1
0146 plt.tight_layout()
0147
0148
0149
0150 set_matplotlib_close(False)
0151 clear_output(wait = True)
0152 plt.pause(0.005)
0153
0154 for chan in range(1, numChans + 1):
0155 data_dict.pop('adcSamplesChan_%s' % str(chan), None)
0156 data_dict.pop('tdcSamplesChan_%s' % str(chan), None)