Commit in projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd on MAIN
HPSTestRunTracker2014.java+688-7473144 -> 3145
cleaned up and applied same template to all volumes. Work in progress.

projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd
HPSTestRunTracker2014.java 3144 -> 3145
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java	2014-05-29 23:13:07 UTC (rev 3144)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java	2014-05-30 07:52:41 UTC (rev 3145)
@@ -33,10 +33,9 @@
 
 /**
  * 
- * Convert an SiTrackerBarrel subdetector to the LCDD format.
+ * Convert the HPS Test run tracker to the LCDD format.
  * 
- * @author Jeremy McCormick <[log in to unmask]>
- * @author Tim Nelson <[log in to unmask]>
+ * @author Per Hansson <[log in to unmask]>
  *
  */
 public class HPSTestRunTracker2014 extends LCDDSubdetector
@@ -224,126 +223,8 @@
 	
 	
 	
-	private void makeExample(LCDD lcdd, SensitiveDetector sens) throws JDOMException {
 	
 	
-	if(_debug) {
-		print("--- makeExample ----");
-		
-	}
-
-	
-	
-	String volName = "example";
-	Box box = new Box(volName + "Box", base_width, base_length , base_height/4.0);
-	lcdd.add(box);
-	Volume baseVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
-	
-	
-	
-	 org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisX = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(1., 0., 0.);
-     org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisY = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0., 1., 0.);
-     org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisZ = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0., 0., 1.);
-
-     double alpha1 = PI / 4.;
-     double alpha2 = PI / 4.;
-     double alpha3 = -PI / 4.;
-
-     //set up a rotation by alpha1 about the X axis
-     org.apache.commons.math3.geometry.euclidean.threed.Rotation r1 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(axisX, alpha1);
-
-     // find y' and z'
-     org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisYPrime = r1.applyTo(axisY);
-     //org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisZPrime = r1.applyTo(axisZ);
-
-     if(_debug) System.out.println("axisYPrime: " + axisYPrime);
-     //if(_debug) System.out.println("axisZPrime: " + axisZPrime);
-
-     //set up a rotation by alpha2 about the Y' axis
-     org.apache.commons.math3.geometry.euclidean.threed.Rotation r2 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(axisYPrime, alpha2);
-
-     //find z''
-     //org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisZPrimePrime = r2.applyTo(axisZPrime);
-     //if(_debug) System.out.println("axisZPrimePrime: " + axisZPrimePrime);
-
-     
-     
-     //set up a rotation by alpha3 about the Z'' axis
-     //org.apache.commons.math3.geometry.euclidean.threed.Rotation r3 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(axisZPrimePrime, alpha3);
-     
-     if(_debug) System.out.println("r1 (XYZ): " + r1.toString());
-     
-     org.apache.commons.math3.geometry.euclidean.threed.Rotation r12 = r2.applyTo(r1);
-     
-     //find z''
-     org.apache.commons.math3.geometry.euclidean.threed.Vector3D axisZPrimePrime = r12.applyTo(axisZ);
-     if(_debug) System.out.println("axisZPrimePrime: " + axisZPrimePrime);
-     org.apache.commons.math3.geometry.euclidean.threed.Rotation r3 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(axisZPrimePrime, alpha3);
-     
-     
-     org.apache.commons.math3.geometry.euclidean.threed.Rotation r123 = r3.applyTo(r12);
-     
-     //double [] rotations = r12.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ);
-     double [] rotations = r123.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ);
-     
-     Position pos = new Position(volName + "_position",0,0,0);
-     Rotation rot = new Rotation(volName + "_rotation",rotations[0],rotations[1],rotations[2]);
-     lcdd.add(pos);
-     lcdd.add(rot);
-	
-	
-     PhysVol basePV = new PhysVol(baseVolume, lcdd.pickMotherVolume(this), pos, rot);
-     if(_debug) {
-    	 print("Created physical vomume " + basePV.getName());
-     }
-	
-     lcdd.add(baseVolume);
-	
-	
-	
-	/*
-	
-	// Find distance to center in the local coordinate system 
-	Hep3Vector box_center_base_local = new BasicHep3Vector(base_width/2.0, base_length/2.0, base_height/2.0);
-	
-	Position pos = new Position(volName + "_position",0,0,0);
-	
-	
-	//org.apache.commons.math3.geometry.euclidean.threed.Vector3D u_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(u.v());
-	//org.apache.commons.math3.geometry.euclidean.threed.Vector3D v_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(v.v());
-	//org.apache.commons.math3.geometry.euclidean.threed.Vector3D u_prime_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(u_prime.v());
-	//org.apache.commons.math3.geometry.euclidean.threed.Vector3D v_prime_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(v_prime.v());
-	//org.apache.commons.math3.geometry.euclidean.threed.Vector3D u_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(1,0,0);
-	//org.apache.commons.math3.geometry.euclidean.threed.Rotation rot = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(u_3D,v_3D,u_prime_3D,v_prime_3D);
-	//double res[] = rot.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ);
-	
-	//org.apache.commons.math3.geometry.euclidean.threed.Rotation rot_cardan = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ,Math.PI/4.0,0,0);
-	
-	
-	//Find LCDD Euler rotation angles from coordinate system unit vectors
-	Hep3Vector lcdd_rot_angles = new BasicHep3Vector(0,0,0); 
-	getEulerAngles(new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0), new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0));
-	//Hep3Vector lcdd_rot_angles = getEulerAngles(new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0), new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0));
-	//Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
-	//Rotation rot = new Rotation(volName + "_rotation",0,Math.PI/4.0,Math.PI/2.0);
-	Rotation rot = new Rotation(volName + "_rotation",0,0,0);
-	lcdd.add(pos);
-	lcdd.add(rot);
-	
-	// Create the physical volume
-	PhysVol basePV = new PhysVol(baseVolume, lcdd.pickMotherVolume(this), pos, rot);
-
-	
-	lcdd.add(baseVolume);
-	
-	*/
-	
-	}
-	
-	
-	
-	
-	
 	private void makeBase(VolWrapper trackingWrap,
 				Hep3Vector ball_pos_base_plate, Hep3Vector vee_pos_base_plate, Hep3Vector flat_pos_base_plate, 
 				LCDD lcdd, SensitiveDetector sens) throws JDOMException {
@@ -384,10 +265,12 @@
 		
 		//translate to the mother coordinate system
 		Hep3Vector box_center_base = trans_base_to_tracking.transformed(box_center_base_local);
-				
-		print(String.format("box_center_base_local  %s", box_center_base_local.toString()));
-		print(String.format("box_center_base        %s", box_center_base.toString()));
-
+		
+		if(_debug) {
+			print(String.format("box_center_base_local  %s", box_center_base_local.toString()));
+			print(String.format("box_center_base        %s", box_center_base.toString()));
+		}
+		
 		// Create the LCDD position
 		Position pos = new Position(volName + "_position",box_center_base.x(), box_center_base.y(), box_center_base.z());
 		
@@ -475,12 +358,6 @@
 		makeSupport("bottom", baseWrap, ball_pos_csup, vee_pos_csup, flat_pos_csup, lcdd, sens );
 				
 		
-		
-	
-		
-		
-		
-		
 		//baseVolume.setVisAttributes(lcdd.getVisAttributes("BasePlateVis"));
 		lcdd.add(baseVolume);
 		
@@ -502,9 +379,6 @@
 		}
 
 		
