Re: [ROOT] Pb with Fits

From: Stephen Bailey (bailey@SLAC.stanford.edu)
Date: Fri Jun 01 2001 - 20:33:13 MEST


Hi.  I had a similar problem last year, wanting to do a fit
within a fit.  Rene posted a suggested solution.  See
"fit within a fit trouble", 22-23 Mar 2000 in the roottalk
digest.

Stephen

On Fri, 1 Jun 2001, Rene Brun wrote:

> Hi Olivier,
>
> In April, I answered a similar question from Pascal Perrodo.
> This was my answer;
> "Currently, TH1 or TGraph::Fit cannot make nested fits.
> All TH1 or TGraph objects share the same fitter. Support for nested fits
> would require each object having its own fitter.
> I would not like to implement this by default because fitters are quite
> fat objects, but it could be an option for cases like yours.
> "
> I see that I have to put a higher priority to this problem.
> Note that you can already do it by making two instances of TFitter.
> The only problem is that you have to save the gMinuit pointer before
> setting the new Fitter and then restore it in the loop.
> Contact me if you do not manage to implement it yourself.
> I cannot work on this problem until end of June.
>
> Rene Brun
>
> On Fri, 1 Jun 2001, Olivier Meplan wrote:
>
> >  Hello Rooters,
> > I have a problem with fits....
> > The goal is to fit the histogram MyHisto, which contains -1/(x+10)^2
> >   between 0 and 100, by the function MyFunction.
> >
> >   Unfortunately, MyFunction uses fits itself, as a way to compute the
> >   derivative of 1/(x+p), in this example.
> >
> >   It seems that the fits performed inside MyFunctions affects the
> >   variables used to perform the main fit, causing a segmentation
> >   fault.
> >
> >   How is it possible to use separate places in memory for those
> >   separate fits ?
> > Thanks
> > Olivier Meplan
> > -----------------------------here is an example ----------
> >
> >
> > #include <TROOT.h>
> > #include <TApplication.h>
> > #include <TCanvas.h>
> > #include <TF1.h>
> > #include <TH1.h>
> >
> > Double_t MyFunction(Double_t *x, Double_t *par) {
> >
> >   TH1D TempHisto("TempHisto","",100,0,100);
> >   for (Int_t i=1;i<=TempHisto.GetNbinsX();i++)
> >     TempHisto.SetBinContent(i,1.0/(i+par[0]));
> >
> >   TF1 PolF1("MyPol","pol1");
> >   TempHisto.Fit(&PolF1,"QN",0,x[0]-5.,x[0]+5.);
> >
> >   return PolF1.GetParameter(1);
> >
> > }
> >
> > int main(int argc,char **argv) {
> >
> >   TROOT MyRoot("MyRoot","");
> >   TApplication MyApp("MyApp", &argc, argv);
> >
> >   TH1D MyHisto("MyHisto","",100,0,100);
> >
> >   for (Int_t i=1;i<=MyHisto.GetNbinsX();i++)
> >     MyHisto.SetBinContent(i,-1.0/(i+10.0)/(i+10.0));
> >
> >   TF1 *MyF1=new TF1("MyFunc",MyFunction,20,80,1);
> >   MyF1->SetParameter(0,15);
> >
> >   TCanvas MyCanvas("MyCanvas","");
> >   MyCanvas.cd();
> >   MyHisto.Draw();
> >   MyHisto.Fit(MyF1,"R");
> >
> >   MyCanvas.Update();
> >
> >   MyApp.Run();
> >
> > }
> >
> >
>
>



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:47 MET