Th3D Drawing

Greetings Rooter’s

I am trying to plot a 3D plot as shown on page 32 or 36 of the “Histograms.pdf”.
I try using options “BOX, SURF3, CONT3, glboxz, LEGO2…etc” and always get a scatter plot.

What am I doing wrong?

Here is the code:

#include "TStyle.h"
#include "TList.h"
#include "TH3.h"
#include "TF1.h"

void Th3DTry(){

  TChain *ch1 = new TChain("Rho");
  Int_t entry = ch1->GetEntries();
  TH3D *hd3 = new TH3D("hd3","hd3",100,0.45,0.55,100,1.1,5.7,100,0.0,2.8);
  Double_t IV_PipPim;
  Double_t DOCA_ang;
  Double_t E_g;
  Double_t Pip_Ptot;
  for(int i =0;i<entry;i++){
    if(!(i%1000000)) std::cout << "done " << i << " out of " << entry << " ==> " << double(i)*100.0/double(entry) << "%" << std::endl;  



Using ROOT version 5.30

From the manual

“3-D Histograms
By default a 3D scatter plot is drawn. If the “BOX” option is specified, a 3D box with a volume proportional to the cell content is drawn.”

I cannot produce such a plot to validate if this is a true statement.

How do I accomplish this?


your data file is missing

Why is a data file necessary?
Use the above code with 3 variables, random or quasi-static will reproduce the original problem.

I get:

Processing Th3DTry.C...
Error in <TFile::TFile>: file run_56515_skimmed_tripinc_0.root does not exist
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] 

and receive an empty canvas. Not even a scatter plot.
Provide a running macro showing the problem.

#include "TStyle.h"
#include "TList.h"
#include "TH3.h"
#include "TF1.h"

#include "TCanvas.h"
#include "TChain.h"
#include "TVector3.h"
#include "TMath.h"
#include "TFile.h"
#include "TSystem.h"
#include "TGStatusBar.h"
#include "TSystem.h"
#include "TXMLEngine.h"
#include "TTree.h"
#include "TLorentzVector.h"
#include "TNtuple.h" 
#include "TString.h"

#include <cstdlib>
#include <vector>
#include <unistd.h>

void Th3DTry(){
  Double_t px,py,pz;

  TH3D *hd3 = new TH3D("hd3","hd3",100,0.45,0.55,100,1.1,5.7,100,0.0,2.8);

  for (Int_t i = 0; i < 50000; i++) {

    Double_t random = gRandom->Rndm(1);
    pz = sqrt(pow(px,2)+pow(py,2));



This simple code reproduces the same result

I think your version of ROOT is too old.
I get the boxes with your macro.
See the attached picture.

Please read my original post, where I explicitly define my root version.

Yes I saw you are running 5.30.
I am running 5.34
I ran your macro with this version (5.34), and get the plot I posted which is correct seems to me.
If you do not get the same, it means your version has a problem with this option, therefore it is too old.

Well only other version available is 5.32 and according to the .pdf file that states the changes made from 5.30 to 5.32, this should not be an issue, therefore it should not be “too old”.

Let me be a little more explicit in what I am trying to accomplish.
I have 3 variables which I believe have correlation. Plotting 2 of these variables and profiling it will not show the correlation. So I am trying to accomplish this by plotting a 3D histogram with some option to view this.

I have looked into using the glboxz and the glcolz, etc and I this does not produce a clear enough representation for analysis.

Now as my original post stated: "I am trying to plot a 3D plot as shown on page 32 or 36 of the “Histograms.pdf”.

Can this be done?


As far as I am aware, 3-D histogram drawing supports only (page 28 in the “3Histograms.pdf” and
so, it makes no sense to try:

You might also try “GLBOX”, “GLBOX1"”, “GLISO”, see:

I tried your macro on ROOT “5.28/00”, “5.28/00g”, “5.30/03” and “5.31/01”.
In all cases I get the same picture as Olivier.

[quote=“Pepe Le Pew”]As far as I am aware, 3D histogram drawing supports only (page 28 in the “3Histograms.pdf”):
so, it makes no sense to try:

I tried your macro on ROOT “5.28/00”, “5.28/00g”, “5.30/03” and “5.31/01”.
In all cases I get the same picture as Olivier.[/quote]

3D histogram also supports glcolz and glboxz which is not in “3Histograms.pdf”, so it made sense to try them all.

Regardless, it appears ROOT does not have the capability to produce the histogram I need for my analysis.


You said:

With the lastest macro I get the box plot as shown on the picture I sent.
So for me it is fine.
Can you sent the picture you get with the last macro you sent ? … if it is not a box plot either you are using a version which is too old or there is a bug on the platform you are running root.

I first said

I then stated the options I used and the described the output. The histogram that is produced by the macro is identical to the histogram produced by me. This representation is not what I am trying to analyze, I am trying to produced 3D histograms using 3 variables that plot like 3D plots on page 32 or 36 of “Histograms.pdf”.

NONE of the pictures on pages 32 and 36 in the “3Histograms.pdf” shows any 3-D histogram.
They ALL are 2-D histogram representations.

You would probably need to create a 2-D histogram in which “X” and “Y” axes will be the first 2 of your variables and the 3-rd variable will be the “bin-contents”.

Or maybe better you could try to have a look at the TGraph2D class and/or the TGraph2DErrors class

Here is a example of what I would like to do.
I have uploaded 2d.jpg, it is a 2D plot of a particles momenta vs. its effective mass.

Notice the density at 0.497 on the x axis.

I would like to plot the z-axis as another variable, say a beam profile.
I have attempted to use TProfile2D

However the density at 0.497 is no longer present, I believe this is due to the nature of the TProfile.

I have uploaded a small .root file along with a new .C script.

I hope this clarifies what I have been attempting to portray.

small.root (1.89 MB)
Th3DTry.C (2.65 KB)

again missing data:

to ch1->Add(“small.root”);

ie, because that is the name of the .root file I uploaded

Yes you are right. I’ll ask Lorenzo to give you more details.

About the suggestion to use TGraph2D

Heres a quote from

This is true, I have over 40k data points, trying to use TGraph2D on 1500 data points ran overnight without results.

Also to remark of Pepe Le Pew post

My original post was asking for a method to reproduce such looking graphs using the 3D histogram, never did I seem to make it implied that the images on pages 32 and 36 were drawn using the 3D histogram, if it were that easy, this help request would not have been sent