Commit in projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry on MAIN | |||
compact/converter/lcdd/HPSTestRunTracker2014.java | +7 | -162 | 3350 -> 3351 |
/HPSTestRunTracker2014GeometryDefinition.java | +47 | -37 | 3350 -> 3351 |
/HPSTrackerJavaBuilder.java | +5 | -27 | 3350 -> 3351 |
/HPSTrackerLCDDBuilder.java | +3 | -10 | 3350 -> 3351 |
util/TransformationUtils.java | +177 | added 3351 | |
+239 | -236 |
Pulling out transformation to a util class. Fix cardan angle extraction. Adding stereo sensor to geometry. Padding module box size to accomodate the half-module volume and some alignment corrections. Random size for now but may need to quantify the sizes later or add tests to avoid overlaps.
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java 2014-09-27 20:47:23 UTC (rev 3350) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java 2014-09-28 21:36:25 UTC (rev 3351) @@ -3,14 +3,12 @@
import static java.lang.Math.PI; import hep.physics.vec.BasicHep3Vector; import hep.physics.vec.Hep3Vector;
-import hep.physics.vec.VecOp;
import java.util.Iterator; import org.jdom.DataConversionException; import org.jdom.Element; import org.jdom.JDOMException;
-import org.lcsim.detector.RotationGeant;
import org.lcsim.detector.Transform3D; import org.lcsim.geometry.compact.converter.lcdd.HPSTrackerLCDDBuilder.GhostLCDDBaseGeometry; import org.lcsim.geometry.compact.converter.lcdd.HPSTrackerLCDDBuilder.LCDDBaseGeometry;
@@ -21,6 +19,7 @@
import org.lcsim.geometry.compact.converter.lcdd.util.Rotation; import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector; import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+import org.lcsim.geometry.util.TransformationUtils;
/**
@@ -296,160 +295,6 @@
- public static void printMatrix(double [][] mat) { - for(int r=0;r<3;++r) { - String row = ""; - for(int c=0;c<3;++c) { - row += String.format(" %f",mat[r][c]); - } - System.out.println(row); - } - } - - - - public static Hep3Vector getEulerAngles(Hep3Vector u, Hep3Vector v, Hep3Vector u_prime, Hep3Vector v_prime) { - int debug = 0; - if (debug>0) System.out.printf("getEulerAngles: u %s v%s -> %s %s\n",u.toString(),v.toString(),u_prime.toString(),v_prime.toString()); - // Convert to correct API - 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()); - //Create the rotation - // Note that the constructor used here creates the rotation using active transformations - 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); - // The the Cardan angles of the rotation - // Since the rotation was created based on active transformations convert to passive right here. - // This conversion is simply to reverse the order of rotations. - double res[] = rot.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.ZYX); - Hep3Vector euler = new BasicHep3Vector(res[2],res[1],res[0]); - //double res[] = rot.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ); - //Hep3Vector euler = new BasicHep3Vector(res); - - if(debug>0) { - System.out.println("Input: u " + u_3D.toString() + " v " + v_3D.toString() + " u' " + u_prime_3D.toString() + " v' " + v_prime_3D.toString()); - System.out.println("rot matrix:"); - printMatrix(rot.getMatrix()); - - System.out.println("Resulting XYZ angles " + euler.toString()); - } - - if(debug>1) { - System.out.println("------- TESTING "); - - org.apache.commons.math3.geometry.euclidean.threed.Rotation r123 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ, res[0], res[1], res[2]); - - - org.apache.commons.math3.geometry.euclidean.threed.Vector3D x_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(1,0,0); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D y_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0,1,0); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D z_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0,0,1); - - - org.apache.commons.math3.geometry.euclidean.threed.Rotation r1 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(x_3D,res[0]); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D x_3D_p = r1.applyTo(x_3D); - org.apache.commons.math3.geometry.euclidean.threed.Rotation r3 = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(z_3D,res[2]); - org.apache.commons.math3.geometry.euclidean.threed.Rotation r13 = r3.applyTo(r1); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D x_3D_pp = r13.applyTo(x_3D); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D y_3D_pp = r13.applyTo(y_3D); - org.apache.commons.math3.geometry.euclidean.threed.Vector3D y_3D_pp_2 = r123.applyTo(y_3D); - System.out.println("x_3D (" + x_3D.getX() + "," + x_3D.getY() + "," + x_3D.getZ()); - System.out.println("y_3D (" + y_3D.getX() + "," + y_3D.getY() + "," + y_3D.getZ()); - System.out.println("z_3D (" + z_3D.getX() + "," + z_3D.getY() + "," + z_3D.getZ()); - System.out.println("r1 " + r1.toString()); - printMatrix(r1.getMatrix()); - System.out.println("x_3D_p (" + x_3D_p.getX() + "," + x_3D_p.getY() + "," + x_3D_p.getZ()); - System.out.println("r3 " + r3.toString()); - printMatrix(r3.getMatrix()); - System.out.println("r13 " + r13.toString()); - printMatrix(r13.getMatrix()); - System.out.println("x_3D_pp (" + x_3D_pp.getX() + "," + x_3D_pp.getY() + "," + x_3D_pp.getZ()); - System.out.println("y_3D_pp (" + y_3D_pp.getX() + "," + y_3D_pp.getY() + "," + y_3D_pp.getZ()); - System.out.println("r123 " + r123.toString()); - printMatrix(r123.getMatrix()); - System.out.println("y_3D_pp_2 (" + y_3D_pp_2.getX() + "," + y_3D_pp_2.getY() + "," + y_3D_pp_2.getZ()); - System.out.println("------- "); - } - return euler; - } - - public static Hep3Vector getActiveEulerAngles(Hep3Vector u, Hep3Vector v, Hep3Vector u_prime, Hep3Vector v_prime) { - int debug = 0; - if (debug>0) System.out.printf("getEulerAngles: u %s v%s -> %s %s\n",u.toString(),v.toString(),u_prime.toString(),v_prime.toString()); - // Convert to correct API - 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()); - //Create the rotation - // Note that the constructor used here creates the rotation using active transformations - 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); - // The the Cardan angles of the rotation - double res[] = rot.getAngles(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ); - Hep3Vector euler = new BasicHep3Vector(res[0],res[1],res[2]); - - return euler; - } - - - public static double[][] getActiveEulerAnglesMatrix(Hep3Vector u, Hep3Vector v, Hep3Vector u_prime, Hep3Vector v_prime) { - int debug = 0; - if (debug>0) System.out.printf("getEulerAngles: u %s v%s -> %s %s\n",u.toString(),v.toString(),u_prime.toString(),v_prime.toString()); - // Convert to correct API - 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()); - //Create the rotation - // Note that the constructor used here creates the rotation using active transformations - 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); - // The the Cardan angles of the rotation - // Since the rotation was created based on active transformations convert to passive right here. - // This conversion is simply to reverse the order of rotations. - return rot.getMatrix(); - - } - - - - - - /** - * Find the displacement of a point when rotating around an arbitrary position - * @param origin_of_rotation - * @param point - * @param lcdd_rot_angles - * @return - */ - public static Hep3Vector getRotationDisplacement(Hep3Vector origin_of_rotation, - Hep3Vector point, Hep3Vector lcdd_rot_angles) { - - // Find the vector from the center of rotation to the point - Hep3Vector s = VecOp.sub(point, origin_of_rotation ); - //Apply the rotation to the vector - RotationGeant r = new RotationGeant(lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z()); - Hep3Vector s_prime = r.rotated(s); - // Find the displaced point - Hep3Vector point_rot = VecOp.add(origin_of_rotation, s_prime ); - /* - if(_debug) { - print("--- getRotationDisplacement---"); - print(String.format("point: %s", point.toString())); - print(String.format("origin_of_rotation: %s", origin_of_rotation.toString())); - print(String.format("s:\n%s", s.toString())); - print(String.format("r:\n%s", r.toString())); - print(String.format("s_prime:\n%s", s_prime.toString())); - print(String.format("point_rot:\n%s", point_rot.toString())); - print("--- getRotationDisplacement END---"); - } - */ - return point_rot; - } - - - - -
private void makeBeamPlane(Volume motherVolume, Hep3Vector ball_pos_base_plate, Hep3Vector vee_pos_base_plate,Hep3Vector flat_pos_base_plate, LCDD lcdd, SensitiveDetector sens) throws JDOMException {
@@ -499,7 +344,7 @@
Position pos = new Position(volName + "_position",box_center_base.x(), box_center_base.y(), box_center_base.z()); //Find LCDD Euler rotation angles from coordinate system unit vectors
- Hep3Vector lcdd_rot_angles = getEulerAngles(beamplane_coord.v(), beamplane_coord.w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
+ Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(beamplane_coord.v(), beamplane_coord.w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z()); lcdd.add(pos); lcdd.add(rot);
@@ -801,7 +646,7 @@
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 w_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(w.v());
- Hep3Vector euler_angles = getEulerAngles(v_L1, w_L1, v, w);
+ Hep3Vector euler_angles = TransformationUtils.getCardanAngles(v_L1, w_L1, v, w);
//Get the generic rotation org.apache.commons.math3.geometry.euclidean.threed.Rotation r = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(v_3D_L1,w_3D_L1,v_3D, w_3D);
@@ -1242,7 +1087,7 @@
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 w_3D = new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(w.v());
- Hep3Vector euler_angles = getEulerAngles(v_L1, w_L1, v, w);
+ Hep3Vector euler_angles = TransformationUtils.getCardanAngles(v_L1, w_L1, v, w);
//Get the generic rotation org.apache.commons.math3.geometry.euclidean.threed.Rotation r = new org.apache.commons.math3.geometry.euclidean.threed.Rotation(v_3D_L1,w_3D_L1,v_3D, w_3D);
@@ -1669,7 +1514,7 @@
Hep3Vector v_L1 = new BasicHep3Vector(-1/Math.sqrt(2),0,1/Math.sqrt(2)); Hep3Vector w_L1 = new BasicHep3Vector(0,-1,0);
- Hep3Vector euler_angles = getEulerAngles(u_L1, v_L1, u, v);
+ Hep3Vector euler_angles = TransformationUtils.getCardanAngles(u_L1, v_L1, u, v);
@@ -1750,7 +1595,7 @@
Hep3Vector v_L1 = new BasicHep3Vector(0,0,1); Hep3Vector w_L1 = new BasicHep3Vector(0,-1,0);
- Hep3Vector euler_angles = getEulerAngles(u_L1, v_L1, u, v);
+ Hep3Vector euler_angles = TransformationUtils.getCardanAngles(u_L1, v_L1, u, v);
@@ -1833,7 +1678,7 @@
Hep3Vector v_L1 = new BasicHep3Vector(0,0,1); Hep3Vector w_L1 = new BasicHep3Vector(1/Math.sqrt(2),-1/Math.sqrt(2),0);
- Hep3Vector euler_angles = getEulerAngles(u_L1, v_L1, u, v);
+ Hep3Vector euler_angles = TransformationUtils.getCardanAngles(u_L1, v_L1, u, v);
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014GeometryDefinition.java 2014-09-27 20:47:23 UTC (rev 3350) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014GeometryDefinition.java 2014-09-28 21:36:25 UTC (rev 3351) @@ -12,7 +12,6 @@
import org.lcsim.detector.Rotation3D; import org.lcsim.detector.Transform3D; import org.lcsim.detector.Translation3D;
-import org.lcsim.geometry.compact.converter.lcdd.util.Box;
import hep.physics.vec.BasicHep3Matrix; import hep.physics.vec.BasicHep3Vector;
@@ -319,14 +318,14 @@
private void calcAndSetFlatPos() { if(HPSTestRunTracker2014GeometryDefinition.use30mradRotation) { // find the rotation to place the flat point
- org.apache.commons.math3.geometry.euclidean.threed.Rotation rot1_csup = - new org.apache.commons.math3.geometry.euclidean.threed.Rotation( - new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(vee_pos_csup_pin_bottom_x-ball_pos_csup_pin_bottom_x,
+ Rotation rot1_csup = + new Rotation( + new Vector3D(vee_pos_csup_pin_bottom_x-ball_pos_csup_pin_bottom_x,
vee_pos_csup_pin_bottom_y-ball_pos_csup_pin_bottom_y, vee_pos_csup_pin_bottom_z-ball_pos_csup_pin_bottom_z),
- new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(1,0,0));
+ new Vector3D(1,0,0));
- org.apache.commons.math3.geometry.euclidean.threed.Vector3D flat_pos_csup_pin_bottom_3D_rot = rot1_csup.applyTo(new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0,10.0,0));
+ Vector3D flat_pos_csup_pin_bottom_3D_rot = rot1_csup.applyTo(new Vector3D(0,10.0,0));
// translate double flat_pos_csup_pin_bottom_x = ball_pos_csup_pin_bottom_x + flat_pos_csup_pin_bottom_3D_rot.getX(); double flat_pos_csup_pin_bottom_y = ball_pos_csup_pin_bottom_y + flat_pos_csup_pin_bottom_3D_rot.getY();
@@ -400,13 +399,13 @@
setBallPos(SupportBottom.ball_pos_csup_bearings_bottom_x, SupportBottom.ball_pos_csup_bearings_bottom_y, ball_pos_csup_bearings_top_z); setVeePos(SupportBottom.vee_pos_csup_bearings_bottom_x, SupportBottom.vee_pos_csup_bearings_bottom_y, ball_pos_csup_bearings_top_z); // build the rotation to find the proper location of the flat
- org.apache.commons.math3.geometry.euclidean.threed.Rotation rot_csup_top = - new org.apache.commons.math3.geometry.euclidean.threed.Rotation(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ,
+ Rotation rot_csup_top = + new Rotation(RotationOrder.XYZ,
SupportPlateTop.support_plate_top_tilt_angle, 0.0, 0.0 ); // apply to flat local position (as for bottom it is arbitrary offset)
- org.apache.commons.math3.geometry.euclidean.threed.Vector3D flat_pos_csup_bearings_top_3D_rot = - rot_csup_top.applyTo(new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0.0,10.0,0.0));
+ Vector3D flat_pos_csup_bearings_top_3D_rot = + rot_csup_top.applyTo(new Vector3D(0.0,10.0,0.0));
// translate the flat position final double flat_pos_csup_bearings_top_x = getBallPos().x() + flat_pos_csup_bearings_top_3D_rot.getX();
@@ -481,12 +480,12 @@
// it is referenced locally to the c-support pin coordinate system here // build the rotation to find the proper location of the flat
- org.apache.commons.math3.geometry.euclidean.threed.Rotation rot_csup = - new org.apache.commons.math3.geometry.euclidean.threed.Rotation(org.apache.commons.math3.geometry.euclidean.threed.RotationOrder.XYZ,
+ Rotation rot_csup = + new Rotation(RotationOrder.XYZ,
SupportPlateBottom.support_plate_bottom_tilt_angle, 0.0, 0.0 ); // apply to flat local position
- org.apache.commons.math3.geometry.euclidean.threed.Vector3D flat_pos_csup_bearings_bottom_3D_rot = - rot_csup.applyTo(new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0.0,10.0,0.0));
+ Vector3D flat_pos_csup_bearings_bottom_3D_rot = + rot_csup.applyTo(new Vector3D(0.0,10.0,0.0));
// translate final double flat_pos_csup_bearings_bottom_x = ball_pos_csup_bearings_bottom_x + flat_pos_csup_bearings_bottom_3D_rot.getX(); final double flat_pos_csup_bearings_bottom_y = ball_pos_csup_bearings_bottom_y + flat_pos_csup_bearings_bottom_3D_rot.getY();
@@ -675,9 +674,10 @@
public static class TestRunModuleL45 extends TestRunModule {
- protected static final double module_box_L45_length = 205.2; // includes lexan spacer and cold block - protected static final double module_box_L45_height = 12.5; // includes screws height - protected static final double module_box_L45_width = 65.3-12.0;
+ + protected static final double module_box_L45_length = 205.2 + box_extra_length; // includes lexan spacer and cold block + protected static final double module_box_L45_height = 12.5 + box_extra_height; // includes screws height + protected static final double module_box_L45_width = 65.3-12.0 + box_extra_width;
protected static final double dist_lower_sensor_edge_to_cold_block_mounting_surface = 7.662;
@@ -706,10 +706,9 @@
} public static class TestRunModuleL13 extends TestRunModule {
- // module references - protected static final double module_box_L13_length = 205.2; // includes lexan spacer and cold block - protected static final double module_box_L13_height = 12.5; // includes screws height - protected static final double module_box_L13_width = 71.3 - 13.0; // height from cold block to encapsulate the whole module
+ protected static final double module_box_L13_length = 205.2 + box_extra_length; // includes lexan spacer and cold block + protected static final double module_box_L13_height = 12.5 + box_extra_height; // includes screws height + protected static final double module_box_L13_width = 71.3 - 13.0 + box_extra_width; // height from cold block to encapsulate the whole module
protected static final double dist_lower_sensor_edge_to_cold_block_mounting_surface = 12.66; public TestRunModuleL13(String name, BaseGeometry mother, int layer, String half) {
@@ -720,7 +719,7 @@
} protected double getColdBlockThickness() { return TestRunColdBlockL13.coldblock_L13_thickness;
- }
+ }
protected double getModuleBoxLength() { return module_box_L13_length; }
@@ -737,6 +736,10 @@
public static abstract class TestRunModule extends BaseModule {
+ protected final static double box_extra_length = 10.0;// random at this point + protected final static double box_extra_width = 15.0;// random at this point + protected final static double box_extra_height = 2.0;// random at this point +
public TestRunModule(String name, BaseGeometry mother, int layer, String half) { super(name, mother,layer,half); init();
@@ -761,7 +764,7 @@
if(debug) System.out.printf("%s: rotation:\n%s\n",this.getClass().getSimpleName(), getCoord().getTransformation().getRotation().toString()); } protected void setCenter() {
- setCenter(getModuleBoxLength()/2.0-5.0, 0.0, getModuleBoxWidth()/2.0);
+ setCenter(getModuleBoxLength()/2.0-5.0, 0.0, getModuleBoxWidth()/2.0-box_extra_width/5.0);
} protected void setPos() {
@@ -1027,10 +1030,10 @@
public TestRunHalfModuleStereo(String name, BaseGeometry mother, int layer, String half) { super(name, mother, layer, half);
- if(layer<=3) stereo_angle = 0.1; - else if(layer>=4&&layer<=5) stereo_angle = 0.05;
+ if(layer<=3) stereo_angle = -0.1; + else if(layer>=4&&layer<=5) stereo_angle = -0.05;
else throw new RuntimeException("Layer " + layer + " is not defined.");
- init();
+ init();
//setExplicitRotation(); }
@@ -1064,14 +1067,14 @@
private void calcAndSetPos() { /* // find the rotation to place the flat point
- org.apache.commons.math3.geometry.euclidean.threed.Rotation rot1_csup = - new org.apache.commons.math3.geometry.euclidean.threed.Rotation( - new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(vee_pos_csup_pin_bottom_x-ball_pos_csup_pin_bottom_x,
+ Rotation rot1_csup = + new Rotation( + new Vector3D(vee_pos_csup_pin_bottom_x-ball_pos_csup_pin_bottom_x,
vee_pos_csup_pin_bottom_y-ball_pos_csup_pin_bottom_y, vee_pos_csup_pin_bottom_z-ball_pos_csup_pin_bottom_z),
- new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(1,0,0));
+ new Vector3D(1,0,0));
- org.apache.commons.math3.geometry.euclidean.threed.Vector3D flat_pos_csup_pin_bottom_3D_rot = rot1_csup.applyTo(new org.apache.commons.math3.geometry.euclidean.threed.Vector3D(0,10.0,0));
+ Vector3D flat_pos_csup_pin_bottom_3D_rot = rot1_csup.applyTo(new Vector3D(0,10.0,0));
// translate double flat_pos_csup_pin_bottom_x = ball_pos_csup_pin_bottom_x + flat_pos_csup_pin_bottom_3D_rot.getX(); double flat_pos_csup_pin_bottom_y = ball_pos_csup_pin_bottom_y + flat_pos_csup_pin_bottom_3D_rot.getY();
@@ -1091,8 +1094,8 @@
} else { stereo_angle = -0.05; }
- 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);
+ Rotation rot_stereo = new Rotation(RotationOrder.XYZ, Math.PI, stereo_angle,0); + double res[] = rot_stereo.getAngles(RotationOrder.XYZ);
explicit_rot_angles = new BasicHep3Vector(res); }
@@ -1104,11 +1107,18 @@
// Rotate these into the right place for the stereo // My rotations here are active rotations in the mother coordinate system frame
- // flip around u
+ // Sloppy description of the frame + // u: direction along long edge of half module i.e. along strips + // v: normal to sensor plane + // w: perpendicular to the sensor + + // flip around u
Rotation r1 = new Rotation(new Vector3D(1,0,0),Math.PI);
- //Rotation r2 = new Rotation(new Vector3D(0,1,0),stereo_angle); - //Rotation r = r2.applyTo(r1); - Rotation r = r1;
+ // apply stereo angle around v + Rotation r2 = new Rotation(new Vector3D(0,1,0),stereo_angle); + // Build full rotation + Rotation r = r2.applyTo(r1); + //Rotation r = r1;
System.out.printf("%s: Coord before corrections\n%s\n", getClass().getSimpleName(),getCoord().toString()); System.out.printf("%s: box center before corrections\n%s\n", getClass().getSimpleName(),getBoxDim().toString()); getCoord().rotateApache(r);
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTrackerJavaBuilder.java 2014-09-27 20:47:23 UTC (rev 3350) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTrackerJavaBuilder.java 2014-09-28 21:36:25 UTC (rev 3351) @@ -29,6 +29,7 @@
import org.lcsim.detector.tracker.silicon.SiTrackerModule; import org.lcsim.geometry.compact.Subdetector; import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.BaseGeometry;
+import org.lcsim.geometry.util.TransformationUtils;
public abstract class HPSTrackerJavaBuilder implements IHPSTrackerJavaBuilder {
@@ -246,7 +247,7 @@
setName(geomObject.getName()); setVolume(vol); // since it's tracking volume, set the pos and rotation trivially
- Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(geomObject.getCoord().v(), geomObject.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
+ Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(geomObject.getCoord().v(), geomObject.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
setPos(new Translation3D(0,0,0)); setRot(new RotationGeant(lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z())); if(isDebug()) System.out.printf("%s: DONE JavaBaseGeometry %s\n", this.getClass().getSimpleName(),geomObject.getName());
@@ -363,27 +364,9 @@
//Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(unit_u,unit_v,base.getCoord().u(), base.getCoord().v()); //Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().u(), base.getCoord().v(), unit_u,unit_v);
- Hep3Vector lcdd_rot_angles_uv = HPSTestRunTracker2014.getEulerAngles(base_u, base_v, unit_u,unit_v); - Hep3Vector lcdd_rot_angles_uw = HPSTestRunTracker2014.getEulerAngles(base_u, base_w, unit_u,unit_w); - Hep3Vector lcdd_rot_angles_vw = HPSTestRunTracker2014.getEulerAngles(base_v, base_w, unit_v,unit_w); - Hep3Vector lcdd_rot_angles = lcdd_rot_angles_uw; - //Hep3Vector lcdd_rot_angles_active = HPSTestRunTracker2014.getActiveEulerAngles(base.getCoord().v(), base.getCoord().w(), unit_v,unit_w); -// double rot_mat[][] = HPSTestRunTracker2014.getActiveEulerAnglesMatrix(base.getCoord().v(), base.getCoord().w(), unit_v,unit_w); -// Rotation3D rot_xcheck = new Rotation3D(); -// BasicHep3Matrix rot_mat_hep = new BasicHep3Matrix(); -// for(int c=0;c<=2;++c) { -// for(int r=0;r<=2;++r) { -// rot_mat_hep.setElement(r, c, rot_xcheck.getComponent(r, c)); -// } -// } -// rot_xcheck.setRotationMatrix(rot_mat_hep); -// if(isDebug()) { -// System.out.printf("%s: xcheck active rotation matrix:\n", this.getClass().getSimpleName()); -// HPSTestRunTracker2014.printMatrix(rot_mat); -// rot_xcheck.toString(); -// } -// - /*
+ Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w); + + /*
// Check if there are explicit rotations built into the object itself which overrides // TODO this should be included in the definition of the coordinate system. Fix this for the affected components.
@@ -417,7 +400,6 @@
// Create the LCDD position setPos(new Translation3D(box_center.x(), box_center.y(), box_center.z())); setRot(new RotationGeant(lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z()));
- //setRot(new Rotation3D(lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z()));
if(isDebug()) {
@@ -427,10 +409,6 @@
System.out.printf("%s: box_center %s\n", this.getClass().getSimpleName(), box_center.toString()); System.out.printf("%s: pos %s\n", this.getClass().getSimpleName(), getPos().toString()); System.out.printf("%s: euler %s\n", this.getClass().getSimpleName(), lcdd_rot_angles.toString());
- System.out.printf("%s: euler (uv) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_uv.toString()); - System.out.printf("%s: euler (uw) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_uw.toString()); - System.out.printf("%s: euler (vw) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_vw.toString()); - //System.out.printf("%s: euler (active) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_active.toString());
System.out.printf("%s: rot %s\n", this.getClass().getSimpleName(), getRot().toString()); //calculate the position in tracking volume separately as a xcheck
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTrackerLCDDBuilder.java 2014-09-27 20:47:23 UTC (rev 3350) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTrackerLCDDBuilder.java 2014-09-28 21:36:25 UTC (rev 3351) @@ -19,6 +19,7 @@
import org.lcsim.geometry.compact.converter.lcdd.util.Rotation; import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector; import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
+import org.lcsim.geometry.util.TransformationUtils;
public abstract class HPSTrackerLCDDBuilder implements IHPSTrackerLCDDBuilder {
@@ -93,7 +94,7 @@
setName(base.getName()); setVolume(volume); if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName());
- Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
+ Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
setPos(new Position(getName() + "_position", 0, 0, 0)); setRot(new Rotation(getName() + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z())); if(isDebug()) System.out.printf("%s: DONE JavaBaseGeometry %s\n", this.getClass().getSimpleName(),base.getName());
@@ -208,12 +209,7 @@
unit_u.toString(),unit_v.toString(),unit_w.toString()); //System.out.printf("%s: unit vectors u %s v %s w %s\n", this.getClass().getSimpleName(),base.getCoord().u().toString(),base.getCoord().v().toString(),base.getCoord().w().toString()); }
- //Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(unit_u,unit_v,base.getCoord().u(), base.getCoord().v()); - //Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().u(), base.getCoord().v(), unit_u,unit_v); - Hep3Vector lcdd_rot_angles_uv = HPSTestRunTracker2014.getEulerAngles(base_u, base_v, unit_u,unit_v); - Hep3Vector lcdd_rot_angles_uw = HPSTestRunTracker2014.getEulerAngles(base_u, base_w, unit_u,unit_w); - Hep3Vector lcdd_rot_angles_vw = HPSTestRunTracker2014.getEulerAngles(base_v, base_w, unit_v,unit_w); - Hep3Vector lcdd_rot_angles = lcdd_rot_angles_uw;
+ Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w);
// Check if there are explicit rotations built into the object itself which overrides // TODO this should be included in the definition of the coordinate system. Fix this for the affected components.
@@ -245,9 +241,6 @@
System.out.printf("%s: box_center %s\n", this.getClass().getSimpleName(), box_center.toString()); System.out.printf("%s: pos %s\n", this.getClass().getSimpleName(), getPos().toString()); System.out.printf("%s: euler %s\n", this.getClass().getSimpleName(), lcdd_rot_angles.toString());
- System.out.printf("%s: euler (uv) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_uv.toString()); - System.out.printf("%s: euler (uw) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_uw.toString()); - System.out.printf("%s: euler (vw) %s\n", this.getClass().getSimpleName(), lcdd_rot_angles_vw.toString());
System.out.printf("%s: rot %s\n", this.getClass().getSimpleName(), getRot().toString()); //calculate the position in tracking volume separately as a xcheck
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/util/TransformationUtils.java (rev 0) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/util/TransformationUtils.java 2014-09-28 21:36:25 UTC (rev 3351) @@ -0,0 +1,177 @@
+package org.lcsim.geometry.util; + +import org.apache.commons.math3.geometry.euclidean.threed.Rotation; +import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import org.lcsim.detector.RotationGeant; + +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +public class TransformationUtils { + + /** + * Extract the Cardan angles that describe a passive XYZ order rotation taking two unit vectors into two new ones. + * @param u - input unit vector + * @param v - input unit vector + * @param u_prime - result of rotation applied to @param u + * @param v_prime - result of rotation applied to @param v + * @return + */ + public static Hep3Vector getCardanAngles(Hep3Vector u, Hep3Vector v, Hep3Vector u_prime, Hep3Vector v_prime) { + int debug = 0; + if (debug>0) System.out.printf("getEulerAngles: u %s v%s -> %s %s\n",u.toString(),v.toString(),u_prime.toString(),v_prime.toString()); + // Convert to correct API + Vector3D u_3D = new Vector3D(u.v()); + Vector3D v_3D = new Vector3D(v.v()); + Vector3D u_prime_3D = new Vector3D(u_prime.v()); + Vector3D v_prime_3D = new Vector3D(v_prime.v()); + + //Create the rotation + // Note that the constructor used here creates the rotation using active transformations + Rotation rot = new Rotation(u_3D,v_3D,u_prime_3D,v_prime_3D); + + // Get the Cardan angles of the rotation + double res[] = rot.getAngles(RotationOrder.ZYX); + + // Since the rotation was created based on active transformations convert to passive right here. + // This conversion is simply to reverse the order of rotations. + Hep3Vector euler = new BasicHep3Vector(res[2],res[1],res[0]); + + if(debug>0) { + System.out.println("Input: u " + u_3D.toString() + " v " + v_3D.toString() + " u' " + u_prime_3D.toString() + " v' " + v_prime_3D.toString()); + System.out.println("rot matrix:"); + TransformationUtils.printMatrix(rot.getMatrix()); + System.out.println("Resulting XYZ angles " + euler.toString()); + } + + if(debug>1) { + System.out.println("------- TESTING "); + + Rotation r123 = new Rotation(RotationOrder.XYZ, res[0], res[1], res[2]); + + + Vector3D x_3D = new Vector3D(1,0,0); + Vector3D y_3D = new Vector3D(0,1,0); + Vector3D z_3D = new Vector3D(0,0,1); + + + Rotation r1 = new Rotation(x_3D,res[0]); + Vector3D x_3D_p = r1.applyTo(x_3D); + Rotation r3 = new Rotation(z_3D,res[2]); + Rotation r13 = r3.applyTo(r1); + Vector3D x_3D_pp = r13.applyTo(x_3D); + Vector3D y_3D_pp = r13.applyTo(y_3D); + Vector3D y_3D_pp_2 = r123.applyTo(y_3D); + System.out.println("x_3D (" + x_3D.getX() + "," + x_3D.getY() + "," + x_3D.getZ()); + System.out.println("y_3D (" + y_3D.getX() + "," + y_3D.getY() + "," + y_3D.getZ()); + System.out.println("z_3D (" + z_3D.getX() + "," + z_3D.getY() + "," + z_3D.getZ()); + System.out.println("r1 " + r1.toString()); + TransformationUtils.printMatrix(r1.getMatrix()); + System.out.println("x_3D_p (" + x_3D_p.getX() + "," + x_3D_p.getY() + "," + x_3D_p.getZ()); + System.out.println("r3 " + r3.toString()); + TransformationUtils.printMatrix(r3.getMatrix()); + System.out.println("r13 " + r13.toString()); + TransformationUtils.printMatrix(r13.getMatrix()); + System.out.println("x_3D_pp (" + x_3D_pp.getX() + "," + x_3D_pp.getY() + "," + x_3D_pp.getZ()); + System.out.println("y_3D_pp (" + y_3D_pp.getX() + "," + y_3D_pp.getY() + "," + y_3D_pp.getZ()); + System.out.println("r123 " + r123.toString()); + TransformationUtils.printMatrix(r123.getMatrix()); + System.out.println("y_3D_pp_2 (" + y_3D_pp_2.getX() + "," + y_3D_pp_2.getY() + "," + y_3D_pp_2.getZ()); + System.out.println("------- "); + } + return euler; + } + + public static boolean areVectorsEqual(Hep3Vector a, Hep3Vector b, double thresh) { + return VecOp.cross(a, b).magnitude() > thresh ? false : true; + } + + /** + * Extract the Cardan angles that describe a passive XYZ order rotation taking a set of three unit vectors into three new one. + * @param u - input unit vector + * @param v - input unit vector + * @param w - input unit vector + * @param u_prime - result of rotation applied to @param u + * @param v_prime - result of rotation applied to @param v + * @param w_prime - result of rotation applied to @param w + * @return + */ + public static Hep3Vector getCardanAngles(Hep3Vector u, Hep3Vector v, Hep3Vector w, + Hep3Vector u_prime, Hep3Vector v_prime, Hep3Vector w_prime) { + + Hep3Vector a1 = getCardanAngles(u, v, u_prime, v_prime); + Hep3Vector a2 = getCardanAngles(u, w, u_prime, w_prime); + Hep3Vector a3 = getCardanAngles(v, w, v_prime, w_prime); + if( !areVectorsEqual(a1, a2, 0.00001) || !areVectorsEqual(a1, a3, 0.00001) || !areVectorsEqual(a2, a3, 0.00001)) { + System.out.printf("u: %s -> %s \n", u.toString(), u_prime.toString()); + System.out.printf("v: %s -> %s \n", v.toString(), v_prime.toString()); + System.out.printf("w: %s -> %s \n", w.toString(), w_prime.toString()); + System.out.printf("a1: %s \n", a1.toString()); + System.out.printf("a2: %s \n", a1.toString()); + System.out.printf("a3: %s \n", a1.toString()); + System.out.printf("a1 a2: %f \n", Math.abs(VecOp.dot(a1, a2)-1)); + System.out.printf("a1 a3: %f \n", Math.abs(VecOp.dot(a1, a3)-1)); + System.out.printf("a2 a3: %f \n", Math.abs(VecOp.dot(a2, a3)-1)); + + throw new RuntimeException("Cardan angles extracted for transformation depend on input unit vectors:"); + } + return a1; + } + + + /** + * Print matrix to stdout. + * @param mat + */ + public static void printMatrix(double [][] mat) { + for(int r=0;r<3;++r) { + String row = ""; + for(int c=0;c<3;++c) { + row += String.format(" %f",mat[r][c]); + } + System.out.println(row); + } + } + + + + + /** + * Find the displacement of a point when rotating around an arbitrary position. + * @param originOfRotation + * @param point to rotate + * @param rotationAngles - Cardan angles describing a passive XYZ order rotation + * @return point after rotation + */ + public static Hep3Vector getRotationDisplacement(Hep3Vector originOfRotation, + Hep3Vector point, Hep3Vector rotationAngles) { + boolean _debug = false; + + // Find the vector from the center of rotation to the point + Hep3Vector s = VecOp.sub(point, originOfRotation ); + // Build a rotataion object + RotationGeant r = new RotationGeant(rotationAngles.x(), rotationAngles.y(), rotationAngles.z()); + // Apply the rotation to the vector + Hep3Vector s_prime = r.rotated(s); + // Find the displaced point + Hep3Vector point_rot = VecOp.add(originOfRotation, s_prime ); + + if(_debug) { + System.out.println("--- getRotationDisplacement---"); + System.out.println(String.format("point: %s", point.toString())); + System.out.println(String.format("origin_of_rotation: %s", originOfRotation.toString())); + System.out.println(String.format("s:\n%s", s.toString())); + System.out.println(String.format("r:\n%s", r.toString())); + System.out.println(String.format("s_prime:\n%s", s_prime.toString())); + System.out.println(String.format("point_rot:\n%s", point_rot.toString())); + System.out.println("--- getRotationDisplacement END---"); + } + + return point_rot; + } + + + +}
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