CMS 3D CMS Logo

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