14#include "Acts/Surfaces/PerigeeSurface.hpp"
84 auto magneticField = std::make_unique<ATLASMagneticFieldWrapper>();
88 detail::Navigator::Config
config{trackingGeometry};
89 config.resolvePassive =
false;
90 config.resolveMaterial =
true;
91 config.resolveSensitive =
true;
99 std::vector<double> absEtaEdges;
102 absEtaEdges.reserve(2ul);
103 absEtaEdges.push_back(0.0);
104 absEtaEdges.push_back(std::numeric_limits<double>::infinity());
114 auto setCut = [](
auto &cfgVal,
const auto &cuts,
size_t ind) ->
void
118 cfgVal = (ind < cuts.size()) ? cuts[ind] : cuts[cuts.size() - 1];
121 Acts::TrackSelector::EtaBinnedConfig trackSelectorCfg{std::move(absEtaEdges)};
124 assert(trackSelectorCfg.cutSets.size() == 1);
125 trackSelectorCfg.cutSets[0].absEtaMin =
m_absEtaMin;
126 trackSelectorCfg.cutSets[0].absEtaMax =
m_absEtaMax;
129 for (
auto &cfg : trackSelectorCfg.cutSets)
131 setCut(cfg.phiMin,
m_phiMin, cutIndex);
132 setCut(cfg.phiMax,
m_phiMax, cutIndex);
133 setCut(cfg.etaMin,
m_etaMin, cutIndex);
134 setCut(cfg.etaMax,
m_etaMax, cutIndex);
135 setCut(cfg.ptMin,
m_ptMin, cutIndex);
136 setCut(cfg.ptMax,
m_ptMax, cutIndex);
137 setCut(cfg.loc0Min,
m_d0Min, cutIndex);
138 setCut(cfg.loc0Max,
m_d0Max, cutIndex);
139 setCut(cfg.loc1Min,
m_z0Min, cutIndex);
140 setCut(cfg.loc1Max,
m_z0Max, cutIndex);
145 setCut(cfg.maxChi2,
m_maxChi2, cutIndex);
155 std::move(extrapolator),
158 Acts::TrackSelector{trackSelectorCfg}};
160 m_trackFinder = std::make_unique<CKF_pimpl>(std::move(ckfConfig));
168 return StatusCode::SUCCESS;
172 ATH_MSG_FATAL(
"execute() method from the base class was called! Implement proper execute() method in the derived class!");
174 return StatusCode::FAILURE;
180 return StatusCode::SUCCESS;
197 measurementSelector->connect(&options.extensions.createTrackStates);
199 return measurementSelector;
205 const Acts::PerigeeSurface* pSurface)
const {
206 Acts::PropagatorPlainOptions plainOptions{detContext.
geometry, detContext.
magField};
208 plainOptions.direction = Acts::Direction::Forward();
213 trackFinder().ckfExtensions, plainOptions, pSurface);
215 std::unique_ptr<ActsTrk::IMeasurementSelector> measurementSelector =
setMeasurementSelector(measurements, options);
217 Acts::PropagatorPlainOptions plainSecondOptions{detContext.
geometry, detContext.
magField};
219 plainSecondOptions.direction = plainOptions.direction.invert();
222 options.extensions, plainSecondOptions, pSurface);
223 secondOptions.targetSurface = pSurface;
224 secondOptions.skipPrePropagationUpdate =
true;
226 return {std::move(options), std::move(secondOptions), std::move(measurementSelector)};
232 return (!(std::abs(
eta) < trackSelectorCfg.absEtaEdges.back())) ? trackSelectorCfg.cutSets.back()
233 : (std::abs(
eta) < trackSelectorCfg.absEtaEdges.front()) ? trackSelectorCfg.cutSets.front()
234 : trackSelectorCfg.getCuts(
eta);
237 std::vector<typename detail::RecoTrackContainer::TrackProxy>
246 if (!secondInitialParameters.referenceSurface().insideBounds(secondInitialParameters.localPosition())) {
250 auto rootBranch = tracksContainerTemp.makeTrack();
251 rootBranch.copyFromWithoutStates(trackProxy);
255 trackFinder().
ckf.findTracks(secondInitialParameters, options, tracksContainerTemp, rootBranch);
256 if (not secondResult.ok()) {
259 return secondResult.value();
263 if (trackState.hasReferenceSurface()) {
264 if (
const auto *actsDetElem =
dynamic_cast<const IDetectorElementBase *
>(trackState.referenceSurface().surfacePlacement())) {
265 switch (actsDetElem->detectorType()) {
281 const detail::RecoTrackContainer::TrackProxy &track,
282 const detail::RecoTrackContainer::TrackStateProxy &trackState,
283 const Acts::TrackSelector::EtaBinnedConfig &trackSelectorCfg,
284 const Acts::GeometryContext &tgContext,
286 const std::size_t typeIndex,
287 EventStats::value_type &event_stat_category_i)
const {
298 measurementIndex,
true);
302 return BranchStopperResult::Continue;
305 const auto ¶meters = trackState.hasFiltered() ? trackState.filtered()
306 : trackState.predicted();
307 double eta = -std::log(std::tan(0.5 * parameters[Acts::eBoundTheta]));
312 double pT = std::sin(parameters[Acts::eBoundTheta]) /
313 parameters[Acts::eBoundQOverP];
317 << pT <<
" after " << track.nMeasurements()
319 return BranchStopperResult::StopAndDrop;
325 !(std::abs(
eta) < trackSelectorCfg.absEtaEdges.back() +
329 <<
eta <<
" after " << track.nMeasurements()
331 return BranchStopperResult::StopAndDrop;
337 bool enoughMeasurements = (track.nMeasurements() >= minMeasurementsBranchStop);
338 bool tooManyHoles = (track.nHoles() > cutSet.maxHoles);
339 bool tooManyOutliers = (track.nOutliers() > cutSet.maxOutliers);
342 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] =
344 enoughMeasurements = enoughMeasurements && enoughMeasurementsPS;
345 tooManyHoles = tooManyHoles || tooManyHolesPS;
346 tooManyOutliers = tooManyOutliers || tooManyOutliersPS;
349 if (!(tooManyHoles || tooManyOutliers)) {
350 return BranchStopperResult::Continue;
353 if (!enoughMeasurements) {
359 << (enoughMeasurements ?
"keep" :
"drop")
360 <<
" branch with nHoles=" << track.nHoles() <<
" ("
364 <<
" hgtd), nOutliers=" << track.nOutliers() <<
" ("
368 <<
"), nMeasurements=" << track.nMeasurements() <<
" ("
374 << (enoughMeasurements ?
"keep" :
"drop")
375 <<
" branch with nHoles=" << track.nHoles()
376 <<
", nOutliers=" << track.nOutliers()
377 <<
", nMeasurements=" << track.nMeasurements());
380 return enoughMeasurements ? BranchStopperResult::StopAndKeep
381 : BranchStopperResult::StopAndDrop;
387 tracksContainer.addColumn<
unsigned int>(
"nPixelHits");
388 tracksContainer.addColumn<
unsigned int>(
"nStripHits");
389 tracksContainer.addColumn<
unsigned int>(
"nHgtdHits");
390 tracksContainer.addColumn<
unsigned int>(
"nPixelHoles");
391 tracksContainer.addColumn<
unsigned int>(
"nStripHoles");
392 tracksContainer.addColumn<
unsigned int>(
"nHgtdHoles");
393 tracksContainer.addColumn<
unsigned int>(
"nPixelOutliers");
394 tracksContainer.addColumn<
unsigned int>(
"nStripOutliers");
395 tracksContainer.addColumn<
unsigned int>(
"nHgtdOutliers");
412 const detail::RecoTrackContainer::TrackProxy &track,
415 if (typeFlags.isHole()) {
417 }
else if (typeFlags.isOutlier()) {
419 }
else if (typeFlags.isMeasurement()) {
423 if (typeFlags.isHole()) {
425 }
else if (typeFlags.isOutlier()) {
427 }
else if (typeFlags.isMeasurement()) {
431 if (typeFlags.isHole()) {
433 }
else if (typeFlags.isOutlier()) {
435 }
else if (typeFlags.isMeasurement()) {
445 ATH_MSG_WARNING(
"mismatched hit count: total (" << track.nMeasurements()
457 ATH_MSG_WARNING(
"mismatched outlier count: total (" << track.nOutliers()
465 bool enoughMeasurements =
true, tooManyHoles =
false, tooManyOutliers =
false;
467 std::size_t etaBin = (std::abs(
eta) < trackSelectorCfg.absEtaEdges.front()) ? 0
468 : (std::abs(
eta) >= trackSelectorCfg.absEtaEdges.back()) ? trackSelectorCfg.absEtaEdges.size() - 1
469 : trackSelectorCfg.binIndex(
eta);
470 auto cutMin = [etaBin](std::size_t val,
const std::vector<std::size_t> &cutSet) {
471 return !cutSet.empty() && (val < (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
473 auto cutMax = [etaBin](std::size_t val,
const std::vector<std::size_t> &cutSet) {
474 return !cutSet.empty() && (val > (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
487 return {enoughMeasurements, tooManyHoles, tooManyOutliers};
495 ATH_MSG_ERROR(
"Outlier chi2 cut off provided but number of elements does not agree with"
496 " chi2 cut off for measurements which however is required: "
498 return StatusCode::FAILURE;
503 chi2CutOffOutlier.push_back( std::make_pair(
static_cast<float>(elm),
506 : std::numeric_limits<float>::max()) );
514 return StatusCode::SUCCESS ;
528 ATH_MSG_FATAL(
"Eta bins for statistics counter not in ascending order.");
538 std::lock_guard<std::mutex> lock(m_mutex);
539 std::size_t category_i = 0;
540 for (
const std::array<unsigned int, kNStat> &src_stat : event_stat)
542 std::array<std::size_t, kNStat> &dest_stat = m_stat[category_i++];
543 for (std::size_t i = 0; i < src_stat.size(); ++i)
545 assert(i < dest_stat.size());
546 dest_stat[i] += src_stat[i];
555 std::vector<std::string> stat_labels =
561 std::make_pair(
kNoTrack,
"Cannot find track"),
569 std::make_pair(
kNoSecond,
"Tracks failing second CKF"),
575 assert(stat_labels.size() ==
kNStat);
576 std::vector<std::string> categories;
579 categories.push_back(
"ALL");
581 std::vector<std::string> eta_labels;
583 for (std::size_t eta_bin_i = 0; eta_bin_i <
m_statEtaBins.size() + 2; ++eta_bin_i)
592 std::vector<std::size_t> stat =
598 std::size_t stat_stride =
602 std::size_t eta_stride =
606 std::stringstream table_out;
612 for (std::size_t stat_i = 0; stat_i <
kNStat; ++stat_i)
614 std::size_t dest_idx_offset = stat_i * stat_stride;
615 table_out <<
makeTable(stat, dest_idx_offset, eta_stride,
620 .dumpHeader(stat_i == 0)
621 .dumpFooter(stat_i + 1 ==
kNStat)
622 .separateLastRow(
true)
623 .minLabelWidth(max_label_width)
624 .labelPrefix(stat_labels.at(stat_i));
634 std::size_t dest_idx_offset = eta_bin_i * eta_stride;
635 table_out <<
makeTable(stat, dest_idx_offset, stat_stride,
638 eta_labels.at(eta_bin_i))
651 auto [ratio_labels, ratio_def] =
653 std::vector<TableUtils::SummandDefinition>{
687 for (std::size_t ratio_i = 0; ratio_i < ratio_labels.size(); ++ratio_i)
690 ratio_i * ratio_stride,
696 .dumpHeader(ratio_i == 0)
697 .dumpFooter(ratio_i + 1 == ratio_labels.size())
698 .separateLastRow(
true)
699 .minLabelWidth(max_label_width)
700 .labelPrefix(ratio_labels.at(ratio_i));
707 (
m_statEtaBins.size() + 1) * ratio_eta_stride + 0 * ratio_stride,
713 .minLabelWidth(max_label_width)
717 eta_labels.erase(eta_labels.end() - 1);
718 constexpr std::size_t ratio_i = 3;
720 ratio_i * ratio_stride,
728 .separateLastRow(
false)
729 .minLabelWidth(max_label_width)
730 .labelPrefix(ratio_labels.at(ratio_i));
739 std::vector<float>::const_iterator bin_iter = std::upper_bound(
m_statEtaBins.begin(),
743 assert(category_i < m_stat.size());
748 std::size_t out = 0u;
753 assert(category_i < stat.size());
754 out += stat[category_i][counter_i];
761 double eta = -std::log(std::tan(0.5 * track.theta()));
762 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] =
selectCounts(track,
eta);
763 return enoughMeasurementsPS && !tooManyHolesPS && !tooManyOutliersPS;
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
base class interface providing the bare minimal interface extension.
Gaudi::Property< std::vector< std::size_t > > m_maxStripHoles
Gaudi::Property< double > m_branchStopperAbsEtaMeasCut
Gaudi::Property< std::vector< float > > m_statEtaBins
Gaudi::Property< double > m_branchStopperPtMinFactor
Gaudi::Property< std::vector< std::size_t > > m_maxOutliers
Gaudi::Property< std::vector< std::size_t > > m_maxHgtdHoles
std::unique_ptr< const Acts::Logger > m_logger
logging instance
void printStatTables() const
Gaudi::Property< std::vector< double > > m_etaBins
Gaudi::Property< bool > m_doTwoWay
Gaudi::Property< bool > m_dumpAllStatEtaBins
Gaudi::Property< std::vector< size_t > > m_numMeasurementsCutOff
Gaudi::Property< std::vector< std::size_t > > m_maxSharedHits
std::unique_ptr< ActsTrk::IMeasurementSelector > setMeasurementSelector(const detail::TrackFindingMeasurements &measurements, TrackFinderOptions &options) const
Setup and attach measurement selector to KF options.
Gaudi::Property< unsigned int > m_maxPropagationStep
static xAOD::UncalibMeasType measurementType(const detail::RecoTrackContainer::TrackStateProxy &trackState)
ToolHandle< ActsTrk::TrackStatePrinterTool > m_trackStatePrinter
Gaudi::Property< double > m_edgeHoleBorderWidth
Gaudi::Property< std::vector< double > > m_etaMax
Gaudi::Property< std::vector< double > > m_ptMin
Gaudi::Property< std::vector< std::size_t > > m_minPixelHits
Gaudi::Property< std::vector< std::size_t > > m_maxStripOutliers
SG::WriteHandleKey< ActsTrk::TrackContainer > m_trackContainerKey
ToolHandle< ActsTrk::IOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_pixelCalibTool
Gaudi::Property< std::vector< double > > m_ptMax
Gaudi::Property< std::vector< double > > m_chi2CutOff
detail::RecoTrackContainer::TrackProxy TrkProxy
Gaudi::Property< std::vector< std::size_t > > m_maxPixelHoles
static constexpr BranchState s_branchState
void copyStats(const EventStats &event_stat) const
Gaudi::Property< std::vector< double > > m_phiMin
Gaudi::Property< double > m_branchStopperMeasCutReduce
Gaudi::Property< std::vector< std::uint32_t > > m_endOfWorldVolumeIds
CKF_pimpl & trackFinder()
Gaudi::Property< std::vector< std::size_t > > m_minStripHits
ActsTrk::MutableTrackContainerHandlesHelper m_tracksBackendHandlesHelper
std::size_t getStatCategory(std::size_t seed_collection, float eta) const
std::size_t seedCollectionStride() const
Gaudi::Property< double > m_branchStopperAbsEtaMaxExtra
ToolHandle< GenericMonitoringTool > m_monTool
static void addCounts(detail::RecoTrackContainer &tracksContainer)
std::vector< typename detail::RecoTrackContainer::TrackProxy > doTwoWayTrackFinding(const detail::RecoTrackStateContainerProxy &firstMeasurement, const TrkProxy &trackProxy, detail::RecoTrackContainer &tracksContainerTemp, const TrackFinderOptions &options) const
Perform two-way track finding.
Gaudi::Property< std::vector< std::size_t > > m_absEtaMaxMeasurements
TrackFindingBaseAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< double > > m_etaMin
Gaudi::Property< std::vector< double > > m_d0Min
virtual StatusCode execute(const EventContext &ctx) const override
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
ToolHandle< ActsTrk::IActsToTrkConverterTool > m_ATLASConverterTool
@ kNStoppedTracksMaxHoles
@ kNForcedSeedMeasurements
Gaudi::Property< std::vector< std::size_t > > m_maxHgtdOutliers
Gaudi::Property< std::vector< double > > m_z0Max
Gaudi::Property< double > m_absEtaMax
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
std::size_t computeStatSum(std::size_t seed_collection, EStat counter_i, const EventStats &stat) const
virtual StatusCode initialize() override
Gaudi::Property< std::vector< double > > m_z0Min
void checkCounts(const detail::RecoTrackContainer::TrackProxy &track) const
Gaudi::Property< bool > m_doBranchStopper
Gaudi::Property< std::vector< std::size_t > > m_minMeasurements
Gaudi::Property< std::vector< double > > m_maxChi2
const Acts::Logger & logger() const
Private access to the logger.
Gaudi::Property< double > m_absEtaMin
BranchStopperResult stopBranch(const detail::RecoTrackContainer::TrackProxy &track, const detail::RecoTrackContainer::TrackStateProxy &trackState, const Acts::TrackSelector::EtaBinnedConfig &trackSelectorCfg, const Acts::GeometryContext &tgContext, const detail::MeasurementIndex &measurementIndex, const std::size_t typeIndex, EventStats::value_type &event_stat_category_i) const
Branch stopper.
static void initCounts(const detail::RecoTrackContainer::TrackProxy &track)
Gaudi::Property< std::vector< std::size_t > > m_maxPixelOutliers
const Acts::TrackSelector::Config & getCuts(double eta) const
Retrieves track selector configuration for given eta value.
Gaudi::Property< bool > m_checkCounts
Gaudi::Property< std::vector< std::size_t > > m_maxHoles
std::array< bool, 3 > selectCounts(const detail::RecoTrackContainer::TrackProxy &track, double eta) const
ToolHandle< ActsTrk::IOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_hgtdCalibTool
std::unique_ptr< CKF_pimpl > m_trackFinder
TrackFindingDefaultOptions getDefaultOptions(const DetectorContextHolder &detContext, const detail::TrackFindingMeasurements &measurements, const Acts::PerigeeSurface *pSurface) const
Get CKF options for first and second pass + pointer to MeasurementSelector.
StatusCode initializeMeasurementSelector()
Acts::CombinatorialKalmanFilterOptions< detail::RecoTrackContainer > TrackFinderOptions
virtual StatusCode finalize() override
std::vector< std::array< unsigned int, kNStat > > EventStats
ToolHandle< ActsTrk::IOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_stripCalibTool
detail::xAODUncalibMeasSurfAcc m_unalibMeasSurfAcc
std::size_t nSeedCollections() const
static void updateCounts(const detail::RecoTrackContainer::TrackProxy &track, Acts::ConstTrackStateTypeMap typeFlags, xAOD::UncalibMeasType detType)
Gaudi::Property< bool > m_addCounts
Gaudi::Property< std::vector< std::size_t > > m_minHgtdHits
struct ActsTrk::TrackFindingBaseAlg::MeasurementSelectorConfig m_measurementSelectorConfig
Gaudi::Property< std::vector< double > > m_phiMax
Gaudi::Property< std::vector< std::size_t > > m_ptMinMeasurements
Gaudi::Property< std::vector< double > > m_d0Max
ToolHandle< ActsTrk::IFitterTool > m_fitterTool
Gaudi::Property< std::vector< double > > m_chi2OutlierCutOff
Acts::CombinatorialKalmanFilterBranchStopperResult BranchStopperResult
bool selectCountsFinal(const detail::RecoTrackContainer::TrackProxy &track) const
Gaudi::Property< std::vector< std::string > > m_seedLabels
const MeasurementRangeList & measurementRanges() const
Helper class to access the Acts::surface associated with an Uncalibrated xAOD measurement.
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
Acts::Result< void > gainMatrixUpdate(const Acts::GeometryContext &gctx, typename trajectory_t::TrackStateProxy trackState, const Acts::Logger &logger)
Acts::Propagator< Stepper, Navigator > Propagator
std::unique_ptr< ActsTrk::IMeasurementSelector > getMeasurementSelector(const ActsTrk::IOnBoundStateCalibratorTool *pixelOnTrackCalibratorTool, const ActsTrk::IOnBoundStateCalibratorTool *stripOnTrackCalibratorTool, const ActsTrk::IOnBoundStateCalibratorTool *hgtdOnTrackCalibratorTool, const ActsTrk::detail::MeasurementRangeList &measurementRanges, const std::vector< float > &etaBinsf, const std::vector< std::pair< float, float > > &chi2CutOffOutlier, const std::vector< size_t > &numMeasurementsCutOff, double edge_hole_border_width)
Acts::SympyStepper Stepper
Adapted from Acts Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithmFunction....
Acts::Navigator Navigator
RecoTrackStateContainer::TrackStateProxy RecoTrackStateContainerProxy
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
RecoTrackStateContainer::ConstTrackStateProxy RecoConstTrackStateContainerProxy
Acts::CombinatorialKalmanFilter< Propagator, RecoTrackContainer > CKF
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string prefixFromTrackContainerName(const std::string &tracks)
Parse TrackContainer name to get the prefix for backends The name has to contain XYZTracks,...
@ Pixel
Inner detector legacy.
std::tuple< std::vector< std::string >, std::vector< RatioDefinition > > splitRatioDefinitionsAndLabels(std::initializer_list< std::tuple< std::string, RatioDefinition > > a_ratio_list)
SummandDefinition defineSummand(T counter_idx, int multiplier)
std::size_t maxLabelWidth(const T_Collection &col)
RatioDefinition defineSimpleRatio(T numerator, T denominator)
std::vector< std::string > makeLabelVector(T_index n_entries, std::initializer_list< std::pair< T_index, T_string > > a_list)
constexpr std::size_t subCategoryStride(const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
constexpr std::size_t counterStride(const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
std::string makeEtaBinLabel(const std::vector< float > &eta_bins, std::size_t eta_bin_i, bool abs_eta=false)
std::tuple< std::string, RatioDefinition > makeRatioDefinition(std::string &&name, std::vector< SummandDefinition > &&numerator, std::vector< SummandDefinition > &&denominator)
std::vector< float > computeRatios(const std::vector< RatioDefinition > &ratio_def, const std::size_t categories, const std::size_t sub_categories, const std::vector< std::size_t > &counter)
constexpr std::size_t ratioStride(const std::size_t categories, const std::size_t sub_categories, const std::vector< RatioDefinition > &ratio_def)
std::vector< T_Output > createCounterArrayWithProjections(const std::size_t categories, const std::size_t sub_categories, const std::vector< std::array< T_Input, N > > &input_counts)
UncalibMeasType
Define the type of the uncalibrated measurement.
Acts::GeometryContext geometry
Acts::MagneticFieldContext magField
Acts::CalibrationContext calib
Acts::CombinatorialKalmanFilterExtensions< RecoTrackContainer > ckfExtensions
Acts::TrackSelector trackSelector