Hi,
I am trying to draw a TH2D plot in a polar coordinate. I have tried:
tree->Draw(“phi:theta>>h2”, “”, “pollego2z”);
(its top view is the 1st plot attached)
and
tree->Draw(“phi:theta>>h2”, “”, “polcolz”);
(the 2nd plot attached)
.
But both of them are not satisfied. Plot 1 needs to add axis and y-axis of plot 2 has a problem. I am wondering if I can plot a TH2D plot in a polar coordinate like :
I do not understand how you get the first plot. In my case I get 2 axis when I use POLCOLZ. See the attached picture. I am using the latest ROOT version.
Because I would like to use the first one, but I don’t manage to do so with “Draw(pol colz);” or your function. Also do you now if theta has to be in degree or radian ? The documentation don’t say.
I had some success trawling through the source code to understand what’s going on. It seems that the axis ranges are messed up if when drawing a TH2 with Draw(“COLZ POL”). I managed to get it working by drawing a dummy histogram beforehand.
[code]void PolarTH2()
{
gStyle->SetOptStat(0);
Double_t rmax(1.);
TH2D* pol_his = new TH2D("polarHist", "polarHist", 20, 0., 2.*TMath::Pi(), 20, 0., rmax); // the polar data. X maps to theta, Y maps to R
Double_t theta, r;
//fill the histogram with something nice.
for(Int_t i=1; i<=pol_his->GetNbinsX(); i++)
{
theta = pol_his->GetXaxis()->GetBinCenter(i);
for(Int_t j=1; j<=pol_his->GetNbinsY(); j++)
{
r = pol_his->GetYaxis()->GetBinCenter(j);
pol_his->SetBinContent(i, j, r*cos(2.*theta) );
}
}
//make a dummy histogram to set the axis range from -rmax to rmax in both directions
TH2D* dummy_his = new TH2D("dummy", "histo title", 100, -rmax, rmax, 100, -rmax, rmax);
TCanvas* c1 = new TCanvas("theCanvas", "theCanvas", 600, 600);
dummy_his->Draw("COL"); // draw the dummy histogram first
pol_his->Draw("COL POL SAME"); // now draw the data histogram. If it has "SAME" it will use the first histogram ranges