35 10.,5.,5.,10., 10.,5.,5.,10.,
36 10.,5.,5.,5., 5.,5.,5.,5., 5.,5.,5.,10.,
37 10.,5.,5.,5., 5.,5.,5.,5., 5.,5.,5.,5., 5.,5.,5.,10.,
105 bool permitFlips = _allowFlips;
106 bool lPickHits = _allowDrops;
113 register double chisqold;
114 double chisqnew, chichange;
115 double chitest = 0.01;
150 std::vector<double> delChi(
nhits,0);
151 std::vector<std::vector<double> > deriv(
nhits);
155 int npar = theTraj.
nPar();
160 bool l3d = (npar > 3);
161 const int minZ = l3d ? 2 : 0;
162 const int minXY = npar - minZ;
163 const int minAct = minZ + minXY;
165 HepSymMatrix vparam(npar,0);
166 HepVector diffsum(npar);
167 HepVector delpar(npar);
169 std::vector<std::vector<double> >::iterator ideriv = deriv.begin();
170 std::vector<double>::iterator idelChi = delChi.begin();
171 assert(((
int)deriv.size()) ==(hitlist.
end()-hitlist.
begin()));
173 ideriv->resize(npar);
174 if (ihit->isActive()) {
189 if (nXY < minXY ||
nZ < minZ || nActive < minAct) {
190 status.
setFailure(11,
"Not enough hits in TrkHelixFitter! ");
207 HepVector derivs(npar);
213 bool mustIterate(
false);
215 for (i = 0; i < npar; i++) diffsum[i] = 0.0;
219 std::vector<std::vector<double> >::iterator ideriv = deriv.begin();
220 std::vector<double>::iterator idelChi = delChi.begin();
221 assert(((
int)deriv.size())==(hitlist.
end()-hitlist.
begin()));
229 calcResult = ihit->getFitStuff(derivs, deltaChiNew);
230 for (i=0; i<npar; ++i) (*ideriv)[i] = derivs[i];
238 calcResult = ihit->getFitStuff(deltaChiNew);
243 cout<<
"ErrMsg(warning) TrkHelixFitter:"
244 <<
"unable to getFitStuff for hit " << *ihit << endl;
246 ihit->setUsability(
false);
249 mustIterate = (mustIterate || (calcResult.
success() != 1));
250 *idelChi = deltaChiNew;
252 cout << (ihit-hitlist.
begin());
253 ihit->print(std::cout);
254 cout <<
" dChi " << *idelChi
255 <<
" amb " << ihit->ambig()
256 <<
" resid " << ihit->resid()
257 <<
" rms " << ihit->hitRms()
258 <<
" hitlen " << ihit->hitLen()
259 <<
" fltlen " << ihit->fltLen() << endl;
261 if (ihit->isActive() ==
false) {
262 if(
m_debug) std::cout<<
"SKIP not active hit"<< std::endl;
265 chisqold += deltaChiNew * deltaChiNew;
267 for (i = 0; i < npar; ++i) {
268 diffsum[i] += (*ideriv)[i] * deltaChiNew;
269 for (
int j = 0; j < i+1; ++j) {
270 vparam.fast(i+1,j+1) += (*ideriv)[i] * (*ideriv)[j];
281 cout<<
"ErrMsg(warning) TrkHelixFitter:"
282 <<
"Matrix inversion failed " << endl;
284 status.
setFailure(12,
"Matrix inversion failed in TrkHelixFitter");
287 delpar = vparam * (-diffsum);
289 cout <<
" delpar = "<<delpar << endl;
293 if (fabs(delpar[1]) > 1.) {
295 cout<<
"ErrMsg(warning) TrkHelixFitter:"
296 <<
"Pathological fit " << endl;
298 status.
setFailure(13,
"Pathological fit in TrkHelixFitter.");
302 for (i = 0; i < npar; ++i) params.
parameter()[i] += delpar[i];
304 cout <<
" params "<<params.
parameter() << endl;
313 double bigDelChi = 0.0;
316 mustIterate = (mustIterate || (
iter <= 2 && lPickHits));
317 ideriv = deriv.begin();
318 idelChi = delChi.begin();
321 ihit->print(std::cout);
323 if(!ihit->isUsable()){
324 if(
m_debug) { std::cout<<
"hit NOT usable "<< std::endl; }
328 for (i = 0; i < npar; i++) {
329 *idelChi += (*ideriv)[i] * delpar[i];
331 if (ihit->isActive()) chisqnew += *idelChi * *idelChi;
334 if (!mustIterate && lPickHits) {
335 double abDelChi = fabs(*idelChi);
337 if (abDelChi <=
nSigmaCut[ihit->layerNumber()] ) {
339 std::cout<<
"abDelChi "<<abDelChi
340 <<
"<?"<<
nSigmaCut[ihit->layerNumber()] << std::endl;
342 if (ihit->isActive() == 0) {
343 ihit->setActivity(1);
344 if(
m_debug){ cout <<
"set ACTIVE, Added " << endl; }
355 if (ihit->isActive()) {
356 if (abDelChi > bigDelChi) {
358 std::cout<<
"bigest set INACTIVE, abDelChi = "<<abDelChi
359 <<
">"<<
nSigmaCut[ihit->layerNumber()] <<
" bigDelChi=" <<bigDelChi<< std::endl; }
360 bigDelChi = abDelChi;
371 if (bigHit != hitlist.
end() && (nActive > minAct)) {
387 bigHit->setActivity(0);
389 std::cout<<
"---deactivate hit!! delChi2="<<bigDelChi<< std::endl;
391 bigHit->print(std::cout);
392 std::cout<<
"--------------------!! "<< std::endl;
399 chichange = chisqold - chisqnew;
401 cout <<
"chisq from "<<chisqold <<
" -> " << chisqnew << endl;
403 if (chichange < -0.5 && !mustIterate && lPicked == 0) {
405 cout<<
"ErrMsg(warning)" <<
" blowing up: " << chichange << endl;
408 setLastChisq(chisqnew);
411 if(
m_debug) std::cout<<
"failure 1 "<< std::endl;
413 }
else if (chichange < chitest && !mustIterate && lPicked ==0){
416 setLastChisq(chisqnew);
417 if(
m_debug) std::cout<<
"success 1 "<< std::endl;
421 if (
iter == itermax) {
422 setLastChisq(chisqnew);
424 if(
m_debug) std::cout<<
"success 2 "<< std::endl;