Exemplo n.º 1
0
    def add_variable(self, variable, bins, thresholds):
        """ This function adds a variable to be tracked by this collection.
        :param variable: The variable name
        :type name: str.
        :param bins: The bins to be used for the variable
        :type bins: list.
        :param thresholds: A list of thresholds for L1 values
        :type thresholds: list.
        """
        # TODO: this will no longer work since 1st dimension is pileup
        if variable in self.keys():
            logger.warn('Variable {0} already exists!')
            return
        self._thresholds[variable] = thresholds
        hist_names = []
        add_name = hist_names.append

        for puBinLower, puBinUpper in pairwise(self._pileUpBins):
            for threshold in thresholds:
                name = '{0}_threshold_gt{1}_pu{2}To{3}'.format(
                    variable, threshold, puBinLower, puBinUpper)
                if not self[puBinLower][variable][threshold]:
                    add_name(name)
                    self[puBinLower][variable][threshold] = _EfficiencyCurve(
                        name, bins, threshold)
        logger.debug('Created {0} histograms: {1}'.format(
            len(hist_names), ', '.join(hist_names)))
Exemplo n.º 2
0
    def add(self, hist_name, bins=[]):
        from rootpy.plotting import Hist
        '''
            Specialisation for 2 dimensions
            TODO: generalise
        '''
        bins = np.array(bins)
        if bins.size == 0:
            logger.error(
                'No bins specified for histogram {0}'.format(hist_name))

        if hist_name in self[self._pileupBins[0]].keys():
            logger.warn('Histogram {0} already exists!'.format(hist_name))
            return
        hist_names = []
        add_name = hist_names.append

        for puBinLower, puBinUpper in pairwise(self._pileupBins):
            name = '{0}_pu{1}To{2}'.format(
                hist_name, puBinLower, puBinUpper)
            if not self[puBinLower] or not self[puBinLower][hist_name]:
                add_name(name)
                self[puBinLower][hist_name] = Hist(bins, name=name)
        logger.debug('Created {0} histograms: {1}'.format(
            len(hist_names), ', '.join(hist_names)))
Exemplo n.º 3
0
    def add_variable(self, variable, bins=[]):
        from rootpy.plotting import Hist
        if variable in self.keys():
            logger.warn('Variable {0} already exists!')
            return
        hist_names = []
        add_name = hist_names.append

        for puBinLower, puBinUpper in pairwise(self._pileUpBins):
            for region in six.iterkeys(self._regions):
                name = '{0}_{1}_pu{2}To{3}'.format(variable, region,
                                                   puBinLower, puBinUpper)
                if not self[puBinLower][variable][region]:
                    add_name(name)
                    self[puBinLower][variable][region] = Hist(bins, name=name)
        logger.debug('Created {0} histograms: {1}'.format(
            len(hist_names), ', '.join(hist_names)))
Exemplo n.º 4
0
    def _get_pu_bin(self, pileup):
        '''
            Returns the pileup bin corresponding to the provided pileup value.

            :Example:
                >>> hists = HistogramsByPileUp(pileupBins=[0,10,15,20,30,999])
                >>> hists._get_pu_bin(1) # returns 0
                >>> hists._get_pu_bin(11) # returns 1
                >>> hists._get_pu_bin(1111) # returns -1
        '''
        if pileup > max(self._pileupBins):
            return -1

        bins = pairwise(self._pileupBins)
        for i, (lowerEdge, upperEdge) in enumerate(bins):
            if pileup >= lowerEdge and pileup < upperEdge:
                return i
        return 0
Exemplo n.º 5
0
    def add_variable(self, variable, vtype='position'):
        bins = ResolutionCollection.BINS['default']
        if vtype in ResolutionCollection.BINS:
            bins = ResolutionCollection.BINS[vtype]

        if variable in self.keys():
            logger.warn('Variable {0} already exists!')
            return
        hist_names = []
        add_name = hist_names.append

        for puBinLower, puBinUpper in pairwise(self._pileUpBins):
            for region in six.iterkeys(self._regions):
                name = '{0}_{1}_pu{2}To{3}'.format(variable, region,
                                                   puBinLower, puBinUpper)
                if not self[puBinLower][variable][region]:
                    add_name(name)
                    self[puBinLower][variable][region] = Hist(bins, name=name)
        logger.debug('Created {0} histograms: {1}'.format(
            len(hist_names), ', '.join(hist_names)))
Exemplo n.º 6
0
 def _calculateEfficiencies(self):
     for puBinLower, _ in pairwise(self._pileUpBins):
         for hist in self[puBinLower].keys():
             for threshold in self._thresholds[hist]:
                 self[puBinLower][hist][threshold].calculate_efficiency()