<commit_before># Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from . import log; log = log[__name__]
from . import MIN_ROOT_VERSION
from ...memory.keepalive import keepalive
from ...core import NamedObject
from ... import asrootpy, QROOT, stl, ROOT_VERSION
import ROOT

if ROOT_VERSION < MIN_ROOT_VERSION:
    raise NotImplementedError(
        "histfactory requires ROOT {0} but you are using {1}".format(
            MIN_ROOT_VERSION, ROOT_VERSION))

__all__ = [
    'Data',
    'Sample',
    'HistoSys',
    'HistoFactor',
    'NormFactor',
    'OverallSys',
    'ShapeFactor',
    'ShapeSys',
    'Channel',
    'Measurement',
]

# generate required dictionaries
stl.vector('RooStats::HistFactory::HistoSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::HistoFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::NormFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::OverallSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::ShapeFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::ShapeSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::Sample')
stl.vector('RooStats::HistFactory::Data')
stl.vector('RooStats::HistFactory::Channel')


class _Named(object):

    @property
    def name(self):
        return self.GetName()

    @name.setter
    def name(self, n):
        self.SetName(n)


class _NamePathFile(object):

    @property
    def histname(self):
        return self.GetHistoName()

    @histname.setter
    def histname(self, name):
        self.SetHistoName(name)

    @property
    def path(self):
        return self.GetHistoPath()

    @path.setter
    def path(self, path):
        self.SetHistoPath(path)

    @property
    def file(self):
        return self.GetInputFile()

    @file.setter
    def file(self, infile):
        self.SetInputFile(infile)


class _SampleBase(_Named, _NamePathFile):

    def SetHisto(self, hist):
        super(_SampleBase, self).SetHisto(hist)
        keepalive(self, hist)

    def GetHisto(self):
        return asrootpy(super(_SampleBase, self).GetHisto())

    @property
    def hist(self):
        return self.GetHisto()

    @hist.setter
    def hist(self, h):
        self.SetHisto(h)

    def __add__(self, other):
        if self.name != other.name:
            raise ValueError('attempting to add samples with different names')
        hist1 = self.GetHisto()
        hist2 = other.GetHisto()
        hist3 = hist1 + hist2
        hist3.name = '%s_plus_%s' % (hist1.name, hist2.name)
        sample = self.__class__(self.name)
        sample.SetHisto(hist3)
        return sample


class Data(_SampleBase, QROOT.RooStats.HistFactory.Data):

    def __init__(self, name):
        # require a name
        super(Data, self).__init__()
        self.name = name


class Sample(_SampleBase, QROOT.RooStats.HistFactory.Sample):

    def __init__(self, name):
        # require a sample name
        super(Sample, self).__init__(name)

    def __add__(self, other):
        sample = super(Sample, self).__add__(other)

        if self.GetHistoFactorList() or other.GetHistoFactorList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain HistoFactors')

        if self.GetShapeFactorList() or other.GetShapeFactorList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain ShapeFactors')

        if self.GetShapeSysList() or other.GetShapeSysList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain ShapeSys')

        # sum the histosys
        syslist1 = self.GetHistoSysList()
        syslist2 = other.GetHistoSysList()
        if len(syslist1) != len(syslist2):
            raise ValueError(
                'attempting to sum Samples with HistoSys lists of '
                'differing lengths')
        for sys1, sys2 in zip(syslist1, syslist2):
            sample.AddHistoSys(sys1 + sys2)

        # include the overallsys
        overall1 = self.GetOverallSysList()
        overall2 = other.GetOverallSysList()
        if len(overall1) != len(overall2):
            raise ValueError(
                'attempting to sum Samples with OverallSys lists of '
                'differing lengths')<commit_msg>transfer NormalizeByTheory setting when summing histfactory samples<commit_after># Copyright 2012 the rootpy developers
# distributed under the terms of the GNU General Public License
from . import log; log = log[__name__]
from . import MIN_ROOT_VERSION
from ...memory.keepalive import keepalive
from ...core import NamedObject
from ... import asrootpy, QROOT, stl, ROOT_VERSION
import ROOT

