Commit in GeomConverter on MAIN
src/org/lcsim/geometry/compact/converter/lcdd/EcalBarrel.java+159-1321.2 -> 1.3
test/org/lcsim/geometry/subdetector/EcalBarrelTest.xml+4-91.2 -> 1.3
+163-141
2 modified files
JM: Update EcalBarrel to derive parameters using Norman's computations.

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
EcalBarrel.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalBarrel.java	21 Jan 2006 02:50:07 -0000	1.2
+++ EcalBarrel.java	24 Jan 2006 18:58:48 -0000	1.3
@@ -30,106 +30,128 @@
  * Class to convert from Ecal model similar to Mokka's "ecal02" to LCDD.
  * 
  * @author jeremym
- * @version $Id: EcalBarrel.java,v 1.2 2006/01/21 02:50:07 jeremy Exp $
+ * @version $Id: EcalBarrel.java,v 1.3 2006/01/24 18:58:48 jeremy Exp $
  */
-// FIXME: need subdetector envelope
+// FIXME: needs subdetector envelope
 public class EcalBarrel extends LCDDSubdetector
 {
+	// change to true if debugging this component
+	private boolean _debug = false;
+
 	EcalBarrel(Element node) throws JDOMException
 	{
 		super(node);
 	}
 
+	/** Add the EcalBarrel geometry to an LCDD instance. */
 	public void addToLCDD(LCDD lcdd, SensitiveDetector sens)
 			throws JDOMException
 	{
-		// dimensions
+		// dimensions element
 		Element dimensions = node.getChild("dimensions");
+
+		// check required attributes
 		assert (dimensions != null);
 		assert (dimensions.getAttribute("nsides") != null);
 		assert (dimensions.getAttribute("inner_radius") != null);
+		assert (dimensions.getAttribute("z") != null);
 
+		// number of sides
 		int nsides = dimensions.getAttribute("nsides").getIntValue();
+
+		// inner radius to first surface of module
 		double inner_radius = dimensions.getAttribute("inner_radius")
 				.getDoubleValue();
 
-		// module parameters
-		Element module = node.getChild("module");
-		assert (module != null);
-		assert (module.getAttribute("x1") != null);
-		assert (module.getAttribute("x2") != null);
-		assert (module.getAttribute("y") != null);
-
-		double module_x1 = module.getAttribute("x1").getDoubleValue();
-		double module_x2 = module.getAttribute("x2").getDoubleValue();
-		double module_y1 = module.getAttribute("y").getDoubleValue();
+		// module Z dimension, corresponding to Z of subdetector
+		double module_y1 = dimensions.getAttribute("z").getDoubleValue();
 		double module_y2 = module_y1;
 
-		double module_x_offset = 0.0;
-		if (module.getAttribute("x_offset") != null)
-		{
-			module_x_offset = module.getAttribute("x_offset").getDoubleValue();
-		}
+		// delta phi per module
+		double dphi = PI * 2.0 / nsides;
+		double hphi = dphi / 2;
 
 		// thickness of the subdetector
 		double module_z = LayerFromCompactCnv
 				.computeDetectorTotalThickness(node);
 
-		// center Y coord of a single module = inner_radius + thickness		
+		// center Y coord of a single module, untransformed
 		double module_y_offset = inner_radius + module_z / 2;
 
-		// get the mother volume
+		// mother volume
 		Volume motherVolume = lcdd.pickMotherVolume(this);
-		
-		// get the name of the detector
+
+		// name of the detector
 		String name = node.getAttributeValue("name");
 
-		// DEBUG prints
-		System.out.println("name=" + name); 
-		System.out.println("nsides=" + nsides); 
-		System.out.println("inner_radius=" + inner_radius);
-		System.out.println("module_x1=" + module_x1);
-		System.out.println("module_x2=" + module_x2);
-		System.out.println("module_y1=" + module_y1);
-		System.out.println("module_y2=" + module_y2);
-		System.out.println("x_offset=" + module_x_offset);
-		System.out.println("module_z=" + module_z);
-		System.out.println("module_y_offset=" + module_y_offset);		
-		
-		// trapezoid for the module 
+		// outer radius, which is really just inner_radius + thickness
+		double outer_radius = inner_radius + module_z;
+
+		// partial trapezoid measurements
+		double bo = tan(hphi) * outer_radius;
+		double bi = tan(hphi) * inner_radius;
+		// double cz = module_z / ( cos(hphi));
+
+		// side triangle calculations to get dx (from Norman)
+		double gamma = (PI * 2) / nsides;
+		double dx = module_z / sin(gamma);
+
+		// offset of a module derived from the dx term
+		double module_x_offset = dx / 2.0;
+
+		// primary top and bottom face measurements of the trapezoid
+		double module_x2 = 2 * bo - dx;
+		double module_x1 = 2 * bi + dx;
+
+		// trapezoid for the module
 		Trapezoid module_trd = LCDDFactory.createTrapezoid(
-				name + "_module_trd", 
-				module_x1, // outer side, the "short" X side
+				name + "_module_trd", module_x1, // outer side, the "short" X
+				// side
 				module_x2, // inner side, the "long" X side
 				module_y1, // corresponds to subdetector (or module) Z
 				module_y2, // ditto
-				module_z); // thickness (in Y for top module, when it is reoriented)
+				module_z); // thickness (in Y for top module, when it is
+		// reoriented)
 		lcdd.add(module_trd);
 
 		// logical volume for the module
-		Volume module_volume = LCDDFactory.createVolume(
-				name + "_module", 
-				lcdd.getMaterial("Air"), 
-				module_trd);
-		
-		// build the stave logical volume		
-		try {
-			buildBarrelStave(lcdd, this, sens, module_volume);
+		Volume module_volume = LCDDFactory.createVolume(name + "_module", lcdd
+				.getMaterial("Air"), module_trd);
+
+		// DEBUG prints
+		if (_debug)
+		{
+			System.out.println("name=" + name);
+			System.out.println("nsides=" + nsides);
+			System.out.println("inner_radius=" + inner_radius);
+			System.out.println("module_y1=" + module_y1);
+			System.out.println("module_y2=" + module_y2);
+			System.out.println("module_z=" + module_z);
+			System.out.println("module_y_offset=" + module_y_offset);
+			System.out.println("module_x_offset=" + module_x_offset);
+			System.out.println("gamma=" + gamma);
+			System.out.println("dx=" + dx);
+			System.out.println("bi=" + bi);
+			System.out.println("bo=" + bo);
+			System.out.println("");
 		}
-		catch ( Exception e)
+
+		// build the stave logical volume
+		try
+		{
+			buildBarrelStave(lcdd, this, sens, module_volume);
+		} catch (Exception e)
 		{
-			throw new RuntimeException("Failed to build layers into " 
-					+ module_volume.getVolumeName(), e );
+			throw new RuntimeException("Failed to build layers into "
+					+ module_volume.getVolumeName(), e);
 		}
-		
+
+		// add the module volume to LCDD
 		lcdd.add(module_volume);
 
 		// phi start for a module
 		double phi = 0;
 
-		// delta phi per module
-		double dphi = PI * 2.0 / nsides;
-
 		// make nsides modules
 		for (int i = 0; i < nsides; i++)
 		{
@@ -137,39 +159,37 @@
 			int module_number = i + 1;
 
 			// rotation of this module
-			Rotation rotation = LCDDFactory.createRotation(
-					name + "_module" + module_number + "_rotation", 
-					PI * 0.5, 
-					phi, 
-					0);
+			Rotation rotation = LCDDFactory.createRotation(name + "_module"
+					+ module_number + "_rotation", PI * 0.5, phi, 0);
 			lcdd.add(rotation);
 
 			// XY position calculation from Mokka's Geometry/Tesla/Ecal02.cc
-			Position position = LCDDFactory.createPosition(
-					name + "_module" + module_number + "_position", 
-					module_x_offset * cos(phi) - module_y_offset * sin(phi), 
-					module_x_offset * sin(phi) + module_y_offset * cos(phi), 
-					0);
+			Position position = LCDDFactory.createPosition(name + "_module"
+					+ module_number + "_position", module_x_offset * cos(phi)
+					- module_y_offset * sin(phi), module_x_offset * sin(phi)
+					+ module_y_offset * cos(phi), 0);
 			lcdd.add(position);
 
 			// place this module
 			PhysVol pv = LCDDFactory.createPhysVol(module_volume, position,
 					rotation, null);
 			pv.addPhysVolID("module", module_number);
-			
+
 			// FIXME: put these ids on subdetector envelope when have it
-			pv.addPhysVolID("system", node.getAttribute("id").getIntValue() );
-			pv.addPhysVolID("barrel",0);
-			
+			pv.addPhysVolID("system", node.getAttribute("id").getIntValue());
+			pv.addPhysVolID("barrel", 0);
+
 			motherVolume.addPhysVol(pv);
 
-			// increment phi 
-			phi += dphi;					
+			// increment phi
+			phi += dphi;
 		}
 	}
 
-	public static void buildBarrelStave(LCDD lcdd, LCDDSubdetector subdetector,
-			SensitiveDetector sensitiveDetector, Volume container) throws Exception
+	/** Build the barrel stave logical volume for this component. */
+	private void buildBarrelStave(LCDD lcdd, LCDDSubdetector subdetector,
+			SensitiveDetector sensitiveDetector, Volume container)
+			throws Exception
 	{
 		Trapezoid trd = (Trapezoid) lcdd.getSolid(container.getSolidRef());
 
@@ -187,60 +207,71 @@
 		Rotation irot = lcdd.getDefine().getRotation("identity_rot");
 
 		double z = trd.z();
-		
-		// some precomputed parameters for figuring out slice dim in X (X1)
-		double adj = ( trd.x1() - trd.x2() ) / 2; // adjacent angle of triangle
-		double hyp = sqrt( z * 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			
-		
-		System.out.println("adj="+adj);
-		System.out.println("beta="+toDegrees(beta));
 
+		// parameters for figuring out slice dim in X (X1)
+		double adj = (trd.x1() - trd.x2()) / 2; // adjacent angle of triangle
+		double hyp = sqrt(z * 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
 				.computeDetectorTotalThickness(node);
 
 		double posZ = -(subdetectorThickness / 2);
-		
-		System.out.println("slice start posZ=" + posZ);
+
 		String detectorName = subdetector.getName();
 
 		double dphi = PI * 2.0 / nsides;
-		System.out.println("dphi=" + toDegrees(dphi));
-		
+
 		double hphi = dphi / 2;
-		System.out.println("hphi=" + toDegrees(hphi));
 
 		// starting slice dim
-		double sliceX = trd.x1();		
-		System.out.println("starting slice X=" + sliceX);
-		
-		System.out.println("");
-		
+		double sliceX = trd.x1();
+
+		if (_debug)
+		{
+			System.out.println("slice start posZ=" + posZ);
+			System.out.println("dphi=" + toDegrees(dphi));
+			System.out.println("hphi=" + toDegrees(hphi));
+			System.out.println("starting slice X=" + sliceX);
+			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;
 		for (Iterator i = subdetector.getElement().getChildren("layer")
 				.iterator(); i.hasNext();)
 		{
-			Element layer = (Element) i.next();					
+			Element layer = (Element) i.next();
 			int repeat = layer.getAttribute("repeat").getIntValue();
 
 			// loop over one set of layers
 			for (int j = 0; j < repeat; j++)
 			{
-				System.out.println("layer=" + j);
-				
+				if (_debug)
+				{
+					System.out.println("layer=" + j);
+				}
+
 				// loop over the slices
 				int sliceNum = 0;
 				for (Iterator k = layer.getChildren("slice").iterator(); k
 						.hasNext();)
 				{
 					Element slice = (Element) k.next();
-					
-					System.out.println("material="+slice.getAttributeValue("material"));
-					System.out.println("thickness="+slice.getAttributeValue("thickness"));
-					System.out.println("sensitive="+slice.getAttributeValue("sensitive"));
-					
+
+					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;
@@ -254,74 +285,70 @@
 							.getDoubleValue();
 					posZ += sliceThickness / 2;
 
-					// position of slice					
+					// position of slice
 					Position slicePosition = LCDDFactory.createPosition(
 							sliceName + "_position", 0, 0, posZ);
 					lcdd.add(slicePosition);
-					
-					System.out.println("slice posZ=" + posZ);
-					
-					// 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					
-					
-					System.out.println("xcut="+xcut);
-					System.out.println("sliceX="+sliceX);
+
+					// 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
+
+					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);									
-					
+					Box sliceBox = LCDDFactory.createBox(sliceName + "_box",
+							sliceX, z, sliceThickness);
+
 					lcdd.add(sliceBox);
 
 					// material of slice
-					Material sliceMaterial = lcdd.getMaterial(slice.getAttributeValue("material"));
-					
+					Material sliceMaterial = lcdd.getMaterial(slice
+							.getAttributeValue("material"));
+
 					// volume of slice
-					Volume sliceVolume = LCDDFactory.createVolume(
-							sliceName,
-							sliceMaterial, 
-							sliceBox);
+					Volume sliceVolume = LCDDFactory.createVolume(sliceName,
+							sliceMaterial, sliceBox);
 					if (sensitive)
 					{
 						sliceVolume.setSensitiveDetector(sensitiveDetector);
 					}
-				
+
 					// volume region
 					subdetector.setRegion(lcdd, slice, sliceVolume);
-					
+
 					// volume limits
 					subdetector.setLimitSet(lcdd, slice, sliceVolume);
-											
+
 					// add volume to LCDD
 					lcdd.add(sliceVolume);
 
 					// placement of slice
 					PhysVol slicePhysVol = LCDDFactory.createPhysVol(
-							sliceVolume, 
-							slicePosition, 
-							irot);
+							sliceVolume, slicePosition, irot);
 					slicePhysVol.addPhysVolID("layer", layerNum);
 					slicePhysVol.addPhysVolID("slice", sliceNum);
 					container.addPhysVol(slicePhysVol);
 
 					// increment loop parameters
 					posZ += sliceThickness / 2;
-										
+
 					++sliceNum;
-					
-					System.out.println("");
 				}
-				
+
 				++layerNum;
 			}
 
 		}
 	}
-	
+
 	public boolean isCalorimeter()
 	{
 		return true;
@@ -339,4 +366,4 @@
 // double module_x2=648.271;
 // double module_y1=546.0;
 // double module_y2=546.0;
-// double module_z=92.0;
\ No newline at end of file
+// double module_z=92.0;

GeomConverter/test/org/lcsim/geometry/subdetector
EcalBarrelTest.xml 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalBarrelTest.xml	21 Jan 2006 02:50:07 -0000	1.2
+++ EcalBarrelTest.xml	24 Jan 2006 18:58:49 -0000	1.3
@@ -30,16 +30,11 @@
     <!-- Example EcalBarrel -->
     <detector id="2" name="EcalBarrelTest" type="EcalBarrel" readout="EcalBarrHits">
 
-      <dimensions nsides="8" inner_radius="1700.0" />
+      <dimensions nsides="8" inner_radius="1700.0" z="546.0 * 2" />
 
-        <module x1="832.271 * 2"
-                x2="648.271 * 2"
-                y="546.0 * 2"
-                x_offset="131.522" />
-
-    	<layer repeat="8">
-    	    <slice material="Lead" thickness="23.0" sensitive="yes" />
-    	</layer>
+      <layer repeat="8">
+        <slice material="Lead" thickness="23.0" sensitive="yes" />
+      </layer>
 
     </detector>
   </detectors>
CVSspam 0.2.8