Hello,
I have a problem with FIT. I have written a very simple program
to show you my problem: I considere 3 points: (x1,y1) (x2,y2) (x3,y3),
and I fit with the 'pol1' on the interval x1 to x2 and with a other 'pol1'
on the interval x2 to x3. In fact, It is very easy to find the solution
(y=ax+b, then a=(y2-y1)/(x2-x1) and b=y2-a*x2=y1-a*x1) but Root don't
arrive to find the good solution! I don't understand why it is a problem.
It is may be a problem in my program but, if it is this case, I don't
know where!
Thank you by advance,
Franck Lavaud
NB: I use root 2.23
-----------------------------------------------------------------------
LAVAUD FRANCK
Institut de Physique Nucleaire - Bat. 102
Universite de Paris-Sud
F91406 ORSAY Cedex
Tel.: (33) 01.69.15.72.43 E-Mail: Lavaud@ipno.in2p3.fr
Lavaud@in2p3.fr
-----------------------------------------------------------------------
#include <stdlib.h>
#include <fstream.h>
#include <math.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TCanvas.h>
#include <TFile.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TH1.h>
#include <TF1.h>
#include <TF2.h>
#include <TKey.h>
#include <TLine.h>
#include <TList.h>
#include <TMath.h>
#include <TEnv.h>
ObjSuf = o
SrcSuf = cxx
ExeSuf =
DllSuf = so
EVENTLIB = $(EVENTO)
OutPutOpt = -o
ROOTCFLAGS = $(shell root-config --cflags)
ROOTLIBS = $(shell root-config --libs)
ROOTGLIBS = $(shell root-config --glibs)
# Alpha/OSF with cxx6
CXX = cxx
CXXFLAGS = -O0
LD = cxx
LDFLAGS = -g
SOFLAGS = -Wl,-expect_unresolved,* -call_shared
CXXFLAGS += $(ROOTCFLAGS)
LIBS = $(ROOTLIBS)
GLIBS = $(ROOTGLIBS)
#------------------------------------------------------------------------------
totoO = toto.$(ObjSuf)
totoS = toto.$(SrcSuf)
toto = toto$(ExeSuf)
OBJS = $(totoO)
PROGRAMS = $(toto)
all: $(PROGRAMS)
$(toto): $(totoO)
$(LD) $(LDFLAGS) $(totoO) $(GLIBS) $(OutPutOpt) $(toto)
@echo "$(toto) done"
clean:
@rm -f $(OBJS) *Dict.* core
.SUFFIXES: .$(SrcSuf)
###
.$(SrcSuf).$(ObjSuf):
$(CXX) $(CXXFLAGS) -c $<
#include "incl.incl"
TCanvas *c1;
extern void InitGui( );
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
TROOT root( "GUI", "GUI test environement", initfuncs );
int main( int argc, char **argv )
{
TApplication theApp( "App", &argc, argv );
c1 = new TCanvas( "c1", "Fenetre graphique", 564, 0, 700, 900 );
float x[3];
float y[3];
float fit_a[ 3 ][ 100 ];
x[0] = 2.000000e+00; // <- Z=2 = z_start
y[0] = 1.931110e-03;
x[1] = 3.000000e+00; // <- Z=3 = z_cut
y[1] = -7.602538e-05;
x[2] = 4.000000e+00; // <- Z=4 = zmax
y[2] = -6.408968e-05;
int z_start = 1;
int z_cut = 3;
int zmax = 4;
TGraph *graph0 = new TGraph( 3, x, y );
TF1 *g01 = new TF1( "g01", "pol1", 2., 3. );
g01 -> SetLineColor( 9 );
g01 -> SetLineStyle( 2 );
TF1 *g02 = new TF1( "g02", "pol1", 3., 4. );
g02 -> SetLineColor( 3 );
g02 -> SetLineStyle( 2 );
graph0 -> Draw( "ALP" );
graph0 -> Fit( "g01", "WQR+" );
graph0 -> Fit( "g02", "WQR+" );
for ( int k = 0; k <= 3 ; k++ )
{
if ( k <= 1 )
{
fit_a[ 0 ][ k ] = g01 -> GetParameter( k );
printf(" fit_a0( %d ) =%e \n", k, fit_a[ 0 ][ k ] );
}
else
{
fit_a[ 0 ][ k ] = g02 -> GetParameter( k-2 );
printf(" fit_a0( %d ) =%e \n", k, fit_a[ 0 ][ k ] );
}
}
c1 -> Update();
theApp.Run();
return 0;
}
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET