Skip to content

Commit cea7463

Browse files
committed
fill in more adapative methods
1 parent 2c596ee commit cea7463

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.jlab.clas.swimtools;
22

3+
import org.jlab.geom.prim.Line3D;
34
import org.jlab.geom.prim.Point3D;
45
import org.jlab.geom.prim.Vector3D;
56

67
/**
7-
*
8+
*
89
* @author baltzell
910
*/
1011
public abstract class ASwim extends SwimPars implements ISwim {
@@ -19,6 +20,11 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) {
1920
throw new UnsupportedOperationException("Not supported yet.");
2021
}
2122

23+
@Override
24+
public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) {
25+
throw new UnsupportedOperationException("Not supported yet.");
26+
}
27+
2228
@Override
2329
public double[] SwimToPlaneLab(double z_cm) {
2430
return SwimPlane(new Vector3D(0,0,1), new Point3D(0,0,z_cm), accuracy);
@@ -34,4 +40,9 @@ public double[] SwimToZ(double Z, int dir) {
3440
return SwimPlane(new Vector3D(0,0,dir*1), new Point3D(0,0,Z), accuracy);
3541
}
3642

43+
@Override
44+
public double[] SwimToBeamLine(double xB, double yB) {
45+
return SwimToLine(new Line3D(xB,yB,-1,xB,yB,1));
46+
}
47+
3748
}

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

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import cnuphys.adaptiveSwim.geometry.Line;
88
import cnuphys.adaptiveSwim.geometry.Point;
99
import cnuphys.adaptiveSwim.geometry.Vector;
10+
import cnuphys.adaptiveSwim.geometry.Sphere;
11+
import cnuphys.adaptiveSwim.geometry.Cylinder;
1012

1113
import cnuphys.adaptiveSwim.AdaptiveSwimException;
1214
import cnuphys.adaptiveSwim.AdaptiveSwimResult;
1315
import cnuphys.adaptiveSwim.AdaptiveSwimmer;
16+
import cnuphys.adaptiveSwim.geometry.Plane;
1417

1518
import cnuphys.swim.SwimTrajectory;
1619

@@ -60,8 +63,8 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r
6063
Point a2 = new Point(axisPoint2.x()/100, axisPoint2.y()/100, axisPoint2.z()/100);
6164
Line centerLine = new Line(a1, a2);
6265

63-
cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius);
64-
66+
Cylinder targetCylinder = new Cylinder(centerLine, radius);
67+
6568
try {
6669

6770
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
@@ -98,7 +101,7 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) {
98101
Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z());
99102
Point point = new Point(p.x()/100, p.y()/100, p.z()/100);
100103

101-
cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point);
104+
Plane targetPlane = new Plane(norm, point);
102105

103106
try {
104107
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
@@ -128,22 +131,73 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) {
128131

129132
@Override
130133
public double[] SwimToSphere(double Rad) {
131-
throw new UnsupportedOperationException("Not supported yet.");
132-
}
133134

134-
@Override
135-
public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) {
136-
throw new UnsupportedOperationException("Not supported yet.");
137-
}
135+
double[] value = new double[8];
138136

139-
@Override
140-
public double[] SwimToBeamLine(double xB, double yB) {
141-
throw new UnsupportedOperationException("Not supported yet.");
137+
// convert to meters:
138+
139+
Sphere targetSphere = new Sphere(new Point(0,0,0), Rad/100);
140+
141+
try {
142+
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
143+
144+
PC.AS.swimSphere(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetSphere,
145+
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
146+
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+
161+
} catch (AdaptiveSwimException e) {
162+
e.printStackTrace();
163+
}
164+
return value;
142165
}
143166

144167
@Override
145168
public double[] SwimToLine(Line3D l) {
146-
throw new UnsupportedOperationException("Not supported yet.");
169+
170+
double[] value = new double[8];
171+
172+
// convert to meters:
173+
Point a1 = new Point(l.origin().x()/100, l.origin().y()/100, l.origin().z()/100);
174+
Point a2 = new Point(l.end().x()/100, l.end().y()/100, l.end().z()/100);
175+
Line targetLine = new Line(a1, a2);
176+
177+
try {
178+
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
179+
180+
PC.AS.swimLine(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetLine,
181+
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+
}
196+
197+
} catch (AdaptiveSwimException e) {
198+
e.printStackTrace();
199+
}
200+
return value;
147201
}
148202

149203
@Override

0 commit comments

Comments
 (0)