Print

Print


Author: phansson
Date: Fri Oct 31 16:08:02 2014
New Revision: 3407

Log:
Abstracting out converters

Added:
    projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTracker2014ConverterBase.java
    projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTracker2014Base.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/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 16:08:02 2014
@@ -4,419 +4,27 @@
 package org.lcsim.detector.converter.compact;
 
 import org.jdom.Element;
-import org.lcsim.detector.DetectorElement;
-import org.lcsim.detector.DetectorElementStore;
-import org.lcsim.detector.DetectorIdentifierHelper;
-import org.lcsim.detector.DetectorIdentifierHelper.SystemMap;
-import org.lcsim.detector.IDetectorElement;
-import org.lcsim.detector.IGeometryInfo;
-import org.lcsim.detector.ILogicalVolume;
-import org.lcsim.detector.IPhysicalVolume;
-import org.lcsim.detector.PhysicalVolume;
-import org.lcsim.detector.Transform3D;
-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.identifier.IIdentifierHelper;
-import org.lcsim.detector.material.IMaterial;
-import org.lcsim.detector.material.MaterialStore;
-import org.lcsim.detector.tracker.silicon.HpsSiSensor;
-import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
-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.JavaSurveyVolume;
-import org.lcsim.geometry.subdetector.HPSTestRunTracker2014;
 
 /**
  * Converters the HPSTestRunTracker2014 compact description into Java runtime objects
  * @author Per Hansson Adrian <[log in to unmask]>
  *
  */
