diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 9617c13a58..461ed7dffc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jlab.detector.base.DetectorType; +import java.util.concurrent.ConcurrentLinkedQueue; import org.jlab.rec.cvt.hit.Hit; /** @@ -13,22 +13,36 @@ */ public class ClusterFinder { - public ClusterFinder() { + static final int NSTRIP = 1200; // max number of strips + static final int NLAYR = 6; + static final int NSEC = 18; + static class HitMapPool extends ConcurrentLinkedQueue { + public HitMapPool() { + super(); + for (int i=0; i<64; i++) + add(new Hit[NSTRIP][NLAYR][NSEC]); + } + @Override + public Hit[][][] poll() { + Hit[][][] x = super.poll(); + for (int i=0; i findClusters(List hits2) // the number of strips depends on the layer + public static ArrayList findClusters(List hits2) // the number of strips depends on the layer { - ArrayList clusters = new ArrayList<>(); - // a Hit Array is used to identify clusters - HitArray = new Hit[nstrip][nlayr][nsec]; + Hit[][][] HitArray = pool.poll(); // initializing non-zero Hit Array entries // with valid hits @@ -46,22 +60,23 @@ public ArrayList findClusters(List hits2) // the number of strips int l = hit.getLayer(); int s = hit.getSector(); - if (w > 0 && w < nstrip) { + if (w > 0 && w < NSTRIP) { HitArray[w - 1][l - 1][s - 1] = hit; } - } + int cid = 1; // cluster id, will increment with each new good cluster + ArrayList clusters = new ArrayList<>(); // for each layer and sector, a loop over the strips // is done to define clusters in that module's layer // clusters are delimited by strips with no hits - for (int s = 0; s < nsec; s++) { - for (int l = 0; l < nlayr; l++) { + for (int s = 0; s < NSEC; s++) { + for (int l = 0; l < NLAYR; l++) { int si = 0; // strip index in the loop // looping over all strips - while (si < nstrip) { + while (si < NSTRIP) { // if there's a hit, it's a cluster candidate if (HitArray[si][l][s] != null || (si < nstrip - 1 && HitArray[si + 1][l][s] != null)) { @@ -69,7 +84,7 @@ public ArrayList findClusters(List hits2) // the number of strips // adding all hits in this and all the subsequent // strip until there's a strip with no hit - while ((si < nstrip - 1 && HitArray[si + 1][l][s] != null) || (HitArray[si][l][s] != null && si < nstrip)) { + while ((si < NSTRIP - 1 && HitArray[si + 1][l][s] != null) || (HitArray[si][l][s] != null && si < NSTRIP)) { if (HitArray[si][l][s] != null) { // continue clustering skipping over bad hit if (this_cluster == null) { Hit seed = HitArray[si][l][s]; @@ -114,6 +129,7 @@ public ArrayList findClusters(List hits2) // the number of strips } } } + pool.offer(HitArray); return clusters; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTReconstruction.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTReconstruction.java index 05bfe8869d..516cd203e0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTReconstruction.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTReconstruction.java @@ -85,12 +85,11 @@ public List> findClusters() { List clusters = new ArrayList<>(); //2) find the clusters from these hits - ClusterFinder clusFinder = new ClusterFinder(); if(this.getSVThits().size()>0) { - clusters.addAll(clusFinder.findClusters(this.getSVThits())); + clusters.addAll(ClusterFinder.findClusters(this.getSVThits())); } if(this.getBMThits().size() > 0) { - clusters.addAll(clusFinder.findClusters(this.getBMThits())); + clusters.addAll(ClusterFinder.findClusters(this.getBMThits())); } CVTclusters.add(new ArrayList<>());