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

References setParameters().

Referenced by clone().

97  :
98  theNr(0),
99  theLinP(linP.clone()), theUpdator( updator.clone()),
100  theSmoother ( smoother.clone() ), theAssProbComputer( ann.clone() ),
101  theComp ( crit.clone() ), theLinTrkFactory ( ltsf.clone() ),
103 {
104  setParameters();
105 }
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 113 of file AdaptiveVertexFitter.cc.

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

Definition at line 125 of file AdaptiveVertexFitter.cc.

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

126 {
127  delete theLinP;
128  delete theUpdator;
129  delete theSmoother;
130  delete theAssProbComputer;
131  delete theComp;
132  delete theLinTrkFactory;
133 }
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 365 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter().

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter().

366 {
367  return new AdaptiveVertexFitter( * this );
368 }
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 514 of file AdaptiveVertexFitter.cc.

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

Referenced by vertex().

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

Definition at line 370 of file AdaptiveVertexFitter.cc.

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

Referenced by reWeightTracks(), and weightTracks().

371 {
372  double weight = theAssProbComputer->weight(chi2);
373 
374  if ( weight > 1.0 )
375  {
376  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " > 1.0!";
377  weight=1.0;
378  };
379 
380  if ( weight < 1e-20 )
381  {
382  // LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " < 0.0!";
383  weight=1e-20;
384  };
385  return weight;
386 }
AnnealingSchedule * theAssProbComputer
int weight
Definition: histoStyle.py:50
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 310 of file AdaptiveVertexFitter.cc.

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

Referenced by vertex().

312 {
313  const GlobalPoint & linP ( seed.position() );
314  vector<RefCountedLinearizedTrackState> lTracks;
315  for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
316  i != tracks.end(); ++i )
317  {
318  try {
321  lTracks.push_back(lTrData);
322  } catch ( exception & e ) {
323  LogInfo("RecoVertex/AdaptiveVertexFitter")
324  << "Exception " << e.what() << " in ::linearizeTracks."
325  << "Your future vertex has just lost a track.";
326  };
327  }
328  return weightTracks(lTracks, seed );
329 }
int i
Definition: DBlmapReader.cc:9
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
GlobalPoint position() const
Definition: VertexState.h:50
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 337 of file AdaptiveVertexFitter.cc.

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

Referenced by fit().

340 {
341  VertexState seed = vertex.vertexState();
342  GlobalPoint linP = seed.position();
343  vector<RefCountedLinearizedTrackState> lTracks;
344  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
345  i != tracks.end(); i++)
346  {
347  try {
349  = theLinTrkFactory->linearizedTrackState( linP, (**i).linearizedTrack()->track() );
350  /*
351  RefCountedLinearizedTrackState lTrData =
352  (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
353  */
354  lTracks.push_back(lTrData);
355  } catch ( exception & e ) {
356  LogInfo("RecoVertex/AdaptiveVertexFitter")
357  << "Exception " << e.what() << " in ::relinearizeTracks. "
358  << "Will not relinearize this track.";
359  lTracks.push_back ( (**i).linearizedTrack() );
360  };
361  };
362  return reWeightTracks(lTracks, vertex );
363 }
int i
Definition: DBlmapReader.cc:9
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
VertexState const & vertexState() const
Definition: CachingVertex.h:85
GlobalPoint position() const
Definition: VertexState.h:50
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 389 of file AdaptiveVertexFitter.cc.

References AnnealingSchedule::currentTemp(), alignCSCRings::e, VertexTrackCompatibilityEstimator< N >::estimate(), cppFunctionSkipper::exception, mergeVDriftHistosByStation::file, getId(), getWeight(), i, getDQMSummary::iter, m, CachingVertex< N >::position(), fileCollector::seed, theAssProbComputer, theComp, theNr, CachingVertex< N >::vertexState(), VertexTrackFactory< N >::vertexTrack(), AnnealingSchedule::weight(), and histoStyle::weight.

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

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

References reWeightTracks().

497 {
498  vector<RefCountedLinearizedTrackState> lTracks;
499  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
500  i != tracks.end(); i++)
501  {
502  lTracks.push_back((**i).linearizedTrack());
503  }
504 
505  return reWeightTracks(lTracks, seed);
506 }
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 135 of file AdaptiveVertexFitter.cc.

References theMaxLPShift, theMaxShift, theMaxStep, and theWeightThreshold.

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

137 {
138  theMaxShift = maxshift;
139  theMaxLPShift = maxlpshift;
140  theMaxStep = maxstep;
141  theWeightThreshold=weightthreshold;
142 }
void AdaptiveVertexFitter::setParameters ( const edm::ParameterSet s)

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

Definition at line 145 of file AdaptiveVertexFitter.cc.

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

