15 #include <dataharvester/Writer.h> 21 void sortTracksByPt(std::vector<reco::TransientTrack> & cont) {
23 float pt2[
s];
int ind[
s];
int i=0;
24 for (
auto const & tk : cont) { ind[
i]=
i; pt2[i++] = tk.impactPointState().globalMomentum().perp2();}
27 std::sort(ind,ind+
s, [p_pt2](
int i,
int j){
return p_pt2[
i]>p_pt2[j];} );
28 std::vector<reco::TransientTrack>
tmp; tmp.reserve(
s);
29 for (
auto i=0
U; i<
s; ++
i) tmp.emplace_back(
std::move( cont[ind[i]] ) );
39 const float initialError = 10000;
41 ret(0,0)=initialError;
42 ret(1,1)=initialError;
43 ret(2,2)=initialError;
53 ret(0,0)=.3; ret(1,1)=.3; ret(2,2)=3.;
58 GlobalError const linPointError = initLinePointError();
64 sortByDistanceToRefPoint (std::vector<RefCountedVertexTrack> & cont,
const GlobalPoint ref ) {
66 float d2[
s];
int ind[
s];
int i=0;
67 for (
auto const & tk : cont) { ind[
i]=
i; d2[i++] = (tk->linearizedTrack()->track().initialFreeState().position() - ref ).
mag2();}
70 std::sort(ind,ind+s, [p_d2](
int i,
int j){
return p_d2[
i]<p_d2[j];} );
71 std::vector<RefCountedVertexTrack>
tmp; tmp.reserve(s);
72 for (
auto i=0
U; i<
s; ++
i) tmp.emplace_back(
std::move( cont[ind[i]] ) );
80 map < RefCountedLinearizedTrackState, int >
ids;
83 int getId (
const RefCountedLinearizedTrackState &
r )
86 if ( ids.count(r) == 0 )
103 theLinP(linP.
clone()), theUpdator( updator.
clone()),
104 theSmoother ( smoother.
clone() ), theAssProbComputer( ann.
clone() ),
105 theComp ( crit.
clone() ), theLinTrkFactory ( ltsf.
clone() ),
106 gsfIntermediarySmoothing_(
false)
160 if ( unstracks.size() < 2 )
162 LogError(
"RecoVertex|AdaptiveVertexFitter")
163 <<
"Supplied fewer than two tracks. Vertex is invalid.";
166 vector < reco::TransientTrack >
tracks = unstracks;
167 sortTracksByPt( tracks);
172 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
175 return fit(vtContainer, seed,
false);
181 if ( tracks.size() < 2 )
183 LogError(
"RecoVertex|AdaptiveVertexFitter")
184 <<
"Supplied fewer than two tracks. Vertex is invalid.";
188 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
190 return fit(tracks, seed,
false);
196 if ( tracks.empty() )
198 LogError(
"RecoVertex|AdaptiveVertexFitter")
199 <<
"Supplied no tracks. Vertex is invalid.";
203 return fit(tracks, beamSpotState,
true );
215 if ( tracks.size() < 2 )
217 LogError(
"RecoVertex|AdaptiveVertexFitter")
218 <<
"Supplied fewer than two tracks. Vertex is invalid.";
223 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
225 return fit(vtContainer, fitseed,
false);
237 if ( unstracks.empty() )
239 LogError(
"RecoVertex|AdaptiveVertexFitter")
240 <<
"Supplied no tracks. Vertex is invalid.";
245 vector<RefCountedVertexTrack> vtContainer;
247 vector < reco::TransientTrack >
tracks = unstracks;
248 sortTracksByPt(tracks);
250 if (tracks.size() > 1) {
260 return fit(vtContainer, beamSpotState,
true);
274 if ( tracks.empty() )
276 LogError(
"RecoVertex|AdaptiveVertexFitter")
277 <<
"Supplied no tracks. Vertex is invalid.";
281 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
282 return fit( vtContainer, seed,
true );
291 const vector<RefCountedVertexTrack> &
tracks,
295 if ( tracks.empty() )
297 LogError(
"RecoVertex|AdaptiveVertexFitter")
298 <<
"Supplied no tracks. Vertex is invalid.";
302 return fit(tracks, seed,
true);
313 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
318 vector<RefCountedLinearizedTrackState> lTracks;
319 for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
320 i != tracks.end(); ++
i )
325 lTracks.push_back(lTrData);
327 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
328 <<
"Exception " << e.what() <<
" in ::linearizeTracks." 329 <<
"Your future vertex has just lost a track.";
340 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
342 const vector<RefCountedVertexTrack> &
tracks,
347 vector<RefCountedLinearizedTrackState> lTracks;
348 for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
349 i != tracks.end(); i++)
358 lTracks.push_back(lTrData);
360 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
361 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. " 362 <<
"Will not relinearize this track.";
363 lTracks.push_back ( (**i).linearizedTrack() );
380 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
384 if ( weight < 1
e-20 )
392 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
394 const vector<RefCountedLinearizedTrackState> & lTracks,
402 vector<RefCountedVertexTrack> finalTracks;
407 for(vector<RefCountedLinearizedTrackState>::const_iterator i
408 = lTracks.begin(); i != lTracks.end(); i++)
412 pair < bool, double > chi2Res (
false, 0. );
417 if (!chi2Res.first) {
419 LogInfo(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
425 RefCountedVertexTrack vTrData
429 map < string, dataharvester::MultiType >
m;
435 m[
"id"]=
getId ( *i );
439 finalTracks.push_back(vTrData);
441 sortByDistanceToRefPoint( finalTracks, vertex.
position() );
446 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
448 const vector<RefCountedLinearizedTrackState> & lTracks,
457 vector<RefCountedVertexTrack> finalTracks;
462 for(vector<RefCountedLinearizedTrackState>::const_iterator i
463 = lTracks.begin(); i != lTracks.end(); 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;
483 m[
"id"]=
getId ( *i );
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());
520 bool withPrior)
const 525 vector<RefCountedVertexTrack> initialTracks;
534 priorVertexPosition,priorVertexError,initialTracks,0);
537 std::vector<RefCountedVertexTrack> globalVTracks =
tracks;
539 sortByDistanceToRefPoint (globalVTracks, priorSeed.
position() );
542 int lpStep = 0;
int step = 0;
563 if ((previousPosition - newPosition).transverse() >
theMaxLPShift)
580 for(vector<RefCountedVertexTrack>::const_iterator i
581 = globalVTracks.begin(); i != globalVTracks.end(); i++)
583 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *i );
584 else nVertex = fVertex;
588 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
592 LogInfo (
"AdaptiveVertexFitter" ) <<
"Vertex candidate just took off to " << nVertex.
position()
593 <<
"! Will discard this update!";
605 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
606 <<
"The updator returned an invalid vertex when adding track " 607 << i-globalVTracks.begin()
608 <<
".\n Your vertex might just have lost one good track.";
611 previousPosition = newPosition;
613 returnVertex = fVertex;
629 <<
" Fitted vertex is invalid.";
634 map < string, dataharvester::MultiType >
m;
639 m[
"id"]=
getId ( *i );
T getParameter(std::string const &) const
virtual VertexUpdator * clone() const =0
virtual const AbstractLTSFactory * clone() const =0
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
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
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
virtual double weight(double chi2) const =0
GlobalPoint position() const
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
AdaptiveVertexFitter * clone() const override
virtual CachingVertex< N > smooth(const CachingVertex< N > &vertex) const =0
void setWeightThreshold(float w)
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
virtual bool isAnnealed() const =0
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
virtual LinearizationPointFinder * clone() const =0
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
virtual double currentTemp() const =0
VertexSmoother< 5 > * theSmoother
virtual AnnealingSchedule * clone() const =0
AnnealingSchedule * theAssProbComputer
virtual CachingVertex< N > add(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
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())
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
GlobalPoint position() const
std::vector< std::vector< double > > tmp
virtual void resetAnnealing()=0
double theWeightThreshold
GlobalError error() const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
~AdaptiveVertexFitter() override
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
virtual VertexSmoother * clone() const =0
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp
bool gsfIntermediarySmoothing_