Skip to content

Commit 9799685

Browse files
committed
move adaptive methods to new wrapper
1 parent c9587af commit 9799685

File tree

3 files changed

+199
-207
lines changed

3 files changed

+199
-207
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package org.jlab.clas.swimtools;
2+
3+
import org.jlab.geom.prim.Line3D;
4+
import org.jlab.geom.prim.Point3D;
5+
import org.jlab.geom.prim.Vector3D;
6+
7+
import cnuphys.adaptiveSwim.geometry.Line;
8+
import cnuphys.adaptiveSwim.geometry.Point;
9+
import cnuphys.adaptiveSwim.geometry.Vector;
10+
11+
import cnuphys.adaptiveSwim.AdaptiveSwimException;
12+
import cnuphys.adaptiveSwim.AdaptiveSwimResult;
13+
import cnuphys.adaptiveSwim.AdaptiveSwimmer;
14+
15+
import cnuphys.swim.SwimTrajectory;
16+
17+
public class AdaptiveSwim extends SwimPars implements ISwim {
18+
19+
@Override
20+
public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) {
21+
throw new UnsupportedOperationException("Not supported yet.");
22+
}
23+
24+
@Override
25+
public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) {
26+
throw new UnsupportedOperationException("Not supported yet.");
27+
}
28+
29+
@Override
30+
public double[] SwimToPlaneLab(double z_cm) {
31+
throw new UnsupportedOperationException("Not supported yet.");
32+
}
33+
34+
@Override
35+
public double[] SwimToCylinder(double radius) {
36+
throw new UnsupportedOperationException("Not supported yet.");
37+
}
38+
39+
@Override
40+
public double[] SwimRho(double radius, double accuracy) {
41+
42+
double[] value = new double[8];
43+
44+
// convert to meters:
45+
radius = radius/100;
46+
47+
try {
48+
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
49+
50+
PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius,
51+
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
52+
53+
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
54+
value[0] = result.getUf()[0] * 100; // convert back to cm
55+
value[1] = result.getUf()[1] * 100; // convert back to cm
56+
value[2] = result.getUf()[2] * 100; // convert back to cm
57+
value[3] = result.getUf()[3] * _pTot; // normalized values
58+
value[4] = result.getUf()[4] * _pTot;
59+
value[5] = result.getUf()[5] * _pTot;
60+
value[6] = result.getFinalS() * 100;
61+
value[7] = 0; // Conversion from kG.m to T.cm
62+
}
63+
else {
64+
return null;
65+
}
66+
} catch (AdaptiveSwimException e) {
67+
e.printStackTrace();
68+
}
69+
return value;
70+
}
71+
72+
public static Point dog(Point3D p) {
73+
return new Point(p.x(), p.y(), p.z());
74+
}
75+
76+
@Override
77+
public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) {
78+
79+
double[] value = new double[8];
80+
81+
// convert to meters:
82+
radius = radius/100;
83+
Point a1 = new Point(axisPoint1.x()/100, axisPoint1.y()/100, axisPoint1.z()/100);
84+
Point a2 = new Point(axisPoint2.x()/100, axisPoint2.y()/100, axisPoint2.z()/100);
85+
Line centerLine = new Line(a1, a2);
86+
87+
cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius);
88+
89+
try {
90+
91+
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
92+
93+
PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder,
94+
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
95+
96+
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
97+
value[0] = result.getUf()[0] * 100; // convert back to cm
98+
value[1] = result.getUf()[1] * 100; // convert back to cm
99+
value[2] = result.getUf()[2] * 100; // convert back to cm
100+
value[3] = result.getUf()[3] * _pTot; // normalized values
101+
value[4] = result.getUf()[4] * _pTot;
102+
value[5] = result.getUf()[5] * _pTot;
103+
value[6] = result.getFinalS() * 100;
104+
value[7] = 0; // Conversion from kG.m to T.cm
105+
}
106+
else {
107+
return null;
108+
}
109+
110+
} catch (AdaptiveSwimException e) {
111+
e.printStackTrace();
112+
}
113+
return value;
114+
}
115+
116+
@Override
117+
public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) {
118+
119+
double[] value = new double[8];
120+
121+
// convert to meters:
122+
Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z());
123+
Point point = new Point(p.x()/100, p.y()/100, p.z()/100);
124+
125+
cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point);
126+
127+
try {
128+
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
129+
130+
PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane,
131+
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
132+
133+
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
134+
value[0] = result.getUf()[0] * 100; // convert back to cm
135+
value[1] = result.getUf()[1] * 100; // convert back to cm
136+
value[2] = result.getUf()[2] * 100; // convert back to cm
137+
value[3] = result.getUf()[3] * _pTot; // normalized values
138+
value[4] = result.getUf()[4] * _pTot;
139+
value[5] = result.getUf()[5] * _pTot;
140+
value[6] = result.getFinalS() * 100;
141+
value[7] = 0; // Conversion from kG.m to T.cm
142+
}
143+
else {
144+
return null;
145+
}
146+
147+
} catch (AdaptiveSwimException e) {
148+
e.printStackTrace();
149+
}
150+
return value;
151+
}
152+
153+
@Override
154+
public double[] SwimToSphere(double Rad) {
155+
throw new UnsupportedOperationException("Not supported yet.");
156+
}
157+
158+
@Override
159+
public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) {
160+
throw new UnsupportedOperationException("Not supported yet.");
161+
}
162+
163+
@Override
164+
public double[] SwimToBeamLine(double xB, double yB) {
165+
throw new UnsupportedOperationException("Not supported yet.");
166+
}
167+
168+
@Override
169+
public double[] SwimToLine(Line3D l) {
170+
throw new UnsupportedOperationException("Not supported yet.");
171+
}
172+
173+
@Override
174+
public double[] SwimToZ(double Z, int dir) {
175+
throw new UnsupportedOperationException("Not supported yet.");
176+
}
177+
178+
@Override
179+
public double[] SwimToDCA(SwimTrajectory trk2) {
180+
throw new UnsupportedOperationException("Not supported yet.");
181+
}
182+
183+
}

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

