Commit in GeomConverter on MAIN
src/org/lcsim/geometry/subdetector/HPSEcal3.java+163-2201.2 -> 1.3
testResources/org/lcsim/geometry/subdetector/HPSEcal3Test.xml+2-21.3 -> 1.4
+165-222
2 modified files
hps ecal update

GeomConverter/src/org/lcsim/geometry/subdetector
HPSEcal3.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HPSEcal3.java	8 Sep 2011 07:26:06 -0000	1.2
+++ HPSEcal3.java	30 Apr 2012 18:04:38 -0000	1.3
@@ -1,5 +1,8 @@
 package org.lcsim.geometry.subdetector;
 
+import hep.graphics.heprep.HepRep;
+import hep.graphics.heprep.HepRepFactory;
+
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -9,6 +12,7 @@
 
 import org.jdom.Element;
 import org.jdom.JDOMException;
+import org.lcsim.detector.converter.heprep.DetectorElementToHepRepConverter;
 import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.geometry.IDDecoder;
@@ -19,10 +23,9 @@
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  * @author Timothy Nelson <[log in to unmask]>
- * @version $Id: HPSEcal3.java,v 1.2 2011/09/08 07:26:06 jeremy Exp $
+ * @version $Id: HPSEcal3.java,v 1.3 2012/04/30 18:04:38 jeremy Exp $
  */
