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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
54e3800
Make calorimeter collections optional
simonge Apr 25, 2025
4041d59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2025
37abda7
Make inputs optional instead
simonge Apr 25, 2025
ea03b66
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2025
71471dc
Remove collection list checks from tracking.cc
simonge Apr 25, 2025
fed19ea
Move exception catching to JOmniFactory and template isOptional
simonge Apr 25, 2025
a9afec9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2025
6dc7c13
Merge remote-tracking branch 'origin/main' into Allow-reconstructed-p…
simonge Apr 26, 2025
d7c7ee9
Don't pass the isoptional flag on
simonge Apr 26, 2025
4582554
Fix collection names
simonge Apr 26, 2025
18f7154
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 26, 2025
6bfdd33
Add tests and try passing isoptional again
simonge Apr 28, 2025
2821517
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 28, 2025
5987bfe
Make test more useful
simonge Apr 28, 2025
3a5187a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 28, 2025
f3fc175
default optional to false
simonge Apr 28, 2025
d6c5e15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 28, 2025
35f2482
Merge remote-tracking branch 'origin/main' into Allow-reconstructed-p…
simonge May 1, 2025
b0a8f6e
Change std::exception catches to JException
simonge May 1, 2025
5f30cc7
Fix typo
simonge May 1, 2025
0bfd773
IWYU
veprbl May 2, 2025
2ea824f
Update copyright year
veprbl May 2, 2025
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
4 changes: 2 additions & 2 deletions src/detectors/LOWQ2/LOWQ2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ void InitPlugin(JApplication* app) {
}

// Combine the tracks from each module into one collection
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track>>(
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track, true>>(
"TaggerTrackerLocalTracks", outputTrackTags, {"TaggerTrackerLocalTracks"}, app));

