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 ((*itm).recHit()->isValid()) {
133  //update
134  currTsos = updator()->update(predTsos, *(*itm).recHit());
135 
136  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
137  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
138  if (!currTsos.isValid()) {
139  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
140  return Trajectory();
141  }
142  //3 different possibilities to calculate smoothed state:
143  //1: update combined predictions with hit
144  //2: combine fwd-prediction with bwd-filter
145  //3: combine bwd-prediction with fwd-filter
146  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
147  if (!combTsos.isValid()) {
148  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!\n"
149  << "pred Tsos pos: " << predTsos.globalPosition() << "\n"
150  << "pred Tsos mom: " << predTsos.globalMomentum() << "\n"
151  << "TrackingRecHit: "
152  << (*itm).recHit()->surface()->toGlobal((*itm).recHit()->localPosition()) << "\n";
153  return Trajectory();
154  }
155 
156  TSOS smooTsos = combiner((*itm).updatedState(), predTsos);
157 
158  if (!smooTsos.isValid()) {
159  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
160  return Trajectory();
161  }
162 
163  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !smooTsos.isValid()) {
164  edm::LogError("InvalidState") << "inside hits with combination.";
165  return Trajectory();
166  }
167 
168  auto chi2 = estimator()->estimate(combTsos, *(*itm).recHit()).second;
169  myTraj.push(TM((*itm).forwardPredictedState(),
170  predTsos,
171  smooTsos,
172  (*itm).recHit(),
173  chi2,
174  theGeometry->idToLayer((*itm).recHit()->geographicalId())),
175  (*itm).estimate());
176  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
177  dump(predTsos, "predTsos", "GsfTrackFitters");
178  dump(smooTsos, "smooTsos", "GsfTrackFitters");
179 
180  } else {
181  currTsos = predTsos;
182  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
183 
184  if (!combTsos.isValid()) {
185  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!";
186  return Trajectory();
187  }
188 
189  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !combTsos.isValid()) {
190  edm::LogError("InvalidState") << "inside hits with invalid rechit.";
191  return Trajectory();
192  }
193 
194  myTraj.push(TM((*itm).forwardPredictedState(),
195  predTsos,
196  combTsos,
197  (*itm).recHit(),
198  0.,
199  theGeometry->idToLayer((*itm).recHit()->geographicalId())));
200  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
201  dump(predTsos, "predTsos", "GsfTrackFitters");
202  dump(combTsos, "smooTsos", "GsfTrackFitters");
203  }
204  if (theMerger)
205  currTsos = theMerger->merge(currTsos);
206 
207  dump(currTsos, "currTsos", "GsfTrackFitters");
208  }
209 
210  //last smoothed tm is last filtered
211  predTsos = usePropagator->propagate(currTsos, *avtm.front().recHit()->surface());
212  if (predTsos.isValid() && theConvolutor && theMatBeforeUpdate)
213  predTsos = (*theConvolutor)(predTsos, usePropagator->propagationDirection());
214  if (!predTsos.isValid()) {
215  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos not valid!";
216  return Trajectory();
217  }
218  if (theMerger)
219  predTsos = theMerger->merge(predTsos);
220 
221  if (avtm.front().recHit()->isValid()) {
222  //update
223  currTsos = updator()->update(predTsos, *avtm.front().recHit());
224  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
225  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
226  if (!currTsos.isValid()) {
227  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
228  return Trajectory();
229  }
230 
231  if (!avtm.front().forwardPredictedState().isValid() || !predTsos.isValid() || !currTsos.isValid()) {
232  edm::LogError("InvalidState") << "last hit";
233  return Trajectory();
234  }
235 
236  auto chi2 = estimator()->estimate(predTsos, *avtm.front().recHit()).second;
237  myTraj.push(TM(avtm.front().forwardPredictedState(),
238  predTsos,
239  currTsos,
240  avtm.front().recHit(),
241  chi2,
242  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())),
243  avtm.front().estimate());
244  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
245  dump(predTsos, "predTsos", "GsfTrackFitters");
246  dump(currTsos, "smooTsos", "GsfTrackFitters");
247 
248  } else {
249  if (!avtm.front().forwardPredictedState().isValid()) {
250  edm::LogError("InvalidState") << "last invalid hit";
251  return Trajectory();
252  }
253  myTraj.push(TM(avtm.front().forwardPredictedState(),
254  avtm.front().recHit(),
255  0.,
256  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())));
257  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
258  }
259 
260  return myTraj;
261 }
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)