def fit_single_mode(datatype, mode, label, lowmass, highmass, test): evtpath = os.path.join(attr.datpath, 'sel', label, 'kkmass') modekey = tools.get_modekey(mode) tag = 'single' evtfile = tools.set_file('evt', datatype, modekey, tag, prefix='', forceCombine=1, extbase=evtpath) load_roofit_lib(datatype, label) cuts = '%f<kkmass && kkmass<%f' % (lowmass, highmass) #err_type = 'ASYM' err_type = 'SYMM' setGamma, setMres, setR, mc = get_common_parameters(datatype, label) Sigma, Fa, Fb, Sa, Sb = get_resolution_paras(modekey, label) N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi = init_paras_single( label, datatype, 's', modekey) title1 = '%s : %s < KK mass < %s ' %(attr.modes[modekey]['uname'], lowmass, highmass) title2 = '%s : %s < KK mass < %s ' %(attr.modes[modekey]['unamebar'], lowmass, highmass) prefix='dir_%s/kkmass2/%s_%s' % (label, lowmass, highmass) epsfile = tools.set_file('eps', datatype, modekey, tag, prefix=prefix, extbase=attr.figpath) txtfile = tools.set_file('txt', datatype, modekey, tag, prefix=prefix, extbase=attr.fitpath) #mbc_gau_che(evtfile, mc, setMres, setGamma, setR, sigmap1, Sa, Sb, Fa, mbc_dline_che(evtfile, mc, setMres, setGamma, setR, sigmap1, Sa, Sb, Fa, Fb, md, p, xi, N1, N2, Nbkgd1, Nbkgd2, title1, title2, epsfile, txtfile, cuts=cuts, err_type=err_type, test=test) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def main(opts, args): if len(args) == 3: brsfile = create_brsfile_three(args) elif len(args) == 2: brsfile = create_brsfile_two(args) else: raise NameError(args) brspath, brsname = os.path.split(brsfile) os.chdir(brspath) figname = brsname.replace('.mnf', '.eps') p = pexpect.spawn ('mn_fit') p.expect ('Give screen device name') p.sendline ('\n') p.expect ('MN_CMD> ') p.sendline ('exec %s' %brsname) if len(args) == 3: p.expect ('any character to skip') p.sendline ('\n') p.expect ('End of Macro %s' %brsname) p.sendline ('\n') p.expect ('MN_CMD> ') p.sendline ('quit') shutil.copyfile('plot.eps', figname) eps2pdf(figname) eps2png(figname) sys.stdout.write('Save as %s/%s \n' %(brspath, figname))
def draw_momenta_kkpi(figpath, datatype, mode, label, test): modekey = tools.get_modekey(mode) sname = attr.modes[modekey]['sname'].lower() figname = '%s_momenta' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') #tab = DHadTable() #tab.row_append(['Name', 'Data/MC']) # -------------------------------------------------- h_pkm = {}; h_pkp = {}; h_ppi = {} h_pkm_c = {}; h_pkp_c = {}; h_ppi_c = {} for datatype in [datatype]: selfile = get_selfile(datatype, mode, label, test=test) selfile = selfile.replace('/trkmtm/', '/trkmtm2/') f = TFile(selfile) if datatype == 'signal': # or datatype == 'generic': tp = 'mc' #if datatype == 'data': # tp = 'data' h_pkm[tp]= f.Get('h_pk'+tp) h_pkp[tp]= f.Get('h_ppi1'+tp) h_ppi[tp]= f.Get('h_ppiz'+tp) h_pkm_c[tp]= f.Get('h_pk_c'+tp) h_pkp_c[tp]= f.Get('h_ppi1_c'+tp) h_ppi_c[tp]= f.Get('h_ppiz_c'+tp) f.Clear() #ratio = h_pkm['data'].Integral()/h_pkm['mc'].Integral() c1 = TCanvas('c1', 'canvas', 900, 900) c1.Divide(2,2) c1.cd(1) h_pkm['mc'].Draw() #h_pkm['data'].Draw('PE') #h_pkm['mc'].Scale(ratio) #h_pkm['mc'].Draw('SAME') c1.cd(2) h_pkp['mc'].Draw() #h_pkp['data'].Draw('PE') #h_pkp['mc'].Scale(ratio) #h_pkp['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppi['mc'].Draw() #h_ppi['data'].Draw('PE') #h_ppi['mc'].Scale(ratio) #h_ppi['mc'].Draw('SAME') c1.Print(epsfile) tools.eps2pdf(epsfile)
def stage_nondiag(dt_type, label, x, y, interact=False): if label != '281ipbv0.2': load_roofit_lib(dt_type, label) ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle("Plain") # STAGE 1: fit for non-diagonal sys.stdout.write('Stage 1: fit non-diagonal.\n') single_modes = [(pair, sign) for pair in modes for sign in [-1, 1]] prefix='dir_'+label+'/crossfeeds' #for x, y in [(x, y) for x in single_modes for y in single_modes if x!=y]: if x[1] == 1: uname = modes[x[0]]['uname'] fname = modes[x[0]]['fname'] else: uname = modes[x[0]]['unamebar'] fname = modes[x[0]]['fnamebar'] if y[1] == 1: unameb = modes[y[0]]['uname'] fnameb = modes[y[0]]['fname'] else: unameb = modes[y[0]]['unamebar'] fnameb = modes[y[0]]['fnamebar'] title = '%s fakes %s' % (uname, unameb) bkgname = ('%s_Single_%s_fakes_Single_%s.evt' %(dt_type, fname, fnameb)) bkgfile = get_bkgfile(bkgname, label) epsname = '%s_Single_%s_fakes_Single_%s.eps' % (dt_type, fname, fnameb) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=epsname) txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fnameb) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname) alpha, mass, n, sigma = get_paras(dt_type, label, fnameb) par_str = '("%s", "%s", "%s", "%s", %s, %s, %s, %s)' par_tuple = (title, bkgfile, epsfile, txtfile, alpha, mass, n, sigma) par = par_str % par_tuple source = 'crossfeeds_nondiag.C' #if interact: source = os.path.join(attr.srcfitpath, source) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() ROOT.gROOT.Macro(source + par) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] for mode in modes: sys.stdout.write('Processing mode %s ...' % mode) prefix = 'dir_%s' % label if mode == 'double_all_d0s': comname = '%s_%s' % (datatype, 'Double_all_D0s') elif mode == 'double_all_dps': comname = '%s_%s' % (datatype, 'Double_all_Dps') else: comname = '%s_%s' % (datatype, mode) finname = set_file('root', comname=comname, prefix=prefix, extbase=attr.figpath) foutname = finname.replace('.root', '_trim.eps') comname1 = '%s_%s' % (datatype, mode.split('__')[0]) #comname2 = '%s_%s_%s' %(datatype, tag, mode.split('__')[1]) foutname1 = foutname.replace(comname, comname1) #foutname2 = foutname.replace(comname, comname2) #load_roofit_lib(datatype, label) fin = TFile.Open(finname, 'READ') if tag == 'single': canvas_name = 'canvas' else: canvas_name = 'c' canvas = fin.Get(canvas_name) pad1 = canvas.GetPrimitive(canvas_name + '_1') if mode == 'double_all_d0s' or mode == 'double_all_dps': pad1 = trim_pad2(pad1, opts) else: pad1 = trim_pad(pad1, opts) pad1.Draw() pad1.SaveAs(foutname1) eps2pdf(foutname1)
def main(opts, args): parsed = parse_args(args) datatype = parsed[0] tag = parsed[1] modes = parsed[2] label = parsed[3] for mode in modes: sys.stdout.write('Processing mode %s ...' %mode) prefix = 'dir_%s' % label if mode == 'double_all_d0s': comname = '%s_%s' %(datatype, 'Double_all_D0s') elif mode == 'double_all_dps': comname = '%s_%s' %(datatype, 'Double_all_Dps') else: comname = '%s_%s' %(datatype, mode) finname = set_file('root', comname=comname, prefix=prefix, extbase=attr.figpath) foutname = finname.replace('.root', '_trim.eps') comname1 = '%s_%s' %(datatype, mode.split('__')[0]) #comname2 = '%s_%s_%s' %(datatype, tag, mode.split('__')[1]) foutname1 = foutname.replace(comname, comname1) #foutname2 = foutname.replace(comname, comname2) #load_roofit_lib(datatype, label) fin = TFile.Open(finname, 'READ') if tag == 'single': canvas_name = 'canvas' else: canvas_name = 'c' canvas = fin.Get(canvas_name) pad1 = canvas.GetPrimitive(canvas_name+'_1') if mode == 'double_all_d0s' or mode == 'double_all_dps': pad1 = trim_pad2(pad1, opts) else: pad1 = trim_pad(pad1, opts) pad1.Draw() pad1.SaveAs(foutname1) eps2pdf(foutname1)
def stage_diag(dt_type, label, mode, sign, interact=False): if label != '281ipbv0.2': load_roofit_lib(dt_type, label) ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle("Plain") sys.stdout.write('Stage 0: Do fits for diagonal. Mode: (%s, %s) \n' %(mode, sign)) prefix='dir_'+label+'/crossfeeds' if sign == 1: uname = modes[mode]['uname'] fname = modes[mode]['fname'] else: uname = modes[mode]['unamebar'] fname = modes[mode]['fnamebar'] title = '%s correct reco' % uname bkgname = ('%s_Single_%s_fakes_Single_%s.evt' %(dt_type, fname, fname)) bkgfile = get_bkgfile(bkgname, label) epsname = '%s_Single_%s_fakes_Single_%s.eps' % (dt_type, fname, fname) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=epsname) txtname = '%s_Single_%s_fakes_Single_%s.txt' % (dt_type, fname, fname) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=txtname) par_str = '("%s", "%s", "%s", "%s")' par_tuple = (title, bkgfile, epsfile, txtfile) par = par_str % par_tuple source = 'crossfeeds.C' #if interact: source = os.path.join(attr.srcfitpath, source) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() ROOT.gROOT.Macro(source + par) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def fit_sidebands_single_mode(datatype, mode, label, test): load_roofit_lib(datatype, label) dt_type=datatype.replace('/', '_') modekey = tools.get_modekey(mode) comname = '%s_%s' %(dt_type, mode) input_label = label sdbpath = os.path.join(attr.evtpath, input_label) sdbfile = set_file(extbase=sdbpath, comname=comname, ext='evt') has_charge_conjugate = False if '__' in mode: has_charge_conjugate = True if not os.access(sdbfile, os.F_OK): if has_charge_conjugate: sdbfile = set_file(extbase=sdbpath, dt_type=dt_type, tag='s', mode=modekey, comname=comname, ext='evt', forceCombine=1) else: raise ValueError(sdbfile) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=comname, ext='eps') txtpath = os.path.join(attr.fitpath, label) txtfile = set_file(extbase=txtpath, comname=comname, ext='txt') if test: epsfile = epsfile + '.test' txtfile = txtfile + '.test' ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV') dflav = ROOT.RooCategory('dflav','D0 flavor') dflav.defineType('dflav',1) dflav.defineType('dbarflav',-1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) dataset = ROOT.RooDataSet.read(sdbfile, dataset_args) arg_cutoff = ebeam arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) arg_power = ROOT.RooRealVar('arg_power', 'Argus power', 0.5, 0.1, 1.5) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') pars = [arg_slope, arg_power, bkg, sigma, yld] mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope, arg_power) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) # e Save = ROOT.RooFit.Save(ROOT.kTRUE) # r Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) # no h Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) # no q if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if has_charge_conjugate: yld_bar = ROOT.RooRealVar('yield_bar', 'Dbar yield', 100, 0, 200000) bkg_bar = ROOT.RooRealVar('bkg_bar', 'Background Bar', 100, 0, 1000000) pars.extend([yld_bar, bkg_bar]) mbc_d0bar = ROOT.RooRealVar('mbc_d0bar', 'D0Bar Mbc', 1.8647, 'GeV') mbc_dm = ROOT.RooRealVar('mbc_dm', 'D- Mbc', 1.8694, 'GeV') gauss_d0bar = ROOT.RooGaussian('gauss_d0bar', 'D0bar gaussian', mbc, mbc_d0bar, sigma) gauss_dm = ROOT.RooGaussian('gauss_dm', 'D- gaussian', mbc, mbc_dm, sigma) sumpdf_d0bar = ROOT.RooAddPdf('sumpdf_d0bar', 'D0bar sum pdf', ROOT.RooArgList(gauss_d0bar, argus), ROOT.RooArgList(yld_bar, bkg_bar)) sumpdf_dm = ROOT.RooAddPdf('sumpdf_dm', 'Dm sum pdf', ROOT.RooArgList(gauss_dm, argus), ROOT.RooArgList(yld_bar, bkg_bar)) pdf = ROOT.RooSimultaneous('totalPdf', 'totalPdf', dflav) if 'D0' in mode: pdf.addPdf(sumpdf_d0, 'dflav') pdf.addPdf(sumpdf_d0bar, 'dbarflav') else: pdf.addPdf(sumpdf_dp, 'dflav') pdf.addPdf(sumpdf_dm, 'dbarflav') if 'nogaus' in label: yld.setVal(1) yld.setConstant(ROOT.kTRUE) pars.remove(yld) if 'floatsigma' not in label: datatype = 'data' tag = 'single' if '818ipb' in label: prefix = 'dir_818ipbv12' frame_max = 1500 #bkg_generic_ddbar_818_max[mode] else: raise NameError(label) tabfile = set_file('txt', datatype, modekey, tag, prefix=prefix, extbase=attr.fitpath) sys.stdout.write('Using width from %s \n' %tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) pars.remove(sigma) #res = pdf.fitTo(dataset, Extended, Save, Verbose) res = pdf.fitTo(dataset, 'emr') #Migrad only, no MINOS res.Print('v') if not has_charge_conjugate: canvas = ROOT.TCanvas('canvas', 'canvas1', 600, 600) canvas.SetFixedAspectRatio(0) xframe = mbc.frame() xframe.SetMaximum(frame_max) xframe.SetMarkerSize(0.3) dataset.plotOn(xframe) pdf.plotOn(xframe) nfitParam = len(pars) chisq_ndof = xframe.chiSquare(nfitParam) nbin = xframe.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) xframe.addObject(chisqbox) pdf.paramOn(xframe, dataset) xframe.SetTitle('Sidebands of %s' % mode) xframe.GetYaxis().SetTitleSize(0.03) xframe.GetYaxis().SetLabelSize(0.03) xframe.GetYaxis().SetTitleOffset(1.8) xframe.GetXaxis().SetTitleSize(0.03) xframe.GetXaxis().SetLabelSize(0.03) xframe.GetXaxis().SetTitleOffset(1.2) xframe.Draw() else: canvas = ROOT.TCanvas('canvas','mbc', 1200, 400); canvas.Divide(3,1) title1 = attr.modes[modekey]['uname'] title2 = attr.modes[modekey]['unamebar'] canvas_1 = canvas.GetListOfPrimitives().FindObject('canvas_1') canvas_2 = canvas.GetListOfPrimitives().FindObject('canvas_2') canvas_1.SetLogy() canvas_2.SetLogy() ebeam.setBins(900) canvas.cd(1) mbcFrame=mbc.frame() mbcFrame=mbc.frame(60) dflav.setLabel('dflav') ebeam_aset = ROOT.RooArgSet(ebeam, dflav) ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset, dataset) Cut = ROOT.RooFit.Cut("dflav==dflav::dflav") LineColor = ROOT.RooFit.LineColor(ROOT.kRed) LineWidth = ROOT.RooFit.LineWidth(1) #Slice = ROOT.RooFit.Slice(dflav, 'dflav') Slice = ROOT.RooFit.Slice(dflav) ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata) dataset.plotOn(mbcFrame, Cut) mbcFrame.getAttMarker().SetMarkerSize(0.6) mbcFrame.Draw() pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData) nfitParam = len(pars) - 2 chisq_ndof = mbcFrame.chiSquare(nfitParam) nbin = mbcFrame.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) mbcFrame.addObject(chisqbox) mbcFrame.SetTitle(title1) mbcFrame.Draw() canvas.cd(2) mbcFrame = mbc.frame() mbcFrame=mbc.frame(60) dflav.setLabel('dbarflav') ebeam_aset = ROOT.RooArgSet(ebeam, dflav) ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset, dataset) Cut = ROOT.RooFit.Cut("dflav==dflav::dbarflav") LineColor = ROOT.RooFit.LineColor(ROOT.kRed) LineWidth = ROOT.RooFit.LineWidth(1) #Slice = ROOT.RooFit.Slice(dflav, 'dbarflav') Slice = ROOT.RooFit.Slice(dflav) ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata) dataset.plotOn(mbcFrame, Cut) mbcFrame.getAttMarker().SetMarkerSize(0.6) mbcFrame.Draw() pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData) nfitParam = len(pars) - 2 chisq_ndof = mbcFrame.chiSquare(nfitParam) nbin = mbcFrame.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) mbcFrame.addObject(chisqbox) mbcFrame.SetTitle(title2) mbcFrame.Draw() canvas.cd(3) mbcFrame = mbc.frame() paramWin1 = pdf.paramOn(mbcFrame,dataset, "",2,"NELU",0.1,0.9,0.9) mbcFrame.GetXaxis().SetLabelSize(0) mbcFrame.GetXaxis().SetTickLength(0) mbcFrame.GetXaxis().SetLabelSize(0) mbcFrame.GetXaxis().SetTitle("") mbcFrame.GetXaxis().CenterTitle() mbcFrame.GetYaxis().SetLabelSize(0) mbcFrame.GetYaxis().SetTitleSize(0.03) mbcFrame.GetYaxis().SetTickLength(0) paramWin1.getAttText().SetTextSize(0.06) mbcFrame.Draw() mbcFrame.SetTitle("Fit Parameters") mbcFrame.Draw() canvas.Print(epsfile) tools.save_fit_result(pars, txtfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def draw_momenta_kkpi(figpath, datatype, mode, label, test): modekey = tools.get_modekey(mode) sname = attr.modes[modekey]['sname'].lower() figname = '%s_momenta' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') tab = DHadTable() tab.row_append(['Name', 'Data/MC']) # -------------------------------------------------- h_pkm = {}; h_pkp = {}; h_ppi = {} h_pkm_c = {}; h_pkp_c = {}; h_ppi_c = {} for datatype in datatype.split('/'): selfile = get_selfile(datatype, mode, label, test=test) selfile = selfile.replace('/trkmtm/', '/trkmtm2/') f = TFile(selfile) if datatype == 'signal' or datatype == 'generic': tp = 'mc' if datatype == 'data': tp = 'data' h_pkm[tp]= f.Get('h_pk'+tp) h_pkp[tp]= f.Get('h_ppi1'+tp) h_ppi[tp]= f.Get('h_ppiz'+tp) h_pkm_c[tp]= f.Get('h_pk_c'+tp) h_pkp_c[tp]= f.Get('h_ppi1_c'+tp) h_ppi_c[tp]= f.Get('h_ppiz_c'+tp) f.Clear() ratio = h_pkm['data'].Integral()/h_pkm['mc'].Integral() c1 = TCanvas('c1', 'canvas', 900, 900) c1.Divide(2,2) c1.cd(1) h_pkm['data'].Draw('PE') h_pkm['mc'].Scale(ratio) h_pkm['mc'].Draw('SAME') c1.cd(2) h_pkp['data'].Draw('PE') h_pkp['mc'].Scale(ratio) h_pkp['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppi['data'].Draw('PE') h_ppi['mc'].Scale(ratio) h_ppi['mc'].Draw('SAME') c1.Print(epsfile) tools.eps2pdf(epsfile) # -------------------------------------------------- c1.Clear() c1.Divide(2,2) c1.cd(1) h_pkm_c['data'].Draw('PE') lratio = h_pkm_c['data'].Integral()/h_pkm_c['mc'].Integral() #print 'km:', lratio/ratio tab.row_append(['Km', lratio/ratio]) h_pkm_c['mc'].Scale(lratio) h_pkm_c['mc'].Draw('SAME') c1.cd(2) h_pkp_c['data'].Draw('PE') lratio = h_pkp_c['data'].Integral()/h_pkp_c['mc'].Integral() #print 'kp:', lratio/ratio tab.row_append(['Kp', lratio/ratio]) h_pkp_c['mc'].Scale(lratio) h_pkp_c['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppi_c['data'].Draw('PE') lratio = h_ppi_c['data'].Integral()/h_ppi_c['mc'].Integral() #print 'pi:', lratio/ratio tab.row_append(['pi', lratio/ratio]) h_ppi_c['mc'].Scale(lratio) h_ppi_c['mc'].Draw('SAME') tab.column_trim('Data/MC', rnd='.0001') figname = '%s_momentacor' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') c1.Print(epsfile) tools.eps2pdf(epsfile) tabname = '%s_syst' % sname tab.output(tabname, label=label, export_html=False)
def draw_momenta_kpipi0(datatype, mode, label, test): modekey = tools.get_modekey(mode) sname = attr.modes[modekey]['sname'].lower() figname = '%s_momenta' % sname figpath = os.path.join(attr.figpath, label, 'trkmtm') epsfile = set_file(extbase=figpath, comname=figname, ext='eps') h_mbc = {}; kpi1 = {} ; pipih = {}; kpiz = {}; kpipih = {}; h_pk = {}; h_ppi1 = {}; h_ppiz = {} h_pk_c = {}; h_ppi1_c = {}; h_ppiz_c = {} h_pk_sb = {}; h_ppi1_sb = {}; h_ppiz_sb = {} h_pk_sb_c = {}; h_ppi1_sb_c = {}; h_ppiz_sb_c = {} h_angk = {}; h_angpi1 = {}; h_angpiz = {} for datatype in datatype.split('/'): selfile = get_selfile(datatype, mode, label, test=test) selfile = selfile.replace('/trkmtm/', '/trkmtm2/') f = TFile(selfile) if datatype == 'signal' or datatype == 'generic': tp = 'mc' if datatype == 'data': tp = 'data' h_mbc[tp]= f.Get('h_mbc_'+tp) kpi1[tp]= f.Get('kpi1_'+tp) pipih[tp]= f.Get('pipih_'+tp) kpiz[tp]= f.Get('kpiz_'+tp) kpipih[tp]= f.Get('kpipih_'+tp) h_pk[tp]= f.Get('h_pk_'+tp) h_ppi1[tp]= f.Get('h_ppi1_'+tp) h_ppiz[tp]= f.Get('h_ppiz_'+tp) h_pk_c[tp]= f.Get('h_pk_c_'+tp) h_ppi1_c[tp]= f.Get('h_ppi1_c_'+tp) h_ppiz_c[tp]= f.Get('h_ppiz_c_'+tp) h_pk_sb[tp]= f.Get('h_pk_sb_'+tp) h_ppi1_sb[tp]= f.Get('h_ppi1_sb_'+tp) h_ppiz_sb[tp]= f.Get('h_ppiz_sb_'+tp) h_pk_sb_c[tp]= f.Get('h_pk_sb_c_'+tp) h_ppi1_sb_c[tp]= f.Get('h_ppi1_sb_c_'+tp) h_ppiz_sb_c[tp]= f.Get('h_ppiz_sb_c_'+tp) h_angk[tp]= f.Get('h_angk_'+tp) h_angpi1[tp]= f.Get('h_angpi1_'+tp) h_angpiz[tp]= f.Get('h_angpiz_'+tp) f.Clear() ratio = h_pk['data'].Integral()/h_pk['mc'].Integral() c1 = TCanvas('c1', 'canvas', 900, 900) c1.Divide(2,2) c1.cd(1) h_pk['data'].Draw('PE') h_pk['mc'].Scale(ratio) h_pk['mc'].Draw('SAME') c1.cd(2) h_ppi1['data'].Draw('PE') h_ppi1['mc'].Scale(ratio) h_ppi1['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppiz['data'].Draw('PE') h_ppiz['mc'].Scale(ratio) h_ppiz['mc'].Draw('SAME') c1.Print(epsfile) tools.eps2pdf(epsfile) tab = DHadTable() tab.row_append(['Name', 'Data/MC']) c1.Clear() c1.Divide(2,2) c1.cd(1) h_pk_c['data'].Draw('PE') lratio = h_pk_c['data'].Integral()/h_pk_c['mc'].Integral() #print 'k:', lratio/ratio tab.row_append(['K', lratio/ratio]) h_pk_c['mc'].Scale(lratio) h_pk_c['mc'].Draw('SAME') c1.cd(2) h_ppi1_c['data'].Draw('PE') lratio = h_ppi1_c['data'].Integral()/h_ppi1_c['mc'].Integral() #print 'pi1:', lratio/ratio tab.row_append(['pi1', lratio/ratio]) h_ppi1_c['mc'].Scale(lratio) h_ppi1_c['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppiz_c['data'].Draw('PE') lratio = h_ppiz_c['data'].Integral()/h_ppiz_c['mc'].Integral() #print 'piz:', lratio/ratio tab.row_append(['piz', lratio/ratio]) h_ppiz_c['mc'].Scale(lratio) h_ppiz_c['mc'].Draw('SAME') tab.column_trim('Data/MC', rnd='.0001') figname = '%s_momentacor' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') c1.Print(epsfile) tools.eps2pdf(epsfile) tabname = '%s_syst' % sname tab.output(tabname, label=label, export_html=False)
def draw_momenta_kkpi(figpath, datatype, mode, label, test): modekey = tools.get_modekey(mode) sname = attr.modes[modekey]['sname'].lower() figname = '%s_momenta' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') #tab = DHadTable() #tab.row_append(['Name', 'Data/MC']) # -------------------------------------------------- h_pkm = {} h_pkp = {} h_ppi = {} h_pkm_c = {} h_pkp_c = {} h_ppi_c = {} for datatype in [datatype]: selfile = get_selfile(datatype, mode, label, test=test) selfile = selfile.replace('/trkmtm/', '/trkmtm2/') f = TFile(selfile) if datatype == 'signal': # or datatype == 'generic': tp = 'mc' #if datatype == 'data': # tp = 'data' h_pkm[tp] = f.Get('h_pk' + tp) h_pkp[tp] = f.Get('h_ppi1' + tp) h_ppi[tp] = f.Get('h_ppiz' + tp) h_pkm_c[tp] = f.Get('h_pk_c' + tp) h_pkp_c[tp] = f.Get('h_ppi1_c' + tp) h_ppi_c[tp] = f.Get('h_ppiz_c' + tp) f.Clear() #ratio = h_pkm['data'].Integral()/h_pkm['mc'].Integral() c1 = TCanvas('c1', 'canvas', 900, 900) c1.Divide(2, 2) c1.cd(1) h_pkm['mc'].Draw() #h_pkm['data'].Draw('PE') #h_pkm['mc'].Scale(ratio) #h_pkm['mc'].Draw('SAME') c1.cd(2) h_pkp['mc'].Draw() #h_pkp['data'].Draw('PE') #h_pkp['mc'].Scale(ratio) #h_pkp['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppi['mc'].Draw() #h_ppi['data'].Draw('PE') #h_ppi['mc'].Scale(ratio) #h_ppi['mc'].Draw('SAME') c1.Print(epsfile) tools.eps2pdf(epsfile)
def fit_sidebands_single_mode(datatype, mode, label, test): load_roofit_lib(datatype, label) dt_type = datatype.replace('/', '_') modekey = tools.get_modekey(mode) comname = '%s_%s' % (dt_type, mode) input_label = label sdbpath = os.path.join(attr.evtpath, input_label) sdbfile = set_file(extbase=sdbpath, comname=comname, ext='evt') has_charge_conjugate = False if '__' in mode: has_charge_conjugate = True if not os.access(sdbfile, os.F_OK): if has_charge_conjugate: sdbfile = set_file(extbase=sdbpath, dt_type=dt_type, tag='s', mode=modekey, comname=comname, ext='evt', forceCombine=1) else: raise ValueError(sdbfile) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=comname, ext='eps') txtpath = os.path.join(attr.fitpath, label) txtfile = set_file(extbase=txtpath, comname=comname, ext='txt') if test: epsfile = epsfile + '.test' txtfile = txtfile + '.test' ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV') dflav = ROOT.RooCategory('dflav', 'D0 flavor') dflav.defineType('dflav', 1) dflav.defineType('dbarflav', -1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) dataset = ROOT.RooDataSet.read(sdbfile, dataset_args) arg_cutoff = ebeam arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) arg_power = ROOT.RooRealVar('arg_power', 'Argus power', 0.5, 0.1, 1.5) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') pars = [arg_slope, arg_power, bkg, sigma, yld] mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope, arg_power) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) # e Save = ROOT.RooFit.Save(ROOT.kTRUE) # r Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) # no h Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) # no q if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if has_charge_conjugate: yld_bar = ROOT.RooRealVar('yield_bar', 'Dbar yield', 100, 0, 200000) bkg_bar = ROOT.RooRealVar('bkg_bar', 'Background Bar', 100, 0, 1000000) pars.extend([yld_bar, bkg_bar]) mbc_d0bar = ROOT.RooRealVar('mbc_d0bar', 'D0Bar Mbc', 1.8647, 'GeV') mbc_dm = ROOT.RooRealVar('mbc_dm', 'D- Mbc', 1.8694, 'GeV') gauss_d0bar = ROOT.RooGaussian('gauss_d0bar', 'D0bar gaussian', mbc, mbc_d0bar, sigma) gauss_dm = ROOT.RooGaussian('gauss_dm', 'D- gaussian', mbc, mbc_dm, sigma) sumpdf_d0bar = ROOT.RooAddPdf('sumpdf_d0bar', 'D0bar sum pdf', ROOT.RooArgList(gauss_d0bar, argus), ROOT.RooArgList(yld_bar, bkg_bar)) sumpdf_dm = ROOT.RooAddPdf('sumpdf_dm', 'Dm sum pdf', ROOT.RooArgList(gauss_dm, argus), ROOT.RooArgList(yld_bar, bkg_bar)) pdf = ROOT.RooSimultaneous('totalPdf', 'totalPdf', dflav) if 'D0' in mode: pdf.addPdf(sumpdf_d0, 'dflav') pdf.addPdf(sumpdf_d0bar, 'dbarflav') else: pdf.addPdf(sumpdf_dp, 'dflav') pdf.addPdf(sumpdf_dm, 'dbarflav') if 'nogaus' in label: yld.setVal(1) yld.setConstant(ROOT.kTRUE) pars.remove(yld) if 'floatsigma' not in label: datatype = 'data' tag = 'single' if '818ipb' in label: prefix = 'dir_818ipbv12' frame_max = 1500 #bkg_generic_ddbar_818_max[mode] else: raise NameError(label) tabfile = set_file('txt', datatype, modekey, tag, prefix=prefix, extbase=attr.fitpath) sys.stdout.write('Using width from %s \n' % tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) pars.remove(sigma) #res = pdf.fitTo(dataset, Extended, Save, Verbose) res = pdf.fitTo(dataset, 'emr') #Migrad only, no MINOS res.Print('v') if not has_charge_conjugate: canvas = ROOT.TCanvas('canvas', 'canvas1', 600, 600) canvas.SetFixedAspectRatio(0) xframe = mbc.frame() xframe.SetMaximum(frame_max) xframe.SetMarkerSize(0.3) dataset.plotOn(xframe) pdf.plotOn(xframe) nfitParam = len(pars) chisq_ndof = xframe.chiSquare(nfitParam) nbin = xframe.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) xframe.addObject(chisqbox) pdf.paramOn(xframe, dataset) xframe.SetTitle('Sidebands of %s' % mode) xframe.GetYaxis().SetTitleSize(0.03) xframe.GetYaxis().SetLabelSize(0.03) xframe.GetYaxis().SetTitleOffset(1.8) xframe.GetXaxis().SetTitleSize(0.03) xframe.GetXaxis().SetLabelSize(0.03) xframe.GetXaxis().SetTitleOffset(1.2) xframe.Draw() else: canvas = ROOT.TCanvas('canvas', 'mbc', 1200, 400) canvas.Divide(3, 1) title1 = attr.modes[modekey]['uname'] title2 = attr.modes[modekey]['unamebar'] canvas_1 = canvas.GetListOfPrimitives().FindObject('canvas_1') canvas_2 = canvas.GetListOfPrimitives().FindObject('canvas_2') canvas_1.SetLogy() canvas_2.SetLogy() ebeam.setBins(900) canvas.cd(1) mbcFrame = mbc.frame() mbcFrame = mbc.frame(60) dflav.setLabel('dflav') ebeam_aset = ROOT.RooArgSet(ebeam, dflav) ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset, dataset) Cut = ROOT.RooFit.Cut("dflav==dflav::dflav") LineColor = ROOT.RooFit.LineColor(ROOT.kRed) LineWidth = ROOT.RooFit.LineWidth(1) #Slice = ROOT.RooFit.Slice(dflav, 'dflav') Slice = ROOT.RooFit.Slice(dflav) ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata) dataset.plotOn(mbcFrame, Cut) mbcFrame.getAttMarker().SetMarkerSize(0.6) mbcFrame.Draw() pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData) nfitParam = len(pars) - 2 chisq_ndof = mbcFrame.chiSquare(nfitParam) nbin = mbcFrame.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) mbcFrame.addObject(chisqbox) mbcFrame.SetTitle(title1) mbcFrame.Draw() canvas.cd(2) mbcFrame = mbc.frame() mbcFrame = mbc.frame(60) dflav.setLabel('dbarflav') ebeam_aset = ROOT.RooArgSet(ebeam, dflav) ebeamdata = ROOT.RooDataHist("ebeamdata", "ebeamdata", ebeam_aset, dataset) Cut = ROOT.RooFit.Cut("dflav==dflav::dbarflav") LineColor = ROOT.RooFit.LineColor(ROOT.kRed) LineWidth = ROOT.RooFit.LineWidth(1) #Slice = ROOT.RooFit.Slice(dflav, 'dbarflav') Slice = ROOT.RooFit.Slice(dflav) ProjWData = ROOT.RooFit.ProjWData(ebeam_aset, ebeamdata) dataset.plotOn(mbcFrame, Cut) mbcFrame.getAttMarker().SetMarkerSize(0.6) mbcFrame.Draw() pdf.plotOn(mbcFrame, LineColor, LineWidth, Slice, ProjWData) nfitParam = len(pars) - 2 chisq_ndof = mbcFrame.chiSquare(nfitParam) nbin = mbcFrame.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.55, 0.2, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.2f/%d = %.2f' % (chisq, ndof, chisq_ndof)) mbcFrame.addObject(chisqbox) mbcFrame.SetTitle(title2) mbcFrame.Draw() canvas.cd(3) mbcFrame = mbc.frame() paramWin1 = pdf.paramOn(mbcFrame, dataset, "", 2, "NELU", 0.1, 0.9, 0.9) mbcFrame.GetXaxis().SetLabelSize(0) mbcFrame.GetXaxis().SetTickLength(0) mbcFrame.GetXaxis().SetLabelSize(0) mbcFrame.GetXaxis().SetTitle("") mbcFrame.GetXaxis().CenterTitle() mbcFrame.GetYaxis().SetLabelSize(0) mbcFrame.GetYaxis().SetTitleSize(0.03) mbcFrame.GetYaxis().SetTickLength(0) paramWin1.getAttText().SetTextSize(0.06) mbcFrame.Draw() mbcFrame.SetTitle("Fit Parameters") mbcFrame.Draw() canvas.Print(epsfile) tools.save_fit_result(pars, txtfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def fit_backgrounds_single_mode(datatype, mode, label, test): comname = '%s_%s' %(datatype.replace('/', '_'), mode) input_label = label if 'nogaus' in label: input_label = label.split('/')[0] bkgpath = os.path.join(attr.bkgpath(), input_label) bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt') if not os.access(bkgfile, os.F_OK): input_prefix = 'dir_%s' % input_label bkgfile = set_file(extbase=attr.bkgpath(), dt_type=datatype.replace('/', '_'), tag='s', mode=mode, prefix=input_prefix, comname=comname, ext='evt', forceCombine=1) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=comname, ext='eps') txtpath = os.path.join(attr.fitpath(), label) txtfile = set_file(extbase=txtpath, comname=comname, ext='txt') if test: epsfile = epsfile + '.test' txtfile = txtfile + '.test' ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam','Ebeam',1.8815,1.892,'GeV') dflav = ROOT.RooCategory('dflav','D0 flavor') dflav.defineType('dflav',1) dflav.defineType('dbarflav',-1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) dataset = ROOT.RooDataSet.read(bkgfile, dataset_args) arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV') arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') pars = [arg_cutoff, arg_slope, bkg, sigma, yld] mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) Save = ROOT.RooFit.Save(ROOT.kTRUE) Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if 'nogaus' in label: yld.setVal(1) yld.setConstant(ROOT.kTRUE) pars.remove(yld) if 'floatsigma' not in label: datatype = 'data' tag = 'single' if '281ipb' in label: prefix = 'dir_281ipbv7' frame_max = bkg_generic_ddbar_281_max[mode] elif '537ipb' in label: prefix = 'dir_537ipbv7' frame_max = bkg_generic_ddbar_537_max[mode] elif '818ipb' in label: prefix = 'dir_818ipbv7' frame_max = bkg_generic_ddbar_818_max[mode] if 'noxfeed' in label: frame_max = bkg_generic_ddbar_818_max_noxfeed[mode] else: raise NameError(label) tabfile = set_file('txt', datatype, mode, tag, prefix=prefix, extbase=attr.fitpath()) sys.stdout.write('Using width from %s \n' %tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) pars.remove(sigma) res = pdf.fitTo(dataset, Extended, Save, Verbose) res.Print('v') c1 = ROOT.TCanvas('c1', 'canvas1', 600, 600) c1.SetFixedAspectRatio(0) xframe = mbc.frame() xframe.SetMaximum(frame_max) xframe.SetMarkerSize(0.3) dataset.plotOn(xframe) pdf.plotOn(xframe) nfitParam = len(pars) chisq_ndof = xframe.chiSquare(nfitParam) nbin = xframe.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.3f/%d = %.3f' % (chisq, ndof, chisq_ndof)) xframe.addObject(chisqbox) pdf.paramOn(xframe, dataset) xframe.SetTitle('Generic faking %s' % mode) xframe.Draw() c1.Print(epsfile) tools.save_fit_result(pars, txtfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def create_fig_nondiag_mode(dt_type, stage, label, x, y): prefix = 'dir_' + label if x[1] == 1: uname = modes[x[0]]['uname'] fname = modes[x[0]]['fname'] title1 = modes[x[0]]['orgname'] else: uname = modes[x[0]]['unamebar'] fname = modes[x[0]]['fnamebar'] title1 = modes[x[0]]['orgnamebar'] if y[1] == 1: unameb = modes[y[0]]['uname'] fnameb = modes[y[0]]['fname'] title2 = modes[y[0]]['orgname'] else: unameb = modes[y[0]]['unamebar'] fnameb = modes[y[0]]['fnamebar'] title2 = modes[y[0]]['orgnamebar'] title = '%s fakes %s' % (title1, title2) comname = '%s_Single_%s_fakes_Single_%s' % (dt_type, fname, fnameb) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=comname + '.eps') pdffile = epsfile.replace('.eps', '.pdf') figlabel = label.split('/')[0] relpath = label.replace(figlabel, '') pdflink = '.%s/%s.pdf' % (relpath, comname) pnglink = '.%s/%s.png' % (relpath, comname) if not os.access(pdffile, os.F_OK): if not os.access(epsfile, os.F_OK): sys.stdout.write('epsfile is not ready for %s, %s \n' % (x, y)) else: sys.stdout.write('Converting %s ...' % epsfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile) sys.stdout.write(' OK.\n') figlink = '[[%s][%s]]' % (pdflink, pnglink) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=comname + '.txt') xstr = pair_to_str(x) ystr = pair_to_str(y) logname = 'stage_%s_%s_%s.txt' % (stage, xstr, ystr) logfile = tools.set_file(extbase=attr.logpath, prefix=prefix, comname=logname) if not os.access(epsfile, os.F_OK): sys.stdout.write('Please check log: %s\n' % logfile) loglink = '' if os.access(logfile, os.F_OK): loglink = '[[../../log/%s/%s][log]]' % (label, logname) tablink = '' if os.access(txtfile, os.F_OK): orgtabfile = txtfile.replace('.txt', '.org') tab = DHadTable(txtfile) tab.output_org(orgtabfile) abspath = os.path.join(attr.base) #, attr.analysis) orgtabfile = orgtabfile.replace(abspath, '../..') tablink = '#+INCLUDE: "%s"\n' % orgtabfile msg = '\n* %s \n %s \n\n%s\n %s\n' % (title, figlink, tablink, loglink) return msg
def double_tag_mode(dt_type, mode, label, interact=False, test=False): mode = get_modekey(mode) tag = 'double' prefix = 'dir_' + label evtprefix = get_evtprefix(dt_type, label) mode1 = mode[0] mode2 = mode[1] title1 = attr.modes[mode1]['uname'] title2 = attr.modes[mode2]['unamebar'] code1 = attr.interfacecodes[mode1] code2 = attr.interfacecodes[mode2] forceCombine = None # Different from single tag case Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma1, F1a, F1b, S1a, S1b = get_resolution_paras(mode1, label) Sigma2, F2a, F2b, S2a, S2b = get_resolution_paras(mode2, label) opt, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat = get_double_paras(label) epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) if not os.access(evtfile, os.F_OK): if '818ipb' in evtprefix: evtfile_281ipb = evtfile.replace('818ipb', '281ipb') evtfile_537ipb = evtfile.replace('818ipb', '537ipb') combine_files(evtfile_281ipb, evtfile_537ipb, evtfile) else: raise ValueError(evtfile) tools.print_sep() par_str = '("%s", %f, %f, %f, %f, %f, "%s", %f, %f, %f, \ %f, %f, "%s", "%s", "%s", %d, "%s", "%s", "%s", %f,\ %f, %f, %f, %f, %f, %f, %f)' par_tuple = (code1, Sigma1, F1a, F1b, S1a, S1b, code2, Sigma2, F2a, F2b, S2a, S2b, evtfile, epsfile, outfile, mc, opt, title1, title2, Gamma, Mres, R, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat) par = par_str % par_tuple print_paras_double(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'lineshapefit2d.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro(source + par) sys.stdout.write('Save output in %s\n' % outfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def create_fig_diag_mode(dt_type, stage, label, mode, sign): prefix = 'dir_' + label if sign == 1: uname = modes[mode]['uname'] fname = modes[mode]['fname'] title = modes[mode]['orgname'] else: uname = modes[mode]['unamebar'] fname = modes[mode]['fnamebar'] title = modes[mode]['orgnamebar'] comname = '%s_Single_%s_fakes_Single_%s' % (dt_type, fname, fname) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=comname + '.eps') pdffile = epsfile.replace('.eps', '.pdf') figlabel = label.split('/')[0] relpath = label.replace(figlabel, '') pdflink = '.%s/%s.pdf' % (relpath, comname) pnglink = '.%s/%s.png' % (relpath, comname) if not os.access(pdffile, os.F_OK): if not os.access(epsfile, os.F_OK): sys.stdout.write('epsfile is not ready for (%s %s) \n' % (mode, sign)) else: tools.eps2png(epsfile) tools.eps2pdf(epsfile) figlink = '[[%s][%s]]' % (pdflink, pnglink) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=comname + '.txt') logname = 'stage_%s_%s_%s.txt' % (stage, mode, sign) logfile = tools.set_file(extbase=attr.logpath, prefix=prefix, comname=logname) loglink = '' if os.access(logfile, os.F_OK): loglink = '[[../../log/%s/%s][log]]' % (label, logname) tablink = '' if os.access(txtfile, os.F_OK): orgtabfile = txtfile.replace('.txt', '.org') tab = DHadTable(txtfile) tab.output_org(orgtabfile) abspath = os.path.join(attr.base) #, attr.analysis) orgtabfile = orgtabfile.replace(abspath, '../..') tablink = '#+INCLUDE: "%s"\n' % orgtabfile msg = '\n* %s \n %s \n\n%s\n %s\n' % (title, figlink, tablink, loglink) return msg
def double_all_dps(dt_type, mode, label, test=False): tag = 'double' prefix = 'dir_' + label evtprefix = get_evtprefix(dt_type, label) if label == '818ipbv12.1': label = '818ipbv12' mode1 = 200 mode2 = 200 title1 = attr.modes[mode1]['uname'] title2 = attr.modes[mode2]['unamebar'] code1 = attr.interfacecodes[mode1] code2 = attr.interfacecodes[mode2] Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma1, F1a, F1b, S1a, S1b = get_resolution_paras(mode1, label) Sigma2, F2a, F2b, S2a, S2b = get_resolution_paras(mode2, label) opt, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat = get_double_paras(label) epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=0, extbase=evtpath) if not os.access(evtfile, os.F_OK): forceCombine = 'all_dps' evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) tools.print_sep() par_str = '("%s", %f, %f, %f, %f, %f, "%s", %f, %f, %f, \ %f, %f, "%s", "%s", "%s", %d, "%s", "%s", "%s", %f,\ %f, %f, %f, %f, %f, %f, %f)' par_tuple = (code1, Sigma1, F1a, F1b, S1a, S1b, code2, Sigma2, F2a, F2b, S2a, S2b, evtfile, epsfile, outfile, mc, opt, title1, title2, Gamma, Mres, R, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat) par = par_str % par_tuple print_paras_double(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'lineshapefit2d.C' if prefix == 'dir_818ipbv12.1': sourcename = 'lineshapefit2d_1.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro(source + par) sys.stdout.write('Save output in %s\n' % outfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def single_tag_mode(dt_type, mode, label, interact=False, test=False): mode = get_modekey(mode) tag = 'single' prefix = 'dir_' + label evtprefix = get_evtprefix(dt_type, label) Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma, Fa, Fb, Sa, Sb = get_resolution_paras(mode, label) N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi = init_paras_single( label, dt_type, tag, mode) # ------------------- Parameters for the fit ---------- title1 = attr.modes[mode]['uname'] title2 = attr.modes[mode]['unamebar'] num_fcn = 3 # : 0 for only background xi_side = 0.0 p_side = 0.0 int_d = 1 optstr = 'p' # To plot, f : fast, w: fixwidth floatwidth = 0 Min = 0.5 options = "" MINUIT = "ermh4" # ------------------------------------------------- if '/p/0.5' in label: p_side = 0.5 if '/argus' in label: options = 'fix_xi,fix_p' xi, p = get_argus_paras_single(label, dt_type, tag, mode) if '/fix_sigmap1' in label: options = 'fix_sigmap1' if '/kssideband' in label: sys.stdout.write('Fixing the sigmap1 as %s ...\n' % Sigma) sigmap1 = Sigma if '/fix_n1n2' in label and '/desideband' in label: options = 'fix_n1n2' N1 = 1 N2 = 1 if dt_type == 'signal' and mode in [0, 200, 202]: p_side = 0.5 tools.print_sep() forceCombine = 1 epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) tools.print_sep() par_str = '( "%s", "%s", "%s", "%s", "%s", %d, %d, %f, %f, %f, %f, \ %f, %f, %f, %d, "%s", %f, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, \ %f, "%s", "%s" )' par_tuple = (title1, title2, evtfile, epsfile, outfile, mc, num_fcn, xi_side, p_side, Sigma, Sa, Sb, Fa, Fb, int_d, optstr, Gamma, floatwidth, R, Mres, N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi, Min, options, MINUIT) par = par_str % par_tuple print_paras(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'mbc_singletag_3s.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro(source + par) if test: evtfile = evtfile + '.test' epsfile = epsfile + '.test' outfile = outfile + '.test' # fit_mbc_single(title1, title2, evtfile, epsfile, outfile, mc, num_fcn, # xi_side, p_side, Sigma, Sa, Sb, Fa, Fb, int_d, optstr, # Gamma, floatwidth, R, Mres, N1, N2, Nbkgd1, Nbkgd2, md, # p, sigmap1, xi, Min, options, MINUIT) sys.stdout.write('Save output in %s\n' % outfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def fit_backgrounds_single(datatype, modes, label, test): epsname = '%s_background' % (datatype.replace('/', '_')) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=epsname, ext='eps') if test: epsfile = epsfile + '.test' input_label = label ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV') dflav = ROOT.RooCategory('dflav', 'D0 flavor') dflav.defineType('dflav', 1) dflav.defineType('dbarflav', -1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV') arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) Save = ROOT.RooFit.Save(ROOT.kTRUE) Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) if '281ipb' in label: prefix = 'dir_281ipbv7' elif '537ipb' in label: prefix = 'dir_537ipbv7' elif '818ipb' in label: prefix = 'dir_818ipbv7' else: raise NameError(label) c1 = ROOT.TCanvas('c1', 'canvas1', 800, 1000) #c1.SetFixedAspectRatio(0) c1.Divide(3, 3) pad = 1 for mode in modes: mode_root_name = get_mode_root_name(mode) if datatype == 'generic/ddbar': frametitle = 'Generic faking %s' % mode_root_name elif datatype == 'generic/cont': frametitle = 'Continuum production faking %s' % mode_root_name elif datatype == 'generic/tau': frametitle = '#tau #tau production faking %s' % mode_root_name elif datatype == 'generic/radret': frametitle = 'Radiative return faking %s' % mode_root_name else: raise NameError(datatype) c1.cd(pad) pad += 1 comname = '%s_%s' % (datatype.replace('/', '_'), mode) bkgpath = os.path.join(attr.bkgpath(), input_label) bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt') if not os.access(bkgfile, os.F_OK): input_prefix = 'dir_%s' % input_label bkgfile = set_file(extbase=attr.bkgpath(), dt_type=datatype.replace('/', '_'), tag='s', mode=mode, prefix=input_prefix, comname=comname, ext='evt', forceCombine=1) dataset = ROOT.RooDataSet.read(bkgfile, dataset_args) if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if 'floatsigma' not in label: tab_datatype = 'data' tag = 'single' tabfile = set_file('txt', tab_datatype, mode, tag, prefix=prefix, extbase=attr.fitpath()) sys.stdout.write('Using width from %s \n' % tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) res = pdf.fitTo(dataset, Extended, Save, Verbose) res.Print('v') xframe = mbc.frame() xframe.SetMarkerSize(0.3) if '818ipb' in label and 'noxfeed' in label: frame_max = bkg_generic_ddbar_818_max_noxfeed[mode] xframe.SetMaximum(frame_max) dataset.plotOn(xframe) pdf.plotOn(xframe) pdf.paramOn(xframe, dataset) xframe.SetTitle(frametitle) xframe.Draw() c1.Print(epsfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def fit_single_mode(datatype, mode, label, lowmass, highmass, test): evtpath = os.path.join(attr.datpath, 'sel', label, 'kpimass') modekey = tools.get_modekey(mode) tag = 'single' evtfile = tools.set_file('evt', datatype, modekey, tag, prefix='', forceCombine=1, extbase=evtpath) load_roofit_lib(datatype, label) cuts = '%f<kpimass && kpimass<%f' % (lowmass, highmass) err_type = 'ASYM' setGamma, setMres, setR, mc = get_common_parameters(datatype, label) Sigma, Fa, Fb, Sa, Sb = get_resolution_paras(modekey, label) N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi = init_paras_single( label, datatype, 's', modekey) title1 = '%s : %s < Kpi mass < %s ' % (attr.modes[modekey]['uname'], lowmass, highmass) title2 = '%s : %s < Kpi mass < %s ' % (attr.modes[modekey]['unamebar'], lowmass, highmass) prefix = 'dir_%s/kpimass/%s_%s' % (label, lowmass, highmass) epsfile = tools.set_file('eps', datatype, modekey, tag, prefix=prefix, extbase=attr.figpath) txtfile = tools.set_file('txt', datatype, modekey, tag, prefix=prefix, extbase=attr.fitpath) mbc_single_3s(evtfile, mc, setMres, setGamma, setR, sigmap1, Sa, Sb, Fa, Fb, md, p, xi, N1, N2, Nbkgd1, Nbkgd2, title1, title2, epsfile, txtfile, cuts=cuts, err_type=err_type, test=test) #mbc_gau_che(evtfile, mc, setMres, setGamma, setR, sigmap1, Sa, Sb, Fa, # Fb, md, p, xi, N1, N2, Nbkgd1, Nbkgd2, title1, title2, # epsfile, txtfile, cuts=cuts, err_type=err_type, test=test) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def double_all_dps(dt_type, mode, label, test=False): tag = 'double' prefix = 'dir_'+label evtprefix = get_evtprefix(dt_type, label) if label == '818ipbv12.1': label = '818ipbv12' mode1 = 200 mode2 = 200 title1 = attr.modes[mode1]['uname'] title2 = attr.modes[mode2]['unamebar'] code1 = attr.interfacecodes[mode1] code2 = attr.interfacecodes[mode2] Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma1, F1a, F1b, S1a, S1b = get_resolution_paras(mode1, label) Sigma2, F2a, F2b, S2a, S2b = get_resolution_paras(mode2, label) opt, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat = get_double_paras(label) epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=0, extbase=evtpath) if not os.access(evtfile, os.F_OK): forceCombine = 'all_dps' evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) tools.print_sep() par_str = '("%s", %f, %f, %f, %f, %f, "%s", %f, %f, %f, \ %f, %f, "%s", "%s", "%s", %d, "%s", "%s", "%s", %f,\ %f, %f, %f, %f, %f, %f, %f)' par_tuple = (code1, Sigma1, F1a, F1b, S1a, S1b, code2, Sigma2, F2a, F2b, S2a, S2b, evtfile, epsfile, outfile, mc, opt, title1, title2, Gamma, Mres, R, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat) par = par_str % par_tuple print_paras_double(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'lineshapefit2d.C' if prefix == 'dir_818ipbv12.1': sourcename = 'lineshapefit2d_1.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro( source + par) sys.stdout.write('Save output in %s\n' % outfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def draw_momenta_ks3pi(datatype, mode, label, test): modekey = tools.get_modekey(mode) sname = attr.modes[modekey]['sname'].lower() figname = '%s_momenta' % sname figpath = os.path.join(attr.figpath, label, 'trkmtm') epsfile = set_file(extbase=figpath, comname=figname, ext='eps') tab = DHadTable() tab.row_append(['Name', 'Data/MC']) # -------------------------------------------------- h_pks = {}; h_ppi1 = {}; h_ppi2 = {}; h_ppim = {} h_pks_c = {}; h_ppi1_c = {}; h_ppi2_c = {}; h_ppim_c = {} for datatype in datatype.split('/'): selfile = get_selfile(datatype, mode, label, test=test) selfile = selfile.replace('/trkmtm/', '/trkmtm2/') f = TFile(selfile) if datatype == 'signal' or datatype == 'generic': tp = 'mc' if datatype == 'data': tp = 'data' h_pks[tp]= f.Get('h_pks'+tp) h_ppi1[tp]= f.Get('h_ppi1'+tp) h_ppi2[tp]= f.Get('h_ppi2'+tp) h_ppim[tp]= f.Get('h_ppim'+tp) h_pks_c[tp]= f.Get('h_pk_c'+tp) h_ppi1_c[tp]= f.Get('h_ppi1_c'+tp) h_ppi2_c[tp]= f.Get('h_ppi2_c'+tp) h_ppim_c[tp]= f.Get('h_ppim_c'+tp) f.Clear() ratio = h_pks['data'].Integral()/h_pks['mc'].Integral() c1 = TCanvas('c1', 'canvas', 900, 900) c1.Divide(2,2) c1.cd(1) h_pks['data'].Draw('PE') h_pks['mc'].Scale(ratio) h_pks['mc'].Draw('SAME') c1.cd(2) h_ppi1['data'].Draw('PE') h_ppi1['mc'].Scale(ratio) h_ppi1['mc'].Draw('SAME') c1.cd(3) h_ppi2['data'].Draw('PE') h_ppi2['mc'].Scale(ratio) h_ppi2['mc'].Draw('SAME') c1.cd(4) h_ppim['data'].Draw('PE') h_ppim['mc'].Scale(ratio) h_ppim['mc'].Draw('SAME') c1.Print(epsfile) tools.eps2pdf(epsfile) # -------------------------------------------------- c1.Clear() c1.Divide(2,2) c1.cd(1) h_pks_c['data'].Draw('PE') lratio = h_pks_c['data'].Integral()/h_pks_c['mc'].Integral() #print 'k:', lratio/ratio tab.row_append(['K', lratio/ratio]) h_pks_c['mc'].Scale(lratio) h_pks_c['mc'].Draw('SAME,HIST') c1.cd(2) h_ppi1_c['data'].Draw('PE') lratio = h_ppi1_c['data'].Integral()/h_ppi1_c['mc'].Integral() #print 'pi1:', lratio/ratio tab.row_append(['pi1', lratio/ratio]) h_ppi1_c['mc'].Scale(lratio) h_ppi1_c['mc'].Draw('SAME,HIST') c1.cd(3) h_ppi2_c['data'].Draw('PE') lratio = h_ppi2_c['data'].Integral()/h_ppi2_c['mc'].Integral() #print 'pi2:', lratio/ratio tab.row_append(['pi2', lratio/ratio]) h_ppi2_c['mc'].Scale(lratio) h_ppi2_c['mc'].Draw('SAME,HIST') c1.cd(4) h_ppim_c['data'].Draw('PE') lratio = h_ppim_c['data'].Integral()/h_ppim_c['mc'].Integral() #print 'pim:', lratio/ratio tab.row_append(['pim', lratio/ratio]) h_ppim_c['mc'].Scale(lratio) h_ppim_c['mc'].Draw('SAME,HIST') tab.column_trim('Data/MC', rnd='.0001') figname = '%s_momentacor' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') c1.Print(epsfile) tools.eps2pdf(epsfile) tabname = '%s_syst' % sname tab.output(tabname, label=label, export_html=False)
def draw_effmomenta_kkpi(figpath, effs, sname, h_pkp, h_pkm, h_ppi): figname = '%s_effmomenta_plain' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') ratio = 1 c1 = TCanvas('c1', 'canvas', 900, 850) c1.Divide(2,2) c1.cd(1) h_pkm['mctruth'].Draw('PE') h_pkm['mc'].Scale(ratio) h_pkm['mc'].Draw('SAME') c1.cd(2) h_pkp['mctruth'].Draw('PE') h_pkp['mc'].Scale(ratio) h_pkp['mc'].Draw('SAME') c1.cd(3) c1.cd(4) h_ppi['mctruth'].Draw('PE') h_ppi['mc'].Scale(ratio) h_ppi['mc'].Draw('SAME') c1.Print(epsfile) c1.Clear() tools.eps2pdf(epsfile) # ------------------------------------- figname = '%s_effmomenta' % sname epsfile = set_file(extbase=figpath, comname=figname, ext='eps') for type in ('mc', 'mctruth'): h_pkm[type].Sumw2() h_pkp[type].Sumw2() h_ppi[type].Sumw2() loceffs = {} c1.Clear() c1.Divide(2,2) c1.cd(1) clone = h_pkm['mctruth'].Clone() clone.Divide(h_pkm['mc'], h_pkm['mctruth'], 1, 1, 'B') clone.SetTitle('Efficiency as a function of K^{-} momentum') clone.Draw('PE') #clone.Print('all') for i in range(1, 1+clone.GetNbinsX()): loceffs[clone.GetBinCenter(i)] = clone.GetBinContent(i) effs['km']=loceffs c1.cd(2) clone = h_pkp['mctruth'].Clone() clone.Divide(h_pkp['mc'], h_pkp['mctruth'], 1, 1, 'B') clone.SetTitle('Efficiency as a function of K^{+} momentum') clone.Draw('PE') loceffs.clear() for i in range(1, 1+clone.GetNbinsX()): loceffs[clone.GetBinCenter(i)] = clone.GetBinContent(i) effs['kp']=loceffs c1.cd(3) c1.cd(4) clone = h_ppi['mctruth'].Clone() clone.Divide(h_ppi['mc'], h_ppi['mctruth'], 1, 1, 'B') clone.SetTitle('Efficiency as a function of #pi^{+} momentum') clone.Draw('PE') loceffs.clear() for i in range(1, 1+clone.GetNbinsX()): loceffs[clone.GetBinCenter(i)] = clone.GetBinContent(i) effs['pi']=loceffs boxes_num = effs['boxes_num'] boxes_denom = effs['boxes_denom'] effs['total'] = boxes_num/boxes_denom effs.close() c1.Print(epsfile) c1.Clear() tools.eps2pdf(epsfile)
def fit_backgrounds_single(datatype, modes, label, test): epsname = '%s_background' %(datatype.replace('/', '_')) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=epsname, ext='eps') if test: epsfile = epsfile + '.test' input_label = label ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam','Ebeam',1.8815,1.892,'GeV') dflav = ROOT.RooCategory('dflav','D0 flavor') dflav.defineType('dflav',1) dflav.defineType('dbarflav',-1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV') arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) Save = ROOT.RooFit.Save(ROOT.kTRUE) Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) if '281ipb' in label: prefix = 'dir_281ipbv7' elif '537ipb' in label: prefix = 'dir_537ipbv7' elif '818ipb' in label: prefix = 'dir_818ipbv7' else: raise NameError(label) c1 = ROOT.TCanvas('c1', 'canvas1', 800, 1000) #c1.SetFixedAspectRatio(0) c1.Divide(3,3) pad = 1 for mode in modes: mode_root_name = get_mode_root_name(mode) if datatype == 'generic/ddbar': frametitle = 'Generic faking %s' % mode_root_name elif datatype == 'generic/cont': frametitle = 'Continuum production faking %s' % mode_root_name elif datatype == 'generic/tau': frametitle = '#tau #tau production faking %s' % mode_root_name elif datatype == 'generic/radret': frametitle = 'Radiative return faking %s' % mode_root_name else: raise NameError(datatype) c1.cd(pad) pad += 1 comname = '%s_%s' %(datatype.replace('/', '_'), mode) bkgpath = os.path.join(attr.bkgpath(), input_label) bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt') if not os.access(bkgfile, os.F_OK): input_prefix = 'dir_%s' % input_label bkgfile = set_file(extbase=attr.bkgpath(), dt_type=datatype.replace('/', '_'), tag='s', mode=mode, prefix=input_prefix, comname=comname, ext='evt', forceCombine=1) dataset = ROOT.RooDataSet.read(bkgfile, dataset_args) if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if 'floatsigma' not in label: tab_datatype = 'data' tag = 'single' tabfile = set_file('txt', tab_datatype, mode, tag, prefix=prefix, extbase=attr.fitpath()) sys.stdout.write('Using width from %s \n' %tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) res = pdf.fitTo(dataset, Extended, Save, Verbose) res.Print('v') xframe = mbc.frame() xframe.SetMarkerSize(0.3) if '818ipb' in label and 'noxfeed' in label: frame_max = bkg_generic_ddbar_818_max_noxfeed[mode] xframe.SetMaximum(frame_max) dataset.plotOn(xframe) pdf.plotOn(xframe) pdf.paramOn(xframe, dataset) xframe.SetTitle(frametitle) xframe.Draw() c1.Print(epsfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def create_fig_nondiag_mode(dt_type, stage, label, x, y): prefix='dir_'+label if x[1] == 1: uname = modes[x[0]]['uname'] fname = modes[x[0]]['fname'] title1 = modes[x[0]]['orgname'] else: uname = modes[x[0]]['unamebar'] fname = modes[x[0]]['fnamebar'] title1 = modes[x[0]]['orgnamebar'] if y[1] == 1: unameb = modes[y[0]]['uname'] fnameb = modes[y[0]]['fname'] title2 = modes[y[0]]['orgname'] else: unameb = modes[y[0]]['unamebar'] fnameb = modes[y[0]]['fnamebar'] title2 = modes[y[0]]['orgnamebar'] title = '%s fakes %s' % (title1, title2) comname = '%s_Single_%s_fakes_Single_%s' % (dt_type, fname, fnameb) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=comname+'.eps') pdffile = epsfile.replace('.eps', '.pdf') figlabel = label.split('/')[0] relpath = label.replace(figlabel, '') pdflink = '.%s/%s.pdf' %(relpath, comname) pnglink = '.%s/%s.png' %(relpath, comname) if not os.access(pdffile, os.F_OK): if not os.access(epsfile, os.F_OK): sys.stdout.write('epsfile is not ready for %s, %s \n' % (x, y)) else: sys.stdout.write('Converting %s ...' % epsfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile) sys.stdout.write(' OK.\n') figlink = '[[%s][%s]]' %(pdflink, pnglink) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=comname+'.txt') xstr = pair_to_str(x) ystr = pair_to_str(y) logname = 'stage_%s_%s_%s.txt' %(stage, xstr,ystr) logfile = tools.set_file(extbase=attr.logpath, prefix=prefix, comname=logname) if not os.access(epsfile, os.F_OK): sys.stdout.write('Please check log: %s\n' % logfile) loglink = '' if os.access(logfile, os.F_OK): loglink = '[[../../log/%s/%s][log]]' %(label, logname) tablink = '' if os.access(txtfile, os.F_OK): orgtabfile = txtfile.replace('.txt', '.org') tab = DHadTable(txtfile) tab.output_org(orgtabfile) abspath = os.path.join(attr.base)#, attr.analysis) orgtabfile = orgtabfile.replace(abspath, '../..') tablink = '#+INCLUDE: "%s"\n' % orgtabfile msg = '\n* %s \n %s \n\n%s\n %s\n' % ( title, figlink, tablink, loglink) return msg
def double_tag_mode(dt_type, mode, label, interact=False, test=False): mode = get_modekey(mode) tag = 'double' prefix = 'dir_'+label evtprefix = get_evtprefix(dt_type, label) mode1 = mode[0] mode2 = mode[1] title1 = attr.modes[mode1]['uname'] title2 = attr.modes[mode2]['unamebar'] code1 = attr.interfacecodes[mode1] code2 = attr.interfacecodes[mode2] forceCombine = None # Different from single tag case Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma1, F1a, F1b, S1a, S1b = get_resolution_paras(mode1, label) Sigma2, F2a, F2b, S2a, S2b = get_resolution_paras(mode2, label) opt, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat = get_double_paras(label) epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) if not os.access(evtfile, os.F_OK): if '818ipb' in evtprefix: evtfile_281ipb = evtfile.replace('818ipb', '281ipb') evtfile_537ipb = evtfile.replace('818ipb', '537ipb') combine_files(evtfile_281ipb, evtfile_537ipb, evtfile) else: raise ValueError(evtfile) tools.print_sep() par_str = '("%s", %f, %f, %f, %f, %f, "%s", %f, %f, %f, \ %f, %f, "%s", "%s", "%s", %d, "%s", "%s", "%s", %f,\ %f, %f, %f, %f, %f, %f, %f)' par_tuple = (code1, Sigma1, F1a, F1b, S1a, S1b, code2, Sigma2, F2a, F2b, S2a, S2b, evtfile, epsfile, outfile, mc, opt, title1, title2, Gamma, Mres, R, N, Nbkgd1, Nbkgd2, Nbkgd3, NbkgdFlat) par = par_str % par_tuple print_paras_double(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'lineshapefit2d.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro( source + par) sys.stdout.write('Save output in %s\n' % outfile) tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def create_fig_diag_mode(dt_type, stage, label, mode, sign): prefix='dir_'+label if sign == 1: uname = modes[mode]['uname'] fname = modes[mode]['fname'] title = modes[mode]['orgname'] else: uname = modes[mode]['unamebar'] fname = modes[mode]['fnamebar'] title = modes[mode]['orgnamebar'] comname = '%s_Single_%s_fakes_Single_%s' % (dt_type, fname, fname) epsfile = tools.set_file(extbase=attr.figpath, prefix=prefix, comname=comname+'.eps') pdffile = epsfile.replace('.eps', '.pdf') figlabel = label.split('/')[0] relpath = label.replace(figlabel, '') pdflink = '.%s/%s.pdf' %(relpath, comname) pnglink = '.%s/%s.png' %(relpath, comname) if not os.access(pdffile, os.F_OK): if not os.access(epsfile, os.F_OK): sys.stdout.write('epsfile is not ready for (%s %s) \n' % (mode, sign)) else: tools.eps2png(epsfile) tools.eps2pdf(epsfile) figlink = '[[%s][%s]]' %(pdflink, pnglink) txtfile = tools.set_file(extbase=attr.fitpath, prefix=prefix, comname=comname+'.txt') logname = 'stage_%s_%s_%s.txt' %(stage, mode, sign) logfile = tools.set_file(extbase=attr.logpath, prefix=prefix, comname=logname) loglink = '' if os.access(logfile, os.F_OK): loglink = '[[../../log/%s/%s][log]]' %(label, logname) tablink = '' if os.access(txtfile, os.F_OK): orgtabfile = txtfile.replace('.txt', '.org') tab = DHadTable(txtfile) tab.output_org(orgtabfile) abspath = os.path.join(attr.base)#, attr.analysis) orgtabfile = orgtabfile.replace(abspath, '../..') tablink = '#+INCLUDE: "%s"\n' % orgtabfile msg = '\n* %s \n %s \n\n%s\n %s\n' % ( title, figlink, tablink, loglink) return msg
def single_tag_mode(dt_type, mode, label, interact=False, test=False): mode = get_modekey(mode) tag = 'single' prefix = 'dir_' + label evtprefix = get_evtprefix(dt_type, label) Gamma, Mres, R, mc = get_common_parameters(dt_type, label) Sigma, Fa, Fb, Sa, Sb = get_resolution_paras(mode, label) N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi = init_paras_single( label, dt_type, tag, mode) # ------------------- Parameters for the fit ---------- title1 = attr.modes[mode]['uname'] title2 = attr.modes[mode]['unamebar'] num_fcn = 3 # : 0 for only background xi_side = 0.0 p_side = 0.0 int_d = 1 optstr = 'p' # To plot, f : fast, w: fixwidth floatwidth = 0 Min = 0.5 options = "" MINUIT = "ermh4" # ------------------------------------------------- if '/p/0.5' in label: p_side = 0.5 if '/argus' in label: options = 'fix_xi,fix_p' xi, p = get_argus_paras_single(label, dt_type, tag, mode) if '/fix_sigmap1' in label: options = 'fix_sigmap1' if '/kssideband' in label: sys.stdout.write('Fixing the sigmap1 as %s ...\n' %Sigma) sigmap1 = Sigma if '/fix_n1n2' in label and '/desideband' in label: options = 'fix_n1n2' N1 = 1 N2 = 1 if dt_type == 'signal' and mode in [0, 200, 202]: p_side = 0.5 tools.print_sep() forceCombine = 1 epsfile = tools.set_file('eps', dt_type, mode, tag, prefix=prefix, extbase=attr.figpath) fitpath = attr.fitpath outfile = tools.set_file('txt', dt_type, mode, tag, prefix=prefix, extbase=fitpath) evtpath = attr.evtpath evtfile = tools.set_file('evt', dt_type, mode, tag, prefix=evtprefix, forceCombine=forceCombine, extbase=evtpath) tools.print_sep() par_str = '( "%s", "%s", "%s", "%s", "%s", %d, %d, %f, %f, %f, %f, \ %f, %f, %f, %d, "%s", %f, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, \ %f, "%s", "%s" )' par_tuple = (title1, title2, evtfile, epsfile, outfile, mc, num_fcn, xi_side, p_side, Sigma, Sa, Sb, Fa, Fb, int_d, optstr, Gamma, floatwidth, R, Mres, N1, N2, Nbkgd1, Nbkgd2, md, p, sigmap1, xi, Min, options, MINUIT) par = par_str % par_tuple print_paras(par_tuple) load_roofit_lib(dt_type, label) sourcename = 'mbc_singletag_3s.C' #if interact: source = os.path.join(attr.srcfitpath, sourcename) tools.print_sep() sys.stdout.write(' ROOT macro: %s \n' % source) tools.print_sep() if test: return ROOT.gROOT.Macro( source + par) if test: evtfile = evtfile + '.test' epsfile = epsfile + '.test' outfile = outfile + '.test' # fit_mbc_single(title1, title2, evtfile, epsfile, outfile, mc, num_fcn, # xi_side, p_side, Sigma, Sa, Sb, Fa, Fb, int_d, optstr, # Gamma, floatwidth, R, Mres, N1, N2, Nbkgd1, Nbkgd2, md, # p, sigmap1, xi, Min, options, MINUIT) sys.stdout.write('Save output in %s\n' % outfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)
def fit_backgrounds_single_mode(datatype, mode, label, test): comname = '%s_%s' % (datatype.replace('/', '_'), mode) input_label = label if 'nogaus' in label: input_label = label.split('/')[0] bkgpath = os.path.join(attr.bkgpath(), input_label) bkgfile = set_file(extbase=bkgpath, comname=comname, ext='evt') if not os.access(bkgfile, os.F_OK): input_prefix = 'dir_%s' % input_label bkgfile = set_file(extbase=attr.bkgpath(), dt_type=datatype.replace('/', '_'), tag='s', mode=mode, prefix=input_prefix, comname=comname, ext='evt', forceCombine=1) epspath = os.path.join(attr.figpath, label) epsfile = set_file(extbase=epspath, comname=comname, ext='eps') txtpath = os.path.join(attr.fitpath(), label) txtfile = set_file(extbase=txtpath, comname=comname, ext='txt') if test: epsfile = epsfile + '.test' txtfile = txtfile + '.test' ROOT.gROOT.SetBatch(1) ROOT.gROOT.SetStyle('Plain') mbc = ROOT.RooRealVar('mbc', 'Beam constrained mass', 1.83, 1.89, 'GeV') mbc_aset = ROOT.RooArgSet(mbc) ebeam = ROOT.RooRealVar('ebeam', 'Ebeam', 1.8815, 1.892, 'GeV') dflav = ROOT.RooCategory('dflav', 'D0 flavor') dflav.defineType('dflav', 1) dflav.defineType('dbarflav', -1) dataset_args = ROOT.RooArgList(mbc, ebeam, dflav) dataset = ROOT.RooDataSet.read(bkgfile, dataset_args) arg_cutoff = ROOT.RooRealVar('arg_cutoff', 'Argus cutoff', 1.88, 1.89, 'GeV') arg_slope = ROOT.RooRealVar('arg_slope', 'Argus slope', -10, -100, -1) yld = ROOT.RooRealVar('yield', 'D yield', 100, 0, 200000) bkg = ROOT.RooRealVar('bkg', 'Background', 100, 0, 1000000) sigma = ROOT.RooRealVar('sigma', 'D width', 0.0001, 0.005, 'GeV') pars = [arg_cutoff, arg_slope, bkg, sigma, yld] mbc_d0 = ROOT.RooRealVar('mbc_d0', 'D0 Mbc', 1.8647, 'GeV') mbc_dp = ROOT.RooRealVar('mbc_dp', 'D+ Mbc', 1.8694, 'GeV') gauss_d0 = ROOT.RooGaussian('gauss_d0', 'D0 gaussian', mbc, mbc_d0, sigma) gauss_dp = ROOT.RooGaussian('gauss_dp', 'D+ gaussian', mbc, mbc_dp, sigma) argus = ROOT.RooArgusBG('argus', 'Argus BG', mbc, arg_cutoff, arg_slope) sumpdf_d0 = ROOT.RooAddPdf('sumpdf_d0', 'D0 sum pdf', ROOT.RooArgList(gauss_d0, argus), ROOT.RooArgList(yld, bkg)) sumpdf_dp = ROOT.RooAddPdf('sumpdf_dp', 'Dp sum pdf', ROOT.RooArgList(gauss_dp, argus), ROOT.RooArgList(yld, bkg)) Extended = ROOT.RooFit.Extended(ROOT.kTRUE) Save = ROOT.RooFit.Save(ROOT.kTRUE) Hesse = ROOT.RooFit.Hesse(ROOT.kFALSE) Verbose = ROOT.RooFit.Verbose(ROOT.kFALSE) if 'D0' in mode: pdf = sumpdf_d0 else: pdf = sumpdf_dp if 'nogaus' in label: yld.setVal(1) yld.setConstant(ROOT.kTRUE) pars.remove(yld) if 'floatsigma' not in label: datatype = 'data' tag = 'single' if '281ipb' in label: prefix = 'dir_281ipbv7' frame_max = bkg_generic_ddbar_281_max[mode] elif '537ipb' in label: prefix = 'dir_537ipbv7' frame_max = bkg_generic_ddbar_537_max[mode] elif '818ipb' in label: prefix = 'dir_818ipbv7' frame_max = bkg_generic_ddbar_818_max[mode] if 'noxfeed' in label: frame_max = bkg_generic_ddbar_818_max_noxfeed[mode] else: raise NameError(label) tabfile = set_file('txt', datatype, mode, tag, prefix=prefix, extbase=attr.fitpath()) sys.stdout.write('Using width from %s \n' % tabfile) tab = DHadTable(tabfile) sigmap1 = float(tab.cell_get('sigmap1', 'Value')) sigma.setVal(sigmap1) sigma.setConstant(ROOT.kTRUE) pars.remove(sigma) res = pdf.fitTo(dataset, Extended, Save, Verbose) res.Print('v') c1 = ROOT.TCanvas('c1', 'canvas1', 600, 600) c1.SetFixedAspectRatio(0) xframe = mbc.frame() xframe.SetMaximum(frame_max) xframe.SetMarkerSize(0.3) dataset.plotOn(xframe) pdf.plotOn(xframe) nfitParam = len(pars) chisq_ndof = xframe.chiSquare(nfitParam) nbin = xframe.GetNbinsX() ndof = nbin - nfitParam chisq = chisq_ndof * ndof chisqbox = ROOT.TPaveText(0.1, 0.1, 0.4, 0.15, 'BRNDC') chisqbox.SetFillColor(0) chisqbox.SetBorderSize(1) chisqbox.AddText('#chi^{2}/ndof = %.3f/%d = %.3f' % (chisq, ndof, chisq_ndof)) xframe.addObject(chisqbox) pdf.paramOn(xframe, dataset) xframe.SetTitle('Generic faking %s' % mode) xframe.Draw() c1.Print(epsfile) tools.save_fit_result(pars, txtfile) if not test: tools.eps2png(epsfile) tools.eps2pdf(epsfile)