2D histogram with contours

Hi everyone
I am trying to do a 2D histogram with some contour lines. The contours look very strange probably because the histogram is a bit noisy. I think I need more smooth contours… I attached the the program I am using. The program produces 2 histogram because this was the only way I found to plot contours and colours. But the contours look ugly… does anybody know how to do this properly?
thanks
florian

#include <math.h>

double kbinwd = 0.2;
double cormax = 30.;
const int kbins = cormax/kbinwd; 

void kaiser(){
   gROOT->SetStyle("Plain");
   gStyle->SetOptStat(0);
   gStyle->SetOptFit(1111);
   gStyle->SetPalette(1);

   double cpibin, csigmabin;
   double value;
   cout<<"kbins = "<<kbins<< endl;

   TCanvas *wake = new TCanvas("c","kaiser plot",0,0,800,800); 
   wake->SetLogz();
   TH2F *h = new TH2F("h","kaiser",2*kbins,-cormax,cormax,2*kbins,-cormax,cormax);
   TH2F *h2 = new TH2F("h","kaiser",2*kbins,-cormax,cormax,2*kbins,-cormax,cormax);

   int n = 0;
   ifstream widthfile("kaiser.txt");
   while((widthfile >> cpibin >> csigmabin >> value)){
      //cout<<"cpibin = "<<cpibin<<" csigmabin = "<<csigmabin<<" value = "<<value<<flush<< endl;
      h->Fill(csigmabin+kbinwd/2,cpibin+kbinwd/2,value);
      h2->Fill(csigmabin+kbinwd/2,cpibin+kbinwd/2,value);
      // mirror the kaiser plot on all axis

      h->Fill(csigmabin+kbinwd/2,-cpibin-kbinwd/2,value);
      h->Fill(-csigmabin-kbinwd/2,cpibin+kbinwd/2,value);
      h->Fill(-csigmabin-kbinwd/2,-cpibin-kbinwd/2,value);
      h2->Fill(csigmabin+kbinwd/2,-cpibin-kbinwd/2,value);
      h2->Fill(-csigmabin-kbinwd/2,cpibin+kbinwd/2,value);
      h2->Fill(-csigmabin-kbinwd/2,-cpibin-kbinwd/2,value);

      n++;
   }  
   widthfile.close();

   h->SetTitle(""); 
   h->GetYaxis()->SetTitle("#pi [h^{-1}Mpc]");
   h->GetXaxis()->SetTitle("#sigma [h^{-1}Mpc]");
   h->GetYaxis()->SetTitleOffset(1.2);

   h2->SetContour(2);
   h2->SetContourLevel(0,10);
   h2->SetContourLevel(1,0.01);
   //h->SetContourLevel(2,1);
   //h->SetContourLevel(3,1);

   //h->SetMaximum(30);
   h->Draw("COLZ");
   h2->Draw("CONT3 same");
   //h->Draw("COLZ");
}

kaiser.txt (396 KB)



c.pdf (316 KB)

In your macro you ask for 2 contours only. Doing that produces a plot with a few cells scattered around the center. If you set the number of contour higher then something conform to the COL option appears. But any way you histogram is very rough and the contour algorithms cannot do really better.

ok I don’t know whether root provides any better way to do that but in case that anybody has the same problem it is possible to plot contours by using histograms with larger bins (an less noise…). The solution I have now is very dodgy since I need a new histogram for each contour but it is giving a usable results (see plot)
Anyway I am still interested in clean solutions if there is any…
best regards
florian


I think the cleanest way would be to use an intermediated smoothed histogram.