CMS 3D CMS Logo

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