示例#1
0
    def load(self, filename):
        '''Check if file exists and load plots from it'''

        if not os.path.exists(filename):
            raise RuntimeError("input file does not exit: " + filename)

        with tfile.topen(filename) as input_:
            self._load(input_)
示例#2
0
    def _save_templates(self):
        """
        Save loaded channels in output ROOT file
        
        Output file will be updated. All channels will be saved or only those,
        that are specified with --savechannels option.

        The histogram naming convention is as follows:

            [analysis]_[plot]__[channel][__[systematics]]

        where
        
            analysis    analysis channel: mu, el
            plot        plot name, e.g. mttbar
            channel     channel name: ttbar, zjets, wjets, singletop, etc.
            systematics source of the systematic error, e.g. jes__plus

        """

        # Make sure required plot is loaded
        channels = self.loader.plots.get("/mttbar_after_htlep")
        if not channels:
            raise RuntimeError("mttbar_after_htlep is not loaded")

        # format string has different format with(-out) systematics
        format_string = str(self.theta_prefix) + "_mttbar__{channel}"
        if self.suffix:
            format_string += self.suffix

        with topen(self.output_filename, "update"):
            # save only those channels that are supported or specified by user
            for channel_type, channel in channels.items():
                if channel_type not in self.channel_names or (
                    self.save_channels and channel_type not in self.save_channels
                ):

                    continue

                # All Zprimes are originally normalized to 5pb. Scale to 1pb
                if channel_type.startswith("zprime"):
                    # channel.hist.Scale(1. / 5)
                    channel.hist.Scale(2.0)

                name = format_string.format(channel=self.channel_names[channel_type])

                hist = channel.hist.Clone(name)
                hist.SetTitle(channel.hist.GetTitle())

                hist.Write(name)
示例#3
0
    def _save_templates(self):
        '''
        Save loaded channels in output ROOT file
        
        Output file will be updated. All channels will be saved or only those,
        that are specified with --savechannels option.

        The histogram naming convention is as follows:

            [analysis]_[plot]__[channel][__[systematics]]

        where
        
            analysis    analysis channel: mu, el
            plot        plot name, e.g. mttbar
            channel     channel name: ttbar, zjets, wjets, singletop, etc.
            systematics source of the systematic error, e.g. jes__plus

        '''

        with topen(self.output_filename, "update"):
            for plot_name, channels in self.loader.plots.items():
                plot_name = plot_name[1:].replace('/', '_')

                # format string has different format with(-out) systematics
                format_string = str(self.theta_prefix) + "_{plot}__{channel}"
                if self.suffix:
                    format_string += self.suffix

                # save only those channels that are supported or specified by user
                for channel_type, channel in channels.items():
                    if (channel_type not in self.channel_names or
                            (self.save_channels and
                             channel_type not in self.save_channels)):

                        continue

                    name = format_string.format(
                            plot={"mttbar_after_htlep": "mttbar",
                                  "njets": "njet"}.get(plot_name, plot_name),
                            channel=self.channel_names[channel_type])

                    hist = channel.hist.Clone(name)
                    hist.SetTitle(channel.hist.GetTitle())

                    hist.Write(name)
示例#4
0
def main():
    style = tdr()
    style.cd()

    for channel in sys.argv[1:]:
        with topen(channel + '/output_signal_p150_hlt.root') as _input:
            all_jets = _input.Get("parton_jets")
            if not all_jets:
                raise RuntimeError("failed to load all jets plot")

            tagged_jets = _input.Get("btagged_parton_jets")
            if not tagged_jets:
                raise RuntimeError("failed to load tagged jets plot")

            canvases = []
            for label, data in {"mistag(u,d,s)": {
                                    "partons": [1, 2, 3],
                                    "range": [0, 0.1],
                                    "y-title": "mistag rate (u,d,s)"
                                    },

                                  "mistag(u,d,s,g)": {
                                      "partons": [1, 2, 3, 21],
                                      "range": [0, 0.1],
                                      "y-title": "mistag rate (u,d,s,g)"
                                      },

                                  "b-tag": {
                                      "partons": [4, 5],
                                      "range": [0, 0.7],
                                      "y-title": "#epsilon_{b}"
                                      }
                                  }.items():
                canvases.append(plot(label, data, all_jets, tagged_jets, channel))


            raw_input("enter")