CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoTracker/TrackProducer/src/TrajectoryToResiduals.cc

Go to the documentation of this file.
00001 #include "TrajectoryToResiduals.h"
00002 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00003 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00004 #include "TrackingTools/TransientTrackingRecHit/interface/HelpertRecHit2DLocalPos.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 reco::TrackResiduals trajectoryToResiduals (const Trajectory &trajectory,
00009                                             enum reco::TrackResiduals::ResidualType type) 
00010 {
00011      reco::TrackResiduals residuals(type);
00012      int i_residual = 0;
00013      Trajectory::DataContainer::const_iterator i_fwd = 
00014           trajectory.measurements().begin(); 
00015      Trajectory::DataContainer::const_reverse_iterator i_bwd = 
00016           trajectory.measurements().rbegin(); 
00017      Trajectory::DataContainer::const_iterator i_end = 
00018           trajectory.measurements().end(); 
00019      Trajectory::DataContainer::const_reverse_iterator i_rend = 
00020           trajectory.measurements().rend(); 
00021      bool forward = trajectory.direction() == alongMomentum;
00022      for (; forward ? i_fwd != i_end : i_bwd != i_rend; 
00023           ++i_fwd, ++i_bwd, ++i_residual) {
00024           const TrajectoryMeasurement *i = forward ? &*i_fwd : &*i_bwd;
00025           if (!i->recHit()->isValid()||i->recHit()->det()==0) 
00026                continue;
00027           TrajectoryStateCombiner combine;
00028           if (!i->forwardPredictedState().isValid() || !i->backwardPredictedState().isValid())
00029             {
00030               edm::LogError("InvalideState")<<"one of the step is invalid";
00031               continue;
00032             }
00033 
00034           TrajectoryStateOnSurface combo = combine(i->forwardPredictedState(),
00035                                                    i->backwardPredictedState());
00036           
00037           if (!combo.isValid()){
00038             edm::LogError("InvalideState")<<"the combined state is invalid";
00039             continue;
00040           }
00041 
00042           LocalPoint combo_localpos = combo.localPosition();
00043           LocalError combo_localerr = combo.localError().positionError();
00044           LocalPoint dethit_localpos = i->recHit()->localPosition();     
00045           LocalError dethit_localerr = i->recHit()->localPositionError();
00046           HelpertRecHit2DLocalPos helper;
00047           AlgebraicSymMatrix error_including_alignment = 
00048                helper.parError(dethit_localerr, *i->recHit()->det());
00049           switch (type) {
00050           case reco::TrackResiduals::X_Y_RESIDUALS: 
00051           {
00052                double x = (dethit_localpos.x() - combo_localpos.x()) / 
00053                     sqrt(error_including_alignment[0][0]);
00054                double y = (dethit_localpos.y() - combo_localpos.y()) / 
00055                     sqrt(error_including_alignment[1][1]);
00056                residuals.setResidualXY(i_residual, x, y);
00057                break;
00058           }
00059           case reco::TrackResiduals::X_Y_PULLS:
00060           {
00061                double x = (dethit_localpos.x() - combo_localpos.x()) / 
00062                     sqrt(error_including_alignment[0][0] + combo_localerr.xx());
00063                double y = (dethit_localpos.y() - combo_localpos.y()) / 
00064                     sqrt(error_including_alignment[1][1] + combo_localerr.yy());
00065                residuals.setPullXY(i_residual, x, y);
00066                break;
00067           }
00068           default:
00069                assert(0);
00070           }
00071      }
00072      return residuals;
00073 }