4 added files
lcsim/test/org/lcsim/recon/tracking/trfdca
diff -N DistSurface_t.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DistSurface_t.java 25 Jul 2007 17:23:55 -0000 1.1
@@ -0,0 +1,82 @@
+/*
+ * DistSurface_t.java
+ *
+ * Created on July 24, 2007, 9:59 PM
+ *
+ * $Id: DistSurface_t.java,v 1.1 2007/07/25 17:23:55 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfdca;
+
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.trfbase.Surface;
+import org.lcsim.recon.tracking.trfcyl.SurfCylinder;
+import org.lcsim.recon.tracking.trfutil.Assert;
+import org.lcsim.recon.tracking.trfutil.StatusDouble;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class DistSurface_t extends TestCase
+{
+ private boolean debug;
+ /** Creates a new instance of DistSurface_t */
+ public void testDistSurface()
+ {
+ String component = "DistSurface";
+ String ok_prefix = component+ " (I): ";
+ String error_prefix = component+ " test (E): ";
+
+ if(debug) System.out.println( ok_prefix
+ + "--------------- testing component" + component
+ + ". -------------");
+ //*******************************************
+
+ // Test data.
+
+ double[] x = { 0., 0., 2., 1., 2., 3. };
+ double[] y = { 0., 0., 3., 2., 2., 0. };
+ double[] z = { 0., 10., 10., 0., 0., 0. };
+ double[] phid = { 0., 0., 0., 0., 0., 0. };
+ double[] tlam = { 0., 0., 0., 0.75, 0.75, 0.75 };
+ double[] wc = { 0., 0., 0., 0., 0., 0. };
+ double[] xbeam = { 0., 1., 1., -1., -1., 0. };
+ double[] ybeam = { 0., 2., 2., -2., -1., 0. };
+ double[] bx = { 0., 0., 0., 0., 1., 0. };
+ double[] by = { 0., 0., 0., 0., 1., 0. };
+ double[] s = { 0., 1., -1., -2.5, -15., 8.75 };
+ double[] r = { 0., 0., 0., 0., 0., 10. };
+
+ int n = x.length;
+
+
+ if(debug) System.out.println( ok_prefix+" Test constructor");
+ for(int i=0; i<n; ++i)
+ {
+ Surface srf;
+ if(r[i] == 0.)
+ {
+ srf = new SurfDCA(xbeam[i], ybeam[i], bx[i], by[i]);
+ }
+ else
+ {
+ srf = new SurfCylinder(r[i]);
+ }
+ DistSurface dist = new DistSurface(x[i], y[i], z[i], phid[i], tlam[i], wc[i], srf);
+ if(debug) System.out.println(dist);
+
+ StatusDouble s1 = dist.distance();
+ if(debug) System.out.println( i + "\t" + s[i] + "\t" + s1.value() );
+ Assert.assertTrue(s1.status() == 0);
+ Assert.assertTrue(Math.abs(s[i] - s1.value()) < 1.e-6);
+
+ }
+
+ //*******************************************
+ if(debug) System.out.println( ok_prefix
+ + "-------------------- All tests passed. -------------------");
+ //*******************************************
+ }
+
+}
lcsim/test/org/lcsim/recon/tracking/trfdca
diff -N SurfDCA_t.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SurfDCA_t.java 25 Jul 2007 17:23:55 -0000 1.1
@@ -0,0 +1,328 @@
+/*
+ * SurfDCA_t.java
+ *
+ * Created on July 24, 2007, 9:03 PM
+ *
+ * $Id: SurfDCA_t.java,v 1.1 2007/07/25 17:23:55 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfdca;
+
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.spacegeom.CylindricalPath;
+import org.lcsim.recon.tracking.spacegeom.SpacePath;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.trfbase.CrossStat;
+import org.lcsim.recon.tracking.trfbase.SurfTest;
+import org.lcsim.recon.tracking.trfbase.TrackVector;
+import org.lcsim.recon.tracking.trfbase.VTrack;
+import org.lcsim.recon.tracking.trfutil.Assert;
+import org.lcsim.recon.tracking.trfutil.TRFMath;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class SurfDCA_t extends TestCase
+{
+ private boolean debug;
+ /** Creates a new instance of SurfDCA_t */
+ public void testSurfDCA()
+ {
+
+ String ok_prefix = "test SurfDCA (I): ";
+ String error_prefix = "test SurfDCA (E): ";
+
+ System.out.println(ok_prefix
+ + "------ Testing component SurfDCA. ------" );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Check indices." );
+ Assert.assertTrue( SurfDCA.IRSIGNED == 0 );
+ Assert.assertTrue( SurfDCA.IZ == 1 );
+ Assert.assertTrue( SurfDCA.IPHID == 2 );
+ Assert.assertTrue( SurfDCA.ITLM == 3 );
+ Assert.assertTrue( SurfDCA.IQPT == 4 );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test constructor." );
+ SurfDCA sdca1 = new SurfDCA();
+ System.out.println(sdca1 );
+ SurfDCA sdca_x1 = new SurfDCA(0.1, 0.2);
+ System.out.println(sdca_x1 );
+ SurfDCA sdca_x2 = new SurfDCA(0.1, 0.3, 0.01, 0.02);
+ System.out.println(sdca_x2 );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test equality and ordering." );
+ Assert.assertTrue( sdca1.pureEqual(sdca1) );
+ Assert.assertTrue( ! sdca1.pureLessThan(sdca1) );
+ Assert.assertTrue( sdca_x1.pureEqual(sdca_x1) );
+ Assert.assertTrue( ! sdca_x1.pureLessThan(sdca_x1) );
+ Assert.assertTrue( sdca_x2.pureEqual(sdca_x2) );
+ Assert.assertTrue( ! sdca_x2.pureLessThan(sdca_x2) );
+
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test virtual constructor." );
+ SurfDCA psdca4 = (SurfDCA) sdca1.newPureSurface();
+ if ( !sdca1.equals(psdca4) )
+ {
+ System.out.println(error_prefix + "Virtual construction failed." );
+ System.exit(5);
+ }
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test type." );
+ System.out.println(SurfDCA.staticType() );
+ // method get_type is implemented in class Surface
+ // it returns get_pure_type, which is implemented in SurfDCA
+ System.out.println(sdca1.type() );
+ Assert.assertTrue( sdca1.type() != null );
+ Assert.assertTrue( sdca1.type().equals(SurfDCA.staticType()) );
+
+ //********************************************************************
+
+ System.out.println( ok_prefix + "Test parameter access." );
+ System.out.println(sdca_x2.parameter(SurfDCA.IX));
+ Assert.assertTrue( sdca_x2.parameter(SurfDCA.IX) == 0.1);
+ Assert.assertTrue( sdca_x2.parameter(SurfDCA.IY) == 0.3);
+ Assert.assertTrue( sdca_x2.parameter(SurfDCA.IDXDZ) == 0.01);
+ Assert.assertTrue( sdca_x2.parameter(SurfDCA.IDYDZ) == 0.02);
+ Assert.assertTrue( sdca_x1.parameter(SurfDCA.IX) == 0.1);
+ Assert.assertTrue( sdca_x1.parameter(SurfDCA.IY) == 0.2);
+ Assert.assertTrue( sdca_x1.parameter(SurfDCA.IDXDZ) == 0.);
+ Assert.assertTrue( sdca_x1.parameter(SurfDCA.IDYDZ) == 0.);
+ Assert.assertTrue( sdca1.parameter(SurfDCA.IX) == 0.0);
+ Assert.assertTrue( sdca1.parameter(SurfDCA.IY) == 0.0);
+ Assert.assertTrue( sdca1.parameter(SurfDCA.IDXDZ) == 0.);
+ Assert.assertTrue( sdca1.parameter(SurfDCA.IDYDZ) == 0.);
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "construct a Track Vector." );
+
+ TrackVector tvec = new TrackVector();
+ tvec.set(0, 1.0); // r_signed
+ tvec.set(1, 2.0); // z
+ tvec.set(2, 3.0); // phi_direction
+ tvec.set(3, 4.0); // tlm
+ tvec.set(4, 5.0); // qpt
+ System.out.println(" *** TrackVector tvec = " + tvec );
+ System.out.println(" *** r_signed = " + tvec.get(0) );
+ System.out.println(" *** z = " + tvec.get(1) );
+ System.out.println(" *** phi_direction = " + tvec.get(2) );
+ System.out.println(" *** tlm = " + tvec.get(3) );
+ System.out.println(" *** qpt = " + tvec.get(4) );
+
+ double r = Math.abs(tvec.get(0));
+ double z = tvec.get(1);
+ double sign = 0.0;
+ double phi = 0.0;
+ if ( tvec.get(0) != 0.0 )
+ {
+ sign = tvec.get(0)/Math.abs(tvec.get(0));
+ phi = tvec.get(2)-(sign*TRFMath.PI2);
+ phi = TRFMath.fmod2( phi, TRFMath.TWOPI );
+ }
+ double tlam = tvec.get(3);
+
+ System.out.println(" *** r = " + r );
+ System.out.println(" *** phi = " + phi );
+ System.out.println(" *** z = " + z );
+
+ Assert.assertTrue( Math.abs(phi-( 1.4292)) < 1.e-4 ) ; // for r_signed = +1
+ // Assert.assertTrue( fabs(phi-(-1.7124)) < 1.e-4 ) ; // for r_signed = -1
+
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test crossing status." );
+
+ double clam = 1.0/Math.sqrt(1.0+tlam*tlam);
+ double slam = tlam/Math.sqrt(1.0+tlam*tlam);
+
+ double dz_ds = slam;
+
+ double alpha_in = -2.0;
+ double calf_in = Math.cos(alpha_in);
+ double salf_in = Math.sin(alpha_in);
+ double dr_ds_in = clam*calf_in;
+ double r_dphi_ds_in = clam*salf_in;
+ CylindricalPath cpth_in = new CylindricalPath(r, phi, z, dr_ds_in, r_dphi_ds_in, dz_ds);
+ SurfTest stest_in = new SurfTest(cpth_in);
+
+ double alpha_out = 1.0;
+ double calf_out = Math.cos(alpha_out);
+ double salf_out = Math.sin(alpha_out);
+ double dr_ds_out = clam*calf_out;
+ double r_dphi_ds_out = clam*salf_out;
+ CylindricalPath cpth_out = new CylindricalPath(r, phi, z, dr_ds_out, r_dphi_ds_out, dz_ds);
+ SurfTest stest_out= new SurfTest(cpth_out);
+
+ VTrack ton = new VTrack( sdca1.newPureSurface(), tvec );
+ System.out.println(" sdca1 = " + sdca1 );
+ System.out.println(" VTrack ton = " + ton );
+ VTrack tin= new VTrack( stest_in.newPureSurface(), tvec );
+ System.out.println(" stest_in = " + stest_in );
+ System.out.println(" VTrack tin = " + tin );
+ VTrack tout= new VTrack( stest_out.newPureSurface(), tvec );
+ System.out.println(" stest_out = " + stest_out );
+ System.out.println(" VTrack tout = " + tout );
+
+ SpacePath sp_on = ton.spacePath();
+ SpacePath sp_in = tin.spacePath();
+ SpacePath sp_out = tout.spacePath();
+
+ System.out.println(" *** sp_on *** " );
+ System.out.println(sp_on );
+ System.out.println(" *** sp_in *** " );
+ System.out.println(sp_in );
+ System.out.println(" *** sp_out *** " );
+ System.out.println(sp_out );
+
+ CrossStat xs1 = sdca1.pureStatus(ton);
+ System.out.println("xs1 = " + xs1 );
+ Assert.assertTrue( xs1.at() && xs1.on() && !xs1.inside() && !xs1.outside()
+ && !xs1.inBounds() && ! xs1.outOfBounds() );
+
+ System.out.println(stest_in );
+ CrossStat xs2 = sdca1.pureStatus(tin);
+ System.out.println("xs2 = " + xs2 );
+ Assert.assertTrue( !xs2.at() && !xs2.on() && xs2.inside() && !xs2.outside()
+ && !xs2.inBounds() && ! xs2.outOfBounds() );
+
+ System.out.println(stest_out );
+ CrossStat xs3 = sdca1.pureStatus(tout);
+ System.out.println("xs3 = " + xs3 );
+ Assert.assertTrue( !xs3.at() && !xs3.on() && !xs3.inside() && xs3.outside()
+ && !xs3.inBounds() && ! xs3.outOfBounds() );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test vector difference." );
+ TrackVector tvec2 = new TrackVector();
+ tvec2.set(0, 1.1); // r_signed
+ tvec2.set(1, 2.2); // z
+ tvec2.set(2, 3.3); // phi_direction
+ tvec2.set(3, 4.4); // tlm
+ tvec2.set(4, 5.5); // qpt
+ TrackVector diff = new TrackVector(sdca1.vecDiff(tvec2,tvec));
+ TrackVector ediff = new TrackVector();
+ ediff.set(0, 0.1);
+ ediff.set(1, 0.2);
+ ediff.set(2, 0.3);
+ ediff.set(3, 0.4);
+ ediff.set(4, 0.5);
+ TrackVector zero = new TrackVector(diff.minus(ediff));
+ if ( zero.amax() > 1.e-10 )
+ {
+ System.out.println( error_prefix + "Incorrect difference." );
+ System.exit(9);
+ }
+
+ // Assert.assertTrue( zero.amax() <= 1.e-10 );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test space point." );
+ SpacePoint spt = ton.spacePoint();
+ System.out.println("spt= "+spt);
+ Assert.assertTrue( myequal(spt.rxy(), 1.0) );
+ Assert.assertTrue( Math.abs(spt.phi()-phi) < 1.e-4 );
+ Assert.assertTrue( spt.z() == 2.0 );
+
+ //********************************************************************
+
+ TrackVector vec_1 = new TrackVector();
+ vec_1.set(SurfDCA.IZ,0.3);
+ VTrack trv_1 = new VTrack((new SurfDCA(0.1,0.2)));
+ trv_1.setVector(vec_1);
+ trv_1.setForward();
+
+ System.out.println("trv_1= "+trv_1);
+ System.out.println("trv_1.spacePoint()"+trv_1.spacePoint());
+
+ Assert.assertTrue( myequal(trv_1.spacePoint().x(),0.1) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().y(),0.2) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().z(),0.3) );
+
+ vec_1.set(SurfDCA.IRSIGNED, 0.3);
+ vec_1.set(SurfDCA.IPHID, TRFMath.PI2);
+ trv_1.setVector(vec_1);
+ trv_1.setForward();
+ Assert.assertTrue( myequal(trv_1.spacePoint().x(),0.1+0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().y(),0.2) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().z(),0.3) );
+
+ vec_1.set(SurfDCA.IRSIGNED, 0.3);
+ vec_1.set(SurfDCA.IPHID, -Math.PI);
+ trv_1.setVector(vec_1);
+ trv_1.setForward();
+ Assert.assertTrue( myequal(trv_1.spacePoint().x(),0.1) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().y(),0.2+0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePoint().z(),0.3) );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix + "Test space vector." );
+ SpacePath svec = ton.spacePath();
+ double lam = Math.atan(4.0);
+ Assert.assertTrue( myequal(svec.rxy(), 1.0) );
+ Assert.assertTrue( Math.abs(spt.phi()-phi) < 1.e-4 );
+ Assert.assertTrue( svec.z() == 2.0 );
+ Assert.assertTrue( myequal( svec.drxy(), Math.cos(lam)*Math.cos(TRFMath.PI2) ) );
+ Assert.assertTrue( myequal( svec.rxy_dphi(), Math.cos(lam)*Math.sin(sign*TRFMath.PI2) ) );
+ Assert.assertTrue( myequal( svec.dz(), Math.sin(lam) ) );
+
+ //********************************************************************
+
+ vec_1.set(SurfDCA.IRSIGNED,0.3);
+ vec_1.set(SurfDCA.IPHID, -Math.PI);
+ trv_1.setVector(vec_1);
+ trv_1.setForward();
+ Assert.assertTrue( myequal(trv_1.spacePath().x(),0.1) );
+ Assert.assertTrue( myequal(trv_1.spacePath().y(),0.2+0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePath().z(),0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dx(),-1.0) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dz(),0.0) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dy(),0.0) );
+ vec_1.set(SurfDCA.IRSIGNED,0.3);
+ vec_1.set(SurfDCA.IPHID, TRFMath.PI2);
+ trv_1.setVector(vec_1);
+ trv_1.setForward();
+ Assert.assertTrue( myequal(trv_1.spacePath().x(),0.1+0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePath().y(),0.2) );
+ Assert.assertTrue( myequal(trv_1.spacePath().z(),0.3) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dx(),0.0) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dz(),0.0) );
+ Assert.assertTrue( myequal(trv_1.spacePath().dy(),1.0) );
+
+ //********************************************************************
+
+ System.out.println(ok_prefix
+ + "------------- All tests passed. -------------" );
+
+ //********************************************************************
+
+ }
+
+ // comparison of doubles
+ public static boolean myequal(double x1, double x2)
+ {
+ double small = 1.e-12;
+ if ( Math.abs(x1-x2) < small ) return true;
+ System.out.println("myequal: difference too large:" );
+ System.out.println("value 1: " + x1 );
+ System.out.println("value 2: " + x2 );
+ System.out.println(" diff: " + (x1-x2) );
+ System.out.println("maxdiff: " + small );
+ return false;
+ }
+
+}
lcsim/test/org/lcsim/recon/tracking/trfdca
diff -N PropCylDCA_t.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PropCylDCA_t.java 25 Jul 2007 17:23:55 -0000 1.1
@@ -0,0 +1,374 @@
+/*
+ * PropCylDCA_t.java
+ *
+ * Created on July 24, 2007, 9:54 PM
+ *
+ * $Id: PropCylDCA_t.java,v 1.1 2007/07/25 17:23:55 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfdca;
+
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.trfbase.ETrack;
+import org.lcsim.recon.tracking.trfbase.PropDir;
+import org.lcsim.recon.tracking.trfbase.PropStat;
+import org.lcsim.recon.tracking.trfbase.Propagator;
+import org.lcsim.recon.tracking.trfbase.Surface;
+import org.lcsim.recon.tracking.trfbase.TrackDerivative;
+import org.lcsim.recon.tracking.trfbase.TrackError;
+import org.lcsim.recon.tracking.trfbase.TrackVector;
+import org.lcsim.recon.tracking.trfbase.VTrack;
+import org.lcsim.recon.tracking.trfcyl.SurfCylinder;
+import org.lcsim.recon.tracking.trfutil.Assert;
+import org.lcsim.recon.tracking.trfutil.TRFMath;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class PropCylDCA_t extends TestCase
+{
+ private boolean debug;
+ /** Creates a new instance of PropCylDCA_t */
+ public void testPropCylDCA()
+ {
+ String ok_prefix = "PropDCACyl (I): ";
+ String error_prefix = "PropDCACyl test (E): ";
+
+ if(debug) System.out.println(ok_prefix
+ + "-------- Testing component PropDCACyl. --------" );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix + "Test constructor." );
+ double bfield = 2.0;
+ PropDCACyl prop = new PropDCACyl(bfield);
+ if(debug) System.out.println(prop );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix + "Test cloning." );
+ Assert.assertTrue( prop.newPropagator() != null);
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test the magnetic field." );
+ Assert.assertTrue( prop.bField() == bfield );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test propagation of a track - without error." );
+
+ PropStat pstat = new PropStat();
+
+ TrackVector tvec = new TrackVector();
+ tvec.set(0, 10.0); // r_signed
+ tvec.set(1, 2.0); // z
+ tvec.set(2, 3.0); // phi_direction
+ tvec.set(3, 4.0); // tlm
+ tvec.set(4, 5.0); // qpt
+ SurfDCA sdca = new SurfDCA();
+ VTrack trv = new VTrack( sdca.newPureSurface(),tvec );
+ SpacePoint spt = trv.spacePoint();
+
+ if(debug) System.out.println(" *** Propagation to Cylinder of same r *** " );
+ SurfCylinder scys = new SurfCylinder(10.0);
+ VTrack trvsf = new VTrack(trv);
+ pstat = prop.vecDirProp(trvsf,scys,PropDir.FORWARD);
+ Assert.assertTrue( pstat.success() );
+ SpacePoint sptsf = trvsf.spacePoint();
+ TrackVector tvec_scys = trvsf.vector();
+ if(debug) System.out.println(" sptsf = " );
+ if(debug) System.out.println( sptsf );
+ if(debug) System.out.println(" tvec_scys = " + tvec_scys );
+ Assert.assertTrue( sptsf.rxy() == tvec.get(SurfDCA.IRSIGNED) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IZ) == tvec.get(SurfDCA.IZ) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IPHI) == spt.phi() );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.ITLM) == tvec.get(SurfDCA.ITLM) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IQPT) == tvec.get(SurfDCA.IQPT) );
+
+ SurfCylinder scyl = new SurfCylinder(15.);
+
+ if(debug) System.out.println(" *** Forward propagation *** " );
+ VTrack trv2f = new VTrack(trv);
+ if(debug) System.out.println(" before propagation: trv2f = " + trv2f );
+ SpacePoint spt2f = trv2f.spacePoint();
+ if(debug) System.out.println(" before propagation: spt2f = " );
+ if(debug) System.out.println(spt2f );
+ Assert.assertTrue( spt2f.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(spt2f.phi()-spt.phi()) < 1.e-4 );
+ Assert.assertTrue( spt2f.z() == 2.0 );
+ pstat = prop.vecDirProp(trv2f,scyl,PropDir.FORWARD);
+ Assert.assertTrue( pstat.forward() );
+ if(debug) System.out.println(" after propagation: trv2f = " + trv2f );
+ spt2f = trv2f.spacePoint();
+ if(debug) System.out.println(" after propagation: spt2f = " );
+ if(debug) System.out.println(spt2f );
+ Assert.assertTrue( spt2f.rxy() == 15.0 );
+
+ if(debug) System.out.println(" *** Backward propagation *** " );
+ VTrack trv2b = new VTrack(trv);
+ if(debug) System.out.println(" before propagation: trv2b = " + trv2b );
+ SpacePoint spt2b = trv2b.spacePoint();
+ if(debug) System.out.println(" before propagation: spt2b = " );
+ if(debug) System.out.println(spt2b );
+ Assert.assertTrue( spt2b.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(spt2b.phi()-spt.phi()) < 1.e-4 );
+ Assert.assertTrue( spt2b.z() == 2.0 );
+ pstat = prop.vecDirProp(trv2b,scyl,PropDir.BACKWARD);
+ Assert.assertTrue( pstat.backward() );
+ if(debug) System.out.println(" after propagation: trv2b = " + trv2b );
+ spt2b = trv2b.spacePoint();
+ if(debug) System.out.println(" after propagation: spt2b = " );
+ if(debug) System.out.println(spt2b );
+ Assert.assertTrue( spt2b.rxy() == 15.0 );
+
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test propagation of a track - with error." );
+
+ // PropStat pstat = new PropStat();
+
+ // TrackVector tvec = new TrackVector();
+ // tvec.set(0, 10.0); // r_signed
+ // tvec.set(1, 2.0); // z
+ // tvec.set(2, 3.0); // phi_direction
+ // tvec.set(3, 4.0); // tlm
+ // tvec.set(4, 5.0); // qpt
+ TrackError err = new TrackError();
+ err.set(0,0, 2.0);
+ err.set(0,1, 1.0);
+ err.set(0,2, 1.0);
+ err.set(0,3, 1.0);
+ err.set(0,4, 1.0);
+ err.set(1,1, 3.0);
+ err.set(1,2, 1.0);
+ err.set(1,3, 1.0);
+ err.set(1,4, 1.0);
+ err.set(2,2, 4.0);
+ err.set(2,3, 1.0);
+ err.set(2,4, 1.0);
+ err.set(3,3, 5.0);
+ err.set(3,4, 1.0);
+ err.set(4,4, 6.0);
+ // SurfDCA sdca;
+ ETrack etrv = new ETrack( sdca.newPureSurface(),tvec,err );
+ SpacePoint espt = etrv.spacePoint();
+
+ // SurfCylinder scyl = new SurfCylinder(15.);
+
+ if(debug) System.out.println(" *** Forward propagation *** " );
+ ETrack etrv2f = new ETrack(etrv);
+ if(debug) System.out.println(" before propagation: etrv2f = " + etrv2f );
+ SpacePoint espt2f = etrv2f.spacePoint();
+ if(debug) System.out.println(" before propagation: espt2f = " );
+ if(debug) System.out.println(espt2f );
+ Assert.assertTrue( espt2f.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(espt2f.phi()-espt.phi()) < 1.e-4 );
+ Assert.assertTrue( espt2f.z() == 2.0 );
+ if(debug) System.out.println("scyl= "+scyl);
+ if(debug) System.out.println("\n* etrv2f before: "+etrv2f);
+ pstat = prop.errDirProp(etrv2f,scyl,PropDir.FORWARD);
+ if(debug) System.out.println("\n* etrv2f after: "+etrv2f);
+ if(debug) System.out.println("pstat after propagation= "+pstat);
+ Assert.assertTrue( pstat.forward() );
+ if(debug) System.out.println(" after propagation: etrv2f = " + etrv2f );
+ espt2f = etrv2f.spacePoint();
+ if(debug) System.out.println(" after propagation: espt2f = " );
+ if(debug) System.out.println(espt2f );
+ Assert.assertTrue( espt2f.rxy() == 15.0 );
+ //********************************************************************
+
+ // Test non 0.0 DCA
+ if(debug) System.out.println("\n\n ***Testing non zero DCA \n\n");
+ int NUM = 10;
+ double[] rad =
+ {20.,2.0,Math.sqrt(5.)};
+ // double[] prec = { 1e-5,1e-5, 1e-5};
+ double[] xv =
+ { 0.5 , 0., 2. , 2., 2., 2., 2. ,2., 2. ,2.};
+ double[] yv =
+ { 0.4 , 0., -1., -1., -1., -1., -1. ,-1., -1. ,-1.};
+ double[] r =
+ { 1. , 0., 0.1, -0.1, -0.1, 0.1 , 0. , 0., -0.1 , 0.1};
+ double[] phid =
+ { 0.1, 0., 0.2, 0.2, 0.2 , 0.2 , 0. , 0., 0. , 0.};
+ double[] z =
+ { 2., 2., 2. , 2., 2., 2., 2. , 3., 2. , 3.};
+ double[] tlm =
+ { -4., 4., 4. , 4., 4., -4., 4. , 2., 4. , 2.};
+ double[] qpt =
+ { 0.1, 0., 0.01, 0.01,-0.01,-0.01,-0.01 , 0.01,0.0 ,0.};
+ for( int j=0; j <3 ;++j)
+ {
+ for(int i=0 ; i< NUM; ++i )
+ {
+ if(debug) System.out.println("\n\n\n\n "+j+" "+i);
+ SurfDCA srf = new SurfDCA(xv[i],yv[i]);
+ TrackVector vec = new TrackVector();
+ TrackError errnzdca = new TrackError();
+ for(int k=1;k<=5;++k) errnzdca.set(k-1,k-1,k);
+ vec.set(SurfDCA.IRSIGNED, r[i]);
+ vec.set(SurfDCA.IZ, z[i]);
+ vec.set(SurfDCA.IPHID, phid[i]);
+ vec.set(SurfDCA.ITLM, tlm[i]);
+ vec.set(SurfDCA.IQPT, qpt[i]);
+ ETrack tre = new ETrack( srf.newPureSurface());
+ tre.setVector(vec);
+ tre.setError(errnzdca);
+ tre.setForward();
+ SurfCylinder cyl = new SurfCylinder(rad[j]);
+ PropDCACyl propdca_cyl = new PropDCACyl( -2.);
+ PropCylDCA propcyl_dca = new PropCylDCA(-2.);
+ ETrack tre0 = new ETrack(tre);
+ ETrack treb = new ETrack(tre);
+ PropStat pstatnzdca = propdca_cyl.errDirProp(tre,cyl,PropDir.FORWARD);
+ Assert.assertTrue( pstatnzdca.success());
+ pstatnzdca = propdca_cyl.errDirProp(treb,cyl,PropDir.BACKWARD);
+ Assert.assertTrue( pstatnzdca.success());
+ check_derivatives(propdca_cyl,tre0,cyl);
+ ETrack tre1 = new ETrack(tre);
+ ETrack tre1b = new ETrack(treb);
+ pstatnzdca = propcyl_dca.errProp(tre,srf);
+ Assert.assertTrue( pstatnzdca.success());
+ pstatnzdca = propcyl_dca.errProp(treb,srf);
+ Assert.assertTrue( pstatnzdca.success());
+ check_derivatives(propcyl_dca,tre1,srf);
+ if(debug) System.out.println("checking equality \n"+tre0+" \n"+tre);
+ if(debug) System.out.println("about_equal: "+about_equal(tre0,tre));
+ //Assert.assertTrue(about_equal(tre0,tre));
+ check_derivatives(propcyl_dca,tre1b,srf);
+ // Assert.assertTrue(about_equal(tre0,treb));
+
+ }
+ }
+
+ //********************************************************************
+ if(debug) System.out.println(ok_prefix
+ + "------------- All tests passed. -------------" );
+
+ //********************************************************************
+
+ }
+ public static boolean about_equal(ETrack tre1, ETrack tre2)
+ {
+ boolean equal = true;
+ double maxdif = 1.e-6;
+ // Check vector.
+ TrackVector vdiff = tre1.surface().vecDiff( tre1.vector(), tre2.vector() );
+ for (int i=0; i<5; ++i)
+ {
+ double adif =Math.abs( vdiff.get(i) );
+ if ( ! (adif < maxdif) )
+ {
+ System.out.println("vecdif(" + i + ") = " + adif );
+ equal = false;
+ }
+ }
+ // Check errors.
+ TrackError ediff = tre1.error().minus(tre2.error());
+ TrackError eavg = tre1.error().plus(tre2.error());
+ for (int i=0; i<5; ++i)
+ {
+ for (int j=0; j<=i; ++j)
+ {
+ double adif = Math.abs( ediff.get(i,j) );
+ double afrac = ediff.get(i,j)/Math.sqrt(eavg.get(i,i)*eavg.get(j,j));
+ if ( !(adif < maxdif) )
+ {
+ System.out.println("errdif(" + i + "," + j + ") = " + adif + " frac = " + afrac );
+ equal = false;
+ }
+ }
+ }
+ return equal;
+ }
+
+ public static void check_derivatives( Propagator prop, VTrack trv0, Surface srf)
+ {
+ check_derivatives( prop, trv0, srf, 1.e-5);
+ }
+
+ public static void check_derivatives( Propagator prop, VTrack trv0, Surface srf,double prec)
+ {
+ for(int i=0;i<4;++i)
+ {
+ for(int j=0;j<4;++j)
+ {
+ check_derivative(prop,trv0,srf,i,j,prec);
+ }
+ }
+ }
+
+
+ public static void check_derivative( Propagator prop, VTrack trv0, Surface srf,int i,int j,double prec)
+ {
+
+ double dx = 1.e-3;
+ VTrack trv = new VTrack(trv0);
+ TrackVector vec = trv.vector();
+ boolean forward = trv0.isForward();
+
+ VTrack trv_0 = new VTrack(trv0);
+ TrackDerivative der = new TrackDerivative();
+ PropStat pstat = prop.vecProp(trv_0,srf,der);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector tmp=vec;
+ double tmpValue = tmp.get(j);
+ tmp.set(j, tmpValue+dx);
+ trv.setVector(tmp);
+ if(forward) trv.setForward();
+ else trv.setBackward();
+
+ VTrack trv_pl = new VTrack(trv);
+ pstat = prop.vecProp(trv_pl,srf);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector vecpl = trv_pl.vector();
+
+ tmp=vec;
+ tmpValue = tmp.get(j);
+ tmp.set(j, tmpValue-dx);
+ trv.setVector(tmp);
+ if(forward) trv.setForward();
+ else trv.setBackward();
+
+ VTrack trv_mn = trv;
+ pstat = prop.vecProp(trv_mn,srf);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector vecmn = trv_mn.vector();
+
+ double dy = (vecpl.get(i)-vecmn.get(i))/2.;
+
+ double dy1 = vecpl.get(i)-trv_0.vector(i);
+
+ if( !TRFMath.isZero(dy) )
+ {
+ if( Math.abs((dy1-dy)/dy) > 0.1 )
+ return;
+ }
+ else
+ {
+ if( Math.abs(dy1) > 1e-5 )
+ return;
+ }
+ if( Math.abs(Math.abs(dy1)-Math.abs(dy)) > 0.01 )
+ dy=dy1;
+
+ double dydx = dy/dx;
+
+ double didj = der.get(i,j);
+
+ if( Math.abs(didj) > 1e-10 )
+ Assert.assertTrue( Math.abs((dydx - didj)/didj) < prec );
+ else
+ Assert.assertTrue( Math.abs(dydx) < prec );
+ }
+}
lcsim/test/org/lcsim/recon/tracking/trfdca
diff -N PropDCACyl_t.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ PropDCACyl_t.java 25 Jul 2007 17:23:55 -0000 1.1
@@ -0,0 +1,374 @@
+/*
+ * PropDCACyl_t.java
+ *
+ * Created on July 24, 2007, 9:57 PM
+ *
+ * $Id: PropDCACyl_t.java,v 1.1 2007/07/25 17:23:55 ngraf Exp $
+ */
+
+package org.lcsim.recon.tracking.trfdca;
+
+import junit.framework.TestCase;
+import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.trfbase.ETrack;
+import org.lcsim.recon.tracking.trfbase.PropDir;
+import org.lcsim.recon.tracking.trfbase.PropStat;
+import org.lcsim.recon.tracking.trfbase.Propagator;
+import org.lcsim.recon.tracking.trfbase.Surface;
+import org.lcsim.recon.tracking.trfbase.TrackDerivative;
+import org.lcsim.recon.tracking.trfbase.TrackError;
+import org.lcsim.recon.tracking.trfbase.TrackVector;
+import org.lcsim.recon.tracking.trfbase.VTrack;
+import org.lcsim.recon.tracking.trfcyl.SurfCylinder;
+import org.lcsim.recon.tracking.trfutil.Assert;
+import org.lcsim.recon.tracking.trfutil.TRFMath;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class PropDCACyl_t extends TestCase
+{
+ private boolean debug;
+ /** Creates a new instance of PropDCACyl_t */
+ public void testPropDCACyl()
+ {
+ String ok_prefix = "PropDCACyl (I): ";
+ String error_prefix = "PropDCACyl test (E): ";
+
+ if(debug) System.out.println(ok_prefix
+ + "-------- Testing component PropDCACyl. --------" );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix + "Test constructor." );
+ double bfield = 2.0;
+ PropDCACyl prop = new PropDCACyl(bfield);
+ if(debug) System.out.println(prop );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix + "Test cloning." );
+ Assert.assertTrue( prop.newPropagator() != null);
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test the magnetic field." );
+ Assert.assertTrue( prop.bField() == bfield );
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test propagation of a track - without error." );
+
+ PropStat pstat = new PropStat();
+
+ TrackVector tvec = new TrackVector();
+ tvec.set(0, 10.0); // r_signed
+ tvec.set(1, 2.0); // z
+ tvec.set(2, 3.0); // phi_direction
+ tvec.set(3, 4.0); // tlm
+ tvec.set(4, 5.0); // qpt
+ SurfDCA sdca = new SurfDCA();
+ VTrack trv = new VTrack( sdca.newPureSurface(),tvec );
+ SpacePoint spt = trv.spacePoint();
+
+ if(debug) System.out.println(" *** Propagation to Cylinder of same r *** " );
+ SurfCylinder scys = new SurfCylinder(10.0);
+ VTrack trvsf = new VTrack(trv);
+ pstat = prop.vecDirProp(trvsf,scys,PropDir.FORWARD);
+ Assert.assertTrue( pstat.success() );
+ SpacePoint sptsf = trvsf.spacePoint();
+ TrackVector tvec_scys = trvsf.vector();
+ if(debug) System.out.println(" sptsf = " );
+ if(debug) System.out.println( sptsf );
+ if(debug) System.out.println(" tvec_scys = " + tvec_scys );
+ Assert.assertTrue( sptsf.rxy() == tvec.get(SurfDCA.IRSIGNED) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IZ) == tvec.get(SurfDCA.IZ) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IPHI) == spt.phi() );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.ITLM) == tvec.get(SurfDCA.ITLM) );
+ Assert.assertTrue( tvec_scys.get(SurfCylinder.IQPT) == tvec.get(SurfDCA.IQPT) );
+
+ SurfCylinder scyl = new SurfCylinder(15.);
+
+ if(debug) System.out.println(" *** Forward propagation *** " );
+ VTrack trv2f = new VTrack(trv);
+ if(debug) System.out.println(" before propagation: trv2f = " + trv2f );
+ SpacePoint spt2f = trv2f.spacePoint();
+ if(debug) System.out.println(" before propagation: spt2f = " );
+ if(debug) System.out.println(spt2f );
+ Assert.assertTrue( spt2f.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(spt2f.phi()-spt.phi()) < 1.e-4 );
+ Assert.assertTrue( spt2f.z() == 2.0 );
+ pstat = prop.vecDirProp(trv2f,scyl,PropDir.FORWARD);
+ Assert.assertTrue( pstat.forward() );
+ if(debug) System.out.println(" after propagation: trv2f = " + trv2f );
+ spt2f = trv2f.spacePoint();
+ if(debug) System.out.println(" after propagation: spt2f = " );
+ if(debug) System.out.println(spt2f );
+ Assert.assertTrue( spt2f.rxy() == 15.0 );
+
+ if(debug) System.out.println(" *** Backward propagation *** " );
+ VTrack trv2b = new VTrack(trv);
+ if(debug) System.out.println(" before propagation: trv2b = " + trv2b );
+ SpacePoint spt2b = trv2b.spacePoint();
+ if(debug) System.out.println(" before propagation: spt2b = " );
+ if(debug) System.out.println(spt2b );
+ Assert.assertTrue( spt2b.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(spt2b.phi()-spt.phi()) < 1.e-4 );
+ Assert.assertTrue( spt2b.z() == 2.0 );
+ pstat = prop.vecDirProp(trv2b,scyl,PropDir.BACKWARD);
+ Assert.assertTrue( pstat.backward() );
+ if(debug) System.out.println(" after propagation: trv2b = " + trv2b );
+ spt2b = trv2b.spacePoint();
+ if(debug) System.out.println(" after propagation: spt2b = " );
+ if(debug) System.out.println(spt2b );
+ Assert.assertTrue( spt2b.rxy() == 15.0 );
+
+
+ //********************************************************************
+
+ if(debug) System.out.println(ok_prefix
+ + "Test propagation of a track - with error." );
+
+ // PropStat pstat = new PropStat();
+
+ // TrackVector tvec = new TrackVector();
+ // tvec.set(0, 10.0); // r_signed
+ // tvec.set(1, 2.0); // z
+ // tvec.set(2, 3.0); // phi_direction
+ // tvec.set(3, 4.0); // tlm
+ // tvec.set(4, 5.0); // qpt
+ TrackError err = new TrackError();
+ err.set(0,0, 2.0);
+ err.set(0,1, 1.0);
+ err.set(0,2, 1.0);
+ err.set(0,3, 1.0);
+ err.set(0,4, 1.0);
+ err.set(1,1, 3.0);
+ err.set(1,2, 1.0);
+ err.set(1,3, 1.0);
+ err.set(1,4, 1.0);
+ err.set(2,2, 4.0);
+ err.set(2,3, 1.0);
+ err.set(2,4, 1.0);
+ err.set(3,3, 5.0);
+ err.set(3,4, 1.0);
+ err.set(4,4, 6.0);
+ // SurfDCA sdca;
+ ETrack etrv = new ETrack( sdca.newPureSurface(),tvec,err );
+ SpacePoint espt = etrv.spacePoint();
+
+ // SurfCylinder scyl = new SurfCylinder(15.);
+
+ if(debug) System.out.println(" *** Forward propagation *** " );
+ ETrack etrv2f = new ETrack(etrv);
+ if(debug) System.out.println(" before propagation: etrv2f = " + etrv2f );
+ SpacePoint espt2f = etrv2f.spacePoint();
+ if(debug) System.out.println(" before propagation: espt2f = " );
+ if(debug) System.out.println(espt2f );
+ Assert.assertTrue( espt2f.rxy() == 10.0 );
+ Assert.assertTrue( Math.abs(espt2f.phi()-espt.phi()) < 1.e-4 );
+ Assert.assertTrue( espt2f.z() == 2.0 );
+ if(debug) System.out.println("scyl= "+scyl);
+ if(debug) System.out.println("\n* etrv2f before: "+etrv2f);
+ pstat = prop.errDirProp(etrv2f,scyl,PropDir.FORWARD);
+ if(debug) System.out.println("\n* etrv2f after: "+etrv2f);
+ if(debug) System.out.println("pstat after propagation= "+pstat);
+ Assert.assertTrue( pstat.forward() );
+ if(debug) System.out.println(" after propagation: etrv2f = " + etrv2f );
+ espt2f = etrv2f.spacePoint();
+ if(debug) System.out.println(" after propagation: espt2f = " );
+ if(debug) System.out.println(espt2f );
+ Assert.assertTrue( espt2f.rxy() == 15.0 );
+ //********************************************************************
+
+ // Test non 0.0 DCA
+ if(debug) System.out.println("\n\n ***Testing non zero DCA \n\n");
+ int NUM = 10;
+ double[] rad =
+ {20.,2.0,Math.sqrt(5.)};
+ // double[] prec = { 1e-5,1e-5, 1e-5};
+ double[] xv =
+ { 0.5 , 0., 2. , 2., 2., 2., 2. ,2., 2. ,2.};
+ double[] yv =
+ { 0.4 , 0., -1., -1., -1., -1., -1. ,-1., -1. ,-1.};
+ double[] r =
+ { 1. , 0., 0.1, -0.1, -0.1, 0.1 , 0. , 0., -0.1 , 0.1};
+ double[] phid =
+ { 0.1, 0., 0.2, 0.2, 0.2 , 0.2 , 0. , 0., 0. , 0.};
+ double[] z =
+ { 2., 2., 2. , 2., 2., 2., 2. , 3., 2. , 3.};
+ double[] tlm =
+ { -4., 4., 4. , 4., 4., -4., 4. , 2., 4. , 2.};
+ double[] qpt =
+ { 0.1, 0., 0.01, 0.01,-0.01,-0.01,-0.01 , 0.01,0.0 ,0.};
+ for( int j=0; j <3 ;++j)
+ {
+ for(int i=0 ; i< NUM; ++i )
+ {
+ if(debug) System.out.println("\n\n\n\n "+j+" "+i);
+ SurfDCA srf = new SurfDCA(xv[i],yv[i]);
+ TrackVector vec = new TrackVector();
+ TrackError errnzdca = new TrackError();
+ for(int k=1;k<=5;++k) errnzdca.set(k-1,k-1,k);
+ vec.set(SurfDCA.IRSIGNED, r[i]);
+ vec.set(SurfDCA.IZ, z[i]);
+ vec.set(SurfDCA.IPHID, phid[i]);
+ vec.set(SurfDCA.ITLM, tlm[i]);
+ vec.set(SurfDCA.IQPT, qpt[i]);
+ ETrack tre = new ETrack( srf.newPureSurface());
+ tre.setVector(vec);
+ tre.setError(errnzdca);
+ tre.setForward();
+ SurfCylinder cyl = new SurfCylinder(rad[j]);
+ PropDCACyl propdca_cyl = new PropDCACyl( -2.);
+ PropCylDCA propcyl_dca = new PropCylDCA(-2.);
+ ETrack tre0 = new ETrack(tre);
+ ETrack treb = new ETrack(tre);
+ PropStat pstatnzdca = propdca_cyl.errDirProp(tre,cyl,PropDir.FORWARD);
+ Assert.assertTrue( pstatnzdca.success());
+ pstatnzdca = propdca_cyl.errDirProp(treb,cyl,PropDir.BACKWARD);
+ Assert.assertTrue( pstatnzdca.success());
+ check_derivatives(propdca_cyl,tre0,cyl);
+ ETrack tre1 = new ETrack(tre);
+ ETrack tre1b = new ETrack(treb);
+ pstatnzdca = propcyl_dca.errProp(tre,srf);
+ Assert.assertTrue( pstatnzdca.success());
+ pstatnzdca = propcyl_dca.errProp(treb,srf);
+ Assert.assertTrue( pstatnzdca.success());
+ check_derivatives(propcyl_dca,tre1,srf);
+ if(debug) System.out.println("checking equality \n"+tre0+" \n"+tre);
+ if(debug) System.out.println("about_equal: "+about_equal(tre0,tre));
+ //Assert.assertTrue(about_equal(tre0,tre));
+ check_derivatives(propcyl_dca,tre1b,srf);
+ // Assert.assertTrue(about_equal(tre0,treb));
+
+ }
+ }
+
+ //********************************************************************
+ if(debug) System.out.println(ok_prefix
+ + "------------- All tests passed. -------------" );
+
+ //********************************************************************
+
+ }
+ public static boolean about_equal(ETrack tre1, ETrack tre2)
+ {
+ boolean equal = true;
+ double maxdif = 1.e-6;
+ // Check vector.
+ TrackVector vdiff = tre1.surface().vecDiff( tre1.vector(), tre2.vector() );
+ for (int i=0; i<5; ++i)
+ {
+ double adif =Math.abs( vdiff.get(i) );
+ if ( ! (adif < maxdif) )
+ {
+ System.out.println("vecdif(" + i + ") = " + adif );
+ equal = false;
+ }
+ }
+ // Check errors.
+ TrackError ediff = tre1.error().minus(tre2.error());
+ TrackError eavg = tre1.error().plus(tre2.error());
+ for (int i=0; i<5; ++i)
+ {
+ for (int j=0; j<=i; ++j)
+ {
+ double adif = Math.abs( ediff.get(i,j) );
+ double afrac = ediff.get(i,j)/Math.sqrt(eavg.get(i,i)*eavg.get(j,j));
+ if ( !(adif < maxdif) )
+ {
+ System.out.println("errdif(" + i + "," + j + ") = " + adif + " frac = " + afrac );
+ equal = false;
+ }
+ }
+ }
+ return equal;
+ }
+
+ public static void check_derivatives( Propagator prop, VTrack trv0, Surface srf)
+ {
+ check_derivatives( prop, trv0, srf, 1.e-5);
+ }
+
+ public static void check_derivatives( Propagator prop, VTrack trv0, Surface srf,double prec)
+ {
+ for(int i=0;i<4;++i)
+ {
+ for(int j=0;j<4;++j)
+ {
+ check_derivative(prop,trv0,srf,i,j,prec);
+ }
+ }
+ }
+
+
+ public static void check_derivative( Propagator prop, VTrack trv0, Surface srf,int i,int j,double prec)
+ {
+
+ double dx = 1.e-3;
+ VTrack trv = new VTrack(trv0);
+ TrackVector vec = trv.vector();
+ boolean forward = trv0.isForward();
+
+ VTrack trv_0 = new VTrack(trv0);
+ TrackDerivative der = new TrackDerivative();
+ PropStat pstat = prop.vecProp(trv_0,srf,der);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector tmp=vec;
+ double tmpValue = tmp.get(j);
+ tmp.set(j, tmpValue+dx);
+ trv.setVector(tmp);
+ if(forward) trv.setForward();
+ else trv.setBackward();
+
+ VTrack trv_pl = new VTrack(trv);
+ pstat = prop.vecProp(trv_pl,srf);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector vecpl = trv_pl.vector();
+
+ tmp=vec;
+ tmpValue = tmp.get(j);
+ tmp.set(j, tmpValue-dx);
+ trv.setVector(tmp);
+ if(forward) trv.setForward();
+ else trv.setBackward();
+
+ VTrack trv_mn = trv;
+ pstat = prop.vecProp(trv_mn,srf);
+ Assert.assertTrue(pstat.success());
+
+ TrackVector vecmn = trv_mn.vector();
+
+ double dy = (vecpl.get(i)-vecmn.get(i))/2.;
+
+ double dy1 = vecpl.get(i)-trv_0.vector(i);
+
+ if( !TRFMath.isZero(dy) )
+ {
+ if( Math.abs((dy1-dy)/dy) > 0.1 )
+ return;
+ }
+ else
+ {
+ if( Math.abs(dy1) > 1e-5 )
+ return;
+ }
+ if( Math.abs(Math.abs(dy1)-Math.abs(dy)) > 0.01 )
+ dy=dy1;
+
+ double dydx = dy/dx;
+
+ double didj = der.get(i,j);
+
+ if( Math.abs(didj) > 1e-10 )
+ Assert.assertTrue( Math.abs((dydx - didj)/didj) < prec );
+ else
+ Assert.assertTrue( Math.abs(dydx) < prec );
+ }
+}
CVSspam 0.2.8