CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 24 of file KinematicConstrainedVertexFitterT.h.

Constructor & Destructor Documentation

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

Default constructor using LMSLinearizationPointFinder

Definition at line 104 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.

104  :
105  field(ifield)
106 {
112  iterations = -1;
113  csum = -1000.0;
114 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
template<int nTrk, int nConstraint>
KinematicConstrainedVertexFitterT< nTrk, nConstraint >::KinematicConstrainedVertexFitterT ( const MagneticField ifield,
const LinearizationPointFinder fnd 
)

Constructor with user-provided LinearizationPointFinder

Definition at line 117 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.

117  :
118  field(ifield)
119 {
120  finder = fnd.clone();
125  iterations = -1;
126  csum = -1000.0;
127 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
virtual LinearizationPointFinder * clone() const =0
template<int nTrk, int nConstraint>
KinematicConstrainedVertexFitterT< nTrk, nConstraint >::~KinematicConstrainedVertexFitterT ( )

Definition at line 130 of file KinematicConstrainedVertexFitterT.h.

References HLT_FULL_cff::updator.

131 {
132  delete finder;
133  delete vCons;
134  delete updator;
135  delete tBuilder;
136 }
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator

Member Function Documentation

template<int nTrk, int nConstraint>
void KinematicConstrainedVertexFitterT< nTrk, nConstraint >::defaultParameters ( )
private
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 51 of file KinematicConstrainedVertexFitterT.h.

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

51  {
52  return fit(part, 0, 0);
53  }
part
Definition: HCALResponse.h:20
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
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 58 of file KinematicConstrainedVertexFitterT.h.

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

Referenced by trackingPlots.Iteration::modules().

59  {
60  return fit(part, cs, 0);
61  };
part
Definition: HCALResponse.h:20
RefCountedKinematicTree fit(const std::vector< RefCountedKinematicParticle > &part)
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 159 of file KinematicConstrainedVertexFitterT.h.

References assert(), delta, Vispa.Plugins.EdmBrowser.EdmDataAccessor::eq(), i, input, KinematicState::isValid(), KinematicState::kinematicParameters(), KinematicState::kinematicParametersError(), LogDebug, KinematicParametersError::matrix(), InputSort::sort(), HLT_FULL_cff::updator, KinematicParameters::vector(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by trackingPlots.Iteration::modules().

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

Definition at line 295 of file KinematicConstrainedVertexFitterT.h.

295  {
296  return csum;
297 }
template<int nTrk, int nConstraint>
int KinematicConstrainedVertexFitterT< nTrk, nConstraint >::getNit ( ) const
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 139 of file KinematicConstrainedVertexFitterT.h.

References edm::ParameterSet::getParameter().

Referenced by ConversionVertexFinder::run().

140 {
141  theMaxDelta = pSet.getParameter<double>("maxDelta");
142  theMaxStep = pSet.getParameter<int>("maxNbrOfIterations");
143  theMaxReducedChiSq = pSet.getParameter<double>("maxReducedChiSq");
144  theMinChiSqImprovement = pSet.getParameter<double>("minChiSqImprovement");
145 }
T getParameter(std::string const &) const

Member Data Documentation

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

Definition at line 79 of file KinematicConstrainedVertexFitterT.h.

template<int nTrk, int nConstraint>
LinearizationPointFinder* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::finder
private
template<int nTrk, int nConstraint>
int KinematicConstrainedVertexFitterT< nTrk, nConstraint >::iterations
private
template<int nTrk, int nConstraint>
ConstrainedTreeBuilderT* KinematicConstrainedVertexFitterT< nTrk, nConstraint >::tBuilder
private
template<int nTrk, int nConstraint>
float KinematicConstrainedVertexFitterT< nTrk, nConstraint >::theMaxDelta
private

Definition at line 85 of file KinematicConstrainedVertexFitterT.h.

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

Definition at line 87 of file KinematicConstrainedVertexFitterT.h.

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

Definition at line 86 of file KinematicConstrainedVertexFitterT.h.

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

Definition at line 88 of file KinematicConstrainedVertexFitterT.h.

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