Skip to content

AlignmentDUTResidual: fix memory issue when prune_tracks is activated and minor improvements

Activating prune_tracks in AlignmentDUTResidual can cause memory issues which result in std::bad_alloc or segmentation faults. The problem is that the associated clusters are only saved to the persistent storage if the track passes the selection. If there are multiple DUTs it can happen that for one DUT the associated cluster of a track is not saved because it does not pass the max_associated_clusters selection but for another DUT the same track and corresponding associated cluster are saved. Any objects that are not saved to the persistent storage get deleted after the run loop finishes the event. Later in the finalize step of AlignmentDUTResidual the method track->getAssociatedClusters(name) gets called. This method loops through all the associated clusters of the track. But if not all the associated clusters of the track have been saved to the persistent storage, it basically accesses memory that has been released, which of course causes undefined behaviour. This fix circumvents this problem by storing the associated clusters in a map and only accessing the ones corresponding to the requested detector when trying to retrieve them.

I also noticed that the tracks get saved globally for all detectors, but the alignment is basically done independently for each DUT. This means that for the alignment some tracks are simply duplicated or there are tracks included that do not have an associated cluster on the DUT that is currently aligned.

Additionally I noticed that the residual profile plots are filled in the wrong way (residual and position are interchanged from what they should be).

Cheers, David

Merge request reports