Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JPoint4D.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <fstream>
6#include <vector>
7
8#include "TROOT.h"
9#include "TFile.h"
10#include "TH1D.h"
11#include "TRandom3.h"
12
13#include "JFit/JPoint4D.hh"
15#include "JROOT/JRootToolkit.hh"
16#include "JTools/JQuantile.hh"
17
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20#include "Jeep/JPrint.hh"
21
22
23/**
24 * \file
25 *
26 * Test program for JFIT::JEstimator<JPoint4D> fit.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
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
122 vector<JHit_t> data;
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
General purpose messaging.
#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
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Linear fit of JFIT::JPoint4D.
int main(int argc, char **argv)
Definition JPoint4D.cc:29
I/O formatting auxiliaries.
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
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
double getT(const JVector3D &pos) const
Get arrival time of Cherenkov light at given position.
Definition JVertex3D.hh:147
Utility class to parse command line options.
Definition JParser.hh:1698
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
std::ostream & print(std::ostream &out, bool lpr=true) const
Print quantile.
Definition JQuantile.hh:382
double getSTDev() const
Get standard deviation.
Definition JQuantile.hh:281
void put(const double x, const double w=1.0)
Put value.
Definition JQuantile.hh:133
double getMean() const
Get mean value.
Definition JQuantile.hh:252