CMS 3D CMS Logo

Public Member Functions | Private Types | Private Attributes

KFTrajectorySmoother Class Reference

#include <KFTrajectorySmoother.h>

Inheritance diagram for KFTrajectorySmoother:
TrajectorySmoother

List of all members.

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, const DetLayerGeometry *detLayerGeometry=0)
 KFTrajectorySmoother (const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, float errorRescaling=100.f, int minHits=3)
const Propagatorpropagator () const
virtual std::vector< Trajectorytrajectories (const Trajectory &aTraj) const
const TrajectoryStateUpdatorupdator () const
virtual ~KFTrajectorySmoother ()

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

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().

                                        :
    thePropagator(aPropagator.clone()),
    theUpdator(aUpdator.clone()),
    theEstimator(aEstimator.clone()),
    theErrorRescaling(errorRescaling),
    minHits_(minHits),
    theGeometry(0){ // to be fixed. Why this first constructor is needed? who is using it? Can it be removed?
      if(!theGeometry) theGeometry = &dummyGeometry;
    }
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.

                                                                   :
    thePropagator(aPropagator->clone()),
    theUpdator(aUpdator->clone()),
    theEstimator(aEstimator->clone()),
    theErrorRescaling(errorRescaling),
    minHits_(minHits),
    theGeometry(detLayerGeometry){
      if(!theGeometry) theGeometry = &dummyGeometry;
    }
KFTrajectorySmoother::~KFTrajectorySmoother ( ) [virtual]

Definition at line 17 of file KFTrajectorySmoother.cc.

References theEstimator, thePropagator, and theUpdator.

                                            {

  delete thePropagator;
  delete theUpdator;
  delete theEstimator;

}

Member Function Documentation

virtual KFTrajectorySmoother* KFTrajectorySmoother::clone ( void  ) const [inline, virtual]
const MeasurementEstimator* KFTrajectorySmoother::estimator ( void  ) const [inline]

Definition at line 68 of file KFTrajectorySmoother.h.

References theEstimator.

Referenced by trajectories().

{return theEstimator;}
const Propagator* KFTrajectorySmoother::propagator ( void  ) const [inline]

Definition at line 66 of file KFTrajectorySmoother.h.

References thePropagator.

Referenced by KalmanAlignmentAlgorithm::initializeAlignmentSetups().

