예제 #1
0
    def load(self, channel_types):
        self.__plots = {}

        for channel_type in channel_types:
            channel_plots = self.load_channel(channel_type)

            for name, channel in channel_plots.items():
                channels = self.plots.get(name)
                if not channels:
                    channels = {}
                    self.plots[name] = channels

                if channel.type in channels:
                    raise RuntimeError("channel {0} is already loaded")

                channels[channel.type] = channel

        # all the cahnnels are loaded, combine MC
        for plot, channels in self.plots.items():
            if "mc" in channels:
                raise RuntimeError(("Monte-Carlo combined is already present "
                                    "for plot {0}").format(plot))

            mc = MCChannelTemplate("mc")
            for channel_type in set(channels.keys()) & set(mc.allowed_inputs):
                mc.add(channels[channel_type])

            if len(mc.input_templates):
                channels[mc.type] = mc
예제 #2
0
    def _apply_scales(self):
        if not self._scales:
            return

        print("apply scales:", ",".join(str(x) for x in self._scales))
        for scales in self._scales:
            if self._verbose:
                print("{0:-<80}".format("-- Scales "))

            # For each loaded plot/channel apply loaded scale if channel type
            # matches scale type
            for plot, channels in self.loader.plots.items():
                # special treatment for MC background(s)
                if "mc" in scales.scales and "mc" in channels:
                    mc_channels = (set(channels["mc"].allowed_inputs) &
                                   set(channels.keys()))
                    mc_scale = scales.scales["mc"]
                else:
                    mc_channels = set()
                    mc_scale = 0

                if "mc" in channels:
                    mc = MCChannelTemplate("mc")
                else:
                    mc = None

                for channel_type, channel in channels.items():
                    if channel_type in scales.scales:
                        scale = scales.scales[channel_type]
                    elif channel_type in mc_channels:
                        scale = mc_scale
                    else:
                        continue

                    if "/mttbar_after_htlep" == plot:
                        print("scale {0} by {1:.2f}".format(channel_type, scale))

                    channel.hist.Scale(scale)

                    # Update mc
                    if None != mc and channel_type in mc.allowed_inputs:
                        mc.add(channel)

                if mc:
                    channels["mc"] = mc

            if self._verbose:
                print()