# TEfficiency TH2 coloring

**URL:** <https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [March 23, 2022, 10:22am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320 "2022-03-23T10:22:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcentanni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dcentanni/32/29230_2.png) [@dcentanni](https://root-forum.cern.ch/u/dcentanni)\
**Post date:** [March 23, 2022, 10:22am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/1 "2022-03-23T10:22:37Z")

</div>

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:

> **Code**
>
> ```auto
> 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();
> th2->SetMinimum(-1);
> th2->Draw("COLZ");
> }
> 
> ```

* * *

_ROOT version_ = 6.26/00  
Kind Regards,  
Daniele

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 23, 2022, 10:35am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/2 "2022-03-23T10:35:10Z")

</div>

It is explained [here](https://root.cern/doc/master/classTHistPainter.html#HP14). =\> COLZ1

---

<div class="post-metadata">

**Author:** ![dcentanni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dcentanni/32/29230_2.png) [@dcentanni](https://root-forum.cern.ch/u/dcentanni)\
**Post date:** [March 23, 2022, 10:46am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/3 "2022-03-23T10:46:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 23, 2022, 10:48am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/4 "2022-03-23T10:48:01Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![dcentanni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dcentanni/32/29230_2.png) [@dcentanni](https://root-forum.cern.ch/u/dcentanni)\
**Post date:** [March 23, 2022, 10:48am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/5 "2022-03-23T10:48:28Z")

</div>

@Wile_E_Coyote Exactly!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 23, 2022, 10:55am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/6 "2022-03-23T10:55:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 23, 2022, 11:26am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/7 "2022-03-23T11:26:20Z")

</div>

Actually, a [TEfficiency](https://root.cern/doc/master/classTEfficiency.html) 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.

---

<div class="post-metadata">

**Author:** ![antonio.iuliano2](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/antonio.iuliano2/32/24948_2.png) [@antonio.iuliano2](https://root-forum.cern.ch/u/antonio.iuliano2)\
**Post date:** [March 23, 2022, 11:48am UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/8 "2022-03-23T11:48:36Z")

</div>

Dear all,

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

First:

- 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,  
Antonio  
[tefficiency2D.C](https://root-forum.cern.ch/uploads/short-url/kDD2MCk0uqcqsjJFxxHIm95HX6T.C) (882 Bytes)

---

<div class="post-metadata">

**Author:** ![dcentanni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dcentanni/32/29230_2.png) [@dcentanni](https://root-forum.cern.ch/u/dcentanni)\
**Post date:** [March 23, 2022, 12:06pm UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/9 "2022-03-23T12:06:34Z")

</div>

Thanks @antonio.iuliano2 , this fixed the problem.  
Hopefully a proper method in the [TEfficiency](https://root.cern.ch/doc/master/classTEfficiency.html) class will be implemented.  
Thanks a lot to all.

Best Regards,  
Daniele

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 23, 2022, 12:16pm UTC](https://root-forum.cern.ch/t/tefficiency-th2-coloring/49320/10 "2022-03-23T12:16:27Z")

</div>

Note that this “brutal fix” modifies the [TEfficiency](https://root.cern/doc/master/classTEfficiency.html) contents, so you should not use it for any calculations later.  
Maybe you would first want to make a “clone” of the [TEfficiency](https://root.cern/doc/master/classTEfficiency.html), just for drawing purposes.
