Spherical harmonics


I’m trying to plot spherical harmonics but I’m facing a few issues.

The closest I can get is in the attached plot and macro.
The distance of the points from (0,0,0) as usual represent the module of the wave function while the color should represent the phase.

In this plot I have the following issues:

  • cannot rescale the axis to have a square box
  • if I update the color ranges to 0-2pi the plot is not updated (the portion with z<0 should be cyan).

Ideally I would like to have a closed surface painted with the colors corresponding to the phase but also the representation with dots would be ok, provided that the axis and colors can be fixed.

Many thanks for help.
y10.pdf (245 KB)
sferiche_nt.C (2.25 KB)

create a canvas with a square aspect ratio. Something like:

  TCanvas *c1 = new TCanvas("c1", "c1",1024,22,715,786);

How ?


thanks for the hint. The box is square however the x and y axis go from -0.25 to 0.25.
I’m trying to change this by using:

TH3F *ht=(TH3F *)gROOT->FindObject(“htemp”);

with no effect.

if I change the color ranges with
the color legend is updated in a strange way and the plot is not updated.

I think SetRangeUser doesn’t not allow to extend the range.

changing the min and max does not change the color map. as it should.

I cannot find a way to specify ranges when projecting this kind of histogram
has no effect.

one possible way:

  TH3F *h3 = new TH3F("h3", "h3", 10,-0.5,0.5,10,-0.5,0.5,10,-0.5,0.5);
  t->Draw("z:y:x:p","","colz same");

From time to time I get this error message
Error in TSelectorDraw::Begin: You cannot use option same when no 3D view exists

After some trial however I get these plots. With “same” option the colors that I was trying hard to put in the plot are completely lost.

I tried also this solution:
TH3F *h=new TH3F(“htemp”,"",10,-0.5,0.5,10,-0.5,0.5,10,-0.5,0.5);
Warning in TSelectorDraw::Begin: Deleting old histogram with different dimensions

There seems to be a bug also here

Moreover I don’t understand how something like “z:y:x:p” can be stored in an histogram with 3 dimensions.
without_same.pdf (454 KB)
with_same.pdf (469 KB)

it is not. The histogram is there for the frame only.

Thanks for the info.
Should I file a bug report?

Yes, see my reply in Jira. I think it answer your problem.
Let me know.

I believe the bug related to “Deleting old histogram with different dimensions” is the same as: sft.its.cern.ch/jira/browse/ROOT-4508

Note that in this VERY OLD “bug report”, one claims that this “brutal fix” should work: TFile *f = new TFile("sferiche_nt.root"); TTree *t; f->GetObject("t", t); TCanvas *c = new TCanvas("c", "c"); if (t) t->Draw("z:y:x:p","","colz"); TH3F *ht=(TH3F *)gROOT->FindObject("htemp"); if (ht) { ht->GetXaxis()->SetLimits(-0.5, 0.5); ht->GetYaxis()->SetLimits(-0.5, 0.5); ht->GetZaxis()->SetLimits(-0.5, 0.5); c->Modified(); c->Update(); }

Thanks for the suggestion. The x, y, z limits are working with SetLimits!

I still have the problem with colors but this I can work around by adding two fake points so that the color range is computed automatically.

Yes SetLimits allows to enlarge the histogram limits whereas SetRangeUser changes the the visible range within these limits.

So, maybe it’s time to “reopen” https://sft.its.cern.ch/jira/browse/ROOT-4508 :stuck_out_tongue:

It was closed because it cannot be reproduced.

I’ve just been able to “reproduce” the (more than two years old) https://sft.its.cern.ch/jira/browse/ROOT-4508 bugs without any problems with ROOT 5.34/18 (actually “heads/v5-34-00-patches@v5-34-18-531-g9e42712”).

  1. Execute the unchanged original macro from [url]Problem with logarithmic X/Y axes with TNtuple then try “h->GetNbinsX()” and/or “h->GetNbinsY()” -> you will get 20, while you should have got 100.
  2. Edit the original macro from [url]Problem with logarithmic X/Y axes with TNtuple and comment out BOTH lines “h->Get[XY]axis()->SetLimits([xy]min, [xy]max);” then execute the modified macro and you will immediately see that 3 points with X <= 1 are missing in the canvas.

BTW. I tried this macro with the newest ROOT 6.00/01. If I enable the line “Double_t xmin = 0.01, xmax = 50, ymin = 0.01, ymax = 50;” (just change the first “#if 0” into “#if 1”), I immediately get “*** Break *** segmentation violation”.

Ok it is reopen. Thanks.

1- Yes the histogram is deleted but it is clearly said with a warning. I guess there is a good reason to have done it this way. ie: redefining the histogram and printing a warning. I am not the author of this code. I cannot tell why.

2- I am getting a weird behaviour. Depending if SetEstimate is used or not I get the right limits or not . Again I am not the author of this code. Hard for me to tell why it behaves like that.

If you change “b:a:c>>h” into “b:a:c>>+h” you will also notice that even in this case, in which is it just supposed to “append data to an existing histogram”, it simply recreates the histogram. So maybe you could notify the one who is the “author of this code” that there are serious problems around.

P.S. Just to make it clear -> if “h” already exists then in case “b:a:c>>h” I expect that “h->Reset();” is automatically executed (just the integral, contents, errors, statistics, minimum and maximum of the histogram are “reset”, but everything else, including the binning, remains untouched).

I updated the reopened Jira report with your macro and explanation.
I also assigned it to the author of this code.