Ejemplo n.º 1
0
 def next(self):
     if self.start <= self.end:
         self.current_cut += self.step
         cut = self.incremental_cut_on + " > " + str(self.current_cut)
         if self.current_cut > self.end:
             raise StopIteration
     if self.start > self.end:
         self.current_cut -= self.step
         cut = self.incremental_cut_on + " < " + str(self.current_cut)
         if self.current_cut < self.end:
             raise StopIteration
     exp = self.pseudo_experiment
     exp.add_cut(str(cut))
     mean_arr = array.array('d')
     for i, prob in izip(xrange(self.experiments_per_step), exp):
         mean_arr.append(prob)
     n = len(mean_arr)
     mean_prob = TMath.Mean(n, mean_arr)
     err_prob = TMath.RMS(n, mean_arr)
     #err_prob /= (n - 1)
     return self.current_cut, mean_prob, err_prob
Ejemplo n.º 2
0
    def add_expected(self, cat, filename, legend, scale = 1.0,
                     line_color = 1, line_style = 1, line_width = 1,
                     marker_color = 1, marker_size = 1.2, marker_style=8,
                     value_type = 'median',
                     error_type = 'rms',
                     fill_style = 1002,
                     fill_color = ROOT.kYellow,
                     fill2_style = 1002,
                     fill2_color = ROOT.kRed,
                     extra_scale_name = 'unit',
                     smooth = None # 'single' or 'comb' or None: special tricks for smoothing expected bands
                     ):

        self.type[cat] = 'expected'

        self.cat.append(cat)
        self.file = filename
        self.tlegend[cat] = legend
        self.line_color[cat] = line_color
        self.line_style[cat] = line_style
        self.line_width[cat] = line_width
        self.marker_color[cat] = marker_color
        self.marker_size[cat] = marker_size
        self.marker_style[cat] = marker_style
        self.fill_style[cat] = fill_style
        self.fill2_style[cat] = fill2_style
        self.fill_color[cat] = fill_color
        self.fill2_color[cat] = fill2_color

        _x  = array('d')
        _y  = array('d')
        _exh = array('d')
        _exl = array('d')
        _eyh = array('d')
        _eyl = array('d')
        _exh2 = array('d')
        _exl2 = array('d')
        _eyh2 = array('d')
        _eyl2 = array('d')
        _d = [] # list of tuples, one tuple per mass point
        with open(filename, 'r') as _file:
            _mass = None
            _arr = array('d')
            _prev_limit = 0.0
            for line in _file:
                #print self.legend, line

                _buf = line.split()

                aMass = float(_buf[0])
                aLim = float(_buf[1])*scale*get_scale(extra_scale_name, aMass)

                if _mass == None:
                    _mass = aMass
                
                if abs(_mass-aMass) > 0.1:
                    _d.append((_mass, _arr))
                    #print self.legend, cat, 'mass =', _mass, 'PEs per point:', len(_arr)
                    _mass = aMass
                    _arr=array('d')

                    
                #if abs(aLim - _prev_limit) < 0.000001:
                #    #print self.legend, 'WARNING: duplicate expected limit, ignoring...'
                #    continue
                
                #_arr.append(float(_buf[1])*scale)
                _arr.append(aLim)
                _prev_limit = aLim
                
            _d.append((_mass, _arr))

        #print self.legend, _d

        for t in _d:

            _x.append(t[0])
            _mean = TMath.Mean(len(t[1]), t[1])
            _median = TMath.Median(len(t[1]), t[1])
            _rms  = TMath.RMS(len(t[1]), t[1])
            _nrms = _rms/len(t[1])

            #print self.legend, t[0], _mean, _rms, _nrms
            if value_type == 'mean':
                _value = _mean
                _y.append(_mean)
            elif value_type == 'median':
                _value = _median
                _y.append(_median)
            _exh.append(0)
            _exl.append(0)
            _exh2.append(0)
            _exl2.append(0)
            if error_type == 'rms':
                _eyh.append(_rms/2)
                _eyl.append(_rms/2)
                _eyh2.append(_rms)
                _eyl2.append(_rms)
            elif error_type == 'quantile':
                _prob = array('d')
                _prob.append(0.021)
                _prob.append(0.159)
                _prob.append(0.841)
                _prob.append(0.979)
                _nprob = 4
                _quantiles = array('d')
                _quantiles.append(0)
                _quantiles.append(0)
                _quantiles.append(0)
                _quantiles.append(0)
                TMath.Quantiles(len(t[1]), _nprob, t[1], _quantiles, _prob)
                #print self.legend, 'Quantiles:', _quantiles

                _eyh.append(abs(_value-_quantiles[2]))
                _eyl.append(abs(_value-_quantiles[1]))
                _eyh2.append(abs(_value-_quantiles[3]))
                _eyl2.append(abs(_value-_quantiles[0]))

        self.x[cat] = _x
        self.y[cat] = _y
        self.exh[cat] = _exh
        self.exl[cat] = _exl
        self.exh2[cat] = _exh2
        self.exl2[cat] = _exl2

        # non-smoothed bands
        #self.eyh[cat] = _eyh
        #self.eyl[cat] = _eyl
        #self.eyh2[cat] = _eyh2
        #self.eyl2[cat] = _eyl2

        # smoothed bands
        # ee, mumu
        #self.eyh[cat] = self.smooth_band(_x,_eyh,_y,[1],300,600,'high')
        #self.eyh2[cat] = self.smooth_band(_x,_eyh2,_y,[1],300,600,'high')
        #self.eyl[cat] = self.smooth_band(_x,_eyl,_y,[],300,600)
        #self.eyl2[cat] = self.smooth_band(_x,_eyl2,_y,[1],300,600)
        # comb
        self.eyh[cat] = self.smooth_band(_x,_eyh,_y,[],300,600,'high')
        self.eyh2[cat] = self.smooth_band(_x,_eyh2,_y,[1],300,600,'high')
        self.eyl[cat] = self.smooth_band(_x,_eyl,_y,[1],300,600)
        self.eyl2[cat] = self.smooth_band(_x,_eyl2,_y,[1],300,600)
