Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd on MAIN
PolyhedraBarrelCalorimeter.java+92-541.2 -> 1.3
Latest version of PolyhedraBarrelCalorimeter.  Geometry appears ok.  (ERROR: SD is always null.)

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
PolyhedraBarrelCalorimeter.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- PolyhedraBarrelCalorimeter.java	25 Aug 2005 08:06:18 -0000	1.2
+++ PolyhedraBarrelCalorimeter.java	25 Aug 2005 20:02:10 -0000	1.3
@@ -2,6 +2,7 @@
 
 import java.util.Iterator;
 import org.jdom.Element;
+import org.jdom.Attribute;
 import org.jdom.JDOMException;
 import org.lcsim.geometry.compact.converter.lcdd.util.Define;
 import static java.lang.Math.PI;
@@ -17,6 +18,7 @@
 import org.lcsim.geometry.compact.converter.lcdd.util.PolyhedraRegular;
 import org.lcsim.geometry.compact.converter.lcdd.util.Rotation;
 import org.lcsim.geometry.compact.converter.lcdd.util.Trapezoid;
+import org.lcsim.geometry.compact.converter.lcdd.util.Box;
 import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
 import org.lcsim.geometry.compact.converter.lcdd.util.Position;
 import org.lcsim.geometry.compact.converter.lcdd.util.Rotation;
@@ -36,31 +38,42 @@
     }
     
     public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
