Print

Print


Author: [log in to unmask]
Date: Wed Dec 17 02:09:46 2014
New Revision: 3462

Log:
Cleanup base classes in event package.  Make sure LCMetaData is handled better when reading from LCIO.  Make LCMetaData required in base class constructors.  (And other minor changes and improvements.)

Added:
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasPosition.java
Removed:
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HitWithPosition.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHitWithPosition.java
Modified:
    projects/lcsim/trunk/cal-recon/src/test/java/org/lcsim/recon/cluster/localequivalence/NNAlgoTest.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/CalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/EventHeader.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasMetaData.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/Hit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/RawTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/SimTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseLCSimEvent.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawCalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimCalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/SamplingFractionManager.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOCalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIORawTrackerHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimCalorimeterHit.java
    projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimTrackerHit.java
    projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/recon/calorimetry/ResetCalorimeterHitEnergy.java
    projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/MergeEventTools.java
    projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/OverlayDriver.java
    projects/lcsim/trunk/tracking/src/main/java/org/lcsim/recon/tracking/digitization/sisim/config/SimTrackerHitReadoutDriver.java

Modified: projects/lcsim/trunk/cal-recon/src/test/java/org/lcsim/recon/cluster/localequivalence/NNAlgoTest.java
 =============================================================================
--- projects/lcsim/trunk/cal-recon/src/test/java/org/lcsim/recon/cluster/localequivalence/NNAlgoTest.java	(original)
+++ projects/lcsim/trunk/cal-recon/src/test/java/org/lcsim/recon/cluster/localequivalence/NNAlgoTest.java	Wed Dec 17 02:09:46 2014
@@ -252,7 +252,6 @@
         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     }
 
-    @Override
     public void setMetaData(EventHeader.LCMetaData meta)
     {
         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/CalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/CalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/CalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -14,7 +14,7 @@
  * @author Tony Johnson <[log in to unmask]>
  * @author Jeremy McCormick <[log in to unmask]>
  */
-public interface CalorimeterHit extends HitWithPosition {
+public interface CalorimeterHit extends Hit {
     
    /**
     * Get the raw energy deposition in GeV.

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/EventHeader.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/EventHeader.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/EventHeader.java	Wed Dec 17 02:09:46 2014
@@ -18,11 +18,6 @@
  */
 public interface EventHeader extends MCEvent
 {
-    /**
-     * Get the path to the file source for this event.
-     */
-    //String getInputFile();
-
     /**
      * Get the list of MC particles associated with this event.
      */

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasMetaData.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasMetaData.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasMetaData.java	Wed Dec 17 02:09:46 2014
@@ -12,7 +12,7 @@
 public interface HasMetaData 
 {
     public LCMetaData getMetaData();
-    public void setMetaData(LCMetaData meta);
+    //protected void setMetaData(LCMetaData meta);
 
     // from LCMetaData
     public Subdetector getSubdetector();

Added: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasPosition.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasPosition.java	(added)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/HasPosition.java	Wed Dec 17 02:09:46 2014
@@ -0,0 +1,10 @@
+package org.lcsim.event;
+
+import hep.physics.vec.Hep3Vector;
+
+public interface HasPosition {
+    
+    Hep3Vector getPositionVec();
+    
+    double[] getPosition();
+}

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/Hit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/Hit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/Hit.java	Wed Dec 17 02:09:46 2014
@@ -5,15 +5,17 @@
 import org.lcsim.detector.identifier.Identifiable;
 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
 
-public interface Hit extends HasMetaData, HasDetectorElement, Identifiable
-{
-	DetectorIdentifierHelper getDetectorIdentifierHelper();
+public interface Hit extends HasMetaData, HasDetectorElement, HasPosition, Identifiable {
 	
-	// FIXME: Should these methods using identifier go here?
-	//        All our hits have these fields but not necessarily
-	//        those produced from an external framework like Mokka.
-	int getSystemId();	
-	BarrelEndcapFlag getBarrelEndcapFlag();	
-	int getLayerNumber();	
+    DetectorIdentifierHelper getDetectorIdentifierHelper();
+	
+    // FIXME: I don't think none of this below belongs here!
+    
+	int getSystemId();
+	
+	BarrelEndcapFlag getBarrelEndcapFlag();
+	
+	int getLayerNumber();
+	
 	int getIdentifierFieldValue(String field);
 }

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/RawTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/RawTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/RawTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -8,9 +8,8 @@
  * @author tonyj
  * @version $Id: RawTrackerHit.java,v 1.10 2008/08/20 01:34:21 jeremy Exp $
  */
-public interface RawTrackerHit
-extends Hit
-{
+public interface RawTrackerHit extends Hit {
+    
    /**
     *  Returns a time measurement associated with the adc values.
     *  E.g. the t0 of the spectrum for the TPC. Subdetector dependent.  

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/SimTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/SimTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/SimTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -5,8 +5,8 @@
  * @author Jeremy McCormick
  * @version $Id: SimTrackerHit.java,v 1.21 2011/08/24 18:51:17 jeremy Exp $
  */
-public interface SimTrackerHit extends HitWithPosition
-{
+public interface SimTrackerHit extends Hit {
+    
    /** 
     * Get the layer number of the hit.
     * @return The layer number of the hit. 

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseCalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -1,6 +1,5 @@
 package org.lcsim.event.base;
 
-import hep.physics.vec.BasicHep3Vector;
 import hep.physics.vec.Hep3Vector;
 
 import org.lcsim.detector.IDetectorElement;
@@ -8,18 +7,17 @@
 import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.geometry.IDDecoder;
+import org.lcsim.event.EventHeader.LCMetaData;
 
 /**
  * Base implementation of CalorimeterHit.
  * 
- * @author tonyj
- * @author jeremym
- * @version $Id: BaseCalorimeterHit.java,v 1.18 2013/02/05 00:18:00 jeremy Exp $
+ * @author Tony Johnson <[log in to unmask]>
+ * @author Jeremy McCormick <[log in to unmask]>
  */
-public class BaseCalorimeterHit extends BaseHitWithPosition implements CalorimeterHit
-{
+public class BaseCalorimeterHit extends BaseHit implements CalorimeterHit {
 
-    private static final double UNSET_ENERGY = -1;
+    public static final double UNSET_ENERGY = Double.MIN_VALUE;
     protected double rawEnergy = UNSET_ENERGY;
     protected double correctedEnergy = UNSET_ENERGY;
     protected double energyError;
@@ -27,29 +25,18 @@
     protected long id;
     protected int type;
 
-    protected BaseCalorimeterHit()
-    {
+    protected BaseCalorimeterHit() {
     }
-    
-    public BaseCalorimeterHit(
-            long id,
-            double correctedEnergy,
-            double time)
-    {
-        this.correctedEnergy = correctedEnergy;
-        this.time = time;
-        this.id = id;
-    }
-
-    public BaseCalorimeterHit(
-            double rawEnergy, 
+      
+    public BaseCalorimeterHit(double rawEnergy, 
             double correctedEnergy, 
             double energyError, 
             double time, 
             long id, 
-            Hep3Vector positionVec,
-            int type)
-    {
+            Hep3Vector positionVec, 
+            int type,
+            LCMetaData metaData) {
+        
         this.rawEnergy = rawEnergy;
         this.correctedEnergy = correctedEnergy;
         this.energyError = energyError;
@@ -57,143 +44,83 @@
         this.id = id;
         this.positionVec = positionVec;
         this.type = type;
+        
+        calculateCorrectedEnergy();
+        calculateRawEnergy();
+        
+        setMetaData(metaData);        
     }
 
-    public double getTime()
-    {
+    public double getTime() {
         return time;
     }
 
-    public int getType()
-    {
+    public int getType() {
         return type;
     }
 
-    public double getRawEnergy()
-    {
-        if (rawEnergy == UNSET_ENERGY) {
-            throw new RuntimeException("No raw energy available for CalorimeterHit.");
-        }
+    public double getRawEnergy() {
         return rawEnergy;
     }
-
-    public double[] getPosition()
-    {
-        if (positionVec == null) {
-            calculatePosition();
-        }
-        return super.getPosition();
-    }
-
-    public Hep3Vector getPositionVec()
-    {
-        if (positionVec == null) {
-            calculatePosition();
-        }
-        return super.getPositionVec();
-    }
-
-    public double getCorrectedEnergy()
-    {
-        if (correctedEnergy == UNSET_ENERGY) {
-            calculateCorrectedEnergy();
-        }
+    
+    public double getCorrectedEnergy() {
         return correctedEnergy;
     }
-
-    public long getCellID()
-    {
+      
+    public long getCellID() {
         return id;
     }
 
-    public int getLayerNumber()
-    {
+    public int getLayerNumber() {
         IDDecoder decoder = getIDDecoder();
         decoder.setID(id);
         return decoder.getLayer();
     }
 
-    private void calculateCorrectedEnergy()
-    {
-        getIDDecoder().setID(id);
-        correctedEnergy = SamplingFractionManager.defaultInstance().getCorrectedEnergy(rawEnergy, getIDDecoder().getLayer(), getSubdetector());
+    public IIdentifier getIdentifier() {
+        if (packedID == null) {
+            packedID = new Identifier(id);
+        }
+        return packedID;
     }
 
-    private void calculatePosition()
-    {
-        if (getMetaData() != null) {
-            IDDecoder decoder = getIDDecoder();
-            decoder.setID(id);
-            positionVec = new BasicHep3Vector(decoder.getPosition());
-        } else {
-            throw new RuntimeException("Can't calculate position.  MetaData is null.");
-        }
-    }
-
-    public IIdentifier getIdentifier()
-    {
-        if (compactId == null)
-            compactId = new Identifier(id);
-        return compactId;
-    }
-
-    public double getEnergyError()
-    {
+    public double getEnergyError() {
         return energyError;
     }
 
-    public void setType(int type)
-    {
+    // FIXME: Remove?
+    public void setType(int type) {
         this.type = type;
     }
 
-    public IDetectorElement getDetectorElement()
-    {
-        if (de == null)
-            findDetectorElementByPosition();
-        // setupDetectorElement();
-        return de;
+    public IDetectorElement getDetectorElement() {
+        return detectorElement;
     }
-
-    public void setCorrectedEnergy(double correctedEnergy)
-    {
-        this.correctedEnergy = correctedEnergy;
+             
+    private void calculateCorrectedEnergy() {
+        // Is the corrected energy unset?
+        if (correctedEnergy == UNSET_ENERGY) {
+            getIDDecoder().setID(id);
+            correctedEnergy = SamplingFractionManager.defaultInstance().getCorrectedEnergy(rawEnergy, getIDDecoder().getLayer(), getSubdetector());
+        }
     }
-
-    public void addCorrectedEnergy(double addEnergy)
-    {
-        this.correctedEnergy += addEnergy;
+    
+    private void calculateRawEnergy() {
+        // Is the raw energy unset?
+        if (rawEnergy == UNSET_ENERGY) {
+            getIDDecoder().setID(id);
+            correctedEnergy = SamplingFractionManager.defaultInstance().getRawEnergy(rawEnergy, getIDDecoder().getLayer(), getSubdetector());
+        }
     }
-
+                          
     /**
      * Conversion to String for printout.
-     * 
      * @return String output.
      */
-    public String toString()
-    {
-        StringBuffer sb = new StringBuffer("CalorimeterHitImpl: \n");
-        sb.append("type: " + type + " energy: " + correctedEnergy + " energyError: " + energyError + "\n");
-        sb.append("position: " + positionVec.x() + " " + positionVec.y() + " " + positionVec.z() + "\n");
-        sb.append("id: " + id + " time: " + time);
+    public String toString() {
+        sb.append("type: " + type + ", energy: " + correctedEnergy + ", energyError: " + energyError + ", ");
+        sb.append("position: (" + positionVec.x() + ", " + positionVec.y() + ", " + positionVec.z() + "), ");
+        sb.append("id: 0x" + getIdentifier().toHexString() + ", time: " + time);
         return sb.toString();
     }
 }
-
-/*
- * protected void setupDetectorElement() { Subdetector subdet = meta.getIDDecoder().getSubdetector();
- * IIdentifierHelper helper = subdet.getDetectorElement().getIdentifierHelper(); SegmentationBase seg =
- * (SegmentationBase)subdet.getIDDecoder(); String[] stripFields = seg.getSegmentationFieldNames(); if
- * (stripFields == null) throw new RuntimeException("stripFields is null"); IIdentifierDictionary dict =
- * helper.getIdentifierDictionary(); int nfields = dict.getNumberOfFields(); IExpandedIdentifier expId =
- * helper.unpack(getIdentifier()); for (int i=0; i<nfields; i++) { int idx =
- * dict.getFieldIndex(stripFields[i]); expId.setValue(idx, 0); } de = findDetectorElement(dict.pack(expId));
- * if (de == null) throw new RuntimeException("DetectorElement not found."); }
- * 
- * private static IDetectorElement findDetectorElement(IIdentifier id) {
- * System.out.println("findDetectorElement - " + id.toHexString()); IDetectorElement de = null;
- * IDetectorElementContainer srch = DetectorElementStore.getInstance().find(id); if (srch.size() == 0) { throw
- * new RuntimeException("No DetectorElement found with id <" + id.toHexString() + ">."); } else if
- * (srch.size() == 1) { de = srch.get(0); } else if (srch.size() > 1) { for (IDetectorElement xde : srch) { if
- * (!xde.hasChildren()) { de = xde; break; } } } return de; }
- */

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseHit.java	Wed Dec 17 02:09:46 2014
@@ -1,5 +1,10 @@
 package org.lcsim.event.base;
 
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+
+import org.lcsim.detector.converter.compact.DeDetector;
+import org.lcsim.detector.DetectorElement;
 import org.lcsim.detector.DetectorElementStore;
 import org.lcsim.detector.DetectorIdentifierHelper;
 import org.lcsim.detector.IDetectorElement;
@@ -14,38 +19,49 @@
 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
 
 /**
- * A base class for hit-like objects.
+ * this is a base class for hit-like objects in a detector.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public abstract class BaseHit implements Hit {
     
-    protected LCMetaData meta;
-    protected IExpandedIdentifier expId;
-    protected IIdentifier compactId;
-    protected IDetectorElement de;
-
-    /**
-     * Get the metadata associated with this hit.
-     * 
+    protected LCMetaData metaData;
+    protected IExpandedIdentifier expandedID;
+    protected IIdentifier packedID;
+    protected IDetectorElement detectorElement;
+    protected Hep3Vector positionVec;
+
+    /**
+     * Get the metadata associated with this hit.     
      * @return The hit's metadata.
      */
     public LCMetaData getMetaData() {
-        return meta;
-    }
-
-    /**
-     * Set the metadata associated with this hit. By default, this will not override an existing value.
+        return metaData;
+    }
+
+    /**
+     * Set the metadata associated with this hit.
      */
     public void setMetaData(LCMetaData meta) {
-        if (this.meta == null) {
-            this.meta = meta;
-        }
-    }
-    
-    /**
-     * Get the subdetector that this hit belongs to.
-     * 
+        
+        this.metaData = meta;        
+        
+        if (this.detectorElement == null) {
+            // If the DE is not set yet, try to look it up by ID (might be null).
+            detectorElement = findDetectorElement(getIdentifier());
+        }
+        
+        // Calculate the position of the hit.  Might use DE.
+        calculatePosition();
+        
+        if (this.detectorElement == null) {
+            // If DE is still null, attempt to find it from the position.
+            detectorElement = findDetectorElement(positionVec);
+        }
+    }
+    
+    /**
+     * Get the subdetector of this hit.     
      * @return The Subdetector of this hit.
      */
     public Subdetector getSubdetector() {
@@ -57,20 +73,16 @@
      * @return The IDetectorElement for this hit.
      */
     public IDetectorElement getDetectorElement() {
-    	if (de == null) {
-    		findDetectorElementByIdentifier();
-    	}
-        return de;
+        return detectorElement;
     }
     
     /**
      * Set the @see org.lcsim.detector.IDetectorElement of this hit. By default, this will not override an
      * existing value.
      */
+    // FIXME: This probably should not be in the public API.  Where is this actually called from?
     public void setDetectorElement(IDetectorElement de) {
-        if (this.de == null) {
-            this.de = de;
-        }
+        this.detectorElement = de;        
     }
 
     /**
@@ -78,10 +90,10 @@
      * @return The expanded identifier of this hit.
      */
     public IExpandedIdentifier getExpandedIdentifier() {
-        if (expId == null) {
-            expId = getIdentifierHelper().unpack(getIdentifier());
-        }
-        return expId;
+        if (expandedID == null) {
+            expandedID = getIdentifierHelper().unpack(getIdentifier());
+        }
+        return expandedID;
     }
 
     /**
@@ -89,7 +101,7 @@
      * @return The identifier of this hit.
      */
     public IIdentifier getIdentifier() {
-        return compactId;
+        return packedID;
     }
 
     /**
@@ -113,7 +125,7 @@
      * @return The hit's id decoder.
      */
     public IDDecoder getIDDecoder() {
-        return meta.getIDDecoder();
+        return metaData.getIDDecoder();
     }
 
     /**
@@ -147,45 +159,84 @@
     public int getIdentifierFieldValue(String field) {
         return getIdentifierHelper().getValue(getIdentifier(), field);
     }
-
-    /**
-     * Use the {@link IIdentifier} associated with this hit to find its DetectorElement
-     * in the geometry hierarchy and set a member variable to point to it.
-     */
-    protected void findDetectorElementByIdentifier() {
-        if (this.de == null) {
-            IDetectorElementContainer srch = DetectorElementStore.getInstance().find(getIdentifier());
-
-            if (srch.size() == 0) {
-                throw new RuntimeException("No DetectorElement found for SimTrackerHit with id <" + getIdentifier().toHexString() + ">.");
-            }
-
-            if (srch.size() == 1) {
-                this.de = srch.get(0);
-            }
-
-            // This can happen sometimes, because the identifiers are not guaranteed to be unique.
-            if (srch.size() > 1) {
-                // Pick the first leaf DetectorElement.
-                for (IDetectorElement xde : srch) {
-                    if (!xde.hasChildren()) {
-                        this.de = xde;
-                        break;
+                  
+    /**    
+     * Get the position of the hit.  This may be different than the position of the hit's DetectorElement.
+     * @return The position of this hit as a double array of size 3.
+     */
+    public double[] getPosition() {
+        return positionVec.v();
+    }
+    
+    /**
+     * Get the position of this hit in mm as a {@see hep.physics.vec.Hep3Vector}.
+     * @return The position vector of the hit in mm.
+     */
+    public Hep3Vector getPositionVec() { 
+        return positionVec;
+    }       
+    
+    /**
+     * Calculate the position of the hit, depending on what variables are available on the object.
+     */
+    protected void calculatePosition() { 
+        // Was there no position information provided explicitly? 
+        if (positionVec == null) {                 
+            // Does the hit ID match the DetectorElement exatly?
+            if (this.detectorElement != null && this.detectorElement.getIdentifier().equals(getIdentifier())) {
+                // Set the position from the DetectorElement.
+                this.positionVec = detectorElement.getGeometry().getPosition();
+            } else {
+                // This is what should happen for IDs with virtual cell values.
+                // The IDDecoder needs to be used here if it is set on the hit.
+                if (this.metaData != null) {
+                    IDDecoder decoder = this.getIDDecoder();
+                    if (decoder != null) {
+                        decoder.setID(this.getIdentifier().getValue());
+                        this.positionVec = new BasicHep3Vector(decoder.getPosition());
                     }
                 }
             }
         }
     }
-
-    /**
-     * Setup link to the DetectorElement using the hit's ID.
-     */
-    protected void setupDetectorElement() {                    
-        try {
-            
-            //System.out.println("Assigned DetectorElement <" + de.getName() + "> to hit.");
-        } catch (RuntimeException x) {
-            throw new RuntimeException("Failed to find DetectorElement for hit.");
-        }        
-    }
-}
+    
+    /**
+     * Find a DetectorElement by global position.
+     * @param position The global position.
+     * @return The DetectorElement at position.
+     */
+    private IDetectorElement findDetectorElement(Hep3Vector position) {
+        IDetectorElement mommy;
+        if (this.metaData != null) {
+            // Use subdetector's volume as top.
+            mommy = this.getIDDecoder().getSubdetector().getDetectorElement();
+        } else {
+            // Use the world volume.
+            mommy = ((DetectorElement) DetectorElementStore.getInstance().get(0)).getTop().findDetectorElement(getPositionVec());
+        }            
+        return mommy.findDetectorElement(this.positionVec);       
+    }
+    
+    /**
+     * Find a DetectorElement by its identifier.
+     * @param id The identifier.
+     * @return The DetectorElement matching the identifier.
+     */
+    private IDetectorElement findDetectorElement(IIdentifier id) {
+        IDetectorElement mommy;
+        if (this.metaData != null) {
+            // Use subdetector's volume as top.
+            mommy = this.getIDDecoder().getSubdetector().getDetectorElement();
+        } else {
+            // Use the world volume.
+            mommy = ((DetectorElement) DetectorElementStore.getInstance().get(0)).getTop();
+        }       
+        IDetectorElementContainer detectorElements = mommy.findDetectorElement(id);
+        // FIXME: Beware! The container can be null, which should be fixed at some point (detector-framework).
+        if (detectorElements != null && detectorElements.size() == 1) {
+            return detectorElements.get(0); 
+        } else {
+            return null;
+        }
+    }
+}

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseLCSimEvent.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseLCSimEvent.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseLCSimEvent.java	Wed Dec 17 02:09:46 2014
@@ -153,12 +153,14 @@
     }
 
     private void setCollectionMetaData(List collection, Class type, LCMetaData meta) {
-        // System.out.println("setCollectionMetaData");
         // Set MetaData on collection objects.
         if (HasMetaData.class.isAssignableFrom(type)) {
             for (Object o : collection) {
-                if (o instanceof HasMetaData) {
-                    ((HasMetaData) o).setMetaData(meta);
+                if (o instanceof BaseHit) {
+                    BaseHit hit = (BaseHit) o;
+                    if (hit.getMetaData() == null) {
+                        ((BaseHit) o).setMetaData(meta);
+                    }
                 }
             }
         }

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawCalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawCalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawCalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -9,7 +9,7 @@
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
-public class BaseRawCalorimeterHit extends BaseHitWithPosition implements RawCalorimeterHit {
+public class BaseRawCalorimeterHit extends BaseHit implements RawCalorimeterHit {
 
     long id;
     int amplitude;
@@ -22,14 +22,14 @@
         this.id = id;
         this.amplitude = amplitude;
         this.timestamp = timestamp;
-        this.compactId = new Identifier(id);
+        this.packedID = new Identifier(id);
     }
 
     public BaseRawCalorimeterHit(long id, int amplitude, int timestamp, IDetectorElement de) {
         this.id = id;
         this.amplitude = amplitude;
         this.timestamp = timestamp;
-        this.de = de;
+        this.detectorElement = de;
     }
 
     public long getCellID() {

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseRawTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -15,10 +15,8 @@
  * @author Jeremy McCormick <[log in to unmask]>
  * @version $Id: BaseRawTrackerHit.java,v 1.13 2012/03/14 00:48:43 jeremy Exp $
  */
-public class BaseRawTrackerHit
-extends BaseHit
-implements RawTrackerHit
-{
+public class BaseRawTrackerHit extends BaseHit implements RawTrackerHit {
+    
     protected int time;
     protected long cellId;
     protected short[] adcValues;
@@ -29,7 +27,7 @@
     		int time,
     		short[] adcValues) {
     	this.cellId = id;
-    	this.compactId = new Identifier(id);
+    	this.packedID = new Identifier(id);
     	this.time = time;
     	this.adcValues = adcValues;
     }
@@ -45,8 +43,8 @@
         this.cellId = cellId;
         this.adcValues = adcValues;
         this.simTrackerHits = simTrackerHits;
-        this.compactId = new Identifier(cellId);
-        this.de = detectorElement;
+        this.packedID = new Identifier(cellId);
+        this.detectorElement = detectorElement;
     }
     
     /**
@@ -82,9 +80,9 @@
     {
 
         IIdentifierHelper helper = null;
-        if (de != null) 
+        if (detectorElement != null) 
         {
-            helper = de.getIdentifierHelper();
+            helper = detectorElement.getIdentifierHelper();
         }
         else if (simTrackerHits != null && simTrackerHits.size() > 0)
         {

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimCalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimCalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimCalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -5,46 +5,35 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.lcsim.detector.DetectorElementStore;
-import org.lcsim.detector.IDetectorElement;
-import org.lcsim.detector.IDetectorElementContainer;
-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.event.EventHeader.LCMetaData;
 import org.lcsim.event.MCParticle;
 import org.lcsim.event.SimCalorimeterHit;
-import org.lcsim.geometry.Subdetector;
-import org.lcsim.geometry.segmentation.SegmentationBase;
 
-public class BaseSimCalorimeterHit extends BaseCalorimeterHit implements SimCalorimeterHit
-{
+public class BaseSimCalorimeterHit extends BaseCalorimeterHit implements SimCalorimeterHit {
     protected int nContributions;
     protected Object[] particle;
     protected float[] energyContrib;
-    protected float[] times; 
+    protected float[] times;
     protected int[] pdg;
     protected List<float[]> steps;
-    
-    protected BaseSimCalorimeterHit()
-    {}
-    
-    public BaseSimCalorimeterHit(
-            long id, 
+
+    protected BaseSimCalorimeterHit() {
+    }
+
+    public BaseSimCalorimeterHit(long id, 
             double rawEnergy, 
             double time, 
             Object[] mcparts, 
             float[] energies, 
             float[] times, 
-            int[] pdgs)
-    {
+            int[] pdgs,
+            LCMetaData meta) {
         // Base class fields.
         super.id = id;
         super.rawEnergy = rawEnergy;
         super.time = time;
-        super.positionVec = null;        
-        
+        super.positionVec = null;
+
         // MCParticle contributions.
         this.nContributions = mcparts.length;
         this.particle = mcparts;
@@ -52,104 +41,91 @@
         this.times = times;
         this.pdg = pdgs;
         this.steps = new ArrayList(nContributions);
+        
+        setMetaData(meta);
     }
-    
+
     /**
      * New ctor with step positions.
      */
-    public BaseSimCalorimeterHit(
-            long id, 
+    public BaseSimCalorimeterHit(long id, 
             double rawEnergy, 
             double time, 
             Object[] mcparts, 
             float[] energies, 
             float[] times, 
-            int[] pdgs,
-            List<float[]> steps)
-    {
+            int[] pdgs, 
+            List<float[]> steps,
+            LCMetaData meta) {
         // Base class fields.
         super.id = id;
         super.rawEnergy = rawEnergy;
         super.time = time;
-        super.positionVec = null;        
-        
+        super.positionVec = null;
+
         // MCParticle contributions.
         this.nContributions = mcparts.length;
         this.particle = mcparts;
         this.energyContrib = energies;
         this.times = times;
         this.pdg = pdgs;
-        this.steps = steps;        
+        this.steps = steps;
+        
+        setMetaData(meta);
     }
-    
-    public void shiftTime(double time)
-    {
-    	super.time = this.getTime() + time;
-    	for (int i=0; i<times.length; i++)
-    	{
-    		times[i] += time;
-    	}    	
+
+    public void shiftTime(double time) {
+        super.time = this.getTime() + time;
+        for (int i = 0; i < times.length; i++) {
+            times[i] += time;
+        }
     }
-   
-    public double getTime()
-    {
+
+    public double getTime() {
         // First check for explicit value that has been set.
-        if (super.time != 0) return super.time;
-        
+        if (super.time != 0)
+            return super.time;
+
         // If the times array is empty, then there is no valid time to find.
-        if (times.length == 0) return 0;        
-        
+        if (times.length == 0)
+            return 0;
+
         // Find the earliest time from the array.
         double t = times[0];
-        for (int i=1; i<times.length; i++)
-        {
-            t = Math.min(t,times[i]);
+        for (int i = 1; i < times.length; i++) {
+            t = Math.min(t, times[i]);
         }
-        
+
         // Cache the minimum time value to avoid repeating the above calculation.
         super.time = t;
-        
+
         return t;
     }
-    
-    public MCParticle getMCParticle(int index)
-    {
+
+    public MCParticle getMCParticle(int index) {
         Object p = particle[index];
-        if (p instanceof SIORef) p = ((SIORef) p).getObject();
+        if (p instanceof SIORef)
+            p = ((SIORef) p).getObject();
         return (MCParticle) p;
-    }      
+    }
 
-    public double getContributedEnergy(int index)
-    {
+    public double getContributedEnergy(int index) {
         return energyContrib[index];
     }
 
-    public int getPDG(int index)
-    {
+    public int getPDG(int index) {
         return pdg[index];
     }
 
-    public double getContributedTime(int index)
-    {
+    public double getContributedTime(int index) {
         return times[index];
     }
-    
-    public float[] getStepPosition(int index)
-    {
+
+    public float[] getStepPosition(int index) {
         return steps.get(index);
     }
 
-    public int getMCParticleCount()
-    {
+    public int getMCParticleCount() {
         return particle.length;
     }
-    
-    /**
-     * Set the metadata associated with this hit. By default, this will not override an existing value.
-     */
-    public void setMetaData(LCMetaData meta) {
-        super.setMetaData(meta);
-        setupDetectorElement();
-    }
-    
-}
+}

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseSimTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -13,11 +13,12 @@
 
 /**
  * A concrete implementation of SimTrackerHit.
+ * 
  * @author Jeremy McCormick
  * @version $Id: BaseSimTrackerHit.java,v 1.19 2012/07/20 09:29:43 grefe Exp $
  */
-public class BaseSimTrackerHit extends BaseHitWithPosition implements SimTrackerHit
-{
+public class BaseSimTrackerHit extends BaseHit implements SimTrackerHit {
+    
     protected double[] position = new double[3];
     protected double[] momentum = new double[3];
     protected MCParticle mcparticle;
@@ -28,15 +29,16 @@
     protected long id;
     protected double pathLength;
     private Hep3Vector startPoint, endPoint;
-    
+
     /**
      * Constructor for subclasses
      */
-    protected BaseSimTrackerHit()
-    {}
-    
+    protected BaseSimTrackerHit() {
+    }
+
     /**
      * Fully qualified constructor
+     * 
      * @param position The center point of the hit in Cartesian coordinates (x,y,z).
      * @param momentum The momentum of the hit in GeV (px,py,pz).
      * @param mcparticle The associated MCParticle. (may be null)
@@ -47,35 +49,24 @@
      * @param meta The LCMetaData associated to this hit. (may be null)
      * @param de The DetectorElement associated to this hit. (may be null)
      */
-    public BaseSimTrackerHit(
-            double[] position, 
-            double dEdx, 
-            double[] momentum, 
-            double pathLength, 
-            double time, 
-            int cellID, 
-            MCParticle mcparticle,
-            LCMetaData meta,
-            IDetectorElement de)
-    {
-        super(position);
+    public BaseSimTrackerHit(double[] position, double dEdx, double[] momentum, double pathLength, double time, int cellID, MCParticle mcparticle, LCMetaData meta, IDetectorElement de) {
         
+        positionVec = new BasicHep3Vector(position[0], position[1], position[2]);
+
         if (position.length != 3)
             throw new IllegalArgumentException("The position array is of the wrong size!");
-        for (int i=0, n=this.position.length; i < n; i++)
-        {
+        for (int i = 0, n = this.position.length; i < n; i++) {
             this.position[i] = position[i];
-        }                
-        
+        }
+
         if (momentum == null)
             throw new IllegalArgumentException("The momentum points to null!");
         if (momentum.length != 3)
             throw new IllegalArgumentException("The momentum array is of the wrong size!");
-        for (int i=0, n=this.momentum.length; i < n; i++)
-        {
+        for (int i = 0, n = this.momentum.length; i < n; i++) {
             this.momentum[i] = momentum[i];
         }
-        
+
         this.mcparticle = mcparticle;
         this.time = time;
         this.dEdx = dEdx;
@@ -83,107 +74,89 @@
         // TODO need to properly set a 64bit ID
         this.id = (long) cellID;
         this.pathLength = pathLength;
-        this.meta = meta;
-        this.de = de;        
+        this.metaData = meta;
+        this.detectorElement = de;
     }
-    
-    /**
-     * Set the metadata associated with this hit. By default, this will not override an existing value.
-     */
-    public void setMetaData(LCMetaData meta) {
-        super.setMetaData(meta);
-        findDetectorElementByIdentifier();
+
+    public void setTime(double time) {
+        this.time = time;
     }
-    
-    public void setTime(double time) {
-		this.time = time;
-	}
-    
-    public int getLayer()
-    {
+
+    public int getLayer() {
         getIDDecoder().setID(getCellID());
         return getIDDecoder().getLayer();
     }
-    
-    public double[] getPoint() 
-    {
+
+    public double[] getPoint() {
         return positionVec.v();
     }
-    
-//    public double[] getPosition()
-//    {
-//    	return getPoint();
-//    }
 
-    public double getTime() 
-    {
+    public double getTime() {
         return time;
     }
 
-    public double getdEdx() 
-    {
+    public double getdEdx() {
         return dEdx;
     }
 
-    public MCParticle getMCParticle() 
-    {
+    public MCParticle getMCParticle() {
         return mcparticle;
     }
 
-    // @Deprecated 
+    // @Deprecated
     // Use {@link #getCellID64()} instead.
-    public int getCellID() 
-    {
-        return cellID0;        
+    public int getCellID() {
+        return cellID0;
     }
-    
-    public long getCellID64()
-    {
+
+    public long getCellID64() {
         return id;
     }
-    
+
     public void setCellID64(long cellID) {
-		id = cellID;
-	}
-      
-    public double getPathLength() 
-    {
+        id = cellID;
+    }
+
+    public double getPathLength() {
         return pathLength;
     }
 
-    public double[] getMomentum() 
-    {
+    public double[] getMomentum() {
         return momentum;
-    }    
+    }
 
-    public double[] getStartPoint() 
-    { 
+    public double[] getStartPoint() {
         if (startPoint == null)
             computePoints();
         return startPoint.v();
     }
 
-    public double[] getEndPoint() 
-    {
+    public double[] getEndPoint() {
         if (endPoint == null)
             computePoints();
         return endPoint.v();
     }
-    
-    private void computePoints()
-    {
+
+    private void computePoints() {
         Hep3Vector midpoint = new BasicHep3Vector(getPoint());
         Hep3Vector direction = VecOp.unit(new BasicHep3Vector(getMomentum()));
-        Hep3Vector half_length = VecOp.mult(getPathLength()/2.0,direction);
+        Hep3Vector halfLength = VecOp.mult(getPathLength() / 2.0, direction);
 
-        startPoint = VecOp.add(midpoint,VecOp.mult(-1.0,half_length));
-        endPoint = VecOp.add(midpoint,half_length);
+        startPoint = VecOp.add(midpoint, VecOp.mult(-1.0, halfLength));
+        endPoint = VecOp.add(midpoint, halfLength);
+    }
+
+    public IIdentifier getIdentifier() {
+        if (packedID == null)
+            packedID = new Identifier(id);
+        return packedID;
     }    
     
-    public IIdentifier getIdentifier()
-    {
-    	if (compactId == null)
-    		compactId = new Identifier(id);
-    	return compactId;
+    /**
+     * Get the {@see org.lcsim.detector.IDetectorElement} associated with this hit.     
+     * @return The IDetectorElement for this hit.
+     */
+    public IDetectorElement getDetectorElement() {
+        return detectorElement;
     }
-}
+}

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/BaseTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -14,200 +14,201 @@
 import org.lcsim.event.TrackerHit;
 
 /**
- * // TODO add methods to add hits to this object.
- * // TODO decide what these hits should be.
+ * // TODO add methods to add hits to this object. // TODO decide what these hits should be.
+ * 
  * @author Norman Graf
  */
-public class BaseTrackerHit implements TrackerHit
-{
+public class BaseTrackerHit implements TrackerHit {
     protected double[] _pos = new double[3];
     protected double[] _covMatrix = new double[6];
     protected double _time;
     protected double _dedx;
-    //TODO set up an enumeration to replace the integer type
+    // TODO set up an enumeration to replace the integer type
     protected int _type;
-    //TODO decide what this is a list of
-    //TODO decide whether this should be a Set
+    // TODO decide what this is a list of
+    // TODO decide whether this should be a Set
     protected List _rawHits = new ArrayList();
     protected long id;
-    
+
     /** Creates a new instance of BaseTrackerHit */
-    public BaseTrackerHit()
-    {}    
-   
+    public BaseTrackerHit() {
+    }
+
     /**
      * fully qualified constructor
-     * @param pos the position of this hit (x,y,z) in mm
-     * @param cov the covariance matrix for the position measurement, packed as 6 elements.
-     * @param t the time for this measurement in ns
-     * @param e the energy deposit associated with this measurement, in GeV
-     * @param type the type of this measurement. not yet defined.
-     */
-    public BaseTrackerHit(double[] pos, double[] cov, double t, double e, int type)
-    {
+     * 
+     * @param pos
+     *            the position of this hit (x,y,z) in mm
+     * @param cov
+     *            the covariance matrix for the position measurement, packed as 6 elements.
+     * @param t
+     *            the time for this measurement in ns
+     * @param e
+     *            the energy deposit associated with this measurement, in GeV
+     * @param type
+     *            the type of this measurement. not yet defined.
+     */
+    public BaseTrackerHit(double[] pos, double[] cov, double t, double e, int type) {
         _pos = pos;
         _covMatrix = cov;
         _time = t;
         _dedx = e;
         _type = type;
     }
-    
+
     // include these setters since I don't know what the final inheriting classes will
     // look like.
     /**
      * The (x,y,z) position of this measurement.
-     * @param pos the position of this hit (x,y,z) in mm 
-     */
-    public void setPosition(double[] pos)
-    {
+     * 
+     * @param pos
+     *            the position of this hit (x,y,z) in mm
+     */
+    public void setPosition(double[] pos) {
         _pos = pos;
     }
-    
+
     /**
      * The covariance matrix for the position measurement.
-     * @param cov Packed array representing the symmetric covariance matrix (6 elements).
-     */
-    public void setCovarianceMatrix( double[] cov)
-    {
+     * 
+     * @param cov
+     *            Packed array representing the symmetric covariance matrix (6 elements).
+     */
+    public void setCovarianceMatrix(double[] cov) {
         _covMatrix = cov;
     }
-    
+
     /**
      * The time at which this measurement was made.
-     * @param t the time in ns.
-     */
-    public void setTime(double t)
-    {
+     * 
+     * @param t
+     *            the time in ns.
+     */
+    public void setTime(double t) {
         _time = t;
     }
-    
+
     /**
      * The energy deposit associated with this measurement.
-     * @param e The energy in GeV.
-     */
-    public void setEnergy(double e)
-    {
+     * 
+     * @param e
+     *            The energy in GeV.
+     */
+    public void setEnergy(double e) {
         _dedx = e;
     }
-    
+
     /**
      * The type of this measurement.
-     * @param type Not yet defined.
-     */
-    public void setType(int type)
-    {
+     * 
+     * @param type
+     *            Not yet defined.
+     */
+    public void setType(int type) {
         _type = type;
     }
-    
+
     /**
      * Add the RawTrackerHit from which this TrackerHit originates
-     * @param hit 
-     */
-    public void addRawTrackerHit(RawTrackerHit hit)
-    {
+     * 
+     * @param hit
+     */
+    public void addRawTrackerHit(RawTrackerHit hit) {
         _rawHits.add(hit);
     }
-    
+
     /**
      * Add the list of RawTrackerHits from which this TrackerHit originates
-     * @param hits 
-     */
-    public void addRawTrackerHits(List<RawTrackerHit> hits)
-    {
+     * 
+     * @param hits
+     */
+    public void addRawTrackerHits(List<RawTrackerHit> hits) {
         _rawHits.addAll(hits);
-    }    
-    
+    }
 
     // TODO consider customizing based on hit type.
-    public String toString()
-    {
+    public String toString() {
         String className = getClass().getName();
         int lastDot = className.lastIndexOf('.');
-        if(lastDot!=-1)className = className.substring(lastDot+1);
-        StringBuffer sb = new StringBuffer(className+": Type: "+_type+"\n");
-        sb.append("(x,y,z): "+_pos[0]+" "+_pos[1]+" "+_pos[2]+"\n");
+        if (lastDot != -1)
+            className = className.substring(lastDot + 1);
+        StringBuffer sb = new StringBuffer(className + ": Type: " + _type + "\n");
+        sb.append("(x,y,z): " + _pos[0] + " " + _pos[1] + " " + _pos[2] + "\n");
         // TODO add in covariance matrix
-        sb.append("dEdx: "+_dedx+" t: "+_time+"\n");
+        sb.append("dEdx: " + _dedx + " t: " + _time + "\n");
         return sb.toString();
     }
-    
+
     // TODO add convenience methods which extend the base interface.
     // TODO return position as SpacePoint
     // TODO return covariance matrix as Matrix
-    
-//TrackerHit interface
+
+    // TrackerHit interface
     /**
      * The (x,y,z) hit position in [mm].
+     * 
      * @return the cartesian position of this point.
      */
-    public double[] getPosition()
-    {
+    public double[] getPosition() {
         return _pos;
     }
-    
+
     /**
      * Covariance of the position (x,y,z) as a 6 element array.
+     * 
      * @return the packed covariance matrix
      */
-    public double[] getCovMatrix()
-    {
+    public double[] getCovMatrix() {
         return _covMatrix;
     }
-    
+
     /**
      * The energy deposited by this hit in [GeV].
+     * 
      * @return the energy deposit associated with this hit.
      */
-    public double getdEdx()
-    {
+    public double getdEdx() {
         return _dedx;
     }
-    
-    /**
-     * The  time of the hit in [ns]. By convention, the earliest time of 
-     * energy deposition is used if this is a composite hit.
+
+    /**
+     * The time of the hit in [ns]. By convention, the earliest time of energy deposition is used if this is a composite hit.
+     * 
      * @return the time of this hit.
      */
-    public double getTime()
-    {
+    public double getTime() {
         return _time;
     }
-    
-    public double getEdepError()
-    {
+
+    public double getEdepError() {
         return 0.;
     }
-    
-    public int getQuality()
-    {
+
+    public int getQuality() {
         return 0;
     }
-    
-    /**
-     * Type of hit. Mapping of integer types to type names
-     * through collection parameters "TrackerHitTypeNames"
-     * and "TrackerHitTypeValues".
+
+    /**
+     * Type of hit. Mapping of integer types to type names through collection parameters "TrackerHitTypeNames" and "TrackerHitTypeValues".
+     * 
      * @return the integer type of this hit.
      */
     // TODO define what this type is.
-    public int getType()
-    {
+    public int getType() {
         return _type;
     }
-    
+
     // TODO fix the covariant return type.
     /**
-     * The raw data hits.
-     * Check getType() to get actual data type.
+     * The raw data hits. Check getType() to get actual data type.
+     * 
      * @return the list of raw hits which contribute to this hit.
      */
-    public List getRawHits()
-    {
+    public List getRawHits() {
         return _rawHits;
     }
-    
-    public long getCellID()
-    {
+
+    public long getCellID() {
         return id;
-    }      
+    }
 }

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/SamplingFractionManager.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/SamplingFractionManager.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/event/base/SamplingFractionManager.java	Wed Dec 17 02:09:46 2014
@@ -10,95 +10,91 @@
 import org.lcsim.geometry.Subdetector;
 
 /**
- * Currently assumes that each subdetector has a single sampling fraction. This
- * is obviously not true if the subdetector has more than one layering scheme,
- * or if a single "subdetector" represents more than one physical detector (e.g.
- * barrel and endcap).
+ * Currently assumes that each subdetector has a single sampling fraction. This is obviously not true if the subdetector has more than one layering scheme, or if a single "subdetector" represents more
+ * than one physical detector (e.g. barrel and endcap).
  *
  * @author tonyj
  */
-public class SamplingFractionManager
-{
-   private static SamplingFractionManager theSamplingFractionManager = new SamplingFractionManager();
-   private ConditionsManager manager;
-   
-   private SamplingFractionManager()
-   {
-      manager = ConditionsManager.defaultInstance();
-      manager.registerConditionsConverter(new SamplingFractionConverter());
-   }
-   
-   public static SamplingFractionManager defaultInstance()
-   {
-      return theSamplingFractionManager;
-   }
-   
-   public double getCorrectedEnergy(double rawEnergy, int layer, Subdetector detector)
-   {
-      SamplingFraction sf = manager.getCachedConditions(SamplingFraction.class,"SamplingFractions/" + detector.getName()).getCachedData();
-      return sf.getCorrectedEnergy(rawEnergy,layer);
-   }
-   private static class SamplingFraction
-   {
-      private final double defaultSamplingFraction;
-      private final boolean digital;
-      private final Map<Integer,Double> layerMap = new HashMap<Integer,Double>();
-      
-      private SamplingFraction(ConditionsSet set)
-      {
-         defaultSamplingFraction = set.getDouble("samplingFraction");
-         digital = set.getBoolean("digital",false);
-         Pattern pattern = Pattern.compile("samplingFraction\\[((\\d+(-\\d+)?)(,\\d+(-\\d+)?)*)\\]");
-         Pattern p2 = Pattern.compile(",?(\\d+)(-(\\d+))?");
-         
-         for (Object o : set.keySet())
-         {
-            String key = o.toString();
+public class SamplingFractionManager {
+    
+    private static SamplingFractionManager theSamplingFractionManager = new SamplingFractionManager();
+    private ConditionsManager manager;
 
-            // Get rid of embedded whitespace, and match
-            Matcher matcher = pattern.matcher(key.replaceAll("\\s",""));
-            if (matcher.matches())
-            {
-               double s = set.getDouble(key);
-               String layers = matcher.group(1);
-               Matcher m2 = p2.matcher(layers);
-               while (m2.find())
-               {
-                  int start = Integer.parseInt(m2.group(1));
-                  int end = m2.group(3) == null ? -1 : Integer.parseInt(m2.group(3));
-                  if (end > start)
-                  {
-                     for (int i=start; i<=end; i++)
-                     {
-                        layerMap.put(i,s);
-                     }
-                  }
-                  else
-                  {
-                     layerMap.put(start,s);
-                  }
-               }
+    private SamplingFractionManager() {
+        manager = ConditionsManager.defaultInstance();
+        manager.registerConditionsConverter(new SamplingFractionConverter());
+    }
+
+    public static SamplingFractionManager defaultInstance() {
+        return theSamplingFractionManager;
+    }
+
+    public double getCorrectedEnergy(double rawEnergy, int layer, Subdetector detector) {
+        SamplingFraction sf = manager.getCachedConditions(SamplingFraction.class, "SamplingFractions/" + detector.getName()).getCachedData();
+        return sf.getCorrectedEnergy(rawEnergy, layer);
+    }
+    
+    public double getRawEnergy(double correctedEnergy, int layer, Subdetector detector) {
+        SamplingFraction sf = manager.getCachedConditions(SamplingFraction.class, "SamplingFractions/" + detector.getName()).getCachedData();
+        return sf.getRawEnergy(correctedEnergy, layer);
+    }
+
+    private static class SamplingFraction {
+        private final double defaultSamplingFraction;
+        private final boolean digital;
+        private final Map<Integer, Double> layerMap = new HashMap<Integer, Double>();
+
+        private SamplingFraction(ConditionsSet set) {
+            defaultSamplingFraction = set.getDouble("samplingFraction");
+            digital = set.getBoolean("digital", false);
+            Pattern pattern = Pattern.compile("samplingFraction\\[((\\d+(-\\d+)?)(,\\d+(-\\d+)?)*)\\]");
+            Pattern p2 = Pattern.compile(",?(\\d+)(-(\\d+))?");
+
+            for (Object o : set.keySet()) {
+                String key = o.toString();
+
+                // Get rid of embedded whitespace, and match
+                Matcher matcher = pattern.matcher(key.replaceAll("\\s", ""));
+                if (matcher.matches()) {
+                    double s = set.getDouble(key);
+                    String layers = matcher.group(1);
+                    Matcher m2 = p2.matcher(layers);
+                    while (m2.find()) {
+                        int start = Integer.parseInt(m2.group(1));
+                        int end = m2.group(3) == null ? -1 : Integer.parseInt(m2.group(3));
+                        if (end > start) {
+                            for (int i = start; i <= end; i++) {
+                                layerMap.put(i, s);
+                            }
+                        } else {
+                            layerMap.put(start, s);
+                        }
+                    }
+                }
             }
-         }
-      }
-      double getCorrectedEnergy(double rawEnergy, int layer)
-      {
-         Double layerSF = layerMap.get(layer);
-         double samplingFraction = layerSF == null ? defaultSamplingFraction : layerSF;
-         return (digital ? 1 : rawEnergy)/samplingFraction;
-      }
-   }
-   private static class SamplingFractionConverter implements ConditionsConverter<SamplingFraction>
-   {
-      public Class<SamplingFractionManager.SamplingFraction> getType()
-      {
-         return SamplingFraction.class;
-      }
+        }
 
-      public SamplingFractionManager.SamplingFraction getData(ConditionsManager manager, String name)
-      {
-         ConditionsSet conditions = manager.getConditions(name);
-         return new SamplingFraction(conditions);
-      }
-   }
+        double getCorrectedEnergy(double rawEnergy, int layer) {
+            Double layerSF = layerMap.get(layer);
+            double samplingFraction = layerSF == null ? defaultSamplingFraction : layerSF;
+            return (digital ? 1 : rawEnergy) / samplingFraction;
+        }
+
+        double getRawEnergy(double correctedEnergy, int layer) {
+            Double layerSF = layerMap.get(layer);
+            double samplingFraction = layerSF == null ? defaultSamplingFraction : layerSF;
+            return (digital ? 1 : correctedEnergy) * samplingFraction;
+        }
+    }
+
+    private static class SamplingFractionConverter implements ConditionsConverter<SamplingFraction> {
+        public Class<SamplingFractionManager.SamplingFraction> getType() {
+            return SamplingFraction.class;
+        }
+
+        public SamplingFractionManager.SamplingFraction getData(ConditionsManager manager, String name) {
+            ConditionsSet conditions = manager.getConditions(name);
+            return new SamplingFraction(conditions);
+        }
+    }
 }

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOCalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOCalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOCalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -18,7 +18,6 @@
 class SIOCalorimeterHit extends BaseCalorimeterHit {
 
     SIOCalorimeterHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException {
-        this.meta = meta;
         int cellid0 = in.readInt();
         int cellid1 = 0;
         if (LCIOUtil.bitTest(flags, LCIOConstants.RCHBIT_ID1) || version == 8) {
@@ -50,6 +49,7 @@
                 in.readPTag(this);
             }
         }
+        setMetaData(meta);
     }
 
     static void write(CalorimeterHit hit, SIOOutputStream out, int flags) throws IOException {

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIORawTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIORawTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIORawTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -28,11 +28,10 @@
 
 	SIORawTrackerHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException
 	{
-	    this.meta = meta;
 		int cellid0 = in.readInt();
 		int cellid1 = LCIOUtil.bitTest(flags,31) ? in.readInt() : 0;
 		cellId = ((long) cellid1)<<32 | cellid0;
-		compactId = new Identifier(cellId);
+		packedID = new Identifier(cellId);
 		time = in.readInt();
 		int nAdc = in.readInt();
 		adcValues = new short[nAdc];
@@ -53,6 +52,7 @@
 		}
 		*/
 		in.readPTag(this);
+            setMetaData(meta);
 	}
 
 	static void write(RawTrackerHit hit, SIOOutputStream out, int flags) throws IOException

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimCalorimeterHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimCalorimeterHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimCalorimeterHit.java	Wed Dec 17 02:09:46 2014
@@ -21,7 +21,6 @@
     // constructor from LCIO data file
     SIOSimCalorimeterHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException
     {           
-        this.meta = meta;
         int cellid0 = in.readInt();
         int cellid1 = 0;
         if (LCIOUtil.bitTest(flags,LCIOConstants.RCHBIT_ID1) || version==8) {
@@ -63,6 +62,7 @@
             }            
         }
         if ( version > 1000 ) in.readPTag(this);
+        setMetaData(meta);
     }
     
     static private float emptyPos[] = new float[3]; 
@@ -102,4 +102,4 @@
         }
         out.writePTag(hit);
     }    
-}
+}

Modified: projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimTrackerHit.java
 =============================================================================
--- projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimTrackerHit.java	(original)
+++ projects/lcsim/trunk/event-model/src/main/java/org/lcsim/lcio/SIOSimTrackerHit.java	Wed Dec 17 02:09:46 2014
@@ -24,9 +24,6 @@
         
     SIOSimTrackerHit(SIOInputStream in, int flags, int version, LCMetaData meta) throws IOException
     {
-        // Metadata.
-        this.meta = meta;
-        
         // Read in the two 32-bit cell IDs.
         cellID0 = in.readInt();
         if(version >= 1060)
@@ -44,7 +41,7 @@
         position[0] = in.readDouble();
         position[1] = in.readDouble();
         position[2] = in.readDouble();
-        setPosition(position);
+        positionVec = new BasicHep3Vector(position[0], position[1], position[2]);
         
         // Energy.
         dEdx = in.readFloat();
@@ -68,6 +65,8 @@
         // Pointer tag.
         if (version > 1000)
             in.readPTag(this);
+
+        setMetaData(meta);
     }   
 
     public MCParticle getMCParticle()

Modified: projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/recon/calorimetry/ResetCalorimeterHitEnergy.java
 =============================================================================
--- projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/recon/calorimetry/ResetCalorimeterHitEnergy.java	(original)
+++ projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/recon/calorimetry/ResetCalorimeterHitEnergy.java	Wed Dec 17 02:09:46 2014
@@ -71,9 +71,7 @@
 					}
 				}
 				
-				BaseSimCalorimeterHit resetHit = new BaseSimCalorimeterHit(id, totalEnergy, time, mcparts, energies, times, pdgs, steps);
-				//resetHit.setDetectorElement(hit.getDetectorElement());
-				resetHit.setMetaData(metaData);
+				BaseSimCalorimeterHit resetHit = new BaseSimCalorimeterHit(id, totalEnergy, time, mcparts, energies, times, pdgs, steps, metaData);
 				resetHits.add(resetHit);
 			}
 			caloHitCollection.clear();

Modified: projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/MergeEventTools.java
 =============================================================================
--- projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/MergeEventTools.java	(original)
+++ projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/MergeEventTools.java	Wed Dec 17 02:09:46 2014
@@ -248,7 +248,7 @@
 			}
 		}
 		
-		BaseSimCalorimeterHit copyHit = new BaseSimCalorimeterHit(id, rawEnergy, time, mcparts, energies, times, pdgs, steps);
+		BaseSimCalorimeterHit copyHit = new BaseSimCalorimeterHit(id, rawEnergy, time, mcparts, energies, times, pdgs, steps, metaData);
 		//copyHit.setDetectorElement(hit.getDetectorElement());
 		copyHit.setMetaData(metaData);
 		
@@ -302,9 +302,7 @@
 		}
 		// need to set time to 0 so it is recalculated from the timeList
 		SimCalorimeterHit mergedHit = new BaseSimCalorimeterHit(hit.getCellID(),
-				rawEnergy, 0., mcpList, eneList, timeList, pdgList, steps);
-		//mergedHit.setDetectorElement(oldHit.getDetectorElement());
-		mergedHit.setMetaData(metaData);
+				rawEnergy, 0., mcpList, eneList, timeList, pdgList, steps, metaData);
 		return mergedHit;
 	}
 	

Modified: projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/OverlayDriver.java
 =============================================================================
--- projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/OverlayDriver.java	(original)
+++ projects/lcsim/trunk/recon-drivers/src/main/java/org/lcsim/util/OverlayDriver.java	Wed Dec 17 02:09:46 2014
@@ -23,11 +23,11 @@
 import org.lcsim.detector.IDetectorElement;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.GenericObject;
-import org.lcsim.event.HitWithPosition;
 import org.lcsim.event.MCParticle;
 import org.lcsim.event.SimCalorimeterHit;
 import org.lcsim.event.SimTrackerHit;
 import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.Hit;
 import org.lcsim.event.base.BaseMCParticle;
 import org.lcsim.event.base.BaseSimCalorimeterHit;
 import org.lcsim.event.base.BaseSimTrackerHit;
@@ -430,7 +430,7 @@
 	 * the position of the given hit along a straight line.
 	 * @param hit
 	 */
-	static protected double getLosTof(HitWithPosition hit) {
+	static protected double getLosTof(Hit hit) {
 		return SpacePoint.distance(new SpacePoint(hit.getPositionVec()), interactionPoint)/c;
 	}
 	
@@ -581,9 +581,7 @@
 					}
 					// need to set time to 0 so it is recalculated from the timeList
 					movedHit = new BaseSimCalorimeterHit(hit.getCellID(),
-							rawEnergy, 0., mcArr, eneArr, timeArr, pdgArr, steps);
-					//movedHit.setDetectorElement(hit.getDetectorElement());
-					movedHit.setMetaData(collection);
+							rawEnergy, 0., mcArr, eneArr, timeArr, pdgArr, steps, collection);
 				} else {
 					double hitTime = hit.getTime() + time;
 					if (timeWindow > 0) {
@@ -734,10 +732,7 @@
 			}
 		}
 		
-		BaseSimCalorimeterHit copyHit = new BaseSimCalorimeterHit(id, rawEnergy, time, mcparts, energies, times, pdgs, steps);
-		//copyHit.setDetectorElement(hit.getDetectorElement());
-		copyHit.setMetaData(meta);
-		
+		BaseSimCalorimeterHit copyHit = new BaseSimCalorimeterHit(id, rawEnergy, time, mcparts, energies, times, pdgs, steps, meta);
 		return copyHit;
 	}
 	
@@ -851,9 +846,9 @@
 					}
 					// need to set time to 0 so it is recalculated from the timeList
 					SimCalorimeterHit mergedHit = new BaseSimCalorimeterHit(oldHit.getCellID(),
-							rawEnergy, 0., mcpList, eneList, timeList, pdgList, steps);
+							rawEnergy, 0., mcpList, eneList, timeList, pdgList, steps, collection);
 					//mergedHit.setDetectorElement(oldHit.getDetectorElement());
-					mergedHit.setMetaData(collection);
+					//mergedHit.setMetaData(collection);
 					// replace old hit with merged hit
 					signalCaloHits.remove(oldHit);
 					signalCaloHits.add(mergedHit);

Modified: projects/lcsim/trunk/tracking/src/main/java/org/lcsim/recon/tracking/digitization/sisim/config/SimTrackerHitReadoutDriver.java
 =============================================================================
--- projects/lcsim/trunk/tracking/src/main/java/org/lcsim/recon/tracking/digitization/sisim/config/SimTrackerHitReadoutDriver.java	(original)
+++ projects/lcsim/trunk/tracking/src/main/java/org/lcsim/recon/tracking/digitization/sisim/config/SimTrackerHitReadoutDriver.java	Wed Dec 17 02:09:46 2014
@@ -60,7 +60,7 @@
             LCMetaData meta = header.getMetaData(collection);
             if (canHandle(meta.getName())) {
                 for (SimTrackerHit hit : collection) {
-                    hit.setMetaData(meta);
+                    //hit.setMetaData(meta);
                     hit.getDetectorElement().getReadout().addHit(hit);
                     if (debug) {
                         System.out.println("Driver assigned hit " + hit.getExpandedIdentifier().toString() + " to "
@@ -80,4 +80,4 @@
             }
         }
     }
-}
+}

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