Commit in GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd on MAIN
SiTrackerEndcap.java+289-121.7 -> 1.8
JM: preliminary LCDD implementation of SiTrackerEndcap modules (last commit was erroneous)

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
SiTrackerEndcap.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- SiTrackerEndcap.java	29 Oct 2007 22:42:35 -0000	1.7
+++ SiTrackerEndcap.java	1 Nov 2007 23:46:01 -0000	1.8
@@ -18,16 +18,26 @@
 import org.lcsim.geometry.compact.converter.lcdd.util.Tube;
 import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
 
-public class SiTrackerEndcap 
-extends LCDDSubdetector
+public class SiTrackerEndcap extends LCDDSubdetector
 {
+    ModuleParameters moduleParameters = null;
+    SensitiveDetector sd = null;
+
     public SiTrackerEndcap(Element node) throws JDOMException
     {
         super(node);
     }
 
     public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
-    {
+    {        
+        if (sens == null)
+            throw new RuntimeException("SD is null");
+
+        this.sd = sens;
+
+        // Set static module parameters.
+        moduleParameters = new ModuleParameters(node.getChild("module"));
+
         for (Object o : node.getChildren("layer"))
         {
             Element layerElement = (Element)o;
@@ -75,7 +85,7 @@
 
             // Positive endcap.
             new PhysVol(layerVolume, lcdd.getTrackingVolume(), position, rotation);
-            
+
             // Negative endcap.
             Rotation rotationReflect = new Rotation(layerName + "_rotation_reflect");
             rotationReflect.setY(Math.PI);
@@ -85,6 +95,8 @@
             lcdd.add(positionReflect);
             new PhysVol(layerVolume, lcdd.getTrackingVolume(), positionReflect, rotationReflect);
         }
+
+        moduleParameters = null;
     }
 
     private Volume makeLayer(
@@ -152,7 +164,7 @@
         //{
         //    layerLV.setVisAttributes(lcdd.getVisAttributes("InvisibleWithDaughters"));
         //}
-        
+
         return layerLV;
     }
 
@@ -184,7 +196,7 @@
         lcdd.add(wedgeTrd);
 
         Volume wedgeLV = new Volume(name, wedgeTrd, material);
-        
+
         makeModules(subdetElement, wedgeLV, layerElement.getChild("module_parameters"), layerN, lcdd);
 
         return wedgeLV;
@@ -299,6 +311,10 @@
                 lcdd.add(sliceBox);
 
                 Volume sliceLV = new Volume(sliceName, sliceBox, sliceMaterial);
+
+                // Make the box module.
+                makeBoxModule(sliceLV, lcdd);
+
                 lcdd.add(sliceLV);
 
                 Position p = new Position(sliceName + "_position");
@@ -307,7 +323,7 @@
                 lcdd.add(p);
                 Rotation rot = new Rotation(sliceName + "_rotation");
                 lcdd.add(rot);
-                
+
                 new PhysVol(
                         sliceLV,
                         wedgeLV,
@@ -324,11 +340,13 @@
 
                 Trapezoid sliceTrd = new Trapezoid(sliceName+"_trapezoid", xsizes1.get(i), xsizes2.get(i), dy, dy, zsizes.get(i));
                 lcdd.add(sliceTrd);
-                
+
                 Volume sliceLV = new Volume(sliceName, sliceTrd, sliceMaterial);
+                
+                makeTrdModule(sliceLV, lcdd);
+                
                 lcdd.add(sliceLV);
 
-                //Transform3D trans = new Transform3D(new Translation3D(0,0,zcenters.get(i)));
                 Position p = new Position(sliceName + "_position");
                 p.setZ(zcenters.get(i));
                 lcdd.add(p);
@@ -364,17 +382,20 @@
 
                     Trap sliceTrap = new Trap(sliceName+"_trap",zsizes.get(i),theta*ix,0.0,dy,xsize1,xsize1,0.0,dy,xsize2,xsize2,0.0);
                     lcdd.add(sliceTrap);
-                    
+
                     Volume sliceLV = new Volume(sliceName, sliceTrap, sliceMaterial);
-                    lcdd.add(sliceLV);
                     
+                    makeTrapModule(sliceLV,lcdd);
+                    
+                    lcdd.add(sliceLV);
+
                     Position p = new Position(sliceName + "_position");
                     p.setX(ix*xcenter);
                     p.setZ(zcenters.get(i));
                     lcdd.add(p);
                     Rotation rot = new Rotation(sliceName + "_rotation");
                     lcdd.add(rot);
-                    
+
                     new PhysVol(
                             sliceLV,
                             wedgeLV,
@@ -386,4 +407,260 @@
             }
         }
     }
+
+    void makeBoxModule(Volume moduleVolume, LCDD lcdd)
+    {
+        Box moduleBox = (Box)lcdd.getSolid(moduleVolume.getSolidRef());
+
+        double moduleX = moduleBox.getX();
+        double posY = moduleBox.getY() / 2;
+        double moduleZ = moduleBox.getZ();    	
+
+        String moduleName = moduleVolume.getVolumeName();
+
+        for (ModuleComponentParameters component : moduleParameters)
+        {
+            double thickness = component.getThickness();
+            Material material = null;
+            try {
+                material = lcdd.getMaterial(component.getMaterialName());
+            }
+            catch (JDOMException x)
+            {
+                throw new RuntimeException(x);
+            }
+            boolean sensitive = component.isSensitive();
+            int componentNumber = component.getComponentNumber();
+
+            posY += thickness / 2;
+
+            String componentName = moduleName + "_component" + componentNumber;
+
+            Box sliceBox = new Box(componentName + "_box", moduleX, thickness, moduleZ);
+            lcdd.add(sliceBox);
+
+            Volume volume = new Volume(componentName, sliceBox, material);
+            lcdd.add(volume);
+
+            if (sensitive)
+                volume.setSensitiveDetector(this.sd);
+
+            Position position = new Position(componentName + "_position", 0., posY, 0.); 
+            lcdd.add(position);
+            Rotation rotation = new Rotation(componentName + "_rotation");
+            rotation.setY(Math.PI);
+            lcdd.add(rotation);
+            PhysVol pv = new PhysVol(volume, moduleVolume, position, rotation);
+            pv.addPhysVolID("component", componentNumber);
+           
+            posY += thickness / 2;
+
+            break;
+        }    	
+    }
+
+    void makeTrdModule(Volume moduleVolume, LCDD lcdd)
+    {
+        Trapezoid trd = (Trapezoid)lcdd.getSolid(moduleVolume.getSolidRef());
+
+        double x1 = trd.x1();
+        double x2 = trd.x2();
+        double y1 = trd.y1();
+        double z = trd.z();
+
+        double posY = -y1;
+
+        String moduleName = moduleVolume.getVolumeName();
+
+        for (ModuleComponentParameters component : moduleParameters)
+        {
+            double thickness = component.getThickness();
+
+            Material material = null;
+            try {
+                material = lcdd.getMaterial(component.getMaterialName());
+            }
+            catch (JDOMException x)
+            {
+                throw new RuntimeException(x);
+            }
+            boolean sensitive = component.isSensitive();
+            int componentNumber = component.getComponentNumber();            
+
+            posY += thickness / 2;
+
+            String componentName = moduleName + "_component" + componentNumber;
+
+            Trapezoid sliceTrd = new Trapezoid(componentName + "_trd", x1, x2, thickness/2, thickness/2, z);
+            lcdd.add(sliceTrd);
+
+            Volume volume = new Volume(componentName, sliceTrd, material);
+            lcdd.add(volume);
+
+            Position position = new Position(componentName + "_position",0.,posY,0);
+            lcdd.add(position);
+            Rotation rotation = new Rotation(componentName + "_rotation");
+            rotation.setY(Math.PI);
+            lcdd.add(rotation);
+
+            PhysVol pv = new PhysVol(volume, moduleVolume, position, rotation);
+            pv.addPhysVolID("component", componentNumber);
+
+            if (sensitive)
+                volume.setSensitiveDetector(this.sd);
+
+            posY += thickness / 2;
+        }   
+    }
+
+    public void makeTrapModule(Volume module, LCDD lcdd)
+    {
+        Trap trap = (Trap)lcdd.getSolid(module.getSolidRef());
+
+        double a1 = trap.getAlpha1();
+        double a2 = trap.getAlpha2();
+        double x1 = trap.getXHalfLength1();
+        double x2 = trap.getXHalfLength2();
+        double x3 = trap.getXHalfLength3();
+        double x4 = trap.getXHalfLength4();
+        double y1 = trap.getYHalfLength1();
+        double z = trap.getZHalfLength();
+        double theta = trap.getTheta();
+        double phi = trap.getPhi();
+
+        double posY = -y1;
+
+        for (ModuleComponentParameters component : moduleParameters)
+        {
+            double thickness = component.getThickness();
+            Material material = null;
+            try {
+                material = lcdd.getMaterial(component.getMaterialName());
+            }
+            catch (JDOMException x)
+            {
+                throw new RuntimeException(x);
+            }
+            boolean sensitive = component.isSensitive();
+            int componentNumber = component.getComponentNumber();
+
+            posY += thickness / 2;
+
+            String componentName = module.getVolumeName() + "_component" + componentNumber;    
+
+            Trap sliceTrap = new Trap(componentName + "_trap", z, theta, phi, thickness/2, x1, x2, a1, thickness/2, x3, x4, a2);
+            lcdd.add(sliceTrap);
+
+            Volume volume = new Volume(componentName, sliceTrap, material);
+            lcdd.add(volume);
+
+            Position position = new Position(componentName + "_position",0,posY,0);
+            lcdd.add(position);
+            Rotation rotation = new Rotation(componentName + "_rotation");
+            rotation.setY(Math.PI);
+            lcdd.add(rotation);
+
+            PhysVol pv = new PhysVol(volume, module, position, rotation);
+            pv.addPhysVolID("component", componentNumber);
+            
+            if (sensitive)
+                volume.setSensitiveDetector(this.sd);
+
+            posY += thickness / 2;
+        }   
+    }
+
+    public boolean isTracker()
+    {
+        return true;
+    }
+
+    // FIXME: Duplicates class in org.lcsim.detector.compact.converter.SiTrackerEndcapConverter,
+    //        because I didn't want to introduce a dependency on the org.lcsim.detector package. 
+    public static class ModuleComponentParameters
+    {
+        String materialName;
+        double thickness;
+        boolean sensitive;
+        int componentNumber;
+
+        public ModuleComponentParameters(double thickness, String materialName, int componentNumber, boolean sensitive)
+        {
+            this.thickness = thickness;
+            this.materialName = materialName;
+            this.sensitive = sensitive;
+            this.componentNumber = componentNumber;
+        }
+
+        public double getThickness()
+        {
+            return thickness;
+        }
+
+        public String getMaterialName()
+        {
+            return materialName;
+        }
+
+        public boolean isSensitive()
+        {
+            return sensitive;
+        }
+
+        public int getComponentNumber()
+        {
+            return componentNumber;
+        }
+    }
+
+    // FIXME: Duplicates class in org.lcsim.detector.compact.converter.SiTrackerEndcapConverter,
+    //        because I didn't want to introduce a dependency on the org.lcsim.detector package. 
+    public static class ModuleParameters
+    extends ArrayList<ModuleComponentParameters>
+    {
+        double thickness=0.;
+        String name;
+        public ModuleParameters(Element element)
+        {
+            name = element.getAttributeValue("name");
+            int cntr=0;
+            for (Object o : element.getChildren("module_component"))
+            {
+                try {
+
+                    Element e = (Element)o;
+
+                    double thickness = e.getAttribute("thickness").getDoubleValue();
+
+                    String materialName = e.getAttributeValue("material");
+
+                    boolean sensitive = false;
+                    if (e.getAttribute("sensitive") != null)
+                        sensitive = e.getAttribute("sensitive").getBooleanValue();
+                    add(new ModuleComponentParameters(thickness, materialName, cntr, sensitive));
+                }
+                catch (JDOMException x)
+                {
+                    throw new RuntimeException(x);
+                }
+                ++cntr;
+            }
+            calculateThickness();
+        }
+
+        public void calculateThickness()
+        {
+            thickness = 0.; // reset thickness
+            for (ModuleComponentParameters p : this)
+            {
+                thickness += p.getThickness();
+            }
+        }
+
+        public double getThickness()
+        {
+            return thickness;
+        }
+    }
+
 }
\ No newline at end of file
CVSspam 0.2.8