Commit in lcsim/src/org/lcsim/recon/cluster/density on MAIN
HitWeightingClusterPropertyCalculator.java+84added 1.1
ClusterBuilder.java+20-421.3 -> 1.4
+104-42
1 added + 1 modified, total 2 files
GL: Add HitWeightingClusterPropertyCalculator for hit-density weighting

lcsim/src/org/lcsim/recon/cluster/density
HitWeightingClusterPropertyCalculator.java added at 1.1
diff -N HitWeightingClusterPropertyCalculator.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HitWeightingClusterPropertyCalculator.java	7 Dec 2005 18:57:12 -0000	1.1
@@ -0,0 +1,84 @@
+package org.lcsim.recon.cluster.density;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.recon.cluster.util.DefaultClusterPropertyCalculator;
+
+/**
+ * Density weighting implementation of a ClusterPropertyCalculator object.
+ *
+ * <br>This alternative hit-weighting scheme can be used for new cluster
+ * properties in two significantly different ways:
+ *
+ * <ol>
+ * <li> By permanently changing the weighting scheme of the Cluster objects:
+ * <pre>
+ *      aCluster.setPropertyCalculator( myCalculator );
+ *      Hep3Vector newPos = new BasicHep3Vector( aCluster.getPosition() );
+ * </pre></li>
+ *
+ * <li> Using another weighting scheme without altering the scheme used
+ *    by the Cluster objects:
+ * <pre>
+ *      myCalculator.calculateProperties( cluster.getCalorimeterHits() );
+ *      Hep3Vector newPos = new BasicHep3Vector( myCalculator.getPosition() );
+ * </pre></li>
+ * </ol>
+ *
+ * @author Guilherme Lima
+ */
+public class HitWeightingClusterPropertyCalculator extends DefaultClusterPropertyCalculator
+{
+    RunControlParameters _runPar = RunControlParameters.getInstance();
+    LoadMyCalorimeterHit _loader = LoadMyCalorimeterHit.getInstance();
+
+    public void calculateProperties(List<CalorimeterHit> hits)
+    {
+      double cluE = 0.0;
+      double sumWt = 0.0;
+      double cluX = 0.0; double cluY = 0.0; double cluZ = 0.0;
+      int cluSize = hits.size();
+      if(cluSize==0) System.out.println("Damn 2");
+      assert cluSize > 0 : "ClusterBuilder: zero-hits cluster found.";
+
+      for( CalorimeterHit hit : hits ){
+	  double ene = hit.getRawEnergy();
+	  double[] pos = hit.getPosition();
+	  cluE += ene;
+	  if(_runPar.getCentroidWeightType()=="Energy") {
+	      cluX += ene*pos[0];
+	      cluY += ene*pos[1];
+	      cluZ += ene*pos[2];
+	      sumWt += ene;
+	  }
+	  if(_runPar.getCentroidWeightType()=="Density") {
+// 	    if(cluSize>1) {
+	      long id = hit.getCellID();
+	      double dens = _loader.getDensity(hit.getCellID());
+	      cluX += dens*pos[0];
+	      cluY += dens*pos[1];
+	      cluZ += dens*pos[2];
+	      sumWt += dens;
+// 	    }
+// 	    else {
+// 		cluX = pos[0];
+// 		cluY = pos[1];
+// 		cluZ = pos[2];
+// 		sumWt = 1.0;
+// 	    }
+	  }
+      }
+      if(sumWt>0.){
+	  cluX /= sumWt;
+	  cluY /= sumWt;
+	  cluZ /= sumWt;
+      }
+
+      position[0] = cluX;
+      position[1] = cluY;
+      position[2] = cluZ;
+    }
+}

lcsim/src/org/lcsim/recon/cluster/density
ClusterBuilder.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ClusterBuilder.java	29 Sep 2005 19:08:36 -0000	1.3
+++ ClusterBuilder.java	7 Dec 2005 18:57:11 -0000	1.4
@@ -1,57 +1,35 @@
 package org.lcsim.recon.cluster.density;
-import java.util.*;
-import org.lcsim.event.SimCalorimeterHit;
+import java.util.Vector;
+import java.util.List;
+import java.util.ArrayList;
 import org.lcsim.event.CalorimeterHit;
+import org.lcsim.recon.cluster.util.BasicCluster;
 
 public class ClusterBuilder {
 
-    LoadMyCalorimeterHit _loader = LoadMyCalorimeterHit.getInstance();
+    HitWeightingClusterPropertyCalculator _hitWeightingCPC = new HitWeightingClusterPropertyCalculator();
 
-    public List<Cluster> makeClusters(Vector<Vector<CalorimeterHit>> hitColl,
-				      RunControlParameters rpar)
+    public List<BasicCluster> makeClusters(Vector<Vector<CalorimeterHit>> inClusters)
     {
-        List<Cluster> clusters = new ArrayList<Cluster>();
-        int nclus = hitColl.size();
+        int nclus = inClusters.size();
 	assert nclus > 0 : "ClusterBuilder: no clusters received.";
 
-	// loop over clusters
-        for(int i=0;i<nclus;i++){
-            double cluE = 0.0;
-            double cluX = 0.0; double cluY = 0.0; double cluZ = 0.0;
-            double sumWt = 0.0;
-            int cluSize = hitColl.get(i).size();
+        List<BasicCluster> outClusters = new ArrayList<BasicCluster>();
 
-	    if(cluSize==0) System.out.println("Damn 2");
+	// loop over clusters
+        for( Vector<CalorimeterHit> hits : inClusters ){
+            int cluSize = hits.size();
 	    assert cluSize > 0 : "ClusterBuilder: zero-hits cluster found.";
 
-	    // loop over hits in this cluster
-            for( CalorimeterHit ihit : hitColl.get(i) ){
-                double ene = ihit.getRawEnergy();
-                double[] pos = ihit.getPosition();
-                cluE += ene;
-                if(rpar.getCentroidWeightType()=="Energy"){
-                    cluX += ene*pos[0];
-                    cluY += ene*pos[1];
-                    cluZ += ene*pos[2];
-                    sumWt += ene;
-                }
-                if(rpar.getCentroidWeightType()=="Density"){
-		    double dens = _loader.getDensity(ihit);
-		    cluX += dens*pos[0];
-		    cluY += dens*pos[1];
-		    cluZ += dens*pos[2];
-		    sumWt += dens;
-                }
-            }
-            if(sumWt>0.){
-                cluX = cluX/sumWt;
-                cluY = cluY/sumWt;
-                cluZ = cluZ/sumWt;
-            }
-	    //	    System.out.println(cluE+" "+cluX+" "+cluY+" "+cluZ);
-            Cluster clus = new Cluster(cluE,cluX,cluY,cluZ,hitColl.get(i));
-            clusters.add(clus);
+	    // create cluster
+            BasicCluster clus = new BasicCluster();
+	    for( CalorimeterHit hit : hits ) clus.addHit( hit );
+
+	    // change cluster's hit-weighting scheme
+ 	    clus.setPropertyCalculator( _hitWeightingCPC );
+
+            outClusters.add(clus);
         }
-        return clusters;
+        return outClusters;
     }
 }
CVSspam 0.2.8