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