CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

MultiVertexFitter Class Reference

#include <MultiVertexFitter.h>

List of all members.

Public Types

typedef std::map< int, double > SeedToWeightMap
typedef std::map
< reco::TransientTrack,
SeedToWeightMap
TrackAndSeedToWeightMap
typedef std::pair
< reco::TransientTrack, float > 
TrackAndWeight

Public Member Functions

 MultiVertexFitter (const AnnealingSchedule &sched=DefaultMVFAnnealing(), const LinearizationPointFinder &seeder=DefaultLinearizationPointFinder(), float revive_below=-1.)
 MultiVertexFitter (const MultiVertexFitter &)
std::vector< CachingVertex< 5 > > vertices (const std::vector< TransientVertex > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
std::vector< CachingVertex< 5 > > vertices (const std::vector< std::vector< TrackAndWeight > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
std::vector< CachingVertex< 5 > > vertices (const std::vector< std::vector< reco::TransientTrack > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
std::vector< CachingVertex< 5 > > vertices (const std::vector< CachingVertex< 5 > > &, const std::vector< reco::TransientTrack > &primaries=std::vector< reco::TransientTrack >())
 ~MultiVertexFitter ()

Private Types

typedef
ReferenceCountingPointer
< LinearizedTrackState< 5 > > 
RefCountedLinearizedTrackState
typedef CachingVertex
< 5 >::RefCountedVertexTrack 
RefCountedVertexTrack

Private Member Functions

void clear ()
void createPrimaries (const std::vector< reco::TransientTrack > &tracks)
void createSeed (const std::vector< reco::TransientTrack > &tracks)
void createSeed (const std::vector< TrackAndWeight > &tracks)
std::vector< CachingVertex< 5 > > fit ()
void lostVertexClaimer ()
void printSeeds () const
void printWeights () const
void printWeights (const reco::TransientTrack &) const
void resetSeedNr ()
int seedNr ()
bool updateSeeds ()
void updateWeights ()

Private Attributes

AnnealingScheduletheAssComp
LinTrackCache theCache
std::set< reco::TransientTrackthePrimaries
float theReviveBelow
LinearizationPointFindertheSeeder
std::vector< reco::TransientTracktheTracks
int theVertexStateNr
std::vector< std::pair< int,
CachingVertex< 5 > > > 
theVertexStates
TrackAndSeedToWeightMap theWeights

Detailed Description

fits n vertices in parallel, associating weights for every track-vertex std::pair. The special constructor's arguments take precedence over the SimpleConfigurables.

SimpleConfigurables:

MultiVertexFitter:Debug = 0 MultiVertexFitter:DisplacementLimit = 0.00001 MultiVertexFitter:MaxIterations = 30 MultiVertexFitter:ClaimLostVertices = true MultiVertexFitter:MinimumWeightFraction = 1e-6 MultiVertexFitter:ReviveBelow = 0.3 MultiVertexFitter:DiscardLightWeights = true

Definition at line 15 of file MultiVertexFitter.h.


Member Typedef Documentation

Definition at line 106 of file MultiVertexFitter.h.

Definition at line 105 of file MultiVertexFitter.h.

typedef std::map< int , double > MultiVertexFitter::SeedToWeightMap

Definition at line 44 of file MultiVertexFitter.h.

Definition at line 45 of file MultiVertexFitter.h.

Definition at line 43 of file MultiVertexFitter.h.


Constructor & Destructor Documentation

MultiVertexFitter::MultiVertexFitter ( const AnnealingSchedule sched = DefaultMVFAnnealing(),
const LinearizationPointFinder seeder = DefaultLinearizationPointFinder(),
float  revive_below = -1. 
)

Definition at line 334 of file MultiVertexFitter.cc.

                                                           :
    theVertexStateNr ( 0 ), theReviveBelow ( revive_below ),
    theAssComp ( ann.clone() ), theSeeder ( seeder.clone() )
{}
MultiVertexFitter::MultiVertexFitter ( const MultiVertexFitter o)
MultiVertexFitter::~MultiVertexFitter ( )

Definition at line 346 of file MultiVertexFitter.cc.

References theAssComp, and theSeeder.

{
  delete theAssComp;
  delete theSeeder;
}

Member Function Documentation

void MultiVertexFitter::clear ( void  ) [private]

Definition at line 88 of file MultiVertexFitter.cc.

void MultiVertexFitter::createPrimaries ( const std::vector< reco::TransientTrack > &  tracks) [private]

Definition at line 118 of file MultiVertexFitter.cc.

References i.

{
  // cout << "[MultiVertexFitter] creating primaries: ";
  for ( vector< reco::TransientTrack >::const_iterator i=tracks.begin(); 
        i!=tracks.end() ; ++i )
  {
    thePrimaries.insert ( *i );
    // cout << i->id() << "  ";
  }
  // cout << endl;
}
void MultiVertexFitter::createSeed ( const std::vector< reco::TransientTrack > &  tracks) [private]
void MultiVertexFitter::createSeed ( const std::vector< TrackAndWeight > &  tracks) [private]
vector< CachingVertex< 5 > > MultiVertexFitter::fit ( ) [private]

Definition at line 582 of file MultiVertexFitter.cc.

References AnnealingSchedule::anneal(), gather_cfg::cout, i, AnnealingSchedule::isAnnealed(), printWeights(), resetSeedNr(), run_regression::ret, theAssComp, theVertexStates, updateSeeds(), and validate_alignment_devdb10_cfg::verbose.

{
  if ( verbose() & 2 ) printWeights();
  int ctr=1;
  static const int ctr_max = 50; /* SimpleConfigurable<int>(100,
      "MultiVertexFitter:MaxIterations").value(); */
  while ( updateSeeds() || !(theAssComp->isAnnealed()) )
  {
    if ( ++ctr >= ctr_max ) break;
    theAssComp->anneal();
    // lostVertexClaimer(); // was a silly(?) idea to "revive" vertex candidates.
    resetSeedNr();
  };

  if ( verbose() )
  {
    cout << "[MultiVertexFitter] number of iterations: " << ctr << endl;
    cout << "[MultiVertexFitter] remaining seeds: "
         << theVertexStates.size() << endl;
    printWeights();
  };

  vector < CachingVertex<5> > ret;
  for ( vector< pair < int, CachingVertex<5> > >::const_iterator 
        i=theVertexStates.begin(); i!=theVertexStates.end() ; ++i )
  {
    ret.push_back ( i->second );
  };

  return ret;
}
void MultiVertexFitter::lostVertexClaimer ( ) [private]

Definition at line 653 of file MultiVertexFitter.cc.

References gather_cfg::cout, i, printWeights(), theReviveBelow, theTracks, theVertexStates, theWeights, and validate_alignment_devdb10_cfg::verbose.

{
  if ( !theReviveBelow < 0. ) return;
  // this experimental method is used to get almost lost vertices
  // back into the play by upweighting vertices with very low total weights

  bool has_revived = false;
  // find out about total weight
  for ( vector< pair < int, CachingVertex<5> > >::const_iterator i=theVertexStates.begin();
        i!=theVertexStates.end() ; ++i )
  {
    double totweight=0.;
    for ( vector< TransientTrack >::const_iterator trk=theTracks.begin();
          trk!=theTracks.end() ; ++trk )
    {
      totweight+=theWeights[*trk][i->first];
    };

    /*
    cout << "[MultiVertexFitter] vertex seed " << TransientVertexNamer().name(*i)
         << " total weight=" << totweight << endl;*/

    if ( totweight < theReviveBelow && totweight > 0.0 )
    {
      cout << "[MultiVertexFitter] now trying to revive vertex"
           << " revive_below=" << theReviveBelow << endl;
      has_revived=true;
      for ( vector< TransientTrack >::const_iterator trk=theTracks.begin();
            trk!=theTracks.end() ; ++trk )
      {
        theWeights[*trk][i->first]/=totweight;
      };
    };
  };
  if ( has_revived && verbose() ) printWeights();
}
void MultiVertexFitter::printSeeds ( ) const [private]

Definition at line 641 of file MultiVertexFitter.cc.

References gather_cfg::cout.

Referenced by updateSeeds().

{
  cout << endl << "Seed table: " << endl << "=====================" << endl;
  /*
  for ( vector < pair < int, CachingVertex<5> > >::const_iterator seed=theVertexStates.begin();
        seed!=theVertexStates.end(); ++seed )
  {
    cout << "  Vertex[" << TransientVertexNamer().name(seed->second) << "] at "
         << seed->second.position() << endl;
  };*/
}
void MultiVertexFitter::printWeights ( const reco::TransientTrack t) const [private]

Definition at line 614 of file MultiVertexFitter.cc.

References gather_cfg::cout, lumiQTWidget::t, theVertexStates, and theWeights.

{
    // cout << "Trk " << t.id();
    for ( vector < pair < int, CachingVertex<5> > >::const_iterator seed=theVertexStates.begin();
          seed!=theVertexStates.end(); ++seed )
    {
      cout << "  -- Vertex[" << seed->first << "] with " << setw(12)
           << setprecision(3) << theWeights[t][seed->first];
    };
    cout << endl;
}
void MultiVertexFitter::printWeights ( ) const [private]

Definition at line 626 of file MultiVertexFitter.cc.

References gather_cfg::cout, thePrimaries, and theTracks.

Referenced by fit(), lostVertexClaimer(), and updateWeights().

{
  cout << endl << "Weight table: " << endl << "=================" << endl;
  for ( set < TransientTrack >::const_iterator trk=thePrimaries.begin();
        trk!=thePrimaries.end() ; ++trk )
  {
    printWeights ( *trk );
  };
  for ( vector< TransientTrack >::const_iterator trk=theTracks.begin();
        trk!=theTracks.end() ; ++trk )
  {
    printWeights ( *trk );
  };
}
void MultiVertexFitter::resetSeedNr ( ) [private]

Definition at line 135 of file MultiVertexFitter.cc.

Referenced by fit().

int MultiVertexFitter::seedNr ( ) [private]

Definition at line 130 of file MultiVertexFitter.cc.

Referenced by updateSeeds().

{
  return theVertexStateNr++;
}
bool MultiVertexFitter::updateSeeds ( ) [private]

Definition at line 437 of file MultiVertexFitter.cc.

References gather_cfg::cout, alignCSCRings::e, exception, mergeVDriftHistosByStation::file, i, LinTrackCache::linTrack(), mag(), CachingVertex< N >::position(), printSeeds(), seedNr(), theCache, thePrimaries, theTracks, theVertexStates, theWeights, updateWeights(), validate_alignment_devdb10_cfg::verbose, KalmanVertexFitter::vertex(), and VertexTrackFactory< N >::vertexTrack().

Referenced by fit().

{
  double max_disp=0.;
  // need to fit with the right weights.
  // also trigger an updateWeights.
  // if the seeds dont move much we return true

  vector < pair < int, CachingVertex<5> > > newSeeds;

  for ( vector< pair < int, CachingVertex<5> > >::const_iterator seed=theVertexStates.begin();
        seed!=theVertexStates.end() ; ++seed )
  {
    // for each seed get the tracks with the right weights.
    // TransientVertex rv = seed->second;
    // const GlobalPoint & seedpos = seed->second.position();
    int snr = seed->first;
    VertexState realseed ( seed->second.position(), seed->second.error() );

    double totweight=0.;
    for ( vector< TransientTrack >::const_iterator track=theTracks.begin();
          track!=theTracks.end() ; ++track )
    {
      totweight+=theWeights[*track][snr];
    };


    int nr_good_trks=0; // how many tracks above weight limit
    // we count those tracks, because that way
    // we can discard lightweights if there are enough tracks
    // and not discard the lightweights if that would give us
    // fewer than two tracks ( we would loose a seed, then ).
    if ( discardLightWeights() )
    {
      for ( vector< TransientTrack >::const_iterator track=theTracks.begin();
            track!=theTracks.end() ; ++track )
      {
        if ( theWeights[*track][snr] > totweight * minWeightFraction() )
        {
          nr_good_trks++;
        };
      };
    };

    vector<RefCountedVertexTrack> newTracks;
    for ( vector< TransientTrack >::const_iterator track=theTracks.begin();
          track!=theTracks.end() ; ++track )
    {
      double weight = validWeight ( theWeights[*track][snr] );
      // Now we add a track, if
      // a. we consider all tracks or
      // b. we discard the lightweights but the track's weight is high enough or
      // c. we discard the lightweights but there arent enough good tracks,
      //    so we add all lightweights again (too expensive to figure out
      //    which lightweights are the most important)
      if ( !discardLightWeights() || weight > minWeightFraction() * totweight
           || nr_good_trks < 2 )
      {
        // if the linearization point didnt move too much,
        // we take the old LinTrackState.
        // Otherwise we relinearize.

        RefCountedLinearizedTrackState lTrData =
          theCache.linTrack ( seed->second.position(), *track );

        VertexTrackFactory<5> vTrackFactory;
        RefCountedVertexTrack vTrData = vTrackFactory.vertexTrack(
          lTrData, realseed, weight );
        newTracks.push_back ( vTrData );
      };
    };

    for ( set< TransientTrack >::const_iterator track=thePrimaries.begin();
          track!=thePrimaries.end() ; ++track )
    {
      double weight = validWeight ( theWeights[*track][snr] );

      RefCountedLinearizedTrackState lTrData =
        theCache.linTrack ( seed->second.position(), *track );

      VertexTrackFactory<5> vTrackFactory;
      RefCountedVertexTrack vTrData = vTrackFactory.vertexTrack(
        lTrData, realseed, weight );
      newTracks.push_back ( vTrData );

    };

    try {
      if ( newTracks.size() < 2 )
      {
        throw VertexException("less than two tracks in vector" );
      };

      if ( verbose() )
      {
        cout << "[MultiVertexFitter] now fitting with Kalman: ";
        for ( vector< RefCountedVertexTrack >::const_iterator i=newTracks.begin(); 
              i!=newTracks.end() ; ++i )
        {
          cout << (**i).weight() << " ";
        };
        cout << endl;
      };

      if ( newTracks.size() > 1 )
      {
        KalmanVertexFitter fitter;
        // warning! first track determines lin pt!
        CachingVertex<5> newVertex = fitter.vertex ( newTracks );
        int snr = seedNr();
        double disp = ( newVertex.position() - seed->second.position() ).mag();
        if ( disp > max_disp ) max_disp = disp;
        newSeeds.push_back ( 
            pair < int, CachingVertex<5> > ( snr, newVertex ) );
      };
    } catch ( exception & e )
    {
      cout << "[MultiVertexFitter] exception: " << e.what() << endl;
    }
  };

  // now discard all old seeds and weights, compute new ones.
  theVertexStates.clear();
  theWeights.clear();
  theVertexStates=newSeeds;
  #ifdef MVFHarvestingDebug
  for ( vector< CachingVertex<5> >::const_iterator i=theVertexStates.begin();
        i!=theVertexStates.end() ; ++i )
    PrimitivesHarvester::file()->save(*i);
  #endif
  updateWeights();

  static const double disp_limit = 1e-4; /* SimpleConfigurable<double>
    (0.0001, "MultiVertexFitter:DisplacementLimit" ).value(); */

  if ( verbose() & 2 )
  {
    printSeeds();
    cout << "[MultiVertexFitter] max displacement in this iteration: "
         << max_disp << endl;
  };
  if ( max_disp < disp_limit ) return false;
  return true;
}
void MultiVertexFitter::updateWeights ( ) [private]

add the primary only tracks to primary vertex only.

now add "free tracks" to all vertices

Definition at line 352 of file MultiVertexFitter.cc.

References gather_cfg::cout, AnnealingSchedule::cutoff(), KalmanVertexTrackCompatibilityEstimator< N >::estimate(), LinTrackCache::linTrack(), AnnealingSchedule::phi(), CachingVertex< N >::position(), printWeights(), query::result, theAssComp, theCache, thePrimaries, theTracks, theVertexStates, theWeights, validate_alignment_devdb10_cfg::verbose, w(), and histoStyle::weight.

Referenced by updateSeeds().

{
  theWeights.clear();
  if ( verbose() & 4 )
  {
    cout << "[MultiVertexFitter] Start weight update." << endl;
  };

  KalmanVertexTrackCompatibilityEstimator<5> theComp;
  
  for ( set < TransientTrack >::const_iterator trk=thePrimaries.begin();
        trk!=thePrimaries.end() ; ++trk )
  {
    int seednr = theVertexStates[0].first;
    CachingVertex<5> seed = theVertexStates[0].second;
    pair<bool, double> result = theComp.estimate ( seed, theCache.linTrack ( seed.position(), *trk ) ); 
    double weight = 0.;
    if (result.first) weight = theAssComp->phi ( result.second );
    theWeights[*trk][seednr]= weight; // FIXME maybe "hard" 1.0 or "soft" weight?
  }

  for ( vector< TransientTrack >::const_iterator trk=theTracks.begin();
        trk!=theTracks.end() ; ++trk )
  {
    double tot_weight=theAssComp->phi ( theAssComp->cutoff() * theAssComp->cutoff() );

    for ( vector < pair < int, CachingVertex<5> > >::const_iterator 
          seed=theVertexStates.begin(); seed!=theVertexStates.end(); ++seed )
    {
      
      pair<bool, double> result = theComp.estimate ( seed->second, theCache.linTrack ( seed->second.position(),
             *trk ) );
      double weight = 0.;
      if (result.first) weight = theAssComp->phi ( result.second );
      tot_weight+=weight;
      theWeights[*trk][seed->first]=weight;
      /* cout << "[MultiVertexFitter] w[" << TransientTrackNamer().name(*trk)
           << "," << seed->position() << "] = " << weight << endl;*/
    };

    // normalize to sum of all weights of one track equals 1.
    // (if we include the "cutoff", as well)
    if ( tot_weight > 0.0 )
    {
      for ( vector < pair < int, CachingVertex<5> > >::const_iterator 
            seed=theVertexStates.begin();
            seed!=theVertexStates.end(); ++seed )
      {
        double normedweight=theWeights[*trk][seed->first]/tot_weight;
        if ( normedweight > 1.0 )
        {
          cout << "[MultiVertexFitter] he? w[" // << TransientTrackNamer().name(*trk)
               << "," << seed->second.position() << "] = " << normedweight
               << " totw=" << tot_weight << endl;
          normedweight=1.0;
        };
        if ( normedweight < 0.0 )
        {
          cout << "[MultiVertexFitter] he? weight=" << normedweight
               << " totw=" << tot_weight << endl;
          normedweight=0.0;
        };
        theWeights[*trk][seed->first]=normedweight;
      };
    } else {
      // total weight equals zero? restart, with uniform distribution!
      cout << "[MultiVertexFitter] track found with no assignment - ";
      cout << "will assign uniformly." << endl;
      float w = .5 / (float) theVertexStates.size();
      for ( vector < pair < int, CachingVertex<5> > >::const_iterator seed=theVertexStates.begin();
            seed!=theVertexStates.end(); ++seed )
      {
        theWeights[*trk][seed->first]=w;
      };
    };
  };
  if ( verbose() & 2 ) printWeights();
}
std::vector< CachingVertex<5> > MultiVertexFitter::vertices ( const std::vector< TransientVertex > &  ,
const std::vector< reco::TransientTrack > &  primaries = std::vector< reco::TransientTrack >() 
)

Same as above.

std::vector< CachingVertex<5> > MultiVertexFitter::vertices ( const std::vector< std::vector< reco::TransientTrack > > &  ,
const std::vector< reco::TransientTrack > &  primaries = std::vector< reco::TransientTrack >() 
)

Supply simple clusters of reco::TransientTracks. primaries: supply tracks which are hard coded to the primary vertex.

std::vector< CachingVertex<5> > MultiVertexFitter::vertices ( const std::vector< std::vector< TrackAndWeight > > &  ,
const std::vector< reco::TransientTrack > &  primaries = std::vector< reco::TransientTrack >() 
)

Supply clusters of tracks with weights, association weights of the other vertices is considered zero. FIXME weights are currently ignored. primaries: supply tracks which are hard coded to the primary vertex.

std::vector< CachingVertex<5> > MultiVertexFitter::vertices ( const std::vector< CachingVertex< 5 > > &  ,
const std::vector< reco::TransientTrack > &  primaries = std::vector< reco::TransientTrack >() 
)

Supply full CachingVertices; CachingVertices are the first seeds. primaries: supply tracks which are hard coded to the primary vertex.


Member Data Documentation

Definition at line 116 of file MultiVertexFitter.h.

Referenced by fit(), updateWeights(), and ~MultiVertexFitter().

Definition at line 119 of file MultiVertexFitter.h.

Referenced by updateSeeds(), and updateWeights().

Definition at line 115 of file MultiVertexFitter.h.

Referenced by printWeights(), updateSeeds(), and updateWeights().

Definition at line 113 of file MultiVertexFitter.h.

Referenced by lostVertexClaimer().

Definition at line 117 of file MultiVertexFitter.h.

Referenced by ~MultiVertexFitter().

Definition at line 114 of file MultiVertexFitter.h.

Referenced by lostVertexClaimer(), printWeights(), updateSeeds(), and updateWeights().

Definition at line 112 of file MultiVertexFitter.h.

std::vector< std::pair < int, CachingVertex<5> > > MultiVertexFitter::theVertexStates [private]

Definition at line 111 of file MultiVertexFitter.h.

Referenced by fit(), lostVertexClaimer(), printWeights(), updateSeeds(), and updateWeights().

Definition at line 118 of file MultiVertexFitter.h.

Referenced by lostVertexClaimer(), printWeights(), updateSeeds(), and updateWeights().