59int main(
int argc,
char **argv)
72 JParser<> zap(
"Auxiliary program for histogram operations.");
74 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
90 <<
"\n\t\"" << JOpera::SAME_AS_OPERATION() <<
"\" -> same as operation; or"
91 <<
"\n\t\"" << JOpera::SAME_AS_INPUT() <<
"\" -> same as input; else"
92 <<
"\n\t as specified") = JOpera::SAME_AS_OPERATION();
97 catch(
const exception &error) {
111 ERROR(
"File: " << input->getFullFilename() <<
" not opened." <<
endl);
121 const TString tag(key->GetName());
127 if (tag.Contains(
regexp) && isTObject(key)) {
133 p = q->ProjectionX();
136 if (
dynamic_cast<TH1*
>(p) ==
NULL) {
137 FATAL(
"Object " << p->GetName() <<
" not compatible with histogram operations." <<
endl);
153 opera == JOpera::Subtract() ||
154 opera == JOpera::Multiply() ||
155 opera == JOpera::Divide() ||
156 opera == JOpera::Replace())) {
161 TF1* f1 = (TF1*) h1->GetListOfFunctions()->First();
164 FATAL(h1->GetName() <<
" has no associated function." <<
endl);
169 if (name == JOpera::SAME_AS_OPERATION())
171 else if (name == JOpera::SAME_AS_INPUT())
172 h3 = (
TH1*) h1->Clone(h1->GetName());
174 h3 = (
TH1*) h1->Clone(name.c_str());
176 if (
opera == JOpera::Add()) {
180 }
else if (
opera == JOpera::Subtract()) {
184 }
else if (
opera == JOpera::Multiply()) {
188 }
else if (
opera == JOpera::Divide()) {
192 }
else if (
opera == JOpera::Replace()) {
208 if (name == JOpera::SAME_AS_OPERATION())
210 else if (name == JOpera::SAME_AS_INPUT())
211 h3 = (
TH1*) h1->Clone(h1->GetName());
213 h3 = (
TH1*) h1->Clone(name.c_str());
215 if (
opera == JOpera::Add()) {
217 h3->Add (h1, h2, +1.0, +1.0);
219 }
else if (
opera == JOpera::Subtract()) {
221 h3->Add (h1, h2, +1.0, -1.0);
223 }
else if (
opera == JOpera::Multiply()) {
225 h3->Multiply(h1, h2, +1.0, +1.0);
227 }
else if (
opera == JOpera::Divide()) {
229 h3->Divide (h1, h2, +1.0, +1.0);
231 }
else if (
opera == JOpera::add() ||
232 opera == JOpera::subtract() ||
233 opera == JOpera::multiply() ||
234 opera == JOpera::divide()) {
236 for (
Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
238 const Double_t x = h1->GetBinCenter (i);
239 const Double_t w1 = h1->GetBinContent(i);
241 const Int_t j = h2->FindBin(x);
242 const Double_t w2 = h2->GetBinContent(j);
246 if (
opera == JOpera::add()) {
250 }
else if (
opera == JOpera::subtract()) {
254 }
else if (
opera == JOpera::multiply()) {
258 }
else if (
opera == JOpera::divide()) {
261 ERROR(
"Bin " << h2->GetName() <<
"[" << j <<
"] empty." <<
endl);
268 h3->SetBinContent(i,
w3);
271 }
else if (
opera == JOpera::efficiency() ||
272 opera == JOpera::stdev() ||
273 opera == JOpera::sqrt()) {
275 for (
Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
277 const Double_t y1 = h1->GetBinContent(i);
278 const Double_t y2 = h2->GetBinContent(i);
286 if (
opera == JOpera::efficiency()) {
289 ERROR(
"Bin " << h2->GetName() <<
"[" << i <<
"] empty." <<
endl);
301 w3 =
y3 * fabs(
y3 - 1.0) * sqrt(w1*w1 + w2*w2);
304 }
else if (
opera == JOpera::stdev()) {
306 w3 = sqrt(w1*w1 + w2*w2);
313 }
else if (
opera == JOpera::sqrt()) {
315 y3 = (y1+y2) * (y1-y2);
325 h3->SetBinContent(i,
y3);
326 h3->SetBinError (i,
w3);
330 }
else if (
opera == JOpera::Add() ||
331 opera == JOpera::Multiply()) {
337 TH1* h1 =
dynamic_cast<TH1*
>(*i);
343 if (name == JOpera::SAME_AS_OPERATION())
345 else if (name == JOpera::SAME_AS_INPUT())
346 h3 = (
TH1*) h1->Clone(h1->GetName());
348 h3 = (
TH1*) h1->Clone(name.c_str());
352 if (
opera == JOpera::Add()) {
354 h3->Add (
h3, h1, +1.0, +1.0);
356 }
else if (
opera == JOpera::Multiply()) {
358 h3->Multiply(
h3, h1, +1.0, +1.0);