LDMX Software
CKFProcessor.h
1#pragma once
2
3//--- Framework ---//
4#include "Framework/Configure/Parameters.h"
6#include "Framework/Logger.h"
7
8//--- C++ ---//
9#include <map>
10#include <memory>
11
12//--- LDMX ---//
13#include "Tracking/EigenStepper.h" // IWYU pragma: keep
14#include "Tracking/Reco/TrackingGeometryUser.h"
15
16//--- ACTS ---//
17
18// Utils and Definitions
19
20// geometry
21
22// magfield
23
24// geometry
25
26// propagation testing
27#include "Acts/Propagator/ActorList.hpp"
28#include "Acts/Propagator/MaterialInteractor.hpp"
29#include "Acts/Propagator/Navigator.hpp"
30#include "Acts/Propagator/Propagator.hpp"
31#include "Acts/Propagator/StandardAborters.hpp"
32#include "Acts/Propagator/VoidNavigator.hpp"
33#include "Acts/Propagator/detail/SteppingLogger.hpp"
34
35// Kalman Filter
36
37// #include "Acts/EventData/Measurement.hpp"
38#include "Acts/EventData/VectorTrackContainer.hpp"
39#include "Acts/Geometry/GeometryIdentifier.hpp"
40#include "Acts/TrackFinding/CombinatorialKalmanFilter.hpp"
41#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
42
43//--- Refit with backward propagation ---//
44
45// GSF
46// #include "Acts/TrackFitting/GaussianSumFitter.hpp"
47
48//--- Tracking ---//
49#include "Tracking/Event/Measurement.h"
50#include "Tracking/Event/Track.h"
51#include "Tracking/Reco/TrackExtrapolatorTool.h"
52#include "Tracking/Sim/IndexSourceLink.h"
53
54//--- Interpolated magnetic field ---//
55#include "Tracking/Sim/BFieldXYZUtils.h"
56// mg Aug 2024 not sure if these are needed...
57using Updater = Acts::GainMatrixUpdater;
58
59using ActionList =
60 Acts::ActorList<Acts::detail::SteppingLogger, Acts::MaterialInteractor,
61 Acts::EndOfWorldReached>;
62
63using CkfPropagator = Acts::Propagator<Acts::EigenStepper<>, Acts::Navigator>;
64using ExtrapPropagator =
65 Acts::Propagator<Acts::EigenStepper<>, Acts::VoidNavigator>;
66using TrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
67 Acts::VectorMultiTrajectory>;
68
69namespace tracking {
70namespace reco {
71
72class CKFProcessor final : public TrackingGeometryUser {
73 public:
80 CKFProcessor(const std::string& name, framework::Process& process);
81
83 virtual ~CKFProcessor() = default;
84
88 void onProcessStart() override;
89
96 void onNewRun(const ldmx::RunHeader& rh) override;
97
101 void onProcessEnd() override;
102
108 void configure(framework::config::Parameters& parameters) override;
109
115 void produce(framework::Event& event) override;
116
117 private:
118 // Make geoid -> source link map Measurements
119 auto makeGeoIdSourceLinkMap(const geo::TrackersTrackingGeometry& tg,
120 const std::vector<ldmx::Measurement>& ldmxsps)
121 -> std::unordered_multimap<Acts::GeometryIdentifier,
123
124 template <typename geometry_t, typename source_link_hash_t,
125 typename source_link_equality_t>
126 std::vector<std::vector<std::size_t>> computeSharedHits(
127 std::vector<ldmx::Track> tracks, std::vector<ldmx::Measurement> meas_coll,
128 geometry_t& tg, source_link_hash_t&& sourceLinkHash,
129 source_link_equality_t&& sourceLinkEquality) const;
130
131 // If we want to dump the tracking geometry
132 bool dumpobj_{false};
133
134 int pionstates_{10};
135
136 int nevents_{0};
137
138 // Processing time counter
139 double processing_time_{0.};
140
141 // time profiling
142 std::map<std::string, double> profiling_map_;
143
144 bool debug_acts_{false};
145
146 std::shared_ptr<Acts::PlaneSurface> target_surface_;
147 Acts::RotationMatrix3 surf_rotation_;
148 // Constant BField
149 double bfield_{0};
150 // Use constant bfield
151 bool const_b_field_{true};
152
153 // Remove stereo measurements
154 bool remove_stereo_{false};
155
156 // Use 2d measurements instead of 1D
157 bool use1_dmeasurements_{true};
158
159 // Minimum number of hits on tracks
160 int min_hits_{7};
161
162 // Stepping size (in mm)
163 double propagator_step_size_{200.};
164 int propagator_max_steps_{1000};
165
166 // The extrapolation surface
167 bool use_extrapolate_location_{true};
168 std::vector<double> extrapolate_location_{0., 0., 0.};
169 bool use_seed_perigee_{false};
170
171 // The measurement collection to use for track reconstruction
172 std::string measurement_collection_{"TaggerMeasurements"};
173
174 std::string sim_particles_coll_name_;
175 std::string sim_particles_event_passname_;
176
177 // Outlier removal pvalue
178 // The Chi2Cut is applied at filtering stage.
179 // 1DOF pvalues: 0.1 = 2.706 0.05 = 3.841 0.025 = 5.024 0.01 = 6.635 0.005
180 // = 7.879 The probability to reject a good measurement is pvalue The
181 // probability to reject an outlier is given in NIM A262 (1987) 444-450
182 double outlier_pval_;
183
184 // The output track collection
185 std::string out_trk_collection_{"Tracks"};
186
187 // The seed track collection
188 std::string seed_coll_name_{"seedTracks"};
189
190 // The interpolated bfield
191 std::string field_map_{""};
192
193 std::string input_pass_name_{""};
194
195 // The Propagator
196 std::unique_ptr<const CkfPropagator> propagator_;
197
198 // The CKF
199 std::unique_ptr<
200 const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
201 ckf_;
202
203 // Track Extrapolator Tool (uses VoidNavigator to propagate freely to any
204 // surface)
205 std::unique_ptr<const ExtrapPropagator> propagator_extrap_;
206 std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
207 trk_extrap_;
208
209 // Zero-B CKF as fallback
210 std::unique_ptr<const CkfPropagator> propagator_zero_b_;
211 std::unique_ptr<
212 const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
213 ckf_zero_b_;
214 std::unique_ptr<const ExtrapPropagator> propagator_extrap_zero_b_;
215 std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
216 trk_extrap_zero_b_;
217
218 // Const-B (1.5T) CKF as fallback for tagger
219 std::unique_ptr<const CkfPropagator> propagator_const_b_;
220 std::unique_ptr<
221 const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
222 ckf_const_b_;
223 std::unique_ptr<const ExtrapPropagator> propagator_extrap_const_b_;
224 std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
225 trk_extrap_const_b_;
226
229 int ntracks_;
230 int eventnr_;
231
232 // CKF fallback statistics
233 int n_fieldmap_ckf_failed_tagger_{0};
234 int n_fieldmap_ckf_failed_recoil_{0};
235 int n_constb_ckf_recovered_tagger_{0};
236 int n_zerob_ckf_recovered_recoil_{0};
237
238 // Extrapolation fallback statistics
239 int n_fieldmap_target_extrap_failed_tagger_{0};
240 int n_constb_target_extrap_recovered_tagger_{0};
241 int n_fieldmap_target_extrap_failed_recoil_{0};
242 int n_zerob_target_extrap_recovered_recoil_{0};
243 int n_fieldmap_ecal_extrap_failed_recoil_{0};
244 int n_zerob_ecal_extrap_recovered_recoil_{0};
245
246 // BField Systematics
247 BFieldDistortion bfield_distortion_{};
248
249 // Keep track on which system this processor is running on
250 bool tagger_tracking_{true};
251
252 // Target point constraint (recoil only), same logic as the seeder
253 bool use_target_constraint_{false};
254 // extra target point sigma [mm] and its 1/p part [mm GeV]
255 std::vector<double> target_sigma_extra_{0., 0.};
256 std::vector<double> target_sigma_extra_ms_{0., 0.};
257 // target thickness for the vertex depth term [mm]
258 double target_thickness_{0.};
259 // apply the target point only up to this many hits, -1 for all
260 int target_constraint_max_hits_{-1};
261 std::string tagger_trks_collection_{""};
262 std::string tagger_trks_event_collection_passname_{""};
263
265 struct TargetPoint {
266 Acts::Vector2 loc_;
267 Acts::Matrix<2, 2> cov_;
268 };
269
271 std::vector<TargetPoint> targetPoints(framework::Event& event);
272
273 // Target constraint statistics
274 int n_tgt_tagger_{0};
275 int n_tgt_nocov_{0};
276
277 // zero field outside the map instead of an out of bounds error
278 bool field_zero_outside_{false};
279
280 // field-map CKF failures by error message
281 std::map<std::string, int> ckf_errors_;
282
283}; // CKFProcessor
284
285} // namespace reco
286} // namespace tracking
The only reason this file exists is to silence an annoying maybe-uninitialized warning that originate...
Base classes for all user event processing components to extend.
Implements an event buffer system for storing event data.
Definition Event.h:40
Class which represents the process under execution.
Definition Process.h:34
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:68
void produce(framework::Event &event) override
Run the processor.
void configure(framework::config::Parameters &parameters) override
Configure the processor using the given user specified parameters.
void onNewRun(const ldmx::RunHeader &rh) override
onNewRun is the first function called for each processor after the conditions are fully configured an...
CKFProcessor(const std::string &name, framework::Process &process)
Constructor.
int nseeds_
n seeds and n tracks
void onProcessStart() override
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
std::vector< TargetPoint > targetPoints(framework::Event &event)
Tagger track points at the target.
void onProcessEnd() override
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
virtual ~CKFProcessor()=default
Destructor.
a helper base class providing some methods to shorten access to common conditions used within the tra...
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...
A deliberate mis-placement of the reconstruction magnetic field, used to quantify how well we need to...
2D point on the target surface with its covariance