TTree 2-dim Draw: how to get TH1 instead of TH2

Is there a way to force TTree Draw to produce TH1 histogram for a 2-dim draw (e.g. “par1:par2”) instead of default TH2?

I use ROOT as a library in a c++ application.
I am doing this:
tree->Draw(What, Cond, Opt)
and then
TH1* tmpHist = dynamic_cast<TH1*>(gDirectory->Get(“htemp”))
The What parameter contains “>>htemp()”

With empty Opt a scatter plot is produced.
With “prof” option, a TProfile is created but it shows true points together with artificially-added zero points.

And it seems it should be possible to do what I need since the Root browser can do this: if Opt is set to “LP”, a line is indeed drawn, while using this option in the approach described above changes nothing.

Any suggestions?


An it is the same with the command line interface if you do:


Thank you Oliver!

An it is the same with the command line interface if you do:

It does not work for me. The line I have to use is:

tree->Draw("x:y>>htemp(100,0,0)", "", "L")

and then

TH1* tmpHist = dynamic_cast<TH1*>(gDirectory->Get("htemp"));

After some internal housekeeping I do


What is actually drawn is TH2F, and, of course, no line.

In the browser, tree->Draw(“x:y”, “”, “L”) works fines, as I wrote before. But to have the object pointer, I have to have that >>htemp.

Is there any other approach?

Found another way myself:
After tree draw:

TGraph *graph = dynamic_cast<TGraph*>(gPad->GetPrimitive("Graph"));

Then I clone the graph and can use the clone with the rest of my code.
The graph indeed shows the line.

Yes you should use the TGraph if you need to do the plot afterwards.

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