Commit in projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact on MAIN
HPSTestRunTracker2014JavaBuilder.java+163-433289 -> 3290
Fixing the local storage of DEs and fixing relation bw physical mother and mother.

projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact
HPSTestRunTracker2014JavaBuilder.java 3289 -> 3290
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014JavaBuilder.java	2014-09-02 05:05:09 UTC (rev 3289)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTestRunTracker2014JavaBuilder.java	2014-09-02 05:07:43 UTC (rev 3290)
@@ -10,11 +10,17 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
+
 import org.lcsim.detector.DetectorElement;
+import org.lcsim.detector.DetectorElementStore;
 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.ITransform3D;
+import org.lcsim.detector.ITranslation3D;
 import org.lcsim.detector.LogicalVolume;
 import org.lcsim.detector.PhysicalVolume;
 import org.lcsim.detector.Rotation3D;
@@ -23,10 +29,12 @@
 import org.lcsim.detector.Translation3D;
 import org.lcsim.detector.identifier.ExpandedIdentifier;
 import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
 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.compact.converter.lcdd.HPSTestRunTracker2014;
 import org.lcsim.geometry.compact.converter.lcdd.HPSTestRunTracker2014Builder;
@@ -80,9 +88,9 @@
 	
 	/**
 	 * Build the JAVA geometry objects.
-	 * @param worldVolume - the reference volume.
+	 * @param trackingVolume - the reference volume.
 	 */
