#include #include #include #include "TRandom3.h" #include "JMath/JLegendre.hh" #include "JMath/JMathSupportkit.hh" #include "JFit/JLegendreEstimator.hh" #include "JTools/JCollection.hh" #include "JTools/JElement.hh" #include "JTools/JQuantile.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test Legendre polynome. * \author mdejong */ int main(int argc, char**argv) { using namespace std; using namespace JPP; const size_t N = 3; typedef JLegendre JLegendre_t; const double xmin = -10.0; const double xmax = +10.0; unsigned int numberOfEvents; unsigned int numberOfBins; JLegendre_t f1(xmin, xmax); double precision; int debug; try { JParser<> zap("Example program to test Legendre polynome."); zap['n'] = make_field(numberOfEvents) = 1000; zap['N'] = make_field(numberOfBins) = 10; zap['L'] = make_field(f1); 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); } typedef JCollection< JElement2D > collection_type; collection_type data; for (unsigned int i = 0; i != numberOfBins; ++i) { const double x = xmin + i * (xmax - xmin) / (numberOfBins - 1); data[x] = f1(x); } for (collection_type::const_iterator i = data.begin(); i != data.end(); ++i) { DEBUG("data: " << FIXED(7,3) << i->getX() << ' ' << FIXED(7,3) << i->getY() << endl); } JEstimator g1(data.begin(), data.end()); for (size_t n = 0; n != g1.size(); ++n) { STATUS("Legendre: " << setw(2) << n << ' ' << FIXED(7,3) << g1[n] << endl); } JQuantile Q; if (numberOfEvents > 0) { for (unsigned int i = 0; i != numberOfEvents; ++i) { const double x = gRandom->Uniform(xmin, xmax); const double y = f1(x); const double z = g1(x); Q.put(y - z); } DEBUG(Q << endl); } ASSERT(numberOfEvents > 0); ASSERT(f1.size() == g1.size()); for (size_t n = 0; n != g1.size(); ++n) { ASSERT(fabs(f1[n] - g1[n]) <= precision, "Legendre: " << setw(2) << n << ' ' << FIXED(7,3) << g1[n]); } ASSERT(fabs(Q.getMean()) <= precision); ASSERT(Q.getSTDev() <= precision); return 0; }