Skip to content

Read MC kinematics per event in MatchITSTPCQC and fix a reader leak - #15914

Merged
sawenzel merged 3 commits into
AliceO2Group:devfrom
sawenzel:mc-kinematics-memory
Oct 8, 2026
Merged

sawenzel merged 3 commits into
AliceO2Group:devfrom
sawenzel:mc-kinematics-memory

Conversation

@sawenzel

@sawenzel sawenzel commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

This PR reduces the memory of the MC mode of the ITS-TPC matching QC by reading the MC kinematics one event at a time, and fixes a leak in the MCKinematicsReader destructor.

MatchITSTPCQC cached the tracks of every event it touched, only to evaluate isPhysicalPrimary for a single track each. For PbPb with Geant4 a signal event holds about 2.7 million MC tracks, so the cache grows to several GB. Separately, the destructor of MCKinematicsReader never deleted the per-event track vectors that were still cached, which shows as 3.9 GB leaked at exit in heaptrack.

The physical-primary flag of all labelled tracks is now resolved event by event, and each event is released after use. The destructor now deletes what is left in the cache, and since the reader owns these vectors its copy operations are deleted. The effect on one timeframe of 8 orbits (nightly MC LHC22k4_nightly, run 311511, 28 signal events, 75.6M MC tracks):

before after
o2-qc device (PSS) 5.7 GB 1.47 GB
task total (PSS) 7.3 GB 3.0 GB

This task is one of three that run together in the QC pass of these jobs and bring it to a median of 27 GB; the other two are in a companion QualityControl PR.

Note that the histograms are unchanged: the 92 histograms of the task have identical bin contents and entries before and after.

The measurements use the recompiled files preloaded into o2-qc of the CVMFS daily v20261007-1. The branch is not yet built on current dev.

Assisted by Claude Code.

sawenzel and others added 3 commits October 8, 2026 10:19
This fixes a memory leak in the MCKinematicsReader destructor.

- The destructor never deleted the per-event track vectors that are still cached.
This reduces the memory of the MC mode of the ITS-TPC matching QC from the size of all kinematics of the TF to that of the largest event.

- The physical-primary flag of all needed labels is now resolved event by event.
- Each event is released after use, whereas before every touched event stayed cached.
- The histograms are unchanged (92 compared bin by bin, same entries).

Peak memory of the `o2-qc` task on one PbPb timeframe of 8 orbits (28 signal events, 75.6M MC tracks):

| | before | after |
|---|---:|---:|
| `o2-qc` device (PSS) | 5.6 GB | 1.45 GB |
| task total (PSS) | 7.1 GB | 2.9 GB |
| wall time | 35 s | 41 s |

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This makes the MCKinematicsReader non-copyable.

- The destructor deletes the cached track vectors, so an implicit copy would free them twice.
- No copy of a reader exists in AliceO2.
@sawenzel
sawenzel requested review from a team and shahor02 as code owners October 8, 2026 12:06
@sawenzel
sawenzel merged commit 72f6798 into AliceO2Group:dev Oct 8, 2026
11 of 12 checks passed
@sawenzel
sawenzel deleted the mc-kinematics-memory branch October 8, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants