Example #1
0
    def _get_muon_entry(self, frame, muon):

        entry = mu_utils.get_muon_initial_point_inside(muon, self._convex_hull)
        if entry is None:
            # get closest approach point as entry approximation
            entry = mu_utils.get_muon_closest_approach_to_center(frame, muon)

        return entry
Example #2
0
    def _get_particle_entry(self, particle):

        entry = mu_utils.get_muon_initial_point_inside(particle,
                                                       self._convex_hull)
        if entry is None:
            # get closest approach point as entry approximation
            entry = mu_utils.get_particle_closest_approach_to_position(
                particle, dataclasses.I3Position(0, 0, 0))
        return entry
Example #3
0
def get_tau_entry_info(frame, tau, convex_hull):
    """Helper function for 'get_cascade_labels'.

    Get tau information for point of entry, or closest approach point,
    if tau does not enter the volume defined by the convex_hull.

    Parameters
    ----------
    frame : I3Frame
        Current I3Frame needed to retrieve I3MCTree
    tau : I3Particle
        Tau I3Particle for which to get the entry information.
    convex_hull : scipy.spatial.ConvexHull, optional
        Defines the desired convex volume.

    Returns
    -------
    I3Position, double, double
        Entry Point (or closest approach point)
        Time of entry point (or closest approach point)
        Energy at entry point (or closest approach point)
        Warning: If 'I3MCTree' does not exist in frame, this
                 will instead return the muon energy
    """
    entry = mu_utils.get_muon_initial_point_inside(tau, convex_hull)
    if entry is None:
        # get closest approach point as entry approximation
        entry = mu_utils.get_particle_closest_approach_to_position(
            tau, dataclasses.I3Position(0, 0, 0))
    time = mu_utils.get_muon_time_at_position(tau, entry)

    # Todo: calculate energy at point of entry for tau as it is done for muon
    # For now, just provide the total tau energy
    if 'I3MCTree' not in frame:
        energy = tau.energy
    else:
        energy = tau.energy
        # energy = mu_utils.get_muon_energy_at_position(frame, tau, entry)
    return entry, time, energy
