15 #include <dataharvester/Writer.h>
27 static bool once=
true;
31 static const float initialError = 10000;
33 ret(0,0)=initialError;
34 ret(1,1)=initialError;
35 ret(2,2)=initialError;
45 static bool once=
true;
59 struct DistanceToRefPoint {
60 DistanceToRefPoint (
const GlobalPoint & ref ) : theRef ( ref ) {}
62 bool operator() (
const RefCountedVertexTrack & v1,
const RefCountedVertexTrack & v2 )
64 return ( distance ( v1 ) < distance ( v2 ) );
67 float distance (
const RefCountedVertexTrack & v1 )
69 return ( v1->linearizedTrack()->track().initialFreeState().position() - theRef ).
mag2();
77 map < RefCountedLinearizedTrackState, int > ids;
80 int getId (
const RefCountedLinearizedTrackState &
r )
83 if ( ids.count(r) == 0 )
100 theLinP(linP.
clone()), theUpdator( updator.
clone()),
101 theSmoother ( smoother.
clone() ), theAssProbComputer( ann.
clone() ),
102 theComp ( crit.
clone() ), theLinTrkFactory ( ltsf.
clone() ),
103 gsfIntermediarySmoothing_(
false)
137 unsigned maxstep,
double weightthreshold )
157 if ( tracks.size() < 2 )
159 LogError(
"RecoVertex|AdaptiveVertexFitter")
160 <<
"Supplied fewer than two tracks. Vertex is invalid.";
167 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
170 return fit(vtContainer, seed,
false);
176 if ( tracks.size() < 2 )
178 LogError(
"RecoVertex|AdaptiveVertexFitter")
179 <<
"Supplied fewer than two tracks. Vertex is invalid.";
183 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
185 return fit(tracks, seed,
false);
191 if ( tracks.size() < 1 )
193 LogError(
"RecoVertex|AdaptiveVertexFitter")
194 <<
"Supplied no tracks. Vertex is invalid.";
198 return fit(tracks, beamSpotState,
true );
210 if ( tracks.size() < 2 )
212 LogError(
"RecoVertex|AdaptiveVertexFitter")
213 <<
"Supplied fewer than two tracks. Vertex is invalid.";
218 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
220 return fit(vtContainer, fitseed,
false);
232 if ( tracks.size() < 1 )
234 LogError(
"RecoVertex|AdaptiveVertexFitter")
235 <<
"Supplied no tracks. Vertex is invalid.";
240 vector<RefCountedVertexTrack> vtContainer;
242 if (tracks.size() > 1) {
252 return fit(vtContainer, beamSpotState,
true);
266 if ( tracks.size() < 1 )
268 LogError(
"RecoVertex|AdaptiveVertexFitter")
269 <<
"Supplied no tracks. Vertex is invalid.";
273 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
274 return fit( vtContainer, seed,
true );
283 const vector<RefCountedVertexTrack> &
tracks,
287 if ( tracks.size() < 1 )
289 LogError(
"RecoVertex|AdaptiveVertexFitter")
290 <<
"Supplied no tracks. Vertex is invalid.";
294 return fit(tracks, seed,
true);
305 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
310 vector<RefCountedLinearizedTrackState> lTracks;
311 for(vector<reco::TransientTrack>::const_iterator
i = tracks.begin();
312 i != tracks.end(); ++
i )
317 lTracks.push_back(lTrData);
320 <<
"Exception " << e.what() <<
" in ::linearizeTracks."
321 <<
"Your future vertex has just lost a track.";
332 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
334 const vector<RefCountedVertexTrack> &
tracks,
339 vector<RefCountedLinearizedTrackState> lTracks;
340 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
341 i != tracks.end();
i++)
350 lTracks.push_back(lTrData);
353 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
354 <<
"Will not relinearize this track.";
355 lTracks.push_back ( (**i).linearizedTrack() );
372 LogWarning(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
376 if ( weight < 1
e-20 )
384 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
386 const vector<RefCountedLinearizedTrackState> & lTracks,
393 vector<RefCountedVertexTrack> finalTracks;
398 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
399 = lTracks.begin();
i != lTracks.end();
i++)
403 if (!chi2Res.first) {
404 cout <<
"[AdaptiveVertexFitter] aie... vertex candidate is at " << vertex.
position() << endl;
405 LogWarning(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
411 RefCountedVertexTrack vTrData
415 map < string, dataharvester::MultiType >
m;
425 finalTracks.push_back(vTrData);
430 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
432 const vector<RefCountedLinearizedTrackState> & lTracks,
441 vector<RefCountedVertexTrack> finalTracks;
446 for(vector<RefCountedLinearizedTrackState>::const_iterator
i
447 = lTracks.begin();
i != lTracks.end();
i++)
452 if (!chi2Res.first) {
453 cout <<
"[AdaptiveVertexFitter] Aiee! " << endl;
454 LogWarning (
"AdaptiveVertexFitter" ) <<
"When weighting a track, chi2 calculation failed;"
455 <<
" will add with w=0.";
459 RefCountedVertexTrack vTrData
462 map < string, dataharvester::MultiType >
m;
471 finalTracks.push_back(vTrData);
481 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
483 const vector<RefCountedVertexTrack> &
tracks,
486 vector<RefCountedLinearizedTrackState> lTracks;
487 for(vector<RefCountedVertexTrack>::const_iterator
i = tracks.begin();
488 i != tracks.end();
i++)
490 lTracks.push_back((**i).linearizedTrack());
504 bool withPrior)
const
508 vector<RefCountedVertexTrack> initialTracks;
517 priorVertexPosition,priorVertexError,initialTracks,0);
522 vector<RefCountedVertexTrack> globalVTracks ( tracks.size() );
524 partial_sort_copy ( tracks.begin(), tracks.end(),
525 globalVTracks.begin(), globalVTracks.end(), DistanceToRefPoint ( priorSeed.
position() ) );
528 int lpStep = 0;
int step = 0;
555 for(vector<RefCountedVertexTrack>::const_iterator
i
556 = globalVTracks.begin();
i != globalVTracks.end();
i++)
558 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *
i );
559 else nVertex = fVertex;
566 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
570 LogWarning (
"AdaptiveVertexFitter" ) <<
"Help! Vertex candidate just took off to " << nVertex.
position()
571 <<
"! Will discard this update!";
584 <<
"The updator returned an invalid vertex when adding track "
585 <<
i-globalVTracks.begin()
586 <<
".\n Your vertex might just have lost one good track.";
589 previousPosition = newPosition;
591 returnVertex = fVertex;
607 <<
" Fitted vertex is invalid.";
612 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
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
T transverse() const
Another name for perp()
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)
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
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
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
DetId getId(const std::vector< std::string > &items)
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
virtual LinearizationPointFinder * clone() const =0
virtual VertexUpdator * clone() const =0
virtual void resetAnnealing()=0
double theWeightThreshold
GlobalError error() const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) 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_