12 #include <sys/types.h> 31 double XOrigin, TVector3& Pos, TVector3& Dir,
float& ChiDOF)
46 if(hitX.size() < 4)
return;
47 if(hitX.size() != hitWID.size())
return;
48 if(hitX.size() != hitXErr.size())
return;
50 const unsigned int nvars = 4;
51 unsigned int npts = hitX.size();
53 TMatrixD A(npts, nvars);
56 unsigned short ninpl[3] = {0};
57 unsigned short nok = 0;
59 unsigned int ipl, tpc, cstat;
60 double x, cw,
sw, off, wght;
61 for(iht = 0; iht < hitX.size(); ++iht) {
62 cstat = hitWID[iht].Cryostat;
63 tpc = hitWID[iht].TPC;
64 ipl = hitWID[iht].Plane;
71 x = hitX[iht] - XOrigin;
72 if(hitXErr[iht] > 0) {
73 wght = 1 / hitXErr[iht];
77 A[iht][0] = wght * cw;
78 A[iht][1] = wght *
sw;
79 A[iht][2] = wght * cw *
x;
80 A[iht][3] = wght * sw *
x;
81 w[iht] = wght * (hitWID[iht].Wire - off);
84 if(ninpl[ipl] == 2) ++nok;
92 TVectorD tVec = svd.Solve(w, ok);
97 if(hitX.size() == 4)
return;
99 double ypr, zpr, diff;
100 for(iht = 0; iht < hitX.size(); ++iht) {
101 cstat = hitWID[iht].Cryostat;
102 tpc = hitWID[iht].TPC;
103 ipl = hitWID[iht].Plane;
107 x = hitX[iht] - XOrigin;
108 ypr = tVec[0] + tVec[2] *
x;
109 zpr = tVec[1] + tVec[3] *
x;
110 if(hitXErr[iht] > 0) {
111 wght = 1 / hitXErr[iht];
115 if(wght <= 0) wght = 1;
116 diff = (ypr * cw + zpr * sw - (hitWID[iht].Wire - off)) / wght;
117 ChiDOF += diff * diff;
123 ChiDOF /= (double)(npts - 4);
125 double norm = sqrt(1 + tVec[2] * tVec[2] + tVec[3] * tVec[3]);
127 Dir[1] = tVec[2] /
norm;
128 Dir[2] = tVec[3] /
norm;
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
void TrkLineFit(std::vector< geo::WireID > &hitWID, std::vector< double > &hitX, std::vector< double > &hitXErr, double XOrigin, TVector3 &Pos, TVector3 &Dir, float &ChiDOF)
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
virtual ~TrackLineFitAlg()
art::ServiceHandle< geo::Geometry > geom