Changeset 14182 for fact/tools


Ignore:
Timestamp:
06/18/12 12:11:32 (12 years ago)
Author:
Jens Buss
Message:
add array of gaussions to fit to spectrum, calculation pulseheights in
spectrum to calculate crosstalk and underlying poisson, plot spektrum
height vs pe
File:
1 edited

Legend:

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

    r14181 r14182  
    736736    const Double_t ampl     = hSum1.GetBinContent(maxbin);
    737737
    738 
    739738    double fwhm2 = 0;
     739
     740    //Calculate full width half Maximum
    740741    for (int i=1; i<maxbin; i++)
    741742        if (hSum1.GetBinContent(maxbin-i)+hSum1.GetBinContent(maxbin+i)<ampl*2)
     
    744745            break;
    745746        }
    746 
    747747    if (fwhm2==0)
    748748    {
     
    750750    }
    751751
    752 
     752    //Set fit parameters
    753753    Double_t par[5] =
    754754    {
    755755        ampl, hSum1.GetBinCenter(maxbin), fwhm2*1.4, 0.1, -10
    756756    };
    757 
    758757    func2.SetParameters(par);
    759758
     759    //calculate fit range
    760760    const double min = par[1]-fwhm2*1.4;
    761761    const double max = par[1]*5;
    762762
     763    //Fit and draw spectrum
    763764    hSum1.Fit(&func2, "NOQS", "", min, max);
    764765    func2.DrawCopy("SAME");
     766
    765767    //-------------------END OF: fit sum spectrum-----------------------------
    766768
    767 
     769    // Draw gain corrected sum specetrum
     770    gROOT->SetSelectedPad(0);
    768771    TCanvas &c12 = d->AddTab("GainHist");
    769772    gPad->SetLogy();
     
    771774    const Double_t fMaxPos  = hSum2.GetBinCenter(maxbin);
    772775
    773     //------------------fit gausses to peaks -----------------------
    774 
    775     UInt_t nfunc = 5;
    776     TF1 **gaus = new TF1*[nfunc];
    777 
     776    //--------fit gausses to peaks of gain corrected sum specetrum -----------
     777    UInt_t nfunc    = 5;
     778
     779    // create array for gaus funtions to fit to peaks of spectrum
     780    TF1 **gaus      = new TF1*[nfunc];
     781
     782    // create histo for height of Maximum amplitudes vs. pe
     783    TH1D hMaxHeights("MaxHeights",      "peak heights",
     784                      20,  0,   20);
     785
     786    // fit gauss functions to spectrum
    778787    for (UInt_t nr = 0; nr<nfunc; nr++)
    779788    {
    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);
     789        char fname[20];
     790        sprintf(fname,"gaus%d",nr);
     791
     792        //create gauss functions
     793        gaus[nr] = new TF1( fname,"gaus",
     794                            fMaxPos*(nr+1)-0.6,     fMaxPos*(nr+1)+0.6);
     795        //fit and draw gauss functions
     796        hSum2.Fit(  gaus[nr],   "N0QS",     "",
     797                    fMaxPos*(nr+1)-0.6,     fMaxPos*(nr+1)+0.6);
    784798        gaus[nr]->DrawCopy("SAME");
    785 //        delete gaus[nr];
    786     }
    787 
     799
     800        //fill histo for height of Maximum amplitudes vs. pe
     801        hMaxHeights.SetBinContent(nr, gaus[nr]->GetParameter(0));
     802        delete gaus[nr];
     803    }
     804    delete[] gaus;
    788805
    789806    //------------------fit gain corrected sum spectrum-----------------------
     
    792809    const Double_t binwidth2 = hSum2.GetBinWidth(maxbin);
    793810    const Double_t ampl2     = hSum2.GetBinContent(maxbin);
    794     cout << "AMPL: " << ampl2 << endl;
    795 
     811
     812    //Calculate full width half Maximum
    796813    fwhm2 = 0;
    797814    for (int i=1; i<maxbin; i++)
     
    801818            break;
    802819        }
    803 
    804820    if (fwhm2==0)
    805821    {
     
    807823    }
    808824
    809 
     825    //Set fit parameters
    810826    Double_t par2[5] =
    811827    {
    812828        ampl2, hSum2.GetBinCenter(maxbin2), fwhm2*1.4, 0.1, 0
    813829    };
    814 
    815         cout << "AMPL: " << ampl2 << endl;
    816             cout << "maxpos: " << hSum2.GetBinCenter(maxbin2) << endl;
    817                 cout << "fwhm: " << fwhm2*1.4 << endl;
    818830
    819831    func3.SetParameters(par2);
     
    825837    func3.DrawCopy("SAME");
    826838    //-------------------END OF: fit sum spectrum-----------------------------
     839
     840    TCanvas &c15 = d->AddTab("PeakHeights");
     841    gPad->SetLogy();
     842    hMaxHeights.DrawCopy();
    827843
    828844    TCanvas &c2 = d->AddTab("Result");
Note: See TracChangeset for help on using the changeset viewer.