CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
AdaptiveVertexFitter Class Reference

#include <AdaptiveVertexFitter.h>

Inheritance diagram for AdaptiveVertexFitter:
VertexFitter< 5 >

Public Types

typedef ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
 
typedef ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
 

Public Member Functions

 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 > &ltsf=LinearizedTrackStateFactory())
 
 AdaptiveVertexFitter (const AdaptiveVertexFitter &original)
 
AdaptiveVertexFitterclone () const
 
void gsfIntermediarySmoothing (bool sm)
 
bool gsfIntermediarySmoothing () const
 
void setParameters (double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
 
void setParameters (const edm::ParameterSet &)
 
void setWeightThreshold (float w)
 
virtual CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &) const
 
virtual CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &) const
 
virtual CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &, const reco::BeamSpot &spot) const
 
virtual CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &, const GlobalPoint &linPoint) const
 
virtual CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &, const GlobalPoint &priorPos, const GlobalError &priorError) const
 
virtual CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &tracks, const reco::BeamSpot &beamSpot) const
 
virtual CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &, const GlobalPoint &priorPos, const GlobalError &priorError) const
 
virtual ~AdaptiveVertexFitter ()
 
- Public Member Functions inherited from VertexFitter< 5 >
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks) const =0
 
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks, const reco::BeamSpot &spot) const =0
 
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks, const GlobalPoint &priorPos, const GlobalError &priorError) const =0
 
 VertexFitter ()
 
virtual ~VertexFitter ()
 

Private Member Functions

