Skip to content

Fix hits event small event binning#130

Merged
cmargalejo merged 4 commits into
masterfrom
cris_fix_hitsEvent_smallevent_binning
Jun 22, 2026
Merged

Fix hits event small event binning#130
cmargalejo merged 4 commits into
masterfrom
cris_fix_hitsEvent_smallevent_binning

Conversation

@cmargalejo

@cmargalejo cmargalejo commented Jun 19, 2026

Copy link
Copy Markdown
Member

cmargalejo Medium: 109 Powered by Pull Request Badge

Summary

The event browser drew small, localized TRestDetectorHitsEvents (e.g. X-ray
calibration hits) as solid colored vertical bands instead of a recognizable hit
cluster. This PR fixes that, hardens the drawing code, and improves the
DrawEvent layout.

What changed (3 commits)

  1. Revert default DrawEvent pitch to use the existing adaptive binning
    Reverts commit 5c7b983d, which set the default option to hist(Cont1,col)[3].
    The [3] forces a 3 mm bin pitch, so nBins = round(range/3) rounds to 0–1 bins
    for events smaller than 3 mm, collapsing them into a single band. Removing it
    restores the adaptive binning that TRestHits::GetBoundaries already computes.
    ⚠️ I could not find the original purpose of the [3] pitch. If anyone knows
    why it was added, or disagrees with this revert, please let me know.

  2. Guard DrawHistograms against degenerate events
    GetBoundaries reads front()/back(), undefined for an empty projection (an
    event with no hits of a given type) — a latent crash. Also clamp nBins >= 1.
    No effect on normal events.

  3. Fix pad layout and add a 3D view for strip events
    Add sub-pad margins so axis titles are no longer cut off (most visibly the
    bottom-right Z histogram). When there is no XY projection (strip readouts with
    XZ/YZ hits), use the otherwise-empty top-right pad for a 3D view: each strip hit
    is a line along its undetermined axis (XZ→Y, YZ→X, XY→Z), colored by energy, and
    the XZ/YZ crossings (reconstructed hit positions) are marked with dots — which
    draws the event in 3D.

Notes

  • Scope is the viewer only (DrawEvent / DrawHistograms); the analysis-facing
    GetXYHistogram / GetXZHistogram / GetYZHistogram are untouched.
  • The 3D crossing markers include ambiguous "ghost" combinations for
    high-multiplicity events — inherent to strip readouts, not a bug.

Before / after

Before — a small X-ray event (572900) collapses into solid vertical bands, and the
bottom-right Z histogram is clipped:

Screenshot 2026-06-18 111625

After — same event: adaptive binning, full axis titles, and the new 3D view with the
strip-crossing markers (reconstructed positions):

Screenshot 2026-06-19 182435

After — an alpha event: the 3D crossings trace out the track cloud:

Screenshot 2026-06-19 182538

cmargalejo and others added 4 commits June 19, 2026 18:15
Reverts commit 5c7b983, which changed the default DrawEvent option from
"hist(Cont1,col)" to "hist(Cont1,col)[3]". That "[3]" sets a fixed 3 mm
pitch, which triggers the `if (pitch > 0)` branch in DrawHistograms and
overrides the adaptive bin count that TRestHits::GetBoundaries already
computes from the data spacing. With the fixed pitch,
nBins = round(range/3) rounds to 0-1 bins for events smaller than 3 mm,
collapsing small/localized events (e.g. X-ray hits) into a single solid
band. Removing the "[3]" restores pitch = 0, so the override is skipped
and the existing adaptive GetBoundaries binning is used again.

I have not been able to determine the original purpose of the "[3]" pitch.
If anyone knows why it was added, or disagrees with this revert, please
let me know.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TRestHits::GetBoundaries reads dist.front()/back(), which is undefined
behaviour when a projection vector is empty (an event with no hits of a
given type, e.g. only XZ hits and no Y-defining hits). Wrap it in a small
helper that returns a safe default range and one bin for an empty
projection.

Also clamp nBins to at least 1 after the optional pitch override, so a
degenerate event (all hits sharing a coordinate, or a sub-pitch extent)
can never request a 0-bin histogram.

These guards do not change the rendering of normal events.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add bottom and left margins to each sub-pad so the axis titles are no
longer cut off (most visibly the bottom-right Z histogram).

When an event has no XY projection (strip readouts with XZ/YZ hits), use
the empty top-right pad for a 3D view. Each strip hit is drawn as a line
along its undetermined axis (XZ -> Y, YZ -> X, XY -> Z), colored by
energy. Where an XZ and a YZ line share the same Z they cross, and that
crossing is the reconstructed hit position, marked with a dot. This draws
the event in 3D. With many strips at the same Z some crossings are
ambiguous "ghost" points, which is normal for strip readouts.

The 3D objects are owned by the pad, so they are freed on the next draw.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cmargalejo cmargalejo changed the title Cris fix hits event smallevent binning Fix hits event small event binning Jun 19, 2026
@cmargalejo
cmargalejo merged commit 4843d45 into master Jun 22, 2026
64 checks passed
@cmargalejo
cmargalejo deleted the cris_fix_hitsEvent_smallevent_binning branch June 22, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants