CMS 3D CMS Logo

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

#include <KinematicConstrainedVertexFitter.h>

Public Member Functions

RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part)
 
RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part, MultiTrackKinematicConstraint *cs)
 
RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part, MultiTrackKinematicConstraint *cs, GlobalPoint *pt)
 
float getCSum () const
 
int getNit () const
 
 KinematicConstrainedVertexFitter ()
 
 KinematicConstrainedVertexFitter (const LinearizationPointFinder &fnd)
 
void setParameters (const edm::ParameterSet &pSet)
 
 ~KinematicConstrainedVertexFitter ()
 

Private Member Functions

void defaultParameters ()
 

Private Attributes

float csum
 
LinearizationPointFinderfinder
 
int iterations
 
ConstrainedTreeBuildertBuilder
 
float theMaxDelta
 
float theMaxReducedChiSq
 
int theMaxStep
 
float theMinChiSqImprovement
 
KinematicConstrainedVertexUpdatorupdator
 
VertexKinematicConstraintvCons
 

Detailed Description

Class fitting the veretx out of set of tracks via usual LMS with Lagrange multipliers. Additional constraints can be applyed to the tracks during the vertex fit (solves non-factorizabele cases). Since the vertex constraint is included by default, do not add a separate VertexKinematicConstraint! Example: Vertex fit with collinear tracks..

Definition at line 21 of file KinematicConstrainedVertexFitter.h.

Constructor & Destructor Documentation

KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter ( )

Default constructor using LMSLinearizationPointFinder

Definition at line 7 of file KinematicConstrainedVertexFitter.cc.

References csum, defaultParameters(), finder, iterations, tBuilder, updator, and vCons.

KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter ( const LinearizationPointFinder fnd)

Constructor with user-provided LinearizationPointFinder

Definition at line 17 of file KinematicConstrainedVertexFitter.cc.

References LinearizationPointFinder::clone(), csum, defaultParameters(), finder, iterations, tBuilder, updator, and vCons.

KinematicConstrainedVertexFitter::~KinematicConstrainedVertexFitter ( )

Definition at line 27 of file KinematicConstrainedVertexFitter.cc.

References finder, tBuilder, updator, and vCons.

27  {
28  delete finder;
29  delete vCons;
30  delete updator;
31  delete tBuilder;
32 }
KinematicConstrainedVertexUpdator * updator

Member Function Documentation

void KinematicConstrainedVertexFitter::defaultParameters ( )
private
RefCountedKinematicTree KinematicConstrainedVertexFitter::fit ( const std::vector< RefCountedKinematicParticle > &  part)
inline

Without additional constraint, this will perform a simple vertex fit using LMS with Lagrange multipliers method.

Definition at line 46 of file KinematicConstrainedVertexFitter.h.

Referenced by KineExample::analyze(), fit(), BPHKinematicFit::kinematicTree(), trackingPlots.Iteration::modules(), and ConversionVertexFinder::run().

46  {
47  return fit(part, nullptr, nullptr);
48  }
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
part
Definition: HCALResponse.h:20
RefCountedKinematicTree KinematicConstrainedVertexFitter::fit ( const std::vector< RefCountedKinematicParticle > &  part,
MultiTrackKinematicConstraint cs 
)
inline

LMS with Lagrange multipliers fit of vertex constraint and user-specified constraint.

Definition at line 53 of file KinematicConstrainedVertexFitter.h.

References fwrapper::cs, defaultParameters(), fit(), getCSum(), getNit(), and DiDispStaMuonMonitor_cfi::pt.

Referenced by trackingPlots.Iteration::modules().

53  {
54  return fit(part, cs, nullptr);
55  };
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
part
Definition: HCALResponse.h:20
RefCountedKinematicTree KinematicConstrainedVertexFitter::fit ( const std::vector< RefCountedKinematicParticle > &  part,
MultiTrackKinematicConstraint cs,
GlobalPoint pt 
)

LMS with Lagrange multipliers fit of vertex constraint, user-specified constraint and user-specified starting point.

Definition at line 48 of file KinematicConstrainedVertexFitter.cc.

