def print_normalisation_table(config, channel, options, initial_normalisation, unfolded_normalisation): cols = 0 variable = options.variable # construct header data = [] n_data = ['data'] n_data.extend([int(v) for (v, _) in initial_normalisation['data']]) data.append(n_data) for sample in config.samples: if sample == 'TTJet': continue values = initial_normalisation[sample] values = [process_values(v) for v in values] cols = len(values) + 1 row = [sample] row.extend(values) data.append(row) data.append([''] * cols) headers = [variable] bins = variable_bins_latex[variable] if options.visiblePS: bins = variable_bins_visiblePS_latex[variable] headers.extend(bins.itervalues()) # replace with bins measured = ['\\ttbar event yield'] measured.extend([process_values(v) for v in unfolded_normalisation['TTJet_measured']]) mc_pred = ['MC prediction'] mc_pred.extend([process_values(v) for v in initial_normalisation['TTJet']]) data.append(measured) data.append(mc_pred) data.append([''] * cols) unfolded = ['\\ttbar event yield'] unfolded.extend([process_values(v) for v in unfolded_normalisation['TTJet_unfolded']]) mc_pred = ['MC prediction'] mc_pred.extend([process_values(v) for v in unfolded_normalisation['POWHEG_HERWIG']]) data.append(unfolded) data.append(mc_pred) table = PrintTable(data, headers) print table.latex()
def print_normalisation_table(config, channel, options, initial_normalisation, unfolded_normalisation): cols = 0 variable = options.variable # construct header data = [] n_data = ['data'] n_data.extend([int(v) for (v, _) in initial_normalisation['data']]) data.append(n_data) for sample in config.samples: if sample == 'TTJet': continue values = initial_normalisation[sample] values = [process_values(v) for v in values] cols = len(values) + 1 row = [sample] row.extend(values) data.append(row) data.append([''] * cols) headers = [variable] bins = variable_bins_latex[variable] if options.visiblePS: bins = variable_bins_visiblePS_latex[variable] headers.extend(bins.itervalues()) # replace with bins measured = ['\\ttbar event yield'] measured.extend( [process_values(v) for v in unfolded_normalisation['TTJet_measured']]) mc_pred = ['MC prediction'] mc_pred.extend([process_values(v) for v in initial_normalisation['TTJet']]) data.append(measured) data.append(mc_pred) data.append([''] * cols) unfolded = ['\\ttbar event yield'] unfolded.extend( [process_values(v) for v in unfolded_normalisation['TTJet_unfolded']]) mc_pred = ['MC prediction'] mc_pred.extend( [process_values(v) for v in unfolded_normalisation['POWHEG_HERWIG']]) data.append(unfolded) data.append(mc_pred) table = PrintTable(data, headers) print table.latex()
def table(result_dict, use_current_k_values = False, style = 'simple'): ''' result_dict has the form { centre-of-mass energy : { variable : { channel : (k_results, tau_results) } } } <reg>_results are of the form: best_<reg>, best_<reg>_rho, <reg>s, rhos ''' for com in result_dict.keys(): # step 1: group the results by centre of mass energy headers = [] if use_current_k_values: headers = ['Variable', 'current k', 'closest tau', 'best tau', 'best k'] else: headers = ['Variable', 'best k', 'rho (best k)', 'best tau', 'rho (best tau)'] data = [] measurement_config = XSectionConfig(com) for variable in result_dict[com].keys(): has_both_channels = len(result_dict[com][variable]) == 2 # step 2: if have electron and muon channel, group them: electron (muon) if has_both_channels: electron_results = result_dict[com][variable]['electron'] muon_results = result_dict[com][variable]['muon'] entry = [] if use_current_k_values: electron_set = get_k_tau_set(measurement_config, 'electron', variable, electron_results) muon_set = get_k_tau_set(measurement_config, 'muon', variable, muon_results) entry = [variable, '%d (%d)' % (electron_set[0], muon_set[0]), '%.1f (%.1f)' % (electron_set[1], muon_set[1]), '%.1f (%.1f)' % (electron_set[2], muon_set[2]), '%d (%d)' % (electron_set[3], muon_set[3]), ] else: entry = [variable, '%d (%d)' % (electron_results[0][0], muon_results[0][0]), '%.1f (%.1f)' % (electron_results[0][1], muon_results[0][1]), '%.1f (%.1f)' % (electron_results[1][0], muon_results[1][0]), '%.1f (%.1f)' % (electron_results[1][1], muon_results[1][1]), ] data.append(entry) else: channel = result_dict[com][variable].keys()[0] results = result_dict[com][variable][channel] if use_current_k_values: result_set = get_k_tau_set(measurement_config, channel, variable, results) entry = [variable, '%d' % result_set[0], '%.1f' % result_set[1], '%.1f' % result_set[2], '%d' % result_set[3], ] else: entry = [variable, '%d' % results[0][0], '%.1f' % results[0][1], '%.1f' % results[1][0], '%.1f' % results[1][1], ] data.append(entry) table = PrintTable(data, headers) print 'Printing table for sqrt(s) = %d TeV' % com if style == 'simple': print table.simple() elif style == 'latex': print table.latex() elif style == 'twiki': print table.twiki() else: print 'unknown printing style "%s"' % style
def table(result_dict, use_current_k_values=False, style='simple'): ''' result_dict has the form { centre-of-mass energy : { variable : { channel : (k_results, tau_results) } } } <reg>_results are of the form: best_<reg>, best_<reg>_rho, <reg>s, rhos ''' for com in result_dict.keys(): # step 1: group the results by centre of mass energy headers = [] if use_current_k_values: headers = [ 'Variable', 'current k', 'closest tau', 'best tau', 'best k' ] else: headers = [ 'Variable', 'best k', 'rho (best k)', 'best tau', 'rho (best tau)' ] data = [] configOutputElectron = {} configOutputMuon = {} configOutputCombined = {} measurement_config = XSectionConfig(com) for variable in result_dict[com].keys(): has_both_channels = len(result_dict[com][variable]) == 3 # step 2: if have electron and muon channel, group them: electron (muon) if has_both_channels: electron_results = result_dict[com][variable]['electron'] muon_results = result_dict[com][variable]['muon'] combined_results = result_dict[com][variable]['combined'] configOutputElectron[variable] = electron_results[1][0] configOutputMuon[variable] = muon_results[1][0] configOutputCombined[variable] = combined_results[1][0] entry = [] if use_current_k_values: electron_set = get_k_tau_set(measurement_config, 'electron', variable, electron_results) muon_set = get_k_tau_set(measurement_config, 'muon', variable, muon_results) combined_set = get_k_tau_set(measurement_config, 'combined', variable, combined_results) entry = [ variable, '%d (%d)' % (electron_set[0], muon_set[0], combined_set[0]), '%.1f (%.1f)' % (electron_set[1], muon_set[1], combined_set[1]), '%.1f (%.1f)' % (electron_set[2], muon_set[2], combined_set[2]), '%d (%d)' % (electron_set[3], muon_set[3], combined_set[3]), ] else: entry = [ variable, '%d %d %d' % (electron_results[0][0], muon_results[0][0], combined_results[0][0]), '%.1f %.1f %.1f' % (electron_results[0][1], muon_results[0][1], combined_results[0][1]), '%.1f %.1f %.1f' % (electron_results[1][0], muon_results[1][0], combined_results[1][0]), '%.1f %.1f %.1f' % (electron_results[1][1], muon_results[1][1], combined_results[1][1]), ] data.append(entry) else: channel = result_dict[com][variable].keys()[0] results = result_dict[com][variable][channel] print channel if channel == 'electron': configOutputElectron[variable] = results[1][0] elif channel == 'muon': configOutputMuon[variable] = results[1][0] else: configOutputCombined[variable] = results[1][0] if use_current_k_values: result_set = get_k_tau_set(measurement_config, channel, variable, results) entry = [ variable, '%d' % result_set[0], '%.1f' % result_set[1], '%.1f' % result_set[2], '%d' % result_set[3], ] else: entry = [ variable, '%d' % results[0][0], '%.1f' % results[0][1], '%.1f' % results[1][0], '%.1f' % results[1][1], ] data.append(entry) print '\nOutput for __init__\n' print configOutputElectron print configOutputMuon print configOutputCombined print 'Electron' for var in configOutputElectron: print '"%s" : %s,' % (var, configOutputElectron[var]) print '\n' print 'Muon' for var in configOutputMuon: print '"%s" : %s,' % (var, configOutputMuon[var]) print '\n' print 'Combined' for var in configOutputCombined: print '"%s" : %s,' % (var, configOutputCombined[var]) print '\n' table = PrintTable(data, headers) print 'Printing table for sqrt(s) = %d TeV' % com if style == 'simple': print table.simple() elif style == 'latex': print table.latex() elif style == 'twiki': print table.twiki() else: print 'unknown printing style "%s"' % style