- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33
Description
True particles from neutrino interactions sometime have exactly the same start and end positions.
For a detailed presentation, please have a look to SBN-doc-43942.
It is an issue for analyses using true particles (coming from G4Particles) position information such as start and end to define signal with containment requirements.
Main source of this bug is happening when the simb::MCParticle has only two indices in its simb::MCTrajectory.
In void FillTrueG4Particle of sbncode/CAFMaker/FillTrue.cxx,
        if (!active_volumes.at(cryostat_index).ContainsPosition(this_point) && active_volumes.at(cryostat_index).ContainsPosition(pos)) {
          exit_point = i-1;
        }
or
    if (exit_point < 0 && entry_point >= 0) {
      exit_point = particle.NumberTrajectoryPoints() - 1;
    }
    if (exit_point >= 0 && ((unsigned)exit_point) < particle.NumberTrajectoryPoints() - 1) {
      srparticle.wallout = sbn::GetWallCross(active_volumes.at(cryostat_index), particle.Position(exit_point).Vect(), particle.Position(exit_point+1).Vect());
    }
This logic has an issue of having exit_point  == entry_point  when particle.NumberTrajectoryPoints()  == 2, first position is within the active volume and the second position is outside of the active volume.
To fix this, I will add an additional if condition to the second code block as
    if (exit_point < 0 && entry_point >= 0) {
      exit_point = particle.NumberTrajectoryPoints() - 1;
    }
    if (exit_point >= 0 && entry_point >=0 && exit_point == entry_point && exit_point < static_cast<int>(particle.NumberTrajectoryPoints()) - 1){
      exit_point++; // to avoid exactly the same start and end positions when single index is inside the active volumne
    }
    if (exit_point >= 0 && ((unsigned)exit_point) < particle.NumberTrajectoryPoints() - 1) {
      srparticle.wallout = sbn::GetWallCross(active_volumes.at(cryostat_index), particle.Position(exit_point).Vect(), particle.Position(exit_point+1).Vect());
    }
into the sbncode for both release/SBN2025A and develop branches.