-		
-		
-		
 
 		// create the coordinate system 
 		// width - u
@@ -559,7 +433,6 @@
 		
 		//Find LCDD Euler rotation angles from coordinate system unit vectors
 		Hep3Vector lcdd_rot_angles = getEulerAngles(base_plate_coord.u, base_plate_coord.v, new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0));
-		//Hep3Vector lcdd_rot_angles = new BasicHep3Vector(0,0,0); 
 		Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
 		lcdd.add(pos);
 		lcdd.add(rot);
@@ -616,10 +489,9 @@
 			support_height = support_bottom_height;
 		}
 		else if( name == "top" ) {
-				support_length = support_top_length;
-				support_width = support_top_width;
-				support_height = support_top_height;
-				
+			support_length = support_top_length;
+			support_width = support_top_width;
+			support_height = support_top_height;
 		} else {
 			print("Error: cannot make support for " + name);
 			System.exit(1);
@@ -629,98 +501,50 @@
 		// create the coordinate system of the c-support
 		CoordSysDef csup_coord = new CoordSysDef(ball_pos_csup, vee_pos_csup, flat_pos_csup);		
 		Transform3D trans_csup_to_base = getTransformation(csup_coord);
-		Transform3D trans_base_to_tracking = getTransformation(baseWrap.coord);
-		if(_debug) {
-			print(String.format("ball_pos_csup %s", ball_pos_csup.toString()));
-			print(String.format("vee_pos_csup  %s", vee_pos_csup.toString()));
-			print(String.format("flat_pos_csup %s", flat_pos_csup.toString()));
-			print(String.format("trans_csup_to_base:\n%s", trans_csup_to_base.toString()));
-			print(String.format("trans_base_to_tracking:\n%s", trans_base_to_tracking.toString()));
-		}
+		
 				
 		
-		// Create the support box in the local coordinate system
+		String volName = "support_" + name;
+		Box box = new Box(volName + "Box", support_width, support_length, support_height);
+		lcdd.add(box);
+		Volume supportVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
 		
-		Hep3Vector box_dim_local = new BasicHep3Vector(support_width, support_length, support_height);
-		//Hep3Vector box_dim_base_plate = trans_csup_to_base_plate.rotated(box_dim_local);
-		//Hep3Vector box_dim = trans_base_plate_to_base.rotated(box_dim_base_plate);
-		Hep3Vector box_dim = box_dim_local;	
 		
 		if(_debug) {
-			print(String.format("box_dim_local      %s", box_dim_local.toString()));
-			//print(String.format("box_dim_base_plate %s", box_dim_base_plate.toString()));
-			print(String.format("box_dim            %s", box_dim.toString()));
+			print(String.format("ball_pos_csup %s", ball_pos_csup.toString()));
+			print(String.format("vee_pos_csup  %s", vee_pos_csup.toString()));
+			print(String.format("flat_pos_csup %s", flat_pos_csup.toString()));
+			print(String.format("csup_coord:\n%s", csup_coord.toString()));
+			print(String.format("baseWrap.coord:\n%s", baseWrap.coord.toString()));
 		}
-
-		// Place the support box in the local coordinate system
 		
-		// Find distance to center
+
+
+		// Find distance to center in the local coordinate system 
 		Hep3Vector box_center_support_local = new BasicHep3Vector(support_bottom_width/2.0, support_bottom_length/2.0, support_bottom_height/2.0);
 		
-		// Rotate the local coordinates into the mother coordinate system
+		//translate to the mother coordinate system
 		Hep3Vector box_center_support_base = trans_csup_to_base.transformed(box_center_support_local);
-		Hep3Vector box_center_support_tracking = trans_base_to_tracking.transformed(box_center_support_base);
 		
-		
-		
-		// find the displacement of the center of the box from the rotation around an arbitrary point in local coordinates
-//
-//		// Find the vector from the center of rotation to a point
-//		Hep3Vector s = VecOp.sub(box_center_support_base, ball_pos_csup);
-//		//Apply the rotation to that vector	to find its displacement
-//		Hep3Vector s_rot = trans_csup_to_base.rotated(s);
-//		// adjust the center for that rotation
-//		Hep3Vector box_center_rot = VecOp.add(box_center_support_base, s_rot);
-//
-//		
-		
-		// find the position of the center in the lcdd box
+		// find the position of the center in the mother coord
 		Hep3Vector box_center = VecOp.sub(box_center_support_base, baseWrap.center);
-		//Hep3Vector box_center = transModuleToSupportCoord.rotated(box_center_sub);
-
-				
-		if(_debug) {
-			print(String.format("box_center_support_local    %s", box_center_support_local.toString()));
-			print(String.format("box_center_support_base     %s", box_center_support_base.toString()));
-			print(String.format("baseWrap.center             %s", baseWrap.center.toString()));
-			print(String.format("box_center                  %s", box_center.toString()));
-			print(String.format("box_center_support_tracking %s", box_center_support_tracking.toString()));
-		}
 		
-
-		// Find the lcdd Euler angles to go to the mother coordinate system
-		Hep3Vector lcdd_rot_angles = this.getEulerAngles(csup_coord.u, csup_coord.v, new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0));
-	
+		print(String.format("box_center_support_local  %s", box_center_support_local.toString()));
+		print(String.format("box_center_support_base   %s", box_center_support_base.toString()));
+		print(String.format("baseWrap.center           %s", baseWrap.center.toString()));
+		print(String.format("box_center                %s", box_center.toString()));
 		
