CMS 3D CMS Logo

GsfTrajectorySmoother.cc
Go to the documentation of this file.
2 
8 
10 
12  const TrajectoryStateUpdator& aUpdator,
13  const MeasurementEstimator& aEstimator,
14  const MultiTrajectoryStateMerger& aMerger,
15  float errorRescaling,
16  const bool materialBeforeUpdate,
17  const DetLayerGeometry* detLayerGeometry)
18  : theAlongPropagator(nullptr),
19  theOppositePropagator(nullptr),
20  theGeomPropagator(nullptr),
21  theConvolutor(nullptr),
22  theUpdator(aUpdator.clone()),
23  theEstimator(aEstimator.clone()),
24  theMerger(aMerger.clone()),
25  theMatBeforeUpdate(materialBeforeUpdate),
26  theErrorRescaling(errorRescaling),
27  theGeometry(detLayerGeometry) {
28  auto p = aPropagator.clone();
29  p->setPropagationDirection(alongMomentum);
31  p = aPropagator.clone();
32  p->setPropagationDirection(oppositeToMomentum);
34  if (!theMatBeforeUpdate) {
37  }
38 
39  if (!theGeometry)
41 }
42 
44  delete theAlongPropagator;
45  delete theOppositePropagator;
46  delete theGeomPropagator;
47  delete theConvolutor;
48  delete theUpdator;
49  delete theEstimator;
50  delete theMerger;
51 }
52 
54  if (aTraj.empty())
55  return Trajectory();
56 
57  const Propagator* usePropagator = theAlongPropagator;
58  if (aTraj.direction() == alongMomentum) {
59  usePropagator = theOppositePropagator;
60  }
61  if (not usePropagator) {
62  usePropagator = theGeomPropagator;
63  }
64 
65  Trajectory myTraj(aTraj.seed(), usePropagator->propagationDirection());
66 
67  std::vector<TM> const& avtm = aTraj.measurements();
68 
69  TSOS predTsos = avtm.back().forwardPredictedState();
71 
72  if (!predTsos.isValid()) {
73  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos of last measurement not valid!";
74  return Trajectory();
75  }
76  TSOS currTsos;
77 
78  //first smoothed tm is last fitted
79  if (avtm.back().recHit()->isValid()) {
80  {
81  // TimeMe t(*updateTimer,false);
82  currTsos = updator()->update(predTsos, *avtm.back().recHit());
83  }
84 
85  if (!currTsos.isValid()) {
86  edm::LogInfo("GsfTrajectorySmoother") << "GsfTrajectorySmoother: tsos not valid after update!";
87  return Trajectory();
88  }
89 
90  //check validity
91  if (!avtm.back().forwardPredictedState().isValid() || !predTsos.isValid() ||
92  !avtm.back().updatedState().isValid()) {
93  edm::LogError("InvalidState") << "first hit";
94  return Trajectory();
95  }
96 
97  myTraj.push(TM(avtm.back().forwardPredictedState(),
98  predTsos,
99  avtm.back().updatedState(),
100  avtm.back().recHit(),
101  avtm.back().estimate(),
102  theGeometry->idToLayer(avtm.back().recHit()->geographicalId())),
103  avtm.back().estimate());
104  } else {
105  currTsos = predTsos;
106  //check validity
107  if (!avtm.back().forwardPredictedState().isValid()) {
108  edm::LogError("InvalidState") << "first hit on invalid hit";
109  return Trajectory();
110  }
111 
112  myTraj.push(TM(avtm.back().forwardPredictedState(),
113  avtm.back().recHit(),
114  0.,
115  theGeometry->idToLayer(avtm.back().recHit()->geographicalId())));
116  }
117 
119 
120  int hitcounter = avtm.size() - 1;
121  for (std::vector<TM>::const_reverse_iterator itm = avtm.rbegin() + 1; itm < avtm.rend() - 1; ++itm) {
122  predTsos = usePropagator->propagate(currTsos, *(*itm).recHit()->surface());
123  if (predTsos.isValid() && theConvolutor && theMatBeforeUpdate)
124  predTsos = (*theConvolutor)(predTsos, usePropagator->propagationDirection());
125  if (!predTsos.isValid()) {
126  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos not valid!";
127  return Trajectory();
128  }
129  if (theMerger)
130  predTsos = theMerger->merge(predTsos);
131 
132  if (!predTsos.isValid()) {
133  return Trajectory();
134  }
135 
136  if ((*itm).recHit()->isValid()) {
137  //update
138  currTsos = updator()->update(predTsos, *(*itm).recHit());
139 
140  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
141  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
142  if (!currTsos.isValid()) {
143  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
144  return Trajectory();
145  }
146  //3 different possibilities to calculate smoothed state:
147  //1: update combined predictions with hit
148  //2: combine fwd-prediction with bwd-filter
149  //3: combine bwd-prediction with fwd-filter
150  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
151  if (!combTsos.isValid()) {
152  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!\n"
153  << "pred Tsos pos: " << predTsos.globalPosition() << "\n"
154  << "pred Tsos mom: " << predTsos.globalMomentum() << "\n"
155  << "TrackingRecHit: "
156  << (*itm).recHit()->surface()->toGlobal((*itm).recHit()->localPosition()) << "\n";
157  return Trajectory();
158  }
159 
160  TSOS smooTsos = combiner((*itm).updatedState(), predTsos);
161 
162  if (!smooTsos.isValid()) {
163  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
164  return Trajectory();
165  }
166 
167  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !smooTsos.isValid()) {
168  edm::LogError("InvalidState") << "inside hits with combination.";
169  return Trajectory();
170  }
171 
172  auto chi2 = estimator()->estimate(combTsos, *(*itm).recHit()).second;
173  myTraj.push(TM((*itm).forwardPredictedState(),
174  predTsos,
175  smooTsos,
176  (*itm).recHit(),
177  chi2,
178  theGeometry->idToLayer((*itm).recHit()->geographicalId())),
179  (*itm).estimate());
180  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
181  dump(predTsos, "predTsos", "GsfTrackFitters");
182  dump(smooTsos, "smooTsos", "GsfTrackFitters");
183 
184  } else {
185  currTsos = predTsos;
186  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
187 
188  if (!combTsos.isValid()) {
189  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!";
190  return Trajectory();
191  }
192 
193  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !combTsos.isValid()) {
194  edm::LogError("InvalidState") << "inside hits with invalid rechit.";
195  return Trajectory();
196  }
197 
198  myTraj.push(TM((*itm).forwardPredictedState(),
199  predTsos,
200  combTsos,
201  (*itm).recHit(),
202  0.,
203  theGeometry->idToLayer((*itm).recHit()->geographicalId())));
204  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
205  dump(predTsos, "predTsos", "GsfTrackFitters");
206  dump(combTsos, "smooTsos", "GsfTrackFitters");
207  }
208  if (theMerger)
209  currTsos = theMerger->merge(currTsos);
210 
211  if (!currTsos.isValid()) {
212  return Trajectory();
213  }
214  dump(currTsos, "currTsos", "GsfTrackFitters");
215  }
216 
217  //last smoothed tm is last filtered
218  predTsos = usePropagator->propagate(currTsos, *avtm.front().recHit()->surface());
219  if (predTsos.isValid() && theConvolutor && theMatBeforeUpdate)
220  predTsos = (*theConvolutor)(predTsos, usePropagator->propagationDirection());
221  if (!predTsos.isValid()) {
222  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos not valid!";
223  return Trajectory();
224  }
225  if (theMerger)
226  predTsos = theMerger->merge(predTsos);
227 
228  if (avtm.front().recHit()->isValid()) {
229  //update
230  currTsos = updator()->update(predTsos, *avtm.front().recHit());
231  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
232  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
233  if (!currTsos.isValid()) {
234  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
235  return Trajectory();
236  }
237 
238  if (!avtm.front().forwardPredictedState().isValid() || !predTsos.isValid() || !currTsos.isValid()) {
239  edm::LogError("InvalidState") << "last hit";
240  return Trajectory();
241  }
242 
243  auto chi2 = estimator()->estimate(predTsos, *avtm.front().recHit()).second;
244  myTraj.push(TM(avtm.front().forwardPredictedState(),
245  predTsos,
246  currTsos,
247  avtm.front().recHit(),
248  chi2,
249  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())),
250  avtm.front().estimate());
251  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
252  dump(predTsos, "predTsos", "GsfTrackFitters");
253  dump(currTsos, "smooTsos", "GsfTrackFitters");
254 
255  } else {
256  if (!avtm.front().forwardPredictedState().isValid()) {
257  edm::LogError("InvalidState") << "last invalid hit";
258  return Trajectory();
259  }
260  myTraj.push(TM(avtm.front().forwardPredictedState(),
261  avtm.front().recHit(),
262  0.,
263  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())));
264  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
265  }
266 
267  return myTraj;
268 }
GsfPropagatorWithMaterial * clone() const override
virtual const DetLayer * idToLayer(const DetId &detId) const
const GsfPropagatorAdapter * theGeomPropagator
const TrajectoryStateUpdator * updator() const
TrajectoryMeasurement TM
Log< level::Error, false > LogError
const SurfaceType & surface() const
const FullConvolutionWithMaterial * theConvolutor
const DetLayerGeometry * theGeometry
DataContainer const & measurements() const
Definition: Trajectory.h:178
U second(std::pair< T, U > const &p)
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
const MultiTrajectoryStateMerger * theMerger
GlobalPoint globalPosition() const
const DetLayerGeometry dummyGeometry
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
FullConvolutionWithMaterial * clone() const
Clone.
TrajectoryStateOnSurface merge(const TrajectoryStateOnSurface &tsos) const
const FullConvolutionWithMaterial & convolutionWithMaterial() const
Access to the convolutor and thus to the material effects.
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
const MeasurementEstimator * theEstimator
Log< level::Info, false > LogInfo
Trajectory trajectory(const Trajectory &aTraj) const override
const MeasurementEstimator * estimator() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
const TrajectoryStateUpdator * theUpdator
const Propagator & geometricalPropagator() const
Access to the geometrical propagator.
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
GlobalVector globalMomentum() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
const GsfPropagatorWithMaterial * theAlongPropagator
const GsfPropagatorWithMaterial * theOppositePropagator
GsfTrajectorySmoother(const GsfPropagatorWithMaterial &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, const MultiTrajectoryStateMerger &merger, float errorRescaling, const bool materialBeforeUpdate=true, const DetLayerGeometry *detLayerGeometry=nullptr)
#define LogDebug(id)