CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KFTrajectorySmoother.cc
Go to the documentation of this file.
16 
18 
19  delete thePropagator;
20  delete theUpdator;
21  delete theEstimator;
22 
23 }
24 
25 std::vector<Trajectory>
27  // let's try to get return value optimization
28  // the 'standard' case is when we return 1 tractory
29 
30  if ( aTraj.direction() == alongMomentum) {
32  } else {
34  }
35 
36  std::vector<Trajectory> ret(1, Trajectory(aTraj.seed(), thePropagator->propagationDirection()));
37  Trajectory & myTraj = ret.front();
38 
39 
40  if(aTraj.empty()) { ret.clear(); return ret; }
41 
42 
43  const std::vector<TM> & avtm = aTraj.measurements();
44  LogDebug("TrackFitters") << "KFTrajectorySmoother::trajectories starting with " << avtm.size() << " HITS\n";
45 
46  myTraj.reserve(avtm.size());
47 
48  for (unsigned int j=0;j<avtm.size();j++) {
49  if (avtm[j].recHit()->det())
50  LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << avtm[j].recHit()->det()->geographicalId().rawId()
51  << " validity=" << avtm[j].recHit()->isValid();
52  else
53  LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
54  }
55 
56  TSOS predTsos = avtm.back().forwardPredictedState();
58  TSOS currTsos;
59 
61 
62  unsigned int hitcounter = avtm.size();
63  for(std::vector<TM>::const_reverse_iterator itm = avtm.rbegin(); itm != (avtm.rend()); ++itm,--hitcounter) {
64 
66 
67  //check surface just for safety: should never be ==0 because they are skipped in the fitter
68  if ( hit->surface()==0 ) {
69  LogDebug("TrackFitters")<< " Error: invalid hit with no GeomDet attached .... skipping";
70  continue;
71  }
72 
73  if (hitcounter != avtm.size())//no propagation needed for first smoothed (==last fitted) hit
74  predTsos = thePropagator->propagate( currTsos, *(hit->surface()) );
75 
76  if(!predTsos.isValid()) {
77  LogDebug("TrackFitters") << "KFTrajectorySmoother: predicted tsos not valid!";
78  if( myTraj.foundHits() >= minHits_ ) {
79  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
80  } else {
81  LogDebug("TrackFitters") << " killing trajectory" << "\n";
82  ret.clear();
83  }
84  break;
85  }
86 
87  if(hit->isValid()) {
88  LogDebug("TrackFitters")
89  << "----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
90  << "HIT IS AT R " << hit->globalPosition().perp() << "\n"
91  << "HIT IS AT Z " << hit->globalPosition().z() << "\n"
92  << "HIT IS AT Phi " << hit->globalPosition().phi() << "\n"
93  << "HIT IS AT Loc " << hit->localPosition() << "\n"
94  << "WITH LocError " << hit->localPositionError() << "\n"
95  << "HIT IS AT Glo " << hit->globalPosition() << "\n"
96  << "SURFACE POSITION: " << hit->surface()->position() << "\n"
97  << "SURFACE ROTATION: " << hit->surface()->rotation() << "\n"
98  << "hit geographicalId=" << hit->geographicalId().rawId();
99 
100  DetId hitId = hit->geographicalId();
101 
102  if(hitId.det() == DetId::Tracker) {
103  if (hitId.subdetId() == StripSubdetector::TIB )
104  LogTrace("TrackFitters") << " I am TIB " << TIBDetId(hitId).layer();
105  else if (hitId.subdetId() == StripSubdetector::TOB )
106  LogTrace("TrackFitters") << " I am TOB " << TOBDetId(hitId).layer();
107  else if (hitId.subdetId() == StripSubdetector::TEC )
108  LogTrace("TrackFitters") << " I am TEC " << TECDetId(hitId).wheel();
109  else if (hitId.subdetId() == StripSubdetector::TID )
110  LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
111  else if (hitId.subdetId() == StripSubdetector::TID )
112  LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
113  else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel )
114  LogTrace("TrackFitters") << " I am PixBar " << PXBDetId(hitId).layer();
115  else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
116  LogTrace("TrackFitters") << " I am PixFwd " << PXFDetId(hitId).disk();
117  else
118  LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
119  }
120  else if(hitId.det() == DetId::Muon) {
121  if(hitId.subdetId() == MuonSubdetId::DT)
122  LogTrace("TrackFitters") << " I am DT " << DTWireId(hitId);
123  else if (hitId.subdetId() == MuonSubdetId::CSC )
124  LogTrace("TrackFitters") << " I am CSC " << CSCDetId(hitId);
125  else if (hitId.subdetId() == MuonSubdetId::RPC )
126  LogTrace("TrackFitters") << " I am RPC " << RPCDetId(hitId);
127  else
128  LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
129  }
130  else
131  LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
132 
133  TSOS combTsos,smooTsos;
134 
135  //3 different possibilities to calculate smoothed state:
136  //1: update combined predictions with hit
137  //2: combine fwd-prediction with bwd-filter
138  //3: combine bwd-prediction with fwd-filter
139 
140  //combTsos is the predicted state with N-1 hits information. this means:
141  //forward predicted state for first smoothed (last fitted) hit
142  //backward predicted state for last smoothed (first fitted) hit
143  //combination of forward and backward predictions for other hits
144  if (hitcounter == avtm.size()) combTsos = itm->forwardPredictedState();
145  else if (hitcounter == 1) combTsos = predTsos;
146  else combTsos = combiner(predTsos, itm->forwardPredictedState());
147  if(!combTsos.isValid()) {
148  LogDebug("TrackFitters") <<
149  "KFTrajectorySmoother: combined tsos not valid!\n" <<
150  "pred Tsos pos: " << predTsos.globalPosition() << "\n" <<
151  "pred Tsos mom: " << predTsos.globalMomentum() << "\n" <<
152  "TrackingRecHit: " << hit->surface()->toGlobal(hit->localPosition()) << "\n" ;
153  if( myTraj.foundHits() >= minHits_ ) {
154  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
155  } else {
156  LogDebug("TrackFitters") << " killing trajectory" << "\n";
157  ret.clear();
158  }
159  break;
160  }
161 
162  TransientTrackingRecHit::RecHitPointer preciseHit = hit->clone(combTsos);
163 
164  if (preciseHit->isValid() == false){
165  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
166  currTsos = predTsos;
167  myTraj.push(TM(predTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId()) ));
168  }else{
169  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
170 
171  //update backward predicted tsos with the hit
172  currTsos = updator()->update(predTsos, *preciseHit);
173  if (!currTsos.isValid()) {
174  currTsos = predTsos;
175  edm::LogWarning("KFSmoother_UpdateFailed") <<
176  "Failed updating state with hit. Rolling back to non-updated state.\n" <<
177  "State: " << predTsos <<
178  "Hit local pos: " << hit->localPosition() << "\n" <<
179  "Hit local err: " << hit->localPositionError() << "\n" <<
180  "Hit global pos: " << hit->globalPosition() << "\n" <<
181  "Hit global err: " << hit->globalPositionError().matrix() <<
182  "\n";
183  }
184 
185  //smooTsos updates the N-1 hits prediction with the hit
186  if (hitcounter == avtm.size()) smooTsos = itm->updatedState();
187  else if (hitcounter == 1) smooTsos = currTsos;
188  else smooTsos = combiner(itm->forwardPredictedState(), currTsos);
189 
190  if(!smooTsos.isValid()) {
191  LogDebug("TrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
192  if( myTraj.foundHits() >= minHits_ ) {
193  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
194  } else {
195  LogDebug("TrackFitters") << " killing trajectory" << "\n";
196  ret.clear();
197  }
198  break;
199  }
200 
201  double estimate;
202  if (hitcounter != avtm.size()) estimate = estimator()->estimate(combTsos, *preciseHit ).second;//correct?
203  else estimate = itm->estimate();
204 
205  LogTrace("TrackFitters")
206  << "predTsos !" << "\n"
207  << predTsos << "\n"
208  << "currTsos !" << "\n"
209  << currTsos << "\n"
210  << "smooTsos !" << "\n"
211  << smooTsos << "\n"
212  << "smoothing estimate (with combTSOS)=" << estimate << "\n"
213  << "filtering estimate=" << itm->estimate() << "\n";
214 
215  //check for valid hits with no det (refitter with constraints)
216  if (preciseHit->det()) myTraj.push(TM(itm->forwardPredictedState(),
217  predTsos,
218  smooTsos,
219  preciseHit,
220  estimate,
221  theGeometry->idToLayer(preciseHit->geographicalId()) ),
222  estimator()->estimate(predTsos,*preciseHit).second);
223  else myTraj.push(TM(itm->forwardPredictedState(),
224  predTsos,
225  smooTsos,
226  preciseHit,
227  estimate),
228  estimator()->estimate(predTsos,*preciseHit).second);
229  //itm->estimate());
230  }
231  } else {
232  LogDebug("TrackFitters")
233  << "----------------- HIT #" << hitcounter << " (INVALID)-----------------------";
234 
235  //no update
236  currTsos = predTsos;
237  TSOS combTsos;
238  if (hitcounter == avtm.size()) combTsos = itm->forwardPredictedState();
239  else if (hitcounter == 1) combTsos = predTsos;
240  else combTsos = combiner(predTsos, itm->forwardPredictedState());
241 
242  if(!combTsos.isValid()) {
243  LogDebug("TrackFitters") <<
244  "KFTrajectorySmoother: combined tsos not valid!";
245  ret.clear(); break;
246  }
247 
248  myTraj.push(TM(itm->forwardPredictedState(),
249  predTsos,
250  combTsos,
251  hit,
252  0,
253  theGeometry->idToLayer(hit->geographicalId()) ));
254  }
255  } // for loop
256 
257  return ret;
258 
259 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
int foundHits() const
Definition: Trajectory.h:224
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
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
const DetLayerGeometry * theGeometry
GlobalPoint globalPosition() const
void reserve(unsigned int n)
Definition: Trajectory.h:159
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
virtual std::vector< Trajectory > trajectories(const Trajectory &aTraj) const
DataContainer const & measurements() const
Definition: Trajectory.h:203
static const int CSC
Definition: MuonSubdetId.h:15
const MeasurementEstimator * estimator() const
int j
Definition: DBlmapReader.cc:9
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
TrajectoryMeasurement TM
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
Definition: DetId.h:20
const TrajectoryStateUpdator * updator() const
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
GlobalVector globalMomentum() const
static const int RPC
Definition: MuonSubdetId.h:16
virtual void setPropagationDirection(PropagationDirection dir) const
Definition: Propagator.h:132
static const int DT
Definition: MuonSubdetId.h:14
virtual const DetLayer * idToLayer(const DetId &detId) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50