Skip to content

Commit 0eff342

Browse files
tongtongcaobaltzell
authored andcommitted
use wrapper to treat similar functions of isExceptionalCluster
1 parent 36dbe47 commit 0eff342

File tree

1 file changed

+35
-55
lines changed

1 file changed

+35
-55
lines changed

reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterCleanerUtilities.java

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,73 +1010,53 @@ public FittedCluster ClusterCleaner(FittedCluster clus, ClusterFitter cf, DCGean
10101010
return BestCluster;
10111011
}
10121012

1013-
/**
1014-
*
1015-
* @param hitsInClus the hits in a cluster
1016-
* @return if one or more layers are skipped in the cluster
1013+
/**
1014+
* Check if one or more layers are skipped in the cluster
1015+
* @param hitsInClus the hits in a cluster (can be either Hit or FittedHit)
1016+
* @param nlayr the number of layers
1017+
* @return true if one or more layers are skipped in the cluster
10171018
*/
1018-
public boolean isExceptionalCluster(List<Hit> hitsInClus){
1019-
// count hits in each layer
1020-
int nlayr = 6;
1019+
private boolean isExceptionalClusterHelper(List<? extends Hit> hitsInClus, int nlayr) {
1020+
// Initialize array to count hits in each layer
10211021
int[] nlayers = new int[nlayr];
1022-
for (int l = 0; l < nlayr; l++) {
1023-
nlayers[l] = 0;
1024-
for (int h = 0; h < hitsInClus.size(); h++) {
1025-
if (hitsInClus.get(h).get_Layer() == l + 1) {
1026-
nlayers[l]++;
1027-
}
1022+
1023+
// Count hits for each layer in a single pass through the hits
1024+
for (Hit hit : hitsInClus) {
1025+
int layer = hit.get_Layer() - 1; // layer numbering starts from 1
1026+
if (layer >= 0 && layer < nlayr) {
1027+
nlayers[layer]++;
10281028
}
10291029
}
10301030

1031-
boolean flag_hasSkippedLayer = false;
1032-
if((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)){
1033-
flag_hasSkippedLayer = true;
1031+
// Check if the first or last two layerers are missed
1032+
if ((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)) {
1033+
return true;
10341034
}
1035-
else{
1036-
for (int l = 0; l < 4; l++) {
1037-
if (nlayers[l] > 0 && nlayers[l+1] == 0) {
1038-
flag_hasSkippedLayer = true;
1039-
break;
1040-
}
1035+
1036+
// Check if there is one or more skipped layers in the middle
1037+
for (int l = 0; l < 4; l++) {
1038+
if (nlayers[l] > 0 && nlayers[l + 1] == 0) {
1039+
return true;
10411040
}
10421041
}
1043-
1044-
return flag_hasSkippedLayer;
1042+
1043+
return false;
10451044
}
10461045

1047-
/*
1048-
* @param hitsInClus the hits in a cluster
1049-
* @return if one or more layers are skipped in the cluster
1050-
*/
1051-
public boolean isExceptionalFittedCluster(List<FittedHit> hitsInClus){
1052-
// count hits in each layer
1053-
int nlayr = 6;
1054-
int[] nlayers = new int[nlayr];
1055-
for (int l = 0; l < nlayr; l++) {
1056-
nlayers[l] = 0;
1057-
for (int h = 0; h < hitsInClus.size(); h++) {
1058-
if (hitsInClus.get(h).get_Layer() == l + 1) {
1059-
nlayers[l]++;
1060-
}
1061-
}
1062-
}
1063-
1064-
boolean flag_hasSkippedLayer = false;
1065-
if((nlayers[0] == 0 && nlayers[1] == 0) || (nlayers[4] == 0 && nlayers[5] == 0)){
1066-
flag_hasSkippedLayer = true;
1067-
}
1068-
else{
1069-
for (int l = 0; l < 4; l++) {
1070-
if (nlayers[l] > 0 && nlayers[l+1] == 0) {
1071-
flag_hasSkippedLayer = true;
1072-
break;
1073-
}
1074-
}
1075-
}
1076-
1077-
return flag_hasSkippedLayer;
1046+
/**
1047+
* Wrapper for checking if a cluster of Hit objects is exceptional.
1048+
*/
1049+
public boolean isExceptionalCluster(List hitsInClus) {
1050+
return isExceptionalClusterHelper(hitsInClus, 6); // 6 layers for Hit objects
10781051
}
10791052

1053+
/**
1054+
* Wrapper for checking if a cluster of FittedHit objects is exceptional.
1055+
*/
1056+
public boolean isExceptionalFittedCluster(List hitsInClus) {
1057+
return isExceptionalClusterHelper(hitsInClus, 6); // 6 layers for FittedHit objects
1058+
}
1059+
10801060
public Cluster ClusterSticher(Cluster thisclus, Cluster nextclus, int cid){
10811061
ClusterFitter cf = new ClusterFitter();
10821062

0 commit comments

Comments
 (0)