42 #define COVEXC "cov_is_zero" 61 for(
unsigned int i=0; i<nreps; ++i){
77 std::vector< std::vector<int>* > planes;
79 int nPlanes = planes.size();
82 for(
unsigned int iBeta=0; iBeta<
fBeta.size(); iBeta++){
85 for(
int ipl=0; ipl<nPlanes; ++ipl){
87 std::vector< GFAbsRecoHit* >
hits;
88 unsigned int nhitsInPlane = planes.at(ipl)->size();
89 for(
unsigned int ihitInPl=0;ihitInPl<nhitsInPlane;++ihitInPl){
90 hits.push_back( trk->
getHit(planes.at(ipl)->at(ihitInPl)) );
94 for(
unsigned int irep=0; irep<nreps; ++irep){
99 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
103 TMatrixT<Double_t> state(repDim,1);
104 TMatrixT<Double_t> cov(repDim,repDim);;
106 if(ipl>0 || (ipl==0 && iBeta==0) ){
112 pl=hits.at(0)->getDetPlane(rep);
116 if(cov[0][0]<1.
E-50){
122 std::cerr << exc.
what();
124 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->
addFailedHit(irep,planes.at(ipl)->at(i));
138 TMatrixT<Double_t> H=hits.at(0)->getHMatrix(rep);
139 bk->
setMatrix(
"fPredSt",planes.at(ipl)->at(0),state);
140 bk->
setMatrix(
"fPredCov",planes.at(ipl)->at(0),cov);
142 TMatrixT<Double_t> covInv;
145 TMatrixT<Double_t> Htransp(H);
148 bk->
setMatrix(
"H",planes.at(ipl)->at(0),H);
151 TMatrixT<Double_t> stMod(state.GetNrows(),1);
154 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
156 bk->
getNumber(
"p",planes.at(ipl)->at(ihit),pki);
159 TMatrixT<Double_t> V = hits.at(0)->getHitCov(pl);
160 TMatrixT<Double_t> Vinv;
162 bk->
setMatrix(
"V",planes.at(ipl)->at(0),V);
163 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
166 TMatrixT<Double_t> m = hits.at(ihit)->getHitCoord(pl);
167 bk->
setMatrix(
"m",planes.at(ipl)->at(ihit),m);
170 bk->
getNumber(
"p",planes.at(ipl)->at(ihit),pki);
171 TMatrixT<Double_t> Gain =
calcGain(cov,V,H,sumPk);
173 stMod += pki*Gain*(m-H*state);
183 for(
int ipl=nPlanes-1; ipl>=0; --ipl){
185 std::vector< GFAbsRecoHit* >
hits;
186 unsigned int nhitsInPlane = planes.at(ipl)->size();
187 for(
unsigned int ihitInPl=0;ihitInPl<nhitsInPlane;++ihitInPl){
188 hits.push_back( trk->
getHit(planes.at(ipl)->at(ihitInPl)) );
192 for(
unsigned int irep=0; irep<nreps; ++irep){
197 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
200 TMatrixT<Double_t> state(repDim,1);
201 TMatrixT<Double_t> cov(repDim,repDim);;
203 TMatrixT<Double_t> H;
204 bk->
getMatrix(
"H",planes.at(ipl)->at(0),H);
205 TMatrixT<Double_t> Htransp(H);
214 if(cov[0][0]<1.
E-50){
221 std::cerr << exc.
what();
224 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->
addFailedHit(irep,planes.at(ipl)->at(i));
235 TMatrixT<Double_t> covInv;
238 bk->
setMatrix(
"bPredSt",planes.at(ipl)->at(0),state);
239 bk->
setMatrix(
"bPredCov",planes.at(ipl)->at(0),cov);
242 TMatrixT<Double_t> stMod(state.GetNrows(),1);
245 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
247 bk->
getNumber(
"p",planes.at(ipl)->at(ihit),pki);
251 TMatrixT<Double_t> V;
252 bk->
getMatrix(
"V",planes.at(ipl)->at(0),V);
253 TMatrixT<Double_t> Vinv;
257 for(
unsigned int ihit=0;ihit<nhitsInPlane;++ihit){
259 TMatrixT<Double_t> m;
260 bk->
getMatrix(
"m",planes.at(ipl)->at(ihit),m);
263 bk->
getNumber(
"p",planes.at(ipl)->at(ihit),pki);
264 TMatrixT<Double_t> Gain =
calcGain(cov,V,H,sumPk);
267 stMod += pki*Gain*(m-H*state);
276 TMatrixT<Double_t> fSt,fCov,bSt,bCov,smooSt,smooCov,fCovInv,bCovInv,m,H,smooResid;
277 for(
int ipl=0; ipl<nPlanes; ++ipl){
278 for(
unsigned int irep=0; irep<nreps; ++irep){
281 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
282 bk->
getMatrix(
"fPredSt",planes.at(ipl)->at(0),fSt);
283 bk->
getMatrix(
"bPredSt",planes.at(ipl)->at(0),bSt);
284 bk->
getMatrix(
"fPredCov",planes.at(ipl)->at(0),fCov);
285 bk->
getMatrix(
"bPredCov",planes.at(ipl)->at(0),bCov);
286 fCovInv.ResizeTo(fCov);
287 bCovInv.ResizeTo(bCov);
290 smooCov.ResizeTo(fCov);
292 smooSt.ResizeTo(fSt.GetNrows(),1);
293 smooSt = smooCov * (fCovInv*fSt + bCovInv*bSt);
295 bk->
getMatrix(
"H",planes.at(ipl)->at(0),H);
296 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
298 bk->
getMatrix(
"m",planes.at(ipl)->at(ihit),m);
299 smooResid.ResizeTo(m.GetNrows(),1);
300 smooResid = m - H*smooSt;
303 bk->
setMatrix(
"smooResid",planes.at(ipl)->at(ihit),smooResid);
309 if(iBeta!=
fBeta.size()-1){
310 for(
unsigned int irep=0; irep<nreps; ++irep){
312 for(
int ipl=0; ipl<nPlanes; ++ipl){
314 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
317 std::vector<double> phi;
318 TMatrixT<Double_t> V;
319 bk->
getMatrix(
"V",planes.at(ipl)->at(0),V);
320 V *=
fBeta.at(iBeta);
321 TMatrixT<Double_t> Vinv;
323 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
325 bk->
getMatrix(
"smooResid",planes.at(ipl)->at(ihit),smooResid);
326 TMatrixT<Double_t> smooResidTransp(smooResid);
328 int dimV = V.GetNrows();
329 double detV = V.Determinant();
330 TMatrixT<Double_t> expArg = smooResidTransp*Vinv*smooResid;
331 if (expArg.GetNrows() != 1)
332 throw std::runtime_error(
"genf::GFDaf::processTrack(): wrong matrix dimensions!");
333 double thisPhi = 1./(pow(2.*TMath::Pi(),dimV/2.)*sqrt(detV))*exp(-0.5*expArg[0][0]);
334 phi.push_back(thisPhi);
339 throw std::runtime_error(
"genf::GFDaf::processTrack(): chi2 cut too low");
340 sumPhiCut += 1./(2*TMath::Pi()*sqrt(detV))*exp(-0.5*cutVal/
fBeta.at(iBeta));
342 for(
unsigned int ihit=0;ihit<planes.at(ipl)->size();++ihit){
343 bk->
setNumber(
"p",planes.at(ipl)->at(ihit), phi.at(ihit)/(sumPhi+sumPhiCut));
358 for(
int irep=0; irep<nreps; ++irep){
362 TMatrixT<Double_t> cov = arep->
getCov();
363 for(
int i=0;i<cov.GetNrows();++i){
364 for(
int j=0;j<cov.GetNcols();++j){
386 if(TMath::IsNaN(det)) {
387 GFException e(
"Daf Gain: det of matrix is nan",__LINE__,__FILE__);
401 const TMatrixT<Double_t>& V,
402 const TMatrixT<Double_t>& H,
406 TMatrixT<Double_t> Cinv;
408 TMatrixT<Double_t> Vinv;
411 TMatrixT<Double_t> Htransp(H);
414 TMatrixT<Double_t> covsum = Cinv + (p*Htransp*Vinv*H);
415 TMatrixT<Double_t> covsumInv;
418 return (covsumInv*Htransp*Vinv);
424 if(fabs(val-0.01)<1.
E-10){
431 else if(fabs(val-0.005)<1.
E-10){
438 else if(fabs(val-0.001)<1.
E-10){
446 throw GFException(
"genf::GFTrackCand::GFDafsetProbCut(): value not supported", __LINE__, __FILE__)
453 double b1,
double b2,
493 throw std::runtime_error(
"genf::GFDaf::setBetas(): b1 <= 0");
496 if (b2 <= 0 || b2 > b1)
497 throw std::runtime_error(
"genf::GFDaf::setBetas(): b2 in wrong range");
502 throw std::runtime_error(
"genf::GFDaf::setBetas(): b3 > b2");
507 throw std::runtime_error(
"genf::GFDaf::setBetas(): b4 > b3");
512 throw std::runtime_error(
"genf::GFDaf::setBetas(): b5 > b4");
517 throw std::runtime_error(
"genf::GFDaf::setBetas(): b6 > b5");
522 throw std::runtime_error(
"genf::GFDaf::setBetas(): b7 > b6");
527 throw std::runtime_error(
"genf::GFDaf::setBetas(): b8 > b7");
532 throw std::runtime_error(
"genf::GFDaf::setBetas(): b9 > b8");
537 throw std::runtime_error(
"genf::GFDaf::setBetas(): b10 > b9");
538 fBeta.push_back(b10);
void setDetPlane(std::string key, unsigned int index, const GFDetPlane &pl)
GFException & setNumbers(std::string, const std::vector< double > &)
set list of numbers with description
GFDaf()
Standard CTOR. Sets default values for annealing scheme and probablity cut.
const GFDetPlane & getReferencePlane() const
void invertMatrix(const TMatrixT< Double_t > &, TMatrixT< Double_t > &)
invert a matrix. First argument is matrix to be inverted, second is return by ref.
void setBetas(double b1, double b2, double b3=-1., double b4=-1., double b5=-1., double b6=-1., double b7=-1., double b8=-1., double b9=-1., double b10=-1.)
Configure the annealing scheme. In the current implementation you need to provide at least two temper...
virtual const char * what() const
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
GFAbsTrackRep * getTrackRep(int id) const
Accessor for track representations.
void setNumber(std::string key, unsigned int index, const double &num)
const TMatrixT< Double_t > & getState() const
void processTrack(GFTrack *)
Performs DAF fit on all track representations in a GFTrack.
Base Class for genfit track representations. Defines interface for track parameterizations.
void setCov(const TMatrixT< Double_t > &aCov)
void setMatrix(std::string key, unsigned int index, const TMatrixT< Double_t > &mat)
std::map< int, double > chi2Cuts
void bookGFDetPlanes(std::string key)
unsigned int getNumReps() const
Get number of track represenatations.
std::vector< double > fBeta
virtual void setData(const TMatrixT< Double_t > &st, const GFDetPlane &pl, const TMatrixT< Double_t > *cov=NULL)
void addFailedHit(unsigned int irep, unsigned int id)
bool isFatal()
get fatal flag.
GFAbsRecoHit * getHit(int id) const
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.
virtual double extrapolate(const GFDetPlane &plane, TMatrixT< Double_t > &statePred)
returns the tracklength spanned in this extrapolation
unsigned int hitFailed(unsigned int)
const TMatrixT< Double_t > & getCov() const
GFBookkeeping * getBK(int index=-1)
get GFBookKeeping object for particular track rep (default is cardinal rep)
void setProbCut(double val)
Set the probabilty cut for the weight calculation for the hits. Currently supported are the values 0...
void info()
print information in the exception object
bool getNumber(std::string key, unsigned int index, double &num) const
unsigned int getNumHits() const
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
void setStatusFlag(int _val)
void bookMatrices(std::string key)
bool getMatrix(std::string key, unsigned int index, TMatrixT< Double_t > &mat) const
void bookNumbers(std::string key, double val=0.)
GFException & setFatal(bool b=true)
set fatal flag. if this is true, the fit stops for this current track repr.
void getHitsByPlane(std::vector< std::vector< int > * > &retVal)
unsigned int getDim() const
returns dimension of state vector
void blowUpCovs(GFTrack *trk)
This is needed to blow up the covariance matrix before a fitting pass. The method drops off-diagonal ...
bool getDetPlane(std::string key, unsigned int index, GFDetPlane &pl) const