Jpp
Functions
JSphereND.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JMapList.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JMultipleMap.hh"
#include "JTools/JMultiGrid.hh"
#include "JTools/JToolsToolkit.hh"
#include "JTools/JFunctionalMap.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 integration of sphere in any number of dimensions.

Author
mdejong

Definition in file JSphereND.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 83 of file JSphereND.cc.

84 {
85  using namespace std;
86 
87  unsigned int numberOfBins;
88  double precision;
89  int debug;
90 
91  try {
92 
93  JParser<> zap("Example program to test integration of sphere in any number of dimensions.");
94 
95  zap['N'] = make_field(numberOfBins) = 11;
96  zap['e'] = make_field(precision) = 1.0e-2;
97  zap['d'] = make_field(debug) = 2;
98 
99  zap(argc, argv);
100  }
101  catch(const exception &error) {
102  FATAL(error.what() << endl);
103  }
104 
105 
106  using namespace JPP;
107 
108 
109  const int N = 7;
110  const double R = 1.0;
111 
112  typedef JGridPolint1Function1D_t JFunction1D_t;
113  typedef JMultipleMap<N-2, JPolint1FunctionalGridMap>::typelist JMaplist_t;
114  typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
115 
116 
117  const JGrid<double> grid(numberOfBins, -R * 1.05, +R * 1.05);
118 
119  JMultiFunction_t gs;
120 
121  gs.configure(make_multigrid<N-2>(grid));
122 
123  for (JMultiFunction_t::super_iterator i = gs.super_begin(); i != gs.super_end(); ++i) {
124 
125  const double x = (*i).getKey().getLength();
126 
127  for (int __i = 0; __i != grid.getSize(); ++__i) {
128 
129  const double y = grid.getX(__i);
130  const double z = R*R - x*x - y*y;
131 
132  if (z > 0.0)
133  (*i).getValue()[y] = 2.0 * sqrt(z);
134  else
135  (*i).getValue()[y] = 0.0;
136  }
137  }
138 
139  gs.compile();
140 
141  const double U = JVolume<N>::get(R);
142 
143  JTimer timer("integrator");
144 
145  timer.start();
146 
147  const double W = getIntegral(gs);
148 
149  timer.stop();
150 
151  NOTICE("Sphere " << N << "D" << endl);
152  NOTICE("Volume (real) " << SCIENTIFIC(12,4) << U << endl);
153  NOTICE("Volume (calc) " << SCIENTIFIC(12,4) << W << endl);
154 
155  NOTICE(timer);
156 
157  ASSERT(fabs(U - W) < precision * U);
158 
159  return 0;
160 }
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JTOOLS::getIntegral
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
Definition: JToolsToolkit.hh:133
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
SCIENTIFIC
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:518
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
JAANET::get
T get(const JHead &header)
Get object from header.
Definition: JHeadToolkit.hh:295
FATAL
#define FATAL(A)
Definition: JMessage.hh:67