-public class HPSTestRunTracker2014Converter extends AbstractSubdetectorConverter {
-
-	private boolean _debug = true; 
-	private IMaterial trackingMaterial = null;
-	private static HPSTrackerJavaBuilder builder;
-	
-	public IIdentifierHelper makeIdentifierHelper(Subdetector subdetector, SystemMap systemMap) {
-		return new SiTrackerIdentifierHelper(subdetector.getDetectorElement(), makeIdentifierDictionary(subdetector), systemMap);
-	}
-	 
-	
-	public Class getSubdetectorType() {
-		return HPSTestRunTracker2014.class;
-	}
+public class HPSTestRunTracker2014Converter extends HPSTracker2014ConverterBase {
 
 	public HPSTestRunTracker2014Converter() {
 		super();
-		
-		
-
 	}
 	
-	public void convert(Subdetector subdet, Detector detector) {
-		
-		if(_debug) System.out.printf("%s: convert %s \n", getClass().getSimpleName(), subdet.getName());
-		
-		
-		// check tracking material
-		trackingMaterial = MaterialStore.getInstance().get("Vacuum");
-		//trackingMaterial = MaterialStore.getInstance().get("Vacuum");
-		if(trackingMaterial==null) {
-			System.out.printf("%s: error the tracking material was not found!\n", this.getClass().getSimpleName());
-			System.exit(1);
-		}
-		
-		// Get XML node for this subdetector.
-        Element node = subdet.getNode();
-        
-		 // Get the tracking volume for module placement.
-        ILogicalVolume trackingVolume = detector.getTrackingVolume().getLogicalVolume();
-		
-        
-        
-        // build the local geometry
-        builder = new HPSTestRunTracker2014JavaBuilder(_debug,node);
-        
-        
-        // Set subdetector for later reference
-        builder.setSubdetector(subdet);
-        
-        // Get ID helper and dictionary for subdetector.
-        builder.setDetectorIdentifierHelper( (DetectorIdentifierHelper) subdet.getDetectorElement().getIdentifierHelper());
-        builder.setIdentifierDictionary(subdet.getDetectorElement().getIdentifierHelper().getIdentifierDictionary());
-        
-        
-        
-        // Build the detector here
-        // setup and build the LCDD geometry
-        if(_debug) System.out.printf("%s: setup and build the JAVA geometry\n", getClass().getSimpleName());
-
-        builder.build(trackingVolume);
-
-        if(_debug) System.out.printf("%s: DONE setup and build the JAVA geometry\n", getClass().getSimpleName());
-
-        setupPhysicalVolumes();
-        
-        if(_debug) {
-        	System.out.printf("%s: Print all %d detector elements in store\n", getClass().getSimpleName(),DetectorElementStore.getInstance().size());
-        	for(IDetectorElement e : DetectorElementStore.getInstance()) {
-        		System.out.printf("%s: Name: %s \n", getClass().getSimpleName(),e.getName());
-        		if(e.hasGeometryInfo()) {
-        			System.out.printf("%s: Position: %s \n", getClass().getSimpleName(),e.getGeometry().getPosition());
-        			System.out.printf("%s: LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getLocalToGlobal()).toString());
-        			//System.out.printf("%s: GlobalToLocal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getGlobalToLocal()).toString());
-        			IGeometryInfo info = e.getGeometry();
-        			if(info!=null) {
-        				while((info=info.parentGeometry())!=null) {
-        					System.out.printf("%s: Parent geometry DE: %s \n", getClass().getSimpleName(),info.getDetectorElement().getName());
-        					System.out.printf("%s: Parent Position: %s \n", getClass().getSimpleName(),info.getPosition());
-        					System.out.printf("%s: Parent LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)info.getLocalToGlobal()).toString());
-
-        				}
-        			}
-        		}
-        	}
-        }
-	}
-
+	/* (non-Javadoc)
+	 * @see org.lcsim.detector.converter.compact.HPSTracker2014ConverterBase#initializeBuilder(org.jdom.Element)
+	 */
+	protected HPSTrackerJavaBuilder initializeBuilder(Element node) {
+	     return new HPSTestRunTracker2014JavaBuilder(_debug,node);
+	 }
+    
 	
-
-	/**
-	 * Setup relations between detector elements.
-	 */
-	private void setupPhysicalVolumes() {
-		
-		if(_debug) System.out.printf("%s: setup the detector elements\n", getClass().getSimpleName());
-
-		setupPhysicalVolumes(builder.getBaseTrackerGeometry());
-		
 	
-		if(_debug) System.out.printf("%s: DONE setup the detector elements\n", getClass().getSimpleName());
-
-	
-	}
-
-	/**
-	 * Setup the detector element for a geometry object.
-	 * @param geometryObject - volume to process.
-	 */
-	private void setupPhysicalVolumes(JavaSurveyVolume geometryObject) {
-
-		if(_debug) System.out.printf("%s: setupDetectorElement for %s\n", getClass().getSimpleName(),geometryObject.getName());
-
-		// Only certain objects are setup as detector elements
-		// Ghost volumes are never setup
-		
-		// I do this recursively for daughters now as I wanted it to be generic
-		// but for now since I know what the daughters are I could manually 
-		// go and add:layer->module->sensor detector elements similar to 
-		// the old setup. I wanted this to be more generic in case more structures 
-		// are added so I keep track of all the elements in the builder in order 
-		// to build a hierarchy.
-		
-		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());
-		
-		} else if(geometryObject.getName().contains("tracking")) {
-			if(_debug) System.out.printf("%s: %s  is the tracking volume, dont create elements or physvol\n", getClass().getSimpleName(),geometryObject.getName());
-		} else {
-
-			// build the physical volume
-			geometryObject.buildPhysVolume();
-			PhysicalVolume physVol = (PhysicalVolume) geometryObject.getPhysVolume();
-			
-			// create detector element
-			// create detector element
-            if(HPSTrackerBuilder.isBase(geometryObject.getName())) {
-                
-                if(_debug) System.out.printf("%s: create the base detector element\n", getClass().getSimpleName());
-
-                
-                int nfields = builder.getDetectorIdentifierHelper().getIdentifierDictionary().getNumberOfFields();
-                IExpandedIdentifier layerPosId = new ExpandedIdentifier(nfields);
-                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("system"), builder.getSubdetector().getSystemID());
-                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
-                int layer = 12; // dummy value
-                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("layer"), layer);
-                IDetectorElement baseDe = builder.getBaseDetectorElement();
-                if(baseDe!=null) {
-                    throw new RuntimeException("Base exists. Shouldn't happen!");
-                } 
-                ILogicalVolume trackingVolume = geometryObject.getPhysMother().getVolume();
-                if(!trackingVolume.getName().contains("tracking")) {
-                    throw new RuntimeException("base phys mother " + geometryObject.getPhysMother().getName() + " is not tracking volume!?");
-                }
-                String physVolPath = trackingVolume.getName() + "/" + geometryObject.getPhysVolume().getName();
-                baseDe = new DetectorElement(builder.getSubdetector().getName() + "_base", builder.getSubdetector().getDetectorElement(), physVolPath, builder.getIdentifierDictionary().pack(layerPosId));
-                builder.addBaseDetectorElement(baseDe);
-                
-                if(_debug) System.out.printf("%s: baseDE name %s  \n", getClass().getSimpleName(),baseDe.getName());
-
-                
-            
-            } else if(HPSTrackerBuilder.isHalfModule(geometryObject.getName())) {
-
-				if(_debug) System.out.printf("%s: create the layer detector element\n", getClass().getSimpleName());
-
-				// The old geometry was built using a layer definition from a barrel tracker
-				// It also only has the concept of half-modules which it calls modules
-				// Thus the nomenclature here is a little strange
-				// Anyway, find those ID's
-				
-				int nfields = builder.getDetectorIdentifierHelper().getIdentifierDictionary().getNumberOfFields();
-				IExpandedIdentifier layerPosId = new ExpandedIdentifier(nfields);
-				layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("system"), builder.getSubdetector().getSystemID());
-				layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
-				//use the old definition of layer number to be consistent
-				//int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
-				int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
-				layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("layer"), layer);
-				if(_debug) System.out.printf("%s: layerPosId layer = %d (compare with new layer %d)\n", getClass().getSimpleName(),layer, HPSTrackerBuilder.getLayerFromVolumeName(geometryObject.getName()));
-				
-				// find the base DE as mother
-				IDetectorElement baseDe = builder.getBaseDetectorElement();
-				if(baseDe==null) {
-				    throw new RuntimeException("Base DE couldn't be found. Shouldn't happen!");
-				} 
-
-                
-				// create the layer detector element and keep track of it
-				//IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
-				IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
-				
-				if(layerDe==null) {
-				    //layerDe =  new DetectorElement(builder.getSubdetector().getName() + "_layer" + layer, builder.getSubdetector().getDetectorElement(), builder.getDetectorIdentifierHelper().pack(layerPosId));
-                    layerDe =  new DetectorElement(builder.getSubdetector().getName() + "_layer" + layer, baseDe, builder.getDetectorIdentifierHelper().pack(layerPosId));
-					builder.addLayerDetectorElement(layerDe);
-				} else {
-					if(_debug) System.out.printf("%s: layerDE exists\n", getClass().getSimpleName());
-				}
-				
-				if(_debug) System.out.printf("%s: layerDE name %s  \n", getClass().getSimpleName(),layerDe.getName());
-
-				
-				
-				if(_debug) System.out.printf("%s: create the module detector element\n", getClass().getSimpleName());
-
-				// create the "module" detector element 
-				// it's under the base element
-				String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
-                if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
-                int moduleNumber = half.equals("top") ? 0 : 1;
-              //String modulePlacementName = builder.getSubdetector().getName() + "_" + moduleName + "_layer" + layer + "_module" + moduleNumber;
-                String modulePlacementName = geometryObject.getName();// builder.getSubdetector().getName() + "_" + moduleName + "_layer" + layer + "_module" + moduleNumber;
-                
-                
-                /*
-				ILogicalVolume trackingVolume = null;
-				if(builder.getBaseTrackerGeometry().getName().contains("tracking")) {
-					trackingVolume = builder.getBaseTrackerGeometry().getVolume();
-				} else {
-					trackingVolume = builder.getBaseTrackerGeometry().getMother().getVolume();
-				}
-				if( trackingVolume == null ) {
-					throw new RuntimeException("failed to get tracking geometry from mother to " + builder.getBaseTrackerGeometry().getName()); 
-				}	
-				String modulePath = String.format("/%s/%s", trackingVolume.getName(), modulePlacementName);                                                        
-                */
-				// use base as mother for physical volume
-                String modulePath = baseDe.getGeometry().getPathString() + "/" + modulePlacementName;
-				
-				if(_debug) {
-					System.out.printf("%s: create SiTrackerModule with: placementname %s, modulePath %s, moduleNumber %d  \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
-					//System.out.printf("%s: print all %d physical volumes from the Store\n", getClass().getSimpleName(),PhysicalVolumeStore.getInstance().size());
-					//for(IPhysicalVolume v :  PhysicalVolumeStore.getInstance()) {
-					//	System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(), v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume()!=null?v.getMotherLogicalVolume().getName():"(no mother)");
-					//}
-				}
-
-				SiTrackerModule moduleDe = new SiTrackerModule(modulePlacementName, layerDe, modulePath, moduleNumber);
-                
-				if(_debug) System.out.printf("%s: add module DE to existing ones  \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
-				
-                
-				//keep track of the module detector element
-				builder.addModuleDetectorElement(moduleDe);
-				
-                
-                
-
-			} else if(HPSTrackerBuilder.isSensor(geometryObject.getName())) {
-				
-				if(_debug) System.out.printf("%s: this is where I would create a detector element for the sensor %s if needed\n", getClass().getSimpleName(),geometryObject.getName());
-
-				// set the physical volume to be sensitive
-				// TODO this should go into the geometry definition?!
-				physVol.setSensitive(true);
-				
-			} else if(HPSTrackerBuilder.isActiveSensor(geometryObject.getName())) {
-
-				// Setup the active sensor element
-				// to be consistent with old converter I also add the sensor 
-				// in the path to the element even though it's not associated with 
-				// with a element. I'm not sure why this is done.
-				
-				if(_debug) System.out.printf("%s: create the active sensor detector element\n", getClass().getSimpleName());
-
-				if(_debug) System.out.printf("%s: find the active sensor phys vol\n", this.getClass().getSimpleName());				
-				
-				// Find active Sensor physical volume.
-				// Keep name consistent with old converter
-				PhysicalVolume sensorPhysVol = physVol;
-
-				if(sensorPhysVol==null) throw new RuntimeException("cannot find physVol for " + geometryObject.getName());
-				
-				if(_debug) System.out.printf("%s: found %s phys vol\n", this.getClass().getSimpleName(),sensorPhysVol.getName());				
-
-				if(_debug) System.out.printf("%s: find the sensor phys vol\n", this.getClass().getSimpleName());				
-	
-				// find the module detector element
-                
-                // Helpers
-                IIdentifierDictionary iddict = builder.getDetectorIdentifierHelper().getIdentifierDictionary();
-				
-                // Find the mother: the module detector element
-                IExpandedIdentifier layerExpId = new ExpandedIdentifier(iddict.getNumberOfFields());
-				layerExpId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
-                layerExpId.setValue(iddict.getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());                            
-                //use the old definition of layer number to be consistent
-				//int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
-				int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
-				layerExpId.setValue(iddict.getFieldIndex("layer"), layer);
-				String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
-				if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
-				int moduleNumber = half.equals("top") ? 0 : 1;
-				
-				// The expId is the same for the layerDE and moduleDE because the tracker module object stores the 
-				// module ID in a member variable. So when searching I need to add this info
-				// TODO Can we change this and add the module ID to the identifier?
-				//IDetectorElement moduleDe = builder.getModuleDetectorElement(layerExpId);
-				//IDetectorElement moduleDe = builder.getSiTrackerModuleDetectorElement(layerExpId, moduleNumber);
-				
-				//Find the layer
-				IDetectorElement layerDe = builder.getLayerDetectorElement(layerExpId);
-
-				if(layerDe==null) throw new RuntimeException("Cannot find layer DE");
-				
-				//Find the module
-				IDetectorElement moduleDe = null;
-				for(IDetectorElement e : layerDe.getChildren()) {
-					if(e instanceof SiTrackerModule) {
-						SiTrackerModule m = (SiTrackerModule)e;
-						if(m.getModuleId()==moduleNumber) {
-							moduleDe = m;
-						}
-					}
-				}
-				
-				
-				if(moduleDe==null) throw new RuntimeException("Cannot find module DE for " + geometryObject.getName());
-				
-				// Setup SiSensor's identifier.
-				IExpandedIdentifier expId = new ExpandedIdentifier(iddict.getNumberOfFields());
-			    expId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
-                expId.setValue(iddict.getFieldIndex("barrel"), 0);                            
-                expId.setValue(iddict.getFieldIndex("layer"), builder.getDetectorIdentifierHelper().getValue(layerDe.getIdentifier(), "layer"));
-                expId.setValue(iddict.getFieldIndex("module"), ((SiTrackerModule) moduleDe).getModuleId());
-                // The sensorNumber is always 0 in the old geometry. Keep it that way.
-                int sensorNumber = 0;
-                expId.setValue(iddict.getFieldIndex("sensor"), sensorNumber);
-
-                // Packed identifier.
-                IIdentifier sensorId = iddict.pack(expId);
-
-                // Sensor paths.
-               String modulePath = moduleDe.getGeometry().getPathString();
-               IPhysicalVolume componentPhysVol = geometryObject.getPhysMother().getPhysVolume();
-               String sensorPath = modulePath.toString() + "/" + componentPhysVol.getName() + "/" + sensorPhysVol.getName();
-               String sensorName = moduleDe.getName() + "_sensor" + sensorNumber;
-
-               if(_debug) System.out.printf("%s: create HpsSiSensor with sensorNumber %d name %s moduleDe %s sensorPath %s sensor Id %d \n", getClass().getSimpleName(), 
-            		   sensorNumber, sensorName, moduleDe.getName(), sensorPath, sensorNumber);
-
-               
-                // Create the sensor.
-                HpsSiSensor sensor = new HpsSiSensor(sensorNumber, sensorName, moduleDe, sensorPath, sensorId);
-                
-                if(_debug) System.out.printf("%s: created sensor %s \n", getClass().getSimpleName(), sensor.getName());
-		        
-                // Increment sensor numbering.
-                // TODO this is just random. Not sure what to do here!
-               // ++sensorNumber;
-
-			} else {
-				throw new RuntimeException("I don't think I should reach this? Should " + geometryObject.getName() + " be a ghost?" );
-			}
-	
-		
-		}
-
-		// add daughters
-		if(_debug) System.out.printf("%s: add %d daughters to %s\n", this.getClass().getSimpleName(),geometryObject.getDaughters().size(), geometryObject.getName());
-		for(JavaSurveyVolume daughter : geometryObject.getDaughters()) {
-			setupPhysicalVolumes(daughter);
-		}
-
-		
-
-		if(_debug) System.out.printf("%s: DONE setup the detector element for %s\n", this.getClass().getSimpleName(),geometryObject.getName());
-
-
-	}
-
-
-
-
-
-
-
-
 }

Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTracker2014ConverterBase.java
 =============================================================================
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTracker2014ConverterBase.java	(added)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/detector/converter/compact/HPSTracker2014ConverterBase.java	Fri Oct 31 16:08:02 2014
@@ -0,0 +1,427 @@
+package org.lcsim.detector.converter.compact;
+
+import org.jdom.Element;
+import org.lcsim.detector.DetectorElement;
+import org.lcsim.detector.DetectorElementStore;
+import org.lcsim.detector.DetectorIdentifierHelper;
+import org.lcsim.detector.IDetectorElement;
+import org.lcsim.detector.IGeometryInfo;
+import org.lcsim.detector.ILogicalVolume;
+import org.lcsim.detector.IPhysicalVolume;
+import org.lcsim.detector.PhysicalVolume;
+import org.lcsim.detector.Transform3D;
+import org.lcsim.detector.DetectorIdentifierHelper.SystemMap;
+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.identifier.IIdentifierHelper;
+import org.lcsim.detector.material.IMaterial;
+import org.lcsim.detector.material.MaterialStore;
+import org.lcsim.detector.tracker.silicon.HpsSiSensor;
+import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
+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.HPSTrackerBuilder;
+import org.lcsim.geometry.compact.converter.HPSTrackerJavaBuilder;
+import org.lcsim.geometry.compact.converter.JavaGhostSurveyVolume;
+import org.lcsim.geometry.compact.converter.JavaSurveyVolume;
+import org.lcsim.geometry.subdetector.HPSTestRunTracker2014;
+
+/**
+ * Converters the compact description into Java runtime objects
+ * @author Per Hansson Adrian <[log in to unmask]>
+ *
+ */
+public abstract class HPSTracker2014ConverterBase extends
+        AbstractSubdetectorConverter {
+
+    protected boolean _debug = true;
+    protected IMaterial trackingMaterial = null;
+    protected static HPSTrackerJavaBuilder builder;
+
+    public HPSTracker2014ConverterBase() {
+        super();
+    }
+
+    /**
+     * Initialize builder for this converter.
+     * @param node
+     * @return builder.
+     */
+    abstract protected HPSTrackerJavaBuilder initializeBuilder(Element node);
+        
+    
+    public IIdentifierHelper makeIdentifierHelper(Subdetector subdetector, SystemMap systemMap) {
+    	return new SiTrackerIdentifierHelper(subdetector.getDetectorElement(), makeIdentifierDictionary(subdetector), systemMap);
+    }
+
+    public Class getSubdetectorType() {
+    	return HPSTestRunTracker2014.class;
+    }
+
+    /* (non-Javadoc)
+     * @see org.lcsim.detector.converter.compact.AbstractSubdetectorConverter#convert(org.lcsim.geometry.compact.Subdetector, org.lcsim.geometry.compact.Detector)
+     */
+    public void convert(Subdetector subdet, Detector detector) {
+
+        if(_debug) System.out.printf("%s: convert %s \n", getClass().getSimpleName(), subdet.getName());
+
+
+        // check tracking material
+        trackingMaterial = MaterialStore.getInstance().get("Vacuum");
+        //trackingMaterial = MaterialStore.getInstance().get("Vacuum");
+        if(trackingMaterial==null) {
+            System.out.printf("%s: error the tracking material was not found!\n", this.getClass().getSimpleName());
+            System.exit(1);
+        }
+
+        // Get XML node for this subdetector.
+        Element node = subdet.getNode();
+
+        // Get the tracking volume for module placement.
+        ILogicalVolume trackingVolume = detector.getTrackingVolume().getLogicalVolume();
+
+
+
+        // build the local geometry
+        builder = initializeBuilder(node);
+        //builder = new HPSTestRunTracker2014JavaBuilder(_debug,node);
+
+
+        // Set subdetector for later reference
+        builder.setSubdetector(subdet);
+
+        // Get ID helper and dictionary for subdetector.
+        builder.setDetectorIdentifierHelper( (DetectorIdentifierHelper) subdet.getDetectorElement().getIdentifierHelper());
+        builder.setIdentifierDictionary(subdet.getDetectorElement().getIdentifierHelper().getIdentifierDictionary());
+
+
+
+        // Build the detector here
+        // setup and build the LCDD geometry
+        if(_debug) System.out.printf("%s: setup and build the JAVA geometry\n", getClass().getSimpleName());
+
+        builder.build(trackingVolume);
+
+        if(_debug) System.out.printf("%s: DONE setup and build the JAVA geometry\n", getClass().getSimpleName());
+
+        setupPhysicalVolumes();
+
+        if(_debug) {
+            System.out.printf("%s: Print all %d detector elements in store\n", getClass().getSimpleName(),DetectorElementStore.getInstance().size());
+            for(IDetectorElement e : DetectorElementStore.getInstance()) {
+                System.out.printf("%s: Name: %s \n", getClass().getSimpleName(),e.getName());
+                if(e.hasGeometryInfo()) {
+                    System.out.printf("%s: Position: %s \n", getClass().getSimpleName(),e.getGeometry().getPosition());
+                    System.out.printf("%s: LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getLocalToGlobal()).toString());
+                    //System.out.printf("%s: GlobalToLocal: \n%s \n", getClass().getSimpleName(),((Transform3D)e.getGeometry().getGlobalToLocal()).toString());
+                    IGeometryInfo info = e.getGeometry();
+                    if(info!=null) {
+                        while((info=info.parentGeometry())!=null) {
+                            System.out.printf("%s: Parent geometry DE: %s \n", getClass().getSimpleName(),info.getDetectorElement().getName());
+                            System.out.printf("%s: Parent Position: %s \n", getClass().getSimpleName(),info.getPosition());
+                            System.out.printf("%s: Parent LocalToGlobal: \n%s \n", getClass().getSimpleName(),((Transform3D)info.getLocalToGlobal()).toString());
+
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Setup physical volumes based on the top level @JavaSurveyVolume
+     */
+    private void setupPhysicalVolumes() {
+
+        if(_debug) System.out.printf("%s: setup the detector elements\n", getClass().getSimpleName());
+
+        setupPhysicalVolumes(builder.getBaseTrackerGeometry());
+
+
+        if(_debug) System.out.printf("%s: DONE setup the detector elements\n", getClass().getSimpleName());
+
+
+    }
+
+
+
+
+
+
+
+    /**
+     * Setup the physical volumes recursively
+     * @param geometryObject - volume to process.
+     */
+    private void setupPhysicalVolumes(JavaSurveyVolume geometryObject) {
+
+        if(_debug) System.out.printf("%s: setupDetectorElement for %s\n", getClass().getSimpleName(),geometryObject.getName());
+
+        // Only certain objects are setup as detector elements
+        // Ghost volumes are never setup
+
+        // I do this recursively for daughters now as I wanted it to be generic
+        // but for now since I know what the daughters are I could manually 
+        // go and add:layer->module->sensor detector elements similar to 
+        // the old setup. I wanted this to be more generic in case more structures 
+        // are added so I keep track of all the elements in the builder in order 
+        // to build a hierarchy.
+
+        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());
+
+        } else if(geometryObject.getName().contains("tracking")) {
+            if(_debug) System.out.printf("%s: %s  is the tracking volume, dont create elements or physvol\n", getClass().getSimpleName(),geometryObject.getName());
+        } else {
+
+            // build the physical volume
+            geometryObject.buildPhysVolume();
+            PhysicalVolume physVol = (PhysicalVolume) geometryObject.getPhysVolume();
+
+            // create detector element
+            // create detector element
+            if(HPSTrackerBuilder.isBase(geometryObject.getName())) {
+
+                if(_debug) System.out.printf("%s: create the base detector element\n", getClass().getSimpleName());
+
+
+                int nfields = builder.getDetectorIdentifierHelper().getIdentifierDictionary().getNumberOfFields();
+                IExpandedIdentifier layerPosId = new ExpandedIdentifier(nfields);
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("system"), builder.getSubdetector().getSystemID());
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
+                int layer = 12; // dummy value
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("layer"), layer);
+                IDetectorElement baseDe = builder.getBaseDetectorElement();
+                if(baseDe!=null) {
+                    throw new RuntimeException("Base exists. Shouldn't happen!");
+                } 
+                ILogicalVolume trackingVolume = geometryObject.getPhysMother().getVolume();
+                if(!trackingVolume.getName().contains("tracking")) {
+                    throw new RuntimeException("base phys mother " + geometryObject.getPhysMother().getName() + " is not tracking volume!?");
+                }
+                String physVolPath = trackingVolume.getName() + "/" + geometryObject.getPhysVolume().getName();
+                baseDe = new DetectorElement(builder.getSubdetector().getName() + "_base", builder.getSubdetector().getDetectorElement(), physVolPath, builder.getIdentifierDictionary().pack(layerPosId));
+                builder.addBaseDetectorElement(baseDe);
+
+                if(_debug) System.out.printf("%s: baseDE name %s  \n", getClass().getSimpleName(),baseDe.getName());
+
+
+
+            } else if(HPSTrackerBuilder.isHalfModule(geometryObject.getName())) {
+
+                if(_debug) System.out.printf("%s: create the layer detector element\n", getClass().getSimpleName());
+
+                // The old geometry was built using a layer definition from a barrel tracker
+                // It also only has the concept of half-modules which it calls modules
+                // Thus the nomenclature here is a little strange
+                // Anyway, find those ID's
+
+                int nfields = builder.getDetectorIdentifierHelper().getIdentifierDictionary().getNumberOfFields();
+                IExpandedIdentifier layerPosId = new ExpandedIdentifier(nfields);
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("system"), builder.getSubdetector().getSystemID());
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());
+                //use the old definition of layer number to be consistent
+                //int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+                int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
+                layerPosId.setValue(builder.getDetectorIdentifierHelper().getFieldIndex("layer"), layer);
+                if(_debug) System.out.printf("%s: layerPosId layer = %d (compare with new layer %d)\n", getClass().getSimpleName(),layer, HPSTrackerBuilder.getLayerFromVolumeName(geometryObject.getName()));
+
+                // find the base DE as mother
+                IDetectorElement baseDe = builder.getBaseDetectorElement();
+                if(baseDe==null) {
+                    throw new RuntimeException("Base DE couldn't be found. Shouldn't happen!");
+                } 
+
+
+                // create the layer detector element and keep track of it
+                //IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
+                IDetectorElement layerDe = builder.getLayerDetectorElement(layerPosId);
+
+                if(layerDe==null) {
+                    //layerDe =  new DetectorElement(builder.getSubdetector().getName() + "_layer" + layer, builder.getSubdetector().getDetectorElement(), builder.getDetectorIdentifierHelper().pack(layerPosId));
+                    layerDe =  new DetectorElement(builder.getSubdetector().getName() + "_layer" + layer, baseDe, builder.getDetectorIdentifierHelper().pack(layerPosId));
+                    builder.addLayerDetectorElement(layerDe);
+                } else {
+                    if(_debug) System.out.printf("%s: layerDE exists\n", getClass().getSimpleName());
+                }
+
+                if(_debug) System.out.printf("%s: layerDE name %s  \n", getClass().getSimpleName(),layerDe.getName());
+
+
+
+                if(_debug) System.out.printf("%s: create the module detector element\n", getClass().getSimpleName());
+
+                // create the "module" detector element 
+                // it's under the base element
+                String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
+                if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
+                int moduleNumber = half.equals("top") ? 0 : 1;
+                //String modulePlacementName = builder.getSubdetector().getName() + "_" + moduleName + "_layer" + layer + "_module" + moduleNumber;
+                String modulePlacementName = geometryObject.getName();// builder.getSubdetector().getName() + "_" + moduleName + "_layer" + layer + "_module" + moduleNumber;
+
+
+                /*
+            ILogicalVolume trackingVolume = null;
+            if(builder.getBaseTrackerGeometry().getName().contains("tracking")) {
+                trackingVolume = builder.getBaseTrackerGeometry().getVolume();
+            } else {
+                trackingVolume = builder.getBaseTrackerGeometry().getMother().getVolume();
+            }
+            if( trackingVolume == null ) {
+                throw new RuntimeException("failed to get tracking geometry from mother to " + builder.getBaseTrackerGeometry().getName()); 
+            }   
+            String modulePath = String.format("/%s/%s", trackingVolume.getName(), modulePlacementName);                                                        
+                 */
+                // use base as mother for physical volume
+                String modulePath = baseDe.getGeometry().getPathString() + "/" + modulePlacementName;
+
+                if(_debug) {
+                    System.out.printf("%s: create SiTrackerModule with: placementname %s, modulePath %s, moduleNumber %d  \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
+                    //System.out.printf("%s: print all %d physical volumes from the Store\n", getClass().getSimpleName(),PhysicalVolumeStore.getInstance().size());
+                    //for(IPhysicalVolume v :  PhysicalVolumeStore.getInstance()) {
+                    //  System.out.printf("%s: %s %s %s\n", getClass().getSimpleName(), v.getName(), v.getLogicalVolume().getName(), v.getMotherLogicalVolume()!=null?v.getMotherLogicalVolume().getName():"(no mother)");
+                    //}
+                }
+
+                SiTrackerModule moduleDe = new SiTrackerModule(modulePlacementName, layerDe, modulePath, moduleNumber);
+
+                if(_debug) System.out.printf("%s: add module DE to existing ones  \n", getClass().getSimpleName(),modulePlacementName, modulePath, moduleNumber);
+
+
+                //keep track of the module detector element
+                builder.addModuleDetectorElement(moduleDe);
+
+
+
+
+            } else if(HPSTrackerBuilder.isSensor(geometryObject.getName())) {
+
+                if(_debug) System.out.printf("%s: this is where I would create a detector element for the sensor %s if needed\n", getClass().getSimpleName(),geometryObject.getName());
+
+                // set the physical volume to be sensitive
+                // TODO this should go into the geometry definition?!
+                physVol.setSensitive(true);
+
+            } else if(HPSTrackerBuilder.isActiveSensor(geometryObject.getName())) {
+
+                // Setup the active sensor element
+                // to be consistent with old converter I also add the sensor 
+                // in the path to the element even though it's not associated with 
+                // with a element. I'm not sure why this is done.
+
+                if(_debug) System.out.printf("%s: create the active sensor detector element\n", getClass().getSimpleName());
+
+                if(_debug) System.out.printf("%s: find the active sensor phys vol\n", this.getClass().getSimpleName());             
+
+                // Find active Sensor physical volume.
+                // Keep name consistent with old converter
+                PhysicalVolume sensorPhysVol = physVol;
+
+                if(sensorPhysVol==null) throw new RuntimeException("cannot find physVol for " + geometryObject.getName());
+
+                if(_debug) System.out.printf("%s: found %s phys vol\n", this.getClass().getSimpleName(),sensorPhysVol.getName());               
+
+                if(_debug) System.out.printf("%s: find the sensor phys vol\n", this.getClass().getSimpleName());                
+
+                // find the module detector element
+
+                // Helpers
+                IIdentifierDictionary iddict = builder.getDetectorIdentifierHelper().getIdentifierDictionary();
+
+                // Find the mother: the module detector element
+                IExpandedIdentifier layerExpId = new ExpandedIdentifier(iddict.getNumberOfFields());
+                layerExpId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
+                layerExpId.setValue(iddict.getFieldIndex("barrel"), builder.getDetectorIdentifierHelper().getBarrelValue());                            
+                //use the old definition of layer number to be consistent
+                //int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+                int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
+                layerExpId.setValue(iddict.getFieldIndex("layer"), layer);
+                String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
+                if(half.equals("")) throw new RuntimeException("No half found for " + geometryObject.getName());
+                int moduleNumber = half.equals("top") ? 0 : 1;
+
+                // The expId is the same for the layerDE and moduleDE because the tracker module object stores the 
+                // module ID in a member variable. So when searching I need to add this info
+                // TODO Can we change this and add the module ID to the identifier?
+                //IDetectorElement moduleDe = builder.getModuleDetectorElement(layerExpId);
+                //IDetectorElement moduleDe = builder.getSiTrackerModuleDetectorElement(layerExpId, moduleNumber);
+
+                //Find the layer
+                IDetectorElement layerDe = builder.getLayerDetectorElement(layerExpId);
+
+                if(layerDe==null) throw new RuntimeException("Cannot find layer DE");
+
+                //Find the module
+                IDetectorElement moduleDe = null;
+                for(IDetectorElement e : layerDe.getChildren()) {
+                    if(e instanceof SiTrackerModule) {
+                        SiTrackerModule m = (SiTrackerModule)e;
+                        if(m.getModuleId()==moduleNumber) {
+                            moduleDe = m;
+                        }
+                    }
+                }
+
+
+                if(moduleDe==null) throw new RuntimeException("Cannot find module DE for " + geometryObject.getName());
+
+                // Setup SiSensor's identifier.
+                IExpandedIdentifier expId = new ExpandedIdentifier(iddict.getNumberOfFields());
+                expId.setValue(iddict.getFieldIndex("system"), builder.getSubdetector().getSystemID());
+                expId.setValue(iddict.getFieldIndex("barrel"), 0);                            
+                expId.setValue(iddict.getFieldIndex("layer"), builder.getDetectorIdentifierHelper().getValue(layerDe.getIdentifier(), "layer"));
+                expId.setValue(iddict.getFieldIndex("module"), ((SiTrackerModule) moduleDe).getModuleId());
+                // The sensorNumber is always 0 in the old geometry. Keep it that way.
+                int sensorNumber = 0;
+                expId.setValue(iddict.getFieldIndex("sensor"), sensorNumber);
+
+                // Packed identifier.
+                IIdentifier sensorId = iddict.pack(expId);
+
+                // Sensor paths.
+                String modulePath = moduleDe.getGeometry().getPathString();
+                IPhysicalVolume componentPhysVol = geometryObject.getPhysMother().getPhysVolume();
+                String sensorPath = modulePath.toString() + "/" + componentPhysVol.getName() + "/" + sensorPhysVol.getName();
+                String sensorName = moduleDe.getName() + "_sensor" + sensorNumber;
+
+                if(_debug) System.out.printf("%s: create HpsSiSensor with sensorNumber %d name %s moduleDe %s sensorPath %s sensor Id %d \n", getClass().getSimpleName(), 
+                        sensorNumber, sensorName, moduleDe.getName(), sensorPath, sensorNumber);
+
+
+                // Create the sensor.
+                HpsSiSensor sensor = new HpsSiSensor(sensorNumber, sensorName, moduleDe, sensorPath, sensorId);
+
+                if(_debug) System.out.printf("%s: created sensor %s \n", getClass().getSimpleName(), sensor.getName());
+
+                // Increment sensor numbering.
+                // TODO this is just random. Not sure what to do here!
+                // ++sensorNumber;
+
+            } else {
+                throw new RuntimeException("I don't think I should reach this? Should " + geometryObject.getName() + " be a ghost?" );
+            }
+
+
+        }
+
+        // add daughters
+        if(_debug) System.out.printf("%s: add %d daughters to %s\n", this.getClass().getSimpleName(),geometryObject.getDaughters().size(), geometryObject.getName());
+        for(JavaSurveyVolume daughter : geometryObject.getDaughters()) {
+            setupPhysicalVolumes(daughter);
+        }
+
+
+
+        if(_debug) System.out.printf("%s: DONE setup the detector element for %s\n", this.getClass().getSimpleName(),geometryObject.getName());
+
+
+    }
+
+
+
+}

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 16:08:02 2014
@@ -4,19 +4,11 @@
 import hep.physics.vec.BasicHep3Vector;
 import hep.physics.vec.Hep3Vector;
 
-import java.util.Iterator;
-
-import org.jdom.DataConversionException;
 import org.jdom.Element;
 import org.jdom.JDOMException;
-import org.lcsim.detector.Transform3D;
 import org.lcsim.geometry.compact.converter.HPSTestRunTracker2014GeometryDefinition;
 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.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;
 import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol;
@@ -29,359 +21,47 @@
 
 /**
  * 
- * Convert the HPS Test run tracker to the LCDD format.
+ * Convert the HPS Test run tracker 2014 to the LCDD format.
  * 
  * @author Per Hansson <[log in to unmask]>
  *
  */
-public class HPSTestRunTracker2014 extends LCDDSubdetector
+public class HPSTestRunTracker2014 extends HPSTracker2014Base
 {
-	private boolean _debug = true; 
-	private final boolean buildBeamPlane = false;
-	// Builder class to handle all geometry information
-	private static HPSTrackerLCDDBuilder builder;
-	
-	
-	
-	/**
-	 * Default constructor
-	 * @param node
-	 * @throws JDOMException
-	 */
 	public HPSTestRunTracker2014(Element node) throws JDOMException
 	{
 		super(node);
-		
-		
-		
 	}
 
-	
-	public boolean isTracker() {
-		return true;
+	/* (non-Javadoc)
+	 * @see org.lcsim.geometry.compact.converter.lcdd.HPSTracker2014Base#initializeBuilder(org.lcsim.geometry.compact.converter.lcdd.util.LCDD, org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector)
+	 */
+	protected HPSTrackerLCDDBuilder initializeBuilder(LCDD lcdd, SensitiveDetector sens) {
+	    HPSTrackerLCDDBuilder b = new HPSTestRunTracker2014LCDDBuilder(_debug,node,lcdd,sens);
+	    return b;
 	}
 	
-	/**
-	 * Build the LCDD for the subdetector.
-	 * @param lcdd - the LCDD file being created.
-	 * @param sens - the SD for this subdetector.
-	 */
-	public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
-	{
-		
-		
-		
-		/** General comments
-		// Roll: rotation around x
-		// pitch: rotation around y
-		// yaw: rotation around z
-		
-		// kinematic mounts:
-		// ball (constraints x,y,z)
-		// vee  (constraints pitch & yaw)
-		// flat (constraints roll)
-		**/
-		
-		
-		
-		// ID of the detector.
-		int id = this.node.getAttribute("id").getIntValue();
-
-		// Name of the detector.
-		String detector_name = this.node.getAttributeValue("name");
-
-		if(_debug) System.out.printf("%s: detector id %d name %s",getClass().getSimpleName(), id,detector_name);
-		
-		
-		// Pick the mother volume (tracking volume).
-		Volume trackingVolume = lcdd.pickMotherVolume(this);
-
-		
-		// setup and build the LCDD geometry
-		if(_debug) System.out.printf("%s: setup and build the LCDD geometry\n", getClass().getSimpleName());
-		
-		builder = new HPSTestRunTracker2014LCDDBuilder(_debug,node,lcdd,sens);
-		
-		//builder.setLCDD(lcdd);
-		//builder.setSensitiveDetector(sens);
-		builder.build(trackingVolume);
-		
-		if(_debug) System.out.printf("%s: DONE setup and build the LCDD geometry\n", getClass().getSimpleName());
-		
-		/*
-		makeExample(lcdd,sens);
-		//makeExample2(lcdd,sens);
-		makeExample3(lcdd,sens);
-		makeExample4(lcdd,sens);
-		makeExample5(lcdd,sens);
-		makeExample3b(lcdd,sens);
-		makeExample5b(lcdd,sens);
-		makeExample6(lcdd,sens);
-		makeExample66(lcdd,sens);
-		makeExample7(lcdd,sens);
-		makeExample77(lcdd,sens);
-		makeExample8(lcdd, sens);
-		makeExample9(lcdd, sens);
-		makeExample10(lcdd, sens);
-		*/
-
-		if(buildBeamPlane ) {
-			// beam plane at global z=0
-			Hep3Vector ball_pos_beamplane = new BasicHep3Vector(-1.0*HPSTestRunTracker2014GeometryDefinition.BasePlate.base_plate_width/2.0,0.0,HPSTestRunTracker2014GeometryDefinition.BasePlate.base_plate_length/2.0);
-			Hep3Vector vee_pos_beamplane = new BasicHep3Vector(ball_pos_beamplane.x()+HPSTestRunTracker2014GeometryDefinition.BasePlate.base_plate_width,ball_pos_beamplane.y(),ball_pos_beamplane.z());
-			Hep3Vector flat_pos_beamplane = new BasicHep3Vector(ball_pos_beamplane.x(), ball_pos_beamplane.y(), ball_pos_beamplane.z()-HPSTestRunTracker2014GeometryDefinition.BasePlate.base_plate_length/2.0);
-			makeBeamPlane(trackingVolume, ball_pos_beamplane, vee_pos_beamplane, flat_pos_beamplane, lcdd, sens);
-		}
-		
-		
-		// Actually build the LCDD
-		buildLCDD();
-		
-		
-	}
-	
-	
-	/**
-	 *  Top function to add objects to the LCDD file using the geometry builder class. 
-	 */
-	private void buildLCDD() {
-		
-		if(_debug) System.out.printf("%s: buildLCDD\n", getClass().getSimpleName());
-		
-		// Get a reference to the LCDD
-		LCDD lcdd  = builder.getLCDD();
-		SensitiveDetector sd  = builder.getSensitiveDetector();
-
-		// Reference to the top level object in the builder class
-		// In this case it is the base volume holding the entire tracker
-		LCDDSurveyVolume lcddObj  = (LCDDSurveyVolume) builder.getBaseLCDD();
-		
-		// Add the base volume and all its daughters to the LCDD
-		addToLCDD(lcddObj,lcdd,sd);
-		
-		if(_debug) System.out.printf("%s: buildLCDD DONE\n", getClass().getSimpleName());
-		
-	}
-	
-	
-
-	/**
-	 * Add a @LCDDBaseGeom geometry object to the LCDD file.
-	 * @param lcddObj to add
-	 * @param lcdd file
-	 */
-	private void addToLCDD(LCDDSurveyVolume lcddObj, LCDD lcdd, SensitiveDetector sd) {
-		
-		if(_debug) System.out.printf("%s: adding %s to LCDD\n", getClass().getSimpleName(),lcddObj.getName());
-
-		boolean doAdd = true;
-		if(lcddObj.getName().contains("tracking")) doAdd=false;
-		
-		if(doAdd) {
-
-			// only world/tracking volume can be ghost here?!
-			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.");
-			}
-			// add box, pos, rotation and create phys volume
-			lcdd.add(lcddObj.getBox());
-			lcdd.add(lcddObj.getPos());
-			lcdd.add(lcddObj.getRot());
-			lcddObj.buildPhysVolume();
-			// Set the phys volume Id's
-			// Since the builder don't have access to the system ID
-			// I keep the phys volume ID's outside. I think these 
-			// should belong to the builder to avoid repeating it in 
-			// the java converter
-			// TODO move this to the builder for each volume
-			try {
-				setPhysicalVolumeProperties(lcddObj, sd);
-			} catch (DataConversionException e) {
-				e.printStackTrace();
-			}
-		} else {
-			if(_debug) System.out.printf("%s:  skip building anything (name=%s)\n", getClass().getSimpleName(),lcddObj.getName());
-		}
-		
-		// add daughters
-		if(_debug) System.out.printf("%s: add %d daughters to %s\n", getClass().getSimpleName(),lcddObj.getDaughters().size(),lcddObj.getName());
-		for(LCDDSurveyVolume daughter : lcddObj.getDaughters()) {
-			addToLCDD(daughter,lcdd, sd);
-		}
-		
-		// finally add volume
-		if(doAdd) {
-			if(_debug) System.out.printf("%s: adding volume %s\n", getClass().getSimpleName(),lcddObj.getName());
-			if(!lcddObj.getVisName().isEmpty()) lcddObj.getVolume().setVisAttributes(lcdd.getVisAttributes(lcddObj.getVisName()));
-			lcdd.add(lcddObj.getVolume());
-		} else {
-			if(_debug) System.out.printf("%s: skip adding volume %s\n", getClass().getSimpleName(),lcddObj.getName());
-		}
-		if(_debug) System.out.printf("%s: DONE adding %s\n", getClass().getSimpleName(),lcddObj.getName());
-	}
-	
-	
-	/**
-	 * Set properties of the physical volume.
-	 * @param geometryObject
-	 */
-	private void setPhysicalVolumeProperties(LCDDSurveyVolume geometryObject, SensitiveDetector sd) throws DataConversionException {
-		
-		if(_debug) System.out.printf("%s: setPhysVolumeProperties for name %s\n", getClass().getSimpleName(),geometryObject.getName());
-		
-		// the physical vol ID's here are for the <module_placement> TestRunModules
-		// which is essentially the sensor objects
-		String name = geometryObject.getName();
-		if(name.endsWith("halfmodule_axial") || name.endsWith("halfmodule_stereo") ) {
-			PhysVol physVol = geometryObject.getPhysVolume();
-			int sysId = node.getAttribute("id").getIntValue();
-			physVol.addPhysVolID("system", sysId);
-			physVol.addPhysVolID("barrel", 0);
-
-			//use the old definition of layer number to be consistent
-			//int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
-			int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
-			if(_debug) System.out.printf("%s: physVolId layer = %d (compare with new layer %d)\n", getClass().getSimpleName(),layer, HPSTrackerBuilder.getLayerFromVolumeName(geometryObject.getName()));
-
-			
-			geometryObject.getPhysVolume().addPhysVolID("layer", layer);
-			String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
-			if(half.equals("")) throw new RuntimeException("no half was found for name " + geometryObject.getName());
-			int moduleId = half.equals("top") ? 0 : 1;
-			geometryObject.getPhysVolume().addPhysVolID("module", moduleId);
-		}
-		
-		//TODO this is always 0 in old geometry? Is the id0 really needed?
-		else if(name.endsWith("sensor_active")) {
-			geometryObject.getPhysVolume().addPhysVolID("sensor", 0);
-			geometryObject.getVolume().setSensitiveDetector(sd);
-		}
-		//TODO are the component id's really needed?
-		else if(name.endsWith("sensor")) {
-			geometryObject.getPhysVolume().addPhysVolID("component", 0);
-		}
-		else if(name.endsWith("lamination")) {
-			geometryObject.getPhysVolume().addPhysVolID("component", 2);
-		}
-		else if(name.endsWith("cf")) {
-			geometryObject.getPhysVolume().addPhysVolID("component", 1);
-		}
-		else if(name.endsWith("hybrid")) {
-			geometryObject.getPhysVolume().addPhysVolID("component", 3);
-		}
-
-		if(_debug) {
-			System.out.printf("%s: %d physvolid's\n", getClass().getSimpleName(),geometryObject.getPhysVolume().getChildren("physvolid").size());
-			//geomObj.getPhysVolume().getChildren("physvolid field_name="sensor" value="0"")
-			for (Iterator i = geometryObject.getPhysVolume().getChildren("physvolid").iterator(); i.hasNext();) {        
-				Element e = (Element)i.next();
-				System.out.printf("%s: %s %d\n", getClass().getSimpleName(),e.getAttributeValue("field_name"),e.getAttribute("value").getIntValue());
-			}
-		
-		if(_debug) System.out.printf("%s: DONE setPhysVolumeProperties for name %s\n", getClass().getSimpleName(),geometryObject.getName());
-			
-		}
-
-		
-	}
-	
-	
-	
-
-	
-	
-	private void print(String str) {
-		System.out.printf("%s: %s\n", this.getClass().getSimpleName(),str);
-	}
-	
-	
-	
-	
-	private void makeBeamPlane(Volume motherVolume, Hep3Vector ball_pos_base_plate, Hep3Vector vee_pos_base_plate,Hep3Vector flat_pos_base_plate, LCDD lcdd, SensitiveDetector sens) throws JDOMException {
+	
+
+
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+	
+	
+	
+	private void makeExample(LCDD lcdd, SensitiveDetector sens) throws JDOMException {
 	
 	
 	if(_debug) {
-		print("--- makeBeamPlane ----");
-		
-	}
-	
-	// create the coordinate system of the beam plane in the tracking volume
-	// since this is a dummy volume it is based on the position of the base plate coordinate system
-	// width - u
-	// length - v
-	// thickness - w
-	Hep3Vector ball_pos_beamplane = ball_pos_base_plate;
-	Hep3Vector vee_pos_beamplane = vee_pos_base_plate; 
-	Hep3Vector flat_pos_beamplane = flat_pos_base_plate;		
-	SurveyCoordinateSystem beamplane_coord = new SurveyCoordinateSystem(ball_pos_beamplane, vee_pos_beamplane, flat_pos_beamplane);		
-	Transform3D trans_beamplane_to_tracking = beamplane_coord.getTransformation();
-	
-	final double beamPlaneThickness = 0.00000001;
-	String volName = "beamPlaneVol";
-	Box box = new Box(volName + "Box", HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_width, HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_length*2, beamPlaneThickness);
-	lcdd.add(box);
-	Volume volume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
-	
-	
-	if(_debug) {
-		print(String.format("ball_pos_beamplane %s", ball_pos_beamplane.toString()));
-		print(String.format("vee_pos_beamplane %s", vee_pos_beamplane.toString()));
-		print(String.format("flat_pos_beamplane %s", flat_pos_beamplane.toString()));
-		print(String.format("beamplane_coord:\n%s", beamplane_coord.toString()));
-	}
-
-	
-	// Find distance to center in the local coordinate system 
-	Hep3Vector box_center_base_local = new BasicHep3Vector(HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_width/2.0, HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_length/2.0, beamPlaneThickness/2.0);
-	
-	//translate to the mother coordinate system
-	Hep3Vector box_center_base = trans_beamplane_to_tracking.transformed(box_center_base_local);
-	
-	if(_debug) {
-		print(String.format("box_center_base_local  %s", box_center_base_local.toString()));
-		print(String.format("box_center_base        %s", box_center_base.toString()));
-	}
-	
-	// Create the LCDD position
-	Position pos = new Position(volName + "_position",box_center_base.x(), box_center_base.y(), box_center_base.z());
-	
-	//Find LCDD Euler rotation angles from coordinate system unit vectors
-	Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(beamplane_coord.v(), beamplane_coord.w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
-	Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
-	lcdd.add(pos);
-	lcdd.add(rot);
-	
-	// Create the physical volume
-	PhysVol basePV = new PhysVol(volume, motherVolume, pos, rot);
-	if(_debug) {
-    	 print("Created physical vomume " + basePV.getName());
-     }
-	
-	
-     
-     volume.setVisAttributes(lcdd.getVisAttributes("BeamPlaneVis"));
-	
-    
-	
-     lcdd.add(volume);
-	
-	
-	
-	
-	}
-	
-	
-	
-	
-	
-	
-	
-	private void makeExample(LCDD lcdd, SensitiveDetector sens) throws JDOMException {
-	
-	
-	if(_debug) {
-		print("--- makeExample ----");
+		System.out.println("--- makeExample ----");
 		
 	}
 
@@ -448,7 +128,7 @@
 	
      PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
      if(_debug) {
-    	 print("Created physical vomume " + basePV.getName());
+    	 System.out.println("Created physical vomume " + basePV.getName());
      }
      
      
@@ -464,7 +144,7 @@
      lcdd.add(subRot);
      PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
      if(_debug) {
-    	 print("Created physical vomume " + subBasePV.getName());
+    	 System.out.println("Created physical vomume " + subBasePV.getName());
      }
 	
      lcdd.add(volumeSub);
@@ -483,7 +163,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample2 ----");
+			System.out.println("--- makeExample2 ----");
 			
 		}
 		
@@ -531,7 +211,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -546,7 +226,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -565,7 +245,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample3 ----");
+			System.out.println("--- makeExample3 ----");
 			
 		}
 		
@@ -677,7 +357,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -692,7 +372,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -710,7 +390,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample4 ----");
+			System.out.println("--- makeExample4 ----");
 			
 		}
 		
@@ -768,7 +448,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -784,7 +464,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -802,7 +482,7 @@
 			
 			
 			if(_debug) {
-				print("--- makeExample5 ----");
+				System.out.println("--- makeExample5 ----");
 				
 			}
 			
@@ -875,7 +555,7 @@
 			
 		     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + basePV.getName());
+		    	 System.out.println("Created physical vomume " + basePV.getName());
 		     }
 			
 		     
@@ -889,7 +569,7 @@
 		     lcdd.add(subRot);
 		     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + subBasePV.getName());
