From 51ca432176d2098b8bd8421c6adc390e4b61bd5b Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 4 May 2026 16:50:23 -0400 Subject: [PATCH 1/2] replace ifs with if-elses --- .../dc/cluster/ClusterCleanerUtilities.java | 60 ++++++------------- 1 file changed, 19 insertions(+), 41 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 6ab72f997e..e8ff221b97 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 @@ -17,14 +17,12 @@ public class ClusterCleanerUtilities { private static final Logger LOGGER = Logger.getLogger(ClusterCleanerUtilities.class.getName()); + private List> sortedHits; + public ClusterCleanerUtilities() { - List> sortdHits = new ArrayList<>(); - for(int l = 0; l < 6; l++) { - sortdHits.add(new ArrayList<>()); - } - sortedHits = sortdHits; + for(int l = 0; l < 6; l++) sortedHits.add(new ArrayList<>()); } - private List> sortedHits = null; + /** * * Pattern Recognition step for identifying clusters in a clump: Find the @@ -220,7 +218,6 @@ public List ClusterSplitter(FittedCluster clus, int nextClsStartI FittedCluster bestCls = OverlappingClusterResolver(cluster, splitclusters); if (bestCls != null) { - if (!(selectedClusList.contains(bestCls))) { selectedClusList.add(bestCls); } @@ -237,7 +234,6 @@ public List ClusterSplitter(FittedCluster clus, int nextClsStartI FittedCluster bestCls = OverlappingClusterResolver(cluster, selectedClusList); if (bestCls != null) { - if (!(selectedClusList2.contains(bestCls))) { selectedClusList2.add(bestCls); } @@ -283,12 +279,9 @@ public List> byLayerListSorter(List DCHits, int sector, int super */ public int count_nlayers_hit(Hit[] hits_inlayer) { int nlayr = 6; - Hit[] allhits_inlayer = new Hit[nlayr]; - allhits_inlayer = hits_inlayer; - int nlayers_hit = 0; for (int la = 0; la < nlayr; la++) { - if (allhits_inlayer[la] != null) { + if (hits_inlayer[la] != null) { nlayers_hit++; } } @@ -341,7 +334,6 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, if (hit.get_LeftRightAmb() == 0) { index++; } - } if (index == 0) { return fClus; // cluster OK @@ -445,7 +437,7 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, arrayOfClus.get(0).addAll(okClus); arrayOfClus.get(1).addAll(okClus); } - if (index == 2) { + else if (index == 2) { for (int i1 = 0; i1 < totNotLRClus.size(); i1++) { for (int i2 = 2; i2 < totNotLRClus.size(); i2++) { if (totNotLRClus.get(i1).get_Id() == totNotLRClus.get(i2).get_Id()) { @@ -459,8 +451,7 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, } } } - - if (index == 3) { + else if (index == 3) { for (int i1 = 0; i1 < totNotLRClus.size(); i1++) { for (int i2 = 2; i2 < totNotLRClus.size(); i2++) { for (int i3 = 4; i3 < totNotLRClus.size(); i3++) { @@ -479,8 +470,7 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, } } } - - if (index == 4) { + else if (index == 4) { for (int i1 = 0; i1 < totNotLRClus.size(); i1++) { for (int i2 = 2; i2 < totNotLRClus.size(); i2++) { for (int i3 = 4; i3 < totNotLRClus.size(); i3++) { @@ -505,8 +495,7 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, } } } - - if (index == 5) { + else if (index == 5) { for (int i1 = 0; i1 < totNotLRClus.size(); i1++) { for (int i2 = 2; i2 < totNotLRClus.size(); i2++) { for (int i3 = 4; i3 < totNotLRClus.size(); i3++) { @@ -538,8 +527,7 @@ public FittedCluster LRAmbiguityResolver(DataEvent event, FittedCluster fClus, } } } - - if (index == 6) { + else if (index == 6) { for (int i1 = 0; i1 < totNotLRClus.size(); i1++) { for (int i2 = 2; i2 < totNotLRClus.size(); i2++) { for (int i3 = 4; i3 < totNotLRClus.size(); i3++) { @@ -613,14 +601,14 @@ public FittedCluster SecondariesRemover(DataEvent event, FittedCluster clus, Clu if (hitsInLayer.isEmpty()) { continue; } - if (hitsInLayer.size() == 1) { + else if (hitsInLayer.size() == 1) { baseClusterHits.addAll(hitsInLayer); // safe all good hits to base cluster for (int j = 0; j < hitsInLayer.size(); j++) { hitsInLayer.get(j).set_LeftRightAmb(0); hitsInLayer.get(j).updateHitPositionWithTime(event, 1, hitsInLayer.get(j).getB(), tab, DcDetector, tde); } } - if (hitsInLayer.size() == 2) { + else if (hitsInLayer.size() == 2) { double docaSum = 0; for (int j = 0; j < hitsInLayer.size(); j++) { docaSum += hitsInLayer.get(j).get_Doca(); @@ -665,7 +653,6 @@ public FittedCluster SecondariesRemover(DataEvent event, FittedCluster clus, Clu } if (nbLyr > 0) { - for (int[] get : Constants.getInstance().CombArray.get(nbLyr - 1)) { ArrayList hitsInClusterCand = new ArrayList<>(); hitsInClusterCand.addAll(baseClusterHits); @@ -675,6 +662,7 @@ public FittedCluster SecondariesRemover(DataEvent event, FittedCluster clus, Clu hitsInClusCandLists.add(hitsInClusterCand); } } + for (int i = 0; i < hitsInClusCandLists.size(); i++) { FittedCluster newClus = new FittedCluster(clus.getBaseCluster()); for (int i1 = 0; i1 < newClus.size(); i1++) { @@ -794,7 +782,7 @@ public List HitListPruner(List hits) { rmHits.removeAll(kHits); sortedHits.get(l).removeAll(rmHits); } - if(sortedHits.get(l).size()>4 && sortedHits.get(l).size()<10) { + else if(sortedHits.get(l).size()>4 && sortedHits.get(l).size()<10) { ArrayList rmHits = (ArrayList) sortedHits.get(l).clone(); ArrayList kHits = new ArrayList<>(); kHits.add(sortedHits.get(l).get(0)); @@ -804,7 +792,7 @@ public List HitListPruner(List hits) { rmHits.removeAll(kHits); sortedHits.get(l).removeAll(rmHits); } - if(sortedHits.get(l).size()>=10) + else if(sortedHits.get(l).size()>=10) sortedHits.get(l).removeAll(sortedHits.get(l)); } @@ -861,13 +849,13 @@ public FittedCluster IsolatedHitsPruner(FittedCluster clus) { fcluster.add(clus.get(i)); } } - if (layer == 6) // look of neighbor in previous layer + else if (layer == 6) // look of neighbor in previous layer { if (HitArray[layer - 2][wire - 1] != null || HitArray[layer - 2][wire - 2] != null || HitArray[layer - 2][wire] != null || HitArray[layer - 1][wire - 2] != null || HitArray[layer - 1][wire] != null) { fcluster.add(clus.get(i)); } } - if (layer > 1 && layer < 6) // look of neighbor in next and previous layers + else if (layer > 1 && layer < 6) // look of neighbor in next and previous layers { if (HitArray[layer][wire - 1] != null || HitArray[layer][wire - 2] != null || HitArray[layer][wire] != null || HitArray[layer - 2][wire - 1] != null || HitArray[layer - 2][wire - 2] != null || HitArray[layer - 2][wire] != null || HitArray[layer - 1][wire - 2] != null || HitArray[layer - 1][wire] != null) { fcluster.add(clus.get(i)); @@ -929,7 +917,7 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean baseClusterHits.addAll(hitsInLayer); // safe all good hits to base cluster } - if (hitsInLayer.size() == 2) { + else if (hitsInLayer.size() == 2) { double docaSum = 0; for (int j = 0; j < hitsInLayer.size(); j++) { docaSum += hitsInLayer.get(j).get_Residual(); @@ -963,7 +951,6 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean } if (nbLyr > 0) { - for (int[] get : Constants.getInstance().CombArray.get(nbLyr - 1)) { ArrayList hitsInClusterCand = new ArrayList<>(); hitsInClusterCand.addAll(baseClusterHits); @@ -973,6 +960,7 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean hitsInClusCandLists.add(hitsInClusterCand); } } + for (int i = 0; i < hitsInClusCandLists.size(); i++) { FittedCluster newClus = new FittedCluster(clus.getBaseCluster()); for (int i1 = 0; i1 < newClus.size(); i1++) { @@ -982,17 +970,7 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean clusters.add(newClus); } - // get the best cluster - //LOGGER.log(Level.INFO, " clusters for selection "); - //for(FittedCluster c : clusters) { - // LOGGER.log(Level.INFO, c.printInfo()); - // for(FittedHit h : c) - // LOGGER.log(Level.INFO, h.printInfo()); - //} FittedCluster BestCluster = cf.BestClusterSelector(clusters, "LC"); - //LOGGER.log(Level.INFO, " ---> selected cluster : "); - //for(FittedHit h : BestCluster) - // LOGGER.log(Level.INFO, h.printInfo()); return BestCluster; } From 3ecb22c0f27ebc8c10a4dfbbe1052ca5fbfd5c37 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 4 May 2026 16:58:06 -0400 Subject: [PATCH 2/2] fix oops --- .../java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java | 1 + 1 file changed, 1 insertion(+) 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 e8ff221b97..48643ca6e2 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 @@ -20,6 +20,7 @@ public class ClusterCleanerUtilities { private List> sortedHits; public ClusterCleanerUtilities() { + sortedHits = new ArrayList<>(); for(int l = 0; l < 6; l++) sortedHits.add(new ArrayList<>()); }