Please read tips for efficient and successful posting and posting code
ROOT Version: 6.24.06
Platform: /
Compiler: gcc/9.3.0
I am trying to combine 3 root files (attached in cernbox link at the bottom of post) using hadd in order to obtain the total monte-carlo weighted samples. I did the following in the terminal:
leongc11@cedar5: hadd AllHT.root 410444.root 410471.root 410429.root
hadd Target file: AllHT.root
hadd compression setting for all output: 1
hadd Source file 1: 410444.root
hadd Source file 2: 410471.root
hadd Source file 3: 410429.root
hadd Target path: AllHT.root:/
leongc11@cedar5: root -l AllHT.root
root [0]
Attaching file AllHT.root as _file0…
(TFile ) 0x25c0de0
root [1] .ls
TFile* AllHT.root
TFile* AllHT.root
KEY: TTree TTree_500000_350000;1 TTree_500000_350000
root [2] TTree_500000_350000->Draw(“lj1LV.M()/lj1LV.M() >> EN”, “weight*(region == 66)”); EN->Integral()
(double) 9572.6191
root [3]
which gives me the expected result of 9572.6191. But when I combined the 3 files in a different order shown below it gives me a different answer:
leongc11@cedar5: hadd AllHT.root 410471.root 410429.root 410444.root
hadd Target file: AllHT.root
hadd compression setting for all output: 1
hadd Source file 1: 410471.root
hadd Source file 2: 410429.root
hadd Source file 3: 410444.root
hadd Target path: AllHT.root:/
leongc11@cedar5: root -l AllHT.root
root [0]
Attaching file AllHT.root as _file0…
(TFile ) 0x3fbe4e0
root [1] TTree_500000_350000->Draw(“lj1LV.M()/lj1LV.M() >> EN”, "weight(region == 66)"); EN->Integral()
(double) 9567.2012
root [2]
I also tried to combine these 3 files using a python script I wrote without hadd,
#!/usr/bin/env python3
from ROOT import TFile, TTree, TBranch, TChain
# Working combination
input_names = ["410444.root", "410471.root", "410429.root"]
#input_names = ["410471.root", "410429.root", "410444.root"]
f_output = TFile.Open("AllHT.root", "RECREATE")
t_output = TChain("TTree_500000_350000", "TTree_500000_350000")
tree = TTree("TTree_500000_350000", "TTree_500000_350000")
weight_br = TBranch()
for name in input_names:
f = TFile.Open(name,'read')
print(f.Get('TTree_500000_350000').GetEntries())
t_output.Add(name)
print(t_output.GetEntries())
#write this TCHain into a TFile
f_output.WriteObject(t_output,"TTree_500000_350000")
but the problem of getting different results using different files combination still remains, which leads to think it’s either a problem within the ROOT file itself or with the TH1::Integral() function. Any help would be appreciated.
CERNbox link: CERNBox