def __init__(self, options, args): self._batch_mode = options.batch self._verbose = options.verbose self._input_filename = options.filename self.use_channels = [] self._systematic = options.systematic if self._systematic: if self._systematic.endswith("+"): self._load_systematic = { "plus": True, "minus": False} elif self._systematic.endswith("-"): self._load_systematic = { "plus": False, "minus": True} else: self._load_systematic = None self._systematic = self._systematic.rstrip("+-") if not self._systematic: raise RuntimeError("systematic is not specified") if options.channels: use_channels, ban_channels = split_use_and_ban(set( channel.strip() for channel in options.channels.split(','))) # use only allowed channels or all if None specified channels = self.channels if use_channels: channels &= use_channels # remove banned channels if ban_channels: channels -= ban_channels self.use_channels = list(channels) else: self.use_channels = self.channels self.loader = None
def __init__(self, options, args): template.templates.Templates.__init__( self, options, args, disable_systematics=False if (options.systematic and ("scale" in options.systematic or "matching" in options.systematic)) else True) if options.systematic: systematic = options.systematic[:-1] self.suffix = "__{0}__{1}".format( systematic + "_ttbar" if "scale" == systematic or "matching" == systematic else systematic, "plus" if options.systematic.endswith("+") else "minus") else: self.suffix = None self.theta_prefix = options.thetaprefix self.output_filename = options.output if options.savechannels: use_channels, ban_channels = split_use_and_ban(set( channel.strip() for channel in options.savechannels.split(','))) # use only allowed channels or all if None specified channels = set(channel_type.ChannelType.channel_types.keys()) if use_channels: channels &= self._expand_channels(use_channels) # remove banned channels if ban_channels: channels -= self._expand_channels(ban_channels) self.save_channels = list(channels) else: self.save_channels = []
def __init__(self, options, args, config, channel_loader=loader.ChannelLoader): self._verbose = (options.verbose if options.verbose else config["core"]["verbose"]) self._batch_mode = (options.batch if options.batch else config["core"]["batch"]) if self._batch_mode and not options.save and self._verbose: print("warning: script is run in batch mode but canvases are not " "saved") # load channel configuration # channel_config = (options.channel_config if options.channel_config else config["template"]["channel"]) if not channel_config: raise RuntimeError("channel config is not defined") self._channel_config = channel.load(os.path.expanduser(channel_config)) # load channel scale(s) # self._channel_scale = ( scale.load(os.path.expanduser(options.channel_scale), self._channel_config) if options.channel_scale else None) # load plot configuration # plot_config = (options.plot_config if options.plot_config else config["template"]["plot"]) if not plot_config: raise RuntimeError("plot config is not defined") self._plot_config = plot.load(os.path.expanduser(plot_config)) # Get list of channels to be loaded # if not options.channels: raise RuntimeError("no channels are specified") use, ban = split_use_and_ban(ch.strip() for ch in options.channels.split(',')) if not use: raise RuntimeError("no channels are turned ON") use = channel.expand(self._channel_config, use, verbose=self._verbose) if ban: use -= channel.expand(self._channel_config, ban, verbose=self._verbose) if not use: raise RuntimeError("all channels are turned OFF") self._channels = use # Loaded plots are kept in the structures like: # plot_name: { # channel1: hist_obj, # channel2: hist_obj, # etc. # } # self._plots = {} self._channel_loader = channel_loader self._prefix = options.prefix if options.save: value = options.save.lower() if value not in ["ps", "pdf"]: raise RuntimeError("unsupported save format: " + value) self._save = value else: self._save = False self._bg_error = options.bg_error if self._bg_error: self._bg_error = float(self._bg_error) if not (0 <= self._bg_error <= 100): raise RuntimeError("background error is out of range") else: self._bg_error /= 100 self._label = options.label or os.getenv("EXO_PLOT_LABEL", None) self._sub_label = options.sub_label or os.getenv("EXO_PLOT_SUBLABEL", None) if options.plots: self._plot_patterns = options.plots.split(':') else: self._plot_patterns = [] self._legend_align = "right" self._legend_valign = "top" self._log = options.log self._ratio= options.ratio
def __init__(self, options, args, disable_systematics=True): ''' Configure Templates object with parsed command-line arguments options and args should represent parsed arguments by OptionParser. Supported options: batch keep all Canvases open and wait for user to press Enter before exit application if set filename specify input ROOT filename to load all plots from scales absolute scale factors for specific channels. If set then corresponding channel histogram will be scaled with specified value fractions relative scale factors for MC, QCD. The scale factor is calculated per plot and equal to: MC_scale * Data.Integral() / MC.Integral() QCD_scale * Data.Integral() / QCD.Integral() therefore Data needs to be loaded Note: TFractionFitter is automatically turned off if --fractions options is used notff Do not use TFractionFitter Note: TFractionFitter is automatically turned off if --fractions options is used ratio Plot ratio of specific channels in the comparision plot. Any two channels cha be specified in the ratio. Use 'bg' to reference background which is MC + QCD. Note: it is user responsibility to make sure corresponding channels are loaded plots list all plot names to be loaded. By default all histograms are loaded from input file. Plot names should be separated with comma. Use '-' to turn specific plot OFF, e.g.: --plots met,mass that is plot met and mass --plots -njets,-mass plot everything except njets and mass folders specify TDirectory(-ies) to load plots from. All subfolders in ROOT file are scanned. Folder names should be separated with comma. Use '-' to exclude specific folders. See --plots comment for example. Note: only plots that are specified in plots option will be loaded if --plots is used channels list channels to be loaded. All channels are loaded by default. Channel names should be separated with comma. Use '-' to exclude specific channels. See --plots comment for example. Note: 'data' can be used to reference all Data channels suffix is added to each canvas when saved if any isspecified ''' self._verbose = options.verbose self._batch_mode = options.batch # wait for Enter before exit self._input_filename = options.filename # ROOT file to load plots from self._logy = options.log if options.suffix: self._canvas_template = "{0}_" + options.suffix + ".pdf" else: self._canvas_template = "{0}.pdf" if options.label: self._label = options.label else: if options.btag: self._label = { "0btag": "N_{btags} = 0", "1btag": "N_{btags} #geq 1" }.get(options.btag, None) else: self._label = None self._btag = options.btag # Absolute scales for specific channels self._scales = [] if options.scales: for filename in options.scales.split(','): scales = Scales() scales.load(filename) if self._verbose: print('loaded scales: ', scales) self._scales.append(scales) # Relative fractions for specific channels if options.fractions: fractions = Scales() fractions.load(options.fractions) tmp_fractions = {} for fraction_type in ["mc", "qcd"]: fraction = fractions.scales.get(fraction_type) if not fraction: raise RuntimeError(("fractions file doe not contain {0} " "fraction").format( fraction_type.upper())) tmp_fractions[fraction_type] = fraction self.fractions = tmp_fractions else: self.fractions = {} # disable/enable TFractionFitter. It is enabled by default self._use_tfraction_fitter = not options.notff and not self.fractions # Use ratio in the comparison plot ratio = options.ratio.lower() if ratio: if "none" == ratio: self._ratio = "none" elif "/" in ratio: self._ratio = ratio.split('/') else: self._ratio = None print("only simple ratios are supported: channel/channel", file = sys.stderr) else: self._ratio = None self.use_plots = [] self.ban_plots = [] if options.plots: self.use_plots, self.ban_plots = map(list, split_use_and_ban(set( plot.strip() for plot in options.plots.split(',')))) self.use_folders = [] self.ban_folders = [] if options.folders: self.use_folders, self.ban_folders = map(list, split_use_and_ban(set( folder.strip() for folder in options.folders.split(',')))) self.use_channels = [] if options.channels: use_channels, ban_channels = split_use_and_ban(set( channel.strip() for channel in options.channels.split(','))) # use only allowed channels or all if None specified if disable_systematics: channels = set(channel for channel in channel_type.ChannelType.channel_types.keys() if "matching" not in channel and "scale" not in channel) else: channels = set(channel_type.ChannelType.channel_types.keys()) if use_channels: channels &= self._expand_channels(use_channels) # remove banned channels if ban_channels: channels -= self._expand_channels(ban_channels) self.use_channels = list(channels) self.loader = None self._str_format = "{0:>20}: {1}" # nice __str__ format