CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GsfTrajectoryFitter.cc
Go to the documentation of this file.
2 
8 
11 
13 
15  const TrajectoryStateUpdator& aUpdator,
16  const MeasurementEstimator& aEstimator,
17  const MultiTrajectoryStateMerger& aMerger,
18  const DetLayerGeometry* detLayerGeometry)
19  : thePropagator(aPropagator.clone()),
20  theUpdator(aUpdator.clone()),
21  theEstimator(aEstimator.clone()),
22  theMerger(aMerger.clone()),
23  theGeometry(detLayerGeometry) {
24  if (!theGeometry)
26 }
27 
29  delete thePropagator;
30  delete theUpdator;
31  delete theEstimator;
32  delete theMerger;
33 }
34 
36  if (aTraj.empty())
37  return Trajectory();
38 
39  TM const& firstTM = aTraj.firstMeasurement();
40  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
41 
42  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos, type);
43 }
44 
46  edm::LogError("GsfTrajectoryFitter") << "GsfTrajectoryFitter::fit(TrajectorySeed, vector<RecHit>) not implemented";
47 
48  return Trajectory();
49 }
50 
52  const RecHitContainer& hits,
53  const TrajectoryStateOnSurface& firstPredTsos,
54  fitType) const {
55  if (hits.empty())
56  return Trajectory();
57 
58  Trajectory myTraj(aSeed, propagator()->propagationDirection());
59 
60  TSOS predTsos(firstPredTsos);
61  if (!predTsos.isValid()) {
62  edm::LogInfo("GsfTrackFitters") << "GsfTrajectoryFitter: predicted tsos of first measurement not valid!";
63  return Trajectory();
64  }
65 
66  TSOS currTsos;
67  if (hits.front()->isValid()) {
68  auto const& ihit = hits.front();
69  //update
70  assert((!(ihit)->canImproveWithTrack()) | (nullptr != theHitCloner));
71  assert((!(ihit)->canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>(ihit.get())));
72  auto preciseHit = theHitCloner->makeShared(ihit, predTsos);
73  dump(*preciseHit, 1, "GsfTrackFitters");
74  { currTsos = updator()->update(predTsos, *preciseHit); }
75  if (!predTsos.isValid() || !currTsos.isValid()) {
76  edm::LogError("InvalidState") << "first hit";
77  return Trajectory();
78  }
79  myTraj.push(TM(predTsos, currTsos, preciseHit, 0., theGeometry->idToLayer(preciseHit->geographicalId())),
80  estimator()->estimate(predTsos, *preciseHit).second);
81  } else {
82  currTsos = predTsos;
83  if (!predTsos.isValid()) {
84  edm::LogError("InvalidState") << "first invalid hit";
85  return Trajectory();
86  }
87  myTraj.push(TM(predTsos, hits.front(), 0., theGeometry->idToLayer((hits.front())->geographicalId())));
88  }
89 
90  int hitcounter = 1;
91  for (RecHitContainer::const_iterator ihit = hits.begin() + 1; ihit != hits.end(); ihit++) {
92  ++hitcounter;
93 
94  //
95  // temporary protection copied from KFTrajectoryFitter.
96  //
97  if ((**ihit).isValid() == false && (**ihit).det() == nullptr) {
98  LogDebug("GsfTrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
99  continue;
100  }
101 
102  {
103  // TimeMe t(*propTimer,false);
104  predTsos = propagator()->propagate(currTsos, (**ihit).det()->surface());
105  }
106  if (!predTsos.isValid()) {
107  if (myTraj.foundHits() >= 3) {
108  edm::LogInfo("GsfTrackFitters") << "GsfTrajectoryFitter: predicted tsos not valid! \n"
109  << "Returning trajectory with " << myTraj.foundHits() << " found hits.";
110  return myTraj;
111  } else {
112  edm::LogInfo("GsfTrackFitters") << "GsfTrajectoryFitter: predicted tsos not valid after " << myTraj.foundHits()
113  << " hits, discarding candidate!";
114  return Trajectory();
115  }
116  }
117  if (merger())
118  predTsos = merger()->merge(predTsos);
119 
120  if ((**ihit).isValid()) {
121  //update
122  assert((!(*ihit)->canImproveWithTrack()) | (nullptr != theHitCloner));
123  assert((!(*ihit)->canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>((*ihit).get())));
124  auto preciseHit = theHitCloner->makeShared(*ihit, predTsos);
125  dump(*preciseHit, hitcounter, "GsfTrackFitters");
126  currTsos = updator()->update(predTsos, *preciseHit);
127  if (!predTsos.isValid() || !currTsos.isValid()) {
128  edm::LogError("InvalidState") << "inside hit";
129  return Trajectory();
130  }
131  auto chi2 = estimator()->estimate(predTsos, *preciseHit).second;
132  myTraj.push(TM(predTsos, currTsos, preciseHit, chi2, theGeometry->idToLayer(preciseHit->geographicalId())));
133  LogDebug("GsfTrackFitters") << "added measurement with chi2 " << chi2;
134  } else {
135  currTsos = predTsos;
136  if (!predTsos.isValid()) {
137  edm::LogError("InvalidState") << "inside invalid hit";
138  return Trajectory();
139  }
140  myTraj.push(TM(predTsos, *ihit, 0., theGeometry->idToLayer((*ihit)->geographicalId())));
141  }
142  dump(predTsos, "predTsos", "GsfTrackFitters");
143  dump(currTsos, "currTsos", "GsfTrackFitters");
144  }
145  return myTraj;
146 }
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
const Propagator * thePropagator
const MultiTrajectoryStateMerger * theMerger
int foundHits() const
Definition: Trajectory.h:206
Trajectory fitOne(const Trajectory &t, fitType type) const override
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
TrajectoryStateOnSurface merge(const TrajectoryStateOnSurface &tsos) const
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:24
const DetLayerGeometry * theGeometry
Log< level::Error, false > LogError
assert(be >=bs)
const MeasurementEstimator * theEstimator
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
const SurfaceType & surface() const
TrajectoryMeasurement TM
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
const MultiTrajectoryStateMerger * merger() const
GsfTrajectoryFitter(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, const MultiTrajectoryStateMerger &aMerger, const DetLayerGeometry *detLayerGeometry=nullptr)
Log< level::Info, false > LogInfo
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
const Propagator * propagator() const
const TrajectoryStateUpdator * updator() const
const TrajectoryStateUpdator * theUpdator
TrajectoryStateOnSurface const & updatedState() const
virtual const DetLayer * idToLayer(const DetId &detId) const
Trajectory::RecHitContainer RecHitContainer
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
const MeasurementEstimator * estimator() const
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.
const DetLayerGeometry dummyGeometry
#define LogDebug(id)
TkCloner const * theHitCloner