Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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;
31  typedef JAbstractHistogram<Double_t> JHistogram_t;
32 
33  string outputFile;
34  string inputFile;
35  string formula;
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) = "";
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  TH3D h0(title.c_str(), NULL,
77  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit(),
78  Y.getNumberOfBins(), Y.getLowerLimit(), Y.getUpperLimit(),
79  Z.getNumberOfBins(), Z.getLowerLimit(), Z.getUpperLimit());
80 
81  if (formula != "") {
82 
83  TF3 f3("f3", formula.c_str());
84 
85  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
86  f3.FixParameter(getParameter(*i), getValue(*i));
87  }
88 
89  if (numberOfEvents > 0) {
90 
91  h0.Sumw2();
92  h0.FillRandom(f3.GetName(), numberOfEvents);
93 
94  } else {
95 
96  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
97  for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
98  for (Int_t iz = 1; iz <= h0.GetZaxis()->GetNbins(); ++iz) {
99 
100  h0.SetBinContent(ix, iy, iz, f3.Eval(h0.GetXaxis()->GetBinCenter(ix),
101  h0.GetYaxis()->GetBinCenter(iy),
102  h0.GetZaxis()->GetBinCenter(iz)));
103  }
104  }
105  }
106  }
107  } else if (inputFile != "") {
108 
109  if (sumw2) {
110  h0.Sumw2();
111  }
112 
113  ifstream in(inputFile.c_str());
114 
115  for (double x, y, z; in >> x >> y >> z; ) {
116  h0.Fill(x, y, z);
117  }
118 
119  in.close();
120  }
121 
122  out.Write();
123  out.Close();
124 }
Utility class to parse command line options.
Definition: JParser.hh:1517
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.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
#define FATAL(A)
Definition: JMessage.hh:67
no fit printf nominal n $STRING awk v X
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
double f3(const double x, const double y, const double z)
3D function.
Definition: JPolynome3D.cc:23
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level