+		    	 System.out.println("Created physical vomume " + subBasePV.getName());
 		     }
 			
 		     lcdd.add(volumeSub);
@@ -909,7 +589,7 @@
 			
 			
 			if(_debug) {
-				print("--- makeExample5b ----");
+				System.out.println("--- makeExample5b ----");
 				
 			}
 			
@@ -966,7 +646,7 @@
 			
 		     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + basePV.getName());
+		    	 System.out.println("Created physical vomume " + basePV.getName());
 		     }
 			
 		     
@@ -980,7 +660,7 @@
 		     lcdd.add(subRot);
 		     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + subBasePV.getName());
+		    	 System.out.println("Created physical vomume " + subBasePV.getName());
 		     }
 			
 		     lcdd.add(volumeSub);
@@ -997,7 +677,7 @@
 			
 			
 			if(_debug) {
-				print("--- makeExample3b ----");
+				System.out.println("--- makeExample3b ----");
 				
 			}
 			
@@ -1117,7 +797,7 @@
 			
 		     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + basePV.getName());
+		    	 System.out.println("Created physical vomume " + basePV.getName());
 		     }
 			
 		     
@@ -1132,7 +812,7 @@
 		     lcdd.add(subRot);
 		     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + subBasePV.getName());
+		    	 System.out.println("Created physical vomume " + subBasePV.getName());
 		     }
 			
 		     lcdd.add(volumeSub);
