Print

Print


Commit in lcsim/src/org/lcsim/util/lcio on MAIN
SIOCluster.java+49-121.2 -> 1.3
GL: New method getRawEnergy() and fixed getSize()

lcsim/src/org/lcsim/util/lcio
SIOCluster.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- SIOCluster.java	25 Aug 2005 23:36:54 -0000	1.2
+++ SIOCluster.java	20 Feb 2006 22:12:52 -0000	1.3
@@ -6,6 +6,8 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.Cluster;
 
@@ -18,6 +20,7 @@
    private final static double[] dummy = new double[6];
    private int type;
    private float energy;
+   private double raw_energy;
    private double[] position;
    private double[] positionError;
    private float theta;
@@ -39,11 +42,12 @@
       for (int i=0; i<3; i++) position[i] = in.readFloat();
       positionError = new double[6];
       for (int i=0; i<6; i++) positionError[i] = in.readFloat();
+
       theta = in.readFloat();
       phi = in.readFloat();
       directionError = new double[3];
       for (int i=0; i<3; i++) directionError[i] = in.readFloat();
-      
+
       int nShape;
       if( version > 1002)
       {
@@ -116,7 +120,7 @@
             calorimeterHits.add((CalorimeterHit) ref.getObject());
          }
          tempHits = null;
-      }
+      } 
       return calorimeterHits;
    }
    
@@ -139,6 +143,7 @@
       return directionError;
    }
    
+    /** Return corrected cluster energy */
    public double getEnergy()
    {
       return energy;
@@ -200,11 +205,15 @@
       for (int i=0; i<3; i++) out.writeFloat((float) p[i]);
       
       p = cluster.getShape();
-      if (p == null) out.writeInt(0);
+      if (p == null) {
+	  out.writeInt(0);
+      }
       else
       {
          out.writeInt(p.length);
-         for (int i=0; i<p.length; i++) out.writeFloat((float) p[i]);
+         for (int i=0; i<p.length; i++) {
+	     out.writeFloat((float) p[i]);
+	 }
       }
       
       out.writeInt(0);
@@ -236,21 +245,49 @@
          }
       }
       p = cluster.getSubdetectorEnergies();
-      if (p == null) out.writeInt(0);
+      if (p == null) {
+	  out.writeInt(0);
+      }
       else
       {
          out.writeInt(p.length);
-         for (int i=0; i<p.length; i++) out.writeFloat((float) p[i]);
+         for (int i=0; i<p.length; i++) {
+	     out.writeFloat((float) p[i]);
+	 }
       }
       out.writePTag(cluster);
    }
 
-    public int getSize() {
-	List<Cluster> temp = getClusters();
-	int size=0;
-	for( Cluster clus : temp ) {
-	    size += clus.getSize();
+    /** Return the hits comprising the cluster, including hits in
+     * subclusters, as per interface.  Hits belonging to more than one
+     * cluster/subcluster should be counted only once.
+     */
+    public int getSize()
+    {
+        Set<CalorimeterHit> hitSet = new HashSet<CalorimeterHit>(this.getCalorimeterHits());
+        for( Cluster clus : this.getClusters() )
+        {
+            hitSet.addAll( clus.getCalorimeterHits() );
+        }
+        return hitSet.size();
+    }
+
+    /**
+     * Return the sum of the raw energies from the hits in the cluster
+     */
+    public double getRawEnergy()
+    {
+	if(raw_energy>0) return raw_energy;
+
+        Set<CalorimeterHit> hitSet = new HashSet<CalorimeterHit>(this.getCalorimeterHits());
+        for( Cluster clus : this.getClusters() )
+        {
+            hitSet.addAll( clus.getCalorimeterHits() );
+        }
+
+	for( CalorimeterHit hit : hitSet ) {
+	    raw_energy += hit.getRawEnergy();
 	}
-	return size;
+	return raw_energy;
     }
 }
CVSspam 0.2.8