Hello,
I try to read a histogram from a ROOT-File, which I plot and further would
like to fit with a self-defined function. I attached this small macro,
since after successfully fitting (the fitting parameters are printed
onto the console) it crashes due to a Segmentation Violation.
However, I have observed, if I do the following steps, I do not have any
problems:
If I comment the last line, where the fit is performed:
// hLandauPart->Fit("myfunc","R");
and run the
program, which simply plots the histogram and then RERUN the macro, this
time with the last line uncommented, then I succeed to also fit the
histogram.
So, what can I do in order to run the macro only once?
Thank you in advance,
Hermine
Double_t myfunction(Double_t *x, Double_t *par)
{
Double_t fval = par[0]*TMath::Gaus( *x, par[1], par[2] )
+ par[3]*TMath::Landau( *x, par[4], par[5] );
return fval;
}
void tryFit() {
TF1 *f1 = new TF1("myfunc",myfunction,5.5,50,6);
// f1->SetParameters(6000,6,0.5,2500,5,1);
f1->SetParameters(30000,2,1,2500,5,1);
TFile *fPart = new TFile("landauPeak570.ROOT", "READ");
TH1F *hLandauPart = (TH1F*) fPart->Get("landauDir/hLandau");
TCanvas *c = new TCanvas();
hLandauPart->DrawCopy();
hLandauPart->Fit("myfunc","R");
}
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:44 MET