12def CreateInputFile(fname):
13 with ROOT.TFile.Open( fname,
"RECREATE",
"Demo ROOT file with histograms" )
as hfile:
15 hpx = ROOT.TH1F(
"hpx",
"This is the px distribution", 100, -4, 4 )
16 hpxpy = ROOT.TH2F(
"hpxpy",
"py vs px", 40, -4, 4, 40, -4, 4 )
17 hprof = ROOT.TProfile(
"hprof",
"Profile of pz versus px", 100, -4, 4, 0, 20 )
18 ntuple = ROOT.TNtuple(
"ntuple",
"Demo ntuple",
"px:py:pz:random:i" )
21 for i
in range( 2000 ):
22 px = random.randrange(0, 1)
23 py = random.randrange(0, 1)
25 r = random.randrange(0, 1)
31 ntuple.Fill( px, py, pz, r, i )
35def MergeFiles(files_to_cleanup, nfiles):
38 with ROOT.TFileMerger(
False)
as fm:
39 fm.OutputFile(
"merged.root")
40 files_to_cleanup.append(fm.GetOutputFile().GetName())
41 for i
in range(0, nfiles):
42 fm.AddFile(f
"tomerge{i}.root")
49 mode = ROOT.TFileMerger.kAll | ROOT.TFileMerger.kIncremental
54if __name__ ==
'__main__':
59 for i
in range(0, nfiles):
60 fname = f
"tomerge{i}.root"
61 CreateInputFile(fname)
62 files_to_cleanup.append(fname)
64 MergeFiles(files_to_cleanup, nfiles)
68 for filename
in files_to_cleanup: