CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
< RefCountedVertexTrack
linearizeTracks (const std::vector< reco::TransientTrack > &, const VertexState &) const
 
std::vector
< RefCountedVertexTrack
reLinearizeTracks (const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
 
std::vector
< RefCountedVertexTrack
reWeightTracks (const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
 
std::vector
< RefCountedVertexTrack
reWeightTracks (const std::vector< RefCountedVertexTrack > &, const CachingVertex< 5 > &seed) const
 
std::vector
< RefCountedVertexTrack
weightTracks (const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
 

Private Attributes

bool gsfIntermediarySmoothing_
 
int mctr_
 
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 98 of file AdaptiveVertexFitter.cc.

References setParameters().

Referenced by clone().

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

Definition at line 120 of file AdaptiveVertexFitter.cc.

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

Definition at line 132 of file AdaptiveVertexFitter.cc.

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

133 {
134  delete theLinP;
135  delete theUpdator;
136  delete theSmoother;
137  delete theAssProbComputer;
138  delete theComp;
139  delete theLinTrkFactory;
140 }
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 372 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter().

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter().

373 {
374  return new AdaptiveVertexFitter( * this );
375 }
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 522 of file AdaptiveVertexFitter.cc.

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

Referenced by vertex().

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

Definition at line 377 of file AdaptiveVertexFitter.cc.

References alignCSCRings::e, theAssProbComputer, AnnealingSchedule::weight(), and CommonMethods::weight().

Referenced by reWeightTracks(), and weightTracks().

378 {
379  double weight = theAssProbComputer->weight(chi2);
380 
381  if ( weight > 1.0 )
382  {
383  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " > 1.0!";
384  weight=1.0;
385  };
386 
387  if ( weight < 1e-20 )
388  {
389  // LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " < 0.0!";
390  weight=1e-20;
391  };
392  return weight;
393 }
AnnealingSchedule * theAssProbComputer
virtual double weight(double chi2) const =0
void AdaptiveVertexFitter::gsfIntermediarySmoothing ( bool  sm)
inline
bool AdaptiveVertexFitter::gsfIntermediarySmoothing ( ) const
inline

Definition at line 143 of file AdaptiveVertexFitter.h.

References gsfIntermediarySmoothing_.

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 317 of file AdaptiveVertexFitter.cc.

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

Referenced by vertex().

319 {
320  const GlobalPoint & linP ( seed.position() );
321  vector<RefCountedLinearizedTrackState> lTracks;
322  for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
323  i != tracks.end(); ++i )
324  {
325  try {
328  lTracks.push_back(lTrData);
329  } catch ( exception & e ) {
330  LogInfo("RecoVertex/AdaptiveVertexFitter")
331  << "Exception " << e.what() << " in ::linearizeTracks."
332  << "Your future vertex has just lost a track.";
333  };
334  }
335  return weightTracks(lTracks, seed );
336 }
int i
Definition: DBlmapReader.cc:9
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
GlobalPoint position() const
Definition: VertexState.h:29
tuple tracks
Definition: testEve_cfg.py:39
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 344 of file AdaptiveVertexFitter.cc.

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

Referenced by fit().

347 {
348  VertexState seed = vertex.vertexState();
349  GlobalPoint linP = seed.position();
350  vector<RefCountedLinearizedTrackState> lTracks;
351  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
352  i != tracks.end(); i++)
353  {
354  try {
356  = theLinTrkFactory->linearizedTrackState( linP, (**i).linearizedTrack()->track() );
357  /*
358  RefCountedLinearizedTrackState lTrData =
359  (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
360  */
361  lTracks.push_back(lTrData);
362  } catch ( exception & e ) {
363  LogInfo("RecoVertex/AdaptiveVertexFitter")
364  << "Exception " << e.what() << " in ::relinearizeTracks. "
365  << "Will not relinearize this track.";
366  lTracks.push_back ( (**i).linearizedTrack() );
367  };
368  };
369  return reWeightTracks(lTracks, vertex );
370 }
int i
Definition: DBlmapReader.cc:9
VertexState vertexState() const
Definition: CachingVertex.h:85
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
GlobalPoint position() const
Definition: VertexState.h:29
tuple tracks
Definition: testEve_cfg.py:39
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 396 of file AdaptiveVertexFitter.cc.

References AnnealingSchedule::currentTemp(), VertexTrackCompatibilityEstimator< N >::estimate(), mergeVDriftHistosByStation::file, getId(), getWeight(), i, m, CachingVertex< N >::position(), python.multivaluedict::sort(), theAssProbComputer, theComp, theNr, CachingVertex< N >::vertexState(), VertexTrackFactory< N >::vertexTrack(), AnnealingSchedule::weight(), and CommonMethods::weight().

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

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

References i, and reWeightTracks().

505 {
506  vector<RefCountedLinearizedTrackState> lTracks;
507  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
508  i != tracks.end(); i++)
509  {
510  lTracks.push_back((**i).linearizedTrack());
511  }
512 
513  return reWeightTracks(lTracks, seed);
514 }
int i
Definition: DBlmapReader.cc:9
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
tuple tracks
Definition: testEve_cfg.py:39
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 142 of file AdaptiveVertexFitter.cc.

