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

feat!: link dRICH PID with Reconstructed*ChargedParticles #829

Merged
merged 16 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
8 changes: 4 additions & 4 deletions docs/design/gaudi-algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ flowchart LR
HcalEndcapPClusters(HcalEndcapPClusters<br/>HcalEndcapPClustersAssoc)
end

MCParticles --> ParticlesWithTruthPID[ParticlesWithTruthPID]:::alg
outputTrackParameters --> ParticlesWithTruthPID
ParticlesWithTruthPID --> ReconstructedChargedParticles(ReconstructedChargedParticles)
ParticlesWithTruthPID --> ReconstructedChargedParticlesAssoc(ReconstructedChargedParticlesAssoc)
MCParticles --> ParticlesWithPID[ParticlesWithPID]:::alg
outputTrackParameters --> ParticlesWithPID
ParticlesWithPID --> ReconstructedChargedParticles(ReconstructedChargedParticles)
ParticlesWithPID --> ReconstructedChargedParticlesAssoc(ReconstructedChargedParticlesAssoc)

MCParticles --> MatchClusters[MatchClusters]:::alg
ReconstructedChargedParticles --> MatchClusters
Expand Down
8 changes: 4 additions & 4 deletions docs/design/particle_matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ flowchart LR
MCParticles --> MC2SmearedParticle[MC2SmearedParticle]:::alg
MC2SmearedParticle --> GeneratedParticles

MCParticles --> ParticlesWithTruthPID[ParticlesWithTruthPID]:::alg
TrackingOutput --> ParticlesWithTruthPID
MCParticles --> ParticlesWithPID[ParticlesWithPID]:::alg
TrackingOutput --> ParticlesWithPID

ParticlesWithTruthPID --> ReconstructedChargedParticles(ReconstructedChargedParticles)
ParticlesWithTruthPID --> ReconstructedChargedParticlesAssoc(ReconstructedChargedParticlesAssoc)
ParticlesWithPID --> ReconstructedChargedParticles(ReconstructedChargedParticles)
ParticlesWithPID --> ReconstructedChargedParticlesAssoc(ReconstructedChargedParticlesAssoc)

MCParticles --> MatchClusters[MatchClusters]:::alg
ReconstructedChargedParticles --> MatchClusters
Expand Down
18 changes: 9 additions & 9 deletions docs/design/tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ flowchart TB

ACTSToModel --> TrackingModel(Tracking PODIO data)

TrackingModel --> ParticlesWithTruthPID:::alg
MCParticles --> ParticlesWithTruthPID[<strong>Track to MC matching</strong>:<br/><i>ParticlesWithTruthPID</i>]
TrackingModel --> ParticlesWithPID:::alg
MCParticles --> ParticlesWithPID[<strong>Track to MC matching</strong>:<br/><i>ParticlesWithPID</i>]
ACTSToModel --> CentralTrackSegments

ParticlesWithTruthPID --> ReconstructedChargedParticles
ParticlesWithTruthPID --> ReconstructedChargedParticlesAssociations
ParticlesWithPID --> ReconstructedChargedParticles
ParticlesWithPID --> ReconstructedChargedParticlesAssociations

subgraph Tracking output
direction LR
Expand Down Expand Up @@ -132,10 +132,10 @@ flowchart TB
CentralCKFTrajectories --> TrackProjector[TrackProjector]:::alg
TrackProjector --> CentralTrackSegments

outputTrackParameters --> ParticlesWithTruthPID[ParticlesWithTruthPID]:::alg
MCParticles --> ParticlesWithTruthPID
ParticlesWithTruthPID --> ReconstructedChargedParticles
ParticlesWithTruthPID --> ReconstructedChargedParticlesAssociations
outputTrackParameters --> ParticlesWithPID[ParticlesWithPID]:::alg
MCParticles --> ParticlesWithPID
ParticlesWithPID --> ReconstructedChargedParticles
ParticlesWithPID --> ReconstructedChargedParticlesAssociations



