コード例 #1
0
def plot_channel_histogram(time_diff,
                           channel_start,
                           channel_stop,
                           n_bins,
                           fit_function=None,
                           param_names=None,
                           param_units=None,
                           p0=None,
                           bounds=(-numpy.inf, numpy.inf),
                           save_fig=False,
                           range_hist=None,
                           x_min=0.,
                           label='',
                           ex_int=(numpy.inf, -numpy.inf),
                           title=''):
    print('\n')
    legend = '%s%d eventi' % (label, len(time_diff))
    bin_width = int(1000 * (range_hist[1] - range_hist[0]) / n_bins)
    ylabel = 'ev./%d ns ' % (bin_width)
    if fit_function is not None:
        plt.subplot(2, 1, 1)
        bins, n, dn = plot_functions.plot_histogram(time_diff,
                                                    "$\Delta t$ [$\mu$s]",
                                                    ylabel,
                                                    n_bins=n_bins,
                                                    range=range_hist,
                                                    title=title,
                                                    legend=legend,
                                                    fmt='.b',
                                                    as_scatter=True)
        opt, pcov = plot_functions.do_fit(bins,
                                          n,
                                          dn,
                                          param_names,
                                          param_units,
                                          fit_function=fit_function,
                                          p0=p0,
                                          bounds=bounds,
                                          x_min=x_min,
                                          ex_int=ex_int)
        l_likelihood = functions.gauss_log_likelihood(bins, n, dn,
                                                      fit_function, *opt)
        plt.subplot(2, 1, 2)
        residuals = n - fit_function(bins, *opt)
        plot_functions.scatter_plot(bins,
                                    residuals,
                                    "$\Delta t$ [$\mu$s]",
                                    'Res.',
                                    dx=None,
                                    dy=dn,
                                    title='')
        #if save_fig == True:
        #    figlabel = 'dt_%d_%d_%s.pdf' % (channel_start, channel_stop, label)
        #    plt.savefig('%s' % figlabel , format = 'pdf')
        return l_likelihood
    else:
        bins, n, dn = plot_functions.plot_histogram(time_diff,
                                                    "$\Delta t$ [$\mu$s]",
                                                    ylabel,
                                                    n_bins=n_bins,
                                                    range=range_hist,
                                                    title=title,
                                                    legend=legend,
                                                    fmt='.b',
                                                    as_scatter=True)
        return bins, n, dn
コード例 #2
0
 legend = '%d' % len(ch_stop)
 bins, n, dn = plot_functions.plot_histogram(time_stop,
                                             "time [$\mu$s]",
                                             "",
                                             n_bins=n_bins,
                                             range=range_hist,
                                             title=title,
                                             legend=legend,
                                             fmt='.b',
                                             as_scatter=True)
 opt_two_expo, pcov_two_expo = plot_functions.do_fit(
     bins,
     n,
     dn,
     param_names_2exp,
     param_units_2exp,
     fit_function=functions.two_expo,
     p0=p0,
     bounds=bounds,
     x_min=fit_min,
     x_max=x_max,
     ex_int=ex_int)
 #opt_expo, pcov_expo = plot_functions.do_fit(bins, n, dn, param_names = param_names, param_units = param_units, fit_function = functions.exponential, p0 = None, bounds = (-numpy.inf, numpy.inf), x_min = x_min, x_max = x_max)
 plt.subplot(2, 1, 2)
 residuals_two_expo = n - functions.two_expo(bins, *opt_two_expo)
 plot_functions.scatter_plot(bins,
                             residuals_two_expo,
                             'time [$\mu$s]',
                             'residuals',
                             dx=None,
                             dy=dn,
                             title='')
コード例 #3
0
    #FIT DEI DATI CON SOPRA VERSO L'ALTO       
    index, channel_diff_up, time_diff_up = utilities.mask_array(ch, time, ch_start, ch_stop_up)   
    range_hist = (time_diff_up[time_diff_up > 0.].min(), x_max)

    plt.figure()        
    plt.subplot(2, 1, 1)
    l_likelihood = two_expo_fit.plot_channel_histogram(time_diff_up, ch_start, ch_stop_up, n_bins = n_bins_up, fit_function = functions.two_expo_integral, param_names = param_names_2exp, param_units = param_units_2exp, p0 = p0 , bounds = bounds, x_min = x_min, range_hist = range_hist, save_fig=save_fig)       

    
    #FIT DEI DATI CON SOPRA VERSO IL BASSO   
    index, channel_diff_down, time_diff_down = utilities.mask_array(ch, time, ch_start, ch_stop_down)   
    range_hist = (time_diff_down[time_diff_down > 0.].min(), x_max)
    plt.figure()
    plt.subplot(2, 1, 1)
    l_likelihood = two_expo_fit.plot_channel_histogram(time_diff_down, ch_start, ch_stop_down, n_bins = n_bins_up, fit_function = functions.two_expo_integral, param_names = param_names_2exp, param_units = param_units_2exp, p0 = p0 , bounds = bounds, x_min = x_min, range_hist = range_hist, save_fig=save_fig)  
     
    #AGGREGANDO I DATI: SOPRA E SOTTO    
    ch_stop = numpy.concatenate((channel_diff_up, channel_diff_down)) 
    time_stop = numpy.concatenate((time_diff_up, time_diff_down)) 
    plt.figure()
    title = ''
    legend = '%d' % len(time_stop)
    bins, n, dn = plot_functions.plot_histogram(time_stop, "time [$\mu$s]", "", n_bins = n_bins, range = range_hist, title = title, legend = legend, fmt = '.b', as_scatter = True) 
    opt, pcov = plot_functions.do_fit(bins, n, dn, param_names_2exp, param_units_2exp, fit_function = functions.two_expo_integral, p0 = p0, bounds = bounds, x_min = x_min, x_max = x_max) 
    bins_grid = numpy.linspace(0., 20., 1000)
    plt.plot(bins_grid, functions.two_expo(bins_grid, *opt))
    
    plt.ion()
    plt.show()

