def get_results(Fit):
    Vnn = collections.OrderedDict()
    p = gv.load(Fit['filename'])
    for i in range(len(Fit['twists'])):
        Fit['M_D_tw{0}'.format(Fit['twists'][i])] = gv.sqrt(
            p['dE:{0}'.format(Fit['Dtw{0}'.format(Fit['twists'][i])])][0]**2 -
            Fit['momenta'][i]**2)
        Fit['E_D_tw{0}'.format(Fit['twists'][i])] = p['dE:{0}'.format(
            Fit['Dtw{0}'.format(Fit['twists'][i])])][0]

    for mass in Fit['masses']:
        Fit['M_G_m{0}'.format(mass)] = p['dE:{0}'.format(
            Fit['Gm{0}'.format(mass)])][0]
        Fit['M_NG_m{0}'.format(mass)] = p['dE:{0}'.format(
            Fit['NGm{0}'.format(mass)])][0]

        for twist in Fit['twists']:
            if 'SVnn_m{0}_tw{1}'.format(mass, twist) in p:
                Fit['Sm{0}_tw{1}'.format(mass, twist)] = 2 * 2 * gv.sqrt(
                    Fit['E_D_tw{0}'.format(twist)] *
                    Fit['M_G_m{0}'.format(mass)]) * p['SVnn_m{0}_tw{1}'.format(
                        mass, twist)][0][0]
            if 'VVnn_m{0}_tw{1}'.format(mass, twist) in p:
                Fit['Vm{0}_tw{1}'.format(mass, twist)] = 2 * 2 * gv.sqrt(
                    Fit['E_D_tw{0}'.format(twist)] *
                    Fit['M_G_m{0}'.format(mass)]) * p['VVnn_m{0}_tw{1}'.format(
                        mass, twist)][0][0]
    return ()
Esempio n. 2
0
def make_prior(models,prior_dict=None,nst=-1,ost=-1,do_amp_prior=True):
 prior = gv.BufferDict()
 
 for model in models:
  skey=model.all_datatags[0]

  if prior_dict is None: ## -- take default from defines
   if (nst > -1 and ost > -1):
    dprior = utf.get_prior_dict(df.define_prior,
     df.define_prior['nkey'],df.define_prior['okey'],nst,ost,do_amp_prior=do_amp_prior)
   else:
    dprior = utf.get_prior_dict(df.define_prior,
     df.define_prior['nkey'],df.define_prior['okey'],df.num_nst,df.num_ost,
      do_amp_prior=do_amp_prior)
   for pkey in dprior[skey]:
    prior[pkey]=dprior[skey][pkey]

   ## -- logarithmize the logarithmic coefficients
   for pkey in prior:
    ## -- don't do logs unless they are in the current model, else double counting
    bkey = utf.get_basekey(pkey)
    #if not(pkey[3:] in model.a+model.b+model.dE) and\
    #   not(pkey[4:] in model.a+model.b+model.dE):
    if not(bkey[1] in model.a+model.b+model.dE):
     continue
    if bkey[0] == 'log':
     negcheck = filter(lambda x: x[1].mean < 0,enumerate(prior[pkey]))
     if len(negcheck) > 0:
      raise ValueError("Prior indices ",list(np.array(negcheck)[:,0]),
       " have negative values, key ",pkey)
     prior[pkey] = gv.log(prior[pkey])
    elif bkey[0] == 'sqrt':
     negcheck = filter(lambda x: x[1].mean < 0,enumerate(prior[pkey]))
     if len(negcheck) > 0:
      raise ValueError("Prior indices ",list(np.array(negcheck)[:,0]),
       " have negative values, key ",pkey)
     prior[pkey] = gv.sqrt(prior[pkey])
  else: ## -- allow passing of new prior, for chained operations
   if (nst > -1 and ost > -1):
    dprior = utf.get_prior_dict(prior_dict,
     prior_dict['nkey'],prior_dict['okey'],nst,ost)
   else:
    dprior = utf.get_prior_dict(prior_dict,
     prior_dict['nkey'],prior_dict['okey'],df.num_nst,df.num_ost)
   for pkey in dprior[skey]:
    prior[pkey]=dprior[skey][pkey]

   for pkey in prior:
    bkey = utf.get_basekey(pkey)
    #if not(pkey[3:] in model.a+model.b+model.dE) and\
    #   not(pkey[4:] in model.a+model.b+model.dE):
    if not(bkey[1] in model.a+model.b+model.dE):
     continue
    if bkey[0] == 'log':
     prior[pkey] = gv.log(prior[pkey])
    elif bkey[0] == 'sqrt':
     prior[pkey] = gv.sqrt(prior[pkey])

 return prior
Esempio n. 3
0
def make_prior_3pt(models,prior_dict=None,nst=-1,ost=-1,n3st=-1,o3st=-1,do_amp_prior=True):
 prior = gv.BufferDict()
 
 for model in models:
  skey=model.all_datatags[0]

  if prior_dict is None: ## -- take default from defines
   if (nst > -1 and ost > -1):
    dprior = utf.get_prior_dict(df.define_prior_3pt,
     df.define_prior_3pt['nkey'],df.define_prior_3pt['okey'],nst,ost,
     df.define_prior_3pt['vkey'],n3st,o3st,
     do_v_symm=df.do_v_symmetric,do_amp_prior=df.do_amp_prior)
   else:
    dprior = utf.get_prior_dict(df.define_prior_3pt,
     df.define_prior_3pt['nkey'],df.define_prior_3pt['okey'],df.num_nst,df.num_ost,
     df.define_prior_3pt['vkey'],df.num_nst_3pt,df.num_ost_3pt,
     do_v_symm=df.do_v_symmetric,do_amp_prior=df.do_amp_prior)
   for pkey in dprior[skey]:
    prior[pkey]=dprior[skey][pkey]

   ## -- logarithmize the logarithmic coefficients
   for pkey in prior:
    ## -- don't do logs unless they are in the current model, else double counting
    bkey = utf.get_basekey(pkey)
    if not(bkey[1] in model.a+model.b+model.dEa+model.dEb):
     continue
    if bkey[0] == 'log':
     #print pkey,prior[pkey]
     prior[pkey] = gv.log(prior[pkey])
    elif bkey[0] == 'sqrt':
     prior[pkey] = gv.sqrt(prior[pkey])
  else: ## -- allow passing of new prior, for chained operations
   if (nst > -1 and ost > -1):
    dprior = utf.get_prior_dict(prior_dict,
     prior_dict['nkey'],prior_dict['okey'],nst,ost,prior_dict['vkey'],n3st,o3st,df.do_v_symmetric)
   else:
    dprior = utf.get_prior_dict(prior_dict,
     prior_dict['nkey'],prior_dict['okey'],df.num_nst,df.num_ost,
     prior_dict['vkey'],df.num_nst_3pt,df.num_ost_3pt,df.do_v_symmetric)
   for pkey in dprior[skey]:
    prior[pkey]=dprior[skey][pkey]

   for pkey in prior:
    bkey = utf.get_basekey(pkey)
    if not(bkey[1] in model.a+model.b+model.dEa+model.dEb):
     continue
    if bkey[0] == 'log':
     prior[pkey] = gv.log(prior[pkey])
    elif bkey[0] == 'sqrt':
     prior[pkey] = gv.sqrt(prior[pkey])

 return prior
Esempio n. 4
0
def safesqrt(x, verbose=False):
    """
    Takes in gvar x, returns sqrt(x). If x not suitable for sqrt, returns sqrt(1.0(9)).
    """
    try:
        sqrtx = sqrt(x)
    except ZeroDivisionError:
        if verbose:
            print(
                'CorrBayes.safesqrt WARNING: invalid argument for sqrt - replacing with sqrt(1.0(9))'
            )
        return sqrt(gv.gvar(1.0, 0.9))
    else:
        return sqrtx
Esempio n. 5
0
def get_results(Fit,thpts):
    p = gv.load(Fit['filename'],method='pickle')
    if 'Hsfilename' in Fit:
        pHs = gv.load(Fit['Hsfilename'],method='pickle')
    # We should only need goldstone masses and energies here
    Fit['M_parent_m{0}'.format(Fit['m_c'])] = p['dE:{0}'.format(Fit['parent-Tag'].format(Fit['m_s'],Fit['m_c']))][0]
    for mass in Fit['masses']:
        Fit['M_parent_m{0}'.format(mass)] = p['dE:{0}'.format(Fit['parent-Tag'].format(Fit['m_s'],mass))][0]
        if Fit['conf'] == 'F':
            print('F',p['dE:{0}'.format('meson-G5T.m{0}_m{1}'.format(Fit['m_s'],mass))][0]-p['dE:{0}'.format(Fit['parent-Tag'].format(Fit['m_s'],mass))][0])
        if Fit['conf'] == 'SF':
            print('SF',p['dE:{0}'.format('meson2G5T.m{0}_m{1}'.format(Fit['m_s'],mass))][0]-p['dE:{0}'.format(Fit['parent-Tag'].format(Fit['m_s'],mass))][0])
        if Fit['conf'] == 'UF':
            print('UF',p['dE:{0}'.format('Bs_G5T-G5T_m{1}'.format(Fit['m_s'],mass))][0]-p['dE:{0}'.format(Fit['parent-Tag'].format(Fit['m_s'],mass))][0])
        if 'Hsfilename' in Fit:
            mass2 = mass 
            if mass == '0.45':
                mass2 = '0.450'
            Fit['MHs_parent_m{0}'.format(mass)] = pHs['dE:{0}'.format(Fit['Hsparent-Tag'].format(Fit['m_s'],mass2))][0]
    Fit['M_daughter'] = p['dE:{0}'.format(Fit['daughter-Tag'][0])][0]
    for t,twist in enumerate(Fit['twists']):
        #Fit is the actual measured value, theory is obtained from the momentum
        Fit['E_daughter_tw{0}_fit'.format(twist)] = p['dE:{0}'.format(Fit['daughter-Tag'][t])][0]
        Fit['E_daughter_tw{0}_theory'.format(twist)] = gv.sqrt(Fit['M_daughter']**2+Fit['momenta'][t]**2)
        for m, mass in enumerate(Fit['masses']):
            for thpt in thpts[Fit['conf']]:
                if twist != '0' or thpt != 'T':   #This second 2 is should be in the data remember for BK
                    Fit['{0}Vnn_m{1}_tw{2}'.format(thpt,mass,twist)] = p['{0}Vnn_m{1}_tw{2}'.format(thpt,mass,twist)][0][0]
                    Fit['{0}_m{1}_tw{2}'.format(thpt,mass,twist)] = 2 * 2 * Fit['Zdisc'][m] * gv.sqrt(Fit['M_parent_m{0}'.format(mass)]*Fit['E_daughter_tw{0}_theory'.format(twist)]) * Fit['{0}Vnn_m{1}_tw{2}'.format(thpt,mass,twist)]
                    #check zdisc is correctly implemented here
    return()
