CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Attributes
KFTrajectorySmoother Class Reference

#include <KFTrajectorySmoother.h>

Inheritance diagram for KFTrajectorySmoother:
TrajectorySmoother

Public Member Functions

virtual KFTrajectorySmootherclone () const
 
const MeasurementEstimatorestimator () const
 
 KFTrajectorySmoother (const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, float errorRescaling=100.f, int minHits=3)
 
 KFTrajectorySmoother (const Propagator *aPropagator, const TrajectoryStateUpdator *aUpdator, const MeasurementEstimator *aEstimator, float errorRescaling=100.f, int minHits=3, const DetLayerGeometry *detLayerGeometry=0)
 
const Propagatorpropagator () const
 
virtual std::vector< Trajectorytrajectories (const Trajectory &aTraj) const
 
const TrajectoryStateUpdatorupdator () const
 
virtual ~KFTrajectorySmoother ()
 
- Public Member Functions inherited from TrajectorySmoother
virtual ~TrajectorySmoother ()
 

Private Types

typedef FreeTrajectoryState FTS
 
typedef TrajectoryMeasurement TM
 
typedef TrajectoryStateOnSurface TSOS
 

Private Attributes

const DetLayerGeometry dummyGeometry
 
int minHits_
 
float theErrorRescaling
 
const MeasurementEstimatortheEstimator
 
const DetLayerGeometrytheGeometry
 
PropagatorthePropagator
 
const TrajectoryStateUpdatortheUpdator
 

Additional Inherited Members

- Public Types inherited from TrajectorySmoother
typedef std::vector< TrajectoryTrajectoryContainer
 
typedef
TrajectoryContainer::iterator 
TrajectoryIterator
 

Detailed Description

A Standard Kalman smoother. The forward fit is not redone, only the backward smoothing. Ported from ORCA

Date:
2009/07/03 01:11:06
Revision:
1.8
Author
todorov, cerati

Definition at line 22 of file KFTrajectorySmoother.h.

Member Typedef Documentation

Definition at line 27 of file KFTrajectorySmoother.h.

Definition at line 28 of file KFTrajectorySmoother.h.

Definition at line 26 of file KFTrajectorySmoother.h.

Constructor & Destructor Documentation

KFTrajectorySmoother::KFTrajectorySmoother ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
float  errorRescaling = 100.f,
int  minHits = 3 
)
inline

Definition at line 32 of file KFTrajectorySmoother.h.

References dummyGeometry, and theGeometry.

Referenced by clone().

36  :
37  thePropagator(aPropagator.clone()),
38  theUpdator(aUpdator.clone()),
39  theEstimator(aEstimator.clone()),
40  theErrorRescaling(errorRescaling),
41  minHits_(minHits),
42  theGeometry(0){ // to be fixed. Why this first constructor is needed? who is using it? Can it be removed?
44  }
virtual TrajectoryStateUpdator * clone() const =0
const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
virtual Propagator * clone() const =0
virtual MeasurementEstimator * clone() const =0
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
KFTrajectorySmoother::KFTrajectorySmoother ( const Propagator aPropagator,
const TrajectoryStateUpdator aUpdator,
const MeasurementEstimator aEstimator,
float  errorRescaling = 100.f,
int  minHits = 3,
const DetLayerGeometry detLayerGeometry = 0 
)
inline

Definition at line 47 of file KFTrajectorySmoother.h.

References dummyGeometry, and theGeometry.

52  :
53  thePropagator(aPropagator->clone()),
54  theUpdator(aUpdator->clone()),
55  theEstimator(aEstimator->clone()),
56  theErrorRescaling(errorRescaling),
57  minHits_(minHits),
58  theGeometry(detLayerGeometry){
60  }
virtual TrajectoryStateUpdator * clone() const =0
const DetLayerGeometry dummyGeometry
const DetLayerGeometry * theGeometry
virtual Propagator * clone() const =0
virtual MeasurementEstimator * clone() const =0
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
KFTrajectorySmoother::~KFTrajectorySmoother ( )
virtual

Definition at line 17 of file KFTrajectorySmoother.cc.

References theEstimator, thePropagator, and theUpdator.

17  {
18 
19  delete thePropagator;
20  delete theUpdator;
21  delete theEstimator;
22 
23 }
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator

Member Function Documentation

virtual KFTrajectorySmoother* KFTrajectorySmoother::clone ( void  ) const
inlinevirtual

Implements TrajectorySmoother.

