TH2Poly in polar coordinates

Dear ROOTers

I want to make a 2-D polar histogram.
The bin edges will be evenly spaced in radius.
But there will be an arbitrary number of angle bins at a given radius.
The only class I know to make bins with arbitrary shapes is the TH2Poly class.
So I want to use this and plot it in polar coordinates using the “pol” option.
I am using ROOT version 5.34/19.

Here is my failed attempt:

[code]void test_TH2Poly_polar()
{
TH2Poly *h = new TH2Poly();
Double_t a0[] = {0, 2, 2, 0};
Double_t r0[] = {0, 0, 1, 1};
Double_t a1[] = {0, 1, 1, 0};
Double_t r1[] = {1, 1, 2, 2};
Double_t a2[] = {1, 2, 2, 1};
Double_t r2[] = {1, 1, 2, 2};

h->AddBin(4, a0, r0);
h->AddBin(4, a1, r1);
h->AddBin(4, a2, r2);

h->Fill(1, 0.5, 1);
h->Fill(0.5, 1.5, 2);
h->Fill(1.5, 1.5, 3);

h->Draw("colz pol"); // <--- "pol" option not working
return;

}

[/code]

Here is what the failed output looks like:
test_TH2Poly_polar.pdf (13.9 KB)

Hi,

actually you don’t need a TH2Poly here. It seems what you want are not arbitrary shapes, but just arbitrary bin borders. The TH2F allows you to do that already. See this answer to a similar problem:
[url]TH2F polar coordinates binning

Hope that helps.
Benedikt

The option pol is not implemented for th2poly

Thank you for your answers.
Forgive me if I am mistaken, but I am interested in an arbitrary number of angle bins at a given radius.
I don’t think the TH2F class allows this as the variable bin edges in the angle axis will be applied to all bins in the radial direction.
I am attempting this because I want the size of the bins to be relatively constant as the radius increases. So at a small radius, there will be only a few angle bins, but at a larger radius, there will be more.

Is there a way I can achieve this?

Polar coordinates as lego or surface plots are implemented for TH2 only.

OK. Got it! Thanks for everyone’s help.