CMS 3D CMS Logo

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

#include <AdaptiveVertexFitter.h>

Inheritance diagram for AdaptiveVertexFitter:
VertexFitter< 5 >

Public Types

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

Public Member Functions

 AdaptiveVertexFitter (const AnnealingSchedule &ann=GeometricAnnealing(), const LinearizationPointFinder &linP=DefaultLinearizationPointFinder(), const VertexUpdator< 5 > &updator=KalmanVertexUpdator< 5 >(), const VertexTrackCompatibilityEstimator< 5 > &estor=KalmanVertexTrackCompatibilityEstimator< 5 >(), const VertexSmoother< 5 > &smoother=DummyVertexSmoother< 5 >(), const AbstractLTSFactory< 5 > &ltsf=LinearizedTrackStateFactory())
 
 AdaptiveVertexFitter (const AdaptiveVertexFitter &original)
 
AdaptiveVertexFitterclone () const override
 
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)
 
CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &) const override
 
CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &) const override
 
CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &, const reco::BeamSpot &spot) const override
 
CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &, const GlobalPoint &linPoint) const override
 
CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &, const GlobalPoint &priorPos, const GlobalError &priorError) const override
 
CachingVertex< 5 > vertex (const std::vector< reco::TransientTrack > &tracks, const reco::BeamSpot &beamSpot) const override
 
CachingVertex< 5 > vertex (const std::vector< RefCountedVertexTrack > &, const GlobalPoint &priorPos, const GlobalError &priorError) const override
 
 ~AdaptiveVertexFitter () override
 
- Public Member Functions inherited from VertexFitter< 5 >
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks) const =0
 
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks, const reco::BeamSpot &spot) const =0
 
virtual CachingVertex< Nvertex (const std::vector< typename CachingVertex< N >::RefCountedVertexTrack > &tracks, const GlobalPoint &priorPos, const GlobalError &priorError) const =0
 
 VertexFitter ()
 
virtual ~VertexFitter ()
 

Private Member Functions

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

Private Attributes

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

Detailed Description

An iterative reweighted fitter. Very robust, very adaptive.

See CMS Note 2007/008.

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

Definition at line 29 of file AdaptiveVertexFitter.h.

Member Typedef Documentation

Definition at line 32 of file AdaptiveVertexFitter.h.

Definition at line 31 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 102 of file AdaptiveVertexFitter.cc.

References setParameters().

Referenced by clone().

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

Definition at line 121 of file AdaptiveVertexFitter.cc.

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

Definition at line 135 of file AdaptiveVertexFitter.cc.

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

135  {
136  delete theLinP;
137  delete theUpdator;
138  delete theSmoother;
139  delete theAssProbComputer;
140  delete theComp;
141  delete theLinTrkFactory;
142 }
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
overridevirtual

Fit vertex out of a VertexSeed

Implements VertexFitter< 5 >.

Definition at line 327 of file AdaptiveVertexFitter.cc.

References AdaptiveVertexFitter().

Referenced by AdaptiveGsfVertexFitter::AdaptiveGsfVertexFitter().

327 { return new AdaptiveVertexFitter(*this); }
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 451 of file AdaptiveVertexFitter.cc.

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

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

