Beispiel #1
0
def _generate_pad_collection(data, pads=None):

    sm = mpl.cm.ScalarMappable(cmap=pad_cm, norm=LogNorm())
    sm.set_array(data)
    colors = sm.to_rgba(data)

    if pads is None:
        pads = generate_pad_plane()

    c = mpl.collections.PolyCollection(pads, facecolors=colors, edgecolors='none')
    return c
Beispiel #2
0
def event_view(evt, pads=None):

    if pads is None:
        pads = generate_pad_plane()

    data = evt.xyzs(pads)
    hits = evt.hits()
    mesh = evt.traces['data'].sum(0)

    fig = plt.figure()

    chax = fig.add_subplot(223)
    chax.set_xlim(0, 511)
    chax.set_ylim(-290, 290)
    chax.set_axis_bgcolor('#c4cccc')
    chax.scatter(data[:, 2],
                 data[:, 1],
                 marker='.',
                 linewidths=0,
                 s=2,
                 cmap='winter',
                 norm=LogNorm(),
                 c=data[:, 3])
    for sp in chax.spines.values():
        sp.visible = False

    msax = fig.add_subplot(221, sharex=chax)
    msax.plot(mesh)

    pdax = fig.add_subplot(224, sharey=chax)
    pdax.axison = False
    pdax.set_aspect('equal')
    pdax.set_xlim(-250, 250)

    hit_pads = _generate_pad_collection(hits, pads)
    bg_pads = mpl.collections.PolyCollection(pads,
                                             facecolors='white',
                                             edgecolors='none')
    bg_circ = plt.Circle((0, 0),
                         radius=290.,
                         facecolor='#c4cccc',
                         edgecolor='none')

    bg_circ.set_zorder(0)
    bg_pads.set_zorder(1)
    hit_pads.set_zorder(2)

    pdax.add_artist(bg_circ)
    pdax.add_collection(bg_pads)
    pdax.add_collection(hit_pads)

    return fig
Beispiel #3
0
def _generate_pad_collection(data, pads=None):

    sm = mpl.cm.ScalarMappable(cmap=pad_cm, norm=LogNorm())
    sm.set_array(data)
    colors = sm.to_rgba(data)

    if pads is None:
        pads = generate_pad_plane()

    c = mpl.collections.PolyCollection(pads,
                                       facecolors=colors,
                                       edgecolors='none')
    return c
Beispiel #4
0
def show_pad_plane(pads=None):
    """Displays the pad plane"""

    if pads is None:
        pads = generate_pad_plane()

    c = mpl.collections.PolyCollection(pads)

    fig, ax = plt.subplots()

    ax.add_collection(c)
    ax.autoscale_view()

    fig.show()
Beispiel #5
0
def show_pad_plane(pads=None):
    """Displays the pad plane"""

    if pads is None:
        pads = generate_pad_plane()

    c = mpl.collections.PolyCollection(pads)

    fig, ax = plt.subplots()

    ax.add_collection(c)
    ax.autoscale_view()

    fig.show()
Beispiel #6
0
    def __init__(self, config, pedestals=None, corrupt_cobo_clocks=False):
        config = copy(config)
        config['mass_num'] = config['beam_mass']
        config['charge_num'] = config['beam_charge']
        config['tracker_max_en'] = config['beam_enu0'] * config[
            'beam_mass'] * 1.1  # The last part is just to be safe

        self.beam_sim = EventSimulator(config)

        beam_evt, _ = self.beam_sim.make_event(0, 0, 1.0, config['beam_enu0'],
                                               0, pi)
        self.beam_mesh = sum((v for v in beam_evt.values()))
        self.beam_mesh /= self.beam_mesh.max()

        pads = generate_pad_plane()
        self.bigpads = np.where(
            np.round(np.abs(pads[:, 1, 1] - pads[:, 0, 1])) > 6)[0]
        self.smallpads = np.where(
            np.round(np.abs(pads[:, 1, 1] - pads[:, 0, 1])) < 6)[0]
        assert (len(self.bigpads) + len(self.smallpads) == 10240)

        self.baseline_depression_scale = config['baseline_depression_scale']
        self.big_pad_multiplier = config['big_pad_multiplier']

        self.noise_stddev = config['noise_stddev']

        if pedestals is not None:
            self.pedestals = pedestals
        else:
            self.pedestals = np.zeros(10240, dtype='float64')

        self.padmap = read_lookup_table(
            config['padmap_path'])  # maps (cobo, asad, aget, ch) -> pad
        self.pad_cobos = np.zeros(
            10240, dtype=np.int64)  # List index = pad, value = cobo
        for (cobo, asad, aget, ch), pad in self.padmap.items():
            self.pad_cobos[pad] = cobo

        self.cobo_offsets = self.make_cobo_clock_offsets()
        if corrupt_cobo_clocks:
            self.apply_cobo_clock_patch()
