Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JGeometry3D/JLegendre.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
5#include "TRandom3.h"
6
7#include "JMath/JLegendre.hh"
9
12
13#include "JTools/JQuantile.hh"
14
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * \file
21 *
22 * Example program to test Legendre polynome.
23 * \author mdejong
24 */
25int main(int argc, char**argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 const double xmin = -10.0;
31 const double xmax = +10.0;
32
34
35 unsigned int numberOfEvents;
36 unsigned int numberOfBins;
37 JLegendre_t f1(xmin, xmax);
38 int debug;
39
40 try {
41
42 JParser<> zap("Example program to test Legendre polynome.");
43
44 zap['n'] = make_field(numberOfEvents) = 0;
45 zap['N'] = make_field(numberOfBins) = 10;
46 zap['L'] = make_field(f1);
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 for (JLegendre_t::iterator i = f1.begin(); i != f1.end(); ++i) {
57
58 i->normalise();
59
60 STATUS("function: " << *i << endl);
61 }
62
63
65
66 for (unsigned int i = 0; i != numberOfBins; ++i) {
67
68 const double x = xmin + i * (xmax - xmin) / (numberOfBins - 1);
69
70 data[x] = f1(x);
71 }
72
73
74 for (map<double, JQuaternion3D>::const_iterator i = data.begin(); i != data.end(); ++i) {
75 DEBUG("data: "
76 << FIXED(7,3) << i->first << " "
77 << i->second << "; "
78 << 360.0 * acos(i->second.getA()) / PI << endl);
79 }
80
81
82 const size_t N = 2;
83
84 JLegendre<JQuaternion3D, N> g1(data.begin(), data.end());
85
86 for (size_t n = 0; n != N + 1; ++n) {
87
88 STATUS("Legendre: " << setw(2) << n << ' ' << g1[n]);
89
90 if (n < f1.size()) {
91 STATUS(' ' << FIXED(7,3) << getAngle(f1[n], g1[n]));
92 }
93
94 STATUS(endl);
95 }
96
97
98 if (numberOfEvents > 0) {
99
100 JQuantile Q;
101
102 for (unsigned int i = 0; i != numberOfEvents; ++i) {
103
104 const double x = gRandom->Uniform(xmin, xmax);
105 const JQuaternion3D y = f1(x);
106 const JQuaternion3D z = g1(x);
107
108 Q.put(getAngle(y,z));
109 }
110
111 Q.print(cout);
112 }
113
114 return 0;
115}
int main(int argc, char **argv)
Auxiliary methods for mathematics.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#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
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
Data structure for unit quaternion in three dimensions.
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
Base class for Legendre polynome.
Definition JLegendre.hh:28
std::vector< JOrdinate_t >::iterator iterator
Definition JLegendre.hh:30
Template definition for function evaluation of Legendre polynome.
Definition JLegendre.hh:269
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
void put(const double x, const double w=1.0)
Put value.
Definition JQuantile.hh:133