Re: [ROOT] TGraph::InitGaus

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Sep 10 2002 - 17:59:40 MEST


Hi Federico,

I do not understand what you try to do by calling directly
TGraph::InitGaus. This function computes an approximation of a fit
with a gaussian on the graph points and then store the estimated values
in the current function that you fit. In your case, you did not define any
function and you will have no way to know the results.
In case you are only interested by the mean value and RMS, you can call
TGraph::GetMean, GetRMS. In case you want to store the results in a
function, you can do something like;
        n=g->GetN();
        cout << "N=" << n << endl;
        TF1 *f1 = new TF1("f1","gaus",0,1)
        g->Fit(f1,"q"); //you need to make this call once only
        g->InitGaus(0,n-1);
        //then you can access the estimated parameters via
        // f1->GetParameter(0), 1,2

Rene Brun

On Tue, 10 Sep 2002, Federico Roncarolo wrote:

> Hi,
> 
> To my understanding "first" and "last" are integers referring to the
> graph index and form the source it looks like that you put them wrong they
> are set to the first and last element of the graph.
> 
> I reduced my code to a simple example, (the input file is attached):
> 
> #include <stdlib.h>
> #include <iostream.h>
> #include <fstream.h>
> #include <TGraph.h>
> #include <TObject.h>
> #include <stdio.h>
> #include <math.h>
> #include <TROOT.h>
> #include <TCanvas.h>
> #include <TApplication.h>
> 
> int main(int argc, char **argv) {
> 
>   ifstream finput;
>   Char_t line[200];
>   Int_t i,n;
>   TGraph *g=new TGraph();
>   Double_t x,y;
>   TApplication theApp("App", &argc, argv);
> 
>   finput.open("fake.in",ios::in);
>   i=0;
>   
>   while(1) {
>    	finput.getline(line,900,'\n');
>  	if(!finput.good()) break;
>  
>   	finput >> x >> y;
>   	cout << x << " " << y << endl;
> 
>   	g->SetPoint(i++,x,y);
>   
> 
>   	}
>   	n=g->GetN();
>   	cout << "N=" << n << endl;
>   	g->InitGaus(0,n-1);
>   
>   	finput.close();
>   	g->Draw("AP");
>   	//delete g;
>   	theApp.Run();
>   }
> 
> It stops before the InitGaus, returning:
> Breakpoint 1 at 0x4082fa80
> (gdb) bt
> #0  0x4082fa80 in TGraph::InitGaus () from /vol2/root/lib/libGraf.so
> #1  0x08048ea9 in main ()
> #2  0x40cf2657 in __libc_start_main (main=0x8048ca0 <main>, argc=1, 
>     ubp_av=0xbfffdea4, init=0x8048a00 <_init>, fini=0x8049090 <_fini>, 
>     rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbfffde9c)
>     at ../sysdeps/generic/libc-start.c:129
> 
> Federico
> 
> 
> On Tue, 10 Sep 2002, Rene Brun wrote:
> 
> > My guess is that you have wrong values for the arguments first and last
> > 
> > Rene Brun
> > 
> > On Tue, 10 Sep 2002, Federico Roncarolo wrote:
> > 
> > > Hello,
> > > 
> > > I'm using version  3.03/08, RH 7.2.
> > > 
> > > I get an error while using TGraph::InitGaus,
> > > the debugger returns:
> > > 
> > > #0  0x4082fa80 in TGraph::InitGaus () from /vol2/root/lib/libGraf.so
> > > #1  0x0804b8c4 in TGaussian::EvalInPar ()
> > > #2  0x0804db44 in ws_fitlist ()
> > > #3  0x0805055a in main ()
> > > #4  0x40cf2657 in __libc_start_main (main=0x805050c <main>, argc=1,
> > > ubp_av=0xbfffe314, init=0x804aa88 <_init>, 
> > >     fini=0x8050940 <_fini>, rtld_fini=0x4000dcd4 <_dl_fini>,
> > > stack_end=0xbfffe30c)
> > >     at ../sysdeps/generic/libc-start.c:129
> > > 
> > > 
> > > 
> > > Can anybody guess the problem or do you need my complete code?
> > > 
> > > Thanks a lot,
> > > Federico
> > > 
> > 
> > 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:09 MET