Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:18

0001 #!/usr/bin/python3.6
0002 
0003 # Copyright 2020, Jefferson Science Associates, LLC.
0004 # Subject to the terms in the LICENSE file found in the top-level directory.
0005 
0006 import zmq, pickle, random
0007 import numpy as np
0008 import matplotlib.pyplot as plt
0009 
0010 # define the subscriber port
0011 subPort = 5558
0012 # configure the subscriber
0013 subContext = zmq.Context()
0014 subscriber = subContext.socket(zmq.SUB)
0015 subscriber.setsockopt(zmq.SUBSCRIBE, b'')
0016 subscriber.connect('tcp://127.0.0.1:%d' % subPort)
0017 print('\nSubscribing to tcp://127.0.0.1:%d\n' % subPort)
0018 
0019 # plot adc samples vs. tdc samples
0020 numRows = 6; numCols = 6; numChans = 80
0021 fig, axs = plt.subplots(numRows, numCols)
0022 fig.set_size_inches(18.5, 10.5, forward = True)
0023 
0024 # lists for colors and markers
0025 cl = ['tab:blue',  'tab:orange', 'tab:green', 'tab:red',   'tab:purple',
0026       'tab:brown', 'tab:pink',   'tab:gray',  'tab:olive', 'tab:cyan']
0027 ml = ['o', '^', 's', 'p', 'P', '*', 'X', 'd']
0028 
0029 # random channel list, ascending and non-repeating
0030 rcl = random.sample(range(1, numChans + 1), numRows*numCols)
0031 rcl.sort()
0032 
0033 # event number list, hit threshold (adc channels), initialize occupancy array
0034 enl = []; hitThresh = 100
0035 
0036 ec = 0  # event counter
0037 # recieve zmq messages from jana subscriber
0038 while True :
0039     # receive zmq packets from jana subscriber
0040     picklePacket = subscriber.recv_pyobj()
0041     print('picklePacket received!')
0042     eventDataDict = pickle.loads(picklePacket)
0043     ec += 1
0044     ic = 0  # index counter
0045     for row in range(numRows) :
0046         for column in range(numCols) :
0047             axs[row, column].cla()
0048             axs[row, column].plot(eventDataDict['tdcSamplesChan_%d' % rcl[ic]],
0049                                   eventDataDict['adcSamplesChan_%d' % rcl[ic]],
0050                                   color = cl[ic % len(cl)], marker = ml[ic % len(ml)],
0051                                   ls = '', label = 'Channel %d' % rcl[ic])
0052             hitLoc = np.where(eventDataDict['adcSamplesChan_%d' % rcl[ic]]>100)[0] + np.min(eventDataDict['tdcSamplesChan_%d' % rcl[ic]])
0053             if len(hitLoc) != 0 : axs[row, column].set_xlim(np.min(hitLoc) - 10, np.max(hitLoc) + 20)
0054             axs[row, column].set_ylim(0, 1024)
0055             if column == 0 : axs[row, column].set_ylabel('ADC Value')
0056             if row == numRows - 1 : axs[row, column].set_xlabel('TDC Sample Number')
0057             axs[row, column].legend(loc = 'best', markerscale = 0, handletextpad = 0, handlelength = 0)
0058             ic += 1
0059     plt.tight_layout()
0060     # plt.savefig('plots/event_%d.png' % ec)
0061     plt.pause(0.05)