453  {
454  // cout << "[AdaptiveVertexFit] fit with " << tracks.size() << endl;
456 
457  vector<RefCountedVertexTrack> initialTracks;
458  GlobalPoint priorVertexPosition = priorSeed.position();
459  GlobalError priorVertexError = priorSeed.error();
460 
461  CachingVertex<5> returnVertex(priorVertexPosition, priorVertexError, initialTracks, 0);
462  if (withPrior) {
463  returnVertex = CachingVertex<5>(
464  priorVertexPosition, priorVertexError, priorVertexPosition, priorVertexError, initialTracks, 0);
465  }
466 
467  std::vector<RefCountedVertexTrack> globalVTracks = tracks;
468  // sort the tracks, according to distance to seed!
469  sortByDistanceToRefPoint(globalVTracks, priorSeed.position());
470 
471  // main loop through all the VTracks
472  int lpStep = 0;
473  int step = 0;
474 
475  CachingVertex<5> initialVertex = returnVertex;
476 
477  GlobalPoint newPosition = priorVertexPosition;
478  GlobalPoint previousPosition = newPosition;
479 
480  int ns_trks = 0; // number of significant tracks.
481  // If we have only two significant tracks, we return an invalid vertex
482 
483  // cout << "[AdaptiveVertexFit] start " << tracks.size() << endl;
484  /*
485  for ( vector< RefCountedVertexTrack >::const_iterator
486  i=globalVTracks.begin(); i!=globalVTracks.end() ; ++i )
487  {
488  cout << " " << (**i).linearizedTrack()->track().initialFreeState().momentum() << endl;
489  }*/
490  do {
491  ns_trks = 0;
492  CachingVertex<5> fVertex = initialVertex;
493  // cout << "[AdaptiveVertexFit] step " << step << " at " << fVertex.position() << endl;
494  if ((previousPosition - newPosition).transverse() > theMaxLPShift) {
495  // relinearize and reweight.
496  // (reLinearizeTracks also reweights tracks)
497  // cout << "[AdaptiveVertexFit] relinearize at " << returnVertex.position() << endl;
499  returnVertex = theSmoother->smooth(returnVertex);
500  globalVTracks = reLinearizeTracks(globalVTracks, returnVertex);
501  lpStep++;
502  } else if (step) {
503  // reweight, if it is not the first step
504  // cout << "[AdaptiveVertexFit] reweight at " << returnVertex.position() << endl;
506  returnVertex = theSmoother->smooth(returnVertex);
507  globalVTracks = reWeightTracks(globalVTracks, returnVertex);
508  }
509  // cout << "[AdaptiveVertexFit] relinarized, reweighted" << endl;
510  // update sequentially the vertex estimate
512  for (vector<RefCountedVertexTrack>::const_iterator i = globalVTracks.begin(); i != globalVTracks.end(); i++) {
513  if ((**i).weight() > 0.)
514  nVertex = theUpdator->add(fVertex, *i);
515  else
516  nVertex = fVertex;
517  if (nVertex.isValid()) {
518  if ((**i).weight() >= theWeightThreshold)
519  ns_trks++;
520 
521  if (fabs(nVertex.position().z()) > 10000. || nVertex.position().perp() > 120.) {
522  // were more than 100 m off!!
523  LogInfo("AdaptiveVertexFitter")
524  << "Vertex candidate just took off to " << nVertex.position() << "! Will discard this update!";
525  // //<< "track pt was " << (**i).linearizedTrack()->track().pt()
526  // << "track momentum was " << (**i).linearizedTrack()->track().initialFreeState().momentum()
527  // << "track position was " << (**i).linearizedTrack()->track().initialFreeState().position()
528  // << "track chi2 was " << (**i).linearizedTrack()->track().chi2()
529  // << "track ndof was " << (**i).linearizedTrack()->track().ndof()
530  // << "track w was " << (**i).weight()
531  // << "track schi2 was " << (**i).smoothedChi2();
532  } else {
533  fVertex = nVertex;
534  }
535  } else {
536  LogInfo("RecoVertex/AdaptiveVertexFitter")
537  << "The updator returned an invalid vertex when adding track " << i - globalVTracks.begin()
538  << ".\n Your vertex might just have lost one good track.";
539  }
540  }
541  previousPosition = newPosition;
542  newPosition = fVertex.position();
543  returnVertex = fVertex;
545  step++;
546  if (step >= theMaxStep)
547  break;
548 
549  } while (
550  // repeat as long as
551  // - vertex moved too much or
552  // - we're not yet annealed
553  (((previousPosition - newPosition).mag() > theMaxShift) || (!(theAssProbComputer->isAnnealed()))));
554 
555  if (theWeightThreshold > 0. && ns_trks < 2 && !withPrior) {
556  LogDebug("AdaptiveVertexFitter") << "fewer than two significant tracks (w>" << theWeightThreshold << ")."
557  << " Fitted vertex is invalid.";
558  return CachingVertex<5>(); // return invalid vertex
559  }
560 
561 #ifdef STORE_WEIGHTS
562  map<string, dataharvester::MultiType> m;
563  m["chi2"] = chi2;
564  m["w"] = theAssProbComputer->weight(chi2);
565  m["T"] = theAssProbComputer->currentTemp();
566  m["n"] = iter;
567  m["id"] = getId(*i);
568  m["pos"] = "final";
569  dataharvester::Writer::file("w.txt").save(m);
570 #endif
571  // cout << "[AdaptiveVertexFit] /fit" << endl;
572  return theSmoother->smooth(returnVertex);
573 }
#define LogDebug(id)
static unsigned int getId()
T perp() const
Definition: PV3DBase.h:69
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
VertexUpdator< 5 > * theUpdator
virtual double weight(double chi2) const =0
GlobalPoint position() const
Definition: VertexState.h:62
std::vector< RefCountedVertexTrack > reLinearizeTracks(const std::vector< RefCountedVertexTrack > &tracks, const CachingVertex< 5 > &vertex) const
virtual CachingVertex< N > smooth(const CachingVertex< N > &vertex) const =0
virtual bool isAnnealed() const =0
T z() const
Definition: PV3DBase.h:61
virtual double currentTemp() const =0
VertexSmoother< 5 > * theSmoother
AnnealingSchedule * theAssProbComputer
virtual CachingVertex< N > add(const CachingVertex< N > &v, const typename CachingVertex< N >::RefCountedVertexTrack t) const =0
GlobalPoint position() const
bool isValid() const
virtual void anneal()=0
virtual void resetAnnealing()=0
GlobalError error() const
Definition: VertexState.h:64
step
Definition: StallMonitor.cc:94
double AdaptiveVertexFitter::getWeight ( float  chi2) const
private

