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() [1/2]

KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter ( )

Default constructor using LMSLinearizationPointFinder

Definition at line 7 of file KinematicConstrainedVertexFitter.cc.

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

◆ KinematicConstrainedVertexFitter() [2/2]

KinematicConstrainedVertexFitter::KinematicConstrainedVertexFitter ( const LinearizationPointFinder fnd)

Constructor with user-provided LinearizationPointFinder

Definition at line 17 of file KinematicConstrainedVertexFitter.cc.

17  {
18  finder = fnd.clone();
23  iterations = -1;
24  csum = -1000.0;
25 }

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

◆ ~KinematicConstrainedVertexFitter()

KinematicConstrainedVertexFitter::~KinematicConstrainedVertexFitter ( )

Definition at line 27 of file KinematicConstrainedVertexFitter.cc.

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

References finder, tBuilder, updator, and vCons.

Member Function Documentation

◆ defaultParameters()

void KinematicConstrainedVertexFitter::defaultParameters ( )
private

Definition at line 41 of file KinematicConstrainedVertexFitter.cc.

41  {
42  theMaxDelta = 0.01;
43  theMaxStep = 1000;
44  theMaxReducedChiSq = 225.;
46 }

References theMaxDelta, theMaxReducedChiSq, theMaxStep, and theMinChiSqImprovement.

Referenced by KinematicConstrainedVertexFitter().

◆ fit() [1/3]

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.

46  {
47  return fit(part, nullptr, nullptr);
48  }

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

◆ fit() [2/3]

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.

53  {
54  return fit(part, cs, nullptr);
55  };

References fwrapper::cs, and fit().

Referenced by trackingPlots.Iteration::modules().

◆ fit() [3/3]

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.

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 }

References ConstrainedTreeBuilder::buildTree(), fwrapper::cs, csum, dumpMFGeometry_cfg::delta, edm::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().

◆ getCSum()

float KinematicConstrainedVertexFitter::getCSum ( ) const

Definition at line 197 of file KinematicConstrainedVertexFitter.cc.

197 { return csum; }

References csum.

◆ getNit()

int KinematicConstrainedVertexFitter::getNit ( ) const

Definition at line 195 of file KinematicConstrainedVertexFitter.cc.

195 { return iterations; }

References iterations.

Referenced by ConversionVertexFinder::run().

◆ setParameters()

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.

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 }

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

Referenced by ConversionVertexFinder::ConversionVertexFinder().

Member Data Documentation

◆ csum

float KinematicConstrainedVertexFitter::csum
private

◆ finder

LinearizationPointFinder* KinematicConstrainedVertexFitter::finder
private

◆ iterations

int KinematicConstrainedVertexFitter::iterations
private

◆ tBuilder

ConstrainedTreeBuilder* KinematicConstrainedVertexFitter::tBuilder
private

◆ theMaxDelta

float KinematicConstrainedVertexFitter::theMaxDelta
private

Definition at line 72 of file KinematicConstrainedVertexFitter.h.

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

◆ theMaxReducedChiSq

float KinematicConstrainedVertexFitter::theMaxReducedChiSq
private

Definition at line 74 of file KinematicConstrainedVertexFitter.h.

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

◆ theMaxStep

int KinematicConstrainedVertexFitter::theMaxStep
private

Definition at line 73 of file KinematicConstrainedVertexFitter.h.

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

◆ theMinChiSqImprovement

float KinematicConstrainedVertexFitter::theMinChiSqImprovement
private

Definition at line 75 of file KinematicConstrainedVertexFitter.h.

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

◆ updator

KinematicConstrainedVertexUpdator* KinematicConstrainedVertexFitter::updator
private

◆ vCons