// Combine the associations from each module into one collection
app->Add(new JOmniFactoryGeneratorT<
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation>>(
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation, true>>(
"TaggerTrackerLocalTrackAssociations", outputTrackAssociationTags,
{"TaggerTrackerLocalTrackAssociations"}, app));

Expand Down
35 changes: 29 additions & 6 deletions src/extensions/jana/JOmniFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JOmniFactory : public JMultifactory {
virtual void GetCollection(const JEvent& event) = 0;
};

template <typename T> class Input : public InputBase {
template <typename T, bool IsOptional = false> class Input : public InputBase {

std::vector<const T*> m_data;

Expand All @@ -58,10 +58,19 @@ class JOmniFactory : public JMultifactory {
private:
friend class JOmniFactory;

void GetCollection(const JEvent& event) { m_data = event.Get<T>(this->collection_names[0]); }
void GetCollection(const JEvent& event) {
try {
m_data = event.Get<T>(this->collection_names[0], !IsOptional);
} catch (const JException& e) {
if constexpr (!IsOptional) {
throw JException("JOmniFactory: Failed to get collection %s: %s",
this->collection_names[0].c_str(), e.what());
}
}
}
};

template <typename PodioT> class PodioInput : public InputBase {
template <typename PodioT, bool IsOptional = false> class PodioInput : public InputBase {

const typename PodioTypeMap<PodioT>::collection_t* m_data;

Expand All @@ -78,11 +87,18 @@ class JOmniFactory : public JMultifactory {
friend class JOmniFactory;

void GetCollection(const JEvent& event) {
m_data = event.GetCollection<PodioT>(this->collection_names[0]);
try {
m_data = event.GetCollection<PodioT>(this->collection_names[0], !IsOptional);
} catch (const JException& e) {
if constexpr (!IsOptional) {
throw JException("JOmniFactory: Failed to get collection %s: %s",
this->collection_names[0].c_str(), e.what());
}
}
}
};

template <typename PodioT> class VariadicPodioInput : public InputBase {
template <typename PodioT, bool IsOptional = false> class VariadicPodioInput : public InputBase {

std::vector<const typename PodioTypeMap<PodioT>::collection_t*> m_data;

Expand All @@ -104,7 +120,14 @@ class JOmniFactory : public JMultifactory {
void GetCollection(const JEvent& event) {
m_data.clear();
for (auto& coll_name : this->collection_names) {
m_data.push_back(event.GetCollection<PodioT>(coll_name));
try {
m_data.push_back(event.GetCollection<PodioT>(coll_name, !IsOptional));
} catch (const JException& e) {
if constexpr (!IsOptional) {
throw JException("JOmniFactory: Failed to get collection %s: %s", coll_name.c_str(),
e.what());
}
}
}
}
};
Expand Down
13 changes: 8 additions & 5 deletions src/factories/meta/CollectionCollector_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

namespace eicrecon {

template <class T>
class CollectionCollector_factory : public JOmniFactory<CollectionCollector_factory<T>> {
template <class T, bool IsOptional = false>
class CollectionCollector_factory
: public JOmniFactory<CollectionCollector_factory<T, IsOptional>> {
public:
using AlgoT = eicrecon::CollectionCollector<typename T::collection_type>;

private:
std::unique_ptr<AlgoT> m_algo;

typename JOmniFactory<CollectionCollector_factory<T>>::template VariadicPodioInput<T> m_inputs{
this};
typename JOmniFactory<CollectionCollector_factory<T>>::template PodioOutput<T> m_output{this};
typename JOmniFactory<CollectionCollector_factory<T, IsOptional>>::template VariadicPodioInput<
T, IsOptional>
m_inputs{this};
typename JOmniFactory<CollectionCollector_factory<T, IsOptional>>::template PodioOutput<T>
m_output{this};

public:
void Configure() {
Expand Down
2 changes: 1 addition & 1 deletion src/global/beam/beam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void InitPlugin(JApplication* app) {
app));

// Combine beam protons and neutrons into beam hadrons
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4hep::MCParticle>>(
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4hep::MCParticle, true>>(
"MCBeamHadrons", {"MCBeamProtons", "MCBeamNeutrons"}, {"MCBeamHadrons"}, app));
}
}
20 changes: 6 additions & 14 deletions src/global/reco/reco.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,15 @@ void InitPlugin(JApplication* app) {
app->Add(new JOmniFactoryGeneratorT<MC2SmearedParticle_factory>(
"GeneratedParticles", {"MCParticles"}, {"GeneratedParticles"}, app));

app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Cluster>>(
"EcalClusters",
{
"EcalEndcapNClusters",
"EcalBarrelScFiClusters",
"EcalEndcapPClusters",
},
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Cluster, true>>(
"EcalClusters", {"EcalEndcapNClusters", "EcalBarrelScFiClusters", "EcalEndcapPClusters"},
{"EcalClusters"}, app));

app->Add(new JOmniFactoryGeneratorT<
CollectionCollector_factory<edm4eic::MCRecoClusterParticleAssociation>>(
CollectionCollector_factory<edm4eic::MCRecoClusterParticleAssociation, true>>(
"EcalClusterAssociations",
{
"EcalEndcapNClusterAssociations",
"EcalBarrelScFiClusterAssociations",
"EcalEndcapPClusterAssociations",
},
{"EcalEndcapNClusterAssociations", "EcalBarrelScFiClusterAssociations",
"EcalEndcapPClusterAssociations"},
{"EcalClusterAssociations"}, app));

app->Add(new JOmniFactoryGeneratorT<MatchClusters_factory>(
Expand Down Expand Up @@ -196,7 +188,7 @@ void InitPlugin(JApplication* app) {
},
app));

app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Cluster>>(
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Cluster, true>>(
"BarrelClusters",
{
"HcalBarrelClusters",
Expand Down
104 changes: 31 additions & 73 deletions src/global/tracking/tracking.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 - 2024, Dmitry Romanov, Tyler Kutz, Wouter Deconinck, Dmitry Kalinkin
// Copyright (C) 2022 - 2025, Dmitry Romanov, Tyler Kutz, Wouter Deconinck, Dmitry Kalinkin

#include <DD4hep/Detector.h>
#include <JANA/JApplication.h>
#include <edm4eic/MCRecoTrackParticleAssociation.h>
#include <edm4eic/MCRecoTrackerHitAssociationCollection.h>
#include <edm4eic/TrackCollection.h>
#include <edm4eic/TrackerHitCollection.h>
#include <fmt/core.h>
#include <algorithm>
#include <gsl/pointers>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <vector>

#include "ActsToTracks.h"
#include "ActsToTracks_factory.h"
Expand All @@ -30,7 +24,6 @@
#include "TracksToParticles_factory.h"
#include "extensions/jana/JOmniFactoryGeneratorT.h"
#include "factories/meta/CollectionCollector_factory.h"
#include "services/geometry/dd4hep/DD4hep_service.h"

//
extern "C" {
Expand All @@ -42,49 +35,26 @@ void InitPlugin(JApplication* app) {
app->Add(new JOmniFactoryGeneratorT<TrackParamTruthInit_factory>(
"CentralTrackTruthSeeds", {"MCParticles"}, {"CentralTrackTruthSeeds"}, {}, app));

// Possible collections from arches, brycecanyon and craterlake configurations
std::vector<std::tuple<std::string, std::string, std::string, std::string>> possible_collections =
{{"SiBarrelHits", "SiBarrelRawHits", "SiBarrelRawHitAssociations", "SiBarrelTrackerRecHits"},
{"VertexBarrelHits", "SiBarrelVertexRawHits", "SiBarrelVertexRawHitAssociations",
"SiBarrelVertexRecHits"},
{"TrackerEndcapHits", "SiEndcapTrackerRawHits", "SiEndcapTrackerRawHitAssociations",
"SiEndcapTrackerRecHits"},
{"TOFBarrelHits", "TOFBarrelRawHits", "TOFBarrelRawHitAssociations", "TOFBarrelRecHits"},
{"TOFEndcapHits", "TOFEndcapRawHits", "TOFEndcapRawHitAssociations", "TOFEndcapRecHits"},
{"MPGDBarrelHits", "MPGDBarrelRawHits", "MPGDBarrelRawHitAssociations", "MPGDBarrelRecHits"},
{"OuterMPGDBarrelHits", "OuterMPGDBarrelRawHits", "OuterMPGDBarrelRawHitAssociations",
"OuterMPGDBarrelRecHits"},
{"BackwardMPGDEndcapHits", "BackwardMPGDEndcapRawHits",
"BackwardMPGDEndcapRawHitAssociations", "BackwardMPGDEndcapRecHits"},
{"ForwardMPGDEndcapHits", "ForwardMPGDEndcapRawHits", "ForwardMPGDEndcapRawHitAssociations",
"ForwardMPGDEndcapRecHits"},
{"B0TrackerHits", "B0TrackerRawHits", "B0TrackerRawHitAssociations", "B0TrackerRecHits"}};

// Filter out collections that are not present in the current configuration
std::vector<std::string> input_rec_collections;
std::vector<std::string> input_raw_assoc_collections;
auto readouts = app->GetService<DD4hep_service>()->detector()->readouts();
for (const auto& [hit_collection, raw_collection, raw_assoc_collection, rec_collection] :
possible_collections) {
if (readouts.find(hit_collection) != readouts.end()) {
// Add the collection to the list of input collections
input_rec_collections.push_back(rec_collection);
input_raw_assoc_collections.push_back(raw_assoc_collection);
}
}

// Tracker hits collector
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::TrackerHit>>(
"CentralTrackingRecHits", input_rec_collections,
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::TrackerHit, true>>(
"CentralTrackingRecHits",
{"SiBarrelTrackerRecHits", "SiBarrelVertexRecHits", "SiEndcapTrackerRecHits",
"TOFBarrelRecHits", "TOFEndcapRecHits", "MPGDBarrelRecHits", "OuterMPGDBarrelRecHits",
"BackwardMPGDEndcapRecHits", "ForwardMPGDEndcapRecHits", "B0TrackerRecHits"},
{"CentralTrackingRecHits"}, // Output collection name
app));

// Tracker hit associations collector
app->Add(
new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::MCRecoTrackerHitAssociation>>(
"CentralTrackingRawHitAssociations", input_raw_assoc_collections,
{"CentralTrackingRawHitAssociations"}, // Output collection name
app));
app->Add(new JOmniFactoryGeneratorT<
CollectionCollector_factory<edm4eic::MCRecoTrackerHitAssociation, true>>(
"CentralTrackingRawHitAssociations",
{"SiBarrelRawHitAssociations", "SiBarrelVertexRawHitAssociations",
"SiEndcapTrackerRawHitAssociations", "TOFBarrelRawHitAssociations",
"TOFEndcapRawHitAssociations", "MPGDBarrelRawHitAssociations",
"OuterMPGDBarrelRawHitAssociations", "BackwardMPGDEndcapRawHitAssociations",
"ForwardMPGDEndcapRawHitAssociations", "B0TrackerRawHitAssociations"},
{"CentralTrackingRawHitAssociations"}, // Output collection name
app));

app->Add(new JOmniFactoryGeneratorT<TrackerMeasurementFromHits_factory>(
"CentralTrackerMeasurements", {"CentralTrackingRecHits"}, {"CentralTrackerMeasurements"},
Expand Down Expand Up @@ -240,36 +210,24 @@ void InitPlugin(JApplication* app) {
}},
app));

std::vector<std::string> input_track_collections, input_track_assoc_collections;
std::vector<std::string> input_truth_track_collections, input_truth_track_assoc_collections;
//Check size of input_rec_collections to determine if CentralCKFTracks should be added to the input_track_collections
if (input_rec_collections.size() > 0) {
input_track_collections.push_back("CentralCKFTracks");
input_track_assoc_collections.push_back("CentralCKFTrackAssociations");
input_truth_track_collections.push_back("CentralCKFTruthSeededTracks");
input_truth_track_assoc_collections.push_back("CentralCKFTruthSeededTrackAssociations");
}
//Check if the TaggerTracker readout is present in the current configuration
if (readouts.find("TaggerTrackerHits") != readouts.end()) {
input_track_collections.push_back("TaggerTrackerTracks");
input_track_assoc_collections.push_back("TaggerTrackerTrackAssociations");
input_truth_track_collections.push_back("TaggerTrackerTracks");
input_truth_track_assoc_collections.push_back("TaggerTrackerTrackAssociations");
}

// Add central and other tracks
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track>>(
"CombinedTracks", input_track_collections, {"CombinedTracks"}, app));
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track, true>>(
"CombinedTracks", {"CentralCKFTracks", "TaggerTrackerTracks"}, {"CombinedTracks"}, app));

app->Add(new JOmniFactoryGeneratorT<
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation>>(
"CombinedTrackAssociations", input_track_assoc_collections, {"CombinedTrackAssociations"},
app));
app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track>>(
"CombinedTruthSeededTracks", input_truth_track_collections, {"CombinedTruthSeededTracks"},
app));
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation, true>>(
"CombinedTrackAssociations",
{"CentralCKFTrackAssociations", "TaggerTrackerTrackAssociations"},
{"CombinedTrackAssociations"}, app));

app->Add(new JOmniFactoryGeneratorT<CollectionCollector_factory<edm4eic::Track, true>>(
"CombinedTruthSeededTracks", {"CentralCKFTruthSeededTracks", "TaggerTrackerTracks"},
{"CombinedTruthSeededTracks"}, app));

app->Add(new JOmniFactoryGeneratorT<
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation>>(
"CombinedTruthSeededTrackAssociations", input_truth_track_assoc_collections,
CollectionCollector_factory<edm4eic::MCRecoTrackParticleAssociation, true>>(
"CombinedTruthSeededTrackAssociations",
{"CentralCKFTruthSeededTrackAssociations", "TaggerTrackerTrackAssociations"},
{"CombinedTruthSeededTrackAssociations"}, app));

app->Add(new JOmniFactoryGeneratorT<TracksToParticles_factory>(
Expand Down
Loading
Loading