Issues with combining ROOT files in different order


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

Try to create a histogram first:

gROOT->cd(); // newly created histograms should go here
TH1D *h_EN = new TH1D("h_EN", "EN;ratio;counts", 100, x_min, x_max); // set apropriate "x_min" and "x_max"
TTree_500000_350000->Draw("lj1LV.M()/lj1LV.M() >> h_EN", "weight*(region == 66)");
std::cout << h_EN->Integral() << std::endl;

Thank you for your reply, this does help to produce the correct result.
Just to follow up, why does it not give the correct result if I don’t create the histogram first? From what I recall from the root tutorial this step wasn’t necessary.

It could be that it’s the difference between the “float” TH1F and the “double” TH1D (e.g., try with “TH1F *h_EN = new TH1F(...);”).
Search also for “Hist.Precision” in the “${ROOTSYS}/etc/system.rootrc” file.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.