lucabaldini / hexsample

Solid-state hybrid detectors with hexagonal sampling.
https://lucabaldini.github.io/hexsample/
GNU General Public License v3.0
2 stars 0 forks source link

Intermittent unit test failure #43

Open lucabaldini opened 7 months ago

lucabaldini commented 7 months ago
=================================== FAILURES ===================================
________________________________ test_diffusion ________________________________

diff_sigma = 40.0

    def test_diffusion(diff_sigma=40.):
        """
        """
        grid = HexagonalGrid(HexagonalLayout.ODD_R, 2, 2, 0.005)
        evt = MonteCarloEvent(0., 8000., 0., 0., 0.05, 3000)
        x, y = evt.propagate(diff_sigma)
        readout = HexagonalReadout(HexagonalLayout.ODD_R, 10, 10, 0.005, 40., 1.)
        padding = Padding(1)
>       digi_event = readout.read(evt.timestamp, x, y, 500., padding, 80, 0)

tests/test_mc.py:35: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
hexsample/digi.py:412: in read
    roi, pha = self.trigger(signal, trg_threshold, min_col, min_row, padding)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <hexsample.digi.HexagonalReadout object at 0x7f17a77ffe50>
signal = array([[  72, 1430,    1,    0],
       [1426,   71,    0,    0]])
trg_threshold = 500.0, min_col = 4, min_row = 4
padding = Padding(top=1, right=1, bottom=1, left=1)

    def trigger(self, signal : np.ndarray, trg_threshold, min_col : int, min_row : int,
        padding : Padding) -> Tuple[RegionOfInterest, np.ndarray]:
        """Apply the trigger, calculate the region of interest, and pad the
        signal array to the proper dimension.

        .. warning::
           This is still incorrect at the edges of the readout chip, as we are
           not trimming the ROI (and the corresponding arrays) to the physical
           dimensions of the chip.
        """
        # pylint: disable=too-many-arguments, too-many-locals
        # Sum the sampled signal into the 2 x 2 trigger miniclusters.
        trg_signal = self.sum_miniclusters(signal)
        # Zero-suppress the trigger signal below the trigger threshold.
        self.zero_suppress(trg_signal, trg_threshold)
        # This is tricky, and needs to be documented properly---basically we
        # build arrays with all the (minicluster) columns and rows for which
        # at least one minicluster is above threshold. The multiplicative factor
        # of 2 serves the purpose of converting minicluster to pixel coordinates.
        trg_cols = 2 * np.nonzero(trg_signal.sum(axis=0))[0]
        trg_rows = 2 * np.nonzero(trg_signal.sum(axis=1))[0]
        # Build the actual ROI in chip coordinates and initialize the RegionOfInterest
        # object.
        roi_min_col = min_col + trg_cols.min() - padding.left
        roi_max_col = min_col + trg_cols.max() + 1 + padding.right
        roi_min_row = min_row + trg_rows.min() - padding.top
        roi_max_row = min_row + trg_rows.max() + 1 + padding.bottom
        roi = RegionOfInterest(roi_min_col, roi_max_col, roi_min_row, roi_max_row, padding)
        # And now the actual PHA array: we start with all zeroes...
        pha = np.full(roi.shape(), 0.)
        # ...and then we patch the original signal array into the proper submask.
        num_rows, num_cols = signal.shape
        start_row = padding.bottom - trg_rows.min()
        start_col = padding.left - trg_cols.min()
>       pha[start_row:start_row + num_rows, start_col:start_col + num_cols] = signal
E       ValueError: could not broadcast input array from shape (2,4) into shape (2,3)

hexsample/digi.py:328: ValueError