Esempio n. 6
0
def effective_amp(c):
    """
    Returns effective amplitude
    a_{eff}(t) = sqrt( C(t) * exp( m_{eff}(t) * t ) )
    """
    m = effective_mass(c)
    return [sqrt(c[t] * exp(m[t] * t)) for t in range(len(c) - 1)]
Esempio n. 7
0
def line_shift(velocity, line, wavenumber=False, relativistic=True):
    """Return the line shift (in nm or in cm-1) given its relativistic velocity 

    beta = v / c

    gamma = sqrt((1 + beta) / (1 - beta))

    lambda - lambda_0 = lambda_0  * (gamma - 1)

    :param velocity: Line velocity in km.s-1

    :param line: Wavelength/wavenumber of the line. Must be in cm-1 if
      wavenumber is True, must be in nm otherwise.

    :param wavenumber: (Optional) If True the result is returned in cm-1,
      else it is returned in nm.
    """
    if wavenumber:
        line = cm12nm(line)
        
    beta = velocity / orb.constants.LIGHT_VEL_KMS
    if relativistic:
        gamma = gvar.sqrt((1. + beta) / (1. - beta))
        shift = line * (gamma - 1.)
    else:
        shift = line * beta

    if wavenumber:
        shift = nm2cm1(line + shift) - nm2cm1(line)
        
    return shift
Esempio n. 8
0
def make_beta_delta_BsEtas(Fits,t_0,Nijk,Npow,addrho,p,fpf0same,Del,MH_s):
    #an = make_an_BsEtas(n,Nijk,addrho,p,tag,Fit,alat,mass,amh,f0fpsame)
    z0 = make_z(0,t_0,MH_s,Metasphys).mean
    zHsstar = make_z(((make_MHsstar(MH_s))**2).mean,t_0,MH_s,Metasphys).mean
    Fit = Fits[0]
    mass = Fit['masses'][0]
    fit = Fit['conf']
    fp0 = make_fp_BsEtas(Nijk,Npow,addrho,p,Fit,0,0,z0,mass,fpf0same,0)
    fpHsstar = make_an_BsEtas(0,Nijk,addrho,p,'p',Fit,0,mass,0,fpf0same) 
    f00 = make_f0_BsEtas(Nijk,Npow,addrho,p,Fit,0,0,z0,mass,fpf0same,0)
    t_plus = (MH_s + Metasphys)**2
    zprime = (-1) / (2* (t_plus + gv.sqrt( t_plus * (t_plus - t_0) ) ) )
    f0prime = (f00/p['MHs0_{0}_m{1}'.format(fit,mass)]**2)
    fpprime = (fp0/p['MHsstar_{0}_m{1}'.format(fit,mass)]**2)
    for n in range(1,Npow):
        f0prime += zprime * n * make_an_BsEtas(n,Nijk,addrho,p,'0',Fit,0,mass,0,fpf0same) * z0**(n-1)
        fpprime += zprime * n * make_an_BsEtas(n,Nijk,addrho,p,'p',Fit,0,mass,0,fpf0same) * ( z0**(n-1) - (-1)**(n-Npow) * z0**(Npow-1))
        fpHsstar += make_an_BsEtas(n,Nijk,addrho,p,'p',Fit,0,mass,0,fpf0same) * ( zHsstar**(n) - (n/Npow) * (-1)**(n-Npow) * zHsstar**(Npow))
    delta = 1 - ((MH_s**2-Metasphys**2)/fp0) * (fpprime-f0prime)
    invbeta = ((MH_s**2-Metasphys**2)/fp0) * f0prime
    alpha = 1 - (fp0/fpHsstar)
    if MH_s == MBsphys.mean:
        print('delta at MBs = ',delta)
        print('alpha at MBs = ',alpha)
        print('beta at MBs = ',1/invbeta)
    if MH_s == MDsphys.mean:
        print('delta at MDs = ',delta)
        print('alpha at MDs = ',alpha)
        print('beta at MDs = ',1/invbeta)
    return(alpha,delta,invbeta)
Esempio n. 9
0
def apply_fn_op(key,val):
 bkey = get_basekey(key)
 if bkey[0] is None:
  return val
 else:
  if bkey[0] == 'log':
   return gv.log(val)
  elif bkey[0] == 'sqrt':
   return gv.sqrt(val)
  else:
   raise KeyError("Unknown function operation:",bkey[0])
