def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] figname = 'kpimass_' + '_'.join(args[:-1]).replace('/', '_') org = UserFile() org.append(attr.fig_web_header) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth for mode in modes: msg = create_fig_mode(opts, tag, datatype, mode, lowmass, highmass, label) org.append(msg) org.append(attr.fig_web_footer) orgname = '%s.org' % figname orgfile = os.path.join(attr.figpath, label, orgname) org.output(orgfile, verbose=1) orglink = '[[./fig/%s/%s][figure]]' % (label, orgname) sys.stdout.write('\n%s\n\n' % orglink) tools.org_export_as_html(orgfile)
def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] figname = 'kkmass_'+'_'.join(args[:-1]).replace('/', '_') org = UserFile() org.append(attr.fig_web_header) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth for mode in modes: msg = create_fig_mode(opts, tag, datatype, mode, lowmass, highmass, label) org.append(msg) org.append(attr.fig_web_footer) orgname = '%s.org' % figname orgfile = os.path.join(attr.figpath, label, orgname) org.output(orgfile, verbose=1) orglink = '[[./fig/%s/%s][figure]]' %(label, orgname) sys.stdout.write('\n%s\n\n' % orglink) tools.org_export_as_html(orgfile)
def argus(opts, args, figname): ''' ARGUS funcion: a(m; m0, xi, p) = A*m*(1- m^2/m0^2)^p * exp(xi*(1-m^2/m0^2)) ''' canvas = TCanvas("aCanvas", "Canvas", 600, 600) m0 = parse_opts_set(opts.set, 'm0') xi = parse_opts_set(opts.set, 'xi') p = parse_opts_set(opts.set, 'p') fun = 'x*TMath::Power((1-x**2/[0]**2),[2])*exp([1]*(1-x**2/[0]**2))' f1 = TF1('argus', fun, 1.83, 1.86) f1.SetParName(0, 'Resonance mass') f1.SetParName(1, 'Slope parameter') f1.SetParName(2, 'Power') f1.SetParameter(0, m0) f1.SetParameter(1, xi) f1.SetParameter(2, p) f1.Draw() canvas_output(canvas, figname, opts.test)
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 kpimass0(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') dbfile = os.path.join(attr.figpath, label, figname+'.db') fullrangedata, fullrangemc = get_fullrange_data_mc( opts, dbfile, label, 'kpimass', modekey, tag, binbase, binwidth, numbins) scaledict(fullrangedata, 1/sumdict(fullrangedata)) scaledict(fullrangemc, 1/sumdict(fullrangemc)) gdata = TGraph(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c','kpi', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) hr = c1.DrawFrame(0.5, 0.0, 1.5, 0.04) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} #pi^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() canvas_output(c1, figname, label, opts.test)
def kpimass0(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') dbfile = os.path.join(attr.figpath, label, figname + '.db') fullrangedata, fullrangemc = get_fullrange_data_mc(opts, dbfile, label, 'kpimass', modekey, tag, binbase, binwidth, numbins) scaledict(fullrangedata, 1 / sumdict(fullrangedata)) scaledict(fullrangemc, 1 / sumdict(fullrangemc)) gdata = TGraph(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c', 'kpi', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) hr = c1.DrawFrame(0.5, 0.0, 1.5, 0.04) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} #pi^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() canvas_output(c1, figname, label, opts.test)
def trim_pad(pad, opts): TitleOffset = parse_opts_set(opts.set, 'SetTitleOffset') if TitleOffset == None: TitleOffset = 1.35 objs = pad.GetListOfPrimitives() for obj in objs: if isinstance(obj, ROOT.TFrame): obj.SetFillColor(0) if isinstance(obj, ROOT.RooPlot): yax = obj.GetYaxis() yax.SetTitleOffset(TitleOffset) obj.SetXTitle('#font[72]{M}_{BC} (GeV/#font[72]{c}^{2})') obj.SetYTitle('Events / (1 MeV/#font[72]{c}^{2})') obj.SetMarkerSize(0.5) if isinstance(obj, ROOT.TPaveText): obj.SetBorderSize(0) obj.SetFillColor(0) if isinstance(obj, ROOT.RooCurve): if obj.GetLineColor() in [ROOT.kGreen, ROOT.kMagenta]: objs.remove(obj) else: obj.SetLineWidth(2) pad.SetFillColor(0) pad.SetRightMargin(0.05) LeftMargin = parse_opts_set(opts.set, 'SetLeftMargin') if LeftMargin == None: LeftMargin = 0.15 pad.SetLeftMargin(LeftMargin) Logy = parse_opts_set(opts.set, 'SetLogy') if Logy != None: pad.SetLogy(Logy) return pad
def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth for mode in modes: if opts.set and 'interact' in opts.set: fit_single_mode(datatype, mode, label, lowmass, highmass, opts.test) else: submit_batch_job(datatype, mode, label, lowmass, highmass, opts)
def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth for mode in modes: if opts.set and 'interact' in opts.set: fit_single_mode(datatype, mode, label, lowmass, highmass, opts.test) else: submit_batch_job(datatype, mode, label, lowmass, highmass, opts)
def cleog_mode(opts, mode, label, tasks=[1]): sys.stdout.write('dhad.gen: Mode %s \n' %mode ) sys.stdout.write('dhad.gen: Label %s \n' %label) sys.stdout.write('dhad.gen: Task %s \n' %tasks) check_decfile(opts, mode, label) check_and_copy_file(opts, label, 'genmc.tcl') check_and_copy_file(opts, label, 'runlist') check_and_copy_file(opts, label, 'cleog-generic-array.sh') jobtype = 'cleog' seeds = tools.parse_opts_set(opts.set, 'seeds') edit_fix_single_mode_list(opts, mode, label) create_tag_numbers_file(opts, mode, label) for task_id in tasks: if opts.set and 'interact' in opts.set: bash_file, logfile = create_bash_interact( jobtype, mode, task_id, label=label, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') else: subprocess.Popen(bash_file) continue if opts.set and 'bg' in opts.set: bash_file, logfile = create_bash_interact( jobtype, mode, task_id, label=label, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') sys.stdout.write(logfile + '\n') else: sys.stdout.write('Save log as %s.\n' %logfile) process = subprocess.Popen(bash_file, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) f = UserFile() f.append(process.communicate()[0]) f.output(logfile) continue bash_file = create_bash_fix_mc_job(jobtype, label, task_id, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') continue output = commands.getoutput(bash_file) sys.stdout.write(output+ '\n')
def get_fullrange_data_mc(opts, dbfile, label, evtdir, modekey, tag, binbase, binwidth, numbins): dbmode = parse_opts_set(opts.set, 'dbmode') if os.access(dbfile, os.F_OK) and dbmode == None: db = open(dbfile) fullrangedata, fullrangemc = json.load(db) return fullrangedata, fullrangemc if dbmode == None: dbmode = 'w' db = open(dbfile, dbmode) fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, evtdir) evtfiledata = tools.set_file('evt', 'data', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth parse_evtfile(evtfiledata, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) json.dump((fullrangedata, fullrangemc), db) db.close() sys.stdout.write('Save db as: %s \n' % dbfile) return fullrangedata, fullrangemc
def create_tag_numbers_file(opts, mode, label): tag_numbers = tools.parse_opts_set(opts.set, 'tag_numbers') if tag_numbers == None: tag_numbers = attr.get_tag_numbers(mode) tag_numbers_file = os.path.join(attr.datpath, 'signal', label, 'src', 'tag_numbers', mode) f = UserFile() f.data.append(str(tag_numbers)) verbose = opts.verbose if opts.test: verbose = 1 f.output(tag_numbers_file, verbose=verbose)
def pi0mass(opts, args, figname): var = 'pi0mass' varname = '#pi^{0} mass' unit = 'GeV' nBins = 100 Xmin = 0.115 Xmax = 0.16 parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] figname = shorten_figname(figname) mode = modes[0] modekey = get_modekey(mode) modename = attr.modes[modekey]['uname'] frametitle = '#pi^{0} mass in %s' % modename labels = [label] if ',' in label: labels = label.split(',') hnames = parse_opts_set(opts.set, 'legend') if hnames: hist_names = hnames.split(',') else: hist_names = labels hist_list = [] for label, hist_name in zip(labels, hist_names): hist_title = frametitle hist = ROOT.TH1D(hist_name, hist_title, nBins, Xmin, Xmax) evtfile = get_evtfile(datatype, mode, label, var, test=False) hist = tools.fill_hist_evtfile(hist, evtfile) hist_list.append(hist) xtitle = '%s (%s)' %(varname, unit) legend = ROOT.TLegend(0.66, 0.8, 0.9, 0.9) canvas = draw_hist(hist_list, xtitle, legend) canvas_output(canvas, figname, test=opts.test)
def ntuple_generic(opts, args): grade = args[0] skim = args[1] label = args[2] datasets = [] if 'data' in label: datasets.append(label) elif '281ipb' in label: numbers = ['31', '32', '33', '35', '36', '37'] for num in numbers: dataset = 'data' + num datasets.append(dataset) elif '537ipb' in label: numbers = ['43', '44', '45', '46'] for num in numbers: dataset = 'data' + num datasets.append(dataset) else: raise NameError(label) for dataset in datasets: if not opts.set or 'jobs' not in opts.set: update_dataselection_tcl('generic', dataset, grade, skim) logfile, qjobname, bash_file = create_bash_dtuple_generic( dataset, grade, skim, label) qsub_jobs(logfile, qjobname, bash_file, _test) continue njobs = parse_opts_set(opts.set, 'njobs') update_dataselection_tcl('generic', dataset, grade, skim, njobs) for job in range(njobs): subdataset = '%s_%s_%s' % (dataset, njobs, job + 1) logfile, qjobname, bash_file = create_bash_dtuple_generic( subdataset, grade, skim, label) qsub_jobs(logfile, qjobname, bash_file, _test)
def get_fullrange_data_mc(opts, dbfile, label, evtdir, modekey, tag, binbase, binwidth, numbins): dbmode = parse_opts_set(opts.set, 'dbmode') if os.access(dbfile, os.F_OK) and dbmode == None: db = open(dbfile) fullrangedata, fullrangemc = json.load(db) return fullrangedata, fullrangemc if dbmode == None: dbmode = 'w' db = open(dbfile, dbmode) fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, evtdir) evtfiledata = tools.set_file('evt', 'data', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth parse_evtfile(evtfiledata, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) json.dump((fullrangedata,fullrangemc), db) db.close() sys.stdout.write('Save db as: %s \n' % dbfile) return fullrangedata, fullrangemc
def kkmass1(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') nohtml = parse_opts_set(opts.set, 'nohtml') if nohtml == None: outputhtml = True else: outputhtml = False dbfile = os.path.join(attr.figpath, label, figname+'.db') alldata, fullrangemc = get_fullrange_data_mc( opts, dbfile, label, 'kkmass', modekey, tag, binbase, binwidth, numbins) fullrangedata = {} init_dict(fullrangedata) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth prefix = 'dir_%s/kkmass/%s_%s' % (label, lowmass, highmass) datafile = tools.set_file('txt', 'data', modekey, tag, prefix=prefix, extbase=attr.fitpath) if os.access(datafile, os.F_OK): parsefile(datafile, lowmass, highmass, fullrangedata) else: sys.stdout.write('Skipped %s %s ...\n' % (lowmass, highmass)) scaledict(fullrangedata, 1/sumdict(fullrangedata)) scaledict(fullrangemc, 1/sumdict(fullrangemc)) gdata = TGraphAsymmErrors(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata), getarray('exl', fullrangedata), getarray('exh', fullrangedata), getarray('eyl', fullrangedata), getarray('eyh', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c','kk', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.5, 0.0, 1.5, 0.04) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} #pi^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21); gmc.SetMarkerColor(kRed); gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20); gdata.SetMarkerColor(kBlue); gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.92, 0.92) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.SetFillColor(0) leg.SetBorderSize(0) leg.Draw() canvas_output(c1, figname, label, opts.test, outputhtml=outputhtml)
def kkmass0_old(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') figname = 'kkmass0_'+'_'.join(args[:-1]).replace('/', '_') figname = figname.replace(',', '_')+'.eps' epsfile = os.path.join(attr.figpath, label, figname) fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfiledata = tools.set_file('evt', 'data', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth parse_evtfile(evtfiledata, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) scaledict(fullrangedata, 1/sumdict(fullrangedata)) scaledict(fullrangemc, 1/sumdict(fullrangemc)) gdata = TGraph(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c','kk',600,600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.95, 0.0, 1.95, 0.12) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} K^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() c1.Print(epsfile) eps2pdf(epsfile)
def kkmass1(opts, args, figname): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') nohtml = parse_opts_set(opts.set, 'nohtml') if nohtml == None: outputhtml = True else: outputhtml = False dbfile = os.path.join(attr.figpath, label, figname + '.db') alldata, fullrangemc = get_fullrange_data_mc(opts, dbfile, label, 'kkmass', modekey, tag, binbase, binwidth, numbins) fullrangedata = {} init_dict(fullrangedata) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth prefix = 'dir_%s/kkmass/%s_%s' % (label, lowmass, highmass) datafile = tools.set_file('txt', 'data', modekey, tag, prefix=prefix, extbase=attr.fitpath) if os.access(datafile, os.F_OK): parsefile(datafile, lowmass, highmass, fullrangedata) else: sys.stdout.write('Skipped %s %s ...\n' % (lowmass, highmass)) scaledict(fullrangedata, 1 / sumdict(fullrangedata)) scaledict(fullrangemc, 1 / sumdict(fullrangemc)) gdata = TGraphAsymmErrors(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata), getarray('exl', fullrangedata), getarray('exh', fullrangedata), getarray('eyl', fullrangedata), getarray('eyh', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c', 'kk', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.5, 0.0, 1.5, 0.04) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} #pi^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.92, 0.92) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.SetFillColor(0) leg.SetBorderSize(0) leg.Draw() canvas_output(c1, figname, label, opts.test, outputhtml=outputhtml)
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 kkmass0_old(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') figname = 'kkmass0_' + '_'.join(args[:-1]).replace('/', '_') figname = figname.replace(',', '_') + '.eps' epsfile = os.path.join(attr.figpath, label, figname) fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfiledata = tools.set_file('evt', 'data', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth parse_evtfile(evtfiledata, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) scaledict(fullrangedata, 1 / sumdict(fullrangedata)) scaledict(fullrangemc, 1 / sumdict(fullrangemc)) gdata = TGraph(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c', 'kk', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.95, 0.0, 1.95, 0.12) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} K^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() c1.Print(epsfile) eps2pdf(epsfile)
def cleog_mode(opts, mode, label, tasks=[1]): sys.stdout.write('dhad.gen: Mode %s \n' % mode) sys.stdout.write('dhad.gen: Label %s \n' % label) sys.stdout.write('dhad.gen: Task %s \n' % tasks) check_decfile(opts, mode, label) check_and_copy_file(opts, label, 'genmc.tcl') check_and_copy_file(opts, label, 'runlist') check_and_copy_file(opts, label, 'cleog-generic-array.sh') jobtype = 'cleog' seeds = tools.parse_opts_set(opts.set, 'seeds') edit_fix_single_mode_list(opts, mode, label) create_tag_numbers_file(opts, mode, label) for task_id in tasks: if opts.set and 'interact' in opts.set: bash_file, logfile = create_bash_interact(jobtype, mode, task_id, label=label, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') else: subprocess.Popen(bash_file) continue if opts.set and 'bg' in opts.set: bash_file, logfile = create_bash_interact(jobtype, mode, task_id, label=label, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') sys.stdout.write(logfile + '\n') else: sys.stdout.write('Save log as %s.\n' % logfile) process = subprocess.Popen(bash_file, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) f = UserFile() f.append(process.communicate()[0]) f.output(logfile) continue bash_file = create_bash_fix_mc_job(jobtype, label, task_id, seeds=seeds) if opts.test: sys.stdout.write(bash_file + '\n') continue output = commands.getoutput(bash_file) sys.stdout.write(output + '\n')
def kkmass2(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase + i * binwidth highmass = binbase + (i + 1) * binwidth prefix = 'dir_%s/kkmass/%s_%s' % (label, lowmass, highmass) datafile = tools.set_file('txt', 'data', modekey, tag, prefix=prefix, extbase=attr.fitpath) #mcfile = tools.set_file('txt', 'signal', modekey, tag, # prefix=prefix, extbase=attr.fitpath) if os.access(datafile, os.F_OK): # and os.access(mcfile, os.F_OK): parsefile(datafile, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) else: sys.stdout.write('Skipped %s %s ...\n' % (lowmass, highmass)) scaledict(fullrangedata, 1 / sumdict(fullrangedata)) scaledict(fullrangemc, 1 / sumdict(fullrangemc)) gdata = TGraphAsymmErrors(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata), getarray('exl', fullrangedata), getarray('exh', fullrangedata), getarray('eyl', fullrangedata), getarray('eyh', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c', 'kk', 600, 600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.95, 0.0, 1.95, 0.12) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} K^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21) gmc.SetMarkerColor(kRed) gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20) gdata.SetMarkerColor(kBlue) gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() c1.Print('comparison.eps') eps2pdf('comparison.eps')
def kkmass2(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] mode = modes[0] modekey = tools.get_modekey(mode) binbase = parse_opts_set(opts.set, 'binbase') binwidth = parse_opts_set(opts.set, 'binwidth') numbins = parse_opts_set(opts.set, 'numbins') fullrangedata = {} init_dict(fullrangedata) fullrangemc = {} init_dict(fullrangemc) evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') evtfilemc = tools.set_file('evt', 'signal', modekey, tag, prefix='', forceCombine=1, extbase=evtpath) for i in xrange(numbins): lowmass = binbase+i*binwidth highmass = binbase+(i+1)*binwidth prefix = 'dir_%s/kkmass/%s_%s' % (label, lowmass, highmass) datafile = tools.set_file('txt', 'data', modekey, tag, prefix=prefix, extbase=attr.fitpath) #mcfile = tools.set_file('txt', 'signal', modekey, tag, # prefix=prefix, extbase=attr.fitpath) if os.access(datafile, os.F_OK): # and os.access(mcfile, os.F_OK): parsefile(datafile, lowmass, highmass, fullrangedata) parse_evtfile(evtfilemc, lowmass, highmass, fullrangemc) else: sys.stdout.write('Skipped %s %s ...\n' % (lowmass, highmass)) scaledict(fullrangedata, 1/sumdict(fullrangedata)) scaledict(fullrangemc, 1/sumdict(fullrangemc)) gdata = TGraphAsymmErrors(len(fullrangedata['x']), getarray('x', fullrangedata), getarray('y', fullrangedata), getarray('exl', fullrangedata), getarray('exh', fullrangedata), getarray('eyl', fullrangedata), getarray('eyh', fullrangedata)) gmc = TGraph(len(fullrangemc['x']), getarray('x', fullrangemc), getarray('y', fullrangemc)) c1 = TCanvas('c','kk',600,600) c1.SetLeftMargin(0.15) c1.SetRightMargin(0.05) c1.SetBottomMargin(0.15) c1.SetTopMargin(0.05) #hr = c1.DrawFrame(0.95, 0.0, 1.95, 0.12) hr = c1.DrawFrame(0.9, 0.0, 1.8, 0.1) hr.GetYaxis().SetTitle('Yield (arbitrary units)') hr.GetXaxis().SetTitle('M(K^{-} K^{+}) (GeV/#font[72]{c}^{2})') hr.GetYaxis().SetTitleOffset(1.4) hr.GetYaxis().SetTitleSize(0.05) hr.GetXaxis().SetTitleOffset(1.3) hr.GetXaxis().SetTitleSize(0.05) gmc.SetMarkerStyle(21); gmc.SetMarkerColor(kRed); gmc.SetMarkerSize(0.6) gmc.SetLineColor(kRed) gmc.Draw("PL") gdata.SetMarkerStyle(20); gdata.SetMarkerColor(kBlue); gdata.SetMarkerSize(0.6) gdata.Draw("P") leg = TLegend(0.6, 0.75, 0.95, 0.95) leg.AddEntry(gdata, 'Data', 'pl') leg.AddEntry(gmc, 'MC', 'pl') leg.Draw() c1.Print('comparison.eps') eps2pdf('comparison.eps')