Re: errors while fitting

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Mar 08 2000 - 09:47:08 MET


Hi Robert,
Thanks for reporting this interesting case. If you add the statement
marked with <=== in your code below, the program will work.
In your case, your histogram already contains a function called
"massfit"
from a previous session. This function is of a different type than your
new function massfit.
I have now protected this situation in my development version.

Rene Brun

Robert Feuerbach wrote:
> 
> Hi,
> 
> I'm trying to write a function that will fit a passed through histogram,
> and so it will be called many times. In debugging and trying to find
> reason for the "*** Break *** segmentation violation" errors I'm getting,
> I now have a very simple histogram fitting routine that still isn't
> working.
> 
> I'm using ROOT 2.23/12 on a Linux Redhat5.2 dual-processor machine.
> 
> What is happening is:
> 
> root [0] TFile *hfile = new TFile("histos-oct13-mar6.root","UPDATE")
> root [1] Double_t obs,err,bck,ebck
> root [2] gDirectory->cd("masshists")
> (Bool_t)1
> root [3] .L /home/feuerbac/kaon/root/fithist-test.cc
> Which: /home/feuerbac/kaon/root/fithist-test.cc =
> /home/feuerbac/kaon/root/fithist-test.cc
> root [4] obs = massfithist(qwcL1_1_4,1,0,&err,&bck,&ebck)
>  FCN=15.5904 FROM MIGRAD    STATUS=CONVERGED      74 CALLS          75
> TOTAL
>                      EDM=7.19503e-05    STRATEGY= 1      ERROR MATRIX
> ACCURATE
>   EXT PARAMETER                                   STEP         FIRST
>   NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
>    1  Constant     2.56006e+01   5.70256e+00   5.07459e-03  -4.34415e-04
>    2  Mean         4.97567e-01   3.18574e-03   3.42157e-06   1.29586e+00
>    3  Sigma        1.56528e-02   3.12983e-03   3.94029e-05  -1.83671e-01
> 
>  *** Break *** segmentation violation
> Root > Function massfithist() busy flag cleared
> 
> .V shows that the error is happening at the first
> 
> hist->Fit("g1","",0,0.45,0.55");
> 
> What am I doing wrong?
> 
> Rob
> 
> // fit histogram with gaussian AREA, width and other parameters
> 
> Double_t SQR(Double_t x) {
>   return x*x;
> }
> 
> static Double_t mid_pnt=0.493677;
> 
> Double_t dga(Double_t *x, Double_t *param) {
>   Double_t xx=x[0];
>   Double_t pi2sqrt = TMath::Sqrt(TMath::Pi()*2.);
>   Double_t f;
>   if (param[2] != 0.)
>     f = param[0]/(param[2]*pi2sqrt)*exp(-0.5*((xx-param[1])/param[2]*(xx-param[1])/param[2]));
>   else
>     f = 0.;
>   return f;
> }
> 
> Double_t dmassfit(Double_t *x, Double_t *param) {
>   Double_t xx=x[0];
>   Double_t f = TMath::Abs(dga(x,param) + param[3] + param[4]*(xx-mid_pnt));
>   return f;
> }
> 
> Double_t massfithist(TH1D *hist, int choice, int useold, Double_t *err, Double_t *bckg, Double_t *dbckg) {
>   Text_t *FitFunc=0;
>   Text_t MassFit[] = "massfit";
> 
>   TF1 *fitfunc = 0;
> 
>   Int_t npar;
> 
>   Float_t range[2] = {0.35,0.65};
>   Double_t par[5]  = {0.,0.,0.,0.,0.};
>   Double_t epar[5] = {0.,0.,0.,0.,0.};
>   Double_t maxm;
>   Double_t xbinsize;
>   static Double_t pi2sqrt = TMath::Sqrt(2.*TMath::Pi());
> 
>   Double_t obs=0., dobs=0., bck=0., dbck=0.;
> 
>   if (!hist) return -999;
> 
>   FitFunc = MassFit;
>   fitfunc = new TF1(MassFit,dmassfit,0.35,0.65,5);
> 
>   if (!fitfunc) return -999;
> 
>   npar = fitfunc->GetNpar();  // number of parameters of function
> 
>   TF1 *g1 = new TF1("g1","gaus",0.45,0.55);
> 
>   maxm = hist->GetMaximum();
>   // seed the fit first time through
> 
    hist->GetListOfFunctions()->Delete(); //<====================
>   hist->Fit("g1","",0,0.45,0.55);       // looks like crashing here!
>   hist->Fit("g1","R0",0,0.45,0.55);
> 
>   // Clean up!
> 
>   delete g1;
>   delete fitfunc;
> 
>   return obs;
> }



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET