# THStack & TH2 with negative values

**URL:** <https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161>\
**Category:** ROOT\
**Created:** [May 29, 2013, 9:10pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161 "2013-05-29T21:10:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [May 29, 2013, 9:10pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/1 "2013-05-29T21:10:39Z")

</div>

Hi there,

TH2 with negative values don’t get properly displayed in THStack (trunk commit c666419d502ab2854a1c28c4b91c6c24dc25e098).

[code]{  
gStyle-\>SetHistMinimumZero(kTRUE) ;  
gStyle-\>SetTitleFontSize(0.10) ;

TH2D \* histo = new TH2D (“histo”,“histo”,3,-3.,3.,3,-3.,3.) ;  
histo-\>SetBinContent(1,1, 1.) ;  
histo-\>SetBinContent(1,2, 3.) ;  
histo-\>SetBinContent(1,3, 4.) ;  
histo-\>SetBinContent(2,1,-6.) ;  
histo-\>SetBinContent(2,2, 0.) ;  
histo-\>SetBinContent(2,3, 9.) ;  
histo-\>SetBinContent(3,1,-8.) ;  
histo-\>SetBinContent(3,2, 2.) ;  
histo-\>SetBinContent(3,3,-5.) ;  
histo-\>SetMinimum(-10.) ;  
histo-\>SetMaximum( 10.) ;  
histo-\>SetStats(kFALSE) ;  
histo-\>SetFillColor(kRed) ;  
histo-\>SetLineColor(kBlack) ;

THStack \* hstack = new THStack (“hstack”,“hstack”) ;  
hstack-\>Add(histo) ;  
hstack-\>SetMinimum(-10.) ;  
hstack-\>SetMaximum( 10.) ;

TCanvas \* canvas = new TCanvas (“canvas”) ;  
canvas-\>Divide(2,3) ;  
canvas-\>cd(1) ; histo -\>Draw(“lego ,fb”) ;  
canvas-\>cd(3) ; histo -\>Draw(“lego1,fb”) ;  
canvas-\>cd(5) ; histo -\>Draw(“lego2,fb”) ;  
canvas-\>cd(2) ; hstack-\>Draw(“lego ,fb”) ;  
canvas-\>cd(4) ; hstack-\>Draw(“lego1,fb”) ;  
canvas-\>cd(6) ; hstack-\>Draw(“lego2,fb”) ;  
}[/code]  
I guess it has something to do with the way Hoption.Zero is handled in TPainter3dAlgorithms::LegoCartesian().  
Could you please fix this?

Cheers,  
Z

 ![](https://root-forum.cern.ch/uploads/default/original/2X/6/68f2e6348a2db0922715ef5f3aebe84c6cf78ab2.png)

---

<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:** [May 30, 2013, 8:01am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/2 "2013-05-30T08:01:58Z")

</div>

what do you mean with:

> [@](#):
>
> (trunk commit c666419d502ab2854a1c28c4b91c6c24dc25e098).

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [May 30, 2013, 8:15am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/3 "2013-05-30T08:15:17Z")

</div>

I meant I did this using this version of ROOT:

```auto
git log
> commit c666419d502ab2854a1c28c4b91c6c24dc25e098
> Author: Olivier Couet <olivier.couet@cern.ch>
> Date: Wed May 29 17:18:14 2013 +0200
> 
> Generate index for A4 pdf. The index is filled via \index{}
```

---

<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:** [May 30, 2013, 8:17am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/4 "2013-05-30T08:17:39Z")

</div>

Oh ok … sorry 🙂 … so the latest root… 🙂

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [May 30, 2013, 8:22am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/5 "2013-05-30T08:22:21Z")

</div>

Yep but as you’re quite active (lots of commits from couet these last days), I prefered specifying the revision number 😉

---

<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:** [May 30, 2013, 8:25am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/6 "2013-05-30T08:25:28Z")

</div>

Thanks. Yes I am working on the User’s Guide. It is not affecting the code. I am doing one more thing for the doc and I’ll be back to your questions.

---

<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:** [May 30, 2013, 2:33pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/7 "2013-05-30T14:33:34Z")

</div>

> [@](#):
>
> I guess it has something to do with the way Hoption.Zero is handled in TPainter3dAlgorithms::LegoCartesian().

No, because in your example the option 0 is not used.

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [May 30, 2013, 4:33pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/8 "2013-05-30T16:33:17Z")

</div>

Stupid me! 😊  
Let’s say it was late…  
Good luck,  
Z

---

<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:** [May 31, 2013, 3:34pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/9 "2013-05-31T15:34:51Z")

</div>

In fact lego stack with negative content cannot work in the general case.  
Stacks are drawn by piling up bricks on top of each other. Imagine that  
we have a negative bricks in the middle … what do we do ?  
May be it should be documented a bit more.

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [May 31, 2013, 9:47pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/10 "2013-05-31T21:47:17Z")

</div>

Good point!  
But in some cases it remains useful, see [Locate like command](https://root-forum.cern.ch/t/locate-like-command/65/1)  
(The solution I use to do this properly consists in transforming my n_m TH2s into partly empty xn_m TH2s or xn\*ym TH2s).  
According to me, this feature is not worth discarding.  
Cheers,  
Z

---

<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:** [June 10, 2013, 6:23am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/11 "2013-06-10T06:23:06Z")

</div>

The post you mentioned is not about negative stacks. The way the stack algorithm is done do not allow negative contents.

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [June 10, 2013, 11:15am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/12 "2013-06-10T11:15:16Z")

</div>

> [@](#):
>
> The post you mentioned is not about negative stacks.

Indeed but it’s about stacks containing histograms that will never pile up (your (relevant) argument) and that can hold negative values. So in the end, that’s the same.

[quote]The way the stack algorithm is done do not allow negative contents.[/quote]For the time being, that’s for sure. But how about tomorrow?

Cheers,  
Z

---

<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:** [June 10, 2013, 11:19am UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/13 "2013-06-10T11:19:11Z")

</div>

Ah, ok so you assume that the histogram do not pile up. That’s a special case.  
I do not think we can assume that the stack will not pile up.

---

<div class="post-metadata">

**Author:** ![Zesp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/z/b5ac83/32.png) [@Zesp](https://root-forum.cern.ch/u/Zesp)\
**Post date:** [June 10, 2013, 7:47pm UTC](https://root-forum.cern.ch/t/thstack-th2-with-negative-values/16161/14 "2013-06-10T19:47:11Z")

</div>

> [@](#):
>
> I do not think we can assume that the stack will not pile up.

I agree. Still it is sometimes necessary to lego-plot several non piling up negative valued TH2s (see link above). THStack have been used so far for convenience. Maybe another object should be used or created (THNeighbors or whatever). Currently one can easily lego-plot a negative valued TH2 or multiple non piling up positive valued TH2s. So plotting multiple non piling up negative valued TH2s should not be a big deal and should be part of ROOT.  
Cheers,  
Z
