THStack & TH2 with negative values

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


what do you mean with:

I meant I did this using this version of ROOT:

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{}

Oh ok … sorry :slight_smile: … so the latest root… :slight_smile:

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

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.

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

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

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.

Good point!
But in some cases it remains useful, see Locate like command
(The solution I use to do this properly consists in transforming my nm TH2s into partly empty xnm TH2s or xn*ym TH2s).
According to me, this feature is not worth discarding.
Cheers,
Z

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

[quote]The post you mentioned is not about negative stacks.[/quote]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

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.

[quote]I do not think we can assume that the stack will not pile up.[/quote]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