Commit in projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim on MAIN | |||
detector/converter/compact/HPSTestRunTracker2014Converter.java | +28 | -9 | 3318 -> 3319 |
/HPSTestRunTracker2014JavaBuilder.java | +59 | -5 | 3318 -> 3319 |
geometry/compact/converter/lcdd/HPSTestRunTracker2014Builder.java | +15 | -361 | 3318 -> 3319 |
/HPSTestRunTracker2014LCDDBuilder.java | +34 | -345 | 3318 -> 3319 |
+136 | -720 |
Use reorg with superclasses
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java 2014-09-12 19:04:24 UTC (rev 3318) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java 2014-09-12 19:06:18 UTC (rev 3319) @@ -5,13 +5,16 @@
import org.jdom.Element; import org.lcsim.detector.DetectorElement;
+import org.lcsim.detector.DetectorElementStore;
import org.lcsim.detector.DetectorIdentifierHelper; import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.IGeometryInfo;
import org.lcsim.detector.ILogicalVolume; import org.lcsim.detector.IPhysicalVolume; import org.lcsim.detector.DetectorIdentifierHelper.SystemMap; import org.lcsim.detector.PhysicalVolume; import org.lcsim.detector.PhysicalVolumeStore;
+import org.lcsim.detector.Transform3D;
import org.lcsim.detector.converter.compact.HPSTestRunTracker2014JavaBuilder.GhostJavaBaseGeom; import org.lcsim.detector.converter.compact.HPSTestRunTracker2014JavaBuilder.JavaBaseGeometry; import org.lcsim.detector.identifier.ExpandedIdentifier;
@@ -36,7 +39,7 @@
*/ public class HPSTestRunTracker2014Converter extends AbstractSubdetectorConverter {
- private boolean _debug = false;
+ private boolean _debug = true;
private IMaterial trackingMaterial = null; private static HPSTestRunTracker2014JavaBuilder builder;
@@ -93,7 +96,26 @@
setupDetectorElements();
+ if(_debug) { + System.out.printf("%s: Print all %d detector elements in store\n", getClass().getSimpleName(),DetectorElementStore.getInstance().size()); + for(IDetectorElement e : DetectorElementStore.getInstance()) { + System.out.printf("%s: Name: %s \n", getClass().getSimpleName(),e.getName()); + if(e.hasGeometryInfo()) { + System.out.printf("%s: Position: %s \n", getClass().getSimpleName(),e.getGeometry().getPosition()); + System.out.printf("%s: LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getLocalToGlobal()).toString()); + //System.out.printf("%s: GlobalToLocal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getGlobalToLocal()).toString()); + IGeometryInfo info = e.getGeometry(); + if(info!=null) { + while((info=info.parentGeometry())!=null) { + System.out.printf("%s: Parent geometry DE: %s \n", getClass().getSimpleName(),info.getDetectorElement().getName()); + System.out.printf("%s: Parent Position: %s \n", getClass().getSimpleName(),info.getPosition()); + System.out.printf("%s: Parent LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)info.getLocalToGlobal()).toString());
+ } + } + } + } + }
}
@@ -191,21 +213,18 @@
if(_debug) { System.out.printf("%s: create SiTrackerModule with: placementname %s, modulePath %s, moduleNumber %d \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
- System.out.printf("%s: print all %d physical volumes from the Store\n", getClass().getSimpleName(),PhysicalVolumeStore.getInstance().size()); - for(IPhysicalVolume v : PhysicalVolumeStore.getInstance()) { - System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(), v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume()!=null?v.getMotherLogicalVolume().getName():"(no mother)"); - }
+ //System.out.printf("%s: print all %d physical volumes from the Store\n", getClass().getSimpleName(),PhysicalVolumeStore.getInstance().size()); + //for(IPhysicalVolume v : PhysicalVolumeStore.getInstance()) { + // System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(), v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume()!=null?v.getMotherLogicalVolume().getName():"(no mother)"); + //}
} SiTrackerModule moduleDe = new SiTrackerModule(modulePlacementName, layerDe, modulePath, moduleNumber);
- //keep track of the module detector element - //builder.addModuleDetectorElement(moduleDe); - -
if(_debug) System.out.printf("%s: add module DE to existing ones \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
+ //keep track of the module detector element
builder.addModuleDetectorElement(moduleDe);
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014JavaBuilder.java 2014-09-12 19:04:24 UTC (rev 3318) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014JavaBuilder.java 2014-09-12 19:06:18 UTC (rev 3319) @@ -3,6 +3,7 @@
*/ package org.lcsim.detector.converter.compact;
+import hep.physics.vec.BasicHep3Matrix;
import hep.physics.vec.BasicHep3Vector; import hep.physics.vec.Hep3Vector; import hep.physics.vec.VecOp;
@@ -18,6 +19,7 @@
import org.lcsim.detector.ITranslation3D; import org.lcsim.detector.LogicalVolume; import org.lcsim.detector.PhysicalVolume;
+import org.lcsim.detector.Rotation3D;
import org.lcsim.detector.RotationGeant; import org.lcsim.detector.Transform3D; import org.lcsim.detector.Translation3D;
@@ -114,8 +116,10 @@
for(ModuleBundle m : modules) { // Do only L1?
- //if(m.getLayer()!=1) continue;
+ if(onlyL1 && m.getLayer()!=1) continue;
+ if(onlyBottom && m.getHalf()!="bottom") continue; +
if(isDebug()) { System.out.printf("%s: build module %s (layer %d half %s)\n", getClass().getSimpleName(),m.module.getName(),m.getLayer(),m.getHalf()); m.print();
@@ -180,8 +184,10 @@
// add half modules addHalfModule(bundle.halfModuleAxial,lcddM);
- addHalfModule(bundle.halfModuleStereo,lcddM);
+ if(!onlyAxial) { + addHalfModule(bundle.halfModuleStereo,lcddM); + }
if(isDebug()) { System.out.printf("%s: DONE addModule %s \n",this.getClass().getSimpleName(), bundle.module.getName());
@@ -216,6 +222,13 @@
JavaBaseGeometry lcddAS = new JavaBaseGeometry(bundle.activeSensor, lcddS, componentNumber); add(lcddAS);
+// if(isDebug()) { +// System.out.printf("%s: added sensor %s \n",this.getClass().getSimpleName(), lcddS.getName()); +// System.out.printf("%s: local coordinate system\n%s\n",this.getClass().getSimpleName(), bundle.sensor.getCoord().toString()); +// dsd +// } + +
} protected DetectorIdentifierHelper getDetectorIdentifierHelper() {
@@ -279,7 +292,7 @@
* @author Per Hansson Adrian <[log in to unmask]> */ protected static class JavaBaseGeometry {
- private boolean debug = false;
+ private boolean debug = true;
private String name; private Box box= null; private ILogicalVolume volume = null;
@@ -390,8 +403,46 @@
Hep3Vector box_center = VecOp.sub(box_center_base, mother_center); //Find LCDD Euler rotation angles from coordinate system unit vectors
- Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
+ //Note that this has to be rotation wrt to physical mother and not just mother as normally is the case + //Use apache lib to get angles, but in principle I should already have it from the trf above + //Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1)); + if(isDebug()) System.out.printf("%s: find LCDD Cardan rotation angles - need to find mother to physical mother transform \n", this.getClass().getSimpleName(),physMother.getName()); + Hep3Vector unit_u = new BasicHep3Vector(1,0,0); + Hep3Vector unit_v = new BasicHep3Vector(0,1,0); + Hep3Vector unit_w = new BasicHep3Vector(0,0,1); + if(!base.getMother().getName().equals(physMother.getName())) { + Transform3D trf_mother = getTransform(base.getMother().getCoord().getTransformation(),base.getMother().getMother(),physMother.getName()); + unit_u = VecOp.unit(trf_mother.rotated(unit_u)); + unit_v = VecOp.unit(trf_mother.rotated(unit_v)); + unit_w = VecOp.unit(trf_mother.rotated(unit_w)); + if(isDebug()) System.out.printf("%s: found transform from mother to physical mother \n%s\n", this.getClass().getSimpleName(),trf_mother.toString()); + } else { + if(isDebug()) System.out.printf("%s: mother and physical mother is the same\n",getClass().getSimpleName()); + }
+ + if(isDebug()) System.out.printf("%s: unit vectors to get Cardan angles from become unit_u %s unit_v %s unit_w %s\n", this.getClass().getSimpleName(),unit_u.toString(),unit_v.toString(),unit_w.toString()); + if(isDebug()) 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_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(); + } + + /* +
// 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. if (base.explicit_rot_angles!=null) {
@@ -418,10 +469,12 @@
// update the position of the center in the mother coord box_center = VecOp.sub(box_center_base_rot, mother_center); }
+ */
// 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()) {
@@ -431,11 +484,12 @@
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 (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 Hep3Vector box_center_tracking_xcheck = transformToTracking(box_center_base_local, base);
- System.out.printf("%s: box_center_tracking_xcheck %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString());
+ System.out.printf("%s: box_center_tracking_xcheck %s for %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString(),base.getName());
} }
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014Builder.java 2014-09-12 19:04:24 UTC (rev 3318) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014Builder.java 2014-09-12 19:06:18 UTC (rev 3319) @@ -3,15 +3,9 @@
*/ package org.lcsim.geometry.compact.converter.lcdd;
-import hep.physics.vec.Hep3Vector; -
import java.util.ArrayList;
-import java.util.List;
-import org.lcsim.detector.Transform3D;
import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.BaseGeometry;
-import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.TestRunColdBlock; -import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.TestRunModule;
/** *
@@ -20,17 +14,14 @@
* @author Per Hansson Adrian <[log in to unmask]> * */
-public class HPSTestRunTracker2014Builder {
+public class HPSTestRunTracker2014Builder extends HPSTrackerBuilder {
- // general members - private boolean debug = false;
+ protected static boolean onlyAxial = true; + protected static boolean onlyBottom = true; + protected static boolean onlyL1 = true;
- //Geometry members - protected List<HPSTestRunTracker2014GeometryDefinition.BaseGeometry> geometries = new ArrayList<HPSTestRunTracker2014GeometryDefinition.BaseGeometry>(); - public List<ModuleBundle> modules;
-
/** * Default constructor. */
@@ -65,13 +56,15 @@
modules = new ArrayList<ModuleBundle>(); for(int l=1; l<=5;++l) {
- makeModuleBundle(l,"bottom"); - makeModuleBundle(l,"top"); - }
+ if(onlyL1 && l!=1) continue; + makeModuleBundle(l,"bottom"); + if(!onlyBottom) + makeModuleBundle(l,"top"); + + }
-
//if(isDebug()) {
- System.out.printf("%s: DONE constructing the geometry objects\n", this.getClass().getSimpleName());
+ System.out.printf("%s: DONE constructing the geometry objects kuk\n", this.getClass().getSimpleName());
System.out.printf("%s: List of all the geometry objects built\n", this.getClass().getSimpleName()); for(BaseGeometry bg : geometries) { System.out.printf("-------\n%s\n", bg.toString());
@@ -128,11 +121,12 @@
makeHalfModule("axial", module);
- makeColdBlock(module);
+ if(!onlyAxial) { + makeColdBlock(module);
- makeHalfModule("stereo", module);
+ makeHalfModule("stereo", module);
+ }
-
if(isDebug()) { System.out.printf("%s: created module bundle:\n", this.getClass().getSimpleName()); bundle.print();
@@ -334,350 +328,10 @@
hm.activeSensor = active_sensor; }
- - - /** - * Get the layer number consistent with the old geometry definition. - * @param module name that contains layer and half information. - * @return the layer. - */ - public static int getOldGeomDefLayerFromVolumeName(String name) { - String half = getHalfFromName(name); - boolean isTopLayer = false; - if(half=="top") isTopLayer=true; - else if(half=="bottom") isTopLayer = false; - else throw new RuntimeException("no half found from " + name); - boolean isAxial = false; - if(name.contains("axial")) isAxial=true; - else if(name.contains("stereo")) isAxial=false; - else throw new RuntimeException("no axial or stereo name found from " + name); - int l = getLayerFromVolumeName(name); - int layer=-1; - // convert to old definition - if(isAxial) { - if(isTopLayer) { - layer = 2*l-1; - } - else { - layer = 2*l; - } - } else { - if(isTopLayer) { - layer = 2*l; - } else { - layer = 2*l-1; - } - } - return layer; - } - - - - public static String getHalfFromName(String name) { - String half = ""; - if(name.contains("bottom")) { - half = "bottom"; - } - if(name.contains("top")) { - // check that both sides are not found - if(half.equals("bottom")) { - throw new RuntimeException("found both halfs from name " + name); - } else { - half = "top"; - } - } - // check for other signatures - if( half.isEmpty()) { - // 6 layers is arbitrary here - for(int layer=1;layer<=6;++layer) { - if(name.contains(String.format("L%db", layer))) { - half = "bottom"; - break; - } - if(name.contains(String.format("L%dt", layer))) { - if(half.equals("bottom")) { - throw new RuntimeException("found both halfs from name " + name); - } - half = "top"; - break; - } - } - } - if( half.isEmpty()) { - System.out.println("found no half from " + name); - throw new RuntimeException("found no half from " + name); - } else { - return half; - - } - } - - - public static int getLayerFromVolumeName(String name) { - int layer = -1; - for(int i=1; i<= 5; ++i) { - if(name.contains(String.format("module_L%d", i))) { - layer = i; - } - } - if( layer == -1) { - System.out.println("cannot find layer from " + name); - System.exit(1); - } - return layer; - } - - public static boolean isHalfModule(String name) { - if(name.endsWith("halfmodule_axial") || name.endsWith("halfmodule_stereo")) { - return true; - } - return false; - } - - public static boolean isSensor(String name) { - if(name.endsWith("sensor")) { - return true; - } - return false; - } - - public static boolean isActiveSensor(String name) { - if(name.endsWith("sensor_active")) { - return true; - } - return false; - }
- /** - * Find geometry object by type. - * @param c - class type to be found - * @return the found type. - */ - protected <T> T getBaseGeometry(Class<T> c) { - ///if(isDebug()) System.out.printf("%s: get Item %s\n", this.getClass().getSimpleName(),c.getName()); - - for(HPSTestRunTracker2014GeometryDefinition.BaseGeometry item : geometries) { - //if(isDebug()) System.out.printf("%s: item %s\n", getClass().getSimpleName(),item.getClass().getName()); - if(c.isInstance(item)) { - return (T)item; - } - } - throw new RuntimeException("Coulnd't find instance of " + c.getSimpleName() + " among the " + geometries.size() + " tracker items!"); - } - - protected List<ModuleBundle> getModules() { - return modules; - } - protected boolean isDebug() { - return debug; - } - protected void setDebug(boolean debug) { - this.debug = debug; - } -
- /** - * Bundle geometry objects in a module. - * This was done in order to package module geometry objects into a simpler form. - * If the geometry definition has access to daughter information I could avoid this? TODO check this? - * - * @author Per Hansson Adrian <[log in to unmask]> - * - */ - public static class ModuleBundle { - public TestRunModule module = null; - public HalfModuleBundle halfModuleAxial = null; - public HalfModuleBundle halfModuleStereo = null; - protected TestRunColdBlock coldBlock = null; - ModuleBundle(TestRunModule m) { - module = m; - } - public int getLayer() { - if(module==null) throw new RuntimeException("Need to add module to bundle first!"); - return getLayerFromVolumeName(module.getName()); - } - public String getHalf() { - if(module==null) throw new RuntimeException("Need to add module to bundle first!"); - return getHalfFromName(module.getName()); - } - /** - * Find mother to this module. - * @return mother - */ - public BaseGeometry getMother() { - if(module==null) throw new RuntimeException("Need to add module to bundle first!"); - return module.getMother(); - } - public void print() { - if(module!=null) System.out.printf("%s: %s\n", this.getClass().getSimpleName(),module.getName()); - if(halfModuleAxial!=null) halfModuleAxial.print(); - if(coldBlock!=null)System.out.printf("%s: %s\n", this.getClass().getSimpleName(),coldBlock.getName()); - if(halfModuleStereo!=null) halfModuleStereo.print(); - } - } - public static class HalfModuleBundle { - public HPSTestRunTracker2014GeometryDefinition.TestRunHalfModule halfModule = null; - public HPSTestRunTracker2014GeometryDefinition.Sensor sensor = null; - public HPSTestRunTracker2014GeometryDefinition.ActiveSensor activeSensor = null; - protected HPSTestRunTracker2014GeometryDefinition.HalfModuleLamination lamination = null; - protected HPSTestRunTracker2014GeometryDefinition.CarbonFiber carbonFiber = null; - protected HPSTestRunTracker2014GeometryDefinition.Hybrid hybrid = null; - HalfModuleBundle(HPSTestRunTracker2014GeometryDefinition.TestRunHalfModule hm) { - halfModule = hm; - } - public void print() { - System.out.printf("%s: %s\n", this.getClass().getSimpleName(),halfModule.getName()); - } - } - - /** - * Find module among the existing bundles. - * @param layer - layer id - * @param half - top or bottom half - * @return module or null if not found - */ - protected ModuleBundle getModuleBundle(int layer, String half) { - for(ModuleBundle m : modules) { - if(m.getLayer()==layer && m.getHalf().equals(half)) { - return m; - } - } - return null; - } - - - /** - * Find module among the existing bundles. - * @param module - to find - * @return bundle - */ - protected ModuleBundle getModuleBundle(HPSTestRunTracker2014GeometryDefinition.TestRunModule module) { - return getModuleBundle(module.getLayer(), module.getHalf()); - } - - /** - * Find half module among the existing bundles. - * @param module - to find - * @return bundle - */ - protected HalfModuleBundle getHalfModuleBundle(HPSTestRunTracker2014GeometryDefinition.TestRunModule module, String halfModuleName) { - ModuleBundle m = getModuleBundle(module.getLayer(), module.getHalf()); - HalfModuleBundle hm = null; - if(m!=null) { - if(halfModuleName.contains("axial")) hm = m.halfModuleAxial; - else if(halfModuleName.contains("stereo")) hm = m.halfModuleStereo; - else throw new RuntimeException("NO axial or stereo string found in half module bundle name " + halfModuleName); - } else { - throw new RuntimeException("No module found for " + module.getLayer() + " and half " + module.getHalf()); - } - return hm; - } - - /** - * Add module to list. - * @param bundle - module to add. - */ - private void addModuleBundle(ModuleBundle bundle) { - ModuleBundle b = getModuleBundle(bundle.getLayer(), bundle.getHalf()); - if(b==null) { - modules.add(bundle); - } else { - throw new RuntimeException("There is already a module bundle with layer " + bundle.getLayer() + " and half " + bundle.getHalf()); - } - } - - - /** - * Checks if the orientation of the sensor is axial. - * Uses the moduleId definition from the "old" geometry for - * consistency. - * - * @return true if it is, false if it is a stereo sensor - */ - private boolean isAxial(boolean isTopLayer, int layer) { - if (isTopLayer && layer % 2 == 1) { - return true; - } else if (!isTopLayer && layer % 2 == 0) { - return true; - } - return false; - }
- - /** - * Find transform to parent volume coordinate system. - * @param t - current transform to mother - * @param mother - geometry object from current transform - * @param targetMotherName - parent volume defining new vector coordinate system - * @return transform. - */ - public static Transform3D getTransform(Transform3D t, BaseGeometry mother, String targetMotherName) { - int debug=0; - if(debug>0) System.out.printf("getTransform mother %s target %s with current transform\n%s\n", mother.getName(), targetMotherName,t.toString()); - if(mother==null) throw new RuntimeException("Trying to get mother transform but there is no mother?!"); - if(mother.getName().equals(targetMotherName)) { - if(debug>0) System.out.printf("found the transform\n"); - return t; - } else { - if(debug>0) System.out.printf("add mother transform\n%s\n",mother.getCoord().getTransformation().toString()); - Transform3D trans = Transform3D.multiply(mother.getCoord().getTransformation(), t); - if(debug>0) System.out.printf("resulting transform\n%s\ncontinue searching\n",trans.toString()); - return getTransform(trans, mother.getMother(), targetMotherName); - } - - } - - - /** - * Find the vector in a parent volume coordinate system. - * @param vec - vector to transform - * @param geometry - geometry where vector is defined. - * @param targetMotherName - parent volume defining new vector coordinate system - * @return transformed vector. - */ - public static Hep3Vector transformToMotherCoord(Hep3Vector vec, BaseGeometry geometry, String targetMotherName) { - int debug =0; - BaseGeometry mother = geometry.getMother(); - if(debug>0) System.out.printf("transformToMotherCoord vec %s geomtry %s mother %s target %s\n", vec.toString(), geometry.getName(), geometry.getMother().getName(), targetMotherName); - - Transform3D t = getTransform(geometry.getCoord().getTransformation(), mother, targetMotherName); - - Hep3Vector vec_t = t.transformed(vec); - - if(debug>0) { - System.out.printf("transformToMotherCoord apply transform \n%s\n",t.toString()); - System.out.printf("transformToMotherCoord vec_t%s\n",vec_t.toString()); - } - - - return vec_t; - } - - - /** - * Find the vector in the tracking volume coordinate system. - * @param vec - vector to transform - * @param geometry - geometry where vector is defined. - * @return transformed vector. - */ - public static Hep3Vector transformToTracking(Hep3Vector vec, BaseGeometry geometry) { - int debug =0; - if(debug>0) System.out.printf("\ntransformToTracking: vec %s in local coordiantes of %s with mother %s\n", vec.toString(), geometry.getName(), geometry.getMother().getName().toString()); - Hep3Vector vec_mother_coord = geometry.getCoord().getTransformation().transformed(vec); - if(debug>0) System.out.printf("vec_mother_coord %s\n",vec_mother_coord.toString()); - if(geometry.getMother().getName().equals("trackingVolume")) { - if(debug>0) System.out.printf("reached tracking volume. Return \n"); - return vec_mother_coord; - } else { - if(debug>0) System.out.printf("continue searching.\n"); - } - return transformToTracking(vec_mother_coord, geometry.getMother()); - } - - - -
/* public static Hep3Vector transformToMotherCoord(Hep3Vector vec, BaseGeometry mother, String targetMotherName) { int debug =1;
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014LCDDBuilder.java 2014-09-12 19:04:24 UTC (rev 3318) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014LCDDBuilder.java 2014-09-12 19:06:18 UTC (rev 3319) @@ -1,16 +1,8 @@
package org.lcsim.geometry.compact.converter.lcdd; import java.util.ArrayList;
-import java.util.List; -import java.util.Map;
-import hep.physics.vec.BasicHep3Vector; -import hep.physics.vec.Hep3Vector; -import hep.physics.vec.VecOp; - -import org.jdom.JDOMException;
import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.Base;
-import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.BaseGeometry;
import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.BasePlate; import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.CSupport; import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.SupportBottom;
@@ -18,54 +10,26 @@
import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.SupportPlateTop; import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.SupportTop; import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014GeometryDefinition.TrackingBase;
-import org.lcsim.geometry.compact.converter.lcdd.util.Box; -import org.lcsim.geometry.compact.converter.lcdd.util.LCDD; -import org.lcsim.geometry.compact.converter.lcdd.util.Material; -import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol; -import org.lcsim.geometry.compact.converter.lcdd.util.Position; -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;
+
/** * Class used by LCDD converter to build detector for SLIC.
- * It encapsulates and adds the LCDD specific information to the generic @HPSTestRunTracker2014Builder.
* * @author Per Hansson Adrian <[log in to unmask]> * */
-public class HPSTestRunTracker2014LCDDBuilder extends HPSTestRunTracker2014Builder { - - protected LCDD lcdd; - protected LCDDBaseGeometry baseTrackerGeometry; - protected List<LCDDBaseGeometry> lcddGeometries; - private SensitiveDetector sensitiveDetector; - - /** - * Default constructor - */
+public class HPSTestRunTracker2014LCDDBuilder extends HPSTrackerLCDDBuilder { + +
public HPSTestRunTracker2014LCDDBuilder(boolean debugFlag) { super(debugFlag); }
- - /** - * Add to list of objects. - * @param geom - object to add. - */ - private void add(LCDDBaseGeometry geom) { - lcddGeometries.add(geom); - } - - - - /** - * Build the LCDD geometry objects. - * @param worldVolume - the reference volume. - */ - protected void build(Volume worldVolume) { -
+ + public void build(Volume worldVolume) { +
if(isDebug()) System.out.printf("%s: build the LCDD geometry objects\n", getClass().getSimpleName());
-
+
// initialize the list to store a reference to each object lcddGeometries = new ArrayList<LCDDBaseGeometry>();
@@ -90,15 +54,17 @@
add(supportPlateTopGeometry); // build modules
-
+
if(isDebug()) System.out.printf("%s: build modules\n", getClass().getSimpleName()); // Loop over all modules created for(ModuleBundle m : modules) {
-
+
// Do only L1?
- //if(m.getLayer()!=1) continue; -
+ if(onlyL1 && m.getLayer()!=1) continue; + + if(onlyBottom && m.getHalf()!="bottom") continue; +
if(isDebug()) { System.out.printf("%s: module layer %d half %s\n", getClass().getSimpleName(),m.getLayer(),m.getHalf()); m.print();
@@ -117,14 +83,14 @@
if(mother==null) throw new RuntimeException("Cound't find mother to module layer " + m.getLayer() + " half "+ m.getHalf()); if(isDebug()) System.out.printf("%s: found mother %s for module layer %d half %s\n", getClass().getSimpleName(),mother.getName(),m.getLayer(),m.getHalf());
-
+
// add the module to the list of objects that will be added to LCDD addModule(m, mother);
-
+
}
- - -
+ + +
//if(isDebug()) { System.out.printf("%s: DONE building the LCDD geometry objects\n", getClass().getSimpleName()); System.out.printf("%s: List of all %d LCDD geometry objects built\n", this.getClass().getSimpleName(), lcddGeometries.size());
@@ -133,14 +99,15 @@
} //}
-
+
// Set visualization features setVisualization();
- -
+ +
}
-
+ +
/** * Rules for adding the LCDD module geometry. * @param bundle - module to be added
@@ -152,12 +119,13 @@
LCDDBaseGeometry lcddM = new LCDDBaseGeometry(bundle.module, lcdd, mother); add(lcddM); addHalfModule(bundle.halfModuleAxial,lcddM);
- LCDDBaseGeometry lcddCB = new LCDDBaseGeometry(bundle.coldBlock, lcdd, lcddM); - add(lcddCB); - addHalfModule(bundle.halfModuleStereo,lcddM); -
+ if(!onlyAxial) { + LCDDBaseGeometry lcddCB = new LCDDBaseGeometry(bundle.coldBlock, lcdd, lcddM); + add(lcddCB); + addHalfModule(bundle.halfModuleStereo,lcddM); + }
}
-
+
/** * Rules for adding the LCDD half module geometry. * @param bundle - module to be added
@@ -183,291 +151,12 @@
// create the hybrid frame LCDDBaseGeometry lcddH = new LCDDBaseGeometry(bundle.hybrid, lcdd, lcddHM); add(lcddH);
- - } - - - protected void setLCDD(LCDD lcdd) { - this.lcdd = lcdd; - } - protected LCDD getLCDD() { - return lcdd; - } - protected LCDDBaseGeometry getBaseLCDD() { - return baseTrackerGeometry; - } -
- - /** - * Interface to the LCDD converter geometry for the geometry definition. - * - * @author Per Hansson Adrian <[log in to unmask]> - */ - protected static class LCDDBaseGeometry extends LCDDBaseGeometryVisualization { - private boolean debug = false; - private String name; - private Box box= null; - private Volume volume = null; - private Position pos = null; - private Rotation rot = null; - private PhysVol physVolume = null; - private LCDD lcdd = null; - private LCDDBaseGeometry mother = null; - protected Map<String,Integer> physVolId = null; - public List<LCDDBaseGeometry> daughters = new ArrayList<LCDDBaseGeometry>(); - /** - * Default constructor - */ - public LCDDBaseGeometry() { - } - - /** - * Interface to the LCDD converter geometry for the geometry definition. - * @param base - input geometry definition - * @param lcdd - lcdd file - * @param mother - reference to mother LCDD definition - */ - public LCDDBaseGeometry(BaseGeometry base, LCDD lcdd, LCDDBaseGeometry mother) { - if(isDebug()) System.out.printf("%s: constructing LCDD object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); - this.lcdd = lcdd; - setName(base.getName()); - setMother(mother); - mother.addDaughter(this); - buildBox(base); - buildVolume(base); - setPositionAndRotation(base); - //buildPhysVolume(mother); - if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); - }
+ }
- - protected void buildPhysVolume() { - if(isDebug()) System.out.printf("%s: build phys volume for %s\n", this.getClass().getSimpleName(),getName()); - setPhysVolume(new PhysVol(volume, getMother().getVolume(), getPos(), getRot())); - } - protected void buildBox(BaseGeometry base) { - if(isDebug()) System.out.printf("%s: build box for %s\n", this.getClass().getSimpleName(),getName()); - setBox(new Box(getName() + "Box", base.getBoxDim().x(), base.getBoxDim().y(), base.getBoxDim().z())); - } - protected void buildVolume(BaseGeometry base) { - if(isDebug()) System.out.printf("%s: build volume for %s with material %s\n", this.getClass().getSimpleName(),getName(),base.getMaterial()); - try { - Material mat = lcdd.getMaterial(base.getMaterial()); - setVolume(new Volume(getName() + "_volume", box, mat)); - } catch (JDOMException e) { - e.printStackTrace(); - } - } - - - protected void setPositionAndRotation(BaseGeometry base) { - - // NOTE: - // This sets position and reference w.r.t. mother coordinate system. - // If I'm not building that volume this will be wrong. - // TODO Similar to in the JAVA converter this should be something like the physical mother. - - - if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); - // Vector from origin to center of box locally - Hep3Vector box_center_base_local = base.getCenter(); - //translate to the mother coordinate system - Hep3Vector box_center_base = base.getCoord().getTransformation().transformed(box_center_base_local); - // find the position of the center in the mother coord - Hep3Vector box_center = VecOp.sub(box_center_base, base.getMother().getCenter()); - //Find LCDD Euler rotation angles from coordinate system unit vectors - Hep3Vector lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().v(), base.getCoord().w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1)); - // 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. - if (base.explicit_rot_angles!=null) { - // there are explicit rotations I need to apply. - // Find the displacement of the box center due to rotation about different origin - Hep3Vector box_center_base_rot = HPSTestRunTracker2014.getRotationDisplacement(base.getCoord().origin(), box_center_base, base.explicit_rot_angles); - if(isDebug()) { - System.out.printf("%s: lcdd_rot_angles %s\n", this.getClass().getSimpleName(),lcdd_rot_angles); - System.out.printf("%s: lcdd_rot_angles_2 %s\n", this.getClass().getSimpleName(),base.explicit_rot_angles); - System.out.printf("%s: box_center_base %s\n", this.getClass().getSimpleName(), box_center_base.toString()); - System.out.printf("%s: box_center_base_rot %s\n", this.getClass().getSimpleName(), box_center_base_rot.toString()); - } - // update the rotation angles - lcdd_rot_angles = base.explicit_rot_angles; - // update the position of the center in the mother coord - box_center = VecOp.sub(box_center_base_rot, base.getMother().getCenter()); - } - // Create the LCDD position - setPos(new Position(getName() + "_position",box_center.x(), box_center.y(), box_center.z())); - - if(getName().contains("module_L1t") && !getName().contains("halfmodule") && !getName().contains("cold")) { - lcdd_rot_angles = new BasicHep3Vector(-Math.PI,0,0.03); - lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().u(), base.getCoord().v(), new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,1,0)); - lcdd_rot_angles = HPSTestRunTracker2014.getEulerAngles(base.getCoord().u(), base.getCoord().w(), new BasicHep3Vector(1,0,0),new BasicHep3Vector(0,0,1)); - } - if(getName().contains("module_L1b") && !getName().contains("halfmodule") && !getName().contains("cold")) { - lcdd_rot_angles = new BasicHep3Vector(0,0,-0.030); - } - - - setRot(new Rotation(getName() + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z())); - if(isDebug()) { - System.out.printf("%s: box_center_base_local %s\n", this.getClass().getSimpleName(), box_center_base_local.toString()); - System.out.printf("%s: box_center_base %s\n", this.getClass().getSimpleName(), box_center_base.toString()); - System.out.printf("%s: mother center %s\n", this.getClass().getSimpleName(), base.getMother().getCenter().toString()); - 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: rot %s\n", this.getClass().getSimpleName(), getRot().toString()); - - //calculate the position in tracking volume separately as a xcheck - Hep3Vector box_center_tracking_xcheck = transformToTracking(box_center_base_local, base); - System.out.printf("%s: box_center_tracking_xcheck %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString()); - } - - } - protected Volume getVolume() { - return volume; - } - protected void setVolume(Volume volume) { - this.volume = volume; - } - protected Box getBox() { - return box; - } - protected void setBox(Box b) { - box = b; - } - protected String getName() { - return name; - } - protected void setName(String name) { - this.name = name; - } - protected Position getPos() { - return pos; - } - protected void setPos(Position pos) { - this.pos = pos; - } - protected Rotation getRot() { - return rot; - } - protected void setRot(Rotation rot) { - this.rot = rot; - } - protected LCDDBaseGeometry getMother() { - return mother; - } - protected void setMother(LCDDBaseGeometry mother) { - this.mother = mother; - } - protected PhysVol getPhysVolume() { - return physVolume; - } - protected void setPhysVolume(PhysVol physVolume) { - this.physVolume = physVolume; - } - public boolean isDebug() { - return debug; - } - protected List<LCDDBaseGeometry> getDaughters() { - return daughters; - } - protected void addDaughter(LCDDBaseGeometry o) { - getDaughters().add(o); - } - public String toString() { - String s = "LCDDBaseGeometry " + getName() + "\n"; - if(getPos()!=null && getRot()!=null) { - double x = Double.valueOf(getPos().getAttributeValue("x")); - double y = Double.valueOf(getPos().getAttributeValue("y")); - double z = Double.valueOf(getPos().getAttributeValue("z")); - s += "Position: " + String.format("(%.4f %.4f %.4f)\n", x,y,z); - x = Double.valueOf(getRot().getAttributeValue("x")); - y = Double.valueOf(getRot().getAttributeValue("y")); - z = Double.valueOf(getRot().getAttributeValue("z")); - s += "Rotation: " + String.format("(%.4f %.4f %.4f)\n", x,y,z); - } else { - s += " - no position/rotation info -\n"; - } - return s; - } - }
-
+ public void setVisualization() {
- /** - * - * Interface to the LCDD converter geometry for the geometry definition. - * No volume is built but it can be used as reference in building the geometry. - * - * @author Per Hansson Adrian <[log in to unmask]> - * - */ - protected static class GhostLCDDBaseGeometry extends LCDDBaseGeometry { - - /** - * Initialize this object with a known volume and no mother. Typically the world volume would use this. - * @param base - object used to get geometry definitions - * @param vol - given volume - */ - public GhostLCDDBaseGeometry(BaseGeometry base, Volume volume) { - super(); - if(isDebug()) System.out.printf("%s: constructing LCDD ghost object %s\n", this.getClass().getSimpleName(),base.getName()); - setName(base.getName()); - setVolume(volume); - if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); - } - - /** - * Initialize with base and mother. This is typically for a reference geometry object - * that is used for referencing coordinate systems but that doesn't have a volume itself. - * @param base - object used to get geometry definitions - * @param mother - mother LCDD object - */ - public GhostLCDDBaseGeometry(BaseGeometry base, LCDDBaseGeometry mother) { - super(); - if(isDebug()) System.out.printf("%s: constructing LCDD ghost object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); - setName(base.getName()); - setMother(mother); - if(isDebug()) System.out.printf("%s: DONE constructing LCDD object %s\n", this.getClass().getSimpleName(),base.getName()); - } - - } - - - - /** - * - * LCDD geometry visualization information - * - * @author Per Hansson Adrian <[log in to unmask]> - */ - protected static class LCDDBaseGeometryVisualization { - protected String visName = ""; - public LCDDBaseGeometryVisualization() {} - protected String getVisName() { - return visName; - } - protected void setVisName(String visName) { - this.visName = visName; - } - - - } - - public void setSensitiveDetector(SensitiveDetector sens) { - this.sensitiveDetector = sens; - } - - public SensitiveDetector getSensitiveDetector() { - return this.sensitiveDetector; - } - - /** - * Set visualization features. - */ - private void setVisualization() { -
if(isDebug()) System.out.printf("%s: Set LCDD visualization for %d LCDD geometry objects \n", getClass().getSimpleName(), lcddGeometries.size()); for(LCDDBaseGeometry g : lcddGeometries) { if(isDebug()) System.out.printf("%s: Set LCDD vis for %s \n", getClass().getSimpleName(), g.getName());
@@ -489,7 +178,7 @@
} } if(isDebug()) System.out.printf("%s: DONE Set LCDD vis \n", getClass().getSimpleName());
- } -
+ }
+
}
\ No newline at end of file
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