53 trk->clearBookkeeping();
57 unsigned int nreps=trk->getNumReps();
58 unsigned int nhits=trk->getNumHits();
60 for(
unsigned int i=0; i<nreps; ++i){
61 GFBookkeeping *bk = trk->getBK(i);
63 bk->bookMatrices(
"fPredSt");
64 bk->bookMatrices(
"fPredCov");
65 bk->bookMatrices(
"bPredSt");
66 bk->bookMatrices(
"bPredCov");
67 bk->bookMatrices(
"H");
68 bk->bookMatrices(
"m");
69 bk->bookMatrices(
"V");
70 bk->bookGFDetPlanes(
"pl");
71 bk->bookMatrices(
"smooResid");
72 bk->bookNumbers(
"p",1.);
76 std::vector< std::vector<int>* >
planes;
77 trk->getHitsByPlane(planes);
78 int nPlanes = planes.size();
80 trk->clearFailedHits();
81 for(
unsigned int iBeta=0; iBeta<
fBeta.size(); iBeta++){
84 for(
int ipl=0; ipl<nPlanes; ++ipl){
86 std::vector< GFAbsRecoHit* > hits;
87 unsigned int nhitsInPlane = planes.at(ipl)->size();
88 for(
unsigned int ihitInPl=0;ihitInPl<nhitsInPlane;++ihitInPl){
89 hits.push_back( trk->getHit(planes.at(ipl)->at(ihitInPl)) );
93 for(
unsigned int irep=0; irep<nreps; ++irep){
94 GFAbsTrackRep* rep=trk->getTrackRep(irep);
95 if(rep->getStatusFlag()!=0)
continue;
97 GFBookkeeping *bk = trk->getBK(irep);
98 if(bk->hitFailed(planes.at(ipl)->at(0))>0)
continue;
101 int repDim=rep->getDim();
102 TMatrixT<Double_t>
state(repDim,1);
103 TMatrixT<Double_t> cov(repDim,repDim);;
105 if(ipl>0 || (ipl==0 && iBeta==0) ){
111 pl=hits.at(0)->getDetPlane(rep);
113 rep->extrapolate(pl,
state,cov);
115 if(cov[0][0]<1.
E-50){
123 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->addFailedHit(irep,planes.at(ipl)->at(i));
125 rep->setStatusFlag(1);
132 pl = rep->getReferencePlane();
133 state = rep->getState();
137 TMatrixT<Double_t> H=hits.at(0)->getHMatrix(rep);
138 bk->setMatrix(
"fPredSt",planes.at(ipl)->at(0),
state);
139 bk->setMatrix(
"fPredCov",planes.at(ipl)->at(0),cov);
141 TMatrixT<Double_t> covInv;
144 TMatrixT<Double_t> Htransp(H);
147 bk->setMatrix(
"H",planes.at(ipl)->at(0),H);
148 bk->setDetPlane(
"pl",planes.at(ipl)->at(0),pl);
150 TMatrixT<Double_t> stMod(
state.GetNrows(),1);
153 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
155 bk->getNumber(
"p",planes.at(ipl)->at(ihit),pki);
158 TMatrixT<Double_t>
V = hits.at(0)->getHitCov(pl);
159 TMatrixT<Double_t> Vinv;
161 bk->setMatrix(
"V",planes.at(ipl)->at(0),
V);
162 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
165 TMatrixT<Double_t>
m = hits.at(ihit)->getHitCoord(pl);
166 bk->setMatrix(
"m",planes.at(ipl)->at(ihit),
m);
169 bk->getNumber(
"p",planes.at(ipl)->at(ihit),pki);
170 TMatrixT<Double_t> Gain =
calcGain(cov,V,H,sumPk);
172 stMod += pki*Gain*(m-H*
state);
176 rep->setData(
state,pl,&cov);
182 for(
int ipl=nPlanes-1; ipl>=0; --ipl){
184 std::vector< GFAbsRecoHit* > hits;
185 unsigned int nhitsInPlane = planes.at(ipl)->size();
186 for(
unsigned int ihitInPl=0;ihitInPl<nhitsInPlane;++ihitInPl){
187 hits.push_back( trk->getHit(planes.at(ipl)->at(ihitInPl)) );
191 for(
unsigned int irep=0; irep<nreps; ++irep){
192 GFAbsTrackRep* rep=trk->getTrackRep(irep);
193 if(rep->getStatusFlag()!=0)
continue;
195 GFBookkeeping *bk = trk->getBK(irep);
196 if(bk->hitFailed(planes.at(ipl)->at(0))>0)
continue;
198 int repDim=rep->getDim();
199 TMatrixT<Double_t>
state(repDim,1);
200 TMatrixT<Double_t> cov(repDim,repDim);;
202 TMatrixT<Double_t> H;
203 bk->getMatrix(
"H",planes.at(ipl)->at(0),H);
204 TMatrixT<Double_t> Htransp(H);
207 bk->getDetPlane(
"pl",planes.at(ipl)->at(0),pl);
212 rep->extrapolate(pl,
state,cov);
213 if(cov[0][0]<1.
E-50){
223 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->addFailedHit(irep,planes.at(ipl)->at(i));
225 rep->setStatusFlag(1);
231 state = rep->getState();
234 TMatrixT<Double_t> covInv;
237 bk->setMatrix(
"bPredSt",planes.at(ipl)->at(0),
state);
238 bk->setMatrix(
"bPredCov",planes.at(ipl)->at(0),cov);
241 TMatrixT<Double_t> stMod(
state.GetNrows(),1);
244 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
246 bk->getNumber(
"p",planes.at(ipl)->at(ihit),pki);
250 TMatrixT<Double_t>
V;
251 bk->getMatrix(
"V",planes.at(ipl)->at(0),
V);
252 TMatrixT<Double_t> Vinv;
256 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
258 TMatrixT<Double_t>
m;
259 bk->getMatrix(
"m",planes.at(ipl)->at(ihit),
m);
262 bk->getNumber(
"p",planes.at(ipl)->at(ihit),pki);
263 TMatrixT<Double_t> Gain =
calcGain(cov,V,H,sumPk);
266 stMod += pki*Gain*(m-H*
state);
271 rep->setData(
state,pl,&cov);
275 TMatrixT<Double_t> fSt,fCov,bSt,bCov,smooSt,smooCov,fCovInv,bCovInv,
m,H,smooResid;
276 for(
int ipl=0; ipl<nPlanes; ++ipl){
277 for(
unsigned int irep=0; irep<nreps; ++irep){
278 if(trk->getTrackRep(irep)->getStatusFlag()!=0)
continue;
279 GFBookkeeping *bk = trk->getBK(irep);
280 if(bk->hitFailed(planes.at(ipl)->at(0))>0)
continue;
281 bk->getMatrix(
"fPredSt",planes.at(ipl)->at(0),fSt);
282 bk->getMatrix(
"bPredSt",planes.at(ipl)->at(0),bSt);
283 bk->getMatrix(
"fPredCov",planes.at(ipl)->at(0),fCov);
284 bk->getMatrix(
"bPredCov",planes.at(ipl)->at(0),bCov);
285 fCovInv.ResizeTo(fCov);
286 bCovInv.ResizeTo(bCov);
289 smooCov.ResizeTo(fCov);
291 smooSt.ResizeTo(fSt.GetNrows(),1);
292 smooSt = smooCov * (fCovInv*fSt + bCovInv*bSt);
294 bk->getMatrix(
"H",planes.at(ipl)->at(0),H);
295 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
297 bk->getMatrix(
"m",planes.at(ipl)->at(ihit),
m);
298 smooResid.ResizeTo(m.GetNrows(),1);
299 smooResid = m - H*smooSt;
302 bk->setMatrix(
"smooResid",planes.at(ipl)->at(ihit),smooResid);
308 if(iBeta!=
fBeta.size()-1){
309 for(
unsigned int irep=0; irep<nreps; ++irep){
310 GFBookkeeping *bk = trk->getBK(irep);
311 for(
int ipl=0; ipl<nPlanes; ++ipl){
312 if(trk->getTrackRep(irep)->getStatusFlag()!=0)
continue;
313 if(bk->hitFailed(planes.at(ipl)->at(0))>0)
continue;
316 std::vector<double> phi;
317 TMatrixT<Double_t>
V;
318 bk->getMatrix(
"V",planes.at(ipl)->at(0),
V);
319 V *=
fBeta.at(iBeta);
320 TMatrixT<Double_t> Vinv;
322 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
324 bk->getMatrix(
"smooResid",planes.at(ipl)->at(ihit),smooResid);
325 TMatrixT<Double_t> smooResidTransp(smooResid);
327 int dimV = V.GetNrows();
328 double detV = V.Determinant();
329 TMatrixT<Double_t> expArg = smooResidTransp*Vinv*smooResid;
330 if (expArg.GetNrows() != 1)
331 throw std::runtime_error(
"genf::GFDaf::processTrack(): wrong matrix dimensions!");
332 double thisPhi = 1./(pow(2.*TMath::Pi(),dimV/2.)*sqrt(detV))*
exp(-0.5*expArg[0][0]);
333 phi.push_back(thisPhi);
338 throw std::runtime_error(
"genf::GFDaf::processTrack(): chi2 cut too low");
339 sumPhiCut += 1./(2*TMath::Pi()*sqrt(detV))*
exp(-0.5*cutVal/
fBeta.at(iBeta));
341 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
342 bk->setNumber(
"p",planes.at(ipl)->at(ihit), phi.at(ihit)/(sumPhi+sumPhiCut));
BEGIN_PROLOG could also be cerr
void invertMatrix(const TMatrixT< Double_t > &, TMatrixT< Double_t > &)
invert a matrix. First argument is matrix to be inverted, second is return by ref.
virtual const char * what() const
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
std::map< int, double > chi2Cuts
std::vector< double > fBeta
bool isFatal()
get fatal flag.
TMatrixT< Double_t > calcGain(const TMatrixT< Double_t > &cov, const TMatrixT< Double_t > &HitCov, const TMatrixT< Double_t > &H, const double &p)
Calculate Kalman Gain.
void info()
print information in the exception object
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
void blowUpCovs(GFTrack *trk)
This is needed to blow up the covariance matrix before a fitting pass. The method drops off-diagonal ...