package hep.graphics.heprep.util;

/**
 *
 * @author Mark Donszelmann
 *
 * @version $Id: HepRepMath.java,v 1.2 2002/09/18 23:59:59 duns Exp $
 */

public class HepRepMath {
    public static final String cvsId = "$Id: HepRepMath.java,v 1.2 2002/09/18 23:59:59 duns Exp $";

    // Static class, not to be instantiated
    private HepRepMath() {
    }

    public static double getX(double x, double xVertex) {
        return x-xVertex;
    }

    public static double getY(double y, double yVertex) {
        return y-yVertex;
    }

    public static double getZ(double z, double zVertex) {
        return z-zVertex;
    }

    public static double getRho(double x, double y, double xVertex, double yVertex) {
        double dx = getX(x, xVertex);
        double dy = getY(y, yVertex);
        return Math.sqrt(dx*dx+dy*dy);
    }

    public static double getRho(double x, double y) {
        return Math.sqrt(x*x+y*y);
    }

    public static double getPhi(double x, double y, double xVertex, double yVertex) {
        return Math.atan2(getY(y, yVertex), getX(x, xVertex));
    }

    public static double getPhi(double x, double y) {
        return Math.atan2(y,x);
    }

    /**
     * Return the dip angle of the track given the z-vertex position.
     */
    public static double getTheta(double x, double y, double z, double xVertex, double yVertex, double zVertex) {
        return Math.atan2(getRho(getX(x, xVertex), getY(y, yVertex)), getZ(z, zVertex));
    }

    /**
     * Return the dip angle of the track assuming a zero z-vertex
     * position.
     */
    public static double getTheta(double x, double y, double z) {
        return Math.atan2(getRho(x, y), z);
    }

    /**
     * Return the spherical radius to the point given the z-vertex
     * position.
     */
    public static double getR(double x, double y, double z, double xVertex, double yVertex, double zVertex) {
        double rho = getRho(getX(x, xVertex), getY(y, yVertex));
        double dz = getZ(z, zVertex);
        return Math.sqrt(rho*rho+dz*dz);
    }

    /**
     * Return the spherical radius to the point assuming a z-vertex
     * position.
     */
    public static double getR(double x, double y, double z) {
        double rho = getRho(x, y);
        return Math.sqrt(rho*rho+z*z);
    }

    /**
     * Return the pseudorapidity of the point given the z-vertex
     * position.
     */
    public static double getEta(double x, double y, double z, double xVertex, double yVertex, double zVertex) {
        double ct = Math.cos(getTheta(x, y, z, xVertex, yVertex, zVertex));
        return -0.5*Math.log((1.-ct)/(1.+ct));
    }

    /**
     * Return the pseudorapidity of the point assuming zero z-vertex
     * position.
     */
    public static double getEta(double x, double y, double z) {
        double ct = Math.cos(getTheta(x, y, z));
        return -0.5*Math.log((1.-ct)/(1.+ct));
    }

}