diff --git a/Phys/B2KShh/job/selection.py b/Phys/B2KShh/job/selection.py index 660adbd..bbf106e 100644 --- a/Phys/B2KShh/job/selection.py +++ b/Phys/B2KShh/job/selection.py @@ -38,24 +38,39 @@ 'B2KKKS' : {'h1': 'K', 'h2': 'K', 'KS': 'KS'}, } +def hypoForProduction(source): + if '2Lcpi-KS0p' in source and 'MC' in source: + hypo = 'B2ppiKS' + elif '2pKKS0' in source and 'MC' in source: + hypo = 'B2pKKS' + elif '2ppiKS0' in source and 'MC' in source: + hypo = 'B2ppiKS' + if not hypo and 'MC' in source: + raise Exception('DANGER: cannot find truth matching hypotesis') + return hypo -def truth_match_string(source, hypo): + +def truth_match_string(source): + hypo = hypoForProduction(source) string = '(' - mother = 'MOTHER' + mother = { 'h1': 'MOTHER', + 'h2': 'MOTHER', + 'KS': 'MOTHER', } b_id = truth_match['Lb'] if 'Lc' in source: - mother = 'GDMOTHER' + mother['h1'] = 'GDMOTHER' + mother['KS'] = 'GDMOTHER' if 'Xib0' in source: b_id = truth_match['Xib0'] for h in ['h1', 'h2', 'KS']: - string += ' && %s_TRUEID == %s' % (h, truth_match[hypos[hypo][h]]) - string += ' && %s_%s_TRUEID == %s' % (h, mother, b_id) + string += ' && abs(%s_TRUEID) == %s' % (h, truth_match[hypos[hypo][h]]) + string += ' && abs(%s_%s_TRUEID) == %s' % (h, mother[h], b_id) string += ')' string = string.replace('( &&', '(') return string -def make_sel_strings(source, recotree): +def make_sel_strings(source): sel_strings = { 'L0' : '(L0HadronDecision_TOS || L0Global_TIS)', 'HLT1' : 'Hlt1TrackAllL0Decision_TOS', @@ -77,7 +92,8 @@ else: raise Exception('DANGER: problem with file name parsing and trigger conditions!') - sel_strings['TruthMatch'] = truth_match_string(source, recotree) + sel_strings['TruthMatch'] = truth_match_string(source) + #print sel_strings['TruthMatch'] return sel_strings @@ -155,12 +171,13 @@ print '\tMaking directory %s ...' % t.location outfile.mkdir(t.location, t.location) outfile.cd(t.location) - sel_strings = make_sel_strings(source, t.name) + sel_strings = make_sel_strings(source) 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) t.cptree.SetDirectory(outfile.GetDirectory(t.location)) - t.cptree.AutoSave() + if t.cptree.GetEntries() > 0: + 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()