コード例 #4
0
 plot_functions.scatter_plot(bins_center,
                             asimmetry,
                             'dt [$\mu$s]',
                             'Asimmetry ',
                             dy=asimmetry_err,
                             title='')
 p0 = [0.1, 3., 0.0, 0.1]
 bounds = (0., 0., -numpy.inf, -numpy.inf), (0.3, numpy.inf, 2 * numpy.pi,
                                             +numpy.inf)
 param_names = ['Amplitude', '$\omega$', '$\phi$', 'costant']
 param_units = ['', 'MHz', 'rad', '']
 opt_wave, pcov_wave = plot_functions.do_fit(bins_center,
                                             asimmetry,
                                             asimmetry_err,
                                             param_names,
                                             param_units,
                                             functions.wave,
                                             p0=p0,
                                             bounds=bounds,
                                             x_min=x_min,
                                             x_max=x_max)
 plt.subplot(3, 1, 2)
 plot_functions.scatter_plot(bins_center,
                             asimmetry,
                             'dt [$\mu$s]',
                             'Asimmetry ',
                             dy=asimmetry_err,
                             title='')
 p0 = [0.1, 3., 0.0, 0.1, 0.1]
 bounds = (0., 0., -numpy.inf, -numpy.inf,
           -numpy.inf), (0.3, numpy.inf, 2 * numpy.pi, +numpy.inf,
                         numpy.inf)
コード例 #5
0
ファイル: mu_decay.py プロジェクト: eleravera/LAB_Mu_Decay
        n_bins=n_bins,
        x0=p0,
        bounds=None,
        fit_min=fit_min,
        range_hist=(0., 15.),
        title=title,
        output_file=output_file)

    plt.subplot(3, 1, (1, 2))
    bounds = (0.0, 0.01, 0.02, 1.5, 0.), (numpy.inf, 1., 1.2, 5., 1000)
    opt, pcov = plot_functions.do_fit(bin_center,
                                      n,
                                      dn,
                                      param_names=param_names_2exp,
                                      param_units=param_units_2exp,
                                      fit_function=functions.two_expo_integral,
                                      p0=p0,
                                      show=True,
                                      bounds=bounds,
                                      draw_on_points=True,
                                      output_file=output_file)

    #MONTE CARLO SOTTRAENDO NOISE
    plt.figure(figsize=[6.4, 7.])
    n = n - functions.exponential(bin_center, norm_noise, tau_noise,
                                  cost_noise)
    mask = (n > 0.)
    bin_center = bin_center[mask]
    n = n[mask]
    dn = numpy.sqrt(n)
    minus_two_ll_two_expo, bin_center, n, dn = likelihood_fit(
コード例 #6
0
 index, channel_diff_up, time_diff_up = utilities.mask_array(
     ch_up, time_up, 1, 4)
 mask = time_diff_up > 0.
 time_diff_up = time_diff_up[mask]
 print(min(time_diff_up))
 bins, n, dn = two_expo_fit.plot_channel_histogram(time_diff_up,
                                                   1,
                                                   4,
                                                   n_bins=n_bins,
                                                   range_hist=range_hist,
                                                   title=title,
                                                   label='stop up, ')
 plot_functions.do_fit(bins,
                       n,
                       dn,
                       param_names,
                       param_units,
                       fit_function=functions.exponential,
                       p0=None)
 plt.xlim(-1., 15)
 plt.ylim(-1., 25)
 index, channel_diff_up, time_diff_up = utilities.mask_array(
     ch_up, time_up, 1, 3)
 plt.subplot(2, 1, 2)
 mask = time_diff_up > 0.
 time_diff_up = time_diff_up[mask]
 print(min(time_diff_up))
 bins, n, dn = two_expo_fit.plot_channel_histogram(time_diff_up,
                                                   1,
                                                   3,
                                                   n_bins=n_bins,