Esempio n. 10
0
def get_results(Fit):
    Vnn = collections.OrderedDict()
    p = gv.load(Fit['filename'])
    for i in range(len(Fit['twists'])):
        Fit['M_KG_tw{0}'.format(Fit['twists'][i])] = gv.sqrt(
            p['dE:{0}'.format(Fit['KGtw{0}'.format(Fit['twists'][i])])][0]**2 -
            Fit['momenta'][i]**2)
        Fit['E_KG_tw{0}'.format(Fit['twists'][i])] = p['dE:{0}'.format(
            Fit['KGtw{0}'.format(Fit['twists'][i])])][0]
        Fit['M_KNG_tw{0}'.format(
            Fit['twists'][i])] = gv.sqrt(p['dE:{0}'.format(Fit[
                'KNGtw{0}'.format(Fit['twists'][i])])][0]**2 -
                                         Fit['momenta'][i]**2)
        Fit['E_KNG_tw{0}'.format(Fit['twists'][i])] = p['dE:{0}'.format(
            Fit['KNGtw{0}'.format(Fit['twists'][i])])][0]
    for mass in Fit['masses']:
        Fit['M_BG_m{0}'.format(mass)] = p['dE:{0}'.format(
            Fit['BGm{0}'.format(mass)])][0]
        Fit['M_BGo_m{0}'.format(mass)] = p['dE:o{0}'.format(
            Fit['BGm{0}'.format(mass)])][0]
        Fit['M_BNG_m{0}'.format(mass)] = p['dE:{0}'.format(
            Fit['BNGm{0}'.format(mass)])][0]
        Fit['M_BNGo_m{0}'.format(mass)] = p['dE:o{0}'.format(
            Fit['BNGm{0}'.format(mass)])][0]
        #print(gv.evalcorr([Fit['M_NG_m{0}'.format(mass)],Fit['M_G_m{0}'.format(mass)]]))
        for twist in Fit['twists']:
            if 'SVnn_m{0}_tw{1}'.format(mass, twist) in p:
                Fit['Sm{0}_tw{1}'.format(mass, twist)] = 2 * 2 * gv.sqrt(
                    Fit['E_KG_tw{0}'.format(twist)] *
                    Fit['M_BG_m{0}'.format(mass)]) * p[
                        'SVnn_m{0}_tw{1}'.format(mass, twist)][0][0]
                Fit['Vm{0}_tw{1}'.format(mass, twist)] = 2 * 2 * gv.sqrt(
                    Fit['E_KG_tw{0}'.format(twist)] *
                    Fit['M_BG_m{0}'.format(mass)]) * p[
                        'VVnn_m{0}_tw{1}'.format(mass, twist)][0][0]
                Fit['Tm{0}_tw{1}'.format(mass, twist)] = 2 * 2 * gv.sqrt(
                    Fit['E_KG_tw{0}'.format(twist)] * Fit['M_BG_m{0}'.format(
                        mass)]) * p['TVnn_m{0}_tw{1}'.format(
                            mass, twist)][0][0]  ### Is this correct???
    return ()
Esempio n. 11
0
def apod2width(apod):
    """Return the width of the gaussian window for a given apodization level.

    :param apod: Apodization level (must be >= 1.)

    The apodization level is the broadening factor of the line (an
    apodization level of 2 mean that the line fwhm will be 2 times
    wider).
    """
    if apod < 1.:
        raise Exception('Apodization level (broadening factor) must be > 1')

    return apod - 1. + (gvar.erf(math.pi / 2. * gvar.sqrt(apod - 1.)) *
                        orb.constants.FWHM_SINC_COEFF)
Esempio n. 12
0
def gaussian1d(x,h,a,dx,fwhm):
    """Return a 1D gaussian given a set of parameters.

    :param x: Array giving the positions where the gaussian is evaluated
    :param h: Height
    :param a: Amplitude
    :param dx: Position of the center
    :param fwhm: FWHM, :math:`\\text{FWHM} = \\text{Width} \\times 2 \\sqrt{2 \\ln 2}`
    """
    if not isinstance(x, np.ndarray):
        x = np.array(x)

    w = fwhm / (2. * gvar.sqrt(2. * gvar.log(2.)))
    return  h + a * gvar.exp(-(x - dx)**2. / (2. * w**2.))
Esempio n. 13
0
def gaussian1d_complex(x,h,a,dx,fwhm):
    """Return a 1D gaussian given a set of parameters.

    :param x: Array giving the positions where the gaussian is evaluated
    :param h: Height
    :param a: Amplitude
    :param dx: Position of the center
    :param fwhm: FWHM, :math:`\\text{FWHM} = \\text{Width} \\times 2 \\sqrt{2 \\ln 2}`
    """
    if not isinstance(x, np.ndarray):
        x = np.array(x)

    w = fwhm / (2. * gvar.sqrt(2. * gvar.log(2.)))
    b = (x - dx) / (np.sqrt(2) * w)
    return  (h + a * gvar.exp(-b**2.), h + a * 2 / np.sqrt(np.pi) * special.dawsn(b))
Esempio n. 14
0
def amp_superav(c):
    """
    Takes superaverage of correlator c, then effective amplitude,
    then applies a correction factor sqrt( 2 / 1 + e^{-m_{eff}(t)} ).

    This is because taking the superaverage shifts the effective amplitude of a correlator,
    this correction cancels that shift.

    """
    c = superav(c)
    m = effective_mass(c)
    return [
        sqrt(c[t] * exp(m[t] * t) * 2 / (1 + exp(-m[t])))
        for t in range(len(c) - 1)
    ]
