Plot branches without specifying parameters


ROOT Version: 6.14/08

Hi. I have a tree “tree” with 2 branches x and y. I’m writing a script to plot y vs x in the shortest way possible, this is, not predefining a TGraph, because I can’t seem to go around telling how many points I’ll have and creating arrays from x and y to feed to it (which I deem should be unnecessary).

I try:

TCanvas *c1 = new TCanvas("c1"); 
tree->Draw("x:y"); 
TGraph *gr = (TGraph*)gPad->GetPrimitive("Graph"); 

Which makes sense, and to test I do gr->SetTitle(“Title;X;Y;Z”); but it does not work. In TGraph from tree user chw0112 remarks “If I put in … it works perfectly”. Sadly, I cannot see what he says there (I just see an empty quotation).

I would appreciate any help.

The title is hold by htemp

TCanvas *c1 = new TCanvas("c1"); 
tree->Draw("x:y"); 
TH2F *h = (TH2F*)gPad->GetPrimitive("htemp"); 
h->SetTitle("Hello");

Thanks a lot, that works, although I wasn’t expecting to be making a histogram really… If I’m not wrong we are dealing with an unbinned dataset (in fact I have to use SetLimits and not SetRangeUser if I want to change axis range), and, as I’ve read in the documentation, they tend to be associated with graphs and multigraphs, not with histograms. Maybe there’s some confusing permissibility?

The histogram, in that case, is only here to hold the title and axis. Do gPad->ls() after having drawn the tree and you will see it. You are right, your data are not binned. The points are stored in the graph you got . Also visible with gPad->ls().

Thanks, gPad->ls() is indeed extremely useful.

Cheers.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.