15 #include <dataharvester/Writer.h>
21 struct CompareTwoTracks {
33 static bool once=
true;
37 static const float initialError = 10000;
39 ret(0,0)=initialError;
40 ret(1,1)=initialError;
41 ret(2,2)=initialError;
51 static bool once=
true;
65 struct DistanceToRefPoint {
66 DistanceToRefPoint (
const GlobalPoint & ref ) : theRef ( ref ) {}
68 bool operator() (
const RefCountedVertexTrack & v1,
const RefCountedVertexTrack & v2 )
70 return ( distance ( v1 ) < distance ( v2 ) );
73 float distance (
const RefCountedVertexTrack & v1 )
75 return ( v1->linearizedTrack()->track().initialFreeState().position() - theRef ).
mag2();
83 map < RefCountedLinearizedTrackState, int > ids;
86 int getId (
const RefCountedLinearizedTrackState &
r )
89 if ( ids.count(r) == 0 )
106 theLinP(linP.
clone()), theUpdator( updator.
clone()),
107 theSmoother ( smoother.
clone() ), theAssProbComputer( ann.
clone() ),
108 theComp ( crit.
clone() ), theLinTrkFactory ( ltsf.
clone() ),
109 gsfIntermediarySmoothing_(
false)
143 unsigned maxstep,
double weightthreshold )
163 if ( unstracks.size() < 2 )
165 LogError(
"RecoVertex|AdaptiveVertexFitter")
166 <<
"Supplied fewer than two tracks. Vertex is invalid.";
169 vector < reco::TransientTrack >
tracks = unstracks;
170 sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
175 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
178 return fit(vtContainer, seed,
false);
184 if ( tracks.size() < 2 )
186 LogError(
"RecoVertex|AdaptiveVertexFitter")
187 <<
"Supplied fewer than two tracks. Vertex is invalid.";
191 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
193 return fit(tracks, seed,
false);
199 if ( tracks.size() < 1 )
201 LogError(
"RecoVertex|AdaptiveVertexFitter")
202 <<
"Supplied no tracks. Vertex is invalid.";
206 return fit(tracks, beamSpotState,
true );
218 if ( tracks.size() < 2 )
220 LogError(
"RecoVertex|AdaptiveVertexFitter")
221 <<
"Supplied fewer than two tracks. Vertex is invalid.";
226 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
228 return fit(vtContainer, fitseed,
false);
240 if ( unstracks.size() < 1 )
242 LogError(
"RecoVertex|AdaptiveVertexFitter")
243 <<
"Supplied no tracks. Vertex is invalid.";
248 vector<RefCountedVertexTrack> vtContainer;
250 vector < reco::TransientTrack >
tracks = unstracks;
251 sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
253 if (tracks.size() > 1) {
263 return fit(vtContainer, beamSpotState,
true);
277 if ( tracks.size() < 1 )
279 LogError(
"RecoVertex|AdaptiveVertexFitter")
280 <<
"Supplied no tracks. Vertex is invalid.";
284 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
285 return fit( vtContainer, seed,
true );
294 const vector<RefCountedVertexTrack> &
tracks,
298 if ( tracks.size() < 1 )
300 LogError(
"RecoVertex|AdaptiveVertexFitter")
301 <<
"Supplied no tracks. Vertex is invalid.";
305 return fit(tracks, seed,
true);
316 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
321 vector<RefCountedLinearizedTrackState> lTracks;
322 for(vector<reco::TransientTrack>::const_iterator
i = tracks.begin();
323 i != tracks.end(); ++
i )
328 lTracks.push_back(lTrData);
331 <<
"Exception " << e.what() <<
" in ::linearizeTracks."
332 <<
"Your future vertex has just lost a track.";
343 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
345 const vector<RefCountedVertexTrack> &
tracks,
350 vector<RefCountedLinearizedTrackState> lTracks;
351 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
352 i != tracks.end();
i++)
361 lTracks.push_back(lTrData);
364 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
365 <<
"Will not relinearize this track.";
366 lTracks.push_back ( (**i).linearizedTrack() );
383 LogWarning(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
387 if ( weight < 1e-20 )
395 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
397 const vector<RefCountedLinearizedTrackState> & lTracks,
404 vector<RefCountedVertexTrack> finalTracks;
409 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
410 = lTracks.begin();
i != lTracks.end();
i++)
414 if (!chi2Res.first) {
415 cout <<
"[AdaptiveVertexFitter] aie... vertex candidate is at " << vertex.
position() << endl;
416 LogWarning(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
422 RefCountedVertexTrack vTrData
426 map < string, dataharvester::MultiType >
m;
436 finalTracks.push_back(vTrData);
438 sort ( finalTracks.begin(), finalTracks.end(),
439 DistanceToRefPoint ( vertex.
position() ) );
443 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
445 const vector<RefCountedLinearizedTrackState> & lTracks,
454 vector<RefCountedVertexTrack> finalTracks;
459 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
460 = lTracks.begin();
i != lTracks.end();
i++)
465 if (!chi2Res.first) {
466 cout <<
"[AdaptiveVertexFitter] Aiee! " << endl;
467 LogWarning (
"AdaptiveVertexFitter" ) <<
"When weighting a track, chi2 calculation failed;"
468 <<
" will add with w=0.";
472 RefCountedVertexTrack vTrData
475 map < string, dataharvester::MultiType >
m;
484 finalTracks.push_back(vTrData);
494 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
496 const vector<RefCountedVertexTrack> &
tracks,
499 vector<RefCountedLinearizedTrackState> lTracks;
500 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
501 i != tracks.end();
i++)
503 lTracks.push_back((**i).linearizedTrack());
517 bool withPrior)
const
521 vector<RefCountedVertexTrack> initialTracks;
530 priorVertexPosition,priorVertexError,initialTracks,0);
535 vector<RefCountedVertexTrack> globalVTracks ( tracks.size() );
537 partial_sort_copy ( tracks.begin(), tracks.end(),
538 globalVTracks.begin(), globalVTracks.end(), DistanceToRefPoint ( priorSeed.
position() ) );
541 int lpStep = 0;
int step = 0;
568 for(vector<RefCountedVertexTrack>::const_iterator
i
569 = globalVTracks.begin();
i != globalVTracks.end();
i++)
571 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *
i );
572 else nVertex = fVertex;
579 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
583 LogWarning (
"AdaptiveVertexFitter" ) <<
"Vertex candidate just took off to " << nVertex.
position()
584 <<
"! Will discard this update!";
597 <<
"The updator returned an invalid vertex when adding track "
598 <<
i-globalVTracks.begin()
599 <<
".\n Your vertex might just have lost one good track.";
602 previousPosition = newPosition;
604 returnVertex = fVertex;
620 <<
" Fitted vertex is invalid.";
625 map < string, dataharvester::MultiType >
m;
virtual bool isAnnealed() const =0
T getParameter(std::string const &) const
VertexState vertexState() const
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
LinearizationPointFinder * theLinP
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
static unsigned int getId(void)
VertexUpdator< 5 > * theUpdator
virtual AnnealingSchedule * clone() const =0
virtual VertexSmoother * clone() const =0
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
virtual const AbstractLTSFactory * clone() const =0
GlobalPoint position() const
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
AdaptiveVertexFitter * clone() const
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
void setWeightThreshold(float w)
virtual CachingVertex< N > add(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
virtual double currentTemp() const =0
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
double getWeight(float chi2) const
AdaptiveVertexFitter(const AnnealingSchedule &ann=GeometricAnnealing(), const LinearizationPointFinder &linP=DefaultLinearizationPointFinder(), const VertexUpdator< 5 > &updator=KalmanVertexUpdator< 5 >(), const VertexTrackCompatibilityEstimator< 5 > &estor=KalmanVertexTrackCompatibilityEstimator< 5 >(), const VertexSmoother< 5 > &smoother=DummyVertexSmoother< 5 >(), const AbstractLTSFactory< 5 > <sf=LinearizedTrackStateFactory())
virtual CachingVertex< N > smooth(const CachingVertex< N > &vertex) const =0
GlobalPoint position() const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
GlobalVector globalMomentum() const
virtual LinearizationPointFinder * clone() const =0
virtual VertexUpdator * clone() const =0
T transverse() const
Another name for perp()
virtual void resetAnnealing()=0
double theWeightThreshold
GlobalError error() const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
TrajectoryStateOnSurface impactPointState() const
virtual ~AdaptiveVertexFitter()
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
virtual double weight(double chi2) const =0
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp
bool gsfIntermediarySmoothing_