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