Commit in lcsim/src/org/lcsim/recon/vertexing/zvtop4 on MAIN
ZvUtil.java+7-61.10 -> 1.11
ZvTop.java+91-821.14 -> 1.15
ZvSwimmer.java+21-151.11 -> 1.12
ZvVertex.java+26-31.2 -> 1.3
ZvFitter.java+37-321.15 -> 1.16
+182-138
5 modified files
Starting to prepare both ZvFitter and ZvVertex to just use Tracks, not ZvTracks. ZvSwimmer is to be obsoleted

lcsim/src/org/lcsim/recon/vertexing/zvtop4
ZvUtil.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- ZvUtil.java	2 Aug 2005 17:55:23 -0000	1.10
+++ ZvUtil.java	16 Aug 2005 19:52:04 -0000	1.11
@@ -51,7 +51,6 @@
     private static SpacePoint parabolaPocaTwoTrackMax(ZvTrack iTrack, ZvTrack jTrack) {
         SpacePoint maxLocation = new SpacePoint();
         // limit the region where to look to the vertex detector.
-        // FIXME look at the real dimensions
         final double maxRad = 50;
         final double maxZ = 150;
         final int maxStep = 1000;
@@ -137,12 +136,14 @@
     /**
      * calculate p/tangent unit vector
      */
-    public static Hep3Vector getUnitTangent(ZvParameters hlxPar)
+    public static Hep3Vector getUnitTangent(double[] hlxPar)
     {
-        double norm = Math.sqrt(1.+hlxPar.tanLambda*hlxPar.tanLambda);
-        double x = Math.cos(hlxPar.phi)/norm;
-        double y = Math.sin(hlxPar.phi)/norm;
-        double z = hlxPar.tanLambda/norm;
+        int tanLambda = Track.ParameterName.s.ordinal();
+        int phi = Track.ParameterName.phi0.ordinal();
+        double norm = Math.sqrt(1.+hlxPar[tanLambda]*hlxPar[tanLambda]);
+        double x = Math.cos(hlxPar[phi])/norm;
+        double y = Math.sin(hlxPar[phi])/norm;
+        double z = hlxPar[tanLambda]/norm;
         return new BasicHep3Vector(x, y, z);
     }
     // conversion constant 

lcsim/src/org/lcsim/recon/vertexing/zvtop4
ZvTop.java 1.14 -> 1.15
diff -u -r1.14 -r1.15
--- ZvTop.java	10 Aug 2005 07:30:32 -0000	1.14
+++ ZvTop.java	16 Aug 2005 19:52:04 -0000	1.15
@@ -31,8 +31,8 @@
 
 // TODO think about implementation in terms of static members
 /**
- * Main class to handle the vertexing
- * Vertices are found by the function
+ * Main class to handle the vertexing Vertices are found by the function
+ * 
  * @see #findVertices(List)
  * @author jstrube
  */
@@ -46,55 +46,58 @@
     // has an effect on many of the other classes
     // Special weight for the IP in the overlap function
     private double ipWeight = 1;
-    // Special weight for the angle of the spatial point (argument of overlap) 
+    // Special weight for the angle of the spatial point (argument of overlap)
     // wrt. the jet axis
     private double angularWeight = 10;
     private double resolvedCut = 0;
     private double chiSquareCut = 0;
     private double _maxDistFromIP = 25;
-    //  Number of points to check along the line from point 1 to point 2
+    // Number of points to check along the line from point 1 to point 2
     int iterationMax = 3000;
-    
+
     private double sigmaT;
     private double sigmaL;
-    
-    
+
     public void setMaxDistFromIP(double d) {
         _maxDistFromIP = d;
     }
-    
+
     public void setIpWeight(double w) {
         ipWeight = w;
     }
-    
+
     public void setAngularWeight(double w) {
         angularWeight = w;
     }
-    
+
     public void setResolvedCut(double c) {
         resolvedCut = c;
     }
-    
+
     public void setChiSquareCut(double c) {
         chiSquareCut = c;
     }
-    
+
     private Hep3Vector _jetAxis;
-    //  resolution function is expensive in CPU    
+    // resolution function is expensive in CPU
     private Map<ZvMaximum, Set<ZvMaximum>> isResolvedFromMap;
     private Map<ZvMaximum, Set<ZvMaximum>> unresolvedMaximaMap;
-    
+
     // List of vertex candidates.
-    // The two-track maxima are transformed to the nearest location of a maximum in the overlap function.
-    // The highest of those maxima is taken as the location of the vertex and all tracks belonging to ZvMaxima that are unresolved from this highest maximum are added to the vertex.
+    // The two-track maxima are transformed to the nearest location of a maximum
+    // in the overlap function.
+    // The highest of those maxima is taken as the location of the vertex and
+    // all tracks belonging to ZvMaxima that are unresolved from this highest
+    // maximum are added to the vertex.
     // At this stage tracks can be assigned to more than one vertex.
-    // The fitVertices function takes care of assigning tracks uniquely to a vertex.
+    // The fitVertices function takes care of assigning tracks uniquely to a
+    // vertex.
     // TODO need to distinguish between pruning and fitting
     private List<ZvVertex> _vertexCandidateList;
-    
+
     /**
      * @author jstrube
-     *
+     * 
      */
     class MaxComp implements Comparator {
 
@@ -106,7 +109,9 @@
             // TODO Auto-generated constructor stub
         }
 
-        /* (non-Javadoc)
+        /*
+         * (non-Javadoc)
+         * 
          * @see java.util.Comparator#compare(T, T)
          */
         public int compare(Object arg1, Object arg2) {
@@ -124,11 +129,11 @@
         }
 
     }
