Skip to content

Fix invalid memory access in ClassifyPhotonElectronAlg

Oleksandr Zenaiev requested to merge fix_ClassifyPhotonElectronAlg into master

The lines

photons.erase( std::remove_if( photons.begin(), photons.end(),
                                   [&]( const auto& hypo ) { return CaloMomentum( hypo ).pt() < m_eTcut; } ),
                   photons.end() );
    electrons.erase( std::remove_if( electrons.begin(), electrons.end(),
                                     [&]( const auto& hypo ) { return CaloMomentum( hypo ).pt() < m_electrEtCut; } ),
                     electrons.end() );

produced invalid memory access in very rare events when corrected calo hypos have pT lower than the same pT cut applied before correction. It seems KeyedContainer does not support remove_if? (cc @sponce) (worth to say that erasing elements happens very rarely, something like 1:1000 events) This was spotted when running (not yet merged) new test from Moore!386 (merged) (one has to run on more than 1000 events to see a crash).

Another small fix is changing m_eTcut -> m_photonEtCut in two places (perhaps a typo? cc @cmarinbe).

Thanks @sstahl for spotting the problem with erasing element in the very first commit.

Should go with Brunel!964 (merged) for references updates

Edited by Rosen Matev

Merge request reports