예제 #1
0
def _load_flux(params, tracks=False):
    name = gen_filename(config["datapath"], config["nu_flux"]+".dat", params)

    if False:
        f = open(name,'rb')
        all_data = pickle.load(f)
        f.close()
    else:
        kwargs ={"as_data":True}
        data = raw_flux(params, kwargs=kwargs) 
        flux = {}
        for key in data.get_keys(just_casc=(not tracks),just_tracks=tracks):
            flux[key] = np.array(data.fluxes[key])
        return (np.array(data.energies), np.array(data.angles), flux)

    return( all_data["e_true"], all_data["a_true"], all_data["flux"] )
예제 #2
0
def generate_astr_flux(params, **kwargs):
    """
    This script generates an astrophysical flux at the given SterileParameters

    It saves the flux to the datapath that the configuration file is configured to
    """
    print("Received {} point".format(params))
    if "forced_filename" not in kwargs:
        kwargs["forced_filename"] =  gen_filename(config["datapath"], config["prop_astro_flux"], params)

    if "flavor_ratio" not in kwargs:
        flavor_ratio = get_flavor_ratio(params)
        kwargs["flavor_ratio"] = flavor_ratio
    else:
        print("Using ratio: {}".format(kwargs["flavor_ratio"]))

    kwargs["state_setter"] = astro_initial_state
    kwargs["osc"] = False

    return raw_flux(params, kwargs)
예제 #3
0
def gen_flux(params):
    """
    First we make a neutrino flux file at the detector (true flux binning)
    Then we get the fluxes, binned in energy deposited
    Then we incorporate the detector response 
    """
    if not isinstance(params, SterileParams):
        raise TypeError("Expected {} for params, not {}".format(
            SterileParams, type(params)))

    raw_flux_name = gen_filename(config["datapath"],
                                 config["nu_flux"] + ".dat", params)
    if os.path.exists(raw_flux_name) and config["use_pregen_mceq_flux"]:
        pass
    else:
        raw_flux_name = raw_flux(params)

    a, b, c, d, err = generate_singly_diff_fluxes(config["n_bins"],
                                                  datafile=raw_flux_name)
    incorporate_recon(a, b, c, d, errors=err, params=params, just_flux=True)
def make_meta_flux(params, do_mc = False):
    """
    This makes and saves 
    """
    # look for the atmospheric fluxes. These should all be pre-generated 
    start = time() 
    kwargs = {}
    kwargs["as_data"]=True
    atmo_data = raw_flux(params,kwargs=kwargs)
    astr_data = generate_astr_flux(params, as_data=True)

    print("Calculating Expected Binned Flux at {}".format(params))
    if do_mc:
        print("In MC mode")
    # now we use these two to build the full expected flux
    if do_mc:
        full_flux = build_mc_flux(atmo_data, astr_data)
    else:
        full_flux = get_expectation(atmo_data, astr_data) #dict 
    middle = time()
    # save the object
    filename = "expected_flux_from_mc_smearedwell.dat" if do_mc else "best_expected_flux.dat"

    suffix = "{}from_mc".format("_not_" if (not do_mc) else "_")
    new_filename = gen_filename(config["datapath"]+ "/expected_fluxes_reco/", filename, params)

    print("Saving to {}".format(new_filename))
    f = open(new_filename ,'wb')
    pickle.dump(full_flux, f, -1)
    f.close()
    end = time()

    print("Flux Sim took {:.1f} seconds".format(middle-start))
    print("Saving took {:.3f} seconds".format(end-middle))

    return full_flux
