Beispiel #1
0
    def __add__(self, other):

        assert self == other, "The bins are not equal"

        if self._is_poisson:

            assert other.is_poisson, 'Trying to add a Poisson and non-poisson histogram together'

            new_errors = None

        else:

            assert not other.is_poisson, 'Trying to add a Poisson and non-poisson histogram together'

            if self._errors is not None:

                assert other.errors is not None, "This histogram has errors, but the other does not"

                new_errors = np.array([ sqrt_sum_of_squares([e1,e2]) for e1,e2 in zip(self._errors,other.errors)])

            else:

                new_errors = None

        if self._sys_errors is not None and other.sys_errors is not None:

            new_sys_errors = np.array([ sqrt_sum_of_squares([e1,e2]) for e1,e2 in zip(self._sys_errors,other.sys_errors)])

        elif self._sys_errors is not None:

            new_sys_errors = self._sys_errors

        elif other.sys_errors is not None:

            new_sys_errors = other.sys_errors

        else:

            new_sys_errors = None

        new_contents = self.contents + other.contents


        # because Hist gets inherited very deeply, when we add we will not know exactly
        # what all the additional class members will be, so we will make a copy of the class
        # This is not ideal and there is probably a better way to do this
        # TODO: better new hist constructor


        new_hist = copy.deepcopy(self)

        new_hist._contents = new_contents
        new_hist._errors = new_errors
        new_hist._sys_errors = new_sys_errors

        return new_hist
Beispiel #2
0
    def total_rate_error(self):
        """
        :return: total rate error
        """
        assert self.is_poisson == False, "Cannot request errors on rates for a Poisson spectrum"

        return sqrt_sum_of_squares(self._errors)
Beispiel #3
0
    def total_rate_error(self):
        """
        :return: total rate error
        """
        assert self.is_poisson == False, "Cannot request errors on rates for a Poisson spectrum"

        return sqrt_sum_of_squares(self._errors)
Beispiel #4
0
    def total_count_error(self):
        """
        :return: total count error
        """

        #VS: impact of this change is unclear to me, it seems to make sense and the tests pass
        if self.is_poisson:
            return None
        else:
            return sqrt_sum_of_squares(self.count_errors)
Beispiel #5
0
 def total_count_error(self):
     """
     :return: total count error
     """
     
     #VS: impact of this change is unclear to me, it seems to make sense and the tests pass
     if self.is_poisson:
         return None
     else:
         return sqrt_sum_of_squares(self.count_errors)
    def total_rate_error(self) -> float:
        """
        :return: total rate error
        """

        if self.is_poisson:
            log.error("Cannot request errors on rates for a Poisson spectrum")

            raise RuntimeError()

        return sqrt_sum_of_squares(self._errors)
Beispiel #7
0
    def total_error(self):

        return sqrt_sum_of_squares(self._errors)