CMS 3D CMS Logo

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

#include <KFTrajectoryFitter.h>

Inheritance diagram for KFTrajectoryFitter:
TrajectoryFitter

Public Member Functions

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=nullptr, TkCloner const *hc=nullptr)
 
 KFTrajectoryFitter (const Propagator *aPropagator, const TrajectoryStateUpdator *aUpdator, const MeasurementEstimator *aEstimator, int minHits=3, const DetLayerGeometry *detLayerGeometry=nullptr, TkCloner const *hc=nullptr)
 
 KFTrajectoryFitter (KFTrajectoryFitter const &)=delete
 
const Propagatorpropagator () const
 
void setHitCloner (TkCloner const *hc) override
 
const TrajectoryStateUpdatorupdator () const
 
 ~KFTrajectoryFitter () override
 
- 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 Attributes

int minHits_
 
bool owner
 
const MeasurementEstimatortheEstimator
 
const DetLayerGeometrytheGeometry
 
TkCloner const * theHitCloner = nullptr
 
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

◆ FTS

Definition at line 25 of file KFTrajectoryFitter.h.

◆ TM

Definition at line 26 of file KFTrajectoryFitter.h.

◆ TSOS

Definition at line 24 of file KFTrajectoryFitter.h.

Constructor & Destructor Documentation

◆ KFTrajectoryFitter() [1/3]

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

Definition at line 30 of file KFTrajectoryFitter.h.

References dummyGeometry, and theGeometry.

Referenced by clone().

36  : thePropagator(aPropagator.clone()),
37  theUpdator(aUpdator.clone()),
38  theEstimator(aEstimator.clone()),
39  theHitCloner(hc),
40  theGeometry(detLayerGeometry),
42  owner(true) {
43  if (!theGeometry)
45  // FIXME. Why this first constructor is needed? who is using it? Can it be removed?
46  // it is uses in many many places
47  }
virtual TrajectoryStateUpdator * clone() const =0
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
TkCloner const * theHitCloner

◆ KFTrajectoryFitter() [2/3]

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

Definition at line 49 of file KFTrajectoryFitter.h.

References dummyGeometry, and theGeometry.

55  : thePropagator(aPropagator),
56  theUpdator(aUpdator),
57  theEstimator(aEstimator),
58  theHitCloner(hc),
59  theGeometry(detLayerGeometry),
61  owner(false) {
62  if (!theGeometry)
64  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
static const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
const Propagator * thePropagator
TkCloner const * theHitCloner

◆ KFTrajectoryFitter() [3/3]

KFTrajectoryFitter::KFTrajectoryFitter ( KFTrajectoryFitter const &  )
delete

◆ ~KFTrajectoryFitter()

KFTrajectoryFitter::~KFTrajectoryFitter ( )
inlineoverride

Definition at line 68 of file KFTrajectoryFitter.h.

References owner, theEstimator, thePropagator, and theUpdator.

68  {
69  if (owner) {
70  delete thePropagator;
71  delete theUpdator;
72  delete theEstimator;
73  }
74  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * thePropagator

Member Function Documentation

◆ clone()

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

Implements TrajectoryFitter.

Definition at line 88 of file KFTrajectoryFitter.h.

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

88  {
89  return owner ? std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
91  : std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
93  }
KFTrajectoryFitter(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, int minHits=3, const DetLayerGeometry *detLayerGeometry=nullptr, TkCloner const *hc=nullptr)
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const DetLayerGeometry * theGeometry
const Propagator * thePropagator
TkCloner const * theHitCloner

◆ estimator()

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

Definition at line 86 of file KFTrajectoryFitter.h.

References theEstimator.

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

86 { return theEstimator; }
const MeasurementEstimator * theEstimator

◆ fitOne() [1/3]

Trajectory KFTrajectoryFitter::fitOne ( const Trajectory aTraj,
fitType  type 
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 14 of file KFTrajectoryFitter.cc.

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

Referenced by KFSplittingFitter::fitOne().

14  {
15  if (aTraj.empty())
16  return Trajectory();
17 
18  const TM& firstTM = aTraj.firstMeasurement();
19  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
20 
21  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos, type);
22 }
TrajectoryMeasurement TM
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
Trajectory fitOne(const Trajectory &aTraj, fitType) const override

◆ fitOne() [2/3]

Trajectory KFTrajectoryFitter::fitOne ( const TrajectorySeed aSeed,
const RecHitContainer hits,
fitType   
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 24 of file KFTrajectoryFitter.cc.

References Exception.

24  {
25  throw cms::Exception("TrackFitters",
26  "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
27 
28  return Trajectory();
29 }

◆ fitOne() [3/3]

Trajectory KFTrajectoryFitter::fitOne ( const TrajectorySeed aSeed,
const RecHitContainer hits,
const TSOS firstPredTsos,
fitType   
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 31 of file KFTrajectoryFitter.cc.

References funct::abs(), anyDirection, cms::cuda::assert(), TrajectorySeed::direction(), submitPVValidationJobs::dump, estimator(), hfClusterShapes_cfi::hits, DetLayerGeometry::idToLayer(), edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), dqmiolumiharvest::j, LIKELY, TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), TrajectoryStateOnSurface::localPosition(), LogDebug, LogTrace, TkCloner::makeShared(), minHits_, LocalTrajectoryError::posDef(), LocalTrajectoryParameters::position(), LocalTrajectoryParameters::qbp(), runTheMatrix::ret, edm::second(), SetPropagationDirection(), theGeometry, theHitCloner, thePropagator, DetId::Tracker, mitigatedMETSequence_cff::U, UNLIKELY, TrajectoryStateUpdator::update(), updator(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

34  {
35  if (hits.empty())
36  return Trajectory();
37 
38  if UNLIKELY (aSeed.direction() == anyDirection)
39  throw cms::Exception("KFTrajectoryFitter", "TrajectorySeed::direction() requested but not set");
40 
41  std::unique_ptr<Propagator> p_cloned = SetPropagationDirection(*thePropagator, aSeed.direction());
42 
43 #ifdef EDM_ML_DEBUG
44  LogDebug("TrackFitters")
45  << " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
46  << " KFTrajectoryFitter::fit starting with " << hits.size() << " HITS";
47 
48  for (unsigned int j = 0; j < hits.size(); j++) {
49  if (hits[j]->det())
50  LogTrace("TrackFitters") << "hit #:" << j + 1 << " rawId=" << hits[j]->det()->geographicalId().rawId()
51  << " validity=" << hits[j]->isValid();
52  else
53  LogTrace("TrackFitters") << "hit #:" << j + 1 << " Hit with no Det information";
54  }
55  LogTrace("TrackFitters") << " INITIAL STATE " << firstPredTsos;
56 #endif
57 
58  Trajectory ret(aSeed, p_cloned->propagationDirection());
59  Trajectory& myTraj = ret;
60  myTraj.reserve(hits.size());
61 
62  TSOS predTsos(firstPredTsos);
63  TSOS currTsos;
64 
65  int hitcounter = 0;
66  for (const auto& ihit : hits) {
67  ++hitcounter;
68 
69  const TransientTrackingRecHit& hit = (*ihit);
70 
71  // if UNLIKELY(hit.det() == nullptr) continue;
72 
73  if UNLIKELY ((!hit.isValid()) && hit.surface() == nullptr) {
74  LogDebug("TrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
75  continue;
76  }
77  // if (hit.det() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId() ;
78  // if (hit.isValid() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId();
79 
80  if (hitcounter != 1) //no propagation needed for the first hit
81  predTsos = p_cloned->propagate(currTsos, *(hit.surface()));
82 
83  if UNLIKELY (!predTsos.isValid()) {
84  LogDebug("TrackFitters") << "SOMETHING WRONG !"
85  << "\n"
86  << "KFTrajectoryFitter: predicted tsos not valid!\n"
87  << "current TSOS: " << currTsos << "\n";
88 
89  if (hit.surface())
90  LogTrace("TrackFitters") << "next Surface: " << hit.surface()->position() << "\n";
91 
92  if (myTraj.foundHits() >= minHits_) {
93  LogDebug("TrackFitters") << " breaking trajectory"
94  << "\n";
95  break;
96  } else {
97  LogDebug("TrackFitters") << " killing trajectory"
98  << "\n";
99  return Trajectory();
100  }
101  }
102 
103  if LIKELY (hit.isValid()) {
104  assert((hit.geographicalId() != 0U) | !hit.canImproveWithTrack());
105  assert(hit.surface() != nullptr);
106  //update
107  LogTrace("TrackFitters") << "THE HIT IS VALID: updating hit with predTsos";
108  assert((!hit.canImproveWithTrack()) | (nullptr != theHitCloner));
109  assert((!hit.canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>((ihit).get())));
110  auto preciseHit = theHitCloner->makeShared(ihit, predTsos);
111  dump(*preciseHit, hitcounter, "TrackFitters");
112  assert(preciseHit->isValid());
113  assert((preciseHit->geographicalId() != 0U) | (!preciseHit->canImproveWithTrack()));
114  assert(preciseHit->surface() != nullptr);
115 
116  if UNLIKELY (!preciseHit->isValid()) {
117  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos"
118  << "\n";
119  currTsos = predTsos;
120  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
121  } else {
122  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos"
123  << "\n";
124  currTsos = updator()->update(predTsos, *preciseHit);
125  //check for valid hits with no det (refitter with constraints)
126  bool badState = (!currTsos.isValid()) ||
127  (hit.geographicalId().det() == DetId::Tracker &&
128  (std::abs(currTsos.localParameters().qbp()) > 100 ||
129  std::abs(currTsos.localParameters().position().y()) > 1000 ||
130  std::abs(currTsos.localParameters().position().x()) > 1000)) ||
131  edm::isNotFinite(currTsos.localParameters().qbp()) || !currTsos.localError().posDef();
132  if UNLIKELY (badState) {
133  if (!currTsos.isValid()) {
134  edm::LogError("FailedUpdate") << "updating with the hit failed. Not updating the trajectory with the hit";
135 
136  } else if (edm::isNotFinite(currTsos.localParameters().qbp())) {
137  edm::LogError("TrajectoryNaN") << "Trajectory has NaN";
138 
139  } else if (!currTsos.localError().posDef()) {
140  edm::LogError("TrajectoryNotPosDef") << "Trajectory covariance is not positive-definite";
141 
142  } else {
143  LogTrace("FailedUpdate") << "updated state is valid but pretty bad, skipping. currTsos " << currTsos
144  << "\n predTsos " << predTsos;
145  }
146  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
147  //There is a no-fail policy here. So, it's time to give up
148  //Keep the traj with invalid TSOS so that it's clear what happened
149  if (myTraj.foundHits() >= minHits_) {
150  LogDebug("TrackFitters") << " breaking trajectory"
151  << "\n";
152  break;
153  } else {
154  LogDebug("TrackFitters") << " killing trajectory"
155  << "\n";
156  return Trajectory();
157  }
158  } else {
159  if (preciseHit->det()) {
160  myTraj.push(TM(predTsos,
161  currTsos,
162  preciseHit,
163  estimator()->estimate(predTsos, *preciseHit).second,
164  theGeometry->idToLayer(preciseHit->geographicalId())));
165  } else {
166  myTraj.push(TM(predTsos, currTsos, preciseHit, estimator()->estimate(predTsos, *preciseHit).second));
167  }
168  }
169  }
170  } else { // invalid hit
171  dump(hit, hitcounter, "TrackFitters");
172  //no update
173  LogDebug("TrackFitters") << "THE HIT IS NOT VALID: using currTsos"
174  << "\n";
175  currTsos = predTsos;
176  assert(((ihit)->det() == nullptr) || (ihit)->geographicalId() != 0U);
177  if ((ihit)->det())
178  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
179  else
180  myTraj.push(TM(predTsos, ihit, 0));
181  }
182  LogTrace("TrackFitters") << "predTsos !"
183  << "\n"
184  << predTsos << " with local position " << predTsos.localPosition() << "currTsos !"
185  << "\n"
186  << currTsos << " with local position " << currTsos.localPosition();
187  }
188 
189  LogDebug("TrackFitters") << "Found 1 trajectory with " << myTraj.foundHits() << " valid hits\n";
190 
191  return ret;
192 }
virtual const DetLayer * idToLayer(const DetId &detId) const
const LocalTrajectoryError & localError() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
ret
prodAgent to be discontinued
#define LIKELY(x)
Definition: Likely.h:20
const LocalTrajectoryParameters & localParameters() const
TrajectoryMeasurement TM
Log< level::Error, false > LogError
assert(be >=bs)
#define LogTrace(id)
PropagationDirection direction() const
U second(std::pair< T, U > const &p)
T x() const
Definition: PV3DBase.h:59
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
T y() const
Definition: PV3DBase.h:60
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
const MeasurementEstimator * estimator() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:24
const DetLayerGeometry * theGeometry
const Propagator * thePropagator
const TrajectoryStateUpdator * updator() const
#define UNLIKELY(x)
Definition: Likely.h:21
LocalPoint position() const
Local x and y position coordinates.
TkCloner const * theHitCloner
#define LogDebug(id)

◆ propagator()

const Propagator* KFTrajectoryFitter::propagator ( ) const
inline

Definition at line 84 of file KFTrajectoryFitter.h.

References thePropagator.

Referenced by KFSplittingFitter::clone().

84 { return thePropagator; }
const Propagator * thePropagator

◆ setHitCloner()

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

Implements TrajectoryFitter.

Definition at line 96 of file KFTrajectoryFitter.h.

References theHitCloner.

Referenced by KFSplittingFitter::setHitCloner().

96 { theHitCloner = hc; }
TkCloner const * theHitCloner

◆ updator()

const TrajectoryStateUpdator* KFTrajectoryFitter::updator ( ) const
inline

Definition at line 85 of file KFTrajectoryFitter.h.

References theUpdator.

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

85 { return theUpdator; }
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

◆ dummyGeometry

const DetLayerGeometry KFTrajectoryFitter::dummyGeometry
staticprivate

Definition at line 99 of file KFTrajectoryFitter.h.

Referenced by KFTrajectoryFitter().

◆ minHits_

int KFTrajectoryFitter::minHits_
private

Definition at line 105 of file KFTrajectoryFitter.h.

Referenced by clone(), and fitOne().

◆ owner

bool KFTrajectoryFitter::owner
private

Definition at line 106 of file KFTrajectoryFitter.h.

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

◆ theEstimator

const MeasurementEstimator* KFTrajectoryFitter::theEstimator
private

Definition at line 102 of file KFTrajectoryFitter.h.

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

◆ theGeometry

const DetLayerGeometry* KFTrajectoryFitter::theGeometry
private

Definition at line 104 of file KFTrajectoryFitter.h.

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

◆ theHitCloner

TkCloner const* KFTrajectoryFitter::theHitCloner = nullptr
private

Definition at line 103 of file KFTrajectoryFitter.h.

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

◆ thePropagator

const Propagator* KFTrajectoryFitter::thePropagator
private

Definition at line 100 of file KFTrajectoryFitter.h.

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

◆ theUpdator

const TrajectoryStateUpdator* KFTrajectoryFitter::theUpdator
private

Definition at line 101 of file KFTrajectoryFitter.h.

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