Beispiel #1
0
def _count(process, region):
    """Computes the weighted event count of a process in a region.

    Args:
        process: The process whose events should be counted
        region: The region whose weighting/selection should be applied

    Returns:
        The weighted event count in the region.
    """
    # Get the combined selection and weight from the region
    region_selection = region.selection_weight()

    # Get patches
    patches = process.patches()

    if not patches:
        selection = region_selection
    else:
        selection = multiplied(region_selection, patches)

    # Create a unique name and title for the histogram
    name = title = uuid4().hex

    # Create the expression string and specify which histogram to fill
    expression = '1>>{0}'.format(name)

    # Load the chain
    chain = process.load()
    chain.Draw(expression, selection)
    h = gDirectory.Get(name)
    return h.Integral(-1, h.GetNbinsX()+1)
Beispiel #2
0
    def selection_weight(self, sample_type):
        """Returns a string of "selection * weight" with all variations
        applied.
        """
        # Grab resultant weight/selection
        selection = self._selection
        try:
            weight = multiplied(self._weight,
                                self._sample_weights[sample_type])
        except:
            weight = self._weight

        # Apply any variations
        for v in self._variations:
            selection, weight = v(selection, weight)

        # Return the product of the selection and weight expressions
        return multiplied(selection, weight)
Beispiel #3
0
    def selection_weight(self, sample_type):
        """Returns a string of "selection * weight" with all variations
        applied.
        """
        # Grab resultant weight/selection
        selection = self._selection
        try:
            weight = multiplied(self._weight,
                                self._sample_weights[sample_type])
        except:
            weight = self._weight

        # Apply any variations
        for v in self._variations:
            selection, weight = v(selection, weight)

        # Return the product of the selection and weight expressions
        return multiplied(selection, weight)
Beispiel #4
0
    def __call__(self, selection, weight):
        """Add's an expression to a region's weight.

        Args:
            selection: The existing selection expression
            weight: The existing weight expression

        Returns:
            A tuple of the form (varied_selection, varied_weight).
        """
        return (selection, multiplied(weight, self._weight))
Beispiel #5
0
    def __call__(self, selection, weight):
        """Add's an expression to a region's weight.

        Args:
            selection: The existing selection expression
            weight: The existing weight expression

        Returns:
            A tuple of the form (varied_selection, varied_weight).
        """
        return (selection, multiplied(weight, self._weight))
Beispiel #6
0
def _make_selection(process, region):
    # Get the combined selection and weight from the region
    region_selection = region.selection_weight()

    # Get patches
    patches = process.patches()

    # Construct the final selection from the region selection and weight and
    # the processes patches.
    if not patches:
        selection = region_selection
    else:
        selection = multiplied(region_selection, patches)
    return selection
Beispiel #7
0
def make_selection(process, region):
    """Make a selection string out of the selection and weight of a region
    and the patches of a process.

    Args:
        region: The region object
        process: The process object

    Returns:
        A selection string
    """
    # Get the combined selection and weight from the region
    selection = region.selection_weight(process.sample_type())

    # Apply process patches
    selection = multiplied(selection, process.patches())

    return selection
Beispiel #8
0
def make_selection(process, region):
    """Make a selection string out of the selection and weight of a region
    and the patches of a process.

    Args:
        region: The region object
        process: The process object

    Returns:
        A selection string
    """
    # Get the combined selection and weight from the region
    selection = region.selection_weight(process.sample_type())

    # Apply process patches
    selection = multiplied(selection, process.patches())

    return selection
Beispiel #9
0
    def selection_weight(self):
        """Returns a string of "selection * weight" with all variations
        applied.
        """
        # Grab resultant weight/selection
        selection, weight = self._selection, self._weight

        # Apply any variations
        for v in self._variations:
            selection, weight = v(selection, weight)

        # If this region isn't weighted, return only the selection
        if selection:
            if self._weighted and weight:
                return multiplied(selection, weight)
            else:
                return selection
        elif self._weighted and weight:
            return weight
        else:
            return ""
 def test_multiplied(self):
     self.assertEqual(multiplied(self.expression_1, self.expression_2), "((x + y > 8) * (3 < (z - y)**2))")
Beispiel #11
0
 def test_multiplied(self):
     self.assertEqual(multiplied(self.expression_1, self.expression_2),
                      '((x + y > 8) * (3 < (z - y)**2))')
Beispiel #12
0
 def patches(self):
     """Returns an expression of patches for the process, if any.
     """
     return multiplied(*[p.selection() for p in self._patches])
Beispiel #13
0
 def patches(self):
     """Returns an expression of patches for the process, if any.
     """
     return multiplied(*self._patches)
Beispiel #14
0
 def patches(self):
     """Returns an expression of patches for the process, if any.
     """
     return multiplied(*[p.selection() for p in self._patches])