lcsim/src/org/lcsim/recon/cluster/util
diff -N ParticleListToClusterListDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ParticleListToClusterListDriver.java 12 Jul 2006 17:57:43 -0000 1.1
@@ -0,0 +1,89 @@
+package org.lcsim.recon.cluster.util;
+
+import java.util.List;
+import java.util.Vector;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.recon.cluster.util.BasicCluster;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.event.Cluster;
+
+/**
+ * Conversion utility. It takes as input a named list of ReconstructedParticles.
+ * For each one it makes a Cluster out of the CalorimeterHits, then writes
+ * the list of Clusters to the event.
+ *
+ * @version $Id: ParticleListToClusterListDriver.java,v 1.1 2006/07/12 17:57:43 mcharles Exp $
+ */
+
+public class ParticleListToClusterListDriver extends Driver
+{
+ /** Simple constructor */
+ public ParticleListToClusterListDriver(String particleList, String clusterList) {
+ super();
+ m_particleListName = particleList;
+ m_clusterListName = clusterList;
+ }
+
+ /** Process one event, performing conversion. */
+ public void process(EventHeader event)
+ {
+ // Input list:
+ List<ReconstructedParticle> inputList = event.get(ReconstructedParticle.class, m_particleListName);
+
+ // Output list:
+ Vector<Cluster> outputList = new Vector<Cluster>();
+
+ for (ReconstructedParticle part : inputList) {
+ // Make a big glob of all the calorimeter hits:
+ Set<CalorimeterHit> hits = recursivelyFindHits(part);
+ // Add it as a cluster:
+ BasicCluster clus = new BasicCluster();
+ for (CalorimeterHit hit : hits) {
+ clus.addHit(hit);
+ }
+ outputList.add(clus);
+ }
+
+ event.put(m_clusterListName, outputList);
+ }
+
+ protected Set<CalorimeterHit> recursivelyFindHits(ReconstructedParticle part)
+ {
+ List<Cluster> subClusters = recursivelyFindSubClusters(part);
+ Set<CalorimeterHit> outputSet = new HashSet<CalorimeterHit>();
+ for (Cluster clus : subClusters) {
+ for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+ outputSet.add(hit);
+ }
+ }
+ return outputSet;
+ }
+ protected List<Cluster> recursivelyFindSubClusters(ReconstructedParticle part)
+ {
+ List<Cluster> allSubClusters = new Vector<Cluster>();
+ for (Cluster clus : part.getClusters()) {
+ List<Cluster> subClusters = recursivelyFindSubClusters(clus);
+ allSubClusters.addAll(subClusters);
+ }
+ return allSubClusters;
+ }
+ protected List<Cluster> recursivelyFindSubClusters(Cluster clus)
+ {
+ List<Cluster> output = new Vector<Cluster>();
+ for (Cluster dau : clus.getClusters()) {
+ output.addAll(recursivelyFindSubClusters(dau));
+ }
+ output.add(clus);
+ return output;
+ }
+
+
+ protected String m_particleListName;
+ protected String m_clusterListName;
+}
+