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 78 of file KFTrajectorySmoother.cc.

References theAlongPropagator, theEstimator, theOppositePropagator, and theUpdator.

Referenced by KFTrajectorySmoother().

78  {
79 
80  delete theAlongPropagator;
81  delete theOppositePropagator;
82  delete theUpdator;
83  delete theEstimator;
84 
85 }
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 88 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(), j, 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().

88  {
89 
90  if(aTraj.empty()) return Trajectory();
91 
92  const Propagator* usePropagator = theAlongPropagator;
93  if(aTraj.direction() == alongMomentum) {
94  usePropagator = theOppositePropagator;
95  }
96 
97  const std::vector<TM> & avtm = aTraj.measurements();
98 
99 
100 
101 
102 #ifdef EDM_ML_DEBUG
103  LogDebug("TrackFitters") << "KFTrajectorySmoother::trajectories starting with " << avtm.size() << " HITS\n";
104  for (unsigned int j=0;j<avtm.size();j++) {
105  if (avtm[j].recHit()->det())
106  LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << avtm[j].recHit()->det()->geographicalId().rawId()
107  << " validity=" << avtm[j].recHit()->isValid();
108  else
109  LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
110  }
111 #endif // EDM_ML_DEBUG
112 
113 
114 
116  bool retry=false;
117  auto start = avtm.rbegin();
118 
119  do {
120  auto hitSize = avtm.rend()-start;
121  if unlikely( hitSize < minHits_ ) {
122  LogDebug("TrackFitters") << " killing trajectory" << "\n";
123  return Trajectory();
124  }
125  Trajectory ret(aTraj.seed(), usePropagator->propagationDirection());
126  Trajectory & myTraj = ret;
127  myTraj.reserve(hitSize);
128  retry=false;
129 
130  TSOS predTsos = (*start).forwardPredictedState();
132  TSOS currTsos;
133 
134  auto hitCounter = hitSize;
135  for(std::vector<TM>::const_reverse_iterator itm = start; itm != (avtm.rend()); ++itm,--hitCounter) {
136 
138 
139  //check surface just for safety: should never be ==0 because they are skipped in the fitter
140  // if unlikely(hit->det() == nullptr) continue;
141  if unlikely( hit->surface()==nullptr ) {
142  LogDebug("TrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
143  continue;
144  }
145 
146 
147  if (itm != start)//no propagation needed for first smoothed (==last fitted) hit
148  predTsos = usePropagator->propagate( currTsos, *(hit->surface()) );
149 
150  if unlikely(!predTsos.isValid()) {
151  LogDebug("TrackFitters") << "KFTrajectorySmoother: predicted tsos not valid!";
152  LogDebug("TrackFitters") << " retry with last hit removed" << "\n";
153  LogDebug("TrackFitters")
154  // std::cout
155  << "tsos not valid " << currTsos.globalMomentum().perp() << ' '
156  << hitSize << ' ' << hitCounter << ' ' << int(hit->geographicalId()) << ' '
157  << hit->surface()->position().perp() << ' ' << hit->surface()->eta() << ' ' << hit->surface()->phi() << std::endl;
158  start++;
159  retry = true;
160  break;
161  }
162 
163  if(hit->isValid()) {
164 
165  TSOS combTsos,smooTsos;
166 
167  //3 different possibilities to calculate smoothed state:
168  //1: update combined predictions with hit
169  //2: combine fwd-prediction with bwd-filter
170  //3: combine bwd-prediction with fwd-filter
171 
172  //combTsos is the predicted state with N-1 hits information. this means:
173  //forward predicted state for first smoothed (last fitted) hit
174  //backward predicted state for last smoothed (first fitted) hit
175  //combination of forward and backward predictions for other hits
176  if (itm == start) combTsos = itm->forwardPredictedState();
177  else if (hitCounter == 1) combTsos = predTsos;
178  else combTsos = combiner(predTsos, itm->forwardPredictedState());
179 
180  if unlikely(!combTsos.isValid()) {
181  LogDebug("TrackFitters") <<
182  "KFTrajectorySmoother: combined tsos not valid!\n" <<
183  "pred Tsos pos: " << predTsos.globalPosition() << "\n" <<
184  "pred Tsos mom: " << predTsos.globalMomentum() << "\n" <<
185  "TrackingRecHit: " << hit->surface()->toGlobal(hit->localPosition()) << "\n" ;
186  start++;
187  retry = true;
188  break;
189  }
190 
191  assert( (hit->geographicalId()!=0U) | (!hit->canImproveWithTrack()) );
192  assert(hit->surface()!=nullptr);
193  assert( (!(hit)->canImproveWithTrack()) | (nullptr!=theHitCloner));
194  assert( (!(hit)->canImproveWithTrack()) | (nullptr!=dynamic_cast<BaseTrackerRecHit const*>(hit.get())));
195  auto preciseHit = theHitCloner->makeShared(hit,combTsos);
196  assert(preciseHit->isValid());
197  assert( (preciseHit->geographicalId()!=0U) | (!preciseHit->canImproveWithTrack()) );
198  assert(preciseHit->surface()!=nullptr);
199 
200  dump(hit,hitCounter);
201 
202  if unlikely(!preciseHit->isValid()){
203  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
204  currTsos = predTsos;
205  myTraj.push(TM(predTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId()) ));
206  }else{
207  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
208 
209  //update backward predicted tsos with the hit
210  currTsos = updator()->update(predTsos, *preciseHit);
211  if unlikely(!currTsos.isValid()) {
212  currTsos = predTsos;
213  edm::LogWarning("KFSmoother_UpdateFailed") <<
214  "Failed updating state with hit. Rolling back to non-updated state.\n" <<
215  "State: " << predTsos <<
216  "Hit local pos: " << hit->localPosition() << "\n" <<
217  "Hit local err: " << hit->localPositionError() << "\n" <<
218  "Hit global pos: " << hit->globalPosition() << "\n" <<
219  "Hit global err: " << hit->globalPositionError().matrix() <<
220  "\n";
221  }
222 
223  //smooTsos updates the N-1 hits prediction with the hit
224  if (itm == start) smooTsos = itm->updatedState();
225  else if (hitCounter == 1) smooTsos = currTsos;
226  else smooTsos = combiner(itm->forwardPredictedState(), currTsos);
227 
228  if unlikely(!smooTsos.isValid()) {
229  LogDebug("TrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
230  start++;
231  retry = true;
232  break;
233  }
234 
235  double estimate;
236  if (itm != start) estimate = estimator()->estimate(combTsos, *preciseHit ).second;//correct?
237  else estimate = itm->estimate();
238 
239  LogTrace("TrackFitters")
240  << "predTsos !" << "\n"
241  << predTsos
242  <<" with local position " << predTsos.localPosition() << "\n\n"
243  << "currTsos !" << "\n"
244  << currTsos << "\n"
245  <<" with local position " << currTsos.localPosition() << "\n\n"
246  << "smooTsos !" << "\n"
247  << smooTsos
248  <<" with local position " << smooTsos.localPosition() << "\n\n"
249  << "smoothing estimate (with combTSOS)=" << estimate << "\n"
250  << "filtering estimate=" << itm->estimate() << "\n";
251 
252  //check for valid hits with no det (refitter with constraints)
253  if (preciseHit->det()) myTraj.push(TM(itm->forwardPredictedState(),
254  predTsos,
255  smooTsos,
256  preciseHit,
257  estimate,
258  theGeometry->idToLayer(preciseHit->geographicalId()) ),
259  estimator()->estimate(predTsos,*preciseHit).second);
260  else myTraj.push(TM(itm->forwardPredictedState(),
261  predTsos,
262  smooTsos,
263  preciseHit,
264  estimate),
265  estimator()->estimate(predTsos,*preciseHit).second);
266  //itm->estimate());
267  }
268  } else {
269  LogDebug("TrackFitters")
270  << "----------------- HIT #" << hitCounter << " (INVALID)-----------------------";
271 
272  //no update
273  currTsos = predTsos;
274  TSOS combTsos;
275  if (itm == start) combTsos = itm->forwardPredictedState();
276  else if (hitCounter == 1) combTsos = predTsos;
277  else combTsos = combiner(predTsos, itm->forwardPredictedState());
278 
279  if unlikely(!combTsos.isValid()) {
280  LogDebug("TrackFitters") <<
281  "KFTrajectorySmoother: combined tsos not valid!";
282  return Trajectory();
283  }
284  assert( (hit->det()==nullptr) || hit->geographicalId()!=0U);
285  if (hit->det())
286  myTraj.push(TM(itm->forwardPredictedState(),
287  predTsos,
288  combTsos,
289  hit,
290  0,
291  theGeometry->idToLayer(hit->geographicalId()) ));
292  else myTraj.push(TM(itm->forwardPredictedState(),
293  predTsos,
294  combTsos,
295  hit,
296  0));
297 
298  }
299  } // for loop
300 
301  if (!retry) return ret;
302  } while(true);
303 
304  return Trajectory();
305 
306 }
#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
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
int j
Definition: DBlmapReader.cc:9
TrajectoryMeasurement TM
#define LogTrace(id)
virtual TrackingRecHit::ConstRecHitPointer makeShared(SiPixelRecHit const &hit, TrajectoryStateOnSurface const &tsos) const =0
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().