24 struct KFFittingSmootherParam {
27 theEstimateCut(conf.getParameter<double>(
"EstimateCut"))
28 ,theMaxFractionOutliers(conf.getParameter<double>(
"MaxFractionOutliers"))
29 ,theMaxNumberOfOutliers(conf.getParameter<int>(
"MaxNumberOfOutliers"))
30 ,theNoOutliersBeginEnd(conf.getParameter<bool>(
"NoOutliersBeginEnd"))
31 ,theMinDof(conf.getParameter<int>(
"MinDof"))
32 ,theMinNumberOfHits(conf.getParameter<int>(
"MinNumberOfHits"))
33 ,rejectTracksFlag(conf.getParameter<bool>(
"RejectTracks"))
34 ,breakTrajWith2ConsecutiveMissing(conf.getParameter<bool>(
"BreakTrajWith2ConsecutiveMissing"))
35 ,noInvalidHitsBeginEnd(conf.getParameter<bool>(
"NoInvalidHitsBeginEnd"))
38 double theEstimateCut;
40 float theMaxFractionOutliers;
41 int theMaxNumberOfOutliers;
42 bool theNoOutliersBeginEnd;
45 int theMinNumberOfHits;
46 bool rejectTracksFlag;
47 bool breakTrajWith2ConsecutiveMissing;
48 bool noInvalidHitsBeginEnd;
62 KFFittingSmootherParam(conf),
63 theFitter(aFitter.
clone()),
64 theSmoother(aSmoother.
clone())
70 desc.
add<
double>(
"EstimateCut",-1);
71 desc.
add<
double>(
"MaxFractionOutliers",0.3);
72 desc.add<
int>(
"MaxNumberOfOutliers",3);
73 desc.add<
int>(
"MinDof",2);
74 desc.add<
bool>(
"NoOutliersBeginEnd",
false);
75 desc.add<
int>(
"MinNumberOfHits",5);
76 desc.add<
bool>(
"RejectTracks",
true);
77 desc.add<
bool>(
"BreakTrajWith2ConsecutiveMissing",
true);
78 desc.add<
bool>(
"NoInvalidHitsBeginEnd",
true);
79 desc.add<
double>(
"LogPixelProbabilityCut",0);
86 const RecHitContainer& hits,
89 const RecHitContainer& hits, fitType
type)
const override;
94 std::unique_ptr<TrajectoryFitter>
clone()
const override {
95 return std::unique_ptr<TrajectoryFitter>(
104 theFitter->setHitCloner(hc);
105 theSmoother->setHitCloner(hc);
110 KFFittingSmootherParam
const & other) :
111 KFFittingSmootherParam(other),
112 theFitter(aFitter.
clone()),
113 theSmoother(aSmoother.
clone())
119 if (theEstimateCut>0) {
121 while (!fitted.empty() &&
122 ( !fitted.lastMeasurement().recHitR().isValid()
123 || ( fitted.lastMeasurement().recHitR().det()!=
nullptr && fitted.lastMeasurement().estimate()>theEstimateCut)
127 if (fitted.foundHits() < theMinNumberOfHits )
return Trajectory();
129 return theSmoother->trajectory(fitted);
134 const std::unique_ptr<TrajectoryFitter> theFitter;
135 const std::unique_ptr<TrajectorySmoother> theSmoother;
139 static bool checkForNans(
const Trajectory &theTraj);
149 #define DPRINT(x) std::cout << x << ": "
150 #define PRINT std::cout
152 #define DPRINT(x) LogTrace(x)
153 #define PRINT LogTrace("")
161 return smoothingStep(theFitter->fitOne(t,type));
164 bool KFFittingSmoother::checkForNans(
const Trajectory & theTraj)
168 for (
auto const & tm : vtm) {
170 auto const &
v = tm.updatedState ().localParameters ().vector();
172 auto const &
m = tm.updatedState ().curvilinearError ().matrix();
173 for (
int i=0;i<5;++
i)
180 const RecHitContainer& hits,
184 LogDebug(
"TrackFitters") <<
"In KFFittingSmoother::fit";
188 RecHitContainer myHits = hits;
192 Trajectory smoothed = smoothingStep(theFitter->fitOne(aSeed, myHits, firstPredTsos));
199 for (
unsigned int j=0;
j<myHits.size();
j++) {
200 if (myHits[
j]->det())
201 LogTrace(
"TrackFitters") <<
"hit #:" <<
j+1 <<
" rawId=" << myHits[
j]->det()->geographicalId().rawId()
202 <<
" validity=" << myHits[
j]->isValid();
204 LogTrace(
"TrackFitters") <<
"hit #:" <<
j+1 <<
" Hit with no Det information";
210 if ( !smoothed.
isValid() || (hasNaN = !checkForNans(smoothed)) || ( smoothed.
foundHits() < theMinNumberOfHits ) ) {
212 if ( smoothed.
foundHits() < theMinNumberOfHits )
LogTrace(
"TrackFitters") <<
"smoothed.foundHits()<theMinNumberOfHits";
213 DPRINT(
"TrackFitters") <<
"smoothed invalid => trajectory rejected with nhits/chi2 " << smoothed.
foundHits() <<
'/' << smoothed.
chiSquared() <<
"\n";
214 if (rejectTracksFlag) {
218 DPRINT(
"TrackFitters") <<
"smoothed invalid => returning orignal trajectory with nhits/chi2 " << smoothed.
foundHits() <<
'/' << smoothed.
chiSquared() <<
"\n";
224 LogTrace(
"TrackFitters") <<
"dump hits after smoothing";
226 for (Trajectory::DataContainer::iterator it=meas.begin();it!=meas.end();++it) {
227 LogTrace(
"TrackFitters") <<
"hit #" << meas.end()-it-1 <<
" validity=" << it->recHit()->isValid()
228 <<
" det=" << it->recHit()->geographicalId().rawId();
234 DPRINT(
"TrackFitters") <<
"lost hits. before/after: " << myHits.size() <<
'/' << smoothed.
measurements().size()<<
"\n";
236 if ( theEstimateCut <= 0)
break;
247 if (tm.estimate()>theEstimateCut
248 && tm.recHitR().det()!=
nullptr
250 if (ind<lastValid && tm.recHitR().det()!=
nullptr && tm.recHitR().isValid()) lastValid=ind;
256 DPRINT(
"TrackFitters") <<
"size/found/outliers list " << smoothed.
measurements().size() <<
'/' << smoothed.
foundHits() <<
' ' << nbad <<
": ";
257 for (
auto i=0U; i<nbad; ++
i)
PRINT << bad[i] <<
',';
264 int(nbad)>theMaxNumberOfOutliers ||
265 float(nbad) > theMaxFractionOutliers*
float(smoothed.
foundHits())
267 DPRINT(
"TrackFitters") <<
"smoothed low quality => trajectory with nhits/chi2 " << smoothed.
foundHits() <<
'/' << smoothed.
chiSquared() <<
"\n";
268 PRINT <<
"try to remove " << lastValid << std::endl;
285 bad[nbad++]=lastValid;
300 auto NHits = myHits.size();
304 for (
auto i=0U; i<nbad; ++
i) {
306 assert(myHits[
j]->geographicalId() == smoothed.
measurements()[bad[
i]].recHitR().geographicalId());
307 auto removedHit = myHits[
j];
309 smoothedCand[
i] = smoothingStep(theFitter->fitOne(aSeed, myHits, firstPredTsos));
310 myHits[
j] = removedHit;
311 if (smoothedCand[i].isValid() && smoothedCand[
i].chiSquared()< minChi2) {
312 minChi2 = smoothedCand[
i].chiSquared();
318 DPRINT(
"TrackFitters") <<
"New trajectories all invalid"<<
"\n";
322 DPRINT(
"TrackFitters") <<
"outlier removed " << bad[loc] <<
'/' << minChi2 <<
" was " << smoothed.
chiSquared()<<
"\n";
326 DPRINT(
"TrackFitters") <<
"removing outlier makes chi2 worse " << minChi2 <<
'/' << smoothed.
chiSquared() <<
"\nOri: ";
328 PRINT << tm.recHitR().geographicalId() <<
'/' << tm.estimate() <<
' ';
330 for (
auto const & tm : smoothedCand[loc].measurements() )
331 PRINT << tm.recHitR().geographicalId() <<
'/' << tm.estimate() <<
' ';
343 DPRINT(
"TrackFitters") <<
"new trajectory with nhits/chi2 " << smoothed.
foundHits() <<
'/' << smoothed.
chiSquared() <<
"\n";
349 if ( breakTrajWith2ConsecutiveMissing ) {
350 unsigned int firstinvalid = myHits.size();
351 for (
unsigned int j=0;
j<myHits.size()-1; ++
j )
355 && ( (myHits[
j ]->geographicalId().rawId()&(~3)) != (myHits[
j+1]->geographicalId().rawId()&(~3) ) )
359 DPRINT(
"TrackFitters") <<
"Found two consecutive missing hits. First invalid: " << firstinvalid <<
"\n";
366 if (firstinvalid != myHits.size()) {
367 myHits.erase(myHits.begin()+firstinvalid,myHits.end());
368 smoothed = smoothingStep(theFitter->fitOne(aSeed, myHits, firstPredTsos));
377 if ( noInvalidHitsBeginEnd
382 LogTrace(
"TrackFitters") <<
"Last measurement is invalid";
389 LogTrace(
"TrackFitters") <<
"First measurement is in`valid";
392 auto it = meas.begin();
393 for ( ; it!=meas.end(); ++it )
394 if ( it->recHitR().isValid() )
break;
397 for (
auto itt=it+1; itt!=meas.end();++itt)
406 LogTrace(
"TrackFitters") <<
"end: returning smoothed trajectory with chi2="
424 const RecHitContainer& hits,fitType type)
const{
427 "KFFittingSmoother::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
bool empty() const
True if trajectory has no measurements.
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
PropagationDirection const & direction() const
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
virtual void setHitCloner(TkCloner const *)=0
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
TrajectoryMeasurement const & lastMeasurement() const
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
ParameterDescriptionBase * add(U const &iLabel, T const &value)
TrajectoryMeasurement const & firstMeasurement() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
ConstRecHitPointer::element_type const & recHitR() const
#define declareDynArray(T, n, x)