BOSS 8.0.0
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 : yoshihito.iwasaki@kek.jp
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/TMLine.h"
15#include "TrkReco/TMLink.h"
16#include "TrkReco/TTrackBase.h"
17
18TLineFitter::TLineFitter( const std::string& name )
19 : TMFitter( name ), _a( 0. ), _b( 0. ), _det( 0. ) {}
20
22
24
25 //...Already fitted ?...
26 if ( t.fitted() ) return TFitAlreadyFitted;
27
28 //...Check # of hits...
29 if ( t.links().length() < 2 ) return TFitErrorFewHits;
30
31 unsigned n = t.links().length();
32 if ( _det == 0. && n == 2 )
33 {
34 double x0 = t.links()[0]->position().x();
35 double y0 = t.links()[0]->position().y();
36 double x1 = t.links()[1]->position().x();
37 double y1 = t.links()[1]->position().y();
38 if ( x0 == x1 ) return TFitFailed;
39 _a = ( y0 - y1 ) / ( x0 - x1 );
40 _b = -_a * x1 + y1;
41 }
42 else
43 {
44 double sum = (double)n;
45 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
46 for ( unsigned i = 0; i < n; i++ )
47 {
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. ) { return TFitFailed; }
63 else
64 {
65 _a = ( sumXY * sum - sumX * sumY ) / _det;
66 _b = ( sumX2 * sumY - sumX * sumXY ) / _det;
67 }
68 }
69
70 if ( t.objectType() == Line ) ( (TMLine&)t ).property( _a, _b, _det );
71 fitDone( t );
72 return 0;
73}
HepGeom::Point3D< double > HepPoint3D
const Int_t n
virtual int fit(TTrackBase &) const
virtual ~TLineFitter()
Destructor.
TLineFitter(const std::string &name)
Constructor.
const std::string & name(void) const
returns name.
TMFitter(const std::string &name)
Constructor.
Definition TMFitter.cxx:17
void fitDone(TTrackBase &) const
sets the fitted flag. (Bad implementation)
Definition TMFitter.cxx:21
A class to represent a track in tracking.
A virtual class for a track class in tracking.
int t()
Definition t.c:1