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=0, TkCloner const *hc=0)
 
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 = 0
 
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

Definition at line 23 of file KFTrajectorySmoother.h.

Definition at line 24 of file KFTrajectorySmoother.h.

Definition at line 22 of file KFTrajectorySmoother.h.

Constructor & Destructor Documentation

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  }
const DetLayerGeometry dummyGeometry
virtual Propagator * clone() const =0
const DetLayerGeometry * theGeometry
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
virtual MeasurementEstimator * clone() const =0
virtual TrajectoryStateUpdator * clone() const =0
const Propagator * theAlongPropagator
const Propagator * theOppositePropagator
KFTrajectorySmoother::KFTrajectorySmoother ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
float  errorRescaling = 100.f,
int  minHits = 3,
const DetLayerGeometry detLayerGeometry = 0,
TkCloner const *  hc = 0 
)
inline

Definition at line 50 of file KFTrajectorySmoother.h.

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

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

Definition at line 13 of file KFTrajectorySmoother.cc.

References theAlongPropagator, theEstimator, theOppositePropagator, and theUpdator.

Referenced by KFTrajectorySmoother().

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

Member Function Documentation

const Propagator* KFTrajectorySmoother::alongPropagator ( ) const
inline

Definition at line 79 of file KFTrajectorySmoother.h.

References theAlongPropagator.

79 { return theAlongPropagator; }
const Propagator * theAlongPropagator
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
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
const Propagator* KFTrajectorySmoother::oppositePropagator ( ) const
inline

Definition at line 80 of file KFTrajectorySmoother.h.

References theOppositePropagator.

80 { return theOppositePropagator; }
const Propagator * theOppositePropagator
void KFTrajectorySmoother::setHitCloner ( TkCloner const *  hc)
inlineoverridevirtual

Implements TrajectorySmoother.

Definition at line 91 of file KFTrajectorySmoother.h.

References AnalysisDataFormats_SUSYBSMObjects::hc, and theHitCloner.

91 { theHitCloner = hc; }
susybsm::HSCParticleCollection hc
Definition: classes.h:25
TkCloner const * theHitCloner
Trajectory KFTrajectorySmoother::trajectory ( const Trajectory aTraj) const
overridevirtual

Implements TrajectorySmoother.

Definition at line 20 of file KFTrajectorySmoother.cc.

References alongMomentum, heavyFlavorValidationHarvestingSequence_cff::combiner, Trajectory::direction(), FrontierConditions_GlobalTag_cff::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().

Referenced by KFTrajectorySmoother().

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

const DetLayerGeometry KFTrajectorySmoother::dummyGeometry
private

Definition at line 94 of file KFTrajectorySmoother.h.

Referenced by KFTrajectorySmoother().

int KFTrajectorySmoother::minHits_
private

Definition at line 101 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

const Propagator* KFTrajectorySmoother::theAlongPropagator
private
float KFTrajectorySmoother::theErrorRescaling
private

Definition at line 100 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

const MeasurementEstimator* KFTrajectorySmoother::theEstimator
private

Definition at line 98 of file KFTrajectorySmoother.h.

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

const DetLayerGeometry* KFTrajectorySmoother::theGeometry
private

Definition at line 102 of file KFTrajectorySmoother.h.

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

TkCloner const* KFTrajectorySmoother::theHitCloner = 0
private

Definition at line 99 of file KFTrajectorySmoother.h.

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

const Propagator* KFTrajectorySmoother::theOppositePropagator
private
const TrajectoryStateUpdator* KFTrajectorySmoother::theUpdator
private

Definition at line 97 of file KFTrajectorySmoother.h.

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