Changeset 14181 for fact


Ignore:
Timestamp:
06/15/12 14:59:24 (12 years ago)
Author:
Jens Buss
Message:
fitt to sum spectrum added
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/marsmacros/singlepe.C

    r14176 r14181  
    593593    func.SetLineColor(kBlue);
    594594
     595    // define fit function for Amplitudespectrum
     596    TF1 func2("sum_spektrum", fcn, 0, 2000, 5);
     597    func2.SetParNames("Maximum", "Gain", "Sigma", "XtalkProb", "Offset");
     598    func2.SetLineColor(kBlue);
     599
     600    // define fit function for Amplitudespectrum
     601    TF1 func3("gain_sum_spektrum", fcn, 0, 10, 5);
     602    func3.SetParNames("Maximum", "Gain", "Sigma", "XtalkProb", "Offset");
     603    func3.SetLineColor(kBlue);
     604
     605
     606
    595607    // Map for which pixel shall be plotted and which not
    596608    TArrayC usePixel(1440);
     
    695707            hist->SetName(Form("Pix%d", pixel));
    696708            hist->DrawCopy()->SetDirectory(0);
    697             //func.DrawCopy("same");
    698         }
     709            func.DrawCopy("SAME");
     710        }
     711
     712
    699713
    700714        count_ok++;
     
    702716        delete hist;
    703717    }
     718
     719    //------------------fill histograms-----------------------
    704720
    705721    hcam.SetUsed(usePixel);
     
    710726    hcam.DrawCopy();
    711727
     728    gROOT->SetSelectedPad(0);
    712729    TCanvas &c11 = d->AddTab("SumHist");
    713730    gPad->SetLogy();
    714731    hSum1.DrawCopy();
    715732
     733    //------------------------fit sum spectrum-------------------------------
     734    const Int_t    maxbin   = hSum1.GetMaximumBin();
     735    const Double_t binwidth = hSum1.GetBinWidth(maxbin);
     736    const Double_t ampl     = hSum1.GetBinContent(maxbin);
     737
     738
     739    double fwhm2 = 0;
     740    for (int i=1; i<maxbin; i++)
     741        if (hSum1.GetBinContent(maxbin-i)+hSum1.GetBinContent(maxbin+i)<ampl*2)
     742        {
     743            fwhm2 = (2*i+1)*binwidth;
     744            break;
     745        }
     746
     747    if (fwhm2==0)
     748    {
     749        cout << "Could not determine start value for sigma." << endl;
     750    }
     751
     752
     753    Double_t par[5] =
     754    {
     755        ampl, hSum1.GetBinCenter(maxbin), fwhm2*1.4, 0.1, -10
     756    };
     757
     758    func2.SetParameters(par);
     759
     760    const double min = par[1]-fwhm2*1.4;
     761    const double max = par[1]*5;
     762
     763    hSum1.Fit(&func2, "NOQS", "", min, max);
     764    func2.DrawCopy("SAME");
     765    //-------------------END OF: fit sum spectrum-----------------------------
     766
     767
    716768    TCanvas &c12 = d->AddTab("GainHist");
    717769    gPad->SetLogy();
    718770    hSum2.DrawCopy();
     771    const Double_t fMaxPos  = hSum2.GetBinCenter(maxbin);
     772
     773    //------------------fit gausses to peaks -----------------------
     774
     775    UInt_t nfunc = 5;
     776    TF1 **gaus = new TF1*[nfunc];
     777
     778    for (UInt_t nr = 0; nr<nfunc; nr++)
     779    {
     780      char fname[20];
     781      sprintf(fname,"gaus%d",nr);
     782      gaus[nr] = new TF1(fname,"gaus",  fMaxPos*(nr+1)-0.6, fMaxPos*(nr+1)+0.6);
     783        hSum2.Fit(gaus[nr], "N0QS", "", fMaxPos*(nr+1)-0.6, fMaxPos*(nr+1)+0.6);
     784        gaus[nr]->DrawCopy("SAME");
     785//        delete gaus[nr];
     786    }
     787
     788
     789    //------------------fit gain corrected sum spectrum-----------------------
     790
     791    const Int_t    maxbin2   = hSum2.GetMaximumBin();
     792    const Double_t binwidth2 = hSum2.GetBinWidth(maxbin);
     793    const Double_t ampl2     = hSum2.GetBinContent(maxbin);
     794    cout << "AMPL: " << ampl2 << endl;
     795
     796    fwhm2 = 0;
     797    for (int i=1; i<maxbin; i++)
     798        if (hSum2.GetBinContent(maxbin2-i)+hSum2.GetBinContent(maxbin2+i)<ampl2*2)
     799        {
     800            fwhm2 = (2*i+1)*binwidth2;
     801            break;
     802        }
     803
     804    if (fwhm2==0)
     805    {
     806        cout << "Could not determine start value for sigma." << endl;
     807    }
     808
     809
     810    Double_t par2[5] =
     811    {
     812        ampl2, hSum2.GetBinCenter(maxbin2), fwhm2*1.4, 0.1, 0
     813    };
     814
     815        cout << "AMPL: " << ampl2 << endl;
     816            cout << "maxpos: " << hSum2.GetBinCenter(maxbin2) << endl;
     817                cout << "fwhm: " << fwhm2*1.4 << endl;
     818
     819    func3.SetParameters(par2);
     820
     821    const double min2 = par2[1]-fwhm2*1.4;
     822    const double max2 = par2[1]*5;
     823
     824    hSum2.Fit(&func3, "N0QS", "", min2, max2);
     825    func3.DrawCopy("SAME");
     826    //-------------------END OF: fit sum spectrum-----------------------------
    719827
    720828    TCanvas &c2 = d->AddTab("Result");
     
    765873
    766874    Double_t y = 0;
    767     for (int order = 1; order < 5; order++)
     875    for (int order = 1; order < 14; order++)
    768876    {
    769877        Double_t arg   = (x - order*gain - shift)/sigma;
Note: See TracChangeset for help on using the changeset viewer.