CMS 3D CMS Logo

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

#include <KFTrajectoryFitter.h>

Inheritance diagram for KFTrajectoryFitter:
TrajectoryFitter

Public Member Functions

virtual std::unique_ptr< TrajectoryFitterclone () const override
 
const MeasurementEstimatorestimator () const
 
Trajectory fitOne (const Trajectory &aTraj, fitType) const override
 
Trajectory fitOne (const TrajectorySeed &aSeed, const RecHitContainer &hits, fitType) const override
 
Trajectory fitOne (const TrajectorySeed &aSeed, const RecHitContainer &hits, const TSOS &firstPredTsos, fitType) const override
 
 KFTrajectoryFitter (const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, int minHits=3, const DetLayerGeometry *detLayerGeometry=0, TkCloner const *hc=0)
 
 KFTrajectoryFitter (const Propagator *aPropagator, const TrajectoryStateUpdator *aUpdator, const MeasurementEstimator *aEstimator, int minHits=3, const DetLayerGeometry *detLayerGeometry=0, TkCloner const *hc=0)
 
const Propagatorpropagator () const
 
virtual void setHitCloner (TkCloner const *hc) override
 
const TrajectoryStateUpdatorupdator () const
 
 ~KFTrajectoryFitter ()
 
- Public Member Functions inherited from TrajectoryFitter
std::vector< Trajectoryfit (const Trajectory &traj, fitType type=standard) const
 
std::vector< Trajectoryfit (const TrajectorySeed &seed, const RecHitContainer &hits, fitType type=standard) const
 
std::vector< Trajectoryfit (const TrajectorySeed &seed, const RecHitContainer &hits, const TrajectoryStateOnSurface &tsos, fitType type=standard) const
 
virtual ~TrajectoryFitter ()
 

Private Types

typedef FreeTrajectoryState FTS
 
typedef TrajectoryMeasurement TM
 
typedef TrajectoryStateOnSurface TSOS
 

Private Member Functions

 KFTrajectoryFitter (KFTrajectoryFitter const &)
 

Private Attributes

int minHits_
 
bool owner
 
const MeasurementEstimatortheEstimator
 
const DetLayerGeometrytheGeometry
 
TkCloner const * theHitCloner = 0
 
const PropagatorthePropagator
 
const TrajectoryStateUpdatortheUpdator
 

Static Private Attributes

static const DetLayerGeometry dummyGeometry
 

Additional Inherited Members

- Public Types inherited from TrajectoryFitter
enum  fitType { standard =0, looper =1 }
 
typedef Trajectory::RecHitContainer RecHitContainer
 
typedef TrajectoryFitterRecord Record
 

Detailed Description

A Kalman track fit that splits matched RecHits into individual components before fitting them. Ported from ORCA

Author
todorov, cerati

A Standard Kalman fit. Ported from ORCA

Author
todorov, cerati

Definition at line 22 of file KFTrajectoryFitter.h.

Member Typedef Documentation

Definition at line 27 of file KFTrajectoryFitter.h.

Definition at line 28 of file KFTrajectoryFitter.h.

Definition at line 26 of file KFTrajectoryFitter.h.

Constructor & Destructor Documentation

KFTrajectoryFitter::KFTrajectoryFitter ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
int  minHits = 3,
const DetLayerGeometry detLayerGeometry = 0,
TkCloner const *  hc = 0 
)
inline

Definition at line 34 of file KFTrajectoryFitter.h.

References dummyGeometry, and theGeometry.

Referenced by clone(), and setHitCloner().

39  :
40  thePropagator(aPropagator.clone()),
41  theUpdator(aUpdator.clone()),
42  theEstimator(aEstimator.clone()),
44  theGeometry(detLayerGeometry),
46  owner(true){
48  // FIXME. Why this first constructor is needed? who is using it? Can it be removed?
49  // it is uses in many many places
50  }
virtual Propagator * clone() const =0
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
static const DetLayerGeometry dummyGeometry
virtual MeasurementEstimator * clone() const =0
const DetLayerGeometry * theGeometry
const Propagator * thePropagator
susybsm::HSCParticleCollection hc
Definition: classes.h:25
virtual TrajectoryStateUpdator * clone() const =0
TkCloner const * theHitCloner
KFTrajectoryFitter::KFTrajectoryFitter ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
int  minHits = 3,
const DetLayerGeometry detLayerGeometry = 0,
TkCloner const *  hc = 0 
)
inline

Definition at line 53 of file KFTrajectoryFitter.h.

References dummyGeometry, and theGeometry.

58  :
59  thePropagator(aPropagator),
60  theUpdator(aUpdator),
61  theEstimator(aEstimator),
63  theGeometry(detLayerGeometry),
65  owner(false){
67  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
static const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
const Propagator * thePropagator
susybsm::HSCParticleCollection hc
Definition: classes.h:25
TkCloner const * theHitCloner
KFTrajectoryFitter::~KFTrajectoryFitter ( )
inline

Definition at line 69 of file KFTrajectoryFitter.h.

References fitOne(), hfClusterShapes_cfi::hits, owner, theEstimator, thePropagator, and theUpdator.

69  {
70  if (owner) {
71  delete thePropagator;
72  delete theUpdator;
73  delete theEstimator;
74  }
75  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * thePropagator
KFTrajectoryFitter::KFTrajectoryFitter ( KFTrajectoryFitter const &  )
private

Member Function Documentation

virtual std::unique_ptr<TrajectoryFitter> KFTrajectoryFitter::clone ( void  ) const
inlineoverridevirtual

Implements TrajectoryFitter.

Definition at line 89 of file KFTrajectoryFitter.h.

References KFTrajectoryFitter(), minHits_, owner, theEstimator, theGeometry, theHitCloner, thePropagator, and theUpdator.

90  {
91  return owner ?
92  std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(*thePropagator,
93  *theUpdator,
94  *theEstimator,
96  std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(thePropagator,
97  theUpdator,
99  minHits_,
101  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const DetLayerGeometry * theGeometry
KFTrajectoryFitter(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, int minHits=3, const DetLayerGeometry *detLayerGeometry=0, TkCloner const *hc=0)
const Propagator * thePropagator
TkCloner const * theHitCloner
const MeasurementEstimator* KFTrajectoryFitter::estimator ( void  ) const
inline

Definition at line 87 of file KFTrajectoryFitter.h.

References theEstimator.

Referenced by KFSplittingFitter::clone(), and fitOne().

87 {return theEstimator;}
const MeasurementEstimator * theEstimator
Trajectory KFTrajectoryFitter::fitOne ( const Trajectory aTraj,
fitType  type 
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 93 of file KFTrajectoryFitter.cc.

References Trajectory::empty(), Trajectory::firstMeasurement(), Trajectory::recHits(), Trajectory::seed(), and TrajectoryMeasurement::updatedState().

Referenced by KFSplittingFitter::fitOne(), and ~KFTrajectoryFitter().

93  {
94 
95  if(aTraj.empty()) return Trajectory();
96 
97  TM firstTM = aTraj.firstMeasurement();
98  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
99 
100  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos,type);
101 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:254
type
Definition: HCALResponse.h:21
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:285
ConstRecHitContainer recHits() const
Definition: Trajectory.h:204
TrajectoryMeasurement TM
Trajectory fitOne(const Trajectory &aTraj, fitType) const override
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:187
Trajectory KFTrajectoryFitter::fitOne ( const TrajectorySeed aSeed,
const RecHitContainer hits,
fitType   
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 103 of file KFTrajectoryFitter.cc.

References Exception.

104  {
105 
106  throw cms::Exception("TrackFitters",
107  "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
108 
109  return Trajectory();
110 }
Trajectory KFTrajectoryFitter::fitOne ( const TrajectorySeed aSeed,
const RecHitContainer hits,
const TSOS firstPredTsos,
fitType   
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 112 of file KFTrajectoryFitter.cc.

References funct::abs(), anyDirection, TrackingRecHit::canImproveWithTrack(), DetId::det(), TrajectorySeed::direction(), FrontierConditions_GlobalTag_cff::dump, estimator(), TrackingRecHit::geographicalId(), DetLayerGeometry::idToLayer(), edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), TrackingRecHit::isValid(), likely, TrajectoryStateOnSurface::localParameters(), TrajectoryStateOnSurface::localPosition(), LogDebug, LogTrace, TkCloner::makeShared(), minHits_, GloballyPositioned< T >::position(), LocalTrajectoryParameters::position(), LocalTrajectoryParameters::qbp(), Trajectory::reserve(), edm::second(), SetPropagationDirection(), TrackingRecHit::surface(), theGeometry, theHitCloner, thePropagator, DetId::Tracker, mitigatedMETSequence_cff::U, unlikely, TrajectoryStateUpdator::update(), updator(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

115 {
116  if(hits.empty()) return Trajectory();
117 
118 
119  if unlikely(aSeed.direction() == anyDirection)
120  throw cms::Exception("KFTrajectoryFitter","TrajectorySeed::direction() requested but not set");
121 
122  std::unique_ptr<Propagator> p_cloned = SetPropagationDirection(*thePropagator,
123  aSeed.direction());
124 
125 #ifdef EDM_ML_DEBUG
126  LogDebug("TrackFitters")
127  <<" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
128  <<" KFTrajectoryFitter::fit starting with " << hits.size() <<" HITS";
129 
130  for (unsigned int j=0;j<hits.size();j++) {
131  if (hits[j]->det())
132  LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << hits[j]->det()->geographicalId().rawId()
133  << " validity=" << hits[j]->isValid();
134  else
135  LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
136  }
137  LogTrace("TrackFitters") << " INITIAL STATE "<< firstPredTsos;
138 #endif
139 
140  Trajectory ret(aSeed, p_cloned->propagationDirection());
141  Trajectory & myTraj = ret;
142  myTraj.reserve(hits.size());
143 
144  TSOS predTsos(firstPredTsos);
145  TSOS currTsos;
146 
147  int hitcounter = 0;
148  for(auto ihit : hits) {
149  ++hitcounter;
150 
151  const TransientTrackingRecHit & hit = (*ihit);
152 
153  // if unlikely(hit.det() == nullptr) continue;
154 
155  if unlikely( (!hit.isValid()) && hit.surface() == nullptr) {
156  LogDebug("TrackFitters")<< " Error: invalid hit with no GeomDet attached .... skipping";
157  continue;
158  }
159  // if (hit.det() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId() ;
160  // if (hit.isValid() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId();
161 
162  if ( hitcounter != 1) //no propagation needed for the first hit
163  predTsos = p_cloned->propagate( currTsos, *(hit.surface()) );
164 
165 
166  if unlikely(!predTsos.isValid()) {
167  LogDebug("TrackFitters")
168  << "SOMETHING WRONG !" << "\n"
169  << "KFTrajectoryFitter: predicted tsos not valid!\n"
170  << "current TSOS: " << currTsos << "\n";
171 
172  if(hit.surface()) LogTrace("TrackFitters") << "next Surface: " << hit.surface()->position() << "\n";
173 
174  if( myTraj.foundHits() >= minHits_ ) {
175  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
176  break;
177  } else {
178  LogDebug("TrackFitters") << " killing trajectory" << "\n";
179  return Trajectory();
180  }
181  }
182 
183 
184  if likely(hit.isValid()) {
185  assert( (hit.geographicalId()!=0U) | !hit.canImproveWithTrack() ) ;
186  assert(hit.surface()!=nullptr);
187  //update
188  LogTrace("TrackFitters") << "THE HIT IS VALID: updating hit with predTsos";
189  assert( (!hit.canImproveWithTrack()) | (nullptr!=theHitCloner));
190  assert( (!hit.canImproveWithTrack()) | (nullptr!=dynamic_cast<BaseTrackerRecHit const*>((ihit).get())));
191  auto preciseHit = theHitCloner->makeShared(ihit,predTsos);
192  dump(*preciseHit,hitcounter);
193  assert(preciseHit->isValid());
194  assert( (preciseHit->geographicalId()!=0U) | (!preciseHit->canImproveWithTrack()) );
195  assert(preciseHit->surface()!=nullptr);
196 
197  if unlikely(!preciseHit->isValid()){
198  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
199  currTsos = predTsos;
200  myTraj.push(TM(predTsos, ihit,0,theGeometry->idToLayer((ihit)->geographicalId()) ));
201 
202  }else{
203  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
204  currTsos = updator()->update(predTsos, *preciseHit);
205  //check for valid hits with no det (refitter with constraints)
206  bool badState = (!currTsos.isValid())
207  || (hit.geographicalId().det() == DetId::Tracker
208  &&
209  (std::abs(currTsos.localParameters().qbp())>100
210  || std::abs(currTsos.localParameters().position().y()) > 1000
211  || std::abs(currTsos.localParameters().position().x()) > 1000
212  ) ) || edm::isNotFinite(currTsos.localParameters().qbp());
213  if unlikely(badState){
214  if (!currTsos.isValid()) {
215  edm::LogError("FailedUpdate") <<"updating with the hit failed. Not updating the trajectory with the hit";
216 
217  }
218  else if (edm::isNotFinite(currTsos.localParameters().qbp())) {
219  edm::LogError("TrajectoryNaN")<<"Trajectory has NaN";
220 
221  }
222  else{
223  LogTrace("FailedUpdate")<<"updated state is valid but pretty bad, skipping. currTsos " <<currTsos<<"\n predTsos "<<predTsos;
224  }
225  myTraj.push(TM(predTsos, ihit,0,theGeometry->idToLayer((ihit)->geographicalId()) ));
226  //There is a no-fail policy here. So, it's time to give up
227  //Keep the traj with invalid TSOS so that it's clear what happened
228  if( myTraj.foundHits() >= minHits_ ) {
229  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
230  break;
231  } else {
232  LogDebug("TrackFitters") << " killing trajectory" << "\n";
233  return Trajectory();
234  }
235  } else{
236  if (preciseHit->det()){
237  myTraj.push(TM(predTsos, currTsos, preciseHit,
238  estimator()->estimate(predTsos, *preciseHit).second,
239  theGeometry->idToLayer(preciseHit->geographicalId()) ));
240  }
241  else{
242  myTraj.push(TM(predTsos, currTsos, preciseHit,
243  estimator()->estimate(predTsos, *preciseHit).second));
244  }
245  }
246  }
247  } else { // invalid hit
248  dump(hit,hitcounter);
249  //no update
250  LogDebug("TrackFitters") << "THE HIT IS NOT VALID: using currTsos" << "\n";
251  currTsos = predTsos;
252  assert( ((ihit)->det()==nullptr) || (ihit)->geographicalId()!=0U);
253  if ((ihit)->det()) myTraj.push(TM(predTsos, ihit,0,theGeometry->idToLayer((ihit)->geographicalId()) ));
254  else myTraj.push(TM(predTsos, ihit,0));
255  }
256  LogTrace("TrackFitters")
257  << "predTsos !" << "\n"
258  << predTsos
259  <<" with local position " << predTsos.localPosition()
260  <<"currTsos !" << "\n"
261  << currTsos
262  <<" with local position " << currTsos.localPosition();
263  }
264 
265  LogDebug("TrackFitters") << "Found 1 trajectory with " << myTraj.foundHits() << " valid hits\n";
266 
267  return ret;
268 }
#define LogDebug(id)
PropagationDirection direction() const
virtual const Surface * surface() const
const LocalTrajectoryParameters & localParameters() const
const TrajectoryStateUpdator * updator() const
LocalPoint position() const
Local x and y position coordinates.
const MeasurementEstimator * estimator() const
T y() const
Definition: PV3DBase.h:63
TrajectoryMeasurement TM
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:23
void reserve(unsigned int n)
Definition: Trajectory.h:150
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
#define unlikely(x)
U second(std::pair< T, U > const &p)
#define likely(x)
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
bool isNotFinite(T x)
Definition: isFinite.h:10
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
const DetLayerGeometry * theGeometry
virtual bool canImproveWithTrack() const
bool isValid() const
const Propagator * thePropagator
DetId geographicalId() const
virtual const DetLayer * idToLayer(const DetId &detId) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
T x() const
Definition: PV3DBase.h:62
const PositionType & position() const
TkCloner const * theHitCloner
const Propagator* KFTrajectoryFitter::propagator ( ) const
inline

Definition at line 85 of file KFTrajectoryFitter.h.

References thePropagator.

Referenced by KFSplittingFitter::clone().

85 {return thePropagator;}
const Propagator * thePropagator
virtual void KFTrajectoryFitter::setHitCloner ( TkCloner const *  hc)
inlineoverridevirtual

Implements TrajectoryFitter.

Definition at line 104 of file KFTrajectoryFitter.h.

References AnalysisDataFormats_SUSYBSMObjects::hc, KFTrajectoryFitter(), and theHitCloner.

Referenced by KFSplittingFitter::setHitCloner().

104 { theHitCloner = hc;}
susybsm::HSCParticleCollection hc
Definition: classes.h:25
TkCloner const * theHitCloner
const TrajectoryStateUpdator* KFTrajectoryFitter::updator ( ) const
inline

Definition at line 86 of file KFTrajectoryFitter.h.

References theUpdator.

Referenced by KFSplittingFitter::clone(), and fitOne().

86 {return theUpdator;}
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

const DetLayerGeometry KFTrajectoryFitter::dummyGeometry
staticprivate

Definition at line 111 of file KFTrajectoryFitter.h.

Referenced by KFTrajectoryFitter().

int KFTrajectoryFitter::minHits_
private

Definition at line 117 of file KFTrajectoryFitter.h.

Referenced by clone(), and fitOne().

bool KFTrajectoryFitter::owner
private

Definition at line 118 of file KFTrajectoryFitter.h.

Referenced by clone(), and ~KFTrajectoryFitter().

const MeasurementEstimator* KFTrajectoryFitter::theEstimator
private

Definition at line 114 of file KFTrajectoryFitter.h.

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

const DetLayerGeometry* KFTrajectoryFitter::theGeometry
private

Definition at line 116 of file KFTrajectoryFitter.h.

Referenced by clone(), fitOne(), and KFTrajectoryFitter().

TkCloner const* KFTrajectoryFitter::theHitCloner = 0
private

Definition at line 115 of file KFTrajectoryFitter.h.

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

const Propagator* KFTrajectoryFitter::thePropagator
private

Definition at line 112 of file KFTrajectoryFitter.h.

Referenced by clone(), fitOne(), propagator(), and ~KFTrajectoryFitter().

const TrajectoryStateUpdator* KFTrajectoryFitter::theUpdator
private

Definition at line 113 of file KFTrajectoryFitter.h.

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