Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPoint3D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH1D.h"
9 #include "TRandom3.h"
10 
11 #include "JGeometry3D/JAxis3D.hh"
12 #include "JFit/JPoint3D.hh"
14 #include "JROOT/JRootToolkit.hh"
15 #include "JTools/JQuantile.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 #include "Jeep/JPrint.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Test program for JFIT::JEstimator<JPoint3D> fit.
26  * \author mdejong
27  */
28 int main(int argc, char**argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  string outputFile;
34  int numberOfEvents;
35  int numberOfAxes;
36  double sigma;
37  double precision;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Test program for position fit.");
43 
44  zap['o'] = make_field(outputFile) = "";
45  zap['n'] = make_field(numberOfEvents) = 1000;
46  zap['N'] = make_field(numberOfAxes) = 3;
47  zap['s'] = make_field(sigma) = 1.0e-4;
48  zap['e'] = make_field(precision) = 1.0e-3;
49  zap['d'] = make_field(debug) = 3;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  TH1D hx("hx", NULL, 101, -1.0, +1.0);
59  TH1D hy("hy", NULL, 101, -1.0, +1.0);
60  TH1D hz("hz", NULL, 101, -1.0, +1.0);
61 
62  JQuantile Qx("x");
63  JQuantile Qy("y");
64  JQuantile Qz("z");
65 
66 
67  for (int i = 0; i != numberOfEvents; ++i) {
68 
69  const JVector3D vertex(0.0, 0.0, 0.0);
70 
71  // generate axes
72 
74 
75  for (int j = 0; j != numberOfAxes; ++j) {
76 
77  const double x = gRandom->Gaus(0.0, sigma);
78  const double y = gRandom->Gaus(0.0, sigma);
79  const double z = gRandom->Gaus(0.0, sigma);
80 
81  const double dx = gRandom->Uniform(-1, +1);
82  const double dy = gRandom->Uniform(-1, +1);
83  const double dz = gRandom->Uniform(-1, +1);
84 
85  detector.push_back(JAxis3D(vertex + JVector3D(x,y,z), JVersor3D(dx,dy,dz)));
86  }
87 
88  // fit
89 
90  JEstimator<JPoint3D> result(detector.begin(), detector.end());
91 
92  hx.Fill(vertex.getX() - result.getX());
93  hy.Fill(vertex.getY() - result.getY());
94  hz.Fill(vertex.getZ() - result.getZ());
95 
96  Qx.put(vertex.getX() - result.getX());
97  Qy.put(vertex.getY() - result.getY());
98  Qz.put(vertex.getZ() - result.getZ());
99  }
100 
101  if (debug >= debug_t) {
102  Qx.print(cout);
103  Qy.print(cout);
104  Qz.print(cout);
105  }
106 
107  if (outputFile != "") {
108 
109  TFile out(outputFile.c_str(), "recreate");
110 
111  out << hx << hy << hz;
112 
113  out.Write();
114  out.Close();
115  }
116 
117  ASSERT(numberOfEvents > 0);
118 
119  ASSERT(fabs(Qx.getMean()) <= precision);
120  ASSERT(fabs(Qy.getMean()) <= precision);
121  ASSERT(fabs(Qz.getMean()) <= precision);
122 
123  ASSERT(Qx.getSTDev() <= precision);
124  ASSERT(Qy.getSTDev() <= precision);
125  ASSERT(Qz.getSTDev() <= precision);
126 
127  return 0;
128 }
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
string outputFile
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
return result
Definition: JPolint.hh:727
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Linear fit of JFIT::JPoint3D.
Utility class to parse command line options.
int j
Definition: JPolint.hh:666
do set_variable DETECTOR_TXT $WORKDIR detector