Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Functions
JGizmo/JHistogram3D.cc File Reference

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

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH3D.h"
#include "TF3.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 TH2D and fill according given formula.

Author
mdejong

Definition in file JGizmo/JHistogram3D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

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

26 {
27  using namespace std;
28  using namespace JPP;
29 
30  typedef JToken<';'> JToken_t;
32 
33  string outputFile;
34  string inputFile;
35  string formula;
36  vector<JToken_t> parameters;
37  Int_t numberOfEvents;
38  string title;
39  JHistogram_t X;
40  JHistogram_t Y;
41  JHistogram_t Z;
42  bool sumw2;
43  int debug;
44 
45  try {
46 
47  JParser<> zap("Program to create TH2D and fill according given formula.");
48 
49  zap['o'] = make_field(outputFile);
50  zap['f'] = make_field(inputFile) = "";
51  zap['F'] = make_field(formula) = "";
52  zap['@'] = make_field(parameters) = JPARSER::initialised();
53  zap['n'] = make_field(numberOfEvents) = 0;
54  zap['T'] = make_field(title) = "h0";
55  zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
56  zap['y'] = make_field(Y) = JHistogram_t(100, -1.0, +1.0);
57  zap['z'] = make_field(Z) = JHistogram_t(100, -1.0, +1.0);
58  zap['s'] = make_field(sumw2);
59  zap['d'] = make_field(debug) = 1;
60 
61  zap(argc, argv);
62  }
63  catch(const exception &error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
68  if ((formula != "" && inputFile != "") ||
69  (formula == "" && inputFile == "")) {
70  FATAL("Specify input file or formula." << endl);
71  }
72 
73 
74  TFile out(outputFile.c_str(), "recreate");
75 
76  const string::size_type pos = title.rfind('/');
77 
78  if (pos != string::npos) {
79 
80  const string dir = title.substr(0, pos);
81 
82  out.mkdir(dir.c_str());
83  out.cd (dir.c_str());
84 
85  title = title.substr(pos + 1);
86  }
87 
88  TH3D h0(title.c_str(), NULL,
92 
93  if (formula != "") {
94 
95  TF3 f3("f3", formula.c_str());
96 
97  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
98  f3.FixParameter(getParameter(*i), getValue(*i));
99  }
100 
101  if (numberOfEvents > 0) {
102 
103  h0.Sumw2();
104  h0.FillRandom(f3.GetName(), numberOfEvents);
105 
106  } else {
107 
108  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
109  for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
110  for (Int_t iz = 1; iz <= h0.GetZaxis()->GetNbins(); ++iz) {
111 
112  h0.SetBinContent(ix, iy, iz, f3.Eval(h0.GetXaxis()->GetBinCenter(ix),
113  h0.GetYaxis()->GetBinCenter(iy),
114  h0.GetZaxis()->GetBinCenter(iz)));
115  }
116  }
117  }
118  }
119  } else if (inputFile != "") {
120 
121  if (sumw2) {
122  h0.Sumw2();
123  }
124 
125  ifstream in(inputFile.c_str());
126 
127  for (double x, y, z; in >> x >> y >> z; ) {
128  h0.Fill(x, y, z);
129  }
130 
131  in.close();
132  }
133 
134  out.Write();
135  out.Close();
136 }
string outputFile
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
double f3(const double x, const double y, const double z)
3D function.
Definition: JPolynome3D.cc:23
Wrapper class around string.
Definition: JToken.hh:26
Utility class to parse command line options.
Definition: JParser.hh:1698
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
JAbstractHistogram< double > JHistogram_t
Type definition for scan along axis.
Definition: JBillabong.cc:61
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.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Simple data structure for histogram binning.
int getNumberOfBins() const
Get number of bins.