Commit in lcsim on MAIN
src/org/lcsim/contrib/JanStrube/standalone/TrackComparison.java+46added 1.1
                                          /PrimaryParticleDaughterFitter.java+56added 1.1
                                          /PrimaryParticleFinder.java+31added 1.1
                                          /MainLoop.java+6-41.3 -> 1.4
                                          /FitterTestDriver_ReconTrack.java+44-271.1 -> 1.2
                                          /FitterTestDriver.java+10-101.2 -> 1.3
                                          /.cvsignore+21.1 -> 1.2
src/org/lcsim/spacegeom/SpacePoint.java+4-71.7 -> 1.8
                       /CartesianVector.java+5-21.2 -> 1.3
                       /CartesianPoint.java+2-31.5 -> 1.6
src/org/lcsim/contrib/JanStrube/vtxFitter/Fitter.java+225-2381.10 -> 1.11
                                         /Vertex.java+29-21.4 -> 1.5
                                         /vertexing.lyx+19-501.8 -> 1.9
                                         /vertexing.pdf[binary]1.4 -> 1.5
src/org/lcsim/contrib/JanStrube/tracking/Track.java+15-11.3 -> 1.4
                                        /NewTrack.java+9-11.6 -> 1.7
test/org/lcsim/contrib/JanStrube/tracking/FitterTest.java+8-71.2 -> 1.3
+511-352
3 added + 14 modified, total 17 files
various updates:
proper derivation of the unit conversion constant
adding a setter for the convergence criterion to the fitter
correcting the convergence criterion
Adding plots to the testcase
un-deprecating some spacegeom to double conversion. I don't think anybody cared in the first place and sometimes it is actually quite useful. Spacegeom is inherently safer than hepvector anyways, so it shouldn't be a problem.
Starting on a test to compare ReconTrack with NewTrack. Trying to use the Fitter with NewTracks fails, because the Lookuptable chokes... This needs to be investigated.

lcsim/src/org/lcsim/contrib/JanStrube/standalone
TrackComparison.java added at 1.1
diff -N TrackComparison.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackComparison.java	29 Aug 2006 19:50:18 -0000	1.1
@@ -0,0 +1,46 @@
+/**
+ * @version $Id: TrackComparison.java,v 1.1 2006/08/29 19:50:18 jstrube Exp $
+ */
+
+
+import hep.physics.particle.Particle;
+import hep.physics.vec.Hep3Vector;
+
+import org.lcsim.contrib.JanStrube.tracking.NewFastMCTrackFactory;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.Track;
+import org.lcsim.mc.fast.tracking.MCFastTracking;
+import org.lcsim.mc.fast.tracking.ReconTrack;
+import org.lcsim.spacegeom.CartesianPoint;
+import org.lcsim.spacegeom.SpacePoint;
+import org.lcsim.util.Driver;
+
+import Jama.Matrix;
+
+/**
+ * Compares the New FastMC Tracks to the information in RecoTrack
+ * @author jstrube
+ *
+ */
+public class TrackComparison extends Driver {
+    public TrackComparison() {
+        add(new MCFastTracking(false, false));
+    }
+    public void process(EventHeader event) {
+        super.process(event);
+        System.out.println("processing...");
+        NewFastMCTrackFactory factory = new NewFastMCTrackFactory(event, false);
+        for (Track oldTrack : event.getTracks()) {
+            ReconTrack recoTrack = (ReconTrack) oldTrack;
+            Particle p = recoTrack.getMCParticle();
+            org.lcsim.contrib.JanStrube.tracking.Track newTrack = factory.getTrack(p.getMomentum(), p.getOrigin(), (int)p.getCharge());
+            System.out.printf("ReconTrack: %s\n", new Matrix(recoTrack.getErrorMatrix()));
+            SpacePoint p_recon = new SpacePoint(recoTrack.getMomentumVec());
+            SpacePoint p_newTrack = newTrack.getMomentum();
+            SpacePoint r_recon = new CartesianPoint(recoTrack.getReferencePoint());
+            SpacePoint r_newTrack = newTrack.getPosition();
+            System.out.printf("NewTrack: %s\n", newTrack.getErrorMatrix());
+        }
+    }
+}
+

lcsim/src/org/lcsim/contrib/JanStrube/standalone
PrimaryParticleDaughterFitter.java added at 1.1
diff -N PrimaryParticleDaughterFitter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PrimaryParticleDaughterFitter.java	29 Aug 2006 19:50:18 -0000	1.1
@@ -0,0 +1,56 @@
+/**
+ * @version $Id: PrimaryParticleDaughterFitter.java,v 1.1 2006/08/29 19:50:18 jstrube Exp $
+ */
+package org.lcsim.contrib.JanStrube.standalone;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import hep.physics.particle.Particle;
+
+import org.lcsim.contrib.JanStrube.tracking.NewFastMCTrackFactory;
+import org.lcsim.contrib.JanStrube.tracking.Track;
+import org.lcsim.contrib.JanStrube.vtxFitter.Fitter;
+import org.lcsim.contrib.JanStrube.vtxFitter.Vertex;
+import org.lcsim.event.EventHeader;
+import org.lcsim.spacegeom.SpacePoint;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+import Jama.Matrix;
+
+import static java.lang.Math.abs;
+import static java.lang.Math.sqrt;
+
+/**
+ * This Driver searches for an MCParticle in the event.
+ * It loops over all the daughter particles and creates FastMC Tracks.
+ * These are then fit and compared to the parent information
+ * @author jstrube
+ *
+ */
+public class PrimaryParticleDaughterFitter extends Driver {
+    AIDA aida = AIDA.defaultInstance();
+    
+    public PrimaryParticleDaughterFitter() {
+        
+    }
+    public void process(EventHeader event) {
+        Particle part = (Particle) event.get("primaryParticle");
+        List<Track> tracks = new ArrayList<Track>();
+        NewFastMCTrackFactory factory = new NewFastMCTrackFactory(event, false);
+        for (Object o : part.getDaughters()) {
+            Particle daughter = (Particle) o;
+            tracks.add(factory.getTrack(daughter.getMomentum(), daughter.getOrigin(), (int) daughter.getCharge()));
+        }
+        Fitter fitter = new Fitter(event);
+        Vertex vtx = fitter.fit(tracks, new SpacePoint());
+        SpacePoint p_org = new SpacePoint(part.getOrigin());
+        SpacePoint v_org = new SpacePoint(vtx.origin());
+        Matrix spatialError = vtx.getSpatialCovarianceMatrix();
+        
+        aida.cloud1D("pull_X").fill(abs(p_org.x()-v_org.x())/sqrt(spatialError.get(0, 0)));
+        aida.cloud1D("pull_Y").fill(abs(p_org.y()-v_org.z())/sqrt(spatialError.get(1, 1)));
+        aida.cloud1D("pull_Z").fill(abs(p_org.z()-v_org.y())/sqrt(spatialError.get(2, 2)));
+    }
+}

