Skip to content

Commit 8f3064a

Browse files
committed
Tentative porting to v.36
1 parent 2a42768 commit 8f3064a

7 files changed

Lines changed: 201 additions & 246 deletions

ACTSTracking/Measurement.hxx

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#pragma once
2+
3+
#include "Acts/Definitions/TrackParametrization.hpp"
4+
#include "Acts/EventData/SourceLink.hpp"
5+
#include "Acts/EventData/detail/CalculateResiduals.hpp"
6+
#include "Acts/EventData/detail/ParameterTraits.hpp"
7+
#include "Acts/EventData/detail/PrintParameters.hpp"
8+
#include "Acts/Utilities/detail/Subspace.hpp"
9+
10+
#include <array>
11+
#include <cstddef>
12+
#include <iosfwd>
13+
#include <variant>
14+
15+
namespace ACTSTracking {
16+
17+
template<typename indices_t, std::size_t kSize>
18+
class TMeasurement {
19+
static constexpr std::size_t kFullSize = Acts::detail::kParametersSize<indices_t>;
20+
21+
using Subspace = Acts::detail::FixedSizeSubspace<kFullSize, kSize>;
22+
23+
public:
24+
using Scalar = Acts::ActsScalar;
25+
using ParametersVector = Acts::ActsVector<kSize>;
26+
using CovarianceMatrix = Acts::ActsSquareMatrix<kSize>;
27+
using FullParametersVector = Acts::ActsVector<kFullSize>;
28+
using ProjectionMatrix = Acts::ActsMatrix<kSize, kFullSize>;
29+
using ExpansionMatrix = Acts::ActsMatrix<kFullSize, kSize>;
30+
31+
template<typename parameters_t, typename covariance_t>
32+
TMeasurement(Acts::SourceLink&& source, const std::array<indices_t, kSize> &indices,
33+
const Eigen::MatrixBase<parameters_t> &params,
34+
const Eigen::MatrixBase<covariance_t> &cov) :
35+
m_source(std::move(source)),
36+
m_subspace(indices),
37+
m_params(params),
38+
m_cov(cov) {}
39+
40+
TMeasurement() = delete;
41+
TMeasurement(const TMeasurement&) = default;
42+
TMeasurement(TMeasurement&&) = default;
43+
~TMeasurement() = default;
44+
TMeasurement& operator=(const TMeasurement&) = default;
45+
TMeasurement& operator=(TMeasurement&&) = default;
46+
47+
const Acts::SourceLink& sourceLink() const {
48+
return m_source;
49+
}
50+
51+
static constexpr std::size_t size() {
52+
return kSize;
53+
}
54+
55+
bool contains(indices_t i) const {
56+
return m_subspace.contains(i);
57+
}
58+
59+
constexpr std::array<indices_t, kSize> indices() const {
60+
std::array < uint8_t, kSize > subInds = m_subspace.indices();
61+
std::array<indices_t, kSize> inds { };
62+
for (std::size_t i = 0; i < kSize; i++) {
63+
inds[i] = static_cast<indices_t>(subInds[i]);
64+
}
65+
return inds;
66+
}
67+
68+
const ParametersVector& parameters() const {
69+
return m_params;
70+
}
71+
72+
const CovarianceMatrix& covariance() const {
73+
return m_cov;
74+
}
75+
76+
ProjectionMatrix projector() const {
77+
return m_subspace.template projector<Scalar>();
78+
}
79+
80+
ExpansionMatrix expander() const {
81+
return m_subspace.template expander<Scalar>();
82+
}
83+
84+
ParametersVector residuals(const FullParametersVector &reference) const {
85+
ParametersVector res = ParametersVector::Zero();
86+
Acts::detail::calculateResiduals(static_cast<indices_t>(kSize),
87+
m_subspace.indices(), reference, m_params, res);
88+
return res;
89+
}
90+
91+
std::ostream& operator<<(std::ostream &os) const {
92+
Acts::detail::printMeasurement(os, static_cast<indices_t>(kSize),
93+
m_subspace.indices().data(), m_params.data(), m_cov.data());
94+
return os;
95+
}
96+
97+
private:
98+
Acts::SourceLink m_source;
99+
Subspace m_subspace;
100+
ParametersVector m_params;
101+
CovarianceMatrix m_cov;
102+
};
103+
104+
template<typename parameters_t, typename covariance_t, typename indices_t,
105+
typename ... tail_indices_t>
106+
auto makeMeasurement(Acts::SourceLink source,
107+
const Eigen::MatrixBase<parameters_t> &params,
108+
const Eigen::MatrixBase<covariance_t> &cov, indices_t index0,
109+
tail_indices_t ... tailIndices) ->
110+
TMeasurement<indices_t, 1u + sizeof...(tail_indices_t)>
111+
{
112+
using IndexContainer = std::array<indices_t, 1u + sizeof...(tail_indices_t)>;
113+
return { std::move(source), IndexContainer {index0, tailIndices...}, params, cov };
114+
}
115+
116+
namespace detail {
117+
118+
template<typename indices_t, std::size_t kN, std::size_t ... kSizes>
119+
struct VariantMeasurementGenerator :
120+
VariantMeasurementGenerator<indices_t, kN - 1u, kN, kSizes...> {};
121+
122+
template<typename indices_t, std::size_t ... kSizes>
123+
struct VariantMeasurementGenerator<indices_t, 0u, kSizes...> {
124+
using Type = std::variant<TMeasurement<indices_t, kSizes>...>;
125+
};
126+
127+
} // namespace detail
128+
129+
template<typename indices_t>
130+
using VariantMeasurement = typename detail::VariantMeasurementGenerator<indices_t,
131+
Acts::detail::kParametersSize<indices_t>>::Type;
132+
133+
using BoundVariantMeasurement = VariantMeasurement<Acts::BoundIndices>;
134+
135+
using FreeVariantMeasurement = VariantMeasurement<Acts::FreeIndices>;
136+
137+
using Measurement = BoundVariantMeasurement;
138+
using MeasurementContainer = std::vector<Measurement>;
139+
140+
template<typename indices_t>
141+
std::ostream& operator<<(std::ostream &os, const VariantMeasurement<indices_t> &vm)
142+
{
143+
return std::visit([&](const auto &m) {
144+
return (os << m);
145+
}, vm);
146+
}
147+
148+
} // namespace Acts