CachingVertex< 5 > fit (const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
 
double getWeight (float chi2) const
 
std::vector< RefCountedVertexTracklinearizeTracks (const std::vector< reco::TransientTrack > &, const VertexState &) const
 
std::vector< RefCountedVertexTrackreLinearizeTracks (const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
 
std::vector< RefCountedVertexTrackreWeightTracks (const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
 
std::vector< RefCountedVertexTrackreWeightTracks (const std::vector< RefCountedVertexTrack > &, const CachingVertex< 5 > &seed) const
 
std::vector< RefCountedVertexTrackweightTracks (const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
 

Private Attributes

bool gsfIntermediarySmoothing_
 
AnnealingScheduletheAssProbComputer
 
VertexTrackCompatibilityEstimator< 5 > * theComp
 
LinearizationPointFindertheLinP
 
const AbstractLTSFactory< 5 > * theLinTrkFactory
 
double theMaxLPShift
 
double theMaxShift
 
int theMaxStep
 
int theNr
 
VertexSmoother< 5 > * theSmoother
 
VertexUpdator< 5 > * theUpdator
 
double theWeightThreshold
 

Detailed Description

An iterative reweighted fitter. Very robust, very adaptive.

See CMS Note 2007/008.

Exceptions VertexException( "Supplied fewer than two tracks" ) VertexException( "fewer than 2 significant tracks (w>threshold)" )

Definition at line 29 of file AdaptiveVertexFitter.h.

Member Typedef Documentation

Definition at line 34 of file AdaptiveVertexFitter.h.

Definition at line 33 of file AdaptiveVertexFitter.h.

Constructor & Destructor Documentation

AdaptiveVertexFitter::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 > &  ltsf = LinearizedTrackStateFactory() 
)

Reimplemented constructors to use any kind of linearisation point finder, vertex updator and smoother. If no smoother is to be used, do not specify an instance for it.

Definition at line 95 of file AdaptiveVertexFitter.cc.

References setParameters().

Referenced by clone(), and setWeightThreshold().

101  :
102  theNr(0),
103  theLinP(linP.clone()), theUpdator( updator.clone()),
104  theSmoother ( smoother.clone() ), theAssProbComputer( ann.clone() ),
105  theComp ( crit.clone() ), theLinTrkFactory ( ltsf.clone() ),
107 {
108  setParameters();
109 }
virtual VertexUpdator * clone() const =0
virtual const AbstractLTSFactory * clone() const =0
LinearizationPointFinder * theLinP
VertexUpdator< 5 > * theUpdator
virtual LinearizationPointFinder * clone() const =0
VertexSmoother< 5 > * theSmoother
virtual AnnealingSchedule * clone() const =0
AnnealingSchedule * theAssProbComputer
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
virtual VertexSmoother * clone() const =0
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp
AdaptiveVertexFitter::AdaptiveVertexFitter ( const AdaptiveVertexFitter original)

Definition at line 117 of file AdaptiveVertexFitter.cc.

117  :
118  theMaxShift ( o.theMaxShift ), theMaxLPShift ( o.theMaxLPShift ),
119  theMaxStep ( o.theMaxStep ), theWeightThreshold ( o.theWeightThreshold ),
120  theNr ( o.theNr ),
121  theLinP ( o.theLinP->clone() ), theUpdator ( o.theUpdator->clone() ),
122  theSmoother ( o.theSmoother->clone() ),
123  theAssProbComputer ( o.theAssProbComputer->clone() ),
124  theComp ( o.theComp->clone() ),
125  theLinTrkFactory ( o.theLinTrkFactory->clone() ),
126  gsfIntermediarySmoothing_(o.gsfIntermediarySmoothing_)
127 {}
LinearizationPointFinder * theLinP
VertexUpdator< 5 > * theUpdator
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp
AdaptiveVertexFitter::~AdaptiveVertexFitter ( )
virtual

Definition at line 129 of file AdaptiveVertexFitter.cc.

References theAssProbComputer, theComp, theLinP, theLinTrkFactory, theSmoother, and theUpdator.

130 {
131  delete theLinP;
132  delete theUpdator;
133  delete theSmoother;
134  delete theAssProbComputer;
135  delete theComp;
136  delete theLinTrkFactory;
137 }
LinearizationPointFinder * theLinP
VertexUpdator< 5 > * theUpdator
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp

Member Function Documentation

AdaptiveVertexFitter * AdaptiveVertexFitter::clone ( void  ) const
virtual

Fit vertex out of a VertexSeed

Implements VertexFitter< 5 >.

Definition at line 369 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter().

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter().

370 {
371  return new AdaptiveVertexFitter( * this );
372 }
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 > &ltsf=LinearizedTrackStateFactory())
CachingVertex< 5 > AdaptiveVertexFitter::fit ( const std::vector< RefCountedVertexTrack > &  tracks,
const VertexState priorSeed,
bool  withPrior 
) const
private

perform the fit

Definition at line 518 of file AdaptiveVertexFitter.cc.

References VertexUpdator< N >::add(), AnnealingSchedule::anneal(), HiEvtPlane_cfi::chi2, AnnealingSchedule::currentTemp(), VertexState::error(), FrontierConditions_GlobalTag_cff::file, getId(), gsfIntermediarySmoothing_, AnnealingSchedule::isAnnealed(), CachingVertex< N >::isValid(), LogDebug, funct::m, mag(), PV3DBase< T, PVType, FrameType >::perp(), VertexState::position(), CachingVertex< N >::position(), reLinearizeTracks(), AnnealingSchedule::resetAnnealing(), reWeightTracks(), VertexSmoother< N >::smooth(), theAssProbComputer, theMaxLPShift, theMaxShift, theMaxStep, theSmoother, theUpdator, theWeightThreshold, l1t::tracks, AnnealingSchedule::weight(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by gsfIntermediarySmoothing(), trackingPlots.Iteration::modules(), and vertex().

521 {
522  // cout << "[AdaptiveVertexFit] fit with " << tracks.size() << endl;
524 
525  vector<RefCountedVertexTrack> initialTracks;
526  GlobalPoint priorVertexPosition = priorSeed.position();
527  GlobalError priorVertexError = priorSeed.error();
528 
529  CachingVertex<5> returnVertex( priorVertexPosition,priorVertexError,
530  initialTracks,0);
531  if (withPrior)
532  {
533  returnVertex = CachingVertex<5>(priorVertexPosition,priorVertexError,
534  priorVertexPosition,priorVertexError,initialTracks,0);
535  }
536 
537  std::vector<RefCountedVertexTrack> globalVTracks = tracks;
538  // sort the tracks, according to distance to seed!
539  sortByDistanceToRefPoint (globalVTracks, priorSeed.position() );
540 
541  // main loop through all the VTracks
542  int lpStep = 0; int step = 0;
543 
544  CachingVertex<5> initialVertex = returnVertex;
545 
546  GlobalPoint newPosition = priorVertexPosition;
547  GlobalPoint previousPosition = newPosition;
548 
549  int ns_trks=0; // number of significant tracks.
550  // If we have only two significant tracks, we return an invalid vertex
551 
552  // cout << "[AdaptiveVertexFit] start " << tracks.size() << endl;
553  /*
554  for ( vector< RefCountedVertexTrack >::const_iterator
555  i=globalVTracks.begin(); i!=globalVTracks.end() ; ++i )
556  {
557  cout << " " << (**i).linearizedTrack()->track().initialFreeState().momentum() << endl;
558  }*/
559  do {
560  ns_trks=0;
561  CachingVertex<5> fVertex = initialVertex;
562  // cout << "[AdaptiveVertexFit] step " << step << " at " << fVertex.position() << endl;
563  if ((previousPosition - newPosition).transverse() > theMaxLPShift)
564  {
565  // relinearize and reweight.
566  // (reLinearizeTracks also reweights tracks)
567  // cout << "[AdaptiveVertexFit] relinearize at " << returnVertex.position() << endl;
568  if (gsfIntermediarySmoothing_) returnVertex = theSmoother->smooth(returnVertex);
569  globalVTracks = reLinearizeTracks( globalVTracks, returnVertex );
570  lpStep++;
571  } else if (step) {
572  // reweight, if it is not the first step
573  // cout << "[AdaptiveVertexFit] reweight at " << returnVertex.position() << endl;
574  if (gsfIntermediarySmoothing_) returnVertex = theSmoother->smooth(returnVertex);
575  globalVTracks = reWeightTracks( globalVTracks, returnVertex );
576  }
577  // cout << "[AdaptiveVertexFit] relinarized, reweighted" << endl;
578  // update sequentially the vertex estimate
579  CachingVertex<5> nVertex;
580  for(vector<RefCountedVertexTrack>::const_iterator i
581  = globalVTracks.begin(); i != globalVTracks.end(); i++)
582  {
583  if ((**i).weight() > 0.) nVertex = theUpdator->add( fVertex, *i );
584  else nVertex = fVertex;
585  if (nVertex.isValid()) {
586  if ( (**i).weight() >= theWeightThreshold ) ns_trks++;
587 
588  if ( fabs ( nVertex.position().z() ) > 10000. ||
589  nVertex.position().perp()>120.)
590  {
591  // were more than 100 m off!!
592  LogInfo ("AdaptiveVertexFitter" ) << "Vertex candidate just took off to " << nVertex.position()
593  << "! Will discard this update!";
594 // //<< "track pt was " << (**i).linearizedTrack()->track().pt()
595 // << "track momentum was " << (**i).linearizedTrack()->track().initialFreeState().momentum()
596 // << "track position was " << (**i).linearizedTrack()->track().initialFreeState().position()
597 // << "track chi2 was " << (**i).linearizedTrack()->track().chi2()
598 // << "track ndof was " << (**i).linearizedTrack()->track().ndof()
599 // << "track w was " << (**i).weight()
600 // << "track schi2 was " << (**i).smoothedChi2();
601  } else {
602  fVertex = nVertex;
603  }
604  } else {
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.";
609  }
610  }
611  previousPosition = newPosition;
612  newPosition = fVertex.position();
613  returnVertex = fVertex;
615  step++;
616  if ( step >= theMaxStep ) break;
617 
618  } while (
619  // repeat as long as
620  // - vertex moved too much or
621  // - we're not yet annealed
622  ( ((previousPosition - newPosition).mag() > theMaxShift) ||
623  (!(theAssProbComputer->isAnnealed()) ) ) ) ;
624 
625  if ( theWeightThreshold > 0. && ns_trks < 2 && !withPrior )
626  {
627  LogDebug("AdaptiveVertexFitter")
628  << "fewer than two significant tracks (w>" << theWeightThreshold << ")."
629  << " Fitted vertex is invalid.";
630  return CachingVertex<5>(); // return invalid vertex
631  }
632 
633  #ifdef STORE_WEIGHTS
634  map < string, dataharvester::MultiType > m;
635  m["chi2"]=chi2;
636  m["w"]=theAssProbComputer->weight(chi2);
638  m["n"]=iter;
639  m["id"]=getId ( *i );
640  m["pos"]="final";
641  dataharvester::Writer::file("w.txt").save ( m );
642  #endif
643  // cout << "[AdaptiveVertexFit] /fit" << endl;
644  return theSmoother->smooth( returnVertex );
645 }
#define LogDebug(id)
T perp() const
Definition: PV3DBase.h:72
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
static unsigned int getId(void)
VertexUpdator< 5 > * theUpdator
virtual double weight(double chi2) const =0
GlobalPoint position() const
Definition: VertexState.h:69
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
virtual CachingVertex< N > smooth(const CachingVertex< N > &vertex) const =0
virtual bool isAnnealed() const =0
T z() const
Definition: PV3DBase.h:64
virtual double currentTemp() const =0
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
virtual CachingVertex< N > add(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
GlobalPoint position() const
bool isValid() const
virtual void anneal()=0
virtual void resetAnnealing()=0
GlobalError error() const
Definition: VertexState.h:74
step
double AdaptiveVertexFitter::getWeight ( float  chi2) const
private

Definition at line 374 of file AdaptiveVertexFitter.cc.

References MillePedeFileConverter_cfg::e, theAssProbComputer, AnnealingSchedule::weight(), and mps_merge::weight.

Referenced by gsfIntermediarySmoothing(), reWeightTracks(), and weightTracks().

375 {
377 
378  if ( weight > 1.0 )
379  {
380  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " > 1.0!";
381  weight=1.0;
382  };
383 
384  if ( weight < 1e-20 )
385  {
386  // LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " < 0.0!";
387  weight=1e-20;
388  };
389  return weight;
390 }
Definition: weight.py:1
virtual double weight(double chi2) const =0
AnnealingSchedule * theAssProbComputer
void AdaptiveVertexFitter::gsfIntermediarySmoothing ( bool  sm)
inline
bool AdaptiveVertexFitter::gsfIntermediarySmoothing ( ) const
inline
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::linearizeTracks ( const std::vector< reco::TransientTrack > &  tracks,
const VertexState seed 
) const
private

Linearize tracks, for the first time in the iteration.

Construct a container of VertexTrack from a set of reco::TransientTracks. As this is the first iteration of the adaptive fit, the initial error does not enter in the computation of the weights. This is to avoid that all tracks get the same weight when using a very large initial error matrix.

Definition at line 314 of file AdaptiveVertexFitter.cc.

References MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, mps_fire::i, AbstractLTSFactory< N >::linearizedTrackState(), VertexState::position(), theLinTrkFactory, and weightTracks().

Referenced by gsfIntermediarySmoothing(), and vertex().

316 {
317  const GlobalPoint & linP ( seed.position() );
318  vector<RefCountedLinearizedTrackState> lTracks;
319  for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
320  i != tracks.end(); ++i )
321  {
322  try {
325  lTracks.push_back(lTrData);
326  } catch ( exception & e ) {
327  LogInfo("RecoVertex/AdaptiveVertexFitter")
328  << "Exception " << e.what() << " in ::linearizeTracks."
329  << "Your future vertex has just lost a track.";
330  };
331  }
332  return weightTracks(lTracks, seed );
333 }
GlobalPoint position() const
Definition: VertexState.h:69
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
const AbstractLTSFactory< 5 > * theLinTrkFactory
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reLinearizeTracks ( const std::vector< RefCountedVertexTrack > &  tracks,
const CachingVertex< 5 > &  vertex 
) const
private

Construct new a container of VertexTrack with a new linearization point and vertex seed, from an existing set of VertexTrack, from which only the recTracks will be used.

Parameters
tracksThe original container of VertexTracks, from which the reco::TransientTracks will be extracted.
vertexThe seed to use for the VertexTracks. This position will also be used as the new linearization point.
Returns
The container of VertexTracks which are to be used in the next fit.

Construct new a container of VertexTrack with a new linearization point and vertex seed, from an existing set of VertexTrack, from which only the recTracks will be used.

Definition at line 341 of file AdaptiveVertexFitter.cc.

References MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, AbstractLTSFactory< N >::linearizedTrackState(), VertexState::position(), reWeightTracks(), SurveyInfoScenario_cff::seed, theLinTrkFactory, and CachingVertex< N >::vertexState().

Referenced by fit(), and gsfIntermediarySmoothing().

344 {
345  VertexState seed = vertex.vertexState();
346  GlobalPoint linP = seed.position();
347  vector<RefCountedLinearizedTrackState> lTracks;
348  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
349  i != tracks.end(); i++)
350  {
351  try {
353  = theLinTrkFactory->linearizedTrackState( linP, (**i).linearizedTrack()->track() );
354  /*
355  RefCountedLinearizedTrackState lTrData =
356  (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
357  */
358  lTracks.push_back(lTrData);
359  } catch ( exception & e ) {
360  LogInfo("RecoVertex/AdaptiveVertexFitter")
361  << "Exception " << e.what() << " in ::relinearizeTracks. "
362  << "Will not relinearize this track.";
363  lTracks.push_back ( (**i).linearizedTrack() );
364  };
365  };
366  return reWeightTracks(lTracks, vertex );
367 }
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
VertexState const & vertexState() const
GlobalPoint position() const
Definition: VertexState.h:69
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
const AbstractLTSFactory< 5 > * theLinTrkFactory
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reWeightTracks ( const std::vector< RefCountedLinearizedTrackState > &  lTracks,
const CachingVertex< 5 > &  seed 
) const
private

Construct a new container of VertexTracks with new weights accounting for vertex error, from an existing set of LinearizedTracks.

Definition at line 393 of file AdaptiveVertexFitter.cc.

References HiEvtPlane_cfi::chi2, AnnealingSchedule::currentTemp(), SoftLeptonByDistance_cfi::distance, MillePedeFileConverter_cfg::e, VertexTrackCompatibilityEstimator< N >::estimate(), cppFunctionSkipper::exception, FrontierConditions_GlobalTag_cff::file, getId(), getWeight(), mps_fire::i, funct::m, CachingVertex< N >::position(), SurveyInfoScenario_cff::seed, theAssProbComputer, theComp, theNr, CachingVertex< N >::vertexState(), VertexTrackFactory< N >::vertexTrack(), and AnnealingSchedule::weight().

Referenced by fit(), gsfIntermediarySmoothing(), reLinearizeTracks(), and reWeightTracks().

396 {
397  VertexState seed = vertex.vertexState();
398  // cout << "[AdaptiveVertexFitter] now reweight around " << seed.position() << endl;
399  theNr++;
400  // GlobalPoint pos = seed.position();
401 
402  vector<RefCountedVertexTrack> finalTracks;
403  VertexTrackFactory<5> vTrackFactory;
404  #ifdef STORE_WEIGHTS
405  iter++;
406  #endif
407  for(vector<RefCountedLinearizedTrackState>::const_iterator i
408  = lTracks.begin(); i != lTracks.end(); i++)
409  {
410  double weight=0.;
411  // cout << "[AdaptiveVertexFitter] estimate " << endl;
412  pair < bool, double > chi2Res ( false, 0. );
413  try {
414  chi2Res = theComp->estimate ( vertex, *i, std::distance(lTracks.begin(),i) );
415  } catch ( exception const & e ) {};
416  // cout << "[AdaptiveVertexFitter] /estimate " << endl;
417  if (!chi2Res.first) {
418  // cout << "[AdaptiveVertexFitter] aie... vertex candidate is at " << vertex.position() << endl;
419  LogInfo("AdaptiveVertexFitter" ) << "When reweighting, chi2<0. Will add this track with w=0.";
420  // edm::LogInfo("AdaptiveVertexFitter" ) << "pt=" << (**i).track().pt();
421  }else {
422  weight = getWeight ( chi2Res.second );
423  }
424 
425  RefCountedVertexTrack vTrData
426  = vTrackFactory.vertexTrack(*i, seed, weight );
427 
428  #ifdef STORE_WEIGHTS
429  map < string, dataharvester::MultiType > m;
430  m["chi2"]=chi2;
431  m["w"]=theAssProbComputer->weight(chi2);
433  m["n"]=iter;
434  m["pos"]="reweight";
435  m["id"]=getId ( *i );
436  dataharvester::Writer::file("w.txt").save ( m );
437  #endif
438 
439  finalTracks.push_back(vTrData);
440  }
441  sortByDistanceToRefPoint( finalTracks, vertex.position() );
442  // cout << "[AdaptiveVertexFitter] /now reweight" << endl;
443  return finalTracks;
444 }
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
VertexState const & vertexState() const
static unsigned int getId(void)
Definition: weight.py:1
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
virtual double weight(double chi2) const =0
virtual CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const
virtual double currentTemp() const =0
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
double getWeight(float chi2) const
GlobalPoint position() const
VertexTrackCompatibilityEstimator< 5 > * theComp
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reWeightTracks ( const std::vector< RefCountedVertexTrack > &  tracks,
const CachingVertex< 5 > &  seed 
) const
private

Construct new a container of VertexTracks with new weights accounting for vertex error, from an existing set of VertexTracks. From these the LinearizedTracks will be reused.

Construct new a container of VertexTrack with new weights accounting for vertex error, from an existing set of VertexTracks. From these the LinearizedTracks will be reused.

Definition at line 498 of file AdaptiveVertexFitter.cc.

References reWeightTracks().

501 {
502  vector<RefCountedLinearizedTrackState> lTracks;
503  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
504  i != tracks.end(); i++)
505  {
506  lTracks.push_back((**i).linearizedTrack());
507  }
508 
509  return reWeightTracks(lTracks, seed);
510 }
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
void AdaptiveVertexFitter::setParameters ( double  maxshift = 0.0001,
double  maxlpshift = 0.1,
unsigned  maxstep = 30,
double  weightthreshold = .001 
)

Reads the configurable parameters.

Parameters
maxshiftif the vertex moves further than this (in cm), then we re-iterate.
maxlpshiftif the vertex moves further than this, then we re-linearize the tracks.
maxstepthat's the maximum of iterations that we allow for.
weightthresholdthat's the minimum track weight for a track to be considered "significant". If fewer than two tracks are significant, an exception is thrown.

Definition at line 139 of file AdaptiveVertexFitter.cc.

References theMaxLPShift, theMaxShift, theMaxStep, theWeightThreshold, and vertexReco_cff::weightthreshold.

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter(), AdaptiveVertexFitter(), ConfigurableAdaptiveFitter::configure(), and setParameters().

void AdaptiveVertexFitter::setParameters ( const edm::ParameterSet s)

Sets parameters. The following parameters are expected: maxshift, maxlpshift, maxstep, weightthreshold

Definition at line 149 of file AdaptiveVertexFitter.cc.

References edm::ParameterSet::getParameter(), and setParameters().

150 {
151  setParameters ( s.getParameter<double>("maxshift"),
152  s.getParameter<double>("maxlpshift"),
153  s.getParameter<int>("maxstep"),
154  s.getParameter<double>("weightthreshold") );
155 }
T getParameter(std::string const &) const
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)
void AdaptiveVertexFitter::setWeightThreshold ( float  w)