lcsim/src/org/lcsim/contrib/JanStrube/standalone
PrimaryParticleFinder.java added at 1.1
diff -N PrimaryParticleFinder.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PrimaryParticleFinder.java	29 Aug 2006 19:50:18 -0000	1.1
@@ -0,0 +1,31 @@
+/**
+ * @version $Id: PrimaryParticleFinder.java,v 1.1 2006/08/29 19:50:18 jstrube Exp $
+ */
+package org.lcsim.contrib.JanStrube.standalone;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.util.Driver;
+
+import static java.lang.Math.abs;
+
+/**
+ * This class finds a primary particle in the event and adds an entry to the event.
+ * To be used with PrimaryParticleFitter 
+ * @author jstrube
+ *
+ */
+public class PrimaryParticleFinder extends Driver {
+    int particle_id;
+    public PrimaryParticleFinder(int id) {
+        particle_id = id;
+    }
+    public void process(EventHeader event) {
+        for (MCParticle p : event.getMCParticles()) {
+            if (abs(p.getPDGID()) == particle_id) {
+                event.put("primaryParticle", p);
+                break;
+            }
+        }
+    }
+}

lcsim/src/org/lcsim/contrib/JanStrube/standalone
MainLoop.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- MainLoop.java	20 Aug 2006 05:56:56 -0000	1.3
+++ MainLoop.java	29 Aug 2006 19:50:18 -0000	1.4
@@ -28,12 +28,14 @@
       File trackFile = cache.getCachedFile(location);
       loop.setStdhepRecordSource(trackFile, "sidaug05");
 //      loop.setLCIORecordSource(input);
-      loop.add(new MCFast(false, false));
-//      loop.add(new FitterTestDriver());
-      loop.add(new FitterTestDriver_ReconTrack());
+//      loop.add(new MCFast(false, false));
+      loop.add(new FitterTestDriver());
+//      loop.add(new FitterTestDriver_ReconTrack());
 //      File output = new File("exampleAnalysisJava.slcio");
 //      loop.add(new LCIODriver(output));
-      loop.loop(-1);
+//      System.out.println("starting:");
+//      loop.add(new TrackComparison());
+      loop.loop(1000);
       loop.dispose();
       AIDA.defaultInstance().saveAs("exampleAnalysisJava.aida");
    }

lcsim/src/org/lcsim/contrib/JanStrube/standalone
FitterTestDriver_ReconTrack.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- FitterTestDriver_ReconTrack.java	27 Aug 2006 22:41:11 -0000	1.1
+++ FitterTestDriver_ReconTrack.java	29 Aug 2006 19:50:18 -0000	1.2
@@ -1,3 +1,5 @@
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Random;
 
 import org.lcsim.contrib.JanStrube.tracking.EMap;
@@ -10,21 +12,24 @@
 import org.lcsim.event.Track;
 import org.lcsim.mc.fast.tracking.ReconTrack;
 import org.lcsim.spacegeom.CartesianPoint;
+import org.lcsim.spacegeom.CartesianVector;
 import org.lcsim.spacegeom.SpacePoint;
+import org.lcsim.spacegeom.SpaceVector;
 import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
 
 import Jama.Matrix;
 
 import static java.lang.Math.abs;
