Print

Print


Commit in GeomConverter/src/org/lcsim on MAIN
detector/converter/compact/HPSEcal2Converter.java+18added 1.1
                          /HPSEcalConverter.java+18added 1.1
                          /DetectorConverter.java+140-1271.51 -> 1.52
geometry/compact/converter/lcdd/HPSEcal.java+8-21.11 -> 1.12
geometry/subdetector/HPSEcal.java+68-171.4 -> 1.5
+252-146
2 added + 3 modified, total 5 files
update to new ecal coord system; fix crystal neighboring algorithm

GeomConverter/src/org/lcsim/detector/converter/compact
HPSEcal2Converter.java added at 1.1
diff -N HPSEcal2Converter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSEcal2Converter.java	18 Jul 2011 21:01:53 -0000	1.1
@@ -0,0 +1,18 @@
+package org.lcsim.detector.converter.compact;
+
+import org.lcsim.geometry.compact.Detector;
+import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.subdetector.HPSEcal2;
+
+public class HPSEcal2Converter extends AbstractSubdetectorConverter
+{
+    public void convert(Subdetector subdet, Detector detector)
+    {
+        System.out.println(this.getClass().getCanonicalName());        
+    }
+    
+    public Class getSubdetectorType()
+    {
+        return HPSEcal2.class;
+    }
+}

GeomConverter/src/org/lcsim/detector/converter/compact
HPSEcalConverter.java added at 1.1
diff -N HPSEcalConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSEcalConverter.java	18 Jul 2011 21:01:53 -0000	1.1
@@ -0,0 +1,18 @@
+package org.lcsim.detector.converter.compact;
+
+import org.lcsim.geometry.compact.Detector;
+import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.subdetector.HPSEcal;
+
+public class HPSEcalConverter extends AbstractSubdetectorConverter
+{
+    public void convert(Subdetector subdet, Detector detector)
+    {
+        System.out.println(this.getClass().getCanonicalName());        
+    }
+    
+    public Class getSubdetectorType()
+    {
+        return HPSEcal.class;
+    }
+}