Definition at line 329 of file AdaptiveVertexFitter.cc.

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

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

329  {
331 
332  if (weight > 1.0) {
333  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " > 1.0!";
334  weight = 1.0;
335  };
336 
337  if (weight < 1e-20) {
338  // LogInfo("RecoVertex/AdaptiveVertexFitter") << "Weight " << weight << " < 0.0!";
339  weight = 1e-20;
340  };
341  return weight;
342 }
Definition: weight.py:1
virtual double weight(double chi2) const =0
AnnealingSchedule * theAssProbComputer
void AdaptiveVertexFitter::gsfIntermediarySmoothing ( bool  sm)
inline
bool AdaptiveVertexFitter::gsfIntermediarySmoothing ( ) const
inline
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::linearizeTracks ( const std::vector< reco::TransientTrack > &  tracks,
const VertexState seed 
) const
private

Linearize tracks, for the first time in the iteration.

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

Definition at line 283 of file AdaptiveVertexFitter.cc.

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

Referenced by gsfIntermediarySmoothing(), and vertex().

284  {
285  const GlobalPoint& linP(seed.position());
286  vector<RefCountedLinearizedTrackState> lTracks;
287  for (vector<reco::TransientTrack>::const_iterator i = tracks.begin(); i != tracks.end(); ++i) {
288  try {
290  lTracks.push_back(lTrData);
291  } catch (exception& e) {
292  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Exception " << e.what() << " in ::linearizeTracks."
293  << "Your future vertex has just lost a track.";
294  };
295  }
296  return weightTracks(lTracks, seed);
297 }
GlobalPoint position() const
Definition: VertexState.h:62
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
const AbstractLTSFactory< 5 > * theLinTrkFactory
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reLinearizeTracks ( const std::vector< RefCountedVertexTrack > &  tracks,
const CachingVertex< 5 > &  vertex 
) const
private

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

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

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

Definition at line 304 of file AdaptiveVertexFitter.cc.

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

Referenced by fit(), and gsfIntermediarySmoothing().

305  {
306  const VertexState& seed = vertex.vertexState();
307  GlobalPoint linP = seed.position();
308  vector<RefCountedLinearizedTrackState> lTracks;
309  for (vector<RefCountedVertexTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
310  try {
312  theLinTrkFactory->linearizedTrackState(linP, (**i).linearizedTrack()->track());
313  /*
314  RefCountedLinearizedTrackState lTrData =
315  (**i).linearizedTrack()->stateWithNewLinearizationPoint(linP);
316  */
317  lTracks.push_back(lTrData);
318  } catch (exception& e) {
319  LogInfo("RecoVertex/AdaptiveVertexFitter") << "Exception " << e.what() << " in ::relinearizeTracks. "
320  << "Will not relinearize this track.";
321  lTracks.push_back((**i).linearizedTrack());
322  };
323  };
324  return reWeightTracks(lTracks, vertex);
325 }
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
VertexState const & vertexState() const
GlobalPoint position() const
Definition: VertexState.h:62
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
const AbstractLTSFactory< 5 > * theLinTrkFactory
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reWeightTracks ( const std::vector< RefCountedLinearizedTrackState > &  lTracks,
const CachingVertex< 5 > &  seed 
) const
private

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

