Root Contour Colors

ROOT produces awful graphical results under some circumstances if you draw dashed contour using a TH2. (The lengths of the dashes in inconsistent, having something to do with the grid spacing or curvature or whatnot.) The following voodoo function takes a TH2D and returns an array of TGraphs for each of the contours that would be drawn. These TGraphs can be drawn with any style and look fine:

TGraph ** h2graph(TH2D * in_hist) // could be TH2F, etc.
{
  TCanvas temp_can;         // This avoids disturbing canvases already in use.
  temp_can.cd();            // Yes, we do need a canvas for this to work, and
  in_hist->Draw("contlist");// yes, we do need to call Update() on it after
  temp_can.Update();        // Draw(). No, ROOT is not very friendly.

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

  TGraph ** agr = (TGraph **)malloc(plah->GetSize() * sizeof(TGraph *));

  for(int i = 0; i < plah->GetSize(); i++){
    TList * list = (TList*) plah->At(i);
    agr[i] = new TGraph(*((TGraph*) list->First()));
    agr[i]->SetLineColor(in_hist->GetLineColor()); // totally optional
  }

  return agr;
}