![]() |
![]() |
#include <TrackingTools/TrackFitters/interface/KFFittingSmoother.h>
Public Member Functions | |
KFFittingSmoother * | clone () const |
virtual std::vector< Trajectory > | fit (const TrajectorySeed &aSeed, const RecHitContainer &hits) const |
virtual std::vector< Trajectory > | fit (const TrajectorySeed &aSeed, const RecHitContainer &hits, const TrajectoryStateOnSurface &firstPredTsos) const |
virtual std::vector< Trajectory > | fit (const Trajectory &t) const |
const TrajectoryFitter * | fitter () const |
KFFittingSmoother (const TrajectoryFitter &aFitter, const TrajectorySmoother &aSmoother, double estimateCut=-1, int minNumberOfHits=5, bool rejectTracks=false, bool BreakTrajWith2ConsecutiveMissing=false, bool NoInvalidHitsBeginEnd=false) | |
constructor with predefined fitter and smoother and propagator | |
const TrajectorySmoother * | smoother () const |
virtual | ~KFFittingSmoother () |
Private Member Functions | |
void | smoothingStep (std::vector< Trajectory > &fitted, std::vector< Trajectory > &smoothed) const |
Private Attributes | |
bool | breakTrajWith2ConsecutiveMissing |
bool | noInvalidHitsBeginEnd |
bool | rejectTracksFlag |
double | theEstimateCut |
const TrajectoryFitter * | theFitter |
int | theMinNumberOfHits |
const TrajectorySmoother * | theSmoother |
TrajectoryStateWithArbitraryError | tsosWithError |
This is necessary e.g. when the seed introduced a bias (by using a beam contraint etc.). Ported from ORCA
Definition at line 19 of file KFFittingSmoother.h.
KFFittingSmoother::KFFittingSmoother | ( | const TrajectoryFitter & | aFitter, | |
const TrajectorySmoother & | aSmoother, | |||
double | estimateCut = -1 , |
|||
int | minNumberOfHits = 5 , |
|||
bool | rejectTracks = false , |
|||
bool | BreakTrajWith2ConsecutiveMissing = false , |
|||
bool | NoInvalidHitsBeginEnd = false | |||
) | [inline] |
constructor with predefined fitter and smoother and propagator
Definition at line 23 of file KFFittingSmoother.h.
Referenced by clone().
00029 : 00030 theFitter(aFitter.clone()), 00031 theSmoother(aSmoother.clone()), 00032 theEstimateCut(estimateCut), 00033 theMinNumberOfHits(minNumberOfHits), 00034 rejectTracksFlag(rejectTracks), 00035 breakTrajWith2ConsecutiveMissing(BreakTrajWith2ConsecutiveMissing), 00036 noInvalidHitsBeginEnd(NoInvalidHitsBeginEnd) {}
KFFittingSmoother::~KFFittingSmoother | ( | ) | [virtual] |
Definition at line 12 of file KFFittingSmoother.cc.
References theFitter, and theSmoother.
00012 { 00013 delete theSmoother; 00014 delete theFitter; 00015 }
KFFittingSmoother* KFFittingSmoother::clone | ( | void | ) | const [inline, virtual] |
Implements TrajectoryFitter.
Definition at line 50 of file KFFittingSmoother.h.
References KFFittingSmoother(), theFitter, and theSmoother.
00050 { 00051 return new KFFittingSmoother(*theFitter,*theSmoother); 00052 }
vector< Trajectory > KFFittingSmoother::fit | ( | const TrajectorySeed & | aSeed, | |
const RecHitContainer & | hits | |||
) | const [virtual] |
Definition at line 210 of file KFFittingSmoother.cc.
References Exception.
00211 { 00212 00213 throw cms::Exception("TrackFitters", 00214 "KFFittingSmoother::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented"); 00215 00216 return vector<Trajectory>(); 00217 }
vector< Trajectory > KFFittingSmoother::fit | ( | const TrajectorySeed & | aSeed, | |
const RecHitContainer & | hits, | |||
const TrajectoryStateOnSurface & | firstPredTsos | |||
) | const [virtual] |
Definition at line 29 of file KFFittingSmoother.cc.
References breakTrajWith2ConsecutiveMissing, InvalidTransientRecHit::build(), EgammaValidation_Zee_cff::cut, direction, empty, MeasurementEstimator::estimate(), KFTrajectorySmoother::estimator(), HLT_VtxMuL3::estimator, Exception, TrajectoryFitter::fit(), fitter(), it, j, LogDebug, LogTrace, TrackingRecHit::missing, noInvalidHitsBeginEnd, lhef::pop(), Trajectory::push(), rejectTracksFlag, edm::second(), smoother(), smoothingStep(), theEstimateCut, and theMinNumberOfHits.
00032 { 00033 LogDebug("TrackFitters") << "In KFFittingSmoother::fit"; 00034 00035 //if(hits.empty()) return vector<Trajectory>(); // gio: moved later to optimize return value 00036 00037 bool hasoutliers; 00038 RecHitContainer myHits = hits; 00039 vector<Trajectory> smoothed; 00040 vector<Trajectory> tmp_first; 00041 00042 do{ 00043 if(hits.empty()) { smoothed.clear(); break; } 00044 00045 //if no outliers the fit is done only once 00046 //for (unsigned int j=0;j<myHits.size();j++) { 00047 //if (myHits[j]->det()) 00048 //LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << myHits[j]->det()->geographicalId().rawId() 00049 //<< " validity=" << myHits[j]->isValid(); 00050 //else 00051 //LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information"; 00052 //} 00053 00054 hasoutliers = false; 00055 double cut = theEstimateCut; 00056 unsigned int outlierId = 0; 00057 const GeomDet* outlierDet = 0; 00058 00059 //call the fitter 00060 vector<Trajectory> fitted = fitter()->fit(aSeed, myHits, firstPredTsos); 00061 //call the smoother 00062 smoothed.clear(); 00063 smoothingStep(fitted, smoothed); 00064 00065 //if (tmp_first.size()==0) tmp_first = smoothed; moved later 00066 00067 if (smoothed.empty()) { 00068 if (rejectTracksFlag){ 00069 LogTrace("TrackFitters") << "smoothed.size()==0 => trajectory rejected"; 00070 //return vector<Trajectory>(); // break is enough to get this 00071 } else { 00072 LogTrace("TrackFitters") << "smoothed.size()==0 => returning orignal trajectory" ; 00073 smoothed.swap(tmp_first); // if first attempt, tmp_first would be empty anyway 00074 } 00075 break; 00076 } 00077 //else { 00078 //LogTrace("TrackFitters") << "dump hits after smoothing"; 00079 //Trajectory::DataContainer meas = smoothed[0].measurements(); 00080 //for (Trajectory::DataContainer::iterator it=meas.begin();it!=meas.end();++it) { 00081 //LogTrace("TrackFitters") << "hit #" << meas.end()-it-1 << " validity=" << it->recHit()->isValid() 00082 //<< " det=" << it->recHit()->geographicalId().rawId(); 00083 //} 00084 //} 00085 00086 if (theEstimateCut>0) { 00087 if (smoothed[0].foundHits()<theMinNumberOfHits) { 00088 if (rejectTracksFlag){ 00089 LogTrace("TrackFitters") << "smoothed[0].foundHits()<theMinNumberOfHits => trajectory rejected"; 00090 smoothed.clear(); 00091 //return vector<Trajectory>(); // break is enough 00092 } else { 00093 // it might be it's the first step 00094 if (!tmp_first.empty()) { tmp_first.swap(smoothed); } 00095 LogTrace("TrackFitters") 00096 << "smoothed[0].foundHits()<theMinNumberOfHits => returning orignal trajectory with chi2=" 00097 << smoothed[0].chiSquared() ; 00098 } 00099 break; 00100 } 00101 //check if there are outliers 00102 const std::vector<TrajectoryMeasurement> & vtm = smoothed[0].measurements(); 00103 for (std::vector<TrajectoryMeasurement>::const_iterator tm=vtm.begin(); tm!=vtm.end();tm++){ 00104 double estimate = tm->estimate(); 00105 if (estimate > cut) { 00106 hasoutliers = true; 00107 cut = estimate; 00108 outlierId = tm->recHit()->geographicalId().rawId(); 00109 outlierDet = tm->recHit()->det(); 00110 } 00111 } 00112 if (hasoutliers) {//reject outliers 00113 00114 //replace outlier hit with invalid hit 00115 for (unsigned int j=0;j<myHits.size();++j) { 00116 if (outlierId == myHits[j]->geographicalId().rawId()){ 00117 LogTrace("TrackFitters") << "Rejecting outlier hit with estimate " << cut << " at position " 00118 << j << " with rawId=" << myHits[j]->geographicalId().rawId(); 00119 LogTrace("TrackFitters") << "The fit will be repeated without the outlier"; 00120 myHits[j] = InvalidTransientRecHit::build(outlierDet, TrackingRecHit::missing); 00121 } 00122 } 00123 00124 //look if there are two consecutive invalid hits 00125 if (breakTrajWith2ConsecutiveMissing) { 00126 unsigned int firstinvalid = myHits.size()-1; 00127 for (unsigned int j=0;j<myHits.size()-1;++j) { 00128 if (myHits[j]->type()==TrackingRecHit::missing && myHits[j+1]->type()==TrackingRecHit::missing) { 00129 firstinvalid = j; 00130 LogTrace("TrackFitters") << "Found two consecutive missing hits. First invalid: " << firstinvalid; 00131 break; 00132 } 00133 } 00134 //reject all the hits after the last valid before two consecutive invalid (missing) hits 00135 //hits are sorted in the same order as in the track candidate FIXME?????? 00136 myHits.erase(myHits.begin()+firstinvalid,myHits.end()); 00137 } 00138 } 00139 } 00140 if ( hasoutliers && // otherwise there won't be a 'next' loop where tmp_first could be useful 00141 !rejectTracksFlag && // othewrise we won't ever need tmp_first 00142 tmp_first.empty() ) { // only at first step 00143 smoothed.swap(tmp_first); 00144 } 00145 00146 } while(hasoutliers); 00147 if (!smoothed.empty()) { 00148 00149 if (noInvalidHitsBeginEnd) { 00150 00151 // discard latest dummy measurements 00152 if (!smoothed[0].empty() && !smoothed[0].lastMeasurement().recHit()->isValid()) 00153 LogTrace("TrackFitters") << "Last measurement is invalid"; 00154 while (!smoothed[0].empty() && !smoothed[0].lastMeasurement().recHit()->isValid()) smoothed[0].pop(); 00155 00156 //remove the invalid hits at the begin of the trajectory 00157 if(!smoothed[0].firstMeasurement().recHit()->isValid()) { 00158 LogTrace("TrackFitters") << "First measurement is invalid"; 00159 Trajectory tmpTraj(smoothed[0].seed(),smoothed[0].direction()); 00160 Trajectory::DataContainer meas = smoothed[0].measurements(); 00161 00162 for (Trajectory::DataContainer::iterator it=meas.begin();it!=meas.end();++it) { 00163 if (!it->recHit()->isValid()) continue; 00164 else { 00165 LogTrace("TrackFitters") << "First valid measurement is: " << it-meas.begin(); 00166 const KFTrajectorySmoother* myKFSmoother = dynamic_cast<const KFTrajectorySmoother*>(smoother()); 00167 if (!myKFSmoother) throw cms::Exception("TrackFitters") << "trying to use outliers rejection with a smoother different from KFTrajectorySmoother. Please disable outlier rejection."; 00168 const MeasurementEstimator* estimator = myKFSmoother->estimator(); 00169 for (Trajectory::DataContainer::iterator itt=it;itt!=meas.end();++itt) { 00170 if (itt->recHit()->isValid()) 00171 tmpTraj.push(*itt,estimator->estimate(itt->backwardPredictedState(),*itt->recHit()).second);//chi2!!!!!! 00172 else tmpTraj.push(*itt); 00173 } 00174 break; 00175 } 00176 } 00177 smoothed.clear(); 00178 smoothed.push_back(tmpTraj); 00179 00180 } 00181 } 00182 00183 LogTrace("TrackFitters") << "end: returning smoothed trajectory with chi2=" 00184 << smoothed[0].chiSquared() ; 00185 00186 //LogTrace("TrackFitters") << "dump hits before return"; 00187 //Trajectory::DataContainer meas = smoothed[0].measurements(); 00188 //for (Trajectory::DataContainer::iterator it=meas.begin();it!=meas.end();++it) { 00189 //LogTrace("TrackFitters") << "hit #" << meas.end()-it-1 << " validity=" << it->recHit()->isValid() 00190 //<< " det=" << it->recHit()->geographicalId().rawId(); 00191 //} 00192 00193 } 00194 return smoothed; 00195 }
vector< Trajectory > KFFittingSmoother::fit | ( | const Trajectory & | t | ) | const [virtual] |
Implements TrajectoryFitter.
Definition at line 19 of file KFFittingSmoother.cc.
References TrajectoryFitter::fit(), fitter(), Trajectory::isValid(), and smoothingStep().
00019 { 00020 vector<Trajectory> smoothed; 00021 if(t.isValid()) { 00022 vector<Trajectory> fitted = fitter()->fit(t); 00023 smoothingStep(fitted, smoothed); 00024 } 00025 return smoothed; 00026 }
const TrajectoryFitter* KFFittingSmoother::fitter | ( | void | ) | const [inline] |
Definition at line 47 of file KFFittingSmoother.h.
References theFitter.
Referenced by fit(), and KalmanAlignmentAlgorithm::initializeAlignmentSetups().
00047 {return theFitter;}
const TrajectorySmoother* KFFittingSmoother::smoother | ( | ) | const [inline] |
Definition at line 48 of file KFFittingSmoother.h.
References theSmoother.
Referenced by fit(), and KalmanAlignmentAlgorithm::initializeAlignmentSetups().
00048 {return theSmoother;}
void KFFittingSmoother::smoothingStep | ( | std::vector< Trajectory > & | fitted, | |
std::vector< Trajectory > & | smoothed | |||
) | const [private] |
Referenced by fit().
bool KFFittingSmoother::noInvalidHitsBeginEnd [private] |
bool KFFittingSmoother::rejectTracksFlag [private] |
double KFFittingSmoother::theEstimateCut [private] |
const TrajectoryFitter* KFFittingSmoother::theFitter [private] |
Definition at line 56 of file KFFittingSmoother.h.
Referenced by clone(), fitter(), and ~KFFittingSmoother().
int KFFittingSmoother::theMinNumberOfHits [private] |
const TrajectorySmoother* KFFittingSmoother::theSmoother [private] |
Definition at line 57 of file KFFittingSmoother.h.
Referenced by clone(), smoother(), and ~KFFittingSmoother().
Definition at line 65 of file KFFittingSmoother.h.