Skip to content

Commit

Permalink
Merge branch 'main' into clean-trackedm-projector
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 29, 2024
2 parents 902c6d0 + e10cd54 commit 9be9e35
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 98 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 @@ -1155,10 +1155,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
18 changes: 8 additions & 10 deletions Examples/Algorithms/TrackFinding/src/MuonHoughSeeder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ ActsExamples::ProcessCode ActsExamples::MuonHoughSeeder::execute(

// create the function parametrising the drift radius uncertainty
auto houghWidth_fromDC = [](double, const DriftCircle& DC) {
return std::min(DC.rDriftError() * 3.,
1.0); // scale reported errors up to at least 1mm or 3
// times the reported error as drift circle calib not
// fully reliable at this stage
// scale reported errors up to at least 1mm or 3 times the reported error as
// drift circle calib not fully reliable at this stage
return std::min(DC.rDriftError() * 3., 1.0);
};

// store the true parameters
Expand All @@ -100,23 +99,22 @@ ActsExamples::ProcessCode ActsExamples::MuonHoughSeeder::execute(
// instantiate the hough plane
Acts::HoughTransformUtils::HoughPlane<Acts::GeometryIdentifier::Value>
houghPlane(planeCfg);
// also insantiate the peak finder
// also instantiate the peak finder
Acts::HoughTransformUtils::PeakFinders::IslandsAroundMax<
Acts::GeometryIdentifier::Value>
peakFinder(peakFinderCfg);

// loop pver true hirs
// loop over true hits
for (auto& SH : gotSH) {
// read the identifier
MuonMdtIdentifierFields detailedInfo =
ActsExamples::splitId(SH.geometryId().value());
// store the true parameters
truePatterns.emplace_back(SH.direction().y() / SH.direction().z(),
SH.fourPosition().y());
// std::cout<<"station name=" <<
// static_cast<int>(SH.stationName)<<std::endl;
std::cout << "direction = " << SH.direction().y() << std::endl;
std::cout << "fourposition y = " << SH.fourPosition().y() << std::endl;
// ACTS_VERBOSE("station name=" << static_cast<int>(SH.stationName));
ACTS_VERBOSE("direction = " << SH.direction().y());
ACTS_VERBOSE("fourposition y = " << SH.fourPosition().y());
std::cin.ignore();
// reset the hough plane
houghPlane.reset();
Expand Down
4 changes: 2 additions & 2 deletions Examples/Io/EDM4hep/src/EDM4hepReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ ProcessCode EDM4hepReader::read(const AlgorithmContext& ctx) {

for (auto it = hitsByParticle.begin(), end = hitsByParticle.end();
it != end; it = hitsByParticle.upper_bound(it->first)) {
std::cout << "Particle " << it->first << " has "
<< hitsByParticle.count(it->first) << " hits" << std::endl;
ACTS_DEBUG("Particle " << it->first << " has "
<< hitsByParticle.count(it->first) << " hits");

std::vector<std::size_t> hitIndices;
hitIndices.reserve(hitsByParticle.count(it->first));
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
3 changes: 0 additions & 3 deletions Examples/Io/Root/src/RootMaterialTrackReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ RootMaterialTrackReader::RootMaterialTrackReader(const Config& config,
ACTS_DEBUG("The full chain has "
<< nentries << " entries for " << m_events
<< " events this corresponds to a batch size of: " << m_batchSize);
std::cout << "The full chain has " << nentries << " entries for " << m_events
<< " events this corresponds to a batch size of: " << m_batchSize
<< std::endl;

// Sort the entry numbers of the events
{
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 @@ -1424,32 +1456,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 @@ -1702,23 +1712,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
Loading

0 comments on commit 9be9e35

Please sign in to comment.