Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSphereND.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JTools/JMapList.hh"
9 #include "JTools/JMultipleMap.hh"
10 #include "JTools/JMultiGrid.hh"
11 #include "JTools/JToolsToolkit.hh"
12 #include "JTools/JFunctionalMap.hh"
13 
14 #include "Jeep/JPrint.hh"
15 #include "Jeep/JTimer.hh"
16 #include "Jeep/JParser.hh"
17 #include "Jeep/JMessage.hh"
18 
19 
20 namespace {
21 
22  /**
23  * Auxiliary class to determine volume of N-dimensional sphere.
24  */
25  template<int N>
26  struct JVolume {
27  /**
28  * Get volume.
29  *
30  * \param R radius
31  * \return volume
32  */
33  static double get(const double R)
34  {
35  return 2*JTOOLS::PI*R*R * JVolume<N-2>::get(R) / N;
36  }
37  };
38 
39 
40  /**
41  * Specialisation of template class JVolume for 2D sphere.
42  */
43  template<>
44  struct JVolume<2> {
45  /**
46  * Get volume.
47  *
48  * \param R radius
49  * \return volume
50  */
51  static double get(const double R)
52  {
53  return JTOOLS::PI*R*R;
54  }
55  };
56 
57 
58  /**
59  * Specialisation of template class JVolume for 1D sphere.
60  */
61  template<>
62  struct JVolume<1> {
63  /**
64  * Get volume.
65  *
66  * \param R radius
67  * \return volume
68  */
69  static double get(const double R)
70  {
71  return 2*R;
72  }
73  };
74 }
75 
76 
77 /**
78  * \file
79  *
80  * Example program to test integration of sphere in any number of dimensions.
81  * \author mdejong
82  */
83 int main(int argc, char **argv)
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
T get(const JHead &header)
Get object from header.
Various implementations of functional maps.
#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:1989
This include file contains various recursive methods to operate on multi-dimensional collections...
#define NOTICE(A)
Definition: JMessage.hh:64
static const double PI
Mathematical constants.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
Utility class to parse command line options.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:484
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:69
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
int debug
debug level