Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGizmo/JHistogram1D.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 "TH1D.h"
#include "TF1.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/JHistogram1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file JGizmo/JHistogram1D.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 inputFile;
35  string formula;
37  Int_t numberOfEvents;
38  string title;
39  JHistogram_t X;
40  bool sumw2;
41  int debug;
42 
43  try {
44 
45  JParser<> zap("Program to create TH1D and fill according given formula.");
46 
47  zap['o'] = make_field(outputFile);
48  zap['f'] = make_field(inputFile) = "";
49  zap['F'] = make_field(formula) = "";
51  zap['n'] = make_field(numberOfEvents) = 0;
52  zap['T'] = make_field(title) = "h0";
53  zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
54  zap['s'] = make_field(sumw2);
55  zap['d'] = make_field(debug) = 1;
56 
57  zap(argc, argv);
58  }
59  catch(const exception &error) {
60  FATAL(error.what() << endl);
61  }
62 
63 
64  if ((formula != "" && inputFile != "") ||
65  (formula == "" && inputFile == "")) {
66  FATAL("Specify input file or formula." << endl);
67  }
68 
69 
70  TFile out(outputFile.c_str(), "recreate");
71 
72  TH1D h0(title.c_str(), NULL,
73  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
74 
75  if (formula != "") {
76 
77  TF1 f1("f1", formula.c_str());
78 
79  for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
80  f1.FixParameter(getParameter(*i), getValue(*i));
81  }
82 
83  if (numberOfEvents > 0) {
84 
85  h0.Sumw2();
86  h0.FillRandom(f1.GetName(), numberOfEvents);
87 
88  } else {
89 
90  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
91  h0.SetBinContent(ix, f1.Eval(h0.GetXaxis()->GetBinCenter(ix)));
92  }
93  }
94 
95  } else if (inputFile != "") {
96 
97  if (sumw2) {
98  h0.Sumw2();
99  }
100 
101  ifstream in(inputFile.c_str());
102 
103  for (double x; in >> x; ) {
104  h0.Fill(x);
105  }
106 
107  in.close();
108  }
109 
110  out.Write();
111  out.Close();
112 }
Utility class to parse command line options.
Definition: JParser.hh:1514
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
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#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 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:48
Wrapper class around string.
Definition: JToken.hh:23
no fit printf nominal n $STRING awk v X
int debug
debug level