Re: TF2 SetRange

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Tue, 23 Nov 2010 09:17:49 +0100


Hi,

 For 2D histograms you cannot set the range directly in the TH1::Fit call. This works only for 1D. For using TFitResultPtr TH1::Fit see http://root.cern.ch/root/htmldoc/TH1.html#TH1:Fit%1

 Best Regards

 Lorenzo
On Nov22, 2010, at 10:24 PM, <nguler_at_jlab.org> <nguler_at_jlab.org> wrote:

> Could you tell me how to use this pointer?
> I have TH2F object:
>    TH2F *histsim = new TH2F(histsimName,histsimName,256,0,256,256,0,256);
> and the TF2 object:
>    TF2 *fitsim2_5 = new TF2("fitsim2_5",Gaus2D,0,90,50,200,5);
>    fitsim2_5->SetParameters(200.,30.,1.,130.,1.);
> then I make the fit:
>    histsim->Fit("fitsim2_5","RN");
> 
> Do I do instead:
>    TFitResultPtr myFit(.......)
> Sorry, the usage of this function is not clear to me.
> Thanks, - Nevzat
> 
> 
>> Hello Nevzat,
>> 
>> Instead of defining your TF2 objects in that range.  Do a broader range
>> in the TF2 constructor and limit your fit when doing the Fit call.  Use
>> this member instead
>> 
>> TFitResultPtr Fit(const char* formula, Option_t* option = "", Option_t*
>> goption = "", Double_t xmin = 0, Double_t xmax = 0)
>> 
>> cheers,
>> 
>> John Idarraga
>> 
>> nguler_at_jlab.org wrote:

>>> Hello All,
>>> I have 2D histograms with various peaks in each. I perform a gaussian fit on
>>> the peaks. For the fit to be successful, I have to set x,y ranges around the
>>> peaks while defining my TF2 object. Therefore, the range of my TF2 is
>>> different than the range of my TH2F. This becomes problem later when I plot
>>> the histogram and the fit results together on the same canvas. So, I rescale
>>> the histogram by using SetRange. To be more clear, I define TH2F:
>>> TH2F *histsim = new TH2F(histsimName,histsimName,256,0,256,256,0,256);
>>> Then define TF2:
>>> TF2 *fitsim = new TF2("fitsim",Gaus2D,0,80,75,125,5);
>>> And I fit and plot:
>>> histsim->Fit("fitsim","RN");
>>> histsim->Draw("surf4");
>>> fitsim->Draw("cont1, same");
>>> But the fitsim is plotted on a different scale and does not overlap with the
>>> peak anymore even if the fit is successful. So, instead I do the following:
>>> histsim->Fit("fitsim","RN");
>>> histsim->Draw("surf4");
>>> fitsim->SetRange(0,0,256,256); //// necessary to rescale to the
>>> histogram
>>> range
>>> fitsim->Draw("cont1, same");
>>> This plots the fitsim on correct x and y positions. However, the z height of
>>> the fit is still off-scale. How can I rescale the fit height so that it is
>>> the
>>> same as the peak height? I tried following:
>>> fitsim->SetRange(0,0,0, 256,256, fitsim->GetParameter(0));
>>> But it did not have any visible effect, the z range of the fit is still very
>>> different than the z range of the histogram.
>>>
>>> I appreciate your suggestions. Thank you,
>>>
>>> - Nevzat Guler
>>>
>>>
>>>
>>>
>>>
>> 
> 
> 
> - Nevzat Guler
> (757) 553-8318
> 
Received on Tue Nov 23 2010 - 09:17:56 CET

This archive was generated by hypermail 2.2.0 : Tue Nov 23 2010 - 11:50:01 CET