Exemplo n.º 1
0
def _workflow(sample, jecv):
    _phs = []

    _add_cuts = [_ac['cut'] for _ac in _ADDITIONAL_CUTS]

    _SAMPLES = []
    for _ac in _ADDITIONAL_CUTS:
        _SAMPLES.append(deepcopy(sample))
        _SAMPLES[-1]['color'] = _ac['color']
        _SAMPLES[-1]['source_label'] = '{}'.format(_ac['label'])

    _ph = PlotHistograms1D(
        basename="control_plots_hist1d_17Nov2017",
        # there is one subplot per sample and cut in each plot
        samples=_SAMPLES,
        jec_correction_string=_CORR_FOLDER,
        additional_cuts=_add_cuts,
        # each quantity cut generates a different plot
        quantities=_QUANTITIES,
        # each selection cut generates a new plot
        selection_cuts=_SELECTION_CUTS,
        show_ratio_to_first=True,
        show_cut_info_text=False,
        plot_label="Fall17 JEC {}".format(jecv))

    _ph2 = PlotHistograms1D(
        basename="control_plots_hist1d_norm_17Nov2017",
        # there is one subplot per sample and cut in each plot
        samples=_SAMPLES,
        jec_correction_string=_CORR_FOLDER,
        additional_cuts=_add_cuts,
        # each quantity cut generates a different plot
        quantities=_QUANTITIES,
        # each selection cut generates a new plot
        selection_cuts=_SELECTION_CUTS,
        normalize_to_first=True,
        show_ratio_to_first=True,
        show_cut_info_text=False)

    for _plot in _ph._plots:
        pass

    #_phs.append(_ph)
    _phs.append(_ph2)

    for _ph in _phs:
        _ph.make_plots()
Exemplo n.º 2
0
def _workflow(sample_data, sample_mc, jecv):
    _phs = []

    #_add_cuts = [_ac['cut'] for _ac in RUN_PERIOD_CUT_DICTS]
    #_add_cuts.insert(0, None)

    _SAMPLES = []

    _SAMPLES.append(deepcopy(sample_mc))
    _SAMPLES[-1]['color'] = '#7293cb'  #'royalblue'
    _SAMPLES[-1]['marker'] = 'bar'
    _SAMPLES[-1]['step_flag'] = False
    _SAMPLES[-1]['source_label'] = sample_mc['source_label']

    _SAMPLES.append(deepcopy(sample_data))
    _SAMPLES[-1]['color'] = 'k'
    _SAMPLES[-1]['marker'] = '.'
    _SAMPLES[-1]['step_flag'] = False
    _SAMPLES[-1]['source_label'] = sample_data['source_label']

    #for _corr_level in ('L1L2L3', 'L1L2L3Res'):
    for _corr_level in ('L1L2L3', ):
        _ph = PlotHistograms1D(
            basename="data_mc_hist_allData_07Aug2017_JEC{}".format(jecv),
            # there is one subplot per sample and cut in each plot
            samples=_SAMPLES,
            jec_correction_string=_corr_level,
            additional_cuts=None,  #[None]*len(_SAMPLES),
            # each quantity cut generates a different plot
            quantities=_QUANTITIES,
            # each selection cut generates a new plot
            selection_cuts=_SELECTION_CUTS,
            normalize_to_first_histo=True,
            show_ratio_to_first=True,
            show_cut_info_text=True,
            show_corr_folder_text=False,
            plot_label="Run2016, 35.82 fb$^{-1}$ (13 TeV)",
            y_subplot_label="Data/MC",
            y_subplot_range=[0.78, 1.22],
        )
        _phs.append(_ph)

        # add cut labels as text
        for _p in _ph._plots:
            if _p._qs[0].name in ('zpt_400', 'jet1pt', 'jet2pt', 'jet3pt'):
                _p._basic_dict['y_log'] = True
            _p._basic_dict['formats'] = ['pdf', 'png']
            _p._basic_dict['texts'].extend(
                [r"$\\bf{CMS}$", r"$\\it{Preliminary}$"])
            _p._basic_dict['texts_size'].extend([25, 20])
            _p._basic_dict['texts_x'].extend([0.04, 0.04])
            _p._basic_dict['texts_y'].extend([0.94, 0.84])

    for _ph in _phs:
        _ph.make_plots()
