LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  October 2015

HPS-SVN October 2015

Subject:

r3848 - /java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerModule.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Fri, 16 Oct 2015 15:20:47 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (153 lines)

Author: [log in to unmask]
Date: Fri Oct 16 08:20:40 2015
New Revision: 3848

Log:
Added method to TriggerModule to create cluster top/bottom pairs to avoid having to re-implement the method in multiple locations.

Modified:
    java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerModule.java

Modified: java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerModule.java
 =============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerModule.java	(original)
+++ java/trunk/record-util/src/main/java/org/hps/record/triggerbank/TriggerModule.java	Fri Oct 16 08:20:40 2015
@@ -1,6 +1,9 @@
 package org.hps.record.triggerbank;
 
+import java.lang.reflect.Array;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
@@ -604,6 +607,127 @@
      */
     public static double getClusterZ(SSPCluster cluster) {
     	return getCrystalPosition(cluster.getXIndex(), cluster.getYIndex())[2];
+    }
+    
+    /**
+     * Forms all possible pairs of top/bottom clusters from a given
+     * list of clusters.
+     * @param clusters - The clusters from which to form the pairs.
+     * @return Returns a <code>List</code> collection of size two
+     * <code>Cluster</code> arrays representing top/bottom pairs. The
+     * first entry in the array is always the top cluster, with the
+     * bottom cluster in the next position.
+     */
+	public static <E> List<E[]> getTopBottomPairs(List<E> clusters, Class<E> clusterType) throws IllegalArgumentException {
+		// Ensure that only valid cluster types are processed.
+		if(!clusterType.equals(Cluster.class) && !clusterType.equals(SSPCluster.class)) {
+			throw new IllegalArgumentException("Class \"" + clusterType.getSimpleName() + "\" is not a supported cluster type.");
+		}
+		
+    	// Create a list to store top clusters, bottom clusters, and
+    	// cluster pairs.
+    	List<E> topClusters = new ArrayList<E>();
+    	List<E> botClusters = new ArrayList<E>();
+    	List<E[]> pairClusters = new ArrayList<E[]>();
+    	
+    	// Separate the cluster list into top/bottom clusters.
+    	for(E cluster : clusters) {
+    		// Process LCIO clusters...
+    		if(clusterType.equals(Cluster.class)) {
+				if(getClusterYIndex((Cluster) cluster) > 0) {
+					topClusters.add(cluster);
+				} else { botClusters.add(cluster); }
+    		}
+    		
+    		// Process SSP clusters...
+    		else if(clusterType.equals(SSPCluster.class)) {
+				if(getClusterYIndex((SSPCluster) cluster) > 0) {
+					topClusters.add(cluster);
+				} else { botClusters.add(cluster); }
+    		}
+    	}
+    	
+    	// Form all top/bottom cluster pairs.
+    	for(E topCluster : topClusters) {
+    		for(E botCluster : botClusters) {
+    			@SuppressWarnings("unchecked")
+				E[] pair = (E[]) Array.newInstance(clusterType, 2);
+    			pair[0] = topCluster;
+    			pair[1] = botCluster;
+    			pairClusters.add(pair);
+    		}
+    	}
+    	
+    	// Return the cluster pairs.
+    	return pairClusters;
+    }
+    
+    /**
+     * Forms all possible pairs of top/bottom clusters from a given
+     * list of clusters.
+     * @param clusters - The clusters from which to form the pairs.
+     * @return Returns a <code>List</code> collection of size two
+     * <code>Cluster</code> arrays representing top/bottom pairs. The
+     * first entry in the array is always the top cluster, with the
+     * bottom cluster in the next position.
+     */
+	public static List<Cluster[]> getTopBottomPairs(Cluster... clusters) {
+    	// Create a list to store top clusters, bottom clusters, and
+    	// cluster pairs.
+    	List<Cluster> topClusters = new ArrayList<Cluster>();
+    	List<Cluster> botClusters = new ArrayList<Cluster>();
+    	List<Cluster[]> pairClusters = new ArrayList<Cluster[]>();
+    	
+    	// Separate the cluster list into top/bottom clusters.
+    	for(Cluster cluster : clusters) {
+			if(getClusterYIndex(cluster) > 0) {
+				topClusters.add(cluster);
+			} else { botClusters.add(cluster); }
+    	}
+    	
+    	// Form all top/bottom cluster pairs.
+    	for(Cluster topCluster : topClusters) {
+    		for(Cluster botCluster : botClusters) {
+    			pairClusters.add(new Cluster[] { topCluster, botCluster });
+    		}
+    	}
+    	
+    	// Return the cluster pairs.
+    	return pairClusters;
+    }
+    
+    /**
+     * Forms all possible pairs of top/bottom clusters from a given
+     * list of clusters.
+     * @param clusters - The clusters from which to form the pairs.
+     * @return Returns a <code>List</code> collection of size two
+     * <code>SSPCluster</code> arrays representing top/bottom pairs.
+     * The first entry in the array is always the top cluster, with
+     * the bottom cluster in the next position.
+     */
+	public static List<SSPCluster[]> getTopBottomPairs(SSPCluster... clusters) {
+    	// Create a list to store top clusters, bottom clusters, and
+    	// cluster pairs.
+    	List<SSPCluster> topClusters = new ArrayList<SSPCluster>();
+    	List<SSPCluster> botClusters = new ArrayList<SSPCluster>();
+    	List<SSPCluster[]> pairClusters = new ArrayList<SSPCluster[]>();
+    	
+    	// Separate the cluster list into top/bottom clusters.
+    	for(SSPCluster cluster : clusters) {
+			if(getClusterYIndex(cluster) > 0) {
+				topClusters.add(cluster);
+			} else { botClusters.add(cluster); }
+    	}
+    	
+    	// Form all top/bottom cluster pairs.
+    	for(SSPCluster topCluster : topClusters) {
+    		for(SSPCluster botCluster : botClusters) {
+    			pairClusters.add(new SSPCluster[] { topCluster, botCluster });
+    		}
+    	}
+    	
+    	// Return the cluster pairs.
+    	return pairClusters;
     }
     
     /**

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use