Commit in GeomConverter on MAIN
src/org/lcsim/geometry/Detector.java+6-221.30 -> 1.31
                      /FieldMap.java+5-21.2 -> 1.3
src/org/lcsim/geometry/compact/converter/lcdd/Dipole.java+41added 1.1
                                             /RZFieldMap.java+1-11.3 -> 1.4
                                             /Solenoid.java+2-11.2 -> 1.3
src/org/lcsim/geometry/compact/converter/lcdd/util/Dipole.java+33added 1.1
                                                  /Field.java+21.1 -> 1.2
                                                  /LCDD.java+51.17 -> 1.18
                                                  /LCDDFactory.java+15-11.2 -> 1.3
                                                  /Solenoid.java-21.2 -> 1.3
src/org/lcsim/geometry/field/Dipole.java+65added 1.1
                            /FieldOverlay.java+51added 1.1
                            /RZFieldMap.java+14-111.3 -> 1.4
                            /Solenoid.java+13-51.4 -> 1.5
test/org/lcsim/geometry/compact/sdjan03_compact.xml+5-11.17 -> 1.18
test/org/lcsim/geometry/field/FieldOverlayTest.java+48added 1.1
+306-46
5 added + 11 modified, total 16 files
JM: Add support for dipole field and field overlays to the compact description.

GeomConverter/src/org/lcsim/geometry
Detector.java 1.30 -> 1.31
diff -u -r1.30 -r1.31
--- Detector.java	8 Feb 2006 01:05:24 -0000	1.30
+++ Detector.java	5 May 2006 23:43:09 -0000	1.31
@@ -9,23 +9,16 @@
 
 import org.jdom.Element;
 import org.lcsim.geometry.compact.Field;
+import org.lcsim.geometry.field.FieldOverlay;
 import org.lcsim.geometry.compact.Readout;
 import org.lcsim.geometry.util.BaseIDDecoder;
 
 /**
  * @author tonyj
  */
-/* NOTE: This class created automatically by GeometryReader/GeometryFactory. */
-
 public class Detector extends org.lcsim.geometry.compact.Detector implements HepRepProvider
 {
-    /*
-     * FieldMap that is initialized to a dummy class. Reset by addField()
-     * method. -- JM
-     */
-    private FieldMap fieldMap = new DummyFieldMap();
-    private static final double[] dummyField =
-    { 0, 0, 0 };
+	private FieldOverlay fieldOverlay = new FieldOverlay();
 
     Detector(Element node)
     {
@@ -34,7 +27,7 @@
 
     public String getName()
     {
-        /* name from header in compact. */
+    	// The name from the compact header.
         return getDetectorName();
     }
 
@@ -51,7 +44,6 @@
         //System.out.println("Added subdet: " + sub.getName() );
     }
 
-    /* setup subdetector backlink in the IDDecoder */
     /*
      * FIXME: There is not a 1-to-1 between subdetectors and readouts. 
      * FIXME: This function is just a hack to setup the IDDecoder. There is probably a
@@ -77,13 +69,13 @@
 
     public FieldMap getFieldMap()
     {
-        return fieldMap;
+        return fieldOverlay;
     }
 
     protected void addField(Field field)
     {
-        super.addField(field);
-        fieldMap = (FieldMap) field; // assumes single field for now
+        super.addField((Field)field);
+        fieldOverlay.addField((FieldMap)field);
     }
 
     public void appendHepRep(HepRepFactory factory, HepRep heprep)
@@ -111,12 +103,4 @@
             }
         }
     }
-
-    private class DummyFieldMap implements FieldMap
-    {
-        public double[] getField(double[] position)
-        {
-            return dummyField;
-        }
-    }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry
FieldMap.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- FieldMap.java	8 Feb 2006 01:01:38 -0000	1.2
+++ FieldMap.java	5 May 2006 23:43:09 -0000	1.3
@@ -6,6 +6,9 @@
  */
 public interface FieldMap
 {
-   // Get the field magnitude and direction at a particular point.
-    public double[] getField(double[] position);
+	// Get the field magnitude and direction at a particular point.
+	public void getField(double[] position, double[] b);
+	
+	// @deprecated @use getField(double[], double[])
+	public double[] getField(double[] position);
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
Dipole.java added at 1.1
diff -N Dipole.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Dipole.java	5 May 2006 23:43:10 -0000	1.1
@@ -0,0 +1,41 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
+import org.lcsim.geometry.compact.converter.lcdd.util.LCDDFactory;
+
+public class Dipole extends LCDDField
+{
+	private Element node;
+	Dipole(Element element)
+	{
+		super(element);
+	    this.node = element;
+	}
+
+	void addToLCDD(LCDD lcdd) throws JDOMException
+	{
+		String name = node.getAttributeValue("name");
+		double zmax = node.getAttribute("zmax").getDoubleValue();
+		double zmin = node.getAttribute("zmin").getDoubleValue();
+		double rmax = node.getAttribute("rmax").getDoubleValue();
+		
+		int ncoeff = node.getChildren("dipoleCoeff").size();
+		double[] coeffs = new double[ncoeff];
+		int i = 0;
+		for (Object o : node.getChildren("dipoleCoeff"))
+		{
+			Element e = (Element)o;
+			double v = e.getAttribute("value").getDoubleValue();
+			coeffs[i] = v;
+			i++;
+		}
+		
+		org.lcsim.geometry.compact.converter.lcdd.util.Dipole dipole = 
+			LCDDFactory.createDipole(name, zmin, zmax, rmax, coeffs);
+		
+		lcdd.add(dipole);
+	}
+
+}

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
RZFieldMap.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- RZFieldMap.java	2 Sep 2005 00:35:02 -0000	1.3
+++ RZFieldMap.java	5 May 2006 23:43:09 -0000	1.4
@@ -87,6 +87,6 @@
             throw new RuntimeException("Error reading field map data", e);
         }
         
-        lcdd.setGlobalField(fmap);
+        //lcdd.setGlobalField(fmap);
     }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