146 {
147  setParameters ( s.getParameter<double>("maxshift"),
148  s.getParameter<double>("maxlpshift"),
149  s.getParameter<int>("maxstep"),
150  s.getParameter<double>("weightthreshold") );
151 }
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 107 of file AdaptiveVertexFitter.cc.

References theWeightThreshold, and w.

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

108 {
110 }
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 154 of file AdaptiveVertexFitter.cc.

References fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), fileCollector::seed, theLinP, and testEve_cfg::tracks.

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

155 {
156  if ( unstracks.size() < 2 )
157  {
158  LogError("RecoVertex|AdaptiveVertexFitter")
159  << "Supplied fewer than two tracks. Vertex is invalid.";
160  return CachingVertex<5>(); // return invalid vertex
161  };
162  vector < reco::TransientTrack > tracks = unstracks;
163  sortTracksByPt( tracks);
164  // Linearization Point
165  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
166  // Initial vertex seed, with a very large error matrix
167  VertexState lseed (linP, linPointError );
168  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, lseed);
169 
170  VertexState seed (linP, fitError );
171  return fit(vtContainer, seed, false);
172 }
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 175 of file AdaptiveVertexFitter.cc.

References fit(), and fileCollector::seed.

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

176 {
177  if ( tracks.size() < 2 )
178  {
179  LogError("RecoVertex|AdaptiveVertexFitter")
180  << "Supplied fewer than two tracks. Vertex is invalid.";
181  return CachingVertex<5>(); // return invalid vertex
182  };
183  // Initial vertex seed, with a very small weight matrix
184  GlobalPoint linP = tracks[0]->linearizedTrack()->linearizationPoint();
185  VertexState seed (linP, fitError );
186  return fit(tracks, seed, false);
187 }
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 190 of file AdaptiveVertexFitter.cc.

References fit().

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

191 {
192  if ( tracks.size() < 1 )
193  {
194  LogError("RecoVertex|AdaptiveVertexFitter")
195  << "Supplied no tracks. Vertex is invalid.";
196  return CachingVertex<5>(); // return invalid vertex
197  };
198  VertexState beamSpotState(spot);
199  return fit(tracks, beamSpotState, true );
200 }
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 208 of file AdaptiveVertexFitter.cc.

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

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

210 {
211  if ( tracks.size() < 2 )
212  {
213  LogError("RecoVertex|AdaptiveVertexFitter")
214  << "Supplied fewer than two tracks. Vertex is invalid.";
215  return CachingVertex<5>(); // return invalid vertex
216  };
217  // Initial vertex seed, with a very large error matrix
218  VertexState seed (linPoint, linPointError );
219  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
220  VertexState fitseed (linPoint, fitError );
221  return fit(vtContainer, fitseed, false);
222 }
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 265 of file AdaptiveVertexFitter.cc.

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

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

269 {
270  if ( tracks.size() < 1 )
271  {
272  LogError("RecoVertex|AdaptiveVertexFitter")
273  << "Supplied no tracks. Vertex is invalid.";
274  return CachingVertex<5>(); // return invalid vertex
275  };
276  VertexState seed (priorPos, priorError);
277  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
278  return fit( vtContainer, seed, true );
279 }
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 230 of file AdaptiveVertexFitter.cc.

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

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

232 {
233  if ( unstracks.size() < 1 )
234  {
235  LogError("RecoVertex|AdaptiveVertexFitter")
236  << "Supplied no tracks. Vertex is invalid.";
237  return CachingVertex<5>(); // return invalid vertex
238  };
239 
240  VertexState beamSpotState(beamSpot);
241  vector<RefCountedVertexTrack> vtContainer;
242 
243  vector < reco::TransientTrack > tracks = unstracks;
244  sortTracksByPt(tracks);
245 
246  if (tracks.size() > 1) {
247  // Linearization Point search if there are more than 1 track
248  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
249  VertexState lpState(linP, linPointError );
250  vtContainer = linearizeTracks(tracks, lpState);
251  } else {
252  // otherwise take the beamspot position.
253  vtContainer = linearizeTracks(tracks, beamSpotState);
254  }
255 
256  return fit(vtContainer, beamSpotState, true);
257 }
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 286 of file AdaptiveVertexFitter.cc.

References fit(), and fileCollector::seed.

Referenced by Tau.Tau::dxy(), and Tau.Tau::dz().

290 {
291  if ( tracks.size() < 1 )
292  {
293  LogError("RecoVertex|AdaptiveVertexFitter")
294  << "Supplied no tracks. Vertex is invalid.";
295  return CachingVertex<5>(); // return invalid vertex
296  };
297  VertexState seed (priorPos, priorError);
298  return fit(tracks, seed, true);
299 }
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 443 of file AdaptiveVertexFitter.cc.

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

Referenced by linearizeTracks().

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

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