import math


def calc_beta(xpix, ypix, phi, dist) :
    """Evaluates fiber beta angle [rad] for two peaks in equatorial region
       - xpix - [in] x coordinate of the point
       - ypix - [in] y coordinate of the point 
       - phi  - [in] fiber tilt angle [rad] if the detector plane
       - dist - [in] distance from sample to detector
    """	
    x1 = xpix / dist
    y1 = ypix / dist
    fac = 1. - math.sqrt(x1*x1 + y1*y1 + 1.)
    return -math.atan((y1*math.cos(phi) + x1*math.sin(phi)) / fac)