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 9 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 20 of file KinematicConstrainedVertexFitter.cc.

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

KinematicConstrainedVertexFitter::~KinematicConstrainedVertexFitter ( )

Definition at line 31 of file KinematicConstrainedVertexFitter.cc.

References finder, tBuilder, updator, and vCons.

32 {
33  delete finder;
34  delete vCons;
35  delete updator;
36  delete tBuilder;
37 }
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 48 of file KinematicConstrainedVertexFitter.h.

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

48  {
49  return fit(part, 0, 0);
50  }
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 55 of file KinematicConstrainedVertexFitter.h.

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

Referenced by trackingPlots.Iteration::modules().

56  {
57  return fit(part, cs, 0);
58  };
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 55 of file KinematicConstrainedVertexFitter.cc.

References ConstrainedTreeBuilder::buildTree(), csum, delta, Vispa.Plugins.EdmBrowser.EdmDataAccessor::eq(), finder, LinearizationPointFinder::getLinearizationPoint(), i, input, KinematicState::isValid(), iterations, j, KinematicState::kinematicParameters(), KinematicState::kinematicParametersError(), LogDebug, KinematicParametersError::matrix(), allConversions_cfi::maxDelta, HadronAndPartonSelector_cfi::particles, EnergyCorrector::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().

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

Definition at line 209 of file KinematicConstrainedVertexFitter.cc.

References csum.

Referenced by fit().

209  {
210  return csum;
211 }
int KinematicConstrainedVertexFitter::getNit ( ) const

Definition at line 205 of file KinematicConstrainedVertexFitter.cc.

References iterations.

Referenced by fit(), and ConversionVertexFinder::run().

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

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

Definition at line 39 of file KinematicConstrainedVertexFitter.cc.

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

40 {
41  theMaxDelta = pSet.getParameter<double>("maxDelta");
42  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
43  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
44  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
45 }
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 76 of file KinematicConstrainedVertexFitter.h.

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

float KinematicConstrainedVertexFitter::theMaxReducedChiSq
private

Definition at line 78 of file KinematicConstrainedVertexFitter.h.

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

int KinematicConstrainedVertexFitter::theMaxStep
private

Definition at line 77 of file KinematicConstrainedVertexFitter.h.

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

float KinematicConstrainedVertexFitter::theMinChiSqImprovement
private

Definition at line 79 of file KinematicConstrainedVertexFitter.h.

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

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