Definition at line 344 of file AdaptiveVertexFitter.cc.

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

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

345  {
346  const VertexState& seed = vertex.vertexState();
347  // cout << "[AdaptiveVertexFitter] now reweight around " << seed.position() << endl;
348  theNr++;
349  // GlobalPoint pos = seed.position();
350 
351  vector<RefCountedVertexTrack> finalTracks;
352  VertexTrackFactory<5> vTrackFactory;
353 #ifdef STORE_WEIGHTS
354  iter++;
355 #endif
356  for (vector<RefCountedLinearizedTrackState>::const_iterator i = lTracks.begin(); i != lTracks.end(); i++) {
357  double weight = 0.;
358  // cout << "[AdaptiveVertexFitter] estimate " << endl;
359  pair<bool, double> chi2Res(false, 0.);
360  try {
361  chi2Res = theComp->estimate(vertex, *i, std::distance(lTracks.begin(), i));
362  } catch (exception const& e) {
363  };
364  // cout << "[AdaptiveVertexFitter] /estimate " << endl;
365  if (!chi2Res.first) {
366  // cout << "[AdaptiveVertexFitter] aie... vertex candidate is at " << vertex.position() << endl;
367  LogInfo("AdaptiveVertexFitter") << "When reweighting, chi2<0. Will add this track with w=0.";
368  // edm::LogInfo("AdaptiveVertexFitter" ) << "pt=" << (**i).track().pt();
369  } else {
370  weight = getWeight(chi2Res.second);
371  }
372 
373  RefCountedVertexTrack vTrData = vTrackFactory.vertexTrack(*i, seed, weight);
374 
375 #ifdef STORE_WEIGHTS
376  map<string, dataharvester::MultiType> m;
377  m["chi2"] = chi2;
378  m["w"] = theAssProbComputer->weight(chi2);
379  m["T"] = theAssProbComputer->currentTemp();
380  m["n"] = iter;
381  m["pos"] = "reweight";
382  m["id"] = getId(*i);
383  dataharvester::Writer::file("w.txt").save(m);
384 #endif
385 
386  finalTracks.push_back(vTrData);
387  }
388  sortByDistanceToRefPoint(finalTracks, vertex.position());
389  // cout << "[AdaptiveVertexFitter] /now reweight" << endl;
390  return finalTracks;
391 }
static unsigned int getId()
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
VertexState const & vertexState() const
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
Definition: weight.py:1
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
virtual double weight(double chi2) const =0
virtual double currentTemp() const =0
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
double getWeight(float chi2) const
GlobalPoint position() const
VertexTrackCompatibilityEstimator< 5 > * theComp
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::reWeightTracks ( const std::vector< RefCountedVertexTrack > &  tracks,
const CachingVertex< 5 > &  seed 
) const
private

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

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

Definition at line 437 of file AdaptiveVertexFitter.cc.

References reWeightTracks().

438  {
439  vector<RefCountedLinearizedTrackState> lTracks;
440  for (vector<RefCountedVertexTrack>::const_iterator i = tracks.begin(); i != tracks.end(); i++) {
441  lTracks.push_back((**i).linearizedTrack());
442  }
443 
444  return reWeightTracks(lTracks, seed);
445 }
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
void AdaptiveVertexFitter::setParameters ( double  maxshift = 0.0001,
double  maxlpshift = 0.1,
unsigned  maxstep = 30,
double  weightthreshold = .001 
)

Reads the configurable parameters.

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

Definition at line 144 of file AdaptiveVertexFitter.cc.

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

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

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

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

Definition at line 151 of file AdaptiveVertexFitter.cc.

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

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

References theWeightThreshold, and w.

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

119 { theWeightThreshold = w; }
const double w
Definition: UKUtility.cc:23
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  unstracks) const
overridevirtual

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