Example #4
0
def get_muon_information(frame,
                         muon,
                         dom_pos_dict,
                         convex_hull,
                         pulse_map_string='InIcePulses',
                         mcpe_series_map_name='I3MCPESeriesMap'):
    '''Function to get labels for a muon

    Parameters
    ----------
    muon : I3Particle
        Muon.

    dom_pos_dict : dict
        Dictionary with key of form (string,key) : (x,y,z)
        for all DOMs.
        string and key are of type int

    convex_hull : scipy.spatial.ConvexHull
        defining the desired convex volume

    pulse_map_string : key of pulse map in frame,
        of which the pulses should be computed for

    mcpe_series_map_name : key of mcpe series map in frame

    Returns
    -------
    info_dict : dictionary
        Dictionary with all labels
    '''

    # check if muon exists
    if muon is None:
        # create and return nan Values
        zero = dataclasses.I3Position(0, 0, 0)
        zero_dist_icecube = geometry.distance_to_icecube_hull(zero)
        zero_dist_deepcore = geometry.distance_to_deepcore_hull(zero)

        zero_dict = {
            'NoOfHitDOMs': 0,
            'NoOfPulses': 0,
            'TotalCharge': 0.,
            'COGDistanceToBorder': zero_dist_icecube,
            'COGDistanceToDeepCore': zero_dist_deepcore,
            'COGx': zero.x,
            'COGy': zero.y,
            'COGz': zero.z,
            'EntryDistanceToDeepCore': zero_dist_deepcore,
            'TimeAtEntry': 0.,
            'Entryx': zero.x,
            'Entryy': zero.y,
            'Entryz': zero.z,
            'EnergyEntry': 0.,
            'CenterDistanceToBorder': zero_dist_icecube,
            'CenterDistanceToDeepCore': zero_dist_deepcore,
            'TimeAtCenter': 0.,
            'Centerx': zero.x,
            'Centery': zero.y,
            'Centerz': zero.z,
            'EnergyCenter': 0.,
            'ExitDistanceToDeepCore': zero_dist_deepcore,
            'TimeAtExit': 0.,
            'Exitx': zero.x,
            'Exity': zero.y,
            'Exitz': zero.z,
            'EnergyExit': 0.,
            'InDetectorTrackLength': 0.,
            'InDetectorEnergyLoss': 0.,
            'Azimuth': 0.,
            'Zenith': 0.,
            'Energy': 0.,
            'TotalTrackLength': 0.,
            'Vertexx': zero.x,
            'Vertexy': zero.y,
            'Vertexz': zero.z,
            'VertexDistanceToBorder': zero_dist_icecube,
            'VertexDistanceToDeepCore': zero_dist_deepcore,
        }
        return zero_dict

    # create empty information dictionary
    info_dict = {}

    # get labels depending on pulse map
    pulse_map = general.get_pulse_map(
        frame,
        muon,
        pulse_map_string=pulse_map_string,
        mcpe_series_map_name=mcpe_series_map_name)

    NoOfHitDOMs = len(pulse_map.keys())
    NoOfPulses = 0
    TotalCharge = 0.
    COG = np.array([0., 0., 0.])

    if NoOfHitDOMs > 0:
        for key in pulse_map.keys():
            for pulse in pulse_map[key]:
                NoOfPulses += 1
                TotalCharge += pulse.charge
                pos = np.array(dom_pos_dict[(key.string, key.om)])
                COG += pos * pulse.charge
        COG = COG / TotalCharge
    COG = dataclasses.I3Position(*COG)

    COGDistanceToBorder = geometry.distance_to_icecube_hull(COG)
    COGDistanceToDeepCore = geometry.distance_to_deepcore_hull(COG)

    # get entry point labels
    Entry = mu_utils.get_muon_initial_point_inside(muon, convex_hull)
    if Entry:
        TimeAtEntry = mu_utils.get_muon_time_at_position(muon, Entry)
        EntryDistanceToDeepCore = geometry.distance_to_deepcore_hull(Entry)
        EnergyEntry = mu_utils.get_muon_energy_at_position(frame, muon, Entry)
    else:
        # handle missing values
        Entry = dataclasses.I3Position(0, 0, 0)
        TimeAtEntry = 0
        EntryDistanceToDeepCore = 0
        EnergyEntry = 0

    # get exit point labels
    Exit = mu_utils.get_muon_exit_point(muon, convex_hull)
    if Exit:
        TimeAtExit = mu_utils.get_muon_time_at_position(muon, Exit)
        ExitDistanceToDeepCore = geometry.distance_to_deepcore_hull(Exit)
        EnergyExit = mu_utils.get_muon_energy_at_position(frame, muon, Exit)
    else:
        # handle missing values
        Exit = dataclasses.I3Position(0, 0, 0)
        TimeAtExit = 0
        ExitDistanceToDeepCore = 0
        EnergyExit = 0

    # get center point labels
    Center = mu_utils.get_muon_closest_approach_to_center(frame, muon)
    TimeAtCenter = mu_utils.get_muon_time_at_position(muon, Center)
    CenterDistanceToBorder = geometry.distance_to_icecube_hull(Center)
    CenterDistanceToDeepCore = geometry.distance_to_deepcore_hull(Center)
    EnergyCenter = mu_utils.get_muon_energy_at_position(frame, muon, Center)

    # other labels
    InDetectorTrackLength = mu_utils.get_muon_track_length_inside(
        muon, convex_hull)
    InDetectorEnergyLoss = mu_utils.get_muon_energy_deposited(
        frame, convex_hull, muon)

    # add labels to info_dict
    info_dict['NoOfHitDOMs'] = NoOfHitDOMs
    info_dict['NoOfPulses'] = NoOfPulses
    info_dict['TotalCharge'] = TotalCharge

    info_dict['COGDistanceToBorder'] = COGDistanceToBorder
    info_dict['COGDistanceToDeepCore'] = COGDistanceToDeepCore
    info_dict['COGx'] = COG.x
    info_dict['COGy'] = COG.y
    info_dict['COGz'] = COG.z

    info_dict['EntryDistanceToDeepCore'] = EntryDistanceToDeepCore
    info_dict['TimeAtEntry'] = TimeAtEntry
    info_dict['Entryx'] = Entry.x
    info_dict['Entryy'] = Entry.y
    info_dict['Entryz'] = Entry.z
    info_dict['EnergyEntry'] = EnergyEntry

    info_dict['CenterDistanceToBorder'] = CenterDistanceToBorder
    info_dict['CenterDistanceToDeepCore'] = CenterDistanceToDeepCore
    info_dict['TimeAtCenter'] = TimeAtCenter
    info_dict['Centerx'] = Center.x
    info_dict['Centery'] = Center.y
    info_dict['Centerz'] = Center.z
    info_dict['EnergyCenter'] = EnergyCenter

    info_dict['ExitDistanceToDeepCore'] = ExitDistanceToDeepCore
    info_dict['TimeAtExit'] = TimeAtExit
    info_dict['Exitx'] = Exit.x
    info_dict['Exity'] = Exit.y
    info_dict['Exitz'] = Exit.z
    info_dict['EnergyExit'] = EnergyExit

    info_dict['InDetectorTrackLength'] = InDetectorTrackLength
    info_dict['InDetectorEnergyLoss'] = InDetectorEnergyLoss

    info_dict['Azimuth'] = muon.dir.azimuth
    info_dict['Zenith'] = muon.dir.zenith
    info_dict['Energy'] = muon.energy
    info_dict['TotalTrackLength'] = muon.length
    info_dict['Vertexx'] = muon.pos.x
    info_dict['Vertexy'] = muon.pos.y
    info_dict['Vertexz'] = muon.pos.z
    info_dict['VertexDistanceToBorder'] = geometry.distance_to_icecube_hull(
        muon.pos)
    info_dict['VertexDistanceToDeepCore'] = geometry.distance_to_deepcore_hull(
        muon.pos)

    return info_dict
