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

refactor: Accumulated vertexing changes in Examples #3121

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions Core/src/Vertexing/AdaptiveMultiVertexFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ Result<bool> AdaptiveMultiVertexFinder::isMergedVertex(
auto sumCovZTInverse = safeInverse(sumCovZT);
if (!sumCovZTInverse) {
ACTS_ERROR("Vertex z-t covariance matrix is singular.");
ACTS_ERROR("sumCovZT:\n" << sumCovZT);
return Result<bool>::failure(VertexingError::SingularMatrix);
}
significance = std::sqrt(deltaZT.dot(*sumCovZTInverse * deltaZT));
Expand All @@ -529,6 +530,7 @@ Result<bool> AdaptiveMultiVertexFinder::isMergedVertex(
const double sumVarZ = otherCov(eZ, eZ) + candidateCov(eZ, eZ);
if (sumVarZ <= 0) {
ACTS_ERROR("Variance of the vertex's z-coordinate is not positive.");
ACTS_ERROR("sumVarZ:\n" << sumVarZ);
return Result<bool>::failure(VertexingError::SingularMatrix);
}
// Use only z significance
Expand All @@ -542,6 +544,7 @@ Result<bool> AdaptiveMultiVertexFinder::isMergedVertex(
auto sumCovInverse = safeInverse(sumCov);
if (!sumCovInverse) {
ACTS_ERROR("Vertex 4D covariance matrix is singular.");
ACTS_ERROR("sumCov:\n" << sumCov);
return Result<bool>::failure(VertexingError::SingularMatrix);
}
significance = std::sqrt(deltaPos.dot(*sumCovInverse * deltaPos));
Expand All @@ -553,6 +556,7 @@ Result<bool> AdaptiveMultiVertexFinder::isMergedVertex(
auto sumCovInverse = safeInverse(sumCov);
if (!sumCovInverse) {
ACTS_ERROR("Vertex 3D covariance matrix is singular.");
ACTS_ERROR("sumCov:\n" << sumCov);
return Result<bool>::failure(VertexingError::SingularMatrix);
}
significance = std::sqrt(deltaPos.dot(*sumCovInverse * deltaPos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ActsExamples/EventData/ProtoVertex.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/EventData/Trajectories.hpp"
#include "ActsExamples/EventData/Vertex.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"
Expand All @@ -45,14 +46,6 @@ struct AlgorithmContext;

class VertexFitterAlgorithm final : public IAlgorithm {
public:
using Propagator = Acts::Propagator<Acts::EigenStepper<>>;
using PropagatorOptions = Acts::PropagatorOptions<>;
using Linearizer = Acts::HelicalTrackLinearizer;
using VertexFitter = Acts::FullBilloirVertexFitter;
using VertexFitterOptions = Acts::VertexingOptions;

using VertexCollection = std::vector<Acts::Vertex>;

struct Config {
/// Optional. Input track parameters collection
std::string inputTrackParameters;
Expand Down Expand Up @@ -95,7 +88,7 @@ class VertexFitterAlgorithm final : public IAlgorithm {
ReadDataHandle<ProtoVertexContainer> m_inputProtoVertices{
this, "InputProtoVertices"};

WriteDataHandle<VertexCollection> m_outputVertices{this, "OutputVertices"};
WriteDataHandle<VertexContainer> m_outputVertices{this, "OutputVertices"};
};

} // namespace ActsExamples
9 changes: 8 additions & 1 deletion Examples/Algorithms/Vertexing/src/VertexFitterAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Acts/Vertexing/TrackAtVertex.hpp"
#include "Acts/Vertexing/Vertex.hpp"
#include "ActsExamples/EventData/ProtoVertex.hpp"
#include "ActsExamples/EventData/Vertex.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"

#include <ostream>
Expand All @@ -41,6 +42,12 @@ ActsExamples::VertexFitterAlgorithm::VertexFitterAlgorithm(

ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute(
const ActsExamples::AlgorithmContext& ctx) const {
using Propagator = Acts::Propagator<Acts::EigenStepper<>>;
using PropagatorOptions = Acts::PropagatorOptions<>;
using Linearizer = Acts::HelicalTrackLinearizer;
using VertexFitter = Acts::FullBilloirVertexFitter;
using VertexFitterOptions = Acts::VertexingOptions;

// Set up EigenStepper
Acts::EigenStepper<> stepper(m_cfg.bField);

Expand Down Expand Up @@ -74,7 +81,7 @@ ActsExamples::ProcessCode ActsExamples::VertexFitterAlgorithm::execute(

std::vector<Acts::InputTrack> inputTracks;

VertexCollection fittedVertices;
VertexContainer fittedVertices;

for (const auto& protoVertex : protoVertices) {
// un-constrained fit requires at least two tracks
Expand Down
20 changes: 20 additions & 0 deletions Examples/Framework/include/ActsExamples/EventData/Vertex.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Vertexing/Vertex.hpp"

#include <vector>

namespace ActsExamples {

/// Container of vertices.
using VertexContainer = std::vector<Acts::Vertex>;

} // namespace ActsExamples
3 changes: 2 additions & 1 deletion Examples/Framework/src/Framework/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ std::pair<std::size_t, std::size_t> Sequencer::determineEventsRange() const {
// since we use event ranges (and not just num events) they might not
// overlap
if (end < beg) {
ACTS_ERROR("Available events ranges from readers do not overlap");
ACTS_ERROR("Available events ranges from readers do not overlap (beg="
<< beg << ", end=" << end << ")");
return kInvalidEventsRange;
}
// configured readers without available events makes no sense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class RootVertexReader : public IReader {
std::string treeName = "vertices";
/// The name of the input file
std::string filePath;
/// Whether the events are ordered or not
bool orderedEvents = true;
};

/// Constructor
Expand Down Expand Up @@ -99,12 +97,13 @@ class RootVertexReader : public IReader {
std::vector<float>* m_vy = new std::vector<float>;
std::vector<float>* m_vz = new std::vector<float>;
std::vector<float>* m_vt = new std::vector<float>;
std::vector<std::vector<std::uint64_t>>* m_outgoingParticles =
new std::vector<std::vector<std::uint64_t>>;
// Decoded vertex identifier; see Barcode definition for details.
std::vector<std::uint32_t>* m_vertexPrimary = new std::vector<std::uint32_t>;
std::vector<std::uint32_t>* m_vertexSecondary =
new std::vector<std::uint32_t>;
std::vector<std::uint32_t>* m_generation = new std::vector<std::uint32_t>;
std::vector<std::vector<double>>* m_outgoingParticles =
new std::vector<std::vector<double>>;
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RootVertexWriter final : public WriterT<SimVertexContainer> {
std::vector<float> m_vz;
std::vector<float> m_vt;
/// Outgoing particles from the vertex.
std::vector<std::vector<double>> m_outgoingParticles;
std::vector<std::vector<std::uint64_t>> m_outgoingParticles;
// Decoded vertex identifier; see Barcode definition for details.
std::vector<std::uint32_t> m_vertexPrimary;
std::vector<std::uint32_t> m_vertexSecondary;
Expand Down
16 changes: 8 additions & 8 deletions Examples/Io/Root/src/RootVertexReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ RootVertexReader::RootVertexReader(const RootVertexReader::Config& config,
m_events = m_inputChain->GetEntries();
ACTS_DEBUG("The full chain has " << m_events << " entries.");

// If the events are not in order, get the entry numbers for ordered events
if (!m_cfg.orderedEvents) {
// Sort the entry numbers of the events
{
m_entryNumbers.resize(m_events);
m_inputChain->Draw("event_id", "", "goff");
// Sort to get the entry numbers of the ordered events
Expand Down Expand Up @@ -104,13 +104,10 @@ ProcessCode RootVertexReader::read(const AlgorithmContext& context) {
SimVertexContainer vertices;

// Read the correct entry
auto entry = context.eventNumber;
if (!m_cfg.orderedEvents && entry < m_entryNumbers.size()) {
entry = m_entryNumbers[entry];
}
auto entry = m_entryNumbers.at(context.eventNumber);
m_inputChain->GetEntry(entry);
ACTS_INFO("Reading event: " << context.eventNumber
<< " stored as entry: " << entry);
ACTS_DEBUG("Reading event: " << context.eventNumber
<< " stored as entry: " << entry);

unsigned int nVertices = m_vertexId->size();

Expand All @@ -133,6 +130,9 @@ ProcessCode RootVertexReader::read(const AlgorithmContext& context) {
vertices.insert(v);
}

ACTS_DEBUG("Read " << vertices.size() << " vertices for event "
<< context.eventNumber);

// Write the collections to the EventStore
m_outputVertices(context, std::move(vertices));

Expand Down
4 changes: 2 additions & 2 deletions Examples/Io/Root/src/RootVertexWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ ProcessCode RootVertexWriter::writeT(const AlgorithmContext& ctx,
Acts::UnitConstants::mm));
// TODO ingoing particles
// outgoing particles
std::vector<double> outgoing;
std::vector<std::uint64_t> outgoing;
for (const auto& particle : vertex.outgoing) {
outgoing.push_back(static_cast<double>(particle.value()));
outgoing.push_back(particle.value());
}
m_outgoingParticles.push_back(std::move(outgoing));
// decoded barcode components
Expand Down
4 changes: 2 additions & 2 deletions Examples/Python/src/Input.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
// Copyright (C) 2021 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -45,7 +45,7 @@ void addInput(Context& ctx) {

ACTS_PYTHON_DECLARE_READER(ActsExamples::RootVertexReader, mex,
"RootVertexReader", outputVertices, treeName,
filePath, orderedEvents);
filePath);

ACTS_PYTHON_DECLARE_READER(ActsExamples::RootMaterialTrackReader, mex,
"RootMaterialTrackReader", outputMaterialTracks,
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/src/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ void addOutput(Context& ctx) {

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::TrackFinderPerformanceWriter, mex,
"TrackFinderPerformanceWriter", inputProtoTracks,
inputParticles, inputMeasurementParticlesMap,
inputProtoTrackParticleMatching, filePath,
fileMode, treeNameTracks, treeNameParticles);
inputMeasurementParticlesMap, inputParticles,
filePath, fileMode, treeNameTracks,
treeNameParticles);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::TrackFitterPerformanceWriter, mex,
"TrackFitterPerformanceWriter", inputTracks,
Expand Down
Loading