TrackFittingAlgorithm.h 4.71 KB
Newer Older
1
#ifndef JUGGLER_JUGRECO_TrackFittingAlgorithm_HH
Whitney Armstrong's avatar
Whitney Armstrong committed
2
#define JUGGLER_JUGRECO_TrackFittingAlgorithm_HH 1
3

Whitney Armstrong's avatar
Whitney Armstrong committed
4
5
6
7
8
#include <functional>
#include <stdexcept>
#include <vector>
#include <random>
#include <stdexcept>
9
10
11
12
13
14
15

#include "GaudiAlg/GaudiAlgorithm.h"
#include "GaudiKernel/ToolHandle.h"
#include "Gaudi/Property.h"

#include "JugBase/DataHandle.h"
#include "JugBase/IGeoSvc.h"
16
#include "JugBase/BField/DD4hepBField.h"
Whitney Armstrong's avatar
Whitney Armstrong committed
17
#include "JugTrack/GeometryContainers.hpp"
Whitney Armstrong's avatar
Whitney Armstrong committed
18
#include "JugTrack/IndexSourceLink.hpp"
19
20
#include "JugTrack/Track.hpp"
#include "JugTrack/Measurement.hpp"
Whitney Armstrong's avatar
Whitney Armstrong committed
21
#include "JugTrack/Trajectories.hpp"
22
#include "JugTrack/ProtoTrack.hpp"
23
24
25

#include "eicd/TrackerHitCollection.h"

Whitney Armstrong's avatar
Whitney Armstrong committed
26
27
28
#include "Acts/Definitions/Common.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
29
30
31
32
33
34
35
36
37
#include "Acts/TrackFitting/KalmanFitter.hpp"
#include "Acts/TrackFitting/GainMatrixSmoother.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Definitions/Common.hpp"


namespace Jug::Reco {

Whitney Armstrong's avatar
Whitney Armstrong committed
38
39
  /** Fitting algorithm implmentation .
   *
Whitney Armstrong's avatar
Whitney Armstrong committed
40
   * \ingroup tracking
Whitney Armstrong's avatar
Whitney Armstrong committed
41
   */
42
43
  class TrackFittingAlgorithm : public GaudiAlgorithm {
  public:
Whitney Armstrong's avatar
Whitney Armstrong committed
44
45
    /// Track fitter function that takes input measurements, initial trackstate
    /// and fitter options and returns some track-fitter-specific result.
46
    #if Acts_VERSION_MAJOR < 14
Whitney Armstrong's avatar
Whitney Armstrong committed
47
48
    using TrackFitterOptions =
        Acts::KalmanFitterOptions<MeasurementCalibrator, Acts::VoidOutlierFinder>;
49
50
51
52
53
54
55
56
    #else
    using TrackFitterOptions =
        Acts::KalmanFitterOptions<
            MeasurementCalibrator,
            Acts::VoidOutlierFinder,
            Acts::VoidReverseFilteringLogic
        >;
    #endif
Whitney Armstrong's avatar
Whitney Armstrong committed
57

58
    //using TrackFinderResult = Acts::Result<Acts::CombinatorialKalmanFilterResult<SourceLink>>;
Whitney Armstrong's avatar
Whitney Armstrong committed
59
    using FitterResult = Acts::Result<Acts::KalmanFitterResult<IndexSourceLink>>;
60

Whitney Armstrong's avatar
Whitney Armstrong committed
61
    /// Fit function that takes input measurements, initial trackstate and fitter
62
    using FitterFunction = std::function<FitterResult(
Whitney Armstrong's avatar
Whitney Armstrong committed
63
      const std::vector<IndexSourceLink>&, const TrackParameters&, const TrackFitterOptions&)>;
64
65

  public:
66
    DataHandle<IndexSourceLinkContainer> m_inputSourceLinks{"inputSourceLinks", Gaudi::DataHandle::Reader, this};
67
    DataHandle<TrackParametersContainer> m_initialTrackParameters{"initialTrackParameters", Gaudi::DataHandle::Reader, this};
Whitney Armstrong's avatar
Whitney Armstrong committed
68
    DataHandle<MeasurementContainer>     m_inputMeasurements{"inputMeasurements", Gaudi::DataHandle::Reader, this};
69
70
71
    DataHandle<ProtoTrackContainer>      m_inputProtoTracks{"inputProtoTracks", Gaudi::DataHandle::Reader, this};
    DataHandle<TrajectoriesContainer>    m_foundTracks{"foundTracks", Gaudi::DataHandle::Reader, this};
    DataHandle<TrajectoriesContainer>    m_outputTrajectories{"outputTrajectories", Gaudi::DataHandle::Writer, this};
72

Whitney Armstrong's avatar
Whitney Armstrong committed
73
    FitterFunction                        m_trackFittingFunc;
74
    SmartIF<IGeoSvc>                      m_geoSvc;
75
    std::shared_ptr<const Jug::BField::DD4hepBField> m_BField = nullptr;
76
77
78
79
80
81
82
83
84
85
86
87
    Acts::GeometryContext                 m_geoctx;
    Acts::CalibrationContext              m_calibctx;
    Acts::MagneticFieldContext            m_fieldctx;

    //Acts::CKFSourceLinkSelector::Config m_sourcelinkSelectorCfg;

    TrackFittingAlgorithm(const std::string& name, ISvcLocator* svcLoc);

    /** Create the track finder function implementation.
     *  The magnetic field is intentionally given by-value since the variant
     *  contains shared_ptr anyways.
     */
Whitney Armstrong's avatar
Whitney Armstrong committed
88
89
90
91
    static FitterFunction
    makeTrackFittingFunction(std::shared_ptr<const Acts::TrackingGeometry>      trackingGeometry,
                             std::shared_ptr<const Acts::MagneticFieldProvider> magneticField);
    // BFieldVariant                                 magneticField);
92
93
94
95

    StatusCode initialize() override;

    StatusCode execute() override;
Whitney Armstrong's avatar
Whitney Armstrong committed
96
97
98
99
100
101
102
103
   private:
    /// Helper function to call correct FitterFunction
    FitterResult fitTrack(
        const std::vector<IndexSourceLink>& sourceLinks,
        const TrackParameters& initialParameters,
        const TrackFitterOptions& options
        ) const;
        //, const std::vector<const Acts::Surface*>& surfSequence) const;
104
105
  };

106
107
108
109
  inline TrackFittingAlgorithm::FitterResult
  TrackFittingAlgorithm::fitTrack(const std::vector<IndexSourceLink>& sourceLinks,
                                  const TrackParameters&              initialParameters,
                                  const TrackFitterOptions&           options) const
Whitney Armstrong's avatar
Whitney Armstrong committed
110
111
112
113
114
115
116
117
  {
    // const std::vector<const Acts::Surface*>& surfSequence) const
    // if (m_cfg.directNavigation) {
    //  return m_cfg.dFit(sourceLinks, initialParameters, options, surfSequence);
    //}
    return m_trackFittingFunc(sourceLinks, initialParameters, options);
  }

118
119
120
} // namespace Jug::Reco

#endif