LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
trkf::TrackLineFitAlg Class Reference

#include "TrackLineFitAlg.h"

Public Member Functions

void TrkLineFit (std::vector< geo::WireID > &hitWID, std::vector< double > &hitX, std::vector< double > &hitXErr, double XOrigin, TVector3 &Pos, TVector3 &Dir, float &ChiDOF) const
 

Private Attributes

geo::WireReadoutGeom const * wireReadoutGeom = &art::ServiceHandle<geo::WireReadout>()->Get()
 

Detailed Description

Definition at line 28 of file TrackLineFitAlg.h.

Member Function Documentation

void trkf::TrackLineFitAlg::TrkLineFit ( std::vector< geo::WireID > &  hitWID,
std::vector< double > &  hitX,
std::vector< double > &  hitXErr,
double  XOrigin,
TVector3 &  Pos,
TVector3 &  Dir,
float &  ChiDOF 
) const

Definition at line 30 of file TrackLineFitAlg.cxx.

References geo::WireReadoutGeom::FirstPlane(), norm, geo::WireReadoutGeom::Plane(), sw, w, geo::PlaneGeo::WireCoordinate(), wireReadoutGeom, and x.

Referenced by trkf::TrackTrajectoryAlg::TrackTrajectory().

37  {
38  // Linear fit using X as the independent variable. Hits to be fitted
39  // are passed in the hits vector in a pair form (X, WireID). The
40  // fitted track position at XOrigin is returned in the Pos vector.
41  // The direction cosines are returned in the Dir vector.
42  //
43  // SVD fit adapted from $ROOTSYS/tutorials/matrix/solveLinear.C
44  // Fit equation is w = A(X)v, where w is a vector of hit wires, A is
45  // a matrix to calculate a track projected to a point at X, and v is
46  // a vector (Yo, Zo, dY/dX, dZ/dX).
47 
48  // assume failure
49  ChiDOF = -1;
50 
51  if (hitX.size() < 4) return;
52  if (hitX.size() != hitWID.size()) return;
53  if (hitX.size() != hitXErr.size()) return;
54 
55  const unsigned int nvars = 4;
56  unsigned int npts = hitX.size();
57 
58  TMatrixD A(npts, nvars);
59  // vector holding the Wire number
60  TVectorD w(npts);
61  unsigned short ninpl[3] = {0};
62  unsigned short nok = 0;
63  for (std::size_t iht = 0; iht < hitX.size(); ++iht) {
64  auto const& wid = hitWID[iht];
65  auto const& plane = wireReadoutGeom->Plane(wid);
66  // get the wire plane offset
67  double const off = plane.WireCoordinate(geo::Point_t{0, 0, 0});
68  // get the "cosine-like" component
69  double const cw = plane.WireCoordinate(geo::Point_t{0, 1, 0}) - off;
70  // the "sine-like" component
71  double const sw = plane.WireCoordinate(geo::Point_t{0, 0, 1}) - off;
72  double const x = hitX[iht] - XOrigin;
73  double wght{1.};
74  if (hitXErr[iht] > 0) { wght = 1 / hitXErr[iht]; }
75  A[iht][0] = wght * cw;
76  A[iht][1] = wght * sw;
77  A[iht][2] = wght * cw * x;
78  A[iht][3] = wght * sw * x;
79  w[iht] = wght * (hitWID[iht].Wire - off);
80  unsigned int ipl = wid.Plane;
81  ++ninpl[ipl];
82  // need at least two points in a plane
83  if (ninpl[ipl] == 2) ++nok;
84  }
85 
86  // need at least 2 planes with at least two points
87  if (nok < 2) return;
88 
89  TDecompSVD svd(A);
90  bool ok;
91  TVectorD tVec = svd.Solve(w, ok);
92 
93  ChiDOF = 0;
94 
95  // not enough points to calculate Chisq
96  if (hitX.size() == 4) return;
97 
98  // FIXME: The 'tpc' and 'cstat' variables are suspect as they are
99  // updated for each iteration below, but only the last
100  // value is used in the geom->WirePitch(...) calculation
101  // below.
102  unsigned int tpc{-1u}, cstat{-1u};
103  for (std::size_t iht = 0; iht < hitX.size(); ++iht) {
104  auto const& wid = hitWID[iht];
105  auto const& plane = wireReadoutGeom->Plane(wid);
106  tpc = wid.TPC;
107  cstat = wid.Cryostat;
108  double const off = plane.WireCoordinate(geo::Point_t{0, 0, 0});
109  double const cw = plane.WireCoordinate(geo::Point_t{0, 1, 0}) - off;
110  double const sw = plane.WireCoordinate(geo::Point_t{0, 0, 1}) - off;
111  double const x = hitX[iht] - XOrigin;
112  double const ypr = tVec[0] + tVec[2] * x;
113  double const zpr = tVec[1] + tVec[3] * x;
114  double wght{1.};
115  if (hitXErr[iht] > 0) { wght = 1 / hitXErr[iht]; }
116  assert(wght > 0.);
117  double const diff = (ypr * cw + zpr * sw - (hitWID[iht].Wire - off)) / wght;
118  ChiDOF += diff * diff;
119  }
120 
121  double werr2 = wireReadoutGeom->FirstPlane({cstat, tpc}).WirePitch();
122  werr2 *= werr2;
123  ChiDOF /= werr2;
124  ChiDOF /= (double)(npts - 4);
125 
126  double norm = sqrt(1 + tVec[2] * tVec[2] + tVec[3] * tVec[3]);
127  Dir[0] = 1 / norm;
128  Dir[1] = tVec[2] / norm;
129  Dir[2] = tVec[3] / norm;
130 
131  Pos[0] = XOrigin;
132  Pos[1] = tVec[0];
133  Pos[2] = tVec[1];
134  } // TrkLineFit()
Float_t x
Definition: compare.C:6
double WireCoordinate(Point_t const &point) const
Returns the coordinate of the point on the plane, in wire units.
Definition: PlaneGeo.h:704
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
Float_t sw
Definition: plot.C:20
PlaneGeo const & FirstPlane(TPCID const &tpcid) const
Returns the first plane of the specified TPC.
Float_t norm
geo::WireReadoutGeom const * wireReadoutGeom
PlaneGeo const & Plane(TPCID const &tpcid, View_t view) const
Returns the specified wire.
Float_t w
Definition: plot.C:20

Member Data Documentation

geo::WireReadoutGeom const* trkf::TrackLineFitAlg::wireReadoutGeom = &art::ServiceHandle<geo::WireReadout>()->Get()
private

Definition at line 39 of file TrackLineFitAlg.h.

Referenced by TrkLineFit().


The documentation for this class was generated from the following files: