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);
330 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
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);
363 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
364 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
365 <<
"Will not relinearize this track.";
366 lTracks.push_back ( (**i).linearizedTrack() );
383 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
387 if ( weight < 1
e-20 )
395 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
397 const vector<RefCountedLinearizedTrackState> & lTracks,
405 vector<RefCountedVertexTrack> finalTracks;
410 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
411 = lTracks.begin();
i != lTracks.end();
i++)
415 pair < bool, double > chi2Res (
false, 0. );
420 if (!chi2Res.first) {
422 LogInfo(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
428 RefCountedVertexTrack vTrData
432 map < string, dataharvester::MultiType >
m;
442 finalTracks.push_back(vTrData);
444 sort ( finalTracks.begin(), finalTracks.end(),
445 DistanceToRefPoint ( vertex.
position() ) );
450 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
452 const vector<RefCountedLinearizedTrackState> & lTracks,
461 vector<RefCountedVertexTrack> finalTracks;
466 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
467 = lTracks.begin();
i != lTracks.end();
i++)
471 pair<bool, double> chi2Res =
theComp->
estimate ( seedvtx, *
i, std::distance(lTracks.begin(),
i) );
472 if (!chi2Res.first) {
474 LogInfo (
"AdaptiveVertexFitter" ) <<
"When weighting a track, chi2 calculation failed;"
475 <<
" will add with w=0.";
479 RefCountedVertexTrack vTrData
482 map < string, dataharvester::MultiType >
m;
491 finalTracks.push_back(vTrData);
501 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
503 const vector<RefCountedVertexTrack> &
tracks,
506 vector<RefCountedLinearizedTrackState> lTracks;
507 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
508 i != tracks.end();
i++)
510 lTracks.push_back((**i).linearizedTrack());
524 bool withPrior)
const
529 vector<RefCountedVertexTrack> initialTracks;
538 priorVertexPosition,priorVertexError,initialTracks,0);
543 vector<RefCountedVertexTrack> globalVTracks ( tracks.size() );
545 partial_sort_copy ( tracks.begin(), tracks.end(),
546 globalVTracks.begin(), globalVTracks.end(), DistanceToRefPoint ( priorSeed.
position() ) );
549 int lpStep = 0;
int step = 0;
587 for(vector<RefCountedVertexTrack>::const_iterator
i
588 = globalVTracks.begin();
i != globalVTracks.end();
i++)
590 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *
i );
591 else nVertex = fVertex;
598 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
602 LogInfo (
"AdaptiveVertexFitter" ) <<
"Vertex candidate just took off to " << nVertex.
position()
603 <<
"! Will discard this update!";
615 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
616 <<
"The updator returned an invalid vertex when adding track "
617 <<
i-globalVTracks.begin()
618 <<
".\n Your vertex might just have lost one good track.";
621 previousPosition = newPosition;
623 returnVertex = fVertex;
639 <<
" Fitted vertex is invalid.";
644 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
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
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_