Esempio n. 15
0
def sincgauss1d_complex(x, h, a, dx, fwhm, sigma):
    """The "complex" version of the sincgauss (dawson definition).

    This is the real sinc*gauss function when ones wants to fit both the real
    part and the imaginary part of the spectrum.

    :param x: 1D array of float64 giving the positions where the
      function is evaluated
    
    :param h: Height
    :param a: Amplitude
    :param dx: Position of the center
    :param fwhm: FWHM of the sinc
    :param sigma: Sigma of the gaussian.
    """
    if np.size(sigma) > 1:
        if np.any(sigma != sigma[0]):
            raise Exception('Only one value of sigma can be passed')
        else:
            sigma = sigma[0]

    sigma = np.fabs(sigma)
    fwhm = np.fabs(fwhm)

    broadening_ratio = np.fabs(sigma / fwhm)
    max_broadening_ratio = gvar.mean(broadening_ratio) + gvar.sdev(
        broadening_ratio)

    if broadening_ratio < 1e-2:
        return sinc1d_complex(x, h, a, dx, fwhm)

    if np.isclose(gvar.mean(sigma), 0.):
        return sinc1d_complex(x, h, a, dx, fwhm)

    if max_broadening_ratio > 7:
        return gaussian1d_complex(x, h, a, dx,
                                  sigma * (2. * gvar.sqrt(2. * gvar.log(2.))))

    width = gvar.fabs(fwhm) / orb.constants.FWHM_SINC_COEFF
    width /= np.pi  ###

    a_ = sigma / np.sqrt(2) / width
    b_ = ((x - dx) / np.sqrt(2) / sigma)
    if b_.dtype == np.float128: b_ = b_.astype(float)

    sg1c = orb.cgvar.sincgauss1d_complex(a_, b_)
    return (h + a * sg1c[0], h + a * sg1c[1])
Esempio n. 16
0
def sincgauss1d(x, h, a, dx, fwhm, sigma):
    """Return a 1D sinc convoluted with a gaussian of parameter sigma.

    If sigma == 0 returns a pure sinc.

    :param x: 1D array of float64 giving the positions where the
    sinc is evaluated
    
    :param h: Height
    :param a: Amplitude
    :param dx: Position of the center
    :param fwhm: FWHM of the sinc
    :param sigma: Sigma of the gaussian.
    """
    if np.size(sigma) > 1:
        if np.any(sigma != sigma[0]):
            raise Exception('Only one value of sigma can be passed')
        else:
            sigma = sigma[0]

    sigma = np.fabs(sigma)
    fwhm = np.fabs(fwhm)

    broadening_ratio = np.fabs(sigma / fwhm)
    max_broadening_ratio = gvar.mean(broadening_ratio) + gvar.sdev(
        broadening_ratio)

    if broadening_ratio < 1e-2:
        return sinc1d(x, h, a, dx, fwhm)

    if np.isclose(gvar.mean(sigma), 0.):
        return sinc1d(x, h, a, dx, fwhm)

    if max_broadening_ratio > 7:
        return gaussian1d(x, h, a, dx,
                          sigma * (2. * gvar.sqrt(2. * gvar.log(2.))))

    width = gvar.fabs(fwhm) / orb.constants.FWHM_SINC_COEFF
    width /= np.pi  ###

    a_ = sigma / math.sqrt(2) / width
    b_ = (x - dx) / math.sqrt(2) / sigma

    return h + a * orb.cgvar.sincgauss1d(a_, b_)
Esempio n. 17
0
def line_shift(velocity, line, wavenumber=False):
    """Return the line shift given its velocity in nm or in cm-1.

    beta = v / c

    gamma = sqrt((1 + beta) / (1 - beta))

    lambda - lambda_0 = lambda_0  * (gamma - 1)

    :param velocity: Line velocity in km.s-1

    :param line: Wavelength/wavenumber of the line. Must be in cm-1 if
      wavenumber is True, must be in nm otherwise.

    :param wavenumber: (Optional) If True the result is returned in cm-1,
      else it is returned in nm.
    """
    beta = velocity / orb.constants.LIGHT_VEL_KMS
    gamma = gvar.sqrt((1. + beta) / (1. - beta))
    if wavenumber:
        shift = line * (1. / gamma - 1.)
    else:
        shift = line * (gamma - 1.)
    return shift
Esempio n. 18
0
def get_sigma_str(key,fit,prior,j,do_unicode=True):
 ## -- list the sigma away from prior
 #
 try:
  ## -- requesting log, log prior
  ##    or requesting linear, linear prior
  sig=int(np.abs(np.trunc(\
      (fit.p[key][j].mean-prior[key][j].mean)\
       /(prior[key][j]).sdev)))
 except KeyError:
  ## -- requested linear, have log or sqrt prior
  try:
   sig=int(np.abs(np.trunc(\
       (gv.log(fit.p[key][j].mean)-prior['log('+key+')'][j].mean)\
        /(prior['log('+key+')'][j]).sdev)))
  except KeyError:
   sig=int(np.abs(np.trunc(\
       (gv.sqrt(fit.p[key][j].mean)-prior['sqrt('+key+')'][j].mean)\
        /(prior['sqrt('+key+')'][j]).sdev)))
 except TypeError:
  ## -- Vnn, Vno, etc...
  #print key,j
  sig=int(np.abs(np.trunc(\
      (fit.p[key][j[0]][j[1]].mean-prior[key][j[0]][j[1]].mean)\
       /(prior[key][j[0]][j[1]]).sdev)))
 if do_unicode:
  if sig > 0:
   sigstr=str(sig)+u'\u03C3' # unicode for sigma (cannot be saved to string)
  else:
   sigstr='  '
 else:
  if sig > 0:
   sigstr=str(sig)+'sig'
  else:
   sigstr='    '
 return sigstr
Esempio n. 19
0
 def gaussian_pdf(x, f=1.):
     xmean = gv.mean(x)
     xvar = gv.var(x) * f ** 2
     return gv.exp(-xmean ** 2 / 2. /xvar) / gv.sqrt(2 * np.pi * xvar)
