Skip to content

Commit

Permalink
Merge branch 'main' into fix/mtj-test-col-names
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 27, 2024
2 parents 401be69 + 9173bb4 commit b091a88
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 101 deletions.
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
30 changes: 21 additions & 9 deletions Examples/Framework/include/ActsExamples/EventData/Measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/MeasurementHelpers.hpp"
#include "Acts/EventData/SubspaceHelpers.hpp"
#include "Acts/EventData/Types.hpp"
#include "Acts/EventData/detail/ParameterTraits.hpp"
#include "Acts/EventData/detail/PrintParameters.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Utilities/Iterator.hpp"
#include "ActsExamples/EventData/GeometryContainers.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/MeasurementConcept.hpp"

#include <array>
#include <compare>
#include <concepts>
#include <cstddef>
#include <iosfwd>
#include <iterator>
#include <type_traits>
#include <variant>
#include <vector>

#include <boost/container/static_vector.hpp>
Expand Down Expand Up @@ -138,6 +129,11 @@ class MeasurementContainer {
return getMeasurement<Size>(addMeasurement(Size, geometryId));
}

template <MeasurementConcept OtherDerived>
VariableProxy copyMeasurement(const OtherDerived& other);
template <MeasurementConcept OtherDerived, std::size_t Size>
FixedProxy<Size> copyMeasurement(const OtherDerived& other);

template <typename... Args>
VariableProxy emplaceMeasurement(std::uint8_t size,
Acts::GeometryIdentifier geometryId,
Expand Down Expand Up @@ -494,6 +490,22 @@ class VariableMeasurementProxy
}
};

template <MeasurementConcept OtherDerived>
MeasurementContainer::VariableProxy MeasurementContainer::copyMeasurement(
const OtherDerived& other) {
VariableProxy meas = makeMeasurement(other.size(), other.geometryId());
meas.copyFrom(other);
return meas;
}

template <MeasurementConcept OtherDerived, std::size_t Size>
MeasurementContainer::FixedProxy<Size> MeasurementContainer::copyMeasurement(
const OtherDerived& other) {
FixedProxy<Size> meas = makeMeasurement<Size>(other.geometryId());
meas.copyFrom(other);
return meas;
}

template <typename... Args>
MeasurementContainer::VariableProxy MeasurementContainer::emplaceMeasurement(
std::uint8_t size, Acts::GeometryIdentifier geometryId, Args&&... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include "Acts/EventData/SourceLink.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"

#include <concepts>
Expand All @@ -23,4 +22,5 @@ concept MeasurementConcept = requires(const T& m) {
{ m.parameters() };
{ m.covariance() };
};

} // namespace ActsExamples
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
Loading

0 comments on commit b091a88

Please sign in to comment.