From ab125838bdab83fee7431e2eb6b7a9591b2c7a77 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 22 Dec 2025 14:26:40 -0500 Subject: [PATCH 01/24] cleanup --- .../jlab/clas/swimtools/MagFieldsEngine.java | 72 ++++++++----------- .../jlab/clas/swimtools/ProbeCollection.java | 5 -- .../java/org/jlab/clas/swimtools/Swim.java | 5 -- .../java/org/jlab/clas/swimtools/Swimmer.java | 1 - 4 files changed, 31 insertions(+), 52 deletions(-) diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/MagFieldsEngine.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/MagFieldsEngine.java index ceab50389a..b02d767101 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/MagFieldsEngine.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/MagFieldsEngine.java @@ -1,8 +1,9 @@ package org.jlab.clas.swimtools; +import cnuphys.magfield.MagneticFieldInitializationException; import cnuphys.magfield.MagneticFields; +import java.io.FileNotFoundException; import java.util.Arrays; -import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -14,7 +15,7 @@ public class MagFieldsEngine extends ReconstructionEngine { - public static Logger LOGGER = Logger.getLogger(MagFieldsEngine.class.getName()); + public static final Logger LOGGER = Logger.getLogger(MagFieldsEngine.class.getName()); private String solShift = null; @@ -22,8 +23,6 @@ public MagFieldsEngine() { super("MagFields", "ziegler", "1.0"); } - AtomicInteger Run = new AtomicInteger(0); - /** * Choose one of YAML or ENV values. * @@ -57,19 +56,19 @@ public boolean initializeMagneticFields() { final String mapDir = CLASResources.getResourcePath("etc")+"/data/magfield"; if (torusMap==null) { - LOGGER.log(Level.SEVERE,"["+this.getName()+"] ERROR: torus field is undefined."); + LOGGER.log(Level.SEVERE, "[{0}] ERROR: torus field is undefined.", this.getName()); return false; } if (solenoidMap==null) { - LOGGER.log(Level.SEVERE,"["+this.getName()+"] ERROR: solenoid is undefined."); + LOGGER.log(Level.SEVERE, "[{0}] ERROR: solenoid is undefined.", this.getName()); return false; } try { MagneticFields.getInstance().initializeMagneticFields(mapDir, torusMap, solenoidMap); } - catch (Exception e) { - e.printStackTrace(); + catch (MagneticFieldInitializationException | FileNotFoundException e) { + LOGGER.log(Level.SEVERE,"Magfields error",e); return false; } @@ -77,77 +76,67 @@ public boolean initializeMagneticFields() { solShift = this.getEngineConfigString("magfieldSolenoidShift"); if (solShift != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with solenoid z shift in tracking config chosen based on yaml = " + solShift + " cm"); - Swimmer.set_zShift(Float.valueOf(solShift)); + LOGGER.log(Level.INFO, "[{0}] run with solenoid z shift in tracking config chosen based on yaml = {1} cm", new Object[]{this.getName(), solShift}); + Swimmer.set_zShift(Float.parseFloat(solShift)); } else { solShift = System.getenv("COAT_MAGFIELD_SOLENOIDSHIFT"); if (solShift != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with solenoid z shift in tracking config chosen based on env = " + solShift + " cm"); - Swimmer.set_zShift(Float.valueOf(solShift)); + LOGGER.log(Level.INFO, "[{0}] run with solenoid z shift in tracking config chosen based on env = {1} cm", new Object[]{this.getName(), solShift}); + Swimmer.set_zShift(Float.parseFloat(solShift)); } } if (solShift == null) { - LOGGER.log(Level.INFO, "[" + this.getName() + "] run with solenoid z shift based on CCDB CD position"); + LOGGER.log(Level.INFO, "[{0}] run with solenoid z shift based on CCDB CD position", this.getName()); // this.solenoidShift = (float) 0; } // torus: String TorX = this.getEngineConfigString("magfieldTorusXShift"); if (TorX != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus x shift in tracking config chosen based on yaml = " + TorX + " cm"); - Swimmer.setTorXShift(Float.valueOf(TorX)); + LOGGER.log(Level.INFO, "[{0}] run with torus x shift in tracking config chosen based on yaml = {1} cm", new Object[]{this.getName(), TorX}); + Swimmer.setTorXShift(Float.parseFloat(TorX)); } else { TorX = System.getenv("COAT_MAGFIELD_TORUSXSHIFT"); if (TorX != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus x shift in tracking config chosen based on env = " + TorX + " cm"); - Swimmer.setTorXShift(Float.valueOf(TorX)); + LOGGER.log(Level.INFO, "[{0}] run with torus x shift in tracking config chosen based on env = {1} cm", new Object[]{this.getName(), TorX}); + Swimmer.setTorXShift(Float.parseFloat(TorX)); } } if (TorX == null) { - LOGGER.log(Level.INFO, "[" + this.getName() + "] run with torus x shift in tracking set to 0 cm"); + LOGGER.log(Level.INFO, "[{0}] run with torus x shift in tracking set to 0 cm", this.getName()); // this.solenoidShift = (float) 0; } String TorY = this.getEngineConfigString("magfieldTorusYShift"); if (TorY != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus y shift in tracking config chosen based on yaml = " + TorY + " cm"); - Swimmer.setTorYShift(Float.valueOf(TorY)); + LOGGER.log(Level.INFO, "[{0}] run with torus y shift in tracking config chosen based on yaml = {1} cm", new Object[]{this.getName(), TorY}); + Swimmer.setTorYShift(Float.parseFloat(TorY)); } else { TorY = System.getenv("COAT_MAGFIELD_TORUSYSHIFT"); if (TorY != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus y shift in tracking config chosen based on env = " + TorY + " cm"); - Swimmer.setTorYShift(Float.valueOf(TorY)); + LOGGER.log(Level.INFO, "[{0}] run with torus y shift in tracking config chosen based on env = {1} cm", new Object[]{this.getName(), TorY}); + Swimmer.setTorYShift(Float.parseFloat(TorY)); } } if (TorY == null) { - LOGGER.log(Level.INFO, "[" + this.getName() + "] run with torus y shift in tracking set to 0 cm"); - // this.solenoidShift = (float) 0; + LOGGER.log(Level.INFO, "[{0}] run with torus y shift in tracking set to 0 cm", this.getName()); } String TorZ = this.getEngineConfigString("magfieldTorusZShift"); if (TorZ != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus z shift in tracking config chosen based on yaml = " + TorZ + " cm"); - Swimmer.setTorZShift(Float.valueOf(TorZ)); + LOGGER.log(Level.INFO, "[{0}] run with torus z shift in tracking config chosen based on yaml = {1} cm", new Object[]{this.getName(), TorZ}); + Swimmer.setTorZShift(Float.parseFloat(TorZ)); } else { TorZ = System.getenv("COAT_MAGFIELD_TORUSZSHIFT"); if (TorZ != null) { - LOGGER.log(Level.INFO, "[" + this.getName() - + "] run with torus z shift in tracking config chosen based on env = " + TorZ + " cm"); - Swimmer.setTorZShift(Float.valueOf(TorZ)); + LOGGER.log(Level.INFO, "[{0}] run with torus z shift in tracking config chosen based on env = {1} cm", new Object[]{this.getName(), TorZ}); + Swimmer.setTorZShift(Float.parseFloat(TorZ)); } } if (TorZ == null) { - LOGGER.log(Level.INFO, "[" + this.getName() + "] run with torus z shift in tracking set to 0 cm"); - // this.solenoidShift = (float) 0; + LOGGER.log(Level.INFO, "[{0}] run with torus z shift in tracking set to 0 cm", this.getName()); } return true; @@ -170,9 +159,10 @@ public boolean processDataEvent(DataEvent event) { if (newRun == 0) return true; - if (solShift == null) { // if no shift is set in the yaml file or environment, read from CCDB - // will read target position and assume that is representative of the shift of - // the whole CD + if (solShift == null) { + // if no shift is set in the yaml file or environment, read from CCDB + // will read target position and assume that is representative of the + // shift of the whole CD IndexedTable targetPosition = this.getConstantsManager().getConstants(newRun, "/geometry/shifts/solenoid"); Swimmer.set_zShift((float) targetPosition.getDoubleValue("z", 0, 0, 0)); } diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ProbeCollection.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ProbeCollection.java index 043ffec40e..f410927af6 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ProbeCollection.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ProbeCollection.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.clas.swimtools; import cnuphys.magfield.CompositeProbe; 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 66897dc346..487cc0455b 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 @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.clas.swimtools; import cnuphys.adaptiveSwim.AdaptiveSwimException; diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java index 7915ce6129..4874b3eab0 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java @@ -2,7 +2,6 @@ import cnuphys.magfield.MagneticFields; import java.util.HashMap; -import java.util.logging.Level; import java.util.logging.Logger; /** From 9a8074415c0d4e90ee8bfdb3dc219bab00f06bb4 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 13:02:10 -0500 Subject: [PATCH 02/24] cleanup --- .../java/org/jlab/clas/swimtools/Swim.java | 618 ++++++------------ .../java/org/jlab/clas/swimtools/Swimmer.java | 3 +- 2 files changed, 210 insertions(+), 411 deletions(-) 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 487cc0455b..fe4df35d45 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 @@ -13,34 +13,32 @@ import org.jlab.geom.prim.Point3D; import cnuphys.adaptiveSwim.AdaptiveSwimResult; import cnuphys.adaptiveSwim.AdaptiveSwimmer; -import cnuphys.adaptiveSwim.geometry.Cylinder; import cnuphys.adaptiveSwim.geometry.Line; import cnuphys.adaptiveSwim.geometry.Point; import cnuphys.adaptiveSwim.geometry.Vector; import java.util.ArrayList; import java.util.List; import org.jlab.geom.prim.Line3D; + /** * * @author ziegler */ - public class Swim { + final double SWIMZMINMOM = 0.75; // GeV/c + final double MINTRKMOM = 0.05; // GeV/c + private double _x0; private double _y0; private double _z0; private double _phi; private double _theta; private double _pTot; - private final double _rMax = 5 + 3; // increase to allow swimming to outer - // detectors + private final double _rMax = 5 + 3; private double _maxPathLength = 9; private boolean SwimUnPhys = false; //Flag to indicate if track is swimmable private int _charge; - - final double SWIMZMINMOM = 0.75; // GeV/c - final double MINTRKMOM = 0.05; // GeV/c double accuracy = 20e-6; // 20 microns public double stepSize = 5.00 * 1.e-4; // 500 microns public double distanceBetweenSaves= 100*stepSize; @@ -61,7 +59,7 @@ public Swim() { /** * Set max swimming path length * - * @param maxPathLength + * @param _maxPathLength */ public void setMaxPathLength(double _maxPathLength) { this._maxPathLength = _maxPathLength; @@ -69,21 +67,18 @@ public void setMaxPathLength(double _maxPathLength) { /** * - * @param direction - * +1 for out -1 for in - * @param x0 - * @param y0 - * @param z0 - * @param thx - * @param thy - * @param p + * @param direction +1 for out -1 for in + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) + * @param thx (units?) + * @param thy (units?) + * @param p (units?) * @param charge */ - public void SetSwimParameters(int direction, double x0, double y0, double z0, double thx, double thy, double p, - int charge) { - - // x,y,z in m = swimmer units - _x0 = x0 / 100; + public void SetSwimParameters(int direction, double x0, double y0, double z0, + double thx, double thy, double p, int charge) { + _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; this.checkR(_x0, _y0, _z0); @@ -93,7 +88,6 @@ public void SetSwimParameters(int direction, double x0, double y0, double z0, do _phi = Math.toDegrees(FastMath.atan2(py, px)); _pTot = Math.sqrt(px * px + py * py + pz * pz); _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = direction * charge; } @@ -101,20 +95,21 @@ public void SetSwimParameters(int direction, double x0, double y0, double z0, do * Sets the parameters used by swimmer based on the input track state vector * parameters swimming outwards * + * // z at a given DC plane in the tilted coordinate system + * * @param superlayerIdx * @param layerIdx - * @param x0 - * @param y0 + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) * @param thx * @param thy * @param p * @param charge */ - public void SetSwimParameters(int superlayerIdx, int layerIdx, double x0, double y0, double z0, double thx, - double thy, double p, int charge) { - // z at a given DC plane in the tilted coordinate system - // x,y,z in m = swimmer units - _x0 = x0 / 100; + public void SetSwimParameters(int superlayerIdx, int layerIdx, + double x0, double y0, double z0, double thx, double thy, double p, int charge) { + _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; this.checkR(_x0, _y0, _z0); @@ -124,33 +119,29 @@ public void SetSwimParameters(int superlayerIdx, int layerIdx, double x0, double _phi = Math.toDegrees(FastMath.atan2(py, px)); _pTot = Math.sqrt(px * px + py * py + pz * pz); _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = charge; - } /** * Sets the parameters used by swimmer based on the input track parameters * - * @param x0 - * @param y0 - * @param z0 + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) * @param px * @param py * @param pz * @param charge */ public void SetSwimParameters(double x0, double y0, double z0, double px, double py, double pz, int charge) { - _x0 = x0 / 100; + _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; this.checkR(_x0, _y0, _z0); _phi = Math.toDegrees(FastMath.atan2(py, px)); _pTot = Math.sqrt(px * px + py * py + pz * pz); _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = charge; - } /** @@ -166,7 +157,6 @@ public void SetSwimParameters(double x0, double y0, double z0, double px, double */ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, double thetaDeg, double p, int charge, double maxPathLength) { - _maxPathLength = maxPathLength; _charge = charge; _phi = phiDeg; @@ -193,7 +183,6 @@ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, */ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, double thetaDeg, double p, int charge, double maxPathLength, double Accuracy, double StepSize) { - _maxPathLength = maxPathLength; accuracy = Accuracy/100; stepSize = StepSize/100; @@ -207,70 +196,55 @@ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, this.checkR(_x0, _y0, _z0); } + /** + * + * @param sector + * @param z_cm + * @return + */ public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { - double z = z_cm / 100; // the magfield method uses meters - double[] value = new double[8]; - - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) // fiducial cut - { - return null; - } - // use a SwimZResult instead of a trajectory (dph) - SwimZResult szr = null; + // Fiducial Cut: + if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; - SwimTrajectory traj = null; + double[] value = new double[8]; double hdata[] = new double[3]; try { + // Try to use new Z-Swimmer: + SwimZResult szr = null; if (_pTot > SWIMZMINMOM) { - - // use the new z swimmer (dph) - // NOTE THE DISTANCE, UNITS FOR swimZ are cm, NOT m like the old - // swimmer (dph) - double stepSizeCM = stepSize * 100; // convert to cm - - // create the starting SwimZ state vector 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); + szr = PC.RCF_z.sectorAdaptiveRK(sector, _charge, _pTot, start, z_cm, stepSizeCM, hdata); } catch (SwimZException e) { - szr = null; - //System.err.println("[WARNING] Tilted SwimZ Failed for p = " + _pTot); + 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; // xf in cm - value[1] = last.y; // yz in cm - value[2] = last.z; // zf in cm + 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 - } else { // use old swimmer. Either low momentum or SwimZ failed. - // (dph) - - traj = PC.RCF.sectorSwim(sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, + } + + // 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); - - // traj.computeBDL(sector, rprob); - if(traj==null) - return null; - + if(traj==null) return null; traj.sectorComputeBDL(sector, PC.RCP); - // traj.computeBDL(rcompositeField); - double lastY[] = traj.lastElement(); value[0] = lastY[0] * 100; // convert back to cm value[1] = lastY[1] * 100; // convert back to cm @@ -280,57 +254,46 @@ public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { value[5] = lastY[5] * _pTot; value[6] = lastY[6] * 100; value[7] = lastY[7] * 10; - } // use old swimmer + } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } return value; } - - public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { - double z = z_cm / 100; // the magfield method uses meters - double[] value = new double[8]; - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) // fiducial cut - { - return null; - } + /** + * + * @param sector + * @param z_cm + * @return + */ + public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { - // use a SwimZResult instead of a trajectory (dph) - SwimZResult szr = null; + // Fiducial Cut: + if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; - SwimTrajectory traj = null; double hdata[] = new double[3]; + double[] value = new double[8]; try { + // Try to use new Z-Swimmer: + SwimZResult szr = null; if (_pTot > SWIMZMINMOM) { - - // use the new z swimmer (dph) - // NOTE THE DISTANCE, UNITS FOR swimZ are cm, NOT m like the old - // swimmer (dph) - double stepSizeCM = stepSize * 100; // convert to cm - - // create the starting SwimZ state vector 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); + szr = PC.RCF_z.sectorAdaptiveRK(sector, _charge, _pTot, start, z_cm, stepSizeCM, hdata); } catch (SwimZException e) { - szr = null; - //System.err.println("[WARNING] Tilted SwimZ Failed for p = " + _pTot); + 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 @@ -339,19 +302,15 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { value[5] = p3[2]; value[6] = pathLength; value[7] = bdl / 10; // convert from kg*cm to T*cm - } else { // use old swimmer. Either low momentum or SwimZ failed. - // (dph) - - traj = PC.RCF.sectorSwim(sector, _charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, + } + + // 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); - - // traj.computeBDL(sector, rprob); - if(traj==null) - return null; - + if (traj==null) return null; traj.sectorComputeBDL(sector, PC.RCP); - // traj.computeBDL(rcompositeField); - double lastY[] = traj.lastElement(); value[0] = lastY[0] * 100; // convert back to cm value[1] = lastY[1] * 100; // convert back to cm @@ -361,12 +320,11 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { value[5] = lastY[5] * _pTot; value[6] = lastY[6] * 100; value[7] = lastY[7] * 10; - } // use old swimmer + } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } return value; - } /** @@ -375,48 +333,31 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { * @return state x,y,z,px,py,pz, pathlength, iBdl at the plane surface */ public double[] SwimToPlaneLab(double z_cm) { - double z = z_cm / 100; // the magfield method uses meters - double[] value = new double[8]; - - if (_pTot < MINTRKMOM || this.SwimUnPhys==true) // fiducial cut - { - return null; - } - SwimTrajectory traj = null; - double hdata[] = new double[3]; - // use a SwimZResult instead of a trajectory (dph) - SwimZResult szr = null; + // Fiducial Cut: + if (_pTot < MINTRKMOM || this.SwimUnPhys==true) return null; + double hdata[] = new double[3]; + double[] value = new double[8]; + try { + // Try to use new Z-Swimmer: + SwimZResult szr = null; if (_pTot > SWIMZMINMOM) { - - // use the new z swimmer (dph) - // NOTE THE DISTANCE, UNITS FOR swimZ are cm, NOT m like the old - // swimmer (dph) - double stepSizeCM = stepSize * 100; // convert to cm - - // create the starting SwimZ state vector 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); + szr = PC.CF_z.adaptiveRK(_charge, _pTot, start, z_cm, stepSizeCM, hdata); } catch (SwimZException e) { - szr = null; - //System.err.println("[WARNING] SwimZ Failed for p = " + _pTot); - + 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 @@ -425,17 +366,16 @@ public double[] SwimToPlaneLab(double z_cm) { value[5] = p3[2]; value[6] = pathLength; value[7] = bdl / 10; // convert from kg*cm to T*cm - } else { // use old swimmer. Either low momentum or SwimZ failed. - // (dph) - traj = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, z, accuracy, _rMax, _maxPathLength, + } + + // 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; + if (traj==null) return null; traj.computeBDL(PC.CP); - // traj.computeBDL(compositeField); - 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 @@ -447,66 +387,43 @@ public double[] SwimToPlaneLab(double z_cm) { } // old swimmer } catch (RungeKuttaException e) { - e.printStackTrace(); + e.printStackTrace(); } return value; - } + /** + * + * @param _x0 + * @param _y0 + * @param _z0 + */ private void checkR(double _x0, double _y0, double _z0) { this.SwimUnPhys=false; if(Math.sqrt(_x0*_x0 + _y0*_y0)>this._rMax || Math.sqrt(_x0*_x0 + _y0*_y0 + _z0*_z0)>this._maxPathLength) this.SwimUnPhys=true; } - /** - * Cylindrical stopper - */ + private class CylindricalBoundarySwimStopper implements IStopper { private double _finalPathLength = Double.NaN; - private double _Rad; - //boolean cutOff = false; - // check that the track can get to R. Stops at the track radius - //float[] b = new float[3]; - //double x0 = _x0*100; - //double y0 = _y0*100; - //double z0 = _z0*100; - double max = -1.0; + /** * A swim stopper that will stop if the boundary of a plane is crossed * - * @param maxR - * the max radial coordinate in meters. + * @param maxR the max radial coordinate in meters. */ private CylindricalBoundarySwimStopper(double Rad) { - // DC reconstruction units are cm. Swim units are m. Hence scale by - // 100 _Rad = Rad; - // check if the track will reach the surface of the cylinder. - //BfieldLab(x0, y0, z0, b); - //double trkR = _pTot*Math.sin(Math.toRadians(_theta))/Math.abs(b[2]*LIGHTVEL); - //double trkXc = x0 + trkR * Math.sin(Math.toRadians(_phi)); - //if(trkR<(Rad+trkXc) && Math.sqrt(x0*x0+y0*y0)<_Rad) { // check only for swimming inside out. - // cutOff=true; - //} } @Override public boolean stopIntegration(double t, double[] y) { - double r = Math.sqrt(y[0] * y[0] + y[1] * y[1]) * 100.; -// if(r>max ) -// max = r; -// else System.out.println(r + " " + max + " " + t); - //if(cutOff) { - return (r < max || r > _Rad); // stop intergration at closest distance to the cylinder - //} - //else { - // return (r > _Rad); - //} + return (r < max || r > _Rad); // stop intergration at closest distance to the cylinder } /** @@ -516,7 +433,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -527,10 +444,9 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } - //private final double LIGHTVEL = 0.000299792458 ; /** * @@ -539,21 +455,17 @@ public void setFinalT(double finalPathLength) { */ public double[] SwimToCylinder(double Rad) { + if (this.SwimUnPhys) return null; double[] value = new double[8]; - if(this.SwimUnPhys) - return null; 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; + 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); - // st.computeBDL(compositeField); 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 @@ -562,9 +474,7 @@ public double[] SwimToCylinder(double Rad) { value[5] = lastY[5] * _pTot; value[6] = lastY[6] * 100; value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; - } /** @@ -584,14 +494,10 @@ public double[] SwimRho(double radius) { */ public double[] SwimRho(double radius, double accuracy) { + if(this.SwimUnPhys) return null; double[] value = null; - // using adaptive stepsize - if(this.SwimUnPhys) - return null; - 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); @@ -607,13 +513,11 @@ public double[] SwimRho(double radius, double accuracy) { 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); - e.printStackTrace(); + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); + e.printStackTrace(); } return value; - } /** @@ -637,6 +541,8 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r */ 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]; @@ -647,13 +553,7 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r p2[1] = axisPoint2.y()/100; p2[2] = axisPoint2.z()/100; - Cylinder targCyl = new Cylinder(p1, p2, radius/100); - // using adaptive stepsize - if(this.SwimUnPhys) - return null; - try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.CF.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, @@ -670,33 +570,34 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r 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); - e.printStackTrace(); + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); + e.printStackTrace(); } return value; } + /** + * + * @param n + * @param p + * @param accuracy + * @return + */ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { - double[] value = null; - + if (this.SwimUnPhys) return null; - // using adaptive stepsize - if(this.SwimUnPhys) - return null; + double[] value = 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 @@ -708,41 +609,32 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { 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); - e.printStackTrace(); + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); + e.printStackTrace(); } return value; - } private class SphericalBoundarySwimStopper implements IStopper { private double _finalPathLength = Double.NaN; - private double _Rad; /** * A swim stopper that will stop if the boundary of a plane is crossed * - * @param maxR - * the max radial coordinate in meters. + * @param maxR the max radial coordinate in meters. */ private SphericalBoundarySwimStopper(double Rad) { - // DC reconstruction units are cm. Swim units are m. Hence scale by - // 100 - _Rad = Rad; + _Rad = Rad; } @Override public boolean stopIntegration(double t, double[] y) { - - double r = Math.sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]) * 100.; - - return (r > _Rad); - + double r = Math.sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]) * 100.; + return r > _Rad; } /** @@ -752,7 +644,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -763,9 +655,10 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } + /** * * @param Rad @@ -773,21 +666,17 @@ public void setFinalT(double finalPathLength) { */ public double[] SwimToSphere(double Rad) { + if (this.SwimUnPhys==true) return null; double[] value = new double[8]; - // using adaptive stepsize - if(this.SwimUnPhys==true) - return null; + 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; + 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); - // st.computeBDL(compositeField); 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 @@ -796,9 +685,7 @@ public double[] SwimToSphere(double Rad) { value[5] = lastY[5] * _pTot; value[6] = lastY[6] * 100; value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - return value; - } // added for swimming to outer detectors @@ -813,8 +700,7 @@ private class PlaneBoundarySwimStopper implements IStopper { /** * A swim stopper that will stop if the boundary of a plane is crossed * - * @param maxR - * the max radial coordinate in meters. + * @param maxR the max radial coordinate in meters. */ private PlaneBoundarySwimStopper(double d, Vector3D n, int dir) { // DC reconstruction units are cm. Swim units are m. Hence scale by @@ -827,35 +713,26 @@ private PlaneBoundarySwimStopper(double d, Vector3D n, int dir) { @Override public boolean stopIntegration(double t, double[] y) { double dtrk = y[0] * _n.x() + y[1] * _n.y() + y[2] * _n.z(); - - double accuracy = 20e-6; // 20 microns - // System.out.println(" dist "+dtrk*100+ " state "+y[0]*100+", - // "+y[1]*100+" , "+y[2]*100); - if (_dir < 0) { - return dtrk < _d; - } else { - return dtrk > _d; - } - + //double accuracy = 20e-6; // 20 microns + return _dir < 0 ? dtrk < _d : dtrk > _d; } @Override public double getFinalT() { - - return _finalPathLength; + return _finalPathLength; } /** * Set the final path length in meters * - * @param finalPathLength - * the final path length in meters + * @param finalPathLength the final path length in meters */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } + /** * * @param d_cm @@ -865,21 +742,18 @@ public void setFinalT(double finalPathLength) { */ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { + if (this.SwimUnPhys) return null; + double[] value = new double[8]; - if(this.SwimUnPhys) - return null; - double d = d_cm / 100; - double hdata[] = new double[3]; - // using adaptive stepsize + double d = d_cm / 100; // convert to meters - // the new swim to plane in swimmer Plane plane = new Plane(n.x(), n.y(), n.z(), d); - SwimTrajectory st; try { - st = PC.CF.swim(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, plane, accuracy, _maxPathLength, stepSize, - cnuphys.swim.Swimmer.CLAS_Tolerance, hdata); + 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); @@ -894,26 +768,16 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { value[6] = lastY[6] * 100; value[7] = lastY[7] * 10; // Conversion from kG.m to T.cm - // System.out.println("\nCOMPARE plane swims DIRECTION = " + - // dir); - // for (int i = 0; i < 8; i++) { - // System.out.print(String.format("%-8.5f ", value[i])); - // } - - } catch (RungeKuttaException e) { - e.printStackTrace(); + e.printStackTrace(); } return value; - } + - - private class BeamLineSwimStopper implements IStopper { private double _finalPathLength = Double.NaN; - private double _xB; private double _yB; double min = Double.POSITIVE_INFINITY; @@ -921,19 +785,19 @@ private class BeamLineSwimStopper implements IStopper { double phiRad = Math.toRadians(_phi); double pz = _pTot * Math.cos(thetaRad); private BeamLineSwimStopper(double xB, double yB) { - // DC reconstruction units are cm. Swim units are m. Hence scale by - // 100 - _xB = xB; - _yB = yB; + _xB = xB; + _yB = yB; } @Override public boolean stopIntegration(double t, double[] y) { - double r = Math.sqrt((_xB-y[0]* 100.) * (_xB-y[0]* 100.) + (_yB-y[1]* 100.) * (_yB-y[1]* 100.)); - if(r min ); + double r = Math.sqrt((_xB-y[0]* 100.) * (_xB-y[0]* 100.) + (_yB-y[1]* 100.) * (_yB-y[1]* 100.)); + // Start at about 2 meters before target. + // Avoid inbending stopping when P dir changes: + if (r min ; } @@ -944,7 +808,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -955,27 +819,24 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } public double[] SwimToBeamLine(double xB, double yB) { + if(this.SwimUnPhys==true) return null; + double[] value = new double[8]; - if(this.SwimUnPhys==true) - return null; 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; + 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); - // st.computeBDL(compositeField); 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 @@ -984,25 +845,19 @@ public double[] SwimToBeamLine(double xB, double yB) { 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 class LineSwimStopper implements IStopper { private double _finalPathLength = Double.NaN; - private Line3D _l; private Point3D _p; double min = 999; private LineSwimStopper(Line3D l) { - // DC reconstruction units are cm. Swim units are m. Hence scale by - // 100 - _l =l; - _p = new Point3D(); + _l =l; + _p = new Point3D(); } @Override @@ -1013,7 +868,6 @@ public boolean stopIntegration(double t, double[] y) { min = doca; } return (doca > min ); - } /** @@ -1023,7 +877,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -1034,27 +888,24 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } public double[] SwimToLine(Line3D l) { + + if (this.SwimUnPhys==true) return null; double[] value = new double[8]; - if(this.SwimUnPhys==true) - return null; 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; + 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); - // st.computeBDL(compositeField); 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 @@ -1063,20 +914,15 @@ public double[] SwimToLine(Line3D l) { 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 void printV(String pfx, double v[]) { - double x = v[0] / 100; - double y = v[1] / 100; - double z = v[2] / 100; - double r = Math.sqrt(x * x + y * y + z * z); - System.out.println(String.format("%s: (%-8.5f, %-8.5f, %-8.5f) R: %-8.5f", pfx, z, y, z, r)); + double x = v[0] / 100; + double y = v[1] / 100; + double z = v[2] / 100; + double r = Math.sqrt(x * x + y * y + z * z); + System.out.println(String.format("%s: (%-8.5f, %-8.5f, %-8.5f) R: %-8.5f", pfx, z, y, z, r)); } /** @@ -1088,15 +934,12 @@ private void printV(String pfx, double v[]) { * @param result B field components in T in the tilted sector system */ public void Bfield(int sector, double x_cm, double y_cm, double z_cm, float[] result) { - PC.RCP.field(sector, (float) x_cm, (float) y_cm, (float) z_cm, result); - // rcompositeField.field((float) x_cm, (float) y_cm, (float) z_cm, - // result); result[0] = result[0] / 10; result[1] = result[1] / 10; result[2] = result[2] / 10; - } + /** * * @param x_cm @@ -1113,10 +956,9 @@ public void BfieldLab(double x_cm, double y_cm, double z_cm, float[] result) { } - - public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { -// System.out.println("Don't use yet"); + + if (this.SwimUnPhys) return null; double[] value = new double[8]; @@ -1125,13 +967,7 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point); - - // using adaptive stepsize - if(this.SwimUnPhys) - return null; - try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane, @@ -1152,29 +988,24 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do } } catch (AdaptiveSwimException e) { - e.printStackTrace(); + e.printStackTrace(); } return value; - } - public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { - // System.out.println("Don't use yet"); + + if (this.SwimUnPhys) return null; + double[] value = new double[8]; radius = radius/100; Point a1 = new Point(a1x/100, a1y/100, a1z/100); Point a2 = new Point(a2x/100, a2y/100, a2z/100); Line centerLine = new Line(a1, a2); - - cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius); + cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius); - // using adaptive stepsize - if(this.SwimUnPhys) - return null; - try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); @@ -1197,24 +1028,19 @@ public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double } } catch (AdaptiveSwimException e) { - e.printStackTrace(); + e.printStackTrace(); } return value; - } public double[] AdaptiveSwimRho(double radius, double accuracy) { System.out.println("Don't use yet"); + if(this.SwimUnPhys) return null; double[] value = new double[8]; radius = radius/100; - // using adaptive stepsize - if(this.SwimUnPhys) - return null; - try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, @@ -1233,36 +1059,27 @@ public double[] AdaptiveSwimRho(double radius, double accuracy) { else { return null; } - } catch (AdaptiveSwimException e) { e.printStackTrace(); } return value; - } -/** + /** * * @param Z + * @param dir * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface */ public double[] SwimToZ(double Z, int dir) { - double[] value = new double[8]; - //if(this.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; + 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); - // st.computeBDL(compositeField); 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 @@ -1271,9 +1088,7 @@ public double[] SwimToZ(double Z, int dir) { 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 SwimTrajectory swimTraj; @@ -1281,26 +1096,18 @@ public double[] SwimToZ(double Z, int dir) { private class ZSwimStopper implements IStopper { private double _finalPathLength = Double.NaN; - private double _Z; private int _dir; private ZSwimStopper(double Z, int dir) { - // The reconstruction units are cm. Swim units are m. Hence scale by - // 100 _Z = Z; _dir = dir; } @Override public boolean stopIntegration(double t, double[] y) { - double z = y[2] * 100.; - if(_dir>0) { - return (z > _Z); - } else { - return (z<_Z); - } + return _dir>0 ? z>_Z : z<_Z; } /** @@ -1310,7 +1117,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -1321,9 +1128,10 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } } + /** * @return the swimTraj */ @@ -1370,7 +1178,6 @@ public boolean stopIntegration(double t, double[] y) { return false; } return true; - } /** @@ -1380,7 +1187,7 @@ public boolean stopIntegration(double t, double[] y) { */ @Override public double getFinalT() { - return _finalPathLength; + return _finalPathLength; } /** @@ -1391,22 +1198,19 @@ public double getFinalT() { */ @Override public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; + _finalPathLength = finalPathLength; } - } + public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track double[] value = new double[6]; - //if(this.SwimUnPhys) - // return null; 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; + 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(); @@ -1416,11 +1220,7 @@ public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca value[3] = lastY[3] * _pTot; // normalized values value[4] = lastY[4] * _pTot; value[5] = lastY[5] * _pTot; - return value; - - - } } \ No newline at end of file diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java index 4874b3eab0..c6344fc593 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swimmer.java @@ -1,15 +1,14 @@ package org.jlab.clas.swimtools; -import cnuphys.magfield.MagneticFields; import java.util.HashMap; import java.util.logging.Logger; +import cnuphys.magfield.MagneticFields; /** * * @author ziegler, heddle */ - public class Swimmer { public static Logger LOGGER = Logger.getLogger(Swimmer.class.getName()); From c8511730b63e980f5553cab7cb5857a5466b04da Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 13:05:41 -0500 Subject: [PATCH 03/24] more cleanup --- .../main/java/org/jlab/clas/swimtools/Swim.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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 fe4df35d45..887b124a3d 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 @@ -616,7 +616,6 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { return value; } - private class SphericalBoundarySwimStopper implements IStopper { private double _finalPathLength = Double.NaN; @@ -703,11 +702,9 @@ private class PlaneBoundarySwimStopper implements IStopper { * @param maxR the max radial coordinate in meters. */ private PlaneBoundarySwimStopper(double d, Vector3D n, int dir) { - // DC reconstruction units are cm. Swim units are m. Hence scale by - // 100 - _d = d; - _n = n; - _dir = dir; + _d = d; + _n = n; + _dir = dir; } @Override @@ -773,7 +770,6 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { } return value; } - private class BeamLineSwimStopper implements IStopper { @@ -848,7 +844,6 @@ public double[] SwimToBeamLine(double xB, double yB) { return value; } - private class LineSwimStopper implements IStopper { private double _finalPathLength = Double.NaN; @@ -948,12 +943,10 @@ public void Bfield(int sector, double x_cm, double y_cm, double z_cm, float[] re * @param result B field components in T in the lab frame */ public void BfieldLab(double x_cm, double y_cm, double z_cm, float[] result) { - PC.CP.field((float) x_cm, (float) y_cm, (float) z_cm, result); result[0] = result[0] / 10; result[1] = result[1] / 10; result[2] = result[2] / 10; - } public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { @@ -1153,7 +1146,6 @@ public DCASwimStopper(SwimTrajectory swimTraj) { for(int i = 0; i < _swimTraj.size()-1; i++) { polylines.add(new Line3D(_swimTraj.get(i)[0],_swimTraj.get(i)[1],_swimTraj.get(i)[2], _swimTraj.get(i+1)[0],_swimTraj.get(i+1)[1],_swimTraj.get(i+1)[2])); - } } @@ -1204,7 +1196,7 @@ public void setFinalT(double finalPathLength) { public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track - double[] value = new double[6]; + double[] value = new double[6]; DCASwimStopper stopper = new DCASwimStopper(trk2); From 0ee52f981b0f283718701a7e04a9b21fb6827e13 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 13:19:40 -0500 Subject: [PATCH 04/24] organize imports --- .../java/org/jlab/clas/swimtools/Swim.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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 887b124a3d..937f34bbe4 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 @@ -1,24 +1,30 @@ package org.jlab.clas.swimtools; -import cnuphys.adaptiveSwim.AdaptiveSwimException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.math3.util.FastMath; + +import org.jlab.geom.prim.Vector3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Line3D; + import cnuphys.rk4.IStopper; import cnuphys.rk4.RungeKuttaException; + import cnuphys.swim.SwimTrajectory; import cnuphys.swim.util.Plane; + import cnuphys.swimZ.SwimZException; import cnuphys.swimZ.SwimZResult; import cnuphys.swimZ.SwimZStateVector; -import org.apache.commons.math3.util.FastMath; -import org.jlab.geom.prim.Vector3D; -import org.jlab.geom.prim.Point3D; + +import cnuphys.adaptiveSwim.AdaptiveSwimException; import cnuphys.adaptiveSwim.AdaptiveSwimResult; import cnuphys.adaptiveSwim.AdaptiveSwimmer; import cnuphys.adaptiveSwim.geometry.Line; import cnuphys.adaptiveSwim.geometry.Point; import cnuphys.adaptiveSwim.geometry.Vector; -import java.util.ArrayList; -import java.util.List; -import org.jlab.geom.prim.Line3D; /** * From cf040d4cbe0cc34a448950789f35252781223e83 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 13:39:10 -0500 Subject: [PATCH 05/24] organize parameters --- .../java/org/jlab/clas/swimtools/Swim.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 937f34bbe4..bdee94b940 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 @@ -83,7 +83,7 @@ public void setMaxPathLength(double _maxPathLength) { * @param charge */ public void SetSwimParameters(int direction, double x0, double y0, double z0, - double thx, double thy, double p, int charge) { + double thx, double thy, double p, int charge) { _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; @@ -114,7 +114,8 @@ public void SetSwimParameters(int direction, double x0, double y0, double z0, * @param charge */ public void SetSwimParameters(int superlayerIdx, int layerIdx, - double x0, double y0, double z0, double thx, double thy, double p, int charge) { + double x0, double y0, double z0, + double thx, double thy, double p, int charge) { _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; @@ -139,7 +140,8 @@ public void SetSwimParameters(int superlayerIdx, int layerIdx, * @param pz * @param charge */ - public void SetSwimParameters(double x0, double y0, double z0, double px, double py, double pz, int charge) { + public void SetSwimParameters(double x0, double y0, double z0, + double px, double py, double pz, int charge) { _x0 = x0 / 100; // convert to meters _y0 = y0 / 100; _z0 = z0 / 100; @@ -161,8 +163,9 @@ public void SetSwimParameters(double x0, double y0, double z0, double px, double * @param charge * @param maxPathLength */ - public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, double thetaDeg, double p, - int charge, double maxPathLength) { + public void SetSwimParameters(double xcm, double ycm, double zcm, + double phiDeg, double thetaDeg, + double p, int charge, double maxPathLength) { _maxPathLength = maxPathLength; _charge = charge; _phi = phiDeg; @@ -187,8 +190,10 @@ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, * @param Accuracy * @param StepSize */ - public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, double thetaDeg, double p, - int charge, double maxPathLength, double Accuracy, double StepSize) { + public void SetSwimParameters(double xcm, double ycm, double zcm, + double phiDeg, double thetaDeg, + double p, int charge, + double maxPathLength, double Accuracy, double StepSize) { _maxPathLength = maxPathLength; accuracy = Accuracy/100; stepSize = StepSize/100; @@ -1145,7 +1150,7 @@ public void setSwimTraj(SwimTrajectory swimTraj) { this.swimTraj = swimTraj; } - private class DCASwimStopper implements IStopper { + private class DCASwimStopper implements IStopper { public DCASwimStopper(SwimTrajectory swimTraj) { _swimTraj = swimTraj; From a205eb4ff1563acbb18b8d3efff6b35dae5025ec Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 13:39:42 -0500 Subject: [PATCH 06/24] interface the necessary methods --- .../java/org/jlab/clas/swimtools/ISwim.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java 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 new file mode 100644 index 0000000000..d90ef4955a --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ISwim.java @@ -0,0 +1,42 @@ +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; + +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); + + public double[] SwimRho(double radius, double accuracy); + + public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy); + + public double[] SwimPlane(Vector3D n, Point3D p, double accuracy); + + public double[] SwimToSphere(double Rad); + + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir); + + public double[] SwimToBeamLine(double xB, double yB); + + public double[] SwimToLine(Line3D l); + + public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy); + + public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy); + + public double[] AdaptiveSwimRho(double radius, double accuracy); + + public double[] SwimToZ(double Z, int dir); + + public double[] SwimToDCA(SwimTrajectory trk2); + +} From 3170534207d51dc8b977027a59a10ec38b0c943d Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 14:46:31 -0500 Subject: [PATCH 07/24] move stoppers to separate class --- .../org/jlab/clas/swimtools/Stoppers.java | 324 ++++++++++++++++++ .../java/org/jlab/clas/swimtools/Swim.java | 324 +----------------- 2 files changed, 331 insertions(+), 317 deletions(-) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Stoppers.java diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Stoppers.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Stoppers.java new file mode 100644 index 0000000000..2532e746a8 --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Stoppers.java @@ -0,0 +1,324 @@ +package org.jlab.clas.swimtools; + +import cnuphys.rk4.IStopper; +import cnuphys.swim.SwimTrajectory; +import java.util.ArrayList; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; + +public class Stoppers { + + public static class CylindricalBoundarySwimStopper implements IStopper { + + private double _finalPathLength = Double.NaN; + private double _Rad; + double max = -1.0; + + /** + * A swim stopper that will stop if the boundary of a plane is crossed + * + * @param Rad the max radial coordinate in meters. + */ + public CylindricalBoundarySwimStopper(double Rad) { + _Rad = Rad; + } + + @Override + public boolean stopIntegration(double t, double[] y) { + double r = Math.sqrt(y[0] * y[0] + y[1] * y[1]) * 100.; + return (r < max || r > _Rad); // stop intergration at closest distance to the cylinder + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength + * the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + + public static class SphericalBoundarySwimStopper implements IStopper { + + private double _finalPathLength = Double.NaN; + private double _Rad; + + /** + * A swim stopper that will stop if the boundary of a plane is crossed + * + * @param maxR the max radial coordinate in meters. + */ + public SphericalBoundarySwimStopper(double Rad) { + _Rad = Rad; + } + + @Override + public boolean stopIntegration(double t, double[] y) { + double r = Math.sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]) * 100.; + return r > _Rad; + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength + * the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + + // added for swimming to outer detectors + public static class PlaneBoundarySwimStopper implements IStopper { + + private double _finalPathLength = Double.NaN; + private double _d; + private Vector3D _n; + private double _dist2plane; + private int _dir; + + /** + * A swim stopper that will stop if the boundary of a plane is crossed + * + * @param d + * @param dir + * @param n + */ + public PlaneBoundarySwimStopper(double d, Vector3D n, int dir) { + _d = d; + _n = n; + _dir = dir; + } + + @Override + public boolean stopIntegration(double t, double[] y) { + double dtrk = y[0] * _n.x() + y[1] * _n.y() + y[2] * _n.z(); + //double accuracy = 20e-6; // 20 microns + return _dir < 0 ? dtrk < _d : dtrk > _d; + } + + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + + public static class LineSwimStopper implements IStopper { + + private double _finalPathLength = Double.NaN; + private Line3D _l; + private Point3D _p; + double min = 999; + public LineSwimStopper(Line3D l) { + _l =l; + _p = new Point3D(); + } + + @Override + public boolean stopIntegration(double t, double[] y) { + _p.set(y[0]* 100.0, y[1]* 100.0, y[2]* 100.0); + double doca = _l.distance(_p).length(); + if(doca min ); + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength + * the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + + public static class ZSwimStopper implements IStopper { + + private double _finalPathLength = Double.NaN; + private double _Z; + private int _dir; + + public ZSwimStopper(double Z, int dir) { + _Z = Z; + _dir = dir; + } + + @Override + public boolean stopIntegration(double t, double[] y) { + double z = y[2] * 100.; + return _dir>0 ? z>_Z : z<_Z; + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength + * the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + + public static class DCASwimStopper implements IStopper { + + public DCASwimStopper(SwimTrajectory swimTraj) { + _swimTraj = swimTraj; + for(int i = 0; i < _swimTraj.size()-1; i++) { + polylines.add(new Line3D(_swimTraj.get(i)[0],_swimTraj.get(i)[1],_swimTraj.get(i)[2], + _swimTraj.get(i+1)[0],_swimTraj.get(i+1)[1],_swimTraj.get(i+1)[2])); + } + } + + private ArrayList polylines = new ArrayList<>(); + private SwimTrajectory _swimTraj; + private double _finalPathLength = Double.NaN; + private double _doca = Double.POSITIVE_INFINITY; + + @Override + public boolean stopIntegration(double t, double[] y) { + + Point3D dcaCand = new Point3D(y[0],y[1],y[2]); + double maxDoca = Double.POSITIVE_INFINITY; + + for(Line3D l : polylines) { + if(l.distance(dcaCand).length() min ; + + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _finalPathLength; + } + + /** + * Set the final path length in meters + * + * @param finalPathLength + * the final path length in meters + */ + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + } + +} \ No newline at end of file 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 bdee94b940..2b8c8a8eba 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 @@ -1,15 +1,11 @@ package org.jlab.clas.swimtools; -import java.util.ArrayList; -import java.util.List; - import org.apache.commons.math3.util.FastMath; import org.jlab.geom.prim.Vector3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Line3D; -import cnuphys.rk4.IStopper; import cnuphys.rk4.RungeKuttaException; import cnuphys.swim.SwimTrajectory; @@ -25,6 +21,13 @@ import cnuphys.adaptiveSwim.geometry.Line; import cnuphys.adaptiveSwim.geometry.Point; import cnuphys.adaptiveSwim.geometry.Vector; +import org.jlab.clas.swimtools.Stoppers.BeamLineSwimStopper; + +import org.jlab.clas.swimtools.Stoppers.CylindricalBoundarySwimStopper; +import org.jlab.clas.swimtools.Stoppers.DCASwimStopper; +import org.jlab.clas.swimtools.Stoppers.LineSwimStopper; +import org.jlab.clas.swimtools.Stoppers.SphericalBoundarySwimStopper; +import org.jlab.clas.swimtools.Stoppers.ZSwimStopper; /** * @@ -416,49 +419,6 @@ private void checkR(double _x0, double _y0, double _z0) { this.SwimUnPhys=true; } - private class CylindricalBoundarySwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private double _Rad; - double max = -1.0; - - /** - * A swim stopper that will stop if the boundary of a plane is crossed - * - * @param maxR the max radial coordinate in meters. - */ - private CylindricalBoundarySwimStopper(double Rad) { - _Rad = Rad; - } - - @Override - public boolean stopIntegration(double t, double[] y) { - double r = Math.sqrt(y[0] * y[0] + y[1] * y[1]) * 100.; - return (r < max || r > _Rad); // stop intergration at closest distance to the cylinder - } - - /** - * Get the final path length in meters - * - * @return the final path length in meters - */ - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength - * the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - /** * * @param Rad @@ -627,48 +587,6 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { return value; } - private class SphericalBoundarySwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private double _Rad; - - /** - * A swim stopper that will stop if the boundary of a plane is crossed - * - * @param maxR the max radial coordinate in meters. - */ - private SphericalBoundarySwimStopper(double Rad) { - _Rad = Rad; - } - - @Override - public boolean stopIntegration(double t, double[] y) { - double r = Math.sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]) * 100.; - return r > _Rad; - } - - /** - * Get the final path length in meters - * - * @return the final path length in meters - */ - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength - * the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - /** * * @param Rad @@ -698,49 +616,6 @@ public double[] SwimToSphere(double Rad) { return value; } - // added for swimming to outer detectors - private class PlaneBoundarySwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private double _d; - private Vector3D _n; - private double _dist2plane; - private int _dir; - - /** - * A swim stopper that will stop if the boundary of a plane is crossed - * - * @param maxR the max radial coordinate in meters. - */ - private PlaneBoundarySwimStopper(double d, Vector3D n, int dir) { - _d = d; - _n = n; - _dir = dir; - } - - @Override - public boolean stopIntegration(double t, double[] y) { - double dtrk = y[0] * _n.x() + y[1] * _n.y() + y[2] * _n.z(); - //double accuracy = 20e-6; // 20 microns - return _dir < 0 ? dtrk < _d : dtrk > _d; - } - - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - /** * * @param d_cm @@ -782,54 +657,6 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { return value; } - private class BeamLineSwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private double _xB; - private double _yB; - double min = Double.POSITIVE_INFINITY; - double thetaRad = Math.toRadians(_theta); - double phiRad = Math.toRadians(_phi); - double pz = _pTot * Math.cos(thetaRad); - private BeamLineSwimStopper(double xB, double yB) { - _xB = xB; - _yB = yB; - } - - @Override - public boolean stopIntegration(double t, double[] y) { - - double r = Math.sqrt((_xB-y[0]* 100.) * (_xB-y[0]* 100.) + (_yB-y[1]* 100.) * (_yB-y[1]* 100.)); - // Start at about 2 meters before target. - // Avoid inbending stopping when P dir changes: - if (r min ; - - } - - /** - * Get the final path length in meters - * - * @return the final path length in meters - */ - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength - * the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - public double[] SwimToBeamLine(double xB, double yB) { if(this.SwimUnPhys==true) return null; @@ -855,49 +682,6 @@ public double[] SwimToBeamLine(double xB, double yB) { return value; } - private class LineSwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private Line3D _l; - private Point3D _p; - double min = 999; - private LineSwimStopper(Line3D l) { - _l =l; - _p = new Point3D(); - } - - @Override - public boolean stopIntegration(double t, double[] y) { - _p.set(y[0]* 100.0, y[1]* 100.0, y[2]* 100.0); - double doca = _l.distance(_p).length(); - if(doca min ); - } - - /** - * Get the final path length in meters - * - * @return the final path length in meters - */ - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength - * the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - public double[] SwimToLine(Line3D l) { if (this.SwimUnPhys==true) return null; @@ -1097,45 +881,6 @@ public double[] SwimToZ(double Z, int dir) { private SwimTrajectory swimTraj; - private class ZSwimStopper implements IStopper { - - private double _finalPathLength = Double.NaN; - private double _Z; - private int _dir; - - private ZSwimStopper(double Z, int dir) { - _Z = Z; - _dir = dir; - } - - @Override - public boolean stopIntegration(double t, double[] y) { - double z = y[2] * 100.; - return _dir>0 ? z>_Z : z<_Z; - } - - /** - * Get the final path length in meters - * - * @return the final path length in meters - */ - @Override - public double getFinalT() { - return _finalPathLength; - } - - /** - * Set the final path length in meters - * - * @param finalPathLength - * the final path length in meters - */ - @Override - public void setFinalT(double finalPathLength) { - _finalPathLength = finalPathLength; - } - } - /** * @return the swimTraj */ @@ -1150,61 +895,6 @@ public void setSwimTraj(SwimTrajectory swimTraj) { this.swimTraj = swimTraj; } - private class DCASwimStopper implements IStopper { - - public DCASwimStopper(SwimTrajectory swimTraj) { - _swimTraj = swimTraj; - for(int i = 0; i < _swimTraj.size()-1; i++) { - polylines.add(new Line3D(_swimTraj.get(i)[0],_swimTraj.get(i)[1],_swimTraj.get(i)[2], - _swimTraj.get(i+1)[0],_swimTraj.get(i+1)[1],_swimTraj.get(i+1)[2])); - } - } - - private List polylines = new ArrayList<>(); - private SwimTrajectory _swimTraj; - private double _finalPathLength = Double.NaN; - private double _doca = Double.POSITIVE_INFINITY; - - @Override - public boolean stopIntegration(double t, double[] y) { - - Point3D dcaCand = new Point3D(y[0],y[1],y[2]); - double maxDoca = Double.POSITIVE_INFINITY; - - for(Line3D l : polylines) { - if(l.distance(dcaCand).length() Date: Tue, 23 Dec 2025 15:15:15 -0500 Subject: [PATCH 08/24] move parameters to separate class --- .../java/org/jlab/clas/swimtools/ISwim.java | 5 + .../java/org/jlab/clas/swimtools/Swim.java | 236 ++---------------- .../org/jlab/clas/swimtools/SwimPars.java | 217 ++++++++++++++++ 3 files changed, 240 insertions(+), 218 deletions(-) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java 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 d90ef4955a..409f529497 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 @@ -5,6 +5,11 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +/** + * Warning, lots of these should probably be removed! + * + * @author baltzell + */ interface ISwim { public double[] SwimToPlaneTiltSecSys(int sector, double z_cm); 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 2b8c8a8eba..f0816bfd00 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 @@ -1,7 +1,5 @@ package org.jlab.clas.swimtools; -import org.apache.commons.math3.util.FastMath; - import org.jlab.geom.prim.Vector3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Line3D; @@ -33,27 +31,8 @@ * * @author ziegler */ -public class Swim { - - final double SWIMZMINMOM = 0.75; // GeV/c - final double MINTRKMOM = 0.05; // GeV/c - - private double _x0; - private double _y0; - private double _z0; - private double _phi; - private double _theta; - private double _pTot; - private final double _rMax = 5 + 3; - private double _maxPathLength = 9; - private boolean SwimUnPhys = false; //Flag to indicate if track is swimmable - private int _charge; - double accuracy = 20e-6; // 20 microns - public double stepSize = 5.00 * 1.e-4; // 500 microns - public double distanceBetweenSaves= 100*stepSize; - - private ProbeCollection PC; - +public class Swim extends SwimPars implements ISwim { + /** * Class for swimming to various surfaces. The input and output units are cm and GeV/c */ @@ -65,157 +44,13 @@ public Swim() { } } - /** - * Set max swimming path length - * - * @param _maxPathLength - */ - public void setMaxPathLength(double _maxPathLength) { - this._maxPathLength = _maxPathLength; - } - - /** - * - * @param direction +1 for out -1 for in - * @param x0 (cm) - * @param y0 (cm) - * @param z0 (cm) - * @param thx (units?) - * @param thy (units?) - * @param p (units?) - * @param charge - */ - public void SetSwimParameters(int direction, double x0, double y0, double z0, - double thx, double thy, double p, int charge) { - _x0 = x0 / 100; // convert to meters - _y0 = y0 / 100; - _z0 = z0 / 100; - this.checkR(_x0, _y0, _z0); - double pz = direction * p / Math.sqrt(thx * thx + thy * thy + 1); - double px = thx * pz; - double py = thy * pz; - _phi = Math.toDegrees(FastMath.atan2(py, px)); - _pTot = Math.sqrt(px * px + py * py + pz * pz); - _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = direction * charge; - } - - /** - * Sets the parameters used by swimmer based on the input track state vector - * parameters swimming outwards - * - * // z at a given DC plane in the tilted coordinate system - * - * @param superlayerIdx - * @param layerIdx - * @param x0 (cm) - * @param y0 (cm) - * @param z0 (cm) - * @param thx - * @param thy - * @param p - * @param charge - */ - public void SetSwimParameters(int superlayerIdx, int layerIdx, - double x0, double y0, double z0, - double thx, double thy, double p, int charge) { - _x0 = x0 / 100; // convert to meters - _y0 = y0 / 100; - _z0 = z0 / 100; - this.checkR(_x0, _y0, _z0); - double pz = p / Math.sqrt(thx * thx + thy * thy + 1); - double px = thx * pz; - double py = thy * pz; - _phi = Math.toDegrees(FastMath.atan2(py, px)); - _pTot = Math.sqrt(px * px + py * py + pz * pz); - _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = charge; - } - - /** - * Sets the parameters used by swimmer based on the input track parameters - * - * @param x0 (cm) - * @param y0 (cm) - * @param z0 (cm) - * @param px - * @param py - * @param pz - * @param charge - */ - public void SetSwimParameters(double x0, double y0, double z0, - double px, double py, double pz, int charge) { - _x0 = x0 / 100; // convert to meters - _y0 = y0 / 100; - _z0 = z0 / 100; - this.checkR(_x0, _y0, _z0); - _phi = Math.toDegrees(FastMath.atan2(py, px)); - _pTot = Math.sqrt(px * px + py * py + pz * pz); - _theta = Math.toDegrees(Math.acos(pz / _pTot)); - _charge = charge; - } - - /** - * - * @param xcm - * @param ycm - * @param zcm - * @param phiDeg - * @param thetaDeg - * @param p - * @param charge - * @param maxPathLength - */ - public void SetSwimParameters(double xcm, double ycm, double zcm, - double phiDeg, double thetaDeg, - double p, int charge, double maxPathLength) { - _maxPathLength = maxPathLength; - _charge = charge; - _phi = phiDeg; - _theta = thetaDeg; - _pTot = p; - _x0 = xcm / 100; - _y0 = ycm / 100; - _z0 = zcm / 100; - this.checkR(_x0, _y0, _z0); - } - - /** - * - * @param xcm - * @param ycm - * @param zcm - * @param phiDeg - * @param thetaDeg - * @param p - * @param charge - * @param maxPathLength - * @param Accuracy - * @param StepSize - */ - public void SetSwimParameters(double xcm, double ycm, double zcm, - double phiDeg, double thetaDeg, - double p, int charge, - double maxPathLength, double Accuracy, double StepSize) { - _maxPathLength = maxPathLength; - accuracy = Accuracy/100; - stepSize = StepSize/100; - _charge = charge; - _phi = phiDeg; - _theta = thetaDeg; - _pTot = p; - _x0 = xcm / 100; - _y0 = ycm / 100; - _z0 = zcm / 100; - this.checkR(_x0, _y0, _z0); - } - /** * * @param sector * @param z_cm * @return */ + @Override public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { // Fiducial Cut: @@ -282,6 +117,7 @@ public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { * @param z_cm * @return */ + @Override public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { // Fiducial Cut: @@ -346,6 +182,7 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { * @param z_cm * @return state x,y,z,px,py,pz, pathlength, iBdl at the plane surface */ + @Override public double[] SwimToPlaneLab(double z_cm) { // Fiducial Cut: @@ -406,24 +243,12 @@ public double[] SwimToPlaneLab(double z_cm) { return value; } - /** - * - * @param _x0 - * @param _y0 - * @param _z0 - */ - private void checkR(double _x0, double _y0, double _z0) { - this.SwimUnPhys=false; - if(Math.sqrt(_x0*_x0 + _y0*_y0)>this._rMax || - Math.sqrt(_x0*_x0 + _y0*_y0 + _z0*_z0)>this._maxPathLength) - this.SwimUnPhys=true; - } - /** * * @param Rad * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface */ + @Override public double[] SwimToCylinder(double Rad) { if (this.SwimUnPhys) return null; @@ -463,6 +288,7 @@ public double[] SwimRho(double radius) { * @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) { if(this.SwimUnPhys) return null; @@ -510,6 +336,7 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r * @param accuracy in cm * @return swam trajectory to the cylinder */ + @Override public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { if(this.SwimUnPhys) return null; @@ -556,6 +383,7 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r * @param accuracy * @return */ + @Override public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { if (this.SwimUnPhys) return null; @@ -592,6 +420,7 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { * @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; @@ -623,6 +452,7 @@ public double[] SwimToSphere(double Rad) { * @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; @@ -657,6 +487,7 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { return value; } + @Override public double[] SwimToBeamLine(double xB, double yB) { if(this.SwimUnPhys==true) return null; @@ -682,6 +513,7 @@ public double[] SwimToBeamLine(double xB, double yB) { return value; } + @Override public double[] SwimToLine(Line3D l) { if (this.SwimUnPhys==true) return null; @@ -707,43 +539,7 @@ public double[] SwimToLine(Line3D l) { return value; } - private void printV(String pfx, double v[]) { - double x = v[0] / 100; - double y = v[1] / 100; - double z = v[2] / 100; - double r = Math.sqrt(x * x + y * y + z * z); - System.out.println(String.format("%s: (%-8.5f, %-8.5f, %-8.5f) R: %-8.5f", pfx, z, y, z, r)); - } - - /** - * - * @param sector - * @param x_cm - * @param y_cm - * @param z_cm - * @param result B field components in T in the tilted sector system - */ - public void Bfield(int sector, double x_cm, double y_cm, double z_cm, float[] result) { - PC.RCP.field(sector, (float) x_cm, (float) y_cm, (float) z_cm, result); - result[0] = result[0] / 10; - result[1] = result[1] / 10; - result[2] = result[2] / 10; - } - - /** - * - * @param x_cm - * @param y_cm - * @param z_cm - * @param result B field components in T in the lab frame - */ - public void BfieldLab(double x_cm, double y_cm, double z_cm, float[] result) { - PC.CP.field((float) x_cm, (float) y_cm, (float) z_cm, result); - result[0] = result[0] / 10; - result[1] = result[1] / 10; - result[2] = result[2] / 10; - } - + @Override public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { if (this.SwimUnPhys) return null; @@ -781,6 +577,7 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do return value; } + @Override public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { if (this.SwimUnPhys) return null; @@ -821,6 +618,7 @@ public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double return value; } + @Override public double[] AdaptiveSwimRho(double radius, double accuracy) { System.out.println("Don't use yet"); if(this.SwimUnPhys) return null; @@ -859,6 +657,7 @@ public double[] AdaptiveSwimRho(double radius, double accuracy) { * @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]; ZSwimStopper stopper = new ZSwimStopper(Z, dir); @@ -895,6 +694,7 @@ public void setSwimTraj(SwimTrajectory swimTraj) { this.swimTraj = swimTraj; } + @Override public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track double[] value = new double[6]; diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java new file mode 100644 index 0000000000..3bbe6118e9 --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java @@ -0,0 +1,217 @@ +package org.jlab.clas.swimtools; + +import org.apache.commons.math3.util.FastMath; + +/** + * + * @author baltzell + */ +public class SwimPars { + + final double SWIMZMINMOM = 0.75; // GeV/c + final double MINTRKMOM = 0.05; // GeV/c + + double _x0; + double _y0; + double _z0; + double _phi; + double _theta; + double _pTot; + final double _rMax = 5 + 3; + double _maxPathLength = 9; + boolean SwimUnPhys = false; //Flag to indicate if track is swimmable + int _charge; + double accuracy = 20e-6; // 20 microns + public double stepSize = 5.00 * 1.e-4; // 500 microns + public double distanceBetweenSaves= 100*stepSize; + + ProbeCollection PC; + + /** + * Set max swimming path length + * + * @param _maxPathLength + */ + public void setMaxPathLength(double _maxPathLength) { + this._maxPathLength = _maxPathLength; + } + + /** + * + * @param direction +1 for out -1 for in + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) + * @param thx (units?) + * @param thy (units?) + * @param p (units?) + * @param charge + */ + public void SetSwimParameters(int direction, double x0, double y0, double z0, + double thx, double thy, double p, int charge) { + _x0 = x0 / 100; // convert to meters + _y0 = y0 / 100; + _z0 = z0 / 100; + this.checkR(_x0, _y0, _z0); + double pz = direction * p / Math.sqrt(thx * thx + thy * thy + 1); + double px = thx * pz; + double py = thy * pz; + _phi = Math.toDegrees(FastMath.atan2(py, px)); + _pTot = Math.sqrt(px * px + py * py + pz * pz); + _theta = Math.toDegrees(Math.acos(pz / _pTot)); + _charge = direction * charge; + } + + /** + * Sets the parameters used by swimmer based on the input track state vector + * parameters swimming outwards + * + * // z at a given DC plane in the tilted coordinate system + * + * @param superlayerIdx + * @param layerIdx + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) + * @param thx + * @param thy + * @param p + * @param charge + */ + public void SetSwimParameters(int superlayerIdx, int layerIdx, + double x0, double y0, double z0, + double thx, double thy, double p, int charge) { + _x0 = x0 / 100; // convert to meters + _y0 = y0 / 100; + _z0 = z0 / 100; + this.checkR(_x0, _y0, _z0); + double pz = p / Math.sqrt(thx * thx + thy * thy + 1); + double px = thx * pz; + double py = thy * pz; + _phi = Math.toDegrees(FastMath.atan2(py, px)); + _pTot = Math.sqrt(px * px + py * py + pz * pz); + _theta = Math.toDegrees(Math.acos(pz / _pTot)); + _charge = charge; + } + + /** + * Sets the parameters used by swimmer based on the input track parameters + * + * @param x0 (cm) + * @param y0 (cm) + * @param z0 (cm) + * @param px + * @param py + * @param pz + * @param charge + */ + public void SetSwimParameters(double x0, double y0, double z0, + double px, double py, double pz, int charge) { + _x0 = x0 / 100; // convert to meters + _y0 = y0 / 100; + _z0 = z0 / 100; + this.checkR(_x0, _y0, _z0); + _phi = Math.toDegrees(FastMath.atan2(py, px)); + _pTot = Math.sqrt(px * px + py * py + pz * pz); + _theta = Math.toDegrees(Math.acos(pz / _pTot)); + _charge = charge; + } + + /** + * + * @param xcm + * @param ycm + * @param zcm + * @param phiDeg + * @param thetaDeg + * @param p + * @param charge + * @param maxPathLength + */ + public void SetSwimParameters(double xcm, double ycm, double zcm, + double phiDeg, double thetaDeg, + double p, int charge, double maxPathLength) { + _maxPathLength = maxPathLength; + _charge = charge; + _phi = phiDeg; + _theta = thetaDeg; + _pTot = p; + _x0 = xcm / 100; + _y0 = ycm / 100; + _z0 = zcm / 100; + this.checkR(_x0, _y0, _z0); + } + + /** + * + * @param xcm + * @param ycm + * @param zcm + * @param phiDeg + * @param thetaDeg + * @param p + * @param charge + * @param maxPathLength + * @param Accuracy + * @param StepSize + */ + public void SetSwimParameters(double xcm, double ycm, double zcm, + double phiDeg, double thetaDeg, + double p, int charge, + double maxPathLength, double Accuracy, double StepSize) { + _maxPathLength = maxPathLength; + accuracy = Accuracy/100; + stepSize = StepSize/100; + _charge = charge; + _phi = phiDeg; + _theta = thetaDeg; + _pTot = p; + _x0 = xcm / 100; + _y0 = ycm / 100; + _z0 = zcm / 100; + this.checkR(_x0, _y0, _z0); + } + + /** + * + * @param sector + * @param x_cm + * @param y_cm + * @param z_cm + * @param result B field components in T in the tilted sector system + */ + public void Bfield(int sector, double x_cm, double y_cm, double z_cm, float[] result) { + PC.RCP.field(sector, (float) x_cm, (float) y_cm, (float) z_cm, result); + result[0] = result[0] / 10; + result[1] = result[1] / 10; + result[2] = result[2] / 10; + } + + /** + * + * @param x_cm + * @param y_cm + * @param z_cm + * @param result B field components in T in the lab frame + */ + public void BfieldLab(double x_cm, double y_cm, double z_cm, float[] result) { + PC.CP.field((float) x_cm, (float) y_cm, (float) z_cm, result); + result[0] = result[0] / 10; + result[1] = result[1] / 10; + result[2] = result[2] / 10; + } + + /** + * + * @param _x0 + * @param _y0 + * @param _z0 + */ + private void checkR(double _x0, double _y0, double _z0) { + this.SwimUnPhys=false; + if(Math.sqrt(_x0*_x0 + _y0*_y0)>this._rMax || + Math.sqrt(_x0*_x0 + _y0*_y0 + _z0*_z0)>this._maxPathLength) + this.SwimUnPhys=true; + } + +} From c6a894c44fde913b2f11e19ed92a1c8431969456 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 15:18:25 -0500 Subject: [PATCH 09/24] cleanup --- .../src/main/java/org/jlab/clas/swimtools/SwimPars.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java index 3bbe6118e9..ab61c74743 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java @@ -2,10 +2,6 @@ import org.apache.commons.math3.util.FastMath; -/** - * - * @author baltzell - */ public class SwimPars { final double SWIMZMINMOM = 0.75; // GeV/c From d287ca39aa4584b5c0890b9a373ecfa30cbdc801 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 15:20:56 -0500 Subject: [PATCH 10/24] add new swim wrapper placeholder --- .../java/org/jlab/clas/swimtools/Swim2.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java new file mode 100644 index 0000000000..d9d31a6a15 --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java @@ -0,0 +1,90 @@ +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; + +public class Swim2 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[] SwimToPlaneLab(double z_cm) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToCylinder(double Rad) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimRho(double radius, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToSphere(double Rad) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToBeamLine(double xB, double yB) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToLine(Line3D l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] AdaptiveSwimRho(double radius, double accuracy) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToZ(double Z, int dir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToDCA(SwimTrajectory trk2) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} From 8b9d79c7c17ff85f35f34891bced43c493228002 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 15:47:20 -0500 Subject: [PATCH 11/24] remove unused interface methods --- .../java/org/jlab/clas/swimtools/ISwim.java | 7 - .../java/org/jlab/clas/swimtools/Swim.java | 134 +++++++++--------- .../java/org/jlab/clas/swimtools/Swim2.java | 17 +-- 3 files changed, 67 insertions(+), 91 deletions(-) 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 409f529497..b5f469d665 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 @@ -6,7 +6,6 @@ import org.jlab.geom.prim.Vector3D; /** - * Warning, lots of these should probably be removed! * * @author baltzell */ @@ -34,12 +33,6 @@ interface ISwim { public double[] SwimToLine(Line3D l); - public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy); - - public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy); - - public double[] AdaptiveSwimRho(double radius, double accuracy); - 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 f0816bfd00..d92e9c84f1 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 @@ -539,7 +539,73 @@ public double[] SwimToLine(Line3D l) { return value; } + /** + * + * @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]; + 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; + } + + private SwimTrajectory swimTraj; + + /** + * @return the swimTraj + */ + public SwimTrajectory getSwimTraj() { + return swimTraj; + } + + /** + * @param swimTraj the swimTraj to set + */ + public void setSwimTraj(SwimTrajectory swimTraj) { + this.swimTraj = swimTraj; + } + + @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; + } + + public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { if (this.SwimUnPhys) return null; @@ -577,7 +643,6 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do return value; } - @Override public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { if (this.SwimUnPhys) return null; @@ -618,7 +683,6 @@ public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double return value; } - @Override public double[] AdaptiveSwimRho(double radius, double accuracy) { System.out.println("Don't use yet"); if(this.SwimUnPhys) return null; @@ -650,70 +714,4 @@ public double[] AdaptiveSwimRho(double radius, double accuracy) { } return value; } - - /** - * - * @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]; - 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; - } - - private SwimTrajectory swimTraj; - - /** - * @return the swimTraj - */ - public SwimTrajectory getSwimTraj() { - return swimTraj; - } - - /** - * @param swimTraj the swimTraj to set - */ - public void setSwimTraj(SwimTrajectory swimTraj) { - this.swimTraj = swimTraj; - } - - @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; - } } \ No newline at end of file diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java index d9d31a6a15..be2b2ba8f2 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java @@ -62,21 +62,6 @@ public double[] SwimToLine(Line3D l) { throw new UnsupportedOperationException("Not supported yet."); } - @Override - public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] AdaptiveSwimRho(double radius, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - @Override public double[] SwimToZ(double Z, int dir) { throw new UnsupportedOperationException("Not supported yet."); @@ -86,5 +71,5 @@ public double[] SwimToZ(double Z, int dir) { public double[] SwimToDCA(SwimTrajectory trk2) { throw new UnsupportedOperationException("Not supported yet."); } - + } From d423ccd9a09bab4abb4e1ec0b3c0cd3a2d406d6b Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:06:57 -0500 Subject: [PATCH 12/24] move it upstream --- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 10 ++-------- .../main/java/org/jlab/clas/swimtools/SwimPars.java | 8 ++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) 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 d92e9c84f1..9d039c7e80 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 @@ -28,20 +28,14 @@ import org.jlab.clas.swimtools.Stoppers.ZSwimStopper; /** + * Class for swimming to various surfaces. The input and output units are cm and GeV/c * * @author ziegler */ public class Swim extends SwimPars implements ISwim { - /** - * Class for swimming to various surfaces. The input and output units are cm and GeV/c - */ public Swim() { - PC = Swimmer.getProbeCollection(Thread.currentThread()); - if (PC == null) { - PC = new ProbeCollection(); - Swimmer.put(Thread.currentThread(), PC); - } + super(); } /** diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java index ab61c74743..d148440f75 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java @@ -23,6 +23,14 @@ public class SwimPars { ProbeCollection PC; + public SwimPars() { + PC = Swimmer.getProbeCollection(Thread.currentThread()); + if (PC == null) { + PC = new ProbeCollection(); + Swimmer.put(Thread.currentThread(), PC); + } + } + /** * Set max swimming path length * From d195e8ee94c178c8b0677408002d0b13fdf6095b Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:32:53 -0500 Subject: [PATCH 13/24] fix units --- .../java/org/jlab/clas/swimtools/SwimPars.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java index d148440f75..d0fadb882c 100644 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/SwimPars.java @@ -46,9 +46,9 @@ public void setMaxPathLength(double _maxPathLength) { * @param x0 (cm) * @param y0 (cm) * @param z0 (cm) - * @param thx (units?) - * @param thy (units?) - * @param p (units?) + * @param thx + * @param thy + * @param p (GeV) * @param charge */ public void SetSwimParameters(int direction, double x0, double y0, double z0, @@ -79,7 +79,7 @@ public void SetSwimParameters(int direction, double x0, double y0, double z0, * @param z0 (cm) * @param thx * @param thy - * @param p + * @param p (GeV) * @param charge */ public void SetSwimParameters(int superlayerIdx, int layerIdx, @@ -104,9 +104,9 @@ public void SetSwimParameters(int superlayerIdx, int layerIdx, * @param x0 (cm) * @param y0 (cm) * @param z0 (cm) - * @param px - * @param py - * @param pz + * @param px (GeV) + * @param py (GeV) + * @param pz (GeV) * @param charge */ public void SetSwimParameters(double x0, double y0, double z0, @@ -128,7 +128,7 @@ public void SetSwimParameters(double x0, double y0, double z0, * @param zcm * @param phiDeg * @param thetaDeg - * @param p + * @param p (GeV) * @param charge * @param maxPathLength */ @@ -153,7 +153,7 @@ public void SetSwimParameters(double xcm, double ycm, double zcm, * @param zcm * @param phiDeg * @param thetaDeg - * @param p + * @param p (GeV) * @param charge * @param maxPathLength * @param Accuracy From c9587af38437a2f063e0e16afbc030e9bf46d9de Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:33:51 -0500 Subject: [PATCH 14/24] cleanup --- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 4 ---- 1 file changed, 4 deletions(-) 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 9d039c7e80..a371d989e0 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 @@ -34,10 +34,6 @@ */ public class Swim extends SwimPars implements ISwim { - public Swim() { - super(); - } - /** * * @param sector From 9799685f63e5c80a9085e5031b8a5727d87c7f55 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:54:25 -0500 Subject: [PATCH 15/24] move adaptive methods to new wrapper --- .../org/jlab/clas/swimtools/AdaptiveSwim.java | 183 ++++++++++++++++++ .../java/org/jlab/clas/swimtools/Swim.java | 148 ++------------ .../java/org/jlab/clas/swimtools/Swim2.java | 75 ------- 3 files changed, 199 insertions(+), 207 deletions(-) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java delete mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java 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 new file mode 100644 index 0000000000..96e87b3ee9 --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java @@ -0,0 +1,183 @@ +package org.jlab.clas.swimtools; + +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; + +import cnuphys.adaptiveSwim.geometry.Line; +import cnuphys.adaptiveSwim.geometry.Point; +import cnuphys.adaptiveSwim.geometry.Vector; + +import cnuphys.adaptiveSwim.AdaptiveSwimException; +import cnuphys.adaptiveSwim.AdaptiveSwimResult; +import cnuphys.adaptiveSwim.AdaptiveSwimmer; + +import cnuphys.swim.SwimTrajectory; + +public class AdaptiveSwim 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[] SwimToPlaneLab(double z_cm) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToCylinder(double radius) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimRho(double radius, double accuracy) { + + double[] value = new double[8]; + + // convert to meters: + radius = radius/100; + + try { + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, + accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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 + } + else { + return null; + } + } catch (AdaptiveSwimException e) { + e.printStackTrace(); + } + return value; + } + + public static Point dog(Point3D p) { + return new Point(p.x(), p.y(), p.z()); + } + + @Override + public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { + + double[] value = new double[8]; + + // convert to meters: + radius = radius/100; + Point a1 = new Point(axisPoint1.x()/100, axisPoint1.y()/100, axisPoint1.z()/100); + Point a2 = new Point(axisPoint2.x()/100, axisPoint2.y()/100, axisPoint2.z()/100); + Line centerLine = new Line(a1, a2); + + cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius); + + try { + + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder, + accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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 + } + else { + return null; + } + + } catch (AdaptiveSwimException e) { + e.printStackTrace(); + } + return value; + } + + @Override + public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { + + double[] value = new double[8]; + + // convert to meters: + Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z()); + Point point = new Point(p.x()/100, p.y()/100, p.z()/100); + + cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point); + + try { + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane, + accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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 + } + else { + return null; + } + + } catch (AdaptiveSwimException e) { + e.printStackTrace(); + } + return value; + } + + @Override + public double[] SwimToSphere(double Rad) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToBeamLine(double xB, double yB) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToLine(Line3D l) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public double[] SwimToZ(double Z, int dir) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @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/Swim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java index a371d989e0..f3976afccf 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 @@ -13,12 +13,7 @@ import cnuphys.swimZ.SwimZResult; import cnuphys.swimZ.SwimZStateVector; -import cnuphys.adaptiveSwim.AdaptiveSwimException; import cnuphys.adaptiveSwim.AdaptiveSwimResult; -import cnuphys.adaptiveSwim.AdaptiveSwimmer; -import cnuphys.adaptiveSwim.geometry.Line; -import cnuphys.adaptiveSwim.geometry.Point; -import cnuphys.adaptiveSwim.geometry.Vector; import org.jlab.clas.swimtools.Stoppers.BeamLineSwimStopper; import org.jlab.clas.swimtools.Stoppers.CylindricalBoundarySwimStopper; @@ -34,6 +29,22 @@ */ public class Swim extends SwimPars implements ISwim { + private SwimTrajectory swimTraj; + + /** + * @return the swimTraj + */ + public SwimTrajectory getSwimTraj() { + return swimTraj; + } + + /** + * @param swimTraj the swimTraj to set + */ + public void setSwimTraj(SwimTrajectory swimTraj) { + this.swimTraj = swimTraj; + } + /** * * @param sector @@ -556,22 +567,6 @@ public double[] SwimToZ(double Z, int dir) { return value; } - private SwimTrajectory swimTraj; - - /** - * @return the swimTraj - */ - public SwimTrajectory getSwimTraj() { - return swimTraj; - } - - /** - * @param swimTraj the swimTraj to set - */ - public void setSwimTraj(SwimTrajectory swimTraj) { - this.swimTraj = swimTraj; - } - @Override public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca for each track @@ -584,124 +579,13 @@ public double[] SwimToDCA(SwimTrajectory trk2) { //use for both traj to get doca 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; - } - - - public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, double ny, double nz, double accuracy) { - - if (this.SwimUnPhys) return null; - - double[] value = new double[8]; - - Vector norm = new Vector(nx,ny,nz); - Point point = new Point(px/100,py/100,pz/100); - - cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point); - - try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane, - accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } - - } catch (AdaptiveSwimException e) { - e.printStackTrace(); - } return value; } - - public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double a2x, double a2y, double a2z, double radius, double accuracy) { - - if (this.SwimUnPhys) return null; - - double[] value = new double[8]; - - radius = radius/100; - Point a1 = new Point(a1x/100, a1y/100, a1z/100); - Point a2 = new Point(a2x/100, a2y/100, a2z/100); - Line centerLine = new Line(a1, a2); - - cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius); - - try { - - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder, - accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } - - } catch (AdaptiveSwimException e) { - e.printStackTrace(); - } - return value; - } - - public double[] AdaptiveSwimRho(double radius, double accuracy) { - System.out.println("Don't use yet"); - if(this.SwimUnPhys) return null; - - double[] value = new double[8]; - - radius = radius/100; - try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); - - PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, - accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } - } catch (AdaptiveSwimException e) { - e.printStackTrace(); - } - return value; - } } \ No newline at end of file diff --git a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java deleted file mode 100644 index be2b2ba8f2..0000000000 --- a/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim2.java +++ /dev/null @@ -1,75 +0,0 @@ -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; - -public class Swim2 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[] SwimToPlaneLab(double z_cm) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToCylinder(double Rad) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimRho(double radius, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToSphere(double Rad) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToBeamLine(double xB, double yB) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToLine(Line3D l) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToZ(double Z, int dir) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public double[] SwimToDCA(SwimTrajectory trk2) { - throw new UnsupportedOperationException("Not supported yet."); - } - -} From 1d40f95c09028c71b57ecec9ddf5c618d85cd922 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:56:48 -0500 Subject: [PATCH 16/24] remove unused method --- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 9 --------- 1 file changed, 9 deletions(-) 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 f3976afccf..97a21f089b 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 @@ -274,15 +274,6 @@ public double[] SwimToCylinder(double Rad) { return value; } - /** - * - * @param radius in cm - * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface - */ - public double[] SwimRho(double radius) { - return SwimRho(radius, accuracy*100); - } - /** * * @param radius in cm From f5d6d6555d53c6e4e72b6c511977e02a7c510569 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 16:59:23 -0500 Subject: [PATCH 17/24] remove unused method --- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 11 ----------- 1 file changed, 11 deletions(-) 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 97a21f089b..cc14ce3f66 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 @@ -309,17 +309,6 @@ public double[] SwimRho(double radius, double accuracy) { return value; } - /** - * - * @param axisPoint1 in cm - * @param axisPoint2 in cm - * @param radius in cm - * @return swam trajectory to the cylinder - */ - public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius) { - return SwimGenCylinder(axisPoint1, axisPoint2, radius, accuracy*100); - } - /** * * @param axisPoint1 in cm From 9b25e455001867d5367bf7bdfe8e97dc4d4cf117 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 17:05:03 -0500 Subject: [PATCH 18/24] cleanup --- .../src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java | 4 ---- 1 file changed, 4 deletions(-) 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 96e87b3ee9..26d122dbd5 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 @@ -69,10 +69,6 @@ public double[] SwimRho(double radius, double accuracy) { return value; } - public static Point dog(Point3D p) { - return new Point(p.x(), p.y(), p.z()); - } - @Override public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { From b2412799aea562ccf16643de959640a09373a115 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 17:13:07 -0500 Subject: [PATCH 19/24] cleanup --- .../src/main/java/org/jlab/clas/swimtools/Swim.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 cc14ce3f66..0e43634bb4 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 @@ -249,7 +249,6 @@ public double[] SwimToPlaneLab(double z_cm) { * @param Rad * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface */ - @Override public double[] SwimToCylinder(double Rad) { if (this.SwimUnPhys) return null; @@ -289,7 +288,8 @@ public double[] SwimRho(double radius, double accuracy) { 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); + 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]; From 5da67f5475c3e9122daf17fab445267c7e67ff6e Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 17:13:19 -0500 Subject: [PATCH 20/24] fill in missing methods --- .../src/main/java/org/jlab/clas/swimtools/AdaptiveSwim.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 26d122dbd5..53f8b1d840 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 @@ -28,12 +28,12 @@ public double[] SwimToPlaneTiltSecSysBdlXZPlane(int sector, double z_cm) { @Override public double[] SwimToPlaneLab(double z_cm) { - throw new UnsupportedOperationException("Not supported yet."); + return SwimPlane(new Vector3D(0,0,1), new Point3D(0,0,z_cm), accuracy); } @Override public double[] SwimToCylinder(double radius) { - throw new UnsupportedOperationException("Not supported yet."); + return SwimGenCylinder(new Point3D(0,0,-1), new Point3D(0,0,1), radius, accuracy); } @Override @@ -168,7 +168,7 @@ public double[] SwimToLine(Line3D l) { @Override public double[] SwimToZ(double Z, int dir) { - throw new UnsupportedOperationException("Not supported yet."); + return SwimPlane(new Vector3D(0,0,dir*1), new Point3D(0,0,Z), accuracy); } @Override From 2c596eeed84010efd6858f9092f89f71cbcf482a Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 17:26:43 -0500 Subject: [PATCH 21/24] generalize --- .../java/org/jlab/clas/swimtools/ASwim.java | 37 +++++++++++++++++++ .../org/jlab/clas/swimtools/AdaptiveSwim.java | 27 +------------- .../java/org/jlab/clas/swimtools/Swim.java | 2 +- 3 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java 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 new file mode 100644 index 0000000000..592d38be85 --- /dev/null +++ b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/ASwim.java @@ -0,0 +1,37 @@ +package org.jlab.clas.swimtools; + +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; + +/** + * + * @author baltzell + */ +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[] 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[] SwimToZ(double Z, int dir) { + return SwimPlane(new Vector3D(0,0,dir*1), new Point3D(0,0,Z), 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 53f8b1d840..71829d4740 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 @@ -14,27 +14,7 @@ import cnuphys.swim.SwimTrajectory; -public class AdaptiveSwim 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[] 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); - } +public class AdaptiveSwim extends ASwim { @Override public double[] SwimRho(double radius, double accuracy) { @@ -166,11 +146,6 @@ public double[] SwimToLine(Line3D l) { throw new UnsupportedOperationException("Not supported yet."); } - @Override - public double[] SwimToZ(double Z, int dir) { - return SwimPlane(new Vector3D(0,0,dir*1), new Point3D(0,0,Z), accuracy); - } - @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/Swim.java b/common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java index 0e43634bb4..cfe18bc05f 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 @@ -27,7 +27,7 @@ * * @author ziegler */ -public class Swim extends SwimPars implements ISwim { +public class Swim extends ASwim { private SwimTrajectory swimTraj; From cea7463493e6fd420d8a297a701f556cf2f475d2 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 17:48:35 -0500 Subject: [PATCH 22/24] fill in more adapative methods --- .../java/org/jlab/clas/swimtools/ASwim.java | 13 ++- .../org/jlab/clas/swimtools/AdaptiveSwim.java | 80 ++++++++++++++++--- 2 files changed, 79 insertions(+), 14 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 592d38be85..49c96bcbfd 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 @@ -1,10 +1,11 @@ package org.jlab.clas.swimtools; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; /** - * + * * @author baltzell */ public abstract class ASwim extends SwimPars implements ISwim { @@ -19,6 +20,11 @@ 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."); + } + @Override public double[] SwimToPlaneLab(double z_cm) { 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) { return SwimPlane(new Vector3D(0,0,dir*1), new Point3D(0,0,Z), accuracy); } + @Override + public double[] SwimToBeamLine(double xB, double yB) { + return SwimToLine(new Line3D(xB,yB,-1,xB,yB,1)); + } + } 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 71829d4740..bea6ff133b 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 @@ -7,10 +7,13 @@ import cnuphys.adaptiveSwim.geometry.Line; import cnuphys.adaptiveSwim.geometry.Point; import cnuphys.adaptiveSwim.geometry.Vector; +import cnuphys.adaptiveSwim.geometry.Sphere; +import cnuphys.adaptiveSwim.geometry.Cylinder; import cnuphys.adaptiveSwim.AdaptiveSwimException; import cnuphys.adaptiveSwim.AdaptiveSwimResult; import cnuphys.adaptiveSwim.AdaptiveSwimmer; +import cnuphys.adaptiveSwim.geometry.Plane; import cnuphys.swim.SwimTrajectory; @@ -60,8 +63,8 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r Point a2 = new Point(axisPoint2.x()/100, axisPoint2.y()/100, axisPoint2.z()/100); Line centerLine = new Line(a1, a2); - cnuphys.adaptiveSwim.geometry.Cylinder targetCylinder = new cnuphys.adaptiveSwim.geometry.Cylinder(centerLine, radius); - + Cylinder targetCylinder = new Cylinder(centerLine, radius); + try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); @@ -98,7 +101,7 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z()); Point point = new Point(p.x()/100, p.y()/100, p.z()/100); - cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(norm, point); + Plane targetPlane = new Plane(norm, point); try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); @@ -128,22 +131,73 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { @Override public double[] SwimToSphere(double Rad) { - throw new UnsupportedOperationException("Not supported yet."); - } - @Override - public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { - throw new UnsupportedOperationException("Not supported yet."); - } + double[] value = new double[8]; - @Override - public double[] SwimToBeamLine(double xB, double yB) { - throw new UnsupportedOperationException("Not supported yet."); + // convert to meters: + + Sphere targetSphere = new Sphere(new Point(0,0,0), Rad/100); + + try { + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + PC.AS.swimSphere(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetSphere, + accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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 + } + else { + return null; + } + + } catch (AdaptiveSwimException e) { + e.printStackTrace(); + } + return value; } @Override public double[] SwimToLine(Line3D l) { - throw new UnsupportedOperationException("Not supported yet."); + + double[] value = new double[8]; + + // convert to meters: + Point a1 = new Point(l.origin().x()/100, l.origin().y()/100, l.origin().z()/100); + Point a2 = new Point(l.end().x()/100, l.end().y()/100, l.end().z()/100); + Line targetLine = new Line(a1, a2); + + try { + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + PC.AS.swimLine(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetLine, + accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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 + } + else { + return null; + } + + } catch (AdaptiveSwimException e) { + e.printStackTrace(); + } + return value; } @Override From e2cb4fab7061dbee47565b45f6fb1dae4d71665e Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 18:38:45 -0500 Subject: [PATCH 23/24] cleanup --- .../org/jlab/clas/swimtools/AdaptiveSwim.java | 115 +++++------------- 1 file changed, 30 insertions(+), 85 deletions(-) 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 bea6ff133b..f5f9fc32be 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 @@ -19,11 +19,25 @@ public class AdaptiveSwim extends ASwim { + private static double[] convert(AdaptiveSwimResult result, double p) { + double[] value = null; + if (result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { + 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] * p; // normalized values + value[4] = result.getUf()[4] * p; + value[5] = result.getUf()[5] * p; + value[6] = result.getFinalS() * 100; + value[7] = 0; // Conversion from kG.m to T.cm + } + return value; + } + @Override public double[] SwimRho(double radius, double accuracy) { - double[] value = new double[8]; - // convert to meters: radius = radius/100; @@ -33,30 +47,17 @@ public double[] SwimRho(double radius, double accuracy) { PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } + return convert(result, _pTot); + } catch (AdaptiveSwimException e) { e.printStackTrace(); } - return value; + return null; } @Override public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { - double[] value = new double[8]; - // convert to meters: radius = radius/100; 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 Cylinder targetCylinder = new Cylinder(centerLine, radius); try { - AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } + return convert(result, _pTot); } catch (AdaptiveSwimException e) { e.printStackTrace(); } - return value; + return null; } @Override public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { - double[] value = new double[8]; - // convert to meters: Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z()); Point point = new Point(p.x()/100, p.y()/100, p.z()/100); @@ -108,34 +94,19 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + return convert(result, _pTot); - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } - } catch (AdaptiveSwimException e) { e.printStackTrace(); } - return value; + return null; } @Override public double[] SwimToSphere(double Rad) { - double[] value = new double[8]; - // convert to meters: - Sphere targetSphere = new Sphere(new Point(0,0,0), Rad/100); try { @@ -143,32 +114,18 @@ public double[] SwimToSphere(double Rad) { PC.AS.swimSphere(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetSphere, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + + return convert(result, _pTot); - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } - } catch (AdaptiveSwimException e) { e.printStackTrace(); } - return value; + return null; } @Override public double[] SwimToLine(Line3D l) { - double[] value = new double[8]; - // convert to meters: Point a1 = new Point(l.origin().x()/100, l.origin().y()/100, l.origin().z()/100); 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) { PC.AS.swimLine(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetLine, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - - if(result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { - 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 - } - else { - return null; - } + + return convert(result, _pTot); } catch (AdaptiveSwimException e) { e.printStackTrace(); } - return value; + return null; } @Override From 81580ffe23bc719954f941789183bcac8421c6c1 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 23 Dec 2025 18:43:14 -0500 Subject: [PATCH 24/24] cleanup --- .../org/jlab/clas/swimtools/AdaptiveSwim.java | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) 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 f5f9fc32be..073a88891e 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 @@ -20,7 +20,9 @@ public class AdaptiveSwim extends ASwim { private static double[] convert(AdaptiveSwimResult result, double p) { + double[] value = null; + if (result.getStatus() == AdaptiveSwimmer.SWIM_SUCCESS) { value = new double[8]; value[0] = result.getUf()[0] * 100; // convert back to cm @@ -32,6 +34,7 @@ private static double[] convert(AdaptiveSwimResult result, double p) { value[6] = result.getFinalS() * 100; value[7] = 0; // Conversion from kG.m to T.cm } + return value; } @@ -43,13 +46,11 @@ public double[] SwimRho(double radius, double accuracy) { try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - return convert(result, _pTot); - - } catch (AdaptiveSwimException e) { + } + catch (AdaptiveSwimException e) { e.printStackTrace(); } return null; @@ -62,19 +63,15 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r radius = radius/100; Point a1 = new Point(axisPoint1.x()/100, axisPoint1.y()/100, axisPoint1.z()/100); Point a2 = new Point(axisPoint2.x()/100, axisPoint2.y()/100, axisPoint2.z()/100); - Line centerLine = new Line(a1, a2); - - Cylinder targetCylinder = new Cylinder(centerLine, radius); + Cylinder targetCylinder = new Cylinder(new Line(a1,a2), radius); try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.AS.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetCylinder, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - return convert(result, _pTot); - - } catch (AdaptiveSwimException e) { + } + catch (AdaptiveSwimException e) { e.printStackTrace(); } return null; @@ -86,18 +83,15 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { // convert to meters: Vector norm = new Vector(n.asUnit().x(), n.asUnit().y(), n.asUnit().z()); Point point = new Point(p.x()/100, p.y()/100, p.z()/100); - Plane targetPlane = new Plane(norm, point); try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.AS.swimPlane(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetPlane, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - return convert(result, _pTot); - - } catch (AdaptiveSwimException e) { + } + catch (AdaptiveSwimException e) { e.printStackTrace(); } return null; @@ -111,13 +105,11 @@ public double[] SwimToSphere(double Rad) { try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.AS.swimSphere(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetSphere, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - return convert(result, _pTot); - - } catch (AdaptiveSwimException e) { + } + catch (AdaptiveSwimException e) { e.printStackTrace(); } return null; @@ -130,16 +122,14 @@ public double[] SwimToLine(Line3D l) { Point a1 = new Point(l.origin().x()/100, l.origin().y()/100, l.origin().z()/100); Point a2 = new Point(l.end().x()/100, l.end().y()/100, l.end().z()/100); Line targetLine = new Line(a1, a2); - + try { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.AS.swimLine(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, targetLine, accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); - return convert(result, _pTot); - - } catch (AdaptiveSwimException e) { + } + catch (AdaptiveSwimException e) { e.printStackTrace(); } return null;