Returns
The fitted vertex

Implements VertexFitter< 5 >.

Definition at line 158 of file AdaptiveVertexFitter.cc.

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

Referenced by PrimaryVertexResolution::Plots::calculateAndFillResolution(), Tau.Tau::dxy(), V0Fitter::fitAll(), PFDisplacedVertexFinder::fitVertexFromSeed(), gsfIntermediarySmoothing(), PFTauPrimaryVertexProducerBase::produce(), TemplatedInclusiveVertexFinder< InputContainer, VTX >::produce(), TrackVertexArbitration< VTX >::trackVertexArbitrator(), AdaptiveGsfVertexFitter::vertex(), and AdaptiveVertexReconstructor::vertices().

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

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 SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

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

Same as above, only now also with BeamSpot constraint.

Definition at line 186 of file AdaptiveVertexFitter.cc.

References fit().

Referenced by Tau.Tau::dxy().

187  {
188  if (tracks.empty()) {
189  LogError("RecoVertex|AdaptiveVertexFitter") << "Supplied no tracks. Vertex is invalid.";
190  return CachingVertex<5>(); // return invalid vertex
191  };
192  VertexState beamSpotState(spot);
193  return fit(tracks, beamSpotState, true);
194 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const GlobalPoint linPoint 
) const
overridevirtual

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

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

Referenced by Tau.Tau::dxy().

200  {
201  if (tracks.size() < 2) {
202  LogError("RecoVertex|AdaptiveVertexFitter") << "Supplied fewer than two tracks. Vertex is invalid.";
203  return CachingVertex<5>(); // return invalid vertex
204  };
205  // Initial vertex seed, with a very large error matrix
206  VertexState seed(linPoint, linPointError);
207  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
208  VertexState fitseed(linPoint, fitError);
209  return fit(vtContainer, fitseed, false);
210 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const GlobalPoint priorPos,
const GlobalError priorError 
) const
overridevirtual

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

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

Referenced by Tau.Tau::dxy().

251 {
252  if (tracks.empty()) {
253  LogError("RecoVertex|AdaptiveVertexFitter") << "Supplied no tracks. Vertex is invalid.";
254  return CachingVertex<5>(); // return invalid vertex
255  };
256  VertexState seed(priorPos, priorError);
257  vector<RefCountedVertexTrack> vtContainer = linearizeTracks(tracks, seed);
258  return fit(vtContainer, seed, true);
259 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< reco::TransientTrack > &  tracks,
const reco::BeamSpot beamSpot 
) const
overridevirtual

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

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

Referenced by Tau.Tau::dxy().

217  {
218  if (unstracks.empty()) {
219  LogError("RecoVertex|AdaptiveVertexFitter") << "Supplied no tracks. Vertex is invalid.";
220  return CachingVertex<5>(); // return invalid vertex
221  };
222 
223  VertexState beamSpotState(beamSpot);
224  vector<RefCountedVertexTrack> vtContainer;
225 
226  vector<reco::TransientTrack> tracks = unstracks;
227  sortTracksByPt(tracks);
228 
229  if (tracks.size() > 1) {
230  // Linearization Point search if there are more than 1 track
231  GlobalPoint linP = theLinP->getLinearizationPoint(tracks);
232  VertexState lpState(linP, linPointError);
233  vtContainer = linearizeTracks(tracks, lpState);
234  } else {
235  // otherwise take the beamspot position.
236  vtContainer = linearizeTracks(tracks, beamSpotState);
237  }
238 
239  return fit(vtContainer, beamSpotState, true);
240 }
LinearizationPointFinder * theLinP
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const
CachingVertex< 5 > AdaptiveVertexFitter::vertex ( const std::vector< RefCountedVertexTrack > &  tracks,
const GlobalPoint priorPos,
const GlobalError priorError 
) const
override

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

References fit(), and SurveyInfoScenario_cff::seed.

Referenced by Tau.Tau::dxy().

