Beispiel #1
0
def mese_followup(**kwargs):
    livetime = 988.54
    livetime += 358.402
    livetime += 368.381
    print("\tLoading MESE with 2 follow-up years...")
    exp = np.append(np.load(os.path.join(path, "MESE_exp.npy")),
                    np.load(os.path.join(path, "MESE_followup_exp.npy")))

    mc = np.load(os.path.join(path, "MESE_MC.npy"))

    if "dist" in exp.dtype.names:
        exp = drop_fields(exp, ["dist"], usemask=False)
    if "dist" in mc.dtype.names:
        mc = drop_fields(mc, ["dist"], usemask=False)

    sinDec = kwargs.pop("sinDec", [-1., hem])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, hem, 12 + 1),
        ]))

    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))
    dec_bins_logE = np.linspace(-1., hem, 4 + 1)
    dec_bins_logE = dec_bins_logE[(dec_bins_logE >= sinDec[0])
                                  & (dec_bins_logE <= sinDec[1])]
    dec_bins_logE = np.unique(np.concatenate([sinDec, dec_bins_logE]))

    energy_bins = [
        np.linspace(2., 8.5, 67 + 1),
        np.linspace(-1., hem, 4 + 1),
    ]
    mc = mc[mc["logE"] > 1.]
    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)
    kwargs.setdefault("mode", "all")
    kwargs.setdefault("seed", 20101112)
    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #2
0
def ic86_I(**kwargs):
    livetime = 332.61
    print("\tLoading IC86 data...")

    decorr = kwargs.pop("no_mese", False)

    if decorr:
        print("\t\tRemove MESE from exp and MC")
        exp = np.load(os.path.join(path, "IC86_noMESE_exp.npy"))
        mc = np.load(os.path.join(path, "IC86_noMESE_corrected_MC.npy"))
    else:
        exp = np.load(os.path.join(path, "IC86_exp.npy"))
        mc = np.load(os.path.join(path, "IC86_corrected_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.2, 10 + 1),
            np.linspace(-0.2, hem, 4 + 1),
            np.linspace(hem, 0.2, 5 + 1),
            np.linspace(0.2, 1., 10),
        ]))

    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))

    energy_bins = [np.linspace(1., 10., 40 + 1), dec_bins]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2011)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #3
0
def ic40(**kwargs):
    livetime = 375.539
    print("\tLoading IC40 data...")
    exp = np.load(os.path.join(path, "IC40_exp.npy"))
    mc = np.load(os.path.join(path, "IC40_MC.npy"))

    #dec_bins = np.linspace(-1., 1., 25 + 1)

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 5 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    dec_bins_logE = np.unique(
        np.concatenate([
            np.linspace(-1., -0.25, 10 + 1),
            np.linspace(-0.25, 0.0, 10 + 1),
            np.linspace(0.0, 1., 10 + 1),
        ]))

    energy_bins = [np.linspace(1., 10., 35 + 1), dec_bins_logE]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2008)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #4
0
def ic79(**kwargs):
    livetime = 315.506
    print("\tLoading IC79 data...")

    decorr = kwargs.pop("no_mese", False)

    if decorr:
        print("\t\tRemove MESE from exp and MC")
        exp = np.load(os.path.join(path, "IC79_noMESE_exp.npy"))
        mc = np.load(os.path.join(path, "IC79_noMESE_corrected_MC.npy"))
    else:
        exp = np.load(os.path.join(path, "IC79_exp.npy"))
        mc = np.load(os.path.join(path, "IC79_corrected_MC.npy"))

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.75, 10 + 1),
            np.linspace(-0.75, 0., 15 + 1),
            np.linspace(0., 1., 20 + 1)
        ]))

    energy_bins = [np.linspace(2., 9., 40 + 1), dec_bins]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2010)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #5
