#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TRandom3.h" #include "JFit/JPoint4D.hh" #include "JFit/JPoint4DEstimator.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 inputFile; string outputFile; int numberOfEvents; double precision; int debug; try { JParser<> zap("Test program for vertex fit."); zap['f'] = make_field(inputFile) = ""; zap['o'] = make_field(outputFile) = ""; zap['n'] = make_field(numberOfEvents) = 1000; zap['e'] = make_field(precision) = 1.0e-5; 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); TH1D ht("ht", NULL, 101, -1.0, +1.0); JQuantile Qx("x"); JQuantile Qy("y"); JQuantile Qz("z"); JQuantile Qt("t"); typedef vector JDetector_t; JDetector_t detector; if (inputFile != "") { ifstream in(inputFile.c_str()); for (double x, y, z; in >> x >> y >> z; ) { detector.push_back(JVector3D(x,y,z)); } in.close(); } else { for (double x = -50.0; x < 100.0; x += 100.0) { for (double y = -50.0; y < 100.0; y += 100.0) { for (double z = -50.0; z < 100.0; z += 100.0) { detector.push_back(JVector3D(x,y,z)); } } } } typedef JVertex3D JHit_t; const double xmin = -1.0; const double xmax = +1.0; const double tmin = -1.0; const double tmax = +1.0; for (int i = 0; i != numberOfEvents; ++i) { // generate point const double x = gRandom->Uniform(xmin, xmax); const double y = gRandom->Uniform(xmin, xmax); const double z = gRandom->Uniform(xmin, xmax); const double t = gRandom->Uniform(tmin, tmax); JPoint4D point(JVector3D(x,y,z), t); DEBUG("point " << FIXED(7,3) << point.getX() << ' ' << FIXED(7,3) << point.getY() << ' ' << FIXED(7,3) << point.getZ() << ' ' << FIXED(7,3) << point.getT() << endl); // generate hits vector data; for (JDetector_t::const_iterator pos = detector.begin(); pos != detector.end(); ++pos) { data.push_back(JHit_t(*pos, point.getT(*pos))); } for (vector::const_iterator hit = data.begin(); hit != data.end(); ++hit) { DEBUG("hit " << FIXED(7,3) << hit->getX() << ' ' << FIXED(7,3) << hit->getY() << ' ' << FIXED(7,3) << hit->getZ() << ' ' << FIXED(7,3) << hit->getT() << endl); } // fit JEstimator result(data.begin(), data.end()); DEBUG("result " << FIXED(7,3) << result.getX() << ' ' << FIXED(7,3) << result.getY() << ' ' << FIXED(7,3) << result.getZ() << ' ' << FIXED(7,3) << result.getT() << endl); hx.Fill(point.getX() - result.getX()); hy.Fill(point.getY() - result.getY()); hz.Fill(point.getZ() - result.getZ()); ht.Fill(point.getT() - result.getT()); Qx.put(point.getX() - result.getX()); Qy.put(point.getY() - result.getY()); Qz.put(point.getZ() - result.getZ()); Qt.put(point.getT() - result.getT()); } if (debug >= debug_t) { Qx.print(cout); Qy.print(cout); Qz.print(cout); Qt.print(cout); } if (outputFile != "") { TFile out(outputFile.c_str(), "recreate"); out << hx << hy << hz << ht; out.Write(); out.Close(); } ASSERT(numberOfEvents > 0); ASSERT(fabs(Qx.getMean()) <= precision); ASSERT(fabs(Qy.getMean()) <= precision); ASSERT(fabs(Qz.getMean()) <= precision); ASSERT(fabs(Qt.getMean()) <= precision); ASSERT(Qx.getSTDev() <= precision); ASSERT(Qy.getSTDev() <= precision); ASSERT(Qz.getSTDev() <= precision); ASSERT(Qt.getSTDev() <= precision); return 0; }