Re: Problems with a simple example

Rene Brun (Rene.Brun@cern.ch)
Thu, 16 Oct 1997 17:11:54 +0200


Pablo P Yepes wrote:
>
> I want to plot the temperature of the Universe as a function of age. I took the graph.c macro from the tutorials area and modified. The result is this:
>

Force the minimum along y (see modified macro below).
The current algorithm to compute the graph range tries to optimize
the y range starting at 0 (OK for linear scale), but forget
about the log scale.
I will modify the algorithm.

Rene Brun

{
> //
> // To see the output of this macro, click begin_h
> re</a>. end_html
> //
> gROOT->Reset();
> c1 = new TCanvas("c1","Temperature of the Univers
>
> c1->SetFillColor(42);
> c1->SetGridx();
> c1->SetGridy();
> c1->GetFrame()->SetFillColor(21);
> c1->GetFrame()->SetBorderSize(12);
> c1->SetLogx() ;
> // c1->SetLogy() ;
>
> Int_t n = 27;
> Float_t x[n], y[n];
> Float_t xx = 1.e-9 ;
> Float_t yy ;
> printf(" x = %f \n",xx);
> for (Int_t i=0;i<n;i++) {
> xx = xx * 10. ;
> x[i] = xx ;
> float xxx = log10(xx);
> float yyy = exp(15 - (14./27.) * (xxx+9)) ;
> y[i] = 15 - (14./27.) * (xxx+9) ;
> printf(" i %i Time %6.2e Temp %6.2e \n",i, x[i],y[i]);
> }
> gr = new TGraph(n,x,y);
> gr->SetFillColor(19);
> gr->SetLineColor(2);
> gr->SetLineWidth(4);
gr->SetMinimum(0.1); // force minimum along y
> gr->Draw("ACP");
>
> //Add axis titles.
> //A graph is drawn using the services of the TH1F histogram class.
> //The histogram is created by TGraph::Paint.
> //TGraph::Paint is called by TCanvas::Update. This function is called by defau
> t
> //when typing <CR> at the keyboard. In a macro, one must force TCanvas::Update
>
> c1->Update();
> gr->GetHistogram()->SetXTitle("Log Time after the Big Bang (seconds)");
> gr->GetHistogram()->SetYTitle("Log Temperature (Degrees Kelvin)");
> }
>
> I have two problems:
>
> 1) if I use the c1->Setlogy(). I get an error because some of the values are negative or zero. I don't see why because all the y values are >0.
> 2) if I don't use the Setlogy() option, the plot only cover the x range ~10^16-10^18.
>
> Thank you,
> Pablo Yepes
> Rice U