00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <cassert>
00011
00012 #include "RConfig.h"
00013 #include "TChi2ExtendedFitData.h"
00014
00015 #include "TVirtualFitter.h"
00016
00017
00018 #include <iostream>
00019
00020 #include "TGraph.h"
00021 #include "TF1.h"
00022
00023
00024
00025 TChi2ExtendedFitData::TChi2ExtendedFitData(const TVirtualFitter & fitter ) {
00026
00027 fSize = 0;
00028
00029 TF1 * func = dynamic_cast<TF1 *> ( fitter.GetUserFunc() );
00030 assert( func != 0);
00031
00032 TObject * obj = fitter.GetObjectFit();
00033
00034
00035 TGraph * graph = dynamic_cast<TGraph*> ( obj );
00036 if (graph) {
00037 GetExtendedFitData(graph, func, &fitter);
00038 }
00039 else {
00040 std::cout << "other fit on different object than TGraf not yet supported- assert" << std::endl;
00041 assert(graph != 0);
00042 }
00043 }
00044
00045
00046
00047 void TChi2ExtendedFitData::GetExtendedFitData(const TGraph * gr, const TF1 * func, const TVirtualFitter * ) {
00048
00049
00050
00051
00052
00053 int nPoints = gr->GetN();
00054 double *gx = gr->GetX();
00055 double *gy = gr->GetY();
00056
00057
00058
00059
00060
00061 CoordData x = CoordData( 1 );
00062
00063
00064
00065
00066 for (int i = 0; i < nPoints; ++i) {
00067
00068 x[0] = gx[i];
00069 if (func->IsInside(&x.front() ) )
00070 SetDataPoint( x, gy[i], gr->GetErrorY(i), gr->GetErrorXlow(i), gr->GetErrorXhigh(i) );
00071
00072 }
00073 }
00074
00075
00076 void TChi2ExtendedFitData::SetDataPoint( const CoordData & x, double y, double ey, double exl, double exh) {
00077
00078
00079 fCoordinates.push_back(x);
00080 fValues.push_back(y);
00081 fErrorsY.push_back(ey);
00082 fErrorsXLow.push_back(exl);
00083 fErrorsXUp.push_back(exh);
00084 fSize++;
00085 }