GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
diff -u -r1.11 -r1.12
--- EcalBarrel.java 10 Oct 2006 18:56:55 -0000 1.11
+++ EcalBarrel.java 17 Oct 2006 22:14:52 -0000 1.12
@@ -26,12 +26,16 @@
import org.lcsim.geometry.compact.converter.lcdd.util.Trapezoid;
import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
import org.lcsim.geometry.layer.LayerFromCompactCnv;
+import org.lcsim.geometry.layer.LayerStack;
+import org.lcsim.geometry.layer.Layering;
/*
- * Class to convert from Ecal model similar to Mokka's "ecal02" to LCDD.
+ * Class to convert an EcalBarrel subdetector to the LCDD format.
+ * This subdetector constructs barrel staves in a pinwheel arrangement
+ * that is similar to the "ecal02" subdetector in the Mokka database.
*
- * @author jeremym
- * @version $Id: EcalBarrel.java,v 1.11 2006/10/10 18:56:55 jeremy Exp $
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: EcalBarrel.java,v 1.12 2006/10/17 22:14:52 jeremy Exp $
*/
public class EcalBarrel extends LCDDSubdetector
{
@@ -219,7 +223,13 @@
lcdd.getStructure().addVolume(envelopeVolume);
}
- /** Build the barrel stave logical volume for this component. */
+ /**
+ * Build the barrel stave logical volume for this component.
+ * @param lcdd The LCDD file being created.
+ * @param subdetector The current EcalBarrel subdetector.
+ * @param sensitiveDetector The sensitive detector of the subdetector.
+ * @param container The trapezoid volume of the stave, to be filled with layers.
+ */
private void buildBarrelStave(LCDD lcdd, LCDDSubdetector subdetector,
SensitiveDetector sensitiveDetector, Volume container)
throws Exception
@@ -242,146 +252,173 @@
double z = trd.y1();
double trd_z = trd.z();
- // parameters for figuring out slice dim in X (X1)
- double adj = (trd.x1() - trd.x2()) / 2; // adjacent angle of triangle
- double hyp = sqrt(trd_z * trd_z + adj * adj); // hypotenuse of triangle
- double beta = acos(adj / hyp); // lower-right angle of triangle
- double tan_beta = tan(beta); // primary coefficient for figuring X
- // cut
- double subdetectorThickness = LayerFromCompactCnv
+ // Parameters for computing the layer X dimension or trapezoid's X1 value.
+
+ // Adjacent angle of triangle.
+ double adj = (trd.x1() - trd.x2()) / 2;
+
+ // Hypotenuse of triangle.
+ double hyp = sqrt(trd_z * trd_z + adj * adj);
+
+ // Lower-right angle of triangle.
+ double beta = acos(adj / hyp);
+
+ // Primary coefficient for figuring X.
+ double tan_beta = tan(beta);
+
+ double subdetector_thickness = LayerFromCompactCnv
.computeDetectorTotalThickness(node);
- double posZ = -(subdetectorThickness / 2);
+ double layer_position_z = -(subdetector_thickness / 2);
- String detectorName = subdetector.getName();
+ String subdetector_name = subdetector.getName();
+ // Delta phi.
double dphi = PI * 2.0 / nsides;
+ // Half delta phi.
double hphi = dphi / 2;
- // starting slice dim
- double sliceX = trd.x1();
+ // Starting X dimension for the layer.
+ double layer_dim_x = trd.x1();
if (_debug)
{
- System.out.println("slice start posZ=" + posZ);
+ System.out.println("slice start posZ=" + layer_position_z);
System.out.println("dphi=" + toDegrees(dphi));
System.out.println("hphi=" + toDegrees(hphi));
- System.out.println("starting slice X=" + sliceX);
+ System.out.println("starting slice X=" + layer_dim_x);
System.out.println("adj=" + adj);
System.out.println("beta=" + toDegrees(beta));
System.out.println("");
}
-
- // loop over the sets of layers in detector element
- int layerNum = 0;
+
+ Layering layering = Layering.makeLayering(node);
+
+ LayerStack layers = layering.getLayerStack();
+
+ // Loop over the sets of layer elements in the detector.
+ int layer_number = 0;
for (Iterator i = subdetector.getElement().getChildren("layer")
.iterator(); i.hasNext();)
{
- Element layer = (Element) i.next();
- int repeat = layer.getAttribute("repeat").getIntValue();
+ Element layer_element = (Element) i.next();
+ int repeat = layer_element.getAttribute("repeat").getIntValue();
- // loop over one set of layers
- for (int j = 0; j < repeat; j++)
+ // Loop over number of repeats for this layer.
+ for (int j=0; j<repeat; j++)
{
- if (_debug)
- {
- System.out.println("layer=" + j);
- }
-
- // loop over the slices
- int sliceNum = 0;
- for (Iterator k = layer.getChildren("slice").iterator(); k
- .hasNext();)
+ // Compute this layer's thickness.
+ double layer_thickness = layers.getLayer(layer_number).getThickness();
+
+ // Increment the Z position to place this layer.
+ layer_position_z += layer_thickness / 2;
+
+ // Name of the layer.
+ String layer_name = subdetector_name + "_layer" + layer_number;
+
+ // Position of the layer.
+ Position layer_position = LCDDFactory.createPosition(
+ layer_name + "_position", 0, 0, layer_position_z);
+ lcdd.add(layer_position);
+
+ // Compute the X dimension for this layer.
+ double xcut = (layer_thickness / tan_beta) * 2;
+ layer_dim_x -= xcut;
+
+ // Box of the layer.
+ Box layer_box = LCDDFactory.createBox(layer_name + "_box",
+ layer_dim_x, z, layer_thickness);
+ lcdd.add(layer_box);
+
+ // Volume of the layer.
+ Volume layer_volume = LCDDFactory.createVolume(layer_name,
+ lcdd.getMaterial("Air"), layer_box);
+
+ // Loop over the sublayers or slices for this layer.
+ int slice_number = 0;
+ double slice_position_z = -(layer_thickness / 2);
+ for (Iterator k = layer_element.getChildren("slice").iterator(); k.hasNext();)
{
- Element slice = (Element) k.next();
-
- if (_debug)
- {
- System.out.println("material="
- + slice.getAttributeValue("material"));
- System.out.println("thickness="
- + slice.getAttributeValue("thickness"));
- System.out.println("sensitive="
- + slice.getAttributeValue("sensitive"));
- }
-
- // name of slice
- String sliceName = detectorName + "_layer" + layerNum
- + "_slice" + sliceNum;
-
- // sensitivity of slice
- Attribute s = slice.getAttribute("sensitive");
+ // XML element of slice.
+ Element slice_element = (Element) k.next();
+
+ // Name of the slice.
+ String slice_name = layer_name + "_slice" + slice_number;
+
+ // Sensitivity.
+ Attribute s = slice_element.getAttribute("sensitive");
boolean sensitive = s != null && s.getBooleanValue();
- // thickness of slice
- double sliceThickness = slice.getAttribute("thickness")
- .getDoubleValue();
- posZ += sliceThickness / 2;
-
- // position of slice
- Position slicePosition = LCDDFactory.createPosition(
- sliceName + "_position", 0, 0, posZ);
- lcdd.add(slicePosition);
-
- // figure out how much to cut from last X to make it fit
- // into the trd
- double xcut = (sliceThickness / tan_beta) * 2;
- sliceX -= xcut; // x dim for next slice
+ // Thickness of slice.
+ double slice_thickness = slice_element.getAttribute("thickness").getDoubleValue();
- if (_debug)
- {
- System.out.println("slice posZ=" + posZ);
- System.out.println("xcut=" + xcut);
- System.out.println("sliceX=" + sliceX);
- System.out.println("");
- }
-
- // box of slice
- Box sliceBox = LCDDFactory.createBox(sliceName + "_box",
- sliceX, z, sliceThickness);
+ // Increment Z position of slice.
+ slice_position_z += slice_thickness / 2;
+
+ // Position of slice.
+ Position slice_position = LCDDFactory.createPosition(
+ slice_name + "_position", 0, 0, slice_position_z);
+ lcdd.add(slice_position);
+
+ // Box of slice.
+ Box slice_box = LCDDFactory.createBox(slice_name + "_box",
+ layer_dim_x, z, slice_thickness);
- lcdd.add(sliceBox);
+ lcdd.add(slice_box);
// material of slice
- Material sliceMaterial = lcdd.getMaterial(slice
+ Material sliceMaterial = lcdd.getMaterial(slice_element
.getAttributeValue("material"));
// volume of slice
- Volume sliceVolume = LCDDFactory.createVolume(sliceName,
- sliceMaterial, sliceBox);
+ Volume slice_volume = LCDDFactory.createVolume(slice_name,
+ sliceMaterial, slice_box);
if (sensitive)
{
- sliceVolume.setSensitiveDetector(sensitiveDetector);
- }
-
- // volume region
- subdetector.setRegion(lcdd, slice, sliceVolume);
-
- // volume limits
- subdetector.setLimitSet(lcdd, slice, sliceVolume);
-
- setVisAttributes(lcdd, node, sliceVolume);
+ slice_volume.setSensitiveDetector(sensitiveDetector);
+ }
- // add volume to LCDD
- lcdd.add(sliceVolume);
+ // Slice region.
+ subdetector.setRegion(lcdd, slice_element, slice_volume);
- // placement of slice
- PhysVol slicePhysVol = LCDDFactory.createPhysVol(
- sliceVolume, slicePosition, irot);
- slicePhysVol.addPhysVolID("layer", layerNum);
- slicePhysVol.addPhysVolID("slice", sliceNum);
- container.addPhysVol(slicePhysVol);
+ // Slice limits.
+ subdetector.setLimitSet(lcdd, slice_element, slice_volume);
- // increment loop parameters
- posZ += sliceThickness / 2;
+ // Slice vis.
+ setVisAttributes(lcdd, node, slice_volume);
+
+ // Add slice volume to LCDD.
+ lcdd.add(slice_volume);
- ++sliceNum;
+ // Slice placement.
+ PhysVol slice_physvol = LCDDFactory.createPhysVol(
+ slice_volume, slice_position, irot);
+ slice_physvol.addPhysVolID("layer", layer_number);
+ slice_physvol.addPhysVolID("slice", slice_number);
+ layer_volume.addPhysVol(slice_physvol);
+
+ // Increment Z position of slice.
+ slice_position_z += slice_thickness / 2;
+
+ // Increment slice number.
+ ++slice_number;
}
+
+ lcdd.add(layer_volume);
+
+ // Place the layer.
+ PhysVol layer_physvol = LCDDFactory.createPhysVol(
+ layer_volume, layer_position, irot);
+ layer_physvol.addPhysVolID("layer", layer_number);
+ container.addPhysVol(layer_physvol);
- ++layerNum;
+ // Increment to next layer Z position.
+ layer_position_z += layer_thickness / 2;
+
+ // Increment layer number.
+ ++layer_number;
}
-
}
}