26 void makeData(Double_t* x, Double_t& d, Double_t& e)
29 Double_t upp[5] = { 10, 10, 10, 10, 1 };
30 Double_t low[5] = { 0, 0, 0, 0, .1 };
31 for (
int i = 0; i < 4; i++)
32 x[i] = (upp[i] - low[i]) * gRandom->Rndm() + low[i];
34 d = x[0] * TMath::Sqrt(x[1] * x[1] + x[2] * x[2] + x[3] * x[3]);
36 e = gRandom->Gaus(upp[4],low[4]);
40 int CompareResults(TMultiDimFit *fit,
bool doFit)
46 double GoodCoeffsNoFit[] = {
71 double GoodCoeffs[] = {
120 Int_t nc = fit->GetNCoefficients();
121 Int_t nv = fit->GetNVariables();
122 const Int_t *powers = fit->GetPowers();
123 const Int_t *pindex = fit->GetPowerIndex();
124 if (nc != 21)
return 1;
125 const TVectorD *coeffs = fit->GetCoefficients();
127 for (Int_t i=0;i<nc;i++) {
129 if (!TMath::AreEqualRel((*coeffs)[i],GoodCoeffs[i],1e-3))
return 2;
132 if (TMath::Abs((*coeffs)[i] - GoodCoeffsNoFit[i]) > 5e-5)
return 2;
134 for (Int_t j=0;j<nv;j++) {
135 if (powers[pindex[i]*nv+j] != GoodPower[k])
return 3;
141 gROOT->ProcessLine(
".L MDF.C");
143 Double_t refMDF = (doFit) ? 43.95 : 43.98;
148 Long_t iret = gROOT->ProcessLine(
" Double_t xvalues[] = {5,5,5,5}; double result=MDF(xvalues); &result;");
149 Double_t rMDF = * ( (Double_t*)iret);
151 if (TMath::Abs(rMDF -refMDF) > 1e-2)
return 4;
156 Int_t multidimfit(
bool doFit =
true)
159 cout <<
"*************************************************" << endl;
160 cout <<
"* Multidimensional Fit *" << endl;
161 cout <<
"* *" << endl;
162 cout <<
"* By Christian Holm <cholm@nbi.dk> 14/10/00 *" << endl;
163 cout <<
"*************************************************" << endl;
167 gRandom =
new TRandom();
170 TFile* output =
new TFile(
"mdf.root",
"RECREATE");
178 TMultiDimFit* fit =
new TMultiDimFit(nVars, TMultiDimFit::kMonomials,
"v");
180 Int_t mPowers[] = { 6 , 6, 6, 6 };
181 fit->SetMaxPowers(mPowers);
182 fit->SetMaxFunctions(1000);
183 fit->SetMaxStudy(1000);
184 fit->SetMaxTerms(30);
185 fit->SetPowerLimit(1);
186 fit->SetMinAngle(10);
187 fit->SetMaxAngle(10);
188 fit->SetMinRelativeError(.01);
197 printf(
"======================================\n");
201 for (i = 0; i < nData ; i++) {
214 fit->MakeHistograms();
217 fit->FindParameterization();
224 Double_t *xMax =
new Double_t[nVars];
225 Double_t *xMin =
new Double_t[nVars];
226 for (i = 0; i < nVars; i++) {
227 xMax[i] = (*fit->GetMaxVariables())(i);
228 xMin[i] = (*fit->GetMinVariables())(i);
231 nData = fit->GetNCoefficients() * 100;
235 for (i = 0; i < nData ; i++) {
239 for (j = 0; j < nVars; j++)
240 if (x[j] < xMin[j] || x[j] > xMax[j])
246 fit->AddTestRow(x,d,e);
268 Int_t compare = CompareResults(fit, doFit);
270 printf(
"\nmultidimfit .............................................. OK\n");
272 printf(
"\nmultidimfit .............................................. fails case %d\n",compare);