From 93b865196bd1a9685c6cf61b82c7d9d6d80600ce Mon Sep 17 00:00:00 2001 From: tongtongcao Date: Thu, 9 Jan 2025 10:21:29 -0500 Subject: [PATCH] use wrapper to treat similar functions of isExceptionalCluster --- .../dc/cluster/ClusterCleanerUtilities.java | 90 ++++++++----------- 1 file changed, 35 insertions(+), 55 deletions(-) diff --git a/reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java b/reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java index aaf81220ae..b2b37c20f1 100644 --- a/reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java +++ b/reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java @@ -1010,73 +1010,53 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean return BestCluster; } - /** - * - * @param hitsInClus the hits in a cluster - * @return if one or more layers are skipped in the cluster + /** + * Check if one or more layers are skipped in the cluster + * @param hitsInClus the hits in a cluster (can be either Hit or FittedHit) + * @param nlayr the number of layers + * @return true if one or more layers are skipped in the cluster */ - public boolean isExceptionalCluster(List hitsInClus){ - // count hits in each layer - int nlayr = 6; + private boolean isExceptionalClusterHelper(List hitsInClus, int nlayr) { + // Initialize array to count hits in each layer int[] nlayers = new int[nlayr]; - for (int l = 0; l < nlayr; l++) { - nlayers[l] = 0; - for (int h = 0; h < hitsInClus.size(); h++) { - if (hitsInClus.get(h).get_Layer() == l + 1) { - nlayers[l]++; - } + + // Count hits for each layer in a single pass through the hits + for (Hit hit : hitsInClus) { + int layer = hit.get_Layer() - 1; // layer numbering starts from 1 + if (layer >= 0 && layer < nlayr) { + nlayers[layer]++; } } - boolean flag_hasSkippedLayer = false; - if((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)){ - flag_hasSkippedLayer = true; + // Check if the first or last two layerers are missed + if ((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)) { + return true; } - else{ - for (int l = 0; l < 4; l++) { - if (nlayers[l] > 0 && nlayers[l+1] == 0) { - flag_hasSkippedLayer = true; - break; - } + + // Check if there is one or more skipped layers in the middle + for (int l = 0; l < 4; l++) { + if (nlayers[l] > 0 && nlayers[l + 1] == 0) { + return true; } } - - return flag_hasSkippedLayer; + + return false; } - /* - * @param hitsInClus the hits in a cluster - * @return if one or more layers are skipped in the cluster - */ - public boolean isExceptionalFittedCluster(List hitsInClus){ - // count hits in each layer - int nlayr = 6; - int[] nlayers = new int[nlayr]; - for (int l = 0; l < nlayr; l++) { - nlayers[l] = 0; - for (int h = 0; h < hitsInClus.size(); h++) { - if (hitsInClus.get(h).get_Layer() == l + 1) { - nlayers[l]++; - } - } - } - - boolean flag_hasSkippedLayer = false; - if((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)){ - flag_hasSkippedLayer = true; - } - else{ - for (int l = 0; l < 4; l++) { - if (nlayers[l] > 0 && nlayers[l+1] == 0) { - flag_hasSkippedLayer = true; - break; - } - } - } - - return flag_hasSkippedLayer; + /** + * Wrapper for checking if a cluster of Hit objects is exceptional. + */ + public boolean isExceptionalCluster(List hitsInClus) { + return isExceptionalClusterHelper(hitsInClus, 6); // 6 layers for Hit objects } + /** + * Wrapper for checking if a cluster of FittedHit objects is exceptional. + */ + public boolean isExceptionalFittedCluster(List hitsInClus) { + return isExceptionalClusterHelper(hitsInClus, 6); // 6 layers for FittedHit objects + } + public Cluster ClusterSticher(Cluster thisclus, Cluster nextclus, int cid){ ClusterFitter cf = new ClusterFitter();