Crash when drawing stack?

Hi everybody,

Please take a look at the attached simple macro that I wrote. It produces a 2d histogram with some numbers in it, as well as a 2d stack with two similar histograms.

I am first drawing the single histogram, and then I’m trying to draw the stack into the same histogram frame, as an overlay. At that point, at the very last line in the macro, the program crashes.

Am I doing something wrong, or is this a ROOT bug?

Thanks!

Cheers,
Peter
same.C (617 Bytes)

Yes the SAME option in that particular case does not work. I am trying to find a work around.

void same() {
   TF2 *xyg = new TF2("xyg","xygaus",0,10,0,10);
   xyg->SetParameters(1,5,2,5,2);  //amplitude, meanx,sigmax,meany,sigmay

   TH2F *h2st0 = new TH2F("h2st0","h2st0",20,-4,4,20,-4,4);
   h2st0->SetFillColor(32);
   h2st0->FillRandom("xyg",4000);

   THStack *a = new THStack("a","Stacked 2D histograms");
   TH2F *h2sta = new TH2F("h2sta","h2sta",20,-4,4,20,-4,4);
   h2sta->SetFillColor(38);
   h2sta->FillRandom("xyg",1000);

   TH2F *h2stb = new TH2F("h2stb","h2stb",20,-4,4,20,-4,4);
   h2stb->SetFillColor(46);
   h2stb->FillRandom("xyg",1000);
   a->SetMaximum(h2st0->GetMaximum());
   a->Add(h2sta);
   a->Add(h2stb);
   a->Draw("");
    h2st0->SetMarkerStyle(20);
   h2st0->Draw("E SAME");
}