예제 #1
0
import numpy as np
import sys

from NuRadioMC.utilities.Veff import get_Veff_Aeff, get_Veff_Aeff_array

if __name__ == "__main__":

	depth = ''
	if(len(sys.argv) == 4):
		print("no depth specified!")
		sys.exit()
	else:
		depth = sys.argv[1]

	top_dir='/data/user/brianclark/Gen2/test_out/'
	data = get_Veff_Aeff(top_dir+depth+'m/', n_cores=8)
	Veffs, energies, energies_low, energies_up, zenith_bins, utrigger_names = get_Veff_Aeff_array(data)
	np.savez('veffs_'+depth+'m.npz',Veffs=Veffs, energies=energies, energies_low=energies_low, energies_up=energies_up, zenith_bins=zenith_bins, utrigger_names=utrigger_names)

"""
data_Veff = get_Veff_Aeff(folder)
"""
Although data_Veff has all the information we need, it is a bit cumbersome
to read directly, so that's why we resort to the function get_Veff_array. This
function returns a 5-element tuple with:
- An 4-D array with the effective volumes
- A 1-D array with the centre energies for each bin (if point_bins=False)
- The zenith bins for each one of the zenith band simulations (in our case, we
only have a single zenith band equal to the whole sky)
- A list with the trigger names
- A 1-D array with the angular weights for each zenith band simulation. If the solid
angle for a simulation set is larger than for the other, it should carry more weight
when we try to patch them all together to get the total volumes.
"""
Veff_array, energies, energies_low, energies_high, zenith_bins, trigger_names = get_Veff_Aeff_array(
    data_Veff)
"""
There are some functions with the same syntax to calculate effective areas for
atmospheric muon simulations: get_Aeff and get_Aeff_array. Keep in mind that the
latter returns a 4-element tuple, with no weights.

The structure of the 4-D Veff_array returned is as follows: the first dimension
chooses the energy, the second chooses the zenith band and the third chooses
the trigger:

Veff_item = Veff_array[i_energy, i_zenith, i_trigger]

