27{
   30 
   33 
   35  string            inputFile;
   36  string            formula;
   38  size_t            numberOfEvents;
   39  string            title;
   41  bool              logx;
   42  bool              sumw2;
   43  UInt_t            seed;
   45 
   46  try {
   47 
   48    JParser<> zap(
"Program to create TH1D and fill according given formula.");
 
   49    
   61 
   62    zap(argc, argv);
   63  }
   64  catch(const exception &error) {
   65    FATAL(error.what() << endl);
 
   66  }
   67 
   68 
   69  if ((formula != "" && inputFile != "") ||
   70      (formula == "" && inputFile == "")) {
   71    FATAL(
"Specify input file or formula." << endl);
 
   72  }
   73 
   74  gRandom->SetSeed(seed);
   75 
   77 
   78  const string::size_type pos = title.rfind('/');
   79 
   80  if (pos != string::npos) {
   81 
   82    const string dir = title.substr(0, pos);
   83 
   84    out.mkdir(dir.c_str());
   85    out.cd   (dir.c_str());
   86 
   87    title = title.substr(pos + 1);
   88  }
   89  
   90  TH1D h0(title.c_str(), NULL,
   92 
   93  if        (formula != "") {
   94 
   95    TF1 f1("f1", formula.c_str(),
   98 
   99    for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
  100      f1.FixParameter(getParameter(*i), 
getValue(*i));
 
  101    }
  102 
  103    if (numberOfEvents > 0) {
  104 
  105      h0.Sumw2();
  106 
  107      for (size_t i = 0; i != numberOfEvents; ++i) {
  108 
  109        const double x = f1.GetRandom(gRandom);
 
  110 
  111        h0.Fill(logx ? log10(x) : x);
  112      }
  113 
  114    } else {
  115 
  116      for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {      
  117        h0.SetBinContent(ix, f1.Eval(h0.GetXaxis()->GetBinCenter(ix)));
  118      }
  119    }
  120 
  121  } else if (inputFile != "") {
  122 
  123    if (sumw2) {
  124      h0.Sumw2();
  125    }
  126 
  127    ifstream in(inputFile.c_str());
  128 
  129    for (
double x; in >> 
x; ) {
 
  130      h0.Fill(x);
  131    }
  132 
  133    in.close();
  134  }
  135 
  136  out.Write();
  137  out.Close();
  138}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Wrapper class around string.
 
Utility class to parse command line options.
 
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
 
T pow(const T &x, const double y)
Power .
 
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)...