Exemple #1
0
    def initialize(self):
        """Initialize the link."""
        # check input arguments
        self.check_arg_types(pages_key=str)

        if isinstance(self.copy_into_ws, str):
            self.copy_into_ws = [self.copy_into_ws]
        assert isinstance(
            self.copy_into_ws,
            list), 'copy_into_ws needs to be a string or list of strings.'

        if isinstance(self.copy_into_ds, str):
            self.copy_into_ds = [self.copy_into_ds]
        assert isinstance(
            self.copy_into_ds,
            list), 'copy_into_ds needs to be a string or list of strings.'

        # read report templates
        with open(resources.template('df_summary_report.tex')) as templ_file:
            self.report_template = templ_file.read()
        with open(resources.template(
                'df_summary_report_page.tex')) as templ_file:
            self.page_template = templ_file.read()
        with open(
                resources.template('df_summary_table_page.tex')) as templ_file:
            self.table_template = templ_file.read()

        self._process_results_path()

        # make sure Eskapade RooFit library is loaded for fitting (for plotting correlation matrix)
        if self._fit:
            roofit_utils.load_libesroofit()

        return StatusCode.Success
    def initialize(self):
        """Initialize the link.."""
        # check input arguments
        self.check_arg_types(read_key=str, binning_name=str, default_number_of_bins=int)
        self.check_arg_types(recurse=True, allow_none=False, columns=str)
        self.check_arg_vals('read_key', 'binning_name', 'var_number_of_bins')

        # make sure Eskapade RooFit library is loaded for the RooNonCentralBinning class
        roofit_utils.load_libesroofit()

        return StatusCode.Success
Exemple #3
0
    def __init__(self, ws, name='', load_libesroofit=False):
        """Initialize model instance.

        :param ROOT.RooWorkspace ws: RooFit workspace
        :param str name: name of model
        :param bool load_libesroofit: load Eskapade RooFit library upon initialization (default is False)
        """
        # check workspace
        if not isinstance(ws, ROOT.RooWorkspace):
            raise TypeError('invalid workspace specified (type "{}")'.format(
                ws.__class__.__name__))

        # set attributes
        self._name = str(name) if name else self.__class__.__name__
        self._ws = ws
        self._is_built = False
        self._pdf_name = None

        if load_libesroofit:
            # load Eskapade RooFit library
            roofit_utils.load_libesroofit()
    def test_load_libesroofit(self, mock_objects, mock_load,
                              mock_get_libraries):
        """Test loading Eskapade RooFit library"""

        # set custom object attributes
        ROOT.MyCustomClass = mock.Mock(name='MyCustomClass')
        ROOT.MyCustomNamespace = mock.Mock(name='MyCustomNamespace')

        # the Eskapade RooFit library name
        esroofit_lib_base = 'libesroofit'
        if sys.platform == 'darwin':
            esroofit_lib_ext = '.dylib'
        else:
            esroofit_lib_ext = '.so'
        esroofit_lib_name = esroofit_lib_base + esroofit_lib_ext

        # test normal build/load
        mock_objects.__iter__ = lambda s: iter(
            ('MyCustomClass', ('MyCustomNamespace', 'MyCustomFunction')))
        mock_load.return_value = 0
        mock_get_libraries.return_value = 'lib/libmylib.so'
        load_libesroofit()
        mock_load.assert_called_once_with(resources.lib(esroofit_lib_name))
        mock_load.reset_mock()

        # test with loaded library
        mock_get_libraries.return_value = 'lib/libmylib.so lib/{}'.format(
            esroofit_lib_name)
        load_libesroofit()
        mock_load.assert_not_called()
        mock_get_libraries.return_value = 'lib/libmylib.so'
        mock_load.reset_mock()

        # test failed load
        mock_load.return_value = -1
        with self.assertRaises(RuntimeError):
            load_libesroofit()
        mock_load.return_value = 0
        mock_load.reset_mock()

        # test missing custom class
        mock_objects.__iter__ = lambda s: iter(('NoSuchClass', ))
        with self.assertRaises(RuntimeError):
            load_libesroofit()

        # delete custom class attribute
        del ROOT.MyCustomClass
