Skip to content

Correlation functions

Rajnandini Mukherjee edited this page Jan 8, 2022 · 4 revisions

Correlators are stored as instances of the class stat_object (in fit_routine.py) and have several useful attributes.

Creating a correlation function

  • Case 1: A single correlation function.

Example: pion two-point function from data (with 100 bootstrap samples).

from fit_routine import *
pion = stat_object(data=pion_data, sampler=bootstrap, K=100,
                               fold=True, object_type='single', name='pion')

To start, this stores the data of the correlator and uses it to generate bootstrap samples, stored in pion.samples. If the correlator is folded, the samples of the unfolded data stored in pion.org_samples. The samples are then used to generate a covariance matrix pion.COV. The jackknife resampling method is also available by specifying sampler=jackknife. Other methods can be used by writing them as functions of the data and passing them via sampler argument. The correlation matrix is also calculated and stored in pion.CORR.

  • Case 2: A combined set of correlation functions.

Example: combined pion and C_Kpi correlator. Combined correlators can be created by passing the list of all the single correlation functions that make up the combined one.

combined_corr = fit_routine.stat_object(data=[pion, C_Kpi], sampler=bootstrap, K=100,
                                        object_type='combined', name='pion and C_Kpi')

This automatically concatenates the data over the inputs, and generates a covariance matrix using resampled data from each individual correlator.

Fitting a correlation function

Once a stat_object is instantiated, it can be fitted with an ansatz over a fit range using the class function fit.

  • Case 1: A single correlation function.

Example: pion two-point function over the range (15,30).

pion.fit(interval=(15,30,1), ansatz=cosh, guess=[2e+4,0.08],
         param_names=['A_p','m_p'], plot=True)

The third number in interval implies thinning. The cosh-like ansatz for two-point functions is available already as ansatz=cosh but any other ansatz can be passed as a function via ansatz=function. One can then view the fit results via the fit_dict attribute. The final values of the fit parameters are stored in pion.params with their errors in pion.params_err. The bootstrap distribution of the parameters is available in pion.params_dist.

The results can be plotted by passing plot=True in the fit function. For correlation functions with a cosh-like ansatz, a plot of the effective mass is automatically generated. But the necessary information can be accessed for plotting using

import matplotlib.pyplot as plt

# plotting the data
plt.errorbar(pion.x, pion.data_avg[pion.x], yerr=pion.input_err[pion.x], capsize=4, fmt='o', label='data')

# plotting the fit
plt.plot(pion.x, pion.fit_avg, label='fit')
plt.xlabel('t')
plt.show()

One can also compute some additional function of the fit parameters and its behaviour over the bootstraps (useful for computing scattering length) by defining:

def func1(params, **kwargs):
    return params[0]+params[1]
   
pion.fit(interval=(15,30,1), ansatz=cosh, guess=[2e+4,0.08], param_names=['A_p','m_p'],
        calc_func=[func1], calc_func_names=['func1'])

Now the fit_dict contains information on this function.

  • Case 2: Combined fits.

Example: combined pion and C_Kpi correlator: In this case, the fit interval is always (0, corr.T-1, 1) since the fit intervals of the individual correlators that make up the combined one are stored within them. Using some predefined ansatz,

combined_corr.fit(interval=(0,combined_corr.T-1,1), ansatz=combined_ansatz, index=1,
                  guess=[2e+4,0.08,1,0.001], param_names=['A_p', 'm_p', 'A_CKpi', 'Delta_E_Kpi'])

index specifies the correlator with the flexible fit range in the list of correlators. This is useful when varying the global fit via the fit range of one of the many correlation functions.

If one wishes to modify the covariance matrix for a fit, it can be done by passing COV_model=func, where the function func recieves the class object as argument and returns the modified covariance matrix. See, for example, the cov_block_diag function in analysis.py.

Autofit: scanning over fit intervals

One can use the autofit function of the class stat_object to perform several fits over multiple fit ranges specified via the starting points t_min_range and intervals fit_ints.

*Case 1: A single correlation function.

Example: pion 2-pt function over multiple fit ranges both unthinned and thinned

pion.autofit(t_min_range=range(5,10), fit_ints=(10,20), ansatz=cosh,
             guess=[2e+4,0.08], thin_list=[1,2])

This populated the Pandas DataFrame pion.autofit_df with information on all the fits performed, the fit results, the errors (over bootstrap samples), the X^2/DOF and pvalues. Using these, a best_fit routine calculates the best fit range for the correlation function. The best fit results are stored once again in pion.fit_dict. pion.autofit_dict stores information on the t_min_range and fit_ints used for the autofit.

The vast information in this DataFrame can be plotted by calling pion.autofit_plot(). This generates a plot for each fit parameter and the variation in its value over different choices of t_min and fit interval. If there are any additional function calculated, it also plots their variations and generates histograms over their values. Refer to the autofit_plot() function in fit_routine.py to see additional options.

*Case 2: Combined fits.

Example: combined pion and C_Kpi correlator. In this case the autofit process loops over fit intervals of a specified individual correlator in the list of correlators passed to the combined correlation function. For example,

combined_corr.autofit(t_min_range=range(5,10), fit_ints=(10,20), ansatz=combined_ansatz, 
                      index=1, guess=[2e+4,0.08,1,0.001])

loops over the various fit ranges of the individual correlator at index 1, ie, the C_Kpi correlation function. The fit interval of the pion is held constant - stored from before in pion.interval.