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 SimCaloHitContribution conversion #7

Merged
merged 1 commit into from
Nov 30, 2022

Conversation

andresailer
Copy link
Contributor

Instead of adding empty contributions at least convert the numbers we know when we do not find the MCParticle

Convert SimCaloHitContributions only in FillMissingCollections, because then MCParticles should have been converted

BEGINRELEASENOTES

ENDRELEASENOTES

Instead of adding empty contributions at least convert the numbers we know when we do not find the MCParticle

Convert SimCaloHitContributions only in FillMissingCollections, because then MCParticles should have been converted
@vvolkl
Copy link
Contributor

vvolkl commented Nov 30, 2022

I'll merge this for the nightlies, but will try to add a regression test in another PR.
EDIT: waiting for thomas to approve too.

@vvolkl vvolkl enabled auto-merge (squash) November 30, 2022 13:11
@vvolkl vvolkl disabled auto-merge November 30, 2022 13:11
@andresailer
Copy link
Contributor Author

Thanks, yes, we need a test,

Copy link
Contributor

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I essentially just have some comments on the code, we can also fix them in a later PR, as I suspect these are not the only instances of the things I commented on.

Overall, I think this looks good. In summary, what changes is that (IIUC):

  • CaloHitContributions are now always populated at least with the data, even if there is no MCParticle found (as opposed to previously, where no contributions where created if no MCParticle was found)
  • If an MCParticle is found than we also link them
  • The whole CaloHitContribution conversion is moved to the very end, which we now have to make sure to always call

Comment on lines +776 to +777
for (int i = 0; i < edm_sch.contributions_size(); ++i) {
const auto& contrib = edm_sch.getContributions(i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int i = 0; i < edm_sch.contributions_size(); ++i) {
const auto& contrib = edm_sch.getContributions(i);
for (const auto& contrib : edm_sch.getContributions()) {

If we are being picky here, we could remove the loop index.

Comment on lines +789 to +800
for (auto& [lcio_mcp, edm_mcp] : collection_pairs.mcparticles) {
if (edm_mcp == edm_contrib_mcp) {
mcp_found = true;
lcio_sch->addMCParticleContribution(
lcio_mcp, contrib.getEnergy(), contrib.getTime(), contrib.getPDG(), step_position.data());
break;
}
}
} // all mcparticles
}
}

} // SimCaloHit
else { // edm mcp available
// std::cout << "WARNING: edm4hep contribution is not available!" << std::endl;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done with std::find? That would make this whole bit a lot easier to read, as we could remove this loop and branching structure with an intermediate boolean here.

If we want to go all in, we replace the vector<pair<LCIO*, edm4hep*>> with an actual map (or an unordered_map to avoid this linear lookup all the time. But that can probably be done at a later point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try, but changing this also needs changes in k4MarlinWrapper.
But the pointer address as key makes the ordering non-deterministic, which isn't nice and could give issues elsewhere.

Copy link
Contributor

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can go ahead with this for now, and do a cleanup in a separate PR as Valentin has suggested already.

@vvolkl vvolkl enabled auto-merge (squash) November 30, 2022 15:48
@andresailer andresailer disabled auto-merge November 30, 2022 16:34
@andresailer andresailer merged commit db8d0e9 into key4hep:master Nov 30, 2022
@andresailer andresailer deleted the fixCaloHitContribution branch November 30, 2022 16:34
@andresailer
Copy link
Contributor Author

The auto-merge didn't work because of the unresolved conversations

@andresailer
Copy link
Contributor Author

previously, where no contributions where created if no MCParticle was found

Previously only contributions with all zeroes were created, when no MCParticle was found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calorimeter hits problem following in CLIC reco recipe
3 participants