lcsim/src/org/lcsim/fit/zsegment
diff -u -r1.1 -r1.2
--- ZSegmentFitter.java 1 Aug 2007 20:54:42 -0000 1.1
+++ ZSegmentFitter.java 29 Nov 2007 19:49:10 -0000 1.2
@@ -63,7 +63,7 @@
_centroid[1] = 0.;
_area = 0.;
_covariance = null;
-// Check that the input values are sensible
+// Check that the input values are sensible
if (_s.length!=_zmin.length) return false;
if (_s.length!=_zmax.length) return false;
if (_s.length<2) return false;
@@ -90,7 +90,7 @@
}
// Check that we have at least 3 polygon vertices - fewer vertices indicates that the
-// pecified z segments are not consistent with a straight line track in s-z space.
+// specified z segments are not consistent with a straight line track in s-z space.
int nv = _polygon.size();
if (nv<3) return false;
@@ -111,7 +111,7 @@
_centroid[0] /= 3*_area;
_centroid[1] /= 3*_area;
_area = Math.abs(_area);
-
+
// Calculate the covariance matrix for this polygon
_covariance = PolygonCovariance();
@@ -131,7 +131,7 @@
if (zpred<_zmin[i]-eps || zpred>_zmax[i]+eps ) return;
}
-// See if this intersection duplicates one we have previously found
+// See if this intersection duplicates one we have previously found
for (double[] old_cross : _polygon) {
if (Math.pow(cross[0]-old_cross[0],2)+Math.pow(cross[1]-old_cross[1],2)<Math.pow(eps,2)) return;
}
@@ -145,8 +145,8 @@
double[] pcent = PseudoCentroid();
int nv = _polygon.size();
for (int i=0; i<nv-1; i++) {
+ double phi1 = Math.atan2(_polygon.get(i)[1]-pcent[1],_polygon.get(i)[0]-pcent[0]);
for (int j=i+1; j<nv; j++) {
- double phi1 = Math.atan2(_polygon.get(i)[1]-pcent[1],_polygon.get(i)[0]-pcent[0]);
double phi2 = Math.atan2(_polygon.get(j)[1]-pcent[1],_polygon.get(j)[0]-pcent[0]);
if (phi1>phi2) {
double[] temp = _polygon.get(j);
@@ -158,12 +158,12 @@
}
private double[] PseudoCentroid() {
- // Find a point within the convex polygon by averaging the coordinates of all vertices
+ // Find a point within the convex polygon by averaging the coordinates of all vertices
double[] pcent = {0.,0.};
int nv = _polygon.size();
for (double[] point : _polygon) {
- pcent[0]+=point[0]/nv;
- pcent[1]+=point[1]/nv;
+ pcent[0] += point[0]/ nv;
+ pcent[1] += point[1]/ nv;
}
return pcent;
}
@@ -186,8 +186,8 @@
vertices.setElement(1,0,_polygon.get(i)[1]-_centroid[1]);
vertices.setElement(0,1,_polygon.get(j)[0]-_centroid[0]);
vertices.setElement(1,1,_polygon.get(j)[1]-_centroid[1]);
-
-// Rotate these vertices to a new x',y' coordinate system where vertex 2 is on the x' axis
+
+// Rotate these vertices to a new x',y' coordinate system where vertex 2 is on the x' axis
double phi = Math.atan2(vertices.e(1,1),vertices.e(0,1));
BasicMatrix rotmat = new BasicMatrix(2,2);
rotmat.setElement(0,0,Math.cos(phi));
@@ -199,7 +199,7 @@
// Find the contributions to the covariance matrix for the triangle in the x',y' coordinate system. If
// the apex of the triangle is at (x'1,y'1), and the base of the triangle is at (0,0) and (x'2,0), then:
// A = 1/2 y'1 * x'2
-// Ix'x' = integral x'*x'*dA = A * (x'1**2 + x'1*x'2 + x'2**2) / 6
+// Ix'x' = integral x'*x'*dA = A * (x'1**2 + x'1*x'2 + x'2**2) / 6
// Ix'y' = integral x'*y'*dA = A * y'1 * (2*x'1 + x'2) / 12
// Iy'y' = integral y'*y'*dA = A * y'1**2 / 6
double darea = Math.abs(0.5*rotvert.e(1,0)*rotvert.e(0,1));
@@ -207,13 +207,13 @@
cov_loc.setElement(0,0,darea*(Math.pow(rotvert.e(0,0),2)+rotvert.e(0,0)*rotvert.e(0,1)+Math.pow(rotvert.e(0,1),2))/6.);
cov_loc.setElement(1,0,darea*rotvert.e(1,0)*(2.*rotvert.e(0,0)+rotvert.e(0,1))/12);
cov_loc.setElement(1,1,darea*Math.pow(rotvert.e(1,0),2)/6);
-
+
// Rotate the 2nd rank tensor back to the local coordinate system: v vT = RT * v' v'T R where R is the rotation matrix,
// v / v' are the (x,y) / (x',y') column vectors, and T indicates the transpose operator. Note that v' = R v and R RT = RT R = 1.
MutableMatrix rotbar = new BasicMatrix(2,2);
MatrixOp.transposed(rotmat,rotbar);
Matrix cov_glb = MatrixOp.mult(rotbar,MatrixOp.mult(cov_loc,rotmat));
-
+
// Add the covariance contribution for this triangle to the polygon sum (note - we need a matrix add operation in freehep !!)
cxx += cov_glb.e(0,0);
cxy += cov_glb.e(1,0);