Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTable2D.cc File Reference

Example program to test interpolation between 2D tables. More...

#include <iostream>
#include <iomanip>
#include <cmath>
#include "TRandom3.h"
#include "JTools/JTable2D.hh"
#include "JTools/JGrid.hh"
#include "JTools/JElement.hh"
#include "JTools/JPolint.hh"
#include "JTools/JGridCollection.hh"
#include "JTools/JMapList.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JTimer.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

Example program to test interpolation between 2D tables.

Author
mdejong

Definition in file JTable2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 52 of file JTable2D.cc.

53 {
54  using namespace std;
55 
56  int numberOfEvents;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Example program to test interpolation between 2D tables.");
62 
63  zap['n'] = make_field(numberOfEvents);
64  zap['d'] = make_field(debug) = 2;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
72 
73  using namespace JPP;
74 
75 
76  const int NX = 21;
77  const int NY = 11;
78  const int NZ = 11;
79 
80  const JGrid<double> X(NX, -10.0, +10.0);
81  const JGrid<double> Y(NY, -5.0, +5.0);
82  const JGrid<double> Z(NZ, -5.0, +5.0);
83 
84 
85  typedef JTable2D<NY, NZ> JTable2D_t;
86  typedef JElement2D<double, JTable2D_t> JElement2D_t;
87  typedef JPolintFunction1D<2, JElement2D_t, JGridCollection> JFunction1D_t;
88 
89 
90  JFunction1D_t buffer;
91 
92  for (int i = 0; i != X.getSize(); ++i) {
93 
94  DEBUG("table[" << i << "]" << endl);
95 
96  const double x = X.getX(i);
97 
98  JTable2D_t& table = buffer[x];
99 
100  for (int __i = 0; __i != NY; ++__i) {
101  for (int __j = 0; __j != NZ; ++__j) {
102 
103  const double y = Y.getX(__i);
104  const double z = Z.getX(__j);
105 
106  table[__i][__j] = f3(x,y,z);
107 
108  DEBUG(' ' << FIXED(5,3) << table[__i][__j]);
109  }
110  DEBUG(endl);
111  }
112  }
113 
114 
115  // interpolator between table cells
116 
117  typedef JMapList<JPolint1FunctionalGridMap> JMaplist_t;
118  typedef JMultiFunction<JGridPolint1Function1D_t, JMaplist_t> JMultiFunction_t;
119 
120  JMultiFunction_t g2;
121 
122  g2.configure(Y);
123 
124  for (JMultiFunction_t::iterator i = g2.begin(); i != g2.end(); ++i) {
125  i->getY().configure(Z);
126  }
127 
128 
129  JTimer t1("table");
130  JTimer t2("polint");
131 
132  JQuantile f1("table");
133  JQuantile f2("polint");
134 
135 
136  for (int i = 0; i != numberOfEvents; ++i) {
137 
138  const double x = gRandom->Uniform(X.getXmin(), X.getXmax());
139  const double y = gRandom->Uniform(Y.getXmin(), Y.getXmax());
140  const double z = gRandom->Uniform(Z.getXmin(), Z.getXmax());
141 
142  const double v = f3(x,y,z);
143 
144 
145  // simple lookup table
146 
147  t1.start();
148 
149  const int __i = (int) (Y.getSize() * (y - X.getXmin()) / (Y.getXmax() - Y.getXmin()));
150  const int __j = (int) (Z.getSize() * (z - Z.getXmin()) / (Z.getXmax() - Z.getXmin()));
151 
152  const double w1 = buffer(x)[__i][__j];
153 
154  t1.stop();
155 
156 
157  // polynomial interpolation
158 
159  t2.start();
160 
161  const JTable2D_t& table = buffer(x);
162 
163  for (int __i = 0; __i != Y.getSize(); ++__i) {
164  for (int __j = 0; __j != Z.getSize(); ++__j) {
165  g2.getY(__i).getY(__j) = table[__i][__j];
166  }
167  }
168 
169  g2.compile();
170 
171  const double w2 = g2(y,z);
172 
173  t2.stop();
174 
175  f1.put(v - w1);
176  f2.put(v - w2);
177  }
178 
179 
180  for (JQuantile buffer[] = { f1, f2, JQuantile() }, *i = buffer; i->getCount() != 0; ++i) {
181 
182  cout << i->getTitle() << endl;
183  cout << "mean " << SCIENTIFIC(10,2) << i->getMean() << endl;
184  cout << "RMS " << SCIENTIFIC(10,2) << i->getSTDev() << endl;
185  }
186 
187  for (JTimer buffer[] = { t1, t2, JTimer() }, *i = buffer; i->getTitle() != ""; ++i) {
188  i->print(cout, true, micro_t);
189  }
190 }
Utility class to parse command line options.
Definition: JParser.hh:1500
micro
Definition: JScale.hh:29
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
const JPolynome f1(1.0, 2.0, 3.0)
Function.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:67
#define FATAL(A)
Definition: JMessage.hh:67
no fit printf nominal n $STRING awk v X
JTOOLS::JElement2D< double, double > JElement2D_t
Definition: JLED.hh:27
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
double f3(const double x, const double y, const double z)
3D function.
Definition: JPolynome3D.cc:23
data_type v[N+1][M+1]
Definition: JPolint.hh:756
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62