Fill TPolyLine object by using colZ

Dear Rooters,

I would like to create an array of TPolyLine objects which will reflect a detector geometry. Then I want to fill in (or paint) each cell to look like what a TH2 will look like with colZ option. Do you have suggestions how to do that?


You will need to access the color palette like THistPainter::PaintColorLevels does it. … html#YSSJU

Probably the simplest solution is to
-create a TH2F empty
-set min and max
-draw it with colz
-draw your polylines with a color code corresponding to the min/max of the TH2F



Thanks for your suggestions. I tried the following lines for filling individual TPolyLine objects:

    float zmin = hist->GetMinimum();
    float zmax = hist->GetMaximum();
    int ndiv     = TMath::(gStyle->GetNumberContours());
    int ncolors  = gStyle->GetNumberOfColors();
   {//loop over i and j
            int binx = hist->GetXaxis()->FindBin(i);
            int biny = hist->GetYaxis()->FindBin(j);
            int bin = hist->GetBin(binx,biny,0);
            float cont = hist->GetBinContent(bin);            
            int q = int((cont/zmax*ncolors)+0.5);
            if( cont > 0)plineW[j][i]->SetFillColor( gStyle->GetColorPalette(q-1));
            if( cont == 0)plineW[j][i]->SetFillColor(0);

It seems working but the color coding on original TH2F and poly lines are different. How can I make the same color scheme? Could you comment on this?


Where do you set the hist min/max?
The min/max must correspond to what you set in your polylines.


Hi Brun,

The hist has its min/max set in a different program. I’m accessing to this histogram, and then getting its min and max. In the code I pasted before the max, along with bin content, is used to calculate color number.

Could you explain it little bit more if I’m not answering your question?


So I assume that for each polyline you have a Z value (like with option COL).
If you want the same behavior as the COL option you should mimic what is done in the function: THistPainter::PaintColorLevels(). something like:

       Double_t scale = ndivz/dz;


        color = Int_t(0.01+(z-zmin)*scale);


         Int_t theColor = Int_t((color+0.99)*Float_t(ncolors)/Float_t(ndivz));
         if (theColor > ncolors-1) theColor = ncolors-1;