Set the weight threshold should be used only to find (once) a good value FIXME this should disappear in the final version

Definition at line 111 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter(), theWeightThreshold, and w.

Referenced by PFTauPrimaryVertexProducer::produce(), and AdaptiveVertexReconstructor::setupFitters().

112 {
114 }
const double w
Definition: UKUtility.cc:23
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  unstracks) const
virtual

Method returning the fitted vertex, from a container of reco::TransientTracks. The linearization point will be searched with the given LP finder. No prior vertex position will be used in the vertex fit.

Returns
The fitted vertex

Implements VertexFitter< 5 >.

Definition at line 158 of file AdaptiveVertexFitter.cc.

References fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), SurveyInfoScenario_cff::seed, theLinP, and l1t::tracks.

Referenced by Tau.Tau::dxy(), NuclearVertexBuilder::FillVertexWithAdaptVtxFitter(), V0Fitter::fitAll(), PFDisplacedVertexFinder::fitVertexFromSeed(), gsfIntermediarySmoothing(), TemplatedInclusiveVertexFinder< InputContainer, VTX >::produce(), PFTauPrimaryVertexProducer::produce(), TrackVertexArbitration< VTX >::trackVertexArbitrator(), AdaptiveGsfVertexFitter::vertex(), and AdaptiveVertexReconstructor::vertices().

159 {
160  if ( unstracks.size() < 2 )
161  {
162  LogError("RecoVertex|AdaptiveVertexFitter")
163  << "Supplied fewer than two tracks. Vertex is invalid.";
164  return CachingVertex<5>(); // return invalid vertex
165  };
166  vector < reco::TransientTrack > tracks = unstracks;
167  sortTracksByPt( tracks);
168  // Linearization Point
169  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
170  // Initial vertex seed, with a very large error matrix
171  VertexState lseed (linP, linPointError );
172  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, lseed);
173 
174  VertexState seed (linP, fitError );
175  return fit(vtContainer, seed, false);
176 }
LinearizationPointFinder * theLinP
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< RefCountedVertexTrack > &  tracks) const
virtual

Method returning the fitted vertex, from a container of VertexTracks. For the first loop, the LinearizedTrack contained in the VertexTracks will be used. If subsequent loops are needed, the new VertexTracks will be created with the last estimate of the vertex as linearization point. No prior vertex position will be used in the vertex fit.

Returns
The fitted vertex

Definition at line 179 of file AdaptiveVertexFitter.cc.

References fit(), and SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

180 {
181  if ( tracks.size() < 2 )
182  {
183  LogError("RecoVertex|AdaptiveVertexFitter")
184  << "Supplied fewer than two tracks. Vertex is invalid.";
185  return CachingVertex<5>(); // return invalid vertex
186  };
187  // Initial vertex seed, with a very small weight matrix
188  GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
189  VertexState seed (linP, fitError );
190  return fit(tracks, seed, false);
191 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< RefCountedVertexTrack > &  tracks,
const reco::BeamSpot spot 
) const
virtual

