#include #include #include "TString.h" #include "TF1.h" #include "TF2.h" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Program to test JGizmoToolkit.hh methods. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; double precision; int debug; try { JParser<> zap("Program to test JGizmoToolkit.hh methods."); zap['e'] = make_field(precision) = 1.0e-10; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } for (TString formula : { "x", "x*x*x*x", "exp(x)" }) { TF1 fa("fa", formula); TF1 fb("fb", getLogarithmic(formula, 'x')); for (Double_t xa : { -1.0, 0.0, +1.0 }) { Double_t xb = pow(10.0, xa); Double_t ya = fa.Eval(xa); Double_t yb = fb.Eval(xb); ASSERT(fabs(ya - yb) <= precision, "Test of function " << fa.GetExpFormula() << " (" << FIXED(5,2) << xa << ")" << ' ' << fb.GetExpFormula() << " (" << FIXED(5,2) << xb << ")"); } } for (TString formula : { "x", "x*x", "exp(x)" }) { TF1 fa("fa", formula); TF1* fb = (TF1*) fa.Clone(); setLogarithmicX(fb); for (Double_t xa : { -1.0, 0.0, +1.0 }) { Double_t xb = pow(10.0, xa); Double_t ya = fa.Eval(xa); Double_t yb = fb->Eval(xb); ASSERT(fabs(ya - yb) <= precision, "Test of function " << fa .GetExpFormula() << " (" << FIXED(5,2) << xa << ")" << ' ' << fb->GetExpFormula() << " (" << FIXED(5,2) << xb << ")"); } delete fb; } for (TString formula : { "x", "y", "x*x*y*y", "exp(x)*exp(y)" }) { TF2 fa("fa", formula); TF2 fb("fb", getLogarithmic(formula, 'x')); TF2 fc("fc", getLogarithmic(formula, 'y')); for (Double_t xa : { -1.0, 0.0, +1.0 }) { for (Double_t ya : { -1.0, 0.0, +1.0 }) { Double_t xb = pow(10.0, xa); Double_t yb = pow(10.0, ya); Double_t za = fa.Eval(xa, ya); Double_t zb = fb.Eval(xb, ya); Double_t zc = fc.Eval(xa, yb); ASSERT(fabs(za - zb) <= precision, "Test of function " << fa.GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << ya << ")" << ' ' << fb.GetExpFormula() << " (" << FIXED(5,2) << xb << "," << FIXED(5,2) << ya << ")"); ASSERT(fabs(za - zc) <= precision, "Test of function " << fa.GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << ya << ")" << ' ' << fc.GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << yb << ")"); } } } for (TString formula : { "x*x*y*y", "exp(x)*exp(y)" }) { TF2 fa("fa", formula); TF2* fb = (TF2*) fa.Clone(); TF2* fc = (TF2*) fa.Clone(); setLogarithmicX(fb); setLogarithmicY(fc); for (Double_t xa : { -1.0, 0.0, +1.0 }) { for (Double_t ya : { -1.0, 0.0, +1.0 }) { Double_t xb = pow(10.0, xa); Double_t yb = pow(10.0, ya); Double_t za = fa.Eval(xa, ya); Double_t zb = fb->Eval(xb, ya); Double_t zc = fc->Eval(xa, yb); ASSERT(fabs(za - zb) <= precision, "Test of function " << fa .GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << ya << ")" << ' ' << fb->GetExpFormula() << " (" << FIXED(5,2) << xb << "," << FIXED(5,2) << ya << ")"); ASSERT(fabs(za - zc) <= precision, "Test of function " << fa .GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << ya << ")" << ' ' << fc->GetExpFormula() << " (" << FIXED(5,2) << xa << "," << FIXED(5,2) << yb << ")"); } } delete fb; delete fc; } return 0; }