27{
   30 
   31  typedef JToken<
';'>                  JToken_t;
 
   33 
   35  string            inputFile;
   36  string            formula;
   38  size_t            numberOfEvents;
   39  string            title;
   43  bool              logx;
   44  bool              logy;
   45  bool              logz;
   46  bool              sumw2;
   47  UInt_t            seed;
   49 
   50  try {
   51 
   52    JParser<> zap(
"Program to create TH3D and fill according given formula.");
 
   53    
   69 
   70    zap(argc, argv);
   71  }
   72  catch(const exception &error) {
   73    FATAL(error.what() << endl);
 
   74  }
   75 
   76 
   77  if ((formula != "" && inputFile != "") ||
   78      (formula == "" && inputFile == "")) {
   79    FATAL(
"Specify input file or formula." << endl);
 
   80  }
   81 
   82  gRandom->SetSeed(seed);
   83 
   85 
   86  const string::size_type pos = title.rfind('/');
   87 
   88  if (pos != string::npos) {
   89 
   90    const string dir = title.substr(0, pos);
   91 
   92    out.mkdir(dir.c_str());
   93    out.cd   (dir.c_str());
   94 
   95    title = title.substr(pos + 1);
   96  }
   97 
   98  TH3D h0(title.c_str(), NULL,
  102 
  103  if        (formula != "") {
  104 
  105    TF3 
f3(
"f3", formula.c_str(),
 
  112 
  113    for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
  114      f3.FixParameter(getParameter(*i), 
getValue(*i));
 
  115    }
  116 
  117    if (numberOfEvents > 0) {
  118 
  119      h0.Sumw2();
  120 
  122 
  123      for (size_t i = 0; i != numberOfEvents; ++i) {
  124 
  125        f3.GetRandom3(x, y, z, gRandom);
 
  126 
  127        h0.Fill(logx ? log10(x) : x,
  128                logy ? log10(y) : y,
  129                logz ? log10(z) : z);
  130      }
  131 
  132    } else {
  133 
  134      for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
  135        for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
  136          for (Int_t iz = 1; iz <= h0.GetZaxis()->GetNbins(); ++iz) {
  137            
  138            h0.SetBinContent(ix, iy, iz, 
f3.Eval(h0.GetXaxis()->GetBinCenter(ix),
 
  139                                                 h0.GetYaxis()->GetBinCenter(iy),
  140                                                 h0.GetZaxis()->GetBinCenter(iz)));
  141          }
  142        }
  143      }
  144    }
  145  } else if (inputFile != "") {
  146 
  147    if (sumw2) {
  148      h0.Sumw2();
  149    }
  150 
  151    ifstream in(inputFile.c_str());
  152 
  153    for (
double x, y, z; in >> 
x >> 
y >> z; ) {
 
  154      h0.Fill(x, y, z);
  155    }
  156 
  157    in.close();
  158  }
  159 
  160  out.Write();
  161  out.Close();
  162}
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
double f3(const double x, const double y, const double z)
3D function.
 
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)...