# Straight line through TH3

**URL:** <https://root-forum.cern.ch/t/straight-line-through-th3/39104>\
**Category:** Newbie\
**Created:** [April 26, 2020, 5:21pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104 "2020-04-26T17:21:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 26, 2020, 5:21pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/1 "2020-04-26T17:21:57Z")

</div>

Hello,

I want to make a plot like this

 ![ImpactsWithLine(Greys)LinewKolor](https://root-forum.cern.ch/uploads/default/original/3X/4/7/47178b9d5787553bd5b16081eb22310454c42e34.png)

three “layers” of histograms from one TH3 with a line going across them.

But what I get from [this code](https://root-forum.cern.ch/uploads/short-url/zXtgOnySUnl9TmnvaLVd3C95tPG.cc) (1.6 KB) is this plot

 ![ImpactsWithLine(Greys)](https://root-forum.cern.ch/uploads/default/original/3X/3/4/34e80c400088bc31ab6e1b975c83bfb5038241dd.png)

As seen (it’s better if you run it yourselves), the line is at the back of the entire histogram, and if I draw it after the TH3, it’s completely in the front. I can’t seem to get the desired effect of going through each “layer”.

I’d appreciate your help with this problem, thanks in advance to you all.

ROOT Version: 6.14/04  
Platform: Ubuntu

---

<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:** [April 27, 2020, 7:57am UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/2 "2020-04-27T07:57:41Z")

</div>

You macro doesn’t run:

```auto
root [0] 
Processing Many3DHistograms.cc...
In file included from input_line_11:1:
/Users/couet/Downloads/Many3DHistograms.cc:40:5: error: use of undeclared identifier 'ZOffset3D'
    ZOffset3D(h, 100); 
    ^
/Users/couet/Downloads/Many3DHistograms.cc:62:5: error: use of undeclared identifier 'NewPalette'
    NewPalette(T, 100,19,12); //greys, works great
    ^
/Users/couet/Downloads/Many3DHistograms.cc:73:1: error: C++ requires a type specifier for all declarations
Many3DHistograms(Nc,N);
^

```

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [April 27, 2020, 8:17am UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/3 "2020-04-27T08:17:01Z")

</div>

@couet and what would be the right type for this - `TGraph2D` as suggested by @juliangb or would you use e.g. `TPolyMarker3D`?

---

<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:** [April 27, 2020, 8:58am UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/4 "2020-04-27T08:58:44Z")

</div>

We have a similar example [here](https://root.cern/doc/master/annotation3d_8C.html).  
I will try to fix this macro and see what’s can be done.

---

<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:** [April 27, 2020, 9:02am UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/5 "2020-04-27T09:02:43Z")

</div>

> [@juliangb](#):
>
> But what I get from [this code](https://root-forum.cern.ch/uploads/short-url/zXtgOnySUnl9TmnvaLVd3C95tPG.cc) (1.6 KB) is this plot

In “this code” the two functions ZOffset3D and NewPalette are missing. Can you post a version containing them ?

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 27, 2020, 2:13pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/6 "2020-04-27T14:13:51Z")

</div>

I’m sorry, here it is with all the functions

[Many3DHistograms.cc](https://root-forum.cern.ch/uploads/short-url/lazkLpr8scVmEeoarlVnMa465q.cc) (2.6 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:** [April 27, 2020, 2:36pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/7 "2020-04-27T14:36:46Z")

</div>

I can run your macro now. I see you are using a TGraph2D to draw the line. I would suggest you look at [https://root.cern/doc/master/annotation3d\_8C.html](https://root.cern/doc/master/annotation3d_8C.html) and draw the line  
as done in that example using [TPolyLine3D](https://root.cern/doc/master/classTPolyLine3D.html)

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 27, 2020, 4:04pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/8 "2020-04-27T16:04:04Z")

</div>

I did use PolyLine3D as you indicated before, but ended up with the same result:

 ![ImpactsWithLine(LowRangeWithPolyLine)](https://root-forum.cern.ch/uploads/default/original/3X/1/7/17704539c7b82441b58c901c310f3b529d7cb23a.png)

Updated code: [Many3DHistograms.cc](https://root-forum.cern.ch/uploads/short-url/ezelFgz5fkQnp1XdSxEWB1eakK3.cc) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![RongkunWang](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rongkunwang/32/36036_2.png) [@RongkunWang](https://root-forum.cern.ch/u/RongkunWang)\
**Post date:** [April 27, 2020, 4:17pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/9 "2020-04-27T16:17:06Z")

</div>

I found this topic interesting so I gave it a try:  
if the line is drawn first, it will be behind any element of it.  
if the TH3D is drawn first, the line always float in front of the histogram.  
It seems like the visualization didn’t seem to handle the relation between objects?

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 27, 2020, 4:52pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/10 "2020-04-27T16:52:05Z")

</div>

> [@RongkunWang](#):
>
> It seems like the visualization didn’t seem to handle the relation between objects?

Yes, that’s exactly my problem. I don’t know if there’s an object that can draw a curve, interacting with (in this case) a TH3 object.

---

<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:** [April 28, 2020, 8:19am UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/11 "2020-04-28T08:19:20Z")

</div>

You can draw the line after like in the attached version of you macro but that does not really help as the line and the TH3s do not known each other and there fore there is not proper hidden line removal done.

[Many3DHistograms.cc](https://root-forum.cern.ch/uploads/short-url/7UDRMxbpWPcxYHnoy1z56b58qfV.cc) (2.4 KB)

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 28, 2020, 12:57pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/12 "2020-04-28T12:57:18Z")

</div>

Exactly, in my macro I drew it before the histogram, but as I said before

> [@juliangb](#):
>
> if I draw it after the TH3, it’s completely in the front

Isn’t there an object that can draw a curve that goes through another? Or a way to make it look like it? I looked everywhere and couldn’t find an answer.

---

<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:** [April 28, 2020, 1:11pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/13 "2020-04-28T13:11:10Z")

</div>

May be TGeo machinery . What you are doing looks like a detector with tracks.

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 28, 2020, 2:24pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/14 "2020-04-28T14:24:26Z")

</div>

> [@couet](#):
>
> What you are doing looks like a detector with tracks.

Yes, that’s exactly what I want to reproduce. Thanks for the advice, I’ll check it.

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 28, 2020, 2:33pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/15 "2020-04-28T14:33:59Z")

</div>

I could find a way to make it look better, although it still has an error.

This is the new code: [Many3DHistograms.cc](https://root-forum.cern.ch/uploads/short-url/kUPKkuQl0dRb0nBpUYNVRkaU8Bg.cc) (4.2 KB) (sorry it’s quite inelegant, couldn’t think of a better way of doing it).

This is the plot if you see it from above:

 ![ImpactsWithLine_Nc3-seems-good](https://root-forum.cern.ch/uploads/default/original/3X/2/a/2ad42053e3820086e0ab46cea6484a7e4f1f08ba.png)

It’s the same if you rotate it around the z-axis, it seems to accomplish the desired effect.

But if you want to see it from below, it looks like this:

 ![ImpactsWithLine_Nc3-error](https://root-forum.cern.ch/uploads/default/original/3X/0/d/0d490dd45cb186cc641255c7c013484eb74c21b8.png)

So it still needs some adjustments.

While I’m at it, how can I draw the palette bar at the right from a given value, let’s say 100?

---

<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:** [April 28, 2020, 2:42pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/16 "2020-04-28T14:42:13Z")

</div>

> [@juliangb](#):
>
> While I’m at it, how can I draw the palette bar at the right from a given value, let’s say 100?

the minimum of the palette is the minimum of the histogram drawn with option colz.

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [April 28, 2020, 2:58pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/17 "2020-04-28T14:58:26Z")

</div>

Hi  
how about going to “real 3d”  
[Many3DHistograms\_OS.cc](https://root-forum.cern.ch/uploads/short-url/btPJmKvJSgNN76FUgphZUEl2DS6.cc) (4.0 KB)  
In this you probably wouldnt need the TH3  
Otto

 ![Screenshot 2020-04-28 at 17.11.16](https://root-forum.cern.ch/uploads/default/original/3X/c/1/c12451a78fa59af5d84c51412e5e2931b18edd9e.png)

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 28, 2020, 4:24pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/18 "2020-04-28T16:24:39Z")

</div>

I need the minimum of the histogram to be 0, but I don’t want to show values between 0 and 100 in the palette bar, I don’t know if there is a way of changing it without modifying the histogram.

---

<div class="post-metadata">

**Author:** ![juliangb](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/juliangb/32/21448_2.png) [@juliangb](https://root-forum.cern.ch/u/juliangb)\
**Post date:** [April 28, 2020, 4:41pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/19 "2020-04-28T16:41:30Z")

</div>

This seems really good, but when I try to run it it gives me the error  
`error: invalid use of incomplete type ‘class TGLViewer’ glv->DoDraw();`

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [April 28, 2020, 4:49pm UTC](https://root-forum.cern.ch/t/straight-line-through-th3/39104/20 "2020-04-28T16:49:10Z")

</div>

Hi,  
your ROOT installation seems n o t to contain OpenGL  
[https://root.cern.ch/building-root](https://root.cern.ch/building-root)  
to find out type:

```auto
root-config --config

```

and look for  
OPENGL\_gl\_LIBRARY=/usr/lib/x86\_64-linux-gnu/libGL.so

Otto

[Next page](https://root-forum.cern.ch/t/straight-line-through-th3/39104.md?page=2)