-public class HPSEcal3 extends AbstractSubdetector
-{
+public class HPSEcal3 extends AbstractSubdetector {
     private int nx;
     private int ny;
     private double beamgap;
@@ -30,27 +33,21 @@
     private boolean oddX;
     List<CrystalRange> removeCrystals = new ArrayList<CrystalRange>();
 
-    public static class NeighborMap extends HashMap<Long,Set<Long>>
-    {
+    public static class NeighborMap extends HashMap<Long, Set<Long>> {
         IIdentifierHelper helper;
-        public NeighborMap(IIdentifierHelper helper)
-        {
+
+        public NeighborMap(IIdentifierHelper helper) {
             this.helper = helper;
         }
-        
-        public String toString()
-        {
+
+        public String toString() {
             System.out.println("NeighborMap has " + this.size() + " entries.");
             StringBuffer buff = new StringBuffer();
-            for (long id : this.keySet())
-            {
-                buff.append(helper.unpack(new Identifier(id)))
-                    .append("\n");
-                Set<Long> nei = this.get(id); 
-                for (long nid : nei)
-                {
-                    buff.append("  " + helper.unpack(new Identifier(nid)))
-                        .append("\n");
+            for (long id : this.keySet()) {
+                buff.append(helper.unpack(new Identifier(id))).append("\n");
+                Set<Long> nei = this.get(id);
+                for (long nid : nei) {
+                    buff.append("  " + helper.unpack(new Identifier(nid))).append("\n");
                 }
             }
             return buff.toString();
@@ -59,375 +56,317 @@
 
     private NeighborMap neighborMap = null;
 
-    HPSEcal3(Element node) throws JDOMException
-    {
+    HPSEcal3(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;
-                       
+
         // Setup range of indices to be skipped.
-        for (Object obj : layout.getChildren("remove"))
-        {
-            Element remove = (Element)obj;
-            try 
-            {
+        for (Object obj : layout.getChildren("remove")) {
+            Element remove = (Element) obj;
+            try {
                 removeCrystals.add(new CrystalRange(remove));
-            }
-            catch (Exception x)
-            {
+            } catch (Exception x) {
                 throw new RuntimeException(x);
             }
         }
-        
+
         /*
-        <remove ixmin="2" ixmax="10" iymin="-1" iymax="1"/>
-        */
+         * <remove ixmin="2" ixmax="10" iymin="-1" iymax="1"/>
+         */
     }
-    
-    private static class CrystalRange
-    {
+
+    private static class CrystalRange {
         int ixmin;
         int ixmax;
         int iymin;
         int iymax;
-                                              
-        CrystalRange(Element elem) throws Exception
-        {
+
+        CrystalRange(Element elem) throws Exception {
             ixmin = ixmax = iymin = iymax = 0;
-                                    
-            if (elem.getAttribute("ixmin") != null)
-            {
-                ixmin = elem.getAttribute("ixmin").getIntValue();                
-            }
-            else               
-            {
+
+            if (elem.getAttribute("ixmin") != null) {
+                ixmin = elem.getAttribute("ixmin").getIntValue();
+            } else {
                 throw new RuntimeException("Missing ixmin parameter.");
             }
-            
-            if (elem.getAttribute("ixmax") != null)
-            {
+
+            if (elem.getAttribute("ixmax") != null) {
                 ixmax = elem.getAttribute("ixmax").getIntValue();
-            }
-            else               
-            {
+            } else {
                 throw new RuntimeException("Missing ixmax parameter.");
             }
-            
-            if (elem.getAttribute("iymin") != null)
-            {
+
+            if (elem.getAttribute("iymin") != null) {
                 iymin = elem.getAttribute("iymin").getIntValue();
-            }
-            else               
-            {
+            } else {
                 throw new RuntimeException("Missing ixmax parameter.");
             }
-            
-            if (elem.getAttribute("iymax") != null)
-            {
+
+            if (elem.getAttribute("iymax") != null) {
                 iymax = elem.getAttribute("iymax").getIntValue();
-            }
-            else
-            {
+            } else {
                 throw new RuntimeException("Missing iymax parameter.");
-            }                                   
+            }
         }
     }
-    
-    private boolean isValidXY(int ix, int iy)
-    {
+
+    private boolean isValidXY(int ix, int iy) {
         if (!isValidX(ix))
             return false;
         if (!isValidY(iy))
             return false;
         return checkRange(ix, iy, this.removeCrystals);
     }
-    
-    private boolean checkRange(int ix, int iy, List<CrystalRange> ranges)
-    {
+
+    private boolean checkRange(int ix, int iy, List<CrystalRange> ranges) {
         if (ranges.size() == 0)
             return true;
-        for (CrystalRange range : ranges)
-        {
-            if ((ix >= range.ixmin && ix <= range.ixmax) 
-                    && ((iy >= range.iymin) && (iy <= range.iymax)))
-            {
+        for (CrystalRange range : ranges) {
+            if ((ix >= range.ixmin && ix <= range.ixmax) && ((iy >= range.iymin) && (iy <= range.iymax))) {
                 return false;
             }
-            
+
         }
         return true;
     }
-    
-    public double distanceToFace()
-    {
+
+    public double distanceToFace() {
         return dface;
     }
-    
-    public double beamGap()
-    {
+
+    public double beamGap() {
         return beamgap;
     }
-    
+
     /**
      * The number of crystals in X in one section.
+     * 
      * @return
      */
-    public double nx()
-    {
+    public double nx() {
         return nx;
     }
-    
+
     /**
      * The number of crystals in y in one section.
+     * 
      * @return
      */
-    public double ny()
-    {
+    public double ny() {
         return ny;
-    }   
-    
-    // Class for storing neighbor incides in XY and side.
-    static class XY implements Comparator<XY>
-    {
+    }
+
+    // Class for storing neighbor indices in XY and side.
+    static class XY implements Comparator<XY> {
         int x;
         int y;
-        
-        public XY(int x, int y)
-        {
+
+        public XY(int x, int y) {
             this.x = x;
             this.y = y;
         }
-        
-        public int x()
-        {
+
+        public int x() {
             return x;
         }
-        
-        public int y()
-        {
+
+        public int y() {
             return y;
         }
-                
-        public boolean equals(Object o)
-        {
-            XY xy = (XY)o;
-            return xy.x() == x && xy.y() == y; 
+
+        public boolean equals(Object o) {
+            XY xy = (XY) o;
+            return xy.x() == x && xy.y() == y;
         }
 
-        public int compare(XY o1, XY o2)
-        {
-            if (o1.equals(o2))
-            {
+        public int compare(XY o1, XY o2) {
+            if (o1.equals(o2)) {
                 return 0;
-            }
-            else
-            {
+            } else {
                 return -1;
             }
         }
     }
-    
+
     /**
-     * Get the neighbors for a given cell ID.  Each crystal not on an edge 
-     * has 8 neighbors.  Edge crystals have fewer.
-     * @param id The cell ID.
+     * Get the neighbors for a given cell ID. Each crystal not on an edge has 8 neighbors. Edge crystals have fewer.
+     * 
+     * @param id
+     *            The cell ID.
      * @return A <code>Set</code> containing the cell's neighbors.
      */
-    Set<Long> getNeighbors(Long id)
-    {        
+    Set<Long> getNeighbors(Long id) {
         // Get the IDDecoder.
-        IDDecoder dec = getIDDecoder();        
-        
+        IDDecoder dec = getIDDecoder();
+
         // Set the ID.
         dec.setID(id);
-        
+
         // Get ID field values.
         int x = dec.getValue("ix");
         int y = dec.getValue("iy");
-       
+
         // Get field indices.
         int ix = dec.getFieldIndex("ix");
         int iy = dec.getFieldIndex("iy");
-        
+
         // Get X, Y, & side neighbor data for this crystal.
         Set<XY> neighbors = getNeighbors(x, y);
 
         // Get buffer with values from current ID.
         int[] buffer = new int[dec.getFieldCount()];
-        dec.getValues(buffer);       
-        
+        dec.getValues(buffer);
+
         // Create an encoder to make neighbor IDs.
         IDEncoder enc = new IDEncoder(dec.getIDDescription());
-     
+
         // Set to hold neighbor IDs.
         Set<Long> ids = new HashSet<Long>();
-        
+
         // Loop over neighbor objects to make IDs.
-        for (XY xyside : neighbors)
-        {
+        for (XY xyside : neighbors) {
             buffer[ix] = xyside.x;
             buffer[iy] = xyside.y;
             long nId = enc.setValues(buffer);
             ids.add(nId);
         }
-        
+
         return ids;
     }
-    
-    Set<XY> getNeighbors(int ix, int iy)
-    {
+
+    Set<XY> getNeighbors(int ix, int iy) {
         Set<Integer> xneighbors = getXNeighbors(ix);
         Set<Integer> yneighbors = getYNeighbors(iy);
-        
+
         Set<XY> neighbors = new HashSet<XY>();
-        
-        for (Integer jx : xneighbors)
-        {
-            for (Integer jy : yneighbors)
-            {                
+
+        for (Integer jx : xneighbors) {
+            for (Integer jy : yneighbors) {
                 // Filter out self.
-                if (jx == ix && jy == iy)
-                {
+                if (jx == ix && jy == iy) {
                     continue;
                 }
-                
+
                 // Check for valid neighbor.
                 // FIXME: Duplication of isValidX + isValidY.
                 if (!isValidXY(jx, jy))
                     continue;
-                
-                neighbors.add(new XY(jx,jy));
+
+                neighbors.add(new XY(jx, jy));
             }
         }
-        
+
         return neighbors;
     }
-    
-    Set<Integer> getXNeighbors(int ix)
-    {
+
+    Set<Integer> getXNeighbors(int ix) {
         Set<Integer> neighbors = new HashSet<Integer>();
-        
+
         // Add self.
         neighbors.add(ix);
-        
+
         // Left neighbor.
-        if (isValidX(ix - 1))
-        {
+        if (isValidX(ix - 1)) {
             neighbors.add(ix - 1);
-        }
-        else if (isValidX(ix - 2))
-        {
+        } else if (isValidX(ix - 2)) {
             neighbors.add(ix - 2);
         }
-        
+
         // Right neighbor.
-        if (isValidX(ix + 1))
-        {
+        if (isValidX(ix + 1)) {
             neighbors.add(ix + 1);
-        }
-        else if (isValidX(ix + 2))
-        {
+        } else if (isValidX(ix + 2)) {
             neighbors.add(ix + 2);
-        }                
-        
+        }
+
         return neighbors;
     }
-    
-    Set<Integer> getYNeighbors(int iy)
-    {
+
+    Set<Integer> getYNeighbors(int iy) {
         Set<Integer> neighbors = new HashSet<Integer>();
-        
+
         // Add self.
         neighbors.add(iy);
-        
+
         // Lower neighbor.
-        if (isValidY(iy - 1))
-        {
+        if (isValidY(iy - 1)) {
             neighbors.add(iy - 1);
         }
-        
+
         // Upper neighbor.
-        if (isValidY(iy + 1))
-        {
+        if (isValidY(iy + 1)) {
             neighbors.add(iy + 1);
         }
-        
+
         return neighbors;
     }
-    
-    boolean isValidY(int iy)
-    {
+
+    boolean isValidY(int iy) {
         // Zero is not valid because ID scheme goes from 1.
         return iy >= -ny && iy <= ny && iy != 0;
     }
-    
-    boolean isValidX(int ix)
-    {
+
+    boolean isValidX(int ix) {
         // Even case.
-        if (!oddX)
-        {
-            return ix >= -nx/2 && ix <= nx/2 && ix != 0;
+        if (!oddX) {
+            return ix >= -nx / 2 && ix <= nx / 2 && ix != 0;
         }
         // Odd case.
-        else
-        {
-            return ix >= (-nx-1)/2 && ix <= (nx+1)/2;
+        else {
+            return ix >= (-nx - 1) / 2 && ix <= (nx + 1) / 2;
         }
     }
-        
+
     /**
      * Create a map of crystal IDs to the <code>Set</code> of neighbor crystal IDs.
+     * 
      * @return A map of neighbors for each crystal ID.
      */
-    public NeighborMap getNeighborMap()
-    {
-        if (neighborMap != null)
-        {
+    public NeighborMap getNeighborMap() {
+        if (neighborMap != null) {
             return neighborMap;
         }
-       
-        // Setup the private instance of the map. 
+
+        // Setup the private instance of the map.
         neighborMap = new NeighborMap(this.getDetectorElement().getIdentifierHelper());
-        
+
         IDDecoder dec = getIDDecoder();
         IDEncoder enc = new IDEncoder(dec.getIDDescription());
-        
+
         int nfields = dec.getFieldCount();
         int[] vals = new int[nfields];
 
         vals[dec.getFieldIndex("system")] = getSystemID();
-        
+
         int idxx = dec.getFieldIndex("ix");
         int idxy = dec.getFieldIndex("iy");
-        
-        int hnx = nx;        
-        
-        // Calculate number of X for loop.  (from LCDD conv)
-        if (oddX)
-        {
+
+        /*
+        int hnx = nx;
+
+        // Calculate number of X for loop. (from LCDD conv)
+        if (oddX) {
             hnx -= 1;
             hnx /= 2;
-        }
-        else
-        {
+        } else {
             hnx /= 2;
         }
-                
+        */
+
         // Loop over y.
-        for (int iy = -ny; iy <= ny; iy++)
-        {            
-            int loopx = (int)Math.floor(nx/2);
+        for (int iy = -ny; iy <= ny; iy++) {
+            int loopx = (int) Math.floor(nx / 2);
             // Loop over x.
-            for (int ix = -loopx; ix <= loopx; ix++)
-            {                                
+            for (int ix = -loopx; ix <= loopx; ix++) {
                 if (!isValidXY(ix, iy))
                     continue;
 
@@ -436,11 +375,15 @@
 
                 Long id = enc.setValues(vals);
                 Set<Long> neighbors = getNeighbors(id);
-                
+
                 neighborMap.put(id, neighbors);
             }
         }
-        
+
         return neighborMap;
-    }    
+    }
+
+    public void appendHepRep(HepRepFactory factory, HepRep heprep) {
+        DetectorElementToHepRepConverter.convert(getDetectorElement(), factory, heprep, -1, false, getVisAttributes().getColor());
+    }
 }
\ No newline at end of file

GeomConverter/testResources/org/lcsim/geometry/subdetector
HPSEcal3Test.xml 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- HPSEcal3Test.xml	30 Apr 2012 16:28:57 -0000	1.3
+++ HPSEcal3Test.xml	30 Apr 2012 18:04:38 -0000	1.4
@@ -26,7 +26,7 @@
         </material>
     </materials>
     <detectors>
-        <detector id="13" 
+        <detector id="2" 
                   name="ECAL" 
                   type="HPSEcal3" 
                   insideTrackingVolume="false" 
@@ -41,7 +41,7 @@
     <readouts>
         <readout name="ECAL_HITS">
             <segmentation type="GridXYZ" gridSizeX="0.0" gridSizeY="0.0" gridSizeZ="0.0" />
-            <id>system:6,side:-2,layer:4,ix:9,iy:9</id>
+            <id>system:6,side:-2,layer:4,ix:-8,iy:-6</id>
         </readout>
     </readouts>
 </lccdd>
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1