Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 {

@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.");
}

@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);
}

@Override
public double[] SwimToBeamLine(double xB, double yB) {
return SwimToLine(new Line3D(xB,yB,-1,xB,yB,1));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
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.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;

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) {

// 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);
return convert(result, _pTot);
}
catch (AdaptiveSwimException e) {
e.printStackTrace();
}
return null;
}

@Override
public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) {

// 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);
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) {
e.printStackTrace();
}
return null;
}

@Override
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) {
e.printStackTrace();
}
return null;
}

@Override
public double[] SwimToSphere(double Rad) {

// 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);
return convert(result, _pTot);
}
catch (AdaptiveSwimException e) {
e.printStackTrace();
}
return null;
}

@Override
public double[] SwimToLine(Line3D l) {

// 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);
return convert(result, _pTot);
}
catch (AdaptiveSwimException e) {
e.printStackTrace();
}
return null;
}

@Override
public double[] SwimToDCA(SwimTrajectory trk2) {
throw new UnsupportedOperationException("Not supported yet.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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;

/**
*
* @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);

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[] SwimToZ(double Z, int dir);

public double[] SwimToDCA(SwimTrajectory trk2);

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,16 +15,14 @@

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;

public MagFieldsEngine() {
super("MagFields", "ziegler", "1.0");
}

AtomicInteger Run = new AtomicInteger(0);

/**
* Choose one of YAML or ENV values.
*
Expand Down Expand Up @@ -57,97 +56,87 @@ 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;
}

// Field Shifts
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;
Expand All @@ -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));
}
Expand Down
Loading