import math


def calc_phi(x1pix, y1pix, x2pix, y2pix, dist) :
    """Evaluates fiber phi angle [rad] for two peaks in equatorial region
       - x1pix - [in] x coordinate of the 1st point
       - y1pix - [in] y coordinate of the 1st point 
       - x1pix - [in] x coordinate of the 2nd point 
       - y1pix - [in] y coordinate of the 2nd point 
       - dist  - [in] distance from sample to detector
    """	
    x1 = x1pix / dist
    y1 = y1pix / dist
    x2 = x2pix / dist
    y2 = y2pix / dist	
    d1 = math.sqrt(x1*x1 + y1*y1 + 1.) - 1.
    d2 = math.sqrt(x2*x2 + y2*y2 + 1.) - 1.
    return math.atan(-(y2*d1 - y1*d2) / (x2*d1 - x1*d2))