Re: Access to TGraph from Tree->Draw 2D

From: Jean-Eric Campagne <campagne_at_lal.in2p3.fr>
Date: Mon, 23 May 2005 16:28:02 +0200


Fine Olivier, I was confused with the TGraph object created and was supposing that the color attribute were derived from the TGraph... Cheers
Jean-Eric

--On lundi 23 mai 2005 16:20 +0200 Olivier Couet <couet_at_mail.cern.ch> wrote:

>
> Well, to change the line color just use SetLineColor on the ntuple. I
> cannot run your example as many things are missing, but here is a very
> simple one based on the ntuple you can find in hsimple.root:
>
> {
> c1 = new TCanvas("c1","ntuple",200,10,700,500);
> TFile f("hsimple.root");
> ntuple->SetLineColor(3);
> ntuple->Draw("px:py","","L");
> }
>
> in this example the lines are green.
>
> Cheers, O.C.
>
> On Mon, 23 May 2005, Jean-Eric Campagne wrote:
>
>> Sorry Olivier I was a little bit too short.
>>
>> 1) When I do only
>> T1.Draw("numum:log10enm","log10enm>-1 && log10enm<2","LSAME");
>> The drawing is Ok but the color of the line is red and I do not manage to
>> change it.
>>
>> 2) When I am trying to access the TGraph
>> T1.Draw("numum:log10enm","log10enm>-1 && log10enm<2");
>> TGraph *graph = (TGraph*)gPad->GetPrimitive("graph");
>> Then graph=0.
>> I was looking for this data access to change color of the line...
>>
>> At the end of the day I would like to superpose other graphs on top of
>> each other.
>>
>> Best
>> J.E
>>
>>
>>
>>
>> --On lundi 23 mai 2005 16:01 +0200 Olivier Couet <couet_at_mail.cern.ch>
>> wrote:
>>
>> >
>> > Hello,
>> >
>> > I am a bit confused with your email. You 1st said:
>> >
>> > "graph seems to be 0."
>> >
>> > But nevertheless it seems you get the graph because later on you said:
>> >
>> > "when I only Draw with LSAME option it is Ok"
>> >
>> > So where is the problem ? you can draw the graph, don't you ? is your
>> > problem "only" with the graph color definition ?
>> >
>> > Cheers, O.Couet
>> >
>> > On Mon, 23 May 2005, Jean-Eric Campagne wrote:
>> >
>> > > Hello,
>> > > I would like to access the TGraph created by a TTree->Draw(x1:x2) as
>> > > in the folowing:
>> > >
>> > > T1.Draw("numum:log10enm","log10enm>-1 && log10enm<2");
>> > > TGraph *graph = (TGraph*)gPad->GetPrimitive("graph");
>> > >
>> > > But graph seems to be 0. My complete C macro is:
>> > >
>> > > {
>> > > TGaxis::SetMaxDigits(2);
>> > > //gStyle->SetOptStat(1); //stat
>> > > TCanvas* c1 = new TCanvas("c1","SPL Flux",100,100,600,600);
>> > > c1->SetGridx();
>> > > c1->SetGridy();
>> > > c1->SetLogx();
>> > >
>> > > //draw a dummy frame
>> > > TH2D* hdum = new TH2D("hdum","Lipari Xcc",10,1e-1,1e2,10,0,1.6);
>> > > hdum->SetXTitle("E_{#nu} (GeV)");
>> > > hdum->SetYTitle("#sigma/E (10^{-38}cm^{2})/GeV");
>> > > hdum->Draw();
>> > >
>> > > TPad *overlay = new TPad("overlay","",
>> > > gStyle->GetPadLeftMargin(),
>> > > gStyle->GetPadBottomMargin(),
>> > > 1-gStyle->GetPadRightMargin(),
>> > > 1-gStyle->GetPadTopMargin());
>> > > overlay->SetFillStyle(4000);
>> > > overlay->Draw();
>> > > overlay->Range(-1.,0.,2.,1.6); //set the range in linear scale
>> > >
>> > >
>> > > TTree T1("t1","Xsection CC");
>> > > //Globes x-section
>> > >
>> > > T1.ReadFile("./LipSezUrtoMauro.txt","log10enm/F:nuem/F:numum/F:nutau
>> > > m/F: anuem/F: anumum/F:anutaum/F");
>> > > overlay->cd();
>> > > T1.Draw("numum:log10enm","log10enm>-1 && log10enm<2");
>> > > TGraph *graph = (TGraph*)gPad->GetPrimitive("graph");
>> > > graph->SetLineColor(4);
>> > > graph->Draw("LSAME");
>> > > }
>> > >
>> > > Of course when I only Draw with LSAME option it is Ok, but I do not
>> > > manage to change the color of the line...
>> > >
>> > > An idea?
>> > > J.E
>> > >
>> > > ....................................................................
>> > > .... ... .LAL - IN2P3 - CNRS
>> > > .LAL - B.P 34 - 91898 Orsay Cedex - France
>> > > .Piece 108
>> > > .Tel +33 (0)1 64 46 84 29
>> > > .Fax +33 (0)1 64 46 83 97
>> > > ....................................................................
>> > > .... ...
>> > >
>> > >
>> > >
>> >
>> > --
>> > Org: CERN - European Laboratory for Particle Physics.
>> > Mail: 1211 Geneve 23 - Switzerland Mailbox:
>> > J25910 E-Mail: Olivier.Couet_at_cern.ch Phone:
>> > +41 22 7676522 WWW: http://cern.ch/Olivier.Couet/
>> > Fax: +41 22 7670300
>>
>>
>>
>> ........................................................................
>> ... .LAL - IN2P3 - CNRS
>> .LAL - B.P 34 - 91898 Orsay Cedex - France
>> .Piece 108
>> .Tel +33 (0)1 64 46 84 29
>> .Fax +33 (0)1 64 46 83 97
>> ........................................................................
>> ...
>>
>>
>>
>
> --
> Org: CERN - European Laboratory for Particle Physics.
> Mail: 1211 Geneve 23 - Switzerland Mailbox: J25910
> E-Mail: Olivier.Couet_at_cern.ch Phone: +41 22
> 7676522 WWW: http://cern.ch/Olivier.Couet/ Fax:
> +41 22 7670300

...........................................................................
.LAL - IN2P3 - CNRS
.LAL - B.P 34 - 91898 Orsay Cedex - France
.Piece 108
.Tel +33 (0)1 64 46 84 29

.Fax +33 (0)1 64 46 83 97
...........................................................................
Received on Mon May 23 2005 - 16:32:32 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:08 MET