1 |
import ROOT
|
2 |
from printcolor import printc
|
3 |
|
4 |
def copytree(pathIN,pathOUT,prefix,newprefix,file,Aprefix,Acut):
|
5 |
|
6 |
print "##### COPY TREE - BEGIN ######"
|
7 |
print "Input File : %s/%s%s.root " %(pathIN,prefix,file)
|
8 |
print "Output File : %s/%s%s%s.root" %(pathOUT,newprefix,Aprefix,file)
|
9 |
|
10 |
input = ROOT.TFile.Open("%s/%s%s.root" %(pathIN,prefix,file),'read')
|
11 |
output = ROOT.TFile.Open("%s/%s%s%s.root" %(pathOUT,newprefix,Aprefix,file),'recreate')
|
12 |
|
13 |
input.cd()
|
14 |
obj = ROOT.TObject
|
15 |
for key in ROOT.gDirectory.GetListOfKeys():
|
16 |
input.cd()
|
17 |
obj = key.ReadObj()
|
18 |
#print obj.GetName()
|
19 |
if obj.GetName() == 'tree':
|
20 |
continue
|
21 |
output.cd()
|
22 |
#print key.GetName()
|
23 |
obj.Write(key.GetName())
|
24 |
|
25 |
inputTree = input.Get("tree")
|
26 |
nEntries = inputTree.GetEntries()
|
27 |
output.cd()
|
28 |
print '\n\t copy file: %s with cut: %s' %(file,Acut)
|
29 |
outputTree = inputTree.CopyTree(Acut)
|
30 |
kEntries = outputTree.GetEntries()
|
31 |
printc('blue','',"\t before cuts\t %s" %nEntries)
|
32 |
printc('green','',"\t survived\t %s" %kEntries)
|
33 |
outputTree.AutoSave()
|
34 |
output.ls()
|
35 |
print "Writing output file"
|
36 |
output.Write()
|
37 |
print "Closing output file"
|
38 |
output.Close()
|
39 |
print "Closing input file"
|
40 |
input.Close()
|
41 |
|
42 |
print "##### COPY TREE - END ######"
|