Jpp
JGizmo/JHistogram2D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH2D.h"
9 #include "TF2.h"
10 
11 #include "JLang/JToken.hh"
13 #include "JGizmo/JGizmoToolkit.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Program to create TH1D and fill according given formula.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  typedef JLANG::JToken<';'> JToken_t;
31  typedef JAbstractHistogram<Double_t> JHistogram_t;
32 
33  string outputFile;
34  string formula;
35  vector<JToken_t> parameterValues;
36  Int_t numberOfEvents;
37  JHistogram_t X;
38  JHistogram_t Y;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Program to create TH1D and fill according given formula.");
44 
45  zap['o'] = make_field(outputFile);
46  zap['F'] = make_field(formula);
47  zap['='] = make_field(parameterValues) = JPARSER::initialised();
48  zap['n'] = make_field(numberOfEvents) = 0;
49  zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
50  zap['y'] = make_field(Y) = JHistogram_t(100, -1.0, +1.0);
51  zap['d'] = make_field(debug) = 1;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
59 
60  TF2 f2("f2", formula.c_str());
61 
62  for (vector<JToken_t>::const_iterator i = parameterValues.begin(); i != parameterValues.end(); ++i) {
63  f2.FixParameter(getParameter(*i), getValue(*i));
64  }
65 
66 
67  TFile out(outputFile.c_str(), "recreate");
68 
69  TH2D h0("h0", NULL,
70  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit(),
71  Y.getNumberOfBins(), Y.getLowerLimit(), Y.getUpperLimit());
72 
73  h0.Sumw2();
74 
75  if (numberOfEvents > 0) {
76 
77  h0.FillRandom(f2.GetName(), numberOfEvents);
78 
79  } else {
80 
81  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
82  for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
83  h0.SetBinContent(ix, iy, f2.Eval(h0.GetXaxis()->GetBinCenter(ix),
84  h0.GetYaxis()->GetBinCenter(iy)));
85  }
86  }
87  }
88 
89 
90  out.Write();
91  out.Close();
92 }
JAbstractHistogram.hh
JGIZMO::getParameter
int getParameter(const std::string &text)
Get parameter number from text string.
Definition: JGizmoToolkit.hh:288
JToken.hh
JMessage.hh
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGizmoToolkit.hh
main
int main(int argc, char **argv)
Definition: JGizmo/JHistogram2D.cc:25
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
JParser.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JLANG::JToken
Wrapper class around string.
Definition: JToken.hh:23
std
Definition: jaanetDictionary.h:36
JEEP::getValue
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37