CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes
KFTrajectorySmoother Class Referencefinal

#include <KFTrajectorySmoother.h>

Inheritance diagram for KFTrajectorySmoother:
TrajectorySmoother

Public Member Functions

const PropagatoralongPropagator () const
 
KFTrajectorySmootherclone () const override
 
const MeasurementEstimatorestimator () const
 
 KFTrajectorySmoother (const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, float errorRescaling=100.f, int minHits=3)
 
 KFTrajectorySmoother (const Propagator *aPropagator, const TrajectoryStateUpdator *aUpdator, const MeasurementEstimator *aEstimator, float errorRescaling=100.f, int minHits=3, const DetLayerGeometry *detLayerGeometry=nullptr, TkCloner const *hc=nullptr)
 
const PropagatoroppositePropagator () const
 
void setHitCloner (TkCloner const *hc) override
 
Trajectory trajectory (const Trajectory &aTraj) const override
 
const TrajectoryStateUpdatorupdator () const
 
 ~KFTrajectorySmoother () override
 
- Public Member Functions inherited from TrajectorySmoother
virtual TrajectoryContainer trajectories (const Trajectory &traj) const
 
virtual ~TrajectorySmoother ()
 

Private Types

typedef FreeTrajectoryState FTS
 
typedef TrajectoryMeasurement TM
 
typedef TrajectoryStateOnSurface TSOS
 

Private Attributes

const DetLayerGeometry dummyGeometry
 
int minHits_
 
const PropagatortheAlongPropagator
 
float theErrorRescaling
 
const MeasurementEstimatortheEstimator
 
const DetLayerGeometrytheGeometry
 
TkCloner const * theHitCloner = nullptr
 
const PropagatortheOppositePropagator
 
const TrajectoryStateUpdatortheUpdator
 

Additional Inherited Members

- Public Types inherited from TrajectorySmoother
typedef std::vector< TrajectoryTrajectoryContainer
 
typedef TrajectoryContainer::iterator TrajectoryIterator
 

Detailed Description

A Standard Kalman smoother. The forward fit is not redone, only the backward smoothing. Ported from ORCA

Author
todorov, cerati

Definition at line 20 of file KFTrajectorySmoother.h.

Member Typedef Documentation

◆ FTS

Definition at line 23 of file KFTrajectorySmoother.h.

◆ TM

Definition at line 24 of file KFTrajectorySmoother.h.

◆ TSOS

Definition at line 22 of file KFTrajectorySmoother.h.

Constructor & Destructor Documentation

◆ KFTrajectorySmoother() [1/2]

KFTrajectorySmoother::KFTrajectorySmoother ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
float  errorRescaling = 100.f,
int  minHits = 3 
)
inline

Definition at line 27 of file KFTrajectorySmoother.h.

References alongMomentum, Propagator::clone(), dummyGeometry, oppositeToMomentum, AlCaHLTBitMon_ParallelJobs::p, theAlongPropagator, theGeometry, and theOppositePropagator.

Referenced by clone().

32  : theAlongPropagator(nullptr),
33  theOppositePropagator(nullptr),
34  theUpdator(aUpdator.clone()),
35  theEstimator(aEstimator.clone()),
38  // to be fixed. Why this first constructor is needed? who is using it? Can it be removed?
39  theGeometry(nullptr) {
40  if (!theGeometry)
42  auto p = aPropagator.clone();
43  p->setPropagationDirection(alongMomentum);
45  p = aPropagator.clone();
46  p->setPropagationDirection(oppositeToMomentum);
48  }
virtual TrajectoryStateUpdator * clone() const =0
const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
virtual Propagator * clone() const =0
virtual MeasurementEstimator * clone() const =0
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * theAlongPropagator
const Propagator * theOppositePropagator

◆ KFTrajectorySmoother() [2/2]

KFTrajectorySmoother::KFTrajectorySmoother ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
float  errorRescaling = 100.f,
int  minHits = 3,
const DetLayerGeometry detLayerGeometry = nullptr,
TkCloner const *  hc = nullptr 
)
inline

