GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.2 -r1.3
--- PolyhedraBarrelCalorimeter.java 26 Aug 2005 02:37:04 -0000 1.2
+++ PolyhedraBarrelCalorimeter.java 2 Sep 2005 19:35:53 -0000 1.3
@@ -4,7 +4,6 @@
* Created on August 24, 2005, 9:37 PM
*
*/
-
package org.lcsim.geometry.subdetector;
import org.jdom.Element;
@@ -15,6 +14,9 @@
import hep.graphics.heprep.HepRepInstanceTree;
import hep.graphics.heprep.HepRepType;
import hep.graphics.heprep.HepRepTypeTree;
+import static java.lang.Math.sin;
+import static java.lang.Math.cos;
+import static java.lang.Math.tan;
/**
*
@@ -30,5 +32,68 @@
}
public void appendHepRep(HepRepFactory factory, HepRep heprep)
- {}
+ {
+ HepRepInstanceTree instanceTree = heprep.getInstanceTreeTop("Detector","1.0");
+ HepRepTypeTree typeTree = heprep.getTypeTree("DetectorType","1.0");
+ HepRepType barrel = typeTree.getType("Barrel");
+
+ HepRepType type = factory.createHepRepType(barrel, getName());
+ type.addAttValue("drawAs","Polygon");
+
+ HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
+
+ /* compute section (x,y) coordinates */
+ double rmin = getInnerR();
+
+ double x1 = rmin * tan(getHalfSectionPhi());
+ double y1 = rmin;
+
+ double x2 = -x1;
+ double y2 = y1;
+
+ double z = getZLength() / 2;
+
+ double rmax = getOuterR();
+
+ double x4 = rmax * tan(getHalfSectionPhi());
+ double y4 = rmax;
+
+ double x3 = -x4;
+ double y3 = y4;
+
+ /*
+ * Place nsides sections by applying matrix transform to starting coordinates.
+ */
+ double phi = 0;
+ for ( int i=0; i<getNumberOfSides(); i++)
+ {
+ instance = factory.createHepRepInstance(instanceTree, type);
+
+ double ix1 = x1 * cos(phi) - y1 * sin(phi);
+ double iy1 = x1 * sin(phi) + y1 * cos(phi);
+
+ double ix2 = x2 * cos(phi) - y2 * sin(phi);
+ double iy2 = x2 * sin(phi) + y2 * cos(phi);
+
+ double ix3 = x3 * cos(phi) - y3 * sin(phi);
+ double iy3 = x3 * sin(phi) + y3 * cos(phi);
+
+ double ix4 = x4 * cos(phi) - y4 * sin(phi);
+ double iy4 = x4 * sin(phi) + y4 * cos(phi);
+
+ /* +z face */
+ factory.createHepRepPoint(instance, ix1, iy1, z);
+ factory.createHepRepPoint(instance, ix2, iy2, z);
+ factory.createHepRepPoint(instance, ix3, iy3, z);
+ factory.createHepRepPoint(instance, ix4, iy4, z);
+
+ /* -z face */
+ factory.createHepRepPoint(instance, ix4, iy4, -z);
+ factory.createHepRepPoint(instance, ix3, iy3, -z);
+ factory.createHepRepPoint(instance, ix2, iy2, -z);
+ factory.createHepRepPoint(instance, ix1, iy1, -z);
+
+ phi += getSectionPhi();
+ }
+ }
}
\ No newline at end of file
GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.1 -r1.2
--- PolyhedraEndcapCalorimeter.java 26 Aug 2005 02:37:04 -0000 1.1
+++ PolyhedraEndcapCalorimeter.java 2 Sep 2005 19:35:53 -0000 1.2
@@ -4,7 +4,6 @@
* Created on August 24, 2005, 9:37 PM
*
*/
-
package org.lcsim.geometry.subdetector;
import org.jdom.Element;
@@ -15,6 +14,9 @@
import hep.graphics.heprep.HepRepInstanceTree;
import hep.graphics.heprep.HepRepType;
import hep.graphics.heprep.HepRepTypeTree;
+import static java.lang.Math.tan;
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
/**
*
@@ -28,7 +30,7 @@
public PolyhedraEndcapCalorimeter(Element node) throws JDOMException
{
super(node);
- build(node);
+ build(node);
}
private void build(Element node) throws JDOMException
@@ -37,7 +39,7 @@
zlength = thickness;
Element dimensions = node.getChild("dimensions");
-
+
zmin = dimensions.getAttribute("zmin").getDoubleValue();
zmax = zmin + thickness;
@@ -56,5 +58,75 @@
}
public void appendHepRep(HepRepFactory factory, HepRep heprep)
- {}
+ {
+ HepRepInstanceTree instanceTree = heprep.getInstanceTreeTop("Detector","1.0");
+ HepRepTypeTree typeTree = heprep.getTypeTree("DetectorType","1.0");
+ HepRepType barrel = typeTree.getType("Endcap");
+
+ HepRepType type = factory.createHepRepType(barrel, getName());
+ type.addAttValue("drawAs","Polygon");
+
+ HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
+
+ /* compute section (x,y) coordinates */
+ double rmin = getInnerR();
+
+ double x1 = rmin * tan(getHalfSectionPhi());
+ double y1 = rmin;
+
+ double x2 = -x1;
+ double y2 = y1;
+
+ double z1 = getZMin();
+ double z2 = getZMax();
+
+ double rmax = getOuterR();
+
+ double x4 = rmax * tan(getHalfSectionPhi());
+ double y4 = rmax;
+
+ double x3 = -x4;
+ double y3 = y4;
+
+ /*
+ * Place nsides sections by applying matrix transform to starting coordinates.
+ */
+ double phi = 0;
+ double flip = 1;
+ for (;;)
+ {
+ for ( int i=0; i<getNumberOfSides(); i++)
+ {
+ instance = factory.createHepRepInstance(instanceTree, type);
+
+ double ix1 = x1 * cos(phi) - y1 * sin(phi);
+ double iy1 = x1 * sin(phi) + y1 * cos(phi);
+
+ double ix2 = x2 * cos(phi) - y2 * sin(phi);
+ double iy2 = x2 * sin(phi) + y2 * cos(phi);
+
+ double ix3 = x3 * cos(phi) - y3 * sin(phi);
+ double iy3 = x3 * sin(phi) + y3 * cos(phi);
+
+ double ix4 = x4 * cos(phi) - y4 * sin(phi);
+ double iy4 = x4 * sin(phi) + y4 * cos(phi);
+
+ /* +z face */
+ factory.createHepRepPoint(instance, ix1, iy1, flip*z1);
+ factory.createHepRepPoint(instance, ix2, iy2, flip*z1);
+ factory.createHepRepPoint(instance, ix3, iy3, flip*z1);
+ factory.createHepRepPoint(instance, ix4, iy4, flip*z1);
+
+ /* -z face */
+ factory.createHepRepPoint(instance, ix4, iy4, flip*z2);
+ factory.createHepRepPoint(instance, ix3, iy3, flip*z2);
+ factory.createHepRepPoint(instance, ix2, iy2, flip*z2);
+ factory.createHepRepPoint(instance, ix1, iy1, flip*z2);
+
+ phi += getSectionPhi();
+ }
+ if (!getReflect() || flip<0) break;
+ flip = -1;
+ }
+ }
}
\ No newline at end of file