# Spherical harmonics

**URL:** <https://root-forum.cern.ch/t/spherical-harmonics/17802>\
**Category:** ROOT\
**Created:** [June 24, 2014, 9:24am UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802 "2014-06-24T09:24:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 9:24am UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/1 "2014-06-24T09:24:10Z")

</div>

Hello,

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.  
Pietro  
[y10.pdf](https://root-forum.cern.ch/uploads/default/original/2X/8/81f5dd62f7156fd82ba06263f362b7bee3a7cf4a.pdf) (245 KB)  
[sferiche\_nt.C](https://root-forum.cern.ch/uploads/default/original/2X/b/bcc6663db2720cc60afe44726e34d2fa9c5c07ad.C) (2.25 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 11:25am UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/2 "2014-06-24T11:25:16Z")

</div>

> [@](#):
>
> - cannot rescale the axis to have a square box

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

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

> [@](#):
>
> - if I update the color ranges to 0-2pi […]

How ?

---

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 12:13pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/3 "2014-06-24T12:13:24Z")

</div>

Hello,

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”);  
ht-\>GetXaxis()-\>SetRangeUser(-0.5,0.5);  
ht-\>GetYaxis()-\>SetRangeUser(-0.5,0.5);  
ht-\>GetZaxis()-\>SetRangeUser(-0.5,0.5);

with no effect.

if I change the color ranges with  
ht-\>SetMinimum(0);  
ht-\>SetMaximum(2.\*TMath::Pi());  
the color legend is updated in a strange way and the plot is not updated.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 12:24pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/4 "2014-06-24T12:24:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 1:00pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/5 "2014-06-24T13:00:35Z")

</div>

I cannot find a way to specify ranges when projecting this kind of histogram  
t-\>Draw(“z:y:x:p\>\>htemp(10,-0.5,0.5,10,-0.5,0.5,10,-0.5,0.5)”,"",“colz”);  
has no effect.  
Pietro

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 1:12pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/6 "2014-06-24T13:12:40Z")

</div>

one possible way:

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

---

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 1:34pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/7 "2014-06-24T13:34:45Z")

</div>

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);  
h-\>Draw();  
c1-\>Show();  
t-\>Project(“htemp”,“z:y:x:p”,"");  
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](https://root-forum.cern.ch/uploads/default/original/2X/8/80d16073c1f8abbb2fb5c1f6b3ffa81f4e2de2ba.pdf) (454 KB)  
[with\_same.pdf](https://root-forum.cern.ch/uploads/default/original/2X/5/5381f03af1e6e8b3b4da16017f63ff7434762c21.pdf) (469 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 1:47pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/8 "2014-06-24T13:47:22Z")

</div>

> [@](#):
>
> Moreover I don’t understand how something like “z:y:x:p” can be stored in an histogram with 3 dimensions.

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

---

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 1:49pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/9 "2014-06-24T13:49:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 1:52pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/10 "2014-06-24T13:52:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 24, 2014, 2:13pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/11 "2014-06-24T14:13:47Z")

</div>

I believe the bug related to “Deleting old histogram with different dimensions” is the same as: [sft.its.cern.ch/jira/browse/ROOT-4508](https://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();
}`

---

<div class="post-metadata">

**Author:** ![cortese](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@cortese](https://root-forum.cern.ch/u/cortese)\
**Post date:** [June 24, 2014, 2:53pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/12 "2014-06-24T14:53:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 2:57pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/13 "2014-06-24T14:57:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 24, 2014, 3:18pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/14 "2014-06-24T15:18:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 24, 2014, 3:22pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/15 "2014-06-24T15:22:50Z")

</div>

It was closed because it cannot be reproduced.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 24, 2014, 4:10pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/16 "2014-06-24T16:10:27Z")

</div>

I’ve just been able to “reproduce” the (more than two years old) [https://sft.its.cern.ch/jira/browse/ROOT-4508](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](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/7) 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](https://root-forum.cern.ch/t/problem-with-logarithmic-x-y-axes-with-tntuple/14497/7) 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”.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 25, 2014, 7:34am UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/17 "2014-06-25T07:34:44Z")

</div>

Ok it is reopen. Thanks.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 25, 2014, 3:11pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/18 "2014-06-25T15:11:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 25, 2014, 3:51pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/19 "2014-06-25T15:51:26Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 25, 2014, 5:55pm UTC](https://root-forum.cern.ch/t/spherical-harmonics/17802/20 "2014-06-25T17:55:14Z")

</div>

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

[Next page](https://root-forum.cern.ch/t/spherical-harmonics/17802.md?page=2)