VertexKinematicConstraint* KinematicConstrainedVertexFitter::vCons
private
KinematicConstrainedVertexFitter::updator
KinematicConstrainedVertexUpdator * updator
Definition: KinematicConstrainedVertexFitter.h:77
mps_fire.i
i
Definition: mps_fire.py:355
input
static const std::string input
Definition: EdmProvDump.cc:48
InputSort
Definition: InputSort.h:14
ConstrainedTreeBuilder
Definition: ConstrainedTreeBuilder.h:15
VertexException
Common base class.
Definition: VertexException.h:12
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:45
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
KinematicState
Definition: KinematicState.h:17
KinematicTree
Definition: KinematicTree.h:36
KinematicConstrainedVertexFitter::theMinChiSqImprovement
float theMinChiSqImprovement
Definition: KinematicConstrainedVertexFitter.h:75
ReferenceCountingPointer< KinematicTree >
allConversions_cfi.maxDelta
maxDelta
Definition: allConversions_cfi.py:44
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
KinematicConstrainedVertexUpdator
Definition: KinematicConstrainedVertexUpdator.h:13
KinematicConstrainedVertexFitter::fit
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
Definition: KinematicConstrainedVertexFitter.h:46
part
part
Definition: HCALResponse.h:20
AlgebraicVector
CLHEP::HepVector AlgebraicVector
Definition: AlgebraicObjects.h:13
KinematicConstrainedVertexFitter::iterations
int iterations
Definition: KinematicConstrainedVertexFitter.h:80
KinematicState::kinematicParametersError
KinematicParametersError const & kinematicParametersError() const
Definition: KinematicState.h:63
Point3DBase< float, GlobalTag >
KinematicConstrainedVertexFitter::theMaxStep
int theMaxStep
Definition: KinematicConstrainedVertexFitter.h:73
KinematicConstrainedVertexFitter::vCons
VertexKinematicConstraint * vCons
Definition: KinematicConstrainedVertexFitter.h:78
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
KinematicConstrainedVertexFitter::defaultParameters
void defaultParameters()
Definition: KinematicConstrainedVertexFitter.cc:41
KinematicConstrainedVertexFitter::theMaxReducedChiSq
float theMaxReducedChiSq
Definition: KinematicConstrainedVertexFitter.h:74
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
KinematicParametersError::matrix
AlgebraicSymMatrix77 const & matrix() const
Definition: KinematicParametersError.h:36
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
KinematicConstrainedVertexFitter::finder
LinearizationPointFinder * finder
Definition: KinematicConstrainedVertexFitter.h:76
VertexKinematicConstraint
Definition: VertexKinematicConstraint.h:14
KinematicConstrainedVertexFitter::csum
float csum
Definition: KinematicConstrainedVertexFitter.h:81
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
ConstrainedTreeBuilder::buildTree
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const AlgebraicMatrix &fCov) const
Definition: ConstrainedTreeBuilder.cc:15
KinematicState::isValid
bool isValid() const
Definition: KinematicState.h:79
edm::eq
bool eq(const ELstring &s1, const ELstring s2)
Definition: ELstring.cc:39
DefaultLinearizationPointFinder
Definition: DefaultLinearizationPointFinder.h:13
KinematicConstrainedVertexFitter::tBuilder
ConstrainedTreeBuilder * tBuilder
Definition: KinematicConstrainedVertexFitter.h:79
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
LinearizationPointFinder::clone
virtual LinearizationPointFinder * clone() const =0
KinematicConstrainedVertexUpdator::update
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
Definition: KinematicConstrainedVertexUpdator.cc:16
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
InputSort::sort
std::pair< std::vector< RefCountedKinematicParticle >, std::vector< FreeTrajectoryState > > sort(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: InputSort.cc:5
KinematicParameters::vector
AlgebraicVector7 const & vector() const
The full vector (7 elements)
Definition: KinematicParameters.h:31
KinematicConstrainedVertexFitter::theMaxDelta
float theMaxDelta
Definition: KinematicConstrainedVertexFitter.h:72
LinearizationPointFinder::getLinearizationPoint
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
KinematicState::kinematicParameters
KinematicParameters const & kinematicParameters() const
Definition: KinematicState.h:61
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66