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 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()