Example #5
0
def get_muon_bundle_information(frame, convex_hull, energy_threshold=20):
    """Calculate muon bundle information:

    Number of muons for certain selections, relative leading muon energy,
    bundle energy.

    This will calculate all muons in MMCTrackList for 'cyl', but for 'entry'
    starting muons will not be considered.

    Parameters
    ----------
    frame : I3Frame
        Current I3Frame needed to retrieve MMCTrackList
    convex_hull : scipy.spatial.ConvexHull, optional
        Defines the desired convex volume.
    energy_threshold : int, optional
        Energy threshold in GeV at which to count muons.
        Muons below this threshold will be discarded.

    Returns
    -------
    dict
        A dictionary with the calculated labels.
    """
    bundle_info = {}

    energies_at_entry = []
    energies_at_cyl = []
    num_muons = 0

    for particle in frame['MMCTrackList']:
        muon = particle.particle
        # Check if particle is a muon
        if not mu_utils.is_muon(muon):
            continue

        # Determine entrance point into the convex hull
        initial_point = mu_utils.get_muon_initial_point_inside(
            muon, convex_hull)

        # Get energy at entry point
        if initial_point is not None:
            # check if it is a starting muon, e.g. if intial point inside
            # is the same as the vertex (Discard muon in this case)
            if (initial_point - muon.pos).magnitude > 1:
                entry_energy = mu_utils.get_muon_energy_at_position(
                    frame, muon, initial_point)
                energies_at_entry.append(entry_energy)

        cyl_energy = particle.Ei
        energies_at_cyl.append(cyl_energy)
        num_muons += 1

    energies_at_entry = np.array(energies_at_entry)
    energies_at_entry = energies_at_entry[np.isfinite(energies_at_entry)]
    mult_mask = energies_at_entry >= energy_threshold
    bundle_info['num_muons_at_entry'] = len(energies_at_entry)
    bundle_info['num_muons_at_entry_above_threshold'] = len(
        energies_at_entry[mult_mask])
    if len(energies_at_entry) > 0:
        bundle_info['leading_energy_rel_entry'] = np.max(
            energies_at_entry) / np.sum(energies_at_entry)
    else:
        bundle_info['leading_energy_rel_entry'] = float('NaN')

    energies_at_cyl = np.array(energies_at_cyl)
    energies_at_cyl = energies_at_cyl[np.isfinite(energies_at_cyl)]
    mult_mask = energies_at_cyl >= energy_threshold
    bundle_info['num_muons_at_cyl'] = len(energies_at_cyl)
    bundle_info['num_muons_at_cyl_above_threshold'] = len(
        energies_at_cyl[mult_mask])

    if len(energies_at_cyl) > 0:
        bundle_info['leading_energy_rel_cyl'] = np.max(
            energies_at_cyl) / np.sum(energies_at_cyl)
    else:
        bundle_info['leading_energy_rel_cyl'] = float('NaN')

    bundle_info['bundle_energy_at_entry'] = np.sum(energies_at_entry)
    bundle_info['bundle_energy_at_cyl'] = np.sum(energies_at_cyl)
    bundle_info['num_muons'] = num_muons

    return bundle_info