GeomConverter/src/org/lcsim/detector/converter/compact
DetectorConverter.java 1.51 -> 1.52
diff -u -r1.51 -r1.52
--- DetectorConverter.java	22 Jun 2011 21:30:05 -0000	1.51
+++ DetectorConverter.java	18 Jul 2011 21:01:53 -0000	1.52
@@ -33,7 +33,7 @@
 public class DetectorConverter implements IDetectorConverter
 {
     // Map of class to converter.
-    Map< Class, ISubdetectorConverter > subdetectorConverters = new HashMap< Class, ISubdetectorConverter >();
+    Map<Class, ISubdetectorConverter> subdetectorConverters = new HashMap<Class, ISubdetectorConverter>();
 
     // The parameters converter.
     ParametersConverter paramCnv = new ParametersConverter();
@@ -46,38 +46,39 @@
     // The SystemMap for setting up the IdentifierHelpers.
     SystemMap sysMap;
 
-    public IPhysicalVolume convert( Detector detector, Document doc ) throws JDOMException, IOException
+    public IPhysicalVolume convert(Detector detector, Document doc) throws JDOMException,
+            IOException
     {
         // Clear out old DetectorStore store before building new detector.
         DetectorStore.getInstance().clear();
 
         // Convert materials.
-        convertMaterials( "/org/lcsim/material/elements.xml" );
-        convertMaterials( "/org/lcsim/material/materials.xml" );
-        convertMaterials( doc );
+        convertMaterials("/org/lcsim/material/elements.xml");
+        convertMaterials("/org/lcsim/material/materials.xml");
+        convertMaterials(doc);
 
         // Construct the world volume.
-        IPhysicalVolume pvWorld = buildWorldVolume( detector );
+        IPhysicalVolume pvWorld = buildWorldVolume(detector);
 
         // Make the default navigator.
         PhysicalVolumeNavigatorStore.getInstance().reset();
-        PhysicalVolumeNavigatorStore.getInstance().createDefault( pvWorld );
+        PhysicalVolumeNavigatorStore.getInstance().createDefault(pvWorld);
 
         // Set the Detector's DetectorElement.
-        IDetectorElement deDet = new DeDetector( detector );
-        detector.setDetectorElement( deDet );
+        IDetectorElement deDet = new DeDetector(detector);
+        detector.setDetectorElement(deDet);
 
         // Construct the tracking volume.
-        buildTrackingVolume( pvWorld.getLogicalVolume(), detector );
+        buildTrackingVolume(pvWorld.getLogicalVolume(), detector);
 
         // Set the world volume.
-        detector.setWorldVolume( pvWorld );
+        detector.setWorldVolume(pvWorld);
 
         // Make the SystemMap.
-        sysMap = makeSystemMap( detector );
+        sysMap = makeSystemMap(detector);
 
         // Convert Subdetectors including creation of IdentifierHelpers.
-        convertSubdetectors( detector );
+        convertSubdetectors(detector);
 
         // Return the world volume.
         return pvWorld;
@@ -86,258 +87,270 @@
     public DetectorConverter()
     {
         // Simple cylindrical detectors.
-        addSubdetectorConverter( new CylindricalBarrelCalorimeterConverter() );
-        addSubdetectorConverter( new CylindricalEndcapCalorimeterConverter() );
-        addSubdetectorConverter( new MultiLayerTrackerConverter() );
-        addSubdetectorConverter( new DiskTrackerConverter() );
+        addSubdetectorConverter(new CylindricalBarrelCalorimeterConverter());
+        addSubdetectorConverter(new CylindricalEndcapCalorimeterConverter());
+        addSubdetectorConverter(new MultiLayerTrackerConverter());
+        addSubdetectorConverter(new DiskTrackerConverter());
 
         // Detailed tracker models.
-        addSubdetectorConverter( new SiTrackerBarrelConverter() );
-        addSubdetectorConverter( new SiTrackerEndcapConverter() );
-        addSubdetectorConverter( new SiTrackerEndcap2Converter() );
-        addSubdetectorConverter( new SiTrackerFixedTargetConverter() );
-        addSubdetectorConverter( new SiTrackerFixedTarget2Converter() );
-          addSubdetectorConverter( new SiTrackerSpectrometerConverter() );
+        addSubdetectorConverter(new SiTrackerBarrelConverter());
+        addSubdetectorConverter(new SiTrackerEndcapConverter());
+        addSubdetectorConverter(new SiTrackerEndcap2Converter());
+        addSubdetectorConverter(new SiTrackerFixedTargetConverter());
+        addSubdetectorConverter(new SiTrackerFixedTarget2Converter());
+        addSubdetectorConverter(new SiTrackerSpectrometerConverter());
 
         // Detailed calorimeter models.
-        addSubdetectorConverter( new PolyhedraBarrelCalorimeterConverter() );
-        addSubdetectorConverter( new PolyhedraBarrelCalorimeter2Converter() );
-        addSubdetectorConverter( new PolyhedraEndcapCalorimeter2Converter() );
-        addSubdetectorConverter( new PolyhedraEndcapCalorimeterConverter() );
-        addSubdetectorConverter( new EcalBarrelConverter() );
+        addSubdetectorConverter(new PolyhedraBarrelCalorimeterConverter());
+        addSubdetectorConverter(new PolyhedraBarrelCalorimeter2Converter());
+        addSubdetectorConverter(new PolyhedraEndcapCalorimeter2Converter());
+        addSubdetectorConverter(new PolyhedraEndcapCalorimeterConverter());
+        addSubdetectorConverter(new EcalBarrelConverter());
+
+        // HPS
+        addSubdetectorConverter(new HPSEcalConverter());
+        addSubdetectorConverter(new HPSEcal2Converter());
 
         // Support structures.
-        addSubdetectorConverter( new PolyconeSupportConverter() );
-        addSubdetectorConverter( new TubeSegmentConverter() );
+        addSubdetectorConverter(new PolyconeSupportConverter());
+        addSubdetectorConverter(new TubeSegmentConverter());
     }
 
-    private void addSubdetectorConverter( ISubdetectorConverter s )
+    private void addSubdetectorConverter(ISubdetectorConverter s)
     {
-        if ( subdetectorConverters.get( s.getSubdetectorType() ) != null )
+        if (subdetectorConverters.get(s.getSubdetectorType()) != null)
         {
-            throw new IllegalArgumentException( "Already have converter for <" + s.getSubdetectorType()
-                    .getCanonicalName() + "> !" );
+            throw new IllegalArgumentException("Already have converter for <"
+                    + s.getSubdetectorType().getCanonicalName() + "> !");
         }
 
-        subdetectorConverters.put( s.getSubdetectorType(), s );
+        subdetectorConverters.put(s.getSubdetectorType(), s);
     }
 
-    private ISubdetectorConverter getSubdetectorConverter( Class klass )
+    private ISubdetectorConverter getSubdetectorConverter(Class klass)
     {
-        return subdetectorConverters.get( klass );
+        return subdetectorConverters.get(klass);
     }
 
-    public IPhysicalVolume convert( Detector detector, String resource ) throws JDOMException, IOException
+    public IPhysicalVolume convert(Detector detector, String resource) throws JDOMException,
+            IOException
     {
-        return convert( detector, CompactDocumentBuilder.build( resource ) );
+        return convert(detector, CompactDocumentBuilder.build(resource));
     }
 
-    private void convertMaterials( Document doc ) throws JDOMException
+    private void convertMaterials(Document doc) throws JDOMException
     {
-        materialCnv.convert( doc );
+        materialCnv.convert(doc);
     }
 
-    private void convertMaterials( String resource ) throws JDOMException, IOException
+    private void convertMaterials(String resource) throws JDOMException, IOException
     {
-        Document doc = CompactDocumentBuilder.build( resource );
+        Document doc = CompactDocumentBuilder.build(resource);
 
-        for ( Object obj : doc.getRootElement().getChildren() )
+        for (Object obj : doc.getRootElement().getChildren())
         {
-            Element e = ( Element ) obj;
-            if ( e.getName().equals( "element" ) )
+            Element e = (Element) obj;
+            if (e.getName().equals("element"))
             {
-                elemCnv.convert( e );
+                elemCnv.convert(e);
             }
-            else if ( e.getName().equals( "material" ) )
+            else if (e.getName().equals("material"))
             {
-                matCnv.convert( e );
+                matCnv.convert(e);
             }
         }
     }
 
-    private void convertSubdetectors( Detector detector )
+    private void convertSubdetectors(Detector detector)
     {
         // Process all Subdetectors in the Detector.
-        for ( Subdetector subdetector : detector.getSubdetectors().values() )
+        for (Subdetector subdetector : detector.getSubdetectors().values())
         {
             // System.out.println("subdetector: " + subdetector.getName());
 
             // Find a converter for this type.
-            ISubdetectorConverter cnv = getSubdetectorConverter( subdetector.getClass() );
+            ISubdetectorConverter cnv = getSubdetectorConverter(subdetector.getClass());
 
-            if ( cnv != null )
+            if (cnv != null)
             {
                 // System.out.println("found cnv handling: " +
                 // cnv.getSubdetectorType().getCanonicalName());
-                DetectorElement subdetectorDE = ( DetectorElement ) cnv.makeSubdetectorDetectorElement(
-                        detector,
-                        subdetector );
+                DetectorElement subdetectorDE = (DetectorElement) cnv
+                        .makeSubdetectorDetectorElement(detector, subdetector);
 
-                // System.out.println("made subdet DE: " + subdetectorDE.getName());
+                // System.out.println("made subdet DE: " +
+                // subdetectorDE.getName());
 
                 // Make the IdentifierHelper for this Subdetector.
-                IIdentifierHelper helper = cnv.makeIdentifierHelper( subdetector, sysMap );
+                IIdentifierHelper helper = cnv.makeIdentifierHelper(subdetector, sysMap);
 
                 // Convert the parameters.
                 try
                 {
-                    paramCnv.convert( subdetector.getNode() );
+                    paramCnv.convert(subdetector.getNode());
                 }
-                catch ( JDOMException x )
+                catch (JDOMException x)
                 {
-                    throw new RuntimeException( x );
+                    throw new RuntimeException(x);
                 }
 
-                if ( subdetectorDE != null )
-                    subdetectorDE.setIdentifierHelper( helper );
+                if (subdetectorDE != null)
+                    subdetectorDE.setIdentifierHelper(helper);
 
-                // Build the Subdetector's geometry and associated DetectorElement(s).
-                cnv.convert( subdetector, detector );
+                // Build the Subdetector's geometry and associated
+                // DetectorElement(s).
+                cnv.convert(subdetector, detector);
 
                 // Get the top level Subdetector node back.
-                DetectorElement subdetDE = ( DetectorElement ) subdetector.getDetectorElement();
+                DetectorElement subdetDE = (DetectorElement) subdetector.getDetectorElement();
 
-                // Check if a DetectorElement was created. Some compact "detector" objects
-                // are not really detectors but dead material so this check is necessary
+                // Check if a DetectorElement was created. Some compact
+                // "detector" objects
+                // are not really detectors but dead material so this check is
+                // necessary
                 // to avoid errors.
-                if ( subdetDE != null )
+                if (subdetDE != null)
                 {
                     // Make the Parameters from the compact detector element
                     // and assign to the Subdetector's DetectorElement.
-                    subdetDE.setParameters( ParametersStore.getInstance().get( subdetector.getName() ) );
+                    subdetDE.setParameters(ParametersStore.getInstance().get(subdetector.getName()));
 
                     // Make the Subdetector IdentifierHelper from the IDDecoder
                     // and assign to the Subdetector's DetectorElement.
-                    if ( helper != null && subdetectorDE.getIdentifierHelper() == null )
-                        subdetDE.setIdentifierHelper( helper );
+                    if (helper != null && subdetectorDE.getIdentifierHelper() == null)
+                        subdetDE.setIdentifierHelper(helper);
 
                     // Make the identifiers for this Subdetector.
-                    cnv.makeIdentifiers( subdetector );
+                    cnv.makeIdentifiers(subdetector);
                 }
             }
             // else
             // {
-            // System.out.println("no converter found for " + subdetector.getName());
+            // System.out.println("no converter found for " +
+            // subdetector.getName());
             // }
             // System.out.println();
         }
     }
 
-    private void buildTrackingVolume( ILogicalVolume world, Detector detector )
+    private void buildTrackingVolume(ILogicalVolume world, Detector detector)
     {
-        Map< String, Constant > constants = detector.getConstants();
+        Map<String, Constant> constants = detector.getConstants();
 
-        if ( constants.get( "tracking_region_zmax" ) == null || constants.get( "tracking_region_radius" ) == null )
+        if (constants.get("tracking_region_zmax") == null
+                || constants.get("tracking_region_radius") == null)
         {
-            throw new RuntimeException( "Missing parameters for defining tracking region!" );
+            throw new RuntimeException("Missing parameters for defining tracking region!");
         }
 
-        double zmax = constants.get( "tracking_region_zmax" ).getValue();
-        double radius = constants.get( "tracking_region_radius" ).getValue();
+        double zmax = constants.get("tracking_region_zmax").getValue();
+        double radius = constants.get("tracking_region_radius").getValue();
 
-        Tube trackingTube = new Tube( "tracking_region_tube", 0, radius, zmax );
+        Tube trackingTube = new Tube("tracking_region_tube", 0, radius, zmax);
 
-        LogicalVolume trackingLV = new LogicalVolume( "tracking_region", trackingTube, MaterialStore.getInstance().get(
-                "Air" ) );
+        LogicalVolume trackingLV = new LogicalVolume("tracking_region", trackingTube, MaterialStore
+                .getInstance().get("Air"));
 
-        new PhysicalVolume( null, "tracking_region", trackingLV, world, 0 );
+        new PhysicalVolume(null, "tracking_region", trackingLV, world, 0);
     }
 
-    private IPhysicalVolume buildWorldVolume( Detector detector )
+    private IPhysicalVolume buildWorldVolume(Detector detector)
     {
-        Map< String, Constant > constants = detector.getConstants();
+        Map<String, Constant> constants = detector.getConstants();
 
-        if ( constants.get( "world_x" ) == null || constants.get( "world_y" ) == null || constants.get( "world_z" ) == null )
+        if (constants.get("world_x") == null || constants.get("world_y") == null
+                || constants.get("world_z") == null)
         {
-            throw new RuntimeException( "Missing world_x, world_y, or world_z!" );
+            throw new RuntimeException("Missing world_x, world_y, or world_z!");
         }
 
-        double x = constants.get( "world_x" ).getValue();
-        double y = constants.get( "world_y" ).getValue();
-        double z = constants.get( "world_z" ).getValue();
+        double x = constants.get("world_x").getValue();
+        double y = constants.get("world_y").getValue();
+        double z = constants.get("world_z").getValue();
 
-        IMaterial air = MaterialStore.getInstance().get( "Air" );
+        IMaterial air = MaterialStore.getInstance().get("Air");
 
-        Box boxWorld = new Box( "world_box", x, y, z );
+        Box boxWorld = new Box("world_box", x, y, z);
 
-        LogicalVolume lvWorld = new LogicalVolume( "world", boxWorld, air );
+        LogicalVolume lvWorld = new LogicalVolume("world", boxWorld, air);
 
-        PhysicalVolume pvWorld = new PhysicalVolume( null, "world", lvWorld, null, 0 );
+        PhysicalVolume pvWorld = new PhysicalVolume(null, "world", lvWorld, null, 0);
 
         return pvWorld;
     }
 
-    // Converts the subdetectors in a detector to a map of subsystems to system id.
+    // Converts the subdetectors in a detector to a map of subsystems to system
+    // id.
     // TODO: Must be a better way to setup these associations in the
     // DetectorIdentifierHelper.
-    public static final SystemMap makeSystemMap( Detector d )
+    public static final SystemMap makeSystemMap(Detector d)
     {
         SystemMap m = new SystemMap();
 
-        for ( Subdetector subdet : d.getSubdetectors().values() )
+        for (Subdetector subdet : d.getSubdetectors().values())
         {
             String name = subdet.getName();
 
             int sys = subdet.getSystemID();
 
             // Based on naming conventions from sid01 and sid02.
-            if ( !name.contains( "Support" ) && !( subdet instanceof PolyconeSupport ) )
+            if (!name.contains("Support") && !(subdet instanceof PolyconeSupport))
             {
-                if ( name.contains( "VertexBarrel" ) )
+                if (name.contains("VertexBarrel"))
                 {
-                    m.put( "vtxBarrel", sys );
+                    m.put("vtxBarrel", sys);
                 }
-                else if ( name.contains( "VertexEndcap" ) )
+                else if (name.contains("VertexEndcap"))
                 {
-                    m.put( "vtxEndcap", sys );
+                    m.put("vtxEndcap", sys);
                 }
-                else if ( name.contains( "TrackerBarrel" ) )
+                else if (name.contains("TrackerBarrel"))
                 {
-                    m.put( "sitBarrel", sys );
+                    m.put("sitBarrel", sys);
                 }
-                else if ( name.contains( "TrackerEndcap" ) )
+                else if (name.contains("TrackerEndcap"))
                 {
-                    m.put( "sitEndcap", sys );
+                    m.put("sitEndcap", sys);
                 }
-                else if ( name.contains( "TrackerForward" ) )
+                else if (name.contains("TrackerForward"))
                 {
-                    m.put( "sitForward", sys );
+                    m.put("sitForward", sys);
                 }
-                else if ( name.contains( "TPC" ) )
+                else if (name.contains("TPC"))
                 {
-                    m.put( "tpc", sys );
+                    m.put("tpc", sys);
                 }
-                else if ( name.contains( "EMBarrel" ) )
+                else if (name.contains("EMBarrel"))
                 {
-                    m.put( "ecalBarrel", sys );
+                    m.put("ecalBarrel", sys);
                 }
-                else if ( name.contains( "EMEndcap" ) && !name.contains( "Forward" ) )
+                else if (name.contains("EMEndcap") && !name.contains("Forward"))
                 {
-                    m.put( "ecalEndcap", sys );
+                    m.put("ecalEndcap", sys);
                 }
-                else if ( name.contains( "HADBarrel" ) )
+                else if (name.contains("HADBarrel"))
                 {
-                    m.put( "hcalBarrel", sys );
+                    m.put("hcalBarrel", sys);
                 }
-                else if ( name.contains( "HADEndcap" ) )
+                else if (name.contains("HADEndcap"))
                 {
-                    m.put( "hcalEndcap", sys );
+                    m.put("hcalEndcap", sys);
                 }
-                else if ( name.contains( "MuonBarrel" ) )
+                else if (name.contains("MuonBarrel"))
                 {
-                    m.put( "muonBarrel", sys );
+                    m.put("muonBarrel", sys);
                 }
-                else if ( name.contains( "MuonEndcap" ) )
+                else if (name.contains("MuonEndcap"))
                 {
-                    m.put( "muonEndcap", sys );
+                    m.put("muonEndcap", sys);
                 }
-                else if ( name.contains( "LuminosityMonitor" ) || name.contains( "LumiCal" ) )
+                else if (name.contains("LuminosityMonitor") || name.contains("LumiCal"))
                 {
-                    m.put( "lumi", sys );
+                    m.put("lumi", sys);
                 }
-                else if ( name.contains( "ForwardEMEndcap" ) )
+                else if (name.contains("ForwardEMEndcap"))
                 {
-                    m.put( "ecalForward", sys );
+                    m.put("ecalForward", sys);
                 }
             }
         }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
HPSEcal.java 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- HPSEcal.java	14 Jul 2011 22:59:17 -0000	1.11
+++ HPSEcal.java	18 Jul 2011 21:01:53 -0000	1.12
@@ -40,7 +40,7 @@
  * @author Jeremy McCormick <[log in to unmask]>
  * @author Tim Nelson <[log in to unmask]>
  * 
- * @version $Id: HPSEcal.java,v 1.11 2011/07/14 22:59:17 jeremy Exp $
+ * @version $Id: HPSEcal.java,v 1.12 2011/07/18 21:01:53 jeremy Exp $
  */
 public class HPSEcal extends LCDDSubdetector
 {
@@ -188,7 +188,10 @@
                 
                 // Add volume IDs.
                 posCrystalPlacement.addPhysVolID("ix", ix);
-                posCrystalPlacement.addPhysVolID("iy", iy);                               
+                posCrystalPlacement.addPhysVolID("iy", iy);            
+
+                // DEBUG
+                System.out.println(ix + ", " + iy);
 
                 // Reflection to negative.
                 if (ix != 0)
@@ -208,6 +211,9 @@
                     // Add volume IDs.
                     negCrystalPlacement.addPhysVolID("ix", -ix);
                     negCrystalPlacement.addPhysVolID("iy", iy);
+                    
+                    // DEBUG
+                    System.out.println(-ix + ", " + iy);
                 }                
 
                 // Increment running X and Z totals and include tolerance to avoid overlaps.

GeomConverter/src/org/lcsim/geometry/subdetector
HPSEcal.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- HPSEcal.java	14 Jul 2011 22:59:17 -0000	1.4
+++ HPSEcal.java	18 Jul 2011 21:01:53 -0000	1.5
@@ -3,7 +3,6 @@
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.jdom.Element;
@@ -15,6 +14,8 @@
  * Reconstruction version of HPS ECal with crystal array.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
+ * @author Timothy Nelson <[log in to unmask]>
+ * @version $Id: HPSEcal.java,v 1.5 2011/07/18 21:01:53 jeremy Exp $
  */
 public class HPSEcal extends AbstractSubdetector
 {
@@ -23,7 +24,12 @@
     private double beamgap;
     private double dface;
     private boolean oddX;
-    
+
+    public static class NeighborMap extends HashMap<Long,Set<Long>>
+    {}
+
+    private NeighborMap neighborMap = null;
+
     HPSEcal(Element node) throws JDOMException
     {
         super(node);
@@ -264,9 +270,21 @@
      * 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 Map<Long,Set<Long>> makeNeighborsMap()
+    public NeighborMap makeNeighborMap()
     {
-        Map<Long,Set<Long>> neighborsMap = new HashMap<Long,Set<Long>>();
+        if (neighborMap != null)
+        {
+            //System.out.println("Returning existing neighbor map ...");
+            return neighborMap;
+        }
+
+        //System.out.println(this.getClass().getCanonicalName() + " - makeNeighborsMap");
+        
+        //System.out.println("  nx = " + nx);
+        //System.out.println("  ny  = " + ny);        
+       
+        // Setup the private instance of the map. 
+        neighborMap = new NeighborMap();
         
         IDDecoder dec = getIDDecoder();
         IDEncoder enc = new IDEncoder(dec.getIDDescription());
@@ -278,27 +296,60 @@
         
         int idxx = dec.getFieldIndex("ix");
         int idxy = dec.getFieldIndex("iy");
+        
+        int hnx = nx;        
+        
+        // Calculate number of X for loop.  (from LCDD conv)
+        if (oddX)
+        {
+            hnx -= 1;
+            hnx /= 2;
+        }
+        else
+        {
+            hnx /= 2;
+        }
                 
         for (int side=-1; side <=1; side++)
-        {
+        {            
+            if (side == 0) continue;            
             vals[dec.getFieldIndex("side")] = side;
-            if (side == 0) continue;
             for (int iy=1; iy<=ny; iy++)
-            {
-                for (int ix=0; ix<=nx; ix++)
-                {                             
-                    vals[idxx] = ix;
-                    vals[idxy] = iy;
-                    
-                    Long id = enc.setValues(vals);
+            {                
+                for (int ix=0; ix<=hnx; ix++)
+                {                                                                                       
+                    // Loop for positive and negative x.
+                    for (int j=-1; j<=1; j++)
+                    {
+                        if (j == 0)
+                            continue;
+                        
+                        //
+                        //System.out.println("side = " + side);
+                        //System.out.println("ix = " + ix);
+                        //System.out.println("iy = " + iy);
+                        //System.out.println("j = " + j);
+                        
+                        vals[idxx] = ix*j;
+                        vals[idxy] = iy;
+                                
+                        //System.out.println(new ExpandedIdentifier(vals));
 
-                    Set<Long> neighbors = getNeighbors(id);
+                        Long id = enc.setValues(vals);
+                        Set<Long> neighbors = getNeighbors(id);
+                    
+                        // DEBUG
+                        //for (Long nid : neighbors)
+                        //{
+                        //    System.out.println("  " + this.getDetectorElement().getIdentifierHelper().unpack(new Identifier(nid)));
+                        //}
                     
-                    neighborsMap.put(id, neighbors);
+                        neighborMap.put(id, neighbors);
+                    }
                 }
             }
         }
         
-        return neighborsMap;
+        return neighborMap;
     }
-}
\ No newline at end of file
+}
CVSspam 0.2.8