References theMaxLPShift, theMaxShift, theMaxStep, and theWeightThreshold.

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

144 {
145  theMaxShift = maxshift;
146  theMaxLPShift = maxlpshift;
147  theMaxStep = maxstep;
148  theWeightThreshold=weightthreshold;
149 }
void AdaptiveVertexFitter::setParameters ( const edm::ParameterSet s)

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

Definition at line 152 of file AdaptiveVertexFitter.cc.

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

153 {
154  setParameters ( s.getParameter<double>("maxshift"),
155  s.getParameter<double>("maxlpshift"),
156  s.getParameter<int>("maxstep"),
157  s.getParameter<double>("weightthreshold") );
158 }
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 114 of file AdaptiveVertexFitter.cc.

References theWeightThreshold, and w().

Referenced by AdaptiveVertexReconstructor::setupFitters().

115 {
117 }
T w() const
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 161 of file AdaptiveVertexFitter.cc.

References fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), python.multivaluedict::sort(), theLinP, and testEve_cfg::tracks.

Referenced by NuclearVertexBuilder::FillVertexWithAdaptVtxFitter(), V0Fitter::fitAll(), PFDisplacedVertexFinder::fitVertexFromSeed(), PrimaryVertexAnalyzer4PU::getSimEvents(), InclusiveVertexFinder::produce(), TrackVertexArbitration::trackVertexArbitrator(), AdaptiveGsfVertexFitter::vertex(), and AdaptiveVertexReconstructor::vertices().

162 {
163  if ( unstracks.size() < 2 )
164  {
165  LogError("RecoVertex|AdaptiveVertexFitter")
166  << "Supplied fewer than two tracks. Vertex is invalid.";
167  return CachingVertex<5>(); // return invalid vertex
168  };
169  vector < reco::TransientTrack > tracks = unstracks;
170  sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
171  // Linearization Point
172  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
173  // Initial vertex seed, with a very large error matrix
174  VertexState lseed (linP, linPointError() );
175  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, lseed);
176 
177  VertexState seed (linP, fitError() );
178  return fit(vtContainer, seed, false);
179 }
LinearizationPointFinder * theLinP
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 182 of file AdaptiveVertexFitter.cc.

References fit().