if ROOT_VERSION < MIN_ROOT_VERSION:
    raise NotImplementedError(
        "histfactory requires ROOT {0} but you are using {1}".format(
            MIN_ROOT_VERSION, ROOT_VERSION))

__all__ = [
    'Data',
    'Sample',
    'HistoSys',
    'HistoFactor',
    'NormFactor',
    'OverallSys',
    'ShapeFactor',
    'ShapeSys',
    'Channel',
    'Measurement',
]

# generate required dictionaries
stl.vector('RooStats::HistFactory::HistoSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::HistoFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::NormFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::OverallSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::ShapeFactor',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::ShapeSys',
           headers='<vector>;<RooStats/HistFactory/Systematics.h>')
stl.vector('RooStats::HistFactory::Sample')
stl.vector('RooStats::HistFactory::Data')
stl.vector('RooStats::HistFactory::Channel')


class _Named(object):

    @property
    def name(self):
        return self.GetName()

    @name.setter
    def name(self, n):
        self.SetName(n)


class _NamePathFile(object):

    @property
    def histname(self):
        return self.GetHistoName()

    @histname.setter
    def histname(self, name):
        self.SetHistoName(name)

    @property
    def path(self):
        return self.GetHistoPath()

    @path.setter
    def path(self, path):
        self.SetHistoPath(path)

    @property
    def file(self):
        return self.GetInputFile()

    @file.setter
    def file(self, infile):
        self.SetInputFile(infile)


class _SampleBase(_Named, _NamePathFile):

    def SetHisto(self, hist):
        super(_SampleBase, self).SetHisto(hist)
        keepalive(self, hist)

    def GetHisto(self):
        return asrootpy(super(_SampleBase, self).GetHisto())

    @property
    def hist(self):
        return self.GetHisto()

    @hist.setter
    def hist(self, h):
        self.SetHisto(h)

    def __add__(self, other):
        if self.name != other.name:
            raise ValueError('attempting to add samples with different names')
        hist1 = self.GetHisto()
        hist2 = other.GetHisto()
        hist3 = hist1 + hist2
        hist3.name = '%s_plus_%s' % (hist1.name, hist2.name)
        sample = self.__class__(self.name)
        sample.SetHisto(hist3)
        return sample


class Data(_SampleBase, QROOT.RooStats.HistFactory.Data):

    def __init__(self, name):
        # require a name
        super(Data, self).__init__()
        self.name = name


class Sample(_SampleBase, QROOT.RooStats.HistFactory.Sample):

    def __init__(self, name):
        # require a sample name
        super(Sample, self).__init__(name)

    def __add__(self, other):

        if self.GetHistoFactorList() or other.GetHistoFactorList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain HistoFactors')

        if self.GetShapeFactorList() or other.GetShapeFactorList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain ShapeFactors')

        if self.GetShapeSysList() or other.GetShapeSysList():
            raise NotImplementedError(
                'Samples cannot be summed if they contain ShapeSys')

        if self.GetNormalizeByTheory() != other.GetNormalizeByTheory():
            raise ValueError(
                'attempting to sum samples with inconsistent NormalizeByTheory')

        sample = super(Sample, self).__add__(other)
        sample.SetNormalizeByTheory(self.GetNormalizeByTheory())

        # sum the histosys
        syslist1 = self.GetHistoSysList()
        syslist2 = other.GetHistoSysList()
        if len(syslist1) != len(syslist2):
            raise ValueError(
                'attempting to sum Samples with HistoSys lists of '
                'differing lengths')
        for sys1, sys2 in zip(syslist1, syslist2):
            sample.AddHistoSys(sys1 + sys2)

        # include the overallsys
        overall1 = self.GetOverallSysList()
        overall2 = other.GetOverallSysList()
        if len(overall1) != len(overall2):
            raise ValueError(
                'attempting to sum Samples with OverallSys lists of '
                'differing lengths')
{'fraction_non_alphanumeric': 0.11033109807208717, 'fraction_numerical': 0.006077116512992456, 'mean_word_length': 2.8472390165255943, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3815907', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2851, 'n_words': 642}