CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
KinematicConstrainedVertexFitterT< nTrk, nConstraint > Class Template Reference

#include <KinematicConstrainedVertexFitterT.h>

Public Member Functions

RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part)
 
RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part, MultiTrackKinematicConstraintT< nTrk, nConstraint > *cs)
 
RefCountedKinematicTree fit (const std::vector< RefCountedKinematicParticle > &part, MultiTrackKinematicConstraintT< nTrk, nConstraint > *cs, GlobalPoint *pt)
 
float getCSum () const
 
int getNit () const
 
 KinematicConstrainedVertexFitterT (const MagneticField *ifield)
 
 KinematicConstrainedVertexFitterT (const MagneticField *ifield, const LinearizationPointFinder &fnd)
 
void setParameters (const edm::ParameterSet &pSet)
 
 ~KinematicConstrainedVertexFitterT ()
 

Private Member Functions

void defaultParameters ()
 

Private Attributes

float csum
 
const MagneticFieldfield
 
LinearizationPointFinderfinder
 
int iterations
 
ConstrainedTreeBuilderTtBuilder
 
float theMaxDelta
 
float theMaxReducedChiSq
 
int theMaxStep
 
float theMinChiSqImprovement
 
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
 
VertexKinematicConstraintTvCons
 

Detailed Description

template<int nTrk, int nConstraint>
class KinematicConstrainedVertexFitterT< nTrk, nConstraint >

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 25 of file KinematicConstrainedVertexFitterT.h.

Constructor & Destructor Documentation

◆ KinematicConstrainedVertexFitterT() [1/2]

template<int nTrk, int nConstraint>
KinematicConstrainedVertexFitterT< nTrk, nConstraint >::KinematicConstrainedVertexFitterT ( const MagneticField ifield)
explicit

Default constructor using LMSLinearizationPointFinder

Definition at line 96 of file KinematicConstrainedVertexFitterT.h.

References KinematicConstrainedVertexFitterT< nTrk, nConstraint >::csum, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::defaultParameters(), KinematicConstrainedVertexFitterT< nTrk, nConstraint >::finder, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::iterations, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::tBuilder, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::updator, and KinematicConstrainedVertexFitterT< nTrk, nConstraint >::vCons.