Definition at line 50 of file KFTrajectorySmoother.h.

References alongMomentum, Propagator::clone(), dummyGeometry, oppositeToMomentum, AlCaHLTBitMon_ParallelJobs::p, theAlongPropagator, theGeometry, and theOppositePropagator.

57  : theAlongPropagator(nullptr),
58  theOppositePropagator(nullptr),
59  theUpdator(aUpdator->clone()),
60  theEstimator(aEstimator->clone()),
61  theHitCloner(hc),
64  theGeometry(detLayerGeometry) {
65  if (!theGeometry)
67  auto p = aPropagator->clone();
68  p->setPropagationDirection(alongMomentum);
70  p = aPropagator->clone();
71  p->setPropagationDirection(oppositeToMomentum);
73  }
virtual TrajectoryStateUpdator * clone() const =0
const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
virtual Propagator * clone() const =0
virtual MeasurementEstimator * clone() const =0
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * theAlongPropagator
const Propagator * theOppositePropagator
TkCloner const * theHitCloner

◆ ~KFTrajectorySmoother()

KFTrajectorySmoother::~KFTrajectorySmoother ( )
override

Definition at line 12 of file KFTrajectorySmoother.cc.

References theAlongPropagator, theEstimator, theOppositePropagator, and theUpdator.

12  {
13  delete theAlongPropagator;
14  delete theOppositePropagator;
15  delete theUpdator;
16  delete theEstimator;
17 }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * theAlongPropagator
const Propagator * theOppositePropagator

Member Function Documentation

◆ alongPropagator()

const Propagator* KFTrajectorySmoother::alongPropagator ( ) const
inline

Definition at line 79 of file KFTrajectorySmoother.h.

References theAlongPropagator.

79 { return theAlongPropagator; }
const Propagator * theAlongPropagator

◆ clone()

KFTrajectorySmoother* KFTrajectorySmoother::clone ( void  ) const
inlineoverridevirtual

Implements TrajectorySmoother.

Definition at line 85 of file KFTrajectorySmoother.h.

References KFTrajectorySmoother(), minHits_, theAlongPropagator, theErrorRescaling, theEstimator, theGeometry, theHitCloner, and theUpdator.

