Commit in GeomConverter on MAIN
src/org/lcsim/geometry/subdetector/HPSEcal.java+206added 1.1
testResources/org/lcsim/geometry/subdetector/HPSEcalTest.xml+59added 1.1
+265
2 added files
add missing class

GeomConverter/src/org/lcsim/geometry/subdetector
HPSEcal.java added at 1.1
diff -N HPSEcal.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSEcal.java	3 May 2011 00:41:30 -0000	1.1
@@ -0,0 +1,206 @@
+package org.lcsim.geometry.subdetector;
+
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+
+/**
+ * @author jeremym
+ */
+public class HPSEcal extends AbstractSubdetector
+{
+    private int nx;
+    private int ny;
+    private double beamgap;
+    private double dface;
+    private boolean oddX;
+    
+    HPSEcal(Element node) throws JDOMException
+    {
+        super(node);
+        
+        Element layout = node.getChild("layout");
+        
+        nx = layout.getAttribute("nx").getIntValue();
+        ny = layout.getAttribute("ny").getIntValue();
+        beamgap = layout.getAttribute("beamgap").getDoubleValue();
+        dface = layout.getAttribute("dface").getDoubleValue();
+        
+        if (nx % 2 != 0)
+            oddX = true;
+     }
+    
+    public double distanceToFace()
+    {
+        return dface;
+    }
+    
+    public double beamGap()
+    {
+        return beamgap;
+    }
+    
+    // Class for storing neighbor incides in XY and side.
+    public static class XYSide implements Comparator<XYSide>
+    {
+        int x;
+        int y;
+        int side;
+        
+        public XYSide(int x, int y, int side)
+        {
+            this.x = x;
+            this.y = y;
+            this.side = side;
+        }
+        
+        public int x()
+        {
+            return x;
+        }
+        
+        public int y()
+        {
+            return y;
+        }
+        
+        public int side()
+        {
+            return side;
+        }
+        
+        public boolean equals(Object o)
+        {
+            XYSide xy = (XYSide)o;
+            return xy.x() == x && xy.y() == y && xy.side() == side; 
+        }
+
+        public int compare(XYSide o1, XYSide o2)
+        {
+            if (o1.equals(o2))
+            {
+                return 0;
+            }
+            else
+            {
+                return -1;
+            }
+        }
+    }
+    
+    public Set<XYSide> getNeighbors(int ix, int iy, int side)
+    {
+        Set<Integer> xneighbors = getXNeighbors(ix);
+        Set<Integer> yneighbors = getYNeighbors(iy);
+        
+        Set<XYSide> neighbors = new HashSet<XYSide>();
+        
+        for (Integer jx : xneighbors)
+        {
+            for (Integer jy : yneighbors)
+            {                
+                // Filter out self.
+                if (jx == ix && jy == iy)
+                {
+                    continue;
+                }
+                
+                neighbors.add(new XYSide(jx,jy,side));
+            }
+        }
+        
+        return neighbors;
+    }
+    
+    public Set<Integer> getXNeighbors(int ix)
+    {
+        Set<Integer> neighbors = new HashSet<Integer>();
+        
+        // Add self.
+        neighbors.add(ix);
+        
+        // Left neighbor.
+        if (isValidX(ix - 1))
+        {
+            neighbors.add(ix - 1);
+        }
+        else if (isValidX(ix - 2))
+        {
+            neighbors.add(ix - 2);
+        }
+        
+        // Right neighbor.
+        if (isValidX(ix + 1))
+        {
+            neighbors.add(ix + 1);
+        }
+        else if (isValidX(ix + 2))
+        {
+            neighbors.add(ix + 2);
+        }                
+        
+        return neighbors;
+    }
+    
+    public Set<Integer> getYNeighbors(int iy)
+    {
+        Set<Integer> neighbors = new HashSet<Integer>();
+        
+        // Add self.
+        neighbors.add(iy);
+        
+        // Lower neighbor.
+        if (isValidY(iy - 1))
+        {
+            neighbors.add(iy - 1);
+        }
+        // Upper neighbor.
+        if (isValidY(iy + 1))
+        {
+            neighbors.add(iy + 1);
+        }
+        
+        return neighbors;
+    }
+    
+    public boolean isValidY(int iy)
+    {
+        // Zero is not valid because ID scheme goes from 1.
+        return iy > 0 && iy <= ny;
+    }
+    
+    public boolean isValidX(int ix)
+    {
+        // Even case.
+        if (!oddX)
+        {
+            return ix >= -nx/2 && ix <= nx/2 && ix != 0;
+        }
+        // Odd case.
+        else
+        {
+            return ix >= (-nx-1)/2 && ix <= (nx+1)/2;
+        }
+    }
+    
+    /**
+     * The number of crystals in X in one section.
+     * @return
+     */
+    public double nx()
+    {
+        return nx;
+    }
+    
+    /**
+     * The number of crystals in y in one section.
+     * @return
+     */
+    public double ny()
+    {
+        return ny;
+    }   
+}
\ No newline at end of file

GeomConverter/testResources/org/lcsim/geometry/subdetector
HPSEcalTest.xml added at 1.1
diff -N HPSEcalTest.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSEcalTest.xml	3 May 2011 00:41:30 -0000	1.1
@@ -0,0 +1,59 @@
+<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
+       xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+       xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
+
+    <info name="HPSEcalTest">
+        <comment>Test of class org.lcsim.geometry.compact.converter.lcdd.TestBeamCalorimeter</comment>
+    </info>
+    
+    <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="150.0*cm"/>
+        <constant name="tracking_region_zmax" value="200.0*cm"/>
+        
+    </define>
+    
+    <materials>
+    </materials>
+    
+    <detectors>
+        
+        <detector id="1" 
+                  name="HPSEcalTest" 
+                  type="HPSEcal" 
+                  insideTrackingVolume="false">
+            <!-- stuff goes here -->
+        </detector>
+    </detectors>
+
+<!--
+                  readout="CalHits"
+-->
+    
+    <readouts>
+<!--
+        <readout name="CalHits">
+            <segmentation type="GridXYZ" gridSizeX="10.0" gridSizeY="10.0" />
+            <id>system:3,barrel:2,layer:7,x:32:-16,y:-16</id>
+        </readout>
+-->
+    </readouts>
+    <fields>
+<!--
+        <field type="Solenoid" name="GlobalSolenoid"
+               inner_field="5.0"
+               outer_field="-0.6"
+               zmax="1000"
+               outer_radius="(221.0+ 5.0 + 17.5 + 40./2.)*cm"/>
+-->
+    </fields>
+</lccdd>
CVSspam 0.2.8