package voi.routines;
import java.io.*;
import java.util.*;

// This class is used to obtain the Absolute Magnitude given apparent magnitude(m) and resdhift(z)

public class Magnitude
{
	static double h0; 			// Hubbles constant
	static final long c = 300000;		// Speed of light 
	static double aop;			// Spectral index in the optical wondow
	static double q0;			// scale factor ??
	static double h100;		
	static double h100Const;
	
	//  This routine outputs the absolute magnitude given its apparent magnitude and redshift
	
	public static void setParameters (double h_0, double q_0, double a_o_p)
	{
		h0 = h_0;
		q0 = q_0;
		aop = a_o_p;
		h100 = h0/100;
		h100Const = 2.5 * (Math.log (h100)/Math.log (10));
	}	
	
	public static double getAbsoluteMagnitude (double appMag, double zz)
	{
		double absMag;
		double term1 = 5 * (Math.log (dm(zz))/Math.log (10));
		double term2 = 2.5 * (1 + aop) * (Math.log (1+zz)/Math.log (10));
		absMag = appMag - term1 - term2 - 42.39 + h100Const;
		return absMag;
	}
	
	public static double dm (double z)
	{
		double temp = fq0 (z) / (1+z);
		return temp;
	}
	
	public static double fq0 (double z)
	{
		if (q0 == 0.0) return (z * (1+z/2));
		else
		{
			double temp = (q0*z + (q0-1)*(Math.sqrt (1+2*q0*z) -1))/(q0*q0);
			return temp;
		}
	}	
	
}