+import static java.lang.Math.sqrt;
 
 class FitterTestDriver_ReconTrack extends Driver {
     private AIDA aida = AIDA.defaultInstance();
     private SpacePoint referencePoint;
     private SpacePoint origin;
     private Random rand;
-    private int count=0;
-    
+    private int count = 0;
+
     public FitterTestDriver_ReconTrack() {
         referencePoint = new CartesianPoint(0, 0, 0);
         origin = new CartesianPoint(0, 0, 0);
@@ -32,36 +37,48 @@
     }
 
     public void process(EventHeader event) {
-    	count++;
-    	if (count % 500 == 0)
-    		System.out.printf("Processing event %d\n", count);
+        count++ ;
+        if (count % 500 == 0)
+            System.out.printf("Processing event %d\n", count);
         // beamconstraint when smearing the tracks ?
         NewFastMCTrackFactory tf = new NewFastMCTrackFactory(event, false);
-        Vertex smearedVertex = new Vertex();
-        smearedVertex.setOrigin(origin);
         MCParticle mother = null;
         // K0: 310, J/Psi: 443
-	for (MCParticle p : event.getMCParticles()) {
-	   if (abs(p.getPDGID()) == 443) {
-        	mother = p;
-	    }
-	}
-       	for (Track t : event.getTracks()) {
-        	ReconTrack rt = (ReconTrack) t;
-        	MCParticle part = (MCParticle) rt.getMCParticle();
-        	
-        	SpacePoint org = new CartesianPoint(t.getReferencePoint());
-        	SpacePoint mom = new CartesianPoint(t.getMomentum());
-        	Matrix errors = new Matrix(t.getErrorMatrix());
-        	EMap parameters = NewTrack.SpaceMomentum2Parameters(org, mom, referencePoint, t.getCharge(), 5);
-        	smearedVertex.addTrack(new NewTrack(referencePoint, parameters, errors, t.getCharge()), 0);
+        for (MCParticle p : event.getMCParticles()) {
+            if (abs(p.getPDGID()) == 443) {
+                mother = p;
+            }
+        }
+        List<org.lcsim.contrib.JanStrube.tracking.Track> tracks = new ArrayList<org.lcsim.contrib.JanStrube.tracking.Track>();
+        for (Track t : event.getTracks()) {
+            ReconTrack rt = (ReconTrack) t;
+            MCParticle part = (MCParticle) rt.getMCParticle();
+
+            SpacePoint org = new CartesianPoint(t.getReferencePoint());
+            SpaceVector mom = new CartesianVector(t.getMomentum());
+            Matrix errors = new Matrix(t.getErrorMatrix());
+            EMap parameters = NewTrack.SpaceMomentum2Parameters(org, mom, referencePoint, t.getCharge(), 5);
+            tracks.add(new NewTrack(referencePoint, parameters, errors, t.getCharge()));
         }
-        Fitter fitter2 = new Fitter(smearedVertex, 5.0);
-        Vertex newVtx2 = fitter2.fit();
+        SpacePoint startingPoint = new SpacePoint();
+        Fitter fitter2 = new Fitter(event);
+        fitter2.setDelta_chi2(0);
+        Vertex newVtx2 = fitter2.fit(tracks, startingPoint);
+        double sigmaX = sqrt(newVtx2.getSpatialCovarianceMatrix().get(0, 0));
+        double sigmaY = sqrt(newVtx2.getSpatialCovarianceMatrix().get(1, 1));
+        double sigmaZ = sqrt(newVtx2.getSpatialCovarianceMatrix().get(2, 2));
+        double deltaX = newVtx2.origin().x() - mother.getOrigin().x();
+        double deltaY = newVtx2.origin().y() - mother.getOrigin().y();
+        double deltaZ = newVtx2.origin().z() - mother.getOrigin().z();
         aida.cloud1D("decayLength").fill(new SpacePoint(mother.getEndPoint()).magnitude());
-        aida.cloud1D("smeared_deltaX").fill(newVtx2.origin().x() - mother.getOrigin().x());
-        aida.cloud1D("smeared_deltaY").fill(newVtx2.origin().y() - mother.getOrigin().y());
-        aida.cloud1D("smeared_deltaZ").fill(newVtx2.origin().z() - mother.getOrigin().z());
+        aida.cloud1D("smeared_deltaX").fill(deltaX);
+        aida.cloud1D("smeared_deltaY").fill(deltaY);
+        aida.cloud1D("smeared_deltaZ").fill(deltaZ);
+        aida.cloud1D("sigma_x").fill(sigmaX);
+        aida.cloud1D("sigma_y").fill(sigmaY);
+        aida.cloud1D("sigma_z").fill(sigmaZ);
+        aida.cloud1D("pull_x").fill(deltaX/sigmaX);
+        aida.cloud1D("pull_y").fill(deltaY/sigmaY);
+        aida.cloud1D("pull_z").fill(deltaZ/sigmaZ);
     }
 }
-

lcsim/src/org/lcsim/contrib/JanStrube/standalone
FitterTestDriver.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FitterTestDriver.java	20 Aug 2006 05:56:56 -0000	1.2
+++ FitterTestDriver.java	29 Aug 2006 19:50:18 -0000	1.3
@@ -1,3 +1,5 @@
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Random;
 
 import org.lcsim.contrib.JanStrube.tracking.NewFastMCTrackFactory;
@@ -37,10 +39,8 @@
         	// K0: 310, J/Psi: 443
             if (abs(part.getPDGID()) != 443)
                 continue;
-          Vertex unsmearedVertex = new Vertex();
-          unsmearedVertex.setOrigin(origin);
-          Vertex smearedVertex = new Vertex();
-          smearedVertex.setOrigin(origin);
+            List<Track> unsmearedInput = new ArrayList<Track>();
+            List<Track> smearedInput = new ArrayList<Track>();
           
           for (MCParticle daughter : part.getDaughters()) {
         	  Track unsmearedTrack = tf.getTrack(
@@ -52,7 +52,7 @@
                       false);
         	  SpacePoint unsmearedPosition = NewTrack.Parameters2Position(unsmearedTrack.getParameters());
         	  SpacePoint unsmearedMomentum = NewTrack.Parameters2Momentum(unsmearedTrack.getParameters());
-              unsmearedVertex.addTrack(unsmearedTrack, 0);
+              unsmearedInput.add(unsmearedTrack);
               aida.cloud1D("unsmeared_pt").fill(unsmearedTrack.getPt());
               aida.cloud1D("unsmeared_diffx").fill(unsmearedPosition.x() - daughter.getOriginX());
               aida.cloud1D("unsmeared_diffy").fill(unsmearedPosition.y() - daughter.getOriginY());
@@ -70,7 +70,7 @@
                       true);
         	  SpacePoint smearedPosition = NewTrack.Parameters2Position(smearedTrack.getParameters());
         	  SpacePoint smearedMomentum = NewTrack.Parameters2Momentum(smearedTrack.getParameters());              
-              smearedVertex.addTrack(smearedTrack, 0);
+              smearedInput.add(smearedTrack);
               aida.cloud1D("smeared_pt").fill(smearedTrack.getPt());
               aida.cloud1D("smeared_diffx").fill(smearedPosition.x() - daughter.getOriginX());
               aida.cloud1D("smeared_diffy").fill(smearedPosition.y() - daughter.getOriginY());
@@ -84,10 +84,10 @@
               aida.cloud1D("diff_z").fill(unsmearedTrack.getParameters().getValues()[3]-smearedTrack.getParameters().getValues()[3]);
               aida.cloud1D("diff_tanLambda").fill(unsmearedTrack.getParameters().getValues()[4]-smearedTrack.getParameters().getValues()[4]);
           }
-          Fitter fitter = new Fitter(unsmearedVertex, 5.0);
-          Vertex newVtx1 = fitter.fit();
-          Fitter fitter2 = new Fitter(smearedVertex, 5.0);
-          Vertex newVtx2 = fitter2.fit();
+          Fitter fitter = new Fitter(event);
+          Vertex newVtx1 = fitter.fit(unsmearedInput, origin);
+          Fitter fitter2 = new Fitter(event);
+          Vertex newVtx2 = fitter2.fit(smearedInput, origin);
           aida.cloud1D("decayLength").fill(new SpacePoint(part.getEndPoint()).magnitude());
           aida.cloud1D("unsmeared_deltaX").fill(newVtx1.origin().x() - part.getOrigin().x());
           aida.cloud1D("unsmeared_deltaY").fill(newVtx1.origin().y() - part.getOrigin().y());

lcsim/src/org/lcsim/contrib/JanStrube/standalone
.cvsignore 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- .cvsignore	28 Jun 2006 01:54:46 -0000	1.1
+++ .cvsignore	29 Aug 2006 19:50:18 -0000	1.2
@@ -1,3 +1,5 @@
 java.hprof.txt
 exampleAnalysisJava.aida
 t.aida
+*.aida
+*.stdhep

lcsim/src/org/lcsim/spacegeom
SpacePoint.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- SpacePoint.java	28 Jun 2006 01:54:50 -0000	1.7
+++ SpacePoint.java	29 Aug 2006 19:50:19 -0000	1.8
@@ -10,7 +10,7 @@
 
 /**
  *
- *@version $Id: SpacePoint.java,v 1.7 2006/06/28 01:54:50 jstrube Exp $
+ *@version $Id: SpacePoint.java,v 1.8 2006/08/29 19:50:19 jstrube Exp $
  */
 public class SpacePoint implements Serializable, Cloneable, Hep3Vector
 {
@@ -387,14 +387,11 @@
         }
         return o;
     }
-    
-    // for legacy reasons
-    // long name to make it visible in code
+
     /**
-     * for legacy code
-     * @deprecated
+     * @return array of doubles, cartesian representation
      */
-    @Deprecated public double[] getCartesianArray()
+    public double[] getCartesianArray()
     {
         return new double[] {_x, _y, _z};
     }

