Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions common-tools/cnuphys/clas12-swimmer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>cnuphys</groupId>
<artifactId>clas12</artifactId>
<version>14.1.2-SNAPSHOT</version>
</parent>

<artifactId>clas12-swimmer</artifactId>
<name>Experimental Commons Math CLAS12 Swimmer</name>

<properties>
<skipTests>false</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>cnuphys</groupId>
<artifactId>swimmer</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>cnuphys</groupId>
<artifactId>magfield</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cnuphys.CLAS12Swim;

public class CLAS12BeamlineListener extends CLAS12DOCAListener {

/**
* Create a CLAS12 beamline crossing listener
*
* @param ivals the initial values of the swim
* @param accuracy the accuracy (cm) (on on difference in successive docas)
* @param sMax the final or max path length (cm)
*/
public CLAS12BeamlineListener(CLAS12Values ivals, double accuracy, double sMax) {
super(ivals, accuracy, sMax);
}

@Override
public double doca(double newS, double[] newU) {
return Math.hypot(newU[0], newU[1]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package cnuphys.CLAS12Swim;

/**
* This is an abstract class to be extended by classes that swim to a boundary.
*/

public abstract class CLAS12BoundaryListener extends CLAS12Listener {

// the requested accuracy in cm
protected final double _accuracy;

/**
* Create a CLAS12 boundary crossing listener
*
* @param ivals the initial values of the swim
* @param accuracy the accuracy (cm)
* @param sMax the final or max path length (cm)
*/
public CLAS12BoundaryListener(CLAS12Values ivals, double accuracy, double sMax) {
super(ivals, sMax);
_accuracy = accuracy;
}

/**
* Get the requested accuracy
*
* @return the requested accuracy
*/
public double getAccuracy() {
return _accuracy;
}

/**
* Called when a new step is taken in the ODE solving process.
*
* @param newS The new path length after the step.
* @param newU The new state vector after the step.
* @return A boolean indicating whether to continue (true) or stop (false) the
* integration.
*/
@Override
public boolean newStep(double newS, double[] newU) {
accept(newS, newU);

// have we crossed the boundary? If so the CrossedBoundary method should handle
// the crossing
// and return with the "intersection" set as the last point. The status should
// be set to SWIM_SUCCESS.
if (crossedBoundary(newS, newU)) {
_status = CLAS12Swimmer.SWIM_SUCCESS;
return false;
}

// have we reached the max path length?
if (newS >= _sMax) {
_status = CLAS12Swimmer.SWIM_TARGET_MISSED;
return false;
}

return true;
}

/**
* Get the absolute distance to the target (boundary) in cm.
*
* @param newS the new path length
* @param newU the new state vector
* @return the distance to the target (boundary) in cm.
*/
public abstract double distanceToTarget(double newS, double[] newU);

/**
* Called when a new step is taken in the ODE solving process.
*
* @param newS The new path length after the step.
* @param newU The new state vector after the step.
* @return A boolean indicating whether the requested accuracy has been reached
*/
public abstract boolean accuracyReached(double newS, double[] newU);

/**
* Have we crossed the boundary?
*
* @param newS The new path length after the step.
* @param newU The new state vector after the step.
* @return <code>true</code> if we crossed the boundary, in which case we should
* terminate and interpolate to the intersection.
*/
public abstract boolean crossedBoundary(double newS, double[] newU);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cnuphys.CLAS12Swim;

import cnuphys.CLAS12Swim.geometry.Cylinder;

/**
* A listener for swimming to the surface of a fixed infinite cylinder
*/

public class CLAS12CylinderListener extends CLAS12BoundaryListener {

// the target cylinder
private Cylinder _targetCylinder;

// starting inside or outside
private boolean _inside;

/**
* Create a CLAS12 boundary target cylinder listener, for swimming to a fixed
* infinite cylinder
*
* @param ivals the initial values of the swim
* @param targetCylinder the target infinite cylinder
* @param accuracy the desired accuracy (cm)
* @param sMax the final or max path length (cm)
*/
public CLAS12CylinderListener(CLAS12Values ivals, Cylinder targetCylinder, double accuracy, double sMax) {
super(ivals, accuracy, sMax);
_targetCylinder = targetCylinder;
_inside = _targetCylinder.isInside(ivals.x, ivals.y, ivals.z);
_canMakeStraightLine = false;
}

@Override
public boolean accuracyReached(double newS, double[] newU) {
double dist = _targetCylinder.distance(newU[0], newU[1], newU[2]);
return dist < _accuracy;
}

@Override
public boolean crossedBoundary(double newS, double[] newU) {
boolean newInside = _targetCylinder.isInside(newU[0], newU[1], newU[2]);
return newInside != _inside;
}

/**
* Get the absolute distance to the target (boundary) in cm.
*
* @param newS the new path length
* @param newU the new state vector
* @return the distance to the target (boundary) in cm.
*/
@Override
public double distanceToTarget(double newS, double[] newU) {
return _targetCylinder.distance(newU[0], newU[1], newU[2]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package cnuphys.CLAS12Swim;

/**
* This is an abstract class to be extended by classes that to a distance of
* closest approach. The assumption is that the first doca is the only one. i.e.
* we are not dealing with low energy particles looping about.
*/

public abstract class CLAS12DOCAListener extends CLAS12Listener {

// the requested accuracy in cm
protected final double _accuracy;

// current doca
protected double _currentDOCA = Double.POSITIVE_INFINITY;

/**
* Create a CLAS12 boundary crossing listener
*
* @param ivals the initial values of the swim
* @param accuracy the accuracy (cm)
* @param sMax the final or max path length (cm)
*/
public CLAS12DOCAListener(CLAS12Values ivals, double accuracy, double sMax) {
super(ivals, sMax);
_accuracy = accuracy;
}

/**
* Reset the current DOCA to infinity
*/
@Override
public void reset() {
super.reset();
_currentDOCA = Double.POSITIVE_INFINITY;
}

/**
* Get the requested accuracy (on on difference in successive docas)in cm.
*
* @return the requested accuracy
*/
public double getAccuracy() {
return _accuracy;
}

/**
* Get the current estimate of the doca
*
* @return the current doca
*/
public double getCurrentDOCA() {
return _currentDOCA;
}

/**
* Called when a new step is taken in the ODE solving process.
*
* @param newS The new path length after the step.
* @param newU The new state vector after the step.
* @return A boolean indicating whether to continue (true) or stop (false) the
* integration.
*/
@Override
public boolean newStep(double newS, double[] newU) {
accept(newS, newU);

double doca = doca(newS, newU);

if (doca > _currentDOCA) { // getting farther
_status = CLAS12Swimmer.SWIM_SUCCESS;
return false;
}

// have we reached the max path length?
if (newS >= _sMax) {
_status = CLAS12Swimmer.SWIM_TARGET_MISSED;
return false;
}

_currentDOCA = doca;
return true;
}

/**
* Get the absolute distance to the target (boundary) in cm.
*
* @param newS the new path length
* @param newU the new state vector
* @return the distance to the target (boundary) in cm.
*/
public abstract double doca(double newS, double[] newU);

}
Loading
Loading