BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TLineFitter.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TLineFitter.cxx,v 1.8 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TLineFitter.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to fit a TTrackBase object to a line.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#include "TrkReco/TLineFitter.h"
14#include "TrkReco/TTrackBase.h"
15#include "TrkReco/TMLine.h"
16#include "TrkReco/TMLink.h"
17
18TLineFitter::TLineFitter(const std::string & name)
19: TMFitter(name), _a(0.), _b(0.), _det(0.) {
20}
21
23}
24
25int
27
28 //...Already fitted ?...
29 if (t.fitted()) return TFitAlreadyFitted;
30
31 //...Check # of hits...
32 if (t.links().length() < 2) return TFitErrorFewHits;
33
34 unsigned n = t.links().length();
35 if (_det == 0. && n == 2) {
36 double x0 = t.links()[0]->position().x();
37 double y0 = t.links()[0]->position().y();
38 double x1 = t.links()[1]->position().x();
39 double y1 = t.links()[1]->position().y();
40 if (x0 == x1) return TFitFailed;
41 _a = (y0 - y1) / (x0 - x1);
42 _b = - _a * x1 + y1;
43 }
44 else {
45 double sum = (double) n;
46 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
47 for (unsigned i = 0; i < n; i++) {
48 const HepPoint3D & p = t.links()[i]->position();
49 double x = p.x();
50 double y = p.y();
51 sumX += x;
52 sumY += y;
53 sumX2 += x * x;
54 sumXY += x * y;
55 sumY2 += y * y;
56 }
57
58 _det = sum * sumX2 - sumX * sumX;
59#ifdef TRKRECO_DEBUG_DETAIL
60 cout << " TLineFitter::fit ... det=" << _det << std::endl;
61#endif
62 if (_det == 0.) {
63 return TFitFailed;
64 }
65 else {
66 _a = (sumXY * sum - sumX * sumY) / _det;
67 _b = (sumX2 * sumY - sumX * sumXY) / _det;
68 }
69 }
70
71 if (t.objectType() == Line)
72 ((TMLine &) t).property(_a, _b, _det);
73 fitDone(t);
74 return 0;
75}
const Int_t n
Double_t x[10]
virtual int fit(TTrackBase &) const
Definition: TLineFitter.cxx:26
virtual ~TLineFitter()
Destructor.
Definition: TLineFitter.cxx:22
TLineFitter(const std::string &name)
Constructor.
Definition: TLineFitter.cxx:18
A class to fit a TTrackBase object.
void fitDone(TTrackBase &) const
sets the fitted flag. (Bad implementation)
Definition: TMFitter.cxx:24
A class to represent a track in tracking.
A virtual class for a track class in tracking.
int t()
Definition: t.c:1