Author: phansson Date: Fri Oct 31 12:37:29 2014 New Revision: 3406 Log: Large refactoring: renaming, pulling out static sub-classes and setting up for extracting common features for the SurveyVolumes into a super class. Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaGhostSurveyVolume.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaSurveyVolume.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDGhostSurveyVolume.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDSurveyVolume.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeImpl.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeVisualization.java Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014JavaBuilder.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014LCDDBuilder.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerJavaBuilder.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerLCDDBuilder.java projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014Converter.java Fri Oct 31 12:37:29 2014 @@ -26,11 +26,11 @@ import org.lcsim.detector.tracker.silicon.SiTrackerModule; import org.lcsim.geometry.compact.Detector; import org.lcsim.geometry.compact.Subdetector; +import org.lcsim.geometry.compact.converter.JavaGhostSurveyVolume; import org.lcsim.geometry.compact.converter.HPSTestRunTracker2014JavaBuilder; import org.lcsim.geometry.compact.converter.HPSTrackerBuilder; import org.lcsim.geometry.compact.converter.HPSTrackerJavaBuilder; -import org.lcsim.geometry.compact.converter.HPSTrackerJavaBuilder.GhostJavaBaseGeom; -import org.lcsim.geometry.compact.converter.HPSTrackerJavaBuilder.JavaBaseGeometry; +import org.lcsim.geometry.compact.converter.JavaSurveyVolume; import org.lcsim.geometry.subdetector.HPSTestRunTracker2014; /** @@ -147,7 +147,7 @@ * Setup the detector element for a geometry object. * @param geometryObject - volume to process. */ - private void setupPhysicalVolumes(JavaBaseGeometry geometryObject) { + private void setupPhysicalVolumes(JavaSurveyVolume geometryObject) { if(_debug) System.out.printf("%s: setupDetectorElement for %s\n", getClass().getSimpleName(),geometryObject.getName()); @@ -161,7 +161,7 @@ // are added so I keep track of all the elements in the builder in order // to build a hierarchy. - if( geometryObject instanceof GhostJavaBaseGeom) { + if( geometryObject instanceof JavaGhostSurveyVolume) { if(_debug) System.out.printf("%s: %s is a ghost volume, dont create elements or physvol\n", getClass().getSimpleName(),geometryObject.getName()); @@ -401,7 +401,7 @@ // add daughters if(_debug) System.out.printf("%s: add %d daughters to %s\n", this.getClass().getSimpleName(),geometryObject.getDaughters().size(), geometryObject.getName()); - for(JavaBaseGeometry daughter : geometryObject.getDaughters()) { + for(JavaSurveyVolume daughter : geometryObject.getDaughters()) { setupPhysicalVolumes(daughter); } Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014JavaBuilder.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014JavaBuilder.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014JavaBuilder.java Fri Oct 31 12:37:29 2014 @@ -62,26 +62,26 @@ if(isDebug()) System.out.printf("%s: build the JAVA geometry objects\n", getClass().getSimpleName()); // initialize the list to store a reference to each object - java_objects = new ArrayList<JavaBaseGeometry>(); + javaSurveyVolumes = new ArrayList<JavaSurveyVolume>(); // Go through the list of volumes to build that is created in the generic builder class - JavaBaseGeometry trackingGeometry = new JavaBaseGeometry(_builder.getBaseGeometry(TrackingVolume.class), trackingVolume); + JavaSurveyVolume trackingGeometry = new JavaSurveyVolume(_builder.getBaseGeometry(TrackingVolume.class), trackingVolume); add(trackingGeometry); //setBaseTrackerGeometry(new GhostJavaBaseGeom(_builder.getBaseGeometry(Base.class), trackingGeometry)); - setBaseTrackerGeometry(new JavaBaseGeometry(_builder.getBaseGeometry(TrackerEnvelope.class), trackingGeometry,1)); + setBaseTrackerGeometry(new JavaSurveyVolume(_builder.getBaseGeometry(TrackerEnvelope.class), trackingGeometry,1)); add(getBaseTrackerGeometry()); - JavaBaseGeometry basePlateGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(BasePlate.class), getBaseTrackerGeometry()); + JavaSurveyVolume basePlateGeometry = new JavaGhostSurveyVolume(_builder.getBaseGeometry(BasePlate.class), getBaseTrackerGeometry()); add(basePlateGeometry); // skip the c-support, this is purely a reference volume in the builder so should have no use here!? //JavaBaseGeometry cSupportGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(CSupport.class), baseTrackerGeometry); //add(cSupportGeometry); - JavaBaseGeometry supportBottomGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(SupportBottom.class), getBaseTrackerGeometry()); + JavaSurveyVolume supportBottomGeometry = new JavaGhostSurveyVolume(_builder.getBaseGeometry(SupportBottom.class), getBaseTrackerGeometry()); add(supportBottomGeometry); - JavaBaseGeometry supportPlateBottomGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(SupportPlateBottom.class), getBaseTrackerGeometry()); + JavaSurveyVolume supportPlateBottomGeometry = new JavaGhostSurveyVolume(_builder.getBaseGeometry(SupportPlateBottom.class), getBaseTrackerGeometry()); add(supportPlateBottomGeometry); - JavaBaseGeometry supportTopGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(SupportTop.class), getBaseTrackerGeometry()); + JavaSurveyVolume supportTopGeometry = new JavaGhostSurveyVolume(_builder.getBaseGeometry(SupportTop.class), getBaseTrackerGeometry()); add(supportTopGeometry); - JavaBaseGeometry supportPlateTopGeometry = new GhostJavaBaseGeom(_builder.getBaseGeometry(SupportPlateTop.class), getBaseTrackerGeometry()); + JavaSurveyVolume supportPlateTopGeometry = new JavaGhostSurveyVolume(_builder.getBaseGeometry(SupportPlateTop.class), getBaseTrackerGeometry()); add(supportPlateTopGeometry); // build modules @@ -98,8 +98,8 @@ // Find the mother among the objects using its name, should probably have a better way... String name_mother = m.getMother().getName(); - JavaBaseGeometry mother = null; - for(JavaBaseGeometry g : java_objects) { + JavaSurveyVolume mother = null; + for(JavaSurveyVolume g : javaSurveyVolumes) { if(g.getName().equals(name_mother)) { mother = g; break; @@ -125,7 +125,7 @@ if(isDebug()) { System.out.printf("%s: DONE building the JAVA geometry objects\n", getClass().getSimpleName()); System.out.printf("%s: List of all the JAVA geometry objects built\n", this.getClass().getSimpleName()); - for(JavaBaseGeometry bg : java_objects) { + for(JavaSurveyVolume bg : javaSurveyVolumes) { System.out.printf("-------\n%s\n", bg.toString()); } } @@ -142,7 +142,7 @@ * @param bundle - module to be added * @param mother - mother JAVA geometry object */ - private void addModule(TestRunModuleBundle bundle, JavaBaseGeometry mother) { + private void addModule(TestRunModuleBundle bundle, JavaSurveyVolume mother) { if(isDebug()) { System.out.printf("%s: addModule %s containing:\n",this.getClass().getSimpleName(), bundle.module.getName()); @@ -150,7 +150,7 @@ } // Create the module - JavaBaseGeometry lcddM = new GhostJavaBaseGeom(bundle.module, mother); + JavaSurveyVolume lcddM = new JavaGhostSurveyVolume(bundle.module, mother); add(lcddM); // add half modules @@ -170,13 +170,13 @@ * @param bundle - module to be added * @param mother - mother JAVA geometry object */ - private void addHalfModule(TestRunHalfModuleBundle bundle, JavaBaseGeometry mother) { + private void addHalfModule(TestRunHalfModuleBundle bundle, JavaSurveyVolume mother) { // Create the half-module // This is not a ghost element but reflects the module // concept in the old compact description // TODO fix the layer IDs int oldCompactModuleId = 0; - JavaBaseGeometry lcddHM = new JavaBaseGeometry(bundle.halfModule, mother,oldCompactModuleId); + JavaSurveyVolume lcddHM = new JavaSurveyVolume(bundle.halfModule, mother,oldCompactModuleId); add(lcddHM); // ComponentNumber is taken from old geometry where it is simply a counter when adding the xml daughters to the TestRunModule. @@ -184,11 +184,11 @@ int componentNumber = ((Sensor)bundle.sensor).getId(); // create the sensor - JavaBaseGeometry lcddS = new JavaBaseGeometry(bundle.sensor, lcddHM, componentNumber); + JavaSurveyVolume lcddS = new JavaSurveyVolume(bundle.sensor, lcddHM, componentNumber); add(lcddS); // create the active sensor - JavaBaseGeometry lcddAS = new JavaBaseGeometry(bundle.activeSensor, lcddS, componentNumber); + JavaSurveyVolume lcddAS = new JavaSurveyVolume(bundle.activeSensor, lcddS, componentNumber); add(lcddAS); // if(isDebug()) { Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014LCDDBuilder.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014LCDDBuilder.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTestRunTracker2014LCDDBuilder.java Fri Oct 31 12:37:29 2014 @@ -49,22 +49,22 @@ // Go through the list of volumes to build that is created in the generic builder class // TODO this is manual now since I don't have a way of knowing in the generic builder class what is a ghost volume at this point. - LCDDBaseGeometry trackingGeometry = new LCDDBaseGeometry(_builder.getBaseGeometry(TrackingVolume.class), worldVolume); + LCDDSurveyVolume trackingGeometry = new LCDDSurveyVolume(_builder.getBaseGeometry(TrackingVolume.class), worldVolume); add(trackingGeometry); - baseTrackerGeometry = new LCDDBaseGeometry(_builder.getBaseGeometry(TrackerEnvelope.class), lcdd, trackingGeometry); - add(baseTrackerGeometry); - LCDDBaseGeometry basePlateGeometry = new LCDDBaseGeometry(_builder.getBaseGeometry(BasePlate.class), lcdd, baseTrackerGeometry); + baseSurveyVolume = new LCDDSurveyVolume(_builder.getBaseGeometry(TrackerEnvelope.class), lcdd, trackingGeometry); + add(baseSurveyVolume); + LCDDSurveyVolume basePlateGeometry = new LCDDSurveyVolume(_builder.getBaseGeometry(BasePlate.class), lcdd, baseSurveyVolume); add(basePlateGeometry); // TODO I don't think this c-support has any use at all since the coordinates of it has been already used in the builder. Should remove? - LCDDBaseGeometry cSupportGeometry = new GhostLCDDBaseGeometry(_builder.getBaseGeometry(CSupport.class), baseTrackerGeometry); + LCDDSurveyVolume cSupportGeometry = new LCDDGhostSurveyVolume(_builder.getBaseGeometry(CSupport.class), baseSurveyVolume); add(cSupportGeometry); - LCDDBaseGeometry supportBottomGeometry = new GhostLCDDBaseGeometry(_builder.getBaseGeometry(SupportBottom.class), baseTrackerGeometry); + LCDDSurveyVolume supportBottomGeometry = new LCDDGhostSurveyVolume(_builder.getBaseGeometry(SupportBottom.class), baseSurveyVolume); add(supportBottomGeometry); - LCDDBaseGeometry supportPlateBottomGeometry = new LCDDBaseGeometry(_builder.getBaseGeometry(SupportPlateBottom.class), lcdd, baseTrackerGeometry); + LCDDSurveyVolume supportPlateBottomGeometry = new LCDDSurveyVolume(_builder.getBaseGeometry(SupportPlateBottom.class), lcdd, baseSurveyVolume); add(supportPlateBottomGeometry); - LCDDBaseGeometry supportTopGeometry = new GhostLCDDBaseGeometry(_builder.getBaseGeometry(SupportTop.class), baseTrackerGeometry); + LCDDSurveyVolume supportTopGeometry = new LCDDGhostSurveyVolume(_builder.getBaseGeometry(SupportTop.class), baseSurveyVolume); add(supportTopGeometry); - LCDDBaseGeometry supportPlateTopGeometry = new LCDDBaseGeometry(_builder.getBaseGeometry(SupportPlateTop.class), lcdd, baseTrackerGeometry); + LCDDSurveyVolume supportPlateTopGeometry = new LCDDSurveyVolume(_builder.getBaseGeometry(SupportPlateTop.class), lcdd, baseSurveyVolume); add(supportPlateTopGeometry); // build modules @@ -82,8 +82,8 @@ // Find the mother among the LCDD objects using its name, should probably have a better way... String name_mother = m.getMother().getName(); - LCDDBaseGeometry mother = null; - for(LCDDBaseGeometry g : lcddGeometries) { + LCDDSurveyVolume mother = null; + for(LCDDSurveyVolume g : lcddSurveyVolumes) { if(g.getName().equals(name_mother)) { mother = g; break; @@ -103,8 +103,8 @@ //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()); - for(LCDDBaseGeometry bg : lcddGeometries) { + System.out.printf("%s: List of all %d LCDD geometry objects built\n", this.getClass().getSimpleName(), lcddSurveyVolumes.size()); + for(SurveyVolumeImpl bg : lcddSurveyVolumes) { System.out.printf("-------\n%s\n", bg.toString()); } //} @@ -123,13 +123,13 @@ * @param bundle - module to be added * @param mother - mother LCDD geometry object */ - private void addModule(ModuleBundle bundle, LCDDBaseGeometry mother) { + private void addModule(ModuleBundle bundle, LCDDSurveyVolume mother) { // This could perhaps be fixed if there is a relation with daughters in geometry definition? // create the module - LCDDBaseGeometry lcddM = new LCDDBaseGeometry(bundle.module, lcdd, mother); + LCDDSurveyVolume lcddM = new LCDDSurveyVolume(bundle.module, lcdd, mother); add(lcddM); if(bundle.halfModuleAxial!=null) addHalfModule((TestRunHalfModuleBundle)bundle.halfModuleAxial,lcddM); - if(bundle.coldBlock!=null) add(new LCDDBaseGeometry(bundle.coldBlock, lcdd, lcddM)); + if(bundle.coldBlock!=null) add(new LCDDSurveyVolume(bundle.coldBlock, lcdd, lcddM)); if(bundle.halfModuleStereo!=null) addHalfModule((TestRunHalfModuleBundle)bundle.halfModuleStereo,lcddM); } @@ -138,25 +138,25 @@ * @param bundle - module to be added * @param mother - mother LCDD geometry object */ - private void addHalfModule(TestRunHalfModuleBundle bundle, LCDDBaseGeometry mother) { + private void addHalfModule(TestRunHalfModuleBundle bundle, LCDDSurveyVolume mother) { // This could perhaps be fixed if there is a relation with daughters in geometry definition? // create the half-module - LCDDBaseGeometry lcddHM = new LCDDBaseGeometry(bundle.halfModule, lcdd, mother); + LCDDSurveyVolume lcddHM = new LCDDSurveyVolume(bundle.halfModule, lcdd, mother); add(lcddHM); // create the sensor - LCDDBaseGeometry lcddS = new LCDDBaseGeometry(bundle.sensor, lcdd, lcddHM); + LCDDSurveyVolume lcddS = new LCDDSurveyVolume(bundle.sensor, lcdd, lcddHM); add(lcddS); // create the active sensor - LCDDBaseGeometry lcddAS = new LCDDBaseGeometry(bundle.activeSensor, lcdd, lcddS); + LCDDSurveyVolume lcddAS = new LCDDSurveyVolume(bundle.activeSensor, lcdd, lcddS); add(lcddAS); // create the lamination - LCDDBaseGeometry lcddL = new LCDDBaseGeometry(bundle.lamination, lcdd, lcddHM); + LCDDSurveyVolume lcddL = new LCDDSurveyVolume(bundle.lamination, lcdd, lcddHM); add(lcddL); // create the carbon fiber frame - LCDDBaseGeometry lcddCF = new LCDDBaseGeometry(bundle.carbonFiber, lcdd, lcddHM); + LCDDSurveyVolume lcddCF = new LCDDSurveyVolume(bundle.carbonFiber, lcdd, lcddHM); add(lcddCF); // create the hybrid frame - LCDDBaseGeometry lcddH = new LCDDBaseGeometry(bundle.hybrid, lcdd, lcddHM); + LCDDSurveyVolume lcddH = new LCDDSurveyVolume(bundle.hybrid, lcdd, lcddHM); add(lcddH); } @@ -164,8 +164,8 @@ public 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 visualization for %d LCDD geometry objects \n", getClass().getSimpleName(), lcddSurveyVolumes.size()); + for(SurveyVolumeImpl g : lcddSurveyVolumes) { if(isDebug()) System.out.printf("%s: Set LCDD vis for %s \n", getClass().getSimpleName(), g.getName()); if(g.getName().endsWith("baseplate")) g.setVisName("BasePlateVis"); //else if(g.getName().contains("base")) g.setVisName("BaseVis"); Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerJavaBuilder.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerJavaBuilder.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerJavaBuilder.java Fri Oct 31 12:37:29 2014 @@ -1,8 +1,4 @@ package org.lcsim.geometry.compact.converter; - -import hep.physics.vec.BasicHep3Vector; -import hep.physics.vec.Hep3Vector; -import hep.physics.vec.VecOp; import java.util.ArrayList; import java.util.List; @@ -11,29 +7,17 @@ import org.lcsim.detector.DetectorIdentifierHelper; import org.lcsim.detector.IDetectorElement; import org.lcsim.detector.ILogicalVolume; -import org.lcsim.detector.IPhysicalVolume; -import org.lcsim.detector.IRotation3D; -import org.lcsim.detector.ITranslation3D; -import org.lcsim.detector.LogicalVolume; -import org.lcsim.detector.PhysicalVolume; -import org.lcsim.detector.RotationGeant; -import org.lcsim.detector.Transform3D; -import org.lcsim.detector.Translation3D; import org.lcsim.detector.identifier.ExpandedIdentifier; import org.lcsim.detector.identifier.IExpandedIdentifier; import org.lcsim.detector.identifier.IIdentifierDictionary; -import org.lcsim.detector.material.IMaterial; -import org.lcsim.detector.material.MaterialStore; -import org.lcsim.detector.solids.Box; import org.lcsim.detector.tracker.silicon.SiTrackerModule; import org.lcsim.geometry.compact.Subdetector; -import org.lcsim.geometry.util.TransformationUtils; public abstract class HPSTrackerJavaBuilder implements IHPSTrackerJavaBuilder { protected boolean _debug = true; - private JavaBaseGeometry baseTrackerGeometry; - protected List<JavaBaseGeometry> java_objects = new ArrayList<JavaBaseGeometry>(); + private JavaSurveyVolume baseSurveyVolume; + protected List<JavaSurveyVolume> javaSurveyVolumes = new ArrayList<JavaSurveyVolume>(); protected DetectorIdentifierHelper detectorIdentifierHelper; protected IIdentifierDictionary identifierDictionary; protected Subdetector subdet; @@ -55,8 +39,8 @@ * Add to list of objects. * @param geom - object to add. */ - public void add(JavaBaseGeometry geom) { - java_objects.add(geom); + public void add(JavaSurveyVolume geom) { + javaSurveyVolumes.add(geom); } public void setBuilder(HPSTrackerBuilder b) { @@ -172,309 +156,15 @@ /** * @return the baseTrackerGeometry */ - public JavaBaseGeometry getBaseTrackerGeometry() { - return baseTrackerGeometry; + public JavaSurveyVolume getBaseTrackerGeometry() { + return baseSurveyVolume; } /** * @param baseTrackerGeometry the baseTrackerGeometry to set */ - public void setBaseTrackerGeometry(JavaBaseGeometry baseTrackerGeometry) { - this.baseTrackerGeometry = baseTrackerGeometry; - } - - - /** - * - * Interface to the JAVA converter geometry for the geometry definition. - * In this case no volume is built but can be used as reference in building the geometry. - * @author Per Hansson Adrian <[log in to unmask]> - */ - public static class GhostJavaBaseGeom extends JavaBaseGeometry { - - /** - * 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 object - */ - public GhostJavaBaseGeom(SurveyVolume base, JavaBaseGeometry mother) { - super(); - if(isDebug()) System.out.printf("%s: constructing JAVA ghost object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); - setName(base.getName()); - setMother(mother); - mother.addDaughter(this); - setPositionAndRotation(base); - if(isDebug()) System.out.printf("%s: DONE constructing JAVA object %s\n", this.getClass().getSimpleName(),base.getName()); - } - - - - } - - /** - * Interface to the JAVA converter geometry for the geometry definition. - * @author Per Hansson Adrian <[log in to unmask]> - */ - public static class JavaBaseGeometry { - private boolean debug = false; - private String name; - private Box box= null; - private ILogicalVolume volume = null; - private ITranslation3D pos = null; - private IRotation3D rot = null; - private IPhysicalVolume physVolume = null; - private JavaBaseGeometry mother = null; - public List<JavaBaseGeometry> daughters = new ArrayList<JavaBaseGeometry>(); - private int componentId = -1; - - /** - * Default constructor - */ - public JavaBaseGeometry() { - } - - /** - * Construct a JAVA geometry object from its geometry definition and an already built logical volume. - * This is typically used by the tracking volume. - * @param geomObject - input geometry definition - * @param vol - logical volume - */ - public JavaBaseGeometry(SurveyVolume geomObject, ILogicalVolume vol) { - if(isDebug()) System.out.printf("%s: JavaBaseGeometry %s (given logical volume %s)\n", this.getClass().getSimpleName(),geomObject.getName(),vol.getName()); - // this must be tracking volume. May change in the future and is probably weird to make this requirement here. - if(!geomObject.getName().contains("tracking")) throw new RuntimeException("this constructor is only used with the tracking volume!?"); - setName(geomObject.getName()); - setVolume(vol); - // since it's tracking volume, set the pos and rotation trivially - 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()); - } - - /** - * Construct a JAVA geometry object from its geometry definition. - * @param geomObject - input geometry definition - * @param mother - reference to mother JAVA definition - * @param volumeId - component id number - */ - public JavaBaseGeometry(SurveyVolume geomObject, JavaBaseGeometry mother, int volumeId) { - if(isDebug()) System.out.printf("%s: JavaBaseGeometry %s (volumeID %d, mother %s)\n", this.getClass().getSimpleName(),geomObject.getName(),volumeId,mother==null?"null":mother.getName()); - setName(geomObject.getName()); - setComponentId(volumeId); - setMother(mother); - mother.addDaughter(this); - buildBox(geomObject); - buildVolume(geomObject); - setPositionAndRotation(geomObject); - if(isDebug()) System.out.printf("%s: DONE JavaBaseGeometry %s\n", this.getClass().getSimpleName(),geomObject.getName()); - } - - protected boolean hasCoordinateSystemInfo() { - return pos!=null && rot!=null; - } - - - public void buildPhysVolume() { - if(isDebug()) System.out.printf("%s: build phys volume for %s with mother %s and physical mother %s\n", this.getClass().getSimpleName(),getName(),getMother().getName(),getPhysMother().getName()); - JavaBaseGeometry physMother = getPhysMother(); - setPhysVolume(new PhysicalVolume(new Transform3D(getPos(), getRot()), name, volume, physMother.getVolume(),getComponentId())); - } - protected void buildBox(SurveyVolume base) { - Hep3Vector b = base.getBoxDim(); - b = VecOp.mult(0.5, b); - if(isDebug()) System.out.printf("%s: build box for %s with dimensions %s \n", this.getClass().getSimpleName(),getName(), b); - setBox(new Box(getName() + "Box", b.x(), b.y(), b.z())); - } - protected void buildVolume(SurveyVolume base) { - if(isDebug()) System.out.printf("%s: build volume for %s with material %s\n", this.getClass().getSimpleName(),getName(),base.getMaterial()); - IMaterial material = MaterialStore.getInstance().get(base.getMaterial()); - setVolume(new LogicalVolume(getName() + "_volume", box, material)); - - } - protected void setPositionAndRotation(SurveyVolume base) { - if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); - - // no mother, this must be the world/tracking volume!? - if(base.getMother()==null) throw new RuntimeException("trying to set coordinates w/o mother defined for "+base.getName()); - - // Vector from origin to center of box locally - Hep3Vector box_center_base_local = base.getCenter(); - - // find the physical mother i.e. not a ghost volume and compound transformations to it - JavaBaseGeometry physMother = getPhysMother(); - if(isDebug()) System.out.printf("%s: physical mother to transform to is %s; find the transform to it\n", this.getClass().getSimpleName(),physMother.getName()); - Transform3D trf = HPSTrackerBuilder.getTransform(base.getCoord().getTransformation(),base.getMother(),physMother.getName()); - if(isDebug()) System.out.printf("%s: found transform to physical mother \n%s\n\n", this.getClass().getSimpleName(),trf.toString()); - - // find the position of the center in the physical mother coord - Hep3Vector box_center_base = trf.transformed(box_center_base_local); - - // find the position of the center of the box in the mother coordinate system, make sure to use the physical mother coordinates - if(isDebug()) System.out.printf("%s: find center of box in physical mother coord %s \n", this.getClass().getSimpleName(),physMother.getName()); - // hack since my getTransform function needs a mother TODO Fix this! - SurveyVolume gm = base; - if(isDebug()) System.out.printf("%s: look for physical mother %s starting from mother %s \n", this.getClass().getSimpleName(),physMother.getName(),gm.getMother()!=null?gm.getMother().getName():"-- no mother --"); - while((gm=gm.getMother()).getName()!=physMother.getName()) { - if(isDebug()) System.out.printf("%s: gm is %s \n", this.getClass().getSimpleName(),gm.getName()); - //gm = gm.getMother(); - } - if(isDebug()) System.out.printf("%s: found physical mother %s with center at %s \n", this.getClass().getSimpleName(),gm.getName(), gm.getCenter()); - - Hep3Vector mother_center = gm.getCenter(); - - // now calculate the position of this box center in the mother LCDD coordinates - Hep3Vector box_center = VecOp.sub(box_center_base, mother_center); - - //Find LCDD Euler rotation angles from coordinate system unit vectors - //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 base_u = base.getCoord().u(); - Hep3Vector base_v = base.getCoord().v(); - Hep3Vector base_w = base.getCoord().w(); - if(isDebug()) System.out.printf("%s: unit vectors in mother coord: %s, %s, %s\n", this.getClass().getSimpleName(),base_u.toString(),base_v.toString(),base_w.toString()); - 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())) { - if(isDebug()) System.out.printf("%s: Need to get unit vectors in physical mother %s coord system\n", this.getClass().getSimpleName(),physMother.getName()); - Transform3D trf_mother = HPSTrackerBuilder.getTransform(base.getMother().getCoord().getTransformation(),base.getMother().getMother(),physMother.getName()); - if(isDebug()) System.out.printf("%s: found transform from mother to physical mother \n%s\n", this.getClass().getSimpleName(),trf_mother.toString()); - //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)); - base_u = VecOp.unit(trf_mother.rotated(base_u)); - base_v = VecOp.unit(trf_mother.rotated(base_v)); - base_w = VecOp.unit(trf_mother.rotated(base_w)); - - } else { - if(isDebug()) System.out.printf("%s: mother and physical mother is the same so unit vectors didn't change\n",getClass().getSimpleName()); - } - - if(isDebug()) { - if(isDebug()) System.out.printf("%s: final unit vectors to get Cardan angles from : \n%s, %s, %s -> %s, %s, %s \n", - this.getClass().getSimpleName(), - base_u.toString(),base_v.toString(),base_w.toString(), - 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 = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w); - - - // 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())); - - 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()==null?" <no mother> ":mother_center.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 = HPSTrackerBuilder.transformToTracking(box_center_base_local, base); - System.out.printf("%s: box_center_tracking_xcheck %s for %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString(),base.getName()); - } - - } - - /** - * Find the first non-ghost volume among parents. - * @return mother object - */ - public JavaBaseGeometry getPhysMother() { - //if(isDebug()) System.out.printf("%s: finding physical mother to %s\n", this.getClass().getSimpleName(), getName()); - if(mother==null) throw new RuntimeException("Trying to get phys mother but there is no mother!"); - if(mother instanceof GhostJavaBaseGeom) { - return mother.getPhysMother(); - } else { - //if(isDebug()) System.out.printf("%s: found a non-ghost volume: %s\n", this.getClass().getSimpleName(), mother.getName()); - return mother; - } - } - - - public ILogicalVolume getVolume() { - return volume; - } - protected void setVolume(ILogicalVolume volume) { - this.volume = volume; - } - protected Box getBox() { - return box; - } - protected void setBox(Box b) { - box = b; - } - public String getName() { - return name; - } - protected void setName(String name) { - this.name = name; - } - protected ITranslation3D getPos() { - return pos; - } - protected void setPos(ITranslation3D iTranslation3D) { - this.pos = iTranslation3D; - } - protected IRotation3D getRot() { - return rot; - } - protected void setRot(IRotation3D iRotation3D) { - this.rot = iRotation3D; - } - public JavaBaseGeometry getMother() { - return mother; - } - protected void setMother(JavaBaseGeometry mother) { - this.mother = mother; - } - public IPhysicalVolume getPhysVolume() { - return physVolume; - } - protected void setPhysVolume(PhysicalVolume physVolume) { - this.physVolume = physVolume; - } - public boolean isDebug() { - return debug; - } - - public List<JavaBaseGeometry> getDaughters() { - return daughters; - } - - protected void addDaughter(JavaBaseGeometry o) { - getDaughters().add(o); - } - - public int getComponentId() { - return componentId; - } - - public void setComponentId(int componentId) { - this.componentId = componentId; - } - - public String toString() { - String s = "JavaBaseGeometry " + getName() + "\n"; - if(getPos()!=null && getRot()!=null) { - s += "Position: " + getPos().toString() + "\n"; - s += "Rotation: " + getRot().toString() + "\n"; - } else { - s+= " - no position/rotation info -\n"; - } - return s; - } - + public void setBaseTrackerGeometry(JavaSurveyVolume baseTrackerGeometry) { + this.baseSurveyVolume = baseTrackerGeometry; } Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerLCDDBuilder.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerLCDDBuilder.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/HPSTrackerLCDDBuilder.java Fri Oct 31 12:37:29 2014 @@ -1,32 +1,19 @@ package org.lcsim.geometry.compact.converter; - -import hep.physics.vec.BasicHep3Vector; -import hep.physics.vec.Hep3Vector; -import hep.physics.vec.VecOp; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.jdom.Element; -import org.jdom.JDOMException; -import org.lcsim.detector.Transform3D; -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; -import org.lcsim.geometry.util.TransformationUtils; public abstract class HPSTrackerLCDDBuilder implements IHPSTrackerLCDDBuilder { public boolean _debug = false; protected LCDD lcdd = null; - protected LCDDBaseGeometry baseTrackerGeometry; - protected List<LCDDBaseGeometry> lcddGeometries = new ArrayList<LCDDBaseGeometry>(); + protected LCDDSurveyVolume baseSurveyVolume; + protected List<LCDDSurveyVolume> lcddSurveyVolumes = new ArrayList<LCDDSurveyVolume>(); private SensitiveDetector sensitiveDetector; public HPSTrackerBuilder _builder = null; protected Element node; @@ -69,266 +56,11 @@ } /** - * Interface to the LCDD converter geometry for the geometry definition. - * - * @author Per Hansson Adrian <[log in to unmask]> - */ - public static class LCDDBaseGeometry extends LCDDBaseGeometryVisualization { - private boolean debug = true; - 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() { - } - - /** - * 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 LCDDBaseGeometry(SurveyVolume base, Volume volume) { - super(); - if(isDebug()) System.out.printf("%s: constructing LCDD object %s with given volume name %s\n", this.getClass().getSimpleName(),base.getName(),volume.getName()); - 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 = 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 %s\n", this.getClass().getSimpleName(),base.getName()); - } - - /** - * 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(SurveyVolume 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()); - } - - - public 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())); - } - public void buildBox(SurveyVolume 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())); - } - public void buildVolume(SurveyVolume 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(); - } - } - - - public void setPositionAndRotation(SurveyVolume base) { - if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); - - // 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(base.getMother()==null) throw new RuntimeException("trying to set coordinates w/o mother defined for "+base.getName()); - - // Vector from origin to center of box locally - Hep3Vector box_center_base_local = base.getCenter(); - - //translate to the mother coordinate system - LCDDBaseGeometry physMother = getPhysMother(); - if(isDebug()) System.out.printf("%s: physical mother to transform to is %s; find the transform to it\n", this.getClass().getSimpleName(),physMother.getName()); - Transform3D trf = HPSTrackerBuilder.getTransform(base.getCoord().getTransformation(),base.getMother(),physMother.getName()); - if(isDebug()) System.out.printf("%s: found transform to physical mother \n%s\n\n", this.getClass().getSimpleName(),trf.toString()); - - // find the position of the center in the physical mother coord - Hep3Vector box_center_base = trf.transformed(box_center_base_local); - - // find the position of the center of the box in the mother coordinate system, make sure to use the physical mother coordinates - if(isDebug()) System.out.printf("%s: find center of box in physical mother coord %s \n", this.getClass().getSimpleName(),physMother.getName()); - // hack since my getTransform function needs a mother TODO Fix this! - SurveyVolume gm = base; - if(isDebug()) System.out.printf("%s: look for physical mother %s starting from mother %s \n", this.getClass().getSimpleName(),physMother.getName(),gm.getMother()!=null?gm.getMother().getName():"-- no mother --"); - while((gm=gm.getMother()).getName()!=physMother.getName()) { - if(isDebug()) System.out.printf("%s: gm is %s \n", this.getClass().getSimpleName(),gm.getName()); - //gm = gm.getMother(); - } - if(isDebug()) System.out.printf("%s: found physical mother %s with center at %s \n", this.getClass().getSimpleName(),gm.getName(), gm.getCenter()); - - Hep3Vector mother_center = gm.getCenter(); - - // find the position of the center in the mother coord - Hep3Vector box_center = VecOp.sub(box_center_base, mother_center); - - //Find LCDD Euler rotation angles from coordinate system unit vectors - //Note that this has to be rotation wrt to physical mother and not just mother as normally is the case - 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 base_u = base.getCoord().u(); - Hep3Vector base_v = base.getCoord().v(); - Hep3Vector base_w = base.getCoord().w(); - if(isDebug()) System.out.printf("%s: unit vectors in mother coord: %s, %s, %s\n", this.getClass().getSimpleName(),base_u.toString(),base_v.toString(),base_w.toString()); - 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())) { - if(isDebug()) System.out.printf("%s: Need to get unit vectors in physical mother %s coord system\n", this.getClass().getSimpleName(),physMother.getName()); - Transform3D trf_mother = HPSTrackerBuilder.getTransform(base.getMother().getCoord().getTransformation(),base.getMother().getMother(),physMother.getName()); - if(isDebug()) System.out.printf("%s: found transform from mother to physical mother \n%s\n", this.getClass().getSimpleName(),trf_mother.toString()); - //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)); - base_u = VecOp.unit(trf_mother.rotated(base_u)); - base_v = VecOp.unit(trf_mother.rotated(base_v)); - base_w = VecOp.unit(trf_mother.rotated(base_w)); - - } else { - if(isDebug()) System.out.printf("%s: mother and physical mother is the same so unit vectors didn't change\n",getClass().getSimpleName()); - } - - if(isDebug()) { - if(isDebug()) System.out.printf("%s: final unit vectors to get Cardan angles from : \n%s, %s, %s -> %s, %s, %s \n", - this.getClass().getSimpleName(), - base_u.toString(),base_v.toString(),base_w.toString(), - 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 = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w); - - - // Create the LCDD position - setPos(new Position(getName() + "_position",box_center.x(), box_center.y(), box_center.z())); - - 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(), mother_center.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 = HPSTrackerBuilder.transformToTracking(box_center_base_local, base); - System.out.printf("%s: box_center_tracking_xcheck %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString()); - } - - } - /** - * Find the first non-ghost volume among parents. - * @return mother object - */ - public LCDDBaseGeometry getPhysMother() { - //if(isDebug()) System.out.printf("%s: finding physical mother to %s\n", this.getClass().getSimpleName(), getName()); - if(mother==null) throw new RuntimeException("Trying to get phys mother but there is no mother!"); - if(mother instanceof GhostLCDDBaseGeometry) { - return mother.getPhysMother(); - } else { - //if(isDebug()) System.out.printf("%s: found a non-ghost volume: %s\n", this.getClass().getSimpleName(), mother.getName()); - return mother; - } - } - - public Volume getVolume() { - return volume; - } - public void setVolume(Volume volume) { - this.volume = volume; - } - public Box getBox() { - return box; - } - public void setBox(Box b) { - box = b; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public Position getPos() { - return pos; - } - public void setPos(Position pos) { - this.pos = pos; - } - public Rotation getRot() { - return rot; - } - public void setRot(Rotation rot) { - this.rot = rot; - } - public LCDDBaseGeometry getMother() { - return mother; - } - public void setMother(LCDDBaseGeometry mother) { - this.mother = mother; - } - public PhysVol getPhysVolume() { - return physVolume; - } - public void setPhysVolume(PhysVol physVolume) { - this.physVolume = physVolume; - } - public boolean isDebug() { - return debug; - } - public List<LCDDBaseGeometry> getDaughters() { - return daughters; - } - public 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; - } - } - - /** * Add to list of objects. * @param geom - object to add. */ - public void add(LCDDBaseGeometry geom) { - lcddGeometries.add(geom); + public void add(LCDDSurveyVolume geom) { + lcddSurveyVolumes.add(geom); } /** @@ -347,63 +79,14 @@ return lcdd; } - public LCDDBaseGeometry getBaseLCDD() { - return baseTrackerGeometry; + public LCDDSurveyVolume getBaseLCDD() { + return baseSurveyVolume; } - /** - * - * 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]> - * - */ - public static class GhostLCDDBaseGeometry extends LCDDBaseGeometry { - - - - /** - * 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(SurveyVolume 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]> - */ - public static class LCDDBaseGeometryVisualization { - protected String visName = ""; - public LCDDBaseGeometryVisualization() {} - public String getVisName() { - return visName; - } - protected void setVisName(String visName) { - this.visName = visName; - } - - - } - - - public 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 visualization for %d LCDD geometry objects \n", getClass().getSimpleName(), lcddSurveyVolumes.size()); + for(SurveyVolumeImpl g : lcddSurveyVolumes) { if(isDebug()) System.out.printf("%s: Set LCDD vis for %s \n", getClass().getSimpleName(), g.getName()); if(g.getName().endsWith("baseplate")) g.setVisName("BasePlateVis"); //else if(g.getName().contains("base")) g.setVisName("BaseVis"); Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaGhostSurveyVolume.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaGhostSurveyVolume.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaGhostSurveyVolume.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,29 @@ +package org.lcsim.geometry.compact.converter; + +/** + * + * Interface to the JAVA converter geometry for the geometry definition. + * In this case no volume is built but can be used as reference in building the geometry. + * @author Per Hansson Adrian <[log in to unmask]> + */ +public class JavaGhostSurveyVolume extends JavaSurveyVolume { + + /** + * 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 object + */ + public JavaGhostSurveyVolume(SurveyVolume base, JavaSurveyVolume mother) { + super(); + if(isDebug()) System.out.printf("%s: constructing JAVA ghost object %s with mother %s\n", this.getClass().getSimpleName(),base.getName(),mother==null?"null":mother.getName()); + setName(base.getName()); + setMother(mother); + mother.addDaughter(this); + setPositionAndRotation(base); + if(isDebug()) System.out.printf("%s: DONE constructing JAVA object %s\n", this.getClass().getSimpleName(),base.getName()); + } + + + +} Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaSurveyVolume.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaSurveyVolume.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/JavaSurveyVolume.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,287 @@ +package org.lcsim.geometry.compact.converter; + +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +import java.util.ArrayList; +import java.util.List; + +import org.lcsim.detector.ILogicalVolume; +import org.lcsim.detector.IPhysicalVolume; +import org.lcsim.detector.IRotation3D; +import org.lcsim.detector.ITranslation3D; +import org.lcsim.detector.LogicalVolume; +import org.lcsim.detector.PhysicalVolume; +import org.lcsim.detector.RotationGeant; +import org.lcsim.detector.Transform3D; +import org.lcsim.detector.Translation3D; +import org.lcsim.detector.material.IMaterial; +import org.lcsim.detector.material.MaterialStore; +import org.lcsim.detector.solids.Box; +import org.lcsim.geometry.util.TransformationUtils; + +/** + * Interface to the JAVA converter geometry for the geometry definition. + * @author Per Hansson Adrian <[log in to unmask]> + */ +public class JavaSurveyVolume { + private boolean debug = false; + private String name; + private Box box= null; + private ILogicalVolume volume = null; + private ITranslation3D pos = null; + private IRotation3D rot = null; + private IPhysicalVolume physVolume = null; + private JavaSurveyVolume mother = null; + public List<JavaSurveyVolume> daughters = new ArrayList<JavaSurveyVolume>(); + private int componentId = -1; + + /** + * Default constructor + */ + public JavaSurveyVolume() { + } + + /** + * Construct a JAVA geometry object from its geometry definition and an already built logical volume. + * This is typically used by the tracking volume. + * @param geomObject - input geometry definition + * @param vol - logical volume + */ + public JavaSurveyVolume(SurveyVolume geomObject, ILogicalVolume vol) { + if(isDebug()) System.out.printf("%s: JavaBaseGeometry %s (given logical volume %s)\n", this.getClass().getSimpleName(),geomObject.getName(),vol.getName()); + // this must be tracking volume. May change in the future and is probably weird to make this requirement here. + if(!geomObject.getName().contains("tracking")) throw new RuntimeException("this constructor is only used with the tracking volume!?"); + setName(geomObject.getName()); + setVolume(vol); + // since it's tracking volume, set the pos and rotation trivially + 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()); + } + + /** + * Construct a JAVA geometry object from its geometry definition. + * @param geomObject - input geometry definition + * @param mother - reference to mother JAVA definition + * @param volumeId - component id number + */ + public JavaSurveyVolume(SurveyVolume geomObject, JavaSurveyVolume mother, int volumeId) { + if(isDebug()) System.out.printf("%s: JavaBaseGeometry %s (volumeID %d, mother %s)\n", this.getClass().getSimpleName(),geomObject.getName(),volumeId,mother==null?"null":mother.getName()); + setName(geomObject.getName()); + setComponentId(volumeId); + setMother(mother); + mother.addDaughter(this); + buildBox(geomObject); + buildVolume(geomObject); + setPositionAndRotation(geomObject); + if(isDebug()) System.out.printf("%s: DONE JavaBaseGeometry %s\n", this.getClass().getSimpleName(),geomObject.getName()); + } + + protected boolean hasCoordinateSystemInfo() { + return pos!=null && rot!=null; + } + + + public void buildPhysVolume() { + if(isDebug()) System.out.printf("%s: build phys volume for %s with mother %s and physical mother %s\n", this.getClass().getSimpleName(),getName(),getMother().getName(),getPhysMother().getName()); + JavaSurveyVolume physMother = getPhysMother(); + setPhysVolume(new PhysicalVolume(new Transform3D(getPos(), getRot()), name, volume, physMother.getVolume(),getComponentId())); + } + protected void buildBox(SurveyVolume base) { + Hep3Vector b = base.getBoxDim(); + b = VecOp.mult(0.5, b); + if(isDebug()) System.out.printf("%s: build box for %s with dimensions %s \n", this.getClass().getSimpleName(),getName(), b); + setBox(new Box(getName() + "Box", b.x(), b.y(), b.z())); + } + protected void buildVolume(SurveyVolume base) { + if(isDebug()) System.out.printf("%s: build volume for %s with material %s\n", this.getClass().getSimpleName(),getName(),base.getMaterial()); + IMaterial material = MaterialStore.getInstance().get(base.getMaterial()); + setVolume(new LogicalVolume(getName() + "_volume", box, material)); + + } + protected void setPositionAndRotation(SurveyVolume base) { + if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); + + // no mother, this must be the world/tracking volume!? + if(base.getMother()==null) throw new RuntimeException("trying to set coordinates w/o mother defined for "+base.getName()); + + // Vector from origin to center of box locally + Hep3Vector box_center_base_local = base.getCenter(); + + // find the physical mother i.e. not a ghost volume and compound transformations to it + JavaSurveyVolume physMother = getPhysMother(); + if(isDebug()) System.out.printf("%s: physical mother to transform to is %s; find the transform to it\n", this.getClass().getSimpleName(),physMother.getName()); + Transform3D trf = HPSTrackerBuilder.getTransform(base.getCoord().getTransformation(),base.getMother(),physMother.getName()); + if(isDebug()) System.out.printf("%s: found transform to physical mother \n%s\n\n", this.getClass().getSimpleName(),trf.toString()); + + // find the position of the center in the physical mother coord + Hep3Vector box_center_base = trf.transformed(box_center_base_local); + + // find the position of the center of the box in the mother coordinate system, make sure to use the physical mother coordinates + if(isDebug()) System.out.printf("%s: find center of box in physical mother coord %s \n", this.getClass().getSimpleName(),physMother.getName()); + // hack since my getTransform function needs a mother TODO Fix this! + SurveyVolume gm = base; + if(isDebug()) System.out.printf("%s: look for physical mother %s starting from mother %s \n", this.getClass().getSimpleName(),physMother.getName(),gm.getMother()!=null?gm.getMother().getName():"-- no mother --"); + while((gm=gm.getMother()).getName()!=physMother.getName()) { + if(isDebug()) System.out.printf("%s: gm is %s \n", this.getClass().getSimpleName(),gm.getName()); + //gm = gm.getMother(); + } + if(isDebug()) System.out.printf("%s: found physical mother %s with center at %s \n", this.getClass().getSimpleName(),gm.getName(), gm.getCenter()); + + Hep3Vector mother_center = gm.getCenter(); + + // now calculate the position of this box center in the mother LCDD coordinates + Hep3Vector box_center = VecOp.sub(box_center_base, mother_center); + + //Find LCDD Euler rotation angles from coordinate system unit vectors + //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 base_u = base.getCoord().u(); + Hep3Vector base_v = base.getCoord().v(); + Hep3Vector base_w = base.getCoord().w(); + if(isDebug()) System.out.printf("%s: unit vectors in mother coord: %s, %s, %s\n", this.getClass().getSimpleName(),base_u.toString(),base_v.toString(),base_w.toString()); + 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())) { + if(isDebug()) System.out.printf("%s: Need to get unit vectors in physical mother %s coord system\n", this.getClass().getSimpleName(),physMother.getName()); + Transform3D trf_mother = HPSTrackerBuilder.getTransform(base.getMother().getCoord().getTransformation(),base.getMother().getMother(),physMother.getName()); + if(isDebug()) System.out.printf("%s: found transform from mother to physical mother \n%s\n", this.getClass().getSimpleName(),trf_mother.toString()); + //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)); + base_u = VecOp.unit(trf_mother.rotated(base_u)); + base_v = VecOp.unit(trf_mother.rotated(base_v)); + base_w = VecOp.unit(trf_mother.rotated(base_w)); + + } else { + if(isDebug()) System.out.printf("%s: mother and physical mother is the same so unit vectors didn't change\n",getClass().getSimpleName()); + } + + if(isDebug()) { + if(isDebug()) System.out.printf("%s: final unit vectors to get Cardan angles from : \n%s, %s, %s -> %s, %s, %s \n", + this.getClass().getSimpleName(), + base_u.toString(),base_v.toString(),base_w.toString(), + 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 = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w); + + + // 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())); + + 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()==null?" <no mother> ":mother_center.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 = HPSTrackerBuilder.transformToTracking(box_center_base_local, base); + System.out.printf("%s: box_center_tracking_xcheck %s for %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString(),base.getName()); + } + + } + + /** + * Find the first non-ghost volume among parents. + * @return mother object + */ + public JavaSurveyVolume getPhysMother() { + //if(isDebug()) System.out.printf("%s: finding physical mother to %s\n", this.getClass().getSimpleName(), getName()); + if(mother==null) throw new RuntimeException("Trying to get phys mother but there is no mother!"); + if(mother instanceof JavaGhostSurveyVolume) { + return mother.getPhysMother(); + } else { + //if(isDebug()) System.out.printf("%s: found a non-ghost volume: %s\n", this.getClass().getSimpleName(), mother.getName()); + return mother; + } + } + + + public ILogicalVolume getVolume() { + return volume; + } + protected void setVolume(ILogicalVolume volume) { + this.volume = volume; + } + protected Box getBox() { + return box; + } + protected void setBox(Box b) { + box = b; + } + public String getName() { + return name; + } + protected void setName(String name) { + this.name = name; + } + protected ITranslation3D getPos() { + return pos; + } + protected void setPos(ITranslation3D iTranslation3D) { + this.pos = iTranslation3D; + } + protected IRotation3D getRot() { + return rot; + } + protected void setRot(IRotation3D iRotation3D) { + this.rot = iRotation3D; + } + public JavaSurveyVolume getMother() { + return mother; + } + protected void setMother(JavaSurveyVolume mother) { + this.mother = mother; + } + public IPhysicalVolume getPhysVolume() { + return physVolume; + } + protected void setPhysVolume(PhysicalVolume physVolume) { + this.physVolume = physVolume; + } + public boolean isDebug() { + return debug; + } + + public List<JavaSurveyVolume> getDaughters() { + return daughters; + } + + protected void addDaughter(JavaSurveyVolume o) { + getDaughters().add(o); + } + + public int getComponentId() { + return componentId; + } + + public void setComponentId(int componentId) { + this.componentId = componentId; + } + + public String toString() { + String s = "JavaBaseGeometry " + getName() + "\n"; + if(getPos()!=null && getRot()!=null) { + s += "Position: " + getPos().toString() + "\n"; + s += "Rotation: " + getRot().toString() + "\n"; + } else { + s+= " - no position/rotation info -\n"; + } + return s; + } + +} Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDGhostSurveyVolume.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDGhostSurveyVolume.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDGhostSurveyVolume.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,29 @@ +package org.lcsim.geometry.compact.converter; + +/** + * + * 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]> + * + */ +public class LCDDGhostSurveyVolume extends LCDDSurveyVolume { + + + + /** + * 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 LCDDGhostSurveyVolume(SurveyVolume base, LCDDSurveyVolume 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()); + } + +} Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDSurveyVolume.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDSurveyVolume.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/LCDDSurveyVolume.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,264 @@ +package org.lcsim.geometry.compact.converter; + +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.jdom.JDOMException; +import org.lcsim.detector.Transform3D; +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.Volume; +import org.lcsim.geometry.util.TransformationUtils; + +/** + * Interface to the LCDD converter geometry for the geometry definition. + * + * @author Per Hansson Adrian <[log in to unmask]> + */ +public class LCDDSurveyVolume extends SurveyVolumeImpl { + Box box= null; + Volume volume = null; + private Position pos = null; + private Rotation rot = null; + private PhysVol physVolume = null; + LCDD lcdd = null; + private LCDDSurveyVolume mother = null; + protected Map<String,Integer> physVolId = null; + public List<LCDDSurveyVolume> daughters = new ArrayList<LCDDSurveyVolume>(); + /** + * Default constructor + */ + public LCDDSurveyVolume() { + } + + /** + * 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 LCDDSurveyVolume(SurveyVolume base, Volume volume) { + super(); + if(isDebug()) System.out.printf("%s: constructing LCDD object %s with given volume name %s\n", this.getClass().getSimpleName(),base.getName(),volume.getName()); + 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 = 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 %s\n", this.getClass().getSimpleName(),base.getName()); + } + + /** + * 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 LCDDSurveyVolume(SurveyVolume base, LCDD lcdd, LCDDSurveyVolume 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()); + } + + + public 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())); + } + public void buildBox(SurveyVolume 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())); + } + public void buildVolume(SurveyVolume 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(); + } + } + + + public void setPositionAndRotation(SurveyVolume base) { + if(isDebug()) System.out.printf("%s: set position and rotation for volume %s\n", this.getClass().getSimpleName(),getName()); + + // 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(base.getMother()==null) throw new RuntimeException("trying to set coordinates w/o mother defined for "+base.getName()); + + // Vector from origin to center of box locally + Hep3Vector box_center_base_local = base.getCenter(); + + //translate to the mother coordinate system + LCDDSurveyVolume physMother = getPhysMother(); + if(isDebug()) System.out.printf("%s: physical mother to transform to is %s; find the transform to it\n", this.getClass().getSimpleName(),physMother.getName()); + Transform3D trf = HPSTrackerBuilder.getTransform(base.getCoord().getTransformation(),base.getMother(),physMother.getName()); + if(isDebug()) System.out.printf("%s: found transform to physical mother \n%s\n\n", this.getClass().getSimpleName(),trf.toString()); + + // find the position of the center in the physical mother coord + Hep3Vector box_center_base = trf.transformed(box_center_base_local); + + // find the position of the center of the box in the mother coordinate system, make sure to use the physical mother coordinates + if(isDebug()) System.out.printf("%s: find center of box in physical mother coord %s \n", this.getClass().getSimpleName(),physMother.getName()); + // hack since my getTransform function needs a mother TODO Fix this! + SurveyVolume gm = base; + if(isDebug()) System.out.printf("%s: look for physical mother %s starting from mother %s \n", this.getClass().getSimpleName(),physMother.getName(),gm.getMother()!=null?gm.getMother().getName():"-- no mother --"); + while((gm=gm.getMother()).getName()!=physMother.getName()) { + if(isDebug()) System.out.printf("%s: gm is %s \n", this.getClass().getSimpleName(),gm.getName()); + //gm = gm.getMother(); + } + if(isDebug()) System.out.printf("%s: found physical mother %s with center at %s \n", this.getClass().getSimpleName(),gm.getName(), gm.getCenter()); + + Hep3Vector mother_center = gm.getCenter(); + + // find the position of the center in the mother coord + Hep3Vector box_center = VecOp.sub(box_center_base, mother_center); + + //Find LCDD Euler rotation angles from coordinate system unit vectors + //Note that this has to be rotation wrt to physical mother and not just mother as normally is the case + 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 base_u = base.getCoord().u(); + Hep3Vector base_v = base.getCoord().v(); + Hep3Vector base_w = base.getCoord().w(); + if(isDebug()) System.out.printf("%s: unit vectors in mother coord: %s, %s, %s\n", this.getClass().getSimpleName(),base_u.toString(),base_v.toString(),base_w.toString()); + 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())) { + if(isDebug()) System.out.printf("%s: Need to get unit vectors in physical mother %s coord system\n", this.getClass().getSimpleName(),physMother.getName()); + Transform3D trf_mother = HPSTrackerBuilder.getTransform(base.getMother().getCoord().getTransformation(),base.getMother().getMother(),physMother.getName()); + if(isDebug()) System.out.printf("%s: found transform from mother to physical mother \n%s\n", this.getClass().getSimpleName(),trf_mother.toString()); + //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)); + base_u = VecOp.unit(trf_mother.rotated(base_u)); + base_v = VecOp.unit(trf_mother.rotated(base_v)); + base_w = VecOp.unit(trf_mother.rotated(base_w)); + + } else { + if(isDebug()) System.out.printf("%s: mother and physical mother is the same so unit vectors didn't change\n",getClass().getSimpleName()); + } + + if(isDebug()) { + if(isDebug()) System.out.printf("%s: final unit vectors to get Cardan angles from : \n%s, %s, %s -> %s, %s, %s \n", + this.getClass().getSimpleName(), + base_u.toString(),base_v.toString(),base_w.toString(), + 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 = TransformationUtils.getCardanAngles(base_u, base_v, base_w, unit_u, unit_v, unit_w); + + + // Create the LCDD position + setPos(new Position(getName() + "_position",box_center.x(), box_center.y(), box_center.z())); + + 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(), mother_center.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 = HPSTrackerBuilder.transformToTracking(box_center_base_local, base); + System.out.printf("%s: box_center_tracking_xcheck %s\n", this.getClass().getSimpleName(), box_center_tracking_xcheck.toString()); + } + + } + /** + * Find the first non-ghost volume among parents. + * @return mother object + */ + public LCDDSurveyVolume getPhysMother() { + //if(isDebug()) System.out.printf("%s: finding physical mother to %s\n", this.getClass().getSimpleName(), getName()); + if(mother==null) throw new RuntimeException("Trying to get phys mother but there is no mother!"); + if(mother instanceof LCDDGhostSurveyVolume) { + return mother.getPhysMother(); + } else { + //if(isDebug()) System.out.printf("%s: found a non-ghost volume: %s\n", this.getClass().getSimpleName(), mother.getName()); + return mother; + } + } + + public Volume getVolume() { + return volume; + } + public void setVolume(Volume volume) { + this.volume = volume; + } + public Box getBox() { + return box; + } + public void setBox(Box b) { + box = b; + } + public Position getPos() { + return pos; + } + public void setPos(Position pos) { + this.pos = pos; + } + public Rotation getRot() { + return rot; + } + public void setRot(Rotation rot) { + this.rot = rot; + } + public LCDDSurveyVolume getMother() { + return mother; + } + public void setMother(LCDDSurveyVolume mother) { + this.mother = mother; + } + public PhysVol getPhysVolume() { + return physVolume; + } + public void setPhysVolume(PhysVol physVolume) { + this.physVolume = physVolume; + } + public List<LCDDSurveyVolume> getDaughters() { + return daughters; + } + public void addDaughter(LCDDSurveyVolume o) { + getDaughters().add(o); + } + public String toString() { + String s = getClass().getSimpleName() +": " + 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; + } +} Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeImpl.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeImpl.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeImpl.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,34 @@ +package org.lcsim.geometry.compact.converter; + +public abstract class SurveyVolumeImpl extends SurveyVolumeVisualization { + + private boolean debug = true; + private String name; + + public SurveyVolumeImpl() { + super(); + } + + public abstract void buildPhysVolume(); + + public abstract void buildBox(SurveyVolume base); + + public abstract void buildVolume(SurveyVolume base); + + public abstract void setPositionAndRotation(SurveyVolume base); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isDebug() { + return debug; + } + + public abstract String toString(); + +} Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeVisualization.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeVisualization.java (added) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/SurveyVolumeVisualization.java Fri Oct 31 12:37:29 2014 @@ -0,0 +1,20 @@ +package org.lcsim.geometry.compact.converter; + +/** + * + * LCDD geometry visualization information + * + * @author Per Hansson Adrian <[log in to unmask]> + */ +public class SurveyVolumeVisualization { + protected String visName = ""; + public SurveyVolumeVisualization() {} + public String getVisName() { + return visName; + } + protected void setVisName(String visName) { + this.visName = visName; + } + + +} Modified: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java ============================================================================= --- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java (original) +++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTestRunTracker2014.java Fri Oct 31 12:37:29 2014 @@ -14,8 +14,8 @@ import org.lcsim.geometry.compact.converter.HPSTestRunTracker2014LCDDBuilder; import org.lcsim.geometry.compact.converter.HPSTrackerBuilder; import org.lcsim.geometry.compact.converter.HPSTrackerLCDDBuilder; -import org.lcsim.geometry.compact.converter.HPSTrackerLCDDBuilder.GhostLCDDBaseGeometry; -import org.lcsim.geometry.compact.converter.HPSTrackerLCDDBuilder.LCDDBaseGeometry; +import org.lcsim.geometry.compact.converter.LCDDGhostSurveyVolume; +import org.lcsim.geometry.compact.converter.LCDDSurveyVolume; import org.lcsim.geometry.compact.converter.SurveyCoordinateSystem; import org.lcsim.geometry.compact.converter.lcdd.util.Box; import org.lcsim.geometry.compact.converter.lcdd.util.LCDD; @@ -154,7 +154,7 @@ // Reference to the top level object in the builder class // In this case it is the base volume holding the entire tracker - LCDDBaseGeometry lcddObj = builder.getBaseLCDD(); + LCDDSurveyVolume lcddObj = (LCDDSurveyVolume) builder.getBaseLCDD(); // Add the base volume and all its daughters to the LCDD addToLCDD(lcddObj,lcdd,sd); @@ -170,7 +170,7 @@ * @param lcddObj to add * @param lcdd file */ - private void addToLCDD(LCDDBaseGeometry lcddObj, LCDD lcdd, SensitiveDetector sd) { + private void addToLCDD(LCDDSurveyVolume lcddObj, LCDD lcdd, SensitiveDetector sd) { if(_debug) System.out.printf("%s: adding %s to LCDD\n", getClass().getSimpleName(),lcddObj.getName()); @@ -180,7 +180,7 @@ if(doAdd) { // only world/tracking volume can be ghost here?! - if(lcddObj instanceof GhostLCDDBaseGeometry ) { + if(lcddObj instanceof LCDDGhostSurveyVolume ) { System.out.printf("%s: trying to add a ghost volume: %s ??\n", getClass().getSimpleName(),lcddObj.getName()); throw new RuntimeException("adding a ghost volume (" + lcddObj.getName() + ") to LCDD is not allowed."); } @@ -206,7 +206,7 @@ // add daughters if(_debug) System.out.printf("%s: add %d daughters to %s\n", getClass().getSimpleName(),lcddObj.getDaughters().size(),lcddObj.getName()); - for(LCDDBaseGeometry daughter : lcddObj.getDaughters()) { + for(LCDDSurveyVolume daughter : lcddObj.getDaughters()) { addToLCDD(daughter,lcdd, sd); } @@ -226,7 +226,7 @@ * Set properties of the physical volume. * @param geometryObject */ - private void setPhysicalVolumeProperties(LCDDBaseGeometry geometryObject, SensitiveDetector sd) throws DataConversionException { + private void setPhysicalVolumeProperties(LCDDSurveyVolume geometryObject, SensitiveDetector sd) throws DataConversionException { if(_debug) System.out.printf("%s: setPhysVolumeProperties for name %s\n", getClass().getSimpleName(),geometryObject.getName()); ######################################################################## 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