KFitTrack.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 ///
3 /// \file KFitTrack.cxx
4 ///
5 /// \brief Basic Kalman filter track class, with fit information.
6 ///
7 /// \author H. Greenlee
8 ///
9 ////////////////////////////////////////////////////////////////////////
10 
12 #include "cetlib_except/exception.h"
13 
14 namespace trkf {
15 
16  /// Default constructor.
17  KFitTrack::KFitTrack() : fPath(0.), fChisq(0.), fStat(INVALID) {}
18 
19  /// Initializing constructor.
20  ///
21  /// Arguments:
22  ///
23  /// tre - KETrack.
24  /// s - Path distance.
25  /// chisq - Fit chisquare.
26  /// stat - Fit status.
27  ///
28  KFitTrack::KFitTrack(const KETrack& tre, double s, double chisq, FitStatus stat)
29  : KETrack(tre), fPath(s), fChisq(chisq), fStat(stat)
30  {}
31 
32  /// Destructor.
34 
35  /// Combine two tracks.
36  ///
37  /// Arguments:
38  ///
39  /// trf - Another track.
40  ///
41  /// Returns: True if success.
42  ///
43  /// This method updates the current track to be the weighted average
44  /// of itself and another track. Track parameters and error matrix
45  /// are updated by method KETrack::combineTrack. The updated
46  /// chissquare is the sum of the original chisquare, the chisquare
47  /// from the other track, and the chisquare of the combination. The
48  /// path distance is not updated.
49  ///
50  /// The updated status is derived from the input
51  /// status according to the following table.
52  ///
53  /// FORWARD + BACKWARD_PREDICTED = OPTIMAL
54  /// FORWARD_PREDICTED + BACKWARD = OPTIMAL
55  /// FORWARD_PREDICTED + BACKWARD_PREDICTED = OPTIMAL_PREDICTED
56  ///
57  /// Any other combination of input statuses will cause this method
58  /// to return failure. This method can also return failure because
59  /// of singular error matrices. In case of failure, the original
60  /// track is not updated.
61  ///
62  /// The two tracks being combined should be on the same surface
63  /// (throw exception if not).
64  ///
65  bool
67  {
68  // Make sure that the two track surfaces are the same.
69  // Throw an exception if they are not.
70 
71  if (!getSurface()->isEqual(*trf.getSurface()))
72  throw cet::exception("KFitTrack") << "Track combination surfaces are not the same.\n";
73 
74  // Default result failure.
75 
76  bool result = false;
77 
78  // Make sure input statuses are compatible and figure out the
79  // updated status.
80 
81  FitStatus stat1 = getStat();
82  FitStatus stat2 = trf.getStat();
83  FitStatus statu = UNKNOWN;
84  if ((stat1 == FORWARD && stat2 == BACKWARD_PREDICTED) ||
85  (stat1 == FORWARD_PREDICTED && stat2 == BACKWARD) ||
86  (stat1 == BACKWARD && stat2 == FORWARD_PREDICTED) ||
87  (stat1 == BACKWARD_PREDICTED && stat2 == FORWARD))
88  statu = OPTIMAL;
89  else if (stat1 == FORWARD_PREDICTED && stat2 == BACKWARD_PREDICTED)
90  statu = OPTIMAL_PREDICTED;
91  else
92  statu = UNKNOWN;
93  if (statu != UNKNOWN) {
94 
95  // Update track parameters and error matrix.
96 
97  std::optional<double> chisq = combineTrack(trf);
98 
99  // Update status and chisquare.
100 
101  if (!!chisq) {
102  result = true;
103  fStat = statu;
104  fChisq = fChisq + trf.getChisq() + *chisq;
105  }
106  }
107 
108  // Done.
109 
110  return result;
111  }
112 
113  /// Printout
114  std::ostream&
115  KFitTrack::Print(std::ostream& out, bool doTitle) const
116  {
117  if (doTitle) out << "KFitTrack:\n";
118 
119  // Print information specific to this class.
120 
121  out << " Distance = " << fPath << "\n";
122  out << " Chisquare = " << fChisq << "\n";
123  out << " Status = "
124  << (fStat == INVALID ?
125  "INVALID" :
126  (fStat == UNKNOWN ?
127  "UNKNOWN" :
128  (fStat == FORWARD ?
129  "FORWARD" :
130  (fStat == FORWARD_PREDICTED ?
131  "FORWARD_PREDICTED" :
132  (fStat == BACKWARD ?
133  "BACKWARD" :
134  (fStat == BACKWARD_PREDICTED ?
135  "BACKWARD_PREDICTED" :
136  (fStat == OPTIMAL ? "OPTIMAL" : "OPTIMAL_PREDICTED")))))))
137  << "\n";
138 
139  // Print base class.
140 
141  KETrack::Print(out, false);
142  return out;
143  }
144 
145 } // end namespace trkf
bool isEqual(float x1, float x2)
const std::shared_ptr< const Surface > & getSurface() const
Surface.
Definition: KTrack.h:55
static QCString result
FitStatus
Fit status enum.
Definition: KFitTrack.h:41
FitStatus fStat
Fit status.
Definition: KFitTrack.h:88
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KFitTrack.cxx:115
std::optional< double > combineTrack(const KETrack &tre)
Combine two tracks.
Definition: KETrack.cxx:89
double fChisq
Fit chisquare.
Definition: KFitTrack.h:87
KFitTrack()
Default constructor.
Definition: KFitTrack.cxx:17
virtual ~KFitTrack()
Destructor.
Definition: KFitTrack.cxx:33
bool combineFit(const KFitTrack &trf)
Combine two tracks.
Definition: KFitTrack.cxx:66
virtual std::ostream & Print(std::ostream &out, bool doTitle=true) const
Printout.
Definition: KETrack.cxx:182
double fPath
Propagation distance.
Definition: KFitTrack.h:86
Basic Kalman filter track class, with fit information.
double getChisq() const
Fit chisquare.
Definition: KFitTrack.h:67
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
FitStatus getStat() const
Fit status.
Definition: KFitTrack.h:68