267  {
268  if (tracks.empty()) {
269  LogError("RecoVertex|AdaptiveVertexFitter") << "Supplied no tracks. Vertex is invalid.";
270  return CachingVertex<5>(); // return invalid vertex
271  };
272  VertexState seed(priorPos, priorError);
273  return fit(tracks, seed, true);
274 }
CachingVertex< 5 > fit(const std::vector< RefCountedVertexTrack > &tracks, const VertexState &priorSeed, bool withPrior) const
vector< AdaptiveVertexFitter::RefCountedVertexTrack > AdaptiveVertexFitter::weightTracks ( const std::vector< RefCountedLinearizedTrackState > &  lTracks,
const VertexState seed 
) const
private

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

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

Definition at line 393 of file AdaptiveVertexFitter.cc.

References hltPixelTracks_cff::chi2, AnnealingSchedule::currentTemp(), HLT_2018_cff::distance, VertexTrackCompatibilityEstimator< N >::estimate(), FrontierConditions_GlobalTag_cff::file, getId(), getWeight(), mps_fire::i, visualization-live-secondInstance_cfg::m, AnnealingSchedule::resetAnnealing(), theAssProbComputer, theComp, theNr, VertexTrackFactory< N >::vertexTrack(), and AnnealingSchedule::weight().

Referenced by gsfIntermediarySmoothing(), and linearizeTracks().

394  {
395  theNr++;
396  CachingVertex<5> seedvtx(seed, vector<RefCountedVertexTrack>(), 0.);
400 
401  vector<RefCountedVertexTrack> finalTracks;
402  VertexTrackFactory<5> vTrackFactory;
403 #ifdef STORE_WEIGHTS
404  iter++;
405 #endif
406  for (vector<RefCountedLinearizedTrackState>::const_iterator i = lTracks.begin(); i != lTracks.end(); i++) {
407  double weight = 0.;
408  pair<bool, double> chi2Res = theComp->estimate(seedvtx, *i, std::distance(lTracks.begin(), i));
409  if (!chi2Res.first) {
410  // cout << "[AdaptiveVertexFitter] Aiee! " << endl;
411  LogInfo("AdaptiveVertexFitter") << "When weighting a track, chi2 calculation failed;"
412  << " will add with w=0.";
413  } else {
414  weight = getWeight(chi2Res.second);
415  }
416  RefCountedVertexTrack vTrData = vTrackFactory.vertexTrack(*i, seed, weight);
417 #ifdef STORE_WEIGHTS
418  map<string, dataharvester::MultiType> m;
419  m["chi2"] = chi2;
420  m["w"] = theAssProbComputer->weight(chi2);
421  m["T"] = theAssProbComputer->currentTemp();
422  m["n"] = iter;
423  m["id"] = getId(*i);
424  m["pos"] = "weight";
425  dataharvester::Writer::file("w.txt").save(m);
426 #endif
427  finalTracks.push_back(vTrData);
428  }
429  return finalTracks;
430 }
static unsigned int getId()
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
Definition: weight.py:1
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
virtual double weight(double chi2) const =0
virtual double currentTemp() const =0
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
double getWeight(float chi2) const
virtual void resetAnnealing()=0
VertexTrackCompatibilityEstimator< 5 > * theComp

Member Data Documentation

bool AdaptiveVertexFitter::gsfIntermediarySmoothing_
private

Definition at line 203 of file AdaptiveVertexFitter.h.

Referenced by fit(), and gsfIntermediarySmoothing().

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

Definition at line 201 of file AdaptiveVertexFitter.h.

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

LinearizationPointFinder* AdaptiveVertexFitter::theLinP
private

Definition at line 197 of file AdaptiveVertexFitter.h.

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

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

Definition at line 192 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

double AdaptiveVertexFitter::theMaxShift
private

Definition at line 191 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

int AdaptiveVertexFitter::theMaxStep
private

Definition at line 193 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

int AdaptiveVertexFitter::theNr
mutableprivate

Definition at line 195 of file AdaptiveVertexFitter.h.

Referenced by reWeightTracks(), and weightTracks().

VertexSmoother<5>* AdaptiveVertexFitter::theSmoother
private

Definition at line 199 of file AdaptiveVertexFitter.h.

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

VertexUpdator<5>* AdaptiveVertexFitter::theUpdator
private

Definition at line 198 of file AdaptiveVertexFitter.h.

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

double AdaptiveVertexFitter::theWeightThreshold
private

Definition at line 194 of file AdaptiveVertexFitter.h.

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