|
| 1 | +''' |
| 2 | + This module creates the bias tests for each variable & |
| 3 | + channel (electron, muon, combined). |
| 4 | +''' |
| 5 | +from rootpy.io import File |
| 6 | + |
| 7 | +from config.variable_binning import bin_edges |
| 8 | +from tools.Unfolding import Unfolding, get_unfold_histogram_tuple |
| 9 | +from config.cross_section_config import XSectionConfig |
| 10 | +from tools.plotting import compare_measurements, Histogram_properties |
| 11 | +from config import latex_labels |
| 12 | + |
| 13 | + |
| 14 | +def main(): |
| 15 | + config = XSectionConfig(13) |
| 16 | +# method = 'RooUnfoldSvd' |
| 17 | + method = 'RooUnfoldBayes' |
| 18 | + file_for_data = File(config.unfolding_powheg_herwig, 'read') |
| 19 | + file_for_unfolding = File(config.unfolding_madgraphMLM, 'read') |
| 20 | + for channel in ['electron', 'muon', 'combined']: |
| 21 | + for variable in bin_edges.keys(): |
| 22 | + tau_value = get_tau_value(config, channel, variable) |
| 23 | + h_truth, h_measured, h_response, h_fakes = get_unfold_histogram_tuple( |
| 24 | + inputfile=file_for_unfolding, |
| 25 | + variable=variable, |
| 26 | + channel=channel, |
| 27 | + met_type=config.met_type, |
| 28 | + centre_of_mass=config.centre_of_mass_energy, |
| 29 | + ttbar_xsection=config.ttbar_xsection, |
| 30 | + luminosity=config.luminosity, |
| 31 | + load_fakes=False, |
| 32 | + visiblePS=False, |
| 33 | + ) |
| 34 | + h_data_model, h_data, _, _ = get_unfold_histogram_tuple( |
| 35 | + inputfile=file_for_data, |
| 36 | + variable=variable, |
| 37 | + channel=channel, |
| 38 | + met_type=config.met_type, |
| 39 | + centre_of_mass=config.centre_of_mass_energy, |
| 40 | + ttbar_xsection=config.ttbar_xsection, |
| 41 | + luminosity=config.luminosity, |
| 42 | + load_fakes=False, |
| 43 | + visiblePS=False, |
| 44 | + ) |
| 45 | + |
| 46 | + unfolding = Unfolding( |
| 47 | + h_truth, h_measured, h_response, h_fakes, |
| 48 | + method=method, k_value=-1, tau=tau_value) |
| 49 | + |
| 50 | + unfolded_data = unfolding.unfold(h_data) |
| 51 | + plot_bias(h_truth, h_data_model, unfolded_data, variable, channel, |
| 52 | + config.centre_of_mass_energy, method) |
| 53 | + |
| 54 | + |
| 55 | +def get_tau_value(config, channel, variable): |
| 56 | + if channel == 'electron': |
| 57 | + return config.tau_values_electron[variable] |
| 58 | + if channel == 'muon': |
| 59 | + return config.tau_values_muon[variable] |
| 60 | + if channel == 'combined': |
| 61 | + return config.tau_values_combined[variable] |
| 62 | + |
| 63 | + |
| 64 | +def plot_bias(h_unfold_model, h_data_model, unfolded_data, variable, |
| 65 | + channel, come, method): |
| 66 | + hp = Histogram_properties() |
| 67 | + hp.name = '{channel}_bias_test_for_{variable}_at_{come}TeV'.format( |
| 68 | + channel=channel, |
| 69 | + variable=variable, |
| 70 | + come=come, |
| 71 | + ) |
| 72 | + v_latex = latex_labels.variables_latex[variable] |
| 73 | + unit = '' |
| 74 | + if variable in ['HT', 'ST', 'MET', 'WPT']: |
| 75 | + unit = ' [GeV]' |
| 76 | + hp.x_axis_title = v_latex + unit |
| 77 | + hp.y_axis_title = 'Events' |
| 78 | + hp.title = 'Closure tests for {variable}'.format(variable=v_latex) |
| 79 | + |
| 80 | + output_folder = 'plots/unfolding/bias_test/{0}/'.format(method) |
| 81 | + |
| 82 | + compare_measurements(models={'MC truth': h_data_model, |
| 83 | + 'unfold model': h_unfold_model}, |
| 84 | + measurements={'unfolded reco': unfolded_data}, |
| 85 | + show_measurement_errors=True, |
| 86 | + histogram_properties=hp, |
| 87 | + save_folder=output_folder, |
| 88 | + save_as=['png', 'pdf']) |
| 89 | + |
| 90 | +if __name__ == '__main__': |
| 91 | + main() |
0 commit comments