TEfficiency TH2 coloring

Hello everyone,
I made an efficiency map, a TH2 with TEfficiency::CreateHistogram(), using two existing TH2 (the “passed” one and the “total” one). I just wanted to ask how can I make the empty bins white (the ones where no entries are found in both passed and total histograms) and the bins with value 0 (so efficiency equals to 0) of blue color (as show in the COLZ palette), because there is no distinction between them, both these categories are drawn in white. I tried h2->SetMinimum(-0.1) but this affects both categories, not only the efficiency 0 one.
Here I am reporting an example code:

void tefficiency2D(){
  const int nbinsx = 5;
  const int nbinsy = 5;
  TH2D *hpassed = new TH2D("hpassed","Passed histograms",nbinsx,0,5,nbinsy,0,5);
  TH2D *hall = new TH2D("hall","All histograms",nbinsx,0,5,nbinsy,0,5);
  //filling histograms
  for (int ibinx = 1; ibinx <= nbinsx;ibinx++){
    for (int ibiny = 1; ibiny <= nbinsy; ibiny++){
      if (ibiny < 3) hpassed->SetBinContent(ibinx,ibiny,5);
      if(ibiny < 4) hall->SetBinContent(ibinx,ibiny,10);
  //plotting efficiency
  TEfficiency *heff = new TEfficiency(*hpassed,*hall);
  TH2* th2 = heff->CreateHistogram();
  TCanvas *c = new TCanvas();

ROOT version = 6.26/00
Kind Regards,

1 Like

It is explained here. => COLZ1

1 Like

Hello @couet , thanks for replying!
This unfortunately doesn’t solve my problem because I need to distinguish 0/n bins (so a bin with no counts in it) from 0/0 bins (so a bin in which neither passed histogram nor total histogram have entries in it). The solution you gave doesn’t draw neither of such cases.

@couet I guess the question is if there is a way to distinguish bins with “hpassed=hall=0” from bins with “hpassed=0” and “hall>0”. So, it’s probably a question to @moneta

1 Like

@Wile_E_Coyote Exactly!

I see. I was answering at the painting level. There is only 3 possible options for “COL”.
COL, COL0, COL1. At painting time we do not know how the histogram drawn was generated. We can just see if a bin is empty or not and act accordingly depending which option is used. “passed” and “hall” are unknown. Yes that’s may be more for @moneta.

1 Like

Actually, a TEfficiency keeps private copies of “hpassed" and “hall”.
So, maybe one should make a distinction between bins with “hpassed_bin_content=hpassed_bin_error=hall_bin_content=hall_bin_error=0” (i.e., “empty bins” only when the contents and the error are both zero) and bins for which any of “hpassed_bin_content”, “hpassed_bin_error”, “hall_bin_content”, “hall_bin_error” is nonzero.

Dear all,

a “quick and dirty” fix I found at least for the coloring.


  • Set for the histogram to be drawn a negative mininum;
  • Check the bins corresponding to hall==0;
  • Set their values to less than the minimum, ensures them not to be drawn.

Instead 0/n values are drawn with colour matching 0.

Best regards,
tefficiency2D.C (882 Bytes)

1 Like

Thanks @antonio.iuliano2 , this fixed the problem.
Hopefully a proper method in the TEfficiency class will be implemented.
Thanks a lot to all.

Best Regards,

Note that this “brutal fix” modifies the TEfficiency contents, so you should not use it for any calculations later.
Maybe you would first want to make a “clone” of the TEfficiency, just for drawing purposes.