Solenoid.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- Solenoid.java	9 Mar 2005 21:49:15 -0000	1.2
+++ Solenoid.java	5 May 2006 23:43:10 -0000	1.3
@@ -24,6 +24,7 @@
       sol.setZMax(node.getAttribute("zmax").getDoubleValue());
       // My inner radius is jeremy's outer radius
       sol.setInnerRadius(node.getAttribute("outer_radius").getDoubleValue());
-      lcdd.setGlobalField(sol);
+      lcdd.add(sol);
+      //lcdd.setGlobalField(sol);
    }
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Dipole.java added at 1.1
diff -N Dipole.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Dipole.java	5 May 2006 23:43:10 -0000	1.1
@@ -0,0 +1,33 @@
+package org.lcsim.geometry.compact.converter.lcdd.util;
+
+import org.jdom.Element;
+
+public class Dipole extends Field
+{
+	public Dipole(String name)
+	{
+		super("dipole", name);
+	}
+	
+	public void setZMax(double zmax)
+	{
+		setAttribute("zmax",String.valueOf(zmax));
+	}
+	
+	public void setZMin(double zmin)
+	{
+		setAttribute("zmin",String.valueOf(zmin));
+	}
+	
+	public void setRMax(double rmax)
+	{
+		setAttribute("rmax",String.valueOf(rmax));
+	}
+	
+	public void addCoeff(double coeff)
+	{
+		Element e = new Element("dipole_coeff");
+		e.setAttribute("value",String.valueOf(coeff));
+		addContent(e);
+	}
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Field.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Field.java	8 Mar 2005 02:58:29 -0000	1.1
+++ Field.java	5 May 2006 23:43:10 -0000	1.2
@@ -10,5 +10,7 @@
    public Field(String type, String name)
    {
       super(type,name);
+      setAttribute("lunit","mm");
+      setAttribute("funit","tesla");
    }
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDD.java 1.17 -> 1.18
diff -u -r1.17 -r1.18
--- LCDD.java	21 Jan 2006 02:30:01 -0000	1.17
+++ LCDD.java	5 May 2006 23:43:10 -0000	1.18
@@ -266,6 +266,11 @@
         getChild("sensitive_detectors").addContent(det);
     }
     
+    public void add(Field field)
+    {
+    	getChild("fields").addContent(field);
+    }
+    
     public void setGlobalField(Field field)
     {
         Element fields = getChild("fields");

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDDFactory.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- LCDDFactory.java	21 Jan 2006 02:30:01 -0000	1.2
+++ LCDDFactory.java	5 May 2006 23:43:10 -0000	1.3
@@ -8,7 +8,7 @@
  * in the org.lcsim.geometry.compact.converter.lcdd.util package.
  * 
  * @author jeremym
- * @version $Id: LCDDFactory.java,v 1.2 2006/01/21 02:30:01 jeremy Exp $
+ * @version $Id: LCDDFactory.java,v 1.3 2006/05/05 23:43:10 jeremy Exp $
  */
 public final class LCDDFactory
 {
@@ -420,4 +420,18 @@
 		}
 		return field;
 	}
