def draw_regularisation_histograms( h_truth, h_measured, h_response, h_fakes = None, h_data = None ):
    global method, variable, output_folder, output_formats, test
    k_max = h_measured.nbins()
    unfolding = Unfolding( h_truth,
                           h_measured,
                           h_response,
                           h_fakes,
                           method = method,
                           k_value = k_max,
                           error_treatment = 4,
                           verbose = 1 )
    
    RMSerror, MeanResiduals, RMSresiduals, Chi2 = unfolding.test_regularisation ( h_data, k_max )

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'chi2_%s_channel_%s' % ( channel, variable )
    histogram_properties.title = '$\chi^2$ for $%s$ in %s channel, %s test' % ( variables_latex[variable], channel, test )
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = '$\chi^2$'
    histogram_properties.set_log_y = True
    make_plot(Chi2, 'chi2', histogram_properties, output_folder, output_formats, draw_errorbar = True, draw_legend = False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'RMS_error_%s_channel_%s' % ( channel, variable )
    histogram_properties.title = 'Mean error for $%s$ in %s channel, %s test' % ( variables_latex[variable], channel, test )
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'Mean error'
    make_plot(RMSerror, 'RMS', histogram_properties, output_folder, output_formats, draw_errorbar = True, draw_legend = False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'RMS_residuals_%s_channel_%s' % ( channel, variable )
    histogram_properties.title = 'RMS of residuals for $%s$ in %s channel, %s test' % ( variables_latex[variable], channel, test )
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'RMS of residuals'
    if test == 'closure':
        histogram_properties.set_log_y = True
    make_plot(RMSresiduals, 'RMSresiduals', histogram_properties, output_folder, output_formats, draw_errorbar = True, draw_legend = False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'mean_residuals_%s_channel_%s' % ( channel, variable )
    histogram_properties.title = 'Mean of residuals for $%s$ in %s channel, %s test' % ( variables_latex[variable], channel, test )
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'Mean of residuals'
    make_plot(MeanResiduals, 'MeanRes', histogram_properties, output_folder, output_formats, draw_errorbar = True, draw_legend = False)
def draw_regularisation_histograms(h_truth,
                                   h_measured,
                                   h_response,
                                   h_fakes=None,
                                   h_data=None):
    global method, variable, output_folder, output_formats, test
    k_max = h_measured.nbins()
    unfolding = Unfolding(h_truth,
                          h_measured,
                          h_response,
                          h_fakes,
                          method=method,
                          k_value=k_max,
                          error_treatment=4,
                          verbose=1)

    RMSerror, MeanResiduals, RMSresiduals, Chi2 = unfolding.test_regularisation(
        h_data, k_max)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'chi2_%s_channel_%s' % (channel, variable)
    histogram_properties.title = '$\chi^2$ for $%s$ in %s channel, %s test' % (
        variables_latex[variable], channel, test)
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = '$\chi^2$'
    histogram_properties.set_log_y = True
    make_plot(Chi2,
              'chi2',
              histogram_properties,
              output_folder,
              output_formats,
              draw_errorbar=True,
              draw_legend=False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'RMS_error_%s_channel_%s' % (channel, variable)
    histogram_properties.title = 'Mean error for $%s$ in %s channel, %s test' % (
        variables_latex[variable], channel, test)
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'Mean error'
    make_plot(RMSerror,
              'RMS',
              histogram_properties,
              output_folder,
              output_formats,
              draw_errorbar=True,
              draw_legend=False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'RMS_residuals_%s_channel_%s' % (channel,
                                                                 variable)
    histogram_properties.title = 'RMS of residuals for $%s$ in %s channel, %s test' % (
        variables_latex[variable], channel, test)
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'RMS of residuals'
    if test == 'closure':
        histogram_properties.set_log_y = True
    make_plot(RMSresiduals,
              'RMSresiduals',
              histogram_properties,
              output_folder,
              output_formats,
              draw_errorbar=True,
              draw_legend=False)

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'mean_residuals_%s_channel_%s' % (channel,
                                                                  variable)
    histogram_properties.title = 'Mean of residuals for $%s$ in %s channel, %s test' % (
        variables_latex[variable], channel, test)
    histogram_properties.x_axis_title = '$i$'
    histogram_properties.y_axis_title = 'Mean of residuals'
    make_plot(MeanResiduals,
              'MeanRes',
              histogram_properties,
              output_folder,
              output_formats,
              draw_errorbar=True,
              draw_legend=False)
def make_plots(channel = 'electron'):
    make_single_efficiency_plot(histograms['probe_passed_pt'], histograms['probe_total_pt'], 'probe_efficiency_pt', channel)
    make_single_efficiency_plot(histograms['probe_passed_eta'], histograms['probe_total_eta'], 'probe_efficiency_eta', channel)

    if channel == 'electron':
        title_channel = 'e+jets'
    else:
        title_channel = '$\mu$+jets'
    histogram_properties = Histogram_properties()
    histogram_properties.name = 'btag_multiplicity'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'N btags'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['btag_multiplicity'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'reco_leptons_multiplicity'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'N reco leptons'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_lepton_multiplicity'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'Z_mass_peak_reco'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Inv. mass 2 reco leptons'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_Z_peak'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'hlt_leptons_multiplicity'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'N HLT leptons'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_lepton_multiplicity'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'Z_mass_peak_hlt'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Inv. mass 2 HLT leptons'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_Z_peak'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'reco_signal_lepton_pt'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Reco signal lepton pt'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_signal_lepton_pt'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'reco_signal_lepton_eta'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Reco signal lepton eta'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_signal_lepton_eta'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'hlt_signal_lepton_pt'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'HLT signal lepton pt'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_signal_lepton_pt'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'hlt_signal_lepton_eta'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'HLT signal lepton eta'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_signal_lepton_eta'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'reco_probe_lepton_pt'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Reco probe lepton pt'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_probe_lepton_pt'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'reco_probe_lepton_eta'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'Reco probe lepton eta'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['reco_probe_lepton_eta'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'hlt_probe_lepton_pt'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'HLT probe lepton pt'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_probe_lepton_pt'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])

    histogram_properties = Histogram_properties()
    histogram_properties.name = 'hlt_probe_lepton_eta'
    histogram_properties.title = title_channel + ', CMS Preliminary, $\sqrt{s}$ = 7 TeV'
    histogram_properties.x_axis_title = 'HLT probe lepton eta'
    histogram_properties.y_axis_title = 'Events'
    make_plot(histograms['hlt_probe_lepton_eta'], 'data', histogram_properties, save_folder = output_folder, save_as = ['pdf'])
    
    # We want to store this variable in a histogram
    # 80 bins, from 0 to 400 (GeV)
    h_gen_met = Hist(80, 0, 400)
    # since we are planning to run over many events, let's cache the fill function
    fill = h_gen_met.Fill
    # ready to read all events
    n_processed_events = 0 
    stop_at = 10**5 # this is enough for this example
    for event in chain:
        gen_met = event.__getattr__("unfolding.genMET")
        fill(gen_met)
        n_processed_events += 1
        if (n_processed_events % 50000 == 0):
            print 'Processed', n_processed_events, 'events.'
        if n_processed_events >= stop_at:
            break
            
    print 'Processed', n_processed_events, 'events.'    
    # lets draw this histogram
    # define the style
    histogram_properties = Histogram_properties()
    histogram_properties.name = 'read_ntuples_gen_met' # it will be saved as that
    histogram_properties.title = 'My awesome MET plot'
    histogram_properties.x_axis_title = 'MET [GeV]'
    histogram_properties.y_axis_title = 'Events / 5 GeV'
    make_plot(h_gen_met, r'$t\bar{t}$', histogram_properties, 
              save_folder = 'examples/plots/', 
              save_as = ['png'])
    
Example #5
0
                fill2(gen_met[0])
        if len(muonq) > 0:
            if (musel) > 0:
                fill2(muonq[0])
                fill3(muonq[0])
        n_processed_events += 1
        if (n_processed_events % 50000 == 0):
            print 'Processed', n_processed_events, 'events.'
        #if n_processed_events >= stop_at:
        #break
    print 'Processed', n_processed_events, 'events.'
    histogram_properties = Histogram_properties()
    histogram_properties.name = 'electrons_charge'  # it will be saved as that
    histogram_properties.title = 'leptons q'
    histogram_properties.x_axis_title = 'q'
    histogram_properties.y_axis_title = 'Events'
    make_plot(h_gen_met,
              histogram_properties,
              save_folder='sb15165',
              save_as=['png'])
    histogram_properties.name = 'leptons_charge'
    make_plot(leptonCharge,
              histogram_properties,
              save_folder='sb15165',
              save_as=['png'])
    histogram_properties.name = 'muons_charge'
    make_plot(MuonCharge,
              histogram_properties,
              save_folder='sb15165',
              save_as=['png'])