@@ -1150,7 +830,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample6 ----");
+			System.out.println("--- makeExample6 ----");
 			
 		}
 		
@@ -1181,7 +861,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -1197,7 +877,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -1216,7 +896,7 @@
 			
 			
 			if(_debug) {
-				print("--- makeExample66 ----");
+				System.out.println("--- makeExample66 ----");
 				
 			}
 			
@@ -1274,7 +954,7 @@
 			
 		     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + basePV.getName());
+		    	 System.out.println("Created physical vomume " + basePV.getName());
 		     }
 			
 		     
@@ -1290,7 +970,7 @@
 		     lcdd.add(subRot);
 		     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + subBasePV.getName());
+		    	 System.out.println("Created physical vomume " + subBasePV.getName());
 		     }
 			
 		     lcdd.add(volumeSub);
@@ -1312,7 +992,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample7 ----");
+			System.out.println("--- makeExample7 ----");
 			
 		}
 		
@@ -1343,7 +1023,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -1359,7 +1039,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -1378,7 +1058,7 @@
 			
 			
 			if(_debug) {
-				print("--- makeExample77 ----");
+				System.out.println("--- makeExample77 ----");
 				
 			}
 			
@@ -1459,7 +1139,7 @@
 			
 		     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + basePV.getName());
