Connecting points in profile hist with a line?

Hello,

I have this profile histogram:
Selection_017
That came from this thing:
Selection_020
And even though I’ve been looking for a while, I can’t seem to find how to connect the blue points in the profile hist with a line. Is it possible to do so?

Here’s how I’m doing this:
Before you have a look, I am a root beginner, if you see something stupid I’d be very thankful if you could give me some pointers… The way I take data from a tree and put into the hModel pointer so that I can use it doesn’t seem very smart to me, not sure if doing it right.
Selection_021
I’ve made other plots where I use the option L in Draw to connect my points in a line but that doesn’t see to work here…
The idea would be to get something like this from the profile hist:
(Sorry for the bad paint drawing)
Selection_017

Any tips?
Thanks,

See the THistPainter class for a description of all the drawing options.

Thank you for your reply,

Before coming here I already spent a considerable amount of time looking at that documentation but still haven’t been able to do what I want. I’ve found out some peculiarities though, which have made me begin to doubt if it’s possible or not: on another part of the program I make a TGraphErrors myGraph and draw it with option “L” for a line to connect my data points.

If I do myGraph->SetLineWidth(something), the line that connects the points is the one that gets thicker.

But if I do that with the hModel profile hist above, what happens is that the profile points themselves get thicker:
With a SetLineWidth(1)
image

vs with a SetLineWidth(4)
image

So I’m thinking that maybe since it thinks of those points as lines, I can’t have a line between them.

Try:

hModel->Draw();
hModel->Draw("HIST L SAME"); // "HIST L SAME" ... or ... "HIST SAME"
1 Like

Funny thing happened:
image
and if I try without the L option it’s basically the same thing:
image

Thanks again,

As you can clearly see it now, the vast majority of your profile histogram’s bins are zeros.

If you want to “connect” bins which are non-zero only then I think you will need to create a separate TGraph with just these points (and then draw this TGraph with “L” on top of your profile histogram’s picture).

Yes! And how might I do that exactly?

hModel->Draw();
TGraph *g = new TGraph();
for (int i = 1; i <= hModel->GetNbinsX(); i++)
  if (hModel->GetBinContent(i) != 0.0)
    g->SetPoint(g->GetN(), hModel->GetBinCenter(i), hModel->GetBinContent(i));
g->SetLineColor(kRed);
if (g->GetN() > 1) g->Draw("L");
2 Likes

Thank you so much! Works like a charm and exactly what I wanted!

My friend let me say this, it’s people like you that make the world spin :slight_smile: .

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