Author: [log in to unmask]
Date: Thu Jan 1 23:32:56 2015
New Revision: 1833
Log:
Rewrite method to use Java sorting utilities.
Modified:
java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterUtilities.java
Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterUtilities.java
=============================================================================
--- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterUtilities.java (original)
+++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ClusterUtilities.java Thu Jan 1 23:32:56 2015
@@ -20,6 +20,7 @@
* @see org.lcsim.event.Cluster
* @see org.lcsim.event.base.BaseCluster
*/
+// TODO: Add method to get MCParticles (see getUniqueMCParticles from BaseCluster).
public final class ClusterUtilities {
private ClusterUtilities() {
@@ -90,14 +91,14 @@
* @return The hit with the highest energy value.
*/
public static CalorimeterHit getHighestEnergyHit(Cluster cluster) {
- double maxEnergy = Double.MIN_VALUE;
- CalorimeterHit highestEnergyHit = null;
- for (CalorimeterHit hit : cluster.getCalorimeterHits()) {
- if (hit.getCorrectedEnergy() > maxEnergy) {
- highestEnergyHit = hit;
- }
+ if (cluster.getCalorimeterHits().size() == 1) {
+ return cluster.getCalorimeterHits().get(0);
}
- return highestEnergyHit;
+ List<CalorimeterHit> hits = new ArrayList<CalorimeterHit>();
+ hits.addAll(cluster.getCalorimeterHits());
+ Collections.sort(hits, new CalorimeterHit.CorrectedEnergyComparator());
+ Collections.reverse(hits);
+ return hits.get(0);
}
/**
|