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

References setParameters().

Referenced by clone().

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

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

Definition at line 128 of file AdaptiveVertexFitter.cc.

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

129 {
130  delete theLinP;
131  delete theUpdator;
132  delete theSmoother;
133  delete theAssProbComputer;
134  delete theComp;
135  delete theLinTrkFactory;
136 }
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 368 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter().

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter().

369 {
370  return new AdaptiveVertexFitter( * this );
371 }
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(), AnnealingSchedule::currentTemp(), VertexState::error(), mergeVDriftHistosByStation::file, getId(), gsfIntermediarySmoothing_, i, 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, transverse(), AnnealingSchedule::weight(), and PV3DBase< T, PVType, FrameType >::z().

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

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

Referenced by reWeightTracks(), and weightTracks().

374 {
375  double weight = theAssProbComputer->weight(chi2);
376 
377  if ( weight > 1.0 )
378  {
379  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " > 1.0!";
380  weight=1.0;
381  };
382 
383  if ( weight < 1e-20 )
384  {
385  // LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " < 0.0!";
386  weight=1e-20;
387  };
388  return weight;
389 }
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 313 of file AdaptiveVertexFitter.cc.

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

Referenced by vertex().

315 {
316  const GlobalPoint & linP ( seed.position() );
317  vector<RefCountedLinearizedTrackState> lTracks;
318  for(vector<reco::TransientTrack>::const_iterator i = tracks.begin();
319  i != tracks.end(); ++i )
320  {
321  try {
324  lTracks.push_back(lTrData);
325  } catch ( exception & e ) {
326  LogInfo("RecoVertex/AdaptiveVertexFitter")
327  << "Exception " << e.what() << " in ::linearizeTracks."
328  << "Your future vertex has just lost a track.";
329  };
330  }
331  return weightTracks(lTracks, seed );
332 }
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 340 of file AdaptiveVertexFitter.cc.

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

Referenced by fit().

343 {
344  VertexState seed = vertex.vertexState();
345  GlobalPoint linP = seed.position();
346  vector<RefCountedLinearizedTrackState> lTracks;
347  for(vector<RefCountedVertexTrack>::const_iterator i = tracks.begin();
348  i != tracks.end(); i++)
349  {
350  try {
352  = theLinTrkFactory->linearizedTrackState( linP, (**i).linearizedTrack()->track() );
353  /*
354  RefCountedLinearizedTrackState lTrData =
355  (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
356  */
357  lTracks.push_back(lTrData);
358  } catch ( exception & e ) {
359  LogInfo("RecoVertex/AdaptiveVertexFitter")
360  << "Exception " << e.what() << " in ::relinearizeTracks. "
361  << "Will not relinearize this track.";
362  lTracks.push_back ( (**i).linearizedTrack() );
363  };
364  };
365  return reWeightTracks(lTracks, vertex );
366 }
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 392 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, python.multivaluedict::sort(), theAssProbComputer, theComp, theNr, CachingVertex< N >::vertexState(), VertexTrackFactory< N >::vertexTrack(), AnnealingSchedule::weight(), and histoStyle::weight.

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

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

References i, and 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 }
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 138 of file AdaptiveVertexFitter.cc.

References theMaxLPShift, theMaxShift, theMaxStep, and theWeightThreshold.

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

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

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

Definition at line 148 of file AdaptiveVertexFitter.cc.

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

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

References theWeightThreshold, and w.

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

111 {
113 }
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 157 of file AdaptiveVertexFitter.cc.

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

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

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

References fit(), and fileCollector::seed.

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

References fit().

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

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

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

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

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

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

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

References fit(), and fileCollector::seed.

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

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