-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added PrimaryVertices factory (subCollection of CentralTrackVertices) (…
…#1609) ### Briefly, what does this PR introduce? ### What kind of change does this PR introduce? - [ ] Bug fix (issue #__) - [X] 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? ### Does this PR change default behavior? --------- Co-authored-by: Xin Dong <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Xin Dong <[email protected]> Co-authored-by: Dmitry Kalinkin <[email protected]>
- Loading branch information
1 parent
f833c1b
commit ca9579e
Showing
6 changed files
with
213 additions
and
0 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,85 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Daniel Brandenburg, Xin Dong | ||
|
||
#include <edm4eic/ReconstructedParticle.h> | ||
#include <edm4eic/VertexCollection.h> | ||
#include <edm4eic/unit_system.h> | ||
#include <edm4hep/Vector4f.h> | ||
#include <fmt/core.h> | ||
#include <podio/RelationRange.h> | ||
#include <cmath> | ||
#include <functional> | ||
#include <gsl/pointers> | ||
#include <map> | ||
|
||
#include "algorithms/reco/PrimaryVertices.h" | ||
#include "algorithms/reco/PrimaryVerticesConfig.h" | ||
|
||
namespace eicrecon { | ||
|
||
/** | ||
* @brief Initialize the PrimaryVertices Algorithm | ||
* | ||
*/ | ||
void PrimaryVertices::init() { | ||
} | ||
|
||
/** | ||
* @brief Produce a list of primary vertex candidates | ||
* | ||
* @param rcvtx - input collection of all vertex candidates | ||
* @return edm4eic::VertexCollection | ||
*/ | ||
void PrimaryVertices::process(const PrimaryVertices::Input& input, | ||
const PrimaryVertices::Output& output) const { | ||
const auto [rcvtx] = input; | ||
auto [out_primary_vertices] = output; | ||
|
||
// this multimap will store intermediate results | ||
// so that we can sort them before filling output | ||
// collection | ||
std::multimap<int, edm4eic::Vertex, std::greater<int>> primaryVertexMap; | ||
|
||
// our output collection of primary vertex | ||
// ordered by N_trk = associatedParticle array size | ||
out_primary_vertices->setSubsetCollection(); | ||
|
||
trace("We have {} candidate vertices", rcvtx->size()); | ||
|
||
for (const auto& vtx: *rcvtx) { | ||
const auto &v = vtx.getPosition(); | ||
|
||
// some basic vertex selection | ||
if (sqrt( v.x*v.x + v.y*v.y ) / edm4eic::unit::mm > m_cfg.maxVr || | ||
fabs( v.z ) / edm4eic::unit::mm > m_cfg.maxVz ) | ||
continue; | ||
|
||
if (vtx.getChi2() > m_cfg.maxChi2) continue; | ||
|
||
int N_trk = vtx.getAssociatedParticles().size(); | ||
trace( "\t N_trk = {}", N_trk ); | ||
primaryVertexMap.insert({N_trk, vtx}); | ||
} // vertex loop | ||
|
||
bool first = true; | ||
// map defined with std::greater<> will be iterated in descending order by the key | ||
for (auto [N_trk, vertex] : primaryVertexMap) { | ||
// Do not save primary candidates that | ||
// are not within range | ||
if ( N_trk > m_cfg.maxNtrk | ||
|| N_trk < m_cfg.minNtrk ){ | ||
continue; | ||
} | ||
|
||
// For logging and development | ||
// report the highest N_trk candidate chosen | ||
if (first) { | ||
trace("Max N_trk Candidate:"); | ||
trace("\t N_trk = {}", N_trk); | ||
trace("\t Primary vertex has xyz=( {}, {}, {} )", vertex.getPosition().x, vertex.getPosition().y, vertex.getPosition().z); | ||
first = false; | ||
} | ||
out_primary_vertices->push_back(vertex); | ||
} // loop on primaryVertexMap | ||
} | ||
} // namespace eicrecon |
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,38 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Daniel Brandenburg, Xin Dong | ||
|
||
#pragma once | ||
|
||
#include <algorithms/algorithm.h> | ||
#include <edm4eic/VertexCollection.h> | ||
#include <string> // for basic_string | ||
#include <string_view> // for string_view | ||
|
||
#include "algorithms/interfaces/WithPodConfig.h" | ||
#include "algorithms/reco/PrimaryVerticesConfig.h" | ||
|
||
|
||
namespace eicrecon { | ||
|
||
using PrimaryVerticesAlgorithm = algorithms::Algorithm< | ||
algorithms::Input<edm4eic::VertexCollection>, | ||
algorithms::Output<edm4eic::VertexCollection>>; | ||
|
||
class PrimaryVertices : | ||
public PrimaryVerticesAlgorithm, | ||
public WithPodConfig<PrimaryVerticesConfig>{ | ||
|
||
public: | ||
PrimaryVertices(std::string_view name) | ||
: PrimaryVerticesAlgorithm{name, | ||
{"inputVertices"}, | ||
{"outputPrimaryVertices"}, | ||
"Sort reconstructed vertices in PrimaryVertices collection"} {} | ||
|
||
void init() final; | ||
void process(const Input&, const Output&) const final; | ||
|
||
private: | ||
|
||
}; | ||
} // namespace eicrecon |
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,23 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Xin Dong | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <DD4hep/DD4hepUnits.h> | ||
|
||
namespace eicrecon { | ||
|
||
struct PrimaryVerticesConfig { | ||
|
||
// For now these are wide open | ||
// In the future the cut should depend | ||
// on the generator settings | ||
float maxVr = 50.0; // mm | ||
float maxVz = 500.0; // mm | ||
float maxChi2 = 10000.0; // | ||
int minNtrk = 1; // >= | ||
int maxNtrk = 1000000; // <= | ||
}; | ||
|
||
} // end eicrecon namespace |
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,51 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
// Copyright (C) 2024 Xin Dong | ||
|
||
#pragma once | ||
|
||
#include <JANA/JEvent.h> | ||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "algorithms/reco/PrimaryVertices.h" | ||
#include "algorithms/reco/PrimaryVerticesConfig.h" | ||
#include "services/algorithms_init/AlgorithmsInit_service.h" | ||
#include "extensions/jana/JOmniFactory.h" | ||
|
||
namespace eicrecon { | ||
|
||
class PrimaryVertices_factory : | ||
public JOmniFactory<PrimaryVertices_factory, PrimaryVerticesConfig> { | ||
|
||
public: | ||
using AlgoT = eicrecon::PrimaryVertices; | ||
private: | ||
std::unique_ptr<AlgoT> m_algo; | ||
|
||
PodioInput<edm4eic::Vertex> m_rc_vertices_input {this}; | ||
|
||
// Declare outputs | ||
PodioOutput<edm4eic::Vertex> m_primary_vertices_output {this}; | ||
|
||
Service<AlgorithmsInit_service> m_algorithmsInit {this}; | ||
|
||
public: | ||
void Configure() { | ||
m_algo = std::make_unique<AlgoT>(GetPrefix()); | ||
m_algo->level((algorithms::LogLevel)logger()->level()); | ||
|
||
m_algo->applyConfig(config()); | ||
m_algo->init(); | ||
} | ||
|
||
void ChangeRun(int64_t run_number) { | ||
} | ||
|
||
void Process(int64_t run_number, uint64_t event_number) { | ||
m_algo->process({m_rc_vertices_input()}, {m_primary_vertices_output().get()}); | ||
} | ||
}; | ||
|
||
} // eicrecon |
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