16 #ifdef MVFHarvestingDebug 17 #include "Vertex/VertexSimpleVis/interface/PrimitivesHarvester.h" 32 static const int ret = 0;
37 double minWeightFraction()
43 static const float ret = 1
e-6;
48 bool discardLightWeights()
50 static const bool ret =
true;
68 vector<RefCountedVertexTrack> (), 0.0 );
71 double validWeight (
double weight )
75 cout <<
"[MultiVertexFitter] weight=" << weight <<
"??" << endl;
81 cout <<
"[MultiVertexFitter] weight=" << weight <<
"??" << endl;
90 theAssComp->resetAnnealing();
93 theVertexStates.clear();
103 if ( tracks.size() > 1 )
106 theSeeder->getLinearizationPoint ( tracks ) );
109 for ( vector< TransientTrack >::const_iterator
track=tracks.begin();
112 theWeights[*
track][snr]=1.;
113 theTracks.push_back ( *
track );
121 for ( vector< reco::TransientTrack >::const_iterator
i=tracks.begin();
122 i!=tracks.end() ; ++
i )
124 thePrimaries.insert ( *
i );
132 return theVertexStateNr++;
143 vector < RefCountedVertexTrack> newTracks;
145 for ( vector< TrackAndWeight >::const_iterator
track=tracks.begin();
148 double weight = validWeight (
track->second );
154 theCache.linTrack ( pos,
track->first );
158 lTrData, realseed, weight );
159 newTracks.push_back ( vTrData );
162 if ( newTracks.size() > 1 )
170 for ( vector< TrackAndWeight >::const_iterator
track=tracks.begin();
173 if ( thePrimaries.count (
track->first ) )
181 theWeights[
track->first][theVertexStates[0].first]=
track->second;
184 float weight =
track->second;
187 cout <<
"[MultiVertexFitter] error weight " << weight <<
" > 1.0 given." 189 cout <<
"[MultiVertexFitter] will revert to 1.0" << endl;
194 cout <<
"[MultiVertexFitter] error weight " << weight <<
" < 0.0 given." 196 cout <<
"[MultiVertexFitter] will revert to 0.0" << endl;
200 theTracks.push_back (
track->first );
207 sort ( theTracks.begin(), theTracks.end() );
208 for ( vector< TransientTrack >::iterator
i=theTracks.begin();
209 i<theTracks.end() ; ++
i )
211 if (
i != theTracks.begin() )
213 if ( (*
i) == ( *(
i-1) ) )
215 theTracks.erase (
i );
222 const vector < TransientVertex > & vtces,
223 const vector < TransientTrack > & primaries )
228 return vector < CachingVertex<5> > ();
230 vector < vector < TrackAndWeight > > bundles;
231 for ( vector< TransientVertex >::const_iterator
vtx=vtces.begin();
232 vtx!=vtces.end() ; ++
vtx )
234 vector < TransientTrack > trks =
vtx->originalTracks();
235 vector < TrackAndWeight > tnws;
236 for ( vector< TransientTrack >::const_iterator trk=trks.begin();
237 trk!=trks.end() ; ++trk )
239 float w =
vtx->trackWeight ( *trk );
243 tnws.push_back ( tmp );
246 bundles.push_back ( tnws );
248 return vertices ( bundles, primaries );
253 const vector < TransientTrack > & primaries )
256 createPrimaries ( primaries );
258 if ( initials.empty() )
return initials;
260 vtx!=initials.end() ; ++
vtx )
267 for ( vector< TransientTrack >::const_iterator trk=trks.begin();
268 trk!=trks.end() ; ++trk )
270 if ( !(thePrimaries.count (*trk )) )
273 theTracks.push_back ( *trk );
277 cout <<
"[MultiVertexFitter] error! track weight currently set to one" 278 <<
" FIXME!!!" << endl;
279 theWeights[*trk][snr]=1.0;
282 #ifdef MVFHarvestingDebug 284 i!=theVertexStates.end() ; ++
i )
291 const vector < vector < TransientTrack > > &
tracks,
292 const vector < TransientTrack > & primaries )
295 createPrimaries ( primaries );
297 for ( vector< vector < TransientTrack > >::const_iterator cluster=
300 createSeed ( *cluster );
306 #ifdef MVFHarvestingDebug 308 i!=theVertexStates.end() ; ++
i )
315 const vector < vector < TrackAndWeight > > &
tracks,
316 const vector < TransientTrack > & primaries )
319 createPrimaries ( primaries );
321 for ( vector< vector < TrackAndWeight > >::const_iterator cluster=
324 createSeed ( *cluster );
336 float revive_below ) :
337 theVertexStateNr ( 0 ), theReviveBelow ( revive_below ),
338 theAssComp ( ann.
clone() ), theSeeder ( seeder.
clone() )
357 cout <<
"[MultiVertexFitter] Start weight update." << endl;
365 for ( set < TransientTrack >::const_iterator trk=
thePrimaries.begin();
372 if (result.first) weight =
theAssComp->
phi ( result.second );
379 for ( vector< TransientTrack >::const_iterator trk=
theTracks.begin();
391 if (result.first) weight =
theAssComp->
phi ( result.second );
400 if ( tot_weight > 0.0 )
407 if ( normedweight > 1.0 )
409 cout <<
"[MultiVertexFitter] he? w[" 410 <<
"," <<
seed->second.position() <<
"] = " << normedweight
411 <<
" totw=" << tot_weight << endl;
414 if ( normedweight < 0.0 )
416 cout <<
"[MultiVertexFitter] he? weight=" << normedweight
417 <<
" totw=" << tot_weight << endl;
424 cout <<
"[MultiVertexFitter] track found with no assignment - ";
425 cout <<
"will assign uniformly." << endl;
444 vector < pair < int, CachingVertex<5> > > newSeeds;
452 int snr =
seed->first;
456 for ( vector< TransientTrack >::const_iterator
track=
theTracks.begin();
468 if ( discardLightWeights() )
470 for ( vector< TransientTrack >::const_iterator
track=
theTracks.begin();
480 vector<RefCountedVertexTrack> newTracks;
481 for ( vector< TransientTrack >::const_iterator
track=
theTracks.begin();
491 if ( !discardLightWeights() || weight > minWeightFraction() * totweight
492 || nr_good_trks < 2 )
503 lTrData, realseed, weight );
504 newTracks.push_back ( vTrData );
518 lTrData, realseed, weight );
519 newTracks.push_back ( vTrData );
524 if ( newTracks.size() < 2 )
531 cout <<
"[MultiVertexFitter] now fitting with Kalman: ";
532 for ( vector< RefCountedVertexTrack >::const_iterator
i=newTracks.begin();
533 i!=newTracks.end() ; ++
i )
535 cout << (**i).weight() <<
" ";
540 if ( newTracks.size() > 1 )
546 double disp = ( newVertex.
position() -
seed->second.position() ).
mag();
547 if ( disp > max_disp ) max_disp = disp;
553 cout <<
"[MultiVertexFitter] exception: " << e.what() << endl;
561 #ifdef MVFHarvestingDebug 568 static const double disp_limit = 1
e-4;
574 cout <<
"[MultiVertexFitter] max displacement in this iteration: " 577 if ( max_disp < disp_limit )
return false;
586 static const int ctr_max = 50;
590 if ( ++ctr >= ctr_max )
break;
598 cout <<
"[MultiVertexFitter] number of iterations: " << ctr << endl;
599 cout <<
"[MultiVertexFitter] remaining seeds: " 604 vector < CachingVertex<5> > ret;
608 ret.push_back (
i->second );
623 auto b =
a->second.find(
seed->first);
624 if (
b !=
a->second.end()) val =
b->second;
626 cout <<
" -- Vertex[" <<
seed->first <<
"] with " << setw(12)
627 << setprecision(3) <<
val;
634 cout << endl <<
"Weight table: " << endl <<
"=================" << endl;
635 for ( set < TransientTrack >::const_iterator trk=
thePrimaries.begin();
640 for ( vector< TransientTrack >::const_iterator trk=
theTracks.begin();
649 cout << endl <<
"Seed table: " << endl <<
"=====================" << endl;
665 bool has_revived =
false;
671 for ( vector< TransientTrack >::const_iterator trk=
theTracks.begin();
681 if ( totweight < theReviveBelow && totweight > 0.0 )
683 cout <<
"[MultiVertexFitter] now trying to revive vertex" 686 for ( vector< TransientTrack >::const_iterator trk=
theTracks.begin();
std::vector< CachingVertex< 5 > > vertices(const std::vector< std::vector< reco::TransientTrack > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
MultiVertexFitter(const AnnealingSchedule &sched=DefaultMVFAnnealing(), const LinearizationPointFinder &seeder=DefaultLinearizationPointFinder(), float revive_below=-1.)
std::pair< reco::TransientTrack, float > TrackAndWeight
std::map< reco::TransientTrack, SeedToWeightMap > TrackAndSeedToWeightMap
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void printWeights() const
GlobalErrorBase< double, ErrorMatrixTag > GlobalError
void createPrimaries(const std::vector< reco::TransientTrack > &tracks)
LinearizationPointFinder * theSeeder
std::set< reco::TransientTrack > thePrimaries
virtual bool isAnnealed() const =0
std::vector< reco::TransientTrack > const & originalTracks() const
std::vector< reco::TransientTrack > theTracks
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
virtual double phi(double chi2) const =0
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &tracks) const override
virtual double cutoff() const =0
std::vector< std::pair< int, CachingVertex< 5 > > > theVertexStates
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
void createSeed(const std::vector< reco::TransientTrack > &tracks)
RefCountedLinearizedTrackState linTrack(const GlobalPoint &, const reco::TransientTrack &)
GlobalPoint position() const
std::vector< std::vector< double > > tmp
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
std::vector< CachingVertex< 5 > > fit()
AnnealingSchedule * theAssComp
TrackAndSeedToWeightMap theWeights
std::map< int, double > SeedToWeightMap