One Kalman step.
304 GFAbsRecoHit*
hit = tr->getHit(ihit);
305 GFAbsTrackRep* rep = tr->getTrackRep(irep);
308 int repDim = rep->getDim();
309 TMatrixT<Double_t> state(repDim,1);
310 TMatrixT<Double_t> cov(repDim,repDim);
311 static TMatrixT<Double_t> covFilt(cov);
312 const double pi2(10.0);
313 GFDetPlane pl, plPrev;
314 unsigned int nhits=tr->getNumHits();
316 static TMatrixT<Double_t> oldState(5,1);
317 static std::vector<TVector3> pointsPrev;
319 const double eps(1.0
e-6);
328 GFAbsRecoHit* hitPrev = tr->getHit(phit);
339 Double_t thetaPlanes(0.0);
340 if(ihit!=tr->getRepAtHit(irep)){
350 pl=hit->getDetPlane(rep);
351 plPrev=hitPrev->getDetPlane(rep);
362 rep->extrapolate(pl,state,cov);
376 throw cet::exception(
"GFKalman.cxx: ") <<
" Line " << __LINE__ <<
", " << __FILE__ <<
" ...Rethrow. \n";
381 pl = rep->getReferencePlane();
382 plPrev = hitPrev->getDetPlane(rep);
383 state = rep->getState();
393 TVector3 u(pl.getU());
394 TVector3 v(pl.getV());
395 TVector3 wold(u.Cross(v));
399 TVector3 pTilde =
direction * (wold + state[1][0] * u + state[2][0] * v);
400 TVector3
w(pTilde.Unit());
402 TVector3 rot(wold.Cross(
w));
403 Double_t ang(TMath::ACos(
w*wold));
404 ang = TMath::Min(ang,0.95*TMath::Pi()/2.0);
415 if(cov[0][0]<1.
E-50 || TMath::IsNaN(cov[0][0])){
419 if (
fGENfPRINT) std::cout<<
"GFKalman::processHit() 1. No longer throw exception. Force cov[0][0] to 0.01."<<
std::endl;
442 int pdg = tr->getPDG();
443 TParticlePDG * part = TDatabasePDG::Instance()->GetParticle(pdg);
444 Double_t mass = part->Mass();
446 Double_t
dist = (pl.getO()-plPrev.getO()).Mag();
447 Double_t mom = fabs(1.0/state[0][0]);
448 Double_t
beta = mom/sqrt(mass*mass+mom*mom);
449 const Double_t lowerLim(0.01);
450 if (std::isnan(dist) || dist<=0.0) dist=lowerLim;
451 if (std::isnan(beta) || beta<0.01) beta=0.01;
452 TMatrixT<Double_t> H=hit->getHMatrix(rep,beta,dist);
457 TMatrixT<Double_t> V=hit->getHitCov(pl,plPrev,state,mass);
459 tr->setHitMeasuredCov(V);
462 TMatrixT<Double_t> Gain(
calcGain(cov,V,H));
467 TMatrixT<Double_t> res=hit->residualVector(rep,state,pl,plPrev,mass);
473 TMatrixT<Double_t> rawcoord = hit->getRawHitCoord();
474 TVector3 point(rawcoord[0][0],rawcoord[1][0],rawcoord[2][0]);
475 TMatrixT<Double_t> prevrawcoord = hitPrev->getRawHitCoord();
476 TVector3 pointPrev(prevrawcoord[0][0],prevrawcoord[1][0],prevrawcoord[2][0]);
477 pointsPrev.push_back(pointPrev);
478 TMatrixT<Double_t> Hnew(H);
482 TVector3 pointer((point-pointPrev).Unit());
483 static TVector3 pointerPrev(pointer);
485 {pointer[0] = 0.0;pointer[1] = 0.0;pointer[2] = 1.0;}
487 {pointer[0] = 0.0;pointer[1] = 0.0;pointer[2] = -1.0;}
488 double thetaMeas = TMath::Min(fabs(pointer.Angle(pointerPrev)),0.95*TMath::Pi()/2.0);
494 ang = (Hnew*state)[0][0];
498 thetaPlanes = gRandom->Gaus(0.0,ang*ang);
499 thetaPlanes = TMath::Min(sqrt(fabs(thetaPlanes)),0.95*TMath::Pi()/2.0);
501 Double_t dtheta = thetaMeas - thetaPlanes;
502 if (((ihit==((
int)nhits-1)||ihit==((
int)nhits-2))&&
direction==-1) || ((ihit==0||ihit==1)&&
direction==1))
506 rep->setData(state,pl,&cov);
508 pointerPrev = pointer;
514 res[0][0] = dtheta/Hnew[0][0];
519 TVector3 uPrev(plPrev.getU());
520 TVector3 vPrev(plPrev.getV());
521 TVector3 wPrev(u.Cross(v));
528 static GFDetPlane plFilt;
529 if (plFilt.getO().Mag()>eps)
531 uPrev = plFilt.getU();
532 vPrev = plFilt.getV();
533 wPrev = plFilt.getNormal();
540 TMatrixT<Double_t> update=Gain*res;
550 tr->setHitUpdate(update);
563 TMatrixT<Double_t> GH(Gain*Hnew);
567 Hnew[0][0] = Hnew[0][0] - eps/Gain[0][0];
569 TMatrixT<Double_t> GHc(GH*cov);
571 cov-=Gain*(Hnew*cov);
577 if (cov[0][0] <= 0.0 || TMath::IsNaN(cov[0][0]))
579 cov[0][0]=
pi2/Hnew[0][0];
590 tr->setHitCov7x7(cov7x7);
591 tr->setHitState(state);
593 if (fabs(1.0/state[0][0])<
fMomLow)
594 state[0][0] = 1.0/
fMomLow*fabs(state[0][0])/state[0][0];
596 state[0][0] = 1.0/
fMomHigh*fabs(state[0][0])/state[0][0];
603 TVector3 uf(pl.getU());
604 TVector3 vf(pl.getV());
605 TVector3 wf(uf.Cross(vf));
606 TVector3 Of(pl.getO());
611 TVector3 pf =
direction*(wf + state[1][0] * uf + state[2][0] * vf);
612 TVector3 pposf = Of + state[3][0] * uf + state[4][0] * vf;
613 Double_t angf = TMath::Min(fabs(pf.Angle(wf)),0.95*TMath::Pi()/2.0);
614 TVector3 rotf(wf.Cross(pf.Unit()));
616 uf.Rotate(angf,rotf);
617 vf.Rotate(angf,rotf);
619 plFilt.setU(uf.Unit());
620 plFilt.setV(vf.Unit());
622 plFilt.setNormal(pf.Unit());
624 tr->setHitPlaneXYZ(plFilt.getO());
625 tr->setHitPlaneUxUyUz(plFilt.getNormal());
626 tr->setHitPlaneU(plFilt.getU());
627 tr->setHitPlaneV(plFilt.getV());
630 TMatrixT<Double_t>
r=hit->residualVector(rep,state,plFilt,plPrev,mass);
631 if (
direction==-1) wold.Rotate(TMath::Pi(),wold.Orthogonal());
632 dtheta = thetaMeas - TMath::Min(fabs(wold.Angle(plFilt.getNormal())),0.95*TMath::Pi()/2.);
633 r[0][0] = dtheta/Hnew[0][0];
640 int ndf = r.GetNrows();
641 if (update[0][0]==0.0) {chi2=0.0; ndf=0;};
642 rep->addChiSqu( chi2 );
644 pointerPrev = pointer;
645 tr->setHitChi2(chi2);
664 rep->setData(state,pl,&cov);
666 tr->setRepAtHit(irep,ihit);
double beta(double KE, const simb::MCParticle *part)
TMatrixT< Double_t > calcGain(const TMatrixT< Double_t > &cov, const TMatrixT< Double_t > &HitCov, const TMatrixT< Double_t > &H)
Calculate Kalman Gain.
double chi2Increment(const TMatrixT< Double_t > &r, const TMatrixT< Double_t > &H, const TMatrixT< Double_t > &cov, const TMatrixT< Double_t > &V)
this returns the reduced chi2 increment for a hit
Detector simulation of raw signals on wires.
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
TMatrixT< Double_t > calcCov7x7(const TMatrixT< Double_t > &cov, const genf::GFDetPlane &plane)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)