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 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  JHistogram_t X;
39  JHistogram_t Y;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Program to create TH1D and fill according given formula.");
45 
46  zap['o'] = make_field(outputFile);
47  zap['f'] = make_field(inputFile) = "";
48  zap['F'] = make_field(formula) = "";
50  zap['n'] = make_field(numberOfEvents) = 0;
51  zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
52  zap['y'] = make_field(Y) = JHistogram_t(100, -1.0, +1.0);
53  zap['d'] = make_field(debug) = 1;
54 
55  zap(argc, argv);
56  }
57  catch(const exception &error) {
58  FATAL(error.what() << endl);
59  }
60 
61 
62  if ((formula != "" && inputFile != "") ||
63  (formula == "" && inputFile == "")) {
64  FATAL("Specify input file or formula." << endl);
65  }
66 
67 
68  TFile out(outputFile.c_str(), "recreate");
69 
70  TH2D h0("h0", NULL,
71  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit(),
72  Y.getNumberOfBins(), Y.getLowerLimit(), Y.getUpperLimit());
73 
74  if (formula != "") {
75 
76  TF2 f2("f2", formula.c_str());
77 
78  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
79  f2.FixParameter(getParameter(*i), getValue(*i));
80  }
81 
82  if (numberOfEvents > 0) {
83 
84  h0.Sumw2();
85  h0.FillRandom(f2.GetName(), numberOfEvents);
86 
87  } else {
88 
89  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
90  for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
91  h0.SetBinContent(ix, iy, f2.Eval(h0.GetXaxis()->GetBinCenter(ix),
92  h0.GetYaxis()->GetBinCenter(iy)));
93  }
94  }
95  }
96  } else if (inputFile != "") {
97 
98  h0.Sumw2();
99 
100  ifstream in(inputFile.c_str());
101 
102  for (double x, y; in >> x >> y; ) {
103  h0.Fill(x, y);
104  }
105 
106  in.close();
107  }
108 
109  out.Write();
110  out.Close();
111 }
Utility class to parse command line options.
Definition: JParser.hh:1500
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:66
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:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
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 source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36