Hi all
I have 3 questions need your help.
Is the 1st jpg in attachment a TH2D or TH3D?
I got a TH2D after looping over the TH1D in attachment 2, how can I get the root file similar to the 1st jpg?
Why is the TH3D after looping over the same TH1D empty?

(code also is uploaded)

Thank in advance,any help will be appreciated. :slight_smile:
exp.c (511 Bytes)
Respense.root (988 Bytes)

You macro has problems:

Processing exp.c...
In file included from input_line_10:1:
/Users/couet/Downloads/exp.c:16:22: error: cannot cast from type 'Double_t'
      (aka 'double') to pointer type 'TH1D *'
  Int_t BinContent = (TH1D*)p->GetBinContent(i);
/Users/couet/Downloads/exp.c:17:29: warning: implicit conversion from 'double'
      to 'Int_t' (aka 'int') changes value from 5.5 to 5 [-Wliteral-conversion]
  ~~~~~~~~                  ^~~

I have corrected the Int_t Bincontent = (TH1D*)p->GetBinContent(i) to Double_t BinContent = (TH1D*)p->GetBinContent(i); It can performs.
Can u tell me the difference between virtual void TH2::SetBinContent ( Int_t binx,
Int_t biny,
Double_t content)
and virtual void TH2::SetBinContent ( Int_t binx,
Int_t biny,
Double_t content )
Thought I could get a file by using TH2::SetBinContent method just like the 1st picture uploaded, however, I get a scatter diagram.

Please post something running so I can have a look at it .

Actually it doesn’t report anything.Here is the log on terminal.

Ok … I will fix the macro… but histo.root is missing

Here is the response.root, thank you
histo.root (31.2 KB)

void exp(){

   TFile f ("histo.root","READ");
   TH1D *p = (TH1D*)f.Get("h");
   TFile* file = new TFile ("Respense.root","RECREATE");
   TH2D *response = new TH2D("response","Response matrix",100,0,14,100,0,14);

   Double_t BinContent;

   for (Int_t i=1; i<=p->GetSize(); i++){
      BinContent = p->GetBinContent(i);

Thanks for your respond!
The result given by your macro seems has little difference with the Response.root I uploaded.
What should I do if I want a file that looks like the image when I firstly posted the question?
It that pic a TH2D or TH3D?

You should fill the TH2D completely … here you just file a few bins … and then drawing with the option LEGO should make it.

LEGO works! Thanks!
Another problem occurs when I fill TH2D with several histos.
I uploaded the code,part histo files and also the errors on the terminal.
Wish you can help.
histo10.root (31.3 KB)
histo5.root (31.2 KB)
exp2.c (712 Bytes)
error.c (309 Bytes)

what you get is correct … what do you think is wrong ??