60{
63
67 string name;
69
70 try {
71
72 JParser<> zap(
"Auxiliary program for histogram operations.");
73
74 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
76 JOpera::Add(),
77 JOpera::add(),
78 JOpera::Subtract(),
79 JOpera::subtract(),
80 JOpera::Multiply(),
81 JOpera::multiply(),
82 JOpera::Divide(),
83 JOpera::divide(),
84 JOpera::efficiency(),
85 JOpera::stdev(),
86 JOpera::Replace();
89 << "\n\t\"" << JOpera::SAME_AS_OPERATION() << "\" -> same as operation; or"
90 << "\n\t\"" << JOpera::SAME_AS_INPUT() << "\" -> same as input; else"
91 << "\n\t as specified") = JOpera::SAME_AS_OPERATION();
93
95 }
96 catch(const exception &error) {
98 }
99
100
102
104
106
108
110 ERROR(
"File: " << input->getFullFilename() <<
" not opened." <<
endl);
111 continue;
112 }
113
115
117
119
120 const TString tag(
key->GetName());
121
123
124
125
127
129
130 if (
dynamic_cast<TH2*
>(p) ==
NULL) {
131 FATAL(
"Object " << p->GetName() <<
" not compatible with histogram operations." <<
endl);
132 }
133
135 }
136 }
137 }
138
139
141
143
145
147 opera == JOpera::Subtract() ||
148 opera == JOpera::Multiply() ||
149 opera == JOpera::Divide() ||
150 opera == JOpera::Replace())) {
151
152
153
155 TF2* f1 = dynamic_cast<TF2*>(h1->GetListOfFunctions()->First());
156
158 FATAL(h1->GetName() <<
" has no associated function." <<
endl);
159 }
160
162
163 if (name == JOpera::SAME_AS_OPERATION())
165 else if (name == JOpera::SAME_AS_INPUT())
166 h3 = (
TH2*) h1->Clone(h1->GetName());
167 else
168 h3 = (
TH2*) h1->Clone(name.c_str());
169
170 if (
opera == JOpera::Add()) {
171
173
174 }
else if (
opera == JOpera::Subtract()) {
175
177
178 }
else if (
opera == JOpera::Multiply()) {
179
181
182 }
else if (
opera == JOpera::Divide()) {
183
185
186 }
else if (
opera == JOpera::Replace()) {
187
189 h3->Fill(0.0, 0.0, 0.0);
191 }
192
194
197
199
200 if (name == JOpera::SAME_AS_OPERATION())
202 else if (name == JOpera::SAME_AS_INPUT())
203 h3 = (
TH2*) h1->Clone(h1->GetName());
204 else
205 h3 = (
TH2*) h1->Clone(name.c_str());
206
207 if (
opera == JOpera::Add()) {
208
209 h3->Add (h1, h2, +1.0, +1.0);
210
211 }
else if (
opera == JOpera::Subtract()) {
212
213 h3->Add (h1, h2, +1.0, -1.0);
214
215 }
else if (
opera == JOpera::Multiply()) {
216
217 h3->Multiply(h1, h2, +1.0, +1.0);
218
219 }
else if (
opera == JOpera::Divide()) {
220
221 h3->Divide (h1, h2, +1.0, +1.0);
222
223 }
else if (
opera == JOpera::add() ||
224 opera == JOpera::subtract() ||
225 opera == JOpera::multiply() ||
226 opera == JOpera::divide()) {
227
230
231 const Double_t x = h1->GetXaxis()->GetBinCenter(
i1);
232 const Double_t y = h1->GetYaxis()->GetBinCenter(
i2);
233
234 const Int_t j1 = h2->GetXaxis()->FindBin(x);
235 const Int_t j2 = h2->GetYaxis()->FindBin(y);
236
239
241
242 if (
opera == JOpera::add()) {
243
245
246 }
else if (
opera == JOpera::subtract()) {
247
249
250 }
else if (
opera == JOpera::multiply()) {
251
253
254 }
else if (
opera == JOpera::divide()) {
255
256 if (w2 == 0.0) {
257 ERROR(
"Bin " << h2->GetName() <<
"[" <<
j1 <<
"," <<
j2 <<
"] empty." <<
endl);
258 continue;
259 }
260
262 }
263
265 }
266 }
267
268 }
else if (
opera == JOpera::efficiency() ||
269 opera == JOpera::stdev() ||
270 opera == JOpera::sqrt()) {
271
274
277
280
283
284 if (
opera == JOpera::efficiency()) {
285
286 if (y2 == 0.0) {
287 ERROR(
"Bin " << h2->GetName() <<
"[" <<
i1 <<
"," <<
i2 <<
"] empty." <<
endl);
288 continue;
289 }
290
292
293 if (y1 != 0.0 &&
294 y2 != 0.0) {
295
296 w1 /= y1;
297 w2 /= y2;
298
299 w3 =
y3 * fabs(
y3 - 1.0) * sqrt(w1*w1 + w2*w2);
300 }
301
302 }
else if (
opera == JOpera::stdev()) {
303
304 w3 = sqrt(w1*w1 + w2*w2);
305
309 }
310
311 }
else if (
opera == JOpera::sqrt()) {
312
313 y3 = (y1+y2) * (y1-y2);
314
317 else
319
321 }
322
325 }
326 }
327 }
328
329 }
else if (
opera == JOpera::Add() ||
330 opera == JOpera::Multiply()) {
331
333
334 TH2* h1 =
dynamic_cast<TH2*
>(*i);
335
337
339
340 if (name == JOpera::SAME_AS_OPERATION())
342 else if (name == JOpera::SAME_AS_INPUT())
343 h3 = (
TH2*) h1->Clone(h1->GetName());
344 else
345 h3 = (
TH2*) h1->Clone(name.c_str());
346
347 } else {
348
349 if (
opera == JOpera::Add()) {
350
351 h3->Add (
h3, h1, +1.0, +1.0);
352
353 }
else if (
opera == JOpera::Multiply()) {
354
355 h3->Multiply(
h3, h1, +1.0, +1.0);
356 }
357 }
358 }
359
360 } else {
361
363 }
364
366
368
370
371 out.Write();
372 out.Close();
373 }
374}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Template definition of a multi-dimensional oscillation probability interpolation table.
Utility class to parse command line options.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).