+		    	 System.out.println("Created physical vomume " + basePV.getName());
 		     }
 			
 		     
@@ -1475,7 +1155,7 @@
 		     lcdd.add(subRot);
 		     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 		     if(_debug) {
-		    	 print("Created physical vomume " + subBasePV.getName());
+		    	 System.out.println("Created physical vomume " + subBasePV.getName());
 		     }
 			
 		     lcdd.add(volumeSub);
@@ -1495,7 +1175,7 @@
 	
 	
 	if(_debug) {
-		print("--- makeExample8 ----");
+		System.out.println("--- makeExample8 ----");
 		
 	}
 	
@@ -1541,7 +1221,7 @@
 	
      PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
      if(_debug) {
-    	 print("Created physical vomume " + basePV.getName());
+    	 System.out.println("Created physical vomume " + basePV.getName());
      }
 	
      
@@ -1557,7 +1237,7 @@
      lcdd.add(subRot);
      PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
      if(_debug) {
-    	 print("Created physical vomume " + subBasePV.getName());
+    	 System.out.println("Created physical vomume " + subBasePV.getName());
      }
 	
      lcdd.add(volumeSub);
@@ -1576,7 +1256,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample9 ----");
+			System.out.println("--- makeExample9 ----");
 			
 		}
 		
