Skip to content

Make CollectionCollector collections optional #1843

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

simonge
Copy link
Contributor

@simonge simonge commented Apr 25, 2025

Briefly, what does this PR introduce?

Allows the creation of ReconstructedParticles using configurations which don't contain the calorimeters, e.g. epic_ip6.xml.

The selection of calorimeter hits included will probably need to change in the future.

What kind of change does this PR introduce?

  • Bug fix (issue #__)
  • New feature (issue #__)
  • Documentation update
  • Other: __

Please check if this PR fulfills the following:

  • Tests for the changes have been added
  • Documentation has been added / updated
  • Changes have been communicated to collaborators

Does this PR introduce breaking changes? What changes might users need to make to their code?

No

Does this PR change default behavior?

No

@simonge simonge requested a review from a team April 25, 2025 12:20
@wdconinc
Copy link
Contributor

I'm curious what others think, but I wonder if this adds unmanageable complexity to plugins. They are supposed to be self-contained and "default constructable" but requiring the DD4hep_service means we need to load one plugin before another. We don't resolve this automatically though, so every so often someone will have to manually reorder the plugin list...

Not that I have a better solution here. Maybe we need to finally figure out optional inputs instead of failing when they are absent.

@simonge
Copy link
Contributor Author

simonge commented Apr 25, 2025

Not that I have a better solution here. Maybe we need to finally figure out optional inputs instead of failing when they are absent.

I'm pretty sure the most recent JANA2 version will allow the optional inputs @nathanwbrei? What was the reason we have our own JOmniFactory rather than directly using the JANA2 versions?

@wdconinc
Copy link
Contributor

What was the reason we have our own JOmniFactory rather than directly using the JANA2 versions?

OT I tried to inherit more of the upstream JOmniFactory functionality, and there are at this point a few issues, primarily the absence of ParameterRef and Resource support upstream. The upstream JOmniFactory also doesn't support our Process signatures (which are JANA2 and JEvent agnostic). Nothing major, but unlikely we'll be able to get rid of src/extensions/jana/JOmniFactory.h entirely. At least I'd like to be able to use class eicrecon::JOmniFactory: public jana::components::JOmniFactory.

@simonge
Copy link
Contributor Author

simonge commented Apr 25, 2025

@wdconinc copying across the minimal changes from main JANA2 for optional collections appears to work for me in the small tests I've done.

@simonge
Copy link
Contributor Author

simonge commented Apr 25, 2025

@wdconinc copying across the minimal changes from main JANA2 for optional collections appears to work for me in the small tests I've done.

Might have jumped the gun, I had just been testing the compilation and forgotten to reinstall...

@simonge simonge changed the title Use calorimeter collections for ReconstrutedParticles conditional on configuration Make CollectionCollector collections optional Apr 25, 2025
@simonge
Copy link
Contributor Author

simonge commented Apr 25, 2025

I'm pretty sure it works properly now. There may be details beyond my understanding which should be fixed.

@veprbl
Copy link
Member

veprbl commented Apr 25, 2025

Looks like it crashes.

void GetCollection(const JEvent& event) {
try {
m_data = event.Get<T>(this->collection_names[0]);
} catch (const std::exception& e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we narrow this to the specific exception when a collection is missing in the input and not the collection's algorithm made a boo-boo? I know, likely it's JException or bust, but I can dream, right?

Copy link
Member

@veprbl veprbl Apr 26, 2025

Choose a reason for hiding this comment

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

But this is just a rethrowing. I think motivation here was to provide nicer debug messages, not improve actual handling of errors.
Ah, I misremembered the context, there is a check for optionality, which affects control flow.

Also, in principle, we could have added such context via boost::exceptions.

Copy link
Member

@veprbl veprbl Apr 26, 2025

Choose a reason for hiding this comment

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

Regarding narrowing by type, it's probably JException for collection not found (probably, same exact exception is thrown when none of the factories succeeded to initialize).

Copy link
Contributor

Choose a reason for hiding this comment

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

But we control the input layer through JEventSourcePodio. Does that help here? (On my phone so I'm not able to check in detail.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't what you have in mind here, we either have a type match or not in this clause. Generally, control over input layer doesn't help unless we can sort the dependency graph.

Copy link
Contributor

Choose a reason for hiding this comment

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

From my point of view this can get dealt with in a future PR, but I'd like to ask we print out at least a warning when a collection is ignored (until we can be sure it is ignored for the right reasons). And we should create an issue to keep track of this need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would probably result in a lot of log messages for incomplete configurations, where every event could flag up every missing collection.

Looking at the capybara report again I am now confused as to how tracking_only already has entries in the ReconstructedParticles collection. Something about the behaviour must be different to what I've been assuming.

Copy link
Member

Choose a reason for hiding this comment

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

Can we agree that exceptions arising from "missing" collections are limited to JException?

Suggested change
} catch (const std::exception& e) {
} catch (const JException& e) {

This will leave more general class std::exceptions to the status quo.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the capybara report again I am now confused as to how tracking_only already has entries in the ReconstructedParticles collection. Something about the behaviour must be different to what I've been assuming.

Do you know of a specific piece that should fail when calorimeters are missing?

Copy link
Contributor Author

@simonge simonge May 1, 2025

Choose a reason for hiding this comment

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

Looking at the capybara report again I am now confused as to how tracking_only already has entries in the ReconstructedParticles collection. Something about the behaviour must be different to what I've been assuming.

Do you know of a specific piece that should fail when calorimeters are missing?

I have done a couple of extra tests on the main branch which show I can recover the behaviour of the tracking_only configuration with the ip6 configuration.

The difference appears to be if I request EcalClusters or all three of EcalEndcapPClusters,EcalBarrelScFiClusters,EcalEndcapNClusters in my output_collections list, it forces the creation of the empty collection(s) even if the inputs don't exist, these empty collections then exist enough to propagate through the factories to fill the ReconstructedParticles collection.

Copy link
Contributor

@ruse-traveler ruse-traveler left a comment

Choose a reason for hiding this comment

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

Apologies, but I'm catching up and I think I lost the thread here. Let me ask a few conceptual questions for my own understanding:

  1. The goal here is to create reconstructed particles without using any calorimeter inputs, i.e. to be able to run MatchClusters without providing a cluster collection, right?
  2. So how does the CollectionCollector fit into this? Is this a test case for making sure optional inputs work now?

If the answer is yes to (1), this seems to me to be the right path towards accomplishing this, though...

@simonge
Copy link
Contributor Author

simonge commented Apr 28, 2025

Apologies, but I'm catching up and I think I lost the thread here. Let me ask a few conceptual questions for my own understanding:

  1. The goal here is to create reconstructed particles without using any calorimeter inputs, i.e. to be able to run MatchClusters without providing a cluster collection, right?
  2. So how does the CollectionCollector fit into this? Is this a test case for making sure optional inputs work now?

If the answer is yes to (1), this seems to me to be the right path towards accomplishing this, though...

The original aim was as you suggested. My initial approach was to just copy what we've done for the tracking and test if the input hit collection exists in the geometry. This was never so allowing properly optional input collections has been implemented instead.

An alternative/future modification would be to have the cluster input into MatchClusters optional. I don't know if this would provide any minor performance improvements.

A bit more context. I am testing some downstream software developed by a colleague which just uses the ReconstructedParticles, MCParticles and Association branches to carry out analysis on various reactions. Testing it on a detector configuration which doesn't include calorimeters didn't produce the ReconstructedParticles even when none of the tracks passed could be matched.

@wdconinc
Copy link
Contributor

test if the input hit collection exists in the geometry

But right now this doesn't just test that, but also whether a collection that is added has failed to be constructed for any other reason. My concern in #1843 (comment) is that this would let these other reasons go unnoticed...

@simonge
Copy link
Contributor Author

simonge commented Apr 28, 2025

But right now this doesn't just test that, but also whether a collection that is added has failed to be constructed for any other reason. My concern in #1843 (comment) is that this would let these other reasons go unnoticed...

I don't see that's any different than the current behaviour? The fact that there are no merged clusters doesn't stop ReconstructedParticles being created, it just silently stops it being populated.

Other than just checking and understanding the output would we require upstream modifications the JANA2 exceptions or a different approach altogether to handle this properly?

@wdconinc
Copy link
Contributor

The fact that there are no merged clusters doesn't stop ReconstructedParticles being created, it just silently stops it being populated.

An empty collection is much more noticeable than a filled collection with some class of elements missing. The only reason we have caught some of these exception issues in the past month is because ReconstructedParticles was empty.

I don't want to hold up this PR, but we should be aware of the pitfalls.

@ruse-traveler
Copy link
Contributor

The original aim was as you suggested. My initial approach was to just copy what we've done for the tracking and test if the input hit collection exists in the geometry. This was never so allowing properly optional input collections has been implemented instead.

An alternative/future modification would be to have the cluster input into MatchClusters optional. I don't know if this would provide any minor performance improvements.

A bit more context. I am testing some downstream software developed by a colleague which just uses the ReconstructedParticles, MCParticles and Association branches to carry out analysis on various reactions. Testing it on a detector configuration which doesn't include calorimeters didn't produce the ReconstructedParticles even when none of the tracks passed could be matched.

Gotcha! Thanks for the clarification! That helps a lot! And in light of that, I'd second deferring additional work on std::exception vs. JException to a follow-up PR. I'm pretty happy with this as-is!

@simonge simonge temporarily deployed to github-pages May 1, 2025 21:15 — with GitHub Actions Inactive
@veprbl veprbl temporarily deployed to github-pages May 2, 2025 19:47 — with GitHub Actions Inactive
Copy link
Member

@veprbl veprbl left a comment

Choose a reason for hiding this comment

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

No objections from me. I think, we should also ping @nathanwbrei on this.

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.

4 participants