30{
   33  
   37 
   38  try {
   39 
   40    JParser<> zap(
"Auxiliary program to determine standard deviation of a set of 1D histograms.");
 
   41 
   42    zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
   45 
   46    zap(argc, argv);
   47  }
   48  catch(const exception &error) {
   49    FATAL(error.what() << endl);
 
   50  }
   51 
   52 
   53  TH1* h3 = NULL;
   54  
   56 
   57  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
   58 
   59    DEBUG(
"Input: " << *input << endl);
 
   60 
   62 
   63    if (dir == NULL) {
   64      ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
   65      continue;
   66    }
   67 
   68    const TRegexp regexp(input->getObjectName());
   69 
   70    TIter iter(dir->GetListOfKeys());
   71 
   72    for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
   73 
   74      const TString tag(key->GetName());
   75 
   76      DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
   77 
   78      
   79 
   80      if (tag.Contains(regexp) && 
isTObject(key)) {
 
   81 
   83 
   84        if (!p->InheritsFrom("TH1")) {
   85          FATAL(
"Object " << p->GetName() << 
" not compatible with histogram operations." << endl);
 
   86        }
   87 
   88        if (h3 == NULL) {
   89 
   90          h3 = (TH1*) p->Clone("stdev");
   91          
   92        } else {
   93 
   94          TH1* h1 = (TH1*) p;
   95          
   96          if (h3->GetXaxis()->GetNbins() != h1->GetXaxis()->GetNbins() ||
   97              h3->GetXaxis()->GetXmin () != h1->GetXaxis()->GetXmin () ||
   98              h3->GetXaxis()->GetXmax () != h1->GetXaxis()->GetXmax ()) {
   99            FATAL(
"Objects " << h3->GetName() << 
" and " << p->GetName() << 
" have different binning." << endl);
 
  100          }
  101        }
  102 
  103        listOfHistograms.push_back((TH1*) p);
  104      }
  105    }
  106  }
  107 
  108  if (listOfHistograms.size() <= 1) {
  109    FATAL(
"Not enough histograms " << listOfHistograms.size() << endl);
 
  110  }
  111 
  112  for (Int_t i = 1; i <= h3->GetNbinsX(); ++i) {
  113 
  114    Double_t Y = 0.0;
  115    Double_t Z = 0.0;
  116 
  117    for (vector<TH1*>::const_iterator p = listOfHistograms.begin(); p != listOfHistograms.end(); ++p) {
  118      Y += (*p)->GetBinContent(i);
  119      Z += (*p)->GetBinError(i) * (*p)->GetBinError(i);
  120    }
  121 
  122    Z  = sqrt(Z);
  123    Y /= listOfHistograms.size();
  124    Z /= listOfHistograms.size();
  125 
  127    
  128    for (vector<TH1*>::const_iterator p = listOfHistograms.begin(); p != listOfHistograms.end(); ++p) {
  129      y += ((*p)->GetBinContent(i) - Y)*((*p)->GetBinContent(i) - Y) / ((*p)->GetBinError(i)*(*p)->GetBinError(i) + Z*Z);
 
  130    }
  131 
  132    y  = sqrt(y / listOfHistograms.size());
 
  133 
  134    h3->SetBinContent(i, y);
  135    h3->SetBinError  (i, 0.0);
  136  }
  137 
  138  if (h3 != NULL) {
  139 
  141    
  142    h3->Write();
  143    
  144    out.Write();
  145    out.Close();
  146  }
  147}
#define DEBUG(A)
Message macros.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
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).