Re: [ROOT] Question

From: Olivier Couet (Olivier.Couet@cern.ch)
Date: Fri Mar 05 2004 - 17:37:27 MET


Ok, here it is:

{
   gROOT->Reset();                       

   ifstream data;                        
   data.open("led1.data");   

   const Int_t n = 100;                        
   Int_t in = 0;
   Float_t x[n], y1[n], y2[n], x1;

   while (data >> x1)
   {
      x[in] = x1;
      data >> y1[in];
      data >> y2[in];
      in++;
   }

   TGraph *inputSpec = new TGraph(in, x, y1);
   TGraph *inputSpec2 = new TGraph(in, x, y2);

   inputSpec->GetHistogram()->SetXTitle("X title");
   inputSpec->GetHistogram()->SetYTitle("Y title");

   TCanvas *c1 = new TCanvas("c1", "Intensity of LED 1",0,  0, 800, 600);
   c1->SetLogy();

   inputSpec->Draw("AC");
   gPad->Update();
   inputSpec2->Draw("CP");


   //draw an axis on the right side
   TGaxis *axis = new TGaxis(gPad->GetUxmax(),
                             gPad->GetUymin(),
                             gPad->GetUxmax(),
                             gPad->GetUymax(),
                             0,10,510,"+L");      

   axis->Draw();
}



On Fri, 5 Mar 2004, Marieke Navin wrote:

> Could you be a bit more explicit at all? I already have the graph.C and 
> twoscales.C but I cannot get the commands to work. Could you advise me as 
> to the modifications I need to do to this code for my own code? the 
> ->Getaxis()->SetTitle doesn't work for me at all. Additionally the two 
> scales is for histograms and I don't know how to modify this for my 
> graph.I have commented out the commands I have been trying.
> Thanks again in advance
> Marieke
> 
> 
> {
>   gROOT->Reset();                       // reset global variables
>   
>   gStyle->SetCanvasColor(10);
>   gStyle->SetTitleColor(10);
>   gStyle->SetFrameFillColor(10);
>   gStyle->SetOptStat(0);
>   
>   ifstream data;                        // declare a file to input from
>   data.open("led1.data");   // open file containing values
>   
>   const Int_t n = 100;                        // number of points to be plotted
>   Int_t in = 0;
> 
>   Float_t x[n], y1[n], y2[n];
>   Float_t x1;
> 
>   char line[1024];
>   while (data >> x1)
>     {
>       x[in] = x1;
>       data >> y1[in];
>       data >> y2[in];
>       in++;
>     }
> 
> 
>   for (Int_t i=0; i<in; i++)
>     {
>       cout << x[i] << " " << y1[i] << " " << y2[i] << endl;
>     }
>   
>   TGraph *inputSpec = new TGraph(in, x, y1);
>   TGraph *inputSpec2 = new TGraph(in, x, y2);
>   inputSpec->SetTitle("Intensity of LED 1");
>   // inputSpec2->GetXaxis()->SetTitle("Cos Theta");
>   // inputSpec->GetYaxis()->SetTitle("pJ/pulse/sr");
> 
>   TCanvas *c1 = new TCanvas("c1", "Intensity of LED 1",0,  0, 800, 600);  
>   c1->SetLogy();
>   
>   // trying to label x axis(doesnt work): inputspec->GetXaxis()->SetTitle("Cos Theta");
> 
>   //trying to draw axis on right here:
>   //c1->Range(-10,-1,10,1);  
>   // TGaxis *axis1 = new TGaxis(-9,-0.8,-9,0.8,0,1e5,50510,"");
>   //axis1->SetName("axis1");
>   //axis1->SetTitle("pJ/pulse/sr");
>   //axis1->Draw();
>   //TGaxis *axis2 = new TGaxis (7,-0.8,7,0.8,0,5e22,50510,"-G");
>   //axis2->SetName("axis2");
>   //axis2->SetTitle("number of photons/pulse/sr");
>   //axis2->Draw();
> 
>   //trying to label x axis here:
>   // TGaxis *axisx = new TGaxis();
>   //axisx->SetName("axisx");
>   //axisx->SetTitle("Cos Theta");
>   
> 
> 
>   inputSpec->Draw("AC");
>   inputSpec2->Draw("CP");
> }
> 
> 

-- 
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