1 #ifndef KinematicConstrainedVertexFitterT_H
2 #define KinematicConstrainedVertexFitterT_H
52 return fit(part, 0, 0);
60 return fit(part, cs, 0);
103 template <
int nTrk,
int nConstra
int>
116 template <
int nTrk,
int nConstra
int>
129 template <
int nTrk,
int nConstra
int>
138 template <
int nTrk,
int nConstra
int>
142 theMaxStep = pSet.
getParameter<
int>(
"maxNbrOfIterations");
143 theMaxReducedChiSq = pSet.
getParameter<
double>(
"maxReducedChiSq");
144 theMinChiSqImprovement = pSet.
getParameter<
double>(
"minChiSqImprovement");
147 template <
int nTrk,
int nConstra
int>
152 theMaxReducedChiSq = 225.;
153 theMinChiSqImprovement = 50.;
157 template <
int nTrk,
int nConstra
int>
163 assert( nConstraint==0 || cs!=0);
164 if(part.size()!=nTrk)
throw VertexException(
"KinematicConstrainedVertexFitterT::input states are not nTrk");
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;
173 GlobalPoint linPoint = (pt!=0) ? *pt : finder->getLinearizationPoint(fStates);
176 ROOT::Math::SVector<double,3+7*nTrk> inPar;
177 ROOT::Math::SVector<double,3+7*nTrk> finPar;
179 ROOT::Math::SMatrix<double, 3+7*nTrk,3+7*nTrk ,ROOT::Math::MatRepSym<double,3+7*nTrk> > inCov;
183 std::vector<KinematicState> lStates(nTrk);
184 for(std::vector<RefCountedKinematicParticle>::const_iterator
i = particles.begin();
i!=particles.end();
i++)
186 lStates[nSt] = (*i)->stateAtPoint(linPoint);
189 LogDebug(
"KinematicConstrainedVertexFitter")
190 <<
"State is invalid at point: "<<linPoint<<std::endl;
205 inPar(0) = linPoint.
x();
206 inPar(1) = linPoint.
y();
207 inPar(2) = linPoint.
z();
217 ROOT::Math::SMatrix<double, 3+7*nTrk,3+7*nTrk ,ROOT::Math::MatRepSym<double,3+7*nTrk> > refCCov;
220 bool convergence =
false;
227 std::vector<KinematicState> oldStates = lStates;
229 rVtx =
updator->update(inPar,refCCov,lStates,lPoint,mf,cs);
230 if (particles.size() != lStates.size()) {
231 LogDebug(
"KinematicConstrainedVertexFitter")
232 <<
"updator failure\n";
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";
248 double maxDelta = 0.0;
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_new()(
i,
i);
256 if (delta>maxDelta) maxDelta =
delta;
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;
271 convergence = maxDelta<theMaxDelta || (nit==theMaxStep && maxDelta<4.0*theMaxDelta);
273 }
while(nit<theMaxStep && !convergence);
285 return tBuilder->buildTree<nTrk>(particles, lStates, rVtx, refCCov);
289 template <
int nTrk,
int nConstra
int>
294 template <
int nTrk,
int nConstra
int>
T getParameter(std::string const &) const
AlgebraicVector7 const & vector() const
The full vector (7 elements)
~KinematicConstrainedVertexFitterT()
VertexKinematicConstraintT * vCons
const MagneticField * field
float theMinChiSqImprovement
LinearizationPointFinder * finder
void setParameters(const edm::ParameterSet &pSet)
KinematicConstrainedVertexFitterT(const MagneticField *ifield)
RefCountedKinematicTree fit(std::vector< RefCountedKinematicParticle > part, MultiTrackKinematicConstraintT< nTrk, nConstraint > *cs)
KinematicParametersError const & kinematicParametersError() const
RefCountedKinematicTree fit(std::vector< RefCountedKinematicParticle > part)
KinematicParameters const & kinematicParameters() const
KinematicConstrainedVertexUpdatorT< nTrk, nConstraint > * updator
virtual LinearizationPointFinder * clone() const =0
ConstrainedTreeBuilderT * tBuilder
AlgebraicSymMatrix77 matrix() const