-		// fix the rotation
-		//Hep3Vector lcdd_rot_angles_support = transModuleToSupportCoord.rotated(lcdd_rot_angles);
-
-		
-		// create the lcdd tags
-		//Position pos = new Position(halfModuleName + "_position",box_center.x(), box_center.y(), box_center.z());
-		//Rotation rot = new Rotation(halfModuleName + "_rotation",lcdd_rot_angles_support.x(), lcdd_rot_angles_support.y(), lcdd_rot_angles_support.z());
-		//lcdd.add(pos);
-		//lcdd.add(rot);
-		
-		
-		
-		String volName = "support_" + name;
-		Box box = new Box(volName + "Box", box_dim.x(), box_dim.y(), box_dim.z());
-		lcdd.add(box);
-
-		Volume supportVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
-
-
-		// Create the LCDD position 
+		// Create the LCDD position
 		Position pos = new Position(volName + "_position",box_center.x(), box_center.y(), box_center.z());
 		
-		
-		
-		
+		//Find LCDD Euler rotation angles from coordinate system unit vectors
+		Hep3Vector lcdd_rot_angles = getEulerAngles(csup_coord.u, csup_coord.v, new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0));
 		Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
 		lcdd.add(pos);
 		lcdd.add(rot);
+
 		
+		// Create the physical volume
 		PhysVol supportPV = new PhysVol(supportVolume, baseWrap.vol, pos, rot);
 		if(_debug) {
 	    	 print("Created physical vomume " + supportPV.getName());
@@ -737,44 +561,43 @@
 		baseWrap.daughters.add(supportWrap);
 
 		
+		
+		
+		
 		// create the support plate inside the support box coordinate system
 		// survey points on the support plate are: 
 		// ball: corner of the hinge end at the surface on the electron side
 		// vee: corner of the hinge end at the surface on the positron side
 		// flat: middle of plate at upstream end at the surface
 		
-		Hep3Vector ball_pos_support_plate = new BasicHep3Vector(0.0, 0.0, 0.0);
+		// TODO figure out what height this should be
+		Hep3Vector ball_pos_support_plate = new BasicHep3Vector(0.0, 0.0, support_plate_bottom_height);
 		Hep3Vector vee_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x() + support_plate_bottom_width, ball_pos_support_plate.y(),ball_pos_support_plate.z());
 		Hep3Vector flat_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x(), ball_pos_support_plate.y() + support_plate_bottom_length,ball_pos_support_plate.z());
-		//Hep3Vector ball_pos_support_plate = new BasicHep3Vector(0.0, -1.0 * support_height/2.0 + support_plate_bottom_height , support_length/2.0);
-		//Hep3Vector vee_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x() + support_plate_bottom_width, ball_pos_support_plate.y(),ball_pos_support_plate.z());
-		//Hep3Vector flat_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x(), ball_pos_support_plate.y(),ball_pos_support_plate.z() - support_plate_bottom_length);
-		//Hep3Vector ball_pos_support_plate = new BasicHep3Vector(-1.0 * support_width/2.0, -1.0 * support_height/2.0 + support_plate_bottom_height , support_length/2.0);
-		//Hep3Vector vee_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x() + support_plate_bottom_width, ball_pos_support_plate.y(),ball_pos_support_plate.z());
-		//Hep3Vector flat_pos_support_plate = new BasicHep3Vector(ball_pos_support_plate.x(), ball_pos_support_plate.y(),ball_pos_support_plate.z() - support_plate_bottom_length);
 		
 		makeSupportPlate(supportWrap, ball_pos_support_plate, vee_pos_support_plate, flat_pos_support_plate, lcdd, sens );
 
 		
+		
+		
+		
 			
 		
 		// create the module from positions of module ball, vee and flat w.r.t. support plate survey points
-
-		// create the coordinate system of the support plate
-		CoordSysDef support_plate_coord = new CoordSysDef(ball_pos_support_plate, vee_pos_support_plate, flat_pos_support_plate);		
-		Transform3D trans_support_plate_to_support = getTransformation(support_plate_coord);
-
+		// ball: hole on electron side
+		// vee:  slot on the positron side
+		// flat: midpoint between line joining ball and vee and offset 90deg along plate going upstream
+		
 		if(_debug) {
 			print("Make modules on support plate");
 		}
 		
-		for(int ilayer = 1; ilayer <=1; ++ilayer) {
+		for(int ilayer = 1; ilayer <=5; ++ilayer) {
 
 			String layerName = String.format("L%db", ilayer);
 			
 			print(layerName);
 
-			// position of survey positions on the support plate in the support plate coordinates system	
 			Hep3Vector ball_pos_mod_local = null;
 			Hep3Vector vee_pos_mod_local = null;
 			Hep3Vector flat_pos_mod_local = null;
@@ -812,7 +635,17 @@
 				print(String.format("flat_pos_mod_local %s", flat_pos_mod_local.toString()));
 			}
 
-			// transform to support frame
+
+			//
+			// Note that the mother volume is the support wrap box which can be different than support plate coord system.
+			// Thus I need to take that into account when making the modules
+			// create the coordinate system of the support plate in the support box
+			CoordSysDef support_plate_coord = new CoordSysDef(ball_pos_support_plate, vee_pos_support_plate, flat_pos_support_plate);		
+			Transform3D trans_support_plate_to_support = getTransformation(support_plate_coord);
+
+
+			
+			// transform module coordinates to support frame in case they are different
 			Hep3Vector ball_pos_mod = trans_support_plate_to_support.transformed(ball_pos_mod_local);
 			Hep3Vector ball_pos_mod_rot = trans_support_plate_to_support.rotated(ball_pos_mod_local);
 			Hep3Vector ball_pos_mod_tr = trans_support_plate_to_support.translated(ball_pos_mod_local);
@@ -828,7 +661,7 @@
 			}
 			
 			// make the module
-			//makeModule(layerName,supportWrap, ball_pos_mod, vee_pos_mod, flat_pos_mod,lcdd, sens);
+			makeModule(layerName,supportWrap, ball_pos_mod, vee_pos_mod, flat_pos_mod,lcdd, sens);
 		
 		} // ilayer
 		
@@ -842,60 +675,13 @@
 
 
 		
-	/*
-				
-		// Get corrections to survey ball positions from compact file to support plate positions (from e.g. survey)
-		Map<String, Hep3Vector> corr_balls = new HashMap<String,Hep3Vector>(); // save for debugging
-		for(Iterator i = node.getChildren("support_plate").iterator(); i.hasNext();) {
-			Element e = (Element)i.next();
-			if(e.getAttributeValue("name").equals("SupportPlateL1-3bot")) {
-				for(Iterator ii = e.getChildren("position").iterator(); ii.hasNext();) {
-					Element element = (Element) ii.next();
-					String name = element.getAttribute("name").getValue();
-					// get vector correction
-					Hep3Vector corr = new BasicHep3Vector(element.getAttribute("x").getDoubleValue(), element.getAttribute("y").getDoubleValue(), element.getAttribute("z").getDoubleValue());
-					if( name.equals("ball")) {
-						VecOp.add(ball_pos, corr);
-						corr_balls.put("ball", corr);
-					}
-					else if( name.equals("vee")) {
-						VecOp.add(vee_pos, corr);
-						corr_balls.put("vee", corr);
-					}
-					else if( name.equals("flat")) {
-						VecOp.add(flat_pos, corr);
-						corr_balls.put("flat", corr);
-					} 
-					else {
-						print(String.format("wrong alignment name for support plate: \"%s\"", name));
-						System.exit(1);
-					}
-				} //ii
-			}
-		} //i
 	
-		
-		// Find the local alignment corrections to the support plate
-		Hep3Vector local_translation = new BasicHep3Vector(0,0,0);
-		Hep3Vector local_rotation = new BasicHep3Vector(0,0,0);
-		for(Iterator i = node.getChildren("support_plate").iterator(); i.hasNext();) {
-			Element e = (Element)i.next();
-			if(e.getAttributeValue("name").equals("SupportPlateL1-3bot")) {
-				for(Iterator ii = e.getChildren("alignment").iterator(); ii.hasNext();) {
-					Element element = (Element) ii.next();
-					local_translation = new BasicHep3Vector(element.getAttribute("x").getDoubleValue(), element.getAttribute("y").getDoubleValue(), element.getAttribute("z").getDoubleValue());
-					local_rotation = new BasicHep3Vector(element.getAttribute("rx").getDoubleValue(), element.getAttribute("ry").getDoubleValue(), element.getAttribute("rz").getDoubleValue());
+	}
 
-				} //ii
-			}
-		} //i
-				
 	
-				
-		*/
-	}
+	
+	
 