Definition at line 70 of file KFTrajectorySmoother.h.

References KFTrajectorySmoother(), minHits_, theErrorRescaling, theEstimator, theGeometry, thePropagator, and theUpdator.

70  {
72  }
const DetLayerGeometry * theGeometry
KFTrajectorySmoother(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, float errorRescaling=100.f, int minHits=3)
const MeasurementEstimator * theEstimator
const TrajectoryStateUpdator * theUpdator
const MeasurementEstimator* KFTrajectorySmoother::estimator ( void  ) const
inline

Definition at line 68 of file KFTrajectorySmoother.h.

References theEstimator.

Referenced by trajectories().

68 {return theEstimator;}
const MeasurementEstimator * theEstimator
const Propagator* KFTrajectorySmoother::propagator ( void  ) const
inline

Definition at line 66 of file KFTrajectorySmoother.h.

References thePropagator.

Referenced by KalmanAlignmentAlgorithm::initializeAlignmentSetups().

66 {return thePropagator;}
std::vector< Trajectory > KFTrajectorySmoother::trajectories ( const Trajectory aTraj) const
virtual

Implements TrajectorySmoother.

Definition at line 26 of file KFTrajectorySmoother.cc.

References alongMomentum, heavyFlavorValidationHarvestingSequence_cff::combiner, MuonSubdetId::CSC, CSCDetId, DetId::det(), Trajectory::direction(), PXFDetId::disk(), MuonSubdetId::DT, Trajectory::empty(), MeasurementEstimator::estimate(), estimator(), Trajectory::foundHits(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), DetLayerGeometry::idToLayer(), TrajectoryStateOnSurface::isValid(), j, PXBDetId::layer(), TOBDetId::layer(), TIBDetId::layer(), LogDebug, LogTrace, Trajectory::measurements(), minHits_, DetId::Muon, oppositeToMomentum, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, Propagator::propagate(), Propagator::propagationDirection(), Trajectory::push(), TrajectoryStateOnSurface::rescaleError(), Trajectory::reserve(), run_regression::ret, MuonSubdetId::RPC, RPCDetId, Trajectory::seed(), Propagator::setPropagationDirection(), DetId::subdetId(), StripSubdetector::TEC, theErrorRescaling, theGeometry, thePropagator, StripSubdetector::TIB, StripSubdetector::TID, StripSubdetector::TOB, DetId::Tracker, TrajectoryStateUpdator::update(), updator(), TIDDetId::wheel(), and TECDetId::wheel().

Referenced by RoadSearchTrackCandidateMakerAlgorithm::PrepareTrackCandidates(), RoadSearchTrackCandidateMakerAlgorithm::run(), CosmicTrajectoryBuilder::run(), CRackTrajectoryBuilder::run(), and MuonRoadTrajectoryBuilder::smooth().

26  {
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
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
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
const TrajectoryStateUpdator* KFTrajectorySmoother::updator ( ) const
inline

Definition at line 67 of file KFTrajectorySmoother.h.

References theUpdator.

Referenced by KalmanAlignmentAlgorithm::initializeAlignmentSetups(), and trajectories().

67 {return theUpdator;}
const TrajectoryStateUpdator * theUpdator

Member Data Documentation

const DetLayerGeometry KFTrajectorySmoother::dummyGeometry
private

Definition at line 75 of file KFTrajectorySmoother.h.

Referenced by KFTrajectorySmoother().

int KFTrajectorySmoother::minHits_
private

Definition at line 80 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectories().

float KFTrajectorySmoother::theErrorRescaling
private

Definition at line 79 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectories().

const MeasurementEstimator* KFTrajectorySmoother::theEstimator
private

Definition at line 78 of file KFTrajectorySmoother.h.

Referenced by clone(), estimator(), and ~KFTrajectorySmoother().

const DetLayerGeometry* KFTrajectorySmoother::theGeometry
private

Definition at line 81 of file KFTrajectorySmoother.h.

Referenced by clone(), KFTrajectorySmoother(), and trajectories().

Propagator* KFTrajectorySmoother::thePropagator
private

Definition at line 76 of file KFTrajectorySmoother.h.

Referenced by clone(), propagator(), trajectories(), and ~KFTrajectorySmoother().

const TrajectoryStateUpdator* KFTrajectorySmoother::theUpdator
private

Definition at line 77 of file KFTrajectorySmoother.h.

Referenced by clone(), updator(), and ~KFTrajectorySmoother().