Crash when drawing THStack

Hi,
I’m facing a very weird bug, where I’m trying to draw a THStack on a pad where the axis are determined by another histogram (see attached macro). If I use the option “axis” on the histogram and then I try to draw the THStack the macro crashes, whereas if I draw the histogram with no options first the macro runs without issues.
The other funny thing is that if I uncomment both methods the macro runs just fine (but it’s quite messy, and definitely not what I want to do here…)

tested on ROOT 6.04/08
test.root (15.2 KB)
test.C (721 Bytes)

void test(){
   Color_t colors[] = {kRed, kBlue, kGreen+2};

   TFile* infile = TFile::Open("test.root");
   TH1D* hist_data = (TH1D*) infile->Get("hist_data");
   hist_data->SetMarkerStyle(20);

   THStack* mcstack = (THStack*) infile->Get("mcstack");
   for(uint imc=0; imc<3; imc++){
      TH1D* hist_mc = (TH1D*) mcstack->GetStack()->At(imc);
      hist_mc->SetLineColor(colors[imc]);
      hist_mc->SetFillStyle(1001);
      hist_mc->SetFillColorAlpha(colors[imc], 0.35);
   }

   TCanvas* c1 = new TCanvas();
   hist_data->Draw("axis");
   gPad->Update();
   mcstack->Draw("hist same");
}

Hi Olivier,
ok, I’m still wondering why the “axis” option is the only one that requires a manual update of the Canvas. The problem is that although this fixes the example macro, in my real life case the two objects are drawn in a subpad of a TCanvas. I tried to call Update() for both the TPad and the TCanvas but somehow it doesn’t seem to work.

I’ll try to prepare another macro to test this slightly more complicated scenario…

Try:
gPad->Modified(); gPad->Update();

Hi Valerio,

Yes, as you can see in the macro I posted, a gPad->Update() is needed after the Draw() with option “axis”. I will check why this is needed and if some fix can be done. You can also add, as first histogram in your stack, an empty one with the right range.