Skip to content

Commit

Permalink
refactor(examples): Support TGeo detector, add seeding documentation (#…
Browse files Browse the repository at this point in the history
…658)

Add TGeo support for the CKF tracking, truth tracking, and seeding examples.
Add duplication plots in the seeding example
This PR also contains the documentation for the seed finding example.
  • Loading branch information
toyamaza committed Mar 17, 2021
1 parent 5a8802d commit 08335b0
Show file tree
Hide file tree
Showing 23 changed files with 481 additions and 73 deletions.
5 changes: 4 additions & 1 deletion Examples/Algorithms/TrackFinding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(
ActsExamplesTrackFinding SHARED
src/SeedingAlgorithm.cpp
src/SpacePointMaker.cpp
src/SpacePointMakerOptions.cpp
src/TrackFindingAlgorithm.cpp
src/TrackFindingAlgorithmFunction.cpp
src/TrackFindingOptions.cpp
Expand All @@ -13,7 +14,9 @@ target_link_libraries(
ActsExamplesTrackFinding
PUBLIC
ActsCore
ActsExamplesFramework ActsExamplesMagneticField
ActsExamplesFramework
ActsExamplesIoJson
ActsExamplesMagneticField
Boost::program_options)

install(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,10 @@ class SpacePointMaker final : public BareAlgorithm {
///
/// Only volumes and layers can be set. Zero values can be used as wildcards
/// to select larger parts of the hierarchy, i.e. setting only the volume
/// selects alls measurements within that volume. Adding a single identifier
/// selects all measurements within that volume. Adding a single identifier
/// with all components set to zero selects all available measurements. The
/// selection must not have duplicates.
std::vector<Acts::GeometryIdentifier> geometrySelection = {
// generic detector barrel layers
// the selection intentionally contains duplicates to demonstrate the
// automatic selection normalization. setting only the volume already
// selects all layers within it. the explicit layers in the selection
// should have no effect.
Acts::GeometryIdentifier().setVolume(8),
Acts::GeometryIdentifier().setVolume(8).setLayer(2),
Acts::GeometryIdentifier().setVolume(8).setLayer(4),
Acts::GeometryIdentifier().setVolume(8).setLayer(6),
// generic detector positive endcap layers
Acts::GeometryIdentifier().setVolume(9).setLayer(2),
Acts::GeometryIdentifier().setVolume(9).setLayer(4),
Acts::GeometryIdentifier().setVolume(9).setLayer(6),
Acts::GeometryIdentifier().setVolume(9).setLayer(8),
// generic detector negative endcap layers
Acts::GeometryIdentifier().setVolume(7).setLayer(14),
Acts::GeometryIdentifier().setVolume(7).setLayer(12),
Acts::GeometryIdentifier().setVolume(7).setLayer(10),
Acts::GeometryIdentifier().setVolume(7).setLayer(8),
};
std::vector<Acts::GeometryIdentifier> geometrySelection;
};

/// Construct the space point maker.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "ActsExamples/TrackFinding/SpacePointMaker.hpp"
#include "ActsExamples/Utilities/OptionsFwd.hpp"

namespace ActsExamples {
namespace Options {

/// Add SpacePointMaker options.
///
/// @param desc The options description to add options to
void addSpacePointMakerOptions(Description& desc);

/// Read SpacePointMaker options to create the algorithm config.
///
/// @param variables The variables to read from
SpacePointMaker::Config readSpacePointMakerConfig(const Variables& variables);

} // namespace Options
} // namespace ActsExamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"layer": 2,
"volume": 8
},
{
"layer": 4,
"volume": 8
},
{
"layer": 6,
"volume": 8
},
{
"layer": 8,
"volume": 8
},
{
"layer": 2,
"volume": 9
},
{
"layer": 4,
"volume": 9
},
{
"layer": 6,
"volume": 9
},
{
"layer": 8,
"volume": 9
},
{
"layer": 14,
"volume": 7
},
{
"layer": 12,
"volume": 7
},
{
"layer": 10,
"volume": 7
},
{
"layer": 8,
"volume": 7
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"layer": 2,
"volume": 13
},
{
"layer": 4,
"volume": 13
},
{
"layer": 6,
"volume": 13
},
{
"layer": 8,
"volume": 13
},
{
"layer": 2,
"volume": 14
},
{
"layer": 4,
"volume": 14
},
{
"layer": 6,
"volume": 14
},
{
"layer": 8,
"volume": 14
},
{
"layer": 16,
"volume": 12
},
{
"layer": 14,
"volume": 12
},
{
"layer": 12,
"volume": 12
},
{
"layer": 10,
"volume": 12
}
]
35 changes: 35 additions & 0 deletions Examples/Algorithms/TrackFinding/src/SpacePointMakerOptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is part 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "ActsExamples/TrackFinding/SpacePointMakerOptions.hpp"

