StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Track.cc
1 //
2 // Pibero Djawotho <pibero@iucf.indiana.edu>
3 // Indiana University
4 // November 17, 2005
5 //
6 #include "TMath.h"
7 // STAR
8 #include "StThreeVectorD.hh"
9 
10 // Local
11 #include "Line.hh"
12 #include "Track.hh"
13 
14 #define MAX_SLOPE 0.1
15 
16 TLinearFitter Track::mXfitter(1, "pol1", "");
17 TLinearFitter Track::mYfitter(1, "pol1", "");
18 
20 {
21  unsigned int oldSize = size();
22  copy(track->begin(), track->end(), back_inserter(*this));
23  inplace_merge(begin(), begin()+oldSize, end(), LessHit());
24 }
25 
26 bool Track::fit()
27 {
28  //
29  // Fit lines to track projections in zx- and zy-plane
30  //
31  mXfitter.ClearPoints();
32  mYfitter.ClearPoints();
33  for (iterator i = begin(); i != end(); ++i) {
34  StHit* hit = *i;
35  double x = hit->position().x();
36  double y = hit->position().y();
37  double z = hit->position().z();
38  mXfitter.AddPoint(&z, x);
39  mYfitter.AddPoint(&z, y);
40  }
41  mXfitter.Eval();
42  mYfitter.Eval();
43  mChiSquareX = mXfitter.GetChisquare();
44  mChiSquareY = mYfitter.GetChisquare();
45  mNumberFreeParameters = mXfitter.GetNumberFreeParameters();
46  mX0 = mXfitter.GetParameter(0);
47  mY0 = mYfitter.GetParameter(0);
48  mdxdz = mXfitter.GetParameter(1);
49  mdydz = mYfitter.GetParameter(1);
50  mX0error = mXfitter.GetParError(0);
51  mY0error = mYfitter.GetParError(0);
52  mdxdzError = mXfitter.GetParError(1);
53  mdydzError = mYfitter.GetParError(1);
54  StThreeVectorD origin(mX0, mY0, 0);
55  StThreeVectorD direction(mdxdz, mdydz, 1);
56  Line line(origin, direction);
57  mLength = abs(line.perigee(lastHit()->position()) - line.perigee(firstHit()->position()));
58 
59  return true;
60 }
61 
62 bool Track::ok() const
63 {
64  return fabs(dxdz()) <= MAX_SLOPE && fabs(dydz()) <= MAX_SLOPE;
65 }
66 
67 bool Track::accept(StHit* hit) const
68 {
69  double dx = x0() + dxdz() * hit->position().z() - hit->position().x();
70  double dy = y0() + dydz() * hit->position().z() - hit->position().y();
71  double dr = hypot(dx, dy);
72  return fabs(dr) <= 5;
73 }
74 
75 ostream& operator<<(ostream& os, Track& track)
76 {
77  os << "Track " << &track << " has " << track.size() << " hits:\n";
78  for (Track::iterator i = track.begin(); i != track.end(); ++i) {
79  StHit* hit = *i;
80  os << hit->position() << '\n';
81  }
82  os << "x0:\t" << track.x0() << " +/- " << track.x0error() << '\n'
83  << "y0:\t" << track.y0() << " +/- " << track.y0error() << '\n'
84  << "dxdz:\t" << track.dxdz() << " +/- " << track.dxdzError() << '\n'
85  << "dydz:\t" << track.dydz() << " +/- " << track.dydzError() << '\n'
86  << "chi2zx:\t" << track.chi2zx() << '\n'
87  << "chi2zy:\t" << track.chi2zy() << '\n'
88  << "probzx:\t" << TMath::Prob(track.chi2zx(), track.ndf()) << '\n'
89  << "probzy:\t" << TMath::Prob(track.chi2zy(), track.ndf()) << '\n';
90  return os;
91 }
void merge(Track *track)
Merge this track with that track.
Definition: Track.cc:19
double y0() const
y-intercept at z = 0
Definition: Track.hh:171
STAR includes.
Definition: Line.hh:23
Definition: StHit.h:125
bool fit()
Perform linear fits in zx- and zy-plane.
Definition: Track.cc:26
double x0error() const
Error on x-intercept.
Definition: Track.hh:174
double chi2zx()
chi square of linear fit in zx-plane
Definition: Track.hh:167
double x0() const
x-intercept at z = 0
Definition: Track.hh:170
bool ok() const
Good track?
Definition: Track.cc:62
double dydz() const
dy/dz slope
Definition: Track.hh:173
StThreeVectorD perigee(const StThreeVectorD &point) const
Perigee, i.e. Closest point on the line to a given point.
Definition: Line.cc:26
double y0error() const
Error on y-intercept.
Definition: Track.hh:175
double chi2zy()
chi square of linear fit in zy-plane
Definition: Track.hh:168
bool accept(StHit *hit) const
Is hit close enough to track?
Definition: Track.cc:67
StHit * firstHit() const
First hit.
Definition: Track.hh:164
StHit * lastHit() const
Last hit.
Definition: Track.hh:165
double dxdz() const
dx/dz slope
Definition: Track.hh:172
double dxdzError() const
Error on dx/dz slope.
Definition: Track.hh:176
double dydzError() const
Error on dy/dz slope.
Definition: Track.hh:177
int ndf() const
Number of degrees of freedom.
Definition: Track.hh:169
C++ STL includes.
Definition: AgUStep.h:47