Skip to content

Commit b69d9b4

Browse files
committed
cleanup
1 parent e7791c9 commit b69d9b4

File tree

1 file changed

+30
-85
lines changed

1 file changed

+30
-85
lines changed

common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java

Lines changed: 30 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@
1919

2020
public class AdaptiveSwim extends ASwim {
2121

22+
private static double[] convert(AdaptiveSwimResult result, double p) {
23+
double[] value = null;
24+
if (result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
25+
value = new double[8];
26+
value[0] = result.getUf()[0] * 100; // convert back to cm
27+
value[1] = result.getUf()[1] * 100; // convert back to cm
28+
value[2] = result.getUf()[2] * 100; // convert back to cm
29+
value[3] = result.getUf()[3] * p; // normalized values
30+
value[4] = result.getUf()[4] * p;
31+
value[5] = result.getUf()[5] * p;
32+
value[6] = result.getFinalS() * 100;
33+
value[7] = 0; // Conversion from kG.m to T.cm
34+
}
35+
return value;
36+
}
37+
2238
@Override
2339
public double[] SwimRho(double radius, double accuracy) {
2440

25-
double[] value = new double[8];
26-
2741
// convert to meters:
2842
radius = radius/100;
2943

@@ -33,30 +47,17 @@ public double[] SwimRho(double radius, double accuracy) {
3347
PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius,
3448
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
3549

36-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
37-
value[0] = result.getUf()[0] * 100; // convert back to cm
38-
value[1] = result.getUf()[1] * 100; // convert back to cm
39-
value[2] = result.getUf()[2] * 100; // convert back to cm
40-
value[3] = result.getUf()[3] * _pTot; // normalized values
41-
value[4] = result.getUf()[4] * _pTot;
42-
value[5] = result.getUf()[5] * _pTot;
43-
value[6] = result.getFinalS() * 100;
44-
value[7] = 0; // Conversion from kG.m to T.cm
45-
}
46-
else {
47-
return null;
48-
}
50+
return convert(result, _pTot);
51+
4952
} catch (AdaptiveSwimException e) {
5053
e.printStackTrace();
5154
}
52-
return value;
55+
return null;
5356
}
5457

5558
@Override
5659
public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) {
5760

58-
double[] value = new double[8];
59-
6061
// convert to meters:
6162
radius = radius/100;
6263
Point a1 = new Point(axisPoint1.x()/100, axisPoint1.y()/100, axisPoint1.z()/100);
@@ -66,37 +67,22 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r
6667
Cylinder targetCylinder = new Cylinder(centerLine, radius);
6768

6869
try {
69-
7070
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
7171

7272
PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder,
7373
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
7474

75-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
76-
value[0] = result.getUf()[0] * 100; // convert back to cm
77-
value[1] = result.getUf()[1] * 100; // convert back to cm
78-
value[2] = result.getUf()[2] * 100; // convert back to cm
79-
value[3] = result.getUf()[3] * _pTot; // normalized values
80-
value[4] = result.getUf()[4] * _pTot;
81-
value[5] = result.getUf()[5] * _pTot;
82-
value[6] = result.getFinalS() * 100;
83-
value[7] = 0; // Conversion from kG.m to T.cm
84-
}
85-
else {
86-
return null;
87-
}
75+
return convert(result, _pTot);
8876

8977
} catch (AdaptiveSwimException e) {
9078
e.printStackTrace();
9179
}
92-
return value;
80+
return null;
9381
}
9482

9583
@Override
9684
public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) {
9785

98-
double[] value = new double[8];
99-
10086
// convert to meters:
10187
Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z());
10288
Point point = new Point(p.x()/100, p.y()/100, p.z()/100);
@@ -108,67 +94,38 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) {
10894

10995
PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane,
11096
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
97+
98+
return convert(result, _pTot);
11199

112-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
113-
value[0] = result.getUf()[0] * 100; // convert back to cm
114-
value[1] = result.getUf()[1] * 100; // convert back to cm
115-
value[2] = result.getUf()[2] * 100; // convert back to cm
116-
value[3] = result.getUf()[3] * _pTot; // normalized values
117-
value[4] = result.getUf()[4] * _pTot;
118-
value[5] = result.getUf()[5] * _pTot;
119-
value[6] = result.getFinalS() * 100;
120-
value[7] = 0; // Conversion from kG.m to T.cm
121-
}
122-
else {
123-
return null;
124-
}
125-
126100
} catch (AdaptiveSwimException e) {
127101
e.printStackTrace();
128102
}
129-
return value;
103+
return null;
130104
}
131105

132106
@Override
133107
public double[] SwimToSphere(double Rad) {
134108

135-
double[] value = new double[8];
136-
137109
// convert to meters:
138-
139110
Sphere targetSphere = new Sphere(new Point(0,0,0), Rad/100);
140111

141112
try {
142113
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
143114

144115
PC.AS.swimSphere(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetSphere,
145116
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
117+
118+
return convert(result, _pTot);
146119

147-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
148-
value[0] = result.getUf()[0] * 100; // convert back to cm
149-
value[1] = result.getUf()[1] * 100; // convert back to cm
150-
value[2] = result.getUf()[2] * 100; // convert back to cm
151-
value[3] = result.getUf()[3] * _pTot; // normalized values
152-
value[4] = result.getUf()[4] * _pTot;
153-
value[5] = result.getUf()[5] * _pTot;
154-
value[6] = result.getFinalS() * 100;
155-
value[7] = 0; // Conversion from kG.m to T.cm
156-
}
157-
else {
158-
return null;
159-
}
160-
161120
} catch (AdaptiveSwimException e) {
162121
e.printStackTrace();
163122
}
164-
return value;
123+
return null;
165124
}
166125

167126
@Override
168127
public double[] SwimToLine(Line3D l) {
169128

170-
double[] value = new double[8];
171-
172129
// convert to meters:
173130
Point a1 = new Point(l.origin().x()/100, l.origin().y()/100, l.origin().z()/100);
174131
Point a2 = new Point(l.end().x()/100, l.end().y()/100, l.end().z()/100);
@@ -179,25 +136,13 @@ public double[] SwimToLine(Line3D l) {
179136

180137
PC.AS.swimLine(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetLine,
181138
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
182-
183-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
184-
value[0] = result.getUf()[0] * 100; // convert back to cm
185-
value[1] = result.getUf()[1] * 100; // convert back to cm
186-
value[2] = result.getUf()[2] * 100; // convert back to cm
187-
value[3] = result.getUf()[3] * _pTot; // normalized values
188-
value[4] = result.getUf()[4] * _pTot;
189-
value[5] = result.getUf()[5] * _pTot;
190-
value[6] = result.getFinalS() * 100;
191-
value[7] = 0; // Conversion from kG.m to T.cm
192-
}
193-
else {
194-
return null;
195-
}
139+
140+
return convert(result, _pTot);
196141

197142
} catch (AdaptiveSwimException e) {
198143
e.printStackTrace();
199144
}
200-
return value;
145+
return null;
201146
}
202147

203148
@Override

0 commit comments

Comments
 (0)