lcsim/src/org/lcsim/recon/cluster/util
diff -N BasicCluster.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BasicCluster.java 30 Jun 2005 20:52:09 -0000 1.1
@@ -0,0 +1,271 @@
+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;
+import org.lcsim.geometry.compact.Subdetector;
+
+
+/**
+ * Default implementation of Cluster Interface for Simulation
+ *
+ * @author cassell
+ */
+public class BasicCluster implements Cluster
+{
+ protected List<CalorimeterHit> hits = new ArrayList<CalorimeterHit>();
+ protected List<Cluster> clusters = new ArrayList<Cluster>();
+ protected List<Subdetector> detectors = new ArrayList<Subdetector>();
+ public double raw_energy;
+ public double corrected_energy;
+ protected List<Double> subdetector_raw_energies = new ArrayList<Double>();
+ protected List<Double> subdetector_corrected_energies = new ArrayList<Double>();
+ protected List<Double> hit_energies = new ArrayList<Double>();
+ protected ClusterPropertyCalculator cluster_property_calculator = new DefaultClusterPropertyCalculator();
+ protected boolean needsPropertyCalculation = true;
+ protected double[] position;
+ protected double[] positionError;
+ protected double iphi;
+ protected double itheta;
+ protected double[] directionError;
+ protected double[] shapeParameters;
+
+ /**
+ * Add a CalorimeterHit to the cluster
+ */
+ public void addHit(CalorimeterHit hit)
+ {
+ hits.add(hit);
+ raw_energy += hit.getEnergy();
+ /*
+ Subdetector d = hit.getSubdetector();
+ int detector_index = detectors.indexOf(d);
+ if(detector_index <0)
+ {
+ detectors.add(d);
+ detector_index = detectors.indexOf(d);
+ subdetector_raw_energies.add(0.);
+ subdetector_corrected_energies.add(0.);
+ }
+ double sampling_fraction = d.getSamplingFraction();
+ */
+ int detector_index = 0;
+ double sampling_fraction = 1.;
+ if(subdetector_raw_energies.size() < 1)
+ {
+ subdetector_raw_energies.add(0.);
+ subdetector_corrected_energies.add(0.);
+ }
+ double hce = hit.getEnergy()/sampling_fraction;
+ corrected_energy += hce;
+ hit_energies.add(hce);
+ subdetector_raw_energies.set(detector_index,subdetector_raw_energies.get(detector_index) + hit.getEnergy());
+ subdetector_corrected_energies.set(detector_index,subdetector_corrected_energies.get(detector_index) + hce);
+ needsPropertyCalculation = true;
+ }
+ /**
+ * Add a Cluster to the cluster
+ */
+ public void addCluster(Cluster cluster)
+ {
+ clusters.add(cluster);
+ List<CalorimeterHit> chits = cluster.getCalorimeterHits();
+ if(chits.size() > 0)
+ {
+ for(int i=0;i<chits.size();i++)
+ {
+ addHit(chits.get(i));
+ }
+ needsPropertyCalculation = true;
+ }
+ else
+ {
+ corrected_energy += cluster.getEnergy();
+ double[] sde = cluster.getSubdetectorEnergies();
+ for(int i=0;i<sde.length;i++)
+ {
+ subdetector_corrected_energies.set(i,subdetector_corrected_energies.get(i) + sde[i]);
+ }
+ }
+ }
+
+ /**
+ * Return the hits comprising the cluster as per interface
+ */
+ public List<CalorimeterHit> getCalorimeterHits()
+ {
+ return hits;
+ }
+
+ /**
+ * Return the clusters comprising the cluster as per interface
+ */
+ public List<Cluster> getClusters()
+ {
+ return clusters;
+ }
+
+ /**
+ * Return the corrected Energy of the cluster as per interface
+ */
+ public double getEnergy()
+ {
+ return corrected_energy;
+ }
+
+ /**
+ * Return the corrected energy contribution of each hit
+ * comprising the cluster as per interface
+ */
+ public double[] getHitContributions()
+ {
+ double[] earray = new double[hit_energies.size()];
+ for(int i=0;i<hit_energies.size();i++)
+ {
+ earray[i] = hit_energies.get(i);
+ }
+ return earray;
+ }
+
+ /**
+ * Return the phi direction of the cluster as per interface
+ */
+ public double getIPhi()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return iphi;
+ }
+
+ /**
+ * Return the theta direction of the cluster as per interface
+ */
+ public double getITheta()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return itheta;
+ }
+
+ /**
+ * Return the direction error of the cluster as per interface
+ */
+ public double[] getDirectionError()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return directionError;
+ }
+
+ /**
+ * Return the position of the cluster as per interface
+ */
+ public double[] getPosition()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return position;
+ }
+
+ /**
+ * Return the position error of the cluster as per interface
+ */
+ public double[] getPositionError()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return positionError;
+ }
+
+ /**
+ * Return the shape parameters of the cluster as per interface
+ */
+ public double[] getShape()
+ {
+ if(needsPropertyCalculation)
+ {
+ calculateProperties();
+ needsPropertyCalculation = false;
+ }
+ return shapeParameters;
+ }
+
+ /**
+ * Return the subdetector energy contributions
+ * of the cluster as per interface
+ */
+ public double[] getSubdetectorEnergies()
+ {
+ double[] sdearray = new double[subdetector_corrected_energies.size()];
+ for(int i=0;i<subdetector_corrected_energies.size();i++)
+ {
+ sdearray[i] = subdetector_corrected_energies.get(i);
+ }
+ return sdearray;
+ }
+
+ /**
+ * Return a bit mask defining the type of cluster as per interface
+ */
+ public int getType()
+ {
+ return 0;
+ }
+
+ /**
+ * Return the sum of the raw energies from the hits in the cluster
+ */
+ public double getRawEnergy()
+ {
+ return raw_energy;
+ }
+
+ /**
+ * Allow for recalculation of cluster properties, or
+ * prevent recalculation after adding to cluster
+ */
+ public void setNeedsPropertyCalculation(boolean tf)
+ {
+ needsPropertyCalculation = tf;
+ }
+
+ /**
+ * Override the default ClusterPropertyCalculator
+ */
+ public void setPropertyCalculator(ClusterPropertyCalculator cpc)
+ {
+ cluster_property_calculator = cpc;
+ }
+
+ /**
+ * Calculate the cluster properties from the hits
+ */
+ public void calculateProperties()
+ {
+ cluster_property_calculator.calculateProperties(hits);
+ position = cluster_property_calculator.getPosition();
+ positionError = cluster_property_calculator.getPositionError();
+ iphi = cluster_property_calculator.getIPhi();
+ itheta = cluster_property_calculator.getITheta();
+ directionError = cluster_property_calculator.getDirectionError();
+ shapeParameters = cluster_property_calculator.getShapeParameters();
+ }
+
+}