diff --git a/Phys/B2KShh/job/download.py b/Phys/B2KShh/job/download.py index ed40d82..dae5efa 100644 --- a/Phys/B2KShh/job/download.py +++ b/Phys/B2KShh/job/download.py @@ -75,17 +75,18 @@ if __name__ == '__main__': - # #mylist = getlist(302, 304) - # out = '/afs/cern.ch/work/e/egraveri/Analysis/ganga/Lb2Lcmunu' - # #pickle.dump(mylist, open(out + '/lfns.pkl', 'wb')) - # mylist = pickle.load(open(out + '/lfns.pkl', 'rb')) - # download(mylist, dest2) - # #deleteFromGrid(mylist) - # #hadd(mylist) - #mylist2 = getlist(287, 300) - out2 = "/home/hep/egraveri/cmtuser/Bender_v27r0p1/Phys/B2KShh/job" - #pickle.dump(mylist2, open(out2 + '/lfns.pkl', 'wb')) - mylist2 = pickle.load(open(out2 + '/lfns.pkl', 'rb')) - #download(mylist2, dest1) - hadd(mylist2, dest1) - #deleteFromGrid(mylist2) + #mylist = getlist(302, 304) + out = '/afs/cern.ch/work/e/egraveri/Analysis/ganga/Lb2Lcmunu' + #pickle.dump(mylist, open(out + '/lfns.pkl', 'wb')) + mylist = pickle.load(open(out + '/lfns.pkl', 'rb')) + download(mylist, dest2) + #deleteFromGrid(mylist) + #hadd(mylist) + + # #mylist2 = getlist(287, 300) + # out2 = "/home/hep/egraveri/cmtuser/Bender_v27r0p1/Phys/B2KShh/job" + # #pickle.dump(mylist2, open(out2 + '/lfns.pkl', 'wb')) + # mylist2 = pickle.load(open(out2 + '/lfns.pkl', 'rb')) + # #download(mylist2, dest1) + # #hadd(mylist2, dest1) + # deleteFromGrid(mylist2) diff --git a/Phys/B2KShh/job/selection.py b/Phys/B2KShh/job/selection.py index 69bcf26..660adbd 100644 --- a/Phys/B2KShh/job/selection.py +++ b/Phys/B2KShh/job/selection.py @@ -51,10 +51,11 @@ string += ' && %s_TRUEID == %s' % (h, truth_match[hypos[hypo][h]]) string += ' && %s_%s_TRUEID == %s' % (h, mother, b_id) string += ')' + string = string.replace('( &&', '(') return string -def make_sel_trings(source, recotree): +def make_sel_strings(source, recotree): sel_strings = { 'L0' : '(L0HadronDecision_TOS || L0Global_TIS)', 'HLT1' : 'Hlt1TrackAllL0Decision_TOS', @@ -96,6 +97,7 @@ def __init__(self, key, obj): self.tree = obj self.location = key.split('/')[1] + self.name = obj.GetName() #truthtrees = [t for t in trees if 'MCTruth' in t.tree.GetName()] @@ -114,25 +116,30 @@ """ If some selections were already performed, use the selected sample as input! + Ignore (redo) the last selection in the list. """ infile_name = target_path + source available_files = os.listdir(target_path) - for i in range(len(sel_names)): - sel_subset = sel_names[:i+1] + # the last selection will be redone! + pre_sel_names = sel_names[:-1] + for i in range(len(pre_sel_names)): + sel_subset = pre_sel_names[:i+1] for f in available_files: if f == source.split('.')[0] + '_' + '_'.join(sel_subset) + '.root': infile_name = target_path + f return infile_name -infile = r.TFile(find_input(target_path, source, sel_names), 'read') +infile_name = find_input(target_path, source, sel_names) +print "\tOpening file %s as input..." % infile_name +infile = r.TFile(infile_name, 'read') trees = [] for k, o in getall(infile): if 'TTree' in o.ClassName(): trees.append(treeWithDirectory(k, o)) -recotrees = [t for t in trees if 'MCTruth' not in t.tree.GetName()] +recotrees = [t for t in trees if 'MCTruth' not in t.name] outfilename = source.split('.')[0] + '_' + '_'.join(sel_names) + '.root' print '\tCreating file %s ...' % outfilename @@ -148,7 +155,7 @@ print '\tMaking directory %s ...' % t.location outfile.mkdir(t.location, t.location) outfile.cd(t.location) - sel_strings = make_sel_strings(source, t.GetName()) + sel_strings = make_sel_strings(source, t.name) t.cptree = t.tree.CopyTree(' && '.join([sel_strings[sel_name] for sel_name in sel_names])) n_new, n_old = t.cptree.GetEntriesFast(), t.tree.GetEntriesFast() print '\t Copying {0}/{1} tree: {2:.1%} out of {3} events selected...'.format(t.location, t.tree.GetName(), n_new / n_old, n_old)