15 #include <dataharvester/Writer.h>
21 struct CompareTwoTracks {
33 const float initialError = 10000;
35 ret(0,0)=initialError;
36 ret(1,1)=initialError;
37 ret(2,2)=initialError;
56 static const GlobalError err( initLinePointError() );
60 struct DistanceToRefPoint {
61 DistanceToRefPoint (
const GlobalPoint & ref ) : theRef ( ref ) {}
63 bool operator() (
const RefCountedVertexTrack & v1,
const RefCountedVertexTrack & v2 )
65 return ( distance ( v1 ) < distance ( v2 ) );
68 float distance (
const RefCountedVertexTrack & v1 )
70 return ( v1->linearizedTrack()->track().initialFreeState().position() - theRef ).
mag2();
79 map < RefCountedLinearizedTrackState, int > ids;
82 int getId (
const RefCountedLinearizedTrackState &
r )
85 if ( ids.count(r) == 0 )
102 theLinP(linP.
clone()), theUpdator( updator.
clone()),
103 theSmoother ( smoother.
clone() ), theAssProbComputer( ann.
clone() ),
104 theComp ( crit.
clone() ), theLinTrkFactory ( ltsf.
clone() ),
105 gsfIntermediarySmoothing_(
false)
139 unsigned maxstep,
double weightthreshold )
159 if ( unstracks.size() < 2 )
161 LogError(
"RecoVertex|AdaptiveVertexFitter")
162 <<
"Supplied fewer than two tracks. Vertex is invalid.";
165 vector < reco::TransientTrack >
tracks = unstracks;
166 sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
170 VertexState lseed (linP, linPointError() );
171 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
173 VertexState seed (linP, fitError() );
174 return fit(vtContainer, seed,
false);
180 if ( tracks.size() < 2 )
182 LogError(
"RecoVertex|AdaptiveVertexFitter")
183 <<
"Supplied fewer than two tracks. Vertex is invalid.";
187 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
188 VertexState seed (linP, fitError() );
189 return fit(tracks, seed,
false);
195 if ( tracks.size() < 1 )
197 LogError(
"RecoVertex|AdaptiveVertexFitter")
198 <<
"Supplied no tracks. Vertex is invalid.";
201 VertexState beamSpotState(spot);
202 return fit(tracks, beamSpotState,
true );
214 if ( tracks.size() < 2 )
216 LogError(
"RecoVertex|AdaptiveVertexFitter")
217 <<
"Supplied fewer than two tracks. Vertex is invalid.";
221 VertexState seed (linPoint, linPointError() );
222 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
223 VertexState fitseed (linPoint, fitError() );
224 return fit(vtContainer, fitseed,
false);
236 if ( unstracks.size() < 1 )
238 LogError(
"RecoVertex|AdaptiveVertexFitter")
239 <<
"Supplied no tracks. Vertex is invalid.";
243 VertexState beamSpotState(beamSpot);
244 vector<RefCountedVertexTrack> vtContainer;
246 vector < reco::TransientTrack >
tracks = unstracks;
247 sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
249 if (tracks.size() > 1) {
252 VertexState lpState(linP, linPointError() );
259 return fit(vtContainer, beamSpotState,
true);
273 if ( tracks.size() < 1 )
275 LogError(
"RecoVertex|AdaptiveVertexFitter")
276 <<
"Supplied no tracks. Vertex is invalid.";
279 VertexState seed (priorPos, priorError);
280 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
281 return fit( vtContainer, seed,
true );
290 const vector<RefCountedVertexTrack> &
tracks,
294 if ( tracks.size() < 1 )
296 LogError(
"RecoVertex|AdaptiveVertexFitter")
297 <<
"Supplied no tracks. Vertex is invalid.";
300 VertexState seed (priorPos, priorError);
301 return fit(tracks, seed,
true);
312 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
314 const VertexState & seed )
const
317 vector<RefCountedLinearizedTrackState> lTracks;
318 for(vector<reco::TransientTrack>::const_iterator
i = tracks.begin();
319 i != tracks.end(); ++
i )
324 lTracks.push_back(lTrData);
326 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
327 <<
"Exception " << e.what() <<
" in ::linearizeTracks."
328 <<
"Your future vertex has just lost a track.";
339 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
341 const vector<RefCountedVertexTrack> &
tracks,
346 vector<RefCountedLinearizedTrackState> lTracks;
347 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
348 i != tracks.end();
i++)
357 lTracks.push_back(lTrData);
359 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
360 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
361 <<
"Will not relinearize this track.";
362 lTracks.push_back ( (**i).linearizedTrack() );
379 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
383 if ( weight < 1
e-20 )
391 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
393 const vector<RefCountedLinearizedTrackState> & lTracks,
401 vector<RefCountedVertexTrack> finalTracks;
406 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
407 = lTracks.begin();
i != lTracks.end();
i++)
411 pair < bool, double > chi2Res (
false, 0. );
416 if (!chi2Res.first) {
418 LogInfo(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
424 RefCountedVertexTrack vTrData
428 map < string, dataharvester::MultiType >
m;
438 finalTracks.push_back(vTrData);
440 sort ( finalTracks.begin(), finalTracks.end(),
441 DistanceToRefPoint ( vertex.
position() ) );
446 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
448 const vector<RefCountedLinearizedTrackState> & lTracks,
449 const VertexState & seed )
const
457 vector<RefCountedVertexTrack> finalTracks;
462 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
463 = lTracks.begin();
i != lTracks.end();
i++)
467 pair<bool, double> chi2Res =
theComp->
estimate ( seedvtx, *
i, std::distance(lTracks.begin(),
i) );
468 if (!chi2Res.first) {
470 LogInfo (
"AdaptiveVertexFitter" ) <<
"When weighting a track, chi2 calculation failed;"
471 <<
" will add with w=0.";
475 RefCountedVertexTrack vTrData
478 map < string, dataharvester::MultiType >
m;
487 finalTracks.push_back(vTrData);
497 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
499 const vector<RefCountedVertexTrack> &
tracks,
502 vector<RefCountedLinearizedTrackState> lTracks;
503 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
504 i != tracks.end();
i++)
506 lTracks.push_back((**i).linearizedTrack());
519 const VertexState & priorSeed,
520 bool withPrior)
const
525 vector<RefCountedVertexTrack> initialTracks;
526 GlobalPoint priorVertexPosition = priorSeed.position();
534 priorVertexPosition,priorVertexError,initialTracks,0);
539 vector<RefCountedVertexTrack> globalVTracks ( tracks.size() );
541 partial_sort_copy ( tracks.begin(), tracks.end(),
542 globalVTracks.begin(), globalVTracks.end(), DistanceToRefPoint ( priorSeed.position() ) );
545 int lpStep = 0;
int step = 0;
583 for(vector<RefCountedVertexTrack>::const_iterator
i
584 = globalVTracks.begin();
i != globalVTracks.end();
i++)
586 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *
i );
587 else nVertex = fVertex;
594 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
598 LogInfo (
"AdaptiveVertexFitter" ) <<
"Vertex candidate just took off to " << nVertex.
position()
599 <<
"! Will discard this update!";
611 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
612 <<
"The updator returned an invalid vertex when adding track "
613 <<
i-globalVTracks.begin()
614 <<
".\n Your vertex might just have lost one good track.";
617 previousPosition = newPosition;
619 returnVertex = fVertex;
635 <<
" Fitted vertex is invalid.";
640 map < string, dataharvester::MultiType >
m;
virtual bool isAnnealed() const =0
T getParameter(std::string const &) 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())
VertexState const & vertexState() const
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
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
AdaptiveVertexFitter * clone() const
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
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
TrajectoryStateOnSurface impactPointState() const
virtual ~AdaptiveVertexFitter()
volatile std::atomic< bool > shutdown_flag false
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_