#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TRandom3.h" #include "JGeometry3D/JCylinder3D.hh" #include "JGeometry3D/JGeometry3DTestkit.hh" #include "JFit/JLine1Z.hh" #include "JFit/JLine1ZEstimator.hh" #include "JROOT/JRootToolkit.hh" #include "JTools/JQuantile.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.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; int numberOfPMTs; 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['N'] = make_field(numberOfPMTs) = 10; 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 ht("ht", NULL, 101, -1.0, +1.0); JQuantile Qx("x"); JQuantile Qy("y"); 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 { const JCylinder3D cylinder(JCircle2D(JVector2D(0.0, 0.0), 100.0), -50.0, +50.0); for (int i = 0; i != numberOfPMTs; ++i) { detector.push_back(getRandomPosition(cylinder)); } } 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 line const double x = 0.0 + gRandom->Uniform(xmin, xmax); const double y = 0.0 + gRandom->Uniform(xmin, xmax); const double z = 0.0; const double t = 0.0 + gRandom->Uniform(tmin, tmax); JLine1Z line(JVector3D(x,y,z), t); DEBUG("line " << FIXED(12,5) << line.getX() << ' ' << FIXED(12,5) << line.getY() << ' ' << FIXED(12,5) << line.getZ() << ' ' << FIXED(12,5) << line.getT() << endl); // generate hits vector data; for (JDetector_t::const_iterator pos = detector.begin(); pos != detector.end(); ++pos) { data.push_back(JHit_t(*pos, line.getT(*pos))); } for (vector::const_iterator hit = data.begin(); hit != data.end(); ++hit) { DEBUG("hit " << FIXED(12,5) << hit->getX() << ' ' << FIXED(12,5) << hit->getY() << ' ' << FIXED(12,5) << hit->getZ() << ' ' << FIXED(12,5) << hit->getT() << endl); } // fit JEstimator result(data.begin(), data.end()); result.setZ(line.getZ(), getSpeedOfLight()); DEBUG("result " << FIXED(12,5) << result.getX() << ' ' << FIXED(12,5) << result.getY() << ' ' << FIXED(12,5) << result.getZ() << ' ' << FIXED(12,5) << result.getT() << endl); hx.Fill(line.getX() - result.getX()); hy.Fill(line.getY() - result.getY()); ht.Fill(line.getT() - result.getT()); Qx.put(line.getX() - result.getX()); Qy.put(line.getY() - result.getY()); Qt.put(line.getT() - result.getT()); } if (debug >= debug_t) { Qx.print(cout); Qy.print(cout); Qt.print(cout); } if (outputFile != "") { TFile out(outputFile.c_str(), "recreate"); out << hx << hy << ht; out.Write(); out.Close(); } ASSERT(numberOfEvents > 0); ASSERT(fabs(Qx.getMean()) <= precision); ASSERT(fabs(Qy.getMean()) <= precision); ASSERT(fabs(Qt.getMean()) <= precision); ASSERT(Qx.getSTDev() <= precision); ASSERT(Qy.getSTDev() <= precision); ASSERT(Qt.getSTDev() <= precision); return 0; }