41 #define COVEXC "cov_is_zero" 60 for(
unsigned int i=0; i<nreps; ++i){
76 std::vector< std::vector<int>* > planes;
78 int nPlanes = planes.size();
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){
98 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
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);
115 if(cov[0][0]<1.
E-50){
121 std::cerr << exc.
what();
123 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->
addFailedHit(irep,planes.at(ipl)->at(i));
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);
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);
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){
196 if(bk->
hitFailed(planes.at(ipl)->at(0))>0)
continue;
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);
213 if(cov[0][0]<1.
E-50){
220 std::cerr << exc.
what();
223 for(
unsigned int i=0;i<planes.at(ipl)->size();++i) trk->
addFailedHit(irep,planes.at(ipl)->at(i));
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);
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){
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){
311 for(
int ipl=0; ipl<nPlanes; ++ipl){
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));
357 for(
int irep=0; irep<nreps; ++irep){
361 TMatrixT<Double_t> cov = arep->
getCov();
362 for(
int i=0;i<cov.GetNrows();++i){
363 for(
int j=0;j<cov.GetNcols();++j){
385 if(TMath::IsNaN(det)) {
386 GFException e(
"Daf Gain: det of matrix is nan",__LINE__,__FILE__);
400 const TMatrixT<Double_t>& V,
401 const TMatrixT<Double_t>& H,
405 TMatrixT<Double_t> Cinv;
407 TMatrixT<Double_t> Vinv;
410 TMatrixT<Double_t> Htransp(H);
413 TMatrixT<Double_t> covsum = Cinv + (p*Htransp*Vinv*H);
414 TMatrixT<Double_t> covsumInv;
417 return (covsumInv*Htransp*Vinv);
423 if(fabs(val-0.01)<1.
E-10){
430 else if(fabs(val-0.005)<1.
E-10){
437 else if(fabs(val-0.001)<1.
E-10){
445 throw GFException(
"genf::GFTrackCand::GFDafsetProbCut(): value not supported", __LINE__, __FILE__)
452 double b1,
double b2,
492 throw std::runtime_error(
"genf::GFDaf::setBetas(): b1 <= 0");
495 if (b2 <= 0 || b2 > b1)
496 throw std::runtime_error(
"genf::GFDaf::setBetas(): b2 in wrong range");
501 throw std::runtime_error(
"genf::GFDaf::setBetas(): b3 > b2");
506 throw std::runtime_error(
"genf::GFDaf::setBetas(): b4 > b3");
511 throw std::runtime_error(
"genf::GFDaf::setBetas(): b5 > b4");
516 throw std::runtime_error(
"genf::GFDaf::setBetas(): b6 > b5");
521 throw std::runtime_error(
"genf::GFDaf::setBetas(): b7 > b6");
526 throw std::runtime_error(
"genf::GFDaf::setBetas(): b8 > b7");
531 throw std::runtime_error(
"genf::GFDaf::setBetas(): b9 > b8");
536 throw std::runtime_error(
"genf::GFDaf::setBetas(): b10 > b9");
537 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