def cr_perturb(dgamma=0.0,
               dnorm=0.0,
               use_mc=False,
               smearmode=False,
               special=False):
    """
    Calculates the expected cosmic ray spectrum, then returns the expected gains/losses in each bin by perturbing the overall spectram index (dgamma) and normalization (dnorm) down/up 

    Returns a tuple containing np.ndarrays 
        The first is the event change from a negative perturbation
        The second is the event change from a positive perturbation
    """
    perturb_gamma = dgamma != 0.0
    perturb_norm = dnorm != 0.0

    if perturb_gamma == perturb_norm:
        raise ValueError(
            "Cannot perturb both norm and gamma simultaneously. Also need to perturb at least one."
        )

    filename = os.path.join(perturb_folder, "cr_central.dat")
    null = SterileParams()

    if special:
        flux_func = lambda *objs: build_flux_sad(*objs, good_angles=True)
    else:
        if smearmode:
            flux_func = build_flux_sad
        else:
            flux_func = build_mc_flux if use_mc else build_flux

    if True:  #not os.path.exists(filename):
        kwargs = {'as_data': True}
        flux_data = flux_func(raw_flux(null, kwargs))
        pickle_save(flux_data, filename)
    else:
        flux_data = pickle_load(filename)

    p_plus = np.zeros(shape=np.shape(flux_data["stat_err"]))
    p_minus = np.zeros(shape=np.shape(flux_data["stat_err"]))

    if perturb_norm:
        mean_norm = 1.19
        return _flipper(flux_data["event_rate"],
                        ((mean_norm - dnorm) * flux_data["event_rate"],
                         (mean_norm + dnorm) * flux_data["event_rate"]))
    if perturb_gamma:
        # scale with
        #phi(e) * (E/(2.2TeV))^deltagamma

        e_edges = flux_data["e_edges"]
        for i_e in range(len(e_edges) - 1):
            for i_a in range(len(flux_data["a_edges"]) - 1):
                # we have the energies at the bin edges...
                # sooo
                mean_dgamma = 0.068
                effective_e = 0.5 * (e_edges[i_e] + e_edges[i_e + 1])
                p_plus[i_e][i_a] = flux_data["event_rate"][i_e][i_a] * pow(
                    effective_e / (2.2e3), -mean_dgamma - dgamma)
                p_minus[i_e][i_a] = flux_data["event_rate"][i_e][i_a] * pow(
                    effective_e / (2.2e3), -mean_dgamma + dgamma)

        return _flipper(flux_data["event_rate"], (p_minus, p_plus))
예제 #6
0
        for i_a in range(a_bins):
            for neut_type in range(2):
                inistate[i_a][i_e][neut_type][1] = 1.0
    return inistate


# either generate the file or load it in!
expected_fn = gen_filename(config["datapath"], "unitary_prob.dat", params)
if os.path.exists(expected_fn):
    final_probs = Data(expected_fn)
else:
    kwargs = {}
    kwargs["as_data"] = False
    kwargs["state_setter"] = state_setter
    kwargs["forced_filename"] = expected_fn
    final_probs = Data(raw_flux(params, kwargs=kwargs))

# now we need three keys
curr = "CC"  # doesn't matter
neut = "nuBar"
root_flav = "Mu"
flavors = ['E', 'Mu', 'Tau']
# flavor neutrino current
keys = ["_".join([flav, neut, curr]) for flav in flavors]

core_b = -0.98
mantle_b = -0.83

energies = np.logspace(2, 7, 200)
angles = np.linspace(-1, 0.2, 100)
    from cascade.utils import get_color

    do_fudge = False
    flavors = ["e", "mu", "tau"]

    if do_fudge:
        core_b = -0.98
        mantle_b = -0.83

        # let's see how the new predicted event rate looks!
        null = SterileParams()
        not_null = SterileParams(theta13=0.1609, theta23=0.2249, msq2=4.47)
        kwargs = {}
        kwargs["as_data"] = True
        atmo_data = raw_flux(null, kwargs=kwargs)
        astr_data = generate_astr_flux(null, as_data=True)
        n_e = 20
        n_a = 10

        raw_data = get_expectation(atmo_data, astr_data)

        e_bins = raw_data["e_edges"]
        a_bins = raw_data["a_edges"]
        events = raw_data["event_rate"]

        plt.pcolormesh(a_bins, e_bins, events)
        plt.xlim([-1, 0.2])
        plt.ylim([1e2, 1e6])
        plt.yscale('log')
        plt.vlines(core_b, ymin=1e2, ymax=10**6, colors="white", ls="-")