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();}
25 std::sort(ind,ind+
s, [&](
int i,
int j){
return pt2[
i]>pt2[
j];} );
26 std::vector<reco::TransientTrack>
tmp; tmp.reserve(
s);
27 for (
auto i=0U; i<
s; ++
i) tmp.emplace_back(std::move( cont[ind[i]] ) );
37 const float initialError = 10000;
39 ret(0,0)=initialError;
40 ret(1,1)=initialError;
41 ret(2,2)=initialError;
56 GlobalError const linPointError = initLinePointError();
62 sortByDistanceToRefPoint (std::vector<RefCountedVertexTrack> & cont,
const GlobalPoint ref ) {
64 float d2[
s];
int ind[
s];
int i=0;
65 for (
auto const & tk : cont) { ind[
i]=
i; d2[i++] = (tk->linearizedTrack()->track().initialFreeState().position() - ref ).
mag2();}
66 std::sort(ind,ind+s, [&](
int i,
int j){
return d2[
i]<d2[
j];} );
67 std::vector<RefCountedVertexTrack>
tmp; tmp.reserve(s);
68 for (
auto i=0U; i<
s; ++
i) tmp.emplace_back(std::move( cont[ind[i]] ) );
76 map < RefCountedLinearizedTrackState, int > ids;
79 int getId (
const RefCountedLinearizedTrackState &
r )
82 if ( ids.count(r) == 0 )
99 theLinP(linP.
clone()), theUpdator( updator.
clone()),
100 theSmoother ( smoother.
clone() ), theAssProbComputer( ann.
clone() ),
101 theComp ( crit.
clone() ), theLinTrkFactory ( ltsf.
clone() ),
102 gsfIntermediarySmoothing_(
false)
136 unsigned maxstep,
double weightthreshold )
156 if ( unstracks.size() < 2 )
158 LogError(
"RecoVertex|AdaptiveVertexFitter")
159 <<
"Supplied fewer than two tracks. Vertex is invalid.";
162 vector < reco::TransientTrack >
tracks = unstracks;
163 sortTracksByPt( tracks);
168 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, lseed);
171 return fit(vtContainer, seed,
false);
177 if ( tracks.size() < 2 )
179 LogError(
"RecoVertex|AdaptiveVertexFitter")
180 <<
"Supplied fewer than two tracks. Vertex is invalid.";
184 GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
186 return fit(tracks, seed,
false);
192 if ( tracks.size() < 1 )
194 LogError(
"RecoVertex|AdaptiveVertexFitter")
195 <<
"Supplied no tracks. Vertex is invalid.";
199 return fit(tracks, beamSpotState,
true );
211 if ( tracks.size() < 2 )
213 LogError(
"RecoVertex|AdaptiveVertexFitter")
214 <<
"Supplied fewer than two tracks. Vertex is invalid.";
219 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
221 return fit(vtContainer, fitseed,
false);
233 if ( unstracks.size() < 1 )
235 LogError(
"RecoVertex|AdaptiveVertexFitter")
236 <<
"Supplied no tracks. Vertex is invalid.";
241 vector<RefCountedVertexTrack> vtContainer;
243 vector < reco::TransientTrack >
tracks = unstracks;
244 sortTracksByPt(tracks);
246 if (tracks.size() > 1) {
256 return fit(vtContainer, beamSpotState,
true);
270 if ( tracks.size() < 1 )
272 LogError(
"RecoVertex|AdaptiveVertexFitter")
273 <<
"Supplied no tracks. Vertex is invalid.";
277 vector<RefCountedVertexTrack> vtContainer =
linearizeTracks(tracks, seed);
278 return fit( vtContainer, seed,
true );
287 const vector<RefCountedVertexTrack> &
tracks,
291 if ( tracks.size() < 1 )
293 LogError(
"RecoVertex|AdaptiveVertexFitter")
294 <<
"Supplied no tracks. Vertex is invalid.";
298 return fit(tracks, seed,
true);
309 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
314 vector<RefCountedLinearizedTrackState> lTracks;
315 for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
316 i != tracks.end(); ++
i )
321 lTracks.push_back(lTrData);
323 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
324 <<
"Exception " << e.what() <<
" in ::linearizeTracks."
325 <<
"Your future vertex has just lost a track.";
336 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
338 const vector<RefCountedVertexTrack> &
tracks,
343 vector<RefCountedLinearizedTrackState> lTracks;
344 for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
345 i != tracks.end(); i++)
354 lTracks.push_back(lTrData);
356 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
357 <<
"Exception " << e.what() <<
" in ::relinearizeTracks. "
358 <<
"Will not relinearize this track.";
359 lTracks.push_back ( (**i).linearizedTrack() );
376 LogInfo(
"RecoVertex/AdaptiveVertexFitter") <<
"Weight " << weight <<
" > 1.0!";
380 if ( weight < 1
e-20 )
388 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
390 const vector<RefCountedLinearizedTrackState> & lTracks,
398 vector<RefCountedVertexTrack> finalTracks;
403 for(vector<RefCountedLinearizedTrackState>::const_iterator i
404 = lTracks.begin(); i != lTracks.end(); i++)
408 pair < bool, double > chi2Res (
false, 0. );
410 chi2Res =
theComp->
estimate ( vertex, *i, std::distance(lTracks.begin(),
i) );
413 if (!chi2Res.first) {
415 LogInfo(
"AdaptiveVertexFitter" ) <<
"When reweighting, chi2<0. Will add this track with w=0.";
421 RefCountedVertexTrack vTrData
425 map < string, dataharvester::MultiType >
m;
431 m[
"id"]=
getId ( *i );
435 finalTracks.push_back(vTrData);
437 sortByDistanceToRefPoint( finalTracks, vertex.
position() );
442 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
444 const vector<RefCountedLinearizedTrackState> & lTracks,
453 vector<RefCountedVertexTrack> finalTracks;
458 for(vector<RefCountedLinearizedTrackState>::const_iterator i
459 = lTracks.begin(); i != lTracks.end(); i++)
463 pair<bool, double> chi2Res =
theComp->
estimate ( seedvtx, *i, std::distance(lTracks.begin(),
i) );
464 if (!chi2Res.first) {
466 LogInfo (
"AdaptiveVertexFitter" ) <<
"When weighting a track, chi2 calculation failed;"
467 <<
" will add with w=0.";
471 RefCountedVertexTrack vTrData
474 map < string, dataharvester::MultiType >
m;
479 m[
"id"]=
getId ( *i );
483 finalTracks.push_back(vTrData);
493 vector<AdaptiveVertexFitter::RefCountedVertexTrack>
495 const vector<RefCountedVertexTrack> &
tracks,
498 vector<RefCountedLinearizedTrackState> lTracks;
499 for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
500 i != tracks.end(); i++)
502 lTracks.push_back((**i).linearizedTrack());
516 bool withPrior)
const
521 vector<RefCountedVertexTrack> initialTracks;
530 priorVertexPosition,priorVertexError,initialTracks,0);
533 std::vector<RefCountedVertexTrack> globalVTracks =
tracks;
535 sortByDistanceToRefPoint (globalVTracks, priorSeed.
position() );
538 int lpStep = 0;
int step = 0;
559 if ((previousPosition - newPosition).transverse() >
theMaxLPShift)
576 for(vector<RefCountedVertexTrack>::const_iterator i
577 = globalVTracks.begin(); i != globalVTracks.end(); i++)
579 if ((**i).weight() > 0.) nVertex =
theUpdator->
add( fVertex, *i );
580 else nVertex = fVertex;
584 if ( fabs ( nVertex.
position().
z() ) > 10000. ||
588 LogInfo (
"AdaptiveVertexFitter" ) <<
"Vertex candidate just took off to " << nVertex.
position()
589 <<
"! Will discard this update!";
601 LogInfo(
"RecoVertex/AdaptiveVertexFitter")
602 <<
"The updator returned an invalid vertex when adding track "
603 << i-globalVTracks.begin()
604 <<
".\n Your vertex might just have lost one good track.";
607 previousPosition = newPosition;
609 returnVertex = fVertex;
625 <<
" Fitted vertex is invalid.";
630 map < string, dataharvester::MultiType >
m;
635 m[
"id"]=
getId ( *i );
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
GlobalPoint position() const
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
std::vector< std::vector< double > > tmp
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()
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_