import java.awt.*;
import java.util.*;
import java.applet.Applet;

public abstract class STfit extends LinearFit {

    static final double mt0 = 174.3;
    static final double mt0err = 5.0;
    static final double mh0 = 100.0;
    static final double alpha0 = 128.933;
 
    double mh, mt, alpha;
    double mWoffset, sin2thetaoffset, Gammaloffset;

    public STfit(){
	super(3);
        setDependence(0,-0.287,0.443);
        setDependence(1,0.00359,-0.00254);
        setDependence(2,-0.191,0.783);
        restorerefvalues();
        restorealpha();
    }
 
    void fillX0(){
        X0[0] = mWval();
        X0[1] = sin2thetaval();
        X0[2] = Gammalval();
    }

    void restorerefvalues(){
        mh = mh0;
        mt = mt0;
        fillX0();
    }
        
    void restorealpha(){
        alpha = alpha0;
        fillX0();
    }
        
    void addmW(double MW, double MWERR){
        addData(0,MW,MWERR);
    }

    void addsin2theta(double SIN2THETA, double SIN2THETAERR){
        addData(1,SIN2THETA,SIN2THETAERR);
    }
 
    void addGammal(double GAMMAL, double GAMMALERR){
        addData(2,GAMMAL,GAMMALERR);
    }
 
    void newrefvalues(double MH, double MT){
	mh = MH; 
        mt = MT;
        fillX0();
    }
       
    void newalpha(double ALPHA){
	alpha = ALPHA; 
        fillX0();
    }

    void drawHiggsBox(Graphics g){
        drawHiggsBox(g,mh0,mt0,mt0err);
    }

    void drawHiggsBox(Graphics g, double mh, double mt, double mterr){
        double S, S0, T, T0, mmt, mmh;
        newrefvalues(mh,mt);
        fit();
        S0 = center[0];
        T0 = center[1];
        for (mmt = mt-mterr; mmt < mt + 1.01*mterr; mmt += mterr){
            plotStream PS = new plotStream();
            for (mmh = 100.0; mmh < 1001.0; mmh += 50.0){
		newrefvalues(mmh,mmt);
                fit();
                S = center[0];
                T = center[1];
                PS.add(S0-S,T0-T);
	    }
            plotCurve(g,PS);
	}
        double[] Hm = { 100.0, 200.0, 300.0, 500.0, 1000.0};
        for (int i = 0; i < 5; i++){
            plotStream PS = new plotStream();
            for (mmt = mt-mterr; mmt < mt + 1.01*mterr; mmt += mterr){
		newrefvalues(Hm[i],mmt);
                fit();
                S = center[0];
                T = center[1];
                PS.add(S0-S,T0-T);
	    }
            plotCurve(g,PS);
	}
    }
       
/* based on W. Marciano, hep-ph/0003181    */

    double mWval(){
        double hlog = Math.log(mh/100.0);
        double tshift = (mt - 174.3)/5.1;
        double alphashift = (alpha - 128.933)/0.021;
        double val = 80.385 + 0.032*tshift + (-0.003 * alphashift)
                                  - (0.0579*hlog + 0.0080* hlog*hlog);
        return val;
    }
      
    double sin2thetaval(){
        double hlog = Math.log(mh/100.0);
        double tshift = (mt - 174.3)/5.1;
        double alphashift = (alpha - 128.933)/0.021;
        double val = 0.23140 + (-0.00017*tshift) + 0.00006 * alphashift
                       + 0.000522*hlog;
        return val;
    }
   
    double Gammalval(){
        double hlog = Math.log(mh/100.0);
        double tshift = (mt - 174.3)/5.1;
        double alphashift = (alpha - 128.933)/0.021;
        double val = 84.011 + 0.047*tshift + (-0.0028 * alphashift)
                    - (0.0538*hlog + 0.0237* hlog*hlog);
        return val;
    }
}
      
