Getting the object created by TNtuple->Draw

Hello,

I’m trying to get a pointer to the TGraph created by TNtuple->Draw(). When I use gPad->GetListOfPrimitives(), I get the actual x and y arrays printed out point by point, as if the objects created are series of markers. But I know that there are TGraph objects in the pad, because in the graphics editor I can change the graph’s line style, etc. In the object inspector there is a TGraph::Graph, but why is it not listed in the list of primitives? Also, in situations where there is more than one Draw command with the “SAME” option, they all seem to have the same name Graph.

So my question is, what is the proper way to get the object made by Draw that will let me change the linestyle, etc?

Thanks for reading/answering,
Joe

Some example code and output that might explain this more clearly

Example macro:

TFile *temp=new TFile("analyse.root", "RECREATE"); TNtuple *ntuple = new TNtuple("TCITC","TCITC","tc:itc"); ntuple->ReadFile("R2Out_32_3.dat"); //text file with format %f %f \n etc..) ntuple->Write(); TCanvas *c1 = new TCanvas("c1"); ntuple->Draw("itc:tc"); //TList *li = new TList(gPad->GetListOfPrimitives()); //li->Print(); //Printing the list doesn't print all of the objects for some reason, perhaps there's some option needed? gPad->GetListOfPrimitives()->Print();

Output:

Collection name='TList', class='TList', size=4 TFrame X1=0.000000 Y1=0.000000 X2=11.000000 Y2=0.052000 FillColor=19 FillStyle=1001 TH1.Print Name = htemp, Entries= 0, Total sum= 0 TPaveText X1=-1.237500 Y1=0.054925 X2=0.064799 Y2=0.058175 FillColor=19 FillStyle=1001 Collection name='TList', class='TList', size=1 Text X=0.000000 Y=0.000000 Text=itc:tc Font=0 Size=0.000000 Color=0 Align=0 x[0]=0.01, y[0]=1.51948e-06 x[1]=0.02, y[1]=1.17205e-05 x[2]=0.03, y[2]=3.81412e-05 x[3]=0.04, y[3]=8.71766e-05 x[4]=0.05, y[4]=0.000164185 x[5]=0.06, y[5]=0.000273588 etc... to end of the NTuple TCITC

Instead of:

TCanvas *c1 = new TCanvas("c1"); ntuple->Draw("itc:tc"); //TList *li = new TList(gPad->GetListOfPrimitives()); //li->Print(); //Printing the list doesn't print all of the objects for some reason, perhaps there's some option needed? gPad->GetListOfPrimitives()->Print(); do

TCanvas *c1 = new TCanvas("c1"); ntuple->Draw("itc:tc"); TGraph *gr = (TGraph*)gPad->GetPrimitive("Graph"); gr->SetMarkerColor(kRed); //or any other atribute or alternatively (the Graph inherits the Tree properties). Here I show the case of 2 consecutive Draws identified with a different color

TCanvas *c1 = new TCanvas("c1"); ntuple->SetMarkerColor(kBlue); ntuple->Draw("itc:tc"); TGraph *gr = (TGraph*)gPad->GetPrimitive("Graph"); gr->SetName("BlueGraph"); ntuple->SetMarkerColor(kRed); ntuple->Draw("itc:tc","some selection"); gr = (TGraph*)gPad->GetPrimitive("Graph"); gr->SetName("RedGraph");

Rene

Thank you, that was very helpful!