def main(opts, args): sys.stdout.write('dhad.gen.subset ... ') sys.stdout.flush() parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey, sign = get_modekey_sign(mode) input_label = label.split('/')[0] children = label.split('/')[1] infile = get_rootfile(datatype, mode, input_label) outfile = get_rootfile(datatype, mode, label, opt='Create') if opts.test: outfile += '.test' sys.stdout.write('Input rootfile: %s \n' % infile) sys.stdout.write('Output rootfile: %s \n' % outfile) pt = add_rootfile(infile) nselected, ntotal = copy_events(pt, outfile, sign, children, opts.test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def deltae(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] alt_deltae = {'decutl': -1, 'decuth': 1} canvas = ROOT.TCanvas("aCanvas", "Canvas", 1000, 1000) canvas.Divide(3,3) deltae_hist = {} hist = ROOT.TH1F('deltae', 'DeltaE', 100, -0.1, 0.1) pad = 1 for mode in modes: frametitle = tools.get_mode_root_name(mode) canvas.cd(pad) pad += 1 modekey, sign = get_modekey_sign(mode) deltae_hist[modekey] = ROOT.TH1F('deltae-%s' % modekey, frametitle, 100, -0.1, 0.1) rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) for pte in pt: d =chooseD(modekey, pte, sign, alt_deltae=alt_deltae) if d != None: deltae_hist[modekey].Fill(pte.ddeltae[d]) deltae_hist[modekey].Draw() canvas_output(canvas, figname, opts.test)
def process_generic_single_mode(datatype, mode, label, test): prefix = 'dir_' + label sys.stdout.write('Processing backgrounds for %s ...\n' % mode) sys.stdout.flush() files = {} inputlabel = label if 'noxfeed' in label: inputlabel = label.split('/')[0] rootfile = tools.get_rootfile(datatype, mode, inputlabel) if test: sys.stdout.write('\ntest: rootfile %s\n' % rootfile) pt = tools.add_rootfile(rootfile) bkgname = '%s_%s.evt' % (datatype, mode) bkgname = bkgname.replace('/', '_') bkgfile = tools.set_file(extbase=attr.bkgpath(), prefix=prefix, comname=bkgname) t_iterstart = time.time() nfaked, npassed, ntotal = output_mbc_ebeam(pt, mode, label, bkgfile, test) dur = tools.duration_human(time.time() - t_iterstart) sys.stdout.write('faked %s , passed %s , total %s. done in %s.\n' % (nfaked, npassed, ntotal, dur)) sys.stdout.flush()
def momentum_pi(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) canvas = ROOT.TCanvas("aCanvas", "Canvas", 600, 600) hist = ROOT.TH1F('pip', '#pi momentum in %s' %modename, 100, 0, 1) num = 0 for pte in pt: if opts.test and num >1000: break d =chooseD(modekey, pte, sign) if d != None: num += 1 npi = pte.ddau2[d] pipx = pte.trpipx[npi] pipy = pte.trpipy[npi] pipz = pte.trpipz[npi] pip = sqrt(pipx**2 + pipy**2 + pipz**2) hist.Fill(pip) hist.Draw() canvas_output(canvas, figname, opts.test) hist.Delete()
def process_generic_single_mode(datatype, mode, label, test): prefix = 'dir_'+label sys.stdout.write('Processing backgrounds for %s ...\n' %mode) sys.stdout.flush() files = {} inputlabel = label if 'noxfeed' in label: inputlabel = label.split('/')[0] rootfile = tools.get_rootfile(datatype, mode, inputlabel) if test: sys.stdout.write('\ntest: rootfile %s\n' % rootfile) pt = tools.add_rootfile(rootfile) bkgname = '%s_%s.evt' %(datatype, mode) bkgname = bkgname.replace('/', '_') bkgfile = tools.set_file( extbase=attr.bkgpath(), prefix=prefix, comname=bkgname) t_iterstart = time.time() nfaked, npassed, ntotal = output_mbc_ebeam( pt, mode, label, bkgfile, test) dur = tools.duration_human(time.time()-t_iterstart) sys.stdout.write('faked %s , passed %s , total %s. done in %s.\n' %(nfaked, npassed, ntotal, dur)) sys.stdout.flush()
def double_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.yield: Processing Mode %s...' % mode) sys.stdout.flush() set_modes_attr(label) rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) evtname = datatype + '_' + mode + '.evt' evtpath = os.path.join(attr.datpath, 'evt', label) evtfile = tools.check_and_join(evtpath, evtname) logname = datatype + '_' + mode + '.log' logpath = os.path.join(attr.logpath, 'evt', label) logfile = tools.check_and_join(logpath, logname) if test: sys.stdout.write('\ntest: rootfile %s \n' % rootfile) evtfile = evtfile + '.test' sys.stdout.write('\ntest: evtfile %s\n' %evtfile) logfile = logfile + '.test' sys.stdout.write('\ntest: logfile %s\n' %logfile) opt = label nselected, ntotal = output_mbc_ebeam(pt, mode, evtfile, logfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def mbc(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes) labels = [label] if ',' in label: labels = label.split(',') figname = shorten_figname(figname) mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] frametitle = modename hnames = parse_opts_set(opts.set, 'legend') if hnames: hist_names = hnames.split(',') else: hist_names = labels nBins = 100 Xmin = 1.83 Xmax = 1.89 hist_list = [] for label, hist_name in zip(labels, hist_names): hist_title = frametitle hist = ROOT.TH1D(hist_name, hist_title, nBins, Xmin, Xmax) rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 d =chooseD(modekey, pte, sign, opt=label) if d != None: hist.Fill(pte.dmbc[d]) nselected += 1 sys.stdout.write('Selected %s out of %s. \n' %(nselected, ntotal)) hist_list.append(hist) xtitle = 'mBC (GeV)' legend = ROOT.TLegend(0.66, 0.8, 0.9, 0.9) canvas = draw_hist(hist_list, xtitle, legend) Logy = parse_opts_set(opts.set, 'SetLogy') if Logy != None: canvas.SetLogy(Logy) canvas_output(canvas, figname, opts.test) hist.Delete()
def se9o25(opts, args, figname): particle = args[0] datatype = args[1] mode = args[2] label = args[3] rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) for pte in pt: if opts.test and num >1000: break sys.exit()
def momentum_pi0(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) #canvas = ROOT.TCanvas("aCanvas", "Canvas", 900, 900) var = 'pi0p' title = modename unit = 'GeV' nBins = 100 Xmin = 0. Xmax = 1. xtitle = '#pi^{0} momentum (GeV)' ytitle = 'Events / (%s %s)' % ((Xmax-Xmin)/nBins, unit) hist = ROOT.TH1F(var, title, nBins, Xmin, Xmax) num = 0 for pte in pt: if opts.test and num >1000: break d =chooseD(modekey, pte, sign) if d != None: num += 1 if modekey == 1 or modekey == 203: npi0 = pte.ddau3[d] if modekey == 201: npi0 = pte.ddau4[d] pi0px = pte.pi0px[npi0] pi0py = pte.pi0py[npi0] pi0pz = pte.pi0pz[npi0] pi0p = sqrt(pi0px**2 + pi0py**2 + pi0pz**2) hist.Fill(pi0p) canvas = draw_hist(hist, xtitle, ytitle) canvas_output(canvas, figname, label, test=opts.test)
def ksmass(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] var = 'ksmass' varname = 'K_{S} mass' unit = 'GeV' nBins = 100 Xmin = 0.45 Xmax = 0.55 if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] histname = '%s in %s' %(varname, modename) rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) canvas = ROOT.TCanvas("aCanvas", "Canvas", 600, 600) hist = ROOT.TH1F(var, histname, nBins, Xmin, Xmax) ntotal = 0 nselected = 0 def alt_checkVetoes(mode, pte, index, opt='', sign=None): return True if modekey not in (202, 203, 204): raise ValueError(modekey) for pte in pt: ntotal += 1 if opts.test and ntotal >1000: break d =chooseD(modekey, pte, sign, checkVetoes=alt_checkVetoes) if d != None: nselected += 1 ksmass = pte.ksmass[pte.ddau1[d]] hist.Fill(ksmass) hist.Draw() canvas_output(canvas, figname, opts.test) hist.Delete() sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal))
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 single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.sel.trkmtm: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selfile = get_selfile(datatype, mode, label, test=test) nselected, ntotal = output_trkmtm(pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' %selfile) sys.stdout.flush()
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multcand: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.evt' %(datatype, mode) if test: selname += '.test' nselected, ntotal = output_multcand(pt, mode, selname, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multcand: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.evt' % (datatype, mode) if test: selname += '.test' nselected, ntotal = output_multcand(pt, mode, selname, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def single_tag_mode(datatype, mode, label, test): rootfile = tools.get_rootfile(datatype, mode, label) if test: sys.stdout.write('rootfile: %s \n' % rootfile) pt = tools.add_rootfile(rootfile) evtfile = get_evtfile(datatype, mode, label, 'kpimass', test=test) nselected = 0 ntotal = 0 modekey, sign = tools.get_modekey_sign(mode) if sign == None: raise ValueError(sign) sys.stdout.write('Saving %s ...' % evtfile) sys.stdout.flush() fo = open(evtfile, 'w') for pte in pt: ntotal += 1 if test and nselected > 100: break d = chooseD(modekey, pte, sign) if d != None: dcand = ptobj(pte, d) mbc = dcand.dmbc if mbc > 1.83 and mbc < 1.89: k1 = trkFourTuple(ptobj(pte, dcand.ddau1), 'k') k2 = trkFourTuple(ptobj(pte, dcand.ddau2), 'k') pi = trkFourTuple(ptobj(pte, dcand.ddau3), 'pi') kpimass = invmass(k1, pi) fo.write('%.5f %.5f %.5f %d\n' % (mbc, pte.ecm / 2, kpimass, pte.dcsign[d])) nselected += 1 fo.close() sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal))
def single_tag_mode(datatype, mode, label, test): rootfile = tools.get_rootfile(datatype, mode, label) if test: sys.stdout.write('rootfile: %s \n' %rootfile) pt = tools.add_rootfile(rootfile) evtfile = get_evtfile(datatype, mode, label, 'kkmass', test=test) nselected = 0 ntotal = 0 modekey, sign = tools.get_modekey_sign(mode) if sign == None: raise ValueError(sign) sys.stdout.write('Saving %s ...' %evtfile) sys.stdout.flush() fo = open(evtfile , 'w') for pte in pt: ntotal += 1 if test and nselected > 100: break d = chooseD(modekey, pte, sign) if d != None: dcand = ptobj(pte, d) mbc = dcand.dmbc if mbc > 1.83 and mbc < 1.89: k1 = trkFourTuple(ptobj(pte, dcand.ddau1), 'k') k2 = trkFourTuple(ptobj(pte, dcand.ddau2), 'k') pi = trkFourTuple(ptobj(pte, dcand.ddau3), 'pi') kkmass = invmass(k1,k2) fo.write('%.5f %.5f %.5f %d\n' % (mbc, pte.ecm/2, kkmass, pte.dcsign[d])) nselected += 1 fo.close() sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal))
def single_tag_mode(datatype, mode, label, test=False): sys.stdout.write('dhad.sel.kssideband: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) if test: sys.stdout.write('rootfile: %s \n' % rootfile) pt = tools.add_rootfile(rootfile) selname = '%s_%s.evt' %(datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'evt', label, 'kssideband') selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_kssideband(pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def single_tag_mode(var, datatype, mode, label, test=False): sys.stdout.write('dhad.yld.var(%s): Processing Mode %s...' %(var,mode)) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) evtname = '%s_%s.evt' %(datatype, mode) evtpath = os.path.join(datpath, 'evt', label, 'var', var) evtfile = tools.check_and_join(evtpath, evtname) if var == 'deltae': nselected, ntotal = output_var_deltae(pt, mode, evtfile, label, test) else: raise NameError(var) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.flush()
def mass_kk(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) canvas = ROOT.TCanvas("aCanvas", "Canvas", 600, 600) hist = ROOT.TH1F('kkmass', 'KK mass in %s' %modename, 100, 0, 2) hist.SetXTitle('M(K^{+}K^{-}) (GeV/c^{2})') num = 0 for pte in pt: if opts.test and num >10000: break d =chooseD(modekey, pte, sign) if modekey != 205: raise NameError(modekey) if d != None: num += 1 kaons = [pte.ddau1[d], pte.ddau2[d]] fourvecs = [] for index in kaons: fourvecs.append([pte.trke[index], pte.trkpy[index], pte.trkpy[index], pte.trkpz[index]]) kkmass = invmass(fourvecs[0], fourvecs[1]) hist.Fill(kkmass) hist.Draw() canvas_output(canvas, figname, label, opts.test, outputroot=True) hist.Delete()
def momentum_K(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) canvas = ROOT.TCanvas("aCanvas", "Canvas") pmax = 1 if modekey == 0: pmax = 1.5 hist = ROOT.TH1F('K', 'K momentum in %s' %modename, 100, 0, pmax) num = 0 for pte in pt: if opts.test and num >1000: break d =chooseD(modekey, pte, sign) if d != None: num += 1 nK = pte.ddau1[d] Kpx = pte.trkpx[nK] Kpy = pte.trkpy[nK] Kpz = pte.trkpz[nK] Kp = sqrt(Kpx**2 + Kpy**2 + Kpz**2) hist.Fill(Kp) hist.Draw() canvas_output(canvas, figname, opts.test) hist.Delete()
def single_tag_mode(var, datatype, mode, label, test=False): sys.stdout.write('dhad.sel.var(%s): Processing Mode %s...' % (var, mode)) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) evtfile = get_evtfile(datatype, mode, label, var, test=test) if var == 'pi0mass': nselected, ntotal = output_var_pi0mass(pt, mode, evtfile, label, test) elif var == 'mctruth': nselected, ntotal = output_var_mctruth(pt, mode, evtfile, label, test) elif var == 'mass_kk': nselected, ntotal = output_var_mass_kk(pt, mode, evtfile, label, test) else: raise NameError(var) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' % evtfile) sys.stdout.flush()
def single_tag_mode(reweight, datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multspec: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.root' %(datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'sel', label, 'multspec', reweight) selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_multspec(reweight, pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' %selfile) sys.stdout.flush()
def single_tag_mode(reweight, datatype, mode, label, test=False): sys.stdout.write('dhad.sel.multspec: Processing Mode %s...' % mode) sys.stdout.flush() datpath = attr.datpath rootfile = tools.get_rootfile(datatype, mode, label) pt = tools.add_rootfile(rootfile) selname = '%s_%s.root' % (datatype, mode) if test: selname += '.test' selpath = os.path.join(attr.datpath, 'sel', label, 'multspec', reweight) selfile = tools.check_and_join(selpath, selname) nselected, ntotal = output_multspec(reweight, pt, mode, selfile, label, test) sys.stdout.write(' selected %s out of %s.\n' % (nselected, ntotal)) sys.stdout.write('Saved as %s \n' % selfile) sys.stdout.flush()
def mass_pi0(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] rootfile = get_rootfile(datatype, mode, label) print rootfile, label sys.exit() pt = add_rootfile(rootfile, debug=opts.debug) canvas = ROOT.TCanvas("aCanvas", "Canvas") hist = ROOT.TH1F('pi0mass', '#pi^{0} mass in %s' %modename, 100, 0.1, 0.2) num = 0 for pte in pt: if opts.test and num >1000: break d =chooseD(modekey, pte, sign) if d != None: num += 1 if modekey == 1 or modekey == 203: npi0 = pte.ddau3[d] if modekey == 201: npi0 = pte.ddau4[d] pi0mass = pte.pi0mass[npi0] hist.Fill(pi0mass) hist.Draw() canvas_output(canvas, figname, opts.test) hist.Delete()
def momentum_pim_KS(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] if len(modes) > 1: raise ValueError(modes, 'Only handle one mode at this time!') labels = [label] if ',' in label: labels = label.split(',') figname = shorten_figname(figname) mode = modes[0] modekey, sign = get_modekey_sign(mode) modename = attr.modes[modekey]['uname'] frametitle = modename if modekey not in (202, 203, 204): raise ValueError(modekey) hnames = parse_opts_set(opts.set, 'legend') if hnames: hist_names = hnames.split(',') else: hist_names = labels nBins = 100 Xmin = 0 Xmax = 1 xtitle = '#pi^{-} (K_{S}) momentum (GeV)' legend = ROOT.TLegend(0.75, 0.8, 0.95, 0.9) hist_list = [] for label, hist_name in zip(labels, hist_names): hist_title = frametitle hist = ROOT.TH1D(hist_name, hist_title, nBins, Xmin, Xmax) rootfile = get_rootfile(datatype, mode, label) pt = add_rootfile(rootfile, debug=opts.debug) ntotal = 0 nselected = 0 for pte in pt: ntotal += 1 if opts.test and ntotal >80000: break d =chooseD(modekey, pte, sign, opt=label) if d != None: nks = pte.ddau1[d] npi = pte.ksdau2[nks] pipx = pte.trpipx[npi] pipy = pte.trpipy[npi] pipz = pte.trpipz[npi] pip = sqrt(pipx**2 + pipy**2 + pipz**2) hist.Fill(pip) nselected += 1 sys.stdout.write('%s: Selected %s out of %s. \n' %( label,nselected, ntotal)) hist_list.append(hist) canvas = draw_hist(hist_list, xtitle, legend) canvas_output(canvas, figname, opts.test) hist.Delete()
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 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 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()