lcsim/src/org/lcsim/spacegeom
CartesianVector.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- CartesianVector.java	18 Oct 2005 16:39:45 -0000	1.2
+++ CartesianVector.java	29 Aug 2006 19:50:19 -0000	1.3
@@ -4,11 +4,10 @@
 import static org.lcsim.spacegeom.Representation.Cartesian;
 /**
  *
- *@version $Id: CartesianVector.java,v 1.2 2005/10/18 16:39:45 ngraf Exp $
+ *@version $Id: CartesianVector.java,v 1.3 2006/08/29 19:50:19 jstrube Exp $
  */
 public class CartesianVector extends SpaceVector
 {
-    
     /**
      * Constructs a new Vector from 3 Cartesian co-ordinates
      * @param x
@@ -26,4 +25,8 @@
         _xy = Double.NaN;
         _xyz = sqrt(_x*_x + _y*_y + _z*_z);
     }
+    
+    public CartesianVector(double[] x) {
+        this(x[0], x[1], x[2]);
+    }
 }

lcsim/src/org/lcsim/spacegeom
CartesianPoint.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- CartesianPoint.java	18 Oct 2005 16:39:45 -0000	1.5
+++ CartesianPoint.java	29 Aug 2006 19:50:20 -0000	1.6
@@ -2,7 +2,7 @@
 /** A Cartesian SpacePoint
  *
  *@author Norman A. Graf
- *@version $Id: CartesianPoint.java,v 1.5 2005/10/18 16:39:45 ngraf Exp $
+ *@version $Id: CartesianPoint.java,v 1.6 2006/08/29 19:50:20 jstrube Exp $
  *
  */
 import static org.lcsim.spacegeom.Representation.Cartesian;
@@ -31,9 +31,8 @@
     /**
      * Constructs a CartesianSpacePoint from a legacy vector
      * @param x
-     * @deprecated please use the explicit constructor
      */
-    @Deprecated public CartesianPoint(double[] x)
+    public CartesianPoint(double[] x)
     {
         this(x[0], x[1], x[2]);
     }

lcsim/src/org/lcsim/contrib/JanStrube/vtxFitter
Fitter.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- Fitter.java	20 Aug 2006 05:56:56 -0000	1.10
+++ Fitter.java	29 Aug 2006 19:50:20 -0000	1.11
@@ -1,94 +1,109 @@
+
 package org.lcsim.contrib.JanStrube.vtxFitter;
+
 /**
- * @version $Id: Fitter.java,v 1.10 2006/08/20 05:56:56 jstrube Exp $
+ * @version $Id: Fitter.java,v 1.11 2006/08/29 19:50:20 jstrube Exp $
  */
 
+import static java.lang.Math.abs;
 import static java.lang.Math.atan2;
 import static java.lang.Math.sqrt;
 import static org.lcsim.constants.Constants.fieldConversion;
-import static org.lcsim.recon.vertexing.zvtop4.VectorArithmetic.subtract;
-import static org.lcsim.recon.vertexing.zvtop4.VectorArithmetic.add;
-import static org.lcsim.recon.vertexing.zvtop4.VectorArithmetic.dot;
 import static org.lcsim.contrib.JanStrube.tracking.NewTrack.SpaceMomentum2Parameters;
 
-import java.util.ArrayList;
+import java.util.Collection;
 
 import org.lcsim.contrib.JanStrube.tracking.HelixSwimmer;
 import org.lcsim.contrib.JanStrube.tracking.Track;
+import org.lcsim.event.EventHeader;
 import org.lcsim.spacegeom.CartesianPoint;
 import org.lcsim.spacegeom.SpacePoint;
 
 import Jama.Matrix;
 
+/**
+ * This is an implementation of a vertex fitter following the paper by Grab and Luchsinger. The parametrization of the
+ * Tracks follows the L3 convention. The fitter takes a collection of tracks as input, then performs the sequence of
+ * filtering and smoothing until convergence of the vertex in chi<sup>2</sup>. The expensive computation of the full
+ * covariance matrix is only done once, after convergence.
+ * 
+ * @author jstrube
+ * 
+ */
 public class Fitter {
     // The Vertex object
-	Vertex particle;
-    
-    Vertex unfittedParticle;
-	// convergence criterion
-	double deltaChi2 = 1e-4;
-	
+    Vertex particle;
+
     double B_z;
+    // convergence criterion
+    double delta_chi2 = 1e-2;
+    int max_iter = 20;
     // position
     Matrix x_prev;
     // covariance for x
-    Matrix C_prev;	
-    
+    Matrix C_prev;
+
     HelixSwimmer _swimmer;
-	
+
     // chi2
     double chi2_prev;
-		
-	/**
-	 * Definitions:
-	 * x_k = estimate of the vertex position after using the information of k tracks
-	 * xt = true vertex position
-	 * C_k = cov(x_k) = cov(xk - xt)
-	 * qk = estimate of the momentum of particle k at xt
-	 * qkt = true momentum of particle k at xt
-	 * D_k = cov(qk) = cov(qk - qkt)
-	 * Ek = cov(xk, qk) = cov((xk-xt)(qk-qkt))
-	 * mk = measurement vector
-	 * vk = measurement noise
-	 * Vk = cov(vk)
-	 * Gk = Vk^-1 weightmatrix of particle k
-	 * @param p
-	 */
-	public Fitter(Vertex p, double bz) {
-	    this(p
-            , bz
-            , new Matrix(new double[][] {{10000, 0, 0}, {0, 10000, 0}, {0, 0, 10000}})
-        );
-	}
-
-	public Fitter(Vertex p, double bz, Matrix c0) {
-	    unfittedParticle = p;
-            B_z = bz;
-	    C_prev = c0;
-	    x_prev = new Matrix(p.origin().getCartesianArray(), 3);
-	    _swimmer = new HelixSwimmer(bz);
-	}
-	
-	
-	public Vertex fit() {
-	    particle = new Vertex();
-	    particle.setOrigin(unfittedParticle.origin());
-	    for (int i=0; i<10; ++i) {
-	    	particle._tracks.clear();
-	    	chi2_prev = 0;
-	    	for (Track t : unfittedParticle.getTracks()) {
-	    		double chi2_track = filter(t);
-//	    		System.out.printf("filtering: chi2=%f\n", chi2_track);
-	    	}
-	    	for (Track t : particle.getTracks()) {
-	    		double chi2_track = smoothe(t);
-//	    		System.out.printf("smoothing: %f\n", chi2_track);
-	    	}
-	    }
-	    return particle;
-	}
     
-    // The problem is that double[] is a column vector...
+    /**
+     * Definitions: x_k = estimate of the vertex position after using the information of k tracks xt = true vertex
+     * position C_k = cov(x_k) = cov(xk - xt) qk = estimate of the momentum of particle k at xt qkt = true momentum of
+     * particle k at xt D_k = cov(qk) = cov(qk - qkt) Ek = cov(xk, qk) = cov((xk-xt)(qk-qkt)) mk = measurement vector vk =
+     * measurement noise Vk = cov(vk) Gk = Vk^-1 weightmatrix of particle k
+     * 
+     * @param p
+     */
+
+    public Fitter(EventHeader event) {
+        this(event.getDetector().getFieldMap().getField(new double[] { 0, 0, 0 })[2]);
+    }
+
+    public Fitter(double bz) {
+        B_z = bz;
+        _swimmer = new HelixSwimmer(bz);
+    }
+
+    public Vertex fit(Collection< ? extends Track> tracks, SpacePoint initialPosition) {
+        C_prev = new Matrix(new double[][] { { 10000, 0, 0 }, { 0, 10000, 0 }, { 0, 0, 10000 } });
+
+        x_prev = new Matrix(initialPosition.getCartesianArray(), 3);
+        particle = new Vertex();
+        particle.setOrigin(initialPosition);
+
+        // set the conditions to enter the loop
+        chi2_prev = 1000;
+        double chi2_this = 0;
+        int n_iter = 0;
+        while (abs(chi2_prev - chi2_this) > delta_chi2 && n_iter < max_iter) {
+//        for (int i=0; i<10; ++i) {
+            n_iter++;
+            particle._tracks.clear();
+//            System.out.printf("before: %f\t after: %f\n", chi2_this, chi2_prev);
+            chi2_this = chi2_prev;
+            chi2_prev = 0;
+            for (Track t : tracks) {
+                double chi2_track = filter(t);
+                // System.out.printf("filtering: chi2=%f\n", chi2_track);
+            }
+            // FIXME: This only changes the parameters of the tracks.
+//            for (Track t : tracks) {
+//                double chi2_track = smoothe(t, false);
+                // System.out.printf("smoothing: %f\n", chi2_track);
+//            }
+        }
+        particle._spatialCovarianceMatrix = C_prev;
+        particle._chi2 = chi2_this;
+        // final iteration, this time compute the full covariance matrix
+//        for (Track t : tracks) {
+//            double chi2_track = smoothe(t, true);
+            // System.out.printf("smoothing: %f\n", chi2_track);
+//        }
+        return particle;
+    }
+
     // Turn everything into a Matrix
     private double filter(Track t) {
         // First, get the Matrices at the point of linearization x0, p0
@@ -99,212 +114,184 @@
         double alpha = _swimmer.getTrackLengthToPoint(particle.origin());
         SpacePoint p = _swimmer.getMomentumAtLength(alpha);
         // x is the POCA of the current track to the best estimate
-        
+
         SpacePoint x = _swimmer.getPointAtLength(alpha);
-        
+
         Matrix A_k = getSpatialDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
         Matrix B_k = getMomentumDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
         Matrix q0 = new Matrix(p.getCartesianArray(), 3);
         // turn the measurement into a Matrix object
-        Matrix h = new Matrix(SpaceMomentum2Parameters(
-                particle.origin(), p, particle.origin(), t.getCharge(), B_z).getValues()
-                , 5);
+        Matrix h = new Matrix(SpaceMomentum2Parameters(particle.origin(), p, particle.origin(), t.getCharge(), B_z)
+                .getValues(), 5);
         // the measurement of the track is taken at the POCA to the best estimate
-        Matrix m_k = new Matrix(SpaceMomentum2Parameters(
-                x, p, particle.origin(), t.getCharge(), B_z).getValues()
-                , 5);
-        Matrix c_k0 =  h.minus(A_k.times(x_prev).plus(B_k.times(q0)));
-        
-        // Now for the real filtering equations        
+        Matrix m_k = new Matrix(SpaceMomentum2Parameters(x, p, particle.origin(), t.getCharge(), B_z).getValues(), 5);
+        Matrix c_k0 = h.minus(A_k.times(x_prev).plus(B_k.times(q0)));
+
+        // Now for the real filtering equations
         Matrix G_k = t.getErrorMatrix().inverse();
         Matrix W_k = (B_k.transpose().times(G_k.times(B_k))).inverse();
-        Matrix G_kB = G_k.minus((G_k.times(B_k.times(W_k.times(B_k.transpose().times(G_k))))));
+        Matrix G_kB = G_k.minus( (G_k.times(B_k.times(W_k.times(B_k.transpose().times(G_k))))));
 
         // cov(x)
-//        System.out.printf("C_k before: %g\t%g\t%g\n", C_prev.get(0, 0), C_prev.get(1, 1), C_prev.get(2, 2));
+        // System.out.printf("C_k before: %g\t%g\t%g\n", C_prev.get(0, 0), C_prev.get(1, 1), C_prev.get(2, 2));
         Matrix C_k = C_prev.inverse().plus(A_k.transpose().times(G_kB.times(A_k))).inverse();
-//        System.out.printf("C_k after: %g\t%g\t%g\n", C_k.get(0, 0), C_k.get(1, 1), C_k.get(2, 2));
-        Matrix x_k = C_k.times(C_prev.inverse().times(x_prev).plus(
-                 A_k.transpose().times(G_kB).times(m_k.minus(c_k0))));
+        // System.out.printf("C_k after: %g\t%g\t%g\n", C_k.get(0, 0), C_k.get(1, 1), C_k.get(2, 2));
+        Matrix x_k = C_k.times(C_prev.inverse().times(x_prev).plus(A_k.transpose().times(G_kB).times(m_k.minus(c_k0))));
         Matrix q_k = W_k.times(B_k.transpose().times(G_k.times(m_k.minus(c_k0.plus(A_k.times(x_k))))));
-        
+
         // cov(q)
-        Matrix D_k = W_k.plus(W_k.times(B_k.transpose().times(G_k.times(A_k.times(C_k.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))))))));
-//        System.out.printf("D_k: %g\t%g\t%g\n", D_k.get(0, 0), D_k.get(1, 1), D_k.get(2, 2));
-        // cov(x, q)
-        Matrix E_k = C_k.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))).uminus();
-        
         // now the chi2
         Matrix r_k = h.minus(c_k0.plus(A_k.times(x_k).plus(B_k.times(q_k))));
