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
 
virtual 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
 
virtual void setHitCloner (TkCloner const *hc) override
 
virtual Trajectory trajectory (const Trajectory &aTraj) const override
 
const TrajectoryStateUpdatorupdator () const
 
virtual ~KFTrajectorySmoother ()
 
- 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 25 of file KFTrajectorySmoother.h.

Definition at line 26 of file KFTrajectorySmoother.h.

Definition at line 24 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 30 of file KFTrajectorySmoother.h.

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

Referenced by clone().

34  :
35  theAlongPropagator(nullptr),
36  theOppositePropagator(nullptr),
37  theUpdator(aUpdator.clone()),
38  theEstimator(aEstimator.clone()),
41  theGeometry(nullptr){ // to be fixed. Why this first constructor is needed? who is using it? Can it be removed?
43  auto p = aPropagator.clone();
44  p->setPropagationDirection(alongMomentum);
46  p = aPropagator.clone();
47  p->setPropagationDirection(oppositeToMomentum);
49  }
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 52 of file KFTrajectorySmoother.h.

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

58  :
59  theAlongPropagator(nullptr),
60  theOppositePropagator(nullptr),
61  theUpdator(aUpdator->clone()),
62  theEstimator(aEstimator->clone()),
66  theGeometry(detLayerGeometry){
68  auto p = aPropagator->clone();
69  p->setPropagationDirection(alongMomentum);
71  p = aPropagator->clone();
72  p->setPropagationDirection(oppositeToMomentum);
74  }
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 ( )
virtual

Definition at line 14 of file KFTrajectorySmoother.cc.

References theAlongPropagator, theEstimator, theOppositePropagator, and theUpdator.

Referenced by KFTrajectorySmoother().

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

Member Function Documentation

const Propagator* KFTrajectorySmoother::alongPropagator ( ) const
inline

Definition at line 80 of file KFTrajectorySmoother.h.

References theAlongPropagator.

80 { return theAlongPropagator;}
const Propagator * theAlongPropagator
virtual KFTrajectorySmoother* KFTrajectorySmoother::clone ( void  ) const
inlineoverridevirtual

Implements TrajectorySmoother.

Definition at line 86 of file KFTrajectorySmoother.h.

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

86  {
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 84 of file KFTrajectorySmoother.h.

References theEstimator.

Referenced by trajectory().

84 {return theEstimator;}
const MeasurementEstimator * theEstimator
const Propagator* KFTrajectorySmoother::oppositePropagator ( ) const
inline

Definition at line 81 of file KFTrajectorySmoother.h.

References theOppositePropagator.

81 {return theOppositePropagator;}
const Propagator * theOppositePropagator
virtual 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 24 of file KFTrajectorySmoother.cc.

References alongMomentum, Trajectory::direction(), FrontierConditions_GlobalTag_cff::dump, Trajectory::empty(), MeasurementEstimator::estimate(), estimator(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), DetLayerGeometry::idToLayer(), createfilelist::int, TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localPosition(), LogDebug, LogTrace, TkCloner::makeShared(), Trajectory::measurements(), minHits_, nullptr, PV3DBase< T, PVType, FrameType >::perp(), Propagator::propagate(), Propagator::propagationDirection(), rpcPointValidation_cfi::recHit, TrajectoryStateOnSurface::rescaleError(), Trajectory::reserve(), Trajectory::seed(), command_line::start, theAlongPropagator, theErrorRescaling, theGeometry, theHitCloner, theOppositePropagator, mitigatedMETSequence_cff::U, unlikely, TrajectoryStateUpdator::update(), and updator().

Referenced by KFTrajectorySmoother().

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

Definition at line 83 of file KFTrajectorySmoother.h.

References theUpdator.

Referenced by trajectory().

83 {return theUpdator;}
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

const DetLayerGeometry KFTrajectorySmoother::dummyGeometry
private

Definition at line 95 of file KFTrajectorySmoother.h.

Referenced by KFTrajectorySmoother().

int KFTrajectorySmoother::minHits_
private

Definition at line 102 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

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

Definition at line 101 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectory().

const MeasurementEstimator* KFTrajectorySmoother::theEstimator
private

Definition at line 99 of file KFTrajectorySmoother.h.

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

const DetLayerGeometry* KFTrajectorySmoother::theGeometry
private

Definition at line 103 of file KFTrajectorySmoother.h.

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

TkCloner const* KFTrajectorySmoother::theHitCloner = 0
private

Definition at line 100 of file KFTrajectorySmoother.h.

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

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

Definition at line 98 of file KFTrajectorySmoother.h.

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