示例#1
0
 #  Get input files and settings
 #
 yamls_to_load, roots_to_load, do_show, do_print_all, do_not_make_matrix, save_file = parse_inputs(
     sys.argv[1:])
 do_save = len(save_file) > 0
 if do_save: plotter.set_save_file(save_file)
 if not do_show and not do_save and not do_print_all:
     msg.warning(
         "inspect_yaml.py",
         "Neither --save, --show nor --print specified. Falling back to --print."
     )
     do_print_all = True
     #
     #  Load input files
     #
 my_tables = DistributionContainer("my_tables")
 HD._make_matrix_if_possible = not do_not_make_matrix
 if len(yamls_to_load) > 0:
     HD.load_yaml_files_from_list(my_tables, yamls_to_load)
 if len(roots_to_load) > 0:
     RT.load_root_files_from_list(my_tables, roots_to_load)
 #
 #  Print contents (if --print was called then go into excruciating detail)
 #
 my_tables.print_keys()
 if do_print_all: my_tables.print_all()
 #
 #  Plot everything
 #
 my_tables.plot_all(save=do_save, show=do_show)
 #
if __name__ == "__main__":
    #
    #  Welcome
    #
    msg.info("plot_ratios.py", "Running program")
    #
    #  Get input files and settings
    #
    num_tag, den_tag, do_show, save_file, yamls_to_load, roots_to_load = parse_inputs(
        sys.argv[1:])
    do_save = len(save_file) > 0
    if do_save: plotter.set_save_file(save_file)
    #
    #  Load input files
    #
    my_tables = DistributionContainer("my_tables")
    HD.load_yaml_files_from_list(my_tables, yamls_to_load)
    RT.load_root_files_from_list(my_tables, roots_to_load)
    #
    #  Get numerator and denominator tables
    #
    num_dists, den_dists = [], []
    for d in [
            my_tables._inclusive_distributions, my_tables._1D_distributions,
            my_tables._2D_distributions, my_tables._ND_distributions
    ]:
        for key, dist in d.items():
            if num_tag in key or num_tag in dist._dep_var._name:
                num_dists.append(dist)
            if den_tag in key or den_tag in dist._dep_var._name:
                den_dists.append(dist)
示例#3
0
 def load_from_hepdata(self, fname, **kwargs):
     my_tables = DistributionContainer(f"InputStore.hepdata.tables.{fname}")
     HD.load_all_yaml_files(my_tables, fname)
     new_entries = []
     look_for_params = kwargs.get("look_for_params", False)
     if "cfg" in kwargs and "key" in kwargs:
         cfg, key = kwargs["cfg"], kwargs["key"]
         keyfile = cfg.get("INPUTS",
                           f"{key}.file.hepdata.keyfile",
                           fallback="")
         if keyfile != "": my_tables.load_keys(keyfile)
         fextract = utils.string_to_object(
             cfg.get("INPUTS", f"{key}.extract", fallback="[]"))
         for entry_name in fextract:
             includes_SM = utils.string_to_object(
                 cfg.get("INPUTS",
                         f"{key}.{entry_name}.IncludesSM",
                         fallback="[]"))
             value_keys = utils.string_to_object(
                 cfg.get("INPUTS",
                         f"{key}.{entry_name}.keys.values",
                         fallback="[]"))
             cov_keys = utils.string_to_object(
                 cfg.get("INPUTS",
                         f"{key}.{entry_name}.keys.covariance",
                         fallback="[]"))
             if type(value_keys) is list and len(value_keys) > 0 and type(
                     value_keys[0]) is str:
                 values = np.concatenate([
                     my_tables[value_key]._dep_var._values
                     for value_key in value_keys
                 ])
             elif type(value_keys) is int:
                 values = np.zeros(shape=value_keys)
             else:
                 values = value_keys
             num_values = len(values)
             cov = np.zeros(shape=(num_values, num_values))
             params = {}
             if look_for_params:
                 for param in glob.scan_params:
                     params[param.name] = cfg.get(
                         "INPUTS",
                         f"{key}.{entry_name}.{param.name}",
                         fallback=None)
             for cov_key in cov_keys:
                 cov = cov + my_tables[cov_key]._dep_var._values
             new_entry = Input(name=entry_name,
                               type=cfg.get("INPUTS",
                                            f"{key}.{entry_name}.type",
                                            fallback=""),
                               origin_file=fname,
                               keys=value_keys,
                               params=params,
                               dist=Distribution(name=entry_name,
                                                 values=values,
                                                 cov=cov,
                                                 includes_SM=includes_SM))
             if entry_name in self.entries:
                 utils.warning("InputStore.load_from_hepdata()",
                               f"Entry named {entry_name} already exists")
             self.entries[entry_name] = new_entry
             new_entries.append(entry_name)
     if not self.do_quick_save: return
     if "save" not in kwargs:
         utils.warning(
             "InputStore.load_from_hepdata",
             f"self.do_quick_save is True but no quicksave file specified for {fname}. Not saving."
         )
         return
     self.quick_save(kwargs["save"], new_entries)
#  =================================== #
#  ====    Brief: main program    ==== #
#  =================================== #
if __name__ == "__main__" :
				#
				#  Welcome
				#
	msg.info("validate_yaml_files.py","Running program")
				#
				#  Get input files and settings
				#
	yamls_to_load, roots_to_load = parse_inputs(sys.argv[1:])
				#
				#  Load input files
				#
	yaml_tables = DistributionContainer("yaml_files")
	HD.load_yaml_files_from_list(yaml_tables,yamls_to_load)
				#
	root_tables = DistributionContainer("root_files")
	RT.load_root_files_from_list(root_tables,roots_to_load)
				#
				#  Look for matches
				#
	keys = yaml_tables.get_keys()
	for l in keys :
		for key in l :
			print_matches ( key , yaml_tables.get_table(key) , root_tables )
				#
				#  Goodbye
				#
	msg.info("validate_yaml_files.py","Program reached the end without crashing and will close :) Have a nice day...")