/*
 * Eichung.C
 *
 *  Created on: 21.07.2010
 *      Author: Katrin Goebel
 *      Calibration for etrax237 adcs
 */

// Eichung etrax237

void Eichung()
{
    gROOT->Reset();
    gStyle->SetOptTitle(0);
    gStyle->SetOptStat(0);
    //gStyle->SetOptFit(11);
    gStyle->SetCanvasColor(10);
    gStyle->SetTitleFillColor(10);
    gStyle->SetStatColor(10);
    gStyle->SetPadRightMargin(0.1);
    gStyle->SetPadLeftMargin(0.15);
    gStyle->SetTitleOffset(1.6,"y");
    gStyle->SetPalette(1);
    gStyle->SetPadColor(10);


    // create the coordinate arrays
    const Int_t n = 5;
    Int_t volts[n] = {0, 2, 5, 7, 9};
    Int_t ch0[n] = {114,  608,1345,1832,2326};
    Int_t ch1[n] = {114,  608,1346,1833,2327};
    Int_t ch2[n] = {114,  608,1345,1833,2327};
    Int_t ch3[n] = {114,  608,1344,1830,2322};
    Int_t ch4[n] = {598, 1033,1592,1912,2354};
    Int_t ch5[n] = {149,  642,1369,1845,2322};
    Int_t ch6[n] = {149,  643,1376,1846,2324};
    Int_t ch7[n] = {114,  608,1345,1833,2326};

    TCanvas* c1 = new TCanvas("c1","Eichung Temperatursensoren",200,10,1000,800);
    c1->Divide(3,3);
    c1->SetGrid();

    TH2F* blub=new TH2F("blub","",100,0,2500,100,0,10);
    blub->SetXTitle("Voltage [V]");
    blub->SetYTitle("ADC channel");

    //############################################################################
    c1 ->cd(1);

    blub->Draw();

    TGraph* gr0 = new TGraph(n,ch0,volts);
    //gr->SetTitle("Plateaukurve");
    gr0->SetMarkerColor(2);
    gr0->SetMarkerStyle(21);
    gr0->GetXaxis()->SetTitle("Spannung [V]");
    gr0->GetYaxis()->SetTitle("[ADC channel]");
    gr0->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit0 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr0->Fit(linearfit0,"NR","x",0,2500);
    linearfit0->Draw("same");


    //############################################################################
    c1 ->cd(2);

    blub->Draw();

    TGraph* gr1 = new TGraph(n,ch1,volts);
    //gr->SetTitle("Plateaukurve");
    gr1->SetMarkerColor(2);
    gr1->SetMarkerStyle(21);
    gr1->GetXaxis()->SetTitle("Spannung [V]");
    gr1->GetYaxis()->SetTitle("[ADC channel]");
    gr1->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit1 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr1->Fit(linearfit1,"NR","x",0,2500);
    linearfit1->Draw("same");


    //############################################################################
    c1 ->cd(3);

    blub->Draw();

    TGraph* gr2 = new TGraph(n,ch2,volts);
    //gr->SetTitle("Plateaukurve");
    gr2->SetMarkerColor(2);
    gr2->SetMarkerStyle(21);
    gr2->GetXaxis()->SetTitle("Spannung [V]");
    gr2->GetYaxis()->SetTitle("[ADC channel]");
    gr2->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit2 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr2->Fit(linearfit2,"NR","x",0,2500);
    linearfit2->Draw("same");


    //############################################################################
    c1 ->cd(4);

    blub->Draw();

    TGraph* gr3 = new TGraph(n,ch3,volts);
    //gr->SetTitle("Plateaukurve");
    gr3->SetMarkerColor(2);
    gr3->SetMarkerStyle(21);
    gr3->GetXaxis()->SetTitle("Spannung [V]");
    gr3->GetYaxis()->SetTitle("[ADC channel]");
    gr3->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit3 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr3->Fit(linearfit3,"NR","x",0,2500);
    linearfit3->Draw("same");


    //############################################################################
    c1 ->cd(5);

    blub->Draw();

    TGraph* gr4 = new TGraph(n,ch4,volts);
    //gr->SetTitle("Plateaukurve");
    gr4->SetMarkerColor(2);
    gr4->SetMarkerStyle(21);
    gr4->GetXaxis()->SetTitle("Spannung [V]");
    gr4->GetYaxis()->SetTitle("[ADC channel]");
    gr4->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit4 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr4->Fit(linearfit4,"NR","x",0,2500);
    linearfit4->Draw("same");


    //############################################################################
    c1 ->cd(6);

    blub->Draw();

    TGraph* gr5 = new TGraph(n,ch5,volts);
    //gr->SetTitle("Plateaukurve");
    gr5->SetMarkerColor(2);
    gr5->SetMarkerStyle(21);
    gr5->GetXaxis()->SetTitle("Spannung [V]");
    gr5->GetYaxis()->SetTitle("[ADC channel]");
    gr5->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit5 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr5->Fit(linearfit5,"NR","x",0,2500);
    linearfit5->Draw("same");


    //############################################################################
    c1 ->cd(7);

    blub->Draw();

    TGraph* gr6 = new TGraph(n,ch6,volts);
    //gr->SetTitle("Plateaukurve");
    gr6->SetMarkerColor(2);
    gr6->SetMarkerStyle(21);
    gr6->GetXaxis()->SetTitle("Spannung [V]");
    gr6->GetYaxis()->SetTitle("[ADC channel]");
    gr6->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit6 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr6->Fit(linearfit6,"NR","x",0,2500);
    linearfit6->Draw("same");


    //############################################################################
    c1 ->cd(8);

    blub->Draw();

    TGraph* gr7 = new TGraph(n,ch7,volts);
    //gr->SetTitle("Plateaukurve");
    gr7->SetMarkerColor(2);
    gr7->SetMarkerStyle(21);
    gr7->GetXaxis()->SetTitle("Spannung [V]");
    gr7->GetYaxis()->SetTitle("[ADC channel]");
    gr7->Draw("Psame");
    //gr0->FitLinear();

    TF1* linearfit7 = new TF1("LinearFit","[0] + [1]*x",0,2500);
    //linearfit0->SetParameter(0,0.231);
    //linearfit0->SetParameter(1,1620);
    //linearfit0->SetParameter(2,31.7);
    gr7->Fit(linearfit7,"NR","x",0,2500);
    linearfit7->Draw("same");



}
