16 #ifdef MVFHarvestingDebug 17 #include "Vertex/VertexSimpleVis/interface/PrimitivesHarvester.h" 30 static const int ret = 0;
35 double minWeightFraction() {
40 static const float ret = 1
e-6;
45 bool discardLightWeights() {
46 static const bool ret =
true;
65 double validWeight(
double weight) {
67 cout <<
"[MultiVertexFitter] weight=" << weight <<
"??" << endl;
72 cout <<
"[MultiVertexFitter] weight=" << weight <<
"??" << endl;
80 theAssComp->resetAnnealing();
83 theVertexStates.clear();
92 if (tracks.size() > 1) {
96 for (vector<TransientTrack>::const_iterator
track = tracks.begin();
track != tracks.end(); ++
track) {
97 theWeights[*
track][snr] = 1.;
98 theTracks.push_back(*
track);
105 for (vector<reco::TransientTrack>::const_iterator
i = tracks.begin();
i != tracks.end(); ++
i) {
106 thePrimaries.insert(*
i);
118 vector<RefCountedVertexTrack> newTracks;
120 for (vector<TrackAndWeight>::const_iterator
track = tracks.begin();
track != tracks.end(); ++
track) {
121 double weight = validWeight(
track->second);
130 newTracks.push_back(vTrData);
133 if (newTracks.size() > 1) {
140 for (vector<TrackAndWeight>::const_iterator
track = tracks.begin();
track != tracks.end(); ++
track) {
141 if (thePrimaries.count(
track->first)) {
148 theWeights[
track->first][theVertexStates[0].first] =
track->second;
151 float weight =
track->second;
153 cout <<
"[MultiVertexFitter] error weight " << weight <<
" > 1.0 given." << endl;
154 cout <<
"[MultiVertexFitter] will revert to 1.0" << endl;
158 cout <<
"[MultiVertexFitter] error weight " << weight <<
" < 0.0 given." << endl;
159 cout <<
"[MultiVertexFitter] will revert to 0.0" << endl;
163 theTracks.push_back(
track->first);
170 sort(theTracks.begin(), theTracks.end());
171 for (vector<TransientTrack>::iterator
i = theTracks.begin();
i < theTracks.end(); ++
i) {
172 if (
i != theTracks.begin()) {
173 if ((*
i) == (*(
i - 1))) {
181 const vector<TransientTrack> &primaries) {
184 return vector<CachingVertex<5> >();
186 vector<vector<TrackAndWeight> > bundles;
187 for (vector<TransientVertex>::const_iterator
vtx = vtces.begin();
vtx != vtces.end(); ++
vtx) {
188 vector<TransientTrack> trks =
vtx->originalTracks();
189 vector<TrackAndWeight> tnws;
190 for (vector<TransientTrack>::const_iterator trk = trks.begin(); trk != trks.end(); ++trk) {
191 float w =
vtx->trackWeight(*trk);
197 bundles.push_back(tnws);
199 return vertices(bundles, primaries);
203 const vector<TransientTrack> &primaries) {
205 createPrimaries(primaries);
207 if (initials.empty())
214 for (vector<TransientTrack>::const_iterator trk = trks.begin(); trk != trks.end(); ++trk) {
215 if (!(thePrimaries.count(*trk))) {
217 theTracks.push_back(*trk);
221 cout <<
"[MultiVertexFitter] error! track weight currently set to one" 222 <<
" FIXME!!!" << endl;
223 theWeights[*trk][snr] = 1.0;
226 #ifdef MVFHarvestingDebug 227 for (vector<
CachingVertex<5> >::const_iterator
i = theVertexStates.begin();
i != theVertexStates.end(); ++
i)
234 const vector<TransientTrack> &primaries) {
236 createPrimaries(primaries);
238 for (vector<vector<TransientTrack> >::const_iterator cluster =
tracks.begin(); cluster !=
tracks.end(); ++cluster) {
239 createSeed(*cluster);
244 #ifdef MVFHarvestingDebug 245 for (vector<
CachingVertex<5> >::const_iterator
i = theVertexStates.begin();
i != theVertexStates.end(); ++
i)
252 const vector<TransientTrack> &primaries) {
254 createPrimaries(primaries);
256 for (vector<vector<TrackAndWeight> >::const_iterator cluster =
tracks.begin(); cluster !=
tracks.end(); ++cluster) {
257 createSeed(*cluster);
269 : theVertexStateNr(0), theReviveBelow(revive_below), theAssComp(ann.
clone()), theSeeder(seeder.
clone()) {}
285 cout <<
"[MultiVertexFitter] Start weight update." << endl;
306 for (vector<TransientTrack>::const_iterator trk =
theTracks.begin(); trk !=
theTracks.end(); ++trk) {
324 if (tot_weight > 0.0) {
329 if (normedweight > 1.0) {
330 cout <<
"[MultiVertexFitter] he? w[" 331 <<
"," <<
seed->second.position() <<
"] = " << normedweight <<
" totw=" << tot_weight << endl;
334 if (normedweight < 0.0) {
335 cout <<
"[MultiVertexFitter] he? weight=" << normedweight <<
" totw=" << tot_weight << endl;
342 cout <<
"[MultiVertexFitter] track found with no assignment - ";
343 cout <<
"will assign uniformly." << endl;
357 double max_disp = 0.;
362 vector<pair<int, CachingVertex<5> > > newSeeds;
370 int snr =
seed->first;
373 double totweight = 0.;
378 int nr_good_trks = 0;
383 if (discardLightWeights()) {
391 vector<RefCountedVertexTrack> newTracks;
400 if (!discardLightWeights() || weight > minWeightFraction() * totweight || nr_good_trks < 2) {
409 newTracks.push_back(vTrData);
420 newTracks.push_back(vTrData);
424 if (newTracks.size() < 2) {
429 cout <<
"[MultiVertexFitter] now fitting with Kalman: ";
430 for (vector<RefCountedVertexTrack>::const_iterator
i = newTracks.begin();
i != newTracks.end(); ++
i) {
431 cout << (**i).weight() <<
" ";
436 if (newTracks.size() > 1) {
447 cout <<
"[MultiVertexFitter] exception: " << e.what() << endl;
455 #ifdef MVFHarvestingDebug 461 static const double disp_limit = 1
e-4;
466 cout <<
"[MultiVertexFitter] max displacement in this iteration: " << max_disp << endl;
468 if (max_disp < disp_limit)
478 static const int ctr_max = 50;
481 if (++ctr >= ctr_max)
489 cout <<
"[MultiVertexFitter] number of iterations: " << ctr << endl;
494 vector<CachingVertex<5> >
ret;
497 ret.push_back(
i->second);
511 auto b =
a->second.find(
seed->first);
512 if (
b !=
a->second.end())
515 cout <<
" -- Vertex[" <<
seed->first <<
"] with " << setw(12) << setprecision(3) <<
val;
521 cout << endl <<
"Weight table: " << endl <<
"=================" << endl;
525 for (vector<TransientTrack>::const_iterator trk =
theTracks.begin(); trk !=
theTracks.end(); ++trk) {
531 cout << endl <<
"Seed table: " << endl <<
"=====================" << endl;
547 bool has_revived =
false;
551 double totweight = 0.;
552 for (vector<TransientTrack>::const_iterator trk =
theTracks.begin(); trk !=
theTracks.end(); ++trk) {
560 if (totweight < theReviveBelow && totweight > 0.0) {
561 cout <<
"[MultiVertexFitter] now trying to revive vertex" 564 for (vector<TransientTrack>::const_iterator trk =
theTracks.begin(); trk !=
theTracks.end(); ++trk) {
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.)
ret
prodAgent to be discontinued
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
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
std::pair< reco::TransientTrack, float > TrackAndWeight
std::map< int, double > SeedToWeightMap
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
CachingVertex< 5 >::RefCountedVertexTrack RefCountedVertexTrack
std::vector< CachingVertex< 5 > > fit()
std::vector< reco::TransientTrack > theTracks
AnnealingSchedule * theAssComp
std::map< reco::TransientTrack, SeedToWeightMap > TrackAndSeedToWeightMap
TrackAndSeedToWeightMap theWeights