-
 	private void makeSupportPlate(VolWrapper supportWrap,
 			Hep3Vector ball_pos_support_plate,
 			Hep3Vector vee_pos_support_plate,
@@ -908,7 +694,7 @@
 		
 		
 
-		// Create the box in mother coordinates
+		// Create the box 
 		String volName = supportWrap.name + "_supportplate";
 		Box box = new Box(volName + "Box", support_plate_bottom_width, support_plate_bottom_length, support_plate_bottom_height);
 		lcdd.add(box);
@@ -917,6 +703,7 @@
 		
 		// create the coordinate system
 		CoordSysDef support_plate_coord = new CoordSysDef(ball_pos_support_plate, vee_pos_support_plate, flat_pos_support_plate);
+		Transform3D trans_support_plate_to_support = getTransformation(support_plate_coord);
 
 		if(_debug) {
 			print(String.format("ball_pos_support_plate %s", ball_pos_support_plate.toString()));
@@ -926,19 +713,12 @@
 		}
 		
 		
-		Transform3D trans_support_plate_to_support = getTransformation(support_plate_coord);
-		
-		
 		// Find distance to center in the local coordinate system 
-		Hep3Vector box_center_support_plate_local = new BasicHep3Vector(support_plate_bottom_width/2.0, support_plate_bottom_length/2.0, support_plate_bottom_height/2.0);
+		Hep3Vector box_center_support_plate_local = new BasicHep3Vector(support_plate_bottom_width/2.0, support_plate_bottom_length/2.0, -support_plate_bottom_height/2.0);
 		
 		//translate to the mother coordinate system
 		Hep3Vector box_center_support = trans_support_plate_to_support.transformed(box_center_support_plate_local);
 		
-	
-		// find the displacement from the rotation around an arbitrary point in local coordinates
-		//Hep3Vector box_center_module_coord_rot = getRotationDisplacement(ball_pos_halfmod, box_center_module_coord, lcdd_rot_angles);
-
 		// find the position of the center in the mother coord
 		Hep3Vector box_center = VecOp.sub(box_center_support, supportWrap.center);
 
@@ -984,24 +764,22 @@
 	
 	
 
-	private void makeModule(String name, VolWrapper supportWrap, Hep3Vector ball_pos_mod, Hep3Vector vee_pos_mod, Hep3Vector flat_pos_mod, LCDD lcdd, SensitiveDetector sens) throws JDOMException 
+	private void makeModule(String name, VolWrapper supportWrap, 
+			Hep3Vector ball_pos_mod, Hep3Vector vee_pos_mod, Hep3Vector flat_pos_mod, 
+			LCDD lcdd, SensitiveDetector sens) throws JDOMException 
     {
 
 		print(String.format("----- makeModule() ------"));
 
-		// create the coordinate system of the module in the support frame
-		CoordSysDef module_coord = new CoordSysDef(ball_pos_mod, vee_pos_mod, flat_pos_mod);
-		Transform3D trans = getTransformation(module_coord); 
 		
-		if(_debug) {
-			print(String.format("module_coord:\n%s", module_coord.toString()));
-			print(String.format("module_coord trans:\n%s", trans.toString()));
-		}
 		
-		String moduleName = "module_" + name;
+		// build the module name
+		String volName = "module_" + name;		
 		
-		int layer = this.getLayerFromVolumeName(moduleName);
+		// find the module layer
+		int layer = this.getLayerFromVolumeName(volName);
 		
+		// Create the box 
 		double coldblock_thickness = -99999.9;
 		double dist_lower_sensor_edge_to_cold_block_mounting_surface = -99999.9;
 		double module_box_length = -99999.9;
@@ -1023,55 +801,78 @@
 			dist_lower_sensor_edge_to_cold_block_mounting_surface = 7.662;
 		}
 
-		box_dim_local = new BasicHep3Vector(module_box_length,module_box_height,module_box_width);
+		//box_dim_local = new BasicHep3Vector(module_box_length,module_box_height,module_box_thickness);
 		
-		Hep3Vector box_dim = trans.rotated(box_dim_local);
-		if(_debug) {
-			print(String.format("box_dim_local: %s", box_dim_local.toString()));
-			print(String.format("box_dim      : %s", box_dim.toString()));
-		}
 		
-		Box box = new Box(moduleName + "_box", box_dim.x(), box_dim.y(), box_dim.z());
+		Box box = new Box(volName + "_box", module_box_length, module_box_height, module_box_width);
 		lcdd.add(box);
-		Volume moduleVolume = new Volume(moduleName + "_volume", box, lcdd.getMaterial("Vacuum"));
+		Volume moduleVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
 		
 		
+		// create the coordinate system
+		CoordSysDef module_coord = new CoordSysDef(ball_pos_mod, vee_pos_mod, flat_pos_mod);
+		Transform3D trans_module_to_support = getTransformation(module_coord); 
 		
-		VolWrapper moduleWrap = new VolWrapper();
-		moduleWrap.name = moduleName;
-		moduleWrap.vol = moduleVolume;
-		moduleWrap.mother = supportWrap;
-		moduleWrap.coord = module_coord;
+		if(_debug) {
+			print(String.format("ball_pos_mod %s", ball_pos_mod.toString()));
+			print(String.format("ball_pos_mod  %s", ball_pos_mod.toString()));
+			print(String.format("ball_pos_mod %s", ball_pos_mod.toString()));
+			print(String.format("module_coord:\n%s", module_coord.toString()));
+		}
 		
-		// distance to the center of the box in the local coordinates
-		Hep3Vector box_center_local = new BasicHep3Vector(box_dim_local.x()/2.0-5.0, 0.0, box_dim_local.z()/2.0); 
-		//Hep3Vector box_center_local = new BasicHep3Vector(0.0, 0.0,0.0);
-		moduleWrap.center = box_center_local;
+		
+		// Find distance to center in the local coordinate system 
+		Hep3Vector box_center_local = new BasicHep3Vector(module_box_length/2.0-5.0, 0.0, module_box_width/2.0); 
 				
-		// vector to the center of module box from ball position/origin
-		Hep3Vector box_center = trans.transformed(box_center_local);
-		Position pos = new Position(moduleName + "_position",box_center.x(), box_center.y(), box_center.z());
-		Hep3Vector lcdd_rot_angles = new BasicHep3Vector(0,0,0); //getLCDDRotation(survey_coord);
-		Rotation rot = new Rotation(moduleName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
+		//translate to the mother coordinate system
+		Hep3Vector box_center_support = trans_module_to_support.transformed(box_center_local);
+		
+		// find the position of the center in the mother coord
+		Hep3Vector box_center = VecOp.sub(box_center_support, supportWrap.center);
+
+		if(_debug) {
+			print(String.format("box_center_local        %s", box_center_local.toString()));
+			print(String.format("box_center_support        %s", box_center_support.toString()));
+			print(String.format("supportWrap.center              %s", supportWrap.center.toString()));
+			print(String.format("box_center                      %s", box_center.toString()));
+		}
+
+		// Create the LCDD position
+		Position pos = new Position(volName + "_position",box_center.x(), box_center.y(), box_center.z());
+				
+		//Find LCDD rotation angles from coordinate system unit vectors
+		Hep3Vector lcdd_rot_angles = this.getEulerAngles(module_coord.u, module_coord.v, new BasicHep3Vector(1,0,0), new BasicHep3Vector(0,1,0));
+		Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
 		lcdd.add(pos);
 		lcdd.add(rot);
+
+
 		
 		PhysVol physVolume = new PhysVol(moduleVolume, supportWrap.vol, pos, rot);
-		supportWrap.daughters.add(moduleWrap);
+		
+		VolWrapper moduleWrap = new VolWrapper();
+		moduleWrap.name = volName;
+		moduleWrap.vol = moduleVolume;
+		moduleWrap.mother = supportWrap;
+		moduleWrap.coord = module_coord;
 		moduleWrap.pv = physVolume;
+		moduleWrap.center = box_center_local;
 		moduleWrap.pos_vol = pos;
 		moduleWrap.rot_vol = rot;
-
-		if(_debug) {
-			print(String.format("module box center local %s",box_center_local.toString()));
-			print(String.format("module box center %s",box_center.toString()));
-		}
+		supportWrap.daughters.add(moduleWrap);
 		
 
 		// Find the coordinate system of the half-modules w.r.t. to the module survey points
-		// We are going to know the sensor center position w.r.t. module frame so the half-module 
+		// We are going to know the sensor center position w.r.t. module coordinate system so the half-module 
 		// is really just a dummy volume to contain the daughters. Therefore place it at the same place 
 		// as where the sensor coordinate system will be to make things simpler.
+
+		// Hints:
+		// The local half-module coord system for axial sensor will be built 
+		// with apv25 chips in more negative v-direction than sensor 
+		// i.e. v-direction is pointing upstream
+		// For the stereo it is 
+		// 
 		
 		// Distance from sensor to CF edge: 180mm
 		// Distance from CF edge to screw hole: 30mm
@@ -1098,7 +899,7 @@
 			print(String.format("flat_pos_halfmod_axial_local %s", flat_pos_halfmod_axial_local.toString()));
 		}
 		
-		//makeHalfModule("axial",moduleWrap, ball_pos_halfmod_axial_local, vee_pos_halfmod_axial_local, flat_pos_halfmod_axial_local,lcdd,sens);
+		makeHalfModule("axial",moduleWrap, ball_pos_halfmod_axial_local, vee_pos_halfmod_axial_local, flat_pos_halfmod_axial_local,lcdd,sens);
 
 		
 		
@@ -1128,16 +929,22 @@
 			print(String.format("flat_pos_coldblock_local %s", flat_pos_coldblock_local.toString()));
 		}
 		
