CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoVertex/GhostTrackFitter/src/SequentialGhostTrackFitter.cc

Go to the documentation of this file.
00001 #include <vector>
00002 
00003 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackState.h"
00004 #include "RecoVertex/GhostTrackFitter/interface/GhostTrackPrediction.h"
00005 
00006 #include "RecoVertex/GhostTrackFitter/interface/SequentialGhostTrackFitter.h"
00007 
00008 using namespace reco;
00009 
00010 namespace {
00011         static inline double sqr(double arg) { return arg * arg; }
00012 }
00013 
00014 SequentialGhostTrackFitter::SequentialGhostTrackFitter() :
00015         maxIteration(15),
00016         minDeltaR(0.0015),
00017         minDistance(0.002),
00018         weightThreshold(0.001)
00019 {
00020 }
00021 
00022 bool SequentialGhostTrackFitter::stable(
00023                                 const GhostTrackPrediction &before,
00024                                 const GhostTrackPrediction &after) const
00025 {
00026         return (sqr(after.sz() - before.sz()) +
00027                 sqr(after.ip() - before.ip()) < sqr(minDistance) &&
00028                 sqr(after.eta() - before.eta()) +
00029                 sqr(after.phi() - before.phi()) < sqr(minDeltaR));
00030 }
00031 
00032 GhostTrackPrediction SequentialGhostTrackFitter::fit(
00033                         const GhostTrackFitter::PredictionUpdater &updater,
00034                         const GhostTrackPrediction &prior,
00035                         std::vector<GhostTrackState> &states,
00036                         double &ndof, double &chi2)
00037 {
00038         GhostTrackPrediction pred, lastPred = prior;
00039 
00040         reset();
00041 
00042         ndof = 0.;
00043         chi2 = 0.;
00044 
00045         unsigned int iteration = 0;
00046         for(;;) {
00047                 pred = prior;
00048 
00049                 if (states.begin() == states.end())
00050                         break;
00051 
00052                 if (iteration > 0) {
00053                         for(unsigned int i = 0; i < states.size(); i++) {
00054                                 GhostTrackState &state = states[i];
00055                                 state.linearize(lastPred);
00056                         }
00057                 }
00058 
00059                 ndof = 0.; // prior gives us an initial ndof
00060                 chi2 = 0.;
00061 
00062                 for(std::vector<GhostTrackState>::const_iterator state = 
00063                         states.begin(); state != states.end(); ++state) {
00064 
00065                         if (state->isValid() &&
00066                             state->weight() > weightThreshold)
00067                                 pred = updater.update(pred, *state,
00068                                                       ndof, chi2);
00069                 }
00070 
00071                 if (++iteration >= maxIteration || stable(lastPred, pred))
00072                         break;
00073 
00074                 postFit(updater, pred, states);
00075 
00076                 lastPred = pred;
00077         }
00078 
00079         return pred;
00080 }