Jpp
Functions
JPoint4D.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TRandom3.h"
#include "JGeometry3D/JVertex3D.hh"
#include "JFit/JPoint4D.hh"
#include "JFit/JPoint4DEstimator.hh"
#include "JROOT/JRootToolkit.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Test program for JFIT::JEstimator<JPoint4D> fit.

Author
mdejong

Definition in file JPoint4D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JPoint4D.cc.

30 {
31  using namespace std;
32 
33  string inputFile;
34  string outputFile;
35  int numberOfEvents;
36  double precision;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Test program for vertex fit.");
42 
43  zap['f'] = make_field(inputFile) = "";
44  zap['o'] = make_field(outputFile) = "";
45  zap['n'] = make_field(numberOfEvents) = 1000;
46  zap['e'] = make_field(precision) = 1.0e-5;
47  zap['d'] = make_field(debug) = 3;
48 
49  zap(argc, argv);
50  }
51  catch(const exception& error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  using namespace JPP;
57 
58 
59  TH1D hx("hx", NULL, 101, -1.0, +1.0);
60  TH1D hy("hy", NULL, 101, -1.0, +1.0);
61  TH1D hz("hz", NULL, 101, -1.0, +1.0);
62  TH1D ht("ht", NULL, 101, -1.0, +1.0);
63 
64  JQuantile Qx("x");
65  JQuantile Qy("y");
66  JQuantile Qz("z");
67  JQuantile Qt("t");
68 
69 
70  typedef vector<JVector3D> JDetector_t;
71 
72  JDetector_t detector;
73 
74  if (inputFile != "") {
75 
76  ifstream in(inputFile.c_str());
77 
78  for (double x, y, z; in >> x >> y >> z; ) {
79  detector.push_back(JVector3D(x,y,z));
80  }
81 
82  in.close();
83 
84  } else {
85 
86  for (double x = -50.0; x < 100.0; x += 100.0) {
87  for (double y = -50.0; y < 100.0; y += 100.0) {
88  for (double z = -50.0; z < 100.0; z += 100.0) {
89  detector.push_back(JVector3D(x,y,z));
90  }
91  }
92  }
93  }
94 
95 
96  typedef JVertex3D JHit_t;
97 
98  const double xmin = -1.0;
99  const double xmax = +1.0;
100 
101  const double tmin = -1.0;
102  const double tmax = +1.0;
103 
104 
105  for (int i = 0; i != numberOfEvents; ++i) {
106 
107  // generate vertex
108 
109  const double x = gRandom->Uniform(xmin, xmax);
110  const double y = gRandom->Uniform(xmin, xmax);
111  const double z = gRandom->Uniform(xmin, xmax);
112  const double t = gRandom->Uniform(tmin, tmax);
113 
114  JVertex3D vertex(JVector3D(x,y,z), t);
115  /*
116  DEBUG("vertex" << endl);
117  DEBUG(fixed << showpos << setprecision(1)
118  << setw(6) << vertex.getX() << ' '
119  << setw(6) << vertex.getY() << ' '
120  << setw(6) << vertex.getZ() << ' '
121  << setw(6) << vertex.getT() << endl);
122  */
123 
124  // generate hits
125 
126  vector<JHit_t> data;
127 
128  for (JDetector_t::const_iterator pos = detector.begin(); pos != detector.end(); ++pos) {
129  data.push_back(JHit_t(*pos, vertex.getT(*pos)));
130  }
131 
132  /*
133  for (vector<JHit_t>::const_iterator hit = data.begin(); hit != data.end(); ++hit) {
134  DEBUG(fixed << showpos << setprecision(1)
135  << setw(6) << hit->getX() << ' '
136  << setw(6) << hit->getY() << ' '
137  << setw(6) << hit->getZ() << ' '
138  << setw(6) << hit->getT() << endl);
139  }
140  */
141 
142  // fit
143 
144  JEstimator<JPoint4D> result(data.begin(), data.end());
145 
146  hx.Fill(vertex.getX() - result.getX());
147  hy.Fill(vertex.getY() - result.getY());
148  hz.Fill(vertex.getZ() - result.getZ());
149  ht.Fill(vertex.getT() - result.getT());
150 
151  Qx.put(vertex.getX() - result.getX());
152  Qy.put(vertex.getY() - result.getY());
153  Qz.put(vertex.getZ() - result.getZ());
154  Qt.put(vertex.getT() - result.getT());
155  }
156 
157  if (debug >= debug_t) {
158  Qx.print(cout);
159  Qy.print(cout);
160  Qz.print(cout);
161  Qt.print(cout);
162  }
163 
164  if (outputFile != "") {
165 
166  TFile out(outputFile.c_str(), "recreate");
167 
168  out << hx << hy << hz << ht;
169 
170  out.Write();
171  out.Close();
172  }
173 
174  ASSERT(numberOfEvents > 0);
175 
176  ASSERT(Qx.getMean() <= precision);
177  ASSERT(Qy.getMean() <= precision);
178  ASSERT(Qz.getMean() <= precision);
179  ASSERT(Qt.getMean() <= precision);
180 
181  ASSERT(Qx.getSTDev() <= precision);
182  ASSERT(Qy.getSTDev() <= precision);
183  ASSERT(Qz.getSTDev() <= precision);
184  ASSERT(Qt.getSTDev() <= precision);
185 
186  return 0;
187 }
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JTOOLS::result
return result
Definition: JPolint.hh:695
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JEEP::debug_t
debug
Definition: JMessage.hh:29