Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGizmo/JHistogram2D.cc File Reference

Program to create TH1D and fill according given formula. More...

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "TF2.h"
#include "JLang/JToken.hh"
#include "JTools/JAbstractHistogram.hh"
#include "JGizmo/JGizmoToolkit.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

Program to create TH1D and fill according given formula.

Author
mdejong

Definition in file JGizmo/JHistogram2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file JGizmo/JHistogram2D.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1493
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
int getParameter(const std::string &text)
Get parameter number from text string.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
Wrapper class around string.
Definition: JToken.hh:23