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

◆ RefCountedLinearizedTrackState

Definition at line 32 of file AdaptiveVertexFitter.h.

◆ RefCountedVertexTrack

Definition at line 31 of file AdaptiveVertexFitter.h.

Constructor & Destructor Documentation

◆ AdaptiveVertexFitter() [1/2]

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 }
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
const AbstractLTSFactory< 5 > * theLinTrkFactory
VertexTrackCompatibilityEstimator< 5 > * theComp

◆ AdaptiveVertexFitter() [2/2]

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::~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

◆ clone()

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

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

◆ fit()

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(), nano_mu_local_reco_cff::chi2, AnnealingSchedule::currentTemp(), VertexState::error(), geometryDiff::file, getId(), gsfIntermediarySmoothing_, mps_fire::i, AnnealingSchedule::isAnnealed(), LogDebug, visualization-live-secondInstance_cfg::m, mag(), L1TEGammaOffline_cfi::nVertex, VertexState::position(), CachingVertex< N >::position(), reLinearizeTracks(), AnnealingSchedule::resetAnnealing(), reWeightTracks(), VertexSmoother< N >::smooth(), theAssProbComputer, theMaxLPShift, theMaxShift, theMaxStep, theSmoother, theUpdator, theWeightThreshold, DiMuonV_cfg::tracks, and AnnealingSchedule::weight().

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

◆ getWeight()

double AdaptiveVertexFitter::getWeight ( float  chi2) const
private

Definition at line 329 of file AdaptiveVertexFitter.cc.

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

Referenced by 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
AnnealingSchedule * theAssProbComputer
Log< level::Info, false > LogInfo
virtual double weight(double chi2) const =0

◆ gsfIntermediarySmoothing() [1/2]

void AdaptiveVertexFitter::gsfIntermediarySmoothing ( bool  sm)
inline

◆ gsfIntermediarySmoothing() [2/2]

bool AdaptiveVertexFitter::gsfIntermediarySmoothing ( ) const
inline

Definition at line 137 of file AdaptiveVertexFitter.h.

References gsfIntermediarySmoothing_.

◆ linearizeTracks()

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(), fileCollector::seed, theLinTrkFactory, DiMuonV_cfg::tracks, and weightTracks().

Referenced by 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 }
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
Log< level::Info, false > LogInfo
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
std::vector< RefCountedVertexTrack > weightTracks(const std::vector< RefCountedLinearizedTrackState > &, const VertexState &seed) const
const AbstractLTSFactory< 5 > * theLinTrkFactory

◆ reLinearizeTracks()

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, mps_fire::i, AbstractLTSFactory< N >::linearizedTrackState(), reWeightTracks(), fileCollector::seed, theLinTrkFactory, DiMuonV_cfg::tracks, vertex(), and CachingVertex< N >::vertexState().

Referenced by fit().

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 }
virtual RefCountedLinearizedTrackState linearizedTrackState(const GlobalPoint &linP, const reco::TransientTrack &track) const =0
VertexState const & vertexState() const
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
Log< level::Info, false > LogInfo
std::vector< RefCountedVertexTrack > reWeightTracks(const std::vector< RefCountedLinearizedTrackState > &, const CachingVertex< 5 > &seed) const
ReferenceCountingPointer< LinearizedTrackState< 5 > > RefCountedLinearizedTrackState
const AbstractLTSFactory< 5 > * theLinTrkFactory

◆ reWeightTracks() [1/2]

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 nano_mu_local_reco_cff::chi2, AnnealingSchedule::currentTemp(), HLT_2024v11_cff::distance, MillePedeFileConverter_cfg::e, VertexTrackCompatibilityEstimator< N >::estimate(), cppFunctionSkipper::exception, geometryDiff::file, getId(), getWeight(), mps_fire::i, visualization-live-secondInstance_cfg::m, CachingVertex< N >::position(), fileCollector::seed, theAssProbComputer, theComp, theNr, vertex(), CachingVertex< N >::vertexState(), VertexTrackFactory< N >::vertexTrack(), and AnnealingSchedule::weight().

Referenced by fit(), 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 }
RefCountedVertexTrack vertexTrack(const RefCountedLinearizedTrackState lt, const VertexState vs, float weight=1.0) const
VertexState const & vertexState() const
Definition: weight.py:1
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
virtual BDpair estimate(const CachingVertex< N > &v, const RefCountedLinearizedTrackState track, unsigned int hint=UINT_MAX) const =0
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
Log< level::Info, false > LogInfo
virtual double currentTemp() const =0
double getWeight(float chi2) const
static unsigned int getId()
GlobalPoint position() const
virtual double weight(double chi2) const =0
VertexTrackCompatibilityEstimator< 5 > * theComp

◆ reWeightTracks() [2/2]

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 mps_fire::i, reWeightTracks(), fileCollector::seed, and DiMuonV_cfg::tracks.

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

◆ setParameters() [1/2]

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_2024v11_cff::weightthreshold.

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

◆ setParameters() [2/2]

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 alignCSCRings::s, 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 }
void setParameters(double maxshift=0.0001, double maxlpshift=0.1, unsigned maxstep=30, double weightthreshold=.001)

