TGraph for each bin

Dear experts,

in a TH1 frame, I want to draw a TGraph by category (or bin the histogram bin), so:

  • I defined the TH1 [1].
  • I set the TH1 bin label [2].
  • I defined the TVectorD to be parse to the TGraph [3].
  • I defined the TGraph[4].

then I got this plot:

But that is not exactly what I want. Indeed, it make a continues line btw the categories, while it should be discontinues. I want to fill each category with a value. For example, for the comb bin, we should have a vertical line which should correspond to the 1st element that I put in the graph vector parameter. Do you see how I can do that?


TH1D *dummy = new TH1D(“dummy”,“dummy”, 4, 120, 135);

vector vlabel{“comb.”, “#mu#tau”, “e#tau”, “e#mu”};
for (int i=0; iGetNbinsX(); i++) dummy->GetXaxis()->SetBinLabel(i+1, vlabel[i].c_str());

array amass=(120, 125, 130, 135);
array azero=(0, 0, 0, 0);

int ndir=amass.size();
TVectorD v_dir (ndir, amass);
TVectorD v_zeros (ndir, azero);
TVectorD v_exp_p2(ndir, aexp_p2);
TVectorD v_exp (ndir, aexp);
TVectorD v_exp_m2(ndir, aexp_m2);

TGraphAsymmErrors *gr_exp2 = new TGraphAsymmErrors(v_dir, v_exp, v_zeros, v_zeros, v_exp_m2, v_exp_p2);

Dear experts,
an ideas?

Can you pst a picture showing the kind of plot you want ?

Dear Couet,
I want a plot like this one:
This only difference is that I want the category (4l, 2l…) to be
on the x axis.

The way you proceed cannot work …
That plot is quiet complex … I see boxes like in the COL option or errors plotted as boxes …
Then error bars on top … then some other lines (dotted) … That sort of plot can be done with root but it really depends on the data you have … There is bot singe recipe to do it. Do you have a macro producing this plot ?

Dear Couet,

the only macro that I have:
run on the root file: … mH125.root … mH125.root

makes plot for this one:

So do you see how I can change to make:

PS: For me the only difference is that I want to plot the value
bin by bin while my current plot it point by point,
and then make a continus line… As TGraph is not histogram,
I can’t do “Fill(bin, value)”…


So why don’t you use a TH1F instead of a TGraph ?

Dear Couet,

my problem is that when I use TH1, I have this:

I do not see how I can fill the area in an elegant way. What I did here is that for each category, and for each value, I fill an histogram, then I draw all of them in the save canvas. Now I want to fill the area with color like here:

Do you know if it would be possible to:
TH1-> SetBinErrorUp();
TH1-> SetBinErrorDown();
Then fill the error area?


May be this option will help: … html#GP03b

Dear Couet,
I’m confused. This is for TGraphError right? Here I have histograms…

Yes but before you had graphs. TGraphErrors allows to draw these error boxes and I think that is what you are looking for.

But I’m using histogram now as you advice me to do it yesterday, right?
So right now I’m not using TGraph. Do you mean that I should used TGraph instead of TH1?

You said :

This mean you want to have some kind of error boxes … right ? … in that case the TGraphAssymErros example I send you does it. TH1 does not have the concept.

But then this will be a mix of Tgraph and histograms, would I be able to plot all this togeter on the TH1 axis?


Dear Couet,

I managed to do that with histograms:

but I wonder why the dotted line are draw on the axis?
To draw the dotted histogram I used:
hlimits-> SetLineWidth(2);
hlimits-> SetLineStyle(2);

Do you know how I can remove the dot on the axis?


I need to see ( and run) the macro to see where they are coming from.

Dear Couet,

I code is: …

the root files: … mH125.root … mH125.root

Do you see what is wrong?


$ root plotlimit_hist.C
  | Welcome to ROOT 6.09/01            |
  |                                    (c) 1995-2016, The ROOT Team |
  | Built for macosx64                                              |
  | From heads/master@v6-09-01-1155-g4e2fa30, Jan 24 2017, 17:32:53 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'      |

root [0] 
Processing plotlimit_hist.C...
In file included from input_line_12:1:
/Users/couet/roottest/plotlimit_hist.C:2:10: fatal error: '' file not found
#include ""
root [1] 

Dear Couet,

sorry, I posted it here: …