TH3D ignores SetMaximum()

Hello Rooters,

I am trying to put two histos into an overlay on a canvas. They are both 3D, and things are getting a little flakey, but it is the best way to visualize my data set. In one histo, I have my main sample, and the second histo (drawn in red) are the events that get cut from the main sample. Because they are in a separate histo, the cut events are drawn with HUGE cubes compared to the main sample (cube size indicates number of events in 3d bin). Sample code is below, where the main sample cubes all have 20 events, cut sample has 1 event per cube. I want the single event cubes to be smaller than the 20 events, but no matter what I do, they are always the same size!

Am I doing something wrong? Please try the test code with “.x test.cpp(A)”, where A=1., 1000., 0., -1., etc. Nothing happens, you get the same plot every time.

void test(double maxToSet=0.){
  TH3F *h1=new TH3F("h1","main sample",10,0.,10.,10,0.,10.,10,0.,10.);
  for (int i=0; i<20; ++i) {
    h1->Fill(2.,3.,3.);
    h1->Fill(2.,7.,3.);
    h1->Fill(2.,3.,5.);
  }
  h1->Fill(2.0,1.0,1.0);  // a little bin for contrast!  Red bins should be this size.

  TH3F *h2=new TH3F("h2","cut sample",10,0.,10.,10,0.,10.,10,0.,10.);
  h2->Fill(8.,3.,3.);
  h2->Fill(8.,7.,3.);
  h2->SetMarkerColor(2); 
    if (maxToSet>0.0){
    cout<<"Setting max to "<<maxToSet<<" from "<<h2->GetMaximum();
    h2->SetMaximum(maxToSet);
    cout<<" and now it is "<<h2->GetMaximum()<<endl;
  }
  if (maxToSet<0.0){
    cout<<"Setting max to "<<h1->GetMaximum()<<" from "<<h2->GetMaximum();
    h2->SetMaximum(h1->GetMaximum());
    cout<<" and now it is "<<h2->GetMaximum()<<endl;
  }

  TCanvas *c1=new TCanvas("c1","c1",600.,600.);
  h1->Draw("box fb bb");
  h2->Draw("same box fb bb ");
}

I’m using ROOT 5.34/34 in Windows.

 - John

Yes it seems the BOX option for 3D plots ignores min and max in that case… I will check.

Now fixed in 6.08 and 5.34. Thanks for reporting.

The macro:

{
   TH3F *h1=new TH3F("h1","main sample",10,0.,10.,10,0.,10.,10,0.,10.);
   for (int i=0; i<20; ++i) {
      h1->Fill(2.,3.,3.);
      h1->Fill(2.,7.,3.);
      h1->Fill(2.,3.,5.);
   }
   h1->Fill(2.0,1.0,1.0);  // a little bin for contrast!  Red bins should be this size.
   h1->SetMinimum(0.);
   h1->SetMaximum(30.);

   TH3F *h2=new TH3F("h2","cut sample",10,0.,10.,10,0.,10.,10,0.,10.);
   h2->Fill(8.,3.,3.);
   h2->Fill(8.,7.,3.);
   h2->SetMarkerColor(2);
   h2->SetMinimum(0.);
   h2->SetMaximum(30.);

   TCanvas *c1=new TCanvas("c1","c1",600.,600.);
   h1->Draw("box fb bb");
   h2->Draw("same box fb bb ");
}

produces the attached plot:


W00t! Thank you!

It seems to me that this still doesn’t work. I pasted your code above into “test2.C”. In the /36 version of root, I get

[code] *******************************************

  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.34/36 5 April 2016 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      http://root.cern.ch            *
    
  •                                     *
    

ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x test2.C[/code]

I get the following plot. Not only did the red cubes not scale, but now I also get little dots marking each empty bin! Are you sure you tested the Windows version? I am using the pre-compiled Windows version.


You need the current “v5-34-00-patches” (or 5.34/38) and (ROOT 5 cannot cope with the “minimum” set to 0):
h1->SetMinimum(1e-11);
h2->SetMinimum(1e-11);

Thank you for your help. I am only using pre-compiled versions, since there seems to be no MSVC project files included with the source code. It looks like a pretty plot will have to wait for the next Prod version.

I have reverted back to 5.34/34. The little dots in the empty bins are unacceptable. In /36, if I forget to reset the minimum to 1e-11, the ROOT process hangs for an interminable amount of time while it draws each little dot. You say ROOT 5 can’t handle zero minimum, but /34 had no problem with whatever was the default and I got no little dots. With /36, something has been broken and the little dots make TH3D almost useless.

I see. The little dots appear with the X11 version on Mac. Checking it now. Thanks to have seen it.

Now fixed in 5.34 and master. Thanks to have reported it.