-	protected void build(ILogicalVolume worldVolume) {
+	protected void build(ILogicalVolume trackingVolume) {
 		
 		if(isDebug()) System.out.printf("%s: build the JAVA geometry objects\n", getClass().getSimpleName());
 		
@@ -90,11 +98,9 @@
 		java_objects = new ArrayList<JavaBaseGeom>();
 
 		// 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.
-		JavaBaseGeom tracking = new GhostJavaBaseGeom(getItem(TrackingBase.class), worldVolume);
-		add(tracking);
-
-		baseTrackerGeometry = new GhostJavaBaseGeom(getItem(Base.class), tracking);
+		JavaBaseGeom trackingGeometry = new JavaBaseGeom(getItem(TrackingBase.class), trackingVolume);
+		add(trackingGeometry);
+		baseTrackerGeometry = new GhostJavaBaseGeom(getItem(Base.class), trackingGeometry);
 		add(baseTrackerGeometry);
 		JavaBaseGeom basePlateGeometry = new GhostJavaBaseGeom(getItem(BasePlate.class), baseTrackerGeometry);
 		add(basePlateGeometry);
@@ -124,7 +130,7 @@
 				m.print();
 			}
 
-			// Find the mother among the LCDD objects using its name, should probably have a better way...
+			// Find the mother among the objects using its name, should probably have a better way...
 			String name_mother = m.getMother().getName();
 			JavaBaseGeom mother = null;
 			for(JavaBaseGeom g : java_objects) {
@@ -161,7 +167,7 @@
 	private void addModule(ModuleBundle bundle, JavaBaseGeom mother) {
 		
 		if(isDebug()) {
-			System.out.printf("%s: addModule:\n",this.getClass().getSimpleName());
+			System.out.printf("%s: addModule %s containing:\n",this.getClass().getSimpleName(), bundle.module.getName());
 			bundle.print();
 		}
 		
@@ -173,6 +179,11 @@
 		addHalfModule(bundle.halfModuleAxial,lcddM);
 		addHalfModule(bundle.halfModuleStereo,lcddM);
 		
+		
+		if(isDebug()) {
+			System.out.printf("%s: DONE addModule %s \n",this.getClass().getSimpleName(), bundle.module.getName());
+		}
+		
 	}
 	
 	
@@ -190,15 +201,16 @@
 		JavaBaseGeom lcddHM = new JavaBaseGeom(bundle.halfModule, mother,oldCompactModuleId);
 		add(lcddHM);
 		
-		//TODO find the sensor id, this needs to be fixed.
-		int sensorNumber = mother.getComponentId();
+		// ComponentNumber is taken from old geometry where it is simply a counter when adding the xml daughters to the TestRunModule.
+		// It is simply 0 for sensor and 1 for carbon fiber in the old geometry 
+		int componentNumber = bundle.sensor.getId();
 
 		// create the sensor
-		JavaBaseGeom lcddS = new JavaBaseGeom(bundle.sensor, lcddHM, sensorNumber);
+		JavaBaseGeom lcddS = new JavaBaseGeom(bundle.sensor, lcddHM, componentNumber);
 		add(lcddS);
 
 		// create the active sensor
-		JavaBaseGeom lcddAS = new JavaBaseGeom(bundle.activeSensor, lcddS, sensorNumber);
+		JavaBaseGeom lcddAS = new JavaBaseGeom(bundle.activeSensor, lcddS, componentNumber);
 		add(lcddAS);
 		
 	}
@@ -241,7 +253,7 @@
 	protected static class GhostJavaBaseGeom extends JavaBaseGeom {
 
 		/**
-		 * Initialize this object with a known volume and no mother. Typically the world volume would use this.
+		 * Initialize this object with a known volume and no mother. Typically the tracking volume would use this.
 		 * @param base - object used to get geometry definitions
 		 * @param vol - given volume
 		 */
@@ -282,8 +294,8 @@
 		private String name;
 		private Box box= null;
 		private ILogicalVolume volume = null;
-		private Translation3D pos = null;
-		private Rotation3D rot = null;
+		private ITranslation3D pos = null;
+		private IRotation3D rot = null;
 		private IPhysicalVolume physVolume = null;
 		private JavaBaseGeom mother = null;
 		public List<JavaBaseGeom> daughters = new ArrayList<JavaBaseGeom>();
@@ -294,6 +306,13 @@
 		 */
 		public JavaBaseGeom() {
 		}
+
+		public JavaBaseGeom(BaseGeometry geomObject, ILogicalVolume vol) {
+			if(isDebug()) System.out.printf("%s: constructing JAVA object %s with volume (name %s)\n", this.getClass().getSimpleName(),geomObject.getName(),vol.getName());
+			setName(geomObject.getName());
+			setVolume(vol);
+			if(isDebug()) System.out.printf("%s: DONE constructing JAVA object %s with volume (name %s)\n", this.getClass().getSimpleName(),geomObject.getName(),vol.getName());
+		}
 		
 		/**
 		 * Construct a JAVA geometry object from its geometry definition. 
@@ -316,8 +335,23 @@
 
 		
 		protected void buildPhysVolume() {
-			if(isDebug()) System.out.printf("%s: build phys volume for %s with mother %s \n", this.getClass().getSimpleName(),getName(),getMother().getName());
-			setPhysVolume(new PhysicalVolume(new Transform3D(pos, rot), name, volume, getMother().getVolume(),getComponentId()));
+			if(isDebug()) System.out.printf("%s: build phys volume for %s\n", this.getClass().getSimpleName(),getName());
+			if(isDebug()) System.out.printf("%s: mother %s \n", this.getClass().getSimpleName(),getMother().getName());
+			// The physical volume needs to be built with a physical mother i.e. anot a ghost volume
+			// Find the closest physical mother
+			JavaBaseGeom physMother =  getPhysMother();
+			if(isDebug()) System.out.printf("%s: physical mother %s \n", this.getClass().getSimpleName(),physMother.getName());
+			// similarly, if the mother is not the physical mother the positions and rotations of the 
+			// mother needs to be updated
+			Transform3D tOld = new Transform3D(getPos(), getRot());
+			if(isDebug()) System.out.printf("%s: transform before update of transform to physical mother\n%s\n", this.getClass().getSimpleName(),tOld.toString());
+			ITransform3D t = getParentTransform(tOld, getMother(), physMother.getName());
+			setPos(t.getTranslation());
+			setRot(t.getRotation());
+			Transform3D tNew = new Transform3D(getPos(), getRot());
+			if(isDebug()) System.out.printf("%s: transform after update of transform to physical mother\n%s\n", this.getClass().getSimpleName(),tNew.toString());
+			// TODO this seems dangerous to change it here, should this be done in the generic builder somehow?			
+			setPhysVolume(new PhysicalVolume(tNew, name, volume, physMother.getVolume(),getComponentId()));
 		}
 		protected void buildBox(BaseGeometry base) {
 			if(isDebug()) System.out.printf("%s: build box for %s\n", this.getClass().getSimpleName(),getName());
@@ -370,6 +404,23 @@
 			}
 			
 		}
+
+		/**
+		 * Find the first non-ghost volume among parents.  
+		 * @return mother object
+		 */
+		public JavaBaseGeom 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;
+			}
+		}
+		
+		
 		protected ILogicalVolume getVolume() {
 			return volume;
 		}
