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