+	
+	/** Create a Dipole magnetic field. */
+	public static Dipole createDipole(String name, double zmin, double zmax, double rmax, double[] coeffs)
+	{
+		Dipole dipole = new Dipole(name);
+		dipole.setZMax(zmax);
+		dipole.setZMin(zmin);
+		dipole.setRMax(rmax);
+		for (int i=0; i<coeffs.length; i++)
+		{
+			dipole.addCoeff(coeffs[i]);
+		}
+		return dipole;
+	}
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Solenoid.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- Solenoid.java	9 Mar 2005 21:49:16 -0000	1.2
+++ Solenoid.java	5 May 2006 23:43:10 -0000	1.3
@@ -11,8 +11,6 @@
    public Solenoid(String name)
    {
       super("solenoid", name);
-      setAttribute("lunit","mm");
-      setAttribute("funit","tesla");
       setAttribute("outer_radius","world_side");
    }
    public void setInnerField(double field)

GeomConverter/src/org/lcsim/geometry/field
Dipole.java added at 1.1
diff -N Dipole.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Dipole.java	5 May 2006 23:43:11 -0000	1.1
@@ -0,0 +1,65 @@
+package org.lcsim.geometry.field;
+
+import static java.lang.Math.pow;
+import static java.lang.Math.sqrt;
+
+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
+{
+	double[] coeffs;
+	double zmin;
+	double zmax;
+	double rmax;
+	
+	public Dipole(Element node) throws JDOMException
+	{
+		super(node);
+
+		zmin = node.getAttribute("zmin").getDoubleValue();
+		zmax = node.getAttribute("zmax").getDoubleValue();
+		rmax = node.getAttribute("rmax").getDoubleValue();
+
+		int ncoeff = node.getChildren("dipoleCoeff").size();
+		coeffs = new double[ncoeff];
+		
+		int i = 0;
+		for (Object o : node.getChildren("dipoleCoeff"))
+		{
+			Element e = (Element) o;
+			double coeff = e.getAttribute("value").getDoubleValue();
+			coeffs[i] = coeff;			
+			++i;
+		}
+	}
+
+	public void getField(double[] position, double[] b)
+	{
+		double bx = 0;
+		double z = position[2];
+		double r = sqrt(position[0] * position[0] + position[1] * position[1]);
+		
+		// Check if z coordinate is within dipole z bounds.
+		if (z > zmin && z < zmax && r < rmax)
+		{
+			// Apply all coefficients to this z coordinate.
+			for (int i = 0; i < coeffs.length; ++i)
+			{
+				bx += coeffs[i] * pow(z, i);
+			}
+
+			// Apply Bx to input array.
+			b[0] += bx;
+		}
+	}
+	
+	public double[] getField(double[] p)
+	{
+		double[] b = new double[3];
+		getField(p, b);
+		return b;
+	}
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/field
FieldOverlay.java added at 1.1
diff -N FieldOverlay.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ FieldOverlay.java	5 May 2006 23:43:11 -0000	1.1
@@ -0,0 +1,51 @@
+package org.lcsim.geometry.field;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lcsim.geometry.FieldMap;
+
+/**
+ * FieldOverlay is a FieldMap that itself
+ * contains a list of references to other FieldMaps.
+ * This setup supports the overlay of multiple
+ * magnetic fields, such as the detector solenoid 
+ * and the DiD.  
+ * 
+ * @see org.lcsim.geometry.Detector
+ * 
+ * @author Jeremy McCormick
+ */
+public class FieldOverlay implements FieldMap
+{
+	List<FieldMap> fields = 
+		new ArrayList<FieldMap>();
+	
+	public FieldOverlay()
+	{}
+	
+	public void addField(FieldMap field)
+	{
+		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)
+	{
+		for (FieldMap field : fields)
+		{
+			field.getField(pos, b);
+		}
+	}
+	
+	public double[] getField(double[] pos)
+	{
+		double[] b = new double[3];
+		getField(pos, b);
+		return b;
+	}
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/field
RZFieldMap.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- RZFieldMap.java	3 Sep 2005 01:04:36 -0000	1.3
+++ RZFieldMap.java	5 May 2006 23:43:11 -0000	1.4
@@ -93,8 +93,6 @@
         FileCache cache = new FileCache();
         File file = cache.getCachedFile(new URL(location));
         
-        URL url = new URL(location);
-        
         BufferedReader reader = new BufferedReader(new FileReader(file));
         
         for (;;)
@@ -137,9 +135,8 @@
         }
     }
     
