コード例 #1
0
ファイル: exponential_test.py プロジェクト: eleravera/Lab_TOF
    errors = numpy.sqrt(n)
    bin_centers = 0.5 * (bins[1:] + bins[:-1])
    
    mask = (n > 0.)
    x = bin_centers[mask]
    y = n[mask]
    dy = errors[mask]
    
    plt.figure("Time distribution")  
    plt.errorbar(x, y, yerr=dy, fmt='o')
    p0 = (10., 0.1)
    opt, pcov = curve_fit(fit_functions.exponential, x, y, sigma = dy, p0=p0)
    param_errors = numpy.sqrt(pcov.diagonal())  

    residuals = y - fit_functions.exponential(x, *opt)
    chi2 = numpy.sum((residuals/dy)**2)
    ndof = len(y)-len(opt)
    
    param_names = ['amplitude', 'rate']
    param_units = ['', 'Hz']
    legend = plot_functions.fit_legend(opt, param_errors, param_names, param_units, chi2, ndof)
    title = '%d eventi %d secondi, 24/03/21' % (len(t), t_run)
    bin_grid = numpy.linspace(*range, 1000)
    plt.plot(bin_grid, fit_functions.exponential(bin_grid, *opt), '-r', label = legend)   
    plot_functions.set_plot("$\Delta t [s]$", "entries/bin", title = title)
    
    
    
    plt.ion()
    plt.show()
コード例 #2
0
ファイル: time_resolution.py プロジェクト: eleravera/Lab_TOF
def convolution_and_fit(T_sim, T_measured, xlabel, ylabel, data_bins, data_range, sim_bins, sim_range, title = None, figlabel='', save_fig = False):    
    #Calcola la spline
    plt.figure()
    n, bins, patches = plt.hist(T_sim, bins = sim_bins, range = sim_range)
    bin_centers = 0.5 * (bins[1:] + bins[:-1])
    x = bin_centers
    y = n
    polynomial_f = interp1d(x, y, kind='linear')    
    plt.plot(x, polynomial_f(x), '-', label = 'Spline geometria')
    plot_functions.set_plot(xlabel, ylabel, title='Simulazione Monte Carlo')
    if save_fig ==True:
      plt.savefig('risoluzione/plot/spline%s.pdf' % figlabel, format = 'pdf')    
        
    data_mean = T_measured.mean()
    p0 = [0.15, len(T_measured)/data_bins,  data_mean - 1., 4., data_mean, 0.9]
    bounds = (0.1, 0., data_mean*0.7, 1., data_mean*0.7 , 0.3 ), (0.4, numpy.inf, data_mean*1.3, 6., data_mean*1.3, 1.)


    #calcola i parametri della doppia gaussiana e calcola la convoluzione
    opt_true, pcov_true = plot_functions.fit2gauss(T_measured, xlabel, ylabel, bins = data_bins, range=data_range, f = True, p0=p0,
    bounds = bounds, title = title)
    if save_fig ==True:    
      plt.savefig('risoluzione/plot/2gauss_fit%s.pdf' % figlabel, format = 'pdf')    
    
    convolved_fit_function = fit_functions.create_convolution(polynomial_f, fit_functions.two_gauss)
    #Fa il fit  
    plt.figure()    
    ni, bins, pat = plt.hist(T_measured, bins = data_bins, range=data_range)
    x = 0.5 * (bins[1:] + bins[:-1])
    nj = ni
    mask_fit = nj>0

    middle_point = (min(x[mask_fit]) + max(x[mask_fit])) * 0.5
    p0 = numpy.copy(opt_true)
    p0[2] = middle_point - (opt_true[4] - opt_true[2])
    p0[4] = middle_point
    bounds = (0.1, 0., p0[2]*0.9, 1., p0[4]*0.9 , 0.4 ), (0.4, numpy.inf, p0[2]*1.1, 6., p0[4]*1.1, 1.)
    opt, pcov = curve_fit(convolved_fit_function, x[mask_fit], nj[mask_fit], p0 = p0, bounds = bounds)

    chi2 = (nj[mask_fit] - convolved_fit_function(x[mask_fit], *opt))**2 / nj[mask_fit]
    chi2 = chi2.sum()
    ndof = len(nj[mask_fit])- len(opt)
    
    param_errors = numpy.sqrt(pcov.diagonal())  
    param_values = numpy.copy(opt) 
    param_values[2] = param_values[2] - middle_point
    param_values[4] = param_values[4] - middle_point
    param_names = ['fraction', 'norm', '$\mu_{1}$', '$\sigma_1$', '$\mu_{2}$', '$\sigma_2$']    
    param_units = ['', 'ns$^{-1}$', 'ns', 'ns', 'ns', 'ns']        
    legend = plot_functions.fit_legend(param_values, param_errors, param_names, param_units, chi2, ndof)
    
    x_grid = x[mask_fit]
    y = convolved_fit_function(x_grid, *opt)
    plt.plot(x_grid, y, '-', label = legend)
    plot_functions.set_plot(xlabel, ylabel, title = title)

    if save_fig ==True:
      plt.savefig('risoluzione/plot/conv_fit%s.pdf' % figlabel, format = 'pdf')    
    
    
    plt.figure()
    middle_point = (bins[-1] + bins[0]) * 0.5
    integral = numpy.sum(fit_functions.two_gauss(x_grid, *opt))
    plt.plot(x_grid - middle_point, fit_functions.two_gauss(x_grid, *opt)/integral, 'r-', label='Response function')     
    plot_functions.set_plot('Time [s]', 'pdf', title = 'Risoluzione ')
    if save_fig ==True:
      plt.savefig('risoluzione/plot/risoluzione%s.pdf' % figlabel, format = 'pdf')
    
    return opt_true, pcov_true, param_values, pcov