-//        System.out.printf("chi2: %s + %s", r_k.transpose().times(G_k.times(r_k)), x_k.minus(x_prev).transpose().times(C_prev.inverse().times(x_k.minus(x_prev))));
+        // System.out.printf("chi2: %s + %s", r_k.transpose().times(G_k.times(r_k)),
+        // x_k.minus(x_prev).transpose().times(C_prev.inverse().times(x_k.minus(x_prev))));
         double chi2_kf = r_k.transpose().times(G_k.times(r_k)).get(0, 0)
-            + x_k.minus(x_prev).transpose().times(C_prev.inverse().times(x_k.minus(x_prev))).get(0, 0);
-		
-        double chi2 = chi2_prev + chi2_kf;
-//		System.out.printf("before: %s", x_prev);
+                + x_k.minus(x_prev).transpose().times(C_prev.inverse().times(x_k.minus(x_prev))).get(0, 0);
+
+        chi2_prev += chi2_kf;
+        // System.out.printf("before: %s", x_prev);
         x_prev = x_k;
-//        System.out.printf("after: %s", x_prev);
+        // System.out.printf("after: %s", x_prev);
         C_prev = C_k;
         particle.addTrack(t, chi2_kf);
         particle._origin = new CartesianPoint(x_k.getRowPackedCopy());