#include "ActsExamples/Io/Json/JsonGeometryList.hpp"

#include <string>

#include <boost/program_options.hpp>

void ActsExamples::Options::addSpacePointMakerOptions(
ActsExamples::Options::Description& desc) {
using boost::program_options::value;

auto opt = desc.add_options();
opt("geo-selection-config-file", value<std::string>()->default_value(""),
"Json file for space point geometry selection");
}

ActsExamples::SpacePointMaker::Config
ActsExamples::Options::readSpacePointMakerConfig(
const ActsExamples::Options::Variables& variables) {
SpacePointMaker::Config cfg;
std::string path{variables["geo-selection-config-file"].as<std::string>()};
if (not path.empty()) {
cfg.geometrySelection = ActsExamples::readJsonGeometryList(path);
}
return cfg;
}
1 change: 1 addition & 0 deletions Examples/Io/Json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_library(
ActsExamplesIoJson SHARED
src/JsonGeometryList.cpp
src/JsonMaterialWriter.cpp
src/JsonSurfacesWriter.cpp
src/JsonOptionsWriter.cpp
Expand Down
36 changes: 36 additions & 0 deletions Examples/Io/Json/include/ActsExamples/Io/Json/JsonGeometryList.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Geometry/GeometryIdentifier.hpp"

#include <vector>

#include <nlohmann/json.hpp>

namespace ActsExamples {

void from_json(const nlohmann::json& data, Acts::GeometryIdentifier& geoId);

void to_json(nlohmann::json& data, const Acts::GeometryIdentifier& geoId);

void from_json(const nlohmann::json& data,
std::vector<Acts::GeometryIdentifier>& geoIdList);

void to_json(nlohmann::json& data,
const std::vector<Acts::GeometryIdentifier>& geoIdList);

std::vector<Acts::GeometryIdentifier> readJsonGeometryList(
const std::string& path);

void writeJsonGeometryList(
const std::vector<Acts::GeometryIdentifier>& geoIdList,
const std::string& path);

} // namespace ActsExamples
75 changes: 75 additions & 0 deletions Examples/Io/Json/src/JsonGeometryList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// This file is part 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
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "ActsExamples/Io/Json/JsonGeometryList.hpp"

#include <fstream>

void ActsExamples::from_json(const nlohmann::json& data,
Acts::GeometryIdentifier& geoId) {
Acts::GeometryIdentifier::Value null(0u);
geoId.setVolume(data.value("volume", null));
geoId.setBoundary(data.value("boundary", null));
geoId.setLayer(data.value("layer", null));
geoId.setApproach(data.value("approach", null));
geoId.setSensitive(data.value("sensitive", null));
}

void ActsExamples::to_json(nlohmann::json& data,
const Acts::GeometryIdentifier& geoId) {
if (geoId.volume())
data["volume"] = geoId.volume();
if (geoId.boundary())
data["boundary"] = geoId.boundary();
if (geoId.layer())
data["layer"] = geoId.layer();
if (geoId.approach())
data["approach"] = geoId.approach();
if (geoId.sensitive())
data["sensitive"] = geoId.sensitive();
}

void ActsExamples::from_json(const nlohmann::json& data,
std::vector<Acts::GeometryIdentifier>& geoIdList) {
for (auto& entry : data) {
Acts::GeometryIdentifier geoId;
from_json(entry, geoId);
geoIdList.push_back(geoId);
}
}

void ActsExamples::to_json(
nlohmann::json& data,
const std::vector<Acts::GeometryIdentifier>& geoIdList) {
for (auto& geoId : geoIdList) {
nlohmann::json entry;
to_json(entry, geoId);
data.push_back(entry);
}
}

std::vector<Acts::GeometryIdentifier> ActsExamples::readJsonGeometryList(
const std::string& path) {
nlohmann::json data;
std::vector<Acts::GeometryIdentifier> geoIdList;
std::ifstream infile(path, std::ifstream::in | std::ifstream::binary);
infile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
infile >> data;
from_json(data, geoIdList);
return geoIdList;
}

void ActsExamples::writeJsonGeometryList(
const std::vector<Acts::GeometryIdentifier>& geoIdList,
const std::string& path) {
nlohmann::json data;
to_json(data, geoIdList);
std::ofstream outfile(path, std::ofstream::out | std::ofstream::binary);
outfile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
outfile << data;
}

0 comments on commit 08335b0

Please sign in to comment.