Same as above, only now also with BeamSpot constraint.

Definition at line 194 of file AdaptiveVertexFitter.cc.

References fit().

Referenced by Tau.Tau::dxy().

195 {
196  if ( tracks.size() < 1 )
197  {
198  LogError("RecoVertex|AdaptiveVertexFitter")
199  << "Supplied no tracks. Vertex is invalid.";
200  return CachingVertex<5>(); // return invalid vertex
201  };
202  VertexState beamSpotState(spot);
203  return fit(tracks, beamSpotState, true );
204 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const GlobalPoint linPoint 
) const
virtual

Fit vertex out of a std::vector of reco::TransientTracks. Uses the specified linearization point.

Fit vertex out of a set of reco::TransientTracks. Uses the specified linearization point.

Implements VertexFitter< 5 >.

Definition at line 212 of file AdaptiveVertexFitter.cc.

References fit(), linearizeTracks(), and SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

214 {
215  if ( tracks.size() < 2 )
216  {
217  LogError("RecoVertex|AdaptiveVertexFitter")
218  << "Supplied fewer than two tracks. Vertex is invalid.";
219  return CachingVertex<5>(); // return invalid vertex
220  };
221  // Initial vertex seed, with a very large error matrix
222  VertexState seed (linPoint, linPointError );
223  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
224  VertexState fitseed (linPoint, fitError );
225  return fit(vtContainer, fitseed, false);
226 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const GlobalPoint priorPos,
const GlobalError priorError 
) const
virtual

