Problem with logarithmic colz with TH2F

Hi rooters,

I am trying to plot a colz plot with a logarithmic z-axis. This should be easy, people keep telling me to use c->SetLogz(), yet this does not work.

What happens is that the scale along the z-axis becomes logarithmic like it should, yet the colours in the plot stay as they were… Not how it should be.

What I have is:

{
TCanvas *c8 = new TCanvas("c8","",w,h);

  //  gPad->SetLogz(1);
  gPad->SetGrid();
  myHistTotalCS("CS",7,10);
}

TH2F* myHistTotalCS(TString name , int Energy, int tanbeta)
{
  if (gSystem->AccessPathName("prosp.root")) {
  gROOT->ProcessLine(".x RootFileMaker.C");
   }
   TFile *f = new TFile("prosp.root");
   TNtuple *ntuple = (TNtuple*)f->Get("ntuple");
   if( gDirectory->Get(name) ) delete  gDirectory->Get(name);
   
   gStyle->SetPalette(1);
   ntuple->Draw("m12:m0:TotalCS>>h5",cutname,"colz");

   TH2F *h5 = (TH2F*)gDirectory->Get("h5");

   return h5;
   
}

Hope someone can help me, cheers!

I cannot run your example because there is files missing. So I did an example showing it is working.

{
   TCanvas *c8 = new TCanvas("c8","");
   c8->Divide(2,1);
   c8->cd(1);
   hpxpy->Draw("colz");
   c8->cd(2);
   gPad->SetLogz(1);
   hpxpy->Draw("colz");
}

hpxpy is an 2D histogram produced by $ROOTSYS/hsimple.C
I get the attached picture.


Thank you, but I tried this, using SetLogz(1), but somehow it did not work like in your example. I guess it might have something to do with how I fill the histogram?

Can you send a small example I can run ? this would really help to understand what is going wrong. Also, for completeness, I was running my example on a linux machine with the last ROOT version.

I sent you an email with everything attached!
I have tried on a linux SLC 4 machine and Mac, both with version 5.24

I am looking at it. Thanks.

The colz option is for 2D histograms. Here you do a 3D variables plot. The histogram
h5 is empty. What you see in you plot are big square markers not the
histograms bins.
To produce a correct 2D histogram you should use TotalCS as weight (not as
3rd variable). Something like:

   ntuple->Draw("m12:m0",TotalCS,"col");

Ok, that solved it, Thanks!

Apparently I cheered too soon… I thought it would work, yet now I am making these plots again, I see something is wrong.

Maybe I should have been more specific in what I wanted to plot… :slight_smile:
What I am trying to get is a grid in this m0, m12 space, where on every point/bin it gives the value of the cross-section (“TotalCS”).

If I do

I get just the histogram, saying how many data points I have at each point in my (m0, m12) space. Which is 1 for all points…

when you do a x:y:z plot as you did before, each variable is mapped on one axis. The colz value is not valid. With the solution I gave you it does exactly what you says ie: fill a 2D histogram for with the colz option is valid.
In a TTree drawing, only when you plot 4 variables the 4th one is mapped on color: x:y:z:t…
may be try x:y:z:z

You’re right of course :slight_smile:

But, what went wrong was that I tried to impose some cuts on it straight away, in this fashion:

   ntuple->Draw("m12:m0>>h5","TotalCS > 0 && Energy == 7", "colz");

When I do this, it does not understand I want to use TotalCS as a weight. Any idea how to do this coorectly?

By the way, I already saw that this solved my initial problem with the SetLogz(); this works now, cheers!

ntuple->Draw("m12:m0>>h5","TotalCS*(Energy == 7)", "colz"); 

Thanks! I should have thought of that myself.

Solved!