Lines changed: 16 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
import cnuphys.swimZ.SwimZResult;
1414
import cnuphys.swimZ.SwimZStateVector;
1515

16-
import cnuphys.adaptiveSwim.AdaptiveSwimException;
1716
import cnuphys.adaptiveSwim.AdaptiveSwimResult;
18-
import cnuphys.adaptiveSwim.AdaptiveSwimmer;
19-
import cnuphys.adaptiveSwim.geometry.Line;
20-
import cnuphys.adaptiveSwim.geometry.Point;
21-
import cnuphys.adaptiveSwim.geometry.Vector;
2217
import org.jlab.clas.swimtools.Stoppers.BeamLineSwimStopper;
2318

2419
import org.jlab.clas.swimtools.Stoppers.CylindricalBoundarySwimStopper;
@@ -34,6 +29,22 @@
3429
*/
3530
public class Swim extends SwimPars implements ISwim {
3631

32+
private SwimTrajectory swimTraj;
33+
34+
/**
35+
* @return the swimTraj
36+
*/
37+
public SwimTrajectory getSwimTraj() {
38+
return swimTraj;
39+
}
40+
41+
/**
42+
* @param swimTraj the swimTraj to set
43+
*/
44+
public void setSwimTraj(SwimTrajectory swimTraj) {
45+
this.swimTraj = swimTraj;
46+
}
47+
3748
/**
3849
*
3950
* @param sector
@@ -556,22 +567,6 @@ public double[] SwimToZ(double Z, int dir) {
556567
return value;
557568
}
558569

559-
private SwimTrajectory swimTraj;
560-
561-
/**
562-
* @return the swimTraj
563-
*/
564-
public SwimTrajectory getSwimTraj() {
565-
return swimTraj;
566-
}
567-
568-
/**
569-
* @param swimTraj the swimTraj to set
570-
*/
571-
public void setSwimTraj(SwimTrajectory swimTraj) {
572-
this.swimTraj = swimTraj;
573-
}
574-
575570
@Override
576571
public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track
577572

@@ -584,124 +579,13 @@ public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca
584579
if (st==null) return null;
585580

586581
double[] lastY = st.lastElement();
587-
588582
value[0] = lastY[0] * 100; // convert back to cm
589583
value[1] = lastY[1] * 100; // convert back to cm
590584
value[2] = lastY[2] * 100; // convert back to cm
591585
value[3] = lastY[3] * _pTot; // normalized values
592586
value[4] = lastY[4] * _pTot;
593587
value[5] = lastY[5] * _pTot;
594-
595-
return value;
596-
}
597-
598-
599-
public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) {
600-
601-
if (this.SwimUnPhys) return null;
602-
603-
double[] value = new double[8];
604-
605-
Vector norm = new Vector(nx,ny,nz);
606-
Point point = new Point(px/100,py/100,pz/100);
607-
608-
cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point);
609-
610-
try {
611-
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
612-
613-
PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane,
614-
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
615-
616-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
617-
value[0] = result.getUf()[0] * 100; // convert back to cm
618-
value[1] = result.getUf()[1] * 100; // convert back to cm
619-
value[2] = result.getUf()[2] * 100; // convert back to cm
620-
value[3] = result.getUf()[3] * _pTot; // normalized values
621-
value[4] = result.getUf()[4] * _pTot;
622-
value[5] = result.getUf()[5] * _pTot;
623-
value[6] = result.getFinalS() * 100;
624-
value[7] = 0; // Conversion from kG.m to T.cm
625-
}
626-
else {
627-
return null;
628-
}
629-
630-
} catch (AdaptiveSwimException e) {
631-
e.printStackTrace();
632-
}
633588
return value;
634589
}
635-
636-
public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) {
637-
638-
if (this.SwimUnPhys) return null;
639-
640-
double[] value = new double[8];
641-
642-
radius = radius/100;
643-
Point a1 = new Point(a1x/100, a1y/100, a1z/100);
644-
Point a2 = new Point(a2x/100, a2y/100, a2z/100);
645-
Line centerLine = new Line(a1, a2);
646-
647-
cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius);
648-
649-
try {
650-
651-
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
652-
653-
PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder,
654-
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
655590

656-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
657-
value[0] = result.getUf()[0] * 100; // convert back to cm
658-
value[1] = result.getUf()[1] * 100; // convert back to cm
659-
value[2] = result.getUf()[2] * 100; // convert back to cm
660-
value[3] = result.getUf()[3] * _pTot; // normalized values
661-
value[4] = result.getUf()[4] * _pTot;
662-
value[5] = result.getUf()[5] * _pTot;
663-
value[6] = result.getFinalS() * 100;
664-
value[7] = 0; // Conversion from kG.m to T.cm
665-
}
666-
else {
667-
return null;
668-
}
669-
670-
} catch (AdaptiveSwimException e) {
671-
e.printStackTrace();
672-
}
673-
return value;
674-
}
675-
676-
public double[] AdaptiveSwimRho(double radius, double accuracy) {
677-
System.out.println("Don't use yet");
678-
if(this.SwimUnPhys) return null;
679-
680-
double[] value = new double[8];
681-
682-
radius = radius/100;
683-
try {
684-
AdaptiveSwimResult result = new AdaptiveSwimResult(false);
685-
686-
PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius,
687-
accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result);
688-
689-
if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) {
690-
value[0] = result.getUf()[0] * 100; // convert back to cm
691-
value[1] = result.getUf()[1] * 100; // convert back to cm
692-
value[2] = result.getUf()[2] * 100; // convert back to cm
693-
value[3] = result.getUf()[3] * _pTot; // normalized values
694-
value[4] = result.getUf()[4] * _pTot;
695-
value[5] = result.getUf()[5] * _pTot;
696-
value[6] = result.getFinalS() * 100;
697-
value[7] = 0; // Conversion from kG.m to T.cm
698-
}
699-
else {
700-
return null;
701-
}
702-
} catch (AdaptiveSwimException e) {
703-
e.printStackTrace();
704-
}
705-
return value;
706-
}
707591
}

0 commit comments

Comments
 (0)