Jpp
Functions
JGizmo/JHistogram1D.cc File Reference
#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

◆ main()

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 formula;
35  vector<JToken_t> parameterValues;
36  Int_t numberOfEvents;
37  JHistogram_t X;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Program to create TH1D and fill according given formula.");
43 
44  zap['o'] = make_field(outputFile);
45  zap['F'] = make_field(formula);
46  zap['='] = make_field(parameterValues) = JPARSER::initialised();
47  zap['n'] = make_field(numberOfEvents) = 0;
48  zap['x'] = make_field(X) = JHistogram_t(100, -1.0, +1.0);
49  zap['d'] = make_field(debug) = 1;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  TF1 f1("f1", formula.c_str());
59 
60  for (vector<JToken_t>::const_iterator i = parameterValues.begin(); i != parameterValues.end(); ++i) {
61  f1.FixParameter(getParameter(*i), getValue(*i));
62  }
63 
64 
65  TFile out(outputFile.c_str(), "recreate");
66 
67  TH1D h0("h0", NULL,
68  X.getNumberOfBins(), X.getLowerLimit(), X.getUpperLimit());
69 
70  h0.Sumw2();
71 
72  if (numberOfEvents > 0) {
73 
74  h0.FillRandom(f1.GetName(), numberOfEvents);
75 
76  } else {
77 
78  for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
79  h0.SetBinContent(ix, f1.Eval(h0.GetXaxis()->GetBinCenter(ix)));
80  }
81  }
82 
83  out.Write();
84  out.Close();
85 }
JGIZMO::getParameter
int getParameter(const std::string &text)
Get parameter number from text string.
Definition: JGizmoToolkit.hh:288
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
std::vector
Definition: JSTDTypes.hh:12
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JLANG::JToken
Wrapper class around string.
Definition: JToken.hh:23
std
Definition: jaanetDictionary.h:36
JEEP::getValue
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37