Re: [ROOT] Length of axis divisions

From: Olivier Couet (Olivier.Couet@cern.ch)
Date: Thu Mar 18 2004 - 14:09:29 MET


Hi Andreas,

 Here is what you want:

void ticks()
{
   gROOT->Reset();
   TCanvas* c1 = new TCanvas("c1","Modulation");

   int NPoints = 360;
   TGraph* gr = new TGraph(NPoints);

   for (int i = 0; i < NPoints; ++i) {
     double x = i*360.0/NPoints;
     double y = 100 + 50*cos(2*x*TMath::Pi()/180);
     gr->SetPoint(i, x, y);
   }

   TH1F *h1 = new TH1F("a","a",1000,0,360);
   gr->SetHistogram(h1);
   gr->Draw("AC");
   c1->Update();

   gr->GetHistogram()->SetXTitle("Azimuthal scatter angle");
   gr->GetHistogram()->SetYTitle("Counts");
   gr->GetHistogram()->SetAxisRange(0, 200, "Y");
   gr->GetXaxis()->SetNdivisions(-504);
   c1->Modified();
}

Explanation: TGraph creates internally an histogram to draw the graph. 
That is the one you get when you do gr->GetHistogram(). That histogram has 
by default 100 bins. In your case a 100 precision is not enough and you 
see that "bin size effect". In this modified version of your macro I book 
an histogram with 1000 bins and give it to the TGraph using 
gr->SetHistogram. Having done that you do not need to set the X range of 
the TGraph.

 Cheers,       Olivier


On Wed, 17 Mar 2004, Andreas Zoglauer wrote:

> 
> Hi Olivier,
> 
> With your method I get 360.89 as upper limit - but I need exactly 360
> 
> Thanks for your help,
> Andreas
> 
> 
> 
> Olivier Couet wrote:
> > Hello,
> > 
> >  The way to do it would be:
> > 
> >    gr->GetHistogram()->SetAxisRange(0, 360, "X");   
> >    gr->GetHistogram()->SetAxisRange(0, 200, "Y");
> >    gr->GetXaxis()->SetNdivisions(-504);    
> > 
> >  a negative number of divisions meaning that the divisions should not be 
> > optimize. But doing that I do not get exactly 360 as upper limit... 
> > That's weird ... I'll investigate.
> 
> 
> 
> 
> 
> 

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet@cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7677155



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET