Beispiel #1
0
from scipy import asarray as ar, exp
import sys
import dask.dataframe as dd
sys.path.append('../../analog_tof/')
sys.path.append('../tof')
import pyTagAnalysis as pta

Dthres = 40
D = pd.read_parquet(
    '../data/finalData/data1hour_clean.pq',
    engine='pyarrow',
    columns=[
        'cfd_trig_rise', 'window_width', 'channel', 'amplitude', 'qdc_lg_fine',
        'qdc_sg_fine', 'ps_fine', 'qdc_lg', 'qdc_sg', 'ps', 'tof', 'invalid'
    ]).query('channel==0 and invalid==False and %s<=amplitude<618' % Dthres)
A = pta.load_data('../data/finalData/Data1793_cooked.root')
A['tof'] = 1000 - A['tdc_det0_yap0']

#figure size
plt.figure(figsize=(8, 8))

#===QDC Spectra===
#Digitized
ax1 = plt.subplot(2, 2, 1)
dcal = np.load('../data/finalData/E_call_digi.npy')

plt.hist(dcal[1] + dcal[0] * D.qdc_lg_fine / 1000,
         bins=500,
         range=(0, 15),
         log=True,
         histtype='step',
Beispiel #2
0
import matplotlib.pyplot as plt
import dask.dataframe as dd
import pandas as pd
import numpy as np
from dask.diagnostics import ProgressBar

import seaborn as sns
sns.set(style='whitegrid')
from scipy.optimize import curve_fit
from scipy import asarray as ar, exp
import sys
sys.path.append('../../../analog_tof')
import pyTagAnalysis as pta

N = pta.load_data('../../data/finalData/analogTimeCal/Data1801_cooked.root')
minimum, maximum = 0, 5000


def gaus(x, a, x0, sigma):
    return a * exp(-(x - x0)**2 / (2 * sigma**2))


def fit_gaus(left, right, df):
    x = np.linspace(left, right, int(0.5 + (right - left) / 1 + 1))
    H = np.histogram(df.tdc_det0_yap0,
                     range=(minimum, maximum),
                     bins=(maximum - minimum))
    y = H[0][int(left / 1 + 0.5):int(right / 1 + 0.5) + 1]
    popt, pcov = curve_fit(gaus, x, y, p0=[max(y), np.mean(x), 5])
    return popt, pcov
Beispiel #3
0
def get_fom(Emin=0, mode='digital'):
    if mode == 'digital':
        N = pd.read_parquet(
            '../data/finalData/finalData.pq/',
            engine='pyarrow',
            columns=['qdc_lg', 'qdc_sg', 'amplitude', 'invalid', 'channel'
                     ]).query('channel==0 and invalid==False and amplitude>40'
                              ).reset_index().head(1000000)
    else:
        N = pta.load_data('../data/finalData/Data1793_cooked.root').head(
            1000000)
    if 'qdc_det0' in N:
        flg = 0
        fsg = 2.0  #1.95#1.9
        N['qdc_lg'] = N.qdc_det0
        N['ps_new'] = ((flg * 500 + N.qdc_det0) -
                       (fsg * 60 + N.qdc_sg_det0)) / (
                           flg * 500 + N.qdc_det0).astype(np.float64)
        Ecal = np.load('../data/finalData/Ecal_A.npy')
        N['E'] = Ecal[1] + Ecal[0] * N['qdc_lg']
        dummy = N.query('-1<ps_new<1 and %s<E<6 and 500<qdc_det0' % Emin)
        outpath = '/home/rasmus/Documents/ThesisWork/Thesistex/AnalogResults/fom/FoM'

    else:
        fsg = 4900  #24500#25000
        flg = 250
        #N['qdc_lg'] = N['qdc_lg_fine']
        #N['qdc_sg'] = N['qdc_sg_fine']
        N['ps_new'] = ((flg * 500 + N['qdc_lg']) -
                       (fsg * 60 + N['qdc_sg'])) / (
                           flg * 500 + N['qdc_lg']).astype(np.float64)
        Ecal = np.load('../data/finalData/Ecal_D.npy') / 1000
        N['E'] = Ecal[1] + Ecal[0] * N['qdc_lg']
        dummy = N.query('-1<ps_new<1 and %s<E<6' % Emin)
        outpath = '/home/rasmus/Documents/ThesisWork/Thesistex/DigitalResults/fom/FoM'

    def gaus(x, a, x0, sigma):
        return a * exp(-(x - x0)**2 / (2 * sigma**2))

    k = 70
    kernel = [0] * 71
    a, x0, sigma = 1, 35, 3
    for i in range(0, 70):
        kernel[i] = gaus(i + 1, a, x0, sigma)
    kernel = np.array(kernel)
    kernel = kernel / sum(kernel)

    bins = 1000
    H = np.histogram(dummy['ps_new'], bins=bins, range=(0, 1))
    G = convolve(H[0], kernel, method='direct', mode='same')

    x = np.linspace((0) / bins, (bins - 1) / bins, bins)
    plt.figure(figsize=(6.2, 3.1))
    #plot smoothed spectrum

    plt.plot(x, H[0], label='Pulse shape histogram', drawstyle='steps-mid')
    #plt.plot(x, G,label='Smoothened pulse histogram', drawstyle='steps-mid')

    #peaks
    peaks = np.r_[True, G[1:] > G[:-1]] & np.r_[G[:-1] > G[1:], True]
    peaks[G < 0.1 * max(G)] = False
    Plist = np.where(peaks)[0]

    valleys = np.r_[True, G[1:] < G[:-1]] & np.r_[G[:-1] < G[1:], True]
    valleys[0:Plist[0]] = False
    valleys[Plist[1]:-1] = False
    Vlist = np.where(valleys)[0]

    #plot extreme points
    print(Plist)
    print(Vlist)
    ax = plt.gca()
    ylim = ax.get_ylim()
    #plt.axvline(Plist[0]/bins, ymin=0, ymax=G[Plist[0]]/ylim[1], lw=1.2, alpha=0.7, color='black')
    #plt.axvline(Plist[1]/bins, ymin=0, ymax=G[Plist[1]]/ylim[1], lw=1.2, alpha=0.7, color='black')
    #plt.axvline(Vlist[0]/bins, ymin=0, ymax=G[Vlist[0]]/ylim[1], label='extreme points', lw=1.2, alpha=0.7, color='black')

    #fit gaussian
    left, right, x0 = 0, Vlist[0], Plist[0] / 1000
    x = H[1][left:right] - (H[1][1] - H[1][0]) / 2
    Gdummy = G[left:right]
    sigma = 0.2
    ymax = max(Gdummy)
    P1, C1 = curve_fit(gaus,
                       x,
                       Gdummy,
                       p0=[ymax, x0, sigma],
                       bounds=((ymax - 10, x0 - 0.001, 0), (ymax + 10,
                                                            x0 + 0.001, 0.5)))
    print(P1)

    left, right, x0 = Vlist[0], 1000, Plist[1] / 1000
    x = (H[1][left:right] - (H[1][1] - H[1][0]) / 2)
    Gdummy = G[left:right]
    sigma = 0.5
    ymax = max(Gdummy)
    P2, C2 = curve_fit(gaus,
                       x,
                       Gdummy,
                       p0=[ymax, x0, sigma],
                       bounds=((ymax - 10, x0 - 0.01, 0), (ymax + 10,
                                                           x0 + 0.01, 0.5)))
    print(P2)

    #fit_gaus(H=G, sigma=2)

    fwhm1 = 2 * math.sqrt(2 * math.log(2)) * P1[2]
    fwhm2 = 2 * math.sqrt(2 * math.log(2)) * P2[2]
    FoM = (P2[1] - P1[1]) / (fwhm1 + fwhm2)
    print('fom = ', FoM)
    x = np.linspace(0.0005, 0.9995, 1000)
    plt.plot(x,
             gaus(x, P1[0], P1[1], P1[2]),
             ms=1,
             label='Fit: FWHM = %s, x$_0$=%.3f' %
             (round(fwhm1, 2), round(P1[1], 3)))
    plt.plot(x,
             gaus(x, P2[0], P2[1], P2[2]),
             ms=1,
             label='Fit: FWHM = %s, x$_0$=%.3f' %
             (round(fwhm2, 2), round(P2[1], 3)))
    plt.xlim(0, 0.7)
    plt.ylim(0, 8000)
    plt.xlabel('PS', fontsize=10)
    plt.ylabel('Counts', fontsize=10)
    plt.text(0.03,
             7100,
             'FoM=%s' % round(FoM, 2),
             fontsize=10,
             verticalalignment='top',
             bbox=dict(facecolor='none',
                       edgecolor='blue',
                       pad=0.5,
                       boxstyle='square'))
    plt.text(0.35, 3000, 'Neutrons', fontsize=10)
    plt.text(0.03, 3000, 'Gamma-rays', fontsize=10)
    ax = plt.gca()
    ax.tick_params(axis='both', which='both', labelsize=10)
    plt.xlim(0, 0.5)
    plt.legend(loc='best')  #, bbox_to_anchor=(0.45, 0., 0.5, 0.5))

    # #use the parameter to generate the psd spectrum
    # plt.axes([.64, 0.61, .3, .3], facecolor='white')
    # dummy=dummy.query('0<ps_new<0.5')
    # plt.hexbin((Ecal[1] + Ecal[0]*dummy.qdc_lg), dummy.ps_new, cmap='viridis', gridsize=(100,100), extent=[0,6,0,0.5])
    # plt.xlabel('E (MeV$_{ee})$', fontsize=10)
    # plt.ylabel('PS', fontsize=10)
    # plt.yticks(rotation=90)
    ax = plt.gca()
    ax.tick_params(axis='both', which='both', labelsize=10)
    plt.tight_layout()

    plt.savefig(
        '/home/rasmus/Documents/ThesisWork/Thesistex/CompareResults/FOM_%s.pdf'
        % mode,
        format='pdf')
    plt.show()
    #plt.close()
    print('%s: ' % mode, Vlist[0])
    return (FoM, Vlist[0])  #, Plist[0], Plist[1], P1, P2
Beispiel #4
0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
import sys
import dask.dataframe as dd
sys.path.append('../analog_tof/')
import pyTagAnalysis as pta

A = pta.load_data('data/Data1791_cooked.root')

ax1 = plt.subplot(2, 2, 1)
plt.hist(A.qdc_det0,
         bins=5000,
         range=(0, 5000),
         log=True,
         histtype='step',
         alpha=0.75,
         lw=1.5)
plt.title('QDC spectrum: Entire spectrum')
plt.ylabel('counts')
plt.xlabel('qdc bin')

ax2 = plt.subplot(2, 2, 2)
dummy = A.query('0<qdc_det0<450')
plt.hist(dummy.qdc_det0,
         bins=450,
         range=(0, 450),
         log=False,
         histtype='step',
Beispiel #5
0
import dask.dataframe as dd
sys.path.append('../../analog_tof/')
sys.path.append('../tof')
import pyTagAnalysis as pta
import matplotlib.ticker as plticker


c=0.299792458# m/ns
fontsize = 10

Dthres=50
D = pd.read_parquet('../data/finalData/finalData.pq/', engine='pyarrow', columns=['cfd_trig_rise', 'window_width', 'channel', 'amplitude', 'qdc_lg', 'qdc_sg', 'ps', 'tof', 'invalid']).query('channel==0 and invalid==False and %s<=amplitude<6180'%Dthres)
dcal = np.load('../data/finalData/Ecal_D.npy')
D['E'] = dcal[1]+dcal[0]*D.qdc_lg/1000
D['tof'] = D['tof']/1000
A = pta.load_data('../data/finalData/Data1793_cooked.root').query('0<qdc_det0<50000')
A['tof'] = 1000 - A['tdc_det0_yap0']
acal = np.load('../data/finalData/Ecal_A.npy')
A['E'] = acal[1]+acal[0]*A.qdc_det0

def gaus(x, a, x0, sigma):
        return a*exp(-(x-x0)**2/(2*sigma**2))
def fit_gaus(left, right, df):
    x = np.linspace(left, right, (right- left)*4)
    H = np.histogram(df.tof, range=(left, right), bins=(right-left)*4)
    #plt.step(x,H[0])
    y = H[0]
    popt,pcov = curve_fit(gaus, x, y, p0=[max(y), np.mean(x), 5])
    #plt.plot(x, gaus(x, popt[0], popt[1], popt[2]))
    #plt.show()
    return popt, pcov