GENFIT Rev: NoNumberAvailable
Loading...
Searching...
No Matches
KalmanFitterInfo.cc
Go to the documentation of this file.
1/* Copyright 2008-2013, Technische Universitaet Muenchen, Ludwig-Maximilians-Universität München
2 Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
3
4 This file is part of GENFIT.
5
6 GENFIT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GENFIT is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "KalmanFitterInfo.h"
21
22#include <cassert>
23#include <TBuffer.h>
24
25#include "IO.h"
26#include "Exception.h"
27#include "FitStatus.h"
28#include "Tools.h"
29#include "Track.h"
30#include "TrackPoint.h"
31
32//#define DEBUG
33
34
35namespace genfit {
36
42
44 AbsFitterInfo(trackPoint, rep), fixWeights_(false)
45{
46 ;
47}
48
52
53
55 KalmanFitterInfo* retVal = new KalmanFitterInfo(this->getTrackPoint(), this->getRep());
60 if (hasForwardUpdate())
66
68 for (std::vector<MeasurementOnPlane*>::const_iterator it = this->measurementsOnPlane_.begin(); it != this->measurementsOnPlane_.end(); ++it) {
70 }
71
72 retVal->fixWeights_ = this->fixWeights_;
73
74 return retVal;
75}
76
77
79
81
82 if(measurementsOnPlane_.size() == 1) {
83 if (ignoreWeights) {
84 retVal.setWeight(1.);
85 }
86 else {
87 double weight = (measurementsOnPlane_[0])->getWeight();
88 if (weight != 1.) {
89 retVal.getCov() *= 1. / weight;
90 }
91 retVal.setWeight(weight);
92 }
93 return retVal;
94 }
95
96 // more than one hit
97
98 // cppcheck-suppress unreadVariable
99 double sumOfWeights(0), weight(0);
100
101 retVal.getState().Zero();
102 retVal.getCov().Zero();
103
104 TMatrixDSym covInv;
105
106 for(unsigned int i=0; i<measurementsOnPlane_.size(); ++i) {
107
108 if (i>0) {
109 // make sure we have compatible measurement types
110 // TODO: replace with Exceptions!
112 assert(*(measurementsOnPlane_[i]->getHMatrix()) == *(measurementsOnPlane_[0]->getHMatrix()));
113 }
114
115 tools::invertMatrix(measurementsOnPlane_[i]->getCov(), covInv); // invert cov
116 if (ignoreWeights) {
117 sumOfWeights += 1.;
118 }
119 else {
120 weight = measurementsOnPlane_[i]->getWeight();
121 sumOfWeights += weight;
122 covInv *= weight; // weigh cov
123 }
124 retVal.getCov() += covInv; // covInv is already inverted and weighted
125
126 retVal.getState() += covInv * measurementsOnPlane_[i]->getState();
127 }
128
129 // invert Cov
130 tools::invertMatrix(retVal.getCov());
131
132 retVal.getState() *= retVal.getCov();
133
134 retVal.setWeight(sumOfWeights);
135
136 return retVal;
137}
138
139
141 if(measurementsOnPlane_.size() == 0)
142 return nullptr;
143
144 if(measurementsOnPlane_.size() == 1)
145 return getMeasurementOnPlane(0);
146
147 double normMin(9.99E99);
148 unsigned int iMin(0);
149 const AbsHMatrix* H = measurementsOnPlane_[0]->getHMatrix();
150 for (unsigned int i=0; i<getNumMeasurements(); ++i) {
151 if (*(measurementsOnPlane_[i]->getHMatrix()) != *H){
152 Exception e("KalmanFitterInfo::getClosestMeasurementOnPlane: Cannot compare measurements with different H-Matrices. Maybe you have to select a different multipleMeasurementHandling.", __LINE__,__FILE__);
153 e.setFatal();
154 throw e;
155 }
156
157 TVectorD res = measurementsOnPlane_[i]->getState() - H->Hv(sop->getState());
158 double norm = sqrt(res.Norm2Sqr());
159 if (norm < normMin) {
160 normMin = norm;
161 iMin = i;
162 }
163 }
164
165 return getMeasurementOnPlane(iMin);
166}
167
168
169std::vector<double> KalmanFitterInfo::getWeights() const {
170 std::vector<double> retVal(getNumMeasurements());
171
172 for (unsigned int i=0; i<getNumMeasurements(); ++i) {
173 retVal[i] = getMeasurementOnPlane(i)->getWeight();
174 }
175
176 return retVal;
177}
178
179
181
182 // check if we can use cached states
183 if (biased && fittedStateBiased_)
184 return *fittedStateBiased_;
185 if (!biased && fittedStateUnbiased_)
186 return *fittedStateUnbiased_;
187
188
189 const TrackPoint* tp = this->getTrackPoint();
190 const Track* tr = tp->getTrack();
191 const AbsTrackRep* rep = this->getRep();
192
193 bool first(false), last(false);
194 PruneFlags& flag = tr->getFitStatus(rep)->getPruneFlags();
195 // if Track is pruned so that only one TrackPoint remains, see if it was the first or last one
196 #ifdef DEBUG
197 if (flag.isPruned()) {
198 debugOut << "KalmanFitterInfo::getFittedState - Track is pruned and has " << tr->getNumPoints() << " TrackPoints \n";
199 flag.Print();
200 }
201 #endif
202 if (flag.isPruned() && tr->getNumPoints() == 1) {
203 if (flag.hasFlags("F")) {
204 first = true;
205 #ifdef DEBUG
206 debugOut << "KalmanFitterInfo::getFittedState - has flag F \n";
207 #endif
208 }
209 else if (flag.hasFlags("L")) {
210 last = true;
211 #ifdef DEBUG
212 debugOut << "KalmanFitterInfo::getFittedState - has flag L \n";
213 #endif
214 }
215 }
216 else { // otherwise check against TrackPoint order
217 first = tr->getPointWithFitterInfo(0, rep) == tp;
218 last = tr->getPointWithFitterInfo(-1, rep) == tp;
219 }
220
221 #ifdef DEBUG
222 debugOut << "KalmanFitterInfo::getFittedState first " << first << ", last " << last << "\n";
223 debugOut << "KalmanFitterInfo::getFittedState forwardPrediction_ " << forwardPrediction_.get() << ", forwardUpdate_ " << forwardUpdate_.get() << "\n";
224 debugOut << "KalmanFitterInfo::getFittedState backwardPrediction_ " << backwardPrediction_.get() << ", backwardUpdate_ " << backwardUpdate_.get() << "\n";
225 #endif
226
227 /*
228 if both needed forward prediction/update and backward prediction are available,
229 use them to calculate smoothed state.
230 Otherwise, if one is missing (i.e. has been pruned) and we are at first or last hit,
231 use only backward or forward prediction (unbiased) of update (biased).
232 */
233
234 if (biased) {
235 // last measurement and no backward prediction -> use forward update
236 if (last && !backwardPrediction_) {
237 if(!forwardUpdate_) {
238 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
239 e.setFatal();
240 throw e;
241 }
242 #ifdef DEBUG
243 debugOut << "KalmanFitterInfo::getFittedState - biased at last measurement = forwardUpdate_ \n";
244 #endif
245 return *forwardUpdate_;
246 }
247
248 // first measurement and no forward update -> use backward update
249 if (first && (!forwardUpdate_ || (backwardUpdate_ && !forwardPrediction_) ) ) {
250 if(!backwardUpdate_.get()) {
251 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
252 e.setFatal();
253 throw e;
254 }
255 #ifdef DEBUG
256 debugOut << "KalmanFitterInfo::getFittedState - biased at first measurement = backwardUpdate_ \n";
257 //backwardUpdate_->Print();
258 #endif
259 return *backwardUpdate_;
260 }
261
263 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
264 e.setFatal();
265 throw e;
266 }
267 #ifdef DEBUG
268 debugOut << "KalmanFitterInfo::getFittedState - biased = mean(forwardUpdate_, backwardPrediction_) \n";
269 #endif
271 return *fittedStateBiased_;
272 }
273
274 // unbiased
275
276 // last measurement and no backward prediction -> use forward prediction
277 if (last && !backwardPrediction_) {
278 if(!forwardPrediction_) {
279 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
280 e.setFatal();
281 throw e;
282 }
283 #ifdef DEBUG
284 debugOut << "KalmanFitterInfo::getFittedState - unbiased at last measurement = forwardPrediction_ \n";
285 #endif
286 return *forwardPrediction_;
287 }
288
289 // first measurement and no forward prediction -> use backward prediction
290 if (first && !forwardPrediction_) {
292 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
293 e.setFatal();
294 throw e;
295 }
296 #ifdef DEBUG
297 debugOut << "KalmanFitterInfo::getFittedState - unbiased at first measurement = backwardPrediction_ \n";
298 #endif
299 return *backwardPrediction_;
300 }
301
303 Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
304 e.setFatal();
305 throw e;
306 }
307 #ifdef DEBUG
308 debugOut << "KalmanFitterInfo::getFittedState - unbiased = mean(forwardPrediction_, backwardPrediction_) \n";
309 #endif
311 return *fittedStateUnbiased_;
312}
313
314
315MeasurementOnPlane KalmanFitterInfo::getResidual(unsigned int iMeasurement, bool biased, bool onlyMeasurementErrors) const {
316
317 const MeasuredStateOnPlane& smoothedState = getFittedState(biased);
318 const MeasurementOnPlane* measurement = measurementsOnPlane_.at(iMeasurement);
319 const SharedPlanePtr& plane = measurement->getPlane();
320
321 // check equality of planes and reps
322 if(*(smoothedState.getPlane()) != *plane) {
323 Exception e("KalmanFitterInfo::getResidual: smoothedState and measurement are not defined in the same plane.", __LINE__,__FILE__);
324 throw e;
325 }
326 if(smoothedState.getRep() != measurement->getRep()) {
327 Exception e("KalmanFitterInfo::getResidual: smoothedState and measurement are not defined wrt the same TrackRep.", __LINE__,__FILE__);
328 throw e;
329 }
330
331 const AbsHMatrix* H = measurement->getHMatrix();
332
333 //TODO: shouldn't the definition be (smoothed - measured) ?
334 // res = -(H*smoothedState - measuredState)
335 TVectorD res(H->Hv(smoothedState.getState()));
336 res -= measurement->getState();
337 res *= -1;
338
339 if (onlyMeasurementErrors) {
340 return MeasurementOnPlane(res, measurement->getCov(), plane, smoothedState.getRep(), H->clone(), measurement->getWeight());
341 }
342
343 TMatrixDSym cov(smoothedState.getCov());
344 H->HMHt(cov);
345 cov += measurement->getCov();
346
347 return MeasurementOnPlane(res, cov, plane, smoothedState.getRep(), H->clone(), measurement->getWeight());
348}
349
350
351double KalmanFitterInfo::getSmoothedChi2(unsigned int iMeasurement) const {
352 const MeasurementOnPlane& res = getResidual(iMeasurement, true, false);
353
354 TMatrixDSym Rinv;
355 tools::invertMatrix(res.getCov(), Rinv);
356 return Rinv.Similarity(res.getState());
357}
358
359
361 referenceState_.reset(referenceState);
362 if (referenceState_)
363 setPlane(referenceState_->getPlane());
364
365 // if plane has changed, delete outdated info
366 /*if (forwardPrediction_ && forwardPrediction_->getPlane() != getPlane())
367 setForwardPrediction(0);
368
369 if (forwardUpdate_ && forwardUpdate_->getPlane() != getPlane())
370 setForwardUpdate(0);
371
372 if (backwardPrediction_ && backwardPrediction_->getPlane() != getPlane())
373 setBackwardPrediction(0);
374
375 if (backwardUpdate_ && backwardUpdate_->getPlane() != getPlane())
376 setBackwardUpdate(0);
377
378 if (measurementsOnPlane_.size() > 0 && measurementsOnPlane_[0]->getPlane() != getPlane())
379 deleteMeasurementInfo();
380 */
381}
382
383
385 forwardPrediction_.reset(forwardPrediction);
386 fittedStateUnbiased_.reset();
387 fittedStateBiased_.reset();
389 setPlane(forwardPrediction_->getPlane());
390}
391
393 backwardPrediction_.reset(backwardPrediction);
394 fittedStateUnbiased_.reset();
395 fittedStateBiased_.reset();
397 setPlane(backwardPrediction_->getPlane());
398}
399
401 forwardUpdate_.reset(forwardUpdate);
402 fittedStateUnbiased_.reset();
403 fittedStateBiased_.reset();
404 if (forwardUpdate_)
405 setPlane(forwardUpdate_->getPlane());
406}
407
409 backwardUpdate_.reset(backwardUpdate);
410 fittedStateUnbiased_.reset();
411 fittedStateBiased_.reset();
412 if (backwardUpdate_)
413 setPlane(backwardUpdate_->getPlane());
414}
415
416
417void KalmanFitterInfo::setMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane) {
419
420 for (std::vector<MeasurementOnPlane*>::const_iterator m = measurementsOnPlane.begin(), mend = measurementsOnPlane.end(); m < mend; ++m) {
422 }
423}
424
425
427 if (measurementsOnPlane_.size() == 0)
428 setPlane(measurementOnPlane->getPlane());
429
430 measurementsOnPlane_.push_back(measurementOnPlane);
431}
432
433void KalmanFitterInfo::addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane) {
434 for (std::vector<MeasurementOnPlane*>::const_iterator m = measurementsOnPlane.begin(), mend = measurementsOnPlane.end(); m < mend; ++m) {
436 }
437}
438
439
441 rep_ = rep;
442
443 if (referenceState_)
444 referenceState_->setRep(rep);
445
447 forwardPrediction_->setRep(rep);
448
449 if (forwardUpdate_)
450 forwardUpdate_->setRep(rep);
451
453 backwardPrediction_->setRep(rep);
454
455 if (backwardUpdate_)
456 backwardUpdate_->setRep(rep);
457
458 for (std::vector<MeasurementOnPlane*>::iterator it = measurementsOnPlane_.begin(); it != measurementsOnPlane_.end(); ++it) {
459 (*it)->setRep(rep);
460 }
461}
462
463
464void KalmanFitterInfo::setWeights(const std::vector<double>& weights) {
465
466 if (weights.size() != getNumMeasurements()) {
467 Exception e("KalmanFitterInfo::setWeights: weights do not have the same size as measurementsOnPlane", __LINE__,__FILE__);
468 throw e;
469 }
470
471 if (fixWeights_) {
472 errorOut << "KalmanFitterInfo::setWeights - WARNING: setting weights even though weights are fixed!" << std::endl;
473 }
474
475 for (unsigned int i=0; i<getNumMeasurements(); ++i) {
476 getMeasurementOnPlane(i)->setWeight(weights[i]);
477 }
478}
479
480
487
494
501
503 // FIXME: need smart pointers / smart containers here
504 for (size_t i = 0; i < measurementsOnPlane_.size(); ++i)
505 delete measurementsOnPlane_[i];
506
507 measurementsOnPlane_.clear();
508}
509
510
511void KalmanFitterInfo::Print(const Option_t*) const {
512 printOut << "genfit::KalmanFitterInfo. Belongs to TrackPoint " << trackPoint_ << "; TrackRep " << rep_ << "\n";
513
514 if (fixWeights_)
515 printOut << "Weights are fixed.\n";
516
517 for (unsigned int i=0; i<measurementsOnPlane_.size(); ++i) {
518 printOut << "MeasurementOnPlane Nr " << i <<": "; measurementsOnPlane_[i]->Print();
519 }
520
521 if (referenceState_) {
522 printOut << "Reference state: "; referenceState_->Print();
523 }
524 if (forwardPrediction_) {
525 printOut << "Forward prediction_: "; forwardPrediction_->Print();
526 }
527 if (forwardUpdate_) {
528 printOut << "Forward update: "; forwardUpdate_->Print();
529 }
531 printOut << "Backward prediction_: "; backwardPrediction_->Print();
532 }
533 if (backwardUpdate_) {
534 printOut << "Backward update: "; backwardUpdate_->Print();
535 }
536
537}
538
539
541
542 bool retVal(true);
543
544 // check if in a TrackPoint
545 if (!trackPoint_) {
546 errorOut << "KalmanFitterInfo::checkConsistency(): trackPoint_ is nullptr" << std::endl;
547 retVal = false;
548 }
549
550 // check if there is a reference state
551 /*if (!referenceState_) {
552 errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is nullptr" << std::endl;
553 retVal = false;
554 }*/
555
556 SharedPlanePtr plane = getPlane();
557
558 if (plane.get() == nullptr) {
560 return true;
561 errorOut << "KalmanFitterInfo::checkConsistency(): plane is nullptr" << std::endl;
562 retVal = false;
563 }
564
565 // cppcheck-suppress unreadVariable
566 TVector3 oTest = plane->getO(); // see if the plane object is there
567 // cppcheck-suppress unreadVariable
568 oTest *= 47.11;
569
570 // if more than one measurement, check if they have the same dimensionality
571 if (measurementsOnPlane_.size() > 1) {
572 int dim = measurementsOnPlane_[0]->getState().GetNrows();
573 for (unsigned int i = 1; i<measurementsOnPlane_.size(); ++i) {
574 if(measurementsOnPlane_[i]->getState().GetNrows() != dim) {
575 errorOut << "KalmanFitterInfo::checkConsistency(): measurementsOnPlane_ do not all have the same dimensionality" << std::endl;
576 retVal = false;
577 }
578 }
579 if (dim == 0) {
580 errorOut << "KalmanFitterInfo::checkConsistency(): measurementsOnPlane_ have dimension 0" << std::endl;
581 retVal = false;
582 }
583 }
584
585 // see if everything else is defined wrt this plane and rep_
586 int dim = rep_->getDim(); // check dim
587 if (referenceState_) {
588 if(referenceState_->getPlane() != plane) {
589 errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is not defined with the correct plane " << referenceState_->getPlane().get() << " vs. " << plane.get() << std::endl;
590 retVal = false;
591 }
592 if (referenceState_->getRep() != rep_) {
593 errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is not defined with the correct TrackRep" << std::endl;
594 retVal = false;
595 }
596 if (referenceState_->getState().GetNrows() != dim) {
597 errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ does not have the right dimension!" << std::endl;
598 retVal = false;
599 }
600 }
601
602 if (forwardPrediction_) {
603 if(forwardPrediction_->getPlane() != plane) {
604 errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ is not defined with the correct plane" << std::endl;
605 retVal = false;
606 }
607 if(forwardPrediction_->getRep() != rep_) {
608 errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ is not defined with the correct TrackRep" << std::endl;
609 retVal = false;
610 }
611 if (forwardPrediction_->getState().GetNrows() != dim || forwardPrediction_->getCov().GetNrows() != dim) {
612 errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ does not have the right dimension!" << std::endl;
613 retVal = false;
614 }
615 }
616 if (forwardUpdate_) {
617 if(forwardUpdate_->getPlane() != plane) {
618 errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ is not defined with the correct plane" << std::endl;
619 retVal = false;
620 }
621 if(forwardUpdate_->getRep() != rep_) {
622 errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ is not defined with the correct TrackRep" << std::endl;
623 retVal = false;
624 }
625 if (forwardUpdate_->getState().GetNrows() != dim || forwardUpdate_->getCov().GetNrows() != dim) {
626 errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ does not have the right dimension!" << std::endl;
627 retVal = false;
628 }
629 }
630
632 if(backwardPrediction_->getPlane() != plane) {
633 errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ is not defined with the correct plane" << std::endl;
634 retVal = false;
635 }
636 if(backwardPrediction_->getRep() != rep_) {
637 errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ is not defined with the correct TrackRep" << std::endl;
638 retVal = false;
639 }
640 if (backwardPrediction_->getState().GetNrows() != dim || backwardPrediction_->getCov().GetNrows() != dim) {
641 errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ does not have the right dimension!" << std::endl;
642 retVal = false;
643 }
644 }
645 if (backwardUpdate_) {
646 if(backwardUpdate_->getPlane() != plane) {
647 errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ is not defined with the correct plane" << std::endl;
648 retVal = false;
649 }
650 if(backwardUpdate_->getRep() != rep_) {
651 errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ is not defined with the correct TrackRep" << std::endl;
652 retVal = false;
653 }
654 if (backwardUpdate_->getState().GetNrows() != dim || backwardUpdate_->getCov().GetNrows() != dim) {
655 errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ does not have the right dimension!" << std::endl;
656 retVal = false;
657 }
658 }
659
660 for (std::vector<MeasurementOnPlane*>::const_iterator it = measurementsOnPlane_.begin(); it != measurementsOnPlane_.end(); ++it) {
661 if((*it)->getPlane() != plane) {
662 errorOut << "KalmanFitterInfo::checkConsistency(): measurement is not defined with the correct plane" << std::endl;
663 retVal = false;
664 }
665 if((*it)->getRep() != rep_) {
666 errorOut << "KalmanFitterInfo::checkConsistency(): measurement is not defined with the correct TrackRep" << std::endl;
667 retVal = false;
668 }
669 if ((*it)->getState().GetNrows() == 0) {
670 errorOut << "KalmanFitterInfo::checkConsistency(): measurement has dimension 0!" << std::endl;
671 retVal = false;
672 }
673 }
674
675 if (flags == nullptr or !flags->hasFlags("U")) { // if predictions have not been pruned
676 // see if there is an update w/o prediction or measurement
678 errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ w/o forwardPrediction_" << std::endl;
679 retVal = false;
680 }
681
682
684 errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ w/o backwardPrediction_" << std::endl;
685 retVal = false;
686 }
687
688 if (flags == nullptr or !flags->hasFlags("M")) {
689 if (forwardUpdate_ && measurementsOnPlane_.size() == 0) {
690 errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ w/o measurement" << std::endl;
691 retVal = false;
692 }
693
694 if (backwardUpdate_ && measurementsOnPlane_.size() == 0) {
695 errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ w/o measurement" << std::endl;
696 retVal = false;
697 }
698 }
699 }
700
701
702 return retVal;
703}
704
705
706// Modified from auto-generated Streamer to correctly deal with smart pointers.
707void KalmanFitterInfo::Streamer(TBuffer &R__b)
708{
709 // Stream an object of class genfit::KalmanFitterInfo.
710
711 //This works around a msvc bug and should be harmless on other platforms
712 typedef ::genfit::KalmanFitterInfo thisClass;
713 UInt_t R__s, R__c;
714 if (R__b.IsReading()) {
715 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
716 //This works around a msvc bug and should be harmless on other platforms
717 typedef genfit::AbsFitterInfo baseClass0;
718 baseClass0::Streamer(R__b);
719 int flag;
720 R__b >> flag;
725 if (flag & 1) {
726 referenceState_.reset(new ReferenceStateOnPlane());
727 referenceState_->Streamer(R__b);
728 referenceState_->setPlane(getPlane());
729 // rep needs to be fixed up
730 }
731 if (flag & (1 << 1)) {
732 forwardPrediction_.reset(new MeasuredStateOnPlane());
733 forwardPrediction_->Streamer(R__b);
734 forwardPrediction_->setPlane(getPlane());
735 // rep needs to be fixed up
736 }
737 if (flag & (1 << 2)) {
738 forwardUpdate_.reset(new KalmanFittedStateOnPlane());
739 forwardUpdate_->Streamer(R__b);
740 forwardUpdate_->setPlane(getPlane());
741 // rep needs to be fixed up
742 }
743 if (flag & (1 << 3)) {
744 backwardPrediction_.reset(new MeasuredStateOnPlane());
745 backwardPrediction_->Streamer(R__b);
746 backwardPrediction_->setPlane(getPlane());
747 // rep needs to be fixed up
748 }
749 if (flag & (1 << 4)) {
750 backwardUpdate_.reset(new KalmanFittedStateOnPlane());
751 backwardUpdate_->Streamer(R__b);
752 backwardUpdate_->setPlane(getPlane());
753 // rep needs to be fixed up
754 }
755 {
756 std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> > &R__stl = measurementsOnPlane_;
757 TClass *R__tcl1 = TBuffer::GetClass(typeid(genfit::MeasurementOnPlane));
758 if (R__tcl1==0) {
759 Error("measurementsOnPlane_ streamer","Missing the TClass object for genfit::MeasurementOnPlane!");
760 return;
761 }
762 int R__i, R__n;
763 R__b >> R__n;
764 R__stl.reserve(R__n);
765 for (R__i = 0; R__i < R__n; R__i++) {
766 genfit::MeasurementOnPlane* R__t = new MeasurementOnPlane();
767 R__t->Streamer(R__b);
768 R__t->setPlane(getPlane());
769 R__stl.push_back(R__t);
770 }
771 }
772 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
773 } else {
774 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
775 //This works around a msvc bug and should be harmless on other platforms
776 typedef genfit::AbsFitterInfo baseClass0;
777 baseClass0::Streamer(R__b);
778 // "!!" forces the value to 1 or 0 (pointer != 0 or pointer == 0),
779 // this value is then written as a bitfield.
780 int flag = ((!!referenceState_)
781 | (!!forwardPrediction_ << 1)
782 | (!!forwardUpdate_ << 2)
783 | (!!backwardPrediction_ << 3)
784 | (!!backwardUpdate_ << 4));
785 R__b << flag;
786 if (flag & 1)
787 referenceState_->Streamer(R__b);
788 if (flag & (1 << 1))
789 forwardPrediction_->Streamer(R__b);
790 if (flag & (1 << 2))
791 forwardUpdate_->Streamer(R__b);
792 if (flag & (1 << 3))
793 backwardPrediction_->Streamer(R__b);
794 if (flag & (1 << 4))
795 backwardUpdate_->Streamer(R__b);
796 {
797 std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> > &R__stl = measurementsOnPlane_;
798 int R__n=int(R__stl.size());
799 R__b << R__n;
800 if(R__n) {
801 std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> >::iterator R__k;
802 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
803 (*R__k)->Streamer(R__b);
804 }
805 }
806 }
807 R__b.SetByteCount(R__c, kTRUE);
808 }
809}
810
811
812} /* End of namespace genfit */
This class collects all information needed and produced by a specific AbsFitter and is specific to on...
const AbsTrackRep * getRep() const
const TrackPoint * trackPoint_
const SharedPlanePtr & getPlane() const
const AbsTrackRep * rep_
No ownership.
void setPlane(const SharedPlanePtr &plane)
const TrackPoint * getTrackPoint() const
HMatrix for projecting from AbsTrackRep parameters to measured parameters in a DetPlane.
Definition AbsHMatrix.h:37
virtual TVectorD Hv(const TVectorD &v) const
H*v.
Definition AbsHMatrix.h:49
virtual void HMHt(TMatrixDSym &M) const
similarity: H*M*H^t
Definition AbsHMatrix.h:56
virtual AbsHMatrix * clone() const =0
Abstract base class for a track representation.
Definition AbsTrackRep.h:66
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition Exception.h:48
void setFatal(bool b=true)
Set fatal flag.
Definition Exception.h:61
PruneFlags & getPruneFlags()
Definition FitStatus.h:137
MeasuredStateOnPlane with additional info produced by a Kalman filter or DAF.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
bool hasBackwardUpdate() const override
void setBackwardUpdate(KalmanFittedStateOnPlane *backwardUpdate)
void setRep(const AbsTrackRep *rep) override
std::vector< MeasurementOnPlane * > measurementsOnPlane_
cache
virtual bool checkConsistency(const genfit::PruneFlags *=nullptr) const override
ReferenceStateOnPlane * getReferenceState() const
bool hasForwardPrediction() const override
void setWeights(const std::vector< double > &)
Set weights of measurements.
void addMeasurementOnPlane(MeasurementOnPlane *measurementOnPlane)
void setMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane * > &measurementsOnPlane)
const MeasuredStateOnPlane & getFittedState(bool biased=true) const override
Get unbiased or biased (default) smoothed state.
std::unique_ptr< ReferenceStateOnPlane > referenceState_
Reference state. Used by KalmanFitterRefTrack.
void setBackwardPrediction(MeasuredStateOnPlane *backwardPrediction)
bool hasBackwardPrediction() const override
void setForwardUpdate(KalmanFittedStateOnPlane *forwardUpdate)
MeasurementOnPlane getAvgWeightedMeasurementOnPlane(bool ignoreWeights=false) const
void addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane * > &measurementsOnPlane)
void setReferenceState(ReferenceStateOnPlane *referenceState)
std::vector< double > getWeights() const
Get weights of measurements.
void deleteBackwardInfo() override
void deleteMeasurementInfo() override
unsigned int getNumMeasurements() const
MeasurementOnPlane getResidual(unsigned int iMeasurement=0, bool biased=false, bool onlyMeasurementErrors=true) const override
Get unbiased (default) or biased residual from ith measurement.
MeasuredStateOnPlane * getForwardPrediction() const
virtual KalmanFitterInfo * clone() const override
Deep copy ctor for polymorphic class.
KalmanFittedStateOnPlane * getBackwardUpdate() const
std::unique_ptr< MeasuredStateOnPlane > fittedStateBiased_
cache
MeasurementOnPlane * getClosestMeasurementOnPlane(const StateOnPlane *) const
Get measurements which is closest to state.
MeasuredStateOnPlane * getBackwardPrediction() const
std::unique_ptr< MeasuredStateOnPlane > forwardPrediction_
virtual void Print(const Option_t *="") const override
bool hasReferenceState() const override
std::unique_ptr< MeasuredStateOnPlane > fittedStateUnbiased_
std::unique_ptr< KalmanFittedStateOnPlane > backwardUpdate_
bool hasForwardUpdate() const override
void deleteReferenceInfo() override
MeasurementOnPlane * getMeasurementOnPlane(int i=0) const
double getSmoothedChi2(unsigned int iMeasurement=0) const
void setForwardPrediction(MeasuredStateOnPlane *forwardPrediction)
KalmanFittedStateOnPlane * getForwardUpdate() const
void deleteForwardInfo() override
std::unique_ptr< KalmanFittedStateOnPlane > forwardUpdate_
std::unique_ptr< MeasuredStateOnPlane > backwardPrediction_
StateOnPlane with additional covariance matrix.
const TMatrixDSym & getCov() const
Measured coordinates on a plane.
void setWeight(double weight)
const AbsHMatrix * getHMatrix() const
StateOnPlane with linearized transport to that ReferenceStateOnPlane from previous and next Reference...
A state with arbitrary dimension defined in a DetPlane.
void setPlane(const SharedPlanePtr &plane)
const TVectorD & getState() const
const AbsTrackRep * getRep() const
const SharedPlanePtr & getPlane() const
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition Track.h:71
FitStatus * getFitStatus(const AbsTrackRep *rep=nullptr) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition Track.h:154
unsigned int getNumPoints() const
Definition Track.h:110
TrackPoint * getPointWithFitterInfo(int id, const AbsTrackRep *rep=nullptr) const
Definition Track.cc:255
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition TrackPoint.h:46
Track * getTrack() const
Definition TrackPoint.h:86
void invertMatrix(const TMatrixDSym &mat, TMatrixDSym &inv, double *determinant=nullptr)
Invert a matrix, throwing an Exception when inversion fails. Optional calculation of determinant.
Definition Tools.cc:38
Defines for I/O streams used for error and debug printing.
MeasuredStateOnPlane calcAverageState(const MeasuredStateOnPlane &forwardState, const MeasuredStateOnPlane &backwardState)
Calculate weighted average between two MeasuredStateOnPlanes.
std::ostream printOut
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
std::ostream debugOut
std::ostream errorOut
Info which information has been pruned from the Track.
Definition FitStatus.h:47
bool hasFlags(Option_t *option="CFLWRMIU") const
check if all the given flags are set
Definition FitStatus.cc:53
bool isPruned() const
check if any of the flags is set
Definition FitStatus.cc:68
void Print(const Option_t *="") const
Definition FitStatus.cc:73