TH2F polar coordinates binning

Hello,

I am trying to fill and draw a 2D histogram in polar coordinates. I am aware of the hist.Draw(“lego2 pol”) option for standard Th2F histograms, but I need to have a precise binning in radius. This is because I am analyzing data from “ring shape” detectors, with fixed and equal thicknesses, having the same center, so I have to bin separately the entries from those separate rings. An arbitrary binning might include parts of two consecutive rings in the same bin.

Is this possible?

Thank you,

Best regards,

Cristian

You can define your own “bin borders” when creating the histogram.
For example:
// both, X and Y, bins "variable"
TH2F::TH2F(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins, Int_t nbinsy, const Double_t* ybins)
// X bins “variable”, Y bins "equidistant"
TH2F::TH2F(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins, Int_t nbinsy, Double_t ylow, Double_t yup)
// X bins “equidistant”, Y bins "variable"
TH2F::TH2F(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, const Double_t* ybins)
Where the “xbins” and “ybins” are the arrays of low-edges for each bin. These are arrays of sizes “nbinsx+1” and “nbinsy+1”, respectively. The very fist values/elements correspond to “xlow” and “ylow” and the very last values/elements are the the low-edges of the “overflow” bins, i.e. they directly correspond to “xup” and “yup”.

Thank you for your reply. But the binning is in x and y, not radius. How can one make sure each concentric ring of given thickness corresponds to one and only one bin, and no bin covers partially two successive rings?

Thank you,

Cristian

These are just names (“X” and “Y”).
You can treat “X” as the “radius” and “Y” as the “angle”.
You simply have to “MyHisto->Fill(radius, angle)” (where “radius” and “angle” were calculated by you in advance).

Of course, that was obvious :blush:

Thank you very much for your help. :smiley:

Best regards,

Cristian

Hello,

I am trying to follow your suggestions and produce a 2D histogram with the two variables radius and angles, drawn in polar coordinates. Since my data shows angular symmetry and only radial dependence, I have to draw a histogram with concentric rings of given thickness different colours showing the filling radial gradient.

So I have

U233_xy=new TH2F(“U233_xy”, “U233_xy”, 60, 0., 60., 1, 0., 360.);
U233_xy->Fill(radius, angle); // where radius>0 & radius< 60 and the angle is between 0 and 360

Due to the angular symmetry of the problem I have only one bin in angle, i.e. each ring of radius r is one bin in the 2D histogram

But drawing in polar coordinates

U233_xy->Draw(“lego2 pol”);

shows a chart with bins divided in angle and not radius.

So I decided to swap the radius and angle:

U233_xy=new TH2F(“U233_xy”, “U233_xy”, 1, 0., 360., 60, 0., 60.);
U233_xy->Fill(angle,radius);

but now

U233_xy->Draw(“lego2 pol”);

gives

Error in TView3D::FindPhiSectors: something strange: num. of critical sector not equal 2
^C
*** Break *** keyboard interrupt :0:
^C
*** Break *** keyboard interrupt
Root > *** Interpreter error recovered ***
Error in TView3D::FindPhiSectors: something strange: num. of critical sector not equal 2

I would be very grateful for any suggestions on drawing the “concentric rings” histogram.

Thank you very much,

Best regards,

Cristian

One single “angle” bin in TH2 makes no sense to me.
Simply use a TH1:
U233_r = new TH1F(“U233_r”, “U233_r”, 60, 0., 60.);
U233_r->Fill(radius);
U233_r->Draw();
BTW. For the “POL” TH2 drawing option, the “X” coordinate is mapped on the “angle” and the “Y” coordinate on the “radius”. See, for example: http://root.cern.ch/root/html/THistPainter.html

Hello,

Thank you for your reply. In order to plot the data to reflect the real geometry of the “concentric ring detectors” I was trying to plot a 2D histogram as concentric rings coloured in such a way to reflect the number of entries.

Having a 1D histogram in R and drawing it will produce the “bar” histogram which it is true that it gives all the information one can need.

However plotting the data as concentric rings as bins of a 2D histogram, so using polar coordinates, I thought it would be a nicer way to show the results.

I thought the order of the 2 variables in the 2D case must be angle and then radius, so I modified the code as mentioned before:

U233_xy=new TH2F(“U233_xy”, “U233_xy”, 1, 0., 360., 60, 0., 60.);
U233_xy->Fill(angle,radius);

but now

U233_xy->Draw(“lego2 pol”);

gives

Error in TView3D::FindPhiSectors: something strange: num. of critical sector not equal 2
^C
*** Break *** keyboard interrupt :0:
^C
*** Break *** keyboard interrupt
Root > *** Interpreter error recovered ***
Error in TView3D::FindPhiSectors: something strange: num. of critical sector not equal 2

Is there a way I could draw those concentric rings as bins of a 2D histogram?

Thank you,

Cristian

If you really want to use TH2 and draw it with “POL”, you will need a decent number of “angle” bins - something between 20 and 60.

Hello,

Thank you very much for your reply. I thought that having more bins in angle might solve this, since certainly some people needed to do a similar task in the past, so it has to be possible to do it…

Thank you,

Cristian :stuck_out_tongue: