TGraphAsymmErrors::Divide gives error passed>total

Hi all, I am trying to divide two histograms using TGraphAsymmErrors::Divide , but I get the following error message:

Info in TROOT::TEfficiency::CheckEntries: Histograms are not consistent: passed bin content > total bin content
Error in TROOT::TEfficiency::CheckConsistency: passed TEfficiency objects do not have consistent bin contents
Error in TGraphAsymmErrors::Divide: passed histograms are not consistent

However, if I then swap the places of my two histograms (so that my passed one becomes my total one) I still get the same error message, so first it says that histogram A > histogram B, and then it says that histogram B > histogram A, so Iā€™m not sure what is going wrong here.

#include "TFile.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TMultiGraph.h"
#include "TGraphAsymmErrors.h"
#include "TString.h"
#include <vector>
#include <iostream>

void function (){
  auto f1 = new TFile ("HaddOutput_1.root");
  auto f2 = new TFile ("HaddOutput.root");
  
  TH1D *histo = (TH1D*)f1->Get("AfterCuts/yCut_0.6/pT1Cut_0/pT2Cut_0/LeadingJetPt");
 
  std::vector<std::string> TriggerCut = {"L1_J20", "L1_J40", "L1_J50", "L1_J100"};
  std::vector<int> mjjCut = {141, 215, 247, 414};
  
  int n1 = TriggerCut.size();
  int n2 = mjjCut.size();
  
   TCanvas *c = new TCanvas("c", " ",1000, 1000);
   c->Divide(2, 2);
   c->SetGrid();

  TH1D *h[n1][n2];
  TMultiGraph *mg[n1];
  TGraphAsymmErrors *eff[n1][n2];
  
  for (int i = 0; i < n1; i++) {
    std::cout << i << std::endl;
    c->cd(i + 1);
    mg[i] = new TMultiGraph();

    for (int j = 0; j < n2; j++) {  
      if (j != i) continue;
      std::cout << j << std::endl;

      f2->GetObject(TString::Format("%s/yCut_0.6/pT1Cut_0/pT2Cut_0/mjjCut_%d/LeadingJetPt", TriggerCut[i].c_str(), mjjCut[j]), h[i][j]);
 
     eff[i][j] = new TGraphAsymmErrors();
     eff[i][j]->Divide(h[i][j], histo); // h[i][j] should be a subset of History
     mg[i]->Add(eff[i][j], "p");     

    }
     mg[i]->Draw("AL");
  }
     
  c->cd(0);
}

Hi,

As explained in the doc, https://root.cern.ch/doc/master/classTGraphAsymmErrors.html#a37a202762b286cf4c7f5d34046be8c0b

the Divide function can be used in two caused:

  1. the passed histogram is a subset of total (binomial case). Then here all bins of passed have to be <= of all bins of total. This is the default case
  2. Division of two independent histogram (Poisson ratio). Here the two histogram can have lower or higher bins as I think is in your case. For using this case you need to use th option "pois"

Best regards

Lorenzo

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.