Ejemplo n.º 3
0
    def add_median(self, cat, filename, legend, scale = 1.0,
                   line_color = 1, line_style = 1, line_width = 1,
                   marker_color = 1, marker_size = 1.2, marker_style=8,
                   dofit=False, fit_min = 100, fit_max = 3000,
                   var_scale = None,
                   fill_style = 1002,
                   fill_color = None,
                   fill2_style = 1002,
                   fill2_color = ROOT.kRed,
                   extra_scale_name = 'unit',
                   value_type = 'median',
                   error_type = 'quantile'):
        #
        # same as add() but for multiple values
        #
        

        if fill_color == None:
            fill_color = line_color

        self.type[cat] = 'observed'

        self.dofit[cat] = dofit
        self.fit_min[cat] = fit_min
        self.fit_max[cat] = fit_max

        self.cat.append(cat)
        self.file = filename
        self.tlegend[cat] = legend
        self.line_color[cat] = line_color
        self.line_style[cat] = line_style
        self.line_width[cat] = line_width
        self.marker_color[cat] = marker_color
        self.marker_size[cat] = marker_size
        self.marker_style[cat] = marker_style
        self.fill_style[cat] = fill_style
        self.fill2_style[cat] = fill2_style
        self.fill_color[cat] = fill_color
        self.fill2_color[cat] = fill2_color

        _x = array('d')
        _y = array('d')
        _exh = array('d')
        _exl = array('d')
        _eyh = array('d')
        _eyl = array('d')
        _d = [] # list of tuples, one tuple per mass point
        with open(filename, 'r') as _file:
            _mass = None
            _arr = array('d')
            _prev_limit = 0.0
            for line in _file:
                #print self.legend, line

                _buf = line.split()

                if _buf[0][0] == '#':
                    continue

                #_mass = float(_buf[0])
                aMass = float(_buf[0])
                _scale = get_scale(var_scale, aMass)
                _scale_err = get_scale_err(var_scale, aMass)

                if _scale != None:
                    _scale = _scale*scale
                else:
                    _scale = scale

                #_xval = float(_buf[0])
                #_x.append(_xval)

                #_yval = float(_buf[1])*_scale*get_scale(extra_scale_name, _xval)
                aLim = float(_buf[1])*_scale*get_scale(extra_scale_name, aMass)
                #_y.append(_yval)

                if _mass == None:
                    _mass = aMass
                
                if abs(_mass-aMass) > 0.1:
                    _d.append((_mass, _arr))
                    #print self.legend, cat, 'mass =', _mass, 'PEs per point:', len(_arr)
                    _mass = aMass
                    _arr=array('d')

                    
                #if abs(aLim - _prev_limit) < 0.000001:
                #    #print self.legend, 'WARNING: duplicate expected limit, ignoring...'
                #    continue
                
                #_arr.append(float(_buf[1])*scale)
                _arr.append(aLim)
                _prev_limit = aLim
                
            _d.append((_mass, _arr))
                
        for t in _d:

            _x.append(t[0])
            _mean = TMath.Mean(len(t[1]), t[1])
            _median = TMath.Median(len(t[1]), t[1])
            _rms  = TMath.RMS(len(t[1]), t[1])
            _nrms = _rms/len(t[1])

            #print self.legend, t[0], _mean, _rms, _nrms
            if value_type == 'mean':
                _value = _mean
                _y.append(_mean)
            elif value_type == 'median':
                _value = _median
                _y.append(_median)
            _exh.append(0)
            _exl.append(0)
            if error_type == 'rms':
                _eyh.append(_rms/2)
                _eyl.append(_rms/2)
            elif error_type == 'quantile':
                _prob = array('d')
                _prob.append(0.021)
                _prob.append(0.159)
                _prob.append(0.841)
                _prob.append(0.979)
                _nprob = 4
                _quantiles = array('d')
                _quantiles.append(0)
                _quantiles.append(0)
                _quantiles.append(0)
                _quantiles.append(0)
                TMath.Quantiles(len(t[1]), _nprob, t[1], _quantiles, _prob)
                #print self.legend, 'Quantiles:', _quantiles

                #_eyh.append(abs(_value-_quantiles[2]))
                #_eyl.append(abs(_value-_quantiles[1]))
                _eyh.append(0)
                _eyl.append(0)

        self.x[cat] = _x
        self.y[cat] = _y
        self.exh[cat] = _exh
        self.exl[cat] = _exl
        self.eyh[cat] = _eyh
        self.eyl[cat] = _eyl
Ejemplo n.º 4
0
def mean(var, altname=''):
    if len(altname) < 1:
        altname = var
    data.Draw(var, '', 'goff')
    return TMath.Mean(data.GetSelectedRows(), data.GetV1())