Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into ML-to-Core
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin-Allaire committed Nov 28, 2024
2 parents abcaf43 + e10cd54 commit d3c9e60
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 83 deletions.
6 changes: 3 additions & 3 deletions CI/physmon/workflows/physmon_trackfitting_gsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

tp = Path(temp)
runTruthTrackingGsf(
setup.trackingGeometry,
setup.field,
setup.digiConfig,
trackingGeometry=setup.trackingGeometry,
field=setup.field,
digiConfigFile=setup.digiConfig,
outputDir=tp,
s=s,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,10 +1166,10 @@ class MultiTrajectoryTestsCommon {
BOOST_CHECK_EQUAL(ts1.template component<T>(col), value);
};

test("std::uint32_t", std::uint32_t{1});
test("std::uint64_t", std::uint64_t{2});
test("std::int32_t", std::int32_t{-3});
test("std::int64_t", std::int64_t{-4});
test("std_uint32_t", std::uint32_t{1});
test("std_uint64_t", std::uint64_t{2});
test("std_int32_t", std::int32_t{-3});
test("std_int64_t", std::int64_t{-4});
test("float", float{8.9});
test("double", double{656.2});

Expand Down
47 changes: 31 additions & 16 deletions Core/include/Acts/TrackFinding/TrackSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class TrackSelector {
std::size_t maxSharedHits = std::numeric_limits<std::size_t>::max();
double maxChi2 = inf;

/// Whether a reference surface is required for the track
/// If false, the parameter cuts are not evaluated
bool requireReferenceSurface = true;

// Defaults to: no cut
MeasurementCounter measurementCounter;

Expand Down Expand Up @@ -447,22 +451,33 @@ bool TrackSelector::isValidTrack(const track_proxy_t& track) const {

const Config& cuts = *cutsPtr;

return track.hasReferenceSurface() &&
within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) &&
(!m_isUnbinned || (within(absEta(), cuts.absEtaMin, cuts.absEtaMax) &&
within(_eta, cuts.etaMin, cuts.etaMax))) &&
within(track.phi(), cuts.phiMin, cuts.phiMax) &&
within(track.loc0(), cuts.loc0Min, cuts.loc0Max) &&
within(track.loc1(), cuts.loc1Min, cuts.loc1Max) &&
within(track.time(), cuts.timeMin, cuts.timeMax) &&
checkMin(track.nMeasurements(), cuts.minMeasurements) &&
checkMax(track.nHoles(), cuts.maxHoles) &&
checkMax(track.nOutliers(), cuts.maxOutliers) &&
checkMax(track.nHoles() + track.nOutliers(),
cuts.maxHolesAndOutliers) &&
checkMax(track.nSharedHits(), cuts.maxSharedHits) &&
checkMax(track.chi2(), cuts.maxChi2) &&
cuts.measurementCounter.isValidTrack(track);
auto parameterCuts = [&]() {
return within(track.transverseMomentum(), cuts.ptMin, cuts.ptMax) &&
(!m_isUnbinned ||
(within(absEta(), cuts.absEtaMin, cuts.absEtaMax) &&
within(_eta, cuts.etaMin, cuts.etaMax))) &&
within(track.phi(), cuts.phiMin, cuts.phiMax) &&
within(track.loc0(), cuts.loc0Min, cuts.loc0Max) &&
within(track.loc1(), cuts.loc1Min, cuts.loc1Max) &&
within(track.time(), cuts.timeMin, cuts.timeMax);
};

auto trackCuts = [&]() {
return checkMin(track.nMeasurements(), cuts.minMeasurements) &&
checkMax(track.nHoles(), cuts.maxHoles) &&
checkMax(track.nOutliers(), cuts.maxOutliers) &&
checkMax(track.nHoles() + track.nOutliers(),
cuts.maxHolesAndOutliers) &&
checkMax(track.nSharedHits(), cuts.maxSharedHits) &&
checkMax(track.chi2(), cuts.maxChi2) &&
cuts.measurementCounter.isValidTrack(track);
};

if (cuts.requireReferenceSurface) {
return track.hasReferenceSurface() && parameterCuts() && trackCuts();
} else {
return trackCuts();
}
}

inline TrackSelector::TrackSelector(
Expand Down
1 change: 0 additions & 1 deletion Examples/Io/Json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_library(
src/JsonGeometryList.cpp
src/JsonMaterialWriter.cpp
src/JsonSurfacesWriter.cpp
src/JsonSurfacesReader.cpp
src/JsonDigitizationConfig.cpp
)
target_include_directories(
Expand Down
80 changes: 37 additions & 43 deletions Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,42 @@
"maxSharedHits",
"maxChi2",
"nMeasurementsGroupMin",
"requireReferenceSurface",
],
defaults=[(None, None)] * 7 + [None] * 7,
defaults=[(None, None)] * 7 + [None] * 8,
)


def trackSelectorDefaultKWArgs(c):
"""
Encapsulate this boilerplate code into a function so different uses do not get out of sync
"""
return acts.examples.defaultKWArgs(
loc0Min=c.loc0[0],
loc0Max=c.loc0[1],
loc1Min=c.loc1[0],
loc1Max=c.loc1[1],
timeMin=c.time[0],
timeMax=c.time[1],
phiMin=c.phi[0],
phiMax=c.phi[1],
etaMin=c.eta[0],
etaMax=c.eta[1],
absEtaMin=c.absEta[0],
absEtaMax=c.absEta[1],
ptMin=c.pt[0],
ptMax=c.pt[1],
minMeasurements=c.nMeasurementsMin,
maxHoles=c.maxHoles,
maxOutliers=c.maxOutliers,
maxHolesAndOutliers=c.maxHolesAndOutliers,
maxSharedHits=c.maxSharedHits,
maxChi2=c.maxChi2,
measurementCounter=c.nMeasurementsGroupMin,
requireReferenceSurface=c.requireReferenceSurface,
)


CkfConfig = namedtuple(
"CkfConfig",
[
Expand Down Expand Up @@ -1418,32 +1450,10 @@ def addCKFTracks(
else trackSelectorConfig
)
)

overwriteArgs = dict() if len(tslist) == 1 else dict(absEtaMax=None)
cutSets = [
acts.TrackSelector.Config(
**acts.examples.defaultKWArgs(
loc0Min=c.loc0[0],
loc0Max=c.loc0[1],
loc1Min=c.loc1[0],
loc1Max=c.loc1[1],
timeMin=c.time[0],
timeMax=c.time[1],
phiMin=c.phi[0],
phiMax=c.phi[1],
etaMin=c.eta[0],
etaMax=c.eta[1],
absEtaMin=c.absEta[0],
absEtaMax=c.absEta[1] if len(tslist) == 1 else None,
ptMin=c.pt[0],
ptMax=c.pt[1],
minMeasurements=c.nMeasurementsMin,
maxHoles=c.maxHoles,
maxOutliers=c.maxOutliers,
maxHolesAndOutliers=c.maxHolesAndOutliers,
maxSharedHits=c.maxSharedHits,
maxChi2=c.maxChi2,
measurementCounter=c.nMeasurementsGroupMin,
)
)
acts.TrackSelector.Config(**(trackSelectorDefaultKWArgs(c) | overwriteArgs))
for c in tslist
]
if len(tslist) == 0:
Expand Down Expand Up @@ -1696,23 +1706,7 @@ def addTrackSelection(

# single cut config for implicit single bin eta configuration
selectorConfig = acts.TrackSelector.Config(
**acts.examples.defaultKWArgs(
loc0Min=trackSelectorConfig.loc0[0],
loc0Max=trackSelectorConfig.loc0[1],
loc1Min=trackSelectorConfig.loc1[0],
loc1Max=trackSelectorConfig.loc1[1],
timeMin=trackSelectorConfig.time[0],
timeMax=trackSelectorConfig.time[1],
phiMin=trackSelectorConfig.phi[0],
phiMax=trackSelectorConfig.phi[1],
etaMin=trackSelectorConfig.eta[0],
etaMax=trackSelectorConfig.eta[1],
absEtaMin=trackSelectorConfig.absEta[0],
absEtaMax=trackSelectorConfig.absEta[1],
ptMin=trackSelectorConfig.pt[0],
ptMax=trackSelectorConfig.pt[1],
minMeasurements=trackSelectorConfig.nMeasurementsMin,
)
**trackSelectorDefaultKWArgs(trackSelectorConfig)
)

trackSelector = acts.examples.TrackSelectorAlgorithm(
Expand Down
6 changes: 6 additions & 0 deletions Examples/Python/src/Detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ void addDetector(Context& ctx) {

patchKwargsConstructor(c);
}

{
py::class_<Acts::DetectorElementBase,
std::shared_ptr<Acts::DetectorElementBase>>(
mex, "DetectorElementBase");
}
}

} // namespace Acts::Python
1 change: 1 addition & 0 deletions Examples/Python/src/ExampleAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void addExampleAlgorithms(Context& ctx) {
ACTS_PYTHON_MEMBER(maxSharedHits);
ACTS_PYTHON_MEMBER(maxChi2);
ACTS_PYTHON_MEMBER(measurementCounter);
ACTS_PYTHON_MEMBER(requireReferenceSurface);
ACTS_PYTHON_STRUCT_END();

pythonRangeProperty(c, "loc0", &Config::loc0Min, &Config::loc0Max);
Expand Down
28 changes: 18 additions & 10 deletions Examples/Python/src/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include "Acts/Detector/ProtoDetector.hpp"
#include "Acts/Plugins/Json/DetectorJsonConverter.hpp"
#include "Acts/Plugins/Json/JsonMaterialDecorator.hpp"
#include "Acts/Plugins/Json/JsonSurfacesReader.hpp"
#include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp"
#include "Acts/Plugins/Json/ProtoDetectorJsonConverter.hpp"
#include "Acts/Plugins/Python/Utilities.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"
#include "ActsExamples/Io/Json/JsonMaterialWriter.hpp"
#include "ActsExamples/Io/Json/JsonSurfacesReader.hpp"
#include "ActsExamples/Io/Json/JsonSurfacesWriter.hpp"
#include "ActsExamples/Io/Json/JsonTrackParamsLookupReader.hpp"
#include "ActsExamples/Io/Json/JsonTrackParamsLookupWriter.hpp"
Expand Down Expand Up @@ -204,21 +204,29 @@ void addJson(Context& ctx) {
}

{
auto sjOptions = py::class_<ActsExamples::JsonSurfacesReader::Options>(
mex, "SurfaceJsonOptions")
.def(py::init<>());
auto sjOptions =
py::class_<Acts::JsonSurfacesReader::Options>(m, "SurfaceJsonOptions")
.def(py::init<>());

ACTS_PYTHON_STRUCT_BEGIN(sjOptions,
ActsExamples::JsonSurfacesReader::Options);
ACTS_PYTHON_STRUCT_BEGIN(sjOptions, Acts::JsonSurfacesReader::Options);
ACTS_PYTHON_MEMBER(inputFile);
ACTS_PYTHON_MEMBER(jsonEntryPath);
ACTS_PYTHON_STRUCT_END();

mex.def("readSurfaceHierarchyMapFromJson",
ActsExamples::JsonSurfacesReader::readHierarchyMap);
m.def("readSurfaceHierarchyMapFromJson",
Acts::JsonSurfacesReader::readHierarchyMap);

mex.def("readSurfaceVectorFromJson",
ActsExamples::JsonSurfacesReader::readVector);
m.def("readSurfaceVectorFromJson", Acts::JsonSurfacesReader::readVector);

py::class_<Acts::JsonDetectorElement, Acts::DetectorElementBase,
std::shared_ptr<Acts::JsonDetectorElement>>(
m, "JsonDetectorElement")
.def("surface", [](Acts::JsonDetectorElement& self) {
return self.surface().getSharedPtr();
});

m.def("readDetectorElementsFromJson",
Acts::JsonSurfacesReader::readDetectorElements);
}

{
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ add_library(
src/VolumeJsonConverter.cpp
src/AmbiguityConfigJsonConverter.cpp
src/DetrayJsonHelper.cpp
src/JsonDetectorElement.cpp
src/JsonSurfacesReader.cpp
)
target_include_directories(
ActsPluginJson
Expand Down
38 changes: 38 additions & 0 deletions Plugins/Json/include/Acts/Plugins/Json/JsonDetectorElement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 "Acts/Geometry/DetectorElementBase.hpp"

#include <nlohmann/json.hpp>

namespace Acts {

/// A implementation of a detector element, that is constructed from a
/// JSON description of a surface. The idea behind this is that it helps
/// importing whole tracking geometries from JSON files. In some parts of
/// the codebase, the existence of a detector element associated to a surface
/// has a specific meaning (e.g., flags surfaces as sensitive).
class JsonDetectorElement : public DetectorElementBase {
public:
JsonDetectorElement(const nlohmann::json &jSurface, double thickness);

Surface &surface() override;
const Surface &surface() const override;

double thickness() const override;

const Transform3 &transform(const GeometryContext &gctx) const override;

private:
std::shared_ptr<Surface> m_surface;
Transform3 m_transform{};
double m_thickness{};
};

} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Geometry/GeometryHierarchyMap.hpp"
#include "Acts/Plugins/Json/JsonDetectorElement.hpp"

#include <memory>
#include <string>
Expand All @@ -18,9 +19,11 @@ namespace Acts {
class Surface;
}

namespace ActsExamples::JsonSurfacesReader {
namespace Acts::JsonSurfacesReader {

/// @brief Options specification for surface reading
/// The file should contain an array of json surfaces
/// as produced by the SurfaceJsonConverter tools
struct Options {
/// @brief Which input file to read from
std::string inputFile = "";
Expand All @@ -29,6 +32,7 @@ struct Options {
};

/// @brief Read the surfaces from the input file
/// For details on the file format see the options struct
///
/// @param options specifies which file and what to read
///
Expand All @@ -37,10 +41,22 @@ Acts::GeometryHierarchyMap<std::shared_ptr<Acts::Surface>> readHierarchyMap(
const Options& options);

/// @brief Read the flat surfaces from the input file
/// For details on the file format see the options struct
///
/// @param inputFile is the input file to read from
/// @param options options for surface reading
///
/// @return a vector of surfaces
std::vector<std::shared_ptr<Acts::Surface>> readVector(const Options& options);

} // namespace ActsExamples::JsonSurfacesReader
/// @brief Read the surfaces from the input file and create
/// detector elements
/// For details on the file format see the options struct
///
/// @param options options for surface reading
/// @param thickness the thickness used to construct the detector element
///
/// @return a vector of surfaces
std::vector<std::shared_ptr<Acts::JsonDetectorElement>> readDetectorElements(
const Options& options, double thickness);

} // namespace Acts::JsonSurfacesReader
Loading

0 comments on commit d3c9e60

Please sign in to comment.