-		//makeColdBlock(moduleWrap, ball_pos_coldblock_local, vee_pos_coldblock_local, flat_pos_coldblock_local,lcdd,sens);
+		makeColdBlock(moduleWrap, ball_pos_coldblock_local, vee_pos_coldblock_local, flat_pos_coldblock_local,lcdd,sens);
 
 		
 		
+		// stereo module
+		
+
+		
 		final double ball_pos_halfmod_stereo_local_x =  ball_pos_halfmod_axial_local_x; 
-		final double ball_pos_halfmod_stereo_local_y =  -1.0 * ball_pos_halfmod_axial_local_y; // note minus sign
+		final double ball_pos_halfmod_stereo_local_y =  -1.0 * ball_pos_halfmod_axial_local_y; // note minus sign to separate from axial
 		final double ball_pos_halfmod_stereo_local_z =  ball_pos_halfmod_axial_local_z;
 		final double vee_pos_halfmod_stereo_local_x =  ball_pos_halfmod_stereo_local_x + sensor_length/2.0;
-		final double vee_pos_halfmod_stereo_local_y =  ball_pos_halfmod_stereo_local_y;
+		//final double vee_pos_halfmod_stereo_local_x =  ball_pos_halfmod_stereo_local_x + sensor_length/2.0*Math.cos(stereo_angle);
+		final double vee_pos_halfmod_stereo_local_y =  ball_pos_halfmod_stereo_local_y; 
 		final double vee_pos_halfmod_stereo_local_z =  ball_pos_halfmod_stereo_local_z;
+		//final double vee_pos_halfmod_stereo_local_z =  ball_pos_halfmod_stereo_local_z + sensor_length/2.0*Math.sin(stereo_angle);
 		final double flat_pos_halfmod_stereo_local_x =  ball_pos_halfmod_stereo_local_x;
 		final double flat_pos_halfmod_stereo_local_y =  ball_pos_halfmod_stereo_local_y + sensor_thickness/2.0;
 		final double flat_pos_halfmod_stereo_local_z =  ball_pos_halfmod_stereo_local_z;		
@@ -1152,9 +959,64 @@
 			print(String.format("flat_pos_halfmod_stereo_local %s", flat_pos_halfmod_stereo_local.toString()));
 		}
 		
-		//makeHalfModule("stereo",moduleWrap, ball_pos_halfmod_stereo_local, vee_pos_halfmod_stereo_local, flat_pos_halfmod_stereo_local,lcdd,sens);
+		/*
+		// determine stereo angle
+		// note that the sign of the stereo angle in this rotation is based on an active rotation, a convention different from lcdd.
+		// I first flip around local u
 
+		double sinTheta = Math.sin(Math.PI/2.0);
+		double cosTheta = Math.cos(Math.PI/2.0);
+		Hep3Matrix mat1 = new BasicHep3Matrix(1,0,0,0,cosTheta,-sinTheta,0,sinTheta,cosTheta);
+		Rotation3D rot1 = new Rotation3D(mat1);
+
+		// and then do a clockwise rotation (negative) of the stereo angle around local v
+		double stereo_angle;
+		if(layer<4) {
+			stereo_angle = -0.1;
+		} else {
+			stereo_angle = -0.05;
+		}
+
+		sinTheta = Math.sin(stereo_angle);
+		cosTheta = Math.cos(stereo_angle);
+
+		Hep3Matrix mat2 = new BasicHep3Matrix(cosTheta,0,sinTheta,0,1,0,-sinTheta,0,cosTheta);
+		Rotation3D rot2 = new Rotation3D(mat2);
+
+		if(_debug) {
+			print(String.format("flip for stereo half-module\nrot1:\n %s", rot1.toString()));
+			
+		}
 		
+		// apply to coordinate system to rotate into place
+		rot1.rotate(ball_pos_halfmod_stereo_local);
+		rot1.rotate(vee_pos_halfmod_stereo_local);
+		rot1.rotate(flat_pos_halfmod_stereo_local);
+		
+		
+		if(_debug) {
+			print(String.format("ball_pos_halfmod_stereo_local %s", ball_pos_halfmod_stereo_local.toString()));
+			print(String.format("vee_pos_halfmod_stereo_local %s", vee_pos_halfmod_stereo_local.toString()));
+			print(String.format("flat_pos_halfmod_stereo_local %s", flat_pos_halfmod_stereo_local.toString()));
+		}
+				
+		print(String.format("stereo angle rotationfor stereo half-module\nrot2:\n %s", rot2.toString()));
+
+		// apply to coordinate system to rotate into place
+		rot2.rotate(ball_pos_halfmod_stereo_local);
+		rot2.rotate(vee_pos_halfmod_stereo_local);
+		rot2.rotate(flat_pos_halfmod_stereo_local);
+
+		if(_debug) {
+			print(String.format("ball_pos_halfmod_stereo_local %s", ball_pos_halfmod_stereo_local.toString()));
+			print(String.format("vee_pos_halfmod_stereo_local %s", vee_pos_halfmod_stereo_local.toString()));
+			print(String.format("flat_pos_halfmod_stereo_local %s", flat_pos_halfmod_stereo_local.toString()));
+		}
+		*/
+		
+		makeHalfModule("stereo",moduleWrap, ball_pos_halfmod_stereo_local, vee_pos_halfmod_stereo_local, flat_pos_halfmod_stereo_local,lcdd,sens);
+
+		
 		moduleVolume.setVisAttributes(lcdd.getVisAttributes("ModuleVis"));
 		
 		lcdd.add(moduleVolume);	
@@ -1163,112 +1025,126 @@
     }
 	
 	
