DUNE / dune-tms

DUNE ND Temporary Muon Spectrometer
0 stars 1 forks source link

Add checks for end and rend in TMS_TrackFinder::Extrapolation #79

Closed jdkio closed 3 months ago

jdkio commented 3 months ago

Sometimes the last 3 code is being run on vectors that are "shorter" than 3. There's a little bit of code looking for distinct z values, so we do end up with cases where there are 3 or more elements in TrackHits, but 2 or more have the same z and so aren't added to the last_three list. In that case, ir is equal to TrackHits.rend(). But because Hit class and TrueHit class are so simple, they don't crash with a seg fault.

But I'm currently adding vectors to TrueHit and now the code in Extrapolation does crash with the seg fault. That's because push_back doesn't check that ir is valid, and so the default constructor copies erroneous memory. That new vector inside the TrueHit is then pointing to an invalid memory address and so it seg faults.

This fix returns the original vector of hits when the last 3 vector is too short. This makes sense since we can't extrapolate with < 3 hits. The only thing I don't understand is why the failure doesn't happen first with first_three hits. I imagine if one is true then the other should be true too

jdkio commented 3 months ago

That would work except that sometimes hits are skipped because of the same z. And also I only got the seg fault with the last_three vector and not the front_three, so idk if an initial check would work. This catches the error I was getting specifically so we should use this for now