How to use TTree with multigraph:

Hi all,

I am trying to put multiple plots on a single graph, with the same scale. I can do this with multigraphs and arrays but i am trying to do this when data is stored in a TTree.
I have the following code but so far only one plot appears on the graph.

graph_both = new TMultiGraph();
fCanvas4->cd();
root_tree->Draw(“g1:time”,"", “CP”, 20,mintime); //first plot
graph1 = (TGraph*)gPad->GetPrimitive(“Graph”);
graph1->SetLineColor(4);
graph_both->Add(graph1, “CP”);

root_tree->Draw(“g2:time”,"", “CP”, 20,mintime);// second plot
graph2 = (TGraph*)gPad->GetPrimitive(“Graph”);
graph2->SetLineColor(2);
graph_both->Add(graph2, “CP”);
graph_both->Draw(“C*”);
fCanvas4->Update(); // this function runs in a loop hence the update
fCanvas4->Clear(); // and clear commands.

and help is appreciated.

thanks!!

John

John,

You don’t need all this gymnastic. Simply do:

[code]root_tree->SetLineColor(4);
root_tree->Draw(“g1:time”,"", “CP”, 20,mintime); //first plot

root_tree->SetLineColor(2);
root_tree->Draw(“g2:time”,"", “CP same”, 20,mintime);// second plot
[/code]

Rene

thanks rene.
I am trying to disable the title box that appears on the graph.
I tried to use root_tree->SetTitle(" "); but SetTitle doesnt seem to effect the title of graphs from trees.

i also tried to access the graph in the tree by :
TGraph graph = (TGraph)gPad->GetPrimitive(“Graph”);
graph->SetTitle(“somethingelse”);
but also yielded no results. Im not understanding why this doesnt work.

Do:

[code]TCanvas *c1 = new TCanvas(“c1”);
root_tree->SetLineColor(4);
root_tree->Draw(“g1:time>>h2”,"", “CP”, 20,mintime); //first plot
TH2 h2 = (TH2)c1->GetPrimitive(“h2”);
h2->SetTitle();

root_tree->SetLineColor(2);
root_tree->Draw(“g2:time”,"", “CP same”, 20,mintime);// second plot
[/code]
Rene