Draw THStack with error bars inside canvas

Hi all,

had a thread on ROOT Support, but bombard this disucssion forum also in hope of solving the problem.

How can I plot a THStack object with error bars with the error bars automatically fitting inside the canvas? It seems like ROOT does not calculate place to fit the error bars and they get cut off and not fully included in the plot.

I attach a figure as example.

I have zoomed below zero so that you can clearly see the error bars that fall outside the actual plot window at negative values.

Regards,
Maiken

Can you post an example macro reproducing this ?

Yes, this simple macro reproduces the problem about errors ending up outside the plot:

{
  TH1D *h1 = new TH1D("h1","h1",10,0,10);
  TH1D *h2 = new TH1D("h2","h2",10,0,10);

  THStack h;
  
  for(int i=0; i<11; i++){

    
    h1->SetBinContent(i,1.5-i/10);
    h1->SetBinError(i,0.5*i);
    h1->SetLineColor(kRed);
    h1->SetMarkerStyle(21),

    h2->SetBinContent(i,10.5-i/10);
    h2->SetBinError(i,0.7*i);
    h2->SetLineColor(kBlue);    
    h2->SetMarkerStyle(21);

  }
  //h1->Draw();
  //h2->Draw();

  h.Add(h1);
  h.Add(h2);

  h.Draw("nostack E1");

}


This will require a fix in the code which I do not have yet. If you want a fast solution without downloading a new root version, here is a quick workaround:

{
   TCanvas *c = new TCanvas("c","c");
   TH1D *h1 = new TH1D("h1","h1",10,0,10);
   TH1D *h2 = new TH1D("h2","h2",10,0,10);
 
   THStack h;
 
   for(int i=0; i<11; i++){
 
 
   h1->SetBinContent(i,1.5-i/10);
   h1->SetBinError(i,0.5*i);
   h1->SetLineColor(kRed);
   h1->SetMarkerStyle(21),
 
   h2->SetBinContent(i,10.5-i/10);
   h2->SetBinError(i,0.7*i);
   h2->SetLineColor(kBlue);
   h2->SetMarkerStyle(21);
 
   }
   //h1->Draw();
   //h2->Draw();
 
   h.Add(h1);
   h.Add(h2);
 
   c->DrawFrame(-1,-5,11,17);
   h.Draw("nostack E1 same");
 
}

Yes, okay.

I have actually been trying to do this for 2 year (!!) now.

Point is that I am looping over many histograms, plotting them and saving them , and want to prevent having to set the ranges by hand for each plot, then I would have to check which of all histograms have the largest range etc, pick out this and set it by hand, which is quite cumbersome.

When do you think it can be included?

By the way, there is also a very strange feature with TGraphError and TMultiGraph. I was trying to see if using these objects would make things better. The problem there is that if I have empty points, they get accumulated automatically at x=0, y=0 . Do you know anything about this “feature”? I link you to the thread I had on support.

http://root.cern.ch/phpBB2/viewtopic.php?t=9328

Thanks!
Maiken

I am looking at it now.

Note that you can avoid doing it by hand by looping on all histograms to compute the good range.

I am looking at it now.

Okay, great, thanks!

Maiken

Hi :slight_smile:

Any news on the case?

Cheers,
Maiken

I am doing the last tests…

Note that it will be fixed in the SVN trunk … so you will need to take it from there to see the effect … is that ok for you ?

Yes, that sounds good :slight_smile:

This problem is now fixed in the SVN trunk.

Super, look forward to testing it!

Thank you very much for your help

Cheers,
Maiken

Hi,

I now managed to build and compile the trunk version (I believe) by following the instructions on
http://root.cern.ch/drupal/content/installing-root-source

with
svn co root.cern.ch/svn/root/trunk root

(notice https and not http)

and chosing the location independent installation.

I then get a root version called 5.25/03 (trunk@30945) is this the right one?

I seem to still get the same problem with the error bars?

And one more thing that I would like to know, how to plot with option E1 and be able to not have line at 0, see attached plot.


Make sure you have the thstack.cxx latest version:

root.cern.ch/viewvc/trunk/hist/h … x?view=log

You can even take it from that page.

Ok, thank you, I will try.

How about the line at 0. Rene suggested to plot with 0 option, but seems this does not work when at the same time plotting with E1 option?

Maiken

Oh … I’ll look …

Hi,

thanks for the implementation - there seems still to be one issue?

Looks like the canvas gets set correctly for the upper limit, but not for the lower limit? The error bars still fall outside the canvas for the minimum y-value.

The plot attached shows the problem.

Thanks!

Maiken


No, it is jut on limit… there is no bottom margin.

This is now fixed in the SVN trunk.