-	private void makeHalfModule(String side, VolWrapper moduleWrap, Hep3Vector ball_pos_halfmod, Hep3Vector vee_pos_halfmod, Hep3Vector flat_pos_halfmod, LCDD lcdd, SensitiveDetector sens) throws JDOMException {
+	private void makeHalfModule(String side, VolWrapper moduleWrap, 
+			Hep3Vector ball_pos_halfmod, Hep3Vector vee_pos_halfmod, Hep3Vector flat_pos_halfmod, 
+			LCDD lcdd, SensitiveDetector sens) throws JDOMException {
 	
 		if(_debug) {
 			print("--- makeHalfModule " + side);
 		}
 		
-		CoordSysDef half_module_coord = new CoordSysDef(ball_pos_halfmod, vee_pos_halfmod, flat_pos_halfmod);		
-		Transform3D transToModuleCoord = getTransformation(half_module_coord); 
-		Transform3D transModuleToSupportCoord = getTransformation(moduleWrap.coord); 
 		
-		if(_debug) {
-			print(String.format("half_module_coord:\n%s", half_module_coord.toString()));
-			print(String.format("transToModuleCoord:\n%s", transToModuleCoord.toString()));
-			print(String.format("transModuleToSupportCoord:\n%s", transModuleToSupportCoord.toString()));
-		}
-
-		
 		// the half-module box is built based on the location of the center of the sensor box
-		String halfModuleName = moduleWrap.name + "_halfmodule_" + side;
-		//find the bounding box for the half module
-		final double x_local = this.half_module_length; 
-		final double y_local = this.half_module_thickness; 
-		final double z_local = this.half_module_width;	
-		Hep3Vector box_dim_local = new BasicHep3Vector( x_local, y_local, z_local); 
-		// rotate to module coordinate system
-		Hep3Vector box_dim_module = transToModuleCoord.rotated(box_dim_local);
-		// apply the same rotation as to mother 
-		Hep3Vector box_dim = transModuleToSupportCoord.rotated(box_dim_module);
+		String volName = moduleWrap.name + "_halfmodule_" + side;
 		
-		if(_debug) {
-			print(String.format("box_dim_local:\n%s", box_dim_local.toString()));
-			print(String.format("box_dim_module:\n%s", box_dim_module.toString()));
-			print(String.format("box_dim:\n%s", box_dim.toString()));
-		}		
 		
-		Box box = new Box(halfModuleName + "Box", box_dim.x(), box_dim.y(), box_dim.z());
+		Box box = new Box(volName + "Box", half_module_length, half_module_thickness, half_module_width);
 		lcdd.add(box);
-		Volume halfModuleVolume = new Volume(halfModuleName + "_volume", box, lcdd.getMaterial("Vacuum"));
+		Volume halfModuleVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
 
 		
-		// vector to the center of the half module box from the half module ball position
+				
+		// create the coordinate system
+		CoordSysDef half_module_coord = new CoordSysDef(ball_pos_halfmod, vee_pos_halfmod, flat_pos_halfmod);		
+		Transform3D transToModuleCoord = getTransformation(half_module_coord); 
+		
+		
+		
+		
+		if(_debug) {
+			print(String.format("ball_pos_halfmod %s", ball_pos_halfmod.toString()));
+			print(String.format("vee_pos_halfmod  %s", vee_pos_halfmod.toString()));
+			print(String.format("flat_pos_halfmod %s", flat_pos_halfmod.toString()));
+			print(String.format("half_module_coord:\n%s", half_module_coord.toString()));
+		}
+				
+		// Find distance to center in the local coordinate system 
+		// Note that this can be different between axial and stereo since the survey positions determine the local coordinate 
+		// system now.
+		// I'm not sure this feels good but this has to be done somewhere
 		double box_center_local_x =  this.half_module_length/2.0 - ( (170.00 + 10.00) - this.sensor_length/2.0); 
 		double box_center_local_y = -1.0*this.half_module_thickness/2.0 + (cf_thickness + kapton_thickness + sensor_thickness/2.0);
 		double box_center_local_z = this.half_module_width/2.0 - ( 12.66 - (8.83 -3.00) + this.sensor_width/2.0 ); 
+
+		// stereo sensor is located at the same place but flipped pi around so v and w switches sign
+		//if(side.equalsIgnoreCase("stereo")) {
+		//	box_center_local_y = box_center_local_y*-1.0;
+		//	box_center_local_z = box_center_local_z*-1.0;
+		//}
+		
 		Hep3Vector box_center_local = new BasicHep3Vector( box_center_local_x, box_center_local_y, box_center_local_z); 
-		//Hep3Vector box_center_local = new BasicHep3Vector( 0.,0.,0.);
 		
+		//translate to the mother coordinate system
+		Hep3Vector box_center_module_coord = transToModuleCoord.transformed(box_center_local);
 		
-		VolWrapper halfModuleWrap = new VolWrapper();
-		halfModuleWrap.name = halfModuleName;
-		halfModuleWrap.vol = halfModuleVolume;
-		halfModuleWrap.coord = half_module_coord;
-		halfModuleWrap.center = box_center_local;
-
+		//Find LCDD rotation angles 
+		// Since we want to keep the local coordinate system the same for both axial and stereo
+		// sensors we rotate the half-modules in place "by-hand" and not only from system unit vectors
 		
-		Hep3Vector box_center_module_coord = transToModuleCoord.transformed(box_center_local);
-		Hep3Vector lcdd_rot_angles;
+		//TODO make this compounded with the below for stereo sensors
+		Hep3Vector lcdd_rot_angles = this.getEulerAngles(half_module_coord.u, half_module_coord.v, new BasicHep3Vector(1,0,0), new BasicHep3Vector(0,1,0));
+
 		if(side.equals("stereo")) {
-			if(halfModuleName.contains("L1") || halfModuleName.contains("L2") ||halfModuleName.contains("L3")) {
-				lcdd_rot_angles = new BasicHep3Vector(Math.PI,-0.1,0); 
+			int layer = this.getLayerFromVolumeName(moduleWrap.name);
+			double stereo_angle;
+			if(layer<4) {
+				stereo_angle = -0.1;
 			} else {
-				lcdd_rot_angles = new BasicHep3Vector(Math.PI,-0.05,0.0); 
+				stereo_angle = -0.05;
 			}
-		} 
-		else {
-			//lcdd_rot_angles = new BasicHep3Vector(Math.PI,0,0); 		
-			lcdd_rot_angles = new BasicHep3Vector(0,0,0); 		
+			
+			org.apache.commons.math3.geometry.euclidean.threed.Rotation rot_stereo = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ, Math.PI, stereo_angle,0);
+			double res[] = rot_stereo.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ);
+			Hep3Vector lcdd_rot_angles_2 = new BasicHep3Vector(res);
+		
+			if(_debug) {
+				print(String.format("lcdd_rot_angles                 %s", lcdd_rot_angles.toString()));
+				print(String.format("lcdd_rot_angles_2               %s", lcdd_rot_angles_2.toString()));
+			}		
+		
+			lcdd_rot_angles = lcdd_rot_angles_2;
 		}
-
-		// find the displacement from the rotation around an arbitrary point in local coordinates
-		Hep3Vector box_center_module_coord_rot = getRotationDisplacement(ball_pos_halfmod, box_center_module_coord, lcdd_rot_angles);
+		// Find the displacement of the box center due to rotation about different origin
+		Hep3Vector box_center_module_coord_rot = this.getRotationDisplacement(half_module_coord.origin, box_center_module_coord, lcdd_rot_angles);
+		//Hep3Vector box_center_module_coord_rot = box_center_module_coord;
 		
-		// find the position of the center in the module box
-		Hep3Vector box_center_sub = VecOp.sub(box_center_module_coord_rot, moduleWrap.center);
-		Hep3Vector box_center = transModuleToSupportCoord.rotated(box_center_sub);
+		// find the position of the center in the mother coord
+		Hep3Vector box_center = VecOp.sub(box_center_module_coord_rot, moduleWrap.center);
 
-		// fix the rotation
-		Hep3Vector lcdd_rot_angles_support = transModuleToSupportCoord.rotated(lcdd_rot_angles);
-
+		if(_debug) {
+			print(String.format("box_center_local               %s", box_center_local.toString()));
+			print(String.format("box_center_module_coord        %s", box_center_module_coord.toString()));
+			print(String.format("box_center_module_coord_rot    %s", box_center_module_coord_rot.toString()));
+			print(String.format("moduleWrap.center              %s", moduleWrap.center.toString()));
+			print(String.format("box_center                     %s", box_center.toString()));
+		}
 		
-		// create the lcdd tags
-		Position pos = new Position(halfModuleName + "_position",box_center.x(), box_center.y(), box_center.z());
-		Rotation rot = new Rotation(halfModuleName + "_rotation",lcdd_rot_angles_support.x(), lcdd_rot_angles_support.y(), lcdd_rot_angles_support.z());
+		// Create the LCDD position
+		Position pos = new Position(volName + "_position",box_center.x(), box_center.y(), box_center.z());
+		// Create the LCDD rotation
+		Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
 		lcdd.add(pos);
 		lcdd.add(rot);
-		
+
 		PhysVol physVolume = new PhysVol(halfModuleVolume, moduleWrap.vol, pos, rot);
+		
+		VolWrapper halfModuleWrap = new VolWrapper();
+		halfModuleWrap.name = volName;
+		halfModuleWrap.vol = halfModuleVolume;
+		halfModuleWrap.coord = half_module_coord;
+		halfModuleWrap.center = box_center_local;
 		halfModuleWrap.pv = physVolume;
 		halfModuleWrap.pos_vol = pos;
 		halfModuleWrap.rot_vol = rot;
 		halfModuleWrap.mother = moduleWrap;
 		moduleWrap.daughters.add(halfModuleWrap);
 		
-		if(_debug) {
-			print(String.format("box_center_local %s", box_center_local.toString()));
-			print(String.format("box_center_module_coord  %s", box_center_module_coord.toString()));
-			print(String.format("box_center_module_coord_rot %s", box_center_module_coord_rot.toString()));
-			print(String.format("moduleWrap.center %s", moduleWrap.center.toString()));
-			print(String.format("box_center_sub %s", box_center_sub.toString()));
-			print(String.format("box_center %s", box_center.toString()));
-			print(String.format("lcdd_rot_angles %s", lcdd_rot_angles.toString()));
-			print(String.format("lcdd_rot_angles_support %s", lcdd_rot_angles_support.toString()));
-			
-			
-		}
 		
+		
+		
+		
+		
+		
 		// create the half module components 
 		
 		Hep3Vector ball_pos_sensor_local = new BasicHep3Vector(0,0,0);
@@ -1350,23 +1226,9 @@
 			print("--- makeColdBlock ");
 		}
 		
