Home | News | Documentation | Download

Show slices of TH3 in 3D view

Hi all,

I would like to draw a set slices of a TH3D in a 3D view. In other words: I would like to have a 3D coordinate systems and at several z positions, I would like to add planes in which TH2s with option “colz” are drawn. The TH2s should show only the content of the TH3 with the given z of the plane.

I know how to get the corresponding TH2. For example, to get the plane at bin z=50, I could do:
int i_zbin=50;
TH3D* my3dhist->GetZaxis()->SetRange(i_zbin,i_zbin);
TH2D* my2dslice50=(TH2D*)my3dhist->Project3D(“yx”);

But I have no idea how to draw this TH2D in a plane with z=50 in a 3D coordinate system.
Do you have an idea how to do this?

Thanks!

Not easy to do. There is not direct option to do that.

I also thought about the following trick: One might copy the TH3D into a new one, but only fill the bins in the selected slices. Then, one could draw the new, filtered TH3D with option “BOX2Z”. But then, one would have to make sure that the scaling of the boxes is chosen such that they all have the same size, namely exactly the voxel size without any gap. Is there a way to achieve this?

I found this post. Here, it was supposed to use an TNtuple with four entries: x,y,z,val. Then, one draws the tuple with option “col” or “colz” as

ntuple->Draw("x:y:z:val","","COL");

Unfortunately, for me (root version 6.20.00), only the first point of the ntuple is drawn and its fourth component determines its color. If I enter only
ntuple->Draw(“x:y:val”,"","");
then I get a TPolyMarker3D with all points, but they of course all have the same color.

Yes the colour is mapper on the fourth variable.
You can define Z=a constant
like :slight_smile:

ntuple->Draw("x:y:1.:val","","COL");

I see how this is done in this post. Unfortunately this not really what I want because the markers do not form a nice surface.

I found that using OpenGL is heading in the right direction. It looks like I want to do the exact same thing as here. I found a way that is very close to want I want:
If hist is my TH3F*, I do

double max=hist->GetMaximum()+1;
hist->SetMinimum(max+1); //do not show any bins
hist->Draw(“glbox”);

Now, I can move slices through the volume on which cuts are shown in colors.There are only three things missing:

  1. I would like to set the positions of the planes programmatically
  2. I would like to add more than only one slice per axis
  3. I need the color palette that was used to create the cuts
    Do you have any ideas how to this this?

I do not think you can do these things with the current implementation.
some coding will be required.
An other way would be to use the option BOX2 on a TH3