4 added + 7 modified, total 11 files
GeomConverter/test/org/lcsim/geometry/field
diff -N FieldTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ FieldTest.java 14 Sep 2007 23:01:54 -0000 1.1
@@ -0,0 +1,56 @@
+package org.lcsim.geometry.field;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import junit.framework.*;
+import org.lcsim.geometry.FieldMap;
+
+/**
+ *
+ * @author tonyj
+ */
+public abstract class FieldTest extends TestCase
+{
+ public FieldTest(String testName)
+ {
+ super(testName);
+ }
+
+ void testFieldAt(FieldMap map, double x, double y, double z, double bx, double by, double bz)
+ {
+ testFieldMethod1(map,x,y,z,bx,by,bz);
+ testFieldMethod2(map,x,y,z,bx,by,bz);
+ testFieldMethod3(map,x,y,z,bx,by,bz);
+ testFieldMethod4(map,x,y,z,bx,by,bz);
+ }
+ private void testFieldMethod1(FieldMap map, double x, double y, double z, double bx, double by, double bz)
+ {
+ double[] field = map.getField(new double[]{x,y,z});
+ assertEquals("Method 1, x",bx,field[0],1e-16);
+ assertEquals("Method 1, y",by,field[1],1e-16);
+ assertEquals("Method 1, z",bz,field[2],1e-16);
+ }
+ private void testFieldMethod2(FieldMap map, double x, double y, double z, double bx, double by, double bz)
+ {
+ Hep3Vector fieldVector = map.getField(new BasicHep3Vector(x,y,z));
+ assertEquals("Method 2, x",bx,fieldVector.x(),1e-16);
+ assertEquals("Method 2, y",by,fieldVector.y(),1e-16);
+ assertEquals("Method 2, z",bz,fieldVector.z(),1e-16);
+ }
+ private void testFieldMethod3(FieldMap map, double x, double y, double z, double bx, double by, double bz)
+ {
+ double[] field = { 9,9,9 };
+ map.getField(new double[]{x,y,z},field);
+ assertEquals("Method 3, x",bx,field[0],1e-16);
+ assertEquals("Method 3, y",by,field[1],1e-16);
+ assertEquals("Method 3, z",bz,field[2],1e-16);
+ }
+ private void testFieldMethod4(FieldMap map, double x, double y, double z, double bx, double by, double bz)
+ {
+ BasicHep3Vector fieldVector = new BasicHep3Vector(9,9,9);
+ map.getField(new BasicHep3Vector(x,y,z),fieldVector);
+ assertEquals("Method 4, x",bx,fieldVector.x(),1e-16);
+ assertEquals("Method 4, y",by,fieldVector.y(),1e-16);
+ assertEquals("Method 4, z",bz,fieldVector.z(),1e-16);
+ }
+}
GeomConverter/test/org/lcsim/geometry/field
diff -N SolenoidTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SolenoidTest.java 14 Sep 2007 23:01:54 -0000 1.1
@@ -0,0 +1,38 @@
+package org.lcsim.geometry.field;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.FieldMap;
+
+/**
+ *
+ * @author tonyj
+ */
+public class SolenoidTest extends FieldTest
+{
+ public SolenoidTest(String testName)
+ {
+ super(testName);
+ }
+
+ FieldMap createMap() throws JDOMException
+ {
+ Element element = new Element("solenoid");
+ element.setAttribute("inner_field","5.0");
+ element.setAttribute("outer_field","-1.0");
+ element.setAttribute("zmax","100");
+ element.setAttribute("outer_radius","50");
+ return new Solenoid(element);
+ }
+ void checkMap(FieldMap map)
+ {
+ testFieldAt(map, 0,0,0,0,0,5);
+ testFieldAt(map, 40,40,0,0,0,-1);
+ testFieldAt(map, 0,0,-150,0,0,0);
+ testFieldAt(map, 40,40,-150,0,0,0);
+ }
+ public void testSolenoid() throws JDOMException
+ {
+ checkMap(createMap());
+ }
+}
\ No newline at end of file
GeomConverter/test/org/lcsim/geometry/field
diff -N DipoleTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DipoleTest.java 14 Sep 2007 23:01:54 -0000 1.1
@@ -0,0 +1,41 @@
+package org.lcsim.geometry.field;
+
+import org.jdom.Element;
+
+/**
+ *
+ * @author tonyj
+ */
+public class DipoleTest extends FieldTest
+{
+ private Dipole dipole;
+ public DipoleTest(String testName)
+ {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception
+ {
+ Element element = new Element("dipole");
+ element.setAttribute("zmin","10");
+ element.setAttribute("zmax","20");
+ element.setAttribute("rmax","100");
+ for (int i=0; i<3; i++)
+ {
+ Element coeff = new Element("dipoleCoeff");
+ coeff.setAttribute("value",String.valueOf(5-i));
+ element.addContent(coeff);
+ }
+ dipole = new Dipole(element);
+ }
+
+ public void testDipole()
+ {
+ testFieldAt(dipole,0,0,0,0,0,0);
+ testFieldAt(dipole,0,0,40,0,0,0);
+ testFieldAt(dipole,80,80,15,0,0,0);
+ // FixMe: This is not correct
+ testFieldAt(dipole,0,0,15,740,0,0);
+ }
+
+}
GeomConverter/test/org/lcsim/geometry/field
diff -u -r1.3 -r1.4
--- FieldOverlayTest.java 16 May 2007 23:27:38 -0000 1.3
+++ FieldOverlayTest.java 14 Sep 2007 23:01:54 -0000 1.4
@@ -1,9 +1,7 @@
package org.lcsim.geometry.field;
import java.io.InputStream;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.jdom.JDOMException;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.FieldMap;
@@ -13,21 +11,16 @@
*
* @author jeremym
*/
-public class FieldOverlayTest extends TestCase
+public class FieldOverlayTest extends FieldTest
{
- Detector det;
+ private Detector det;
/** Creates a new instance of FieldOverlayTest */
public FieldOverlayTest(String name)
{
super(name);
}
-
- public static junit.framework.Test suite()
- {
- return new TestSuite(FieldOverlayTest.class);
- }
-
+
protected void setUp() throws Exception
{
InputStream in =
@@ -39,10 +32,20 @@
public void testFieldOverlay() throws Exception
{
FieldMap field = det.getFieldMap();
- double[] p = {0,0,0};
- double[] v = field.getField(p);
- assertTrue(v[0] > 0.0);
- assertTrue(v[2] > 0.0);
- //System.out.println(v[0] + " " + v[1] + " " + v[2]);
- }
+ testFieldAt(field,0,0,0,1,0,5);
+ }
+
+ public void testEmptyOverlay()
+ {
+ FieldOverlay overlay = new FieldOverlay();
+ testFieldAt(overlay,0,0,0,0,0,0);
+ }
+
+ public void testSingleOverlay() throws JDOMException
+ {
+ SolenoidTest test = new SolenoidTest("SolenoidTest");
+ FieldOverlay overlay = new FieldOverlay();
+ overlay.addField(test.createMap());
+ test.checkMap(overlay);
+ }
}
\ No newline at end of file
GeomConverter/test/org/lcsim/geometry/field
diff -u -r1.1 -r1.2
--- RZFieldMapTest.java 1 Sep 2005 22:33:59 -0000 1.1
+++ RZFieldMapTest.java 14 Sep 2007 23:01:54 -0000 1.2
@@ -1,40 +1,28 @@
-/*
- * RZFieldMapTest.java
- *
- * Created on September 1, 2005, 1:57 PM
- *
- */
-
package org.lcsim.geometry.field;
import java.io.InputStream;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.FieldMap;
import org.lcsim.geometry.GeometryReader;
/**
*
* @author jeremym
*/
-public class RZFieldMapTest extends TestCase
+public class RZFieldMapTest extends FieldTest
{
-
/** Creates a new instance of RZFieldMapTest */
public RZFieldMapTest(String name)
{
super(name);
}
-
- public static junit.framework.Test suite()
- {
- return new TestSuite(RZFieldMapTest.class);
- }
-
+
public void testRead() throws Exception
{
InputStream in = this.getClass().getResourceAsStream("/org/lcsim/geometry/field/RZFieldMapTest.xml");
GeometryReader reader = new GeometryReader();
Detector det = reader.read(in);
+ FieldMap map = det.getFieldMap();
+ testFieldAt(map,0,0,0,0,0,5.0011);
}
}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry
diff -u -r1.5 -r1.6
--- FieldMap.java 11 May 2007 00:21:09 -0000 1.5
+++ FieldMap.java 14 Sep 2007 23:01:54 -0000 1.6
@@ -11,14 +11,14 @@
{
/** Get the field magnitude and direction at a particular point.
* @param position The position at which the field is requested
- * @param b The field (the object is passed by reference and updated)
+ * @param b The field (the object is passed by reference and set to the correct field)
*/
public void getField(double[] position, double[] b);
/**
* Get the field magnitude and direction at a particular point. This method
* requires allocation of a new object on each call, and should therefore not
- * be used if it we be called many times.
+ * be used if it may be called many times.
* @param position The position at which the field is requested
* @return The field.
* @deprecated @use getField(double[], double[])
@@ -28,7 +28,7 @@
/**
* Get the field magnitude and direction at a particular point.
* @param position The position at which the field is requested.
- * @param field The field. If not <code>null</code> this is passed by reference and updated
+ * @param field The field. If not <code>null</code> this is passed by reference and set to the correct field
* @return The field. This will be the same object passed as field, unless field was <code>null</code>
*/
public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field);
GeomConverter/src/org/lcsim/geometry/field
diff -N AbstractFieldMap.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AbstractFieldMap.java 14 Sep 2007 23:01:54 -0000 1.1
@@ -0,0 +1,50 @@
+package org.lcsim.geometry.field;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import org.jdom.Element;
+import org.lcsim.geometry.FieldMap;
+import org.lcsim.geometry.compact.Field;
+
+/**
+ * Base class for field map implementations. Subclasses should override
+ * getXField, getYField, getZField as appropriate (the default implementation
+ * returns 0).
+ * @author tonyj
+ */
+abstract class AbstractFieldMap extends Field implements FieldMap
+{
+ AbstractFieldMap(Element node)
+ {
+ super(node);
+ }
+ abstract void getField(double x, double y, double z, BasicHep3Vector field);
+
+ public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field)
+ {
+ if (field == null) field = new BasicHep3Vector();
+ getField(position.x(),position.y(),position.z(),field);
+ return field;
+ }
+
+ public Hep3Vector getField(Hep3Vector position)
+ {
+ return getField(position,null);
+ }
+
+ public void getField(double[] position, double[] b)
+ {
+ BasicHep3Vector field = new BasicHep3Vector();
+ getField(position[0],position[1],position[2],field);
+ b[0] = field.x();
+ b[1] = field.y();
+ b[2] = field.z();
+ }
+
+ public double[] getField(double[] position)
+ {
+ BasicHep3Vector field = new BasicHep3Vector();
+ getField(position[0],position[1],position[2],field);
+ return field.v();
+ }
+}
GeomConverter/src/org/lcsim/geometry/field
diff -u -r1.6 -r1.7
--- Solenoid.java 9 Apr 2007 05:04:29 -0000 1.6
+++ Solenoid.java 14 Sep 2007 23:01:54 -0000 1.7
@@ -1,24 +1,20 @@
package org.lcsim.geometry.field;
import hep.physics.vec.BasicHep3Vector;
-import hep.physics.vec.Hep3Vector;
import org.jdom.Element;
import org.jdom.JDOMException;
-import org.lcsim.geometry.FieldMap;
-import org.lcsim.geometry.compact.Field;
/**
- * Solenoidal magentic field.
+ * Solenoidal magnetic field.
* @author tonyj
*/
-public class Solenoid extends Field implements FieldMap
+public class Solenoid extends AbstractFieldMap
{
private double[] innerField;
private double[] outerField;
private double zmax;
- private double outerRadius2;
- //private double[] noField = { 0, 0, 0 };
+ private double outerRadiusSquared;
Solenoid(Element node) throws JDOMException
{
@@ -30,23 +26,18 @@
outerField = new double[] { 0, 0, o};
zmax = node.getAttribute("zmax").getDoubleValue();
double r = node.getAttribute("outer_radius").getDoubleValue();
- outerRadius2 = r*r;
+ outerRadiusSquared = r*r;
}
- public void getField(double[] position, double[] b)
+ void getField(double x, double y, double z, BasicHep3Vector field)
{
- if (Math.abs(position[2])>zmax) return;
- double r2 = position[0]*position[0] + position[1]*position[1];
- if (r2 > outerRadius2) b[2] += outerField[2];
- else b[2] += innerField[2];
- }
-
- // @deprecated
- public double[] getField(double[] pos)
- {
- double[] b = new double[3];
- getField(pos, b);
- return b;
+ if (Math.abs(z)>zmax) field.setV(0,0,0);
+ else
+ {
+ double r2 = x*x + y*y;
+ double bz = (r2 > outerRadiusSquared) ? outerField[2] : innerField[2];
+ field.setV(0,0,bz);
+ }
}
public double[] getInnerField()
@@ -66,18 +57,6 @@
public double getOuterRadius2()
{
- return outerRadius2;
- }
-
- public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field)
- {
- if (field == null) field = new BasicHep3Vector();
- getField(position.v(),field.v());
- return field;
- }
-
- public Hep3Vector getField(Hep3Vector position)
- {
- return getField(position,null);
+ return outerRadiusSquared;
}
}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/field
diff -u -r1.5 -r1.6
--- RZFieldMap.java 9 Apr 2007 05:04:29 -0000 1.5
+++ RZFieldMap.java 14 Sep 2007 23:01:54 -0000 1.6
@@ -1,19 +1,10 @@
-/*
- * RZFieldMap.java
- *
- * Created on September 1, 2005, 12:59 PM
- *
- */
package org.lcsim.geometry.field;
import hep.physics.vec.BasicHep3Vector;
-import hep.physics.vec.Hep3Vector;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import org.lcsim.geometry.FieldMap;
-import org.lcsim.geometry.compact.Field;
import org.jdom.Element;
import org.jdom.JDOMException;
import java.net.URL;
@@ -28,8 +19,7 @@
*
* @author jeremym
*/
-public class RZFieldMap extends Field
- implements FieldMap
+public class RZFieldMap extends AbstractFieldMap
{
private int numBinsR;
private int numBinsZ;
@@ -39,6 +29,7 @@
private double maxZ;
private double maxR;
+ private double maxRSquared;
private String location;
@@ -62,17 +53,18 @@
{
throw new JDOMException("numBinsZ is invalid: " + numBinsZ);
}
+
+ /* FIXME: Hard-coded conversion of cm to mm. */
+ gridSizeR = node.getAttribute("gridSizeR").getDoubleValue() * 10;
+ gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue() * 10;
maxR = ( numBinsR - 1 ) * gridSizeR;
maxZ = ( numBinsZ - 1 ) * gridSizeZ;
+ maxRSquared = maxR*maxR;
BrArray = new double[numBinsZ][numBinsR];
BzArray = new double[numBinsZ][numBinsR];
-
- /* FIXME: Hard-coded conversion of cm to mm. */
- gridSizeR = node.getAttribute("gridSizeR").getDoubleValue() * 10;
- gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue() * 10;
-
+
location = node.getAttribute("url").getValue();
try
@@ -111,12 +103,12 @@
}
/* FIXME: Hard-coded unit conversion of cm to mm. */
- double z = Double.valueOf(chunks[0]).doubleValue() * 10;
- double r = Double.valueOf(chunks[1]).doubleValue() * 10;
+ double z = Double.parseDouble(chunks[0]) * 10;
+ double r = Double.parseDouble(chunks[1]) * 10;
/* FIXME: Hard-coded unit conversion of kilogauss to tesla. */
- double Bz = Double.valueOf(chunks[2]).doubleValue() / 10;
- double Br = Double.valueOf(chunks[3]).doubleValue() / 10;
+ double Bz = Double.parseDouble(chunks[2]) / 10;
+ double Br = Double.parseDouble(chunks[3]) / 10;
int iz= (int) ((z + 0.0001)/gridSizeZ);
int ir=(int) ((r + 0.0001)/gridSizeR);
@@ -137,25 +129,27 @@
}
}
- public void getField(double[] position, double[] b)
+ void getField(double x, double y, double z, BasicHep3Vector field)
{
- double r = sqrt( ( position[0] * position[0] ) + ( position[1] * position[1] ) );
- double z = position[2];
+ double rSquared = x*x + y*y;
double hz = 0;
double hr = 0;
- if(abs(z)>maxZ || r>maxR)
+ if(abs(z)>maxZ || rSquared>maxRSquared)
{
+ field.setV(0,0,0);
return;
}
-
+ double r = sqrt(rSquared);
+ // FIXME: .001?
int iz = (int) ((abs(z)+0.001)/gridSizeZ);
int ir = (int) ((r+0.001)/gridSizeR);
// outside
if(iz<0 || ir>numBinsR)
{
+ field.setV(0,0,0);
return;
}
@@ -200,35 +194,13 @@
if(z<0.0) hr = -hr;
- double theta = atan2(position[1], position[0]);
+ double theta = atan2(y, x);
double hx = hr * cos(theta);
double hy = hr * sin(theta);
- b[0] += hx;
- b[1] += hy;
- b[2] += hz;
+ field.setV(hx,hy,hz);
}
-
- // @deprecated
- public double[] getField(double[] pos)
- {
- double[] b = new double[3];
- getField(pos, b);
- return b;
- }
-
- public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field)
- {
- if (field == null) field = new BasicHep3Vector();
- getField(position.v(),field.v());
- return field;
- }
-
- public Hep3Vector getField(Hep3Vector position)
- {
- return getField(position,null);
- }
-
+
public final int getNumBinsR()
{
return numBinsR;
GeomConverter/src/org/lcsim/geometry/field
diff -u -r1.3 -r1.4
--- FieldOverlay.java 9 Apr 2007 05:04:29 -0000 1.3
+++ FieldOverlay.java 14 Sep 2007 23:01:54 -0000 1.4
@@ -30,19 +30,26 @@
fields.add(field);
}
- /**
- * @param pos An array of size 3 containing the position.
- * @param b An array of size 3 that is updated by this method to
- * contain the Bfield components (bx,by,bz) of the overlay at pos.
- */
public void getField(double[] pos, double[] b)
{
- b[0] = b[1] = b[2] = 0.;
- double[] temp = new double[3];
- for (FieldMap field : fields)
+ int size = fields.size();
+ if (size == 0)
{
- field.getField(pos, temp);
- for (int i=0; i<3; i++) b[i] += temp[i];
+ b[0] = b[1] = b[2] = 0.;
+ }
+ else if (size == 1)
+ {
+ fields.get(0).getField(pos,b);
+ }
+ else
+ {
+ double[] temp = new double[3];
+ b[0] = b[1] = b[2] = 0.;
+ for (FieldMap field : fields)
+ {
+ field.getField(pos, temp);
+ for (int i=0; i<3; i++) b[i] += temp[i];
+ }
}
}
@@ -56,13 +63,35 @@
public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field)
{
if (field == null) field = new BasicHep3Vector();
- getField(position.v(),field.v());
+ int size = fields.size();
+ if (size == 0)
+ {
+ field.setV(0,0,0);
+ }
+ else if (size == 1)
+ {
+ fields.get(0).getField(position,field);
+ }
+ else
+ {
+ double bx = 0;
+ double by = 0;
+ double bz = 0;
+ BasicHep3Vector temp = new BasicHep3Vector();
+ for (FieldMap map : fields)
+ {
+ map.getField(position,temp);
+ bx += temp.x();
+ by += temp.y();
+ bz += temp.z();
+ }
+ field.setV(bx,by,bz);
+ }
return field;
}
-
+
public Hep3Vector getField(Hep3Vector position)
{
return getField(position,null);
}
-
}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/field
diff -u -r1.2 -r1.3
--- Dipole.java 9 Apr 2007 05:04:29 -0000 1.2
+++ Dipole.java 14 Sep 2007 23:01:54 -0000 1.3
@@ -1,21 +1,16 @@
package org.lcsim.geometry.field;
import hep.physics.vec.BasicHep3Vector;
-import hep.physics.vec.Hep3Vector;
-import static java.lang.Math.pow;
-import static java.lang.Math.sqrt;
-
+import java.util.List;
import org.jdom.Element;
import org.jdom.JDOMException;
-import org.lcsim.geometry.FieldMap;
-import org.lcsim.geometry.compact.Field;
-public class Dipole extends Field implements FieldMap
+public class Dipole extends AbstractFieldMap
{
private double[] coeffs;
private double zmin;
private double zmax;
- private double rmax;
+ private double rSquaredMax;
public Dipole(Element node) throws JDOMException
{
@@ -23,57 +18,34 @@
zmin = node.getAttribute("zmin").getDoubleValue();
zmax = node.getAttribute("zmax").getDoubleValue();
- rmax = node.getAttribute("rmax").getDoubleValue();
+ double rmax = node.getAttribute("rmax").getDoubleValue();
+ rSquaredMax = rmax*rmax;
int ncoeff = node.getChildren("dipoleCoeff").size();
coeffs = new double[ncoeff];
int i = 0;
- for (Object o : node.getChildren("dipoleCoeff"))
+ for (Element e : (List<Element>) node.getChildren("dipoleCoeff"))
{
- Element e = (Element) o;
- double coeff = e.getAttribute("value").getDoubleValue();
- coeffs[i] = coeff;
- ++i;
+ coeffs[i++] = e.getAttribute("value").getDoubleValue();
}
}
-
- public void getField(double[] position, double[] b)
+ void getField(double x, double y, double z, BasicHep3Vector field)
{
double bx = 0;
- double z = position[2];
- double r = sqrt(position[0] * position[0] + position[1] * position[1]);
+ double rSquared = x*x + y*y;
+ double zPowerI = 1;
// Check if z coordinate is within dipole z bounds.
- if (z > zmin && z < zmax && r < rmax)
+ if (z > zmin && z < zmax && rSquared < rSquaredMax)
{
// Apply all coefficients to this z coordinate.
for (int i = 0; i < coeffs.length; ++i)
{
- bx += coeffs[i] * pow(z, i);
+ bx += coeffs[i] * zPowerI;
+ zPowerI *= z;
}
-
- // Apply Bx to input array.
- b[0] += bx;
}
- }
-
- public double[] getField(double[] p)
- {
- double[] b = new double[3];
- getField(p, b);
- return b;
- }
-
- public Hep3Vector getField(Hep3Vector position, BasicHep3Vector field)
- {
- if (field == null) field = new BasicHep3Vector();
- getField(position.v(),field.v());
- return field;
- }
-
- public Hep3Vector getField(Hep3Vector position)
- {
- return getField(position,null);
+ field.setV(bx,0,0);
}
}
\ No newline at end of file
CVSspam 0.2.8