Beispiel #7
0
def event_view(evt, pads=None):

    if pads is None:
        pads = generate_pad_plane()

    data = evt.xyzs(pads)
    hits = evt.hits()
    mesh = evt.traces['data'].sum(0)

    fig = plt.figure()

    chax = fig.add_subplot(223)
    chax.set_xlim(0, 511)
    chax.set_ylim(-290, 290)
    chax.set_axis_bgcolor('#c4cccc')
    chax.scatter(data[:, 2], data[:, 1], marker='.', linewidths=0, s=2, cmap='winter', norm=LogNorm(), c=data[:, 3])
    for sp in chax.spines.values():
        sp.visible = False

    msax = fig.add_subplot(221, sharex=chax)
    msax.plot(mesh)

    pdax = fig.add_subplot(224, sharey=chax)
    pdax.axison = False
    pdax.set_aspect('equal')
    pdax.set_xlim(-250, 250)

    hit_pads = _generate_pad_collection(hits, pads)
    bg_pads = mpl.collections.PolyCollection(pads, facecolors='white', edgecolors='none')
    bg_circ = plt.Circle((0, 0), radius=290., facecolor='#c4cccc', edgecolor='none')

    bg_circ.set_zorder(0)
    bg_pads.set_zorder(1)
    hit_pads.set_zorder(2)

    pdax.add_artist(bg_circ)
    pdax.add_collection(bg_pads)
    pdax.add_collection(hit_pads)


    return fig
Beispiel #8
0
This module contains code to track a particle in data.

"""

from __future__ import division, print_function
import numpy as np
from sklearn.cluster import DBSCAN
from functools import lru_cache

from pytpc.constants import *
import pytpc.simulation as sim
from pytpc.ukf import UnscentedKalmanFilter as UKF
from pytpc.padplane import generate_pad_plane


pads = generate_pad_plane()  # FIXME: Take rotation angle
pr = np.round(pads)


@lru_cache(maxsize=10240)
def find_adj(p, depth=0):
    """Recursively finds the neighboring pads to pad `p`.

    This function returns a set of neighboring pad numbers. The neighboring pads are determined by looking for
    all pads that (approximately) share a vertex with the given pad.

    .. note::
        Since only vertices are compared, this algorithm will not identify a neighboring pad that only shares a side,
        and not a vertex.

    The `depth` parameter allows recursion an arbitrary number of times. For instance, if `depth == 1`, the function
Beispiel #9
0
"""Particle Tracking

This module contains code to track a particle in data.

"""

from __future__ import division, print_function
import numpy as np
from functools import lru_cache

from pytpc.padplane import generate_pad_plane


pads = generate_pad_plane()  # FIXME: Take rotation angle
pr = np.round(pads)