コード例 #3
0
            electron_down.append(-25.)

    material_depth = numpy.array(material_depth)
    electron_up = numpy.array(electron_up)
    electron_down = numpy.array(electron_down)
    epsilon_electron = numpy.array(epsilon_electron)
    epsilon_muon = numpy.array(epsilon_muon)
    epsilon = epsilon_electron * epsilon_muon

    electron_e_mean_range = spline_electron(37.25)

    title = '%s' % (element)
    plt.figure()
    plt.plot(material_depth, epsilon_electron, '-r', label='Elettroni')
    plt.plot(material_depth, epsilon_muon, '-b', label='Muoni')
    plot_functions.set_plot("$\Delta x$ [cm]", "$N_i$/$N_{tot}$", title=title)
    if save_fig == True:
        plt.savefig('mu_ele_epsilon_%s.pdf' % element, format='pdf')

    plt.figure()
    title = '%s' % (element)
    plt.plot(material_depth, epsilon, '-')
    plot_functions.set_plot("$\Delta x$ [cm]", "$\epsilon$", title=title)
    plt.axvline(electron_e_mean_range, color='g')
    if save_fig == True:
        plt.savefig('epsilon_%s.pdf' % element, format='pdf')

    plt.figure()
    plt.plot(material_depth, electron_up, '-', label='up')
    plt.plot(material_depth, electron_down, '-', label='down')
    plt.ylim(-0.1, 1.1)
コード例 #4
0
ファイル: counts_plot.py プロジェクト: eleravera/LAB_Mu_Decay
    'Scintillator6': ('dati_15_04/Vss_40mv_6.txt', 'dati_15_04/Vss_70mv_6.txt',
                      'dati_20_04/s6.txt', 'dati_20_04/s6.txt')
}

plt.figure()
date = '15/04/21'
for scintillator in data_dict:
    data_file = data_dict[scintillator][0]
    Vss, counts, time = numpy.loadtxt(data_file, unpack=True)
    #Vth = 40. #mV
    title = '%s' % (date)
    rate = counts / time
    dcounts = numpy.sqrt(counts)
    drate = dcounts / time
    plt.errorbar(Vss, rate, yerr=drate, label=scintillator)
    plot_functions.set_plot('$V_a$ [V]', 'Rate [Hz]', title=title)

plt.figure()
for scintillator in data_dict:
    data_file = data_dict[scintillator][1]
    Vss, counts, time = numpy.loadtxt(data_file, unpack=True)
    #Vth = 70. #mV
    title = '%s' % (date)
    rate = counts / time
    dcounts = numpy.sqrt(counts)
    drate = dcounts / time
    plt.errorbar(Vss, rate, yerr=drate, label=scintillator)
    plot_functions.set_plot('$V_a$ [V]', 'Rate [Hz]', title=title)

date = '20/04/21'
plt.figure()
コード例 #5
0
ファイル: T12_e.py プロジェクト: eleravera/Lab_TOF
    utilities.rate_and_saturation(t, ch0, ch1)
    t_run = utilities.acquisition_duration(t)      
    T12, tau = utilities.TAC_scale(ch0, ch1) 
    mask_0 = T12 > 0.0
    T12 = T12[mask_0]    
     
    T12 = numpy.concatenate((t12, T12)) 
    mean = numpy.mean(T12)
    print("mean", mean)
            
    bins = 101
    range = (0., 70.)    
    title = '%d eventi %d secondi, %s' % (len(T12), t_run, '31/03/21')
    

    plt.figure()
    n, bins = numpy.histogram(T12,  bins = bins, range = range, density = None)
    n = n/n.max()
    n, bins, patches = plt.hist(bins[1:],  weights=n, bins = bins, label = '', alpha = 0.4)    
    plot_functions.set_plot('$T_{12}$ [ns]', 'a.u.', title = title)

    #T12 = T12 - mean    
    #x = (geometry.X1*100 - T12/numpy.abs(m))*0.5 
    #plot_functions.histogram(x, "x [cm]", "", f = False, bins = bins) 
    
    
    
    plt.ion()
    plt.show()
    
コード例 #6
0
ファイル: calibration.py プロジェクト: eleravera/Lab_TOF
        input_file, unpack=True)

    plt.figure()
    plt.subplot(2, 1, 1)
    plt.errorbar(x,
                 mean1_13,
                 yerr=dmean1_13,
                 fmt='.r',
                 label='$\mu_{1}$ $T_{13}$')
    plt.errorbar(x,
                 mean2_13,
                 yerr=dmean2_13,
                 fmt='.b',
                 label='$\mu_{2}$ $T_{13}$')

    plot_functions.set_plot('x [cm]', '$\mu(T_{13})$', title='')

    plt.subplot(2, 1, 2)
    plt.errorbar(x,
                 mean1_23,
                 yerr=dmean1_23,
                 fmt='.r',
                 label='$\mu_{1}$ $T_{23}$')
    plt.errorbar(x,
                 mean2_23,
                 yerr=dmean2_23,
                 fmt='.b',
                 label='$\mu_{2}$ $T_{23}$')
    plot_functions.set_plot('x [cm]', '$\mu(T_{23})$', title='')

    if save_fig == True: