42 class FitEditorUnitTesting
56 class InvalidPointer:
public std::exception
61 InvalidPointer(
const char*
exp): _exp(exp) {};
62 const char*
what() {
return _exp; };
66 FitEditorUnitTesting() {
68 old_stdout = dup (fileno (stdout));
69 (
void) freopen (
"outputUnitTesting.txt",
"w", stdout);
70 out = fdopen (old_stdout,
"w");
73 gROOT->ProcessLine(
".x $ROOTSYS/tutorials/fit/FittingDemo.C+");
76 TCanvas* c1 =
static_cast<TCanvas*
>(
gROOT->FindObject(
"c1") );
77 TH1* h =
static_cast<TH1*
> (
gROOT->FindObject(
"histo") );
82 throw InvalidPointer(
"In FitEditorUnitTesting constructor");
91 ~FitEditorUnitTesting() {
103 template <
typename T>
104 int MakeTest(
const char* str,
T func )
106 fprintf(stdout,
"\n***** %s *****\n", str);
107 int status = (this->*
func)();
109 fprintf(stdout,
"%s..........", str);
110 fprintf(
out,
"%s..........", str);
112 fprintf(stdout,
"OK\n");
113 fprintf(
out,
"OK\n");
116 fprintf(stdout,
"FAILED\n");
117 fprintf(
out,
"FAILED\n");
128 fprintf(
out,
"\n**STARTING TFitEditor Unit Tests**\n\n");
130 result += MakeTest(
"TestHistogramFit...", &FitEditorUnitTesting::TestHistogramFit);
132 result += MakeTest(
"TestGSLFit.........", &FitEditorUnitTesting::TestGSLFit);
134 result += MakeTest(
"TestUpdate.........", &FitEditorUnitTesting::TestUpdate);
136 result += MakeTest(
"TestGraph..........", &FitEditorUnitTesting::TestGraph);
138 result += MakeTest(
"TestGraphError.....", &FitEditorUnitTesting::TestGraphError);
140 result += MakeTest(
"TestGraph2D........", &FitEditorUnitTesting::TestGraph2D);
142 result += MakeTest(
"TestGraph2DError...", &FitEditorUnitTesting::TestGraph2DError);
144 result += MakeTest(
"TestUpdateTree.....", &FitEditorUnitTesting::TestUpdateTree);
146 result += MakeTest(
"TestTree1D.........", &FitEditorUnitTesting::TestTree1D);
148 result += MakeTest(
"TestTree2D.........", &FitEditorUnitTesting::TestTree2D);
150 result += MakeTest(
"TestTreeND.........", &FitEditorUnitTesting::TestTreeND);
152 fprintf(
out,
"\nRemember to also check outputUnitTesting.txt for "
153 "more detailed information\n\n");
163 static int counter = 0;
164 fprintf(
out,
"Printing the Func Pars (%d)\n", ++counter);
165 for (
unsigned int i = 0; i <
f->fFuncPars.size(); ++i ) {
166 fprintf(
out,
"%30.20f %30.20f %30.20f\n",
f->fFuncPars[i][0],
f->fFuncPars[i][1],
f->fFuncPars[i][2]);
174 int CompareFuncPars(std::vector<TFitEditor::FuncParamData_t>& pars)
177 for (
unsigned int i = 0; i <
f->fFuncPars.size(); ++i ) {
178 for (
unsigned int j = 0; j < 3; ++j) {
179 int internalStatus =
equals(pars[i][j],
f->fFuncPars[i][j]);
181 status += internalStatus;
192 int TestHistogramFit() {
197 std::vector<TFitEditor::FuncParamData_t> pars(6);
198 pars[0][0] = -0.86471376634076801970; pars[0][1] = pars[0][2] = 0.0;
199 pars[1][0] = 45.84337697060870908672; pars[1][1] = pars[1][2] = 0.0;
200 pars[2][0] = -13.32141783912906873866; pars[2][1] = pars[2][2] = 0.0;
201 pars[3][0] = 13.80743352672578438955; pars[3][1] = pars[3][2] = 0.0;
202 pars[4][0] = 0.17230936727526752206; pars[4][1] = pars[4][2] = 0.0;
203 pars[5][0] = 0.98728095791845293938; pars[5][1] = pars[5][2] = 0.0;
205 return CompareFuncPars(pars);
210 f->fLibGSL->Toggled(
kTRUE);
214 std::vector<TFitEditor::FuncParamData_t> pars(6);
215 pars[0][0] = -0.86471376626133966692; pars[0][1] = pars[0][2] = 0.0;
216 pars[1][0] = 45.84337697042452219875; pars[1][1] = pars[1][2] = 0.0;
217 pars[2][0] = -13.32141783972060622432; pars[2][1] = pars[2][2] = 0.0;
218 pars[3][0] = 13.80743352667312962012; pars[3][1] = pars[3][2] = 0.0;
219 pars[4][0] = 0.17230936776683797307; pars[4][1] = pars[4][2] = 0.0;
220 pars[5][0] = 0.98728095212777022827; pars[5][1] = pars[5][2] = 0.0;
222 return CompareFuncPars(pars);
226 gROOT->ProcessLine(
".x $ROOTSYS/tutorials/fit/ConfidenceIntervals.C+");
235 f->fLibMinuit2->Toggled(
kTRUE);
242 std::vector<TFitEditor::FuncParamData_t> pars(2);
243 pars[0][0] = -1.07569876898511784802; pars[0][1] = pars[0][2] = 0.0;
244 pars[1][0] = 1.83337233651544084800; pars[1][1] = pars[1][2] = 0.0;
246 return CompareFuncPars(pars);
249 int TestGraphError() {
252 f->fLibMinuit2->Toggled(
kTRUE);
259 std::vector<TFitEditor::FuncParamData_t> pars(2);
260 pars[0][0] = -1.07569876898508010044; pars[0][1] = pars[0][2] = 0.0;
261 pars[1][0] = 1.83337233651530895351; pars[1][1] = pars[1][2] = 0.0;
263 return CompareFuncPars(pars);
269 f->fLibMinuit2->Toggled(
kTRUE);
278 f->fFuncPars[0][0] = 0.5;
279 f->fFuncPars[1][0] = 1.5;
283 std::vector<TFitEditor::FuncParamData_t> pars(2);
284 pars[0][0] = 0.57910401391086918643; pars[0][1] = pars[0][2] = 0.0;
285 pars[1][0] = 1.73731204173242681499; pars[1][1] = pars[1][2] = 0.0;
287 return CompareFuncPars(pars);
290 int TestGraph2DError() {
293 f->fLibMinuit2->Toggled(
kTRUE);
302 f->fFuncPars[0][0] = 0.5;
303 f->fFuncPars[1][0] = 1.5;
307 std::vector<TFitEditor::FuncParamData_t> pars(2);
308 pars[0][0] = 0.57911670684083915717; pars[0][1] = pars[0][2] = 0.0;
309 pars[1][0] = 1.73735012087486695442; pars[1][1] = pars[1][2] = 0.0;
311 return CompareFuncPars(pars);
314 int TestUpdateTree() {
315 gROOT->ProcessLine(
".x ~/tmp/fitpanel/createTree.C++");
323 throw InvalidPointer(
"In TestUpdateTree");
327 f->ProcessTreeInput(objSelected, selected,
"x",
"y>1");
331 f->fFuncPars.resize(3);
332 f->fFuncPars[0][0] =
f->fFuncPars[0][1] =
f->fFuncPars[0][2] = 1;
333 f->fFuncPars[1][0] = 0;
334 f->fFuncPars[2][0] = 1;
338 std::vector<TFitEditor::FuncParamData_t> pars(3);
339 pars[0][0] = 1.0; pars[0][1] = pars[0][2] = 1.0;
340 pars[1][0] = 0.57616222565122654498; pars[1][1] = pars[1][2] = 0.0;
341 pars[2][0] = 0.90739764318839521984; pars[2][1] = pars[2][2] = 0.0;
343 return CompareFuncPars(pars);
349 throw InvalidPointer(
"In TestUpdateTree");
353 f->ProcessTreeInput(objSelected, selected,
"x:y",
"");
357 f->fFuncPars[0][0] = 1;
f->fFuncPars[0][1] =
f->fFuncPars[0][2] = 0;
358 f->fFuncPars[1][0] = 1;
f->fFuncPars[1][1] =
f->fFuncPars[1][2] = 0;
359 f->fFuncPars[2][0] = 0;
f->fFuncPars[2][1] =
f->fFuncPars[2][2] = 0;
363 std::vector<TFitEditor::FuncParamData_t> pars(3);
364 pars[0][0] = 1.01009862846512765699; pars[0][1] = pars[0][2] = 0.0;
365 pars[1][0] = 2.00223267618221001385; pars[1][1] = pars[1][2] = 0.0;
366 pars[2][0] = 0.49143171847344568892; pars[2][1] = pars[2][2] = 0.0;
368 return CompareFuncPars(pars);
374 throw InvalidPointer(
"In TestUpdateTree");
378 f->ProcessTreeInput(objSelected, selected,
"x:y:z:u:v:w",
"");
382 f->fFuncPars[ 0][0] = 1.0;
f->fFuncPars[ 0][1] =
f->fFuncPars[ 0][2] = 0;
383 f->fFuncPars[ 1][0] = 1.0;
f->fFuncPars[ 1][1] =
f->fFuncPars[ 1][2] = 0;
384 f->fFuncPars[ 2][0] = 0.1;
f->fFuncPars[ 2][1] =
f->fFuncPars[ 2][2] = 0;
385 f->fFuncPars[ 3][0] = 0.0;
f->fFuncPars[ 3][1] =
f->fFuncPars[ 3][2] = 0;
386 f->fFuncPars[ 4][0] = 2.0;
f->fFuncPars[ 4][1] =
f->fFuncPars[ 4][2] = 0;
387 f->fFuncPars[ 5][0] = 0.0;
f->fFuncPars[ 5][1] =
f->fFuncPars[ 5][2] = 0;
388 f->fFuncPars[ 6][0] = 3.0;
f->fFuncPars[ 6][1] =
f->fFuncPars[ 6][2] = 0;
389 f->fFuncPars[ 7][0] = 0.0;
f->fFuncPars[ 7][1] =
f->fFuncPars[ 7][2] = 0;
390 f->fFuncPars[ 8][0] = 4.0;
f->fFuncPars[ 8][1] =
f->fFuncPars[ 8][2] = 0;
391 f->fFuncPars[ 9][0] = 0.0;
f->fFuncPars[ 9][1] =
f->fFuncPars[ 9][2] = 0;
392 f->fFuncPars[10][0] = 9.0;
f->fFuncPars[10][1] =
f->fFuncPars[10][2] = 0;
396 std::vector<TFitEditor::FuncParamData_t> pars(11);
397 pars[ 0][0] = 1.01010130092504835098; pars[ 0][1] = pars[ 0][2] = 0;
398 pars[ 1][0] = 2.00223693541403102714; pars[ 1][1] = pars[ 1][2] = 0;
399 pars[ 2][0] = 0.49142981449519324011; pars[ 2][1] = pars[ 2][2] = 0;
400 pars[ 3][0] = 0.03058404503876750724; pars[ 3][1] = pars[ 3][2] = 0;
401 pars[ 4][0] = 2.98217423626109168211; pars[ 4][1] = pars[ 4][2] = 0;
402 pars[ 5][0] = 0.08458881936812148727; pars[ 5][1] = pars[ 5][2] = 0;
403 pars[ 6][0] = 3.97659923278031923743; pars[ 6][1] = pars[ 6][2] = 0;
404 pars[ 7][0] = -0.03584554242634782617; pars[ 7][1] = pars[ 7][2] = 0;
405 pars[ 8][0] = 4.96478032328273499729; pars[ 8][1] = pars[ 8][2] = 0;
406 pars[ 9][0] = 0.89557700499129078153; pars[ 9][1] = pars[ 9][2] = 0;
407 pars[10][0] = 9.92938972972320499366; pars[10][1] = pars[10][2] = 0;
410 return CompareFuncPars(pars);
419 FitEditorUnitTesting fUT;
421 return fUT.UnitTesting();
426 int main(
int argc,
char** argv)
int SelectEntry(TGComboBox *cb, const char *name)
static TFitEditor * GetInstance(TVirtualPad *pad=0, TObject *obj=0)
int equals(Double_t n1, Double_t n2, double ERRORLIMIT=1.E-10)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
R__EXTERN TApplication * gApplication
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
double func(double *x, double *p)
Mother of all ROOT objects.
typedef void((*Func_t)())
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
int main(int argc, char **argv)