27{
   30 
   31  typedef JToken<
';'>                  JToken_t;
 
   33 
   35  string            inputFile;
   36  string            formula;
   38  size_t            numberOfEvents;
   39  string            title;
   42  bool              logx;
   43  bool              logy;
   44  bool              sumw2;
   45  UInt_t            seed;
   47 
   48  try {
   49 
   50    JParser<> zap(
"Program to create TH2D and fill according given formula.");
 
   51    
   65 
   66    zap(argc, argv);
   67  }
   68  catch(const exception &error) {
   69    FATAL(error.what() << endl);
 
   70  }
   71 
   72 
   73  if ((formula != "" && inputFile != "") ||
   74      (formula == "" && inputFile == "")) {
   75    FATAL(
"Specify input file or formula." << endl);
 
   76  }
   77 
   78  gRandom->SetSeed(seed);
   79 
   81 
   82  const string::size_type pos = title.rfind('/');
   83 
   84  if (pos != string::npos) {
   85 
   86    const string dir = title.substr(0, pos);
   87 
   88    out.mkdir(dir.c_str());
   89    out.cd   (dir.c_str());
   90 
   91    title = title.substr(pos + 1);
   92  }
   93 
   94  TH2D h0(title.c_str(), NULL,
   97 
   98  if        (formula != "") {
   99 
  100    TF2 f2("f2", formula.c_str(),
  105 
  106    for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
  107      f2.FixParameter(getParameter(*i), 
getValue(*i));
 
  108    }
  109 
  110    if (numberOfEvents > 0) {
  111 
  112      h0.Sumw2();
  113 
  115 
  116      for (size_t i = 0; i != numberOfEvents; ++i) {
  117 
  118        f2.GetRandom2(x, y, gRandom);
  119 
  120        h0.Fill(logx ? log10(x) : x,
  121                logy ? log10(y) : y);
  122      }
  123 
  124    } else {
  125 
  126      for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
  127        for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
  128          h0.SetBinContent(ix, iy, f2.Eval(h0.GetXaxis()->GetBinCenter(ix),
  129                                           h0.GetYaxis()->GetBinCenter(iy)));
  130        }
  131      }
  132    }
  133  } else if (inputFile != "") {
  134 
  135    if (sumw2) {
  136      h0.Sumw2();
  137    }
  138 
  139    ifstream in(inputFile.c_str());
  140 
  141    for (
double x, y; in >> 
x >> 
y; ) {
 
  142      h0.Fill(x, y);
  143    }
  144 
  145    in.close();
  146  }
  147 
  148  out.Write();
  149  out.Close();
  150}
#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)...