Problem with logarithmic X/Y axes with TNtuple

Hi,

As a simple example some times ago, i’m trying to plot 3 sets of data using TNtuple with a logarithmic axis, either x or y.
The problem is that with “SetLogx(1)” or “SetLogy(1)”, i can’t see all points since i can’t fix the log scale myself, and i don’t see a solution actually.

Below one simple example :

#include <TStyle.h>
#include <TCanvas.h>
#include <TNtuple.h>
{
TNtuple* nt = new TNtuple("nt","","a:b:c");
TCanvas *Can = new TCanvas("Can","",200,10,600,400);

Double_t x[16] =  {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 0.00020, 500000.55,
      20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double_t x3, y3, z3;

for(Int_t h1 =0;h1<16;++h1)
{
x3 = x[h1];
y3 = y[h1];
z3 = z[h1]; nt->Fill(x3,y3,z3);
}
gPad->SetLogy(1);
Can->SetTickx(1);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
nt->SetMarkerStyle(20);
nt->SetMarkerSize(1);
nt->Draw("b:a:c","c","colz");
}

In log scale, i can’t see points xith x<1 here.

Any suggestions ?

Thanks

May be something like that would help:

{
TNtuple* nt = new TNtuple("nt","","a:b:c");
TCanvas *Can = new TCanvas("Can","Can",200,10,600,400);

Double_t x[16] =  {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
      20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 0.00020, 500000.55,
      20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double_t x3, y3, z3;

for(Int_t h1 =0;h1<16;++h1)
{
x3 = x[h1];
y3 = y[h1];
z3 = z[h1]; nt->Fill(x3,y3,z3);
}
Can->SetTickx(1);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
nt->SetMarkerStyle(20);
nt->SetMarkerSize(1);
nt->Draw("b:a:c>>h(100,0.01,22,100,0.01,22)","","col ");
gPad->SetLogx(1);

}

thanks, but i don’t really understand the use of “nt->Draw(“b:a:c>>h(100,0.01,22,100,0.01,22)”,”","col “);” :

Actually i understand that the fourth “h” command, here 100, is xmax - xmin (i tried others values to get it), but i don’t understand the others, especially if i want to use log scale on y axis.

Search for “>>” in http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch12s20.html#d5e17157 and in http://root.cern.ch/root/html/TTree.html#TTree:Draw@2

OK i see now, but the problem with this code

nt->Draw("b:a:c>>h(100,0.01,22,100,0.01,22)","","col ");

is that it just fix x and color axes, but not y axis (“b”).
To be able to have logarithmic y axis, i tried for instance

nt->Draw("b:a:c>>h(10,0.01,1,100,0.01,22,100,0.01,22)","","colz");

but the result is completely wrong : is there a possibility to improve this function ?

Thanks

In order to get “logarithmic y axis”, simply add “gPad->SetLogy(1);” in the end of Olivier’s example (right after “gPad->SetLogx(1);”).

Try this: [code]{
TNtuple* nt = new TNtuple(“nt”,"",“a:b:c”);
TCanvas *Can = new TCanvas(“Can”,“Can”,200,10,600,400);

Double_t x[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t y[16] = {1.00, 2.00, 6.00, 7.00, 3.00, 10.00, 0.20, 5.55,
20.50, 9.75, 1.50, 8.00, 5.00, 0.95, 3.85, 8.70};
Double_t z[16] = {0.001, 2.50, 600.00, 0.00001, 30.00, 10.001, 300000.0, 500000.55,
20.50, 9.75, 280000.50, 8.00, 5.00, 0.95, 3.85, 8.70};

Double_t x3, y3, z3;

for(Int_t h1 =0;h1<16;++h1)
{
x3 = x[h1];
y3 = y[h1];
z3 = z[h1]; nt->Fill(x3,y3,z3);
}
Can->SetTickx(1);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
nt->SetMarkerStyle(20);
nt->SetMarkerSize(1);

#if 0 /* 0 or 1 /
Double_t xmin = 0.01, xmax = 50, ymin = 0.01, ymax = 50;
#else /
0 or 1 */
nt->SetEstimate(nt->GetEntries() + 1);
Double_t xmin = nt->GetMinimum(“a”); // “a” is X in the nt->Draw below
Double_t xmax = nt->GetMaximum(“a”);
Double_t ymin = nt->GetMinimum(“b”); // “b” is Y in the nt->Draw below
Double_t ymax = nt->GetMaximum(“b”);
xmin *= ((xmin < 0.0) ? 1.000001 : 0.999999);
xmax *= ((xmax < 0.0) ? 0.999999 : 1.000001);
ymin *= ((ymin < 0.0) ? 1.000001 : 0.999999);
ymax = ((ymax < 0.0) ? 0.999999 : 1.000001);
#endif /
0 or 1 */

// http://root.cern.ch/root/html/TTree.html#TTree:Draw@2
#if 1 /* 0 or 1 */
TH2F h = new TH2F(“h”, “h”, 100, xmin, xmax, 100, ymin, ymax);
nt->Draw(“b:a:c>>h”, “”, “colz”); // warning: TTree::Draw destroys “h”
// gPad->Modified(); gPad->Update();
h->GetXaxis()->SetLimits(xmin, xmax); // restore proper “h” X axis limits
h->GetYaxis()->SetLimits(ymin, ymax); // restore proper “h” Y axis limits
#else /
0 or 1 */
nt->Draw(“b:a:c”, “”, “colz”); // note: TTree::Draw creates a “htemp”
// gPad->Modified(); gPad->Update();
// TH2F *htemp = ((TH2F )(gPad->GetPrimitive(“htemp”)));
htemp->GetXaxis()->SetLimits(xmin, xmax); // set proper “htemp” X axis limits
htemp->GetYaxis()->SetLimits(ymin, ymax); // set proper “htemp” Y axis limits
#endif /
0 or 1 */

gPad->SetLogx(1);
gPad->SetLogy(1);
// gPad->Modified(); gPad->Update();
}[/code] Note: the TTree::Draw method unconditionally deletes the “original” histogram “h”, regardless whether one says “b:a:c>>h” or “b:a:c>>+h”. The X and Y “numbers of bins” of the histogram will be set to 20 (instead of the original 100). What’s more important, it also changes the X and the Y axes limits of the histogram (it calculates them automatically, without any respect for the “original” settings). As a result, in case one uses logarithmic axes, NOT ALL POINTS ARE DRAWN (and one gets NO WARNING that parts of ones histogram are removed from the picture). Once one “manually” restores proper X and Y axes limits, one should see all points (unless there are “additional” points outside of these limits, of course).

Thanks ! It works very well !