Esempio n. 20
0
import gvar       as gv
import util_funcs as utf

## -- HISQ a=0.15 l3248 physical
## -- prior mass splittings

xnpi=gv.sqrt(30) ## -- N pi state suppression factor (EFT gives 1/30.)
## -- PDG inputs
## -- S8'
ngrd_s8p=gv.gvar(0.94,0.1)  ## -- even ground state (PDG \Delta mass)
nn1440_s8p=gv.gvar(1.10,0.1) ## -- even radial state (PDG Nucleon(1440) state)
nn1680_s8p=gv.gvar(1.28,0.1) ## -- even radial state (PDG Nucleon(1680) state)
on1520_s8p=gv.gvar(1.16,0.1)  ## -- odd nucleon state (PDG nucleon(1520) state)
on1535_s8p=gv.gvar(1.17,0.1)  ## -- odd nucleon state (PDG nucleon(1535) state)
on1650_s8p=gv.gvar(1.26,0.1)  ## -- odd nucleon state (PDG delta(1675) state)
on1675_s8p=gv.gvar(1.28,0.1)  ## -- odd nucleon state (PDG delta(1675) state)
nd1600_s8p=gv.gvar(1.22,0.1)  ## -- odd delta state (PDG delta(1600) state)
nd1620_s8p=gv.gvar(1.23,0.1)  ## -- odd delta state (PDG delta(1600) state)
nd1680_s8p=gv.gvar(1.28,0.1)  ## -- odd delta state (PDG delta(1680) state)
od1620_s8p=gv.gvar(1.23,0.1)  ## -- odd delta state (PDG delta(1620) state) (UNUSED)
od1700_s8p=gv.gvar(1.29,0.1)  ## -- odd delta state (PDG delta(1700) state)
delr_s8p=gv.gvar(0.30,0.1)  ## -- radial splitting (PDG radial state)
## -- S8
ngrd_s8=gv.gvar(0.71,0.1)  ## -- even ground state (PDG Nucleon mass)
ogrd_s8=gv.gvar(0.97,0.1)  ## -- odd ground state (N+pi, 1 momentum unit)
onpi100t_s8=gv.gvar(1.01,0.1)  ## -- odd ground state (N+pi, 1 momentum unit+taste)
#onpi100t_s8=gv.gvar(1.03,0.1)  ## -- odd ground state (N+pi, 1 momentum unit+taste)
onpi110_s8=gv.gvar(1.07,0.1)  ## -- odd ground state (N+pi, 2 momentum unit)
#onpi110_s8=gv.gvar(1.07,0.03)  ## -- odd ground state (N+pi, 2 momentum unit)
nn1440_s8=nn1440_s8p       ## -- even radial state (PDG Nucleon(1440) state)
nn1680_s8=nn1680_s8p       ## -- even radial state (PDG Nucleon(1680) state)
Esempio n. 21
0
 def gaussian_pdf(x, f=1.):
     xmean = gv.mean(x)
     xvar = gv.var(x) * f**2
     return gv.exp(-xmean**2 / 2. / xvar) / gv.sqrt(2 * np.pi * xvar)
Esempio n. 22
0
def effective_mass(c):
    """
    Returns effective mass of correlator "c"
     m_{eff}(t) = log( C(t) / C(t+1) ).
    """
    return [log(sqrt(c[t] / c[t + 1])**2) for t in range(len(c) - 1)]
Esempio n. 23
0
    def print_fit(self,par,outfile):
        """print the energy and amplitude results from a fit"""
        fit = self.results
        name = self.name
        p = fit.p
        self.chi2_cal()
        #self.chi2_aug_part()
        self.Q = conf_int(self.chi2/2, par.ncon, self.dof/2)
        nexp = self.child.nexp

        name = self.child.name
        CdE = exp(p['log('+name+':dE)'])
        CE = [sum(CdE[:i+1]) for i in range(nexp)]
        a = exp(p['log('+name+':a)'])
        if self.name != 'pimom0':
            CdEo = exp(p['log('+name+':dEo)'])
            CEo = [sum(CdEo[:i+1]) for i in range(nexp)]
            ao = exp(p['log('+name+':ao)'])

        name = self.parent.name
        PdE = exp(p['log('+name+':dE)'])
        PE = [sum(PdE[:i+1]) for i in range(nexp)]
        b = exp(p['log('+name+':a)'])
        if self.name != 'pimom0':
            PdEo = exp(p['log('+name+':dEo)'])
            PEo = [sum(PdEo[:i+1]) for i in range(nexp)]
            bo = exp(p['log('+name+':ao)'])

        # calculating f_0
        # DOESN"T WORK FOR D TO K YET!!!!!!!!!
        if self.child.name == 'pimom0':
            mpi = CE[0]
        else:
            mpi = gvar(par.pi0,par.pi0_err)
        if self.child.name == 'pimom0' or self.child.name == 'pimom2':
            m_q = par.m_l
        else:
            m_q = par.m_s
        Epi = CE[0]
        mD = PE[0]
        v = p['Vnn'][0][0]
        self.f_0 = v*sqrt(Epi*mD)*(par.m_c-m_q)/(mD**2-mpi**2)
        self.qsq = mpi**2+mD**2-2*mD*Epi        

        ofile = open(outfile,'a')

        if self.dof != 0:
            chi2dof = self.chi2/self.dof
        else:
            chi2dof = 99.9
        if chi2dof > 99:
            chi2dof = 99.9

        pars = "{:s} & {:2d}-{:2d} & {:2d}-{:2d} & {:d}+{:d} & {:4.1f} & {:3d} & {:4.2f} & "
        energies = "{:s} & {:<11s} & {:<11s} & "
        form = "{:<12s} & {:<12s} \\\\ \n"
        ofile.write( pars.format( self.name,self.tmin,self.child.tmax,self.tmax,self.parent.tmax,
                                  nexp,nexp,chi2dof,self.dof,self.Q )
                     +energies.format( self.child.name,CE[0].fmt(ndecimal=4),a[0].fmt(ndecimal=4) )
                     +energies.format( self.parent.name,PE[0].fmt(ndecimal=4),b[0].fmt(ndecimal=4) )
                     +form.format( self.f_0.fmt(ndecimal=4), self.qsq.fmt(ndecimal=4) ) )