Fit vertex out of a set of reco::TransientTracks. Uses the position as both the linearization point AND as prior estimate of the vertex position. The error is used for the weight of the prior estimate.

Implements VertexFitter< 5 >.

Definition at line 269 of file AdaptiveVertexFitter.cc.

References fit(), linearizeTracks(), and SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

273 {
274  if ( tracks.size() < 1 )
275  {
276  LogError("RecoVertex|AdaptiveVertexFitter")
277  << "Supplied no tracks. Vertex is invalid.";
278  return CachingVertex<5>(); // return invalid vertex
279  };
280  VertexState seed (priorPos, priorError);
281  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
282  return fit( vtContainer, seed, true );
283 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const reco::BeamSpot beamSpot 
) const
virtual

Fit vertex out of a set of TransientTracks. The specified BeamSpot will be used as priot, but NOT for the linearization. The specified LinearizationPointFinder will be used to find the linearization point.

Implements VertexFitter< 5 >.

Definition at line 234 of file AdaptiveVertexFitter.cc.

References fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), theLinP, and l1t::tracks.

Referenced by Tau.Tau::dxy().

236 {
237  if ( unstracks.size() < 1 )
238  {
239  LogError("RecoVertex|AdaptiveVertexFitter")
240  << "Supplied no tracks. Vertex is invalid.";
241  return CachingVertex<5>(); // return invalid vertex
242  };
243 
244  VertexState beamSpotState(beamSpot);
245  vector<RefCountedVertexTrack> vtContainer;
246 
247  vector < reco::TransientTrack > tracks = unstracks;
248  sortTracksByPt(tracks);
249 
250  if (tracks.size() > 1) {
251  // Linearization Point search if there are more than 1 track
252  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
253  VertexState lpState(linP, linPointError );
254  vtContainer = linearizeTracks(tracks, lpState);
255  } else {
256  // otherwise take the beamspot position.
257  vtContainer = linearizeTracks(tracks, beamSpotState);
258  }
259 
260  return fit(vtContainer, beamSpotState, true);
261 }
LinearizationPointFinder * theLinP
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< RefCountedVertexTrack > &  tracks,
const GlobalPoint priorPos,
const GlobalError priorError 
) const
virtual