-    {
-        String detName = node.getAttributeValue("name");
-        int id = node.getAttribute("id").getIntValue();
+    {        
+        if ( sens == null)
+        {
+            throw new IllegalArgumentException("PolyhedraBarrelCalorimeter's SD is null.");
+        }
         
+        /* local refs to LCDD objects */
         Solids solids = lcdd.getSolids();
         Structure structure = lcdd.getStructure();
         Volume motherVolume = lcdd.pickMotherVolume(this);
         Material air = lcdd.getMaterial("Air");
         Define define = lcdd.getDefine();
-        
+     
+        /* name and id */
+        String detName = node.getAttributeValue("name");
+        int id = node.getAttribute("id").getIntValue();
+
+        /* get dimensions */
         Element dimensions = node.getChild("dimensions");
-        double z = dimensions.getAttribute("z").getDoubleValue();
+        double detZ = dimensions.getAttribute("z").getDoubleValue();
         double rmin = dimensions.getAttribute("rmin").getDoubleValue();
         int numsides = dimensions.getAttribute("numsides").getIntValue();
         
+        /* polyhedra rotation so it lays "flat" */
         double zrot = Math.PI / numsides;
         Rotation rot = new Rotation(detName + "_rotation");
         rot.setZ(zrot);
         define.addRotation(rot);
-        
+
+        /* total thickness of the detector */
         double totalThickness = org.lcsim.geometry.layer.LayerFromCompactCnv.computeDetectorTotalThickness(node);
         
+        /* envelope volume */
         PolyhedraRegular polyhedra = new PolyhedraRegular(
                 detName + "_polyhedra",
-                numsides, rmin, rmin+totalThickness, z);
+                numsides, rmin, rmin+totalThickness, detZ);
         solids.addSolid(polyhedra);
         
         Volume envelopeVolume = new Volume(detName + "_envelope");
@@ -73,12 +86,13 @@
         envelopePhysvol.addPhysVolID("barrel",0);
         motherVolume.addPhysVol(envelopePhysvol);
         
+        /* single stave trapezoid */
         double innerAngle = Math.PI * 2 / numsides;
         double halfInnerAngle = innerAngle/2;
-        
+         
         Trapezoid sectTrd = new Trapezoid(detName + "_stave_trapezoid");
-        sectTrd.setY2(z);
-        sectTrd.setY1(z);
+        sectTrd.setY2(detZ);
+        sectTrd.setY1(detZ);
         sectTrd.setZ(totalThickness);
         
         double innerFaceLength = rmin * tan(halfInnerAngle) * 2;
@@ -91,20 +105,75 @@
         Volume sectVolume = new Volume(detName + "_stave");
         sectVolume.setMaterial(air);
         sectVolume.setSolid(sectTrd);
-        structure.addVolume(sectVolume);
-        
-        /*
-       <constant name="inner_face" value="( inner_radius * tan( half_inner_angle * deg ) ) * 2" />
-        <constant name="outer_face" value="( outer_radius * tan( half_inner_angle * deg ) ) * 2" />
          
-         <trd name="sect_trd"
-           x1="inner_face"
-           x2="outer_face"
-           y1="sect_long_dim"
-           y2="sect_long_dim"
-           z="sect_thickness" />
-         */
+        /* build the box layers in the stave */
+        double layerOuterAngle = (PI - innerAngle) / 2;
+        double layerInnerAngle = (PI/2 - layerOuterAngle);
+        
+        int layerNum = 0;
+        double posZ = -( totalThickness / 2 );
+        double dimX = innerFaceLength;
+        for (Iterator i = node.getChildren("layer").iterator(); i.hasNext();)
+        {
+            Element layer = (Element) i.next();
+            int repeat = layer.getAttribute("repeat").getIntValue();
+            for ( int j=0; j<repeat; j++)
+            {
+                int sliceNum = 0;
+                for ( Iterator k = layer.getChildren("slice").iterator(); k.hasNext();)
+                {
+                    String sliceName = detName + "_stave_layer" + layerNum + "_slice" + sliceNum;
+                    
+                    Element slice = (Element) k.next();
+                    
+                    Attribute s = slice.getAttribute("sensitive");
+                    boolean sensitive = s != null && s.getBooleanValue();
+                    
+                    double thickness = slice.getAttribute("thickness").getDoubleValue();
+                    posZ +=  thickness / 2;
+                    
+                    Position slicePosition = new Position(sliceName + "_position");
+                    slicePosition.setZ(posZ);
+                    define.addPosition(slicePosition);
+                    
+                    /* slice box */
+                    Box sliceBox = new Box(sliceName + "_box");                 
+                    sliceBox.setX(dimX);
+                    sliceBox.setY(detZ);
+                    sliceBox.setZ(thickness);
+                    solids.addSolid(sliceBox);
+                    
+                    /* slice volume */
+                    Volume sliceVolume = new Volume(sliceName);
+                    sliceVolume.setSolid(sliceBox);
+                    Material sliceMaterial = lcdd.getMaterial(slice.getAttributeValue("material"));
+                    sliceVolume.setMaterial(sliceMaterial);
+                    if ( sensitive ) sliceVolume.setSensitiveDetector(sens);
+                    structure.addVolume(sliceVolume);
+                    
+                    /* slice PhysVol */
+                    PhysVol slicePhysVol = new PhysVol(sliceVolume);
+                    slicePhysVol.setPosition(slicePosition);
+                    slicePhysVol.addPhysVolID("layer", layerNum);
+                    slicePhysVol.addPhysVolID("slice", sliceNum);
+                    sectVolume.addPhysVol(slicePhysVol);
+                                     
+                    /* incr X dim */
+                    dimX += thickness * tan( layerInnerAngle ) * 2; 
+                    
+                    /* incr Z position */
+                    posZ += thickness / 2;
+                    
+                    /* incr slice number */
+                    ++sliceNum;
+                }
+                ++layerNum;
+            }
+        }      
         
+        structure.addVolume(sectVolume);
+ 
+        /* place the staves */
         double innerRotation = innerAngle;
         double offsetRotation = -innerRotation / 2;
         double placementRotation = -offsetRotation;
@@ -133,46 +202,15 @@
             sectPhysVol.setPosition(position);
             sectPhysVol.setRotation(rotation);
         
-//            motherVolume.addPhysVol(sectPhysVol);
             envelopeVolume.addPhysVol(sectPhysVol);
             sectPhysVol.addPhysVolID("stave",0);
             sectPhysVol.addPhysVolID("module",moduleNumber);
-            
-            /*
-              <constant name="irot" value="inner_angle * deg" />
-              <constant name="offrot" value="-irot / 2" />
-              <constant name="placerot" value="-offrot" />
-             
-              <constant name="sect0_rot_y" value="-offrot" />
-              <constant name="sect0_pos_x" value="-sect_center_radius * sin( sect0_rot_y )" />
-              <constant name="sect0_pos_y" value="sect_center_radius * cos( sect0_rot_y )" />
-             
-              <constant name="sect1_rot_y" value="sect0_rot_y - irot" />
-              <constant name="sect1_pos_x" value="-sect_center_radius * sin( sect1_rot_y )" />
-              <constant name="sect1_pos_y" value="sect_center_radius * cos( sect1_rot_y )" />
-             */
-            
+           
             rotY -= innerRotation;
             posX = -sectCenterRadius * sin(rotY);
             posY = sectCenterRadius * cos(rotY);
         }
         
-        /*
-        for (Iterator i = node.getChildren("layer").iterator(); i.hasNext();)
-        {
-            Element layer = (Element) i.next();
-            int repeat = layer.getAttribute("repeat").getIntValue();
-            for ( int j=0; j<repeat; j++)
-            {
-                for ( Iterator k = layer.getChildren("slice").iterator(); k.hasNext();)
-                {
-                    Element slice = (Element) k.next();
-                    totalThickness += slice.getAttribute("thickness").getDoubleValue();
-                }
-            }
-        }
-         */
-        
         structure.addVolume(envelopeVolume);
     }
 }
\ No newline at end of file
CVSspam 0.2.8