Jpp  19.1.0
the software that should make you happy
JTools/JHistogram3D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
6 #include "TMath.h"
7 #include "TRandom.h"
8 
12 #include "JTools/JMultiSet.hh"
13 #include "JTools/JQuadrature.hh"
14 #include "JTools/JToolsToolkit.hh"
15 #include "JTools/JFunction1D_t.hh"
16 #include "JTools/JQuantile.hh"
17 #include "JTools/JMultiPDF.hh"
18 #include "JIO/JFileStreamIO.hh"
19 #include "JLang/JObjectIO.hh"
20 
21 #include "Jeep/JPrint.hh"
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 namespace {
27 
28  /**
29  * Normalised function in 3D.
30  *
31  * \param x x value
32  * \param y y value
33  * \param z z value
34  * \return function value
35  */
36  inline Double_t g3(const Double_t x,
37  const Double_t y,
38  const Double_t z)
39  {
40  return (TMath::Gaus(x, 0.0, 1.0, kTRUE) *
41  TMath::Gaus(y, 0.0, 1.0, kTRUE) *
42  TMath::Gaus(z, 0.0, 1.0, kTRUE));
43  }
44 }
45 
46 
47 /**
48  * \file
49  *
50  * Example program to test JTOOLS::JMultiHistogram.
51  * \author mdejong
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56 
57  string inputFile;
58  string outputFile;
59  int numberOfEvents;
60  int numberOfBins;
61  int debug;
62 
63  try {
64 
65  JParser<> zap("Example program to test 3D histogram.");
66 
67  zap['f'] = make_field(inputFile) = "";
68  zap['o'] = make_field(outputFile) = "";
69  zap['n'] = make_field(numberOfEvents);
70  zap['N'] = make_field(numberOfBins) = 11;
71  zap['d'] = make_field(debug) = 3;
72 
73  zap(argc, argv);
74  }
75  catch(const exception &error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  if (numberOfEvents <= 0) {
81  FATAL("No events." << endl);
82  }
83 
84  using namespace JPP;
85 
86 
89  JPolint1FunctionalMap>::maplist> JMultiPDF_t;
90 
91 
92  if (outputFile != "") {
93 
94  typedef JMAPLIST<JHistogramMap_t,
95  JHistogramMap_t>::maplist JMapList_t;
96 
97  typedef JMultiHistogram<JHistogram1D_t, JMapList_t> JMultiHistogram_t;
98 
99 
100  JMultiHistogram_t histogram;
101 
103 
104 
105  // fill
106 
107  for (int i = 0; i != numberOfEvents; ++i) {
108 
109  if (i%1000 == 0) {
110  STATUS("event: " << setw(10) << i << '\r'); DEBUG(endl);
111  }
112 
113  const double x = gRandom->Gaus(0.0, 1.0);
114  const double y = gRandom->Gaus(0.0, 1.0);
115  const double z = gRandom->Gaus(0.0, 1.0);
116  const double w = 1.0;
117 
118  histogram.fill(x, y, z, w);
119  }
120  STATUS(endl);
121 
122  histogram.div((double) numberOfEvents);
123 
124 
125  try {
126 
127  JMultiPDF_t pdf(histogram);
128 
129  JLANG::store<JIO::JFileStreamWriter>(outputFile.c_str(), pdf);
130  }
131  catch(const JException& error) {
132  FATAL(error.what() << endl);
133  }
134  }
135 
136 
137  if (inputFile != "") {
138 
139  JMultiPDF_t pdf;
140 
141  JLANG::load<JIO::JFileStreamReader>(inputFile.c_str(), pdf);
142 
143  JQuantile Q;
144 
145  for (int i = 0; i != numberOfEvents; ++i) {
146 
147  const double x = gRandom->Gaus(0.0, 1.0);
148  const double y = gRandom->Gaus(0.0, 1.0);
149  const double z = gRandom->Gaus(0.0, 1.0);
150 
151  try {
152 
153  const double u = g3 (x, y, z);
154  const double v = pdf(x, y, z);
155 
156  Q.put(u - v);
157  }
158  catch(const std::exception& error) {}
159  }
160 
163  JMapList<JPolint1FunctionalMap> > > JMultiFunction_t;
164 
165  cout << "normalisation " << FIXED(5,3) << getIntegral(static_cast<const JMultiFunction_t&>(pdf)) << endl;
166  cout << "efficiency " << FIXED(5,3) << (double) Q.getCount() / (double) numberOfEvents << endl;
167 
168  Q.print(cout);
169  }
170 }
string outputFile
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:69
General methods for loading and storing a single object from and to a file, respectively.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
I/O formatting auxiliaries.
Auxiliary classes for numerical integration.
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:70
This include file contains various recursive methods to operate on multi-dimensional collections.
int main(int argc, char **argv)
General exception.
Definition: JException.hh:24
virtual const char * what() const override
Get error message.
Definition: JException.hh:64
Utility class to parse command line options.
Definition: JParser.hh:1698
Numerical integrator for .
Definition: JQuadrature.hh:251
Multidimensional interpolation method.
Multidimensional histogram.
General purpose class for multi-dimensional probability density function (PDF).
Definition: JMultiPDF.hh:37
T make_set(T __begin, T __end, JResult_t std::iterator_traits< T >::value_type::*value, const JComparator_t &comparator)
Method to exclude outliers from already sorted data.
Definition: JVectorize.hh:169
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
data_type w[N+1][M+1]
Definition: JPolint.hh:867
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
double u[N+1]
Definition: JPolint.hh:865
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Type definition of a JHistogramMap based on JMap implementation.
Auxiliary class for recursive map list generation.
Definition: JMapList.hh:109
Map list.
Definition: JMapList.hh:25
Type definition of a 1st degree polynomial interpolation with result type double.
Type definition of a 1st degree polynomial interpolation based on a JMap implementation.
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
long long int getCount() const
Get total count.
Definition: JQuantile.hh:186