85  {
86  return new KFTrajectorySmoother(
88  }
const DetLayerGeometry * theGeometry
KFTrajectorySmoother(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, float errorRescaling=100.f, int minHits=3)
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * theAlongPropagator
TkCloner const * theHitCloner

◆ estimator()

const MeasurementEstimator* KFTrajectorySmoother::estimator ( void  ) const
inline

Definition at line 83 of file KFTrajectorySmoother.h.

References theEstimator.

Referenced by trajectory().

83 { return theEstimator; }
const MeasurementEstimator * theEstimator

◆ oppositePropagator()

const Propagator* KFTrajectorySmoother::oppositePropagator ( ) const
inline

Definition at line 80 of file KFTrajectorySmoother.h.

References theOppositePropagator.

80 { return theOppositePropagator; }
const Propagator * theOppositePropagator

◆ setHitCloner()

void KFTrajectorySmoother::setHitCloner ( TkCloner const *  hc)
inlineoverridevirtual

Implements TrajectorySmoother.

Definition at line 91 of file KFTrajectorySmoother.h.

References theHitCloner.

Referenced by CosmicTrajectoryBuilder::init().

91 { theHitCloner = hc; }
TkCloner const * theHitCloner

◆ trajectory()

Trajectory KFTrajectorySmoother::trajectory ( const Trajectory aTraj) const
overridevirtual

Implements TrajectorySmoother.

Definition at line 19 of file KFTrajectorySmoother.cc.

References alongMomentum, cms::cuda::assert(), heavyFlavorValidationHarvestingSequence_cff::combiner, Trajectory::direction(), GCP_Ntuples_cfg::dump, Trajectory::empty(), MeasurementEstimator::estimate(), estimator(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), DetLayerGeometry::idToLayer(), createfilelist::int, TrajectoryStateOnSurface::isValid(), dqmiolumiharvest::j, TrajectoryStateOnSurface::localPosition(), LogDebug, LogTrace, TkCloner::makeShared(), Trajectory::measurements(), minHits_, PV3DBase< T, PVType, FrameType >::perp(), Propagator::propagate(), Propagator::propagationDirection(), rpcPointValidation_cfi::recHit, TrajectoryStateOnSurface::rescaleError(), runTheMatrix::ret, Trajectory::seed(), command_line::start, theAlongPropagator, theErrorRescaling, theGeometry, theHitCloner, theOppositePropagator, mitigatedMETSequence_cff::U, UNLIKELY, TrajectoryStateUpdator::update(), and updator().

19  {
20  if (aTraj.empty())
21  return Trajectory();
22 
23  const Propagator* usePropagator = theAlongPropagator;
24  if (aTraj.direction() == alongMomentum) {
25  usePropagator = theOppositePropagator;
26  }
27 
28  const std::vector<TM>& avtm = aTraj.measurements();
29 
30 #ifdef EDM_ML_DEBUG
31  LogDebug("TrackFitters") << "KFTrajectorySmoother::trajectories starting with " << avtm.size() << " HITS\n";
32  for (unsigned int j = 0; j < avtm.size(); j++) {
33  if (avtm[j].recHit()->det())
34  LogTrace("TrackFitters") << "hit #:" << j + 1 << " rawId=" << avtm[j].recHit()->det()->geographicalId().rawId()
35  << " validity=" << avtm[j].recHit()->isValid();
36  else
37  LogTrace("TrackFitters") << "hit #:" << j + 1 << " Hit with no Det information";
38  }
39 #endif // EDM_ML_DEBUG
40 
42  bool retry = false;
43  auto start = avtm.rbegin();
44 
45  do {
46  auto hitSize = avtm.rend() - start;
47  if UNLIKELY (hitSize < minHits_) {
48  LogDebug("TrackFitters") << " killing trajectory"
49  << "\n";
50  return Trajectory();
51  }
52  Trajectory ret(aTraj.seed(), usePropagator->propagationDirection());
53  Trajectory& myTraj = ret;
54  myTraj.reserve(hitSize);
55  retry = false;
56 
57  TSOS predTsos = (*start).forwardPredictedState();
59  TSOS currTsos;
60 
61  auto hitCounter = hitSize;
62  for (std::vector<TM>::const_reverse_iterator itm = start; itm != (avtm.rend()); ++itm, --hitCounter) {
64 
65  //check surface just for safety: should never be ==0 because they are skipped in the fitter
66  // if UNLIKELY(hit->det() == nullptr) continue;
67  if UNLIKELY (hit->surface() == nullptr) {
68  LogDebug("TrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
69  continue;
70  }
71 
72  if (itm != start) //no propagation needed for first smoothed (==last fitted) hit
73  predTsos = usePropagator->propagate(currTsos, *(hit->surface()));
74 
75  if UNLIKELY (!predTsos.isValid()) {
76  LogDebug("TrackFitters") << "KFTrajectorySmoother: predicted tsos not valid!";
77  LogDebug("TrackFitters") << " retry with last hit removed"
78  << "\n";
79  LogDebug("TrackFitters")
80  // std::cout
81  << "tsos not valid " << currTsos.globalMomentum().perp() << ' ' << hitSize << ' ' << hitCounter << ' '
82  << int(hit->geographicalId()) << ' ' << hit->surface()->position().perp() << ' ' << hit->surface()->eta()
83  << ' ' << hit->surface()->phi() << std::endl;
84  start++;
85  retry = true;
86  break;
87  }
88 
89  if (hit->isValid()) {
90  TSOS combTsos, smooTsos;
91 
92  //3 different possibilities to calculate smoothed state:
93  //1: update combined predictions with hit
94  //2: combine fwd-prediction with bwd-filter
95  //3: combine bwd-prediction with fwd-filter
96 
97  //combTsos is the predicted state with N-1 hits information. this means:
98  //forward predicted state for first smoothed (last fitted) hit
99  //backward predicted state for last smoothed (first fitted) hit
100  //combination of forward and backward predictions for other hits
101  if (itm == start)
102  combTsos = itm->forwardPredictedState();
103  else if (hitCounter == 1)
104  combTsos = predTsos;
105  else
106  combTsos = combiner(predTsos, itm->forwardPredictedState());
107 
108  if UNLIKELY (!combTsos.isValid()) {
109  LogDebug("TrackFitters") << "KFTrajectorySmoother: combined tsos not valid!\n"
110  << "pred Tsos pos: " << predTsos.globalPosition() << "\n"
111  << "pred Tsos mom: " << predTsos.globalMomentum() << "\n"
112  << "TrackingRecHit: " << hit->surface()->toGlobal(hit->localPosition()) << "\n";
113  start++;
114  retry = true;
115  break;
116  }
117 
118  assert((hit->geographicalId() != 0U) | (!hit->canImproveWithTrack()));
119  assert(hit->surface() != nullptr);
120  assert((!(hit)->canImproveWithTrack()) | (nullptr != theHitCloner));
121  assert((!(hit)->canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>(hit.get())));
122  auto preciseHit = theHitCloner->makeShared(hit, combTsos);
123  assert(preciseHit->isValid());
124  assert((preciseHit->geographicalId() != 0U) | (!preciseHit->canImproveWithTrack()));
125  assert(preciseHit->surface() != nullptr);
126 
127  dump(*hit, hitCounter, "TrackFitters");
128 
129  if UNLIKELY (!preciseHit->isValid()) {
130  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos"
131  << "\n";
132  currTsos = predTsos;
133  myTraj.push(TM(predTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId())));
134  } else {
135  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos"
136  << "\n";
137 
138  //update backward predicted tsos with the hit
139  currTsos = updator()->update(predTsos, *preciseHit);
140  if UNLIKELY (!currTsos.isValid()) {
141  currTsos = predTsos;
142  edm::LogWarning("KFSmoother_UpdateFailed")
143  << "Failed updating state with hit. Rolling back to non-updated state.\n"
144  << "State: " << predTsos << "Hit local pos: " << hit->localPosition() << "\n"
145  << "Hit local err: " << hit->localPositionError() << "\n"
146  << "Hit global pos: " << hit->globalPosition() << "\n"
147  << "Hit global err: " << hit->globalPositionError().matrix() << "\n";
148  }
149 
150  //smooTsos updates the N-1 hits prediction with the hit
151  if (itm == start)
152  smooTsos = itm->updatedState();
153  else if (hitCounter == 1)
154  smooTsos = currTsos;
155  else
156  smooTsos = combiner(itm->forwardPredictedState(), currTsos);
157 
158  if UNLIKELY (!smooTsos.isValid()) {
159  LogDebug("TrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
160  start++;
161  retry = true;
162  break;
163  }
164 
165  double estimate;
166  if (itm != start)
167  estimate = estimator()->estimate(combTsos, *preciseHit).second; //correct?
168  else
169  estimate = itm->estimate();
170 
171  LogTrace("TrackFitters") << "predTsos !"
172  << "\n"
173  << predTsos << " with local position " << predTsos.localPosition() << "\n\n"
174  << "currTsos !"
175  << "\n"
176  << currTsos << "\n"
177  << " with local position " << currTsos.localPosition() << "\n\n"
178  << "smooTsos !"
179  << "\n"
180  << smooTsos << " with local position " << smooTsos.localPosition() << "\n\n"
181  << "smoothing estimate (with combTSOS)=" << estimate << "\n"
182  << "filtering estimate=" << itm->estimate() << "\n";
183 
184  //check for valid hits with no det (refitter with constraints)
185  if (preciseHit->det())
186  myTraj.push(TM(itm->forwardPredictedState(),
187  predTsos,
188  smooTsos,
189  preciseHit,
190  estimate,
191  theGeometry->idToLayer(preciseHit->geographicalId())),
192  estimator()->estimate(predTsos, *preciseHit).second);
193  else
194  myTraj.push(TM(itm->forwardPredictedState(), predTsos, smooTsos, preciseHit, estimate),
195  estimator()->estimate(predTsos, *preciseHit).second);
196  //itm->estimate());
197  }
198  } else {
199  LogDebug("TrackFitters") << "----------------- HIT #" << hitCounter << " (INVALID)-----------------------";
200 
201  //no update
202  currTsos = predTsos;
203  TSOS combTsos;
204  if (itm == start)
205  combTsos = itm->forwardPredictedState();
206  else if (hitCounter == 1)
207  combTsos = predTsos;
208  else
209  combTsos = combiner(predTsos, itm->forwardPredictedState());
210 
211  if UNLIKELY (!combTsos.isValid()) {
212  LogDebug("TrackFitters") << "KFTrajectorySmoother: combined tsos not valid!";
213  return Trajectory();
214  }
215  assert((hit->det() == nullptr) || hit->geographicalId() != 0U);
216  if (hit->det())
217  myTraj.push(TM(
218  itm->forwardPredictedState(), predTsos, combTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId())));
219  else
220  myTraj.push(TM(itm->forwardPredictedState(), predTsos, combTsos, hit, 0));
221  }
222  } // for loop
223 
224  if (!retry)
225  return ret;
226  } while (true);
227 
228  return Trajectory();
229 }
Definition: start.py:1
virtual const DetLayer * idToLayer(const DetId &detId) const
T perp() const
Definition: PV3DBase.h:69
ret
prodAgent to be discontinued
const DetLayerGeometry * theGeometry
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
assert(be >=bs)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
#define LogTrace(id)
DataContainer const & measurements() const
Definition: Trajectory.h:178
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
GlobalPoint globalPosition() const
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
TrajectoryMeasurement TM
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:24
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
const MeasurementEstimator * estimator() const
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
GlobalVector globalMomentum() const
const TrajectoryStateUpdator * updator() const
const Propagator * theAlongPropagator
const Propagator * theOppositePropagator
#define UNLIKELY(x)
Definition: Likely.h:21
Log< level::Warning, false > LogWarning
TkCloner const * theHitCloner
#define LogDebug(id)

◆ updator()

const TrajectoryStateUpdator* KFTrajectorySmoother::updator ( ) const
inline

Definition at line 82 of file KFTrajectorySmoother.h.

References theUpdator.

Referenced by trajectory().

82 { return theUpdator; }
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

◆ dummyGeometry

const DetLayerGeometry KFTrajectorySmoother::dummyGeometry
private

Definition at line 94 of file KFTrajectorySmoother.h.

Referenced by KFTrajectorySmoother().

◆ minHits_

int KFTrajectorySmoother::minHits_
private

Definition at line 101 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

◆ theAlongPropagator

const Propagator* KFTrajectorySmoother::theAlongPropagator
private

◆ theErrorRescaling

float KFTrajectorySmoother::theErrorRescaling
private

Definition at line 100 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

◆ theEstimator

const MeasurementEstimator* KFTrajectorySmoother::theEstimator
private

Definition at line 98 of file KFTrajectorySmoother.h.

Referenced by clone(), estimator(), and ~KFTrajectorySmoother().

◆ theGeometry

const DetLayerGeometry* KFTrajectorySmoother::theGeometry
private

Definition at line 102 of file KFTrajectorySmoother.h.

Referenced by clone(), KFTrajectorySmoother(), and trajectory().

◆ theHitCloner

TkCloner const* KFTrajectorySmoother::theHitCloner = nullptr
private

Definition at line 99 of file KFTrajectorySmoother.h.

Referenced by clone(), setHitCloner(), and trajectory().

◆ theOppositePropagator

const Propagator* KFTrajectorySmoother::theOppositePropagator
private

◆ theUpdator

const TrajectoryStateUpdator* KFTrajectorySmoother::theUpdator
private

Definition at line 97 of file KFTrajectorySmoother.h.

Referenced by clone(), updator(), and ~KFTrajectorySmoother().