Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JHistogram3D.cc File Reference

Program to create TH3D 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 "TRandom3.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 TH3D 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 26 of file JGizmo/JHistogram3D.cc.

27{
28 using namespace std;
29 using namespace JPP;
30
31 typedef JToken<';'> JToken_t;
33
34 string outputFile;
35 string inputFile;
36 string formula;
37 vector<JToken_t> parameters;
38 size_t numberOfEvents;
39 string title;
42 JHistogram_t Z;
43 bool logx;
44 bool logy;
45 bool logz;
46 bool sumw2;
47 UInt_t seed;
48 int debug;
49
50 try {
51
52 JParser<> zap("Program to create TH3D and fill according given formula.");
53
54 zap['o'] = make_field(outputFile);
55 zap['f'] = make_field(inputFile) = "";
56 zap['F'] = make_field(formula) = "";
57 zap['@'] = make_field(parameters) = JPARSER::initialised();
58 zap['n'] = make_field(numberOfEvents) = 0;
59 zap['T'] = make_field(title) = "h0";
60 zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
61 zap['y'] = make_field(Y) = JHistogram_t(100, -1.0, +1.0);
62 zap['z'] = make_field(Z) = JHistogram_t(100, -1.0, +1.0);
63 zap['X'] = make_field(logx);
64 zap['Y'] = make_field(logy);
65 zap['Z'] = make_field(logz);
66 zap['s'] = make_field(sumw2);
67 zap['S'] = make_field(seed) = 0;
68 zap['d'] = make_field(debug) = 1;
69
70 zap(argc, argv);
71 }
72 catch(const exception &error) {
73 FATAL(error.what() << endl);
74 }
75
76
77 if ((formula != "" && inputFile != "") ||
78 (formula == "" && inputFile == "")) {
79 FATAL("Specify input file or formula." << endl);
80 }
81
82 gRandom->SetSeed(seed);
83
84 TFile out(outputFile.c_str(), "recreate");
85
86 const string::size_type pos = title.rfind('/');
87
88 if (pos != string::npos) {
89
90 const string dir = title.substr(0, pos);
91
92 out.mkdir(dir.c_str());
93 out.cd (dir.c_str());
94
95 title = title.substr(pos + 1);
96 }
97
98 TH3D h0(title.c_str(), NULL,
102
103 if (formula != "") {
104
105 TF3 f3("f3", formula.c_str(),
106 logx ? pow(10.0, X.getLowerLimit()) : X.getLowerLimit(),
107 logx ? pow(10.0, X.getUpperLimit()) : X.getUpperLimit(),
108 logy ? pow(10.0, Y.getLowerLimit()) : Y.getLowerLimit(),
109 logy ? pow(10.0, Y.getUpperLimit()) : Y.getUpperLimit(),
110 logz ? pow(10.0, Z.getLowerLimit()) : Z.getLowerLimit(),
111 logz ? pow(10.0, Z.getUpperLimit()) : Z.getUpperLimit());
112
113 for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
114 f3.FixParameter(getParameter(*i), getValue(*i));
115 }
116
117 if (numberOfEvents > 0) {
118
119 h0.Sumw2();
120
121 Double_t x, y, z;
122
123 for (size_t i = 0; i != numberOfEvents; ++i) {
124
125 f3.GetRandom3(x, y, z, gRandom);
126
127 h0.Fill(logx ? log10(x) : x,
128 logy ? log10(y) : y,
129 logz ? log10(z) : z);
130 }
131
132 } else {
133
134 for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
135 for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
136 for (Int_t iz = 1; iz <= h0.GetZaxis()->GetNbins(); ++iz) {
137
138 h0.SetBinContent(ix, iy, iz, f3.Eval(h0.GetXaxis()->GetBinCenter(ix),
139 h0.GetYaxis()->GetBinCenter(iy),
140 h0.GetZaxis()->GetBinCenter(iz)));
141 }
142 }
143 }
144 }
145 } else if (inputFile != "") {
146
147 if (sumw2) {
148 h0.Sumw2();
149 }
150
151 ifstream in(inputFile.c_str());
152
153 for (double x, y, z; in >> x >> y >> z; ) {
154 h0.Fill(x, y, z);
155 }
156
157 in.close();
158 }
159
160 out.Write();
161 out.Close();
162}
string outputFile
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#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.
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
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition JScale.hh:47
T pow(const T &x, const double y)
Power .
Definition JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
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.