GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -N TubeSegment.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TubeSegment.java 29 Oct 2007 23:17:29 -0000 1.1
@@ -0,0 +1,130 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import org.jdom.Element;
+import org.jdom.JDOMException;
+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.Position;
+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.Tube;
+import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+
+/**
+ * LCDD implementation of a TubeSegment for beampipe elements.
+ *
+ * @author Jeremy McCormick
+ * @version $Id: TubeSegment.java,v 1.1 2007/10/29 23:17:29 jeremy Exp $
+ */
+public class TubeSegment
+extends LCDDSubdetector
+{
+ public TubeSegment(Element node) throws JDOMException
+ {
+ super(node);
+ }
+
+ void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
+ {
+ // Find the mother volume
+ Volume mother = null;
+ if (isInsideTrackingVolume())
+ {
+ mother = lcdd.getTrackingVolume();
+ }
+ else
+ {
+ mother = lcdd.getWorldVolume();
+ }
+
+ // Name
+ String name = node.getAttributeValue("name");
+
+ // Id
+ int id = node.getAttribute("id").getIntValue();
+
+ // Material
+ Material material = lcdd.getMaterial(node.getChild("material").getAttributeValue("name"));
+
+ // Tube
+ Element tubsParam = node.getChild("tubs");
+ double innerR, outerR, zHalf;
+ innerR = tubsParam.getAttribute("rmin").getDoubleValue();
+ outerR = tubsParam.getAttribute("rmax").getDoubleValue();
+ zHalf = tubsParam.getAttribute("zhalf").getDoubleValue();
+ Tube tube = new Tube(name + "_tube", innerR, outerR, zHalf);
+ lcdd.add(tube);
+
+ // Volume
+ Volume volume = new Volume(name, tube, material);
+ lcdd.add(volume);
+
+ // Position
+ Position position = null;
+ Element positionElement = node.getChild("position");
+ if (positionElement == null)
+ {
+ position = new Position(name + "_position");
+ }
+ else
+ {
+ double x,y,z;
+ x = y = z = 0.;
+
+ if (positionElement.getAttribute("x") != null)
+ {
+ x = positionElement.getAttribute("x").getDoubleValue();
+ }
+
+ if (positionElement.getAttribute("y") != null)
+ {
+ y = positionElement.getAttribute("y").getDoubleValue();
+ }
+
+ if (positionElement.getAttribute("z") != null)
+ {
+ z = positionElement.getAttribute("z").getDoubleValue();
+ }
+
+ position.setX(x);
+ position.setY(y);
+ position.setZ(z);
+ }
+
+ // Rotation
+ Rotation rotation = null;
+ Element rotationElement = node.getChild("rotation");
+ if (rotationElement == null)
+ {
+ rotation = new Rotation(name + "_rotation");
+ }
+ else
+ {
+ double x,y,z;
+ x = y = z = 0.;
+
+ if (rotationElement.getAttribute("x") != null)
+ {
+ x = rotationElement.getAttribute("x").getDoubleValue();
+ }
+
+ if (rotationElement.getAttribute("y") != null)
+ {
+ y = rotationElement.getAttribute("y").getDoubleValue();
+ }
+
+ if (rotationElement.getAttribute("z") != null)
+ {
+ z = rotationElement.getAttribute("z").getDoubleValue();
+ }
+
+ rotation.setX(x);
+ rotation.setY(y);
+ rotation.setZ(z);
+ }
+
+ PhysVol tubePV = new PhysVol(volume, mother, position, rotation);
+ tubePV.addPhysVolID("id", id);
+ }
+}
\ No newline at end of file