def _workflow(sample):
    _phs = []
    for _run_period_cut_name, _run_period_cut in _run_period_cuts.iteritems():

        if _run_period_cut is None:
            _add_cuts = [_ac['cut'] for _ac in RUN_PERIOD_CUT_DICTS]
        else:
            _add_cuts = [(_ac['cut'] + _run_period_cut)
                         if _ac['cut'] is not None else _run_period_cut
                         for _ac in RUN_PERIOD_CUT_DICTS]

        _source_label = "{}".format(_run_period_cut_name)

        _SAMPLES = []
        for _ac in _ADDITIONAL_CUTS:
            _SAMPLES.append(deepcopy(sample))
            _SAMPLES[-1]['color'] = _ac['color']
            _SAMPLES[-1]['source_label'] = '{}, {}'.format(
                _source_label, _ac['label'])

        _ph = PlotHistograms1D(
            basename="adhoc_etaphiveto_jetpthist_07Aug2017_{}".format(
                _source_label),
            # there is one subplot per sample and cut in each plot
            samples=_SAMPLES,
            jec_correction_string=_CORR_FOLDER,
            additional_cuts=_add_cuts,
            # each quantity cut generates a different plot
            quantities=_QUANTITIES,
            # each selection cut generates a new plot
            selection_cuts=_SELECTION_CUTS,
            show_ratio_to_first=True,
            show_cut_info_text=False)
        _eta_range = _eta_ranges.get(_run_period_cut_name)
        _phi_range = _phi_ranges.get(_run_period_cut_name)
        for _plot in _ph._plots:
            if _plot._q.name.endswith('eta') and _eta_range is not None:
                _plot._basic_dict['vertical_lines'] = list(_eta_range)
            if _plot._q.name.endswith('phi') and _phi_range is not None:
                _plot._basic_dict['vertical_lines'] = list(_phi_range)

        _phs.append(_ph)

    for _ph in _phs:
        _ph.make_plots()
Exemplo n.º 4
0
def _workflow(sample_data, sample_mc, jecv):
    _phs = []

    _add_cuts = [_ac['cut'] for _ac in RUN_PERIOD_CUT_DICTS]

    _add_cuts.insert(0, None)

    _SAMPLES = []

    _SAMPLES.append(deepcopy(sample_mc))
    _SAMPLES[-1]['color'] = 'k'
    _SAMPLES[-1]['source_label'] = sample_mc['source_label']

    for _ac in RUN_PERIOD_CUT_DICTS:
        _SAMPLES.append(deepcopy(sample_data))
        _SAMPLES[-1]['color'] = _ac['color']
        _SAMPLES[-1]['source_label'] = '{}'.format(_ac['label'])

    #for _corr_level in ('L1L2L3', 'L1L2L3Res'):
    for _corr_level in ('L1L2L3', ):
        _ph = PlotHistograms1D(
            basename="pf_fractions_hist_07Aug2017_JEC{}".format(jecv),
            # there is one subplot per sample and cut in each plot
            samples=_SAMPLES,
            jec_correction_string=_corr_level,
            additional_cuts=_add_cuts,
            # each quantity cut generates a different plot
            quantities=_QUANTITIES,
            # each selection cut generates a new plot
            selection_cuts=_SELECTION_CUTS,
            normalize_to_first_histo=True,
            show_ratio_to_first=True,
            show_cut_info_text=False,
            plot_label="Summer16 JEC {}".format(jecv),
            y_log_scale=True)

        _phs.append(_ph)

        for _ph in _phs:
            _ph.make_plots()
