def selection(pte, sign, children): result = False if children == 'phipi': if sign == 1: daughters = set([pdgid_phi, pdgid_pip]) else: daughters = set([pdgid_phi, pdgid_pim]) elif children == 'k0star': if sign == 1: daughters = set([pdgid_K0bstar, pdgid_Kp]) else: daughters = set([pdgid_K0star, pdgid_Km]) elif children == 'kstar1410': if sign == 1: daughters = set([pdgid_K0bstar0, pdgid_Kp]) else: daughters = set([pdgid_K0star0, pdgid_Km]) elif children == 'phsp': if sign == 1: daughters = set([pdgid_Kp, pdgid_Km, pdgid_pip]) else: daughters = set([pdgid_Kp, pdgid_Km, pdgid_pim]) else: raise NameError(children) d = makeDDecaySubTree(pte, sign)[0] decay_daus = set([dau.pdgid for dau in d.daughters]) #if decay_daus == daughters: # for i in range(pte.nmcpart): # pid = pte.mcpdgid[i] # pname = particle_data.findId(pid) # print '%s: %s' % (i, pname) # phi = makeDDecaySubTree(pte, sign)[1] # phi_daus = set([dau.pdgid for dau in phi.daughters]) # kk = set([pdgid_Kp, pdgid_Km]) # kkg = set([pdgid_Kp, pdgid_Km, pdgid_gammaFSR]) # if phi_daus != kk and phi_daus != kkg: # print phi, phi_daus # sys.exit() #if children == 'phsp': # print daughters # sys.exit() #result = (decay_daus in daughters) #else: # print daughters # sys.exit() #result = (decay_daus == daughters) result = (decay_daus == daughters) return result
def daughter_dump(pte, dsign): d = makeDDecaySubTree(pte, dsign)[0] # print pte.run, pte.event, rv = makedict(map(lambda x: particle_data.findId(x.pdgid).name, d.daughters)) mcdmode = d.mcDmode() ng2 = mcDmodeGetRad(mcdmode) if ng2 == 0: return ng = rv.get('gamma', 0) if ng > 0 and ng == mcDmodeGetRad(mcdmode): return if rv not in ignore[204]: print rv, mcdmodetostring(mcdmode), mcDmodeGetRad(mcdmode)
def daughter_dump(pte, dsign): d = makeDDecaySubTree(pte, dsign)[0] # print pte.run, pte.event, rv = makedict( map(lambda x: particle_data.findId(x.pdgid).name, d.daughters)) mcdmode = d.mcDmode() ng2 = mcDmodeGetRad(mcdmode) if ng2 == 0: return ng = rv.get('gamma', 0) if ng > 0 and ng == mcDmodeGetRad(mcdmode): return if rv not in ignore[204]: print rv, mcdmodetostring(mcdmode), mcDmodeGetRad(mcdmode)
def process_signal_single_mode(mode, label, test): datatype = 'signal' prefix = 'dir_'+label sys.stdout.write('Processing crossfeeds for %s ...\n' %mode) sys.stdout.flush() files = {} for dbarmode in attr.single_mode_list: bkgname = '%s_%s_fakes_%s.evt' % (datatype, mode, dbarmode) bkgfile = tools.set_file( extbase=attr.bkgpath, prefix=prefix, comname=bkgname) files[dbarmode] = open(bkgfile, 'w') rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) modekey, sign = tools.get_modekey_sign(mode) t_iterstart = time.time() entries = 0 for pte in ifilter(lambda x: x.ecm > 3.7, pt): entries += 1 if test and entries > 1000: break otherside = tools.mcDmodeFixRad(tools.makeDDecaySubTree(pte, -sign)[0].mcDmode()) for dbarmode in attr.single_mode_list: dbarmodekey, dbarsign = tools.get_modekey_sign(dbarmode) x = (modekey, sign) y = (dbarmodekey, dbarsign) considerevt = considerThisEvent(x, y, otherside) if not considerevt: continue mbc = 1.84 d = tools.cuts.chooseD(y[0], pte, y[1]) passed = False if d != None and tools.cuts.passDE(d, pte): passed = True; mbc = pte.dmbc[d] if x == (1,1) and y == (1,-1) and passed: print tools.mcdmodetostring(pte.mcdmode), tools.mcdmodetostring(pte.mcdbmode) files[dbarmode].write('%.5f %.5f %d\n' % (mbc, pte.ecm/2, int(passed))) pt.Delete() for f in files.values(): f.close() dur = tools.duration_human(time.time()-t_iterstart) sys.stdout.write(' done %s.\n' %dur)
def ddbars(opts, args): tabname = 'entries_ddbars_' + '_'.join(args).replace('/', '_') test = False # opts.test datatype = args[0] label = args[1] rootfile = tools.get_rootfile(datatype, label=label, test=test) print rootfile sys.exit() pt = tools.add_rootfile(rootfile) print pt nd0d0b = 0 ndpdm = 0 ntotal = 0 dmodecount = {}; dbmodecount = {} dtmodecount = {} for i in modes: dmodecount[i] = 0; dbmodecount[i] = 0 for pair in possible_double_tags: dtmodecount[pair] = 0 for pte in pt: if pte.entry % 100000 == 0: print pte.entry realdtag = None realdbtag = None ntotal += 1 if pte.mcpdgid[3] == pdgid_Dz: nd0d0b += 1 elif pte.mcpdgid[3] == pdgid_Dp: ndpdm += 1 else: print 'HEEELP!' dtree = makeDDecaySubTree(pte,1) dbtree = makeDDecaySubTree(pte,-1) d = dtree[0] db = dbtree[0] mcdmode = d.mcDmode() mcdbmode = db.mcDmode() if ((mcDmodeFixRad(mcdmode) == modes[3]['mcdmode']) and mcdmode != mcDmodeFixRad(mcdmode)): for node in d.interestingDescendants(): if node.pdgid == pdgid_gamma: gnode = node break if (gnode.parent.pdgid != pdgid_Dz and abs(gnode.parent.pdgid) != 20213 and gnode.parent.pdgid != pdgid_rhoz and abs(gnode.parent.pdgid) != 313 and abs(gnode.parent.pdgid) != 10323): print 'xxxxxxxxxxxxxxxxxx' print pte.run, pte.event for node in dtree: print node pass ## print 'HELP', mcdmode, pte.mcdmode ## print mcdmodetostring(mcdmode), mcdmodetostring(pte.mcdmode) ## print d ## for node in d.interestingDescendants(): ## print node for j in modes: if mcDmodeFixRad(mcdmode) == modes[j]['mcdmode']: if j in (202, 203, 204): nodes_of_interest = d.interestingDescendants() for node in nodes_of_interest: if node.pdgid == pdgid_KS: dmodecount[j] += 1 realdtag = j break else: dmodecount[j] += 1 realdtag = j if j == 204: daughter_dump(pte, 1) if (False and j in (202, 203, 204) and mcdmodetostring(mcdmode) != 'K0 pi+ ' and len(d.daughters) != 3): tree = makeDecayTree(pte) for node in tree: if node.pdgid == pdgid_Dz: nodes_of_interest = node.interestingDescendants() break print '--------------' print mcdmode, mcdbmode, pte.mcdmode, pte.mcdbmode print mcdmodetostring(mcdmode) for node in tree: print node if mcDmodeFixRad(mcdbmode) == modes[j]['mcdbmode']: if j in (202, 203, 204): nodes_of_interest = db.interestingDescendants() for node in nodes_of_interest: if node.pdgid == pdgid_KS: dbmodecount[j] += 1 realdbtag = j break else: dbmodecount[j] += 1 realdbtag = j if realdtag != None and realdbtag != None: dtmodecount[(realdtag,realdbtag)] += 1 print 'N(all):', ntotal print 'N(D0D0B):', nd0d0b print 'N(D+D-):', ndpdm if nd0d0b > 0: print 'Ratio:', float(ndpdm)/nd0d0b for j in dmodecount: print modes[j]['fname'], dmodecount[j], if j < 200 and nd0d0b > 0: print float(dmodecount[j])/nd0d0b elif ndpdm > 0: print float(dmodecount[j])/ndpdm else: print print modes[j]['fnamebar'], dbmodecount[j], if j < 200 and nd0d0b > 0: print float(dbmodecount[j])/nd0d0b elif ndpdm > 0: print float(dbmodecount[j])/ndpdm else: print for pair in possible_double_tags: print "%s/%s %d" % (modes[pair[0]]['fname'], modes[pair[1]]['fnamebar'], dtmodecount[pair]) sys.exit()
def output_trkmtm_ks3pi(pt, mode, selfile, label, test=False): nselected = 0 ntotal = 0 modekey, signs = tools.get_modekey_sign(mode) f = TFile(selfile, 'recreate') efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) if signs != None: # single tag if not isinstance(signs, list): signs = [signs] mbc = {}; kpi1 = {} ; kpi2 = {}; pipih = {}; pipil = {}; pipipi = {} kpim = {}; kpipih = {}; kpipil = {} h_pks = {}; h_ppi1 = {}; h_ppi2 = {}; h_ppim = {} h_angks = {}; h_angpi1 = {}; h_angpi2 = {}; h_angpim = {} real_ks_pmag = 0 ; real_p1_pmag = 0 ; real_p2_pmag = 0 ; real_pm_pmag = 0 h_ks_dp = TH1F('h_ks_dp', 'K_{S} delta p', 100, -0.05, 0.05) h_p1_dp = TH1F('h_p1_dp', 'pi1 delta p', 100, -0.05, 0.05) h_p2_dp = TH1F('h_p2_dp', 'pi2 delta p', 100, -0.05, 0.05) h_pm_dp = TH1F('h_pm_dp', 'pi- delta p', 100, -0.05, 0.05) for type in ('mc', 'mctruth'): mbc[type] = TH1F('mbc_' + type, 'mbc', 100, 1.83, 1.89) h_pks[type] = TH1F('h_pk_' + type, 'K_{S} momentum', 20, 0, 1) h_ppi1[type] = TH1F('h_ppi1_' + type, '#pi^{+}_{1} momentum', 20, 0, 1) h_ppi2[type] = TH1F('h_ppi2_' + type, '#pi^{+}_{2} momentum', 20, 0, 1) h_ppim[type] = TH1F('h_ppim_' + type, '#pi^{-} momentum', 20, 0, 1) args_p = (12, 0.1, 0.95, 4, 0.05, 0.9, 8, 0.05, 0.75, 4, 0.05, 0.9) args_a = (6, 0, 1, 6, 0, 1, 6, 0, 1, 6, 0, 1) boxes_num_p = histBox(*args_p) boxes_denom_p = histBox(*args_p) boxes_num_a = histBox(*args_a) boxes_denom_a = histBox(*args_a) for pte in pt: if test and nselected > 10: break ntotal += 1 for sign in signs: loctree = makeDDecaySubTree(pte, sign) if sign == 1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[204]['mcdmode']: continue if sign == -1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[204]['mcdbmode']: continue mc_ks = None; mc_pi1 = None; mc_pi2 = None; mc_pim = None; mc_kl = None reald = loctree[0] nodes_of_interest = reald.interestingDescendants() for node in nodes_of_interest: if node.pdgid == sign*pdgid_KS: mc_ks = node elif node.pdgid == sign*pdgid_KL: mc_kl = node elif node.pdgid == sign*pdgid_pip: if not mc_pi1: mc_pi1 = node else: if mc_pi2: print 'ERROR' print len(nodes_of_interest) print mc_pi1 print mc_pi2 print node print ' ---- ' for nnode in nodes_of_interest: print nnode print '-' print '=================' mc_pi2 = node elif node.pdgid == sign*pdgid_pim: mc_pim = node if not mc_ks or not mc_pi1 or not mc_pi2 or not mc_pim: if mc_kl: continue else: print 'ERROR2', mc_ks, mc_pi1, mc_pi2, mc_pim else: pass ks = mc_ks.index ; pip1 = mc_pi1.index ; pip2 = mc_pi2.index pim = mc_pim.index pks = (pte.mce[ks], pte.mcpx[ks], pte.mcpy[ks], pte.mcpz[ks]) ppip1 = (pte.mce[pip1], pte.mcpx[pip1], pte.mcpy[pip1], pte.mcpz[pip1]) ppip2 = (pte.mce[pip2], pte.mcpx[pip2], pte.mcpy[pip2], pte.mcpz[pip2]) ppim = (pte.mce[pim], pte.mcpx[pim], pte.mcpy[pim], pte.mcpz[pim]) real_ks_pmag = pmag(pks) ; real_pm_pmag = pmag(ppim) zhat = (0,1,0,0) ang_ks = abs(cosangle(pks,zhat)) ang_pim = abs(cosangle(ppim,zhat)) h_pks['mctruth'].Fill(real_ks_pmag) h_ppim['mctruth'].Fill(real_pm_pmag) mag_ppi1 = pmag(ppip1); mag_ppi2 = pmag(ppip2) if max(mag_ppi1, mag_ppi2) == mag_ppi1: h_ppi1['mctruth'].Fill(mag_ppi1) h_ppi2['mctruth'].Fill(mag_ppi2) real_p1_pmag = mag_ppi1 ; real_p2_pmag = mag_ppi2 ang_pi1 = abs(cosangle(ppip1,zhat)); ang_pi2 = abs(cosangle(ppip2,zhat)) else: h_ppi1['mctruth'].Fill(mag_ppi2) h_ppi2['mctruth'].Fill(mag_ppi1) real_p1_pmag = mag_ppi2 ; real_p2_pmag = mag_ppi1 ang_pi1 = abs(cosangle(ppip2,zhat)); ang_pi2 = abs(cosangle(ppip1,zhat)) boxes_denom_p.fill(real_ks_pmag, real_p1_pmag, real_p2_pmag, real_pm_pmag) boxes_denom_a.fill(ang_ks, ang_pi1, ang_pi2, ang_pim) choice = chooseD(204, pte, sign) if choice != None: # and passDE(choice, pte): nselected += 1 mbc['mc'].Fill(pte.dmbc[choice]) if not 1.865 < pte.dmbc[choice] < 1.875: continue ks = pte.ddau1[choice]; pip1 = pte.ddau2[choice]; pip2 = pte.ddau3[choice]; pim = pte.ddau4[choice] pks = (pte.kse[ks], pte.kspx[ks], pte.kspy[ks], pte.kspz[ks]) ppip1 = (pte.trpie[pip1], pte.trpipx[pip1], pte.trpipy[pip1], pte.trpipz[pip1]) ppip2 = (pte.trpie[pip2], pte.trpipx[pip2], pte.trpipy[pip2], pte.trpipz[pip2]) ppim = (pte.trpie[pim], pte.trpipx[pim], pte.trpipy[pim], pte.trpipz[pim]) h_ks_dp.Fill(pmag(pks)-real_ks_pmag) h_pm_dp.Fill(pmag(ppim)-real_pm_pmag) h_pks['mc'].Fill(pmag(pks)) h_ppim['mc'].Fill(pmag(ppim)) try: ang_ks = abs(pte.trcosth[ks]) ang_pim = abs(pte.trcosth[pim]) except IndexError: pass mag_ppi1 = pmag(ppip1); mag_ppi2 = pmag(ppip2) if max(mag_ppi1, mag_ppi2) == mag_ppi1: h_ppi1['mc'].Fill(mag_ppi1) h_ppi2['mc'].Fill(mag_ppi2) h_p1_dp.Fill(mag_ppi1 - real_p1_pmag) h_p2_dp.Fill(mag_ppi2 - real_p2_pmag) ang_pi1 = abs(pte.trcosth[pip1]) ang_pi2 = abs(pte.trcosth[pip2]) else: h_ppi1['mc'].Fill(mag_ppi2) h_ppi2['mc'].Fill(mag_ppi1) h_p1_dp.Fill(mag_ppi2 - real_p1_pmag) h_p2_dp.Fill(mag_ppi1 - real_p2_pmag) ang_pi1 = abs(pte.trcosth[pip2]) ang_pi2 = abs(pte.trcosth[pip1]) boxes_num_p.fill(pmag(pks), min(mag_ppi2, mag_ppi1), max(mag_ppi2, mag_ppi1), pmag(ppim)) boxes_num_a.fill(ang_ks, ang_pi1, ang_pi2, ang_pim) effs['boxes_num_p'] = boxes_num_p effs['boxes_denom_p'] = boxes_denom_p effs['boxes_num_a'] = boxes_num_a effs['boxes_denom_a'] = boxes_denom_a effs.close() f.Write() f.Close() pt.Delete() return nselected, ntotal
def output_trkmtm_kspipi0(pt, mode, selfile, label, test=False): nselected = 0 ntotal = 0 modekey, signs = tools.get_modekey_sign(mode) f = TFile(selfile, 'recreate') efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) if signs != None: # single tag if not isinstance(signs, list): signs = [signs] mbc = {}; kpi1 = {} ; kpi2 = {}; pipih = {}; pipil = {}; pipipi = {} kpiz = {}; kpipih = {}; kpipil = {} h_pks = {}; h_ppi1 = {}; h_ppiz = {} h_angks = {}; h_angpi1 = {}; h_angpi2 = {}; h_angpiz = {} real_ks_pmag = 0 ; real_p1_pmag = 0 ; real_pz_pmag = 0 h_ks_dp = TH1F('h_ks_dp', 'K_{S} delta p', 100, -0.05, 0.05) h_p1_dp = TH1F('h_p1_dp', '#pi^{+} delta p', 100, -0.05, 0.05) h_pz_dp = TH1F('h_pz_dp', '#pi^{0} delta p', 100, -0.05, 0.05) h_dalitz = TH2F('h_dalitz', 'K_{S} #pi^{+} #pi^{0} Dalitz plot', 100, 0, 2, 100, 0, 3) for type in ('mc', 'mctruth'): mbc[type] = TH1F('mbc_' + type, 'mbc', 100, 1.83, 1.89) h_pks[type] = TH1F('h_pks_' + type, 'K_{S} momentum', 20, 0, 1) h_ppi1[type] = TH1F('h_ppi1_' + type, '#pi^{+} momentum', 20, 0, 1) h_ppiz[type] = TH1F('h_ppiz_' + type, '#pi^{0} momentum', 20, 0, 1) args = (11, 0, 1.1, 8, 0, 1.0, 8, 0, 1.0) boxes_num = histBox(*args) boxes_denom = histBox(*args) for pte in pt: if test and nselected > 10: break ntotal += 1 for sign in signs: loctree = makeDDecaySubTree(pte, sign) if sign == 1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[203]['mcdmode']: continue if sign == -1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[203]['mcdbmode']: continue mc_ks = None; mc_pi1 = None; mc_piz = None reald = loctree[0] nodes_of_interest = reald.interestingDescendants() for node in nodes_of_interest: if node.pdgid == pdgid_KS or node.pdgid == pdgid_KL: mc_ks = node elif node.pdgid == sign*pdgid_pip: if not mc_pi1: mc_pi1 = node else: print 'ERROR' elif node.pdgid == pdgid_piz: mc_piz = node if mc_ks and mc_ks.pdgid == pdgid_KL: continue if not mc_ks or not mc_pi1 or not mc_piz: print 'ERROR2', mc_ks, mc_pi1, mc_piz for node in nodes_of_interest: print node else: pass ks = mc_ks.index ; pip1 = mc_pi1.index ; piz = mc_piz.index pks = (pte.mce[ks], pte.mcpx[ks], pte.mcpy[ks], pte.mcpz[ks]) ppip1 = (pte.mce[pip1], pte.mcpx[pip1], pte.mcpy[pip1], pte.mcpz[pip1]) ppiz = (pte.mce[piz], pte.mcpx[piz], pte.mcpy[piz], pte.mcpz[piz]) real_ks_pmag = pmag(pks) ; real_pz_pmag = pmag(ppiz) if pmag(ppiz) >0: # print 'K0+piz give', invmass(pks, ppiz) # print 'piz+pip give', invmass(ppiz, ppip1) h_dalitz.Fill(invmasssq(ppiz, ppip1), invmasssq(pks, ppiz)) h_pks['mctruth'].Fill(real_ks_pmag) h_ppiz['mctruth'].Fill(real_pz_pmag) mag_ppi1 = pmag(ppip1) h_ppi1['mctruth'].Fill(mag_ppi1) real_p1_pmag = mag_ppi1 boxes_denom.fill(real_ks_pmag, real_p1_pmag, real_pz_pmag) choice = chooseD(203, pte, sign) if choice != None: # and passDE(choice, pte): nselected += 1 mbc['mc'].Fill(pte.dmbc[choice]) if not 1.86 < pte.dmbc[choice] < 1.87: continue ks = pte.ddau1[choice]; pip1 = pte.ddau2[choice]; piz = pte.ddau3[choice] pks = (pte.kse[ks], pte.kspx[ks], pte.kspy[ks], pte.kspz[ks]) ppip1 = (pte.trpie[pip1], pte.trpipx[pip1], pte.trpipy[pip1], pte.trpipz[pip1]) ppiz = (pte.pi0e[piz], pte.pi0px[piz], pte.pi0py[piz], pte.pi0pz[piz]) h_ks_dp.Fill(pmag(pks)-real_ks_pmag) h_pz_dp.Fill(pmag(ppiz)-real_pz_pmag) h_pks['mc'].Fill(pmag(pks)) h_ppiz['mc'].Fill(pmag(ppiz)) mag_ppi1 = pmag(ppip1); h_ppi1['mc'].Fill(mag_ppi1) h_p1_dp.Fill(mag_ppi1 - real_p1_pmag) boxes_num.fill(pmag(pks), mag_ppi1, pmag(ppiz)) effs['boxes_num'] = boxes_num effs['boxes_denom'] = boxes_denom effs.close() f.Write() f.Close() pt.Delete() return nselected, ntotal
def output_trkmtm_kkpi(pt, mode, selfile, label, test=False): nselected = 0 ntotal = 0 modekey, signs = tools.get_modekey_sign(mode) f = TFile(selfile, 'recreate') efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) if signs != None: # single tag if not isinstance(signs, list): signs = [signs] mbc = {}; kpi1 = {} ; kpi2 = {}; pipih = {}; pipil = {}; pipipi = {} kpiz = {}; kpipih = {}; kpipil = {} h_pkp = {}; h_pkm = {}; h_ppi = {} h_angkp = {}; h_angkm = {}; h_angpi = {}; real_kp_pmag = 0 ; real_km_pmag = 0 ; real_pi_pmag = 0 h_kp_dp = TH1F('h_kp_dp', 'K^{+} delta p', 100, -0.05, 0.05) h_km_dp = TH1F('h_km_dp', 'K^{-} delta p', 100, -0.05, 0.05) h_pi_dp = TH1F('h_pi_dp', '#pi^{+} delta p', 100, -0.05, 0.05) for type in ('mc', 'mctruth'): mbc[type] = TH1F('mbc_' + type, 'mbc', 100, 1.83, 1.89) h_pkp[type] = TH1F('h_pkp_' + type, 'K^{+} momentum', 20, 0, 1) h_pkm[type] = TH1F('h_pkm_' + type, 'K^{-} momentum', 20, 0, 1) h_ppi[type] = TH1F('h_ppi_' + type, '#pi^{+} momentum', 20, 0, 1) args = (11, 0, 1.1, 8, 0, 1.0, 8, 0, 1.0) boxes_num = histBox(*args) boxes_denom = histBox(*args) for pte in pt: if test and nselected > 10: break ntotal += 1 for sign in signs: loctree = makeDDecaySubTree(pte, sign) if sign == 1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[205]['mcdmode']: continue if sign == -1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[205]['mcdbmode']: continue mc_kp = None; mc_km = None; mc_pi = None reald = loctree[0] nodes_of_interest = reald.interestingDescendants() for node in nodes_of_interest: if node.pdgid == sign*pdgid_Kp: mc_kp = node elif node.pdgid == sign*pdgid_Km: mc_km = node elif node.pdgid == sign*pdgid_pip: mc_pi = node if not mc_kp or not mc_km or not mc_pi: print 'ERROR2', mc_kp, mc_km, mc_pi else: pass kp = mc_kp.index ; km = mc_km.index ; pi = mc_pi.index pkp = (pte.mce[kp], pte.mcpx[kp], pte.mcpy[kp], pte.mcpz[kp]) pkm = (pte.mce[km], pte.mcpx[km], pte.mcpy[km], pte.mcpz[km]) ppi = (pte.mce[pi], pte.mcpx[pi], pte.mcpy[pi], pte.mcpz[pi]) real_kp_pmag = pmag(pkp) ; real_km_pmag = pmag(pkm) real_pi_pmag = pmag(ppi) h_pkp['mctruth'].Fill(real_kp_pmag) h_pkm['mctruth'].Fill(real_km_pmag) h_ppi['mctruth'].Fill(real_pi_pmag) boxes_denom.fill(real_kp_pmag, real_km_pmag, real_pi_pmag) choice = chooseD(205, pte, sign) if choice != None: # and passDE(choice, pte): nselected += 1 mbc['mc'].Fill(pte.dmbc[choice]) if not 1.865 < pte.dmbc[choice] < 1.875: continue km = pte.ddau1[choice]; kp = pte.ddau2[choice]; pi = pte.ddau3[choice] pkp = (pte.trke[kp], pte.trkpx[kp], pte.trkpy[kp], pte.trkpz[kp]) pkm = (pte.trke[km], pte.trkpx[km], pte.trkpy[km], pte.trkpz[km]) ppi = (pte.trpie[pi], pte.trpipx[pi], pte.trpipy[pi], pte.trpipz[pi]) h_kp_dp.Fill(pmag(pkp)-real_kp_pmag) h_km_dp.Fill(pmag(pkm)-real_km_pmag) h_pi_dp.Fill(pmag(ppi) - real_pi_pmag) h_pkm['mc'].Fill(pmag(pkm)) h_pkp['mc'].Fill(pmag(pkp)) h_ppi['mc'].Fill(pmag(ppi)) boxes_num.fill(pmag(pkp), pmag(pkm), pmag(ppi)) effs['boxes_num'] = boxes_num effs['boxes_denom'] = boxes_denom effs.close() f.Write() f.Close() pt.Delete() return nselected, ntotal
def output_trkmtm_kpipi0(pt, mode, selfile, label, test=False): nselected = 0 ntotal = 0 modekey, signs = tools.get_modekey_sign(mode) if signs != None: # single tag if not isinstance(signs, list): signs = [signs] real_k_pmag = 0 ; real_p1_pmag = 0 ; real_pz_pmag = 0 mbc = {}; kpi1 = {} ; kpi2 = {}; pipih = {}; pipil = {}; pipipi = {} kpiz = {}; kpipih = {}; kpipil = {} h_pk = {}; h_ppi1 = {}; h_ppiz = {} h_angk = {}; h_angpi1 = {}; h_angpi2 = {}; h_angpiz = {} f = TFile(selfile, 'recreate') efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) h_k_dp = TH1F('h_k_dp', 'K delta p', 100, -0.05, 0.05) h_p1_dp = TH1F('h_p1_dp', 'pi1 delta p', 100, -0.05, 0.05) h_pz_dp = TH1F('h_pz_dp', 'pi^{0} delta p', 100, -0.05, 0.05) for type in ('mc', 'mctruth'): mbc[type] = TH1F('mbc_' + type, 'mbc', 100, 1.83, 1.89) h_pk[type] = TH1F('h_pk_' + type, 'K^{-} momentum', 20, 0, 1) h_ppi1[type] = TH1F('h_ppi1_' + type, '#pi^{+} momentum', 20, 0, 1) h_ppiz[type] = TH1F('h_ppiz_' + type, '#pi^{0} momentum', 20, 0, 1) args = (11, 0, 1.1, 8, 0, 1.0, 8, 0, 1.0) boxes_num = histBox(*args) boxes_denom = histBox(*args) for pte in pt: if test and nselected > 10: break ntotal += 1 for sign in signs: loctree = makeDDecaySubTree(pte, sign) if sign == 1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[1]['mcdmode']: continue if sign == -1 and mcDmodeFixRad( loctree[0].mcDmode()) != modes[1]['mcdbmode']: continue # do MC truth stuff first mc_k = None mc_pi1 = None mc_piz = None reald = loctree[0] nodes_of_interest = reald.interestingDescendants() for node in nodes_of_interest: if node.pdgid == sign*pdgid_Km: mc_k = node elif node.pdgid == sign*pdgid_pip: if not mc_pi1: mc_pi1 = node else: print 'ERROR' elif node.pdgid == pdgid_piz: mc_piz = node if not mc_k or not mc_pi1 or not mc_piz: print 'ERROR2', mc_k, mc_pi1, mc_piz else: pass k = mc_k.index ; pip1 = mc_pi1.index ; piz = mc_piz.index pk = (pte.mce[k], pte.mcpx[k], pte.mcpy[k], pte.mcpz[k]) ppip1 = (pte.mce[pip1], pte.mcpx[pip1], pte.mcpy[pip1], pte.mcpz[pip1]) ppiz = (pte.mce[piz], pte.mcpx[piz], pte.mcpy[piz], pte.mcpz[piz]) real_k_pmag = pmag(pk) ; real_pz_pmag = pmag(ppiz) h_pk['mctruth'].Fill(real_k_pmag) h_ppiz['mctruth'].Fill(real_pz_pmag) mag_ppi1 = pmag(ppip1) h_ppi1['mctruth'].Fill(mag_ppi1) real_p1_pmag = mag_ppi1 boxes_denom.fill(real_k_pmag, real_p1_pmag, real_pz_pmag) choice = chooseD(modekey, pte, sign) if choice != None : #and passDE(choice, pte): included in chooseD nselected += 1 mbc['mc'].Fill(pte.dmbc[choice]) if not 1.86 < pte.dmbc[choice] < 1.87: continue k = pte.ddau1[choice]; pip1 = pte.ddau2[choice]; piz = pte.ddau3[choice] pk = (pte.trke[k], pte.trkpx[k], pte.trkpy[k], pte.trkpz[k]) ppip1 = (pte.trpie[pip1], pte.trpipx[pip1], pte.trpipy[pip1], pte.trpipz[pip1]) ppiz = (pte.pi0e[piz], pte.pi0px[piz], pte.pi0py[piz], pte.pi0pz[piz]) h_k_dp.Fill(pmag(pk)-real_k_pmag) h_pz_dp.Fill(pmag(ppiz)-real_pz_pmag) h_pk['mc'].Fill(pmag(pk)) h_ppiz['mc'].Fill(pmag(ppiz)) mag_ppi1 = pmag(ppip1); h_ppi1['mc'].Fill(mag_ppi1) h_p1_dp.Fill(mag_ppi1 - real_p1_pmag) boxes_num.fill(pmag(pk), mag_ppi1, pmag(ppiz)) effs['boxes_num'] = boxes_num effs['boxes_denom'] = boxes_denom effs.close() f.Write() f.Close() pt.Delete() return nselected, ntotal
def output_multspec(reweight, pt, mode, selfile, label, test=False): mode, signs = tools.get_modekey_sign(mode) f = TFile(selfile, 'recreate') load_roofit_lib('signal', label) from ROOT import RooRealVar, RooDataSet, RooArgList, RooArgSet, \ RooGaussian, RooArgusBG, RooCBShape, RooAddPdf, RooPolynomial, \ gSystem, TCanvas efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) mbc = RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') weight2 = RooRealVar('weight2', 'weight', 1) weight3 = RooRealVar('weight3', 'weight', 1) mbc_aset = RooArgSet(mbc) ntrack_d0 = TH1F('ntrack_d0', 'Number of other side tracks for D^{0} #rightarrow K#pi', 10, 0, 9) ntrack_dp = TH1F( 'ntrack_dp', 'Number of other side tracks for D^{+} #rightarrow K#pi#pi', 10, 0, 9) unweight_sum = 0 reweight_ntr_sum = 0 reweight_npi0_sum = 0 reweight_ntr_mcand_cnt = 0 reweight_npi0_mcand_cnt = 0 unweight_dmbc = TH1F('unweight_dmbc', 'm_{BC}, direct MC', 100, 1.83, 1.89) reweight_ntr_dmbc = TH1F('reweight_ntr_dmbc', 'm_{BC}, track reweighted MC', 100, 1.83, 1.89) reweight_npi0_dmbc = TH1F('reweight_npi0_dmbc', 'm_{BC}, #pi^{0} reweighted MC', 100, 1.83, 1.89) chgpart = (pdgid_pip, pdgid_pim, pdgid_Kp, pdgid_Km, pdgid_mup, pdgid_mum, pdgid_ep, pdgid_em) neupart = (pdgid_KL, pdgid_piz, pdgid_gamma) intpart = chgpart + neupart ntr_denoms = {} gen_dmbc_ntr = {} npi0_denoms = {} gen_dmbc_npi0 = {} for i in range(7 + 1): ntr_denoms[i] = 0 gen_dmbc_ntr[i] = TH1F('gen_dmbc_ntr_' + ` i `, 'm_{BC} for ' + ` i ` + ' tracks', 100, 1.83, 1.89) for i in range(5 + 1): npi0_denoms[i] = 0 gen_dmbc_npi0[i] = TH1F('gen_dmbc_npi0_' + ` i `, 'm_{BC} for ' + ` i ` + ' #pi^{0}', 100, 1.83, 1.89) ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and nselected > 10: break if test and ntotal > 1000: break if pte.ecm < 3.7: continue othsidetrk = 0 othsidepi0 = 0 dtree = makeDDecaySubTree(pte, -1) ddesc = dtree[0].interestingDescendants(intpart, False, False) for i in ddesc: if i.pdgid in chgpart: othsidetrk += 1 if (i.pdgid in chgpart and i.parent.pdgid == pdgid_KS and len(i.parent.daughters) == 1): # This absurd special case is due to GEANT's "K_S -> pi" decay othsidetrk += 1 if i.pdgid == pdgid_piz: othsidepi0 += 1 if (i.pdgid == pdgid_KS) and len(i.daughters) != 2: print i if mode >= 200: mod2 = 1 else: mod2 = 0 if (othsidetrk % 2) != mod2: print '-----------------------------------', othsidetrk print chgpart # for node in makeDecayTree(pte): # pass # if len(node.daughters) == 0 and node.pdgid in chgpart: # print node choice = chooseD(mode, pte, 1) if choice != None and not passDE(choice, pte): choice = None unweight_sum += 1 index_tr = getindex(othsidetrk, ntr_denoms) ntr_denoms[index_tr] += 1 index_pi0 = getpi0index(othsidepi0, npi0_denoms) npi0_denoms[index_pi0] += 1 final_weight_vector_ntr = attr.multiplicity_weight_ntr[reweight] initial_weight_vector_ntr = attr.multiplicity_weight_ntr['init'] final_weight_vector_npi0 = attr.multiplicity_weight_npi0[reweight] initial_weight_vector_npi0 = attr.multiplicity_weight_npi0['init'] reweight_ntr_sum += (final_weight_vector_ntr[index_tr] / initial_weight_vector_ntr[index_tr]) reweight_npi0_sum += (final_weight_vector_npi0[index_pi0] / initial_weight_vector_npi0[index_pi0]) if choice != None: nselected += 1 unweight_dmbc.Fill(pte.dmbc[choice]) reweight_ntr_dmbc.Fill(pte.dmbc[choice], (final_weight_vector_ntr[index_tr] / initial_weight_vector_ntr[index_tr])) reweight_npi0_dmbc.Fill(pte.dmbc[choice], (final_weight_vector_npi0[index_pi0] / initial_weight_vector_npi0[index_pi0])) gen_dmbc_ntr[index_tr].Fill(pte.dmbc[choice]) gen_dmbc_npi0[index_pi0].Fill(pte.dmbc[choice]) mbc.setVal(pte.dmbc[choice]) effs['npi0_denom'] = npi0_denoms effs['ntr_denom'] = ntr_denoms effs['unweight_sum'] = unweight_sum effs['reweight_ntr_sum'] = reweight_ntr_sum effs['reweight_npi0_sum'] = reweight_npi0_sum effs.close() #sys.stdout.write('Saved %s \n' %efffile) f.Write() f.Close() pt.Delete() return nselected, ntotal
def main(opts, args): label = args[0] test = opts.test sys.stdout.write('dhad.sel.extlbkgs ...') sys.stdout.flush() datpath = attr.datpath datatype = 'generic' rootfile = tools.get_rootfile(datatype, label=label, test=test) pt = tools.add_rootfile(rootfile) bkg_mcdmodes = { 'kpi' : mcstringtodmode('K+ pi-'), 'kpipi0' : mcstringtodmode('K+ pi- pi0'), 'k3pi' : mcstringtodmode('K+ pi- pi+ pi-'), 'kkspi' : mcstringtodmode('K- K0 pi+'), 'kkspibar' : mcstringtodmode('K+ K0 pi-'), '3pi' : mcstringtodmode('pi+ pi- pi+'), '3pipi0' : mcstringtodmode('pi+ pi- pi+ pi0'), '5pi' : mcstringtodmode('pi+ pi- pi+ pi- pi+'), 'kskspi' : mcstringtodmode('K0 K0 pi+') } bkg_mcdmodes_rev = {} counts = {} files = {} selpath = os.path.join(attr.datpath, 'sel', label, 'extlbkgs') for i in bkg_mcdmodes: bkg_mcdmodes_rev[bkg_mcdmodes[i]] = i counts[i] = 0 selname = 'singtag_bkg_%s.evt' % i if test: selname += '.test' selfile = tools.check_and_join(selpath, selname) files[i] = open(selfile, 'w') # First number is the sign of the D we should look at for the fake signal; # second number is the mode. bkg_dmodes = { 'kpi' : (-1, 0), 'kpipi0' : (-1, 1), 'k3pi' : (-1, 3), 'kkspi' : (1, 3), 'kkspibar' : (-1, 3), '3pi' : (1, 202), '3pipi0' : (1, 203), '5pi' : (1, 204), 'kskspi' : (1, 204) } ensure_other_side_is_not = { 'kpi' : (mcstringtodmode('K+ pi-'),), 'kpipi0' : (mcstringtodmode('K+ pi- pi0'),), 'k3pi' : (mcstringtodmode('K+ pi- pi+ pi-'), mcstringtodmode('K+ K0 pi-')), 'kkspi' : (mcstringtodmode('K- K0 pi+'), mcstringtodmode('K- pi+ pi- pi+')), 'kkspibar' : (mcstringtodmode('K+ K0 pi-'), mcstringtodmode('K+ pi- pi- pi+')), '3pi' : (), '3pipi0' : (), '5pi' : (), 'kskspi' : () } ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and ntotal > 1000: break mcd = makeDDecaySubTree(pte, 1) mcdb = makeDDecaySubTree(pte, -1) mcdmode = mcDmodeFixRad(mcd[0].mcDmode()) mcdbmode = mcDmodeFixRad(mcdb[0].mcDmode()) if (mcdmode in bkg_mcdmodes_rev): mcdmode_string = bkg_mcdmodes_rev[mcdmode] if mcdbmode not in ensure_other_side_is_not[mcdmode_string]: counts[mcdmode_string] += 1 choice = chooseD(bkg_dmodes[mcdmode_string][1], pte, bkg_dmodes[mcdmode_string][0]) if choice != None and passDE(choice, pte): nselected += 1 files[mcdmode_string].write('%g\n' % pte.dmbc[choice]) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Number of mcdmode: %s. \n' % counts) sys.stdout.flush()
def ddbars(opts, args): tabname = 'entries_ddbars_' + '_'.join(args).replace('/', '_') test = False # opts.test datatype = args[0] label = args[1] rootfile = tools.get_rootfile(datatype, label=label, test=test) print rootfile sys.exit() pt = tools.add_rootfile(rootfile) print pt nd0d0b = 0 ndpdm = 0 ntotal = 0 dmodecount = {} dbmodecount = {} dtmodecount = {} for i in modes: dmodecount[i] = 0 dbmodecount[i] = 0 for pair in possible_double_tags: dtmodecount[pair] = 0 for pte in pt: if pte.entry % 100000 == 0: print pte.entry realdtag = None realdbtag = None ntotal += 1 if pte.mcpdgid[3] == pdgid_Dz: nd0d0b += 1 elif pte.mcpdgid[3] == pdgid_Dp: ndpdm += 1 else: print 'HEEELP!' dtree = makeDDecaySubTree(pte, 1) dbtree = makeDDecaySubTree(pte, -1) d = dtree[0] db = dbtree[0] mcdmode = d.mcDmode() mcdbmode = db.mcDmode() if ((mcDmodeFixRad(mcdmode) == modes[3]['mcdmode']) and mcdmode != mcDmodeFixRad(mcdmode)): for node in d.interestingDescendants(): if node.pdgid == pdgid_gamma: gnode = node break if (gnode.parent.pdgid != pdgid_Dz and abs(gnode.parent.pdgid) != 20213 and gnode.parent.pdgid != pdgid_rhoz and abs(gnode.parent.pdgid) != 313 and abs(gnode.parent.pdgid) != 10323): print 'xxxxxxxxxxxxxxxxxx' print pte.run, pte.event for node in dtree: print node pass ## print 'HELP', mcdmode, pte.mcdmode ## print mcdmodetostring(mcdmode), mcdmodetostring(pte.mcdmode) ## print d ## for node in d.interestingDescendants(): ## print node for j in modes: if mcDmodeFixRad(mcdmode) == modes[j]['mcdmode']: if j in (202, 203, 204): nodes_of_interest = d.interestingDescendants() for node in nodes_of_interest: if node.pdgid == pdgid_KS: dmodecount[j] += 1 realdtag = j break else: dmodecount[j] += 1 realdtag = j if j == 204: daughter_dump(pte, 1) if (False and j in (202, 203, 204) and mcdmodetostring(mcdmode) != 'K0 pi+ ' and len(d.daughters) != 3): tree = makeDecayTree(pte) for node in tree: if node.pdgid == pdgid_Dz: nodes_of_interest = node.interestingDescendants() break print '--------------' print mcdmode, mcdbmode, pte.mcdmode, pte.mcdbmode print mcdmodetostring(mcdmode) for node in tree: print node if mcDmodeFixRad(mcdbmode) == modes[j]['mcdbmode']: if j in (202, 203, 204): nodes_of_interest = db.interestingDescendants() for node in nodes_of_interest: if node.pdgid == pdgid_KS: dbmodecount[j] += 1 realdbtag = j break else: dbmodecount[j] += 1 realdbtag = j if realdtag != None and realdbtag != None: dtmodecount[(realdtag, realdbtag)] += 1 print 'N(all):', ntotal print 'N(D0D0B):', nd0d0b print 'N(D+D-):', ndpdm if nd0d0b > 0: print 'Ratio:', float(ndpdm) / nd0d0b for j in dmodecount: print modes[j]['fname'], dmodecount[j], if j < 200 and nd0d0b > 0: print float(dmodecount[j]) / nd0d0b elif ndpdm > 0: print float(dmodecount[j]) / ndpdm else: print print modes[j]['fnamebar'], dbmodecount[j], if j < 200 and nd0d0b > 0: print float(dbmodecount[j]) / nd0d0b elif ndpdm > 0: print float(dbmodecount[j]) / ndpdm else: print for pair in possible_double_tags: print "%s/%s %d" % (modes[pair[0]]['fname'], modes[pair[1]]['fnamebar'], dtmodecount[pair]) sys.exit()
def output_multspec(reweight, pt, mode, selfile, label, test=False): mode, signs = tools.get_modekey_sign(mode) f = TFile(selfile, 'recreate') load_roofit_lib('signal', label) from ROOT import RooRealVar, RooDataSet, RooArgList, RooArgSet, \ RooGaussian, RooArgusBG, RooCBShape, RooAddPdf, RooPolynomial, \ gSystem, TCanvas efffile = selfile.replace('.root', '.db') effs = shelve.open(efffile) mbc = RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') weight2 = RooRealVar('weight2', 'weight', 1) weight3 = RooRealVar('weight3', 'weight', 1) mbc_aset = RooArgSet(mbc) ntrack_d0 = TH1F('ntrack_d0', 'Number of other side tracks for D^{0} #rightarrow K#pi', 10, 0, 9) ntrack_dp = TH1F('ntrack_dp', 'Number of other side tracks for D^{+} #rightarrow K#pi#pi', 10, 0, 9) unweight_sum = 0 reweight_ntr_sum = 0; reweight_npi0_sum = 0 reweight_ntr_mcand_cnt = 0; reweight_npi0_mcand_cnt = 0 unweight_dmbc = TH1F('unweight_dmbc', 'm_{BC}, direct MC', 100, 1.83, 1.89) reweight_ntr_dmbc = TH1F('reweight_ntr_dmbc', 'm_{BC}, track reweighted MC', 100, 1.83, 1.89) reweight_npi0_dmbc = TH1F('reweight_npi0_dmbc', 'm_{BC}, #pi^{0} reweighted MC', 100, 1.83, 1.89) chgpart = (pdgid_pip, pdgid_pim, pdgid_Kp, pdgid_Km, pdgid_mup, pdgid_mum, pdgid_ep, pdgid_em) neupart = (pdgid_KL, pdgid_piz, pdgid_gamma) intpart = chgpart + neupart ntr_denoms = {}; gen_dmbc_ntr = {}; npi0_denoms = {}; gen_dmbc_npi0 = {} for i in range(7+1): ntr_denoms[i] = 0 gen_dmbc_ntr[i] = TH1F('gen_dmbc_ntr_'+`i`, 'm_{BC} for '+`i`+' tracks', 100, 1.83, 1.89) for i in range(5+1): npi0_denoms[i] = 0 gen_dmbc_npi0[i] = TH1F('gen_dmbc_npi0_'+`i`, 'm_{BC} for '+`i`+' #pi^{0}', 100, 1.83, 1.89) ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if test and nselected > 10: break if test and ntotal > 1000: break if pte.ecm < 3.7: continue othsidetrk = 0; othsidepi0 = 0 dtree = makeDDecaySubTree(pte, -1) ddesc = dtree[0].interestingDescendants(intpart, False, False) for i in ddesc: if i.pdgid in chgpart: othsidetrk += 1 if (i.pdgid in chgpart and i.parent.pdgid == pdgid_KS and len(i.parent.daughters) == 1): # This absurd special case is due to GEANT's "K_S -> pi" decay othsidetrk += 1 if i.pdgid == pdgid_piz: othsidepi0 += 1 if (i.pdgid == pdgid_KS) and len(i.daughters) != 2: print i if mode >= 200: mod2 = 1 else: mod2 = 0 if (othsidetrk % 2) != mod2: print '-----------------------------------', othsidetrk print chgpart # for node in makeDecayTree(pte): # pass # if len(node.daughters) == 0 and node.pdgid in chgpart: # print node choice = chooseD(mode, pte, 1) if choice != None and not passDE(choice, pte): choice = None unweight_sum += 1 index_tr = getindex(othsidetrk, ntr_denoms) ntr_denoms[index_tr] += 1 index_pi0 = getpi0index(othsidepi0, npi0_denoms) npi0_denoms[index_pi0] += 1 final_weight_vector_ntr = attr.multiplicity_weight_ntr[reweight] initial_weight_vector_ntr = attr.multiplicity_weight_ntr['init'] final_weight_vector_npi0 = attr.multiplicity_weight_npi0[reweight] initial_weight_vector_npi0 = attr.multiplicity_weight_npi0['init'] reweight_ntr_sum += (final_weight_vector_ntr[index_tr]/ initial_weight_vector_ntr[index_tr]) reweight_npi0_sum += (final_weight_vector_npi0[index_pi0]/ initial_weight_vector_npi0[index_pi0]) if choice != None: nselected += 1 unweight_dmbc.Fill(pte.dmbc[choice]) reweight_ntr_dmbc.Fill(pte.dmbc[choice], (final_weight_vector_ntr[index_tr]/ initial_weight_vector_ntr[index_tr])) reweight_npi0_dmbc.Fill(pte.dmbc[choice], (final_weight_vector_npi0[index_pi0]/ initial_weight_vector_npi0[index_pi0])) gen_dmbc_ntr[index_tr].Fill(pte.dmbc[choice]) gen_dmbc_npi0[index_pi0].Fill(pte.dmbc[choice]) mbc.setVal(pte.dmbc[choice]) effs['npi0_denom'] = npi0_denoms effs['ntr_denom'] = ntr_denoms effs['unweight_sum'] = unweight_sum effs['reweight_ntr_sum'] = reweight_ntr_sum effs['reweight_npi0_sum'] = reweight_npi0_sum effs.close() #sys.stdout.write('Saved %s \n' %efffile) f.Write() f.Close() pt.Delete() return nselected, ntotal