@@ -388,17 +439,17 @@
 		protected void setName(String name) {
 			this.name = name;
 		}
-		protected Translation3D getPos() {
+		protected ITranslation3D getPos() {
 			return pos;
 		}
-		protected void setPos(Translation3D pos) {
-			this.pos = pos;
+		protected void setPos(ITranslation3D iTranslation3D) {
+			this.pos = iTranslation3D;
 		}
-		protected Rotation3D getRot() {
+		protected IRotation3D getRot() {
 			return rot;
 		}
-		protected void setRot(Rotation3D rot) {
-			this.rot = rot;
+		protected void setRot(IRotation3D iRotation3D) {
+			this.rot = iRotation3D;
 		}
 		protected JavaBaseGeom getMother() {
 			return mother;
@@ -434,43 +485,112 @@
 
 	}
 	
-	// Find detector elements
-	// I could keep a single list of elements for all types since 
-	// the search is done using idenitifier which should be unique. 
-	// But it looks like the module DE has the same expanded ID as the layer
-	// since the module ID is saved not inside the ID?
-	// TODO Jeremy, is this correct?
-	protected IDetectorElement getLayerDetectorElement(IExpandedIdentifier layerPosId) {
-		IDetectorElement element = null;
-		for(IDetectorElement e : layerDetectorElements) {
-			if(e.getExpandedIdentifier().match(layerPosId)==0) {
-				//check that only one was found
+	
+
+	public Hep3Vector transformToMotherCoord(Hep3Vector vec, JavaBaseGeom mother, String targetMotherName) {
+		if(isDebug()) System.out.printf("transformToMotherCoord vec %s mother %s target %s\n", vec.toString(), mother.name, targetMotherName);
+		if(mother.name.equals(targetMotherName)) {
+			if(isDebug()) System.out.printf(String.format("found the transformed vec %s\n", vec.toString()));
+			return vec;
+		} else {
+			if(mother.name.equals("trackingVolume")) {
+				if(isDebug()) System.out.print("reached tracking volume. return null?!\n");
+				return null;
+			}
+
+			Transform3D trans = new Transform3D(mother.pos, mother.rot);
+			Hep3Vector vec_t = trans.transformed(vec);
+			if(isDebug()) System.out.print("continue searching\n");
+			return transformToMotherCoord(vec_t, mother.mother, targetMotherName);
+		}
+		
+	}
+
+	
+	/**
+	 * Find the transform to a given parent volume.  
+	 * @param t transformation of the object. 
+	 * @param mother of the object
+	 * @param targetMotherName is the name of the parent volume to transform to.
+	 * @return translation to the target mother volume.
+	 */
+	public static ITransform3D getParentTransform(Transform3D t, JavaBaseGeom mother, String targetMotherName) {
+		boolean debug = true;
+		if(mother==null) throw new RuntimeException("Trying to get mother transform but there is no mother?!");
+		if(debug) System.out.printf("getParentTransform for mother %s target mother %s with current transform\n%s\n",mother.getName(), targetMotherName, t.toString());
+		if(mother.getName().equals(targetMotherName)) {
+			if(debug) System.out.printf("found the target object\n");
+			return t; 
+		} else {
+			// Compound the transforms
+			ITranslation3D p = mother.getPos();
+			IRotation3D r = mother.getRot();
+			if(p==null) throw new RuntimeException("cannot compound transform since the mother " + mother.getName() + " has no translation!?");
+			if(r==null) throw new RuntimeException("cannot compound transform since the mother " + mother.getName() + " has no rotation!?");
+			Transform3D tM = new Transform3D(p, r);
+			if(debug) System.out.printf("add transform\n%s\n",tM.toString());
+			t.multiplyBy(tM);
+			if(debug) System.out.printf("resulting transform\n%s\n",((Transform3D)t).toString());
+			if(debug) System.out.printf("continue searching\n");
+			return getParentTransform(t, mother.getMother(), targetMotherName);
+		}
+	}
+	
+	
+	
+	
+
+	// This finds specific type. I would like to use the ID for this but can't, I think.
+	// TODO there must be a factory instance to do this
+	public SiTrackerModule getModuleDetectorElement(SiTrackerModule testElement) {
+		if(isDebug()) System.out.printf("%s: getModuleDetectorElement for module  %s path: \"%s\"\n", this.getClass().getSimpleName(),testElement.getName(),testElement.getGeometry().getPathString());
+		SiTrackerModule element = null;
+		for(IDetectorElement e : moduleDetectorElements) {
+			SiTrackerModule m = (SiTrackerModule) e;
+			if(isDebug()) System.out.printf("%s: compare with module  %s path: %s\"%s\" \n", this.getClass().getSimpleName(),m.getName(),m.getGeometry().getPathString());
+			if(m.getGeometry().getPathString().equals(testElement.getGeometry().getPathString())) {
 				if(element!=null) throw new RuntimeException("two DE sharing extended ID?");
-				element = e;
+				if(isDebug()) System.out.printf("%s: found it\n", this.getClass().getSimpleName());
+				element = m;
 			}
 		}
 		return element;
 	}
-	protected IDetectorElement getModuleDetectorElement(IExpandedIdentifier layerPosId) {
+
+	
+	// Find detector elements
+	// TODO This should be using some global geometry code like DetectorElementStore?
+	protected IDetectorElement getLayerDetectorElement(IExpandedIdentifier expId) {
 		IDetectorElement element = null;
-		for(IDetectorElement e : moduleDetectorElements) {
-			if(e.getExpandedIdentifier().match(layerPosId)==0) {
+		if(isDebug()) System.out.printf("%s: search among %d layer DEs\n", this.getClass().getSimpleName(), layerDetectorElements.size());
+		for(IDetectorElement e : layerDetectorElements) {
+			if(isDebug()) System.out.printf("%s: test %s\n", this.getClass().getSimpleName(),e.getName());
+			ExpandedIdentifier eId = (ExpandedIdentifier) e.getExpandedIdentifier();
+			if(eId.equals(expId)) { // TODO order matters as expId is an interface without that function!?
 				//check that only one was found
 				if(element!=null) throw new RuntimeException("two DE sharing extended ID?");
+				if(isDebug()) System.out.printf("%s: found it\n", this.getClass().getSimpleName());
 				element = e;
 			}
+
 		}
 		return element;
 	}
+
+
 	protected void addLayerDetectorElement(IDetectorElement e) {
-		if(getLayerDetectorElement(e.getExpandedIdentifier()) != null) 
+		IExpandedIdentifier expId = e.getExpandedIdentifier();
+		if(getLayerDetectorElement(expId) != null) 
 			throw new RuntimeException("Trying to add an existing layer detector element.");
 		layerDetectorElements.add(e);
 	}
+	
 	protected void addModuleDetectorElement(IDetectorElement e) {
-		if(getLayerDetectorElement(e.getExpandedIdentifier()) != null) 
-			throw new RuntimeException("Trying to add an existing layer detector element.");
-		moduleDetectorElements.add(e);
+		if(!(e instanceof SiTrackerModule)) 
+			throw new RuntimeException("Trying to add an existing module of wrong type.");
+		if(getModuleDetectorElement((SiTrackerModule) e) != null) 
+			throw new RuntimeException("Trying to add an already existing module detector element.");
+		layerDetectorElements.add(e);
 	}
 	
 
SVNspam 0.1


Use REPLY-ALL to reply to list

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