I personally prefer to use sensitive detector instead of usersteppingaction, because then you don’t need to discard all the steps
that are not within the volumes that you attached the SD to.
since you want to only record each volume
once, get rid of the duplicates from multiple steps in the same volume, e.g. like so: Multiple Steps on geometricBoundary
you would need to keep track of the copyID of the visited volumes somehow. you could use the „hitsmap“ for this, and then process the map at the end of each event to check for multiple entries.
inspiration can be found here: geant4/EventAction.cc at v11.1.1 · Geant4/geant4 · GitHub