Expand Down Expand Up @@ -165,5 +165,5 @@ The flow is:
- Reconstructed hits from all detectors get to **TrackerSourceLinker** which provides measurement and linkage data for ACTS
- **CFKTracking** does fitting and produces results in ACTS classes
- **ParticlesFromTrackFit** process ACTS data and store it to PODIO edm4hep/eic data model
- **ParticlesWithTruthPID** algorithm does track-matching with MCParticles and produce resulted `edm4eic::ReconstructedParticles` with association class
- **ParticlesWithPID** algorithm does track-matching with MCParticles and produce resulted `edm4eic::ReconstructedParticles` with association class
- **TrackProjection** - saves track states/points data to PODIO data model and returns CetntralTrackSegments data
84 changes: 84 additions & 0 deletions src/algorithms/pid/ConvertParticleID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2023, Christopher Dilks

// Converters of ParticleID objects
//

#pragma once

#include <cstddef>
#include <map>

// data model
#include <edm4eic/CherenkovParticleID.h>
#include <edm4eic/CherenkovParticleIDHypothesis.h>
#include <edm4hep/ParticleIDCollection.h>

namespace eicrecon {

class ConvertParticleID {
public:

// index map, used for external access to the converted objects
using IndexMap = std::map<std::size_t, unsigned int>; // <collection index, object ID>

// convert edm4eic::CherenkovParticleID hypotheses to list of edm4hep::ParticleID objects
// - requires input `CherenkovParticleID` object `in_pid`
// - adds output `ParticleID` objects to collection `out_pids`
// - sorted by likelihood, if `sort_by_likelihood==true`
// - returns a map of the new `out_pid` indices to new `ParticleID` IDs, so the caller can
// access the newly created `ParticleID` objects
static IndexMap ConvertToParticleIDs(
const edm4eic::CherenkovParticleID& in_pid,
edm4hep::ParticleIDCollection& out_pids,
bool sort_by_likelihood = false
)
{

// output vector of collection indices
IndexMap out_indices;

// build list of (hypothesis index, hypothesis weight)
using HypIndex = std::pair<std::size_t, decltype(edm4eic::CherenkovParticleIDHypothesis::weight)>;
std::vector<HypIndex> hyp_indices;
for(std::size_t hyp_index=0; hyp_index<in_pid.hypotheses_size(); hyp_index++)
hyp_indices.push_back(HypIndex{
hyp_index,
in_pid.getHypotheses(hyp_index).weight
});

// sort it by likelihood, if needed
if(sort_by_likelihood)
std::sort(
hyp_indices.begin(),
hyp_indices.end(),
[] (HypIndex& a, HypIndex& b) { return a.second > b.second; }
);

// create and fill output objects
for(const auto& [hyp_index, hyp_weight] : hyp_indices) {

// get the input hypothesis
auto in_hyp = in_pid.getHypotheses(hyp_index);

// create output `ParticleID` object
auto out_index = out_pids.size();
auto out_pid = out_pids.create();
out_indices.insert({out_index, out_pid.id()});

// fill scalars
out_pid.setPDG( static_cast<decltype(edm4hep::ParticleIDData::PDG)> (in_hyp.PDG) );
out_pid.setLikelihood( static_cast<decltype(edm4hep::ParticleIDData::likelihood)> (in_hyp.weight) );
out_pid.setType( static_cast<decltype(edm4hep::ParticleIDData::type)> (0) ); // FIXME: not used yet
out_pid.setAlgorithmType( static_cast<decltype(edm4hep::ParticleIDData::algorithmType)> (0) ); // FIXME: not used yet

// fill parameters vector
out_pid.addToParameters( static_cast<float> (in_hyp.npe) ); // NPE for this hypothesis

}

return out_indices;
}

}; // class ConvertParticleID
} // namespace eicrecon
Loading