Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
87  typedef JMultiPDF<JPolint1Function1D_t,
88  JMAPLIST<JPolint1FunctionalMap,
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 
102  configure(histogram, make_set(JGaussHermite(numberOfBins)));
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 
161  typedef JMultiFunction<JPolint1Function1D_t,
162  JMapList<JPolint1FunctionalMap,
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
data_type w[N+1][M+1]
Definition: JPolint.hh:757
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
#define STATUS(A)
Definition: JMessage.hh:63
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
This include file contains various recursive methods to operate on multi-dimensional collections...
int debug
debug level
Definition: JSirene.cc:67
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
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Auxiliary classes for numerical integration.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
Utility class to parse command line options.
General methods for loading and storing a single object from and to a file, respectively.
data_type v[N+1][M+1]
Definition: JPolint.hh:756
double u[N+1]
Definition: JPolint.hh:755
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:68
JContainer_t::ordinate_type getIntegral(const JContainer_t &input)
Get integral of input data points.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62