Problem with tree and histogram

I have a problem with the programs in attached:
root.C create three files: Maxwell.dat, Maxwell.root and TABLE.dat;
plot.C reads file .root and its tree, so I declare a new tree and three histograms to plot data generated in root.C.
For the first (h1) and second (h2) histogram I haven’t problems ( they are both TH2F), but with h3, that is a TH3F, I have two problems( c2.png in attached):

  • Statistics are all zero ( so I think the TH3F has problems to read tree’s data);
  • Range of palette is wrong: radius of sphere is 1, so distance of markers can’t be more than one.

I have another question: if I put in my program the function " system(“read”)" the menus bar of Canvas isn’t shown, how can I resolve It?

Thanks and sorry for my English :smiley:
root.C (5.47 KB)
plot.C (3.23 KB)


When I run your macro I get:


Processing root.C...
In file included from input_line_10:1:
/Users/couet/Downloads/root.C:145:7: warning: switch condition has boolean value [-Wswitch-bool]
             switch(ratio>=test)
             ^      ~~~~~~~~~~~
type Nmol: 1
type Molecule kind (max 20 chars & no blanks): 

Can you fix the code and tell me what I should answer to the questions your program asks ?

[quote=“couet”]When I run your macro I get:


Processing root.C...
In file included from input_line_10:1:
/Users/couet/Downloads/root.C:145:7: warning: switch condition has boolean value [-Wswitch-bool]
             switch(ratio>=test)
             ^      ~~~~~~~~~~~
type Nmol: 1
type Molecule kind (max 20 chars & no blanks): 

Can you fix the code and tell me what I should answer to the questions your program asks ?[/quote]

Right! I fixed programs ( and I put them in attachments of first post). Now values are just entered.
Thank you

So it is ok now ? we can mark this as solved ?

No… I put values in root.C so you can compile program with right values, but the problems about first post persist.

I simplified your macro to :

void plot(){
   TFile *f = new TFile("Maxwell.root");
   TTree *tree3= (TTree*)f->Get("tree");
   TH3F *h3 = new TH3F("h3","Representation of gas in the sphere",10,-1,1,10,-1,1,10,-1,1);
   gStyle->SetPalette(55);
   tree3->Draw("x:y:z:8*sqrt(x*x+y*y+z*z)>>h3"," sqrt(x*x+y*y+z*z)>0","colz",100000);
}

The stats are 0 … it looks like the histogram is not filled…

Actually I can reproduce this behavior with the simple ntuple produced by :
root.cern.ch/doc/master/hsimple_8C.html

root [0] ntuple->Draw("px:py:pz:sin(px)>>h3","","colz")
root [1] h3->GetMean(1)
(Double_t) 0.00000
root [2] h3->GetMean(2)
(Double_t) 0.00000
root [3] h3->GetMean(3)
(Double_t) 0.00000
root [4] h3->GetEntries()
(Double_t) 25000.0

It looks like the histogram is filled because there is 25000 entries… but the Means are nul.

In fact in that case the histogram is not filled. It is a polymarker 3d as explained here:
root.cern.ch/doc/master/classTT … 3c70bfe8d7

[quote=“couet”]In fact in that case the histogram is not filled. It is a polymarker 3d as explained here:
root.cern.ch/doc/master/classTT … 3c70bfe8d7[/quote]

I edit root.C adding:

tree->Branch("xx",&recn.x,"x"); tree->Branch("yy",&recn.y,"y"); tree->Branch("zz",&recn.z,"z");

and plot.C with:

tree3->SetBranchAddress("xx",&x); tree3->SetBranchAddress("yy",&y); tree3->SetBranchAddress("zz",&z); for(int i=0;i<1000000;i++) { tree3->GetEntry(i); h3->Fill(x,y,z); }

Now 3D histogram is filled and statistics in the Canvas are rights. But there is a problem with colour, if I write

gStyle->SetPalette(55); h3->Draw("colz")
it doesn’t work ( view attachment).


The COL option is not implemented for 3D histograms. See the available options here:
root.cern.ch/doc/master/classTH … .html#HP25

The COL option is not implemented for 3D histograms. See the available options here:
root.cern.ch/doc/master/classTH … .html#HP25

you can try GL may be:

root.cern.ch/doc/master/classTH … html#HP290

A brutal fix:

{
  gStyle->SetPalette(55);
  TFile *f = TFile::Open("Maxwell.root");
  TTree *t; f->GetObject("tree", t);
  TH3F *h3 = new TH3F("h3", "Representation of gas in the sphere", 10, -1, 1, 10, -1, 1, 10, -1, 1);
  t->Project("h3", "z:y:x", "sqrt(x*x+y*y+z*z)>0", "", 100000);
  ((TArrayF *)h3)->Reset(); // "reset" histogram's bins' contents
  t->Draw("z:y:x:8*sqrt(x*x+y*y+z*z)>>+h3", "sqrt(x*x+y*y+z*z)>0", "colz", 100000);
}

BTW. Another example can be found in this thread. For "e1:e2" draw expressions, which produce unbinned 2-d scatter-plots (TGraph), there is this thread.

Good solution, thanks!!