Hello,
I tried to make TMultiDimFit to work for me and got an absolutely unsuccessful experience
I.e. I read the class description and tried to play around with the example
($ROOTSYS/tutorials/multidimfit.C). I change to example to approximate a two dimensional
function f(x,y) = x*y and the class interpolates the function absolutely incorrectly. I tried to
change some algorithm parameters with no positive result.
I really want to try to use the class to develop a new tracking for my analysis
The second thing that is suspicious is that I always (even with the standard example) get
the following warnings:
Warning in <TMatrixD::Invert(Double_t *)>: Determinant under/over-flows double: det= 0.8784 2^288
Warning in TMultiDimFit::MakeCoefficientErrors: curvature matrix is singular
Here is my modified standard example:
#include "Riostream.h"
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TSystem.h"
#include "TBrowser.h"
#include "TFile.h"
#include "TRandom.h"
#include "TMultiDimFit.h"
//____________________________________________________________________
void makeData(Double_t* x, Double_t& d, Double_t& e)
{
// Make data points
Double_t upp[2] = { 10.0, 10.0 };
Double_t low[2] = { 0.0, 0.0 };
for (int i = 0; i < 2; i++)
x[i] = low[i] + (upp[i] - low[i]) * gRandom->Rndm();
d = x[0]*x[1];
//d = x[0];
//d = x[1];
//d = 3.0;
//d = x[0]+x[1];
//cout<<"x[0]="<<x[0]<<" x[1]="<<x[1]<<" d="<<d<<endl;
e = gRandom->Gaus(1.0, 1.0);
}
//____________________________________________________________________
Int_t MultDimFit()
{
cout << "*************************************************" << endl;
cout << "* Multidimensional Fit *" << endl;
cout << "* *" << endl;
cout << "* By Christian Holm <cholm@nbi.dk> 14/10/00 *" << endl;
cout << "*************************************************" << endl;
cout << endl;
// Initialize global TRasnom object.
gRandom = new TRandom();
// Open output file
TFile* output = new TFile("mdf.root", "RECREATE");
// Global data parameters
Int_t nVars = 2;
Int_t nData = 1000;
// make fit object and set parameters on it.
TMultiDimFit* fit = new TMultiDimFit(nVars, TMultiDimFit::kMonomials,"v");
Int_t mPowers[] = { 5 , 5 };
fit->SetMaxPowers(mPowers);
fit->SetMaxFunctions(1000);
fit->SetMaxStudy(1000);
fit->SetMaxTerms(1000);
fit->SetPowerLimit(1);
fit->SetMinAngle(10);
fit->SetMaxAngle(10);
fit->SetMinRelativeError(0.1);
// variables to hold the temporary input data
Double_t d;
Double_t e;
Double_t *x = new Double_t[nVars];
// Print out the start parameters
fit->Print("p");
// Create training sample
Int_t i;
for (i = 0; i < nData ; i++) {
// Make some data
makeData(x,d,e);
// Add the row to the fit object
fit->AddRow(x,d,e);
}
// Print out the statistics
fit->Print("s");
// Book histograms
fit->MakeHistograms();
// Find the parameterization
fit->FindParameterization();
// Print coefficents
fit->Print("rc");
// Get the min and max of variables from the training sample, used
// for cuts in test sample.
Double_t *xMax = new Double_t[nVars];
Double_t *xMin = new Double_t[nVars];
for (i = 0; i < nVars; i++) {
xMax[i] = (*fit->GetMaxVariables())(i);
xMin[i] = (*fit->GetMinVariables())(i);
}
nData = fit->GetNCoefficients() * 100;
Int_t j;
// Create test sample
for (i = 0; i < nData ; i++) {
// Make some data
makeData(x,d,e);
for (j = 0; j < nVars; j++)
if (x[j] < xMin[j] || x[j] > xMax[j])
break;
// If we get through the loop above, all variables are in range
if (j == nVars)
// Add the row to the fit object
fit->AddTestRow(x,d,e);
else
i--;
}
delete gRandom;
// Test the parameterizatio and coefficents using the test sample.
fit->Fit();
// Print result
fit->Print("fc");
// Write code to file
fit->MakeCode();
// Write histograms to disk, and close file
output->Write();
output->Close();
delete output;
// We're done
delete fit;
cout << "The END" << endl;
return 0;
}
Here is my drawing script:
#include "MDF.C"
/**************************************************************************/
double MDFfun(Double_t *x, Double_t *par)
{
return MDF(x);
//return x[0]*x[1];
}// end of function
/**************************************************************************/
void MultDimFitDraw(void)
{
TF2* zzz = new TF2("zzz", MDFfun, 0.0, +10.0, 0.0, 10.0, 0);
zzz->Draw("surf1");
} // end of function
/**************************************************************************/
Sincerely yours,
Sergei.