3 added files
GeomConverter/src/org/lcsim/geometry/field
diff -N RZFieldMap.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RZFieldMap.java 1 Sep 2005 22:33:59 -0000 1.1
@@ -0,0 +1,239 @@
+/*
+ * RZFieldMap.java
+ *
+ * Created on September 1, 2005, 12:59 PM
+ *
+ */
+package org.lcsim.geometry.field;
+
+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;
+import org.lcsim.util.cache.FileCache;
+import static java.lang.Math.abs;
+import static java.lang.Math.sqrt;
+import static java.lang.Math.atan2;
+import static java.lang.Math.sin;
+import static java.lang.Math.cos;
+
+/**
+ *
+ * @author jeremym
+ */
+public class RZFieldMap extends Field
+ implements FieldMap
+{
+ int numBinsR;
+ int numBinsZ;
+
+ double gridSizeR;
+ double gridSizeZ;
+
+ double maxZ;
+ double maxR;
+
+ String location;
+
+ double[][] BrArray;
+ double[][] BzArray;
+
+ public RZFieldMap(Element node) throws JDOMException
+ {
+ super(node);
+
+ System.out.println("RZFieldMap");
+
+ numBinsR = node.getAttribute("numBinsR").getIntValue();
+
+ if (numBinsR < 2)
+ {
+ throw new JDOMException("numBinsR is invalid: " + numBinsR);
+ }
+
+ numBinsZ = node.getAttribute("numBinsZ").getIntValue();
+
+ if (numBinsZ < 2)
+ {
+ throw new JDOMException("numBinsZ is invalid: " + numBinsZ);
+ }
+
+ maxR = ( numBinsR - 1 ) * gridSizeR;
+ maxZ = ( numBinsZ - 1 ) * gridSizeZ;
+
+ BrArray = new double[numBinsZ][numBinsR];
+ BzArray = new double[numBinsZ][numBinsR];
+
+ gridSizeR = node.getAttribute("gridSizeR").getDoubleValue();
+ gridSizeZ = node.getAttribute("gridSizeZ").getDoubleValue();
+
+ location = node.getAttribute("url").getValue();
+
+ try
+ {
+ readFieldMap();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error reading field map from " + location, e);
+ }
+ }
+
+ private void readFieldMap() throws IOException
+ {
+ readFieldMap(this.location);
+ }
+
+ private void readFieldMap(String location) throws IOException
+ {
+ FileCache cache = new FileCache();
+ File file = cache.getCachedFile(new URL(location));
+
+ URL url = new URL(location);
+
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+
+ for (;;)
+ {
+ String line = reader.readLine();
+ if (line == null) break;
+ String[] chunks = line.trim().split(" +");
+
+ if ( chunks.length != 4 )
+ {
+ throw new IOException("Invalid RZ field map line: " + line);
+ }
+
+ double z = Double.valueOf(chunks[0]).doubleValue();
+ double r = Double.valueOf(chunks[1]).doubleValue();
+ double Bz = Double.valueOf(chunks[2]).doubleValue();
+ double Br = Double.valueOf(chunks[3]).doubleValue();
+
+ int iz= (int) ((z + 0.0001)/gridSizeZ);
+ int ir=(int) ((r + 0.0001)/gridSizeR);
+
+ if ( iz > ( numBinsZ - 1) )
+ {
+ throw new IOException("z bin out of range: " + iz);
+ }
+
+ if ( ir > ( numBinsR - 1) )
+ {
+ throw new IOException("r bin out of range:" + ir);
+ }
+
+ BzArray[iz][ir] = Bz;
+ BrArray[iz][ir] = Br;
+ }
+ }
+
+ public double[] getField(double[] position)
+ {
+ double[] Bfield = new double[3];
+ double r = sqrt( ( position[0] * position[0] ) + ( position[1] * position[1] ) );
+ double z = position[2];
+
+ double hz = 0;
+ double hr = 0;
+
+ if(abs(z)>maxZ || r>maxR)
+ {
+ return Bfield;
+ }
+
+ int iz = (int) ((abs(z)+0.001)/gridSizeZ);
+ int ir = (int) ((r+0.001)/gridSizeR);
+
+ // outside
+ if(iz<0 || ir>numBinsR)
+ {
+ return Bfield;
+ }
+
+ int izfar = 0;
+ if(iz>=numBinsZ)
+ {
+ izfar = 1;
+ iz = numBinsZ;
+ }
+
+ double bz0 = BzArray[iz][ir];
+ double br0 = BrArray[iz][ir];
+
+ double delz = 0.;
+ double delr = 0.;
+
+ double brdz = 0.;
+ double brdr = 0.;
+
+ if(r>0.0)
+ {
+ delr = r - ((float)ir) * gridSizeR;
+ brdz = (BrArray[iz+1][ir]-br0)/gridSizeZ;
+ brdr = (BrArray[iz][ir+1]-br0)/gridSizeR;
+ }
+
+ delz = abs(z) - ((float)iz) * gridSizeZ;
+
+ double bzdz = (BzArray[iz+1][ir]-bz0)/gridSizeZ;
+ double bzdr = (BzArray[iz][ir+1]-bz0)/gridSizeR;
+
+ if(izfar==1)
+ {
+ hz = bz0+bzdr*delr;
+ hr = br0+brdr*delr;
+ }
+ else
+ {
+ hz = bz0+bzdz*delz+bzdr*delr;
+ hr = br0+brdz*delz+brdr*delr;
+ }
+
+ if(z<0.0) hr = -hr;
+
+ double theta = atan2(position[1], position[0]);
+ double hx = hr * cos(theta);
+ double hy = hr * sin(theta);
+
+ Bfield[0] = hx;
+ Bfield[1] = hy;
+ Bfield[2] = hz;
+
+ return Bfield;
+ }
+
+ public final int getNumBinsR()
+ {
+ return numBinsR;
+ }
+
+ public final int getNumBinsZ()
+ {
+ return numBinsZ;
+ }
+
+ public final double getGridSizeR()
+ {
+ return gridSizeR;
+ }
+
+ public final double getGridSizeZ()
+ {
+ return gridSizeZ;
+ }
+
+ public final double getMaxZ()
+ {
+ return maxZ;
+ }
+
+ public final double getMaxR()
+ {
+ return maxR;
+ }
+}
\ No newline at end of file
GeomConverter/test/org/lcsim/geometry/field
diff -N RZFieldMapTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RZFieldMapTest.java 1 Sep 2005 22:33:59 -0000 1.1
@@ -0,0 +1,40 @@
+/*
+ * 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.GeometryReader;
+
+/**
+ *
+ * @author jeremym
+ */
+public class RZFieldMapTest extends TestCase
+{
+
+ /** 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);
+ }
+}
\ No newline at end of file
GeomConverter/test/org/lcsim/geometry/field
diff -N RZFieldMapTest.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RZFieldMapTest.xml 1 Sep 2005 22:33:59 -0000 1.1
@@ -0,0 +1,48 @@
+<!-- top-level compact description element -->
+<lccdd xmlns:lccdd="namespaceUrl"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+ xs:noNamespaceSchemaLocation="noNamespaceUrl">
+
+ <info name="TPCTest"
+ title="TPCTest"
+ author="Jeremy McCormick"
+ url="NONE">
+ <comment>Test of org.lcsim.geometry.subdetector.TPC class.</comment>
+ </info>
+
+ <!-- Constants -->
+ <define>
+ <constant name="cm" value="10"/>
+
+ <!-- world -->
+ <constant name="world_side" value="30000" />
+ <constant name="world_x" value="world_side" />
+ <constant name="world_y" value="world_side" />
+ <constant name="world_z" value="world_side" />
+
+ <!-- tracking region -->
+ <constant name="tracking_region_radius" value="1100.0*cm"/>
+ <constant name="tracking_region_zmax" value="150.0*cm"/>
+ </define>
+
+ <materials>
+ </materials>
+
+ <detectors>
+ </detectors>
+
+ <readouts>
+ <readout name="TPCHits">
+ <id>layer:10,system:3,barrel:3</id>
+ </readout>
+ </readouts>
+
+ <fields>
+ <field type="RZFieldMap" name="RZFieldMapTest"
+ gridSizeZ="10.0"
+ gridSizeR="10.0"
+ numBinsZ="64"
+ numBinsR="67"
+ url="http://www.lcsim.org/test/solenoid_5tesla.dat"/>
+ </fields>
+</lccdd>
\ No newline at end of file
CVSspam 0.2.8