GeomConverter/src/org/lcsim/geometry/subdetector
diff -u -r1.1 -r1.2
--- PolyhedraEndcapCalorimeter2.java 6 Feb 2009 16:36:23 -0000 1.1
+++ PolyhedraEndcapCalorimeter2.java 18 Nov 2009 20:09:55 -0000 1.2
@@ -1,5 +1,15 @@
package org.lcsim.geometry.subdetector;
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+import static java.lang.Math.tan;
+import hep.graphics.heprep.HepRep;
+import hep.graphics.heprep.HepRepFactory;
+import hep.graphics.heprep.HepRepInstance;
+import hep.graphics.heprep.HepRepInstanceTree;
+import hep.graphics.heprep.HepRepType;
+import hep.graphics.heprep.HepRepTypeTree;
+
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -10,6 +20,80 @@
super(node);
}
+ 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");
+
+ setHepRepColor(type);
+
+ HepRepInstance instance = factory.createHepRepInstance(instanceTree, type);
+
+ // Compute section (x,y) coordinates.
+ double rmin = getInnerR();
+
+ double x1 = rmin * tan(this.getHalfSectionPhi());
+ double y1 = rmin;
+
+ double x2 = -x1;
+ double y2 = y1;
+
+ double t = this.getLayering().getLayerStack().getTotalThickness();
+ double zin = this.getZMin();
+ double zout = zin + t;
+
+ double rmax = this.getOuterR();
+
+ double x4 = rmax * tan(this.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 < 2; i++)
+ {
+ for (int j=0; j<getNumberOfSides(); j++)
+ {
+ 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);
+
+ factory.createHepRepPoint(instance, ix1, iy1, zin);
+ factory.createHepRepPoint(instance, ix2, iy2, zin);
+ factory.createHepRepPoint(instance, ix3, iy3, zin);
+ factory.createHepRepPoint(instance, ix4, iy4, zin);
+
+ factory.createHepRepPoint(instance, ix4, iy4, zout);
+ factory.createHepRepPoint(instance, ix3, iy3, zout);
+ factory.createHepRepPoint(instance, ix2, iy2, zout);
+ factory.createHepRepPoint(instance, ix1, iy1, zout);
+
+ phi += getSectionPhi();
+ }
+ // TODO: Break here if not reflected. Heprep converter does not pickup correct default
+ // of reflect being true unless set to false. Doesn't have access to compact
+ // schema defaults.
+ zin = -zin;
+ zout = -zout;
+ }
+ }
+
public boolean isEndcap()
{
return true;