-    
+
     /**
-     * Constructor
-     * Creates a list of ZvTracks from the argument list.
-     * Calculates the overlap and resolution functions for the tracks
+     * Constructor Creates a list of ZvTracks from the argument list. Calculates
+     * the overlap and resolution functions for the tracks
+     * 
      * @param jetAxisValue
      */
     public ZvTop(Hep3Vector jetAxisValue, ZvFitter f) {
@@ -144,23 +149,24 @@
         vtxFitter = f;
         return;
     }
-      
+
     /**
      * Finds the Maxima
+     * 
      * @param list
      * @return
      */
     public List<ZvVertex> findVertices(List<Track> list) {
         trackList.clear();
         System.err.println("entering findVertives\n");
-//         FIXME Put in IP as constraint. At the moment, no vertex contains IP        
+        // FIXME Put in IP as constraint. At the moment, no vertex contains IP
         for (Track iTrack : list) {
             trackList.add(new ZvTrack(iTrack));
         }
         int size = trackList.size();
-        for (int i=0; i<size; ++i) {
+        for (int i = 0; i < size; ++i) {
             ZvTrack iTrack = trackList.get(i);
-            for (int j=i+1; j<size; ++j) {
+            for (int j = i + 1; j < size; ++j) {
                 ZvTrack jTrack = trackList.get(j);
                 SpacePoint location = twoTrackMax(iTrack, jTrack);
                 double overlap = overlap(location);
@@ -174,13 +180,14 @@
         System.err.println("done findVertices\n");
         return fitVertices();
     }
-      
+
     /**
-     * Calculates the global overlap at a given point in space
-     * The global overlap is the sum S of all track tubes minus
-     * the sum of the squares of the track tubes divided by S 
+     * Calculates the global overlap at a given point in space The global
+     * overlap is the sum S of all track tubes minus the sum of the squares of
+     * the track tubes divided by S
+     * 
      * @param location The point in space at which to evaluate the function
-     * @return The value at that point 
+     * @return The value at that point
      */
     public double overlap(SpacePoint location) {
         double numerator = 0;
@@ -193,39 +200,42 @@
         vec2Location.setEndPoint(location);
         vec2Location.setOrigin(new CartesianPoint(origin[0], origin[1], origin[2]));
         double angle = angle(_jetAxis, vec2Location);
-        double angularFactor = Math.exp(-angularWeight*angle*angle);
+        double angularFactor = Math.exp(-angularWeight * angle * angle);
         if (dot(unit(_jetAxis), vec2Location) > _maxDistFromIP) {
             return 0;
         }
-        // FIXME dealing with IP 
-        double ipFactor = 0; //ipWeight * trackList.get(0).getTubeValue(location);
+        // FIXME dealing with IP
+        double ipFactor = 0; // ipWeight *
+        // trackList.get(0).getTubeValue(location);
         denominator += ipFactor;
-        numerator += 0; //ipFactor * trackList.get(0).getTubeValue(location);
-        for (int i=0; i<trackList.size(); ++i) {
+        numerator += 0; // ipFactor * trackList.get(0).getTubeValue(location);
+        for (int i = 0; i < trackList.size(); ++i) {
             ZvTrack iTrack = trackList.get(i);
             double iTubeVal = iTrack.getTubeValue(location);
-            numerator += iTubeVal*iTubeVal;
+            numerator += iTubeVal * iTubeVal;
             denominator += iTubeVal;
         }
-        return angularFactor * (denominator - numerator/denominator);
+        return angularFactor * (denominator - numerator / denominator);
     }
-    
+
     /**
-     * Calculates the resolution for two points in space.
-     * Two points in space are resolved, if the maximum overlap along the line
-     * that connects them divided by the greater of the overlap values at the two points
-     * is less than a cutoff value R0
+     * Calculates the resolution for two points in space. Two points in space
+     * are resolved, if the maximum overlap along the line that connects them
+     * divided by the greater of the overlap values at the two points is less
+     * than a cutoff value R0
+     * 
      * @param sp1 point 1
      * @param sp2 point 2
-     * @return true, if the resolution function is less than the cutoff, false otherwise
+     * @return true, if the resolution function is less than the cutoff, false
+     *         otherwise
      */
     public boolean areResolved(SpacePoint sp1, SpacePoint sp2) {
         double minOverlap = 0;
         // TODO conversion SpacePoint Hep3Vector :-(
         Hep3Vector vec = subtract(sp2, sp1);
         Hep3Vector toSp1 = new BasicHep3Vector(sp1.x(), sp1.y(), sp1.z());
-        for (int i=1; i<iterationMax; ++i) {
-            Hep3Vector rVec = add(toSp1, multiply(vec, i/3000));
+        for (int i = 1; i < iterationMax; ++i) {
+            Hep3Vector rVec = add(toSp1, multiply(vec, i / 3000));
             SpacePoint r = new CartesianPoint(rVec.x(), rVec.y(), rVec.z());
             double overlap = overlap(r);
             if (overlap < minOverlap)
@@ -233,14 +243,14 @@
         }
         double overlap1 = overlap(sp1);
         double overlap2 = overlap(sp2);
-        if (overlap1<minOverlap)
+        if (overlap1 < minOverlap)
             minOverlap = overlap1;
         if (overlap2 < minOverlap)
             minOverlap = overlap2;
         // overall minimum / min(overlap1, overlap2) < resolvedCut ?
         return minOverlap / ((overlap2 < overlap1) ? overlap2 : overlap1) < resolvedCut;
     }
-    
+
     /**
      * Calculates for each ZvMaximum whether of not it is resolved from other
      * ZvMaxima. Fills two maps to cache those values. Each ZvMaximum is mapped
@@ -263,11 +273,10 @@
             unresolvedMaximaMap.put(iMax, isNotResolvedFromImax);
         }
     }
-    
+
     /**
-     * Transforms each of the maxima in the two-track overlap 
-     * to the nearest global maximum in V(r).
-     * Finds the global maxima first.
+     * Transforms each of the maxima in the two-track overlap to the nearest
+     * global maximum in V(r). Finds the global maxima first.
      */
     // TODO maybe the maxima don't even have to be transformed
     // TODO the sequence of for-loops is a little clumsy
@@ -288,7 +297,7 @@
             // for every direction: go in positive direction,
             // reset to initial position and go in negative direction
             // +x
-            for (int x=1; x<=maxSteps; ++x) {
+            for (int x = 1; x <= maxSteps; ++x) {
                 xPos += xyStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -302,7 +311,7 @@
             }
             xPos = iMax.getLocation().x();
             // -x
-            for (int x=1; x<=maxSteps; ++x) {
+            for (int x = 1; x <= maxSteps; ++x) {
                 xPos -= xyStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -316,7 +325,7 @@
             }
             xPos = maxPoint.x();
             // +y
-            for (int y=1; y<=maxSteps; ++y) {
+            for (int y = 1; y <= maxSteps; ++y) {
                 yPos += xyStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -330,7 +339,7 @@
             }
             yPos = iMax.getLocation().y();
             // -y
-            for (int y=1; y<=maxSteps; ++y) {
+            for (int y = 1; y <= maxSteps; ++y) {
                 yPos -= xyStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -344,7 +353,7 @@
             }
             yPos = maxPoint.y();
             // +z
-            for (int z=1; z<=maxSteps; ++z) {
+            for (int z = 1; z <= maxSteps; ++z) {
                 zPos += zStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -358,7 +367,7 @@
             }
             zPos = iMax.getLocation().z();
             // -z
-            for (int z=1; z<=maxSteps; ++z) {
+            for (int z = 1; z <= maxSteps; ++z) {
                 zPos -= zStep;
                 searchPoint = new CartesianPoint(xPos, yPos, zPos);
                 double overlap = overlap(searchPoint);
@@ -372,25 +381,25 @@
             }
             iMax.setLocation(maxPoint);
         }
-        
+
     }
-    
+
     /**
-     * Creates a list of Vertex candidates.
-     * Each candidate consists of a number of track-IP overlaps
-     * that are not spatially resolved.
-     * The assignment is unique in the sense that each overlap is assigned 
-     * to exactly one candidate. 
+     * Creates a list of Vertex candidates. Each candidate consists of a number
+     * of track-IP overlaps that are not spatially resolved. The assignment is
+     * unique in the sense that each overlap is assigned to exactly one
+     * candidate.
      */
     private void clusterCandidates() {
         System.err.println("entering clusterCandidates");
         SortedSet<ZvMaximum> isAvailable = new TreeSet<ZvMaximum>(maximumMatrix.getMaxima());
         // each cluster consists of several ZvMaxima
-        // add the maximum and the set of unresolved maxima to the list of candidates
+        // add the maximum and the set of unresolved maxima to the list of
+        // candidates
         // __is__ already sorted by overlap value
-        while (! isAvailable.isEmpty()) {
+        while (!isAvailable.isEmpty()) {
             ZvMaximum highestRemaining = isAvailable.first();
-            Set<ZvMaximum> unresolvedSet = unresolvedMaximaMap.get(highestRemaining);            
+            Set<ZvMaximum> unresolvedSet = unresolvedMaximaMap.get(highestRemaining);
             unresolvedSet.add(highestRemaining);
             ZvVertex vtx = new ZvVertex(highestRemaining.getLocation(), unresolvedSet);
             _vertexCandidateList.add(vtx);
@@ -399,22 +408,22 @@
         System.err.println("done clusterCandidates");
         return;
     }
-    
+
     /**
-     * fits the tracks to the vertices.
-     * A ZvVertex can only have tracks with a chi2 contribution
-     * below a certain cut value.
-     * They are assigned from a sorted set of maxima, so that the tracks are
-     * always assigned to the vertex with the highest value of V(r), if possible
+     * fits the tracks to the vertices. A ZvVertex can only have tracks with a
+     * chi2 contribution below a certain cut value. They are assigned from a
+     * sorted set of maxima, so that the tracks are always assigned to the
+     * vertex with the highest value of V(r), if possible
+     * 
      * @return A List of Vertices
      */
     private List<ZvVertex> fitVertices() {
         List<ZvVertex> l = new ArrayList<ZvVertex>();
         Set<ZvTrack> unavailableTracks = new HashSet<ZvTrack>();
         System.err.printf("found %d Candidates\n", _vertexCandidateList.size());
-        for (ZvVertex iCand : _vertexCandidateList) {
-            System.err.printf(iCand.toString());
-        }
+        for (ZvVertex iCand : _vertexCandidateList) {
+            System.err.printf(iCand.toString());
+        }
         // The Maxima are clustered according to the resolution function
         // A Cluster is a Set of ZvMaxima
         // Add all tracks from a cluster to the vertex
@@ -426,10 +435,10 @@
                 iVtx.removeTrack(t);
             }
             ZvFitStatus status = vtxFitter.doFit(iVtx);
-            // TODO fit the vertex, make sure the tracks in the vertex
-            // are below the chi2 cut, so that at any time only good tracks are in the
+            // TODO fit the vertex, make sure the tracks in the vertex are below
+            // the chi2 cut, so that at any time only good tracks are in the
             // vertex
-            if (! iVtx.getFitStatus().isOK()) {
+            if (!iVtx.getFitStatus().isOK()) {
                 System.err.printf("FitStatus is: %s\n", status);
             }
             l.add(iVtx);

lcsim/src/org/lcsim/recon/vertexing/zvtop4
ZvSwimmer.java 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- ZvSwimmer.java	12 Aug 2005 03:09:05 -0000	1.11
+++ ZvSwimmer.java	16 Aug 2005 19:52:04 -0000	1.12
@@ -5,7 +5,9 @@
 
 import hep.physics.vec.BasicHep3Vector;
 import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
 
+import org.lcsim.event.Track;
 import org.lcsim.geometry.Detector;
 import org.lcsim.spacegeom.CartesianPoint;
 import org.lcsim.spacegeom.SpacePoint;
@@ -75,12 +77,12 @@
      * @param targetPosition the point in space where to swim the track
      * @return a ZvFitStatus object to determine if the action was successful
      */
-    public ZvFitStatus swimTo(ZvTrack track, SpacePoint targetPosition) {
+    public ZvFitStatus swimTo(Track track, SpacePoint targetPosition) {
         Hep3Vector orgBField = new BasicHep3Vector(detector.getFieldMap().getField(track.getReferencePoint()));
-        Hep3Vector orgTangent = getUnitTangent(track.zvParameters());
+        Hep3Vector orgTangent = getUnitTangent(track.getTrackParameters());
         Hep3Vector orgNormal = cross(orgTangent, orgBField);
         ZvFitStatus status = ZvFitStatus.FAILED_ON_ENTRY; 
-        ZvParameters orgParameters = new ZvParameters(track.zvParameters());
+        Track.Parameters orgParameters = new Track.Parameters(track.getTrackParameters());
         Matrix orgErrorMatrix = new Matrix(track.getErrorMatrix());
         
         // FIXME detector radius
@@ -90,13 +92,14 @@
             return ZvFitStatus.POS_OUT_OF_VOLUME;
 
         // get track parameters and error matrix
-        ZvParameters hlxPar = track.zvParameters();
+        double[] hlxPar = track.getTrackParameters();
         double[][] dHlxPar = track.getErrorMatrix();
         
         double charge = track.getCharge();
         double sgnq = charge / Math.abs(charge);
 
-        double pTot = track.momentum().magnitude();
+        // FIXME cast from double to BasicHep3Vector
+        double pTot = new BasicHep3Vector(track.getMomentum()).magnitude();
 
         // TODO
 //        ZvHelixVec hlxVec = new ZvHelixVec(hlxPar);
@@ -163,15 +166,18 @@
         } while (Math.abs(f) > stepMin); // master loop
 
         // recalculate helix parameters
-        hlxPar.phi = Math.atan2(tangentUnit.y(), tangentUnit.x());
-        if (hlxPar.phi < 0)
-            hlxPar.phi += 2. * Math.PI; // phi
+        int phi0 = Track.ParameterName.phi0.ordinal();
+        int tanLambda = Track.ParameterName.s.ordinal();
+        hlxPar[phi0] = Math.atan2(tangentUnit.y(), tangentUnit.x());
+        if (hlxPar[phi0] < 0)
+            hlxPar[phi0] += 2. * Math.PI; // phi
+        // FIXME these parameters are screwed up for sure, ZvSwimmer is to be obsoleted anyway
         double cosL = Math.sqrt(1. - tangentUnit.z() * tangentUnit.z());
-        hlxPar.kappa = 1. / (pTot * cosL); // kappa
-        hlxPar.tanLambda = tangentUnit.z() / cosL; // tan(lambda)
-        hlxPar.x  = vCurPos.x(); // x
-        hlxPar.y = vCurPos.y(); // y
-        hlxPar.z = vCurPos.z(); // z
+        hlxPar[2] = 1. / (pTot * cosL); // kappa
+        hlxPar[tanLambda] = tangentUnit.z() / cosL; // tan(lambda)
+        hlxPar[4]  = vCurPos.x(); // x
+        hlxPar[5] = vCurPos.y(); // y
+        hlxPar[6] = vCurPos.z(); // z
 
         // check current position
         if ( vCurPos.rxy() > maxRadius || vCurPos.z() > maxZ )  
@@ -229,13 +235,13 @@
     // FIXME bad example of global variable
     static Hep3Vector globalpUnit;
     // TODO naming of vectors is obscure
-    private static SpacePoint leapToNewPosition(ZvTrack track
+    private static SpacePoint leapToNewPosition(Track track
             , double arcLen
             , SpacePoint xPosition
             , Hep3Vector tan
             , double pTot
             , double charge) {
-        Hep3Vector oldTangent = getUnitTangent(track.zvParameters());
+        Hep3Vector oldTangent = getUnitTangent(track.getTrackParameters());
         
         Hep3Vector tangentUnit = unit(tan);
         Hep3Vector bField = unit(detector.getFieldMap().getField(xPosition.getCartesianArray()));

lcsim/src/org/lcsim/recon/vertexing/zvtop4
ZvVertex.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- ZvVertex.java	10 Aug 2005 07:30:32 -0000	1.2
+++ ZvVertex.java	16 Aug 2005 19:52:04 -0000	1.3
@@ -9,6 +9,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.lcsim.event.Track;
 import org.lcsim.spacegeom.CartesianPoint;
 import org.lcsim.spacegeom.SpacePoint;
 
@@ -28,7 +29,7 @@
  * NOTE: An unfitted vertex can share tracks with another vertex !
  * TODO pruning <-> fitting
  * @author J. Strube
- * 
+ * @version
  */
 // -------------------------------------------------------------------------
 public class ZvVertex extends SpacePoint {
@@ -224,6 +225,17 @@
         return longDist;
     }
 
+    // FIXME ZvVertex doesn't need any ZvTracks, just regular tracks.
+    public void setVtxRawTracks(Collection<Track> tracks) {
+        for (Track iTrack : tracks) {
+            trackChi2Map.put(new ZvTrack(iTrack), 0.0);
+        }
+        this.sumQ = sumTrackCharge(trackChi2Map.keySet());
+        this.sumMom = sumTrackMomenta(trackChi2Map.keySet());
+        this.alphaDis = calcAlphaDis(xIP);
+        this.longDist = calcLongDist(xIP, direction);
+    }
+    
     /**
      * TODO needs to be improved wrt addVtxTrack
      * set assigned tracks as track list
@@ -286,6 +298,15 @@
         return trackChi2Map.containsKey(track);
     }
 
+    public boolean hasTrack(Track track) {
+        if (trackChi2Map == null)
+            return false;
+        for (ZvTrack iTrack : trackChi2Map.keySet()) {
+            if (iTrack.orgTrack == track)
+                return true;
+        }
+        return false;
+    }
     /**
      * set whether beam spot is in vertex <br>
      * default: false
@@ -411,8 +432,10 @@
     }
 
     // TODO this better works !
-    public void setTrackChi2(ZvTrack track, double value) {
-        trackChi2Map.put(track, value);
+    // FIXME check for duplication
+    // FIXME ZvTrack cast
+    public void setTrackChi2(Track track, double value) {
+        trackChi2Map.put(new ZvTrack(track), value);
     }
     
     void removeTrack(ZvTrack t) {

lcsim/src/org/lcsim/recon/vertexing/zvtop4
ZvFitter.java 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- ZvFitter.java	2 Aug 2005 17:55:23 -0000	1.15
+++ ZvFitter.java	16 Aug 2005 19:52:04 -0000	1.16
@@ -14,6 +14,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.lcsim.event.Track;
 import org.lcsim.geometry.Detector;
 import org.lcsim.geometry.FieldMap;
 import org.lcsim.spacegeom.CartesianPoint;
@@ -26,7 +27,7 @@
  * Fitter class based on a least squares method
  * 
  * @author W.Walkowiak, 09/18/00
- * @version $Id: ZvFitter.java,v 1.15 2005/08/02 17:55:23 jstrube Exp $
+ * @version $Id: ZvFitter.java,v 1.16 2005/08/16 19:52:04 jstrube Exp $
  */
 
 /* TODO static members only
@@ -150,7 +151,11 @@
 
         // the outer loop
         ZvVertex fittedVertex = vtx;
-        Set<ZvTrack> trackList = new HashSet<ZvTrack>(vtx.getVtxTracks());
+        Set<Track> trackList = new HashSet<Track>();
+        for (ZvTrack iTrack : vtx.getVtxTracks()) {
+            trackList.add(iTrack.orgTrack);
+        }
+        
         int iter = 0;
         double dis = 99999.;
         // TODO make nicer loop
@@ -175,7 +180,8 @@
             status = ZvFitStatus.OK;
 
         // prepare fittedVertex for output
-        fittedVertex.setVtxTracks(trackList);
+        // FIXME this adds the tracks with a chi2 of 0
+        fittedVertex.setVtxRawTracks(trackList);
         fittedVertex.setFitStatus(status);
 
         return status;
@@ -186,7 +192,7 @@
      * private methods
      * --------------------------------------------------------------------
      */
-    private ZvVertex findVertex(Set<ZvTrack> trackList, SpacePoint location,
+    private ZvVertex findVertex(Set<Track> trackList, SpacePoint location,
             Matrix error) {
         double[] viVtxErr = new double[]{error.get(1, 1), error.get(2, 2), error.get(3, 3)};
         // preset result to null
@@ -198,7 +204,7 @@
         Hep3Vector[] tKsi = new Hep3Vector[nTrk];
         Hep3Vector[] tEta = new Hep3Vector[nTrk];
         SpacePoint[] tDee = new SpacePoint[nTrk];
-        ZvParameters[] trackParameters = new ZvParameters[nTrk];
+        Track.Parameters[] trackParameters = new Track.Parameters[nTrk];
         double[][] tA0 = new double[nTrk][5];
         Matrix[] tHml = new Matrix[nTrk];
         Matrix[] tQml = new Matrix[nTrk];
@@ -208,25 +214,22 @@
 
         // setup loop I
         // TODO howto modify inplace ?
-        ZvTrack[] trackArray = trackList.toArray(new ZvTrack[0]);
+        Track[] trackArray = trackList.toArray(new Track[0]);
         SpacePoint vR0 = new SpacePoint();
         Matrix mR0Err = new Matrix(3, 3, 0.);
         for (int i = 0; i < nTrk; i++) {
-            ZvTrack track = trackArray[i];
+            Track track = trackArray[i];
             // reswim track, if necessary
             // TODO move swimTo into HelicalSwimmer
             // TODO optimizing inserts
-            if (subtract(location, track.referencePoint()).magnitude() > swimDistMin) {
+            // FIXME SpacePoint cast
+            if (subtract(location, new CartesianPoint(track.getReferencePoint())).magnitude() > swimDistMin) {
                 if (! trackList.remove(track)) {
                     System.err.println("Could not remove element");
                 }
-                ZvTrack orgTrack = new ZvTrack(track);
-                trackList.add(orgTrack);
+                trackList.add(track);
                 ZvFitStatus swimStatus = swimmer.swimTo(track, location);
-                if (swimStatus.success()) {
-                    trackList.remove(orgTrack);
-                    trackList.add(track);
-                } else {
+                if (! swimStatus.success()) {
                     System.out.println("SwimStatus is (in ZvFitter): " + swimStatus);
                     status = ZvFitStatus.SWIM_FAILURE;
                     return vertex;
@@ -236,12 +239,13 @@
             // TODO trackParameters !
             // TODO What the heck are those deleted for ???
             // --> see later: Error Matrix
-            trackParameters[i] = new ZvParameters(track.zvParameters());
-            trackParameters[i].phi = 0.;
-            trackParameters[i].kappa = 0.;
-            trackParameters[i].tanLambda = 0.;
+            trackParameters[i] = new Track.Parameters(track.getTrackParameters());
+            trackParameters[i].phi0 = 0.;
+            trackParameters[i].omega = 0.;
+            trackParameters[i].s = 0.;
             
-            tDee[i] = track.referencePoint();
+            // FIXME SpacePoint cast
+            tDee[i] = new CartesianPoint(track.getReferencePoint());
                 
             // create unit vectors
             // TODO Horrible !!!
@@ -249,7 +253,7 @@
             double[] bb = detector.getFieldMap().getField(where);
             Hep3Vector vmUnit = unit(new BasicHep3Vector(bb[0], bb[1], bb[2]));
             {
-                Hep3Vector x = unit(track.momentum());
+                Hep3Vector x = unit(track.getMomentum());
                 Hep3Vector vpUnit = new BasicHep3Vector(x.x(), x.y(), x.z());
                 Hep3Vector vnbUnit = unit(cross(x, vmUnit));
             
@@ -275,9 +279,10 @@
         for (int i = 0; i < nTrk; i++) {
             Hep3Vector vDel = subtract(vR0, tDee[i]);
             // TODO make sure components are correct
-            tA0[i][0] = trackParameters[i].get(ZvParameterNames.phi);
-            tA0[i][1] = trackParameters[i].get(ZvParameterNames.kappa);
-            tA0[i][2] = trackParameters[i].get(ZvParameterNames.s);
+            tA0[i][0] = trackParameters[i].get(Track.ParameterName.phi0);
+            // FIXME this used to be kappa...
+            tA0[i][1] = trackParameters[i].get(Track.ParameterName.omega);
+            tA0[i][2] = trackParameters[i].get(Track.ParameterName.s);
             tA0[i][3] = dot(vDel, tKsi[i]);
             tA0[i][4] = dot(vDel, tEta[i]);
         }
@@ -303,21 +308,21 @@
             // Chi2 vector w
             Matrix mW = new Matrix(3 * nTrk + 3, 1, 0.);
             for (int i = 0; i < nTrk; i++) {
-                ZvParameters trackParms = trackParameters[i];
+                Track.Parameters trackParms = trackParameters[i];
                 for (int j = 0; j < 3; j++) {
                     double sum = 0;
                     for (int k = 0; k < 5; k++)
                         // TODO cache names
-                        sum += (trackParms.get(ZvParameterNames.values()[k]) - tA0[i][k]) * tHml[i].get(k, j);
+                        sum += (trackParms.get(Track.ParameterName.values()[k]) - tA0[i][k]) * tHml[i].get(k, j);
                     mW.set(3 * i + j, 0, sum);
                 }
             }
             for (int j = 0; j < 3; j++) {
                 double sum = 0.;
                 for (int i = 0; i < nTrk; i++) {
-                    ZvParameters trackParms = trackParameters[i];
+                    Track.Parameters trackParms = trackParameters[i];
                     for (int k = 0; k < 5; k++)
-                        sum += (trackParms.get(ZvParameterNames.values()[k]) - tA0[i][k])
+                        sum += (trackParms.get(Track.ParameterName.values()[k]) - tA0[i][k])
                                 * (tHml[i].get(k, 3) * tKsi[i].v()[j] + tHml[i].get(k, 4)
                                         * tEta[i].v()[j]);
                 }
@@ -378,12 +383,12 @@
             totChi2 = 0.;
             for (int n = 0; n < nTrk; n++) {
                 trkChi2[n] = 0.;
-                ZvParameters trackParms = trackParameters[n];
+                Track.Parameters trackParms = trackParameters[n];
                 for (int i = 0; i < 5; i++)
                     for (int j = 0; j < 5; j++)
                         // TODO cache names
-                        trkChi2[n] += (trackParms.get(ZvParameterNames.values()[i]) - tA0[n][i]) * tHml[n].get(i, j)
-                                * (trackParms.get(ZvParameterNames.values()[j]) - tA0[n][j]);
+                        trkChi2[n] += (trackParms.get(Track.ParameterName.values()[i]) - tA0[n][i]) * tHml[n].get(i, j)
+                                * (trackParms.get(Track.ParameterName.values()[j]) - tA0[n][j]);
                 totChi2 += trkChi2[n];
             }
             // add contribution of initial vertex constraint
@@ -424,9 +429,9 @@
         // problem: iterate over two lists simultaneously
         // solution: Don't need so many loops -> make local variable in loop
         // reswim tracks to r0
-        ZvTrack[] trackArray2 = trackList.toArray(new ZvTrack[0]);
+        Track[] trackArray2 = trackList.toArray(new Track[0]);
         for (int i = 0; i < nTrk; i++) {
-            ZvTrack track = trackArray2[i];
+            Track track = trackArray2[i];
             ZvFitStatus swimStatus = swimmer.swimTo(track, vR0);
 
             if (! swimStatus.success()) {
CVSspam 0.2.8