52 int main(
int argc, 
char **argv)
 
   65     JParser<> zap(
"Auxiliary program for histogram operations.");
 
   67     zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
   82                                                   << 
"\n\"" << JOpera::SAME_AS_OPERATION() << 
"\" -> same as operation; or" 
   83                                                   << 
"\n\"" << JOpera::SAME_AS_INPUT()     << 
"\" -> same as input; else" 
   84                                                   << 
"\nas specified")) = JOpera::SAME_AS_OPERATION();
 
   89   catch(
const exception &error) {
 
   90     FATAL(error.what() << endl);
 
   98     DEBUG(
"Input: " << *input << endl);
 
  103       ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
  107     const TRegexp regexp(input->getObjectName());
 
  109     TIter iter(dir->GetListOfKeys());
 
  111     for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
  113       const TString tag(key->GetName());
 
  115       DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
  119       if (tag.Contains(regexp)) {
 
  123         if (dynamic_cast<TH1*>(p) == NULL) {
 
  124           FATAL(
"Object " << p->GetName() << 
" not compatible with histogram operations." << endl);
 
  127         listOfObjects.push_back(p);
 
  135   if        (listOfObjects.size() == 0) {
 
  137     FATAL(
"Number of histograms " << listOfObjects.size() << 
" = 0." << endl);
 
  139   } 
else if (listOfObjects.size() == 1 && (opera == JOpera::Add()      ||
 
  140                                            opera == JOpera::Subtract() ||
 
  141                                            opera == JOpera::Multiply() ||
 
  142                                            opera == JOpera::Divide())) {
 
  146     TH1* h1 = dynamic_cast<TH1*>(listOfObjects[0]);
 
  147     TF1* f1 = (TF1*) h1->GetListOfFunctions()->First();
 
  150       FATAL(h1->GetName() << 
" has no associated function." << endl);
 
  153     NOTICE(h1->GetName() << 
' ' << opera << 
' ' << f1->GetName() << endl);
 
  155     if      (name == JOpera::SAME_AS_OPERATION())
 
  156       h3 = (TH1*) h1->Clone(opera.c_str());
 
  157     else if (name == JOpera::SAME_AS_INPUT())
 
  158       h3 = (TH1*) h1->Clone(h1->GetName());
 
  160       h3 = (TH1*) h1->Clone(name.c_str());
 
  162     if        (opera == JOpera::Add()) {
 
  166     } 
else if (opera == JOpera::Subtract()) {
 
  170     } 
else if (opera == JOpera::Multiply()) {
 
  174     } 
else if (opera == JOpera::Divide()) {
 
  179   } 
else if (listOfObjects.size() == 2) {
 
  183     TH1* h1 = dynamic_cast<TH1*>(listOfObjects[0]);
 
  184     TH1* h2 = dynamic_cast<TH1*>(listOfObjects[1]);
 
  186     NOTICE(h1->GetName() << 
' ' << opera << 
' ' << h2->GetName() << endl);
 
  188     if      (name == JOpera::SAME_AS_OPERATION())
 
  189       h3 = (TH1*) h1->Clone(opera.c_str());
 
  190     else if (name == JOpera::SAME_AS_INPUT())
 
  191       h3 = (TH1*) h1->Clone(h1->GetName());
 
  193       h3 = (TH1*) h1->Clone(name.c_str());
 
  195     if        (opera == JOpera::Add()) {
 
  197       h3->Add     (h1, h2, +1.0, +1.0);
 
  199     } 
else if (opera == JOpera::Subtract()) {
 
  201       h3->Add     (h1, h2, +1.0, -1.0);
 
  203     } 
else if (opera == JOpera::Multiply()) {
 
  205       h3->Multiply(h1, h2, +1.0, +1.0);
 
  207     } 
else if (opera == JOpera::Divide()) {
 
  209       h3->Divide  (h1, h2, +1.0, +1.0);
 
  211     } 
else if (opera == JOpera::add()       ||
 
  212                opera == JOpera::subtract()  ||
 
  213                opera == JOpera::multiply()  ||
 
  214                opera == JOpera::divide()) {
 
  216       for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
 
  218         const Double_t x  = h1->GetBinCenter (i);
 
  219         const Double_t w1 = h1->GetBinContent(i);
 
  221         const Int_t    
j  = h2->FindBin(x);
 
  222         const Double_t w2 = h2->GetBinContent(
j);
 
  226         if        (opera == JOpera::add()) {
 
  230         } 
else if (opera == JOpera::subtract()) {
 
  234         } 
else if (opera == JOpera::multiply()) {
 
  238         } 
else if (opera == JOpera::divide()) {
 
  241             ERROR(
"Bin " << h2->GetName() << 
"[" << 
j << 
"] empty." << endl);
 
  248         h3->SetBinContent(i, w3);
 
  251     } 
else if (opera == JOpera::efficiency() ||
 
  252                opera == JOpera::stdev()      ||
 
  253                opera == JOpera::sqrt()) {
 
  255       for (Int_t i = 1; i <= h1->GetNbinsX(); ++i) {
 
  257         const Double_t y1 = h1->GetBinContent(i);
 
  258         const Double_t y2 = h2->GetBinContent(i);
 
  260         Double_t w1 = h1->GetBinError(i);
 
  261         Double_t w2 = h2->GetBinError(i);
 
  266         if        (opera == JOpera::efficiency()) {
 
  269             ERROR(
"Bin " << h2->GetName() << 
"[" << i << 
"] empty." << endl);
 
  281             w3  = y3 * fabs(y3 - 1.0) * sqrt(w1*w1 + w2*w2);
 
  284         } 
else if (opera == JOpera::stdev()) {
 
  286           w3 = sqrt(w1*w1 + w2*w2);
 
  293         } 
else if (opera == JOpera::sqrt()) {
 
  295           y3 = (y1+y2) * (y1-y2);
 
  305         h3->SetBinContent(i, y3);
 
  306         h3->SetBinError  (i, w3);
 
  310   } 
else if (opera == JOpera::Add()      ||
 
  311              opera == JOpera::Multiply()) {
 
  317       TH1* h1 = dynamic_cast<TH1*>(*i);
 
  319       NOTICE(h1->GetName() << 
' ' << opera << endl);
 
  323         if      (name == JOpera::SAME_AS_OPERATION())
 
  324           h3 = (TH1*) h1->Clone(opera.c_str());
 
  325         else if (name == JOpera::SAME_AS_INPUT())
 
  326           h3 = (TH1*) h1->Clone(h1->GetName());
 
  328           h3 = (TH1*) h1->Clone(name.c_str());
 
  332         if        (opera == JOpera::Add()) {
 
  334           h3->Add     (h3, h1, +1.0, +1.0);
 
  336         } 
else if (opera == JOpera::Multiply()) {
 
  338           h3->Multiply(h3, h1, +1.0, +1.0);
 
  345     FATAL(
"Incompatible number of histograms " << listOfObjects.size() << 
" with option " << opera << endl);