TTree saving number of entries

Dear Experts,

I am working on some data analysis. I am trying to construct a TTree to store some data. However, the values that are being stored are incorrect. I want to display “sp” and “sp_err” for now. It seems that the TTree stores the number of entires rather than the actual number. I would appreciate any recommendations. Here is my code: (I have edited the files paths)
sep_macro.C (6.7 KB)

At first look, the output file should be fine.
Attach it for inspection if you think it is not.

BTW. Remove "spe->Write(); from inside of the “for” loop and after the “for” loop, add:

delete spe; // automatically deletes the tree, too

Unfortunately, I still have the same issue. Ideally I would like a TTree that can hold the sp variable in a way I can easily incorporate it in plots later. My end goal is something similar to this:

Here is the spe.root file:
spe.root (5.8 KB)

Processing sep_macro.C...
Error in <TFile::TFile>: file /Users/couet/Downloads/kpkm_final3.root does not exist
Error in <TFile::TFile>: file /Users/couet/Downloads/pippim_final1.root does not exist
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/sep_macro.C:120:40: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
                hist_Ldiff_phi_kp[i] = (TH1D*) file_phi->Get(hnames_phi[i]);

We cannot run your macro. Some files are missing.

Sorry, some of my files are too large to upload here. The is a drive folder with the files: GlueX Data – Google Drive

Your macro gives this plot:

what is wrong there ?

The TTree the macro creates is storing the wrong values. This should be storing the sp value (~2.5 → 3 unitless) so I can include it in another plot, but for some reason I think it is storing the number of entries in the TTree.

On second look, after inspecting the attached “spe.root” file, I noticed a bug.
Inside of the “for” loop, you need “sp = ...” and “sep_err = ...” but there must be NO “double” in front of them.

1 Like

Aha, that was it! Thank you for your help. Previously I did not have sp defined as a double outside of the for loop and I forgot to change this.