-		CoordSysDef coldblock_coord = new CoordSysDef(ball_pos_coldblock, vee_pos_coldblock, flat_pos_coldblock);		
-		Transform3D transToModuleCoord = getTransformation(coldblock_coord); 
-		Transform3D transModuleToSupportCoord = getTransformation(moduleWrap.coord); 
+		String volName = moduleWrap.name + "_coldBlock";
 		
-		if(_debug) {
-			print(String.format("coldblock_coord:\n%s", coldblock_coord.toString()));
-			print(String.format("transToModuleCoord:\n%s", transToModuleCoord.toString()));
-			print(String.format("transModuleToSupportCoord:\n%s", transModuleToSupportCoord.toString()));
-		}
-
-		
-		String coldBlockName = moduleWrap.name + "_coldBlock";
-		
 		int layer = getLayerFromVolumeName(moduleWrap.name);
-		double x_local = -99999.9; 
-		double y_local = -99999.9; 
-		double z_local = -99999.9;
 		double coldblock_length = -99999.9; 
 		double coldblock_thickness = -99999.9; 
 		double coldblock_width = -99999.9; 
@@ -1383,76 +1245,65 @@
 			System.exit(1);
 		}
 
-		x_local = coldblock_length; 
-		y_local = coldblock_thickness; 
-		z_local = coldblock_width;	
+		
+		Box box = new Box(volName + "Box", coldblock_length, coldblock_thickness, coldblock_width);
+		lcdd.add(box);
+		Volume coldBlockVolume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
 
 		
-		Hep3Vector box_dim_local = new BasicHep3Vector( x_local, y_local, z_local); 
-		// rotate to module coordinate system
-		Hep3Vector box_dim_module = transToModuleCoord.rotated(box_dim_local);
-		// apply the same rotation as to mother 
-		Hep3Vector box_dim = transModuleToSupportCoord.rotated(box_dim_module);
-		
+				
+		// create the coordinate system
[truncated at 1000 lines; 892 more skipped]
SVNspam 0.1


Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1