Re: [ROOT] A loop with 2 different fits = only one pass through loop

From: Rene Brun (
Date: Thu Aug 19 2004 - 23:42:23 MEST

See example of nested Fits in the macro DoubleFit.C in attachement

Rene Brun

On Thu, 
19 Aug 2004, Dr. John Krane wrote:

> Hi,
> I'm running a stand-alone program with ROOT libraries (v4.00/03) 
> compilied into it so I can use Minuit.  Because I am doing complicated 
> fits, I can't just fit a histogram, I instead do:
>   TVirtualFitter *minuit = TVirtualFitter::Fitter(0, 150);
>   minuit->SetFCN(dummy_func);   // wrapper for my full-blown fit routine
> ...etc. and all is well.  I have the command
>     minuit->ExecuteCommand("MINI",arglist,0);
> inside a loop that adds a new data point each time through.  Again, all 
> this is working just fine, but today I decided I would like to look at 
> the slope of the residuals of this fit.  So I figured I would use TH1D 
> for the residuals and the method Fit("pol1").  (Actually, I made my own 
> TF1 so I can get the slope parameter.)  So into the loop I put:
>       TF1 p1("p1","[0]+x*[1]",0.0,100.0);
>       p1.SetParameters(0.0,0.0);
>       tempbvalshist.Fit("p1");
>       slope1=p1.GetParameter(1);
> ...and this works as well...once.  When I get back up to the 
> minuit->ExecuteCommand("MINI") part, I get a terrible crash:
>  *** Break *** segmentation violation
>  Generating stack trace...
>  0x40fbe949 in TMinuit::Eval(int, double*, double&, double*, int) + 0x2b 
> from /bin/root/lib/
>  0x40fc2dfc in TMinuit::mnderi() + 0x47c from /bin/root/lib/
>  0x40fcb8f7 in TMinuit::mnmigr() + 0x20b from /bin/root/lib/
>  0x40fc45d6 in TMinuit::mnexcm(char const*, double*, int, int&) + 0x686 
> from /bin/root/lib/
>  0x40fba057 in TFitter::ExecuteCommand(char const*, double*, int) + 0x31 
> from /bin/root/lib/
>  0x080598fc in main + 0x22fa from simulate_signals
>  0x420156a4 in __libc_start_main + 0xe4 from /lib/tls/
>  0x0804ead9 in TFile::TFile[in-charge](char const*, char const*, char 
> const*, int) + 0x31 from simulate_signals
> Aborted
> Now, it seems from reading through the roottalk archives that Greg 
> Landsberg had this problem back in March 2003, running in ROOT with a 
> macro.  His solution was to save the pointer gMinuit before his second 
> fit and then restore the pointer afterward.  Because I'm running 
> stand-alone, I don't have a gMinuit, I only have my pointer to the 
> TVirtualFitter.  The roottalk archives indicate that Rene has fixed 
> things, but I'm still stuck.  I'm using version 4.00/03, which dates 
> from 10 May 2004, so I'm not sure if this is the same problem Greg had 
> after all.
> Could somebody please advise me on how to get out of this little hole 
> I'm stuck in?
>     - John

This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET