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

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
 
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 Member Functions

 KFTrajectoryFitter (KFTrajectoryFitter const &)=delete
 

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 25 of file KFTrajectoryFitter.h.

Definition at line 26 of file KFTrajectoryFitter.h.

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

References dummyGeometry, and theGeometry.

Referenced by clone(), and setHitCloner().

36  : thePropagator(aPropagator.clone()),
37  theUpdator(aUpdator.clone()),
38  theEstimator(aEstimator.clone()),
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 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 49 of file KFTrajectoryFitter.h.

References dummyGeometry, and theGeometry.

55  : thePropagator(aPropagator),
56  theUpdator(aUpdator),
57  theEstimator(aEstimator),
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
susybsm::HSCParticleCollection hc
Definition: classes.h:25
TkCloner const * theHitCloner
KFTrajectoryFitter::~KFTrajectoryFitter ( )
inlineoverride

Definition at line 66 of file KFTrajectoryFitter.h.

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

66  {
67  if (owner) {
68  delete thePropagator;
69  delete theUpdator;
70  delete theEstimator;
71  }
72  }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const Propagator * thePropagator
KFTrajectoryFitter::KFTrajectoryFitter ( KFTrajectoryFitter const &  )
privatedelete

Member Function Documentation

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

Implements TrajectoryFitter.

Definition at line 86 of file KFTrajectoryFitter.h.

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

86  {
87  return owner ? std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
89  : std::unique_ptr<TrajectoryFitter>(new KFTrajectoryFitter(
91  }
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 84 of file KFTrajectoryFitter.h.

References theEstimator.

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

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

Implements TrajectoryFitter.

Definition at line 13 of file KFTrajectoryFitter.cc.

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

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

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

Implements TrajectoryFitter.

Definition at line 23 of file KFTrajectoryFitter.cc.

References Exception.

23  {
24  throw cms::Exception("TrackFitters",
25  "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
26 
27  return Trajectory();
28 }
Trajectory KFTrajectoryFitter::fitOne ( const TrajectorySeed aSeed,
const RecHitContainer hits,
const TSOS firstPredTsos,
fitType   
) const
overridevirtual

Implements TrajectoryFitter.

Definition at line 30 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(), dqmiolumiharvest::j, LIKELY, TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), TrajectoryStateOnSurface::localPosition(), LogDebug, LogTrace, TkCloner::makeShared(), minHits_, LocalTrajectoryError::posDef(), GloballyPositioned< T >::position(), LocalTrajectoryParameters::position(), LocalTrajectoryParameters::qbp(), runTheMatrix::ret, 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().

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

Definition at line 82 of file KFTrajectoryFitter.h.

References thePropagator.

Referenced by KFSplittingFitter::clone().

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

Implements TrajectoryFitter.

Definition at line 94 of file KFTrajectoryFitter.h.

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

Referenced by KFSplittingFitter::setHitCloner().

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

Definition at line 83 of file KFTrajectoryFitter.h.

References theUpdator.

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

83 { return theUpdator; }
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

const DetLayerGeometry KFTrajectoryFitter::dummyGeometry
staticprivate

Definition at line 99 of file KFTrajectoryFitter.h.

Referenced by KFTrajectoryFitter().

int KFTrajectoryFitter::minHits_
private

Definition at line 105 of file KFTrajectoryFitter.h.

Referenced by clone(), and fitOne().

bool KFTrajectoryFitter::owner
private

Definition at line 106 of file KFTrajectoryFitter.h.

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

const MeasurementEstimator* KFTrajectoryFitter::theEstimator
private

Definition at line 102 of file KFTrajectoryFitter.h.

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

const DetLayerGeometry* KFTrajectoryFitter::theGeometry
private

Definition at line 104 of file KFTrajectoryFitter.h.

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

TkCloner const* KFTrajectoryFitter::theHitCloner = 0
private

Definition at line 103 of file KFTrajectoryFitter.h.

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

const Propagator* KFTrajectoryFitter::thePropagator
private

Definition at line 100 of file KFTrajectoryFitter.h.

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

const TrajectoryStateUpdator* KFTrajectoryFitter::theUpdator
private

Definition at line 101 of file KFTrajectoryFitter.h.

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