Esempio n. 24
0
def main():
    make_params()
    for Fit in Fits:
        print('Plot for', Fit['filename'])
        get_results(Fit)
        F_0 = collections.OrderedDict()
        F_plus = collections.OrderedDict()
        F_T = collections.OrderedDict()
        qSq = collections.OrderedDict()
        Z = collections.OrderedDict()
        Sca = collections.OrderedDict()
        Vec = collections.OrderedDict()
        Ten = collections.OrderedDict()
        for mass in Fit['masses']:
            F_0[mass] = collections.OrderedDict()
            F_plus[mass] = collections.OrderedDict()
            F_T[mass] = collections.OrderedDict()
            qSq[mass] = collections.OrderedDict()
            Z[mass] = collections.OrderedDict()
            Sca[mass] = collections.OrderedDict()
            Vec[mass] = collections.OrderedDict()
            Ten[mass] = collections.OrderedDict()
            Z_v = (float(mass) -
                   float(Fit['m_s'])) * Fit['Sm{0}_tw0'.format(mass)] / (
                       (Fit['M_BG_m{0}'.format(mass)] - Fit['M_KG_tw0']) *
                       Fit['Vm{0}_tw0'.format(mass)])
            plt.errorbar((Fit['a']**2).mean,
                         Z_v.mean,
                         xerr=(Fit['a']**2).sdev,
                         yerr=Z_v.sdev,
                         label=mass)
            for twist in Fit['twists']:
                if 'Sm{0}_tw{1}'.format(mass, twist) in Fit:
                    delta = (float(mass) - float(Fit['m_s'])) * (
                        Fit['M_BG_m{0}'.format(mass)] -
                        Fit['E_KG_tw{0}'.format(twist)])
                    qsq = Fit['M_BG_m{0}'.format(mass)]**2 + Fit[
                        'M_KG_tw{0}'.format(
                            twist)]**2 - 2 * Fit['M_BG_m{0}'.format(
                                mass)] * Fit['E_KG_tw{0}'.format(twist)]
                    t = (Fit['M_BG_m{0}'.format(mass)] +
                         Fit['M_KG_tw{0}'.format(twist)])**2
                    z = (gv.sqrt(t - qsq) - gv.sqrt(t)) / (gv.sqrt(t - qsq) +
                                                           gv.sqrt(t))
                    if FitNegQsq == False:
                        if qsq.mean >= 0:
                            F0 = (float(mass) - float(Fit['m_s'])) * (
                                1 / (Fit['M_BG_m{0}'.format(mass)]**2 -
                                     Fit['M_KG_tw{0}'.format(twist)]**2)
                            ) * Fit['Sm{0}_tw{1}'.format(mass, twist)]
                            FT = Fit['Sm{0}_tw{1}'.format(mass, twist)] * (
                                Fit['M_BG_m{0}'.format(mass)] +
                                Fit['M_KG_m{0}'.format(mass)]) / (
                                    2 * Fit['M_BG_m{0}'.format(mass)] *
                                    float(twist)
                                )  # Have we used correct masses?
                            F_0[mass][twist] = F0
                            F_T[mass][twist] = FT
                            qSq[mass][twist] = qsq
                            Z[mass][twist] = z
                            Sca[mass][twist] = Fit['Sm{0}_tw{1}'.format(
                                mass, twist)]
                            Vec[mass][twist] = Fit['Vm{0}_tw{1}'.format(
                                mass, twist)]
                            Ten[mass][twist] = Fit['Tm{0}_tw{1}'.format(
                                mass, twist)]
                            A = Fit['M_BG_m{0}'.format(mass)] + Fit[
                                'E_KG_tw{0}'.format(twist)]
                            B = (Fit['M_BG_m{0}'.format(mass)]**2 -
                                 Fit['M_KG_tw{0}'.format(twist)]**2) * (
                                     Fit['M_BG_m{0}'.format(mass)] -
                                     Fit['E_KG_tw{0}'.format(twist)]) / qsq
                            if twist != '0':
                                F_plus[mass][twist] = (1 / (A - B)) * (
                                    Z_v * Fit['Vm{0}_tw{1}'.format(
                                        mass, twist)] - B * F0)
                    elif FitNegQsq == True:
                        F0 = (float(mass) - float(Fit['m_s'])) * (
                            1 / (Fit['M_BG_m{0}'.format(mass)]**2 -
                                 Fit['M_KG_tw{0}'.format(twist)]**2)
                        ) * Fit['Sm{0}_tw{1}'.format(mass, twist)]
                        FT = Fit['Sm{0}_tw{1}'.format(mass, twist)] * (
                            Fit['M_BG_m{0}'.format(mass)] +
                            Fit['M_KG_m{0}'.format(mass)]
                        ) / (2 * Fit['M_BG_m{0}'.format(mass)] * float(twist))
                        F_0[mass][twist] = F0
                        F_T[mass][twist] = FT
                        qSq[mass][twist] = qsq
                        Z[mass][twist] = z
                        Sca[mass][twist] = Fit['Sm{0}_tw{1}'.format(
                            mass, twist)]
                        Vec[mass][twist] = Fit['Vm{0}_tw{1}'.format(
                            mass, twist)]
                        Ten[mass][twist] = Fit['Tm{0}_tw{1}'.format(
                            mass, twist)]
                        A = Fit['M_BG_m{0}'.format(mass)] + Fit[
                            'E_KG_tw{0}'.format(twist)]
                        B = (Fit['M_BG_m{0}'.format(mass)]**2 -
                             Fit['M_KG_tw{0}'.format(twist)]**2) * (
                                 Fit['M_BG_m{0}'.format(mass)] -
                                 Fit['E_KG_tw{0}'.format(twist)]) / qsq
                        if twist != '0':
                            F_plus[mass][twist] = (1 / (A - B)) * (
                                Z_v * Fit['Vm{0}_tw{1}'.format(mass, twist)] -
                                B * F0)
        plot_f(Fit, F_0, F_plus, qSq, Z, Sca, Vec)
    plt.show()
    return ()