{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, CSC(), CSCDetId, DetId::det(), Trajectory::direction(), PXFDetId::disk(), GeomDetEnumerators::DT, Trajectory::empty(), MeasurementEstimator::estimate(), estimator(), Trajectory::foundHits(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), DetLayerGeometry::idToLayer(), TrajectoryStateOnSurface::isValid(), j, TIBDetId::layer(), TOBDetId::layer(), PXBDetId::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, dedefs::RPC, RPCDetId, Trajectory::seed(), Propagator::setPropagationDirection(), DetId::subdetId(), sistripsummary::TEC, theErrorRescaling, theGeometry, thePropagator, sistripsummary::TIB, sistripsummary::TID, sistripsummary::TOB, align::Tracker, TrajectoryStateUpdator::update(), updator(), TIDDetId::wheel(), and TECDetId::wheel().

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

                                                                {
  // let's try to get return value optimization
  // the 'standard' case is when we return 1 tractory

  if (  aTraj.direction() == alongMomentum) {
    thePropagator->setPropagationDirection(oppositeToMomentum);
  } else {
    thePropagator->setPropagationDirection(alongMomentum);
  }

  std::vector<Trajectory> ret(1, Trajectory(aTraj.seed(), thePropagator->propagationDirection()));
  Trajectory & myTraj = ret.front();


  if(aTraj.empty()) { ret.clear(); return ret; } 


  const std::vector<TM> & avtm = aTraj.measurements();
  LogDebug("TrackFitters") << "KFTrajectorySmoother::trajectories starting with " << avtm.size() << " HITS\n";

  myTraj.reserve(avtm.size());

  for (unsigned int j=0;j<avtm.size();j++) { 
    if (avtm[j].recHit()->det()) 
      LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << avtm[j].recHit()->det()->geographicalId().rawId() 
                               << " validity=" << avtm[j].recHit()->isValid();
    else
      LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
  }

  TSOS predTsos = avtm.back().forwardPredictedState();
  predTsos.rescaleError(theErrorRescaling);
  TSOS currTsos;
 
  TrajectoryStateCombiner combiner;

  unsigned int hitcounter = avtm.size();
  for(std::vector<TM>::const_reverse_iterator itm = avtm.rbegin(); itm != (avtm.rend()); ++itm,--hitcounter) {

    TransientTrackingRecHit::ConstRecHitPointer hit = itm->recHit();

    //check surface just for safety: should never be ==0 because they are skipped in the fitter 
    if ( hit->surface()==0 ) {
      LogDebug("TrackFitters")<< " Error: invalid hit with no GeomDet attached .... skipping";
      continue;
    }

    if (hitcounter != avtm.size())//no propagation needed for first smoothed (==last fitted) hit 
      predTsos = thePropagator->propagate( currTsos, *(hit->surface()) );

    if(!predTsos.isValid()) {
      LogDebug("TrackFitters") << "KFTrajectorySmoother: predicted tsos not valid!";
      if( myTraj.foundHits() >= minHits_ ) {
        LogDebug("TrackFitters") << " breaking trajectory" << "\n";
      } else {        
        LogDebug("TrackFitters") << " killing trajectory" << "\n";      
        ret.clear(); 
      }
      break;      
    }

    if(hit->isValid()) {
      LogDebug("TrackFitters")
        << "----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
        << "HIT IS AT R   " << hit->globalPosition().perp() << "\n"
        << "HIT IS AT Z   " << hit->globalPosition().z() << "\n"
        << "HIT IS AT Phi " << hit->globalPosition().phi() << "\n"
        << "HIT IS AT Loc " << hit->localPosition() << "\n"
        << "WITH LocError " << hit->localPositionError() << "\n"
        << "HIT IS AT Glo " << hit->globalPosition() << "\n"
        << "SURFACE POSITION: " << hit->surface()->position() << "\n"
        << "SURFACE ROTATION: " << hit->surface()->rotation() << "\n"
        << "hit geographicalId=" << hit->geographicalId().rawId();
   
      DetId hitId = hit->geographicalId();

      if(hitId.det() == DetId::Tracker) {
        if (hitId.subdetId() == StripSubdetector::TIB )  
          LogTrace("TrackFitters") << " I am TIB " << TIBDetId(hitId).layer();
        else if (hitId.subdetId() == StripSubdetector::TOB ) 
          LogTrace("TrackFitters") << " I am TOB " << TOBDetId(hitId).layer();
        else if (hitId.subdetId() == StripSubdetector::TEC ) 
          LogTrace("TrackFitters") << " I am TEC " << TECDetId(hitId).wheel();
        else if (hitId.subdetId() == StripSubdetector::TID ) 
          LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
        else if (hitId.subdetId() == StripSubdetector::TID ) 
          LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
        else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel ) 
          LogTrace("TrackFitters") << " I am PixBar " << PXBDetId(hitId).layer();
        else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
          LogTrace("TrackFitters") << " I am PixFwd " << PXFDetId(hitId).disk();
        else 
          LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
      }
      else if(hitId.det() == DetId::Muon) {
        if(hitId.subdetId() == MuonSubdetId::DT)
          LogTrace("TrackFitters") << " I am DT " << DTWireId(hitId);
        else if (hitId.subdetId() == MuonSubdetId::CSC )
          LogTrace("TrackFitters") << " I am CSC " << CSCDetId(hitId);
        else if (hitId.subdetId() == MuonSubdetId::RPC )
          LogTrace("TrackFitters") << " I am RPC " << RPCDetId(hitId);
        else 
          LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
      }
      else
        LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
    
      TSOS combTsos,smooTsos;

      //3 different possibilities to calculate smoothed state:
      //1: update combined predictions with hit
      //2: combine fwd-prediction with bwd-filter
      //3: combine bwd-prediction with fwd-filter

      //combTsos is the predicted state with N-1 hits information. this means: 
      //forward predicted state for first smoothed (last fitted) hit
      //backward predicted state for last smoothed (first fitted) hit
      //combination of forward and backward predictions for other hits
      if (hitcounter == avtm.size()) combTsos = itm->forwardPredictedState();
      else if (hitcounter == 1) combTsos = predTsos;
      else combTsos = combiner(predTsos, itm->forwardPredictedState());
      if(!combTsos.isValid()) {
        LogDebug("TrackFitters") << 
          "KFTrajectorySmoother: combined tsos not valid!\n" <<
          "pred Tsos pos: " << predTsos.globalPosition() << "\n" <<
          "pred Tsos mom: " << predTsos.globalMomentum() << "\n" <<
          "TrackingRecHit: " << hit->surface()->toGlobal(hit->localPosition()) << "\n" ;
        if( myTraj.foundHits() >= minHits_ ) {
          LogDebug("TrackFitters") << " breaking trajectory" << "\n";
        } else {        
          LogDebug("TrackFitters") << " killing trajectory" << "\n";       
          ret.clear(); 
        }
        break;      
      }

      TransientTrackingRecHit::RecHitPointer preciseHit = hit->clone(combTsos);

      if (preciseHit->isValid() == false){
        LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
        currTsos = predTsos;
        myTraj.push(TM(predTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId()) ));
      }else{
        LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
        
        //update backward predicted tsos with the hit
        currTsos = updator()->update(predTsos, *preciseHit);
        if (!currTsos.isValid()) {
            currTsos = predTsos;
            edm::LogWarning("KFSmoother_UpdateFailed") << 
                "Failed updating state with hit. Rolling back to non-updated state.\n" <<
                "State: "   << predTsos << 
                "Hit local pos:  " << hit->localPosition() << "\n" <<
                "Hit local err:  " << hit->localPositionError() << "\n" <<
                "Hit global pos: " << hit->globalPosition() << "\n" <<
                "Hit global err: " << hit->globalPositionError().matrix() << 
                "\n";
        }

        //smooTsos updates the N-1 hits prediction with the hit
        if (hitcounter == avtm.size()) smooTsos = itm->updatedState();
        else if (hitcounter == 1) smooTsos = currTsos;
        else smooTsos = combiner(itm->forwardPredictedState(), currTsos); 
        
        if(!smooTsos.isValid()) {
          LogDebug("TrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
          if( myTraj.foundHits() >= minHits_ ) {
            LogDebug("TrackFitters") << " breaking trajectory" << "\n";
          } else {        
            LogDebug("TrackFitters") << " killing trajectory" << "\n";       
            ret.clear(); 
          }
          break;
        }
        
        double estimate;
        if (hitcounter != avtm.size()) estimate = estimator()->estimate(combTsos, *preciseHit ).second;//correct?
        else estimate = itm->estimate();
        
        LogTrace("TrackFitters")
          << "predTsos !" << "\n"
          << predTsos << "\n"
          << "currTsos !" << "\n"
          << currTsos << "\n"
          << "smooTsos !" << "\n"
          << smooTsos << "\n"
          << "smoothing estimate (with combTSOS)=" << estimate << "\n"
          << "filtering estimate=" << itm->estimate() << "\n";
        
        //check for valid hits with no det (refitter with constraints)
        if (preciseHit->det()) myTraj.push(TM(itm->forwardPredictedState(),
                                              predTsos,
                                              smooTsos,
                                              preciseHit,
                                              estimate,
                                              theGeometry->idToLayer(preciseHit->geographicalId()) ),
                                           estimator()->estimate(predTsos,*preciseHit).second);
        else myTraj.push(TM(itm->forwardPredictedState(),
                            predTsos,
                            smooTsos,
                            preciseHit,
                            estimate),
                         estimator()->estimate(predTsos,*preciseHit).second);
        //itm->estimate());
      }
    } else {
      LogDebug("TrackFitters") 
        << "----------------- HIT #" << hitcounter << " (INVALID)-----------------------";      

      //no update
      currTsos = predTsos;
      TSOS combTsos;
      if (hitcounter == avtm.size()) combTsos = itm->forwardPredictedState();
      else if (hitcounter == 1) combTsos = predTsos;
      else combTsos = combiner(predTsos, itm->forwardPredictedState());
      
      if(!combTsos.isValid()) {
        LogDebug("TrackFitters") << 
          "KFTrajectorySmoother: combined tsos not valid!";
        ret.clear(); break;
      }
      
      myTraj.push(TM(itm->forwardPredictedState(),
                     predTsos,
                     combTsos,
                     hit,
                     0,
                     theGeometry->idToLayer(hit->geographicalId()) ));
    }
  } // for loop

  return ret; 
  
}
const TrajectoryStateUpdator* KFTrajectorySmoother::updator ( ) const [inline]

Definition at line 67 of file KFTrajectorySmoother.h.

References theUpdator.

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

{return theUpdator;}

Member Data Documentation

Definition at line 75 of file KFTrajectorySmoother.h.

Referenced by KFTrajectorySmoother().

Definition at line 80 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectories().

Definition at line 79 of file KFTrajectorySmoother.h.

Referenced by clone(), and trajectories().

Definition at line 78 of file KFTrajectorySmoother.h.

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

Definition at line 81 of file KFTrajectorySmoother.h.

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

Definition at line 76 of file KFTrajectorySmoother.h.

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

Definition at line 77 of file KFTrajectorySmoother.h.

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