Exemple #5
0
modification, are permitted according to the terms listed in the file
LICENSE.
"""

import ROOT
from ROOT import RooFit

from eskapade import ConfigObject, Chain, process_manager
from eskapade import core_ops
from eskapade.logger import Logger

from esroofit import roofit_utils
from esroofit.links import WsUtils, PrintWs

# make sure Eskapade RooFit library is loaded
roofit_utils.load_libesroofit()

logger = Logger()

logger.debug(
    'Now parsing configuration file esk407_classification_unbiased_fit_estimate'
)

#########################################################################################
# --- minimal analysis information

settings = process_manager.service(ConfigObject)
settings['analysisName'] = 'esk407_classification_unbiased_fit_estimate'
settings['version'] = 0

#########################################################################################
    def initialize(self):
        """Initialize the link."""
        # check input arguments
        self.check_arg_types(read_key=str, significance_key=str, sk_significance_map=str, sk_residuals_map=str,
                             sk_residuals_overview=str, default_number_of_bins=int, nsims_per_significance=int,
                             prefix=str, var_binning=dict,
                             z_threshold=float, pages_key=str, client_pages_key=str, hist_dict_key=str, var_binning_key=str)
        self.check_arg_types(recurse=True, allow_none=True, columns=str)
        self.check_arg_types(recurse=True, allow_none=True, x_columns=str)
        self.check_arg_types(recurse=True, allow_none=True, y_columns=str)
        self.check_arg_types(recurse=True, allow_none=True, ignore_categories=str)
        self.check_arg_types(recurse=True, allow_none=True, accept_categories=str)
        self.check_arg_types(recurse=True, allow_none=True, ignore_values=float)
        self.check_arg_vals('read_key')
        self.check_arg_vals('significance_key')

        if self.map_to_original and not isinstance(self.map_to_original, str) \
                and not isinstance(self.map_to_original, dict):
            raise TypeError('map_to_original needs to be a dict or string (to fetch a dict from the datastore)')

        # read report templates
        with open(resources.template('df_summary_report.tex')) as templ_file:
            self.report_template = templ_file.read()
        with open(resources.template('df_summary_report_page.tex')) as templ_file:
            self.page_template = templ_file.read()
        with open(resources.template('df_summary_table_page.tex')) as templ_file:
            self.table_template = templ_file.read()

        self._process_results_path()
        self._process_prefix()

        # check provided columns
        if self.columns:
            assert not self.x_columns and not self.y_columns, 'Set either columns OR x_columns and y_columns.'
        if self.x_columns:
            assert not self.columns and self.y_columns, 'Set either columns OR x_columns and y_columns.'

        # check that var_ignore_categories are set correctly.
        for col, ic in self.var_ignore_categories.items():
            if isinstance(ic, str):
                self.var_ignore_categories[col] = [ic]
            elif not isinstance(ic, list):
                raise TypeError('var_ignore_categories key "{}" needs to be a string or list of strings'.format(col))

        # check that var_accept_categories are set correctly.
        for col, ic in self.var_accept_categories.items():
            if isinstance(ic, str):
                self.var_accept_categories[col] = [ic]
            elif not isinstance(ic, list):
                raise TypeError('var_accept_categories key "{}" needs to be a string or list of strings'.format(col))

        # check that var_ignore_values are set correctly.
        for col, iv in self.var_ignore_values.items():
            if isinstance(iv, float):
                self.var_ignore_values[col] = [iv]
            elif not isinstance(iv, list):
                raise TypeError('var_ignore_values key "{}" needs to be a float or list of floats'.format(col))

        # load roofit classes
        roofit_utils.load_libesroofit()

        return StatusCode.Success