References ConstrainedTreeBuilder::buildTree(), csum, dumpMFGeometry_cfg::delta, Vispa.Plugins.EdmBrowser.EdmDataAccessor::eq(), finder, LinearizationPointFinder::getLinearizationPoint(), mps_fire::i, input, KinematicState::isValid(), iterations, dqmiolumiharvest::j, KinematicState::kinematicParameters(), KinematicState::kinematicParametersError(), LogDebug, KinematicParametersError::matrix(), allConversions_cfi::maxDelta, ecalTrigSettings_cff::particles, DiDispStaMuonMonitor_cfi::pt, InputSort::sort(), tBuilder, theMaxDelta, theMaxReducedChiSq, theMaxStep, theMinChiSqImprovement, KinematicConstrainedVertexUpdator::update(), updator, KinematicParameters::vector(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by trackingPlots.Iteration::modules().

50  {
51  if (part.size() < 2)
52  throw VertexException("KinematicConstrainedVertexFitter::input states are less than 2");
53 
54  //sorting out the input particles
55  InputSort iSort;
56  std::pair<std::vector<RefCountedKinematicParticle>, std::vector<FreeTrajectoryState> > input = iSort.sort(part);
57  const std::vector<RefCountedKinematicParticle> &particles = input.first;
58  const std::vector<FreeTrajectoryState> &fStates = input.second;
59 
60  // linearization point
61  // (only compute it using the linearization point finder if no point was passed to the fit function):
62  GlobalPoint linPoint;
63  if (pt != nullptr) {
64  linPoint = *pt;
65  } else {
66  linPoint = finder->getLinearizationPoint(fStates);
67  }
68 
69  //initial parameters:
70  int vSize = particles.size();
71  AlgebraicVector inPar(3 + 7 * vSize, 0);
72 
73  //final parameters
74  AlgebraicVector finPar(3 + 7 * vSize, 0);
75 
76  //initial covariance
77  AlgebraicMatrix inCov(3 + 7 * vSize, 3 + 7 * vSize, 0);
78 
79  //making initial vector of parameters and initial particle-related covariance
80  int nSt = 0;
81  std::vector<KinematicState> inStates;
82  for (std::vector<RefCountedKinematicParticle>::const_iterator i = particles.begin(); i != particles.end(); i++) {
83  KinematicState state = (*i)->stateAtPoint(linPoint);
84  if (!state.isValid()) {
85  LogDebug("KinematicConstrainedVertexFitter") << "State is invalid at point: " << linPoint << std::endl;
87  }
88  AlgebraicVector prPar = asHepVector<7>(state.kinematicParameters().vector());
89  for (int j = 1; j < 8; j++) {
90  inPar(3 + 7 * nSt + j) = prPar(j);
91  }
92  AlgebraicSymMatrix l_cov = asHepMatrix<7>(state.kinematicParametersError().matrix());
93  inCov.sub(4 + 7 * nSt, 4 + 7 * nSt, l_cov);
94  inStates.push_back(state);
95  ++nSt;
96  }
97 
98  //initial vertex error matrix components (huge error method)
99  //and vertex related initial vector components
100  double in_er = 100.;
101  inCov(1, 1) = in_er;
102  inCov(2, 2) = in_er;
103  inCov(3, 3) = in_er;
104 
105  inPar(1) = linPoint.x();
106  inPar(2) = linPoint.y();
107  inPar(3) = linPoint.z();
108 
109  //constraint equations value and number of iterations
110  double eq;
111  int nit = 0;
112  iterations = 0;
113  csum = 0.0;
114 
115  std::vector<KinematicState> lStates = inStates;
116  GlobalPoint lPoint = linPoint;
118  AlgebraicMatrix refCCov;
119 
120  double chisq = 1e6;
121  bool convergence = false;
122  //iterarions over the updator: each time updated parameters
123  //are taken as new linearization point
124  do {
125  eq = 0.;
126  std::pair<std::pair<std::vector<KinematicState>, AlgebraicMatrix>, RefCountedKinematicVertex> lRes =
127  updator->update(inPar, inCov, lStates, lPoint, cs);
128 
129  const std::vector<KinematicState> &newStates = lRes.first.first;
130 
131  if (particles.size() != newStates.size()) {
132  LogDebug("KinematicConstrainedVertexFitter") << "updator failure\n";
134  }
135 
136  rVtx = lRes.second;
137 
138  double newchisq = rVtx->chiSquared();
139  if (nit > 2 && newchisq > theMaxReducedChiSq * rVtx->degreesOfFreedom() &&
140  (newchisq - chisq) > (-theMinChiSqImprovement)) {
141  LogDebug("KinematicConstrainedVertexFitter") << "bad chisq and insufficient improvement, bailing\n";
143  }
144  chisq = newchisq;
145 
146  const GlobalPoint &newPoint = rVtx->position();
147 
148  double maxDelta = 0.0;
149 
150  double deltapos[3];
151  deltapos[0] = newPoint.x() - lPoint.x();
152  deltapos[1] = newPoint.y() - lPoint.y();
153  deltapos[2] = newPoint.z() - lPoint.z();
154  for (int i = 0; i < 3; ++i) {
155  double delta = deltapos[i] * deltapos[i] / rVtx->error().matrix()(i, i);
156  if (delta > maxDelta)
157  maxDelta = delta;
158  }
159 
160  for (std::vector<KinematicState>::const_iterator itold = lStates.begin(), itnew = newStates.begin();
161  itnew != newStates.end();
162  ++itold, ++itnew) {
163  for (int i = 0; i < 7; ++i) {
164  double deltapar = itnew->kinematicParameters()(i) - itold->kinematicParameters()(i);
165  double delta = deltapar * deltapar / itnew->kinematicParametersError().matrix()(i, i);
166  if (delta > maxDelta)
167  maxDelta = delta;
168  }
169  }
170 
171  lStates = newStates;
172  lPoint = newPoint;
173 
174  refCCov = lRes.first.second;
175  nit++;
176  convergence = maxDelta < theMaxDelta || (nit == theMaxStep && maxDelta < 4.0 * theMaxDelta);
177 
178  } while (nit < theMaxStep && !convergence);
179 
180  if (!convergence) {
182  }
183 
184  // std::cout << "old full cov matrix" << std::endl;
185  // std::cout << refCCov << std::endl;
186 
187  // cout<<"number of relinearizations "<<nit<<endl;
188  // cout<<"value obtained: "<<eq<<endl;
189  iterations = nit;
190  csum = eq;
191 
192  return tBuilder->buildTree(particles, lStates, rVtx, refCCov);
193 }
#define LogDebug(id)
std::pair< std::pair< std::vector< KinematicState >, AlgebraicMatrix >, RefCountedKinematicVertex > update(const AlgebraicVector &inState, const AlgebraicMatrix &inCov, const std::vector< KinematicState > &lStates, const GlobalPoint &lPoint, MultiTrackKinematicConstraint *cs) const
AlgebraicVector7 const & vector() const
The full vector (7 elements)
bool isValid() const
Common base class.
T y() const
Definition: PV3DBase.h:60
AlgebraicSymMatrix77 const & matrix() const
static std::string const input
Definition: EdmProvDump.cc:48
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
std::pair< std::vector< RefCountedKinematicParticle >, std::vector< FreeTrajectoryState > > sort(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: InputSort.cc:5
CLHEP::HepMatrix AlgebraicMatrix
T z() const
Definition: PV3DBase.h:61
KinematicParametersError const & kinematicParametersError() const
KinematicConstrainedVertexUpdator * updator
CLHEP::HepVector AlgebraicVector
KinematicParameters const & kinematicParameters() const
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
part
Definition: HCALResponse.h:20
CLHEP::HepSymMatrix AlgebraicSymMatrix
T x() const
Definition: PV3DBase.h:59
float KinematicConstrainedVertexFitter::getCSum ( ) const

Definition at line 197 of file KinematicConstrainedVertexFitter.cc.

References csum.

Referenced by fit().

int KinematicConstrainedVertexFitter::getNit ( ) const
void KinematicConstrainedVertexFitter::setParameters ( const edm::ParameterSet pSet)

Configuration through PSet: number of iterations(maxDistance) and stopping condition (maxNbrOfIterations)

Definition at line 34 of file KinematicConstrainedVertexFitter.cc.

References edm::ParameterSet::getParameter(), theMaxDelta, theMaxReducedChiSq, theMaxStep, and theMinChiSqImprovement.

34  {
35  theMaxDelta = pSet.getParameter<double>("maxDelta");
36  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
37  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
38  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
39 }
T getParameter(std::string const &) const

Member Data Documentation

float KinematicConstrainedVertexFitter::csum
private
LinearizationPointFinder* KinematicConstrainedVertexFitter::finder
private
int KinematicConstrainedVertexFitter::iterations
private
ConstrainedTreeBuilder* KinematicConstrainedVertexFitter::tBuilder
private
float KinematicConstrainedVertexFitter::theMaxDelta
private

Definition at line 72 of file KinematicConstrainedVertexFitter.h.

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

float KinematicConstrainedVertexFitter::theMaxReducedChiSq
private

Definition at line 74 of file KinematicConstrainedVertexFitter.h.

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

int KinematicConstrainedVertexFitter::theMaxStep
private

Definition at line 73 of file KinematicConstrainedVertexFitter.h.

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

float KinematicConstrainedVertexFitter::theMinChiSqImprovement
private

Definition at line 75 of file KinematicConstrainedVertexFitter.h.

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

KinematicConstrainedVertexUpdator* KinematicConstrainedVertexFitter::updator
private
VertexKinematicConstraint* KinematicConstrainedVertexFitter::vCons
private