Exemplo n.º 5
0
def _old_workflow(sample_data, sample_mc, jecv):
    _phs = []

    _add_cuts = [_ac['cut'] for _ac in RUN_PERIOD_CUT_DICTS]

    _add_cuts.insert(0, None)

    _SAMPLES = []

    _SAMPLES.append(deepcopy(sample_mc))
    _SAMPLES[-1]['color'] = 'k'
    _SAMPLES[-1]['source_label'] = sample_mc['source_label']

    for _ac in RUN_PERIOD_CUT_DICTS:
        _SAMPLES.append(deepcopy(sample_data))
        _SAMPLES[-1]['color'] = _ac['color']
        _SAMPLES[-1]['source_label'] = '{}'.format(_ac['label'])

    #for _corr_level in ('L1L2L3', 'L1L2L3Res'):
    for _corr_level in ('L1L2L3', 'L1L2Res'):
        _ph = PlotHistograms1D(
            basename="data_mc_hist_17Nov2017_JEC{}".format(jecv),
            # there is one subplot per sample and cut in each plot
            samples=_SAMPLES,
            jec_correction_string=_corr_level,
            additional_cuts=_add_cuts,
            # each quantity cut generates a different plot
            quantities=_QUANTITIES,
            # each selection cut generates a new plot
            selection_cuts=_SELECTION_CUTS,
            normalize_to_first=True,
            show_ratio_to_first=True,
            show_cut_info_text=False,
            plot_label="Fall17 JEC {}".format(jecv))
        #_phs.append(_ph)

        for _bin_cut in _ADDITIONAL_CUTS_ETA:
            break
            _ph2 = PlotHistograms1D(
                basename="data_mc_hist_etabins_17Nov2017_JEC{}".format(jecv),
                # there is one subplot per sample and cut in each plot
                samples=_SAMPLES,
                jec_correction_string=_corr_level,
                additional_cuts=_add_cuts,
                # each quantity cut generates a different plot
                quantities=_QUANTITIES,
                # each selection cut generates a new plot
                selection_cuts=[
                    _sel_cut + _bin_cut['cut'] for _sel_cut in _SELECTION_CUTS
                ],
                normalize_to_first=True,
                show_ratio_to_first=True,
                show_cut_info_text=False,
                plot_label="Fall17 JEC {}".format(jecv))
            _phs.append(_ph2)

        for _bin_cut in _ADDITIONAL_CUTS_ZPT:
            break
            _ph2 = PlotHistograms1D(
                basename="data_mc_hist_zptbins_17Nov2017_JEC{}".format(jecv),
                # there is one subplot per sample and cut in each plot
                samples=_SAMPLES,
                jec_correction_string=_corr_level,
                additional_cuts=_add_cuts,
                # each quantity cut generates a different plot
                quantities=_QUANTITIES,
                # each selection cut generates a new plot
                selection_cuts=[
                    _sel_cut + _bin_cut['cut'] for _sel_cut in _SELECTION_CUTS
                ],
                normalize_to_first=True,
                show_ratio_to_first=True,
                show_cut_info_text=False,
                plot_label="Fall17 JEC {}".format(jecv))
            _phs.append(_ph2)

        for _bin_cut_1 in _ADDITIONAL_CUTS_ETA[17:]:
            for _bin_cut_2 in _ADDITIONAL_CUTS_ZPT:
                break
                _ph2 = PlotHistograms1D(
                    basename="data_mc_hist_zptbins_17Nov2017_JEC{}".format(
                        jecv),
                    # there is one subplot per sample and cut in each plot
                    samples=_SAMPLES,
                    jec_correction_string=_corr_level,
                    additional_cuts=_add_cuts,
                    # each quantity cut generates a different plot
                    quantities=_QUANTITIES,
                    # each selection cut generates a new plot
                    selection_cuts=[
                        _sel_cut + _bin_cut_1['cut'] + _bin_cut_2['cut']
                        for _sel_cut in _SELECTION_CUTS
                    ],
                    normalize_to_first=True,
                    show_ratio_to_first=True,
                    show_cut_info_text=False,
                    plot_label="Fall17 JEC {}".format(jecv))
                _phs.append(_ph2)

        for _ph in _phs:
            _ph.make_plots()
