Problem with gStyle->SetNumberContours

Dear rooters,

I can’t seem to find any way of making my TH2F histograms being plot with number of contours different than default from a level of macro.
I can achieve it however, when I first type “gStyle->SetNumberContours(999)” into root console and then execute my macro. The very same command executed by the macro has no effect at all.

Here I enclose a minimal code to replicate my problem. I run it with ".x min.C++"min.C (705 Bytes)

999 as number of contour is a non sense as the palette you are using is only 255 level. Try the following macro and you will see it works:

void plot_TH2F()
{
   TH2F* dummy = new TH2F("dummy","dummy", 10, 0.0, 1.0, 10, 0.0, 1.0);
   gRandom->SetSeed();
   for (Int_t i=0; i<100000; i++) {
      Float_t x = gRandom->Gaus(0.0,1.0);
      Float_t y = gRandom->Gaus(0.0,1.0);
      dummy->Fill(x,y);
   }

   TCanvas* c1 = new TCanvas("c1","c1",800,600);
   c1->cd();
   dummy->Draw("colz");
}

void min()
{
   gStyle->SetNumberContours(10); // change to 20 and you will the difference
   plot_TH2F();
}

This is quite strange, because it helped when I removed a declaration of my own TStyle “st1”.
Using just gStyle->… works like a charm. Am I doing something wrong with my declaration of TStyle?

And also it seems that the numbers of contours higher than 255 do make sense. Take a look at this macro:

#include <iostream>
#include <TStyle.h>
#include <TSystem.h>
#include <TCanvas.h>
#include <TRandom.h>
#include <TH2F.h>
#include <TROOT.h>

void plot_TH2F()
{
        TH2F* dummy = new TH2F("dummy","dummy", 10, 0.0, 1.0, 10, 0.0, 1.0);
        gRandom->SetSeed();
        for (Int_t i=0; i<100000; i++) {
                Float_t x = gRandom->Gaus(0.0,1.0);
                Float_t y = gRandom->Gaus(0.0,1.0);
                dummy->Fill(x,y);
        }

        TCanvas* c1 = new TCanvas("c1","c1",800,600);
        c1->cd();
        dummy->Draw("colz");

        for(int i=2; i<=999; i++) {
                gStyle->SetNumberContours(i);
                dummy->SetTitle(TString::Format("number of contours: %i",i));
                dummy->DrawCopy("colz");
                gPad->Modified();
                gPad->Update();
                gSystem->Sleep(100);
        }
}

void modmin()
{
        gROOT->Reset();
        gStyle->SetPalette(55);
        plot_TH2F();
}

As said here the predefined palettes have 255 colors:
root.cern/doc/master/classTColor.html#C06
If you have the numbers of contours > 255 it means tu have more contours than colors…