Пример #1
0
    def __isub__(self, other):
        """self -= b
        b is a pair of numbers (x, xerr_square) or another histogram
        """
        data = self._data; errs = self._errors
        
        if isNumberPair(other) and self.isunitless():
            
            x, xerr = other
            data -= x; errs += xerr

            pass

        elif isDimensionalPair(other):

            x, xerr = other
            data -= x; errs += xerr

            pass
        
        elif isHistogram(other):
            
            data -=  other._data; errs +=  other._errors 

        else:
            
            raise NotImplementedError , "__sub__ is not defined for %s and %s" % (
                self.__class__.__name__, other.__class__.__name__, )
        
        return self
Пример #2
0
    def __rdiv__(self, other):
        if isNumberPair(other):
            r = self.copy()
            r.reverse()
            r *= other
            return r

        raise NotImplementedError , "__rdiv__ is not defined for %s and %s" % (
            other.__class__.__name__, self.__class__.__name__, )
Пример #3
0
    def __idiv__(self, other):
        """self /= b
        b is a pair of numbers (x, xerr_square) or another histogram
        """
        data = self._data; errs = self._errors
        # sigmaA**2/B**2 + A**2*sigmaB**2/B**4
        
        if isNumberPair(other):
            y,  dy2 = other
            y, dy2 = float(y), float(dy2)
            if dy2 == 0 or dy2 == 0.0: #special case
                #ydx/y^2
                self._setunit(1.*self.unit()/y)
                return self

            errs /= y*y
            errs += dy2 * data * data / y**4
            
            data /= y
            pass
        
        elif isDimensionalPair(other):
            y, dy2 = other
            unitlessother = 1, dy2/y/y
            self._setunit( 1.*self.unit()/y )
            self /= unitlessother
            pass
        
        elif isHistogram(other):

            y = other._data; dy2 = other._errors
            
            if dy2 == None: #special case
                #ydx/y^2
                errs /= y; errs /= y
                data /= y
                return self

            errs /= y*y
            errs += dy2 * data * data /y/y/y/y
            
            data /= y

            self._setunit( self.unit()/other.unit() )
            
        else:
            
            raise NotImplementedError , "__div__ is not defined for %s and %s. "\
                  "self=%s, other=%s" % (
                self.__class__.__name__, other.__class__.__name__,
                self, other)

        self._syncUnit()
        return self
Пример #4
0
    def __iadd__(self, other):
        """self += b
        b is a pair of numbers (x, xerr_square) or another histogram
        """
        data = self._data; errs = self._errors
        
        if isNumberPair(other) and self.isunitless():
            
            x, xerr = other
            data += x
            errs += xerr

            pass

        elif isDimensionalPair( other ):

            x, xerr = other
            data += x
            errs += xerr

            pass
        
        elif isHistogram(other):
            
            data +=  other._data;
            if errs is None:
                if other._errors is not None: 
                    self._dataCont.replaceDataset("error", other._errors.copy() )
                    pass
                pass
            else:
                errs +=  other._errors
                pass
            pass
        
        else:
            
            raise NotImplementedError , "__add__ is not defined for %s and %s" % (
                self.__class__.__name__, other.__class__.__name__, )
        
        return self
Пример #5
0
    def __imul__(self, other):
        """self *= b
        b is a pair of numbers (x, xerr_square) or another histogram
        """
        data = self._data; errs = self._errors
        
        if isNumberPair(other) or isDimensionalPair(other):
            
            y, dy2 = other
            y, dy2 = float(y), float(dy2)

            #B**2*sigmaA**2 + A**2*sigmaB**2
            #term2 = dy2 * data * data
            #term1 = errs * y * y
            errs *= y*y
            errs += dy2*data*data
            
            data *= y
            pass

        
        elif isHistogram(other):
            y = other.data(); dy2 = other.errors()
            #
            errs *= y*y
            errs += dy2 * data*data

            data *= y

            self._setunit( self.unit() * other.unit() )
            
        else:
            
            raise NotImplementedError , "__mul__ is not defined for %s and %s" % (
                self.__class__.__name__, other.__class__.__name__, )

        self._syncUnit()
        return self