97  : field(ifield) {
103  iterations = -1;
104  csum = -1000.0;
105 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator

◆ KinematicConstrainedVertexFitterT() [2/2]

template<int nTrk, int nConstraint>
KinematicConstrainedVertexFitterT< nTrk, nConstraint >::KinematicConstrainedVertexFitterT ( const MagneticField ifield,
const LinearizationPointFinder fnd 
)

Constructor with user-provided LinearizationPointFinder

Definition at line 108 of file KinematicConstrainedVertexFitterT.h.

References LinearizationPointFinder::clone(), KinematicConstrainedVertexFitterT< nTrk, nConstraint >::csum, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::defaultParameters(), KinematicConstrainedVertexFitterT< nTrk, nConstraint >::finder, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::iterations, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::tBuilder, KinematicConstrainedVertexFitterT< nTrk, nConstraint >::updator, and KinematicConstrainedVertexFitterT< nTrk, nConstraint >::vCons.

110  : field(ifield) {
111  finder = fnd.clone();
116  iterations = -1;
117  csum = -1000.0;
118 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
virtual LinearizationPointFinder * clone() const =0

◆ ~KinematicConstrainedVertexFitterT()

template<int nTrk, int nConstraint>
KinematicConstrainedVertexFitterT< nTrk, nConstraint >::~KinematicConstrainedVertexFitterT ( )

Definition at line 121 of file KinematicConstrainedVertexFitterT.h.

References HLT_2022v15_cff::finder, and HLT_2022v15_cff::updator.

121  {
122  delete finder;
123  delete vCons;
124  delete updator;
125  delete tBuilder;
126 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator

Member Function Documentation

◆ defaultParameters()

template<int nTrk, int nConstraint>
void KinematicConstrainedVertexFitterT< nTrk, nConstraint >::defaultParameters ( )
private

◆ fit() [1/3]

template<int nTrk, int nConstraint>
RefCountedKinematicTree KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit ( const std::vector< RefCountedKinematicParticle > &  part)
inline

Without additional constraint, this will perform a simple vertex fit using LMS with Lagrange multipliers method (by definition valid only if nConstraint=0)

Definition at line 50 of file KinematicConstrainedVertexFitterT.h.

References KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit().

Referenced by KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit(), trackingPlots.Iteration::modules(), and ConversionVertexFinder::run().

50 { return fit(part, 0, 0); }
part
Definition: HCALResponse.h:20
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)

◆ fit() [2/3]

template<int nTrk, int nConstraint>
RefCountedKinematicTree KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit ( const std::vector< RefCountedKinematicParticle > &  part,
MultiTrackKinematicConstraintT< nTrk, nConstraint > *  cs 
)
inline

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

Definition at line 55 of file KinematicConstrainedVertexFitterT.h.

References callgraph::cs, and KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit().

Referenced by trackingPlots.Iteration::modules().

56  {
57  return fit(part, cs, nullptr);
58  };
part
Definition: HCALResponse.h:20
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)

◆ fit() [3/3]

template<int nTrk, int nConstraint>
RefCountedKinematicTree KinematicConstrainedVertexFitterT< nTrk, nConstraint >::fit ( const std::vector< RefCountedKinematicParticle > &  part,
MultiTrackKinematicConstraintT< nTrk, nConstraint > *  cs,
GlobalPoint pt 
)

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

Definition at line 145 of file KinematicConstrainedVertexFitterT.h.

References cms::cuda::assert(), callgraph::cs, dumpMFGeometry_cfg::delta, HLT_2022v15_cff::finder, mps_fire::i, input, LogDebug, allConversions_cfi::maxDelta, ecalTrigSettings_cff::particles, DiDispStaMuonMonitor_cfi::pt, InputSort::sort(), HLT_2022v15_cff::updator, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by trackingPlots.Iteration::modules().

148  {
149  assert(nConstraint == 0 || cs != nullptr);
150  if (part.size() != nTrk)
151  throw VertexException("KinematicConstrainedVertexFitterT::input states are not nTrk");
152 
153  //sorting out the input particles
154  InputSort iSort;
155  std::pair<std::vector<RefCountedKinematicParticle>, std::vector<FreeTrajectoryState> > input = iSort.sort(part);
156  const std::vector<RefCountedKinematicParticle>& particles = input.first;
157  const std::vector<FreeTrajectoryState>& fStates = input.second;
158 
159  // linearization point:
160  GlobalPoint linPoint = (pt != nullptr) ? *pt : finder->getLinearizationPoint(fStates);
161 
162  //initial parameters:
163  ROOT::Math::SVector<double, 3 + 7 * nTrk> inPar; //3+ 7*ntracks
164  ROOT::Math::SVector<double, 3 + 7 * nTrk> finPar; //3+ 7*ntracks
165 
166  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > inCov;
167 
168  //making initial vector of parameters and initial particle-related covariance
169  int nSt = 0;
170  std::vector<KinematicState> lStates(nTrk);
171  for (std::vector<RefCountedKinematicParticle>::const_iterator i = particles.begin(); i != particles.end(); i++) {
172  lStates[nSt] = (*i)->stateAtPoint(linPoint);
173  KinematicState const& state = lStates[nSt];
174  if (!state.isValid()) {
175  LogDebug("KinematicConstrainedVertexFitter") << "State is invalid at point: " << linPoint << std::endl;
177  }
178  inPar.Place_at(state.kinematicParameters().vector(), 3 + 7 * nSt);
179  inCov.Place_at(state.kinematicParametersError().matrix(), 3 + 7 * nSt, 3 + 7 * nSt);
180  ++nSt;
181  }
182 
183  //initial vertex error matrix components (huge error method)
184  //and vertex related initial vector components
185  double in_er = 100.;
186  inCov(0, 0) = in_er;
187  inCov(1, 1) = in_er;
188  inCov(2, 2) = in_er;
189 
190  inPar(0) = linPoint.x();
191  inPar(1) = linPoint.y();
192  inPar(2) = linPoint.z();
193 
194  //constraint equations value and number of iterations
195  double eq;
196  int nit = 0;
197  iterations = 0;
198  csum = 0.0;
199 
200  GlobalPoint lPoint = linPoint;
202  ROOT::Math::SMatrix<double, 3 + 7 * nTrk, 3 + 7 * nTrk, ROOT::Math::MatRepSym<double, 3 + 7 * nTrk> > refCCov =
203  ROOT::Math::SMatrixNoInit();
204 
205  double chisq = 1e6;
206  bool convergence = false;
207 
208  //iterarions over the updator: each time updated parameters
209  //are taken as new linearization point
210  do {
211  eq = 0.;
212  refCCov = inCov;
213  std::vector<KinematicState> oldStates = lStates;
214  GlobalVector mf = field->inInverseGeV(lPoint);
215  rVtx = updator->update(inPar, refCCov, lStates, lPoint, mf, cs);
216  if (particles.size() != lStates.size() || rVtx == nullptr) {
217  LogDebug("KinematicConstrainedVertexFitter") << "updator failure\n";
219  }
220 
221  double newchisq = rVtx->chiSquared();
222  if (nit > 2 && newchisq > theMaxReducedChiSq * rVtx->degreesOfFreedom() &&
223  (newchisq - chisq) > (-theMinChiSqImprovement)) {
224  LogDebug("KinematicConstrainedVertexFitter") << "bad chisq and insufficient improvement, bailing\n";
226  }
227  chisq = newchisq;
228 
229  const GlobalPoint& newPoint = rVtx->position();
230 
231  double maxDelta = 0.0;
232 
233  double deltapos[3];
234  deltapos[0] = newPoint.x() - lPoint.x();
235  deltapos[1] = newPoint.y() - lPoint.y();
236  deltapos[2] = newPoint.z() - lPoint.z();
237  for (int i = 0; i < 3; ++i) {
238  double delta = deltapos[i] * deltapos[i] / rVtx->error().matrix()(i, i);
239  if (delta > maxDelta)
240  maxDelta = delta;
241  }
242 
243  for (std::vector<KinematicState>::const_iterator itold = oldStates.begin(), itnew = lStates.begin();
244  itnew != lStates.end();
245  ++itold, ++itnew) {
246  for (int i = 0; i < 7; ++i) {
247  double deltapar = itnew->kinematicParameters()(i) - itold->kinematicParameters()(i);
248  double delta = deltapar * deltapar / itnew->kinematicParametersError().matrix()(i, i);
249  if (delta > maxDelta)
250  maxDelta = delta;
251  }
252  }
253 
254  lPoint = newPoint;
255 
256  nit++;
257  convergence = maxDelta < theMaxDelta || (nit == theMaxStep && maxDelta < 4.0 * theMaxDelta);
258 
259  } while (nit < theMaxStep && !convergence);
260 
261  if (!convergence) {
263  }
264 
265  // std::cout << "new full cov matrix" << std::endl;
266  // std::cout << refCCov << std::endl;
267 
268  iterations = nit;
269  csum = eq;
270 
271  return tBuilder->buildTree<nTrk>(particles, lStates, rVtx, refCCov);
272 }
std::pair< std::vector< RefCountedKinematicParticle >, std::vector< FreeTrajectoryState > > sort(const std::vector< RefCountedKinematicParticle > &particles) const
Definition: InputSort.cc:5
T z() const
Definition: PV3DBase.h:61
Common base class.
GlobalVector inInverseGeV(const GlobalPoint &gp) const
Field value ad specified global point, in 1/Gev.
Definition: MagneticField.h:36
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
part
Definition: HCALResponse.h:20
virtual GlobalPoint getLinearizationPoint(const std::vector< reco::TransientTrack > &) const =0
RefCountedKinematicTree buildTree(const std::vector< RefCountedKinematicParticle > &initialParticles, const std::vector< KinematicState > &finalStates, const RefCountedKinematicVertex vtx, const ROOT::Math::SMatrix< double, 3+7 *nTrk, 3+7 *nTrk, ROOT::Math::MatRepSym< double, 3+7 *nTrk > > &fCov) const
#define LogDebug(id)

◆ getCSum()

template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::getCSum ( ) const

Definition at line 280 of file KinematicConstrainedVertexFitterT.h.

◆ getNit()

template<int nTrk, int nConstraint>
int KinematicConstrainedVertexFitterT< nTrk, nConstraint >::getNit ( ) const

◆ setParameters()

template<int nTrk, int nConstraint>
void KinematicConstrainedVertexFitterT< nTrk, nConstraint >::setParameters ( const edm::ParameterSet pSet)

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

Definition at line 129 of file KinematicConstrainedVertexFitterT.h.

References edm::ParameterSet::getParameter().

Referenced by ConversionVertexFinder::run().

129  {
130  theMaxDelta = pSet.getParameter<double>("maxDelta");
131  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
132  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
133  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
134 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

Member Data Documentation

◆ csum

template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::csum
private

◆ field

template<int nTrk, int nConstraint>
const MagneticField* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::field
private

Definition at line 75 of file KinematicConstrainedVertexFitterT.h.

◆ finder

template<int nTrk, int nConstraint>
LinearizationPointFinder* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::finder
private

◆ iterations

template<int nTrk, int nConstraint>
int KinematicConstrainedVertexFitterT< nTrk, nConstraint >::iterations
private

◆ tBuilder

template<int nTrk, int nConstraint>
ConstrainedTreeBuilderT* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::tBuilder
private

◆ theMaxDelta

template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::theMaxDelta
private

Definition at line 81 of file KinematicConstrainedVertexFitterT.h.

◆ theMaxReducedChiSq

template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::theMaxReducedChiSq
private

Definition at line 83 of file KinematicConstrainedVertexFitterT.h.

◆ theMaxStep

template<int nTrk, int nConstraint>
int KinematicConstrainedVertexFitterT< nTrk, nConstraint >::theMaxStep
private

Definition at line 82 of file KinematicConstrainedVertexFitterT.h.

◆ theMinChiSqImprovement

template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::theMinChiSqImprovement
private

Definition at line 84 of file KinematicConstrainedVertexFitterT.h.

◆ updator

template<int nTrk, int nConstraint>
KinematicConstrainedVertexUpdatorT<nTrk, nConstraint>* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::updator
private

◆ vCons

template<int nTrk, int nConstraint>
VertexKinematicConstraintT* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::vCons
private