def compare(fn1, fn2, outbase): f1, f2 = fs = ROOT.TFile.Open(fn1), ROOT.TFile.Open(fn2) samples_1 = dict((name, isample) for isample, name in isamplename_iterator(f1)) samples_2 = dict((name, isample) for isample, name in isamplename_iterator(f2)) names_1 = set(samples_1) names_2 = set(samples_2) names = sorted(names_1 & names_2) nnames = len(names) if not names: print 'no samples in common between %s and %s' % (fn1, fn2) return else: print '%i samples in common' % nnames if names_1 != names_2: print '# samples only in %s: %i' % (fn1, len(names_1 - names_2)) #pprint(sorted(names_1 - names_2)) print '# samples only in %s: %i' % (fn2, len(names_2 - names_1)) #pprint(sorted(names_2 - names_1)) h_fcns = [] def make_h_fcn(nm, fcn): h = ROOT.TH1D(nm, '%s - %s' % (fn1, fn2), nnames, 0, nnames) h_fcns.append((h, fcn)) return h h_eff1v = make_h_fcn('eff1v', eff1v) h_eff2v = make_h_fcn('eff2v', eff2v) h_dbvmean = make_h_fcn('dbvmean', lambda f,isample: (h_dbv(f,isample).GetMean(), h_dbv(f,isample).GetMeanError())) h_dbvrms = make_h_fcn('dbvrms', lambda f,isample: (h_dbv(f,isample).GetRMS(), h_dbv(f,isample).GetRMSError() )) h_dvvmean = make_h_fcn('dvvmean', lambda f,isample: (h_dvv(f,isample).GetMean(), h_dvv(f,isample).GetMeanError())) h_dvvrms = make_h_fcn('dvvrms', lambda f,isample: (h_dvv(f,isample).GetRMS(), h_dvv(f,isample).GetRMSError() )) all_stat_same, all_same = True, True for iname, name in enumerate(names): isamples = samples_1[name], samples_2[name] for h, fcn in h_fcns: (v1,e1), (v2, e2) = [fcn(f, isample) for f,isample in zip(fs, isamples)] h.GetXaxis().SetBinLabel(iname+1, name) d = v1 - v2 e = (e1**2 + e2**2)**0.5 h.SetBinContent(iname+1, d) h.SetBinError (iname+1, e) if abs(d) > 1e-5: all_same = False if abs(d) > e: all_stat_same = False c = ROOT.TCanvas('c', '', 1000, 800) line = ROOT.TLine(0, 0, nnames, 0) line.SetLineStyle(2) line.SetLineWidth(2) for i,(h,_) in enumerate(h_fcns): h.SetStats(0) h.SetLineWidth(2) h.Draw('e') line.Draw() for ext in 'root', 'png': c.SaveAs(outbase + '/%i_%s.%s' % (i, h.GetName(), ext)) print 'all same? %r statistically? %r' % (all_same, all_stat_same)
print '\t', i print print 'samples with gen eff NOT within %s%% of reco eff:' % gen_rec_cut for i in not_matched: print '\t', i c = ROOT.TCanvas() c.SetTickx() c.SetTicky() c.SetRightMargin(0.3) g_all = ROOT.TGraphErrors(len(x), to_array(x), to_array(y), to_array(ex), to_array(ey)) g_all.SetTitle(';reconstructed-level efficiency;generator-level efficiency') g_all.GetXaxis().SetLimits(0,1) g_all.GetHistogram().GetYaxis().SetRangeUser(0,1) g_all.Draw('AP') for g in gs: g.Draw('P') l1.SetFillColor(0) l1.Draw() l2.SetFillColor(0) l2.Draw() line0 = ROOT.TLine(0,0,1,1) line0.SetLineStyle(7) line1 = ROOT.TLine(0,0,1,1-0.01*gen_rec_cut) line2 = ROOT.TLine(0,0,1-0.01*gen_rec_cut,1) line0.Draw() line1.Draw() line2.Draw() if save_plot: c.SaveAs(os.path.join(plot_path, 'gen_vs_reco_eff_%s_divide_%s%s%s.pdf' % (gen_num, gen_den, '' if ctau == '' else '_%s'%ctau, match)))