diff --git a/Phys/B2KShh/job/selection.py b/Phys/B2KShh/job/selection.py index 6f1fc2f..9b53ce3 100644 --- a/Phys/B2KShh/job/selection.py +++ b/Phys/B2KShh/job/selection.py @@ -29,16 +29,23 @@ infile = r.TFile(source_path + source, 'read') trees = [] + +class treeWithDirectory(object): + def __init__(self, key, obj): + self.tree = obj + self.location = key.split('/')[1] + + for k, o in getall(infile): if 'TTree' in o.ClassName(): - trees.append(o) + trees.append(treeWithDirectory(k, o)) -recotrees = [t for t in trees if 'MCTruth' not in t.GetName()] -truthtrees = [t for t in trees if 'MCTruth' in t.GetName()] -if len(truthtrees) == 1: - truth_tree = truthtrees[0] -else: - truth_tree = None +recotrees = [t for t in trees if 'MCTruth' not in t.tree.GetName()] +#truthtrees = [t for t in trees if 'MCTruth' in t.tree.GetName()] +#if len(truthtrees) == 1: +# truth_tree = truthtrees[0] +#else: +# truth_tree = None os.system('mkdir -p %s' % target_path) if not os.path.isfile(target_path + source): @@ -48,16 +55,22 @@ outfilename = source.split('.')[0] + '_' + '_'.join(sel_names) + '.root' print '\tCreating file %s ...' % outfilename outfile = r.TFile(target_path + outfilename, 'recreate') -clones = [] -if truth_tree: - print '\tCopying MCTruth tree...' - #truth_tree.AutoSave() - clones.append(truth_tree.CopyTree('')) +#clones = [] +#if truth_tree: +# print '\tCopying MCTruth tree...' +# #truth_tree.AutoSave() +# #clones.append(truth_tree.tree.CopyTree('')) +# truth_tree.cptree = truth_tree.tree.CopyTree('') for t in recotrees: - print '\tCopying %s tree...' % t.GetName() - clones.append(t.CopyTree(' && '.join([sel_strings[sel_name] for sel_name in sel_names]))) -for c in clones: - c.AutoSave() + print '\tCopying %s tree...' % t.tree.GetName() + t.cptree = t.tree.CopyTree(' && '.join([sel_strings[sel_name] for sel_name in sel_names])) + if not outfile.GetDirectory(t.location): + outfile.mkdir(t.location, t.location) + t.cptree.SetDirectory(outfile.GetDirectory(t.location)) + t.cptree.AutoSave() + #clones.append(t.tree.CopyTree(' && '.join([sel_strings[sel_name] for sel_name in sel_names]))) +#for c in clones: +# c.AutoSave() outfile.Close() infile.Close() print '\tAll done.'