@lru_cache(maxsize=10240)
def find_adj(p, depth=0):
    """Recursively finds the neighboring pads to pad `p`.

    This function returns a set of neighboring pad numbers. The neighboring pads are determined by looking for
    all pads that (approximately) share a vertex with the given pad.

    .. note::
        Since only vertices are compared, this algorithm will not identify a neighboring pad that only shares a side,
        and not a vertex.

    The `depth` parameter allows recursion an arbitrary number of times. For instance, if `depth == 1`, the function
    will return the pads adjacent to pad `p` and those adjacent to its immediate neighbors.
Beispiel #10
0
def pad_plot(data, pads=None, scale='log', cmap_type='seq'):
    """ Plot the given data on the pads of the Micromegas.

    Parameters
    ----------
    data : array-like
        The data to be plotted. This should be a 1-D array with an entry for each pad.
    pads : array-like, optional
        The vertices of the pads. If this is not provided, the default pad plane will be generated using
        `generate_pad_plane`. This can be used for a rotated pad plane, for example.

    Returns
    -------
    fig : matplotlib figure
        The generated figure
    """

    data = numpy.asanyarray(data)

    if scale is 'log':
        nm = LogNorm()
    elif scale is 'linear':
        nm = None
    else:
        raise ValueError('invalid scale. Must be in set {}'.format(('log', 'linear')))

    if cmap_type == 'div':
        cmap = 'BrBG'
    else:
        cmap = pad_cm

    sm = mpl.cm.ScalarMappable(cmap=cmap, norm=nm)
    sm.set_array(data)
    if cmap_type == 'div':
        extr = numpy.abs(data).max()
        sm.set_clim(-extr, extr)
    colors = sm.to_rgba(data)

    if pads is None:
        pads = generate_pad_plane()
    else:
        pads = numpy.asanyarray(pads)

    c = mpl.collections.PolyCollection(pads, facecolors=colors, edgecolors='none')
    cbg = mpl.collections.PolyCollection(pads, facecolors='white', edgecolors='none')

    c.set_zorder(2)
    cbg.set_zorder(1)

    fig, ax = plt.subplots()

    ax.axison = False

    bdcirc = plt.Circle((0, 0), radius=290., facecolor='#c4cccc', edgecolor='none')
    bdcirc.set_zorder(0)
    ax.add_artist(bdcirc)

    ax.add_collection(cbg)
    ax.add_collection(c)

    plt.axis('equal')

    cbar = fig.colorbar(sm)
    cbar.set_label('Activation')

    return fig
Beispiel #11
0
def pad_plot(data, pads=None, scale='log', cmap=pad_cm, cmin=None, cmax=None):
    """ Plot the given data on the pads of the Micromegas.

    Parameters
    ----------
    data : array-like
        The data to be plotted. This should be a 1-D array with an entry for each pad.
    pads : array-like, optional
        The vertices of the pads. If this is not provided, the default pad plane will be generated using
        `generate_pad_plane`. This can be used for a rotated pad plane, for example.
    scale : string, optional
        Scale for color map. 'log' for log scale, or 'linear' for linear.
    cmap : string or Matplotlib color map, optional
        Matplotlib color map or name of a color map
    cmin, cmax: float, optional
        The min and max values for the color scale. If omitted, Matplotlib will choose its default values.

    Returns
    -------
    fig : Figure
        The generated figure
    sm : matplotlib.cm.ScalarMappable
        The color mapping object used in the plot. This can be used to generate a colorbar with
        `plt.colorbar(sm)`.
    """

    data = numpy.asanyarray(data)

    if scale is 'log':
        nm = LogNorm()
    elif scale is 'linear':
        nm = None
    else:
        raise ValueError('invalid scale. Must be in set {}'.format(
            ('log', 'linear')))

    sm = mpl.cm.ScalarMappable(cmap=cmap, norm=nm)
    sm.set_array(data)
    sm.set_clim(cmin, cmax)
    colors = sm.to_rgba(data)

    if pads is None:
        pads = generate_pad_plane()
    else:
        pads = numpy.asanyarray(pads)

    c = mpl.collections.PolyCollection(pads,
                                       facecolors=colors,
                                       edgecolors='none')
    cbg = mpl.collections.PolyCollection(pads,
                                         facecolors='white',
                                         edgecolors='none')

    c.set_zorder(2)
    cbg.set_zorder(1)

    fig, ax = plt.subplots()

    ax.axison = False

    bdcirc = plt.Circle((0, 0),
                        radius=290.,
                        facecolor='#c4cccc',
                        edgecolor='none')
    bdcirc.set_zorder(0)
    ax.add_artist(bdcirc)

    ax.add_collection(cbg)
    ax.add_collection(c)

    plt.axis('equal')

    return fig, sm