TH1D Formatting help

Hello all,

I can’t figure out how to do the following two things related to histograms I am producing. Any help in these matters would be very appreciated:

-How to add uncertainties to the bins of the histograms. I know the uncertainties belonging to the bins but I can’t display it on my stacked histogram. Ideally it would be great if the format looked like this:

-A separate graph for Data/Monte Carlo results. Do I just need to make a separate graph for this? Or is there an easier option.

Many thanks in advance!

I am not sure I completely understand what you mean. But I would say “yes”…

Haha okay I agree with you there. Forget that question.

I would appreciate however if you told me how to plot error bars on the maximum value of a THStacked histogram. The purpose of this would be to display the error on the total background. If for example, I calculate an error of 0.9 on the sum of a certain bin of a stacked histogram, how would I show that?

Here is an example
hstack1.C (700 Bytes)

Thanks! I see you set the error bar option on the last histogram to be added to the stack. However I still have a couple questions:

  • Why did the last histogram to be stacked not be displayed with a green fill (the one with the error bars)?
  • Do you know of any way I could make the error bars be rectangles instead (and look more like the figure I attacked before).

hs->Add(h3st,“HIST E”);

see all the error options here:

Thanks so much!

I can’t say enough good things about this Support service that is offered. Specifically you and Wile E Coyote have been a tremendous help in helping me work out some of my problems while learning ROOT.


Thanks :slight_smile:

Another quick question: How come the negative y error bar does not extend farther than the lower limit of that histogram (if it is big enough)?

Say for example I included the line: h3st->SetBinError(50,5000);

The lower error bar does not extend the entire way.

Is there a way around this?

It is because the computation of the Y axis is based on the sum of the bon content without taking car of the errors. The workaround would be to draw the axis first and them the stack on it using the option "SAME"like in the following example:


   THStack *hs = new THStack("hs","Stacked 1D histograms");

   //create three 1-d histograms
   TH1F *h1st = new TH1F("h1st","test hstack",100,-4,4);
   TH1F *h2st = new TH1F("h2st","test hstack",100,-4,4);
   TH1F *h3st = new TH1F("h3st","test hstack",100,-4,4);
   hs->Add(h3st,"HIST E");

   TCanvas *cst = new TCanvas("cst","stacked hists",10,10,700,700);

Is there any way to do that, while keeping the fill colours of the other histograms in the stack?

Not that simple… I think we are on the wrong track. Better do:

1- Build the stack as normal.
2- Plot it as you did before (without errors).
3- Make a 4th histogram being the sum of the 3 in the stack
4- Plot it on top of the stack with the option SAME.

It makes more sense.

Okay then I have another dilemma for you haha.

If this blank ‘error’ histogram is to plotted using “same”, then the fill must be clear (->SetFillStyle(0):wink: so that it does not overlap the stacked histogram.

However I would like the error bars to be rectangles (option E2) with SetFillStyle(3005);. Is this possible? Or do I just need to suck it up and use regular error bars?

No need for that. When drawn with errors the filled part is not drawn. Just option “E SAME”

Yes option “E2 SAME”


Thanks again!