3 ROOT.gROOT.SetBatch(
True)
7 from argparse
import ArgumentParser
8 parser = ArgumentParser()
9 parser.add_argument(
"inputFile", type=str)
10 parser.add_argument(
"fraction", type=float)
11 parser.add_argument(
"outputFile", type=str)
12 options = parser.parse_args()
14 frac = options.fraction
15 input = ROOT.TFile(options.inputFile)
16 output = ROOT.TFile(options.outputFile,
"RECREATE")
17 for k
in input.GetListOfKeys():
18 print(k.GetName(), k.GetClassName())
19 if k.GetClassName() ==
"TDirectoryFile":
20 print(
" processing directory ",k.GetName())
21 din = input.Get(k.GetName())
22 dout = output.mkdir(k.GetName())
23 for i
in din.GetListOfKeys():
24 if i.GetClassName() ==
"TTree":
25 src = din.Get(i.GetName())
26 newEntries =
int(src.GetEntries()*frac)
27 print(
" cropped TTree",i.GetName(),
", original entries",src.GetEntries(),
", new entries",newEntries)
28 cloned = src.CloneTree(newEntries)
29 dout.WriteTObject(cloned, i.GetName())
30 elif i.GetClassName() !=
"TDirectory":
31 dout.WriteTObject(i.ReadObj(), i.GetName())
32 print(
" copied ",i.GetClassName(),i.GetName())
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)