Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests by disregarding order of mc-reco links #130

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions tests/src/compare_delphes_converter_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,26 @@ template <typename DelphesT> std::vector<GenParticle*> getAssociatedMCParticles(
*/
template <typename DelphesT>
bool compareMCRelations(const DelphesT* delphesCand, edm4hep::ReconstructedParticle edm4hepCand,
const edm4hep::MCRecoParticleAssociationCollection& associations) {
const auto delphesGenParticles = getAssociatedMCParticles(delphesCand);
const auto edm4hepMCParticles = getAssociatedMCParticles(edm4hepCand, associations);
const edm4hep::RecoMCParticleLinkCollection& associations) {
auto delphesGenParticles = getAssociatedMCParticles(delphesCand);
auto edm4hepMCParticles = getAssociatedMCParticles(edm4hepCand, associations);

if (delphesGenParticles.size() != edm4hepMCParticles.size()) {
return false;
}

// In some cases the order of the vectors is not exactly the same, because
// Delphes(!) seems to write them in a different order from time to time even
andresailer marked this conversation as resolved.
Show resolved Hide resolved
// with equal random seeds. Here we sort them simply by the x coordinate of
// the momentum since that is easiest to do without having to wade into the
// subtleties of potentially small differences in energy in a four vector
// depending on whether energy is stored directly or whether we compute it via
// the momentum and the mass.
std::sort(delphesGenParticles.begin(), delphesGenParticles.end(),
[](const auto* a, const auto* b) { return a->P4().X() < b->P4().X(); });
std::sort(edm4hepMCParticles.begin(), edm4hepMCParticles.end(),
[](const auto& a, const auto& b) { return a.getMomentum().x < b.getMomentum().x; });

for (size_t i = 0; i < delphesGenParticles.size(); ++i) {
if (!compareKinematics(delphesGenParticles[i], edm4hepMCParticles[i])) {
return false;
Expand Down
Loading