Commit in lcsim/src/org/lcsim/util/event on MAIN
BaseCalorimeterHit.java+91-731.6 -> 1.7
JM: private calculation methods for getters

lcsim/src/org/lcsim/util/event
BaseCalorimeterHit.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- BaseCalorimeterHit.java	17 Aug 2007 23:58:31 -0000	1.6
+++ BaseCalorimeterHit.java	15 May 2008 01:19:48 -0000	1.7
@@ -1,7 +1,6 @@
 package org.lcsim.util.event;
 
 import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.RawCalorimeterHit;
 import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.geometry.IDDecoder;
 import org.lcsim.geometry.Subdetector;
@@ -10,76 +9,95 @@
  *
  * @author tonyj
  */
-public abstract class BaseCalorimeterHit implements CalorimeterHit
-{
-   // Fixme: Maybe energy should be left to subclass to allow double/float, same for time
-   protected double rawEnergy;
-   protected LCMetaData data;
-   protected double[] position;
-   protected double time;
-   protected long id;
-   protected int layer=-1;
-        
-   public double getTime()
-   {
-      return time;
-   }
-
-   public Subdetector getSubdetector()
-   {
-      return SubdetectorLocator.locateSubdetector(data,id);
-   }
-
-   public double getRawEnergy()
-   {
-      return rawEnergy;
-   }
-
-   public double[] getPosition()
-   {
-      if (position == null)
-      { 
-    	  if (data != null)
-    	  {
-    		  IDDecoder iddecoder = data.getIDDecoder();
-    		  iddecoder.setID( id );
-    		  position = new double[3];
-    		  position[0] = iddecoder.getX();
-    		  position[1] = iddecoder.getY();
-    		  position[2] = iddecoder.getZ();
-    	  }
-      }
-      return position;
-   }
-
-   public IDDecoder getIDDecoder()
-   {
-      return data.getIDDecoder();
-   }
-   
-   public LCMetaData getLCMetaData()
-   {
-       return data;
-   }
-
-   public double getCorrectedEnergy()
-   {
-      IDDecoder decoder = getIDDecoder();
-      decoder.setID(id);
-      return SamplingFractionManager.defaultInstance().getCorrectedEnergy(rawEnergy,decoder.getLayer(),getSubdetector());
-   }
-
-   public long getCellID()
-   {
-      return id;
-   }
-   
-   public int getLayerNumber()
-   {
-	   if (layer == -1)
-	   {
-		   layer = getIDDecoder().getLayer();
-	   }
-       return layer;
-   }
+public abstract class BaseCalorimeterHit implements CalorimeterHit 
+{       
+    protected double rawEnergy;
+    protected double corrEnergy = -1;
+    protected LCMetaData data;
+    protected double[] position;
+    protected double time;
+    protected long id;
+    protected Subdetector subdet;
+    
+    public double getTime() 
+    {
+        return time;
+    }
+
+    public Subdetector getSubdetector() 
+    {
+        if (subdet == null)
+        {
+            findSubdetector();
+        }
+        return subdet;
+    }
+
+    public double getRawEnergy() 
+    {
+        return rawEnergy;
+    }
+
+    public double[] getPosition() 
+    {
+        if (position == null)
+        {
+            calculatePosition();
+        }
+        return position;
+    }
+
+    public IDDecoder getIDDecoder() 
+    {
+        return data.getIDDecoder();
+    }
+
+    public LCMetaData getLCMetaData() 
+    {
+        return data;
+    }
+
+    public double getCorrectedEnergy() 
+    {
+        if (corrEnergy == -1)
+        {
+            calculateCorrectedEnergy();
+        }
+        return corrEnergy;
+    }
+
+    public long getCellID() 
+    {
+        return id;
+    }
+
+    public int getLayerNumber() 
+    {
+        return getIDDecoder().getLayer();
+    }
+    
+    private void findSubdetector()
+    {
+        subdet = SubdetectorLocator.locateSubdetector(data, id);
+    }
+    
+    private void calculateCorrectedEnergy()
+    {
+        IDDecoder decoder = getIDDecoder();
+        decoder.setID(id);
+        corrEnergy = SamplingFractionManager.defaultInstance().getCorrectedEnergy(rawEnergy, decoder.getLayer(), getSubdetector());
+    }
+    
+    private void calculatePosition()
+    {        
+        if (data != null) 
+        {
+            position = new double[3];
+            IDDecoder iddecoder = data.getIDDecoder();
+            iddecoder.setID(id);
+            position[0] = iddecoder.getX();
+            position[1] = iddecoder.getY();
+            position[2] = iddecoder.getZ();
+        }
+    }           
 }
\ No newline at end of file
CVSspam 0.2.8