lcsim/src/org/lcsim/recon/cluster/util
diff -N DefaultClusterPropertyCalculator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultClusterPropertyCalculator.java 30 Jun 2005 20:53:49 -0000 1.1
@@ -0,0 +1,83 @@
+package org.lcsim.recon.cluster.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+
+/**
+ * Default implementation of ClusterPropertyCalculator Interface
+ *
+ * @author cassell
+ */
+public class DefaultClusterPropertyCalculator implements ClusterPropertyCalculator
+{
+ protected double[] position;
+ protected double[] positionError;
+ protected double iphi;
+ protected double itheta;
+ protected double[] directionError;
+ protected double[] shapeParameters;
+
+ /**
+ * Calculate the cluster properties from the hits
+ */
+ public DefaultClusterPropertyCalculator()
+ {
+ position = new double[3];
+ positionError = new double[6];
+ iphi = 0.;
+ itheta = 0.;
+ directionError = new double[6];
+ shapeParameters = new double[6];
+ }
+ public void calculateProperties(List<CalorimeterHit> hits)
+ {
+ double[] sums = {0.,0.,0.};
+ double wtsum = 0.;
+ for(int i=0;i<hits.size();i++)
+ {
+ CalorimeterHit hit = hits.get(i);
+ double[] pos = hit.getPosition();
+ double wt = hit.getEnergy();
+ wtsum += wt;
+ for(int j=0;j<3;j++)
+ {
+ sums[j] += wt*pos[j];
+ }
+ }
+ if(wtsum > 0.)
+ {
+ for(int j=0;j<3;j++)
+ {
+ position[j] = sums[j]/wtsum;
+ }
+ }
+ }
+ public double[] getPosition()
+ {
+ return position;
+ }
+ public double[] getPositionError()
+ {
+ return positionError;
+ }
+ public double getIPhi()
+ {
+ return iphi;
+ }
+ public double getITheta()
+ {
+ return itheta;
+ }
+ public double[] getDirectionError()
+ {
+ return directionError;
+ }
+ public double[] getShapeParameters()
+ {
+ return shapeParameters;
+ }
+
+}