Then, each Veff_item has three numbers.
- Veff_item[0] is the effective volume
- Veff_item[1] is the poissonian uncertainty of the effective volume
- Veff_item[2] is the sum of the weights of all the triggering events contained
예제 #3
0
def get_flavor_zenith_averages(
        det, det_dict):  # det ('deep') and the associated dictionary

    if 'trigger' not in det_dict.keys():
        print("A trigger is not specified")
    trigger = det_dict['trigger']

    tmp = {}  # a holder
    tmp[trigger] = {}

    for iF, flavor in enumerate(flavors):

        # first, the low energies
        filename = f'data__{deep_det}__{shallow_det}/{det}_{flavor}_lo.pkl'
        data = pickle.load(open(filename, 'br'))
        output, energies, energies_low, energies_up, zenith_bins, trigger_names = get_Veff_Aeff_array(
            data)

        if trigger not in trigger_names:
            print("The requested trigger is not available. Options are {}".
                  format(trigger_names))
        tmp['E'] = energies
        tmp['zen_bins'] = zenith_bins
        tmp[trigger][flavor] = {}
        tmp[trigger][flavor][
            'Veff_zen'] = output[:, :,
                                 get_index(trigger, trigger_names), 0]
        tmp[trigger][flavor]['Veff'] = np.average(
            output[:, :, get_index(trigger, trigger_names), 0], axis=1)
        tmp[trigger][flavor][
            'Vefferror'] = tmp[trigger][flavor]['Veff'] / np.sum(
                output[:, :, get_index(trigger, trigger_names),
                       2], axis=1)**0.5
        tmp[trigger][flavor]['Vefferror_up'] = np.sum(
            (output[:, :, get_index(trigger, trigger_names), 4] -
             output[:, :, get_index(trigger, trigger_names), 0])**2,
            axis=1)**0.5 / output.shape[1]
        tmp[trigger][flavor]['Vefferror_down'] = np.sum(
            (output[:, :, get_index(trigger, trigger_names), 0] -
             output[:, :, get_index(trigger, trigger_names), 3])**2,
            axis=1)**0.5 / output.shape[1]

        # print("low energy energies {}".format(energies))
        # print("low energy veffs {}".format(np.average(output[:, :, get_index(trigger, trigger_names), 0], axis=1)))
        # print("low energy veffs vs zen {}".format(output[:, :, get_index(trigger, trigger_names), 0]))

        # now, the high energies
        filename = f'data__{deep_det}__{shallow_det}/{det}_{flavor}_hi.pkl'
        data = pickle.load(open(filename, 'br'))
        output, energies, energies_low, energies_up, zenith_bins, trigger_names = get_Veff_Aeff_array(
            data)

        if trigger not in trigger_names:
            print("The requested trigger is not available. Options are {}".
                  format(trigger_names))

        # Brian did something silly, and for the 1.5km station, his files accidentally contain an incorrect calculation for the low energies
        # so we need to splice those away, which are index 0 (1E16), 1 (1E16.5), 2 (1E17), 3 (1E17.5), 4 (1E18)
        start_splice_index = 0
        if flavor == 'mu' and det == 'shallow' and shallow_det == 'surface_1.50km':
            start_splice_index = 5

        tmp['E'] = np.append(
            tmp['E'], energies[start_splice_index:]
        )  # we assume we have the same energies simulated for each flavor
        tmp[trigger][flavor]['Veff_zen'] = np.append(
            tmp[trigger][flavor]['Veff_zen'],
            output[:, :, get_index(trigger, trigger_names),
                   0][start_splice_index:])
        tmp[trigger][flavor]['Veff'] = np.append(
            tmp[trigger][flavor]['Veff'],
            np.average(output[:, :, get_index(trigger, trigger_names), 0],
                       axis=1)[start_splice_index:])
        tmp[trigger][flavor]['Vefferror'] = np.append(
            tmp[trigger][flavor]['Vefferror'],
            np.average(output[:, :, get_index(trigger, trigger_names), 0],
                       axis=1)[start_splice_index:] /
            np.sum(output[:, :, get_index(trigger, trigger_names), 2],
                   axis=1)[start_splice_index:]**0.5)
        tmp[trigger][flavor]['Vefferror_up'] = np.append(
            tmp[trigger][flavor]['Vefferror_up'],
            np.sum((output[:, :, get_index(trigger, trigger_names), 4] -
                    output[:, :, get_index(trigger, trigger_names),
                           0])[start_splice_index:]**2,
                   axis=1)**0.5 / output.shape[1])
        tmp[trigger][flavor]['Vefferror_down'] = np.append(
            tmp[trigger][flavor]['Vefferror_down'],
            np.sum((output[:, :, get_index(trigger, trigger_names), 0] -
                    output[:, :, get_index(trigger, trigger_names),
                           3])[start_splice_index:]**2,
                   axis=1)**0.5 / output.shape[1])

        # print("high energy energies {}".format(energies[start_splice_index:]))
        # print("high energy veffs {}".format(np.average(output[:, :, get_index(trigger, trigger_names), 0], axis=1)[start_splice_index:]))
        # print("\n")

    # do the flavor average
    tmp[trigger]['Veff'] = 0
    tmp[trigger]['Vefferror'] = 0
    tmp[trigger]['Vefferror_down'] = 0
    tmp[trigger]['Vefferror_up'] = 0
    tmp[trigger]['Veff_zen'] = 0
    for flavor in flavors:
        tmp[trigger]['Veff'] += tmp[trigger][flavor]['Veff']
        tmp[trigger]['Vefferror'] += tmp[trigger][flavor]['Vefferror']
        tmp[trigger]['Veff_zen'] += tmp[trigger][flavor]['Veff_zen']
        tmp[trigger]['Vefferror_up'] += tmp[trigger][flavor]['Vefferror_up']**2
        tmp[trigger]['Vefferror_down'] += tmp[trigger][flavor][
            'Vefferror_down']**2
    tmp[trigger]['Vefferror'] /= 3
    tmp[trigger]['Veff_zen'] /= 3
    tmp[trigger]['Veff'] /= 3
    tmp[trigger]['Vefferror_up'] = tmp[trigger]['Vefferror_up']**0.5 / 3
    tmp[trigger]['Vefferror_down'] = tmp[trigger]['Vefferror_down']**0.5 / 3

    return tmp