40 #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;
101 int repDim = rep->
getDim();
102 TMatrixT<Double_t> state(repDim, 1);
103 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)
139 TMatrixT<Double_t> H = hits.at(0)->getHMatrix(rep);
140 bk->
setMatrix(
"fPredSt", planes.at(ipl)->at(0), state);
141 bk->
setMatrix(
"fPredCov", planes.at(ipl)->at(0), cov);
143 TMatrixT<Double_t> covInv;
146 TMatrixT<Double_t> Htransp(H);
149 bk->
setMatrix(
"H", planes.at(ipl)->at(0), H);
152 TMatrixT<Double_t> stMod(state.GetNrows(), 1);
155 for (
unsigned int ihit = 0; ihit < nhitsInPlane; ++ihit) {
157 bk->
getNumber(
"p", planes.at(ipl)->at(ihit), pki);
160 TMatrixT<Double_t> V = hits.at(0)->getHitCov(pl);
161 TMatrixT<Double_t> Vinv;
163 bk->
setMatrix(
"V", planes.at(ipl)->at(0), V);
164 for (
unsigned int ihit = 0; ihit < nhitsInPlane; ++ihit) {
167 TMatrixT<Double_t> m = hits.at(ihit)->getHitCoord(pl);
168 bk->
setMatrix(
"m", planes.at(ipl)->at(ihit), m);
171 bk->
getNumber(
"p", planes.at(ipl)->at(ihit), pki);
172 TMatrixT<Double_t> Gain =
calcGain(cov, V, H, sumPk);
174 stMod += pki * Gain * (m - H * state);
184 for (
int ipl = nPlanes - 1; ipl >= 0; --ipl) {
186 std::vector<GFAbsRecoHit*>
hits;
187 unsigned int nhitsInPlane = planes.at(ipl)->size();
188 for (
unsigned int ihitInPl = 0; ihitInPl < nhitsInPlane; ++ihitInPl) {
189 hits.push_back(trk->
getHit(planes.at(ipl)->at(ihitInPl)));
193 for (
unsigned int irep = 0; irep < nreps; ++irep) {
198 if (bk->
hitFailed(planes.at(ipl)->at(0)) > 0)
continue;
200 int repDim = rep->
getDim();
201 TMatrixT<Double_t> state(repDim, 1);
202 TMatrixT<Double_t> cov(repDim, repDim);
205 TMatrixT<Double_t> H;
206 bk->
getMatrix(
"H", planes.at(ipl)->at(0), H);
207 TMatrixT<Double_t> Htransp(H);
212 if (ipl < (nPlanes - 1)) {
216 if (cov[0][0] < 1.
E-50) {
223 std::cerr << exc.
what();
226 for (
unsigned int i = 0; i < planes.at(ipl)->size(); ++i)
236 TMatrixT<Double_t> covInv;
239 bk->
setMatrix(
"bPredSt", planes.at(ipl)->at(0), state);
240 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;
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;
315 double sumPhiCut = 0.;
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!");
333 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));
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) {
383 if (TMath::IsNaN(det)) {
384 GFException e(
"Daf Gain: det of matrix is nan", __LINE__, __FILE__);
389 GFException e(
"cannot invert matrix in Daf - det=0", __LINE__, __FILE__);
396 const TMatrixT<Double_t>& V,
397 const TMatrixT<Double_t>& H,
402 TMatrixT<Double_t> Cinv;
404 TMatrixT<Double_t> Vinv;
407 TMatrixT<Double_t> Htransp(H);
410 TMatrixT<Double_t> covsum = Cinv + (p * Htransp * Vinv * H);
411 TMatrixT<Double_t> covsumInv;
414 return (covsumInv * Htransp * Vinv);
420 if (fabs(val - 0.01) < 1.
E-10) {
427 else if (fabs(val - 0.005) < 1.
E-10) {
434 else if (fabs(val - 0.001) < 1.
E-10) {
443 "genf::GFTrackCand::GFDafsetProbCut(): value not supported", __LINE__, __FILE__)
490 if (b1 <= 0)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b1 <= 0");
493 if (b2 <= 0 || b2 > b1)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b2 in wrong range");
497 if (b3 > b2)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b3 > b2");
501 if (b4 > b3)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b4 > b3");
505 if (b5 > b4)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b5 > b4");
509 if (b6 > b5)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b6 > b5");
513 if (b7 > b6)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b7 > b6");
517 if (b8 > b7)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b8 > b7");
521 if (b9 > b8)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b9 > b8");
524 if (b10 < 0.)
return;
525 if (b10 > b9)
throw std::runtime_error(
"genf::GFDaf::setBetas(): b10 > b9");
526 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...
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)
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)
std::map< int, double > chi2Cuts
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
const char * what() const noexcept override
standard error message handling for exceptions. use like "std::cerr << e.what();" ...
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