-//        System.out.println(particle._origin);
-        chi2_prev = chi2;
+        // System.out.println(particle._origin);
+//        if (fullFit) {
+//            Matrix D_k = W_k.plus(W_k.times(B_k.transpose().times(
+//                    G_k.times(A_k.times(C_k.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))))))));
+//            // System.out.printf("D_k: %g\t%g\t%g\n", D_k.get(0, 0), D_k.get(1, 1), D_k.get(2, 2));
+//            // cov(x, q)
+//            Matrix E_k = C_k.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))).uminus();
+//        }
+
         return chi2_kf;
-	}
-	
-	private double smoothe(Track t) {
-	    _swimmer.setTrack(t);
-	    // at the moment, particle.origin is the best estimate so far
-	    double alpha = _swimmer.getTrackLengthToPoint(particle.origin());
-	    SpacePoint p = _swimmer.getMomentumAtLength(alpha);
-	    // x is the POCA of the current track to the best estimate
-	    Matrix q0 = new Matrix(p.getCartesianArray(), 3);
-            SpacePoint x = _swimmer.getPointAtLength(alpha);
-        
-	    Matrix A_k = getSpatialDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
-	    Matrix B_k = getMomentumDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
+    }
+
+    private double smoothe(Track t, boolean fullFit) {
+        _swimmer.setTrack(t);
+        // at the moment, particle.origin is the best estimate so far
+        double alpha = _swimmer.getTrackLengthToPoint(particle.origin());
+        SpacePoint p = _swimmer.getMomentumAtLength(alpha);
+        // x is the POCA of the current track to the best estimate
+        Matrix q0 = new Matrix(p.getCartesianArray(), 3);
+        SpacePoint x = _swimmer.getPointAtLength(alpha);
+
+        Matrix A_k = getSpatialDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
+        Matrix B_k = getMomentumDerivativeMatrix(particle.origin(), p, t.getCharge(), B_z);
+
+        Matrix G_k = t.getErrorMatrix().inverse();
+        Matrix W_k = B_k.transpose().times(G_k.times(B_k)).uminus();
+        // the measurement of the track is taken at the POCA to the best estimate
+        Matrix m_k = new Matrix(SpaceMomentum2Parameters(x, p, particle.origin(), t.getCharge(), B_z).getValues(), 5);
+        Matrix c_k0 = m_k.minus(A_k.times(x_prev).plus(B_k.times(q0)));
+
+        if (fullFit) {
+            Matrix q_kN = W_k.times(B_k.transpose().times(G_k)).times(m_k.minus(c_k0.plus(A_k.times(x_prev))));
+            Matrix D_kN = W_k.plus(W_k.times(B_k.transpose().times(
+                    G_k.times(A_k.times(C_prev.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))))))));
+            Matrix E_kN = C_prev.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))).uminus();
+        }
         