-    public double[] getField(double[] position)
+    public void getField(double[] position, double[] b)
     {
-        double[] Bfield = new double[3];
         double r = sqrt( ( position[0] * position[0] ) + ( position[1] * position[1] ) );
         double z = position[2];
         
@@ -148,7 +145,7 @@
         
         if(abs(z)>maxZ || r>maxR)
         {
-            return Bfield;
+            return;
         }
         
         int iz = (int) ((abs(z)+0.001)/gridSizeZ);
@@ -157,7 +154,7 @@
         // outside
         if(iz<0 || ir>numBinsR)
         {
-            return Bfield;
+            return;
         }
         
         int izfar = 0;
@@ -205,11 +202,17 @@
         double hx = hr * cos(theta);
         double hy = hr * sin(theta);
         
-        Bfield[0] = hx;
-        Bfield[1] = hy;
-        Bfield[2] = hz;
-        
-        return Bfield;
+        b[0] += hx;
+        b[1] += hy;
+        b[2] += hz;
+    }
+    
+    // @deprecated
+    public double[] getField(double[] pos)
+    {
+    	double[] b = new double[3];
+    	getField(pos, b);
+    	return b;
     }
     
     public final int getNumBinsR()

GeomConverter/src/org/lcsim/geometry/field
Solenoid.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- Solenoid.java	24 Jul 2005 10:49:28 -0000	1.4
+++ Solenoid.java	5 May 2006 23:43:11 -0000	1.5
@@ -16,7 +16,7 @@
    private double[] outerField;
    private double zmax;
    private double outerRadius2;
-   private double[] noField = { 0, 0, 0 };
+   //private double[] noField = { 0, 0, 0 };
 
    Solenoid(Element node) throws JDOMException
    {
@@ -31,12 +31,20 @@
       outerRadius2 = r*r;
    }
 
-   public double[] getField(double[] position)
+   public void getField(double[] position, double[] b)
    {
-      if (Math.abs(position[2])>zmax) return noField;
+      if (Math.abs(position[2])>zmax) return;
       double r2 = position[0]*position[0] + position[1]*position[1];
-      if (r2 > outerRadius2) return outerField;
-      else return innerField;
+      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;
    }
 
    public double[] getInnerField()

GeomConverter/test/org/lcsim/geometry/compact
sdjan03_compact.xml 1.17 -> 1.18
diff -u -r1.17 -r1.18
--- sdjan03_compact.xml	16 Feb 2006 00:57:13 -0000	1.17
+++ sdjan03_compact.xml	5 May 2006 23:43:11 -0000	1.18
@@ -250,10 +250,14 @@
          </readout>
    </readouts>
    <fields>
-    <field type="Solenoid" name="GlobalSolenoid"
+    <field type="Solenoid" name="TestSolenoid"
               inner_field="5.0"
               outer_field="-0.6"
               zmax="1000"
               outer_radius="144*cm+(2+1)*34*cm"/>
+    <field type="Dipole" name="TestDipole" zmax="100.0" zmin="-100.0" rmax="1000.0">
+    	<dipoleCoeff value="1.0"/>
+    	<dipoleCoeff value="2.0"/>
+    </field>
    </fields>
 </lccdd>

GeomConverter/test/org/lcsim/geometry/field
FieldOverlayTest.java added at 1.1
diff -N FieldOverlayTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ FieldOverlayTest.java	5 May 2006 23:43:12 -0000	1.1
@@ -0,0 +1,48 @@
+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 FieldOverlayTest extends TestCase
+{
+    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 = 
+        	this.getClass().getResourceAsStream("/org/lcsim/geometry/compact/sdjan03_compact.xml");        
+        GeometryReader reader = new GeometryReader();
+        det = reader.read(in);
+    }
+    	
+    public void testFieldOverlay() throws Exception
+    {
+    	FieldMap field = det.getFieldMap();
+    	double[] p = {0,0,0};
+    	double[] v = field.getField(p);
+    	assert(v[0] > 0.0);
+    	assert(v[3] > 0.0);
+    	System.out.println(v[0] + " " + v[1] + " " + v[2]);
+    }    
+}
\ No newline at end of file
CVSspam 0.2.8