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<TH3*
>(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 = (
TH3*) h1->Clone(h1->GetName());
167 else
168 h3 = (
TH3*) 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 = (
TH3*) h1->Clone(h1->GetName());
204 else
205 h3 = (
TH3*) 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
231
232 const Double_t x = h1->GetXaxis()->GetBinCenter(
i1);
233 const Double_t y = h1->GetYaxis()->GetBinCenter(
i2);
234 const Double_t z = h1->GetZaxis()->GetBinCenter(
i3);
235
236 const Int_t j1 = h2->GetXaxis()->FindBin(x);
237 const Int_t j2 = h2->GetYaxis()->FindBin(y);
238 const Int_t j3 = h2->GetYaxis()->FindBin(z);
239
242
244
245 if (
opera == JOpera::add()) {
246
248
249 }
else if (
opera == JOpera::subtract()) {
250
252
253 }
else if (
opera == JOpera::multiply()) {
254
256
257 }
else if (
opera == JOpera::divide()) {
258
259 if (w2 == 0.0) {
260 ERROR(
"Bin " << h2->GetName() <<
"[" <<
j1 <<
"," <<
j2 <<
"] empty." <<
endl);
261 continue;
262 }
263
265 }
266
268 }
269 }
270 }
271
272 }
else if (
opera == JOpera::efficiency() ||
273 opera == JOpera::stdev() ||
274 opera == JOpera::sqrt()) {
275
279
282
285
288
289 if (
opera == JOpera::efficiency()) {
290
291 if (y2 == 0.0) {
292 ERROR(
"Bin " << h2->GetName() <<
"[" <<
i1 <<
"," <<
i2 <<
"] empty." <<
endl);
293 continue;
294 }
295
297
298 if (y1 != 0.0 &&
299 y2 != 0.0) {
300
301 w1 /= y1;
302 w2 /= y2;
303
304 w3 =
y3 * fabs(
y3 - 1.0) * sqrt(w1*w1 + w2*w2);
305 }
306
307 }
else if (
opera == JOpera::stdev()) {
308
309 w3 = sqrt(w1*w1 + w2*w2);
310
314 }
315
316 }
else if (
opera == JOpera::sqrt()) {
317
318 y3 = (y1+y2) * (y1-y2);
319
322 else
324
326 }
327
330 }
331 }
332 }
333 }
334
335 }
else if (
opera == JOpera::Add() ||
336 opera == JOpera::Multiply()) {
337
339
340 TH3* h1 =
dynamic_cast<TH3*
>(*i);
341
343
345
346 if (name == JOpera::SAME_AS_OPERATION())
348 else if (name == JOpera::SAME_AS_INPUT())
349 h3 = (
TH3*) h1->Clone(h1->GetName());
350 else
351 h3 = (
TH3*) h1->Clone(name.c_str());
352
353 } else {
354
355 if (
opera == JOpera::Add()) {
356
357 h3->Add (
h3, h1, +1.0, +1.0);
358
359 }
else if (
opera == JOpera::Multiply()) {
360
361 h3->Multiply(
h3, h1, +1.0, +1.0);
362 }
363 }
364 }
365
366 } else {
367
369 }
370
372
374
376
377 out.Write();
378 out.Close();
379 }
380}
#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).