# Problem with logarithmic X/Y axes with TNtuple

**URL:** <https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497>\
**Category:** ROOT\
**Created:** [June 28, 2012, 6:02pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497 "2012-06-28T18:02:34Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [July 2, 2012, 12:43pm UTC](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/7 "2012-07-02T12:43:49Z")

</div>

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](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).

---

_[View the full topic](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497)._