Esempio n. 25
0
def main():
    make_params()
    for Fit in Fits:
        print('Plot for', Fit['filename'])
        get_results(Fit)
        F_0 = collections.OrderedDict()
        F_plus = collections.OrderedDict()
        qSq = collections.OrderedDict()
        Z = collections.OrderedDict()
        Sca = collections.OrderedDict()
        Vec = collections.OrderedDict()
        for mass in Fit['masses']:
            F_0[mass] = []
            F_plus[mass] = []
            qSq[mass] = []
            Z[mass] = []
            Sca[mass] = []
            Vec[mass] = []
            Z_v = (float(mass) -
                   float(Fit['m_s'])) * Fit['Sm{0}_tw0'.format(mass)] / (
                       (Fit['M_G_m{0}'.format(mass)] - Fit['M_D_tw0']) *
                       Fit['Vm{0}_tw0'.format(mass)])
            for twist in Fit['twists']:
                if 'Sm{0}_tw{1}'.format(mass, twist) in Fit:
                    delta = (float(mass) - float(Fit['m_s'])) * (
                        Fit['M_G_m{0}'.format(mass)] -
                        Fit['E_D_tw{0}'.format(twist)])
                    qsq = (Fit['M_G_m{0}'.format(mass)]**2 +
                           Fit['M_D_tw{0}'.format(twist)]**2 -
                           2 * Fit['M_G_m{0}'.format(mass)] *
                           Fit['E_D_tw{0}'.format(twist)])
                    t = (Fit['M_G_m{0}'.format(mass)] +
                         Fit['M_D_tw{0}'.format(twist)])**2
                    z = (gv.sqrt(t - qsq) - gv.sqrt(t)) / (gv.sqrt(t - qsq) +
                                                           gv.sqrt(t))
                    if qsq.mean >= 0:
                        F0 = (float(mass) - float(Fit['m_s'])) * (
                            1 / (Fit['M_G_m{0}'.format(mass)]**2 -
                                 Fit['M_D_tw{0}'.format(twist)]**2)
                        ) * Fit['Sm{0}_tw{1}'.format(mass, twist)]
                        F_0[mass].append(F0)
                        if GeV == True:
                            qSq[mass].append(qsq / (Fit['a']**2))
                        else:
                            qSq[mass].append(qsq)
                        Z[mass].append(z)
                        Sca[mass].append(Fit['Sm{0}_tw{1}'.format(mass,
                                                                  twist)])
                        Vec[mass].append(Fit['Vm{0}_tw{1}'.format(mass,
                                                                  twist)])
                        A = Fit['M_G_m{0}'.format(mass)] + Fit[
                            'E_D_tw{0}'.format(twist)]
                        B = (Fit['M_G_m{0}'.format(mass)]**2 -
                             Fit['M_D_tw{0}'.format(twist)]**2) * (
                                 Fit['M_G_m{0}'.format(mass)] -
                                 Fit['E_D_tw{0}'.format(twist)]) / qsq
                        if twist != '0':
                            F_plus[mass].append(
                                (1 / (A - B)) *
                                (Z_v * Fit['Vm{0}_tw{1}'.format(mass, twist)] -
                                 B * F0))
        plot_f(Fit, F_0, F_plus, qSq, Z, Sca, Vec)
    plt.show()
    return ()
Esempio n. 26
0
def make_z(qsq,t_0,M_parent,M_daughter):
    t_plus = make_t_plus(M_parent,M_daughter)
    z = (gv.sqrt(t_plus - qsq) - gv.sqrt(t_plus - t_0)) / (gv.sqrt(t_plus - qsq) + gv.sqrt(t_plus - t_0))
    if z.mean ==0 and z.sdev ==0:
        z = gv.gvar(0,1e-16)
    return(z)