Keeping track of unique tracks in 2 different sensitive detectors

Hello experts, I have a question:

I have a simple geometry, two slices of stainless steel,inside a “vacuum” world(G4_Galactic)

The slices are 100 x 20 x 5 cm (x,y,z) and with a 5 cm distance from another(See below)

Image 1

There is a global electric field in between, but not inside the slices(I did set it to zero via LocalFieldManager).

The source is 800 MeV photons placed at (0,0,0) and are shot whith a small angle in order to hit the “right” box, which is a sensitive detector, so it can record hits.
I needed to count the number of some particles, so I followed the advice in this topic:

And finally on to the potential problem.
I declared the “left” box as a different (meaning, I have a unique class that describes the “right” slice and another class that describes the “left” slice) sensitive detector, which has a unique collection of hits.Thus I have 2 sensitive detectors (and two HitsCollections)
So, the proton hits the “right” slice, some electrons may escape, go across the gap and interact with the “left” slice and produce more electrons.
I need to count how many electrons are the result of the “right” slice-electrons that passed the gap.
My approach is:

  1. I use two std::vector TrackID, one for each slice.
    These 2 vectors are filled at G4Step.

  2. Next I check, if the two vectors have any elements in common (with std::set_intersection).
    If they have any TrackID in common, then it is given in a third
    std::unordered_set commonTrackID. This set is filled by the std::set_intersection.

  3. Then, I simply remove any TrackID from the “left” slice std::vector TrackID that matches the set mentioned in (2). If there is anything left inside the “left” TrackID vector, it is the result of the “right”
    electrons that crossed the gap and interacted with the “left” slice.

  4. I clear everything at the end of each event

Is this a correct approach?
Are the trackID from Geant4 “global” per event (and all distinct sensitive detectors)?
For example, an electron that escaped form the “right” slice (let’s say it has TrackID=10 on the “right” slice), crosses the gap and interacts with the “left” slice will be detected with TrackID=10 there?
Is there possibly any other problem I can’t think of?
Sorry for the long post, but I’m still learning to use geant4, so any help is greatly appreciated!

PS: I forgot to mention that I run Geant4 in MT mode

I think you’ll find it easier to record uniqueness if you use a single SD for your two targets. If you do the placement of the two targets with different copy numbers, then you can distinguish them in the SD code, and in your hit collection (include the copy number as a data member of your hit).

@mkelsey Thank you very much for the suggestion and sorry for the late reply! A small update, I tried the approach in my first post with geant4 built in sequential mode (I still haven’t tried it in MT mode). As far I can tell, it seems to work.
I also think it will be easier to work with one HitsCollection, so I’m gonna try the same approach with one HitstCollection for both targets, as you suggested.
Thank you again for the help!