Skip to content

Commit dfd1905

Browse files
authored
fix: replace DC string comparisons with enums (#1246)
* cleanup * remove string bookkeeping * cleanup * satisfy spotbug/dependency analysis * satisfy spotbugs
1 parent 9a05b5b commit dfd1905

6 files changed

Lines changed: 76 additions & 72 deletions

File tree

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6-
import java.util.logging.Logger;
7-
import org.jlab.detector.geant4.v2.DCGeant4Factory;
8-
import org.jlab.io.base.DataEvent;
96

7+
import org.jlab.io.base.DataEvent;
108
import org.jlab.rec.dc.Constants;
9+
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
1110
import org.jlab.rec.dc.hit.FittedHit;
1211
import org.jlab.rec.dc.hit.Hit;
1312
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
1413
import org.jlab.utils.groups.IndexedTable;
14+
import org.jlab.detector.geant4.v2.DCGeant4Factory;
1515

1616
public class ClusterCleanerUtilities {
1717

18-
private static final Logger LOGGER = Logger.getLogger(ClusterCleanerUtilities.class.getName());
19-
2018
private List<ArrayList<Hit>> sortedHits;
2119

2220
public ClusterCleanerUtilities() {
@@ -194,7 +192,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
194192
if((!isExceptionalCluster(newClus) && nLayers >= Constants.DC_MIN_NLAYERS)
195193
|| (isExceptionalCluster(newClus) && nLayers >= Constants.DC_MIN_NLAYERS - 1)) {
196194
//require consistency with line
197-
cf.SetFitArray(newClus, "LC");
195+
cf.SetFitArray(newClus, CoordSys.LC);
198196
cf.Fit(newClus, true);
199197
if ((nLayers == 6 && newClus.get_fitProb() > 0.9) || (nLayers == 5 && newClus.get_fitProb() > 0.85)
200198
|| (nLayers == 4 && newClus.get_fitProb() > 0.75) || (nLayers == 3 && newClus.get_fitProb() > 0.65)) {
@@ -213,7 +211,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
213211
int newcid = nextClsStartIndex;
214212
for (FittedCluster cluster : splitclusters) {
215213
cluster.set_Id(newcid++);
216-
cf.SetFitArray(cluster, "LC");
214+
cf.SetFitArray(cluster, CoordSys.LC);
217215
cf.Fit(cluster, true);
218216

219217
FittedCluster bestCls = OverlappingClusterResolver(cluster, splitclusters);
@@ -229,7 +227,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
229227
List<FittedCluster> selectedClusList2 = new ArrayList<>();
230228
for (FittedCluster cluster : selectedClusList) {
231229
cluster.set_Id(newcid++);
232-
cf.SetFitArray(cluster, "LC");
230+
cf.SetFitArray(cluster, CoordSys.LC);
233231
cf.Fit(cluster, true);
234232

235233
FittedCluster bestCls = OverlappingClusterResolver(cluster, selectedClusList);
@@ -569,7 +567,7 @@ else if (index == 6) {
569567
}
570568
}
571569

572-
return cf.BestClusterSelector(arrayOfClus, "TSC");
570+
return cf.BestClusterSelector(arrayOfClus, CoordSys.TSC);
573571

574572
}
575573

@@ -680,7 +678,7 @@ else if (hitsInLayer.size() == 2) {
680678
// for(FittedHit h : c)
681679
// LOGGER.log(Level.INFO, h.printInfo());
682680
//}
683-
FittedCluster BestCluster = cf.BestClusterSelector(clusters, "LC");
681+
FittedCluster BestCluster = cf.BestClusterSelector(clusters, CoordSys.LC);
684682
//LOGGER.log(Level.INFO, " ---> selected cluster : ");
685683
//for(FittedHit h : BestCluster)
686684
// LOGGER.log(Level.INFO, h.printInfo());
@@ -752,13 +750,14 @@ public FittedCluster OverlappingClusterResolver(FittedCluster thisclus, List<Fit
752750
return overlapingClusters.get(0);
753751

754752
}
755-
/**
753+
754+
/**
756755
* Prunes the input hit list to remove noise candidates; the algorithm finds
757756
* contiguous hits in a layer (column) and removes hits according to the
758757
* number (Nc) of such contiguous hits in a given layer.If Nc=3, keep only
759-
the middle hit If Nc=4, keep only the first and last hit in that column;
760-
if Nc > 4, keep the first 2 and last 2 hits in that column, if Nc > 10
761-
remove all hits in that column.
758+
* the middle hit If Nc=4, keep only the first and last hit in that column;
759+
* if Nc > 4, keep the first 2 and last 2 hits in that column, if Nc > 10
760+
* remove all hits in that column.
762761
*
763762
* @param hits the unfitted hits
764763
* @return
@@ -971,8 +970,7 @@ else if (hitsInLayer.size() == 2) {
971970
clusters.add(newClus);
972971
}
973972

974-
FittedCluster BestCluster = cf.BestClusterSelector(clusters, "LC");
975-
return BestCluster;
973+
return cf.BestClusterSelector(clusters, CoordSys.LC);
976974
}
977975

978976
/**

‎reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterFinder.java‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
import java.util.Map;
99
import java.util.logging.Level;
1010
import java.util.logging.Logger;
11-
import org.jlab.detector.geant4.v2.DCGeant4Factory;
12-
import org.jlab.io.base.DataEvent;
1311

12+
import org.jlab.io.base.DataEvent;
1413
import org.jlab.io.evio.EvioDataBank;
1514
import org.jlab.io.evio.EvioDataEvent;
1615
import org.jlab.rec.dc.Constants;
16+
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
1717
import org.jlab.rec.dc.hit.Hit;
1818
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
1919
import org.jlab.rec.dc.hit.FittedHit;
2020
import org.jlab.utils.groups.IndexedTable;
21+
import org.jlab.detector.geant4.v2.DCGeant4Factory;
2122

2223
/**
2324
* A hit pruning algorithm to reject noise that gives a pattern of hits that are
@@ -216,12 +217,12 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane
216217

217218
for (FittedCluster clus : selectedClusList) {
218219

219-
cf.SetFitArray(clus, "LC");
220+
cf.SetFitArray(clus, CoordSys.LC);
220221
cf.Fit(clus, true);
221222
if(!ct.isExceptionalFittedCluster(clus) && clus.get_fitProb()<Constants.HITBASEDTRKGMINFITHI2PROB) {
222223
ct.IsolatedHitsPruner(clus);
223224
//Refit
224-
cf.SetFitArray(clus, "LC");
225+
cf.SetFitArray(clus, CoordSys.LC);
225226
cf.Fit(clus, true);
226227
}
227228
if (clus.get_fitProb() > Constants.HITBASEDTRKGMINFITHI2PROB ){
@@ -246,7 +247,7 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane
246247
//fhit.set_AssociatedClusterID(clus.get_Id());
247248
}
248249

249-
cf.SetFitArray(clus, "TSC");
250+
cf.SetFitArray(clus, CoordSys.TSC);
250251
cf.Fit(clus, true);
251252
cf.SetResidualDerivedParams(clus, false, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false, local= false
252253

@@ -273,7 +274,7 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane
273274
}
274275
clus.removeAll(rmHits);
275276
clus.addAll(addHits);
276-
cf.SetFitArray(clus, "TSC");
277+
cf.SetFitArray(clus, CoordSys.TSC);
277278
cf.Fit(clus, false);
278279
cf.SetSegmentLineParameters(clus.get(0).get_Z(), clus);
279280
if (clus != null ) {
@@ -318,7 +319,7 @@ public List<FittedCluster> RecomposeClusters(Map<Integer, ArrayList<FittedHit>>
318319

319320
for (FittedCluster clus : clusters) {
320321
if (clus != null) {
321-
cf.SetFitArray(clus, "TSC");
322+
cf.SetFitArray(clus, CoordSys.TSC);
322323
cf.Fit(clus, true);
323324
cf.SetResidualDerivedParams(clus, true, false, dcDetector); //calcTimeResidual=false, resetLRAmbig=false
324325
cf.Fit(clus, false);
@@ -476,7 +477,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
476477
}
477478

478479
}
479-
cf.SetFitArray(Clus2, "TSC");
480+
cf.SetFitArray(Clus2, CoordSys.TSC);
480481
cf.Fit(Clus2, true);
481482

482483
if (Math.abs(clus.get_Chisq() - Clus2.get_Chisq()) < 1) {
@@ -488,7 +489,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
488489

489490
for (FittedCluster clus : clusters) {
490491

491-
cf.SetFitArray(clus, "TSC");
492+
cf.SetFitArray(clus, CoordSys.TSC);
492493
cf.Fit(clus, true);
493494

494495
// update the hits
@@ -500,7 +501,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
500501
double prevChi2 = 999999999;
501502
double trkAngleFinal = 0;
502503
while (Chi2Diff > 0) {
503-
cf.SetFitArray(clus, "TSC");
504+
cf.SetFitArray(clus, CoordSys.TSC);
504505
cf.Fit(clus, true);
505506
Chi2Diff = prevChi2 - clus.get_Chisq();
506507
if (Chi2Diff > 0) {
@@ -519,11 +520,11 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
519520
for (FittedHit fhit : clus) {
520521
fhit.updateHitPositionWithTime(event, trkAngleFinal, fhit.getB(), tab, DcDetector, tde);
521522
}
522-
cf.SetFitArray(clus, "TSC");
523+
cf.SetFitArray(clus, CoordSys.TSC);
523524
cf.Fit(clus, true);
524525
cf.SetResidualDerivedParams(clus, true, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false
525526

526-
cf.SetFitArray(clus, "TSC");
527+
cf.SetFitArray(clus, CoordSys.TSC);
527528
cf.Fit(clus, false);
528529

529530
cf.SetSegmentLineParameters(clus.get(0).get_Z(), clus);
@@ -582,7 +583,7 @@ public EvioDataBank getLayerEfficiencies(List<FittedCluster> fclusters, List<Hit
582583

583584
int status = 0;
584585
//fit
585-
cf.SetFitArray(clus, "LC");
586+
cf.SetFitArray(clus, org.jlab.rec.dc.cluster.ClusterFitter.CoordSys.LC);
586587
cf.Fit(clus, true);
587588

588589
for (Hit hit : allhits) {

‎reconstruction/dc/src/main/java/org/jlab/rec/dc/cluster/ClusterFitter.java‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6-
import org.jlab.detector.geant4.v2.DCGeant4Factory;
76

87
import org.jlab.geom.prim.Line3D;
98
import org.jlab.geom.prim.Point3D;
109
import org.jlab.geom.prim.Vector3D;
1110
import org.jlab.rec.dc.track.fit.basefit.LineFitPars;
1211
import org.jlab.rec.dc.track.fit.basefit.LineFitter;
1312
import org.jlab.rec.dc.Constants;
13+
import org.jlab.detector.geant4.v2.DCGeant4Factory;
1414

1515
public class ClusterFitter {
1616

17+
public static enum CoordSys {
18+
LC (1, "LC"),
19+
TSC (2, "TSC"),
20+
LTS (3, "LTS");
21+
public int id;
22+
public String name;
23+
CoordSys(int id, String name) {
24+
this.id = id;
25+
this.name = name;
26+
}
27+
}
28+
29+
private CoordSys coordinateSystem;
30+
1731
/**
1832
* Fits a cluster to a line
1933
*
@@ -40,25 +54,24 @@ public void reset() {
4054
ey.clear();
4155
}
4256

43-
public void SetFitArray(FittedCluster clus, String system) {
57+
public void SetFitArray(FittedCluster clus, CoordSys system) {
4458

4559
Collections.sort(clus);
4660
reset();
47-
61+
4862
for (int i = 0; i < clus.size(); i++) {
49-
if (system.equals("LC")) {
50-
CoordinateSystem = "LC"; // local coordinate grid Delta_z = 1
63+
if (system.equals(CoordSys.LC)) {
64+
coordinateSystem = CoordSys.LC; // local coordinate grid Delta_z = 1
5165
x.add(i, clus.get(i).get_lX());
5266
ex.add(i, (double) 0);
5367
y.add(i, clus.get(i).get_lY());
5468
ey.add(i, (double) 1);
5569
}
56-
if (system.equals("TSC")) {
57-
CoordinateSystem = "TSC"; // local tilted coordinate system Delta_z ~ cell size
70+
if (system.equals(CoordSys.TSC)) {
71+
coordinateSystem = CoordSys.TSC; // local tilted coordinate system Delta_z ~ cell size
5872
x.add(i, clus.get(i).get_Z());
5973
ex.add(i, (double) 0);
6074
y.add(i, clus.get(i).get_X());
61-
//ey[i]= clus.get(i).get_DocaErr(); //CODEFIX1
6275
ey.add(i, clus.get(i).get_DocaErr() / stereo);
6376
}
6477

@@ -138,7 +151,6 @@ public void SetSegmentLineParameters(double x0, FittedCluster clus) {
138151

139152
} else {
140153
System.err.println("Cluster Fit Params not set!!!");
141-
142154
}
143155
}
144156

@@ -199,7 +211,7 @@ public void SetResidualDerivedParams(FittedCluster clus, boolean calcTimeResidua
199211
}
200212
}
201213
if (resetLRAmbig) {
202-
if ((CoordinateSystem.equals("LC") && Math.abs(residual) < 0.01) || (CoordinateSystem.equals("LTS")
214+
if ((coordinateSystem.equals(CoordSys.LC) && Math.abs(residual) < 0.01) || (coordinateSystem.equals(CoordSys.LTS)
203215
&& clus.get(i).get_Doca() / clus.get(i).get_CellSize() < 0.4)) { // DOCA require to be larger than 40% of cell size for hit-based tracking LR assignment
204216
clus.get(i).set_LeftRightAmb(0);
205217
}
@@ -231,7 +243,7 @@ public void SetResidualDerivedParams(FittedCluster clus, boolean calcTimeResidua
231243
* @param system coordinate system in which the fit is performed
232244
* @return the fitted cluster with the best fit chi2
233245
*/
234-
public FittedCluster BestClusterSelector(List<FittedCluster> clusters, String system) {
246+
public FittedCluster BestClusterSelector(List<FittedCluster> clusters, CoordSys system) {
235247

236248
FittedCluster BestCluster = null;
237249
double bestChisq = 999999999.;
@@ -315,5 +327,4 @@ private boolean isBrickWall(FittedCluster clusCand) {
315327
}
316328
return isBW;
317329
}
318-
319330
}

‎reconstruction/dc/src/main/java/org/jlab/rec/dc/cross/CrossListFinder.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.jlab.io.base.DataEvent;
1111
import org.jlab.rec.dc.Constants;
1212
import org.jlab.rec.dc.cluster.ClusterFitter;
13+
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
1314
import org.jlab.rec.dc.hit.FittedHit;
1415
import org.jlab.rec.dc.segment.Segment;
1516
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
@@ -216,18 +217,18 @@ private void recalcParsSegment(DataEvent event, Segment _Segment1, IndexedTable
216217
fhit.updateHitPositionWithTime(event, trkAngle, fhit.getB(), tab, DcDetector, tde);
217218
}
218219

219-
cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
220+
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
220221
cf.Fit(_Segment1.get_fittedCluster(), true);
221222
trkAngle = _Segment1.get_fittedCluster().get_clusterLineFitSlope();
222223

223224
for (FittedHit fhit : _Segment1.get_fittedCluster()) {
224225
fhit.updateHitPositionWithTime(event, trkAngle, fhit.getB(), tab, DcDetector, tde);
225226
}
226-
cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
227+
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
227228
cf.Fit(_Segment1.get_fittedCluster(), true);
228229
cf.SetResidualDerivedParams(_Segment1.get_fittedCluster(), true, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false
229230

230-
cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
231+
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
231232
cf.Fit(_Segment1.get_fittedCluster(), false);
232233

233234
cf.SetSegmentLineParameters(_Segment1.get_fittedCluster().get(0).get_Z(), _Segment1.get_fittedCluster());

‎reconstruction/dc/src/main/java/org/jlab/rec/dc/nn/PatternRec.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jlab.rec.dc.cluster.ClusterCleanerUtilities;
1515
import org.jlab.rec.dc.cluster.ClusterFinder;
1616
import org.jlab.rec.dc.cluster.ClusterFitter;
17+
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
1718
import org.jlab.rec.dc.cluster.FittedCluster;
1819
import org.jlab.rec.dc.cross.Cross;
1920
import org.jlab.rec.dc.cross.CrossList;
@@ -172,7 +173,7 @@ public List<Segment> RecomposeSegments(List<Hit> fhits,
172173
fhit.updateHitPosition(DcDetector);
173174
}
174175

175-
cf.SetFitArray(fclus, "TSC");
176+
cf.SetFitArray(fclus, CoordSys.TSC);
176177
cf.Fit(fclus, true);
177178
cf.SetResidualDerivedParams(fclus, false, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false, local= false
178179

@@ -183,7 +184,7 @@ public List<Segment> RecomposeSegments(List<Hit> fhits,
183184
fhit.set_AssociatedClusterID(fclus.get_Id());
184185
fhit.set_AssociatedHBTrackID(entry.getKey());
185186
}
186-
cf.SetFitArray(fclus, "TSC");
187+
cf.SetFitArray(fclus, org.jlab.rec.dc.cluster.ClusterFitter.CoordSys.TSC);
187188
cf.Fit(fclus, false);
188189
cf.SetSegmentLineParameters(fclus.get(0).get_Z(), fclus);
189190

0 commit comments

Comments
 (0)