◆ setWeightThreshold()

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 PATRefitVertexProducer::produce(), PFTauPrimaryVertexProducerBase::produce(), and AdaptiveVertexReconstructor::setupFitters().

119 { theWeightThreshold = w; }
T w() const

◆ vertex() [1/7]

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(), fileCollector::seed, theLinP, and DiMuonV_cfg::tracks.

Referenced by SplitVertexResolution::analyze(), PrimaryVertexResolution::Plots::calculateAndFillResolution(), Tau.Tau::dxy(), V0Fitter::fitAll(), PFDisplacedVertexFinder::fitVertexFromSeed(), PATRefitVertexProducer::produce(), PFTauPrimaryVertexProducerBase::produce(), TemplatedInclusiveVertexFinder< InputContainer, VTX >::produce(), reLinearizeTracks(), reWeightTracks(), 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
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
Log< level::Error, false > LogError
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const

◆ vertex() [2/7]

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(), fileCollector::seed, and DiMuonV_cfg::tracks.

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
Log< level::Error, false > LogError

◆ vertex() [3/7]

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(), and DiMuonV_cfg::tracks.

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
Log< level::Error, false > LogError

◆ vertex() [4/7]

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(), fileCollector::seed, and DiMuonV_cfg::tracks.

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
Log< level::Error, false > LogError
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const

◆ vertex() [5/7]

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(), fileCollector::seed, and DiMuonV_cfg::tracks.

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
Log< level::Error, false > LogError
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const

◆ vertex() [6/7]

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 pwdgSkimBPark_cfi::beamSpot, fit(), LinearizationPointFinder::getLinearizationPoint(), linearizeTracks(), theLinP, and DiMuonV_cfg::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
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
Log< level::Error, false > LogError
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
std::vector< RefCountedVertexTrack > linearizeTracks(const std::vector< reco::TransientTrack > &, const VertexState &) const

◆ vertex() [7/7]

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(), fileCollector::seed, and DiMuonV_cfg::tracks.

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
Log< level::Error, false > LogError

◆ weightTracks()

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 nano_mu_local_reco_cff::chi2, AnnealingSchedule::currentTemp(), HLT_2024v11_cff::distance, VertexTrackCompatibilityEstimator< N >::estimate(), geometryDiff::file, getId(), getWeight(), mps_fire::i, visualization-live-secondInstance_cfg::m, AnnealingSchedule::resetAnnealing(), fileCollector::seed, theAssProbComputer, theComp, theNr, VertexTrackFactory< N >::vertexTrack(), and AnnealingSchedule::weight().

Referenced by 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 }
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
ReferenceCountingPointer< VertexTrack< 5 > > RefCountedVertexTrack
AnnealingSchedule * theAssProbComputer
Log< level::Info, false > LogInfo
virtual double currentTemp() const =0
double getWeight(float chi2) const
static unsigned int getId()
virtual void resetAnnealing()=0
virtual double weight(double chi2) const =0
VertexTrackCompatibilityEstimator< 5 > * theComp

Member Data Documentation

◆ gsfIntermediarySmoothing_

bool AdaptiveVertexFitter::gsfIntermediarySmoothing_
private

Definition at line 203 of file AdaptiveVertexFitter.h.

Referenced by fit(), and gsfIntermediarySmoothing().

◆ theAssProbComputer

AnnealingSchedule* AdaptiveVertexFitter::theAssProbComputer
private

◆ theComp

VertexTrackCompatibilityEstimator<5>* AdaptiveVertexFitter::theComp
private

Definition at line 201 of file AdaptiveVertexFitter.h.

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

◆ theLinP

LinearizationPointFinder* AdaptiveVertexFitter::theLinP
private

Definition at line 197 of file AdaptiveVertexFitter.h.

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

◆ theLinTrkFactory

const AbstractLTSFactory<5>* AdaptiveVertexFitter::theLinTrkFactory
private

◆ theMaxLPShift

double AdaptiveVertexFitter::theMaxLPShift
private

Definition at line 192 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

◆ theMaxShift

double AdaptiveVertexFitter::theMaxShift
private

Definition at line 191 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

◆ theMaxStep

int AdaptiveVertexFitter::theMaxStep
private

Definition at line 193 of file AdaptiveVertexFitter.h.

Referenced by fit(), and setParameters().

◆ theNr

int AdaptiveVertexFitter::theNr
mutableprivate

Definition at line 195 of file AdaptiveVertexFitter.h.

Referenced by reWeightTracks(), and weightTracks().

◆ theSmoother

VertexSmoother<5>* AdaptiveVertexFitter::theSmoother
private

Definition at line 199 of file AdaptiveVertexFitter.h.

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

◆ theUpdator

VertexUpdator<5>* AdaptiveVertexFitter::theUpdator
private

Definition at line 198 of file AdaptiveVertexFitter.h.

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

◆ theWeightThreshold

double AdaptiveVertexFitter::theWeightThreshold
private

Definition at line 194 of file AdaptiveVertexFitter.h.

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