Re: [ROOT] Setting range on axis.

From: Olivier Couet (Olivier.Couet@cern.ch)
Date: Tue Mar 23 2004 - 16:41:33 MET


Hi Manoj,

The piece of code you are talking about is the following I guess:

TGraph *gr = new TGraph (nBINeta, x,y);
TH1F *h1 = new TH1F("h1","h1",nBINeta,1.5,1.9);
h1->SetMaximum(1);
h1->SetMinimum(0);
gr->SetHistogram(h1);
TAxis *axis = gr->GetXaxis();
axis->SetLimits(1.5,1.9);
gr->Draw("AC*");

I think you can remove the lines:

TAxis *axis = gr->GetXaxis();
axis->SetLimits(1.5,1.9);

as you set yourself the histogram. But this doesn't explain why you get 
that crash. Are you sure that nBINeta is always valid ? To book the 
histogram you can use a fixed value (100 for instance). Sorry to not help 
more but I cannot execute your macro which requires many files I do not 
have.

 Cheers,        OlivIer


On Tue, 23 Mar 2004, Manoj Jha wrote:

> Hi Oliver,
>     I followed your method. It is working. But, when I implementing in 
> the script "efficiency.C (line no. 147-170) ",  I faced with the 
> following error
> 
> ---------------------------------------------------------------------------------------------------------
> 
> [jha@dulinux2 test]$ root efficiency.C
> Warning in <Format>: string truncated: .:/cms/external/lcg/external/r...
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   3.10/01    8 October 2003   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
> 
> FreeType Engine v2.1.3 used to render TrueType fonts.
> Compiled for linux with thread support.
> 
> CINT/ROOT C/C++ Interpreter version 5.15.105, Sep 28 2003
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0]
> Processing efficiency.C...
> RTTI works locally ...
> Running on a Pentium
> 
> One clock tick corresponds to 3.846e-10 seconds
> COBRA/GenUtil initializing
> adding file /cms/Releases/COBRA/COBRA_7_5_0/src/Data/.cobrarc 1
> adding file /cms/Releases/COBRA/COBRA_7_5_0/src/Data/.orcarc 0
> adding file /cms/Releases/ORCA/ORCA_7_6_1/src/Data/.cobrarc 0
> adding file /cms/Releases/ORCA/ORCA_7_6_1/src/Data/.orcarc 1
> adding file /home/jha/program/orca/ORCA_7_6_1/src/Data/.cobrarc 0
> adding file /home/jha/program/orca/ORCA_7_6_1/src/Data/.orcarc 0
> adding file ./.cobrarc 0
> adding file ./.orcarc 0
> eta = 1.6 Bin_efficiency 1
> eta = 1.7 Bin_efficiency 0.915094
> <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> ======= END ======
> root [1]
>  *** Break *** segmentation violation
>  Generating stack trace...
>  0x40a4ca68 in TGraph::Paint(char const*) + 0x8c from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGraf.so
>  0x410d0ed0 in TPad::PaintModified() + 0x400 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
>  0x410b5e04 in TCanvas::Update() + 0x78 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGpad.so
>  0x413c4077 in TRootCanvas::HandleContainerConfigure(Event_t*) + 0x4f 
> from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x413c47e1 in TRootContainer::HandleConfigureNotify(Event_t*) + 0x3b 
> from /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x4136209c in TGFrame::HandleEvent(Event_t*) + 0x82 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x41345f7b in TGClient::HandleEvent(Event_t*) + 0xd7 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x41345c74 in TGClient::ProcessOneEvent() + 0x6e from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x41345cfe in TGClient::HandleInput() + 0x28 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x4134487a in TGInputHandler::Notify() + 0x22 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libGui.so
>  0x401c643e in TUnixSystem::DispatchOneEvent(bool) + 0x3a from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
>  0x401313b3 in TSystem::InnerLoop() + 0x25 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
>  0x40131341 in TSystem::Run() + 0x7b from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
>  0x400e19f6 in TApplication::Run(bool) + 0x30 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libCore.so
>  0x40e12bdb in TRint::Run(bool) + 0x311 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/lib/libRint.so
>  0x08048890 in main + 0x90 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/bin/root.exe
>  0x40f225d9 in __libc_start_main + 0x95 from /lib/libc.so.6
>  0x08048711 in _Unwind_Resume + 0x35 from 
> /cms/external/lcg/external/root/3.10.01/rh73_gcc32/bin/root.exe
> Root >
> -------------------------------------------------------------------------------------------------------------------------------------------------
> 
> Could you please enlighten me in this case ? Waiting for your response.
> 
> Thanks and with regards,
> manoj
> 
> 
> Olivier Couet wrote:
> 
> >Hello Manoj,
> >
> > Ah yes, it seems my way is better on the y axis :-) try:
> >
> >{
> >   Int_t n=20;
> >   Double_t x[n],y[n];
> >   for (Int_t i=0; i<n; i++) {
> >      x[i]=i*0.1;
> >      y[i]=10*sin(x[i]+0.2);
> >   }
> >   TGraph *gr1 = new TGraph (n,x,y);
> >   TH1F *h1 = new TH1F("","",100,0,5);
> >   h1->SetMaximum(9); 
> >   h1->SetMinimum(2); 
> >   gr1->SetHistogram(h1);
> >   TAxis *xaxis = gr1->GetXaxis();
> >   xaxis->SetLimits(0,5);
> >   gr1->Draw("AC*");
> >}
> >
> > Cheers,      Olivier
> >
> >
> >
> >On Tue, 23 Mar 2004, Manoj Jha wrote:
> >
> >  
> >
> >>Hi Oliver,
> >>       Thanks again. Rene answer worked. But, it is not working in the 
> >>script "efficiency.C" ( line no. 147-166). I have set the range of Y 
> >>axis from (0,1) in the script. In the plot, the range is from (0.90,1.0).
> >>
> >>Thanks and with regards,
> >>manoj
> >>
> >>
> >>Olivier Couet wrote:
> >>
> >>    
> >>
> >>>Hi Manoj,
> >>>
> >>>I answered you request before Rene's answer arrived. His answer is 
> >>>simpler. The  SetMaximum define the maximum of the histogram used by 
> >>>TGraph
> >>>
> >>>Cheers, Olivier
> >>>
> >>>
> >>>On Tue, 23 Mar 2004, Manoj Jha wrote:
> >>>
> >>> 
> >>>
> >>>      
> >>>
> >>>>Hi Olivier,
> >>>>  Thanks for mail. Could you please tell me the meaning of the 
> >>>>following statment
> >>>>
> >>>>h1->SetMaximum(12);
> >>>>
> >>>>
> >>>>
> >>>>waiting for your response.
> >>>>
> >>>>Best wishes,
> >>>>manoj
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>Olivier Couet wrote:
> >>>>
> >>>>   
> >>>>
> >>>>        
> >>>>
> >>>>>Hi Manoj,
> >>>>>
> >>>>>One possible way is;
> >>>>>
> >>>>>{
> >>>>> Int_t n=20;
> >>>>> Double_t x[n],y[n];
> >>>>> for (Int_t i=0; i<n; i++) { 
> >>>>>    x[i]=i*0.1;
> >>>>>    y[i]=10*sin(x[i]+0.2);
> >>>>> }
> >>>>> TGraph *gr1 = new TGraph (n,x,y);
> >>>>> TH1F *h1 = new TH1F("","",100,0,5);
> >>>>> h1->SetMaximum(12);
> >>>>> gr1->SetHistogram(h1);   
> >>>>> gr1->Draw("AC*");
> >>>>>}
> >>>>>
> >>>>>Cheers,      Olivier
> >>>>>
> >>>>>On Tue, 23 Mar 2004, Manoj Jha wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>     
> >>>>>
> >>>>>          
> >>>>>
> >>>>>>Dear rooters,
> >>>>>>    I am facing problem in setting range of the axis of the graph. For 
> >>>>>>this purpose, I had written a root scripts and  attaching it (51.C).  In 
> >>>>>>the scripts, I am trying to  set the range of the  X axis from (0,5). 
> >>>>>>But, it is taking the default one (0,2). I am also attaching the output 
> >>>>>>(graph.ps) that i am getting from the root script (51.C).  Please let me 
> >>>>>>know the possible solution for it.
> >>>>>>
> >>>>>>With best wishes ,
> >>>>>>manoj
> >>>>>>
> >>>>>>
> >>>>>>  
> >>>>>>
> >>>>>>       
> >>>>>>
> >>>>>>            
> >>>>>>
> >>>>>     
> >>>>>
> >>>>>          
> >>>>>
> >>>>   
> >>>>
> >>>>        
> >>>>
> >>> 
> >>>
> >>>      
> >>>
> >>    
> >>
> >
> >  
> >
> 
> 

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