Fit vertex out of a set of VertexTracks Uses the position and error for the prior estimate of the vertex. This position is not used to relinearize the tracks.

Definition at line 290 of file AdaptiveVertexFitter.cc.

References fit(), and SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

294 {
295  if ( tracks.size() < 1 )
296  {
297  LogError("RecoVertex|AdaptiveVertexFitter")
298  << "Supplied no tracks. Vertex is invalid.";
299  return CachingVertex<5>(); // return invalid vertex
300  };
301  VertexState seed (priorPos, priorError);
302  return fit(tracks, seed, true);
303 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::weightTracks ( const std::vector< RefCountedLinearizedTrackState > &  lTracks,
const VertexState seed 
) const
private

Weight the tracks, for the first time, using KalmanChiSquare.

track weighting, as opposed to re-weighting, must always be done with a reset annealer!

Definition at line 447 of file AdaptiveVertexFitter.cc.

References HiEvtPlane_cfi::chi2, AnnealingSchedule::currentTemp(), SoftLeptonByDistance_cfi::distance, VertexTrackCompatibilityEstimator< N >::estimate(), FrontierConditions_GlobalTag_cff::file, getId(), getWeight(), mps_fire::i, funct::m, AnnealingSchedule::resetAnnealing(), theAssProbComputer, theComp, theNr, VertexTrackFactory< N >::vertexTrack(), and AnnealingSchedule::weight().

Referenced by gsfIntermediarySmoothing(), and linearizeTracks().

450 {
451  theNr++;
452  CachingVertex<5> seedvtx ( seed, vector<RefCountedVertexTrack> (), 0. );
456 
457  vector<RefCountedVertexTrack> finalTracks;
458  VertexTrackFactory<5> vTrackFactory;
459  #ifdef STORE_WEIGHTS
460  iter++;
461  #endif
462  for(vector<RefCountedLinearizedTrackState>::const_iterator i
463  = lTracks.begin(); i != lTracks.end(); i++)
464  {
465 
466  double weight = 0.;
467  pair<bool, double> chi2Res = theComp->estimate ( seedvtx, *i, std::distance(lTracks.begin(),i) );
468  if (!chi2Res.first) {
469  // cout << "[AdaptiveVertexFitter] Aiee! " << endl;
470  LogInfo ("AdaptiveVertexFitter" ) << "When weighting a track, chi2 calculation failed;"
471  << " will add with w=0.";
472  } else {
473  weight = getWeight ( chi2Res.second );
474  }
475  RefCountedVertexTrack vTrData
476  = vTrackFactory.vertexTrack(*i, seed, weight );
477  #ifdef STORE_WEIGHTS
478  map < string, dataharvester::MultiType > m;
479  m["chi2"]=chi2;
480  m["w"]=theAssProbComputer->weight(chi2);
482  m["n"]=iter;
483  m["id"]=getId ( *i );
484  m["pos"]="weight";
485  dataharvester::Writer::file("w.txt").save ( m );
486  #endif
487  finalTracks.push_back(vTrData);
488  }
489  return finalTracks;
490 }
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
static unsigned int getId(void)
Definition: weight.py:1
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
virtual double weight(double chi2) const =0
virtual double currentTemp() const =0
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
double getWeight(float chi2) const
virtual void resetAnnealing()=0
VertexTrackCompatibilityEstimator< 5 > * theComp

Member Data Documentation

bool AdaptiveVertexFitter::gsfIntermediarySmoothing_
private

Definition at line 215 of file AdaptiveVertexFitter.h.

Referenced by fit(), and gsfIntermediarySmoothing().

AnnealingSchedule* AdaptiveVertexFitter::theAssProbComputer
private
VertexTrackCompatibilityEstimator<5>* AdaptiveVertexFitter::theComp
private

Definition at line 213 of file AdaptiveVertexFitter.h.

Referenced by reWeightTracks(), weightTracks(), and ~AdaptiveVertexFitter().

LinearizationPointFinder* AdaptiveVertexFitter::theLinP
private

Definition at line 209 of file AdaptiveVertexFitter.h.

Referenced by vertex(), and ~AdaptiveVertexFitter().

const AbstractLTSFactory<5>* AdaptiveVertexFitter::theLinTrkFactory
private
double AdaptiveVertexFitter::theMaxLPShift
private

Definition at line 204 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

double AdaptiveVertexFitter::theMaxShift
private

Definition at line 203 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

int AdaptiveVertexFitter::theMaxStep
private

Definition at line 205 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

int AdaptiveVertexFitter::theNr
mutableprivate

Definition at line 207 of file AdaptiveVertexFitter.h.

Referenced by reWeightTracks(), and weightTracks().

VertexSmoother<5>* AdaptiveVertexFitter::theSmoother
private

Definition at line 211 of file AdaptiveVertexFitter.h.

Referenced by fit(), and ~AdaptiveVertexFitter().

VertexUpdator<5>* AdaptiveVertexFitter::theUpdator
private

Definition at line 210 of file AdaptiveVertexFitter.h.

Referenced by fit(), and ~AdaptiveVertexFitter().

double AdaptiveVertexFitter::theWeightThreshold
private

Definition at line 206 of file AdaptiveVertexFitter.h.

Referenced by fit(), setParameters(), and setWeightThreshold().