Problems with TH2 Palette colors and negative values

Hiya,
I want to plot a 2D histogram with the colz option using my own palette.
The range of the the histogram is [-10;50]. I’d like to have the negative values in black and the positive ones below and above my threshold (30 ADC counts) respectively in blue and white.
But using negative values mess everything up. A shift appears and the colors get not really respect (e.g. the border between blue and white is not 30 but a bit less). This does not happen whilst using positive value (but the result is pointless: Cf pictures attached). Here’s my code:

  h_mimo5->SetMaximum(+50.) ; 
  h_mimo5->SetMinimum(-10.) ;

  // Creating a personal palette
  Int_t myPalette[6] ;  // 1=black / 9=blue / 0=white
    myPalette[0] =  1 ; // -10 ->  0
    myPalette[1] =  9 ; //   0 -> 10 
    myPalette[2] =  9 ; //  10 -> 20
    myPalette[3] =  9 ; //  20 -> 30
    myPalette[4] =  0 ; //  30 -> 40
    myPalette[5] =  0 ; //  40 -> 50
  gStyle->SetPalette(6,myPalette) ; 

Any clue ?
Cheers, Zesp




Could you
-indicate which version of ROOT
-send the shortest possible running script reproducing the problem?

Rene

Hi Rene,
Thanks for having answered so fast.
So here we go I did the same thing on a 16*16 matrix.
I’m using Root 4.00/04 (30 April 2004) and CINT 5.15.133
(18 April 2004).
Cheers, Zesp


{

gROOT->Reset() ;

Int_t threshold=30 , nPix=16 ;

FILE *fin = fopen("myProg.txt","r") ; 
if ( fin==NULL ) 
  { fprintf (stderr, "!!! Error: 'myProg.txt' not readable\n") ; exit(1) ; }

TCanvas *c1 = new TCanvas ("c1","",10,10,800,800) ;
gStyle->SetOptStat(0) ;

TH2I *h_mimo5 = new TH2I ("h_mimo5","",nPix,0,nPix , nPix,0,nPix) ;
h_mimo5->SetMaximum(+50.) ; 
h_mimo5->SetMinimum(-10.) ;

Int_t myPalette[6] ;  // 1=black / 9=blue / 0=white
  myPalette[0] =  1 ; // -10 ->  0
  myPalette[1] =  9 ; //   0 -> 10 
  myPalette[2] =  9 ; //  10 -> 20
  myPalette[3] =  9 ; //  20 -> 30
  myPalette[4] =  0 ; //  30 -> 40
  myPalette[5] =  0 ; //  40 -> 50
gStyle->SetPalette(6,myPalette) ; 

Int_t raw=0,col=0 , data ;
for (Int_t i=0 ; i<nPix**2 ; i++)
{
  fscanf (fin,"%i",&data) ; 
  h_mimo5->SetBinContent(raw+1,col+1,data) ;
  col ++ ;
  if ( col==nPix ) { col=0 ; raw++ ; }
}
h_mimo5->Draw("colz") ; 
c1->SaveAs("myProg.gif") ;

fclose (fin) ;

}

myProg.txt (595 Bytes)



myProg.c (950 Bytes)

You have a mismatch between the number of colors in your palette and the default number of contours.
Simply add the following statement just before Drawing the histogram:
h_mimo5->SetContour(6);

Rene

Brilliant,
Thanks a lot,
CU around, Zesp