Re: [ROOT] How to take the diff. b/w histo contents and fit

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 20 2003 - 08:53:52 MET


Hi Kirti,

I suggest to look at the tutorial FittingDemo.C.

If you still have difficulties, send me a small tar file with the strict minimum
to reproduce the problem, with an explanation of the problem.

Rene Brun

kirti@fnal.gov wrote:
> 
> Hi!
> Thanks a lot for your help.
> I don't know why but the first option is not giving me the correct
> histogram, in fact histo h1 shows no entry at all with some strange
> looking plot. But the 2nd option (shorter  one) is working fine.
> 
> Actually I have one histogram in which I have to fit a given small range
> by linear fit (pol1). Then using its parameters p0 and p1, I have to
> extrapolate that linear fit to larger range (but still not the whole
> range).
> Next I want to take the difference between the histo content up to the
> larger ranger and the combined linear fit.
> 
> For that I am doing the following:
> //1d projection of 2d histgram with 50 bins
> 
> > TH1D *h = (TH1D*) h_ave->ProjectionY("", 29, 29);
> 
> //fitting in small range
> 
> > TF1 *pol1 = new TF1("pol1","pol1",0,h->GetBinContent(20));
> > h->Fit("pol1","R");
> 
> //getting fit parameters p0 & p1
> 
> >Double_t po1 = pol1->GetParameter(0);
> >Double_t po2 = pol1->GetParameter(1);
> 
> //define a linear function myfun with two parameters, and setting the
> two values previously obtained from pol1
> 
> >TF1 *myfun = new TF1("myfun", "[0]+[1]*x",h->GetBinContent(21),
> h->GetBinContent(bin));
> > myfun->SetParameters(po1,po2);
> > h->Fit("myfun",R+);
> // Then combining two fits into single fit
> 
> >TF1 *total = new TF1("total","pol1+myfun",0,h->GetBinContent(bin));
> >h->Fit("total","R+");
> 
> //and then the subtraction for which I am using your second option.
> >TH1F *h1 = (TH1F*)h->Clone("h1");
> > h1->Add(h->GetFunction("total"),-1);
> 
> // But then when I subtract using clone, I get the subtraction over the
> whole range which I want to be limited to  some h->GetBinContent(bin). I
> also don't know if this is the right methodology or not. I did not get
> much from the multifit tutorial also.
> Please help.
> Thanks a lot,
> kirti.
> 
> ----- Original Message -----
> From: Rene Brun <Rene.Brun@cern.ch>
> Date: Wednesday, November 19, 2003 2:36 am
> Subject: Re: [ROOT] How to take the diff. b/w histo contents and fit
> 
> > Hi Kirti,
> >
> > After the fit, ou can do something like
> >
> > TF1 *func = h->GetFunction("pol1");
> > for (int bin=1, bin<=nbins;bin++) {
> >    double x = h->GetXaxis()->GetBinCenter(bin);
> >    double fval = func->Eval(x);
> >    h1->SetBinContent(bin,h->GetBinContent(bin)-fval);
> > }
> >
> > or even simpler
> >
> > TH1F *h1 = (TH1F*)h->Clone("h1");
> > h1->Add(h->GetFunction("pol1"),-1);
> >
> > Rene Brun
> >
> >
> > kirti@fnal.gov wrote:
> > >
> > > Hi again!
> > > I have one more query:
> > >
> > > I am plotting one dim. histogram and then fit it with linear(po1)
> > fit in
> > > some specified range.
> > >
> > > >TH1D *h = (TH1D*) h_ave->ProjectionY("", 29, 29);
> > >
> > > //where h_ave is 2D histogram. There are 50 bins and the maximum
> > value> in this plot goes up to 20000.
> > >
> > > >TF1 *pol1 = new TF1("pol1","pol1",0,2000);
> > > h->Fit("pol1","R");
> > >
> > > I would now like to take the difference between the two i.e., Fit
> > and> original Histogram, and plot it.
> > >
> > > For histogram I can find the Bin Content by using:
> > > >for(bin=0; bin<50;bin++)
> > > h1->SetBinContent(1+bin,h->GetBinContent(1+bin));
> > >
> > > But I do not understand how to find the bin content for Fit and then
> > > take the differnce.
> > > Please suggest.
> > > Kirti
> > >
> > >
> > >
> >
> >



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET