Esempio n. 1
0
print("Flux setting:")
print(" - gamma = {:.2f}".format(gamma_inj))
print(" - E0    = {:.1f} GeV".format(E0_inj))

if use_skylab_bins:
    print("Using official skylab binnings for the PDFs!")
    outpath = os.path.join(PATHS.data, "diff_perf_skylab_bins_CROSSCHECK")
else:
    outpath = os.path.join(PATHS.data, "diff_perf_CROSSCHECK")

if not os.path.isdir(outpath):
    os.makedirs(outpath)

# Extract source info
sources = _loader.source_list_loader()
srcs_rec = np.lib.recfunctions.drop_fields(make_src_records(sources, 0, 0),
                                           drop_names=["dt0", "dt1"])
nsrcs = len(sources)
src_ra = srcs_rec["ra"]
src_dec = srcs_rec["dec"]
# Theo weights need to be normalized manually in skylab?
src_w = np.ones(nsrcs, dtype=float) / float(nsrcs)
srcs_rec["w_theo"] = src_w
# Load healpy reco map for each source
src_maps = _loader.source_map_loader(sources)
assert nsrcs == len(src_maps)

# Create the multi LLH
rndgen = np.random.RandomState(rnd_seed)
multillh = MultiPointSourceLLH(seed=rnd_seed + 1000, ncpu=1)
multiinj = MultiPowerLawFluxInjector(random_state=rndgen)
bg_injs = {}
sig_injs = {}
llhs = {}

# Load files and build the models one after another to save memory
sample_names = _loader.source_list_loader()
for key in sample_names:
    print("\n" + 80 * "#")
    print("# :: Setup for sample {} ::".format(key))
    opts = _loader.settings_loader(key)[key].copy()
    exp_off = _loader.off_data_loader(key)[key]
    mc = _loader.mc_loader(key)[key]
    srcs = _loader.source_list_loader(key)[key]
    runlist = _loader.runlist_loader(key)[key]
    # Process to tdepps format
    srcs_rec = make_src_records(srcs, dt0=dt0, dt1=dt1)

    # Setup BG injector
    bg_inj_i = TimeDecDependentBGDataInjector(inj_opts=opts["bg_inj_opts"],
                                              random_state=rndgen)
    bg_inj_i.fit(X=exp_off, srcs=srcs_rec, run_list=runlist)
    bg_injs[key] = bg_inj_i

    # Setup LLH model and LLH
    fmod = opts["model_energy_opts"].pop("flux_model")
    flux_model = flux_model_factory(fmod["model"], **fmod["args"])
    opts["model_energy_opts"]["flux_model"] = flux_model
    llhmod = GRBModel(X=exp_off,
                      MC=mc,
                      srcs=srcs_rec,
                      run_list=runlist,