ACTSTracking/MeasurementCalibrator.hxx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#pragma once
22

3-
#include <Acts/EventData/Measurement.hpp>
43
#include "Acts/EventData/SourceLink.hpp"
54
#include "Acts/EventData/VectorMultiTrajectory.hpp"
65
#include "Acts/Geometry/GeometryContext.hpp"
76
#include "Acts/Utilities/CalibrationContext.hpp"
87

98
#include "SourceLink.hxx"
9+
#include "Measurement.hxx"
1010

1111
namespace ACTSTracking {
12-
//! Hit stored as an measurement
13-
using Measurement = Acts::BoundVariantMeasurement;
14-
15-
//! Collection of measurements
16-
using MeasurementContainer = std::vector<Measurement>;
1712

1813
class MeasurementCalibrator {
1914
public:
@@ -40,16 +35,20 @@ class MeasurementCalibrator {
4035
void calibrate(const Acts::GeometryContext& gctx,
4136
const Acts::CalibrationContext& cctx,
4237
const Acts::SourceLink& sourceLink,
43-
Acts::VectorMultiTrajectory::TrackStateProxy trackState) const {
38+
Acts::VectorMultiTrajectory::TrackStateProxy trackState) const
39+
{
4440
trackState.setUncalibratedSourceLink(sourceLink);
4541
const auto& idxSourceLink = sourceLink.get<ACTSTracking::SourceLink>();
4642

4743
assert((idxSourceLink.index() < m_measurements.size()) and
4844
"Source link index is outside the container bounds");
4945

50-
const auto& meas = std::get<1>(m_measurements[idxSourceLink.index()]); //TODO workaround
51-
trackState.allocateCalibrated(meas.size());
52-
trackState.setCalibrated(meas);
46+
const auto meas = std::get<1>(m_measurements[idxSourceLink.index()]);
47+
constexpr std::size_t kMeasurementSize = decltype(meas)::size();
48+
49+
trackState.allocateCalibrated(kMeasurementSize);
50+
trackState.calibrated<kMeasurementSize>() = meas.parameters();
51+
trackState.calibratedCovariance<kMeasurementSize>() = meas.covariance();
5352
}
5453

5554
private:

src/ACTSProcBase.cxx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <Acts/Plugins/Json/JsonMaterialDecorator.hpp>
2222
#include <Acts/Plugins/TGeo/TGeoDetectorElement.hpp>
2323
#include <Acts/Plugins/TGeo/TGeoLayerBuilder.hpp>
24+
#include "Acts/Utilities/BinningType.hpp"
2425

2526
#include "Helpers.hxx"
2627

@@ -260,11 +261,10 @@ void ACTSProcBase::buildDetector() {
260261
layerBuilderConfig.autoSurfaceBinning = true;
261262

262263
// AutoBinning
263-
std::vector<std::pair<double, double>> binTolerances{(int)Acts::binValues,
264-
{0., 0.}};
265-
binTolerances[Acts::binR] = range_from_json(volume["geo-tgeo-sfbin-r-tolerance"]);
266-
binTolerances[Acts::binZ] = range_from_json(volume["geo-tgeo-sfbin-z-tolerance"]);
267-
binTolerances[Acts::binPhi] = range_from_json(volume["geo-tgeo-sfbin-phi-tolerance"]);
264+
std::vector<std::pair<double, double>> binTolerances { Acts::numBinningValues(), { 0., 0. } };
265+
binTolerances[static_cast<int>(Acts::BinningValue::binR)] = range_from_json(volume["geo-tgeo-sfbin-r-tolerance"]);
266+
binTolerances[static_cast<int>(Acts::BinningValue::binZ)] = range_from_json(volume["geo-tgeo-sfbin-z-tolerance"]);
267+
binTolerances[static_cast<int>(Acts::BinningValue::binPhi)] = range_from_json(volume["geo-tgeo-sfbin-phi-tolerance"]);
268268
layerBuilderConfig.surfaceBinMatcher =
269269
Acts::SurfaceBinningMatcher(binTolerances);
270270

@@ -286,21 +286,21 @@ void ACTSProcBase::buildDetector() {
286286
0.1 * Acts::UnitConstants::mm, 0.1 * Acts::UnitConstants::mm);
287287

288288
// Fill the parsing restrictions in r
289-
lConfig.parseRanges.push_back({Acts::binR, range_from_json(volume["geo-tgeo-layer-r-ranges"][subvolumeName])});
289+
lConfig.parseRanges.push_back({Acts::BinningValue::binR, range_from_json(volume["geo-tgeo-layer-r-ranges"][subvolumeName])});
290290

291291
// Fill the parsing restrictions in z
292-
lConfig.parseRanges.push_back({Acts::binZ, range_from_json(volume["geo-tgeo-layer-z-ranges"][subvolumeName])});
292+
lConfig.parseRanges.push_back({Acts::BinningValue::binZ, range_from_json(volume["geo-tgeo-layer-z-ranges"][subvolumeName])});
293293

294294
// Fill the layer splitting parameters in z
295295
float rsplit = volume["geo-tgeo-layer-r-split"][subvolumeName];
296296
if(rsplit > 0) {
297-
lConfig.splitConfigs.push_back({Acts::binR, rsplit});
297+
lConfig.splitConfigs.push_back({Acts::BinningValue::binR, rsplit});
298298
}
299299

300300
// Fill the layer splitting parameters in z
301301
float zsplit = volume["geo-tgeo-layer-z-split"][subvolumeName];
302302
if(zsplit > 0) {
303-
lConfig.splitConfigs.push_back({Acts::binZ, zsplit});
303+
lConfig.splitConfigs.push_back({Acts::BinningValue::binZ, zsplit});
304304
}
305305

306306
// Save
@@ -368,7 +368,7 @@ void ACTSProcBase::buildDetector() {
368368
-> void {
369369
for (const auto& lcfg : lConfigs) {
370370
for (const auto& scfg : lcfg.splitConfigs) {
371-
if (scfg.first == Acts::binR and scfg.second > 0.) {
371+
if (scfg.first == Acts::BinningValue::binR and scfg.second > 0.) {
372372
volumeConfig.ringTolerance =
373373
std::max(volumeConfig.ringTolerance, scfg.second);
374374
volumeConfig.checkRingLayout = true;

src/ACTSSeededCKFTrackingProc.cxx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ using namespace Acts::UnitLiterals;
3333
#include "SeedSpacePoint.hxx"
3434
#include "SourceLink.hxx"
3535

36-
// Track fitting definitions
36+
using TrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
37+
Acts::VectorMultiTrajectory,
38+
std::shared_ptr>;
3739
using TrackFinderOptions =
3840
Acts::CombinatorialKalmanFilterOptions<ACTSTracking::SourceLinkAccessor::Iterator,
39-
Acts::VectorMultiTrajectory>;
41+
TrackContainer>;
4042
using SSPoint = ACTSTracking::SeedSpacePoint;
4143
using SSPointGrid = Acts::CylindricalSpacePointGrid<SSPoint>;
4244

@@ -316,15 +318,12 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
316318
ACTSTracking::SourceLink sourceLink(surface->geometryId(),
317319
measurements.size(), hit.second);
318320
Acts::SourceLink src_wrap { sourceLink };
319-
Acts::Measurement meas = Acts::makeMeasurement(
321+
ACTSTracking::Measurement meas = ACTSTracking::makeMeasurement(
320322
src_wrap, loc, localCov, Acts::eBoundLoc0, Acts::eBoundLoc1);
321323

322324
measurements.push_back(meas);
323325
sourceLinks.emplace_hint(sourceLinks.end(), sourceLink);
324326

325-
//std::cout << surface->geometryId() << std::endl;
326-
//std::cout << _seedGeometrySelection.check(surface->geometryId()) << std::endl;
327-
328327
//
329328
// Seed selection and conversion to useful coordinates
330329
if (_seedGeometrySelection.check(surface->geometryId())) {
@@ -382,7 +381,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
382381
using Stepper = Acts::EigenStepper<>;
383382
using Navigator = Acts::Navigator;
384383
using Propagator = Acts::Propagator<Stepper, Navigator>;
385-
using CKF = Acts::CombinatorialKalmanFilter<Propagator, Acts::VectorMultiTrajectory>;
384+
using CKF = Acts::CombinatorialKalmanFilter<Propagator, TrackContainer>;
386385

387386
// Configurations
388387
Navigator::Config navigatorCfg{trackingGeometry()};
@@ -401,7 +400,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
401400
{Acts::GeometryIdentifier(),
402401
{ {}, { _CKF_chi2CutOff }, { (std::size_t)(_CKF_numMeasurementsCutOff) }}}};
403402

404-
Acts::PropagatorPlainOptions pOptions;
403+
Acts::PropagatorPlainOptions pOptions { geometryContext(), magneticFieldContext() };
405404
pOptions.maxSteps = 10000;
406405
if (_propagateBackward) {
407406
pOptions.direction = Acts::Direction::Backward;
@@ -416,7 +415,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
416415

417416
Acts::MeasurementSelector measSel { measurementSelectorCfg };
418417
ACTSTracking::MeasurementCalibrator measCal { measurements };
419-
Acts::CombinatorialKalmanFilterExtensions<Acts::VectorMultiTrajectory>
418+
Acts::CombinatorialKalmanFilterExtensions<TrackContainer>
420419
extensions;
421420
extensions.calibrator.connect<
422421
&ACTSTracking::MeasurementCalibrator::calibrate>(
@@ -547,9 +546,9 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
547546
finderCfg.useDetailedDoubleMeasurementInfo);
548547

549548
float up = Acts::clampValue<float>(
550-
std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2);
549+
std::floor(rRangeSPExtent.max(Acts::BinningValue::binR) / 2) * 2);
551550
const Acts::Range1D<float> rMiddleSPRange(
552-
std::floor(rRangeSPExtent.min(Acts::binR) / 2) * 2 +
551+
std::floor(rRangeSPExtent.min(Acts::BinningValue::binR) / 2) * 2 +
553552
finderCfg.deltaRMiddleMinSPRange,
554553
up - finderCfg.deltaRMiddleMaxSPRange); // TODO investigate
555554

@@ -561,7 +560,7 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
561560

562561
finder.createSeedsForGroup(
563562
finderOpts, state, spacePointsGrouping.grid(),
564-
std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange);
563+
seeds, bottom, middle, top, rMiddleSPRange);
565564

566565
//
567566
// Loop over seeds and get track parameters
@@ -662,15 +661,12 @@ void ACTSSeededCKFTrackingProc::processEvent(LCEvent *evt) {
662661
// Find the tracks
663662
if (!_runCKF) continue;
664663

665-
using TrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
666-
Acts::VectorMultiTrajectory,
667-
std::shared_ptr>;
668664
auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
669665
auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
670666
TrackContainer tracks(trackContainer, trackStateContainer);
671667

672-
Acts::PropagatorOptions<Acts::ActionList<Acts::MaterialInteractor>,
673-
Acts::AbortList<Acts::EndOfWorldReached>>
668+
Propagator::template Options<Acts::ActionList<Acts::MaterialInteractor>,
669+
Acts::AbortList<Acts::EndOfWorldReached>>
674670
extrapolationOptions(geometryContext(), magFieldContext);
675671

676672
for (std::size_t iseed = 0; iseed < paramseeds.size(); ++iseed) {

0 commit comments

Comments
 (0)