-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
223 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2023, Christopher Dilks | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#include "MergeTracks.h" | ||
|
||
// AlgorithmInit | ||
//--------------------------------------------------------------------------- | ||
void eicrecon::MergeTracks::AlgorithmInit(std::shared_ptr<spdlog::logger>& logger) | ||
{ | ||
m_log = logger; | ||
} | ||
|
||
|
||
// AlgorithmChangeRun | ||
//--------------------------------------------------------------------------- | ||
void eicrecon::MergeTracks::AlgorithmChangeRun() { | ||
} | ||
|
||
|
||
// AlgorithmProcess | ||
//--------------------------------------------------------------------------- | ||
std::unique_ptr<edm4eic::TrackSegmentCollection> eicrecon::MergeTracks::AlgorithmProcess( | ||
std::vector<const edm4eic::TrackSegmentCollection*> in_track_collections | ||
) | ||
{ | ||
// logging | ||
m_log->trace("{:=^70}"," call MergeTracks::AlgorithmProcess "); | ||
|
||
// start output collection | ||
auto out_tracks = std::make_unique<edm4eic::TrackSegmentCollection>(); | ||
|
||
// check that all input collections have the same size | ||
std::size_t n_tracks = -1; | ||
for(const auto& in_track_collection : in_track_collections) { | ||
if(n_tracks == -1) | ||
n_tracks = in_track_collection->size(); | ||
else if(n_tracks != in_track_collection->size()) { | ||
m_log->error("input track collections do not have the same size; cannot merge"); | ||
return out_tracks; | ||
} | ||
} | ||
|
||
// loop over track collection elements | ||
for(std::size_t i_track=0; i_track<n_tracks; i_track++) { | ||
|
||
// create a new output track, and a local container to hold its track points | ||
auto out_track = out_tracks->create(); | ||
std::vector<edm4eic::TrackPoint> out_track_points; | ||
|
||
// loop over collections for this track, and add each track's points to `out_track_points` | ||
for(const auto& in_track_collection : in_track_collections) { | ||
const auto& in_track = in_track_collection->at(i_track); | ||
for(const auto& point : in_track.getPoints()) | ||
out_track_points.push_back(point); | ||
} | ||
|
||
// sort all `out_track_points` by time | ||
std::sort( | ||
out_track_points.begin(), | ||
out_track_points.end(), | ||
[] (edm4eic::TrackPoint& a, edm4eic::TrackPoint& b) { return a.time < b.time; } | ||
); | ||
|
||
// add these sorted points to `out_track` | ||
for(const auto& point : out_track_points) | ||
out_track.addToPoints(point); | ||
|
||
/* FIXME: merge other members, such as `length` and `lengthError`; | ||
* currently not needed for RICH tracks, so such members are left as default | ||
*/ | ||
|
||
} // end loop over tracks | ||
|
||
return out_tracks; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023, Christopher Dilks | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
// merge together TrackSegments, sorting their TrackPoints by time | ||
/* FIXME: only VectorMember `points` is combined, which is all that is needed | ||
* for the RICH detectors. If using this algorithm for any other purpose, you | ||
* may want to combine the other members and relations in `TrackSegment`. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <algorithm> | ||
|
||
// data model | ||
#include <edm4eic/TrackSegmentCollection.h> | ||
|
||
// EICrecon | ||
#include <spdlog/spdlog.h> | ||
|
||
namespace eicrecon { | ||
|
||
class MergeTracks { | ||
|
||
public: | ||
MergeTracks() = default; | ||
~MergeTracks() {} | ||
|
||
void AlgorithmInit(std::shared_ptr<spdlog::logger>& logger); | ||
void AlgorithmChangeRun(); | ||
|
||
// AlgorithmProcess | ||
// - input: a list of TrackSegment collections | ||
// - output: the merged TrackSegment collections, effectively the "zip" of the input collections | ||
std::unique_ptr<edm4eic::TrackSegmentCollection> AlgorithmProcess( | ||
std::vector<const edm4eic::TrackSegmentCollection*> in_track_collections | ||
); | ||
|
||
private: | ||
std::shared_ptr<spdlog::logger> m_log; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2022, 2023, Christopher Dilks | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#include "MergeTrack_factory.h" | ||
|
||
//----------------------------------------------------------------------------- | ||
void eicrecon::MergeTrack_factory::Init() { | ||
|
||
// get plugin name and tag | ||
auto app = GetApplication(); | ||
auto detector_name = eicrecon::str::ReplaceAll(GetPluginName(), ".so", ""); | ||
auto param_prefix = detector_name + ":" + GetTag(); | ||
InitDataTags(param_prefix); | ||
|
||
// services | ||
InitLogger(param_prefix, "info"); | ||
m_algo.AlgorithmInit(m_log); | ||
m_log->debug("detector_name='{}' param_prefix='{}'", detector_name, param_prefix); | ||
|
||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void eicrecon::MergeTrack_factory::BeginRun(const std::shared_ptr<const JEvent> &event) { | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
void eicrecon::MergeTrack_factory::Process(const std::shared_ptr<const JEvent> &event) { | ||
|
||
// get input collections | ||
std::vector<const edm4eic::TrackSegmentCollection*> in_track_collections; | ||
for(auto& input_tag : GetInputTags()) | ||
in_track_collections.push_back( | ||
static_cast<const edm4eic::TrackSegmentCollection*>(event->GetCollectionBase(input_tag)) | ||
); | ||
|
||
// call the MergeTracks algorithm | ||
try { | ||
auto out_track_collection = m_algo.AlgorithmProcess(in_track_collections); | ||
SetCollection(std::move(out_track_collection)); | ||
} | ||
catch(std::exception &e) { | ||
m_log->warn("Exception in underlying algorithm: {}. Event data will be skipped", e.what()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2022, 2023 Christopher Dilks | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
|
||
// JANA | ||
#include <extensions/jana/JChainFactoryT.h> | ||
#include <JANA/JEvent.h> | ||
|
||
// data model | ||
#include <edm4eic/TrackSegmentCollection.h> | ||
|
||
// algorithms | ||
#include <algorithms/pid/MergeTracks.h> | ||
|
||
// services | ||
#include <services/log/Log_service.h> | ||
#include <extensions/spdlog/SpdlogExtensions.h> | ||
#include <extensions/spdlog/SpdlogMixin.h> | ||
#include <extensions/string/StringHelpers.h> | ||
|
||
namespace eicrecon { | ||
|
||
class MergeTracks; | ||
|
||
class MergeTrack_factory : | ||
public JChainFactoryT<edm4eic::TrackSegment>, | ||
public SpdlogMixin<MergeTrack_factory> | ||
{ | ||
|
||
public: | ||
|
||
explicit MergeTrack_factory(std::vector<std::string> default_input_tags) : | ||
JChainFactoryT<edm4eic::TrackSegment>(std::move(default_input_tags)) {} | ||
|
||
/** One time initialization **/ | ||
void Init() override; | ||
|
||
/** On run change preparations **/ | ||
void BeginRun(const std::shared_ptr<const JEvent> &event) override; | ||
|
||
/** Event by event processing **/ | ||
void Process(const std::shared_ptr<const JEvent> &event) override; | ||
|
||
private: | ||
|
||
// underlying algorithm | ||
eicrecon::MergeTracks m_algo; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters