I have an analysis script that takes as input a root file and creates a new root file containing a tree with one branch that my script fills. However, I noticed that if I hadd two of my input root files and run the script on that input, the output I obtain is different than what I get if I run my analysis script on those two individual input root files, and then hadd those two output root files. But these definitely should be the same; I have TH2Ds in my output files that match regardless of where the hadding occurs. I’m not sure how to hadd these output file trees properly?
The relevant code in my script:
int hitsPer1cmVoxel;
TFile* outfile = new TFile(Form("CRTana_%s",input_crtfile.c_str()),"recreate");
TTree *tree = new TTree("tree","tree of hits per voxel");
tree->Branch("hitsPer1cmVoxel", &hitsPer1cmVoxel, "hitsPer1cmVoxel/I");
...
for (int i = 1; i <= (xyzBins[0]/voxelSize[0]); i++) {
for (int j = 1; j <= (xyzBins[1]/voxelSize[0]); j++) {
for (int k = 1; k <= (xyzBins[2]/voxelSize[0]); k++) {
hitsPer1cmVoxel = hitcount_xyz_th3d[0]->GetBinContent(i, j, k);
tree->Fill();
}
}
}
outfile->Write();
outfile->Close();
I first noticed that they different in the number of entries, but when I just now tried tree->Print() I get different output for other parameters too (e.g. baskets, compression):
For files hadded before running script (this is what I expect):
Hm, the second case has exactly twice the number of entries than the first one. Could it be that for the second run, files were hadd’ed before and after running the script?
No, each hadd only occurred once.
I just redid the procedure and get the same result. It goes like this:
First output:
1). hadd haddedInput.root input1.root input2.root
2). ./scriptExecutable haddedInput.root output.root
I get one file (output.root) and open this
For some reason, the two output.root files from both methods don’t match.
Additionally, when I tried hadding more than 2 files with these methods, the result in output #2 was more than double the number of entries in output #1.