-	    Matrix G_k = t.getErrorMatrix().inverse();
-	    Matrix W_k = B_k.transpose().times(G_k.times(B_k)).uminus();
-	    // the measurement of the track is taken at the POCA to the best estimate
-	    Matrix m_k = new Matrix(SpaceMomentum2Parameters(
-                x, p, particle.origin(), t.getCharge(), B_z).getValues()
-                , 5);
-	    Matrix c_k0 =  m_k.minus(A_k.times(x_prev).plus(B_k.times(q0)));
-
-	    Matrix q_kN = W_k.times(B_k.transpose().times(G_k)).times(m_k.minus(c_k0.plus(A_k.times(x_prev))));
-	    // Matrix D_kN = W_k.plus(W_k.times(B_k.transpose().times(G_k.times(A_k.times(C_prev.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))))))));
-	    // Matrix E_kN = C_prev.times(A_k.transpose().times(G_k.times(B_k.times(W_k)))).uminus();
-	    return 0;
-	}
-
-
-//	// returns y = A.x
-//	static double[] multiply(Matrix A, double[] x) {
-//		if (A.getColumnDimension() != x.length)
-//			throw new IllegalArgumentException("dimensions do not match");
-//		double[] result = new double[A.getRowDimension()];
-//		
-//		for (int i=0; i<A.getRowDimension(); i++) {
-//			for (int j=0; j<A.getColumnDimension(); j++) {
-//				result[i] += A.get(i, j) * x[j];
-//			}
-//		}
-//		return result;
-//	}
-//	
-//	// for notational convenience
-//	static Matrix multiply(Matrix a, Matrix b) {
-//		return a.times(b);
-//	}
-	
-	public static Matrix getMomentumDerivativeMatrix(SpacePoint x, SpacePoint p, int charge, double Bz) {
-        double field = Bz*fieldConversion;
-    	double pt = p.rxy();
-    	double px0 = p.x() - charge*field;
-    	double py0 = p.y() + charge*field;
-    	double pt0 = sqrt(px0*px0 + py0*py0);
-    	double phi = atan2(p.y(), p.x());
-    	double phi0 = atan2(py0, px0);
-    	double l = (phi-phi0)*pt/(charge*field);
-    
-        double[] dTanLambda_dp = new double[] {
-                -p.z()*p.x() / (pt*pt*pt)
-                , -p.z()*p.y() / (pt*pt*pt)
-                , 1/pt
-        };
-        double[] dPhi_dp = new double[] {
-                -py0 / (pt0*pt0)
-                , px0 / (pt0*pt0)
-                , 0
-        };
-        double[] dOmega_dp = new double[] {
-                -charge*field*p.x() / (pt*pt*pt)
-                , -charge*field*p.y() / (pt*pt*pt)
-                , 0
-        };
-        double[] dD0_dp = new double[] {
-                -py0/pt0
-                , px0/pt0
-                , 0
-        };
-        double[] dZ_dp = new double[] {
-                -p.z() / (field*charge) * (p.y()/(pt*pt) - py0/(pt0*pt0))
-                , -p.z() / (field*charge) * (p.x()/(pt*pt) - px0/(pt0*pt0))
-                , -l/pt
-        };        
-    	return new Matrix(new double[][] {
-                dD0_dp, dPhi_dp, dOmega_dp, dZ_dp, dTanLambda_dp
-                });
+        return 0;
+    }
+
+    // // returns y = A.x
+    // static double[] multiply(Matrix A, double[] x) {
+    // if (A.getColumnDimension() != x.length)
+    // throw new IllegalArgumentException("dimensions do not match");
+    // double[] result = new double[A.getRowDimension()];
+    //		
+    // for (int i=0; i<A.getRowDimension(); i++) {
+    // for (int j=0; j<A.getColumnDimension(); j++) {
+    // result[i] += A.get(i, j) * x[j];
+    // }
+    // }
+    // return result;
+    // }
+    //	
+    // // for notational convenience
+    // static Matrix multiply(Matrix a, Matrix b) {
+    // return a.times(b);
+    // }
+
+    public static Matrix getMomentumDerivativeMatrix(SpacePoint x, SpacePoint p, int charge, double Bz) {
+        double field = Bz * fieldConversion;
+        double pt = p.rxy();
+        double px0 = p.x() - charge * field;
+        double py0 = p.y() + charge * field;
+        double pt0 = sqrt(px0 * px0 + py0 * py0);
+        double phi = atan2(p.y(), p.x());
+        double phi0 = atan2(py0, px0);
+        double l = (phi - phi0) * pt / (charge * field);
+
+        double[] dTanLambda_dp = new double[] { -p.z() * p.x() / (pt * pt * pt), -p.z() * p.y() / (pt * pt * pt),
+                1 / pt };
+        double[] dPhi_dp = new double[] { -py0 / (pt0 * pt0), px0 / (pt0 * pt0), 0 };
+        double[] dOmega_dp = new double[] { -charge * field * p.x() / (pt * pt * pt),
+                -charge * field * p.y() / (pt * pt * pt), 0 };
+        double[] dD0_dp = new double[] { -py0 / pt0, px0 / pt0, 0 };
+        double[] dZ_dp = new double[] { -p.z() / (field * charge) * (p.y() / (pt * pt) - py0 / (pt0 * pt0)),
+                -p.z() / (field * charge) * (p.x() / (pt * pt) - px0 / (pt0 * pt0)), -l / pt };
+        return new Matrix(new double[][] { dD0_dp, dPhi_dp, dOmega_dp, dZ_dp, dTanLambda_dp });
     }
 
     /**
      * Calculates the derivatives of the measurement vector with respect to cartesian spatial coordinates.
+     * 
      * @param x
      * @param p
      * @param charge
      * @return the derivatives Matrix. Assumes an ordering of ??? in the measurement vector
      */
     public static Matrix getSpatialDerivativeMatrix(SpacePoint x, SpacePoint p, int charge, double Bz) {
-        double field = Bz*fieldConversion;
-    
-        double px0 = p.x() - charge*field;
-    	double py0 = p.y() + charge*field;
-    	double pt0 = sqrt(px0*px0 + py0*py0);
-    			
+        double field = Bz * fieldConversion;
+
+        double px0 = p.x() - charge * field;
+        double py0 = p.y() + charge * field;
+        double pt0 = sqrt(px0 * px0 + py0 * py0);
+
         // be very explicit about the derivatives
         // dr = (dx, dy, dz)^T
-        double[] dTanLambda_dr = new double[] {
-                0, 0, 0
-        };
-        
-        double[] dPhi_dr = new double[] {
-                px0*field*charge / (pt0*pt0)
-                , py0*field*charge / (pt0*pt0)
-                , 0
-        };
-        
-        double[] dOmega_dr = new double[] {
-                0, 0, 0
-        };
-        
-        double[] dD0_dr = new double[] {
-                -py0 / pt0
-                , px0 / pt0
-                , 0
-        };
-        
-        double[] dZ_dr = new double[] {
-                -p.z() * px0 / (pt0*pt0)
-                , -p.z() * py0 / (pt0*pt0)
-                , 1
-        };
-        
-    	return new Matrix(new double[][] {
-                dD0_dr, dPhi_dr, dOmega_dr, dZ_dr, dTanLambda_dr
-                });
-    }
-	
-	// for notational convenience
-	static Matrix add(Matrix a, Matrix b) {
-		return a.plus(b);
-	}
-	
-	// matrix A_c in the Grab and Luchsinger paper
-	static Matrix chargedSpatialLinearity(Track t) {
-		
-		return new Matrix(0, 0);
-	}
-	
-	static Matrix chargedMomentumLinearity(Track t) {
-		return new Matrix(0, 0);
-	}
-	
-	static Matrix calcSpatialLinearityMatrix(Track t) {
-		return new Matrix(5, 5);
-	}
-	
-	static Matrix calcMomentumLinearityMatrix(Track t) {
-		return new Matrix(5, 5);
-	}
+        double[] dTanLambda_dr = new double[] { 0, 0, 0 };
+
+        double[] dPhi_dr = new double[] { px0 * field * charge / (pt0 * pt0), py0 * field * charge / (pt0 * pt0), 0 };
+
+        double[] dOmega_dr = new double[] { 0, 0, 0 };
+
+        double[] dD0_dr = new double[] { -py0 / pt0, px0 / pt0, 0 };
+
+        double[] dZ_dr = new double[] { -p.z() * px0 / (pt0 * pt0), -p.z() * py0 / (pt0 * pt0), 1 };
+
+        return new Matrix(new double[][] { dD0_dr, dPhi_dr, dOmega_dr, dZ_dr, dTanLambda_dr });
+    }
+
+    // for notational convenience
+    static Matrix add(Matrix a, Matrix b) {
+        return a.plus(b);
+    }
+
+    // matrix A_c in the Grab and Luchsinger paper
+    static Matrix chargedSpatialLinearity(Track t) {
+
+        return new Matrix(0, 0);
+    }
+
+    static Matrix chargedMomentumLinearity(Track t) {
+        return new Matrix(0, 0);
+    }
+
+    static Matrix calcSpatialLinearityMatrix(Track t) {
+        return new Matrix(5, 5);
+    }
+
+    static Matrix calcMomentumLinearityMatrix(Track t) {
+        return new Matrix(5, 5);
+    }
+
+    public double getDelta_chi2() {
+        return delta_chi2;
+    }
+
+    public void setDelta_chi2(double d) {
+        delta_chi2 = d;
+    }
 }

