From 511eac536fdf0478afba4809d9d26476c4ed9f17 Mon Sep 17 00:00:00 2001 From: veronique Date: Mon, 12 Jan 2026 18:22:16 -0500 Subject: [PATCH 1/2] swimtools cleanup --- .../jlab/clas/decay/analysis/Particle.java | 2 +- .../java/org/jlab/clas/swimtools/ASwim.java | 28 +- .../org/jlab/clas/swimtools/AdaptiveSwim.java | 4 - .../java/org/jlab/clas/swimtools/ISwim.java | 10 +- .../java/org/jlab/clas/swimtools/Swim.java | 743 +++++++----------- .../rec/dc/track/TrackCandListFinder.java | 4 +- .../jlab/rec/dc/trajectory/Trajectory.java | 8 +- .../java/org/jlab/rec/fmt/track/Track.java | 2 +- 8 files changed, 300 insertions(+), 501 deletions(-) diff --git a/common-tools/clas-decay-tools/src/main/java/org/jlab/clas/decay/analysis/Particle.java b/common-tools/clas-decay-tools/src/main/java/org/jlab/clas/decay/analysis/Particle.java index cbea622750..219288a909 100644 --- a/common-tools/clas-decay-tools/src/main/java/org/jlab/clas/decay/analysis/Particle.java +++ b/common-tools/clas-decay-tools/src/main/java/org/jlab/clas/decay/analysis/Particle.java @@ -997,7 +997,7 @@ private double calcUncorrMass(Particle part1, Particle part2) { //momentum not c } else { swim.SetSwimParameters(vxch, vych, vzch, -pxch, -pych, -pzch, -q); - double[] tr1 = swim.SwimToPlaneBoundary((vzvo-buffer),new Vector3D(0,0,1), -1); + double[] tr1 = swim.SwimToPlaneBoundary((vzvo-buffer),new Vector3D(0,0,1)); swim.SetSwimParameters(tr1[0], tr1[1], tr1[2], -tr1[3], -tr1[4], -tr1[5], q); } diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java index 49c96bcbfd..b289a088c5 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java @@ -11,18 +11,17 @@ public abstract class ASwim extends SwimPars implements ISwim { @Override - public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { - throw new UnsupportedOperationException("Not supported yet."); + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n) { + // Normalize the normal - should already be done, but just in case + Vector3D nhat = n.asUnit(); + + // Point on the plane at distance d_cm from origin + Point3D p = new Point3D( + nhat.x() * d_cm, + nhat.y() * d_cm, + nhat.z() * d_cm + ); + return SwimPlane(nhat, p, accuracy); } @Override @@ -34,6 +33,11 @@ public double[] SwimToPlaneLab(double z_cm) { public double[] SwimToCylinder(double radius) { return SwimGenCylinder(new Point3D(0,0,-1), new Point3D(0,0,1), radius, accuracy); } + + @Override + public double[] SwimRho(double radius, double accuracy) { + return SwimGenCylinder(new Point3D(0,0,-1), new Point3D(0,0,1), radius, accuracy); + } @Override public double[] SwimToZ(double Z, int dir) { diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java index 073a88891e..835824b48c 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java @@ -135,9 +135,5 @@ public double[] SwimToLine(Line3D l) { return null; } - @Override - public double[] SwimToDCA(SwimTrajectory trk2) { - throw new UnsupportedOperationException("Not supported yet."); - } } diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java index 259329f29d..0c4b672a33 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java @@ -1,21 +1,15 @@ package org.jlab.clas.swimtools; -import cnuphys.swim.SwimTrajectory; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; /** - * FIXME: Can any of these be removed? * * @author baltzell */ interface ISwim { - public double[] SwimToPlaneTiltSecSys(int sector, double z_cm); - - public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm); - public double[] SwimToPlaneLab(double z_cm); public double[] SwimToCylinder(double Rad); @@ -28,7 +22,7 @@ interface ISwim { public double[] SwimToSphere(double Rad); - public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir); + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n); public double[] SwimToBeamLine(double xB, double yB); @@ -36,6 +30,4 @@ interface ISwim { public double[] SwimToZ(double Z, int dir); - public double[] SwimToDCA(SwimTrajectory trk2); - } diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java index cfe18bc05f..2483e717cb 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java @@ -14,6 +14,7 @@ import cnuphys.swimZ.SwimZStateVector; import cnuphys.adaptiveSwim.AdaptiveSwimResult; +import cnuphys.rk4.IStopper; import org.jlab.clas.swimtools.Stoppers.BeamLineSwimStopper; import org.jlab.clas.swimtools.Stoppers.CylindricalBoundarySwimStopper; @@ -29,543 +30,349 @@ */ public class Swim extends ASwim { - private SwimTrajectory swimTraj; - - /** - * @return the swimTraj - */ + private static final int STATE_SIZE = 8; + private static final double CM_PER_M = 100.0; + private static final double KGCM_TO_TCM = 0.1; // divide by 10 + + private SwimTrajectory swimTraj; + public SwimTrajectory getSwimTraj() { return swimTraj; } - /** - * @param swimTraj the swimTraj to set - */ public void setSwimTraj(SwimTrajectory swimTraj) { this.swimTraj = swimTraj; } - - /** - * - * @param sector - * @param z_cm - * @return - */ - @Override - public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { - // Fiducial Cut: - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; + // ------------------------------------------------------------------------ + // Common guards and helpers + // ------------------------------------------------------------------------ + + private boolean isInvalid() { + return SwimUnPhys || _pTot < MINTRKMOM; + } - double[] value = new double[8]; - double hdata[] = new double[3]; + private double[] newState() { + return new double[STATE_SIZE]; + } + + private void fillFromTrajectory(double[] out, SwimTrajectory traj) { + double[] y = traj.lastElement(); + out[0] = y[0] * CM_PER_M; + out[1] = y[1] * CM_PER_M; + out[2] = y[2] * CM_PER_M; + out[3] = y[3] * _pTot; + out[4] = y[4] * _pTot; + out[5] = y[5] * _pTot; + out[6] = y[6] * CM_PER_M; + out[7] = y[7] * 10.0; // kG·m → T·cm + } + + private void fillFromZResult(double[] out, SwimZResult szr, double bdlKgCm) { + SwimZStateVector last = szr.last(); + double[] p3 = szr.getThreeMomentum(last); + out[0] = last.x; + out[1] = last.y; + out[2] = last.z; + out[3] = p3[0]; + out[4] = p3[1]; + out[5] = p3[2]; + out[6] = szr.getPathLength(); + out[7] = bdlKgCm * KGCM_TO_TCM; + } + private SwimZResult tryZSwimSector(int sector, double z_cm, double[] hdata) { + if (_pTot <= SWIMZMINMOM) return null; try { + double stepSizeCM = stepSize * CM_PER_M; + SwimZStateVector start = new SwimZStateVector( + _x0 * CM_PER_M, _y0 * CM_PER_M, _z0 * CM_PER_M, + _pTot, _theta, _phi); + return PC.RCF_z.sectorAdaptiveRK(sector, _charge, _pTot, start, z_cm, stepSizeCM, hdata); + } catch (SwimZException e) { + return null; + } + } - // Try to use new Z-Swimmer: - SwimZResult szr = null; - if (_pTot > SWIMZMINMOM) { - double stepSizeCM = stepSize * 100; // convert to cm - SwimZStateVector start = new SwimZStateVector(_x0 * 100, _y0 * 100, _z0 * 100, _pTot, _theta, _phi); - try { - szr = PC.RCF_z.sectorAdaptiveRK(sector, _charge, _pTot, start, z_cm, stepSizeCM, hdata); - } catch (SwimZException e) { - szr = null; - } - } - if (szr != null) { - double bdl = szr.sectorGetBDL(sector, PC.RCF_z.getProbe()); - double pathLength = szr.getPathLength(); // already in cm - SwimZStateVector last = szr.last(); - double p3[] = szr.getThreeMomentum(last); - value[0] = last.x; // cm - value[1] = last.y; // cm - value[2] = last.z; // cm - value[3] = p3[0]; - value[4] = p3[1]; - value[5] = p3[2]; - value[6] = pathLength; - value[7] = bdl / 10; // convert from kg*cm to T*cm - } - - // Use older swimmer: - else { - final double z = z_cm / 100; // convert to meters - SwimTrajectory traj = PC.RCF.sectorSwim(sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, - _maxPathLength, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); - if(traj==null) return null; - traj.sectorComputeBDL(sector, PC.RCP); - double lastY[] = traj.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; - } - } catch (Exception e) { - e.printStackTrace(); + private SwimZResult tryZSwimLab(double z_cm, double[] hdata) { + if (_pTot <= SWIMZMINMOM) return null; + try { + double stepSizeCM = stepSize * CM_PER_M; + SwimZStateVector start = new SwimZStateVector( + _x0 * CM_PER_M, _y0 * CM_PER_M, _z0 * CM_PER_M, + _pTot, _theta, _phi); + return PC.CF_z.adaptiveRK(_charge, _pTot, start, z_cm, stepSizeCM, hdata); + } catch (SwimZException e) { + return null; } - return value; + } + // ------------------------------------------------------------------------ + // Plane / Z swimmers + // ------------------------------------------------------------------------ + + public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { + if (isInvalid()) return null; + + double[] hdata = new double[3]; + double[] out = newState(); + + SwimZResult szr = tryZSwimSector(sector, z_cm, hdata); + if (szr != null) { + double bdl = szr.sectorGetBDL(sector, PC.RCF_z.getProbe()); + fillFromZResult(out, szr, bdl); + return out; + } + + try { + double z_m = z_cm / CM_PER_M; + SwimTrajectory traj = PC.RCF.sectorSwim( + sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + z_m, accuracy, _rMax, _maxPathLength, stepSize, + cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); + if (traj == null) return null; + traj.sectorComputeBDL(sector, PC.RCP); + fillFromTrajectory(out, traj); + return out; + } catch (RungeKuttaException e) { + return null; + } } - /** - * - * @param sector - * @param z_cm - * @return - */ - @Override public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { + if (isInvalid()) return null; - // Fiducial Cut: - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; + double[] hdata = new double[3]; + double[] out = newState(); - double hdata[] = new double[3]; - double[] value = new double[8]; + SwimZResult szr = tryZSwimSector(sector, z_cm, hdata); + if (szr != null) { + double bdl = szr.sectorGetBDLXZPlane(sector, PC.RCF_z.getProbe()); + fillFromZResult(out, szr, bdl); + return out; + } try { - - // Try to use new Z-Swimmer: - SwimZResult szr = null; - if (_pTot > SWIMZMINMOM) { - double stepSizeCM = stepSize * 100; // convert to cm - SwimZStateVector start = new SwimZStateVector(_x0 * 100, _y0 * 100, _z0 * 100, _pTot, _theta, _phi); - try { - szr = PC.RCF_z.sectorAdaptiveRK(sector, _charge, _pTot, start, z_cm, stepSizeCM, hdata); - } catch (SwimZException e) { - szr = null; - } - } - if (szr != null) { - double bdl = szr.sectorGetBDLXZPlane(sector, PC.RCF_z.getProbe()); - double pathLength = szr.getPathLength(); // already in cm - SwimZStateVector last = szr.last(); - double p3[] = szr.getThreeMomentum(last); - value[0] = last.x; // xf in cm - value[1] = last.y; // yz in cm - value[2] = last.z; // zf in cm - value[3] = p3[0]; - value[4] = p3[1]; - value[5] = p3[2]; - value[6] = pathLength; - value[7] = bdl / 10; // convert from kg*cm to T*cm - } - - // Use older swimmer: - else { - double z = z_cm / 100; // convert to meters - SwimTrajectory traj = PC.RCF.sectorSwim(sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, - _maxPathLength, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); - if (traj==null) return null; - traj.sectorComputeBDL(sector, PC.RCP); - double lastY[] = traj.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; - } - } catch (Exception e) { - e.printStackTrace(); + double z_m = z_cm / CM_PER_M; + SwimTrajectory traj = PC.RCF.sectorSwim( + sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + z_m, accuracy, _rMax, _maxPathLength, stepSize, + cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); + if (traj == null) return null; + traj.sectorComputeBDL(sector, PC.RCP); + fillFromTrajectory(out, traj); + return out; + } catch (RungeKuttaException e) { + return null; } - return value; } - - /** - * - * @param z_cm - * @return state x,y,z,px,py,pz, pathlength, iBdl at the plane surface - */ + @Override public double[] SwimToPlaneLab(double z_cm) { + if (isInvalid()) return null; - // Fiducial Cut: - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; + double[] hdata = new double[3]; + double[] out = newState(); - double hdata[] = new double[3]; - double[] value = new double[8]; - - try { - - // Try to use new Z-Swimmer: - SwimZResult szr = null; - if (_pTot > SWIMZMINMOM) { - double stepSizeCM = stepSize * 100; // convert to cm - SwimZStateVector start = new SwimZStateVector(_x0 * 100, _y0 * 100, _z0 * 100, _pTot, _theta, _phi); - try { - szr = PC.CF_z.adaptiveRK(_charge, _pTot, start, z_cm, stepSizeCM, hdata); - } catch (SwimZException e) { - szr = null; - } - } - if (szr != null) { - double bdl = szr.getBDL(PC.CF_z.getProbe()); - double pathLength = szr.getPathLength(); // already in cm - SwimZStateVector last = szr.last(); - double p3[] = szr.getThreeMomentum(last); - value[0] = last.x; // xf in cm - value[1] = last.y; // yz in cm - value[2] = last.z; // zf in cm - value[3] = p3[0]; - value[4] = p3[1]; - value[5] = p3[2]; - value[6] = pathLength; - value[7] = bdl / 10; // convert from kg*cm to T*cm - } - - // Use older swimmer: - else { - double z = z_cm / 100; // the magfield method uses meters - SwimTrajectory traj = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, _maxPathLength, - stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); - if (traj==null) return null; - traj.computeBDL(PC.CP); - double lastY[] = traj.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; - } // old swimmer + SwimZResult szr = tryZSwimLab(z_cm, hdata); + if (szr != null) { + double bdl = szr.getBDL(PC.CF_z.getProbe()); + fillFromZResult(out, szr, bdl); + return out; + } + try { + double z_m = z_cm / CM_PER_M; + SwimTrajectory traj = PC.CF.swim( + _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + z_m, accuracy, _rMax, _maxPathLength, stepSize, + cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); + if (traj == null) return null; + traj.computeBDL(PC.CP); + fillFromTrajectory(out, traj); + return out; } catch (RungeKuttaException e) { - e.printStackTrace(); + return null; } - return value; } - /** - * - * @param Rad - * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface - */ - public double[] SwimToCylinder(double Rad) { - - if (this.SwimUnPhys) return null; - double[] value = new double[8]; - - CylindricalBoundarySwimStopper stopper = new CylindricalBoundarySwimStopper(Rad); - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, 0.0005); - if (st==null) return null; - st.computeBDL(PC.CP); - - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; + // ------------------------------------------------------------------------ + // Geometry-based stoppers + // ------------------------------------------------------------------------ + + @Override + public double[] SwimToCylinder(double radius) { + if (SwimUnPhys) return null; + return swimWithStopper(new CylindricalBoundarySwimStopper(radius)); } - /** - * - * @param radius in cm - * @param accuracy in cm - * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface - */ @Override - public double[] SwimRho(double radius, double accuracy) { + public double[] SwimToSphere(double radius) { + if (SwimUnPhys) return null; + return swimWithStopper(new SphericalBoundarySwimStopper(radius)); + } - if(this.SwimUnPhys) return null; - double[] value = null; + @Override + public double[] SwimToBeamLine(double xB, double yB) { + if (SwimUnPhys) return null; + return swimWithStopper(new BeamLineSwimStopper(xB, yB)); + } + + @Override + public double[] SwimToLine(Line3D l) { + if (SwimUnPhys) return null; + return swimWithStopper(new LineSwimStopper(l)); + } + private double[] swimWithStopper(IStopper stopper) { try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - radius/100, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - - if(result.getStatus()==0) { - value = new double[8]; - value[0] = result.getUf()[0] * 100; // convert back to cm - value[1] = result.getUf()[1] * 100; // convert back to cm - value[2] = result.getUf()[2] * 100; // convert back to cm - value[3] = result.getUf()[3] * _pTot; // normalized values - value[4] = result.getUf()[4] * _pTot; - value[5] = result.getUf()[5] * _pTot; - value[6] = result.getFinalS() * 100; - value[7] = 0; // Conversion from kG.m to T.cm - } - } catch (RungeKuttaException e) { - System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); + SwimTrajectory traj = PC.CF.swim( + _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + stopper, _maxPathLength, stepSize, 0.0005); + if (traj == null) return null; + traj.computeBDL(PC.CP); + double[] out = newState(); + fillFromTrajectory(out, traj); + return out; + } catch (Exception e) { e.printStackTrace(); + return null; } - return value; } - - /** - * - * @param axisPoint1 in cm - * @param axisPoint2 in cm - * @param radius in cm - * @param accuracy in cm - * @return swam trajectory to the cylinder - */ + + // ------------------------------------------------------------------------ + // Adaptive swimmers + // ------------------------------------------------------------------------ + @Override - public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { - - if(this.SwimUnPhys) return null; - - double[] value = null; - double[] p1 = new double[3]; - double[] p2 = new double[3]; - p1[0] = axisPoint1.x()/100; - p1[1] = axisPoint1.y()/100; - p1[2] = axisPoint1.z()/100; - p2[0] = axisPoint2.x()/100; - p2[1] = axisPoint2.y()/100; - p2[2] = axisPoint2.z()/100; - + public double[] SwimRho(double radius, double accuracy) { + if (SwimUnPhys) return null; try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.CF.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - p1, p2, radius/100, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - - if(result.getStatus()==0) { - value = new double[8]; - value[0] = result.getUf()[0] * 100; // convert back to cm - value[1] = result.getUf()[1] * 100; // convert back to cm - value[2] = result.getUf()[2] * 100; // convert back to cm - value[3] = result.getUf()[3] * _pTot; // normalized values - value[4] = result.getUf()[4] * _pTot; - value[5] = result.getUf()[5] * _pTot; - value[6] = result.getFinalS() * 100; - value[7] = 0; // Conversion from kG.m to T.cm - } + AdaptiveSwimResult r = new AdaptiveSwimResult(false); + PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, + radius / CM_PER_M, accuracy / CM_PER_M, + _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, r); + return r.getStatus() == 0 ? adaptiveOut(r) : null; } catch (RungeKuttaException e) { - System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); e.printStackTrace(); + return null; } - return value; - } - /** - * - * @param n - * @param p - * @param accuracy - * @return - */ @Override - public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { - - if (this.SwimUnPhys) return null; - - double[] value = null; - + public double[] SwimGenCylinder(Point3D a1, Point3D a2, double radius, double accuracy) { + if (SwimUnPhys) return null; try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.CF.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - n.x(),n.y(),n.z(),p.x()/100,p.y()/100,p.z()/100, - accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - - if(result.getStatus()==0) { - value = new double[8]; - value[0] = result.getUf()[0] * 100; // convert back to cm - value[1] = result.getUf()[1] * 100; // convert back to cm - value[2] = result.getUf()[2] * 100; // convert back to cm - value[3] = result.getUf()[3] * _pTot; // normalized values - value[4] = result.getUf()[4] * _pTot; - value[5] = result.getUf()[5] * _pTot; - value[6] = result.getFinalS() * 100; - value[7] = 0; // Conversion from kG.m to T.cm - } + AdaptiveSwimResult r = new AdaptiveSwimResult(false); + double[] p1 = {a1.x() / CM_PER_M, a1.y() / CM_PER_M, a1.z() / CM_PER_M}; + double[] p2 = {a2.x() / CM_PER_M, a2.y() / CM_PER_M, a2.z() / CM_PER_M}; + PC.CF.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, + p1, p2, radius / CM_PER_M, accuracy / CM_PER_M, + _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, r); + return r.getStatus() == 0 ? adaptiveOut(r) : null; } catch (RungeKuttaException e) { - System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); e.printStackTrace(); + return null; } - return value; - } - - /** - * - * @param Rad - * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface - */ - @Override - public double[] SwimToSphere(double Rad) { - - if (this.SwimUnPhys==true) return null; - double[] value = new double[8]; - - SphericalBoundarySwimStopper stopper = new SphericalBoundarySwimStopper(Rad); - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, 0.0005); - if (st==null) return null; - st.computeBDL(PC.CP); - - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; } - /** - * - * @param d_cm - * @param n - * @param dir - * @return return state x,y,z,px,py,pz, pathlength, iBdl at the plane surface in the lab frame - */ @Override - public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { - - if (this.SwimUnPhys) return null; - - double[] value = new double[8]; - double hdata[] = new double[3]; - double d = d_cm / 100; // convert to meters - - Plane plane = new Plane(n.x(), n.y(), n.z(), d); + public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { + if (SwimUnPhys) return null; try { - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - plane, accuracy, _maxPathLength, stepSize, - cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); - - st.computeBDL(PC.CP); - - double[] lastY = st.lastElement(); - - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - + AdaptiveSwimResult r = new AdaptiveSwimResult(false); + PC.CF.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, + n.x(), n.y(), n.z(), + p.x() / CM_PER_M, p.y() / CM_PER_M, p.z() / CM_PER_M, + accuracy / CM_PER_M, _rMax, stepSize, + cnuphys.swim.Swimmer.CLAS_Tolerance, r); + return r.getStatus() == 0 ? adaptiveOut(r) : null; } catch (RungeKuttaException e) { e.printStackTrace(); + return null; } - return value; } - @Override - public double[] SwimToBeamLine(double xB, double yB) { - - if(this.SwimUnPhys==true) return null; - - double[] value = new double[8]; - - BeamLineSwimStopper stopper = new BeamLineSwimStopper(xB, yB); - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, 0.0005); - if (st==null) return null; - st.computeBDL(PC.CP); - - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; + private double[] adaptiveOut(AdaptiveSwimResult r) { + double[] out = newState(); + out[0] = r.getUf()[0] * CM_PER_M; + out[1] = r.getUf()[1] * CM_PER_M; + out[2] = r.getUf()[2] * CM_PER_M; + out[3] = r.getUf()[3] * _pTot; + out[4] = r.getUf()[4] * _pTot; + out[5] = r.getUf()[5] * _pTot; + out[6] = r.getFinalS() * CM_PER_M; + out[7] = 0.0; + return out; } - + + // ------------------------------------------------------------------------ + // Swim to boundaries in the lab + // ------------------------------------------------------------------------ + @Override - public double[] SwimToLine(Line3D l) { - - if (this.SwimUnPhys==true) return null; - - double[] value = new double[8]; - - LineSwimStopper stopper = new LineSwimStopper(l); - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, 0.0005); - if (st==null) return null; - st.computeBDL(PC.CP); - - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n) { + if (SwimUnPhys) return null; + try { + Plane plane = new Plane(n.x(), n.y(), n.z(), d_cm / CM_PER_M); + SwimTrajectory traj = PC.CF.swim( + _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + plane, accuracy, _maxPathLength, stepSize, + cnuphys.swim.Swimmer.CLAS_Tolerance, new double[3]); + if (traj == null) return null; + traj.computeBDL(PC.CP); + double[] out = newState(); + fillFromTrajectory(out, traj); + return out; + } catch (RungeKuttaException e) { + e.printStackTrace(); + return null; + } } - /** - * - * @param Z - * @param dir - * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface - */ @Override public double[] SwimToZ(double Z, int dir) { - double[] value = new double[8]; + if (SwimUnPhys) return null; ZSwimStopper stopper = new ZSwimStopper(Z, dir); - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, distanceBetweenSaves); - if (st==null) return null; - st.computeBDL(PC.CP); - this.setSwimTraj(st); - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - value[6] = lastY[6] * 100; - value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; + try { + SwimTrajectory traj = PC.CF.swim( + _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + stopper, _maxPathLength, stepSize, distanceBetweenSaves); + if (traj == null) return null; + traj.computeBDL(PC.CP); + setSwimTraj(traj); + double[] out = newState(); + fillFromTrajectory(out, traj); + return out; + } catch (Exception e) { + e.printStackTrace(); + return null; + } } - @Override - public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track - - double[] value = new double[6]; - - DCASwimStopper stopper = new DCASwimStopper(trk2); - - SwimTrajectory st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - stopper, _maxPathLength, stepSize, 0.0005); - if (st==null) return null; - - double[] lastY = st.lastElement(); - value[0] = lastY[0] * 100; // convert back to cm - value[1] = lastY[1] * 100; // convert back to cm - value[2] = lastY[2] * 100; // convert back to cm - value[3] = lastY[3] * _pTot; // normalized values - value[4] = lastY[4] * _pTot; - value[5] = lastY[5] * _pTot; - return value; - } + // ------------------------------------------------------------------------ + // Swim to track trajectory - used for detached vertexing + // ------------------------------------------------------------------------ -} \ No newline at end of file + public double[] SwimToDCA(SwimTrajectory trk2) { + if (SwimUnPhys) return null; + try { + SwimTrajectory traj = PC.CF.swim( + _charge, _x0, _y0, _z0, _pTot, _theta, _phi, + new DCASwimStopper(trk2), _maxPathLength, stepSize, 0.0005); + if (traj == null) return null; + double[] y = traj.lastElement(); + return new double[]{ + y[0] * CM_PER_M, + y[1] * CM_PER_M, + y[2] * CM_PER_M, + y[3] * _pTot, + y[4] * _pTot, + y[5] * _pTot + }; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java b/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java index 6f68d554ab..88c4e488b5 100644 --- a/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java +++ b/reconstruction/dc/src/main/java/org/jlab/rec/dc/track/TrackCandListFinder.java @@ -526,7 +526,7 @@ public void setTrackPars(Track cand, double theta_n = ((double) (sector - 1)) * Math.toRadians(60.); double x_n = Math.cos(theta_n); double y_n = Math.sin(theta_n); - double[] Vt = dcSwim.SwimToPlaneBoundary(0, new Vector3D(x_n, y_n, 0), -1); + double[] Vt = dcSwim.SwimToPlaneBoundary(0, new Vector3D(x_n, y_n, 0)); if (Vt == null) { return; @@ -672,7 +672,7 @@ public void setTrackPars(Track cand, //double x_n = Math.cos(theta_n); //double y_n = Math.sin(theta_n); //double d = x_n*xB + y_n*yB; - //Vt = dcSwim.SwimToPlaneBoundary(d, new Vector3D(x_n, y_n, 0), -1); + //Vt = dcSwim.SwimToPlaneBoundary(d, new Vector3D(x_n, y_n, 0)); //if(Vt==null) // return; double xOrFix = Vt[0]; diff --git a/reconstruction/dc/src/main/java/org/jlab/rec/dc/trajectory/Trajectory.java b/reconstruction/dc/src/main/java/org/jlab/rec/dc/trajectory/Trajectory.java index ddb69ebf94..b56c2671f2 100644 --- a/reconstruction/dc/src/main/java/org/jlab/rec/dc/trajectory/Trajectory.java +++ b/reconstruction/dc/src/main/java/org/jlab/rec/dc/trajectory/Trajectory.java @@ -218,19 +218,19 @@ public void calcTrajectory(int trackId, Swim dcSwim, Point3D v, Vector3D p, int // swim backward from HTCC to Target if(surface.getDetectorType() == DetectorType.TARGET) { - int dir = -1; + //int dir = -1; float b[] = new float[3]; dcSwim.BfieldLab(v.x(), v.y(), v.z(), b); dcSwim.SetSwimParameters(last.getPoint().x(), last.getPoint().y(), last.getPoint().z(), -last.getMomentum().x(), -last.getMomentum().y(), -last.getMomentum().z(), -q); - double[] tPars = dcSwim.SwimToPlaneBoundary(surface.getD(), surface.getNormal(), dir); + double[] tPars = dcSwim.SwimToPlaneBoundary(surface.getD(), surface.getNormal()); if(tPars==null || surface.distanceFromPlane(tPars[0], tPars[1], tPars[2])>TOLERANCE) return; this.addTrajectoryPoint(tPars[0], tPars[1], tPars[2], -tPars[3], -tPars[4], -tPars[5], last.getPath()-tPars[6], last.getiBdl()-tPars[7], surface); } // swim forward from vertex to FMT and from HTCC to FD planes else { - int dir = 1; + //int dir = 1; double path = 0; double bdl = 0; if(surface.getDetectorType() == DetectorType.FMT) { @@ -242,7 +242,7 @@ public void calcTrajectory(int trackId, Swim dcSwim, Point3D v, Vector3D p, int path = htccPars[6]; bdl = htccPars[7]; } - double[] tPars = dcSwim.SwimToPlaneBoundary(surface.getD(), surface.getNormal(), dir); + double[] tPars = dcSwim.SwimToPlaneBoundary(surface.getD(), surface.getNormal()); if(tPars==null) return; double MAXDIST = -99; if(surface.getDetectorType() == DetectorType.RICH) MAXDIST = -1; diff --git a/reconstruction/fmt/src/main/java/org/jlab/rec/fmt/track/Track.java b/reconstruction/fmt/src/main/java/org/jlab/rec/fmt/track/Track.java index 4b6bb58d2a..f6819ce356 100644 --- a/reconstruction/fmt/src/main/java/org/jlab/rec/fmt/track/Track.java +++ b/reconstruction/fmt/src/main/java/org/jlab/rec/fmt/track/Track.java @@ -444,7 +444,7 @@ private static double[] getTrajectory(double x, double y, double z, double px, d double d = p.dot(n); if(v.dot(n) Date: Fri, 16 Jan 2026 17:36:10 -0500 Subject: [PATCH 2/2] remove swimRho from interface. --- .../src/main/java/org/jlab/clas/swimtools/ASwim.java | 8 ++++---- .../main/java/org/jlab/clas/swimtools/AdaptiveSwim.java | 2 -- .../src/main/java/org/jlab/clas/swimtools/ISwim.java | 2 +- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java index b289a088c5..75dff76274 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java @@ -29,10 +29,10 @@ public double[] SwimToPlaneLab(double z_cm) { return SwimPlane(new Vector3D(0,0,1), new Point3D(0,0,z_cm), accuracy); } - @Override - public double[] SwimToCylinder(double radius) { - return SwimGenCylinder(new Point3D(0,0,-1), new Point3D(0,0,1), radius, accuracy); - } + //@Override + //public double[] SwimToCylinder(double radius) { + // return SwimGenCylinder(new Point3D(0,0,-1), new Point3D(0,0,1), radius, accuracy); + //} @Override public double[] SwimRho(double radius, double accuracy) { diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java index 835824b48c..d28ff1487e 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java @@ -15,8 +15,6 @@ import cnuphys.adaptiveSwim.AdaptiveSwimmer; import cnuphys.adaptiveSwim.geometry.Plane; -import cnuphys.swim.SwimTrajectory; - public class AdaptiveSwim extends ASwim { private static double[] convert(AdaptiveSwimResult result, double p) { diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java index 0c4b672a33..5fd721d968 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java @@ -12,7 +12,7 @@ interface ISwim { public double[] SwimToPlaneLab(double z_cm); - public double[] SwimToCylinder(double Rad); + //public double[] SwimToCylinder(double Rad); public double[] SwimRho(double radius, double accuracy); diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java index 2483e717cb..2dcd98ef5e 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java @@ -200,7 +200,7 @@ public double[] SwimToPlaneLab(double z_cm) { // Geometry-based stoppers // ------------------------------------------------------------------------ - @Override +// @Override public double[] SwimToCylinder(double radius) { if (SwimUnPhys) return null; return swimWithStopper(new CylindricalBoundarySwimStopper(radius));