#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TRandom3.h" #include "JGeometry3D/JAxis3D.hh" #include "JFit/JPoint3D.hh" #include "JFit/JPoint3DEstimator.hh" #include "JROOT/JRootToolkit.hh" #include "JTools/JQuantile.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JPrint.hh" /** * \file * * Test program for JFIT::JEstimator fit. * \author mdejong */ int main(int argc, char**argv) { using namespace std; using namespace JPP; string outputFile; int numberOfEvents; int numberOfAxes; double sigma; double precision; int debug; try { JParser<> zap("Test program for position fit."); zap['o'] = make_field(outputFile) = ""; zap['n'] = make_field(numberOfEvents) = 1000; zap['N'] = make_field(numberOfAxes) = 3; zap['s'] = make_field(sigma) = 1.0e-4; zap['e'] = make_field(precision) = 1.0e-3; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } TH1D hx("hx", NULL, 101, -1.0, +1.0); TH1D hy("hy", NULL, 101, -1.0, +1.0); TH1D hz("hz", NULL, 101, -1.0, +1.0); JQuantile Qx("x"); JQuantile Qy("y"); JQuantile Qz("z"); for (int i = 0; i != numberOfEvents; ++i) { const JVector3D vertex(0.0, 0.0, 0.0); // generate axes vector detector; for (int j = 0; j != numberOfAxes; ++j) { const double x = gRandom->Gaus(0.0, sigma); const double y = gRandom->Gaus(0.0, sigma); const double z = gRandom->Gaus(0.0, sigma); const double dx = gRandom->Uniform(-1, +1); const double dy = gRandom->Uniform(-1, +1); const double dz = gRandom->Uniform(-1, +1); detector.push_back(JAxis3D(vertex + JVector3D(x,y,z), JVersor3D(dx,dy,dz))); } // fit JEstimator result(detector.begin(), detector.end()); hx.Fill(vertex.getX() - result.getX()); hy.Fill(vertex.getY() - result.getY()); hz.Fill(vertex.getZ() - result.getZ()); Qx.put(vertex.getX() - result.getX()); Qy.put(vertex.getY() - result.getY()); Qz.put(vertex.getZ() - result.getZ()); } if (debug >= debug_t) { Qx.print(cout); Qy.print(cout); Qz.print(cout); } if (outputFile != "") { TFile out(outputFile.c_str(), "recreate"); out << hx << hy << hz; out.Write(); out.Close(); } ASSERT(numberOfEvents > 0); ASSERT(fabs(Qx.getMean()) <= precision); ASSERT(fabs(Qy.getMean()) <= precision); ASSERT(fabs(Qz.getMean()) <= precision); ASSERT(Qx.getSTDev() <= precision); ASSERT(Qy.getSTDev() <= precision); ASSERT(Qz.getSTDev() <= precision); return 0; }