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

Update TrackClusterMergeSplitter to output track-cluster associations (PFA0) #1699

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
68672a9
Add hooks for track-cluster match outputs
ruse-traveler Jan 9, 2025
90a9ccc
Update algorithm to operate on clusters
ruse-traveler Jan 9, 2025
335d224
Begin filling in cluster reconstruction calculation
ruse-traveler Jan 9, 2025
68fa03d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2025
f8605e8
Add position calculation
ruse-traveler Jan 10, 2025
de78ffb
Fix typos in input collection names
ruse-traveler Jan 10, 2025
1d04aa8
Merge branch 'output-splitmerge-track-associations' of github.com:eic…
ruse-traveler Jan 10, 2025
30b92d3
Add missing edm4eic version header
ruse-traveler Jan 15, 2025
021e11b
Be safer with creating new clusters
ruse-traveler Jan 15, 2025
0307731
Rework weight calculation to accomodate cluster re-reconstruction
ruse-traveler Jan 15, 2025
f8d2050
Fill track-cluster match output
ruse-traveler Jan 15, 2025
3dab6d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 15, 2025
bf31964
Add missed edm4eic version header
ruse-traveler Jan 16, 2025
178ecb8
Merge branch 'output-splitmerge-track-associations' of github.com:eic…
ruse-traveler Jan 16, 2025
b4b0aca
Add shape calculation
ruse-traveler Feb 3, 2025
303f3f2
Wire in associations
ruse-traveler Feb 4, 2025
a2ff2f1
Copy associations of unused clusters into output
ruse-traveler Feb 4, 2025
f7476b4
Fill in mergerd cluster associations
ruse-traveler Feb 4, 2025
14deb24
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2025
b5a364c
Merge branch 'main' into output-splitmerge-track-associations
ruse-traveler Feb 11, 2025
8141330
Fix HcalEndcapNClusterAssociations typo
ruse-traveler Feb 11, 2025
1c17703
Merge branch 'output-splitmerge-track-associations' of github.com:eic…
ruse-traveler Feb 11, 2025
0c75eb9
Template ObjectID comparator
ruse-traveler Feb 11, 2025
bd55165
Rewrite splitting weight calculation to use maps
ruse-traveler Feb 22, 2025
32af87f
Merge branch 'main' into output-splitmerge-track-associations
ruse-traveler Feb 22, 2025
cc282d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 22, 2025
143df2a
Merge main
ruse-traveler Mar 10, 2025
8288600
Remove shape calculation from merge/splitter
ruse-traveler Mar 10, 2025
30c9ab2
Merge branch 'output-splitmerge-track-associations' of github.com:eic…
ruse-traveler Mar 10, 2025
9d33912
Make split/merge shape parameters consistent with RecoCoG
ruse-traveler Mar 10, 2025
a8537b1
IWYU
veprbl Mar 11, 2025
004b053
Merge branch 'main' into output-splitmerge-track-associations
ruse-traveler Mar 13, 2025
87c0458
Disable saving split/merge track-cluster matches to output
ruse-traveler Mar 13, 2025
f79708b
Merge branch 'output-splitmerge-track-associations' of github.com:eic…
ruse-traveler Mar 13, 2025
27711f5
Merge branch 'main' into output-splitmerge-track-associations
ruse-traveler Mar 17, 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
387 changes: 283 additions & 104 deletions src/algorithms/calorimetry/TrackClusterMergeSplitter.cc

Large diffs are not rendered by default.

87 changes: 64 additions & 23 deletions src/algorithms/calorimetry/TrackClusterMergeSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@

