def make_fakes_view(weight_type, scale): scaled_bare_data = views.ScaleView(all_data_view, scale) scaled_wz_data = views.ScaleView(all_wz_view, scale) scaled_data = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( scaled_data, 'ss/%s/p1f2f3/%s2' % (tau_charge, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1f2f3/%s12' % (tau_charge, weight_type)) # Give the individual object views nice colors obj1_view = views.TitleView( views.StyleView(obj1_view, **remove_name_entry(data_styles['TT*'])), 'Reducible bkg. 1') obj2_view = views.TitleView( views.StyleView(obj2_view, **remove_name_entry(data_styles['QCD*'])), 'Reducible bkg. 2') obj12_view = views.TitleView( views.StyleView(obj12_view, **remove_name_entry(data_styles['WW*'])), 'Reducible bkg. 12') subtract_obj12_view = views.ScaleView(obj12_view, -1) return obj1_view, obj2_view, obj12_view, subtract_obj12_view
def make_qcd_proj_views(self, control_region, rebin): ''' Make views when obj1 or obj2 fails, projecting QCD in QCD comes from the triple fake region ''' all_data_view = self.rebin_view(self.get_view('data'), rebin) mapping = { 1: { 'obs': 'ss/tau_os/f1p2p3', 'qcd': 'ss/tau_os/f1f2f3/w23', }, 2: { 'obs': 'ss/tau_os/p1f2p3', 'qcd': 'ss/tau_os/f1f2f3/w13', }, } data_view = views.TitleView(views.SubdirectoryView( all_data_view, mapping[control_region]['obs']), "Anti-iso obj %i" % control_region) qcd_view = views.TitleView(views.SubdirectoryView( all_data_view, mapping[control_region]['qcd']), "QCD") qcd_view = views.StyleView( qcd_view, drawstyle='hist', linecolor=colors['red'], fillstyle=0, legendstyle='l' ) return {'obs': data_view, 'qcd': qcd_view}
def make_views(self, rebin): ''' Make signal views with FR background estimation ''' wz_view = InflateErrorView( views.SubdirectoryView( self.rebin_view(self.get_view('WZ*'), rebin), 'charge'), 0.16) zz_view = InflateErrorView( views.SubdirectoryView( self.rebin_view(self.get_view('ZZ*'), rebin), 'charge'), 0.16) zj_view = views.SubdirectoryView( self.rebin_view(self.get_view('Zjets*'), rebin), 'charge') diboson_view = views.StyleView(views.SumView(wz_view, zz_view), fillcolor=(ROOT.EColor.kRed - 7), drawstyle='hist') all_data_view = views.SubdirectoryView( self.rebin_view(self.get_view('data'), rebin), 'charge') output = { 'wz': wz_view, 'zz': zz_view, 'zjets': zj_view, 'data': all_data_view, 'diboson': diboson_view, } return output
def make_regions(sample): regions = { 'wjets': views.SubdirectoryView(sample, 'wjets'), 'qcd': views.SubdirectoryView(sample, 'qcd'), 'zmm': views.SubdirectoryView(sample, 'zmm'), 'zmm_tau20': views.SubdirectoryView(sample, 'zmm_tau20'), } # EWK is combo of wjets and ZMM #regions['ewk'] = views.SumView(regions['wjets'], regions['zmm']), return regions
def make_signal_views(self, rebin, unblinded=True): ''' Make signal views with FR background estimation ''' wz_view = views.SubdirectoryView( self.rebin_view(self.get_view('WZ*'), rebin), 'os/All_Passed/') zz_view = views.SubdirectoryView( self.rebin_view(self.get_view('ZZ*'), rebin), 'os/All_Passed/') all_data_view = self.rebin_view(self.get_view('data'), rebin) if unblinded and self.blind: all_data_view = self.rebin_view( self.get_view('data', 'unblinded_view'), rebin) data_view = views.SubdirectoryView(all_data_view, 'os/All_Passed/') #Categories (to match Abdollah's naming convention) probes = [p + 'IsoFailed' for p in products_map[self.channel][1]] cat0 = 'os/' + '_'.join(probes) + '/all_weights_applied/' cat1 = 'os/' + probes[0] + '/obj1_weight/' cat2 = 'os/' + probes[1] + '/obj2_weight/' # View of weighted obj1-fails data cat1_view = views.SubdirectoryView(all_data_view, cat1) # View of weighted obj2-fails data cat2_view = views.SubdirectoryView(all_data_view, cat2) # View of weighted obj1&2-fails data cat0_view = views.SubdirectoryView(all_data_view, cat0) subtract_cat0_view = views.ScaleView(cat0_view, -1) # Corrected fake view Zjets_view = views.SumView(cat1_view, cat2_view, subtract_cat0_view) Zjets_view = views.TitleView( views.StyleView(Zjets_view, **data_styles['Zjets*']), 'Non-prompt') charge_fakes = views.TitleView( views.StyleView( views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1'), **data_styles['TT*']), 'Charge mis-id') output = { 'wz': wz_view, 'zz': zz_view, 'data': data_view, 'cat1': cat1_view, 'cat2': cat2_view, 'Zjets': Zjets_view, 'charge_fakes': charge_fakes, } # Add signal for mass in [110, 120, 130, 140]: vh_view = views.SubdirectoryView( self.rebin_view(self.get_view('VH_H2Tau_M-%i' % mass), rebin), 'os/All_Passed/') output['vh%i' % mass] = vh_view ww_view = views.SubdirectoryView( self.rebin_view(self.get_view('VH_%i_HWW' % mass), rebin), 'os/All_Passed/') output['vh%i_hww' % mass] = ww_view output['signal%i' % mass] = views.SumView(ww_view, vh_view) return output
def make_fakes_view(sign, weight_type): # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( data_view, '%s/f1p2/%s' % (sign, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( data_view, '%s/p1f2/%s' % (sign, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( data_view, '%s/f1f2/%s' % (sign, weight_type)) # Give the individual object views nice colors subtract_obj12_view = views.ScaleView(obj12_view, -1) return obj1_view, obj2_view, subtract_obj12_view
def make_signal_views(self, rebin, unblinded=True): ''' Make signal views with FR background estimation ''' wz_view = views.SubdirectoryView( self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), 'ss/p1p2p3/') zz_view = views.SubdirectoryView( self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1p2p3/') all_data_view = self.rebin_view(self.get_view('data'), rebin) if unblinded: all_data_view = self.rebin_view( self.get_view('data', 'unblinded_view'), rebin) data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3/') # View of weighted obj1-fails data obj1_view = views.SubdirectoryView(all_data_view, 'ss/f1p2p3/w1') # View of weighted obj2-fails data obj2_view = views.SubdirectoryView(all_data_view, 'ss/p1f2p3/w2') # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView(all_data_view, 'ss/f1f2p3/w12') subtract_obj12_view = views.ScaleView(obj12_view, -1) # Corrected fake view fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view) fakes_view = views.TitleView( views.StyleView(fakes_view, **data_styles['Zjets*']), 'Non-prompt') charge_fakes = views.TitleView( views.StyleView( views.SubdirectoryView(all_data_view, 'os/p1p2p3/c1'), **data_styles['TT*']), 'Charge mis-id') output = { 'wz': wz_view, 'zz': zz_view, 'data': data_view, 'obj1': obj1_view, 'obj2': obj2_view, 'fakes': fakes_view, 'charge_fakes': charge_fakes, } # Add signal for mass in [110, 120, 130, 140]: vh_view = views.SubdirectoryView( self.rebin_view(self.get_view('VH_*%i' % mass), rebin), 'ss/p1p2p3/') output['vh%i' % mass] = vh_view ww_view = views.SubdirectoryView( self.rebin_view(self.get_view('WH_%i*' % mass), rebin), 'ss/p1p2p3/') output['vh%i_hww' % mass] = ww_view output['signal%i' % mass] = views.SumView(ww_view, vh_view) return output
def make_view(tf, subdir, title, colour): return urviews.NormalizedView( views.TitleView( views.StyleView(views.SubdirectoryView(tf, subdir), linecolor=colour, drawstyle='hist', linewidth=3, legendstyle='l'), title))
def get_flip_data(self, rebin=1, xaxis='', data_type='data'): data_view = self.get_view(data_type) data_view = self.rebin_view(data_view, rebin) if rebin != 1 else data_view #Get ss/p1p2 views ss_p1p2_view = views.SubdirectoryView(data_view, 'ss/p1p2') ss_p1p2_view = views.TitleView( views.StyleView(ss_p1p2_view, **data_styles['data*']), 'observed;%s' % xaxis) #def make_fakes_view(sign, weight_type): # # View of weighted obj1-fails data # obj1_view = views.SubdirectoryView(data_view, '%s/f1p2/%s' % (sign, weight_type)) # # View of weighted obj2-fails data # obj2_view = views.SubdirectoryView(data_view, '%s/p1f2/%s' % (sign, weight_type)) # # View of weighted obj1&2-fails data # obj12_view = views.SubdirectoryView(data_view, '%s/f1f2/%s' % (sign, weight_type)) # # Give the individual object views nice colors # subtract_obj12_view = views.ScaleView(obj12_view, -1) # return obj1_view, obj2_view, subtract_obj12_view #Get fakes according to WJets or QCD #ss_f1p2_qcd_view, ss_p1f2_qcd_view, ss_f1f2_qcd_view = self.make_fakes_view(data_view, 'ss','qcd_w') ss_f1p2_wje_view, ss_p1f2_wje_view, ss_f1f2_wje_view = self.make_fakes_view( data_view, 'ss', 'wjet_w') ss_fakes_1 = ss_f1p2_wje_view #MedianView(lowv=ss_f1p2_qcd_view, highv=ss_f1p2_wje_view) ss_fakes_2 = ss_p1f2_wje_view #MedianView(lowv=ss_p1f2_qcd_view, highv=ss_p1f2_wje_view) ss_fakes_12 = ss_f1f2_wje_view #MedianView(lowv=ss_f1f2_qcd_view, highv=ss_f1f2_wje_view) ss_fakes_est = views.SumView(ss_fakes_1, ss_fakes_2, ss_fakes_12) ss_fakes_est = views.TitleView( views.StyleView(ss_fakes_est, **data_styles['Zjets*']), 'Fakes;%s' % xaxis) os_flip_est_up = views.SubdirectoryView(data_view, 'os/p1p2/charge_weightSysUp') os_flip_est = views.SubdirectoryView(data_view, 'os/p1p2/charge_weight') #os_flip_est = MedianView(highv=os_flip_est_up, centv=os_flip_est) os_flip_est_nofake = os_flip_est #views.SumView(os_flip_est, neg_os_fakes) os_flip_est_nofake = views.TitleView( views.StyleView(os_flip_est_nofake, **data_styles['WZ*']), 'charge-fakes;%s' % xaxis) return ss_p1p2_view, ss_fakes_est, os_flip_est_nofake
def region_directory(base_view, is_os, passed1, passed2): ''' Get the directory given the configuration ''' directory = "_".join([ "os" if is_os else "ss", args.l1name, "pass" if passed1 else "fail", args.l2name, "pass" if passed2 else "fail", ]) return views.SubdirectoryView(base_view, directory)
def make_additional_fakes_view(self, unblinded=False, rebin=1, project=None, project_axis=None, tau_charge='tau_os' ): other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' def preprocess(view): ret = view if project and project_axis: ret = ProjectionView(ret, project_axis, project) return RebinView( ret, rebin ) zjets_view = preprocess( self.get_view('Zjets*') ) all_data_view = preprocess( self.get_view('data') ) zjets_fakes = views.SumView( views.SubdirectoryView( zjets_view, 'ss/%s/f1p2p3/w1/' % tau_charge ), views.SubdirectoryView( zjets_view, 'ss/%s/p1f2p3/w2/' % tau_charge ) #,views.SubdirectoryView( zjets_view, 'ss/%s/f1f2p3/w12/' % tau_charge ) #FIXME: check that effect is small ) tau_fakes = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2f3/w3/' % tau_charge) full_fakes = views.SumView(tau_fakes, zjets_fakes) return { 'fakes' : full_fakes, 'zjet_fakes' : zjets_fakes, 'tau_fakes' : tau_fakes, }
def make_wz_cr_views(self, rebin): ''' Make WZ control region views with FR background estimation ''' wz_view = views.SubdirectoryView( self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), 'ss/p1p2p3_enhance_wz/') zz_view = views.SubdirectoryView( self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1p2p3_enhance_wz/') all_data_view = self.rebin_view(self.get_view('data'), rebin) data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2p3_enhance_wz/') # View of weighted obj2-fails data fakes_view = views.SubdirectoryView(all_data_view, 'ss/p1f2p3_enhance_wz/w2') fakes_view = views.StyleView(fakes_view, **data_styles['Zjets*']) # Correct wz_in_fakes_view = views.SubdirectoryView( self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), 'ss/p1f2p3_enhance_wz/w2') zz_in_fakes_view = views.SubdirectoryView( self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1f2p3_enhance_wz/w2') diboson_view = views.SumView(wz_in_fakes_view, zz_in_fakes_view) inverted_diboson_view = views.ScaleView(diboson_view, -1) fakes_view = views.SumView(fakes_view, inverted_diboson_view) fakes_view = views.TitleView(fakes_view, 'Non-prompt') output = { 'wz': wz_view, 'zz': zz_view, 'data': data_view, 'fakes': fakes_view } # Add signal for mass in [110, 120, 130, 140]: vh_view = views.SubdirectoryView( self.rebin_view(self.get_view('VH_*%i' % mass), rebin), 'ss/p1p2p3/') output['vh%i' % mass] = vh_view return output
def make_wz_cr_views(self, rebin=1, project=None, project_axis=None): ''' Make WZ control region views with FR background estimation ''' def preprocess(view): ret = view if project and project_axis: ret = ProjectionView(ret, project_axis, project) return RebinView( ret, rebin ) wz_view_tautau_all = preprocess( self.get_view('WZJetsTo3LNu*ZToTauTau*') ) wz_view_tautau = views.SubdirectoryView(wz_view_tautau_all, 'ss/tau_os/p1p2p3_enhance_wz/') tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' wz_view_3l_all = preprocess( self.get_view(tomatch) ) wz_view_3l = views.SubdirectoryView(wz_view_3l_all, 'ss/tau_os/p1p2p3_enhance_wz/') wz_view_all = views.SumView(wz_view_tautau_all, wz_view_3l_all) zz_view_all = preprocess( self.get_view('ZZJetsTo4L*') ) zz_view = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1p2p3_enhance_wz/') all_data_view = preprocess( self.get_view('data') ) data_view = views.SubdirectoryView( all_data_view, 'ss/tau_os/p1p2p3_enhance_wz/') # View of weighted obj2-fails data fakes_view = views.SubdirectoryView( all_data_view, 'ss/tau_os/p1f2p3_enhance_wz/w2') fakes_view = views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])) # Correct wz_in_fakes_view = views.SubdirectoryView(wz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2') zz_in_fakes_view = views.SubdirectoryView(zz_view_all, 'ss/tau_os/p1f2p3_enhance_wz/w2') diboson_view = views.SumView(wz_in_fakes_view, zz_in_fakes_view) inverted_diboson_view = views.ScaleView(diboson_view, -1) fakes_view = views.SumView(fakes_view, inverted_diboson_view) fakes_view = views.TitleView(fakes_view, 'Reducible bkg.') output = { 'wz_ztt': wz_view_tautau, 'wz_3l' : wz_view_3l, 'zz' : zz_view, 'data' : data_view, 'fakes' : fakes_view } return output
def make_obj3_fail_cr_views(self, rebin): ''' Make views when obj3 fails, estimating the bkg in obj1 pass using f1p2f3 ''' wz_view = views.SubdirectoryView( self.rebin_view(self.get_view('WZJetsTo3LNu*'), rebin), 'ss/p1p2f3/') zz_view = views.SubdirectoryView( self.rebin_view(self.get_view('ZZJetsTo4L*'), rebin), 'ss/p1p2f3/') all_data_view = self.rebin_view(self.get_view('data'), rebin) data_view = views.SubdirectoryView(all_data_view, 'ss/p1p2f3/') # View of weighted obj1-fails data obj1_view = views.SubdirectoryView(all_data_view, 'ss/f1p2f3/w1') # View of weighted obj2-fails data obj2_view = views.SubdirectoryView(all_data_view, 'ss/p1f2f3/w2') # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView(all_data_view, 'ss/f1f2f3/w12') subtract_obj12_view = views.ScaleView(obj12_view, -1) # Corrected fake view fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view) fakes_view = views.TitleView( views.StyleView(fakes_view, **data_styles['Zjets*']), 'Non-prompt') charge_fakes = views.TitleView( views.StyleView( views.SubdirectoryView(all_data_view, 'os/p1p2f3/c1'), **data_styles['TT*']), 'Charge mis-id') output = { 'wz': wz_view, 'zz': zz_view, 'data': data_view, 'obj1': obj1_view, 'obj2': obj2_view, 'fakes': fakes_view, 'charge_fakes': charge_fakes, } return output
def __init__(self, data_view, cr, cr_qcd_est, cr_ewk_weight, cr_qcd_weight): self.cr = views.SubdirectoryView(data_view, cr) self.cr_qcd_est = views.SubdirectoryView(data_view, cr_qcd_est) self.cr_ewk_weight = views.SubdirectoryView(data_view, cr_ewk_weight) self.cr_qcd_weight = views.SubdirectoryView(data_view, cr_qcd_weight)
def plot_zee_control(self, variable, xaxis='', rebin=1, legend_on_the_left=False, x_range=None, show_ratio=False, logscale=False): data_view = self.get_view('data') data_view = self.rebin_view(data_view, rebin) if rebin != 1 else data_view mc_views = [ self.get_view(i) for i in ['ZZ*', 'WZ*', 'WW*', 'TT*', 'Zjets_M50'] ] if rebin != 1: mc_views = [self.rebin_view(i, rebin) for i in mc_views] zee_data = views.SubdirectoryView(data_view, 'os/p1p2/') zee_mcs = [views.SubdirectoryView(i, 'os/p1p2/') for i in mc_views] #os_f1p2_qcd_view, os_p1f2_qcd_view, os_f1f2_qcd_view = self.make_fakes_view(data_view, 'os','qcd_w') os_f1p2_wje_view, os_p1f2_wje_view, os_f1f2_wje_view = self.make_fakes_view( data_view, 'os', 'wjet_w') os_fakes_1 = os_f1p2_wje_view #MedianView(lowv=os_f1p2_qcd_view, highv=os_f1p2_wje_view) os_fakes_2 = os_p1f2_wje_view #MedianView(lowv=os_p1f2_qcd_view, highv=os_p1f2_wje_view) os_fakes_12 = os_f1f2_wje_view #MedianView(lowv=os_f1f2_qcd_view, highv=os_f1f2_wje_view) os_fakes_est = views.SumView(os_fakes_1, os_fakes_2, os_fakes_12) os_fakes_est = views.TitleView( views.StyleView(os_fakes_est, **data_styles['WplusJets*']), 'Fakes;%s' % xaxis) zee_mcs = zee_mcs[:-1] + [os_fakes_est] + zee_mcs[-1:] events_estimate = views.StackView(*zee_mcs) estimate_hist = events_estimate.Get(variable) obs_hist = zee_data.Get(variable) hmax = max([estimate_hist.GetMaximum(), max(list(obs_hist))]) if logscale: obs_hist.GetYaxis().SetRangeUser(10**-2, hmax * 10**4) self.pad.SetLogy(True) else: obs_hist.GetYaxis().SetRangeUser(0., hmax * 1.3) if x_range: obs_hist.GetXaxis().SetRangeUser(x_range[0], x_range[1]) obs_hist.Draw() estimate_hist.Draw('same') obs_hist.Draw('same') self.canvas.Update() self.keep.extend([estimate_hist, obs_hist]) legend = self.add_legend([obs_hist], leftside=legend_on_the_left, entries=len(zee_mcs) + 1) legend.AddEntry(estimate_hist, 'f') #legend.AddEntry(estimate_error,'f') legend.Draw() if show_ratio: self.add_ratio_plot(obs_hist, estimate_hist, x_range, ratio_range=0.2) self.add_cms_blurb(self.sqrts)
'png': True, 'pdf': False }}) ttjets = urviews.NormalizedView( root_open('results/%s/permProbComputer/ttJets.root' % jobid)) subs_and_col = [ ('semilep_visible_right', 'violet'), ('other_tt_decay', 'blue'), ('semilep_right_thad', 'cyan'), ('semilep_right_tlep', 'red'), ('semilep_wrong', '#00960a'), ] samples = [ views.TitleView( views.StyleView(views.SubdirectoryView(ttjets, i), linecolor=j, drawstyle='hist', legendstyle='l'), i) for i, j in subs_and_col ] plots = ['nusolver_chi2', 'thfr', 'tlfr', 'wfr_jcosth_delta'] #plotter.set_subdir('shapes') #for var in plots: # shapes = [i.Get('nosys/%s' % var) for i in samples] # legend = LegendDefinition(position='NE') # plotter.overlay(shapes, legend_def=legend, ytitle='a.u.', y_range='shape', ignore_style=True) # plotter.save(var) systematics = [ ('nosys', 'violet'),
logging.info("Opened file %s" % tfile_name) #get a directory and look into that keys = [ i.GetName() for i in tfile.Get(categories[0]).GetListOfKeys() if not fnmatch(i.GetName(), options.nuisances) ] if options.excluded: keys = [i for i in keys if not fnmatch(i, options.excluded)] data = [i for i in keys if i.startswith('data')][0] keys = [i for i in keys if not i.startswith('data')] logging.debug("These shapes will be plotted: %s" % keys.__repr__()) input_view = views.SumView( *[views.SubdirectoryView(tfile, category) for category in categories]) if options.differential == 1: input_view = DifferentialView(input_view) histograms = [apply_style(input_view.Get(i), i) for i in keys] histograms = sorted(histograms, key=lambda x: x.Integral()) observed = apply_style(input_view.Get(data), data) logging.debug("debugging histos:") for histo in histograms: logging.debug(" %s: style: %s, integral: %.2f" % (histo.GetTitle(), histo.drawstyle, histo.Integral())) stack = plotting.HistStack() for obj in histograms:
def make_obj3_fail_cr_views(self, qcd_correction=False, qcd_weight_fraction=0, tau_charge='tau_os'): ''' Make views when obj3 fails, estimating the bkg in obj1 pass using f1p2f3 ''' other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' all_wz_ztt_view = self.get_view('WZJetsTo3LNu*ZToTauTau*') wz_view = views.SubdirectoryView( all_wz_ztt_view, 'ss/%s/p1p2f3/' % tau_charge ) tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' all_wz_3l_view = self.get_view(tomatch) wz_view_3l = views.SubdirectoryView( all_wz_3l_view, 'ss/%s/p1p2f3/' % tau_charge ) all_wz_view = views.SumView(all_wz_ztt_view, all_wz_3l_view) zz_view = views.SubdirectoryView( self.get_view('ZZJetsTo4L*'), 'ss/%s/p1p2f3/' % tau_charge ) all_data_view = self.get_view('data') data_view = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2f3/' % tau_charge) def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_bare_data = views.ScaleView(all_data_view, scale) scaled_wz_data = views.ScaleView(all_wz_view, scale) scaled_data = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2f3/%s1' % (tau_charge, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( scaled_data, 'ss/%s/p1f2f3/%s2' % (tau_charge, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1f2f3/%s12' % (tau_charge, weight_type)) # Give the individual object views nice colors obj1_view = views.TitleView( views.StyleView(obj1_view, **remove_name_entry(data_styles['TT*'])), 'Reducible bkg. 1') obj2_view = views.TitleView( views.StyleView(obj2_view, **remove_name_entry(data_styles['QCD*'])), 'Reducible bkg. 2') obj12_view = views.TitleView( views.StyleView(obj12_view, **remove_name_entry(data_styles['WW*'])), 'Reducible bkg. 12') subtract_obj12_view = views.ScaleView(obj12_view, -1) return obj1_view, obj2_view, obj12_view, subtract_obj12_view qcd1, qcd2, qcd12, negqcd12 = make_fakes_view('q', qcd_fraction) wjet1, wjet2, wjet12, negwjet12 = make_fakes_view( 'w', 1 - qcd_fraction) obj1_view = views.SumView(qcd1, wjet1) obj2_view = views.SumView(qcd2, wjet2) obj12_view = views.SumView(qcd12, wjet12) subtract_obj12_view = views.SumView(negqcd12, negwjet12) # Corrected fake view fakes_view = views.SumView(obj1_view, obj2_view, subtract_obj12_view) fakes_view = views.TitleView( views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])), 'Reducible bkg.') return obj1_view, obj2_view, obj12_view, fakes_view obj1_view, obj2_view, obj12_view, fakes_view = make_fakes(qcd_weight_fraction) fakes_view_05 = make_fakes(0.5)[-1] fakes_view_0 = make_fakes(0)[-1] fakes_view_1 = make_fakes(1)[-1] style_dict_no_name = remove_name_entry(data_styles['TT*']) charge_fakes = views.TitleView( #FIXME views.StyleView( views.SumView( views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c1' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c2' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), **style_dict_no_name), 'Charge mis-id') charge_fakes_sysup = views.TitleView( views.StyleView( views.SumView( views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c1_sysup' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2f3/c2_sysup' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), **style_dict_no_name), 'Charge mis-id') #charge_fakes = MedianView(highv=charge_fakes_sysup, centv=charge_fakes) output = { 'wz': wz_view, 'wz_3l': wz_view_3l, 'zz': zz_view, 'data': data_view, 'obj1': obj1_view, 'obj2': obj2_view, 'obj12': obj12_view, 'fakes': fakes_view, 'weighted_fakes' : { 0. : fakes_view_0, 0.5 : fakes_view_05, 1. : fakes_view_1, }, 'charge_fakes': { 'central' : charge_fakes, 'sys_up' : charge_fakes_sysup, } } #Add signal @ 120, just mo make bkg fitting easier mass = 120 vh_view = views.SubdirectoryView( self.get_view('VH_*%i' % mass), 'ss/tau_os/p1p2f3/' ) output['vh%i' % mass] = vh_view try: ww_view = views.SubdirectoryView( self.get_view('VH_%i_HWW*' % mass), 'ss/tau_os/p1p2f3/' ) except KeyError: #logging.warning('No sample found matching VH_%i_HWW*' % mass) ww_view = None output['vh%i_hww' % mass] = ww_view output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view return output
def get_wild_dir(self, view, path): '''equivalent of SubdirectoryView, but with unix-style wildcards''' paths = self.expand_path(path) return views.SumView(*[views.SubdirectoryView(view, i) for i in paths])
jobid = os.environ['jobid'] ura_proj = os.environ['URA_PROJECT'] input_file = '%s/results/%s/htt_flav_effs/ttJets.root' % (ura_proj, jobid) tfile = io.root_open(input_file) pt_bins = [ 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0, 210.0, 220.0, 230.0, 240.0, 250.0, 260.0, 270.0, 280.0, 290.0, 300.0, 310.0, 320.0, 330.0, 350.0, 370.0, 410.0, 600.0 ] #[30, 60, 100, 150, 200, 1000] eta_bins = [-2.4, -1.8, -1.2, -0.6, 0.0, 0.6, 1.2, 1.8, 2.4] #[-2.4, -1.4, -0.8, 0.0, 0.8, 1.4, 2.4] hview = urviews.RebinView(tfile, [pt_bins, eta_bins]) hview = views.SumView(views.SubdirectoryView(hview, 'electrons'), views.SubdirectoryView(hview, 'muons')) basedir = tfile.muons def make_efficiency(hpass, hall): eff = hpass.Clone() eff.Reset() for bin_eff, bin_pass, bin_all in zip(eff, hpass, hall): if not bin_eff.overflow and bin_pass.value < 20: log.warning('bin (%.0f, %.2f) has %i entries' % (bin_eff.x.center, bin_eff.y.center, bin_pass.value)) bin_eff.value = bin_pass.value / bin_all.value if bin_all.value else 0 if bin_eff.value == 0 and not bin_eff.overflow: log.error('bin (%.0f, %.2f) has 0 efficiency' % (bin_eff.x.center, bin_eff.y.center))
'SMH', 'singleT',#'Wplus', 'TT'#, #'DYLL', #'DYTT' ]) def get_fakeTaus(x): y=x if x.startswith('os') or x.startswith('ss'): y = x.replace('.*s/', 'tLoose/*s/') return y print mc_samples #myFake = views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : x.startswith('data'), mc_samples)]),**remove_name_entry(data_styles['Fakes*'])), 'Fakes') Fakes = views.SubdirectoryView(views.TitleView(views.StyleView(views.SumView( *[ plotter.get_view(regex) for regex in filter(lambda x : 'Fake*' in x, mc_samples)]), **remove_name_entry(data_styles['Fakes*'])),'Fakes'), 'tLoose/') plotter.views['Fakes']= {'view': Fakes} new_mc_samples.extend(['Fakes']) print new_mc_samples histoname = [('tPt', 'p_T(#tau) (GeV)', 5), ('tEta', '#eta(#tau)', 2), ('tPhi', '#phi(#tau)', 5), ('ePt', 'p_T(e) (GeV)', 5), ('eEta', '#eta(e)', 2), ('ePhi', '#phi(e)', 5), ('et_DeltaPhi', 'e#tau #Delta#phi', 1.), ('et_DeltaR', 'e#tau #Delta{R}', 1.), ('h_collmass_pfmet', 'M_{coll}(e#tau) (GeV)', 1.), ('h_vismass', 'M_{vis} (GeV)', 1.), ('jetN_30', 'number of jets (p_T > 30 GeV)', 1.) ] plotter.mc_samples = new_mc_samples
def make_closure_plots(self, var, testDir, refDir, rebin=1, xaxis=''): '''helper function to make comparison between data and data (closure test for fakerates etc.)''' self.canvas.cd() data_view = self.rebin_view(self.data, rebin) test_view = views.StyleView(views.TitleView( views.SubdirectoryView(data_view, testDir), 'Weighted data'), fillcolor=ROOT.EColor.kRed, drawstyle='hist') #.Get(var) refData = views.SubdirectoryView(data_view, refDir).Get(var) testSampleName = '_'.join(testDir.split('/')[1:]).replace( 'IsoFailed', 'fail').replace('_weight', 'w') refSampleName = refDir.split('/')[1].replace('IsoFailed', 'fail').replace( '_weight', 'w') #testData.SetTitle(testSampleName) refData.SetTitle(refSampleName) diboson_views = [ InflateErrorView( views.SubdirectoryView( self.rebin_view(self.get_view(pattern), rebin), refDir), 0.16) for pattern in ['WZ*'] ] #, 'ZZ*', 'WW*'] ] to_stack_views = diboson_views + [test_view] #+ stack_hist = views.StackView(*to_stack_views).Get(var) refData.drawstyle = "ep" stack_hist.drawstyle = "HIST same" # same" #"HISTe same " hmax = max([ max([(b.content + b.error) for b in zipBins(refData)]), stack_hist.GetMaximum() ]) refData.GetYaxis().SetRangeUser(0, hmax * 1.3) refData.GetXaxis().SetTitle(xaxis) tgTest = HistStackToTGRaphErrors(stack_hist) tgTest.SetFillStyle(3013) tgTest.GetXaxis().SetTitle(xaxis) tgTest.GetYaxis().SetRangeUser(0, hmax * 1.3) self.keep.append(tgTest) refData.SetMarkerStyle(20) refData.SetMarkerSize(1) self.keep.append(refData) self.keep.append(stack_hist) refData.Draw() stack_hist.Draw('same') stack_hist.GetXaxis().SetTitle(xaxis) stack_hist.GetYaxis().SetRangeUser(0, hmax * 1.3) refData.Draw('same') tgTest.Draw('2 same') #stack_hist.Draw() #self.canvas.SetLogy() legend = self.add_legend([refData], leftside=False, entries=len(to_stack_views) + 1) legend.AddEntry(stack_hist, 'f') legend.Draw() self.add_cms_blurb(self.sqrts)
def merge_views(inview, subnames): subviews = [views.SubdirectoryView(inview, i) for i in subnames] return views.SumView(*subviews)
def make_signal_views(self, unblinded=False, qcd_weight_fraction=0, #MARK rebin=1, project=None, project_axis=None, tau_charge='tau_os' ): ''' Make signal views with FR background estimation ''' other_tau_sign = 'tau_os' if tau_charge == 'tau_ss' else 'tau_ss' def preprocess(view): ret = view if project and project_axis: ret = ProjectionView(ret, project_axis, project) return RebinView( ret, rebin ) all_wz_view_tautau = preprocess( self.get_view('WZJetsTo3LNu*ZToTauTau*') ) wz_view_tautau = views.SubdirectoryView( all_wz_view_tautau, 'ss/%s/p1p2p3/' % tau_charge ) tomatch = 'WZJetsTo3LNu' if self.sqrts == 7 else 'WZJetsTo3LNu_pythia' all_wz_view_3l = preprocess( self.get_view(tomatch) ) wz_view_3l = views.SubdirectoryView( all_wz_view_3l, 'ss/%s/p1p2p3/' % tau_charge ) all_wz_view = views.SumView(all_wz_view_tautau, all_wz_view_3l) zz_view = preprocess( views.SubdirectoryView( self.get_view('ZZJetsTo4L*'), 'ss/%s/p1p2p3/' % tau_charge ) ) all_data_view = self.get_view('data') #if unblinded: # all_data_view = self.get_view('data', 'unblinded_view') all_data_view = preprocess(all_data_view) data_view = views.SubdirectoryView(all_data_view, 'ss/%s/p1p2p3/' % tau_charge) def make_fakes(qcd_fraction): def make_fakes_view(weight_type, scale): scaled_bare_data = views.ScaleView(all_data_view, scale) scaled_wz_data = views.ScaleView(all_wz_view, scale) scaled_data = SubtractionView(scaled_bare_data, scaled_wz_data, restrict_positive=True) # View of weighted obj1-fails data obj1_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1p2p3/%s1' % (tau_charge, weight_type)) # View of weighted obj2-fails data obj2_view = views.SubdirectoryView( scaled_data, 'ss/%s/p1f2p3/%s2' % (tau_charge, weight_type)) # View of weighted obj1&2-fails data obj12_view = views.SubdirectoryView( scaled_data, 'ss/%s/f1f2p3/%s12' % (tau_charge, weight_type)) # Give the individual object views nice colors obj1_view = views.TitleView( views.StyleView(obj1_view, **remove_name_entry(data_styles['TT*'])), 'Reducible bkg. 1') obj2_view = views.TitleView( views.StyleView(obj2_view, **remove_name_entry(data_styles['QCD*'])), 'Reducible bkg. 2') obj12_view = views.TitleView( views.StyleView(obj12_view, **remove_name_entry(data_styles['WW*'])), 'Reducible bkg. 12') return obj1_view, obj2_view, obj12_view qcd1, qcd2, qcd12 = make_fakes_view('q', qcd_fraction) wjet1, wjet2, wjet12 = make_fakes_view( 'w', 1 - qcd_fraction) obj1_view = views.SumView(qcd1, wjet1) obj2_view = views.SumView(qcd2, wjet2) obj12_view = views.SumView(qcd12, wjet12) # Corrected fake view fakes_view = views.MultiFunctorView(fake_rate_estimate, obj1_view, obj2_view, obj12_view) fakes_view = views.TitleView( views.StyleView(fakes_view, **remove_name_entry(data_styles['Zjets*'])), 'Reducible bkg.') return obj1_view, obj2_view, obj12_view, fakes_view obj1_view, obj2_view, obj12_view, fakes_view = make_fakes(qcd_weight_fraction) fakes_view_05 = make_fakes(0.5)[-1] fakes_view_0 = make_fakes(0)[-1] fakes_view_1 = make_fakes(1)[-1] charge_fakes = views.TitleView( views.StyleView( views.SumView( views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c1' % other_tau_sign), #FIXME: needs to be fixed for charge 3 region create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c2' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), **remove_name_entry(data_styles['TT*'])), 'Charge mis-id') charge_fakes_sysup = views.TitleView( views.StyleView( views.SumView( views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c1_sysup' % other_tau_sign), create_mapper(self.obj1_charge_mapper) ), views.PathModifierView( views.SubdirectoryView(all_data_view, 'os/%s/p1p2p3/c2_sysup' % tau_charge), create_mapper(self.obj2_charge_mapper) ), ), **remove_name_entry(data_styles['TT*'])), 'Charge mis-id') #charge_fakes = MedianView(highv=charge_fakes_sysup, centv=charge_fakes) output = { 'wz': wz_view_tautau, 'wz_3l': wz_view_3l, 'zz': zz_view, 'data': data_view, 'obj1': obj1_view, 'obj2': obj2_view, 'obj12': obj12_view, 'fakes': fakes_view, 'weighted_fakes' : { 0. : fakes_view_0, 0.5 : fakes_view_05, 1. : fakes_view_1, }, 'charge_fakes': { 'central' : charge_fakes, 'sys_up' : charge_fakes_sysup, } } # Add signal data_total_lumi = self.views['data']['intlumi'] for mass in range(90, 165, 5): try: vh_base_name = 'VH_%s' % mass if self.sqrts == 7 else 'VH_H2Tau_M-%s' % mass vh_base_name = 'VHtautau_lepdecay_%s' % mass \ if 'VHtautau_lepdecay_%s' % mass in self.views else \ vh_base_name #print 'using %s' % vh_base_name vh_base_view = self.views[vh_base_name]['view'] vh_view = views.SubdirectoryView( vh_base_view, #self.get_view('VH_*%i' % mass), 'ss/%s/p1p2p3/' % tau_charge ) output['vh%i' % mass] = preprocess(vh_view) except KeyError: #logging.warning('No sample found matching VH_*%i' % mass) continue if mass % 10 == 0 and mass < 150: # Only have 10 GeV steps for WW try: ww_view = views.SubdirectoryView( self.get_view('VH_%i_HWW*' % mass), 'ss/%s/p1p2p3/' % tau_charge ) output['vh%i_hww' % mass] = preprocess(ww_view) except KeyError: #logging.warning('No sample found matching VH_%i_HWW*' % mass) continue #output['signal%i' % mass] = views.SumView(ww_view, vh_view) if ww_view else vh_view return output
#!/usr/bin/env python ''' Get fake systematic. ''' from rootpy import io import rootpy.plotting.views as views import sys the_filename = sys.argv[1] base_dirs = sys.argv[2].split(',') syst_name = sys.argv[3] the_file = io.open(the_filename, 'READ') nom_view = views.SumView( *[views.SubdirectoryView(the_file, dirname) for dirname in base_dirs]) qcd_view = views.SumView(*[ views.SubdirectoryView(the_file, dirname + '_q') for dirname in base_dirs ]) nom = nom_view.Get('fakes').Integral() qcd = qcd_view.Get('fakes').Integral() print "%s fakes %s %0.2f" % (','.join(base_dirs), syst_name, 1 + abs(nom - qcd) / nom)
return latex.DrawLatex(0.18, 0.97, label_text) vh_7TeV = io.open('VHTT/cmb/common/vhtt.input_7TeV.root') vh_8TeV = io.open('VHTT/cmb/common/vhtt.input_8TeV.root') vh_7TeV_pf = io.open('../HiggsAnalysis/HiggsToTauTau/test/root_postfit/vhtt.input_7TeV.root') vh_8TeV_pf = io.open('../HiggsAnalysis/HiggsToTauTau/test/root_postfit/vhtt.input_8TeV.root') # We only care about 7 + 8 TeV for pf_suffix, (vh7file, vh8file) in [('', (vh_7TeV, vh_8TeV)), ('_postfit', (vh_7TeV_pf, vh_8TeV_pf))]: vh_7and8 = views.SumView(vh7file, vh8file) for period, vh_combined in [('7+8', vh_7and8), ('7', vh7file), ('8', vh8file)]: # Now combine sub-channels llt_combined = views.SumView(*[ views.SubdirectoryView(vh_combined, x) for x in ['emt', 'mmt', ]]) zh_combined = views.SumView(*[ views.SubdirectoryView(vh_combined, x) for x in [ 'eeem_zh', 'eeet_zh', 'eemt_zh', 'eett_zh', 'mmme_zh', 'mmet_zh', 'mmmt_zh', 'mmtt_zh', ]]) # Make views of individual backgrounds channels = { 'llt' : {}, 'ltt' : {}, 'zh' : {}, # tau_h tau_h 'boost' : {},
categories = arguments tfile = io.open(tfile_name) logging.info("Opened file %s" % tfile_name) #get a directory and look into that keys = [i.GetName() for i in tfile.Get(categories[0]).GetListOfKeys() if not fnmatch(i.GetName(), options.nuisances)] if options.excluded: keys = [ i for i in keys if not fnmatch(i, options.excluded)] data = [i for i in keys if i.startswith('data')][0] keys = [i for i in keys if not i.startswith('data')] logging.debug("These shapes will be plotted: %s" % keys.__repr__()) input_view = views.SumView( *[ views.SubdirectoryView( tfile, category ) for category in categories] ) if options.differential == 1: input_view = DifferentialView( input_view ) histograms = [ apply_style(input_view.Get(i), i) for i in keys ] histograms = sorted(histograms, key=lambda x: x.Integral()) observed = apply_style(input_view.Get(data), data) logging.debug("debugging histos:") for histo in histograms: logging.debug(" %s: style: %s, integral: %.2f" % ( histo.GetTitle(), histo.drawstyle, histo.Integral() ) ) stack = plotting.HistStack()
from pdb import set_trace from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('input', help='input root file') parser.add_argument('out', help='output dir') args = parser.parse_args() tfile = root_open(args.input) plotter = BasePlotter( args.out, defaults={'save': { 'pdf': False }}, ) b_plots = views.StyleView(views.TitleView(views.SubdirectoryView(tfile, 'B'), 'B'), linewidth=2, linecolor='#2aa198', legendstyle='l', drawstyle='hist') c_plots = views.StyleView( views.TitleView(views.SubdirectoryView(tfile, 'C'), 'C'), linewidth=2, linecolor='#0055ff', legendstyle='l', drawstyle='hist', ) l_plots = views.StyleView(