lcsim/src/org/lcsim/contrib/JanStrube/vtxFitter
Vertex.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- Vertex.java	16 Aug 2006 06:23:44 -0000	1.4
+++ Vertex.java	29 Aug 2006 19:50:20 -0000	1.5
@@ -12,16 +12,20 @@
 import org.lcsim.spacegeom.CartesianPoint;
 import org.lcsim.spacegeom.SpacePoint;
 
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
 import Jama.Matrix;
 
 public class Vertex {
 	SpacePoint _origin;
     SpacePoint _originError;
-    Map<Track, Double> _tracks;    
+    Map<Track, Double> _tracks;
     
     double _chi2;
     double _ndf;
-    Matrix _covMatrix;
+    Matrix _fullCovarianceMatrix;
+    Matrix _spatialCovarianceMatrix;
+    Matrix _momentumCovarianceMatrix;
     
 	public Vertex() {
 		_origin = new SpacePoint();
@@ -71,4 +75,27 @@
     public Set<Track> getTracks() {
         return _tracks.keySet();
     }
+    
+    /**
+     * @return The full covarianceMatrix.
+     * The covariance matrices for position and momentum are submatrices of this Matrix.
+     */
+    public Matrix getCovarianceMatrix() {
+        throw new NotImplementedException();
+    }
+    
+    /**
+     * @return The spatial components of the full covariance matrix
+     */
+    public Matrix getSpatialCovarianceMatrix() {
+        return _spatialCovarianceMatrix;
+    }
+    
+    
+    /**
+     * @return The momentum components of the full covariance matrix
+     */
+    public Matrix getMomentumCovarianceMatrix() {
+        throw new NotImplementedException();
+    }
 }

lcsim/src/org/lcsim/contrib/JanStrube/vtxFitter
vertexing.lyx 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- vertexing.lyx	20 Aug 2006 05:56:56 -0000	1.8
+++ vertexing.lyx	29 Aug 2006 19:50:20 -0000	1.9
@@ -284,8 +284,8 @@
 \begin_layout Standard
 The formula that relates the transverse momentum to field, charge and radius
  is
-\begin_inset Formula \[
-p_{t}=aqB_{z}r,\]
+\begin_inset Formula \begin{equation}
+p_{t}=qB_{z}r,\label{eq:pt_r}\end{equation}
 
 \end_inset
 
@@ -293,38 +293,6 @@
 \end_layout
 
 \begin_layout Standard
-where 
-\begin_inset Formula $a$
-\end_inset
-
- is a factor that takes care of the unit conversion.
- Now in order to compute 
-\begin_inset Formula $a$
-\end_inset
-
- one has to be careful: It is a unit conversion factor, 
-\emph on
-not
-\emph default
- a physical quantity.
- In our computations, we enter unitless numbers rather than physical quantities
- into the formula above.
- Therefore the constant 
-\begin_inset Formula $a$
-\end_inset
-
- 
-\emph on
-collects
-\emph default
- rather than 
-\emph on
-cancels
-\emph default
- the units.
-\end_layout
-
-\begin_layout Standard
 In SI units, 
 \begin_inset Formula $[p_{t}]=\text{kg}\text{m}\text{s}^{-1}$
 \end_inset
@@ -342,17 +310,8 @@
 \end_inset
 
 .
- From this it is easy to see that 
-\begin_inset Formula $[a]=1$
-\end_inset
-
-.
- The specific value of a now depends on your choice of units.
- Obviously, in SI units 
-\begin_inset Formula $a=1$
-\end_inset
-
-.
+ From this it is easy to see that all the units match up, as they have to
+ in order for the equation to make any sense.
 \end_layout
 
 \begin_layout Standard
@@ -378,12 +337,22 @@
 \end_inset
 
 .
-\end_layout
+ In our computations, we enter 
+\emph on
+unitless 
+\emph default
+numbers rather than physical quantities into the formula above, but 
+\emph on
+any physical equation is meaningless without units
+\emph default
+.
+ We can collect the units in a constant 
+\begin_inset Formula $\tilde{a}$
+\end_inset
 
-\begin_layout Standard
-In compuations we use the following:
-\begin_inset Formula \[
-\tilde{p}_{t}=\tilde{a}\tilde{q}\tilde{B_{z}}\tilde{r}\]
+:
+\begin_inset Formula \begin{equation}
+\tilde{p}_{t}\cdot[p_{t}]=\tilde{q}\cdot[q]\times\tilde{B}_{z}\cdot[B_{z}]\times\tilde{r}\cdot[r]=\tilde{a}\tilde{q}\tilde{B_{z}}\tilde{r}\label{eq:pt_r_numeric}\end{equation}
 
 \end_inset
 

lcsim/src/org/lcsim/contrib/JanStrube/tracking
Track.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- Track.java	18 Jul 2006 13:20:41 -0000	1.3
+++ Track.java	29 Aug 2006 19:50:27 -0000	1.4
@@ -1,5 +1,5 @@
 /**
- * @version $Id: Track.java,v 1.3 2006/07/18 13:20:41 jstrube Exp $
+ * @version $Id: Track.java,v 1.4 2006/08/29 19:50:27 jstrube Exp $
  */
 package org.lcsim.contrib.JanStrube.tracking;
 
@@ -31,6 +31,20 @@
     public abstract EMap getParameters();
     
     /**
+     * Accessor to the POCA of the reference point.
+     * This is just another way of parametrizing the track
+     * @return The POCA to the reference point
+     */
+    public abstract SpacePoint getPosition();
+    
+    /**
+     * Accessor to the momentum vector of the track at the POCA to the reference point.
+     * Together with {@link getPosition}, this is just another way of parametrizing the track. 
+     * @return The momentum vector of the particle at the POCA to the reference point
+     */
+    public abstract SpacePoint getMomentum();
+    
+    /**
      * Returns the transverse momentum
      * @return The transverse momentum
      */

lcsim/src/org/lcsim/contrib/JanStrube/tracking
NewTrack.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- NewTrack.java	15 Aug 2006 23:49:55 -0000	1.6
+++ NewTrack.java	29 Aug 2006 19:50:27 -0000	1.7
@@ -1,5 +1,5 @@
 /**
- * @version $Id: NewTrack.java,v 1.6 2006/08/15 23:49:55 jstrube Exp $
+ * @version $Id: NewTrack.java,v 1.7 2006/08/29 19:50:27 jstrube Exp $
  */
 package org.lcsim.contrib.JanStrube.tracking;
 
@@ -134,4 +134,12 @@
     public Matrix getErrorMatrix() {
         return _errorMatrix;
     }
+    
+    public SpacePoint getPosition() {
+        return Parameters2Position(_parameters);
+    }
+    
+    public SpacePoint getMomentum() {
+        return Parameters2Momentum(_parameters);
+    }
 }

lcsim/test/org/lcsim/contrib/JanStrube/tracking
FitterTest.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FitterTest.java	15 Aug 2006 23:50:05 -0000	1.2
+++ FitterTest.java	29 Aug 2006 19:50:27 -0000	1.3
@@ -2,6 +2,8 @@
 
 
 import java.util.Random;
+import java.util.List;
+import java.util.ArrayList;
 
 import junit.framework.TestCase;
 
@@ -40,18 +42,17 @@
 
     
     public void testFit() {
-        Vertex particle = new Vertex();
+	List<Track> tracks = new ArrayList<Track>();
         NewFastMCTrackFactory fac = new NewFastMCTrackFactory("sidaug05", 5., false);
         SpacePoint pos = new CartesianPoint(0, 0, 0);
         SpacePoint mom1 = new CartesianPoint(1, 2, 3);
         SpacePoint mom2 = new CartesianPoint(2, -2, 1.5);
         SpacePoint mom3 = new CartesianPoint(-1, 2, 2);
         SpacePoint ref = new CartesianPoint(3, 6, 9);
-        particle.addTrack(fac.getTrack(mom1, ref, ref, -1, new Random(), false), 0);
-        particle.addTrack(fac.getTrack(mom2, ref, ref, 1, new Random(), false), 0);
-        particle.addTrack(fac.getTrack(mom3, ref, ref, -1, new Random(), false), 0);
-        particle.setOrigin(pos);
-        Fitter f = new Fitter(particle, 5.0);
-        f.fit();
+        tracks.add(fac.getTrack(mom1, ref, ref, -1, new Random(), false));
+        tracks.add(fac.getTrack(mom2, ref, ref, 1, new Random(), false));
+        tracks.add(fac.getTrack(mom3, ref, ref, -1, new Random(), false));
+        Fitter f = new Fitter(5.0);
+        Vertex particle = f.fit(tracks, pos);
     }
 }
CVSspam 0.2.8