Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd on MAIN
PolyhedraEndcapCalorimeter3.java+165added 1.1


GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
PolyhedraEndcapCalorimeter3.java added at 1.1
diff -N PolyhedraEndcapCalorimeter3.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ PolyhedraEndcapCalorimeter3.java	14 Sep 2010 00:46:57 -0000	1.1
@@ -0,0 +1,165 @@
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: PolyhedraEndcapCalorimeter3.java,v 1.1 2010/09/14 00:46:57 jeremy Exp $
+ */
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import java.util.ArrayList;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.Define;
+import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
+import org.lcsim.geometry.compact.converter.lcdd.util.Material;
+import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol;
+import org.lcsim.geometry.compact.converter.lcdd.util.Polyhedra;
+import org.lcsim.geometry.compact.converter.lcdd.util.Rotation;
+import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector;
+import org.lcsim.geometry.compact.converter.lcdd.util.Solids;
+import org.lcsim.geometry.compact.converter.lcdd.util.Structure;
+import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+import org.lcsim.geometry.compact.converter.lcdd.util.ZPlane;
+import org.lcsim.geometry.layer.LayerStack;
+import org.lcsim.geometry.layer.Layering;
+
+public class PolyhedraEndcapCalorimeter3 extends LCDDSubdetector
+{
+    public PolyhedraEndcapCalorimeter3(Element node) throws JDOMException
+    {
+        super(node);
+        this.node = node;
+    }
+
+    public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
+    {
+        Solids solids = lcdd.getSolids();
+        Structure structure = lcdd.getStructure();
+        Volume motherVolume = lcdd.pickMotherVolume(this);
+        Material air = lcdd.getMaterial("Air");
+        Define define = lcdd.getDefine();
+        Rotation identityRotation = define.getRotation("identity_rot");
+        
+        String subdetectorName = node.getAttributeValue("name");
+        int id = node.getAttribute("id").getIntValue();        
+        
+        Element dimensions = node.getChild("dimensions");
+        double zmin = dimensions.getAttribute("zmin").getDoubleValue();
+        double rmin = dimensions.getAttribute("rmin").getDoubleValue();
+        double rmax = dimensions.getAttribute("rmax").getDoubleValue();
+        int numsides = dimensions.getAttribute("numsides").getIntValue();
+        double innerAngle = dimensions.getAttribute("angle").getDoubleValue();
+        
+        System.out.println("detector...");
+        System.out.println("rmin = " + rmin);
+        System.out.println("rmax = " + rmax);
+        System.out.println(" angle = " + innerAngle);        
+        
+        // Compute outer angle.
+        //double outerAngle = Math.PI - Math.PI / 2 - innerAngle;
+        //double outerAngle = Math.PI / 2 - innerAngle;
+        
+        //System.out.println("outerAngle="+outerAngle);
+
+        // Make layering to get thickness.
+        // FIXME: This should happen automatically.
+        LayerStack layers = Layering.makeLayering(this.node).getLayerStack();
+        
+        double thickness = layers.getTotalThickness();
+        
+        System.out.println("thickness="+thickness);
+        
+        // Compute radius at last zplane of envelope.
+        double r3 = thickness * Math.tan(innerAngle);
+        
+        System.out.println("r3="+r3);
+        System.out.println();
+        
+        // Setup envelope volume so that rmin increases along +z.
+        ArrayList<ZPlane> zplanes = new ArrayList<ZPlane>();
+        ZPlane frontZPlane = new ZPlane(rmin, rmax, zmin);
+        ZPlane backZPlane = new ZPlane(rmin + r3, rmax, zmin  + thickness);
+        zplanes.add(frontZPlane);
+        zplanes.add(backZPlane);
+        Polyhedra envelopePolyhedra = new Polyhedra(
+                subdetectorName + "_envelope_polyhedra",
+                numsides,
+                zplanes);
+        
+        solids.addSolid(envelopePolyhedra);
+        Volume envelopeVolume = new Volume(subdetectorName + "_volume", envelopePolyhedra, air);        
+        
+        // Orientation of polyhedras with flat side down.
+        double zrot = Math.PI / numsides;
+        Rotation positiveEndcapRotation = new Rotation(subdetectorName + "_positive");
+        positiveEndcapRotation.setZ(zrot);
+        lcdd.getDefine().addRotation(positiveEndcapRotation);
+        
+        //
+        // Setup some layering variables for the loop...
+        //
+        
+        // The absolute z coordinate of the layer front face.
+        double layerZ = zmin;
+        
+        // The rmin of the layer which will decrease along z.
+        double layerRmin = rmin;
+                        
+        // Loop over layers.
+        for (int i=0, l=layers.getNumberOfLayers(); i<l; i++)
+        {            
+            System.out.println("layer" + i);
+            System.out.println("    zmin = " + layerZ);
+            
+            // Get this layer's thickness.
+            double layerThickness = layers.getLayer(i).getThickness();
+            
+            System.out.println("    layerThickness = " + layerThickness);
+            
+            // Increment inner radius by dx as rmin of layer increases along z.
+            double layerdx = Math.tan(innerAngle) * layerThickness;
+            layerRmin += layerdx;
+            
+            System.out.println("    dx = " + layerdx);
+            System.out.println("    rmin = " + layerRmin);
+                                                                
+            // Make layer polyhedra.
+            ArrayList<ZPlane> layerZplanes = new ArrayList<ZPlane>();
+            ZPlane layerFrontZPlane = new ZPlane(layerRmin, rmax, layerZ);
+            ZPlane layerBackZPlane = new ZPlane(layerRmin, rmax, layerZ + layerThickness);
+            layerZplanes.add(layerFrontZPlane);
+            layerZplanes.add(layerBackZPlane);
+            Polyhedra layerPolyhedra = new Polyhedra(
+                    subdetectorName + "_layer" + i + "_polyhedra",
+                    numsides,
+                    layerZplanes);
+            
+            // Add layer volume to solids.
+            solids.addContent(layerPolyhedra);
+            
+            // Make layer volume.            
+            Volume layerVolume = 
+                new Volume(subdetectorName + "_layer" + i + "_volume", layerPolyhedra, air);
+            structure.addVolume(layerVolume);            
+            
+            // Make layer placement.
+            PhysVol layerPhysVol = new PhysVol(layerVolume);
+            //layerPhysVol.setRotation(positiveEndcapRotation);
+            envelopeVolume.addPhysVol(layerPhysVol);            
+            
+            // Set z to edge of next layer.
+            layerZ += layerThickness;            
+        }
+        
+        // Add envelope volume to structure (TEST).
+        structure.addVolume(envelopeVolume);
+                
+        PhysVol envelopePhysVol = new PhysVol(envelopeVolume);
+        //envelopePhysVol.setZ(zmin+thickness/2);
+        envelopePhysVol.addPhysVolID("system",id);
+        envelopePhysVol.addPhysVolID("barrel",1);     
+                
+        //envelopePhysVol.setRotation(positiveEndcapRotation);
+                
+        motherVolume.addPhysVol(envelopePhysVol);        
+    }   
+}
CVSspam 0.2.8