183 {
184  if ( tracks.size() < 2 )
185  {
186  LogError("RecoVertex|AdaptiveVertexFitter")
187  << "Supplied fewer than two tracks. Vertex is invalid.";
188  return CachingVertex<5>(); // return invalid vertex
189  };
190  // Initial vertex seed, with a very small weight matrix
191  GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
192  VertexState seed (linP, fitError() );
193  return fit(tracks, seed, false);
194 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 197 of file AdaptiveVertexFitter.cc.

References fit().

198 {
199  if ( tracks.size() < 1 )
200  {
201  LogError("RecoVertex|AdaptiveVertexFitter")
202  << "Supplied no tracks. Vertex is invalid.";
203  return CachingVertex<5>(); // return invalid vertex
204  };
205  VertexState beamSpotState(spot);
206  return fit(tracks, beamSpotState, true );
207 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 215 of file AdaptiveVertexFitter.cc.

References fit(), and linearizeTracks().

217 {
218  if ( tracks.size() < 2 )
219  {
220  LogError("RecoVertex|AdaptiveVertexFitter")
221  << "Supplied fewer than two tracks. Vertex is invalid.";
222  return CachingVertex<5>(); // return invalid vertex
223  };
224  // Initial vertex seed, with a very large error matrix
225  VertexState seed (linPoint, linPointError() );
226  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
227  VertexState fitseed (linPoint, fitError() );
228  return fit(vtContainer, fitseed, false);
229 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 272 of file AdaptiveVertexFitter.cc.

References fit(), and linearizeTracks().

276 {
277  if ( tracks.size() < 1 )
278  {
279  LogError("RecoVertex|AdaptiveVertexFitter")
280  << "Supplied no tracks. Vertex is invalid.";
281  return CachingVertex<5>(); // return invalid vertex
282  };
283  VertexState seed (priorPos, priorError);
284  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
285  return fit( vtContainer, seed, true );
286 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 237 of file AdaptiveVertexFitter.cc.

References fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), python.multivaluedict::sort(), theLinP, and testEve_cfg::tracks.

239 {
240  if ( unstracks.size() < 1 )
241  {
242  LogError("RecoVertex|AdaptiveVertexFitter")
243  << "Supplied no tracks. Vertex is invalid.";
244  return CachingVertex<5>(); // return invalid vertex
245  };
246 
247  VertexState beamSpotState(beamSpot);
248  vector<RefCountedVertexTrack> vtContainer;
249 
250  vector < reco::TransientTrack > tracks = unstracks;
251  sort ( tracks.begin(), tracks.end(), CompareTwoTracks() );
252 
253  if (tracks.size() > 1) {
254  // Linearization Point search if there are more than 1 track
255  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
256  VertexState lpState(linP, linPointError() );
257  vtContainer = linearizeTracks(tracks, lpState);
258  } else {
259  // otherwise take the beamspot position.
260  vtContainer = linearizeTracks(tracks, beamSpotState);
261  }
262 
263  return fit(vtContainer, beamSpotState, true);
264 }
LinearizationPointFinder * theLinP
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 293 of file AdaptiveVertexFitter.cc.

References fit().

297 {
298  if ( tracks.size() < 1 )
299  {
300  LogError("RecoVertex|AdaptiveVertexFitter")
301  << "Supplied no tracks. Vertex is invalid.";
302  return CachingVertex<5>(); // return invalid vertex
303  };
304  VertexState seed (priorPos, priorError);
305  return fit(tracks, seed, true);
306 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
tuple tracks
Definition: testEve_cfg.py:39
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 451 of file AdaptiveVertexFitter.cc.

References AnnealingSchedule::currentTemp(), VertexTrackCompatibilityEstimator< N >::estimate(), mergeVDriftHistosByStation::file, getId(), getWeight(), i, m, AnnealingSchedule::resetAnnealing(), theAssProbComputer, theComp, theNr, VertexTrackFactory< N >::vertexTrack(), AnnealingSchedule::weight(), and CommonMethods::weight().

Referenced by linearizeTracks().

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

Member Data Documentation

bool AdaptiveVertexFitter::gsfIntermediarySmoothing_
private

Definition at line 215 of file AdaptiveVertexFitter.h.

Referenced by fit(), and gsfIntermediarySmoothing().

int AdaptiveVertexFitter::mctr_
mutableprivate

Definition at line 216 of file AdaptiveVertexFitter.h.

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().