Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 7 additions & 5 deletions Core/include/Acts/Seeding/GbtsDataStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// TODO: update to C++17 style
#include "Acts/Seeding/GbtsGeometry.hpp"
#include "Acts/Seeding/GbtsLutParser.hpp"
#include "Acts/Seeding/SeedFinderGbtsConfig.hpp"

#include <array>
Expand Down Expand Up @@ -79,8 +80,9 @@ class GbtsEtaBin {

class GbtsDataStorage {
public:
explicit GbtsDataStorage(const GbtsGeometry& geometry,
const SeedFinderGbtsConfig& config);
explicit GbtsDataStorage(std::shared_ptr<const GbtsGeometry> geometry,
const SeedFinderGbtsConfig config,
std::shared_ptr<const GbtsLutParser> lutParser);
~GbtsDataStorage();

int loadPixelGraphNodes(short layerIndex, const std::vector<GbtsNode>& coll,
Expand All @@ -100,9 +102,9 @@ class GbtsDataStorage {
}

protected:
const GbtsGeometry& m_geo;
const SeedFinderGbtsConfig& m_config;
std::vector<std::array<float, 5>> m_mlLUT;
std::shared_ptr<const GbtsGeometry> m_geo;
const SeedFinderGbtsConfig m_config;
std::shared_ptr<const GbtsLutParser> m_lutParser;
std::vector<GbtsEtaBin> m_etaBins;
};

Expand Down
31 changes: 31 additions & 0 deletions Core/include/Acts/Seeding/GbtsLutParser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include <array>
#include <string>
#include <vector>

namespace Acts::Experimental {

class GbtsLutParser {
public:
explicit GbtsLutParser() = default;

void parseLutFile(std::string& lutInputFile, bool useML);

const std::vector<std::array<float, 5>>& getParsedLut() const {
return m_mlLUT;
}

private:
std::vector<std::array<float, 5>> m_mlLUT{};
};

} // namespace Acts::Experimental
30 changes: 15 additions & 15 deletions Core/include/Acts/Seeding/SeedFinderGbts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/EventData/SeedContainer2.hpp"
#include "Acts/Seeding/GbtsDataStorage.hpp"
#include "Acts/Seeding/GbtsGeometry.hpp"
#include "Acts/Seeding/GbtsLutParser.hpp"
#include "Acts/Seeding/SeedFinderGbtsConfig.hpp"
#include "Acts/TrackFinding/RoiDescriptor.hpp"
#include "Acts/Utilities/Logger.hpp"
Expand All @@ -31,16 +32,14 @@ using SPContainerComponentsType =

class SeedFinderGbts {
public:
SeedFinderGbts(const SeedFinderGbtsConfig config, const GbtsGeometry* gbtsGeo,
SeedFinderGbts(const SeedFinderGbtsConfig config,
std::unique_ptr<GbtsGeometry> gbtsGeo,
const std::vector<TrigInDetSiLayer>* layerGeometry,
std::unique_ptr<GbtsLutParser> gbtsLutParser,
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("Finder",
Acts::Logging::Level::INFO));

using GNN_Node = GbtsNode;
using GNN_DataStorage = GbtsDataStorage;
using GNN_Edge = GbtsEdge;

struct seedProperties {
seedProperties(float quality, int clone, std::vector<unsigned int> sps)
: seedQuality(quality), isClone(clone), spacepoints(std::move(sps)) {}
Expand All @@ -57,30 +56,31 @@ class SeedFinderGbts {

SeedContainer2 CreateSeeds(
const RoiDescriptor& roi,
const SPContainerComponentsType& SpContainerComponents, int max_layers);
const SPContainerComponentsType& SpContainerComponents,
int max_layers) const;

std::vector<std::vector<SeedFinderGbts::GNN_Node>> CreateNodes(
const auto& container, int MaxLayers);
std::vector<std::vector<GbtsNode>> CreateNodes(const auto& container,
int MaxLayers) const;

std::pair<int, int> buildTheGraph(
const RoiDescriptor& roi, const std::unique_ptr<GNN_DataStorage>& storage,
std::vector<GNN_Edge>& edgeStorage) const;
const RoiDescriptor& roi, const std::unique_ptr<GbtsDataStorage>& storage,
std::vector<GbtsEdge>& edgeStorage) const;

int runCCA(int nEdges, std::vector<GNN_Edge>& edgeStorage) const;
int runCCA(int nEdges, std::vector<GbtsEdge>& edgeStorage) const;

void extractSeedsFromTheGraph(
int maxLevel, int nEdges, int nHits, std::vector<GNN_Edge>& edgeStorage,
int maxLevel, int nEdges, int nHits, std::vector<GbtsEdge>& edgeStorage,
std::vector<seedProperties>& vSeedCandidates) const;

private:
SeedFinderGbtsConfig m_config;

const GbtsGeometry* m_geo;

std::unique_ptr<GNN_DataStorage> m_storage = nullptr;
const std::shared_ptr<const GbtsGeometry> m_geo;

const std::vector<TrigInDetSiLayer>* m_layerGeometry;

const std::shared_ptr<const GbtsLutParser> m_lutParser;

std::unique_ptr<const Acts::Logger> m_logger =
Acts::getDefaultLogger("Finder", Acts::Logging::Level::INFO);

Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/TrackFinding/GbtsConnector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

// TODO: update to C++17 style
// Consider to moving to detail subdirectory
#include <fstream>
#include <map>
#include <string>
#include <vector>

namespace Acts::Experimental {
Expand All @@ -37,7 +37,7 @@ class GbtsConnector {
};

public:
GbtsConnector(std::ifstream& inFile, bool LRTmode);
GbtsConnector(std::string& inFile, bool LRTmode);
~GbtsConnector();

float m_etaBin{};
Expand Down
1 change: 1 addition & 0 deletions Core/src/Seeding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target_sources(
EstimateTrackParamsFromSeed.cpp
CompSpacePointAuxiliaries.cpp
CompositeSpacePointLineFitter.cpp
GbtsLutParser.cpp
GbtsDataStorage.cpp
GbtsGeometry.cpp
GbtsTrackingFilter.cpp
Expand Down
57 changes: 17 additions & 40 deletions Core/src/Seeding/GbtsDataStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numbers>
#include <utility>
namespace Acts::Experimental {

GbtsEtaBin::GbtsEtaBin() {
Expand All @@ -29,7 +29,7 @@ GbtsEtaBin::~GbtsEtaBin() {
}

void GbtsEtaBin::sortByPhi() {
std::vector<std::pair<float, const GbtsNode*> > phiBuckets[32];
std::vector<std::pair<float, const GbtsNode*>> phiBuckets[32];

int nBuckets = 31;

Expand Down Expand Up @@ -101,38 +101,15 @@ void GbtsEtaBin::generatePhiIndexing(float dphi) {
std::pair<float, unsigned int>(phi + 2 * std::numbers::pi, nIdx));
}
}
GbtsDataStorage::GbtsDataStorage(const GbtsGeometry& geometry,
const SeedFinderGbtsConfig& config)
: m_geo(geometry), m_config(config) {
GbtsDataStorage::GbtsDataStorage(std::shared_ptr<const GbtsGeometry> geometry,
SeedFinderGbtsConfig config,
std::shared_ptr<const GbtsLutParser> lutParser)
: m_geo(std::move(geometry)),
m_config(std::move(config)),
m_lutParser(std::move(lutParser)) {
// parse the look up table if useML is true
if (m_config.useML) {
if (m_config.lutInputFile.empty()) {
throw std::runtime_error("Cannot find ML predictor LUT file");
} else {
m_mlLUT.reserve(100);
std::ifstream ifs(std::string(m_config.lutInputFile).c_str());

if (!ifs.is_open()) {
throw std::runtime_error("Failed to open LUT file");
}

float cl_width{}, min1{}, max1{}, min2{}, max2{};

while (ifs >> cl_width >> min1 >> max1 >> min2 >> max2) {
std::array<float, 5> lut_line = {cl_width, min1, max1, min2, max2};
m_mlLUT.emplace_back(lut_line);
}
if (!ifs.eof()) {
// ended if parse error present, not clean EOF

throw std::runtime_error("Stopped reading LUT file due to parse error");
}

ifs.close();
}
}

m_etaBins.resize(geometry.num_bins());
m_etaBins.resize(m_geo->num_bins());
}

GbtsDataStorage::~GbtsDataStorage() = default;
Expand All @@ -142,7 +119,7 @@ int GbtsDataStorage::loadPixelGraphNodes(short layerIndex,
bool useML) {
int nLoaded = 0;

const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIndex);
const GbtsLayer* pL = m_geo->getGbtsLayerByIndex(layerIndex);

if (pL == nullptr) {
return -1;
Expand Down Expand Up @@ -179,7 +156,7 @@ int GbtsDataStorage::loadStripGraphNodes(short layerIndex,
const std::vector<GbtsNode>& coll) {
int nLoaded = 0;

const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIndex);
const GbtsLayer* pL = m_geo->getGbtsLayerByIndex(layerIndex);

if (pL == nullptr) {
return -1;
Expand Down Expand Up @@ -218,18 +195,18 @@ void GbtsDataStorage::initializeNodes(bool useML) {
for (auto& b : m_etaBins) {
b.initializeNodes();
if (!b.m_vn.empty()) {
b.m_layerKey = m_geo.getGbtsLayerKeyByIndex((*b.m_vn.begin())->m_layer);
b.m_layerKey = m_geo->getGbtsLayerKeyByIndex((*b.m_vn.begin())->m_layer);
}
}

if (!useML) {
return;
}

unsigned int nL = m_geo.num_layers();
unsigned int nL = m_geo->num_layers();

for (unsigned int layerIdx = 0; layerIdx < nL; layerIdx++) {
const GbtsLayer* pL = m_geo.getGbtsLayerByIndex(layerIdx);
const GbtsLayer* pL = m_geo->getGbtsLayerByIndex(layerIdx);

if (pL->m_layer.m_subdet <
20000) { // skip strips volumes: layers in range [1200X-1400X]
Expand All @@ -243,8 +220,8 @@ void GbtsDataStorage::initializeNodes(bool useML) {
}

// adjusting cuts on |cot(theta)| using pre-trained LUT loaded from file

int lutSize = m_mlLUT.size();
auto& mlLUT = m_lutParser->getParsedLut();
int lutSize = mlLUT.size();

int nBins = pL->m_bins.size();

Expand All @@ -271,7 +248,7 @@ void GbtsDataStorage::initializeNodes(bool useML) {
continue; // protect against negative index
}

const std::array<float, 5> lutBin = m_mlLUT[lutBinIdx];
const std::array<float, 5> lutBin = mlLUT[lutBinIdx];

float dist2border = 10.0 - std::abs(locPosY);

Expand Down
43 changes: 43 additions & 0 deletions Core/src/Seeding/GbtsLutParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#include "Acts/Seeding/GbtsLutParser.hpp"

#include <fstream>

namespace Acts::Experimental {

void GbtsLutParser::parseLutFile(std::string& lutInputFile, bool useML) {
if (useML) {
if (lutInputFile.empty()) {
throw std::runtime_error("Cannot find ML predictor LUT file");
} else {
m_mlLUT.reserve(100);
std::ifstream ifs(std::string(lutInputFile).c_str());

if (!ifs.is_open()) {
throw std::runtime_error("Failed to open LUT file");
}

float cl_width{}, min1{}, max1{}, min2{}, max2{};

while (ifs >> cl_width >> min1 >> max1 >> min2 >> max2) {
std::array<float, 5> lut_line = {cl_width, min1, max1, min2, max2};
m_mlLUT.emplace_back(lut_line);
}
if (!ifs.eof()) {
// ended if parse error present, not clean EOF

throw std::runtime_error("Stopped reading LUT file due to parse error");
}

ifs.close();
}
}
}
} // namespace Acts::Experimental
Loading
Loading