EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KalmanFitterInfo.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KalmanFitterInfo.cc
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 
35 namespace genfit {
36 
38  AbsFitterInfo(), fixWeights_(false)
39 {
40  ;
41 }
42 
44  AbsFitterInfo(trackPoint, rep), fixWeights_(false)
45 {
46  ;
47 }
48 
51 }
52 
53 
55  KalmanFitterInfo* retVal = new KalmanFitterInfo(this->getTrackPoint(), this->getRep());
56  if (hasReferenceState())
60  if (hasForwardUpdate())
64  if (hasBackwardUpdate())
66 
67  retVal->measurementsOnPlane_.reserve(getNumMeasurements());
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  double sumOfWeights(0), weight(0);
99 
100  retVal.getState().Zero();
101  retVal.getCov().Zero();
102 
103  TMatrixDSym covInv;
104 
105  for(unsigned int i=0; i<measurementsOnPlane_.size(); ++i) {
106 
107  if (i>0) {
108  // make sure we have compatible measurement types
109  // TODO: replace with Exceptions!
111  assert(*(measurementsOnPlane_[i]->getHMatrix()) == *(measurementsOnPlane_[0]->getHMatrix()));
112  }
113 
114  tools::invertMatrix(measurementsOnPlane_[i]->getCov(), covInv); // invert cov
115  if (ignoreWeights) {
116  sumOfWeights += 1.;
117  }
118  else {
119  weight = measurementsOnPlane_[i]->getWeight();
120  sumOfWeights += weight;
121  covInv *= weight; // weigh cov
122  }
123  retVal.getCov() += covInv; // covInv is already inverted and weighted
124 
125  retVal.getState() += covInv * measurementsOnPlane_[i]->getState();
126  }
127 
128  // invert Cov
129  tools::invertMatrix(retVal.getCov());
130 
131  retVal.getState() *= retVal.getCov();
132 
133  retVal.setWeight(sumOfWeights);
134 
135  return retVal;
136 }
137 
138 
140  if(measurementsOnPlane_.size() == 0)
141  return nullptr;
142 
143  if(measurementsOnPlane_.size() == 1)
144  return getMeasurementOnPlane(0);
145 
146  double normMin(9.99E99);
147  unsigned int iMin(0);
148  const AbsHMatrix* H = measurementsOnPlane_[0]->getHMatrix();
149  for (unsigned int i=0; i<getNumMeasurements(); ++i) {
150  if (*(measurementsOnPlane_[i]->getHMatrix()) != *H){
151  Exception e("KalmanFitterInfo::getClosestMeasurementOnPlane: Cannot compare measurements with different H-Matrices. Maybe you have to select a different multipleMeasurementHandling.", __LINE__,__FILE__);
152  e.setFatal();
153  throw e;
154  }
155 
156  TVectorD res = measurementsOnPlane_[i]->getState() - H->Hv(sop->getState());
157  double norm = sqrt(res.Norm2Sqr());
158  if (norm < normMin) {
159  normMin = norm;
160  iMin = i;
161  }
162  }
163 
164  return getMeasurementOnPlane(iMin);
165 }
166 
167 
168 std::vector<double> KalmanFitterInfo::getWeights() const {
169  std::vector<double> retVal(getNumMeasurements());
170 
171  for (unsigned int i=0; i<getNumMeasurements(); ++i) {
172  retVal[i] = getMeasurementOnPlane(i)->getWeight();
173  }
174 
175  return retVal;
176 }
177 
178 
180 
181  // check if we can use cached states
182  if (biased && fittedStateBiased_)
183  return *fittedStateBiased_;
184  if (!biased && fittedStateUnbiased_)
185  return *fittedStateUnbiased_;
186 
187 
188  const TrackPoint* tp = this->getTrackPoint();
189  const Track* tr = tp->getTrack();
190  const AbsTrackRep* rep = this->getRep();
191 
192  bool first(false), last(false);
193  PruneFlags& flag = tr->getFitStatus(rep)->getPruneFlags();
194  // if Track is pruned so that only one TrackPoint remains, see if it was the first or last one
195  #ifdef DEBUG
196  if (flag.isPruned()) {
197  debugOut << "KalmanFitterInfo::getFittedState - Track is pruned and has " << tr->getNumPoints() << " TrackPoints \n";
198  flag.Print();
199  }
200  #endif
201  if (flag.isPruned() && tr->getNumPoints() == 1) {
202  if (flag.hasFlags("F")) {
203  first = true;
204  #ifdef DEBUG
205  debugOut << "KalmanFitterInfo::getFittedState - has flag F \n";
206  #endif
207  }
208  else if (flag.hasFlags("L")) {
209  last = true;
210  #ifdef DEBUG
211  debugOut << "KalmanFitterInfo::getFittedState - has flag L \n";
212  #endif
213  }
214  }
215  else { // otherwise check against TrackPoint order
216  first = tr->getPointWithFitterInfo(0, rep) == tp;
217  last = tr->getPointWithFitterInfo(-1, rep) == tp;
218  }
219 
220  #ifdef DEBUG
221  debugOut << "KalmanFitterInfo::getFittedState first " << first << ", last " << last << "\n";
222  debugOut << "KalmanFitterInfo::getFittedState forwardPrediction_ " << forwardPrediction_.get() << ", forwardUpdate_ " << forwardUpdate_.get() << "\n";
223  debugOut << "KalmanFitterInfo::getFittedState backwardPrediction_ " << backwardPrediction_.get() << ", backwardUpdate_ " << backwardUpdate_.get() << "\n";
224  #endif
225 
226  /*
227  if both needed forward prediction/update and backward prediction are available,
228  use them to calculate smoothed state.
229  Otherwise, if one is missing (i.e. has been pruned) and we are at first or last hit,
230  use only backward or forward prediction (unbiased) of update (biased).
231  */
232 
233  if (biased) {
234  // last measurement and no backward prediction -> use forward update
235  if (last && !backwardPrediction_) {
236  if(!forwardUpdate_) {
237  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
238  e.setFatal();
239  throw e;
240  }
241  #ifdef DEBUG
242  debugOut << "KalmanFitterInfo::getFittedState - biased at last measurement = forwardUpdate_ \n";
243  #endif
244  return *forwardUpdate_;
245  }
246 
247  // first measurement and no forward update -> use backward update
248  if (first && (!forwardUpdate_ || (backwardUpdate_ && !forwardPrediction_) ) ) {
249  if(!backwardUpdate_.get()) {
250  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
251  e.setFatal();
252  throw e;
253  }
254  #ifdef DEBUG
255  debugOut << "KalmanFitterInfo::getFittedState - biased at first measurement = backwardUpdate_ \n";
256  //backwardUpdate_->Print();
257  #endif
258  return *backwardUpdate_;
259  }
260 
262  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
263  e.setFatal();
264  throw e;
265  }
266  #ifdef DEBUG
267  debugOut << "KalmanFitterInfo::getFittedState - biased = mean(forwardUpdate_, backwardPrediction_) \n";
268  #endif
270  return *fittedStateBiased_;
271  }
272 
273  // unbiased
274 
275  // last measurement and no backward prediction -> use forward prediction
276  if (last && !backwardPrediction_) {
277  if(!forwardPrediction_) {
278  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
279  e.setFatal();
280  throw e;
281  }
282  #ifdef DEBUG
283  debugOut << "KalmanFitterInfo::getFittedState - unbiased at last measurement = forwardPrediction_ \n";
284  #endif
285  return *forwardPrediction_;
286  }
287 
288  // first measurement and no forward prediction -> use backward prediction
289  if (first && !forwardPrediction_) {
290  if(!backwardPrediction_) {
291  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
292  e.setFatal();
293  throw e;
294  }
295  #ifdef DEBUG
296  debugOut << "KalmanFitterInfo::getFittedState - unbiased at first measurement = backwardPrediction_ \n";
297  #endif
298  return *backwardPrediction_;
299  }
300 
302  Exception e("KalmanFitterInfo::getFittedState: Needed updates/predictions not available in this FitterInfo.", __LINE__,__FILE__);
303  e.setFatal();
304  throw e;
305  }
306  #ifdef DEBUG
307  debugOut << "KalmanFitterInfo::getFittedState - unbiased = mean(forwardPrediction_, backwardPrediction_) \n";
308  #endif
310  return *fittedStateUnbiased_;
311 }
312 
313 
314 MeasurementOnPlane KalmanFitterInfo::getResidual(unsigned int iMeasurement, bool biased, bool onlyMeasurementErrors) const {
315 
316  const MeasuredStateOnPlane& smoothedState = getFittedState(biased);
317  const MeasurementOnPlane* measurement = measurementsOnPlane_.at(iMeasurement);
318  const SharedPlanePtr& plane = measurement->getPlane();
319 
320  // check equality of planes and reps
321  if(*(smoothedState.getPlane()) != *plane) {
322  Exception e("KalmanFitterInfo::getResidual: smoothedState and measurement are not defined in the same plane.", __LINE__,__FILE__);
323  throw e;
324  }
325  if(smoothedState.getRep() != measurement->getRep()) {
326  Exception e("KalmanFitterInfo::getResidual: smoothedState and measurement are not defined wrt the same TrackRep.", __LINE__,__FILE__);
327  throw e;
328  }
329 
330  const AbsHMatrix* H = measurement->getHMatrix();
331 
332  //TODO: shouldn't the definition be (smoothed - measured) ?
333  // res = -(H*smoothedState - measuredState)
334  TVectorD res(H->Hv(smoothedState.getState()));
335  res -= measurement->getState();
336  res *= -1;
337 
338  if (onlyMeasurementErrors) {
339  return MeasurementOnPlane(res, measurement->getCov(), plane, smoothedState.getRep(), H->clone(), measurement->getWeight());
340  }
341 
342  TMatrixDSym cov(smoothedState.getCov());
343  H->HMHt(cov);
344  cov += measurement->getCov();
345 
346  return MeasurementOnPlane(res, cov, plane, smoothedState.getRep(), H->clone(), measurement->getWeight());
347 }
348 
349 
350 double KalmanFitterInfo::getSmoothedChi2(unsigned int iMeasurement) const {
351  const MeasurementOnPlane& res = getResidual(iMeasurement, true, false);
352 
353  TMatrixDSym Rinv;
354  tools::invertMatrix(res.getCov(), Rinv);
355  return Rinv.Similarity(res.getState());
356 }
357 
358 
360  referenceState_.reset(referenceState);
361  if (referenceState_)
362  setPlane(referenceState_->getPlane());
363 
364  // if plane has changed, delete outdated info
365  /*if (forwardPrediction_ && forwardPrediction_->getPlane() != getPlane())
366  setForwardPrediction(0);
367 
368  if (forwardUpdate_ && forwardUpdate_->getPlane() != getPlane())
369  setForwardUpdate(0);
370 
371  if (backwardPrediction_ && backwardPrediction_->getPlane() != getPlane())
372  setBackwardPrediction(0);
373 
374  if (backwardUpdate_ && backwardUpdate_->getPlane() != getPlane())
375  setBackwardUpdate(0);
376 
377  if (measurementsOnPlane_.size() > 0 && measurementsOnPlane_[0]->getPlane() != getPlane())
378  deleteMeasurementInfo();
379  */
380 }
381 
382 
384  forwardPrediction_.reset(forwardPrediction);
385  fittedStateUnbiased_.reset();
386  fittedStateBiased_.reset();
387  if (forwardPrediction_)
388  setPlane(forwardPrediction_->getPlane());
389 }
390 
392  backwardPrediction_.reset(backwardPrediction);
393  fittedStateUnbiased_.reset();
394  fittedStateBiased_.reset();
396  setPlane(backwardPrediction_->getPlane());
397 }
398 
400  forwardUpdate_.reset(forwardUpdate);
401  fittedStateUnbiased_.reset();
402  fittedStateBiased_.reset();
403  if (forwardUpdate_)
404  setPlane(forwardUpdate_->getPlane());
405 }
406 
408  backwardUpdate_.reset(backwardUpdate);
409  fittedStateUnbiased_.reset();
410  fittedStateBiased_.reset();
411  if (backwardUpdate_)
412  setPlane(backwardUpdate_->getPlane());
413 }
414 
415 
416 void KalmanFitterInfo::setMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane) {
418 
419  for (std::vector<MeasurementOnPlane*>::const_iterator m = measurementsOnPlane.begin(), mend = measurementsOnPlane.end(); m < mend; ++m) {
421  }
422 }
423 
424 
426  if (measurementsOnPlane_.size() == 0)
427  setPlane(measurementOnPlane->getPlane());
428 
429  measurementsOnPlane_.push_back(measurementOnPlane);
430 }
431 
432 void KalmanFitterInfo::addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane* >& measurementsOnPlane) {
433  for (std::vector<MeasurementOnPlane*>::const_iterator m = measurementsOnPlane.begin(), mend = measurementsOnPlane.end(); m < mend; ++m) {
435  }
436 }
437 
438 
440  rep_ = rep;
441 
442  if (referenceState_)
443  referenceState_->setRep(rep);
444 
445  if (forwardPrediction_)
446  forwardPrediction_->setRep(rep);
447 
448  if (forwardUpdate_)
449  forwardUpdate_->setRep(rep);
450 
452  backwardPrediction_->setRep(rep);
453 
454  if (backwardUpdate_)
455  backwardUpdate_->setRep(rep);
456 
457  for (std::vector<MeasurementOnPlane*>::iterator it = measurementsOnPlane_.begin(); it != measurementsOnPlane_.end(); ++it) {
458  (*it)->setRep(rep);
459  }
460 }
461 
462 
463 void KalmanFitterInfo::setWeights(const std::vector<double>& weights) {
464 
465  if (weights.size() != getNumMeasurements()) {
466  Exception e("KalmanFitterInfo::setWeights: weights do not have the same size as measurementsOnPlane", __LINE__,__FILE__);
467  throw e;
468  }
469 
470  if (fixWeights_) {
471  errorOut << "KalmanFitterInfo::setWeights - WARNING: setting weights even though weights are fixed!" << std::endl;
472  }
473 
474  for (unsigned int i=0; i<getNumMeasurements(); ++i) {
475  getMeasurementOnPlane(i)->setWeight(weights[i]);
476  }
477 }
478 
479 
481  setForwardPrediction(nullptr);
482  setForwardUpdate(nullptr);
483  fittedStateUnbiased_.reset();
484  fittedStateBiased_.reset();
485 }
486 
488  setBackwardPrediction(nullptr);
489  setBackwardUpdate(nullptr);
490  fittedStateUnbiased_.reset();
491  fittedStateBiased_.reset();
492 }
493 
495  setForwardPrediction(nullptr);
496  setBackwardPrediction(nullptr);
497  fittedStateUnbiased_.reset();
498  fittedStateBiased_.reset();
499 }
500 
502  // FIXME: need smart pointers / smart containers here
503  for (size_t i = 0; i < measurementsOnPlane_.size(); ++i)
504  delete measurementsOnPlane_[i];
505 
506  measurementsOnPlane_.clear();
507 }
508 
509 
510 void KalmanFitterInfo::Print(const Option_t*) const {
511  printOut << "genfit::KalmanFitterInfo. Belongs to TrackPoint " << trackPoint_ << "; TrackRep " << rep_ << "\n";
512 
513  if (fixWeights_)
514  printOut << "Weights are fixed.\n";
515 
516  for (unsigned int i=0; i<measurementsOnPlane_.size(); ++i) {
517  printOut << "MeasurementOnPlane Nr " << i <<": "; measurementsOnPlane_[i]->Print();
518  }
519 
520  if (referenceState_) {
521  printOut << "Reference state: "; referenceState_->Print();
522  }
523  if (forwardPrediction_) {
524  printOut << "Forward prediction_: "; forwardPrediction_->Print();
525  }
526  if (forwardUpdate_) {
527  printOut << "Forward update: "; forwardUpdate_->Print();
528  }
529  if (backwardPrediction_) {
530  printOut << "Backward prediction_: "; backwardPrediction_->Print();
531  }
532  if (backwardUpdate_) {
533  printOut << "Backward update: "; backwardUpdate_->Print();
534  }
535 
536 }
537 
538 
540 
541  bool retVal(true);
542 
543  // check if in a TrackPoint
544  if (!trackPoint_) {
545  errorOut << "KalmanFitterInfo::checkConsistency(): trackPoint_ is nullptr" << std::endl;
546  retVal = false;
547  }
548 
549  // check if there is a reference state
550  /*if (!referenceState_) {
551  errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is nullptr" << std::endl;
552  retVal = false;
553  }*/
554 
556 
557  if (plane.get() == nullptr) {
559  return true;
560  errorOut << "KalmanFitterInfo::checkConsistency(): plane is nullptr" << std::endl;
561  retVal = false;
562  }
563 
564  TVector3 oTest = plane->getO(); // see if the plane object is there
565  oTest *= 47.11;
566 
567  // if more than one measurement, check if they have the same dimensionality
568  if (measurementsOnPlane_.size() > 1) {
569  int dim = measurementsOnPlane_[0]->getState().GetNrows();
570  for (unsigned int i = 1; i<measurementsOnPlane_.size(); ++i) {
571  if(measurementsOnPlane_[i]->getState().GetNrows() != dim) {
572  errorOut << "KalmanFitterInfo::checkConsistency(): measurementsOnPlane_ do not all have the same dimensionality" << std::endl;
573  retVal = false;
574  }
575  }
576  if (dim == 0) {
577  errorOut << "KalmanFitterInfo::checkConsistency(): measurementsOnPlane_ have dimension 0" << std::endl;
578  retVal = false;
579  }
580  }
581 
582  // see if everything else is defined wrt this plane and rep_
583  int dim = rep_->getDim(); // check dim
584  if (referenceState_) {
585  if(referenceState_->getPlane() != plane) {
586  errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is not defined with the correct plane " << referenceState_->getPlane().get() << " vs. " << plane.get() << std::endl;
587  retVal = false;
588  }
589  if (referenceState_->getRep() != rep_) {
590  errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ is not defined with the correct TrackRep" << std::endl;
591  retVal = false;
592  }
593  if (referenceState_->getState().GetNrows() != dim) {
594  errorOut << "KalmanFitterInfo::checkConsistency(): referenceState_ does not have the right dimension!" << std::endl;
595  retVal = false;
596  }
597  }
598 
599  if (forwardPrediction_) {
600  if(forwardPrediction_->getPlane() != plane) {
601  errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ is not defined with the correct plane" << std::endl;
602  retVal = false;
603  }
604  if(forwardPrediction_->getRep() != rep_) {
605  errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ is not defined with the correct TrackRep" << std::endl;
606  retVal = false;
607  }
608  if (forwardPrediction_->getState().GetNrows() != dim || forwardPrediction_->getCov().GetNrows() != dim) {
609  errorOut << "KalmanFitterInfo::checkConsistency(): forwardPrediction_ does not have the right dimension!" << std::endl;
610  retVal = false;
611  }
612  }
613  if (forwardUpdate_) {
614  if(forwardUpdate_->getPlane() != plane) {
615  errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ is not defined with the correct plane" << std::endl;
616  retVal = false;
617  }
618  if(forwardUpdate_->getRep() != rep_) {
619  errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ is not defined with the correct TrackRep" << std::endl;
620  retVal = false;
621  }
622  if (forwardUpdate_->getState().GetNrows() != dim || forwardUpdate_->getCov().GetNrows() != dim) {
623  errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ does not have the right dimension!" << std::endl;
624  retVal = false;
625  }
626  }
627 
628  if (backwardPrediction_) {
629  if(backwardPrediction_->getPlane() != plane) {
630  errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ is not defined with the correct plane" << std::endl;
631  retVal = false;
632  }
633  if(backwardPrediction_->getRep() != rep_) {
634  errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ is not defined with the correct TrackRep" << std::endl;
635  retVal = false;
636  }
637  if (backwardPrediction_->getState().GetNrows() != dim || backwardPrediction_->getCov().GetNrows() != dim) {
638  errorOut << "KalmanFitterInfo::checkConsistency(): backwardPrediction_ does not have the right dimension!" << std::endl;
639  retVal = false;
640  }
641  }
642  if (backwardUpdate_) {
643  if(backwardUpdate_->getPlane() != plane) {
644  errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ is not defined with the correct plane" << std::endl;
645  retVal = false;
646  }
647  if(backwardUpdate_->getRep() != rep_) {
648  errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ is not defined with the correct TrackRep" << std::endl;
649  retVal = false;
650  }
651  if (backwardUpdate_->getState().GetNrows() != dim || backwardUpdate_->getCov().GetNrows() != dim) {
652  errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ does not have the right dimension!" << std::endl;
653  retVal = false;
654  }
655  }
656 
657  for (std::vector<MeasurementOnPlane*>::const_iterator it = measurementsOnPlane_.begin(); it != measurementsOnPlane_.end(); ++it) {
658  if((*it)->getPlane() != plane) {
659  errorOut << "KalmanFitterInfo::checkConsistency(): measurement is not defined with the correct plane" << std::endl;
660  retVal = false;
661  }
662  if((*it)->getRep() != rep_) {
663  errorOut << "KalmanFitterInfo::checkConsistency(): measurement is not defined with the correct TrackRep" << std::endl;
664  retVal = false;
665  }
666  if ((*it)->getState().GetNrows() == 0) {
667  errorOut << "KalmanFitterInfo::checkConsistency(): measurement has dimension 0!" << std::endl;
668  retVal = false;
669  }
670  }
671 
672  if (flags == nullptr or !flags->hasFlags("U")) { // if predictions have not been pruned
673  // see if there is an update w/o prediction or measurement
675  errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ w/o forwardPrediction_" << std::endl;
676  retVal = false;
677  }
678 
679 
681  errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ w/o backwardPrediction_" << std::endl;
682  retVal = false;
683  }
684 
685  if (flags == nullptr or !flags->hasFlags("M")) {
686  if (forwardUpdate_ && measurementsOnPlane_.size() == 0) {
687  errorOut << "KalmanFitterInfo::checkConsistency(): forwardUpdate_ w/o measurement" << std::endl;
688  retVal = false;
689  }
690 
691  if (backwardUpdate_ && measurementsOnPlane_.size() == 0) {
692  errorOut << "KalmanFitterInfo::checkConsistency(): backwardUpdate_ w/o measurement" << std::endl;
693  retVal = false;
694  }
695  }
696  }
697 
698 
699  return retVal;
700 }
701 
702 
703 // Modified from auto-generated Streamer to correctly deal with smart pointers.
704 void KalmanFitterInfo::Streamer(TBuffer &R__b)
705 {
706  // Stream an object of class genfit::KalmanFitterInfo.
707 
708  //This works around a msvc bug and should be harmless on other platforms
709  typedef ::genfit::KalmanFitterInfo thisClass;
710  UInt_t R__s, R__c;
711  if (R__b.IsReading()) {
712  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
713  //This works around a msvc bug and should be harmless on other platforms
714  typedef genfit::AbsFitterInfo baseClass0;
715  baseClass0::Streamer(R__b);
716  int flag;
717  R__b >> flag;
722  if (flag & 1) {
723  referenceState_.reset(new ReferenceStateOnPlane());
724  referenceState_->Streamer(R__b);
725  referenceState_->setPlane(getPlane());
726  // rep needs to be fixed up
727  }
728  if (flag & (1 << 1)) {
729  forwardPrediction_.reset(new MeasuredStateOnPlane());
730  forwardPrediction_->Streamer(R__b);
731  forwardPrediction_->setPlane(getPlane());
732  // rep needs to be fixed up
733  }
734  if (flag & (1 << 2)) {
735  forwardUpdate_.reset(new KalmanFittedStateOnPlane());
736  forwardUpdate_->Streamer(R__b);
737  forwardUpdate_->setPlane(getPlane());
738  // rep needs to be fixed up
739  }
740  if (flag & (1 << 3)) {
741  backwardPrediction_.reset(new MeasuredStateOnPlane());
742  backwardPrediction_->Streamer(R__b);
743  backwardPrediction_->setPlane(getPlane());
744  // rep needs to be fixed up
745  }
746  if (flag & (1 << 4)) {
747  backwardUpdate_.reset(new KalmanFittedStateOnPlane());
748  backwardUpdate_->Streamer(R__b);
749  backwardUpdate_->setPlane(getPlane());
750  // rep needs to be fixed up
751  }
752  {
753  std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> > &R__stl = measurementsOnPlane_;
754  TClass *R__tcl1 = TBuffer::GetClass(typeid(genfit::MeasurementOnPlane));
755  if (R__tcl1==0) {
756  Error("measurementsOnPlane_ streamer","Missing the TClass object for genfit::MeasurementOnPlane!");
757  return;
758  }
759  int R__i, R__n;
760  R__b >> R__n;
761  R__stl.reserve(R__n);
762  for (R__i = 0; R__i < R__n; R__i++) {
763  genfit::MeasurementOnPlane* R__t = new MeasurementOnPlane();
764  R__t->Streamer(R__b);
765  R__t->setPlane(getPlane());
766  R__stl.push_back(R__t);
767  }
768  }
769  R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
770  } else {
771  R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
772  //This works around a msvc bug and should be harmless on other platforms
773  typedef genfit::AbsFitterInfo baseClass0;
774  baseClass0::Streamer(R__b);
775  // "!!" forces the value to 1 or 0 (pointer != 0 or pointer == 0),
776  // this value is then written as a bitfield.
777  int flag = ((!!referenceState_)
778  | (!!forwardPrediction_ << 1)
779  | (!!forwardUpdate_ << 2)
780  | (!!backwardPrediction_ << 3)
781  | (!!backwardUpdate_ << 4));
782  R__b << flag;
783  if (flag & 1)
784  referenceState_->Streamer(R__b);
785  if (flag & (1 << 1))
786  forwardPrediction_->Streamer(R__b);
787  if (flag & (1 << 2))
788  forwardUpdate_->Streamer(R__b);
789  if (flag & (1 << 3))
790  backwardPrediction_->Streamer(R__b);
791  if (flag & (1 << 4))
792  backwardUpdate_->Streamer(R__b);
793  {
794  std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> > &R__stl = measurementsOnPlane_;
795  int R__n=(&R__stl) ? int(R__stl.size()) : 0;
796  R__b << R__n;
797  if(R__n) {
798  std::vector<genfit::MeasurementOnPlane*,std::allocator<genfit::MeasurementOnPlane*> >::iterator R__k;
799  for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
800  (*R__k)->Streamer(R__b);
801  }
802  }
803  }
804  R__b.SetByteCount(R__c, kTRUE);
805  }
806 }
807 
808 
809 } /* End of namespace genfit */