I am working with a TFile that contains a lot of TH1F objects. Each TH1F is a histogram of 2048 points. I am trying to open the file, read a particular TH1F (Histo1 in this example), and then write it to another TFile as a TLeaf in a TBranch in a TTree. I am trying to use the code below, but it segfaults.
The declaration of a branch is the bit that breaks it. If I remove the & from wf, the code runs, but it just fills TH1F inside the branch with 2048 points of rubbish pointer addresses. I have checked the contents of wf using wf->GetBinContent(), and wf contains the correct values.
Any help with getting this to run will be appreciated!
wf is the address of the histogram itself, i.e. its metadata, not the address data stored in the histogram! (actually, &wf it is even the address of the pointer (on the stack) to the histogram metadata!)
You could use histogram->GetArray to get the underlying data array (but consider underflow/overflow bins as well). Also, what is fisevent in your code? What do you want to fill? It might be cleaner to copy the data from the histogram into a separate array.