Jpp  17.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JTools/JHistogram2D.cc File Reference

Example program to test JTOOLS::JMultiHistogram. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "TMath.h"
#include "TRandom.h"
#include "JTools/JHistogram1D_t.hh"
#include "JTools/JHistogramMap_t.hh"
#include "JTools/JMultiHistogram.hh"
#include "JTools/JCollection.hh"
#include "JTools/JMultiGrid.hh"
#include "JTools/JMultiSet.hh"
#include "JTools/JQuadrature.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JToolsToolkit.hh"
#include "JTools/JMultiPDF.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 JTOOLS::JMultiHistogram.

Author
mdejong

Definition in file JTools/JHistogram2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 85 of file JTools/JHistogram2D.cc.

86 {
87  using namespace std;
88 
89  string outputFile;
90  int numberOfEvents;
91  int numberOfBins;
92  bool quadrature;
93  bool subtract;
94  int debug;
95 
96  try {
97 
98  JParser<> zap("Example program to test 2D histogram.");
99 
100  zap['o'] = make_field(outputFile) = "histogram.root";
101  zap['n'] = make_field(numberOfEvents);
102  zap['N'] = make_field(numberOfBins);
103  zap['Q'] = make_field(quadrature);
104  zap['D'] = make_field(subtract);
105  zap['d'] = make_field(debug) = 3;
106 
107  zap(argc, argv);
108  }
109  catch(const exception &error) {
110  FATAL(error.what() << endl);
111  }
112 
113 
114  if (numberOfEvents <= 0) {
115  FATAL("No events." << endl);
116  }
117 
118  using namespace JPP;
119 
120  const Int_t nx = 100;
121  const Double_t xmin = -3.0;
122  const Double_t xmax = +3.0;
123 
124  typedef JMultiHistogram<JHistogram1D_t,
125  JMapList<JHistogramMap_t> > JHistogram2D_t;
126 
127  JHistogram2D_t histogram;
128 
129 
130  // abscissa
131 
132  if (!quadrature)
133  configure(histogram, make_grid(numberOfBins + 1, xmin, xmax));
134  else
135  configure(histogram, make_set(JGaussHermite(numberOfBins + 1)));
136 
137 
138  // fill
139 
140  for (int i = 0; i != numberOfEvents; ++i) {
141 
142  const double x = gRandom->Gaus(0.0, 1.0);
143  const double y = gRandom->Gaus(0.0, 1.0);
144 
145  histogram.fill(x, y, 1.0);
146  }
147 
148 
149  histogram.div((double) numberOfEvents);
150 
151 
152  // interpolation based on function values
153 
154  JMultiPDF<JPolint2Function1D_t,
155  JMapList<JPolint2FunctionalMap> > f2(histogram);
156 
157 
158  // interpolation based on integral values
159 
160  accumulate(histogram);
161 
162  JMultiFunction<JPolint3Function1H_t,
163  JMapList<JPolint3FunctionalMapH> > F2;
164 
165  copy(histogram, F2);
166 
167  F2.compile();
168 
169 
170  TFile out(outputFile.c_str(), "recreate");
171 
172  TH2D h0("h0", NULL, nx, xmin, xmax, nx, xmin, xmax);
173  TH2D h1("h1", NULL, nx, xmin, xmax, nx, xmin, xmax);
174  TH2D h2("h2", NULL, nx, xmin, xmax, nx, xmin, xmax);
175 
176 
177  for (int i = 1; i <= h0.GetXaxis()->GetNbins(); ++i) {
178  for (int j = 1; j <= h0.GetYaxis()->GetNbins(); ++j) {
179 
180  const Double_t x = h0.GetXaxis()->GetBinCenter(i);
181  const Double_t y = h0.GetYaxis()->GetBinCenter(j);
182 
183  h0.SetBinContent(i, j, g2(x,y));
184 
185  try {
186  h1.SetBinContent(i, j, F2(x,y).fp.fp);
187  h2.SetBinContent(i, j, f2(x,y));
188  }
189  catch(const exception& error) {
190  //ERROR(error.what() << endl);
191  }
192  }
193  }
194 
195  if (subtract) {
196  h1.Add(&h0, -1.0);
197  h2.Add(&h0, -1.0);
198  }
199 
200  out.Write();
201  out.Close();
202 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1517
string outputFile
bool quadrature
Definition: JResultPDF.cc:23
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
JHistogram1D< JElement2D< double, double >, JCollection > JHistogram1D_t
Type definition of a 1 dimensional histogram based on a JCollection.
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
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
int j
Definition: JPolint.hh:703
JGrid< JAbscissa_t > make_grid(const int nx, const JAbscissa_t Xmin, const JAbscissa_t Xmax)
Helper method for JGrid.
Definition: JGrid.hh:209
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:69
int debug
debug level
void accumulate(T &value, JBool< false > option)
Accumulation of value.