Exemplo n.º 6
0
def _workflow(sample, which='hist1D'):
    _phs = []
    for _run_period_cut_name, _run_period_cut in _run_period_cuts.iteritems():

        if _run_period_cut is None:
            _add_cuts = [_ac['cut'] for _ac in RUN_PERIOD_CUT_DICTS]
        else:
            _add_cuts = [(_ac['cut'] + _run_period_cut)
                         if _ac['cut'] is not None else _run_period_cut
                         for _ac in RUN_PERIOD_CUT_DICTS]

        _source_label = "{}".format(_run_period_cut_name)

        _SAMPLES = []
        for _ac in _ADDITIONAL_CUTS:
            _SAMPLES.append(deepcopy(sample))
            _SAMPLES[-1]['color'] = _ac['color']
            _SAMPLES[-1]['source_label'] = '{}, {}'.format(
                _source_label, _ac['label'])

        if which == 'hist1D':
            _ph = PlotHistograms1D(
                basename="adhoc_etaphiveto_1D_07Aug2017_{}".format(
                    _source_label),
                # there is one subplot per sample and cut in each plot
                samples=_SAMPLES,
                jec_correction_string=_CORR_FOLDER,
                additional_cuts=_add_cuts,
                # each quantity cut generates a different plot
                quantities=_QUANTITIES,
                # each selection cut generates a new plot
                selection_cuts=_SELECTION_CUTS,
                show_ratio_to_first=True,
                show_cut_info_text=False)
            _eta_range = _hcal_hot_eta_ranges.get(_run_period_cut_name)
            _phi_range = _hcal_hot_phi_ranges.get(_run_period_cut_name)
            for _plot in _ph._plots:
                if _plot._q.name.endswith('eta') and _eta_range is not None:
                    _plot._basic_dict['vertical_lines'] = list(_eta_range)
                if _plot._q.name.endswith('phi') and _phi_range is not None:
                    _plot._basic_dict['vertical_lines'] = list(_phi_range)
                if _plot._q.name == 'zpt':
                    del _plot._basic_dict['x_lims']
                    _plot._basic_dict['x_bins'] = 'zpt'
                    _plot._basic_dict['x_log'] = True
            _phs.append(_ph)
        elif which == 'hist2D':
            for _ac in _add_cuts:
                _cutname = "all" if _ac is None else _ac.name
                _ph = PlotHistograms2D(
                    basename="adhoc_etaphiveto_2D_07Aug2017_{}_{}".format(
                        _cutname, _source_label),
                    # there is one subplot per sample and cut in each plot
                    samples=_SAMPLES,
                    jec_correction_string=_CORR_FOLDER,
                    additional_cuts=[_ac],
                    # each quantity cut generates a different plot
                    quantity_pairs=_QUANTITY_PAIRS,
                    # each selection cut generates a new plot
                    selection_cuts=_SELECTION_CUTS,
                    # show_ratio_to_first=True
                )
                _eta_range = _hcal_hot_eta_ranges.get(_run_period_cut_name)
                _phi_range = _hcal_hot_phi_ranges.get(_run_period_cut_name)
                for _plot in _ph._plots:
                    if (_plot._qy.name.endswith('eta')
                            or _plot._qy.name.endswith('eta_zoom')
                        ) and _eta_range is not None:
                        _plot._basic_dict['lines'] = list(_eta_range)
                    if (_plot._qx.name.endswith('phi')
                            or _plot._qx.name.endswith('phi_zoom')
                        ) and _phi_range is not None:
                        _plot._basic_dict['vertical_lines'] = list(_phi_range)
                _phs.append(_ph)
        elif which == 'profile':
            _ph = PlotHistograms2D(
                basename="adhoc_etaphiveto_profile_07Aug2017_{}".format(
                    _source_label),
                # there is one subplot per sample and cut in each plot
                samples=_SAMPLES,
                jec_correction_string=_CORR_FOLDER,
                additional_cuts=_add_cuts,
                # each quantity cut generates a different plot
                quantity_pairs=_QUANTITY_PAIRS_PROFILE,
                # each selection cut generates a new plot
                selection_cuts=_SELECTION_CUTS,
                #show_ratio_to_first=True,
                show_as_profile=True,
            )

            for _plot in _ph._plots:
                del _plot._basic_dict['y_bins']
                if _plot._qy.name == 'mpf' or _plot._qy.name == 'ptbalance':
                    _plot._basic_dict['y_lims'] = [0.8, 1.2]
                if _plot._qx.name == 'zpt':
                    del _plot._basic_dict['x_lims']
                    _plot._basic_dict['x_bins'] = 'zpt'
                    _plot._basic_dict['x_log'] = True

            _phs.append(_ph)
        else:
            raise ValueError("UNKNOWN 'which' = '{}'".format(which))

    for _ph in _phs:
        # for _plot in _ph._plots:
        #     print _plot.get_dict()
        #     import json
        #     with open('test.json', 'w') as f:
        #         json.dump(_plot.get_dict(), f)
        #     exit(44)
        _ph.make_plots()

        if which == 'hist1D':
            for _plot in _ph._plots:
                _plot.count_events(write_to_file=True)