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 ) {
27  theGeomPropagator = new GsfPropagatorAdapter(thePropagator->geometricalPropagator());
28  theConvolutor = thePropagator->convolutionWithMaterial().clone();
29  }
30 
31  if(!theGeometry) theGeometry = &dummyGeometry;
32 
33  // static SimpleConfigurable<bool> timeConf(false,"GsfTrajectorySmoother:activateTiming");
34  // theTiming = timeConf.value();
35 }
36 
37 GsfTrajectorySmoother::~GsfTrajectorySmoother() {
38  delete thePropagator;
39  delete theGeomPropagator;
40  delete theConvolutor;
41  delete theUpdator;
42  delete theEstimator;
43  delete theMerger;
44 }
45 
47 GsfTrajectorySmoother::trajectory(const Trajectory& aTraj) const {
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 Trajectory();
59 
60  if ( aTraj.direction() == alongMomentum) {
61  thePropagator->setPropagationDirection(oppositeToMomentum);
62  }
63  else {
64  thePropagator->setPropagationDirection(alongMomentum);
65  }
66 
67  Trajectory myTraj(aTraj.seed(), propagator()->propagationDirection());
68 
69  std::vector<TM> const & avtm = aTraj.measurements();
70 
71  TSOS predTsos = avtm.back().forwardPredictedState();
72  predTsos.rescaleError(theErrorRescaling);
73 
74  if(!predTsos.isValid()) {
75  edm::LogInfo("GsfTrajectorySmoother")
76  << "GsfTrajectorySmoother: predicted tsos of last measurement not valid!";
77  return 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 
88  if(!currTsos.isValid()) {
89  edm::LogInfo("GsfTrajectorySmoother") << "GsfTrajectorySmoother: tsos not valid after update!";
90  return Trajectory();
91  }
92 
93  //check validity
94  if (!avtm.back().forwardPredictedState().isValid() || !predTsos.isValid() || !avtm.back().updatedState().isValid()){
95  edm::LogError("InvalidState")<<"first hit";
96  return Trajectory();
97  }
98 
99  myTraj.push(TM(avtm.back().forwardPredictedState(),
100  predTsos,
101  avtm.back().updatedState(),
102  avtm.back().recHit(),
103  avtm.back().estimate(),
104  theGeometry->idToLayer(avtm.back().recHit()->geographicalId()) ),
105  avtm.back().estimate());
106  } else {
107  currTsos = predTsos;
108  //check validity
109  if (!avtm.back().forwardPredictedState().isValid()){
110  edm::LogError("InvalidState")<<"first hit on invalid hit";
111  return Trajectory();
112  }
113 
114  myTraj.push(TM(avtm.back().forwardPredictedState(),
115  avtm.back().recHit(),
116  0.,
117  theGeometry->idToLayer(avtm.back().recHit()->geographicalId() ) ));
118  }
119 
121 
122  for(std::vector<TM>::const_reverse_iterator itm = avtm.rbegin() + 1;
123  itm < avtm.rend() - 1; ++itm) {
124  {
125  // TimeMe t(*propTimer,false);
126  // //
127  // // check type of surface in case of invalid hit
128  // // (in this version only propagations to planes are
129  // // supported for multi trajectory states)
130  // //
131  // if ( !(*itm).recHit().isValid() ) {
132  // const BoundPlane* plane =
133  // dynamic_cast<const BoundPlane*>(&(*itm).recHit().det().surface());
134  // //
135  // // no plane: insert invalid
136  // if ( plane==0 ) {
137  // myTraj.push(TM(TrajectoryStateOnSurface(),
138  // (*itm).recHit());
139  // continue;
140  // }
141  // }
142  predTsos = propagator()->propagate(currTsos,
143  *(*itm).recHit()->surface());
144  }
145  if ( predTsos.isValid() && theConvolutor && theMatBeforeUpdate )
146  predTsos = (*theConvolutor)(predTsos,
147  propagator()->propagationDirection());
148  if(!predTsos.isValid()) {
149  edm::LogInfo("GsfTrajectorySmoother") << "GsfTrajectorySmoother: predicted tsos not valid!";
150  return Trajectory();
151  }
152  if ( theMerger ) predTsos = theMerger->merge(predTsos);
153 
154  if((*itm).recHit()->isValid()) {
155  //update
156  {
157  // TimeMe t(*updateTimer,false);
158  currTsos = updator()->update(predTsos, *(*itm).recHit());
159  }
160  if ( currTsos.isValid() && theConvolutor && !theMatBeforeUpdate )
161  currTsos = (*theConvolutor)(currTsos,
162  propagator()->propagationDirection());
163  if(!currTsos.isValid()) {
164  edm::LogInfo("GsfTrajectorySmoother")
165  << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
166  return Trajectory();
167  }
168  //3 different possibilities to calculate smoothed state:
169  //1: update combined predictions with hit
170  //2: combine fwd-prediction with bwd-filter
171  //3: combine bwd-prediction with fwd-filter
172  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
173  if(!combTsos.isValid()) {
174  LogDebug("GsfTrajectorySmoother") <<
175  "KFTrajectorySmoother: combined tsos not valid!\n"<<
176  "pred Tsos pos: "<<predTsos.globalPosition()<< "\n" <<
177  "pred Tsos mom: "<<predTsos.globalMomentum()<< "\n" <<
178  "TrackingRecHit: "<<(*itm).recHit()->surface()->toGlobal((*itm).recHit()->localPosition())<< "\n" ;
179  return Trajectory();
180  }
181 
182  TSOS smooTsos = combiner((*itm).updatedState(), predTsos);
183 
184  if(!smooTsos.isValid()) {
185  LogDebug("GsfTrajectorySmoother") <<
186  "KFTrajectorySmoother: smoothed tsos not valid!";
187  return Trajectory();
188  }
189 
190  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !smooTsos.isValid() ){
191  edm::LogError("InvalidState")<<"inside hits with combination.";
192  return Trajectory();
193  }
194 
195 
196  myTraj.push(TM((*itm).forwardPredictedState(),
197  predTsos,
198  smooTsos,
199  (*itm).recHit(),
200  estimator()->estimate(combTsos, *(*itm).recHit()).second,
201  theGeometry->idToLayer((*itm).recHit()->geographicalId() ) ),
202  (*itm).estimate());
203  }
204  else {
205  currTsos = predTsos;
206  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
207 
208  if(!combTsos.isValid()) {
209  LogDebug("GsfTrajectorySmoother") <<
210  "KFTrajectorySmoother: combined tsos not valid!";
211  return Trajectory();
212  }
213 
214  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !combTsos.isValid() ){
215  edm::LogError("InvalidState")<<"inside hits with invalid rechit.";
216  return Trajectory();
217  }
218 
219  myTraj.push(TM((*itm).forwardPredictedState(),
220  predTsos,
221  combTsos,
222  (*itm).recHit(),
223  0.,
224  theGeometry->idToLayer((*itm).recHit()->geographicalId()) ));
225  }
226  if ( theMerger ) currTsos = theMerger->merge(currTsos);
227  }
228 
229  //last smoothed tm is last filtered
230  {
231  // TimeMe t(*propTimer,false);
232  predTsos = propagator()->propagate(currTsos,
233  *avtm.front().recHit()->surface());
234  }
235  if ( predTsos.isValid() && theConvolutor && theMatBeforeUpdate )
236  predTsos = (*theConvolutor)(predTsos,
237  propagator()->propagationDirection());
238  if(!predTsos.isValid()) {
239  edm::LogInfo("GsfTrajectorySmoother") << "GsfTrajectorySmoother: predicted tsos not valid!";
240  return Trajectory();
241  }
242  if ( theMerger ) predTsos = theMerger->merge(predTsos);
243 
244  if(avtm.front().recHit()->isValid()) {
245  //update
246  {
247  // TimeMe t(*updateTimer,false);
248  currTsos = updator()->update(predTsos, *avtm.front().recHit());
249  }
250  if ( currTsos.isValid() && theConvolutor && !theMatBeforeUpdate )
251  currTsos = (*theConvolutor)(currTsos,
252  propagator()->propagationDirection());
253  if(!currTsos.isValid()) {
254  edm::LogInfo("GsfTrajectorySmoother")
255  << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
256  return Trajectory();
257  }
258 
259  if (!avtm.front().forwardPredictedState().isValid() || !predTsos.isValid() || !currTsos.isValid() ){
260  edm::LogError("InvalidState")<<"last hit";
261  return Trajectory();
262  }
263 
264  myTraj.push(TM(avtm.front().forwardPredictedState(),
265  predTsos,
266  currTsos,
267  avtm.front().recHit(),
268  estimator()->estimate(predTsos, *avtm.front().recHit()).second,
269  theGeometry->idToLayer(avtm.front().recHit()->geographicalId() )),
270  avtm.front().estimate());
271  //estimator()->estimate(predTsos, avtm.front().recHit()));
272  }
273  else {
274  if (!avtm.front().forwardPredictedState().isValid()){
275  edm::LogError("InvalidState")<<"last invalid hit";
276  return Trajectory();
277  }
278  myTraj.push(TM(avtm.front().forwardPredictedState(),
279  avtm.front().recHit(),
280  0.,
281  theGeometry->idToLayer(avtm.front().recHit()->geographicalId()) ));
282  }
283 
284  return myTraj;
285 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:246
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:277
GlobalPoint globalPosition() const
FullConvolutionWithMaterial * clone() const
Clone.
PropagationDirection const & direction() const
Definition: Trajectory.cc:196
U second(std::pair< T, U > const &p)
DataContainer const & measurements() const
Definition: Trajectory.h:215
const SurfaceType & surface() const
void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
DeepCopyPointerByClone< FullConvolutionWithMaterial > theConvolutor
GlobalVector globalMomentum() const
tuple clone
Definition: statics.py:58