Print

Print


Commit in GeomConverter on MAIN
src/org/lcsim/geometry/compact/Detector.java+135-1091.10 -> 1.11
src/org/lcsim/geometry/compact/converter/lcdd/CylindricalEndcapCalorimeter.java+2-11.10 -> 1.11
                                             /ForwardDetector.java+1-11.6 -> 1.7
                                             /LCDDSubdetector.java+24-141.5 -> 1.6
src/org/lcsim/geometry/layer/LayerFromCompactCnv.java+8-51.2 -> 1.3
test/org/lcsim/geometry/GeometryReaderTest.java+85-231.3 -> 1.4
+255-153
6 modified files
Tweaks for layering engine.

GeomConverter/src/org/lcsim/geometry/compact
Detector.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- Detector.java	18 Jul 2005 18:00:03 -0000	1.10
+++ Detector.java	18 Jul 2005 22:04:10 -0000	1.11
@@ -1,9 +1,7 @@
 package org.lcsim.geometry.compact;
-
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import org.jdom.Element;
 import org.lcsim.material.XMLMaterialManager;
 
@@ -13,111 +11,139 @@
  */
 public class Detector
 {
-   private Header header;
-   private Map<String,Constant> constants = new HashMap<String,Constant>();
-   private Map<String,Subdetector> subdetectors = new HashMap<String,Subdetector>();
-   private Map<String,Readout> readouts = new HashMap<String,Readout>();
-   private Map<String,Field> fields = new HashMap<String,Field>();   
-   
-   protected XMLMaterialManager materialMgr;
-   
-   /**
-    * Called by the reader to create a new Detector
-    * @param element The JDOM element corresponding to the detector definition in the XML file.
-    */
-   protected Detector(Element element)
-   {       
-        materialMgr = XMLMaterialManager.create(XMLMaterialManager.materials() );        
-   }
-   
-   /**
-    * Called by the reader to associate a header with this detector
-    * @param header The header.
-    */
-   protected void setHeader(Header header)
-   {
-      this.header = header;
-   }
-   /**
-    * Get the header associated with this detector.
-    * @return The header
-    */
-   public Header getHeader()
-   {
-      return header;
-   }
-   
-   /**
-    * Get the detector name from the header.
-    * @return the detector name
-    */
-   public String getDetectorName()
-   {
-       return getHeader().getDetectorName();
-   }
-   
-   /**
-    * Called by the reader to add a constant to this detector.
-    * @param c The constant to add.
-    */
-   protected void addConstant(Constant c)
-   {
-      constants.put(c.getName(),c);
-   }
-   /**
-    * Get the constants associated with this detector.
-    * @return A map of containing all of the constants, indexed by name.
-    */
-   public Map<String,Constant> getConstants()
-   {
-      return constants;
-   }
-   /**
-    * Called by the reader to add a new Readout to this detector.
-    * @param r The readout to add.
-    */
-   protected void addReadout(Readout r)
-   {
-      //System.out.println("geometry.compact.Detector.addReadout() - " + r.getName() );
-      readouts.put(r.getName(),r);
-   }
-   /**
-    * Get the readouts associated with this detector.
-    * @return A map of containing all of the readouts, indexed by name.
-    */
-   public Map<String, Readout> getReadouts()
-   {
-      return readouts;
-   }
-   /**
-    * Called by the reader to add a sub-detector to this detector.
-    * @param sub The sub-detector to add.
-    */
-   protected void addSubdetector(Subdetector sub)
-   {
-      subdetectors.put(sub.getName(),sub);
-   }
-   /**
-    * Get the sub-detectors associated with this detector.
-    * @return A map of containing all of the sub-detectors, indexed by name.
-    */
-   public Map<String,Subdetector> getSubdetectors()
-   {
-      return subdetectors;
-   }
-   
-   protected void addField(Field field)
-   {
-      fields.put(field.getName(),field);
-   }
-   
-   public Map<String,Field> getFields()
-   {
-      return fields;
-   }        
-   
-   public XMLMaterialManager getMaterialManager()
-   {
+    private Header header;
+    private Map<String,Constant> constants = new HashMap<String,Constant>();
+    private Map<String,Subdetector> subdetectors = new HashMap<String,Subdetector>();
+    private Map<String,Readout> readouts = new HashMap<String,Readout>();
+    private Map<String,Field> fields = new HashMap<String,Field>();
+    
+    protected XMLMaterialManager materialMgr;
+    
+    /**
+     * Called by the reader to create a new Detector
+     * @param element The JDOM element corresponding to the detector definition in the XML file.
+     */
+    protected Detector(Element element)
+    {
+        materialMgr = XMLMaterialManager.create(XMLMaterialManager.materials() );
+    }
+    
+    /**
+     * Called by the reader to associate a header with this detector
+     * @param header The header.
+     */
+    protected void setHeader(Header header)
+    {
+        this.header = header;
+    }
+    /**
+     * Get the header associated with this detector.
+     * @return The header
+     */
+    public Header getHeader()
+    {
+        return header;
+    }
+    
+    /**
+     * Get the detector name from the header.
+     * @return the detector name
+     */
+    public String getDetectorName()
+    {
+        return getHeader().getDetectorName();
+    }
+    
+    /**
+     * Called by the reader to add a constant to this detector.
+     * @param c The constant to add.
+     */
+    protected void addConstant(Constant c)
+    {
+        constants.put(c.getName(),c);
+    }
+    /**
+     * Get the constants associated with this detector.
+     * @return A map of containing all of the constants, indexed by name.
+     */
+    public Map<String,Constant> getConstants()
+    {
+        return constants;
+    }
+    /**
+     * Called by the reader to add a new Readout to this detector.
+     * @param r The readout to add.
+     */
+    protected void addReadout(Readout r)
+    {
+        //System.out.println("geometry.compact.Detector.addReadout() - " + r.getName() );
+        readouts.put(r.getName(),r);
+    }
+    /**
+     * Get the readouts associated with this detector.
+     * @return A map of containing all of the readouts, indexed by name.
+     */
+    public Map<String, Readout> getReadouts()
+    {
+        return readouts;
+    }
+    
+    /**
+     * Convenience method to get readout by name.
+     **/
+    public Readout getReadout(String rn)
+    {
+        return readouts.get(rn);
+    }
+    
+    /**
+     * Called by the reader to add a sub-detector to this detector.
+     * @param sub The sub-detector to add.
+     */
+    protected void addSubdetector(Subdetector sub)
+    {
+        subdetectors.put(sub.getName(),sub);
+    }
+    
+    /*
+     * Convenience method to retrieve subdetector by name.
+     * @param subdetector with this name (null if doesn't exist)
+     */
+    public Subdetector getSubdetector(String name)
+    {
+        return subdetectors.get(name);
+    }
+
+    /**
+     * Convenience method to retrieve set of detector names.
+     * @return set of subdetector name strings
+     */
+    public Set<String> getSubdetectorNames()
+    {
+        return getSubdetectors().keySet();
+    }
+    
+    /**
+     * Get the sub-detectors associated with this detector.
+     * @return A map of containing all of the sub-detectors, indexed by name.
+     */
+    public Map<String,Subdetector> getSubdetectors()
+    {
+        return subdetectors;
+    }
+    
+    protected void addField(Field field)
+    {
+        fields.put(field.getName(),field);
+    }
+    
+    public Map<String,Field> getFields()
+    {
+        return fields;
+    }
+    
+    public XMLMaterialManager getMaterialManager()
+    {
         return materialMgr;
-   }
+    }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
CylindricalEndcapCalorimeter.java 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- CylindricalEndcapCalorimeter.java	15 Jul 2005 00:47:50 -0000	1.10
+++ CylindricalEndcapCalorimeter.java	18 Jul 2005 22:04:11 -0000	1.11
@@ -43,7 +43,8 @@
         double rmin = dimensions.getAttribute("inner_r").getDoubleValue();
         double rmax = dimensions.getAttribute("outer_r").getDoubleValue();
         
-        double totWidth = LayerFromCompactCnv.computeDetectorThickness(node);                
+        double totWidth = layers.getLayerStack().getTotalThickness();
+                //LayerFromCompactCnv.computeDetectorThickness(node);                
         double z = zmin;
         
         Tube envelope = new Tube(detectorName+"_envelope");

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
ForwardDetector.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- ForwardDetector.java	15 Jul 2005 00:47:06 -0000	1.6
+++ ForwardDetector.java	18 Jul 2005 22:04:11 -0000	1.7
@@ -66,7 +66,7 @@
         double xangleHalf = xangle / 2;                
         
         /** Computed z values. */
-        double thickness = LayerFromCompactCnv.computeDetectorThickness(node);        
+        double thickness = layers.getLayerStack().getTotalThickness();        
         double zpos = zinner + (thickness / 2);
         double zouter = zinner + thickness;
         

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
LCDDSubdetector.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- LCDDSubdetector.java	15 Jul 2005 00:47:50 -0000	1.5
+++ LCDDSubdetector.java	18 Jul 2005 22:04:11 -0000	1.6
@@ -5,23 +5,33 @@
 import org.lcsim.geometry.compact.Subdetector;
 import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
 import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector;
-
+import org.lcsim.geometry.layer.Layering;
 
 /**
- * 
+ *
  * @author tonyj
  */
 public abstract class LCDDSubdetector extends Subdetector
-{  
-   protected Element node;
-   LCDDSubdetector(Element c) throws JDOMException
-   {
-      super(c);
-      node = c;
-   }
-   abstract void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException;
-   public Element getElement()
-   {
+{
+    protected Element node;
+    protected Layering layers;
+    
+    LCDDSubdetector(Element c) throws JDOMException
+    {
+        super(c);
+        node = c;
+        
+        /* make compact layering descr for thickness calcs in addToLCDD */
+        if ( layers == null )
+        {
+            layers = org.lcsim.geometry.layer.Layering.makeLayering(c);
+        }
+    }
+    
+    abstract void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException;
+    
+    public Element getElement()
+    {
         return node;
-   }
-}
+    }
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/geometry/layer
LayerFromCompactCnv.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- LayerFromCompactCnv.java	18 Jul 2005 18:00:04 -0000	1.2
+++ LayerFromCompactCnv.java	18 Jul 2005 22:04:11 -0000	1.3
@@ -25,6 +25,8 @@
     
     public static LayerStack makeLayerStackFromCompact(Element e) throws JDOMException, DataConversionException
     {   
+//        System.out.println("making layers: " + e.getAttributeValue("name"));
+        
         if ( e == null )
         {
             throw new JDOMException("LayerFromCompactCnv.makeLayerStackFromCompact() - got null element");
@@ -101,6 +103,7 @@
                 /* Add layer to stack once for each repetition. */
                 for (int k = 0; k < repeat; k++)
                 {
+  //                  System.out.println("add layer");
                     layerStack.addLayer(lyr);
                 }
             }
@@ -108,14 +111,14 @@
         else {
             System.err.println("LayerFromCompactCnv.makeLayerStackFromCompact() - no layer child elements to build");
         }
-        
+    
         return layerStack;
     }
     
-    public static double computeDetectorThickness(Element node) throws JDOMException
-    {
-        return LayerFromCompactCnv.makeLayerStackFromCompact(node).getTotalThickness();
-    }
+//    public static double computeDetectorThickness(Element node) throws JDOMException
+//    {
+//        return LayerFromCompactCnv.makeLayerStackFromCompact(node).getTotalThickness();
+//    }
     
     /** Compute the thickness of a single layer, ignoring the repeat attribute. */
     public static double computeSingleLayerThickness(Element node) throws JDOMException

GeomConverter/test/org/lcsim/geometry
GeometryReaderTest.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- GeometryReaderTest.java	18 Jul 2005 18:00:07 -0000	1.3
+++ GeometryReaderTest.java	18 Jul 2005 22:04:11 -0000	1.4
@@ -1,10 +1,7 @@
 package org.lcsim.geometry;
-
-import java.io.IOException;
 import junit.framework.*;
 import java.io.InputStream;
-import org.jdom.JDOMException;
-import org.lcsim.util.xml.ElementFactory.ElementCreationException;
+import org.lcsim.geometry.layer.Layering;
 
 /**
  *
@@ -12,22 +9,87 @@
  */
 public class GeometryReaderTest extends TestCase
 {
-   
-   public GeometryReaderTest(String testName)
-   {
-      super(testName);
-   }   
-   
-   public static Test suite()
-   {
-      return new TestSuite(GeometryReaderTest.class);
-   }   
-   
-   public void testRead() throws IOException, JDOMException, ElementCreationException
-   {
-      InputStream in = GeometryReaderTest.class.getResourceAsStream("/org/lcsim/geometry/compact/sdjan03_compact.xml");
-      GeometryReader reader = new GeometryReader();
-      Detector det = reader.read(in);
-      assertEquals(10,det.getSubdetectors().size());   
-   }
-}
+    private static final String detName = "GeometryReaderTest";
+    private static final String detLoc = detName + ".xml";
+    
+    Detector detector;
+    int nDetectors = 10;
+    int nConstants = 10;
+    int nTrackerLayers = 5;
+    int nTrackerEndcapLayers = 10;
+    int nFields = 1;
+    int nEMLayers = 30;
+    int nHADLayers = 34;
+    
+    public GeometryReaderTest(String testName)
+    {
+        super(testName);
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite(GeometryReaderTest.class);
+    }
+    
+    protected void setUp() throws Exception
+    {
+        try
+        {
+            InputStream in = GeometryReaderTest.class.getResourceAsStream(detLoc);
+            GeometryReader reader = new GeometryReader();
+            detector = reader.read(in);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException("GeometryReaderTest.setUp() - GeometryReader failed.", e);
+        }
+    }
+    
+    public void testSizes()
+    {
+        assertEquals(nDetectors, detector.getSubdetectors().size() );
+        assertEquals(nDetectors, detector.getReadouts().size() );
+        assertEquals(nConstants, detector.getConstants().size() );
+        assertEquals(nFields, detector.getFields().size() );
+    }
+    
+    public void testAttributes()
+    {
+        assertEquals("GeometryReaderTest", detector.getName() );
+        
+        org.lcsim.geometry.Subdetector subdetector = null;
+        for ( String sn : detector.getSubdetectorNames() )
+        {
+            System.out.println("subdet: " + sn);
+            
+            subdetector = detector.getSubdetector(sn);
+            assert(sn != null);
+            
+            Layering layers = subdetector.getLayering();
+            assert(layers != null);
+            
+            System.out.println("layer count: " + layers.getLayerCount() );
+            
+            if ( sn.equals("BarrelVertex") || sn.equals("BarrelTracker") ||
+                    sn.equals("EndcapVertex") )
+            {
+                assertEquals(layers.getLayerCount(), nTrackerLayers);
+            }
+            
+            if ( sn.equals("EndcapTracker") )
+            {
+                assertEquals(layers.getLayerCount(), nTrackerEndcapLayers );
+            }
+            
+            if ( sn.equals("EMBarrel") || sn.equals("EMEndcap") )
+            {
+                assertEquals(layers.getLayerCount(), nEMLayers);
+            }
+            
+            if ( sn.equals("HADBarrel") || sn.equals("HADEndcap") )
+            {
+                assertEquals(layers.getLayerCount(), nHADLayers);
+            }
+        }
+    }
+}
\ No newline at end of file
CVSspam 0.2.8