26{
29
30 typedef JToken<
';'> JToken_t;
32
34 string inputFile;
35 string formula;
37 Int_t numberOfEvents;
38 string title;
41 bool sumw2;
43
44 try {
45
46 JParser<> zap(
"Program to create TH2D and fill according given formula.");
47
58
59 zap(argc, argv);
60 }
61 catch(const exception &error) {
62 FATAL(error.what() << endl);
63 }
64
65
66 if ((formula != "" && inputFile != "") ||
67 (formula == "" && inputFile == "")) {
68 FATAL(
"Specify input file or formula." << endl);
69 }
70
71
73
74 const string::size_type pos = title.rfind('/');
75
76 if (pos != string::npos) {
77
78 const string dir = title.substr(0, pos);
79
80 out.mkdir(dir.c_str());
81 out.cd (dir.c_str());
82
83 title = title.substr(pos + 1);
84 }
85
86 TH2D h0(title.c_str(), NULL,
89
90 if (formula != "") {
91
92 TF2 f2("f2", formula.c_str());
93
94 for (vector<JToken_t>::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
95 f2.FixParameter(getParameter(*i),
getValue(*i));
96 }
97
98 if (numberOfEvents > 0) {
99
100 h0.Sumw2();
101 h0.FillRandom(f2.GetName(), numberOfEvents);
102
103 } else {
104
105 for (Int_t ix = 1; ix <= h0.GetXaxis()->GetNbins(); ++ix) {
106 for (Int_t iy = 1; iy <= h0.GetYaxis()->GetNbins(); ++iy) {
107 h0.SetBinContent(ix, iy, f2.Eval(h0.GetXaxis()->GetBinCenter(ix),
108 h0.GetYaxis()->GetBinCenter(iy)));
109 }
110 }
111 }
112 } else if (inputFile != "") {
113
114 if (sumw2) {
115 h0.Sumw2();
116 }
117
118 ifstream in(inputFile.c_str());
119
120 for (
double x, y; in >>
x >>
y; ) {
121 h0.Fill(x, y);
122 }
123
124 in.close();
125 }
126
127 out.Write();
128 out.Close();
129}
#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.
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)...