@@ -1622,7 +1302,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -1638,7 +1318,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -1659,7 +1339,7 @@
 		
 		
 		if(_debug) {
-			print("--- makeExample10 ----");
+			System.out.println("--- makeExample10 ----");
 			
 		}
 		
@@ -1705,7 +1385,7 @@
 		
 	     PhysVol basePV = new PhysVol(volume, lcdd.pickMotherVolume(this), pos, rot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + basePV.getName());
+	    	 System.out.println("Created physical vomume " + basePV.getName());
 	     }
 		
 	     
@@ -1721,7 +1401,7 @@
 	     lcdd.add(subRot);
 	     PhysVol subBasePV = new PhysVol(volumeSub, volume, subPos, subRot);
 	     if(_debug) {
-	    	 print("Created physical vomume " + subBasePV.getName());
+	    	 System.out.println("Created physical vomume " + subBasePV.getName());
 	     }
 		
 	     lcdd.add(volumeSub);
@@ -1733,7 +1413,8 @@
 		
 		
 		}
-		
+
+   
 			
 	
 	

Added: projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTracker2014Base.java
 =============================================================================
--- projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTracker2014Base.java	(added)
+++ projects/lcsim/trunk/detector-framework/src/main/java/org/lcsim/geometry/compact/converter/lcdd/HPSTracker2014Base.java	Fri Oct 31 16:08:02 2014
@@ -0,0 +1,366 @@
+package org.lcsim.geometry.compact.converter.lcdd;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+
+import java.util.Iterator;
+
+import org.jdom.DataConversionException;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.lcsim.detector.Transform3D;
+import org.lcsim.geometry.compact.converter.HPSTrackerBuilder;
+import org.lcsim.geometry.compact.converter.HPSTrackerLCDDBuilder;
+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;
+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;
+
+/**
+ * 
+ * Convert an HPS tracker "2014" to the LCDD format.
+ * 
+ * @author Per Hansson <[log in to unmask]>
+ *
+ */
+public abstract class HPSTracker2014Base extends LCDDSubdetector {
+
+    protected boolean _debug = true;
+    protected static HPSTrackerLCDDBuilder builder;
+    private final boolean buildBeamPlane = false;
+    private final double beamPlaneWidth = 385.00;
+    private final double beamPlaneLength = 1216.00;
+    private final double beamPlaneThickness = 0.00000001;
+
+    public HPSTracker2014Base(Element c) throws JDOMException {
+        super(c);
+    }
+    
+    
+    /**
+     * Set the @HPSTrackerLCDDBuilder for this converter.
+     * @param lcdd
+     * @param sens
+     * @return the builder.
+     */
+    abstract protected HPSTrackerLCDDBuilder initializeBuilder(LCDD lcdd, SensitiveDetector sens);
+    
+    
+    public boolean isTracker() {
+        return true;
+    }
+    
+    /**
+     * Build the LCDD for the subdetector.
+     * @param lcdd - the LCDD file being created.
+     * @param sens - the SD for this subdetector.
+     */
+    
+    public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
+    {
+        
+        
+        
+        /// General comments
+        // Roll: rotation around x
+        // pitch: rotation around y
+        // yaw: rotation around z
+        
+        // kinematic mounts:
+        // ball (constraints x,y,z)
+        // vee  (constraints pitch & yaw)
+        // flat (constraints roll)
+        ///
+        
+        
+        
+        // ID of the detector.
+        int id = node.getAttribute("id").getIntValue();
+
+        // Name of the detector.
+        String detector_name = node.getAttributeValue("name");
+
+        if(_debug) System.out.printf("%s: detector id %d name %s",getClass().getSimpleName(), id,detector_name);
+        
+        
+        // Pick the mother volume (tracking volume).
+        Volume trackingVolume = lcdd.pickMotherVolume(this);
+
+        
+        if(_debug) System.out.printf("%s: setup and build the LCDD geometry\n", getClass().getSimpleName());
+
+        // setup and build the LCDD geometry
+        builder = initializeBuilder(lcdd, sens);
+        //builder = new HPSTestRunTracker2014LCDDBuilder(_debug,node,lcdd,sens);
+        
+        //builder.setLCDD(lcdd);
+        //builder.setSensitiveDetector(sens);
+        builder.build(trackingVolume);
+        
+        if(_debug) System.out.printf("%s: DONE setup and build the LCDD geometry\n", getClass().getSimpleName());
+        
+        
+//      makeExample(lcdd,sens);
+//      //makeExample2(lcdd,sens);
+//      makeExample3(lcdd,sens);
+//      makeExample4(lcdd,sens);
+//      makeExample5(lcdd,sens);
+//      makeExample3b(lcdd,sens);
+//      makeExample5b(lcdd,sens);
+//      makeExample6(lcdd,sens);
+//      makeExample66(lcdd,sens);
+//      makeExample7(lcdd,sens);
+//      makeExample77(lcdd,sens);
+//      makeExample8(lcdd, sens);
+//      makeExample9(lcdd, sens);
+//      makeExample10(lcdd, sens);
+//      
+
+        if(buildBeamPlane ) {
+           makeBeamPlane(trackingVolume, lcdd, sens);
+        }
+        
+        
+        // Actually build the LCDD
+        buildLCDD();
+        
+        
+    }
+    
+
+    
+    
+    /**
+     *  Top function to add objects to the LCDD file using the geometry builder class. 
+     */
+    protected void buildLCDD() {
+        
+        if(_debug) System.out.printf("%s: buildLCDD\n", getClass().getSimpleName());
+        
+        // Get a reference to the LCDD
+        LCDD lcdd  = builder.getLCDD();
+        SensitiveDetector sd  = builder.getSensitiveDetector();
+
+        // Reference to the top level object in the builder class
+        // In this case it is the base volume holding the entire tracker
+        LCDDSurveyVolume lcddObj  = (LCDDSurveyVolume) builder.getBaseLCDD();
+        
+        // Add the base volume and all its daughters to the LCDD
+        addToLCDD(lcddObj,lcdd,sd);
+        
+        if(_debug) System.out.printf("%s: buildLCDD DONE\n", getClass().getSimpleName());
+        
+    }
+    
+   
+
+    /**
+     * Add a @LCDDBaseGeom geometry object to the LCDD file.
+     * @param lcddObj to add
+     * @param lcdd file
+     */
+    private void addToLCDD(LCDDSurveyVolume lcddObj, LCDD lcdd, SensitiveDetector sd) {
+        
+        if(_debug) System.out.printf("%s: adding %s to LCDD\n", getClass().getSimpleName(),lcddObj.getName());
+
+        boolean doAdd = true;
+        if(lcddObj.getName().contains("tracking")) doAdd=false;
+        
+        if(doAdd) {
+
+            // only world/tracking volume can be ghost here?!
+            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.");
+            }
+            // add box, pos, rotation and create phys volume
+            lcdd.add(lcddObj.getBox());
+            lcdd.add(lcddObj.getPos());
+            lcdd.add(lcddObj.getRot());
+            lcddObj.buildPhysVolume();
+            // Set the phys volume Id's
+            // Since the builder don't have access to the system ID
+            // I keep the phys volume ID's outside. I think these 
+            // should belong to the builder to avoid repeating it in 
+            // the java converter
+            // TODO move this to the builder for each volume
+            try {
+                setPhysicalVolumeProperties(lcddObj, sd);
+            } catch (DataConversionException e) {
+                e.printStackTrace();
+            }
+        } else {
+            if(_debug) System.out.printf("%s:  skip building anything (name=%s)\n", getClass().getSimpleName(),lcddObj.getName());
+        }
+        
+        // add daughters
+        if(_debug) System.out.printf("%s: add %d daughters to %s\n", getClass().getSimpleName(),lcddObj.getDaughters().size(),lcddObj.getName());
+        for(LCDDSurveyVolume daughter : lcddObj.getDaughters()) {
+            addToLCDD(daughter,lcdd, sd);
+        }
+        
+        // finally add volume
+        if(doAdd) {
+            if(_debug) System.out.printf("%s: adding volume %s\n", getClass().getSimpleName(),lcddObj.getName());
+            if(!lcddObj.getVisName().isEmpty()) lcddObj.getVolume().setVisAttributes(lcdd.getVisAttributes(lcddObj.getVisName()));
+            lcdd.add(lcddObj.getVolume());
+        } else {
+            if(_debug) System.out.printf("%s: skip adding volume %s\n", getClass().getSimpleName(),lcddObj.getName());
+        }
+        if(_debug) System.out.printf("%s: DONE adding %s\n", getClass().getSimpleName(),lcddObj.getName());
+    }
+    
+    
+    /**
+     * Set properties of the physical volume.
+     * @param geometryObject
+     */
+    private void setPhysicalVolumeProperties(LCDDSurveyVolume geometryObject, SensitiveDetector sd) throws DataConversionException {
+        
+        if(_debug) System.out.printf("%s: setPhysVolumeProperties for name %s\n", getClass().getSimpleName(),geometryObject.getName());
+        
+        // the physical vol ID's here are for the <module_placement> TestRunModules
+        // which is essentially the sensor objects
+        String name = geometryObject.getName();
+        if(name.endsWith("halfmodule_axial") || name.endsWith("halfmodule_stereo") ) {
+            PhysVol physVol = geometryObject.getPhysVolume();
+            int sysId = node.getAttribute("id").getIntValue();
+            physVol.addPhysVolID("system", sysId);
+            physVol.addPhysVolID("barrel", 0);
+
+            //use the old definition of layer number to be consistent
+            //int layer = HPSTestRunTracker2014Builder.getLayerFromVolumeName(geometryObject.getName());
+            int layer = HPSTrackerBuilder.getOldGeomDefLayerFromVolumeName(geometryObject.getName());
+            if(_debug) System.out.printf("%s: physVolId layer = %d (compare with new layer %d)\n", getClass().getSimpleName(),layer, HPSTrackerBuilder.getLayerFromVolumeName(geometryObject.getName()));
+
+            
+            geometryObject.getPhysVolume().addPhysVolID("layer", layer);
+            String half = HPSTrackerBuilder.getHalfFromName(geometryObject.getName());
+            if(half.equals("")) throw new RuntimeException("no half was found for name " + geometryObject.getName());
+            int moduleId = half.equals("top") ? 0 : 1;
+            geometryObject.getPhysVolume().addPhysVolID("module", moduleId);
+        }
+        
+        //TODO this is always 0 in old geometry? Is the id0 really needed?
+        else if(name.endsWith("sensor_active")) {
+            geometryObject.getPhysVolume().addPhysVolID("sensor", 0);
+            geometryObject.getVolume().setSensitiveDetector(sd);
+        }
+        //TODO are the component id's really needed?
+        else if(name.endsWith("sensor")) {
+            geometryObject.getPhysVolume().addPhysVolID("component", 0);
+        }
+        else if(name.endsWith("lamination")) {
+            geometryObject.getPhysVolume().addPhysVolID("component", 2);
+        }
+        else if(name.endsWith("cf")) {
+            geometryObject.getPhysVolume().addPhysVolID("component", 1);
+        }
+        else if(name.endsWith("hybrid")) {
+            geometryObject.getPhysVolume().addPhysVolID("component", 3);
+        }
+
+        if(_debug) {
+            System.out.printf("%s: %d physvolid's\n", getClass().getSimpleName(),geometryObject.getPhysVolume().getChildren("physvolid").size());
+            //geomObj.getPhysVolume().getChildren("physvolid field_name="sensor" value="0"")
+            for (Iterator i = geometryObject.getPhysVolume().getChildren("physvolid").iterator(); i.hasNext();) {        
+                Element e = (Element)i.next();
+                System.out.printf("%s: %s %d\n", getClass().getSimpleName(),e.getAttributeValue("field_name"),e.getAttribute("value").getIntValue());
+            }
+        
+        if(_debug) System.out.printf("%s: DONE setPhysVolumeProperties for name %s\n", getClass().getSimpleName(),geometryObject.getName());
+            
+        }
+
+        
+    }
+
+    
+    protected void makeBeamPlane(Volume motherVolume,  LCDD lcdd, SensitiveDetector sens) throws JDOMException {
+        Hep3Vector ball_pos_beamplane = new BasicHep3Vector(-1.0*beamPlaneWidth/2.0,0.0,beamPlaneLength/2.0);
+        Hep3Vector vee_pos_beamplane = new BasicHep3Vector(ball_pos_beamplane.x()+beamPlaneWidth,ball_pos_beamplane.y(),ball_pos_beamplane.z());
+        Hep3Vector flat_pos_beamplane = new BasicHep3Vector(ball_pos_beamplane.x(), ball_pos_beamplane.y(), ball_pos_beamplane.z()-beamPlaneLength/2.0);
+        makeBeamPlane(motherVolume, ball_pos_beamplane, vee_pos_beamplane, flat_pos_beamplane, lcdd, sens);
+    }
+
+    
+    
+    protected void makeBeamPlane(Volume motherVolume, Hep3Vector ball_pos_base_plate, Hep3Vector vee_pos_base_plate,Hep3Vector flat_pos_base_plate, LCDD lcdd, SensitiveDetector sens) throws JDOMException {
+    
+    
+    if(_debug) {
+        System.out.println("--- makeBeamPlane ----");
+        
+    }
+    
+    // create the coordinate system of the beam plane in the tracking volume
+    // since this is a dummy volume it is based on the position of the base plate coordinate system
+    // width - u
+    // length - v
+    // thickness - w
+    Hep3Vector ball_pos_beamplane = ball_pos_base_plate;
+    Hep3Vector vee_pos_beamplane = vee_pos_base_plate; 
+    Hep3Vector flat_pos_beamplane = flat_pos_base_plate;        
+    SurveyCoordinateSystem beamplane_coord = new SurveyCoordinateSystem(ball_pos_beamplane, vee_pos_beamplane, flat_pos_beamplane);     
+    Transform3D trans_beamplane_to_tracking = beamplane_coord.getTransformation();
+    
+    String volName = "beamPlaneVol";
+    //Box box = new Box(volName + "Box", HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_width, HPSTestRunTracker2014GeometryDefinition.TrackerEnvelope.base_length*2, beamPlaneThickness);
+    Box box = new Box(volName + "Box", beamPlaneWidth, beamPlaneLength*2, beamPlaneThickness);
+    lcdd.add(box);
+    Volume volume = new Volume(volName + "_volume", box, lcdd.getMaterial("Vacuum"));
+    
+    
+    if(_debug) {
+        System.out.println(String.format("ball_pos_beamplane %s", ball_pos_beamplane.toString()));
+        System.out.println(String.format("vee_pos_beamplane %s", vee_pos_beamplane.toString()));
+        System.out.println(String.format("flat_pos_beamplane %s", flat_pos_beamplane.toString()));
+        System.out.println(String.format("beamplane_coord:\n%s", beamplane_coord.toString()));
+    }
+
+    
+    // Find distance to center in the local coordinate system 
+    Hep3Vector box_center_base_local = new BasicHep3Vector(beamPlaneWidth/2.0, beamPlaneLength/2.0, beamPlaneThickness/2.0);
+    
+    //translate to the mother coordinate system
+    Hep3Vector box_center_base = trans_beamplane_to_tracking.transformed(box_center_base_local);
+    
+    if(_debug) {
+        System.out.println(String.format("box_center_base_local  %s", box_center_base_local.toString()));
+        System.out.println(String.format("box_center_base        %s", box_center_base.toString()));
+    }
+    
+    // Create the LCDD position
+    Position pos = new Position(volName + "_position",box_center_base.x(), box_center_base.y(), box_center_base.z());
+    
+    //Find LCDD Euler rotation angles from coordinate system unit vectors
+    Hep3Vector lcdd_rot_angles = TransformationUtils.getCardanAngles(beamplane_coord.v(), beamplane_coord.w(), new BasicHep3Vector(0,1,0),new BasicHep3Vector(0,0,1));
+    Rotation rot = new Rotation(volName + "_rotation",lcdd_rot_angles.x(), lcdd_rot_angles.y(), lcdd_rot_angles.z());
+    lcdd.add(pos);
+    lcdd.add(rot);
+    
+    // Create the physical volume
+    PhysVol basePV = new PhysVol(volume, motherVolume, pos, rot);
+    if(_debug) {
+         System.out.println("Created physical vomume " + basePV.getName());
+     }
+    
+     volume.setVisAttributes(lcdd.getVisAttributes("BeamPlaneVis"));
+
+     lcdd.add(volume);
+    
+    }
+    
+    
+   
+    
+    
+    
+}

########################################################################
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