Warning, file /jana2/src/examples/misc/InteractiveStreamingExample/python/streamDet_Uproot.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 numpy as np
0007 import uproot as ur
0008 import matplotlib.pyplot as plt
0009 import random, os, time
0010
0011
0012 eos = 0; rif = 'outFile.root'
0013
0014 sizeDiffCntr = 0; fileEndCntr = 0
0015
0016 numChans = 80
0017
0018
0019 numRows = 6; numCols = 6
0020 fig, axs = plt.subplots(numRows, numCols)
0021 fig.set_size_inches(18.5, 10.5, forward = True)
0022
0023
0024
0025
0026
0027
0028 cl = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple',
0029 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan']
0030 ml = ['o', '^', 's', 'p', 'P', '*', 'X', 'd']
0031
0032
0033 rcl = random.sample(range(1, numChans + 1), numRows*numCols)
0034 rcl.sort()
0035
0036
0037 enl = []; hitThresh = 100
0038 detOcc = np.zeros(numChans)
0039
0040
0041 def hitFunc(sample, peak, startTime, decayTime, baseLine):
0042 adcSample = np.piecewise(sample, [sample < startTime, sample >= startTime], [lambda sample: baseLine,
0043 lambda sample: (peak * np.power(((sample - startTime) / decayTime), 4) *
0044 np.exp((-4) * ((sample - startTime) / decayTime)) + baseLine)])
0045 return adcSample
0046
0047 while eos == 0 :
0048 rifInitSize = os.stat(rif).st_size
0049 time.sleep(1)
0050 rifCurrSize = os.stat(rif).st_size
0051 print('rifInitSize = %d, rifCurrSize = %d, fileEndCntr = %d' % (rifInitSize, rifCurrSize, fileEndCntr))
0052 sizeDiff = rifCurrSize - rifInitSize
0053 if sizeDiff > 0 :
0054 sizeDiffCntr += 1
0055 print('sizeDiff = %d, sizeDiffCntr = %d' % (sizeDiff, sizeDiffCntr))
0056
0057 et = ur.open(rif)['ET']
0058
0059 enl.append(et[b'event'].numentries)
0060 currEvent = enl[len(enl) - 1]
0061 if len(enl) == 1 : prevEvent = 1
0062 else : prevEvent = enl[len(enl) - 2]
0063 numEventsBetween = currEvent - prevEvent
0064 print ('enl = ', enl)
0065 print ('currEvent = %d, prevEvent = %d, numEventsBetween = %d' % (currEvent, prevEvent, numEventsBetween))
0066
0067 st = ur.open(rif)['ST']
0068
0069 adcDict = st.arrays(['adc*'])
0070 tdcDict = st.arrays(['tdc*'])
0071 print('eventNum = %d, size of adcDict[b\'adcSamplesChan_80\'] = %d' % (enl[len(enl) - 1], len(adcDict[b'adcSamplesChan_80'])))
0072
0073 for chan in range(1, numChans + 1) :
0074 for ievent in range(1, numEventsBetween + 1) :
0075 for sample in adcDict[b'adcSamplesChan_%d' % chan][1024*(prevEvent + ievent - 1):1024*(prevEvent + ievent)] :
0076 if sample > hitThresh :
0077 detOcc[chan-1] += 1
0078 break
0079 if chan % 10 == 0 : print('decOcc for chan %d = ' % chan, detOcc[chan-1])
0080 ic = 0
0081 for row in range(numRows) :
0082 for column in range(numCols) :
0083 axs[row, column].cla()
0084 axs[row, column].plot(tdcDict[b'tdcSamplesChan_%d' % rcl[ic]][-1024:],
0085 adcDict[b'adcSamplesChan_%d' % rcl[ic]][-1024:],
0086 color = cl[ic % len(cl)], marker = ml[ic % len(ml)],
0087 ls = '', label = 'Channel %d' % rcl[ic])
0088 hitLoc = np.where(adcDict[b'adcSamplesChan_%d' % rcl[ic]][-1024:]>100)[0] + len(adcDict[b'adcSamplesChan_%d' % rcl[ic]]) - 1024
0089 if len(hitLoc) != 0 : axs[row, column].set_xlim(np.min(hitLoc) - 10, np.max(hitLoc) + 20)
0090 axs[row, column].set_ylim(0, 1024)
0091 if column == 0 : axs[row, column].set_ylabel('ADC Value')
0092 if row == numRows - 1 : axs[row, column].set_xlabel('TDC Sample Number')
0093 axs[row, column].legend(loc = 'best', markerscale = 0, handletextpad = 0, handlelength = 0)
0094 ic += 1
0095 plt.tight_layout()
0096 plt.pause(0.05)
0097 else :
0098 fileEndCntr += 1
0099 if fileEndCntr == 60 :
0100 print('\nData stream no longer present! Exiting now...buh bye!\n')
0101 eos = 1