# Smooth 2D contours from TH2

Hi,

I have a TH2 histogram that I am drawing with “cont3” (see can.gif). Since the binning is rather coarse I thought to retrieve the contour graphs and draw them with the “c” option in a new canvas (see can2.gif). Unfortunately, the results are rather disappointing as you can see. You can reproduce this with the macro below (I was using 5.14/00b). How would I get really smooth contours from my histogram?
(Increasing the binning for the histogram is not an option for my real life application, in which the artifacts are actually even worse.)

Thanks for any help,
Frank

``````{
TH2F* h2 = new TH2F("h2","",10,-3,3,10,-3,3);
for (int ix=1; ix<=h2->GetNbinsX(); ix++) {
for (int iy=1; iy<=h2->GetNbinsY(); iy++) {
double x = h2->GetXaxis()->GetBinCenter(ix);
double y = h2->GetYaxis()->GetBinCenter(iy);
h2->Fill(x,y,x*x+y*y);
}
}

double conts[] = {1,3,6};
h2->SetContour(3,conts);
TCanvas* can = new TCanvas("can","can",400,400);
h2->Draw("cont,list");
can->Update();

TCanvas* can2 = new TCanvas("can2","can2",400,400);
TH2F* h = new TH2F("h2","",10,-3,3,10,-3,3);
h->Draw();

TObjArray *contours =
(TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");

for (int ic=0; ic<contours->GetEntries(); ic++) {
TList* graphlist = (TList*)contours->At(ic);
for (int ig=0; ig<graphlist->GetEntries(); ig++) {
TGraph* gr = (TGraph*)graphlist->At(ig);
gr->Draw("csame");
}
}
}``````

I know you do not want to do it but I am afraid that the answer to your problem is to increase the number of bins.
None of the CONT# option is able to generate a really smooth contour with this small number of bins (I tried them all). When you get the graphs from the contour using option LIST it is also the same, ie: the number of bins being small, the number of points in each graph is small too and the smoothing algorithm has some problems (as you can see), in particular in places with vertical lines.