#include <DD4hep/Detector.h>
#include <algorithms/algorithm.h>
#include <edm4eic/ProtoClusterCollection.h>
#include <edm4eic/CalorimeterHit.h>
#include <edm4eic/ClusterCollection.h>
#include <edm4eic/EDM4eicVersion.h>
#include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
#if EDM4EIC_VERSION_MAJOR >= 8
#include <edm4eic/TrackClusterMatchCollection.h>
#endif
#include <edm4eic/Track.h>
#include <edm4eic/TrackPoint.h>
#include <edm4eic/TrackSegmentCollection.h>
#include <edm4hep/Vector3f.h>
#include <podio/ObjectID.h>
#if EDM4EIC_VERSION_MAJOR >= 7
#include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
#else
#include <edm4hep/SimCalorimeterHitCollection.h>
#endif
#include <algorithm>
#include <map>
#include <optional>
#include <set>
#include <string>
#include <string_view>
Expand All @@ -26,14 +37,14 @@
namespace eicrecon {

// --------------------------------------------------------------------------
//! Comparator struct for protoclusters
//! Comparator struct for object IDs
// --------------------------------------------------------------------------
/*! Organizes protoclusters by their ObjectID's in decreasing collection
/*! Organizes objects by their ObjectID's in decreasing collection
* ID first, and second by decreasing index second.
*/
struct CompareProto {
template <typename T> struct CompareObjectID {

bool operator() (const edm4eic::ProtoCluster& lhs, const edm4eic::ProtoCluster& rhs) const {
bool operator() (const T& lhs, const T& rhs) const {
if (lhs.getObjectID().collectionID == rhs.getObjectID().collectionID) {
return (lhs.getObjectID().index < rhs.getObjectID().index);
} else {
Expand All @@ -43,16 +54,24 @@ namespace eicrecon {

}; // end CompareObjectID

// specialization for clusters, hits
using CompareClust = CompareObjectID<edm4eic::Cluster>;
using CompareHit = CompareObjectID<edm4eic::CalorimeterHit>;



// --------------------------------------------------------------------------
//! Convenience types
// --------------------------------------------------------------------------
using VecTrk = std::vector<edm4eic::Track>;
using VecProj = std::vector<edm4eic::TrackPoint>;
using VecClust = std::vector<edm4eic::ProtoCluster>;
using SetClust = std::set<edm4eic::ProtoCluster, CompareProto>;
using MapToVecProj = std::map<edm4eic::ProtoCluster, VecProj, CompareProto>;
using MapToVecClust = std::map<edm4eic::ProtoCluster, VecClust, CompareProto>;
using VecClust = std::vector<edm4eic::Cluster>;
using SetClust = std::set<edm4eic::Cluster, CompareClust>;
using MapToVecTrk = std::map<edm4eic::Cluster, VecTrk, CompareClust>;
using MapToVecProj = std::map<edm4eic::Cluster, VecProj, CompareClust>;
using MapToVecClust = std::map<edm4eic::Cluster, VecClust, CompareClust>;
using MapToWeight = std::map<edm4eic::CalorimeterHit, double, CompareHit>;
using VecWeights = std::vector<MapToWeight>;



Expand All @@ -61,11 +80,21 @@ namespace eicrecon {
// --------------------------------------------------------------------------
using TrackClusterMergeSplitterAlgorithm = algorithms::Algorithm<
algorithms::Input<
edm4eic::ProtoClusterCollection,
edm4eic::TrackSegmentCollection
edm4eic::ClusterCollection,
edm4eic::TrackSegmentCollection,
std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>,
#if EDM4EIC_VERSION_MAJOR >= 7
std::optional<edm4eic::MCRecoCalorimeterHitAssociationCollection>
#else
std::optional<edm4hep::SimCalorimeterHitCollection>
#endif
>,
algorithms::Output<
edm4eic::ProtoClusterCollection
edm4eic::ClusterCollection,
#if EDM4EIC_VERSION_MAJOR >= 8
edm4eic::TrackClusterMatchCollection,
#endif
std::optional<edm4eic::MCRecoClusterParticleAssociationCollection>
>
>;

Expand All @@ -74,8 +103,8 @@ namespace eicrecon {
// --------------------------------------------------------------------------
//! Track-Based Cluster Merger/Splitter
// --------------------------------------------------------------------------
/*! An algorithm which takes a collection of proto-clusters, matches
* track projections, and then decides to merge or split those proto-
/*! An algorithm which takes a collection of clusters, matches
* track projections, and then decides to merge or split those
* clusters based on average E/p from simulations.
*
* Heavily inspired by Eur. Phys. J. C (2017) 77:466
Expand All @@ -91,8 +120,16 @@ namespace eicrecon {
TrackClusterMergeSplitter(std::string_view name) :
TrackClusterMergeSplitterAlgorithm {
name,
{"InputProtoClusterCollection", "InputTrackProjections"},
{"OutputProtoClusterCollection"},
#if EDM4EIC_VERSION_MAJOR >= 7
{"InputClusterCollection", "InputTrackProjections", "InputMCClusterAssociations", "InputMCHitAssociations"},
#else
{"InputClusterCollection", "InputTrackProjections", "InputMCClusterAssociations", "InputMCHits"},
#endif
#if EDM4EIC_VERSION_MAJOR >= 8
{"OutputProtoClusterCollection", "OutputTrackClusterMatches", "OutputMCClusterAssociations"},
#else
{"OutputProtoClusterCollection", "OutputMCClusterAssociations"},
#endif
"Merges or splits clusters based on tracks projected to them."
} {}

Expand All @@ -103,11 +140,15 @@ namespace eicrecon {
private:

// private methods
void get_projections(const edm4eic::TrackSegmentCollection* projections, VecProj& relevant_projects) const;
void match_clusters_to_tracks(const edm4eic::ProtoClusterCollection* clusters, const VecProj& projections, MapToVecProj& matches) const;
void merge_and_split_clusters(const VecClust& to_merge, const VecProj& to_split, edm4eic::ProtoClusterCollection* out_protoclusters) const;
float get_cluster_energy(const edm4eic::ProtoCluster& clust) const;
edm4hep::Vector3f get_cluster_position(const edm4eic::ProtoCluster& clust) const;
void get_projections(const edm4eic::TrackSegmentCollection* projections, VecProj& relevant_projects, VecTrk& relevant_trks) const;
void match_clusters_to_tracks(const edm4eic::ClusterCollection* clusters, const VecProj& projections, const VecTrk& tracks, MapToVecProj& matched_projects, MapToVecTrk& matched_tracks) const;
void merge_and_split_clusters(const VecClust& to_merge, const VecProj& to_split, std::vector<edm4eic::MutableCluster>& new_clusters) const;
void make_cluster(const VecClust& old_clusts, edm4eic::MutableCluster& new_clust, std::optional<MapToWeight> split_weights = std::nullopt) const;
#if EDM4EIC_VERSION_MAJOR >= 7
void collect_associations(const edm4eic::MutableCluster& new_clust, const VecClust& old_clusts, const edm4eic::MCRecoClusterParticleAssociationCollection* old_clust_assocs, const edm4eic::MCRecoCalorimeterHitAssociationCollection* old_hit_assocs, edm4eic::MCRecoClusterParticleAssociationCollection* new_clust_assocs) const;
#else
void collect_associations(const edm4eic::MutableCluster& new_clust, const VecClust& old_clusts, const edm4eic::MCRecoClusterParticleAssociationCollection* old_clust_assocs, const edm4hep::SimCalorimeterHitCollection* old_sim_hits, edm4eic::MCRecoClusterParticleAssociationCollection* new_clust_assocs) const;
#endif

// calorimeter id
int m_idCalo {0};
Expand Down
41 changes: 18 additions & 23 deletions src/detectors/BHCAL/BHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,20 @@ extern "C" {

app->Add(
new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
"HcalBarrelSplitMergeProtoClusters",
{"HcalBarrelIslandProtoClusters",
"CalorimeterTrackProjections"},
{"HcalBarrelSplitMergeProtoClusters"},
"HcalBarrelSplitMergeClustersWithoutShapes",
{"HcalBarrelClusters",
"CalorimeterTrackProjections",
"HcalBarrelClusterAssociations",
#if EDM4EIC_VERSION_MAJOR >= 7
"HcalBarrelRawHitAssociations"},
#else
"HcalBarrelHits"},
#endif
{"HcalBarrelSplitMergeClustersWithoutShapes",
#if EDM4EIC_VERSION_MAJOR >= 8
"HcalBarrelTrackSplitMergeClusterMatches",
#endif
"HcalBarrelSplitMergeClusterAssociationsWithoutShapes"},
{
.idCalo = "HcalBarrel_ID",
.minSigCut = -2.0,
Expand All @@ -211,34 +221,19 @@ extern "C" {
)
);

app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
"HcalBarrelSplitMergeClustersWithoutShapes",
{"HcalBarrelSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
"HcalBarrelHits"}, // edm4hep::SimCalorimeterHitCollection
{"HcalBarrelSplitMergeClustersWithoutShapes", // edm4eic::Cluster
"HcalBarrelSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
},
app // TODO: Remove me once fixed
)
);

app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
"HcalBarrelSplitMergeClusters",
{"HcalBarrelSplitMergeClustersWithoutShapes",
"HcalBarrelSplitMergeClusterAssociationsWithoutShapes"},
{"HcalBarrelSplitMergeClusters",
"HcalBarrelSplitMergeClusterAssociations"},
{},
{
.energyWeight = "log",
.logWeightBase = 6.2
},
app
)
);

}
}
51 changes: 22 additions & 29 deletions src/detectors/EEMC/EEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,6 @@ extern "C" {
)
);

app->Add(
new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
"EcalEndcapNSplitMergeProtoClusters",
{"EcalEndcapNIslandProtoClusters",
"CalorimeterTrackProjections"},
{"EcalEndcapNSplitMergeProtoClusters"},
{
.idCalo = "EcalEndcapN_ID",
.minSigCut = -1.0,
.avgEP = 1.0,
.sigEP = 0.10,
.drAdd = 0.08,
.sampFrac = 1.0,
.transverseEnergyProfileScale = 1.0
},
app // TODO: remove me once fixed
)
);

#if EDM4EIC_VERSION_MAJOR >= 8
app->Add(new JOmniFactoryGeneratorT<CalorimeterParticleIDPreML_factory>(
"EcalEndcapNParticleIDPreML",
Expand Down Expand Up @@ -248,19 +229,31 @@ extern "C" {
#endif

app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
"EcalEndcapNSplitMergeClustersWithoutShapes",
{"EcalEndcapNSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
"EcalEndcapNHits"}, // edm4hep::SimCalorimeterHitCollection
{"EcalEndcapNSplitMergeClustersWithoutShapes", // edm4eic::Cluster
"EcalEndcapNSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
"EcalEndcapNSplitMergeClustersWithoutShapes",
{"EcalEndcapNClustersWithoutPID",
"CalorimeterTrackProjections",
"EcalEndcapNClusterAssociations",
#if EDM4EIC_VERSION_MAJOR >= 7
"EcalEndcapNRawHitAssociations"},
#else
"EcalEndcapNHits"},
#endif
{"EcalEndcapNSplitMergeClustersWithoutShapes",
#if EDM4EIC_VERSION_MAJOR >= 8
"EcalEndcapNTrackSplitMergeClusterMatches",
#endif
"EcalEndcapNSplitMergeClusterAssociationsWithoutShapes"},
{
.energyWeight = "log",
.idCalo = "EcalEndcapN_ID",
.minSigCut = -1.0,
.avgEP = 1.0,
.sigEP = 0.10,
.drAdd = 0.08,
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false
.transverseEnergyProfileScale = 1.0
},
app // TODO: Remove me once fixed
app // TODO: remove me once fixed
)
);

Expand Down
34 changes: 14 additions & 20 deletions src/detectors/EHCAL/EHCAL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,20 @@ extern "C" {
);
app->Add(
new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
"HcalEndcapNSplitMergeProtoClusters",
{"HcalEndcapNIslandProtoClusters",
"CalorimeterTrackProjections"},
{"HcalEndcapNSplitMergeProtoClusters"},
"HcalEndcapNSplitMergeClustersWithoutShapes",
{"HcalEndcapNClusters",
"CalorimeterTrackProjections",
"HcalEndcapNClusterAssociations",
#if EDM4EIC_VERSION_MAJOR >= 7
"HcalEndcapNRawHitAssociations"},
#else
"HcalEndcapNHits"},
#endif
{"HcalEndcapNSplitMergeClustersWithoutShapes",
#if EDM4EIC_VERSION_MAJOR >= 8
"HcalEndcapNTrackSplitMergeClusterMatches",
#endif
"HcalEndcapNSplitMergeClusterAssociationsWithoutShapes"},
{
.idCalo = "HcalEndcapN_ID",
.minSigCut = -2.0,
Expand All @@ -179,22 +189,6 @@ extern "C" {
app // TODO: remove me once fixed
)
);
app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
"HcalEndcapNSplitMergeClustersWithoutShapes",
{"HcalEndcapNSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
"HcalEndcapNHits"}, // edm4hep::SimCalorimeterHitCollection
{"HcalEndcapNSplitMergeClustersWithoutShapes", // edm4eic::Cluster
"HcalEndcapNSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 6.2,
.enableEtaBounds = false
},
app // TODO: Remove me once fixed
)
);
app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
"HcalEndcapNSplitMergeClusters",
Expand Down
35 changes: 14 additions & 21 deletions src/detectors/FEMC/FEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,20 @@ extern "C" {

app->Add(
new JOmniFactoryGeneratorT<TrackClusterMergeSplitter_factory>(
"EcalEndcapPSplitMergeProtoClusters",
{"EcalEndcapPIslandProtoClusters",
"CalorimeterTrackProjections"},
{"EcalEndcapPSplitMergeProtoClusters"},
"EcalEndcapPSplitMergeClustersWithoutShapes",
{"EcalEndcapPClusters",
"CalorimeterTrackProjections",
"EcalEndcapPClusterAssociations",
#if EDM4EIC_VERSION_MAJOR >= 7
"EcalEndcapPRawHitAssociations"},
#else
"EcalEndcapPHits"},
#endif
{"EcalEndcapPSplitMergeClustersWithoutShapes",
#if EDM4EIC_VERSION_MAJOR >= 8
"EcalEndcapPTrackSplitMergeClusterMatches",
#endif
"EcalEndcapPSplitMergeClusterAssociationsWithoutShapes"},
{
.idCalo = "EcalEndcapP_ID",
.minSigCut = -2.0,
Expand All @@ -177,23 +187,6 @@ extern "C" {
)
);

app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterRecoCoG_factory>(
"EcalEndcapPSplitMergeClustersWithoutShapes",
{"EcalEndcapPSplitMergeProtoClusters", // edm4eic::ProtoClusterCollection
"EcalEndcapPHits"}, // edm4hep::SimCalorimeterHitCollection
{"EcalEndcapPSplitMergeClustersWithoutShapes", // edm4eic::Cluster
"EcalEndcapPSplitMergeClusterAssociationsWithoutShapes"}, // edm4eic::MCRecoClusterParticleAssociation
{
.energyWeight = "log",
.sampFrac = 1.0,
.logWeightBase = 3.6,
.enableEtaBounds = false
},
app // TODO: Remove me once fixed
)
);

app->Add(
new JOmniFactoryGeneratorT<CalorimeterClusterShape_factory>(
"EcalEndcapPSplitMergeClusters",
Expand Down
Loading
Loading