CMS 3D CMS Logo

gridTesters.cc
Go to the documentation of this file.
1 #include "Grid1D.h"
2 #include "Grid3D.h"
3 #include <cassert>
4 
5 namespace {
6  bool testGrid1D(Grid1D const& grid) {
7  bool ok = true;
8 
10  int i = grid.index(7.2, f);
11  ok &= grid.inRange(i);
12 
13  ok &= (8 == i);
14  ok &= (0.6f == f);
15 
16  return ok;
17  }
18 } // namespace
19 
20 #include <iostream>
21 #include <cstdlib>
22 #include <cstdio>
23 
24 namespace {
27  int i = grid.index(a, f);
28  ::printf("%i %f %a\n", i, f, f);
29  grid.normalize(i, f);
30  ::printf("%i %f %a\n", i, f, f);
31  }
32 } // namespace
33 
34 int grid1d_t() {
35  bool ok = true;
36  Grid1D grid(-10., 10., 11);
37 
38  print(grid, 7.2);
39  print(grid, 10.);
40  print(grid, -10.2);
41  print(grid, 10.2);
42 
43  ok &= testGrid1D(grid);
44 
45  assert(ok ? 0 : 1);
46  return ok ? 0 : 1;
47 }
48 
49 namespace {
50 
51  Grid3D const* factory() {
52  Grid1D ga(0., 10., 5);
53  Grid1D gb(-10., 10., 11);
54  Grid1D gc(-10., 10., 11);
55 
56  std::vector<Grid3D::BVector> data;
57  data.reserve(ga.nodes() * gb.nodes() * gc.nodes());
58  for (int i = 0; i < ga.nodes(); ++i)
59  for (int j = 0; j < gb.nodes(); ++j)
60  for (int k = 0; k < gc.nodes(); ++k) {
61  data.push_back(Grid3D::BVector(10 * ga.node(i), 10 * gb.node(j), 10 * gc.node(k)));
62  }
63 
64  return new Grid3D(ga, gb, gc, data);
65  }
66 
67 } // namespace
68 
70 #include <iostream>
71 
72 int grid3d_t() {
73  Grid3D const* grid = factory();
74 
76 
77  std::cout << inter.interpolate(7.5, 7.2, -3.4) << std::endl;
78  std::cout << inter.interpolate(-0.5, 10.2, -3.4) << std::endl;
79 
80  delete grid;
81  return 0;
82 }
int grid3d_t()
Definition: gridTesters.cc:72
float Scalar
Definition: Grid1D.h:9
ReturnType interpolate(Scalar a, Scalar b, Scalar c)
assert(be >=bs)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
double f[11][100]
Definition: Grid3D.h:28
Definition: Grid1D.h:7
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
double a
Definition: hdecay.h:121
int grid1d_t()
Definition: gridTesters.cc:34