Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPoint4D.cc File Reference

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

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#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"

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 using namespace JPP;
33
34 string inputFile;
35 string outputFile;
36 int numberOfEvents;
37 double precision;
38 int debug;
39
40 try {
41
42 JParser<> zap("Test program for vertex fit.");
43
44 zap['f'] = make_field(inputFile) = "";
45 zap['o'] = make_field(outputFile) = "";
46 zap['n'] = make_field(numberOfEvents) = 1000;
47 zap['e'] = make_field(precision) = 1.0e-5;
48 zap['d'] = make_field(debug) = 3;
49
50 zap(argc, argv);
51 }
52 catch(const exception& error) {
53 FATAL(error.what() << endl);
54 }
55
56
57 TH1D hx("hx", NULL, 101, -1.0, +1.0);
58 TH1D hy("hy", NULL, 101, -1.0, +1.0);
59 TH1D hz("hz", NULL, 101, -1.0, +1.0);
60 TH1D ht("ht", NULL, 101, -1.0, +1.0);
61
62 JQuantile Qx("x");
63 JQuantile Qy("y");
64 JQuantile Qz("z");
65 JQuantile Qt("t");
66
67
68 typedef vector<JVector3D> JDetector_t;
69
70 JDetector_t detector;
71
72 if (inputFile != "") {
73
74 ifstream in(inputFile.c_str());
75
76 for (double x, y, z; in >> x >> y >> z; ) {
77 detector.push_back(JVector3D(x,y,z));
78 }
79
80 in.close();
81
82 } else {
83
84 for (double x = -50.0; x < 100.0; x += 100.0) {
85 for (double y = -50.0; y < 100.0; y += 100.0) {
86 for (double z = -50.0; z < 100.0; z += 100.0) {
87 detector.push_back(JVector3D(x,y,z));
88 }
89 }
90 }
91 }
92
93
94 typedef JVertex3D JHit_t;
95
96 const double xmin = -1.0;
97 const double xmax = +1.0;
98
99 const double tmin = -1.0;
100 const double tmax = +1.0;
101
102
103 for (int i = 0; i != numberOfEvents; ++i) {
104
105 // generate point
106
107 const double x = gRandom->Uniform(xmin, xmax);
108 const double y = gRandom->Uniform(xmin, xmax);
109 const double z = gRandom->Uniform(xmin, xmax);
110 const double t = gRandom->Uniform(tmin, tmax);
111
112 JPoint4D point(JVector3D(x,y,z), t);
113
114 DEBUG("point "
115 << FIXED(7,3) << point.getX() << ' '
116 << FIXED(7,3) << point.getY() << ' '
117 << FIXED(7,3) << point.getZ() << ' '
118 << FIXED(7,3) << point.getT() << endl);
119
120 // generate hits
121
123
124 for (JDetector_t::const_iterator pos = detector.begin(); pos != detector.end(); ++pos) {
125 data.push_back(JHit_t(*pos, point.getT(*pos)));
126 }
127
128 for (vector<JHit_t>::const_iterator hit = data.begin(); hit != data.end(); ++hit) {
129 DEBUG("hit "
130 << FIXED(7,3) << hit->getX() << ' '
131 << FIXED(7,3) << hit->getY() << ' '
132 << FIXED(7,3) << hit->getZ() << ' '
133 << FIXED(7,3) << hit->getT() << endl);
134 }
135
136 // fit
137
138 JEstimator<JPoint4D> result(data.begin(), data.end());
139
140 DEBUG("result "
141 << FIXED(7,3) << result.getX() << ' '
142 << FIXED(7,3) << result.getY() << ' '
143 << FIXED(7,3) << result.getZ() << ' '
144 << FIXED(7,3) << result.getT() << endl);
145
146 hx.Fill(point.getX() - result.getX());
147 hy.Fill(point.getY() - result.getY());
148 hz.Fill(point.getZ() - result.getZ());
149 ht.Fill(point.getT() - result.getT());
150
151 Qx.put(point.getX() - result.getX());
152 Qy.put(point.getY() - result.getY());
153 Qz.put(point.getZ() - result.getZ());
154 Qt.put(point.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(fabs(Qx.getMean()) <= precision);
177 ASSERT(fabs(Qy.getMean()) <= precision);
178 ASSERT(fabs(Qz.getMean()) <= precision);
179 ASSERT(fabs(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}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Template definition of linear fit.
Definition JEstimator.hh:25
Data structure for vertex fit.
Definition JPoint4D.hh:24
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Utility class to parse command line options.
Definition JParser.hh:1698
const double xmax
const double xmin
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary class to set-up Hit.
Definition JSirene.hh:58
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46