26 vector<Trajectory> smoothed;
29 vector<Trajectory> fitted = fitter()->fit(t);
30 smoothingStep(fitted, smoothed);
38 const std::vector<TrajectoryMeasurement> & vtm = theTraj.
measurements();
39 for (std::vector<TrajectoryMeasurement>::const_iterator tm=vtm.begin(); tm!=vtm.end();tm++) {
54 LogDebug(
"TrackFitters") <<
"In KFFittingSmoother::fit";
59 bool has_low_pixel_prob;
62 double log_pixel_probability_lower_limit = -15.0;
65 vector<Trajectory> smoothed;
66 vector<Trajectory> tmp_first;
86 has_low_pixel_prob =
false;
88 double cut = theEstimateCut;
90 double log_pixel_prob_cut = theLogPixelProbabilityCut;
93 unsigned int outlierId = 0;
96 unsigned int low_pixel_prob_Id = 0;
97 const GeomDet* low_pixel_prob_Det = 0;
100 vector<Trajectory> fitted = fitter()->fit(aSeed, myHits, firstPredTsos);
103 smoothingStep(fitted, smoothed);
107 if ( smoothed.empty() )
109 if ( rejectTracksFlag )
111 LogTrace(
"TrackFitters") <<
"smoothed.size()==0 => trajectory rejected";
116 LogTrace(
"TrackFitters") <<
"smoothed.size()==0 => returning orignal trajectory" ;
117 smoothed.swap(tmp_first);
129 if (!checkForNans(smoothed[0])) {
135 if ( theEstimateCut > 0 || log_pixel_prob_cut > log_pixel_probability_lower_limit )
137 if ( smoothed[0].foundHits() < theMinNumberOfHits )
139 if ( rejectTracksFlag )
141 LogTrace(
"TrackFitters") <<
"smoothed[0].foundHits()<theMinNumberOfHits => trajectory rejected";
148 if ( !tmp_first.empty() )
150 tmp_first.swap(smoothed);
154 <<
"smoothed[0].foundHits()<theMinNumberOfHits => returning orignal trajectory with chi2="
155 << smoothed[0].chiSquared() ;
161 const std::vector<TrajectoryMeasurement> & vtm = smoothed[0].measurements();
163 double log_pixel_hit_probability = -999999.9;
165 for (std::vector<TrajectoryMeasurement>::const_iterator tm=vtm.begin(); tm!=vtm.end();tm++)
167 double estimate = tm->estimate();
170 if ( estimate > cut && theEstimateCut > 0 )
174 outlierId = tm->recHit()->geographicalId().rawId();
175 outlierDet = tm->recHit()->det();
181 if(log_pixel_prob_cut > log_pixel_probability_lower_limit){
189 unsigned int testSubDetID = ( hit->geographicalId().subdetId() );
191 if ( hit->isValid() &&
201 if ( !persistentHit == 0 &&
208 double pixel_hit_probability = (float)pixhit->clusterProbability(0);
210 if ( pixel_hit_probability < 0.0 )
211 LogDebug(
"From KFFittingSmoother.cc")
212 <<
"Wraning : Negative pixel hit probability !!!! Will set the probability to 10^{-15} !!!" << endl;
214 if ( pixel_hit_probability <= 0.0 || log10( pixel_hit_probability ) < log_pixel_probability_lower_limit )
215 log_pixel_hit_probability = log_pixel_probability_lower_limit;
217 log_pixel_hit_probability = log10( pixel_hit_probability );
219 int qbin = (int)pixhit->qBin();
221 if ( ( log_pixel_hit_probability < log_pixel_prob_cut ) &&
224 has_low_pixel_prob =
true;
225 log_pixel_prob_cut = log_pixel_hit_probability;
226 low_pixel_prob_Id = tm->recHit()->geographicalId().rawId();
227 low_pixel_prob_Det = tm->recHit()->det();
240 if ( hasoutliers || has_low_pixel_prob )
244 for (
unsigned int j=0;
j<myHits.size(); ++
j )
246 if ( hasoutliers && outlierId == myHits[
j]->geographicalId().rawId() )
248 LogTrace(
"TrackFitters") <<
"Rejecting outlier hit with estimate " << cut <<
" at position "
249 <<
j <<
" with rawId=" << myHits[
j]->geographicalId().rawId();
250 LogTrace(
"TrackFitters") <<
"The fit will be repeated without the outlier";
253 else if ( has_low_pixel_prob && low_pixel_prob_Id == myHits[
j]->geographicalId().rawId() )
255 LogTrace(
"TrackFitters") <<
"Rejecting low proability pixel hit with log_pixel_prob_cut = "
256 << log_pixel_prob_cut <<
" at position "
257 <<
j <<
" with rawId =" << myHits[
j]->geographicalId().rawId();
258 LogTrace(
"TrackFitters") <<
"The fit will be repeated without the outlier";
265 if ( breakTrajWith2ConsecutiveMissing )
267 unsigned int firstinvalid = myHits.size()-1;
268 for (
unsigned int j=0;
j<myHits.size()-1; ++
j )
274 LogTrace(
"TrackFitters") <<
"Found two consecutive missing hits. First invalid: " << firstinvalid;
281 myHits.erase(myHits.begin()+firstinvalid,myHits.end());
289 if ( ( hasoutliers ||
290 has_low_pixel_prob ) &&
294 smoothed.swap(tmp_first);
298 while ( hasoutliers || has_low_pixel_prob );
300 if ( !smoothed.empty() )
302 if ( noInvalidHitsBeginEnd )
305 if ( !smoothed[0].
empty() &&
306 !smoothed[0].lastMeasurement().recHit()->isValid() )
307 LogTrace(
"TrackFitters") <<
"Last measurement is invalid";
309 while ( !smoothed[0].
empty() &&
310 !smoothed[0].lastMeasurement().recHit()->isValid() )
314 if ( !smoothed[0].firstMeasurement().recHit()->isValid() )
316 LogTrace(
"TrackFitters") <<
"First measurement is invalid";
317 Trajectory tmpTraj(smoothed[0].seed(),smoothed[0].direction());
320 Trajectory::DataContainer::iterator it;
321 for ( it=meas.begin(); it!=meas.end(); ++it )
323 if ( !it->recHit()->isValid() )
327 tmpTraj.
push(*it,smoothed[0].chiSquared());
329 for (Trajectory::DataContainer::iterator itt=it+1; itt!=meas.end();++itt)
331 tmpTraj.
push(*itt,0);
335 smoothed.push_back(tmpTraj);
341 LogTrace(
"TrackFitters") <<
"end: returning smoothed trajectory with chi2="
342 << smoothed[0].chiSquared() ;
362 for(vector<Trajectory>::iterator it = fitted.begin(); it != fitted.end();
364 vector<Trajectory> mysmoothed = smoother()->trajectories(*it);
365 smoothed.insert(smoothed.end(), mysmoothed.begin(), mysmoothed.end());
367 LogDebug(
"TrackFitters") <<
"In KFFittingSmoother::smoothingStep "<<smoothed.size();
374 "KFFittingSmoother::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
376 return vector<Trajectory>();
virtual std::vector< Trajectory > fit(const Trajectory &t) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
bool checkForNans(const Trajectory &theTraj) const
Method to check that the trajectory has no NaN in the states and chi2.
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
void smoothingStep(std::vector< Trajectory > &fitted, std::vector< Trajectory > &smoothed) const
virtual ~KFFittingSmoother()
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Trajectory::RecHitContainer RecHitContainer
void push(const TrajectoryMeasurement &tm)
double chiSquared() const