0
def mese(**kwargs):
    livetime = 988.54
    print("\tLoading MESE...")
    exp = np.load(os.path.join(path, "MESE_exp.npy"))
    mc = np.load(os.path.join(path, "MESE_MC.npy"))

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.92, 3 + 1),
            np.linspace(-0.92, hem, 10 + 1),
        ]))

    energy_bins = [
        np.linspace(2., 8.5, 40 + 1),
        np.linspace(-1., hem, 4 + 1),
    ]

    mc = mc[mc["logE"] > 1.]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("mode", "all")

    kwargs.setdefault("seed", 20101112)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #6
0
def ic86_2012(dataset=[2012, 2013], **kwargs):
    lt12 = 331.358
    lt13 = 359.768
    lt14 = 367.209
    livetime = 0.
    exp = list()

    decorr = kwargs.pop("no_mese", False)

    if 2012 in dataset:
        livetime += lt12
        print("\tLoading IC86-2012 ...")
        if decorr:
            print("\t\tRemove MESE from IC86-2012 exp")
            exp.append(np.load(os.path.join(path, "IC86-2012_noMESE_exp.npy")))
        else:
            exp.append(np.load(os.path.join(path, "IC86-2012_exp.npy")))
    if 2013 in dataset:
        livetime += lt13
        print("\tLoading IC86-2013 ...")
        exp.append(np.load(os.path.join(path, "IC86-2013_exp.npy")))

    if 2014 in dataset:
        livetime += lt14
        print("\tLoading IC86-2014 ...")
        exp.append(np.load(os.path.join(path, "IC86-2014_exp.npy")))

    exp = np.concatenate(exp)
    if decorr:
        print("\t\tRemove MESE from IC86-2012 MC")
        mc = np.load(os.path.join(path, "IC86-2012_noMESE_MC.npy"))
    else:
        mc = np.load(os.path.join(path, "IC86-2012_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] < sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] < sinDec[-1])]

    exp = drop_fields(exp, ["BDT"])
    mc = drop_fields(mc, ["BDT"])

    dec_bins = np.unique(
        np.concatenate([
            np.linspace(-1., -0.93, 4 + 1),
            np.linspace(-0.93, -0.3, 10 + 1),
            np.linspace(-0.3, 0.05, 9 + 1),
            np.linspace(0.05, 1., 18 + 1),
        ]))
    dec_bins = dec_bins[(dec_bins >= sinDec[0]) & (dec_bins <= sinDec[1])]
    dec_bins = np.unique(np.concatenate([sinDec, dec_bins]))

    energy_bins = [np.linspace(1., 9.5, 50 + 1), dec_bins]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2012)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    print("{0:>80s}".format("[done]"))
    return llh
Beispiel #7
0
def ic86_2012_precut(**kwargs):
    livetime = 331.88
    print("\tLoading IC86-II with precut applied...")
    exp = np.load(os.path.join(path, "IC86-2012-precut_exp.npy"))
    mc = np.load(os.path.join(path, "IC86-2012-precut_MC.npy"))

    sinDec = kwargs.pop("sinDec", [-1., 1.])
    exp = exp[(exp["sinDec"] > sinDec[0]) & (exp["sinDec"] <= sinDec[-1])]
    mc = mc[(mc["sinDec"] > sinDec[0]) & (mc["sinDec"] <= sinDec[-1])]

    if "perc" in kwargs:
        perc = kwargs.pop("perc")
        print("\tCutting on percentage {0:8.3%}".format(perc))

        nbins = 400
        h, bins = np.histogram(exp["sinDec"], bins=nbins, range=sinDec)
        NpB = perc * np.sum(h, dtype=np.float) / nbins
        eps = np.zeros_like(h, dtype=np.float)
        eps[h > 0] = NpB / h[h > 0]
        eps[eps > 1] = 1.
        xdec = np.array([])
        ybdt = np.array([])
        for eps_i, lbin, ubin in zip(eps, bins[:-1], bins[1:]):
            m = (exp["sinDec"] > lbin) & (exp["sinDec"] < ubin)
            if not np.any(m):
                print("No events in", lbin, ubin)
                continue
            bdt_cut = np.percentile(exp["BDT"][m], 100. * (1. - eps_i))
            np.set_printoptions(precision=4)
            xdec = np.append(xdec, (lbin + ubin) / 2.)
            ybdt = np.append(ybdt, bdt_cut)

        pol = np.polyfit(xdec, ybdt, 6)

        N1 = len(exp)

        polexp = np.polyval(pol, exp["sinDec"])
        polmc = np.polyval(pol, mc["sinDec"])

        mexp = exp["BDT"] > polexp
        mmc = mc["BDT"] > polmc

        exp = exp[mexp]
        mc = mc[mmc]

        N2 = len(exp)

        print("\tCut: {0:7.2%}".format(float(N2) / N1))

    elif "bdt" in kwargs and "bdt2" in kwargs:
        comp = kwargs.pop("comp", np.logical_or)
        bdt = kwargs.pop("bdt")
        if not callable(bdt):
            print("\tCutting on bdt {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        bdt2 = kwargs.pop("bdt2")
        if not callable(bdt2):
            print("\tCutting on bdt2 {0:5.3f}".format(bdt2))
            bdt_val2 = bdt2
            bdt2 = lambda cz: bdt_val2 * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt2 from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt2(np.asarray(sinDec))))
        exp = exp[comp(exp["BDT"] > bdt(exp["sinDec"]),
                       exp["BDT2"] > bdt2(exp["sinDec"]))]
        mc = mc[comp(mc["BDT"] > bdt(mc["sinDec"]),
                     mc["BDT2"] > bdt2(mc["sinDec"]))]

    elif "bdt" in kwargs:
        bdt = kwargs.pop("bdt")
        if not callable(bdt):
            print("\tCutting on bdt {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        exp = exp[exp["BDT"] > bdt(exp["sinDec"])]
        mc = mc[mc["BDT"] > bdt(mc["sinDec"])]
    elif "bdt2" in kwargs:
        bdt = kwargs.pop("bdt2")
        if not callable(bdt):
            print("\tCutting on bdt2 {0:5.3f}".format(bdt))
            bdt_val = bdt
            bdt = lambda cz: bdt_val * np.ones_like(cz)
        else:
            print(
                "\tCutting bdt from {0:5.3f} to {1:5.3f} in dec range".format(
                    *bdt(np.asarray(sinDec))))
        exp = exp[exp["BDT2"] > bdt(exp["sinDec"])]
        mc = mc[mc["BDT2"] > bdt(mc["sinDec"])]

    nmin = 10
    nbins = 40
    dec_bins = np.linspace(*sinDec, num=nbins)
    while np.any(np.histogram(exp["sinDec"], bins=dec_bins)[0] < nmin):
        print("Found close-to-empty bins, reduce binsize")
        h, b = np.histogram(exp["sinDec"], bins=dec_bins)
        b = np.array([b[1:], b[:-1]])
        print(b[:, h < nmin])
        if nbins < 2:
            raise ValueError("Need more than 2 bins!")
        nbins -= 1
        dec_bins = np.linspace(*sinDec, num=nbins)

    energy_bins = [np.linspace(0., 9.5, 30 + 1), dec_bins]

    llh_model = EnergyLLH(twodim_bins=energy_bins, sinDec_bins=dec_bins)

    if "upscale" in kwargs and kwargs["upscale"] is not None and (
            kwargs["upscale"] or not type(kwargs["upscale"]) == bool):
        lt = kwargs.pop("livetime", 332.61)  #livetime)
        kwargs["upscale"] = (int(kwargs.pop("upscale")), lt)

    kwargs.pop("livetime", None)

    kwargs.setdefault("seed", 2012)

    llh = StackingPointSourceLLH(exp,
                                 mc,
                                 livetime,
                                 llh_model=llh_model,
                                 **kwargs)

    if "pol" in locals():
        llh.pol = pol

    print("{0:>80s}".format("[done]"))
    return llh