From c2f03769ee704e02d990d952403b2e2201d5e5b7 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 22 Oct 2020 15:47:28 +0200 Subject: [PATCH 001/291] imported new adaptive swimRho from D. Heddle swimming developments --- .../java/cnuphys/swim/DefaultRhoStopper.java | 152 ++++++++++++ .../main/java/cnuphys/swim/SwimResult.java | 52 +++++ .../src/main/java/cnuphys/swim/Swimmer.java | 221 ++++++++++++++++++ .../java/org/jlab/clas/swimtools/Swim.java | 70 +++++- 4 files changed, 493 insertions(+), 2 deletions(-) create mode 100644 common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/DefaultRhoStopper.java create mode 100644 common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/SwimResult.java diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/DefaultRhoStopper.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/DefaultRhoStopper.java new file mode 100644 index 000000000..f2efe65d2 --- /dev/null +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/DefaultRhoStopper.java @@ -0,0 +1,152 @@ +package cnuphys.swim; + +import cnuphys.rk4.IStopper; + +/** + * This stopper is to stop at a fixed value of the cylindrical coordinate rho. It can + * also be considered a cylindrical stopper if the cylinder is centered on the z axis. + * @author heddle + * + */ +public class DefaultRhoStopper implements IStopper { + + private double _targetRho; + private double _totS; //total path length + private double _prevS; //previous step path length + private double _maxS; + private double _accuracy; + private double _currentRho = Double.NaN; + private double[] _uf; //final state vector + private double[] _uprev; //last u with the same sign + private double _s0; //starting path length + + private int _dim; //dimension of our system + + private int _startSign; //is starting val bigger or smaller than targ value + + /** + * Rho stopper that doesn't check max R (does check max path length) + * + * @param uo starting state vector + * @param s0 starting path length in meters + * @param sMax maximal path length in meters + * @param targetRho stopping rho in meters + * @param accuracy the accuracy in meters + * @param normalDirection if going smaller to larger rho + */ + public DefaultRhoStopper(double[] uo, double s0, double sMax, double rho0, double targetRho, double accuracy) { + + _s0 = s0; + _dim = uo.length; + + _uf = new double[_dim]; + _uprev = new double[_dim]; + + _targetRho = targetRho; + _totS = 0; + _prevS = 0; + _maxS = sMax; + _accuracy = accuracy; + _startSign = sign(rho0); + } + + //get the sign based on the current rho + private int sign(double currentRho) { + return ((currentRho < _targetRho) ? -1 : 1); + } + + + private void copy(double src[], double[] dest) { + System.arraycopy(src, 0, dest, 0, _dim); + } + + @Override + public boolean stopIntegration(double s, double[] u) { + + _currentRho = Math.hypot(u[0], u[1]); + _totS = s; + + // within accuracy? + if (Math.abs(_currentRho - _targetRho) < _accuracy) { + copy(u, _uf); + return true; + } + + // independent variable s is the path length + if (s > _maxS) { + copy(u, _uf); + return true; + } + + //stop (and backup/reset to prev) if we crossed the boundary + if (sign(_currentRho) != _startSign) { + _totS = _prevS; + copy(_uprev, _uf); + return true; + } + + //copy current to previous + _prevS = _totS; + copy(u, _uprev); + return false; + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _s0 + _totS; + } + + /** + * Is the current rho within accuracy + * + * @param rho current rho + * @param accuracy accuracy + * @return true if current z with accuracy + */ + public boolean withinAccuracy(double rho, double accuracy) { + return Math.abs(rho - _targetRho) < accuracy; + } + + @Override + public void setFinalT(double finalT) { + // Do nothing + } + + /** + * Get the final value of the state vector + * @return + */ + public double[] getFinalU() { + if (_uf == null) { + System.err.println("Returning null final u"); + } + return _uf; + } + /** + * Generally this is the same as stop integration. So most will just return + * stopIntegration(). But sometimes stop just means we reset and integrate more. + * For example, with a fixed rho integrator we "stop" when we cross the rho boundary + * however we are not done unless we are within tolerance. If we are within + * tolerance (on either side) we are really done! + * + * @param t the current value of the independent variable (typically pathlength) + * @param y the current state vector (typically [x, y, z, vx, vy, vz]) + * @return true if we should stop now. + */ + @Override + public boolean terminateIntegration(double t, double y[]) { + boolean stop = Math.abs(_currentRho - _targetRho) < _accuracy; + + if (stop) { + copy(_uf, y); + } + + return stop; + } + +} \ No newline at end of file diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/SwimResult.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/SwimResult.java new file mode 100644 index 000000000..31b18efbf --- /dev/null +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/SwimResult.java @@ -0,0 +1,52 @@ +package cnuphys.swim; + +public class SwimResult { + + //the final state vector + private double[] _uf; + + //the number of integration steps + private int _nStep; + + //the final path length + private double _finalS; + + /** + * Create a container for the swim results + * @param dim the dimension of the system (probably 6) + */ + public SwimResult(int dim) { + _uf = new double[dim]; + } + + public double[] getUf() { + return _uf; + } + + + public void setUf(double[] uf) { + _uf = uf; + } + + + public int getNStep() { + return _nStep; + } + + + public void setNStep(int nStep) { + _nStep = nStep; + } + + + public double getFinalS() { + return _finalS; + } + + + public void setFinalS(double finalS) { + _finalS = finalS; + } + + +} \ No newline at end of file diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java index 02303b19f..326d2771d 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java @@ -276,6 +276,227 @@ public SwimTrajectory swim(int charge, double xo, double yo, double zo, double m return swim(charge, xo, yo, zo, momentum, theta, phi, stopper, maxPathLength, stepSize, distanceBetweenSaves); } + /** + * Swims a particle with a built it stopper for the rho coordinate. + * This does NOT cach the steps, so the result contains only the stopping point. + * along the path. Uses an adaptive stepsize algorithm. + * + * @param charge the charge: -1 for electron, 1 for proton, etc + * @param xo the x vertex position in meters + * @param yo the y vertex position in meters + * @param zo the z vertex position in meters + * @param momentum initial momentum in GeV/c + * @param theta initial polar angle in degrees + * @param phi initial azimuthal angle in degrees + * @param fixedRho the fixed rho value (meters) that terminates (or + * maxPathLength if reached first) + * @param accuracy the accuracy of the fixed z termination, in meters + * @param sMax Max path length in meters. This determines the max number + * of steps based on the step size. If a stopper is used, + * the integration might terminate before all the steps are + * taken. A reasonable value for CLAS is 8. meters + * @param stepSize the initial step size in meters. + * @param relTolerance the error tolerance as fractional diffs. Note it is a + * vector, the same dimension of the problem, e.g., 6 for + * [x,y,z,vx,vy,vz]. It might be something like {1.0e-10, + * 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8, 1.0e-8} + * @param result upon return, results from the swim including the final state vector [x, y, z, px/p, py/p, pz/p] + * @throws RungeKuttaException + */ + public void swimRho(int charge, double xo, double yo, double zo, double momentum, double theta, double phi, + final double fixedRho, double accuracy, double sMax, double stepSize, double relTolerance[], SwimResult result) + throws RungeKuttaException { + // normally we swim from small rho to a larger rho cutoff. + // but we can handle either + + double rho0 = Math.hypot(xo, yo); + // set u to the starting state vector + double thetaRad = Math.toRadians(theta); + double phiRad = Math.toRadians(phi); + double sinTheta = Math.sin(thetaRad); + + result.getUf()[0] = xo; + result.getUf()[1] = yo; + result.getUf()[2] = zo; + result.getUf()[3] = sinTheta*Math.cos(phiRad); //px/p + result.getUf()[4] = sinTheta*Math.sin(phiRad); //py/p + result.getUf()[5] = Math.cos(thetaRad); //pz/p + + + DefaultRhoStopper stopper = new DefaultRhoStopper(result.getUf(), 0, sMax, rho0, fixedRho, accuracy); + + if (momentum < MINMOMENTUM) { + System.err.println("Skipping low momentum fixed rho swim (A)"); + result.setNStep(0); + result.setFinalS(0); + return; + } + + // First try + + int ns = swim(charge, xo, yo, zo, momentum, theta, phi, stopper, null, sMax, stepSize, relTolerance, null); + System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); + + // if we stopped because of max pathlength, we are done (never reached + // target rho) + double finalPathLength = stopper.getFinalT(); + if (finalPathLength > sMax) { + result.setNStep(ns); + result.setFinalS(finalPathLength); + return; + } + + // are we there yet? + double rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); + double del = Math.abs(rholast - fixedRho); + int maxtry = 10; + int count = 0; + + // set the step size to half the accuracy + stepSize = accuracy / 2; + + + while ((count < maxtry) && (del > accuracy)) { + xo = result.getUf()[0]; + yo = result.getUf()[1]; + zo = result.getUf()[2]; + double px = result.getUf()[3]; + double py = result.getUf()[4]; + double pz = result.getUf()[5]; + double rhoCurr = Math.hypot(xo, yo); + + stopper = new DefaultRhoStopper(result.getUf(), finalPathLength, sMax, rhoCurr, fixedRho, accuracy); + + theta = FastMath.acos2Deg(pz); + phi = FastMath.atan2Deg(py, px); + + ns += swim(charge, xo, yo, zo, momentum, theta, phi, stopper, null, sMax, stepSize, relTolerance, null); + + System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); + + finalPathLength = stopper.getFinalT(); + + rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); + del = Math.abs(rholast - fixedRho); + count++; + stepSize /= 2; + } // while + + result.setNStep(ns); + result.setFinalS(finalPathLength); + } + + /** + * Swims a particle with a built it stopper for the rho coordinate. + * This does NOT cach the steps, so the result contains only the stopping point. + * along the path. Uses a fixed stepsize algorithm. + * + * @param charge the charge: -1 for electron, 1 for proton, etc + * @param xo the x vertex position in meters + * @param yo the y vertex position in meters + * @param zo the z vertex position in meters + * @param momentum initial momentum in GeV/c + * @param theta initial polar angle in degrees + * @param phi initial azimuthal angle in degrees + * @param fixedRho the fixed rho value (meters) that terminates (or + * maxPathLength if reached first) + * @param accuracy the accuracy of the fixed z termination, in + * meters + * @param stopper an optional object that can terminate the + * swimming based on some condition + * @param sMax in meters. This determines the max number of + * steps based on the step size. If a stopper is + * used, the integration might terminate before all + * the steps are taken. A reasonable value for CLAS + * is 8. meters + * @param stepSize the uniform step size in meters. + * @param result upon return, results from the swim including the final state vector [x, y, z, px/p, py/p, pz/p] + */ + public void swimRho(int charge, double xo, double yo, double zo, double momentum, double theta, double phi, + final double fixedRho, final double accuracy, double sMax, double stepSize, SwimResult result) { + + // normally we swim from small rho to a larger rho cutoff. + // but we can handle either + + double rho0 = Math.hypot(xo, yo); + + //set u to the starting state vector + double thetaRad = Math.toRadians(theta); + double phiRad = Math.toRadians(phi); + double sinTheta = Math.sin(thetaRad); + + result.getUf()[0] = xo; + result.getUf()[1] = yo; + result.getUf()[2] = zo; + result.getUf()[3] = sinTheta*Math.cos(phiRad); //px/p + result.getUf()[4] = sinTheta*Math.sin(phiRad); //py/p + result.getUf()[5] = Math.cos(thetaRad); //pz/p + + + DefaultRhoStopper stopper = new DefaultRhoStopper(result.getUf(), 0, sMax, rho0, fixedRho, accuracy); + + + if (momentum < MINMOMENTUM) { + System.err.println("Skipping low momentum fixed rho swim (B)"); + result.setNStep(0); + result.setFinalS(0); + return; + } + + // our first attempt + int ns = swim(charge, xo, yo, zo, momentum, theta, phi, stopper, null, sMax, stepSize); + System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); + + // if we stopped because of max pathlength, we are done (never reached + // target rho) + double finalPathLength = stopper.getFinalT(); + + if (finalPathLength > sMax) { + result.setNStep(ns); + result.setFinalS(finalPathLength); + return; + } + + // are we there yet? + double rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); + double del = Math.abs(rholast - fixedRho); + int maxtry = 10; + int count = 0; + + // reduce the step size + stepSize = stepSize / 2; + + while ((count < maxtry) && (del > accuracy)) { + xo = result.getUf()[0]; + yo = result.getUf()[1]; + zo = result.getUf()[2]; + double px = result.getUf()[3]; + double py = result.getUf()[4]; + double pz = result.getUf()[5]; + double rhoCurr = Math.hypot(xo, yo); + + stopper = new DefaultRhoStopper(result.getUf(), finalPathLength, sMax, rhoCurr, fixedRho, accuracy); + + theta = FastMath.acos2Deg(pz); + phi = FastMath.atan2Deg(py, px); + + ns += swim(charge, xo, yo, zo, momentum, theta, phi, stopper, null, sMax, stepSize); + + System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); + + + finalPathLength = stopper.getFinalT(); + + rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); + del = Math.abs(rholast - fixedRho); + count++; + stepSize = stepSize / 2; + } // while + + result.setNStep(ns); + result.setFinalS(finalPathLength); + } + /** * Swims a charged particle. This is for the listener mode, where a callback * is called for each advance of the integration Uses a fixed stepsize 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 4d146ee87..1a3d89c7c 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 @@ -7,6 +7,7 @@ import cnuphys.rk4.IStopper; import cnuphys.rk4.RungeKuttaException; +import cnuphys.swim.SwimResult; import cnuphys.swim.SwimTrajectory; import cnuphys.swim.util.Plane; import cnuphys.swimZ.SwimZException; @@ -36,8 +37,8 @@ public class Swim { final double SWIMZMINMOM = 0.75; // GeV/c final double MINTRKMOM = 0.05; // GeV/c - final double accuracy = 20e-6; // 20 microns - final double stepSize = 5.00 * 1.e-4; // 500 microns + double accuracy = 20e-6; // 20 microns + double stepSize = 5.00 * 1.e-4; // 500 microns private ProbeCollection PC; @@ -163,6 +164,35 @@ public void SetSwimParameters(double xcm, double ycm, double zcm, double phiDeg, } + /** + * + * @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; + + } + public double[] SwimToPlaneTiltSecSys(int sector, double z_cm) { double z = z_cm / 100; // the magfield method uses meters double[] value = new double[8]; @@ -441,6 +471,42 @@ public double[] SwimToCylinder(double Rad) { } + /** + * + * @param radius + * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface + */ + public double[] SwimRho(double radius) { + + double[] value = new double[8]; + + // using adaptive stepsize + if(this.SwimUnPhys) + return null; + + try { + + SwimResult result = new SwimResult(6); + + PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); + + 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) { + e.printStackTrace(); + } + return value; + + } + private class SphericalBoundarySwimStopper implements IStopper { private double _finalPathLength = Double.NaN; From 520467ee9939cc6c9862ecb8b252686ad889304a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 22 Oct 2020 16:54:27 +0200 Subject: [PATCH 002/291] New clas-tracking package --- common-tools/clas-tracking/nbactions.xml | 46 + common-tools/clas-tracking/pom.xml | 44 + .../clas/tracking/kalmanfilter/Surface.java | 144 +++ .../jlab/clas/tracking/kalmanfilter/Type.java | 34 + .../kalmanfilter/helical/KFitter.java | 382 ++++++++ .../kalmanfilter/helical/MeasVecs.java | 222 +++++ .../kalmanfilter/helical/StateVecs.java | 826 ++++++++++++++++++ .../org/jlab/clas/tracking/objects/Cross.java | 135 +++ .../jlab/clas/tracking/objects/Segment.java | 164 ++++ .../org/jlab/clas/tracking/objects/Strip.java | 321 +++++++ .../jlab/clas/tracking/objects/TObject.java | 134 +++ .../tracking/patternrec/CircleHoughTrans.java | 345 ++++++++ .../tracking/patternrec/LineHoughTrans.java | 332 +++++++ .../jlab/clas/tracking/trackrep/Helix.java | 557 ++++++++++++ .../org/jlab/clas/tracking/trackrep/Seed.java | 103 +++ .../clas/tracking/trackrep/Trajectory.java | 63 ++ .../tracking/utilities/OverlapRemover.java | 134 +++ .../utilities/SelectEventsToFile.java | 77 ++ common-tools/coat-lib/pom.xml | 7 + common-tools/pom.xml | 1 + 20 files changed, 4071 insertions(+) create mode 100644 common-tools/clas-tracking/nbactions.xml create mode 100644 common-tools/clas-tracking/pom.xml create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Type.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java diff --git a/common-tools/clas-tracking/nbactions.xml b/common-tools/clas-tracking/nbactions.xml new file mode 100644 index 000000000..708e66a69 --- /dev/null +++ b/common-tools/clas-tracking/nbactions.xml @@ -0,0 +1,46 @@ + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath org.jlab.clas.tracking.trackrep.Helix + java + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath org.jlab.clas.tracking.trackrep.Helix + java + true + + + + profile + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath org.jlab.clas.tracking.trackrep.Helix + java + + + diff --git a/common-tools/clas-tracking/pom.xml b/common-tools/clas-tracking/pom.xml new file mode 100644 index 000000000..43bdf0292 --- /dev/null +++ b/common-tools/clas-tracking/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + org.jlab.clas + clas-tracking + 6.5.11-SNAPSHOT + jar + + + org.jlab.clas + clas12rec + ../../parent/pom.xml + 6.5.11-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + org.jlab.clas + swim-tools + 6.5.11-SNAPSHOT + jar + + + + + 1.8 + 1.8 + + + diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java new file mode 100644 index 000000000..044fabc95 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -0,0 +1,144 @@ +/* + * 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.tracking.kalmanfilter; + +import org.jlab.clas.tracking.objects.Strip; +import org.jlab.geom.prim.Plane3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; + +/** + * + * @author ziegler + */ +public class Surface implements Comparable { + + public Type type; + public Plane3D plane; + public Point3D refPoint; + public Point3D lineEndPoint1; + public Point3D lineEndPoint2; + public Point3D finitePlaneCorner1; + public Point3D finitePlaneCorner2; + public Cylindrical3D cylinder; + public Arc3D arc; + public Strip strip; + private double error; + private int layer; + private int sector; + + public Surface(Plane3D plane3d, Point3D refrPoint, Point3D c1, Point3D c2) { + type = Type.PLANEWITHPOINT; + plane = plane3d; + refPoint = refrPoint; + finitePlaneCorner1 = c1; + finitePlaneCorner2 = c2; + } + public Surface(Plane3D plane3d, Point3D endPoint1, Point3D endPoint2, Point3D c1, Point3D c2) { + type = Type.PLANEWITHLINE; + plane = plane3d; + lineEndPoint1 = endPoint1; + lineEndPoint2 = endPoint2; + finitePlaneCorner1 = c1; + finitePlaneCorner2 = c2; + } + public Surface(Plane3D plane3d, Strip strp, Point3D c1, Point3D c2) { + type = Type.PLANEWITHSTRIP; + plane = plane3d; + strip = strp; + finitePlaneCorner1 = c1; + finitePlaneCorner2 = c2; + lineEndPoint1 = new Point3D(strip.getX(), strip.getY(), strip.getZ()); + lineEndPoint2 = new Point3D(strip.getX()+strip.getLength()*strip.getUx(), + strip.getY()+strip.getLength()*strip.getUy(), + strip.getZ()+strip.getLength()*strip.getUz()); + } + public Surface(Cylindrical3D cylinder3d, Strip strp) { + type = Type.CYLINDERWITHSTRIP; + cylinder = cylinder3d; + strip = strp; + lineEndPoint1 = new Point3D(strip.getX(), strip.getY(), strip.getZ()); + lineEndPoint2 = new Point3D(strip.getX()+strip.getLength()*strip.getUx(), + strip.getY()+strip.getLength()*strip.getUy(), + strip.getZ()+strip.getLength()*strip.getUz()); + } + public Surface(Cylindrical3D cylinder3d, Point3D refrPoint) { + type = Type.CYLINDERWITHPOINT; + cylinder = cylinder3d; + refPoint = refrPoint; + } + public Surface(Cylindrical3D cylinder3d, Point3D endPoint1, Point3D endPoint2) { + type = Type.CYLINDERWITHLINE; + cylinder = cylinder3d; + lineEndPoint1 = endPoint1; + lineEndPoint2 = endPoint2; + } + + /** + * @return the error + */ + public double getError() { + return error; + } + + /** + * @param error the error to set + */ + public void setError(double error) { + this.error = error; + } + + /** + * @return the layer + */ + public int getLayer() { + return layer; + } + + /** + * @param layer the layer to set + */ + public void setLayer(int layer) { + this.layer = layer; + } + + /** + * @return the sector + */ + public int getSector() { + return sector; + } + + /** + * @param sector the sector to set + */ + public void setSector(int sector) { + this.sector = sector; + } + public Surface(Cylindrical3D cylinder3d, Arc3D refArc, + Point3D endPoint1, Point3D endPoint2) { + type = Type.CYLINDERWITHARC; + cylinder = cylinder3d; + arc = refArc; + if(endPoint1 == null) { + lineEndPoint1 = arc.origin(); + } + if(endPoint2 == null) { + lineEndPoint2 = arc.end(); + } + } + + @Override + public int compareTo(Surface o) { + if (this.layer > o.layer) { + return 1; + } else { + return -1; + } + } + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Type.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Type.java new file mode 100644 index 000000000..b1c811304 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Type.java @@ -0,0 +1,34 @@ +/* + * 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.tracking.kalmanfilter; + +/** + * + * @author ziegler + */ +public enum Type { + UDF(-1), PLANEWITHPOINT(0), PLANEWITHLINE(1), PLANEWITHSTRIP(2), + CYLINDERWITHPOINT(3), CYLINDERWITHLINE(4), CYLINDERWITHARC(5), CYLINDERWITHSTRIP(6); + private final int value; + + Type(int value) { + this.value = value; + } + + public byte value() { + return (byte) this.value; + } + + public static Type create(byte value) { + for (Type hp : Type.values()) { + if (hp.value() == value) { + return hp; + } + } + return UDF; + } + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java new file mode 100644 index 000000000..29d898fc8 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -0,0 +1,382 @@ +package org.jlab.clas.tracking.kalmanfilter.helical; + +import java.util.ArrayList; +import java.util.List; + +import java.util.HashMap; +import java.util.Map; + +import org.jlab.geom.prim.Point3D; +import org.jlab.io.base.DataEvent; + +import Jama.Matrix; +import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.Surface; +import org.jlab.clas.tracking.kalmanfilter.helical.StateVecs.StateVec; +import org.jlab.clas.tracking.trackrep.Helix; + +public class KFitter { + + public static int polarity = -1; + + public boolean setFitFailed = true; + + StateVecs sv = new StateVecs(); + + MeasVecs mv = new MeasVecs(); + + public StateVec finalStateVec; + + private double _Xb; + private double _Yb; + private double resiCut = 100;//residual cut for the measurements + public boolean filterOn; + + public void setMeasurements(List measSurfaces) { + mv.setMeasVecs(measSurfaces); + } + + public KFitter(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb, double Yb, + double Zref, List measSurfaces) { + _Xb = Xb; + _Yb = Yb; + this.init(helix, cov, event, swimmer, Xb, Yb, + Zref, mv, measSurfaces); + } + //private Matrix iCov; + public void init(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb, double Yb, + double Zref, MeasVecs mv, List measSurfaces) { + + //iCov = cov; + mv.setMeasVecs(measSurfaces); + if (sv.Layer != null) { + sv.Layer.clear(); + } else { + sv.Layer = new ArrayList(); + } + if (sv.Sector != null) { + sv.Sector.clear(); + } else { + sv.Sector = new ArrayList(); + } + if (sv.X0 != null) { + sv.X0.clear(); + } else { + sv.X0 = new ArrayList(); + } + if (sv.Y0 != null) { + sv.Y0.clear(); + } else { + sv.Y0 = new ArrayList(); + } + if (sv.Z0 != null) { + sv.Z0.clear(); + } else { + sv.Z0 = new ArrayList(); + } + //take first plane along beam line with n = y-dir; + sv.Layer.add(0); + sv.Sector.add(0); + sv.X0.add(Xb); + sv.Y0.add(Yb); + sv.Z0.add(Zref); + for (int i = 1; i < mv.measurements.size(); i++) { + sv.Layer.add(mv.measurements.get(i).layer); + sv.Sector.add(mv.measurements.get(i).sector); + Point3D ref = new Point3D(Xb, Yb, Zref); + sv.X0.add(ref.x()); + sv.Y0.add(ref.y()); + sv.Z0.add(ref.z()); + } + sv.init( helix, cov, this, swimmer); + this.NDF = mv.measurements.size()-6; + } + + /** + * @return the resiCut + */ + public double getResiCut() { + return resiCut; + } + + /** + * @param resiCut the resiCut to set + */ + public void setResiCut(double resiCut) { + this.resiCut = resiCut; + } + + public int totNumIter = 5; + double newChisq = Double.POSITIVE_INFINITY; + + public void runFitter(Swim swimmer) { + if(this.filterOn==false) + totNumIter=2; + double newchisq = Double.POSITIVE_INFINITY; + this.NDF = sv.X0.size()-5; + + for (int it = 0; it < totNumIter; it++) { + this.chi2 = 0; + for (int k = 0; k < sv.X0.size() - 1; k++) { + if (sv.trackCov.get(k) == null || mv.measurements.get(k + 1) == null) { + return; + } + sv.transport(k, k + 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k+1), + swimmer); + this.filter(k + 1, swimmer, 1); + } + + for (int k = sv.X0.size() - 1; k>0 ;k--) { + if (sv.trackCov.get(k) == null || mv.measurements.get(k - 1) == null) { + return; + } + sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), + swimmer); + if(k>1) + this.filter(k - 1, swimmer, -1); + } + + // chi2 + this.chi2=this.calc_chi2(swimmer); + if(this.chi2 TrjPoints = new HashMap(); + + public void setTrajectory() { + TrjPoints.clear(); + for (int k = 1; k < sv.trackTraj.size(); k++) { + int layer = mv.measurements.get(k).layer; + double x = sv.trackTraj.get(k).x; + double y = sv.trackTraj.get(k).y; + double z = sv.trackTraj.get(k).z; + double azi = sv.trackTraj.get(k).phi0 + sv.trackTraj.get(k).phi; + //System.out.println("Trj "+x+","+y+","+z); + double invKappa = 1. / Math.abs(sv.trackTraj.get(k).kappa); + double px = -invKappa * Math.sin(azi); + double py = invKappa * Math.cos(azi); + double pz = invKappa * sv.trackTraj.get(k).tanL; + TrjPoints.put(layer, new HitOnTrack(layer, x, y, z, px, py, pz)); + if(mv.measurements.get(k).skip) + TrjPoints.get(layer).isMeasUsed = false; + //System.out.println(" Traj layer "+layer+" x "+TrjPoints.get(layer).x+" y "+TrjPoints.get(layer).y+" z "+TrjPoints.get(layer).z); + } + } + + + public Helix KFHelix; + + + public double chi2 = 0; + public int NDF = 0; + + private double calc_chi2(Swim swimmer) { + //get the measurement + double m = 0; + //get the projector state + double h = 0; + double chi2 =0; + m=0; + h=0; + int ndf = -5; + StateVec stv = sv.transported(0, 1, sv.trackTraj.get(0), mv.measurements.get(1), swimmer); + double dh = mv.dh(1, stv); + if(mv.measurements.get(1).skip==false) { + chi2 = dh*dh / mv.measurements.get(1).error; + ndf++; + } + for(int k = 1; k< sv.X0.size()-1; k++) { + if(mv.measurements.get(k+1).skip==false) { + stv = sv.transported(k, k+1, stv, mv.measurements.get(k+1), swimmer); + dh = mv.dh(k+1, stv); + chi2 += dh*dh / mv.measurements.get(k+1).error; + ndf++; + } + } + return chi2; + } + + private void filter(int k, Swim swimmer, int dir) { + + if (sv.trackTraj.get(k) != null && sv.trackCov.get(k).covMat != null + && mv.measurements.get(k).skip == false && this.filterOn==true) { + + double[] K = new double[5]; + double V = mv.measurements.get(k).error; + + double dh = mv.dh(k, sv.trackTraj.get(k)); + + //get the projector Matrix + double[] H = new double[5]; + H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), swimmer, dir); + double[][] HTGH = new double[][]{ + {H[0] * H[0] / V, H[0] * H[1] / V, H[0] * H[2] / V, H[0] * H[3] / V, H[0] * H[4] / V}, + {H[1] * H[0] / V, H[1] * H[1] / V, H[1] * H[2] / V, H[1] * H[3] / V, H[1] * H[4] / V}, + {H[2] * H[0] / V, H[2] * H[1] / V, H[2] * H[2] / V, H[2] * H[3] / V, H[2] * H[4] / V}, + {H[3] * H[0] / V, H[3] * H[1] / V, H[3] * H[2] / V, H[3] * H[3] / V, H[3] * H[4] / V}, + {H[4] * H[0] / V, H[4] * H[1] / V, H[4] * H[2] / V, H[4] * H[3] / V, H[4] * H[4] / V} + }; + + Matrix Ci = null; + if (this.isNonsingular(sv.trackCov.get(k).covMat) == false) { + //System.err.println("Covariance Matrix is non-invertible - quit filter!"); + return; + } + try { + Ci = sv.trackCov.get(k).covMat.inverse(); + } catch (Exception e) { + return; + } + Matrix Ca = null; + try { + Ca = Ci.plus(new Matrix(HTGH)); + } catch (Exception e) { + return; + } + if (Ca != null && this.isNonsingular(Ca) == false) { + //System.err.println("Covariance Matrix Ca is non-invertible - quit filter!"); + return; + } + + if (Ca != null && this.isNonsingular(Ca) == true) { + if (Ca.inverse() != null) { + Matrix CaInv = Ca.inverse(); + sv.trackCov.get(k).covMat = CaInv; + //System.err.println("Error: e"); + } else { + return; + } + } else { + return; + } + + for (int j = 0; j < 5; j++) { + // the gain matrix + K[j] = 0; + for (int i = 0; i < 5; i++) { + K[j] += H[i] * sv.trackCov.get(k).covMat.get(j, i) / V; + } + } + if(sv.straight == true) { + //for (int i = 0; i < 5; i++) { + K[2] = 0; + //} + } + double drho_filt = sv.trackTraj.get(k).d_rho; + double phi0_filt = sv.trackTraj.get(k).phi0; + double kappa_filt = sv.trackTraj.get(k).kappa; + double dz_filt = sv.trackTraj.get(k).dz; + double tanL_filt = sv.trackTraj.get(k).tanL; + + if (!Double.isNaN(dh)) { + drho_filt -= K[0] * dh; + phi0_filt -= K[1] * dh; + kappa_filt -= K[2] * dh; + dz_filt -= K[3] * dh; + tanL_filt -= K[4] * dh; + } + + StateVec fVec = sv.new StateVec(sv.trackTraj.get(k).k); + fVec.d_rho = drho_filt; + fVec.phi0 = phi0_filt; + fVec.kappa = kappa_filt; + fVec.dz = dz_filt; + fVec.tanL = tanL_filt; + fVec.alpha = sv.trackTraj.get(k).alpha; + sv.setStateVecPosAtMeasSite(k, fVec, mv.measurements.get(k), swimmer); + + double dh_filt = mv.dh(k, fVec); + if (Math.abs(dh_filt) < Math.abs(dh) + && Math.abs(dh_filt)/Math.sqrt(V) measurements = new ArrayList(); + + public void setMeasVecs(List measSurfaces) { + Collections.sort(measSurfaces); + for(int i = 0; i < measSurfaces.size(); i++) { + MeasVec mvec = new MeasVec(); + mvec.k = i ; + mvec.layer = measSurfaces.get(i).getLayer(); + mvec.sector = measSurfaces.get(i).getSector(); + mvec.surface = measSurfaces.get(i); + if(mvec.surface.getError()!=0) + mvec.error = mvec.surface.getError(); + measurements.add(mvec); + } + } + + + public double dh(int k, StateVec stateVec) { + + double value = Double.NaN; + + if (stateVec == null|| this.measurements.get(stateVec.k) == null) { + return value; + } + + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { + Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); + value = p.distance(stateVec.x, stateVec.y, stateVec.z); + } + if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { + double phia = this.measurements.get(stateVec.k).surface.arc.theta(); + value = Math.atan2(stateVec.y, stateVec.x)-phia; + System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { + value = stateVec.z-this.measurements.get(stateVec.k).surface.strip.getZ(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { + value = Math.atan2(stateVec.y, stateVec.x)-this.measurements.get(stateVec.k).surface.strip.getPhi(); + } + } + return value; + } + + + public double h(int k, StateVec stateVec) { + + double value = Double.NaN; + + if (stateVec == null|| this.measurements.get(stateVec.k) == null) { + return value; + } + + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { + Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); + value = p.distance(stateVec.x, stateVec.y, stateVec.z); + } + if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { + double phia = this.measurements.get(stateVec.k).surface.arc.theta(); + value = value = Math.atan2(stateVec.y, stateVec.x); + System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { + value = stateVec.z; + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { + value = Math.atan2(stateVec.y, stateVec.x); + } + } + return value; + } + + private double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; + double sqrt_epsilon = Math.sqrt(2.2*1.e-16); + private double[] Hval = new double[5]; + public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim swimmer, int dir) { + StateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); + StateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); + delta_d_a[0]=2*sqrt_epsilon*stateVec.d_rho; + delta_d_a[1]=2*sqrt_epsilon*stateVec.phi0; + delta_d_a[2]=2*sqrt_epsilon*stateVec.kappa; + delta_d_a[3]=2*sqrt_epsilon*stateVec.dz; + delta_d_a[4]=2*sqrt_epsilon*stateVec.tanL; + + for(int i = 0; i < getHval().length; i++) + getHval()[i] = 0; + for(int i = 0; i < getDelta_d_a().length; i++) { + SVplus = this.reset(SVplus, stateVec, sv); + SVminus = this.reset(SVminus, stateVec, sv); + if(i ==0) { + SVplus.d_rho = stateVec.d_rho + getDelta_d_a()[i] / 2.; + SVminus.d_rho = stateVec.d_rho - getDelta_d_a()[i] / 2.; + } + if(i ==1) { + SVplus.phi0 = stateVec.phi0 + getDelta_d_a()[i] / 2.; + SVminus.phi0 = stateVec.phi0 - getDelta_d_a()[i] / 2.; + } + if(i ==2) { + SVplus.kappa = stateVec.kappa + getDelta_d_a()[i] / 2.; + SVminus.kappa = stateVec.kappa - getDelta_d_a()[i] / 2.; + } + if(i ==3) { + SVplus.dz = stateVec.dz + getDelta_d_a()[i] / 2.; + SVminus.dz = stateVec.dz - getDelta_d_a()[i] / 2.; + } + if(i ==4) { + SVplus.tanL = stateVec.tanL + getDelta_d_a()[i] / 2.; + SVminus.tanL = stateVec.tanL - getDelta_d_a()[i] / 2.; + } + SVplus = sv.newStateVecAtMeasSite(stateVec.k, SVplus, mv, swimmer, false); + SVminus = sv.newStateVecAtMeasSite(stateVec.k, SVminus, mv, swimmer, false); + Hval[i] = (this.h(stateVec.k, SVplus) - this.h(stateVec.k, SVminus)) / getDelta_d_a()[i] ; + } + + return getHval(); + } + + private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec stateVec, StateVecs sv) { + SVplus = sv.new StateVec(stateVec.k); + SVplus.d_rho = stateVec.d_rho; + SVplus.alpha = stateVec.alpha; + SVplus.phi0 = stateVec.phi0; + SVplus.kappa = stateVec.kappa; + SVplus.dz = stateVec.dz; + SVplus.tanL = stateVec.tanL; + SVplus.alpha = stateVec.alpha; + + return SVplus; + } + + public class MeasVec implements Comparable { + public Surface surface; + public int layer = -1; + public int sector = -1; + public double error = 1; + public int k = -1; + public boolean skip = false; + + + + @Override + public int compareTo(MeasVec arg) { + int CompLay = this.layer < arg.layer ? -1 : this.layer == arg.layer ? 0 : 1; + return CompLay; + } + } + + /** + * @return the delta_d_a + */ + public double[] getDelta_d_a() { + return delta_d_a; + } + + /** + * @return the Hval + */ + public double[] getHval() { + return Hval; + } + + /** + * @param Hval the Hval to set + */ + public void setHval(double[] Hval) { + this.Hval = Hval; + } + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java new file mode 100644 index 000000000..0965a9322 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -0,0 +1,826 @@ +package org.jlab.clas.tracking.kalmanfilter.helical; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jlab.geom.prim.Vector3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Line3D; +import Jama.Matrix; +import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.helical.MeasVecs.MeasVec; +import org.jlab.clas.tracking.trackrep.Helix; + + +public class StateVecs { + + private Helix util ; + public double units; + public double lightVel; + + public boolean straight; + public List bfieldPoints = new ArrayList(); + public Map trackTraj = new HashMap(); + public Map trackCov = new HashMap(); + + public StateVec StateVec; + public CovMat CovMat; + public Matrix F; + MeasVecs mv = new MeasVecs(); + + public List X0; + public List Y0; + public List Z0; // reference points + + public List Layer; + public List Sector; + + double[] value = new double[4]; // x,y,z,phi + double[] swimPars = new double[7]; + B Bf = new B(0); + + public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, + boolean useSwimmer) { + this.resetArrays(swimPars); + this.resetArrays(value); + + Point3D ps = new Point3D(0,0,0) ; + + StateVec kVec = new StateVec(k); + kVec.phi0 = iVec.phi0; + kVec.d_rho = iVec.d_rho; + kVec.kappa = iVec.kappa; + kVec.dz = iVec.dz; + kVec.tanL = iVec.tanL; + kVec.alpha = iVec.alpha; + + if(mv.surface!=null) { + double x = X0.get(0) + kVec.d_rho * Math.cos(kVec.phi0); + double y = Y0.get(0) + kVec.d_rho * Math.sin(kVec.phi0); + double z = Z0.get(0) + kVec.dz; + + Bf.swimmer = swim; + Bf.x = x; + Bf.y = y; + Bf.z = z; + Bf.set(); + kVec.alpha = Bf.alpha; + + if(k==0) { + value[0] = x; + value[1] = y; + value[2] = z; + value[3] = 0.0; + return value; + } + + if(this.straight) { + Vector3D u = new Vector3D(-(Math.signum(kVec.kappa)) * Math.sin(kVec.phi0), + (Math.signum(kVec.kappa)) * Math.cos(kVec.phi0), + (Math.signum(kVec.kappa)) * kVec.tanL).asUnit(); + + if(mv.surface.plane!=null) { + double alpha = (mv.surface.finitePlaneCorner2.y() - mv.surface.finitePlaneCorner1.y()) / + (mv.surface.finitePlaneCorner2.x() - mv.surface.finitePlaneCorner1.x()); + double l = (alpha*(x-mv.surface.finitePlaneCorner1.x()) -(y-mv.surface.finitePlaneCorner1.y()))/(u.y() - alpha*u.x()); + + kVec.x = x+l*u.x(); + kVec.y = y+l*u.y(); + kVec.z = z+l*u.z(); + + } + if(mv.surface.cylinder!=null) { + double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); + double delta = Math.sqrt((x*u.x()+y*u.y())*(x*u.x()+y*u.y())-(-r*r+x*x+y*y)*(u.x()*u.x()+u.y()*u.y())); + double l = (-(x*u.x()+y*u.y())+delta)/(u.x()*u.x()+u.y()*u.y()); + double phi = Math.atan2(trackTraj.get(k-1).y,trackTraj.get(k-1).x); + double phiref = Math.atan2(y+l*u.y(), x+l*u.x()); + + if(Math.abs(phiref-phi)>Math.PI/2) { + l = (-(x*u.x()+y*u.y())-delta)/(u.x()*u.x()+u.y()*u.y()); + } + + kVec.x = x+l*u.x(); + kVec.y = y+l*u.y(); + kVec.z = z+l*u.z(); + + } + value[0] = kVec.x; + value[1] = kVec.y; + value[2] = kVec.z; + value[3] = this.calcPhi(kVec); + + return value; + } + if(mv.surface.plane!=null) { + //Update B + double r0 = mv.surface.finitePlaneCorner1.toVector3D().dot(mv.surface.plane.normal()); + double stepSize = 5; //mm + int nSteps = (int) (r0/stepSize); + + double dist = 0; + + for(int i = 1; i 0) { + if (dir >99999990 ) { + Vector3D trkDir = this.P(iVec.k).asUnit(); + Vector3D trkPos = this.X(iVec.k); + double x = trkPos.x(); + double y = trkPos.y(); + double z = trkPos.z(); + double ux = trkDir.x(); + double uy = trkDir.y(); + double uz = trkDir.z(); + + double cosEntranceAngle = Math.abs((x * ux + y * uy + z * uz) / Math.sqrt(x * x + y * y + z * z)); + + double pt = Math.abs(1. / iVec.kappa); + double pz = pt * iVec.tanL; + double p = Math.sqrt(pt * pt + pz * pz); + + //double t_ov_X0 = 2. * 0.32 / Constants.SILICONRADLEN; //path length in radiation length units = t/X0 [true path length/ X0] ; Si radiation length = 9.36 cm + double t_ov_X0 = this.get_t_ov_X0(Math.sqrt(iVec.x*iVec.x+iVec.y*iVec.y)); //System.out.println(Math.log(t_ov_X0)/9.+" rad "+Math.sqrt(iVec.x*iVec.x+iVec.y*iVec.y)+" t/x0 "+t_ov_X0); + double mass = MassHypothesis(2); // assume given mass hypothesis (2=pion) + double beta = p / Math.sqrt(p * p + mass * mass); // use particle momentum + double pathLength = t_ov_X0 / cosEntranceAngle; + double sctRMS = (0.00141 / (beta * p)) * Math.sqrt(pathLength) * (1 + Math.log10(pathLength)/9.); // Highland-Lynch-Dahl formula + + Q = new Matrix(new double[][]{ + {0, 0, 0, 0, 0}, + {0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL), 0, 0, 0}, + {0, 0, sctRMS*sctRMS * (iVec.kappa * iVec.kappa * iVec.tanL * iVec.tanL), 0, sctRMS*sctRMS * (iVec.kappa * iVec.tanL * (1 + iVec.tanL * iVec.tanL))}, + {0, 0, 0, 0, 0}, + {0, 0, sctRMS*sctRMS * (iVec.kappa * iVec.tanL * (1 + iVec.tanL * iVec.tanL)), 0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL) * (1 + iVec.tanL * iVec.tanL)} + }); + } + + return Q; + } + + private StateVec reset(StateVec SV, StateVec stateVec) { + SV = new StateVec(stateVec.k); + SV.x = stateVec.x; + SV.y = stateVec.y; + SV.z = stateVec.z; + SV.d_rho = stateVec.d_rho; + SV.dz = stateVec.dz; + SV.phi0 = stateVec.phi0; + SV.phi = stateVec.phi; + SV.tanL = stateVec.tanL; + SV.alpha = stateVec.alpha; + SV.kappa = stateVec.kappa; + + return SV; + } + + private void resetArrays(double[] swimPars) { + for(int i = 0; i=Math.abs(C)) { + util.setD0(-x0/S) ; + } else { + util.setD0(y0/C) ; + } + + util.Update(); + } + + private void setHelixPars(StateVec kVec, Swim swim) { + double x0 = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) ; + double y0 = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) ; + double z0 = Z0.get(kVec.k) + kVec.dz ; + double invKappa = 1. / Math.abs(kVec.kappa); + double px0 = -invKappa * Math.sin(kVec.phi0 ); + double py0 = invKappa * Math.cos(kVec.phi0 ); + double pz0 = invKappa * kVec.tanL; + + int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); + + double B = 1. / (lightVel * kVec.alpha); + this.setHelix(util, x0,y0,z0,px0,py0,pz0,ch, B); + } + + private void setTrackPars(StateVec kVec, Swim swim) { + + double x0 = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) ; + double y0 = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) ; + double z0 = Z0.get(kVec.k) + kVec.dz ; + double invKappa = 1. / Math.abs(kVec.kappa); + double px0 = -invKappa * Math.sin(kVec.phi0 ); + double py0 = invKappa * Math.cos(kVec.phi0 ); + double pz0 = invKappa * kVec.tanL; + int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); + + swim.SetSwimParameters( + x0/units, + y0/units, + z0/units, + px0, py0, pz0, ch); + } + + private double calcPhi(StateVec kVec) { + double xc = X0.get(kVec.k) + (kVec.d_rho + kVec.alpha / kVec.kappa) * Math.cos(kVec.phi0); + double yc = Y0.get(kVec.k) + (kVec.d_rho + kVec.alpha / kVec.kappa) * Math.sin(kVec.phi0); + double r = Math.abs(kVec.alpha / kVec.kappa); + Vector3D ToPoint = new Vector3D(); + Vector3D ToRef = new Vector3D(X0.get(kVec.k) - xc, Y0.get(kVec.k) - yc, 0); + + ToPoint = new Vector3D(kVec.x - xc, kVec.y - yc, 0); + double phi = ToRef.angle(ToPoint); + phi *= -Math.signum(kVec.kappa); + + return phi; + } + + private void iterateHelixAtR(int it, int k, StateVec kVec, Swim swim, + double r, B Bf, Point3D ps) { + for(int i = 0; i < it; i++) { + this.setHelixPars(kVec, swim); + ps = util.getHelixPointAtR(r); + kVec.x = ps.x(); + kVec.y = ps.y(); + kVec.z = ps.z(); + this.tranState(k, kVec, swim); + Bf = new B(kVec.k, kVec.x, kVec.y, kVec.z, swim); + kVec.alpha = Bf.alpha; + this.tranState(k, kVec, swim); + this.setHelixPars(kVec, swim); + kVec.x = ps.x(); + kVec.y = ps.y(); + kVec.z = ps.z(); + this.tranState(k, kVec, swim); + } + } + + public class StateVec { + + final int k; + + public double x; + public double y; + public double z; + public double kappa; + public double d_rho; + public double phi0; + public double phi; + public double tanL; + public double dz; + public double alpha; + + StateVec(int k) { + this.k = k; + } + private double[] _ELoss = new double[3]; + + public double[] get_ELoss() { + return _ELoss; + } + + public void set_ELoss(double[] _ELoss) { + this._ELoss = _ELoss; + } + + } + + public class CovMat { + + final int k; + public Matrix covMat; + + CovMat(int k) { + this.k = k; + } + + } + + public class B { + + final int k; + public double x; + public double y; + public double z; + public Swim swimmer; + + public double Bx; + public double By; + public double Bz; + + public double alpha; + + float b[] = new float[3]; + B(int k) { + this.k = k; + } + B(int k, double x, double y, double z, Swim swimmer) { + this.k = k; + this.x = x; + this.y = y; + this.z = z; + + swimmer.BfieldLab(x/units, y/units, z/units, b); + this.Bx = b[0]; + this.By = b[1]; + this.Bz = b[2]; + + this.alpha = 1. / (lightVel * Math.abs(b[2])); + } + + public void set() { + swimmer.BfieldLab(x/units, y/units, z/units, b); + this.Bx = b[0]; + this.By = b[1]; + this.Bz = b[2]; + + this.alpha = 1. / (lightVel * Math.abs(b[2])); + } + } + + //public String massHypo = "pion"; + public double MassHypothesis(int H) { + double piMass = 0.13957018; + double KMass = 0.493677; + double muMass = 0.105658369; + double eMass = 0.000510998; + double pMass = 0.938272029; + double value = piMass; //default + if (H == 4) { + value = pMass; + } + if (H == 1) { + value = eMass; + } + if (H == 2) { + value = piMass; + } + if (H == 3) { + value = KMass; + } + if (H == 0) { + value = muMass; + } + return value; + } + + public Vector3D P(int kf) { + if (this.trackTraj.get(kf) != null) { + double px = -(Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * Math.sin(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi); + double py = (Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * Math.cos(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi); + double pz = (Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * this.trackTraj.get(kf).tanL; + + return new Vector3D(px, py, pz); + } else { + return new Vector3D(0, 0, 0); + } + + } + public Vector3D X(int kf) { + if (this.trackTraj.get(kf) != null) { + double x = X0.get(kf) + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.cos(this.trackTraj.get(kf).phi0) - Math.cos(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); + double y = Y0.get(kf) + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.sin(this.trackTraj.get(kf).phi0) - Math.sin(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); + double z = Z0.get(kf) + this.trackTraj.get(kf).dz - this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * this.trackTraj.get(kf).tanL * this.trackTraj.get(kf).phi; + + return new Vector3D(x, y, z); + } else { + return new Vector3D(0, 0, 0); + } + + } + public Vector3D X(StateVec kVec, double phi) { + if (kVec != null) { + double x = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.cos(kVec.phi0) - Math.cos(kVec.phi0 + phi)); + double y = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.sin(kVec.phi0) - Math.sin(kVec.phi0 + phi)); + double z = Z0.get(kVec.k) + kVec.dz - kVec.alpha / kVec.kappa * kVec.tanL * phi; + + return new Vector3D(x, y, z); + } else { + return new Vector3D(0, 0, 0); + } + + } + public Vector3D P0(int kf) { + if (this.trackTraj.get(kf) != null) { + double px = -(Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * Math.sin(this.trackTraj.get(kf).phi0); + double py = (Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * Math.cos(this.trackTraj.get(kf).phi0); + double pz = (Math.signum(this.trackTraj.get(kf).kappa) / this.trackTraj.get(kf).kappa) * this.trackTraj.get(kf).tanL; + + return new Vector3D(px, py, pz); + } else { + return new Vector3D(0, 0, 0); + } + + } + public Vector3D X0(int kf) { + if (this.trackTraj.get(kf) != null) { + double x = X0.get(kf) + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0); + double y = Y0.get(kf) + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0); + double z = Z0.get(kf) + this.trackTraj.get(kf).dz; + + return new Vector3D(x, y, z); + } else { + return new Vector3D(0, 0, 0); + } + + } + + public Helix getHelixAtBeamLine(int k, Swim swim) { + this.resetArrays(swimPars); + StateVec kVec = this.trackTraj.get(k); + double x0 = kVec.x ; + double y0 = kVec.y ; + double z0 = kVec.z ; + + Vector3D p = this.P(k); + double px0 = p.x(); + double py0 = p.y(); + double pz0 = p.z(); + int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); + + swim.SetSwimParameters( + x0/units, + y0/units, + z0/units, + -px0, -py0, -pz0, -ch); + + swimPars = swim.SwimToBeamLine(X0.get(0), Y0.get(0)); + + for(int j =0; j < 3; j++) { + swimPars[j]*=units; + } + + int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(k).kappa); + double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel; + + this.setHelix(util, swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], q, B); + + return util; + } + public Helix setTrackPars() { + Vector3D X = this.X0(0); + Vector3D P = this.P0(0); + + int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(0).kappa); + double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel ; + + return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, util.units); + } + public StateVec initSV = new StateVec(0); + public void init(Helix trk, Matrix cov, KFitter kf, + Swim swimmer) { + this.units = trk.getUnitScale(); + this.lightVel = trk.getLIGHTVEL(); + this.util = trk; + //init stateVec + //StateVec initSV = new StateVec(0); + initSV.x = - trk.getD0() * Math.sin(trk.getPhi0()); + initSV.y = trk.getD0() * Math.cos(trk.getPhi0()); + initSV.z = trk.getZ0(); + + double xcen = (1. / trk.getOmega() - trk.getD0()) * Math.sin(trk.getPhi0()); + double ycen = (-1. / trk.getOmega() + trk.getD0()) * Math.cos(trk.getPhi0()); + + B Bf = new B(0, (float)initSV.x, (float)initSV.x, (float)initSV.z, swimmer); + + if(Math.abs(Bf.Bz)<0.001) + this.straight = true; + + initSV.alpha = Bf.alpha; + initSV.kappa = Bf.alpha * trk.getOmega(); + initSV.phi0 = Math.atan2(ycen, xcen); + if (initSV.kappa < 0) { + initSV.phi0 = Math.atan2(-ycen, -xcen); + } + + initSV.dz = trk.getZ(); + initSV.tanL = trk.getTanL(); + initSV.d_rho = trk.getD0()*(Math.cos(trk.getPhi0())*Math.sin(initSV.phi0) -Math.sin(trk.getPhi0())*Math.cos(initSV.phi0)); + + double x0 = X0.get(0) + initSV.d_rho * Math.cos(initSV.phi0) ; + double y0 = Y0.get(0) + initSV.d_rho * Math.sin(initSV.phi0) ; + double z0 = Z0.get(0) + initSV.dz ; + double invKappa = 1. / Math.abs(initSV.kappa); + double px0 = -invKappa * Math.sin(initSV.phi0 ); + double py0 = invKappa * Math.cos(initSV.phi0 ); + double pz0 = invKappa * initSV.tanL; + + initSV.phi = 0; + + this.trackTraj.put(0, initSV); + CovMat initCM = new CovMat(0); + Matrix covKF = cov.copy(); + /* + System.out.println("----------------"); + for(int ic = 0; ic<5; ic++) { + for(int ir = 0; ir<5; ir++) { + if(ic==ir) { + System.out.println(Math.sqrt(covKF.get(ic, ir))); + } + } + } + */ + covKF.set(2, 2, cov.get(2, 2)*600 ); + + initCM.covMat = covKF; + this.trackCov.put(0, initCM); + } + + public void printMatrix(Matrix C) { + for (int k = 0; k < 5; k++) { + System.out.println(C.get(k, 0) + " " + C.get(k, 1) + " " + C.get(k, 2) + " " + C.get(k, 3) + " " + C.get(k, 4)); + } + } + + public void printlnStateVec(StateVec S) { + System.out.println(S.k + ") drho " + S.d_rho + " phi0 " + S.phi0 + " kappa " + S.kappa + " dz " + S.dz + " tanL " + S.tanL + " phi " + S.phi + " x " + S.x + " y " + S.y + " z " + S.z + " alpha " + S.alpha); + } +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java new file mode 100644 index 000000000..e23984eb3 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java @@ -0,0 +1,135 @@ +/* + * 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.tracking.objects; + +/** + * + * @author ziegler + */ +public class Cross extends TObject { + + public Cross() { + } + + public Cross(int id, double x, double y, double z, double ux, double uy) { + super(id, x, y, z); + _ux = ux; + _uy = uy; + } + public Cross(int id, double x, double y, double z) { + super(id, x, y, z); + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + + if (!(o instanceof Cross)) { + return false; + } + + Cross c = (Cross) o; + + return Double.compare(_x, c._x) == 0 + && Double.compare(_y, c._y) == 0 + && Double.compare(_z, c._z) == 0; + } + /** + * @return the _id + */ + public int getId() { + return _id; + } + + /** + * @param _id the _id to set + */ + public void setId(int _id) { + this._id = _id; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _z + */ + public double getZ() { + return _z; + } + + /** + * @param _z the _z to set + */ + public void setZ(double _z) { + this._z = _z; + } + + /** + * @return the _ux + */ + public double getUx() { + return _ux; + } + + /** + * @param _ux the _ux to set + */ + public void setUx(double _ux) { + this._ux = _ux; + } + + /** + * @return the _uy + */ + public double getUy() { + return _uy; + } + + /** + * @param _uy the _uy to set + */ + public void setUy(double _uy) { + this._uy = _uy; + } + + private int _id; + private double _x; + private double _y; + private double _z; + private double _ux; + private double _uy; + + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java new file mode 100644 index 000000000..79c39562d --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java @@ -0,0 +1,164 @@ +/* + * 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.tracking.objects; + +/** + * + * @author ziegler + */ +public class Segment extends TObject{ + + public void setLength(double _length) { + this._length = _length; + } + + public Segment(int id, double x, double y, double z, + double ux, double uy, double uz, double length) { + super(id, x, y, z); + _ux = ux; + _uy = uy; + _uz = uz; + _length = length; + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + + if (!(o instanceof Segment)) { + return false; + } + + Segment c = (Segment) o; + + return Double.compare(_x, c._x) == 0 + && Double.compare(_y, c._y) == 0 + && Double.compare(_z, c._z) == 0 + && Double.compare(_ux, c._ux) == 0 + && Double.compare(_uy, c._uy) == 0 + && Double.compare(_uz, c._uz) == 0; + } + + /** + * @return the _id + */ + public int getId() { + return _id; + } + + /** + * @param _id the _id to set + */ + public void setId(int _id) { + this._id = _id; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _z + */ + public double getZ() { + return _z; + } + + /** + * @param _z the _z to set + */ + public void setZ(double _z) { + this._z = _z; + } + + /** + * @return the _ux + */ + public double getUx() { + return _ux; + } + + /** + * @param _ux the _ux to set + */ + public void setUx(double _ux) { + this._ux = _ux; + } + + /** + * @return the _uy + */ + public double getUy() { + return _uy; + } + + /** + * @param _uy the _uy to set + */ + public void setUy(double _uy) { + this._uy = _uy; + } + + /** + * @return the _uz + */ + public double getUz() { + return _uz; + } + + /** + * @param _uz the _uz to set + */ + public void setUz(double _uz) { + this._uz = _uz; + } + + /** + * @return the _length + */ + public double getLength() { + return _length; + } + + /** + * @param _length the _length to set + */ + private int _id; + private double _x; + private double _y; + private double _z; + private double _ux; + private double _uy; + private double _uz; + private double _length; +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java new file mode 100644 index 000000000..128a4b12c --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java @@ -0,0 +1,321 @@ +/* + * 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.tracking.objects; + +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Vector3D; +/** + * + * @author ziegler + */ +public class Strip extends TObject { + + /** + * @return the _id + */ + public int getId() { + return _id; + } + + /** + * @param _id the _id to set + */ + public void setId(int _id) { + this._id = _id; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _z + */ + public double getZ() { + return _z; + } + + /** + * @param _z the _z to set + */ + public void setZ(double _z) { + this._z = _z; + } + + /** + * @return the _ux + */ + public double getUx() { + return _ux; + } + + /** + * @param _ux the _ux to set + */ + public void setUx(double _ux) { + this._ux = _ux; + } + + /** + * @return the _uy + */ + public double getUy() { + return _uy; + } + + /** + * @param _uy the _uy to set + */ + public void setUy(double _uy) { + this._uy = _uy; + } + + /** + * @return the _uz + */ + public double getUz() { + return _uz; + } + + /** + * @param _uz the _uz to set + */ + public void setUz(double _uz) { + this._uz = _uz; + } + + /** + * @return the _ex + */ + public double getEx() { + return _ex; + } + + /** + * @param _ex the _ex to set + */ + public void setEx(double _ex) { + this._ex = _ex; + } + + /** + * @return the _ey + */ + public double getEy() { + return _ey; + } + + /** + * @param _ey the _ey to set + */ + public void setEy(double _ey) { + this._ey = _ey; + } + + /** + * @return the _ez + */ + public double getEz() { + return _ez; + } + + /** + * @param _ez the _ez to set + */ + public void setEz(double _ez) { + this._ez = _ez; + } + + /** + * @return the _length + */ + public double getLength() { + return _length; + } + + /** + * @param _length the _length to set + */ + public void setLength(double _length) { + this._length = _length; + } + + /** + * @return the _c + */ + public double getC() { + return _c; + } + + /** + * @param _c the _c to set + */ + public void setC(double _c) { + this._c = _c; + } + + /** + * @return the _ce + */ + public double getCe() { + return _ce; + } + + /** + * @param _ce the _ce to set + */ + public void setCe(double _ce) { + this._ce = _ce; + } + + /** + * @return the _phi + */ + public double getPhi() { + return _phi; + } + + /** + * @param _phi the _phi to set + */ + public void setPhi(double _phi) { + this._phi = _phi; + } + + /** + * @return the _phie + */ + public double getPhie() { + return _phie; + } + + /** + * @param _phie the _phie to set + */ + public void setPhie(double _phie) { + this._phie = _phie; + } + + public Strip(int id, double centroid, double x1, double y1, double z1, + double x2, double y2, double z2) { + super(id, x1, y1, z1); + Line3D l = new Line3D(x1,y1,z1,x2,y2,z2); + Vector3D dir = l.direction().asUnit(); + _x = x1; + _y = y1; + _z = z1; + _ux = dir.x(); + _uy = dir.y(); + _uz = dir.z(); + _length = l.length(); + _c = centroid; + type = Type.XYZ; + } + public Strip(int id, double centroid, double x, double y, double z, + double ux, double uy, double uz, double length) { + super(id, x, y, z); + _x = x; + _y = y; + _z = z; + _ux = ux; + _uy = uy; + _uz = uz; + _length = length; + _c = centroid; + type = Type.XYZ; + } + + public Strip(int id, double centroid, double x, double y, double phi) { + super(id, x, y, -999); + _phi = phi; + _c = centroid; + type = Type.PHI; + } + + public Strip(int id, double centroid, double z) { + super(id, -999, -999, z); + _c = centroid; + _z = z; + type = Type.Z; + } + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + + if (!(o instanceof Strip)) { + return false; + } + + Strip c = (Strip) o; + + return Double.compare(getX(), c.getX()) == 0 + && Double.compare(getY(), c.getY()) == 0 + && Double.compare(getZ(), c.getZ()) == 0 + && Double.compare(getUx(), c.getUx()) == 0 + && Double.compare(getUy(), c.getUy()) == 0 + && Double.compare(getUz(), c.getUz()) == 0; + } + + + private int _id; + private double _x; + private double _y; + private double _z; + private double _ux; + private double _uy; + private double _uz; + private double _ex; //errors + private double _ey; + private double _ez; + private double _length; + private double _c; //centroid + private double _ce; //centroid error + private double _phi; + private double _phie; //phi error + public Type type; + + public enum Type { + UDF(-1), XYZ(0), Z(1), PHI(2); + private final int value; + + Type(int value) { + this.value = value; + } + + public byte value() { + return (byte) this.value; + } + } + + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java new file mode 100644 index 000000000..a3b33f4e5 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java @@ -0,0 +1,134 @@ +/* + * 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.tracking.objects; + +/** + * + * @author ziegler + */ + +public class TObject { + /** + * TObject is a tracking object that can be a cross + * or a segment representing a strip or a wire + */ + public TObject(){ + } + public TObject(int id, double x, double y, double z) { + _id = id; + _x = x; + _y = y; + _z = z; + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + + if (!(o instanceof TObject)) { + return false; + } + + TObject c = (TObject) o; + + return Double.compare(_x, c._x) == 0 + && Double.compare(_y, c._y) == 0 + && Double.compare(_z, c._z) == 0; + } + /** + * @return the _id + */ + public int getId() { + return _id; + } + + /** + * @param _id the _id to set + */ + public void setId(int _id) { + this._id = _id; + } + + /** + * @return the _layer + */ + public int getLayer() { + return _layer; + } + + /** + * @param _layer the _layer to set + */ + public void setLayer(int _layer) { + this._layer = _layer; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _z + */ + public double getZ() { + return _z; + } + + /** + * @param _z the _z to set + */ + public void setZ(double _z) { + this._z = _z; + } + + /** + * @return the _r + */ + public double getR() { + return _r; + } + + /** + * @param _r the _r to set + */ + public void setR(double _r) { + this._r = _r; + } + + private int _id; + private int _layer; + private double _x; + private double _y; + private double _z; + private double _r; +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java new file mode 100644 index 000000000..a54ee20e2 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java @@ -0,0 +1,345 @@ +/* + * 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.tracking.patternrec; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import static java.util.stream.Collectors.toMap; +import org.jlab.clas.tracking.trackrep.Helix; + +/** + * + * @author ziegler + */ +public class CircleHoughTrans { + + private double _RMin = 200; // minimum helix radius + private double _RWidth = 2200;// maximum helix radius + private double _RBinWidth = 20; // R bin width + + private int width = 1400; // x range for helix (p~<3.25) + private int height = 4100; // y range + + double R_Array[]; + int[] acc; + int[] results; + + public CircleHoughTrans() { + int nR = (int) (_RWidth/_RBinWidth); + R_Array = new double[nR]; + for(int i = 0; i < nR; i++) { + R_Array[i] = _RMin + (0.5 + i)*_RBinWidth; + } + acc = new int[width * height]; + results = new int[width * height*3]; + } + private Map peaks = new HashMap(); + public int minAccVal = 4; + + public void fillAccumulator(ListX, ListY) { + double t; + double x; + double y; + double x0, y0; + for(int j = 0; j < X.size(); j++) { + x = X.get(j); + y = Y.get(j); + + for(int i = 0; i < R_Array.length; i++) { + for (int theta=0; theta<360; theta++) { + t = (theta * 3.14159265) / 180; + x0 = (x - R_Array[i] * Math.cos(t)) ; + y0 = (y - R_Array[i] * Math.sin(t)) ; + if(x0 < width/2 && x0 > -width/2 && y0 < height/2 && y0 > -height/2) { + acc[(int)x0+ (int) (width/2) + (((int)y0 + (int) (height/2)) * width)] += 1; + if(acc[(int)x0+ (int) (width/2) + (((int)y0 + (int) (height/2)) * width)]>=minAccVal) { + peaks.put((int)x0+ (int) (width/2) + (((int)y0 + (int) (height/2)) * width), + acc[(int)x0+ (int) (width/2) + (((int)y0 + (int) (height/2)) * width)]); + + } + } + } + } + } + } + List xy; // xy of seed points + + private List> set = new ArrayList>(); + public List> CHTSeeds = new ArrayList>(); + + public void findCircles(ListX, ListY, ListL) { + for(int j = 0; j < set.size(); j++) { + set.clear(); + } + for(int j = 0; j < CHTSeeds.size(); j++) { + CHTSeeds.clear(); + } + fillAccumulator(X, Y); + // find the peaks of the accumulator array + Map sorted = peaks.entrySet() + .stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .collect( + toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, + LinkedHashMap::new)); + + for(Map.Entry entry:sorted.entrySet()){ + + xy = new ArrayList((int)entry.getValue()); + + double t; + int l; + double x; + double y; + double x0, y0; + for(int j = 0; j < X.size(); j++) { + l = L.get(j); + x = X.get(j); + y = Y.get(j); + + for(int i = 0; i < R_Array.length; i++) { + for (int theta=0; theta<360; theta++) { + t = (theta * 3.14159265) / 180; + x0 = (x - R_Array[i] * Math.cos(t)) ; + y0 = (y - R_Array[i] * Math.sin(t)) ; + + if((int)x0+ (int) (width/2) + (((int)y0 + (int) (height/2)) * width)==(int)entry.getKey()) { + xy.add(new Point2D(x,y,l,R_Array[i],t)); + } + } + } + } + + if(this.contains(xy,set)==false){ + set.add((ArrayList) xy); + List> newset = this.split(); + for(int i = 0; i < newset.size(); i++) { + if(newset.get(i).size()>=this.minAccVal && + this.contains(newset.get(i),CHTSeeds)==false) { + CHTSeeds.add(newset.get(i)); + System.out.println("================="); + for(int j = 0; j < newset.get(i).size(); j++) { + Point2D p =newset.get(i).get(j); + System.out.println(p._layer+" "+p._x+" "+p._y+" rad "+p._radius+" pt "+(p._radius*(5*Helix.LIGHTVEL))); + } + } + } + } + } + } + Map> hxy = new HashMap<>(); + + private List> split() { + hxy.clear(); + List> newset = new ArrayList>(); + //get list with single hit per layer + List base = new ArrayList(); // xy of seed points + base.add(xy.get(0)); + for(int i = 1; i < xy.size(); i++) { + if(xy.get(i-1).getLayer() != xy.get(i).getLayer()) { + base.add(xy.get(i)); + } + } + List offbase = new ArrayList(); + offbase.addAll(xy); + offbase.removeAll(base); + + //get same layer hits + for(Point2D p : offbase) { + hxy.put(p.getLayer(),new ArrayList()); + } + for(Point2D p : offbase) { + hxy.get(p.getLayer()).add(p); + } + newset.add((ArrayList) base); + + for (Map.Entry> entry : hxy.entrySet()) { + for(Point2D p : entry.getValue()) { + List base2 = new ArrayList(); + base2.addAll(base); + for(int k = 0; k < base2.size(); k++) { + Point2D bp = base2.get(k); + if(p.getLayer()==bp.getLayer()) { + base2.remove(k); + base2.add(k,p); + } + } + newset.add((ArrayList) base2); + } + } + return newset; + } + private boolean contains(List x0y0, List> set) { + boolean isc = false; + + x0y0.sort(Comparator.comparing(Point2D::getLayer).thenComparing(Point2D::getR)); + + for(int i = 0; i < set.size(); i++) { + List xy = set.get(i); + + xy.sort(Comparator.comparing(Point2D::getLayer).thenComparing(Point2D::getR)); + + if(xy.size() == x0y0.size()) { + int n = 0; + for(int k =0; k < xy.size(); k++) { + if(xy.get(k).equals(x0y0.get(k))) + n++; + } + if(n == xy.size()) + isc = true; + } + } + + return isc; + } + + public class Point2D { + + public Point2D(double x, double y) { + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + } + public Point2D(double x, double y, int layer) { + this._layer = layer; + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + } + public Point2D(double x, double y, int layer, double rad, double azi) { + this._layer = layer; + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + this._radius = rad; + this._azimuth = azi; + } + public void set(Point2D p) { + this._layer = p._layer; + this._x = p._x; + this._y = p._y; + this._r = p._r; + } + // Overriding equals() to compare two objects + @Override + public boolean equals(Object o) { + + // If the object is compared with itself then return true + if (o == this) { + return true; + } + + /* Check if o is an instance of Point2D or not + "null instanceof [type]" also returns false */ + if (!(o instanceof Point2D)) { + return false; + } + + // typecast o to Point2D so that we can compare data members + Point2D c = (Point2D) o; + + // Compare the data members and return accordingly + return Double.compare(_x, c._x) == 0 + && Double.compare(_y, c._y) == 0; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _layer + */ + public int getLayer() { + return _layer; + } + + /** + * @param _layer the _layer to set + */ + public void setLayer(int _layer) { + this._layer = _layer; + } + + /** + * @return the _r + */ + public double getR() { + return _r; + } + + /** + * @param _r the _r to set + */ + public void setR(double _r) { + this._r = _r; + } + + /** + * @return the _radius + */ + public double getRadius() { + return _radius; + } + + /** + * @param _radius the _radius to set + */ + public void setRadius(double _radius) { + this._radius = _radius; + } + + /** + * @return the _azimuth + */ + public double getAzimuth() { + return _azimuth; + } + + /** + * @param _azimuth the _azimuth to set + */ + public void setAzimuth(double _azimuth) { + this._azimuth = _azimuth; + } + + private double _x; + private double _y; + private int _layer; + private double _r; + private double _radius; + private double _azimuth; + } +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java new file mode 100644 index 000000000..5b8d04aca --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java @@ -0,0 +1,332 @@ +/* + * 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.tracking.patternrec; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import static java.util.stream.Collectors.toMap; + +/** + * + * @author ziegler + */ +public class LineHoughTrans { + + private double _TBinWidth; + + double C_Array[]; + double S_Array[]; + + + int[][] acc; + int[] results; + + int nTh = 180; + int n = 45; + public LineHoughTrans() { + _TBinWidth = nTh/ (double) nTh; + + C_Array = new double[nTh]; + S_Array = new double[nTh]; + for(int i = 0; i < nTh; i++) { + C_Array[i] = Math.cos((0.5 + i)*_TBinWidth); + S_Array[i] = Math.cos((0.5 + i)*_TBinWidth); + } + acc = new int[n][nTh]; + results = new int[n * nTh *3]; + } + private Map peaks = new HashMap(); + public int minAccVal = 4; + + public void fillAccumulator(ListX, ListY) { + double x; + double y; + + for(int j = 0; j < X.size(); j++) { + x = X.get(j); + y = Y.get(j); + + for(int i = 0; i < nTh; i++) { + acc[(int) Math.floor(n * (y*C_Array[i] + x*S_Array[i] + 180.0) / 360.0)][i]++; + peaks.put((int) Math.floor(n * (y*C_Array[i] + x*S_Array[i] + 180.0) / 360.0), + acc[(int) Math.floor(n * (y*C_Array[i] + x*S_Array[i] + 180.0) / 360.0)][i]); + } + } + } + List xy; // xy of seed points + + private List> set = new ArrayList>(); + public List> LHTSeeds = new ArrayList>(); + + public void findLines(ListX, ListY, ListL) { + for(int j = 0; j < set.size(); j++) { + set.clear(); + } + for(int j = 0; j < LHTSeeds.size(); j++) { + LHTSeeds.clear(); + } + fillAccumulator(X, Y); + // find the peaks of the accumulator array + Map sorted = peaks.entrySet() + .stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .collect( + toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, + LinkedHashMap::new)); + + for(Map.Entry entry:sorted.entrySet()){ + + xy = new ArrayList((int)entry.getValue()); + + double t; + int l; + double x; + double y; + double x0, y0; + for(int j = 0; j < X.size(); j++) { + l = L.get(j); + x = X.get(j); + y = Y.get(j); + + for(int i = 0; i < nTh; i++) { + if((int) Math.floor(n * (y*C_Array[i] + x*S_Array[i] + 180.0) / 360.0)==(int)entry.getKey()) { + xy.add(new Point2D(x,y,l,(int)entry.getKey(),i)); + xy.get(xy.size()-1).index = j; + } + } + } + + + if(this.contains(xy,set)==false){ + set.add((ArrayList) xy); + List> newset = this.split(); + for(int i = 0; i < newset.size(); i++) { + if(newset.get(i).size()>=this.minAccVal && + this.contains(newset.get(i),LHTSeeds)==false) { + LHTSeeds.add(newset.get(i)); + System.out.println("================="); + for(int j = 0; j < newset.get(i).size(); j++) { + Point2D p =newset.get(i).get(j); + System.out.println(p._layer+" "+p._x+" "+p._y+" rho "+p._rho+" phi "+(p._phi)); + } + } + } + } + } + } + Map> hxy = new HashMap<>(); + + private List> split() { + hxy.clear(); + List> newset = new ArrayList>(); + //get list with single hit per layer + List base = new ArrayList(); // xy of seed points + base.add(xy.get(0)); + for(int i = 1; i < xy.size(); i++) { + if(xy.get(i-1).getLayer() != xy.get(i).getLayer()) { + base.add(xy.get(i)); + } + } + List offbase = new ArrayList(); + offbase.addAll(xy); + offbase.removeAll(base); + + //get same layer hits + for(Point2D p : offbase) { + hxy.put(p.getLayer(),new ArrayList()); + } + for(Point2D p : offbase) { + hxy.get(p.getLayer()).add(p); + } + newset.add((ArrayList) base); + + for (Map.Entry> entry : hxy.entrySet()) { + for(Point2D p : entry.getValue()) { + List base2 = new ArrayList(); + base2.addAll(base); + for(int k = 0; k < base2.size(); k++) { + Point2D bp = base2.get(k); + if(p.getLayer()==bp.getLayer()) { + base2.remove(k); + base2.add(k,p); + } + } + newset.add((ArrayList) base2); + } + } + return newset; + } + private boolean contains(List x0y0, List> set) { + boolean isc = false; + + x0y0.sort(Comparator.comparing(Point2D::getLayer).thenComparing(Point2D::getR)); + + for(int i = 0; i < set.size(); i++) { + List xy = set.get(i); + + xy.sort(Comparator.comparing(Point2D::getLayer).thenComparing(Point2D::getR)); + + if(xy.size() == x0y0.size()) { + int n = 0; + for(int k =0; k < xy.size(); k++) { + if(xy.get(k).equals(x0y0.get(k))) + n++; + } + if(n == xy.size()) + isc = true; + } + } + + return isc; + } + + public class Point2D { + public int index = -1; + public Point2D(double x, double y) { + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + } + public Point2D(double x, double y, int layer) { + this._layer = layer; + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + } + public Point2D(double x, double y, int layer, double rad, double azi) { + this._layer = layer; + this._x = x; + this._y = y; + this._r = Math.sqrt(x*x + y*y); + this._rho = rad; + this._phi = azi; + } + public void set(Point2D p) { + this._layer = p._layer; + this._x = p._x; + this._y = p._y; + this._r = p._r; + } + // Overriding equals() to compare two objects + @Override + public boolean equals(Object o) { + + // If the object is compared with itself then return true + if (o == this) { + return true; + } + + /* Check if o is an instance of Point2D or not + "null instanceof [type]" also returns false */ + if (!(o instanceof Point2D)) { + return false; + } + + // typecast o to Point2D so that we can compare data members + Point2D c = (Point2D) o; + + // Compare the data members and return accordingly + return Double.compare(_x, c._x) == 0 + && Double.compare(_y, c._y) == 0; + } + + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _layer + */ + public int getLayer() { + return _layer; + } + + /** + * @param _layer the _layer to set + */ + public void setLayer(int _layer) { + this._layer = _layer; + } + + /** + * @return the _r + */ + public double getR() { + return _r; + } + + /** + * @param _r the _r to set + */ + public void setR(double _r) { + this._r = _r; + } + + /** + * @return the _rho + */ + public double getRho() { + return _rho; + } + + /** + * @param _radius the _rho to set + */ + public void setRho(double _radius) { + this._rho = _radius; + } + + /** + * @return the _phi + */ + public double getphi() { + return _phi; + } + + /** + * @param _azimuth the _phi to set + */ + public void setPhi(double _azimuth) { + this._phi = _azimuth; + } + + private double _x; + private double _y; + private int _layer; + private double _r; + private double _rho; + private double _phi; + } +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java new file mode 100644 index 000000000..4fffecca9 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -0,0 +1,557 @@ +/* + * 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.tracking.trackrep; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; + +/** + * + * @author ziegler + */ +public class Helix { + + //Setting for Negative polarity of the solenoid. + // turningSign = -charge*polarity = + charge for nominal configuration + + private double _B; + private double _d0; + private double _phi0; + private double _omega; + private double _z0; + private double _tanL; + private int _turningSign; + + private double tFlightLen = 0; + private double _R; + + private double _xd; + private double _yd; + private double _xc; + private double _yc; + private double _x; + private double _y; + private double _z; + private double _px; + private double _py; + private double _pz; + + public Units units = Units.CM; //default + + public Helix(double d0, double phi0, double omega, double z0, double tanL, + int turningSign, double B, Units unit) { + _d0 = d0; + _phi0 = phi0; + _omega = omega; + _z0 = z0; + _tanL = tanL; + _turningSign = turningSign; + _B = B; + this.units = unit; + this.setUnitScale(unit.unit); + setLIGHTVEL(LIGHTVEL*unit.unit); + this.Update(); + } + + public Helix(double x0, double y0, double z0, double px0, double py0, double pz0, + int q, double B, Units unit) { + _turningSign = q; + _B = B; + double pt = Math.sqrt(px0*px0 + py0*py0); + this.units = unit; + setUnitScale(unit.unit); + setLIGHTVEL(LIGHTVEL*unit.unit); + _R = pt/(B*LIGHTVEL*unit.unit); + _phi0 = Math.atan2(py0, px0); + _tanL = pz0/pt; + _z0 = z0; + _omega = (double) -_turningSign/_R; + double S = Math.sin(_phi0); + double C = Math.cos(_phi0); + if(Math.abs(S)>=Math.abs(C)) { + _d0 = -x0/S; + } else { + _d0 = y0/C; + } + this.Update(); + } + + public double getPhi(double l) { + return getPhi0() + getOmega()*l; + } + + public double getPt(double B) { + return getLIGHTVEL() * getR() * B; + } + public double getX(double l){ + return getXc() + getTurningSign()*getR()*Math.sin(getPhi(l)); + } + public double getY(double l){ + return getYc() - getTurningSign()*getR()*Math.cos(getPhi(l)); + } + public double getZ(double l){ + return getZ0() -l*getTanL(); + } + public double getPx(double B, double l) { + return getPt(B) * Math.cos(getPhi(l)); + } + public double getPy(double B, double l) { + return getPt(B) * Math.sin(getPhi(l)); + } + public double getPz(double B) { + return getPt(B)*getTanL(); + } + + /** + * @return the _B + */ + public double getB() { + return _B; + } + + /** + * @param _B the _B to set + */ + public void setB(double _B) { + this._B = _B; + } + + /** + * @return the _d0 + */ + public double getD0() { + return _d0; + } + + /** + * @param _d0 the _d0 to set + */ + public void setD0(double _d0) { + this._d0 = _d0; + } + + /** + * @return the _phi0 + */ + public double getPhi0() { + return _phi0; + } + + /** + * @param _phi0 the _phi0 to set + */ + public void setPhi0(double _phi0) { + this._phi0 = _phi0; + } + + /** + * @return the _omega + */ + public double getOmega() { + return _omega; + } + + /** + * @param _omega the _omega to set + */ + public void setOmega(double _omega) { + this._omega = _omega; + } + + /** + * @return the _z0 + */ + public double getZ0() { + return _z0; + } + + /** + * @param _z0 the _z0 to set + */ + public void setZ0(double _z0) { + this._z0 = _z0; + } + + /** + * @return the _tanL + */ + public double getTanL() { + return _tanL; + } + + /** + * @param _tanL the _tanL to set + */ + public void setTanL(double _tanL) { + this._tanL = _tanL; + } + + /** + * @return the _turningSign + */ + public int getTurningSign() { + return _turningSign; + } + + /** + * @param _turningSign the _turningSign to set + */ + public void setTurningSign(int _turningSign) { + this._turningSign = _turningSign; + } + + /** + * @return the _R + */ + public double getR() { + return _R; + } + + /** + * @param _R the _R to set + */ + public void setR(double _R) { + this._R = _R; + } + + public void Reset(double d0, double phi0, double omega, double z0, double tanL, + double B){ + setD0(d0); + setPhi0(phi0); + setOmega(omega); + setZ0(z0); + setTanL(tanL); + setB(B); + + this.Update(); + } + public void Update() { + setR(1./Math.abs(getOmega())); + _xd = -getD0()*Math.sin(getPhi0()); + _yd = getD0()*Math.cos(getPhi0()); + setXc(-(_turningSign*_R + _d0)*Math.sin(getPhi0())); + setYc((_turningSign*_R + _d0)*Math.cos(getPhi0())); + setX(getX(tFlightLen)); + setY(getY(tFlightLen)); + setZ(getZ(tFlightLen)); + setPx(getPx(getB(), tFlightLen)); + setPy(getPy(getB(), tFlightLen)); + setPz(getPz(getB())); + } + + public double getLAtPlane(double X1, double Y1, double X2, double Y2, + double tolerance) { + // Find the intersection of the helix circle with the module plane projection in XY which is a line + // Plane representative line equation y = mx +d + double X = 0; + double Y = 0; + if (X2 - X1 == 0) { + X = X1; + double y1 = getYc() + Math.sqrt(getR() * getR() - (X - getXc()) * (X - getXc())); + double y2 = getYc() - Math.sqrt(getR() * getR() - (X - getXc()) * (X - getXc())); + + if (Math.abs(y1 - Y1) < Math.abs(Y2 - Y1)+tolerance) { + Y = y1; + } else { + if (Math.abs(y2 - Y2) < Math.abs(Y2 - Y1)+tolerance) { + Y = y2; + } + } + } + if (Y2 - Y1 == 0) { + Y = Y1; + double x1 = getXc() + Math.sqrt(getR() * getR() - (Y - getYc()) * (Y - getYc())); + double x2 = getXc() - Math.sqrt(getR() * getR() - (Y - getYc()) * (Y - getYc())); + + if (Math.abs(x1 - X1) < Math.abs(X2 - X1)+tolerance) { + X = x1; + } else { + if (Math.abs(x2 - X1) < Math.abs(X2 - X1)+tolerance) { + X = x2; + } + } + } + + if (X2 - X1 != 0 && Y2 - Y1 != 0) { + double m = (Y2 - Y1) / (X2 - X1); + double d = Y1 - X1 * m; + + //double del = r*r*(1+m*m) - (yc-m*xc-d)*(yc-m*xc-d); + double del = (getXc() + (-d + getYc()) * m) * (getXc() + (-d + getYc()) * m) - + (1 + m * m) * (getXc() * getXc() + (d - getYc()) * (d - getYc()) - getR()*getR()); + if (del < 0) { + System.err.println("Helix Plane Intersection error - Returning 0 "); + return 0; + } + double x1 = (getXc() + (-d + getYc()) * m + Math.sqrt(del)) / (1 + m * m); + double x2 = (getXc() + (-d + getYc()) * m - Math.sqrt(del)) / (1 + m * m); + + if (Math.abs(x1 - X1) < Math.abs(X2 - X1)+tolerance) { + X = x1; + } else { + if (Math.abs(x2 - X1) < Math.abs(X2 - X1)+tolerance) { + X = x2; + } + } + double y1 = getYc() + Math.sqrt(getR() * getR() - (X - getXc()) * (X - getXc())); + double y2 = getYc() - Math.sqrt(getR() * getR() - (X - getXc()) * (X - getXc())); + + if (Math.abs(y1 - Y1) < Math.abs(Y2 - Y1)+tolerance) { + Y = y1; + } else { + if (Math.abs(y2 - Y1) < Math.abs(Y2 - Y1)+tolerance) { + Y = y2; + } + } + } + + double phi1 = Math.atan2(_yd -getYc(), _xd -getXc()); + double phi2 = Math.atan2(Y -getYc(), X -getXc()); + double dphi = phi2 - phi1; + // put dphi in (-pi, pi) + if (dphi > Math.PI) { + dphi -= 2. * Math.PI; + } + if (dphi < -Math.PI) { + dphi += 2. * Math.PI; + } + + return dphi/getOmega(); + } + + + + public Point3D getHelixPointAtPlane(double X1, double Y1, double X2, double Y2, + double tolerance) { + double l = getLAtPlane(X1, Y1, X2, Y2, tolerance); + return new Point3D(getX(l),getY(l),getZ(l)); + } + public Vector3D getMomentumAtPlane(double X1, double Y1, double X2, double Y2, + double tolerance) { + double l = getLAtPlane(X1, Y1, X2, Y2, tolerance); + return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); + } + + /** + * + * @param r radius + * @return Computes intersection of helix with circle centered at 0 and of radius R + */ + public double getLAtR(double r) { + + double x; + double y; + + double a = 0.5 * (r * r - getR() * getR() + getXc() * getXc() + getYc() * getYc()) / getYc(); + double b = -getXc() / getYc(); + + double delta = a * a * b * b - (1 + b * b) * (a * a - r * r); + + double xp = (-a * b + Math.sqrt(delta)) / (1 + b * b); + double xm = (-a * b - Math.sqrt(delta)) / (1 + b * b); + + double yp = a + b * xp; + double ym = a + b * xm; + + double Cp = new Vector3D(xp,yp,0).asUnit().dot(new Vector3D(Math.cos(getPhi0()), Math.sin(getPhi0()),0)); + double Cm = new Vector3D(xm,ym,0).asUnit().dot(new Vector3D(Math.cos(getPhi0()), Math.sin(getPhi0()),0)); + + if(Cp > Cm) { + x = xp; + y = yp; + } else { + x = xm; + y = ym; + } + + double phi1 = Math.atan2(_yd -getYc(), _xd -getXc()); + double phi2 = Math.atan2(y -getYc(), x -getXc()); + double dphi = phi2 - phi1; + // put dphi in (-pi, pi) + if (dphi > Math.PI) { + dphi -= 2. * Math.PI; + } + if (dphi < -Math.PI) { + dphi += 2. * Math.PI; + } + + return dphi/getOmega(); + } + public Point3D getHelixPointAtR(double r) { + double l = getLAtR( r); + return new Point3D(getX(l),getY(l),getZ(l)); + } + public Vector3D getMomentumAtR(double r) { + double l = getLAtR( r); + return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); + } + public double getLAtZ(double z) { + return (z - getZ0())/getTanL(); + } + public Point3D getHelixPointAtZ(double z) { + double l = getLAtZ( z); + return new Point3D(getX(l),getY(l),getZ(l)); + } + public Vector3D getMomentumAtZ(double z) { + double l = getLAtZ( z); + return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); + } + /** + * @return the _x + */ + public double getX() { + return _x; + } + + /** + * @param _x the _x to set + */ + public void setX(double _x) { + this._x = _x; + } + + /** + * @return the _y + */ + public double getY() { + return _y; + } + + /** + * @param _y the _y to set + */ + public void setY(double _y) { + this._y = _y; + } + + /** + * @return the _z + */ + public double getZ() { + return _z; + } + + /** + * @param _z the _z to set + */ + public void setZ(double _z) { + this._z = _z; + } + + /** + * @return the _px + */ + public double getPx() { + return _px; + } + + /** + * @param _px the _px to set + */ + public void setPx(double _px) { + this._px = _px; + } + + /** + * @return the _py + */ + public double getPy() { + return _py; + } + + /** + * @param _py the _py to set + */ + public void setPy(double _py) { + this._py = _py; + } + + /** + * @return the _pz + */ + public double getPz() { + return _pz; + } + + /** + * @param _pz the _pz to set + */ + public void setPz(double _pz) { + this._pz = _pz; + } + + /** + * @return the _xc + */ + public double getXc() { + return _xc; + } + + /** + * @param _xc the _xc to set + */ + public void setXc(double _xc) { + this._xc = _xc; + } + + /** + * @return the _yc + */ + public double getYc() { + return _yc; + } + + /** + * @param _yc the _yc to set + */ + public void setYc(double _yc) { + this._yc = _yc; + } + + + public enum Units { + MM (10.0), + CM (1.0); + + private final double unit; + Units(double unit) { + this.unit = unit; + } + private double unit() { return unit; } + } + + /** + * @return the unitScale + */ + public double getUnitScale() { + return unitScale; + } + + /** + * @param aUnitScale the unitScale to set + */ + public void setUnitScale(double aUnitScale) { + unitScale = aUnitScale; + } + + /** + * @return the LightVel + */ + public double getLIGHTVEL() { + return LightVel; + } + + /** + * @param aLIGHTVEL the LightVel to set + */ + public void setLIGHTVEL(double aLIGHTVEL) { + LightVel = aLIGHTVEL; + } + + public static final double LIGHTVEL = 0.0000299792458; // velocity of light (cm/ns) - conversion factor from radius in mm to momentum in GeV/c + + private static double LightVel = 0.0000299792458; // velocity of light (cm/ns) - conversion factor from radius in mm to momentum in GeV/c + private static double unitScale = 1; +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java new file mode 100644 index 000000000..a6f4c437e --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java @@ -0,0 +1,103 @@ +/* + * 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.tracking.trackrep; + +import java.util.ArrayList; +import java.util.List; +import org.jlab.clas.tracking.objects.TObject; + +/** + * + * @author ziegler + */ +public class Seed extends ArrayList { + + public Seed(){ + } + public Seed(int id) { + _id = id; + } + public Seed(int id, List tobjects) { + _id = id; + this.addAll(tobjects); + } + /** + * @return the _id + */ + public int getId() { + return _id; + } + + /** + * @param _id the _id to set + */ + public void setId(int _id) { + this._id = _id; + } + + /** + * @return the _qualFac + */ + public double getQualFac() { + return _qualFac; + } + + /** + * @param _qualFac the _qualFac to set + */ + public void setQualFac(double _qualFac) { + this._qualFac = _qualFac; + } + + /** + * @return the _overlapFlag + */ + public int getOverlapFlag() { + return _overlapFlag; + } + + /** + * @param _overlapFlag the _overlapFlag to set + */ + public void setOverlapFlag(int _overlapFlag) { + this._overlapFlag = _overlapFlag; + } + + /** + * @return the _tobjects + */ + public List getTObjects() { + return this; + } + + /** + * @param to the _tobjects to set + */ + public void setTObjects(List to) { + this.addAll(to); + } + + /** + * @return the _overlaps + */ + public List getOverlaps() { + return _overlaps; + } + + /** + * @param _overlaps the _overlaps to set + */ + public void setOverlaps(List _overlaps) { + this._overlaps = _overlaps; + } + + private int _id; + private double _qualFac; + private int _overlapFlag = 0; //0: not an overlap; 1: an overlap with another seed + private List _overlaps; + + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java new file mode 100644 index 000000000..27a0fbef9 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java @@ -0,0 +1,63 @@ +/* + * 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.tracking.trackrep; + +import java.util.List; + +/** + * + * @author ziegler + */ +public class Trajectory { + + /** + * @return the _X + */ + public List getX() { + return _X; + } + + /** + * @param _X the _X to set + */ + public void setX(List _X) { + this._X = _X; + } + + /** + * @return the _Y + */ + public List getY() { + return _Y; + } + + /** + * @param _Y the _Y to set + */ + public void setY(List _Y) { + this._Y = _Y; + } + + /** + * @return the _Z + */ + public List getZ() { + return _Z; + } + + /** + * @param _Z the _Z to set + */ + public void setZ(List _Z) { + this._Z = _Z; + } + + private List _X; + private List _Y; + private List _Z; + + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java new file mode 100644 index 000000000..d29050334 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java @@ -0,0 +1,134 @@ +/* + * 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.tracking.utilities; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import org.jlab.clas.tracking.objects.TObject; +import org.jlab.clas.tracking.trackrep.Seed; + +/** + * + * @author ziegler + */ +public class OverlapRemover { + + private boolean contains(Seed s0, List set) { + boolean isc = false; + List c0 = s0.getTObjects(); + c0.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + + for(int i = 0; i < set.size(); i++) { + List c1 = set.get(i).getTObjects(); + c1.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + + if(c1.size() == c0.size()) { + int n = 0; + for(int k =0; k < c1.size(); k++) { + if(c1.get(k).equals(c0.get(k))) + n++; + } + if(n == c1.size()) + isc = true; + } + } + + return isc; + } + + private boolean equals(List c0, List c1) { + boolean isc = false; + + c0.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + c1.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + if(c1.size() == c0.size()) { + int n = 0; + for(int k =0; k < c1.size(); k++) { + if(c1.get(k).equals(c0.get(k))) + n++; + } + if(n == c1.size()) + isc = true; + } + + return isc; + } + + private List findOverlapObjects(List c0, List c1) { + List covrl = new ArrayList(); + c0.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + c1.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); + + //List largerCList = ((c0.size()>c1.size()) ? c0 : c1); + for(TObject ci : c0) { + for(TObject cj : c1) { + if(ci.equals(cj)) { + covrl.add(cj); + } + } + } + System.out.println("Comparing lists "); + for(TObject c : c0) { + System.out.println("c0: "+c.getX()); + } + for(TObject c : c1) { + System.out.println("c1: "+c.getX()); + } + for(TObject c : covrl) { + System.out.println("covrl: "+c.getX()); + } + return covrl; + } + private boolean equalLists(List c0, List c1) { + if(c0.size()!=c1.size()) { + return false; + } + boolean eq = true; + for(int i = 0; i < c0.size(); i++) { + if(c0.get(i).equals(c1.get(i))) { //un-matched objects + eq = false; + } + } + return eq; + } + + public void flagOverlap(Seed s0, Seed s1) { + List ovrl = this.findOverlapObjects(s0.getTObjects(), s1.getTObjects()); + if(ovrl == null) { + return; + } + if(ovrl.size()==s0.size()) { + s0.setOverlapFlag(1); + } else { + s1.setOverlapFlag(1); + } + } + + public void removeDuplicates(List seeds) { + List dupl = new ArrayList(); + for(int i = 0; i < seeds.size(); i++) { + Seed ci = seeds.get(i); + seeds.remove(i); //exlude it from list + if(this.contains(ci, seeds)) { + dupl.add(ci); + } + seeds.add(ci); //put it back + } + seeds.removeAll(dupl); + } + + public void flagOverlaps(List seeds) { + //clean up the list + this.removeDuplicates(seeds); + //flag overlaps + for(int i = 0; i < seeds.size()-1; i++) { + for(int j = i+1; j < seeds.size(); j++) { + this.flagOverlap(seeds.get(i), seeds.get(j)); + } + } + } +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java new file mode 100644 index 000000000..ac743e951 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java @@ -0,0 +1,77 @@ +/* + * 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.tracking.utilities; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.io.hipo.HipoDataSync; + +/** + * + * @author ziegler + */ +public class SelectEventsToFile { + public static void main(String[] args) throws FileNotFoundException { + String[] splited ; + BufferedReader reader; + Map evts = new HashMap(); + try { + reader = new BufferedReader(new FileReader("/Users/ziegler/Desktop/Base/CodeDevel/Validation/hipo4Validation/selEvts.txt")); + try { + String line = reader.readLine(); + while(line != null) { + splited = line.split("\\s+"); + evts.put(Integer.parseInt(splited[1]), Integer.parseInt(splited[0])); + + line = reader.readLine(); + } + } catch (IOException ex) { + Logger.getLogger(SelectEventsToFile.class.getName()).log(Level.SEVERE, null, ex); + } + + } catch (FileNotFoundException ex) { + Logger.getLogger(SelectEventsToFile.class.getName()).log(Level.SEVERE, null, ex); + } + + String inputFile = "/Users/ziegler/Desktop/Base/CodeDevel/Validation/hipo4Validation/infiles/sidis.hipo"; + + HipoDataSource hiporeader = new HipoDataSource(); + hiporeader.open(inputFile); + + HipoDataSync writer = new HipoDataSync(); + //Writer + + String outputFile = "/Users/ziegler/Desktop/Base/CodeDevel/Validation/hipo4Validation/infiles/sidisFilt.hipo"; + + writer.open(outputFile); + + while (hiporeader.hasEvent()) { + + DataEvent event = hiporeader.getNextEvent(); + + DataBank bank = event.getBank("RUN::config"); + + int run = bank.getInt("run", 0); + int evt = bank.getInt("event", 0); + if(evts.get(evt)!=null && evts.get(evt).intValue()==run) { + writer.writeEvent(event); + System.out.println("PROCESSED EVENT " + event.getBank("RUN::config").getInt("event", 0)); + } + + } + writer.close(); + + } +} diff --git a/common-tools/coat-lib/pom.xml b/common-tools/coat-lib/pom.xml index 61d1f15b1..bf60a65ed 100644 --- a/common-tools/coat-lib/pom.xml +++ b/common-tools/coat-lib/pom.xml @@ -133,6 +133,13 @@ swim-tools 6.5.11-SNAPSHOT + + + org.jlab.clas + clas-tracking + 6.5.11-SNAPSHOT + + match C "+closestCross.toString()); matchedMMCrosses.add(closestCross); } } @@ -957,14 +932,14 @@ private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosse if (Math.acos(cosAngMeasToTrk) < Math.acos(minCosAngMeasToTrk)) { minCosAngMeasToTrk = cosAngMeasToTrk; - closestCross = MMCrosses.get(i); + closestCross = (Cross) MMCrosses.get(i).clone(); closestCross.set_Point(new Point3D(m_x, m_y, z)); closestCross.set_PointErr(new Point3D(MMCrosses.get(i).get_PointErr().x(), MMCrosses.get(i).get_PointErr().y(), 10.)); // to do : put in the correct error } } if (closestCross != null) { //if(minCosAngMeasToTrk sVTclusters, TrajectoryFinder tf, org.jl continue; } if (Math.abs(st.get_CalcCentroidStrip() - cls.get_Centroid()) < 4) { - //tf.setHitResolParams("SVT", cls.get_Sector(), cls.get_Layer(), cls, - // st, svt_geo, bmt_geo, trajFinal); + tf.setHitResolParams("SVT", cls.get_Sector(), cls.get_Layer(), cls, + st, svt_geo, bmt_geo, trajFinal); //System.out.println("trying to associate a cluster ");cls.printInfo(); System.out.println(" to "+st.get_CalcCentroidStrip()+" dStp = "+(st.get_CalcCentroidStrip()-cls.get_Centroid())); cls.set_AssociatedTrackID(k); for (FittedHit h : cls) { From cc600a5902f62a52a33fd4b0526bb84604c45a1d Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 27 Oct 2020 13:45:50 -0400 Subject: [PATCH 020/291] Update BMT cross information done in RecUtilities class. --- .../java/org/jlab/rec/cvt/services/RecUtilities.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 80c40006c..1845bac3a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -178,8 +178,17 @@ public void MatchTrack2Traj(Seed trkcand, Map Date: Tue, 27 Oct 2020 19:03:16 +0100 Subject: [PATCH 021/291] First commit of new BMT geometry based on Line3D and Arc3D --- .../org/jlab/rec/cvt/bmt/BMTgeometry.java | 307 ++++++++++++++++++ .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 20 +- .../java/org/jlab/rec/cvt/bmt/Constants.java | 8 + 3 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java new file mode 100644 index 000000000..b650f2a86 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java @@ -0,0 +1,307 @@ +package org.jlab.rec.cvt.bmt; + +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; + +/** + * + * @author devita + */ +public class BMTgeometry { + + private final static int[] lZ = { 2, 3, 5}; + private final static int[] lC = { 1, 4, 6}; + + + /** + * + */ + public BMTgeometry() { + } + + /** + * Return layer number for a given region and detector type + * @param region (1-3) + * @param detector (C or Z) + * @return layer (1-6) + */ + public int getLayer(int region, String detector) { + int layer = -1; + if(region>=1 && region<=3) { + if( detector.equalsIgnoreCase("Z") ) { + layer = lZ[ region - 1 ]; + } + if( detector.equalsIgnoreCase("C") ) { + layer = lC[ region - 1 ]; + } + } + return layer; + } + + /** + * Return region number for a given layer + * @param layer (1-6) + * @return region (1-3) + */ + public int getRegion(int layer) { + int region = -1; + if(layer>=1 && layer<=6) { + region = (int) Math.floor((layer+1)/2); + } + return region; + } + + + /** + * Return region number for a given layer + * @param layer (1-6) + * @return type ("C" or "Z"); + */ + public String getDetectorType(int layer) { + if(layer == 1 || layer == 4 || layer == 6) return "C"; + else if(layer == 2 || layer == 3 || layer == 5) return "Z"; + else return null; + } + + + /** + * Return radius of the selected layer + * @param layer (1-6) + * @return radius (=0 if layer is out of range) + */ + public double getRadius(int layer) { + + int region = this.getRegion(layer); + String det = this.getDetectorType(layer); + + double radius = 0; + if(region>0 && det!=null) { + if (det.equalsIgnoreCase("C")) radius = Constants.getCRCRADIUS()[region-1]; + else if(det.equalsIgnoreCase("Z")) radius = Constants.getCRZRADIUS()[region-1]; + } + return radius; + } + + /** + * Return offset of the selected tile, identified by layer and sector + * @param layer (1-6) + * @param sector (1-3) + * @return Point3D offset: 3D offset + */ + public Point3D getOffset(int layer, int sector) { + + Point3D offset = new Point3D(); + offset.copy(Constants.shifts[layer-1][sector-1]); + offset.translateXYZ(0, 0, org.jlab.rec.cvt.Constants.getZoffset()); + + return offset; + } + + /** + * Return rotations for the selected tile, identified by layer and sector + * @param layer (1-6) + * @param sector (1-3) + * @return Point3D offset: 3D offset + */ + public Vector3D getRotation(int layer, int sector) { + + return Constants.rotations[layer-1][sector-1]; + } + + + /** + * Returns Line3D for Z detector strip identified from region, sector, strip numbers, for ideal geometry + * @param region + * @param sector + * @param strip + * @return Line3D + */ + public Line3D getIdealZstrip(int region, int sector, int strip) { + + double radius = Constants.getCRZRADIUS()[region-1]; + double zmin = Constants.getCRCZMIN()[region-1]; + double zmax = Constants.getCRCZMAX()[region-1]; + double angle = Constants.getCRZEDGE1()[region-1][sector-1] + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; + + Point3D p1= new Point3D(radius, 0, zmin); + p1.rotateZ(angle); + Point3D p2= new Point3D(radius, 0, zmax); + p2.rotateZ(angle); + + Line3D stripline = new Line3D(p1,p2); + + return stripline; + } + + /** + * Returns Line3D for Z detector strip identified from region, sector, strip numbers, for real geometry + * @param region + * @param sector + * @param strip + * @return stripline + */ + public Line3D getZstrip(int region, int sector, int strip) { + + int layer = this.getLayer(region, "Z"); + Line3D stripline = this.getIdealZstrip(region, sector, strip); + + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + stripline.rotateX(rotation.x()); + stripline.rotateY(rotation.y()); + stripline.rotateZ(rotation.z()); + stripline.translateXYZ(offset.x(),offset.y(),offset.z()); + + + return stripline; + } + + + /** + * Returns the Z position of the selected C-detector strip in the local frame + * @param region + * @param strip + * @return zc + */ + public double getCstripZ(int region, int strip) { + + //For CR6C, this function returns the Z position of the strip center + int group = 0; + int limit = Constants.getCRCGROUP()[region-1][group]; + double zc = Constants.getCRCZMIN()[region-1]; + + if (strip > 1) { + for (int j = 1; j < strip; j++) { + zc += Constants.getCRCWIDTH()[region-1][group]; + if (j >= limit) { //test if we change the width + group++; + limit += Constants.getCRCGROUP()[region-1][group]; + } + } + } + zc += Constants.getCRCWIDTH()[region-1][group]/2.; + return zc; //in mm + } + + /** + * Returns Arc3D corresponding to the selected C-detector strip according to ideal geometry (local frame) + * @param region (1-3) + * @param sector (1-3) + * @param strip + * @return Arc3D striparc + */ + public Arc3D getIdealCstrip(int region, int sector, int strip) { + + double radius = Constants.getCRCRADIUS()[region-1]; + double angle = Constants.getCRCEDGE1()[region-1][sector-1] + Constants.getCRCXPOS()[region-1] / Constants.getCRCRADIUS()[region-1]; + double theta = (Constants.getCRCXPOS()[region-1]+Constants.getCRCLENGTH()[region-1]) / Constants.getCRCRADIUS()[region-1]; + double z = this.getCstripZ(region, strip); + + Point3D origin = new Point3D(radius,0,z); + origin.rotateZ(angle); + Point3D center = new Point3D(0,0,z); + Vector3D normal = new Vector3D(0,0,1); + + Arc3D striparc = new Arc3D(origin,center,normal,theta); + return striparc; + } + + /** + * Returns Arc3D corresponding to the selected C-detector strip according to real geometry + * @param region + * @param sector + * @param strip + * @return + */ + public Arc3D getCstrip(int region, int sector, int strip) { + + int layer = this.getLayer(region, "C"); + Arc3D arcline = this.getIdealCstrip(region, sector, strip); + + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + arcline.rotateX(rotation.x()); + arcline.rotateY(rotation.y()); + arcline.rotateZ(rotation.z()); + arcline.translateXYZ(offset.x(),offset.y(),offset.z()); + + return arcline; + } + + /** + * Return the number of the closest strip to the given trajectory point + * Detector mis-alignments geometry are taken into account by transforming + * the trajectory point to detector local frame + * @param layer (1-6) + * @param sector (1-3) + * @param traj trajectory point on the layer surface in the lab + * @return strip number (0 if the point is not within the active area) + */ + public int getStrip(int layer, int sector, Point3D traj) { + + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); + traj.rotateZ(-rotation.z()); + traj.rotateY(-rotation.y()); + traj.rotateX(-rotation.x()); + + return this.getStripLocal(layer, sector, traj); + } + + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param layer (1-6) + * @param sector (1-3) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + public int getStripLocal(int layer, int sector, Point3D traj) { + + String type = this.getDetectorType(layer); + + if(type == null) return 0; + + if(type.equalsIgnoreCase("C")) { + return this.getCstrip(layer,traj); + } + else if(type.equalsIgnoreCase("Z")) { + return this.getZstrip(layer,traj); + } + else return 0; + } + + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param layer (1-6) + * @param sector (1-3) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + public int getCstrip(int region, Point3D traj) { + + int strip = 0; + return strip; + } + + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param layer (1-6) + * @param sector (1-3) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + public int getZstrip(int region, Point3D traj) { + + int strip = 0; + return strip; + } + + + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 6ef02369c..714248ac6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -89,6 +89,9 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) dbprovider.loadTable("/calibration/mvt/bmt_hv/drift_fullfield"); dbprovider.loadTable("/calibration/mvt/bmt_hv/drift_midfield"); + //load alignment parameters + dbprovider.loadTable("/geometry/cvt/mvt/alignment"); + //beam offset table dbprovider.loadTable("/geometry/beam/position"); @@ -162,7 +165,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) EDGE2[j] = middle + ((double) Nstrips) * (CRZWIDTH[region - 1] / radius) / 2. - 0 * CRZWIDTH[region - 1] / radius; EDGE2[j] -= 2 * Math.PI; } - + } CRZEDGE1[region - 1] = EDGE1; CRZEDGE2[region - 1] = EDGE2; @@ -248,7 +251,20 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) HV_DRIFT_MF[i][2]=dbprovider.getDouble("/calibration/mvt/bmt_hv/drift_midfield/Sector_3", i); } - // beam offset + + // alignment + for (int i = 0; i Date: Wed, 28 Oct 2020 10:50:52 -0400 Subject: [PATCH 022/291] comment out debug statement --- .../src/main/java/org/jlab/clas/tracking/trackrep/Helix.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 4fffecca9..cc11e1c57 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -282,9 +282,9 @@ public double getLAtPlane(double X1, double Y1, double X2, double Y2, double del = (getXc() + (-d + getYc()) * m) * (getXc() + (-d + getYc()) * m) - (1 + m * m) * (getXc() * getXc() + (d - getYc()) * (d - getYc()) - getR()*getR()); if (del < 0) { - System.err.println("Helix Plane Intersection error - Returning 0 "); + //System.err.println("Helix Plane Intersection error - Returning 0 "); return 0; - } + } double x1 = (getXc() + (-d + getYc()) * m + Math.sqrt(del)) / (1 + m * m); double x2 = (getXc() + (-d + getYc()) * m - Math.sqrt(del)) / (1 + m * m); From 1a329c294613323a550e9c82188cf2cda53d73af Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 28 Oct 2020 10:51:24 -0400 Subject: [PATCH 023/291] Improved seeding algorithm --- .../java/org/jlab/rec/cvt/cross/Cross.java | 1 + .../rec/cvt/services/TracksFromTargetRec.java | 6 +++++- .../org/jlab/rec/cvt/track/TrackSeeder.java | 20 +++++++++++++++---- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 6 +++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index b906d9be5..c1b48981a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -22,6 +22,7 @@ public class Cross extends ArrayList implements Comparable { * serial id */ private static final long serialVersionUID = 5317526429163382618L; + public boolean isInSeed = false; /** * @param detector SVT or BMT diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 337cf0426..2e5bb7c1b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -61,7 +61,11 @@ public boolean processEvent(DataEvent event, } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); + seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); + //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA + TrackSeeder trseed2 = new TrackSeeder(); + trseed2.unUsedHitsOnly = true; + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); } } if(seeds ==null || seeds.size() == 0) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 16e1b826e..ab25ca6d8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -25,6 +25,7 @@ public class TrackSeeder { List Xs ; List Ys ; List Ws ; + public boolean unUsedHitsOnly = false; public TrackSeeder() { //init lists for scan @@ -207,23 +208,30 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); - public List findSeed(List svt_crosses, List bmt_crosses, + public List findSeed(List bst_crosses, List bmt_crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, Swim swimmer) { List seedlist = new ArrayList(); List crosses = new ArrayList(); + List svt_crosses = new ArrayList(); List bmtC_crosses = new ArrayList(); if(bmt_crosses!=null) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType().equalsIgnoreCase("Z")) + if(c.get_DetectorType().equalsIgnoreCase("Z") && this.unUsedHitsOnly == true) crosses.add(c); - if(c.get_DetectorType().equalsIgnoreCase("C")) + if(c.get_DetectorType().equalsIgnoreCase("C") && this.unUsedHitsOnly == true) bmtC_crosses.add(c); } } + if(bst_crosses!=null) { + for(Cross c : bst_crosses) { + if(this.unUsedHitsOnly == true) + svt_crosses.add(c); + } + } this.FindSeedCrossList(svt_crosses); this.MatchSeed(crosses); @@ -329,7 +337,11 @@ public List findSeed(List svt_crosses, List bmt_crosses, } } } - + for (Seed bseed : seedlist) { + for(Cross c : bseed.get_Crosses()) { + c.isInSeed = true; + } + } return seedlist; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 387137d74..996e13c78 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -261,7 +261,11 @@ public List findSeed(List svt_crosses, List bmt_crosses, } seed.set_Clusters(clusters); } - + for (Seed bseed : seedlist) { + for(Cross c : bseed.get_Crosses()) { + c.isInSeed = true; + } + } return seedlist; } From 3be8bc64e160375044f3a047cc2067909646345b Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 18:16:43 -0400 Subject: [PATCH 024/291] Proper handling of the beam spot and target shift in the new KF. --- .../kalmanfilter/helical/StateVecs.java | 45 +++---------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index d10e5d762..0e510f004 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -33,7 +33,7 @@ public class StateVecs { public List X0; public List Y0; public List Z0; // reference points - + public double shift; // target shift public List Layer; public List Sector; @@ -466,11 +466,10 @@ private void setHelix(Helix util, double x0, double y0, double z0, double px0, d double S = Math.sin(util.getPhi0()); double C = Math.cos(util.getPhi0()); - if(Math.abs(S)>=Math.abs(C)) { - util.setD0(-x0/S) ; + util.setD0(-(x0-X0.get(0))/S) ; } else { - util.setD0(y0/C) ; + util.setD0((y0-Y0.get(0))/C) ; } util.Update(); @@ -608,7 +607,7 @@ public class B { this.y = y; this.z = z; - swimmer.BfieldLab(x/units, y/units, z/units, b); + swimmer.BfieldLab(x/units, y/units, z/units + shift/units, b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; @@ -617,7 +616,7 @@ public class B { } public void set() { - swimmer.BfieldLab(x/units, y/units, z/units, b); + swimmer.BfieldLab(x/units, y/units, z/units + shift/units, b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; @@ -713,38 +712,6 @@ public Vector3D X0(int kf) { } - public Helix getHelixAtBeamLine(int k, Swim swim) { - this.resetArrays(swimPars); - StateVec kVec = this.trackTraj.get(k); - double x0 = kVec.x ; - double y0 = kVec.y ; - double z0 = kVec.z ; - - Vector3D p = this.P(k); - double px0 = p.x(); - double py0 = p.y(); - double pz0 = p.z(); - int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); - - swim.SetSwimParameters( - x0/units, - y0/units, - z0/units, - -px0, -py0, -pz0, -ch); - - swimPars = swim.SwimToBeamLine(X0.get(0), Y0.get(0)); - - for(int j =0; j < 3; j++) { - swimPars[j]*=units; - } - - int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(k).kappa); - double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel; - - this.setHelix(util, swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], q, B); - - return util; - } public Helix setTrackPars() { Vector3D X = this.X0(0); Vector3D P = this.P0(0); @@ -752,7 +719,7 @@ public Helix setTrackPars() { int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(0).kappa); double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel ; - return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, util.units); + return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, X0.get(0), Y0.get(0), util.units); } public StateVec initSV = new StateVec(0); public void init(Helix trk, Matrix cov, KFitter kf, From 94bc6e646048ecd090a28acc14163c4ca28637c4 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 18:17:35 -0400 Subject: [PATCH 025/291] Avoid zero denominator in numeric projector computation. --- .../clas/tracking/kalmanfilter/helical/MeasVecs.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 4d9d39b52..e826b9b21 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -129,11 +129,11 @@ public double h(int k, StateVec stateVec) { public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim swimmer, int dir) { StateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); StateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); - delta_d_a[0]=2*sqrt_epsilon*stateVec.d_rho; - delta_d_a[1]=2*sqrt_epsilon*stateVec.phi0; - delta_d_a[2]=2*sqrt_epsilon*stateVec.kappa; - delta_d_a[3]=2*sqrt_epsilon*stateVec.dz; - delta_d_a[4]=2*sqrt_epsilon*stateVec.tanL; + delta_d_a[0]=2*sqrt_epsilon*(stateVec.d_rho+1); + delta_d_a[1]=2*sqrt_epsilon*(stateVec.phi0+1); + delta_d_a[2]=2*sqrt_epsilon*(stateVec.kappa+1); + delta_d_a[3]=2*sqrt_epsilon*(stateVec.dz+1); + delta_d_a[4]=2*sqrt_epsilon*(stateVec.tanL+1); for(int i = 0; i < getHval().length; i++) getHval()[i] = 0; From 58f2e378066e00d7c1172e707e98fe6d8f1068e8 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 18:19:12 -0400 Subject: [PATCH 026/291] Proper handling of shift setting in KFitter --- .../kalmanfilter/helical/KFitter.java | 64 +++++++++++++++---- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 135a826d7..8a7365e5f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -26,8 +26,8 @@ public class KFitter { MeasVecs mv = new MeasVecs(); public StateVec finalStateVec; - - private double _Xb; + private double _tarShift; //targetshift + private double _Xb; //beam axis pars private double _Yb; private double resiCut = 100;//residual cut for the measurements @@ -39,13 +39,14 @@ public KFitter(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb double Zref, List measSurfaces) { _Xb = Xb; _Yb = Yb; + _tarShift = Zref; this.init(helix, cov, event, swimmer, Xb, Yb, Zref, mv, measSurfaces); } //private Matrix iCov; public void init(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb, double Yb, double Zref, MeasVecs mv, List measSurfaces) { - + sv.shift = Zref; //iCov = cov; mv.setMeasVecs(measSurfaces); if (sv.Layer != null) { @@ -78,11 +79,11 @@ public void init(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double sv.Sector.add(0); sv.X0.add(Xb); sv.Y0.add(Yb); - sv.Z0.add(Zref); + sv.Z0.add(0.0); for (int i = 1; i < mv.measurements.size(); i++) { sv.Layer.add(mv.measurements.get(i).layer); sv.Sector.add(mv.measurements.get(i).sector); - Point3D ref = new Point3D(Xb, Yb, Zref); + Point3D ref = new Point3D(Xb, Yb, 0.0); sv.X0.add(ref.x()); sv.Y0.add(ref.y()); sv.Z0.add(ref.z()); @@ -129,8 +130,8 @@ public void runFitter(Swim swimmer) { } sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), swimmer); - if(k>1) - this.filter(k - 1, swimmer, -1); + if(k>1) + this.filter(k - 1, swimmer, -1); } // chi2 @@ -139,7 +140,6 @@ public void runFitter(Swim swimmer) { newchisq=this.chi2; KFHelix = sv.setTrackPars(); finalStateVec = sv.trackTraj.get(0); - //KFHelix = sv.getHelixAtBeamLine(1, swimmer); this.setTrajectory(); setFitFailed = false; } else { @@ -189,7 +189,7 @@ private double calc_chi2(Swim swimmer) { int ndf = -5; StateVec stv = sv.transported(0, 1, sv.trackTraj.get(0), mv.measurements.get(1), swimmer); double dh = mv.dh(1, stv); - if(mv.measurements.get(1).skip==false) { + if(mv.measurements.get(1).skip==false) { chi2 = dh*dh / mv.measurements.get(1).error; ndf++; } @@ -237,7 +237,7 @@ private void filter(int k, Swim swimmer, int dir) { } Matrix Ca = null; try { - Ca = Ci.plus(new Matrix(HTGH)); + Ca = Ci.plus(new Matrix(HTGH)); } catch (Exception e) { return; } @@ -304,7 +304,7 @@ private void filter(int k, Swim swimmer, int dir) { sv.trackTraj.get(k).phi = fVec.phi; sv.trackTraj.get(k).x = fVec.x; sv.trackTraj.get(k).y = fVec.y; - sv.trackTraj.get(k).z = fVec.z; + sv.trackTraj.get(k).z = fVec.z; } else { this.NDF--; mv.measurements.get(k).skip = true; @@ -312,6 +312,48 @@ private void filter(int k, Swim swimmer, int dir) { } } + /** + * @return the _Xb + */ + public double getXb() { + return _Xb; + } + + /** + * @param _Xb the _Xb to set + */ + public void setXb(double _Xb) { + this._Xb = _Xb; + } + + /** + * @return the _Yb + */ + public double getYb() { + return _Yb; + } + + /** + * @param _Yb the _Yb to set + */ + public void setYb(double _Yb) { + this._Yb = _Yb; + } + + /** + * @return the _tarShift + */ + public double getTarShift() { + return _tarShift; + } + + /** + * @param _TarShift the _tarShift to set + */ + public void setTarShift(double _TarShift) { + this._tarShift = _TarShift; + } + /** * prints the matrix -- used for debugging * From 0e870edcfc70edf3a3cd69b83dc87624bf93b528 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 18:19:36 -0400 Subject: [PATCH 027/291] Proper handling of beam offset parameter in Helix class. --- .../jlab/clas/tracking/trackrep/Helix.java | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index cc11e1c57..efb2c68b0 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -31,6 +31,8 @@ public class Helix { private double _yd; private double _xc; private double _yc; + private double _xb; + private double _yb; private double _x; private double _y; private double _z; @@ -41,7 +43,7 @@ public class Helix { public Units units = Units.CM; //default public Helix(double d0, double phi0, double omega, double z0, double tanL, - int turningSign, double B, Units unit) { + int turningSign, double B, double xb, double yb, Units unit) { _d0 = d0; _phi0 = phi0; _omega = omega; @@ -49,6 +51,8 @@ public Helix(double d0, double phi0, double omega, double z0, double tanL, _tanL = tanL; _turningSign = turningSign; _B = B; + _xb = xb; + _yb = yb; this.units = unit; this.setUnitScale(unit.unit); setLIGHTVEL(LIGHTVEL*unit.unit); @@ -56,7 +60,7 @@ public Helix(double d0, double phi0, double omega, double z0, double tanL, } public Helix(double x0, double y0, double z0, double px0, double py0, double pz0, - int q, double B, Units unit) { + int q, double B, double xb, double yb, Units unit) { _turningSign = q; _B = B; double pt = Math.sqrt(px0*px0 + py0*py0); @@ -71,10 +75,12 @@ public Helix(double x0, double y0, double z0, double px0, double py0, double pz0 double S = Math.sin(_phi0); double C = Math.cos(_phi0); if(Math.abs(S)>=Math.abs(C)) { - _d0 = -x0/S; + _d0 = -(x0-xb)/S; } else { - _d0 = y0/C; + _d0 = (y0-yb)/C; } + _xb = xb; + _yb = yb; this.Update(); } @@ -229,10 +235,10 @@ public void Reset(double d0, double phi0, double omega, double z0, double tanL, } public void Update() { setR(1./Math.abs(getOmega())); - _xd = -getD0()*Math.sin(getPhi0()); - _yd = getD0()*Math.cos(getPhi0()); - setXc(-(_turningSign*_R + _d0)*Math.sin(getPhi0())); - setYc((_turningSign*_R + _d0)*Math.cos(getPhi0())); + _xd = -getD0()*Math.sin(getPhi0())+_xb; + _yd = getD0()*Math.cos(getPhi0())+_yb; + setXc(-(_turningSign*_R + _d0)*Math.sin(getPhi0())+_xb); + setYc((_turningSign*_R + _d0)*Math.cos(getPhi0())+_yb); setX(getX(tFlightLen)); setY(getY(tFlightLen)); setZ(getZ(tFlightLen)); @@ -509,6 +515,34 @@ public double getYc() { public void setYc(double _yc) { this._yc = _yc; } + + /** + * @return the _xb + */ + public double getXb() { + return _xb; + } + + /** + * @param _xb the _xb to set + */ + public void setXb(double _xb) { + this._xb = _xb; + } + + /** + * @return the _yb + */ + public double getYb() { + return _yb; + } + + /** + * @param _yb the _yb to set + */ + public void setYb(double _yb) { + this._yb = _yb; + } public enum Units { From c9f1085f88831072c44c476caba71cf40b68b34e Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 18:31:59 -0400 Subject: [PATCH 028/291] Include beam offset parameters xb, yb in CVT Track bank for CVT track vertex calculation in REC::Particle --- .../main/java/org/jlab/clas/detector/DetectorData.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java index e9dafb237..80cb326e8 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java @@ -596,13 +596,15 @@ public static List readCentralDetectorTracks(DataEvent event, St double tandip = bank.getFloat("tandip", row); double z0 = bank.getFloat("z0", row); double d0 = bank.getFloat("d0", row); - + double xb = bank.getFloat("xb", row); + double yb = bank.getFloat("yb", row); + double pz = pt*tandip; double py = pt*Math.sin(phi0); double px = pt*Math.cos(phi0); - double vx = -d0*Math.sin(phi0); - double vy = d0*Math.cos(phi0); + double vx = -d0*Math.sin(phi0)+xb; + double vy = d0*Math.cos(phi0)+yb; DetectorTrack track = new DetectorTrack(charge,p,row); track.setVector(px, py, pz); From cd9459db83b551672194117ed2e9b25c90edfa82 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Sat, 31 Oct 2020 19:12:12 -0400 Subject: [PATCH 029/291] Use analysis (mm) units for target shift in CVT. Proper passing of beam spot information to fitter. Fix to run SVT standalone. --- .../org/jlab/rec/cvt/banks/RecoBankWriter.java | 14 +++++++------- .../org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 4 ++-- .../org/jlab/rec/cvt/services/CVTRecNewKF.java | 2 +- .../jlab/rec/cvt/services/TracksFromTargetRec.java | 14 +++++++------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index b37f880f2..b4fd5af15 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -131,7 +131,7 @@ public DataBank fillSVTCrossesBank(DataEvent event, List> cross bank.setByte("region", index, (byte) crosses.get(i).get(j).get_Region()); bank.setFloat("x", index, (float) (crosses.get(i).get(j).get_Point().x()/10.)); bank.setFloat("y", index, (float) (crosses.get(i).get(j).get_Point().y()/10.)); - bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10.+zShift)); + bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10.+zShift/10)); bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).get_PointErr().x()/10.)); bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).get_PointErr().y()/10.)); bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).get_PointErr().z()/10.)); @@ -267,7 +267,7 @@ public DataBank fillBMTCrossesBank(DataEvent event, List> cross bank.setByte("region", index, (byte) crosses.get(i).get(j).get_Region()); bank.setFloat("x", index, (float) (crosses.get(i).get(j).get_Point().x()/10.)); bank.setFloat("y", index, (float) (crosses.get(i).get(j).get_Point().y()/10.)); - bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10.+zShift)); + bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10.+zShift/10.)); bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).get_PointErr().x()/10.)); bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).get_PointErr().y()/10.)); bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).get_PointErr().z()/10.)); @@ -332,7 +332,7 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh Helix helix = trkcands.get(i).get_helix(); bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); bank.setFloat("tandip", i, (float) helix.get_tandip()); - bank.setFloat("z0", i, (float) (helix.get_Z0()/10.+zShift)); + bank.setFloat("z0", i, (float) (helix.get_Z0()/10.+zShift/10)); bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); bank.setFloat("xb", i, (float) (org.jlab.rec.cvt.Constants.getXb()/10.0)); bank.setFloat("yb", i, (float) (org.jlab.rec.cvt.Constants.getYb()/10.0)); @@ -365,7 +365,7 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh } bank.setFloat("c_x", i, (float) (trkcands.get(i).get_TrackPointAtCTOFRadius().x() / 10.)); // convert to cm bank.setFloat("c_y", i, (float) (trkcands.get(i).get_TrackPointAtCTOFRadius().y() / 10.)); // convert to cm - bank.setFloat("c_z", i, (float) (trkcands.get(i).get_TrackPointAtCTOFRadius().z() / 10. + zShift)); // convert to cm + bank.setFloat("c_z", i, (float) (trkcands.get(i).get_TrackPointAtCTOFRadius().z() / 10. + zShift/10)); // convert to cm bank.setFloat("c_ux", i, (float) trkcands.get(i).get_TrackDirAtCTOFRadius().x()); bank.setFloat("c_uy", i, (float) trkcands.get(i).get_TrackDirAtCTOFRadius().y()); bank.setFloat("c_uz", i, (float) trkcands.get(i).get_TrackDirAtCTOFRadius().z()); @@ -434,7 +434,7 @@ public DataBank fillStraightTracksBank(DataEvent event, bank.setFloat("trkline_yx_slope", i, (float) cosmics.get(i).get_ray().get_yxslope()); bank.setFloat("trkline_yx_interc", i, (float) (cosmics.get(i).get_ray().get_yxinterc()/10.)); bank.setFloat("trkline_yz_slope", i, (float) cosmics.get(i).get_ray().get_yzslope()); - bank.setFloat("trkline_yz_interc", i, (float) (cosmics.get(i).get_ray().get_yzinterc()/10.+zShift)); + bank.setFloat("trkline_yz_interc", i, (float) (cosmics.get(i).get_ray().get_yzinterc()/10.+zShift/10)); // get the cosmics ray unit direction vector Vector3D u = new Vector3D(cosmics.get(i).get_ray().get_yxslope(), 1, cosmics.get(i).get_ray().get_yzslope()).asUnit(); @@ -497,7 +497,7 @@ public DataBank fillStraightTracksTrajectoryBank(DataEvent event, bank.setByte("layer", k, (byte) stVec.get_SurfaceLayer()); bank.setFloat("x", k, (float) (stVec.x()/10.)); bank.setFloat("y", k, (float) (stVec.y()/10.)); - bank.setFloat("z", k, (float) (stVec.z()/10. + zShift)); + bank.setFloat("z", k, (float) (stVec.z()/10. + zShift/10)); bank.setFloat("phi", k, (float) stVec.get_TrkPhiAtSurface()); bank.setFloat("theta", k, (float) stVec.get_TrkThetaAtSurface()); bank.setFloat("langle", k, (float) stVec.get_TrkToModuleAngle()); @@ -549,7 +549,7 @@ public DataBank fillHelicalTracksTrajectoryBank(DataEvent event, bank.setByte("layer", k, (byte) stVec.get_SurfaceLayer()); bank.setFloat("x", k, (float) (stVec.x()/10.)); bank.setFloat("y", k, (float) (stVec.y()/10.)); - bank.setFloat("z", k, (float) (stVec.z()/10. + zShift)); + bank.setFloat("z", k, (float) (stVec.z()/10. + zShift/10)); bank.setFloat("phi", k, (float) stVec.get_TrkPhiAtSurface()); bank.setFloat("theta", k, (float) stVec.get_TrkThetaAtSurface()); bank.setFloat("langle", k, (float) stVec.get_TrkToModuleAngle()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 6ef02369c..3381a34ef 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -261,8 +261,8 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) org.jlab.rec.cvt.Constants.setRbErr(err*10); System.out.println(" ................READ BEAM OFFSET PARAMETERS "+xb+" & "+yb+" cm......."); - // target position - org.jlab.rec.cvt.Constants.setZoffset(ztarget); + // target position mm + org.jlab.rec.cvt.Constants.setZoffset(ztarget*10); Constants.setCRCRADIUS(CRCRADIUS); Constants.setCRZRADIUS(CRZRADIUS); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index eec5f4f6b..81676b321 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -91,7 +91,7 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int // Load the constants //------------------- - int newRun = bank.getInt("run", 0); + int newRun = bank.getInt("run", 0); if (Run != newRun) { boolean align=false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 2e5bb7c1b..0ae26cd2b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -57,8 +57,9 @@ public boolean processEvent(DataEvent event, } else { if(isSVTonly) { TrackSeeder trseed = new TrackSeeder(); + trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null, SVTGeom, BMTGeom, swimmer); - + } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); @@ -89,14 +90,14 @@ public boolean processEvent(DataEvent event, double pz = pt*seed.get_Helix().get_tandip(); double px = pt*Math.cos(seed.get_Helix().get_phi_at_dca()); double py = pt*Math.sin(seed.get_Helix().get_phi_at_dca()); - int charge = (int) (Math.signum(Constants.getSolenoidscale())*seed.get_Helix().get_charge()); if(Math.abs(Constants.getSolenoidVal())<0.001) charge = 1; - + xr += org.jlab.rec.cvt.Constants.getXb(); + yr += org.jlab.rec.cvt.Constants.getYb(); hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, - charge, Constants.getSolenoidVal(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); - + charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), + org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); Matrix cov = seed.get_Helix().get_covmatrix(); if(Math.abs(Constants.getSolenoidVal())>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *Constants.getSolenoidVal()0) { From eec4781435c6a62ffef44c180a8b5df60d776c88 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 4 Nov 2020 14:19:51 -0500 Subject: [PATCH 030/291] fix filling of cvt local angle in trajectory bank --- .../main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 6fe7e4a3a..7092a0ba3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -126,6 +126,8 @@ public Trajectory findTrajectory(int id, Track trk, stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); stVec.set_SurfaceLayer(layer); stVec.set_SurfaceSector(sector); + Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); + this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); stVec.set_CalcCentroidStrip(svt_geo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); stVec.set_Path(path*10); stVec.set_ID(id); From 30ef6aa3286986d07fcdd194d38ad9048041e844 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 4 Nov 2020 14:21:18 -0500 Subject: [PATCH 031/291] algorithm to find missing clusters on track --- .../jlab/rec/cvt/services/RecUtilities.java | 72 +++++++++++++++++-- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 1845bac3a..8ed903be1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -1,14 +1,13 @@ package org.jlab.rec.cvt.services; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; - +import java.util.HashMap; +import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.clas.tracking.objects.Strip; - import org.jlab.detector.geant4.v2.SVT.SVTConstants; import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Plane3D; @@ -19,7 +18,8 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.track.Seed; -import org.jlab.rec.cvt.track.Track; +import org.jlab.rec.cvt.track.Track; +import org.jlab.clas.swimtools.Swim; /** * Service to return reconstructed TRACKS @@ -150,7 +150,69 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge } return KFSites; } - + public Map FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, + org.jlab.rec.cvt.svt.Geometry sgeo, + Swim swimmer) { + Map clusMap = new HashMap(); + //Map stripMap = new HashMap(); + Map docaMap = new HashMap(); + Map trajMap = new HashMap(); + int[] Sectors = new int[org.jlab.rec.cvt.svt.Constants.NLAYR]; + for (int a = 0; a < Sectors.length; a++) { + Point3D I = helix.getPointAtRadius(org.jlab.rec.cvt.svt.Constants.MODULERADIUS[a][0]); + int sec = sgeo.findSectorFromAngle(a + 1, I); + Sectors[a] = sec; + } + // initialize swimmer starting from the track vertex + double maxPathLength = 1; + swimmer.SetSwimParameters((helix.xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (helix.ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, helix.get_Z0() / 10, + Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), + P, Q, maxPathLength) ; + double[] inters = null; + double path = 0; + // SVT + for (int l = 0; l < org.jlab.rec.cvt.svt.Constants.NLAYR; l++) { + // reinitilize swimmer from last surface + if(inters!=null) { + double intersPhi = Math.atan2(inters[4], inters[3]); + double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), + P, Q, maxPathLength) ; + } + int layer = l + 1; + int sector = Sectors[l]; + if(sector == -1) + continue; + + Vector3D n = sgeo.findBSTPlaneNormal(sector, layer); + Point3D p = sgeo.getPlaneModuleOrigin(sector, layer); + double d = n.dot(p.toVector3D()); + inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); + Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); + double nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); + //stripMap.put((sector*1000+layer), nearstp); + docaMap.put((sector*1000+layer), sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); + trajMap.put((sector*1000+layer), trp); + } + for(Cluster cls : allClusters) { + int clsKey = cls.get_Sector()*1000+cls.get_Layer(); + //double trjCent = stripMap.get(clsKey); + double clsDoca = sgeo.getDOCAToStrip(cls.get_Sector(), cls.get_Layer(), + cls.get_Centroid(), trajMap.get(clsKey)); + if(clusMap.containsKey(clsKey)) { + //double filldCent = clusMap.get(clsKey).get_Centroid(); + double filldDoca = docaMap.get(clsKey); + if(Math.abs(clsDoca) traj, From 65e89547dba584f9e3c3c91f8b02c9c2c93eab6d Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 4 Nov 2020 21:30:25 +0100 Subject: [PATCH 032/291] Methods added to BMTgeometry, new enum class for detector type, removed duplicated dependency from pom file --- reconstruction/cvt/pom.xml | 6 - .../java/org/jlab/rec/cvt/bmt/BMTType.java | 60 +++ .../org/jlab/rec/cvt/bmt/BMTgeometry.java | 448 ++++++++++++++++-- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 108 +++-- .../java/org/jlab/rec/cvt/bmt/Constants.java | 78 ++- .../java/org/jlab/rec/cvt/bmt/Geometry.java | 4 +- 6 files changed, 613 insertions(+), 91 deletions(-) create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java diff --git a/reconstruction/cvt/pom.xml b/reconstruction/cvt/pom.xml index d47420863..ca4905596 100644 --- a/reconstruction/cvt/pom.xml +++ b/reconstruction/cvt/pom.xml @@ -92,12 +92,6 @@ 1.0 - - org.jlab.coda - jclara - 4.3-SNAPSHOT - - org.jlab.clas swim-tools diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java new file mode 100644 index 000000000..d561324a6 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java @@ -0,0 +1,60 @@ +/* + * 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.rec.cvt.bmt; + +/** + * + * @author devita + */ +public enum BMTType { + + UNDEFINED ( 0, "UNDEF"), + C ( 1, "C"), + Z ( 2, "Z"); + + private final int detectorId; + private final String detectorName; + + BMTType(){ + detectorId = 0; + detectorName = "UNDEFINED"; + } + + BMTType(int id, String name){ + detectorId = id; + detectorName = name; + } + /** + * Returns the name of the detector. + * @return the name of the detector + */ + public String getName() { + return detectorName; + } + + /** + * Returns the id number of the detector. + * @return the id number of the detector + */ + public int getDetectorId() { + return detectorId; + } + + public static BMTType getType(String name) { + name = name.trim(); + for(BMTType id: BMTType.values()) + if (id.getName().equalsIgnoreCase(name)) + return id; + return UNDEFINED; + } + public static BMTType getType(Integer detId) { + + for(BMTType id: BMTType.values()) + if (id.getDetectorId() == detId) + return id; + return UNDEFINED; + } +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java index b650f2a86..6ad982c9b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTgeometry.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.bmt; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; @@ -13,10 +14,11 @@ public class BMTgeometry { private final static int[] lZ = { 2, 3, 5}; private final static int[] lC = { 1, 4, 6}; - + private final static double accuracy = 1E-4; // mm + private final static double udf = -9999; // mm /** - * + * Handles BMT geometry */ public BMTgeometry() { } @@ -27,16 +29,17 @@ public BMTgeometry() { * @param detector (C or Z) * @return layer (1-6) */ - public int getLayer(int region, String detector) { + public int getLayer(int region, BMTType detector) { int layer = -1; if(region>=1 && region<=3) { - if( detector.equalsIgnoreCase("Z") ) { + if( detector == BMTType.Z ) { layer = lZ[ region - 1 ]; } - if( detector.equalsIgnoreCase("C") ) { + else if( detector == BMTType.C ) { layer = lC[ region - 1 ]; } } + else System.out.println("ERROR: out of range region number in getLayer(int region, BMTType detector)"); return layer; } @@ -50,6 +53,7 @@ public int getRegion(int layer) { if(layer>=1 && layer<=6) { region = (int) Math.floor((layer+1)/2); } + else System.out.println("ERROR: out of range layer number in getRegion(int layer)"); return region; } @@ -59,10 +63,13 @@ public int getRegion(int layer) { * @param layer (1-6) * @return type ("C" or "Z"); */ - public String getDetectorType(int layer) { - if(layer == 1 || layer == 4 || layer == 6) return "C"; - else if(layer == 2 || layer == 3 || layer == 5) return "Z"; - else return null; + public BMTType getDetectorType(int layer) { + if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; + else if(layer == lZ[0] || layer == lZ[1] || layer == lZ[2]) return BMTType.Z; + else { + System.out.println("ERROR: out of range layer number in getDetectorType(int layer)"); + return null; + } } @@ -74,16 +81,85 @@ public String getDetectorType(int layer) { public double getRadius(int layer) { int region = this.getRegion(layer); - String det = this.getDetectorType(layer); + BMTType det = this.getDetectorType(layer); double radius = 0; if(region>0 && det!=null) { - if (det.equalsIgnoreCase("C")) radius = Constants.getCRCRADIUS()[region-1]; - else if(det.equalsIgnoreCase("Z")) radius = Constants.getCRZRADIUS()[region-1]; + if (det == BMTType.C) radius = Constants.getCRCRADIUS()[region-1]; + else if(det == BMTType.Z) radius = Constants.getCRZRADIUS()[region-1]; } + else System.out.println("ERROR: out of range layer number in getRadius(int layer)"); return radius; } + /** + * Return number of strips of the selected layer + * @param layer (1-6) + * @return radius (=0 if layer is out of range) + */ + public int getNStrips(int layer) { + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + int nstrips = 0; + if(region>0 && det!=null) { + if (det == BMTType.C) nstrips = Constants.getCRCNSTRIPS()[region-1]; + else if(det == BMTType.Z) nstrips = Constants.getCRZNSTRIPS()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getNStrips(int layer)"); + return nstrips; + } + + /** + * Return minimum z of the selected layer + * @param layer (1-6) + * @return z (=udf if layer is out of range) + */ + public double getZmin(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && det!=null) { + if (det == BMTType.C) z = Constants.getCRCZMIN()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMIN()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getZmin(int layer)"); + return z; + } + + /** + * Return maximum z of the selected layer + * @param layer (1-6) + * @return z (=udf if layer is out of range) + */ + public double getZmax(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && det!=null) { + if (det == BMTType.C) z = Constants.getCRCZMAX()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMAX()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getZmax(int layer)"); + return z; + } + + /** + * Return thickness of the drift gap + * @return thickness + */ + public double getThickness() { + + return Constants.hDrift; + } + /** * Return offset of the selected tile, identified by layer and sector * @param layer (1-6) @@ -123,7 +199,8 @@ public Line3D getIdealZstrip(int region, int sector, int strip) { double radius = Constants.getCRZRADIUS()[region-1]; double zmin = Constants.getCRCZMIN()[region-1]; double zmax = Constants.getCRCZMAX()[region-1]; - double angle = Constants.getCRZEDGE1()[region-1][sector-1] + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; + double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] + + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; Point3D p1= new Point3D(radius, 0, zmin); p1.rotateZ(angle); @@ -144,7 +221,7 @@ public Line3D getIdealZstrip(int region, int sector, int strip) { */ public Line3D getZstrip(int region, int sector, int strip) { - int layer = this.getLayer(region, "Z"); + int layer = this.getLayer(region, BMTType.Z); Line3D stripline = this.getIdealZstrip(region, sector, strip); Point3D offset = this.getOffset(layer, sector); @@ -158,6 +235,43 @@ public Line3D getZstrip(int region, int sector, int strip) { return stripline; } + /** + * Return the C detector strip group + * @param region [1-3] + * @param strip + * @return group [1-...] + */ + public int getCGroup(int region, int strip) { + int group = 0; + if(strip>0 && strip<=Constants.getCRCNSTRIPS()[region-1]) { + for(int i=0; iConstants.getCRCZMIN()[region-1] && zConstants.getCRCGRPZMIN()[region-1][i] && z 1) { - for (int j = 1; j < strip; j++) { - zc += Constants.getCRCWIDTH()[region-1][group]; - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[region-1][group]; - } - } + + double z = udf; + + int group = getCGroup(region,strip); + if(group>0) { + double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; // group minimum z + double pitch = Constants.getCRCWIDTH()[region-1][group-1]; // group pitch + int nmin = Constants.getCRCGRPNMIN()[region-1][group-1]; + z = zmin + (strip - nmin + 0.5) * pitch; } - zc += Constants.getCRCWIDTH()[region-1][group]/2.; - return zc; //in mm + return z; } /** @@ -195,8 +303,8 @@ public double getCstripZ(int region, int strip) { public Arc3D getIdealCstrip(int region, int sector, int strip) { double radius = Constants.getCRCRADIUS()[region-1]; - double angle = Constants.getCRCEDGE1()[region-1][sector-1] + Constants.getCRCXPOS()[region-1] / Constants.getCRCRADIUS()[region-1]; - double theta = (Constants.getCRCXPOS()[region-1]+Constants.getCRCLENGTH()[region-1]) / Constants.getCRCRADIUS()[region-1]; + double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; + double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; double z = this.getCstripZ(region, strip); Point3D origin = new Point3D(radius,0,z); @@ -217,7 +325,7 @@ public Arc3D getIdealCstrip(int region, int sector, int strip) { */ public Arc3D getCstrip(int region, int sector, int strip) { - int layer = this.getLayer(region, "C"); + int layer = this.getLayer(region, BMTType.C); Arc3D arcline = this.getIdealCstrip(region, sector, strip); Point3D offset = this.getOffset(layer, sector); @@ -229,6 +337,61 @@ public Arc3D getCstrip(int region, int sector, int strip) { return arcline; } + + /** + * Return the sector number + * @param layer [1-6] + * @param angle in radians + * @return sector [1-3] or 0 if undefined + */ + public int getSector(int layer, double angle) { + + int region = getRegion(layer); + Vector3D vec = new Vector3D(Math.cos(angle),Math.sin(angle),0); + + int sector = 0; + double width = 0.5; // Math.cos(60deg); + for (int i = 0; i < Constants.NSECTORS; i++) { + double phi = Constants.getCRCPHI()[region-1][i]; + Vector3D center = new Vector3D(Math.cos(phi),Math.sin(phi),0); + double dcosphi = center.dot(vec); + if(dcosphi>width) { + sector = i+1; + } + } + return sector; + } + + /** + * Return the layer number + * @param traj point on one of the detector surfaces + * @return layer [1-6] or 0 if undefined + */ + public int getLayer(Point3D traj) { + int layer=0; + + double radius = Math.sqrt(traj.x()*traj.x()+traj.y()*traj.y()); + for(int i=1; i<=Constants.NLAYERS; i++) { + if(Math.abs(radius-this.getRadius(i))0 && sector>0) strip = getStrip(layer,sector,traj); + return strip; + } /** * Return the number of the closest strip to the given trajectory point @@ -248,60 +411,245 @@ public int getStrip(int layer, int sector, Point3D traj) { traj.rotateY(-rotation.y()); traj.rotateX(-rotation.x()); - return this.getStripLocal(layer, sector, traj); + return this.getStripLocal(layer, traj); } /** * Return the number of the closest strip to the given trajectory point * in the detector local frame * @param layer (1-6) - * @param sector (1-3) * @param traj trajectory point on the layer surface in the local frame * @return strip number (0 if the point is not within the active area) */ - public int getStripLocal(int layer, int sector, Point3D traj) { - - String type = this.getDetectorType(layer); + public int getStripLocal(int layer, Point3D traj) { - if(type == null) return 0; - - if(type.equalsIgnoreCase("C")) { - return this.getCstrip(layer,traj); - } - else if(type.equalsIgnoreCase("Z")) { - return this.getZstrip(layer,traj); + BMTType type = this.getDetectorType(layer); + int region = this.getRegion(layer); + switch (type) { + case C: + return this.getCstrip(region,traj); + case Z: + return this.getZstrip(region,traj); + default: + return 0; } - else return 0; } /** * Return the number of the closest strip to the given trajectory point * in the detector local frame - * @param layer (1-6) - * @param sector (1-3) + * @param region (1-3) * @param traj trajectory point on the layer surface in the local frame * @return strip number (0 if the point is not within the active area) */ public int getCstrip(int region, Point3D traj) { int strip = 0; + + int group = getCGroup(region, traj.z()); + if(group>0) { + double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; + double pitch = Constants.getCRCWIDTH()[region-1][group-1]; + strip = (int) Math.floor((traj.z()-zmin)/pitch); + if(group>0) strip += Constants.getCRCGRPNMIN()[region-1][group-1]; + } return strip; } /** * Return the number of the closest strip to the given trajectory point * in the detector local frame - * @param layer (1-6) - * @param sector (1-3) + * @param region (1-3) * @param traj trajectory point on the layer surface in the local frame * @return strip number (0 if the point is not within the active area) */ public int getZstrip(int region, Point3D traj) { int strip = 0; + + int layer = getLayer(region, BMTType.Z); + + double angle = Math.atan2(traj.y(), traj.x()); + if(angle<0) angle += 2*Math.PI; + + int sector = getSector(layer,angle); + if(sector>=1 && sector <=3) { + // CHECKME + double edge = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1]; // 30 150 270 + double pitch = Constants.getCRZWIDTH()[region-1]; + double radius = Constants.getCRZRADIUS()[region-1]; + double dphi = angle - edge; + if(dphi<0) dphi += 2*Math.PI; + strip = (int) Math.floor(dphi*radius/pitch) + 1; +// System.out.println(Math.toDegrees(angle) + " " + Math.toDegrees(dphi) + " " + sector + " " + strip_calc); + if (strip < 1 || strip > Constants.getCRZNSTRIPS()[region-1]) { + strip = -1; + } + } return strip; + } + public static void main (String arg[]) { + + CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, "default")); + + Geometry oldGeo = new Geometry(); + BMTgeometry newGeo = new BMTgeometry(); + + System.out.println("\nLayer number for region and detector type:"); + System.out.println("\tRegion\tType\tLayer"); + for(int i=1; i<=Constants.NREGIONS; i++) { + System.out.println("\t" + i + "\t" + newGeo.getLayer(i, BMTType.C) + "\t" + newGeo.getLayer(i, BMTType.Z)); + } + + System.out.println("\nDetector information by layer:"); + System.out.println("\tLayer\tRegion\tType\tRadius(mm)\tThickness(mm)\tZmin(mm)\tZmax(mm)\tNNstrips"); + for(int i=1; i<=Constants.NLAYERS; i++) { + System.out.println("\t" + i + "\t" + newGeo.getRegion(i) + "\t" + newGeo.getDetectorType(i) + + "\t" + newGeo.getRadius(i) + "\t\t" + newGeo.getThickness() + + "\t\t" + newGeo.getZmin(i) + "\t\t" + newGeo.getZmax(i) + + "\t\t" + newGeo.getNStrips(i) + ); + } + + System.out.println("\nOffsets and Rotations"); + System.out.println("\tLayer\tSector\tOffset and Rotation"); + for(int i=1; i<=Constants.NLAYERS; i++) { + for(int j=1; j<=Constants.NSECTORS; j++) { + System.out.println("\t" + i + "\t" + j + "\t" + newGeo.getOffset(i, j).toString() + "\t" + newGeo.getRotation(i, j).toString()); + } + } + + System.out.println("\n\nC strip geometry check: z (mm), begin and end phi angles (radians)"); + System.out.println("\tRegion\tSector\tStrip\tZ\t\t\t\tBegin phi\t\tEnd phi"); + System.out.println("\t \t \t \tNew/Old/Comp \t\t\tNew/Old/Comp \t\tNew/Old/Comp"); + for(int i=1; i<=Constants.NREGIONS; i++) { + for(int k=1; k<=Constants.NSECTORS; k++) { + for(int j=1; j<=Constants.getCRCNSTRIPS()[i-1]; j++) { + // z + double ngeo = newGeo.getCstrip(i, 1, j).center().z(); + double ogeo = oldGeo.CRCStrip_GetZ(newGeo.getLayer(i, BMTType.C),j); + String snew = String.format("%.4f", ngeo); + String sold = String.format("%.4f", ogeo); + String scom = String.format("%.4f", ngeo-ogeo); + // begin angle + double ngeo1 = Math.atan2(newGeo.getCstrip(i, k, j).origin().y(),newGeo.getCstrip(i, k, j).origin().x()); + if(ngeo1<0) ngeo1 += 2*Math.PI; + double ogeo1 = oldGeo.CRC_GetBeginStrip(k, newGeo.getLayer(i, BMTType.C)); + String snew1 = String.format("%.4f", ngeo1); + String sold1 = String.format("%.4f", ogeo1); + String scom1 = String.format("%.4f", ngeo1-ogeo1); + // end angle + double ngeo2 = Math.atan2(newGeo.getCstrip(i, k, j).end().y(),newGeo.getCstrip(i, k, j).end().x()); + if(ngeo2<0) ngeo2 += 2*Math.PI; + double ogeo2 = oldGeo.CRC_GetEndStrip(k, newGeo.getLayer(i, BMTType.C)); + String snew2 = String.format("%.4f", ngeo2); + String sold2 = String.format("%.4f", ogeo2); + String scom2 = String.format("%.4f", ngeo2-ogeo2); + if(j==1 || j==Constants.getCRCNSTRIPS()[i-1]) + System.out.println("\t" + i + "\t" + k + "\t" + j + "\t" + snew + "/" + sold + "/" + scom + "\t" + snew1 + "/" + sold1 + "/" + scom1 + "\t" + snew2 + "/" + sold2 + "/" + scom2); + } + } + } + + + System.out.println("\n\nZ strip geometry check: phi (radians), begin and end z (mm)"); + System.out.println("\tRegion\tSector\tStrip\tphi\t\t\tBegin Z\t\t\t\tEnd Z"); + System.out.println("\t \t \t \tNew/Old/Comp \t\tNew/Old/Comp \t\t\tNew/Old/Comp"); + for(int i=1; i<=Constants.NREGIONS; i++) { + for(int k=1; k<=Constants.NSECTORS; k++) { + for(int j=1; j<=Constants.getCRZNSTRIPS()[i-1]; j++) { + // phi + double ngeo = Math.atan2(newGeo.getZstrip(i, k, j).origin().y(), newGeo.getZstrip(i, k, j).origin().x()); + if(ngeo<0) ngeo += 2*Math.PI; + double ogeo = oldGeo.CRZStrip_GetPhi(k, newGeo.getLayer(i, BMTType.Z), j)%(2*Math.PI); + String snew = String.format("%.4f", ngeo); + String sold = String.format("%.4f", ogeo); + String scom = String.format("%.4f", ngeo-ogeo); + // begin z + double ngeo1 = newGeo.getZstrip(i, k, j).origin().z(); + double ogeo1 = Constants.getCRCZMIN()[i-1]; + String snew1 = String.format("%.4f", ngeo1); + String sold1 = String.format("%.4f", ogeo1); + String scom1 = String.format("%.4f", ngeo1-ogeo1); + // end z + double ngeo2 = newGeo.getZstrip(i, k, j).end().z(); + double ogeo2 = Constants.getCRCZMAX()[i-1]; + String snew2 = String.format("%.4f", ngeo2); + String sold2 = String.format("%.4f", ogeo2); + String scom2 = String.format("%.4f", ngeo2-ogeo2); + if(j==1 || j==Constants.getCRZNSTRIPS()[i-1]) + System.out.println("\t" + i + "\t" + k + "\t" + j + "\t" + snew + "/" + sold + "/" + scom + "\t" + snew1 + "/" + sold1 + "/" + scom1 + "\t" + snew2 + "/" + sold2 + "/" + scom2); + } + } + } + + + System.out.println("\n\n Trajectory -> strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + for(int j=0; j<5; j++) { + double z = Math.random()*(zmax-zmin)+zmin; + //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; + //double z = oldGeo.CRCStrip_GetZ(i, j); + double phi = Math.random()*2*Math.PI; + //double phi = (1.0*j/500.0)*2*Math.PI; + //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nsect = newGeo.getSector(i, phi); + int nstrip = newGeo.getStrip(traj); + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(nsect, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; + System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); + } + } + + + System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + boolean check = true; + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + int nstrips = newGeo.getNStrips(i); + int region = newGeo.getRegion(i); + for(int k=1; k<=Constants.NSECTORS; k++) { + double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; + double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; + for(int j=1; j<=nstrips; j++) { + + double z = Math.random()*(zmax-zmin)+zmin; + if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); + + double phi = Math.random()*(phmax-phmin)+phmin; + if(newGeo.getDetectorType(i)==BMTType.Z) { + phi = oldGeo.CRZStrip_GetPhi(k, i, j); + } + + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nstrip = newGeo.getStrip(traj); + + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(k, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; + if(nstrip!=j) check=false; + if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" + + j + "/" + nstrip + "/" + ostrip + "/" + diff); + } + } + } + System.out.println("Check: " + check); + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 714248ac6..aa43f3df6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -1,6 +1,8 @@ package org.jlab.rec.cvt.bmt; import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; /** * @@ -22,7 +24,9 @@ public CCDBConstantsLoader() { public static final synchronized void Load(DatabaseConstantProvider dbprovider) { // initialize the constants //Z detector characteristics - int NREGIONS = 3; + int NREGIONS = Constants.NREGIONS; + int NSECTORS = Constants.NSECTORS; + int NLAYERS = Constants.NLAYERS; double[] CRZRADIUS = new double[NREGIONS]; // the radius of the Z detector in mm int[] CRZNSTRIPS = new int[NREGIONS]; // the number of strips double[] CRZSPACING = new double[NREGIONS]; // the strip spacing in mm @@ -31,8 +35,10 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double[] CRZZMIN = new double[NREGIONS]; // PCB upstream extremity mm double[] CRZZMAX = new double[NREGIONS]; // PCB downstream extremity mm double[] CRZOFFSET = new double[NREGIONS]; // Beginning of strips in mm - double[][] CRZEDGE1 = new double[NREGIONS][3]; // the angle of the first edge of each PCB detector A, B, C - double[][] CRZEDGE2 = new double[NREGIONS][3]; // the angle of the second edge of each PCB detector A, B, C + double[][] CRZPHI = new double[NREGIONS][NSECTORS]; // the the central phi of the PCB + double[][] CRZDPHI = new double[NREGIONS][NSECTORS]; // the the half phi width of the PCB + double[][] CRZEDGE1 = new double[NREGIONS][NSECTORS]; // the angle of the first edge of each PCB detector A, B, C + double[][] CRZEDGE2 = new double[NREGIONS][NSECTORS]; // the angle of the second edge of each PCB detector A, B, C double[] CRZXPOS = new double[NREGIONS]; // Distance on the PCB between the PCB first edge and the edge of the first strip in mm //C detector characteristics @@ -45,12 +51,18 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double[] CRCOFFSET = new double[NREGIONS]; // Beginning of strips in mm int[][] CRCGROUP = new int[NREGIONS][100]; // Number of strips with same width double[][] CRCWIDTH = new double[NREGIONS][100]; // the width of the corresponding group of strips - double[][] CRCEDGE1 = new double[NREGIONS][3]; // the angle of the first edge of each PCB detector A, B, C - double[][] CRCEDGE2 = new double[NREGIONS][3]; // the angle of the second edge of each PCB detector A, B, C + int[][] CRCGRPNMIN = new int[NREGIONS][100]; // the group min strip number + int[][] CRCGRPNMAX = new int[NREGIONS][100]; // the group max strip number + double[][] CRCGRPZMIN = new double[NREGIONS][100]; // the group minimum z + double[][] CRCGRPZMAX = new double[NREGIONS][100]; // the group maximum z + double[][] CRCPHI = new double[NREGIONS][NSECTORS]; // the the central phi of the PCB + double[][] CRCDPHI = new double[NREGIONS][NSECTORS]; // the the half phi width of the PCB + double[][] CRCEDGE1 = new double[NREGIONS][NSECTORS]; // the angle of the first edge of each PCB detector A, B, C + double[][] CRCEDGE2 = new double[NREGIONS][NSECTORS]; // the angle of the second edge of each PCB detector A, B, C double[] CRCXPOS = new double[NREGIONS]; // Distance on the PCB between the PCB first edge and the edge of the first strip in mm - double[] EFF_Z_OVER_A = new double[NREGIONS*2]; - double[] T_OVER_X0 = new double[NREGIONS*2]; + double[] EFF_Z_OVER_A = new double[NLAYERS]; + double[] T_OVER_X0 = new double[NLAYERS]; int GRID_SIZE=405; double[] THETA_L_grid = new double [GRID_SIZE]; @@ -58,8 +70,8 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double[] MAG_grid = new double [GRID_SIZE]; // HV settings for Lorentz Angle - double [][] HV_DRIFT_FF= new double [NREGIONS*2][3]; - double [][] HV_DRIFT_MF= new double [NREGIONS*2][3]; + double [][] HV_DRIFT_FF= new double [NLAYERS][NSECTORS]; + double [][] HV_DRIFT_MF= new double [NLAYERS][NSECTORS]; // Load the tables @@ -107,18 +119,33 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) // dbprovider.show(); // Getting the Constants // 1) pitch info - for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L1/Group_size"); i++) { - CRCGROUP[0][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L1/Group_size", i); - CRCWIDTH[0][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L1/Pitch", i); - } - for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L4/Group_size"); i++) { - CRCGROUP[1][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L4/Group_size", i); - CRCWIDTH[1][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L4/Pitch", i); - } - for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L6/Group_size"); i++) { - CRCGROUP[2][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L6/Group_size", i); - CRCWIDTH[2][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L6/Pitch", i); + int[] C_Layers = {1, 4, 6}; + for (int j = 0; j < NREGIONS; j++) { + for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L" + C_Layers[j] + "/Group_size"); i++) { + CRCGROUP[j][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L" + C_Layers[j] + "/Group_size", i); + CRCWIDTH[j][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L" + C_Layers[j] + "/Pitch", i); + if(i==0) { + CRCGRPNMIN[j][i] = 1; + CRCGRPNMAX[j][i] = CRCGROUP[j][i]; + CRCGRPZMIN[j][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_layer_noshim/Zmin", C_Layers[j]-1); + CRCGRPZMAX[j][i] = CRCGRPZMIN[j][i] + CRCGROUP[j][i]*CRCWIDTH[j][i]; + } + else { + CRCGRPNMIN[j][i] = CRCGRPNMAX[j][i-1] + 1; + CRCGRPNMAX[j][i] = CRCGRPNMAX[j][i-1] + CRCGROUP[j][i]; + CRCGRPZMIN[j][i] = CRCGRPZMAX[j][i-1]; + CRCGRPZMAX[j][i] = CRCGRPZMIN[j][i] + CRCGROUP[j][i]*CRCWIDTH[j][i]; + } + } } +// for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L4/Group_size"); i++) { +// CRCGROUP[1][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L4/Group_size", i); +// CRCWIDTH[1][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L4/Pitch", i); +// } +// for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L6/Group_size"); i++) { +// CRCGROUP[2][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L6/Group_size", i); +// CRCWIDTH[2][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L6/Pitch", i); +// } CRZWIDTH[0] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L2/Pitch", 0); CRZWIDTH[1] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L3/Pitch", 0); @@ -152,6 +179,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) CRZZMAX[region - 1] = Zmax; CRZLENGTH[region - 1] = Zmax - Zmin; CRZSPACING[region - 1] = spacing; + for (int j = 0; j < 3; j++) { if (EDGE2[j] > EDGE1[j]) { @@ -165,7 +193,10 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) EDGE2[j] = middle + ((double) Nstrips) * (CRZWIDTH[region - 1] / radius) / 2. - 0 * CRZWIDTH[region - 1] / radius; EDGE2[j] -= 2 * Math.PI; } - + if (j==0) CRZPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2 + 120); + else if(j==1) CRZPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2); + else if(j==2) CRZPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2 + 240); + CRZDPHI[region-1][j] = Nstrips * CRZWIDTH[region - 1]/radius/2; } CRZEDGE1[region - 1] = EDGE1; CRZEDGE2[region - 1] = EDGE2; @@ -179,6 +210,12 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) CRCSPACING[region - 1] = spacing; CRCEDGE1[region - 1] = EDGE1; CRCEDGE2[region - 1] = EDGE2; + for (int j = 0; j < 3; j++) { + if (j==0) CRCPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2 + 120); + else if(j==1) CRCPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2); + else if(j==2) CRCPHI[region-1][j] = Math.toRadians((Phi_min+Phi_max)/2 + 240); + CRCDPHI[region-1][j] = Math.toRadians((Phi_max-Phi_min)/2 ); + } } } @@ -242,7 +279,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) MAG_grid[i]=dbprovider.getDouble("/calibration/mvt/lorentz/Bfield",i); } - for (int i = 0; i<2*NREGIONS; i++) { + for (int i = 0; i Date: Wed, 4 Nov 2020 16:12:24 -0500 Subject: [PATCH 033/291] version bump --- common-tools/clas-analysis/pom.xml | 14 ++++++------- common-tools/clas-detector/pom.xml | 10 +++++----- common-tools/clas-geometry/pom.xml | 4 ++-- common-tools/clas-io/pom.xml | 6 +++--- common-tools/clas-jcsg/pom.xml | 8 ++++---- common-tools/clas-math/pom.xml | 4 ++-- common-tools/clas-physics/pom.xml | 4 ++-- common-tools/clas-reco/pom.xml | 14 ++++++------- common-tools/clas-tracking/pom.xml | 6 +++--- common-tools/clas-utils/pom.xml | 4 ++-- common-tools/cnuphys/ced/pom.xml | 8 ++++---- common-tools/cnuphys/magfield/pom.xml | 2 +- common-tools/cnuphys/swimmer/pom.xml | 2 +- common-tools/coat-lib/deployDistribution.sh | 2 +- common-tools/coat-lib/pom.xml | 22 ++++++++++----------- common-tools/parent/pom.xml | 2 +- common-tools/pom.xml | 4 ++-- common-tools/swim-tools/pom.xml | 6 +++--- parent/pom.xml | 2 +- pom.xml | 4 ++-- reconstruction/band/pom.xml | 2 +- reconstruction/cnd/pom.xml | 2 +- reconstruction/cvt/pom.xml | 12 +++++------ reconstruction/dc/pom.xml | 12 +++++------ reconstruction/eb/pom.xml | 10 +++++----- reconstruction/ec/pom.xml | 14 ++++++------- reconstruction/ft/pom.xml | 8 ++++---- reconstruction/fvt/pom.xml | 6 +++--- reconstruction/htcc/pom.xml | 8 ++++---- reconstruction/ltcc/pom.xml | 6 +++--- reconstruction/pom.xml | 4 ++-- reconstruction/rich/pom.xml | 8 ++++---- reconstruction/rtpc/pom.xml | 6 +++--- reconstruction/swaps/pom.xml | 12 +++++------ reconstruction/tof/pom.xml | 4 ++-- 35 files changed, 121 insertions(+), 121 deletions(-) diff --git a/common-tools/clas-analysis/pom.xml b/common-tools/clas-analysis/pom.xml index c8f8dc149..8d0f5689e 100644 --- a/common-tools/clas-analysis/pom.xml +++ b/common-tools/clas-analysis/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-analysis - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -30,31 +30,31 @@ org.jlab.clas clas-utils - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-physics - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-io - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-geometry - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-detector - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-detector/pom.xml b/common-tools/clas-detector/pom.xml index 16bb8e226..0e61aa7e2 100644 --- a/common-tools/clas-detector/pom.xml +++ b/common-tools/clas-detector/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-detector - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -30,7 +30,7 @@ org.jlab.clas clas-utils - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -42,13 +42,13 @@ org.jlab.clas clas-io - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-geometry - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-geometry/pom.xml b/common-tools/clas-geometry/pom.xml index cafc6a178..17bc50ee8 100644 --- a/common-tools/clas-geometry/pom.xml +++ b/common-tools/clas-geometry/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-geometry - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-io/pom.xml b/common-tools/clas-io/pom.xml index 244f4481d..1cee661fc 100644 --- a/common-tools/clas-io/pom.xml +++ b/common-tools/clas-io/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-io - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -75,7 +75,7 @@ org.jlab.clas clas-utils - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-jcsg/pom.xml b/common-tools/clas-jcsg/pom.xml index 83b33109f..90045cd2c 100644 --- a/common-tools/clas-jcsg/pom.xml +++ b/common-tools/clas-jcsg/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-jcsg - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -40,12 +40,12 @@ org.jlab.clas clas-geometry - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT org.jlab.clas clas-detector - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT java3d diff --git a/common-tools/clas-math/pom.xml b/common-tools/clas-math/pom.xml index 62fd5f13d..9490adeba 100644 --- a/common-tools/clas-math/pom.xml +++ b/common-tools/clas-math/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-math - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-physics/pom.xml b/common-tools/clas-physics/pom.xml index f4f3e6847..99336706f 100644 --- a/common-tools/clas-physics/pom.xml +++ b/common-tools/clas-physics/pom.xml @@ -4,7 +4,7 @@ org.jlab.clas clas-physics - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar @@ -23,7 +23,7 @@ org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT diff --git a/common-tools/clas-reco/pom.xml b/common-tools/clas-reco/pom.xml index 49d442dde..a598300b6 100644 --- a/common-tools/clas-reco/pom.xml +++ b/common-tools/clas-reco/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-reco - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT @@ -67,7 +67,7 @@ org.jlab.clas clas-math - 6.5.11-SNAPSHOT + 6.5.12-SNAPSHOT meas phi // define new cross - Cross this_cross = new Cross("BMT", "Z", Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); + Cross this_cross = new Cross("BMT", BMTType.Z, Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); this_cross.set_Id(pid); this_cross.set_Cluster1(Zlayerclus); // this is the inner shell //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips @@ -183,7 +184,7 @@ private ArrayList findBMTCrosses( } // C detector --> meas z // define new cross - Cross this_cross = new Cross("BMT", "C", Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); + Cross this_cross = new Cross("BMT", BMTType.C, Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); this_cross.set_Id(pid); // measurement of z @@ -236,11 +237,11 @@ public ArrayList> sortClusterByDetectorAndIO( // Sorting by layer first: for (Cluster theclus : clusters) { if (theclus.get_Detector() == 1) { - if (Geometry.getZorC(theclus.get_Layer()) == 1) { + if (BMTGeometry.getZorC(theclus.get_Layer()) == 1) { bmt_Zlayrclus.add(theclus); } - if (Geometry.getZorC(theclus.get_Layer()) == 0) { + if (BMTGeometry.getZorC(theclus.get_Layer()) == 0) { bmt_Clayrclus.add(theclus); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index d1fa84db5..9dead28a1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -5,6 +5,7 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.Geometry; @@ -88,9 +89,9 @@ public List findCandidateCrossLists(List crossList) { */ public CrossList findCosmicsCandidateCrossLists(List> crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.Geometry bmt_geo, int NbSVTRegions) { + org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { // start finding svt crosses ArrayList svt_crosses = crosses.get(0); // if there are no svt crosses then return - there is no track @@ -349,7 +350,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, private List errY = new ArrayList(); private ArrayList get_XYTrajectory(List crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.Geometry bmt_geo, int NbSVTRegions) { + org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { ArrayList projectedCrosses = new ArrayList(); @@ -406,7 +407,7 @@ private ArrayList get_XYTrajectory(List crosses, org.jlab.rec.cvt. */ private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.Geometry bmt_geo, int NbSVTRegions) { + org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { ArrayList projectedCrosses = new ArrayList(); //Layer 1-8: @@ -436,7 +437,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, if (Delt.mag() < org.jlab.rec.cvt.svt.Constants.ACTIVESENWIDTH / 2) { double tX = fac * yxslope + yxinterc; double tY = fac; - Cross cross2D = new Cross("SVT", "", s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane + Cross cross2D = new Cross("SVT", BMTType.UNDEFINED, s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane cross2D.set_Point0(new Point3D(tX, tY, 0)); projectedCrosses.add(cross2D); } @@ -450,24 +451,24 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, this.calcBMT2DPoint(yxslope, yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); - Cross cross2D1 = new Cross("BMT", "C", bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D1); if (t[3] != t[1] && t[2] != t[0]) { - Cross cross2D2 = new Cross("BMT", "C", bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D2); } this.calcBMT2DPoint(yxslope, yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); - Cross cross2D3 = new Cross("BMT", "Z", bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D3); if (t[3] != t[1] && t[2] != t[0]) { - Cross cross2D4 = new Cross("BMT", "Z", bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D4); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 1d0b4951d..ef5aec7b5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -3,6 +3,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.Constants; +import org.jlab.rec.cvt.bmt.Geometry; public class Strip { @@ -136,9 +137,9 @@ public void set_Edep(double _Edep) { * @param geo the BMT geometry class Sets the Lorentz corrected phi and * strip number for Z detectors, the z position for C detectors */ - public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.Geometry geo, int sector, int layer) { + public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector, int layer) { - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { // C-dtectors + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { // C-dtectors // set z double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); this.set_Z(z); @@ -146,8 +147,8 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.Geometry geo, int sector, i this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { // Z-detectors - geo.SetLorentzAngle(layer, sector); + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { // Z-detectors + geo.setLorentzAngle(layer, sector); double theMeasuredPhi = geo.CRZStrip_GetPhi(sector, layer, this.get_Strip()); double theLorentzCorrectedAngle = geo.LorentzAngleCorr(theMeasuredPhi, layer); // set the phi diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 81676b321..4365d237e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -38,7 +38,7 @@ public class CVTRecNewKF extends ReconstructionEngine { org.jlab.rec.cvt.svt.Geometry SVTGeom; - org.jlab.rec.cvt.bmt.Geometry BMTGeom; + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom; CTOFGeant4Factory CTOFGeom; Detector CNDGeom ; SVTStripFactory svtIdealStripFactory; @@ -49,7 +49,7 @@ public CVTRecNewKF() { super("CVTTracks", "ziegler", "4.0"); SVTGeom = new org.jlab.rec.cvt.svt.Geometry(); - BMTGeom = new org.jlab.rec.cvt.bmt.Geometry(); + BMTGeom = new org.jlab.rec.cvt.bmt.BMTGeometry(); strgtTrksRec = new CosmicTracksRec(); trksFromTargetRec = new TracksFromTargetRec(); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index aa2d722c8..cde31f480 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -31,7 +31,7 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.Geometry BMTGeom, + org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, RecoBankWriter rbc, double zShift) { // make list of crosses consistent with a track candidate diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index d6d69f0fc..c13701ecd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -20,6 +20,7 @@ import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; +import org.jlab.rec.cvt.bmt.BMTType; /** * Service to return reconstructed TRACKS @@ -116,7 +117,7 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); - if (trkcand.get_Crosses().get(c).get_DetectorType().equalsIgnoreCase("Z")) { + if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.Z) { double x = trkcand.get_Crosses().get(c).get_Point().x(); double y = trkcand.get_Crosses().get(c).get_Point().y(); double phi = Math.atan2(y,x); @@ -139,7 +140,7 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge continue; KFSites.add(meas); } - if (trkcand.get_Crosses().get(c).get_DetectorType().equalsIgnoreCase("C")) { + if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.C) { double z = trkcand.get_Crosses().get(c).get_Point().z(); double err = trkcand.get_Crosses().get(c).get_Cluster1().get_ZErr(); @@ -227,7 +228,7 @@ public Map FindClustersOnTrk (List allClusters, Helix public void MatchTrack2Traj(Seed trkcand, Map traj, - org.jlab.rec.cvt.svt.Geometry sgeo, org.jlab.rec.cvt.bmt.Geometry bgeo) { + org.jlab.rec.cvt.svt.Geometry sgeo, org.jlab.rec.cvt.bmt.BMTGeometry bgeo) { for (int i = 0; i < trkcand.get_Clusters().size(); i++) { //SVT if(trkcand.get_Clusters().get(i).get_Detector()==0) { @@ -269,7 +270,7 @@ public void MatchTrack2Traj(Seed trkcand, Map SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.Geometry BMTGeom, + org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, double shift, @@ -64,9 +65,9 @@ public boolean processEvent(DataEvent event, TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - TrackSeeder trseed2 = new TrackSeeder(); - trseed2.unUsedHitsOnly = true; - seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); + // TrackSeeder trseed2 = new TrackSeeder(); + // trseed2.unUsedHitsOnly = true; + // seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); } } if(seeds ==null || seeds.size() == 0) { @@ -190,7 +191,7 @@ public boolean processEvent(DataEvent event, if( c.get_AssociatedTrackID() < 0 ) { c.set_Dir( new Vector3D(0,0,0)); c.set_DirErr( new Vector3D(0,0,0)); - if( c.get_DetectorType().equalsIgnoreCase("C")) { + if( c.get_DetectorType()==BMTType.C) { // System.out.println(c + " " + c.get_AssociatedTrackID()); c.set_Point(new Point3D(Double.NaN,Double.NaN,c.get_Point().z())); // System.out.println(c.get_Point()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 29bd24d17..7026e755e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -4,7 +4,8 @@ import javax.vecmath.Point2d; import javax.vecmath.Vector2d; -import org.jlab.rec.cvt.bmt.Geometry; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; /** @@ -43,7 +44,7 @@ private double getCrossRadius( Cross c ) { // TODO: can this be moved inside th if( c.get_Detector().equalsIgnoreCase("SVT") ) return Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); - if( c.get_DetectorType().equalsIgnoreCase("Z") ) + if( c.get_DetectorType()==BMTType.Z ) return org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[c.get_Region()-1 ]; return org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[c.get_Region()-1 ]; @@ -92,7 +93,7 @@ private boolean checkAngles( Cell cell ) { return true; } - public void createCells( List crs, Geometry bgeom ){ + public void createCells( List crs, BMTGeometry bgeom ){ // this function loops over the crosses and looks for pairs that pass the cuts // Collections.sort(crs); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 1dabf5458..158c962f2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -7,6 +7,7 @@ import java.util.Map; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.CircleFitter; @@ -94,7 +95,7 @@ private void FitSeed(List seedcrs) { Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) System.err.println("WRONG CROSS TYPE"); + if(c.get_DetectorType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); @@ -220,7 +221,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); public List findSeed(List svt_crosses, List bmt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, boolean isSVTOnly) { + org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean isSVTOnly) { List seedlist = new ArrayList(); @@ -229,9 +230,9 @@ public List findSeed(List svt_crosses, List bmt_crosses, if(isSVTOnly == false ) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType().equalsIgnoreCase("Z")) + if(c.get_DetectorType()== BMTType.Z) crosses.add(c); - if(c.get_DetectorType().equalsIgnoreCase("C")) + if(c.get_DetectorType()==BMTType.C) bmtC_crosses.add(c); } } @@ -244,7 +245,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C ) continue; c.set_AssociatedTrackID(122220); } // loop until a good circular fit. removing far crosses each time @@ -261,7 +262,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C ) continue; c.set_AssociatedTrackID(122221); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); @@ -280,7 +281,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, double r = pars.rho(); double f = pars.phi(); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C ) continue; c.set_AssociatedTrackID(122222); double xi = c.get_Point().x(); double yi = c.get_Point().y(); @@ -351,7 +352,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init @@ -508,7 +509,7 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -524,7 +525,7 @@ public List findCandUsingMicroMegas(Seed trkCand, //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_DetectorType().equalsIgnoreCase("C")) {// C-detector + if (bmt_cross.get_DetectorType()==BMTType.C) {// C-detector BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); } } @@ -586,7 +587,7 @@ public List findCandUsingMicroMegas(Seed trkCand, return AllSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index b5e107a83..715efa7ef 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -11,6 +11,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.Constants; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -131,7 +132,7 @@ private class RayMeasurements { * @param list the input list of crosses * @return an array list of track candidates in the SVT */ - public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { X.clear(); Y.clear(); Z.clear(); @@ -216,7 +217,7 @@ public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, or * @return an array list of track candidates in the SVT */ public ArrayList getHelicalTracks(CrossList crossList, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, Swim swimmer) { @@ -333,7 +334,7 @@ public ArrayList getHelicalTracks(CrossList crossList, * @param SVTCrossList the input list of crosses * @return an array list of track candidates in the SVT */ - public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { ArrayList cands = new ArrayList(); Map candMap= new HashMap(); @@ -541,14 +542,14 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, //make lists for (Cross c : list) { - if (c.get_Detector() == "SVT") { + if (c.get_Detector().equalsIgnoreCase("SVT")) { SVTcrossesInTrk.add(c); } - if (c.get_Detector() == "BMT") { // Micromegas - if (c.get_DetectorType() == "C") {//C-detector --> only Z defined + if (c.get_Detector().equalsIgnoreCase("BMT")) { // Micromegas + if (c.get_DetectorType() == BMTType.C) {//C-detector --> only Z defined BMTCdetcrossesInTrk.add(c); } - if (c.get_DetectorType() == "Z") {//Z-detector --> only phi defined + if (c.get_DetectorType() == BMTType.Z) {//Z-detector --> only phi defined BMTZdetcrossesInTrk.add(c); } } @@ -679,10 +680,10 @@ private RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, bo SVTcrossesInTrk.add(c); } if (c.get_Detector().equalsIgnoreCase("BMT")) { // Micromegas - if (c.get_DetectorType() == "C") {//C-detector --> only Z defined + if (c.get_DetectorType() == BMTType.C) {//C-detector --> only Z defined BMTCdetcrossesInTrk.add(c); } - if (c.get_DetectorType().equalsIgnoreCase("Z")) {//Z-detector --> only phi defined + if (c.get_DetectorType()==BMTType.Z) {//Z-detector --> only phi defined BMTZdetcrossesInTrk.add(c); } } @@ -771,7 +772,7 @@ private void resetUnusedCross(Cross cross, org.jlab.rec.cvt.svt.Geometry geo) { * @param geo the BMT geometry * @return an arraylist of BMT crosses matched to the track */ - public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thecand, org.jlab.rec.cvt.bmt.Geometry geo) { + public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thecand, org.jlab.rec.cvt.bmt.BMTGeometry geo) { double matchCutOff = org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUAL; // ? guess @@ -810,7 +811,7 @@ public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thec return BMTCrossList; } - private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, org.jlab.rec.cvt.bmt.Geometry geo) { + private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, org.jlab.rec.cvt.bmt.BMTGeometry geo) { ArrayList matchedMMCrosses = new ArrayList(); @@ -849,7 +850,7 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse continue; } //if(Double.isNaN(MMCrosses.get(i).get_Point0().z())) - if (MMCrosses.get(i).get_DetectorType().equalsIgnoreCase("Z")) { + if (MMCrosses.get(i).get_DetectorType()==BMTType.Z) { continue; } double m_z = MMCrosses.get(i).get_Point().z(); @@ -917,7 +918,7 @@ private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosse } // measuring phi //if(Double.isNaN(MMCrosses.get(i).get_Point0().x())) - if (MMCrosses.get(i).get_DetectorType().equalsIgnoreCase("C")) { + if (MMCrosses.get(i).get_DetectorType()==BMTType.C) { continue; } double m_x = MMCrosses.get(i).get_Point().x(); @@ -1043,7 +1044,7 @@ private void EliminateStraightTrackOutliers(ArrayList crossesToFit, } } - public void matchClusters(List sVTclusters, TrajectoryFinder tf, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, boolean trajFinal, + public void matchClusters(List sVTclusters, TrajectoryFinder tf, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal, ArrayList trajectory, int k) { if(trajectory == null) return; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 837896687..c32d8311f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -9,6 +9,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -26,7 +27,7 @@ public TrackListFinder() { * @return the list of selected tracks */ public List getTracks(List cands, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, Swim bstSwim) { List tracks = new ArrayList(); @@ -161,7 +162,7 @@ private void getOverlapLists(Track track, List trkcands, List list for( Cross c : t ) { // do not check on BMTC - if( c.get_DetectorType().equalsIgnoreCase("C") == true ) continue; + if( c.get_DetectorType()==BMTType.C == true ) continue; if( track.contains(c) ) { N++; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index ab25ca6d8..768f8d98c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -8,6 +8,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.CircleFitter; @@ -83,7 +84,7 @@ private void FitSeed(List seedcrs) { Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) System.err.println("WRONG CROSS TYPE"); + if(c.get_DetectorType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); @@ -209,7 +210,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); public List findSeed(List bst_crosses, List bmt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, Swim swimmer) { List seedlist = new ArrayList(); @@ -220,9 +221,9 @@ public List findSeed(List bst_crosses, List bmt_crosses, if(bmt_crosses!=null) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType().equalsIgnoreCase("Z") && this.unUsedHitsOnly == true) + if(c.get_DetectorType()==BMTType.Z && this.unUsedHitsOnly == true) crosses.add(c); - if(c.get_DetectorType().equalsIgnoreCase("C") && this.unUsedHitsOnly == true) + if(c.get_DetectorType()==BMTType.C && this.unUsedHitsOnly == true) bmtC_crosses.add(c); } } @@ -238,7 +239,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, for(Seed mseed : seedScan) { List seedcrs = mseed.get_Crosses(); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C ) continue; c.set_AssociatedTrackID(122220); } // loop until a good circular fit. removing far crosses each time @@ -255,7 +256,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C ) continue; c.set_AssociatedTrackID(122221); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); @@ -274,7 +275,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, double r = pars.rho(); double f = pars.phi(); for (Cross c : seedcrs ) { - if(c.get_DetectorType().equalsIgnoreCase("C") ) continue; + if(c.get_DetectorType()==BMTType.C) continue; c.set_AssociatedTrackID(122222); double xi = c.get_Point().x(); double yi = c.get_Point().y(); @@ -346,7 +347,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init @@ -515,7 +516,7 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -531,7 +532,7 @@ public List findCandUsingMicroMegas(Seed trkCand, //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_DetectorType().equalsIgnoreCase("C")) // C-detector + if (bmt_cross.get_DetectorType()==BMTType.C) // C-detector BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); } @@ -592,7 +593,7 @@ public List findCandUsingMicroMegas(Seed trkCand, return AllSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 996e13c78..ccd378352 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -8,6 +8,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.CircleFitter; @@ -169,7 +170,7 @@ private ArrayList getCrossFromCells( List l ){ // create and run the cellular automaton public List runCAMaker( String plane, int nepochs, ArrayList crs, - org.jlab.rec.cvt.bmt.Geometry bgeom, + org.jlab.rec.cvt.bmt.BMTGeometry bgeom, Swim swimmer){ MakerCA camaker = new MakerCA(false); camaker.set_plane( plane ); @@ -192,7 +193,7 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs, public List findSeed(List svt_crosses, List bmt_crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, Swim swimmer) { List seedlist = new ArrayList(); @@ -206,9 +207,9 @@ public List findSeed(List svt_crosses, List bmt_crosses, // Collections.sort(crosses); for(Cross c : bmt_crosses) { - if(c.get_DetectorType().equalsIgnoreCase("Z")) + if(c.get_DetectorType()==BMTType.Z) crosses.add(c); - if(c.get_DetectorType().equalsIgnoreCase("C")) { + if(c.get_DetectorType()==BMTType.C) { bmtC_crosses.get(c.get_Sector()-1).add(c); } } @@ -330,7 +331,7 @@ public List> CAonRZ( List>xytracks , List> bmtC_crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, Swim swimmer) { List> seedCrosses = new ArrayList>(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 7092a0ba3..9ec191760 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -14,6 +14,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.hit.FittedHit; @@ -42,7 +43,7 @@ public TrajectoryFinder() { * @return a trajectory object */ public Trajectory findTrajectory(int id, Track trk, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, + org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, Swim swimmer, String isFinal) { Helix helix = trk.get_helix(); @@ -170,10 +171,10 @@ public Trajectory findTrajectory(int id, Track trk, } double R = 0; - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(l + 1-6) == 1) { + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1-6) == 1) { R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(l + 1-6) == 0) { + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1-6) == 0) { R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } @@ -314,7 +315,7 @@ private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, } - public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo) { + public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { Trajectory traj = new Trajectory(ray); traj.set_Id(id); @@ -432,7 +433,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList if (this.matchCrossToStateVec(c, stVec, l + 1, c.get_Sector()) == false) { continue; } - if (c.get_DetectorType().equalsIgnoreCase("C")) { //C-detector measuring Z + if (c.get_DetectorType()==BMTType.C) { //C-detector measuring Z //if(traj.isFinal) { // reset the cross only for final trajectory c.set_Point(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.get_Point().z())); @@ -444,7 +445,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList stVec, svt_geo, bmt_geo, traj.isFinal); } - if (c.get_DetectorType().equalsIgnoreCase("Z")) { //Z-detector measuring phi + if (c.get_DetectorType()==BMTType.Z) { //Z-detector measuring phi //if(traj.isFinal) { c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), ZtrackIntersSurf)); @@ -496,8 +497,8 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec if (c.get_Region() != (int) (l / 2) + 1) { value = false; // reauire same region } - if (c.get_DetectorType().equalsIgnoreCase("C")) { //C-detector measuring Z - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { //Z-detector measuring phi + if (c.get_DetectorType()==BMTType.C) { //C-detector measuring Z + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { //Z-detector measuring phi value = false; } @@ -505,8 +506,8 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec value = false; } } - if (c.get_DetectorType().equalsIgnoreCase("Z")) { //Z-detector measuring phi - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { //C-detector + if (c.get_DetectorType()==BMTType.Z) { //Z-detector measuring phi + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { //C-detector value = false; } double deltaXt = Math.sqrt((stVec.x() - c.get_Point().x()) * (stVec.x() - c.get_Point().x()) + (stVec.y() - c.get_Point().y()) * (stVec.y() - c.get_Point().y())); @@ -527,7 +528,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec * @param stVec stateVec */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, - StateVec stVec, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.Geometry bmt_geo, boolean trajFinal) { + StateVec stVec, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal) { if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); @@ -547,7 +548,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } if (detector.equalsIgnoreCase("BMT")) { - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { //C-detector measuring z + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { //C-detector measuring z for (FittedHit h1 : cluster) { // calculate the hit residuals double docaToTrk = stVec.z() - h1.get_Strip().get_Z(); @@ -561,7 +562,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { //Z-detector measuring phi + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { //Z-detector measuring phi // calculate the hit residuals for (FittedHit h1 : cluster) { double StripX = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] * Math.cos(h1.get_Strip().get_Phi()); @@ -582,7 +583,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } - private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.Geometry bmt_geo, int start_layer) { + private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int start_layer) { //[l][hemisphere], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip; hemisphere = [1]top or [0]bottom double[][][] result = new double[6][2][7]; for (int l = start_layer - 1; l < 6; l++) { @@ -740,7 +741,7 @@ private double[] getIntersectionTrackWithSVTModule(int s, int l, private double[][] getIntersectionTrackWithBMTModules(int l, double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2, org.jlab.rec.cvt.bmt.Geometry geo) { + double _yzslope2, org.jlab.rec.cvt.bmt.BMTGeometry geo) { // array [][][][] =[x][y][z][stripCentroid] double[][] inters = new double[2][4]; double[] inters_top = new double[4]; @@ -756,10 +757,10 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters_bottom[3] = Double.NaN; double R = 0; - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(l + 1) == 0) { + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1) == 0) { R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(l + 1) == 1) { + if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1) == 1) { R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } // solve for intersection of line with cylinder of radius R From 051f577e340a1412b49f2da58e554ec2aaa2b58d Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 12 Nov 2020 09:29:37 -0500 Subject: [PATCH 042/291] refactoring for geometry implementation From 93f32a632c16ee2669751b4d8f14f5bdb4b9dc10 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 12 Nov 2020 09:59:22 -0500 Subject: [PATCH 043/291] run second algorithm only on hits not on track. --- .../rec/cvt/services/TracksFromTargetRec.java | 6 ++-- .../org/jlab/rec/cvt/track/TrackSeeder.java | 31 +++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index c14fba65d..cfc99f31e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -65,9 +65,9 @@ public boolean processEvent(DataEvent event, TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - // TrackSeeder trseed2 = new TrackSeeder(); - // trseed2.unUsedHitsOnly = true; - // seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); + TrackSeeder trseed2 = new TrackSeeder(); + trseed2.unUsedHitsOnly = true; + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); } } if(seeds ==null || seeds.size() == 0) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 768f8d98c..72d7b5baf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -221,16 +221,35 @@ public List findSeed(List bst_crosses, List bmt_crosses, if(bmt_crosses!=null) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType()==BMTType.Z && this.unUsedHitsOnly == true) - crosses.add(c); - if(c.get_DetectorType()==BMTType.C && this.unUsedHitsOnly == true) - bmtC_crosses.add(c); + if(c.get_DetectorType()==BMTType.Z) { + if(this.unUsedHitsOnly == false) { + crosses.add(c); + } else { + if(this.unUsedHitsOnly == true && c.isInSeed == false) { + crosses.add(c); + } + } + } + if(c.get_DetectorType()==BMTType.C) { + if(this.unUsedHitsOnly == false) { + bmtC_crosses.add(c); + } else { + if(this.unUsedHitsOnly == true && c.isInSeed == false) { + bmtC_crosses.add(c); + } + } + } } } if(bst_crosses!=null) { for(Cross c : bst_crosses) { - if(this.unUsedHitsOnly == true) - svt_crosses.add(c); + if(this.unUsedHitsOnly == false) { + svt_crosses.add(c); + } else { + if(this.unUsedHitsOnly == true && c.isInSeed == false) { + svt_crosses.add(c); + } + } } } this.FindSeedCrossList(svt_crosses); From 8b2bc42e2f203fb7fbf52a4f648d1ecc9aa93be3 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 12 Nov 2020 21:34:43 +0100 Subject: [PATCH 044/291] SVT geometry: read and use new layeralignment table --- .../detector/geant4/v2/SVT/SVTConstants.java | 29 +++++++++++++++++++ .../geant4/v2/SVT/SVTStripFactory.java | 20 ++++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index de0a4eee5..a4edff0cb 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -38,6 +38,7 @@ public class SVTConstants // data for alignment shifts private static double[][] SECTORSHIFTDATA = null; private static String filenameSectorShiftData = null; + private static double[][][] LAYERSHIFTDATA = null; //private static double[][] LAYERSHIFTDATA = null; //private static String filenameLayerShiftData = null; @@ -118,6 +119,7 @@ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) cp.loadTable( ccdbPath +"material/box"); cp.loadTable( ccdbPath +"material/tube"); cp.loadTable( ccdbPath +"alignment"); + cp.loadTable( ccdbPath +"layeralignment"); //shift by target cp.loadTable("/geometry/target"); @@ -379,6 +381,22 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table } + LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS][]; + for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 + { + int sector = cp.getInteger(ccdbPath+"layeralignment/sector", i ); + int layer = cp.getInteger(ccdbPath+"layeralignment/layer", i ); + double tx = cp.getDouble(ccdbPath+"layeralignment/deltaX", i ); + double ty = cp.getDouble(ccdbPath+"layeralignment/deltaY", i ); + double tz = cp.getDouble(ccdbPath+"layeralignment/deltaZ", i ); + double rx = cp.getDouble(ccdbPath+"layeralignment/rotX", i ); + double ry = cp.getDouble(ccdbPath+"layeralignment/rotY", i ); + double rz = cp.getDouble(ccdbPath+"layeralignment/rotZ", i ); + double ra = cp.getDouble(ccdbPath+"layeralignment/rotA", i ); + LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; + } + + if( VERBOSE ) { System.out.println("NSECTORS STATUS Z0ACTIVE REFRADIUS SUPPORTRADIUS LAYERRADIUS (U,V)"); @@ -832,4 +850,15 @@ public static double[][] getDataAlignmentSectorShift() if( SECTORSHIFTDATA == null ){ System.err.println("error: SVTConstants.getDataAlignmentSectorShift: SECTORSHIFTDATA requested is null"); } // System.exit(-1); return SECTORSHIFTDATA; } + + /** + * Returns the layer/sector alignment data + * @return + */ + public static double[][][] getLayerSectorAlignmentData() { + if(LAYERSHIFTDATA == null ) { System.err.println("error: SVTConstants.getLayerSectorAlignmentData: LAYERSHIFTDATA requested is null"); } + return LAYERSHIFTDATA; + } + + } diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java index e978e7bfb..52a9a59de 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java @@ -46,7 +46,7 @@ public SVTStripFactory( DatabaseConstantProvider cp, boolean applyAlignmentShift { SVTConstants.load( cp ); setApplyAlignmentShifts( applyAlignmentShifts ); - if( bShift == true && SVTConstants.getDataAlignmentSectorShift() == null ){ + if( bShift == true && SVTConstants.getLayerSectorAlignmentData()== null ){ System.err.println("error: SVTStripFactory: no shifts loaded"); System.exit(-1); } @@ -290,10 +290,13 @@ public Line3d getShiftedStrip( int aLayer, int aSector, int aStrip ) throws Ille */ public Line3d getShiftedStrip( int aRegion, int aSector, int aModule, int aStrip ) { + int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); Line3d stripLine = getIdealStrip( aRegion, aSector, aModule, aStrip ); - AlignmentFactory.applyShift( stripLine.origin(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( aRegion, aSector )], SVTAlignmentFactory.getIdealFiducialCenter( aRegion, aSector ), scaleT, scaleR ); - AlignmentFactory.applyShift( stripLine.end(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( aRegion, aSector )], SVTAlignmentFactory.getIdealFiducialCenter( aRegion, aSector ), scaleT, scaleR ); - return stripLine; + if(aRegion Date: Tue, 17 Nov 2020 22:23:21 +0100 Subject: [PATCH 045/291] SVTgeometry: completed switch to new layeralignment table --- .../geant4/v2/SVT/SVTAlignmentFactory.java | 8 +- .../detector/geant4/v2/SVT/SVTConstants.java | 200 +++++------------- .../geant4/v2/SVT/SVTStripFactory.java | 17 -- .../geant4/v2/SVT/SVTVolumeFactory.java | 5 +- .../java/org/jlab/rec/cvt/svt/Geometry.java | 18 +- 5 files changed, 66 insertions(+), 182 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java index a3f6b38a4..fac568607 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java @@ -237,7 +237,7 @@ public static double[][] getShiftedFiducialData() Vector3d fidPos3Ds[] = getShiftedFiducials( region, sector ); for( int fid = 0; fid < SVTConstants.NFIDUCIALS; fid++ ) data[SVTConstants.convertRegionSectorFiducial2Index( region, sector, fid )] = new double[]{ fidPos3Ds[fid].x, fidPos3Ds[fid].y, fidPos3Ds[fid].z }; - } + } return data; } @@ -257,9 +257,9 @@ public static double[][] getFactoryIdealFiducialData() for( int fid = 0; fid < SVTConstants.NFIDUCIALS; fid++ ) { data[SVTConstants.convertRegionSectorFiducial2Index( region, sector, fid )] - = new double[]{ fidPos3Ds[fid].x, fidPos3Ds[fid].y, fidPos3Ds[fid].z }; + = new double[]{ fidPos3Ds[fid].x, fidPos3Ds[fid].y, fidPos3Ds[fid].z }; + } } - } return data; } @@ -282,7 +282,7 @@ public static Vector3d[] getShiftedFiducials( int aRegion, int aSector ) throws Triangle3d fidTri3D = new Triangle3d( fidPos3Ds[0], fidPos3Ds[1], fidPos3Ds[2] ); for( int f = 0; f < SVTConstants.NFIDUCIALS; f++ ) - applyShift( fidPos3Ds[f], SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( aRegion, aSector )], fidTri3D.center() ); + applyShift( fidPos3Ds[f], SVTConstants.getLayerSectorAlignmentData()[aSector][SVTConstants.convertRegionModule2Layer(aRegion, 0)], fidTri3D.center() ); return fidPos3Ds; } diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index a4edff0cb..ba38ff105 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -36,8 +36,7 @@ public class SVTConstants private static boolean bLoadedConstants = false; // only load constants once // data for alignment shifts - private static double[][] SECTORSHIFTDATA = null; - private static String filenameSectorShiftData = null; +// private static String filenameSectorShiftData = null; private static double[][][] LAYERSHIFTDATA = null; //private static double[][] LAYERSHIFTDATA = null; @@ -118,7 +117,6 @@ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) cp.loadTable( ccdbPath +"fiducial"); cp.loadTable( ccdbPath +"material/box"); cp.loadTable( ccdbPath +"material/tube"); - cp.loadTable( ccdbPath +"alignment"); cp.loadTable( ccdbPath +"layeralignment"); //shift by target cp.loadTable("/geometry/target"); @@ -360,28 +358,13 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table for( int aSector = 0; aSector < NSECTORS[aRegion]; aSector++ ) { RSI[aRegion][aSector] = convertRegionSector2Index( aRegion, aSector ); - System.out.println(" a Region "+aRegion +" aSector "+aSector+" RSI "+RSI[aRegion][aSector] ); +// System.out.println(" a Region "+aRegion +" aSector "+aSector+" RSI "+RSI[aRegion][aSector] ); } } System.out.println("Reading alignment shifts from database"); - SECTORSHIFTDATA = new double[NTOTALSECTORS][]; - for( int i = 0; i < NTOTALSECTORS; i++ ) - { - double tx = cp.getDouble(ccdbPath+"alignment/tx", i ); - double ty = cp.getDouble(ccdbPath+"alignment/ty", i ); - double tz = cp.getDouble(ccdbPath+"alignment/tz", i ); - double rx = cp.getDouble(ccdbPath+"alignment/rx", i ); - double ry = cp.getDouble(ccdbPath+"alignment/ry", i ); - double rz = cp.getDouble(ccdbPath+"alignment/rz", i ); - double ra = cp.getDouble(ccdbPath+"alignment/ra", i ); - - SECTORSHIFTDATA[i] = new double[]{ tx, ty, tz, rx, ry, rz, Math.toRadians(ra) }; - - } - - LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS][]; + LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { int sector = cp.getInteger(ccdbPath+"layeralignment/sector", i ); @@ -395,7 +378,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table double ra = cp.getDouble(ccdbPath+"layeralignment/rotA", i ); LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; } - + if( VERBOSE ) showLayerShiftData(); if( VERBOSE ) { @@ -481,93 +464,41 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table } } - - - /** - * Reads alignment data from CCDB. - * - * @param cp a DatabaseConstantProvider that has loaded the "alignment" table - */ - public static synchronized void loadAlignmentShifts( ConstantProvider cp ) - { - System.out.println("reading alignment shifts from database"); - SECTORSHIFTDATA = new double[NTOTALSECTORS][]; - //LAYERSHIFTDATA = new double[NTOTALSECTORS*NMODULES][]; - - for( int i = 0; i < NTOTALSECTORS; i++ ) - { - double tx = cp.getDouble(ccdbPath+"alignment/tx", i ); - double ty = cp.getDouble(ccdbPath+"alignment/ty", i ); - double tz = cp.getDouble(ccdbPath+"alignment/tz", i ); - double rx = cp.getDouble(ccdbPath+"alignment/rx", i ); - double ry = cp.getDouble(ccdbPath+"alignment/ry", i ); - double rz = cp.getDouble(ccdbPath+"alignment/rz", i ); - double ra = cp.getDouble(ccdbPath+"alignment/ra", i ); - - SECTORSHIFTDATA[i] = new double[]{ tx, ty, tz, rx, ry, rz, Math.toRadians(ra) }; - - /*double stx = cp.getDouble(ccdbPath+"alignment/sector/tx", i ); - double sty = cp.getDouble(ccdbPath+"alignment/sector/ty", i ); - double stz = cp.getDouble(ccdbPath+"alignment/sector/tz", i ); - double srx = cp.getDouble(ccdbPath+"alignment/sector/rx", i ); - double sry = cp.getDouble(ccdbPath+"alignment/sector/ry", i ); - double srz = cp.getDouble(ccdbPath+"alignment/sector/rz", i ); - double sra = cp.getDouble(ccdbPath+"alignment/sector/ra", i ); - - SECTORSHIFTDATA[i] = new double[]{ tx, ty, tz, rx, ry, rz, Math.toRadians(ra) }; - - for( int j = 0; j < NMODULES; j++ ) - { - double ltx = cp.getDouble(ccdbPath+"alignment/layer/tx", i ); - double lty = cp.getDouble(ccdbPath+"alignment/layer/ty", i ); - double ltz = cp.getDouble(ccdbPath+"alignment/layer/tz", i ); - double lrx = cp.getDouble(ccdbPath+"alignment/layer/rx", i ); - double lry = cp.getDouble(ccdbPath+"alignment/layer/ry", i ); - double lrz = cp.getDouble(ccdbPath+"alignment/layer/rz", i ); - double lra = cp.getDouble(ccdbPath+"alignment/layer/ra", i ); - - SECTORSHIFTDATA[i] = new double[]{ ltx, lty, ltz, lrx, lry, lrz, Math.toRadians(lra) }; - }*/ - } - //if( VERBOSE ) - showSectorShiftData(); - } - - /** - * Reads alignment data for sectors from the given file. - * The translation and axis-angle rotation data should be of the form { tx, ty, tz, rx, ry, rz, ra }. - * - * @param aFilename a filename - */ - public static void loadAlignmentSectorShifts( String aFilename ) - { - filenameSectorShiftData = aFilename; - - try - { - SECTORSHIFTDATA = Util.inputTaggedData( filenameSectorShiftData, AlignmentFactory.NSHIFTDATARECLEN ); // 3 translation(x,y,z), 4 rotation(x,y,z,a) - } - catch( Exception e ) - { - e.printStackTrace(); - System.exit(-1); // trigger fatal error - } - - if( SECTORSHIFTDATA == null ) - { - System.err.println("stop: SHIFTDATA is null after reading file \""+filenameSectorShiftData+"\""); - System.exit(-1); - } - - for( int k = 0; k < NTOTALSECTORS; k++ ) - { - SECTORSHIFTDATA[k][6] = Math.toRadians(SECTORSHIFTDATA[k][6]); // convert shift angle to radians - } - - if( VERBOSE ) showSectorShiftData(); - } +// /** +// * Reads alignment data for sectors from the given file. +// * The translation and axis-angle rotation data should be of the form { tx, ty, tz, rx, ry, rz, ra }. +// * +// * @param aFilename a filename +// */ +// public static void loadAlignmentSectorShifts( String aFilename ) +// { +// filenameSectorShiftData = aFilename; +// +// try +// { +// SECTORSHIFTDATA = Util.inputTaggedData( filenameSectorShiftData, AlignmentFactory.NSHIFTDATARECLEN ); // 3 translation(x,y,z), 4 rotation(x,y,z,a) +// } +// catch( Exception e ) +// { +// e.printStackTrace(); +// System.exit(-1); // trigger fatal error +// } +// +// if( SECTORSHIFTDATA == null ) +// { +// System.err.println("stop: SHIFTDATA is null after reading file \""+filenameSectorShiftData+"\""); +// System.exit(-1); +// } +// +// for( int k = 0; k < NTOTALSECTORS; k++ ) +// { +// SECTORSHIFTDATA[k][6] = Math.toRadians(SECTORSHIFTDATA[k][6]); // convert shift angle to radians +// } +// +// if( VERBOSE ) showSectorShiftData(); +// } /* @@ -608,45 +539,25 @@ public static void loadAlignmentSectorShifts( String aFilename ) /** * Prints alignment shift data for sectors to screen. */ - public static void showSectorShiftData() + public static void showLayerShiftData() { - //System.out.printf("i%8stx%7sty%7stz%7srx%7sry%7srz%7sra\n","","","","","","",""); - System.out.printf(" i%9stranslation(x,y,z)%19srotation(x,y,z,a)\n","",""); - for( int i = 0; i < NTOTALSECTORS; i++ ) - { - System.out.printf("%2d", i+1 ); + System.out.printf(" l%3ss%4stranslation(x,y,z)%9srotation(x,y,z,a)\n","","",""); + for( int k = 0; k < NLAYERS-2; k++ ) + { + for( int i = 0; i < NSECTORS[k/2]; i++ ) + { + System.out.printf("%2d %2d", k+1, i+1); for( int d = 0; d < AlignmentFactory.NSHIFTDATARECLEN-1; d++ ) - System.out.printf(" %8.3f", SECTORSHIFTDATA[i][d] ); - System.out.printf(" %8.3f", Math.toDegrees(SECTORSHIFTDATA[i][AlignmentFactory.NSHIFTDATARECLEN-1]) ); + System.out.printf(" %8.3f", LAYERSHIFTDATA[i][k][d] ); + System.out.printf(" %8.3f", Math.toDegrees(LAYERSHIFTDATA[i][k][AlignmentFactory.NSHIFTDATARECLEN-1]) ); System.out.println(); + } } } - - - /* - * Prints alignment shift data for layers to screen. - */ - /*public static void showLayersShiftData() - { - //System.out.printf("i%8stx%7sty%7stz%7srx%7sry%7srz%7sra\n","","","","","","",""); - System.out.printf(" i%9stranslation(x,y,z)%19srotation(x,y,z,a)\n","",""); - for( int i = 0; i < NTOTALSECTORS; i++ ) - { - for( int j = 0; j < NMODULES; j++ ) - { - System.out.printf("%2d", i+1 ); - for( int d = 0; d < AlignmentFactory.NSHIFTDATARECLEN-1; d++ ) - System.out.printf(" %8.3f", LAYERSHIFTDATA[i][d] ); - System.out.printf(" %8.3f", Math.toDegrees(LAYERSHIFTDATA[i][AlignmentFactory.NSHIFTDATARECLEN-1]) ); - System.out.println(); - } - } - }*/ - + /** - * Converts RSF indices to linear index. - * Useful for writing data files. + * Converts RSF indices to linear index.Useful for writing data files. * * @param aRegion an index starting from 0 * @param aSector an index starting from 0 @@ -704,7 +615,7 @@ public static int convertRegionSector2Index( int aRegion, int aSector ) throws I } - + /** * Converts linear index to Region and Sector indices. * For use with data files. @@ -840,17 +751,6 @@ public static Transform getStripFrame( boolean aFlip ) } - /** - * Returns the sector alignment data. - * - * @return double[][] an array of translations and axis-angle rotations of the form { tx, ty, tz, rx, ry, rz, ra } - */ - public static double[][] getDataAlignmentSectorShift() - { - if( SECTORSHIFTDATA == null ){ System.err.println("error: SVTConstants.getDataAlignmentSectorShift: SECTORSHIFTDATA requested is null"); } // System.exit(-1); - return SECTORSHIFTDATA; - } - /** * Returns the layer/sector alignment data * @return diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java index 52a9a59de..3ea0f0a84 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java @@ -52,23 +52,6 @@ public SVTStripFactory( DatabaseConstantProvider cp, boolean applyAlignmentShift } } - /** - * Constructs a new geometry factory for sensor strips, with alignment shifts applied from the given file. - * Please run {@code SVTConstants.connect() } first. - * - * @param cp a DatabaseConstantProvider that has loaded the necessary tables - * @param filenameAlignmentShifts a file containing the alignment shifts to be applied - * - * @see SVTConstants#connect - */ - public SVTStripFactory( DatabaseConstantProvider cp, String filenameAlignmentShifts ) - { - SVTConstants.load( cp ); - bShift = true; - SVTConstants.loadAlignmentSectorShifts( filenameAlignmentShifts ); - } - - /** * Returns either an ideal or shifted strip, depending on this factory's setup. * diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTVolumeFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTVolumeFactory.java index f0475af44..b3d788e43 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTVolumeFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTVolumeFactory.java @@ -107,7 +107,7 @@ public SVTVolumeFactory( DatabaseConstantProvider cp, boolean applyAlignmentShif { SVTConstants.load( cp ); setApplyAlignmentShifts( applyAlignmentShifts ); - if( bShift == true && SVTConstants.getDataAlignmentSectorShift() == null ){ + if( bShift == true && SVTConstants.getLayerSectorAlignmentData() == null ){ System.err.println("error: SVTVolumeFactory: no shifts loaded"); System.exit(-1); } @@ -269,7 +269,8 @@ public void makeVolumes() //System.out.println( stepVol.getChildren().get(j).gemcString() ); }*/ - AlignmentFactory.applyShift( sectorVol, SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( region, sector )], fidTri3D.center(), scaleT, scaleR ); + // FIXME currently using shifts from bottom module of each region + AlignmentFactory.applyShift( sectorVol, SVTConstants.getLayerSectorAlignmentData()[sector][region*2], fidTri3D.center(), scaleT, scaleR ); //System.out.println("S "+sectorVol.gemcString() ); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java index 24fb72f72..5c7f5642f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java @@ -78,10 +78,10 @@ public Point3D getPlaneModuleOrigin(int sector, int layer) { //System.out.println(" GET MODULE O "+labFrameLine.origin().toString()); //System.out.println(" GET MODULE 1 "+SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( rm[0],sector-1)].toString()); //System.out.println(" GET MODULE 2 "+new Point3D(SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).x, SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).y, SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).z).toString()); - if(SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( rm[0],sector-1)]==null) + if(SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1]==null) System.out.println(" SHIFT ARRAY NULL FOR "+rm[0]+" sect "+(sector-1)); - AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); - AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); // return only the origin of the line. @@ -106,8 +106,8 @@ public Point3D getPlaneModuleEnd(int sector, int layer) { SVTConstants.Z0ACTIVE[ rm[0] ] )); // apply the shifts to both ends of labFrameLine double scaleT = 1.0, scaleR = -1.0;// scale factors used for visualization. Not relevant here. - AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); - AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); // return only the origin of this line. return new Point3D(labFrameLine.origin().x, labFrameLine.origin().y, labFrameLine.origin().z); @@ -237,8 +237,8 @@ public Point3D transformToFrame(int sector, int layer, double x, double y, doubl //gpg apply the shifts to both ends of labFrameLine. double scaleT = 1.0, scaleR = -1.0;// scale factors used for visualization. Not relevant here. - AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); - AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); + AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); transf= new Point3D(labFrameLine.origin().x, labFrameLine.origin().y, @@ -251,8 +251,8 @@ public Point3D transformToFrame(int sector, int layer, double x, double y, doubl //gpg need to apply the reverse survey shifts here. double scaleT = 1.0, scaleR = -1.0;// scale factors used for visualization. Not relevant here. - AlignmentFactory.applyInverseShift( glLine.origin(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); - AlignmentFactory.applyInverseShift( glLine.end(), SVTConstants.getDataAlignmentSectorShift()[SVTConstants.RSI[rm[0]][sector-1]], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); + AlignmentFactory.applyInverseShift( glLine.origin(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); + AlignmentFactory.applyInverseShift( glLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); Line3d localLine = glLine.transformed(SVTConstants.getLabFrame( (int)((layer+1)/2) -1, sector-1, From 775768bbaf19bb820be4eb3f634a521be4611a8f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 16:00:12 -0500 Subject: [PATCH 046/291] code cleanup. --- .../kalmanfilter/helical/StateVecs.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index f74042f85..8768ca03a 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -7,7 +7,6 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Line3D; import Jama.Matrix; import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.clas.swimtools.Swim; @@ -44,9 +43,17 @@ public class StateVecs { public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, boolean useSwimmer) { - this.resetArrays(swimPars); - this.resetArrays(value); - + if(swimPars!=null) { + this.resetArrays(swimPars); + } else { + swimPars = new double[7]; + } + if(value!=null) { + this.resetArrays(value); + } else { + value = new double[4]; + } + Point3D ps = new Point3D(0,0,0) ; StateVec kVec = new StateVec(k); @@ -170,12 +177,6 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim int nSteps = (int) (r/stepSize); double dist = 0; - -// for(int i = 1; i=Math.abs(C)) { util.setD0(-(x0-X0.get(0))/S) ; } else { From 0191e48d462649dc34b741300cf3d5eca3d3c49c Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 16:01:40 -0500 Subject: [PATCH 047/291] CVT fit speed improvements. Cut off KF iterations based on delta chi2 --- .../kalmanfilter/helical/KFitter.java | 5 +- .../jlab/clas/tracking/trackrep/Helix.java | 53 ++++++++++++++++--- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 8a7365e5f..d4c30de85 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -137,11 +137,14 @@ public void runFitter(Swim swimmer) { // chi2 this.chi2=this.calc_chi2(swimmer); if(this.chi2 Cm) { x = xp; y = yp; From c1fedae25f4a8670f30d16a58ab764da4ccdb8d3 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 16:02:32 -0500 Subject: [PATCH 048/291] SwimRho step size and accuracy increase for swimming speed increase. --- .../swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1a3d89c7c..4e6d83f54 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 @@ -488,7 +488,7 @@ public double[] SwimRho(double radius) { SwimResult result = new SwimResult(6); - PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); + PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy*2, _rMax, stepSize*10, cnuphys.swim.Swimmer.CLAS_Tolerance, result); value[0] = result.getUf()[0] * 100; // convert back to cm value[1] = result.getUf()[1] * 100; // convert back to cm From d9c7453913c9a699363a6f03e5c870f6ff5cbe62 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 16:03:08 -0500 Subject: [PATCH 049/291] Unit test switch to new service --- .../java/org/jlab/rec/cvt/services/CVTReconstructionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java b/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java index deb15892e..63ed61612 100644 --- a/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java +++ b/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java @@ -45,7 +45,7 @@ public void testCVTReconstruction() { enf.init(); enf.processDataEvent(testEvent); - CVTReconstruction CVTengine = new CVTReconstruction(); + CVTRecNewKF CVTengine = new CVTRecNewKF(); CVTengine.init(); testEvent.show(); From 5b1ec4ee4bd8f78753a93fe06201172732b4fcbd Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 16:04:20 -0500 Subject: [PATCH 050/291] Remove duplicate seeds before fitting. --- .../org/jlab/rec/cvt/services/TracksFromTargetRec.java | 5 ++--- .../main/java/org/jlab/rec/cvt/track/TrackSeederCA.java | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index cfc99f31e..862412bcc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -13,7 +13,6 @@ import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; @@ -63,7 +62,7 @@ public boolean processEvent(DataEvent event, } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); + seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA TrackSeeder trseed2 = new TrackSeeder(); trseed2.unUsedHitsOnly = true; @@ -134,7 +133,7 @@ public boolean processEvent(DataEvent event, tracks.get(i).set_Id(i+1); } //System.out.println( " *** *** trkcands " + trkcands.size() + " * trks " + trks.size()); - trkFinder.removeOverlappingTracks(tracks); //turn off until debugged + //trkFinder.removeOverlappingTracks(tracks); //turn off until debugged for (int c = 0; c < tracks.size(); c++) { tracks.get(c).set_Id(c + 1); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index ccd378352..ccf69e48b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -190,7 +190,7 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs, camaker.evolve( nepochs ); return camaker.getNodes(); } - + TrackListFinder trkFinder = new TrackListFinder(); public List findSeed(List svt_crosses, List bmt_crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, @@ -244,8 +244,8 @@ public List findSeed(List svt_crosses, List bmt_crosses, } // for( int i=0;i VTCrosses, else { cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses } - + cand.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); + cand.setNDF(X.size()+Z.size()); //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; From 2c16a2a7409e2c5555586869c4ca455954a5aacd Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 18 Nov 2020 17:34:20 -0500 Subject: [PATCH 051/291] switch CVT service name --- .../src/main/java/org/jlab/clas/reco/EngineProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java index 55a2a9f06..ca68c3e8b 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java @@ -98,7 +98,7 @@ public void initAll(){ "org.jlab.service.dc.DCHBEngine", "org.jlab.service.ftof.FTOFHBEngine", "org.jlab.service.ec.ECEngine", - "org.jlab.rec.cvt.services.CVTReconstruction", + "org.jlab.rec.cvt.services.CVTRecNewKF", "org.jlab.service.ctof.CTOFEngine", //"org.jlab.service.cnd.CNDEngine", "org.jlab.service.cnd.CNDCalibrationEngine", From 62b7d1669b664b80f5ab3f3691796a4e8e74a4a2 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 25 Nov 2020 19:37:16 -0500 Subject: [PATCH 052/291] New BMT Geometry implementation. --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 710 +++++++++--------- .../cross/StraightTrackCrossListFinder.java | 12 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 18 +- .../java/org/jlab/rec/cvt/track/MakerCA.java | 7 +- .../rec/cvt/track/StraightTrackSeeder.java | 7 +- .../rec/cvt/track/TrackCandListFinder.java | 4 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 10 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 34 +- 8 files changed, 420 insertions(+), 382 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 3891ec2e2..9173f31fd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -863,93 +863,93 @@ public static void main (String arg[]) { //added methods: - public int isInDetector(int layer, double angle, double jitter) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - int num_detector = 2; - //double jitter = Math.toRadians(Constants.isInSectorJitter); - for (int i = 0; i < 3; i++) { - - //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; - //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; - angle_i = Constants.getCRCEDGE1()[num_region][i]; - angle_f = Constants.getCRCEDGE2()[num_region][i]; - if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { - num_detector = i; - } - } - - return num_detector; - } - public int isInSector(int layer, double angle, double jitter) { - //double jitter = Math.toRadians(Constants.isInSectorJitter); - int value = -1; - int num_det = this.isInDetector(layer, angle, jitter); - /* if(num_det == 0) - value = 2; - if(num_det ==2) - value = 3; - if(num_det == 1) - value = 1; */ - value = num_det + 1; - - return value; - } +// public int isInDetector(int layer, double angle, double jitter) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// int num_detector = 2; +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// for (int i = 0; i < 3; i++) { +// +// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; +// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; +// angle_i = Constants.getCRCEDGE1()[num_region][i]; +// angle_f = Constants.getCRCEDGE2()[num_region][i]; +// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { +// num_detector = i; +// } +// } +// +// return num_detector; +// } +// public int isInSector(int layer, double angle, double jitter) { +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// int value = -1; +// int num_det = this.isInDetector(layer, angle, jitter); +// /* if(num_det == 0) +// value = 2; +// if(num_det ==2) +// value = 3; +// if(num_det == 1) +// value = 1; */ +// value = num_det + 1; +// +// return value; +// } - /** - * - * @param layer the hit layer - * @param strip the hit strip - * @return the z position in mm for the C-detectors - */ - public double CRCStrip_GetZ(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center - int group = 0; - int limit = Constants.getCRCGROUP()[num_region][group]; - double zc = Constants.getCRCZMIN()[num_region]; - - if (num_strip > 0) { - for (int j = 1; j < num_strip + 1; j++) { - zc += Constants.getCRCWIDTH()[num_region][group]; - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } - } - } - zc += Constants.getCRCWIDTH()[num_region][group]/2.; - return zc; //in mm - } - - public double CRCStrip_GetPitch(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center - int group = 0; - int limit = Constants.getCRCGROUP()[num_region][group]; - - if (num_strip > 0) { - for (int j = 1; j < num_strip + 1; j++) { - - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } - } - } - - return Constants.getCRCWIDTH()[num_region][group]; // - } +// /** +// * +// * @param layer the hit layer +// * @param strip the hit strip +// * @return the z position in mm for the C-detectors +// */ +// public double CRCStrip_GetZ(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// double zc = Constants.getCRCZMIN()[num_region]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// zc += Constants.getCRCWIDTH()[num_region][group]; +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// zc += Constants.getCRCWIDTH()[num_region][group]/2.; +// return zc; //in mm +// } + +// public double CRCStrip_GetPitch(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// +// return Constants.getCRCWIDTH()[num_region][group]; // +// } /** * * @param sector the sector in CLAS12 1...3 @@ -969,56 +969,56 @@ public double CRZStrip_GetPhi(int sector, int layer, int strip) { double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; return angle; //in rad } - /** - * - * @param layer the layer 1...6 - * @param angle the position angle of the hit in the Z detector - * @return the Z strip as a function of azimuthal angle - */ - public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle - double jitter = Math.toRadians(Constants.isInSectorJitter); - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int num_detector = isInDetector(layer, angle, jitter); - if (num_detector == -1) { - return -1; - } - - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - if (num_detector == 1) { - double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; - if (angle >= 0 && angle <= angle_f) { - angle += 2 * Math.PI; - } - } - //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); - //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); - double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; - strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); - int strip_num = (int) Math.floor(strip_calc); - - int value = strip_num + 1; - //int value = strip_num; - - if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { - value = -1; - } - - return value; - } +// /** +// * +// * @param layer the layer 1...6 +// * @param angle the position angle of the hit in the Z detector +// * @return the Z strip as a function of azimuthal angle +// */ +// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle +// double jitter = Math.toRadians(Constants.isInSectorJitter); +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int num_detector = isInDetector(layer, angle, jitter); +// if (num_detector == -1) { +// return -1; +// } +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// if (num_detector == 1) { +// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; +// if (angle >= 0 && angle <= angle_f) { +// angle += 2 * Math.PI; +// } +// } +// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); +// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); +// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; +// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); +// int strip_num = (int) Math.floor(strip_calc); +// +// int value = strip_num + 1; +// //int value = strip_num; +// +// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { +// value = -1; +// } +// +// return value; +// } public void setLorentzAngle(int layer, int sector) { org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); } - // Correct strip position before clustering - public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { - - double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); - double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); - - return this.getZStrip(layer, theLorentzCorrectedAngle); - } +// // Correct strip position before clustering +// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { +// +// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); +// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); +// +// return this.getZStrip(layer, theLorentzCorrectedAngle); +// } public double LorentzAngleCorr(double phi, int layer) { int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 @@ -1027,230 +1027,230 @@ public double LorentzAngleCorr(double phi, int layer) { return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); } - /** - * - * @param sector - * @param layer - * @param x - * @return a boolean indicating is the track hit is in the fiducial detector - */ - public boolean isInFiducial(int sector, int layer, int axis, double[] x) { - - boolean isInFid = false; - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; - - double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit - double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit - - double R_i = 0; // inner radius init - double R_f = 0; // outer radius init for a C or Z detector - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { - R_i = Constants.getCRZRADIUS()[num_region]; // Z layer - } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { - R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors - } - R_f = R_i + Constants.hDrift; - - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - double A_i = CRC_GetBeginStrip(sector, layer); - double A_f = CRC_GetEndStrip(sector, layer); - angle_i = A_i; - angle_f = A_f; - if (A_i > A_f) { // for B-detector - angle_f = A_i; - angle_i = A_f; - } - // the hit parameters - double angle = Math.atan2(x[1], x[0]); - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); - double z = x[2]; - - if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { - isInFid = true; - } - - return isInFid; - } - /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the beginning of the strips - */ - public double CRC_GetBeginStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = sector -1; // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the beginning of the strips - double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; //in rad - } - - /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the end of the strips - */ - public double CRC_GetEndStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = sector -1; // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the end of the strips - double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; //in rad - } - /** - * - * @param angle - * @param sector - * @param layer - * @param x - * @return a boolean indicating if the given angle is the sector - */ - public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { - if( layer < 1 || layer > 6 ) { - System.err.println(" BMT layer has to be 1 <= layer <= 6"); - return false; - } - if( sector < 1 || sector > 3 ) { - System.err.println(" BMT sector has to be 1 <= layer <= 3"); - return false; - } - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; - angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; - - - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - - if( sector == 3 ) { - if( angle < Math.PI ) { - if( angle < angle_f + jitter ) return true; - else return false; - } - else { - if( angle > angle_i - jitter ) return true; - else return false; - } - } - else { - if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) - return true; - else - return false; - - } - } - - /** - * - * @param layer - * @param trk_z the track z position of intersection with the C-detector - * @return the C-strip - */ - public int getCStrip(int layer, double trk_z) { - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int strip_group = 0; - int ClosestStrip = -1; - // get group - int len = Constants.getCRCGROUP()[num_region].length; - double[] Z_lowBound = new double[len]; - double[] Z_uppBound = new double[len]; - int[] NStrips = new int[len]; - - double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; - double z = trk_z - zi; - - for (int i = 0; i < len; i++) { - if(i==0) { - Z_lowBound[i] = 0; - NStrips[i] = Constants.getCRCGROUP()[num_region][i]; - } - else { - Z_lowBound[i] = Z_uppBound[i - 1]; - NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; - } - Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; - - if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { - strip_group = i; - ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); - if(i>0) ClosestStrip += NStrips[i - 1]; - //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; - - len = i; - } - } - return ClosestStrip; - } +// /** +// * +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating is the track hit is in the fiducial detector +// */ +// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { +// +// boolean isInFid = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; +// +// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit +// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit +// +// double R_i = 0; // inner radius init +// double R_f = 0; // outer radius init for a C or Z detector +// if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { +// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer +// } +// if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { +// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors +// } +// R_f = R_i + Constants.hDrift; +// +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// double A_i = CRC_GetBeginStrip(sector, layer); +// double A_f = CRC_GetEndStrip(sector, layer); +// angle_i = A_i; +// angle_f = A_f; +// if (A_i > A_f) { // for B-detector +// angle_f = A_i; +// angle_i = A_f; +// } +// // the hit parameters +// double angle = Math.atan2(x[1], x[0]); +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); +// double z = x[2]; +// +// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { +// isInFid = true; +// } +// +// return isInFid; +// } +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the beginning of the strips +// */ +// public double CRC_GetBeginStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the beginning of the strips +// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the end of the strips +// */ +// public double CRC_GetEndStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the end of the strips +// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// /** +// * +// * @param angle +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating if the given angle is the sector +// */ +// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { +// if( layer < 1 || layer > 6 ) { +// System.err.println(" BMT layer has to be 1 <= layer <= 6"); +// return false; +// } +// if( sector < 1 || sector > 3 ) { +// System.err.println(" BMT sector has to be 1 <= layer <= 3"); +// return false; +// } +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; +// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; +// +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// +// if( sector == 3 ) { +// if( angle < Math.PI ) { +// if( angle < angle_f + jitter ) return true; +// else return false; +// } +// else { +// if( angle > angle_i - jitter ) return true; +// else return false; +// } +// } +// else { +// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) +// return true; +// else +// return false; +// +// } +// } - public boolean isInFiducial(double x, double y, double z, int layer) { - - boolean isOK = false; - - int num_region = (int) (layer + 1) / 2 - 1; - - int axis = Geometry.getZorC(layer); - - double R = 0; - if (axis == 0) { - R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; - } - if (axis == 1) { - R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; - } - - double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; - double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; - double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; - - double z_min = CRZZMIN + CRZOFFSET; - double z_max = z_min + CRZLENGTH; - - double epsilon = 1e-1; - - if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { - isOK = true; - } - return isOK; - } - - /** - * - * @param layer the layer 1...6 - * @return the Z position of the strip center - */ - private double CRZ_GetZStrip(int layer) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //For CRZ, this function returns the Z position of the strip center - double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; - return zc; //in mm - } +// /** +// * +// * @param layer +// * @param trk_z the track z position of intersection with the C-detector +// * @return the C-strip +// */ +// public int getCStrip(int layer, double trk_z) { +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int strip_group = 0; +// int ClosestStrip = -1; +// // get group +// int len = Constants.getCRCGROUP()[num_region].length; +// double[] Z_lowBound = new double[len]; +// double[] Z_uppBound = new double[len]; +// int[] NStrips = new int[len]; +// +// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; +// double z = trk_z - zi; +// +// for (int i = 0; i < len; i++) { +// if(i==0) { +// Z_lowBound[i] = 0; +// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; +// } +// else { +// Z_lowBound[i] = Z_uppBound[i - 1]; +// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; +// } +// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; +// +// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { +// strip_group = i; +// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); +// if(i>0) ClosestStrip += NStrips[i - 1]; +// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; +// +// len = i; +// } +// } +// return ClosestStrip; +// } +// +// public boolean isInFiducial(double x, double y, double z, int layer) { +// +// boolean isOK = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; +// +// int axis = Geometry.getZorC(layer); +// +// double R = 0; +// if (axis == 0) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; +// } +// if (axis == 1) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; +// } +// +// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; +// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; +// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; +// +// double z_min = CRZZMIN + CRZOFFSET; +// double z_max = z_min + CRZLENGTH; +// +// double epsilon = 1e-1; +// +// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { +// isOK = true; +// } +// return isOK; +// } +// +// /** +// * +// * @param layer the layer 1...6 +// * @return the Z position of the strip center +// */ +// private double CRZ_GetZStrip(int layer) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //For CRZ, this function returns the Z position of the strip center +// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; +// return zc; //in mm +// } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index 036188324..b5c79db64 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -451,24 +451,28 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, this.calcBMT2DPoint(yxslope, yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); - Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D1); if (t[3] != t[1] && t[2] != t[0]) { - Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D2); } this.calcBMT2DPoint(yxslope, yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); - Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D3); if (t[3] != t[1] && t[2] != t[0]) { - Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); + Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D4); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index ef5aec7b5..f2754b403 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -141,10 +141,14 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { // C-dtectors // set z - double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); + //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); + int region = (int) ((layer + 1) / 2 ); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 + double z = geo.getCstripZ(region, this.get_Strip()); this.set_Z(z); // max z err - this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); + //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); + this.set_ZErr(geo.getCPitch(region, this.get_Strip()) / Math.sqrt(12.)); + } if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { // Z-detectors @@ -155,13 +159,19 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector this.set_Phi(theLorentzCorrectedAngle); this.set_Phi0(theMeasuredPhi); // uncorrected //System.out.println(" sec "+sector+" strip "+this.get_Strip()+" LC strip "+geo.getZStrip(layer, theLorentzCorrectedAngle)); - int theLorentzCorrectedStrip = geo.getZStrip(layer, theLorentzCorrectedAngle); + //int theLorentzCorrectedStrip = geo.getZStrip(layer, theLorentzCorrectedAngle); + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; + double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* + Math.cos(theLorentzCorrectedAngle); + double yl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* + Math.sin(theLorentzCorrectedAngle); + int theLorentzCorrectedStrip = geo.getStrip( layer, sector, + new Point3D(xl,yl,0)); // get the strip number after correcting for Lorentz angle this.set_LCStrip(theLorentzCorrectedStrip); double sigma = org.jlab.rec.cvt.bmt.Constants.SigmaDrift / Math.cos(org.jlab.rec.cvt.bmt.Constants.getThetaL()); // max sigma for drift distance (hDrift) = total gap from top to mesh - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; //max phi err double phiErrL = sigma / org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 7026e755e..558d48c26 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -108,7 +108,7 @@ public void createCells( List crs, BMTGeometry bgeom ){ if( this._debug ) { System.out.println( "\n cross a " + a.get_Id() + " " + a.get_Detector() +a.get_DetectorType() + " sect:" + a.get_Sector() + " reg:" + aReg + " phi:" + a.get_Point().toVector3D().phi() + " in BMT sector:" + - bgeom.isInSector(1, a.get_Point().toVector3D().phi(), 0 )); + bgeom.getSector(1, a.get_Point().toVector3D().phi())); } @@ -125,7 +125,7 @@ public void createCells( List crs, BMTGeometry bgeom ){ if( this._debug ) { System.out.println( " cross b " + b.get_Id() + " " + b.get_Detector() +b.get_DetectorType() + " sect:" + b.get_Sector() + " reg:" + bReg + " phi:" + b.get_Point().toVector3D().phi() + " in BMT sector:" + - bgeom.isInSector(1, b.get_Point().toVector3D().phi(), 0 )); + bgeom.getSector(1, b.get_Point().toVector3D().phi() )); } if( bReg <= aReg ) continue; // crosses should be ordered. skip in case they are not @@ -151,7 +151,8 @@ public void createCells( List crs, BMTGeometry bgeom ){ } else{ double aphi = a.get_Point().toVector3D().phi() ; - if( ! bgeom.checkIsInSector( aphi, b.get_Sector(), 1, Math.toRadians(10) ) ) { + //if( ! bgeom.checkIsInSector( aphi, b.get_Sector(), 1, Math.toRadians(10) ) ) { + if(bgeom.getSector(b.get_Region()*2, aphi)>0) { if( this._debug) System.out.println("cross b and a are not in the same sector"); continue; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 158c962f2..4d28130c3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -365,7 +365,9 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c if (angle < 0) { angle += 2 * Math.PI; } - if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) == bmt_crosses.get(i).get_Sector() - 1) { + //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) + // == bmt_crosses.get(i).get_Sector() - 1) + if (bmt_geo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), ref)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -595,7 +597,8 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt. double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; Point3D refPoint = trkCand.get_Crosses().get(0).get_Point(); - if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { + //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { + if (bmt_geo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x())) != bmt_Ccross.get_Sector()) { return false; } double dzdr_bmt = z_bmt / r_bmt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 715efa7ef..9f3440de1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -854,8 +854,8 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse continue; } double m_z = MMCrosses.get(i).get_Point().z(); - int sector = geo.isInSector(MMCrosses.get(i).get_Region() * 2, phi, Math.toRadians(Constants.isInSectorJitter)); - + //int sector = geo.isInSector(MMCrosses.get(i).get_Region() * 2, phi, Math.toRadians(Constants.isInSectorJitter)); + int sector = geo.getSector(MMCrosses.get(i).get_Region() * 2, phi); if (sector != MMCrosses.get(i).get_Sector()) { continue; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 72d7b5baf..67106ab8a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -379,7 +379,10 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c if (angle < 0) { angle += 2 * Math.PI; } - if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) == bmt_crosses.get(i).get_Sector() - 1) { + //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) + // == bmt_crosses.get(i).get_Sector() - 1) + //inDetector(int layer, int sector, Point3D traj) + if (bmt_geo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), pAtBMTSurf)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -620,7 +623,10 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt. double z_bmt = bmt_Ccross.get_Point().z(); double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; Point3D phiHelixAtSurf = trkCand.get_Helix().getPointAtRadius(r_bmt); - if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { + //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) + // != bmt_Ccross.get_Sector()) + int sector = bmt_geo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); + if(sector!= bmt_Ccross.get_Sector()){ return false; } double dzdr_bmt = z_bmt / r_bmt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 9ec191760..a81522189 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -190,7 +190,8 @@ public Trajectory findTrajectory(int id, Track trk, StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); double phiPos = Math.atan2(stVec.y(),stVec.x()); - int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); + //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); + int sector = bmt_geo.getSector(BMTRegIdx+1,phiPos); stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); stVec.set_SurfaceSector(sector); stVec.set_SurfaceLayer(l+1); @@ -198,7 +199,9 @@ public Trajectory findTrajectory(int id, Track trk, stVec.set_Path(path*10); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); this.fill_HelicalTrkAngleWRTBMTTangentPlane(dir, stVec); - stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); + //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); + stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(BMTRegIdx+1, + new Point3D(stVec.x(),stVec.y(),stVec.z()))); stateVecs.add(stVec); //} //else { @@ -404,7 +407,8 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList double XtrackIntersSurf = BMTIntersections[l][h][0]; double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; - int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(org.jlab.rec.cvt.bmt.Constants.isInSectorJitter)); + //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(org.jlab.rec.cvt.bmt.Constants.isInSectorJitter)); + int SectorTrackIntersSurf = bmt_geo.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; double trkToMPlnAngl = BMTIntersections[l][h][5]; @@ -775,26 +779,36 @@ private double[][] getIntersectionTrackWithBMTModules(int l, double z_plus = _yzslope2 * y_plus + _yzinterc2; double z_minus = _yzslope2 * y_minus + _yzinterc2; - if (geo.isInFiducial(x_plus, y_plus, z_plus, l + 1)) { - inters_top[0] = x_plus; + //if (geo.isInFiducial(x_plus, y_plus, z_plus, l + 1)) { + if(geo.inDetector(new Point3D(x_plus, y_plus, z_plus))) { + inters_top[0] = x_plus; inters_top[1] = y_plus; inters_top[2] = z_plus; if (l % 2 == 1) { - inters_top[3] = geo.getCStrip(l + 1, z_plus); + //inters_top[3] = geo.getCStrip(l + 1, z_plus); + inters_top[3] = geo.getCstrip(l + 1, new Point3D(x_plus,y_plus,z_plus)); } if (l % 2 == 0) { - inters_top[3] = geo.getZStrip(l + 1, Math.atan2(y_plus, x_plus)); + //inters_top[3] = geo.getZStrip(l + 1, Math.atan2(y_plus, x_plus)); + int sector = geo.getSector(l, Math.atan2(y_plus, x_plus)); + inters_top[3]= geo.getStrip( l + 1, sector, + new Point3D(x_plus, y_plus,0)); } } - if (geo.isInFiducial(x_minus, y_minus, z_minus, l + 1)) { + //if (geo.isInFiducial(x_minus, y_minus, z_minus, l + 1)) { + if(geo.inDetector(new Point3D(x_minus, y_minus, z_minus))) { inters_bottom[0] = x_minus; inters_bottom[1] = y_minus; inters_bottom[2] = z_minus; if (l % 2 == 1) { - inters_bottom[3] = geo.getCStrip(l + 1, z_minus); + //inters_bottom[3] = geo.getCStrip(l + 1, z_minus); + inters_bottom[3] = geo.getCstrip(l + 1, new Point3D(x_minus,y_minus,z_minus)); } if (l % 2 == 0) { - inters_bottom[3] = geo.getZStrip(l + 1, Math.atan2(y_minus, x_minus)); + //inters_bottom[3] = geo.getZStrip(l + 1, Math.atan2(y_minus, x_minus)); + int sector = geo.getSector(l, Math.atan2(y_minus, x_minus)); + inters_bottom[3]= geo.getStrip( l + 1, sector, + new Point3D(x_minus, y_minus,0)); } } From 2310360ba82c261477c16fa101857fa2dab2716f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 30 Nov 2020 12:41:46 -0500 Subject: [PATCH 053/291] New BMT Geometry implementation fix --- .../org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index a81522189..382f9d0d5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -191,7 +191,7 @@ public Trajectory findTrajectory(int id, Track trk, stVec.set_planeIdx(l); double phiPos = Math.atan2(stVec.y(),stVec.x()); //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); - int sector = bmt_geo.getSector(BMTRegIdx+1,phiPos); + int sector = bmt_geo.getSector(2*(BMTRegIdx+1),phiPos); stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); stVec.set_SurfaceSector(sector); stVec.set_SurfaceLayer(l+1); @@ -786,11 +786,11 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters_top[2] = z_plus; if (l % 2 == 1) { //inters_top[3] = geo.getCStrip(l + 1, z_plus); - inters_top[3] = geo.getCstrip(l + 1, new Point3D(x_plus,y_plus,z_plus)); + inters_top[3] = geo.getCstrip((int)(l/2 + 1), new Point3D(x_plus,y_plus,z_plus)); } if (l % 2 == 0) { //inters_top[3] = geo.getZStrip(l + 1, Math.atan2(y_plus, x_plus)); - int sector = geo.getSector(l, Math.atan2(y_plus, x_plus)); + int sector = geo.getSector(l + 1, Math.atan2(y_plus, x_plus)); inters_top[3]= geo.getStrip( l + 1, sector, new Point3D(x_plus, y_plus,0)); } @@ -802,11 +802,11 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters_bottom[2] = z_minus; if (l % 2 == 1) { //inters_bottom[3] = geo.getCStrip(l + 1, z_minus); - inters_bottom[3] = geo.getCstrip(l + 1, new Point3D(x_minus,y_minus,z_minus)); + inters_bottom[3] = geo.getCstrip((int)(l/2 + 1), new Point3D(x_minus,y_minus,z_minus)); } if (l % 2 == 0) { //inters_bottom[3] = geo.getZStrip(l + 1, Math.atan2(y_minus, x_minus)); - int sector = geo.getSector(l, Math.atan2(y_minus, x_minus)); + int sector = geo.getSector(l + 1, Math.atan2(y_minus, x_minus)); inters_bottom[3]= geo.getStrip( l + 1, sector, new Point3D(x_minus, y_minus,0)); } From c5aa979aeb2fe5371b5ee5a45cebbb5ddfa4590f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 3 Dec 2020 14:50:37 -0500 Subject: [PATCH 054/291] Turn back on overlap remover --- .../java/org/jlab/rec/cvt/services/TracksFromTargetRec.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 862412bcc..c723f5cd1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -133,7 +133,7 @@ public boolean processEvent(DataEvent event, tracks.get(i).set_Id(i+1); } //System.out.println( " *** *** trkcands " + trkcands.size() + " * trks " + trks.size()); - //trkFinder.removeOverlappingTracks(tracks); //turn off until debugged + trkFinder.removeOverlappingTracks(tracks); //turn off until debugged for (int c = 0; c < tracks.size(); c++) { tracks.get(c).set_Id(c + 1); From 32f113643a87dfe2bf9c7a4bd44a466aeb75455e Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 7 Dec 2020 14:06:53 +0100 Subject: [PATCH 055/291] completed import of missing methods to BMTGeometry and propagated usage in the code --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 84 +++++++++++++------ .../java/org/jlab/rec/cvt/bmt/Constants.java | 4 +- .../java/org/jlab/rec/cvt/bmt/Lorentz.java | 2 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 4 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 11 +-- .../rec/cvt/trajectory/TrajectoryFinder.java | 17 ++-- 6 files changed, 79 insertions(+), 43 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 9173f31fd..27816688c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -9,6 +9,9 @@ import org.jlab.groot.data.H2F; import org.jlab.groot.graphics.EmbeddedCanvas; import org.jlab.groot.group.DataGroup; +import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; +import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; +import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; /** * @@ -67,7 +70,7 @@ public int getRegion(int layer) { * @param layer (1-6) * @return type ("C" or "Z"); */ - public BMTType getDetectorType(int layer) { + public static BMTType getDetectorType(int layer) { if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; else if(layer == lZ[0] || layer == lZ[1] || layer == lZ[2]) return BMTType.Z; else { @@ -395,7 +398,7 @@ private int getCGroup(int region, double z) { * @param strip * @return zc */ - public double getCstripZ(int region, int strip) { + private double getCstripZ(int region, int strip) { double z = udf; @@ -662,13 +665,44 @@ public int getZstrip(int region, Point3D traj) { return strip; } - public static int getZorC(int layer) { - int axis = 0; - if (layer == 2 || layer == 3 || layer == 5) { - axis = 1; + + /** + * Calculate Theta Lorentz based on solenoid scale and drift settings + * @param layer + * @param sector + * @return thetaL in radians + */ + public double getThetaLorentz(int layer, int sector) { + + double thetaL = 0; + + double solenoidScale = org.jlab.rec.cvt.Constants.getSolenoidscale(); + + if(Math.abs(solenoidScale)<0.001) { + thetaL = 0; + } + else { + if(Math.abs(solenoidScale)<0.8) { + thetaL = Math.toRadians(getLorentzAngle(Constants.E_DRIFT_MF[layer-1][sector-1],Math.abs(solenoidScale*50))); + } else { + thetaL = Math.toRadians(getLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(solenoidScale*50))); + } } - return axis; + if (solenoidScale<0) thetaL=-thetaL; + return thetaL; + } + + /** + * Calculate Lorentz angle correction + * @param layer + * @param sector + * @return + */ + public double LorentzAngleCorr(int layer, int sector) { + return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); } + + /** * Executable method: implements checks * @param arg @@ -1008,25 +1042,25 @@ public double CRZStrip_GetPhi(int sector, int layer, int strip) { // return value; // } - public void setLorentzAngle(int layer, int sector) { - org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); - } -// // Correct strip position before clustering -// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { +// public void setLorentzAngle(int layer, int sector) { +// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); +// } +//// // Correct strip position before clustering +//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { +//// +//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); +//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); +//// +//// return this.getZStrip(layer, theLorentzCorrectedAngle); +//// } +// public double LorentzAngleCorr(double phi, int layer) { // -// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); -// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); -// -// return this.getZStrip(layer, theLorentzCorrectedAngle); -// } - public double LorentzAngleCorr(double phi, int layer) { - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; - //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - } - +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; +// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// } +// // /** // * // * @param sector diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java index 226f253a7..b6af6a2c9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java @@ -133,9 +133,9 @@ public static synchronized void setThetaL(int layer, int sector) { } else { if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { - ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.GetLorentzAngle(E_DRIFT_MF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); + ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle(E_DRIFT_MF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); } else { - ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.GetLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); + ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); } } if (org.jlab.rec.cvt.Constants.getSolenoidscale()<0) ThetaL=-ThetaL; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java index c1f9db84f..13dc71e96 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java @@ -11,7 +11,7 @@ public Lorentz() { } - public static double GetLorentzAngle(double xe, double xb) { + public static double getLorentzAngle(double xe, double xb) { if (xe==0||xb==0) return 0; double de = (org.jlab.rec.cvt.bmt.Constants.emax-org.jlab.rec.cvt.bmt.Constants.emin)/(org.jlab.rec.cvt.bmt.Constants.Ne-1); double db = (org.jlab.rec.cvt.bmt.Constants.bmax-org.jlab.rec.cvt.bmt.Constants.bmin)/(org.jlab.rec.cvt.bmt.Constants.Nb-1); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 9a8467d90..9eb72221d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -237,11 +237,11 @@ public ArrayList> sortClusterByDetectorAndIO( // Sorting by layer first: for (Cluster theclus : clusters) { if (theclus.get_Detector() == 1) { - if (BMTGeometry.getZorC(theclus.get_Layer()) == 1) { + if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.Z) { bmt_Zlayrclus.add(theclus); } - if (BMTGeometry.getZorC(theclus.get_Layer()) == 0) { + if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.C) { bmt_Clayrclus.add(theclus); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index f2754b403..5701807b8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -2,6 +2,8 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.Constants; import org.jlab.rec.cvt.bmt.Geometry; @@ -139,11 +141,11 @@ public void set_Edep(double _Edep) { */ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector, int layer) { - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { // C-dtectors + if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); int region = (int) ((layer + 1) / 2 ); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 - double z = geo.getCstripZ(region, this.get_Strip()); + double z = geo.getCstrip(region, sector, this.get_Strip()).center().z(); this.set_Z(z); // max z err //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); @@ -151,10 +153,9 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector } - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { // Z-detectors - geo.setLorentzAngle(layer, sector); + if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors double theMeasuredPhi = geo.CRZStrip_GetPhi(sector, layer, this.get_Strip()); - double theLorentzCorrectedAngle = geo.LorentzAngleCorr(theMeasuredPhi, layer); + double theLorentzCorrectedAngle = theMeasuredPhi + geo.LorentzAngleCorr(layer,sector); // set the phi this.set_Phi(theLorentzCorrectedAngle); this.set_Phi0(theMeasuredPhi); // uncorrected diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 382f9d0d5..12c68a2d6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -14,6 +14,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -171,10 +172,10 @@ public Trajectory findTrajectory(int id, Track trk, } double R = 0; - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1-6) == 1) { + if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.Z) { R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1-6) == 0) { + if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.C) { R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } @@ -502,7 +503,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec value = false; // reauire same region } if (c.get_DetectorType()==BMTType.C) { //C-detector measuring Z - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { //Z-detector measuring phi + if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi value = false; } @@ -511,7 +512,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec } } if (c.get_DetectorType()==BMTType.Z) { //Z-detector measuring phi - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { //C-detector + if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector value = false; } double deltaXt = Math.sqrt((stVec.x() - c.get_Point().x()) * (stVec.x() - c.get_Point().x()) + (stVec.y() - c.get_Point().y()) * (stVec.y() - c.get_Point().y())); @@ -552,7 +553,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } if (detector.equalsIgnoreCase("BMT")) { - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 0) { //C-detector measuring z + if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z for (FittedHit h1 : cluster) { // calculate the hit residuals double docaToTrk = stVec.z() - h1.get_Strip().get_Z(); @@ -566,7 +567,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } } - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(layer) == 1) { //Z-detector measuring phi + if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi // calculate the hit residuals for (FittedHit h1 : cluster) { double StripX = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] * Math.cos(h1.get_Strip().get_Phi()); @@ -761,10 +762,10 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters_bottom[3] = Double.NaN; double R = 0; - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1) == 0) { + if (BMTGeometry.getDetectorType(l + 1) == BMTType.C) { R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } - if (org.jlab.rec.cvt.bmt.BMTGeometry.getZorC(l + 1) == 1) { + if (BMTGeometry.getDetectorType(l + 1) == BMTType.Z) { R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; } // solve for intersection of line with cylinder of radius R From 4face0ad9a327992fa1b0bd1268fc2f97d8420e8 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 7 Dec 2020 16:12:54 +0100 Subject: [PATCH 056/291] Adding global offsets for SVT and BMT --- .../detector/geant4/v2/SVT/SVTConstants.java | 599 +++++++++--------- .../jlab/rec/cvt/services/CVTRecNewKF.java | 2 +- 2 files changed, 304 insertions(+), 297 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index ba38ff105..d8c548f55 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -118,6 +118,7 @@ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) cp.loadTable( ccdbPath +"material/box"); cp.loadTable( ccdbPath +"material/tube"); cp.loadTable( ccdbPath +"layeralignment"); + cp.loadTable( ccdbPath +"position"); //shift by target cp.loadTable("/geometry/target"); @@ -163,306 +164,312 @@ public static void setCcdbPath( String aPath ) */ public static synchronized void load( ConstantProvider cp ) { - if( !bLoadedConstants ) - { - // read constants from svt table - NREGIONS = cp.getInteger( ccdbPath+"svt/nRegions", 0 ); - NMODULES = cp.getInteger( ccdbPath+"svt/nModules", 0 ); - NSENSORS = cp.getInteger( ccdbPath+"svt/nSensors", 0 ); - NSTRIPS = cp.getInteger( ccdbPath+"svt/nStrips", 0 ); - NFIDUCIALS = cp.getInteger( ccdbPath+"svt/nFiducials", 0 ); - NPADS = cp.getInteger( ccdbPath+"svt/nPads", 0 ); - - READOUTPITCH = cp.getDouble( ccdbPath+"svt/readoutPitch", 0 ); - STEREOANGLE = Math.toRadians(cp.getDouble( ccdbPath+"svt/stereoAngle", 0 )); - PHI0 = Math.toRadians(cp.getDouble( ccdbPath+"svt/phiStart", 0 )); - SECTOR0 = Math.toRadians(cp.getDouble( ccdbPath+"svt/zRotationStart", 0 )); - LAYERPOSFAC = cp.getDouble( ccdbPath+"svt/modulePosFac", 0 ); - - SILICONTHK = cp.getDouble( ccdbPath+"svt/siliconThk", 0 ); - PHYSSENLEN = cp.getDouble( ccdbPath+"svt/physSenLen", 0 ); - PHYSSENWID = cp.getDouble( ccdbPath+"svt/physSenWid", 0 ); - ACTIVESENLEN = cp.getDouble( ccdbPath+"svt/activeSenLen", 0 ); - ACTIVESENWID = cp.getDouble( ccdbPath+"svt/activeSenWid", 0 ); - DEADZNLEN = cp.getDouble( ccdbPath+"svt/deadZnLen", 0 ); - DEADZNWID = cp.getDouble( ccdbPath+"svt/deadZnWid", 0 ); - MICROGAPLEN = cp.getDouble( ccdbPath+"svt/microGapLen", 0 ); - - FIDCUX = cp.getDouble( ccdbPath+"fiducial/CuX", 0 ); - FIDPKX = cp.getDouble( ccdbPath+"fiducial/PkX", 0 ); - FIDORIGINZ = cp.getDouble( ccdbPath+"fiducial/OriginZ", 0 ); - FIDCUZ = cp.getDouble( ccdbPath+"fiducial/CuZ", 0 ); - FIDPKZ0 = cp.getDouble( ccdbPath+"fiducial/PkZ0", 0 ); - FIDPKZ1 = cp.getDouble( ccdbPath+"fiducial/PkZ1", 0 ); - - // read constants from materials table - NMATERIALS = 14; // number of unique materials, not length of materialNames - - // cannot read String variables from CCDB, so put them here in the correct order - MATERIALTYPES.put("heatSink", "box"); - MATERIALTYPES.put("heatSinkCu", "box"); - MATERIALTYPES.put("heatSinkRidge", "box"); - MATERIALTYPES.put("rohacell", "box"); - MATERIALTYPES.put("rohacellCu", "box"); - MATERIALTYPES.put("plastic", "box"); - MATERIALTYPES.put("plasticPk", "box"); - MATERIALTYPES.put("carbonFiber", "box"); - MATERIALTYPES.put("carbonFiberCu", "box"); - MATERIALTYPES.put("carbonFiberPk", "box"); - MATERIALTYPES.put("busCable", "box"); - MATERIALTYPES.put("busCableCu", "box"); - MATERIALTYPES.put("busCablePk", "box"); - MATERIALTYPES.put("pitchAdaptor", "box"); - MATERIALTYPES.put("pcBoardAndChips", "box"); - MATERIALTYPES.put("pcBoard", "box"); - MATERIALTYPES.put("chip", "box"); - MATERIALTYPES.put("epoxyAndRailAndPads","box"); - MATERIALTYPES.put("epoxyMajorCu", "box"); - MATERIALTYPES.put("epoxyMinorCu", "box"); - MATERIALTYPES.put("epoxyMajorPk", "box"); - MATERIALTYPES.put("epoxyMinorPk", "box"); - MATERIALTYPES.put("rail", "box"); - MATERIALTYPES.put("wirebond", "box"); - MATERIALTYPES.put("kaptonWrapTapeSide", "box"); - MATERIALTYPES.put("kaptonWrapTapeCap", "box"); - MATERIALTYPES.put("kaptonWrapGlueSide", "box"); - MATERIALTYPES.put("kaptonWrapGlueCap", "box"); - - MATERIALTYPES.put("pad", "tube"); - - int boxNum = 0; // number of box types - int mat = 0; - for( Entry entry : MATERIALTYPES.entrySet() ) - { - String key = entry.getKey(); - String value = entry.getValue(); - double[] dimensions = null; - - if( value == "box" ) - { - boxNum++; - dimensions = new double[]{ - cp.getDouble( ccdbPath+"material/box/wid", mat ), - cp.getDouble( ccdbPath+"material/box/thk", mat ), - cp.getDouble( ccdbPath+"material/box/len", mat ) - }; - } - else if( value == "tube" ) // offset by boxNum to reset row for CCDB table - { - dimensions = new double[]{ - cp.getDouble( ccdbPath+"material/tube/rmin", mat - boxNum ), - cp.getDouble( ccdbPath+"material/tube/rmax", mat - boxNum ), - cp.getDouble( ccdbPath+"material/tube/zlen", mat - boxNum ), - cp.getDouble( ccdbPath+"material/tube/phi0", mat - boxNum ), - cp.getDouble( ccdbPath+"material/tube/dphi", mat - boxNum ) - }; - } - MATERIALDIMENSIONS.put( key, dimensions ); - mat++; - } - - - // calculate derived constants - NLAYERS = NMODULES*NREGIONS; - MODULELEN = NSENSORS*(ACTIVESENLEN + 2*DEADZNLEN) + (NSENSORS - 1)*MICROGAPLEN; - STRIPLENMAX = MODULELEN - 2*DEADZNLEN; - MODULEWID = ACTIVESENWID + 2*DEADZNWID; - STRIPOFFSETWID = cp.getDouble(ccdbPath+"svt/stripStart", 0 ); - LAYERGAPTHK = cp.getDouble(ccdbPath+"svt/layerGapThk", 0 ); - PASSIVETHK = MATERIALDIMENSIONS.get("carbonFiber")[1] + MATERIALDIMENSIONS.get("busCable")[1] + MATERIALDIMENSIONS.get("epoxyAndRailAndPads")[1]; - SECTORLEN = MATERIALDIMENSIONS.get("heatSink")[2] + MATERIALDIMENSIONS.get("rohacell")[2]; - double layerGapThk = MATERIALDIMENSIONS.get("rohacell")[1] + 2*PASSIVETHK; // construct from material thicknesses instead - - - if( VERBOSE ) System.out.printf("LAYERGAPTHK (CCDB) = % 8.3f\n", LAYERGAPTHK ); - if( VERBOSE ) System.out.printf("layerGapThk (MATERIALS) = % 8.3f\n", layerGapThk ); - LAYERGAPTHK = layerGapThk; if( VERBOSE ) System.out.println("set LAYERGAPTHK to layerGapThk"); - - if( VERBOSE ) - { - System.out.printf("NREGIONS %4d\n", NREGIONS ); - System.out.printf("NMODULES %4d\n", NMODULES ); - System.out.printf("NLAYERS %4d\n", NLAYERS ); - System.out.printf("NSENSORS %4d\n", NSENSORS ); - System.out.printf("NSTRIPS %4d\n", NSTRIPS ); - System.out.printf("NFIDUCIALS %4d\n", NFIDUCIALS ); - System.out.printf("NPADS %4d\n", NPADS ); - System.out.println(); - } - - // read constants from region and support table - NSECTORS = new int[NREGIONS]; - STATUS = new int[NREGIONS]; - Z0ACTIVE = new double[NREGIONS]; - REFRADIUS = new double[NREGIONS]; // used to derive LAYERRADIUS - SUPPORTRADIUS = new double[NREGIONS]; // used to build volumes - LAYERRADIUS = new double[NREGIONS][NMODULES]; // used to build strips - - // Consider Region 1 Sector 6 (not to scale) - // - // y (vertical) .------------------^------------- - // ^ | V (outer) | - // | | sensor layer | 0.32 silicon thickness - // | | | - // | .--------+--------------^---v------------- module radius 1 - // | | passiveThk | - // |------^-----------------^-------------+-----------------------|----------------- fiducial layer - // | | | | | - // | | heatSink | | | - // | | | 2.50 | rohacell | 3.236 layer gap - // | | 2.88 | | | - // | | | | | - // | | +--v-------------+-----------------------|------------------ module radius 0 - // | | | | passiveThk | - // | | | '---^----+--------------v-----^------------ radius CCDB - // |------v-------^------' | | | radius MechEng - // | | | | U (inner) | 0.32 silicon thickness - // | | | | sensor layer | - // | | | '--------------------v----------- - // | | support | reference - // | | radius | radius - // | | | - // o==============v===========================v===================================-> z (beamline) - System.out.println("SVT READ Z SHIFT VALUE "+cp.getDouble("/geometry/target/position", 0)); - // LAYERRADIUS and ZSTARTACTIVE are used primarily by the Reconstruction and getStrip() - for( int region = 0; region < NREGIONS; region++ ) - { - NSECTORS[region] = cp.getInteger(ccdbPath+"region/nSectors", region ); - - STATUS[region] = cp.getInteger(ccdbPath+"region/status", region ); - Z0ACTIVE[region] = cp.getDouble(ccdbPath+"region/zStart", region ); // Cu edge of hybrid sensor's active volume - REFRADIUS[region] = cp.getDouble(ccdbPath+"region/UlayerOuterRadius", region); // radius to outer side of U (inner) module - SUPPORTRADIUS[region] = cp.getDouble(ccdbPath+"region/CuSupportInnerRadius", region); // radius to inner side of heatSinkRidge - - for( int m = 0; m < NMODULES; m++ ) - { - switch( m ) - { - case 0: // U = lower / inner - LAYERRADIUS[region][m] = REFRADIUS[region] - LAYERPOSFAC*SILICONTHK; - break; - case 1: // V = upper / outer - LAYERRADIUS[region][m] = REFRADIUS[region] + LAYERGAPTHK + LAYERPOSFAC*SILICONTHK; - break; - } - //System.out.println("LAYERRADIUS "+ LAYERRADIUS[region][m]); - } - } - - NTOTALSECTORS = convertRegionSector2Index( NREGIONS-1, NSECTORS[NREGIONS-1]-1 )+1; - NTOTALFIDUCIALS = convertRegionSectorFiducial2Index(NREGIONS-1, NSECTORS[NREGIONS-1]-1, NFIDUCIALS-1 )+1; - - RSI = new int[NREGIONS][NTOTALSECTORS]; - for( int aRegion = 0; aRegion < NREGIONS; aRegion++ ) - { - for( int aSector = 0; aSector < NSECTORS[aRegion]; aSector++ ) - { - RSI[aRegion][aSector] = convertRegionSector2Index( aRegion, aSector ); + // read constants from svt table + NREGIONS = cp.getInteger( ccdbPath+"svt/nRegions", 0 ); + NMODULES = cp.getInteger( ccdbPath+"svt/nModules", 0 ); + NSENSORS = cp.getInteger( ccdbPath+"svt/nSensors", 0 ); + NSTRIPS = cp.getInteger( ccdbPath+"svt/nStrips", 0 ); + NFIDUCIALS = cp.getInteger( ccdbPath+"svt/nFiducials", 0 ); + NPADS = cp.getInteger( ccdbPath+"svt/nPads", 0 ); + + READOUTPITCH = cp.getDouble( ccdbPath+"svt/readoutPitch", 0 ); + STEREOANGLE = Math.toRadians(cp.getDouble( ccdbPath+"svt/stereoAngle", 0 )); + PHI0 = Math.toRadians(cp.getDouble( ccdbPath+"svt/phiStart", 0 )); + SECTOR0 = Math.toRadians(cp.getDouble( ccdbPath+"svt/zRotationStart", 0 )); + LAYERPOSFAC = cp.getDouble( ccdbPath+"svt/modulePosFac", 0 ); + + SILICONTHK = cp.getDouble( ccdbPath+"svt/siliconThk", 0 ); + PHYSSENLEN = cp.getDouble( ccdbPath+"svt/physSenLen", 0 ); + PHYSSENWID = cp.getDouble( ccdbPath+"svt/physSenWid", 0 ); + ACTIVESENLEN = cp.getDouble( ccdbPath+"svt/activeSenLen", 0 ); + ACTIVESENWID = cp.getDouble( ccdbPath+"svt/activeSenWid", 0 ); + DEADZNLEN = cp.getDouble( ccdbPath+"svt/deadZnLen", 0 ); + DEADZNWID = cp.getDouble( ccdbPath+"svt/deadZnWid", 0 ); + MICROGAPLEN = cp.getDouble( ccdbPath+"svt/microGapLen", 0 ); + + FIDCUX = cp.getDouble( ccdbPath+"fiducial/CuX", 0 ); + FIDPKX = cp.getDouble( ccdbPath+"fiducial/PkX", 0 ); + FIDORIGINZ = cp.getDouble( ccdbPath+"fiducial/OriginZ", 0 ); + FIDCUZ = cp.getDouble( ccdbPath+"fiducial/CuZ", 0 ); + FIDPKZ0 = cp.getDouble( ccdbPath+"fiducial/PkZ0", 0 ); + FIDPKZ1 = cp.getDouble( ccdbPath+"fiducial/PkZ1", 0 ); + + // read constants from materials table + NMATERIALS = 14; // number of unique materials, not length of materialNames + + // cannot read String variables from CCDB, so put them here in the correct order + MATERIALTYPES.put("heatSink", "box"); + MATERIALTYPES.put("heatSinkCu", "box"); + MATERIALTYPES.put("heatSinkRidge", "box"); + MATERIALTYPES.put("rohacell", "box"); + MATERIALTYPES.put("rohacellCu", "box"); + MATERIALTYPES.put("plastic", "box"); + MATERIALTYPES.put("plasticPk", "box"); + MATERIALTYPES.put("carbonFiber", "box"); + MATERIALTYPES.put("carbonFiberCu", "box"); + MATERIALTYPES.put("carbonFiberPk", "box"); + MATERIALTYPES.put("busCable", "box"); + MATERIALTYPES.put("busCableCu", "box"); + MATERIALTYPES.put("busCablePk", "box"); + MATERIALTYPES.put("pitchAdaptor", "box"); + MATERIALTYPES.put("pcBoardAndChips", "box"); + MATERIALTYPES.put("pcBoard", "box"); + MATERIALTYPES.put("chip", "box"); + MATERIALTYPES.put("epoxyAndRailAndPads","box"); + MATERIALTYPES.put("epoxyMajorCu", "box"); + MATERIALTYPES.put("epoxyMinorCu", "box"); + MATERIALTYPES.put("epoxyMajorPk", "box"); + MATERIALTYPES.put("epoxyMinorPk", "box"); + MATERIALTYPES.put("rail", "box"); + MATERIALTYPES.put("wirebond", "box"); + MATERIALTYPES.put("kaptonWrapTapeSide", "box"); + MATERIALTYPES.put("kaptonWrapTapeCap", "box"); + MATERIALTYPES.put("kaptonWrapGlueSide", "box"); + MATERIALTYPES.put("kaptonWrapGlueCap", "box"); + + MATERIALTYPES.put("pad", "tube"); + + int boxNum = 0; // number of box types + int mat = 0; + for( Entry entry : MATERIALTYPES.entrySet() ) + { + String key = entry.getKey(); + String value = entry.getValue(); + double[] dimensions = null; + + if( value == "box" ) + { + boxNum++; + dimensions = new double[]{ + cp.getDouble( ccdbPath+"material/box/wid", mat ), + cp.getDouble( ccdbPath+"material/box/thk", mat ), + cp.getDouble( ccdbPath+"material/box/len", mat ) + }; + } + else if( value == "tube" ) // offset by boxNum to reset row for CCDB table + { + dimensions = new double[]{ + cp.getDouble( ccdbPath+"material/tube/rmin", mat - boxNum ), + cp.getDouble( ccdbPath+"material/tube/rmax", mat - boxNum ), + cp.getDouble( ccdbPath+"material/tube/zlen", mat - boxNum ), + cp.getDouble( ccdbPath+"material/tube/phi0", mat - boxNum ), + cp.getDouble( ccdbPath+"material/tube/dphi", mat - boxNum ) + }; + } + MATERIALDIMENSIONS.put( key, dimensions ); + mat++; + } + + + // calculate derived constants + NLAYERS = NMODULES*NREGIONS; + MODULELEN = NSENSORS*(ACTIVESENLEN + 2*DEADZNLEN) + (NSENSORS - 1)*MICROGAPLEN; + STRIPLENMAX = MODULELEN - 2*DEADZNLEN; + MODULEWID = ACTIVESENWID + 2*DEADZNWID; + STRIPOFFSETWID = cp.getDouble(ccdbPath+"svt/stripStart", 0 ); + LAYERGAPTHK = cp.getDouble(ccdbPath+"svt/layerGapThk", 0 ); + PASSIVETHK = MATERIALDIMENSIONS.get("carbonFiber")[1] + MATERIALDIMENSIONS.get("busCable")[1] + MATERIALDIMENSIONS.get("epoxyAndRailAndPads")[1]; + SECTORLEN = MATERIALDIMENSIONS.get("heatSink")[2] + MATERIALDIMENSIONS.get("rohacell")[2]; + double layerGapThk = MATERIALDIMENSIONS.get("rohacell")[1] + 2*PASSIVETHK; // construct from material thicknesses instead + + + if( VERBOSE ) System.out.printf("LAYERGAPTHK (CCDB) = % 8.3f\n", LAYERGAPTHK ); + if( VERBOSE ) System.out.printf("layerGapThk (MATERIALS) = % 8.3f\n", layerGapThk ); + LAYERGAPTHK = layerGapThk; if( VERBOSE ) System.out.println("set LAYERGAPTHK to layerGapThk"); + + if( VERBOSE ) + { + System.out.printf("NREGIONS %4d\n", NREGIONS ); + System.out.printf("NMODULES %4d\n", NMODULES ); + System.out.printf("NLAYERS %4d\n", NLAYERS ); + System.out.printf("NSENSORS %4d\n", NSENSORS ); + System.out.printf("NSTRIPS %4d\n", NSTRIPS ); + System.out.printf("NFIDUCIALS %4d\n", NFIDUCIALS ); + System.out.printf("NPADS %4d\n", NPADS ); + System.out.println(); + } + + // read constants from region and support table + NSECTORS = new int[NREGIONS]; + STATUS = new int[NREGIONS]; + Z0ACTIVE = new double[NREGIONS]; + REFRADIUS = new double[NREGIONS]; // used to derive LAYERRADIUS + SUPPORTRADIUS = new double[NREGIONS]; // used to build volumes + LAYERRADIUS = new double[NREGIONS][NMODULES]; // used to build strips + + // Consider Region 1 Sector 6 (not to scale) + // + // y (vertical) .------------------^------------- + // ^ | V (outer) | + // | | sensor layer | 0.32 silicon thickness + // | | | + // | .--------+--------------^---v------------- module radius 1 + // | | passiveThk | + // |------^-----------------^-------------+-----------------------|----------------- fiducial layer + // | | | | | + // | | heatSink | | | + // | | | 2.50 | rohacell | 3.236 layer gap + // | | 2.88 | | | + // | | | | | + // | | +--v-------------+-----------------------|------------------ module radius 0 + // | | | | passiveThk | + // | | | '---^----+--------------v-----^------------ radius CCDB + // |------v-------^------' | | | radius MechEng + // | | | | U (inner) | 0.32 silicon thickness + // | | | | sensor layer | + // | | | '--------------------v----------- + // | | support | reference + // | | radius | radius + // | | | + // o==============v===========================v===================================-> z (beamline) + System.out.println("SVT READ Z SHIFT VALUE "+cp.getDouble("/geometry/target/position", 0)); + // LAYERRADIUS and ZSTARTACTIVE are used primarily by the Reconstruction and getStrip() + for( int region = 0; region < NREGIONS; region++ ) + { + NSECTORS[region] = cp.getInteger(ccdbPath+"region/nSectors", region ); + + STATUS[region] = cp.getInteger(ccdbPath+"region/status", region ); + Z0ACTIVE[region] = cp.getDouble(ccdbPath+"region/zStart", region ); // Cu edge of hybrid sensor's active volume + REFRADIUS[region] = cp.getDouble(ccdbPath+"region/UlayerOuterRadius", region); // radius to outer side of U (inner) module + SUPPORTRADIUS[region] = cp.getDouble(ccdbPath+"region/CuSupportInnerRadius", region); // radius to inner side of heatSinkRidge + + for( int m = 0; m < NMODULES; m++ ) + { + switch( m ) + { + case 0: // U = lower / inner + LAYERRADIUS[region][m] = REFRADIUS[region] - LAYERPOSFAC*SILICONTHK; + break; + case 1: // V = upper / outer + LAYERRADIUS[region][m] = REFRADIUS[region] + LAYERGAPTHK + LAYERPOSFAC*SILICONTHK; + break; + } + //System.out.println("LAYERRADIUS "+ LAYERRADIUS[region][m]); + } + } + + NTOTALSECTORS = convertRegionSector2Index( NREGIONS-1, NSECTORS[NREGIONS-1]-1 )+1; + NTOTALFIDUCIALS = convertRegionSectorFiducial2Index(NREGIONS-1, NSECTORS[NREGIONS-1]-1, NFIDUCIALS-1 )+1; + + RSI = new int[NREGIONS][NTOTALSECTORS]; + for( int aRegion = 0; aRegion < NREGIONS; aRegion++ ) + { + for( int aSector = 0; aSector < NSECTORS[aRegion]; aSector++ ) + { + RSI[aRegion][aSector] = convertRegionSector2Index( aRegion, aSector ); // System.out.println(" a Region "+aRegion +" aSector "+aSector+" RSI "+RSI[aRegion][aSector] ); - } + } + } + + System.out.println("Reading detector global position from database"); + double xpos = cp.getDouble(ccdbPath+"position/x", 0 ); + double ypos = cp.getDouble(ccdbPath+"position/y", 0 ); + double zpos = cp.getDouble(ccdbPath+"position/z", 0 ); + System.out.println("SVT position set to (" + xpos + "," + ypos + "," + zpos + ") mm"); + + System.out.println("Reading alignment shifts from database"); + + + LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; + for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 + { + int sector = cp.getInteger(ccdbPath+"layeralignment/sector", i ); + int layer = cp.getInteger(ccdbPath+"layeralignment/layer", i ); + double tx = cp.getDouble(ccdbPath+"layeralignment/deltaX", i ); + double ty = cp.getDouble(ccdbPath+"layeralignment/deltaY", i ); + double tz = cp.getDouble(ccdbPath+"layeralignment/deltaZ", i ); + double rx = cp.getDouble(ccdbPath+"layeralignment/rotX", i ); + double ry = cp.getDouble(ccdbPath+"layeralignment/rotY", i ); + double rz = cp.getDouble(ccdbPath+"layeralignment/rotZ", i ); + double ra = cp.getDouble(ccdbPath+"layeralignment/rotA", i ); + // adding global shift to internal alignment shifts + tx += xpos; + ty += ypos; + tz += zpos; + LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; + } + if( VERBOSE ) showLayerShiftData(); + + if( VERBOSE ) + { + System.out.println("NSECTORS STATUS Z0ACTIVE REFRADIUS SUPPORTRADIUS LAYERRADIUS (U,V)"); + for(int r = 0; r < NREGIONS; r++ ) + { + System.out.printf("%6s%2d","", NSECTORS[r] ); + System.out.printf("%6s%1d","", STATUS[r] ); + System.out.printf("%1s%8.3f","", Z0ACTIVE[r] ); + System.out.printf("%2s%8.3f","", REFRADIUS[r] ); + System.out.printf("%6s%8.3f","", SUPPORTRADIUS[r] ); + System.out.printf("%1s%8.3f %8.3f","", LAYERRADIUS[r][0], LAYERRADIUS[r][1] ); + System.out.println(); } - System.out.println("Reading alignment shifts from database"); - - - LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; - for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 + } + + + + // check one constant from each table + //if( NREGIONS == 0 || NSECTORS[0] == 0 || FIDCUX == 0 || MATERIALS[0][0] == 0 || SUPPORTRADIUS[0] == 0 ) + //throw new NullPointerException("please load the following tables from CCDB in "+ccdbPath+"\n svt\n region\n support\n fiducial\n material\n"); + + if( VERBOSE ) + { + System.out.println(); + System.out.printf("NTOTALSECTORS %4d\n", NTOTALSECTORS ); + System.out.printf("NTOTALFIDUCIALS %4d\n", NTOTALFIDUCIALS ); + System.out.printf("PHI0 %8.3f\n", Math.toDegrees(PHI0) ); + System.out.printf("SECTOR0 %8.3f\n", Math.toDegrees(SECTOR0) ); + System.out.printf("STEREOANGLE %8.3f\n", Math.toDegrees(STEREOANGLE) ); + System.out.printf("READOUTPITCH %8.3f\n", READOUTPITCH ); + System.out.printf("STRIPOFFSETWID %8.3f\n", STRIPOFFSETWID ); + System.out.printf("STRIPLENMAX %8.3f\n", STRIPLENMAX ); + System.out.printf("LAYERPOSFAC %8.3f\n", LAYERPOSFAC ); + System.out.printf("PHYSSENLEN %8.3f\n", PHYSSENLEN ); + System.out.printf("SILICONTHK %8.3f\n", SILICONTHK ); + System.out.printf("PHYSSENWID %8.3f\n", PHYSSENWID ); + System.out.printf("ACTIVESENLEN %8.3f\n", ACTIVESENLEN ); + System.out.printf("ACTIVESENWID %8.3f\n", ACTIVESENWID ); + System.out.printf("DEADZNLEN %8.3f\n", DEADZNLEN ); + System.out.printf("DEADZNWID %8.3f\n", DEADZNWID ); + System.out.printf("MICROGAPLEN %8.3f\n", MICROGAPLEN ); + System.out.printf("MODULEWID %8.3f\n", MODULEWID ); + System.out.printf("MODULELEN %8.3f\n", MODULELEN ); + System.out.printf("LAYERGAPTHK %8.3f\n", LAYERGAPTHK ); + System.out.printf("PASSIVETHK %8.3f\n", PASSIVETHK ); + System.out.printf("SECTORLEN %8.3f\n", SECTORLEN ); + System.out.printf("FIDCUX %8.3f\n", FIDCUX ); + System.out.printf("FIDPKX %8.3f\n", FIDPKX ); + System.out.printf("FIDORIGINZ %8.3f\n", FIDORIGINZ ); + System.out.printf("FIDCUZ %8.3f\n", FIDCUZ ); + System.out.printf("FIDPKZ0 %8.3f\n", FIDPKZ0 ); + System.out.printf("FIDPKZ1 %8.3f\n", FIDPKZ1 ); + + double fidXDist = 2*SVTConstants.FIDCUX; + double fidZDist = SVTConstants.FIDCUZ + SVTConstants.FIDPKZ0 + SVTConstants.FIDPKZ1; + double fidZDist0 = Math.sqrt( Math.pow(fidZDist,2) + Math.pow(SVTConstants.FIDCUX + SVTConstants.FIDPKX, 2) ); + double fidZDist1 = Math.sqrt( Math.pow(fidZDist,2) + Math.pow(SVTConstants.FIDCUX - SVTConstants.FIDPKX, 2) ); + + System.out.printf("fidXDist %8.3f\n", fidXDist ); + System.out.printf("fidZDist %8.3f\n", fidZDist ); + System.out.printf("fidZDist0 %8.3f\n", fidZDist0 ); + System.out.printf("fidZDist1 %8.3f\n", fidZDist1 ); + + int maxStrLenName = 32; + int maxStrLenType = 5; + for( Map.Entry entryType : MATERIALTYPES.entrySet() ) { - int sector = cp.getInteger(ccdbPath+"layeralignment/sector", i ); - int layer = cp.getInteger(ccdbPath+"layeralignment/layer", i ); - double tx = cp.getDouble(ccdbPath+"layeralignment/deltaX", i ); - double ty = cp.getDouble(ccdbPath+"layeralignment/deltaY", i ); - double tz = cp.getDouble(ccdbPath+"layeralignment/deltaZ", i ); - double rx = cp.getDouble(ccdbPath+"layeralignment/rotX", i ); - double ry = cp.getDouble(ccdbPath+"layeralignment/rotY", i ); - double rz = cp.getDouble(ccdbPath+"layeralignment/rotZ", i ); - double ra = cp.getDouble(ccdbPath+"layeralignment/rotA", i ); - LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; + String name = entryType.getKey(); + String type = entryType.getValue(); + double[] dimensions = MATERIALDIMENSIONS.get( name ); + String fmt = "%s %"+(maxStrLenName - name.length())+"s"; + System.out.printf(fmt, name, "" ); + fmt = "%s %"+(maxStrLenType - type.length())+"s"; + System.out.printf(fmt, type, "" ); + for( int i = 0; i < dimensions.length; i++ ) + System.out.printf("%8.3f ", dimensions[i] ); + System.out.println(); } - if( VERBOSE ) showLayerShiftData(); - - if( VERBOSE ) - { - System.out.println("NSECTORS STATUS Z0ACTIVE REFRADIUS SUPPORTRADIUS LAYERRADIUS (U,V)"); - for(int r = 0; r < NREGIONS; r++ ) - { - System.out.printf("%6s%2d","", NSECTORS[r] ); - System.out.printf("%6s%1d","", STATUS[r] ); - System.out.printf("%1s%8.3f","", Z0ACTIVE[r] ); - System.out.printf("%2s%8.3f","", REFRADIUS[r] ); - System.out.printf("%6s%8.3f","", SUPPORTRADIUS[r] ); - System.out.printf("%1s%8.3f %8.3f","", LAYERRADIUS[r][0], LAYERRADIUS[r][1] ); - System.out.println(); - } - } - - - - // check one constant from each table - //if( NREGIONS == 0 || NSECTORS[0] == 0 || FIDCUX == 0 || MATERIALS[0][0] == 0 || SUPPORTRADIUS[0] == 0 ) - //throw new NullPointerException("please load the following tables from CCDB in "+ccdbPath+"\n svt\n region\n support\n fiducial\n material\n"); - - bLoadedConstants = true; - - if( VERBOSE ) - { - System.out.println(); - System.out.printf("NTOTALSECTORS %4d\n", NTOTALSECTORS ); - System.out.printf("NTOTALFIDUCIALS %4d\n", NTOTALFIDUCIALS ); - System.out.printf("PHI0 %8.3f\n", Math.toDegrees(PHI0) ); - System.out.printf("SECTOR0 %8.3f\n", Math.toDegrees(SECTOR0) ); - System.out.printf("STEREOANGLE %8.3f\n", Math.toDegrees(STEREOANGLE) ); - System.out.printf("READOUTPITCH %8.3f\n", READOUTPITCH ); - System.out.printf("STRIPOFFSETWID %8.3f\n", STRIPOFFSETWID ); - System.out.printf("STRIPLENMAX %8.3f\n", STRIPLENMAX ); - System.out.printf("LAYERPOSFAC %8.3f\n", LAYERPOSFAC ); - System.out.printf("PHYSSENLEN %8.3f\n", PHYSSENLEN ); - System.out.printf("SILICONTHK %8.3f\n", SILICONTHK ); - System.out.printf("PHYSSENWID %8.3f\n", PHYSSENWID ); - System.out.printf("ACTIVESENLEN %8.3f\n", ACTIVESENLEN ); - System.out.printf("ACTIVESENWID %8.3f\n", ACTIVESENWID ); - System.out.printf("DEADZNLEN %8.3f\n", DEADZNLEN ); - System.out.printf("DEADZNWID %8.3f\n", DEADZNWID ); - System.out.printf("MICROGAPLEN %8.3f\n", MICROGAPLEN ); - System.out.printf("MODULEWID %8.3f\n", MODULEWID ); - System.out.printf("MODULELEN %8.3f\n", MODULELEN ); - System.out.printf("LAYERGAPTHK %8.3f\n", LAYERGAPTHK ); - System.out.printf("PASSIVETHK %8.3f\n", PASSIVETHK ); - System.out.printf("SECTORLEN %8.3f\n", SECTORLEN ); - System.out.printf("FIDCUX %8.3f\n", FIDCUX ); - System.out.printf("FIDPKX %8.3f\n", FIDPKX ); - System.out.printf("FIDORIGINZ %8.3f\n", FIDORIGINZ ); - System.out.printf("FIDCUZ %8.3f\n", FIDCUZ ); - System.out.printf("FIDPKZ0 %8.3f\n", FIDPKZ0 ); - System.out.printf("FIDPKZ1 %8.3f\n", FIDPKZ1 ); - - double fidXDist = 2*SVTConstants.FIDCUX; - double fidZDist = SVTConstants.FIDCUZ + SVTConstants.FIDPKZ0 + SVTConstants.FIDPKZ1; - double fidZDist0 = Math.sqrt( Math.pow(fidZDist,2) + Math.pow(SVTConstants.FIDCUX + SVTConstants.FIDPKX, 2) ); - double fidZDist1 = Math.sqrt( Math.pow(fidZDist,2) + Math.pow(SVTConstants.FIDCUX - SVTConstants.FIDPKX, 2) ); - - System.out.printf("fidXDist %8.3f\n", fidXDist ); - System.out.printf("fidZDist %8.3f\n", fidZDist ); - System.out.printf("fidZDist0 %8.3f\n", fidZDist0 ); - System.out.printf("fidZDist1 %8.3f\n", fidZDist1 ); - - int maxStrLenName = 32; - int maxStrLenType = 5; - for( Map.Entry entryType : MATERIALTYPES.entrySet() ) - { - String name = entryType.getKey(); - String type = entryType.getValue(); - double[] dimensions = MATERIALDIMENSIONS.get( name ); - String fmt = "%s %"+(maxStrLenName - name.length())+"s"; - System.out.printf(fmt, name, "" ); - fmt = "%s %"+(maxStrLenType - type.length())+"s"; - System.out.printf(fmt, type, "" ); - for( int i = 0; i < dimensions.length; i++ ) - System.out.printf("%8.3f ", dimensions[i] ); - System.out.println(); - } - } - - } + } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 4365d237e..e2d8191a9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -131,7 +131,7 @@ public void setFieldsConfig(String fieldsConfig) { public boolean processDataEvent(DataEvent event) { this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); - double shift = org.jlab.rec.cvt.Constants.getZoffset(); + double shift = 0;//org.jlab.rec.cvt.Constants.getZoffset(); this.FieldsConfig = this.getFieldsConfig(); From 418da63cd32db18eb11baec74bd52f16fa159445 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 7 Dec 2020 19:06:09 +0100 Subject: [PATCH 057/291] CVT: using /geometry/cvt/.../position tables for absolute detector position --- .../jlab/detector/geant4/v2/SVT/SVTConstants.java | 4 ++-- .../main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java | 2 +- .../org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 13 +++++++++---- .../java/org/jlab/rec/cvt/services/CVTRecNewKF.java | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index d8c548f55..9d743971e 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -120,7 +120,7 @@ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) cp.loadTable( ccdbPath +"layeralignment"); cp.loadTable( ccdbPath +"position"); //shift by target - cp.loadTable("/geometry/target"); +// cp.loadTable("/geometry/target"); //if( loadAlignmentTables ) cp.loadTable( ccdbPath +"alignment/sector"); // possible future tables //if( loadAlignmentTables ) cp.loadTable( ccdbPath +"alignment/layer"); @@ -322,7 +322,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table // | | radius | radius // | | | // o==============v===========================v===================================-> z (beamline) - System.out.println("SVT READ Z SHIFT VALUE "+cp.getDouble("/geometry/target/position", 0)); +// System.out.println("SVT READ Z SHIFT VALUE "+cp.getDouble("/geometry/target/position", 0)); // LAYERRADIUS and ZSTARTACTIVE are used primarily by the Reconstruction and getStrip() for( int region = 0; region < NREGIONS; region++ ) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 27816688c..1d920de02 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -278,7 +278,7 @@ public Point3D getOffset(int layer, int sector) { Point3D offset = new Point3D(); offset.copy(Constants.shifts[layer-1][sector-1]); - offset.translateXYZ(0, 0, org.jlab.rec.cvt.Constants.getZoffset()); +// offset.translateXYZ(0, 0, org.jlab.rec.cvt.Constants.getZoffset()); return offset; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 39d891226..ff7cee876 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -104,6 +104,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) //load alignment parameters dbprovider.loadTable("/geometry/cvt/mvt/alignment"); + dbprovider.loadTable("/geometry/cvt/mvt/position"); //beam offset table dbprovider.loadTable("/geometry/beam/position"); @@ -116,7 +117,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) // target position double ztarget = dbprovider.getDouble("/geometry/target/position", 0); - System.out.println(" ................READ TARGET SHIFT "+ztarget+" cm......."); +// System.out.println(" ................READ TARGET SHIFT "+ztarget+" cm......."); // dbprovider.show(); // Getting the Constants // 1) pitch info @@ -290,13 +291,17 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) } - // alignment + // alignment and offsets + double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); + double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); + double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); for (int j = 0; j Date: Mon, 14 Dec 2020 15:53:12 +0100 Subject: [PATCH 058/291] Correct definition of BMT trajeectory planes to account for the drift gap thickness --- .../cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java | 2 +- .../java/org/jlab/rec/cvt/track/TrackCandListFinder.java | 2 +- .../org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java index b6af6a2c9..813f9dee4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java @@ -105,7 +105,7 @@ private Constants() { public static final double phi14cut = 35.; public static final double radcut = 100.; public static final double drdzcut = 150.; - public static final double LYRTHICKN = 0.0; // old LYRTHICKN = 4.; +// public static final double LYRTHICKN = 0.0; // old LYRTHICKN = 4.; public static final double isInSectorJitter = 2.0; // 2 deg public static final int STARTINGLAYR = 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 9f3440de1..791da12d2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -629,7 +629,7 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, for (int j = shift + j0; j < shift + j0 + BMTCdetcrossesInTrk.size(); j++) { Z.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN); + Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); ErrRho.add(j, 0.01); // check this error on thickness measurement ErrZ.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_PointErr().z()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 12c68a2d6..b46e5026e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -173,10 +173,10 @@ public Trajectory findTrajectory(int id, Track trk, double R = 0; if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.Z) { - R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; + R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; } if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.C) { - R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; + R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; } // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, @@ -763,10 +763,10 @@ private double[][] getIntersectionTrackWithBMTModules(int l, double R = 0; if (BMTGeometry.getDetectorType(l + 1) == BMTType.C) { - R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; + R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; } if (BMTGeometry.getDetectorType(l + 1) == BMTType.Z) { - R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.LYRTHICKN; + R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; } // solve for intersection of line with cylinder of radius R // x = _yxslope2*y +_yxinterc2; x^2+y^2 = R^2 From c6b2ca7f092c0ee08f43c9ff3d9d2c04ad49454a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 15 Dec 2020 18:44:36 +0100 Subject: [PATCH 059/291] fixed mistake in loading CVT alignment constants --- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index ff7cee876..2c444793e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -295,25 +295,24 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); - for (int j = 0; j Date: Wed, 16 Dec 2020 13:49:51 -0500 Subject: [PATCH 060/291] Configuration to remove layers from the fit. --- .../main/java/org/jlab/rec/cvt/Constants.java | 19 +++++++++++++ .../jlab/rec/cvt/services/CVTRecNewKF.java | 27 +++++++++++++++++++ .../jlab/rec/cvt/services/RecUtilities.java | 6 +++++ 3 files changed, 52 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 3ec149e2d..baf7025ea 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -1,5 +1,8 @@ package org.jlab.rec.cvt; +import java.util.HashMap; +import java.util.Map; + public class Constants { public static double PTCUT = 0.075; @@ -39,6 +42,8 @@ public class Constants { private static int _rmReg = 0; + private static Map layersUsed = new HashMap(); + public static double getXb() { return _Xb; } @@ -78,6 +83,20 @@ public static int getRmReg() { public static void setRmReg(int _reg) { Constants._rmReg = _reg; } + + /** + * @return the layersUsed + */ + public static Map getLayersUsed() { + return layersUsed; + } + + /** + * @param aLayersUsed the layersUsed to set + */ + public static void setLayersUsed(Map aLayersUsed) { + layersUsed = aLayersUsed; + } //public static final boolean DEBUGMODE =false; // for landau inverse calculation diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 435133e7f..223a82125 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -275,6 +275,33 @@ public boolean init() { if (svtCosmics==null) { System.out.println("["+this.getName()+"] run with cosmics settings default = false"); } + + for(int i = 0; i < 12; i++) + Constants.getLayersUsed().put(i+1, 1); + + //Skip layers + String exLys = this.getEngineConfigString("excludeLayers"); + + if (exLys!=null) { + System.out.println("["+this.getName()+"] run with layers "+exLys+"excluded in fit config chosen based on yaml"); + String exlys = String.valueOf(exLys); + String[] values = exlys.split(","); + for(int k = 0; k < values.length; k++) + Constants.getLayersUsed().put(Integer.valueOf(values[k]), 0); + } + else { + exLys = System.getenv("COAT_CVT_EXCLUDELAYERS"); + if (exLys!=null) { + System.out.println("["+this.getName()+"] run with region "+rmReg+"excluded in fit config chosen based on env"); + String exlys = String.valueOf(exLys); + String[] values = exlys.split(","); + for(int k = 0; k < values.length; k++) + Constants.getLayersUsed().put(Integer.valueOf(values[k]), 0); + } + } + if (exLys==null) { + System.out.println("["+this.getName()+"] run with all layer in fit (default) "); + } // Load other geometries variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index c13701ecd..d1ab1bb79 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -100,6 +100,8 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge if(trkcand.get_Clusters().get(i).get_Layer()%2==1) thickn_ov_X0 = org.jlab.rec.cvt.svt.Constants.SILICONTHICK / org.jlab.rec.cvt.svt.Constants.SILICONRADLEN; meas.setl_over_X0(thickn_ov_X0); + if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + meas.notUsedInFit=true; if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); @@ -136,6 +138,8 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); + if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + meas.notUsedInFit=true; if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); @@ -154,6 +158,8 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); + if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + meas.notUsedInFit=true; if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); From 5dbf78fe4c923822c059a25059af20b04dbed216 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 16 Dec 2020 13:50:01 -0500 Subject: [PATCH 061/291] Configuration to remove layers from the fit. --- .../main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java | 1 + .../org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java | 1 + 2 files changed, 2 insertions(+) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java index bf44ddaab..8eb9eed1c 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -34,6 +34,7 @@ public class Surface implements Comparable { private double _l_over_X0; //this is for energy loss private double _Z_over_A_times_l; + public boolean notUsedInFit = false; public Surface(Plane3D plane3d, Point3D refrPoint, Point3D c1, Point3D c2) { type = Type.PLANEWITHPOINT; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index b486692d2..77cb3223f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -36,6 +36,7 @@ public void setMeasVecs(List measSurfaces) { if(mvec.surface.getError()!=0) mvec.error = mvec.surface.getError(); mvec.l_over_X0 = mvec.surface.getl_over_X0(); + mvec.skip = mvec.surface.notUsedInFit; measurements.add(mvec); } } From 5a238259e4747ee07338aca699fcc99e90b75b24 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 16 Dec 2020 14:08:32 -0500 Subject: [PATCH 062/291] Configuration to remove layers from the fit. --- .../main/java/org/jlab/rec/cvt/services/RecUtilities.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index d1ab1bb79..5dcf05009 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -138,8 +138,10 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); - if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) { + //System.out.println("Exluding layer "+meas.getLayer()); meas.notUsedInFit=true; + } if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); @@ -158,8 +160,10 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); - if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) { + //System.out.println("Exluding layer "+meas.getLayer()); meas.notUsedInFit=true; + } if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); From 45a52d6026baafb5cbef6157fe62e460b3c61d0d Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 5 Jan 2021 17:28:26 -0500 Subject: [PATCH 063/291] Added reseeding with cross exclusion functionality. --- .../rec/cvt/services/CosmicTracksRec.java | 3 + .../jlab/rec/cvt/services/RecUtilities.java | 102 ++++++++++++++++++ .../rec/cvt/services/TracksFromTargetRec.java | 5 +- .../rec/cvt/track/TrackCandListFinder.java | 18 ++-- .../org/jlab/rec/cvt/track/TrackSeeder.java | 3 +- 5 files changed, 120 insertions(+), 11 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index cde31f480..dfee1dfbc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -12,6 +12,7 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossList; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; +import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.TrackCandListFinder; @@ -56,6 +57,8 @@ public boolean processEvent(DataEvent event, return true; } + CosmicFitter fitTrk = new CosmicFitter(); + cosmics = recUtil.reFit(cosmics, fitTrk, trkcandFinder); if (cosmics.size() > 0) { for (int k1 = 0; k1 < cosmics.size(); k1++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 5dcf05009..c5fead625 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -21,6 +21,10 @@ import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.fit.CosmicFitter; +import org.jlab.rec.cvt.track.StraightTrack; +import org.jlab.rec.cvt.track.TrackCandListFinder; +import org.jlab.rec.cvt.track.TrackSeeder; /** * Service to return reconstructed TRACKS @@ -361,4 +365,102 @@ public Track OutputTrack(Seed seed) { } + public List reFit(List seedlist,org.jlab.rec.cvt.svt.Geometry svt_geo, + Swim swimmer, TrackSeeder trkseedr) { + List filtlist = new ArrayList(); + if(seedlist==null) + return filtlist; + for (Seed bseed : seedlist) { + if(bseed == null) + continue; + if(this.reFit(bseed, svt_geo, swimmer, trkseedr) == true) { + filtlist.add(bseed); + } + } + return filtlist; + } + public boolean reFit(Seed bseed, + org.jlab.rec.cvt.svt.Geometry svt_geo, + Swim swimmer, TrackSeeder trkseedr) { + boolean pass = true; + + List refi = new ArrayList(); + for(Cross c : bseed.get_Crosses()) { + int layr = 0; + int layr2 = 0; + if(c.get_Detector().equalsIgnoreCase("BMT")) { + layr = c.get_Cluster1().get_Layer()+6; + if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0) + refi.add(c); + } else { + layr = c.get_Cluster1().get_Layer(); + layr2 = c.get_Cluster2().get_Layer(); + if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0 + && org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)!=(Integer)0) + refi.add(c); + } + } + Track cand = null; + if(refi.size()>=3) { + cand = trkseedr.fitSeed(refi, svt_geo, 5, false, swimmer); + if(cand!=null && cand.get_helix()!=null) { + bseed.set_Helix(cand.get_helix()); + } else { + pass = false; + } + } else { + pass = false; + } + return pass; + } + + public List reFit(List seedlist, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + List filtlist = new ArrayList(); + if(seedlist==null) + return filtlist; + for (StraightTrack bseed : seedlist) { + if(this.reFit(bseed, fitTrk, trkfindr) == true) { + filtlist.add(bseed); + } + } + return filtlist; + } + + public boolean reFit(StraightTrack cand, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + boolean pass = true; + List refi = new ArrayList(); + List crosses = cand; + for(Cross c : crosses) { + int layr = 0; + int layr2 = 0; + if(c.get_Detector().equalsIgnoreCase("BMT")) { + layr = c.get_Cluster1().get_Layer()+6; + if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0) + refi.add(c); + } else { + layr = c.get_Cluster1().get_Layer(); + layr2 = c.get_Cluster2().get_Layer(); + if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0 + && org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)!=(Integer)0) + refi.add(c); + } + } + + if(refi.size()>=3) { + TrackCandListFinder.RayMeasurements NewMeasArrays = trkfindr. + get_RayMeasurementsArrays((ArrayList) refi, false, false); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, + NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, + NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + if(fitTrk.get_ray()!=null) { + cand = new StraightTrack(fitTrk.get_ray()); + } else { + pass = false; + } + } else { + pass = false; + } + return pass; + } + } \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index c723f5cd1..ffe7fa8c4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -60,6 +60,7 @@ public boolean processEvent(DataEvent event, trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null, SVTGeom, BMTGeom, swimmer); + seeds = recUtil.reFit(seeds, SVTGeom, swimmer, trseed); } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); @@ -67,6 +68,8 @@ public boolean processEvent(DataEvent event, TrackSeeder trseed2 = new TrackSeeder(); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); + + seeds = recUtil.reFit(seeds, SVTGeom, swimmer, trseed2); } } if(seeds ==null || seeds.size() == 0) { @@ -77,7 +80,7 @@ public boolean processEvent(DataEvent event, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf = null; List trkcands = new ArrayList(); - + for (Seed seed : seeds) { org.jlab.clas.tracking.trackrep.Helix hlx = null ; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 791da12d2..f261578b7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -100,15 +100,15 @@ private class HelixMeasurements { * @author ziegler * */ - private class RayMeasurements { + public class RayMeasurements { - List _X; // x coordinate array - List _Y; // y coordinate array (same size as X array) - List _Z; // z coordinate array - List _Y_prime; // y coordinate array (same size as Z array) - List _ErrZ; // z uncertainty (same size as Z array) - List _ErrY_prime; // y uncertainty (same size as Z array) - List _ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) + public List _X; // x coordinate array + public List _Y; // y coordinate array (same size as X array) + public List _Z; // z coordinate array + public List _Y_prime; // y coordinate array (same size as Z array) + public List _ErrZ; // z uncertainty (same size as Z array) + public List _ErrY_prime; // y uncertainty (same size as Z array) + public List _ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) RayMeasurements(List X, List Y, @@ -661,7 +661,7 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, List BMTCdetcrossesInTrk = new ArrayList(); List BMTZdetcrossesInTrk = new ArrayList(); - private RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, boolean ignoreErr, boolean resetSVTMeas) { + public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, boolean ignoreErr, boolean resetSVTMeas) { X.clear(); Y.clear(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 67106ab8a..64cecf051 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -73,7 +73,7 @@ private void MatchSeed(List othercrs) { } } } - private void FitSeed(List seedcrs) { + public void FitSeed(List seedcrs) { Xs.clear(); Ys.clear(); Ws.clear(); @@ -357,6 +357,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, } } } + for (Seed bseed : seedlist) { for(Cross c : bseed.get_Crosses()) { c.isInSeed = true; From 432e4cfd893a8c8a41d48f16fccc48b32902f996 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 12:56:21 -0500 Subject: [PATCH 064/291] Add svt sorting before running CA. --- .../java/org/jlab/rec/cvt/track/TrackSeederCA.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index ccf69e48b..4c8f77e44 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -237,10 +237,10 @@ public List findSeed(List svt_crosses, List bmt_crosses, // System.out.println(seedlist.size()); for (int s = 0; s < seedCrosses.size(); s++) { Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters - Track cand = fitSeed(seedCrosses.get(s), svt_geo, 5, false, swimmer); - if (cand != null) { - cands.add(cand); - } + Track cand = fitSeed(seedCrosses.get(s), svt_geo, 5, false, swimmer); + if (cand != null) { + cands.add(cand); + } } // for( int i=0;i findSeed(List svt_crosses, List bmt_crosses, seed.set_Crosses(cand); seed.set_Helix(cand.get_helix()); seedlist.add(seed); - List clusters = new ArrayList(); + List clusters = new ArrayList(); for(Cross c : seed.get_Crosses()) { if(c.get_Detector().equalsIgnoreCase("SVT")) { clusters.add(c.get_Cluster1()); @@ -485,7 +485,7 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, int fitIter, boolean originConstraint, Swim swimmer) { double chisqMax = Double.POSITIVE_INFINITY; - + Collections.sort(VTCrosses); Track cand = null; HelicalTrackFitter fitTrk = new HelicalTrackFitter(); for (int i = 0; i < fitIter; i++) { @@ -513,7 +513,7 @@ public Track fitSeed(List VTCrosses, BMTCrossesC.clear(); BMTCrossesZ.clear(); SVTCrosses.clear(); - + for (Cross c : VTCrosses) { if (!(Double.isNaN(c.get_Point().z()) || Double.isNaN(c.get_Point().x()))) { SVTCrosses.add(c); From ce5c5a5da69ea25885c148b899685a226a3c002a Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 12:57:17 -0500 Subject: [PATCH 065/291] Set flag for running layer exclusion track refit algo. --- .../java/org/jlab/rec/cvt/services/CVTRecNewKF.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 223a82125..917dde783 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -58,6 +58,7 @@ public CVTRecNewKF() { int Run = -1; public boolean isSVTonly = false; public boolean isCosmic = false; + public boolean exclLayrs = false; public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int iRun, boolean addMisAlignmts, String misAlgnFile) { if (event.hasBank("RUN::config") == false) { @@ -127,9 +128,10 @@ public String getFieldsConfig() { public void setFieldsConfig(String fieldsConfig) { FieldsConfig = fieldsConfig; } + @Override public boolean processDataEvent(DataEvent event) { - + this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); double shift = 0;//org.jlab.rec.cvt.Constants.getZoffset(); @@ -217,7 +219,7 @@ public boolean processDataEvent(DataEvent event) { } else { trksFromTargetRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, shift, swimmer, this.isSVTonly); + crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, shift, swimmer, this.isSVTonly, this.exclLayrs); } return true; } @@ -302,6 +304,13 @@ public boolean init() { if (exLys==null) { System.out.println("["+this.getName()+"] run with all layer in fit (default) "); } + + int exlyrsnb = 0; + for(int ilayrs = 0; ilayrs<12; ilayrs++) { + exlyrsnb+=(int)org.jlab.rec.cvt.Constants.getLayersUsed().get(ilayrs+1); + } + if(exlyrsnb>0) + exclLayrs = true; // Load other geometries variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); From 557c2126d72ea69ad949c31c065e7c4f7b4aaa93 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 12:57:41 -0500 Subject: [PATCH 066/291] Fix layer exclusion track refit algo. --- .../jlab/rec/cvt/services/RecUtilities.java | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index c5fead625..b7801698f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.services; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -25,6 +26,7 @@ import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.TrackCandListFinder; import org.jlab.rec.cvt.track.TrackSeeder; +import org.jlab.rec.cvt.track.TrackSeederCA; /** * Service to return reconstructed TRACKS @@ -104,7 +106,7 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge if(trkcand.get_Clusters().get(i).get_Layer()%2==1) thickn_ov_X0 = org.jlab.rec.cvt.svt.Constants.SILICONTHICK / org.jlab.rec.cvt.svt.Constants.SILICONRADLEN; meas.setl_over_X0(thickn_ov_X0); - if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) + if((int)Constants.getLayersUsed().get(meas.getLayer())<1) meas.notUsedInFit=true; if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; @@ -142,8 +144,8 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); - if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) { - //System.out.println("Exluding layer "+meas.getLayer()); + if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); meas.notUsedInFit=true; } if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) @@ -164,8 +166,8 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge //for multiple scattering double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; meas.setl_over_X0(thickn_ov_X0); - if(Constants.getLayersUsed().get(meas.getLayer())==(Integer)0) { - //System.out.println("Exluding layer "+meas.getLayer()); + if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); meas.notUsedInFit=true; } if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) @@ -365,53 +367,60 @@ public Track OutputTrack(Seed seed) { } - public List reFit(List seedlist,org.jlab.rec.cvt.svt.Geometry svt_geo, - Swim swimmer, TrackSeeder trkseedr) { + public List reFit(List seedlist, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { List filtlist = new ArrayList(); if(seedlist==null) return filtlist; for (Seed bseed : seedlist) { if(bseed == null) continue; - if(this.reFit(bseed, svt_geo, swimmer, trkseedr) == true) { - filtlist.add(bseed); + List fseeds = this.reFitSeed(bseed, SVTGeom, BMTGeom, swimmer, trseed, trseed2); + if(fseeds!=null) { + filtlist.addAll(fseeds); } } return filtlist; } - public boolean reFit(Seed bseed, - org.jlab.rec.cvt.svt.Geometry svt_geo, - Swim swimmer, TrackSeeder trkseedr) { + public List reFitSeed(Seed bseed, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { boolean pass = true; - + + List seedlist = new ArrayList(); + List refib = new ArrayList(); List refi = new ArrayList(); for(Cross c : bseed.get_Crosses()) { int layr = 0; int layr2 = 0; if(c.get_Detector().equalsIgnoreCase("BMT")) { - layr = c.get_Cluster1().get_Layer()+6; - if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0) - refi.add(c); + layr = c.getOrderedRegion()+3; + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + c.isInSeed = false; + // System.out.println("refit "+c.printInfo()); + refib.add(c); + } } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0 - && org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)!=(Integer)0) - refi.add(c); - } - } - Track cand = null; - if(refi.size()>=3) { - cand = trkseedr.fitSeed(refi, svt_geo, 5, false, swimmer); - if(cand!=null && cand.get_helix()!=null) { - bseed.set_Helix(cand.get_helix()); - } else { - pass = false; + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 + && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + c.set_CrossParamsSVT(null, SVTGeom); + c.isInSeed = false; + // System.out.println("refit "+c.printInfo()); + refi.add(c); + } } - } else { - pass = false; } - return pass; + Collections.sort(refi); + seedlist = trseed.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer); + trseed2.unUsedHitsOnly = true; + seedlist.addAll( trseed2.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer)); + + return seedlist; } public List reFit(List seedlist, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { @@ -434,14 +443,14 @@ public boolean reFit(StraightTrack cand, CosmicFitter fitTrk, TrackCandListFind int layr = 0; int layr2 = 0; if(c.get_Detector().equalsIgnoreCase("BMT")) { - layr = c.get_Cluster1().get_Layer()+6; - if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0) + layr = c.getOrderedRegion()+3; + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) refi.add(c); } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if(org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)!=(Integer)0 - && org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)!=(Integer)0) + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 + && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) refi.add(c); } } From c378546b66ae8ce4afe34a3b0528bf1418f3fb92 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 12:57:57 -0500 Subject: [PATCH 067/291] Fix layer exclusion track refit algo. --- .../org/jlab/rec/cvt/services/TracksFromTargetRec.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index ffe7fa8c4..0248ec790 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -45,7 +45,7 @@ public boolean processEvent(DataEvent event, RecoBankWriter rbc, double shift, Swim swimmer, - boolean isSVTonly) { + boolean isSVTonly, boolean exLayrs) { // make list of crosses consistent with a track candidate List seeds = null; @@ -59,17 +59,17 @@ public boolean processEvent(DataEvent event, TrackSeeder trseed = new TrackSeeder(); trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null, SVTGeom, BMTGeom, swimmer); - - seeds = recUtil.reFit(seeds, SVTGeom, swimmer, trseed); } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA + TrackSeeder trseed2 = new TrackSeeder(); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); - - seeds = recUtil.reFit(seeds, SVTGeom, swimmer, trseed2); + if(exLayrs==true) { + seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); + } } } if(seeds ==null || seeds.size() == 0) { From 7ab03a255b0ab37b24ab25909bfd575558ef5442 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 12:59:29 -0500 Subject: [PATCH 068/291] Fix CA bug using new BMT geometry. --- .../cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 558d48c26..ac84125fc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -152,7 +152,7 @@ public void createCells( List crs, BMTGeometry bgeom ){ else{ double aphi = a.get_Point().toVector3D().phi() ; //if( ! bgeom.checkIsInSector( aphi, b.get_Sector(), 1, Math.toRadians(10) ) ) { - if(bgeom.getSector(b.get_Region()*2, aphi)>0) { + if(bgeom.getSector(b.get_Region()*2, aphi)==0) { if( this._debug) System.out.println("cross b and a are not in the same sector"); continue; } From e5c6eecc59d3c86e32558f833dcb397adc90a7ad Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 13:01:37 -0500 Subject: [PATCH 069/291] Check cross size >0 to start fitter. --- .../src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 64cecf051..ffe604961 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -219,7 +219,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, List svt_crosses = new ArrayList(); List bmtC_crosses = new ArrayList(); - if(bmt_crosses!=null) { + if(bmt_crosses!=null && bmt_crosses.size()>0) { for(Cross c : bmt_crosses) { if(c.get_DetectorType()==BMTType.Z) { if(this.unUsedHitsOnly == false) { @@ -241,7 +241,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, } } } - if(bst_crosses!=null) { + if(bst_crosses!=null && bst_crosses.size()>0) { for(Cross c : bst_crosses) { if(this.unUsedHitsOnly == false) { svt_crosses.add(c); @@ -358,7 +358,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, } } - for (Seed bseed : seedlist) { + for (Seed bseed : seedlist) { for(Cross c : bseed.get_Crosses()) { c.isInSeed = true; } From 417950ef2e4ddcdc7c9d6c78ec77f7362323f91f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 13:02:22 -0500 Subject: [PATCH 070/291] Remove debug statement. --- .../main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index 9dead28a1..cf9c38c96 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -178,8 +178,7 @@ public List findCandidateCrossLists(List clusters = new ArrayList(); - System.out.println(" seed crosses "); - for(Cross c : s ) { System.out.println(" --> "+c.printInfo()); + for(Cross c : s ) { if(c.get_Detector().equalsIgnoreCase("SVT")) { c.get_Cluster1().set_CentroidError(this.calcCentErr(c, c.get_Cluster1(), svt_geo)); c.get_Cluster2().set_CentroidError(this.calcCentErr(c, c.get_Cluster2(), svt_geo)); From 515ad27eca7a376ecf42c3051ae73b549c9c7ba9 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 18:02:27 -0500 Subject: [PATCH 071/291] Added layer exclusion reconstruction for zero field. --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 2 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 2 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 6 +- .../rec/cvt/services/CosmicTracksRec.java | 10 +- .../jlab/rec/cvt/services/RecUtilities.java | 99 +++++++++++++++---- .../rec/cvt/services/TracksFromTargetRec.java | 4 + .../rec/cvt/track/StraightTrackSeeder.java | 1 - 7 files changed, 99 insertions(+), 25 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 1d920de02..59cc656fe 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -234,7 +234,7 @@ public double getPhi(int layer, int sector) { if (det == BMTType.C) phi = Constants.getCRCPHI()[region-1][sector-1]; else if(det == BMTType.Z) phi = Constants.getCRZPHI()[region-1][sector-1]; } - else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"); + else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); return phi; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 8fd45dc9e..1f18568a3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -402,7 +402,7 @@ public String toString() { public String printInfo() { String s = " cross: " + this.get_Detector() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + " Region " + this.get_Region() - + " Point " + this.get_Point().toString() + + " Point " + this.get_Point().toString()+ " Point0 " + this.get_Point0().toString() + " sort "+this.getOrderedRegion(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 917dde783..5238ca7e6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -215,11 +215,13 @@ public boolean processDataEvent(DataEvent event) { crosses_svtOnly.add(0, crosses.get(0)); crosses_svtOnly.add(1, new ArrayList()); } - strgtTrksRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, SVTGeom, BMTGeom, rbc, shift); + strgtTrksRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, + crosses, SVTGeom, BMTGeom, rbc, shift, this.exclLayrs); } else { trksFromTargetRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, shift, swimmer, this.isSVTonly, this.exclLayrs); + crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, shift, swimmer, + this.isSVTonly, this.exclLayrs); } return true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index dfee1dfbc..423477d0e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -34,7 +34,7 @@ public boolean processEvent(DataEvent event, List> crosses, org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, RecoBankWriter rbc, - double zShift) { + double zShift, boolean exLayrs) { // make list of crosses consistent with a track candidate CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, @@ -57,8 +57,12 @@ public boolean processEvent(DataEvent event, return true; } - CosmicFitter fitTrk = new CosmicFitter(); - cosmics = recUtil.reFit(cosmics, fitTrk, trkcandFinder); + + + if(exLayrs==true) { + CosmicFitter fitTrk = new CosmicFitter(); + cosmics = recUtil.reFit(cosmics, SVTGeom, fitTrk, trkcandFinder); + } if (cosmics.size() > 0) { for (int k1 = 0; k1 < cosmics.size(); k1++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index b7801698f..3075744d8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -24,6 +24,7 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.track.StraightTrack; +import org.jlab.rec.cvt.track.StraightTrackSeeder; import org.jlab.rec.cvt.track.TrackCandListFinder; import org.jlab.rec.cvt.track.TrackSeeder; import org.jlab.rec.cvt.track.TrackSeederCA; @@ -367,6 +368,58 @@ public Track OutputTrack(Seed seed) { } + public List reFit(List seedlist, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + Swim swimmer, StraightTrackSeeder trseed) { + List filtlist = new ArrayList(); + if(seedlist==null) + return filtlist; + for (Seed bseed : seedlist) { + if(bseed == null) + continue; + List fseeds = this.reFitSeed(bseed, SVTGeom, BMTGeom, trseed); + if(fseeds!=null) { + filtlist.addAll(fseeds); + } + } + return filtlist; + } + + public List reFitSeed(Seed bseed, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + StraightTrackSeeder trseed) { + + List seedlist = new ArrayList(); + List refib = new ArrayList(); + List refi = new ArrayList(); + for(Cross c : bseed.get_Crosses()) { + int layr = 0; + int layr2 = 0; + if(c.get_Detector().equalsIgnoreCase("BMT")) { + layr = c.getOrderedRegion()+3; + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + c.isInSeed = false; + // System.out.println("refit "+c.printInfo()); + refib.add(c); + } + } else { + layr = c.get_Cluster1().get_Layer(); + layr2 = c.get_Cluster2().get_Layer(); + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 + && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + c.set_CrossParamsSVT(null, SVTGeom); + c.isInSeed = false; + refi.add(c); + } + } + } + Collections.sort(refi); + seedlist.addAll(trseed.findSeed(refi, refib, SVTGeom, BMTGeom, false)); + return seedlist; + } + public List reFit(List seedlist, org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, @@ -423,38 +476,54 @@ public List reFitSeed(Seed bseed, return seedlist; } - public List reFit(List seedlist, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + public List reFit(List seedlist, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + CosmicFitter fitTrk, TrackCandListFinder trkfindr) { List filtlist = new ArrayList(); if(seedlist==null) return filtlist; for (StraightTrack bseed : seedlist) { - if(this.reFit(bseed, fitTrk, trkfindr) == true) { - filtlist.add(bseed); + if(bseed == null) + continue; + List fseeds = this.reFitSeed(bseed, SVTGeom, fitTrk, trkfindr); + if(fseeds!=null) { + filtlist.addAll(fseeds); } } return filtlist; } - public boolean reFit(StraightTrack cand, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + + public List reFitSeed(StraightTrack cand, + org.jlab.rec.cvt.svt.Geometry SVTGeom, + CosmicFitter fitTrk, TrackCandListFinder trkfindr) { boolean pass = true; + + List seedlist = new ArrayList(); + List refib = new ArrayList(); List refi = new ArrayList(); - List crosses = cand; - for(Cross c : crosses) { + for(Cross c : cand) { int layr = 0; int layr2 = 0; if(c.get_Detector().equalsIgnoreCase("BMT")) { layr = c.getOrderedRegion()+3; - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) - refi.add(c); + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + c.isInSeed = false; + // System.out.println("refit "+c.printInfo()); + refib.add(c); + } } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 - && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) - refi.add(c); + && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + c.set_CrossParamsSVT(null, SVTGeom); + c.isInSeed = false; + // System.out.println("refit "+c.printInfo()); + refi.add(c); + } } } - if(refi.size()>=3) { TrackCandListFinder.RayMeasurements NewMeasArrays = trkfindr. get_RayMeasurementsArrays((ArrayList) refi, false, false); @@ -463,13 +532,9 @@ public boolean reFit(StraightTrack cand, CosmicFitter fitTrk, TrackCandListFind NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); if(fitTrk.get_ray()!=null) { cand = new StraightTrack(fitTrk.get_ray()); - } else { - pass = false; + seedlist.add(cand); } - } else { - pass = false; } - return pass; + return seedlist; } - } \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 0248ec790..8a508ea9f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -52,6 +52,9 @@ public boolean processEvent(DataEvent event, if(Math.abs(Constants.getSolenoidVal())<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(); seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, isSVTonly); + if(exLayrs==true) { + seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed); + } //TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder //seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); } else { @@ -102,6 +105,7 @@ public boolean processEvent(DataEvent event, charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); Matrix cov = seed.get_Helix().get_covmatrix(); + if(Math.abs(Constants.getSolenoidVal())>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *Constants.getSolenoidVal() findSeed(List svt_crosses, List bmt_crosses, } } } - return seedlist; } From cf1376e6cc2e1e0004c4c916c40da590aa001581 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 21 Jan 2021 18:05:15 -0500 Subject: [PATCH 072/291] NDF initialization fix in KF. --- .../jlab/clas/tracking/kalmanfilter/helical/KFitter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index d4c30de85..ffeabd78e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -80,16 +80,20 @@ public void init(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double sv.X0.add(Xb); sv.Y0.add(Yb); sv.Z0.add(0.0); + this.NDF = -5; for (int i = 1; i < mv.measurements.size(); i++) { sv.Layer.add(mv.measurements.get(i).layer); sv.Sector.add(mv.measurements.get(i).sector); + if(mv.measurements.get(i).skip==false) { + this.NDF++; + } Point3D ref = new Point3D(Xb, Yb, 0.0); sv.X0.add(ref.x()); sv.Y0.add(ref.y()); sv.Z0.add(ref.z()); } sv.init( helix, cov, this, swimmer); - this.NDF = mv.measurements.size()-6; + } /** From 263a6bf78ff0d2c83201f4bcf15aff6d2c45e354 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Fri, 22 Jan 2021 11:36:29 -0500 Subject: [PATCH 073/291] Fix reading layer exclusion flag. --- .../main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 5238ca7e6..dcd49d7fc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -279,7 +279,7 @@ public boolean init() { if (svtCosmics==null) { System.out.println("["+this.getName()+"] run with cosmics settings default = false"); } - + //all layers used --> 1 for(int i = 0; i < 12; i++) Constants.getLayersUsed().put(i+1, 1); @@ -300,7 +300,7 @@ public boolean init() { String exlys = String.valueOf(exLys); String[] values = exlys.split(","); for(int k = 0; k < values.length; k++) - Constants.getLayersUsed().put(Integer.valueOf(values[k]), 0); + Constants.getLayersUsed().put(Integer.valueOf(values[k]), 0);// layer excluded --->0 } } if (exLys==null) { @@ -309,7 +309,10 @@ public boolean init() { int exlyrsnb = 0; for(int ilayrs = 0; ilayrs<12; ilayrs++) { - exlyrsnb+=(int)org.jlab.rec.cvt.Constants.getLayersUsed().get(ilayrs+1); + if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(ilayrs+1)<1) { + System.out.println("EXCLUDE CVT LAYER "+(ilayrs+1)); + exlyrsnb++; + } } if(exlyrsnb>0) exclLayrs = true; From 32f240dc2b71379b1b8115c9f1481584bd78d1b0 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 26 Jan 2021 21:33:40 +0100 Subject: [PATCH 074/291] BG merging: removed ADC>0 constrain for BST and BMT --- .../main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java index b5bea148c..5f998412c 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java @@ -59,7 +59,7 @@ public List ADCbank(String detector,DataBank bankDGTZ) { int adc = bankDGTZ.getInt("ADC", i); float time = bankDGTZ.getFloat("time", i); short ped = bankDGTZ.getShort("ped", i); - if(adc<=0) continue; + if(adc<=0 && !(detector == DetectorType.BST.getName() || detector == DetectorType.BMT.getName())) continue; if(detector == DetectorType.BST.getName()) { long timestamp = (int)bankDGTZ.getLong("timestamp", i); adcData = new ADC(sector,layer,component,order,adc,time,ped,timestamp); From 77cac149e97828860a309a94e78e3ed890262f0a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 27 Jan 2021 10:23:40 +0100 Subject: [PATCH 075/291] BG merging: removed ADC>0 constrain for BST and BMT, bug fix --- .../jlab/analysis/eventmerger/ADCTDCMerger.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java index 5f998412c..cfe8e71f2 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/eventmerger/ADCTDCMerger.java @@ -59,17 +59,23 @@ public List ADCbank(String detector,DataBank bankDGTZ) { int adc = bankDGTZ.getInt("ADC", i); float time = bankDGTZ.getFloat("time", i); short ped = bankDGTZ.getShort("ped", i); - if(adc<=0 && !(detector == DetectorType.BST.getName() || detector == DetectorType.BMT.getName())) continue; - if(detector == DetectorType.BST.getName()) { + + if(adc<=0) + if(!detector.equals(DetectorType.BST.getName()) && !detector.equals(DetectorType.BMT.getName())) + continue; + + if(detector.equals(DetectorType.BST.getName())) { long timestamp = (int)bankDGTZ.getLong("timestamp", i); adcData = new ADC(sector,layer,component,order,adc,time,ped,timestamp); } - else if(detector == DetectorType.BMT.getName() || detector==DetectorType.FMT.getName() || detector==DetectorType.FTTRK.getName()) { + else if(detector.equals(DetectorType.BMT.getName()) || + detector.equals(DetectorType.FMT.getName()) || + detector.equals(DetectorType.FTTRK.getName())) { long timestamp = (int)bankDGTZ.getLong("timestamp", i); int integral = bankDGTZ.getInt("integral", i); adcData = new ADC(sector,layer,component,order,adc,time,ped,timestamp,integral); } - else if(detector == DetectorType.BAND.getName()) { + else if(detector.equals(DetectorType.BAND.getName())) { int amplitude = bankDGTZ.getInt("amplitude", i); adcData = new ADC(sector,layer,component,order,adc,time,ped,amplitude); } @@ -78,6 +84,7 @@ else if(detector == DetectorType.BAND.getName()) { } adcStore.add(adcData); } + if(debug) System.out.println("Reading bank " + detector + "::adc with " + bankDGTZ.rows() + ", collected " + adcStore.size() + " hits"); return adcStore; } From c8ba83077516125d038b3a9d208446a29826ea8e Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 28 Jan 2021 10:37:12 -0500 Subject: [PATCH 076/291] Fix Seeder algorithm loop. --- .../main/java/org/jlab/rec/cvt/services/RecUtilities.java | 4 ++-- .../java/org/jlab/rec/cvt/track/StraightTrackSeeder.java | 8 ++++---- .../src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 3075744d8..7088d43f7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -401,7 +401,7 @@ public List reFitSeed(Seed bseed, layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; - // System.out.println("refit "+c.printInfo()); + //System.out.println("refit "+c.printInfo()); refib.add(c); } } else { @@ -409,7 +409,7 @@ public List reFitSeed(Seed bseed, layr2 = c.get_Cluster2().get_Layer(); if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { - c.set_CrossParamsSVT(null, SVTGeom); + c.set_CrossParamsSVT(null, SVTGeom); c.isInSeed = false; refi.add(c); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index d9dbadc77..03f88e45f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -222,7 +222,8 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); public List findSeed(List svt_crosses, List bmt_crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean isSVTOnly) { - + BMTmatches.clear(); + seedScan.clear() ; List seedlist = new ArrayList(); List crosses = new ArrayList(); @@ -337,13 +338,12 @@ public List findSeed(List svt_crosses, List bmt_crosses, seed.set_Crosses(bseed.get_Crosses()); seed.set_Clusters(bseed.get_Clusters()); seed.set_Helix(bcand.get_helix()); - List seedcrs2 = seed.get_Crosses(); } } seedlist.add(seed); - } else { // no bmt - seedlist.add(seed); + } else { + // seedlist.add(seed); System.out.println("no BMT matched"+seed.get_Helix().get_Z0()); } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index ffe604961..e18a4cd62 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -353,7 +353,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, seedlist.add(seed); } else { // no bmt - seedlist.add(seed); + // seedlist.add(seed); } } } From 5cdf80da8e0e99b36746cd1d29d7d5a40fe5d7cf Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 8 Feb 2021 18:02:29 -0500 Subject: [PATCH 077/291] Fix for Cosmic reconstruction. Update getLayer method in BMTGeometry to take into account the midDrift. --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 6 ++-- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 32 +++++++++---------- .../java/org/jlab/rec/cvt/cross/Cross.java | 2 -- .../cross/StraightTrackCrossListFinder.java | 8 ++--- .../org/jlab/rec/cvt/fit/CosmicFitter.java | 2 ++ .../jlab/rec/cvt/services/CVTRecNewKF.java | 2 -- .../rec/cvt/services/CosmicTracksRec.java | 6 ++-- .../jlab/rec/cvt/services/RecUtilities.java | 2 +- .../java/org/jlab/rec/cvt/svt/Geometry.java | 3 +- .../rec/cvt/track/TrackCandListFinder.java | 7 ++-- .../java/org/jlab/rec/cvt/trajectory/Ray.java | 3 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 20 ++++++------ 12 files changed, 44 insertions(+), 49 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 8e75e9591..846ada1de 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -430,8 +430,8 @@ public DataBank fillStraightTracksBank(DataEvent event, bank.setShort("ID", i, (short) cosmics.get(i).get_Id()); - bank.setFloat("chi2", i, (float) cosmics.get(i).get_chi2()); - bank.setShort("ndf", i, (short) cosmics.get(i).get_ndf()); + bank.setFloat("chi2", i, (float) cosmics.get(i).get_ray().chi2); + bank.setShort("ndf", i, (short) (cosmics.get(i).size()-2)); bank.setFloat("trkline_yx_slope", i, (float) cosmics.get(i).get_ray().get_yxslope()); bank.setFloat("trkline_yx_interc", i, (float) (cosmics.get(i).get_ray().get_yxinterc()/10.)); bank.setFloat("trkline_yz_slope", i, (float) cosmics.get(i).get_ray().get_yzslope()); @@ -442,11 +442,9 @@ public DataBank fillStraightTracksBank(DataEvent event, // calculate the theta and phi components of the ray direction vector in degrees bank.setFloat("theta", i, (float) Math.toDegrees(u.theta())); bank.setFloat("phi", i, (float) Math.toDegrees(u.phi())); - // the array of cross ids is filled in order of the SVT cosmic region 1 to 8 starting from the bottom-most double layer for (int j = 0; j < cosmics.get(i).size(); j++) { crossIdxArray.add(cosmics.get(i).get(j).get_Id()); - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 59cc656fe..2d74d0234 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -12,6 +12,7 @@ import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; +import org.jlab.rec.cvt.services.CVTRecNewKF; /** * @@ -234,7 +235,7 @@ public double getPhi(int layer, int sector) { if (det == BMTType.C) phi = Constants.getCRCPHI()[region-1][sector-1]; else if(det == BMTType.Z) phi = Constants.getCRZPHI()[region-1][sector-1]; } - else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); + else System.out.println("ERROR: out of range inputs in getPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); return phi; } @@ -255,7 +256,8 @@ public double getDPhi(int layer, int sector) { if (det == BMTType.C) dphi = Constants.getCRCDPHI()[region-1][sector-1]; else if(det == BMTType.Z) dphi = Constants.getCRZDPHI()[region-1][sector-1]; } - else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"); + else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); + return dphi; } @@ -464,7 +466,6 @@ public Arc3D getCstrip(int region, int sector, int strip) { * @return sector [1-3] (not) accounting for dead areas if layer (0) [1-6] or 0 if layer is undefined */ public int getSector(int layer, double angle) { - boolean full = false; if(layer==0) { full = true; @@ -473,12 +474,12 @@ public int getSector(int layer, double angle) { int region = this.getRegion(layer); Vector3D vec = new Vector3D(Math.cos(angle),Math.sin(angle),0); - + if(Double.isNaN(angle)) vec = null; int sector = 0; double width = 0.5; // Math.cos(60deg); double delta = -1; for (int i = 0; i < Constants.NSECTORS; i++) { - double phi = this.getPhi(layer, i+1); + double phi = this.getPhi(layer, i+1); Vector3D center = new Vector3D(Math.cos(phi),Math.sin(phi),0); double dcosphi = center.dot(vec); if(dcosphi>width) { @@ -488,7 +489,7 @@ public int getSector(int layer, double angle) { } if(!full) { if(delta0 && layer<=Constants.NLAYERS && sector>0 && sector<=Constants.NSECTORS) { - Point3D offset = this.getOffset(layer, sector); + Point3D offset = this.getOffset(layer, sector); Vector3D rotation = this.getRotation(layer, sector); traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); traj.rotateZ(-rotation.z()); traj.rotateY(-rotation.y()); traj.rotateX(-rotation.x()); - if(traj.z()>this.getZmin(layer) && traj.z()0 && sector>0) strip = getStrip(layer,sector,traj); return strip; @@ -880,7 +880,7 @@ public static void main (String arg[]) { double z = Math.random()*(zmax-zmin)+zmin; double phi = Math.random()*2*Math.PI; Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - if(i!=newGeo.getLayer(traj)) System.out.println("Error in getLayer"); + if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); if(newGeo.inDetector(i, newGeo.getSector(i, phi), traj)) hi_acc.fill(z, Math.toDegrees(phi)); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 1f18568a3..e7a91ada9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -566,10 +566,8 @@ public static void main(String arg[]) { // check that the correct lists are created for (int i = 0; i < theListsByRegion.size(); i++) { - System.out.println(" i " + i); for (int j = 0; j < theListsByRegion.get(i).size(); j++) { Cross c = theListsByRegion.get(i).get(j); - System.out.println(c.get_Detector() + " " + c.get_Region() + " " + c.get_Point0().toVector3D().phi()); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index b5c79db64..929a99378 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -453,13 +453,13 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); - cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); + cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D1); if (t[3] != t[1] && t[2] != t[0]) { //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); - cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); + cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D2); } this.calcBMT2DPoint(yxslope, @@ -467,13 +467,13 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); - cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); + cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D3); if (t[3] != t[1] && t[2] != t[0]) { //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); - cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); + cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D4); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java index c7b2eded0..06a966faa 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java @@ -6,6 +6,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.trajectory.Ray; +import trackfitter.fitter.utilities.ProbChi2perNDF; /** * A fitter which does sequential fit (for x, y coordinates) and then (for r, z @@ -124,6 +125,7 @@ public FitStatus fit(List X, List Y, List Z, List cosmics = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); @@ -58,7 +57,6 @@ public boolean processEvent(DataEvent event, return true; } - if(exLayrs==true) { CosmicFitter fitTrk = new CosmicFitter(); cosmics = recUtil.reFit(cosmics, SVTGeom, fitTrk, trkcandFinder); @@ -67,7 +65,7 @@ public boolean processEvent(DataEvent event, if (cosmics.size() > 0) { for (int k1 = 0; k1 < cosmics.size(); k1++) { cosmics.get(k1).set_Id(k1 + 1); - for (int k2 = 0; k2 < cosmics.get(k1).size(); k2++) { + for (int k2 = 0; k2 < cosmics.get(k1).size(); k2++) { cosmics.get(k1).get(k2).set_AssociatedTrackID(cosmics.get(k1).get_Id()); // associate crosses if (cosmics.get(k1).get(k2).get_Cluster1() != null) { cosmics.get(k1).get(k2).get_Cluster1().set_AssociatedTrackID(cosmics.get(k1).get_Id()); // associate cluster1 in cross diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 7088d43f7..8db0f2b9a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -237,7 +237,6 @@ public Map FindClustersOnTrk (List allClusters, Helix } if(Math.abs(clsDoca) reFitSeed(StraightTrack cand, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); if(fitTrk.get_ray()!=null) { cand = new StraightTrack(fitTrk.get_ray()); + cand.addAll(refi); seedlist.add(cand); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java index 5c7f5642f..768d35fac 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java @@ -78,8 +78,7 @@ public Point3D getPlaneModuleOrigin(int sector, int layer) { //System.out.println(" GET MODULE O "+labFrameLine.origin().toString()); //System.out.println(" GET MODULE 1 "+SVTConstants.getDataAlignmentSectorShift()[SVTConstants.convertRegionSector2Index( rm[0],sector-1)].toString()); //System.out.println(" GET MODULE 2 "+new Point3D(SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).x, SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).y, SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1).z).toString()); - if(SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1]==null) - System.out.println(" SHIFT ARRAY NULL FOR "+rm[0]+" sect "+(sector-1)); + AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index f261578b7..374124ec5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -807,7 +807,7 @@ public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thec } } } - } + } return BMTCrossList; } @@ -836,6 +836,7 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse y[0] = (-sx * ix + Math.sqrt(D)) / (1 + sx * sx); y[1] = (-sx * ix - Math.sqrt(D)) / (1 + sx * sx); } + for (int j = 0; j < y.length; j++) { double x = sx * y[j] + ix; double phi = Math.atan2(y[j], x); @@ -853,7 +854,7 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse if (MMCrosses.get(i).get_DetectorType()==BMTType.Z) { continue; } - double m_z = MMCrosses.get(i).get_Point().z(); + double m_z = MMCrosses.get(i).get_Point().z(); //int sector = geo.isInSector(MMCrosses.get(i).get_Region() * 2, phi, Math.toRadians(Constants.isInSectorJitter)); int sector = geo.getSector(MMCrosses.get(i).get_Region() * 2, phi); if (sector != MMCrosses.get(i).get_Sector()) { @@ -1049,7 +1050,7 @@ public void matchClusters(List sVTclusters, TrajectoryFinder tf, org.jl if(trajectory == null) return; Collections.sort(sVTclusters); - for (StateVec st : trajectory) { + for (StateVec st : trajectory) { for (Cluster cls : sVTclusters) { if (cls.get_AssociatedTrackID() != -1) { continue; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java index 971590f47..db7f0df8a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java @@ -16,7 +16,8 @@ public class Ray { private double _yzslopeErr; private double _yxintercErr; private double _yzintercErr; - + public double chi2; + public Ray(Point3D refPoint, Vector3D dirVec) { set_refPoint(refPoint); set_dirVec(dirVec); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index b46e5026e..d7971f12c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -599,7 +599,7 @@ private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.BMTGeomet result[l][h][3] = -999; result[l][h][4] = -999; } - } + } //Layer 1-6: for (int l = start_layer - 1; l < 6; l++) { double[][] trkIntersCombinedInf = this.getIntersectionTrackWithBMTModules(l, ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), bmt_geo); @@ -607,10 +607,13 @@ private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.BMTGeomet //hemisphere 1-2 for (int h = 0; h < 2; h++) { double[] trkIntersInf = trkIntersCombinedInf[0]; - + + if(Double.isNaN(trkIntersInf[0]) || Double.isNaN(trkIntersInf[1]) || Double.isNaN(trkIntersInf[2]) ) + continue; + Point3D p = new Point3D(trkIntersInf[0], trkIntersInf[1], trkIntersInf[2]); - if (p.toVector3D().mag() == 0) { + if (p.toVector3D().mag() == 0 ) { continue; } @@ -760,7 +763,6 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters_bottom[1] = Double.NaN; inters_bottom[2] = Double.NaN; inters_bottom[3] = Double.NaN; - double R = 0; if (BMTGeometry.getDetectorType(l + 1) == BMTType.C) { R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[l / 2] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; @@ -778,11 +780,10 @@ private double[][] getIntersectionTrackWithBMTModules(int l, double x_minus = _yxslope2 * y_minus + _yxinterc2; double z_plus = _yzslope2 * y_plus + _yzinterc2; - double z_minus = _yzslope2 * y_minus + _yzinterc2; - + double z_minus = _yzslope2 * y_minus + _yzinterc2; //if (geo.isInFiducial(x_plus, y_plus, z_plus, l + 1)) { - if(geo.inDetector(new Point3D(x_plus, y_plus, z_plus))) { - inters_top[0] = x_plus; + if(geo.inDetector(new Point3D(x_plus, y_plus, z_plus), org.jlab.rec.cvt.bmt.Constants.hStrip2Det)) { + inters_top[0] = x_plus; inters_top[1] = y_plus; inters_top[2] = z_plus; if (l % 2 == 1) { @@ -797,7 +798,7 @@ private double[][] getIntersectionTrackWithBMTModules(int l, } } //if (geo.isInFiducial(x_minus, y_minus, z_minus, l + 1)) { - if(geo.inDetector(new Point3D(x_minus, y_minus, z_minus))) { + if(geo.inDetector(new Point3D(x_minus, y_minus, z_minus), org.jlab.rec.cvt.bmt.Constants.hStrip2Det)) { inters_bottom[0] = x_minus; inters_bottom[1] = y_minus; inters_bottom[2] = z_minus; @@ -815,7 +816,6 @@ private double[][] getIntersectionTrackWithBMTModules(int l, inters[1] = inters_top; inters[0] = inters_bottom; - return inters; } From da08ab19b293c275c2b688c5ef2367163d7953f1 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 9 Feb 2021 13:36:04 -0500 Subject: [PATCH 078/291] Fix thread safety issue for cosmics. --- .../main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 841fe3d20..a8aa6d664 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -24,8 +24,6 @@ public class CosmicTracksRec { - private StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); - private RecUtilities recUtil = new RecUtilities(); public boolean processEvent(DataEvent event, @@ -36,6 +34,7 @@ public boolean processEvent(DataEvent event, RecoBankWriter rbc, double zShift, boolean exLayrs) { // make list of crosses consistent with a track candidate + StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, BMTGeom, 3); if (crosslist == null || crosslist.size() == 0) { From bd7a4a2d52b883cf5b2bb9fb9fb721951d2e3b42 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 24 Feb 2021 20:16:03 -0500 Subject: [PATCH 079/291] Fix for layer exclusion in track refitting. --- .../main/java/org/jlab/rec/cvt/services/RecUtilities.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 8db0f2b9a..5548141b2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -423,6 +423,8 @@ public List reFit(List seedlist, org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { + trseed = new TrackSeederCA(); + trseed2 = new TrackSeeder(); List filtlist = new ArrayList(); if(seedlist==null) return filtlist; @@ -452,7 +454,7 @@ public List reFitSeed(Seed bseed, layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; - // System.out.println("refit "+c.printInfo()); + //System.out.println("refit BMT "+c.printInfo()); refib.add(c); } } else { @@ -478,6 +480,8 @@ public List reFitSeed(Seed bseed, public List reFit(List seedlist, org.jlab.rec.cvt.svt.Geometry SVTGeom, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + fitTrk = new CosmicFitter(); + trkfindr = new TrackCandListFinder(); List filtlist = new ArrayList(); if(seedlist==null) return filtlist; From be4a66208396ea21c10a5d55e9c4f3dc67b370e8 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 24 Feb 2021 20:16:31 -0500 Subject: [PATCH 080/291] getDPhi error fix. --- .../cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java index 768d35fac..366526288 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java @@ -514,10 +514,9 @@ public double getDOCAToStrip(int sector, int layer, double centroidstrip, Point3 Vector3D r = LocPoint.vectorTo(pointOnStrip); // Vector3D d = r.cross(vecAlongStrip); - Line3D l = new Line3D(pointOnStrip, - pointOnStrip.toVector3D().add(vecAlongStrip.multiply(10))); - //fix for hemisphere + vecAlongStrip ); +//fix for hemisphere return d.y()*Math.signum(this.findBSTPlaneNormal(sector, layer).y()); } From 3e01b2781b993b6573a6b246c8fdee92c57a17e5 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 24 Feb 2021 20:17:44 -0500 Subject: [PATCH 081/291] getDPhi error fix. --- .../cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 2d74d0234..fc17c23ce 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -488,7 +488,8 @@ public int getSector(int layer, double angle) { } } if(!full) { - if(delta Date: Wed, 24 Feb 2021 20:18:07 -0500 Subject: [PATCH 082/291] getDPhi error fix. --- .../cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index e18a4cd62..ff0e4a147 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -627,7 +627,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt. //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) // != bmt_Ccross.get_Sector()) int sector = bmt_geo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); - if(sector!= bmt_Ccross.get_Sector()){ + if(sector!= bmt_Ccross.get_Sector() || sector ==0){ return false; } double dzdr_bmt = z_bmt / r_bmt; From b0b7c5db419023ba8a192a9f8c840838b3ce691a Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 24 Feb 2021 20:20:28 -0500 Subject: [PATCH 083/291] modified straight track algorithm. --- .../cross/StraightTrackCrossListFinder.java | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index 929a99378..40a5f8715 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -2,7 +2,9 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -264,23 +266,68 @@ private boolean regionUniquenessFlag(ArrayList crossList) { public CrossList findCosmicsCandidateCrossLists(List> crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { + CrossList crossLists = new CrossList(); // start finding svt crosses ArrayList svt_crosses = crosses.get(0); // if there are no svt crosses then return - there is no track if (svt_crosses.size() == 0) { return null; } - + + Map svtMap = new HashMap>(); + for(Cross c : svt_crosses) { + if(svtMap.containsKey(c.get_Region())==false) { + ArrayList list = new ArrayList(); + list.add(c); + svtMap.put(c.get_Region(), list); + } else { + ArrayList list = (ArrayList) svtMap.get(c.get_Region()); + list.add(c); + } + } + + int L[] = new int[3]; + for(int i = 0; i<3; i++) { + if(svtMap.containsKey(i+1)==true) { + L[i]++; + } + } + for(int i = 0; i<3; i++) { + if(L[i]==0) + L[i]=1; + } + for(int i1 = 0; i1 list = new ArrayList(); + if(svtMap.containsKey(1)==true) { + ArrayList list1 = (ArrayList) svtMap.get(1); + list.add(list1.get(i1)); + } + if(svtMap.containsKey(2)==true) { + ArrayList list1 = (ArrayList) svtMap.get(2); + list.add(list1.get(i2)); + } + if(svtMap.containsKey(3)==true) { + ArrayList list1 = (ArrayList) svtMap.get(3); + list.add(list1.get(i3)); + } + crossLists.addAll(this.findTrackSeeds(list)); + } + } + } // first look for seeds - CrossList crossLists = this.findTrackSeeds(svt_crosses); - + //CrossList crossLists = this.findTrackSeeds(svt_crosses); + // instantiate the resulting crosslist CrossList crossListFinal = new CrossList(); ArrayList> newCrossLists = new ArrayList>(); // loop over the list of crosslists for (int i = 0; i < crossLists.size(); i++) { - if (crossLists.get(i).size() > 0) { + if (crossLists.get(i).size() > 0) {System.out.println("In list :"); + for(Cross c : crossLists.get(i)) + System.out.println("In :"+c.printInfo()); ArrayList crossList = new ArrayList(); // find the trajectory for each crosslist ArrayList TrajPoints = get_XYTrajectory(crossLists.get(i), svt_geo, bmt_geo, NbSVTRegions); @@ -340,6 +387,10 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, for (int k = 0; k < newCrossLists.size(); k++) { if (newCrossLists.get(k).size() != 0) { crossListFinal.add(newCrossLists.get(k)); + System.out.println("In list :"); + for(Cross c : newCrossLists.get(k)) + System.out.println("In :"+c.printInfo()); + } } return crossListFinal; From 1064c8b5ba2917034798affac83b7ed25bd3d3db Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 24 Feb 2021 20:20:57 -0500 Subject: [PATCH 084/291] Debugging statements (commented out). --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 2 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 2 +- .../rec/cvt/services/TracksFromTargetRec.java | 2 +- .../java/org/jlab/rec/cvt/svt/Constants.java | 1 - .../rec/cvt/track/TrackCandListFinder.java | 37 +++++++++++++------ .../rec/cvt/trajectory/TrajectoryFinder.java | 11 +++++- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 846ada1de..8f6eaabc9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -686,7 +686,7 @@ public void appendCVTCosmicsBanks(DataEvent event, //found trajectories DataBank bank8 = this.fillStraightTracksTrajectoryBank(event, trks, zShift); - if (bank8 != null) { + if (bank8 != null) { cvtbanks.add(bank8); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index e7a91ada9..740c754fe 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -403,7 +403,7 @@ public String toString() { public String printInfo() { String s = " cross: " + this.get_Detector() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + " Region " + this.get_Region() + " Point " + this.get_Point().toString()+ " Point0 " + this.get_Point0().toString() - + " sort "+this.getOrderedRegion(); + + " sort "+this.getOrderedRegion()+" cosmic region "+this.get_SVTCosmicsRegion(); return s; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 8a508ea9f..5fca29c62 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -86,7 +86,7 @@ public boolean processEvent(DataEvent event, for (Seed seed : seeds) { org.jlab.clas.tracking.trackrep.Helix hlx = null ; - + double xr = -seed.get_Helix().get_dca()*Math.sin(seed.get_Helix().get_phi_at_dca()); double yr = seed.get_Helix().get_dca()*Math.cos(seed.get_Helix().get_phi_at_dca()); double zr = seed.get_Helix().get_Z0(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java index 6b1a3f1cf..31ca2baa7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java @@ -213,7 +213,6 @@ public static synchronized void Load() { } LAYRGAP = MODULERADIUS[1][0] - MODULERADIUS[0][0]; - Geometry geo = new Geometry(); for(int l =0; l < NLAYR; l++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 374124ec5..89871b648 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -144,7 +144,7 @@ public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, or List list = cand.get_Crosses(); if (list.size() == 0) { - System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); + //System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); return; } // instantiating the Helical Track fitter @@ -397,7 +397,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List arrayList, boo ErrRt.add(j, (double) 1); } } - + for (int j = j0; j < j0 + BMTCdetcrossesInTrk.size(); j++) { Z.add(j, BMTCdetcrossesInTrk.get(j - j0).get_Point().z()); Y_prime.add(j, BMTCdetcrossesInTrk.get(j - j0).get_Point().y()); ErrY_prime.add(j, 0.); ErrZ.add(j, BMTCdetcrossesInTrk.get(j - j0).get_PointErr().z()); - } if (resetSVTMeas) { //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - for (int j = 0; j < SVTcrossesInTrk.size(); j++) { - X.add(j, SVTcrossesInTrk.get(j).get_Point0().x()); - Y.add(j, SVTcrossesInTrk.get(j).get_Point0().y()); - Z.add(j, SVTcrossesInTrk.get(j).get_Point0().z()); - ErrY_prime.add(j, SVTcrossesInTrk.get(j).get_Point0().y()); - ErrZ.add(j, SVTcrossesInTrk.get(j).get_PointErr0().z()); - } +// for (int j = 0; j < SVTcrossesInTrk.size(); j++) { +// X.add(j, SVTcrossesInTrk.get(j).get_Point0().x()); +// Y.add(j, SVTcrossesInTrk.get(j).get_Point0().y()); +// Z.add(j, SVTcrossesInTrk.get(j).get_Point0().z()); +// ErrY_prime.add(j, SVTcrossesInTrk.get(j).get_Point0().y()); +// ErrZ.add(j, SVTcrossesInTrk.get(j).get_PointErr0().z()); +// } } + if(BMTCdetcrossesInTrk.size()>1) { + //System.out.print("RESETTING MEAS ARRAY"); + Z.clear(); + Y_prime.clear(); + ErrZ.clear(); + ErrY_prime.clear(); + for (int j = 0; j < BMTCdetcrossesInTrk.size(); j++) { + Z.add(j, BMTCdetcrossesInTrk.get(j).get_Point().z()); + Y_prime.add(j, BMTCdetcrossesInTrk.get(j).get_Point().y()); + ErrY_prime.add(j, 0.); + ErrZ.add(j, BMTCdetcrossesInTrk.get(j).get_PointErr().z()); + + } + } RayMeasurements MeasArray = new RayMeasurements(X, Y, Z, Y_prime, ErrZ, ErrY_prime, ErrRt); return MeasArray; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index d7971f12c..e9e9ff971 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -11,6 +11,8 @@ import org.jlab.detector.hits.CTOFDetHit; import org.jlab.detector.hits.DetHit; import org.jlab.geom.base.Detector; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; @@ -534,13 +536,18 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, StateVec stVec, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal) { - +System.out.println("SETTING HIT RESOL..."); if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); double doca2Seed = svt_geo.getDOCAToStrip(sector, layer, (double) cluster.get_SeedStrip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); cluster.set_SeedResidual(doca2Seed); cluster.set_CentroidResidual(doca2Cls); - +// Point3D endPt1 = cluster.getEndPoint1(); +// Point3D endPt2 = cluster.getEndPoint2(); +// Line3D l = new Line3D(endPt1,endPt2); +// Plane3D pl = new Plane3D(endPt1, svt_geo.findBSTPlaneNormal(sector, layer)); +// double d = new Vector3D(stVec.x(), stVec.y(), stVec.z()).dot(pl.normal())-pl.point().toVector3D().dot(pl.normal()); +// System.out.println(d+" calc "+l.distance(new Point3D(stVec.x(), stVec.y(), stVec.z())).length()+" d "+doca2Cls); for (FittedHit hit : cluster) { double doca1 = svt_geo.getDOCAToStrip(sector, layer, (double) hit.get_Strip().get_Strip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); double sigma1 = svt_geo.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); From 6912b23efdac287308096ad62e813cad47e93046 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 11:43:36 -0500 Subject: [PATCH 085/291] Add Lorentz angle correction to define the pseudo C Strip for the BMT detector geometry. --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index fc17c23ce..97654d6b6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -353,6 +353,56 @@ public Line3D getZstrip(int region, int sector, int strip) { stripline.translateXYZ(offset.x(),offset.y(),offset.z()); + return stripline; + } + /** + * Returns Line3D for Z detector pseudostrip identified from region, sector, strip numbers, for ideal geometry + * After Loentz angle correction + * @param region + * @param sector + * @param strip + * @return Line3D + */ + public Line3D getIdealLCZstrip(int region, int sector, int strip) { + + double radius = Constants.getCRZRADIUS()[region-1]; + int layer = this.getLayer(region, BMTType.Z); + double zmin = Constants.getCRCZMIN()[region-1]; + double zmax = Constants.getCRCZMAX()[region-1]; + double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] + + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; + double theLorentzCorrectedAngle = angle + this.LorentzAngleCorr(layer,sector); + Point3D p1= new Point3D(radius, 0, zmin); + p1.rotateZ(theLorentzCorrectedAngle); + Point3D p2= new Point3D(radius, 0, zmax); + p2.rotateZ(angle); + + Line3D stripline = new Line3D(p1,p2); + + return stripline; + } + + /** + * Returns Line3D for Z detector pseudo-strip identified from region, sector, strip numbers, for real geometry + * After Lorentz angle correction + * @param region + * @param sector + * @param strip + * @return stripline + */ + public Line3D getLCZstrip(int region, int sector, int strip) { + + int layer = this.getLayer(region, BMTType.Z); + Line3D stripline = this.getIdealLCZstrip(region, sector, strip); + + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + stripline.rotateX(rotation.x()); + stripline.rotateY(rotation.y()); + stripline.rotateZ(rotation.z()); + stripline.translateXYZ(offset.x(),offset.y(),offset.z()); + + return stripline; } @@ -409,7 +459,7 @@ private double getCstripZ(int region, int strip) { double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; // group minimum z double pitch = Constants.getCRCWIDTH()[region-1][group-1]; // group pitch int nmin = Constants.getCRCGRPNMIN()[region-1][group-1]; - z = zmin + (strip - nmin + 0.5) * pitch; + z = zmin + (strip - nmin + 0.5) * pitch ; } return z; } From de74b0033b5780e48a73017455fd390d128f4e34 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 15:16:02 -0500 Subject: [PATCH 086/291] Strip class modification to use BMT geometry allowing for generic cylinder. --- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 5701807b8..1d4aa5956 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -1,5 +1,7 @@ package org.jlab.rec.cvt.hit; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -145,12 +147,16 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector // set z //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); int region = (int) ((layer + 1) / 2 ); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 - double z = geo.getCstrip(region, sector, this.get_Strip()).center().z(); + Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); + double z = arcLine.center().z(); this.set_Z(z); // max z err //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); this.set_ZErr(geo.getCPitch(region, this.get_Strip()) / Math.sqrt(12.)); - + this.set_ImplantPoint(arcLine.origin()); + this.set_MidPoint(arcLine.center()); + this.set_EndPoint(arcLine.end()); + this.set_StripDir(arcLine.normal()); } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors @@ -180,6 +186,13 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector this.set_PhiErr(Math.sqrt(phiErr * phiErr + phiErrL * phiErrL)); //System.out.println("arcerr "+org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]+" * "+Math.toDegrees(sigma/org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region])); this.set_PhiErr0(phiErr); + + //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); + Line3D L = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip()); + this.set_ImplantPoint(L.origin()); + this.set_MidPoint(L.midpoint()); + this.set_EndPoint(L.end()); + this.set_StripDir(L.direction()); } } From a6b9ab6685b109e273a877a0f6395839050f82c1 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 15:16:53 -0500 Subject: [PATCH 087/291] cluster class modification to use BMT geometry allowing for generic cylinderto get the cluster position. --- .../org/jlab/rec/cvt/cluster/Cluster.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index c4c0faeac..727fe9727 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -164,7 +164,12 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { double weightedY2 = 0; // SVT strip centroid positions of endpoints double weightedZ1 = 0; // SVT strip centroid positions of endpoints double weightedZ2 = 0; // SVT strip centroid positions of endpoints - + /* + this.set_ImplantPoint(arcLine.origin()); + this.set_MidPoint(arcLine.center()); + this.set_EndPoint(arcLine.end()); + this.set_StripDir(arcLine.normal()); + */ int nbhits = this.size(); if (nbhits != 0) { @@ -199,6 +204,14 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { // for C detector the Z of the centroid is calculated weightedZ += strpEn * thehit.get_Strip().get_Z(); weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); + Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); + Point3D stEP2 = thehit.get_Strip().get_EndPoint(); + weightedX1 += strpEn * stEP1.x(); + weightedY1 += strpEn * stEP1.y(); + weightedZ1 += strpEn * stEP1.z(); + weightedX2 += strpEn * stEP2.x(); + weightedY2 += strpEn * stEP2.y(); + weightedZ2 += strpEn * stEP2.z(); } if (this.get_DetectorType()==1) { // Z-detectors // for Z detectors Larentz-correction is applied to the strip @@ -209,6 +222,12 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); weightedPhi0 += strpEn * thehit.get_Strip().get_Phi0(); weightedPhiErrSq0 += (thehit.get_Strip().get_PhiErr0()) * (thehit.get_Strip().get_PhiErr0()); + Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); + Point3D stEP2 = thehit.get_Strip().get_EndPoint(); + weightedX1 += strpEn * stEP1.x(); + weightedY1 += strpEn * stEP1.y(); + weightedX2 += strpEn * stEP2.x(); + weightedY2 += strpEn * stEP2.y(); } } @@ -258,6 +277,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { //phiErrCent = Math.sqrt(weightedPhiErrSq); //phiErrCent0 = Math.sqrt(weightedPhiErrSq0); //zErrCent = Math.sqrt(weightedZErrSq); + //System.out.println("end Points "+this.getEndPoint1().toString()+this.getEndPoint2().toString()+" for"); this.printInfo(); } _TotalEnergy = totEn; From 4dd08817c3aed0f7094a5fe5741b10899b0297d0 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 16:29:13 -0500 Subject: [PATCH 088/291] Fix in getIdealLCZstrip method in BMT geometry. --- .../cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 97654d6b6..77c5b1d01 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -12,7 +12,6 @@ import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; -import org.jlab.rec.cvt.services.CVTRecNewKF; /** * @@ -375,7 +374,7 @@ public Line3D getIdealLCZstrip(int region, int sector, int strip) { Point3D p1= new Point3D(radius, 0, zmin); p1.rotateZ(theLorentzCorrectedAngle); Point3D p2= new Point3D(radius, 0, zmax); - p2.rotateZ(angle); + p2.rotateZ(theLorentzCorrectedAngle); Line3D stripline = new Line3D(p1,p2); From 26de62e57806ef9a5d512392cdca8023ed59d51a Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 16:32:52 -0500 Subject: [PATCH 089/291] Added tracking status to seed: 2 = CA algorithm; 1 = phase space scanning algorithm. --- .../cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index 2174461ab..d7c3e6480 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -14,6 +14,8 @@ */ public class Seed implements Comparable{ + public int trkStatus; + public Seed() { // TODO Auto-generated constructor stub } From 40eb9c2de0dcf09236c46ec53c49e721b2c2b9f9 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 16:34:09 -0500 Subject: [PATCH 090/291] In CA sorting of the crosses on track according to radii. --- .../java/org/jlab/rec/cvt/track/TrackSeederCA.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 4c8f77e44..37f1cd7af 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -250,15 +250,17 @@ public List findSeed(List svt_crosses, List bmt_crosses, Seed seed = new Seed(); seed.set_Crosses(cand); seed.set_Helix(cand.get_helix()); + seed.trkStatus = 2; seedlist.add(seed); List clusters = new ArrayList(); - for(Cross c : seed.get_Crosses()) { + Collections.sort(seed.get_Crosses());System.out.println("CA seed : "); + for(Cross c : seed.get_Crosses()) { System.out.println(c.printInfo()); if(c.get_Detector().equalsIgnoreCase("SVT")) { clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); - } else { - clusters.add(c.get_Cluster1()); - } + } else { + clusters.add(c.get_Cluster1()); + } } seed.set_Clusters(clusters); } From 3f3419d3b856f1702d67754aa20a30473328ab1d Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 16:37:18 -0500 Subject: [PATCH 091/291] In CA sorting of the crosses on track according to radii. Comment out debug statements. --- .../src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 37f1cd7af..d10382a55 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -253,8 +253,8 @@ public List findSeed(List svt_crosses, List bmt_crosses, seed.trkStatus = 2; seedlist.add(seed); List clusters = new ArrayList(); - Collections.sort(seed.get_Crosses());System.out.println("CA seed : "); - for(Cross c : seed.get_Crosses()) { System.out.println(c.printInfo()); + Collections.sort(seed.get_Crosses()); + for(Cross c : seed.get_Crosses()) { if(c.get_Detector().equalsIgnoreCase("SVT")) { clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); From d3987c5def771fb1eb21adf27b0010bf711345e6 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 17:11:00 -0500 Subject: [PATCH 092/291] Scanner seeder fix for seeds with no bmt matches. --- .../org/jlab/rec/cvt/track/TrackSeeder.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index ff0e4a147..68c862edf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -339,26 +339,28 @@ public List findSeed(List bst_crosses, List bmt_crosses, if (sameSectorCrosses.size() >= 0) { BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses, bmt_geo); } - - for (Seed bseed : BMTmatches) { - //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false, swimmer); - if (bcand != null) { - seed = new Seed(); - seed.set_Crosses(bseed.get_Crosses()); - seed.set_Clusters(bseed.get_Clusters()); - seed.set_Helix(bcand.get_helix()); + if(BMTmatches.size()==0) { // no bmt matches; save svt stand-alone + seedlist.add(seed); + } else { //bmt matches found + for (Seed bseed : BMTmatches) { + //refit using the BMT + Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false, swimmer); + if (bcand != null) { + seed = new Seed(); + Collections.sort(bseed.get_Crosses()); + seed.set_Crosses(bseed.get_Crosses()); + seed.set_Clusters(bseed.get_Clusters()); + seed.set_Helix(bcand.get_helix()); + seedlist.add(seed); + } } } - - seedlist.add(seed); - } else { // no bmt - // seedlist.add(seed); - } + } } } for (Seed bseed : seedlist) { + bseed.trkStatus = 1; for(Cross c : bseed.get_Crosses()) { c.isInSeed = true; } From 910aa0a33196c51590f15e2b452e1bf2a2d21758 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:11:59 -0500 Subject: [PATCH 093/291] Added rotated and translated cylinder object to get the normal for tracking. --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 77c5b1d01..67ad14dc5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -3,6 +3,7 @@ import javax.swing.JFrame; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -508,6 +509,28 @@ public Arc3D getCstrip(int region, int sector, int strip) { return arcline; } + /** + * + * @param layer + * @param sector + * @return rotated cylinder corresponding to the BMT surface + */ + public Cylindrical3D getCylinder(int layer, int sector) { + Cylindrical3D cyl = new Cylindrical3D(); + cyl.baseArc().setCenter(new Point3D(0, 0, 0)); + cyl.highArc().setCenter(new Point3D(0, 0, 0)); + cyl.baseArc().setNormal(new Vector3D(0,1,0)); + cyl.highArc().setNormal(new Vector3D(0,1,0)); + + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + cyl.rotateX(rotation.x()); + cyl.rotateY(rotation.y()); + cyl.rotateZ(rotation.z()); + cyl.translateXYZ(offset.x(),offset.y(),offset.z()); + + return cyl; + } /** * Return the sector number * @param layer [0-6] From c5200b7c652eedd28fba495bed128a7b32b7323f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:45:29 -0500 Subject: [PATCH 094/291] Modified straight track fitting algorithm to include the svt in the z profile fitting after the svt cross z posiiton has been corrected using the bmt only fit to get the direction vector of the track. --- .../rec/cvt/track/TrackCandListFinder.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 89871b648..866a5532e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -20,6 +20,7 @@ import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.svt.Geometry; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -361,7 +362,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List(); - //crossesToFitWithBMT.addAll(cand); - //crossesToFitWithBMT.addAll(BMTmatches); - + //refit not using only BMT to fit the z profile + NewMeasArrays = this.get_RayMeasurementsArrays(crossesToFitWithBMT, false, false, false); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + cand = new StraightTrack(fitTrk.get_ray()); + cand.update_Crosses(cand.get_ray().get_yxslope(), cand.get_ray().get_yxinterc(), svt_geo); cand.set_ndf(NewMeasArrays._Y.size() + NewMeasArrays._Y_prime.size() - 4); double chi2 = cand.calc_straightTrkChi2(); cand.set_chi2(chi2); @@ -661,7 +663,8 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, List BMTCdetcrossesInTrk = new ArrayList(); List BMTZdetcrossesInTrk = new ArrayList(); - public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, boolean ignoreErr, boolean resetSVTMeas) { + public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, + boolean ignoreErr, boolean resetSVTMeas, boolean useBMTCforZonly) { X.clear(); Y.clear(); @@ -752,7 +755,7 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, boo // } } - if(BMTCdetcrossesInTrk.size()>1) { + if(BMTCdetcrossesInTrk.size()>1 && useBMTCforZonly==true) { //System.out.print("RESETTING MEAS ARRAY"); Z.clear(); Y_prime.clear(); @@ -766,6 +769,7 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, boo } } + //set_CrossParamsSVT(Vector3D dirAtBstPlane, Geometry geo) RayMeasurements MeasArray = new RayMeasurements(X, Y, Z, Y_prime, ErrZ, ErrY_prime, ErrRt); return MeasArray; From 928079638ea492a88e1b3ee9b60ede2e18b64122 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:46:23 -0500 Subject: [PATCH 095/291] Modified RecUtilities to use the new bmt geometry class. --- .../jlab/rec/cvt/services/RecUtilities.java | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 5548141b2..62ee08c54 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -21,6 +21,7 @@ import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; +import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.track.StraightTrack; @@ -73,7 +74,9 @@ public void CleanupSpuriousCrosses(List> crosses, List t } } - public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sgeo) { + public List setMeasVecs(Seed trkcand, + org.jlab.rec.cvt.svt.Geometry sgeo, + org.jlab.rec.cvt.bmt.BMTGeometry bgeo) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), @@ -118,11 +121,15 @@ public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sge // adding the BMT for (int c = 0; c < trkcand.get_Crosses().size(); c++) { if (trkcand.get_Crosses().get(c).get_Detector().equalsIgnoreCase("BMT")) { - Cylindrical3D cyl = new Cylindrical3D(); - cyl.baseArc().setCenter(new Point3D(0, 0, 0)); - cyl.highArc().setCenter(new Point3D(0, 0, 0)); - cyl.baseArc().setNormal(new Vector3D(0,1,0)); - cyl.highArc().setNormal(new Vector3D(0,1,0)); +// Cylindrical3D cyl = new Cylindrical3D(); +// cyl.baseArc().setCenter(new Point3D(0, 0, 0)); +// cyl.highArc().setCenter(new Point3D(0, 0, 0)); +// cyl.baseArc().setNormal(new Vector3D(0,1,0)); +// cyl.highArc().setNormal(new Vector3D(0,1,0)); + int lyer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); + int sec = trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(); + + Cylindrical3D cyl = bgeo.getCylinder(lyer, sec); int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); @@ -450,11 +457,12 @@ public List reFitSeed(Seed bseed, for(Cross c : bseed.get_Crosses()) { int layr = 0; int layr2 = 0; + c.set_AssociatedTrackID(-1); if(c.get_Detector().equalsIgnoreCase("BMT")) { layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; - //System.out.println("refit BMT "+c.printInfo()); + System.out.println("refit BMT "+c.printInfo()); refib.add(c); } } else { @@ -471,9 +479,21 @@ public List reFitSeed(Seed bseed, } Collections.sort(refi); seedlist = trseed.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer); + System.out.println("First Algo"); + for(Seed s : seedlist) { + System.out.println("seed "); + for(Cross c : s.get_Crosses()) System.out.println(c.printInfo()); + System.out.println("--------------------------"); + } + trseed2.unUsedHitsOnly = true; seedlist.addAll( trseed2.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer)); - + System.out.println("After Second Algo"); + for(Seed s : seedlist) { + System.out.println("seed "); + for(Cross c : s.get_Crosses()) System.out.println(c.printInfo()); + System.out.println("--------------------------"); + } return seedlist; } @@ -529,13 +549,20 @@ public List reFitSeed(StraightTrack cand, } if(refi.size()>=3) { TrackCandListFinder.RayMeasurements NewMeasArrays = trkfindr. - get_RayMeasurementsArrays((ArrayList) refi, false, false); + get_RayMeasurementsArrays((ArrayList) refi, false, false, true); fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); if(fitTrk.get_ray()!=null) { cand = new StraightTrack(fitTrk.get_ray()); cand.addAll(refi); + //refit with the SVT included to determine the z profile + NewMeasArrays = trkfindr. + get_RayMeasurementsArrays((ArrayList) refi, false, false, false); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, + NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + cand = new StraightTrack(fitTrk.get_ray()); + cand.addAll(refi); seedlist.add(cand); } } From a36748b4df9e72097fcd4dba5fa6f2d24208f9cc Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:47:00 -0500 Subject: [PATCH 096/291] Update output of fitting method according to which seeding algorithm was employed. --- .../org/jlab/rec/cvt/banks/RecoBankWriter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 8f6eaabc9..a8dbd8aff 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -314,18 +314,18 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh } DataBank bank = event.createBank("CVTRec::Tracks", trkcands.size()); - // an array representing the ids of the crosses that belong to the track: for a helical track with the current - // 4 regions of SVT + 1 region of BMT there can be up to 4 crosses of type SVT and 2 of type BMT (1 for the C detector and 1 for the Z detector) + // an array representing the ids of the crosses that belong to the track List crossIdxArray = new ArrayList(); for (int i = 0; i < trkcands.size(); i++) { if(trkcands.get(i)==null) continue; - if(trkcands.get(i).getChi2()!=0) { - bank.setByte("fittingMethod", i, (byte) 2); - } else { - bank.setByte("fittingMethod", i, (byte) 0); - } +// if(trkcands.get(i).getChi2()!=0) { +// bank.setByte("fittingMethod", i, (byte) 2); +// } else { +// bank.setByte("fittingMethod", i, (byte) 0); +// } + bank.setByte("fittingMethod", i, (byte) trkcands.get(i).get_TrackingStatus()); bank.setShort("ID", i, (short) trkcands.get(i).get_Id()); bank.setByte("q", i, (byte)trkcands.get(i).get_Q()); bank.setFloat("p", i, (float) trkcands.get(i).get_P()); From 8bf024c98fe3510bf426599eabbf69925a861719 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:47:56 -0500 Subject: [PATCH 097/291] Update tracking service methods to employ bmt geometry. --- .../org/jlab/rec/cvt/services/TracksFromTargetRec.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 5fca29c62..2b70e26fe 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -113,12 +113,12 @@ public boolean processEvent(DataEvent event, org.jlab.rec.cvt.Constants.getXb(), org.jlab.rec.cvt.Constants.getYb(), shift, - recUtil.setMeasVecs(seed, SVTGeom)) ; + recUtil.setMeasVecs(seed, SVTGeom, BMTGeom)) ; kf.runFitter(swimmer); if (kf.setFitFailed == false && kf.NDF>0) { trkcands.add(recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom)); - trkcands.get(trkcands.size() - 1).set_TrackingStatus(2); + trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); } //} else { //trkcands.add(recUtil.OutputTrack(seed)); @@ -141,7 +141,11 @@ public boolean processEvent(DataEvent event, //System.out.println( " *** *** trkcands " + trkcands.size() + " * trks " + trks.size()); trkFinder.removeOverlappingTracks(tracks); //turn off until debugged - + // reset cross IDs + for(int a = 0; a<2; a++) { + for(Cross c : crosses.get(a)) + c.set_AssociatedTrackID(-1); + } for (int c = 0; c < tracks.size(); c++) { tracks.get(c).set_Id(c + 1); for (int ci = 0; ci < tracks.get(c).size(); ci++) { From 393926dd5abc04c2a55c52570055b6c19e65207e Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:48:59 -0500 Subject: [PATCH 098/291] Modified BMT cross information to use the strip implant point which is corrected for misalignments. --- .../src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 9eb72221d..b9d490150 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -162,11 +162,13 @@ private ArrayList findBMTCrosses( this_cross.set_Point0(new Point3D(x0, y0, Double.NaN)); this_cross.set_PointErr0(new Point3D(x0Er, y0Er, Double.NaN)); //the x,y position of the Z detector cluster centroid. This is calculated from the Lorentz angle corrected strips - double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); - double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); + //double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); + //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); + double x = Zlayerclus.getEndPoint1().x(); + double y = Zlayerclus.getEndPoint1().y(); double xEr = -org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); double yEr = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); - + // set only the coordinates for which there is a measurement (x,y) this_cross.set_Point(new Point3D(x, y, Double.NaN)); this_cross.set_PointErr(new Point3D(Math.abs(xEr), Math.abs(yEr), Double.NaN)); From 6d88eb40c4a12f0e4dd332d59e983e949173418e Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 18:50:11 -0500 Subject: [PATCH 099/291] Fix comments. --- .../cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java | 2 +- .../cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 727fe9727..6cf4ed056 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -214,7 +214,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { weightedZ2 += strpEn * stEP2.z(); } if (this.get_DetectorType()==1) { // Z-detectors - // for Z detectors Larentz-correction is applied to the strip + // for Z detectors Lorentz-correction is applied to the strip strpNb = thehit.get_Strip().get_LCStrip(); strpNb0 = thehit.get_Strip().get_Strip(); // for C detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 1d4aa5956..c352eee19 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -189,7 +189,7 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); Line3D L = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip()); - this.set_ImplantPoint(L.origin()); + this.set_ImplantPoint(L.origin()); this.set_MidPoint(L.midpoint()); this.set_EndPoint(L.end()); this.set_StripDir(L.direction()); From 3d87ade38aa086e05b4179f52d1a2fdf32c89023 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 20:45:52 -0500 Subject: [PATCH 100/291] Removed debug printouts. --- .../cvt/cross/StraightTrackCrossListFinder.java | 8 +------- .../org/jlab/rec/cvt/services/RecUtilities.java | 14 +------------- .../jlab/rec/cvt/track/TrackCandListFinder.java | 2 +- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index 40a5f8715..8b5d56dff 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -325,9 +325,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, // loop over the list of crosslists for (int i = 0; i < crossLists.size(); i++) { - if (crossLists.get(i).size() > 0) {System.out.println("In list :"); - for(Cross c : crossLists.get(i)) - System.out.println("In :"+c.printInfo()); + if (crossLists.get(i).size() > 0) { ArrayList crossList = new ArrayList(); // find the trajectory for each crosslist ArrayList TrajPoints = get_XYTrajectory(crossLists.get(i), svt_geo, bmt_geo, NbSVTRegions); @@ -387,10 +385,6 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, for (int k = 0; k < newCrossLists.size(); k++) { if (newCrossLists.get(k).size() != 0) { crossListFinal.add(newCrossLists.get(k)); - System.out.println("In list :"); - for(Cross c : newCrossLists.get(k)) - System.out.println("In :"+c.printInfo()); - } } return crossListFinal; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 62ee08c54..ef474f505 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -462,7 +462,6 @@ public List reFitSeed(Seed bseed, layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; - System.out.println("refit BMT "+c.printInfo()); refib.add(c); } } else { @@ -479,21 +478,10 @@ public List reFitSeed(Seed bseed, } Collections.sort(refi); seedlist = trseed.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer); - System.out.println("First Algo"); - for(Seed s : seedlist) { - System.out.println("seed "); - for(Cross c : s.get_Crosses()) System.out.println(c.printInfo()); - System.out.println("--------------------------"); - } trseed2.unUsedHitsOnly = true; seedlist.addAll( trseed2.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer)); - System.out.println("After Second Algo"); - for(Seed s : seedlist) { - System.out.println("seed "); - for(Cross c : s.get_Crosses()) System.out.println(c.printInfo()); - System.out.println("--------------------------"); - } + return seedlist; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 866a5532e..d46b5ac5f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -678,7 +678,7 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, BMTZdetcrossesInTrk.clear(); //make lists - for (Cross c : arrayList) { //System.out.println(" getting measurement arrays "+c.printInfo()); + for (Cross c : arrayList) { if (c.get_Detector().equalsIgnoreCase("SVT")) { SVTcrossesInTrk.add(c); } From 94dabc295071715fdb347cb3330636b2f89ef207 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 3 Mar 2021 20:48:44 -0500 Subject: [PATCH 101/291] Removed debug printouts. --- .../main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index e9e9ff971..33e355d20 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -536,7 +536,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, StateVec stVec, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal) { -System.out.println("SETTING HIT RESOL..."); + if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); double doca2Seed = svt_geo.getDOCAToStrip(sector, layer, (double) cluster.get_SeedStrip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); From 5261b248f74a94271c900de79fceaadbfe00ce13 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 9 Mar 2021 19:25:21 -0500 Subject: [PATCH 102/291] Fixed execution time issue. --- .../rec/cvt/track/TrackCandListFinder.java | 2 - .../org/jlab/rec/cvt/track/TrackSeeder.java | 52 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index d46b5ac5f..5e8b68b79 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -20,7 +20,6 @@ import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; -import org.jlab.rec.cvt.svt.Geometry; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -769,7 +768,6 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, } } - //set_CrossParamsSVT(Vector3D dirAtBstPlane, Geometry geo) RayMeasurements MeasArray = new RayMeasurements(X, Y, Z, Y_prime, ErrZ, ErrY_prime, ErrRt); return MeasArray; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 68c862edf..a8152af9f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -339,28 +339,29 @@ public List findSeed(List bst_crosses, List bmt_crosses, if (sameSectorCrosses.size() >= 0) { BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses, bmt_geo); } - if(BMTmatches.size()==0) { // no bmt matches; save svt stand-alone - seedlist.add(seed); - } else { //bmt matches found - for (Seed bseed : BMTmatches) { - //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false, swimmer); - if (bcand != null) { - seed = new Seed(); - Collections.sort(bseed.get_Crosses()); - seed.set_Crosses(bseed.get_Crosses()); - seed.set_Clusters(bseed.get_Clusters()); - seed.set_Helix(bcand.get_helix()); - seedlist.add(seed); - } + Seed bestSeed = null; + double chi2_Circ = Double.POSITIVE_INFINITY; + double chi2_Line = Double.POSITIVE_INFINITY; + + for (Seed bseed : BMTmatches) { + //refit using the BMT + Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false, swimmer); + + if (bcand != null && bcand.get_circleFitChi2PerNDF() VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge } //System.out.println(" Seed fitter "+fitTrk.get_chisq()[0]+" "+fitTrk.get_chisq()[1]); if(chisqMax>Constants.CIRCLEFIT_MAXCHI2) - cand=null; + return null; + if(X.size() > 3) + cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params + if(Z.size() > 2) + cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params return cand; } @@ -545,7 +550,7 @@ public List findCandUsingMicroMegas(Seed trkCand, List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); - List AllSeeds = new ArrayList(); + Map AllSeeds = new HashMap(); int[] S = new int[3]; for (int r = 0; r < 3; r++) { @@ -594,14 +599,16 @@ public List findCandUsingMicroMegas(Seed trkCand, } matches.addAll(trkCand.get_Crosses()); - + Collections.sort(matches); if (matches.size() > 0) { Seed BMTTrkSeed = new Seed(); - + String st = ""; + for(Cross c : matches) + st+=c.get_Id(); BMTTrkSeed.set_Helix(trkCand.get_Helix()); BMTTrkSeed.set_Crosses(matches); BMTTrkSeed.set_Clusters(trkCand.get_Clusters()); - AllSeeds.add(BMTTrkSeed); + AllSeeds.put(st,BMTTrkSeed); //if (AllSeeds.size() > 200) { // AllSeeds.clear(); @@ -614,8 +621,11 @@ public List findCandUsingMicroMegas(Seed trkCand, } } + List outputSeeds = new ArrayList(); + for(Seed s : AllSeeds.values()) + outputSeeds.add(s); - return AllSeeds; + return outputSeeds; } private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { From 7feed54a4d3bf0a7d6f694adae4793e19564ee6c Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 18 Mar 2021 12:13:22 -0400 Subject: [PATCH 103/291] Search for SVT clusters on track that are not included in crosses on track in first pass tracking. Include them in list of clusters used in the fit at second pass tracking. --- .../jlab/rec/cvt/services/RecUtilities.java | 56 +++++++++++-------- .../rec/cvt/services/TracksFromTargetRec.java | 17 ++++++ .../java/org/jlab/rec/cvt/svt/Geometry.java | 4 +- .../jlab/rec/cvt/track/TrackListFinder.java | 18 +++--- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index ef474f505..d16e584b2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -186,9 +186,9 @@ public List setMeasVecs(Seed trkcand, } return KFSites; } - public Map FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, + public List FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, org.jlab.rec.cvt.svt.Geometry sgeo, - Swim swimmer) { + Swim swimmer) { Map clusMap = new HashMap(); //Map stripMap = new HashMap(); Map docaMap = new HashMap(); @@ -224,29 +224,37 @@ public Map FindClustersOnTrk (List allClusters, Helix Point3D p = sgeo.getPlaneModuleOrigin(sector, layer); double d = n.dot(p.toVector3D()); inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); - Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); - double nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); - //stripMap.put((sector*1000+layer), nearstp); - docaMap.put((sector*1000+layer), sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); - trajMap.put((sector*1000+layer), trp); + if(inters!=null) { + Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); + double nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); + //stripMap.put((sector*1000+layer), nearstp); + docaMap.put((sector*1000+layer), sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); + trajMap.put((sector*1000+layer), trp); + } } for(Cluster cls : allClusters) { int clsKey = cls.get_Sector()*1000+cls.get_Layer(); - //double trjCent = stripMap.get(clsKey); - double clsDoca = sgeo.getDOCAToStrip(cls.get_Sector(), cls.get_Layer(), - cls.get_Centroid(), trajMap.get(clsKey)); - if(clusMap.containsKey(clsKey)) { - //double filldCent = clusMap.get(clsKey).get_Centroid(); - double filldDoca = docaMap.get(clsKey); - if(Math.abs(clsDoca) clustersOnTrack = new ArrayList(); + for(Cluster cl : clusMap.values()) { + clustersOnTrack.add(cl); + } + return clustersOnTrack; } public void MatchTrack2Traj(Seed trkcand, Map0) { + Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); + for(Cross c : fittedTrack) { + if(c.get_Detector().equalsIgnoreCase("SVT")) { + c.get_Cluster1().set_AssociatedTrackID(0); + c.get_Cluster2().set_AssociatedTrackID(0); + } + } + //refit adding missing clusters + List clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, fittedTrack.get_helix(), + fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); + seed.get_Clusters().addAll(clsOnTrack); + kf = new org.jlab.clas.tracking.kalmanfilter.helical.KFitter( hlx, cov, event, swimmer, + org.jlab.rec.cvt.Constants.getXb(), + org.jlab.rec.cvt.Constants.getYb(), + shift, + recUtil.setMeasVecs(seed, SVTGeom, BMTGeom)) ; + kf.runFitter(swimmer); trkcands.add(recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom)); trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java index 366526288..a60c34469 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java @@ -499,9 +499,9 @@ public double getDOCAToStrip(int sector, int layer, double centroidstrip, Point3 double b1 = SVTConstants.ACTIVESENWID - interc; double b2 = interc; - Vector3D vecAlongStrip = new Vector3D(); + Vector3D vecAlongStrip = new Vector3D(); Point3D pointOnStrip = new Point3D(); - Point3D LocPoint = this.transformToFrame(sector, layer, point0.x(), point0.y(), point0.z(), "local", ""); + Point3D LocPoint = this.transformToFrame(sector, layer, point0.x(), point0.y(), point0.z(), "local", ""); if (layer % 2 == 0) { //layers 2,4,6 == top ==j ==>(2) : regular configuration vecAlongStrip = new Vector3D(m2, 0, 1).asUnit(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index c32d8311f..3f026a30f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -56,19 +56,21 @@ public List getTracks(List cands, maxPathLength) ; double[] pointAtCylRad = bstSwim.SwimRho(Constants.CTOFINNERRADIUS/10); - trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); - trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); + if(pointAtCylRad!=null) { + trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); + trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); - trk.set_pathLength(pointAtCylRad[6]*10); + trk.set_pathLength(pointAtCylRad[6]*10); - TrajectoryFinder trjFind = new TrajectoryFinder(); + TrajectoryFinder trjFind = new TrajectoryFinder(); - Trajectory traj = trjFind.findTrajectory(trk.get_Id(), trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, bstSwim, "final"); + Trajectory traj = trjFind.findTrajectory(trk.get_Id(), trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, bstSwim, "final"); - trk.set_Trajectory(traj.get_Trajectory()); + trk.set_Trajectory(traj.get_Trajectory()); - //if(trk.passCand == true) - tracks.add(trk); + //if(trk.passCand == true) + tracks.add(trk); + } } } From 1a081d3ee282ca13d95c65fa4f6e977bdcc1fee1 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 26 Apr 2021 09:39:03 -0400 Subject: [PATCH 104/291] created dev-align3, which is a clone of TracTools-ExLayr, except with added classes from dev-align2. This removes crap that I've merged in from other branches --- .../rec/cvt/banks/AlignmentBankWriter.java | 33 + .../jlab/rec/cvt/banks/RecoBankReader.java | 436 ++++++ .../jlab/rec/cvt/services/CVTAlignment.java | 1238 +++++++++++++++++ 3 files changed, 1707 insertions(+) create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/AlignmentBankWriter.java create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/AlignmentBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/AlignmentBankWriter.java new file mode 100644 index 000000000..811b95e89 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/AlignmentBankWriter.java @@ -0,0 +1,33 @@ +package org.jlab.rec.cvt.banks; + +import java.util.List; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; + +import Jama.Matrix; + +public class AlignmentBankWriter { + + public void write_Matrix(DataEvent event, String matrixName, List matrices) { + + //System.out.println("attempting to write matrices"); + if(event == null) + System.out.println("event is null"); + if(matrixName == null) + System.out.println("matrixName is null"); + if(matrices == null) + System.out.println("matrix list is null"); + DataBank bank = event.createBank("Align::" + matrixName, matrices.size()); + for(int i = 0; i< matrices.size(); i++) { + bank.setShort("rows",i,(short) matrices.get(i).getRowDimension()); + bank.setShort("columns",i,(short) matrices.get(i).getColumnDimension()); + for(int j = 0; j _cosmics; + private List _SVTcrosses; + private List _SVTclusters; + private List _SVTHits; + private List _BMTcrosses; + private List _BMTclusters; + private List _BMThits; + + + + + + + + public void fetch_SVTCrosses(DataEvent event, double zShift) { + if(_SVTclusters == null) + fetch_SVTClusters(event); + + if (event.hasBank("BSTRec::Crosses") == false) { + //System.err.println("there is no BST bank "); + _SVTcrosses = new ArrayList(); + + return; + } + _SVTcrosses = new ArrayList(); + DataBank bank = event.getBank("BSTRec::Crosses"); + + for (int j = 0; j < bank.rows(); j++) { + int region = bank.getByte("region", j); + int sector = bank.getByte("sector", j); + int id = bank.getShort("ID",j); + Cross cross = new Cross("SVT", BMTType.UNDEFINED, sector, region, j); + cross.set_Id(id); + cross.set_Point(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); + cross.set_PointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); + cross.set_AssociatedTrackID(bank.getShort("trkID",j)); + cross.set_Dir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); + + int cluster1id = bank.getShort("Cluster1_ID", j); + for (Cluster cluster: _SVTclusters) + if (cluster.get_Id() == cluster1id) + cross.set_Cluster1(cluster); + int cluster2id = bank.getShort("Cluster2_ID", j); + for (Cluster cluster: _SVTclusters) + if (cluster.get_Id() == cluster2id) + cross.set_Cluster2(cluster); + + _SVTcrosses.add(cross); + } + + + + } + + public void fetch_BMTCrosses(DataEvent event, double zShift) { + if(_BMTclusters == null) + fetch_BMTClusters(event); + + if (event.hasBank("BMTRec::Crosses") == false) { + //System.err.println("there is no BST bank "); + _BMTcrosses = new ArrayList(); + + return; + } + _BMTcrosses = new ArrayList(); + DataBank bank = event.getBank("BMTRec::Crosses"); + + for (int j = 0; j < bank.rows(); j++) { + int region = bank.getByte("region", j); + int sector = bank.getByte("sector", j); + int id = bank.getShort("ID",j); + Cross cross = new Cross("BMT", BMTType.UNDEFINED, sector, region, id); + cross.set_Point(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); + cross.set_PointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); + cross.set_AssociatedTrackID(bank.getShort("trkID",j)); + cross.set_Dir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); + + int cluster1id = bank.getShort("Cluster1_ID", j); + for (Cluster cluster: _BMTclusters) { + if (cluster.get_Id() == cluster1id) { + cross.set_Cluster1(cluster); + cross.set_DetectorType(BMTGeometry.getDetectorType(cluster.get_Layer())); + } + } + //int cluster2id = bank.getShort("Cluster2_ID", j); + //for (Cluster cluster: _clusters) + // if (cluster.get_Id() == cluster2id) + // cross.set_Cluster2(cluster); + + _BMTcrosses.add(cross); + } + + } + + public void fetch_BMTClusters(DataEvent event) { + _BMTclusters = new ArrayList(); + if(_BMThits == null) + this.fetch_BMTHits(event); + DataBank bank = event.getBank("BMTRec::Clusters"); + + for (int i = 0; i < bank.rows(); i++) { + + + int id = bank.getShort("ID", i); + int layer = bank.getByte("layer", i); + int sector = bank.getByte("sector", i); + Cluster cluster = new Cluster(0, 0, sector, layer, id); + + int size = bank.getInt("size", i); + cluster.set_TotalEnergy(bank.getFloat("ETot", i)); + cluster.set_SeedStrip(bank.getInt("seedStrip", i)); + cluster.set_Centroid(bank.getFloat("centroid",i)); + cluster.set_SeedEnergy(bank.getFloat("seedE",i)); + cluster.set_SeedEnergy(bank.getFloat("seedE",i)); + cluster.set_CentroidResidual(bank.getFloat("centroidResidual",i)); + cluster.set_SeedResidual(bank.getFloat("seedResidual",i)); + cluster.set_AssociatedTrackID(bank.getShort("trkID",i)); + //Since only up to 5 hits per track are written... + for (int j = 0; j < 5; j++) { + String hitStrg = "Hit"; + hitStrg += (j + 1); + hitStrg += "_ID"; + if(!hasColumn(bank,hitStrg)) + continue; + int hitId = bank.getShort(hitStrg, i); + for(FittedHit hit : _BMThits) { + if (hit.get_Id() == hitId) { + cluster.add(hit); + } + } + } + _BMTclusters.add(cluster); + + } + } + + public void fetch_Cosmics(DataEvent event, double zShift) { + + if(_SVTcrosses == null) + fetch_SVTCrosses(event, zShift); + if(_BMTcrosses == null) + fetch_BMTCrosses(event, zShift); + if (event.hasBank("CVTRec::Cosmics") == false) { + //System.err.println("there is no BST bank "); + _cosmics = new ArrayList(); + + return; + } + + List hits = new ArrayList(); + + DataBank bank = event.getBank("CVTRec::Cosmics"); + + int rows = bank.rows();; + + short ids[] = bank.getShort("ID"); + float chi2s[] = bank.getFloat("chi2"); + short ndfs[] = bank.getShort("ndf"); + float yx_slopes[] = bank.getFloat("trkline_yx_slope"); + float yx_intercs[] = bank.getFloat("trkline_yx_interc"); + float yz_slopes[] = bank.getFloat("trkline_yz_slope"); + float yz_intercs[] = bank.getFloat("trkline_yz_interc"); + + + _cosmics = new ArrayList(); + + + for(int i = 0; i _tracks; + + public void fetch_Tracks(DataEvent event, org.jlab.rec.cvt.svt.Geometry geo, double zShift) { + + if(_SVTcrosses == null) + fetch_SVTCrosses(event, zShift); + if(_BMTcrosses == null) + fetch_BMTCrosses(event, zShift); + if (event.hasBank("CVTRec::Tracks") == false) { + //System.err.println("there is no BST bank "); + _tracks = new ArrayList(); + + return; + } + + List hits = new ArrayList(); + + DataBank bank = event.getBank("CVTRec::Tracks"); + + int rows = bank.rows();; + + short ids[] = bank.getShort("ID"); + float chi2s[] = bank.getFloat("chi2"); + short ndfs[] = bank.getShort("ndf"); + byte qs[] = bank.getByte("q"); + float ps[] = bank.getFloat("p"); + float pts[] = bank.getFloat("pt"); + float tandips[] = bank.getFloat("tandip"); + float phi0s[] = bank.getFloat("phi0"); + float z0s[] = bank.getFloat("z0"); + float d0s[] = bank.getFloat("d0"); + float xbs[] = bank.getFloat("xb"); + float ybs[] = bank.getFloat("yb"); + + float curvatures[]; + try { + curvatures = bank.getFloat("curvature"); + }catch(Exception e){ + curvatures = new float[ids.length]; + } + + /*bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); + bank.setFloat("tandip", i, (float) helix.get_tandip()); + bank.setFloat("z0", i, (float) (helix.get_Z0()/10.+zShift)); + bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); + bank.setFloat("xb", i, (float) (org.jlab.rec.cvt.Constants.getXb()/10.0)); + bank.setFloat("yb", i, (float) (org.jlab.rec.cvt.Constants.getYb()/10.0));*/ + + _tracks = new ArrayList(); + + for(int i = 0; i(); + if(_SVTHits == null) + this.fetch_SVTHits(event); + DataBank bank = event.getBank("BSTRec::Clusters"); + + for (int i = 0; i < bank.rows(); i++) { + + + int id = bank.getShort("ID", i); + int layer = bank.getByte("layer", i); + int sector = bank.getByte("sector", i); + Cluster cluster = new Cluster(0, 0, sector, layer, id); + + int size = bank.getInt("size", i); + cluster.set_TotalEnergy(bank.getFloat("ETot", i)); + cluster.set_SeedStrip(bank.getInt("seedStrip", i)); + cluster.set_Centroid(bank.getFloat("centroid",i)); + cluster.set_SeedEnergy(bank.getFloat("seedE",i)); + cluster.set_SeedEnergy(bank.getFloat("seedE",i)); + cluster.set_CentroidResidual(bank.getFloat("centroidResidual",i)); + cluster.set_SeedResidual(bank.getFloat("seedResidual",i)); + cluster.set_AssociatedTrackID(bank.getShort("trkID",i)); + + //Since only up to 5 hits per track are written... + for (int j = 0; j < 5; j++) { + String hitStrg = "Hit"; + hitStrg += (j + 1); + hitStrg += "_ID"; + if(!hasColumn(bank,hitStrg)) + continue; + int hitId = bank.getShort(hitStrg, i); + for(FittedHit hit : _SVTHits) { + if (hit.get_Id() == hitId) { + cluster.add(hit); + } + } + } + _SVTclusters.add(cluster); + + } + + } + + + private void fetch_SVTHits(DataEvent event) { + DataBank bank = event.getBank("BSTRec::Hits"); + + _SVTHits = new ArrayList(); + for (int i = 0; i < bank.rows(); i++) { + int layer = bank.getByte("layer", i); + int sector = bank.getByte("sector", i); + int strip = bank.getInt("strip", i); + int id = bank.getShort("ID", i); + FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0,0)); + + hit.set_Id(id); + hit.set_docaToTrk(bank.getFloat("fitResidual", i)); + hit.set_TrkgStatus(bank.getInt("trkingStat", i)); + + hit.set_AssociatedClusterID(bank.getShort("clusterID", i)); + hit.set_AssociatedTrackID(bank.getShort("trkID", i)); + _SVTHits.add(hit); + } + //bank.show(); + } + + public void fetch_BMTHits(DataEvent event) { + DataBank bank = event.getBank("BSTRec::Hits"); + + _BMThits = new ArrayList(); + for (int i = 0; i < bank.rows(); i++) { + int layer = bank.getByte("layer", i); + int sector = bank.getByte("sector", i); + int strip = bank.getInt("strip", i); + int id = bank.getShort("ID", i); + FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0,0)); + + hit.set_Id(id); + hit.set_docaToTrk(bank.getFloat("fitResidual", i)); + hit.set_TrkgStatus(bank.getInt("trkingStat", i)); + + hit.set_AssociatedClusterID(bank.getShort("clusterID", i)); + hit.set_AssociatedTrackID(bank.getShort("trkID", i)); + _BMThits.add(hit); + } + //bank.show(); + } + + public List get_Cosmics() { + return _cosmics; + } + + public List get_Tracks() { + return _tracks; + } + + public List get_ClustersSVT() { + return _SVTclusters; + } + + public List get_ClustersBMT() { + return _BMTclusters; + } + + public List get_CrossesSVT() { + return _SVTcrosses; + } + + public List get_CrossesBMT() { + return _BMTcrosses; + } + +} \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java new file mode 100644 index 000000000..667f1e9b1 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -0,0 +1,1238 @@ +package org.jlab.rec.cvt.services; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.jlab.clas.reco.ReconstructionEngine; +//import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; +import org.jlab.detector.base.GeometryFactory; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.detector.geant4.v2.CTOFGeant4Factory; +import org.jlab.detector.geant4.v2.SVT.SVTAlignmentFactory; +import org.jlab.detector.geant4.v2.SVT.SVTConstants; +import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; +import org.jlab.geom.base.ConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +import org.jlab.geometry.prim.Line3d; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.Constants; + +import org.jlab.rec.cvt.banks.AlignmentBankWriter; +import org.jlab.rec.cvt.banks.RecoBankReader; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; +import org.jlab.rec.cvt.cluster.Cluster; +import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.track.StraightTrack; +import org.jlab.rec.cvt.track.Track; +import org.jlab.rec.cvt.trajectory.Helix; +import org.jlab.rec.cvt.trajectory.Ray; +import org.jlab.rec.cvt.trajectory.Trajectory; + +import Jama.Matrix; +import eu.mihosoft.vrl.v3d.Vector3d; + +/** + * Service to return reconstructed TRACKS + * format + * + * @author ziegler + * + */ +public class CVTAlignment extends ReconstructionEngine { + + org.jlab.rec.cvt.svt.Geometry SVTGeom; + org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom; + CTOFGeant4Factory CTOFGeom; + Detector CNDGeom ; + SVTStripFactory svtIdealStripFactory; + + public CVTAlignment() { + super("CVTAlignment", "spaul", "4.0"); + + SVTGeom = new org.jlab.rec.cvt.svt.Geometry(); + BMTGeom = new org.jlab.rec.cvt.bmt.BMTGeometry(); + + } + + String FieldsConfig = ""; + int Run = -1; + public boolean isSVTonly = false; + private Boolean svtTopBottomSep; + public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int iRun, boolean addMisAlignmts, String misAlgnFile) { + if (event.hasBank("RUN::config") == false) { + System.err.println("RUN CONDITIONS NOT READ!"); + return; + } + + int Run = iRun; + + boolean isMC = false; + boolean isCosmics = false; + DataBank bank = event.getBank("RUN::config"); + //System.out.println("EVENTNUM "+bank.getInt("event",0)); + if (bank.getByte("type", 0) == 0) { + isMC = true; + } + if (bank.getByte("mode", 0) == 1) { + isCosmics = true; + } + + + + // Load the fields + //----------------- + String newConfig = "SOLENOID" + bank.getFloat("solenoid", 0); + + if (FieldsConfig.equals(newConfig) == false) { + // Load the Constants + + this.setFieldsConfig(newConfig); + } + FieldsConfig = newConfig; + + // Load the constants + //------------------- + int newRun = bank.getInt("run", 0); + + if (Run != newRun) { + boolean align=false; + //Load field scale + double SolenoidScale =(double) bank.getFloat("solenoid", 0); + Constants.setSolenoidscale(SolenoidScale); + if(Math.abs(SolenoidScale)<0.001) + Constants.setCosmicsData(true); + + System.out.println(" LOADING BMT GEOMETRY...............................variation = "+variationName); + CCDBConstantsLoader.Load(new DatabaseConstantProvider(newRun, variationName)); + // System.out.println("SVT LOADING WITH VARIATION "+variationName); + // DatabaseConstantProvider cp = new DatabaseConstantProvider(newRun, variationName); + // cp = SVTConstants.connect( cp ); + // cp.disconnect(); + // SVTStripFactory svtFac = new SVTStripFactory(cp, true); + // SVTGeom.setSvtStripFactory(svtFac); + Constants.Load(isCosmics, isSVTonly); + this.setRun(newRun); + + } + + Run = newRun; + this.setRun(Run); + } + + public int getRun() { + return Run; + } + + public void setRun(int run) { + Run = run; + } + + public String getFieldsConfig() { + return FieldsConfig; + } + + public void setFieldsConfig(String fieldsConfig) { + FieldsConfig = fieldsConfig; + } + + boolean isCosmics = false; + private boolean isBMTonly; + + @Override + public boolean processDataEvent(DataEvent event) { + int runNum = event.getBank("RUN::config").getInt("run", 0); + int eventNum = event.getBank("RUN::config").getInt("event", 0); + this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); + + double shift = 0;//org.jlab.rec.cvt.Constants.getZoffset();; + + this.FieldsConfig = this.getFieldsConfig(); + + + RecoBankReader reader = new RecoBankReader(); + + //reader.fetch_Cosmics(event, SVTGeom, 0); + + List tracks; + if(isCosmics) { + reader.fetch_Cosmics(event, shift); + tracks = reader.get_Cosmics(); + } else { + reader.fetch_Tracks(event, SVTGeom, shift); + tracks = reader.get_Tracks(); + } + /*System.out.println(reader.get_ClustersSVT().size()+ " clusters found in SVT"); + System.out.println(reader.get_ClustersBMT().size()+ " clusters found in BMT"); + System.out.println(reader.get_CrossesSVT().size() + " crosses found in SVT"); + System.out.println(reader.get_CrossesBMT().size() + " crosses found in BMT"); + System.out.println(tracks.size() + " tracks found");*/ + + + //System.out.println("H"); + List Is = new ArrayList(); + List As = new ArrayList(); + List Bs = new ArrayList(); + List Vs = new ArrayList(); + List ms = new ArrayList(); + List cs = new ArrayList(); + List trackIDs = new ArrayList(); + + + tracksLoop : for (Trajectory track : tracks) { + + if(Math.abs(getDoca(track))>maxDocaCut) + continue; + /*System.out.println("track read: "); + System.out.println("track chi2: "+ track.get_chi2()); + System.out.println("ndf: "+ track.get_ndf()); + System.out.println("ncrosses: "+ track.size()); + System.out.println("ray: "+ track.get_ray().get_refPoint() + + " + lambda*" + track.get_ray().get_dirVec()); + System.out.println();*/ + + //System.out.println("BMT crosses"); + int nCrossSVT = 0, nCrossBMT = 0; + for(Cross c : track) { + if(c.get_Detector().equalsIgnoreCase("SVT") && !isBMTonly) + nCrossSVT++; + if(c.get_Detector().equalsIgnoreCase("BMT") && !isSVTonly) { + nCrossBMT++; + //System.out.println(c.get_Sector()+" "+c.get_Region() + " " + c.get_Cluster1().get_Centroid()+" " + c.get_Id()); + } + if(nCrossBMT>12) { + System.out.println("Too many BMT crosses!"); + System.exit(0); + } + } + int nCross = nCrossSVT + nCrossBMT; + if(nCross <= 2) + continue; + Ray ray = track.get_ray(); + if(ray == null) { + ray = getRay(track.get_helix()); + //System.out.println("curvature " + track.get_helix().get_curvature()); + //System.out.println("doca " + track.get_helix().get_dca()); + if(Math.abs(track.get_helix().get_curvature())>0.001) { + continue; + } + } + //getRay(track); + //System.out.println(ray.get_dirVec().toString()); + //System.out.println(ray.get_refPoint().toString()); + + + + int colsA = nAlignVars*((svtTopBottomSep ? 2*nCrossSVT : nCrossSVT) + nCrossBMT + (isCosmics ? 0:1)); + int rows = 2*nCrossSVT+nCrossBMT + (isCosmics ? 0:1); + Matrix A = new Matrix(rows, colsA);//not sure why there aren't 6 columns + Matrix B = new Matrix(rows, 4); + Matrix V = new Matrix(rows,rows); + Matrix m = new Matrix(rows,1); + Matrix c = new Matrix(rows,1); + Matrix I = new Matrix(rows,1); + + int i = 0; + + for(Cross cross : track) { + //System.out.println("cross " +cross.get_Point()); + if(cross.get_Detector().equalsIgnoreCase("SVT")) + { + if(isBMTonly) + continue; + Cluster cl1 = cross.get_Cluster1(); + boolean ok = fillMatricesSVT(i,ray,cl1,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + Cluster cl2 = cross.get_Cluster2(); + ok = fillMatricesSVT(i,ray,cl2,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + } else { + if(isSVTonly) + continue; + Cluster cl = cross.get_Cluster1(); + + + if(cross.get_DetectorType() == BMTType.Z) { + boolean ok = fillMatricesBMTZ(i,ray,cl,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in a BMT Z layer"); + continue tracksLoop; + } + } + else if(cross.get_DetectorType() == BMTType.C) { + boolean ok = fillMatricesBMTC(i,ray,cl,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in a BMT C layer"); + continue tracksLoop; + } + } + + } + + } + if(!isCosmics) { + fillMatricesBeamspot(i, ray, A,B,V,m,c,I); + } + /*Matrix dm = m.minus(c); + System.out.println("dm: "); + dm.print(6, 2); + System.out.println("V: "); + V.print(7, 4); + System.out.println("B: "); + B.print(7, 4); + System.out.println("A: "); + A.print(7, 4); + System.out.println("I: "); + I.print(7, 4); + System.out.println("track chi2: " + dm.transpose().times(V.inverse()).times(dm).get(0, 0)); + System.out.println();*/ + + for(double res : c.minus(m).getRowPackedCopy()) { + if(Math.abs(res)>maxResidualCut) { + System.out.println("rejecting track due to large residual"); + continue tracksLoop; + } + } + As.add(A); + Bs.add(B); + Vs.add(V); + ms.add(m); + cs.add(c); + Is.add(I); + + + //c.print(7, 4); + //m.print(7, 4); + + trackIDs.add(track.get_Id()); + } + AlignmentBankWriter writer = new AlignmentBankWriter(); + writer.write_Matrix(event, "I", Is); + writer.write_Matrix(event, "A", As); + writer.write_Matrix(event, "B", Bs); + writer.write_Matrix(event, "V", Vs); + writer.write_Matrix(event, "m", ms); + writer.write_Matrix(event, "c", cs); + fillMisc(event,runNum,eventNum,trackIDs,As,Bs,Vs,ms,cs,Is); + + //event.show(); + return true; + + } + int nAlignables; + + private Ray getRay(Helix h) { + + double d = h.get_dca(); + double z = h.get_Z0(); + double phi = h.get_phi_at_dca(); + double td = h.get_tandip(); + double cd = 1/Math.hypot(td, 1); + double sd = td*cd; + //Vector3D u = new Vector3D(-cd*Math.sin(phi), cd*Math.cos(phi), sd); + //Point3D x = new Point3D(d*Math.cos(phi),d*Math.sin(phi), z); + Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); + + + Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); + //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + //if(u.y() <0) + // u = u.multiply(-1); + //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); + Ray ray = new Ray(x, u); + //System.out.println("doca " + d); + //System.out.println("td " + td); + + return ray; + } + + + + private double getDoca(Trajectory track) { + if(track instanceof StraightTrack) { + Ray ray = track.get_ray(); + double intercept = ray.get_yxinterc(); + double slope = ray.get_yxslope(); + return Math.abs(intercept)/Math.hypot(1, slope); + } else return track.get_helix().get_dca(); + } + + private void fillMisc(DataEvent event, int runNum, int eventNum, List trackIDs, + List As, List Bs, List Vs, List ms, List cs, + List is) { + DataBank bank = event.createBank("Align::misc", trackIDs.size()); + for(int i = 0; i 10) { //this can only happen if the angle between the track and the normal is small + //System.out.println("rejecting track"); + return false; + } + int index = nAlignables-1; + + + //Use the same reference point for both inner and outer layer of region + Vector3d cref = new Vector3d(0,0,0); + + + + //for debugging + /* + double phi1 = Math.atan2(n.y, n.x), phi2 = Math.atan2(cref.y, cref.x); + double dphi = phi1-phi2; + while (dphi < -Math.PI) + dphi += 2*Math.PI; + while (dphi > Math.PI) + dphi -= 2*Math.PI; + System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); + */ + + Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); + dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); + /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 3, dmdr.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 4, dmdr.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ + + //System.out.println("i = " + i + "; rows = " + A.getRowDimension() + "; cols = " + + A.getColumnDimension()); + if(orderTx >= 0) + A.set(i, i*nAlignVars + orderTx, -sp.x); + if(orderTy >= 0) + A.set(i, i*nAlignVars + orderTy, -sp.y); + if(orderTz >= 0) + A.set(i, i*nAlignVars + orderTz, -sp.z); + if(orderRx >= 0) + A.set(i, i*nAlignVars + orderRx, dmdr.x); + if(orderRy >= 0) + A.set(i, i*nAlignVars + orderRy, dmdr.y); + if(orderRz >= 0) + A.set(i, i*nAlignVars + orderRz, dmdr.z); + + + + I.set(i, 0, index); + + Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); + if(!this.useDocaPhiZTandip) { + B.set(i,0, sp.x); + B.set(i,1, sp.z); + B.set(i,2, dmdu.x); + B.set(i,3, dmdu.z); + } else { + + double phi = Math.atan2(u.y,u.x); + Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); + Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x, u.y); + double d = mscphi.dot(xref); + B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); + //B.set(i, 1, s.dot(csphi.times(-d) + // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) + // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(u.times(d*n.dot(csphi)/udotn))) + // ); + B.set(i, 1, -s.dot(csphi)*d + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) + + sdotu/udotn*d*n.dot(csphi)); + B.set(i, 2, s.z-sdotu*n.z/udotn); + B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); + + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + + double ci = s.dot(extrap); + double mi = s.dot(e); + + + System.out.println(extrap.toStlString()); + System.out.println(e.toStlString()); + System.out.println(extrap.minus(e).toStlString()); + System.out.println(s.toStlString()); + + if(Math.abs(ci-mi)>maxResidualCut) + return false; + c.set(i,0,ci); + m.set(i,0,mi); + + return true; + } + + //returns false if there's a problem + private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { + int region = cl.get_Region(); + int layer = cl.get_Layer(); + int sector = cl.get_Sector(); + //System.out.println("RLS " + region + " " + layer + " " + sector); + //System.out.println("th" + c.get_Phi()); + double centroid = cl.get_Centroid(); + + // this avoids a certain bug that only occurs if + // there is a single-hit cluster on the last strip, + // in which obtaining the next strip (line2) gives + // an IllegalArgumentException + + + if(centroid == SVTConstants.NSTRIPS) + centroid = SVTConstants.NSTRIPS-.001; + Line3d line1 = SVTGeom.getStripFactory().getShiftedStrip(layer-1, sector-1, (int)Math.floor(centroid)-1); + Line3d line2 = SVTGeom.getStripFactory().getShiftedStrip(layer-1, sector-1, (int)Math.floor(centroid)-0); + + //System.out.println( SVTConstants.getLayerSectorAlignmentData()[0][0][1]); + + + //take the weighted average of the directions of the two lines. + Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); + + Vector3d e1 = line1.origin(); + Vector3d e2 = line2.origin(); + Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); + Vector3d s = e2.minus(e1); + s = s.minus(l.times(s.dot(l))).normalized(); + + Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); + Vector3d u = convertVector(ray.get_dirVec()); + Vector3d n = l.cross(s); + double udotn = u.dot(n); + if(Math.abs(udotn)<0.01) { + if(debug) System.out.println("rejecting track: abs(udotn)<0.01"); + return false; + } + double sdotu = s.dot(u); + Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); + + + //System.out.println(extrap.toStlString()); + double resolution = cl.get_ResolutionAlongZ(extrap.z-SVTConstants.Z0ACTIVE[(layer-1)/2], SVTGeom); + //System.out.println("resolution: " + resolution + "; z=" + extrap.z-); + + V.set(i, i, Math.pow(resolution,2)); + + + Vector3d sp = s.minus(n.times(sdotu/udotn)); + if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small + if(debug) System.out.println("rejecting track: sp.magnitude() > 10"); + return false; + } + int index = getIndexSVT(layer-1, sector-1); + + + //Use the same reference point for both inner and outer layer of region + Vector3d cref = getModuleReferencePoint(sector,layer); + + + + //for debugging + /* + double phi1 = Math.atan2(n.y, n.x), phi2 = Math.atan2(cref.y, cref.x); + double dphi = phi1-phi2; + while (dphi < -Math.PI) + dphi += 2*Math.PI; + while (dphi > Math.PI) + dphi -= 2*Math.PI; + System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); + */ + + Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); + dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); + /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 3, dmdr.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 4, dmdr.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ + if(orderTx >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, -sp.x); + if(orderTy >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, -sp.y); + if(orderTz >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, -sp.z); + if(orderRx >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, dmdr.x); + if(orderRy >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, dmdr.y); + if(orderRz >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, dmdr.z); + + + + I.set(i, 0, index); + + Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); + if(!this.useDocaPhiZTandip) { + B.set(i,0, sp.x); + B.set(i,1, sp.z); + B.set(i,2, dmdu.x); + B.set(i,3, dmdu.z); + } else { + + double phi = Math.atan2(u.y,u.x); + Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); + Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x, u.y); + double d = mscphi.dot(xref); + B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); + //B.set(i, 1, s.dot(csphi.times(-d) + // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) + // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(u.times(d*n.dot(csphi)/udotn))) + // ); + B.set(i, 1, -s.dot(csphi)*d + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) + + sdotu/udotn*d*n.dot(csphi)); + B.set(i, 2, s.z-sdotu*n.z/udotn); + B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); + + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + + double ci = s.dot(extrap); + double mi = s.dot(e); + if(Math.abs(ci-mi)>maxResidualCut) { + if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); + return false; + } + c.set(i,0,ci); + m.set(i,0,mi); + + + return true; + + } + boolean debug = false; + + + private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, + Matrix I) { + int region = cl.get_Region(); + int layer = cl.get_Layer(); + int sector = cl.get_Sector(); + double centroid = cl.get_Centroid(); + //Z layer + if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]) + centroid = org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]-.001; + Line3d line1 = convertLine(BMTGeom.getZstrip(region, sector, (int)Math.floor(centroid)-0)); + Line3d line2 = convertLine(BMTGeom.getZstrip(region, sector, (int)Math.floor(centroid)+1)); + + + + Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); + + Vector3d e1 = line1.origin(); + Vector3d e2 = line2.origin(); + Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); + Vector3d s = e2.minus(e1); + s = s.minus(l.times(s.dot(l))).normalized(); + + + Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); + Vector3d u = convertVector(ray.get_dirVec()); + Vector3d n = l.cross(s); + double udotn = u.dot(n); + if(Math.abs(udotn)<0.01) + return false; + double sdotu = s.dot(u); + + Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); + //org.jlab.rec.cvt.bmt.Constants. + //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); + + //System.out.println(extrap.toStlString()); + double resolution = e1.distance(e2)/Math.sqrt(12); + + + V.set(i, i, Math.pow(resolution,2)); + + + Vector3d sp = s.minus(n.times(sdotu/udotn)); + if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small + System.out.println("rejecting track"); + return false; + } + int index = getIndexBMT(layer-1, sector-1); + + + //Use the same reference point for both inner and outer layer of region + Vector3d cref = getModuleReferencePoint(sector,layer); + + + + //for debugging + /* + double phi1 = Math.atan2(n.y, n.x), phi2 = Math.atan2(cref.y, cref.x); + double dphi = phi1-phi2; + while (dphi < -Math.PI) + dphi += 2*Math.PI; + while (dphi > Math.PI) + dphi -= 2*Math.PI; + System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); + */ + + Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); + dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); + /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 3, dmdr.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 4, dmdr.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ + if(orderTx >= 0) + A.set(i, i*nAlignVars + orderTx, -sp.x); + if(orderTy >= 0) + A.set(i, i*nAlignVars + orderTy, -sp.y); + if(orderTz >= 0) + A.set(i, i*nAlignVars + orderTz, -sp.z); + if(orderRx >= 0) + A.set(i, i*nAlignVars + orderRx, dmdr.x); + if(orderRy >= 0) + A.set(i, i*nAlignVars + orderRy, dmdr.y); + if(orderRz >= 0) + A.set(i, i*nAlignVars + orderRz, dmdr.z); + + + + I.set(i, 0, index); + + Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); + if(!this.useDocaPhiZTandip) { + B.set(i,0, sp.x); + B.set(i,1, sp.z); + B.set(i,2, dmdu.x); + B.set(i,3, dmdu.z); + } else { + + double phi = Math.atan2(u.y,u.x); + Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); + Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x, u.y); + double d = mscphi.dot(xref); + B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); + //B.set(i, 1, s.dot(csphi.times(-d) + // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) + // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(u.times(d*n.dot(csphi)/udotn))) + // ); + B.set(i, 1, -s.dot(csphi)*d + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) + + sdotu/udotn*d*n.dot(csphi)); + B.set(i, 2, s.z-sdotu*n.z/udotn); + B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); + + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + //c.set(i,0,s.dot(extrap)); + //m.set(i,0,s.dot(e)); + double mi = e1.distance(e2)*centroid; + double ci = mi+s.dot(extrap.minus(e)); + m.set(i, 0, mi); + if(Math.abs(ci-mi)>maxResidualCut) + return false; + c.set(i, 0, ci); + + return true; + + } + private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, + Matrix I) { + + int region = cl.get_Region(); + int layer = cl.get_Layer(); + int sector = cl.get_Sector(); + //System.out.println(region+" "+layer +" "+sector); + double centroid = cl.get_Centroid(); + if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]) + centroid = org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]-.001; + + Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); + Vector3d u = convertVector(ray.get_dirVec()); + + Arc3D arc1 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-1); + Arc3D arc2 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-0); + + //find the extrapolation point to the cylinder + double R = arc1.radius(); + //cylindrical axis + Vector3d axis = convertVector(arc1.normal()); + Vector3d center = convertVector(arc1.center().toVector3D()); + double a = 1-Math.pow(u.dot(axis),2); + double b = 2*center.minus(xref).dot(u.minus(axis.times(axis.dot(u)))); + double cc = xref.minus(center).minus(axis.times(axis.dot(xref.minus(center)))).magnitudeSq()-R*R; + // two intersections between line and cylinder. Whichever is closest to the midpoint of the strip + // is chosen + double lambda = (-b+Math.sqrt(b*b-4*a*cc))/(2*a); + double lambda_alt = (-b-Math.sqrt(b*b-4*a*cc))/(2*a); + Vector3d extrap1 = xref.plus(u.times(lambda)); + Vector3d extrap2 = xref.plus(u.times(lambda_alt)); + Vector3d midpoint = midpoint(arc1).midpoint(midpoint(arc2)); + Vector3d extrap = null; + if(extrap1.distance(midpoint) > (extrap2.distance(midpoint))) + extrap = extrap2; + else + extrap = extrap1; + + Vector3d s = axis; + Vector3d n = extrap.minus(center); + n = n.minus(axis.times(axis.dot(n))).normalized(); + Vector3d l = s.cross(n); + + + //System.out.printf("s vector %f %f %f\n", s.x,s.y,s.z); + //System.out.printf("n vector %f %f %f\n", n.x,n.y,n.z); + //System.out.printf("l vector %f %f %f\n", l.x,l.y,l.z); + //Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); + + Vector3d e1 = convertVector(arc1.origin().toVector3D()); + Vector3d e2 = convertVector(arc2.origin().toVector3D()); + Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); + //Vector3d s = e2.minus(e1); + //s = s.minus(l.times(s.dot(l))).normalized(); + + + + double udotn = u.dot(n); + if(Math.abs(udotn)<0.01) + return false; + double sdotu = s.dot(u); + + + //org.jlab.rec.cvt.bmt.Constants. + //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); + + //System.out.println(extrap.toStlString()); + + + double resolution = e1.distance(e2)/Math.sqrt(12); + //fake resolution + resolution = 1; + V.set(i, i, Math.pow(resolution,2)); + + + Vector3d sp = s.minus(n.times(sdotu/udotn)); + if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small + System.out.println("rejecting track"); + return false; + } + int index = getIndexBMT(layer-1, sector-1); + + + //Use the same reference point for both inner and outer layer of region + Vector3d cref = getModuleReferencePoint(sector,layer); + + Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); + dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); + /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 3, dmdr.x); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 4, dmdr.y); + A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ + if(orderTx >= 0) + A.set(i, i*nAlignVars + orderTx, -sp.x); + if(orderTy >= 0) + A.set(i, i*nAlignVars + orderTy, -sp.y); + if(orderTz >= 0) + A.set(i, i*nAlignVars + orderTz, -sp.z); + if(orderRx >= 0) + A.set(i, i*nAlignVars + orderRx, dmdr.x); + if(orderRy >= 0) + A.set(i, i*nAlignVars + orderRy, dmdr.y); + if(orderRz >= 0) + A.set(i, i*nAlignVars + orderRz, dmdr.z); + + + + I.set(i, 0, index); + + Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); + if(!this.useDocaPhiZTandip) { + B.set(i,0, sp.x); + B.set(i,1, sp.z); + B.set(i,2, dmdu.x); + B.set(i,3, dmdu.z); + } else { + + double phi = Math.atan2(u.y,u.x); + Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); + Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x, u.y); + double d = mscphi.dot(xref); + B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); + //B.set(i, 1, s.dot(csphi.times(-d) + // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) + // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(u.times(d*n.dot(csphi)/udotn))) + // ); + B.set(i, 1, -s.dot(csphi)*d + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(extrap.minus(xref)) + + sdotu/udotn*d*n.dot(csphi)); + B.set(i, 2, s.z-sdotu*n.z/udotn); + B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(extrap.minus(xref))); + + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + double ci = s.dot(extrap); + double mi = s.dot(e); + if(Math.abs(ci-mi)>maxResidualCut) + return false; + c.set(i,0,ci); + m.set(i,0,mi); + + return true; + } + + private Vector3d midpoint(Arc3D arc1) { + + return convertVector(arc1.point(arc1.theta()/2).toVector3D()); + } + + private int getIndex(Cluster c) { + int layer = c.get_Layer()-1; + int sector = c.get_Sector()-1; + int index = -1; + if(c.get_Detector() == 0) { + int region = layer/2; + if (region == 0) + index = sector; + else if (region == 1) + index = org.jlab.rec.cvt.svt.Constants.NSECT[0] + sector; + else if (region == 2) + index = org.jlab.rec.cvt.svt.Constants.NSECT[0] + + org.jlab.rec.cvt.svt.Constants.NSECT[2] + sector; + if(svtTopBottomSep && layer%2==1) { + index += 42; + } + } else if (c.get_Detector() == 1) { + index = 84+layer*3+sector; + } + + return index; + } + + private int getIndexBMT(int layer, int sector) { + if (layer < 0 || sector < 0) + return -1; + return 84+layer*3+sector; + } + + private int getIndexSVT(int layer, int sect){ + int index = -1; + int region = layer/2; + if (region == 0) + index = sect; + else if (region == 1) + index = org.jlab.rec.cvt.svt.Constants.NSECT[0] + sect; + else if (region == 2) + index = org.jlab.rec.cvt.svt.Constants.NSECT[0] + + org.jlab.rec.cvt.svt.Constants.NSECT[2] + sect; + if(svtTopBottomSep && layer%2==1) { + index += 42; + } + return index; + + } + + private Vector3d getModuleReferencePoint(int sector, int layer) { + return SVTAlignmentFactory.getIdealFiducialCenter((layer-1)/2, sector-1); + } + + @Override + public boolean init() { + if(this.getEngineConfiguration() == null || "null".equals(this.getEngineConfiguration())) { + return true; //prevents init from being run twice. + } + // Load config + String rmReg = this.getEngineConfigString("removeRegion"); + + if (rmReg!=null) { + System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on yaml"); + Constants.setRmReg(Integer.valueOf(rmReg)); + } + else { + rmReg = System.getenv("COAT_CVT_REMOVEREGION"); + if (rmReg!=null) { + System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on env"); + Constants.setRmReg(Integer.valueOf(rmReg)); + } + } + if (rmReg==null) { + System.out.println("["+this.getName()+"] run with all region (default) "); + } + //svt stand-alone + String svtStAl = this.getEngineConfigString("svtOnly"); + + if (svtStAl!=null) { + System.out.println("["+this.getName()+"] align SVT only "+svtStAl+" config chosen based on yaml"); + this.isSVTonly= Boolean.valueOf(svtStAl); + } + else { + svtStAl = System.getenv("COAT_ALIGN_SVT_ONLY"); + if (svtStAl!=null) { + System.out.println("["+this.getName()+"] align SVT only "+svtStAl+" config chosen based on env"); + this.isSVTonly= Boolean.valueOf(svtStAl); + } + } + if (svtStAl==null) { + System.out.println("["+this.getName()+"] align SVT only (default) "); + this.isSVTonly = true; + } + + String bmtOnly = this.getEngineConfigString("bmtOnly"); + + if (bmtOnly!=null) { + System.out.println("["+this.getName()+"] align BMT only "+bmtOnly+" config chosen based on yaml"); + this.isBMTonly= Boolean.valueOf(bmtOnly); + } + else { + bmtOnly = System.getenv("COAT_ALIGN_SVT_ONLY"); + if (bmtOnly!=null) { + System.out.println("["+this.getName()+"] align BMT only "+bmtOnly+" config chosen based on env"); + this.isBMTonly= Boolean.valueOf(bmtOnly); + } + } + if (bmtOnly==null) { + System.out.println("["+this.getName()+"] not BMT only (default) "); + this.isBMTonly = false; + } + // Load other geometries + + variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); + System.out.println(" CVT YAML VARIATION NAME + "+variationName); + + System.out.println("SVT LOADING WITH VARIATION "+variationName); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); + //cp = new HackConstantsProvider(cp); + cp = SVTConstants.connect( cp ); + cp.disconnect(); + CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variationName)); + xb = org.jlab.rec.cvt.Constants.getXb(); + yb = org.jlab.rec.cvt.Constants.getYb(); + System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][0])); + System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][1])); + SVTStripFactory svtFac = new SVTStripFactory(cp, true); + SVTGeom.setSvtStripFactory(svtFac); + + String svtTopBottomSep = this.getEngineConfigString("svtAlignTopBottomSeparately"); + if (svtTopBottomSep!=null) { + System.out.println("["+this.getName()+"] run with SVT alignment for top and bottom as separate modules "+svtTopBottomSep+" config chosen based on yaml"); + this.svtTopBottomSep= Boolean.valueOf(svtTopBottomSep); + } + else { + svtTopBottomSep = System.getenv("COAT_SVT_TOP_BOTTOM"); + if (svtTopBottomSep!=null) { + System.out.println("["+this.getName()+"] run with SVT alignment for top and bottom as separate modules "+svtTopBottomSep+" config chosen based on env"); + this.svtTopBottomSep= Boolean.valueOf(svtTopBottomSep); + } + } + if (svtTopBottomSep==null) { + System.out.println("["+this.getName()+"] run with SVT top and bottom as a single module (default) "); + this.svtTopBottomSep = false; + } + + String alignVars = this.getEngineConfigString("alignVariables"); + if (alignVars!=null) { + System.out.println("["+this.getName()+"] obtain alignment derivatives for the following variables "+svtTopBottomSep+" config chosen based on yaml"); + this.setAlignVars(alignVars); + } + else { + alignVars = System.getenv("COAT_ALIGN_VARS"); + if (alignVars!=null) { + System.out.println("["+this.getName()+"] obtain alignment derivatives for the following variables "+svtTopBottomSep+" config chosen based on env"); + this.setAlignVars(alignVars); + } + } + if (alignVars==null) { + System.out.println("["+this.getName()+"] obtain alignment derivatives for all 6 variables (default) "); + this.setAlignVars("Tx Ty Tz Rx Ry Rz"); + } + + + String maxDocaCut = this.getEngineConfigString("maxDocaCut"); + + if(maxDocaCut != null) { + System.out.println("["+this.getName()+"] max doca cut "+ maxDocaCut + " mm"); + this.maxDocaCut = Double.parseDouble(maxDocaCut); + } + else { + System.out.println("["+this.getName()+"] no max doca cut set (default)"); + this.maxDocaCut = Double.MAX_VALUE; + } + + String cosmics = this.getEngineConfigString("cosmics"); + + if(cosmics != null) { + System.out.println("["+this.getName()+"] use cosmics bank instead of tracks bank? "+ cosmics ); + this.isCosmics = Boolean.parseBoolean(cosmics); + } + else { + System.out.println("["+this.getName()+"] using tracks bank (default)"); + this.isCosmics = false; + } + + //svt stand-alone + String maxResidual = this.getEngineConfigString("maxResidual"); + + if (maxResidual!=null) { + System.out.println("["+this.getName()+"] run with cut on maximum residual "+maxResidual+" config chosen based on yaml"); + this.maxResidualCut = Double.valueOf(maxResidual); + } + + if (maxResidual==null) { + System.out.println("["+this.getName()+"] run with maximum residual cut setting default = none"); + this.maxResidualCut = Double.MAX_VALUE; + } + + for(int layer = 0; layer<6; layer++) + { + Line3d line = SVTGeom.getStrip(layer, 0, 0); + System.out.println("debug. Layer" + layer + " (" + line.origin().x + ", "+ line.origin().y + ", "+ line.origin().z+"), " + + " (" + line.end().x + ", "+ line.end().y + ", "+ line.end().z+"), "); + } + + this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (isCosmics? 0 : 1)); + + //svt stand-alone + String debug = this.getEngineConfigString("debug"); + + if (debug!=null) { + System.out.println("["+this.getName()+"] debug "+debug+" config chosen based on yaml"); + this.debug = Boolean.parseBoolean(debug); + } else { + System.out.println("["+this.getName()+"] debug false; config chosen based on yaml"); + this.debug = false; + } + + + return true; + } + + double xb, yb; + + double maxResidualCut; + + double maxDocaCut; + + + + private void setAlignVars(String alignVars) { + String split[] = alignVars.split("[ \t]+"); + int i = 0; + orderTx = -1; + orderTy = -1; + orderTz = -1; + orderRx = -1; + orderRy = -1; + orderRz = -1; + for(String s : split) { + if(s.equals("Tx")) { + orderTx = i; i++; + } else if(s.equals("Ty")) { + orderTy = i; i++; + } else if(s.equals("Tz")) { + orderTz = i; i++; + } else if(s.equals("Rx")) { + orderRx = i; i++; + } else if(s.equals("Ry")) { + orderRy = i; i++; + } else if(s.equals("Rz")) { + orderRz = i; i++; + } + } + nAlignVars = i; + System.out.println(nAlignVars + " alignment variables requested"); + } + private int nAlignVars; + private int orderTx; + private int orderTy; + private int orderTz; + private int orderRx; + private int orderRy; + private int orderRz; + + private String variationName; + + +} \ No newline at end of file From a3c9f1af4f2d01cb50c8e2d7184349c8ec3c82f3 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 26 Apr 2021 13:17:46 -0400 Subject: [PATCH 105/291] added align.json from the dev-align2 branch From 590177a0e3e639081ff84b52a5cbc4580804eac6 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Tue, 27 Apr 2021 16:06:46 -0400 Subject: [PATCH 106/291] removed shift in cvt prealignment --- .../src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java | 4 ++-- .../main/java/org/jlab/rec/cvt/services/CVTAlignment.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 13aa06cec..e35a9cf15 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -374,7 +374,7 @@ private void fetch_SVTHits(DataEvent event) { int sector = bank.getByte("sector", i); int strip = bank.getInt("strip", i); int id = bank.getShort("ID", i); - FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0,0)); + FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0)); hit.set_Id(id); hit.set_docaToTrk(bank.getFloat("fitResidual", i)); @@ -396,7 +396,7 @@ public void fetch_BMTHits(DataEvent event) { int sector = bank.getByte("sector", i); int strip = bank.getInt("strip", i); int id = bank.getShort("ID", i); - FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0,0)); + FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0)); hit.set_Id(id); hit.set_docaToTrk(bank.getFloat("fitResidual", i)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 667f1e9b1..13321afc3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -30,6 +30,7 @@ import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; +import org.jlab.rec.cvt.bmt.Geometry; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.track.StraightTrack; @@ -353,8 +354,8 @@ private Ray getRay(Helix h) { Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); - Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); - //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + //Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); + Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); //if(u.y() <0) // u = u.multiply(-1); //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); From a59edd90ff9b2c77c579bb64a3c39a931c6a3fea Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 3 May 2021 17:09:57 -0400 Subject: [PATCH 107/291] Fixed bug where the run number was being set to the actual run number (instead of staying at 11). Also minor stuff like using LCZ strip --- .../java/org/jlab/rec/cvt/services/CVTAlignment.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 13321afc3..9fa564038 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -17,6 +17,7 @@ import org.jlab.geom.base.ConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -113,8 +114,8 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int if(Math.abs(SolenoidScale)<0.001) Constants.setCosmicsData(true); - System.out.println(" LOADING BMT GEOMETRY...............................variation = "+variationName); - CCDBConstantsLoader.Load(new DatabaseConstantProvider(newRun, variationName)); + //System.out.println(" LOADING BMT GEOMETRY...............................variation = "+variationName); + //CCDBConstantsLoader.Load(new DatabaseConstantProvider(newRun, variationName)); // System.out.println("SVT LOADING WITH VARIATION "+variationName); // DatabaseConstantProvider cp = new DatabaseConstantProvider(newRun, variationName); // cp = SVTConstants.connect( cp ); @@ -694,12 +695,12 @@ private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, //Z layer if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]) centroid = org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]-.001; - Line3d line1 = convertLine(BMTGeom.getZstrip(region, sector, (int)Math.floor(centroid)-0)); - Line3d line2 = convertLine(BMTGeom.getZstrip(region, sector, (int)Math.floor(centroid)+1)); + Line3d line1 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)-1)); + Line3d line2 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)+0)); - Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); + Vector3d l = line1.diff().normalized();//.times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); Vector3d e1 = line1.origin(); Vector3d e2 = line2.origin(); From fc886345294327a26ff2d06127d2bc239d1ec2ab Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 18 May 2021 11:18:18 -0400 Subject: [PATCH 108/291] Added banks for alignment. --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 59 ++- .../org/jlab/rec/cvt/cluster/Cluster.java | 405 +++++++++++++++++- .../jlab/rec/cvt/cluster/ClusterFinder.java | 4 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 4 +- 4 files changed, 440 insertions(+), 32 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index a8dbd8aff..d55c0b3bd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -102,9 +102,26 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { hitStrg += "_ID"; bank.setShort(hitStrg, i, (short) hitIdxArray[j]); } - - } - //bank.show(); + + bank.setFloat("x1", i, (float)cluslist.get(i).getX1()); + bank.setFloat("y1", i, (float)cluslist.get(i).getY1()); + bank.setFloat("z1", i, (float)cluslist.get(i).getZ1()); + bank.setFloat("x2", i, (float)cluslist.get(i).getX2()); + bank.setFloat("y2", i, (float)cluslist.get(i).getY2()); + bank.setFloat("z2", i, (float)cluslist.get(i).getZ2()); + bank.setFloat("lx", i, (float)cluslist.get(i).getL().x()); + bank.setFloat("ly", i, (float)cluslist.get(i).getL().y()); + bank.setFloat("lz", i, (float)cluslist.get(i).getL().z()); + bank.setFloat("sx", i, (float)cluslist.get(i).getS().x()); + bank.setFloat("sy", i, (float)cluslist.get(i).getS().y()); + bank.setFloat("sz", i, (float)cluslist.get(i).getS().z()); + bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); + bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); + bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); + bank.setFloat("e", i, (float)cluslist.get(i).get_CentroidError()); + + } + bank.show(); return bank; } @@ -238,9 +255,39 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { hitStrg += "_ID"; bank.setShort(hitStrg, i, (short) hitIdxArray[j]); } - - } - + + bank.setFloat("x1", i, (float)cluslist.get(i).getX1()); + bank.setFloat("y1", i, (float)cluslist.get(i).getY1()); + bank.setFloat("z1", i, (float)cluslist.get(i).getZ1()); + bank.setFloat("x2", i, (float)cluslist.get(i).getX2()); + bank.setFloat("y2", i, (float)cluslist.get(i).getY2()); + bank.setFloat("z2", i, (float)cluslist.get(i).getZ2()); + bank.setFloat("ox", i, (float)cluslist.get(i).getOx()); + bank.setFloat("oy", i, (float)cluslist.get(i).getOy()); + bank.setFloat("oz", i, (float)cluslist.get(i).getOz()); + bank.setFloat("cx", i, (float)cluslist.get(i).getCx()); + bank.setFloat("cy", i, (float)cluslist.get(i).getCy()); + bank.setFloat("cz", i, (float)cluslist.get(i).getCz()); + bank.setFloat("theta",i, (float)cluslist.get(i).getTheta()); + bank.setFloat("ax1", i, (float)cluslist.get(i).getCylAxis().origin().x()); + bank.setFloat("ay1", i, (float)cluslist.get(i).getCylAxis().origin().y()); + bank.setFloat("az1", i, (float)cluslist.get(i).getCylAxis().origin().z()); + bank.setFloat("ax2", i, (float)cluslist.get(i).getCylAxis().end().x()); + bank.setFloat("ay2", i, (float)cluslist.get(i).getCylAxis().end().y()); + bank.setFloat("az2", i, (float)cluslist.get(i).getCylAxis().end().z()); + bank.setFloat("lx", i, (float)cluslist.get(i).getL().x()); + bank.setFloat("ly", i, (float)cluslist.get(i).getL().y()); + bank.setFloat("lz", i, (float)cluslist.get(i).getL().z()); + bank.setFloat("sx", i, (float)cluslist.get(i).getS().x()); + bank.setFloat("sy", i, (float)cluslist.get(i).getS().y()); + bank.setFloat("sz", i, (float)cluslist.get(i).getS().z()); + bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); + bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); + bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); + bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); + + } + bank.show(); return bank; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 6cf4ed056..f5eedfaae 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -1,7 +1,10 @@ package org.jlab.rec.cvt.cluster; import java.util.ArrayList; +import org.jlab.geom.prim.Cylindrical3D; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; @@ -33,6 +36,26 @@ public class Cluster extends ArrayList implements Comparable private double _PhiErr0; private double _Z; // for C-detectors private double _ZErr; + + //added variables for alignment + private double _x1; //cluster first end point x + private double _y1; //svt cluster first end point y + private double _z1; //svt cluster first end point z + private double _x2; //svt cluster second end point x + private double _y2; //svt cluster second end point y + private double _z2; //svt cluster second end point z + private double _ox; //bmt cluster arc origin x + private double _oy; //bmt cluster arc origin y + private double _oz; //bmt cluster arc origin z + private double _cx; //bmt cluster arc center x + private double _cy; //bmt cluster arc center y + private double _cz; //bmt cluster arc center z + private double _theta; //bmt cluster arc theta + private Line3D _cyl; // bmt axis + private Vector3D _l; //svt vector along cluster pseudo-strip direction or bmt vector along cluster pseudo-strip direction in the middle of the arc + private Vector3D _s; //svt vector perpendicular to cluster pseudo-strip direction in the module plane or bmt vector perpendicular to cluster pseudo-strip in direction tangential to the cluster surface in the middle of the arc + private Vector3D _n; //svt vector normal to the cluster module plane or bmt vector normal to the cluster surface in the middle of the arc + public Cluster(int detector, int detectortype, int sector, int layer, int cid) { this._Detector = detector; @@ -139,7 +162,8 @@ public int get_RegionSlayer() { * (energy-weighted) value, the energy-weighted phi for Z detectors and the * energy-weighted z for C detectors */ - public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { + public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, + org.jlab.rec.cvt.bmt.BMTGeometry geo) { // instantiation of variables double stripNumCent = 0; // cluster Lorentz-angle-corrected energy-weighted strip = centroid double stripNumCent0 = 0; // cluster uncorrected energy-weighted strip = centroid @@ -158,12 +182,16 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { double weightedPhiErrSq0 = 0; // Err^2 on uncorrected energy-weighted phi of the strip double weightedZ = 0; // Energy-weighted z of the strip double weightedZErrSq = 0; // Err^2 on energy-weighted z of the strip - double weightedX1 = 0; // SVT strip centroid positions of endpoints - double weightedX2 = 0; // SVT strip centroid positions of endpoints - double weightedY1 = 0; // SVT strip centroid positions of endpoints - double weightedY2 = 0; // SVT strip centroid positions of endpoints - double weightedZ1 = 0; // SVT strip centroid positions of endpoints - double weightedZ2 = 0; // SVT strip centroid positions of endpoints + double weightedX1 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedX2 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedXC = 0; // BMT strip centroid positions of arc center + double weightedY1 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedY2 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedYC = 0; // BMT strip centroid positions of arc center + double weightedZ1 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedZ2 = 0; // SVT/BMT strip centroid positions of endpoints + double weightedZC = 0; // BMT strip centroid positions of arc center + /* this.set_ImplantPoint(arcLine.origin()); this.set_MidPoint(arcLine.center()); @@ -198,20 +226,32 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { weightedZ2 += strpEn * stEP2.z(); } if (this.get_Detector()==1) { + Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); + Point3D stEP2 = thehit.get_Strip().get_EndPoint(); + Point3D stCent = thehit.get_Strip().get_MidPoint(); + weightedX1 += strpEn * stEP1.x(); + weightedY1 += strpEn * stEP1.y(); + weightedZ1 += strpEn * stEP1.z(); + weightedX2 += strpEn * stEP2.x(); + weightedY2 += strpEn * stEP2.y(); + weightedZ2 += strpEn * stEP2.z(); + weightedXC += strpEn * stCent.x(); + weightedYC += strpEn * stCent.y(); + weightedZC += strpEn * stCent.z(); // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_DetectorType()==0) { // C-detectors strpNb = thehit.get_Strip().get_Strip(); // for C detector the Z of the centroid is calculated weightedZ += strpEn * thehit.get_Strip().get_Z(); weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); - Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); - Point3D stEP2 = thehit.get_Strip().get_EndPoint(); - weightedX1 += strpEn * stEP1.x(); - weightedY1 += strpEn * stEP1.y(); - weightedZ1 += strpEn * stEP1.z(); - weightedX2 += strpEn * stEP2.x(); - weightedY2 += strpEn * stEP2.y(); - weightedZ2 += strpEn * stEP2.z(); +// Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); +// Point3D stEP2 = thehit.get_Strip().get_EndPoint(); +// weightedX1 += strpEn * stEP1.x(); +// weightedY1 += strpEn * stEP1.y(); +// weightedZ1 += strpEn * stEP1.z(); +// weightedX2 += strpEn * stEP2.x(); +// weightedY2 += strpEn * stEP2.y(); +// weightedZ2 += strpEn * stEP2.z(); } if (this.get_DetectorType()==1) { // Z-detectors // for Z detectors Lorentz-correction is applied to the strip @@ -222,12 +262,14 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); weightedPhi0 += strpEn * thehit.get_Strip().get_Phi0(); weightedPhiErrSq0 += (thehit.get_Strip().get_PhiErr0()) * (thehit.get_Strip().get_PhiErr0()); - Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); - Point3D stEP2 = thehit.get_Strip().get_EndPoint(); - weightedX1 += strpEn * stEP1.x(); - weightedY1 += strpEn * stEP1.y(); - weightedX2 += strpEn * stEP2.x(); - weightedY2 += strpEn * stEP2.y(); +// Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); +// Point3D stEP2 = thehit.get_Strip().get_EndPoint(); +// weightedX1 += strpEn * stEP1.x(); +// weightedY1 += strpEn * stEP1.y(); +// weightedZ1 += strpEn * stEP1.z(); +// weightedX2 += strpEn * stEP2.x(); +// weightedY2 += strpEn * stEP2.y(); +// weightedZ2 += strpEn * stEP2.z(); } } @@ -274,6 +316,85 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { zErrCent = Math.sqrt(weightedZErrSq); this.setEndPoint1(new Point3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn)); this.setEndPoint2(new Point3D(weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); + //setting variables used for alignment + //----------------------------------- + if (this.get_Detector()==0) { //SVT + this.setX1(weightedX1/totEn); + this.setY1(weightedY1/totEn); + this.setZ1(weightedZ1/totEn); + this.setX2(weightedX2/totEn); + this.setY2(weightedY2/totEn); + this.setZ2(weightedZ2/totEn); + + Vector3D l = new Vector3D(weightedX2/totEn-weightedX1/totEn, + weightedY2/totEn-weightedY1/totEn, + weightedZ2/totEn-weightedZ1/totEn).asUnit(); + + Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). + vectorTo(sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer())).asUnit(); + + Vector3D n = sgeo.findBSTPlaneNormal(this.get_Sector(), this.get_Layer()); + + this.setL(l); + this.setS(s); + this.setN(n); + } + if (this.get_Detector()==1) { //BMT + Cylindrical3D cyl = geo.getCylinder(this.get_Layer(), this.get_Sector()); + // for the BMT the analysis distinguishes between C and Z type detectors + if (this.get_DetectorType()==0) { // C-detectors + this.setOx(weightedX1/totEn); + this.setOy(weightedY1/totEn); + this.setOz(weightedZ1/totEn); + this.setCx(weightedXC/totEn); + this.setCy(weightedYC/totEn); + this.setCz(weightedZC/totEn); + Vector3D C2P1 = new Vector3D(weightedX1/totEn-weightedXC/totEn, + weightedY1/totEn-weightedYC/totEn, + weightedZ1/totEn-weightedZC/totEn).asUnit(); + Vector3D C2P2 = new Vector3D(weightedX2/totEn-weightedXC/totEn, + weightedY2/totEn-weightedYC/totEn, + weightedZ2/totEn-weightedZC/totEn).asUnit(); + double theta = Math.acos(C2P1.dot(C2P2)); + this.setTheta(theta); + + Vector3D s = C2P1.cross(C2P2).asUnit(); + Vector3D n = cyl.baseArc().normal(); + Vector3D t = cyl.baseArc().center().vectorTo(cyl.baseArc().point(theta/2)); + Vector3D l = s.cross(t).asUnit(); + + this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); + this.setL(l); + this.setS(s); + this.setN(n); + + } + if (this.get_DetectorType()==1) { // Z-detectors + // for Z detectors Lorentz-correction is applied to the strip + this.setX1(weightedX1/totEn); + this.setY1(weightedY1/totEn); + this.setZ1(weightedZ1/totEn); + this.setX2(weightedX2/totEn); + this.setY2(weightedY2/totEn); + this.setZ2(weightedZ2/totEn); + + Vector3D l = new Vector3D(weightedX2/totEn-weightedX1/totEn, + weightedY2/totEn-weightedY1/totEn, + weightedZ2/totEn-weightedZ1/totEn).asUnit(); + Vector3D n = cyl.baseArc().center().vectorTo(new Point3D((weightedX2/totEn+weightedX1/totEn)/2, + (weightedY2/totEn+weightedY1/totEn)/2, + (weightedZ2/totEn+weightedZ1/totEn)/2)).asUnit(); + Vector3D s = l.cross(n); + + + this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); + this.setL(l); + this.setS(s); + this.setN(n); + + } + } + //phiErrCent = Math.sqrt(weightedPhiErrSq); //phiErrCent0 = Math.sqrt(weightedPhiErrSq0); //zErrCent = Math.sqrt(weightedZErrSq); @@ -286,13 +407,14 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { set_Centroid0(stripNumCent0); _Phi = phiCent; _PhiErr = phiErrCent; - + this.set_Error(geo.getRadius(_Layer)*phiErrCent); set_Phi0(phiCent0); set_PhiErr0(phiErrCent0); } if (this.get_DetectorType() == 0) { _Z = zCent; _ZErr = zErrCent; + this.set_Error(zErrCent); } } @@ -540,6 +662,245 @@ public void setEndPoint2(Point3D _EndPoint2) { this._EndPoint2 = _EndPoint2; } + /** + * @return the _x1 + */ + public double getX1() { + return _x1; + } + + /** + * @param _x1 the _x1 to set + */ + public void setX1(double _x1) { + this._x1 = _x1; + } + + /** + * @return the _y1 + */ + public double getY1() { + return _y1; + } + + /** + * @param _y1 the _y1 to set + */ + public void setY1(double _y1) { + this._y1 = _y1; + } + + /** + * @return the _z1 + */ + public double getZ1() { + return _z1; + } + + /** + * @param _z1 the _z1 to set + */ + public void setZ1(double _z1) { + this._z1 = _z1; + } + + /** + * @return the _x2 + */ + public double getX2() { + return _x2; + } + + /** + * @param _x2 the _x2 to set + */ + public void setX2(double _x2) { + this._x2 = _x2; + } + + /** + * @return the _y2 + */ + public double getY2() { + return _y2; + } + + /** + * @param _y2 the _y2 to set + */ + public void setY2(double _y2) { + this._y2 = _y2; + } + + /** + * @return the _z2 + */ + public double getZ2() { + return _z2; + } + + /** + * @param _z2 the _z2 to set + */ + public void setZ2(double _z2) { + this._z2 = _z2; + } + + /** + * @return the _ox + */ + public double getOx() { + return _ox; + } + + /** + * @param _ox the _ox to set + */ + public void setOx(double _ox) { + this._ox = _ox; + } + + /** + * @return the _oy + */ + public double getOy() { + return _oy; + } + + /** + * @param _oy the _oy to set + */ + public void setOy(double _oy) { + this._oy = _oy; + } + + /** + * @return the _oz + */ + public double getOz() { + return _oz; + } + + /** + * @param _oz the _oz to set + */ + public void setOz(double _oz) { + this._oz = _oz; + } + + /** + * @return the _cx + */ + public double getCx() { + return _cx; + } + + /** + * @param _cx the _cx to set + */ + public void setCx(double _cx) { + this._cx = _cx; + } + + /** + * @return the _cy + */ + public double getCy() { + return _cy; + } + + /** + * @param _cy the _cy to set + */ + public void setCy(double _cy) { + this._cy = _cy; + } + + /** + * @return the _cz + */ + public double getCz() { + return _cz; + } + + /** + * @param _cz the _cz to set + */ + public void setCz(double _cz) { + this._cz = _cz; + } + + /** + * @return the _theta + */ + public double getTheta() { + return _theta; + } + + /** + * @param _theta the _theta to set + */ + public void setTheta(double _theta) { + this._theta = _theta; + } + + /** + * @return the _cyl + */ + public Line3D getCylAxis() { + return _cyl; + } + + /** + * @param _cyl the _cyl to set + */ + public void setCylAxis(Line3D _cyl) { + this._cyl = _cyl; + } + + /** + * @return the _l + */ + public Vector3D getL() { + return _l; + } + + /** + * @param _l the _l to set + */ + public void setL(Vector3D _l) { + this._l = _l; + } + + /** + * @return the _s + */ + public Vector3D getS() { + return _s; + } + + /** + * @param _s the _s to set + */ + public void setS(Vector3D _s) { + this._s = _s; + } + + /** + * @return the _n + */ + public Vector3D getN() { + return _n; + } + + /** + * @param _n the _n to set + */ + public void setN(Vector3D _n) { + this._n = _n; + } + + private Point3D _EndPoint1; private Point3D _EndPoint2; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 71dcccca6..caf92fb7e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -23,7 +23,7 @@ public ClusterFinder() { int nstrip = 1200; // max number of strips int nlayr = 6; int nsec = 18; - public ArrayList findClusters(List hits2,org.jlab.rec.cvt.bmt.BMTGeometry geo_bmt) // the number of strips depends on the layer + public ArrayList findClusters(List hits2,org.jlab.rec.cvt.svt.Geometry geo_bst,org.jlab.rec.cvt.bmt.BMTGeometry geo_bmt) // the number of strips depends on the layer { ArrayList clusters = new ArrayList(); @@ -84,7 +84,7 @@ public ArrayList findClusters(List hits2,org.jlab.rec.cvt.bmt.BMTG h.set_AssociatedClusterID(this_cluster.get_Id()); } - this_cluster.calc_CentroidParams(geo_bmt); + this_cluster.calc_CentroidParams(geo_bst,geo_bmt); //make arraylist clusters.add(this_cluster); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index d02798dcc..f755c4c4d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -177,9 +177,9 @@ public boolean processDataEvent(DataEvent event) { //2) find the clusters from these hits ClusterFinder clusFinder = new ClusterFinder(); - clusters.addAll(clusFinder.findClusters(svt_hits, BMTGeom)); + clusters.addAll(clusFinder.findClusters(svt_hits, SVTGeom, BMTGeom)); if(bmt_hits != null && bmt_hits.size() > 0) - clusters.addAll(clusFinder.findClusters(bmt_hits, BMTGeom)); + clusters.addAll(clusFinder.findClusters(bmt_hits, SVTGeom, BMTGeom)); if (clusters.size() == 0) { rbc.appendCVTBanks(event, SVThits, BMThits, null, null, null, null, shift); From 9d23d17cd4633619d3730170052e9be74a0532d7 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 18 May 2021 11:19:01 -0400 Subject: [PATCH 109/291] Added banks for alignment. --- etc/bankdefs/hipo4/bmt.json | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/etc/bankdefs/hipo4/bmt.json b/etc/bankdefs/hipo4/bmt.json index 822112786..cf3e581f8 100644 --- a/etc/bankdefs/hipo4/bmt.json +++ b/etc/bankdefs/hipo4/bmt.json @@ -36,7 +36,36 @@ {"name":"Hit3_ID", "type":"S", "info":"Index of hit 3 in cluster"}, {"name":"Hit4_ID", "type":"S", "info":"Index of hit 4 in cluster"}, {"name":"Hit5_ID", "type":"S", "info":"Index of hit 5 in cluster"}, - {"name":"trkID", "type":"S", "info":"associated track ID"} + {"name":"trkID", "type":"S", "info":"associated track ID"}, + {"name":"x1", "type":"F", "info":"bmt-Z cluster first end point x"}, + {"name":"y1", "type":"F", "info":"bmt-Z cluster first end point y"}, + {"name":"z1", "type":"F", "info":"bmt-Z cluster first end point z"}, + {"name":"x2", "type":"F", "info":"bmt-Z cluster second end point x"}, + {"name":"y2", "type":"F", "info":"bmt-Z cluster second end point y"}, + {"name":"z2", "type":"F", "info":"bmt-Z cluster second end point z"}, + {"name":"ox", "type":"F", "info":"bmt-C cluster arc origin x"}, + {"name":"oy", "type":"F", "info":"bmt-C cluster arc origin y"}, + {"name":"oz", "type":"F", "info":"bmt-C cluster arc origin z"}, + {"name":"cx", "type":"F", "info":"bmt-C cluster arc center x"}, + {"name":"cy", "type":"F", "info":"bmt-C cluster arc center y"}, + {"name":"cz", "type":"F", "info":"bmt-C cluster arc center z"}, + {"name":"theta", "type":"F", "info":"cluster arc theta"}, + {"name":"ax1", "type":"F", "info":"bmt cylinder axis first end point x"}, + {"name":"ay1", "type":"F", "info":"bmt cylinder axis first end point y"}, + {"name":"az1", "type":"F", "info":"bmt cylinder axis first end point z"}, + {"name":"ax2", "type":"F", "info":"bmt cylinder axis second end point x"}, + {"name":"ay2", "type":"F", "info":"bmt cylinder axis second end point y"}, + {"name":"az2", "type":"F", "info":"bmt cylinder axis second end point z"}, + {"name":"lx", "type":"F", "info":"vector x comp along cluster pseudo-strip direction"}, + {"name":"ly", "type":"F", "info":"vector y comp along cluster pseudo-strip direction"}, + {"name":"lz", "type":"F", "info":"vector z comp along cluster pseudo-strip direction"}, + {"name":"sx", "type":"F", "info":"vector x comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"sy", "type":"F", "info":"vector y comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"sz", "type":"F", "info":"vector z comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"nx", "type":"F", "info":"vector x comp normal to the cluster module plane"}, + {"name":"ny", "type":"F", "info":"vector y comp normal to the cluster module plane"}, + {"name":"nz", "type":"F", "info":"vector z comp normal to the cluster module plane"}, + {"name":"e", "type":"F", "info":"cluster spacial uncertainty"} ] }, { From 39350714b202bd8ee20302b42f5aea0b5bbed638 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 18 May 2021 11:19:10 -0400 Subject: [PATCH 110/291] Added banks for alignment. --- etc/bankdefs/hipo4/bst.json | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/etc/bankdefs/hipo4/bst.json b/etc/bankdefs/hipo4/bst.json index f5fb4ac2e..1f362c16f 100644 --- a/etc/bankdefs/hipo4/bst.json +++ b/etc/bankdefs/hipo4/bst.json @@ -36,7 +36,23 @@ {"name":"Hit3_ID", "type":"S", "info":"Index of hit 3 in cluster"}, {"name":"Hit4_ID", "type":"S", "info":"Index of hit 4 in cluster"}, {"name":"Hit5_ID", "type":"S", "info":"Index of hit 5 in cluster"}, - {"name":"trkID", "type":"S", "info":"associated track ID"} + {"name":"trkID", "type":"S", "info":"associated track ID"}, + {"name":"x1", "type":"F", "info":"cluster first end point x"}, + {"name":"y1", "type":"F", "info":"cluster first end point y"}, + {"name":"z1", "type":"F", "info":"cluster first end point z"}, + {"name":"x2", "type":"F", "info":"cluster second end point x"}, + {"name":"y2", "type":"F", "info":"cluster second end point y"}, + {"name":"z2", "type":"F", "info":"cluster second end point z"}, + {"name":"lx", "type":"F", "info":"vector x comp along cluster pseudo-strip direction"}, + {"name":"ly", "type":"F", "info":"vector y comp along cluster pseudo-strip direction"}, + {"name":"lz", "type":"F", "info":"vector z comp along cluster pseudo-strip direction"}, + {"name":"sx", "type":"F", "info":"vector x comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"sy", "type":"F", "info":"vector y comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"sz", "type":"F", "info":"vector z comp perpendicular to cluster pseudo-strip direction in the module plane"}, + {"name":"nx", "type":"F", "info":"vector x comp normal to the cluster module plane"}, + {"name":"ny", "type":"F", "info":"vector y comp normal to the cluster module plane"}, + {"name":"nz", "type":"F", "info":"vector z comp normal to the cluster module plane"}, + {"name":"e", "type":"F", "info":"cluster spacial uncertainty"} ] }, { From 15257749c1aff42e578c74bdebe6597e15d99aba Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Tue, 18 May 2021 12:30:57 -0400 Subject: [PATCH 111/291] some cleanup before merging with TracTools-NewBanks --- .../jlab/rec/cvt/services/CVTAlignment.java | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 9fa564038..7b169137c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -154,11 +154,13 @@ public void setFieldsConfig(String fieldsConfig) { public boolean processDataEvent(DataEvent event) { int runNum = event.getBank("RUN::config").getInt("run", 0); int eventNum = event.getBank("RUN::config").getInt("event", 0); - this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); - + + + + //this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); double shift = 0;//org.jlab.rec.cvt.Constants.getZoffset();; - this.FieldsConfig = this.getFieldsConfig(); + //this.FieldsConfig = this.getFieldsConfig(); RecoBankReader reader = new RecoBankReader(); @@ -221,7 +223,7 @@ public boolean processDataEvent(DataEvent event) { continue; Ray ray = track.get_ray(); if(ray == null) { - ray = getRay(track.get_helix()); + ray = getRay(track.get_helix(),xb,yb); //System.out.println("curvature " + track.get_helix().get_curvature()); //System.out.println("doca " + track.get_helix().get_dca()); if(Math.abs(track.get_helix().get_curvature())>0.001) { @@ -342,7 +344,7 @@ else if(cross.get_DetectorType() == BMTType.C) { } int nAlignables; - private Ray getRay(Helix h) { + private Ray getRay(Helix h,double xb, double yb) { double d = h.get_dca(); double z = h.get_Z0(); @@ -355,8 +357,8 @@ private Ray getRay(Helix h) { Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); - //Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); - Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); + //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); //if(u.y() <0) // u = u.multiply(-1); //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); @@ -693,10 +695,10 @@ private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, int sector = cl.get_Sector(); double centroid = cl.get_Centroid(); //Z layer - if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]) - centroid = org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]-.001; - Line3d line1 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)-1)); - Line3d line2 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)+0)); + //if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]) + // centroid = org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]-.001; + Line3d line1 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid))); + Line3d line2 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)+1)); @@ -1018,7 +1020,8 @@ else if (region == 2) } private Vector3d getModuleReferencePoint(int sector, int layer) { - return SVTAlignmentFactory.getIdealFiducialCenter((layer-1)/2, sector-1); + //return SVTAlignmentFactory.getIdealFiducialCenter((layer-1)/2, sector-1); + return new Vector3d(0,0,0); } @Override @@ -1026,23 +1029,7 @@ public boolean init() { if(this.getEngineConfiguration() == null || "null".equals(this.getEngineConfiguration())) { return true; //prevents init from being run twice. } - // Load config - String rmReg = this.getEngineConfigString("removeRegion"); - - if (rmReg!=null) { - System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on yaml"); - Constants.setRmReg(Integer.valueOf(rmReg)); - } - else { - rmReg = System.getenv("COAT_CVT_REMOVEREGION"); - if (rmReg!=null) { - System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on env"); - Constants.setRmReg(Integer.valueOf(rmReg)); - } - } - if (rmReg==null) { - System.out.println("["+this.getName()+"] run with all region (default) "); - } + //svt stand-alone String svtStAl = this.getEngineConfigString("svtOnly"); @@ -1110,8 +1097,8 @@ public boolean init() { } } if (svtTopBottomSep==null) { - System.out.println("["+this.getName()+"] run with SVT top and bottom as a single module (default) "); - this.svtTopBottomSep = false; + System.out.println("["+this.getName()+"] run with SVT top and bottom as separate modules (default) "); + this.svtTopBottomSep = true; } String alignVars = this.getEngineConfigString("alignVariables"); @@ -1154,7 +1141,6 @@ public boolean init() { this.isCosmics = false; } - //svt stand-alone String maxResidual = this.getEngineConfigString("maxResidual"); if (maxResidual!=null) { @@ -1176,7 +1162,7 @@ public boolean init() { this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (isCosmics? 0 : 1)); - //svt stand-alone + String debug = this.getEngineConfigString("debug"); if (debug!=null) { From 184accc9f77c4bd82e5b74084fbf138b8ab49204 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sat, 13 Feb 2021 15:31:14 -0500 Subject: [PATCH 112/291] enable github actions, to replace Travis --- .github/workflows/maven.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000000000..865f89877 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,36 @@ +# https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Coatjava CI + +on: + push: + branches: [ '**' ] + pull_request: + branches: [ '**' ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: build + run: ./build-coatjava.sh --spotbugs --unittests + - name: kpp-test + run: cd validation/advanced-tests && ./run-advanced-tests.sh + - name: eb-ep-test + run: cd validation/advanced-tests && ./run-eb-tests.sh -100 electronproton + - name: eb-eg-test + run: cd validation/advanced-tests && ./run-eb-tests.sh -100 electrongamma + - name: eb-epc-test + run: cd validation/advanced-tests && ./run-eb-tests.sh -100 electronprotonC + - name: eb-enc-test + run: cd validation/advanced-tests && ./run-eb-tests.sh -100 electronneutronC + - name: eb-eftpi-test + run: cd validation/advanced-tests && ./run-eb-tests.sh -100 electronFTpion + From ca51d435a21fb849b68ea47910bf477cb2892ded Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 12 Feb 2021 21:12:24 +0100 Subject: [PATCH 113/291] yaml cleanup --- etc/services/data.yaml | 22 +-------- etc/services/data_endplates.yaml | 80 -------------------------------- 2 files changed, 2 insertions(+), 100 deletions(-) delete mode 100644 etc/services/data_endplates.yaml diff --git a/etc/services/data.yaml b/etc/services/data.yaml index e2c68967b..d25ff759d 100644 --- a/etc/services/data.yaml +++ b/etc/services/data.yaml @@ -48,35 +48,17 @@ configuration: io-services: writer: compression: 2 + variation: rga_fall2018 services: MAGFIELDS: magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat - magfieldTorusMap: Full_torus_r251_phi181_z251_08May2018.dat - variation: rga_fall2018 - CND: - variation: rga_fall2018 - CTOF: - variation: rga_fall2018 - CVT: - variation: rga_fall2018 + magfieldTorusMap: Full_torus_r251_phi181_z251_08May2018.dat DCHB: - variation: rga_fall2018 dcGeometryVariation: rga_fall2018 dcT2DFunc: "Polynomial" dcWireDistortion: "true" DCTB: - variation: rga_fall2018 dcGeometryVariation: rga_fall2018 - EC: - variation: rga_fall2018 - FTOFHB: - variation: rga_fall2018 - FTOFTB: - variation: rga_fall2018 - EBHB: - variation: rga_fall2018 - EBTB: - variation: rga_fall2018 mime-types: - binary/data-hipo diff --git a/etc/services/data_endplates.yaml b/etc/services/data_endplates.yaml deleted file mode 100644 index ff984b381..000000000 --- a/etc/services/data_endplates.yaml +++ /dev/null @@ -1,80 +0,0 @@ -io-services: - reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader - name: HipoToHipoReader - writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter - name: HipoToHipoWriter -services: - - class: org.jlab.clas.swimtools.MagFieldsEngine - name: MAGFIELDS - - class: org.jlab.rec.ft.cal.FTCALEngine - name: FTCAL - - class: org.jlab.rec.ft.hodo.FTHODOEngine - name: FTHODO - - class: org.jlab.rec.ft.FTEBEngine - name: FTEB - - class: org.jlab.service.dc.DCHBEngine - name: DCHB - - class: org.jlab.service.ftof.FTOFHBEngine - name: FTOFHB - - class: org.jlab.service.ec.ECEngine - name: EC - - class: org.jlab.rec.cvt.services.CVTReconstruction - name: CVT - - class: org.jlab.service.ctof.CTOFEngine - name: CTOF - - class: org.jlab.service.cnd.CNDCalibrationEngine - name: CND - - class: org.jlab.service.band.BANDEngine - name: BAND - - class: org.jlab.service.htcc.HTCCReconstructionService - name: HTCC - - class: org.jlab.service.ltcc.LTCCEngine - name: LTCC - - class: org.jlab.service.eb.EBHBEngine - name: EBHB - - class: org.jlab.service.dc.DCTBEngine - name: DCTB - - class: org.jlab.service.ftof.FTOFTBEngine - name: FTOFTB - - class: org.jlab.service.eb.EBTBEngine - name: EBTB - - class: org.jlab.rec.rich.RICHEBEngine - name: RICH -configuration: - io-services: - writer: - compression: 2 - services: - MAGFIELDS: - magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat - magfieldTorusMap: Full_torus_r251_phi181_z251_08May2018.dat - variation: rga_fall2018 - CND: - variation: rga_fall2018 - CTOF: - variation: rga_fall2018 - CVT: - variation: rga_fall2018 - DCHB: - variation: rga_fall2018 - dcGeometryVariation: rga_fall2018_endplatebow - dcT2DFunc: "Polynomial" - dcWireDistortion: "true" - DCTB: - variation: rga_fall2018 - dcGeometryVariation: rga_fall2018_endplatebow - EC: - variation: rga_fall2018 - FTOFHB: - variation: rga_fall2018 - FTOFTB: - variation: rga_fall2018 - EBHB: - variation: rga_fall2018 - EBTB: - variation: rga_fall2018 - -mime-types: - - binary/data-hipo From d386d06c7598d66469d8c893302aee8d2b5c267a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 12 Feb 2021 21:33:11 +0100 Subject: [PATCH 114/291] resolving conflict with cherry-pick --- etc/services/data.yaml | 3 ++ etc/services/dst.yaml | 81 ------------------------------------------ 2 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 etc/services/dst.yaml diff --git a/etc/services/data.yaml b/etc/services/data.yaml index d25ff759d..3b34805c4 100644 --- a/etc/services/data.yaml +++ b/etc/services/data.yaml @@ -49,6 +49,9 @@ configuration: writer: compression: 2 variation: rga_fall2018 +# schema_dir: "absolute-path-to-schema-folder" +# for example: +# schema_dir: "/home/clas12-1/chef/myClara/plugins/clas12/etc/bankdefs/dst" services: MAGFIELDS: magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat diff --git a/etc/services/dst.yaml b/etc/services/dst.yaml deleted file mode 100644 index 683862406..000000000 --- a/etc/services/dst.yaml +++ /dev/null @@ -1,81 +0,0 @@ -io-services: - reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader - name: HipoToHipoReader - writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter - name: HipoToHipoWriter -services: - - class: org.jlab.clas.swimtools.MagFieldsEngine - name: MAGFIELDS - - class: org.jlab.rec.ft.cal.FTCALEngine - name: FTCAL - - class: org.jlab.rec.ft.hodo.FTHODOEngine - name: FTHODO - - class: org.jlab.rec.ft.FTEBEngine - name: FTEB - - class: org.jlab.service.dc.DCHBEngine - name: DCHB - - class: org.jlab.service.ftof.FTOFHBEngine - name: FTOFHB - - class: org.jlab.service.ec.ECEngine - name: EC - - class: org.jlab.rec.cvt.services.CVTRecNewKF - name: CVT - - class: org.jlab.service.ctof.CTOFEngine - name: CTOF - - class: org.jlab.service.cnd.CNDCalibrationEngine - name: CND - - class: org.jlab.service.band.BANDEngine - name: BAND - - class: org.jlab.service.htcc.HTCCReconstructionService - name: HTCC - - class: org.jlab.service.ltcc.LTCCEngine - name: LTCC - - class: org.jlab.service.eb.EBHBEngine - name: EBHB - - class: org.jlab.service.dc.DCTBEngine - name: DCTB - - class: org.jlab.service.ftof.FTOFTBEngine - name: FTOFTB - - class: org.jlab.service.eb.EBTBEngine - name: EBTB - - class: org.jlab.rec.rich.RICHEBEngine - name: RICH -configuration: - io-services: - writer: - compression: 2 -# schema_dir: "absolute-path-to-schema-folder" -# schema_dir: "/home/clas12-1/chef/myClara/plugins/clas12/etc/bankdefs/dst" - services: - MAGFIELDS: - magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat - magfieldTorusMap: Full_torus_r251_phi181_z251_08May2018.dat - variation: rga_fall2018 - CND: - variation: rga_fall2018 - CTOF: - variation: rga_fall2018 - CVT: - variation: rga_fall2018 - DCHB: - variation: rga_fall2018 - dcGeometryVariation: rga_fall2018 - dcT2DFunc: "Polynomial" - DCTB: - variation: rga_fall2018 - dcGeometryVariation: rga_fall2018 - EC: - variation: rga_fall2018 - FTOFHB: - variation: rga_fall2018 - FTOFTB: - variation: rga_fall2018 - EBHB: - variation: rga_fall2018 - EBTB: - variation: rga_fall2018 - -mime-types: - - binary/data-hipo From 4c7035bfa130934d3dcc5585c46229ad40688c10 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 12 Feb 2021 21:55:17 +0100 Subject: [PATCH 115/291] another yaml cleanup --- etc/services/services.yaml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 etc/services/services.yaml diff --git a/etc/services/services.yaml b/etc/services/services.yaml deleted file mode 100644 index 002a08ccb..000000000 --- a/etc/services/services.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -services: - - class: org.jlab.clas.reco.DummyEngine - name: DUMMY From 4f802d1fcfb5dd69a7e7276568ae0777bbc755ab Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 12 Feb 2021 22:02:25 +0100 Subject: [PATCH 116/291] another yaml cleanup --- etc/services/debug.yaml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 etc/services/debug.yaml diff --git a/etc/services/debug.yaml b/etc/services/debug.yaml deleted file mode 100644 index f51fbdef1..000000000 --- a/etc/services/debug.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -services: - - class: org.jlab.service.dc.DCHBEngine - name: DCHB - - class: org.jlab.service.ftof.FTOFEngine - name: FTOF - - class: org.jlab.service.ec.ECEngine - name: EC From 67020a864218b886b575e3de5853de1cdd025170 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 25 Feb 2021 15:29:12 +0100 Subject: [PATCH 117/291] yaml: fixed error in data.yaml --- etc/services/data.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/etc/services/data.yaml b/etc/services/data.yaml index 3b34805c4..f8eac91be 100644 --- a/etc/services/data.yaml +++ b/etc/services/data.yaml @@ -45,10 +45,12 @@ services: - class: org.jlab.service.rtpc.RTPCEngine name: RTPC configuration: + global: + variation: rga_fall2018 +# timestamp: 12/31/2020-00:00:00 io-services: writer: compression: 2 - variation: rga_fall2018 # schema_dir: "absolute-path-to-schema-folder" # for example: # schema_dir: "/home/clas12-1/chef/myClara/plugins/clas12/etc/bankdefs/dst" From 0a9c037565d8ef4c5651c3c982c87853b9689554 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 2 Mar 2021 17:50:45 -0500 Subject: [PATCH 118/291] disable TravisCI --- .travis.yml | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ac345fa68..000000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- - -sudo: required - -language: java - -jdk: - - openjdk11 - -addons: - apt: - packages: - - openjfx - -before_install: - - ls -lthra - - java -version - - echo "starting build..." - -install: - - java -version - - ./build-coatjava.sh --spotbugs --unittests --quiet - -script: - - ls -lthra - - which groovy - - echo "starting advanced tests..." - - cd validation/advanced-tests/ - - ./run-advanced-tests.sh || travis_terminate 1; - - ./run-eb-tests.sh -100 electronproton || travis_terminate 1; - - ./run-eb-tests.sh -100 electrongamma || travis_terminate 1; - - ./run-eb-tests.sh -100 electronprotonC || travis_terminate 1; - - ./run-eb-tests.sh -100 electronneutronC || travis_terminate 1; - - ./run-eb-tests.sh -100 electronFTpion || travis_terminate 1; - - cd - - - echo "finished advanced tests" -# - mvn cobertura:cobertura &> /dev/null # for codecov - -#after_success: -# - bash <(curl -s https://codecov.io/bash) - -notifications: - emails: false From 63f693c89b01e7d9d2b640413703e78a31882b4c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 5 Mar 2021 15:28:32 -0500 Subject: [PATCH 119/291] remove defunct yamls --- etc/services/test_dc.yaml | 4 ---- etc/services/test_ec.yaml | 5 ----- etc/services/test_htcc.yaml | 4 ---- etc/services/test_swimmer.yaml | 4 ---- 4 files changed, 17 deletions(-) delete mode 100644 etc/services/test_dc.yaml delete mode 100644 etc/services/test_ec.yaml delete mode 100644 etc/services/test_htcc.yaml delete mode 100644 etc/services/test_swimmer.yaml diff --git a/etc/services/test_dc.yaml b/etc/services/test_dc.yaml deleted file mode 100644 index f91835cb5..000000000 --- a/etc/services/test_dc.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -services: - - class: org.jlab.service.DCEngine - name: DCHB diff --git a/etc/services/test_ec.yaml b/etc/services/test_ec.yaml deleted file mode 100644 index 9bcc46d3c..000000000 --- a/etc/services/test_ec.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -services: - - class: org.jlab.service.ec.ECEngine - name: EC - diff --git a/etc/services/test_htcc.yaml b/etc/services/test_htcc.yaml deleted file mode 100644 index 060f74e5c..000000000 --- a/etc/services/test_htcc.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -services: - - class: org.jlab.service.htcc.HTCCReconstructionService - name: HTCC diff --git a/etc/services/test_swimmer.yaml b/etc/services/test_swimmer.yaml deleted file mode 100644 index d8e420bff..000000000 --- a/etc/services/test_swimmer.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- -services: - - class: org.jlab.service.swim.SwimEngine - name: SWIMMER From fa4217667292f88104eb02cd0c7ade05b78e7c2a Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 5 Mar 2021 15:37:48 -0500 Subject: [PATCH 120/291] rename eb yaml --- etc/services/{eventBuilder.yaml => eb.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename etc/services/{eventBuilder.yaml => eb.yaml} (100%) diff --git a/etc/services/eventBuilder.yaml b/etc/services/eb.yaml similarity index 100% rename from etc/services/eventBuilder.yaml rename to etc/services/eb.yaml From a7dc0ae480083789fca514b887fb9e45afa99b53 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 5 Mar 2021 15:38:16 -0500 Subject: [PATCH 121/291] rename ambiguous yaml --- etc/services/{reconstruction.yaml => kpp.yaml} | 0 validation/advanced-tests/run-advanced-tests.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename etc/services/{reconstruction.yaml => kpp.yaml} (100%) diff --git a/etc/services/reconstruction.yaml b/etc/services/kpp.yaml similarity index 100% rename from etc/services/reconstruction.yaml rename to etc/services/kpp.yaml diff --git a/validation/advanced-tests/run-advanced-tests.sh b/validation/advanced-tests/run-advanced-tests.sh index aba4ebd6f..28ab458ee 100755 --- a/validation/advanced-tests/run-advanced-tests.sh +++ b/validation/advanced-tests/run-advanced-tests.sh @@ -62,7 +62,7 @@ echo "set session s_cook" >> cook.clara echo "set description d_cook" >> cook.clara ls twoTrackEvents_809.hipo > files.list echo "set fileList $PWD/files.list" >> cook.clara -echo "set servicesFile $CLARA_HOME/plugins/clas12/config/services.yaml" >> cook.clara +echo "set servicesFile $CLARA_HOME/plugins/clas12/config/kpp.yaml" >> cook.clara echo "run local" >> cook.clara echo "run local" >> cook.clara echo "exit" >> cook.clara From 6850406572c89fe7837abc87464a8a0ea868c6a0 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 5 Mar 2021 16:21:54 -0500 Subject: [PATCH 122/291] replace Travis with github action badge --- .github/workflows/maven.yml | 2 +- README.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 865f89877..523390b07 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,6 +1,6 @@ # https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: Coatjava CI +name: Coatjava-CI on: push: diff --git a/README.md b/README.md index 31bd54aa4..8192a05ad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -# clas12-offline-software [![Build Status](https://travis-ci.org/JeffersonLab/clas12-offline-software.svg?branch=development)](https://travis-ci.org/JeffersonLab/clas12-offline-software) [![codecov](https://codecov.io/gh/JeffersonLab/clas12-offline-software/branch/development/graph/badge.svg?precision=2)](https://codecov.io/gh/JeffersonLab/clas12-offline-software/branch/development) +# clas12-offline-software +[![Build Status](https://github.com/jeffersonlab/clas12-offline-software/workflows/Coatjava-CI/badge.svg)](https://github.com/jeffersonlab/clas12-offline-software/actions) +[![codecov](https://codecov.io/gh/JeffersonLab/clas12-offline-software/branch/development/graph/badge.svg?precision=2)](https://codecov.io/gh/JeffersonLab/clas12-offline-software/branch/development) + + CLAS12 Offline Software ## Quick Start From 31fc8de7842c979c0b478ef05a5f2c8026a3fda8 Mon Sep 17 00:00:00 2001 From: raffaelladevita Date: Sat, 15 May 2021 16:13:55 -0400 Subject: [PATCH 123/291] Maven blocking (#698) * using https for freehep * one more attempt * trying via mirror * trying via mirror * cleanup Co-authored-by: Nathan Baltzell --- build-coatjava.sh | 6 ++++-- maven-settings.xml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 maven-settings.xml diff --git a/build-coatjava.sh b/build-coatjava.sh index c66d03575..f72583893 100755 --- a/build-coatjava.sh +++ b/build-coatjava.sh @@ -29,12 +29,14 @@ do fi done +top="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" + wget='wget' -mvn='mvn' +mvn="mvn --settings $top/maven-settings.xml" if [ "$quiet" == "yes" ] then wget='wget --progress=dot:mega' - mvn='mvn -q -B' + mvn="mvn -q -B --settings $top/maven-settings.xml" fi # download the default field maps, as defined in bin/env.sh: diff --git a/maven-settings.xml b/maven-settings.xml new file mode 100644 index 000000000..e3cad1ff7 --- /dev/null +++ b/maven-settings.xml @@ -0,0 +1,17 @@ + + + + + new-freehep + freehep + freehep + https://java.freehep.org/maven2 + + + From 776a9a0de8ecd1acbcc20cee0cc829067bb7aee8 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 20 May 2021 10:32:01 -0400 Subject: [PATCH 124/291] Added banks output fixes. --- .../java/org/jlab/rec/cvt/banks/RecoBankWriter.java | 6 +++--- .../main/java/org/jlab/rec/cvt/cluster/Cluster.java | 10 +++++++--- .../main/java/org/jlab/rec/cvt/cross/CrossMaker.java | 6 ++++++ .../java/org/jlab/rec/cvt/services/RecUtilities.java | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index d55c0b3bd..608c12b82 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -118,10 +118,10 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); - bank.setFloat("e", i, (float)cluslist.get(i).get_CentroidError()); + bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); } - bank.show(); + //bank.show(); return bank; } @@ -287,7 +287,7 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); } - bank.show(); + //bank.show(); return bank; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index f5eedfaae..fe23bb4d6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -330,9 +330,13 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, weightedY2/totEn-weightedY1/totEn, weightedZ2/totEn-weightedZ1/totEn).asUnit(); - Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). - vectorTo(sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer())).asUnit(); - + //Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). + // vectorTo(sgeo.getPlaneModuleEnd(this.get_Sector(), this.get_Layer())).asUnit(); + double[][] Xi = sgeo.getStripEndPoints(1, (this.get_Layer() - 1) % 2); + double[][] Xf = sgeo.getStripEndPoints(100, (this.get_Layer() - 1) % 2); + Point3D EPi = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xi[0][0], 0, Xi[0][1], "lab", ""); + Point3D EPf = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xf[0][0], 0, Xf[0][1], "lab", ""); + Vector3D s = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips Vector3D n = sgeo.findBSTPlaneNormal(this.get_Sector(), this.get_Layer()); this.setL(l); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index b9d490150..9233b73f8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -63,6 +63,12 @@ public ArrayList findSVTCrosses( List svt_innerlayrclus, List svt_outerlayrclus, org.jlab.rec.cvt.svt.Geometry svt_geo) { + for(Cluster cl : svt_innerlayrclus) { + cl.set_Error(cl.get_ResolutionAlongZ(0, svt_geo) ); + } + for(Cluster cl : svt_outerlayrclus) { + cl.set_Error(cl.get_ResolutionAlongZ(0, svt_geo) ); + } // instantiate the list of crosses ArrayList crosses = new ArrayList(); int rid = 0; // cross id diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index d16e584b2..684f92975 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -21,7 +21,6 @@ import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; -import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.track.StraightTrack; @@ -103,6 +102,7 @@ public List setMeasVecs(Seed trkcand, meas.setSector(trkcand.get_Clusters().get(i).get_Sector()); meas.setLayer(trkcand.get_Clusters().get(i).get_Layer()); double err = trkcand.get_Clusters().get(i).get_Error(); + meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? //the thickness for multiple scattering. MS is outward the thickness is set for the 1st layer in the superlayer // air gap ignored From d21d548277156dec546ab5a82933b319e8d6d50a Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Thu, 20 May 2021 14:39:03 -0400 Subject: [PATCH 125/291] use new banks in pre-align --- .../jlab/rec/cvt/banks/RecoBankReader.java | 59 +++++++ .../jlab/rec/cvt/services/CVTAlignment.java | 155 +++++++++++++++++- 2 files changed, 213 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index e35a9cf15..c2c7c6396 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -4,6 +4,7 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataBank; @@ -138,6 +139,41 @@ public void fetch_BMTClusters(DataEvent event) { cluster.set_CentroidResidual(bank.getFloat("centroidResidual",i)); cluster.set_SeedResidual(bank.getFloat("seedResidual",i)); cluster.set_AssociatedTrackID(bank.getShort("trkID",i)); + + cluster.setX1(bank.getFloat("x1", i)); + cluster.setX2(bank.getFloat("x2", i)); + cluster.setY1(bank.getFloat("y1", i)); + cluster.setY2(bank.getFloat("y2", i)); + cluster.setZ1(bank.getFloat("z1", i)); + cluster.setZ2(bank.getFloat("z2", i)); + cluster.setS(new Vector3D( + bank.getFloat("sx", i), + bank.getFloat("sy", i), + bank.getFloat("sz", i))); + cluster.setN(new Vector3D( + bank.getFloat("nx", i), + bank.getFloat("ny", i), + bank.getFloat("nz", i))); + cluster.setL(new Vector3D( + bank.getFloat("lx", i), + bank.getFloat("ly", i), + bank.getFloat("lz", i))); + cluster.set_Error(bank.getFloat("e", i)); + + + cluster.setOx(bank.getFloat("ox", i)); + cluster.setOy(bank.getFloat("oy", i)); + cluster.setOz(bank.getFloat("oz", i)); + cluster.setTheta(bank.getFloat("theta", i)); + cluster.setCylAxis(new Line3D( + bank.getFloat("ax1", i), + bank.getFloat("ay1", i), + bank.getFloat("az1", i), + bank.getFloat("ax2", i), + bank.getFloat("ay2", i), + bank.getFloat("az2", i))); + + //Since only up to 5 hits per track are written... for (int j = 0; j < 5; j++) { String hitStrg = "Hit"; @@ -344,6 +380,26 @@ public void fetch_SVTClusters(DataEvent event) { cluster.set_SeedResidual(bank.getFloat("seedResidual",i)); cluster.set_AssociatedTrackID(bank.getShort("trkID",i)); + cluster.setX1(bank.getFloat("x1", i)); + cluster.setX2(bank.getFloat("x2", i)); + cluster.setY1(bank.getFloat("y1", i)); + cluster.setY2(bank.getFloat("y2", i)); + cluster.setZ1(bank.getFloat("z1", i)); + cluster.setZ2(bank.getFloat("z2", i)); + cluster.setS(new Vector3D( + bank.getFloat("sx", i), + bank.getFloat("sy", i), + bank.getFloat("sz", i))); + cluster.setN(new Vector3D( + bank.getFloat("nx", i), + bank.getFloat("ny", i), + bank.getFloat("nz", i))); + cluster.setL(new Vector3D( + bank.getFloat("lx", i), + bank.getFloat("ly", i), + bank.getFloat("lz", i))); + cluster.set_Error(bank.getFloat("e", i)); + //Since only up to 5 hits per track are written... for (int j = 0; j < 5; j++) { String hitStrg = "Hit"; @@ -398,6 +454,9 @@ public void fetch_BMTHits(DataEvent event) { int id = bank.getShort("ID", i); FittedHit hit = new FittedHit(0, 0, sector, layer, new Strip(strip, 0)); + + + hit.set_Id(id); hit.set_docaToTrk(bank.getFloat("fitResidual", i)); hit.set_TrkgStatus(bank.getInt("trkingStat", i)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 7b169137c..7aa04bf7f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -246,8 +246,35 @@ public boolean processDataEvent(DataEvent event) { Matrix I = new Matrix(rows,1); int i = 0; - + boolean useNewFillMatrices = true; for(Cross cross : track) { + if(useNewFillMatrices) { + if(cross.get_Detector().equalsIgnoreCase("SVT")){ + Cluster cl1 = cross.get_Cluster1(); + boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + Cluster cl2 = cross.get_Cluster2(); + ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + } else { + Cluster cl1 = cross.get_Cluster1(); + boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in a BMT layer"); + continue tracksLoop; + } + } + continue; + } //System.out.println("cross " +cross.get_Point()); if(cross.get_Detector().equalsIgnoreCase("SVT")) { @@ -542,6 +569,132 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix return true; } + + /** + * generic method that uses any type of cluster. + * @param i + * @param ray + * @param cl + * @param A + * @param B + * @param V + * @param m + * @param c + * @param I + * @return + */ + private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { + int region = cl.get_Region(); + int layer = cl.get_Layer(); + int sector = cl.get_Sector(); + //System.out.println("RLS " + region + " " + layer + " " + sector); + //System.out.println("th" + c.get_Phi()); + double centroid = cl.get_Centroid(); + + + Vector3D l = cl.getL(); + Vector3D s = cl.getS(); + Vector3D n = cl.getN(); + + //Vector3d e1 = cl.getX + Vector3D e = new Vector3D(cl.getX1(),cl.getY1(),cl.getZ1()); + + Vector3D xref = ray.get_refPoint().toVector3D(); + Vector3D u = ray.get_dirVec(); + double udotn = u.dot(n); + if(Math.abs(udotn)<0.01) { + if(debug) System.out.println("rejecting track: abs(udotn)<0.01"); + return false; + } + double sdotu = s.dot(u); + Vector3D extrap = xref.add(u.multiply(n.dot(e.sub(xref))/udotn)); + + + //System.out.println(extrap.toStlString()); + double resolution = cl.get_Error(); + //System.out.println("resolution: " + resolution + "; z=" + extrap.z-); + + V.set(i, i, Math.pow(resolution,2)); + + + Vector3D sp = s.sub(n.multiply(sdotu/udotn)); + if(sp.mag() > 10) { //this can only happen if the angle between the track and the normal is small + if(debug) System.out.println("rejecting track: sp.magnitude() > 10"); + return false; + } + + + + Vector3D cref = new Vector3D(0,0,0); + + + + + + Vector3D dmdr =sp.cross(extrap).add(n.cross(cref).multiply(sdotu/udotn)); + dmdr = dmdr.sub(n.cross(u).multiply(n.dot(e.sub(extrap))*sdotu/(udotn*udotn))); + if(orderTx >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, -sp.x()); + if(orderTy >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, -sp.y()); + if(orderTz >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, -sp.z()); + if(orderRx >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, dmdr.x()); + if(orderRy >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, dmdr.y()); + if(orderRz >= 0) + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, dmdr.z()); + + + if(cl.get_Detector() == 0) + I.set(i, 0, getIndexSVT(layer-1,sector-1)); + if(cl.get_Detector() == 1) + I.set(i, 0, getIndexBMT(layer-1,sector-1)); + + Vector3D dmdu = sp.multiply(e.sub(xref).dot(n)/udotn); + if(!this.useDocaPhiZTandip) { + B.set(i,0, sp.x()); + B.set(i,1, sp.z()); + B.set(i,2, dmdu.x()); + B.set(i,3, dmdu.z()); + } else { + + double phi = Math.atan2(u.y(),u.x()); + Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi),0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x(), u.y()); + double d = mscphi.dot(xref); + B.set(i, 0, s.dot(mscphi.sub(u.multiply(n.dot(mscphi)/udotn)))); + //B.set(i, 1, s.dot(csphi.times(-d) + // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) + // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(u.times(d*n.dot(csphi)/udotn))) + // ); + B.set(i, 1, -s.dot(csphi)*d + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.sub(xref)) + + sdotu/udotn*d*n.dot(csphi)); + B.set(i, 2, s.z()-sdotu*n.z()/udotn); + B.set(i, 3, (s.z()/udotn-n.z()*sdotu/(udotn*udotn))*n.dot(e.sub(xref))); + + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + + double ci = s.dot(extrap); + double mi = s.dot(e); + if(Math.abs(ci-mi)>maxResidualCut) { + if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); + return false; + } + c.set(i,0,ci); + m.set(i,0,mi); + + + return true; + + } + //returns false if there's a problem private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { From 0e3955645bb1855e0317b6cc054b352befd465c0 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 8 Jun 2021 16:00:37 -0400 Subject: [PATCH 126/291] Added banks output fixes. --- .../org/jlab/rec/cvt/cluster/Cluster.java | 15 +++++++++++ .../jlab/rec/cvt/services/RecUtilities.java | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index fe23bb4d6..288d6de87 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -36,6 +36,7 @@ public class Cluster extends ArrayList implements Comparable private double _PhiErr0; private double _Z; // for C-detectors private double _ZErr; + private Point3D _TrakInters; //track intersection with the cluster //added variables for alignment private double _x1; //cluster first end point x @@ -565,6 +566,20 @@ public void set_CentroidResidual(double _CentroidResidual) { this._CentroidResidual = _CentroidResidual; } + /** + * @return the _TrakInters + */ + public Point3D getTrakInters() { + return _TrakInters; + } + + /** + * @param _TrakInters the _TrakInters to set + */ + public void setTrakInters(Point3D _TrakInters) { + this._TrakInters = _TrakInters; + } + /** * * @return cluster info. about location and number of hits contained in it diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 684f92975..b11af50f4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -21,6 +21,7 @@ import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; +import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.track.StraightTrack; @@ -365,6 +366,32 @@ public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical. this.MatchTrack2Traj(seed, kf.TrjPoints, SVTGeom, BMTGeom); cand.addAll(seed.get_Crosses()); + for(Cluster cl : seed.get_Clusters()) { + int layer = cl.get_Layer(); + if(cl.get_Detector()==1){ + layer = layer + 6; + + Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); + Line3D cln = BMTGeom.getAxis(cl.get_Layer(), cl.get_Sector()); + double v = (kf.TrjPoints.get(layer).z-cyl.baseArc().center().z())/cln.direction().z(); + double x = cyl.baseArc().center().x()+v*cln.direction().x(); + double y = cyl.baseArc().center().y()+v*cln.direction().y(); + Vector3D n = new Point3D(x, y, kf.TrjPoints.get(layer).z). + vectorTo(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).asUnit(); + cl.setN(n); + if (cl.get_DetectorType()==0) { + cl.setL(cl.getS().cross(n).asUnit()); + } + } + //double x = kf.TrjPoints.get(layer).x; + //double y = kf.TrjPoints.get(layer).y; + //double z = kf.TrjPoints.get(layer).z; + //double px = kf.TrjPoints.get(layer).px; + //double py = kf.TrjPoints.get(layer).py; + //double pz = kf.TrjPoints.get(layer).pz; + cl.setTrakInters(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)); + } + return cand; } From 100b2f0ed1fbbffdfbcb0d200822dd6037f570bc Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 10 Jun 2021 17:03:06 -0400 Subject: [PATCH 127/291] Fix for cosmic tracks reconstruction. --- .../org/jlab/rec/cvt/track/StraightTrack.java | 4 ++-- .../rec/cvt/track/TrackCandListFinder.java | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index 88278af1d..f0d198e84 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -103,8 +103,8 @@ public double calc_straightTrkChi2() { double yxSl = this.get_ray().get_yxslope(); double yzSl = this.get_ray().get_yzslope(); double yxIt = this.get_ray().get_yxinterc(); - double yzIt = this.get_ray().get_yzinterc(); - + double yzIt = this.get_ray().get_yzinterc(); + for (Cross c : this) { double errSq = c.get_PointErr().x() * c.get_PointErr().x() + c.get_PointErr().z() * c.get_PointErr().z(); double y = c.get_Point().y(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 5e8b68b79..2f15b3428 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -361,7 +361,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List arrayList, } if(BMTCdetcrossesInTrk.size()>1 && useBMTCforZonly==true) { - //System.out.print("RESETTING MEAS ARRAY"); + Z.clear(); Y_prime.clear(); ErrZ.clear(); From 11c7410ebc2fba3e24b4eeadd7fe3fbc8c61c21e Mon Sep 17 00:00:00 2001 From: heddle Date: Fri, 11 Jun 2021 15:06:24 -0400 Subject: [PATCH 128/291] modified the swimToRho uniform step size swimmer --- .../adaptiveSwim/AdaptiveSwimResult.java | 15 ++ .../adaptiveSwim/test/InitialValues.java | 11 +- .../java/cnuphys/lund/LundTrackDialog.java | 41 ++++- .../java/cnuphys/swim/NumStepStopper.java | 33 ++++ .../src/main/java/cnuphys/swim/Swimmer.java | 118 ++++++++++---- .../java/cnuphys/swimtest/RandomData.java | 7 +- .../main/java/cnuphys/swimtest/SwimTest.java | 145 +++++++++++++++++- 7 files changed, 324 insertions(+), 46 deletions(-) create mode 100644 common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/NumStepStopper.java diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/AdaptiveSwimResult.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/AdaptiveSwimResult.java index f424622ad..7cb72f000 100644 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/AdaptiveSwimResult.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/AdaptiveSwimResult.java @@ -276,6 +276,21 @@ public String toString() { return initialValuesString() + sb.toString(); } + /** + * A final location string + * @return a location string + */ + public String finalLocationString() { + double x = _uf[0]; + double y = _uf[1]; + double z = _uf[2]; + double rho = Math.hypot(x, y); + double phi = Math.toDegrees(Math.atan2(y, x)); + return String.format("[x,y,z] = [%8.5f, %8.5f, %8.5f] cm [phi,rho] = [%8.5f deg, %8.5f cm] S = %8.5f cm", + 100*x, 100*y, 100*z, phi, 100*rho, 100*getFinalS()); + + } + //the location private String locationString() { double x = _uf[0]; diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/InitialValues.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/InitialValues.java index 66586bcea..2e5884c84 100644 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/InitialValues.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/InitialValues.java @@ -38,6 +38,11 @@ public InitialValues() { } + + public String toStringRaw() { + return String.format("%-7.4f %-7.4f %-7.4f %-6.3f %-6.3f %-6.3f", xo, yo, zo, p, theta, phi); + } + /** * Store the initial conditions of a swim * @param charge The integer charge @@ -70,9 +75,9 @@ public InitialValues(InitialValues src) { public String toString() { return String.format("Q: %d\n", charge) + - String.format("xo: %10.7e cm\n", xo) + - String.format("yo: %10.7e cm\n", yo) + - String.format("zo: %10.7e cm\n", zo) + + String.format("xo: %10.7e m\n", xo) + + String.format("yo: %10.7e m\n", yo) + + String.format("zo: %10.7e m\n", zo) + String.format("p: %10.7e GeV/c\n", p) + String.format("theta: %10.7f deg\n", theta) + String.format("phi: %10.7f deg", phi); diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/lund/LundTrackDialog.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/lund/LundTrackDialog.java index 6a70ed141..10d277f54 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/lund/LundTrackDialog.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/lund/LundTrackDialog.java @@ -36,7 +36,7 @@ @SuppressWarnings("serial") public class LundTrackDialog extends JDialog { - public enum SWIM_ALGORITHM {STANDARD, FIXEDZ, FIXEDRHO} + public enum SWIM_ALGORITHM {STANDARD, FIXEDZ, FIXEDS, FIXEDRHO} private SWIM_ALGORITHM _algorithm = SWIM_ALGORITHM.STANDARD; @@ -87,6 +87,9 @@ public enum SWIM_ALGORITHM {STANDARD, FIXEDZ, FIXEDRHO} // fixed z cutoff private JRadioButton _fixedZRB; + // fixed s (pathlength) cutoff + private JRadioButton _fixedSRB; + // fixed z cutoff private JRadioButton _fixedRhoRB; @@ -96,6 +99,11 @@ public enum SWIM_ALGORITHM {STANDARD, FIXEDZ, FIXEDRHO} // fixed Z value private JTextField _fixedZ; + + + // fixed S (pathlength) value + private JTextField _fixedS; + // accuracy in fixed z private JTextField _accuracy; @@ -165,6 +173,9 @@ else if (_fixedZRB.isSelected()) { else if (_fixedRhoRB.isSelected()) { _algorithm = SWIM_ALGORITHM.FIXEDRHO; } + else if (_fixedSRB.isSelected()) { + _algorithm = SWIM_ALGORITHM.FIXEDS; + } fixState(); @@ -174,19 +185,24 @@ else if (_fixedRhoRB.isSelected()) { _standardRB = new JRadioButton("Standard"); _fixedZRB = new JRadioButton("Fixed Z"); + _fixedSRB = new JRadioButton("Fixed S"); + _fixedRhoRB = new JRadioButton("Fixed " + SMALL_RHO); _standardRB.setSelected((_algorithm == SWIM_ALGORITHM.STANDARD)); _fixedZRB.setSelected((_algorithm == SWIM_ALGORITHM.FIXEDZ)); + _fixedSRB.setSelected((_algorithm == SWIM_ALGORITHM.FIXEDS)); _fixedRhoRB.setSelected((_algorithm == SWIM_ALGORITHM.FIXEDRHO)); _standardRB.addActionListener(al); _fixedZRB.addActionListener(al); + _fixedSRB.addActionListener(al); _fixedRhoRB.addActionListener(al); bg.add(_standardRB); bg.add(_fixedZRB); + bg.add(_fixedSRB); bg.add(_fixedRhoRB); fixState(); @@ -197,7 +213,7 @@ else if (_fixedRhoRB.isSelected()) { private void fixState() { _fixedZ.setEnabled(_fixedZRB.isSelected()); _fixedRho.setEnabled(_fixedRhoRB.isSelected()); - + _fixedS.setEnabled(_fixedSRB.isSelected()); } /** @@ -289,7 +305,7 @@ private void doCommonSwim() { double theta = Double.parseDouble(_theta.getText()); double phi = Double.parseDouble(_phi.getText()); - double stepSize = 5e-4; // m + double stepSize = 1e-5; // m double maxPathLen = 8.0; // m double eps = 1.0e-6; @@ -314,6 +330,16 @@ private void doCommonSwim() { stepSize, eps, result); prompt = "RESULT from fixed Z swim:\n"; break; + + case FIXEDS: + // convert accuracy from microns to meters + accuracy = Double.parseDouble(_accuracy.getText()) / 1.0e6; + double targetS = Double.parseDouble(_fixedS.getText()) / 100; // meters + swimmer.swimS(lid.getCharge(), xo, yo, zo, momentum, theta, phi, accuracy, targetS, + stepSize, eps, result); + prompt = "RESULT from fixed S swim:\n"; + break; + case FIXEDRHO: // convert accuracy from microns to meters @@ -457,11 +483,13 @@ public void actionPerformed(ActionEvent arg0) { private JPanel cutoffPanel() { _fixedZ = new JTextField(8); + _fixedS = new JTextField(8); _fixedRho = new JTextField(8); _accuracy = new JTextField(8); _fixedRho.setText("100.0"); + _fixedS.setText("29.990"); _fixedZ.setText("575.0"); _accuracy.setText("10"); @@ -474,6 +502,8 @@ private JPanel cutoffPanel() { box.add(Box.createVerticalStrut(5)); box.add(labeledTextField(" Stopping Z", _fixedZ, "cm", -1)); box.add(Box.createVerticalStrut(5)); + box.add(labeledTextField(" Stopping S", _fixedS, "cm", -1)); + box.add(Box.createVerticalStrut(5)); box.add(labeledTextField(" Stopping " + SMALL_RHO, _fixedRho, "cm", -1)); box.add(Box.createVerticalStrut(5)); box.add(labeledTextField(" Accuracy", _accuracy, "microns", -1)); @@ -490,13 +520,12 @@ private JPanel cutoffType() { createAlgorithmButtons(bg); JPanel spanel = new JPanel(); - spanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); + spanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0)); spanel.add(_standardRB); spanel.add(_fixedZRB); + spanel.add(_fixedSRB); spanel.add(_fixedRhoRB); - - JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(spanel); diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/NumStepStopper.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/NumStepStopper.java new file mode 100644 index 000000000..1747ff459 --- /dev/null +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/NumStepStopper.java @@ -0,0 +1,33 @@ +package cnuphys.swim; + +import cnuphys.rk4.IStopper; + +public class NumStepStopper implements IStopper { + + private int _maxStep; + private int count; + + protected double _finalPathLength = Double.NaN; + + + public NumStepStopper(int numStep) { + _maxStep = numStep; + } + + @Override + public boolean stopIntegration(double t, double[] y) { + count++; + return count >= _maxStep; + } + + @Override + public double getFinalT() { + return _finalPathLength; + } + + @Override + public void setFinalT(double finalPathLength) { + _finalPathLength = finalPathLength; + } + +} diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java index fa5f35f21..5cc6c4ca0 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java @@ -553,14 +553,12 @@ public void swimRho(int charge, double xo, double yo, double zo, double momentum return; } - //cutoff value of s with tolerance - double sCutoff = sMax - SMAX_TOLERANCE; - double del = Double.POSITIVE_INFINITY; - int maxtry = 11; + int maxtry = 25; int count = 0; double sFinal = 0; int ns = 0; + while ((count < maxtry) && (del > accuracy)) { @@ -573,50 +571,102 @@ public void swimRho(int charge, double xo, double yo, double zo, double momentum phi = FastMath.atan2Deg(py, px); } - double rhoCurr = Math.hypot(uf[0], uf[1]); - - DefaultRhoStopper stopper = new DefaultRhoStopper(uf, sFinal, sMax, rhoCurr, fixedRho, accuracy); - - if ((sFinal + stepSize) > sMax) { - stepSize = sMax-sFinal; - - if (stepSize < 0) { - break; - } - } - - + DefaultRhoStopper stopper = new DefaultRhoStopper(uf, sFinal, sMax, Math.hypot(uf[0], uf[1]), fixedRho, accuracy); ns += swim(charge, uf[0], uf[1], uf[2], momentum, theta, phi, stopper, null, sMax-sFinal, stepSize); System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); - sFinal = stopper.getFinalT(); - + sFinal = stopper.getFinalT(); + + del = Math.abs(stopper.getRho() - fixedRho); - double rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); - del = Math.abs(rholast - fixedRho); - + // succeed? + if (del < accuracy) { + break; + } - if ((sFinal) > sCutoff) { + // passed max path length? + if (stopper.passedSmax()) { break; } - + count++; - stepSize = Math.min(stepSize, (sMax-sFinal)/4); - -// stepSize /= 2; - + + if (stopper.crossedBoundary()) { + stepSize = Math.max(stepSize / 2, del / 5); + } + + } // while result.setNStep(ns); result.setFinalS(sFinal); - - if (del < accuracy) { - result.setStatus(0); - } else { - result.setStatus(-1); - } + +// //cutoff value of s with tolerance +// double sCutoff = sMax - SMAX_TOLERANCE; +// +// double del = Double.POSITIVE_INFINITY; +// int maxtry = 25; +// int count = 0; +// double sFinal = 0; +// int ns = 0; +// +// while ((count < maxtry) && (del > accuracy)) { +// +// uf = result.getUf(); +// if (count > 0) { +// px = uf[3]; +// py = uf[4]; +// pz = uf[5]; +// theta = FastMath.acos2Deg(pz); +// phi = FastMath.atan2Deg(py, px); +// } +// +// double rhoCurr = Math.hypot(uf[0], uf[1]); +// +// DefaultRhoStopper stopper = new DefaultRhoStopper(uf, sFinal, sMax, rhoCurr, fixedRho, accuracy); +// +// if ((sFinal + stepSize) > sMax) { +// stepSize = sMax-sFinal; +// +// if (stepSize < 0) { +// break; +// } +// } +// +// +// +// ns += swim(charge, uf[0], uf[1], uf[2], momentum, theta, phi, stopper, null, sMax-sFinal, stepSize); +// +// System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); +// +// sFinal = stopper.getFinalT(); +// +// +// double rholast = Math.hypot(result.getUf()[0], result.getUf()[1]); +// del = Math.abs(rholast - fixedRho); +// +// +// if ((sFinal) > sCutoff) { +// break; +// } +// +// count++; +// stepSize = Math.min(stepSize, (sMax-sFinal)/4); +// +//// stepSize /= 2; +// +// } // while +// +// result.setNStep(ns); +// result.setFinalS(sFinal); +// +// if (del < accuracy) { +// result.setStatus(0); +// } else { +// result.setStatus(-1); +// } } diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java index 269e268fa..537257f85 100644 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java @@ -22,7 +22,12 @@ public class RandomData { public RandomData(int n, long seed) { this(n, seed, -0.01, 0.02, -0.01, 0.02, -0.01, 0.02, - 0.9, 0.0, 25, 20, 0, 360); + 0.9, 5.0, 25, 20, 0, 360); + } + + public String toStringRaw(int index) { + return String.format("%2d %7.4f %7.4f %7.4f %6.3f %6.3f %7.3f", + charge[index], xo[index], yo[index], zo[index], p[index], theta[index], phi[index]); } /** diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java index a889b5653..64e381a6b 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java @@ -42,9 +42,12 @@ import cnuphys.magfield.MagneticFields; import cnuphys.magfield.MagneticFields.FieldType; +import cnuphys.rk4.IStopper; import cnuphys.rk4.RungeKuttaException; +import cnuphys.splot.plot.UnicodeSupport; import cnuphys.swim.BeamLineStopper; import cnuphys.swim.DefaultSwimStopper; +import cnuphys.swim.NumStepStopper; import cnuphys.swim.SwimMenu; import cnuphys.swim.SwimTrajectory; import cnuphys.swim.Swimmer; @@ -887,6 +890,70 @@ private static void swimToCylinderTest(int n, long seed) { } + private static void gemcTrackTest() { + System.out.println("GEMC Track Comparison"); + MagneticFields.getInstance().setActiveField(FieldType.SOLENOID); + MagneticFields.getInstance().getSolenoid().setScaleFactor(-1); + + double gemcXF = 272.3931; //mm + double gemcYF = 62.3494; //mm + double gemcZF = 102.5624; //mm + double gemcSF = 299.9000; //mm + + double xo = 0; + double yo = 0; + double zo = 0; + + System.out.println("Old Swimmer, Uniform Step, Step = 0.1mm"); + Swimmer swimmer = new Swimmer(); + + double stepSize = 1e-4; // 0.1mm + double sMax = 5; //m + int charge = 1; + double theta = 70; + double phi = 0; + double distanceBetweenSaves = stepSize; + double p = 1.; //GeV + double accuracy = 1e-7; // meters + double fixedZ = 102.5624/1000; //meters + double hdata[] = new double[3]; + + //the false means the whole trajectory is not saved + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + + + NumStepStopper stopper = new NumStepStopper(2999); + + SwimTrajectory traj = swimmer.swim(charge, xo, yo, zo, p, theta, phi, + stopper, sMax, stepSize, distanceBetweenSaves); + + double finalStateVector[] = traj.lastElement(); + printSummary("\nresult from uniform stepsize method ", traj.size(), + p, finalStateVector, null); + + System.out.println("Sfinal = " + 1000*stopper.getFinalT() + " mm"); + + + System.out.println("\nOld Swimmer, Adaptive Step, Step = 0.1mm"); + + try { + traj = swimmer.swim(charge, xo, yo, zo, p, theta, phi, + fixedZ, accuracy, sMax, stepSize, Swimmer.CLAS_Tolerance, hdata); + + printSummary("\nresult from uniform stepsize method ", traj.size(), + p, finalStateVector, hdata); + + System.out.println("Sfinal = " + 1000*stopper.getFinalT() + " mm"); + + } catch (RungeKuttaException e) { + e.printStackTrace(); + } + + + } + + //swim to a fixed rho private static void swimToRhoTest(int n, long seed) { MagneticFields.getInstance().setActiveField(FieldType.COMPOSITE); @@ -1072,6 +1139,76 @@ private static void swimToRhoTest(int n, long seed) { + } + + //test the uniform step size swim to rho + private static void uniformSwimToRhoTest(int n, long seed) { + MagneticFields.getInstance().setActiveField(FieldType.COMPOSITE); + System.err.println("SwimToRho Uniform Stepsize Test"); + + Swimmer swimmer = new Swimmer(); + + //every distance is in meters + double accuracy = 20e-6; // meters + double[] stepSize = {1e-5, 4e-5, 9.e-5, 2.5e-4, 3.5e-4, 5e-4}; // 500 microns + + double rho = 0.3; //200 mm + double sMax = 5; + + System.err.println(String.format("Target RHO: %-7.4f m", rho)); + System.err.println(String.format("Desired Accuracy: %6.2f microns\n", 1.0e6*accuracy)); + + RandomData data = new RandomData(n, seed); + + //the false means the whole trajectory is not saved + AdaptiveSwimResult result = new AdaptiveSwimResult(false); + + System.err.print("Q xo (m) yo (m) zo (m) p (GeV) " + UnicodeSupport.SMALL_THETA + " (deg) "+ UnicodeSupport.SMALL_PHI+ " (deg) "); + + for (double ss : stepSize) { + System.err.print(String.format("%7.0f ", 1.e6*ss)); + } + + System.err.println(); + + + + for (int i = 0; i < n; i++) { + + System.err.print(data.toStringRaw(i)); + + for (int j = 0; j < stepSize.length; j++) { + swimmer.swimRho(data.charge[i], data.xo[i], data.yo[i], data.zo[i], data.p[i], data.theta[i], data.phi[i], + rho, accuracy, sMax, stepSize[j], result); + + + double del = 1.0e6*Math.abs(result.getFinalRho() - rho); + System.err.print(String.format(" %7.2f", del)); + } + + System.err.println(); + + } + + System.err.println("\nFor last track, final locations for different step sizes:\n"); + System.err.println("step (microns) "); + + int nm1 = n - 1; + for (int j = 0; j < stepSize.length; j++) { + swimmer.swimRho(data.charge[nm1], data.xo[nm1], data.yo[nm1], data.zo[nm1], data.p[nm1], data.theta[nm1], data.phi[nm1], + rho, accuracy, sMax, stepSize[j], result); + String s = String.format("%7.0f %s", + 1.e6*stepSize[j], result.finalLocationString()); + + System.err.println(s); + + } + + + + + + // System.err.println("\n\nLast swim: " + result); } /** @@ -1088,7 +1225,7 @@ public static void main(String arg[]) { File mfdir = new File(System.getProperty("user.home"), "magfield"); System.out.println("mfdir exists: " + (mfdir.exists() && mfdir.isDirectory())); try { - mf.initializeMagneticFields(mfdir.getPath(), "Full_torus_r251_phi181_z251_25Jan2021.dat", + mf.initializeMagneticFields(mfdir.getPath(), "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -1102,7 +1239,11 @@ public static void main(String arg[]) { //swimToRhoTest(10000, 33557799); //test the swim to a cylinder - swimToCylinderTest(93450, 33557799); + //swimToCylinderTest(93450, 33557799); + + //gemcTrackTest(); + + uniformSwimToRhoTest(20, 33557799); // write out data file From 003f4eed29e00ebf9da4b376a6ac799c657b25f2 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 17 Jun 2021 22:40:24 -0400 Subject: [PATCH 129/291] Fix for l,s,n alignment support vectors. --- .../org/jlab/rec/cvt/cluster/Cluster.java | 36 +++++++++++++++---- .../jlab/rec/cvt/services/RecUtilities.java | 9 +++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 288d6de87..bbef33af6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.cluster; import java.util.ArrayList; +import org.jlab.clas.tracking.kalmanfilter.helical.StateVecs; import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; @@ -337,8 +338,10 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, double[][] Xf = sgeo.getStripEndPoints(100, (this.get_Layer() - 1) % 2); Point3D EPi = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xi[0][0], 0, Xi[0][1], "lab", ""); Point3D EPf = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xf[0][0], 0, Xf[0][1], "lab", ""); - Vector3D s = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips + + Vector3D se = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips Vector3D n = sgeo.findBSTPlaneNormal(this.get_Sector(), this.get_Layer()); + Vector3D s = l.cross(n).asUnit(); this.setL(l); this.setS(s); @@ -366,7 +369,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, Vector3D s = C2P1.cross(C2P2).asUnit(); Vector3D n = cyl.baseArc().normal(); Vector3D t = cyl.baseArc().center().vectorTo(cyl.baseArc().point(theta/2)); - Vector3D l = s.cross(t).asUnit(); + Vector3D l = s.cross(n).asUnit(); this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); this.setL(l); @@ -386,12 +389,19 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, Vector3D l = new Vector3D(weightedX2/totEn-weightedX1/totEn, weightedY2/totEn-weightedY1/totEn, weightedZ2/totEn-weightedZ1/totEn).asUnit(); - Vector3D n = cyl.baseArc().center().vectorTo(new Point3D((weightedX2/totEn+weightedX1/totEn)/2, - (weightedY2/totEn+weightedY1/totEn)/2, - (weightedZ2/totEn+weightedZ1/totEn)/2)).asUnit(); - Vector3D s = l.cross(n); - + + this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); + this.getCylAxis().setOrigin(this.getCylAxis().origin().x(), this.getCylAxis().origin().y(), weightedZ1/totEn); + this.getCylAxis().setEnd(this.getCylAxis().end().x(), this.getCylAxis().end().y(), weightedZ2/totEn); + Vector3D n = this.getN(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, this.getCylAxis()); + //Vector3D n = cyl.baseArc().center().vectorTo(new Point3D((weightedX2/totEn+weightedX1/totEn)/2, + // (weightedY2/totEn+weightedY1/totEn)/2, + // (weightedZ2/totEn+weightedZ1/totEn)/2)).asUnit(); + + + Vector3D s = l.cross(n).asUnit(); + this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); this.setL(l); this.setS(s); @@ -424,6 +434,18 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, } + + public Vector3D getN(double x, double y, double z, Line3D cln) { + double v = (cln.origin().z()-z)/cln.direction().z(); + double xs = x+v*cln.direction().x(); + double ys = y+v*cln.direction().y(); + + Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). + vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); + + return n; + } + public double get_Centroid() { return _Centroid; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index b11af50f4..9545c2a7c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -368,7 +368,7 @@ public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical. cand.addAll(seed.get_Crosses()); for(Cluster cl : seed.get_Clusters()) { int layer = cl.get_Layer(); - if(cl.get_Detector()==1){ + if(cl.get_Detector()==1 && cl.get_DetectorType()==0){ layer = layer + 6; Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); @@ -378,10 +378,9 @@ public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical. double y = cyl.baseArc().center().y()+v*cln.direction().y(); Vector3D n = new Point3D(x, y, kf.TrjPoints.get(layer).z). vectorTo(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).asUnit(); - cl.setN(n); - if (cl.get_DetectorType()==0) { - cl.setL(cl.getS().cross(n).asUnit()); - } + cl.setN(cl.getN(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z,cln)); + cl.setL(cl.getS().cross(n).asUnit()); + } //double x = kf.TrjPoints.get(layer).x; //double y = kf.TrjPoints.get(layer).y; From 1d24d9b9b89f20deb6b901f66023d641a1c75361 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 23 Jun 2021 15:36:49 -0400 Subject: [PATCH 130/291] fix helix point along hexliz at z --- .../src/main/java/org/jlab/clas/tracking/trackrep/Helix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 55aeebfa1..7d8eddd9e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -437,7 +437,7 @@ public double getLAtZ(double z) { } public Point3D getHelixPointAtZ(double z) { double l = getLAtZ( z); - return new Point3D(getX(l),getY(l),getZ(l)); + return new Point3D(getX(l),getY(l),z); } public Vector3D getMomentumAtZ(double z) { double l = getLAtZ( z); From e5e143cd5731d87debd016509ccc9179474a5b32 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 23 Jun 2021 15:37:36 -0400 Subject: [PATCH 131/291] add axis to Cylinder --- .../java/org/jlab/geom/prim/Cylindrical3D.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java index dbc5da615..43de3cd38 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java @@ -14,7 +14,7 @@ public final class Cylindrical3D implements Face3D { private final Arc3D baseArc = new Arc3D(); private double height; - + private final Line3D axis = new Line3D(); /** * Constructs a new {@code Cylindrical3D} such that the arc of the surface * is centered around the z axis, the radius is one, the arc begins at x=1 @@ -71,6 +71,20 @@ public void setArc(Arc3D arc) { this.baseArc.copy(arc); } + /** + * Sets the axis of this cylinder. + * @param axis the base of the cylindrical segment + */ + public void setAxis(Line3D axis) { + this.axis.copy(axis); + } + /** + * returns the axis of this cylinder. + */ + public Line3D getAxis() { + return this.axis; + } + /** * Sets the height of this cylindrical segment. * @param height the height From 84bb93a951b2f87d213c4f9308fb40cf054726a2 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 23 Jun 2021 15:38:15 -0400 Subject: [PATCH 132/291] use generic cylinder projetor --- .../kalmanfilter/helical/MeasVecs.java | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 77cb3223f..d81d59a5d 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -13,8 +13,10 @@ import org.jlab.clas.tracking.kalmanfilter.Type; import org.jlab.clas.tracking.kalmanfilter.helical.StateVecs.StateVec; import org.jlab.clas.tracking.objects.Strip; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; /** * @@ -64,26 +66,65 @@ public double dh(int k, StateVec stateVec) { this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, this.measurements.get(stateVec.k).surface.lineEndPoint2); - value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + Line3D WL = new Line3D(); + WL.copy(l); + WL.copy(WL.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z))); + + value = WL.length(); } if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, this.measurements.get(stateVec.k).surface.lineEndPoint2); - value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + if(l.direction().z()<0) { + l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); + l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); + } + Line3D WL = new Line3D(); + WL.copy(l); + Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); + WL.copy(WL.distance(svP)); + double sideStrip = Math.signum(l.direction().cross(WL.direction()). + dot(this.measurements.get(stateVec.k).surface.plane.normal())); + //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); + value = WL.length()*sideStrip; } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { value = stateVec.z-this.measurements.get(stateVec.k).surface.strip.getZ(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - value = Math.atan2(stateVec.y, stateVec.x)-this.measurements.get(stateVec.k).surface.strip.getPhi(); + value = this.getPhi(stateVec)-this.measurements.get(stateVec.k).surface.strip.getPhi(); } } return value; } - + public double getPhiATZ(StateVec stateVec) { + Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; + Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); + double v = (stateVec.z-cyl.baseArc().center().z())/cln.direction().z(); + double x = cyl.baseArc().center().x()+v*cln.direction().x(); + double y = cyl.baseArc().center().y()+v*cln.direction().y(); + Vector3D n = new Point3D(x, y, stateVec.z). + vectorTo(new Point3D(stateVec.x,stateVec.y,stateVec.z)).asUnit(); + return n.phi(); + } + + public double getPhi(StateVec stateVec) { + Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); + + double v = (cln.origin().z()-stateVec.z)/cln.direction().z(); + double xs = stateVec.x+v*cln.direction().x(); + double ys = stateVec.y+v*cln.direction().y(); + + Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). + vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); + return n.phi(); + } + public double h(int k, StateVec stateVec) { double value = Double.NaN; @@ -113,13 +154,27 @@ public double h(int k, StateVec stateVec) { if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, this.measurements.get(stateVec.k).surface.lineEndPoint2); - value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + if(l.direction().z()<0) { + l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); + l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); + } + Line3D WL = new Line3D(); + WL.copy(l); + Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); + WL.copy(WL.distance(svP)); + double sideStrip = Math.signum(l.direction().cross(WL.direction()). + dot(this.measurements.get(stateVec.k).surface.plane.normal())); + //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); + value = WL.length()*sideStrip; + } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { value = stateVec.z; } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - value = Math.atan2(stateVec.y, stateVec.x); + //value = Math.atan2(stateVec.y, stateVec.x); + value = this.getPhi(stateVec); } } return value; @@ -182,7 +237,7 @@ private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec s return SVplus; } - + public class MeasVec implements Comparable { public Surface surface; public int layer = -1; From 152134529e01104ee6c9ba716c82085f2d72d5e2 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 23 Jun 2021 15:40:45 -0400 Subject: [PATCH 133/291] reduce step size in SwimRho --- .../swim-tools/src/main/java/org/jlab/clas/swimtools/Swim.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4e6d83f54..1a3d89c7c 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 @@ -488,7 +488,7 @@ public double[] SwimRho(double radius) { SwimResult result = new SwimResult(6); - PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy*2, _rMax, stepSize*10, cnuphys.swim.Swimmer.CLAS_Tolerance, result); + PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); value[0] = result.getUf()[0] * 100; // convert back to cm value[1] = result.getUf()[1] * 100; // convert back to cm From 5b5d3508a639fbb0d65744209965449b2b759264 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 23 Jun 2021 15:51:22 -0400 Subject: [PATCH 134/291] Modification to getting Lorentz angle byt reading the field. Lorentz angle correction fix. Fix in BMT uncertainty used in the fit. Fix in using isolated SVT clusters in track refit. Hit sorting using time and Edep. New clustering implemented; Default = off. --- .../main/java/org/jlab/rec/cvt/Constants.java | 4 +- .../org/jlab/rec/cvt/banks/HitReader.java | 13 +-- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 66 ++++++++++++--- .../java/org/jlab/rec/cvt/bmt/Constants.java | 12 +-- .../java/org/jlab/rec/cvt/bmt/Lorentz.java | 81 ++++++++++--------- .../org/jlab/rec/cvt/cluster/Cluster.java | 37 +++++++-- .../java/org/jlab/rec/cvt/cross/Cross.java | 17 +++- .../java/org/jlab/rec/cvt/hit/FittedHit.java | 22 +++-- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 27 +++++-- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 72 ++++++++++++----- .../jlab/rec/cvt/services/CVTRecNewKF.java | 28 ++++++- .../jlab/rec/cvt/services/RecUtilities.java | 35 ++++++-- .../rec/cvt/services/TracksFromTargetRec.java | 50 +++++++++--- 13 files changed, 338 insertions(+), 126 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index baf7025ea..0db175c50 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -6,6 +6,7 @@ public class Constants { public static double PTCUT = 0.075; + /** * Constants used in the reconstruction @@ -13,9 +14,6 @@ public class Constants { Constants() { } - // SIMULATION FLAG - public static boolean isSimulation = true; - // CONSTANTS USED IN RECONSTRUCTION //--------------------------------- public static final double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index e8ed194d5..b587b6369 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -72,7 +73,7 @@ public void set_SVTHits(List _SVTHits) { * Edep for gemc, adc for cosmics) * @param geo the BMT geometry */ - public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cvt.bmt.BMTGeometry geo) { + public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cvt.bmt.BMTGeometry geo, Swim swim) { // return if there is no BMT bank if (event.hasBank("BMT::adc") == false) { @@ -103,9 +104,10 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cv continue; } // create the strip object for the BMT - Strip BmtStrip = new Strip((int) bankDGTZ.getShort("component", i), ADCtoEdep); + //Strip BmtStrip = new Strip((int) bankDGTZ.getShort("component", i), ADCtoEdep); + Strip BmtStrip = new Strip((int) bankDGTZ.getShort("component", i), ADCtoEdep, (double) bankDGTZ.getFloat("time", i)); // calculate the strip parameters for the BMT hit - BmtStrip.calc_BMTStripParams(geo,(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i)); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect + BmtStrip.calc_BMTStripParams(geo,(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect // create the hit object for detector type BMT Hit hit = new Hit(1, this.getZorC((int) bankDGTZ.getByte("layer", i)),(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), BmtStrip); @@ -150,7 +152,8 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int[] layer = new int[rows]; int[] strip = new int[rows]; int[] ADC = new int[rows]; - + float[] time = new float[rows]; + if (event.hasBank("BST::adc") == true) { //bankDGTZ.show(); for (int i = 0; i < rows; i++) { @@ -195,7 +198,7 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, //if(adcConv.SVTADCtoDAQ(ADC[i], event)<50) // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate - Strip SvtStrip = new Strip(strip[i], adcConv.SVTADCtoDAQ(ADC[i], event)); + Strip SvtStrip = new Strip(strip[i], adcConv.SVTADCtoDAQ(ADC[i], event), (double) time[i]); // get the strip endPoints double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 67ad14dc5..a4fb00e99 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -13,7 +13,7 @@ import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; - +import org.jlab.clas.swimtools.Swim; /** * * @author devita @@ -321,7 +321,7 @@ public Line3D getIdealZstrip(int region, int sector, int strip) { double zmin = Constants.getCRCZMIN()[region-1]; double zmax = Constants.getCRCZMAX()[region-1]; double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] - + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; + + ((double) strip-0.5-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; Point3D p1= new Point3D(radius, 0, zmin); p1.rotateZ(angle); @@ -363,23 +363,35 @@ public Line3D getZstrip(int region, int sector, int strip) { * @param strip * @return Line3D */ - public Line3D getIdealLCZstrip(int region, int sector, int strip) { + public Line3D getIdealLCZstrip(int region, int sector, int strip, Swim swim) { double radius = Constants.getCRZRADIUS()[region-1]; int layer = this.getLayer(region, BMTType.Z); double zmin = Constants.getCRCZMIN()[region-1]; double zmax = Constants.getCRCZMAX()[region-1]; double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] - + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; - double theLorentzCorrectedAngle = angle + this.LorentzAngleCorr(layer,sector); + + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / radius ; +// double theLorentzCorrectedAngle = angle + this.LorentzAngleCorr(layer,sector); Point3D p1= new Point3D(radius, 0, zmin); - p1.rotateZ(theLorentzCorrectedAngle); + p1.rotateZ(angle); Point3D p2= new Point3D(radius, 0, zmax); - p2.rotateZ(theLorentzCorrectedAngle); - + p2.rotateZ(angle); Line3D stripline = new Line3D(p1,p2); + double x = stripline.midpoint().x(); + double y = stripline.midpoint().y(); + double z = stripline.midpoint().z(); - return stripline; + double alpha = this.getThetaLorentz(layer, sector, x,y,z,swim); + double ralpha = Math.atan2(Constants.hStrip2Det*Math.tan(alpha), radius + Constants.hStrip2Det); + Point3D np1= new Point3D((radius+ Constants.hStrip2Det) * Math.cos(ralpha), + (radius+Constants.hStrip2Det) * Math.sin(ralpha), zmin); + Point3D np2= new Point3D((radius+ Constants.hStrip2Det) * Math.cos(ralpha), + (radius+Constants.hStrip2Det) * Math.sin(ralpha), zmax); + np1.rotateZ(angle); + np2.rotateZ(angle); + + Line3D nstripline = new Line3D(np1,np2); + return nstripline; } /** @@ -390,10 +402,10 @@ public Line3D getIdealLCZstrip(int region, int sector, int strip) { * @param strip * @return stripline */ - public Line3D getLCZstrip(int region, int sector, int strip) { + public Line3D getLCZstrip(int region, int sector, int strip, Swim swim) { int layer = this.getLayer(region, BMTType.Z); - Line3D stripline = this.getIdealLCZstrip(region, sector, strip); + Line3D stripline = this.getIdealLCZstrip(region, sector, strip, swim); Point3D offset = this.getOffset(layer, sector); Vector3D rotation = this.getRotation(layer, sector); @@ -767,6 +779,38 @@ public double getThetaLorentz(int layer, int sector) { return thetaL; } + /** + * Calculate Theta Lorentz based on solenoid scale and drift settings + * @param layer + * @param sector + * @return thetaL in radians + */ + public double getThetaLorentz(int layer, int sector, double x, double y, double z, Swim swim) { + + double thetaL = 0; + float[] b = new float[3]; + swim.BfieldLab(x/10, y/10, z/10, b); + double EDrift=0; + if(Constants.isMC == true) { + EDrift = 5000*Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()); + } else { + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { + EDrift = Constants.E_DRIFT_MF[layer-1][sector-1]; + } else { + EDrift = Constants.E_DRIFT_FF[layer-1][sector-1]; + } + } + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001) { + thetaL = 0; + } + else { + thetaL = Math.toRadians(getLorentzAngle(EDrift,Math.abs(b[2]*10))); + } + if (org.jlab.rec.cvt.Constants.getSolenoidscale()<0) thetaL=-thetaL; + return thetaL; + } + + /** * Calculate Lorentz angle correction * @param layer diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java index 813f9dee4..dc9720372 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java @@ -9,8 +9,8 @@ public class Constants { private Constants() { } - - + public static boolean newClustering = false; + public static boolean isMC = true; /* * The algorithm to describe the geometry of the Barrel Micromegas is provided by Franck Sabatie and implemented into the Java framework. * This version is for the last region of the BMT only. @@ -415,15 +415,15 @@ public static synchronized void setB_grid(double[] cB_grid) { public static synchronized void setPar_grid() { double pe=0; double pb=0; - + Ne=15; + Nb=27; for (int j=0;j<405;j++) { if(Ne==0 && Nb==0 ){ emin = E_grid[j]; emax = E_grid[j]; bmin = B_grid[j]; bmax = B_grid[j]; - Ne=15; - Nb=27; + pe = E_grid[j]; pb = B_grid[j]; continue; @@ -446,7 +446,7 @@ public static synchronized void setPar_grid() { public static synchronized void setE_drift_FF(double[][] cHV_drift) { for (int i=0; i<2*NREGIONS;i++) { for (int j=0; j<3;j++) { - E_DRIFT_FF[i][j] = 10*cHV_drift[i][j]/hDrift; + E_DRIFT_FF[i][j] = 10*cHV_drift[i][j]/hDrift; } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java index 13dc71e96..065076ba0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java @@ -12,46 +12,47 @@ public Lorentz() { } public static double getLorentzAngle(double xe, double xb) { - if (xe==0||xb==0) return 0; - double de = (org.jlab.rec.cvt.bmt.Constants.emax-org.jlab.rec.cvt.bmt.Constants.emin)/(org.jlab.rec.cvt.bmt.Constants.Ne-1); - double db = (org.jlab.rec.cvt.bmt.Constants.bmax-org.jlab.rec.cvt.bmt.Constants.bmin)/(org.jlab.rec.cvt.bmt.Constants.Nb-1); - - if (xe=org.jlab.rec.cvt.bmt.Constants.emax) { - xe=org.jlab.rec.cvt.bmt.Constants.emax*0.99; - System.err.println("Warning: E out of grid... setting it to Emax"); - } - if (xb>org.jlab.rec.cvt.bmt.Constants.bmax) { - xb=org.jlab.rec.cvt.bmt.Constants.bmax*0.99; - System.err.println("Warning: B field out of grid... setting it to Bmax"); - } - - int i11 = getBin( xe, xb); - int i12 = getBin( xe, xb+db); - int i21 = getBin( xe+de, xb); - int i22 = getBin( xe+de, xb+db); - - double Q11 = 0; double Q12 = 0; double Q21 = 0; double Q22 = 0; - double e1 = org.jlab.rec.cvt.bmt.Constants.emin; double e2 = org.jlab.rec.cvt.bmt.Constants.emax; double b1 = 0; double b2 = org.jlab.rec.cvt.bmt.Constants.bmax; - if (i11>=0) { - Q11=org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i11]; e1 = org.jlab.rec.cvt.bmt.Constants.E_grid[i11]; b1 = org.jlab.rec.cvt.bmt.Constants.B_grid[i11]; - } - if (i12>=0) Q12 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i12]; - if (xb>=org.jlab.rec.cvt.bmt.Constants.bmin) Q21 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i21]; - if (xb=0) { - Q22 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i22]; e2 = org.jlab.rec.cvt.bmt.Constants.E_grid[i22]; b2 = org.jlab.rec.cvt.bmt.Constants.B_grid[i22]; - } - - double R1 = linInterp( xe, e1,e2,Q11,Q21); - double R2 = linInterp( xe, e1,e2,Q12,Q22); - - double P = linInterp( xb, b1,b2,R1, R2); - - return P; + + if (xe==0||xb==0) return 0; + double de = (org.jlab.rec.cvt.bmt.Constants.emax-org.jlab.rec.cvt.bmt.Constants.emin)/(org.jlab.rec.cvt.bmt.Constants.Ne-1); + double db = (org.jlab.rec.cvt.bmt.Constants.bmax-org.jlab.rec.cvt.bmt.Constants.bmin)/(org.jlab.rec.cvt.bmt.Constants.Nb-1); + + if (xe=org.jlab.rec.cvt.bmt.Constants.emax) { + xe=org.jlab.rec.cvt.bmt.Constants.emax; + System.err.println("Warning: E out of grid... setting it to Emax"); + } + if (xb>org.jlab.rec.cvt.bmt.Constants.bmax) { + xb=org.jlab.rec.cvt.bmt.Constants.bmax; + //System.err.println("Warning: B field out of grid... setting it to Bmax = "+org.jlab.rec.cvt.bmt.Constants.bmax); + } + + int i11 = getBin( xe, xb); + int i12 = getBin( xe, xb+db); + int i21 = getBin( xe+de, xb); + int i22 = getBin( xe+de, xb+db); + + double Q11 = 0; double Q12 = 0; double Q21 = 0; double Q22 = 0; + double e1 = org.jlab.rec.cvt.bmt.Constants.emin; double e2 = org.jlab.rec.cvt.bmt.Constants.emax; double b1 = 0; double b2 = org.jlab.rec.cvt.bmt.Constants.bmax; + if (i11>=0) { + Q11=org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i11]; e1 = org.jlab.rec.cvt.bmt.Constants.E_grid[i11]; b1 = org.jlab.rec.cvt.bmt.Constants.B_grid[i11]; + } + if (i12>=0) Q12 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i12]; + if (xb>=org.jlab.rec.cvt.bmt.Constants.bmin) Q21 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i21]; + if (xb=0) { + Q22 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i22]; e2 = org.jlab.rec.cvt.bmt.Constants.E_grid[i22]; b2 = org.jlab.rec.cvt.bmt.Constants.B_grid[i22]; + } + + double R1 = linInterp( xe, e1,e2,Q11,Q12); + double R2 = linInterp( xe, e1,e2,Q21,Q22); + + double P = linInterp( xb, b1,b2,R1, R2); + + return P; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 6cf4ed056..2fd1d3198 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -6,6 +6,8 @@ import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; +import java.util.Collections; +import org.jlab.rec.cvt.bmt.Constants; /** * A cluster in the BST consists of an array of hits that are grouped together * according to the algorithm of the ClusterFinder class @@ -171,21 +173,24 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { this.set_StripDir(arcLine.normal()); */ int nbhits = this.size(); - + //sort for bmt detector + //this.sort(Comparator.comparing(FittedHit.get_Strip()::get_Edep).thenComparing(FittedHit.get_Strip()::get_Edep)); + Collections.sort(this); if (nbhits != 0) { int min = 1000000; int max = -1; int seed = -1; double Emax = -1; + // looping over the number of hits in the cluster for (int i = 0; i < nbhits; i++) { FittedHit thehit = this.get(i); // gets the energy value of the strip - double strpEn = thehit.get_Strip().get_Edep(); - + double strpEn = -1; int strpNb = -1; int strpNb0 = -1; //before LC if (this.get_Detector()==0) { + strpEn = thehit.get_Strip().get_Edep(); // for the SVT the analysis only uses the centroid strpNb = thehit.get_Strip().get_Strip(); Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); @@ -196,10 +201,23 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { weightedX2 += strpEn * stEP2.x(); weightedY2 += strpEn * stEP2.y(); weightedZ2 += strpEn * stEP2.z(); + + totEn += strpEn; + weightedStrp += strpEn * (double) strpNb; + weightedStrp0 += strpEn * (double) strpNb0; } if (this.get_Detector()==1) { + if(Constants.newClustering) { + strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); + } else { + //strpEn = thehit.get_Strip().get_Edep(); + strpEn = 1; + } + if(Constants.newClustering && nbhits>2 && i>1) + continue; // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_DetectorType()==0) { // C-detectors + //strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); strpNb = thehit.get_Strip().get_Strip(); // for C detector the Z of the centroid is calculated weightedZ += strpEn * thehit.get_Strip().get_Z(); @@ -226,14 +244,21 @@ public void calc_CentroidParams(org.jlab.rec.cvt.bmt.BMTGeometry geo) { Point3D stEP2 = thehit.get_Strip().get_EndPoint(); weightedX1 += strpEn * stEP1.x(); weightedY1 += strpEn * stEP1.y(); + weightedZ1 += strpEn * stEP1.z(); weightedX2 += strpEn * stEP2.x(); weightedY2 += strpEn * stEP2.y(); + weightedZ2 += strpEn * stEP2.z(); } + + totEn += strpEn; + weightedStrp += strpEn * (double) strpNb; + weightedStrp0 += strpEn * (double) strpNb0; + } - totEn += strpEn; - weightedStrp += strpEn * (double) strpNb; - weightedStrp0 += strpEn * (double) strpNb0; +// totEn += strpEn; +// weightedStrp += strpEn * (double) strpNb; +// weightedStrp0 += strpEn * (double) strpNb0; // getting the max and min strip number in the cluster if (strpNb <= min) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 740c754fe..ce830c73f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -24,7 +24,8 @@ public class Cross extends ArrayList implements Comparable { */ private static final long serialVersionUID = 5317526429163382618L; public boolean isInSeed = false; - + private double cCrossRadius = 0; + /** * @param detector SVT or BMT * @param detectortype detector type for BMT, C or Z detector @@ -522,6 +523,20 @@ public void set_AssociatedTrackID(int associatedTrackID) { AssociatedTrackID = associatedTrackID; } + /** + * @return the cCrossRadius + */ + public double getcCrossRadius() { + return cCrossRadius; + } + + /** + * @param cCrossRadius the cCrossRadius to set + */ + public void setcCrossRadius(double cCrossRadius) { + this.cCrossRadius = cCrossRadius; + } + public static void main(String arg[]) { Constants.Load(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java index 1112b01e4..eb9e41437 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java @@ -66,13 +66,23 @@ public void set_TrkgStatus(int trkgStatus) { * @param arg0 the other hit * @return an int used to sort a collection of hits by layer number */ - public int compareTo(FittedHit arg0) { - if (this.get_Layer() > arg0.get_Layer()) { - return 1; - } else { - return 0; + public int compareTo(FittedHit arg) { +// if (this.get_Layer() > arg.get_Layer()) { +// return 1; +// } else { +// return 0; +// } + + //sort by layer, then time, then edep + int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; + int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; + int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; + + int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); + int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); + + return return_val; } - } public double _QualityFac; // a quality factor depending on the hit status and goodness of fit diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index 6fd2e8a34..baeb04c7b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -128,20 +128,31 @@ public int get_RegionSlayer() { * by wire is used in clustering. */ @Override - public int compareTo(Hit arg0) { - if (this._Strip.get_Strip() > arg0._Strip.get_Strip()) { - return 1; - } else { - return 0; +// public int compareTo(Hit arg0) { +// if (this._Strip.get_Strip() > arg0._Strip.get_Strip()) { +// return 1; +// } else { +// return 0; +// } +// } + public int compareTo(Hit arg) { + //sort by layer, then time, then edep + int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; + int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; + int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; + + int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); + int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); + + return return_val; } - } - /** * * @return print statement with hit information */ public void printInfo() { - String s = " Hit: Detector " + this.get_Detector() + "ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Strip " + this.get_Strip().get_Strip() + " Edep " + this.get_Strip().get_Edep(); + String s = " Hit: Detector " + this.get_Detector() + "ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Strip " + this.get_Strip().get_Strip() + + " Edep " + this.get_Strip().get_Edep()+ " Time " + this.get_Strip().get_Time(); System.out.println(s); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index c352eee19..93937c04c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -1,20 +1,22 @@ package org.jlab.rec.cvt.hit; +import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.Constants; -import org.jlab.rec.cvt.bmt.Geometry; public class Strip { - public Strip(int strip, double edep) { + public Strip(int strip, double edep, double time) { this._Strip = strip; this._Edep = edep; + this._Time = time; } + private int _Strip; // strip read from daq private int _LCStrip; // strip number taking into account Lorentz angle correction (for MM Z detectors) @@ -26,7 +28,8 @@ public Strip(int strip, double edep) { private double _Z; // for MM C-detectors. the z position at the strip midwidth private double _ZErr; private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value - + private double _Time; + private Point3D _ImplantPoint; // the end-point of the strip at implant (lab frame) private Point3D _MidPoint; // the mid-point of the strip (lab frame) private Point3D _EndPoint; // the end-point of the strip (lab frame) @@ -136,12 +139,26 @@ public void set_Edep(double _Edep) { this._Edep = _Edep; } + /** + * @return the _Time + */ + public double get_Time() { + return _Time; + } + + /** + * @param _Time the _Time to set + */ + public void set_Time(double _Time) { + this._Time = _Time; + } + /** * * @param geo the BMT geometry class Sets the Lorentz corrected phi and * strip number for Z detectors, the z position for C detectors */ - public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector, int layer) { + public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector, int layer, Swim swim) { if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z @@ -160,24 +177,44 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors + //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); + Line3D L = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip(), swim); + this.set_ImplantPoint(L.origin()); + this.set_MidPoint(L.midpoint()); + this.set_EndPoint(L.end()); + this.set_StripDir(L.direction()); + + Cylindrical3D cyl = geo.getCylinder(layer, sector); + Line3D cln = geo.getAxis(layer, sector); + cln.set(cln.origin().x(), cln.origin().y(), L.origin().z(), + cln.end().x(), cln.end().y(), L.end().z()); + + double v = (L.origin().z()-cln.origin().z())/cln.direction().z(); + double x = cln.origin().x()+v*cln.direction().x(); + double y = cln.origin().y()+v*cln.direction().y(); + Vector3D n = new Point3D(x, y, L.origin().z()). + vectorTo(new Point3D(L.origin().x(),L.origin().y(),L.origin().z())).asUnit(); + double theMeasuredPhi = geo.CRZStrip_GetPhi(sector, layer, this.get_Strip()); - double theLorentzCorrectedAngle = theMeasuredPhi + geo.LorentzAngleCorr(layer,sector); + //double theLorentzCorrectedAngle = L.midpoint().toVector3D().phi(); + double theLorentzCorrectedAngle = n.phi(); // set the phi this.set_Phi(theLorentzCorrectedAngle); this.set_Phi0(theMeasuredPhi); // uncorrected //System.out.println(" sec "+sector+" strip "+this.get_Strip()+" LC strip "+geo.getZStrip(layer, theLorentzCorrectedAngle)); //int theLorentzCorrectedStrip = geo.getZStrip(layer, theLorentzCorrectedAngle); int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; - double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* - Math.cos(theLorentzCorrectedAngle); - double yl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* - Math.sin(theLorentzCorrectedAngle); - int theLorentzCorrectedStrip = geo.getStrip( layer, sector, - new Point3D(xl,yl,0)); +// double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* +// Math.cos(theLorentzCorrectedAngle); +// double yl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* +// Math.sin(theLorentzCorrectedAngle); +// int theLorentzCorrectedStrip = geo.getStrip( layer, sector, +// new Point3D(xl,yl,0)); + int theLorentzCorrectedStrip = geo.getStrip( layer, sector, L.midpoint()); // get the strip number after correcting for Lorentz angle this.set_LCStrip(theLorentzCorrectedStrip); - - double sigma = org.jlab.rec.cvt.bmt.Constants.SigmaDrift / Math.cos(org.jlab.rec.cvt.bmt.Constants.getThetaL()); // max sigma for drift distance (hDrift) = total gap from top to mesh + + double sigma = org.jlab.rec.cvt.bmt.Constants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh //max phi err double phiErrL = sigma / org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; @@ -187,12 +224,7 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector //System.out.println("arcerr "+org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]+" * "+Math.toDegrees(sigma/org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region])); this.set_PhiErr0(phiErr); - //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); - Line3D L = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip()); - this.set_ImplantPoint(L.origin()); - this.set_MidPoint(L.midpoint()); - this.set_EndPoint(L.end()); - this.set_StripDir(L.direction()); + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index d02798dcc..88c0d3b0a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -69,7 +69,6 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int boolean isMC = false; boolean isCosmics = false; DataBank bank = event.getBank("RUN::config"); - //System.out.println("EVENTNUM "+bank.getInt("event",0)); if (bank.getByte("type", 0) == 0) { isMC = true; } @@ -107,6 +106,12 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int Constants.setSolenoidVal(Math.abs(b[2])); Constants.Load(isCosmics, isSVTonly); this.setRun(newRun); + + if(newRun<100) { + org.jlab.rec.cvt.bmt.Constants.isMC = true; + } else { + org.jlab.rec.cvt.bmt.Constants.isMC = false; + } } Run = newRun; @@ -144,7 +149,7 @@ public boolean processDataEvent(DataEvent event) { HitReader hitRead = new HitReader(); hitRead.fetch_SVTHits(event, adcConv, -1, -1, SVTGeom); if(isSVTonly==false) - hitRead.fetch_BMTHits(event, adcConv, BMTGeom); + hitRead.fetch_BMTHits(event, adcConv, BMTGeom, swimmer); List hits = new ArrayList(); //I) get the hits @@ -314,6 +319,25 @@ public boolean init() { } if(exlyrsnb>0) exclLayrs = true; + + //new clustering + String newClustering = this.getEngineConfigString("newclustering"); + + if (newClustering!=null) { + System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on yaml"); + org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); + } + else { + newClustering = System.getenv("COAT_CVT_NEWCLUSTERING"); + if (newClustering!=null) { + System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on env"); + org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); + } + } + if (newClustering==null) { + System.out.println("["+this.getName()+"] run with newclustering settings default = false"); + } + // Load other geometries variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index d16e584b2..64e31ffb3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -76,7 +76,7 @@ public void CleanupSpuriousCrosses(List> crosses, List t public List setMeasVecs(Seed trkcand, org.jlab.rec.cvt.svt.Geometry sgeo, - org.jlab.rec.cvt.bmt.BMTGeometry bgeo) { + org.jlab.rec.cvt.bmt.BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), @@ -130,17 +130,37 @@ public List setMeasVecs(Seed trkcand, int sec = trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(); Cylindrical3D cyl = bgeo.getCylinder(lyer, sec); - + Line3D cln = bgeo.getAxis(lyer, sec); + Line3D l = bgeo.getLCZstrip(bgeo.getRegion(lyer), sec, 1, swim); + cln.set(cln.origin().x(), cln.origin().y(), l.origin().z(), + cln.end().x(), cln.end().y(), l.end().z()); + cyl.setAxis(cln); int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.Z) { - double x = trkcand.get_Crosses().get(c).get_Point().x(); - double y = trkcand.get_Crosses().get(c).get_Point().y(); - double phi = Math.atan2(y,x); - double err = trkcand.get_Crosses().get(c).get_Cluster1().get_PhiErr() - *(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + //double x = trkcand.get_Crosses().get(c).get_Point().x(); + //double y = trkcand.get_Crosses().get(c).get_Point().y(); + Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint1(); + //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); + + double v = (EP1.z()-cln.origin().z())/cln.direction().z(); + double x = cln.origin().x()+v*cln.direction().x(); + double y = cln.origin().y()+v*cln.direction().y(); + Vector3D n = new Point3D(x, y, EP1.z()). + vectorTo(new Point3D(EP1.x(),EP1.y(),EP1.z())).asUnit(); + + double phi = n.phi(); + + //double phi = Math.atan2(y,x); + double err = trkcand.get_Crosses().get(c).get_Cluster1().get_PhiErr(); + // *(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + //Strip strp = new Strip(id, ce, x, y, phi); + //Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint1(); + //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); Strip strp = new Strip(id, ce, x, y, phi); + //Strip strp = new Strip( id, ce, EP1.x(), EP1.y(), EP1.z(), EP2.x(), EP2.y(), EP2.z()); + //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); @@ -167,6 +187,7 @@ public List setMeasVecs(Seed trkcand, Strip strp = new Strip(id, ce, z); cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + Surface meas = new Surface(cyl, strp); meas.setSector(trkcand.get_Crosses().get(c).get_Sector()); meas.setLayer(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index e6741f681..6931b43ea 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -7,7 +7,9 @@ import Jama.Matrix; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; @@ -16,6 +18,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -101,22 +104,24 @@ public boolean processEvent(DataEvent event, charge = 1; xr += org.jlab.rec.cvt.Constants.getXb(); yr += org.jlab.rec.cvt.Constants.getYb(); + hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); + Matrix cov = seed.get_Helix().get_covmatrix(); if(Math.abs(Constants.getSolenoidVal())>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *Constants.getSolenoidVal()0) { + if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) { Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); for(Cross c : fittedTrack) { if(c.get_Detector().equalsIgnoreCase("SVT")) { @@ -127,13 +132,36 @@ public boolean processEvent(DataEvent event, //refit adding missing clusters List clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, fittedTrack.get_helix(), fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); - seed.get_Clusters().addAll(clsOnTrack); + if(clsOnTrack.size()>0) { + seed.get_Clusters().addAll(clsOnTrack); + } + + //reset pars + xr = -fittedTrack.get_helix().get_dca()*Math.sin(fittedTrack.get_helix().get_phi_at_dca()); + yr = fittedTrack.get_helix().get_dca()*Math.cos(fittedTrack.get_helix().get_phi_at_dca()); + zr = fittedTrack.get_helix().get_Z0(); + pt = Constants.LIGHTVEL * fittedTrack.get_helix().radius() * Constants.getSolenoidVal(); + if(Math.abs(Constants.getSolenoidVal())<0.001) + pt = 100; + pz = pt*fittedTrack.get_helix().get_tandip(); + px = pt*Math.cos(fittedTrack.get_helix().get_phi_at_dca()); + py = pt*Math.sin(fittedTrack.get_helix().get_phi_at_dca()); + charge = (int) (Math.signum(Constants.getSolenoidscale())*fittedTrack.get_helix().get_charge()); + if(Math.abs(Constants.getSolenoidVal())<0.001) + charge = 1; + xr += org.jlab.rec.cvt.Constants.getXb(); + yr += org.jlab.rec.cvt.Constants.getYb(); + hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, + charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), + org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); + kf = new org.jlab.clas.tracking.kalmanfilter.helical.KFitter( hlx, cov, event, swimmer, org.jlab.rec.cvt.Constants.getXb(), org.jlab.rec.cvt.Constants.getYb(), shift, - recUtil.setMeasVecs(seed, SVTGeom, BMTGeom)) ; + recUtil.setMeasVecs(seed, SVTGeom, BMTGeom, swimmer)) ; kf.runFitter(swimmer); + trkcands.add(recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom)); trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); } @@ -153,8 +181,10 @@ public boolean processEvent(DataEvent event, //This last part does ELoss C TrackListFinder trkFinder = new TrackListFinder(); List tracks = trkFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); + for( int i=0;i Date: Fri, 25 Jun 2021 00:49:43 -0400 Subject: [PATCH 135/291] Fix s,l,n vectors for arbitrary BMT axis. --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 26 ++++++++++- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 24 ++++++---- .../org/jlab/rec/cvt/cluster/Cluster.java | 44 ++++++++----------- .../jlab/rec/cvt/services/RecUtilities.java | 18 +++++--- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 608c12b82..5d3f1093a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -119,7 +119,17 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); - +// cluslist.get(i).printInfo(); +// System.out.println("N "+cluslist.get(i).getN().toString()+" \n"+ +// " L "+cluslist.get(i).getL().toString()+" \n"+ +// " S "+cluslist.get(i).getS().toString()+" \n"+ +// " NxL "+cluslist.get(i).getN().cross(cluslist.get(i).getL()).toString()+" \n"+ +// " NxS "+cluslist.get(i).getN().cross(cluslist.get(i).getS()).toString()+" \n"+ +// " SxL "+cluslist.get(i).getS().cross(cluslist.get(i).getL()).toString()+" \n"+ +// " N.L "+cluslist.get(i).getN().dot(cluslist.get(i).getL())+ +// " N.S "+cluslist.get(i).getN().dot(cluslist.get(i).getS())+ +// " S.L "+cluslist.get(i).getS().dot(cluslist.get(i).getL()) +// ); } //bank.show(); return bank; @@ -285,7 +295,19 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); - +// if(cluslist.get(i).get_AssociatedTrackID()>0) { +// cluslist.get(i).printInfo(); +// System.out.println("N "+cluslist.get(i).getN().toString()+" \n"+ +// " L "+cluslist.get(i).getL().toString()+" \n"+ +// " S "+cluslist.get(i).getS().toString()+" \n"+ +// " NxL "+cluslist.get(i).getN().cross(cluslist.get(i).getL()).toString()+" \n"+ +// " NxS "+cluslist.get(i).getN().cross(cluslist.get(i).getS()).toString()+" \n"+ +// " SxL "+cluslist.get(i).getS().cross(cluslist.get(i).getL()).toString()+" \n"+ +// " N.L "+cluslist.get(i).getN().dot(cluslist.get(i).getL())+ +// " N.S "+cluslist.get(i).getN().dot(cluslist.get(i).getS())+ +// " S.L "+cluslist.get(i).getS().dot(cluslist.get(i).getL()) +// ); +// } } //bank.show(); return bank; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 67ad14dc5..56c0567b7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -517,17 +517,25 @@ public Arc3D getCstrip(int region, int sector, int strip) { */ public Cylindrical3D getCylinder(int layer, int sector) { Cylindrical3D cyl = new Cylindrical3D(); - cyl.baseArc().setCenter(new Point3D(0, 0, 0)); - cyl.highArc().setCenter(new Point3D(0, 0, 0)); - cyl.baseArc().setNormal(new Vector3D(0,1,0)); - cyl.highArc().setNormal(new Vector3D(0,1,0)); + Point3D cent = new Point3D(0, 0, 0); + Vector3D norm = new Vector3D(0,1,0); Point3D offset = this.getOffset(layer, sector); Vector3D rotation = this.getRotation(layer, sector); - cyl.rotateX(rotation.x()); - cyl.rotateY(rotation.y()); - cyl.rotateZ(rotation.z()); - cyl.translateXYZ(offset.x(),offset.y(),offset.z()); + cent.rotateX(rotation.x()); + cent.rotateY(rotation.y()); + cent.rotateZ(rotation.z()); + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + norm.rotateX(rotation.x()); + norm.rotateY(rotation.y()); + norm.rotateZ(rotation.z()); + + cyl.baseArc().setCenter(cent); + cyl.highArc().setCenter(cent); + cyl.baseArc().setNormal(norm); + cyl.highArc().setNormal(norm); + + return cyl; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index bbef33af6..ab3646631 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -349,6 +349,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, } if (this.get_Detector()==1) { //BMT Cylindrical3D cyl = geo.getCylinder(this.get_Layer(), this.get_Sector()); + this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_DetectorType()==0) { // C-detectors this.setOx(weightedX1/totEn); @@ -357,21 +358,22 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, this.setCx(weightedXC/totEn); this.setCy(weightedYC/totEn); this.setCz(weightedZC/totEn); - Vector3D C2P1 = new Vector3D(weightedX1/totEn-weightedXC/totEn, - weightedY1/totEn-weightedYC/totEn, - weightedZ1/totEn-weightedZC/totEn).asUnit(); - Vector3D C2P2 = new Vector3D(weightedX2/totEn-weightedXC/totEn, - weightedY2/totEn-weightedYC/totEn, - weightedZ2/totEn-weightedZC/totEn).asUnit(); - double theta = Math.acos(C2P1.dot(C2P2)); +// Vector3D C2P1 = new Vector3D(weightedX1/totEn-weightedXC/totEn, +// weightedY1/totEn-weightedYC/totEn, +// weightedZ1/totEn-weightedZC/totEn).asUnit(); +// Vector3D C2P2 = new Vector3D(weightedX2/totEn-weightedXC/totEn, +// weightedY2/totEn-weightedYC/totEn, +// weightedZ2/totEn-weightedZC/totEn).asUnit(); + + double theta = Math.acos(this.getN(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, this.getCylAxis()) + .dot(this.getN(weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn, this.getCylAxis()))); this.setTheta(theta); - Vector3D s = C2P1.cross(C2P2).asUnit(); + //Vector3D s = C2P1.cross(C2P2).asUnit(); + Vector3D s = this.getCylAxis().direction().asUnit(); Vector3D n = cyl.baseArc().normal(); - Vector3D t = cyl.baseArc().center().vectorTo(cyl.baseArc().point(theta/2)); Vector3D l = s.cross(n).asUnit(); - this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); this.setL(l); this.setS(s); this.setN(n); @@ -386,14 +388,9 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, this.setY2(weightedY2/totEn); this.setZ2(weightedZ2/totEn); - Vector3D l = new Vector3D(weightedX2/totEn-weightedX1/totEn, - weightedY2/totEn-weightedY1/totEn, - weightedZ2/totEn-weightedZ1/totEn).asUnit(); - - - this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); - this.getCylAxis().setOrigin(this.getCylAxis().origin().x(), this.getCylAxis().origin().y(), weightedZ1/totEn); - this.getCylAxis().setEnd(this.getCylAxis().end().x(), this.getCylAxis().end().y(), weightedZ2/totEn); + Vector3D l = this.getCylAxis().direction().asUnit(); + //this.getCylAxis().setOrigin(this.getCylAxis().origin().x(), this.getCylAxis().origin().y(), weightedZ1/totEn); + //this.getCylAxis().setEnd(this.getCylAxis().end().x(), this.getCylAxis().end().y(), weightedZ2/totEn); Vector3D n = this.getN(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, this.getCylAxis()); //Vector3D n = cyl.baseArc().center().vectorTo(new Point3D((weightedX2/totEn+weightedX1/totEn)/2, // (weightedY2/totEn+weightedY1/totEn)/2, @@ -402,10 +399,10 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, Vector3D s = l.cross(n).asUnit(); - this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); this.setL(l); this.setS(s); this.setN(n); + //System.out.println("bmtz"+l.toString()+" "+s.toString()+" "+n.toString()+" \n"+s.cross(l).toString()+" "+s.cross(n).toString()); } } @@ -436,12 +433,9 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, public Vector3D getN(double x, double y, double z, Line3D cln) { - double v = (cln.origin().z()-z)/cln.direction().z(); - double xs = x+v*cln.direction().x(); - double ys = y+v*cln.direction().y(); - - Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). - vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); + Point3D trk = new Point3D(x,y,z); + Point3D Or = cln.distance(new Point3D(x,y,z)).origin(); + Vector3D n = Or.vectorTo(trk).asUnit(); return n; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 9545c2a7c..a0fc7abe6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -367,19 +367,23 @@ public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical. this.MatchTrack2Traj(seed, kf.TrjPoints, SVTGeom, BMTGeom); cand.addAll(seed.get_Crosses()); for(Cluster cl : seed.get_Clusters()) { + + int layer = cl.get_Layer(); - if(cl.get_Detector()==1 && cl.get_DetectorType()==0){ + + if(cl.get_Detector()==1) { + layer = layer + 6; + if(cl.get_DetectorType()==0) { + Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); Line3D cln = BMTGeom.getAxis(cl.get_Layer(), cl.get_Sector()); - double v = (kf.TrjPoints.get(layer).z-cyl.baseArc().center().z())/cln.direction().z(); - double x = cyl.baseArc().center().x()+v*cln.direction().x(); - double y = cyl.baseArc().center().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, kf.TrjPoints.get(layer).z). - vectorTo(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).asUnit(); + cl.setN(cl.getN(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z,cln)); - cl.setL(cl.getS().cross(n).asUnit()); + cl.setL(cl.getS().cross(cl.getN()).asUnit()); + + } } //double x = kf.TrjPoints.get(layer).x; From 242c2eb5464f8f9a2406db8ef476a18605cf6d06 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 29 Jun 2021 13:57:16 -0400 Subject: [PATCH 136/291] version bump --- common-tools/clas-analysis/pom.xml | 14 ++++++------- common-tools/clas-detector/pom.xml | 10 +++++----- common-tools/clas-geometry/pom.xml | 4 ++-- common-tools/clas-io/pom.xml | 6 +++--- common-tools/clas-jcsg/pom.xml | 8 ++++---- common-tools/clas-math/pom.xml | 4 ++-- common-tools/clas-physics/pom.xml | 4 ++-- common-tools/clas-reco/pom.xml | 14 ++++++------- common-tools/clas-tracking/pom.xml | 6 +++--- common-tools/clas-utils/pom.xml | 4 ++-- common-tools/cnuphys/ced/pom.xml | 8 ++++---- common-tools/cnuphys/magfield/pom.xml | 2 +- common-tools/cnuphys/swimmer/pom.xml | 2 +- common-tools/coat-lib/deployDistribution.sh | 2 +- common-tools/coat-lib/pom.xml | 22 ++++++++++----------- common-tools/parent/pom.xml | 2 +- common-tools/pom.xml | 4 ++-- common-tools/swim-tools/pom.xml | 6 +++--- parent/pom.xml | 2 +- pom.xml | 4 ++-- reconstruction/band/pom.xml | 2 +- reconstruction/cnd/pom.xml | 2 +- reconstruction/cvt/pom.xml | 12 +++++------ reconstruction/dc/pom.xml | 12 +++++------ reconstruction/eb/pom.xml | 10 +++++----- reconstruction/ec/pom.xml | 14 ++++++------- reconstruction/ft/pom.xml | 8 ++++---- reconstruction/fvt/pom.xml | 6 +++--- reconstruction/htcc/pom.xml | 8 ++++---- reconstruction/ltcc/pom.xml | 6 +++--- reconstruction/pom.xml | 4 ++-- reconstruction/rich/pom.xml | 8 ++++---- reconstruction/rtpc/pom.xml | 6 +++--- reconstruction/swaps/pom.xml | 12 +++++------ reconstruction/tof/pom.xml | 4 ++-- 35 files changed, 121 insertions(+), 121 deletions(-) diff --git a/common-tools/clas-analysis/pom.xml b/common-tools/clas-analysis/pom.xml index 8d0f5689e..7e175de1d 100644 --- a/common-tools/clas-analysis/pom.xml +++ b/common-tools/clas-analysis/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-analysis - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -30,31 +30,31 @@ org.jlab.clas clas-utils - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-physics - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-io - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-geometry - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-detector - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-detector/pom.xml b/common-tools/clas-detector/pom.xml index 0e61aa7e2..14a226429 100644 --- a/common-tools/clas-detector/pom.xml +++ b/common-tools/clas-detector/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-detector - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -30,7 +30,7 @@ org.jlab.clas clas-utils - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -42,13 +42,13 @@ org.jlab.clas clas-io - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-geometry - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-geometry/pom.xml b/common-tools/clas-geometry/pom.xml index 17bc50ee8..0d1dcc4a9 100644 --- a/common-tools/clas-geometry/pom.xml +++ b/common-tools/clas-geometry/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-geometry - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-io/pom.xml b/common-tools/clas-io/pom.xml index 1cee661fc..89a9cd7ad 100644 --- a/common-tools/clas-io/pom.xml +++ b/common-tools/clas-io/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-io - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -75,7 +75,7 @@ org.jlab.clas clas-utils - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-jcsg/pom.xml b/common-tools/clas-jcsg/pom.xml index 90045cd2c..d647ecbff 100644 --- a/common-tools/clas-jcsg/pom.xml +++ b/common-tools/clas-jcsg/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-jcsg - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -40,12 +40,12 @@ org.jlab.clas clas-geometry - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT org.jlab.clas clas-detector - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT java3d diff --git a/common-tools/clas-math/pom.xml b/common-tools/clas-math/pom.xml index 9490adeba..afda800a2 100644 --- a/common-tools/clas-math/pom.xml +++ b/common-tools/clas-math/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-math - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-physics/pom.xml b/common-tools/clas-physics/pom.xml index 99336706f..2289154e1 100644 --- a/common-tools/clas-physics/pom.xml +++ b/common-tools/clas-physics/pom.xml @@ -4,7 +4,7 @@ org.jlab.clas clas-physics - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar @@ -23,7 +23,7 @@ org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT diff --git a/common-tools/clas-reco/pom.xml b/common-tools/clas-reco/pom.xml index a598300b6..58f80f477 100644 --- a/common-tools/clas-reco/pom.xml +++ b/common-tools/clas-reco/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-reco - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT @@ -67,7 +67,7 @@ org.jlab.clas clas-math - 6.5.12-SNAPSHOT + 6.6.4-SNAPSHOT bottom + double r = this.getRadius(layer); + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + Point3D ref = new Point3D(); + ref.copy(ray.get_refPoint()); + Vector3D u = new Vector3D(); + u.copy(ray.get_dirVec()); + ref.translateXYZ(-offset.x(), -offset.y(), -offset.z()); + ref.rotateZ(-rotation.z()); + ref.rotateY(-rotation.y()); + ref.rotateX(-rotation.x()); + u.rotateZ(-rotation.z()); + u.rotateY(-rotation.y()); + u.rotateX(-rotation.x()); + double delta = Math.sqrt((ref.x()*u.x()+ref.y()*u.y())*(ref.x()*u.x()+ref.y()*u.y()) + -(-r*r+ref.x()*ref.x()+ref.y()*ref.y())*(u.x()*u.x()+u.y()*u.y())); + double l = (-(ref.x()*u.x()+ref.y()*u.y())+delta)/(u.x()*u.x()+u.y()*u.y()); + if((int)Math.signum(ref.y()+l*u.y())!=hemisphere) { + l = (-(ref.x()*u.x()+ref.y()*u.y())-delta)/(u.x()*u.x()+u.y()*u.y()); + } - System.out.println("\n\nZ strip geometry check: phi (radians), begin and end z (mm)"); - System.out.println("\tRegion\tSector\tStrip\tphi\t\t\tBegin Z\t\t\t\tEnd Z"); - System.out.println("\t \t \t \tNew/Old/Comp \t\tNew/Old/Comp \t\t\tNew/Old/Comp"); - for(int i=1; i<=Constants.NREGIONS; i++) { - for(int k=1; k<=Constants.NSECTORS; k++) { - for(int j=1; j<=Constants.getCRZNSTRIPS()[i-1]; j++) { - // phi - double ngeo = Math.atan2(newGeo.getZstrip(i, k, j).origin().y(), newGeo.getZstrip(i, k, j).origin().x()); - if(ngeo<0) ngeo += 2*Math.PI; - double ogeo = oldGeo.CRZStrip_GetPhi(k, newGeo.getLayer(i, BMTType.Z), j)%(2*Math.PI); - String snew = String.format("%.4f", ngeo); - String sold = String.format("%.4f", ogeo); - String scom = String.format("%.4f", ngeo-ogeo); - // begin z - double ngeo1 = newGeo.getZstrip(i, k, j).origin().z(); - double ogeo1 = Constants.getCRCZMIN()[i-1]; - String snew1 = String.format("%.4f", ngeo1); - String sold1 = String.format("%.4f", ogeo1); - String scom1 = String.format("%.4f", ngeo1-ogeo1); - // end z - double ngeo2 = newGeo.getZstrip(i, k, j).end().z(); - double ogeo2 = Constants.getCRCZMAX()[i-1]; - String snew2 = String.format("%.4f", ngeo2); - String sold2 = String.format("%.4f", ogeo2); - String scom2 = String.format("%.4f", ngeo2-ogeo2); - if(j==1 || j==Constants.getCRZNSTRIPS()[i-1]) - System.out.println("\t" + i + "\t" + k + "\t" + j + "\t" + snew + "/" + sold + "/" + scom + "\t" + snew1 + "/" + sold1 + "/" + scom1 + "\t" + snew2 + "/" + sold2 + "/" + scom2); - } - } - } + Point3D cylInt = new Point3D(ref.x()+l*u.x(),ref.y()+l*u.y(),ref.z()+l*u.z()); + cylInt.translateXYZ(offset.x(), offset.y(), offset.z()); + cylInt.rotateZ(rotation.z()); + cylInt.rotateY(rotation.y()); - - System.out.println("\n\n Trajectory -> strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - for(int j=0; j<5; j++) { - double z = Math.random()*(zmax-zmin)+zmin; - //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; - //double z = oldGeo.CRCStrip_GetZ(i, j); - double phi = Math.random()*2*Math.PI; - //double phi = (1.0*j/500.0)*2*Math.PI; - //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nsect = newGeo.getSector(i, phi); - int nstrip = newGeo.getStrip(i,nsect,traj); - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; - System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); - } - } - - - System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - boolean check = true; - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - int nstrips = newGeo.getNStrips(i); - int region = newGeo.getRegion(i); - for(int k=1; k<=Constants.NSECTORS; k++) { - double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; - double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; - for(int j=1; j<=nstrips; j++) { - - double z = Math.random()*(zmax-zmin)+zmin; - if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); - - double phi = Math.random()*(phmax-phmin)+phmin; - if(newGeo.getDetectorType(i)==BMTType.Z) { - phi = oldGeo.CRZStrip_GetPhi(k, i, j); - } - - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nstrip = newGeo.getStrip(i,k,traj); - - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; - if(nstrip!=j) check=false; - if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" - + j + "/" + nstrip + "/" + ostrip + "/" + diff + "\t" + newGeo.getPitch(i, j)); - } - } - } - System.out.println("Check: " + check); - - - System.out.println("\nPlotting acceptance"); - DataGroup acceptance = new DataGroup(3,2); - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - H2F hi_acc = new H2F("hi_acc","Layer "+i, 50, -200, 300, 120, 0, 360); - acceptance.addDataSet(hi_acc, i-1); - for(int j=0; j<5000; j++) { - double z = Math.random()*(zmax-zmin)+zmin; - double phi = Math.random()*2*Math.PI; - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); - if(newGeo.inDetector(i, newGeo.getSector(i, phi), traj)) - hi_acc.fill(z, Math.toDegrees(phi)); - } - } - JFrame frame = new JFrame("FT Reconstruction"); - frame.setSize(1200, 800); - EmbeddedCanvas canvas = new EmbeddedCanvas(); - canvas.draw(acceptance); - frame.add(canvas); - frame.setLocationRelativeTo(null); - frame.setVisible(true); + return cylInt; } - - - //added methods: -// public int isInDetector(int layer, double angle, double jitter) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// int num_detector = 2; -// //double jitter = Math.toRadians(Constants.isInSectorJitter); -// for (int i = 0; i < 3; i++) { -// -// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; -// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; -// angle_i = Constants.getCRCEDGE1()[num_region][i]; -// angle_f = Constants.getCRCEDGE2()[num_region][i]; -// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { -// num_detector = i; -// } -// } -// -// return num_detector; -// } -// public int isInSector(int layer, double angle, double jitter) { -// //double jitter = Math.toRadians(Constants.isInSectorJitter); -// int value = -1; -// int num_det = this.isInDetector(layer, angle, jitter); -// /* if(num_det == 0) -// value = 2; -// if(num_det ==2) -// value = 3; -// if(num_det == 1) -// value = 1; */ -// value = num_det + 1; -// -// return value; -// } - -// /** -// * -// * @param layer the hit layer -// * @param strip the hit strip -// * @return the z position in mm for the C-detectors -// */ -// public double CRCStrip_GetZ(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; -// double zc = Constants.getCRCZMIN()[num_region]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// zc += Constants.getCRCWIDTH()[num_region][group]; -// if (j >= limit) { //test if we change the width -// group++; -// limit += Constants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// zc += Constants.getCRCWIDTH()[num_region][group]/2.; -// return zc; //in mm -// } - -// public double CRCStrip_GetPitch(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// -// if (j >= limit) { //test if we change the width -// group++; -// limit += Constants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// -// return Constants.getCRCWIDTH()[num_region][group]; // -// } -/** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @param strip the strip number (starts at 1) - * @return the angle to localize the center of strip - */ - public double CRZStrip_GetPhi(int sector, int layer, int strip) { - - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" - int num_detector = sector - 1; // index of the detector (0...2) - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - return angle; //in rad - } -// /** -// * -// * @param layer the layer 1...6 -// * @param angle the position angle of the hit in the Z detector -// * @return the Z strip as a function of azimuthal angle -// */ -// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle -// double jitter = Math.toRadians(Constants.isInSectorJitter); -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int num_detector = isInDetector(layer, angle, jitter); -// if (num_detector == -1) { -// return -1; -// } -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// if (num_detector == 1) { -// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; -// if (angle >= 0 && angle <= angle_f) { -// angle += 2 * Math.PI; -// } -// } -// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); -// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); -// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; -// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); -// int strip_num = (int) Math.floor(strip_calc); -// -// int value = strip_num + 1; -// //int value = strip_num; -// -// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { -// value = -1; -// } -// -// return value; -// } - -// public void setLorentzAngle(int layer, int sector) { -// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); -// } -//// // Correct strip position before clustering -//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { -//// -//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); -//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); -//// -//// return this.getZStrip(layer, theLorentzCorrectedAngle); -//// } -// public double LorentzAngleCorr(double phi, int layer) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; -// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); -// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); -// } -// -// /** -// * -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating is the track hit is in the fiducial detector -// */ -// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { -// -// boolean isInFid = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; -// -// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit -// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit -// -// double R_i = 0; // inner radius init -// double R_f = 0; // outer radius init for a C or Z detector -// if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { -// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer -// } -// if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { -// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors -// } -// R_f = R_i + Constants.hDrift; -// -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// double A_i = CRC_GetBeginStrip(sector, layer); -// double A_f = CRC_GetEndStrip(sector, layer); -// angle_i = A_i; -// angle_f = A_f; -// if (A_i > A_f) { // for B-detector -// angle_f = A_i; -// angle_i = A_f; -// } -// // the hit parameters -// double angle = Math.atan2(x[1], x[0]); -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); -// double z = x[2]; -// -// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { -// isInFid = true; -// } -// -// return isInFid; -// } -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the beginning of the strips -// */ -// public double CRC_GetBeginStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the beginning of the strips -// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the end of the strips -// */ -// public double CRC_GetEndStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the end of the strips -// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// /** -// * -// * @param angle -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating if the given angle is the sector -// */ -// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { -// if( layer < 1 || layer > 6 ) { -// System.err.println(" BMT layer has to be 1 <= layer <= 6"); -// return false; -// } -// if( sector < 1 || sector > 3 ) { -// System.err.println(" BMT sector has to be 1 <= layer <= 3"); -// return false; -// } -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; -// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; -// -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// -// if( sector == 3 ) { -// if( angle < Math.PI ) { -// if( angle < angle_f + jitter ) return true; -// else return false; -// } -// else { -// if( angle > angle_i - jitter ) return true; -// else return false; -// } -// } -// else { -// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) -// return true; -// else -// return false; -// -// } -// } - -// /** -// * -// * @param layer -// * @param trk_z the track z position of intersection with the C-detector -// * @return the C-strip -// */ -// public int getCStrip(int layer, double trk_z) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int strip_group = 0; -// int ClosestStrip = -1; -// // get group -// int len = Constants.getCRCGROUP()[num_region].length; -// double[] Z_lowBound = new double[len]; -// double[] Z_uppBound = new double[len]; -// int[] NStrips = new int[len]; -// -// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; -// double z = trk_z - zi; -// -// for (int i = 0; i < len; i++) { -// if(i==0) { -// Z_lowBound[i] = 0; -// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; -// } -// else { -// Z_lowBound[i] = Z_uppBound[i - 1]; -// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; -// } -// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; -// -// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { -// strip_group = i; -// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); -// if(i>0) ClosestStrip += NStrips[i - 1]; -// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; -// -// len = i; -// } -// } -// return ClosestStrip; -// } -// -// public boolean isInFiducial(double x, double y, double z, int layer) { -// -// boolean isOK = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; -// -// int axis = Geometry.getZorC(layer); -// -// double R = 0; -// if (axis == 0) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; -// } -// if (axis == 1) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; -// } -// -// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; -// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; -// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; -// -// double z_min = CRZZMIN + CRZOFFSET; -// double z_max = z_min + CRZLENGTH; -// -// double epsilon = 1e-1; -// -// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { -// isOK = true; -// } -// return isOK; -// } -// -// /** -// * -// * @param layer the layer 1...6 -// * @return the Z position of the strip center -// */ -// private double CRZ_GetZStrip(int layer) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //For CRZ, this function returns the Z position of the strip center -// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; -// return zc; //in mm -// } - - - public void putInFrame(Point3D cent, Point3D offset, Vector3D rotation) { - cent.rotateX(rotation.x()); - cent.rotateY(rotation.y()); - cent.rotateZ(rotation.z()); - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 4e0f41c76..a3dedcaaa 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -295,18 +295,20 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); + for (int row = 0; row=1 && region<=3) { + if( detector == BMTType.Z ) { + layer = lZ[ region - 1 ]; + } + else if( detector == BMTType.C ) { + layer = lC[ region - 1 ]; + } + } + else System.out.println("ERROR: out of range region number in getLayer(int region, BMTType detector)"); return layer; } - + /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @param strip the strip number (starts at 1) - * @return the angle to localize the center of strip + * Return region number for a given layer + * @param layer (1-6) + * @return region (1-3) */ - public double CRZStrip_GetPhi(int sector, int layer, int strip) { - - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) + public int getRegion(int layer) { + int region = -1; + if(layer>=1 && layer<=6) { + region = (int) Math.floor((layer+1)/2); + } + else System.out.println("ERROR: out of range layer number in getRegion(int layer)"); + return region; + } - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(Constants.getCRZXPOS()[num_region]+(Constants.getCRZWIDTH()[num_region]/2.+num_strip*(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region])))/Constants.getCRZRADIUS()[num_region]; - //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(0.5+num_strip)*Constants.getCRZWIDTH()[num_region]/Constants.getCRZRADIUS()[num_region]; - //double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - return angle; //in rad + /** + * Return region number for a given layer + * @param layer (1-6) + * @return type ("C" or "Z"); + */ + public static BMTType getDetectorType(int layer) { + if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; + else if(layer == lZ[0] || layer == lZ[1] || layer == lZ[2]) return BMTType.Z; + else { + System.out.println("ERROR: out of range layer number in getDetectorType(int layer)"); + return null; + } } - + /** - * - * @param layer the layer 1...6 - * @param angle the position angle of the hit in the Z detector - * @return the Z strip as a function of azimuthal angle + * Return radius of the selected layer + * @param layer (1-6) + * @return radius (=0 if layer is out of range) */ - public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle - double jitter = Math.toRadians(Constants.isInSectorJitter); - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int num_detector = isInDetector(layer, angle, jitter); - if (num_detector == -1) { - return -1; + public double getRadius(int layer) { + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + double radius = 0; + if(region>0 && det!=null) { + if (det == BMTType.C) radius = Constants.getCRCRADIUS()[region-1]; + else if(det == BMTType.Z) radius = Constants.getCRZRADIUS()[region-1]; } - - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi + else System.out.println("ERROR: out of range layer number in getRadius(int layer)"); + return radius; + } + + /** + * Return number of strips of the selected layer + * @param layer (1-6) + * @return nstrips (=0 if layer is out of range) + */ + public int getNStrips(int layer) { + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + int nstrips = 0; + if(region>0 && det!=null) { + if (det == BMTType.C) nstrips = Constants.getCRCNSTRIPS()[region-1]; + else if(det == BMTType.Z) nstrips = Constants.getCRZNSTRIPS()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getNStrips(int layer)"); + return nstrips; + } + + /** + * Return pitch for the selected layer and strip + * @param layer (1-6) + * @param strip + * @return pitch (=0 if layer is out of range) + */ + public double getPitch(int layer, int strip) { + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + double pitch = 0; + if(region>0 && det!=null) { + if (det == BMTType.C) pitch = this.getCPitch(region, strip); + else if(det == BMTType.Z) pitch = this.getZPitch(region, strip); } - if (num_detector == 1) { - double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; - if (angle >= 0 && angle <= angle_f) { - angle += 2 * Math.PI; + else System.out.println("ERROR: out of range layer number in getNStrips(int layer)"); + return pitch; + } + + /** + * Return pitch for C strips + * @param region (1-3) + * @param strip + * @return pitch (0 if region or strip are out of range + */ + public double getCPitch(int region, int strip) { + double pitch=0; + + if(region>=1 && region<=3) { + if(strip>0 && strip<=Constants.getCRCNSTRIPS()[region-1]) { + int group = this.getCGroup(region, strip); + pitch = Constants.getCRCWIDTH()[region-1][group-1]; } + else System.out.println("ERROR: out of range strip number in getZPitch(int region, int strip)"); } - //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); - //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); - double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; - strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); - int strip_num = (int) Math.floor(strip_calc); - - int value = strip_num + 1; - //int value = strip_num; - - if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { - value = -1; + else System.out.println("ERROR: out of range region number in getZPitch(int region, int strip)"); + return pitch; + } + + /** + * Return pitch for Z strips + * @param region (1-3) + * @param strip + * @return pitch (0 if region or strip are out of range + */ + public double getZPitch(int region, int strip) { + double pitch=0; + + if(region>=1 && region<=3) { + if(strip>0 && strip<=Constants.getCRZNSTRIPS()[region-1]) { + pitch = Constants.getCRZWIDTH()[region-1]; + } + else System.out.println("ERROR: out of range strip number in getZPitch(int region, int strip)"); } - - return value; + else System.out.println("ERROR: out of range region number in getZPitch(int region, int strip)"); + return pitch; } - + /** - * - * @param layer the layer 1...6 - * @return the Z position of the strip center + * Return minimum z of the selected layer in the local frame + * @param layer (1-6) + * @return z (=udf if layer is out of range) */ - private double CRZ_GetZStrip(int layer) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //For CRZ, this function returns the Z position of the strip center - double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; - return zc; //in mm + public double getZmin(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && det!=null) { + if (det == BMTType.C) z = Constants.getCRCZMIN()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMIN()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getZmin(int layer)"); + return z; } - + /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the beginning of the strips + * Return maximum z of the selected layer in the local frame + * @param layer (1-6) + * @return z (=udf if layer is out of range) */ - public double CRC_GetBeginStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the beginning of the strips - double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; + public double getZmax(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && det!=null) { + if (det == BMTType.C) z = Constants.getCRCZMAX()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMAX()[region-1]; } - return angle; //in rad + else System.out.println("ERROR: out of range layer number in getZmax(int layer)"); + return z; } - + /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the end of the strips + * Return tile phi center + * @param layer (1-6) + * @param sector (1-3) + * @return phi (=udf if layer is out of range) */ - public double CRC_GetEndStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the end of the strips - double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; + public double getPhi(int layer, int sector) { + + double phi = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && sector>0 && det!=null) { + if (det == BMTType.C) phi = Constants.getCRCPHI()[region-1][sector-1]; + else if(det == BMTType.Z) phi = Constants.getCRZPHI()[region-1][sector-1]; } - return angle; //in rad + else System.out.println("ERROR: out of range inputs in getPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); + return phi; } - + /** - * - * @param layer the hit layer - * @param strip the hit strip - * @return the z position in mm for the C-detectors + * Return half tile phi coverage + * @param layer (1-6) + * @param sector (1-3) + * @return dz (=udf if layer is out of range) */ - public double CRCStrip_GetZ(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center - int group = 0; - int limit = Constants.getCRCGROUP()[num_region][group]; - double zc = Constants.getCRCZMIN()[num_region]; - - if (num_strip > 0) { - for (int j = 1; j < num_strip + 1; j++) { - zc += Constants.getCRCWIDTH()[num_region][group]; - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } - } + public double getDPhi(int layer, int sector) { + + double dphi = udf; + + int region = this.getRegion(layer); + BMTType det = this.getDetectorType(layer); + + if(region>0 && sector>0 && det!=null) { + if (det == BMTType.C) dphi = Constants.getCRCDPHI()[region-1][sector-1]; + else if(det == BMTType.Z) dphi = Constants.getCRZDPHI()[region-1][sector-1]; } - zc += Constants.getCRCWIDTH()[num_region][group]/2.; - return zc; //in mm + else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); + + return dphi; } - - public double CRCStrip_GetPitch(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center + + /** + * Return thickness of the drift gap + * @return thickness + */ + public double getThickness() { + + return Constants.hDrift; + } + + /** + * Return offset of the selected tile, identified by layer and sector + * @param layer (1-6) + * @param sector (1-3) + * @return Point3D offset: 3D offset + */ + public Point3D getOffset(int layer, int sector) { + Point3D offset = new Point3D(); + if(layer>0 && layer 0 && sector0 && layer 0 && sector0 && layer 0 && sector0 && layer0 && layer 0) { - for (int j = 1; j < num_strip + 1; j++) { - - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } + if(strip>0 && strip<=Constants.getCRCNSTRIPS()[region-1]) { + for(int i=0; i= Z_lowBound[i] && z <= Z_uppBound[i]) { - strip_group = i; - ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); - if(i>0) ClosestStrip += NStrips[i - 1]; - //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; - - len = i; + private int getCGroup(int region, double z) { + int group = 0; + if(z>Constants.getCRCZMIN()[region-1] && zConstants.getCRCGRPZMIN()[region-1][i] && z0) { + double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; // group minimum z + double pitch = Constants.getCRCWIDTH()[region-1][group-1]; // group pitch + int nmin = Constants.getCRCGRPNMIN()[region-1][group-1]; + z = zmin + (strip - nmin + 0.5) * pitch ; + } + return z; } /** - * - * @param layer - * @param x x-coordinate of the hit in the lab frame - * @param y y-coordinate of the hit in the lab frame - * @return the sigma along in the azimuth direction taking the Lorentz angle - * into account + * Returns Arc3D corresponding to the selected C-detector strip according to ideal geometry (local frame) + * @param region (1-3) + * @param sector (1-3) + * @param strip + * @return Arc3D striparc */ - public double getSigmaAzimuth(int layer, double x, double y) { // sigma for Z-detectors - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; - double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift / Math.cos(Constants.getThetaL())); - - return sigma; - + private Arc3D getIdealCstrip(int region, int sector, int strip) { + + double radius = Constants.getCRCRADIUS()[region-1]; + double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; + double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; + double z = this.getCstripZ(region, strip); + + Point3D origin = new Point3D(radius,0,z); + origin.rotateZ(angle); + Vector3D normal = new Vector3D(0,1,0); + normal.rotateZ(angle); + Point3D center = new Point3D(0,0,z); + + Arc3D striparc = new Arc3D(origin,center,normal,theta); + return striparc; } + + /** + * Returns Arc3D corresponding to the selected C-detector strip according to real geometry + * @param region + * @param sector + * @param strip + * @return + */ + public Arc3D getCstrip(int region, int sector, int strip) { + int layer = this.getLayer(region, BMTType.C); + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + + double radius = Constants.getCRCRADIUS()[region-1]; + double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; + double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; + double z = this.getCstripZ(region, strip); + + Point3D origin = new Point3D(radius,0,z); + origin.rotateZ(angle); + Vector3D normal = new Vector3D(0,1,0); + normal.rotateZ(angle); + Point3D center = new Point3D(0,0,z); + Arc3D striparc = new Arc3D(origin,center,normal,theta); + this.alignArc(offset, rotation, striparc); + return striparc; + } + + public void alignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { + Point3D origin = arcline.origin(); + Vector3D normal = arcline.normal(); + Point3D center = arcline.center(); + origin.rotateX(rotation.x()); + origin.rotateY(rotation.y()); + origin.rotateZ(rotation.z()); + origin.translateXYZ(offset.x(),offset.y(),offset.z()); + center.rotateX(rotation.x()); + center.rotateY(rotation.y()); + center.rotateZ(rotation.z()); + center.translateXYZ(offset.x(),offset.y(),offset.z()); + normal.rotateX(rotation.x()); + normal.rotateY(rotation.y()); + normal.rotateZ(rotation.z()); + } + + public void antiAlignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { + Point3D origin = arcline.origin(); + Vector3D normal = arcline.normal(); + Point3D center = arcline.center(); + origin.translateXYZ(offset.x(),offset.y(),offset.z()); + origin.rotateZ(rotation.z()); + origin.rotateY(rotation.y()); + origin.rotateX(rotation.x()); + center.translateXYZ(offset.x(),offset.y(),offset.z()); + center.rotateZ(rotation.z()); + center.rotateY(rotation.y()); + center.rotateX(rotation.x()); + normal.rotateZ(rotation.z()); + normal.rotateY(rotation.y()); + normal.rotateX(rotation.x()); + } + + /** - * + * * @param layer - * @param x x-coordinate of the hit in the lab frame - * @param y y-coordinate of the hit in the lab frame - * @param z z-coordinate of the hit in the lab frame - * @return X[] = the smeared position x = X[0], y = X[1], z = X[2] taking - * the Lorentz angle into account - */ - /* - public double[] smearedPosition(int layer, double x, double y, double z) { - - double[] newPos = new double[3]; - Random rand = new Random(); - - int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; - - double sigma =0; - if(layer%2==0) if(Double.isNaN(z)) {// C layer - sigma = getSigmaLongit(layer, x, y); // longitudinal shower profile - // changes z - z = this.randomGaus(z, sigma, rand); - } - - if(layer%2==1) {// Z layer - sigma = getSigmaAzimuth(layer, x, y); // azimuth shower profile taking into account the Lorentz angle - // changes phi - double phicorr = (this.randomGaus(0, sigma, rand)/Math.cos(Constants.getThetaL()) - -(Math.sqrt(x*x+y*y)-Constants.getCRZRADIUS()[num_region]+ - Constants.hStrip2Det)*Math.tan(Constants.getThetaL()))/Constants.getCRZRADIUS()[num_region]; - double phi = Math.atan2(y, x); - phi+=phicorr; - - x = Math.sqrt(x*x+y*y)*Math.cos(phi); - y = Math.sqrt(x*x+y*y)*Math.sin(phi); - } - newPos[0] = x; - newPos[1] = y; - newPos[2] = z; - - return newPos; - } - */ - private double randomGaus(double mean, double width, Random aRandom) { - if (width <= 0) { - return 0; + * @param sector + * @return rotated cylinder corresponding to the BMT surface + */ + public Cylindrical3D getCylinder(int layer, int sector) { + Cylindrical3D cyl = new Cylindrical3D(); + + Point3D cent = new Point3D(0, 0, 0); + Vector3D norm = new Vector3D(0,1,0); + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + cent.rotateX(rotation.x()); + cent.rotateY(rotation.y()); + cent.rotateZ(rotation.z()); + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + norm.rotateX(rotation.x()); + norm.rotateY(rotation.y()); + norm.rotateZ(rotation.z()); + + cyl.baseArc().setCenter(cent); + cyl.highArc().setCenter(cent); + cyl.baseArc().setNormal(norm); + cyl.highArc().setNormal(norm); + + + + return cyl; + } + /** + * Return the sector number + * @param layer [0-6] + * @param angle angle in the local frame in radians + * @return sector [1-3] (not) accounting for dead areas if layer (0) [1-6] or 0 if layer is undefined + */ + public int getSector(int layer, double angle) { + boolean full = false; + if(layer==0) { + full = true; + layer = 1; } - - double smear = width * aRandom.nextGaussian(); - double randomNumber = mean + smear; - - return randomNumber; + int region = this.getRegion(layer); + + Vector3D vec = new Vector3D(Math.cos(angle),Math.sin(angle),0); + if(Double.isNaN(angle)) vec = null; + int sector = 0; + double width = 0.5; // Math.cos(60deg); + double delta = -1; + for (int i = 0; i < Constants.NSECTORS; i++) { + double phi = this.getPhi(layer, i+1); + Vector3D center = new Vector3D(Math.cos(phi),Math.sin(phi),0); + double dcosphi = center.dot(vec); + if(dcosphi>width) { + delta = dcosphi; + sector = i+1; + } + } + if(!full) { + if(sector!=0) + if(delta0 && layer<=Constants.NLAYERS && sector>0 && sector<=Constants.NSECTORS) { + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); + traj.rotateZ(-rotation.z()); + traj.rotateY(-rotation.y()); + traj.rotateX(-rotation.x()); + if(traj.z()>this.getZmin(layer) && traj.z()Math.cos(this.getDPhi(layer, sector))) in=true; + } + } + return in; + } - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; + /** + * Checks whether a trajectory point is within the active area of a tile + * @param traj + * @return true/false + */ + public int getStrip(Point3D traj, double strip2Det) { + int strip = 0; + int layer = getLayer(traj, strip2Det); + int sector = getSector(layer,Math.atan2(traj.y(), traj.x())); + if(layer>0 && sector>0) strip = getStrip(layer,sector,traj); + return strip; + } - double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit - double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit - double R_i = 0; // inner radius init - double R_f = 0; // outer radius init for a C or Z detector - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 1) { - R_i = Constants.getCRZRADIUS()[num_region]; // Z layer + /** + * Return the number of the closest strip to the given trajectory point + * Detector mis-alignments geometry are taken into account by transforming + * the trajectory point to detector local frame + * @param layer (1-6) + * @param sector (1-3) + * @param traj trajectory point on the layer surface in the lab + * @return strip number (0 if the point is not within the active area) + */ + public int getStrip(int layer, int sector, Point3D traj) { + int strip= 0; + if(layer>0 && layer<=Constants.NLAYERS && sector>0 && sector<=Constants.NSECTORS) { + Point3D offset = this.getOffset(layer, sector); + Vector3D rotation = this.getRotation(layer, sector); + traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); + traj.rotateZ(-rotation.z()); + traj.rotateY(-rotation.y()); + traj.rotateX(-rotation.x()); + strip = this.getStripLocal(layer, traj); } - if (org.jlab.rec.cvt.bmt.Geometry.getZorC(layer) == 0) { - R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors + return strip; + } + + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param layer (1-6) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + private int getStripLocal(int layer, Point3D traj) { + + BMTType type = this.getDetectorType(layer); + int region = this.getRegion(layer); + switch (type) { + case C: + return this.getCstrip(region,traj); + case Z: + return this.getZstrip(region,traj); + default: + return 0; } - R_f = R_i + Constants.hDrift; - - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - double A_i = CRC_GetBeginStrip(sector, layer); - double A_f = CRC_GetEndStrip(sector, layer); - angle_i = A_i; - angle_f = A_f; - if (A_i > A_f) { // for B-detector - angle_f = A_i; - angle_i = A_f; - } - // the hit parameters - double angle = Math.atan2(x[1], x[0]); - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); - double z = x[2]; + } - if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { - isInFid = true; + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param region (1-3) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + public int getCstrip(int region, Point3D traj) { + + int strip = 0; + + int group = getCGroup(region, traj.z()); + if(group>0) { + double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; + double pitch = Constants.getCRCWIDTH()[region-1][group-1]; + strip = (int) Math.floor((traj.z()-zmin)/pitch); + if(group>0) strip += Constants.getCRCGRPNMIN()[region-1][group-1]; } - - return isInFid; + return strip; } - - // in A (index 0), B (index 1), in C (index 2) - public int isInDetector(int layer, double angle, double jitter) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - int num_detector = 2; - //double jitter = Math.toRadians(Constants.isInSectorJitter); - for (int i = 0; i < 3; i++) { - - //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; - //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; - angle_i = Constants.getCRCEDGE1()[num_region][i]; - angle_f = Constants.getCRCEDGE2()[num_region][i]; - if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { - num_detector = i; + + /** + * Return the number of the closest strip to the given trajectory point + * in the detector local frame + * @param region (1-3) + * @param traj trajectory point on the layer surface in the local frame + * @return strip number (0 if the point is not within the active area) + */ + public int getZstrip(int region, Point3D traj) { + + int strip = 0; + + int layer = getLayer(region, BMTType.Z); + + double angle = Math.atan2(traj.y(), traj.x()); + if(angle<0) angle += 2*Math.PI; + + int sector = getSector(layer,angle); + if(sector>=1 && sector <=Constants.NSECTORS) { + // CHECKME + double edge = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1]; // 30 150 270 + double pitch = Constants.getCRZWIDTH()[region-1]; + double radius = Constants.getCRZRADIUS()[region-1]; + double dphi = angle - edge; + if(dphi<0) dphi += 2*Math.PI; + strip = (int) Math.floor(dphi*radius/pitch) + 1; +// System.out.println(Math.toDegrees(angle) + " " + Math.toDegrees(dphi) + " " + sector + " " + strip_calc); + if (strip < 1 || strip > Constants.getCRZNSTRIPS()[region-1]) { + strip = -1; } } - - return num_detector; - } - - public int isInSector(int layer, double angle, double jitter) { - //double jitter = Math.toRadians(Constants.isInSectorJitter); - int value = -1; - int num_det = this.isInDetector(layer, angle, jitter); - /* if(num_det == 0) - value = 2; - if(num_det ==2) - value = 3; - if(num_det == 1) - value = 1; */ - value = num_det + 1; + return strip; - return value; } - + /** - * - * @param angle - * @param sector - * @param layer - * @param x - * @return a boolean indicating if the given angle is the sector - */ - public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { - if( layer < 1 || layer > 6 ) { - System.err.println(" BMT layer has to be 1 <= layer <= 6"); - return false; - } - if( sector < 1 || sector > 3 ) { - System.err.println(" BMT sector has to be 1 <= layer <= 3"); - return false; - } - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; - angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; + * Calculate Theta Lorentz based on solenoid scale and drift settings + * @param layer + * @param sector + * @return thetaL in radians + */ + public double getThetaLorentz(int layer, int sector) { + + double thetaL = 0; + + double solenoidScale = org.jlab.rec.cvt.Constants.getSolenoidscale(); + if(Math.abs(solenoidScale)<0.001) { + thetaL = 0; + } + else { + if(Math.abs(solenoidScale)<0.8) { + thetaL = Math.toRadians(getLorentzAngle(E_DRIFT_MF[layer-1][sector-1],Math.abs(solenoidScale*50))); + } else { + thetaL = Math.toRadians(getLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(solenoidScale*50))); + } + } + if (solenoidScale<0) thetaL=-thetaL; + return thetaL; + } - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi + /** + * Calculate Theta Lorentz based on solenoid scale and drift settings + * @param layer + * @param sector + * @return thetaL in radians + */ + public double getThetaLorentz(int layer, int sector, double x, double y, double z, Swim swim) { + + double thetaL = 0; + float[] b = new float[3]; + swim.BfieldLab(x/10, y/10, z/10, b); + double EDrift=0; + if(Constants.isMC == true) { + EDrift = 5000*Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()); + } else { + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { + EDrift = Constants.E_DRIFT_MF[layer-1][sector-1]; + } else { + EDrift = Constants.E_DRIFT_FF[layer-1][sector-1]; + } } - - if( sector == 3 ) { - if( angle < Math.PI ) { - if( angle < angle_f + jitter ) return true; - else return false; - } - else { - if( angle > angle_i - jitter ) return true; - else return false; - } + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001) { + thetaL = 0; } else { - if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) - return true; - else - return false; - + thetaL = Math.toRadians(getLorentzAngle(EDrift,Math.abs(b[2]*10))); } + if (org.jlab.rec.cvt.Constants.getSolenoidscale()<0) thetaL=-thetaL; + return thetaL; } - public double LorentzAngleCorr(double phi, int layer) { - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; - //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - } - public void SetLorentzAngle(int layer, int sector) { - org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); - } - // Correct strip position before clustering - public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { - - double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); - double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); - - return this.getZStrip(layer, theLorentzCorrectedAngle); + /** + * Calculate Lorentz angle correction + * @param layer + * @param sector + * @return + */ + public double LorentzAngleCorr(int layer, int sector) { + return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); } - public static void main(String arg[]) { - - Constants.Load(); - Geometry geo = new Geometry(); - - double trk_z = 0; - int layer = 5; - System.out.println(geo.CRCStrip_GetZ(6, 267) + " strip " + geo.getCStrip(6, -65.)); - /* - int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int strip_group = 0; - int ClosestStrip =-1; - System.out.println((""+1*1+""+1*0+"")); - // get group - int len = Constants.CRCGROUP[num_region].length; - double[] Z_lowBound = new double[len]; - double[] Z_uppBound = new double[len]; - int[] NStrips = new int[len]; - - double zi= Constants.CRCZMIN[num_region]+Constants.CRCOFFSET[num_region]; - double z = trk_z - zi; - - Z_lowBound[0] = Constants.CRCWIDTH[num_region][0]/2.; // the lower bound is the zMin+theOffset with half the width - Z_uppBound[0] = Z_lowBound[0] - + (Constants.CRCGROUP[num_region][0]-1)*(Constants.CRCWIDTH[num_region][0]+ Constants.CRCSPACING[num_region]); - NStrips[0] = Constants.CRCGROUP[num_region][0]; - for(int i =1; i< len; i++) - { - Z_lowBound[i] = Z_uppBound[i-1] + Constants.CRCWIDTH[num_region][i-1]/2. + Constants.CRCSPACING[num_region] + Constants.CRCWIDTH[num_region][i]/2.; - Z_uppBound[i] = Z_lowBound[i] + (Constants.CRCGROUP[num_region][i]-1)*(Constants.CRCWIDTH[num_region][i] + Constants.CRCSPACING[num_region]); - - NStrips[i] = NStrips[i-1] + Constants.CRCGROUP[num_region][i]; - - if(z>=Z_lowBound[i] && z<=Z_uppBound[i]) { - strip_group = i; - ClosestStrip = 1 + (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.CRCWIDTH[num_region][strip_group] + Constants.CRCSPACING[num_region]))))+NStrips[i-1]; - - len =i; - } - } - double[] X = geo.smearedPosition(5, 0 , Constants.CRZRADIUS[2] , 0); - System.out.println(0+", "+(0.3+Constants.CRZRADIUS[2])+" , "+0+" smeared "+X[0]+", "+X[1]+" , "+X[2]); - System.out.println(geo.getZStrip(5, Math.atan2(Constants.CRZRADIUS[2],0 ))); - System.out.println(geo.getZStrip(5, Math.atan2(X[1],X[0]))); - System.out.println(Math.toDegrees( geo.CRZStrip_GetPhi(1,6, geo.getZStrip(5, Math.atan2(X[1],X[0]))) )); - int theMeasuredZStrip = geo.getZStrip(5, Math.atan2(X[1],X[0])); // start reco - double theMeasuredPhi = geo.CRZStrip_GetPhi(1,6,theMeasuredZStrip); - double theLorentzCorrectedAngle = geo.LorentzAngleCorr( theMeasuredPhi, 6); - System.out.println(" corrected phi = "+Math.toDegrees(theLorentzCorrectedAngle)); - int theLorentzCorrectedStrip = geo.getZStrip(5, theLorentzCorrectedAngle); - System.out.println(theMeasuredZStrip+" "+theLorentzCorrectedStrip); */ - /* - double phiC = geo.CRZStrip_GetPhi(3,6,216); - double x = Constants.CRCRADIUS[2]*Math.cos(phiC); - double y = Constants.CRCRADIUS[2]*Math.sin(phiC); - int theMeasuredCStrip = geo.getCStrip(6,X[2]); - double z = geo.CRCStrip_GetZ(6,309); - System.out.println(x+", "+y+", "+z);*/ - //List Hits = geo.GEMCBMTHits(layer, sector, -199.89230321711165 , 93.78543124898611 , -164.52000000000007, .1); - //System.out.println("There are "+Hits.size()+" hits in this cluster"); - //for(int i =0; i strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + for(int j=0; j<5; j++) { + double z = Math.random()*(zmax-zmin)+zmin; + //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; + //double z = oldGeo.CRCStrip_GetZ(i, j); + double phi = Math.random()*2*Math.PI; + //double phi = (1.0*j/500.0)*2*Math.PI; + //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nsect = newGeo.getSector(i, phi); + int nstrip = newGeo.getStrip(i,nsect,traj); + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(i, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; + System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); + } } - - double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; - double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; - double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; - - double z_min = CRZZMIN + CRZOFFSET; - double z_max = z_min + CRZLENGTH; - - double epsilon = 1e-1; - - if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { - isOK = true; + + + System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + boolean check = true; + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + int nstrips = newGeo.getNStrips(i); + int region = newGeo.getRegion(i); + for(int k=1; k<=Constants.NSECTORS; k++) { + double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; + double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; + for(int j=1; j<=nstrips; j++) { + + double z = Math.random()*(zmax-zmin)+zmin; + if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); + + double phi = Math.random()*(phmax-phmin)+phmin; + if(newGeo.getDetectorType(i)==BMTType.Z) { + phi = oldGeo.CRZStrip_GetPhi(k, i, j); + } + + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nstrip = newGeo.getStrip(i,k,traj); + + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(i, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; + if(nstrip!=j) check=false; + if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" + + j + "/" + nstrip + "/" + ostrip + "/" + diff + "\t" + newGeo.getPitch(i, j)); + } + } + } + System.out.println("Check: " + check); + + + System.out.println("\nPlotting acceptance"); + DataGroup acceptance = new DataGroup(3,2); + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + H2F hi_acc = new H2F("hi_acc","Layer "+i, 50, -200, 300, 120, 0, 360); + acceptance.addDataSet(hi_acc, i-1); + for(int j=0; j<5000; j++) { + double z = Math.random()*(zmax-zmin)+zmin; + double phi = Math.random()*2*Math.PI; + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); + if(newGeo.inDetector(i, newGeo.getSector(i, phi), traj)) + hi_acc.fill(z, Math.toDegrees(phi)); + } } - return isOK; + JFrame frame = new JFrame("FT Reconstruction"); + frame.setSize(1200, 800); + EmbeddedCanvas canvas = new EmbeddedCanvas(); + canvas.draw(acceptance); + frame.add(canvas); + frame.setLocationRelativeTo(null); + frame.setVisible(true); } + + + + //added methods: +// public int isInDetector(int layer, double angle, double jitter) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// int num_detector = 2; +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// for (int i = 0; i < 3; i++) { +// +// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; +// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; +// angle_i = Constants.getCRCEDGE1()[num_region][i]; +// angle_f = Constants.getCRCEDGE2()[num_region][i]; +// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { +// num_detector = i; +// } +// } +// +// return num_detector; +// } +// public int isInSector(int layer, double angle, double jitter) { +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// int value = -1; +// int num_det = this.isInDetector(layer, angle, jitter); +// /* if(num_det == 0) +// value = 2; +// if(num_det ==2) +// value = 3; +// if(num_det == 1) +// value = 1; */ +// value = num_det + 1; +// +// return value; +// } + +// /** +// * +// * @param layer the hit layer +// * @param strip the hit strip +// * @return the z position in mm for the C-detectors +// */ +// public double CRCStrip_GetZ(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// double zc = Constants.getCRCZMIN()[num_region]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// zc += Constants.getCRCWIDTH()[num_region][group]; +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// zc += Constants.getCRCWIDTH()[num_region][group]/2.; +// return zc; //in mm +// } + +// public double CRCStrip_GetPitch(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// +// return Constants.getCRCWIDTH()[num_region][group]; // +// } +/** + * + * @param sector the sector in CLAS12 1...3 + * @param layer the layer 1...6 + * @param strip the strip number (starts at 1) + * @return the angle to localize the center of strip + */ + public double CRZStrip_GetPhi(int sector, int layer, int strip) { - public static final synchronized int getZorC(int layer) { - int axis = 0; - if (layer == 2 || layer == 3 || layer == 5) { - axis = 1; + // Sector = num_detector + 1; + // num_detector = 0 (region A), 1 (region B), 2, (region C) + //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" + int num_detector = sector - 1; // index of the detector (0...2) + + int num_strip = strip - 1; // index of the strip (starts at 0) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; + return angle; //in rad + } +// /** +// * +// * @param layer the layer 1...6 +// * @param angle the position angle of the hit in the Z detector +// * @return the Z strip as a function of azimuthal angle +// */ +// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle +// double jitter = Math.toRadians(Constants.isInSectorJitter); +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int num_detector = isInDetector(layer, angle, jitter); +// if (num_detector == -1) { +// return -1; +// } +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// if (num_detector == 1) { +// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; +// if (angle >= 0 && angle <= angle_f) { +// angle += 2 * Math.PI; +// } +// } +// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); +// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); +// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; +// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); +// int strip_num = (int) Math.floor(strip_calc); +// +// int value = strip_num + 1; +// //int value = strip_num; +// +// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { +// value = -1; +// } +// +// return value; +// } + +// public void setLorentzAngle(int layer, int sector) { +// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); +// } +//// // Correct strip position before clustering +//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { +//// +//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); +//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); +//// +//// return this.getZStrip(layer, theLorentzCorrectedAngle); +//// } +// public double LorentzAngleCorr(double phi, int layer) { +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; +// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// } +// +// /** +// * +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating is the track hit is in the fiducial detector +// */ +// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { +// +// boolean isInFid = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; +// +// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit +// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit +// +// double R_i = 0; // inner radius init +// double R_f = 0; // outer radius init for a C or Z detector +// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { +// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer +// } +// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { +// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors +// } +// R_f = R_i + Constants.hDrift; +// +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// double A_i = CRC_GetBeginStrip(sector, layer); +// double A_f = CRC_GetEndStrip(sector, layer); +// angle_i = A_i; +// angle_f = A_f; +// if (A_i > A_f) { // for B-detector +// angle_f = A_i; +// angle_i = A_f; +// } +// // the hit parameters +// double angle = Math.atan2(x[1], x[0]); +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); +// double z = x[2]; +// +// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { +// isInFid = true; +// } +// +// return isInFid; +// } +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the beginning of the strips +// */ +// public double CRC_GetBeginStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the beginning of the strips +// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the end of the strips +// */ +// public double CRC_GetEndStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the end of the strips +// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// /** +// * +// * @param angle +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating if the given angle is the sector +// */ +// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { +// if( layer < 1 || layer > 6 ) { +// System.err.println(" BMT layer has to be 1 <= layer <= 6"); +// return false; +// } +// if( sector < 1 || sector > 3 ) { +// System.err.println(" BMT sector has to be 1 <= layer <= 3"); +// return false; +// } +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; +// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; +// +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// +// if( sector == 3 ) { +// if( angle < Math.PI ) { +// if( angle < angle_f + jitter ) return true; +// else return false; +// } +// else { +// if( angle > angle_i - jitter ) return true; +// else return false; +// } +// } +// else { +// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) +// return true; +// else +// return false; +// +// } +// } + +// /** +// * +// * @param layer +// * @param trk_z the track z position of intersection with the C-detector +// * @return the C-strip +// */ +// public int getCStrip(int layer, double trk_z) { +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int strip_group = 0; +// int ClosestStrip = -1; +// // get group +// int len = Constants.getCRCGROUP()[num_region].length; +// double[] Z_lowBound = new double[len]; +// double[] Z_uppBound = new double[len]; +// int[] NStrips = new int[len]; +// +// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; +// double z = trk_z - zi; +// +// for (int i = 0; i < len; i++) { +// if(i==0) { +// Z_lowBound[i] = 0; +// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; +// } +// else { +// Z_lowBound[i] = Z_uppBound[i - 1]; +// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; +// } +// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; +// +// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { +// strip_group = i; +// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); +// if(i>0) ClosestStrip += NStrips[i - 1]; +// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; +// +// len = i; +// } +// } +// return ClosestStrip; +// } +// +// public boolean isInFiducial(double x, double y, double z, int layer) { +// +// boolean isOK = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; +// +// int axis = OldGeometry.getZorC(layer); +// +// double R = 0; +// if (axis == 0) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; +// } +// if (axis == 1) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; +// } +// +// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; +// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; +// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; +// +// double z_min = CRZZMIN + CRZOFFSET; +// double z_max = z_min + CRZLENGTH; +// +// double epsilon = 1e-1; +// +// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { +// isOK = true; +// } +// return isOK; +// } +// +// /** +// * +// * @param layer the layer 1...6 +// * @return the Z position of the strip center +// */ +// private double CRZ_GetZStrip(int layer) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //For CRZ, this function returns the Z position of the strip center +// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; +// return zc; //in mm +// } + + + public void putInFrame(Point3D cent, Point3D offset, Vector3D rotation, boolean inverse) { + if(inverse==false) { + cent.rotateX(rotation.x()); + cent.rotateY(rotation.y()); + cent.rotateZ(rotation.z()); + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + } else { + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + cent.rotateZ(rotation.z()); + cent.rotateY(rotation.y()); + cent.rotateX(rotation.x()); } - return axis; } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java new file mode 100644 index 000000000..5105f6cb6 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java @@ -0,0 +1,670 @@ +package org.jlab.rec.cvt.bmt; + +import java.util.Random; + +public class OldGeometry { + + public OldGeometry() { + + } + + // Comments on the OldGeometry of the BMT + //------------------------------------ + // The BMT geometry consists of 3 cylindical double layers of MicroMegas. + // The inner (i.e. closest to beam in double layer) layer contain longitudinal strips oriented in the Z direction. + // This is called the Z layer. + // The outer layer contain arched strips at a non-constant pitch in Z. This is called the C layer. + // The cylinder phi profile in divided into 3 sectors, A, B, C. + // + /** + * + * @param sector + * @return detector index A (=0), B (=1), C (=2) + */ + public int getDetectorIndex(int sector) { + int DetIdx = -1; + + DetIdx = sector - 1; + return DetIdx; + } + + // Return the layer number 1..6, given the region 1..3 and the detector type "C" or "Z" + public int getLayer( int region, String detType ) { + int layer = -1; + int[] lZ = { 2, 3, 5}; + int[] lC = { 1, 4, 6}; + if( detType.equalsIgnoreCase("Z") ) { + layer = lZ[ region - 1 ]; + } + if( detType.equalsIgnoreCase("C") ) { + layer = lC[ region - 1 ]; + } + return layer; + } + + /** + * + * @param sector the sector in CLAS12 1...3 + * @param layer the layer 1...6 + * @param strip the strip number (starts at 1) + * @return the angle to localize the center of strip + */ + public double CRZStrip_GetPhi(int sector, int layer, int strip) { + + // Sector = num_detector + 1; + // num_detector = 0 (region A), 1 (region B), 2, (region C) + //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" + int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) + + int num_strip = strip - 1; // index of the strip (starts at 0) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + + //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(Constants.getCRZXPOS()[num_region]+(Constants.getCRZWIDTH()[num_region]/2.+num_strip*(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region])))/Constants.getCRZRADIUS()[num_region]; + //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(0.5+num_strip)*Constants.getCRZWIDTH()[num_region]/Constants.getCRZRADIUS()[num_region]; + //double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; + double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; + return angle; //in rad + } + + + /** + * + * @param layer the layer 1...6 + * @param angle the position angle of the hit in the Z detector + * @return the Z strip as a function of azimuthal angle + */ + public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle + double jitter = Math.toRadians(Constants.isInSectorJitter); + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + int num_detector = isInDetector(layer, angle, jitter); + if (num_detector == -1) { + return -1; + } + + if (angle < 0) { + angle += 2 * Math.PI; // from 0 to 2Pi + } + if (num_detector == 1) { + double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; + if (angle >= 0 && angle <= angle_f) { + angle += 2 * Math.PI; + } + } + //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); + //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); + double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; + strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); + int strip_num = (int) Math.floor(strip_calc); + + int value = strip_num + 1; + //int value = strip_num; + + if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { + value = -1; + } + + return value; + } + + /** + * + * @param layer the layer 1...6 + * @return the Z position of the strip center + */ + private double CRZ_GetZStrip(int layer) { + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + //For CRZ, this function returns the Z position of the strip center + double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; + return zc; //in mm + } + + /** + * + * @param sector the sector in CLAS12 1...3 + * @param layer the layer 1...6 + * @return the angle to localize the beginning of the strips + */ + public double CRC_GetBeginStrip(int sector, int layer) { + // Sector = num_detector + 1; + // num_detector = 0 (region A), 1 (region B), 2, (region C) + + int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + + //For CRC, this function returns the angle to localize the beginning of the strips + double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; + if (angle > 2 * Math.PI) { + angle -= 2 * Math.PI; + } + return angle; //in rad + } + + /** + * + * @param sector the sector in CLAS12 1...3 + * @param layer the layer 1...6 + * @return the angle to localize the end of the strips + */ + public double CRC_GetEndStrip(int sector, int layer) { + // Sector = num_detector + 1; + // num_detector = 0 (region A), 1 (region B), 2, (region C) + + int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + + //For CRC, this function returns the angle to localize the end of the strips + double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; + if (angle > 2 * Math.PI) { + angle -= 2 * Math.PI; + } + return angle; //in rad + } + + /** + * + * @param layer the hit layer + * @param strip the hit strip + * @return the z position in mm for the C-detectors + */ + public double CRCStrip_GetZ(int layer, int strip) { + + int num_strip = strip - 1; // index of the strip (starts at 0) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + + //For CR6C, this function returns the Z position of the strip center + int group = 0; + int limit = Constants.getCRCGROUP()[num_region][group]; + double zc = Constants.getCRCZMIN()[num_region]; + + if (num_strip > 0) { + for (int j = 1; j < num_strip + 1; j++) { + zc += Constants.getCRCWIDTH()[num_region][group]; + if (j >= limit) { //test if we change the width + group++; + limit += Constants.getCRCGROUP()[num_region][group]; + } + } + } + zc += Constants.getCRCWIDTH()[num_region][group]/2.; + return zc; //in mm + } + + public double CRCStrip_GetPitch(int layer, int strip) { + + int num_strip = strip - 1; // index of the strip (starts at 0) + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + + //For CR6C, this function returns the Z position of the strip center + int group = 0; + int limit = Constants.getCRCGROUP()[num_region][group]; + + if (num_strip > 0) { + for (int j = 1; j < num_strip + 1; j++) { + + if (j >= limit) { //test if we change the width + group++; + limit += Constants.getCRCGROUP()[num_region][group]; + } + } + } + + return Constants.getCRCWIDTH()[num_region][group]; // + } + + /** + * + * @param layer + * @param trk_z the track z position of intersection with the C-detector + * @return the C-strip + */ + public int getCStrip(int layer, double trk_z) { + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + int strip_group = 0; + int ClosestStrip = -1; + // get group + int len = Constants.getCRCGROUP()[num_region].length; + double[] Z_lowBound = new double[len]; + double[] Z_uppBound = new double[len]; + int[] NStrips = new int[len]; + + double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; + double z = trk_z - zi; + + for (int i = 0; i < len; i++) { + if(i==0) { + Z_lowBound[i] = 0; + NStrips[i] = Constants.getCRCGROUP()[num_region][i]; + } + else { + Z_lowBound[i] = Z_uppBound[i - 1]; + NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; + } + Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; + + if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { + strip_group = i; + ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); + if(i>0) ClosestStrip += NStrips[i - 1]; + //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; + + len = i; + } + } + return ClosestStrip; + } + + /** + * + * @param layer + * @param x x-coordinate of the hit in the lab frame + * @param y y-coordinate of the hit in the lab frame + * @return the sigma along the beam direction (longitudinal) + */ + public double getSigmaLongit(int layer, double x, double y) { // sigma for C-detector + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + //double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRCRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift); + double sigma = Constants.SigmaDrift * ((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift / Math.cos(Constants.getThetaL())); + + return sigma; + + } + + /** + * + * @param layer + * @param x x-coordinate of the hit in the lab frame + * @param y y-coordinate of the hit in the lab frame + * @return the sigma along in the azimuth direction taking the Lorentz angle + * into account + */ + public double getSigmaAzimuth(int layer, double x, double y) { // sigma for Z-detectors + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; + double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift / Math.cos(Constants.getThetaL())); + + return sigma; + + } + + /** + * + * @param layer + * @param x x-coordinate of the hit in the lab frame + * @param y y-coordinate of the hit in the lab frame + * @param z z-coordinate of the hit in the lab frame + * @return X[] = the smeared position x = X[0], y = X[1], z = X[2] taking + * the Lorentz angle into account + */ + /* + public double[] smearedPosition(int layer, double x, double y, double z) { + + double[] newPos = new double[3]; + Random rand = new Random(); + + int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; + + double sigma =0; + if(layer%2==0) if(Double.isNaN(z)) {// C layer + sigma = getSigmaLongit(layer, x, y); // longitudinal shower profile + // changes z + z = this.randomGaus(z, sigma, rand); + } + + if(layer%2==1) {// Z layer + sigma = getSigmaAzimuth(layer, x, y); // azimuth shower profile taking into account the Lorentz angle + // changes phi + double phicorr = (this.randomGaus(0, sigma, rand)/Math.cos(Constants.getThetaL()) + -(Math.sqrt(x*x+y*y)-Constants.getCRZRADIUS()[num_region]+ + Constants.hStrip2Det)*Math.tan(Constants.getThetaL()))/Constants.getCRZRADIUS()[num_region]; + double phi = Math.atan2(y, x); + phi+=phicorr; + + x = Math.sqrt(x*x+y*y)*Math.cos(phi); + y = Math.sqrt(x*x+y*y)*Math.sin(phi); + } + newPos[0] = x; + newPos[1] = y; + newPos[2] = z; + + return newPos; + } + */ + private double randomGaus(double mean, double width, Random aRandom) { + if (width <= 0) { + return 0; + } + + double smear = width * aRandom.nextGaussian(); + double randomNumber = mean + smear; + + return randomNumber; + } + + public double[] LabToDetFrame(int layer, int sector, double x, double y, double z) { + double[] newPos = new double[3]; + + newPos[0] = x-org.jlab.rec.cvt.bmt.Constants.Cx[layer-1][sector-1]; + newPos[1] = y-org.jlab.rec.cvt.bmt.Constants.Cy[layer-1][sector-1]; + newPos[2] = z-org.jlab.rec.cvt.bmt.Constants.Cz[layer-1][sector-1]; + + double ThetaZ=org.jlab.rec.cvt.bmt.Constants.Rz[layer-1][sector-1]; + double ThetaY=org.jlab.rec.cvt.bmt.Constants.Ry[layer-1][sector-1]; + double ThetaX=org.jlab.rec.cvt.bmt.Constants.Rx[layer-1][sector-1]; + + //Rotate around z + double xx=newPos[0]; + newPos[0]=Math.cos(ThetaZ)*xx+Math.sin(ThetaZ)*newPos[1]; + newPos[1]=-Math.sin(ThetaZ)*xx+Math.cos(ThetaZ)*newPos[1]; + + //Rotate around x + double yy=newPos[1]; + newPos[1]=Math.cos(ThetaX)*yy+Math.sin(ThetaX)*newPos[2]; + newPos[2]=-Math.sin(ThetaX)*yy+Math.cos(ThetaX)*newPos[2]; + + //Rotate around Y + double zz=newPos[2]; + newPos[2]=Math.cos(ThetaY)*zz+Math.sin(ThetaY)*newPos[0]; + newPos[0]=-Math.sin(ThetaY)*zz+Math.cos(ThetaY)*newPos[0]; + + return newPos; + } + + public double[] DetToLabFrame(int layer, int sector, double x, double y, double z) { + + double[] newPos = new double[3]; + + newPos[0] = x; + newPos[1] = y; + newPos[2] = z; + + double ThetaZ=-org.jlab.rec.cvt.bmt.Constants.Rz[layer-1][sector-1]; + double ThetaY=-org.jlab.rec.cvt.bmt.Constants.Ry[layer-1][sector-1]; + double ThetaX=-org.jlab.rec.cvt.bmt.Constants.Rx[layer-1][sector-1]; + + //Rotate around z + double xx=newPos[0]; + newPos[0]=Math.cos(ThetaZ)*xx+Math.sin(ThetaZ)*newPos[1]; + newPos[1]=-Math.sin(ThetaZ)*xx+Math.cos(ThetaZ)*newPos[1]; + + //Rotate around x + double yy=newPos[1]; + newPos[1]=Math.cos(ThetaX)*yy+Math.sin(ThetaX)*newPos[2]; + newPos[2]=-Math.sin(ThetaX)*yy+Math.cos(ThetaX)*newPos[2]; + + //Rotate around Y + double zz=newPos[2]; + newPos[2]=Math.cos(ThetaY)*zz+Math.sin(ThetaY)*newPos[0]; + newPos[0]=-Math.sin(ThetaY)*zz+Math.cos(ThetaY)*newPos[0]; + + newPos[0] = x+org.jlab.rec.cvt.bmt.Constants.Cx[layer-1][sector-1]; + newPos[1] = y+org.jlab.rec.cvt.bmt.Constants.Cy[layer-1][sector-1]; + newPos[2] = z+org.jlab.rec.cvt.bmt.Constants.Cz[layer-1][sector-1]; + + return newPos; + } + + /** + * + * @param sector + * @param layer + * @param x + * @return a boolean indicating is the track hit is in the fiducial detector + */ + public boolean isInFiducial(int sector, int layer, int axis, double[] x) { + + boolean isInFid = false; + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; + + double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit + double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit + + double R_i = 0; // inner radius init + double R_f = 0; // outer radius init for a C or Z detector + if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { + R_i = Constants.getCRZRADIUS()[num_region]; // Z layer + } + if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { + R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors + } + R_f = R_i + Constants.hDrift; + + double angle_i = 0; // first angular boundary init + double angle_f = 0; // second angular boundary for detector A, B, or C init + double A_i = CRC_GetBeginStrip(sector, layer); + double A_f = CRC_GetEndStrip(sector, layer); + angle_i = A_i; + angle_f = A_f; + if (A_i > A_f) { // for B-detector + angle_f = A_i; + angle_i = A_f; + } + // the hit parameters + double angle = Math.atan2(x[1], x[0]); + if (angle > 2 * Math.PI) { + angle -= 2 * Math.PI; + } + double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); + double z = x[2]; + + if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { + isInFid = true; + } + + return isInFid; + } + + // in A (index 0), B (index 1), in C (index 2) + public int isInDetector(int layer, double angle, double jitter) { + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + if (angle < 0) { + angle += 2 * Math.PI; // from 0 to 2Pi + } + double angle_i = 0; // first angular boundary init + double angle_f = 0; // second angular boundary for detector A, B, or C init + int num_detector = 2; + //double jitter = Math.toRadians(Constants.isInSectorJitter); + for (int i = 0; i < 3; i++) { + + //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; + //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; + angle_i = Constants.getCRCEDGE1()[num_region][i]; + angle_f = Constants.getCRCEDGE2()[num_region][i]; + if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { + num_detector = i; + } + } + + return num_detector; + } + + public int isInSector(int layer, double angle, double jitter) { + //double jitter = Math.toRadians(Constants.isInSectorJitter); + int value = -1; + int num_det = this.isInDetector(layer, angle, jitter); + /* if(num_det == 0) + value = 2; + if(num_det ==2) + value = 3; + if(num_det == 1) + value = 1; */ + value = num_det + 1; + + return value; + } + + /** + * + * @param angle + * @param sector + * @param layer + * @param x + * @return a boolean indicating if the given angle is the sector + */ + public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { + if( layer < 1 || layer > 6 ) { + System.err.println(" BMT layer has to be 1 <= layer <= 6"); + return false; + } + if( sector < 1 || sector > 3 ) { + System.err.println(" BMT sector has to be 1 <= layer <= 3"); + return false; + } + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + double angle_i = 0; // first angular boundary init + double angle_f = 0; // second angular boundary for detector A, B, or C init + angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; + angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; + + + if (angle < 0) { + angle += 2 * Math.PI; // from 0 to 2Pi + } + + if( sector == 3 ) { + if( angle < Math.PI ) { + if( angle < angle_f + jitter ) return true; + else return false; + } + else { + if( angle > angle_i - jitter ) return true; + else return false; + } + } + else { + if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) + return true; + else + return false; + + } + } + + + public double LorentzAngleCorr(double phi, int layer) { + + int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; + //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); + return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); + } + public void SetLorentzAngle(int layer, int sector) { + org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); + } + // Correct strip position before clustering + public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { + + double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); + double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); + + return this.getZStrip(layer, theLorentzCorrectedAngle); + } + + public static void main(String arg[]) { + + Constants.Load(); + OldGeometry geo = new OldGeometry(); + + double trk_z = 0; + + int layer = 5; + System.out.println(geo.CRCStrip_GetZ(6, 267) + " strip " + geo.getCStrip(6, -65.)); + /* + int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 + int strip_group = 0; + int ClosestStrip =-1; + System.out.println((""+1*1+""+1*0+"")); + // get group + int len = Constants.CRCGROUP[num_region].length; + double[] Z_lowBound = new double[len]; + double[] Z_uppBound = new double[len]; + int[] NStrips = new int[len]; + + double zi= Constants.CRCZMIN[num_region]+Constants.CRCOFFSET[num_region]; + double z = trk_z - zi; + + Z_lowBound[0] = Constants.CRCWIDTH[num_region][0]/2.; // the lower bound is the zMin+theOffset with half the width + Z_uppBound[0] = Z_lowBound[0] + + (Constants.CRCGROUP[num_region][0]-1)*(Constants.CRCWIDTH[num_region][0]+ Constants.CRCSPACING[num_region]); + NStrips[0] = Constants.CRCGROUP[num_region][0]; + for(int i =1; i< len; i++) + { + Z_lowBound[i] = Z_uppBound[i-1] + Constants.CRCWIDTH[num_region][i-1]/2. + Constants.CRCSPACING[num_region] + Constants.CRCWIDTH[num_region][i]/2.; + Z_uppBound[i] = Z_lowBound[i] + (Constants.CRCGROUP[num_region][i]-1)*(Constants.CRCWIDTH[num_region][i] + Constants.CRCSPACING[num_region]); + + NStrips[i] = NStrips[i-1] + Constants.CRCGROUP[num_region][i]; + + if(z>=Z_lowBound[i] && z<=Z_uppBound[i]) { + strip_group = i; + ClosestStrip = 1 + (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.CRCWIDTH[num_region][strip_group] + Constants.CRCSPACING[num_region]))))+NStrips[i-1]; + + len =i; + } + } + double[] X = geo.smearedPosition(5, 0 , Constants.CRZRADIUS[2] , 0); + System.out.println(0+", "+(0.3+Constants.CRZRADIUS[2])+" , "+0+" smeared "+X[0]+", "+X[1]+" , "+X[2]); + System.out.println(geo.getZStrip(5, Math.atan2(Constants.CRZRADIUS[2],0 ))); + System.out.println(geo.getZStrip(5, Math.atan2(X[1],X[0]))); + System.out.println(Math.toDegrees( geo.CRZStrip_GetPhi(1,6, geo.getZStrip(5, Math.atan2(X[1],X[0]))) )); + int theMeasuredZStrip = geo.getZStrip(5, Math.atan2(X[1],X[0])); // start reco + double theMeasuredPhi = geo.CRZStrip_GetPhi(1,6,theMeasuredZStrip); + double theLorentzCorrectedAngle = geo.LorentzAngleCorr( theMeasuredPhi, 6); + System.out.println(" corrected phi = "+Math.toDegrees(theLorentzCorrectedAngle)); + int theLorentzCorrectedStrip = geo.getZStrip(5, theLorentzCorrectedAngle); + System.out.println(theMeasuredZStrip+" "+theLorentzCorrectedStrip); */ + /* + double phiC = geo.CRZStrip_GetPhi(3,6,216); + double x = Constants.CRCRADIUS[2]*Math.cos(phiC); + double y = Constants.CRCRADIUS[2]*Math.sin(phiC); + int theMeasuredCStrip = geo.getCStrip(6,X[2]); + double z = geo.CRCStrip_GetZ(6,309); + System.out.println(x+", "+y+", "+z);*/ + //List Hits = geo.GEMCBMTHits(layer, sector, -199.89230321711165 , 93.78543124898611 , -164.52000000000007, .1); + //System.out.println("There are "+Hits.size()+" hits in this cluster"); + //for(int i =0; i z_min - epsilon && z < z_max + epsilon) { + isOK = true; + } + return isOK; + } + + public static final synchronized int getZorC(int layer) { + int axis = 0; + if (layer == 2 || layer == 3 || layer == 5) { + axis = 1; + } + return axis; + } +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index f16d3321b..0bd49ed55 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -11,6 +11,7 @@ import org.jlab.rec.cvt.hit.Hit; import java.util.Collections; +import org.jlab.geom.prim.Arc3D; import org.jlab.rec.cvt.bmt.Constants; /** * A cluster in the BST consists of an array of hits that are grouped together @@ -30,7 +31,7 @@ public class Cluster extends ArrayList implements Comparable private int _Id; // cluster Id private double _Centroid; // after LC (Lorentz Correction) private double _CentroidError; - private double _Error; // strip resolution + private double _Error; // strip resolution private double _Centroid0; // before LC private double _TotalEnergy; private double _Phi; // for Z-detectors @@ -39,7 +40,9 @@ public class Cluster extends ArrayList implements Comparable private double _PhiErr0; private double _Z; // for C-detectors private double _ZErr; + private Arc3D _Arc; private Point3D _TrakInters; //track intersection with the cluster + private double _Radius; //added variables for alignment private double _x1; //cluster first end point x @@ -161,6 +164,20 @@ public int get_RegionSlayer() { return (this._Layer + 1) % 2 + 1; } + /** + * @return the _Radius + */ + public double getRadius() { + return _Radius; + } + + /** + * @param _Radius the _Radius to set + */ + public void setRadius(double _Radius) { + this._Radius = _Radius; + } + /** * sets energy-weighted parameters; these are the strip centroid * (energy-weighted) value, the energy-weighted phi for Z detectors and the @@ -205,6 +222,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, int nbhits = this.size(); //sort for bmt detector //this.sort(Comparator.comparing(FittedHit.get_Strip()::get_Edep).thenComparing(FittedHit.get_Strip()::get_Edep)); + Collections.sort(this); if (nbhits != 0) { int min = 1000000; @@ -233,14 +251,9 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, weightedZ2 += strpEn * stEP2.z(); } if (this.get_Detector()==1) { - if(Constants.newClustering || Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.0001) { - strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); - } else { - //strpEn = thehit.get_Strip().get_Edep(); - strpEn = 1; - } - if((Constants.newClustering && nbhits>2 && i>1) - || Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.0001 && nbhits>2 && i>1) + + strpEn = this.getBMTStripEnergy(thehit); + if(thehit.newClustering && nbhits>Constants.MAXCLUSSIZE && i>Constants.MAXCLUSSIZE-1) continue; //end points: Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); @@ -261,7 +274,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, //strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); strpNb = thehit.get_Strip().get_Strip(); // for C detector the Z of the centroid is calculated - weightedZ += strpEn * thehit.get_Strip().get_Z(); + //weightedZ += strpEn * thehit.get_Strip().get_Z(); weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); } if (this.get_DetectorType()==1) { // Z-detectors @@ -315,7 +328,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, phiCent = weightedPhi / totEn; //phiCent = geo.LorentzAngleCorr(phiCent0,this.get_Layer()); phiCent0 = weightedPhi0 / totEn; - zCent = weightedZ / totEn; + //zCent = weightedZ / totEn; phiErrCent = Math.sqrt(weightedPhiErrSq); phiErrCent0 = Math.sqrt(weightedPhiErrSq0); zErrCent = Math.sqrt(weightedZErrSq); @@ -351,6 +364,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, this.setN(n); } if (this.get_Detector()==1) { //BMT + this.setRadius(geo.getRadius(_Layer)); Cylindrical3D cyl = geo.getCylinder(this.get_Layer(), this.get_Sector()); this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); // for the BMT the analysis distinguishes between C and Z type detectors @@ -386,6 +400,8 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, this.setL(l); this.setS(s); this.setN(n); + this.set_Arc(geo.getCstrip(this.get_Region(), this.get_Sector(), this)); + //this.set_Z(this.get_Arc().center().z()); } if (this.get_DetectorType()==1) { // Z-detectors @@ -432,11 +448,11 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, set_PhiErr0(phiErrCent0); } if (this.get_DetectorType() == 0) { - _Z = zCent; + //_Z = zCent; _ZErr = zErrCent; this.set_Error(zErrCent); } - + } @@ -525,6 +541,21 @@ public void set_ZErr(double _ZErr) { this._ZErr = _ZErr; } + /** + * @return the _Arc + */ + public Arc3D get_Arc() { + return _Arc; + } + + /** + * @param _Arc the _Arc to set + */ + public void set_Arc(Arc3D _Arc) { + this._Arc = _Arc; + this.set_Z(this._Arc.center().z()); + } + public double get_TotalEnergy() { return _TotalEnergy; } @@ -608,7 +639,8 @@ public void setTrakInters(Point3D _TrakInters) { * @return cluster info. about location and number of hits contained in it */ public void printInfo() { - String s = " cluster: Detector " + this.get_Detector() +" Detector Type " + this.get_DetectorType() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Size " + this.size() +" centroid "+this.get_Centroid(); + String s = " cluster: Detector " + this.get_Detector() +" Detector Type " + this.get_DetectorType() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + + " Layer " + this.get_Layer() + " Radius " + this.getRadius()+ " Size " + this.size() +" centroid "+this.get_Centroid(); System.out.println(s); } @@ -945,6 +977,13 @@ public void setN(Vector3D _n) { private Point3D _EndPoint1; private Point3D _EndPoint2; + + public double getBMTStripEnergy(FittedHit thehit) { + double strpEn = thehit.get_Strip().get_Edep(); + + return strpEn ; + } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index caf92fb7e..724819198 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.cluster; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.jlab.rec.cvt.hit.FittedHit; @@ -16,7 +17,7 @@ public class ClusterFinder { public ClusterFinder() { } - + // cluster finding algorithm // the loop is done over sectors Hit[][][] HitArray; @@ -74,21 +75,36 @@ public ArrayList findClusters(List hits2,org.jlab.rec.cvt.svt.Geom } si++; } - + // define new cluster Cluster this_cluster = new Cluster(hits.get(0).get_Detector(), hits.get(0).get_DetectorType(), hits.get(0).get_Sector(), l + 1, cid++); this_cluster.set_Id(clusters.size() + 1); // add hits to the cluster this_cluster.addAll(hits); - for (FittedHit h : hits) { + if(hits.size()>2) { + for(int hi = 1; hi> sortClusterByDetectorAndIO( } if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.C) { - bmt_Clayrclus.add(theclus); + bmt_Clayrclus.add(theclus); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java index eb9e41437..a48d48235 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java @@ -17,12 +17,10 @@ public class FittedHit extends Hit implements Comparable { */ public FittedHit(int detector, int detectortype, int sector, int layer, Strip strip) { super(detector, detectortype, sector, layer, strip); - } private double _docaToTrk; // 3-D distance of closest approach of the helix to the wire - private double _stripResolutionAtDoca; // position resolution at distance of closest approach of the helix to the wire - + private double _stripResolutionAtDoca; private int _TrkgStatus = -1; // TrkgStatusFlag factor (-1: no fit; 0: global helical fit; 1: KF fit) public double get_docaToTrk() { @@ -61,29 +59,24 @@ public void set_TrkgStatus(int trkgStatus) { _TrkgStatus = trkgStatus; } - /** - * - * @param arg0 the other hit - * @return an int used to sort a collection of hits by layer number - */ - public int compareTo(FittedHit arg) { -// if (this.get_Layer() > arg.get_Layer()) { -// return 1; -// } else { -// return 0; -// } - - //sort by layer, then time, then edep - int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; - int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; - int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; - - int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); - int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); - - return return_val; - } - +// /** +// * +// * @param arg0 the other hit +// * @return an int used to sort a collection of hits by layer number +// */ +// public int compareTo(FittedHit arg) { +// +// //sort by layer, then time, then edep +// int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; +// int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; +// int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; +// +// int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); +// int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); +// +// return return_val; +// } + public double _QualityFac; // a quality factor depending on the hit status and goodness of fit public double get_QualityFac() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index baeb04c7b..6d35371d6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -1,5 +1,7 @@ package org.jlab.rec.cvt.hit; +import org.jlab.rec.cvt.bmt.Constants; + /** * A hit characterized by layer, sector, wire number, and Edep. The ADC to time * conversion has been done. @@ -120,7 +122,7 @@ public int get_Region() { public int get_RegionSlayer() { return (this._Layer + 1) % 2 + 1; } - + public boolean newClustering = false; /** * * @param arg0 the other hit @@ -128,24 +130,23 @@ public int get_RegionSlayer() { * by wire is used in clustering. */ @Override -// public int compareTo(Hit arg0) { -// if (this._Strip.get_Strip() > arg0._Strip.get_Strip()) { -// return 1; -// } else { -// return 0; -// } -// } public int compareTo(Hit arg) { - //sort by layer, then time, then edep - int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; - int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; - int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; - - int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); - int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); - - return return_val; + if(this.newClustering) { + //sort by layer, then time, then edep + int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; + int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; + int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; + + int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); + int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); + + return return_val; + } else { + int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; + int return_val1 = this.get_Strip().get_Strip() < arg.get_Strip().get_Strip() ? -1 : this.get_Strip().get_Strip() == arg.get_Strip().get_Strip() ? 0 : 1; + return ((CompLyr == 0) ? return_val1 : CompLyr); } + } /** * * @return print statement with hit information diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 93937c04c..edcd61af6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -25,7 +25,7 @@ public Strip(int strip, double edep, double time) { private double _Phi0; // for MM Z-detectors, the azimuth angle at the strip midwidth before LC private double _PhiErr0; - private double _Z; // for MM C-detectors. the z position at the strip midwidth + private Arc3D _Arc; // for MM C-detectors. the arc position at the strip midwidth private double _ZErr; private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value private double _Time; @@ -115,12 +115,12 @@ public void set_PhiErr0(double _PhiErr0) { this._PhiErr0 = _PhiErr0; } - public double get_Z() { - return _Z; + public Arc3D get_Arc() { + return _Arc; } - public void set_Z(double _Z) { - this._Z = _Z; + public void set_Arc(Arc3D _Arc) { + this._Arc = _Arc; } public double get_ZErr() { @@ -165,8 +165,8 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); int region = (int) ((layer + 1) / 2 ); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); - double z = arcLine.center().z(); - this.set_Z(z); + //double z = arcLine.center().z(); + this.set_Arc(arcLine); // max z err //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); this.set_ZErr(geo.getCPitch(region, this.get_Strip()) / Math.sqrt(12.)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index dae93ebc6..62c1688a1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -88,7 +88,6 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int this.setFieldsConfig(newConfig); } FieldsConfig = newConfig; - // Load the constants //------------------- int newRun = bank.getInt("run", 0); @@ -105,7 +104,7 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int Constants.setSolenoidVal(Math.abs(b[2])); Constants.Load(isCosmics, isSVTonly); this.setRun(newRun); - + if(newRun<100) { org.jlab.rec.cvt.bmt.Constants.isMC = true; } else { @@ -321,23 +320,23 @@ public boolean init() { if(exlyrsnb>0) exclLayrs = true; - //new clustering - String newClustering = this.getEngineConfigString("newclustering"); - - if (newClustering!=null) { - System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on yaml"); - org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); - } - else { - newClustering = System.getenv("COAT_CVT_NEWCLUSTERING"); - if (newClustering!=null) { - System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on env"); - org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); - } - } - if (newClustering==null) { - System.out.println("["+this.getName()+"] run with newclustering settings default = false"); - } +// //new clustering +// String newClustering = this.getEngineConfigString("newclustering"); +// +// if (newClustering!=null) { +// System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on yaml"); +// org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); +// } +// else { +// newClustering = System.getenv("COAT_CVT_NEWCLUSTERING"); +// if (newClustering!=null) { +// System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on env"); +// org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); +// } +// } +// if (newClustering==null) { +// System.out.println("["+this.getName()+"] run with newclustering settings default = false"); +// } // Load other geometries diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 0fdd60763..0dd6c3893 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -197,60 +197,18 @@ public boolean processEvent(DataEvent event, int sector = cl.get_Sector(); cosmics.get(k1).clsMap.get(keys.get(i)).setTrakInters(tj); - if (cl.get_Detector()==0 ) { - double doca2Cls = SVTGeom.getDOCAToStrip(sector, layer, cl.get_Centroid(), tj); - double doca2Seed = SVTGeom.getDOCAToStrip(sector, layer, (double) cl.get_SeedStrip(), tj); - cl.set_SeedResidual(doca2Seed); - cl.set_CentroidResidual(resi); - - for (FittedHit hit : cl) { - double doca1 = SVTGeom.getDOCAToStrip(sector, layer, (double) hit.get_Strip().get_Strip(), tj); - double sigma1 = SVTGeom.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), tj.z()); - hit.set_stripResolutionAtDoca(sigma1); - hit.set_docaToTrk(doca1); - hit.set_TrkgStatus(1); - } - } + cl.set_CentroidResidual(resi); + if (cl.get_Detector()==1 ) { - if (cl.get_DetectorType()==0) { //C-detector measuring z - double doca2Cls = tj.z() -cl.get_Z(); - cl.set_CentroidResidual(doca2Cls); - for (FittedHit h1 : cl) { - // calculate the hit residuals - double docaToTrk = tj.z() - h1.get_Strip().get_Z(); - double stripResol = h1.get_Strip().get_ZErr(); - h1.set_docaToTrk(docaToTrk); - h1.set_stripResolutionAtDoca(stripResol); - if(h1.get_Strip().get_Strip()==cl.get_SeedStrip()) - cl.set_SeedResidual(docaToTrk); - h1.set_TrkgStatus(1); - } - } if (cl.get_DetectorType()==1) { //Z-detector measuring phi Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); Line3D cln = cl.getCylAxis(); - double doca2Cls = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cl.get_Layer() + 1) / 2 - 1] *(Math.atan2(tj.y(), tj.x())- cl.get_Phi()); - cl.set_CentroidResidual((org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cl.get_Layer() + 1) / 2 - 1] +org.jlab.rec.cvt.bmt.Constants.hStrip2Det)*resi); - + double r = BMTGeom.getRadius(layer)+org.jlab.rec.cvt.bmt.Constants.hStrip2Det; + cl.set_CentroidResidual(resi*r); cl.setN(cl.getNFromTraj(tj.x(),tj.y(),tj.z(),cln)); cl.setS(cl.getL().cross(cl.getN()).asUnit()); - // calculate the hit residuals - for (FittedHit h1 : cl) { - double StripX = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cl.get_Layer() + 1) / 2 - 1] * Math.cos(h1.get_Strip().get_Phi()); - double StripY = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cl.get_Layer() + 1) / 2 - 1] * Math.sin(h1.get_Strip().get_Phi()); - - double Sign = Math.signum(Math.atan2(StripY - tj.y(), StripX - tj.x())); - double docaToTrk = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cl.get_Layer() + 1) / 2 - 1] *(Math.atan2(tj.y(), tj.x())- h1.get_Strip().get_Phi()); - double stripResol = h1.get_Strip().get_PhiErr(); - h1.set_docaToTrk(docaToTrk); - h1.set_stripResolutionAtDoca(stripResol); - if(h1.get_Strip().get_Strip()==cl.get_SeedStrip()) - cl.set_SeedResidual(docaToTrk); - h1.set_TrkgStatus(1); - - } } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 1a6411923..64591ad18 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -33,6 +33,9 @@ import java.util.Collections; import java.util.Comparator; import org.jlab.geom.prim.Arc3D; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; /** @@ -142,6 +145,8 @@ public List setMeasVecs(Seed trkcand, cyl.setAxis(cln); int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); + + double hemisp = trkcand.get_Helix().getPointAtRadius(300).y(); if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.Z) { //double x = trkcand.get_Crosses().get(c).get_Point().x(); //double y = trkcand.get_Crosses().get(c).get_Point().y(); @@ -190,27 +195,28 @@ public List setMeasVecs(Seed trkcand, } if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; + meas.hemisphere = hemisp; KFSites.add(meas); } if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.C) { double z = trkcand.get_Crosses().get(c).get_Point().z(); double err = trkcand.get_Crosses().get(c).get_Cluster1().get_ZErr(); - int clInt = (int)trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); - Arc3D arc = bgeo.getCstrip(bgeo.getRegion(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()), - trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(), clInt); - Point3D ct = new Point3D(trkcand.get_Crosses().get(c).get_Cluster1().getCx(), - trkcand.get_Crosses().get(c).get_Cluster1().getCy(), - trkcand.get_Crosses().get(c).get_Cluster1().getCz()); - Point3D og = new Point3D(trkcand.get_Crosses().get(c).get_Cluster1().getOx(), - trkcand.get_Crosses().get(c).get_Cluster1().getOy(), - trkcand.get_Crosses().get(c).get_Cluster1().getOz()); - arc.setCenter(ct); - arc.setOrigin(og); + + Arc3D arc = trkcand.get_Crosses().get(c).get_Cluster1().get_Arc(); + //Point3D ct = new Point3D(trkcand.get(i).get_Cluster1().getCx(), + // trkcand.get(i).get_Cluster1().getCy(), + // trkcand.get(i).get_Cluster1().getCz()); + // Point3D og = new Point3D(trkcand.get(i).get_Cluster1().getOx(), + // trkcand.get(i).get_Cluster1().getOy(), + // trkcand.get(i).get_Cluster1().getOz()); + //arc.setCenter(ct); + //arc.setOrigin(og); Strip strp = new Strip(id, ce, arc); cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); Surface meas = new Surface(cyl, strp); + Point3D offset = bgeo.getOffset(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), trkcand.get_Crosses().get(c).get_Sector()); Vector3D rotation = bgeo.getRotation(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), @@ -228,6 +234,7 @@ public List setMeasVecs(Seed trkcand, //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); meas.notUsedInFit=true; } + meas.hemisphere = hemisp; if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) continue; KFSites.add(meas); @@ -373,17 +380,15 @@ public List setMeasVecs(StraightTrack trkcand, if (trkcand.get(i).get_DetectorType()==BMTType.C) { double z = trkcand.get(i).get_Point().z(); double err = trkcand.get(i).get_Cluster1().get_ZErr(); - int clInt = (int)trkcand.get(i).get_Cluster1().get_Centroid(); - Arc3D arc = bgeo.getCstrip(bgeo.getRegion(trkcand.get(i).get_Cluster1().get_Layer()), - trkcand.get(i).get_Cluster1().get_Sector(), clInt); - Point3D ct = new Point3D(trkcand.get(i).get_Cluster1().getCx(), - trkcand.get(i).get_Cluster1().getCy(), - trkcand.get(i).get_Cluster1().getCz()); - Point3D og = new Point3D(trkcand.get(i).get_Cluster1().getOx(), - trkcand.get(i).get_Cluster1().getOy(), - trkcand.get(i).get_Cluster1().getOz()); - arc.setCenter(ct); - arc.setOrigin(og); + Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); + //Point3D ct = new Point3D(trkcand.get(i).get_Cluster1().getCx(), + // trkcand.get(i).get_Cluster1().getCy(), + // trkcand.get(i).get_Cluster1().getCz()); + // Point3D og = new Point3D(trkcand.get(i).get_Cluster1().getOx(), + // trkcand.get(i).get_Cluster1().getOy(), + // trkcand.get(i).get_Cluster1().getOz()); + //arc.setCenter(ct); + //arc.setOrigin(og); Strip strp = new Strip(id, ce, arc); cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); @@ -528,6 +533,12 @@ public void MatchTrack2Traj(Seed trkcand, Map reFitSeed(StraightTrack cand, } return seedlist; } + + public double[] MCtrackPars(DataEvent event) { + double[] value = new double[6]; + if (event.hasBank("MC::Particle") == false) { + return value; + } + DataBank bank = event.getBank("MC::Particle"); + + // fills the arrays corresponding to the variables + if(bank!=null) { + value[0] = (double) bank.getFloat("vx", 0)*10; + value[1] = (double) bank.getFloat("vy", 0)*10; + value[2] = (double) bank.getFloat("vz", 0)*10; + value[3] = (double) bank.getFloat("px", 0); + value[4] = (double) bank.getFloat("py", 0); + value[5] = (double) bank.getFloat("pz", 0); + } + return value; + } + + } \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 6931b43ea..0422714de 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -104,7 +104,9 @@ public boolean processEvent(DataEvent event, charge = 1; xr += org.jlab.rec.cvt.Constants.getXb(); yr += org.jlab.rec.cvt.Constants.getYb(); - + //Uncomment to force to MC truth: + //double[] pars = recUtil.MCtrackPars(event); + //xr = pars[0];yr=pars[1];zr=pars[2];px=pars[3];py=pars[4];pz=pars[5]; hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); @@ -120,6 +122,8 @@ public boolean processEvent(DataEvent event, org.jlab.rec.cvt.Constants.getYb(), shift, recUtil.setMeasVecs(seed, SVTGeom, BMTGeom, swimmer)) ; + //Uncomment to let track be fitted + //kf.filterOn=false; kf.runFitter(swimmer); if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) { Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); @@ -160,9 +164,14 @@ public boolean processEvent(DataEvent event, org.jlab.rec.cvt.Constants.getYb(), shift, recUtil.setMeasVecs(seed, SVTGeom, BMTGeom, swimmer)) ; + //Uncomment to let track be fitted + //kf.filterOn = false; kf.runFitter(swimmer); - trkcands.add(recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom)); + Track trk = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); + + trkcands.add(trk); + trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); } //} else { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 8ba46cd41..555ce0006 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -14,6 +14,7 @@ import org.jlab.detector.hits.CTOFDetHit; import org.jlab.detector.hits.DetHit; import org.jlab.geom.base.Detector; +import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Plane3D; @@ -633,38 +634,62 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } if (detector.equalsIgnoreCase("BMT")) { cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); + Point3D offset = bmt_geo.getOffset(cluster.get_Layer(), cluster.get_Sector()); + Vector3D rotation = bmt_geo.getRotation(cluster.get_Layer(), cluster.get_Sector()); + double ce = cluster.get_Centroid(); + Point3D p = new Point3D(stVec.x(), stVec.y(), stVec.z()); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z - double doca2Cls = stVec.z() -cluster.get_Z(); + Arc3D arcC = cluster.get_Arc(); + double doca2Cls = bmt_geo.getBMTCresi(arcC, p, offset, rotation); cluster.set_CentroidResidual(doca2Cls); for (FittedHit h1 : cluster) { // calculate the hit residuals - double docaToTrk = stVec.z() - h1.get_Strip().get_Z(); - double stripResol = h1.get_Strip().get_ZErr(); - h1.set_docaToTrk(docaToTrk); - h1.set_stripResolutionAtDoca(stripResol); + Arc3D arcH = h1.get_Strip().get_Arc(); + double doca1 = bmt_geo.getBMTCresi(arcH, p, offset, rotation); + //double doca1 = p.z()-hit.get_Strip().get_Z(); if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip()) - cluster.set_SeedResidual(docaToTrk); + cluster.set_SeedResidual(doca1); + h1.set_TrkgStatus(1); + h1.set_docaToTrk(doca1); h1.set_TrkgStatus(1); if (trajFinal) { h1.set_TrkgStatus(2); } } + } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi - double doca2Cls = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] *(Math.atan2(stVec.y(), stVec.x())- cluster.get_Phi()); - cluster.set_CentroidResidual(doca2Cls); - // calculate the hit residuals + int bsector = cluster.get_Sector(); + int blayer = cluster.get_Layer(); + double cxh = Math.cos(cluster.get_Phi())* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double cyh = Math.sin(cluster.get_Phi())* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double phic = bmt_geo.getPhi(new Point3D(cxh,cyh,0), bsector, blayer); + double phit = bmt_geo.getPhi(p, sector, blayer); + double doca2Cls = (phic-phit)* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + cluster.set_CentroidResidual(doca2Cls); + for (FittedHit h1 : cluster) { - double StripX = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] * Math.cos(h1.get_Strip().get_Phi()); - double StripY = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] * Math.sin(h1.get_Strip().get_Phi()); - - double Sign = Math.signum(Math.atan2(StripY - stVec.y(), StripX - stVec.x())); - double docaToTrk = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(cluster.get_Layer() + 1) / 2 - 1] *(Math.atan2(stVec.y(), stVec.x())- h1.get_Strip().get_Phi()); - double stripResol = h1.get_Strip().get_PhiErr(); - h1.set_docaToTrk(docaToTrk); - h1.set_stripResolutionAtDoca(stripResol); + double xh = Math.cos(h1.get_Strip().get_Phi())* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double yh = Math.sin(h1.get_Strip().get_Phi())* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double hphic = bmt_geo.getPhi(new Point3D(xh,yh,0), sector, blayer); + double hphit = bmt_geo.getPhi(p, sector, blayer); + double doca1 = (hphic-hphit)* + (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] + + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip()) - cluster.set_SeedResidual(docaToTrk); + cluster.set_SeedResidual(doca1); + h1.set_TrkgStatus(1); if (trajFinal) { h1.set_TrkgStatus(2); @@ -800,6 +825,7 @@ private double[][][] calc_trackIntersSVT(Ray ray, org.jlab.rec.cvt.svt.Geometry return result; } + public double[] getIntersectionTrackWithSVTModule(int s, int l, double _yxinterc2, double _yxslope2, double _yzinterc2, double _yzslope2, org.jlab.rec.cvt.svt.Geometry geo) { @@ -898,8 +924,8 @@ private double[][] getIntersectionTrackWithBMTModules(int l, rotation = geo.getRotation(lyer, topsec); ioffset = geo.getInverseOffset(lyer, topsec); irotation = geo.getInverseRotation(lyer, topsec); - geo.putInFrame(trkOr, ioffset, irotation); - geo.putInFrame(trkEn, ioffset, irotation); + geo.putInFrame(trkOr, ioffset, irotation, true); + geo.putInFrame(trkEn, ioffset, irotation, true); intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); top = intersNominal.get(0); topstp = geo.getStrip( l + 1, topsec, top); @@ -910,23 +936,24 @@ private double[][] getIntersectionTrackWithBMTModules(int l, rotation = geo.getRotation(lyer, bottomsec); ioffset = geo.getInverseOffset(lyer, bottomsec); irotation = geo.getInverseRotation(lyer, bottomsec); - geo.putInFrame(trkOr, ioffset, irotation); - geo.putInFrame(trkEn, ioffset, irotation); + geo.putInFrame(trkOr, ioffset, irotation, true); + geo.putInFrame(trkEn, ioffset, irotation, true); intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); bottom = intersNominal.get(1); bottomstp = geo.getStrip( l + 1, bottomsec, bottom); } + if(top.toVector3D().mag()>0) { inters_top[0] = top.x(); inters_top[1] = top.y(); inters_top[2] = top.z(); - inters_top[3] = topstp; + inters_top[3] = geo.getStrip( l + 1, bottomsec, top); } if(bottom.toVector3D().mag()>0) { inters_bottom[0] = bottom.x(); inters_bottom[1] = bottom.y(); inters_bottom[2] = bottom.z(); - inters_bottom[3]= bottomstp; + inters_bottom[3]= geo.getStrip( l + 1, bottomsec, bottom); } inters[0] = inters_top; @@ -1042,14 +1069,14 @@ private List getIntersBMT(int lyer, double radius, double x_minus, doub if(this.checkBMTAcceptance(ipos, lyer,geo)) { if(offset!=null && rotation!=null) - geo.putInFrame(ipos, offset, rotation); + geo.putInFrame(ipos, offset, rotation, false); } else { ipos.set(0,0,0); } if(this.checkBMTAcceptance(ineg, lyer,geo)) { if(offset!=null && rotation!=null) - geo.putInFrame(ineg, offset, rotation); + geo.putInFrame(ineg, offset, rotation, false); } else { ineg.set(0,0,0); } From c29ffbbe2726b62a6227313ba990e970fe5dbd5f Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 14 Sep 2021 15:59:14 +0200 Subject: [PATCH 162/291] CVT: code cleanups, fixes to BMT trajectory calculation --- .../java/org/jlab/rec/cvt/svt/{Geometry.java => SVTGeometry.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/{Geometry.java => SVTGeometry.java} (100%) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java similarity index 100% rename from reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Geometry.java rename to reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java From 307551023fd7fd68b22adf1821c88f194349d675 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 14 Sep 2021 16:06:51 +0200 Subject: [PATCH 163/291] CVT: code cleanups, fixes to BMT trajectory calculation --- .../org/jlab/rec/cvt/banks/HitReader.java | 3 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 3 +- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 9 +- .../java/org/jlab/rec/cvt/bmt/Constants.java | 7 +- .../java/org/jlab/rec/cvt/bmt/Geometry.java | 321 +++++++++++++++--- .../org/jlab/rec/cvt/bmt/OldGeometry.java | 6 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 12 +- .../jlab/rec/cvt/cluster/ClusterFinder.java | 5 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 6 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 23 +- .../rec/cvt/cross/HelixCrossListFinder.java | 22 +- .../cross/StraightTrackCrossListFinder.java | 18 +- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 2 - .../main/java/org/jlab/rec/cvt/hit/Strip.java | 19 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 10 +- .../rec/cvt/services/CosmicTracksRec.java | 10 +- .../jlab/rec/cvt/services/RecUtilities.java | 78 ++--- .../rec/cvt/services/TracksFromTargetRec.java | 6 +- .../java/org/jlab/rec/cvt/svt/Constants.java | 2 +- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 4 +- .../jlab/rec/cvt/track/EnergyLossCorr.java | 2 +- .../java/org/jlab/rec/cvt/track/MakerCA.java | 1 - .../org/jlab/rec/cvt/track/StraightTrack.java | 7 +- .../rec/cvt/track/StraightTrackSeeder.java | 23 +- .../java/org/jlab/rec/cvt/track/Track.java | 6 +- .../rec/cvt/track/TrackCandListFinder.java | 32 +- .../jlab/rec/cvt/track/TrackListFinder.java | 20 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 25 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 34 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 113 +++--- 30 files changed, 501 insertions(+), 328 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index b587b6369..e3972cd57 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -11,6 +11,7 @@ import org.jlab.rec.cvt.hit.ADCConvertor; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * A class to fill in lists of hits corresponding to reconstructed hits @@ -132,7 +133,7 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cv * @param adcConv converter from adc to daq values * @param geo the SVT geometry */ - public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, org.jlab.rec.cvt.svt.Geometry geo) { + public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, SVTGeometry geo) { if (event.hasBank("BST::adc") == false) { //System.err.println("there is no BST bank "); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index a4921abd4..919ec6afb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -12,7 +12,6 @@ import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.trajectory.Ray; -import org.yaml.snakeyaml.scanner.Constant; /** * @@ -21,7 +20,7 @@ public class BMTGeometry extends Geometry { public Arc3D getCstrip(int region, int sector, Cluster clus) { - double radius = Constants.getCRCRADIUS()[region-1]+Constants.hStrip2Det; + double radius = this.getRadiusMidDrift(this.getLayer(region, BMTType.C)); double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; double z = 0; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index a3dedcaaa..269d62b8e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -295,7 +295,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); - + double angle = -0;//Math.toDegrees(0.003); for (int row = 0; row0 && det!=null) { + if (det == BMTType.C) radius = Constants.getCRCRADIUS()[region-1]; + else if(det == BMTType.Z) radius = Constants.getCRZRADIUS()[region-1]; + } + else System.out.println("ERROR: out of range layer number in getRadius(int layer)"); + radius += Constants.hDrift/2; + return radius; + } + /** * Return number of strips of the selected layer * @param layer (1-6) @@ -148,7 +176,7 @@ public double getPitch(int layer, int strip) { * @param strip * @return pitch (0 if region or strip are out of range */ - public double getCPitch(int region, int strip) { + private double getCPitch(int region, int strip) { double pitch=0; if(region>=1 && region<=3) { @@ -168,7 +196,7 @@ public double getCPitch(int region, int strip) { * @param strip * @return pitch (0 if region or strip are out of range */ - public double getZPitch(int region, int strip) { + private double getZPitch(int region, int strip) { double pitch=0; if(region>=1 && region<=3) { @@ -307,6 +335,23 @@ public Vector3D getRotation(int layer, int sector) { } } + public Transformation3D getTransformation3D(int layer, int sector) { + Transformation3D transform = new Transformation3D(); + + if(!(0 trajs = new ArrayList<>(); + newGeo.getSurface(layer,sector).intersection(particle, trajs); + if(trajs.size()==0) continue; + // for(Point3D traj : trajs) System.out.println(layer + " " + sector + " " + newGeo.getRadius(layer) + " " + traj.toString()); + + for (int k = 0; k < mcTrue.rows(); k++) { + if (mcTrue.getInt("hitn", k) == id && mcTrue.getByte("detector", k) == DetectorType.BMT.getDetectorId()) { + double xTrue = mcTrue.getFloat("avgX", k); + double yTrue = mcTrue.getFloat("avgY", k); + double zTrue = mcTrue.getFloat("avgZ", k); + Point3D hit = new Point3D(xTrue, yTrue, zTrue); +// Line3D hitR = newGeo.getAxis(layer, sector).distance(hit); +// Line3D hitR = new Line3D(new Point3D(0,0,0), hit); +// hit = hitR.lerpPoint(newGeo.getRadius(layer)/(newGeo.getRadius(layer)+newGeo.getThickness()/2)); + double residual = -newGeo.getResidual(trajs.get(0), layer, sector, seed); + if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { +// Line3D strip = newGeo.getZstrip(region, sector, component); +// Line3D dist = strip.distance(hit); + dgBMT.getH1F("hiz_res" + region).fill(residual); + // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); + dgBMT.getH2F("hiz_res_z" + region).fill(zTrue, residual); + } + else { + dgBMT.getH1F("hic_res" + region).fill(residual); + dgBMT.getH2F("hic_res_z" + region).fill(zTrue, residual); + } + } + } + } + } + } + + JFrame frame = new JFrame("BMT geometry"); frame.setSize(1200, 800); - EmbeddedCanvas canvas = new EmbeddedCanvas(); - canvas.draw(acceptance); + EmbeddedCanvasTabbed canvas = new EmbeddedCanvasTabbed("BMT"); + canvas.getCanvas("BMT").draw(dgBMT); frame.add(canvas); frame.setLocationRelativeTo(null); frame.setVisible(true); @@ -1199,25 +1428,7 @@ public static void main (String arg[]) { // // return Constants.getCRCWIDTH()[num_region][group]; // // } -/** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @param strip the strip number (starts at 1) - * @return the angle to localize the center of strip - */ - public double CRZStrip_GetPhi(int sector, int layer, int strip) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" - int num_detector = sector - 1; // index of the detector (0...2) - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - return angle; //in rad - } // /** // * // * @param layer the layer 1...6 diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java index 5105f6cb6..f3541f760 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java @@ -265,7 +265,7 @@ public double getSigmaLongit(int layer, double x, double y) { // sigma for C-det int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 //double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRCRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift); - double sigma = Constants.SigmaDrift * ((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift / Math.cos(Constants.getThetaL())); + double sigma = Constants.SigmaDrift * ((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hDrift/2) / Constants.hDrift / Math.cos(Constants.getThetaL())); return sigma; @@ -282,7 +282,7 @@ public double getSigmaLongit(int layer, double x, double y) { // sigma for C-det public double getSigmaAzimuth(int layer, double x, double y) { // sigma for Z-detectors int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; - double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift / Math.cos(Constants.getThetaL())); + double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hDrift/2) / Constants.hDrift / Math.cos(Constants.getThetaL())); return sigma; @@ -549,7 +549,7 @@ public double LorentzAngleCorr(double phi, int layer) { int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); + return phi + (Constants.hDrift/2 * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); } public void SetLorentzAngle(int layer, int sector) { org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 0bd49ed55..48e515f7d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -1,15 +1,14 @@ package org.jlab.rec.cvt.cluster; import java.util.ArrayList; -import org.jlab.clas.tracking.kalmanfilter.helical.StateVecs; import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; - +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; - +import org.jlab.rec.cvt.svt.SVTGeometry; import java.util.Collections; import org.jlab.geom.prim.Arc3D; import org.jlab.rec.cvt.bmt.Constants; @@ -183,8 +182,7 @@ public void setRadius(double _Radius) { * (energy-weighted) value, the energy-weighted phi for Z detectors and the * energy-weighted z for C detectors */ - public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, - org.jlab.rec.cvt.bmt.BMTGeometry geo) { + public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { // instantiation of variables double stripNumCent = 0; // cluster Lorentz-angle-corrected energy-weighted strip = centroid double stripNumCent0 = 0; // cluster uncorrected energy-weighted strip = centroid @@ -443,7 +441,7 @@ public void calc_CentroidParams(org.jlab.rec.cvt.svt.Geometry sgeo, set_Centroid0(stripNumCent0); _Phi = phiCent; _PhiErr = phiErrCent; - this.set_Error((geo.getRadius(_Layer)+org.jlab.rec.cvt.bmt.Constants.hStrip2Det)*phiErrCent); + this.set_Error(geo.getRadiusMidDrift(_Layer)*phiErrCent); set_Phi0(phiCent0); set_PhiErr0(phiErrCent0); } @@ -652,7 +650,7 @@ public void printInfo() { * SVT * */ - public double get_ResolutionAlongZ(double Z, org.jlab.rec.cvt.svt.Geometry geo) { + public double get_ResolutionAlongZ(double Z, SVTGeometry geo) { // returns the total resolution for a group of strips in a cluster // the single strip resolution varies at each point along the strip as a function of Z (due to the graded angle of the strips) and diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 724819198..463129d01 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -3,9 +3,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * @@ -24,7 +25,7 @@ public ClusterFinder() { int nstrip = 1200; // max number of strips int nlayr = 6; int nsec = 18; - public ArrayList findClusters(List hits2,org.jlab.rec.cvt.svt.Geometry geo_bst,org.jlab.rec.cvt.bmt.BMTGeometry geo_bmt) // the number of strips depends on the layer + public ArrayList findClusters(List hits2, SVTGeometry geo_bst, BMTGeometry geo_bmt) // the number of strips depends on the layer { ArrayList clusters = new ArrayList(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index d987c3fa9..37898bbbe 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -8,7 +8,7 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.Constants; -import org.jlab.rec.cvt.svt.Geometry; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * The crosses are objects used to find tracks and are characterized by a 3-D @@ -358,7 +358,7 @@ public void set_MatchedCCross(Cross _MatchedCCross) { /** * Sets the cross parameters: the position and direction unit vector */ - public void set_CrossParamsSVT(Vector3D dirAtBstPlane, Geometry geo) { + public void set_CrossParamsSVT(Vector3D dirAtBstPlane, SVTGeometry geo) { Cluster inlayerclus = this.get_Cluster1(); Cluster outlayerclus = this.get_Cluster2(); @@ -591,7 +591,7 @@ public static void main(String arg[]) { } - public boolean isInFiducial(Geometry svt_geo) { + public boolean isInFiducial(SVTGeometry svt_geo) { boolean pass = true; Point3D LC = svt_geo.transformToFrame(this.get_Sector(), this.get_Cluster1().get_Layer(), this.get_Point().x(), this.get_Point().y(), this.get_Point().z(), "local", ""); if (((LC.x() < -0.10 || LC.x() > Constants.ACTIVESENWIDTH + 0.10)) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 899a473bd..34a03e272 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -8,6 +8,7 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.Constants; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * Driver class to make crosses @@ -27,8 +28,8 @@ public CrossMaker() { * @param svt_geo svt geometry * @return list of crosses for the SVT and BMT */ - public ArrayList> findCrosses(List clusters, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + public ArrayList> findCrosses(List clusters, SVTGeometry svt_geo, + BMTGeometry bmt_geo) { // instantiate array of clusters that are sorted by detector (SVT, BMT [C, Z]) and inner/outer layers ArrayList> sortedClusters = new ArrayList>(); // fill the sorted list @@ -62,7 +63,7 @@ public ArrayList> findCrosses(List clusters, org.jlab. public ArrayList findSVTCrosses( List svt_innerlayrclus, List svt_outerlayrclus, - org.jlab.rec.cvt.svt.Geometry svt_geo) { + SVTGeometry svt_geo) { // instantiate the list of crosses ArrayList crosses = new ArrayList(); int rid = 0; // cross id @@ -118,7 +119,7 @@ public ArrayList findSVTCrosses( return crosses; } - private void calcCentErr(Cross c, Cluster Cluster1, org.jlab.rec.cvt.svt.Geometry svt_geo) { + private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { double Z = svt_geo.transformToFrame(Cluster1.get_Sector(), Cluster1.get_Layer(), c.get_Point().x(), c.get_Point().y(), c.get_Point().z(), "local", "").z(); if(Z<0) Z=0; @@ -137,7 +138,7 @@ private void calcCentErr(Cross c, Cluster Cluster1, org.jlab.rec.cvt.svt.Geometr private ArrayList findBMTCrosses( ArrayList Clayrclus, ArrayList Zlayrclus, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + BMTGeometry bmt_geo) { //instanciates the list of crosses ArrayList crosses = new ArrayList(); @@ -154,10 +155,10 @@ private ArrayList findBMTCrosses( this_cross.set_Cluster1(Zlayerclus); // this is the inner shell //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips // in the cluster prior to taking Lorentz angle correction into account - double x0 = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi0()); - double y0 = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi0()); - double x0Er = -org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.sin(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); - double y0Er = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.cos(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); + double x0 = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi0()); + double y0 = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi0()); + double x0Er = -bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); + double y0Er = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); // set only the coordinates for which there is a measurement this_cross.set_Point0(new Point3D(x0, y0, Double.NaN)); this_cross.set_PointErr0(new Point3D(x0Er, y0Er, Double.NaN)); @@ -166,8 +167,8 @@ private ArrayList findBMTCrosses( //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); double x = Zlayerclus.getEndPoint1().x(); double y = Zlayerclus.getEndPoint1().y(); - double xEr = -org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); - double yEr = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); + double xEr = -bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); + double yEr = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); // set only the coordinates for which there is a measurement (x,y) this_cross.set_Point(new Point3D(x, y, Double.NaN)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index cf9c38c96..a079c379f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -5,10 +5,11 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.Constants; -import org.jlab.rec.cvt.svt.Geometry; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackSeeder; @@ -53,7 +54,7 @@ public HelixCrossListFinder() { * a track in the cvt */ public List findCandidateCrossLists(List> cvt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, Swim swimmer) { + SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { // instantiate the crosslist //List seedList = new ArrayList(); @@ -169,11 +170,11 @@ public List findCandidateCrossLists(List R1Crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, Swim swimmer) { + private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { if(s==null) return; - Track cand = s.seedFit.fitSeed(s, svt_geo, 3, true, swimmer); + Track cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); if(cand==null) return; @@ -483,9 +485,9 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, org.jlab.rec.cvt } - private void MatchBMTC(Seed s, ArrayList BMTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, Swim swimmer) { + private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { - Track cand = s.seedFit.fitSeed(s, svt_geo, 3, true, swimmer); + Track cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); if(s==null) return; double maxChi2 = Double.POSITIVE_INFINITY; @@ -495,7 +497,7 @@ private void MatchBMTC(Seed s, ArrayList BMTCrosses, org.jlab.rec.cvt.svt continue; } else { s.add(BMTCrosses.get(i)); - cand = s.seedFit.fitSeed(s, svt_geo, 3, true, swimmer); + cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); if(cand==null) continue; double linechi2perndf = cand.get_lineFitChi2PerNDF(); @@ -529,7 +531,7 @@ private boolean ContainsSeed(List CirTrks, Seed cand) { return inSeed; } - private double calcCentErr(Cross c, Cluster Cluster1, Geometry svt_geo) { + private double calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { double Z = svt_geo.transformToFrame(Cluster1.get_Sector(), Cluster1.get_Layer(), c.get_Point().x(), c.get_Point().y(), c.get_Point().z(), "local", "").z(); if(Z<0) Z=0; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index 8b5d56dff..ab88f9de5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -8,10 +8,11 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.Constants; import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * A class with methods used to find lists of crosses. This is the Pattern @@ -264,8 +265,7 @@ private boolean regionUniquenessFlag(ArrayList crossList) { * @return find track guess with svt only */ public CrossList findCosmicsCandidateCrossLists(List> crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { + SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { CrossList crossLists = new CrossList(); // start finding svt crosses ArrayList svt_crosses = crosses.get(0); @@ -394,8 +394,8 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, private List errX = new ArrayList(); private List errY = new ArrayList(); - private ArrayList get_XYTrajectory(List crosses, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { + private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_geo, + BMTGeometry bmt_geo, int NbSVTRegions) { ArrayList projectedCrosses = new ArrayList(); @@ -451,8 +451,7 @@ private ArrayList get_XYTrajectory(List crosses, org.jlab.rec.cvt. * @return calculated crosses on the trajectory in the xy plane */ private ArrayList get_CalcHitsOnTrackXY(double yxslope, - double yxinterc, org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int NbSVTRegions) { + double yxinterc, SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { ArrayList projectedCrosses = new ArrayList(); //Layer 1-8: @@ -493,8 +492,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, double[] t = new double[4]; for (int r = 0; r < 3; r++) { - this.calcBMT2DPoint(yxslope, - yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); + this.calcBMT2DPoint(yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.C)), t); //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); @@ -508,7 +506,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, projectedCrosses.add(cross2D2); } this.calcBMT2DPoint(yxslope, - yxinterc, org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[r] + org.jlab.rec.cvt.bmt.Constants.hDrift, t); + yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.Z)), t); //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index 6d35371d6..b460a99e0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -1,7 +1,5 @@ package org.jlab.rec.cvt.hit; -import org.jlab.rec.cvt.bmt.Constants; - /** * A hit characterized by layer, sector, wire number, and Edep. The ADC to time * conversion has been done. diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index edcd61af6..3144245d2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -8,6 +8,7 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.bmt.Constants; public class Strip { @@ -158,18 +159,19 @@ public void set_Time(double _Time) { * @param geo the BMT geometry class Sets the Lorentz corrected phi and * strip number for Z detectors, the z position for C detectors */ - public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector, int layer, Swim swim) { + public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swim) { + int region = geo.getRegion(layer); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 + if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); - int region = (int) ((layer + 1) / 2 ); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); //double z = arcLine.center().z(); this.set_Arc(arcLine); // max z err //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); - this.set_ZErr(geo.getCPitch(region, this.get_Strip()) / Math.sqrt(12.)); + this.set_ZErr(geo.getPitch(layer, this.get_Strip()) / Math.sqrt(12.)); this.set_ImplantPoint(arcLine.origin()); this.set_MidPoint(arcLine.center()); this.set_EndPoint(arcLine.end()); @@ -195,7 +197,7 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector Vector3D n = new Point3D(x, y, L.origin().z()). vectorTo(new Point3D(L.origin().x(),L.origin().y(),L.origin().z())).asUnit(); - double theMeasuredPhi = geo.CRZStrip_GetPhi(sector, layer, this.get_Strip()); + double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.get_Strip()); //double theLorentzCorrectedAngle = L.midpoint().toVector3D().phi(); double theLorentzCorrectedAngle = n.phi(); // set the phi @@ -203,8 +205,7 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector this.set_Phi0(theMeasuredPhi); // uncorrected //System.out.println(" sec "+sector+" strip "+this.get_Strip()+" LC strip "+geo.getZStrip(layer, theLorentzCorrectedAngle)); //int theLorentzCorrectedStrip = geo.getZStrip(layer, theLorentzCorrectedAngle); - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; -// double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* + // double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* // Math.cos(theLorentzCorrectedAngle); // double yl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* // Math.sin(theLorentzCorrectedAngle); @@ -214,12 +215,12 @@ public void calc_BMTStripParams(org.jlab.rec.cvt.bmt.BMTGeometry geo, int sector // get the strip number after correcting for Lorentz angle this.set_LCStrip(theLorentzCorrectedStrip); - double sigma = org.jlab.rec.cvt.bmt.Constants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh + double sigma = Constants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh //max phi err - double phiErrL = sigma / org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; + double phiErrL = sigma / geo.getRadius(layer); - double phiErr = org.jlab.rec.cvt.bmt.Constants.getCRZWIDTH()[num_region] / org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region] / Math.sqrt(12.); + double phiErr = geo.getPitch(layer, this.get_Strip()) / geo.getRadius(layer) / Math.sqrt(12.); this.set_PhiErr(Math.sqrt(phiErr * phiErr + phiErrL * phiErrL)); //System.out.println("arcerr "+org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]+" * "+Math.toDegrees(sigma/org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region])); this.set_PhiErr0(phiErr); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 62c1688a1..13fc25380 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -19,6 +19,7 @@ import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.HitReader; import org.jlab.rec.cvt.banks.RecoBankWriter; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cluster.ClusterFinder; @@ -27,6 +28,7 @@ import org.jlab.rec.cvt.hit.ADCConvertor; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * Service to return reconstructed TRACKS @@ -37,8 +39,8 @@ */ public class CVTRecNewKF extends ReconstructionEngine { - org.jlab.rec.cvt.svt.Geometry SVTGeom; - org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom; + SVTGeometry SVTGeom; + BMTGeometry BMTGeom; CTOFGeant4Factory CTOFGeom; Detector CNDGeom ; SVTStripFactory svtIdealStripFactory; @@ -48,8 +50,8 @@ public class CVTRecNewKF extends ReconstructionEngine { public CVTRecNewKF() { super("CVTTracks", "ziegler", "4.0"); - SVTGeom = new org.jlab.rec.cvt.svt.Geometry(); - BMTGeom = new org.jlab.rec.cvt.bmt.BMTGeometry(); + SVTGeom = new SVTGeometry(); + BMTGeom = new BMTGeometry(); strgtTrksRec = new CosmicTracksRec(); trksFromTargetRec = new TracksFromTargetRec(); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 0dd6c3893..f421fa8e4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -6,7 +6,6 @@ package org.jlab.rec.cvt.services; import Jama.Matrix; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; @@ -17,22 +16,19 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataEvent; -import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossList; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackCandListFinder; -import org.jlab.rec.cvt.track.TrackListFinder; import org.jlab.rec.cvt.trajectory.Ray; -import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; /** @@ -48,7 +44,7 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, double zShift, boolean exLayrs, Swim swimmer) { @@ -204,7 +200,7 @@ public boolean processEvent(DataEvent event, if (cl.get_DetectorType()==1) { //Z-detector measuring phi Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); Line3D cln = cl.getCylAxis(); - double r = BMTGeom.getRadius(layer)+org.jlab.rec.cvt.bmt.Constants.hStrip2Det; + double r = BMTGeom.getRadiusMidDrift(layer); cl.set_CentroidResidual(resi*r); cl.setN(cl.getNFromTraj(tj.x(),tj.y(),tj.z(),cln)); cl.setS(cl.getL().cross(cl.getN()).asUnit()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 64591ad18..f4dd48d97 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -36,6 +36,8 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; /** @@ -48,7 +50,7 @@ public class RecUtilities { public void CleanupSpuriousCrosses(List> crosses, List trks, - org.jlab.rec.cvt.svt.Geometry SVTGeom) { + SVTGeometry SVTGeom) { List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { @@ -82,9 +84,7 @@ public void CleanupSpuriousCrosses(List> crosses, List t } } - public List setMeasVecs(Seed trkcand, - org.jlab.rec.cvt.svt.Geometry sgeo, - org.jlab.rec.cvt.bmt.BMTGeometry bgeo, Swim swim) { + public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), @@ -173,8 +173,8 @@ public List setMeasVecs(Seed trkcand, //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); - cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); Surface meas = new Surface(cyl, strp); Point3D offset = bgeo.getOffset(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), trkcand.get_Crosses().get(c).get_Sector()); @@ -212,8 +212,8 @@ public List setMeasVecs(Seed trkcand, //arc.setCenter(ct); //arc.setOrigin(og); Strip strp = new Strip(id, ce, arc); - cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); Surface meas = new Surface(cyl, strp); @@ -245,8 +245,7 @@ public List setMeasVecs(Seed trkcand, } private TrajectoryFinder tf = new TrajectoryFinder(); public List setMeasVecs(StraightTrack trkcand, - org.jlab.rec.cvt.svt.Geometry sgeo, - org.jlab.rec.cvt.bmt.BMTGeometry bgeo, Swim swim) { + SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), @@ -352,8 +351,8 @@ public List setMeasVecs(StraightTrack trkcand, //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); - cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); Surface meas = new Surface(cyl, strp); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); Point3D offset = bgeo.getOffset(trkcand.get(i).get_Cluster1().get_Layer(), @@ -390,8 +389,8 @@ public List setMeasVecs(StraightTrack trkcand, //arc.setCenter(ct); //arc.setOrigin(og); Strip strp = new Strip(id, ce, arc); - cyl.baseArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - cyl.highArc().setRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); Surface meas = new Surface(cyl, strp); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); @@ -425,8 +424,7 @@ public List setMeasVecs(StraightTrack trkcand, } public List FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, - org.jlab.rec.cvt.svt.Geometry sgeo, - Swim swimmer) { + SVTGeometry sgeo, Swim swimmer) { Map clusMap = new HashMap(); //Map stripMap = new HashMap(); Map docaMap = new HashMap(); @@ -497,7 +495,7 @@ public List FindClustersOnTrk (List allClusters, Helix helix, public void MatchTrack2Traj(Seed trkcand, Map traj, - org.jlab.rec.cvt.svt.Geometry sgeo, org.jlab.rec.cvt.bmt.BMTGeometry bgeo) { + SVTGeometry sgeo, BMTGeometry bgeo) { for (int i = 0; i < trkcand.get_Clusters().size(); i++) { //SVT if(trkcand.get_Clusters().get(i).get_Detector()==0) { @@ -551,31 +549,19 @@ public void MatchTrack2Traj(Seed trkcand, Map reFit(List seedlist, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, Swim swimmer, StraightTrackSeeder trseed) { List filtlist = new ArrayList(); if(seedlist==null) @@ -706,8 +691,7 @@ public List reFit(List seedlist, } public List reFitSeed(Seed bseed, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, StraightTrackSeeder trseed) { List seedlist = new ArrayList(); @@ -740,8 +724,7 @@ public List reFitSeed(Seed bseed, } public List reFit(List seedlist, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { trseed = new TrackSeederCA(); trseed2 = new TrackSeeder(); @@ -759,8 +742,7 @@ public List reFit(List seedlist, return filtlist; } public List reFitSeed(Seed bseed, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { boolean pass = true; @@ -799,8 +781,7 @@ public List reFitSeed(Seed bseed, } public List reFit(List seedlist, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + SVTGeometry SVTGeom, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { fitTrk = new CosmicFitter(); trkfindr = new TrackCandListFinder(); List filtlist = new ArrayList(); @@ -819,8 +800,7 @@ public List reFit(List seedlist, public List reFitSeed(StraightTrack cand, - org.jlab.rec.cvt.svt.Geometry SVTGeom, - CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + SVTGeometry SVTGeom, CosmicFitter fitTrk,TrackCandListFinder trkfindr) { boolean pass = true; List seedlist = new ArrayList(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 0422714de..abd169483 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -20,6 +20,7 @@ import org.jlab.rec.cvt.banks.RecoBankWriter; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; @@ -43,7 +44,7 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - org.jlab.rec.cvt.svt.Geometry SVTGeom, org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom, + SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, double shift, @@ -90,7 +91,7 @@ public boolean processEvent(DataEvent event, for (Seed seed : seeds) { org.jlab.clas.tracking.trackrep.Helix hlx = null ; - double xr = -seed.get_Helix().get_dca()*Math.sin(seed.get_Helix().get_phi_at_dca()); + double xr = -seed.get_Helix().get_dca()*Math.sin(seed.get_Helix().get_phi_at_dca()); double yr = seed.get_Helix().get_dca()*Math.cos(seed.get_Helix().get_phi_at_dca()); double zr = seed.get_Helix().get_Z0(); double pt = Constants.LIGHTVEL * seed.get_Helix().radius() * Constants.getSolenoidVal(); @@ -196,6 +197,7 @@ public boolean processEvent(DataEvent event, } //System.out.println( " *** *** trkcands " + trkcands.size() + " * trks " + trks.size()); + // RDV: can it be done before doing trajectories?? trkFinder.removeOverlappingTracks(tracks); //turn off until debugged // reset cross IDs for(int a = 0; a<2; a++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java index 9f9755c09..8ab85967b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java @@ -214,7 +214,7 @@ public static synchronized void Load() { LAYRGAP = MODULERADIUS[1][0] - MODULERADIUS[0][0]; - Geometry geo = new Geometry(); + SVTGeometry geo = new SVTGeometry(); for(int l =0; l < NLAYR; l++) { for(int j = 0; j< NSECT[l]; j++) { for(int k = 0; k crosses, double phiShift) { List BMTmatches = new ArrayList(); public List findSeed(List svt_crosses, List bmt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean isSVTOnly) { + SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean isSVTOnly) { BMTmatches.clear(); seedScan.clear() ; List seedlist = new ArrayList(); @@ -304,7 +306,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); Track cand = null; if(seedcrs.size()>=3) - cand = fitSeed(seedcrs, svt_geo, 5, false); + cand = fitSeed(seedcrs, svt_geo, bmt_geo, 5, false); if (cand != null) { Seed seed = new Seed(); seed.set_Crosses(seedcrs); @@ -332,7 +334,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, for (Seed bseed : BMTmatches) { Collections.sort(bseed.get_Crosses()); //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false); + Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, bmt_geo, 5, false); if (bcand != null) { seed = new Seed(); seed.set_Crosses(bseed.get_Crosses()); @@ -351,7 +353,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, BMTGeometry bmt_geo) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init @@ -386,7 +388,7 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c List BMTCrossesZ = new ArrayList(); List SVTCrosses = new ArrayList(); - public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, int fitIter, + public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint) { double chisqMax = Double.POSITIVE_INFINITY; @@ -470,10 +472,9 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - ErrRho.add(j, org.jlab.rec.cvt.bmt.Constants.hStrip2Det / Math.sqrt(12.)); + ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } @@ -510,7 +511,7 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + List bmt_crosses, BMTGeometry bmt_geo) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -588,12 +589,12 @@ public List findCandUsingMicroMegas(Seed trkCand, return AllSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; + double r_bmt = bmt_geo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); Point3D refPoint = trkCand.get_Crosses().get(0).get_Point(); //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index f3fdaf561..b6cb20c34 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -4,7 +4,7 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.svt.Geometry; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -134,7 +134,7 @@ public void set_HelicalTrack(Helix Helix) { * * @param geo the SVT geometry */ - public void update_Crosses(Geometry geo) { + public void update_Crosses(SVTGeometry geo) { if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { Helix helix = this.get_helix(); @@ -164,7 +164,7 @@ public void update_Crosses(Geometry geo) { } - public void finalUpdate_Crosses(Geometry geo) { + public void finalUpdate_Crosses(SVTGeometry geo) { if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { Helix helix = this.get_helix(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 0b096919f..bfec00cce 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -11,8 +11,8 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.Constants; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossList; @@ -20,6 +20,7 @@ import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -132,7 +133,7 @@ public class RayMeasurements { * @param list the input list of crosses * @return an array list of track candidates in the SVT */ - public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) { X.clear(); Y.clear(); Z.clear(); @@ -217,7 +218,7 @@ public void getHelicalTrack(Seed cand, org.jlab.rec.cvt.svt.Geometry svt_geo, or * @return an array list of track candidates in the SVT */ public ArrayList getHelicalTracks(CrossList crossList, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, + SVTGeometry svt_geo, BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, Swim swimmer) { @@ -334,7 +335,7 @@ public ArrayList getHelicalTracks(CrossList crossList, * @param SVTCrossList the input list of crosses * @return an array list of track candidates in the SVT */ - public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo) { ArrayList cands = new ArrayList(); Map candMap= new HashMap(); @@ -505,7 +506,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List hitsOnTrack = new ArrayList(); @@ -648,7 +649,8 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, for (int j = shift + j0; j < shift + j0 + BMTCdetcrossesInTrk.size(); j++) { Z.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hDrift/2); + System.out.println(BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().toString() + " " + org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1]); ErrRho.add(j, 0.01); // check this error on thickness measurement ErrZ.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_PointErr().z()); @@ -791,7 +793,7 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, return MeasArray; } - private void resetUnusedCross(Cross cross, org.jlab.rec.cvt.svt.Geometry geo) { + private void resetUnusedCross(Cross cross, SVTGeometry geo) { cross.set_Dir(new Vector3D(0, 0, 0)); @@ -805,7 +807,7 @@ private void resetUnusedCross(Cross cross, org.jlab.rec.cvt.svt.Geometry geo) { * @param geo the BMT geometry * @return an arraylist of BMT crosses matched to the track */ - public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thecand, org.jlab.rec.cvt.bmt.BMTGeometry geo) { + public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thecand, BMTGeometry geo) { double matchCutOff = org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUAL; // ? guess @@ -822,7 +824,7 @@ public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thec // for configuration in 3 double SVT layers + 3 double BMT layers //------------------------------------------------------------------------------------------------------ for (int regionIdx = 0; regionIdx < 3; regionIdx++) { - ArrayList MatchedMMCrossZDet = this.MatchMMCrossZ(regionIdx + 1, thecand2.get_ray(), MMCrosses, Math.toRadians(2)); // 2 degrees opening angle + ArrayList MatchedMMCrossZDet = this.MatchMMCrossZ(regionIdx + 1, thecand2.get_ray(), MMCrosses, Math.toRadians(2), geo); // 2 degrees opening angle if (MatchedMMCrossZDet.size() > 0) { BMTCrossList.addAll(MatchedMMCrossZDet); } @@ -844,11 +846,11 @@ public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thec return BMTCrossList; } - private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, org.jlab.rec.cvt.bmt.BMTGeometry geo) { + private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, BMTGeometry geo) { ArrayList matchedMMCrosses = new ArrayList(); - double R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[Region - 1] + org.jlab.rec.cvt.bmt.Constants.hDrift / 2; // R for C detector + double R = geo.getRadiusMidDrift(geo.getLayer(Region,BMTType.C)); // R for C detector double sx = ray.get_yxslope(); double ix = ray.get_yxinterc(); @@ -915,11 +917,11 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse return matchedMMCrosses; } - private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosses, double matchCutOff) { + private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosses, double matchCutOff, BMTGeometry geo) { ArrayList matchedMMCrosses = new ArrayList(); - double R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Region - 1] + org.jlab.rec.cvt.bmt.Constants.hDrift / 2; // R for Z detector + double R = geo.getRadiusMidDrift(geo.getLayer(Region,BMTType.Z)); // R for Z detector double sx = ray.get_yxslope(); double ix = ray.get_yxinterc(); double sz = ray.get_yzslope(); @@ -1068,7 +1070,7 @@ private ArrayList rmStraightTrkClones(boolean removeClones, Array } private void EliminateStraightTrackOutliers(ArrayList crossesToFit, - CosmicFitter fitTrk, org.jlab.rec.cvt.svt.Geometry svt_geo) { + CosmicFitter fitTrk, SVTGeometry svt_geo) { for (int j = 0; j < crossesToFit.size(); j++) { if (Math.abs(fitTrk.get_ray().get_yxslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yxinterc() - crossesToFit.get(j).get_Point().x()) > org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUAL || Math.abs(fitTrk.get_ray().get_yzslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yzinterc() - crossesToFit.get(j).get_Point().z()) > org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUALZ) { @@ -1078,7 +1080,7 @@ private void EliminateStraightTrackOutliers(ArrayList crossesToFit, } } - public void matchClusters(List sVTclusters, TrajectoryFinder tf, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal, + public void matchClusters(List sVTclusters, TrajectoryFinder tf, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal, ArrayList trajectory, int k) { if(trajectory == null) return; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 3f026a30f..9ec38b0fb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -9,8 +9,10 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -24,14 +26,18 @@ public TrackListFinder() { * * @param cands the list of track candidates * @param svt_geo the svt geometry + * @param bmt_geo + * @param ctof_geo + * @param cnd_geo + * @param cvtSwim * @return the list of selected tracks */ public List getTracks(List cands, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, + SVTGeometry svt_geo, BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, - Swim bstSwim) { - List tracks = new ArrayList(); - if (cands.size() == 0) { + Swim cvtSwim) { + List tracks = new ArrayList<>(); + if (cands.isEmpty()) { System.err.print("Error no tracks found"); return cands; } @@ -50,12 +56,12 @@ public List getTracks(List cands, int charge = trk.get_Q(); double maxPathLength = 5.0;//very loose cut - bstSwim.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10 , + cvtSwim.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10 , Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), trk.get_P(), charge, maxPathLength) ; - double[] pointAtCylRad = bstSwim.SwimRho(Constants.CTOFINNERRADIUS/10); + double[] pointAtCylRad = cvtSwim.SwimRho(Constants.CTOFINNERRADIUS/10); if(pointAtCylRad!=null) { trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); @@ -64,7 +70,7 @@ public List getTracks(List cands, TrajectoryFinder trjFind = new TrajectoryFinder(); - Trajectory traj = trjFind.findTrajectory(trk.get_Id(), trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, bstSwim, "final"); + Trajectory traj = trjFind.findTrajectory(trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, cvtSwim, "final"); trk.set_Trajectory(traj.get_Trajectory()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index a8152af9f..eb8020fbd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -8,6 +8,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -15,6 +16,7 @@ import org.jlab.rec.cvt.fit.CircleFitPars; import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.svt.Constants; +import org.jlab.rec.cvt.svt.SVTGeometry; public class TrackSeeder { int NBINS = 36; @@ -210,7 +212,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); public List findSeed(List bst_crosses, List bmt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, + SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { List seedlist = new ArrayList(); @@ -316,7 +318,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); Track cand = null; if(seedcrs.size()>=3) - cand = fitSeed(seedcrs, svt_geo, 5, false, swimmer); + cand = fitSeed(seedcrs, svt_geo, bmt_geo, 5, false, swimmer); if (cand != null) { Seed seed = new Seed(); seed.set_Crosses(seedcrs); @@ -345,7 +347,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, for (Seed bseed : BMTmatches) { //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, 5, false, swimmer); + Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, bmt_geo, 5, false, swimmer); if (bcand != null && bcand.get_circleFitChi2PerNDF() findSeed(List bst_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, BMTGeometry bmt_geo) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init double jitter = Math.toRadians(10); // 10 degrees jitter for (int i = 0; i < bmt_crosses.size(); i++) { - Point3D pAtBMTSurf =seed.get_Helix().getPointAtRadius(org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_crosses.get(i).get_Region()-1]); + Point3D pAtBMTSurf =seed.get_Helix().getPointAtRadius(bmt_geo.getRadius(bmt_crosses.get(i).get_Cluster1().get_Layer())); // the hit parameters double angle = Math.atan2(pAtBMTSurf.y(), pAtBMTSurf.x()); if (angle < 0) { @@ -407,7 +409,7 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c List SVTCrosses = new ArrayList(); float b[] = new float[3]; - public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_geo, int fitIter, + public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, Swim swimmer) { double chisqMax = Double.POSITIVE_INFINITY; @@ -500,10 +502,9 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - ErrRho.add(j, org.jlab.rec.cvt.bmt.Constants.hStrip2Det / Math.sqrt(12.)); + ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } @@ -546,7 +547,7 @@ public Track fitSeed(List VTCrosses, org.jlab.rec.cvt.svt.Geometry svt_ge public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + List bmt_crosses, BMTGeometry bmt_geo) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -628,13 +629,13 @@ public List findCandUsingMicroMegas(Seed trkCand, return outputSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; + double r_bmt = bmt_geo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); Point3D phiHelixAtSurf = trkCand.get_Helix().getPointAtRadius(r_bmt); //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) // != bmt_Ccross.get_Sector()) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index d10382a55..4574fd549 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -1,21 +1,19 @@ package org.jlab.rec.cvt.track; -import org.jlab.rec.cvt.track.MakerCA; -import org.jlab.rec.cvt.track.Cell; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.svt.Constants; +import org.jlab.rec.cvt.svt.SVTGeometry; public class TrackSeederCA { @@ -28,8 +26,8 @@ public TrackSeederCA() { // Retrieve lists of crosses as track candidates // from the output of the cellular automaton // it looks only for the maximum state, TODO: remove found candidate and continue - public List> getCAcandidates( List nodes, org.jlab.rec.cvt.svt.Geometry svt_geo, - Swim swimmer ) { + public List> getCAcandidates( List nodes, SVTGeometry svt_geo, + BMTGeometry bmt_geo, Swim swimmer ) { //System.out.println("\n\n\t ____inside get candidates___"); List> trCands = new ArrayList>(); List> cellCands = new ArrayList>(); @@ -117,7 +115,7 @@ public List> getCAcandidates( List nodes, org.jlab.rec.cv // System.out.println(" "); if( cand.get(0).get_plane().equalsIgnoreCase("XY")) { if( candlen > 2 ){ - if( fitSeed(getCrossFromCells(cand), svt_geo, 2, false, swimmer) != null) { + if( fitSeed(getCrossFromCells(cand), svt_geo, bmt_geo, 2, false, swimmer) != null) { cellCands.add(cand); for( Cell n : cand ) { @@ -192,9 +190,7 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs, } TrackListFinder trkFinder = new TrackListFinder(); public List findSeed(List svt_crosses, List bmt_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, - Swim swimmer) { + SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { List seedlist = new ArrayList(); @@ -219,7 +215,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, // run the cellular automaton over SVT and BMT_Z crosses List xynodes = runCAMaker( "XY", 5, crosses, bmt_geo, swimmer); - List> xytracks = getCAcandidates( xynodes, svt_geo, swimmer); + List> xytracks = getCAcandidates( xynodes, svt_geo, bmt_geo, swimmer); // System.out.println( " XY tracks " + xytracks ); //// TODO: TEST TEST TEST @@ -237,7 +233,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, // System.out.println(seedlist.size()); for (int s = 0; s < seedCrosses.size(); s++) { Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters - Track cand = fitSeed(seedCrosses.get(s), svt_geo, 5, false, swimmer); + Track cand = fitSeed(seedCrosses.get(s), svt_geo, bmt_geo, 5, false, swimmer); if (cand != null) { cands.add(cand); } @@ -332,8 +328,7 @@ private List rmDuplicate( List tracks) { public List> CAonRZ( List>xytracks , List> bmtC_crosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, - org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, + SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { List> seedCrosses = new ArrayList>(); @@ -388,7 +383,7 @@ public List> CAonRZ( // run the CAmaker List zrnodes = runCAMaker( "ZR", 5, crsZR, bmt_geo, swimmer); //System.out.println(zrnodes); - List> zrtracks = getCAcandidates( zrnodes, svt_geo, swimmer); + List> zrtracks = getCAcandidates( zrnodes, svt_geo, bmt_geo, swimmer); // System.out.println("sector" + sector + " len " + zrtracks.size()); @@ -412,7 +407,7 @@ public List> CAonRZ( List EZ= new ArrayList(); for( Cross c : zrcross ) { - R.add( org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[c.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det ); + R.add( bmt_geo.getRadiusMidDrift(c.get_Cluster1().get_Layer())); Z.add( c.get_Point().z() ); EZ.add( c.get_PointErr().z()); } @@ -484,7 +479,7 @@ public List> CAonRZ( float b[] = new float[3]; public Track fitSeed(List VTCrosses, - org.jlab.rec.cvt.svt.Geometry svt_geo, int fitIter, boolean originConstraint, + SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, Swim swimmer) { double chisqMax = Double.POSITIVE_INFINITY; Collections.sort(VTCrosses); @@ -577,10 +572,9 @@ public Track fitSeed(List VTCrosses, if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - ErrRho.add(j, org.jlab.rec.cvt.bmt.Constants.hStrip2Det / Math.sqrt(12.)); + ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 555ce0006..2f8371e55 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -3,7 +3,6 @@ import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -15,9 +14,7 @@ import org.jlab.detector.hits.DetHit; import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Arc3D; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; @@ -28,6 +25,7 @@ import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.Constants; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.Track; /** @@ -50,8 +48,8 @@ public TrajectoryFinder() { * @param isFinal * @return a trajectory object */ - public Trajectory findTrajectory(int id, Track trk, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, + public Trajectory findTrajectory(Track trk, + SVTGeometry svt_geo, BMTGeometry bmt_geo, CTOFGeant4Factory ctof_geo, Detector cnd_geo, Swim swimmer, String isFinal) { Helix helix = trk.get_helix(); @@ -63,7 +61,7 @@ public Trajectory findTrajectory(int id, Track trk, traj.isFinal = true; } - traj.set_Id(id); + traj.set_Id(trk.get_Id()); if (candCrossList.size() == 0) { System.err.print("Trajectory Error: cross list is empty"); @@ -154,7 +152,7 @@ public Trajectory findTrajectory(int id, Track trk, this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); stVec.set_CalcCentroidStrip(svt_geo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); stVec.set_Path(path*10); - stVec.set_ID(id); + stVec.set_ID(trk.get_Id()); stateVecs.add(stVec); String svtSt1 = "1."; svtSt1+=sector; @@ -186,7 +184,7 @@ public Trajectory findTrajectory(int id, Track trk, inters = null; path = 0; //BMT - for (int l = org.jlab.rec.cvt.svt.Constants.NLAYR; l < org.jlab.rec.cvt.svt.Constants.NLAYR + 2 * org.jlab.rec.cvt.bmt.Constants.NREGIONS; l++) { + for (int l = org.jlab.rec.cvt.svt.Constants.NLAYR; l < org.jlab.rec.cvt.svt.Constants.NLAYR + bmt_geo.getNLayers(); l++) { // re-initilize swimmer from last surface if(inters!=null) { double intersPhi = Math.atan2(inters[4], inters[3]); @@ -194,46 +192,43 @@ public Trajectory findTrajectory(int id, Track trk, swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; } if(inters!=null || l==org.jlab.rec.cvt.svt.Constants.NLAYR) { // don't swim if previous layers was not reached - int BMTRegIdx = (l - org.jlab.rec.cvt.svt.Constants.NLAYR) / 2; - - if (org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] == 0) { - continue; // Use the correctly defined geometry - } - double R = 0; - - if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.Z) { - R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; - } - if (BMTGeometry.getDetectorType(l + 1-6) == BMTType.C) { - R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTRegIdx] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det; - } - - // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + int layer = l - org.jlab.rec.cvt.svt.Constants.NLAYR + 1; + int region = bmt_geo.getRegion(layer); + + // RDV: tried using this to determine the sector but t is giving bogus number + //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); + double radius = bmt_geo.getRadiusMidDrift(layer)/10; + inters = swimmer.SwimRho(radius); + int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); + + Line3D axis = bmt_geo.getAxis(layer, sector); + Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); + Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); + // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), // trk.get_P(), trk.get_Q(), // 5.0) ; - inters = swimmer.SwimToCylinder(R/10); + inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius); double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); path = path + inters[6]; - - //if(r>(R - org.jlab.rec.cvt.bmt.Constants.LYRTHICKN)/10) { + //if(r>(radius - org.jlab.rec.cvt.bmt.Constants.LYRTHICKN)/10) { StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); - double phiPos = Math.atan2(stVec.y(),stVec.x()); - //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); - int sector = bmt_geo.getSector(2*(BMTRegIdx+1),phiPos); +// double phiPos = Math.atan2(stVec.y(),stVec.x()); +// //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); +// int sector = bmt_geo.getSector(layer,phiPos); stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); stVec.set_SurfaceSector(sector); stVec.set_SurfaceLayer(l+1); - stVec.set_ID(id); + stVec.set_ID(trk.get_Id()); stVec.set_Path(path*10); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); this.fill_HelicalTrkAngleWRTBMTTangentPlane(dir, stVec); //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); - stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(BMTRegIdx+1, + stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(region, new Point3D(stVec.x(),stVec.y(),stVec.z()))); stVec.set_Path(path*10); - stVec.set_ID(id); + stVec.set_ID(trk.get_Id()); String bmtSt1 = "2."; bmtSt1+=sector; @@ -258,7 +253,7 @@ public Trajectory findTrajectory(int id, Track trk, swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; // swim to CTOF double radius = ctof_geo.getRadius(1); - inters = swimmer.SwimToCylinder(radius); + inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius); // update parameters double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); @@ -269,7 +264,7 @@ public Trajectory findTrajectory(int id, Track trk, stVec.set_SurfaceDetector(DetectorType.CTOF.getDetectorId()); stVec.set_SurfaceSector(1); stVec.set_SurfaceLayer(1); - stVec.set_ID(id); + stVec.set_ID(trk.get_Id()); stVec.set_TrkPhiAtSurface(intersPhi); stVec.set_TrkThetaAtSurface(intersTheta); stVec.set_TrkToModuleAngle(0); @@ -292,8 +287,8 @@ public Trajectory findTrajectory(int id, Track trk, // swim to CTOF Point3D center = cnd_geo.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); double radius = Math.sqrt(center.x()*center.x()+center.y()*center.y()); - inters = swimmer.SwimToCylinder(radius); - // update parameters + inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius); + // update parameters double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); @@ -303,12 +298,12 @@ public Trajectory findTrajectory(int id, Track trk, stVec.set_SurfaceDetector(DetectorType.CND.getDetectorId()); stVec.set_SurfaceSector(1); stVec.set_SurfaceLayer(ilayer+1); - stVec.set_ID(id); + stVec.set_ID(trk.get_Id()); stVec.set_TrkPhiAtSurface(intersPhi); stVec.set_TrkThetaAtSurface(intersTheta); stVec.set_TrkToModuleAngle(0); stVec.set_Path(path*10); - stateVecs.add(stVec); + stateVecs.add(stVec); } } @@ -338,7 +333,7 @@ private void fill_HelicalTrkAngleWRTBMTTangentPlane(Vector3D trkDir, StateVec st } private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, - Vector3D trkDir, org.jlab.rec.cvt.svt.Geometry svt_geo, StateVec stVec) { + Vector3D trkDir, SVTGeometry svt_geo, StateVec stVec) { Vector3D n = svt_geo.findBSTPlaneNormal(sector, layer); Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module @@ -360,7 +355,7 @@ private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, } public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, - org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo) { + SVTGeometry svt_geo, BMTGeometry bmt_geo) { Trajectory traj = new Trajectory(ray); traj.set_Id(id); @@ -607,7 +602,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec * @param stVec stateVec */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, - StateVec stVec, org.jlab.rec.cvt.svt.Geometry svt_geo, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, boolean trajFinal) { + StateVec stVec, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal) { if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); @@ -661,31 +656,19 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi int bsector = cluster.get_Sector(); int blayer = cluster.get_Layer(); - double cxh = Math.cos(cluster.get_Phi())* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - double cyh = Math.sin(cluster.get_Phi())* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double cxh = Math.cos(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); + double cyh = Math.sin(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double phic = bmt_geo.getPhi(new Point3D(cxh,cyh,0), bsector, blayer); double phit = bmt_geo.getPhi(p, sector, blayer); - double doca2Cls = (phic-phit)* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double doca2Cls = (phic-phit)*bmt_geo.getRadiusMidDrift(blayer); cluster.set_CentroidResidual(doca2Cls); for (FittedHit h1 : cluster) { - double xh = Math.cos(h1.get_Strip().get_Phi())* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - double yh = Math.sin(h1.get_Strip().get_Phi())* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double xh = Math.cos(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); + double yh = Math.sin(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double hphic = bmt_geo.getPhi(new Point3D(xh,yh,0), sector, blayer); double hphit = bmt_geo.getPhi(p, sector, blayer); - double doca1 = (hphic-hphit)* - (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[cluster.get_Region() - 1] - + org.jlab.rec.cvt.bmt.Constants.hStrip2Det); + double doca1 = (hphic-hphit)*bmt_geo.getRadiusMidDrift(blayer); if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip()) cluster.set_SeedResidual(doca1); @@ -699,7 +682,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } - private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.BMTGeometry bmt_geo, int start_layer) { + private double[][][] calc_trackIntersBMT(Ray ray, BMTGeometry bmt_geo, int start_layer) { //[l][hemisphere], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip; hemisphere = [1]top or [0]bottom double[][][] result = new double[6][2][7]; @@ -764,7 +747,7 @@ private double[][][] calc_trackIntersBMT(Ray ray, org.jlab.rec.cvt.bmt.BMTGeomet return result; } - private double[][][] calc_trackIntersSVT(Ray ray, org.jlab.rec.cvt.svt.Geometry svt_geo) { + private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { //[l][s], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip double[][][] result = new double[org.jlab.rec.cvt.svt.Constants.NLAYR][org.jlab.rec.cvt.svt.Constants.NSECT[org.jlab.rec.cvt.svt.Constants.NLAYR - 1]][7]; for (int l = 0; l < org.jlab.rec.cvt.svt.Constants.NLAYR; l++) { @@ -828,7 +811,7 @@ private double[][][] calc_trackIntersSVT(Ray ray, org.jlab.rec.cvt.svt.Geometry public double[] getIntersectionTrackWithSVTModule(int s, int l, double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2, org.jlab.rec.cvt.svt.Geometry geo) { + double _yzslope2, SVTGeometry geo) { // array [][][][] =[x][y][z][stripCentroid] double[] inters = new double[4]; inters[0] = Double.NaN; @@ -874,7 +857,7 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, private double[][] getIntersectionTrackWithBMTModules(int l, double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2, org.jlab.rec.cvt.bmt.BMTGeometry geo) { + double _yzslope2, BMTGeometry geo) { // array [][][][] =[x][y][z][stripCentroid] double[][] inters = new double[2][4]; @@ -893,7 +876,7 @@ private double[][] getIntersectionTrackWithBMTModules(int l, int lyer = l+1; - double radius = geo.getRadius(lyer)+org.jlab.rec.cvt.bmt.Constants.hStrip2Det; + double radius = geo.getRadiusMidDrift(lyer); double y_minus = -300; double y_plus = 350; @@ -1042,7 +1025,7 @@ private boolean checkBMTAcceptance(Point3D ipos, int lyer, BMTGeometry geo) { } private List getIntersBMT(int lyer, double radius, double x_minus, double y_minus, double z_minus, - Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation, org.jlab.rec.cvt.bmt.BMTGeometry geo) { + Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation, BMTGeometry geo) { List result = new ArrayList(); Line3D trk = new Line3D(trkOr, trkEn); From 509887f415324327e079158f5bd1c867e27fb9de Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 18 Sep 2021 12:18:36 +0200 Subject: [PATCH 164/291] clas-geometry: added bisect method to Arc3D and fixed axis in Cylindrical3D --- .../src/main/java/org/jlab/geom/prim/Arc3D.java | 6 ++++++ .../java/org/jlab/geom/prim/Cylindrical3D.java | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Arc3D.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Arc3D.java index 4d3b105c9..f32d4f466 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Arc3D.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Arc3D.java @@ -204,6 +204,12 @@ public Point3D point(double t) { return new Point3D(center, v); } + public Vector3D bisect() { + Point3D midpoint = this.point(theta/2); + Vector3D bisect = center.vectorTo(midpoint).asUnit(); + return bisect; + } + @Override public void translateXYZ(double dx, double dy, double dz) { origin.translateXYZ(dx, dy, dz); diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java index 43de3cd38..e4d826f43 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/prim/Cylindrical3D.java @@ -14,7 +14,6 @@ public final class Cylindrical3D implements Face3D { private final Arc3D baseArc = new Arc3D(); private double height; - private final Line3D axis = new Line3D(); /** * Constructs a new {@code Cylindrical3D} such that the arc of the surface * is centered around the z axis, the radius is one, the arc begins at x=1 @@ -76,15 +75,23 @@ public void setArc(Arc3D arc) { * @param axis the base of the cylindrical segment */ public void setAxis(Line3D axis) { - this.axis.copy(axis); + this.baseArc.setCenter(axis.origin()); + this.baseArc.setNormal(axis.originDir()); + this.height = axis.length(); } + /** * returns the axis of this cylinder. + * @return the axis of the cylindrical segment */ public Line3D getAxis() { - return this.axis; + Point3D origin = new Point3D(baseArc.center()); + Vector3D dir = new Vector3D(baseArc.normal()); + dir.setMag(height); + Line3D axis = new Line3D(origin,dir); + return axis; } - + /** * Sets the height of this cylindrical segment. * @param height the height From f759da0ab2282c0a2f118508c1db805a6bc4261a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 18 Sep 2021 16:13:03 +0200 Subject: [PATCH 165/291] CVT: - Refactoring of clusters and strips with inclusion of Transformation3D, primitives, and residual calculation - Use DetectorType and BMType to categorize clusters, strips and hits - Cleanup of geometry, using fixed Cylindrical3D - Define BMT Z crosses based on strip midpoint (relevant to reduce bias in seeding with rotations) - Code cleanups clas-tracking: - Additional strip constructor based on Line3D - Use of Transformation3D --- .../clas/tracking/kalmanfilter/Surface.java | 21 +- .../kalmanfilter/helical/MeasVecs.java | 68 +- .../kalmanfilter/helical/StateVecs.java | 22 +- .../kalmanfilter/straight/MeasVecs.java | 33 +- .../kalmanfilter/straight/StateVecs.java | 27 +- .../org/jlab/clas/tracking/objects/Strip.java | 15 + .../org/jlab/rec/cvt/banks/HitReader.java | 26 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 72 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 1686 +++++++++++++++- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 20 +- .../java/org/jlab/rec/cvt/bmt/Constants.java | 3 + .../java/org/jlab/rec/cvt/bmt/Geometry.java | 1730 ----------------- .../org/jlab/rec/cvt/cluster/Cluster.java | 687 +++---- .../jlab/rec/cvt/cluster/ClusterFinder.java | 4 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 29 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 21 +- .../rec/cvt/cross/HelixCrossListFinder.java | 13 +- .../cross/StraightTrackCrossListFinder.java | 11 +- .../java/org/jlab/rec/cvt/hit/FittedHit.java | 30 +- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 47 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 107 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 4 +- .../rec/cvt/services/CosmicTracksRec.java | 13 +- .../jlab/rec/cvt/services/RecUtilities.java | 263 +-- .../rec/cvt/services/TracksFromTargetRec.java | 5 +- .../java/org/jlab/rec/cvt/track/Cell.java | 3 +- .../java/org/jlab/rec/cvt/track/MakerCA.java | 27 +- .../org/jlab/rec/cvt/track/StraightTrack.java | 5 +- .../rec/cvt/track/StraightTrackSeeder.java | 17 +- .../java/org/jlab/rec/cvt/track/Track.java | 5 +- .../rec/cvt/track/TrackCandListFinder.java | 25 +- .../jlab/rec/cvt/track/TrackListFinder.java | 5 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 17 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 15 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 52 +- 35 files changed, 2312 insertions(+), 2816 deletions(-) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Geometry.java diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java index d110435b1..f0ca3dc3e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -10,6 +10,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Cylindrical3D; +import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; /** @@ -26,8 +27,10 @@ public class Surface implements Comparable { public Point3D finitePlaneCorner1; public Point3D finitePlaneCorner2; public Cylindrical3D cylinder; - public Point3D cylShift; - public Vector3D cylRotation; +// public Point3D cylShift; +// public Vector3D cylRotation; + private Transformation3D toGlobal; + private Transformation3D toLocal; public Arc3D arc; public Strip strip; private double error; @@ -156,6 +159,20 @@ public double getZ_over_A_times_l() { public void setZ_over_A_times_l(double _Z_over_A_times_l) { this._Z_over_A_times_l = _Z_over_A_times_l; } + + public Transformation3D toGlobal() { + return toGlobal; + } + + public Transformation3D toLocal() { + return toLocal; + } + + public void setTransformation(Transformation3D transform) { + this.toGlobal = transform; + this.toLocal = transform.inverse(); + } + public Surface(Cylindrical3D cylinder3d, Arc3D refArc, Point3D endPoint1, Point3D endPoint2) { type = Type.CYLINDERWITHARC; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 6b8c47dd1..26b4f92f0 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -17,6 +17,7 @@ import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; /** @@ -98,16 +99,12 @@ public double dh(int k, StateVec stateVec) { value = stateVec.z-this.measurements.get(stateVec.k).surface.strip.getZ(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Point3D offset =this.measurements.get(stateVec.k).surface.cylShift; - Vector3D rotation = this.measurements.get(stateVec.k).surface.cylRotation; + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); Arc3D arc = new Arc3D(); arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); - this.antiAlignArc(offset, rotation, arc); + toLocal.apply(arc); Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - stV.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - stV.rotateZ(-rotation.z()); - stV.rotateY(-rotation.y()); - stV.rotateX(-rotation.x()); + toLocal.apply(stV); value = stV.z()-arc.center().z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { @@ -118,22 +115,23 @@ public double dh(int k, StateVec stateVec) { } - private void antiAlignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { - Point3D origin = arcline.origin(); - Vector3D normal = arcline.normal(); - Point3D center = arcline.center(); - origin.translateXYZ(-offset.x(),-offset.y(),-offset.z()); - origin.rotateZ(-rotation.z()); - origin.rotateY(-rotation.y()); - origin.rotateX(-rotation.x()); - center.translateXYZ(-offset.x(),-offset.y(),-offset.z()); - center.rotateZ(-rotation.z()); - center.rotateY(-rotation.y()); - center.rotateX(-rotation.x()); - normal.rotateZ(-rotation.z()); - normal.rotateY(-rotation.y()); - normal.rotateX(-rotation.x()); - } +// private void antiAlignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { +// Point3D origin = arcline.origin(); +// Vector3D normal = arcline.normal(); +// Point3D center = arcline.center(); +// origin.translateXYZ(-offset.x(),-offset.y(),-offset.z()); +// origin.rotateZ(-rotation.z()); +// origin.rotateY(-rotation.y()); +// origin.rotateX(-rotation.x()); +// center.translateXYZ(-offset.x(),-offset.y(),-offset.z()); +// center.rotateZ(-rotation.z()); +// center.rotateY(-rotation.y()); +// center.rotateX(-rotation.x()); +// normal.rotateZ(-rotation.z()); +// normal.rotateY(-rotation.y()); +// normal.rotateX(-rotation.x()); +// } + public double getPhiATZ(StateVec stateVec) { Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); @@ -146,15 +144,9 @@ public double getPhiATZ(StateVec stateVec) { } public double getPhi(StateVec stateVec) { - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - - double v = (cln.origin().z()-stateVec.z)/cln.direction().z(); - double xs = stateVec.x+v*cln.direction().x(); - double ys = stateVec.y+v*cln.direction().y(); - - Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). - vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); - return n.phi(); + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + this.measurements.get(stateVec.k).surface.toLocal().apply(sv); + return sv.toVector3D().phi(); } public double h(int k, StateVec stateVec) { @@ -205,14 +197,10 @@ public double h(int k, StateVec stateVec) { value = stateVec.z; } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Point3D offset =this.measurements.get(stateVec.k).surface.cylShift; - Vector3D rotation = this.measurements.get(stateVec.k).surface.cylRotation; - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - stV.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - stV.rotateZ(-rotation.z()); - stV.rotateY(-rotation.y()); - stV.rotateX(-rotation.x()); - value = stV.z(); + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { //value = Math.atan2(stateVec.y, stateVec.x); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 4497a3e24..aae07182b 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -13,6 +13,7 @@ import org.jlab.clas.tracking.kalmanfilter.helical.MeasVecs.MeasVec; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Transformation3D; public class StateVecs { @@ -100,18 +101,10 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } if(mv.surface.cylinder!=null) { - Point3D offset =mv.surface.cylShift; - Vector3D rotation = mv.surface.cylRotation; - - Point3D st = new Point3D(x,y,z); - Point3D stu = new Point3D(u.x(),u.y(),u.z()); - st.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - st.rotateZ(-rotation.z()); - st.rotateY(-rotation.y()); - st.rotateX(-rotation.x()); - stu.rotateZ(-rotation.z()); - stu.rotateY(-rotation.y()); - stu.rotateX(-rotation.x()); + Point3D st = new Point3D(x,y,z); + Vector3D stu = new Vector3D(u.x(),u.y(),u.z()); + mv.surface.toLocal().apply(st); + mv.surface.toLocal().apply(stu); double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(u.x()*stu.x()+stu.y()*stu.y())); @@ -120,10 +113,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim l = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); } Point3D cylInt = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); - cylInt.rotateX(rotation.x()); - cylInt.rotateY(rotation.y()); - cylInt.rotateZ(rotation.z()); - cylInt.translateXYZ(offset.x(), offset.y(), offset.z()); + mv.surface.toGlobal().apply(cylInt); kVec.x = cylInt.x(); kVec.y = cylInt.y(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java index 392530047..9ab21854d 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java @@ -18,6 +18,7 @@ import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; /** @@ -100,21 +101,13 @@ public double dh(int k, StateVec stateVec) { } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Point3D offset =this.measurements.get(stateVec.k).surface.cylShift; - Vector3D rotation = this.measurements.get(stateVec.k).surface.cylRotation; + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); Arc3D arc = new Arc3D(); - arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); - Point3D arccen = arc.center(); - arccen.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - arccen.rotateZ(-rotation.z()); - arccen.rotateY(-rotation.y()); - arccen.rotateX(-rotation.x()); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - stV.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - stV.rotateZ(-rotation.z()); - stV.rotateY(-rotation.y()); - stV.rotateX(-rotation.x()); - value = stV.z()-arccen.z(); + arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); + toLocal.apply(arc); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z()-arc.center().z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { @@ -195,14 +188,10 @@ public double h(int k, StateVec stateVec) { value = stateVec.z; } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Point3D offset =this.measurements.get(stateVec.k).surface.cylShift; - Vector3D rotation = this.measurements.get(stateVec.k).surface.cylRotation; - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - stV.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - stV.rotateZ(-rotation.z()); - stV.rotateY(-rotation.y()); - stV.rotateX(-rotation.x()); - value = stV.z(); + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { //value = Math.atan2(stateVec.y, stateVec.x); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index b04bdcf82..c23378b44 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -102,15 +102,8 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } if(mv.surface.cylinder!=null) { - Point3D offset = mv.surface.cylShift; - Vector3D rotation = mv.surface.cylRotation; - ref.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - ref.rotateZ(-rotation.z()); - ref.rotateY(-rotation.y()); - ref.rotateX(-rotation.x()); - u.rotateZ(-rotation.z()); - u.rotateY(-rotation.y()); - u.rotateX(-rotation.x()); + mv.surface.toLocal().apply(ref); + mv.surface.toLocal().apply(u); double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); double delta = Math.sqrt((ref.x()*u.x()+ref.y()*u.y())*(ref.x()*u.x()+ref.y()*u.y()) -(-r*r+ref.x()*ref.x()+ref.y()*ref.y())*(u.x()*u.x()+u.y()*u.y())); @@ -120,18 +113,10 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } Point3D cylInt = new Point3D(ref.x()+l*u.x(),ref.y()+l*u.y(),ref.z()+l*u.z()); - cylInt.rotateX(rotation.x()); - cylInt.rotateY(rotation.y()); - cylInt.rotateZ(rotation.z()); - cylInt.translateXYZ(offset.x(), offset.y(), offset.z()); - - ref.rotateX(rotation.x()); - ref.rotateY(rotation.y()); - ref.rotateZ(rotation.z()); - ref.translateXYZ(offset.x(), offset.y(), offset.z()); - u.rotateX(rotation.x()); - u.rotateY(rotation.y()); - u.rotateZ(rotation.z()); + mv.surface.toGlobal().apply(cylInt); +// mv.surface.toGlobal().apply(ref); +// mv.surface.toGlobal().apply(u); + kVec.dl = l; kVec.x = cylInt.x(); kVec.y = cylInt.y(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java index 16864f07d..c6a1e6d3f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java @@ -253,6 +253,21 @@ public Strip(int id, double centroid, double x1, double y1, double z1, _c = centroid; type = Type.XYZ; } + + public Strip(int id, double centroid, Line3D line) { + super(id, line.origin().x(), line.origin().y(), line.origin().z()); + Vector3D dir = line.direction().asUnit(); + _x = line.origin().x(); + _y = line.origin().y(); + _z = line.origin().z(); + _ux = dir.x(); + _uy = dir.y(); + _uz = dir.z(); + _length = line.length(); + _c = centroid; + type = Type.XYZ; + } + public Strip(int id, double centroid, double x, double y, double z, double ux, double uy, double uz, double length) { super(id, x, y, z); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index e3972cd57..6ed60a3b2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -3,11 +3,15 @@ import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.hit.ADCConvertor; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; @@ -74,7 +78,7 @@ public void set_SVTHits(List _SVTHits) { * Edep for gemc, adc for cosmics) * @param geo the BMT geometry */ - public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cvt.bmt.BMTGeometry geo, Swim swim) { + public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo, Swim swim) { // return if there is no BMT bank if (event.hasBank("BMT::adc") == false) { @@ -111,7 +115,7 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, org.jlab.rec.cv BmtStrip.calc_BMTStripParams(geo,(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect // create the hit object for detector type BMT - Hit hit = new Hit(1, this.getZorC((int) bankDGTZ.getByte("layer", i)),(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), BmtStrip); + Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(bankDGTZ.getByte("layer", i)),(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), BmtStrip); // a place holder to set the status of the hit, for simulated data if the strip number is in range and the Edep is above threshold the hit has status 1, useable hit.set_Status(1); //if(BmtStrip.get_Edep()==0) @@ -204,10 +208,7 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); Point3D EP2 = geo.transformToFrame(sector[i], layer[i], X[1][0], 0, X[1][1], "lab", ""); - Point3D MP = new Point3D((EP1.x() + EP2.x()) / 2., (EP1.y() + EP2.y()) / 2., (EP1.z() + EP2.z()) / 2.); - Vector3D Dir = new Vector3D((-EP1.x() + EP2.x()), (-EP1.y() + EP2.y()), (-EP1.z() + EP2.z())); - SvtStrip.set_ImplantPoint(EP1); - SvtStrip.set_EndPoint(EP2); + SvtStrip.set_Line(new Line3D(EP1, EP2)); // BMTGeometry implementation using the geometry package: Charles Platt // Line3d shiftedStrip = geo.getStrip(layer[i]-1, sector[i]-1, strip[i]-1); // @@ -223,11 +224,10 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // Point3D passVals = new Point3D(o1.x, o1.y, o1.z); //switch from Vector3d to Point3D // SvtStrip.set_ImplantPoint(passVals); - SvtStrip.set_MidPoint(MP); - SvtStrip.set_StripDir(Dir); + // create the hit object - Hit hit = new Hit(0, -1, sector[i], layer[i], SvtStrip); + Hit hit = new Hit(DetectorType.BST, BMTType.UNDEFINED, sector[i], layer[i], SvtStrip); // if the hit is useable in the analysis its status is 1 hit.set_Status(1); if (SvtStrip.get_Edep() == 0) { @@ -245,13 +245,5 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, this.set_SVTHits(hits); } - // moved this method from geometry here... check for duplicate usages - private int getZorC(int layer) { // 1=Z detector, 0=Cdetector - int axis = 0; - if (layer == 2 || layer == 3 || layer == 5) { - axis = 1; - } - return axis; - } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 81224abcc..8e80206fc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -15,8 +15,8 @@ import org.jlab.rec.cvt.trajectory.StateVec; import Jama.Matrix; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; -import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; public class RecoBankWriter { @@ -85,9 +85,9 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); bank.setShort("size", i, (short) cluslist.get(i).size()); bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); - bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip()); + bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); - bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedEnergy()); + bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); bank.setShort("trkID", i, (short) cluslist.get(i).get_AssociatedTrackID()); @@ -105,12 +105,12 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setShort(hitStrg, i, (short) hitIdxArray[j]); } - bank.setFloat("x1", i, (float)cluslist.get(i).getX1()); - bank.setFloat("y1", i, (float)cluslist.get(i).getY1()); - bank.setFloat("z1", i, (float)cluslist.get(i).getZ1()); - bank.setFloat("x2", i, (float)cluslist.get(i).getX2()); - bank.setFloat("y2", i, (float)cluslist.get(i).getY2()); - bank.setFloat("z2", i, (float)cluslist.get(i).getZ2()); + bank.setFloat("x1", i, (float)cluslist.get(i).origin().x()); + bank.setFloat("y1", i, (float)cluslist.get(i).origin().y()); + bank.setFloat("z1", i, (float)cluslist.get(i).origin().z()); + bank.setFloat("x2", i, (float)cluslist.get(i).end().x()); + bank.setFloat("y2", i, (float)cluslist.get(i).end().y()); + bank.setFloat("z2", i, (float)cluslist.get(i).end().z()); bank.setFloat("lx", i, (float)cluslist.get(i).getL().x()); bank.setFloat("ly", i, (float)cluslist.get(i).getL().y()); bank.setFloat("lz", i, (float)cluslist.get(i).getL().z()); @@ -249,11 +249,11 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); bank.setShort("size", i, (short) cluslist.get(i).size()); bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); - bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip()); + bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); - bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedEnergy()); + bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); bank.setShort("trkID", i, (short) cluslist.get(i).get_AssociatedTrackID()); for (int j = 0; j < cluslist.get(i).size(); j++) { if (j < hitIdxArray.length) { @@ -267,26 +267,22 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { hitStrg += "_ID"; bank.setShort(hitStrg, i, (short) hitIdxArray[j]); } - - bank.setFloat("x1", i, (float)cluslist.get(i).getX1()); - bank.setFloat("y1", i, (float)cluslist.get(i).getY1()); - bank.setFloat("z1", i, (float)cluslist.get(i).getZ1()); - bank.setFloat("x2", i, (float)cluslist.get(i).getX2()); - bank.setFloat("y2", i, (float)cluslist.get(i).getY2()); - bank.setFloat("z2", i, (float)cluslist.get(i).getZ2()); - bank.setFloat("ox", i, (float)cluslist.get(i).getOx()); - bank.setFloat("oy", i, (float)cluslist.get(i).getOy()); - bank.setFloat("oz", i, (float)cluslist.get(i).getOz()); - bank.setFloat("cx", i, (float)cluslist.get(i).getCx()); - bank.setFloat("cy", i, (float)cluslist.get(i).getCy()); - bank.setFloat("cz", i, (float)cluslist.get(i).getCz()); - bank.setFloat("theta",i, (float)cluslist.get(i).getTheta()); - bank.setFloat("ax1", i, (float)cluslist.get(i).getCylAxis().origin().x()); - bank.setFloat("ay1", i, (float)cluslist.get(i).getCylAxis().origin().y()); - bank.setFloat("az1", i, (float)cluslist.get(i).getCylAxis().origin().z()); - bank.setFloat("ax2", i, (float)cluslist.get(i).getCylAxis().end().x()); - bank.setFloat("ay2", i, (float)cluslist.get(i).getCylAxis().end().y()); - bank.setFloat("az2", i, (float)cluslist.get(i).getCylAxis().end().z()); + bank.setFloat("x1", i, (float)cluslist.get(i).origin().x()); + bank.setFloat("y1", i, (float)cluslist.get(i).origin().y()); + bank.setFloat("z1", i, (float)cluslist.get(i).origin().z()); + bank.setFloat("x2", i, (float)cluslist.get(i).end().x()); + bank.setFloat("y2", i, (float)cluslist.get(i).end().y()); + bank.setFloat("z2", i, (float)cluslist.get(i).end().z()); + bank.setFloat("cx", i, (float)cluslist.get(i).center().x()); + bank.setFloat("cy", i, (float)cluslist.get(i).center().y()); + bank.setFloat("cz", i, (float)cluslist.get(i).center().z()); + bank.setFloat("theta",i, (float)cluslist.get(i).theta()); + bank.setFloat("ax1", i, (float)cluslist.get(i).getAxis().origin().x()); + bank.setFloat("ay1", i, (float)cluslist.get(i).getAxis().origin().y()); + bank.setFloat("az1", i, (float)cluslist.get(i).getAxis().origin().z()); + bank.setFloat("ax2", i, (float)cluslist.get(i).getAxis().end().x()); + bank.setFloat("ay2", i, (float)cluslist.get(i).getAxis().end().y()); + bank.setFloat("az2", i, (float)cluslist.get(i).getAxis().end().z()); bank.setFloat("lx", i, (float)cluslist.get(i).getL().x()); bank.setFloat("ly", i, (float)cluslist.get(i).getL().y()); bank.setFloat("lz", i, (float)cluslist.get(i).getL().z()); @@ -297,8 +293,8 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); - if(debug && cluslist.get(i).get_AssociatedTrackID()>0 && cluslist.get(i).get_DetectorType()==1) { - Line3D cln = new Line3D(cluslist.get(i).getEndPoint1(), cluslist.get(i).getEndPoint2()); + if(debug && cluslist.get(i).get_AssociatedTrackID()>0 && cluslist.get(i).get_Type()==BMTType.Z) { + Line3D cln = new Line3D(cluslist.get(i).origin(), cluslist.get(i).end()); System.out.println("Check: N "+cluslist.get(i).getN().toString()+" \n"+ " L "+cluslist.get(i).getL().toString()+" \n"+ " S "+cluslist.get(i).getS().toString()+" \n"+ @@ -462,13 +458,13 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); } // counter to get status word - if(trkcands.get(i).get(j).get_Detector().equalsIgnoreCase("SVT")) + if(trkcands.get(i).get(j).get_Detector()==DetectorType.BST) a++; - if(trkcands.get(i).get(j).get_Detector().equalsIgnoreCase("BMT") - && trkcands.get(i).get(j).get_DetectorType()==BMTType.Z) + if(trkcands.get(i).get(j).get_Detector()==DetectorType.BMT + && trkcands.get(i).get(j).get_Type()==BMTType.Z) b++; - if(trkcands.get(i).get(j).get_Detector().equalsIgnoreCase("BMT") - && trkcands.get(i).get(j).get_DetectorType()==BMTType.C) + if(trkcands.get(i).get(j).get_Detector()==DetectorType.BMT + && trkcands.get(i).get(j).get_Type()==BMTType.C) c++; } bank.setShort("status", i, (short) ((short) 1000+a*100+b*10+c)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 919ec6afb..e238755eb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -1,122 +1,1622 @@ -/* - * 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.rec.cvt.bmt; +import javax.swing.JFrame; +import java.util.ArrayList; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.hit.FittedHit; -import org.jlab.rec.cvt.trajectory.Ray; - +import org.jlab.groot.data.H2F; +import org.jlab.groot.group.DataGroup; +import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; +import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; +import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; +import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Transformation3D; +import org.jlab.groot.data.H1F; +import org.jlab.groot.graphics.EmbeddedCanvasTabbed; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; /** * - * @author ziegler + * @author devita */ -public class BMTGeometry extends Geometry { +public class BMTGeometry { + + private final static int[] lZ = { 2, 3, 5}; + private final static int[] lC = { 1, 4, 6}; + private final static double accuracy = 1E-4; // mm + private final static double udf = -9999; // mm + + /** + * Handles BMT geometry + */ + public BMTGeometry() { + } - public Arc3D getCstrip(int region, int sector, Cluster clus) { - double radius = this.getRadiusMidDrift(this.getLayer(region, BMTType.C)); - double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; - double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; - double z = 0; - double totEn =0; + public int getNLayers() { + return Constants.NLAYERS; + } + + /** + * Return layer number for a given region and detector type + * @param region (1-3) + * @param detector (C or Z) + * @return layer (1-6) + */ + public int getLayer(int region, BMTType detector) { + + if(!(region>=1 && region<=3)) + throw new IllegalArgumentException("Error: invalid region="+region); + if(detector!=BMTType.C && detector!=BMTType.Z) + throw new IllegalArgumentException("Error: invalid detector type"); + + if( detector == BMTType.Z ) { + return lZ[ region - 1 ]; + } + else { + return lC[ region - 1 ]; + } + } + + /** + * Return region number for a given layer + * @param layer (1-6) + * @return region (1-3) + */ + public int getRegion(int layer) { + if(!(layer>=1 && layer<=Constants.NLAYERS)) + throw new IllegalArgumentException("Error: invalid layer="+layer); + + return (int) Math.floor((layer+1)/2); + } + + + /** + * Return region number for a given layer + * @param layer (1-6) + * @return type ("C" or "Z"); + */ + public static BMTType getDetectorType(int layer) { + if(!(layer>=1 && layer<=Constants.NLAYERS)) + throw new IllegalArgumentException("Error: invalid layer="+layer); + + if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; + else return BMTType.Z; + } + + + /** + * Return radius of the selected strip layer + * @param layer (1-6) + * @return radius + */ + public double getRadius(int layer) { + + int region = this.getRegion(layer); + BMTType det = BMTGeometry.getDetectorType(layer); + + if(det == BMTType.C) return Constants.getCRCRADIUS()[region-1]; + else return Constants.getCRZRADIUS()[region-1]; + } + + /** + * Return radius of the selected layer corresponding to the center of the drift gap + * @param layer (1-6) + * @return radius (=0 if layer is out of range) + */ + public double getRadiusMidDrift(int layer) { + return this.getRadius(layer) + Constants.hDrift/2; + } + + /** + * Return number of strips of the selected layer + * @param layer (1-6) + * @return nstrips (=0 if layer is out of range) + */ + public int getNStrips(int layer) { + + int region = this.getRegion(layer); + BMTType det = BMTGeometry.getDetectorType(layer); + + int nstrips = 0; + if (det == BMTType.C) nstrips = Constants.getCRCNSTRIPS()[region-1]; + else if(det == BMTType.Z) nstrips = Constants.getCRZNSTRIPS()[region-1]; + return nstrips; + } + + /** + * Return pitch for the selected layer and strip + * @param layer (1-6) + * @param strip + * @return pitch (=0 if layer is out of range) + */ + public double getPitch(int layer, int strip) { + + int region = this.getRegion(layer); + BMTType det = BMTGeometry.getDetectorType(layer); + + double pitch = 0; + if (det == BMTType.C) pitch = this.getCPitch(region, strip); + else if(det == BMTType.Z) pitch = this.getZPitch(region, strip); + return pitch; + } + + /** + * Return pitch for C strips + * @param region (1-3) + * @param strip + * @return pitch (0 if region or strip are out of range + */ + private double getCPitch(int region, int strip) { + if(!(region>=1 && region<=3)) + throw new IllegalArgumentException("Error: invalid region="+region); + if(!(strip>=1 && strip<=Constants.getCRCNSTRIPS()[region-1])) + throw new IllegalArgumentException("Error: invalid strip="+strip); + + int group = this.getCGroup(region, strip); + double pitch = Constants.getCRCWIDTH()[region-1][group-1]; + return pitch; + } + + /** + * Return pitch for Z strips + * @param region (1-3) + * @param strip + * @return pitch (0 if region or strip are out of range + */ + private double getZPitch(int region, int strip) { + if(!(region>=1 && region<=3)) + throw new IllegalArgumentException("Error: invalid region="+region); + if(!(strip>=1 && strip<=Constants.getCRZNSTRIPS()[region-1])) + throw new IllegalArgumentException("Error: invalid strip="+strip); + + return Constants.getCRZWIDTH()[region-1]; + } + + /** + * Return minimum z of the selected layer in the local frame + * @param layer (1-6) + * @return z (=udf if layer is out of range) + */ + public double getZmin(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = BMTGeometry.getDetectorType(layer); + + if (det == BMTType.C) z = Constants.getCRCZMIN()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMIN()[region-1]; + return z; + } + + /** + * Return maximum z of the selected layer in the local frame + * @param layer (1-6) + * @return z (=udf if layer is out of range) + */ + public double getZmax(int layer) { + + double z = udf; + + int region = this.getRegion(layer); + BMTType det = BMTGeometry.getDetectorType(layer); + + if (det == BMTType.C) z = Constants.getCRCZMAX()[region-1]; + else if(det == BMTType.Z) z = Constants.getCRZZMAX()[region-1]; + return z; + } + + /** + * Return tile phi center + * @param layer (1-6) + * @param sector (1-3) + * @return phi (=udf if layer is out of range) + */ + public double getPhi(int layer, int sector) { + + if(!(00 && layer 0 && sector0 && layer Constants.getCRZNSTRIPS()[region-1]) { + strip = -1; + } + } + return strip; + + } + + public double getPhi(int layer, int sector, Point3D traj) { + Point3D local = this.toLocal(traj, layer, sector); + return local.toVector3D().phi(); + } + /** + * Calculate Theta Lorentz based on solenoid scale and drift settings + * @param layer + * @param sector + * @return thetaL in radians + */ + public double getThetaLorentz(int layer, int sector) { + + if(!(0 strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + for(int j=0; j<5; j++) { + double z = Math.random()*(zmax-zmin)+zmin; + //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; + //double z = oldGeo.CRCStrip_GetZ(i, j); + double phi = Math.random()*2*Math.PI; + //double phi = (1.0*j/500.0)*2*Math.PI; + //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nsect = newGeo.getSector(i, phi); + int nstrip = newGeo.getStrip(i,nsect,traj); + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(i, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; + System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); + } + } + + + System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; + System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); + boolean check = true; + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + int nstrips = newGeo.getNStrips(i); + int region = newGeo.getRegion(i); + for(int k=1; k<=Constants.NSECTORS; k++) { + double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; + double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; + for(int j=1; j<=nstrips; j++) { + + double z = Math.random()*(zmax-zmin)+zmin; + if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); + + double phi = Math.random()*(phmax-phmin)+phmin; + if(newGeo.getDetectorType(i)==BMTType.Z) { + phi = oldGeo.CRZStrip_GetPhi(k, i, j); + } + + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); + int nstrip = newGeo.getStrip(i,k,traj); + + int ostrip = -1; + if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); + else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(i, phi); + int diff = -1; + if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; + if(nstrip!=j) check=false; + if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" + + j + "/" + nstrip + "/" + ostrip + "/" + diff + "\t" + newGeo.getPitch(i, j)); + } + } + } + System.out.println("Check: " + check); + + + System.out.println("\nPlotting acceptance"); + DataGroup acceptance = new DataGroup(3,2); + for(int i=1; i<=Constants.NLAYERS; i++) { + double radius = newGeo.getRadius(i); + double zmin = newGeo.getZmin(i); + double zmax = newGeo.getZmax(i); + H2F hi_acc = new H2F("hi_acc","Layer "+i, 50, -200, 300, 120, 0, 360); + acceptance.addDataSet(hi_acc, i-1); + for(int j=0; j<5000; j++) { + double z = Math.random()*(zmax-zmin)+zmin; + double phi = Math.random()*2*Math.PI; + Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); +// if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); + if(newGeo.getTileSurface(i, newGeo.getSector(i, phi)).isOnSurface(traj)) + hi_acc.fill(z, Math.toDegrees(phi)); + } + } + + DataGroup dgBMT = new DataGroup(4, 3); + for (int i = 0; i < 3; i++) { + int region = i+1; + H2F hiz_res_z = new H2F("hiz_res_z" + region, "BMTZ R" + region, 500, -150, 150, 500, -5, 5); + hiz_res_z.setTitleX("z (cm)"); + hiz_res_z.setTitleY("Residual (mm)"); + H1F hiz_res = new H1F("hiz_res" + region, "BMTZ R" + region, 500, -5, 5); + hiz_res.setTitleX("Residual (mm)"); + hiz_res.setTitleY("Counts"); + H2F hic_res_z = new H2F("hic_res_z" + region, "BMTC R" + region, 500, -150, 150, 500, -5, 5); + hic_res_z.setTitleX("z (cm)"); + hic_res_z.setTitleY("Residual (mm)"); + H1F hic_res = new H1F("hic_res" + region, "BMTC R" + region, 500, -5, 5); + hic_res.setTitleX("Residual (mm)"); + hic_res.setTitleY("Counts"); + dgBMT.addDataSet(hiz_res_z, 0 + i * 4); + dgBMT.addDataSet(hiz_res, 1 + i * 4); + dgBMT.addDataSet(hic_res_z, 2 + i * 4); + dgBMT.addDataSet(hic_res, 3 + i * 4); + } + + + HipoDataSource reader = new HipoDataSource(); + reader.open("/Users/devita/Work/clas12/simulations/bmt/out.rec.hipo"); + while (reader.hasEvent() == true) { + DataEvent event = reader.getNextEvent(); + DataBank bmtADC = null; + DataBank bmtHit = null; + DataBank bmtCluster = null; + DataBank bmtCross = null; + DataBank mcTrue = null; + DataBank mcPart = null; + + if (event.hasBank("BMT::adc")) { + bmtADC = event.getBank("BMT::adc"); + } + if (event.hasBank("BMTRec::Hits")) { + bmtHit = event.getBank("BMTRec::Hits"); + } + if (event.hasBank("BMTRec::Clusters")) { + bmtCluster = event.getBank("BMTRec::Clusters"); + } + if (event.hasBank("BMTRec::Crosses")) { + bmtCross = event.getBank("BMTRec::Crosses"); + } + if (event.hasBank("MC::Particle")) { + mcPart = event.getBank("MC::Particle"); + } + if (event.hasBank("MC::True")) { + mcTrue = event.getBank("MC::True"); + } + + if (bmtCluster != null && bmtHit != null && bmtADC != null && mcPart != null && mcTrue != null) { + Vector3D dir = new Vector3D(mcPart.getFloat("px", 0),mcPart.getFloat("py", 0),mcPart.getFloat("pz", 0)); + Line3D particle = new Line3D(); + particle.set(new Point3D(mcPart.getFloat("vx", 0),mcPart.getFloat("vy", 0),mcPart.getFloat("vz", 0)), dir); + + for (int j = 0; j < bmtHit.rows(); j++) { + int id = bmtHit.getShort("ID", j); + int sector = bmtHit.getByte("sector", j); + int layer = bmtHit.getByte("layer", j); + int strip = bmtHit.getInt("strip", j); + int iclus = bmtHit.getShort("clusterID", j)-1; + int region = newGeo.getRegion(layer); + int seed = bmtCluster.getInt("seedStrip", iclus); + double centroid = bmtCluster.getFloat("centroid", iclus); + + ArrayList trajs = new ArrayList<>(); + newGeo.getTileSurface(layer,sector).intersection(particle, trajs); + if(trajs.size()==0) continue; + // for(Point3D traj : trajs) System.out.println(layer + " " + sector + " " + newGeo.getRadius(layer) + " " + traj.toString()); + + for (int k = 0; k < mcTrue.rows(); k++) { + if (mcTrue.getInt("hitn", k) == id && mcTrue.getByte("detector", k) == DetectorType.BMT.getDetectorId()) { + double xTrue = mcTrue.getFloat("avgX", k); + double yTrue = mcTrue.getFloat("avgY", k); + double zTrue = mcTrue.getFloat("avgZ", k); + Point3D hit = new Point3D(xTrue, yTrue, zTrue); +// Line3D hitR = newGeo.getAxis(layer, sector).distance(hit); +// Line3D hitR = new Line3D(new Point3D(0,0,0), hit); +// hit = hitR.lerpPoint(newGeo.getRadius(layer)/(newGeo.getRadius(layer)+newGeo.getThickness()/2)); + double residual = -newGeo.getResidual(trajs.get(0), layer, sector, seed); + if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { +// Line3D strip = newGeo.getZstrip(region, sector, component); +// Line3D dist = strip.distance(hit); + dgBMT.getH1F("hiz_res" + region).fill(residual); + // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); + dgBMT.getH2F("hiz_res_z" + region).fill(zTrue, residual); + } + else { + dgBMT.getH1F("hic_res" + region).fill(residual); + dgBMT.getH2F("hic_res_z" + region).fill(zTrue, residual); + } + } + } + } + } + } + + JFrame frame = new JFrame("BMT geometry"); + frame.setSize(1200, 800); + EmbeddedCanvasTabbed canvas = new EmbeddedCanvasTabbed("BMT"); + canvas.getCanvas("BMT").draw(dgBMT); + frame.add(canvas); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + + + //added methods: +// public int isInDetector(int layer, double angle, double jitter) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// int num_detector = 2; +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// for (int i = 0; i < 3; i++) { +// +// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; +// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; +// angle_i = Constants.getCRCEDGE1()[num_region][i]; +// angle_f = Constants.getCRCEDGE2()[num_region][i]; +// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { +// num_detector = i; +// } +// } +// +// return num_detector; +// } +// public int isInSector(int layer, double angle, double jitter) { +// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// int value = -1; +// int num_det = this.isInDetector(layer, angle, jitter); +// /* if(num_det == 0) +// value = 2; +// if(num_det ==2) +// value = 3; +// if(num_det == 1) +// value = 1; */ +// value = num_det + 1; +// +// return value; +// } + +// /** +// * +// * @param layer the hit layer +// * @param strip the hit strip +// * @return the z position in mm for the C-detectors +// */ +// public double CRCStrip_GetZ(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// double zc = Constants.getCRCZMIN()[num_region]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// zc += Constants.getCRCWIDTH()[num_region][group]; +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// zc += Constants.getCRCWIDTH()[num_region][group]/2.; +// return zc; //in mm +// } + +// public double CRCStrip_GetPitch(int layer, int strip) { +// +// int num_strip = strip - 1; // index of the strip (starts at 0) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CR6C, this function returns the Z position of the strip center +// int group = 0; +// int limit = Constants.getCRCGROUP()[num_region][group]; +// +// if (num_strip > 0) { +// for (int j = 1; j < num_strip + 1; j++) { +// +// if (j >= limit) { //test if we change the width +// group++; +// limit += Constants.getCRCGROUP()[num_region][group]; +// } +// } +// } +// +// return Constants.getCRCWIDTH()[num_region][group]; // +// } + +// /** +// * +// * @param layer the layer 1...6 +// * @param angle the position angle of the hit in the Z detector +// * @return the Z strip as a function of azimuthal angle +// */ +// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle +// double jitter = Math.toRadians(Constants.isInSectorJitter); +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int num_detector = isInDetector(layer, angle, jitter); +// if (num_detector == -1) { +// return -1; +// } +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// if (num_detector == 1) { +// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; +// if (angle >= 0 && angle <= angle_f) { +// angle += 2 * Math.PI; +// } +// } +// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); +// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); +// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; +// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); +// int strip_num = (int) Math.floor(strip_calc); +// +// int value = strip_num + 1; +// //int value = strip_num; +// +// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { +// value = -1; +// } +// +// return value; +// } + +// public void setLorentzAngle(int layer, int sector) { +// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); +// } +//// // Correct strip position before clustering +//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { +//// +//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); +//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); +//// +//// return this.getZStrip(layer, theLorentzCorrectedAngle); +//// } +// public double LorentzAngleCorr(double phi, int layer) { +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; +// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// } +// +// /** +// * +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating is the track hit is in the fiducial detector +// */ +// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { +// +// boolean isInFid = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; +// +// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit +// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit +// +// double R_i = 0; // inner radius init +// double R_f = 0; // outer radius init for a C or Z detector +// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { +// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer +// } +// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { +// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors +// } +// R_f = R_i + Constants.hDrift; +// +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// double A_i = CRC_GetBeginStrip(sector, layer); +// double A_f = CRC_GetEndStrip(sector, layer); +// angle_i = A_i; +// angle_f = A_f; +// if (A_i > A_f) { // for B-detector +// angle_f = A_i; +// angle_i = A_f; +// } +// // the hit parameters +// double angle = Math.atan2(x[1], x[0]); +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); +// double z = x[2]; +// +// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { +// isInFid = true; +// } +// +// return isInFid; +// } +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the beginning of the strips +// */ +// public double CRC_GetBeginStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the beginning of the strips +// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// +// /** +// * +// * @param sector the sector in CLAS12 1...3 +// * @param layer the layer 1...6 +// * @return the angle to localize the end of the strips +// */ +// public double CRC_GetEndStrip(int sector, int layer) { +// // Sector = num_detector + 1; +// // num_detector = 0 (region A), 1 (region B), 2, (region C) +// +// int num_detector = sector -1; // index of the detector (0...2) +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// +// //For CRC, this function returns the angle to localize the end of the strips +// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// if (angle > 2 * Math.PI) { +// angle -= 2 * Math.PI; +// } +// return angle; //in rad +// } +// /** +// * +// * @param angle +// * @param sector +// * @param layer +// * @param x +// * @return a boolean indicating if the given angle is the sector +// */ +// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { +// if( layer < 1 || layer > 6 ) { +// System.err.println(" BMT layer has to be 1 <= layer <= 6"); +// return false; +// } +// if( sector < 1 || sector > 3 ) { +// System.err.println(" BMT sector has to be 1 <= layer <= 3"); +// return false; +// } +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// double angle_i = 0; // first angular boundary init +// double angle_f = 0; // second angular boundary for detector A, B, or C init +// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; +// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; +// +// +// if (angle < 0) { +// angle += 2 * Math.PI; // from 0 to 2Pi +// } +// +// if( sector == 3 ) { +// if( angle < Math.PI ) { +// if( angle < angle_f + jitter ) return true; +// else return false; +// } +// else { +// if( angle > angle_i - jitter ) return true; +// else return false; +// } +// } +// else { +// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) +// return true; +// else +// return false; +// +// } +// } + +// /** +// * +// * @param layer +// * @param trk_z the track z position of intersection with the C-detector +// * @return the C-strip +// */ +// public int getCStrip(int layer, double trk_z) { +// +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// int strip_group = 0; +// int ClosestStrip = -1; +// // get group +// int len = Constants.getCRCGROUP()[num_region].length; +// double[] Z_lowBound = new double[len]; +// double[] Z_uppBound = new double[len]; +// int[] NStrips = new int[len]; +// +// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; +// double z = trk_z - zi; +// +// for (int i = 0; i < len; i++) { +// if(i==0) { +// Z_lowBound[i] = 0; +// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; +// } +// else { +// Z_lowBound[i] = Z_uppBound[i - 1]; +// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; +// } +// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; +// +// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { +// strip_group = i; +// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); +// if(i>0) ClosestStrip += NStrips[i - 1]; +// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; +// +// len = i; +// } +// } +// return ClosestStrip; +// } +// +// public boolean isInFiducial(double x, double y, double z, int layer) { +// +// boolean isOK = false; +// +// int num_region = (int) (layer + 1) / 2 - 1; +// +// int axis = OldGeometry.getZorC(layer); +// +// double R = 0; +// if (axis == 0) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; +// } +// if (axis == 1) { +// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; +// } +// +// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; +// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; +// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; +// +// double z_min = CRZZMIN + CRZOFFSET; +// double z_max = z_min + CRZLENGTH; +// +// double epsilon = 1e-1; +// +// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { +// isOK = true; +// } +// return isOK; +// } +// +// /** +// * +// * @param layer the layer 1...6 +// * @return the Z position of the strip center +// */ +// private double CRZ_GetZStrip(int layer) { +// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 +// //For CRZ, this function returns the Z position of the strip center +// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; +// return zc; //in mm +// } + + + public void putInFrame(Point3D cent, Point3D offset, Vector3D rotation, boolean inverse) { + if(inverse==false) { + cent.rotateX(rotation.x()); + cent.rotateY(rotation.y()); + cent.rotateZ(rotation.z()); + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + } else { + cent.translateXYZ(offset.x(),offset.y(),offset.z()); + cent.rotateZ(rotation.z()); + cent.rotateY(rotation.y()); + cent.rotateX(rotation.x()); + } + } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 269d62b8e..d2dcf97d2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -3,6 +3,7 @@ import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; /** @@ -295,7 +296,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); - double angle = -0;//Math.toDegrees(0.003); + double angle = -2;//Math.toDegrees(0.003); for (int row = 0; row=1 && region<=3) { - if( detector == BMTType.Z ) { - layer = lZ[ region - 1 ]; - } - else if( detector == BMTType.C ) { - layer = lC[ region - 1 ]; - } - } - else System.out.println("ERROR: out of range region number in getLayer(int region, BMTType detector)"); - return layer; - } - - /** - * Return region number for a given layer - * @param layer (1-6) - * @return region (1-3) - */ - public int getRegion(int layer) { - int region = -1; - if(layer>=1 && layer<=6) { - region = (int) Math.floor((layer+1)/2); - } - else System.out.println("ERROR: out of range layer number in getRegion(int layer)"); - return region; - } - - - /** - * Return region number for a given layer - * @param layer (1-6) - * @return type ("C" or "Z"); - */ - public static BMTType getDetectorType(int layer) { - if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; - else if(layer == lZ[0] || layer == lZ[1] || layer == lZ[2]) return BMTType.Z; - else { - System.out.println("ERROR: out of range layer number in getDetectorType(int layer)"); - return null; - } - } - - - /** - * Return radius of the selected strip layer - * @param layer (1-6) - * @return radius (=0 if layer is out of range) - */ - public double getRadius(int layer) { - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - double radius = 0; - if(region>0 && det!=null) { - if (det == BMTType.C) radius = Constants.getCRCRADIUS()[region-1]; - else if(det == BMTType.Z) radius = Constants.getCRZRADIUS()[region-1]; - } - else System.out.println("ERROR: out of range layer number in getRadius(int layer)"); - return radius; - } - - /** - * Return radius of the selected layer corresponding to the center of the drift gap - * @param layer (1-6) - * @return radius (=0 if layer is out of range) - */ - public double getRadiusMidDrift(int layer) { - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - double radius = 0; - if(region>0 && det!=null) { - if (det == BMTType.C) radius = Constants.getCRCRADIUS()[region-1]; - else if(det == BMTType.Z) radius = Constants.getCRZRADIUS()[region-1]; - } - else System.out.println("ERROR: out of range layer number in getRadius(int layer)"); - radius += Constants.hDrift/2; - return radius; - } - - /** - * Return number of strips of the selected layer - * @param layer (1-6) - * @return nstrips (=0 if layer is out of range) - */ - public int getNStrips(int layer) { - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - int nstrips = 0; - if(region>0 && det!=null) { - if (det == BMTType.C) nstrips = Constants.getCRCNSTRIPS()[region-1]; - else if(det == BMTType.Z) nstrips = Constants.getCRZNSTRIPS()[region-1]; - } - else System.out.println("ERROR: out of range layer number in getNStrips(int layer)"); - return nstrips; - } - - /** - * Return pitch for the selected layer and strip - * @param layer (1-6) - * @param strip - * @return pitch (=0 if layer is out of range) - */ - public double getPitch(int layer, int strip) { - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - double pitch = 0; - if(region>0 && det!=null) { - if (det == BMTType.C) pitch = this.getCPitch(region, strip); - else if(det == BMTType.Z) pitch = this.getZPitch(region, strip); - } - else System.out.println("ERROR: out of range layer number in getNStrips(int layer)"); - return pitch; - } - - /** - * Return pitch for C strips - * @param region (1-3) - * @param strip - * @return pitch (0 if region or strip are out of range - */ - private double getCPitch(int region, int strip) { - double pitch=0; - - if(region>=1 && region<=3) { - if(strip>0 && strip<=Constants.getCRCNSTRIPS()[region-1]) { - int group = this.getCGroup(region, strip); - pitch = Constants.getCRCWIDTH()[region-1][group-1]; - } - else System.out.println("ERROR: out of range strip number in getZPitch(int region, int strip)"); - } - else System.out.println("ERROR: out of range region number in getZPitch(int region, int strip)"); - return pitch; - } - - /** - * Return pitch for Z strips - * @param region (1-3) - * @param strip - * @return pitch (0 if region or strip are out of range - */ - private double getZPitch(int region, int strip) { - double pitch=0; - - if(region>=1 && region<=3) { - if(strip>0 && strip<=Constants.getCRZNSTRIPS()[region-1]) { - pitch = Constants.getCRZWIDTH()[region-1]; - } - else System.out.println("ERROR: out of range strip number in getZPitch(int region, int strip)"); - } - else System.out.println("ERROR: out of range region number in getZPitch(int region, int strip)"); - return pitch; - } - - /** - * Return minimum z of the selected layer in the local frame - * @param layer (1-6) - * @return z (=udf if layer is out of range) - */ - public double getZmin(int layer) { - - double z = udf; - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - if(region>0 && det!=null) { - if (det == BMTType.C) z = Constants.getCRCZMIN()[region-1]; - else if(det == BMTType.Z) z = Constants.getCRZZMIN()[region-1]; - } - else System.out.println("ERROR: out of range layer number in getZmin(int layer)"); - return z; - } - - /** - * Return maximum z of the selected layer in the local frame - * @param layer (1-6) - * @return z (=udf if layer is out of range) - */ - public double getZmax(int layer) { - - double z = udf; - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - if(region>0 && det!=null) { - if (det == BMTType.C) z = Constants.getCRCZMAX()[region-1]; - else if(det == BMTType.Z) z = Constants.getCRZZMAX()[region-1]; - } - else System.out.println("ERROR: out of range layer number in getZmax(int layer)"); - return z; - } - - /** - * Return tile phi center - * @param layer (1-6) - * @param sector (1-3) - * @return phi (=udf if layer is out of range) - */ - public double getPhi(int layer, int sector) { - - double phi = udf; - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - if(region>0 && sector>0 && det!=null) { - if (det == BMTType.C) phi = Constants.getCRCPHI()[region-1][sector-1]; - else if(det == BMTType.Z) phi = Constants.getCRZPHI()[region-1][sector-1]; - } - else System.out.println("ERROR: out of range inputs in getPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); - return phi; - } - - /** - * Return half tile phi coverage - * @param layer (1-6) - * @param sector (1-3) - * @return dz (=udf if layer is out of range) - */ - public double getDPhi(int layer, int sector) { - - double dphi = udf; - - int region = this.getRegion(layer); - BMTType det = this.getDetectorType(layer); - - if(region>0 && sector>0 && det!=null) { - if (det == BMTType.C) dphi = Constants.getCRCDPHI()[region-1][sector-1]; - else if(det == BMTType.Z) dphi = Constants.getCRZDPHI()[region-1][sector-1]; - } - else System.out.println("ERROR: out of range inputs in getDPhi(int layer, int sector)"+" layer "+layer+" sector "+sector); - - return dphi; - } - - /** - * Return thickness of the drift gap - * @return thickness - */ - public double getThickness() { - - return Constants.hDrift; - } - - /** - * Return offset of the selected tile, identified by layer and sector - * @param layer (1-6) - * @param sector (1-3) - * @return Point3D offset: 3D offset - */ - public Point3D getOffset(int layer, int sector) { - Point3D offset = new Point3D(); - if(layer>0 && layer 0 && sector0 && layer 0 && sector0 && layer0 && layer2*Math.PI) dphi -= 2*Math.PI; - else if(dphi<-2*Math.PI) dphi += 2*Math.PI; - return radius*dphi; - } - - /** - * Returns Line3D for Z detector strip identified from region, sector, strip numbers, for ideal geometry - * @param region - * @param sector - * @param strip - * @return Line3D - */ - private Line3D getIdealZstrip(int region, int sector, int strip) { - - double radius = Constants.getCRZRADIUS()[region-1]; - double zmin = Constants.getCRCZMIN()[region-1]; - double zmax = Constants.getCRCZMAX()[region-1]; - double angle = this.getZstripPhi(region,sector,strip); - - Point3D p1= new Point3D(radius, 0, zmin); - p1.rotateZ(angle); - Point3D p2= new Point3D(radius, 0, zmax); - p2.rotateZ(angle); - - Line3D stripline = new Line3D(p1,p2); - - return stripline; - } - - /** - * Returns Line3D for Z detector strip identified from region, sector, strip numbers, for real geometry - * @param region - * @param sector - * @param strip - * @return stripline - */ - public Line3D getZstrip(int region, int sector, int strip) { - - int layer = this.getLayer(region, BMTType.Z); - Line3D stripline = this.getIdealZstrip(region, sector, strip); - - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - stripline.rotateX(rotation.x()); - stripline.rotateY(rotation.y()); - stripline.rotateZ(rotation.z()); - stripline.translateXYZ(offset.x(),offset.y(),offset.z()); - - return stripline; - } - - /** - * Returns Line3D for Z detector pseudostrip identified from region, sector, strip numbers, for ideal geometry - * After Loentz angle correction - * @param region - * @param sector - * @param strip - * @return Line3D - */ - public Line3D getIdealLCZstrip(int region, int sector, int strip, Swim swim) { - - double radius = Constants.getCRZRADIUS()[region-1]; - int layer = this.getLayer(region, BMTType.Z); - double zmin = Constants.getCRCZMIN()[region-1]; - double zmax = Constants.getCRCZMAX()[region-1]; - double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] - + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / radius ; -// double theLorentzCorrectedAngle = angle + this.LorentzAngleCorr(layer,sector); - Point3D p1= new Point3D(radius, 0, zmin); - p1.rotateZ(angle); - Point3D p2= new Point3D(radius, 0, zmax); - p2.rotateZ(angle); - Line3D stripline = new Line3D(p1,p2); - double x = stripline.midpoint().x(); - double y = stripline.midpoint().y(); - double z = stripline.midpoint().z(); - - double alpha = this.getThetaLorentz(layer, sector, x,y,z,swim); - double ralpha = Math.atan2(this.getThickness()/2*Math.tan(alpha), this.getRadiusMidDrift(layer)); - Point3D np1= new Point3D(this.getRadiusMidDrift(layer) * Math.cos(ralpha), - this.getRadiusMidDrift(layer) * Math.sin(ralpha), zmin); - Point3D np2= new Point3D(this.getRadiusMidDrift(layer) * Math.cos(ralpha), - this.getRadiusMidDrift(layer) * Math.sin(ralpha), zmax); - np1.rotateZ(angle); - np2.rotateZ(angle); - - Line3D nstripline = new Line3D(np1,np2); - return nstripline; - } - - /** - * Returns Line3D for Z detector pseudo-strip identified from region, sector, strip numbers, for real geometry - * After Lorentz angle correction - * @param region - * @param sector - * @param strip - * @return stripline - */ - public Line3D getLCZstrip(int region, int sector, int strip, Swim swim) { - - int layer = this.getLayer(region, BMTType.Z); - Line3D stripline = this.getIdealLCZstrip(region, sector, strip, swim); - - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - stripline.rotateX(rotation.x()); - stripline.rotateY(rotation.y()); - stripline.rotateZ(rotation.z()); - stripline.translateXYZ(offset.x(),offset.y(),offset.z()); - - - return stripline; - } - - /** - * @param region - * @param sector - * @param strip - * @return the phi angle of the strip center in radians - */ - public double getZstripPhi(int region, int sector, int strip) { - double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] - + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; - return angle; //in rad - } - - /** - * Return the C detector strip group - * @param region [1-3] - * @param strip - * @return group [1-...] - */ - private int getCGroup(int region, int strip) { - int group = 0; - if(strip>0 && strip<=Constants.getCRCNSTRIPS()[region-1]) { - for(int i=0; iConstants.getCRCZMIN()[region-1] && zConstants.getCRCGRPZMIN()[region-1][i] && z0) { - double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; // group minimum z - double pitch = Constants.getCRCWIDTH()[region-1][group-1]; // group pitch - int nmin = Constants.getCRCGRPNMIN()[region-1][group-1]; - z = zmin + (strip - nmin + 0.5) * pitch ; - } - return z; - } - - /** - * Returns Arc3D corresponding to the selected C-detector strip according to ideal geometry (local frame) - * @param region (1-3) - * @param sector (1-3) - * @param strip - * @return Arc3D striparc - */ - private Arc3D getIdealCstrip(int region, int sector, int strip) { - - double radius = Constants.getCRCRADIUS()[region-1]; - double angle = Constants.getCRCPHI()[region-1][sector-1] - Constants.getCRCDPHI()[region-1][sector-1]; - double theta = Constants.getCRCDPHI()[region-1][sector-1]*2; - double z = this.getCstripZ(region, strip); - - Point3D origin = new Point3D(radius,0,z); - origin.rotateZ(angle); - Point3D center = new Point3D(0,0,z); - Vector3D normal = new Vector3D(0,0,1); - - Arc3D striparc = new Arc3D(origin,center,normal,theta); - return striparc; - } - - /** - * Returns Arc3D corresponding to the selected C-detector strip according to real geometry - * @param region - * @param sector - * @param strip - * @return - */ - public Arc3D getCstrip(int region, int sector, int strip) { - - int layer = this.getLayer(region, BMTType.C); - Arc3D arcline = this.getIdealCstrip(region, sector, strip); - - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - arcline.rotateX(rotation.x()); - arcline.rotateY(rotation.y()); - arcline.rotateZ(rotation.z()); - arcline.translateXYZ(offset.x(),offset.y(),offset.z()); - - return arcline; - } - - public void alignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { - Point3D origin = arcline.origin(); - Vector3D normal = arcline.normal(); - Point3D center = arcline.center(); - origin.rotateX(rotation.x()); - origin.rotateY(rotation.y()); - origin.rotateZ(rotation.z()); - origin.translateXYZ(offset.x(),offset.y(),offset.z()); - center.rotateX(rotation.x()); - center.rotateY(rotation.y()); - center.rotateZ(rotation.z()); - center.translateXYZ(offset.x(),offset.y(),offset.z()); - normal.rotateX(rotation.x()); - normal.rotateY(rotation.y()); - normal.rotateZ(rotation.z()); - } - - public void antiAlignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { - Point3D origin = arcline.origin(); - Vector3D normal = arcline.normal(); - Point3D center = arcline.center(); - origin.translateXYZ(offset.x(),offset.y(),offset.z()); - origin.rotateZ(rotation.z()); - origin.rotateY(rotation.y()); - origin.rotateX(rotation.x()); - center.translateXYZ(offset.x(),offset.y(),offset.z()); - center.rotateZ(rotation.z()); - center.rotateY(rotation.y()); - center.rotateX(rotation.x()); - normal.rotateZ(rotation.z()); - normal.rotateY(rotation.y()); - normal.rotateX(rotation.x()); - } - - - /** - * - * @param layer - * @param sector - * @return rotated cylinder corresponding to the BMT surface - */ - public Cylindrical3D getCylinder(int layer, int sector) { - Cylindrical3D cyl = new Cylindrical3D(); - - Point3D cent = new Point3D(0, 0, 0); - Vector3D norm = new Vector3D(0,1,0); - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - cent.rotateX(rotation.x()); - cent.rotateY(rotation.y()); - cent.rotateZ(rotation.z()); - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - norm.rotateX(rotation.x()); - norm.rotateY(rotation.y()); - norm.rotateZ(rotation.z()); - - cyl.baseArc().setCenter(cent); - cyl.highArc().setCenter(cent); - cyl.baseArc().setNormal(norm); - cyl.highArc().setNormal(norm); - - - - return cyl; - } - - public Cylindrical3D getSurface(int layer, int sector) { - double phMin = this.getPhi(layer, sector)-this.getDPhi(layer, sector); - double radius = this.getRadius(layer)+this.getThickness()/2; - Point3D origin = new Point3D(radius*Math.cos(phMin), - radius*Math.sin(phMin), - this.getZmin(layer)); - Point3D center = new Point3D(0,0,this.getZmin(layer)); - Vector3D axis = new Vector3D(0,0,1); - Arc3D base = new Arc3D(origin, center, axis, 2*this.getDPhi(layer, sector)); - Cylindrical3D surface = new Cylindrical3D(base, this.getZmax(layer)-this.getZmin(layer)); - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - surface.rotateX(rotation.x()); - surface.rotateY(rotation.y()); - surface.rotateZ(rotation.z()); - surface.translateXYZ(offset.x(), offset.y(), offset.z()); - return surface; - } - - /** - * Return the sector number - * @param layer [0-6] - * @param angle angle in the local frame in radians - * @return sector [1-3] (not) accounting for dead areas if layer (0) [1-6] or 0 if layer is undefined - */ - public int getSector(int layer, double angle) { - boolean full = false; - if(layer==0) { - full = true; - layer = 1; - } - int region = this.getRegion(layer); - - Vector3D vec = new Vector3D(Math.cos(angle),Math.sin(angle),0); - if(Double.isNaN(angle)) vec = null; - int sector = 0; - double width = 0.5; // Math.cos(60deg); - double delta = -1; - for (int i = 0; i < Constants.NSECTORS; i++) { - double phi = this.getPhi(layer, i+1); - Vector3D center = new Vector3D(Math.cos(phi),Math.sin(phi),0); - double dcosphi = center.dot(vec); - if(dcosphi>width) { - delta = dcosphi; - sector = i+1; - } - } - if(!full) { - if(sector!=0) - if(delta0 && layer<=Constants.NLAYERS && sector>0 && sector<=Constants.NSECTORS) { - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - traj.rotateZ(-rotation.z()); - traj.rotateY(-rotation.y()); - traj.rotateX(-rotation.x()); - if(traj.z()>this.getZmin(layer) && traj.z()Math.cos(this.getDPhi(layer, sector))) in=true; - } - } - return in; - } - - /** - * Checks whether a trajectory point is within the active area of a tile - * @param traj - * @return true/false - */ - public int getStrip(Point3D traj, double strip2Det) { - int strip = 0; - int layer = getLayer(traj, strip2Det); - int sector = getSector(layer,Math.atan2(traj.y(), traj.x())); - if(layer>0 && sector>0) strip = getStrip(layer,sector,traj); - return strip; - } - - - /** - * Return the number of the closest strip to the given trajectory point - * Detector mis-alignments geometry are taken into account by transforming - * the trajectory point to detector local frame - * @param layer (1-6) - * @param sector (1-3) - * @param traj trajectory point on the layer surface in the lab - * @return strip number (0 if the point is not within the active area) - */ - public int getStrip(int layer, int sector, Point3D traj) { - int strip= 0; - if(layer>0 && layer<=Constants.NLAYERS && sector>0 && sector<=Constants.NSECTORS) { - Point3D offset = this.getOffset(layer, sector); - Vector3D rotation = this.getRotation(layer, sector); - traj.translateXYZ(-offset.x(), -offset.y(), -offset.z()); - traj.rotateZ(-rotation.z()); - traj.rotateY(-rotation.y()); - traj.rotateX(-rotation.x()); - strip = this.getStripLocal(layer, traj); - } - return strip; - } - - /** - * Return the number of the closest strip to the given trajectory point - * in the detector local frame - * @param layer (1-6) - * @param traj trajectory point on the layer surface in the local frame - * @return strip number (0 if the point is not within the active area) - */ - private int getStripLocal(int layer, Point3D traj) { - - BMTType type = this.getDetectorType(layer); - int region = this.getRegion(layer); - switch (type) { - case C: - return this.getCstrip(region,traj); - case Z: - return this.getZstrip(region,traj); - default: - return 0; - } - } - - /** - * Return the number of the closest strip to the given trajectory point - * in the detector local frame - * @param region (1-3) - * @param traj trajectory point on the layer surface in the local frame - * @return strip number (0 if the point is not within the active area) - */ - public int getCstrip(int region, Point3D traj) { - - int strip = 0; - - int group = getCGroup(region, traj.z()); - if(group>0) { - double zmin = Constants.getCRCGRPZMIN()[region-1][group-1]; - double pitch = Constants.getCRCWIDTH()[region-1][group-1]; - strip = (int) Math.floor((traj.z()-zmin)/pitch); - if(group>0) strip += Constants.getCRCGRPNMIN()[region-1][group-1]; - } - return strip; - } - - /** - * Return the number of the closest strip to the given trajectory point - * in the detector local frame - * @param region (1-3) - * @param traj trajectory point on the layer surface in the local frame - * @return strip number (0 if the point is not within the active area) - */ - public int getZstrip(int region, Point3D traj) { - - int strip = 0; - - int layer = getLayer(region, BMTType.Z); - - double angle = Math.atan2(traj.y(), traj.x()); - if(angle<0) angle += 2*Math.PI; - - int sector = getSector(layer,angle); - if(sector>=1 && sector <=Constants.NSECTORS) { - // CHECKME - double edge = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1]; // 30 150 270 - double pitch = Constants.getCRZWIDTH()[region-1]; - double radius = Constants.getCRZRADIUS()[region-1]; - double dphi = angle - edge; - if(dphi<0) dphi += 2*Math.PI; - strip = (int) Math.floor(dphi*radius/pitch) + 1; -// System.out.println(Math.toDegrees(angle) + " " + Math.toDegrees(dphi) + " " + sector + " " + strip_calc); - if (strip < 1 || strip > Constants.getCRZNSTRIPS()[region-1]) { - strip = -1; - } - } - return strip; - - } - - /** - * Calculate Theta Lorentz based on solenoid scale and drift settings - * @param layer - * @param sector - * @return thetaL in radians - */ - public double getThetaLorentz(int layer, int sector) { - - double thetaL = 0; - - double solenoidScale = org.jlab.rec.cvt.Constants.getSolenoidscale(); - - if(Math.abs(solenoidScale)<0.001) { - thetaL = 0; - } - else { - if(Math.abs(solenoidScale)<0.8) { - thetaL = Math.toRadians(getLorentzAngle(E_DRIFT_MF[layer-1][sector-1],Math.abs(solenoidScale*50))); - } else { - thetaL = Math.toRadians(getLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(solenoidScale*50))); - } - } - if (solenoidScale<0) thetaL=-thetaL; - return thetaL; - } - - /** - * Calculate Theta Lorentz based on solenoid scale and drift settings - * @param layer - * @param sector - * @return thetaL in radians - */ - public double getThetaLorentz(int layer, int sector, double x, double y, double z, Swim swim) { - - double thetaL = 0; - float[] b = new float[3]; - swim.BfieldLab(x/10, y/10, z/10, b); - double EDrift=0; - if(Constants.isMC == true) { - EDrift = 5000*Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()); - } else { - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { - EDrift = Constants.E_DRIFT_MF[layer-1][sector-1]; - } else { - EDrift = Constants.E_DRIFT_FF[layer-1][sector-1]; - } - } - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001) { - thetaL = 0; - } - else { - thetaL = Math.toRadians(getLorentzAngle(EDrift,Math.abs(b[2]*10))); - } - if (org.jlab.rec.cvt.Constants.getSolenoidscale()<0) thetaL=-thetaL; - return thetaL; - } - - - /** - * Calculate Lorentz angle correction - * @param layer - * @param sector - * @return - */ - public double LorentzAngleCorr(int layer, int sector) { - return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); - } - - - /** - * Executable method: implements checks - * @param arg - */ - public static void main (String arg[]) { - - CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, "default")); - - OldGeometry oldGeo = new OldGeometry(); - BMTGeometry newGeo = new BMTGeometry(); - - System.out.println("\nLayer number for region and detector type:"); - System.out.println("\tRegion\tType\tLayer"); - for(int i=1; i<=Constants.NREGIONS; i++) { - System.out.println("\t" + i + "\t" + newGeo.getLayer(i, BMTType.C) + "\t" + newGeo.getLayer(i, BMTType.Z)); - } - - System.out.println("\nDetector information by layer:"); - System.out.println("\tLayer\tRegion\tType\tRadius(mm)\tThickness(mm)\tZmin(mm)\tZmax(mm)\tNNstrips"); - for(int i=1; i<=Constants.NLAYERS; i++) { - System.out.println("\t" + i + "\t" + newGeo.getRegion(i) + "\t" + newGeo.getDetectorType(i) - + "\t" + newGeo.getRadius(i) + "\t\t" + newGeo.getThickness() - + "\t\t" + newGeo.getZmin(i) + "\t\t" + newGeo.getZmax(i) - + "\t\t" + newGeo.getNStrips(i) - ); - } - - System.out.println("\nOffsets and Rotations"); - System.out.println("\tLayer\tSector\tOffset and Rotation"); - for(int i=1; i<=Constants.NLAYERS; i++) { - for(int j=1; j<=Constants.NSECTORS; j++) { - System.out.println("\t" + i + "\t" + j + "\t" + newGeo.getOffset(i, j).toString() + "\t" + newGeo.getRotation(i, j).toString()); - } - } - - System.out.println("\n\nC strip geometry check: z (mm), begin and end phi angles (radians)"); - System.out.println("\tRegion\tSector\tStrip\tZ\t\t\t\tBegin phi\t\tEnd phi"); - System.out.println("\t \t \t \tNew/Old/Comp \t\t\tNew/Old/Comp \t\tNew/Old/Comp"); - for(int i=1; i<=Constants.NREGIONS; i++) { - for(int k=1; k<=Constants.NSECTORS; k++) { - for(int j=1; j<=Constants.getCRCNSTRIPS()[i-1]; j++) { - // z - double ngeo = newGeo.getCstrip(i, 1, j).center().z(); - double ogeo = oldGeo.CRCStrip_GetZ(newGeo.getLayer(i, BMTType.C),j); - String snew = String.format("%.4f", ngeo); - String sold = String.format("%.4f", ogeo); - String scom = String.format("%.4f", ngeo-ogeo); - // begin angle - double ngeo1 = Math.atan2(newGeo.getCstrip(i, k, j).origin().y(),newGeo.getCstrip(i, k, j).origin().x()); - if(ngeo1<0) ngeo1 += 2*Math.PI; - double ogeo1 = oldGeo.CRC_GetBeginStrip(k, newGeo.getLayer(i, BMTType.C)); - String snew1 = String.format("%.4f", ngeo1); - String sold1 = String.format("%.4f", ogeo1); - String scom1 = String.format("%.4f", ngeo1-ogeo1); - // end angle - double ngeo2 = Math.atan2(newGeo.getCstrip(i, k, j).end().y(),newGeo.getCstrip(i, k, j).end().x()); - if(ngeo2<0) ngeo2 += 2*Math.PI; - double ogeo2 = oldGeo.CRC_GetEndStrip(k, newGeo.getLayer(i, BMTType.C)); - String snew2 = String.format("%.4f", ngeo2); - String sold2 = String.format("%.4f", ogeo2); - String scom2 = String.format("%.4f", ngeo2-ogeo2); - if(j==1 || j==Constants.getCRCNSTRIPS()[i-1]) - System.out.println("\t" + i + "\t" + k + "\t" + j + "\t" + snew + "/" + sold + "/" + scom + "\t" + snew1 + "/" + sold1 + "/" + scom1 + "\t" + snew2 + "/" + sold2 + "/" + scom2); - } - } - } - - - System.out.println("\n\nZ strip geometry check: phi (radians), begin and end z (mm)"); - System.out.println("\tRegion\tSector\tStrip\tphi\t\t\tBegin Z\t\t\t\tEnd Z"); - System.out.println("\t \t \t \tNew/Old/Comp \t\tNew/Old/Comp \t\t\tNew/Old/Comp"); - for(int i=1; i<=Constants.NREGIONS; i++) { - for(int k=1; k<=Constants.NSECTORS; k++) { - for(int j=1; j<=Constants.getCRZNSTRIPS()[i-1]; j++) { - // phi - double ngeo = Math.atan2(newGeo.getZstrip(i, k, j).origin().y(), newGeo.getZstrip(i, k, j).origin().x()); - if(ngeo<0) ngeo += 2*Math.PI; - double ogeo = oldGeo.CRZStrip_GetPhi(k, newGeo.getLayer(i, BMTType.Z), j)%(2*Math.PI); - String snew = String.format("%.4f", ngeo); - String sold = String.format("%.4f", ogeo); - String scom = String.format("%.4f", ngeo-ogeo); - // begin z - double ngeo1 = newGeo.getZstrip(i, k, j).origin().z(); - double ogeo1 = Constants.getCRCZMIN()[i-1]; - String snew1 = String.format("%.4f", ngeo1); - String sold1 = String.format("%.4f", ogeo1); - String scom1 = String.format("%.4f", ngeo1-ogeo1); - // end z - double ngeo2 = newGeo.getZstrip(i, k, j).end().z(); - double ogeo2 = Constants.getCRCZMAX()[i-1]; - String snew2 = String.format("%.4f", ngeo2); - String sold2 = String.format("%.4f", ogeo2); - String scom2 = String.format("%.4f", ngeo2-ogeo2); - if(j==1 || j==Constants.getCRZNSTRIPS()[i-1]) { - System.out.println("\t" + i + "\t" + k + "\t" + j + "\t" + snew + "/" + sold + "/" + scom + "\t" + snew1 + "/" + sold1 + "/" + scom1 + "\t" + snew2 + "/" + sold2 + "/" + scom2); - System.out.println(newGeo.getZstrip(i, k, j).origin().toString() + " " + newGeo.getZstrip(i, k, j).end().toString()); - } - } - } - } - - - System.out.println("\n\n Trajectory -> strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - for(int j=0; j<5; j++) { - double z = Math.random()*(zmax-zmin)+zmin; - //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; - //double z = oldGeo.CRCStrip_GetZ(i, j); - double phi = Math.random()*2*Math.PI; - //double phi = (1.0*j/500.0)*2*Math.PI; - //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nsect = newGeo.getSector(i, phi); - int nstrip = newGeo.getStrip(i,nsect,traj); - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; - System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); - } - } - - - System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - boolean check = true; - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - int nstrips = newGeo.getNStrips(i); - int region = newGeo.getRegion(i); - for(int k=1; k<=Constants.NSECTORS; k++) { - double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; - double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; - for(int j=1; j<=nstrips; j++) { - - double z = Math.random()*(zmax-zmin)+zmin; - if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); - - double phi = Math.random()*(phmax-phmin)+phmin; - if(newGeo.getDetectorType(i)==BMTType.Z) { - phi = oldGeo.CRZStrip_GetPhi(k, i, j); - } - - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nstrip = newGeo.getStrip(i,k,traj); - - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; - if(nstrip!=j) check=false; - if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" - + j + "/" + nstrip + "/" + ostrip + "/" + diff + "\t" + newGeo.getPitch(i, j)); - } - } - } - System.out.println("Check: " + check); - - - System.out.println("\nPlotting acceptance"); - DataGroup acceptance = new DataGroup(3,2); - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - H2F hi_acc = new H2F("hi_acc","Layer "+i, 50, -200, 300, 120, 0, 360); - acceptance.addDataSet(hi_acc, i-1); - for(int j=0; j<5000; j++) { - double z = Math.random()*(zmax-zmin)+zmin; - double phi = Math.random()*2*Math.PI; - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); -// if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); - if(newGeo.inDetector(i, newGeo.getSector(i, phi), traj)) - hi_acc.fill(z, Math.toDegrees(phi)); - } - } - - DataGroup dgBMT = new DataGroup(4, 3); - for (int i = 0; i < 3; i++) { - int region = i+1; - H2F hiz_res_z = new H2F("hiz_res_z" + region, "BMTZ R" + region, 500, -150, 150, 500, -5, 5); - hiz_res_z.setTitleX("z (cm)"); - hiz_res_z.setTitleY("Residual (mm)"); - H1F hiz_res = new H1F("hiz_res" + region, "BMTZ R" + region, 500, -5, 5); - hiz_res.setTitleX("Residual (mm)"); - hiz_res.setTitleY("Counts"); - H2F hic_res_z = new H2F("hic_res_z" + region, "BMTC R" + region, 500, -150, 150, 500, -5, 5); - hic_res_z.setTitleX("z (cm)"); - hic_res_z.setTitleY("Residual (mm)"); - H1F hic_res = new H1F("hic_res" + region, "BMTC R" + region, 500, -5, 5); - hic_res.setTitleX("Residual (mm)"); - hic_res.setTitleY("Counts"); - dgBMT.addDataSet(hiz_res_z, 0 + i * 4); - dgBMT.addDataSet(hiz_res, 1 + i * 4); - dgBMT.addDataSet(hic_res_z, 2 + i * 4); - dgBMT.addDataSet(hic_res, 3 + i * 4); - } - - Vector3D dir = new Vector3D(0,Math.sin(Math.toRadians(60)),Math.cos(Math.toRadians(60))); - Line3D particle = new Line3D(); - particle.set(new Point3D(0,0,0), dir); - - HipoDataSource reader = new HipoDataSource(); - reader.open("/Users/devita/Work/clas12/simulations/bmt/out.rec.hipo"); - while (reader.hasEvent() == true) { - DataEvent event = reader.getNextEvent(); - DataBank bmtADC = null; - DataBank bmtHit = null; - DataBank bmtCluster = null; - DataBank bmtCross = null; - DataBank mcTrue = null; - - if (event.hasBank("BMT::adc")) { - bmtADC = event.getBank("BMT::adc"); - } - if (event.hasBank("BMTRec::Hits")) { - bmtHit = event.getBank("BMTRec::Hits"); - } - if (event.hasBank("BMTRec::Clusters")) { - bmtCluster = event.getBank("BMTRec::Clusters"); - } - if (event.hasBank("BMTRec::Crosses")) { - bmtCross = event.getBank("BMTRec::Crosses"); - } - if (event.hasBank("MC::True")) { - mcTrue = event.getBank("MC::True"); - } - - if (bmtCluster != null && bmtHit != null && bmtADC != null && mcTrue != null) { - for (int j = 0; j < bmtHit.rows(); j++) { - int id = bmtHit.getShort("ID", j); - int sector = bmtHit.getByte("sector", j); - int layer = bmtHit.getByte("layer", j); - int strip = bmtHit.getInt("strip", j); - int iclus = bmtHit.getShort("clusterID", j)-1; - int region = newGeo.getRegion(layer); - int seed = bmtCluster.getInt("seedStrip", iclus); - double centroid = bmtCluster.getFloat("centroid", iclus); - - ArrayList trajs = new ArrayList<>(); - newGeo.getSurface(layer,sector).intersection(particle, trajs); - if(trajs.size()==0) continue; - // for(Point3D traj : trajs) System.out.println(layer + " " + sector + " " + newGeo.getRadius(layer) + " " + traj.toString()); - - for (int k = 0; k < mcTrue.rows(); k++) { - if (mcTrue.getInt("hitn", k) == id && mcTrue.getByte("detector", k) == DetectorType.BMT.getDetectorId()) { - double xTrue = mcTrue.getFloat("avgX", k); - double yTrue = mcTrue.getFloat("avgY", k); - double zTrue = mcTrue.getFloat("avgZ", k); - Point3D hit = new Point3D(xTrue, yTrue, zTrue); -// Line3D hitR = newGeo.getAxis(layer, sector).distance(hit); -// Line3D hitR = new Line3D(new Point3D(0,0,0), hit); -// hit = hitR.lerpPoint(newGeo.getRadius(layer)/(newGeo.getRadius(layer)+newGeo.getThickness()/2)); - double residual = -newGeo.getResidual(trajs.get(0), layer, sector, seed); - if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { -// Line3D strip = newGeo.getZstrip(region, sector, component); -// Line3D dist = strip.distance(hit); - dgBMT.getH1F("hiz_res" + region).fill(residual); - // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); - dgBMT.getH2F("hiz_res_z" + region).fill(zTrue, residual); - } - else { - dgBMT.getH1F("hic_res" + region).fill(residual); - dgBMT.getH2F("hic_res_z" + region).fill(zTrue, residual); - } - } - } - } - } - } - - JFrame frame = new JFrame("BMT geometry"); - frame.setSize(1200, 800); - EmbeddedCanvasTabbed canvas = new EmbeddedCanvasTabbed("BMT"); - canvas.getCanvas("BMT").draw(dgBMT); - frame.add(canvas); - frame.setLocationRelativeTo(null); - frame.setVisible(true); - } - - - - //added methods: -// public int isInDetector(int layer, double angle, double jitter) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// int num_detector = 2; -// //double jitter = Math.toRadians(Constants.isInSectorJitter); -// for (int i = 0; i < 3; i++) { -// -// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; -// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; -// angle_i = Constants.getCRCEDGE1()[num_region][i]; -// angle_f = Constants.getCRCEDGE2()[num_region][i]; -// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { -// num_detector = i; -// } -// } -// -// return num_detector; -// } -// public int isInSector(int layer, double angle, double jitter) { -// //double jitter = Math.toRadians(Constants.isInSectorJitter); -// int value = -1; -// int num_det = this.isInDetector(layer, angle, jitter); -// /* if(num_det == 0) -// value = 2; -// if(num_det ==2) -// value = 3; -// if(num_det == 1) -// value = 1; */ -// value = num_det + 1; -// -// return value; -// } - -// /** -// * -// * @param layer the hit layer -// * @param strip the hit strip -// * @return the z position in mm for the C-detectors -// */ -// public double CRCStrip_GetZ(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; -// double zc = Constants.getCRCZMIN()[num_region]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// zc += Constants.getCRCWIDTH()[num_region][group]; -// if (j >= limit) { //test if we change the width -// group++; -// limit += Constants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// zc += Constants.getCRCWIDTH()[num_region][group]/2.; -// return zc; //in mm -// } - -// public double CRCStrip_GetPitch(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// -// if (j >= limit) { //test if we change the width -// group++; -// limit += Constants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// -// return Constants.getCRCWIDTH()[num_region][group]; // -// } - -// /** -// * -// * @param layer the layer 1...6 -// * @param angle the position angle of the hit in the Z detector -// * @return the Z strip as a function of azimuthal angle -// */ -// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle -// double jitter = Math.toRadians(Constants.isInSectorJitter); -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int num_detector = isInDetector(layer, angle, jitter); -// if (num_detector == -1) { -// return -1; -// } -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// if (num_detector == 1) { -// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; -// if (angle >= 0 && angle <= angle_f) { -// angle += 2 * Math.PI; -// } -// } -// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); -// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); -// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; -// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); -// int strip_num = (int) Math.floor(strip_calc); -// -// int value = strip_num + 1; -// //int value = strip_num; -// -// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { -// value = -1; -// } -// -// return value; -// } - -// public void setLorentzAngle(int layer, int sector) { -// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); -// } -//// // Correct strip position before clustering -//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { -//// -//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); -//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); -//// -//// return this.getZStrip(layer, theLorentzCorrectedAngle); -//// } -// public double LorentzAngleCorr(double phi, int layer) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; -// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); -// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); -// } -// -// /** -// * -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating is the track hit is in the fiducial detector -// */ -// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { -// -// boolean isInFid = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; -// -// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit -// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit -// -// double R_i = 0; // inner radius init -// double R_f = 0; // outer radius init for a C or Z detector -// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { -// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer -// } -// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { -// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors -// } -// R_f = R_i + Constants.hDrift; -// -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// double A_i = CRC_GetBeginStrip(sector, layer); -// double A_f = CRC_GetEndStrip(sector, layer); -// angle_i = A_i; -// angle_f = A_f; -// if (A_i > A_f) { // for B-detector -// angle_f = A_i; -// angle_i = A_f; -// } -// // the hit parameters -// double angle = Math.atan2(x[1], x[0]); -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); -// double z = x[2]; -// -// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { -// isInFid = true; -// } -// -// return isInFid; -// } -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the beginning of the strips -// */ -// public double CRC_GetBeginStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the beginning of the strips -// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the end of the strips -// */ -// public double CRC_GetEndStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the end of the strips -// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// /** -// * -// * @param angle -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating if the given angle is the sector -// */ -// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { -// if( layer < 1 || layer > 6 ) { -// System.err.println(" BMT layer has to be 1 <= layer <= 6"); -// return false; -// } -// if( sector < 1 || sector > 3 ) { -// System.err.println(" BMT sector has to be 1 <= layer <= 3"); -// return false; -// } -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; -// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; -// -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// -// if( sector == 3 ) { -// if( angle < Math.PI ) { -// if( angle < angle_f + jitter ) return true; -// else return false; -// } -// else { -// if( angle > angle_i - jitter ) return true; -// else return false; -// } -// } -// else { -// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) -// return true; -// else -// return false; -// -// } -// } - -// /** -// * -// * @param layer -// * @param trk_z the track z position of intersection with the C-detector -// * @return the C-strip -// */ -// public int getCStrip(int layer, double trk_z) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int strip_group = 0; -// int ClosestStrip = -1; -// // get group -// int len = Constants.getCRCGROUP()[num_region].length; -// double[] Z_lowBound = new double[len]; -// double[] Z_uppBound = new double[len]; -// int[] NStrips = new int[len]; -// -// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; -// double z = trk_z - zi; -// -// for (int i = 0; i < len; i++) { -// if(i==0) { -// Z_lowBound[i] = 0; -// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; -// } -// else { -// Z_lowBound[i] = Z_uppBound[i - 1]; -// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; -// } -// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; -// -// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { -// strip_group = i; -// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); -// if(i>0) ClosestStrip += NStrips[i - 1]; -// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; -// -// len = i; -// } -// } -// return ClosestStrip; -// } -// -// public boolean isInFiducial(double x, double y, double z, int layer) { -// -// boolean isOK = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; -// -// int axis = OldGeometry.getZorC(layer); -// -// double R = 0; -// if (axis == 0) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; -// } -// if (axis == 1) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; -// } -// -// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; -// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; -// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; -// -// double z_min = CRZZMIN + CRZOFFSET; -// double z_max = z_min + CRZLENGTH; -// -// double epsilon = 1e-1; -// -// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { -// isOK = true; -// } -// return isOK; -// } -// -// /** -// * -// * @param layer the layer 1...6 -// * @return the Z position of the strip center -// */ -// private double CRZ_GetZStrip(int layer) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //For CRZ, this function returns the Z position of the strip center -// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; -// return zc; //in mm -// } - - - public void putInFrame(Point3D cent, Point3D offset, Vector3D rotation, boolean inverse) { - if(inverse==false) { - cent.rotateX(rotation.x()); - cent.rotateY(rotation.y()); - cent.rotateZ(rotation.z()); - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - } else { - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - cent.rotateZ(rotation.z()); - cent.rotateY(rotation.y()); - cent.rotateX(rotation.x()); - } - } - -} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 48e515f7d..e49612721 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.cluster; import java.util.ArrayList; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -10,8 +9,12 @@ import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import java.util.Collections; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Transformation3D; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.Constants; +import org.jlab.rec.cvt.hit.Strip; /** * A cluster in the BST consists of an array of hits that are grouped together * according to the algorithm of the ClusterFinder class @@ -23,8 +26,8 @@ public class Cluster extends ArrayList implements Comparable private static final long serialVersionUID = 9153980362683755204L; - private int _Detector; // The detector SVT or BMT - private int _DetectorType; // The detector type for BMT C or Z + private DetectorType _Detector; // The detector SVT or BMT + private BMTType _Type; // The detector type for BMT C or Z private int _Sector; // sector[1...] private int _Layer; // layer [1,...] private int _Id; // cluster Id @@ -36,36 +39,43 @@ public class Cluster extends ArrayList implements Comparable private double _Phi; // for Z-detectors private double _PhiErr; private double _Phi0; // for Z-detectors before LC - private double _PhiErr0; + private double _PhiErr0; // local Z private double _Z; // for C-detectors private double _ZErr; - private Arc3D _Arc; + private Line3D _Line; + private Arc3D _Arc; private Point3D _TrakInters; //track intersection with the cluster - private double _Radius; + + private int _MinStrip; // the min strip number in the cluster + private int _MaxStrip; // the max strip number in the cluster + private FittedHit _Seed; // the seed: the strip with largest deposited energy + + private double _SeedResidual; // residual is doca to seed strip from trk intersection with module plane + private double _CentroidResidual; // residual is doca to centroid of cluster to trk inters with module plane //added variables for alignment - private double _x1; //cluster first end point x - private double _y1; //svt cluster first end point y - private double _z1; //svt cluster first end point z - private double _x2; //svt cluster second end point x - private double _y2; //svt cluster second end point y - private double _z2; //svt cluster second end point z - private double _ox; //bmt cluster arc origin x - private double _oy; //bmt cluster arc origin y - private double _oz; //bmt cluster arc origin z - private double _cx; //bmt cluster arc center x - private double _cy; //bmt cluster arc center y - private double _cz; //bmt cluster arc center z - private double _theta; //bmt cluster arc theta - private Line3D _cyl; // bmt axis +// private double _x1; //cluster first end point x +// private double _y1; //svt cluster first end point y +// private double _z1; //svt cluster first end point z +// private double _x2; //svt cluster second end point x +// private double _y2; //svt cluster second end point y +// private double _z2; //svt cluster second end point z +// private double _ox; //bmt cluster arc origin x +// private double _oy; //bmt cluster arc origin y +// private double _oz; //bmt cluster arc origin z +// private double _cx; //bmt cluster arc center x +// private double _cy; //bmt cluster arc center y +// private double _cz; //bmt cluster arc center z +// private double _theta; //bmt cluster arc theta +// private Line3D _cyl; // bmt axis private Vector3D _l; //svt vector along cluster pseudo-strip direction or bmt vector along cluster pseudo-strip direction in the middle of the arc private Vector3D _s; //svt vector perpendicular to cluster pseudo-strip direction in the module plane or bmt vector perpendicular to cluster pseudo-strip in direction tangential to the cluster surface in the middle of the arc private Vector3D _n; //svt vector normal to the cluster module plane or bmt vector normal to the cluster surface in the middle of the arc - public Cluster(int detector, int detectortype, int sector, int layer, int cid) { + public Cluster(DetectorType detector, BMTType type, int sector, int layer, int cid) { this._Detector = detector; - this._DetectorType = detectortype; + this._Type = type; this._Sector = sector; this._Layer = layer; this._Id = cid; @@ -80,23 +90,23 @@ public Cluster(int detector, int detectortype, int sector, int layer, int cid) { * number. */ public Cluster newCluster(Hit hit, int cid) { - return new Cluster(hit.get_Detector(), hit.get_DetectorType(), hit.get_Sector(), hit.get_Layer(), cid); + return new Cluster(hit.get_Detector(), hit.get_Type(), hit.get_Sector(), hit.get_Layer(), cid); } - public int get_Detector() { + public DetectorType get_Detector() { return _Detector; } - public void set_Detector(int _Detector) { + public void set_Detector(DetectorType _Detector) { this._Detector = _Detector; } - public int get_DetectorType() { - return _DetectorType; + public BMTType get_Type() { + return _Type; } - public void set_DetectorType(int _DetectorType) { - this._DetectorType = _DetectorType; + public void set_Type(BMTType type) { + this._Type = type; } /** @@ -167,20 +177,29 @@ public int get_RegionSlayer() { * @return the _Radius */ public double getRadius() { - return _Radius; + if(this.get_Detector()==DetectorType.BST) + return 0; + else { + if(this.get_Type()==BMTType.C) + return this.get_Arc().radius(); + else + return this.get(0).get_Strip().get_Axis().distance(this.getLine()).length(); + } } - /** - * @param _Radius the _Radius to set - */ - public void setRadius(double _Radius) { - this._Radius = _Radius; + public Line3D getAxis() { + if(this.get_Detector()==DetectorType.BST || true) + return new Line3D(); + else { + return this.get(0).get_Strip().get_Axis(); + } } - /** * sets energy-weighted parameters; these are the strip centroid * (energy-weighted) value, the energy-weighted phi for Z detectors and the * energy-weighted z for C detectors + * @param sgeo + * @param geo */ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { // instantiation of variables @@ -200,7 +219,7 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { double weightedPhi0 = 0; // Uncorrected energy-weighted phi of the strip double weightedPhiErrSq0 = 0; // Err^2 on uncorrected energy-weighted phi of the strip double weightedZ = 0; // Energy-weighted z of the strip - double weightedZErrSq = 0; // Err^2 on energy-weighted z of the strip + double weightedZErrSq = 0; // Err^2 on energy-weighted z of the strip double weightedX1 = 0; // SVT/BMT strip centroid positions of endpoints double weightedX2 = 0; // SVT/BMT strip centroid positions of endpoints double weightedXC = 0; // BMT strip centroid positions of arc center @@ -211,12 +230,6 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { double weightedZ2 = 0; // SVT/BMT strip centroid positions of endpoints double weightedZC = 0; // BMT strip centroid positions of arc center - /* - this.set_ImplantPoint(arcLine.origin()); - this.set_MidPoint(arcLine.center()); - this.set_EndPoint(arcLine.end()); - this.set_StripDir(arcLine.normal()); - */ int nbhits = this.size(); //sort for bmt detector //this.sort(Comparator.comparing(FittedHit.get_Strip()::get_Edep).thenComparing(FittedHit.get_Strip()::get_Edep)); @@ -225,60 +238,53 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { if (nbhits != 0) { int min = 1000000; int max = -1; - int seed = -1; - double Emax = -1; + FittedHit seed = null; // looping over the number of hits in the cluster for (int i = 0; i < nbhits; i++) { FittedHit thehit = this.get(i); - // gets the energy value of the strip - double strpEn = -1; + int strpNb = -1; int strpNb0 = -1; //before LC - if (this.get_Detector()==0) { - strpEn = thehit.get_Strip().get_Edep(); - // for the SVT the analysis only uses the centroid + + //strip points: + Point3D stEP1 = null; + Point3D stEP2 = null; + Point3D stCent = null; + // strip energy + double strpEn = thehit.get_Strip().get_Edep(); + + if (this.get_Detector()==DetectorType.BST) { + // for the SVT the analysis only uses the centroid strpNb = thehit.get_Strip().get_Strip(); - Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); - Point3D stEP2 = thehit.get_Strip().get_EndPoint(); - weightedX1 += strpEn * stEP1.x(); - weightedY1 += strpEn * stEP1.y(); - weightedZ1 += strpEn * stEP1.z(); - weightedX2 += strpEn * stEP2.x(); - weightedY2 += strpEn * stEP2.y(); - weightedZ2 += strpEn * stEP2.z(); - } - if (this.get_Detector()==1) { + stEP1 = thehit.get_Strip().get_Line().origin(); + stEP2 = thehit.get_Strip().get_Line().end(); + stCent = thehit.get_Strip().get_Line().midpoint(); + + } + else if (this.get_Detector()==DetectorType.BMT) { - strpEn = this.getBMTStripEnergy(thehit); if(thehit.newClustering && nbhits>Constants.MAXCLUSSIZE && i>Constants.MAXCLUSSIZE-1) continue; - //end points: - Point3D stEP1 = thehit.get_Strip().get_ImplantPoint(); - Point3D stEP2 = thehit.get_Strip().get_EndPoint(); - Point3D stCent = thehit.get_Strip().get_MidPoint(); - weightedX1 += strpEn * stEP1.x(); - weightedY1 += strpEn * stEP1.y(); - weightedZ1 += strpEn * stEP1.z(); - weightedX2 += strpEn * stEP2.x(); - weightedY2 += strpEn * stEP2.y(); - weightedZ2 += strpEn * stEP2.z(); - weightedXC += strpEn * stCent.x(); - weightedYC += strpEn * stCent.y(); - weightedZC += strpEn * stCent.z(); // for the BMT the analysis distinguishes between C and Z type detectors - if (this.get_DetectorType()==0) { // C-detectors + if (this.get_Type()==BMTType.C) { // C-detectors //strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); strpNb = thehit.get_Strip().get_Strip(); + stEP1 = thehit.get_Strip().get_Arc().origin(); + stEP2 = thehit.get_Strip().get_Arc().end(); + stCent = thehit.get_Strip().get_Arc().center(); // for C detector the Z of the centroid is calculated - //weightedZ += strpEn * thehit.get_Strip().get_Z(); + weightedZ += strpEn * thehit.get_Strip().get_Z(); weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); } - if (this.get_DetectorType()==1) { // Z-detectors + if (this.get_Type()==BMTType.Z) { // Z-detectors // for Z detectors Lorentz-correction is applied to the strip strpNb = thehit.get_Strip().get_LCStrip(); strpNb0 = thehit.get_Strip().get_Strip(); + stEP1 = thehit.get_Strip().get_Line().origin(); + stEP2 = thehit.get_Strip().get_Line().end(); + stCent = thehit.get_Strip().get_Line().midpoint(); // for C detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid weightedPhi += strpEn * thehit.get_Strip().get_Phi(); weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); @@ -290,6 +296,15 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { } totEn += strpEn; + weightedX1 += strpEn * stEP1.x(); + weightedY1 += strpEn * stEP1.y(); + weightedZ1 += strpEn * stEP1.z(); + weightedX2 += strpEn * stEP2.x(); + weightedY2 += strpEn * stEP2.y(); + weightedZ2 += strpEn * stEP2.z(); + weightedXC += strpEn * stCent.x(); + weightedYC += strpEn * stCent.y(); + weightedZC += strpEn * stCent.z(); weightedStrp += strpEn * (double) strpNb; weightedStrp0 += strpEn * (double) strpNb0; @@ -301,59 +316,39 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { max = strpNb; } // getting the seed strip which is defined as the strip with the largest deposited energy - if (strpEn >= Emax) { - Emax = strpEn; - seed = strpNb; - if (this.get_DetectorType()==1) { - seed = strpNb0; - } + if (seed==null || strpEn >= seed.get_Strip().get_Edep()) { + seed = thehit; } } if (totEn == 0) { - System.err.println(" Cluster energy is null .... exit "+this._Detector+" "+this._DetectorType); + System.err.println(" Cluster energy is null .... exit "+this._Detector+" "+this._Type); return; } this.set_MinStrip(min); this.set_MaxStrip(max); - this.set_SeedStrip(seed); - this.set_SeedEnergy(Emax); + this.set_Seed(seed); // calculates the centroid values and associated errors - stripNumCent = weightedStrp / totEn; + stripNumCent = weightedStrp / totEn; stripNumCent0 = weightedStrp0 / totEn; - phiCent = weightedPhi / totEn; - //phiCent = geo.LorentzAngleCorr(phiCent0,this.get_Layer()); - phiCent0 = weightedPhi0 / totEn; - //zCent = weightedZ / totEn; - phiErrCent = Math.sqrt(weightedPhiErrSq); - phiErrCent0 = Math.sqrt(weightedPhiErrSq0); - zErrCent = Math.sqrt(weightedZErrSq); - this.setEndPoint1(new Point3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn)); - this.setEndPoint2(new Point3D(weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); - //setting variables used for alignment + + //setting final variables, including the ones used for alignment //----------------------------------- - if (this.get_Detector()==0) { //SVT - this.setX1(weightedX1/totEn); - this.setY1(weightedY1/totEn); - this.setZ1(weightedZ1/totEn); - this.setX2(weightedX2/totEn); - this.setY2(weightedY2/totEn); - this.setZ2(weightedZ2/totEn); + if (this.get_Detector()==DetectorType.BST) { //SVT - Vector3D l = new Vector3D(weightedX2/totEn-weightedX1/totEn, - weightedY2/totEn-weightedY1/totEn, - weightedZ2/totEn-weightedZ1/totEn).asUnit(); + this.setLine(new Line3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); + Vector3D l = new Vector3D(this.getLine().direction().asUnit()); - //Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). - // vectorTo(sgeo.getPlaneModuleEnd(this.get_Sector(), this.get_Layer())).asUnit(); - double[][] Xi = sgeo.getStripEndPoints(1, (this.get_Layer() - 1) % 2); - double[][] Xf = sgeo.getStripEndPoints(100, (this.get_Layer() - 1) % 2); - Point3D EPi = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xi[0][0], 0, Xi[0][1], "lab", ""); - Point3D EPf = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xf[0][0], 0, Xf[0][1], "lab", ""); - - Vector3D se = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips +// //Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). +// // vectorTo(sgeo.getPlaneModuleEnd(this.get_Sector(), this.get_Layer())).asUnit(); +// double[][] Xi = sgeo.getStripEndPoints(1, (this.get_Layer() - 1) % 2); +// double[][] Xf = sgeo.getStripEndPoints(100, (this.get_Layer() - 1) % 2); +// Point3D EPi = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xi[0][0], 0, Xi[0][1], "lab", ""); +// Point3D EPf = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xf[0][0], 0, Xf[0][1], "lab", ""); +// +// Vector3D se = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips Vector3D n = sgeo.findBSTPlaneNormal(this.get_Sector(), this.get_Layer()); Vector3D s = l.cross(n).asUnit(); @@ -361,65 +356,52 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { this.setS(s); this.setN(n); } - if (this.get_Detector()==1) { //BMT - this.setRadius(geo.getRadius(_Layer)); - Cylindrical3D cyl = geo.getCylinder(this.get_Layer(), this.get_Sector()); - this.setCylAxis(geo.getAxis(this.get_Layer(), this.get_Sector())); + else if (this.get_Detector()==DetectorType.BMT) { //BMT // for the BMT the analysis distinguishes between C and Z type detectors - if (this.get_DetectorType()==0) { // C-detectors - this.setOx(weightedX1/totEn); - this.setOy(weightedY1/totEn); - this.setOz(weightedZ1/totEn); - this.setCx(weightedXC/totEn); - this.setCy(weightedYC/totEn); - this.setCz(weightedZC/totEn); - this.setX1(weightedX1/totEn); - this.setY1(weightedY1/totEn); - this.setZ1(weightedZ1/totEn); - this.setX2(weightedX2/totEn); - this.setY2(weightedY2/totEn); - this.setZ2(weightedZ2/totEn); -// Vector3D C2P1 = new Vector3D(weightedX1/totEn-weightedXC/totEn, -// weightedY1/totEn-weightedYC/totEn, -// weightedZ1/totEn-weightedZC/totEn).asUnit(); -// Vector3D C2P2 = new Vector3D(weightedX2/totEn-weightedXC/totEn, -// weightedY2/totEn-weightedYC/totEn, -// weightedZ2/totEn-weightedZC/totEn).asUnit(); - - double theta = Math.acos(this.getNFromTraj(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, this.getCylAxis()) - .dot(this.getNFromTraj(weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn, this.getCylAxis()))); - this.setTheta(theta); - - //Vector3D s = C2P1.cross(C2P2).asUnit(); - Vector3D s = this.getCylAxis().direction().asUnit(); - Vector3D n = cyl.baseArc().normal(); + if (this.get_Type()==BMTType.C) { // C-detectors + Point3D origin = new Point3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn); + Point3D center = new Point3D(weightedXC/totEn, weightedYC/totEn, weightedZC/totEn); + Vector3D normal = this.get(0).get_Strip().get_Arc().normal(); + double theta = this.get(0).get_Strip().get_Arc().theta(); + this.set_Arc(new Arc3D(origin,center,normal,theta)); + + Vector3D s = this.get_Arc().normal(); + Vector3D n = this.get_Arc().bisect(); Vector3D l = s.cross(n).asUnit(); this.setL(l); this.setS(s); this.setN(n); - this.set_Arc(geo.getCstrip(this.get_Region(), this.get_Sector(), this)); - //this.set_Z(this.get_Arc().center().z()); - } - if (this.get_DetectorType()==1) { // Z-detectors - // for Z detectors Lorentz-correction is applied to the strip - this.setX1(weightedX1/totEn); - this.setY1(weightedY1/totEn); - this.setZ1(weightedZ1/totEn); - this.setX2(weightedX2/totEn); - this.setY2(weightedY2/totEn); - this.setZ2(weightedZ2/totEn); + zCent = weightedZ/totEn; + zErrCent = Math.sqrt(weightedZErrSq); - Vector3D l = this.getCylAxis().direction().asUnit(); - //this.getCylAxis().setOrigin(this.getCylAxis().origin().x(), this.getCylAxis().origin().y(), weightedZ1/totEn); - //this.getCylAxis().setEnd(this.getCylAxis().end().x(), this.getCylAxis().end().y(), weightedZ2/totEn); - Vector3D n = this.getNFromTraj(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, this.getCylAxis()); - //Vector3D n = cyl.baseArc().center().vectorTo(new Point3D((weightedX2/totEn+weightedX1/totEn)/2, - // (weightedY2/totEn+weightedY1/totEn)/2, - // (weightedZ2/totEn+weightedZ1/totEn)/2)).asUnit(); + _Z = zCent; + _ZErr = zErrCent; + this.set_Error(zErrCent); + } + if (this.get_Type()==BMTType.Z) { // Z-detectors + + //phiCent = geo.LorentzAngleCorr(phiCent0,this.get_Layer()); + phiCent = weightedPhi / totEn; + phiCent0 = weightedPhi0 / totEn; + //zCent = weightedZ / totEn; + phiErrCent = Math.sqrt(weightedPhiErrSq); + phiErrCent0 = Math.sqrt(weightedPhiErrSq0); + + set_Centroid0(stripNumCent0); + _Phi = phiCent; + _PhiErr = phiErrCent; + this.set_Error(geo.getRadiusMidDrift(_Layer)*phiErrCent); + set_Phi0(phiCent0); + set_PhiErr0(phiErrCent0); + // for Z detectors Lorentz-correction is applied to the strip + this.setLine(new Line3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); + Vector3D l = new Vector3D(this.getLine().direction().asUnit()); + + Vector3D n = geo.getAxis(_Layer, _Sector).distance(_Line).direction().asUnit(); Vector3D s = l.cross(n).asUnit(); this.setL(l); @@ -428,38 +410,19 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { } } - - //phiErrCent = Math.sqrt(weightedPhiErrSq); - //phiErrCent0 = Math.sqrt(weightedPhiErrSq0); - //zErrCent = Math.sqrt(weightedZErrSq); - //System.out.println("end Points "+this.getEndPoint1().toString()+this.getEndPoint2().toString()+" for"); this.printInfo(); } _TotalEnergy = totEn; _Centroid = stripNumCent; - if (this.get_DetectorType() == 1) { - set_Centroid0(stripNumCent0); - _Phi = phiCent; - _PhiErr = phiErrCent; - this.set_Error(geo.getRadiusMidDrift(_Layer)*phiErrCent); - set_Phi0(phiCent0); - set_PhiErr0(phiErrCent0); - } - if (this.get_DetectorType() == 0) { - //_Z = zCent; - _ZErr = zErrCent; - this.set_Error(zErrCent); - } - } - - public Vector3D getNFromTraj(double x, double y, double z, Line3D cln) { - Point3D trk = new Point3D(x,y,z); - Point3D Or = cln.distance(new Point3D(x,y,z)).origin(); - Vector3D n = Or.vectorTo(trk).asUnit(); - return n; - } +// +// public Vector3D getNFromTraj(double x, double y, double z, Line3D cln) { +// Point3D trk = new Point3D(x,y,z); +// Point3D Or = cln.distance(new Point3D(x,y,z)).origin(); +// Vector3D n = Or.vectorTo(trk).asUnit(); +// return n; +// } public double get_Centroid() { return _Centroid; @@ -551,9 +514,83 @@ public Arc3D get_Arc() { */ public void set_Arc(Arc3D _Arc) { this._Arc = _Arc; - this.set_Z(this._Arc.center().z()); } + public Point3D origin() { + if(this.get_Detector()==DetectorType.BST) + return this.getLine().origin(); + else { + if(this.get_Type()==BMTType.C) + return this.get_Arc().origin(); + else + return this.getLine().origin(); + } + } + + public Point3D end() { + if(this.get_Detector()==DetectorType.BST) + return this.getLine().end(); + else { + if(this.get_Type()==BMTType.C) + return this.get_Arc().end(); + else + return this.getLine().end(); + } + } + + public Point3D center() { + if(this.get_Detector()==DetectorType.BST) + return this.getLine().midpoint(); + else { + if(this.get_Type()==BMTType.C) + return this.get_Arc().center(); + else + return this.getLine().midpoint(); + } + } + + public double theta() { + if(this.get_Detector()==DetectorType.BST) + return 0; + else { + if(this.get_Type()==BMTType.C) + return this.get_Arc().theta(); + else + return 0; + } + } + + public Transformation3D toLocal() { + return this.get(0).get_Strip().toLocal(); + } + + public Transformation3D toGlobal() { + return this.get(0).get_Strip().toGlobal(); + } + + public double residual(Point3D traj) { + double value = 0; + if(this.get_Detector()==DetectorType.BST) + ; + else { + Point3D local = new Point3D(traj); + this.toLocal().apply(local); + if(this.get_Type()==BMTType.C) + value = local.z()-this.get_Z(); + else + ; + } + return value; + } + + public void set_CentroidResidual(Point3D traj) { + this.set_CentroidResidual(this.residual(traj)); + } + + public void set_SeedResidual(Point3D traj) { + this.set_SeedResidual(this.get_Seed().residual(traj)); + } + public double get_TotalEnergy() { return _TotalEnergy; } @@ -561,14 +598,6 @@ public double get_TotalEnergy() { public void set_TotalEnergy(double _TotalEnergy) { this._TotalEnergy = _TotalEnergy; } - - private int _MinStrip; // the min strip number in the cluster - private int _MaxStrip; // the max strip number in the cluster - private int _SeedStrip; // the seed: the strip with largest deposited energy - private double _SeedEnergy; // the deposited energy of the seed - - private double _SeedResidual; // residual is doca to seed strip from trk intersection with module plane - private double _CentroidResidual; // residual is doca to centroid of cluster to trk inters with module plane public int get_MinStrip() { return _MinStrip; @@ -586,20 +615,16 @@ public void set_MaxStrip(int _MaxStrip) { this._MaxStrip = _MaxStrip; } - public int get_SeedStrip() { - return _SeedStrip; - } - - public void set_SeedStrip(int _SeedStrip) { - this._SeedStrip = _SeedStrip; + public Strip get_SeedStrip() { + return _Seed.get_Strip(); } - public double get_SeedEnergy() { - return _SeedEnergy; + public FittedHit get_Seed() { + return _Seed; } - public void set_SeedEnergy(double _SeedEnergy) { - this._SeedEnergy = _SeedEnergy; + public void set_Seed(FittedHit _Seed) { + this._Seed = _Seed; } public double get_SeedResidual() { @@ -637,7 +662,7 @@ public void setTrakInters(Point3D _TrakInters) { * @return cluster info. about location and number of hits contained in it */ public void printInfo() { - String s = " cluster: Detector " + this.get_Detector() +" Detector Type " + this.get_DetectorType() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + String s = " cluster: Detector " + this.get_Detector().getName() +" Detector Type " + this.get_Type().getName() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Radius " + this.getRadius()+ " Size " + this.size() +" centroid "+this.get_Centroid(); System.out.println(s); } @@ -684,12 +709,12 @@ public void set_AssociatedTrackID(int associatedTrackID) { public int compareTo(Cluster arg) { //sort by phi of strip implant of first strip in the cluster, then by layer, then by seed strip number - double this_phi = PhiInRange(this.get(0).get_Strip().get_ImplantPoint().toVector3D().phi()); - double arg_phi = PhiInRange(arg.get(0).get_Strip().get_ImplantPoint().toVector3D().phi()); + double this_phi = PhiInRange(this.get(0).get_Strip().get_Line().origin().toVector3D().phi()); + double arg_phi = PhiInRange(arg.get(0).get_Strip().get_Line().origin().toVector3D().phi()); int CompPhi = this_phi < arg_phi ? -1 : this_phi == arg_phi ? 0 : 1; int CompLay = this._Layer < arg._Layer ? -1 : this._Layer == arg._Layer ? 0 : 1; - int CompId = this._SeedStrip < arg._SeedStrip ? -1 : this._SeedStrip == arg._SeedStrip ? 0 : 1; + int CompId = this.get_SeedStrip().get_Strip()< arg.get_SeedStrip().get_Strip() ? -1 : this.get_SeedStrip().get_Strip() == arg.get_SeedStrip().get_Strip() ? 0 : 1; int return_val1 = ((CompLay == 0) ? CompId : CompLay); int return_val = ((CompPhi == 0) ? return_val1 : CompPhi); @@ -706,228 +731,12 @@ private double PhiInRange(double phi) { return phi; } - /** - * @return the _EndPoint1 - */ - public Point3D getEndPoint1() { - return _EndPoint1; - } - - /** - * @param _EndPoint1 the _EndPoint1 to set - */ - public void setEndPoint1(Point3D _EndPoint1) { - this._EndPoint1 = _EndPoint1; - } - - /** - * @return the _EndPoint2 - */ - public Point3D getEndPoint2() { - return _EndPoint2; - } - - /** - * @param _EndPoint2 the _EndPoint2 to set - */ - public void setEndPoint2(Point3D _EndPoint2) { - this._EndPoint2 = _EndPoint2; - } - - /** - * @return the _x1 - */ - public double getX1() { - return _x1; - } - - /** - * @param _x1 the _x1 to set - */ - public void setX1(double _x1) { - this._x1 = _x1; - } - - /** - * @return the _y1 - */ - public double getY1() { - return _y1; - } - - /** - * @param _y1 the _y1 to set - */ - public void setY1(double _y1) { - this._y1 = _y1; - } - - /** - * @return the _z1 - */ - public double getZ1() { - return _z1; - } - - /** - * @param _z1 the _z1 to set - */ - public void setZ1(double _z1) { - this._z1 = _z1; - } - - /** - * @return the _x2 - */ - public double getX2() { - return _x2; - } - - /** - * @param _x2 the _x2 to set - */ - public void setX2(double _x2) { - this._x2 = _x2; - } - - /** - * @return the _y2 - */ - public double getY2() { - return _y2; - } - - /** - * @param _y2 the _y2 to set - */ - public void setY2(double _y2) { - this._y2 = _y2; - } - - /** - * @return the _z2 - */ - public double getZ2() { - return _z2; - } - - /** - * @param _z2 the _z2 to set - */ - public void setZ2(double _z2) { - this._z2 = _z2; - } - - /** - * @return the _ox - */ - public double getOx() { - return _ox; - } - - /** - * @param _ox the _ox to set - */ - public void setOx(double _ox) { - this._ox = _ox; - } - - /** - * @return the _oy - */ - public double getOy() { - return _oy; - } - - /** - * @param _oy the _oy to set - */ - public void setOy(double _oy) { - this._oy = _oy; - } - - /** - * @return the _oz - */ - public double getOz() { - return _oz; - } - - /** - * @param _oz the _oz to set - */ - public void setOz(double _oz) { - this._oz = _oz; + public Line3D getLine() { + return _Line; } - /** - * @return the _cx - */ - public double getCx() { - return _cx; - } - - /** - * @param _cx the _cx to set - */ - public void setCx(double _cx) { - this._cx = _cx; - } - - /** - * @return the _cy - */ - public double getCy() { - return _cy; - } - - /** - * @param _cy the _cy to set - */ - public void setCy(double _cy) { - this._cy = _cy; - } - - /** - * @return the _cz - */ - public double getCz() { - return _cz; - } - - /** - * @param _cz the _cz to set - */ - public void setCz(double _cz) { - this._cz = _cz; - } - - /** - * @return the _theta - */ - public double getTheta() { - return _theta; - } - - /** - * @param _theta the _theta to set - */ - public void setTheta(double _theta) { - this._theta = _theta; - } - - /** - * @return the _cyl - */ - public Line3D getCylAxis() { - return _cyl; - } - - /** - * @param _cyl the _cyl to set - */ - public void setCylAxis(Line3D _cyl) { - this._cyl = _cyl; + public void setLine(Line3D _Line) { + this._Line = _Line; } /** @@ -972,16 +781,4 @@ public void setN(Vector3D _n) { this._n = _n; } - - private Point3D _EndPoint1; - private Point3D _EndPoint2; - - public double getBMTStripEnergy(FittedHit thehit) { - double strpEn = thehit.get_Strip().get_Edep(); - - return strpEn ; - } - - - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 463129d01..836e7c911 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -69,7 +69,7 @@ public ArrayList findClusters(List hits2, SVTGeometry geo_bst, BMT // strip until there's a strip with no hit while ((si < nstrip - 1 && HitArray[si + 1][l][s] != null) || (HitArray[si][l][s] != null && si < nstrip)) { if (HitArray[si][l][s] != null) { // continue clustering skipping over bad hit - FittedHit hitInCls = new FittedHit(HitArray[si][l][s].get_Detector(), HitArray[si][l][s].get_DetectorType(), HitArray[si][l][s].get_Sector(), HitArray[si][l][s].get_Layer(), HitArray[si][l][s].get_Strip()); + FittedHit hitInCls = new FittedHit(HitArray[si][l][s].get_Detector(), HitArray[si][l][s].get_Type(), HitArray[si][l][s].get_Sector(), HitArray[si][l][s].get_Layer(), HitArray[si][l][s].get_Strip()); hitInCls.set_Id(HitArray[si][l][s].get_Id()); hits.add(hitInCls); @@ -78,7 +78,7 @@ public ArrayList findClusters(List hits2, SVTGeometry geo_bst, BMT } // define new cluster - Cluster this_cluster = new Cluster(hits.get(0).get_Detector(), hits.get(0).get_DetectorType(), hits.get(0).get_Sector(), l + 1, cid++); + Cluster this_cluster = new Cluster(hits.get(0).get_Detector(), hits.get(0).get_Type(), hits.get(0).get_Sector(), l + 1, cid++); this_cluster.set_Id(clusters.size() + 1); // add hits to the cluster this_cluster.addAll(hits); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 37898bbbe..f7563ec9f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collections; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -34,9 +35,9 @@ public class Cross extends ArrayList implements Comparable { * @param rid the cross ID (if there are only 3 crosses in the event, the ID * corresponds to the region index */ - public Cross(String detector, BMTType detectortype, int sector, int region, int crid) { + public Cross(DetectorType detector, BMTType detectortype, int sector, int region, int crid) { this._Detector = detector; - this._DetectorType = detectortype; + this._Type = detectortype; this._Sector = sector; this._Region = region; this._Id = crid; @@ -44,8 +45,8 @@ public Cross(String detector, BMTType detectortype, int sector, int region, int this._usedInZRcand = false; } - private String _Detector; // the detector SVT or BMT - private BMTType _DetectorType; // the detector type for BMT, C or Z detector + private DetectorType _Detector; // the detector SVT or BMT + private BMTType _Type; // the detector type for BMT, C or Z detector private int _Sector; // sector [1...] private int _Region; // region [1,...] private int _OrderedRegion; // 1...3:SVT; 4...9: BMT @@ -92,20 +93,20 @@ public boolean equals(Object obj) { return true; } - public String get_Detector() { + public DetectorType get_Detector() { return _Detector; } - public void set_Detector(String _Detector) { + public void set_Detector(DetectorType _Detector) { this._Detector = _Detector; } - public BMTType get_DetectorType() { - return _DetectorType; + public BMTType get_Type() { + return _Type; } - public void set_DetectorType(BMTType _DetectorType) { - this._DetectorType = _DetectorType; + public void set_Type(BMTType type) { + this._Type = type; } /** @@ -416,7 +417,7 @@ public String printInfo() { public int get_SVTCosmicsRegion() { int theRegion = 0; - if (this.get_Detector().equalsIgnoreCase("SVT")) { + if (this.get_Detector()==DetectorType.BST) { /* if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[6][0] + Constants.MODULERADIUS[7][0]) * 0.5 < 15) { if (this.get_Point0().y() > 0) { @@ -548,18 +549,18 @@ public static void main(String arg[]) { ArrayList testList = new ArrayList(); for (int i = 0; i < 5; i++) { - Cross c1 = new Cross("SVT", BMTType.UNDEFINED, 1, 1, 1 + i); + Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 1, 1 + i); c1.set_Point0(new Point3D(-1.2 - i, 66.87, 0)); testList.add(c1); } for (int i = 0; i < 5; i++) { - Cross c1 = new Cross("SVT", BMTType.UNDEFINED, 1, 3, 1 + i); + Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 3, 1 + i); c1.set_Point0(new Point3D(-1.2 + i, 123, 0)); testList.add(c1); } for (int i = 0; i < 5; i++) { - Cross c1 = new Cross("SVT", BMTType.UNDEFINED, 1, 2, 1 + i); + Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 2, 1 + i); c1.set_Point0(new Point3D(-1.2 - i, 95, 0)); testList.add(c1); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 34a03e272..2893d44de 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -91,7 +92,7 @@ public ArrayList findSVTCrosses( && (inlayerclus.get_MaxStrip() + outlayerclus.get_MaxStrip() < Constants.sumStpNumMax)) { // the intersection is valid // define new cross - Cross this_cross = new Cross("SVT", BMTType.UNDEFINED, inlayerclus.get_Sector(), inlayerclus.get_Region(), rid++); + Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, inlayerclus.get_Sector(), inlayerclus.get_Region(), rid++); // cluster1 is the inner layer cluster this_cross.set_Cluster1(inlayerclus); // cluster2 is the outer layer cluster @@ -103,7 +104,7 @@ public ArrayList findSVTCrosses( if (this_cross.get_Point0() != null) { //pass the cross to the arraylist of crosses this_cross.set_Id(crosses.size() + 1); - this_cross.set_Detector("SVT"); + this_cross.set_Detector(DetectorType.BST); calcCentErr(this_cross, this_cross.get_Cluster1(), svt_geo); calcCentErr(this_cross, this_cross.get_Cluster2(), svt_geo); crosses.add(this_cross); @@ -150,7 +151,7 @@ private ArrayList findBMTCrosses( } // Z detector --> meas phi // define new cross - Cross this_cross = new Cross("BMT", BMTType.Z, Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); + Cross this_cross = new Cross(DetectorType.BMT, BMTType.Z, Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); this_cross.set_Id(pid); this_cross.set_Cluster1(Zlayerclus); // this is the inner shell //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips @@ -165,8 +166,8 @@ private ArrayList findBMTCrosses( //the x,y position of the Z detector cluster centroid. This is calculated from the Lorentz angle corrected strips //double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); - double x = Zlayerclus.getEndPoint1().x(); - double y = Zlayerclus.getEndPoint1().y(); + double x = Zlayerclus.getLine().midpoint().x(); + double y = Zlayerclus.getLine().midpoint().y(); double xEr = -bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); double yEr = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); @@ -187,11 +188,11 @@ private ArrayList findBMTCrosses( } // C detector --> meas z // define new cross - Cross this_cross = new Cross("BMT", BMTType.C, Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); + Cross this_cross = new Cross(DetectorType.BMT, BMTType.C, Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); this_cross.set_Id(pid); // measurement of z - double z = Clayerclus.get_Z(); + double z = Clayerclus.center().z(); double zErr = Clayerclus.get_ZErr(); // there is no measurement of x,y, hence only the z component is set this_cross.set_Point0(new Point3D(Double.NaN, Double.NaN, z)); @@ -212,7 +213,7 @@ private ArrayList findBMTCrosses( //} for (Cross c : crosses) { int rg = 3 + - bmt_geo.getLayer( c.get_Region(), c.get_DetectorType()) ; + bmt_geo.getLayer( c.get_Region(), c.get_Type()) ; c.setOrderedRegion(rg); } return crosses; @@ -239,7 +240,7 @@ public ArrayList> sortClusterByDetectorAndIO( // Sorting by layer first: for (Cluster theclus : clusters) { - if (theclus.get_Detector() == 1) { + if (theclus.get_Detector() == DetectorType.BMT) { if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.Z) { bmt_Zlayrclus.add(theclus); } @@ -249,7 +250,7 @@ public ArrayList> sortClusterByDetectorAndIO( } } - if (theclus.get_Detector() == 0) { + if (theclus.get_Detector() == DetectorType.BST) { if (theclus.get_Layer() % 2 == 0) { svt_outerlayrclus.add(theclus); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index a079c379f..aaf3204e0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -88,11 +89,11 @@ public List findCandidateCrossLists(List findCandidateCrossLists(List clusters = new ArrayList(); for(Cross c : s ) { - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { c.get_Cluster1().set_CentroidError(this.calcCentErr(c, c.get_Cluster1(), svt_geo)); c.get_Cluster2().set_CentroidError(this.calcCentErr(c, c.get_Cluster2(), svt_geo)); clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); } - if(c.get_Detector().equalsIgnoreCase("BMT")) { + if(c.get_Detector()==DetectorType.BMT) { clusters.add(c.get_Cluster1()); } @@ -235,7 +236,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { double avg_tandip =0; int countCrosses =0; for(Cross c : trkCand) { - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { countCrosses++; avg_tandip+=c.get_Point().z()/Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index ab88f9de5..e9bb17d4a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -481,7 +482,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, if (Delt.mag() < org.jlab.rec.cvt.svt.Constants.ACTIVESENWIDTH / 2) { double tX = fac * yxslope + yxinterc; double tY = fac; - Cross cross2D = new Cross("SVT", BMTType.UNDEFINED, s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane + Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane cross2D.set_Point0(new Point3D(tX, tY, 0)); projectedCrosses.add(cross2D); } @@ -495,13 +496,13 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, this.calcBMT2DPoint(yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.C)), t); //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); + Cross cross2D1 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D1); if (t[3] != t[1] && t[2] != t[0]) { //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); + Cross cross2D2 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D2); } @@ -509,13 +510,13 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.Z)), t); //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); + Cross cross2D3 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); projectedCrosses.add(cross2D3); if (t[3] != t[1] && t[2] != t[0]) { //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); + Cross cross2D4 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); projectedCrosses.add(cross2D4); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java index a48d48235..b00e5766b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java @@ -1,5 +1,9 @@ package org.jlab.rec.cvt.hit; +import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTType; + /** * A hit that is used in a fitted track. * @@ -10,13 +14,13 @@ public class FittedHit extends Hit implements Comparable { /** * @param detector SVT (0) or BMT (1) + * @param type * @param sector (1...) * @param layer (1...) * @param strip (1...) - * @param Edep (for gemc output without digitization) */ - public FittedHit(int detector, int detectortype, int sector, int layer, Strip strip) { - super(detector, detectortype, sector, layer, strip); + public FittedHit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) { + super(detector, type, sector, layer, strip); } private double _docaToTrk; // 3-D distance of closest approach of the helix to the wire @@ -31,6 +35,26 @@ public void set_docaToTrk(double _docaToTrk) { this._docaToTrk = _docaToTrk; } + public void set_docaToTrk(Point3D traj) { + this.set_docaToTrk(this.residual(traj)); + } + + public double residual(Point3D traj) { + double value = 0; + if(this.get_Detector()==DetectorType.BST) + ; + else { + Point3D local = new Point3D(traj); + this.get_Strip().toLocal().apply(local); + if(this.get_Type()==BMTType.C) + value = local.z()-this.get_Strip().get_Z(); + else + ; + } + return value; + } + + public double get_stripResolutionAtDoca() { return _stripResolutionAtDoca; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index b460a99e0..32ce39ad8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -1,5 +1,8 @@ package org.jlab.rec.cvt.hit; +import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.bmt.BMTType; + /** * A hit characterized by layer, sector, wire number, and Edep. The ADC to time * conversion has been done. @@ -10,42 +13,42 @@ public class Hit implements Comparable { // class implements Comparable interface to allow for sorting a collection of hits by wire number values + private DetectorType _Detector; // the detector SVT or BMT + private BMTType _Type; // for the BMT, either C or Z + + private int _Sector; // sector[1...24] for SVT, [1..3] for BMT + private int _Layer; // layer [1,...] + private Strip _Strip; // Strip object + + private int _Id; // Hit Id + private int _Status; // Status -1 dead, 0 noisy, 1 good + // constructor - public Hit(int detector, int detectortype, int sector, int layer, Strip strip) { - this._Detector = detector; // 0 = SVT, 1 = BMT - this._DetectorType = detectortype; // 0 = C, 1 = Z - this._Sector = sector; - this._Layer = layer; - this._Strip = strip; + public Hit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) { + this._Detector = detector; // 0 = SVT, 1 = BMT + this._Type = type; // set according to BMTType + this._Sector = sector; + this._Layer = layer; + this._Strip = strip; } - public int get_Detector() { + public DetectorType get_Detector() { return _Detector; } - public void set_Detector(int _detector) { + public void set_Detector(DetectorType _detector) { this._Detector = _detector; } - public int get_DetectorType() { - return _DetectorType; + public BMTType get_Type() { + return _Type; } - public void set_DetectorType(int _DetectorType) { - this._DetectorType = _DetectorType; + public void set_Type(BMTType type) { + this._Type = type; } - private int _Detector; // the detector SVT or BMT - private int _DetectorType; // for the BMT, either C or Z - - private int _Sector; // sector[1...24] for SVT, [1..3] for BMT - private int _Layer; // layer [1,...] - private Strip _Strip; // Strip object - - private int _Id; // Hit Id - private int _Status; // Status -1 dead, 0 noisy, 1 good - /** * * @return the sector (1...24) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 3144245d2..feaf18e34 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -2,9 +2,9 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Arc3D; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -19,23 +19,24 @@ public Strip(int strip, double edep, double time) { } - private int _Strip; // strip read from daq + private int _Strip; // strip read from daq + private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value + private double _Time; + private int _LCStrip; // strip number taking into account Lorentz angle correction (for MM Z detectors) private double _Phi; // for MM Z-detectors, the azimuth angle at the strip midwidth after LC private double _PhiErr; private double _Phi0; // for MM Z-detectors, the azimuth angle at the strip midwidth before LC private double _PhiErr0; - - private Arc3D _Arc; // for MM C-detectors. the arc position at the strip midwidth + private double _Z; private double _ZErr; - private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value - private double _Time; - private Point3D _ImplantPoint; // the end-point of the strip at implant (lab frame) - private Point3D _MidPoint; // the mid-point of the strip (lab frame) - private Point3D _EndPoint; // the end-point of the strip (lab frame) - private Vector3D _StripDir; // unit direction vector along the strip (lab frame) - + private Arc3D _Arc; + private Line3D _Line; + private Line3D _Axis; + private Transformation3D toLocal; + private Transformation3D toGlobal; + public int get_Strip() { return _Strip; } @@ -44,36 +45,44 @@ public void set_Strip(int _Strip) { this._Strip = _Strip; } - public Point3D get_ImplantPoint() { - return _ImplantPoint; + public Arc3D get_Arc() { + return _Arc; } - public void set_ImplantPoint(Point3D _ImplantPoint) { - this._ImplantPoint = _ImplantPoint; + public void set_Arc(Arc3D _Arc) { + this._Arc = _Arc; } - public Point3D get_MidPoint() { - return _MidPoint; + public Line3D get_Line() { + return _Line; } - public void set_MidPoint(Point3D _MidPoint) { - this._MidPoint = _MidPoint; + public void set_Line(Line3D _Line) { + this._Line = _Line; } - public Point3D get_EndPoint() { - return _EndPoint; + public Line3D get_Axis() { + return _Axis; } - public void set_EndPoint(Point3D _EndPoint) { - this._EndPoint = _EndPoint; + public void set_Axis(Line3D _Axis) { + this._Axis = _Axis; } - - public Vector3D get_StripDir() { - return _StripDir; + + public Transformation3D toLocal() { + return toLocal; + } + + public void setToLocal(Transformation3D toLocal) { + this.toLocal = toLocal; + } + + public Transformation3D toGlobal() { + return toGlobal; } - public void set_StripDir(Vector3D _StripDir) { - this._StripDir = _StripDir; + public void setToGlobal(Transformation3D toGlobal) { + this.toGlobal = toGlobal; } public int get_LCStrip() { @@ -116,12 +125,12 @@ public void set_PhiErr0(double _PhiErr0) { this._PhiErr0 = _PhiErr0; } - public Arc3D get_Arc() { - return _Arc; + public double get_Z() { + return _Z; } - public void set_Arc(Arc3D _Arc) { - this._Arc = _Arc; + public void set_Z(double _Z) { + this._Z = _Z; } public double get_ZErr() { @@ -162,43 +171,39 @@ public void set_Time(double _Time) { public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swim) { int region = geo.getRegion(layer); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 + this.setToGlobal(geo.toGlobal(layer, sector)); + this.setToLocal(geo.toLocal(layer, sector)); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); - //double z = arcLine.center().z(); this.set_Arc(arcLine); + this.set_Axis(geo.getAxis(layer, sector)); // max z err - //this.set_ZErr(geo.CRCStrip_GetPitch(layer, this.get_Strip()) / Math.sqrt(12.)); + this.set_Z(geo.getCstripZ(geo.getRegion(layer),this.get_Strip())); this.set_ZErr(geo.getPitch(layer, this.get_Strip()) / Math.sqrt(12.)); - this.set_ImplantPoint(arcLine.origin()); - this.set_MidPoint(arcLine.center()); - this.set_EndPoint(arcLine.end()); - this.set_StripDir(arcLine.normal()); + } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); - Line3D L = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip(), swim); - this.set_ImplantPoint(L.origin()); - this.set_MidPoint(L.midpoint()); - this.set_EndPoint(L.end()); - this.set_StripDir(L.direction()); + Line3D line = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip(), swim); + this.set_Line(line); + this.set_Axis(geo.getAxis(layer, sector)); - Cylindrical3D cyl = geo.getCylinder(layer, sector); Line3D cln = geo.getAxis(layer, sector); - cln.set(cln.origin().x(), cln.origin().y(), L.origin().z(), - cln.end().x(), cln.end().y(), L.end().z()); + cln.set(cln.origin().x(), cln.origin().y(), line.origin().z(), + cln.end().x(), cln.end().y(), line.end().z()); - double v = (L.origin().z()-cln.origin().z())/cln.direction().z(); + double v = (line.origin().z()-cln.origin().z())/cln.direction().z(); double x = cln.origin().x()+v*cln.direction().x(); double y = cln.origin().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, L.origin().z()). - vectorTo(new Point3D(L.origin().x(),L.origin().y(),L.origin().z())).asUnit(); + Vector3D n = new Point3D(x, y, line.origin().z()). + vectorTo(new Point3D(line.origin().x(),line.origin().y(),line.origin().z())).asUnit(); double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.get_Strip()); - //double theLorentzCorrectedAngle = L.midpoint().toVector3D().phi(); + //double theLorentzCorrectedAngle = line.midpoint().toVector3D().phi(); double theLorentzCorrectedAngle = n.phi(); // set the phi this.set_Phi(theLorentzCorrectedAngle); @@ -211,7 +216,7 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi // Math.sin(theLorentzCorrectedAngle); // int theLorentzCorrectedStrip = geo.getStrip( layer, sector, // new Point3D(xl,yl,0)); - int theLorentzCorrectedStrip = geo.getStrip( layer, sector, L.midpoint()); + int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); // get the strip number after correcting for Lorentz angle this.set_LCStrip(theLorentzCorrectedStrip); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 13fc25380..f6495a8d7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -194,11 +194,11 @@ public boolean processDataEvent(DataEvent event) { // fill the fitted hits list. if (clusters.size() != 0) { for (int i = 0; i < clusters.size(); i++) { - if (clusters.get(i).get_Detector() == 0) { + if (clusters.get(i).get_Detector() == DetectorType.BST) { SVTclusters.add(clusters.get(i)); SVThits.addAll(clusters.get(i)); } - if (clusters.get(i).get_Detector() == 1) { + if (clusters.get(i).get_Detector() == DetectorType.BMT) { BMTclusters.add(clusters.get(i)); BMThits.addAll(clusters.get(i)); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index f421fa8e4..d66104154 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Cylindrical3D; @@ -18,6 +19,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.banks.RecoBankWriter; import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossList; @@ -111,7 +113,7 @@ public boolean processEvent(DataEvent event, for (int k1 = 0; k1 < cosmics.size(); k1++) { cosmics.get(k1).set_Id(k1 + 1); for (int k2 = 0; k2 < cosmics.get(k1).size(); k2++) { - if(cosmics.get(k1).get(k2).get_Detector().equalsIgnoreCase("SVT")==true) + if(cosmics.get(k1).get(k2).get_Detector()==DetectorType.BST) continue; bmtCrossesRm.add(cosmics.get(k1).get(k2)); cosmics.get(k1).get(k2).set_AssociatedTrackID(k1+1); @@ -195,14 +197,13 @@ public boolean processEvent(DataEvent event, cosmics.get(k1).clsMap.get(keys.get(i)).setTrakInters(tj); cl.set_CentroidResidual(resi); - if (cl.get_Detector()==1 ) { + if (cl.get_Detector()==DetectorType.BMT) { - if (cl.get_DetectorType()==1) { //Z-detector measuring phi - Cylindrical3D cyl = BMTGeom.getCylinder(cl.get_Layer(), cl.get_Sector()); - Line3D cln = cl.getCylAxis(); + if (cl.get_Type()==BMTType.Z) { //Z-detector measuring phi + Line3D cln = BMTGeom.getAxis(layer, sector); double r = BMTGeom.getRadiusMidDrift(layer); cl.set_CentroidResidual(resi*r); - cl.setN(cl.getNFromTraj(tj.x(),tj.y(),tj.z(),cln)); + cl.setN(cln.distance(refPoint).direction().asUnit()); cl.setS(cl.getL().cross(cl.getN()).asUnit()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index f4dd48d97..20579f423 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.Comparator; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Arc3D; import org.jlab.io.base.DataBank; @@ -95,18 +96,19 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge meas0.setLayer(0); meas0.setError(1); KFSites.add(meas0); - for (int i = 0; i < trkcand.get_Clusters().size(); i++) { //SVT - if(trkcand.get_Clusters().get(i).get_Detector()==0) { - int id = trkcand.get_Clusters().get(i).get_Id(); - double ce = trkcand.get_Clusters().get(i).get_Centroid(); - Point3D endPt1 = trkcand.get_Clusters().get(i).getEndPoint1(); - Point3D endPt2 = trkcand.get_Clusters().get(i).getEndPoint2(); - Strip strp = new Strip(id, ce, endPt1.x(), endPt1.y(), endPt1.z(), - endPt2.x(), endPt2.y(), endPt2.z()); - Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(trkcand.get_Clusters().get(i).get_Sector(), - trkcand.get_Clusters().get(i).get_Layer())); - Point3D Or = sgeo.getPlaneModuleOrigin(trkcand.get_Clusters().get(i).get_Sector(), trkcand.get_Clusters().get(i).get_Layer()); - Point3D En = sgeo.getPlaneModuleEnd(trkcand.get_Clusters().get(i).get_Sector(), trkcand.get_Clusters().get(i).get_Layer()); + + // SVT measurements + for (int i = 0; i < trkcand.get_Clusters().size(); i++) { + if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { + int id = trkcand.get_Clusters().get(i).get_Id(); + int layer = trkcand.get_Clusters().get(i).get_Layer(); + int sector = trkcand.get_Clusters().get(i).get_Sector(); + double ce = trkcand.get_Clusters().get(i).get_Centroid(); + Line3D line = trkcand.get_Clusters().get(i).getLine(); + Strip strp = new Strip(id, ce, line); + Plane3D pln = new Plane3D(line.origin(),sgeo.findBSTPlaneNormal(sector,layer)); + Point3D Or = sgeo.getPlaneModuleOrigin(sector,layer); + Point3D En = sgeo.getPlaneModuleEnd(sector,layer); Surface meas = new Surface(pln, strp, Or, En); meas.setSector(trkcand.get_Clusters().get(i).get_Sector()); meas.setLayer(trkcand.get_Clusters().get(i).get_Layer()); @@ -128,31 +130,24 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge // adding the BMT for (int c = 0; c < trkcand.get_Crosses().size(); c++) { - if (trkcand.get_Crosses().get(c).get_Detector().equalsIgnoreCase("BMT")) { -// Cylindrical3D cyl = new Cylindrical3D(); -// cyl.baseArc().setCenter(new Point3D(0, 0, 0)); -// cyl.highArc().setCenter(new Point3D(0, 0, 0)); -// cyl.baseArc().setNormal(new Vector3D(0,1,0)); -// cyl.highArc().setNormal(new Vector3D(0,1,0)); - int lyer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); - int sec = trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(); + if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { - Cylindrical3D cyl = bgeo.getCylinder(lyer, sec); - Line3D cln = bgeo.getAxis(lyer, sec); - Line3D l = bgeo.getLCZstrip(bgeo.getRegion(lyer), sec, 1, swim); + int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); + int sector = trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(); + + Cylindrical3D cyl = bgeo.getTileSurface(layer, sector); + Line3D cln = bgeo.getAxis(layer, sector); + Line3D l = bgeo.getLCZstrip(bgeo.getRegion(layer), sector, 1, swim); //cln.set(cln.origin().x(), cln.origin().y(), l.origin().z(), // cln.end().x(), cln.end().y(), l.end().z()); - cyl.setAxis(cln); - int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); + //cyl.setAxis(cln); + int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); double hemisp = trkcand.get_Helix().getPointAtRadius(300).y(); - if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.Z) { - //double x = trkcand.get_Crosses().get(c).get_Point().x(); - //double y = trkcand.get_Crosses().get(c).get_Point().y(); - Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint1(); - //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); - + if (trkcand.get_Crosses().get(c).get_Type()==BMTType.Z) { + Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getLine().origin(); + double v = (EP1.z()-cln.origin().z())/cln.direction().z(); double x = cln.origin().x()+v*cln.direction().x(); double y = cln.origin().y()+v*cln.direction().y(); @@ -173,15 +168,11 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(layer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(layer)); Surface meas = new Surface(cyl, strp); - Point3D offset = bgeo.getOffset(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), - trkcand.get_Crosses().get(c).get_Sector()); - Vector3D rotation = bgeo.getRotation(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), - trkcand.get_Crosses().get(c).get_Sector()); - meas.cylShift = offset; - meas.cylRotation = rotation; + + meas.setTransformation(bgeo.toGlobal(layer,sector)); meas.setSector(trkcand.get_Crosses().get(c).get_Sector()); meas.setLayer(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6); @@ -198,7 +189,7 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge meas.hemisphere = hemisp; KFSites.add(meas); } - if (trkcand.get_Crosses().get(c).get_DetectorType()==BMTType.C) { + if (trkcand.get_Crosses().get(c).get_Type()==BMTType.C) { double z = trkcand.get_Crosses().get(c).get_Point().z(); double err = trkcand.get_Crosses().get(c).get_Cluster1().get_ZErr(); @@ -212,17 +203,13 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge //arc.setCenter(ct); //arc.setOrigin(og); Strip strp = new Strip(id, ce, arc); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); + cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(layer)); + cyl.highArc().setRadius(bgeo.getRadiusMidDrift(layer)); Surface meas = new Surface(cyl, strp); - Point3D offset = bgeo.getOffset(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), - trkcand.get_Crosses().get(c).get_Sector()); - Vector3D rotation = bgeo.getRotation(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), - trkcand.get_Crosses().get(c).get_Sector()); - meas.cylShift = offset; - meas.cylRotation = rotation; + meas.setTransformation(bgeo.toGlobal(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), + trkcand.get_Crosses().get(c).get_Sector())); meas.setSector(trkcand.get_Crosses().get(c).get_Sector()); meas.setLayer(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6); @@ -244,6 +231,8 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge return KFSites; } private TrajectoryFinder tf = new TrajectoryFinder(); + + public List setMeasVecs(StraightTrack trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); @@ -260,7 +249,7 @@ public List setMeasVecs(StraightTrack trkcand, Map clsMap = new HashMap(); trkcand.sort(Comparator.comparing(Cross::getY).reversed()); for (int i = 0; i < trkcand.size(); i++) { //SVT - if(trkcand.get(i).get_Detector().equalsIgnoreCase("SVT")) { + if(trkcand.get(i).get_Detector()==DetectorType.BST) { List cls = new ArrayList(); int s = trkcand.get(i).get_Cluster1().get_Sector()-1; int lt = trkcand.get(i).get_Cluster1().get_Layer()-1; @@ -281,8 +270,8 @@ public List setMeasVecs(StraightTrack trkcand, for (int j = 0; j < cls.size(); j++) { int id = cls.get(j).get_Id(); double ce = cls.get(j).get_Centroid(); - Point3D endPt1 = cls.get(j).getEndPoint1(); - Point3D endPt2 = cls.get(j).getEndPoint2(); + Point3D endPt1 = cls.get(j).getLine().origin(); + Point3D endPt2 = cls.get(j).getLine().end(); Strip strp = new Strip(id, ce, endPt1.x(), endPt1.y(), endPt1.z(), endPt2.x(), endPt2.y(), endPt2.z()); Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cls.get(j).get_Sector(), @@ -292,7 +281,6 @@ public List setMeasVecs(StraightTrack trkcand, Surface meas = new Surface(pln, strp, Or, En); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setSector(cls.get(j).get_Sector()); - //meas.setLayer(i+1); double err = cls.get(j).get_Error(); meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? //the thickness for multiple scattering. MS is outward the thickness is set for the 1st layer in the superlayer @@ -312,105 +300,45 @@ public List setMeasVecs(StraightTrack trkcand, // adding the BMT - if (trkcand.get(i).get_Detector().equalsIgnoreCase("BMT")) { - int lyer = trkcand.get(i).get_Cluster1().get_Layer(); - int sec = trkcand.get(i).get_Cluster1().get_Sector(); + if (trkcand.get(i).get_Detector()==DetectorType.BMT) { + int layer = trkcand.get(i).get_Cluster1().get_Layer(); + int sector = trkcand.get(i).get_Cluster1().get_Sector(); - Cylindrical3D cyl = bgeo.getCylinder(lyer, sec); - Line3D cln = bgeo.getAxis(lyer, sec); - Line3D l = bgeo.getLCZstrip(bgeo.getRegion(lyer), sec, 1, swim); - //cln.set(cln.origin().x(), cln.origin().y(), l.origin().z(), - // cln.end().x(), cln.end().y(), l.end().z()); - cyl.setAxis(cln); int id = trkcand.get(i).get_Cluster1().get_Id(); double ce = trkcand.get(i).get_Cluster1().get_Centroid(); - if (trkcand.get(i).get_DetectorType()==BMTType.Z) { - //double x = trkcand.get_Crosses().get(c).get_Point().x(); - //double y = trkcand.get_Crosses().get(c).get_Point().y(); - Point3D EP1 = trkcand.get(i).get_Cluster1().getEndPoint1(); - //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); - - double v = (EP1.z()-cln.origin().z())/cln.direction().z(); - double x = cln.origin().x()+v*cln.direction().x(); - double y = cln.origin().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, EP1.z()). - vectorTo(new Point3D(EP1.x(),EP1.y(),EP1.z())).asUnit(); - - double phi = n.phi(); - - //double phi = Math.atan2(y,x); + if (trkcand.get(i).get_Type()==BMTType.Z) { + Point3D point = trkcand.get(i).get_Cluster1().getLine().origin(); + double phi = bgeo.getPhi(layer, sector, point); double err = trkcand.get(i).get_Cluster1().get_PhiErr(); - // *(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - - //Strip strp = new Strip(id, ce, x, y, phi); - //Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint1(); - //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); - Strip strp = new Strip(id, ce, x, y, phi); - //Strip strp = new Strip( id, ce, EP1.x(), EP1.y(), EP1.z(), EP2.x(), EP2.y(), EP2.z()); - - //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); - //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - Surface meas = new Surface(cyl, strp); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); - Point3D offset = bgeo.getOffset(trkcand.get(i).get_Cluster1().get_Layer(), - trkcand.get(i).get_Sector()); - Vector3D rotation = bgeo.getRotation(trkcand.get(i).get_Cluster1().get_Layer(), - trkcand.get(i).get_Sector()); - meas.cylShift = offset; - meas.cylRotation = rotation; + bgeo.toLocal(point, layer, sector); + Strip strp = new Strip(id, ce, point.x(), point.y(), phi); + Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp); + meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); + meas.setTransformation(bgeo.toGlobal(layer,sector)); meas.setSector(trkcand.get(i).get_Sector()); - //meas.setLayer(i+1); meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? //for multiple scattering - double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]; - meas.setl_over_X0(thickn_ov_X0); - //if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { - //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); - //meas.notUsedInFit=true; - //} + meas.setl_over_X0(bgeo.getToverX0(layer)); KFSites.add(meas); clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); } - if (trkcand.get(i).get_DetectorType()==BMTType.C) { - double z = trkcand.get(i).get_Point().z(); + else if (trkcand.get(i).get_Type()==BMTType.C) { + double z = trkcand.get(i).get_Point().z(); double err = trkcand.get(i).get_Cluster1().get_ZErr(); - Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); - //Point3D ct = new Point3D(trkcand.get(i).get_Cluster1().getCx(), - // trkcand.get(i).get_Cluster1().getCy(), - // trkcand.get(i).get_Cluster1().getCz()); - // Point3D og = new Point3D(trkcand.get(i).get_Cluster1().getOx(), - // trkcand.get(i).get_Cluster1().getOy(), - // trkcand.get(i).get_Cluster1().getOz()); - //arc.setCenter(ct); - //arc.setOrigin(og); + Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); Strip strp = new Strip(id, ce, arc); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(lyer)); - - Surface meas = new Surface(cyl, strp); + + Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); - Point3D offset = bgeo.getOffset(trkcand.get(i).get_Cluster1().get_Layer(), - trkcand.get(i).get_Sector()); - Vector3D rotation = bgeo.getRotation(trkcand.get(i).get_Cluster1().get_Layer(), - trkcand.get(i).get_Sector()); - meas.cylShift = offset; - meas.cylRotation = rotation; + meas.setTransformation(bgeo.toGlobal(layer,sector)); - meas.setSector(trkcand.get(i).get_Sector()); - //meas.setLayer(i+1); + meas.setSector(sector); meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? //for multiple scattering - double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get(i).get_Cluster1().get_Layer() + 1) / 2 - 1]; - meas.setl_over_X0(thickn_ov_X0); - //if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { - // //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); - // meas.notUsedInFit=true; - //} + meas.setl_over_X0(bgeo.getToverX0(layer)); KFSites.add(meas); clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); @@ -498,13 +426,13 @@ public void MatchTrack2Traj(Seed trkcand, Map reFitSeed(Seed bseed, for(Cross c : bseed.get_Crosses()) { int layr = 0; int layr2 = 0; - if(c.get_Detector().equalsIgnoreCase("BMT")) { + if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; @@ -753,7 +668,7 @@ public List reFitSeed(Seed bseed, int layr = 0; int layr2 = 0; c.set_AssociatedTrackID(-1); - if(c.get_Detector().equalsIgnoreCase("BMT")) { + if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; @@ -809,7 +724,7 @@ public List reFitSeed(StraightTrack cand, for(Cross c : cand) { int layr = 0; int layr2 = 0; - if(c.get_Detector().equalsIgnoreCase("BMT")) { + if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index abd169483..41390a8cb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Point3D; @@ -129,7 +130,7 @@ public boolean processEvent(DataEvent event, if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) { Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); for(Cross c : fittedTrack) { - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { c.get_Cluster1().set_AssociatedTrackID(0); c.get_Cluster2().set_AssociatedTrackID(0); } @@ -259,7 +260,7 @@ public boolean processEvent(DataEvent event, if( c.get_AssociatedTrackID() < 0 ) { c.set_Dir( new Vector3D(0,0,0)); c.set_DirErr( new Vector3D(0,0,0)); - if( c.get_DetectorType()==BMTType.C) { + if( c.get_Type()==BMTType.C) { c.set_Point(new Point3D(Double.NaN,Double.NaN,c.get_Point().z())); } else { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java index c74fc4226..46419ee27 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java @@ -6,6 +6,7 @@ import javax.vecmath.Point2d; import javax.vecmath.Vector2d; +import org.jlab.detector.base.DetectorType; /** * Base cell for the cellular automaton @@ -78,7 +79,7 @@ public Point2d get_Crs2D( int i, String vw ){ } if( vw.equalsIgnoreCase("ZR")){ double R = 0.; - if( cross.get_Detector().equalsIgnoreCase("SVT")){ + if( cross.get_Detector()==DetectorType.BST){ R = Math.sqrt(cross.get_Point().x()*cross.get_Point().x() + cross.get_Point().y()*cross.get_Point().y() ); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 0e9a3c87c..377b142b7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -2,6 +2,7 @@ import java.util.*; import javax.vecmath.Vector2d; +import org.jlab.detector.base.DetectorType; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -40,10 +41,10 @@ public MakerCA(){ private double getCrossRadius( Cross c ) { // TODO: can this be moved inside the Cross class? - if( c.get_Detector().equalsIgnoreCase("SVT") ) + if( c.get_Detector()==DetectorType.BST) return Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); - if( c.get_DetectorType()==BMTType.Z ) + if( c.get_Type()==BMTType.Z ) return org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[c.get_Region()-1 ]; return org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[c.get_Region()-1 ]; @@ -75,8 +76,8 @@ private boolean checkAngles( Cell cell ) { if( this._plane.equalsIgnoreCase("ZR")) { // on ZR, make loose selection on SVT // and tight selections on BMT - if( cell.get_c1().get_Detector().equalsIgnoreCase("SVT")) { - if( cell.get_c2().get_Detector().equalsIgnoreCase("SVT")) { + if( cell.get_c1().get_Detector()==DetectorType.BST) { + if( cell.get_c2().get_Detector()==DetectorType.BST) { if( Math.toDegrees(va.angle(vb)) > 30. ) return false; } else @@ -100,12 +101,12 @@ public void createCells( List crs, BMTGeometry bgeom ){ for( int ic=0;ic crs, BMTGeometry bgeom ){ // we skip same region crosses int bReg = b.get_Region(); - if( b.get_Detector().equalsIgnoreCase("BMT")) { - bReg = 3 + bgeom.getLayer( bReg , b.get_DetectorType() ); + if( b.get_Detector()==DetectorType.BMT) { + bReg = 3 + bgeom.getLayer( bReg , b.get_Type() ); } if( this._debug ) { - System.out.println( " cross b " + b.get_Id() + " " + b.get_Detector() +b.get_DetectorType() + " sect:" + b.get_Sector() + " reg:" + System.out.println( " cross b " + b.get_Id() + " " + b.get_Detector().getName() +b.get_Type().getName() + " sect:" + b.get_Sector() + " reg:" + bReg + " phi:" + b.get_Point().toVector3D().phi() + " in BMT sector:" + bgeom.getSector(1, b.get_Point().toVector3D().phi() )); } @@ -144,8 +145,8 @@ public void createCells( List crs, BMTGeometry bgeom ){ } // stay in the same BMT sector - if( b.get_Detector().equalsIgnoreCase("BMT") ){ - if( a.get_Detector().equalsIgnoreCase("BMT")){ + if( b.get_Detector()==DetectorType.BMT){ + if( a.get_Detector()==DetectorType.BMT){ if(b.get_Sector() != a.get_Sector() ) continue; } else{ @@ -173,7 +174,7 @@ public void createCells( List crs, BMTGeometry bgeom ){ // when running on ZR // if both cells are SVT, check that they are "ok" in xy if( this._plane.equalsIgnoreCase("ZR")){ - if( b.get_Detector().equalsIgnoreCase("SVT") ){ + if( b.get_Detector()==DetectorType.BST){ double xaxy = scell.get_Crs2D(1, "XY").x; double yaxy = scell.get_Crs2D(1, "XY").y; Vector2d vaxy = new Vector2d(xaxy,yaxy); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index 1432892b8..77a8de1ad 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.track; import java.util.Map; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -33,7 +34,7 @@ public StraightTrack(Ray ray) { */ public void update_Crosses(double fit_yxslope, double fit_yzslope, SVTGeometry geo) { for (Cross c : this) { - if (c.get_Detector().equalsIgnoreCase("SVT")) //only update for the svt + if (c.get_Detector()==DetectorType.BST) //only update for the svt { update_Cross(c, fit_yxslope, fit_yzslope, geo); } @@ -42,7 +43,7 @@ public void update_Crosses(double fit_yxslope, double fit_yzslope, SVTGeometry g } public void reset_Crosses() { for (Cross c : this) { - if (c.get_Detector().equalsIgnoreCase("SVT")) //only update for the svt + if (c.get_Detector()==DetectorType.BST) //only update for the svt { c.set_Point(c.get_Point0()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 275b52476..5c65368ee 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -97,7 +98,7 @@ private void FitSeed(List seedcrs) { Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); + if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); @@ -233,9 +234,9 @@ public List findSeed(List svt_crosses, List bmt_crosses, if(isSVTOnly == false ) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType()== BMTType.Z) + if(c.get_Type()== BMTType.Z) crosses.add(c); - if(c.get_DetectorType()==BMTType.C) + if(c.get_Type()==BMTType.C) bmtC_crosses.add(c); } } @@ -248,7 +249,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) continue; + if(c.get_Type()==BMTType.C ) continue; c.set_AssociatedTrackID(122220); } // loop until a good circular fit. removing far crosses each time @@ -265,7 +266,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) continue; + if(c.get_Type()==BMTType.C ) continue; c.set_AssociatedTrackID(122221); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); @@ -284,7 +285,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, double r = pars.rho(); double f = pars.phi(); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) continue; + if(c.get_Type()==BMTType.C ) continue; c.set_AssociatedTrackID(122222); double xi = c.get_Point().x(); double yi = c.get_Point().y(); @@ -314,7 +315,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List clusters = new ArrayList(); for(Cross c : seed.get_Crosses()) { c.set_AssociatedTrackID(1111); - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); } else { @@ -527,7 +528,7 @@ public List findCandUsingMicroMegas(Seed trkCand, //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_DetectorType()==BMTType.C) {// C-detector + if (bmt_cross.get_Type()==BMTType.C) {// C-detector BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index b6cb20c34..d8f8ba154 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.track; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cross.Cross; @@ -139,7 +140,7 @@ public void update_Crosses(SVTGeometry geo) { Helix helix = this.get_helix(); for (int i = 0; i < this.size(); i++) { - if (!this.get(i).get_Detector().equalsIgnoreCase("SVT")) { + if (this.get(i).get_Detector()!=DetectorType.BST) { continue; } double R = Math.sqrt(this.get(i).get_Point().x() * this.get(i).get_Point().x() + this.get(i).get_Point().y() * this.get(i).get_Point().y()); @@ -169,7 +170,7 @@ public void finalUpdate_Crosses(SVTGeometry geo) { Helix helix = this.get_helix(); for (int i = 0; i < this.size(); i++) { - if (!this.get(i).get_Detector().equalsIgnoreCase("SVT")) { + if (this.get(i).get_Detector()!=DetectorType.BST) { continue; } double R = Math.sqrt(this.get(i).get_Point().x() * this.get(i).get_Point().x() + this.get(i).get_Point().y() * this.get(i).get_Point().y()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index bfec00cce..6e513fbad 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; @@ -437,7 +438,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List hitsOnTrack = new ArrayList(); for (Cross c : cand) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { hitsOnTrack.add(c); } } @@ -562,14 +563,14 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, //make lists for (Cross c : list) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { SVTcrossesInTrk.add(c); } - if (c.get_Detector().equalsIgnoreCase("BMT")) { // Micromegas - if (c.get_DetectorType() == BMTType.C) {//C-detector --> only Z defined + if (c.get_Detector()==DetectorType.BMT) { // Micromegas + if (c.get_Type() == BMTType.C) {//C-detector --> only Z defined BMTCdetcrossesInTrk.add(c); } - if (c.get_DetectorType() == BMTType.Z) {//Z-detector --> only phi defined + if (c.get_Type() == BMTType.Z) {//Z-detector --> only phi defined BMTZdetcrossesInTrk.add(c); } } @@ -698,14 +699,14 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, //make lists for (Cross c : arrayList) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { SVTcrossesInTrk.add(c); } - if (c.get_Detector().equalsIgnoreCase("BMT")) { // Micromegas - if (c.get_DetectorType() == BMTType.C) {//C-detector --> only Z defined + if (c.get_Detector()==DetectorType.BMT) { // Micromegas + if (c.get_Type() == BMTType.C) {//C-detector --> only Z defined BMTCdetcrossesInTrk.add(c); } - if (c.get_DetectorType()==BMTType.Z) {//Z-detector --> only phi defined + if (c.get_Type()==BMTType.Z) {//Z-detector --> only phi defined BMTZdetcrossesInTrk.add(c); } } @@ -886,7 +887,7 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse continue; } //if(Double.isNaN(MMCrosses.get(i).get_Point0().z())) - if (MMCrosses.get(i).get_DetectorType()==BMTType.Z) { + if (MMCrosses.get(i).get_Type()==BMTType.Z) { continue; } double m_z = MMCrosses.get(i).get_Point().z(); @@ -954,7 +955,7 @@ private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosse } // measuring phi //if(Double.isNaN(MMCrosses.get(i).get_Point0().x())) - if (MMCrosses.get(i).get_DetectorType()==BMTType.C) { + if (MMCrosses.get(i).get_Type()==BMTType.C) { continue; } double m_x = MMCrosses.get(i).get_Point().x(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 9ec38b0fb..3a3a4652d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; @@ -88,7 +89,7 @@ private void assignTrkPID(Track trk) { int NbHits = 0; double TotE = 0; for (int i = 0; i < trk.size(); i++) { - if (trk.get(i).get_Detector() != "SVT") { + if (trk.get(i).get_Detector() != DetectorType.BST) { continue; } for (int j = 0; j < trk.get(i).get_Cluster1().size(); j++) { @@ -170,7 +171,7 @@ private void getOverlapLists(Track track, List trkcands, List list for( Cross c : t ) { // do not check on BMTC - if( c.get_DetectorType()==BMTType.C == true ) continue; + if( c.get_Type()==BMTType.C) continue; if( track.contains(c) ) { N++; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index eb8020fbd..8e47f048e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -86,7 +87,7 @@ public void FitSeed(List seedcrs) { Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); + if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); @@ -223,7 +224,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, if(bmt_crosses!=null && bmt_crosses.size()>0) { for(Cross c : bmt_crosses) { - if(c.get_DetectorType()==BMTType.Z) { + if(c.get_Type()==BMTType.Z) { if(this.unUsedHitsOnly == false) { crosses.add(c); } else { @@ -232,7 +233,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, } } } - if(c.get_DetectorType()==BMTType.C) { + if(c.get_Type()==BMTType.C) { if(this.unUsedHitsOnly == false) { bmtC_crosses.add(c); } else { @@ -260,7 +261,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, for(Seed mseed : seedScan) { List seedcrs = mseed.get_Crosses(); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) continue; + if(c.get_Type()==BMTType.C ) continue; c.set_AssociatedTrackID(122220); } // loop until a good circular fit. removing far crosses each time @@ -277,7 +278,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C ) continue; + if(c.get_Type()==BMTType.C ) continue; c.set_AssociatedTrackID(122221); Xs.add(c.get_Point().x()); Ys.add(c.get_Point().y()); @@ -296,7 +297,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, double r = pars.rho(); double f = pars.phi(); for (Cross c : seedcrs ) { - if(c.get_DetectorType()==BMTType.C) continue; + if(c.get_Type()==BMTType.C) continue; c.set_AssociatedTrackID(122222); double xi = c.get_Point().x(); double yi = c.get_Point().y(); @@ -326,7 +327,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, List clusters = new ArrayList(); for(Cross c : seed.get_Crosses()) { c.set_AssociatedTrackID(1111); - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); } else { @@ -563,7 +564,7 @@ public List findCandUsingMicroMegas(Seed trkCand, //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_DetectorType()==BMTType.C) // C-detector + if (bmt_cross.get_Type()==BMTType.C) // C-detector BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 4574fd549..25d19f3b6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.base.DetectorType; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -76,7 +77,7 @@ public List> getCAcandidates( List nodes, SVTGeometry svt if( cn.get_state() >= ms ){ ms = cn.get_state(); if( neighbour.get_plane().equalsIgnoreCase("ZR") && - neighbour.get_c1().get_Detector().equalsIgnoreCase("SVT") ){ + neighbour.get_c1().get_Detector()==DetectorType.BST){ if( cn.get_length() < dist ){ dist = cn.get_length(); id = ic; @@ -203,9 +204,9 @@ public List findSeed(List svt_crosses, List bmt_crosses, // Collections.sort(crosses); for(Cross c : bmt_crosses) { - if(c.get_DetectorType()==BMTType.Z) + if(c.get_Type()==BMTType.Z) crosses.add(c); - if(c.get_DetectorType()==BMTType.C) { + if(c.get_Type()==BMTType.C) { bmtC_crosses.get(c.get_Sector()-1).add(c); } } @@ -251,7 +252,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List clusters = new ArrayList(); Collections.sort(seed.get_Crosses()); for(Cross c : seed.get_Crosses()) { - if(c.get_Detector().equalsIgnoreCase("SVT")) { + if(c.get_Detector()==DetectorType.BST) { clusters.add(c.get_Cluster1()); clusters.add(c.get_Cluster2()); } else { @@ -348,7 +349,7 @@ public List> CAonRZ( //------------------------------------------------------------------ int sector = -1; for( Cross c : xycross ){ - if( c.get_Detector().equalsIgnoreCase("SVT")){ + if( c.get_Detector()==DetectorType.BST){ svtcrs.add(c); // System.out.print( " " + c.get_Id() + " " +c.get_Detector() + " " + c.get_DetectorType() + " ; " ); } @@ -449,14 +450,14 @@ public List> CAonRZ( // add bmt z for( Cross c : xycross ){ - if( c.get_Detector().equalsIgnoreCase("BMT")){ + if( c.get_Detector()==DetectorType.BMT){ seedCrosses.get(scsize-1).add(c); } } // add bmt c for( Cross c : zrcross ){ - if( c.get_Detector().equalsIgnoreCase("BMT")){ + if( c.get_Detector()==DetectorType.BMT){ seedCrosses.get(scsize-1).add(c); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 2f8371e55..b5b46eeac 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -72,7 +72,7 @@ public Trajectory findTrajectory(Track trk, ArrayList BMTCrossList = new ArrayList(); Map ClsMap = new HashMap(); for (Cross c : candCrossList) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { String svtSt1 = "1."; svtSt1+=c.get_Cluster1().get_Sector(); svtSt1 += "."; @@ -368,7 +368,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList Map ClsMap = new HashMap(); for (Cross c : candCrossList) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { String svtSt1 = "1."; svtSt1+=c.get_Cluster1().get_Sector(); svtSt1 += "."; @@ -518,7 +518,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList continue; } - if (c.get_DetectorType()==BMTType.C) { //C-detector measuring Z + if (c.get_Type()==BMTType.C) { //C-detector measuring Z //if(traj.isFinal) { // reset the cross only for final trajectory c.set_Point(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.get_Point().z())); @@ -530,7 +530,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList stVec, svt_geo, bmt_geo, traj.isFinal); } - if (c.get_DetectorType()==BMTType.Z) { //Z-detector measuring phi + if (c.get_Type()==BMTType.Z) { //Z-detector measuring phi //if(traj.isFinal) { c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), ZtrackIntersSurf)); @@ -562,7 +562,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sector) { - if (c.get_Detector().equalsIgnoreCase("SVT")) { + if (c.get_Detector()==DetectorType.BST) { int l = layer - 1; if (c.get_Region() != (int) (l / 2) + 1) { @@ -577,7 +577,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec } } - if (c.get_Detector().equalsIgnoreCase("BMT")) { // BMT + if (c.get_Detector()==DetectorType.BMT) { // BMT double Rsv = Math.sqrt(stVec.x()*stVec.x()+stVec.y()*stVec.y()); double Rcs = Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); @@ -606,7 +606,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); - double doca2Seed = svt_geo.getDOCAToStrip(sector, layer, (double) cluster.get_SeedStrip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); + double doca2Seed = svt_geo.getDOCAToStrip(sector, layer, (double) cluster.get_SeedStrip().get_Strip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); cluster.set_SeedResidual(doca2Seed); cluster.set_CentroidResidual(doca2Cls); cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); @@ -634,18 +634,12 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl double ce = cluster.get_Centroid(); Point3D p = new Point3D(stVec.x(), stVec.y(), stVec.z()); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z - Arc3D arcC = cluster.get_Arc(); - double doca2Cls = bmt_geo.getBMTCresi(arcC, p, offset, rotation); - cluster.set_CentroidResidual(doca2Cls); + cluster.set_CentroidResidual(p); + cluster.set_SeedResidual(p); for (FittedHit h1 : cluster) { // calculate the hit residuals - Arc3D arcH = h1.get_Strip().get_Arc(); - double doca1 = bmt_geo.getBMTCresi(arcH, p, offset, rotation); - //double doca1 = p.z()-hit.get_Strip().get_Z(); - if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip()) - cluster.set_SeedResidual(doca1); h1.set_TrkgStatus(1); - h1.set_docaToTrk(doca1); + h1.set_docaToTrk(p); h1.set_TrkgStatus(1); if (trajFinal) { h1.set_TrkgStatus(2); @@ -658,19 +652,19 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl int blayer = cluster.get_Layer(); double cxh = Math.cos(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double cyh = Math.sin(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double phic = bmt_geo.getPhi(new Point3D(cxh,cyh,0), bsector, blayer); - double phit = bmt_geo.getPhi(p, sector, blayer); + double phic = bmt_geo.getPhi(blayer, bsector, new Point3D(cxh,cyh,0)); + double phit = bmt_geo.getPhi(blayer, bsector, p); double doca2Cls = (phic-phit)*bmt_geo.getRadiusMidDrift(blayer); cluster.set_CentroidResidual(doca2Cls); for (FittedHit h1 : cluster) { double xh = Math.cos(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double yh = Math.sin(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double hphic = bmt_geo.getPhi(new Point3D(xh,yh,0), sector, blayer); - double hphit = bmt_geo.getPhi(p, sector, blayer); + double hphic = bmt_geo.getPhi(blayer, bsector, new Point3D(xh,yh,0)); + double hphit = bmt_geo.getPhi(blayer, bsector, p); double doca1 = (hphic-hphit)*bmt_geo.getRadiusMidDrift(blayer); - if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip()) + if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip().get_Strip()) cluster.set_SeedResidual(doca1); h1.set_TrkgStatus(1); @@ -903,24 +897,16 @@ private double[][] getIntersectionTrackWithBMTModules(int l, int bottomstp = 0; if(top.toVector3D().mag()>0 && geo.getSector(lyer, top.toVector3D().phi())>0) { topsec = geo.getSector(lyer, top.toVector3D().phi()); - offset = geo.getOffset(lyer, topsec); - rotation = geo.getRotation(lyer, topsec); - ioffset = geo.getInverseOffset(lyer, topsec); - irotation = geo.getInverseRotation(lyer, topsec); - geo.putInFrame(trkOr, ioffset, irotation, true); - geo.putInFrame(trkEn, ioffset, irotation, true); + trkOr = geo.toLocal(trkOr, lyer, topsec); + trkEn = geo.toLocal(trkEn, lyer, topsec); intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); top = intersNominal.get(0); topstp = geo.getStrip( l + 1, topsec, top); } if(bottom.toVector3D().mag()>0 && geo.getSector(lyer, bottom.toVector3D().phi())>0) { bottomsec = geo.getSector(lyer, bottom.toVector3D().phi()); - offset = geo.getOffset(lyer, bottomsec); - rotation = geo.getRotation(lyer, bottomsec); - ioffset = geo.getInverseOffset(lyer, bottomsec); - irotation = geo.getInverseRotation(lyer, bottomsec); - geo.putInFrame(trkOr, ioffset, irotation, true); - geo.putInFrame(trkEn, ioffset, irotation, true); + trkOr = geo.toLocal(trkOr, lyer, bottomsec); + trkEn = geo.toLocal(trkEn, lyer, bottomsec); intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); bottom = intersNominal.get(1); bottomstp = geo.getStrip( l + 1, bottomsec, bottom); From f689966701cdfef82314cfd2a12327dc48cfa2cb Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 18 Sep 2021 16:23:16 +0200 Subject: [PATCH 166/291] CVT: rename BMT geometry class --- .../cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index e238755eb..2a4590d51 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -875,7 +875,7 @@ public double getThetaLorentz(int layer, int sector) { double solenoidScale = org.jlab.rec.cvt.Constants.getSolenoidscale(); - if(Math.abs(solenoidScale)<0.001 || true) { + if(Math.abs(solenoidScale)<0.001) { thetaL = 0; } else { From 55ccc98ec8416420dbe659d430b15db452ca0caa Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 18 Sep 2021 16:30:04 +0200 Subject: [PATCH 167/291] CVT: removing hardcoded rotation --- .../src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index d2dcf97d2..70e58d60e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -296,7 +296,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); - double angle = -2;//Math.toDegrees(0.003); + double angle = 0;//Math.toDegrees(0.003); for (int row = 0; row Date: Wed, 22 Sep 2021 18:20:48 -0400 Subject: [PATCH 168/291] max residuals for each detector separately Also added reading the Cx, Cy, Cz cluster banks to the RecoBankReader --- .../jlab/rec/cvt/banks/RecoBankReader.java | 12 +- .../jlab/rec/cvt/services/CVTAlignment.java | 115 ++++++++++++++---- 2 files changed, 101 insertions(+), 26 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index aaf197abc..67d774ed1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -160,7 +160,9 @@ public void fetch_BMTClusters(DataEvent event) { bank.getFloat("lz", i))); cluster.set_Error(bank.getFloat("e", i)); - + cluster.setCx(bank.getFloat("cx", i)); + cluster.setCy(bank.getFloat("cy", i)); + cluster.setCz(bank.getFloat("cz", i)); cluster.setOx(bank.getFloat("ox", i)); cluster.setOy(bank.getFloat("oy", i)); cluster.setOz(bank.getFloat("oz", i)); @@ -299,11 +301,11 @@ public void fetch_Tracks(DataEvent event, org.jlab.rec.cvt.svt.Geometry geo, dou float curvatures[]; - try { - curvatures = bank.getFloat("curvature"); - }catch(Exception e){ + //try { + // curvatures = bank.getFloat("curvature"); + //}catch(Exception e){ curvatures = new float[ids.length]; - } + //} /*bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); bank.setFloat("tandip", i, (float) helix.get_tandip()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 416fd9a52..f2a2985f2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -213,6 +213,7 @@ public boolean processDataEvent(DataEvent event) { //System.out.println("BMT crosses"); int nCrossSVT = 0, nCrossBMT = 0; + int countBMTZ = 0, countBMTC = 0; for(Cross c : track) { if(c.get_Detector().equalsIgnoreCase("SVT") && !isBMTonly) { nCrossSVT++; @@ -222,10 +223,12 @@ public boolean processDataEvent(DataEvent event) { if (c.get_DetectorType() != BMTType.C || ! skipBMTC) nCrossBMT++; if (c.get_DetectorType() == BMTType.C) { + countBMTC++; gCountBMTC++; } if(c.get_DetectorType() == BMTType.Z) { gCountBMTZ++; + countBMTZ++; } //System.out.println(c.get_Sector()+" "+c.get_Region() + " " + c.get_Cluster1().get_Centroid()+" " + c.get_Id()); } @@ -234,6 +237,15 @@ public boolean processDataEvent(DataEvent event) { System.exit(0); } } + + + if(nCrossSVT*2maxResidualCut) - return false; + //if(Math.abs(ci-mi)>50) + // return false; c.set(i,0,ci); m.set(i,0,mi); @@ -676,36 +688,46 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, else { // BMTC Vector3D a = cl.getCylAxis().direction().asUnit(); - - System.out.println("a: " +a); + if(debug) + System.out.println("a: " +a); Vector3D cc = cl.getCylAxis().origin().toVector3D(); Vector3D uT = perp(u,a); + Vector3D tmp1 = perp(xref.clone().sub(cc),a); + Vector3D endpoint = new Vector3D(cl.getX1(),cl.getY1(),cl.getZ1()); + double R = perp(endpoint.clone().sub(cc),a).mag(); - System.out.println("R: " + R); + if(debug) + System.out.println("R: " + R); double AA = uT.mag2(); - double BB = -2*xref.clone().sub(cc).dot(uT); - double CC = perp(xref.clone().sub(cc),a).mag2()-R*R; + + + double BB = 2*tmp1.dot(uT); + double CC = tmp1.mag2()-R*R; double lambda_plus = (-BB+Math.sqrt(BB*BB-4*AA*CC))/(2*AA); double lambda_minus = (-BB-Math.sqrt(BB*BB-4*AA*CC))/(2*AA); Vector3D extrap_plus = xref.clone().add(u.multiply(lambda_plus)); Vector3D extrap_minus = xref.clone().add(u.multiply(lambda_minus)); - - //if(extrap_plus.clone().sub(O).mag()maxResidualCut) { + if(Math.abs(ci-mi)>maxResidualCutSVT && detector.equals("SVT") || + Math.abs(ci-mi)>maxResidualCutBMTZ && detector.equals("BMTZ") || + Math.abs(ci-mi)>maxResidualCutBMTC && detector.equals("BMTC")) { if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); return false; } @@ -1006,7 +1030,7 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, double ci = s.dot(extrap); double mi = s.dot(e); - if(Math.abs(ci-mi)>maxResidualCut) { + if(Math.abs(ci-mi)>maxResidualCutSVT) { if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); return false; } @@ -1029,6 +1053,9 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, } boolean debug = false; + private int minClustersSVT = 0; + private int minClustersBMTC = 0; + private int minClustersBMTZ = 0; private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, @@ -1172,7 +1199,7 @@ private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, System.out.println("u: " + u.toString()); System.out.println("m: " + mi); System.out.println("c: " + ci); - if(Math.abs(ci-mi)>maxResidualCut) + if(Math.abs(ci-mi)>maxResidualCutBMTZ) return false; return true; @@ -1325,7 +1352,7 @@ private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, System.out.println("c: " + ci); } - if(Math.abs(ci-mi)>maxResidualCut) + if(Math.abs(ci-mi)>maxResidualCutBMTC) return false; c.set(i,0,ci); m.set(i,0,mi); @@ -1512,14 +1539,58 @@ public boolean init() { if (maxResidual!=null) { System.out.println("["+this.getName()+"] run with cut on maximum residual "+maxResidual+" config chosen based on yaml"); - this.maxResidualCut = Double.valueOf(maxResidual); + this.maxResidualCutBMTZ = this.maxResidualCutBMTC = this.maxResidualCutSVT = Double.valueOf(maxResidual); } if (maxResidual==null) { System.out.println("["+this.getName()+"] run with maximum residual cut setting default = none"); - this.maxResidualCut = Double.MAX_VALUE; + this.maxResidualCutBMTC = Double.MAX_VALUE; + this.maxResidualCutBMTZ = Double.MAX_VALUE; + this.maxResidualCutSVT = Double.MAX_VALUE; } + + maxResidual = this.getEngineConfigString("maxResidualBMTZ"); + if (maxResidual!=null) { + System.out.println("["+this.getName()+"] run with cut on maximum BMTZ residual "+maxResidual+" config chosen based on yaml"); + this.maxResidualCutBMTZ = Double.valueOf(maxResidual); + } + + maxResidual = this.getEngineConfigString("maxResidualBMTC"); + + if (maxResidual!=null) { + System.out.println("["+this.getName()+"] run with cut on maximum BMTC residual "+maxResidual+" config chosen based on yaml"); + this.maxResidualCutBMTC = Double.valueOf(maxResidual); + } + + maxResidual = this.getEngineConfigString("maxResidualSVT"); + + if (maxResidual!=null) { + System.out.println("["+this.getName()+"] run with cut on maximum SVT residual "+maxResidual+" config chosen based on yaml"); + this.maxResidualCutSVT = Double.valueOf(maxResidual); + } + + String minClusters = this.getEngineConfigString("minClustersSVT"); + + if (minClusters!=null) { + System.out.println("["+this.getName()+"] run with cut on minimum SVT clusters "+minClusters+" config chosen based on yaml"); + this.minClustersSVT = Integer.valueOf(minClusters); + } + + minClusters = this.getEngineConfigString("minClustersBMTZ"); + + if (minClusters!=null) { + System.out.println("["+this.getName()+"] run with cut on minimum BMTZ clusters "+minClusters+" config chosen based on yaml"); + this.minClustersBMTZ = Integer.valueOf(minClusters); + } + + minClusters = this.getEngineConfigString("minClustersBMTC"); + + if (minClusters!=null) { + System.out.println("["+this.getName()+"] run with cut on minimum BMTZ clusters "+minClusters+" config chosen based on yaml"); + this.minClustersBMTC = Integer.valueOf(minClusters); + } + for(int layer = 0; layer<6; layer++) { Line3d line = SVTGeom.getStrip(layer, 0, 0); @@ -1546,7 +1617,9 @@ public boolean init() { double xb, yb; - double maxResidualCut; + double maxResidualCutSVT; + double maxResidualCutBMTC; + double maxResidualCutBMTZ; double maxDocaCut; From 2b6616f6069b3a1ab6e179cbee94b4d88594f53c Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Thu, 23 Sep 2021 10:20:23 -0400 Subject: [PATCH 169/291] output track parameters in output of pre-alignment --- .../org/jlab/rec/cvt/services/CVTAlignment.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index f2a2985f2..375fbd5ab 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -196,6 +196,7 @@ public boolean processDataEvent(DataEvent event) { List Vs = new ArrayList(); List ms = new ArrayList(); List cs = new ArrayList(); + List qs = new ArrayList(); List trackIDs = new ArrayList(); if (tracks.size() < 3) @@ -272,7 +273,15 @@ public boolean processDataEvent(DataEvent event) { Matrix m = new Matrix(rows,1); Matrix c = new Matrix(rows,1); Matrix I = new Matrix(rows,1); - + Matrix q = new Matrix(4, 1); //track parameters, for plotting kinematic dependence. Not used in KFA. + + q.set(0, 0, track.get_helix().get_dca()); + q.set(1, 0, track.get_helix().get_phi_at_dca()); + q.set(2, 0, track.get_helix().get_Z0()); + q.set(3, 0, track.get_helix().get_tandip()); + + q.print(4, 4); + int i = 0; boolean useNewFillMatrices = true; for(Cross cross : track) { @@ -396,6 +405,7 @@ else if(cross.get_DetectorType() == BMTType.C) { ms.add(m); cs.add(c); Is.add(I); + qs.add(q); //c.print(7, 4); @@ -410,6 +420,7 @@ else if(cross.get_DetectorType() == BMTType.C) { writer.write_Matrix(event, "V", Vs); writer.write_Matrix(event, "m", ms); writer.write_Matrix(event, "c", cs); + writer.write_Matrix(event, "q", qs); fillMisc(event,runNum,eventNum,trackIDs,As,Bs,Vs,ms,cs,Is); System.out.println("BMTC total clusters: " + gCountBMTC+"; BMTZ total clusters: " + gCountBMTZ+"; SVT total crosses: "+ gCountSVT); //event.show(); From dfc56998b14000b190b794658ac865a8b9995b25 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 27 Sep 2021 10:54:13 +0200 Subject: [PATCH 170/291] CVT: further restructuring of cluster class, added geometry info to strip class, fixed issue with helix not allowing to calculate point at given radius for straight tracks, switched from arc-strip to z-strip in BMT-C KF, fixed issue with grid interpolation for Lorents angle calculation and wrong assignment of Edrift for MC --- .../clas/tracking/kalmanfilter/Surface.java | 48 +-- .../kalmanfilter/helical/MeasVecs.java | 28 +- .../kalmanfilter/helical/StateVecs.java | 26 +- .../org/jlab/clas/tracking/objects/Strip.java | 14 + etc/bankdefs/hipo4/bmt.json | 5 +- .../org/jlab/rec/cvt/banks/HitReader.java | 11 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 6 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 114 ++++---- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 22 +- .../java/org/jlab/rec/cvt/bmt/Constants.java | 4 +- .../java/org/jlab/rec/cvt/bmt/Lorentz.java | 167 ++++++----- .../org/jlab/rec/cvt/cluster/Cluster.java | 276 ++++++++++-------- .../jlab/rec/cvt/cluster/ClusterFinder.java | 4 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 2 +- .../java/org/jlab/rec/cvt/hit/FittedHit.java | 18 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 88 +++--- .../jlab/rec/cvt/services/CVTRecNewKF.java | 4 +- .../jlab/rec/cvt/services/RecUtilities.java | 137 ++------- .../rec/cvt/services/TracksFromTargetRec.java | 10 +- .../java/org/jlab/rec/cvt/track/Track.java | 3 +- .../org/jlab/rec/cvt/trajectory/Helix.java | 18 +- 21 files changed, 513 insertions(+), 492 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java index f0ca3dc3e..90c78068c 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -11,7 +11,6 @@ import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Transformation3D; -import org.jlab.geom.prim.Vector3D; /** * @@ -27,10 +26,8 @@ public class Surface implements Comparable { public Point3D finitePlaneCorner1; public Point3D finitePlaneCorner2; public Cylindrical3D cylinder; -// public Point3D cylShift; -// public Vector3D cylRotation; - private Transformation3D toGlobal; - private Transformation3D toLocal; + private Transformation3D toGlobal = new Transformation3D(); + private Transformation3D toLocal = new Transformation3D(); public Arc3D arc; public Strip strip; private double error; @@ -90,6 +87,34 @@ public Surface(Cylindrical3D cylinder3d, Point3D endPoint1, Point3D endPoint2) { lineEndPoint2 = endPoint2; } + public Surface(Cylindrical3D cylinder3d, Arc3D refArc, Point3D endPoint1, Point3D endPoint2) { + type = Type.CYLINDERWITHARC; + cylinder = cylinder3d; + arc = refArc; + if(endPoint1 == null) { + lineEndPoint1 = arc.origin(); + } + if(endPoint2 == null) { + lineEndPoint2 = arc.end(); + } + } + + @Override + public String toString() { + String s = "Surface: "; + s = s + String.format("Layer=%d Sector=%d Emisphere=%.1f X0=%.4f Z/AL=%.4f Error=%.4f",this.getLayer(),this.getSector(),this.hemisphere,this.getl_over_X0(),this.getZ_over_A_times_l(),this.getError()); + if(type==Type.PLANEWITHSTRIP) { + s = s + "\n\t" + this.plane.toString(); + s = s + "\n\t" + this.finitePlaneCorner1.toString(); + s = s + "\n\t" + this.finitePlaneCorner2.toString(); + s = s + "\n\t" + this.strip.toString(); + } + else if(type==Type.CYLINDERWITHSTRIP) { + s = s + "\n\t" + this.cylinder.toString(); + s = s + "\n\t" + this.strip.toString(); + } + return s; + } /** * @return the error */ @@ -172,19 +197,6 @@ public void setTransformation(Transformation3D transform) { this.toGlobal = transform; this.toLocal = transform.inverse(); } - - public Surface(Cylindrical3D cylinder3d, Arc3D refArc, - Point3D endPoint1, Point3D endPoint2) { - type = Type.CYLINDERWITHARC; - cylinder = cylinder3d; - arc = refArc; - if(endPoint1 == null) { - lineEndPoint1 = arc.origin(); - } - if(endPoint2 == null) { - lineEndPoint2 = arc.end(); - } - } @Override public int compareTo(Surface o) { diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 26b4f92f0..ab5bdb391 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -96,7 +96,10 @@ public double dh(int k, StateVec stateVec) { value = WL.length()*sideStrip; } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { - value = stateVec.z-this.measurements.get(stateVec.k).surface.strip.getZ(); + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z()-this.measurements.get(stateVec.k).surface.strip.getZ(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); @@ -108,30 +111,17 @@ public double dh(int k, StateVec stateVec) { value = stV.z()-arc.center().z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - value = this.getPhi(stateVec)-this.measurements.get(stateVec.k).surface.strip.getPhi(); + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(sv); + value = sv.toVector3D().phi()-this.measurements.get(stateVec.k).surface.strip.getPhi(); + if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; } } return value; } -// private void antiAlignArc(Point3D offset, Vector3D rotation, Arc3D arcline) { -// Point3D origin = arcline.origin(); -// Vector3D normal = arcline.normal(); -// Point3D center = arcline.center(); -// origin.translateXYZ(-offset.x(),-offset.y(),-offset.z()); -// origin.rotateZ(-rotation.z()); -// origin.rotateY(-rotation.y()); -// origin.rotateX(-rotation.x()); -// center.translateXYZ(-offset.x(),-offset.y(),-offset.z()); -// center.rotateZ(-rotation.z()); -// center.rotateY(-rotation.y()); -// center.rotateX(-rotation.x()); -// normal.rotateZ(-rotation.z()); -// normal.rotateY(-rotation.y()); -// normal.rotateX(-rotation.x()); -// } - public double getPhiATZ(StateVec stateVec) { Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index aae07182b..62964b492 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -13,7 +13,6 @@ import org.jlab.clas.tracking.kalmanfilter.helical.MeasVecs.MeasVec; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Transformation3D; public class StateVecs { @@ -87,9 +86,9 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } if(this.straight) { - Vector3D u = new Vector3D(-(Math.signum(kVec.kappa)) * Math.sin(kVec.phi0), - (Math.signum(kVec.kappa)) * Math.cos(kVec.phi0), - (Math.signum(kVec.kappa)) * kVec.tanL).asUnit(); + Vector3D u = new Vector3D((Math.signum(kVec.kappa)) * Math.sin(kVec.phi0), + -(Math.signum(kVec.kappa)) * Math.cos(kVec.phi0), + -(Math.signum(kVec.kappa)) * kVec.tanL).asUnit(); if(mv.surface.plane!=null) { Line3D toPln = new Line3D(new Point3D(x,y,z),u); @@ -97,24 +96,31 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim int ints = mv.surface.plane.intersection(toPln, inters); kVec.x = inters.x() ; kVec.y = inters.y() ; - kVec.z = inters.z() ; + kVec.z = inters.z() ; } - if(mv.surface.cylinder!=null) { + else if(mv.surface.cylinder!=null) { Point3D st = new Point3D(x,y,z); Vector3D stu = new Vector3D(u.x(),u.y(),u.z()); mv.surface.toLocal().apply(st); mv.surface.toLocal().apply(stu); - double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); - double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(u.x()*stu.x()+stu.y()*stu.y())); + double r = mv.surface.cylinder.baseArc().radius(); + double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(stu.x()*stu.x()+stu.y()*stu.y())); double l = (-(st.x()*stu.x()+st.y()*stu.y())+delta)/(stu.x()*stu.x()+stu.y()*stu.y()); if(Math.signum(st.y()+l*stu.y())!=mv.hemisphere) { l = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); } Point3D cylInt = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); mv.surface.toGlobal().apply(cylInt); - + // RDV: should switch to use clas-geometry intersection method, not done now to alwys return a value +// List inters = new ArrayList<>(); +// int ints = mv.surface.cylinder.intersection(toPln, inters); +// if(ints==1) { +// kVec.x = inters.get(0).x(); +// kVec.y = inters.get(0).y(); +// kVec.z = inters.get(0).z(); +// } kVec.x = cylInt.x(); kVec.y = cylInt.y(); kVec.z = cylInt.z(); @@ -175,7 +181,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } if(mv.surface.cylinder!=null) { - double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); + double r = mv.surface.cylinder.baseArc().radius(); if(useSwimmer==false) { double stepSize = 5; //mm int nSteps = (int) (r/stepSize); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java index c6a1e6d3f..7d23625e6 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java @@ -303,6 +303,20 @@ public Strip(int id, double centroid, Arc3D arc) { type = Type.ARC; } + public String toString() { + String s = String.format("Strip id: %d",super.getId()); + if(this.type==Type.XYZ) { + s = s + String.format("\n\tPoint=(%.4f,%.4f,%.4f) Dir=(%.4f,%.4f,%.4f) Length=%.4f Centroid=%.4f", _x,_y,_z,_ux,_uy,_uz,_length,_c); + } + else if(this.type==Type.PHI) { + s = s + String.format("\n\tXY=(%.4f,%.4f) Phi=%.4f Centroid=%.4f",super.getX(),super.getY(), _phi,_c); + } + else if(this.type==Type.ARC) { + s = s + "\n\t" +_arc.toString() + String.format("\n\tCentroid=%.4f",_c); + } + return s; + } + @Override public boolean equals(Object o) { diff --git a/etc/bankdefs/hipo4/bmt.json b/etc/bankdefs/hipo4/bmt.json index cf3e581f8..ddee7322c 100755 --- a/etc/bankdefs/hipo4/bmt.json +++ b/etc/bankdefs/hipo4/bmt.json @@ -29,6 +29,8 @@ {"name":"seedE", "type":"F", "info":"energy of the seed "}, {"name":"seedStrip", "type":"I", "info":"seed strip"}, {"name":"centroid", "type":"F", "info":"centroid strip number"}, + {"name":"centroidValue", "type":"F", "info":"centroid value (z or phi)"}, + {"name":"centroidError", "type":"F", "info":"centroid value error"}, {"name":"centroidResidual","type":"F", "info":"centroid residual"}, {"name":"seedResidual", "type":"F", "info":"seed residual"}, {"name":"Hit1_ID", "type":"S", "info":"Index of hit 1 in cluster"}, @@ -43,9 +45,6 @@ {"name":"x2", "type":"F", "info":"bmt-Z cluster second end point x"}, {"name":"y2", "type":"F", "info":"bmt-Z cluster second end point y"}, {"name":"z2", "type":"F", "info":"bmt-Z cluster second end point z"}, - {"name":"ox", "type":"F", "info":"bmt-C cluster arc origin x"}, - {"name":"oy", "type":"F", "info":"bmt-C cluster arc origin y"}, - {"name":"oz", "type":"F", "info":"bmt-C cluster arc origin z"}, {"name":"cx", "type":"F", "info":"bmt-C cluster arc center x"}, {"name":"cy", "type":"F", "info":"bmt-C cluster arc center y"}, {"name":"cz", "type":"F", "info":"bmt-C cluster arc center z"}, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index 6ed60a3b2..226762a8c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -7,7 +7,6 @@ import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -15,6 +14,7 @@ import org.jlab.rec.cvt.hit.ADCConvertor; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; +import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; /** @@ -204,11 +204,20 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate Strip SvtStrip = new Strip(strip[i], adcConv.SVTADCtoDAQ(ADC[i], event), (double) time[i]); + SvtStrip.set_Pitch(Constants.PITCH); // get the strip endPoints double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); Point3D EP2 = geo.transformToFrame(sector[i], layer[i], X[1][0], 0, X[1][1], "lab", ""); SvtStrip.set_Line(new Line3D(EP1, EP2)); + SvtStrip.set_Normal(geo.findBSTPlaneNormal(sector[i], layer[i])); // add normal to the plane defined from the strip midpoint + SvtStrip.set_Module(new Line3D(geo.getPlaneModuleOrigin(sector[i], layer[i]), geo.getPlaneModuleEnd(sector[i], layer[i]))); + if(layer[i]%2==1) { + SvtStrip.setToverX0(Constants.SILICONTHICK / Constants.SILICONRADLEN); + } + else { + SvtStrip.setToverX0(0); + } // BMTGeometry implementation using the geometry package: Charles Platt // Line3d shiftedStrip = geo.getStrip(layer[i]-1, sector[i]-1, strip[i]-1); // diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 8e80206fc..1e60d304c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -120,7 +120,7 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); - bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); + bank.setFloat("e", i, (float)cluslist.get(i).get_Resolution()); // cluslist.get(i).printInfo(); // System.out.println("N "+cluslist.get(i).getNFromTraj().toString()+" \n"+ // " L "+cluslist.get(i).getL().toString()+" \n"+ @@ -251,6 +251,8 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); + bank.setFloat("centroidValue", i, (float) cluslist.get(i).get_CentroidValue()); + bank.setFloat("centroidError", i, (float) cluslist.get(i).get_CentroidError()); bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); @@ -292,7 +294,7 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); - bank.setFloat("e", i, (float)cluslist.get(i).get_Error()); + bank.setFloat("e", i, (float)cluslist.get(i).get_Resolution()); if(debug && cluslist.get(i).get_AssociatedTrackID()>0 && cluslist.get(i).get_Type()==BMTType.Z) { Line3D cln = new Line3D(cluslist.get(i).origin(), cluslist.get(i).end()); System.out.println("Check: N "+cluslist.get(i).getN().toString()+" \n"+ diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 2a4590d51..6eebd6393 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -468,6 +468,7 @@ public Line3D getZstrip(int region, int sector, int strip) { * @param region * @param sector * @param strip + * @param swim * @return Line3D */ public Line3D getIdealLCZstrip(int region, int sector, int strip, Swim swim) { @@ -477,30 +478,21 @@ public Line3D getIdealLCZstrip(int region, int sector, int strip, Swim swim) { double radius = Constants.getCRZRADIUS()[region-1]; int layer = this.getLayer(region, BMTType.Z); - double zmin = Constants.getCRCZMIN()[region-1]; - double zmax = Constants.getCRCZMAX()[region-1]; - double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] - + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / radius ; -// double theLorentzCorrectedAngle = angle + this.LorentzAngleCorr(layer,sector); - Point3D p1= new Point3D(radius, 0, zmin); - p1.rotateZ(angle); - Point3D p2= new Point3D(radius, 0, zmax); - p2.rotateZ(angle); - Line3D stripline = new Line3D(p1,p2); + Line3D stripline = this.getZstrip(region, sector, strip); double x = stripline.midpoint().x(); double y = stripline.midpoint().y(); double z = stripline.midpoint().z(); - - double alpha = this.getThetaLorentz(layer, sector, x,y,z,swim); - double ralpha = Math.atan2(this.getThickness()/2*Math.tan(alpha), this.getRadiusMidDrift(layer)); - Point3D np1= new Point3D(this.getRadiusMidDrift(layer) * Math.cos(ralpha), - this.getRadiusMidDrift(layer) * Math.sin(ralpha), zmin); - Point3D np2= new Point3D(this.getRadiusMidDrift(layer) * Math.cos(ralpha), - this.getRadiusMidDrift(layer) * Math.sin(ralpha), zmax); - np1.rotateZ(angle); - np2.rotateZ(angle); - + double alpha = this.getThetaLorentz(layer, sector, x, y, z, swim); + double ralpha = Math.atan2(this.getThickness()/2*Math.tan(alpha), this.getRadius(layer)); +// System.out.println(region + " " + alpha + " " + ralpha); + + Point3D np1= new Point3D(this.getRadius(layer) * Math.cos(ralpha), + this.getRadius(layer) * Math.sin(ralpha), this.getZmin(layer)); + Point3D np2= new Point3D(this.getRadius(layer) * Math.cos(ralpha), + this.getRadius(layer) * Math.sin(ralpha), this.getZmax(layer)); Line3D nstripline = new Line3D(np1,np2); + nstripline.rotateZ(this.getZstripPhi(region, sector, strip)); + return nstripline; } @@ -510,6 +502,7 @@ public Line3D getIdealLCZstrip(int region, int sector, int strip, Swim swim) { * @param region * @param sector * @param strip + * @param swim * @return stripline */ public Line3D getLCZstrip(int region, int sector, int strip, Swim swim) { @@ -906,16 +899,12 @@ public double getThetaLorentz(int layer, int sector, double x, double y, double float[] b = new float[3]; swim.BfieldLab(x/10, y/10, z/10, b); double EDrift=0; - if(Constants.isMC == true) { - EDrift = 5000*Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()); + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { + EDrift = Constants.E_DRIFT_MF[layer-1][sector-1]; } else { - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { - EDrift = Constants.E_DRIFT_MF[layer-1][sector-1]; - } else { - EDrift = Constants.E_DRIFT_FF[layer-1][sector-1]; - } + EDrift = Constants.E_DRIFT_FF[layer-1][sector-1]; } - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001 || true) { + if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001) { thetaL = 0; } else { @@ -1117,21 +1106,22 @@ public static void main (String arg[]) { double phi = Math.random()*2*Math.PI; Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); // if(i!=newGeo.getLayer(traj,0)) System.out.println("Error in getLayer"); - if(newGeo.getTileSurface(i, newGeo.getSector(i, phi)).isOnSurface(traj)) - hi_acc.fill(z, Math.toDegrees(phi)); + if(newGeo.getSector(i, phi)>0) + if(newGeo.getTileSurface(i, newGeo.getSector(i, phi)).isOnSurface(traj)) + hi_acc.fill(z, Math.toDegrees(phi)); } } DataGroup dgBMT = new DataGroup(4, 3); for (int i = 0; i < 3; i++) { int region = i+1; - H2F hiz_res_z = new H2F("hiz_res_z" + region, "BMTZ R" + region, 500, -150, 150, 500, -5, 5); + H2F hiz_res_z = new H2F("hiz_res_z" + region, "BMTZ R" + region, 100, -150, 150, 100, -1.5, 1.5); hiz_res_z.setTitleX("z (cm)"); hiz_res_z.setTitleY("Residual (mm)"); H1F hiz_res = new H1F("hiz_res" + region, "BMTZ R" + region, 500, -5, 5); hiz_res.setTitleX("Residual (mm)"); hiz_res.setTitleY("Counts"); - H2F hic_res_z = new H2F("hic_res_z" + region, "BMTC R" + region, 500, -150, 150, 500, -5, 5); + H2F hic_res_z = new H2F("hic_res_z" + region, "BMTC R" + region, 100, -150, 150, 100, -1.5, 1.5); hic_res_z.setTitleX("z (cm)"); hic_res_z.setTitleY("Residual (mm)"); H1F hic_res = new H1F("hic_res" + region, "BMTC R" + region, 500, -5, 5); @@ -1188,35 +1178,51 @@ public static void main (String arg[]) { int region = newGeo.getRegion(layer); int seed = bmtCluster.getInt("seedStrip", iclus); double centroid = bmtCluster.getFloat("centroid", iclus); + double measure = bmtCluster.getFloat("centroidValue", iclus); ArrayList trajs = new ArrayList<>(); newGeo.getTileSurface(layer,sector).intersection(particle, trajs); if(trajs.size()==0) continue; + newGeo.toLocal(layer, sector).apply(trajs.get(0)); // for(Point3D traj : trajs) System.out.println(layer + " " + sector + " " + newGeo.getRadius(layer) + " " + traj.toString()); - for (int k = 0; k < mcTrue.rows(); k++) { - if (mcTrue.getInt("hitn", k) == id && mcTrue.getByte("detector", k) == DetectorType.BMT.getDetectorId()) { - double xTrue = mcTrue.getFloat("avgX", k); - double yTrue = mcTrue.getFloat("avgY", k); - double zTrue = mcTrue.getFloat("avgZ", k); - Point3D hit = new Point3D(xTrue, yTrue, zTrue); -// Line3D hitR = newGeo.getAxis(layer, sector).distance(hit); -// Line3D hitR = new Line3D(new Point3D(0,0,0), hit); -// hit = hitR.lerpPoint(newGeo.getRadius(layer)/(newGeo.getRadius(layer)+newGeo.getThickness()/2)); - double residual = -newGeo.getResidual(trajs.get(0), layer, sector, seed); - if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { -// Line3D strip = newGeo.getZstrip(region, sector, component); -// Line3D dist = strip.distance(hit); - dgBMT.getH1F("hiz_res" + region).fill(residual); - // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); - dgBMT.getH2F("hiz_res_z" + region).fill(zTrue, residual); - } - else { - dgBMT.getH1F("hic_res" + region).fill(residual); - dgBMT.getH2F("hic_res_z" + region).fill(zTrue, residual); - } - } + if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { +// measure=newGeo.getZstripPhi(region, sector, seed); + double residual=Math.atan2(trajs.get(0).y(),trajs.get(0).x())-measure; + if(Math.abs(residual)>2*Math.PI) residual-=Math.signum(residual)*2*Math.PI; + dgBMT.getH1F("hiz_res" + region).fill(residual); +// System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); + dgBMT.getH2F("hiz_res_z" + region).fill(trajs.get(0).z(), residual); + } + else { +// measure=newGeo.getCstripZ(region, strip); + double residual=trajs.get(0).z()-measure; + dgBMT.getH1F("hic_res" + region).fill(residual); + dgBMT.getH2F("hic_res_z" + region).fill(trajs.get(0).z(), residual); } +// for (int k = 0; k < mcTrue.rows(); k++) { +// if (mcTrue.getInt("hitn", k) == id && mcTrue.getByte("detector", k) == DetectorType.BMT.getDetectorId()) { +// double xTrue = mcTrue.getFloat("avgX", k); +// double yTrue = mcTrue.getFloat("avgY", k); +// double zTrue = mcTrue.getFloat("avgZ", k); +// Point3D hit = new Point3D(xTrue, yTrue, zTrue); +//// Line3D hitR = newGeo.getAxis(layer, sector).distance(hit); +//// Line3D hitR = new Line3D(new Point3D(0,0,0), hit); +//// hit = hitR.lerpPoint(newGeo.getRadius(layer)/(newGeo.getRadius(layer)+newGeo.getThickness()/2)); +// double residual = -newGeo.getResidual(trajs.get(0), layer, sector, seed); +// if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { +//// Line3D strip = newGeo.getZstrip(region, sector, component); +//// Line3D dist = strip.distance(hit); +// dgBMT.getH1F("hiz_res" + region).fill(residual); +// // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); +// dgBMT.getH2F("hiz_res_z" + region).fill(zTrue, residual); +// } +// else { +// dgBMT.getH1F("hic_res" + region).fill(residual); +// dgBMT.getH2F("hic_res_z" + region).fill(zTrue, residual); +// } +// } +// } } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 70e58d60e..612de09c9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -296,26 +296,32 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double xpos = dbprovider.getDouble("/geometry/cvt/mvt/position/x", 0 ); double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); - double angle = 0;//Math.toDegrees(0.003); + // hardcode gemc rotation: set angles to 0 to null it + Vector3D gemcRot = new Vector3D(0,0,0); + Point3D bmtCenter = new Point3D(0,0,-94.7); // the original BMT Center + Point3D bmtShift = new Point3D(bmtCenter); + bmtCenter.rotateZ(Math.toRadians(gemcRot.z())); + bmtCenter.rotateY(Math.toRadians(gemcRot.y())); + bmtCenter.rotateX(Math.toRadians(gemcRot.x())); + bmtShift.translateXYZ(-bmtCenter.x(), -bmtCenter.y(), -bmtCenter.z()); for (int row = 0; row=org.jlab.rec.cvt.bmt.Constants.emax) { - xe=org.jlab.rec.cvt.bmt.Constants.emax; - System.err.println("Warning: E out of grid... setting it to Emax"); - } - if (xb>org.jlab.rec.cvt.bmt.Constants.bmax) { - xb=org.jlab.rec.cvt.bmt.Constants.bmax; - //System.err.println("Warning: B field out of grid... setting it to Bmax = "+org.jlab.rec.cvt.bmt.Constants.bmax); - } - - int i11 = getBin( xe, xb); - int i12 = getBin( xe, xb+db); - int i21 = getBin( xe+de, xb); - int i22 = getBin( xe+de, xb+db); - - double Q11 = 0; double Q12 = 0; double Q21 = 0; double Q22 = 0; - double e1 = org.jlab.rec.cvt.bmt.Constants.emin; double e2 = org.jlab.rec.cvt.bmt.Constants.emax; double b1 = 0; double b2 = org.jlab.rec.cvt.bmt.Constants.bmax; - if (i11>=0) { - Q11=org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i11]; e1 = org.jlab.rec.cvt.bmt.Constants.E_grid[i11]; b1 = org.jlab.rec.cvt.bmt.Constants.B_grid[i11]; - } - if (i12>=0) Q12 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i12]; - if (xb>=org.jlab.rec.cvt.bmt.Constants.bmin) Q21 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i21]; - if (xb=0) { - Q22 = org.jlab.rec.cvt.bmt.Constants.ThetaL_grid[i22]; e2 = org.jlab.rec.cvt.bmt.Constants.E_grid[i22]; b2 = org.jlab.rec.cvt.bmt.Constants.B_grid[i22]; - } - - double R1 = linInterp( xe, e1,e2,Q11,Q12); - double R2 = linInterp( xe, e1,e2,Q21,Q22); - - double P = linInterp( xb, b1,b2,R1, R2); - - return P; - } - - - public static double linInterp(double x0, double xa, double xb, double ya, double yb) { - double x = x0; - if(x>xb) - x=xb; - if(x= Constants.emax) { + xe = Constants.emax; + System.err.println("Warning: E out of grid... setting it to Emax"); + } + if (xb > Constants.bmax) { + xb = Constants.bmax; + //System.err.println("Warning: B field out of grid... setting it to Bmax = "+Constants.bmax); + } + + int i11 = getBin(xe, xb); + int i12 = getBin(xe, xb + db); + int i21 = getBin(xe + de, xb); + int i22 = getBin(xe + de, xb + db); + + double Q11 = 0; + double Q12 = 0; + double Q21 = 0; + double Q22 = 0; + double e1 = Constants.emin; + double e2 = Constants.emax; + double b1 = 0; // RDV check if it should be 0 or bmin + double b2 = Constants.bmax; + if (i11 >= 0) { + Q11 = Constants.ThetaL_grid[i11]; + e1 = Constants.E_grid[i11]; + b1 = Constants.B_grid[i11]; + } + if (i12 >= 0) { + Q12 = Constants.ThetaL_grid[i12]; + } + if (xb >= Constants.bmin) { + Q21 = Constants.ThetaL_grid[i21]; + } + if (xb < Constants.bmin) { + Q21 = 0; + } + if (i22 >= 0) { + Q22 = Constants.ThetaL_grid[i22]; + e2 = Constants.E_grid[i22]; + b2 = Constants.B_grid[i22]; + } + + double R1 = linInterp(xe, e1, e2, Q11, Q21); + double R2 = linInterp(xe, e1, e2, Q12, Q22); + + double P = linInterp(xb, b1, b2, R1, R2); + + return P; + } + + + public static double linInterp(double x0, double xa, double xb, double ya, double yb) { + + double m = (yb - ya) / (xb - xa); + + // return + return m * (x0 - xa) + ya; + } + + + public static int getBin(double e, double b) { + double de = (Constants.emax - Constants.emin) / (Constants.Ne - 1); + double db = (Constants.bmax - Constants.bmin) / (Constants.Nb - 1); + + int ie = (int) Math.floor((e - Constants.emin) / de); + int ib = (int) Math.floor((b - Constants.bmin) / db); + + return ib + Constants.Nb * ie; + } +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index e49612721..489b6c29f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -4,13 +4,15 @@ import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import java.util.Collections; +import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; +import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Transformation3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.Constants; @@ -26,25 +28,28 @@ public class Cluster extends ArrayList implements Comparable private static final long serialVersionUID = 9153980362683755204L; - private DetectorType _Detector; // The detector SVT or BMT - private BMTType _Type; // The detector type for BMT C or Z - private int _Sector; // sector[1...] - private int _Layer; // layer [1,...] - private int _Id; // cluster Id - private double _Centroid; // after LC (Lorentz Correction) - private double _CentroidError; - private double _Error; // strip resolution - private double _Centroid0; // before LC + private DetectorType _Detector; // The detector SVT or BMT + private BMTType _Type; // The detector type for BMT C or Z + private int _Sector; // sector[1...] + private int _Layer; // layer [1,...] + private int _Id; // cluster Id + private double _Centroid; // after LC (Lorentz Correction) + private double _Centroid0; // before LC + private double _CentroidValue; // the value used in the KF + private double _CentroidError; // for BMT error or Z or phi + private double _Resolution; // cluster spatial resolution private double _TotalEnergy; - private double _Phi; // for Z-detectors + private double _Phi; // local LC phi and error for BMT-Z private double _PhiErr; - private double _Phi0; // for Z-detectors before LC - private double _PhiErr0; // local Z - private double _Z; // for C-detectors - private double _ZErr; - private Line3D _Line; - private Arc3D _Arc; - private Point3D _TrakInters; //track intersection with the cluster + private double _Phi0; // local uncorrected phi and error for BMT-Z + private double _PhiErr0; + private double _Z; // local Z and correspondng error for BMT-C + private double _ZErr; + private Line3D _Line; // 3D line for SVT and BMT-Z + private Arc3D _Arc; // 3D Arc for BMT-C + private Point3D _TrakInters; //track intersection with the cluster + private int AssociatedTrackID = -1; // the track ID associated with that hit + private int _MinStrip; // the min strip number in the cluster private int _MaxStrip; // the max strip number in the cluster @@ -53,21 +58,6 @@ public class Cluster extends ArrayList implements Comparable private double _SeedResidual; // residual is doca to seed strip from trk intersection with module plane private double _CentroidResidual; // residual is doca to centroid of cluster to trk inters with module plane - //added variables for alignment -// private double _x1; //cluster first end point x -// private double _y1; //svt cluster first end point y -// private double _z1; //svt cluster first end point z -// private double _x2; //svt cluster second end point x -// private double _y2; //svt cluster second end point y -// private double _z2; //svt cluster second end point z -// private double _ox; //bmt cluster arc origin x -// private double _oy; //bmt cluster arc origin y -// private double _oz; //bmt cluster arc origin z -// private double _cx; //bmt cluster arc center x -// private double _cy; //bmt cluster arc center y -// private double _cz; //bmt cluster arc center z -// private double _theta; //bmt cluster arc theta -// private Line3D _cyl; // bmt axis private Vector3D _l; //svt vector along cluster pseudo-strip direction or bmt vector along cluster pseudo-strip direction in the middle of the arc private Vector3D _s; //svt vector perpendicular to cluster pseudo-strip direction in the module plane or bmt vector perpendicular to cluster pseudo-strip in direction tangential to the cluster surface in the middle of the arc private Vector3D _n; //svt vector normal to the cluster module plane or bmt vector normal to the cluster surface in the middle of the arc @@ -180,37 +170,32 @@ public double getRadius() { if(this.get_Detector()==DetectorType.BST) return 0; else { - if(this.get_Type()==BMTType.C) - return this.get_Arc().radius(); - else - return this.get(0).get_Strip().get_Axis().distance(this.getLine()).length(); + return this.get(0).get_Strip().get_Tile().baseArc().radius(); } } public Line3D getAxis() { - if(this.get_Detector()==DetectorType.BST || true) + if(this.get_Detector()==DetectorType.BST) return new Line3D(); else { - return this.get(0).get_Strip().get_Axis(); + return this.get(0).get_Strip().get_Tile().getAxis(); + } + } + + public Cylindrical3D getTile() { + if(this.get_Detector()==DetectorType.BST) + return null; + else { + return this.get(0).get_Strip().get_Tile(); } } /** * sets energy-weighted parameters; these are the strip centroid * (energy-weighted) value, the energy-weighted phi for Z detectors and the * energy-weighted z for C detectors - * @param sgeo - * @param geo */ - public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { + public void calc_CentroidParams() { // instantiation of variables - double stripNumCent = 0; // cluster Lorentz-angle-corrected energy-weighted strip = centroid - double stripNumCent0 = 0; // cluster uncorrected energy-weighted strip = centroid - double phiCent = 0; // cluster Lorentz-angle-corrected energy-weighted phi - double phiErrCent = 0; // cluster Lorentz-angle-corrected energy-weighted phi error - double phiCent0 = 0; // cluster uncorrected energy-weighted phi - double phiErrCent0 = 0; // cluster uncorrected energy-weighted phi error - double zCent = 0; // cluster energy-weighted z - double zErrCent = 0; // cluster energy-weighted z error double totEn = 0.; // cluster total energy double weightedStrp = 0; // Lorentz-angle-corrected energy-weighted strip double weightedStrp0 = 0; // uncorrected energy-weighted strip @@ -248,9 +233,10 @@ public void calc_CentroidParams(SVTGeometry sgeo, BMTGeometry geo) { int strpNb0 = -1; //before LC //strip points: - Point3D stEP1 = null; - Point3D stEP2 = null; - Point3D stCent = null; + Point3D stEP1 = null; + Point3D stEP2 = null; + Point3D stCent = null; + // strip energy double strpEn = thehit.get_Strip().get_Edep(); @@ -284,9 +270,9 @@ else if (this.get_Detector()==DetectorType.BMT) { strpNb0 = thehit.get_Strip().get_Strip(); stEP1 = thehit.get_Strip().get_Line().origin(); stEP2 = thehit.get_Strip().get_Line().end(); - stCent = thehit.get_Strip().get_Line().midpoint(); + // RDV: should remove stuff that is not used or necessary from cluster strips and so on // for C detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid - weightedPhi += strpEn * thehit.get_Strip().get_Phi(); + stCent = new Point3D(Math.cos(thehit.get_Strip().get_Phi()),Math.sin(thehit.get_Strip().get_Phi()),0); weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); weightedPhi0 += strpEn * thehit.get_Strip().get_Phi0(); weightedPhiErrSq0 += (thehit.get_Strip().get_PhiErr0()) * (thehit.get_Strip().get_PhiErr0()); @@ -331,27 +317,33 @@ else if (this.get_Detector()==DetectorType.BMT) { this.set_MaxStrip(max); this.set_Seed(seed); // calculates the centroid values and associated errors - stripNumCent = weightedStrp / totEn; - stripNumCent0 = weightedStrp0 / totEn; - + weightedStrp /= totEn; + weightedStrp0 /= totEn; + weightedX1 /= totEn; + weightedY1 /= totEn; + weightedZ1 /= totEn; + weightedX2 /= totEn; + weightedY2 /= totEn; + weightedZ2 /= totEn; + weightedXC /= totEn; + weightedYC /= totEn; + weightedZC /= totEn; + weightedZ /= totEn; + weightedPhi = Math.atan2(weightedYC, weightedXC); + weightedPhi0 /= totEn; + + this.set_Centroid(weightedStrp); + this.set_TotalEnergy(totEn); + //setting final variables, including the ones used for alignment //----------------------------------- if (this.get_Detector()==DetectorType.BST) { //SVT - this.setLine(new Line3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); + this.setLine(new Line3D(weightedX1, weightedY1, weightedZ1, weightedX2, weightedY2, weightedZ2)); Vector3D l = new Vector3D(this.getLine().direction().asUnit()); - -// //Vector3D s = sgeo.getPlaneModuleOrigin(this.get_Sector(), this.get_Layer()). -// // vectorTo(sgeo.getPlaneModuleEnd(this.get_Sector(), this.get_Layer())).asUnit(); -// double[][] Xi = sgeo.getStripEndPoints(1, (this.get_Layer() - 1) % 2); -// double[][] Xf = sgeo.getStripEndPoints(100, (this.get_Layer() - 1) % 2); -// Point3D EPi = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xi[0][0], 0, Xi[0][1], "lab", ""); -// Point3D EPf = sgeo.transformToFrame(this.get_Sector(), this.get_Layer(), Xf[0][0], 0, Xf[0][1], "lab", ""); -// -// Vector3D se = EPi.vectorTo(EPf).asUnit(); // in direction of increasing strips - Vector3D n = sgeo.findBSTPlaneNormal(this.get_Sector(), this.get_Layer()); + Vector3D n = this.get(0).get_Strip().get_Normal(); Vector3D s = l.cross(n).asUnit(); - + this.setL(l); this.setS(s); this.setN(n); @@ -359,8 +351,8 @@ else if (this.get_Detector()==DetectorType.BMT) { else if (this.get_Detector()==DetectorType.BMT) { //BMT // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_Type()==BMTType.C) { // C-detectors - Point3D origin = new Point3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn); - Point3D center = new Point3D(weightedXC/totEn, weightedYC/totEn, weightedZC/totEn); + Point3D origin = new Point3D(weightedX1, weightedY1, weightedZ1); + Point3D center = new Point3D(weightedXC, weightedYC, weightedZC); Vector3D normal = this.get(0).get_Strip().get_Arc().normal(); double theta = this.get(0).get_Strip().get_Arc().theta(); this.set_Arc(new Arc3D(origin,center,normal,theta)); @@ -373,35 +365,28 @@ else if (this.get_Detector()==DetectorType.BMT) { //BMT this.setS(s); this.setN(n); - zCent = weightedZ/totEn; - zErrCent = Math.sqrt(weightedZErrSq); - - _Z = zCent; - _ZErr = zErrCent; - this.set_Error(zErrCent); + this.set_Z(weightedZ); + this.set_ZErr(Math.sqrt(weightedZErrSq)); + this.set_CentroidValue(weightedZ); + this.set_CentroidError(Math.sqrt(weightedZErrSq)); + this.set_Resolution(Math.sqrt(weightedZErrSq)); } if (this.get_Type()==BMTType.Z) { // Z-detectors - //phiCent = geo.LorentzAngleCorr(phiCent0,this.get_Layer()); - phiCent = weightedPhi / totEn; - phiCent0 = weightedPhi0 / totEn; - //zCent = weightedZ / totEn; - phiErrCent = Math.sqrt(weightedPhiErrSq); - phiErrCent0 = Math.sqrt(weightedPhiErrSq0); - - set_Centroid0(stripNumCent0); - _Phi = phiCent; - _PhiErr = phiErrCent; - this.set_Error(geo.getRadiusMidDrift(_Layer)*phiErrCent); - set_Phi0(phiCent0); - set_PhiErr0(phiErrCent0); + this.set_Centroid0(weightedStrp0); + this.set_Phi(weightedPhi); + this.set_PhiErr(Math.sqrt(weightedPhiErrSq)); + this.set_Phi0(weightedPhi0); + this.set_PhiErr0(Math.sqrt(weightedPhiErrSq0)); + this.set_CentroidValue(weightedPhi); + this.set_CentroidError(Math.sqrt(weightedPhiErrSq)); + this.set_Resolution(this.getTile().baseArc().radius()*Math.sqrt(weightedPhiErrSq)); // for Z detectors Lorentz-correction is applied to the strip - this.setLine(new Line3D(weightedX1/totEn, weightedY1/totEn, weightedZ1/totEn, weightedX2/totEn, weightedY2/totEn, weightedZ2/totEn)); + this.setLine(new Line3D(weightedX1, weightedY1, weightedZ1, weightedX2, weightedY2, weightedZ2)); - Vector3D l = new Vector3D(this.getLine().direction().asUnit()); - - Vector3D n = geo.getAxis(_Layer, _Sector).distance(_Line).direction().asUnit(); + Vector3D l = this.getLine().direction().asUnit(); + Vector3D n = this.getAxis().distance(this.getLine().midpoint()).direction().asUnit(); Vector3D s = l.cross(n).asUnit(); this.setL(l); @@ -411,18 +396,8 @@ else if (this.get_Detector()==DetectorType.BMT) { //BMT } } } - - _TotalEnergy = totEn; - _Centroid = stripNumCent; } -// -// public Vector3D getNFromTraj(double x, double y, double z, Line3D cln) { -// Point3D trk = new Point3D(x,y,z); -// Point3D Or = cln.distance(new Point3D(x,y,z)).origin(); -// Vector3D n = Or.vectorTo(trk).asUnit(); -// return n; -// } public double get_Centroid() { return _Centroid; @@ -432,19 +407,12 @@ public void set_Centroid(double _Centroid) { this._Centroid = _Centroid; } - public double get_CentroidError() { - return _CentroidError; + public double get_Resolution() { + return _Resolution; } - public void set_CentroidError(double _CentroidE) { - this._CentroidError = _CentroidE; - } - public double get_Error() { - return _Error; - } - - public void set_Error(double E) { - this._Error = E; + public void set_Resolution(double E) { + this._Resolution = E; } public double get_Centroid0() { return _Centroid0; @@ -502,6 +470,22 @@ public void set_ZErr(double _ZErr) { this._ZErr = _ZErr; } + public void set_CentroidValue(double _CentroidValue) { + this._CentroidValue = _CentroidValue; + } + + public double get_CentroidValue() { + return this._CentroidValue; + } + + public double get_CentroidError() { + return this._CentroidError; + } + + public void set_CentroidError(double _CentroidError) { + this._CentroidError = _CentroidError; + } + /** * @return the _Arc */ @@ -543,7 +527,7 @@ public Point3D center() { return this.getLine().midpoint(); else { if(this.get_Type()==BMTType.C) - return this.get_Arc().center(); + return this.get_Arc().point(this.get_Arc().theta()/2); else return this.getLine().midpoint(); } @@ -570,15 +554,20 @@ public Transformation3D toGlobal() { public double residual(Point3D traj) { double value = 0; - if(this.get_Detector()==DetectorType.BST) - ; + if(this.get_Detector()==DetectorType.BST) { + Line3D dist = this.getLine().distance(traj); + double side = -Math.signum(this.getLine().direction().cross(dist.direction()).dot(this.getN())); + value = dist.length()*side; + } else { Point3D local = new Point3D(traj); this.toLocal().apply(local); if(this.get_Type()==BMTType.C) - value = local.z()-this.get_Z(); - else - ; + value = local.z()-this.get_Centroid(); + else { + value = local.toVector3D().phi()-this.get_Centroid(); + if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + } } return value; } @@ -657,6 +646,47 @@ public void setTrakInters(Point3D _TrakInters) { this._TrakInters = _TrakInters; } + public Surface measurement(int mlayer) { + Surface surface = null; + if(this.get_Detector()==DetectorType.BST) { + Point3D endPt1 = this.getLine().origin(); + Point3D endPt2 = this.getLine().end(); + org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), + endPt1.x(), endPt1.y(), endPt1.z(), + endPt2.x(), endPt2.y(), endPt2.z()); + Plane3D plane = new Plane3D(endPt1, this.getN()); + Line3D module = this.get(0).get_Strip().get_Module(); + surface = new Surface(plane, strp, module.origin(), module.end()); + surface.hemisphere = Math.signum(this.center().y()); + surface.setLayer(mlayer); + surface.setSector(this.get_Sector()); + surface.setError(this.get_Resolution()*this.get_Resolution()); + surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); + } + else { + if(this.get_Type()==BMTType.C) { + org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), this.get_CentroidValue()); + surface = new Surface(this.get(0).get_Strip().get_Tile(), strp); + double error = this.get_CentroidError(); + surface.setError(error*error); + } + else { + Point3D point = new Point3D(this.getLine().midpoint()); + this.toLocal().apply(point); + org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), point.x(), point.y(), this.get_CentroidValue()); + surface = new Surface(this.getTile(), strp); + double error = this.get_CentroidError();///this.getTile().baseArc().radius(); + surface.setError(error*error); + + } + surface.setTransformation(this.toGlobal()); + surface.setLayer(mlayer); + surface.setSector(this.get_Sector()); + surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); + } + return surface; + } + /** * * @return cluster info. about location and number of hits contained in it @@ -695,8 +725,6 @@ public double get_ResolutionAlongZ(double Z, SVTGeometry geo) { return Math.sqrt(res); } - private int AssociatedTrackID = -1; // the track ID associated with that hit - public int get_AssociatedTrackID() { return AssociatedTrackID; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 836e7c911..d8327e499 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -25,7 +25,7 @@ public ClusterFinder() { int nstrip = 1200; // max number of strips int nlayr = 6; int nsec = 18; - public ArrayList findClusters(List hits2, SVTGeometry geo_bst, BMTGeometry geo_bmt) // the number of strips depends on the layer + public ArrayList findClusters(List hits2) // the number of strips depends on the layer { ArrayList clusters = new ArrayList(); @@ -95,7 +95,7 @@ public ArrayList findClusters(List hits2, SVTGeometry geo_bst, BMT h.newClustering = true; } - this_cluster.calc_CentroidParams(geo_bst,geo_bmt); + this_cluster.calc_CentroidParams(); for (FittedHit h : this_cluster) { h.newClustering = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 2893d44de..75235ba4f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -127,7 +127,7 @@ private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { if(Z>Constants.ACTIVESENLEN) Z=Constants.ACTIVESENLEN; Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z, svt_geo) / (Constants.PITCH / Math.sqrt(12.))); - Cluster1.set_Error(Cluster1.get_ResolutionAlongZ(Z, svt_geo) ); + Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z, svt_geo) ); } /** * diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java index b00e5766b..595e23450 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.hit; import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTType; @@ -41,18 +42,23 @@ public void set_docaToTrk(Point3D traj) { public double residual(Point3D traj) { double value = 0; - if(this.get_Detector()==DetectorType.BST) - ; + if(this.get_Detector()==DetectorType.BST) { + Line3D dist = this.get_Strip().get_Line().distance(traj); + double side = -Math.signum(this.get_Strip().get_Line().direction().cross(dist.direction()).dot(this.get_Strip().get_Normal())); + value = dist.length()*side; + } else { Point3D local = new Point3D(traj); this.get_Strip().toLocal().apply(local); if(this.get_Type()==BMTType.C) value = local.z()-this.get_Strip().get_Z(); - else - ; - } + else { + value = Math.atan2(local.y(),local.x())-this.get_Strip().get_Phi(); + value = (value + 8*Math.PI) % (2*Math.PI); + } + } return value; - } + } public double get_stripResolutionAtDoca() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index feaf18e34..c7c0871e4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -2,6 +2,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Transformation3D; @@ -31,9 +32,13 @@ public Strip(int strip, double edep, double time) { private double _Z; private double _ZErr; - private Arc3D _Arc; + private double _Pitch; + private Arc3D _Arc; private Line3D _Line; - private Line3D _Axis; + private Cylindrical3D _Tile; + private Line3D _Module; + private Vector3D _Normal; + private double _ToverX0; private Transformation3D toLocal; private Transformation3D toGlobal; @@ -45,6 +50,14 @@ public void set_Strip(int _Strip) { this._Strip = _Strip; } + public double get_Pitch() { + return _Pitch; + } + + public void set_Pitch(double _Pitch) { + this._Pitch = _Pitch; + } + public Arc3D get_Arc() { return _Arc; } @@ -61,12 +74,36 @@ public void set_Line(Line3D _Line) { this._Line = _Line; } - public Line3D get_Axis() { - return _Axis; + public Cylindrical3D get_Tile() { + return _Tile; + } + + public void set_Tile(Cylindrical3D _Tile) { + this._Tile = _Tile; + } + + public Line3D get_Module() { + return _Module; + } + + public void set_Module(Line3D _Module) { + this._Module = _Module; + } + + public Vector3D get_Normal() { + return _Normal; } - public void set_Axis(Line3D _Axis) { - this._Axis = _Axis; + public void set_Normal(Vector3D _Normal) { + this._Normal = _Normal; + } + + public double getToverX0() { + return _ToverX0; + } + + public void setToverX0(double _ToverX0) { + this._ToverX0 = _ToverX0; } public Transformation3D toLocal() { @@ -173,13 +210,16 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi int region = geo.getRegion(layer); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 this.setToGlobal(geo.toGlobal(layer, sector)); this.setToLocal(geo.toLocal(layer, sector)); + this.set_Tile(geo.getTileSurface(layer, sector)); + this.set_Pitch(geo.getPitch(layer, this.get_Strip())); + this.setToverX0(geo.getToverX0(layer)); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); this.set_Arc(arcLine); - this.set_Axis(geo.getAxis(layer, sector)); + this.set_Normal(arcLine.bisect()); // max z err this.set_Z(geo.getCstripZ(geo.getRegion(layer),this.get_Strip())); this.set_ZErr(geo.getPitch(layer, this.get_Strip()) / Math.sqrt(12.)); @@ -187,37 +227,18 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors - //Line3D L0 = geo.getZstrip(geo.getRegion(layer), sector, this.get_Strip()); Line3D line = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip(), swim); this.set_Line(line); - this.set_Axis(geo.getAxis(layer, sector)); - - Line3D cln = geo.getAxis(layer, sector); - cln.set(cln.origin().x(), cln.origin().y(), line.origin().z(), - cln.end().x(), cln.end().y(), line.end().z()); - - double v = (line.origin().z()-cln.origin().z())/cln.direction().z(); - double x = cln.origin().x()+v*cln.direction().x(); - double y = cln.origin().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, line.origin().z()). - vectorTo(new Point3D(line.origin().x(),line.origin().y(),line.origin().z())).asUnit(); - - double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.get_Strip()); - //double theLorentzCorrectedAngle = line.midpoint().toVector3D().phi(); - double theLorentzCorrectedAngle = n.phi(); + this.set_Normal(this.get_Tile().getAxis().distance(line.midpoint()).direction().asUnit()); // set the phi + Point3D local = geo.getIdealLCZstrip(region, sector, this.get_Strip(), swim).midpoint(); + double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.get_Strip()); + double theLorentzCorrectedAngle = local.toVector3D().phi(); this.set_Phi(theLorentzCorrectedAngle); - this.set_Phi0(theMeasuredPhi); // uncorrected - //System.out.println(" sec "+sector+" strip "+this.get_Strip()+" LC strip "+geo.getZStrip(layer, theLorentzCorrectedAngle)); - //int theLorentzCorrectedStrip = geo.getZStrip(layer, theLorentzCorrectedAngle); - // double xl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* -// Math.cos(theLorentzCorrectedAngle); -// double yl = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]* -// Math.sin(theLorentzCorrectedAngle); -// int theLorentzCorrectedStrip = geo.getStrip( layer, sector, -// new Point3D(xl,yl,0)); - int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); + this.set_Phi0(theMeasuredPhi); // uncorrected, can be outside of -pi,pi + // get the strip number after correcting for Lorentz angle + int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); this.set_LCStrip(theLorentzCorrectedStrip); double sigma = Constants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh @@ -227,7 +248,6 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi double phiErr = geo.getPitch(layer, this.get_Strip()) / geo.getRadius(layer) / Math.sqrt(12.); this.set_PhiErr(Math.sqrt(phiErr * phiErr + phiErrL * phiErrL)); - //System.out.println("arcerr "+org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]+" * "+Math.toDegrees(sigma/org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region])); this.set_PhiErr0(phiErr); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index f6495a8d7..677cfb950 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -182,9 +182,9 @@ public boolean processDataEvent(DataEvent event) { //2) find the clusters from these hits ClusterFinder clusFinder = new ClusterFinder(); - clusters.addAll(clusFinder.findClusters(svt_hits, SVTGeom, BMTGeom)); + clusters.addAll(clusFinder.findClusters(svt_hits)); if(bmt_hits != null && bmt_hits.size() > 0) { - clusters.addAll(clusFinder.findClusters(bmt_hits, SVTGeom, BMTGeom)); + clusters.addAll(clusFinder.findClusters(bmt_hits)); } if (clusters.size() == 0) { rbc.appendCVTBanks(event, SVThits, BMThits, null, null, null, null, shift); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 20579f423..b84b39215 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -85,7 +85,7 @@ public void CleanupSpuriousCrosses(List> crosses, List t } } - public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { + public List setMeasVecs(Seed trkcand, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), @@ -100,26 +100,8 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge // SVT measurements for (int i = 0; i < trkcand.get_Clusters().size(); i++) { if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { - int id = trkcand.get_Clusters().get(i).get_Id(); - int layer = trkcand.get_Clusters().get(i).get_Layer(); - int sector = trkcand.get_Clusters().get(i).get_Sector(); - double ce = trkcand.get_Clusters().get(i).get_Centroid(); - Line3D line = trkcand.get_Clusters().get(i).getLine(); - Strip strp = new Strip(id, ce, line); - Plane3D pln = new Plane3D(line.origin(),sgeo.findBSTPlaneNormal(sector,layer)); - Point3D Or = sgeo.getPlaneModuleOrigin(sector,layer); - Point3D En = sgeo.getPlaneModuleEnd(sector,layer); - Surface meas = new Surface(pln, strp, Or, En); - meas.setSector(trkcand.get_Clusters().get(i).get_Sector()); - meas.setLayer(trkcand.get_Clusters().get(i).get_Layer()); - double err = trkcand.get_Clusters().get(i).get_Error(); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //the thickness for multiple scattering. MS is outward the thickness is set for the 1st layer in the superlayer - // air gap ignored - double thickn_ov_X0 = 0; - if(trkcand.get_Clusters().get(i).get_Layer()%2==1) - thickn_ov_X0 = org.jlab.rec.cvt.svt.Constants.SILICONTHICK / org.jlab.rec.cvt.svt.Constants.SILICONRADLEN; - meas.setl_over_X0(thickn_ov_X0); + int mlayer = trkcand.get_Clusters().get(i).get_Layer(); + Surface meas = trkcand.get_Clusters().get(i).measurement(mlayer); if((int)Constants.getLayersUsed().get(meas.getLayer())<1) meas.notUsedInFit=true; if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) @@ -129,110 +111,29 @@ public List setMeasVecs(Seed trkcand, SVTGeometry sgeo, BMTGeometry bge } // adding the BMT + double hemisp = Math.signum(trkcand.get_Helix().getPointAtRadius(300).y()); for (int c = 0; c < trkcand.get_Crosses().size(); c++) { - if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { - - int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); - int sector = trkcand.get_Crosses().get(c).get_Cluster1().get_Sector(); - - Cylindrical3D cyl = bgeo.getTileSurface(layer, sector); - Line3D cln = bgeo.getAxis(layer, sector); - Line3D l = bgeo.getLCZstrip(bgeo.getRegion(layer), sector, 1, swim); - //cln.set(cln.origin().x(), cln.origin().y(), l.origin().z(), - // cln.end().x(), cln.end().y(), l.end().z()); - //cyl.setAxis(cln); - int id = trkcand.get_Crosses().get(c).get_Cluster1().get_Id(); - double ce = trkcand.get_Crosses().get(c).get_Cluster1().get_Centroid(); - - double hemisp = trkcand.get_Helix().getPointAtRadius(300).y(); - if (trkcand.get_Crosses().get(c).get_Type()==BMTType.Z) { - Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getLine().origin(); - - double v = (EP1.z()-cln.origin().z())/cln.direction().z(); - double x = cln.origin().x()+v*cln.direction().x(); - double y = cln.origin().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, EP1.z()). - vectorTo(new Point3D(EP1.x(),EP1.y(),EP1.z())).asUnit(); - - double phi = n.phi(); - - //double phi = Math.atan2(y,x); - double err = trkcand.get_Crosses().get(c).get_Cluster1().get_PhiErr(); - // *(org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]+org.jlab.rec.cvt.bmt.Constants.hStrip2Det); - - //Strip strp = new Strip(id, ce, x, y, phi); - //Point3D EP1 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint1(); - //Point3D EP2 = trkcand.get_Crosses().get(c).get_Cluster1().getEndPoint2(); - Strip strp = new Strip(id, ce, x, y, phi); - //Strip strp = new Strip( id, ce, EP1.x(), EP1.y(), EP1.z(), EP2.x(), EP2.y(), EP2.z()); - - //cyl.baseArc().setRadius(Math.sqrt(x*x+y*y)); - //cyl.highArc().setRadius(Math.sqrt(x*x+y*y)); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(layer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(layer)); - Surface meas = new Surface(cyl, strp); - - meas.setTransformation(bgeo.toGlobal(layer,sector)); - - meas.setSector(trkcand.get_Crosses().get(c).get_Sector()); - meas.setLayer(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //for multiple scattering - double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; - meas.setl_over_X0(thickn_ov_X0); - if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { - //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); - meas.notUsedInFit=true; - } - if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) - continue; - meas.hemisphere = hemisp; - KFSites.add(meas); - } - if (trkcand.get_Crosses().get(c).get_Type()==BMTType.C) { - double z = trkcand.get_Crosses().get(c).get_Point().z(); - double err = trkcand.get_Crosses().get(c).get_Cluster1().get_ZErr(); - - Arc3D arc = trkcand.get_Crosses().get(c).get_Cluster1().get_Arc(); - //Point3D ct = new Point3D(trkcand.get(i).get_Cluster1().getCx(), - // trkcand.get(i).get_Cluster1().getCy(), - // trkcand.get(i).get_Cluster1().getCz()); - // Point3D og = new Point3D(trkcand.get(i).get_Cluster1().getOx(), - // trkcand.get(i).get_Cluster1().getOy(), - // trkcand.get(i).get_Cluster1().getOz()); - //arc.setCenter(ct); - //arc.setOrigin(og); - Strip strp = new Strip(id, ce, arc); - cyl.baseArc().setRadius(bgeo.getRadiusMidDrift(layer)); - cyl.highArc().setRadius(bgeo.getRadiusMidDrift(layer)); - - Surface meas = new Surface(cyl, strp); - - meas.setTransformation(bgeo.toGlobal(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(), - trkcand.get_Crosses().get(c).get_Sector())); - - meas.setSector(trkcand.get_Crosses().get(c).get_Sector()); - meas.setLayer(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //for multiple scattering - double thickn_ov_X0 = org.jlab.rec.cvt.bmt.Constants.get_T_OVER_X0()[(trkcand.get_Crosses().get(c).get_Cluster1().get_Layer() + 1) / 2 - 1]; - meas.setl_over_X0(thickn_ov_X0); - if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { - //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); - meas.notUsedInFit=true; - } - meas.hemisphere = hemisp; - if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) - continue; - KFSites.add(meas); + if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { + int mlayer=trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6; + Surface meas = trkcand.get_Crosses().get(c).get_Cluster1().measurement(mlayer); + meas.hemisphere = hemisp; + if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); + meas.notUsedInFit=true; } + if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + continue; + KFSites.add(meas); } } +// for(int i=0; i setMeasVecs(StraightTrack trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); @@ -281,7 +182,7 @@ public List setMeasVecs(StraightTrack trkcand, Surface meas = new Surface(pln, strp, Or, En); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setSector(cls.get(j).get_Sector()); - double err = cls.get(j).get_Error(); + double err = cls.get(j).get_Resolution(); meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? //the thickness for multiple scattering. MS is outward the thickness is set for the 1st layer in the superlayer // air gap ignored @@ -468,7 +369,7 @@ public void MatchTrack2Traj(Seed trkcand, Map 100 m, assume it's straight track + double x = r*Math.cos(phi0); + double y = r*Math.sin(phi0); + double z = r*tandip; + return new Point3D(x, y, z); + } + + double par = 1. - ((r * r - d0 * d0) * omega * omega) / (2. * (1. + d0 * Math.abs(omega))); double newPathLength = Math.abs(Math.acos(par) / omega); @@ -243,6 +247,12 @@ public Vector3D getTrackDirectionAtRadius(double r) { return trkDir.asUnit(); } + @Override + public String toString() { + String s = String.format("Helix: Z0=%.4f R=%.4e DCA=%.4f Phi=%.4f Tan=%.4f", this._Z0,this._curvature,this._dca,this._phi_at_dca,this._tandip); + return s; + } + public static void main(String arg[]) { // Helix h = new Helix(0, 0, 1/5., 0, -999, null); From 1b8875335ad65b6965a43e5e32f8d4442b6fcfcb Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 29 Sep 2021 01:22:46 +0200 Subject: [PATCH 171/291] correct calculation of phi0 (no lorentz correction for BMT-Z clusters --- .../org/jlab/clas/tracking/objects/Strip.java | 3 + .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 61 ++++++++++--------- .../org/jlab/rec/cvt/cluster/Cluster.java | 46 ++++++++------ 3 files changed, 62 insertions(+), 48 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java index 7d23625e6..6d33baabb 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java @@ -314,6 +314,9 @@ else if(this.type==Type.PHI) { else if(this.type==Type.ARC) { s = s + "\n\t" +_arc.toString() + String.format("\n\tCentroid=%.4f",_c); } + else if(this.type==Type.Z) { + s = s + String.format("\n\tZ=%.4f Centroid=%.4f", _z,_c); + } return s; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 6eebd6393..2c7208a93 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -387,36 +387,36 @@ public Point3D toGlobal(Point3D local, int layer, int sector) { return global; } - public double getResidual(Point3D traj, int layer, int sector, int strip) { - BMTType type = BMTGeometry.getDetectorType(layer); - switch (type) { - case C: - return this.getCResidual(traj, layer, sector, strip); - case Z: - return this.getZResidual(traj, layer, sector, strip); - default: - return 0; - } - } - - private double getCResidual(Point3D traj, int layer, int sector, int strip) { - int region = this.getRegion(layer); - Point3D local = this.toLocal(traj, layer, sector); - return local.z()-this.getCstripZ(region, strip); - } - - - private double getZResidual(Point3D traj, int layer, int sector, int strip) { - int region = this.getRegion(layer); - Point3D local = this.toLocal(traj, layer, sector); - - double phi = Math.atan2(local.y(),local.x()); - double radius = this.getRadius(layer)+this.getThickness()/2; - double dphi = phi-this.getZstripPhi(region, sector, strip); - if(dphi>2*Math.PI) dphi -= 2*Math.PI; - else if(dphi<-2*Math.PI) dphi += 2*Math.PI; - return radius*dphi; - } +// public double getResidual(Point3D traj, int layer, int sector, int strip) { +// BMTType type = BMTGeometry.getDetectorType(layer); +// switch (type) { +// case C: +// return this.getCResidual(traj, layer, sector, strip); +// case Z: +// return this.getZResidual(traj, layer, sector, strip); +// default: +// return 0; +// } +// } +// +// private double getCResidual(Point3D traj, int layer, int sector, int strip) { +// int region = this.getRegion(layer); +// Point3D local = this.toLocal(traj, layer, sector); +// return local.z()-this.getCstripZ(region, strip); +// } +// +// +// private double getZResidual(Point3D traj, int layer, int sector, int strip) { +// int region = this.getRegion(layer); +// Point3D local = this.toLocal(traj, layer, sector); +// +// double phi = Math.atan2(local.y(),local.x()); +// double radius = this.getRadius(layer)+this.getThickness()/2; +// double dphi = phi-this.getZstripPhi(region, sector, strip); +// if(dphi>2*Math.PI) dphi -= 2*Math.PI; +// else if(dphi<-2*Math.PI) dphi += 2*Math.PI; +// return radius*dphi; +// } /** * Returns Line3D for Z detector strip identified from region, sector, strip numbers, for ideal geometry @@ -526,6 +526,7 @@ public double getZstripPhi(int region, int sector, int strip) { throw new IllegalArgumentException("Error: invalid region="+region); double angle = Constants.getCRZPHI()[region-1][sector-1] - Constants.getCRZDPHI()[region-1][sector-1] + ((double) strip-0.5) * Constants.getCRZWIDTH()[region-1] / Constants.getCRZRADIUS()[region-1]; + if(Math.abs(angle)>Math.PI) angle -= 2*Math.PI*Math.signum(angle); return angle; //in rad } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 489b6c29f..90f16cea8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -207,13 +207,16 @@ public void calc_CentroidParams() { double weightedZErrSq = 0; // Err^2 on energy-weighted z of the strip double weightedX1 = 0; // SVT/BMT strip centroid positions of endpoints double weightedX2 = 0; // SVT/BMT strip centroid positions of endpoints - double weightedXC = 0; // BMT strip centroid positions of arc center + double weightedXC = 0; // BMT strip centroid positions of strip midpoint + double weightedX0 = 0; // BMT strip centroid positions of strip position with no LC double weightedY1 = 0; // SVT/BMT strip centroid positions of endpoints double weightedY2 = 0; // SVT/BMT strip centroid positions of endpoints - double weightedYC = 0; // BMT strip centroid positions of arc center + double weightedYC = 0; // BMT strip centroid positions of strip midpoint + double weightedY0 = 0; // BMT strip centroid positions of strip midpoint with no LC double weightedZ1 = 0; // SVT/BMT strip centroid positions of endpoints double weightedZ2 = 0; // SVT/BMT strip centroid positions of endpoints - double weightedZC = 0; // BMT strip centroid positions of arc center + double weightedZC = 0; // BMT strip centroid positions of strip midpoint + double weightedZ0 = 0; // BMT strip centroid positions of strip midpoint with no LC int nbhits = this.size(); //sort for bmt detector @@ -236,17 +239,18 @@ public void calc_CentroidParams() { Point3D stEP1 = null; Point3D stEP2 = null; Point3D stCent = null; + Point3D stCent0 = null; // strip energy double strpEn = thehit.get_Strip().get_Edep(); if (this.get_Detector()==DetectorType.BST) { // for the SVT the analysis only uses the centroid - strpNb = thehit.get_Strip().get_Strip(); - stEP1 = thehit.get_Strip().get_Line().origin(); - stEP2 = thehit.get_Strip().get_Line().end(); - stCent = thehit.get_Strip().get_Line().midpoint(); - + strpNb = thehit.get_Strip().get_Strip(); + stEP1 = thehit.get_Strip().get_Line().origin(); + stEP2 = thehit.get_Strip().get_Line().end(); + stCent = thehit.get_Strip().get_Line().midpoint(); + stCent0 = thehit.get_Strip().get_Line().midpoint(); } else if (this.get_Detector()==DetectorType.BMT) { @@ -256,10 +260,11 @@ else if (this.get_Detector()==DetectorType.BMT) { // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_Type()==BMTType.C) { // C-detectors //strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); - strpNb = thehit.get_Strip().get_Strip(); - stEP1 = thehit.get_Strip().get_Arc().origin(); - stEP2 = thehit.get_Strip().get_Arc().end(); - stCent = thehit.get_Strip().get_Arc().center(); + strpNb = thehit.get_Strip().get_Strip(); + stEP1 = thehit.get_Strip().get_Arc().origin(); + stEP2 = thehit.get_Strip().get_Arc().end(); + stCent = thehit.get_Strip().get_Arc().center(); + stCent0 = thehit.get_Strip().get_Arc().center(); // for C detector the Z of the centroid is calculated weightedZ += strpEn * thehit.get_Strip().get_Z(); weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); @@ -272,9 +277,9 @@ else if (this.get_Detector()==DetectorType.BMT) { stEP2 = thehit.get_Strip().get_Line().end(); // RDV: should remove stuff that is not used or necessary from cluster strips and so on // for C detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid - stCent = new Point3D(Math.cos(thehit.get_Strip().get_Phi()),Math.sin(thehit.get_Strip().get_Phi()),0); - weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); - weightedPhi0 += strpEn * thehit.get_Strip().get_Phi0(); + stCent = new Point3D(Math.cos(thehit.get_Strip().get_Phi()),Math.sin(thehit.get_Strip().get_Phi()),0); + stCent0 = new Point3D(Math.cos(thehit.get_Strip().get_Phi0()),Math.sin(thehit.get_Strip().get_Phi0()),0); + weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); weightedPhiErrSq0 += (thehit.get_Strip().get_PhiErr0()) * (thehit.get_Strip().get_PhiErr0()); } @@ -291,6 +296,9 @@ else if (this.get_Detector()==DetectorType.BMT) { weightedXC += strpEn * stCent.x(); weightedYC += strpEn * stCent.y(); weightedZC += strpEn * stCent.z(); + weightedX0 += strpEn * stCent0.x(); + weightedY0 += strpEn * stCent0.y(); + weightedZ0 += strpEn * stCent0.z(); weightedStrp += strpEn * (double) strpNb; weightedStrp0 += strpEn * (double) strpNb0; @@ -328,10 +336,12 @@ else if (this.get_Detector()==DetectorType.BMT) { weightedXC /= totEn; weightedYC /= totEn; weightedZC /= totEn; + weightedX0 /= totEn; + weightedY0 /= totEn; + weightedZ0 /= totEn; weightedZ /= totEn; - weightedPhi = Math.atan2(weightedYC, weightedXC); - weightedPhi0 /= totEn; - + weightedPhi = Math.atan2(weightedYC, weightedXC); + weightedPhi0 = Math.atan2(weightedY0, weightedX0); this.set_Centroid(weightedStrp); this.set_TotalEnergy(totEn); From 5e5f1c21652f82250d16065a1cbc7fe59882cbad Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 4 Oct 2021 16:55:35 +0200 Subject: [PATCH 172/291] CVT: SVT shifts properly accounted for in all geometry methods, geometry reorganization and cleanup --- .../geant4/v2/SVT/SVTAlignmentFactory.java | 4 +- .../detector/geant4/v2/SVT/SVTConstants.java | 23 +- .../geant4/v2/SVT/SVTStripFactory.java | 239 +++++++- .../main/java/org/jlab/rec/cvt/Constants.java | 1 - .../org/jlab/rec/cvt/banks/HitReader.java | 40 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 1 - .../jlab/rec/cvt/cluster/ClusterFinder.java | 2 - .../java/org/jlab/rec/cvt/cross/Cross.java | 21 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 28 +- .../rec/cvt/cross/HelixCrossListFinder.java | 66 +- .../cross/StraightTrackCrossListFinder.java | 15 +- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 4 +- .../jlab/rec/cvt/fit/StraightTrackFitter.java | 4 +- .../org/jlab/rec/cvt/hit/ADCConvertor.java | 5 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 8 +- .../jlab/rec/cvt/services/RecUtilities.java | 117 +++- .../rec/cvt/services/TracksFromTargetRec.java | 4 +- .../java/org/jlab/rec/cvt/svt/Constants.java | 351 ----------- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 575 +++++------------- .../org/jlab/rec/cvt/svt/SVTParameters.java | 154 +++++ .../jlab/rec/cvt/track/EnergyLossCorr.java | 11 +- .../rec/cvt/track/StraightTrackSeeder.java | 10 +- .../java/org/jlab/rec/cvt/track/Track.java | 6 +- .../rec/cvt/track/TrackCandListFinder.java | 21 +- .../jlab/rec/cvt/track/TrackListFinder.java | 5 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 14 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 8 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 57 +- 28 files changed, 813 insertions(+), 981 deletions(-) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java index fac568607..62aaf720f 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTAlignmentFactory.java @@ -307,10 +307,10 @@ public static Vector3d[] getIdealFiducials( int aRegion, int aSector ) throws Il double heatSinkTotalThk = SVTConstants.MATERIALDIMENSIONS.get("heatSink")[1]; double radius = SVTConstants.SUPPORTRADIUS[aRegion] + heatSinkTotalThk; - Transform labFrame = SVTConstants.getLabFrame( aRegion, aSector, radius, fidOriginZ ); + Transform detFrame = SVTConstants.getDetectorFrame( aRegion, aSector, radius, fidOriginZ ); for( int f = 0; f < SVTConstants.NFIDUCIALS; f++ ) - fidPos3Ds[f].transform(labFrame); + fidPos3Ds[f].transform(detFrame); return fidPos3Ds; } diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index 94147e513..8eb964767 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -6,7 +6,6 @@ import java.util.Map.Entry; import org.jlab.detector.calib.utils.DatabaseConstantProvider; // coatjava-3.0 -import org.jlab.geom.base.ConstantProvider; import eu.mihosoft.vrl.v3d.Transform; @@ -59,7 +58,7 @@ public class SVTConstants public static double STEREOANGLE; // total angle swept by sensor strips public static int[] STATUS; // whether a region is used in Reconstruction // - public static int[][] RSI; + public static int[][] RSI; // position and orientation of layers public static double PHI0; public static double SECTOR0; @@ -103,7 +102,9 @@ public class SVTConstants public static double STRIPLENMAX; // || AZ | DZ |MG| DZ | AZ | DZ |MG| DZ | AZ || public static double MODULEWID; // || DZ | AZ | DZ || public static double SECTORLEN; - + public static final double SIDETOL = 1.0; // extra width used in defining the module corners + public static final double LENGTHTOL = 10.0; // extra length for track intersection + // faraday cup cage public static double[] FARADAYCAGERMIN = new double[4]; public static double[] FARADAYCAGERMAX = new double[4]; @@ -115,6 +116,10 @@ public class SVTConstants public static double[] REGIONPEEKRMIN; public static double[] REGIONPEEKRMAX; public static double[] REGIONPEEKLENGTH; + + // material and radiation length information + public static final double SILICONRADLEN = 9.36 * 10; //check this - converted to mm + /** * Loads the the necessary tables for the SVT geometry for a given DatabaseConstantProvider. @@ -401,7 +406,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table System.out.println("Reading alignment shifts from database"); - + double[] myShift = {2, 2,-2, 0, 0, 0, 0,}; LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { @@ -419,6 +424,11 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table ty += ypos; tz += zpos; LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; + if (layer == 1 || layer == 2) { + for(int j=0; j NREGIONS-1 ){ throw new IllegalArgumentException("region out of bounds"); } if( aSector < 0 || aSector > NSECTORS[aRegion]-1 ){ throw new IllegalArgumentException("sector out of bounds"); } diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java index 3ea0f0a84..2dac0c3d5 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTStripFactory.java @@ -5,6 +5,7 @@ import eu.mihosoft.vrl.v3d.Transform; import eu.mihosoft.vrl.v3d.Vector3d; +import org.jlab.geom.prim.Vector3D; /** *

Geometry for the SVT

@@ -134,7 +135,7 @@ public Line3d getIdealStrip( int aRegion, int aSector, int aModule, int aStrip ) Line3d stripLine = createIdealStrip( aStrip, aModule ); // strip end points are returned relative to the front edge along z, and the centre along x double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; double z = SVTConstants.Z0ACTIVE[aRegion]; - return stripLine.transformed( SVTConstants.getLabFrame( aRegion, aSector, r, z ) ); // local frame -> lab frame + return stripLine.transformed( SVTConstants.getDetectorFrame( aRegion, aSector, r, z ) ); // local frame -> lab frame } @@ -299,10 +300,61 @@ public Line3d createShiftedStrip( int aRegion, int aSector, int aModule, int aSt double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; double z = SVTConstants.Z0ACTIVE[aRegion]; - return stripLine.transformed( SVTConstants.getLabFrame( aRegion, aSector, r, z ).invert() ); // lab frame -> local frame; + return stripLine.transformed( SVTConstants.getDetectorFrame( aRegion, aSector, r, z ).invert() ); // lab frame -> local frame; } + /** + * Returns the normal the module in the lab frame, depending on this factory's setup. + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @return Vector3d unit vector, normal to the plane, pointing radially outwards + * + * @see SVTStripFactory#setApplyAlignmentShifts + * @see SVTStripFactory#isSetApplyAlignmentShifts + */ + public Vector3d getModuleNormal( int aLayer, int aSector) + { + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + + Vector3d[] corners = this.getLayerCorners(aLayer, aSector); + + Vector3d v1 = corners[1].minus(corners[0]); // along the short edge + if(rm[1]==0) v1 = v1.negated(); // for odd layers, reverse the vector to have the normal always pointing radially outward + Vector3d v2 = corners[2].minus(corners[1]); // along the long edge, pointing to positive z + return v1.cross(v2).normalized(); + } + + /** + * Returns the end points of the module in the lab frame, depending on this factory's setup. + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @return Line3d going from origin to e end of modules + * + * @see SVTStripFactory#setApplyAlignmentShifts + * @see SVTStripFactory#isSetApplyAlignmentShifts + */ + public Line3d getModuleEndPoints( int aLayer, int aSector ) + { + Vector3d[] corners = null; + if( bShift ) + corners = getShiftedLayerCorners(aLayer, aSector ); + else + corners = getIdealLayerCorners(aLayer, aSector ); + + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + if(rm[1]==0) { // odd layers + return new Line3d(corners[1], corners[0]); + } + else { //even layers + return new Line3d(corners[0], corners[1]); + } + } + + + /** * Returns the corners of a sensor layer in the lab frame, depending on this factory's setup. * @@ -343,7 +395,7 @@ public Vector3d[] getLayerCorners( int aRegion, int aSector, int aModule ) /** - * Returns the corners of a sensor layer in the lab frame. + * Returns the corners of a sensor layer in the detector frame. * * @param aLayer an index starting from 0 * @param aSector an index starting from 0 @@ -360,7 +412,7 @@ public Vector3d[] getIdealLayerCorners( int aLayer, int aSector ) throws Illegal /** - * Returns the corners of a sensor layer in the lab frame. + * Returns the corners of a sensor layer in the detector frame. * * @param aRegion an index starting from 0 * @param aSector an index starting from 0 @@ -369,12 +421,12 @@ public Vector3d[] getIdealLayerCorners( int aLayer, int aSector ) throws Illegal */ public Vector3d[] getIdealLayerCorners( int aRegion, int aSector, int aModule ) { - Vector3d[] cornerPos3Ds = createIdealLayerCorners( aModule ); + Vector3d[] cornerPos3Ds = createIdealLayerCorners( aModule); double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; double z = SVTConstants.Z0ACTIVE[aRegion]; - Transform labFrame = SVTConstants.getLabFrame( aRegion, aSector, r, z ); - for( int i = 0; i < cornerPos3Ds.length; i++ ){ cornerPos3Ds[i].transform( labFrame ); } // local frame -> lab frame + Transform labFrame = SVTConstants.getDetectorFrame( aRegion, aSector, r, z ); + for( int i = 0; i < cornerPos3Ds.length; i++ ){ cornerPos3Ds[i].transform( labFrame ); } // local frame -> detector frame return cornerPos3Ds; } @@ -387,15 +439,15 @@ public Vector3d[] getIdealLayerCorners( int aRegion, int aSector, int aModule ) * @return Point3D[] array of corners in order ( origin, max width, max width and max length, max length ) * @throws IllegalArgumentException index out of bounds */ - public Vector3d[] createIdealLayerCorners( int aModule ) throws IllegalArgumentException + public Vector3d[] createIdealLayerCorners( int aModule) throws IllegalArgumentException { if( aModule < 0 || aModule > 1 ){ throw new IllegalArgumentException("module out of bounds"); } Vector3d[] cornerPos3Ds = new Vector3d[4]; - cornerPos3Ds[0] = new Vector3d( 0, 0, 0 ); - cornerPos3Ds[1] = new Vector3d( SVTConstants.ACTIVESENWID, 0, 0 ); - cornerPos3Ds[2] = new Vector3d( SVTConstants.ACTIVESENWID, 0, SVTConstants.STRIPLENMAX ); - cornerPos3Ds[3] = new Vector3d( 0, 0, SVTConstants.STRIPLENMAX ); + cornerPos3Ds[0] = new Vector3d( -SVTConstants.SIDETOL, 0, 0 ); + cornerPos3Ds[1] = new Vector3d( SVTConstants.SIDETOL + SVTConstants.ACTIVESENWID, 0, 0 ); + cornerPos3Ds[2] = new Vector3d( SVTConstants.SIDETOL + SVTConstants.ACTIVESENWID, 0, SVTConstants.STRIPLENMAX ); + cornerPos3Ds[3] = new Vector3d( -SVTConstants.SIDETOL, 0, SVTConstants.STRIPLENMAX ); Transform stripFrame = SVTConstants.getStripFrame( aModule == 0 ); // flip U layer for( int i = 0; i < cornerPos3Ds.length; i++ ){ cornerPos3Ds[i].transform( stripFrame ); } // strip frame -> local frame @@ -432,10 +484,13 @@ public Vector3d[] getShiftedLayerCorners( int aLayer, int aSector ) throws Illeg public Vector3d[] getShiftedLayerCorners( int aRegion, int aSector, int aModule ) { int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); - Vector3d[] cornerPos3Ds = getIdealLayerCorners( aRegion, aSector, aModule ); + Vector3d[] cornerPos3Ds = getIdealLayerCorners( aRegion, aSector, aModule ); if(aRegion local frame + cornerPos3Ds[i].transform( SVTConstants.getDetectorFrame( aRegion, aSector, r, z ).invert() ); // lab frame -> local frame return cornerPos3Ds; } /** + * Transform the (x,y,z) point from the lab to the local frame + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @param x + * @param y + * @param z + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLocal(int aLayer, int aSector, double x, double y, double z) + { + return this.transformToLocal(aLayer, aSector, new Vector3d(x,y,z)); + } + + /** + * Transform the pLab point from the lab to the local frame + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @param pLab a point in the lab frame + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLocal(int aLayer, int aSector, Vector3d pLab) + { + if( aLayer < 0 || aLayer > SVTConstants.NLAYERS-1 ){ + throw new IllegalArgumentException("layer out of bounds"); + } + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + if( aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]]-1){ + throw new IllegalArgumentException("sector out of bounds"); + } + return this.transformToLocal(rm[0], aSector, rm[1], pLab); + } + + /** + * Transform the pLab point from the lab to the local frame + * + * @param aRegion an index starting from 0 + * @param aSector an index starting from 0 + * @param aModule an index starting from 0 + * @param pLab a point in the lab frame + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLocal(int aRegion, int aSector, int aModule, Vector3d pLab) + { + if( aRegion < 0 || aRegion > SVTConstants.NREGIONS-1 ){ + throw new IllegalArgumentException("region out of bounds"); + } + int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); + if( aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion]-1){ + throw new IllegalArgumentException("sector out of bounds"); + } + Vector3d pLoc = pLab.clone(); + // transform to detector frame + AlignmentFactory.applyInverseShift(pLoc, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], + SVTAlignmentFactory.getIdealFiducialCenter(aRegion, aSector ), + scaleT, scaleR ); + // transform to local frame + double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; + double z = SVTConstants.Z0ACTIVE[aRegion]; + Transform labFrame = SVTConstants.getDetectorFrame( aRegion, aSector, r, z ); + pLoc.transform(labFrame.invert()); + + // transform to strip frame + Transform stripFrame = SVTConstants.getStripFrame(false); + pLoc.transform(stripFrame.invert()); + + return pLoc; + } + + + /** + * Transform the (x,y,z) point from the local to the lab frame + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @param x + * @param y + * @param z + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLab(int aLayer, int aSector, double x, double y, double z) + { + return this.transformToLab(aLayer, aSector, new Vector3d(x,y,z)); + } + + /** + * Transform the pLoc point from the strip to the lab frame + * + * @param aLayer an index starting from 0 + * @param aSector an index starting from 0 + * @param pLoc a point in the lab frame + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLab(int aLayer, int aSector, Vector3d pLoc) + { + if( aLayer < 0 || aLayer > SVTConstants.NLAYERS-1 ){ + throw new IllegalArgumentException("layer out of bounds"); + } + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + if( aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]]-1){ + throw new IllegalArgumentException("sector out of bounds"); + } + return this.transformToLab(rm[0], aSector, rm[1], pLoc); + } + + /** + * Transform the pLab point from the strip to the lab frame + * + * @param aRegion an index starting from 0 + * @param aSector an index starting from 0 + * @param aModule an index starting from 0 + * @param pLoc a point in the local frame + * @return Vector3d of point coordinate in the module local frame + * @throws IllegalArgumentException indices out of bounds + */ + public Vector3d transformToLab(int aRegion, int aSector, int aModule, Vector3d pLoc) + { + if( aRegion < 0 || aRegion > SVTConstants.NREGIONS-1 ){ + throw new IllegalArgumentException("region out of bounds"); + } + int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); + if( aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion]-1){ + throw new IllegalArgumentException("sector out of bounds"); + } + Vector3d pLab = pLoc.clone(); + + // transform to local frame + Transform stripFrame = SVTConstants.getStripFrame(false); + pLab.transform(stripFrame); + + // transform to detector frame + double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; + double z = SVTConstants.Z0ACTIVE[aRegion]; + Transform labFrame = SVTConstants.getDetectorFrame( aRegion, aSector, r, z ); + pLab.transform(labFrame); + + // transform to lab frame + AlignmentFactory.applyShift(pLab, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], + SVTAlignmentFactory.getIdealFiducialCenter(aRegion, aSector ), + scaleT, scaleR ); + + return pLab; + } + + + /** * Manually sets whether alignment shifts should be applied. * Use this to override the setting made at time of construction. * @@ -494,5 +701,5 @@ public void setAlignmentShiftScale( double aScaleTranslation, double aScaleRotat { scaleT = aScaleTranslation; scaleR = aScaleRotation; - } + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 6d7436495..17d04487f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -278,7 +278,6 @@ public static synchronized void Load(boolean isCosmics, boolean isSVTonly) { Constants.setCosmicsData(false); setSVTOnly(isSVTonly); - org.jlab.rec.cvt.svt.Constants.Load(); org.jlab.rec.cvt.bmt.Constants.Load(); areConstantsLoaded = true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index 226762a8c..9b1f40559 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -1,12 +1,14 @@ package org.jlab.rec.cvt.banks; +import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +import org.jlab.geometry.prim.Line3d; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -14,7 +16,6 @@ import org.jlab.rec.cvt.hit.ADCConvertor; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; /** @@ -174,7 +175,7 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, strip[i] = bankDGTZ.getShort("component", i); ADC[i] = bankDGTZ.getInt("ADC", i); - double angle = 2. * Math.PI * ((double) (sector[i] - 1) / (double) org.jlab.rec.cvt.svt.Constants.NSECT[layer[i] - 1]) + org.jlab.rec.cvt.svt.Constants.PHI0[layer[i] - 1]; + double angle = geo.getSectorPhi(layer[i], sector[i]); int hemisphere = (int) Math.signum(Math.sin(angle)); if (sector[i] == 7 && layer[i] > 6) { hemisphere = 1; @@ -204,16 +205,31 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate Strip SvtStrip = new Strip(strip[i], adcConv.SVTADCtoDAQ(ADC[i], event), (double) time[i]); - SvtStrip.set_Pitch(Constants.PITCH); - // get the strip endPoints - double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); - Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); - Point3D EP2 = geo.transformToFrame(sector[i], layer[i], X[1][0], 0, X[1][1], "lab", ""); - SvtStrip.set_Line(new Line3D(EP1, EP2)); - SvtStrip.set_Normal(geo.findBSTPlaneNormal(sector[i], layer[i])); // add normal to the plane defined from the strip midpoint - SvtStrip.set_Module(new Line3D(geo.getPlaneModuleOrigin(sector[i], layer[i]), geo.getPlaneModuleEnd(sector[i], layer[i]))); + SvtStrip.set_Pitch(SVTGeometry.getPitch()); + // get the strip line + SvtStrip.set_Line(geo.getStrip(layer[i], sector[i], strip[i])); + SvtStrip.set_Module(geo.getModule(layer[i], sector[i])); + SvtStrip.set_Normal(geo.getNormal(layer[i], sector[i])); + +// double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); +// Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); +// Point3D EP2 = geo.transformToFrame(sector[i], layer[i], X[1][0], 0, X[1][1], "lab", ""); +//// SvtStrip.set_Line(new Line3D(EP1, EP2)); +//// if(Constants.geoDebug) System.out.println("Strip: layer " + layer[i] + " sector " + sector[i] + "\n" + SvtStrip.get_Line().toString()); +//// SvtStrip.set_Normal(geo.findBSTPlaneNormal(sector[i], layer[i])); // add normal to the plane defined from the strip midpoint +//// SvtStrip.set_Module(new Line3D(geo.getPlaneModuleOrigin(sector[i], layer[i]), geo.getPlaneModuleEnd(sector[i], layer[i]))); +// if(Constants.geoDebug) { +// Vector3D nn = geo.findBSTPlaneNormal(sector[i], layer[i]); +// Point3D l1 = geo.getPlaneModuleOrigin(sector[i], layer[i]); +// Point3D l2 = geo.getPlaneModuleEnd(sector[i], layer[i]); +// if(EP1.distance(SvtStrip.get_Module().origin())>1E-3 || EP2.distance(SvtStrip.get_Module().end())>1E-3 || +// l1.distance(SvtStrip.get_Line().origin())>1E-3 || l2.distance(SvtStrip.get_Line().end())>1E-3 || nn.cross(SvtStrip.get_Normal()).mag()>1E-6) { +// System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); +// System.out.println("Module \n" + SvtStrip.get_Module().toString()); +// } +// } if(layer[i]%2==1) { - SvtStrip.setToverX0(Constants.SILICONTHICK / Constants.SILICONRADLEN); + SvtStrip.setToverX0(SVTGeometry.getToverX0()); } else { SvtStrip.setToverX0(0); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 2c7208a93..8dc73da00 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -14,7 +14,6 @@ import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Transformation3D; import org.jlab.groot.data.H1F; import org.jlab.groot.graphics.EmbeddedCanvasTabbed; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index d8327e499..0bf2fc71c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -3,10 +3,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.svt.SVTGeometry; /** * diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index f7563ec9f..9eec21e81 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.cross; +import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.Collections; import org.jlab.detector.base.DetectorType; @@ -8,7 +9,6 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; /** @@ -368,7 +368,7 @@ public void set_CrossParamsSVT(Vector3D dirAtBstPlane, SVTGeometry geo) { } double[] Params = geo.getCrossPars(outlayerclus.get_Sector(), outlayerclus.get_Layer(), - inlayerclus.get_Centroid(), outlayerclus.get_Centroid(), "lab", dirAtBstPlane); + inlayerclus.get_Centroid(), outlayerclus.get_Centroid(), dirAtBstPlane); double val = Params[0]; if (Double.isNaN(val)) { @@ -453,7 +453,7 @@ public int get_SVTCosmicsRegion() { */ - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[4][0] + Constants.MODULERADIUS[5][0]) * 0.5 < 15) { + if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(3) < 15) { if (this.get_Point0().y() > 0) { theRegion = 6; } else { @@ -461,7 +461,7 @@ public int get_SVTCosmicsRegion() { } } - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[2][0] + Constants.MODULERADIUS[3][0]) * 0.5 < 15) { + if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(2) < 15) { if (this.get_Point0().y() > 0) { theRegion = 5; } else { @@ -469,7 +469,7 @@ public int get_SVTCosmicsRegion() { } } - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[0][0] + Constants.MODULERADIUS[1][0]) * 0.5 < 15) { + if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(1) < 15) { if (this.get_Point0().y() > 0) { theRegion = 4; } else { @@ -543,7 +543,6 @@ public void setcCrossRadius(double cCrossRadius) { public static void main(String arg[]) { - Constants.Load(); // Geometry geo = new Geometry(); ArrayList testList = new ArrayList(); @@ -592,14 +591,4 @@ public static void main(String arg[]) { } - public boolean isInFiducial(SVTGeometry svt_geo) { - boolean pass = true; - Point3D LC = svt_geo.transformToFrame(this.get_Sector(), this.get_Cluster1().get_Layer(), this.get_Point().x(), this.get_Point().y(), this.get_Point().z(), "local", ""); - if (((LC.x() < -0.10 || LC.x() > Constants.ACTIVESENWIDTH + 0.10)) - || ((LC.z() < -1 || LC.z() > Constants.MODULELENGTH + 1))) { - pass = false; - } - return pass; - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 75235ba4f..291a5c2f7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -8,8 +8,8 @@ import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; /** * Driver class to make crosses @@ -71,11 +71,11 @@ public ArrayList findSVTCrosses( //loop over the clusters // inner clusters for (Cluster inlayerclus : svt_innerlayrclus) { - if(inlayerclus.get_TotalEnergy() findSVTCrosses( // define new cross )) // a cut to avoid looping over all strips - from geometry there is a minimum (maximum) strip sum of inner and outer layers that can give a strip intersection - if ((inlayerclus.get_MinStrip() + outlayerclus.get_MinStrip() > Constants.sumStpNumMin) - && (inlayerclus.get_MaxStrip() + outlayerclus.get_MaxStrip() < Constants.sumStpNumMax)) { // the intersection is valid + if ((inlayerclus.get_MinStrip() + outlayerclus.get_MinStrip() > SVTParameters.sumStpNumMin) + && (inlayerclus.get_MaxStrip() + outlayerclus.get_MaxStrip() < SVTParameters.sumStpNumMax)) { // the intersection is valid // define new cross Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, inlayerclus.get_Sector(), inlayerclus.get_Region(), rid++); @@ -121,12 +121,14 @@ public ArrayList findSVTCrosses( } private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { - double Z = svt_geo.transformToFrame(Cluster1.get_Sector(), Cluster1.get_Layer(), c.get_Point().x(), c.get_Point().y(), c.get_Point().z(), "local", "").z(); + double Z = svt_geo.toLocal(Cluster1.get_Layer(), + Cluster1.get_Sector(), + c.get_Point()).z(); if(Z<0) Z=0; - if(Z>Constants.ACTIVESENLEN) - Z=Constants.ACTIVESENLEN; - Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z, svt_geo) / (Constants.PITCH / Math.sqrt(12.))); + if(Z>SVTGeometry.getActiveSensorLength()) + Z=SVTGeometry.getActiveSensorLength(); + Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z, svt_geo) /(SVTGeometry.getPitch() / Math.sqrt(12.))); Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z, svt_geo) ); } /** @@ -279,14 +281,14 @@ public ArrayList> sortClusterByDetectorAndIO( */ public List crossLooperCands(List> crosses) { // nb SVT layers - int nlayr = Constants.NLAYR; + int nlayr = SVTGeometry.NLAYERS; // list of crosses in a sector ArrayList>> secList = new ArrayList>>(); //initialize for (int i = 0; i < nlayr; i++) { secList.add(i, new ArrayList>()); - for (int j = 0; j < Constants.NSECT[i]; j++) { + for (int j = 0; j < SVTGeometry.NSECTORS[i]; j++) { secList.get(i).add(j, new ArrayList()); } } @@ -303,9 +305,9 @@ public List crossLooperCands(List> crosses) { ArrayList listOfCrossesToRm = new ArrayList(); for (int i = 0; i < nlayr; i++) { - for (int j = 0; j < Constants.NSECT[i]; j++) { + for (int j = 0; j < SVTGeometry.NSECTORS[i]; j++) { //System.out.println(" number of crosses in sector "+(j+1)+" = "+secList.get(i).get(j).size()); - if (secList.get(i).get(j).size() > Constants.MAXNUMCROSSESINMODULE) { + if (secList.get(i).get(j).size() > SVTParameters.MAXNUMCROSSESINMODULE) { listOfCrossesToRm.addAll(secList.get(i).get(j)); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index aaf3204e0..6d8b1c7f6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -9,8 +9,8 @@ import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackSeeder; @@ -248,7 +248,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; System.out.println(bmt_Ccross.get_Point().toString() + " " + bmt_Ccross.getcCrossRadius()); double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= Constants.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= SVTParameters.dzdrcut) // add this to the track pass = true; return pass; @@ -291,47 +291,47 @@ private Seed isTrack5(Cross c1, Cross c2, Cross c3, Cross c4, Cross c5) { if(c1==null || c2==null || c3==null || c4==null || c5==null) return null; double phi12 = Math.abs(relPhi(c1, c2)); - if (phi12 > Constants.phi12cut) { + if (phi12 > SVTParameters.phi12cut) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > Constants.phi13cut) { + if (phi13 > SVTParameters.phi13cut) { return null; } double phi14 = Math.abs(relPhi(c1, c4)); - if (phi14 > Constants.phi14cut) { + if (phi14 > SVTParameters.phi14cut) { return null; } double phi15 = Math.abs(relPhi(c1, c5)); - if (phi15 > Constants.phi14cut) { + if (phi15 > SVTParameters.phi14cut) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < Constants.radcut) { + if (Math.abs(rad123) < SVTParameters.radcut) { return null; } double rad124 = radCurvature(c1, c2, c4); - if (Math.abs(rad124) < Constants.radcut) { + if (Math.abs(rad124) < SVTParameters.radcut) { return null; } double rad134 = radCurvature(c1, c3, c4); - if (Math.abs(rad134) < Constants.radcut) { + if (Math.abs(rad134) < SVTParameters.radcut) { return null; } double rad234 = radCurvature(c2, c3, c4); - if (Math.abs(rad234) < Constants.radcut) { + if (Math.abs(rad234) < SVTParameters.radcut) { return null; } double rad135 = radCurvature(c1, c3, c5); - if (Math.abs(rad135) < Constants.radcut) { + if (Math.abs(rad135) < SVTParameters.radcut) { return null; } double rad235 = radCurvature(c2, c3, c5); - if (Math.abs(rad235) < Constants.radcut) { + if (Math.abs(rad235) < SVTParameters.radcut) { return null; } double rad245 = radCurvature(c2, c4, c5); - if (Math.abs(rad245) < Constants.radcut) { + if (Math.abs(rad245) < SVTParameters.radcut) { return null; } double[] seed_delta_phi = {phi12, phi13, phi14, phi15}; @@ -351,31 +351,31 @@ private Seed isTrack4(Cross c1, Cross c2, Cross c3, Cross c4) { return null; double phi12 = Math.abs(relPhi(c1, c2)); - if (phi12 > Constants.phi12cut) { + if (phi12 > SVTParameters.phi12cut) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > Constants.phi13cut) { + if (phi13 > SVTParameters.phi13cut) { return null; } double phi14 = Math.abs(relPhi(c1, c4)); - if (phi14 > Constants.phi14cut) { + if (phi14 > SVTParameters.phi14cut) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < Constants.radcut) { + if (Math.abs(rad123) < SVTParameters.radcut) { return null; } double rad124 = radCurvature(c1, c2, c4); - if (Math.abs(rad124) < Constants.radcut) { + if (Math.abs(rad124) < SVTParameters.radcut) { return null; } double rad134 = radCurvature(c1, c3, c4); - if (Math.abs(rad134) < Constants.radcut) { + if (Math.abs(rad134) < SVTParameters.radcut) { return null; } double rad234 = radCurvature(c2, c3, c4); - if (Math.abs(rad234) < Constants.radcut) { + if (Math.abs(rad234) < SVTParameters.radcut) { return null; } double[] seed_delta_phi = {phi12, phi13, phi14}; @@ -394,15 +394,15 @@ private Seed isTrack3(Cross c1, Cross c2, Cross c3) { if(c1==null || c2==null || c3==null) return null; double phi12 = Math.abs(relPhi(c1,c2)); - if (phi12 > Constants.phi12cut) { + if (phi12 > SVTParameters.phi12cut) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > Constants.phi13cut) { + if (phi13 > SVTParameters.phi13cut) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < Constants.radcut) { + if (Math.abs(rad123) < SVTParameters.radcut) { return null; } @@ -458,7 +458,7 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_ if(cand==null) return; - Point3D trkAtR1 =cand.get_helix().getPointAtRadius(org.jlab.rec.cvt.svt.Constants.MODULERADIUS[0][0]+org.jlab.rec.cvt.svt.Constants.LAYRGAP/2); + Point3D trkAtR1 =cand.get_helix().getPointAtRadius(svt_geo.getRegionRadius(1)); List candMatches = new ArrayList(); for (int i = 0; i < R1Crosses.size(); i++) { if(R1Crosses.get(i)==null) @@ -468,14 +468,14 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_ Math.sqrt(R1Crosses.get(i).get_Point().x()*R1Crosses.get(i).get_Point().x()+R1Crosses.get(i).get_Point().y()*R1Crosses.get(i).get_Point().y()))<2) candMatches.add(R1Crosses.get(i)); } - Point3D trkAtL1 =cand.get_helix().getPointAtRadius(org.jlab.rec.cvt.svt.Constants.MODULERADIUS[0][0]); - Point3D trkAtL2 =cand.get_helix().getPointAtRadius(org.jlab.rec.cvt.svt.Constants.MODULERADIUS[0][0]+org.jlab.rec.cvt.svt.Constants.LAYRGAP); + Point3D trkAtL1 =cand.get_helix().getPointAtRadius(svt_geo.getLayerRadius(1)); + Point3D trkAtL2 =cand.get_helix().getPointAtRadius(svt_geo.getLayerRadius(2)); double dMin = Double.POSITIVE_INFINITY; Cross cMatch = null; for (int i = 0; i < candMatches.size(); i++) {//find cross for which the distance of the track to the 2 clusters in the double layers is minimal - double d = svt_geo.getDOCAToStrip(candMatches.get(i).get_Sector(), candMatches.get(i).get_Cluster1().get_Layer(), candMatches.get(i).get_Cluster1().get_Centroid(), trkAtL1) - +svt_geo.getDOCAToStrip(candMatches.get(i).get_Sector(), candMatches.get(i).get_Cluster2().get_Layer(), candMatches.get(i).get_Cluster2().get_Centroid(), trkAtL2); + double d = candMatches.get(i).get_Cluster1().residual(trkAtL1) + + candMatches.get(i).get_Cluster1().residual(trkAtL2); if(d CirTrks, Seed cand) { } private double calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { - double Z = svt_geo.transformToFrame(Cluster1.get_Sector(), Cluster1.get_Layer(), c.get_Point().x(), c.get_Point().y(), c.get_Point().z(), "local", "").z(); + double Z = svt_geo.toLocal(Cluster1.get_Layer(), + Cluster1.get_Sector(), + c.get_Point()).z(); if(Z<0) Z=0; - if(Z>Constants.ACTIVESENLEN) - Z=Constants.ACTIVESENLEN; - return Cluster1.get_ResolutionAlongZ(Z, svt_geo) / (Constants.PITCH / Math.sqrt(12.)); + if(Z>SVTGeometry.getActiveSensorLength()) + Z=SVTGeometry.getActiveSensorLength(); + return Cluster1.get_ResolutionAlongZ(Z, svt_geo) / (SVTGeometry.getPitch() / Math.sqrt(12.)); } /** * A class representing the seed object. The seed of a track is the initial diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index e9bb17d4a..e4567dda6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.cross; +import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -14,6 +15,7 @@ import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; /** * A class with methods used to find lists of crosses. This is the Pattern @@ -351,7 +353,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, } if (closestCross != null) // if there is a closest point it has to be within the cuts { - if (Math.abs(closestCross.get_Point0().x() - p.get_Point0().x()) < org.jlab.rec.cvt.svt.Constants.MAXDISTTOTRAJXY && Math.abs(closestCross.get_Point0().y() - p.get_Point0().y()) < org.jlab.rec.cvt.svt.Constants.MAXDISTTOTRAJXY) { + if (Math.abs(closestCross.get_Point0().x() - p.get_Point0().x()) < SVTParameters.MAXDISTTOTRAJXY && Math.abs(closestCross.get_Point0().y() - p.get_Point0().y()) < SVTParameters.MAXDISTTOTRAJXY) { crossList.add(closestCross); } @@ -461,17 +463,18 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, continue; } - for (int s = 0; s < org.jlab.rec.cvt.svt.Constants.NSECT[l]; s++) { + for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { double epsilon = 1e-6; - Vector3D n = svt_geo.findBSTPlaneNormal(s + 1, l + 1); - +// Vector3D n = svt_geo.findBSTPlaneNormal(s + 1, l + 1); + Vector3D n = svt_geo.getNormal(l+1, s+1); + double dot = (n.x() * yxslope + n.y()); if (Math.abs(dot) < epsilon) { continue; } - double R = (org.jlab.rec.cvt.svt.Constants.MODULERADIUS[l][0] + org.jlab.rec.cvt.svt.Constants.MODULERADIUS[l + 1][0]) / 2.; + double R = svt_geo.getRegionRadius(l/2+1); Vector3D w = new Vector3D(yxinterc - R * n.x(), -R * n.y(), 0); @@ -479,7 +482,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, Vector3D Delt = new Vector3D(fac * yxslope + yxinterc - R * n.x(), fac - R * n.y(), 0); - if (Delt.mag() < org.jlab.rec.cvt.svt.Constants.ACTIVESENWIDTH / 2) { + if (Delt.mag() < SVTGeometry.getActiveSensorWidth() / 2) { double tX = fac * yxslope + yxinterc; double tY = fac; Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index 6345ab559..f17052439 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.List; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.trajectory.Helix; import Jama.Matrix; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * A fitter which does sequential fit (for r, phi coordinates) to a circle using @@ -162,7 +162,7 @@ public FitStatus fit(List X, List Y, List Z, List Constants.MODULERADIUS[0][0]) { + if (Math.abs(fit_dca) > SVTGeometry.getLayerRadius(1)) { // if (Math.abs(fit_dca) > Constants.MODULERADIUS[0][0] || Math.abs(fit_Z0) > 100) { return null; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java index 41001931b..a0e85623a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java @@ -3,12 +3,12 @@ import java.util.ArrayList; import java.util.List; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.trajectory.Helix; import Jama.Matrix; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.svt.SVTGeometry; /** * A fitter which does sequential fit (for r, phi coordinates) to a circle using @@ -115,7 +115,7 @@ public FitStatus fit(List X, List Y, List Z, List Constants.MODULERADIUS[0][0] || Math.abs(fit_Z0) > 100) { + if (Math.abs(fit_dca) > SVTGeometry.getLayerRadius(1) || Math.abs(fit_Z0) > 100) { return null; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java index 3f1dff2a4..2ad690b08 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java @@ -4,6 +4,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.svt.SVTParameters; public class ADCConvertor { @@ -34,8 +35,8 @@ public double SVTADCtoDAQ(int adc, DataEvent event) { int START[] = new int[8]; int END[] = new int[8]; for (int i = 0; i < 8; i++) { - START[i] = org.jlab.rec.cvt.svt.Constants.initThresholds + org.jlab.rec.cvt.svt.Constants.deltaThresholds * i; - END[i] = org.jlab.rec.cvt.svt.Constants.initThresholds + org.jlab.rec.cvt.svt.Constants.deltaThresholds * (i + 1); + START[i] = SVTParameters.initThresholds + SVTParameters.deltaThresholds * i; + END[i] = SVTParameters.initThresholds + SVTParameters.deltaThresholds * (i + 1); } END[7] = 1000; //overflow diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 677cfb950..b25662e0d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -29,6 +29,7 @@ import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; /** * Service to return reconstructed TRACKS @@ -50,7 +51,6 @@ public class CVTRecNewKF extends ReconstructionEngine { public CVTRecNewKF() { super("CVTTracks", "ziegler", "4.0"); - SVTGeom = new SVTGeometry(); BMTGeom = new BMTGeometry(); strgtTrksRec = new CosmicTracksRec(); trksFromTargetRec = new TracksFromTargetRec(); @@ -154,7 +154,7 @@ public boolean processDataEvent(DataEvent event) { List hits = new ArrayList(); //I) get the hits List svt_hits = hitRead.get_SVTHits(); - if(svt_hits.size()>org.jlab.rec.cvt.svt.Constants.MAXSVTHITS) + if(svt_hits.size()>SVTParameters.MAXSVTHITS) return true; if (svt_hits != null && svt_hits.size() > 0) { hits.addAll(svt_hits); @@ -208,7 +208,7 @@ public boolean processDataEvent(DataEvent event) { List> crosses = new ArrayList>(); CrossMaker crossMake = new CrossMaker(); crosses = crossMake.findCrosses(clusters, SVTGeom, BMTGeom); - if(crosses.get(0).size() > org.jlab.rec.cvt.svt.Constants.MAXSVTCROSSES ) { + if(crosses.get(0).size() > SVTParameters.MAXSVTCROSSES ) { rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, null, null, shift); return true; } @@ -357,7 +357,7 @@ public boolean init() { cp = SVTConstants.connect( cp ); cp.disconnect(); SVTStripFactory svtFac = new SVTStripFactory(cp, true); - SVTGeom.setSvtStripFactory(svtFac); + SVTGeom = new SVTGeometry(svtFac); return true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index b84b39215..e1821343f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.services; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -9,8 +8,6 @@ import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.clas.tracking.objects.Strip; -import org.jlab.detector.geant4.v2.SVT.SVTConstants; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -55,8 +52,11 @@ public void CleanupSpuriousCrosses(List> crosses, List t List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { - double z = SVTGeom.transformToFrame(c.get_Sector(), c.get_Region()*2, c.get_Point().x(), c.get_Point().y(),c.get_Point().z(), "local", "").z(); - if(z<-0.1 || z>SVTConstants.MODULELEN) { + double z = SVTGeom.toLocal(c.get_Region()*2-1, + c.get_Sector(), + c.get_Point()).z(); + + if(z<-0.1 || z>SVTGeometry.getModuleLength()) { rmCrosses.add(c); } } @@ -126,7 +126,6 @@ public List setMeasVecs(Seed trkcand, Swim swim) { KFSites.add(meas); } } -// for(int i=0; i setMeasVecs(StraightTrack trkcand, Point3D endPt2 = cls.get(j).getLine().end(); Strip strp = new Strip(id, ce, endPt1.x(), endPt1.y(), endPt1.z(), endPt2.x(), endPt2.y(), endPt2.z()); - Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cls.get(j).get_Sector(), - cls.get(j).get_Layer())); - Point3D Or = sgeo.getPlaneModuleOrigin(cls.get(j).get_Sector(), cls.get(j).get_Layer()); - Point3D En = sgeo.getPlaneModuleEnd(cls.get(j).get_Sector(), cls.get(j).get_Layer()); - Surface meas = new Surface(pln, strp, Or, En); +// Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cls.get(j).get_Sector(), +// cls.get(j).get_Layer())); + Plane3D pln = new Plane3D(endPt1,cls.get(j).getN()); +// Point3D Or = sgeo.getPlaneModuleOrigin(cls.get(j).get_Sector(), cls.get(j).get_Layer()); +// Point3D En = sgeo.getPlaneModuleEnd(cls.get(j).get_Sector(), cls.get(j).get_Layer()); + Surface meas = new Surface(pln, strp, cls.get(j).origin(), cls.get(j).end()); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setSector(cls.get(j).get_Sector()); double err = cls.get(j).get_Resolution(); @@ -188,7 +188,7 @@ public List setMeasVecs(StraightTrack trkcand, // air gap ignored double thickn_ov_X0 = 0; if(cls.get(j).get_Layer()%2==1) - thickn_ov_X0 = org.jlab.rec.cvt.svt.Constants.SILICONTHICK / org.jlab.rec.cvt.svt.Constants.SILICONRADLEN; + thickn_ov_X0 = cls.get(j).get(0).get_Strip().getToverX0(); meas.setl_over_X0(thickn_ov_X0); //if((int)Constants.getLayersUsed().get(meas.getLayer())<1) // meas.notUsedInFit=true; @@ -252,17 +252,78 @@ else if (trkcand.get(i).get_Type()==BMTType.C) { return KFSites; } + public List FindClustersOnTrkNew (List allClusters, Helix helix, double P, int Q, + SVTGeometry sgeo, Swim swimmer) { + + int[] Sectors = new int[SVTGeometry.NLAYERS]; + // RDV it is not correct for tiltes/shifted geometry + for (int ilayer = 0; ilayer < SVTGeometry.NLAYERS; ilayer++) { + Point3D traj = helix.getPointAtRadius(sgeo.getLayerRadius(ilayer+1)); + int sec = sgeo.getSector(ilayer+1, traj); + Sectors[ilayer] = sec; + } + // initialize swimmer starting from the track vertex + double maxPathLength = 1; + swimmer.SetSwimParameters((helix.xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (helix.ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, helix.get_Z0() / 10, + Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), + P, Q, maxPathLength) ; + double[] inters = null; + double path = 0; + // SVT + List clustersOnTrack = new ArrayList(); + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + // reinitilize swimmer from last surface + if(inters!=null) { + double intersPhi = Math.atan2(inters[4], inters[3]); + double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), + P, Q, maxPathLength) ; + } + int layer = l + 1; + int sector = Sectors[l]; + if(sector == -1) + continue; + + double doca = Double.MAX_VALUE; + Point3D traj = null; + Cluster cluster = null; + for(Cluster cls : allClusters) { + if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { + // for first relevant cluster, swim to the plane to get the trajectory + if(traj==null) { + Vector3D n = cls.get(0).get_Strip().get_Normal(); + Point3D p = cls.get(0).get_Strip().get_Module().origin(); + double d = n.dot(p.toVector3D()); + inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); + if(inters!=null) + traj = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); + } + if(traj!=null) { + double clsDoca = cls.residual(traj); + if(Math.abs(clsDoca) FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, SVTGeometry sgeo, Swim swimmer) { Map clusMap = new HashMap(); //Map stripMap = new HashMap(); Map docaMap = new HashMap(); Map trajMap = new HashMap(); - int[] Sectors = new int[org.jlab.rec.cvt.svt.Constants.NLAYR]; + int[] Sectors = new int[SVTGeometry.NLAYERS]; + // RDV it is not correct for tilte/shifted geometry for (int a = 0; a < Sectors.length; a++) { - Point3D I = helix.getPointAtRadius(org.jlab.rec.cvt.svt.Constants.MODULERADIUS[a][0]); - int sec = sgeo.findSectorFromAngle(a + 1, I); - Sectors[a] = sec; + Point3D I = helix.getPointAtRadius(sgeo.getLayerRadius(a+1)); + int sec = sgeo.getSector(a+1, I); + Sectors[a] = sec; } // initialize swimmer starting from the track vertex double maxPathLength = 1; @@ -272,7 +333,7 @@ public List FindClustersOnTrk (List allClusters, Helix helix, double[] inters = null; double path = 0; // SVT - for (int l = 0; l < org.jlab.rec.cvt.svt.Constants.NLAYR; l++) { + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { // reinitilize swimmer from last surface if(inters!=null) { double intersPhi = Math.atan2(inters[4], inters[3]); @@ -285,15 +346,15 @@ public List FindClustersOnTrk (List allClusters, Helix helix, if(sector == -1) continue; - Vector3D n = sgeo.findBSTPlaneNormal(sector, layer); - Point3D p = sgeo.getPlaneModuleOrigin(sector, layer); + Vector3D n = sgeo.getNormal(layer, sector); + Point3D p = sgeo.getModule(layer, sector).origin(); double d = n.dot(p.toVector3D()); inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); if(inters!=null) { Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); double nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); //stripMap.put((sector*1000+layer), nearstp); - docaMap.put((sector*1000+layer), sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); + docaMap.put((sector*1000+layer), 10.0);//sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); trajMap.put((sector*1000+layer), trp); } } @@ -301,8 +362,7 @@ public List FindClustersOnTrk (List allClusters, Helix helix, int clsKey = cls.get_Sector()*1000+cls.get_Layer(); if(cls.get_AssociatedTrackID()==-1 && trajMap!=null && trajMap.get(clsKey)!=null) { //double trjCent = stripMap.get(clsKey); - double clsDoca = sgeo.getDOCAToStrip(cls.get_Sector(), cls.get_Layer(), - cls.get_Centroid(), trajMap.get(clsKey)); + double clsDoca = cls.residual(trajMap.get(clsKey)); if(clusMap.containsKey(clsKey)) { //double filldCent = clusMap.get(clsKey).get_Centroid(); double filldDoca = docaMap.get(clsKey); @@ -332,13 +392,14 @@ public void MatchTrack2Traj(Seed trkcand, Map clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, fittedTrack.get_helix(), + List clsOnTrack = recUtil.FindClustersOnTrkNew(SVTclusters, fittedTrack.get_helix(), fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); if(clsOnTrack.size()>0) { seed.get_Clusters().addAll(clsOnTrack); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java deleted file mode 100644 index 8ab85967b..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/Constants.java +++ /dev/null @@ -1,351 +0,0 @@ -package org.jlab.rec.cvt.svt; - -import java.util.ArrayList; -import org.jlab.detector.geant4.v2.SVT.SVTConstants; - -import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Shape3D; -import org.jlab.geom.prim.Triangle3D; - -public class Constants { - - - /** - * Constants used in the reconstruction - */ - Constants() { - } - //CUTS - public static int MAXSVTHITS = 700; - public static int MAXSVTCROSSES = 1000; - public static double RESIMAX = 5; - - // THRESHOLDS - public static int initThresholds = 30; - public static int deltaThresholds = 15; - - // RECONSTRUCTION CONSTANTS - public static final double RHOVTXCONSTRAINT = 1. / Math.sqrt(12.);//0.1; - public static final double ZVTXCONSTRAINT = 50. / Math.sqrt(12);//5cm - public static double ETOTCUT = 10.0; - // GEOMETRY PARAMETERS - public static final int[] NSECT = new int[8]; - public static final int NSLAYR = 2; - public static final int NLAYR = 6; - public static final int NREG = 3; - //public static final int NREG = 4; - public static final int NSTRIP = 256; - - public static final int MAXNUMSECT = 18; - // public static final int MAXNUMSECT = 24; - public static double[][] MODULERADIUS = new double[NLAYR][MAXNUMSECT]; // the radius of a BST module w.r.t. the beam axis - public static double[][] TX = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] TY = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] TZ = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] RX = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] RY = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] RZ = new double[NREG][MAXNUMSECT]; // shift par - public static double[][] RA = new double[NREG][MAXNUMSECT]; // shift par - - public static Point3D[][][] LEP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //left strip end point - public static Point3D[][][] REP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //right strip end point - - public static double FIDCUX = 17.35; - public static double FIDCUZ = 3.75; - public static double FIDPKX = 3.5; - public static double FIDPKZ0 = 402.624; - public static double FIDPKZ1 = 2.50; - public static double OriginZ = 62.13; - - public static double[] Z0 = new double[NLAYR]; // the z-position of a BST module in the lab-frame - public static double[] PHI0 = new double[NLAYR]; // the angle of the mid plane of the hybrid sensor for the first sector - - public static double PITCH = 0.156; - public static double STEREOANGLE = Math.toRadians(3.); // value of stereo angle - - //---------------- - // the unit is mm - //---------------- - public static final double SILICONTHICK = 0.320; // Silicon sensor width - - //public static final double ACTIVESENWIDTH = 40.052; - public static final double ACTIVESENWIDTH = 40.032; - public static final double STRIPTSTART = 0.048; - public static double LAYRGAP = 3.166; //LAYRGAP = 3.547; DB:3.166 - //public static double LAYRGAP = 3.262; //<-- GEMC value--> should be 3.236 - public static double ACTIVESENLEN = 109.955; - static double TOTSENLEN = 111.625; - static double MICROGAP = 0.112; - //public static double DEADZNLEN = TOTSENLEN-ACTIVESENLEN; - public static final double DEADZNLEN = 0.835; - //MODULELEN = NSENSORS*(ACTIVESENLEN + 2*DEADZNLEN) + (NSENSORS - 1)*MICROGAPLEN; - //STRIPLENMAX = MODULELEN - 2*DEADZNLEN; - - //public static final double MODULELENGTH = 3*ACTIVESENLEN+2*DEADZNLEN+2*MICROGAP; // active area for 3 sensors including inbetween dead zones - public static final double MODULELENGTH = 3 * ACTIVESENLEN + 4 * DEADZNLEN + 2 * MICROGAP; // active area for 3 sensors including inbetween dead zones - public static final double LOCZAXISROTATION = -Math.toRadians(90.); - - // CONSTANTS USED IN RECONSTRUCTION - //--------------------------------- - public static double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c - - // selection cuts for helical tracks - public static final double MINRADCURV = 200.00; //in cm - - // cut on Edep min; - public static double edep_min = 0.020; //20keV=0.020 - // cut on strip intersection tolerance - public static double TOLTOMODULELEN = 10.0; //10.0 = /1 cm - public static final double TOLTOMODULEEDGE = 1.0; // Tolerance for track trajectory point at layer to module fiducial edge (mm) - // sum of strip numbers for valid intersection: - //public static int sumStpNumMin = 174; - //public static int sumStpNumMax = 259; - public static int sumStpNumMin = 70; - public static int sumStpNumMax = 350; - - // contants for dEdx - //------------------ - //public static double rho = 2.3296; // g/cm^3 (Si) - static double CaThick = 0.5; - static double RohacellThick = 2.5; - static double Z_eff_roha = Math.pow((7.84 / 100.) * Math.pow(1, 2.94) + (64.5 / 100.) * Math.pow(6, 2.94) + (8.38 / 100.) * Math.pow(7, 2.94) + (19.12 / 100.) * Math.pow(8, 2.94), (1. / 2.94)); - - // empirical scaling factor from MC - public static double detMatZ_ov_A_timesThickn = (14. * 2 * SILICONTHICK / 28.0855 + (Z_eff_roha * RohacellThick / 12.0588) + 6 * CaThick / 12.0107); - //................... - //Code for identifying BST in making an ID for a bst intersection - public static int BSTidCode = 1; - - // ----- cut based cand select - public static double phi12cut = 35.; - public static double phi13cut = 35.; - public static double phi14cut = 35.; - public static double radcut = 100.; - public static double dzdrcut = 200.;// used to be 150 - - //BST misalignments - public static boolean isRadialMisalignmentTest = false; - public static final double RadSpecs = 0.750; - - public static final double CIRCLEFIT_MAXCHI2 = 100; - - public static final int BSTTRKINGNUMBERITERATIONS = 3; - - public static final int MAXNUMCROSSES = 50; - - public static final int MAXNUMCROSSESINMODULE = 4; - - // these are the constants for ADC to energy conversion - public static final int NBITSADC = 3; // 3bit adc for BST - - public static int EMAXREADOUT = 1; - - // for cosmics - public static final double COSMICSMINRESIDUAL = 12; - public static final double COSMICSMINRESIDUALZ = 120; - - public static ArrayList> MODULEPLANES; - - // track list cut-off - public static int maxNcands = 200; - public static boolean hasWidthResolution = false; - - public static boolean ignoreErr = false; - - public static boolean areConstantsLoaded = false; - - public static boolean removeClones = true; - - public static final double SILICONRADLEN = 9.36 * 10; //check this - converted to mm - - public static final double MODULEPOSFAC = 0.5; // % wrt top of module - - public static final double PIDCUTOFF = 2.6; - - public static double MAXDISTTOTRAJXY = 5; //max xy dist to cross in cm - - public static int BSTEXCLUDEDFITREGION = 0; - - public static boolean newGeometry = true; - - public static boolean LAYEREFFS = false; - - public static synchronized void Load() { - if (areConstantsLoaded) { - return; - } - - NSECT[0] = 10; - NSECT[1] = 10; - NSECT[2] = 14; - NSECT[3] = 14; - NSECT[4] = 18; - NSECT[5] = 18; - - Z0[0] = SVTConstants.Z0ACTIVE[0]; - Z0[1] = SVTConstants.Z0ACTIVE[0]; - Z0[2] = SVTConstants.Z0ACTIVE[1]; - Z0[3] = SVTConstants.Z0ACTIVE[1]; - Z0[4] = SVTConstants.Z0ACTIVE[2]; - Z0[5] = SVTConstants.Z0ACTIVE[2]; - - for(int k =0; k<6; k++) - PHI0[k] = SVTConstants.PHI0; - - for (int s = 0; s < NSECT[0]; s++) { - MODULERADIUS[0][s] = SVTConstants.LAYERRADIUS[0][0]; - } - for (int s = 0; s < NSECT[2]; s++) { - MODULERADIUS[2][s] = SVTConstants.LAYERRADIUS[1][0]; - } - for (int s = 0; s < NSECT[4]; s++) { - MODULERADIUS[4][s] = SVTConstants.LAYERRADIUS[2][0]; - } - - for (int s = 0; s < NSECT[1]; s++) { - MODULERADIUS[1][s] = SVTConstants.LAYERRADIUS[0][1]; - } - for (int s = 0; s < NSECT[3]; s++) { - MODULERADIUS[3][s] = SVTConstants.LAYERRADIUS[1][1]; - } - for (int s = 0; s < NSECT[5]; s++) { - MODULERADIUS[5][s] = SVTConstants.LAYERRADIUS[2][1]; - } - - LAYRGAP = MODULERADIUS[1][0] - MODULERADIUS[0][0]; - - SVTGeometry geo = new SVTGeometry(); - for(int l =0; l < NLAYR; l++) { - for(int j = 0; j< NSECT[l]; j++) { - for(int k = 0; k> modules = new ArrayList>(); - //Geometry geo = new Geometry(); - - for (int layer = 1; layer <= 8; layer++) { - ArrayList layerModules = new ArrayList(); - - for (int sector = 1; sector <= Constants.NSECT[layer - 1]; sector++) { - - Shape3D module = new Shape3D(); - - Point3D PlaneModuleOrigin = geo.getPlaneModuleOrigin(sector, layer); - double x0 = PlaneModuleOrigin.x(); - double y0 = PlaneModuleOrigin.y(); - Point3D PlaneModuleEnd = geo.getPlaneModuleEnd(sector, layer); - double x1 = PlaneModuleEnd.x(); - double y1 = PlaneModuleEnd.y(); - - double[] z = new double[6]; - z[0] = PlaneModuleOrigin.z(); - z[1] = PlaneModuleOrigin.z() + Constants.ACTIVESENLEN; - z[2] = PlaneModuleOrigin.z() + Constants.ACTIVESENLEN + 1 * Constants.DEADZNLEN; - z[3] = PlaneModuleOrigin.z() + 2 * Constants.ACTIVESENLEN + 1 * Constants.DEADZNLEN; - z[4] = PlaneModuleOrigin.z() + 2 * Constants.ACTIVESENLEN + 2 * Constants.DEADZNLEN; - z[5] = PlaneModuleOrigin.z() + 3 * Constants.ACTIVESENLEN + 2 * Constants.DEADZNLEN; - - for (int i = 0; i < 5; i++) { - Point3D ModulePoint1 = new Point3D(x0, y0, z[i]); - Point3D ModulePoint2 = new Point3D(x1, y1, z[i]); - Point3D ModulePoint3 = new Point3D(x0, y0, z[i + 1]); - Point3D ModulePoint4 = new Point3D(x1, y1, z[i + 1]); - - Triangle3D Module1 = new Triangle3D(ModulePoint1, ModulePoint2, ModulePoint4); - Triangle3D Module2 = new Triangle3D(ModulePoint1, ModulePoint3, ModulePoint4); - - module.addFace(Module1); - module.addFace(Module2); - } - - layerModules.add(module); - } - modules.add(layer - 1, layerModules); - } - MODULEPLANES = modules; - } - - areConstantsLoaded = true; - System.out.println(" SVT geometry constants loaded ? " + areConstantsLoaded); - - } - -} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 015756f54..1881b9b87 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -1,164 +1,146 @@ package org.jlab.rec.cvt.svt; -//import java.io.File; import eu.mihosoft.vrl.v3d.Vector3d; -import java.io.FileNotFoundException; +import org.jlab.detector.geant4.v2.SVT.SVTConstants; +import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.prim.Line3D; - import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.rec.cvt.trajectory.Helix; - -import org.jlab.detector.geant4.v2.SVT.*; -import org.jlab.detector.geant4.v2.SVT.SVTConstants; -import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; -import org.jlab.detector.geant4.v2.SVT.AlignmentFactory; import org.jlab.geometry.prim.Line3d; public class SVTGeometry { - private SVTStripFactory _svtStripFactory; - - public SVTStripFactory getStripFactory() { - return _svtStripFactory; + private final SVTStripFactory _svtStripFactory; + public static final int NREGIONS = 3; + public static final int NLAYERS = 6; + public static final int NSTRIPS = SVTConstants.NSTRIPS; + public static final int[] NSECTORS = new int[NLAYERS]; + + + + public SVTGeometry(SVTStripFactory factory) { + this._svtStripFactory = factory; + this.init(); } + + private void init() { + for(int ilayer=0; ilayer 1; max. value 8: (8+1)/2 -> 4.5 -> 5? - int myLayerIndex = 2*(region - 1); // always even - int mySectorIndex = sector - 1; - - Line3d l1 = this._svtStripFactory.getStrip(myLayerIndex, mySectorIndex, 0); - Line3d l2 = this._svtStripFactory.getStrip(myLayerIndex, mySectorIndex, 255); - - // subtracts origin of first strip from end of first strip; substracts origin of last strip from end of last strip; - Vector3d u1 = l1.end().sub(l1.origin()); - Vector3d u2 = l2.end().sub(l2.origin()); - - Vector3d n = u1.cross(u2).normalized(); - return new Vector3D(n.x, n.y, 0); - } - //*** public double[] getLocCoord(double s1, double s2) { //2 top, 1 bottom @@ -208,65 +190,11 @@ public double[] getLocCoordErrs(int lay1, int lay2, double s1, double s2, double return Xerr; } + - public Point3D transformToFrame(int sector, int layer, double x, double y, double z, String frame, String MiddlePlane) { - - int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); - - double gap = 0; - - if (MiddlePlane.equals("middle")) { - if ((layer - 1) % 2 == 0) { // for a cross take the bottom layer; - int[] rm1 = SVTConstants.convertLayer2RegionModule(layer); - int[] rm2 = SVTConstants.convertLayer2RegionModule(layer-1); - //gap = SVTConstants.LAYERRADIUS[rm1[0]][rm1[1]] - // - SVTConstants.LAYERRADIUS[rm2[0]][rm2[1]]; //gap+=0.004; - } - } - Point3D transf = null; - if (frame.equals("lab")) { - Line3d localLine = new Line3d(new Vector3d(x-SVTConstants.ACTIVESENWID/2, y, z), - new Vector3d(x-SVTConstants.ACTIVESENWID/2, y, z)) ; - Line3d labFrameLine = localLine.transformed(SVTConstants.getLabFrame( (int)((layer+1)/2) -1, - sector-1, - //= SVTConstants.LAYERRADIUS[rm[0]][rm[1]] - SVTConstants.LAYERRADIUS[rm[0]][rm[1]]+gap/2, - SVTConstants.Z0ACTIVE[rm[0]] )); - - - //gpg apply the shifts to both ends of labFrameLine. - double scaleT = 1.0, scaleR = -1.0;// scale factors used for visualization. Not relevant here. - AlignmentFactory.applyShift(labFrameLine.origin(),SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); - AlignmentFactory.applyShift(labFrameLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1),scaleT,scaleR ); - - transf= new Point3D(labFrameLine.origin().x, - labFrameLine.origin().y, - labFrameLine.origin().z); - } - if (frame.equals("local")) { - Line3d glLine = new Line3d(new Vector3d(x,y,z), - new Vector3d(x,y,z)) ; - boolean flip = true; - - //gpg need to apply the reverse survey shifts here. - double scaleT = 1.0, scaleR = -1.0;// scale factors used for visualization. Not relevant here. - AlignmentFactory.applyInverseShift( glLine.origin(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); - AlignmentFactory.applyInverseShift( glLine.end(), SVTConstants.getLayerSectorAlignmentData()[sector-1][layer-1], SVTAlignmentFactory.getIdealFiducialCenter( rm[0], sector-1 ), scaleT, scaleR ); - - Line3d localLine = glLine.transformed(SVTConstants.getLabFrame( (int)((layer+1)/2) -1, - sector-1, - SVTConstants.LAYERRADIUS[rm[0]][rm[1]]+gap/2, - SVTConstants.Z0ACTIVE[rm[0]] ).invert()); - transf= new Point3D(localLine.origin().x+SVTConstants.ACTIVESENWID/2, - localLine.origin().y, - localLine.origin().z); - } - return transf; - } - //*** point and its error - - public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, String frame, Vector3D trkDir) { - double[] vals = new double[6]; + public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, Vector3D trkDir) { + + double[] vals = new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; // if first iteration trkDir == null double s2corr = s2; @@ -282,28 +210,24 @@ public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, S s2corr = s2; } - double[] LC = getLocCoord(s1, s2corr); - double LC_x = LC[0]; - double LC_z = LC[1]; - - Point3D crPoint = transformToFrame(sector, upperlayer - 1, LC_x, 0, LC_z, "lab", "middle"); - - vals[0] = crPoint.x(); - vals[1] = crPoint.y(); - vals[2] = crPoint.z(); + double[] LC = getLocCoord(s1, s2corr); double[] LCErr = getLocCoordErrs(upperlayer - 1, upperlayer, s1, s2corr, zf); + + Point3D crPoint = this.toGlobal(upperlayer-1, sector, new Point3D(LC[0], 0, LC[1])); + Vector3D crErr = this.toGlobal(upperlayer-1, sector, new Vector3D(LCErr[0], 0, LCErr[1])); + double LCErr_x = LCErr[0]; double LCErr_z = LCErr[1]; - // global rotation angle to get the error in the lab frame - int layerIdx = upperlayer - 1; + // global rotation angle to get the error in the local frame int[] rm = SVTConstants.convertLayer2RegionModule(upperlayer-1); // global rotation angle double Glob_rangl = ((double) -(sector - 1) / (double) SVTConstants.NSECTORS[rm[0]]) * 2. * Math.PI + SVTConstants.PHI0; // angle to rotate to global frame - double Loc_to_Glob_rangl = Glob_rangl - org.jlab.rec.cvt.svt.Constants.LOCZAXISROTATION; + double LOCZAXISROTATION = -Math.toRadians(90.); + double Loc_to_Glob_rangl = Glob_rangl - LOCZAXISROTATION; double cosRotation = Math.cos(Loc_to_Glob_rangl); double sinRotation = Math.sin(Loc_to_Glob_rangl); @@ -311,31 +235,30 @@ public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, S double yerr = Math.abs(cosRotation * LCErr_x); double xerr = Math.abs(sinRotation * LCErr_x); - vals[3] = xerr; - vals[4] = yerr; - vals[5] = LCErr_z; - - if (LC_z > SVTConstants.MODULELEN + org.jlab.rec.cvt.svt.Constants.TOLTOMODULELEN * 2) { - return new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; + // RDV: check because old errors seems to be rotated by 90 deg +// System.out.println("Cross:\n" + xerr + " " + yerr + " " + LCErr_z); +// System.out.println(crErr.toString()); +// System.out.println(crPoint.toString()); + + if (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL * 2) { + return vals; } - // once there is a trk, the cross should be well calculated //if the local cross is not in the fiducial volume it is not physical - if ((trkDir != null && (LC_x < 0 || LC_x > SVTConstants.ACTIVESENWID + org.jlab.rec.cvt.svt.Constants.TOLTOMODULEEDGE)) - || (trkDir != null && (LC_z < -org.jlab.rec.cvt.svt.Constants.TOLTOMODULELEN - || LC_z > SVTConstants.MODULELEN + org.jlab.rec.cvt.svt.Constants.TOLTOMODULELEN))) { - return new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; + else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConstants.ACTIVESENWID + SVTConstants.SIDETOL)) + || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN+ SVTConstants.LENGTHTOL))) { + return vals; } - - double[] values = new double[6]; - if (frame.equals("lab")) { - values = vals; - } - if (frame.equals("local")) { - values = new double[]{LC_x, 0, LC_z, LCErr_x, 0, LCErr_z}; + else { + vals[0] = crPoint.x(); + vals[1] = crPoint.y(); + vals[2] = crPoint.z(); + vals[3] = Math.abs(crErr.x()); + vals[4] = Math.abs(crErr.y()); + vals[5] = Math.abs(crErr.z()); } - return values; + return vals; } @@ -361,10 +284,10 @@ private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D public double calcNearestStrip(double X, double Y, double Z, int layer, int sect) { - Point3D LocPoint = this.transformToFrame(sect, layer, X, Y, Z, "local", ""); + Vector3d LocPoint = this._svtStripFactory.transformToLocal(layer-1, sect-1, X, Y, Z); - double x = LocPoint.x(); - double z = LocPoint.z(); + double x = LocPoint.x; + double z = LocPoint.y; double alpha = SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); @@ -486,27 +409,6 @@ public double getSingleStripResolution(int lay, int strip, double Z) { // as a f } //**** - public double getDOCAToStrip(int sector, int layer, double centroidstrip, Point3D point0) { - double[][] X = this.getStripEndPoints(centroidstrip, (layer - 1) % 2); - Point3D EP1 = this.transformToFrame(sector, layer, X[0][0], 0, X[0][1], "lab", ""); - Point3D EP2 = this.transformToFrame(sector, layer, X[1][0], 0, X[1][1], "lab", ""); - Line3D l = new Line3D(EP1, EP2); - if(l.direction().z()<0) { - l.setEnd(EP1); - l.setOrigin(EP2); - } - Line3D WL = new Line3D(); - WL.copy(l); - WL.copy(WL.distance(point0)); - double sideStrip = Math.signum(l.direction().cross(WL.direction()). - dot(this.findBSTPlaneNormal(sector, layer))); - //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); - return WL.length()*sideStrip; - - - } - //**** - // in the local coordinate system public double getXAtZ(int layer, double centroidstrip, double Z) { double X = 0; @@ -536,15 +438,12 @@ public double getStripIndexShift(int sector, int layer, Vector3D trkDir, double double tx = trkDir.x(); double ty = trkDir.y(); - Vector3D trkDir_t = new Vector3D(tx / Math.sqrt(tx * tx + ty * ty), - ty / Math.sqrt(tx * tx + ty * ty), - 0 ); - Vector3D n = findBSTPlaneNormal(sector, layer); - - if (org.jlab.rec.cvt.Constants.isCosmicsData() && Math.acos(n.dot(trkDir_t)) > Math.PI / 2) { // flip track dir for y<0 for cosmics: - trkDir_t = new Vector3D(-trkDir_t.x(), - -trkDir_t.y(), - 0 ); + Vector3D trkDir_t = new Vector3D(tx,ty,0); + trkDir_t.unit(); + Vector3D n = this.getNormal(layer, sector); + + if (Math.acos(n.dot(trkDir_t)) > Math.PI / 2) { // flip track dir for y<0 for cosmics: + trkDir_t.negative(); } double TrkToPlnNormRelatAngl = Math.acos(n.dot(trkDir_t)); @@ -574,173 +473,15 @@ public double getStripIndexShift(int sector, int layer, Vector3D trkDir, double } //*** - public double planeNormDotTrkDir(int sector, int layer, Point3D trkDir, double s2, double z) { - double tx = trkDir.x(); - double ty = trkDir.y(); - Vector3D trkDir_t = new Vector3D(tx / Math.sqrt(tx * tx + ty * ty), ty / Math.sqrt(tx * tx + ty * ty), 0); - Vector3D n = findBSTPlaneNormal(sector, layer); - - return Math.abs(n.dot(trkDir_t)); - } - - //*** - public Point3D intersectionOfHelixWithPlane(int layer, int sector, Helix helix) { + public boolean isInFiducial(int layer, int sector, Point3D traj) { - int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); - - int nstep = 1; - double stepSize = 0.001; - - double Theta = Math.atan2((SVTConstants.ACTIVESENWID / 2), - SVTConstants.LAYERRADIUS[rm[0]][rm[1]]); // = - - double RMin = SVTConstants.LAYERRADIUS[rm[0]][rm[1]]; - double RMax = RMin / Math.cos(Theta); - double R = RMin; - - Point3D InterPoint = helix.getPointAtRadius(R); - - double minDelta = RMax - RMin; - - while (R < RMax) { - - Point3D I = helix.getPointAtRadius(R); - Vector3D Inorm = I.toVector3D().asUnit(); - - double Rinter = RMin / findBSTPlaneNormal(sector, layer).dot(Inorm); - double y_rho = Math.sqrt(I.x() * I.x() + I.y() * I.y()); - if (Math.abs(Rinter - y_rho) < minDelta) { - InterPoint = I; - minDelta = Math.abs(Rinter - y_rho); - } - R += nstep * stepSize; - nstep++; - - } - return InterPoint; - - } - - public Point3D recalcCrossFromTrajectoryIntersWithModulePlanes(int s, double s1, double s2, int l1, int l2, - double trajX1, double trajY1, double trajZ1, - double trajX2, double trajY2, double trajZ2) { - Point3D LocPoint1 = this.transformToFrame(s, l1, trajX1, trajY1, trajZ1, "local", ""); - Point3D LocPoint2 = this.transformToFrame(s, l2, trajX2, trajY2, trajZ2, "local", ""); - double m = (LocPoint1.x() - LocPoint2.x()) / - (LocPoint1.z() - LocPoint2.z()); - double b = LocPoint1.x() - m * LocPoint1.z(); - - double ialpha1 = (s1 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc1 = (s1 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - double ialpha2 = (s2 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc2 = (s2 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - - // Equation for strip line is x = mz + b [i.e. z is the direction of the length of the module] - // ------------------------------------- - double m1 = -Math.tan(ialpha1); - double m2 = Math.tan(ialpha2); - double b1 = SVTConstants.ACTIVESENWID - interc1; - double b2 = interc2; - - double z1 = (b - b1) / (m1 - m); - double x1 = m1 * z1 + b1; - double z2 = (b - b2) / (m2 - m); - double x2 = m2 * z2 + b2; - - Point3D Point1 = this.transformToFrame(s, l1, x1, 0, z1, "lab", ""); - Point3D Point2 = this.transformToFrame(s, l2, x2, 0, z2, "lab", ""); - // unit vec along dir of track - Vector3D t = new Vector3D(Point2.x() - Point1.x(), Point2.y() - Point1.y(), Point2.z() - Point1.z()).asUnit(); - //normal to plane of module - Vector3D n = this.findBSTPlaneNormal(s, l1); - - int[] rm1 = SVTConstants.convertLayer2RegionModule(l1-1); - int[] rm2 = SVTConstants.convertLayer2RegionModule(l2-1); - - //path length tranversed inbetween modules - double l = (SVTConstants.LAYERRADIUS[rm1[0]][rm1[1]] - SVTConstants.LAYERRADIUS[rm2[0]][rm2[1]]) / (n.dot(t)); - //Point inbetween the modules - - Point3D Point = new Point3D(Point1.x() + t.x() * ((double) l / 2), - Point1.y() + t.y() * ((double) l / 2), - Point1.z() + t.z() * ((double) l / 2) ); - - return Point; - } - - public Line3d getStrip(int alayer, int asector, int astrip) { - - Line3d shiftedStrip = this._svtStripFactory.getStrip(alayer, asector, astrip); // shifted if bshift = true - - return shiftedStrip; - } - - public double[][] getStripEndPoints(double strip, int slyr) { //1 top, 0 bottom - - double[][] X = new double[2][2]; - - double z1 = 0; - double x1 = 0; - double z2 = 0; - double x2 = 0; - - // Equation for strip line is x = mz + b [i.e. z is the direction of the length of the module] - // ------------------------------------- - if (slyr == 0) { - double s1 = strip; - double ialpha1 = (s1 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc1 = (s1 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - double m1 = -Math.tan(ialpha1); - double b1 = SVTConstants.ACTIVESENWID - interc1; - - z1 = 0; - x1 = m1 * z1 + b1; - z2 = SVTConstants.MODULELEN; - x2 = m1 * z2 + b1; - - if (x2 < 0) { - x2 = 0; - z2 = -b1 / m1; - } - } - - if (slyr == 1) { - double s2 = strip; - double ialpha2 = (s2 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc2 = (s2 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - double m2 = Math.tan(ialpha2); - double b2 = interc2; - - z1 = 0; - x1 = m2 * z1 + b2; - z2 = SVTConstants.MODULELEN; - x2 = m2 * z2 + b2; - - if (x2 > SVTConstants.ACTIVESENWID) { - x2 = SVTConstants.ACTIVESENWID; - z2 = (x2 - b2) / m2; - } - } - X[0][0] = x1; - X[0][1] = z1; - X[1][0] = x2; - X[1][1] = z2; - -/* - System.out.println("createIdealStrip: " + this._svtStripFactory.createIdealStrip(strip, slyr)); - System.out.println("X: " + strip + " + " + slyr ); - System.out.println(" x1: " + X[0][0] ); - System.out.println(" z1: " + X[0][1] ); - System.out.println(" x2: " + X[1][0] ); - System.out.println(" z2: " + X[1][1] ); -*/ - return X; - } - - public static void main(String arg[]) throws FileNotFoundException { + Point3D local = this.toLocal(layer, sector, traj); + + if(local.x()<-SVTConstants.SIDETOL || local.x()>(SVTConstants.ACTIVESENWID+SVTConstants.SIDETOL)) + return false; + else if(local.z()<-SVTConstants.LENGTHTOL || local.z()>(SVTConstants.MODULELEN+SVTConstants.LENGTHTOL)) + return false; + else + return true; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java new file mode 100644 index 000000000..637dd9241 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java @@ -0,0 +1,154 @@ +package org.jlab.rec.cvt.svt; + +import org.jlab.detector.geant4.v2.SVT.SVTConstants; + + +public class SVTParameters { + + + /** + * Constants used in the reconstruction + */ + SVTParameters() { + } + public static boolean geoDebug = false; + //CUTS + public static int MAXSVTHITS = 700; + public static int MAXSVTCROSSES = 1000; + public static double RESIMAX = 5; + + // THRESHOLDS + public static int initThresholds = 30; + public static int deltaThresholds = 15; + + // RECONSTRUCTION CONSTANTS +// public static final double RHOVTXCONSTRAINT = 1. / Math.sqrt(12.);//0.1; +// public static final double ZVTXCONSTRAINT = 50. / Math.sqrt(12);//5cm + public static double ETOTCUT = 10.0; + // GEOMETRY PARAMETERS +// public static final int[] NSECT = new int[8]; +// public static final int NSLAYR = 2; +// public static final int NLAYR = 6; +// public static final int NREG = 3; + //public static final int NREG = 4; +// public static final int NSTRIP = 256; + +// public static final int MAXNUMSECT = 18; + +// public static Point3D[][][] LEP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //left strip end point +// public static Point3D[][][] REP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //right strip end point + +// public static double FIDCUX = 17.35; +// public static double FIDCUZ = 3.75; +// public static double FIDPKX = 3.5; +// public static double FIDPKZ0 = 402.624; +// public static double FIDPKZ1 = 2.50; +// public static double OriginZ = 62.13; + +// d public static double[] Z0 = new double[NLAYR]; // the z-position of a BST module in the lab-frame +// d public static double[] PHI0 = new double[NLAYR]; // the angle of the mid plane of the hybrid sensor for the first sector + +// public static double PITCH = 0.156; +// public static double STEREOANGLE = Math.toRadians(3.); // value of stereo angle + + //---------------- + // the unit is mm + //---------------- +// public static final double SILICONTHICK = 0.320; // Silicon sensor width + + //public static final double ACTIVESENWIDTH = 40.052; +// public static final double ACTIVESENWIDTH = 40.032; +// public static final double STRIPTSTART = 0.048; + + //public static double LAYRGAP = 3.262; //<-- GEMC value--> should be 3.236 +// public static double ACTIVESENLEN = 109.955; +// static double TOTSENLEN = 111.625; +// static double MICROGAP = 0.112; + //public static double DEADZNLEN = TOTSENLEN-ACTIVESENLEN; +// public static final double DEADZNLEN = 0.835; + //MODULELEN = NSENSORS*(ACTIVESENLEN + 2*DEADZNLEN) + (NSENSORS - 1)*MICROGAPLEN; + //STRIPLENMAX = MODULELEN - 2*DEADZNLEN; + + + // RDV CHECK CHECK + //public static final double MODULELENGTH = 3*ACTIVESENLEN+2*DEADZNLEN+2*MICROGAP; // active area for 3 sensors including inbetween dead zones +// public static final double MODULELENGTH = 3 * ACTIVESENLEN + 4 * DEADZNLEN + 2 * MICROGAP; // active area for 3 sensors including inbetween dead zones +// public static final double LOCZAXISROTATION = -Math.toRadians(90.); + + // CONSTANTS USED IN RECONSTRUCTION + //--------------------------------- + public static double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c + + // selection cuts for helical tracks + public static final double MINRADCURV = 200.00; //in cm + + // cut on Edep min; + public static double edep_min = 0.020; //20keV=0.020 + // sum of strip numbers for valid intersection: + //public static int sumStpNumMin = 174; + //public static int sumStpNumMax = 259; + public static int sumStpNumMin = 70; + public static int sumStpNumMax = 350; + + // contants for dEdx + //------------------ + //public static double rho = 2.3296; // g/cm^3 (Si) + static double CaThick = 0.5; + static double RohacellThick = 2.5; + static double Z_eff_roha = Math.pow((7.84 / 100.) * Math.pow(1, 2.94) + (64.5 / 100.) * Math.pow(6, 2.94) + (8.38 / 100.) * Math.pow(7, 2.94) + (19.12 / 100.) * Math.pow(8, 2.94), (1. / 2.94)); + + // empirical scaling factor from MC + public static double detMatZ_ov_A_timesThickn = (14. * 2 * SVTConstants.SILICONTHK / 28.0855 + (Z_eff_roha * RohacellThick / 12.0588) + 6 * CaThick / 12.0107); + //................... +// //Code for identifying BST in making an ID for a bst intersection +// public static int BSTidCode = 1; + + // ----- cut based cand select + public static double phi12cut = 35.; + public static double phi13cut = 35.; + public static double phi14cut = 35.; + public static double radcut = 100.; + public static double dzdrcut = 200.;// used to be 150 + + //BST misalignments +// public static boolean isRadialMisalignmentTest = false; + // public static final double RadSpecs = 0.750; + + public static final double CIRCLEFIT_MAXCHI2 = 100; + + public static final int BSTTRKINGNUMBERITERATIONS = 3; + + public static final int MAXNUMCROSSES = 50; + + public static final int MAXNUMCROSSESINMODULE = 4; + + // these are the constants for ADC to energy conversion + public static final int NBITSADC = 3; // 3bit adc for BST + + public static int EMAXREADOUT = 1; + + // for cosmics + public static final double COSMICSMINRESIDUAL = 12; + public static final double COSMICSMINRESIDUALZ = 120; + + // track list cut-off + public static int maxNcands = 200; + public static boolean hasWidthResolution = false; + + public static boolean ignoreErr = false; + + public static boolean areConstantsLoaded = false; + + public static boolean removeClones = true; + +// public static final double MODULEPOSFAC = 0.5; // % wrt top of module + + public static final double PIDCUTOFF = 2.6; + + public static double MAXDISTTOTRAJXY = 5; //max xy dist to cross in cm + + public static int BSTEXCLUDEDFITREGION = 0; + + public static boolean LAYEREFFS = false; + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java index 0ec9f78f1..f197e22bf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java @@ -1,8 +1,7 @@ package org.jlab.rec.cvt.track; import org.jlab.clas.swimtools.Swim; -import org.jlab.rec.cvt.svt.Constants; -import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Helix; /** @@ -64,11 +63,11 @@ public void doCorrection(Track trkcand) { double pt0 = trkcand.get_Pt() + ELossMax * stepSize;// Assumes the max ELoss is 600 MeV double pt = pt0; - double curv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / pt; + double curv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / pt; for (int j = 0; j < nbins; j++) { if (Math.abs(this.OrigTrack.get_curvature()) < Math.abs(curv)) { - double correctedCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / (pt + stepSize); + double correctedCurv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / (pt + stepSize); trkcand.get_helix().set_curvature(correctedCurv); trkcand.set_HelicalTrack(trkcand.get_helix()); return; @@ -143,7 +142,7 @@ private double doEnergyLossCorrection(int m, double pt, double B) { double delta = 0.; //double dEdx = 0.0001535*(Constants.detMatZ/Constants.detMatA)*(Math.log(logterm)-2*beta*beta-delta)/(beta*beta); - double dEdx = 0.00001535 * Constants.detMatZ_ov_A_timesThickn * (Math.log(logterm) - 2 * beta * beta - delta) / (beta * beta); + double dEdx = 0.00001535 * SVTParameters.detMatZ_ov_A_timesThickn * (Math.log(logterm) - 2 * beta * beta - delta) / (beta * beta); double tmpPtot = p; @@ -155,7 +154,7 @@ private double doEnergyLossCorrection(int m, double pt, double B) { double newPt = Math.sqrt(tmpPtotCorrSq / (1 + tanL * tanL)); - double newCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / newPt; + double newCurv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / newPt; return newCurv; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 5c65368ee..d84864cbd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -15,8 +15,8 @@ import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.fit.CircleFitPars; import org.jlab.rec.cvt.fit.StraightTrackFitter; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; public class StraightTrackSeeder { int NBINS = 36; @@ -292,7 +292,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); - if(Math.abs(res)>Constants.RESIMAX) { + if(Math.abs(res)>SVTParameters.RESIMAX) { //System.out.println(" remove detector " + c .get_Detector() + " region " + c.get_Region() + " sector " + c.get_Sector() ); seedcrs.remove(c); break; @@ -498,13 +498,13 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) + if(chisqMax>SVTParameters.CIRCLEFIT_MAXCHI2) cand=null; return cand; } @@ -603,7 +603,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) return false; } double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= Constants.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= SVTParameters.dzdrcut) // add this to the track { pass = true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index d57f3ee05..829678a7c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.track; import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cross.Cross; @@ -151,8 +152,9 @@ public void update_Crosses(SVTGeometry geo) { double z = helix.getPointAtRadius(R).z(); double x = this.get(i).get_Point().x(); double y = this.get(i).get_Point().y(); - double z1 = geo.getPlaneModuleOrigin(this.get(i).get_Cluster2().get_Sector(), this.get(i).get_Cluster2().get_Layer()).z(); - double z2 = geo.getPlaneModuleEnd(this.get(i).get_Cluster2().get_Sector(), this.get(i).get_Cluster2().get_Layer()).z(); + Line3D module = this.get(i).get_Cluster2().get(0).get_Strip().get_Module(); + double z1 = module.origin().z(); + double z2 = module.end().z(); if (z - z1 < z2 - z1) { this.get(i).set_Point(new Point3D(x, y, z)); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 6e513fbad..820330e31 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -22,6 +22,7 @@ import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -157,12 +158,12 @@ public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) // shift =1; // interate the fit a number of times set in the constants file - int Max_Number_Of_Iterations = org.jlab.rec.cvt.svt.Constants.BSTTRKINGNUMBERITERATIONS; + int Max_Number_Of_Iterations = SVTParameters.BSTTRKINGNUMBERITERATIONS; // loop over the cross list and do the fits to the crosses if (list.size() >= 3) { // for debugging purposes only sets all errors to 1 - boolean ignoreErr = org.jlab.rec.cvt.svt.Constants.ignoreErr; + boolean ignoreErr = SVTParameters.ignoreErr; int Number_Of_Iterations = 0; // do till the number of iterations is reached @@ -246,12 +247,12 @@ public ArrayList getHelicalTracks(CrossList crossList, } // interate the fit a number of times set in the constants file - int Max_Number_Of_Iterations = org.jlab.rec.cvt.svt.Constants.BSTTRKINGNUMBERITERATIONS; + int Max_Number_Of_Iterations = SVTParameters.BSTTRKINGNUMBERITERATIONS; // loop over the cross list and do the fits to the crosses for (int i = 0; i < crossList.size(); i++) { // for debugging purposes only sets all errors to 1 - boolean ignoreErr = org.jlab.rec.cvt.svt.Constants.ignoreErr; + boolean ignoreErr = SVTParameters.ignoreErr; int Number_Of_Iterations = 0; // do till the number of iterations is reached @@ -309,7 +310,7 @@ public ArrayList getHelicalTracks(CrossList crossList, } } // remove clones - ArrayList passedcands = this.rmHelicalTrkClones(org.jlab.rec.cvt.svt.Constants.removeClones, cands); + ArrayList passedcands = this.rmHelicalTrkClones(SVTParameters.removeClones, cands); // loop over candidates and set the trajectories // for (int ic = 0; ic < passedcands.size(); ic++) { @@ -351,7 +352,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List crossesToFit = new ArrayList(); // remove SVT regions for (Cross crossInTrackToFit : SVTCrosses.get(i)) { - if (crossInTrackToFit.get_Region() != org.jlab.rec.cvt.svt.Constants.BSTEXCLUDEDFITREGION) {// remove the crosses from the exluded region to fit the track + if (crossInTrackToFit.get_Region() != SVTParameters.BSTEXCLUDEDFITREGION) {// remove the crosses from the exluded region to fit the track crossesToFit.add(crossInTrackToFit); } } @@ -438,7 +439,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List matchTrackToMM(List MMCrosses, StraightTrack thecand, BMTGeometry geo) { - double matchCutOff = org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUAL; // ? guess + double matchCutOff = SVTParameters.COSMICSMINRESIDUAL; // ? guess ArrayList BMTCrossList = new ArrayList(); StraightTrack thecand2 = thecand; @@ -1073,8 +1074,8 @@ private ArrayList rmStraightTrkClones(boolean removeClones, Array private void EliminateStraightTrackOutliers(ArrayList crossesToFit, CosmicFitter fitTrk, SVTGeometry svt_geo) { for (int j = 0; j < crossesToFit.size(); j++) { - if (Math.abs(fitTrk.get_ray().get_yxslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yxinterc() - crossesToFit.get(j).get_Point().x()) > org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUAL - || Math.abs(fitTrk.get_ray().get_yzslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yzinterc() - crossesToFit.get(j).get_Point().z()) > org.jlab.rec.cvt.svt.Constants.COSMICSMINRESIDUALZ) { + if (Math.abs(fitTrk.get_ray().get_yxslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yxinterc() - crossesToFit.get(j).get_Point().x()) > SVTParameters.COSMICSMINRESIDUAL + || Math.abs(fitTrk.get_ray().get_yzslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yzinterc() - crossesToFit.get(j).get_Point().z()) > SVTParameters.COSMICSMINRESIDUALZ) { resetUnusedCross(crossesToFit.get(j), svt_geo); crossesToFit.remove(j); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 3a3a4652d..dfee0f2a3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -14,6 +14,7 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -103,10 +104,10 @@ private void assignTrkPID(Track trk) { } TotE /= (double) NbHits; - if (TotE <= org.jlab.rec.cvt.svt.Constants.PIDCUTOFF) { + if (TotE <= SVTParameters.PIDCUTOFF) { trk.set_PID("pion"); } - if (TotE > org.jlab.rec.cvt.svt.Constants.PIDCUTOFF) { + if (TotE > SVTParameters.PIDCUTOFF) { trk.set_PID("proton"); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 8e47f048e..a4df3bf6a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -16,8 +16,8 @@ import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.fit.CircleFitPars; import org.jlab.rec.cvt.fit.HelicalTrackFitter; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; public class TrackSeeder { int NBINS = 36; @@ -67,7 +67,7 @@ private void MatchSeed(List othercrs) { double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); - if(Math.abs(res) seedcrs) { double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); - if(Math.abs(res)>Constants.RESIMAX) { + if(Math.abs(res)>SVTParameters.RESIMAX) { failed = true; return; } @@ -304,7 +304,7 @@ public List findSeed(List bst_crosses, List bmt_crosses, double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); - if(Math.abs(res)>Constants.RESIMAX) { + if(Math.abs(res)>SVTParameters.RESIMAX) { //System.out.println(" remove detector " + c .get_Detector() + " region " + c.get_Region() + " sector " + c.get_Sector() ); seedcrs.remove(c); break; @@ -530,13 +530,13 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) + if(chisqMax>SVTParameters.CIRCLEFIT_MAXCHI2) return null; if(X.size() > 3) cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params @@ -645,7 +645,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) return false; } double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= Constants.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= SVTParameters.dzdrcut) // add this to the track { pass = true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 25d19f3b6..d05f26748 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -13,8 +13,8 @@ import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; -import org.jlab.rec.cvt.svt.Constants; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.svt.SVTParameters; public class TrackSeederCA { @@ -429,13 +429,13 @@ public List> CAonRZ( int l1 = c.get_Cluster1().get_Layer(); int s1 = c.get_Cluster1().get_Sector(); double c1 = c.get_Cluster1().get_Centroid(); - double r1 = org.jlab.rec.cvt.svt.Constants.MODULERADIUS[l1-1][s1-1]; + double r1 = svt_geo.getLayerRadius(l1); double nstr1 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r1 - b)/m, l1, s1); int l2 = c.get_Cluster2().get_Layer(); int s2 = c.get_Cluster2().get_Sector(); double c2 = c.get_Cluster2().get_Centroid(); - double r2 = org.jlab.rec.cvt.svt.Constants.MODULERADIUS[l2-1][s2-1]; + double r2 = svt_geo.getLayerRadius(l2); double nstr2 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r2 - b)/m, l2, s2); if( Math.abs( c1 - nstr1 ) < 8 && Math.abs( c2 - nstr2 ) < 8 ) @@ -618,7 +618,7 @@ public Track fitSeed(List VTCrosses, //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMax candCrossList double[][][] SVTIntersections = calc_trackIntersSVT(ray, svt_geo); - for (int l = 0; l < Constants.NLAYR; l++) { - for (int s = 0; s < Constants.NSECT[l]; s++) { + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { if (SVTIntersections[l][s][0] != -999) { @@ -572,7 +570,7 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec return false; // same sector } double deltaXt = Math.sqrt((stVec.x() - c.get_Point().x()) * (stVec.x() - c.get_Point().x()) + (stVec.y() - c.get_Point().y()) * (stVec.y() - c.get_Point().y())); - if (deltaXt > org.jlab.rec.cvt.svt.Constants.ACTIVESENWIDTH / 2) { + if (deltaXt > SVTGeometry.getActiveSensorWidth() / 2) { return false; // within 1/2 module width } } @@ -605,8 +603,8 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl StateVec stVec, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal) { if (detector.equalsIgnoreCase("SVT") ) { - double doca2Cls = svt_geo.getDOCAToStrip(sector, layer, cluster.get_Centroid(), new Point3D(stVec.x(), stVec.y(), stVec.z())); - double doca2Seed = svt_geo.getDOCAToStrip(sector, layer, (double) cluster.get_SeedStrip().get_Strip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); + double doca2Cls = cluster.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); + double doca2Seed = cluster.get(0).residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); cluster.set_SeedResidual(doca2Seed); cluster.set_CentroidResidual(doca2Cls); cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); @@ -617,7 +615,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl // double d = new Vector3D(stVec.x(), stVec.y(), stVec.z()).dot(pl.normal())-pl.point().toVector3D().dot(pl.normal()); // System.out.println(d+" calc "+l.distance(new Point3D(stVec.x(), stVec.y(), stVec.z())).length()+" d "+doca2Cls); for (FittedHit hit : cluster) { - double doca1 = svt_geo.getDOCAToStrip(sector, layer, (double) hit.get_Strip().get_Strip(), new Point3D(stVec.x(), stVec.y(), stVec.z())); + double doca1 = hit.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); double sigma1 = svt_geo.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); hit.set_stripResolutionAtDoca(sigma1); hit.set_docaToTrk(doca1); @@ -743,9 +741,9 @@ private double[][][] calc_trackIntersBMT(Ray ray, BMTGeometry bmt_geo, int start private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { //[l][s], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip - double[][][] result = new double[org.jlab.rec.cvt.svt.Constants.NLAYR][org.jlab.rec.cvt.svt.Constants.NSECT[org.jlab.rec.cvt.svt.Constants.NLAYR - 1]][7]; - for (int l = 0; l < org.jlab.rec.cvt.svt.Constants.NLAYR; l++) { - for (int s = 0; s < org.jlab.rec.cvt.svt.Constants.NSECT[l]; s++) { + double[][][] result = new double[SVTGeometry.NLAYERS][SVTGeometry.NSECTORS[SVTGeometry.NLAYERS-1]][7]; + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { result[l][s][0] = -999; result[l][s][1] = -999; result[l][s][2] = -999; @@ -754,8 +752,8 @@ private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { } } //Layer 1-8: - for (int l = 0; l < org.jlab.rec.cvt.svt.Constants.NLAYR; l++) { - for (int s = 0; s < org.jlab.rec.cvt.svt.Constants.NSECT[l]; s++) { + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { double[] trkIntersInf = this.getIntersectionTrackWithSVTModule(s, l, ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), svt_geo); @@ -765,9 +763,9 @@ private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { continue; } - if ((Math.sqrt(p.x() * p.x() + p.y() * p.y()) <= Math.sqrt(0.25 * Constants.ACTIVESENLEN * Constants.ACTIVESENWIDTH + Constants.MODULERADIUS[l][0] * Constants.MODULERADIUS[l][0]))) { + if ((Math.sqrt(p.x() * p.x() + p.y() * p.y()) <= Math.sqrt(0.25 * SVTGeometry.getActiveSensorLength() * SVTGeometry.getActiveSensorWidth() + Math.pow(SVTGeometry.getLayerRadius(l+1),2.0)))) { - Vector3D n = svt_geo.findBSTPlaneNormal(s + 1, l + 1); + Vector3D n = svt_geo.getNormal(l+1, s+1); Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module @@ -821,9 +819,10 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, double z_plus = _yzslope2 * y_plus + _yzinterc2; double z_minus = _yzslope2 * y_minus + _yzinterc2; - Vector3D n = geo.findBSTPlaneNormal(s + 1, l + 1); - Point3D Or = geo.getPlaneModuleOrigin(s + 1, l + 1); - Point3D En = geo.getPlaneModuleEnd(s + 1, l + 1); + Vector3D n = geo.getNormal(l+1, s+1); + Line3D mod = geo.getModule(l+1, s+1); + Point3D Or = mod.origin(); + Point3D En = mod.end(); Vector3D u = new Vector3D(x_plus-x_minus,y_plus-y_minus,z_plus-z_minus).asUnit(); @@ -936,7 +935,7 @@ public void hitsToArray(List hits2) { if (hits2 == null) { return; } - HitArray = new Hit[Constants.NLAYR][Constants.NSECT[Constants.NLAYR - 1]][Constants.NSTRIP]; + HitArray = new Hit[SVTGeometry.NLAYERS][SVTGeometry.NSECTORS[SVTGeometry.NLAYERS - 1]][SVTGeometry.NSTRIPS]; // initializing non-zero Hit Array entries // with valid hits From e0a62770cd94ed0425e213f4e4fee102e0d31a85 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 4 Oct 2021 16:57:14 +0200 Subject: [PATCH 173/291] zeroing hardcoded SVT test shifts --- .../main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index 8eb964767..bb673fb3d 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -406,7 +406,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table System.out.println("Reading alignment shifts from database"); - double[] myShift = {2, 2,-2, 0, 0, 0, 0,}; + double[] myShift = {0, 0, 0, 0, 0, 0, 0,}; LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { From c5ea85d610a7905d2c7c227cf1ce11c43636d88a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 4 Oct 2021 22:47:30 +0200 Subject: [PATCH 174/291] CVT: fixing bug introduced in geometry cleanups --- .../java/org/jlab/rec/cvt/services/RecUtilities.java | 2 +- .../src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index e1821343f..2eaa467b0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -52,7 +52,7 @@ public void CleanupSpuriousCrosses(List> crosses, List t List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { - double z = SVTGeom.toLocal(c.get_Region()*2-1, + double z = SVTGeom.toLocal(c.get_Region()*2, c.get_Sector(), c.get_Point()).z(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 1881b9b87..8906a4c3b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -30,9 +30,6 @@ private void init() { } } -// public SVTStripFactory getStripFactory() { -// return _svtStripFactory; -// } public static double getLayerRadius(int layer) { int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); @@ -284,10 +281,10 @@ private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D public double calcNearestStrip(double X, double Y, double Z, int layer, int sect) { - Vector3d LocPoint = this._svtStripFactory.transformToLocal(layer-1, sect-1, X, Y, Z); + Point3D LocPoint = this.toLocal(layer, sect, new Point3D(X,Y,Z)); - double x = LocPoint.x; - double z = LocPoint.y; + double x = LocPoint.x(); + double z = LocPoint.z(); double alpha = SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); From 6069502138bb555a165c27c705e4b149d111ea83 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 6 Oct 2021 12:08:35 +0200 Subject: [PATCH 175/291] CVT: cleanup of constants and more geometry fixes --- .../org/jlab/rec/cvt/cross/CrossMaker.java | 6 +- .../rec/cvt/services/TracksFromTargetRec.java | 5 -- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 2 +- .../org/jlab/rec/cvt/svt/SVTParameters.java | 63 +------------------ .../jlab/rec/cvt/track/EnergyLossCorr.java | 7 ++- .../rec/cvt/trajectory/TrajectoryFinder.java | 4 +- 6 files changed, 12 insertions(+), 75 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 291a5c2f7..cff072091 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -124,10 +124,8 @@ private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { double Z = svt_geo.toLocal(Cluster1.get_Layer(), Cluster1.get_Sector(), c.get_Point()).z(); - if(Z<0) - Z=0; - if(Z>SVTGeometry.getActiveSensorLength()) - Z=SVTGeometry.getActiveSensorLength(); + if(Z>SVTGeometry.getModuleLength()) Z=SVTGeometry.getModuleLength(); + else if(Z<0) Z=0; Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z, svt_geo) /(SVTGeometry.getPitch() / Math.sqrt(12.))); Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z, svt_geo) ); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 2f55f6444..b916ac88b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.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.rec.cvt.services; import Jama.Matrix; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 8906a4c3b..1e606c082 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -243,7 +243,7 @@ public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, V // once there is a trk, the cross should be well calculated //if the local cross is not in the fiducial volume it is not physical else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConstants.ACTIVESENWID + SVTConstants.SIDETOL)) - || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN+ SVTConstants.LENGTHTOL))) { + || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL))) { return vals; } else { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java index 637dd9241..0c56efcbb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java @@ -11,7 +11,7 @@ public class SVTParameters { */ SVTParameters() { } - public static boolean geoDebug = false; + //CUTS public static int MAXSVTHITS = 700; public static int MAXSVTCROSSES = 1000; @@ -22,68 +22,13 @@ public class SVTParameters { public static int deltaThresholds = 15; // RECONSTRUCTION CONSTANTS -// public static final double RHOVTXCONSTRAINT = 1. / Math.sqrt(12.);//0.1; -// public static final double ZVTXCONSTRAINT = 50. / Math.sqrt(12);//5cm public static double ETOTCUT = 10.0; - // GEOMETRY PARAMETERS -// public static final int[] NSECT = new int[8]; -// public static final int NSLAYR = 2; -// public static final int NLAYR = 6; -// public static final int NREG = 3; - //public static final int NREG = 4; -// public static final int NSTRIP = 256; - -// public static final int MAXNUMSECT = 18; - -// public static Point3D[][][] LEP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //left strip end point -// public static Point3D[][][] REP = new Point3D[MAXNUMSECT][NLAYR][NSTRIP]; //right strip end point - -// public static double FIDCUX = 17.35; -// public static double FIDCUZ = 3.75; -// public static double FIDPKX = 3.5; -// public static double FIDPKZ0 = 402.624; -// public static double FIDPKZ1 = 2.50; -// public static double OriginZ = 62.13; - -// d public static double[] Z0 = new double[NLAYR]; // the z-position of a BST module in the lab-frame -// d public static double[] PHI0 = new double[NLAYR]; // the angle of the mid plane of the hybrid sensor for the first sector - -// public static double PITCH = 0.156; -// public static double STEREOANGLE = Math.toRadians(3.); // value of stereo angle - - //---------------- - // the unit is mm - //---------------- -// public static final double SILICONTHICK = 0.320; // Silicon sensor width - - //public static final double ACTIVESENWIDTH = 40.052; -// public static final double ACTIVESENWIDTH = 40.032; -// public static final double STRIPTSTART = 0.048; - - //public static double LAYRGAP = 3.262; //<-- GEMC value--> should be 3.236 -// public static double ACTIVESENLEN = 109.955; -// static double TOTSENLEN = 111.625; -// static double MICROGAP = 0.112; - //public static double DEADZNLEN = TOTSENLEN-ACTIVESENLEN; -// public static final double DEADZNLEN = 0.835; - //MODULELEN = NSENSORS*(ACTIVESENLEN + 2*DEADZNLEN) + (NSENSORS - 1)*MICROGAPLEN; - //STRIPLENMAX = MODULELEN - 2*DEADZNLEN; - - - // RDV CHECK CHECK - //public static final double MODULELENGTH = 3*ACTIVESENLEN+2*DEADZNLEN+2*MICROGAP; // active area for 3 sensors including inbetween dead zones -// public static final double MODULELENGTH = 3 * ACTIVESENLEN + 4 * DEADZNLEN + 2 * MICROGAP; // active area for 3 sensors including inbetween dead zones -// public static final double LOCZAXISROTATION = -Math.toRadians(90.); - - // CONSTANTS USED IN RECONSTRUCTION - //--------------------------------- - public static double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c + // cut on Edep min; + public static double EDEPMIN = 0.020; //20keV=0.020 // selection cuts for helical tracks public static final double MINRADCURV = 200.00; //in cm - // cut on Edep min; - public static double edep_min = 0.020; //20keV=0.020 // sum of strip numbers for valid intersection: //public static int sumStpNumMin = 174; //public static int sumStpNumMax = 259; @@ -137,8 +82,6 @@ public class SVTParameters { public static boolean ignoreErr = false; - public static boolean areConstantsLoaded = false; - public static boolean removeClones = true; // public static final double MODULEPOSFAC = 0.5; // % wrt top of module diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java index f197e22bf..db0247c13 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.track; import org.jlab.clas.swimtools.Swim; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Helix; @@ -63,11 +64,11 @@ public void doCorrection(Track trkcand) { double pt0 = trkcand.get_Pt() + ELossMax * stepSize;// Assumes the max ELoss is 600 MeV double pt = pt0; - double curv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / pt; + double curv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / pt; for (int j = 0; j < nbins; j++) { if (Math.abs(this.OrigTrack.get_curvature()) < Math.abs(curv)) { - double correctedCurv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / (pt + stepSize); + double correctedCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / (pt + stepSize); trkcand.get_helix().set_curvature(correctedCurv); trkcand.set_HelicalTrack(trkcand.get_helix()); return; @@ -154,7 +155,7 @@ private double doEnergyLossCorrection(int m, double pt, double B) { double newPt = Math.sqrt(tmpPtotCorrSq / (1 + tanL * tanL)); - double newCurv = (SVTParameters.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / newPt; + double newCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / newPt; return newCurv; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 47c2cdc9e..cc59a6eb5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -762,8 +762,8 @@ private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { if (p.toVector3D().mag() == 0) { continue; } - - if ((Math.sqrt(p.x() * p.x() + p.y() * p.y()) <= Math.sqrt(0.25 * SVTGeometry.getActiveSensorLength() * SVTGeometry.getActiveSensorWidth() + Math.pow(SVTGeometry.getLayerRadius(l+1),2.0)))) { + // RDV check me + if ((Math.sqrt(p.x() * p.x() + p.y() * p.y()) <= Math.sqrt(0.25 * SVTGeometry.getModuleLength()* SVTGeometry.getActiveSensorWidth() + Math.pow(SVTGeometry.getLayerRadius(l+1),2.0)))) { Vector3D n = svt_geo.getNormal(l+1, s+1); Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module From cf0dab515b2d6462b70d94f46e0ef1d6e3a0d7bb Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 5 Oct 2021 17:57:21 -0400 Subject: [PATCH 176/291] Fix Helix for 90 deg tracks. --- .../jlab/clas/tracking/trackrep/Helix.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 7d8eddd9e..8f0580aa1 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -385,18 +385,27 @@ public double getLAtR(double r) { double x; double y; - + double xp = 0; + double xm = 0; + double yp = 0; + double ym = 0; + if( getYc() >1.e-09) { double a = 0.5 * (r * r - getR() * getR() + getXc() * getXc() + getYc() * getYc()) / getYc(); - double b = -getXc() / getYc(); + double b = -getXc() / getYc(); - double delta = a * a * b * b - (1 + b * b) * (a * a - r * r); + double delta = a * a * b * b - (1 + b * b) * (a * a - r * r); - double xp = (-a * b + Math.sqrt(delta)) / (1 + b * b); - double xm = (-a * b - Math.sqrt(delta)) / (1 + b * b); + xp = (-a * b + Math.sqrt(delta)) / (1 + b * b); + xm = (-a * b - Math.sqrt(delta)) / (1 + b * b); - double yp = a + b * xp; - double ym = a + b * xm; - + yp = a + b * xp; + ym = a + b * xm; + } else { + xm = (getXc()*getXc()-getR()*getR()+r*r)/(2*getXc()); + xp = xm; + ym = Math.sqrt(r*r-xm*xm); + yp = Math.sqrt(r*r-xp*xp); + } //double Cp = new Vector3D(xp,yp,0).asUnit().dot(new Vector3D(Math.cos(getPhi0()), Math.sin(getPhi0()),0)); //double Cm = new Vector3D(xm,ym,0).asUnit().dot(new Vector3D(Math.cos(getPhi0()), Math.sin(getPhi0()),0)); double Np = Math.sqrt(xp*xp+yp*yp); From 8cb68629bbffca28a0f5415509fc70d0e3d55e8d Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 6 Oct 2021 17:59:01 +0200 Subject: [PATCH 177/291] Partial merge of TrakTools-Test2Dev and updates to findClustersOnTrack method --- .../jlab/clas/tracking/trackrep/Helix.java | 2 +- .../jlab/rec/cvt/services/RecUtilities.java | 130 +++++++++++------- .../rec/cvt/services/TracksFromTargetRec.java | 2 +- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 20 ++- 4 files changed, 103 insertions(+), 51 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 8f0580aa1..929543643 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -389,7 +389,7 @@ public double getLAtR(double r) { double xm = 0; double yp = 0; double ym = 0; - if( getYc() >1.e-09) { + if( Math.abs(getYc()) >1.e-09) { double a = 0.5 * (r * r - getR() * getR() + getXc() * getXc() + getYc() * getYc()) / getYc(); double b = -getXc() / getYc(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 2eaa467b0..ba400fbb6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Comparator; +import java.util.Map.Entry; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Arc3D; @@ -174,11 +175,11 @@ public List setMeasVecs(StraightTrack trkcand, Point3D endPt2 = cls.get(j).getLine().end(); Strip strp = new Strip(id, ce, endPt1.x(), endPt1.y(), endPt1.z(), endPt2.x(), endPt2.y(), endPt2.z()); -// Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cls.get(j).get_Sector(), -// cls.get(j).get_Layer())); +// Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cluster.get(j).get_Sector(), +// cluster.get(j).get_Layer())); Plane3D pln = new Plane3D(endPt1,cls.get(j).getN()); -// Point3D Or = sgeo.getPlaneModuleOrigin(cls.get(j).get_Sector(), cls.get(j).get_Layer()); -// Point3D En = sgeo.getPlaneModuleEnd(cls.get(j).get_Sector(), cls.get(j).get_Layer()); +// Point3D Or = sgeo.getPlaneModuleOrigin(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); +// Point3D En = sgeo.getPlaneModuleEnd(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); Surface meas = new Surface(pln, strp, cls.get(j).origin(), cls.get(j).end()); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setSector(cls.get(j).get_Sector()); @@ -227,7 +228,7 @@ public List setMeasVecs(StraightTrack trkcand, clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); } else if (trkcand.get(i).get_Type()==BMTType.C) { - double z = trkcand.get(i).get_Point().z(); + double z = trkcand.get(i).get_Cluster1().get_Z(); double err = trkcand.get(i).get_Cluster1().get_ZErr(); Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); Strip strp = new Strip(id, ce, arc); @@ -252,26 +253,26 @@ else if (trkcand.get(i).get_Type()==BMTType.C) { return KFSites; } - public List FindClustersOnTrkNew (List allClusters, Helix helix, double P, int Q, + public List FindClustersOnTrkNew (List allClusters, List seedCluster, Helix helix, double P, int Q, SVTGeometry sgeo, Swim swimmer) { - int[] Sectors = new int[SVTGeometry.NLAYERS]; - // RDV it is not correct for tiltes/shifted geometry - for (int ilayer = 0; ilayer < SVTGeometry.NLAYERS; ilayer++) { - Point3D traj = helix.getPointAtRadius(sgeo.getLayerRadius(ilayer+1)); - int sec = sgeo.getSector(ilayer+1, traj); - Sectors[ilayer] = sec; - } // initialize swimmer starting from the track vertex double maxPathLength = 1; swimmer.SetSwimParameters((helix.xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (helix.ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, helix.get_Z0() / 10, Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), P, Q, maxPathLength) ; double[] inters = null; - double path = 0; - // SVT - List clustersOnTrack = new ArrayList(); - for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + + // load SVT clusters that are in the seed + Map clusterMap = new HashMap<>(); + for(Cluster cluster : seedCluster) { + if(cluster.get_Detector() == DetectorType.BMT) + continue; + clusterMap.put(sgeo.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); + } + + // for each layer + for (int ilayer = 0; ilayer < SVTGeometry.NLAYERS; ilayer++) { // reinitilize swimmer from last surface if(inters!=null) { double intersPhi = Math.atan2(inters[4], inters[3]); @@ -279,40 +280,52 @@ public List FindClustersOnTrkNew (List allClusters, Helix heli swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), P, Q, maxPathLength) ; } - int layer = l + 1; - int sector = Sectors[l]; - if(sector == -1) - continue; + int layer = ilayer + 1; - double doca = Double.MAX_VALUE; - Point3D traj = null; - Cluster cluster = null; - for(Cluster cls : allClusters) { - if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { - // for first relevant cluster, swim to the plane to get the trajectory - if(traj==null) { - Vector3D n = cls.get(0).get_Strip().get_Normal(); - Point3D p = cls.get(0).get_Strip().get_Module().origin(); - double d = n.dot(p.toVector3D()); - inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); - if(inters!=null) - traj = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); + for(int isector=0; isector clustersOnTrack = new ArrayList<>(); + for(Entry entry : clusterMap.entrySet()) { + if(entry.getValue().get_AssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); + } + return clustersOnTrack; } - public List FindClustersOnTrk (List allClusters, Helix helix, double P, int Q, + public List FindClustersOnTrk (List allClusters, List seedCluster, Helix helix, double P, int Q, SVTGeometry sgeo, Swim swimmer) { Map clusMap = new HashMap(); //Map stripMap = new HashMap(); @@ -352,13 +365,21 @@ public List FindClustersOnTrk (List allClusters, Helix helix, inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); if(inters!=null) { Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); - double nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); + int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); //stripMap.put((sector*1000+layer), nearstp); - docaMap.put((sector*1000+layer), 10.0);//sgeo.getDOCAToStrip(sector, layer, nearstp, trp)); + docaMap.put((sector*1000+layer), sgeo.getDoca(layer, sector, nearstp, trp)); trajMap.put((sector*1000+layer), trp); } } + for(Cluster cls : seedCluster) { + if(cls.get_Detector() == DetectorType.BMT) + continue; + int clsKey = cls.get_Sector()*1000+cls.get_Layer(); + clusMap.put(clsKey, cls); + } for(Cluster cls : allClusters) { + if(cls.get_Detector() == DetectorType.BMT) + continue; int clsKey = cls.get_Sector()*1000+cls.get_Layer(); if(cls.get_AssociatedTrackID()==-1 && trajMap!=null && trajMap.get(clsKey)!=null) { //double trjCent = stripMap.get(clsKey); @@ -379,6 +400,11 @@ public List FindClustersOnTrk (List allClusters, Helix helix, for(Cluster cl : clusMap.values()) { clustersOnTrack.add(cl); } + // RDV can lead to duplicates + for(Cluster cls : seedCluster) { + if(cls.get_Detector() == DetectorType.BMT) + clustersOnTrack.add(cls); + } return clustersOnTrack; } @@ -459,8 +485,18 @@ public void MatchTrack2Traj(Seed trkcand, Map clsOnTrack = recUtil.FindClustersOnTrkNew(SVTclusters, fittedTrack.get_helix(), + List clsOnTrack = recUtil.FindClustersOnTrkNew(SVTclusters, seed.get_Clusters(), fittedTrack.get_helix(), fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); if(clsOnTrack.size()>0) { seed.get_Clusters().addAll(clsOnTrack); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 1e606c082..a992ed27c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -86,6 +86,10 @@ public Line3D getModule(int layer, int sector) { line.end().x, line.end().y, line.end().z); } + public int getModuleId(int layer, int sector) { + return layer*100+sector; + } + public Vector3D getNormal(int layer, int sector) { Vector3d normal = this._svtStripFactory.getModuleNormal(layer-1, sector-1); return new Vector3D(normal.x, normal.y, normal.z); @@ -113,6 +117,8 @@ public Vector3D toGlobal(int layer, int sector, Vector3D dir) { return new Vector3D(lab.x-zero.x, lab.y-zero.y, lab.z-zero.z); } + + @Deprecated public int getSector(int layer, Point3D traj) { int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); @@ -259,6 +265,16 @@ else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConst } + public double getDoca(int layer, int sector, int strip, Point3D traj) { + return this.getStrip(layer, sector, strip).distance(traj).length(); + } + + public double getResidual(int layer, int sector, int strip, Point3D traj) { + Line3D dist = this.getStrip(layer, sector, strip).distance(traj); + double side = -Math.signum(this.getStrip(layer, sector, strip).direction().cross(dist.direction()).dot(this.getNormal(layer, sector))); + return dist.length()*side; + } + private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D trkDir, double ZalongModule) { double s2corr = s2; // second iteration: there is a track direction @@ -279,7 +295,7 @@ private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D return s2corr; } - public double calcNearestStrip(double X, double Y, double Z, int layer, int sect) { + public int calcNearestStrip(double X, double Y, double Z, int layer, int sect) { Point3D LocPoint = this.toLocal(layer, sect, new Point3D(X,Y,Z)); @@ -366,7 +382,7 @@ public double calcNearestStrip(double X, double Y, double Z, int layer, int sect } //System.out.println(" layer "+layer+" sector "+sect+" strip "+s); - return s; + return (int) s; } //**** From 5a6a6d3ef7ca13b1c85cbe85f65a62383bd52af8 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 6 Oct 2021 20:00:25 +0200 Subject: [PATCH 178/291] BMT geometry: shifted strips to be at the center of the drift, to facilitate cross positions calculations --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 105 ++++++------------ 1 file changed, 32 insertions(+), 73 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 8dc73da00..76249b6b9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -328,36 +328,6 @@ public Transformation3D toLocal(int layer, int sector) { return Constants.toLocal[layer-1][sector-1]; } -// public Point3D getInverseOffset(int layer, int sector) { -// -// Point3D offset = new Point3D(); -// if(layer>0 && layer 0 && sector0 && layer Constants.getCRZNSTRIPS()[region-1]) { + if (strip < 1 || strip > this.getNStrips(layer)) { strip = -1; } } From 41969b706e6d0c3d576091b9156f3a7c919273e7 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Sat, 9 Oct 2021 23:48:58 -0400 Subject: [PATCH 179/291] merged with TracTools-Test3. Wowzers, this fixes the weirdly large residuals in the BMTC --- .../jlab/rec/cvt/banks/RecoBankReader.java | 45 ++-- .../jlab/rec/cvt/services/CVTAlignment.java | 201 ++++++++---------- 2 files changed, 117 insertions(+), 129 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 11ef50a39..2acc89d43 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -134,6 +134,7 @@ public void fetch_BMTClusters(DataEvent event) { int size = bank.getInt("size", i); cluster.set_TotalEnergy(bank.getFloat("ETot", i)); + //cluster.set_Seed(bank.getInt("seedStrip", i)); cluster.set_Centroid(bank.getFloat("centroid",i)); //cluster.set_SeedEnergy(bank.getFloat("seedE",i)); @@ -164,26 +165,36 @@ public void fetch_BMTClusters(DataEvent event) { cluster.set_Resolution(bank.getFloat("e", i)); + Point3D x1 = new Point3D( + bank.getFloat("x1", i), + bank.getFloat("y1", i), + bank.getFloat("z1", i)); + /*Point3D x2 = new Point3D( + bank.getFloat("x2", i), + bank.getFloat("y2", i), + bank.getFloat("z2", i)); + Point3D c = new Point3D( + bank.getFloat("cx", i), + bank.getFloat("cy", i), + bank.getFloat("cz", i));*/ + Point3D a1 = new Point3D( + bank.getFloat("ax1", i), + bank.getFloat("ay1", i), + bank.getFloat("az1", i)); + Point3D a2 = new Point3D( + bank.getFloat("ax2", i), + bank.getFloat("ay2", i), + bank.getFloat("az2", i)); + + Vector3D a = a1.vectorTo(a2).asUnit(); + Point3D arccenter = a1.toVector3D().add(a.multiply(a.dot(a1.vectorTo(x1)))).toPoint3D(); + cluster.set_Arc(new Arc3D( - new Point3D( - bank.getFloat("x1", i), - bank.getFloat("y1", i), - bank.getFloat("z1", i)), - new Point3D( - bank.getFloat("cx", i), - bank.getFloat("cy", i), - bank.getFloat("cz", i)), - new Point3D( - bank.getFloat("ax1", i), - bank.getFloat("ay1", i), - bank.getFloat("az1", i)) - .vectorTo(new Point3D( - bank.getFloat("ax2", i), - bank.getFloat("ay2", i), - bank.getFloat("az2", i))).asUnit(), + x1, + arccenter, a, bank.getFloat("theta", i) )); - + cluster.set_Type(BMTGeometry.getDetectorType(layer)); //Since only up to 5 hits per track are written... for (int j = 0; j < 5; j++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index f0ce4ed70..006852f0b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -8,15 +8,12 @@ //import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.detector.geant4.v2.SVT.SVTConstants; -import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; -import org.jlab.geom.base.Detector; +//import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.geometry.prim.Line3d; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; @@ -34,7 +31,7 @@ import org.jlab.rec.cvt.trajectory.Trajectory; import Jama.Matrix; -import eu.mihosoft.vrl.v3d.Vector3d; +//import eu.mihosoft.vrl.v3d.Vector3d; /** * Service to return reconstructed TRACKS @@ -46,9 +43,8 @@ public class CVTAlignment extends ReconstructionEngine { //org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom; - CTOFGeant4Factory CTOFGeom; - Detector CNDGeom ; - SVTStripFactory svtIdealStripFactory; + //CTOFGeant4Factory CTOFGeom; + //SVTStripFactory svtIdealStripFactory; public CVTAlignment() { super("CVTAlignment", "spaul", "4.0"); @@ -146,12 +142,16 @@ public void setFieldsConfig(String fieldsConfig) { int gCountBMTC = 0; int gCountSVT = 0; int gCountBMTZ =0; - + int debugPrintEventCount = 0; + @Override public boolean processDataEvent(DataEvent event) { int runNum = event.getBank("RUN::config").getInt("run", 0); int eventNum = event.getBank("RUN::config").getInt("event", 0); + if((debugPrintEventCount++) %1000==0) + System.out.println("BMTC total clusters: " + gCountBMTC+"; BMTZ total clusters: " + gCountBMTZ+"; SVT total crosses: "+ gCountSVT); + //this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); @@ -212,13 +212,13 @@ public boolean processDataEvent(DataEvent event) { gCountSVT++; } if(c.get_Detector() == DetectorType.BMT && !isSVTonly) { - if (c.get_Type() != BMTType.C || ! skipBMTC) + if (c.get_Cluster1().get_Type() != BMTType.C || ! skipBMTC) nCrossBMT++; - if (c.get_Type() == BMTType.C) { + if (c.get_Cluster1().get_Type() == BMTType.C) { countBMTC++; gCountBMTC++; } - if(c.get_Type() == BMTType.Z) { + if(c.get_Cluster1().get_Type() == BMTType.Z) { gCountBMTZ++; countBMTZ++; } @@ -238,9 +238,9 @@ public boolean processDataEvent(DataEvent event) { if(countBMTCmaxResidualCut) { - // System.out.println("rejecting track due to large residual"); - // continue tracksLoop; - //} - } + As.add(A); Bs.add(B); Vs.add(V); @@ -413,7 +381,6 @@ else if(cross.get_DetectorType() == BMTType.C) { writer.write_Matrix(event, "c", cs); writer.write_Matrix(event, "q", qs); fillMisc(event,runNum,eventNum,trackIDs,As,Bs,Vs,ms,cs,Is); - System.out.println("BMTC total clusters: " + gCountBMTC+"; BMTZ total clusters: " + gCountBMTZ+"; SVT total crosses: "+ gCountSVT); //event.show(); //only include events that have tracks that will be used in alignment @@ -487,40 +454,40 @@ private void fillMisc(DataEvent event, int runNum, int eventNum, List t * converts a Vector3D to a Vector3d. * These objects are from two different packages. */ - private Vector3d convertVector(Vector3D v) { + /*private Vector3d convertVector(Vector3D v) { return new Vector3d(v.x(),v.y(),v.z()); - } + }*/ /* * converts a Vector3D to a Vector3d. * These objects are from two different packages. */ - private Line3d convertLine(Line3D line) { + /*private Line3d convertLine(Line3D line) { return new Line3d(convertVector(line.origin().toVector3D()), convertVector(line.end().toVector3D())); - } + }*/ boolean useDocaPhiZTandip=true; private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I){ // a point along the beam - Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); + Vector3D xref = ray.get_refPoint().toVector3D(); //System.out.println("xref: " + xref.toStlString()); - Vector3d u = convertVector(ray.get_dirVec()); + Vector3D u = ray.get_dirVec(); - Vector3d e = new Vector3d(xb,yb,0); - Vector3d l = new Vector3d(0,0,1); + Vector3D e = new Vector3D(xb,yb,0); + Vector3D l = new Vector3D(0,0,1); //in this case - Vector3d n = new Vector3d(u.x, u.y, 0); - n = n.normalized(); - Vector3d s = l.cross(n); + Vector3D n = new Vector3D(u.x(), u.y(), 0); + n = n.asUnit(); + Vector3D s = l.cross(n); double udotn = u.dot(n); if(Math.abs(udotn)<0.01) return false; double sdotu = s.dot(u); - Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); + Vector3D extrap = xref.clone().add(u.multiply(n.dot(e.clone().sub(xref))/udotn)); //this should be about equal to the beam width @@ -530,8 +497,8 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix V.set(i, i, Math.pow(resolution,2)); - Vector3d sp = s.minus(n.times(sdotu/udotn)); - if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small + Vector3D sp = s.clone().sub(n.multiply(sdotu/udotn)); + if(sp.mag() > 10) { //this can only happen if the angle between the track and the normal is small //System.out.println("rejecting track"); return false; } @@ -539,7 +506,7 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix //Use the same reference point for both inner and outer layer of region - Vector3d cref = new Vector3d(0,0,0); + //Vector3d cref = new Vector3d(0,0,0); @@ -554,8 +521,8 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); */ - Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); - dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); + Vector3D dmdr =sp.cross(extrap); + dmdr = dmdr.clone().sub(n.cross(u).multiply(n.dot(e.clone().sub(extrap))*sdotu/(udotn*udotn))); /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); @@ -565,46 +532,46 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix //System.out.println("i = " + i + "; rows = " + A.getRowDimension() + "; cols = " + + A.getColumnDimension()); if(orderTx >= 0) - A.set(i, i*nAlignVars + orderTx, -sp.x); + A.set(i, i*nAlignVars + orderTx, -sp.x()); if(orderTy >= 0) - A.set(i, i*nAlignVars + orderTy, -sp.y); + A.set(i, i*nAlignVars + orderTy, -sp.y()); if(orderTz >= 0) - A.set(i, i*nAlignVars + orderTz, -sp.z); + A.set(i, i*nAlignVars + orderTz, -sp.z()); if(orderRx >= 0) - A.set(i, i*nAlignVars + orderRx, dmdr.x); + A.set(i, i*nAlignVars + orderRx, dmdr.x()); if(orderRy >= 0) - A.set(i, i*nAlignVars + orderRy, dmdr.y); + A.set(i, i*nAlignVars + orderRy, dmdr.y()); if(orderRz >= 0) - A.set(i, i*nAlignVars + orderRz, dmdr.z); + A.set(i, i*nAlignVars + orderRz, dmdr.z()); I.set(i, 0, index); - Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); + Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x); - B.set(i,1, sp.z); - B.set(i,2, dmdu.x); - B.set(i,3, dmdu.z); + B.set(i,0, sp.x()); + B.set(i,1, sp.z()); + B.set(i,2, dmdu.x()); + B.set(i,3, dmdu.z()); } else { - double phi = Math.atan2(u.y,u.x); - Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); - Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x, u.y); + double phi = Math.atan2(u.y(),u.x()); + Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi),0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x(), u.y()); double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); + B.set(i, 0, s.dot(mscphi.clone().sub(u.multiply(n.dot(mscphi)/udotn)))); //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) - // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) + // .plus(mscphi.times(n.dot(e.clone().subtract(xref))/udotn)) + // .clone().subtract(u.times(mscphi.dot(n)*n.dot(e.clone().subtract(xref))/(udotn*udotn))) // .plus(u.times(d*n.dot(csphi)/udotn))) // ); B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) + + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.clone().clone().sub(xref)) + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z-sdotu*n.z/udotn); - B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); + B.set(i, 2, s.z()-sdotu*n.z()/udotn); + B.set(i, 3, (s.z()/udotn-n.z()*sdotu/(udotn*udotn))*n.dot(e.clone().sub(xref))); } @@ -642,7 +609,7 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix * @return */ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, - Matrix c, Matrix I, String detector, boolean debug) { + Matrix c, Matrix I, DetectorType detector, BMTType bmtType, boolean debug) { int layer = cl.get_Layer(); int sector = cl.get_Sector(); //System.out.println("RLS " + region + " " + layer + " " + sector); @@ -674,7 +641,7 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, //Vector3d e1 = cl.getX Vector3D e = null; Vector3D extrap = null; - if(detector.equals("SVT") || detector.equals("BMTZ")) { + if(detector == DetectorType.BST || detector == DetectorType.BMT && bmtType==BMTType.Z) { l = cl.getL(); s = cl.getS(); n = cl.getN(); @@ -699,11 +666,13 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Vector3D tmp1 = perp(xref.clone().sub(cc),a); - Vector3D endpoint = cl.get_Arc().originVector(); + Vector3D endpoint = cl.get_Arc().origin().toVector3D(); double R = perp(endpoint.clone().sub(cc),a).mag(); - if(debug) + if(debug) { + System.out.println("center: " + cc.toStringBrief()); System.out.println("R: " + R); + } double AA = uT.mag2(); @@ -785,7 +754,7 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, } //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - if(detector.equals("BMTZ") && debug) { + if(detector == DetectorType.BMT && bmtType==BMTType.Z && debug) { Vector3D diff = xref.clone(); double check = l.cross(u).dot(diff); System.out.println("distance between track and strip, phi,r: " + check + " " + u.phi() + " "+ e.mag()); @@ -813,7 +782,7 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, - Vector3D cref = new Vector3D(0,0,0); + //Vector3D cref = new Vector3D(0,0,0); @@ -837,9 +806,9 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, dmdr.z()); - if(detector.equals("SVT")) + if(detector == DetectorType.BST) I.set(i, 0, getIndexSVT(layer-1,sector-1)); - if(detector.equals("BMTZ") || detector.equals("BMTC")) + if(detector == DetectorType.BMT) I.set(i, 0, getIndexBMT(layer-1,sector-1)); Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); @@ -889,9 +858,9 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, System.out.println("m: " + mi); System.out.println("c: " + ci); } - if(Math.abs(ci-mi)>maxResidualCutSVT && detector.equals("SVT") || - Math.abs(ci-mi)>maxResidualCutBMTZ && detector.equals("BMTZ") || - Math.abs(ci-mi)>maxResidualCutBMTC && detector.equals("BMTC")) { + if(Math.abs(ci-mi)>maxResidualCutSVT && detector == DetectorType.BST || + Math.abs(ci-mi)>maxResidualCutBMTZ && detector == DetectorType.BMT && bmtType==BMTType.Z || + Math.abs(ci-mi)>maxResidualCutBMTC && detector == DetectorType.BMT && bmtType==BMTType.C) { if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); return false; } @@ -1046,7 +1015,7 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, private int minClustersSVT = 0; private int minClustersBMTC = 0; private int minClustersBMTZ = 0; - private SVTGeometry SVTGeom; + //private SVTGeometry SVTGeom; /* private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, @@ -1332,12 +1301,12 @@ private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, return true; }*/ - private Vector3d midpoint(Arc3D arc1) { + /*private Vector3d midpoint(Arc3D arc1) { return convertVector(arc1.point(arc1.theta()/2).toVector3D()); - } + }*/ - private int getIndex(Cluster c) { + /*private int getIndex(Cluster c) { int layer = c.get_Layer()-1; int sector = c.get_Sector()-1; int index = -1; @@ -1358,7 +1327,7 @@ else if (region == 2) } return index; - } + }*/ private int getIndexBMT(int layer, int sector) { if (layer < 0 || sector < 0) @@ -1383,10 +1352,10 @@ else if (region == 2) } - private Vector3d getModuleReferencePoint(int sector, int layer) { + /*private Vector3d getModuleReferencePoint(int sector, int layer) { //return SVTAlignmentFactory.getIdealFiducialCenter((layer-1)/2, sector-1); return new Vector3d(0,0,0); - } + }*/ @Override public boolean init() { @@ -1430,8 +1399,16 @@ public boolean init() { System.out.println("["+this.getName()+"] not BMT only (default) "); this.isBMTonly = false; } - // Load other geometries + + String skipBMTC = this.getEngineConfigString("skipBMTC"); + + if (skipBMTC!=null) { + System.out.println("["+this.getName()+"] skip BMTC? "+skipBMTC+" config chosen based on yaml"); + this.isBMTonly= Boolean.valueOf(skipBMTC); + } + + variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); System.out.println(" CVT YAML VARIATION NAME + "+variationName); @@ -1445,8 +1422,8 @@ public boolean init() { yb = org.jlab.rec.cvt.Constants.getYb(); //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][0])); //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][1])); - SVTStripFactory svtFac = new SVTStripFactory(cp, true); - SVTGeom = new SVTGeometry(svtFac); + //SVTStripFactory svtFac = new SVTStripFactory(cp, true); + //SVTGeom = new SVTGeometry(svtFac); String svtTopBottomSep = this.getEngineConfigString("svtAlignTopBottomSeparately"); if (svtTopBottomSep!=null) { From 34dc48fbb13268b0bc4e77b9c78ca4098be6031e Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 10 Oct 2021 14:53:32 +0200 Subject: [PATCH 180/291] CVT: SVT crosses now accounts for rotations, both SVT and BMT crosses updates during helical fit iterations --- .../main/java/org/jlab/rec/cvt/Constants.java | 2 + .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 2 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 166 ++++++-- .../org/jlab/rec/cvt/cross/CrossMaker.java | 68 +-- .../jlab/rec/cvt/services/RecUtilities.java | 27 +- .../rec/cvt/services/TracksFromTargetRec.java | 4 +- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 399 ++++++++++-------- .../org/jlab/rec/cvt/svt/SVTParameters.java | 2 - .../org/jlab/rec/cvt/track/StraightTrack.java | 2 +- .../rec/cvt/track/StraightTrackSeeder.java | 21 +- .../java/org/jlab/rec/cvt/track/Track.java | 26 +- .../rec/cvt/track/TrackCandListFinder.java | 4 +- .../jlab/rec/cvt/track/TrackListFinder.java | 2 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 16 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 17 +- 15 files changed, 475 insertions(+), 283 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 17d04487f..72c0f0611 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -21,6 +21,8 @@ public class Constants { // selection cuts for helical tracks public static final double MINRADCURV = 200.00; //in cm + public static final double CIRCLEFIT_MAXCHI2 = 100; + private static boolean isCosmicsData = false; private static boolean SVTOnly = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 612de09c9..f77a9040a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -297,7 +297,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); // hardcode gemc rotation: set angles to 0 to null it - Vector3D gemcRot = new Vector3D(0,0,0); + Vector3D gemcRot = new Vector3D(-2,0,0); Point3D bmtCenter = new Point3D(0,0,-94.7); // the original BMT Center Point3D bmtShift = new Point3D(bmtCenter); bmtCenter.rotateZ(Math.toRadians(gemcRot.z())); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 9eec21e81..df614b814 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -1,9 +1,9 @@ package org.jlab.rec.cvt.cross; -import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.Collections; import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -32,8 +32,7 @@ public class Cross extends ArrayList implements Comparable { * @param detectortype detector type for BMT, C or Z detector * @param sector the sector (1...) * @param region the region (1...) - * @param rid the cross ID (if there are only 3 crosses in the event, the ID - * corresponds to the region index + * @param crid */ public Cross(DetectorType detector, BMTType detectortype, int sector, int region, int crid) { this._Detector = detector; @@ -359,37 +358,156 @@ public void set_MatchedCCross(Cross _MatchedCCross) { /** * Sets the cross parameters: the position and direction unit vector */ - public void set_CrossParamsSVT(Vector3D dirAtBstPlane, SVTGeometry geo) { + public void setBMTCrossPosition(Point3D trackPos) { - Cluster inlayerclus = this.get_Cluster1(); + Cluster cluster = this.get_Cluster1(); + + if(this.get_Detector()!=DetectorType.BMT) return; + + Point3D crossPoint = this.getBMTCrossPoint(trackPos); + Vector3D crossError = this.getBMTCrossError(trackPos); + if (trackPos == null) { + this.set_Point0(crossPoint); + this.set_PointErr0(crossError.toPoint3D()); + } + this.set_Point(crossPoint); + this.set_PointErr(crossError.toPoint3D()); + } + + private Point3D getBMTCrossPoint(Point3D trackPos) { + Cluster cluster = this.get_Cluster1(); + + Point3D cross = cluster.center(); + + if(trackPos!=null) { + Point3D local = new Point3D(trackPos); + cluster.get_SeedStrip().toLocal().apply(local); + if(this.get_Type()==BMTType.C) { + double phi = Math.atan2(local.y(), local.x()); + double phi0 = Math.atan2(cluster.origin().y(), cluster.origin().x()); + double t = phi-phi0; + if(Math.abs(t)>Math.PI) t-=Math.signum(t)*2*Math.PI; + if(t<0) + cross = cluster.origin(); + else if(t>cluster.get_Arc().theta()) + cross = cluster.end(); + else { + cross = cluster.get_Arc().point(t); + } + } + else { + cross = cluster.getLine().distanceSegment(trackPos).origin(); + } + } + return cross; + } + + + private Vector3D getBMTCrossError(Point3D trackPos) { + Cluster cluster = this.get_Cluster1(); + Point3D cross = this.getBMTCrossPoint(trackPos); + + Point3D local = new Point3D(cross); + cluster.get_SeedStrip().toLocal().apply(local); + + Vector3D error = new Vector3D(cluster.getS()); + error.scale(cluster.get_Resolution()); + error.setXYZ(Math.abs(error.x()), Math.abs(error.y()), Math.abs(error.z())); + return error; + } + + /** + * Sets the cross parameters: the position and direction unit vector + */ + public void setSVTCrossPosition(Vector3D trackDir, SVTGeometry geo) { + + Cluster inlayerclus = this.get_Cluster1(); Cluster outlayerclus = this.get_Cluster2(); if (inlayerclus == null || outlayerclus == null) { return; } - - double[] Params = geo.getCrossPars(outlayerclus.get_Sector(), outlayerclus.get_Layer(), - inlayerclus.get_Centroid(), outlayerclus.get_Centroid(), dirAtBstPlane); - - double val = Params[0]; - if (Double.isNaN(val)) { - return; // cross not withing fiducial region + // RDV: z error is now smaller because resulting from strip resolution instead of +/- 1 strip + Point3D crossPoint = this.getSVTCrossPoint(trackDir, geo); + Vector3D crossError = this.getSVTCrossError(trackDir, geo); + + if(crossPoint==null || crossError==null) { + return; + } + + if (trackDir == null) { + this.set_Point0(crossPoint); + this.set_PointErr0(crossError.toPoint3D()); } - Point3D interPoint = new Point3D(Params[0], Params[1], Params[2]); - Point3D interPointErr = new Point3D(Params[3], Params[4], Params[5]); + this.set_Point(crossPoint); +// this.set_Dir(trackDir); + this.set_PointErr(crossError.toPoint3D()); - if (dirAtBstPlane == null) { - this.set_Point0(interPoint); - this.set_PointErr0(interPointErr); - } + } - this.set_Point(interPoint); - this.set_Dir(dirAtBstPlane); - this.set_PointErr(interPointErr); + /** + * Calculate the cross point from the two strips and the track direction + * @param trackDir track direction + * @param geo SVT geometry class + * @return + */ + public Point3D getSVTCrossPoint(Vector3D trackDir, SVTGeometry geo) { + + int layer = this.get_Cluster1().get_Layer(); + int sector = this.get_Cluster1().get_Sector(); + + Point3D cross = geo.getCross(sector, layer, this.get_Cluster1().getLine(), this.get_Cluster2().getLine(), trackDir); + + return cross; + } - //System.out.println("[Cross] in setCrossPars interPoint "+interPoint.toString()); - //if(dirAtBstPlane!=null) - // System.out.println(" dirAtBstPlane "+dirAtBstPlane.toString()); + /** + * Calculate the cross position error from the two strips and the track direction + * @param trackDir track direction + * @param geo VT geometry + * @return + */ + public Vector3D getSVTCrossError(Vector3D trackDir, SVTGeometry geo) { + Vector3D error = null; + + int layer = this.get_Cluster1().get_Layer(); + int sector = this.get_Cluster1().get_Sector(); + + Point3D cross = this.getSVTCrossPoint(trackDir, geo); + if(cross!=null) { + // get the strip resolution + Point3D local = geo.toLocal(layer, sector, cross); + double sigma1 = geo.getSingleStripResolution(layer, this.get_Cluster1().get_SeedStrip().get_Strip(), local.z()); + double sigma2 = geo.getSingleStripResolution(layer, this.get_Cluster2().get_SeedStrip().get_Strip(), local.z()); + + double delta = 1e-3; // 1micron shift + Line3D strip1 = this.get_Cluster1().getLine(); + Line3D strip2 = this.get_Cluster2().getLine(); + + Vector3D t1 = strip1.direction().asUnit().cross(this.get_Cluster1().getN()).multiply(delta); + Line3D strip1Plus = new Line3D(strip1); + Line3D strip1Minus = new Line3D(strip1); + strip1Plus.translateXYZ(t1.x(), t1.y(), t1.z()); + strip1Minus.translateXYZ(-t1.x(),-t1.y(),-t1.z()); + + Vector3D t2 = strip2.direction().asUnit().cross(this.get_Cluster2().getN()).multiply(delta); + Line3D strip2Plus = new Line3D(strip2); + Line3D strip2Minus = new Line3D(strip2); + strip2Plus.translateXYZ(t2.x(), t2.y(), t2.z()); + strip2Minus.translateXYZ(-t2.x(),-t2.y(),-t2.z()); + + Point3D cross1Plus = geo.getCross(sector, layer, strip1Plus, strip2, trackDir); + Point3D cross1Minus = geo.getCross(sector, layer, strip1Minus, strip2, trackDir); + Point3D cross2Plus = geo.getCross(sector, layer, strip1, strip2Plus, trackDir); + Point3D cross2Minus = geo.getCross(sector, layer, strip1, strip2Minus, trackDir); + Vector3D error1 = cross1Minus.vectorTo(cross1Plus).multiply(sigma1/delta); + Vector3D error2 = cross2Minus.vectorTo(cross2Plus).multiply(sigma2/delta); + error = new Vector3D(Math.sqrt(error1.x()*error1.x()+error2.x()*error2.x()), + Math.sqrt(error1.y()*error1.y()+error2.y()*error2.y()), + Math.sqrt(error1.z()*error1.z()+error2.z()*error2.z())); + if(error.x()==0 && error.y()==0) System.out.println(cross.toString() + "\n" + error.toString()); + } + return error; } @Override diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index cff072091..38c55bbbe 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -99,7 +99,7 @@ public ArrayList findSVTCrosses( this_cross.set_Cluster2(outlayerclus); this_cross.set_Id(rid); // sets the cross parameters (point3D and associated error) from the SVT geometry - this_cross.set_CrossParamsSVT(null, svt_geo); + this_cross.setSVTCrossPosition(null, svt_geo); // the uncorrected point obtained from default estimate that the track is at 90 deg wrt the module should not be null if (this_cross.get_Point0() != null) { //pass the cross to the arraylist of crosses @@ -153,28 +153,33 @@ private ArrayList findBMTCrosses( // define new cross Cross this_cross = new Cross(DetectorType.BMT, BMTType.Z, Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); this_cross.set_Id(pid); - this_cross.set_Cluster1(Zlayerclus); // this is the inner shell - //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips - // in the cluster prior to taking Lorentz angle correction into account - double x0 = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi0()); - double y0 = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi0()); - double x0Er = -bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); - double y0Er = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); - // set only the coordinates for which there is a measurement - this_cross.set_Point0(new Point3D(x0, y0, Double.NaN)); - this_cross.set_PointErr0(new Point3D(x0Er, y0Er, Double.NaN)); - //the x,y position of the Z detector cluster centroid. This is calculated from the Lorentz angle corrected strips - //double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); - //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); - double x = Zlayerclus.getLine().midpoint().x(); - double y = Zlayerclus.getLine().midpoint().y(); - double xEr = -bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); - double yEr = bmt_geo.getRadiusMidDrift(Zlayerclus.get_Layer()) * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); - - // set only the coordinates for which there is a measurement (x,y) - this_cross.set_Point(new Point3D(x, y, Double.NaN)); - this_cross.set_PointErr(new Point3D(Math.abs(xEr), Math.abs(yEr), Double.NaN)); - this_cross.set_Cluster1(Zlayerclus); + this_cross.set_Cluster1(Zlayerclus); + this_cross.setBMTCrossPosition(null); +// //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips +// // in the cluster prior to taking Lorentz angle correction into account +// double radius = Zlayerclus.getRadius(); +// double x0 = radius * Math.cos(Zlayerclus.get_Phi0()); +// double y0 = radius * Math.sin(Zlayerclus.get_Phi0()); +// double x0Er = radius * Math.sin(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); +// double y0Er = radius * Math.cos(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); +// // set only the coordinates for which there is a measurement +// this_cross.set_Point0(new Point3D(x0, y0, Double.NaN)); +// this_cross.set_PointErr0(new Point3D(x0Er, y0Er, Double.NaN)); +// //the x,y position of the Z detector cluster centroid. This is calculated from the Lorentz angle corrected strips +// //double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); +// //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); +// double x = Zlayerclus.center().x(); +// double y = Zlayerclus.center().y(); +// double xEr = radius * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); +// double yEr = radius * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); +// System.out.println(this_cross.get_Point().toString()); +// System.out.println(this_cross.get_PointErr().toString()); +// System.out.println(x + " " + y + " " + xEr + " " + yEr); +// +// // set only the coordinates for which there is a measurement (x,y) +// this_cross.set_Point(new Point3D(x, y, Double.NaN)); +// this_cross.set_PointErr(new Point3D(Math.abs(xEr), Math.abs(yEr), Double.NaN)); +// this_cross.set_Cluster1(Zlayerclus); if (this_cross.get_Point0() != null) { //make arraylist crosses.add(this_cross); @@ -192,15 +197,16 @@ private ArrayList findBMTCrosses( this_cross.set_Id(pid); // measurement of z - double z = Clayerclus.center().z(); - double zErr = Clayerclus.get_ZErr(); - // there is no measurement of x,y, hence only the z component is set - this_cross.set_Point0(new Point3D(Double.NaN, Double.NaN, z)); - this_cross.set_PointErr0(new Point3D(Double.NaN, Double.NaN, zErr)); - // at this stage there is no additional correction to the measured centroid - this_cross.set_Point(new Point3D(Double.NaN, Double.NaN, z)); - this_cross.set_PointErr(new Point3D(Double.NaN, Double.NaN, zErr)); +// double z = Clayerclus.center().z(); +// double zErr = Clayerclus.get_ZErr(); +// // there is no measurement of x,y, hence only the z component is set +// this_cross.set_Point0(new Point3D(Double.NaN, Double.NaN, z)); +// this_cross.set_PointErr0(new Point3D(Double.NaN, Double.NaN, zErr)); +// // at this stage there is no additional correction to the measured centroid +// this_cross.set_Point(Clayerclus.center()); +// this_cross.set_PointErr(new Point3D(Double.NaN, Double.NaN, zErr)); this_cross.set_Cluster1(Clayerclus); + this_cross.setBMTCrossPosition(null); if (this_cross.get_Point0() != null) { //make arraylist crosses.add(this_cross); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index ba400fbb6..7328d5962 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -273,6 +273,11 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrkNew (List allClusters, List2*Math.PI/SVTGeometry.NSECTORS[ilayer]) continue; + int key = sgeo.getModuleId(layer, sector); // calculate trajectory - Point3D traj = null; - Vector3D n = sgeo.getNormal(layer, sector); + Point3D traj = null; Point3D p = sgeo.getModule(layer, sector).origin(); double d = n.dot(p.toVector3D()); inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); @@ -297,11 +307,10 @@ public List FindClustersOnTrkNew (List allClusters, List reFitSeed(Seed bseed, layr2 = c.get_Cluster2().get_Layer(); if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { - c.set_CrossParamsSVT(null, SVTGeom); + c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; refi.add(c); } @@ -677,7 +686,7 @@ public List reFitSeed(Seed bseed, layr2 = c.get_Cluster2().get_Layer(); if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { - c.set_CrossParamsSVT(null, SVTGeom); + c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refi.add(c); @@ -734,7 +743,7 @@ public List reFitSeed(StraightTrack cand, layr2 = c.get_Cluster2().get_Layer(); if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { - c.set_CrossParamsSVT(null, SVTGeom); + c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refi.add(c); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 82b7e80c6..5b52b4f68 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -119,7 +119,7 @@ public boolean processEvent(DataEvent event, shift, recUtil.setMeasVecs(seed, swimmer)) ; //Uncomment to let track be fitted - //kf.filterOn=false; + kf.filterOn=false; kf.runFitter(swimmer); if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) { Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); @@ -162,7 +162,7 @@ public boolean processEvent(DataEvent event, shift, recUtil.setMeasVecs(seed, swimmer)) ; //Uncomment to let track be fitted - //kf.filterOn = false; + kf.filterOn = false; kf.runFitter(swimmer); Track trk = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index a992ed27c..96793a520 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -4,6 +4,7 @@ import org.jlab.detector.geant4.v2.SVT.SVTConstants; import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; @@ -95,6 +96,37 @@ public Vector3D getNormal(int layer, int sector) { return new Vector3D(normal.x, normal.y, normal.z); } + public Plane3D getPlane(int layer, int sector) { + return new Plane3D(this.getModule(layer, sector).midpoint(), this.getNormal(layer, sector)); + } + + public Line3D getStripProjection(Line3D strip, Plane3D plane, Vector3D dir) { + Point3D stripO = new Point3D(); + plane.intersection(new Line3D(strip.origin(),dir), stripO); + Point3D stripE = new Point3D(); + plane.intersection(new Line3D(strip.end(),dir), stripE); + + return new Line3D(stripO, stripE); + } + + public Point3D getCross(int sector, int layer, Line3D strip1, Line3D strip2, Vector3D dir) { + Point3D cross = null; + + // if direction is not provided, use normal to the plane + Vector3D n = this.getNormal(layer, sector); + if(dir != null) { + n = new Vector3D(dir); + n.unit(); + } + + Line3D strip2Projection = this.getStripProjection(strip2, this.getPlane(layer, sector), n); + if(strip2Projection!=null) { + cross = strip1.distance(strip2Projection).origin(); + if(dir!=null && !this.isInFiducial(layer, sector, cross)) cross = null; + } + return cross; + } + public Point3D toLocal(int layer, int sector, Point3D traj) { Vector3d local = this._svtStripFactory.transformToLocal(layer-1, sector-1, traj.x(), traj.y(), traj.z()); return new Point3D(local.x, local.y, local.z); @@ -117,6 +149,15 @@ public Vector3D toGlobal(int layer, int sector, Vector3D dir) { return new Vector3D(lab.x-zero.x, lab.y-zero.y, lab.z-zero.z); } + public double getDoca(int layer, int sector, int strip, Point3D traj) { + return this.getStrip(layer, sector, strip).distance(traj).length(); + } + + public double getResidual(int layer, int sector, int strip, Point3D traj) { + Line3D dist = this.getStrip(layer, sector, strip).distance(traj); + double side = -Math.signum(this.getStrip(layer, sector, strip).direction().cross(dist.direction()).dot(this.getNormal(layer, sector))); + return dist.length()*side; + } @Deprecated public int getSector(int layer, Point3D traj) { @@ -144,156 +185,146 @@ public int getSector(int layer, Point3D traj) { return Sect; } - //*** - public double[] getLocCoord(double s1, double s2) { //2 top, 1 bottom - - double[] X = new double[2]; - double ialpha1 = (s1 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc1 = (s1 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - double ialpha2 = (s2 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); - //the active area starts at the first strip - double interc2 = (s2 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; - - // Equation for strip line is x = mz + b [i.e. z is the direction of the length of the module] - // ------------------------------------- - double m1 = -Math.tan(ialpha1); - double m2 = Math.tan(ialpha2); - double b1 = SVTConstants.ACTIVESENWID - interc1; - double b2 = interc2; - - double z = (b2 - b1) / (m1 - m2); - double x = m1 * z + b1; - X[0] = x; - X[1] = z; - - return X; - } - - public double[] getLocCoordErrs(int lay1, int lay2, double s1, double s2, double z) { - double[] Xerr = new double[2]; - - double sigma1 = getSingleStripResolution(lay1, (int) s1, z); - double sigma2 = getSingleStripResolution(lay2, (int) s2, z); - - Xerr[0] = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2); - - Xerr[1] = (getLocCoord(s1 - 0.5, s2 - 0.5)[1] - - getLocCoord(s1 + 0.5, s2 + 0.5)[1]); - - if (s1 <= 1) { - Xerr[1] = (getLocCoord(s1, s2 - 0.5)[1] - - getLocCoord(s1 + 1.5, s2 + 0.5)[1]); - } - if (s2 <= 1) { - Xerr[1] = (getLocCoord(s1 - 0.5, s2)[1] - - getLocCoord(s1 + 1.5, s2 + 2.5)[1]); - } - - return Xerr; - - } +// //*** +// public double[] getLocCoord(double s1, double s2) { //2 top, 1 bottom +// +// double[] X = new double[2]; +// double ialpha1 = (s1 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); +// //the active area starts at the first strip +// double interc1 = (s1 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; +// double ialpha2 = (s2 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); +// //the active area starts at the first strip +// double interc2 = (s2 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; +// +// // Equation for strip line is x = mz + b [i.e. z is the direction of the length of the module] +// // ------------------------------------- +// double m1 = -Math.tan(ialpha1); +// double m2 = Math.tan(ialpha2); +// double b1 = SVTConstants.ACTIVESENWID - interc1; +// double b2 = interc2; +// +// double z = (b2 - b1) / (m1 - m2); +// double x = m1 * z + b1; +// X[0] = x; +// X[1] = z; +// +// return X; +// } +// +// public double[] getLocCoordErrs(int lay1, int lay2, double s1, double s2, double z) { +// double[] Xerr = new double[2]; +// +// double sigma1 = getSingleStripResolution(lay1, (int) s1, z); +// double sigma2 = getSingleStripResolution(lay2, (int) s2, z); +// +// Xerr[0] = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2); +// +// Xerr[1] = (getLocCoord(s1 - 0.5, s2 - 0.5)[1] +// - getLocCoord(s1 + 0.5, s2 + 0.5)[1]); +// +// if (s1 <= 1) { +// Xerr[1] = (getLocCoord(s1, s2 - 0.5)[1] +// - getLocCoord(s1 + 1.5, s2 + 0.5)[1]); +// } +// if (s2 <= 1) { +// Xerr[1] = (getLocCoord(s1 - 0.5, s2)[1] +// - getLocCoord(s1 + 1.5, s2 + 2.5)[1]); +// } +// +// return Xerr; +// +// } - - public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, Vector3D trkDir) { - - double[] vals = new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; - - // if first iteration trkDir == null - double s2corr = s2; - // now use track info - s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, SVTConstants.MODULELEN); - double z = getLocCoord(s1, s2corr)[1]; - //update using the corrected z - s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, z); - double zf = getLocCoord(s1, s2corr)[1]; - - if (upperlayer % 2 != 0) // should not happen as is upper layer...but just in case - { - s2corr = s2; - } - - double[] LC = getLocCoord(s1, s2corr); - double[] LCErr = getLocCoordErrs(upperlayer - 1, upperlayer, s1, s2corr, zf); - - Point3D crPoint = this.toGlobal(upperlayer-1, sector, new Point3D(LC[0], 0, LC[1])); - Vector3D crErr = this.toGlobal(upperlayer-1, sector, new Vector3D(LCErr[0], 0, LCErr[1])); - - double LCErr_x = LCErr[0]; - double LCErr_z = LCErr[1]; - - // global rotation angle to get the error in the local frame - int[] rm = SVTConstants.convertLayer2RegionModule(upperlayer-1); - - // global rotation angle - double Glob_rangl = ((double) -(sector - 1) / (double) SVTConstants.NSECTORS[rm[0]]) - * 2. * Math.PI + SVTConstants.PHI0; - // angle to rotate to global frame - double LOCZAXISROTATION = -Math.toRadians(90.); - double Loc_to_Glob_rangl = Glob_rangl - LOCZAXISROTATION; - - double cosRotation = Math.cos(Loc_to_Glob_rangl); - double sinRotation = Math.sin(Loc_to_Glob_rangl); - - double yerr = Math.abs(cosRotation * LCErr_x); - double xerr = Math.abs(sinRotation * LCErr_x); - - // RDV: check because old errors seems to be rotated by 90 deg -// System.out.println("Cross:\n" + xerr + " " + yerr + " " + LCErr_z); -// System.out.println(crErr.toString()); -// System.out.println(crPoint.toString()); - - if (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL * 2) { - return vals; - } - // once there is a trk, the cross should be well calculated - //if the local cross is not in the fiducial volume it is not physical - else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConstants.ACTIVESENWID + SVTConstants.SIDETOL)) - || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL))) { - return vals; - } - else { - vals[0] = crPoint.x(); - vals[1] = crPoint.y(); - vals[2] = crPoint.z(); - vals[3] = Math.abs(crErr.x()); - vals[4] = Math.abs(crErr.y()); - vals[5] = Math.abs(crErr.z()); - } - - return vals; - - } - - public double getDoca(int layer, int sector, int strip, Point3D traj) { - return this.getStrip(layer, sector, strip).distance(traj).length(); - } - public double getResidual(int layer, int sector, int strip, Point3D traj) { - Line3D dist = this.getStrip(layer, sector, strip).distance(traj); - double side = -Math.signum(this.getStrip(layer, sector, strip).direction().cross(dist.direction()).dot(this.getNormal(layer, sector))); - return dist.length()*side; - } +// public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, Vector3D trkDir) { +// +// double[] vals = new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; +// +// // if first iteration trkDir == null +// double s2corr = s2; +// // now use track info +// s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, SVTConstants.MODULELEN); +// double z = getLocCoord(s1, s2corr)[1]; +// //update using the corrected z +// s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, z); +// double zf = getLocCoord(s1, s2corr)[1]; +// +// if (upperlayer % 2 != 0) // should not happen as is upper layer...but just in case +// { +// s2corr = s2; +// } +// +// double[] LC = getLocCoord(s1, s2corr); +// double[] LCErr = getLocCoordErrs(upperlayer - 1, upperlayer, s1, s2corr, zf); +// +// Point3D crPoint = this.toGlobal(upperlayer-1, sector, new Point3D(LC[0], 0, LC[1])); +// Vector3D crErr = this.toGlobal(upperlayer-1, sector, new Vector3D(LCErr[0], 0, LCErr[1])); +// +// double LCErr_x = LCErr[0]; +// double LCErr_z = LCErr[1]; +// +// // global rotation angle to get the error in the local frame +// int[] rm = SVTConstants.convertLayer2RegionModule(upperlayer-1); +// +// // global rotation angle +// double Glob_rangl = ((double) -(sector - 1) / (double) SVTConstants.NSECTORS[rm[0]]) +// * 2. * Math.PI + SVTConstants.PHI0; +// // angle to rotate to global frame +// double LOCZAXISROTATION = -Math.toRadians(90.); +// double Loc_to_Glob_rangl = Glob_rangl - LOCZAXISROTATION; +// +// double cosRotation = Math.cos(Loc_to_Glob_rangl); +// double sinRotation = Math.sin(Loc_to_Glob_rangl); +// +// double yerr = Math.abs(cosRotation * LCErr_x); +// double xerr = Math.abs(sinRotation * LCErr_x); +// +// // RDV: check because old errors seems to be rotated by 90 deg +//// System.out.println("Cross:\n" + xerr + " " + yerr + " " + LCErr_z); +//// System.out.println(crErr.toString()); +//// System.out.println(crPoint.toString()); +// +// if (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL * 2) { +// return vals; +// } +// // once there is a trk, the cross should be well calculated +// //if the local cross is not in the fiducial volume it is not physical +// else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConstants.ACTIVESENWID + SVTConstants.SIDETOL)) +// || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL))) { +// return vals; +// } +// else { +// vals[0] = crPoint.x(); +// vals[1] = crPoint.y(); +// vals[2] = crPoint.z(); +// vals[3] = Math.abs(crErr.x()); +// vals[4] = Math.abs(crErr.y()); +// vals[5] = Math.abs(crErr.z()); +// } +// +// return vals; +// +// } - private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D trkDir, double ZalongModule) { - double s2corr = s2; - // second iteration: there is a track direction - if (trkDir != null) { - double stripCorr = getStripIndexShift(sector, upperlayer, trkDir, s2, ZalongModule); - if (s2 > 1) { - s2corr = s2 + stripCorr; - } - if (s2 == 1) { - if (stripCorr >= 0) { - s2corr = s2 + stripCorr; - } - if (stripCorr < 0) { - s2corr = s2; - } - } - } - return s2corr; - } +// private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D trkDir, double ZalongModule) { +// double s2corr = s2; +// // second iteration: there is a track direction +// if (trkDir != null) { +// double stripCorr = getStripIndexShift(sector, upperlayer, trkDir, s2, ZalongModule); +// if (s2 > 1) { +// s2corr = s2 + stripCorr; +// } +// if (s2 == 1) { +// if (stripCorr >= 0) { +// s2corr = s2 + stripCorr; +// } +// if (stripCorr < 0) { +// s2corr = s2; +// } +// } +// } +// return s2corr; +// } public int calcNearestStrip(double X, double Y, double Z, int layer, int sect) { @@ -447,43 +478,43 @@ public double getXAtZ(int layer, double centroidstrip, double Z) { } //*** - public double getStripIndexShift(int sector, int layer, Vector3D trkDir, double s2, double z) { - - double tx = trkDir.x(); - double ty = trkDir.y(); - Vector3D trkDir_t = new Vector3D(tx,ty,0); - trkDir_t.unit(); - Vector3D n = this.getNormal(layer, sector); - - if (Math.acos(n.dot(trkDir_t)) > Math.PI / 2) { // flip track dir for y<0 for cosmics: - trkDir_t.negative(); - } - - double TrkToPlnNormRelatAngl = Math.acos(n.dot(trkDir_t)); - double sign = Math.signum(n.cross(trkDir_t).z()); - - //correction to the pitch to take into account the grading of the angle -- get the upper or lower strip depending on the trkdir - double pitchcorr = SVTConstants.READOUTPITCH; - - if (s2 > 2 && s2 < 255) { - double pitchToNextStrp = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); - double pitchToPrevStrp = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); - pitchcorr = (pitchToNextStrp + pitchToPrevStrp) / 2.; - } - if (s2 <= 2) { - pitchcorr = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); - } - if (s2 == 256) { - pitchcorr = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); - } - - double layerGap = SVTConstants.LAYERRADIUS[0][1] // MODULERADIUS[1][0] = 65.447 + LAYRGAP + MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][1] - - SVTConstants.LAYERRADIUS[0][0]; // MODULERADIUS[0][0] = 65.447 - MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][0] - - double shift = sign * layerGap * Math.tan(TrkToPlnNormRelatAngl) / pitchcorr; - - return -shift; - } +// public double getStripIndexShift(int sector, int layer, Vector3D trkDir, double s2, double z) { +// +// double tx = trkDir.x(); +// double ty = trkDir.y(); +// Vector3D trkDir_t = new Vector3D(tx,ty,0); +// trkDir_t.unit(); +// Vector3D n = this.getNormal(layer, sector); +// +// if (Math.acos(n.dot(trkDir_t)) > Math.PI / 2) { // flip track dir for y<0 for cosmics: +// trkDir_t.negative(); +// } +// +// double TrkToPlnNormRelatAngl = Math.acos(n.dot(trkDir_t)); +// double sign = Math.signum(n.cross(trkDir_t).z()); +// +// //correction to the pitch to take into account the grading of the angle -- get the upper or lower strip depending on the trkdir +// double pitchcorr = SVTConstants.READOUTPITCH; +// +// if (s2 > 2 && s2 < 255) { +// double pitchToNextStrp = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); +// double pitchToPrevStrp = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); +// pitchcorr = (pitchToNextStrp + pitchToPrevStrp) / 2.; +// } +// if (s2 <= 2) { +// pitchcorr = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); +// } +// if (s2 == 256) { +// pitchcorr = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); +// } +// +// double layerGap = SVTConstants.LAYERRADIUS[0][1] // MODULERADIUS[1][0] = 65.447 + LAYRGAP + MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][1] +// - SVTConstants.LAYERRADIUS[0][0]; // MODULERADIUS[0][0] = 65.447 - MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][0] +// +// double shift = sign * layerGap * Math.tan(TrkToPlnNormRelatAngl) / pitchcorr; +// +// return -shift; +// } //*** public boolean isInFiducial(int layer, int sector, Point3D traj) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java index 0c56efcbb..db79a86d4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java @@ -59,8 +59,6 @@ public class SVTParameters { // public static boolean isRadialMisalignmentTest = false; // public static final double RadSpecs = 0.750; - public static final double CIRCLEFIT_MAXCHI2 = 100; - public static final int BSTTRKINGNUMBERITERATIONS = 3; public static final int MAXNUMCROSSES = 50; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index 77a8de1ad..96ce183ad 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -69,7 +69,7 @@ public void update_Cross(Cross cross, double fit_yxslope, double fit_yzslope, SV Vector3D trkDir = new Vector3D(x, y, z); if (trkDir != null) { - cross.set_CrossParamsSVT(trkDir, geo); + cross.setSVTCrossPosition(trkDir, geo); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index d84864cbd..94e63a252 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -8,6 +8,7 @@ import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -413,14 +414,11 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt SVTCrosses.clear(); for (Cross c : VTCrosses) { - if (!(Double.isNaN(c.get_Point().z()) || Double.isNaN(c.get_Point().x()))) { + if (c.get_Detector() == DetectorType.BST) { SVTCrosses.add(c); - } - - if (Double.isNaN(c.get_Point().x())) { + } else if (c.get_Detector() == DetectorType.BMT && c.get_Type() == BMTType.C) { BMTCrossesC.add(c); - } - if (Double.isNaN(c.get_Point().z())) { + } else if (c.get_Detector() == DetectorType.BMT && c.get_Type() == BMTType.Z) { BMTCrossesZ.add(c); } } @@ -492,19 +490,24 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt cand = new Track(fitTrk.get_helix()); //cand.addAll(SVTCrosses); cand.addAll(SVTCrosses); + cand.addAll(BMTCrossesZ); + cand.addAll(BMTCrossesC); fitTrk.get_helix().B = 0; cand.set_HelicalTrack(fitTrk.get_helix()); //if(shift==0) +// if(i==0) System.out.println(); +// System.out.println(fitTrk.get_chisq()[0] + " " + chisqMax + " " + Constants.CIRCLEFIT_MAXCHI2); + cand.update_Crosses(svt_geo, bmt_geo); if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxSVTParameters.CIRCLEFIT_MAXCHI2) + if(chisqMax>Constants.CIRCLEFIT_MAXCHI2) cand=null; return cand; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 829678a7c..c4679c7ff 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -1,11 +1,13 @@ package org.jlab.rec.cvt.track; +import org.jlab.clas.swimtools.Swimmer; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -130,6 +132,28 @@ public void set_HelicalTrack(Helix Helix) { } } + public void update_Crosses(SVTGeometry sgeo, BMTGeometry bgeo) { + if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { +// System.out.println("Updating crosses"); + + Helix helix = this.get_helix(); + for (int i = 0; i < this.size(); i++) { + Cross cross = this.get(i); + double R = Math.sqrt(cross.get_Point().x() * cross.get_Point().x() + cross.get_Point().y() * cross.get_Point().y()); + Point3D helixPos = helix.getPointAtRadius(R); + Vector3D helixDir = helix.getTrackDirectionAtRadius(R); +// System.out.println("Traj " + cross.get_Cluster1().get_Layer() + " " + helixPos.toString()); +// System.out.println("Cross " + cross.get_Detector().getName() + " " + cross.get_Point().toString()); + if(cross.get_Detector()==DetectorType.BST) + cross.setSVTCrossPosition(helixDir, sgeo); + else if(cross.get_Detector()==DetectorType.BMT) + cross.setBMTCrossPosition(helixPos); + } + + } + + } + /** * updates the crosses positions based on the track direction for a helical * trajectory @@ -146,7 +170,7 @@ public void update_Crosses(SVTGeometry geo) { } double R = Math.sqrt(this.get(i).get_Point().x() * this.get(i).get_Point().x() + this.get(i).get_Point().y() * this.get(i).get_Point().y()); Vector3D helixTanVecAtLayer = helix.getTrackDirectionAtRadius(R); - this.get(i).set_CrossParamsSVT(helixTanVecAtLayer, geo); + this.get(i).setSVTCrossPosition(helixTanVecAtLayer, geo); if (this.get(i).get_Cluster2().get_Centroid() <= 1) { //recalculate z using track pars: double z = helix.getPointAtRadius(R).z(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 820330e31..b112adbe1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -131,7 +131,7 @@ public class RayMeasurements { } /** - * + * NOT Used * @param list the input list of crosses * @return an array list of track candidates in the SVT */ @@ -799,7 +799,7 @@ private void resetUnusedCross(Cross cross, SVTGeometry geo) { cross.set_Dir(new Vector3D(0, 0, 0)); - cross.set_CrossParamsSVT(null, geo); + cross.setSVTCrossPosition(null, geo); } /** diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index dfee0f2a3..ad022e43f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -63,7 +63,7 @@ public List getTracks(List cands, trk.get_P(), charge, maxPathLength) ; - double[] pointAtCylRad = cvtSwim.SwimRho(Constants.CTOFINNERRADIUS/10); + double[] pointAtCylRad = cvtSwim.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,0), Constants.CTOFINNERRADIUS/10); if(pointAtCylRad!=null) { trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index a4df3bf6a..18acdeca1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -9,6 +9,7 @@ import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -443,14 +444,13 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt SVTCrosses.clear(); for (Cross c : VTCrosses) { - if (!(Double.isNaN(c.get_Point().z()) || Double.isNaN(c.get_Point().x()))) { + if (c.get_Detector()==DetectorType.BST) { SVTCrosses.add(c); } - - if (Double.isNaN(c.get_Point().x())) { + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { BMTCrossesC.add(c); } - if (Double.isNaN(c.get_Point().z())) { + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { BMTCrossesZ.add(c); } } @@ -522,6 +522,8 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt cand = new Track(fitTrk.get_helix()); //cand.addAll(SVTCrosses); cand.addAll(SVTCrosses); + cand.addAll(BMTCrossesC); + cand.addAll(BMTCrossesZ); swimmer.BfieldLab(0, 0, 0, b); double Bz = Math.abs(b[2]); @@ -530,13 +532,13 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxSVTParameters.CIRCLEFIT_MAXCHI2) + if(chisqMax>Constants.CIRCLEFIT_MAXCHI2) return null; if(X.size() > 3) cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index d05f26748..01f5c713d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -5,6 +5,7 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -14,7 +15,6 @@ import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.svt.SVTGeometry; -import org.jlab.rec.cvt.svt.SVTParameters; public class TrackSeederCA { @@ -429,13 +429,13 @@ public List> CAonRZ( int l1 = c.get_Cluster1().get_Layer(); int s1 = c.get_Cluster1().get_Sector(); double c1 = c.get_Cluster1().get_Centroid(); - double r1 = svt_geo.getLayerRadius(l1); + double r1 = SVTGeometry.getLayerRadius(l1); double nstr1 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r1 - b)/m, l1, s1); int l2 = c.get_Cluster2().get_Layer(); int s2 = c.get_Cluster2().get_Sector(); double c2 = c.get_Cluster2().get_Centroid(); - double r2 = svt_geo.getLayerRadius(l2); + double r2 = SVTGeometry.getLayerRadius(l2); double nstr2 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r2 - b)/m, l2, s2); if( Math.abs( c1 - nstr1 ) < 8 && Math.abs( c2 - nstr2 ) < 8 ) @@ -513,14 +513,13 @@ public Track fitSeed(List VTCrosses, SVTCrosses.clear(); for (Cross c : VTCrosses) { - if (!(Double.isNaN(c.get_Point().z()) || Double.isNaN(c.get_Point().x()))) { + if (c.get_Detector()==DetectorType.BST) { SVTCrosses.add(c); } - - if (Double.isNaN(c.get_Point().x())) { + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { BMTCrossesC.add(c); } - if (Double.isNaN(c.get_Point().z())) { + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { BMTCrossesZ.add(c); } } @@ -618,8 +617,8 @@ public Track fitSeed(List VTCrosses, //if(shift==0) if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; - if(chisqMax Date: Sun, 10 Oct 2021 14:54:25 +0200 Subject: [PATCH 181/291] CVT: removed hardcoded rotation --- .../src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index f77a9040a..612de09c9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -297,7 +297,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double ypos = dbprovider.getDouble("/geometry/cvt/mvt/position/y", 0 ); double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); // hardcode gemc rotation: set angles to 0 to null it - Vector3D gemcRot = new Vector3D(-2,0,0); + Vector3D gemcRot = new Vector3D(0,0,0); Point3D bmtCenter = new Point3D(0,0,-94.7); // the original BMT Center Point3D bmtShift = new Point3D(bmtCenter); bmtCenter.rotateZ(Math.toRadians(gemcRot.z())); From 9ff549a3205a9d75e7527dbfe3608c661d3436d5 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Sun, 10 Oct 2021 15:22:41 -0400 Subject: [PATCH 182/291] flipped the sign conventions for A and B to match Widl et al. --- .../jlab/rec/cvt/services/CVTAlignment.java | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 006852f0b..555790326 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -521,8 +521,8 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); */ - Vector3D dmdr =sp.cross(extrap); - dmdr = dmdr.clone().sub(n.cross(u).multiply(n.dot(e.clone().sub(extrap))*sdotu/(udotn*udotn))); + //Vector3D dmdr =sp.cross(extrap); + //dmdr = dmdr.clone().sub(n.cross(u).multiply(n.dot(e.clone().sub(extrap))*sdotu/(udotn*udotn))); /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); @@ -531,12 +531,13 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ //System.out.println("i = " + i + "; rows = " + A.getRowDimension() + "; cols = " + + A.getColumnDimension()); + Vector3D dmdr = sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e))/udotn)); if(orderTx >= 0) - A.set(i, i*nAlignVars + orderTx, -sp.x()); + A.set(i, i*nAlignVars + orderTx, sp.x()); if(orderTy >= 0) - A.set(i, i*nAlignVars + orderTy, -sp.y()); + A.set(i, i*nAlignVars + orderTy, sp.y()); if(orderTz >= 0) - A.set(i, i*nAlignVars + orderTz, -sp.z()); + A.set(i, i*nAlignVars + orderTz, sp.z()); if(orderRx >= 0) A.set(i, i*nAlignVars + orderRx, dmdr.x()); if(orderRy >= 0) @@ -561,17 +562,10 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); double cosdip = Math.hypot(u.x(), u.y()); double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.clone().sub(u.multiply(n.dot(mscphi)/udotn)))); - //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.clone().subtract(xref))/udotn)) - // .clone().subtract(u.times(mscphi.dot(n)*n.dot(e.clone().subtract(xref))/(udotn*udotn))) - // .plus(u.times(d*n.dot(csphi)/udotn))) - // ); - B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.clone().clone().sub(xref)) - + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z()-sdotu*n.z()/udotn); - B.set(i, 3, (s.z()/udotn-n.z()*sdotu/(udotn*udotn))*n.dot(e.clone().sub(xref))); + B.set(i, 0, -sp.dot(mscphi)); + B.set(i, 1, -sp.dot(mscphi)*n.dot(e.clone().sub(xref))*cosdip/udotn+sp.dot(csphi)*d); + B.set(i, 2, -sp.z()); + B.set(i, 3, -sp.z()*n.dot(e.clone().sub(xref))/udotn); } @@ -793,17 +787,17 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Vector3D dmdr =sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e))/udotn)); if(orderTx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, -sp.x()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, sp.x()); if(orderTy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, -sp.y()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, sp.y()); if(orderTz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, -sp.z()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, sp.z()); if(orderRx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, dmdr.x()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, -dmdr.x()); if(orderRy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, dmdr.y()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, -dmdr.y()); if(orderRz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, dmdr.z()); + A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, -dmdr.z()); if(detector == DetectorType.BST) @@ -813,10 +807,10 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x()); - B.set(i,1, sp.z()); - B.set(i,2, dmdu.x()); - B.set(i,3, dmdu.z()); + B.set(i,0, -sp.x()); + B.set(i,1, -sp.z()); + B.set(i,2, -dmdu.x()); + B.set(i,3, -dmdu.z()); } else { double phi = Math.atan2(u.y(),u.x()); @@ -824,17 +818,10 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); double cosdip = Math.hypot(u.x(), u.y()); double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.clone().sub(u.multiply(n.dot(mscphi)/udotn)))); - //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) - // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) - // .plus(u.times(d*n.dot(csphi)/udotn))) - // ); - B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.clone().sub(xref)) - + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z()-sdotu*n.z()/udotn); - B.set(i, 3, (s.z()/udotn-n.z()*sdotu/(udotn*udotn))*n.dot(e.clone().sub(xref))); + B.set(i, 0, -sp.dot(mscphi)); + B.set(i, 1, -sp.dot(mscphi)*n.dot(e.clone().sub(xref))*cosdip/udotn+sp.dot(csphi)*d); + B.set(i, 2, -sp.z()); + B.set(i, 3, -sp.z()*n.dot(e.clone().sub(xref))/udotn); } From 1c164e39c14516e3015be166bd728b64c070d3e3 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 11 Oct 2021 23:08:15 +0200 Subject: [PATCH 183/291] SVT geometry service: changed meaning of rx,ry,rz to be rotation angles if ra==0; added temporary swimPlane method mimicking swimGenCylinder for better accuracy in SVT residuals; use swimming for SVT residuals instead of helical point in order to support rotations; more code cleanup --- .../geant4/v2/SVT/AlignmentFactory.java | 68 +- .../detector/geant4/v2/SVT/SVTConstants.java | 4 +- .../geant4/v2/SVT/SVTStripFactory.java | 172 ++--- .../kalmanfilter/helical/StateVecs.java | 79 ++- .../jlab/clas/tracking/trackrep/Helix.java | 5 - .../java/cnuphys/swim/NewPlaneStopper.java | 171 +++++ .../src/main/java/cnuphys/swim/Swimmer.java | 92 ++- .../java/org/jlab/clas/swimtools/Swim.java | 37 +- .../main/java/org/jlab/rec/cvt/Constants.java | 33 +- .../org/jlab/rec/cvt/banks/HitReader.java | 5 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 5 +- .../bmt/{Constants.java => BMTConstants.java} | 48 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 375 ++++------ .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 101 +-- .../java/org/jlab/rec/cvt/bmt/Lorentz.java | 54 +- .../org/jlab/rec/cvt/bmt/OldGeometry.java | 670 ------------------ .../org/jlab/rec/cvt/cluster/Cluster.java | 4 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 5 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 47 +- .../rec/cvt/cross/HelixCrossListFinder.java | 3 +- .../org/jlab/rec/cvt/fit/CircleFitter.java | 4 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 4 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 32 +- .../jlab/rec/cvt/services/RecUtilities.java | 105 +-- .../rec/cvt/services/TracksFromTargetRec.java | 94 ++- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 2 +- .../java/org/jlab/rec/cvt/track/Cell.java | 3 +- .../java/org/jlab/rec/cvt/track/MakerCA.java | 5 +- .../rec/cvt/track/StraightTrackSeeder.java | 13 +- .../java/org/jlab/rec/cvt/track/Track.java | 85 +-- .../rec/cvt/track/TrackCandListFinder.java | 34 +- .../jlab/rec/cvt/track/TrackListFinder.java | 2 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 12 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 4 +- .../org/jlab/rec/cvt/trajectory/Helix.java | 28 +- .../org/jlab/rec/cvt/trajectory/StateVec.java | 5 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 22 +- 37 files changed, 909 insertions(+), 1523 deletions(-) create mode 100644 common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/NewPlaneStopper.java rename reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/{Constants.java => BMTConstants.java} (89%) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java index 3c8c97eee..c672f84c0 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java @@ -332,23 +332,31 @@ public static void applyShift( Vector3d aPoint, double[] aShift, Vector3d aCente } // do the rotation here. - if( !(ra < 1E-3) ) - { - aCenter.times( -1 ); // reverse translation - aPoint.set( aPoint.add( aCenter ) ); // move origin to center of rotation axis + aCenter.times( -1 ); // reverse translation + aPoint.set( aPoint.add( aCenter ) ); // move origin to center of rotation axis //System.out.printf("PC: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); - - Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); - vecAxis.rotate( aPoint, ra ); - + // if ra!=0, assume rx,ry,rz defines the rotation axis and ra the angle + // if angle is non-zero but it is too small, don't do anything + if(Math.abs(ra) >1E-5) + { + Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); + vecAxis.rotate( aPoint, ra ); + } + // if ra==0, assume rx,ry,rz are the rotation angles around the 3 axis + else if(ra==0) + { + aPoint.rotateZ(rz); + aPoint.rotateY(ry); + aPoint.rotateX(rx); + } //System.out.printf("PR: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); - aCenter.times( -1 ); // reverse translation - aPoint.set( aPoint.add( aCenter ) ); - + aCenter.times( -1 ); // reverse translation + aPoint.set( aPoint.add( aCenter ) ); + //System.out.printf("PC: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); - } + // do the translation here. Vector3d translationVec = new Vector3d( tx, ty, tz ); @@ -399,23 +407,31 @@ public static void applyInverseShift( Vector3d aPoint, double[] aShift, Vector3d aPoint.set( aPoint.add( translationVec ) ); // test size of rotation - too small creates errors. - if( !(ra < 1E-3) ) - { - aCenter.times( -1 ); // reverse translation - aPoint.set( aPoint.add( aCenter ) ); // move origin to center of rotation axis + aCenter.times( -1 ); // reverse translation + aPoint.set( aPoint.add( aCenter ) ); // move origin to center of rotation axis //System.out.printf("PC: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); + // if ra!=0, assume rx,ry,rz defines the rotation axis and ra the angle + // if angle is non-zero but it is too small, don't do anything + if(Math.abs(ra) >1E-5) + { + Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); + vecAxis.rotate( aPoint, ra ); + } + // if ra==0, assume rx,ry,rz are the rotation angles around the 3 axis + else if(ra==0) + { + aPoint.rotateX(-rx); + aPoint.rotateY(-ry); + aPoint.rotateZ(-rz); + } - Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); - vecAxis.rotate( aPoint, -ra ); - - //System.out.printf("PR: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); - - aCenter.times( -1 ); // reverse translation - aPoint.set( aPoint.add( aCenter ) ); - - //System.out.printf("PC: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); - } + //System.out.printf("PR: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); + + aCenter.times( -1 ); // reverse translation + aPoint.set( aPoint.add( aCenter ) ); + + //System.out.printf("PC: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); if( VERBOSE ) System.out.printf("PS: % 8.3f % 8.3f % 8.3f\n", aPoint.x, aPoint.y, aPoint.z ); diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index bb673fb3d..feb1e46f3 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -406,7 +406,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table System.out.println("Reading alignment shifts from database"); - double[] myShift = {0, 0, 0, 0, 0, 0, 0,}; + double[] myShift = {0, 0, 0, -Math.toRadians(0), 0, 0, 0}; LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { @@ -424,7 +424,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table ty += ypos; tz += zpos; LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; - if (layer == 1 || layer == 2) { + if (layer == 1 || layer == 2 || true) { for(int j=0; j Geometry for the SVT @@ -31,6 +30,7 @@ public class SVTStripFactory { private boolean bShift = false; // switch to select whether alignment shifts are applied private double scaleT = 1.0, scaleR = 1.0; + private Vector3d labCenter = new Vector3d(0,0,0); /** * Constructs a new geometry factory for sensor strips. @@ -276,10 +276,18 @@ public Line3d getShiftedStrip( int aRegion, int aSector, int aModule, int aStrip { int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); Line3d stripLine = getIdealStrip( aRegion, aSector, aModule, aStrip ); +// System.out.println(aLayer + " " + aSector + " " + stripLine.toString()); if(aRegion SVTConstants.NLAYERS-1 ){ - throw new IllegalArgumentException("layer out of bounds"); - } - int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); - if( aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]]-1){ - throw new IllegalArgumentException("sector out of bounds"); - } - return this.transformToLocal(rm[0], aSector, rm[1], pLab); - } + if (aLayer < 0 || aLayer > SVTConstants.NLAYERS - 1) { + throw new IllegalArgumentException("layer out of bounds"); + } + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + if (aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]] - 1) { + throw new IllegalArgumentException("sector out of bounds"); + } + return this.transformToLocal(rm[0], aSector, rm[1], pLab); + } /** * Transform the pLab point from the lab to the local frame @@ -565,29 +574,28 @@ public Vector3d transformToLocal(int aLayer, int aSector, Vector3d pLab) */ public Vector3d transformToLocal(int aRegion, int aSector, int aModule, Vector3d pLab) { - if( aRegion < 0 || aRegion > SVTConstants.NREGIONS-1 ){ - throw new IllegalArgumentException("region out of bounds"); - } - int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); - if( aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion]-1){ - throw new IllegalArgumentException("sector out of bounds"); - } - Vector3d pLoc = pLab.clone(); - // transform to detector frame - AlignmentFactory.applyInverseShift(pLoc, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], - SVTAlignmentFactory.getIdealFiducialCenter(aRegion, aSector ), - scaleT, scaleR ); - // transform to local frame - double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; - double z = SVTConstants.Z0ACTIVE[aRegion]; - Transform labFrame = SVTConstants.getDetectorFrame( aRegion, aSector, r, z ); - pLoc.transform(labFrame.invert()); - - // transform to strip frame - Transform stripFrame = SVTConstants.getStripFrame(false); - pLoc.transform(stripFrame.invert()); - - return pLoc; + if (aRegion < 0 || aRegion > SVTConstants.NREGIONS - 1) { + throw new IllegalArgumentException("region out of bounds"); + } + int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); + if (aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion] - 1) { + throw new IllegalArgumentException("sector out of bounds"); + } + Vector3d pLoc = pLab.clone(); + // transform to detector frame + AlignmentFactory.applyInverseShift(pLoc, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], + labCenter, scaleT, scaleR); + // transform to local frame + double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; + double z = SVTConstants.Z0ACTIVE[aRegion]; + Transform labFrame = SVTConstants.getDetectorFrame(aRegion, aSector, r, z); + pLoc.transform(labFrame.invert()); + + // transform to strip frame + Transform stripFrame = SVTConstants.getStripFrame(false); + pLoc.transform(stripFrame.invert()); + + return pLoc; } @@ -604,8 +612,8 @@ public Vector3d transformToLocal(int aRegion, int aSector, int aModule, Vector3d */ public Vector3d transformToLab(int aLayer, int aSector, double x, double y, double z) { - return this.transformToLab(aLayer, aSector, new Vector3d(x,y,z)); - } + return this.transformToLab(aLayer, aSector, new Vector3d(x,y,z)); + } /** * Transform the pLoc point from the strip to the lab frame @@ -618,15 +626,15 @@ public Vector3d transformToLab(int aLayer, int aSector, double x, double y, doub */ public Vector3d transformToLab(int aLayer, int aSector, Vector3d pLoc) { - if( aLayer < 0 || aLayer > SVTConstants.NLAYERS-1 ){ - throw new IllegalArgumentException("layer out of bounds"); - } - int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); - if( aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]]-1){ - throw new IllegalArgumentException("sector out of bounds"); - } - return this.transformToLab(rm[0], aSector, rm[1], pLoc); - } + if (aLayer < 0 || aLayer > SVTConstants.NLAYERS - 1) { + throw new IllegalArgumentException("layer out of bounds"); + } + int[] rm = SVTConstants.convertLayer2RegionModule(aLayer); + if (aSector < 0 || aSector > SVTConstants.NSECTORS[rm[0]] - 1) { + throw new IllegalArgumentException("sector out of bounds"); + } + return this.transformToLab(rm[0], aSector, rm[1], pLoc); + } /** * Transform the pLab point from the strip to the lab frame @@ -638,34 +646,32 @@ public Vector3d transformToLab(int aLayer, int aSector, Vector3d pLoc) * @return Vector3d of point coordinate in the module local frame * @throws IllegalArgumentException indices out of bounds */ - public Vector3d transformToLab(int aRegion, int aSector, int aModule, Vector3d pLoc) - { - if( aRegion < 0 || aRegion > SVTConstants.NREGIONS-1 ){ - throw new IllegalArgumentException("region out of bounds"); - } - int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); - if( aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion]-1){ - throw new IllegalArgumentException("sector out of bounds"); - } - Vector3d pLab = pLoc.clone(); - - // transform to local frame - Transform stripFrame = SVTConstants.getStripFrame(false); - pLab.transform(stripFrame); - - // transform to detector frame - double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; - double z = SVTConstants.Z0ACTIVE[aRegion]; - Transform labFrame = SVTConstants.getDetectorFrame( aRegion, aSector, r, z ); - pLab.transform(labFrame); - - // transform to lab frame - AlignmentFactory.applyShift(pLab, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], - SVTAlignmentFactory.getIdealFiducialCenter(aRegion, aSector ), - scaleT, scaleR ); - - return pLab; - } + public Vector3d transformToLab(int aRegion, int aSector, int aModule, Vector3d pLoc) { + if (aRegion < 0 || aRegion > SVTConstants.NREGIONS - 1) { + throw new IllegalArgumentException("region out of bounds"); + } + int aLayer = SVTConstants.convertRegionModule2Layer(aRegion, aModule); + if (aSector < 0 || aSector > SVTConstants.NSECTORS[aRegion] - 1) { + throw new IllegalArgumentException("sector out of bounds"); + } + Vector3d pLab = pLoc.clone(); + + // transform to local frame + Transform stripFrame = SVTConstants.getStripFrame(false); + pLab.transform(stripFrame); + + // transform to detector frame + double r = SVTConstants.LAYERRADIUS[aRegion][aModule]; + double z = SVTConstants.Z0ACTIVE[aRegion]; + Transform labFrame = SVTConstants.getDetectorFrame(aRegion, aSector, r, z); + pLab.transform(labFrame); + + // transform to lab frame + AlignmentFactory.applyShift(pLab, SVTConstants.getLayerSectorAlignmentData()[aSector][aLayer], + labCenter, scaleT, scaleR); + + return pLab; + } /** diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 62964b492..55ebb5fdc 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -134,50 +134,53 @@ else if(mv.surface.cylinder!=null) { } else { if(mv.surface.plane!=null) { //Update B - double r0 = mv.surface.finitePlaneCorner1.toVector3D().dot(mv.surface.plane.normal()); - double stepSize = 5; //mm - int nSteps = (int) (r0/stepSize); - - double dist = 0; - - for(int i = 1; i if going smaller to larger rho + */ + public NewPlaneStopper(double[] u0, double s0, double sMax, Plane targetPlane, double accuracy) { + + + _s0 = s0; + _dim = u0.length; + + _uf = new double[_dim]; + copy(u0, _uf); + + _targetPlane = targetPlane; + _distance = _targetPlane.signedDistance(u0[0], u0[1], u0[2]); + _totS = 0; + _sMax = sMax; + _accuracy = accuracy; + _startSign = Math.signum(_distance); + } + + @Override + public boolean stopIntegration(double s, double[] unew) { + + //a negative distance means we are inside the cylinder + double newDist = _targetPlane.signedDistance(unew[0], unew[1], unew[2]); + double newSign = Math.signum(newDist); + newDist = Math.abs(newDist); + + // within accuracy? + if (newDist < _accuracy) { + _distance = newDist; + _totS = s; + copy(unew, _uf); + return true; + } + + //if we crossed the boundary (don't accept, reset) + _crossedBoundary = newSign != _startSign; + if (_crossedBoundary) { + return true; + } + + + _passedSmax = (s > _sMax); + //if exceeded max path length accept and stop + if (_passedSmax) { + _distance = newDist; + _totS = s; + copy(unew, _uf); + return true; + } + + + //accept and continue + _distance = newDist; + _totS = s; + copy(unew, _uf); + return false; + } + + //array copy for state vectors + private void copy(double src[], double[] dest) { + System.arraycopy(src, 0, dest, 0, _dim); + } + + /** + * Did we pas the max path length? + * @return true if we crossed the boundary + */ + public boolean passedSmax() { + return _passedSmax; + } + + + /** + * Did we cross the boundary + * @return true if we crossed the boundary + */ + public boolean crossedBoundary() { + return _crossedBoundary; + } + + /** + * Get the final path length in meters + * + * @return the final path length in meters + */ + @Override + public double getFinalT() { + return _s0 + _totS; + } + + @Override + public void setFinalT(double finalT) { + // Do nothing + } + + /** + * Get the final value of the state vector + * @return + */ + public double[] getFinalU() { + if (_uf == null) { + System.err.println("Returning null final u"); + } + return _uf; + } + + /** + * Generally this is the same as stop integration. So most will just return + * stopIntegration(). But sometimes stop just means we reset and integrate more. + * For example, with a fixed rho integrator we "stop" when we cross the rho boundary + * however we are not done unless we are within tolerance. If we are within + * tolerance (on either side) we are really done! + * + * @param t the current value of the independent variable (typically pathlength) + * @param y the current state vector (typically [x, y, z, vx, vy, vz]) + * @return true if we should stop now. + */ + @Override + public boolean terminateIntegration(double t, double y[]) { + System.err.println("Should not be called. Ever."); + System.exit(1); + return false; + } + +} diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java index 5cc6c4ca0..cc0fd919e 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swim/Swimmer.java @@ -4,6 +4,8 @@ import cnuphys.adaptiveSwim.AdaptiveSwimResult; import cnuphys.adaptiveSwim.geometry.Cylinder; +import cnuphys.adaptiveSwim.geometry.Point; +import cnuphys.adaptiveSwim.geometry.Vector; import cnuphys.lund.GeneratedParticleRecord; import cnuphys.magfield.FastMath; import cnuphys.magfield.FieldProbe; @@ -263,8 +265,8 @@ public void swimCylinder(int charge, double xo, double yo, double zo, double mom result.setFinalS(sFinal); } - - /** + + /** * Swims a particle with a built in stopper at the boundary of an * arbitrary cylinder. Uses a fixed stepsize algorithm. * @@ -669,7 +671,93 @@ public void swimRho(int charge, double xo, double yo, double zo, double momentum // } } + public void swimPlane(int charge, double xo, double yo, double zo, double momentum, double theta, double phi, + double normX, double normY, double normZ, double pointX, double pointY, double pointZ, + double accuracy, double sMax, double stepSize, double relTolerance[], AdaptiveSwimResult result) + throws RungeKuttaException { + + cnuphys.adaptiveSwim.geometry.Plane targetPlane = new cnuphys.adaptiveSwim.geometry.Plane(new Vector(normX,normY,normZ), new Point(pointX,pointY,pointZ)); +// System.out.println(targetPlane.toString()); + result.setInitialValues(charge, xo, yo, zo, momentum, theta, phi); + + // set u to the starting state vector + double thetaRad = Math.toRadians(theta); + double phiRad = Math.toRadians(phi); + double sinTheta = Math.sin(thetaRad); + + double px = sinTheta*Math.cos(phiRad); //px/p + double py = sinTheta*Math.sin(phiRad); //py/p + double pz = Math.cos(thetaRad); //pz/p + + double uf[] = result.getUf(); + uf[0] = xo; + uf[1] = yo; + uf[2] = zo; + uf[3] = px; + uf[4] = py; + uf[5] = pz; +// System.out.println(xo + " " +yo + " " + zo + " " + targetPlane.signedDistance(xo, yo, zo)); + if (momentum < MINMOMENTUM) { + System.err.println("Skipping low momentum fixed rho swim (A)"); + result.setNStep(0); + result.setFinalS(0); + result.setStatus(-2); + return; + } + + double del = Double.POSITIVE_INFINITY; + int maxtry = 25; + int count = 0; + double sFinal = 0; + int ns = 0; + + + while ((count < maxtry) && (del > accuracy)) { + + uf = result.getUf(); + if (count > 0) { + px = uf[3]; + py = uf[4]; + pz = uf[5]; + theta = FastMath.acos2Deg(pz); + phi = FastMath.atan2Deg(py, px); + } + + + NewPlaneStopper stopper = new NewPlaneStopper(uf, sFinal, sMax, targetPlane, accuracy); + + ns += swim(charge, uf[0], uf[1], uf[2], momentum, theta, phi, stopper, null, sMax-sFinal, stepSize, relTolerance, null); + + System.arraycopy(stopper.getFinalU(), 0, result.getUf(), 0, result.getUf().length); + + sFinal = stopper.getFinalT(); + + del = Math.abs(targetPlane.signedDistance(stopper.getFinalU()[0], stopper.getFinalU()[1], stopper.getFinalU()[2])); +// System.out.println(del + " " + stopper.getFinalU()[0] + " " + stopper.getFinalU()[1] + " " + stopper.getFinalU()[2]); + // succeed? + if (del < accuracy) { + break; + } + + // passed max path length? + if (stopper.passedSmax()) { + break; + } + + count++; + + if (stopper.crossedBoundary()) { + stepSize = Math.max(stepSize / 2, del / 5); + } + + } // while + + result.setNStep(ns); + result.setFinalS(sFinal); + + } + /** * Get the tolerance used by the CLAS_Toleance array * 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 19477e5aa..488f03847 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 @@ -555,6 +555,41 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r } return value; + } + + public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { + + double[] value = new double[8]; + + + // using adaptive stepsize + if(this.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); + + + 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) { + e.printStackTrace(); + } + return value; + } private class SphericalBoundarySwimStopper implements IStopper { @@ -722,7 +757,7 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { 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 diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 72c0f0611..e9d4584c0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -1,7 +1,10 @@ package org.jlab.rec.cvt; +import cnuphys.magfield.MagneticFields; import java.util.HashMap; import java.util.Map; +import org.jlab.clas.swimtools.Swim; +import org.jlab.rec.cvt.bmt.BMTConstants; public class Constants { @@ -9,13 +12,15 @@ public class Constants { /** - * Constants used in the reconstruction + * BMTConstants used in the reconstruction */ Constants() { } // CONSTANTS USED IN RECONSTRUCTION //--------------------------------- + public static boolean isMC = true; + public static final double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c // selection cuts for helical tracks @@ -275,13 +280,10 @@ public static synchronized void Load(boolean isCosmics, boolean isSVTonly) { if (areConstantsLoaded) { return; } - Constants.setCosmicsData(false); setSVTOnly(isSVTonly); - org.jlab.rec.cvt.bmt.Constants.Load(); - areConstantsLoaded = true; System.out.println("CVT constants loaded ? " + areConstantsLoaded); @@ -302,24 +304,15 @@ public static final boolean isSVTOnly() { public static final void setSVTOnly(boolean sVTOnly) { SVTOnly = sVTOnly; } - - private static double SOLENOIDSCALE = 0; - private static double SOLENOIDVAL = 0; - - public static final void setSolenoidscale(double scale) { - SOLENOIDSCALE = scale; - } - - public static final double getSolenoidscale() { - return SOLENOIDSCALE; - } - public static final void setSolenoidVal(double val) { - SOLENOIDVAL = val; + public static double getSolenoidMagnitude() { + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + return Math.abs(b[2]); } - public static final double getSolenoidVal() { - return SOLENOIDVAL; + public static double getSolenoidScale() { + return MagneticFields.getInstance().getScaleFactor(MagneticFields.FieldType.SOLENOID); } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index 9b1f40559..55182a131 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -11,6 +11,7 @@ import org.jlab.geometry.prim.Line3d; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.hit.ADCConvertor; @@ -123,7 +124,7 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo // hit.set_Status(-1); hit.set_Id(i+1); // add this hit - if(hit.get_Layer()+3!=org.jlab.rec.cvt.Constants.getRmReg()) + if(hit.get_Layer()+3!=Constants.getRmReg()) hits.add(hit); } // fills the list of BMT hits @@ -262,7 +263,7 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, hit.set_Id(id[i]); // add this hit - if(SvtStrip.get_Edep()>0 && hit.get_Region()!=org.jlab.rec.cvt.Constants.getRmReg()) + if(SvtStrip.get_Edep()>0 && hit.get_Region()!=Constants.getRmReg()) hits.add(hit); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 1e60d304c..5a9c29305 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -17,6 +17,7 @@ import Jama.Matrix; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; public class RecoBankWriter { @@ -409,8 +410,8 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh bank.setFloat("tandip", i, (float) helix.get_tandip()); bank.setFloat("z0", i, (float) (helix.get_Z0()/10.+zShift/10)); bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); - bank.setFloat("xb", i, (float) (org.jlab.rec.cvt.Constants.getXb()/10.0)); - bank.setFloat("yb", i, (float) (org.jlab.rec.cvt.Constants.getYb()/10.0)); + bank.setFloat("xb", i, (float) (Constants.getXb()/10.0)); + bank.setFloat("yb", i, (float) (Constants.getYb()/10.0)); // this is the format of the covariance matrix for helical tracks // cov matrix = // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java similarity index 89% rename from reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java rename to reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java index f903e3fb6..9ad7a7388 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java @@ -5,18 +5,17 @@ import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; -public class Constants { +public class BMTConstants { - private Constants() { + private BMTConstants() { } - public static boolean isMC = true; /* - * The algorithm to describe the geometry of the Barrel Micromegas is provided by Franck Sabatie and implemented into the Java framework. - * This version is for the last region of the BMT only. - CRC and CRZ characteristics localize strips in the cylindrical coordinate system. The target center is at the origin. The Z-axis is along the beam axis. - The angles are defined with theZ-axis oriented from the accelerator to the beam dump. + * The algorithm to describe the geometry of the Barrel Micromegas is provided by Franck Sabatie and implemented into the Java framework. + * This version is for the last region of the BMT only. + CRC and CRZ characteristics localize strips in the cylindrical coordinate system. The target center is at the origin. The Z-axis is along the beam axis. + The angles are defined with theZ-axis oriented from the accelerator to the beam dump. */ //CUTS public static double MAXCLUSSIZE = 5; @@ -113,37 +112,10 @@ private Constants() { public static final int STARTINGLAYR = 1; - public static synchronized void Load() { - if (areConstantsLoaded) { - return; - } - - //if (org.jlab.rec.cvt.Constants.isCosmicsData() == false) { - //setThetaL(Math.toRadians(20. * Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()))); // for 5-T field - //System.out.println(" LORENTZ ANGLE (radians) = "+getThetaL()); - //} - areConstantsLoaded = true; - - } - public static double getThetaL() { return ThetaL; } - public static synchronized void setThetaL(int layer, int sector) { - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.001) { - ThetaL = 0; - } - else { - if(Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale())<0.8) { - ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle(E_DRIFT_MF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); - } else { - ThetaL = Math.toRadians(org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle(E_DRIFT_FF[layer-1][sector-1],Math.abs(org.jlab.rec.cvt.Constants.getSolenoidscale()*50))); - } - } - if (org.jlab.rec.cvt.Constants.getSolenoidscale()<0) ThetaL=-ThetaL; - } - public static double[] getCRZRADIUS() { return CRZRADIUS; } @@ -213,7 +185,7 @@ public static double[][] getCRZPHI() { } public static void setCRZPHI(double[][] cRZPHI) { - Constants.CRZPHI = cRZPHI; + BMTConstants.CRZPHI = cRZPHI; } public static double[][] getCRZDPHI() { @@ -221,7 +193,7 @@ public static double[][] getCRZDPHI() { } public static void setCRZDPHI(double[][] cRZDPHI) { - Constants.CRZDPHI = cRZDPHI; + BMTConstants.CRZDPHI = cRZDPHI; } public static double[][] getCRZEDGE1() { @@ -357,7 +329,7 @@ public static double[][] getCRCPHI() { } public static void setCRCPHI(double[][] cRCPHI) { - Constants.CRCPHI = cRCPHI; + BMTConstants.CRCPHI = cRCPHI; } public static double[][] getCRCDPHI() { @@ -365,7 +337,7 @@ public static double[][] getCRCDPHI() { } public static void setCRCDPHI(double[][] cRCDPHI) { - Constants.CRCDPHI = cRCDPHI; + BMTConstants.CRCDPHI = cRCDPHI; } public static double[][] getCRCEDGE1() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 76249b6b9..2e1cacb87 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -10,8 +10,8 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.groot.data.H2F; import org.jlab.groot.group.DataGroup; -import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_FF; -import static org.jlab.rec.cvt.bmt.Constants.E_DRIFT_MF; +import static org.jlab.rec.cvt.bmt.BMTConstants.E_DRIFT_FF; +import static org.jlab.rec.cvt.bmt.BMTConstants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; import org.jlab.clas.swimtools.Swim; import org.jlab.geom.prim.Transformation3D; @@ -20,6 +20,7 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.cvt.Constants; /** * * @author devita @@ -38,7 +39,7 @@ public BMTGeometry() { } public int getNLayers() { - return Constants.NLAYERS; + return BMTConstants.NLAYERS; } /** @@ -68,7 +69,7 @@ public int getLayer(int region, BMTType detector) { * @return region (1-3) */ public int getRegion(int layer) { - if(!(layer>=1 && layer<=Constants.NLAYERS)) + if(!(layer>=1 && layer<=BMTConstants.NLAYERS)) throw new IllegalArgumentException("Error: invalid layer="+layer); return (int) Math.floor((layer+1)/2); @@ -81,7 +82,7 @@ public int getRegion(int layer) { * @return type ("C" or "Z"); */ public static BMTType getDetectorType(int layer) { - if(!(layer>=1 && layer<=Constants.NLAYERS)) + if(!(layer>=1 && layer<=BMTConstants.NLAYERS)) throw new IllegalArgumentException("Error: invalid layer="+layer); if(layer == lC[0] || layer == lC[1] || layer == lC[2]) return BMTType.C; @@ -99,8 +100,8 @@ public double getRadius(int layer) { int region = this.getRegion(layer); BMTType det = BMTGeometry.getDetectorType(layer); - if(det == BMTType.C) return Constants.getCRCRADIUS()[region-1]; - else return Constants.getCRZRADIUS()[region-1]; + if(det == BMTType.C) return BMTConstants.getCRCRADIUS()[region-1]; + else return BMTConstants.getCRZRADIUS()[region-1]; } /** @@ -109,7 +110,7 @@ public double getRadius(int layer) { * @return radius (=0 if layer is out of range) */ public double getRadiusMidDrift(int layer) { - return this.getRadius(layer) + Constants.hDrift/2; + return this.getRadius(layer) + BMTConstants.hDrift/2; } /** @@ -123,8 +124,8 @@ public int getNStrips(int layer) { BMTType det = BMTGeometry.getDetectorType(layer); int nstrips = 0; - if (det == BMTType.C) nstrips = Constants.getCRCNSTRIPS()[region-1]; - else if(det == BMTType.Z) nstrips = Constants.getCRZNSTRIPS()[region-1]; + if (det == BMTType.C) nstrips = BMTConstants.getCRCNSTRIPS()[region-1]; + else if(det == BMTType.Z) nstrips = BMTConstants.getCRZNSTRIPS()[region-1]; return nstrips; } @@ -154,11 +155,11 @@ public double getPitch(int layer, int strip) { private double getCPitch(int region, int strip) { if(!(region>=1 && region<=3)) throw new IllegalArgumentException("Error: invalid region="+region); - if(!(strip>=1 && strip<=Constants.getCRCNSTRIPS()[region-1])) + if(!(strip>=1 && strip<=BMTConstants.getCRCNSTRIPS()[region-1])) throw new IllegalArgumentException("Error: invalid strip="+strip); int group = this.getCGroup(region, strip); - double pitch = Constants.getCRCWIDTH()[region-1][group-1]; + double pitch = BMTConstants.getCRCWIDTH()[region-1][group-1]; return pitch; } @@ -171,10 +172,10 @@ private double getCPitch(int region, int strip) { private double getZPitch(int region, int strip) { if(!(region>=1 && region<=3)) throw new IllegalArgumentException("Error: invalid region="+region); - if(!(strip>=1 && strip<=Constants.getCRZNSTRIPS()[region-1])) + if(!(strip>=1 && strip<=BMTConstants.getCRZNSTRIPS()[region-1])) throw new IllegalArgumentException("Error: invalid strip="+strip); - return Constants.getCRZWIDTH()[region-1]; + return BMTConstants.getCRZWIDTH()[region-1]; } /** @@ -189,8 +190,8 @@ public double getZmin(int layer) { int region = this.getRegion(layer); BMTType det = BMTGeometry.getDetectorType(layer); - if (det == BMTType.C) z = Constants.getCRCZMIN()[region-1]; - else if(det == BMTType.Z) z = Constants.getCRZZMIN()[region-1]; + if (det == BMTType.C) z = BMTConstants.getCRCZMIN()[region-1]; + else if(det == BMTType.Z) z = BMTConstants.getCRZZMIN()[region-1]; return z; } @@ -206,8 +207,8 @@ public double getZmax(int layer) { int region = this.getRegion(layer); BMTType det = BMTGeometry.getDetectorType(layer); - if (det == BMTType.C) z = Constants.getCRCZMAX()[region-1]; - else if(det == BMTType.Z) z = Constants.getCRZZMAX()[region-1]; + if (det == BMTType.C) z = BMTConstants.getCRCZMAX()[region-1]; + else if(det == BMTType.Z) z = BMTConstants.getCRZZMAX()[region-1]; return z; } @@ -219,7 +220,7 @@ public double getZmax(int layer) { */ public double getPhi(int layer, int sector) { - if(!(00 && layer 0 && sector0 && layer 0 && sector strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - for(int j=0; j<5; j++) { - double z = Math.random()*(zmax-zmin)+zmin; - //double z = (1.0*j/500.0)*(zmax-zmin)+zmin; - //double z = oldGeo.CRCStrip_GetZ(i, j); - double phi = Math.random()*2*Math.PI; - //double phi = (1.0*j/500.0)*2*Math.PI; - //double phi = oldGeo.CRZStrip_GetPhi(3, i, j+1); - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nsect = newGeo.getSector(i, phi); - int nstrip = newGeo.getStrip(i,nsect,traj); - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z && nsect>0) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff = nstrip - ostrip; - System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + nsect + "\t" + nstrip + "/" + ostrip + "/" + diff); - } - } - - - System.out.println("\n\n Strip -> Trajectory -> strip check: new/old strip numbers");; - System.out.println("\tLayer\tz (mm)\t\tphi (deg)\tsector\tnew/old/comp strip numbers"); - boolean check = true; - for(int i=1; i<=Constants.NLAYERS; i++) { - double radius = newGeo.getRadius(i); - double zmin = newGeo.getZmin(i); - double zmax = newGeo.getZmax(i); - int nstrips = newGeo.getNStrips(i); - int region = newGeo.getRegion(i); - for(int k=1; k<=Constants.NSECTORS; k++) { - double phmin = Constants.getCRCPHI()[region-1][k-1]-Constants.getCRCDPHI()[region-1][k-1]; - double phmax = Constants.getCRCPHI()[region-1][k-1]+Constants.getCRCDPHI()[region-1][k-1]; - for(int j=1; j<=nstrips; j++) { - - double z = Math.random()*(zmax-zmin)+zmin; - if(newGeo.getDetectorType(i)==BMTType.C) z = oldGeo.CRCStrip_GetZ(i, j); - - double phi = Math.random()*(phmax-phmin)+phmin; - if(newGeo.getDetectorType(i)==BMTType.Z) { - phi = oldGeo.CRZStrip_GetPhi(k, i, j); - } - - Point3D traj = new Point3D(radius*Math.cos(phi),radius*Math.sin(phi),z); - int nstrip = newGeo.getStrip(i,k,traj); - - int ostrip = -1; - if (newGeo.getDetectorType(i)==BMTType.C) ostrip = oldGeo.getCStrip(i, z); - else if(newGeo.getDetectorType(i)==BMTType.Z) ostrip = oldGeo.getZStrip(i, phi); - int diff = -1; - if(nstrip>0 && ostrip>0) diff=nstrip-ostrip; - if(nstrip!=j) check=false; - if(diff!=0 || !check) System.out.println("\t" + i + "\t" + String.format("%8.4f",z) + "\t" + String.format("%8.4f", Math.toDegrees(phi)) + "\t" + k + "\t" - + j + "/" + nstrip + "/" + ostrip + "/" + diff + "\t" + newGeo.getPitch(i, j)); - } - } - } - System.out.println("Check: " + check); - - System.out.println("\nPlotting acceptance"); DataGroup acceptance = new DataGroup(3,2); - for(int i=1; i<=Constants.NLAYERS; i++) { + for(int i=1; i<=BMTConstants.NLAYERS; i++) { double radius = newGeo.getRadius(i); double zmin = newGeo.getZmin(i); double zmax = newGeo.getZmax(i); @@ -1206,13 +1075,13 @@ public static void main (String arg[]) { // double angle_i = 0; // first angular boundary init // double angle_f = 0; // second angular boundary for detector A, B, or C init // int num_detector = 2; -// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// //double jitter = Math.toRadians(BMTConstants.isInSectorJitter); // for (int i = 0; i < 3; i++) { // -// //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; -// //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; -// angle_i = Constants.getCRCEDGE1()[num_region][i]; -// angle_f = Constants.getCRCEDGE2()[num_region][i]; +// //angle_i=BMTConstants.getCRCEDGE1()[num_region][i]+BMTConstants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; +// //angle_f=BMTConstants.getCRCEDGE1()[num_region][i]+(BMTConstants.getCRCXPOS()[num_region]+BMTConstants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; +// angle_i = BMTConstants.getCRCEDGE1()[num_region][i]; +// angle_f = BMTConstants.getCRCEDGE2()[num_region][i]; // if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { // num_detector = i; // } @@ -1221,7 +1090,7 @@ public static void main (String arg[]) { // return num_detector; // } // public int isInSector(int layer, double angle, double jitter) { -// //double jitter = Math.toRadians(Constants.isInSectorJitter); +// //double jitter = Math.toRadians(BMTConstants.isInSectorJitter); // int value = -1; // int num_det = this.isInDetector(layer, angle, jitter); // /* if(num_det == 0) @@ -1248,19 +1117,19 @@ public static void main (String arg[]) { // // //For CR6C, this function returns the Z position of the strip center // int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; -// double zc = Constants.getCRCZMIN()[num_region]; +// int limit = BMTConstants.getCRCGROUP()[num_region][group]; +// double zc = BMTConstants.getCRCZMIN()[num_region]; // // if (num_strip > 0) { // for (int j = 1; j < num_strip + 1; j++) { -// zc += Constants.getCRCWIDTH()[num_region][group]; +// zc += BMTConstants.getCRCWIDTH()[num_region][group]; // if (j >= limit) { //test if we change the width // group++; -// limit += Constants.getCRCGROUP()[num_region][group]; +// limit += BMTConstants.getCRCGROUP()[num_region][group]; // } // } // } -// zc += Constants.getCRCWIDTH()[num_region][group]/2.; +// zc += BMTConstants.getCRCWIDTH()[num_region][group]/2.; // return zc; //in mm // } @@ -1271,19 +1140,19 @@ public static void main (String arg[]) { // // //For CR6C, this function returns the Z position of the strip center // int group = 0; -// int limit = Constants.getCRCGROUP()[num_region][group]; +// int limit = BMTConstants.getCRCGROUP()[num_region][group]; // // if (num_strip > 0) { // for (int j = 1; j < num_strip + 1; j++) { // // if (j >= limit) { //test if we change the width // group++; -// limit += Constants.getCRCGROUP()[num_region][group]; +// limit += BMTConstants.getCRCGROUP()[num_region][group]; // } // } // } // -// return Constants.getCRCWIDTH()[num_region][group]; // +// return BMTConstants.getCRCWIDTH()[num_region][group]; // // } // /** @@ -1293,7 +1162,7 @@ public static void main (String arg[]) { // * @return the Z strip as a function of azimuthal angle // */ // public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle -// double jitter = Math.toRadians(Constants.isInSectorJitter); +// double jitter = Math.toRadians(BMTConstants.isInSectorJitter); // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 // int num_detector = isInDetector(layer, angle, jitter); // if (num_detector == -1) { @@ -1304,21 +1173,21 @@ public static void main (String arg[]) { // angle += 2 * Math.PI; // from 0 to 2Pi // } // if (num_detector == 1) { -// double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; +// double angle_f = BMTConstants.getCRCEDGE1()[num_region][1] + (BMTConstants.getCRCXPOS()[num_region] + BMTConstants.getCRCLENGTH()[num_region]) / BMTConstants.getCRCRADIUS()[num_region] - 2 * Math.PI; // if (angle >= 0 && angle <= angle_f) { // angle += 2 * Math.PI; // } // } -// //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); -// //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); -// double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; +// //double strip_calc = ( (angle-BMTConstants.getCRZEDGE1()[num_region][num_detector])*BMTConstants.getCRZRADIUS()[num_region]-BMTConstants.getCRZXPOS()[num_region]-BMTConstants.getCRZWIDTH()[num_region]/2.)/(BMTConstants.getCRZWIDTH()[num_region]+BMTConstants.getCRZSPACING()[num_region]); +// //double strip_calc = ((angle - BMTConstants.getCRZEDGE1()[num_region][num_detector]) * BMTConstants.getCRZRADIUS()[num_region]) / (BMTConstants.getCRZWIDTH()[num_region]); +// double strip_calc = ((angle - BMTConstants.getCRZEDGE1()[num_region][num_detector]) * BMTConstants.getCRZRADIUS()[num_region]) / (BMTConstants.getCRZWIDTH()[num_region])-0.5; // strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); // int strip_num = (int) Math.floor(strip_calc); // // int value = strip_num + 1; // //int value = strip_num; // -// if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { +// if (value < 1 || value > BMTConstants.getCRZNSTRIPS()[num_region]) { // value = -1; // } // @@ -1326,7 +1195,7 @@ public static void main (String arg[]) { // } // public void setLorentzAngle(int layer, int sector) { -// org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); +// BMTConstants.setThetaL(layer, sector); // } //// // Correct strip position before clustering //// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { @@ -1339,9 +1208,9 @@ public static void main (String arg[]) { // public double LorentzAngleCorr(double phi, int layer) { // // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; -// //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); -// return phi + (Constants.hStrip2Det * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); +// //return phi +( BMTConstants.hDrift/2*Math.tan(BMTConstants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; +// //return phi + (BMTConstants.hDrift * Math.tan(BMTConstants.getThetaL())) / (BMTConstants.getCRZRADIUS()[num_region]); +// return phi + (BMTConstants.hStrip2Det * Math.tan(BMTConstants.getThetaL())) / (BMTConstants.getCRZRADIUS()[num_region]); // } // // /** @@ -1357,18 +1226,18 @@ public static void main (String arg[]) { // // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; // -// double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit -// double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit +// double z_i = CRZ_GetZStrip(layer) - BMTConstants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit +// double z_f = CRZ_GetZStrip(layer) + BMTConstants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit // // double R_i = 0; // inner radius init // double R_f = 0; // outer radius init for a C or Z detector // if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { -// R_i = Constants.getCRZRADIUS()[num_region]; // Z layer +// R_i = BMTConstants.getCRZRADIUS()[num_region]; // Z layer // } // if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { -// R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors +// R_i = BMTConstants.getCRCRADIUS()[num_region]; // // C-dtectors // } -// R_f = R_i + Constants.hDrift; +// R_f = R_i + BMTConstants.hDrift; // // double angle_i = 0; // first angular boundary init // double angle_f = 0; // second angular boundary for detector A, B, or C init @@ -1408,7 +1277,7 @@ public static void main (String arg[]) { // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 // // //For CRC, this function returns the angle to localize the beginning of the strips -// double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// double angle = BMTConstants.getCRCEDGE1()[num_region][num_detector] + BMTConstants.getCRCXPOS()[num_region] / BMTConstants.getCRCRADIUS()[num_region]; // if (angle > 2 * Math.PI) { // angle -= 2 * Math.PI; // } @@ -1429,7 +1298,7 @@ public static void main (String arg[]) { // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 // // //For CRC, this function returns the angle to localize the end of the strips -// double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; +// double angle = BMTConstants.getCRCEDGE2()[num_region][num_detector] + BMTConstants.getCRCXPOS()[num_region] / BMTConstants.getCRCRADIUS()[num_region]; // if (angle > 2 * Math.PI) { // angle -= 2 * Math.PI; // } @@ -1456,8 +1325,8 @@ public static void main (String arg[]) { // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 // double angle_i = 0; // first angular boundary init // double angle_f = 0; // second angular boundary for detector A, B, or C init -// angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; -// angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; +// angle_i = BMTConstants.getCRCEDGE1()[num_region][sector-1]; +// angle_f = BMTConstants.getCRCEDGE2()[num_region][sector-1]; // // // if (angle < 0) { @@ -1495,30 +1364,30 @@ public static void main (String arg[]) { // int strip_group = 0; // int ClosestStrip = -1; // // get group -// int len = Constants.getCRCGROUP()[num_region].length; +// int len = BMTConstants.getCRCGROUP()[num_region].length; // double[] Z_lowBound = new double[len]; // double[] Z_uppBound = new double[len]; // int[] NStrips = new int[len]; // -// double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; +// double zi = BMTConstants.getCRCZMIN()[num_region] + BMTConstants.getCRCOFFSET()[num_region]; // double z = trk_z - zi; // // for (int i = 0; i < len; i++) { // if(i==0) { // Z_lowBound[i] = 0; -// NStrips[i] = Constants.getCRCGROUP()[num_region][i]; +// NStrips[i] = BMTConstants.getCRCGROUP()[num_region][i]; // } // else { // Z_lowBound[i] = Z_uppBound[i - 1]; -// NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; +// NStrips[i] = NStrips[i - 1] + BMTConstants.getCRCGROUP()[num_region][i]; // } -// Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; +// Z_uppBound[i] = Z_lowBound[i] + BMTConstants.getCRCGROUP()[num_region][i] * BMTConstants.getCRCWIDTH()[num_region][i]; // // if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { // strip_group = i; -// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); +// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / BMTConstants.getCRCWIDTH()[num_region][strip_group]); // if(i>0) ClosestStrip += NStrips[i - 1]; -// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; +// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(BMTConstants.getCRCWIDTH()[num_region][strip_group] + BMTConstants.getCRCSPACING()[num_region]))))+NStrips[i-1]; // // len = i; // } @@ -1536,15 +1405,15 @@ public static void main (String arg[]) { // // double R = 0; // if (axis == 0) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[num_region]; +// R = BMTConstants.getCRCRADIUS()[num_region]; // } // if (axis == 1) { -// R = org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[num_region]; +// R = BMTConstants.getCRZRADIUS()[num_region]; // } // -// double CRZLENGTH = org.jlab.rec.cvt.bmt.Constants.getCRCLENGTH()[num_region]; -// double CRZZMIN = org.jlab.rec.cvt.bmt.Constants.getCRZZMIN()[num_region]; -// double CRZOFFSET = org.jlab.rec.cvt.bmt.Constants.getCRZOFFSET()[num_region]; +// double CRZLENGTH = BMTConstants.getCRCLENGTH()[num_region]; +// double CRZZMIN = BMTConstants.getCRZZMIN()[num_region]; +// double CRZOFFSET = BMTConstants.getCRZOFFSET()[num_region]; // // double z_min = CRZZMIN + CRZOFFSET; // double z_max = z_min + CRZLENGTH; @@ -1565,7 +1434,7 @@ public static void main (String arg[]) { // private double CRZ_GetZStrip(int layer) { // int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 // //For CRZ, this function returns the Z position of the strip center -// double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; +// double zc = BMTConstants.getCRZZMIN()[num_region] + BMTConstants.getCRZOFFSET()[num_region] + BMTConstants.getCRZLENGTH()[num_region] / 2.; // return zc; //in mm // } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 612de09c9..05c2c99f0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -5,6 +5,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.Constants; /** * @@ -26,9 +27,9 @@ public CCDBConstantsLoader() { public static final synchronized void Load(DatabaseConstantProvider dbprovider) { // initialize the constants //Z detector characteristics - int NREGIONS = Constants.NREGIONS; - int NSECTORS = Constants.NSECTORS; - int NLAYERS = Constants.NLAYERS; + int NREGIONS = BMTConstants.NREGIONS; + int NSECTORS = BMTConstants.NSECTORS; + int NLAYERS = BMTConstants.NLAYERS; double[] CRZRADIUS = new double[NREGIONS]; // the radius of the Z detector in mm int[] CRZNSTRIPS = new int[NREGIONS]; // the number of strips double[] CRZSPACING = new double[NREGIONS]; // the strip spacing in mm @@ -120,7 +121,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) // System.out.println(" ................READ TARGET SHIFT "+ztarget+" cm......."); // dbprovider.show(); - // Getting the Constants + // Getting the BMTConstants // 1) pitch info int[] C_Layers = {1, 4, 6}; for (int j = 0; j < NREGIONS; j++) { @@ -154,7 +155,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) CRZWIDTH[1] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L3/Pitch", 0); CRZWIDTH[2] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L5/Pitch", 0); - // Getting the Constants + // Getting the BMTConstants // 2) Layer info for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_layer_noshim/Layer"); i++) { @@ -325,11 +326,11 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) transform.translateXYZ(shift.x(), shift.y(), shift.z()); Line3D axis = new Line3D(new Point3D(0,0,Zmin), new Vector3D(0,0,Zmax)); transform.apply(axis); - Constants.shifts[layer-1][sector-1] = shift; - Constants.rotations[layer-1][sector-1] = rot; - Constants.axes[layer-1][sector-1] = axis; - Constants.toGlobal[layer-1][sector-1] = transform; - Constants.toLocal[layer-1][sector-1] = transform.inverse(); + BMTConstants.shifts[layer-1][sector-1] = shift; + BMTConstants.rotations[layer-1][sector-1] = rot; + BMTConstants.axes[layer-1][sector-1] = axis; + BMTConstants.toGlobal[layer-1][sector-1] = transform; + BMTConstants.toLocal[layer-1][sector-1] = transform.inverse(); } @@ -341,50 +342,50 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double err = 0; if(Math.sqrt(xb*xb+yb*yb)!=0) err = Math.sqrt((Math.pow(xb*exb,2)+Math.pow(yb*eyb,2))/(xb*xb+yb*yb)); - org.jlab.rec.cvt.Constants.setXb(xb*10); - org.jlab.rec.cvt.Constants.setYb(yb*10); - org.jlab.rec.cvt.Constants.setRbErr(err*10); + Constants.setXb(xb*10); + Constants.setYb(yb*10); + Constants.setRbErr(err*10); System.out.println(" ................READ BEAM OFFSET PARAMETERS "+xb+" & "+yb+" cm......."); // target position mm - org.jlab.rec.cvt.Constants.setZoffset(ztarget*10); + Constants.setZoffset(ztarget*10); - Constants.setCRCRADIUS(CRCRADIUS); - Constants.setCRZRADIUS(CRZRADIUS); - Constants.setCRZNSTRIPS(CRZNSTRIPS); - Constants.setCRZZMIN(CRZZMIN); - Constants.setCRZZMAX(CRZZMAX); - Constants.setCRZLENGTH(CRZLENGTH); - Constants.setCRZSPACING(CRZSPACING); - Constants.setCRZPHI(CRZPHI); - Constants.setCRZDPHI(CRZDPHI); - Constants.setCRZEDGE1(CRZEDGE1); - Constants.setCRZEDGE2(CRZEDGE2); - Constants.setCRCRADIUS(CRCRADIUS); - Constants.setCRCNSTRIPS(CRCNSTRIPS); - Constants.setCRCZMIN(CRCZMIN); - Constants.setCRCZMAX(CRCZMAX); - Constants.setCRCLENGTH(CRCLENGTH); - Constants.setCRCSPACING(CRCSPACING); - Constants.setCRCPHI(CRCPHI); - Constants.setCRCDPHI(CRCDPHI); - Constants.setCRCEDGE1(CRCEDGE1); - Constants.setCRCEDGE2(CRCEDGE2); - Constants.setCRCGROUP(CRCGROUP); - Constants.setCRCWIDTH(CRCWIDTH); - Constants.setCRCGRPZMIN(CRCGRPZMIN); - Constants.setCRCGRPZMAX(CRCGRPZMAX); - Constants.setCRCGRPNMIN(CRCGRPNMIN); - Constants.setCRCGRPNMAX(CRCGRPNMAX); - Constants.setCRZWIDTH(CRZWIDTH); - Constants.setEFF_Z_OVER_A(EFF_Z_OVER_A); - Constants.set_T_OVER_X0(T_OVER_X0); - Constants.setTHETAL_grid(THETA_L_grid); - Constants.setE_grid(ELEC_grid); - Constants.setB_grid(MAG_grid); - Constants.setPar_grid(); - Constants.setE_drift_FF(HV_DRIFT_FF); - Constants.setE_drift_MF(HV_DRIFT_MF); + BMTConstants.setCRCRADIUS(CRCRADIUS); + BMTConstants.setCRZRADIUS(CRZRADIUS); + BMTConstants.setCRZNSTRIPS(CRZNSTRIPS); + BMTConstants.setCRZZMIN(CRZZMIN); + BMTConstants.setCRZZMAX(CRZZMAX); + BMTConstants.setCRZLENGTH(CRZLENGTH); + BMTConstants.setCRZSPACING(CRZSPACING); + BMTConstants.setCRZPHI(CRZPHI); + BMTConstants.setCRZDPHI(CRZDPHI); + BMTConstants.setCRZEDGE1(CRZEDGE1); + BMTConstants.setCRZEDGE2(CRZEDGE2); + BMTConstants.setCRCRADIUS(CRCRADIUS); + BMTConstants.setCRCNSTRIPS(CRCNSTRIPS); + BMTConstants.setCRCZMIN(CRCZMIN); + BMTConstants.setCRCZMAX(CRCZMAX); + BMTConstants.setCRCLENGTH(CRCLENGTH); + BMTConstants.setCRCSPACING(CRCSPACING); + BMTConstants.setCRCPHI(CRCPHI); + BMTConstants.setCRCDPHI(CRCDPHI); + BMTConstants.setCRCEDGE1(CRCEDGE1); + BMTConstants.setCRCEDGE2(CRCEDGE2); + BMTConstants.setCRCGROUP(CRCGROUP); + BMTConstants.setCRCWIDTH(CRCWIDTH); + BMTConstants.setCRCGRPZMIN(CRCGRPZMIN); + BMTConstants.setCRCGRPZMAX(CRCGRPZMAX); + BMTConstants.setCRCGRPNMIN(CRCGRPNMIN); + BMTConstants.setCRCGRPNMAX(CRCGRPNMAX); + BMTConstants.setCRZWIDTH(CRZWIDTH); + BMTConstants.setEFF_Z_OVER_A(EFF_Z_OVER_A); + BMTConstants.set_T_OVER_X0(T_OVER_X0); + BMTConstants.setTHETAL_grid(THETA_L_grid); + BMTConstants.setE_grid(ELEC_grid); + BMTConstants.setB_grid(MAG_grid); + BMTConstants.setPar_grid(); + BMTConstants.setE_drift_FF(HV_DRIFT_FF); + BMTConstants.setE_drift_MF(HV_DRIFT_MF); dbprovider.disconnect(); CSTLOADED = true; System.out diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java index e2fd5fe63..e353afa8b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/Lorentz.java @@ -16,20 +16,20 @@ public static double getLorentzAngle(double xe, double xb) { if (xe == 0 || xb == 0) { return 0; } - double de = (Constants.emax - Constants.emin) / (Constants.Ne - 1); - double db = (Constants.bmax - Constants.bmin) / (Constants.Nb - 1); + double de = (BMTConstants.emax - BMTConstants.emin) / (BMTConstants.Ne - 1); + double db = (BMTConstants.bmax - BMTConstants.bmin) / (BMTConstants.Nb - 1); - if (xe < Constants.emin) { - xe = Constants.emin; + if (xe < BMTConstants.emin) { + xe = BMTConstants.emin; System.err.println("Warning: E out of grid... setting it to Emin"); } - if (xe >= Constants.emax) { - xe = Constants.emax; + if (xe >= BMTConstants.emax) { + xe = BMTConstants.emax; System.err.println("Warning: E out of grid... setting it to Emax"); } - if (xb > Constants.bmax) { - xb = Constants.bmax; - //System.err.println("Warning: B field out of grid... setting it to Bmax = "+Constants.bmax); + if (xb > BMTConstants.bmax) { + xb = BMTConstants.bmax; + //System.err.println("Warning: B field out of grid... setting it to Bmax = "+BMTConstants.bmax); } int i11 = getBin(xe, xb); @@ -41,28 +41,28 @@ public static double getLorentzAngle(double xe, double xb) { double Q12 = 0; double Q21 = 0; double Q22 = 0; - double e1 = Constants.emin; - double e2 = Constants.emax; + double e1 = BMTConstants.emin; + double e2 = BMTConstants.emax; double b1 = 0; // RDV check if it should be 0 or bmin - double b2 = Constants.bmax; + double b2 = BMTConstants.bmax; if (i11 >= 0) { - Q11 = Constants.ThetaL_grid[i11]; - e1 = Constants.E_grid[i11]; - b1 = Constants.B_grid[i11]; + Q11 = BMTConstants.ThetaL_grid[i11]; + e1 = BMTConstants.E_grid[i11]; + b1 = BMTConstants.B_grid[i11]; } if (i12 >= 0) { - Q12 = Constants.ThetaL_grid[i12]; + Q12 = BMTConstants.ThetaL_grid[i12]; } - if (xb >= Constants.bmin) { - Q21 = Constants.ThetaL_grid[i21]; + if (xb >= BMTConstants.bmin) { + Q21 = BMTConstants.ThetaL_grid[i21]; } - if (xb < Constants.bmin) { + if (xb < BMTConstants.bmin) { Q21 = 0; } if (i22 >= 0) { - Q22 = Constants.ThetaL_grid[i22]; - e2 = Constants.E_grid[i22]; - b2 = Constants.B_grid[i22]; + Q22 = BMTConstants.ThetaL_grid[i22]; + e2 = BMTConstants.E_grid[i22]; + b2 = BMTConstants.B_grid[i22]; } double R1 = linInterp(xe, e1, e2, Q11, Q21); @@ -84,12 +84,12 @@ public static double linInterp(double x0, double xa, double xb, double ya, doubl public static int getBin(double e, double b) { - double de = (Constants.emax - Constants.emin) / (Constants.Ne - 1); - double db = (Constants.bmax - Constants.bmin) / (Constants.Nb - 1); + double de = (BMTConstants.emax - BMTConstants.emin) / (BMTConstants.Ne - 1); + double db = (BMTConstants.bmax - BMTConstants.bmin) / (BMTConstants.Nb - 1); - int ie = (int) Math.floor((e - Constants.emin) / de); - int ib = (int) Math.floor((b - Constants.bmin) / db); + int ie = (int) Math.floor((e - BMTConstants.emin) / de); + int ib = (int) Math.floor((b - BMTConstants.bmin) / db); - return ib + Constants.Nb * ie; + return ib + BMTConstants.Nb * ie; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java deleted file mode 100644 index f3541f760..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/OldGeometry.java +++ /dev/null @@ -1,670 +0,0 @@ -package org.jlab.rec.cvt.bmt; - -import java.util.Random; - -public class OldGeometry { - - public OldGeometry() { - - } - - // Comments on the OldGeometry of the BMT - //------------------------------------ - // The BMT geometry consists of 3 cylindical double layers of MicroMegas. - // The inner (i.e. closest to beam in double layer) layer contain longitudinal strips oriented in the Z direction. - // This is called the Z layer. - // The outer layer contain arched strips at a non-constant pitch in Z. This is called the C layer. - // The cylinder phi profile in divided into 3 sectors, A, B, C. - // - /** - * - * @param sector - * @return detector index A (=0), B (=1), C (=2) - */ - public int getDetectorIndex(int sector) { - int DetIdx = -1; - - DetIdx = sector - 1; - return DetIdx; - } - - // Return the layer number 1..6, given the region 1..3 and the detector type "C" or "Z" - public int getLayer( int region, String detType ) { - int layer = -1; - int[] lZ = { 2, 3, 5}; - int[] lC = { 1, 4, 6}; - if( detType.equalsIgnoreCase("Z") ) { - layer = lZ[ region - 1 ]; - } - if( detType.equalsIgnoreCase("C") ) { - layer = lC[ region - 1 ]; - } - return layer; - } - - /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @param strip the strip number (starts at 1) - * @return the angle to localize the center of strip - */ - public double CRZStrip_GetPhi(int sector, int layer, int strip) { - - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - //For CRZ, this function returns the angle to localize the center of strip "num_strip" for the "num_detector" - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(Constants.getCRZXPOS()[num_region]+(Constants.getCRZWIDTH()[num_region]/2.+num_strip*(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region])))/Constants.getCRZRADIUS()[num_region]; - //double angle=Constants.getCRZEDGE1()[num_region][num_detector]+(0.5+num_strip)*Constants.getCRZWIDTH()[num_region]/Constants.getCRZRADIUS()[num_region]; - //double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - double angle = Constants.getCRZEDGE1()[num_region][num_detector] + ((double) num_strip+0.5) * Constants.getCRZWIDTH()[num_region] / Constants.getCRZRADIUS()[num_region]; - return angle; //in rad - } - - - /** - * - * @param layer the layer 1...6 - * @param angle the position angle of the hit in the Z detector - * @return the Z strip as a function of azimuthal angle - */ - public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle - double jitter = Math.toRadians(Constants.isInSectorJitter); - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int num_detector = isInDetector(layer, angle, jitter); - if (num_detector == -1) { - return -1; - } - - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - if (num_detector == 1) { - double angle_f = Constants.getCRCEDGE1()[num_region][1] + (Constants.getCRCXPOS()[num_region] + Constants.getCRCLENGTH()[num_region]) / Constants.getCRCRADIUS()[num_region] - 2 * Math.PI; - if (angle >= 0 && angle <= angle_f) { - angle += 2 * Math.PI; - } - } - //double strip_calc = ( (angle-Constants.getCRZEDGE1()[num_region][num_detector])*Constants.getCRZRADIUS()[num_region]-Constants.getCRZXPOS()[num_region]-Constants.getCRZWIDTH()[num_region]/2.)/(Constants.getCRZWIDTH()[num_region]+Constants.getCRZSPACING()[num_region]); - //double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region]); - double strip_calc = ((angle - Constants.getCRZEDGE1()[num_region][num_detector]) * Constants.getCRZRADIUS()[num_region]) / (Constants.getCRZWIDTH()[num_region])-0.5; - strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); - int strip_num = (int) Math.floor(strip_calc); - - int value = strip_num + 1; - //int value = strip_num; - - if (value < 1 || value > Constants.getCRZNSTRIPS()[num_region]) { - value = -1; - } - - return value; - } - - /** - * - * @param layer the layer 1...6 - * @return the Z position of the strip center - */ - private double CRZ_GetZStrip(int layer) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //For CRZ, this function returns the Z position of the strip center - double zc = Constants.getCRZZMIN()[num_region] + Constants.getCRZOFFSET()[num_region] + Constants.getCRZLENGTH()[num_region] / 2.; - return zc; //in mm - } - - /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the beginning of the strips - */ - public double CRC_GetBeginStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the beginning of the strips - double angle = Constants.getCRCEDGE1()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; //in rad - } - - /** - * - * @param sector the sector in CLAS12 1...3 - * @param layer the layer 1...6 - * @return the angle to localize the end of the strips - */ - public double CRC_GetEndStrip(int sector, int layer) { - // Sector = num_detector + 1; - // num_detector = 0 (region A), 1 (region B), 2, (region C) - - int num_detector = this.getDetectorIndex(sector); // index of the detector (0...2) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CRC, this function returns the angle to localize the end of the strips - double angle = Constants.getCRCEDGE2()[num_region][num_detector] + Constants.getCRCXPOS()[num_region] / Constants.getCRCRADIUS()[num_region]; - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; //in rad - } - - /** - * - * @param layer the hit layer - * @param strip the hit strip - * @return the z position in mm for the C-detectors - */ - public double CRCStrip_GetZ(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center - int group = 0; - int limit = Constants.getCRCGROUP()[num_region][group]; - double zc = Constants.getCRCZMIN()[num_region]; - - if (num_strip > 0) { - for (int j = 1; j < num_strip + 1; j++) { - zc += Constants.getCRCWIDTH()[num_region][group]; - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } - } - } - zc += Constants.getCRCWIDTH()[num_region][group]/2.; - return zc; //in mm - } - - public double CRCStrip_GetPitch(int layer, int strip) { - - int num_strip = strip - 1; // index of the strip (starts at 0) - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - - //For CR6C, this function returns the Z position of the strip center - int group = 0; - int limit = Constants.getCRCGROUP()[num_region][group]; - - if (num_strip > 0) { - for (int j = 1; j < num_strip + 1; j++) { - - if (j >= limit) { //test if we change the width - group++; - limit += Constants.getCRCGROUP()[num_region][group]; - } - } - } - - return Constants.getCRCWIDTH()[num_region][group]; // - } - - /** - * - * @param layer - * @param trk_z the track z position of intersection with the C-detector - * @return the C-strip - */ - public int getCStrip(int layer, double trk_z) { - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int strip_group = 0; - int ClosestStrip = -1; - // get group - int len = Constants.getCRCGROUP()[num_region].length; - double[] Z_lowBound = new double[len]; - double[] Z_uppBound = new double[len]; - int[] NStrips = new int[len]; - - double zi = Constants.getCRCZMIN()[num_region] + Constants.getCRCOFFSET()[num_region]; - double z = trk_z - zi; - - for (int i = 0; i < len; i++) { - if(i==0) { - Z_lowBound[i] = 0; - NStrips[i] = Constants.getCRCGROUP()[num_region][i]; - } - else { - Z_lowBound[i] = Z_uppBound[i - 1]; - NStrips[i] = NStrips[i - 1] + Constants.getCRCGROUP()[num_region][i]; - } - Z_uppBound[i] = Z_lowBound[i] + Constants.getCRCGROUP()[num_region][i] * Constants.getCRCWIDTH()[num_region][i]; - - if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { - strip_group = i; - ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / Constants.getCRCWIDTH()[num_region][strip_group]); - if(i>0) ClosestStrip += NStrips[i - 1]; - //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.getCRCWIDTH()[num_region][strip_group] + Constants.getCRCSPACING()[num_region]))))+NStrips[i-1]; - - len = i; - } - } - return ClosestStrip; - } - - /** - * - * @param layer - * @param x x-coordinate of the hit in the lab frame - * @param y y-coordinate of the hit in the lab frame - * @return the sigma along the beam direction (longitudinal) - */ - public double getSigmaLongit(int layer, double x, double y) { // sigma for C-detector - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRCRADIUS()[num_region] + Constants.hStrip2Det) / Constants.hDrift); - double sigma = Constants.SigmaDrift * ((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hDrift/2) / Constants.hDrift / Math.cos(Constants.getThetaL())); - - return sigma; - - } - - /** - * - * @param layer - * @param x x-coordinate of the hit in the lab frame - * @param y y-coordinate of the hit in the lab frame - * @return the sigma along in the azimuth direction taking the Lorentz angle - * into account - */ - public double getSigmaAzimuth(int layer, double x, double y) { // sigma for Z-detectors - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6double Z0=0; - double sigma = Constants.SigmaDrift * Math.sqrt((Math.sqrt(x * x + y * y) - Constants.getCRZRADIUS()[num_region] + Constants.hDrift/2) / Constants.hDrift / Math.cos(Constants.getThetaL())); - - return sigma; - - } - - /** - * - * @param layer - * @param x x-coordinate of the hit in the lab frame - * @param y y-coordinate of the hit in the lab frame - * @param z z-coordinate of the hit in the lab frame - * @return X[] = the smeared position x = X[0], y = X[1], z = X[2] taking - * the Lorentz angle into account - */ - /* - public double[] smearedPosition(int layer, double x, double y, double z) { - - double[] newPos = new double[3]; - Random rand = new Random(); - - int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; - - double sigma =0; - if(layer%2==0) if(Double.isNaN(z)) {// C layer - sigma = getSigmaLongit(layer, x, y); // longitudinal shower profile - // changes z - z = this.randomGaus(z, sigma, rand); - } - - if(layer%2==1) {// Z layer - sigma = getSigmaAzimuth(layer, x, y); // azimuth shower profile taking into account the Lorentz angle - // changes phi - double phicorr = (this.randomGaus(0, sigma, rand)/Math.cos(Constants.getThetaL()) - -(Math.sqrt(x*x+y*y)-Constants.getCRZRADIUS()[num_region]+ - Constants.hStrip2Det)*Math.tan(Constants.getThetaL()))/Constants.getCRZRADIUS()[num_region]; - double phi = Math.atan2(y, x); - phi+=phicorr; - - x = Math.sqrt(x*x+y*y)*Math.cos(phi); - y = Math.sqrt(x*x+y*y)*Math.sin(phi); - } - newPos[0] = x; - newPos[1] = y; - newPos[2] = z; - - return newPos; - } - */ - private double randomGaus(double mean, double width, Random aRandom) { - if (width <= 0) { - return 0; - } - - double smear = width * aRandom.nextGaussian(); - double randomNumber = mean + smear; - - return randomNumber; - } - - public double[] LabToDetFrame(int layer, int sector, double x, double y, double z) { - double[] newPos = new double[3]; - - newPos[0] = x-org.jlab.rec.cvt.bmt.Constants.Cx[layer-1][sector-1]; - newPos[1] = y-org.jlab.rec.cvt.bmt.Constants.Cy[layer-1][sector-1]; - newPos[2] = z-org.jlab.rec.cvt.bmt.Constants.Cz[layer-1][sector-1]; - - double ThetaZ=org.jlab.rec.cvt.bmt.Constants.Rz[layer-1][sector-1]; - double ThetaY=org.jlab.rec.cvt.bmt.Constants.Ry[layer-1][sector-1]; - double ThetaX=org.jlab.rec.cvt.bmt.Constants.Rx[layer-1][sector-1]; - - //Rotate around z - double xx=newPos[0]; - newPos[0]=Math.cos(ThetaZ)*xx+Math.sin(ThetaZ)*newPos[1]; - newPos[1]=-Math.sin(ThetaZ)*xx+Math.cos(ThetaZ)*newPos[1]; - - //Rotate around x - double yy=newPos[1]; - newPos[1]=Math.cos(ThetaX)*yy+Math.sin(ThetaX)*newPos[2]; - newPos[2]=-Math.sin(ThetaX)*yy+Math.cos(ThetaX)*newPos[2]; - - //Rotate around Y - double zz=newPos[2]; - newPos[2]=Math.cos(ThetaY)*zz+Math.sin(ThetaY)*newPos[0]; - newPos[0]=-Math.sin(ThetaY)*zz+Math.cos(ThetaY)*newPos[0]; - - return newPos; - } - - public double[] DetToLabFrame(int layer, int sector, double x, double y, double z) { - - double[] newPos = new double[3]; - - newPos[0] = x; - newPos[1] = y; - newPos[2] = z; - - double ThetaZ=-org.jlab.rec.cvt.bmt.Constants.Rz[layer-1][sector-1]; - double ThetaY=-org.jlab.rec.cvt.bmt.Constants.Ry[layer-1][sector-1]; - double ThetaX=-org.jlab.rec.cvt.bmt.Constants.Rx[layer-1][sector-1]; - - //Rotate around z - double xx=newPos[0]; - newPos[0]=Math.cos(ThetaZ)*xx+Math.sin(ThetaZ)*newPos[1]; - newPos[1]=-Math.sin(ThetaZ)*xx+Math.cos(ThetaZ)*newPos[1]; - - //Rotate around x - double yy=newPos[1]; - newPos[1]=Math.cos(ThetaX)*yy+Math.sin(ThetaX)*newPos[2]; - newPos[2]=-Math.sin(ThetaX)*yy+Math.cos(ThetaX)*newPos[2]; - - //Rotate around Y - double zz=newPos[2]; - newPos[2]=Math.cos(ThetaY)*zz+Math.sin(ThetaY)*newPos[0]; - newPos[0]=-Math.sin(ThetaY)*zz+Math.cos(ThetaY)*newPos[0]; - - newPos[0] = x+org.jlab.rec.cvt.bmt.Constants.Cx[layer-1][sector-1]; - newPos[1] = y+org.jlab.rec.cvt.bmt.Constants.Cy[layer-1][sector-1]; - newPos[2] = z+org.jlab.rec.cvt.bmt.Constants.Cz[layer-1][sector-1]; - - return newPos; - } - - /** - * - * @param sector - * @param layer - * @param x - * @return a boolean indicating is the track hit is in the fiducial detector - */ - public boolean isInFiducial(int sector, int layer, int axis, double[] x) { - - boolean isInFid = false; - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; - - double z_i = CRZ_GetZStrip(layer) - Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit - double z_f = CRZ_GetZStrip(layer) + Constants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit - - double R_i = 0; // inner radius init - double R_f = 0; // outer radius init for a C or Z detector - if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { - R_i = Constants.getCRZRADIUS()[num_region]; // Z layer - } - if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { - R_i = Constants.getCRCRADIUS()[num_region]; // // C-dtectors - } - R_f = R_i + Constants.hDrift; - - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - double A_i = CRC_GetBeginStrip(sector, layer); - double A_f = CRC_GetEndStrip(sector, layer); - angle_i = A_i; - angle_f = A_f; - if (A_i > A_f) { // for B-detector - angle_f = A_i; - angle_i = A_f; - } - // the hit parameters - double angle = Math.atan2(x[1], x[0]); - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); - double z = x[2]; - - if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { - isInFid = true; - } - - return isInFid; - } - - // in A (index 0), B (index 1), in C (index 2) - public int isInDetector(int layer, double angle, double jitter) { - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - int num_detector = 2; - //double jitter = Math.toRadians(Constants.isInSectorJitter); - for (int i = 0; i < 3; i++) { - - //angle_i=Constants.getCRCEDGE1()[num_region][i]+Constants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; - //angle_f=Constants.getCRCEDGE1()[num_region][i]+(Constants.getCRCXPOS()[num_region]+Constants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; - angle_i = Constants.getCRCEDGE1()[num_region][i]; - angle_f = Constants.getCRCEDGE2()[num_region][i]; - if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { - num_detector = i; - } - } - - return num_detector; - } - - public int isInSector(int layer, double angle, double jitter) { - //double jitter = Math.toRadians(Constants.isInSectorJitter); - int value = -1; - int num_det = this.isInDetector(layer, angle, jitter); - /* if(num_det == 0) - value = 2; - if(num_det ==2) - value = 3; - if(num_det == 1) - value = 1; */ - value = num_det + 1; - - return value; - } - - /** - * - * @param angle - * @param sector - * @param layer - * @param x - * @return a boolean indicating if the given angle is the sector - */ - public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { - if( layer < 1 || layer > 6 ) { - System.err.println(" BMT layer has to be 1 <= layer <= 6"); - return false; - } - if( sector < 1 || sector > 3 ) { - System.err.println(" BMT sector has to be 1 <= layer <= 3"); - return false; - } - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - double angle_i = 0; // first angular boundary init - double angle_f = 0; // second angular boundary for detector A, B, or C init - angle_i = Constants.getCRCEDGE1()[num_region][sector-1]; - angle_f = Constants.getCRCEDGE2()[num_region][sector-1]; - - - if (angle < 0) { - angle += 2 * Math.PI; // from 0 to 2Pi - } - - if( sector == 3 ) { - if( angle < Math.PI ) { - if( angle < angle_f + jitter ) return true; - else return false; - } - else { - if( angle > angle_i - jitter ) return true; - else return false; - } - } - else { - if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) - return true; - else - return false; - - } - } - - - public double LorentzAngleCorr(double phi, int layer) { - - int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - //return phi +( Constants.hDrift/2*Math.tan(Constants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; - //return phi + (Constants.hDrift * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - return phi + (Constants.hDrift/2 * Math.tan(Constants.getThetaL())) / (Constants.getCRZRADIUS()[num_region]); - } - public void SetLorentzAngle(int layer, int sector) { - org.jlab.rec.cvt.bmt.Constants.setThetaL(layer, sector); - } - // Correct strip position before clustering - public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { - - double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); - double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); - - return this.getZStrip(layer, theLorentzCorrectedAngle); - } - - public static void main(String arg[]) { - - Constants.Load(); - OldGeometry geo = new OldGeometry(); - - double trk_z = 0; - - int layer = 5; - System.out.println(geo.CRCStrip_GetZ(6, 267) + " strip " + geo.getCStrip(6, -65.)); - /* - int num_region = (int) (layer+1)/2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 - int strip_group = 0; - int ClosestStrip =-1; - System.out.println((""+1*1+""+1*0+"")); - // get group - int len = Constants.CRCGROUP[num_region].length; - double[] Z_lowBound = new double[len]; - double[] Z_uppBound = new double[len]; - int[] NStrips = new int[len]; - - double zi= Constants.CRCZMIN[num_region]+Constants.CRCOFFSET[num_region]; - double z = trk_z - zi; - - Z_lowBound[0] = Constants.CRCWIDTH[num_region][0]/2.; // the lower bound is the zMin+theOffset with half the width - Z_uppBound[0] = Z_lowBound[0] - + (Constants.CRCGROUP[num_region][0]-1)*(Constants.CRCWIDTH[num_region][0]+ Constants.CRCSPACING[num_region]); - NStrips[0] = Constants.CRCGROUP[num_region][0]; - for(int i =1; i< len; i++) - { - Z_lowBound[i] = Z_uppBound[i-1] + Constants.CRCWIDTH[num_region][i-1]/2. + Constants.CRCSPACING[num_region] + Constants.CRCWIDTH[num_region][i]/2.; - Z_uppBound[i] = Z_lowBound[i] + (Constants.CRCGROUP[num_region][i]-1)*(Constants.CRCWIDTH[num_region][i] + Constants.CRCSPACING[num_region]); - - NStrips[i] = NStrips[i-1] + Constants.CRCGROUP[num_region][i]; - - if(z>=Z_lowBound[i] && z<=Z_uppBound[i]) { - strip_group = i; - ClosestStrip = 1 + (int) (Math.round(((z-Z_lowBound[strip_group])/(Constants.CRCWIDTH[num_region][strip_group] + Constants.CRCSPACING[num_region]))))+NStrips[i-1]; - - len =i; - } - } - double[] X = geo.smearedPosition(5, 0 , Constants.CRZRADIUS[2] , 0); - System.out.println(0+", "+(0.3+Constants.CRZRADIUS[2])+" , "+0+" smeared "+X[0]+", "+X[1]+" , "+X[2]); - System.out.println(geo.getZStrip(5, Math.atan2(Constants.CRZRADIUS[2],0 ))); - System.out.println(geo.getZStrip(5, Math.atan2(X[1],X[0]))); - System.out.println(Math.toDegrees( geo.CRZStrip_GetPhi(1,6, geo.getZStrip(5, Math.atan2(X[1],X[0]))) )); - int theMeasuredZStrip = geo.getZStrip(5, Math.atan2(X[1],X[0])); // start reco - double theMeasuredPhi = geo.CRZStrip_GetPhi(1,6,theMeasuredZStrip); - double theLorentzCorrectedAngle = geo.LorentzAngleCorr( theMeasuredPhi, 6); - System.out.println(" corrected phi = "+Math.toDegrees(theLorentzCorrectedAngle)); - int theLorentzCorrectedStrip = geo.getZStrip(5, theLorentzCorrectedAngle); - System.out.println(theMeasuredZStrip+" "+theLorentzCorrectedStrip); */ - /* - double phiC = geo.CRZStrip_GetPhi(3,6,216); - double x = Constants.CRCRADIUS[2]*Math.cos(phiC); - double y = Constants.CRCRADIUS[2]*Math.sin(phiC); - int theMeasuredCStrip = geo.getCStrip(6,X[2]); - double z = geo.CRCStrip_GetZ(6,309); - System.out.println(x+", "+y+", "+z);*/ - //List Hits = geo.GEMCBMTHits(layer, sector, -199.89230321711165 , 93.78543124898611 , -164.52000000000007, .1); - //System.out.println("There are "+Hits.size()+" hits in this cluster"); - //for(int i =0; i z_min - epsilon && z < z_max + epsilon) { - isOK = true; - } - return isOK; - } - - public static final synchronized int getZorC(int layer) { - int axis = 0; - if (layer == 2 || layer == 3 || layer == 5) { - axis = 1; - } - return axis; - } -} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 90f16cea8..fda5eca43 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -15,7 +15,7 @@ import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Transformation3D; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.Constants; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.hit.Strip; /** * A cluster in the BST consists of an array of hits that are grouped together @@ -254,7 +254,7 @@ public void calc_CentroidParams() { } else if (this.get_Detector()==DetectorType.BMT) { - if(thehit.newClustering && nbhits>Constants.MAXCLUSSIZE && i>Constants.MAXCLUSSIZE-1) + if(thehit.newClustering && nbhits>BMTConstants.MAXCLUSSIZE && i>BMTConstants.MAXCLUSSIZE-1) continue; // for the BMT the analysis distinguishes between C and Z type detectors diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index df614b814..a035e1178 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -7,6 +7,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; @@ -440,7 +441,7 @@ public void setSVTCrossPosition(Vector3D trackDir, SVTGeometry geo) { } this.set_Point(crossPoint); -// this.set_Dir(trackDir); + this.set_Dir(trackDir); this.set_PointErr(crossError.toPoint3D()); } @@ -606,7 +607,7 @@ public int get_SVTCosmicsRegion() { public int compareTo(Cross arg) { int return_val = 0; - if (org.jlab.rec.cvt.Constants.isCosmicsData() == true) { + if (Constants.isCosmicsData() == true) { int RegComp = this.get_SVTCosmicsRegion() < arg.get_SVTCosmicsRegion() ? -1 : this.get_SVTCosmicsRegion() == arg.get_SVTCosmicsRegion() ? 0 : 1; int IDComp = this.get_Id() < arg.get_Id() ? -1 : this.get_Id() == arg.get_Id() ? 0 : 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 38c55bbbe..6fd147947 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -3,8 +3,8 @@ import java.util.ArrayList; import java.util.List; import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.bmt.BMTConstants; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -146,7 +146,7 @@ private ArrayList findBMTCrosses( // For BMT start id at 1000 int pid = 1000; for (Cluster Zlayerclus : Zlayrclus) { - if (Zlayerclus.get_TotalEnergy() < org.jlab.rec.cvt.bmt.Constants.ETOTCUT) { + if (Zlayerclus.get_TotalEnergy() < BMTConstants.ETOTCUT) { continue; } // Z detector --> meas phi @@ -155,31 +155,6 @@ private ArrayList findBMTCrosses( this_cross.set_Id(pid); this_cross.set_Cluster1(Zlayerclus); this_cross.setBMTCrossPosition(null); -// //the uncorrected x,y position of the Z detector cluster centroid. This is calculated from the measured strips -// // in the cluster prior to taking Lorentz angle correction into account -// double radius = Zlayerclus.getRadius(); -// double x0 = radius * Math.cos(Zlayerclus.get_Phi0()); -// double y0 = radius * Math.sin(Zlayerclus.get_Phi0()); -// double x0Er = radius * Math.sin(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); -// double y0Er = radius * Math.cos(Zlayerclus.get_Phi0()) * Zlayerclus.get_PhiErr0(); -// // set only the coordinates for which there is a measurement -// this_cross.set_Point0(new Point3D(x0, y0, Double.NaN)); -// this_cross.set_PointErr0(new Point3D(x0Er, y0Er, Double.NaN)); -// //the x,y position of the Z detector cluster centroid. This is calculated from the Lorentz angle corrected strips -// //double x = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.cos(Zlayerclus.get_Phi()); -// //double y = (org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[Zlayerclus.get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hStrip2Det) * Math.sin(Zlayerclus.get_Phi()); -// double x = Zlayerclus.center().x(); -// double y = Zlayerclus.center().y(); -// double xEr = radius * Math.sin(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); -// double yEr = radius * Math.cos(Zlayerclus.get_Phi()) * Zlayerclus.get_PhiErr(); -// System.out.println(this_cross.get_Point().toString()); -// System.out.println(this_cross.get_PointErr().toString()); -// System.out.println(x + " " + y + " " + xEr + " " + yEr); -// -// // set only the coordinates for which there is a measurement (x,y) -// this_cross.set_Point(new Point3D(x, y, Double.NaN)); -// this_cross.set_PointErr(new Point3D(Math.abs(xEr), Math.abs(yEr), Double.NaN)); -// this_cross.set_Cluster1(Zlayerclus); if (this_cross.get_Point0() != null) { //make arraylist crosses.add(this_cross); @@ -188,23 +163,13 @@ private ArrayList findBMTCrosses( } for (Cluster Clayerclus : Clayrclus) { - if (Clayerclus.get_TotalEnergy() < org.jlab.rec.cvt.bmt.Constants.ETOTCUT) { + if (Clayerclus.get_TotalEnergy() < BMTConstants.ETOTCUT) { continue; } // C detector --> meas z // define new cross Cross this_cross = new Cross(DetectorType.BMT, BMTType.C, Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); this_cross.set_Id(pid); - - // measurement of z -// double z = Clayerclus.center().z(); -// double zErr = Clayerclus.get_ZErr(); -// // there is no measurement of x,y, hence only the z component is set -// this_cross.set_Point0(new Point3D(Double.NaN, Double.NaN, z)); -// this_cross.set_PointErr0(new Point3D(Double.NaN, Double.NaN, zErr)); -// // at this stage there is no additional correction to the measured centroid -// this_cross.set_Point(Clayerclus.center()); -// this_cross.set_PointErr(new Point3D(Double.NaN, Double.NaN, zErr)); this_cross.set_Cluster1(Clayerclus); this_cross.setBMTCrossPosition(null); if (this_cross.get_Point0() != null) { @@ -212,11 +177,7 @@ private ArrayList findBMTCrosses( crosses.add(this_cross); } } - //for (Cross c : crosses) { - // int rg = (c.get_Detector().equalsIgnoreCase("BMT")) ? 3 + - // bmt_geo.getLayer( c.get_Region(), c.get_DetectorType()) : c.get_Region(); - // c.setOrderedRegion(rg); - //} + for (Cross c : crosses) { int rg = 3 + bmt_geo.getLayer( c.get_Region(), c.get_Type()) ; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index 6d8b1c7f6..8c3c94713 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -6,6 +6,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -245,7 +246,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { } double dzdrsum = avg_tandip*countCrosses; double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; + double r_bmt = BMTConstants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; System.out.println(bmt_Ccross.get_Point().toString() + " " + bmt_Ccross.getcCrossRadius()); double dzdr_bmt = z_bmt / r_bmt; if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= SVTParameters.dzdrcut) // add this to the track diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index f7e5aa17a..69bdbd993 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -43,8 +43,8 @@ public class CircleFitter { * Constructor Sets the reference point to (0,0) */ public CircleFitter() { - _xref = org.jlab.rec.cvt.Constants.getXb(); - _yref = org.jlab.rec.cvt.Constants.getYb(); + _xref = Constants.getXb(); + _yref = Constants.getYb(); _covr = new double[6]; } // Now set the reference point for the fit diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index c7c0871e4..2b394149f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -9,7 +9,7 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.Constants; +import org.jlab.rec.cvt.bmt.BMTConstants; public class Strip { @@ -241,7 +241,7 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); this.set_LCStrip(theLorentzCorrectedStrip); - double sigma = Constants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh + double sigma = BMTConstants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh //max phi err double phiErrL = sigma / geo.getRadius(layer); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index b25662e0d..728c9b40b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -19,6 +19,7 @@ import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.HitReader; import org.jlab.rec.cvt.banks.RecoBankWriter; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; import org.jlab.rec.cvt.cluster.Cluster; @@ -85,7 +86,7 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int String newConfig = "SOLENOID" + bank.getFloat("solenoid", 0); if (FieldsConfig.equals(newConfig) == false) { - // Load the Constants + // Load the BMTConstants this.setFieldsConfig(newConfig); } @@ -94,23 +95,14 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int //------------------- int newRun = bank.getInt("run", 0); if (Run != newRun) { - boolean align=false; - //Load field scale - double SolenoidScale =(double) bank.getFloat("solenoid", 0); - if(SolenoidScale==0) - SolenoidScale=0.000001; - Constants.setSolenoidscale(SolenoidScale); - float[]b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - Constants.setSolenoidVal(Math.abs(b[2])); + Constants.Load(isCosmics, isSVTonly); this.setRun(newRun); if(newRun<100) { - org.jlab.rec.cvt.bmt.Constants.isMC = true; + Constants.isMC = true; } else { - org.jlab.rec.cvt.bmt.Constants.isMC = false; + Constants.isMC = false; } } @@ -137,7 +129,7 @@ public void setFieldsConfig(String fieldsConfig) { @Override public boolean processDataEvent(DataEvent event) { this.setRunConditionsParameters(event, FieldsConfig, Run, false, ""); - double shift = 0;//org.jlab.rec.cvt.Constants.getZoffset(); + double shift = 0;//org.jlab.rec.cvt.BMTConstants.getZoffset(); this.FieldsConfig = this.getFieldsConfig(); @@ -164,7 +156,7 @@ public boolean processDataEvent(DataEvent event) { if (bmt_hits != null && bmt_hits.size() > 0) { hits.addAll(bmt_hits); - if(bmt_hits.size()>org.jlab.rec.cvt.bmt.Constants.MAXBMTHITS) + if(bmt_hits.size()>BMTConstants.MAXBMTHITS) return true; } @@ -271,14 +263,14 @@ public boolean init() { if (svtCosmics!=null) { System.out.println("["+this.getName()+"] run with cosmics settings "+svtCosmics+" config chosen based on yaml"); this.isCosmic= Boolean.valueOf(svtCosmics); - org.jlab.rec.cvt.Constants.setCosmicsData(isCosmic); + Constants.setCosmicsData(isCosmic); } else { svtCosmics = System.getenv("COAT_CVT_COSMICS"); if (svtCosmics!=null) { System.out.println("["+this.getName()+"] run with cosmics settings "+svtCosmics+" config chosen based on env"); this.isCosmic= Boolean.valueOf(svtCosmics); - org.jlab.rec.cvt.Constants.setCosmicsData(isCosmic); + Constants.setCosmicsData(isCosmic); } } if (svtCosmics==null) { @@ -314,7 +306,7 @@ public boolean init() { int exlyrsnb = 0; for(int ilayrs = 0; ilayrs<12; ilayrs++) { - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(ilayrs+1)<1) { + if((int)Constants.getLayersUsed().get(ilayrs+1)<1) { System.out.println("EXCLUDE CVT LAYER "+(ilayrs+1)); exlyrsnb++; } @@ -327,13 +319,13 @@ public boolean init() { // // if (newClustering!=null) { // System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on yaml"); -// org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); +// BMTConstants.newClustering= Boolean.valueOf(newClustering); // } // else { // newClustering = System.getenv("COAT_CVT_NEWCLUSTERING"); // if (newClustering!=null) { // System.out.println("["+this.getName()+"] run with new clustering settings "+newClustering+" config chosen based on env"); -// org.jlab.rec.cvt.bmt.Constants.newClustering= Boolean.valueOf(newClustering); +// BMTConstants.newClustering= Boolean.valueOf(newClustering); // } // } // if (newClustering==null) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 7328d5962..ab5eae509 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -258,7 +258,7 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrk (List allClusters, List } // initialize swimmer starting from the track vertex double maxPathLength = 1; - swimmer.SetSwimParameters((helix.xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (helix.ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, helix.get_Z0() / 10, + swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), P, Q, maxPathLength) ; double[] inters = null; @@ -370,8 +370,8 @@ public List FindClustersOnTrk (List allClusters, List Vector3D n = sgeo.getNormal(layer, sector); Point3D p = sgeo.getModule(layer, sector).origin(); - double d = n.dot(p.toVector3D()); - inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); + Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + inters = swimmer.SwimPlane(n, pm, 1E-3); if(inters!=null) { Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); @@ -424,15 +424,11 @@ public void MatchTrack2Traj(Seed trkcand, Map reFitSeed(Seed bseed, int layr2 = 0; if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; //System.out.println("refit "+c.printInfo()); refib.add(c); @@ -632,8 +583,8 @@ public List reFitSeed(Seed bseed, } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 - && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getLayersUsed().get(layr)>0 + && (int)Constants.getLayersUsed().get(layr2)>0) { c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; refi.add(c); @@ -677,15 +628,15 @@ public List reFitSeed(Seed bseed, c.set_AssociatedTrackID(-1); if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; refib.add(c); } } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 - && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getLayersUsed().get(layr)>0 + && (int)Constants.getLayersUsed().get(layr2)>0) { c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); @@ -733,7 +684,7 @@ public List reFitSeed(StraightTrack cand, int layr2 = 0; if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getLayersUsed().get(layr)>0) { c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refib.add(c); @@ -741,8 +692,8 @@ public List reFitSeed(StraightTrack cand, } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr)>0 - && (int)org.jlab.rec.cvt.Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getLayersUsed().get(layr)>0 + && (int)Constants.getLayersUsed().get(layr2)>0) { c.setSVTCrossPosition(null, SVTGeom); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 5b52b4f68..e914e72b0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -1,9 +1,12 @@ package org.jlab.rec.cvt.services; import Jama.Matrix; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.helical.KFitter; +import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; @@ -44,10 +47,15 @@ public boolean processEvent(DataEvent event, double shift, Swim swimmer, boolean isSVTonly, boolean exLayrs) { - // make list of crosses consistent with a track candidate + + // get field value and scale + double solenoidScale = Constants.getSolenoidScale(); + double solenoidValue = Constants.getSolenoidMagnitude(); // already the absolute value + + // make list of crosses consistent with a track candidate List seeds = null; - if(Math.abs(Constants.getSolenoidVal())<0.001) { + if(solenoidValue<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(); seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, isSVTonly); if(exLayrs==true) { @@ -79,47 +87,38 @@ public boolean processEvent(DataEvent event, return true; } - org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf = null; + KFitter kf = null; List trkcands = new ArrayList(); - for (Seed seed : seeds) { - org.jlab.clas.tracking.trackrep.Helix hlx = null ; - - double xr = -seed.get_Helix().get_dca()*Math.sin(seed.get_Helix().get_phi_at_dca()); - double yr = seed.get_Helix().get_dca()*Math.cos(seed.get_Helix().get_phi_at_dca()); - double zr = seed.get_Helix().get_Z0(); - double pt = Constants.LIGHTVEL * seed.get_Helix().radius() * Constants.getSolenoidVal(); - if(Math.abs(Constants.getSolenoidVal())<0.001) - pt = 100; - double pz = pt*seed.get_Helix().get_tandip(); - double px = pt*Math.cos(seed.get_Helix().get_phi_at_dca()); - double py = pt*Math.sin(seed.get_Helix().get_phi_at_dca()); - int charge = (int) (Math.signum(Constants.getSolenoidscale())*seed.get_Helix().get_charge()); - if(Math.abs(Constants.getSolenoidVal())<0.001) + for (Seed seed : seeds) { + Point3D v = seed.get_Helix().getVertex(); + Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); + int charge = (int) (Math.signum(solenoidScale)*seed.get_Helix().get_charge()); + if(solenoidValue<0.001) charge = 1; - xr += org.jlab.rec.cvt.Constants.getXb(); - yr += org.jlab.rec.cvt.Constants.getYb(); + v.translateXYZ(Constants.getXb(), + Constants.getYb(), + 0); //Uncomment to force to MC truth: -// double[] pars = recUtil.MCtrackPars(event); -// xr = pars[0];yr=pars[1];zr=pars[2];px=pars[3];py=pars[4];pz=pars[5]; -// System.out.println(xr + " " + yr + " " + zr + " " + px + " " + py + " " + pz); - hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, - charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), - org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); + //double[] pars = recUtil.MCtrackPars(event); + //v = new Point3D(pars[0],pars[1],pars[2]); + //p = new Vector3D(pars[3],pars[4],pars[5]); + Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, + solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); Matrix cov = seed.get_Helix().get_covmatrix(); - if(Math.abs(Constants.getSolenoidVal())>0.001 && - Constants.LIGHTVEL * seed.get_Helix().radius() *Constants.getSolenoidVal()0.001 && + Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0 && kf.KFHelix!=null) { Track fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); @@ -137,38 +136,27 @@ public boolean processEvent(DataEvent event, } //reset pars - xr = -fittedTrack.get_helix().get_dca()*Math.sin(fittedTrack.get_helix().get_phi_at_dca()); - yr = fittedTrack.get_helix().get_dca()*Math.cos(fittedTrack.get_helix().get_phi_at_dca()); - zr = fittedTrack.get_helix().get_Z0(); - pt = Constants.LIGHTVEL * fittedTrack.get_helix().radius() * Constants.getSolenoidVal(); - if(Math.abs(Constants.getSolenoidVal())<0.001) - pt = 100; - pz = pt*fittedTrack.get_helix().get_tandip(); - px = pt*Math.cos(fittedTrack.get_helix().get_phi_at_dca()); - py = pt*Math.sin(fittedTrack.get_helix().get_phi_at_dca()); - charge = (int) (Math.signum(Constants.getSolenoidscale())*fittedTrack.get_helix().get_charge()); - if(Math.abs(Constants.getSolenoidVal())<0.001) + v = fittedTrack.get_helix().getVertex(); + p = fittedTrack.get_helix().getPXYZ(solenoidValue); + charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); + if(solenoidValue<0.001) charge = 1; - xr += org.jlab.rec.cvt.Constants.getXb(); - yr += org.jlab.rec.cvt.Constants.getYb(); -// System.out.println(xr + " " + yr + " " + zr + " " + px + " " + py + " " + pz); - hlx = new org.jlab.clas.tracking.trackrep.Helix(xr,yr,zr,px,py,pz, - charge, Constants.getSolenoidVal(), org.jlab.rec.cvt.Constants.getXb(), - org.jlab.rec.cvt.Constants.getYb(), org.jlab.clas.tracking.trackrep.Helix.Units.MM); + v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); + hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, + solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - kf = new org.jlab.clas.tracking.kalmanfilter.helical.KFitter( hlx, cov, event, swimmer, - org.jlab.rec.cvt.Constants.getXb(), - org.jlab.rec.cvt.Constants.getYb(), + kf = new KFitter( hlx, cov, event, swimmer, + Constants.getXb(), + Constants.getYb(), shift, recUtil.setMeasVecs(seed, swimmer)) ; //Uncomment to let track be fitted - kf.filterOn = false; + //kf.filterOn = false; kf.runFitter(swimmer); Track trk = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); trkcands.add(trk); - trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); } //} else { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 96793a520..fdd009479 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -11,7 +11,7 @@ public class SVTGeometry { - private final SVTStripFactory _svtStripFactory; + private SVTStripFactory _svtStripFactory; public static final int NREGIONS = 3; public static final int NLAYERS = 6; public static final int NSTRIPS = SVTConstants.NSTRIPS; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java index 46419ee27..6ed8613a3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java @@ -7,6 +7,7 @@ import javax.vecmath.Point2d; import javax.vecmath.Vector2d; import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.bmt.BMTConstants; /** * Base cell for the cellular automaton @@ -84,7 +85,7 @@ public Point2d get_Crs2D( int i, String vw ){ cross.get_Point().y()*cross.get_Point().y() ); } else { - R = org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[cross.get_Region()-1]; + R = BMTConstants.getCRCRADIUS()[cross.get_Region()-1]; } point.set( cross.get_Point().z(), R ); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 377b142b7..277eb3e26 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -3,6 +3,7 @@ import javax.vecmath.Vector2d; import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -45,9 +46,9 @@ private double getCrossRadius( Cross c ) { // TODO: can this be moved inside th return Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); if( c.get_Type()==BMTType.Z ) - return org.jlab.rec.cvt.bmt.Constants.getCRZRADIUS()[c.get_Region()-1 ]; + return BMTConstants.getCRZRADIUS()[c.get_Region()-1 ]; - return org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[c.get_Region()-1 ]; + return BMTConstants.getCRCRADIUS()[c.get_Region()-1 ]; } private boolean checkAngles( Cell cell ) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 94e63a252..18f6bdf3c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; @@ -95,8 +96,8 @@ private void FitSeed(List seedcrs) { ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, org.jlab.rec.cvt.Constants.getXb()); - Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); + Xs.add(0, Constants.getXb()); + Ys.add(0, Constants.getYb()); Ws.add(0,0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); @@ -263,8 +264,8 @@ public List findSeed(List svt_crosses, List bmt_crosses, ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, org.jlab.rec.cvt.Constants.getXb()); - Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); + Xs.add(0, Constants.getXb()); + Ys.add(0, Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) continue; @@ -477,8 +478,8 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } - //X.add((double) org.jlab.rec.cvt.Constants.getXb()); - //Y.add((double) org.jlab.rec.cvt.Constants.getYb()); + //X.add((double) Constants.getXb()); + //Y.add((double) Constants.getYb()); //ErrRt.add((double) 0.1); fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index c4679c7ff..98b8b52de 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.track; +import org.jlab.clas.swimtools.Swim; import org.jlab.clas.swimtools.Swimmer; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; @@ -22,7 +23,29 @@ */ public class Track extends Trajectory implements Comparable { + /** + * serialVersionUID + */ + private static final long serialVersionUID = 1763744434903318419L; + + private int _Q; // track charge + private double _Pt; // track pt + private double _Pz; // track pz + private double _P; // track p + + private String _PID; // track pid + private int _TrackingStatus; + + private double _circleFitChi2PerNDF; // the chi2 for the helical track circle fit + private double _lineFitChi2PerNDF; // the linear fit to get the track dip angle + + private Point3D _TrackPointAtCTOFRadius; // a point of reference at the CTOF radius [the track is extrapolated to the CTOF radius and matched to CTOF hits to get the TOF] + private Vector3D _TrackDirAtCTOFRadious; // the direction of the track at the reference point described above. + private double _pathLength; // the pathlength from the doca of the track to the z axis to the reference point described above + public boolean passCand; // a flag to pass the candidate. + private int _NDF; + private double _Chi2; public void set_TrackingStatus(int ts) { @@ -42,17 +65,6 @@ public Track(Helix helix) { set_HelicalTrack(helix); } } - /** - * serialVersionUID - */ - private static final long serialVersionUID = 1763744434903318419L; - - private int _Q; // track charge - private double _Pt; // track pt - private double _Pz; // track pz - private double _P; // track p - - private String _PID; // track pid /** * @@ -115,7 +127,7 @@ public void set_P(double _P) { */ public void set_HelicalTrack(Helix Helix) { if (Helix != null) { - set_Q(((int) Math.signum(Constants.getSolenoidscale()) * Helix.get_charge())); + set_Q(((int) Math.signum(Constants.getSolenoidScale()) * Helix.get_charge())); double calcPt = 10; if(Math.abs(Helix.B)>0.0001) { calcPt = Constants.LIGHTVEL * Helix.radius() * Helix.B; @@ -132,6 +144,13 @@ public void set_HelicalTrack(Helix Helix) { } } + /** + * updates the crosses positions based on the track direction for a helical + * trajectory + * + * @param sgeo + * @param bgeo + */ public void update_Crosses(SVTGeometry sgeo, BMTGeometry bgeo) { if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { // System.out.println("Updating crosses"); @@ -152,14 +171,10 @@ else if(cross.get_Detector()==DetectorType.BMT) } - } + } - /** - * updates the crosses positions based on the track direction for a helical - * trajectory - * - * @param geo the SVT geometry - */ + + @Deprecated public void update_Crosses(SVTGeometry geo) { if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { @@ -191,35 +206,6 @@ public void update_Crosses(SVTGeometry geo) { } - // not used - public void finalUpdate_Crosses(SVTGeometry geo) { - if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { - - Helix helix = this.get_helix(); - for (int i = 0; i < this.size(); i++) { - if (this.get(i).get_Detector()!=DetectorType.BST) { - continue; - } - double R = Math.sqrt(this.get(i).get_Point().x() * this.get(i).get_Point().x() + this.get(i).get_Point().y() * this.get(i).get_Point().y()); - Vector3D helixTanVecAtLayer = helix.getTrackDirectionAtRadius(R); - Point3D helixPosAtLayer = helix.getPointAtRadius(R); - this.get(i).set_Point(helixPosAtLayer); - this.get(i).set_Dir(helixTanVecAtLayer); - - } - - } - - } - - private double _circleFitChi2PerNDF; // the chi2 for the helical track circle fit - private double _lineFitChi2PerNDF; // the linear fit to get the track dip angle - - private Point3D _TrackPointAtCTOFRadius; // a point of reference at the CTOF radius [the track is extrapolated to the CTOF radius and matched to CTOF hits to get the TOF] - private Vector3D _TrackDirAtCTOFRadious; // the direction of the track at the reference point described above. - private double _pathLength; // the pathlength from the doca of the track to the z axis to the reference point described above - public boolean passCand; // a flag to pass the candidate. - /** * * @param cross the cross @@ -320,9 +306,6 @@ public void set_lineFitChi2PerNDF(double _lineFitChi2PerNDF) { this._lineFitChi2PerNDF = _lineFitChi2PerNDF; } - private int _NDF; - private double _Chi2; - public int getNDF() { return _NDF; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index b112adbe1..939ae1945 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -12,6 +12,8 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -154,7 +156,7 @@ public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) HelicalTrackFitter fitTrk = new HelicalTrackFitter(); // sets the index according to assumption that the track comes from the origin or not int shift = 0; - // if(org.jlab.rec.cvt.Constants.trk_comesfrmOrig) + // if(org.jlab.rec.cvt.BMTConstants.trk_comesfrmOrig) // shift =1; // interate the fit a number of times set in the constants file @@ -242,7 +244,7 @@ public ArrayList getHelicalTracks(CrossList crossList, HelicalTrackFitter fitTrk = new HelicalTrackFitter(); // sets the index according to assumption that the track comes from the origin or not int shift = 0; - if (org.jlab.rec.cvt.Constants.trk_comesfrmOrig) { + if (Constants.trk_comesfrmOrig) { shift = 1; } @@ -484,7 +486,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List cands.add(value)); } - //ArrayList passedcands = this.rmStraightTrkClones(org.jlab.rec.cvt.svt.Constants.removeClones, cands); + //ArrayList passedcands = this.rmStraightTrkClones(org.jlab.rec.cvt.svt.BMTConstants.removeClones, cands); ArrayList passedcands = this.rmStraightTrkClones(true, cands); // for (int ic = 0; ic < passedcands.size(); ic++) { @@ -596,19 +598,19 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, if (shift == 1) { //X.add(0, (double) 0); //Y.add(0, (double) 0); - double xb = org.jlab.rec.cvt.Constants.getXb(); - double yb = org.jlab.rec.cvt.Constants.getYb(); + double xb = Constants.getXb(); + double yb = Constants.getYb(); double rb = Math.sqrt(xb*xb+yb*yb); - X.add(0, (double) org.jlab.rec.cvt.Constants.getXb()); - Y.add(0, (double) org.jlab.rec.cvt.Constants.getYb()); + X.add(0, (double) Constants.getXb()); + Y.add(0, (double) Constants.getYb()); //Z.add(0, (double) 0); //Rho.add(0, (double) 0); Rho.add(0, (double) rb); - //ErrRt.add(0, org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - ErrRt.add(0, org.jlab.rec.cvt.Constants.getRbErr()); - //ErrZ.add(0, org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); - //ErrRho.add(0, org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - ErrRho.add(0, org.jlab.rec.cvt.Constants.getRbErr()); + //ErrRt.add(0, org.jlab.rec.cvt.svt.BMTConstants.RHOVTXCONSTRAINT); + ErrRt.add(0, Constants.getRbErr()); + //ErrZ.add(0, org.jlab.rec.cvt.svt.BMTConstants.ZVTXCONSTRAINT); + //ErrRho.add(0, org.jlab.rec.cvt.svt.BMTConstants.RHOVTXCONSTRAINT); + ErrRho.add(0, Constants.getRbErr()); } for (int j = shift; j < shift + SVTcrossesInTrk.size(); j++) { @@ -651,8 +653,8 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, for (int j = shift + j0; j < shift + j0 + BMTCdetcrossesInTrk.size(); j++) { Z.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().z()); - Rho.add(j, org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + org.jlab.rec.cvt.bmt.Constants.hDrift/2); - System.out.println(BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().toString() + " " + org.jlab.rec.cvt.bmt.Constants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1]); + Rho.add(j, BMTConstants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + BMTConstants.hDrift/2); + System.out.println(BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().toString() + " " + BMTConstants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1]); ErrRho.add(j, 0.01); // check this error on thickness measurement ErrZ.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_PointErr().z()); @@ -668,7 +670,7 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, ErrZ.add(j, SVTcrossesInTrk.get(j - shift-1).get_PointErr0().z()); } } - // if(Constants.DEBUGMODE) { + // if(BMTConstants.DEBUGMODE) { // System.out.println(" FIT ARRAYS "); // for(int i =0; i findSeed(List bst_crosses, List bmt_crosses, ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, org.jlab.rec.cvt.Constants.getXb()); - Ys.add(0, org.jlab.rec.cvt.Constants.getYb()); + Xs.add(0, Constants.getXb()); + Ys.add(0, Constants.getYb()); Ws.add(0, 0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) continue; @@ -509,8 +509,8 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } - X.add((double) org.jlab.rec.cvt.Constants.getXb()); - Y.add((double) org.jlab.rec.cvt.Constants.getYb()); + X.add((double) Constants.getXb()); + Y.add((double) Constants.getYb()); ErrRt.add((double) 0.1); fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 01f5c713d..882a31720 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -578,8 +578,8 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } - X.add((double) org.jlab.rec.cvt.Constants.getXb()); - Y.add((double) org.jlab.rec.cvt.Constants.getYb()); + X.add((double) Constants.getXb()); + Y.add((double) Constants.getYb()); ErrRt.add((double) 0.1); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index 3e7be8595..78ef7e0b0 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -4,6 +4,7 @@ import org.jlab.geom.prim.Vector3D; import Jama.Matrix; +import org.jlab.rec.cvt.Constants; /** * A class describing a helix; the helix parameters are field of the track @@ -149,6 +150,21 @@ public double ydca() { return this.get_dca() * Math.cos(this.get_phi_at_dca()); } + public Point3D getVertex() { + return new Point3D(this.xdca(),this.ydca(),this.get_Z0()); + } + + public Vector3D getPXYZ(double solenoidMag) { + double pt = Constants.LIGHTVEL * this.radius() * solenoidMag; + if(solenoidMag<0.001) + pt = 100; + double pz = pt*this.get_tandip(); + double px = pt*Math.cos(this.get_phi_at_dca()); + double py = pt*Math.sin(this.get_phi_at_dca()); + + return new Vector3D(px,py,pz); + } + public double getArcLength_dca(Point3D refpoint) { //insure that the refpoint is on the helix if (refpoint == null) { @@ -223,13 +239,17 @@ public Point3D getPointAtRadius(double r) { public Vector3D getTrackDirectionAtRadius(double r) { // a method to return a point (as a vector) at a given radial position. - if (_curvature == 0) { - return null; - } - double d0 = _dca; double omega = _curvature; double phi0 = _phi_at_dca; + double tandip = _tandip; + + if (_curvature <1E-5) { // R > 100 m, assume it's straight track + double ux = Math.cos(phi0); + double uy = Math.sin(phi0); + double uz = tandip; + return new Vector3D(ux, uy, uz); + } double par = 1. - ((r * r - d0 * d0) * omega * omega) / (2. * (1. + d0 * Math.abs(omega))); double newPathLength = Math.abs(Math.acos(par) / omega); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java index 328085eb6..41fb4d8c0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.trajectory; import Jama.*; +import org.jlab.rec.cvt.Constants; /** * A StateVec describes a cross measurement in the BST. It is characterized by a @@ -287,13 +288,13 @@ public double uz() { public int compareTo(StateVec arg) { int return_val = 0; - if (org.jlab.rec.cvt.Constants.isCosmicsData() == false) { + if (Constants.isCosmicsData() == false) { int RegComp = this.get_SurfaceLayer() < arg.get_SurfaceLayer() ? -1 : this.get_SurfaceLayer() == arg.get_SurfaceLayer() ? 0 : 1; int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; return_val = ((RegComp == 0) ? IDComp : RegComp); } - if (org.jlab.rec.cvt.Constants.isCosmicsData() == true) { + if (Constants.isCosmicsData() == true) { int RegComp = this.y() < arg.y() ? -1 : this.y() == arg.y() ? 0 : 1; int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index cc59a6eb5..deb9850a1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -17,6 +17,8 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -118,7 +120,7 @@ public Trajectory findTrajectory(Track trk, // initialize swimmer starting from the track vertex double maxPathLength = 1; - swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().ydca()+Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), trk.get_P(), trk.get_Q(), maxPathLength) ; double[] inters = null; @@ -137,9 +139,9 @@ public Trajectory findTrajectory(Track trk, continue; Vector3D n = svt_geo.getNormal(layer, sector); - Point3D p = svt_geo.getModule(layer, sector).origin(); - double d = n.dot(p.toVector3D()); - inters = swimmer.SwimToPlaneBoundary(d/10.0, n, 1); + Point3D p = svt_geo.getModule(layer, sector).origin(); + Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + inters = swimmer.SwimPlane(n, pm, 5E-4); path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); @@ -176,7 +178,7 @@ public Trajectory findTrajectory(Track trk, } // reinitialize from vertex maxPathLength = 1.5; - swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().ydca()+Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), trk.get_P(), trk.get_Q(), maxPathLength) ; inters = null; @@ -202,14 +204,14 @@ public Trajectory findTrajectory(Track trk, Line3D axis = bmt_geo.getAxis(layer, sector); Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); - // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.Constants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), // trk.get_P(), trk.get_Q(), // 5.0) ; inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius); double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); path = path + inters[6]; - //if(r>(radius - org.jlab.rec.cvt.bmt.Constants.LYRTHICKN)/10) { + //if(r>(radius - BMTConstants.LYRTHICKN)/10) { StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); // double phiPos = Math.atan2(stVec.y(),stVec.x()); @@ -460,9 +462,9 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList } } - double[][][] BMTIntersections = calc_trackIntersBMT(ray, bmt_geo, org.jlab.rec.cvt.bmt.Constants.STARTINGLAYR); + double[][][] BMTIntersections = calc_trackIntersBMT(ray, bmt_geo, BMTConstants.STARTINGLAYR); - for (int l = org.jlab.rec.cvt.bmt.Constants.STARTINGLAYR - 1; l < 6; l++) { + for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { //hemisphere 1-2 for (int h = 0; h < 2; h++) { @@ -472,7 +474,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList double XtrackIntersSurf = BMTIntersections[l][h][0]; double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; - //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(org.jlab.rec.cvt.bmt.Constants.isInSectorJitter)); + //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); int SectorTrackIntersSurf = bmt_geo.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; From 57b87f7a0ab1f26d70070455d388a91d649acc30 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Fri, 15 Oct 2021 00:57:33 -0400 Subject: [PATCH 184/291] # WARNING: head commit changed in the meantime Merge remote-tracking branch 'origin/TracTools-Test3Dev' into dev-align3 # Conflicts: # reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java # reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java --- .../jlab/rec/cvt/banks/RecoBankReader.java | 14 +++- .../jlab/rec/cvt/services/CVTAlignment.java | 81 ++++++++++++++----- 2 files changed, 71 insertions(+), 24 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 2acc89d43..5d19077af 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -317,7 +317,11 @@ public void fetch_Tracks(DataEvent event, double zShift) { float d0s[] = bank.getFloat("d0"); float xbs[] = bank.getFloat("xb"); float ybs[] = bank.getFloat("yb"); - + if(xbs.length > 0) { + xb = xbs[0]*10.f; + yb = ybs[0]*10.f; + } + //System.out.println("xb yb from file" + xbs[0] + ybs[0]); float curvatures[]; @@ -368,7 +372,13 @@ public void fetch_Tracks(DataEvent event, double zShift) { } } - + private double xb, yb; + public double getXbeam() { + return xb; + } + public double getYbeam() { + return yb; + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 555790326..447f29c19 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -7,8 +7,8 @@ import org.jlab.clas.reco.ReconstructionEngine; //import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.detector.geant4.v2.SVT.SVTConstants; +//import org.jlab.detector.calib.utils.DatabaseConstantProvider; +//import org.jlab.detector.geant4.v2.SVT.SVTConstants; //import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Line3D; @@ -21,7 +21,7 @@ import org.jlab.rec.cvt.banks.AlignmentBankWriter; import org.jlab.rec.cvt.banks.RecoBankReader; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; +//import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; @@ -57,7 +57,7 @@ public CVTAlignment() { int Run = -1; public boolean isSVTonly = false; private Boolean svtTopBottomSep; - public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int iRun, boolean addMisAlignmts, String misAlgnFile) { + /*public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int iRun, boolean addMisAlignmts, String misAlgnFile) { if (event.hasBank("RUN::config") == false) { System.err.println("RUN CONDITIONS NOT READ!"); return; @@ -116,7 +116,7 @@ public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int Run = newRun; this.setRun(Run); - } + }*/ public int getRun() { return Run; @@ -243,7 +243,7 @@ public boolean processDataEvent(DataEvent event) { // continue; Ray ray = track.get_ray(); if(ray == null) { - ray = getRay(track.get_helix(),xb,yb); + ray = getRay(track.get_helix(),reader.getXbeam(),reader.getYbeam()); //System.out.println("curvature " + track.get_helix().get_curvature()); //System.out.println("doca " + track.get_helix().get_dca()); if(Math.abs(track.get_helix().get_curvature())>0.001) { @@ -255,9 +255,9 @@ public boolean processDataEvent(DataEvent event) { //System.out.println(ray.get_refPoint().toString()); - - int colsA = nAlignVars*((svtTopBottomSep ? 2*nCrossSVT : nCrossSVT) + nCrossBMT + (isCosmics ? 0:1)); - int rows = 2*nCrossSVT+nCrossBMT + (isCosmics ? 0:1); + int paramsFromBeamspot = (isCosmics || ! includeBeamspot ? 0:1); + int colsA = nAlignVars*((svtTopBottomSep ? 2*nCrossSVT : nCrossSVT) + nCrossBMT + paramsFromBeamspot); + int rows = 2*nCrossSVT+nCrossBMT + paramsFromBeamspot; Matrix A = new Matrix(rows, colsA);//not sure why there aren't 6 columns Matrix B = new Matrix(rows, 4); Matrix V = new Matrix(rows,rows); @@ -354,8 +354,8 @@ else if(cross.get_DetectorType() == BMTType.C) { }*/ } - if(!isCosmics) { - fillMatricesBeamspot(i, ray, A,B,V,m,c,I); + if(!isCosmics && includeBeamspot) { + fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); } As.add(A); @@ -406,6 +406,9 @@ private Ray getRay(Helix h,double xb, double yb) { Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + + //System.out.println("xb yb from db" + xb + yb); + //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); //if(u.y() <0) // u = u.multiply(-1); //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); @@ -467,8 +470,9 @@ private void fillMisc(DataEvent event, int runNum, int eventNum, List t boolean useDocaPhiZTandip=true; + boolean includeBeamspot = false; private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, - Matrix I){ + Matrix I, double xb, double yb){ // a point along the beam Vector3D xref = ray.get_refPoint().toVector3D(); //System.out.println("xref: " + xref.toStlString()); @@ -491,7 +495,7 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix //this should be about equal to the beam width - double resolution = 0.2; + double resolution = 0.5; V.set(i, i, Math.pow(resolution,2)); @@ -539,11 +543,11 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix if(orderTz >= 0) A.set(i, i*nAlignVars + orderTz, sp.z()); if(orderRx >= 0) - A.set(i, i*nAlignVars + orderRx, dmdr.x()); + A.set(i, i*nAlignVars + orderRx, -dmdr.x()); if(orderRy >= 0) - A.set(i, i*nAlignVars + orderRy, dmdr.y()); + A.set(i, i*nAlignVars + orderRy, -dmdr.y()); if(orderRz >= 0) - A.set(i, i*nAlignVars + orderRz, dmdr.z()); + A.set(i, i*nAlignVars + orderRz, -dmdr.z()); @@ -1400,13 +1404,13 @@ public boolean init() { System.out.println(" CVT YAML VARIATION NAME + "+variationName); System.out.println("SVT LOADING WITH VARIATION "+variationName); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); + /*DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); //cp = new HackConstantsProvider(cp); cp = SVTConstants.connect( cp ); cp.disconnect(); CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variationName)); xb = org.jlab.rec.cvt.Constants.getXb(); - yb = org.jlab.rec.cvt.Constants.getYb(); + yb = org.jlab.rec.cvt.Constants.getYb();*/ //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][0])); //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][1])); //SVTStripFactory svtFac = new SVTStripFactory(cp, true); @@ -1532,7 +1536,17 @@ public boolean init() { + " (" + line.end().x + ", "+ line.end().y + ", "+ line.end().z+"), "); }*/ - this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (isCosmics? 0 : 1)); + String useBeamspotStr = this.getEngineConfigString("useBeamspot"); + + if (useBeamspotStr!=null) { + System.out.println("["+this.getName()+"] treat beamspot as an additional measurement "+useBeamspotStr+" config chosen based on yaml"); + this.includeBeamspot = Boolean.valueOf(useBeamspotStr); + } else{ + System.out.println("["+this.getName()+"] treat beamspot as an additional measurement false [default]"); + + } + + this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (isCosmics || !includeBeamspot? 0 : 1)); String debug = this.getEngineConfigString("debug"); @@ -1549,7 +1563,7 @@ public boolean init() { return true; } - double xb, yb; + //double xb, yb; double maxResidualCutSVT; double maxResidualCutBMTC; @@ -1560,14 +1574,37 @@ public boolean init() { private void setAlignVars(String alignVars) { - String split[] = alignVars.split("[ \t]+"); - int i = 0; orderTx = -1; orderTy = -1; orderTz = -1; orderRx = -1; orderRy = -1; orderRz = -1; + if(alignVars.length() >2 && !alignVars.contains(" ")) { + for(int i = 0;i Date: Tue, 19 Oct 2021 10:33:27 -0400 Subject: [PATCH 185/291] removed an unnecessary print statement of track parameters. Should only be printed when debug is set to true --- .../main/java/org/jlab/rec/cvt/services/CVTAlignment.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 447f29c19..7e7ecdba8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -271,7 +271,10 @@ public boolean processDataEvent(DataEvent event) { q.set(2, 0, track.get_helix().get_Z0()); q.set(3, 0, track.get_helix().get_tandip()); - q.print(4, 4); + if(debug) { + System.out.println("track parameters"); + q.print(4, 4); + } int i = 0; boolean useNewFillMatrices = true; From 4600ceb8e3e6d03e7e16da2c47524c743b43d6d9 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 19 Oct 2021 17:30:37 +0200 Subject: [PATCH 186/291] CVT: writing out banks for events with no tracks --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 61 +++---------------- .../rec/cvt/services/TracksFromTargetRec.java | 5 +- 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 5a9c29305..f66a3e50b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -647,73 +647,28 @@ public void appendCVTBanks(DataEvent event, List cvtbanks = new ArrayList(); DataBank bank1 = this.fillSVTHitsBank(event, sVThits); - if (bank1 != null) { - svtbanks.add(bank1); - } + if (bank1 != null) event.appendBank(bank1); DataBank bank2 = this.fillBMTHitsBank(event, bMThits); - if (bank2 != null) { - bmtbanks.add(bank2); - } + if (bank2 != null) event.appendBank(bank2); DataBank bank3 = this.fillSVTClustersBank(event, sVTclusters); - if (bank3 != null) { - svtbanks.add(bank3); - } + if (bank3 != null) event.appendBank(bank3); DataBank bank4 = this.fillBMTClustersBank(event, bMTclusters); - if (bank4 != null) { - bmtbanks.add(bank4); - } + if (bank4 != null) event.appendBank(bank4); DataBank bank5 = this.fillSVTCrossesBank(event, crosses, zShift); - if (bank5 != null) { - svtbanks.add(bank5); - } + if (bank5 != null) event.appendBank(bank5); DataBank bank6 = this.fillBMTCrossesBank(event, crosses, zShift); - if (bank6 != null) { - bmtbanks.add(bank6); - } + if (bank6 != null) event.appendBank(bank6); - //found tracks DataBank bank7 = this.fillTracksBank(event, trks, zShift); - if (bank7 != null) { - cvtbanks.add(bank7); - } + if (bank7 != null) event.appendBank(bank7); - //found trajectories DataBank bank8 = this.fillHelicalTracksTrajectoryBank(event, trks, zShift); - if (bank8 != null) { - cvtbanks.add(bank8); - } - - if (svtbanks.size() == 3) { - event.appendBanks(svtbanks.get(0), svtbanks.get(1), svtbanks.get(2)); - } - if (svtbanks.size() == 2) { - event.appendBanks(svtbanks.get(0), svtbanks.get(1)); - } - if (svtbanks.size() == 1) { - event.appendBanks(svtbanks.get(0)); - } - if (bmtbanks.size() == 3) { - event.appendBanks(bmtbanks.get(0), bmtbanks.get(1), bmtbanks.get(2)); - } - if (bmtbanks.size() == 2) { - event.appendBanks(bmtbanks.get(0), bmtbanks.get(1)); - } - if (bmtbanks.size() == 1) { - event.appendBanks(bmtbanks.get(0)); - } - if (cvtbanks.size() == 2) { - event.appendBanks(cvtbanks.get(0), cvtbanks.get(1)); - } - if (cvtbanks.size() == 1) { - event.appendBanks(cvtbanks.get(0)); - } - - //event.show(); + if (bank8 != null) event.appendBank(bank8); } public void appendCVTCosmicsBanks(DataEvent event, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index e914e72b0..89395d442 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.services; import Jama.Matrix; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; @@ -177,7 +176,7 @@ public boolean processEvent(DataEvent event, List tracks = trkFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); for( int i=0;i 0) { recUtil.CleanupSpuriousCrosses(crosses, tracks, SVTGeom) ; - rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, tracks, shift); } + rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, tracks, shift); return true; From c70546aea04778c0756d1d9a72e6c6a039585048 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 19 Oct 2021 17:34:34 +0200 Subject: [PATCH 187/291] CVT: better checks on SVT cross error calculation --- .../java/org/jlab/rec/cvt/cross/Cross.java | 96 ++++++++++++++----- 1 file changed, 70 insertions(+), 26 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index a035e1178..3ce0fcf1f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -462,7 +462,7 @@ public Point3D getSVTCrossPoint(Vector3D trackDir, SVTGeometry geo) { return cross; } - /** + /** * Calculate the cross position error from the two strips and the track direction * @param trackDir track direction * @param geo VT geometry @@ -481,33 +481,77 @@ public Vector3D getSVTCrossError(Vector3D trackDir, SVTGeometry geo) { double sigma1 = geo.getSingleStripResolution(layer, this.get_Cluster1().get_SeedStrip().get_Strip(), local.z()); double sigma2 = geo.getSingleStripResolution(layer, this.get_Cluster2().get_SeedStrip().get_Strip(), local.z()); - double delta = 1e-3; // 1micron shift - Line3D strip1 = this.get_Cluster1().getLine(); - Line3D strip2 = this.get_Cluster2().getLine(); - - Vector3D t1 = strip1.direction().asUnit().cross(this.get_Cluster1().getN()).multiply(delta); - Line3D strip1Plus = new Line3D(strip1); - Line3D strip1Minus = new Line3D(strip1); - strip1Plus.translateXYZ(t1.x(), t1.y(), t1.z()); - strip1Minus.translateXYZ(-t1.x(),-t1.y(),-t1.z()); - - Vector3D t2 = strip2.direction().asUnit().cross(this.get_Cluster2().getN()).multiply(delta); - Line3D strip2Plus = new Line3D(strip2); - Line3D strip2Minus = new Line3D(strip2); - strip2Plus.translateXYZ(t2.x(), t2.y(), t2.z()); - strip2Minus.translateXYZ(-t2.x(),-t2.y(),-t2.z()); + // get the error associated to each strip + Vector3D error1 = this.getSVTCrossDerivative(1, trackDir, geo).multiply(sigma1); + Vector3D error2 = this.getSVTCrossDerivative(2, trackDir, geo).multiply(sigma2); + if(error1!=null && error2!=null) + error = new Vector3D(Math.sqrt(error1.x()*error1.x()+error2.x()*error2.x()), + Math.sqrt(error1.y()*error1.y()+error2.y()*error2.y()), + Math.sqrt(error1.z()*error1.z()+error2.z()*error2.z())); +// if(error.x()==0 && error.y()==0) System.out.println(cross.toString() + "\n" + error.toString()); + } + return error; + } + /** + * Calculate the cross derivative for the translation of one strip + * useful for the error calculation + * @param trackDir track direction + * @param geo VT geometry + * @return + */ + public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir, SVTGeometry geo) { + Vector3D error = null; + + // check the cluster to be used in the derivative calculation is either 1 or 2 + if(icluster<1 || icluster>2) return null; + + // if the croos position is not well defined, don't do anything + Point3D cross = this.getSVTCrossPoint(trackDir, geo); + if(cross==null) return null; + + int layer = this.get_Cluster1().get_Layer(); + int sector = this.get_Cluster1().get_Sector(); + + double delta = 1e-3; // 1micron shift + + // get the clusters + Cluster clusA = this.get_Cluster1(); + Cluster clusB = this.get_Cluster2(); + if(icluster==2) { + clusA = this.get_Cluster2(); + clusB = this.get_Cluster1(); + } + + // shift the selected cluster to the left and right of the line + Vector3D t = clusA.getLine().direction().asUnit().cross(clusA.getN()).multiply(delta); + Line3D stripAPlus = new Line3D(clusA.getLine()); + Line3D stripAMinus = new Line3D(clusA.getLine()); + stripAPlus.translateXYZ( t.x(), t.y(), t.z()); + stripAMinus.translateXYZ(-t.x(),-t.y(),-t.z()); - Point3D cross1Plus = geo.getCross(sector, layer, strip1Plus, strip2, trackDir); - Point3D cross1Minus = geo.getCross(sector, layer, strip1Minus, strip2, trackDir); - Point3D cross2Plus = geo.getCross(sector, layer, strip1, strip2Plus, trackDir); - Point3D cross2Minus = geo.getCross(sector, layer, strip1, strip2Minus, trackDir); - Vector3D error1 = cross1Minus.vectorTo(cross1Plus).multiply(sigma1/delta); - Vector3D error2 = cross2Minus.vectorTo(cross2Plus).multiply(sigma2/delta); - error = new Vector3D(Math.sqrt(error1.x()*error1.x()+error2.x()*error2.x()), - Math.sqrt(error1.y()*error1.y()+error2.y()*error2.y()), - Math.sqrt(error1.z()*error1.z()+error2.z()*error2.z())); - if(error.x()==0 && error.y()==0) System.out.println(cross.toString() + "\n" + error.toString()); + // calculate the shifted cross positions + Point3D crossAPlus = null; + Point3D crossAMinus = null; + if(clusA.get_Layer()%2 == 1) { + crossAPlus = geo.getCross(sector, layer, stripAPlus, clusB.getLine(), trackDir); + crossAMinus = geo.getCross(sector, layer, stripAMinus, clusB.getLine(), trackDir); } + else { + crossAPlus = geo.getCross(sector, layer, clusB.getLine(), stripAPlus, trackDir); + crossAMinus = geo.getCross(sector, layer, clusB.getLine(), stripAMinus, trackDir); + } + + // if at least one is non-null, calculate the derivative + if(crossAPlus!=null && crossAMinus!=null) { + error = crossAMinus.vectorTo(crossAPlus).multiply(1/delta); + } + else if(crossAPlus!=null) { + error = cross.vectorTo(crossAPlus).multiply(2/delta); + } + else if(crossAMinus!=null) { + error = crossAPlus.vectorTo(cross).multiply(2/delta); + } + return error; } From e65730eeaa75435507b28354a2a0fb91decd9fa7 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 19 Oct 2021 17:49:55 +0200 Subject: [PATCH 188/291] CVT: switched to using new adaptive swimming for helical tracks, first shot at optimizing swimming accuracy --- .../clas/tracking/kalmanfilter/Surface.java | 23 ++- .../kalmanfilter/helical/MeasVecs.java | 2 +- .../kalmanfilter/helical/StateVecs.java | 29 +++- .../jlab/clas/swimtools/ProbeCollection.java | 2 + .../java/org/jlab/clas/swimtools/Swim.java | 135 +++++++++++++++++- .../main/java/org/jlab/rec/cvt/Constants.java | 6 +- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 14 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 7 +- .../jlab/rec/cvt/services/RecUtilities.java | 29 ++-- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 2 +- .../jlab/rec/cvt/track/TrackListFinder.java | 2 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 22 +-- 12 files changed, 225 insertions(+), 48 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java index 90c78068c..91222f8d3 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -37,25 +37,29 @@ public class Surface implements Comparable { private double _l_over_X0; //this is for energy loss private double _Z_over_A_times_l; + // this is for swimming + public double swimAccuracy; public boolean notUsedInFit = false; public double hemisphere = 1; - public Surface(Plane3D plane3d, Point3D refrPoint, Point3D c1, Point3D c2) { + public Surface(Plane3D plane3d, Point3D refrPoint, Point3D c1, Point3D c2, double accuracy) { type = Type.PLANEWITHPOINT; plane = plane3d; refPoint = refrPoint; finitePlaneCorner1 = c1; finitePlaneCorner2 = c2; + swimAccuracy = accuracy; } - public Surface(Plane3D plane3d, Point3D endPoint1, Point3D endPoint2, Point3D c1, Point3D c2) { + public Surface(Plane3D plane3d, Point3D endPoint1, Point3D endPoint2, Point3D c1, Point3D c2, double accuracy) { type = Type.PLANEWITHLINE; plane = plane3d; lineEndPoint1 = endPoint1; lineEndPoint2 = endPoint2; finitePlaneCorner1 = c1; finitePlaneCorner2 = c2; + swimAccuracy = accuracy; } - public Surface(Plane3D plane3d, Strip strp, Point3D c1, Point3D c2) { + public Surface(Plane3D plane3d, Strip strp, Point3D c1, Point3D c2, double accuracy) { type = Type.PLANEWITHSTRIP; plane = plane3d; strip = strp; @@ -65,8 +69,9 @@ public Surface(Plane3D plane3d, Strip strp, Point3D c1, Point3D c2) { lineEndPoint2 = new Point3D(strip.getX()+strip.getLength()*strip.getUx(), strip.getY()+strip.getLength()*strip.getUy(), strip.getZ()+strip.getLength()*strip.getUz()); + swimAccuracy = accuracy; } - public Surface(Cylindrical3D cylinder3d, Strip strp) { + public Surface(Cylindrical3D cylinder3d, Strip strp, double accuracy) { type = Type.CYLINDERWITHSTRIP; cylinder = cylinder3d; strip = strp; @@ -74,20 +79,23 @@ public Surface(Cylindrical3D cylinder3d, Strip strp) { lineEndPoint2 = new Point3D(strip.getX()+strip.getLength()*strip.getUx(), strip.getY()+strip.getLength()*strip.getUy(), strip.getZ()+strip.getLength()*strip.getUz()); + swimAccuracy = accuracy; } - public Surface(Cylindrical3D cylinder3d, Point3D refrPoint) { + public Surface(Cylindrical3D cylinder3d, Point3D refrPoint, double accuracy) { type = Type.CYLINDERWITHPOINT; cylinder = cylinder3d; refPoint = refrPoint; + swimAccuracy = accuracy; } - public Surface(Cylindrical3D cylinder3d, Point3D endPoint1, Point3D endPoint2) { + public Surface(Cylindrical3D cylinder3d, Point3D endPoint1, Point3D endPoint2, double accuracy) { type = Type.CYLINDERWITHLINE; cylinder = cylinder3d; lineEndPoint1 = endPoint1; lineEndPoint2 = endPoint2; + swimAccuracy = accuracy; } - public Surface(Cylindrical3D cylinder3d, Arc3D refArc, Point3D endPoint1, Point3D endPoint2) { + public Surface(Cylindrical3D cylinder3d, Arc3D refArc, Point3D endPoint1, Point3D endPoint2, double accuracy) { type = Type.CYLINDERWITHARC; cylinder = cylinder3d; arc = refArc; @@ -97,6 +105,7 @@ public Surface(Cylindrical3D cylinder3d, Arc3D refArc, Point3D endPoint1, Point3 if(endPoint2 == null) { lineEndPoint2 = arc.end(); } + swimAccuracy = accuracy; } @Override diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index ab5bdb391..0b228446f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -201,7 +201,7 @@ public double h(int k, StateVec stateVec) { } private double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; - double sqrt_epsilon = Math.sqrt(2.2*1.e-16); + double sqrt_epsilon = Math.sqrt(2.2*1.e-16); //RDV, why so small? private double[] Hval = new double[5]; public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim swimmer, int dir) { StateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 55ebb5fdc..fa65caab3 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -13,6 +13,7 @@ import org.jlab.clas.tracking.kalmanfilter.helical.MeasVecs.MeasVec; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Plane3D; public class StateVecs { @@ -172,7 +173,26 @@ else if(mv.surface.cylinder!=null) { Point3D point = new Point3D(mv.surface.plane.point().x()/units, mv.surface.plane.point().y()/units, mv.surface.plane.point().z()/units); - swimPars = swim.SwimPlane(norm,point,0.005/units); + double accuracy = mv.surface.swimAccuracy/units; +// swimPars = swim.SwimToPlaneBoundary(norm.dot(point.toVector3D()), norm, 1, 0.005/units); +// swimPars = swim.SwimPlane(norm,point,0.005/units); +// System.out.println(mv.surface.plane.point() + " " + current + " " + kVec.k); +// double distance = Math.abs(current.vectorTo(mv.surface.plane.point()).dot(norm)); +// double stepsize = Math.min(distance/2, 0.5);// System.out.println(distance + " " + stepsize); + swimPars = swim.AdaptiveSwimPlane(point.x(), point.y(), point.z(), norm.x(), norm.y(), norm.z(), accuracy); +// Point3D swimP = new Point3D(swimPars[0], swimPars[1], swimPars[2]); +// Vector3D swimD = new Vector3D(swimPars[3], swimPars[4], swimPars[5]); +// Line3D swimL = new Line3D(swimP, swimD); +// Plane3D plane = new Plane3D(point, norm); +// Point3D swimF = new Point3D(); +// plane.intersection(swimL, swimF); +// Point3D p0 = new Point3D(swimPars0[0], swimPars0[1], swimPars0[2]); +// Point3D p1 = new Point3D(swimPars1[0], swimPars1[1], swimPars1[2]); +// Point3D p = new Point3D(swimPars[0], swimPars[1], swimPars[2]); +// System.out.println(); +// System.out.println(swimPars0[0] + " " + swimPars0[1] + " " + swimPars0[2] + " " + point.vectorTo(p0).dot(norm)); +// System.out.println(swimPars1[0] + " " + swimPars1[1] + " " + swimPars1[2] + " " + point.vectorTo(p1).dot(norm)); +// System.out.println(swimPars[0] + " " + swimPars[1] + " " + swimPars[2] + " " + point.vectorTo(p).dot(norm)); if(swimPars==null) return null; for(int j =0; j < 3; j++) { @@ -214,7 +234,11 @@ else if(mv.surface.cylinder!=null) { Point3D p2 = new Point3D(mv.surface.cylinder.getAxis().end().x()/units, mv.surface.cylinder.getAxis().end().y()/units, mv.surface.cylinder.getAxis().end().z()/units) ; - swimPars = swim.SwimGenCylinder(p1,p2,r/units); + double accuracy = mv.surface.swimAccuracy/units; +// swimPars = swim.SwimGenCylinder(p1,p2,r/units); + swimPars = swim.AdaptiveSwimCylinder(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z(), r/units, accuracy); +// System.out.println(swimPars2[0] + " " + swimPars2[1] + " " + swimPars2[2]); +// System.out.println(swimPars[0] + " " + swimPars[1] + " " + swimPars[2]); if(swimPars==null) return null; for(int j =0; j < 3; j++) { @@ -716,6 +740,7 @@ public Helix setTrackPars() { return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, X0.get(0), Y0.get(0), util.units); } public StateVec initSV = new StateVec(0); + //RDV KF not used public void init(Helix trk, Matrix cov, KFitter kf, Swim swimmer) { this.units = trk.getUnitScale(); 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 d305eeca3..043ffec40 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 @@ -20,6 +20,7 @@ public class ProbeCollection { public final cnuphys.swimZ.SwimZ CF_z; // composite field - for swimming to fixed z public final cnuphys.swim.Swimmer RCF; // rotated composite field public final cnuphys.swim.Swimmer CF; // composite field + public final cnuphys.adaptiveSwim.AdaptiveSwimmer AS; // adaptive swimmer //Probes: public final RotatedCompositeProbe RCP; public final CompositeProbe CP; @@ -34,5 +35,6 @@ public ProbeCollection() { CF_z = new SwimZ(MagneticFields.getInstance().getCompositeField()); RCF = new cnuphys.swim.Swimmer(MagneticFields.getInstance().getRotatedCompositeField()); CF = new cnuphys.swim.Swimmer(MagneticFields.getInstance().getCompositeField()); + AS = new cnuphys.adaptiveSwim.AdaptiveSwimmer(MagneticFields.getInstance().getCompositeField()); } } 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 488f03847..ee7c4541d 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 @@ -5,6 +5,7 @@ */ package org.jlab.clas.swimtools; +import cnuphys.adaptiveSwim.AdaptiveSwimException; import cnuphys.rk4.IStopper; import cnuphys.rk4.RungeKuttaException; import cnuphys.swim.SwimTrajectory; @@ -16,7 +17,11 @@ import org.jlab.geom.prim.Vector3D; 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; /** * * @author ziegler @@ -591,6 +596,8 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { return value; } + + private class SphericalBoundarySwimStopper implements IStopper { private double _finalPathLength = Double.NaN; @@ -742,7 +749,7 @@ public double[] SwimToPlaneBoundary(double d_cm, Vector3D n, int dir) { if(this.SwimUnPhys) return null; double d = d_cm / 100; - + double hdata[] = new double[3]; // using adaptive stepsize @@ -906,4 +913,130 @@ 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) { + + 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); + + + // 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, + 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) { + + 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); + + + // using adaptive stepsize + if(this.SwimUnPhys) + return null; + + 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) { + + 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, + accuracy, _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/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index e9d4584c0..11edda239 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.Map; import org.jlab.clas.swimtools.Swim; -import org.jlab.rec.cvt.bmt.BMTConstants; public class Constants { @@ -28,6 +27,11 @@ public class Constants { public static final double CIRCLEFIT_MAXCHI2 = 100; + public static final double DEFAULTSWIMACC = 0.020; // in mm + public static final double SWIMACCURACYSVT = 0.010; // in mm + public static final double SWIMACCURACYBMT = 0.050; // in mm + public static final double SWIMACCURACYCD = 0.500; // in mm + private static boolean isCosmicsData = false; private static boolean SVTOnly = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 05c2c99f0..5c409cc2f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -299,19 +299,19 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double zpos = dbprovider.getDouble("/geometry/cvt/mvt/position/z", 0 ); // hardcode gemc rotation: set angles to 0 to null it Vector3D gemcRot = new Vector3D(0,0,0); - Point3D bmtCenter = new Point3D(0,0,-94.7); // the original BMT Center - Point3D bmtShift = new Point3D(bmtCenter); - bmtCenter.rotateZ(Math.toRadians(gemcRot.z())); - bmtCenter.rotateY(Math.toRadians(gemcRot.y())); - bmtCenter.rotateX(Math.toRadians(gemcRot.x())); - bmtShift.translateXYZ(-bmtCenter.x(), -bmtCenter.y(), -bmtCenter.z()); + Point3D gemcCenter = new Point3D(0,0,-94.7); // the original BMT Center + Point3D gemcShift = new Point3D(gemcCenter); + gemcCenter.rotateZ(Math.toRadians(gemcRot.z())); + gemcCenter.rotateY(Math.toRadians(gemcRot.y())); + gemcCenter.rotateX(Math.toRadians(gemcRot.x())); + gemcShift.translateXYZ(-gemcCenter.x(), -gemcCenter.y(), -gemcCenter.z()); for (int row = 0; row setMeasVecs(Seed trkcand, Swim swim) { Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), new Vector3D(0,0,1)); Surface meas0 = new Surface(pln0,new Point3D(Constants.getXb(),Constants.getYb(),0), - new Point3D(Constants.getXb()-300,Constants.getYb(),0), new Point3D(Constants.getXb()+300,Constants.getYb(),0)); + new Point3D(Constants.getXb()-300,Constants.getYb(),0), new Point3D(Constants.getXb()+300,Constants.getYb(),0), Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); meas0.setError(1); @@ -141,7 +141,7 @@ public List setMeasVecs(StraightTrack trkcand, Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), new Vector3D(0,0,1)); Surface meas0 = new Surface(pln0,new Point3D(0,0,0), - new Point3D(-300,0,0), new Point3D(300,0,0)); + new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); meas0.setError(1); @@ -180,7 +180,7 @@ public List setMeasVecs(StraightTrack trkcand, Plane3D pln = new Plane3D(endPt1,cls.get(j).getN()); // Point3D Or = sgeo.getPlaneModuleOrigin(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); // Point3D En = sgeo.getPlaneModuleEnd(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); - Surface meas = new Surface(pln, strp, cls.get(j).origin(), cls.get(j).end()); + Surface meas = new Surface(pln, strp, cls.get(j).origin(), cls.get(j).end(), Constants.SWIMACCURACYSVT); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setSector(cls.get(j).get_Sector()); double err = cls.get(j).get_Resolution(); @@ -216,7 +216,7 @@ public List setMeasVecs(StraightTrack trkcand, bgeo.toLocal(point, layer, sector); Strip strp = new Strip(id, ce, point.x(), point.y(), phi); - Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp); + Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp, Constants.SWIMACCURACYBMT); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setTransformation(bgeo.toGlobal(layer,sector)); meas.setSector(trkcand.get(i).get_Sector()); @@ -233,7 +233,7 @@ else if (trkcand.get(i).get_Type()==BMTType.C) { Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); Strip strp = new Strip(id, ce, arc); - Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp); + Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp, Constants.SWIMACCURACYBMT); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); meas.setTransformation(bgeo.toGlobal(layer,sector)); @@ -268,7 +268,7 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrkNew (List allClusters, List2*Math.PI/SVTGeometry.NSECTORS[ilayer]) continue; - int key = sgeo.getModuleId(layer, sector); + int key = SVTGeometry.getModuleId(layer, sector); // calculate trajectory Point3D traj = null; - Point3D p = sgeo.getModule(layer, sector).origin(); - Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.SwimPlane(n, pm, 1E-3); + Point3D p = sgeo.getModule(layer, sector).origin(); + Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), Constants.DEFAULTSWIMACC/10); if(inters!=null) { traj = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); } @@ -334,6 +334,7 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrk (List allClusters, List seedCluster, Helix helix, double P, int Q, SVTGeometry sgeo, Swim swimmer) { Map clusMap = new HashMap(); @@ -368,10 +369,10 @@ public List FindClustersOnTrk (List allClusters, List if(sector == -1) continue; - Vector3D n = sgeo.getNormal(layer, sector); - Point3D p = sgeo.getModule(layer, sector).origin(); - Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.SwimPlane(n, pm, 1E-3); + Vector3D n = sgeo.getNormal(layer, sector); + Point3D p = sgeo.getModule(layer, sector).origin(); + Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), 2*Constants.SWIMACCURACYSVT/10); if(inters!=null) { Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index fdd009479..0e6d5f7a3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -87,7 +87,7 @@ public Line3D getModule(int layer, int sector) { line.end().x, line.end().y, line.end().z); } - public int getModuleId(int layer, int sector) { + public static int getModuleId(int layer, int sector) { return layer*100+sector; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 237ee3418..b39accb96 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -63,7 +63,7 @@ public List getTracks(List cands, trk.get_P(), charge, maxPathLength) ; - double[] pointAtCylRad = cvtSwim.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,0), Constants.CTOFINNERRADIUS/10); + double[] pointAtCylRad = cvtSwim.AdaptiveSwimRho(Constants.CTOFINNERRADIUS/10, Constants.SWIMACCURACYCD); if(pointAtCylRad!=null) { trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index deb9850a1..a4d798662 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -138,10 +138,11 @@ public Trajectory findTrajectory(Track trk, if(sector == -1) continue; - Vector3D n = svt_geo.getNormal(layer, sector); - Point3D p = svt_geo.getModule(layer, sector).origin(); - Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.SwimPlane(n, pm, 5E-4); + Vector3D n = svt_geo.getNormal(layer, sector); + Point3D p = svt_geo.getModule(layer, sector).origin(); + Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + double accuracy = 2*Constants.SWIMACCURACYSVT/10; + inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), accuracy); path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); @@ -202,13 +203,14 @@ public Trajectory findTrajectory(Track trk, int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); Line3D axis = bmt_geo.getAxis(layer, sector); - Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); - Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); + Point3D a1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); + Point3D a2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); + double accuracy = Constants.SWIMACCURACYBMT/10; // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), // trk.get_P(), trk.get_Q(), // 5.0) ; - inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius); + inters = swimmer.AdaptiveSwimCylinder(a1.x(), a1.y(), a1.z(), a2.x(), a2.y(), a2.z(), radius, accuracy); double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); path = path + inters[6]; //if(r>(radius - BMTConstants.LYRTHICKN)/10) { @@ -253,7 +255,7 @@ public Trajectory findTrajectory(Track trk, swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; // swim to CTOF double radius = ctof_geo.getRadius(1); - inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius); + inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); // update parameters double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); @@ -287,8 +289,8 @@ public Trajectory findTrajectory(Track trk, // swim to CTOF Point3D center = cnd_geo.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); double radius = Math.sqrt(center.x()*center.x()+center.y()*center.y()); - inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius); - // update parameters + inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); + // update parameters double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); From 6bf5cf720c6bfd5ec2d3c7eabb249aba330eed5d Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 15:55:03 +0200 Subject: [PATCH 189/291] updating yamls to use the newly relocated io service and fixing null exceptions due to different behaviour of the new swimmer compared to the old --- etc/services/data.yaml | 4 ++-- etc/services/eb.yaml | 4 ++-- etc/services/kpp.yaml | 4 ++-- etc/services/mc.yaml | 4 ++-- etc/services/swaps.yaml | 4 ++-- .../org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 9 +++------ 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/etc/services/data.yaml b/etc/services/data.yaml index 84f710609..c3fad64ae 100644 --- a/etc/services/data.yaml +++ b/etc/services/data.yaml @@ -1,9 +1,9 @@ io-services: reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader + class: org.jlab.io.clara.HipoToHipoReader name: HipoToHipoReader writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter + class: org.jlab.io.clara.HipoToHipoWriter name: HipoToHipoWriter services: - class: org.jlab.clas.swimtools.MagFieldsEngine diff --git a/etc/services/eb.yaml b/etc/services/eb.yaml index 1929e11af..a0372bfa0 100644 --- a/etc/services/eb.yaml +++ b/etc/services/eb.yaml @@ -1,9 +1,9 @@ io-services: reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader + class: org.jlab.io.clara.HipoToHipoReader name: HipoToHipoReader writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter + class: org.jlab.io.clara.HipoToHipoWriter name: HipoToHipoWriter services: - class: org.jlab.service.eb.EBTBEngine diff --git a/etc/services/kpp.yaml b/etc/services/kpp.yaml index 213d3d5cb..40660b0fe 100644 --- a/etc/services/kpp.yaml +++ b/etc/services/kpp.yaml @@ -1,9 +1,9 @@ io-services: reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader + class: org.jlab.io.clara.HipoToHipoReader name: HipoToHipoReader writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter + class: org.jlab.io.clara.HipoToHipoWriter name: HipoToHipoWriter services: - class: org.jlab.clas.swimtools.MagFieldsEngine diff --git a/etc/services/mc.yaml b/etc/services/mc.yaml index fbd3466e2..40d172b55 100644 --- a/etc/services/mc.yaml +++ b/etc/services/mc.yaml @@ -1,9 +1,9 @@ io-services: reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader + class: org.jlab.io.clara.HipoToHipoReader name: HipoToHipoReader writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter + class: org.jlab.io.clara.HipoToHipoWriter name: HipoToHipoWriter services: - class: org.jlab.clas.swimtools.MagFieldsEngine diff --git a/etc/services/swaps.yaml b/etc/services/swaps.yaml index 662ded542..2ff5ae047 100644 --- a/etc/services/swaps.yaml +++ b/etc/services/swaps.yaml @@ -2,10 +2,10 @@ # Note, it must come before all other services. io-services: reader: - class: org.jlab.clas.std.services.convertors.HipoToHipoReader + class: org.jlab.io.clara.HipoToHipoReader name: HipoToHipoReader writer: - class: org.jlab.clas.std.services.convertors.HipoToHipoWriter + class: org.jlab.io.clara.HipoToHipoWriter name: HipoToHipoWriter services: - class: org.jlab.service.swaps.SwapEngine diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index a4d798662..741aab4e7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -211,8 +211,8 @@ public Trajectory findTrajectory(Track trk, // trk.get_P(), trk.get_Q(), // 5.0) ; inters = swimmer.AdaptiveSwimCylinder(a1.x(), a1.y(), a1.z(), a2.x(), a2.y(), a2.z(), radius, accuracy); - double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); - path = path + inters[6]; + if(inters!=null) { + path = path + inters[6]; //if(r>(radius - BMTConstants.LYRTHICKN)/10) { StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); @@ -241,10 +241,7 @@ public Trajectory findTrajectory(Track trk, stVec.set_CalcCentroidStrip(cent); } stateVecs.add(stVec); - //} - //else { - // inters=null; - //} + } } } // CTOF From 79d6dcebf55165c8de6df71eb17b0d21d3a6eeeb Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 16:07:46 +0200 Subject: [PATCH 190/291] one more null exception fix --- .../rec/cvt/trajectory/TrajectoryFinder.java | 101 ++++++++---------- 1 file changed, 47 insertions(+), 54 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 741aab4e7..d3e0c6012 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -206,42 +206,37 @@ public Trajectory findTrajectory(Track trk, Point3D a1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); Point3D a2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); double accuracy = Constants.SWIMACCURACYBMT/10; - // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, - // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - // trk.get_P(), trk.get_Q(), - // 5.0) ; inters = swimmer.AdaptiveSwimCylinder(a1.x(), a1.y(), a1.z(), a2.x(), a2.y(), a2.z(), radius, accuracy); - if(inters!=null) { - path = path + inters[6]; - //if(r>(radius - BMTConstants.LYRTHICKN)/10) { - StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); - stVec.set_planeIdx(l); + if(inters==null) break; // give up on this track if swimming failed + + path = path + inters[6]; + StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); + stVec.set_planeIdx(l); // double phiPos = Math.atan2(stVec.y(),stVec.x()); // //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); // int sector = bmt_geo.getSector(layer,phiPos); - stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); - stVec.set_SurfaceSector(sector); - stVec.set_SurfaceLayer(l+1); - stVec.set_ID(trk.get_Id()); - stVec.set_Path(path*10); - Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); - this.fill_HelicalTrkAngleWRTBMTTangentPlane(dir, stVec); - //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); - stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(region, - new Point3D(stVec.x(),stVec.y(),stVec.z()))); - stVec.set_Path(path*10); - stVec.set_ID(trk.get_Id()); - - String bmtSt1 = "2."; - bmtSt1+=sector; - bmtSt1 += "."; - bmtSt1+=(l+1); - if(ClsMap.get(bmtSt1)!=null) { - double cent = ClsMap.get(bmtSt1); - stVec.set_CalcCentroidStrip(cent); - } - stateVecs.add(stVec); + stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); + stVec.set_SurfaceSector(sector); + stVec.set_SurfaceLayer(l+1); + stVec.set_ID(trk.get_Id()); + stVec.set_Path(path*10); + Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); + this.fill_HelicalTrkAngleWRTBMTTangentPlane(dir, stVec); + //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); + stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(region, + new Point3D(stVec.x(),stVec.y(),stVec.z()))); + stVec.set_Path(path*10); + stVec.set_ID(trk.get_Id()); + + String bmtSt1 = "2."; + bmtSt1+=sector; + bmtSt1 += "."; + bmtSt1+=(l+1); + if(ClsMap.get(bmtSt1)!=null) { + double cent = ClsMap.get(bmtSt1); + stVec.set_CalcCentroidStrip(cent); } + stateVecs.add(stVec); } } // CTOF @@ -254,11 +249,10 @@ public Trajectory findTrajectory(Track trk, double radius = ctof_geo.getRadius(1); inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); // update parameters - double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); - intersPhi = Math.atan2(inters[4], inters[3]); - intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - path = path + inters[6]; - //if(r>=radius) { + if(inters!=null) { + intersPhi = Math.atan2(inters[4], inters[3]); + intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_SurfaceDetector(DetectorType.CTOF.getDetectorId()); stVec.set_SurfaceSector(1); @@ -269,10 +263,8 @@ public Trajectory findTrajectory(Track trk, stVec.set_TrkToModuleAngle(0); stVec.set_Path(path*10); stateVecs.add(stVec); - - //} - //else inters=null; } + } // CND if(cnd_geo!=null && inters!=null) { // don't swim to CND if swimming to CTOF failed for(int ilayer=0; ilayer Date: Wed, 20 Oct 2021 16:13:00 +0200 Subject: [PATCH 191/291] one more null exception fix --- .../main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index d3e0c6012..31b687a48 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -281,7 +281,6 @@ public Trajectory findTrajectory(Track trk, inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); // update parameters if(inters!=null) { - double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); path = path + inters[6]; From 73ea1349cfc3104cffdbacfb382b5c701ed3770e Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 16:20:16 +0200 Subject: [PATCH 192/291] one more attempt --- .../rec/cvt/trajectory/TrajectoryFinder.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 31b687a48..ceb254944 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -279,22 +279,21 @@ public Trajectory findTrajectory(Track trk, Point3D center = cnd_geo.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); double radius = Math.sqrt(center.x()*center.x()+center.y()*center.y()); inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); + if(inters==null) break; // give up on this track if swimming failed // update parameters - if(inters!=null) { - intersPhi = Math.atan2(inters[4], inters[3]); - intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - path = path + inters[6]; - StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); - stVec.set_SurfaceDetector(DetectorType.CND.getDetectorId()); - stVec.set_SurfaceSector(1); - stVec.set_SurfaceLayer(ilayer+1); - stVec.set_ID(trk.get_Id()); - stVec.set_TrkPhiAtSurface(intersPhi); - stVec.set_TrkThetaAtSurface(intersTheta); - stVec.set_TrkToModuleAngle(0); - stVec.set_Path(path*10); - stateVecs.add(stVec); - } + intersPhi = Math.atan2(inters[4], inters[3]); + intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + path = path + inters[6]; + StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); + stVec.set_SurfaceDetector(DetectorType.CND.getDetectorId()); + stVec.set_SurfaceSector(1); + stVec.set_SurfaceLayer(ilayer+1); + stVec.set_ID(trk.get_Id()); + stVec.set_TrkPhiAtSurface(intersPhi); + stVec.set_TrkThetaAtSurface(intersTheta); + stVec.set_TrkToModuleAngle(0); + stVec.set_Path(path*10); + stateVecs.add(stVec); } } From 0fa65bc42d786d077ea28f15ceb3982ff3616bfd Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 16:40:53 +0200 Subject: [PATCH 193/291] one more attempt 2 --- .../org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index ceb254944..716bae821 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -141,8 +141,10 @@ public Trajectory findTrajectory(Track trk, Vector3D n = svt_geo.getNormal(layer, sector); Point3D p = svt_geo.getModule(layer, sector).origin(); Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - double accuracy = 2*Constants.SWIMACCURACYSVT/10; + double accuracy = Constants.DEFAULTSWIMACC/10; inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), accuracy); + if(inters==null) break; // give up on this track if swimming failed + path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); @@ -199,13 +201,13 @@ public Trajectory findTrajectory(Track trk, // RDV: tried using this to determine the sector but t is giving bogus number //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); double radius = bmt_geo.getRadiusMidDrift(layer)/10; - inters = swimmer.SwimRho(radius); + double accuracy = Constants.SWIMACCURACYBMT/10; + inters = swimmer.AdaptiveSwimRho(radius, accuracy); int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); Line3D axis = bmt_geo.getAxis(layer, sector); Point3D a1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); Point3D a2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); - double accuracy = Constants.SWIMACCURACYBMT/10; inters = swimmer.AdaptiveSwimCylinder(a1.x(), a1.y(), a1.z(), a2.x(), a2.y(), a2.z(), radius, accuracy); if(inters==null) break; // give up on this track if swimming failed From eab9d2436dc86b7e79e957cfa3754183905a63d9 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 16:52:28 +0200 Subject: [PATCH 194/291] CVT : fixed bug in cross error calculation --- .../cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 3ce0fcf1f..8d3067937 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -549,7 +549,7 @@ else if(crossAPlus!=null) { error = cross.vectorTo(crossAPlus).multiply(2/delta); } else if(crossAMinus!=null) { - error = crossAPlus.vectorTo(cross).multiply(2/delta); + error = crossAMinus.vectorTo(cross).multiply(2/delta); } return error; From 7fa8286257a6065015d17764f470b2af8e1e2367 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 20 Oct 2021 17:05:51 +0200 Subject: [PATCH 195/291] CVT: fixing more exception --- .../main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 716bae821..d8f1fc4ac 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -203,6 +203,7 @@ public Trajectory findTrajectory(Track trk, double radius = bmt_geo.getRadiusMidDrift(layer)/10; double accuracy = Constants.SWIMACCURACYBMT/10; inters = swimmer.AdaptiveSwimRho(radius, accuracy); + if(inters==null) break; // give up on this track if swimming failed int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); Line3D axis = bmt_geo.getAxis(layer, sector); From 201d6ea0164422f0020e21beb7f382672ac415c3 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 25 Oct 2021 23:37:57 +0200 Subject: [PATCH 196/291] CVT: updated cosmic tracking to support rotations based on existing methods, code cleanup and two relevant bug fixes - cross point update based on tracks was wrong for BMT-Z in case of rotations; - cluster residual method was wrong for BMT: this didn't affect the KF but only some utility method. --- .../kalmanfilter/helical/MeasVecs.java | 5 - .../kalmanfilter/helical/StateVecs.java | 87 +++----- .../kalmanfilter/straight/KFitter.java | 2 - .../kalmanfilter/straight/MeasVecs.java | 31 ++- .../kalmanfilter/straight/StateVecs.java | 6 +- .../main/java/org/jlab/rec/cvt/Constants.java | 4 +- .../org/jlab/rec/cvt/banks/HitReader.java | 23 -- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 4 + .../org/jlab/rec/cvt/cluster/Cluster.java | 13 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 102 ++++----- .../cross/StraightTrackCrossListFinder.java | 192 ++++++++--------- .../org/jlab/rec/cvt/fit/LineFitPars.java | 10 + .../rec/cvt/services/CosmicTracksRec.java | 78 +++---- .../jlab/rec/cvt/services/RecUtilities.java | 130 ++++-------- .../org/jlab/rec/cvt/svt/SVTParameters.java | 4 - .../org/jlab/rec/cvt/track/StraightTrack.java | 37 +++- .../rec/cvt/track/TrackCandListFinder.java | 164 ++++++++++----- .../java/org/jlab/rec/cvt/trajectory/Ray.java | 41 +++- .../rec/cvt/trajectory/TrajectoryFinder.java | 199 ++++++++++-------- 19 files changed, 570 insertions(+), 562 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 0b228446f..06eb7c08a 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.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.tracking.kalmanfilter.helical; import java.util.ArrayList; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index fa65caab3..ddef998ac 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -134,65 +134,44 @@ else if(mv.surface.cylinder!=null) { return value; } else { if(mv.surface.plane!=null) { - //Update B -// double r0 = mv.surface.finitePlaneCorner1.toVector3D().dot(mv.surface.plane.normal()); -// double stepSize = 5; //mm -// int nSteps = (int) (r0/stepSize); -// -// double dist = 0; -// -// for(int i = 1; i2*Math.PI) value-=Math.signum(value)*2*Math.PI; } } return value; @@ -129,15 +128,9 @@ public double getPhiATZ(StateVec stateVec) { } public double getPhi(StateVec stateVec) { - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - - double v = (cln.origin().z()-stateVec.z)/cln.direction().z(); - double xs = stateVec.x+v*cln.direction().x(); - double ys = stateVec.y+v*cln.direction().y(); - - Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). - vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); - return n.phi(); + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + this.measurements.get(stateVec.k).surface.toLocal().apply(sv); + return sv.toVector3D().phi(); } public double h(int k, StateVec stateVec) { diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index c23378b44..e0a0d603d 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -1,6 +1,5 @@ package org.jlab.clas.tracking.kalmanfilter.straight; -import org.jlab.clas.tracking.kalmanfilter.straight.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -13,7 +12,6 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.straight.MeasVecs.MeasVec; import org.jlab.clas.tracking.trackrep.Helix; -import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.geom.prim.Line3D; @@ -110,8 +108,8 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim double l = (-(ref.x()*u.x()+ref.y()*u.y())+delta)/(u.x()*u.x()+u.y()*u.y()); if(Math.signum(ref.y()+l*u.y())!=mv.hemisphere) { l = (-(ref.x()*u.x()+ref.y()*u.y())-delta)/(u.x()*u.x()+u.y()*u.y()); - } - + } + Point3D cylInt = new Point3D(ref.x()+l*u.x(),ref.y()+l*u.y(),ref.z()+l*u.z()); mv.surface.toGlobal().apply(cylInt); // mv.surface.toGlobal().apply(ref); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 11edda239..64562519e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -33,7 +33,9 @@ public class Constants { public static final double SWIMACCURACYCD = 0.500; // in mm private static boolean isCosmicsData = false; - + public static final double COSMICSMINRESIDUALX = 120; // in mm + public static final double COSMICSMINRESIDUALZ = 12; // in mm + private static boolean SVTOnly = false; public static final boolean trk_comesfrmOrig = true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index 55182a131..ae5393f7a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -1,14 +1,9 @@ package org.jlab.rec.cvt.banks; -import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.geom.prim.Line3D; - -import org.jlab.geom.prim.Vector3D; -import org.jlab.geometry.prim.Line3d; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; @@ -211,24 +206,6 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, SvtStrip.set_Line(geo.getStrip(layer[i], sector[i], strip[i])); SvtStrip.set_Module(geo.getModule(layer[i], sector[i])); SvtStrip.set_Normal(geo.getNormal(layer[i], sector[i])); - -// double[][] X = geo.getStripEndPoints(SvtStrip.get_Strip(), (layer[i] - 1) % 2); -// Point3D EP1 = geo.transformToFrame(sector[i], layer[i], X[0][0], 0, X[0][1], "lab", ""); -// Point3D EP2 = geo.transformToFrame(sector[i], layer[i], X[1][0], 0, X[1][1], "lab", ""); -//// SvtStrip.set_Line(new Line3D(EP1, EP2)); -//// if(Constants.geoDebug) System.out.println("Strip: layer " + layer[i] + " sector " + sector[i] + "\n" + SvtStrip.get_Line().toString()); -//// SvtStrip.set_Normal(geo.findBSTPlaneNormal(sector[i], layer[i])); // add normal to the plane defined from the strip midpoint -//// SvtStrip.set_Module(new Line3D(geo.getPlaneModuleOrigin(sector[i], layer[i]), geo.getPlaneModuleEnd(sector[i], layer[i]))); -// if(Constants.geoDebug) { -// Vector3D nn = geo.findBSTPlaneNormal(sector[i], layer[i]); -// Point3D l1 = geo.getPlaneModuleOrigin(sector[i], layer[i]); -// Point3D l2 = geo.getPlaneModuleEnd(sector[i], layer[i]); -// if(EP1.distance(SvtStrip.get_Module().origin())>1E-3 || EP2.distance(SvtStrip.get_Module().end())>1E-3 || -// l1.distance(SvtStrip.get_Line().origin())>1E-3 || l2.distance(SvtStrip.get_Line().end())>1E-3 || nn.cross(SvtStrip.get_Normal()).mag()>1E-6) { -// System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); -// System.out.println("Module \n" + SvtStrip.get_Module().toString()); -// } -// } if(layer[i]%2==1) { SvtStrip.setToverX0(SVTGeometry.getToverX0()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 2e1cacb87..6b4948b8c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -42,6 +42,10 @@ public int getNLayers() { return BMTConstants.NLAYERS; } + public int getNSectors() { + return BMTConstants.NSECTORS; + } + /** * Return layer number for a given region and detector type * @param region (1-3) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 753acd153..b9eea57b6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -574,9 +574,9 @@ public double residual(Point3D traj) { Point3D local = new Point3D(traj); this.toLocal().apply(local); if(this.get_Type()==BMTType.C) - value = local.z()-this.get_Centroid(); + value = local.z()-this.get_CentroidValue(); else { - value = local.toVector3D().phi()-this.get_Centroid(); + value = local.toVector3D().phi()-this.get_CentroidValue(); if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; } } @@ -657,7 +657,7 @@ public void setTrakInters(Point3D _TrakInters) { this._TrakInters = _TrakInters; } - public Surface measurement(int mlayer) { + public Surface measurement(int layerID) { Surface surface = null; if(this.get_Detector()==DetectorType.BST) { Point3D endPt1 = this.getLine().origin(); @@ -669,7 +669,7 @@ public Surface measurement(int mlayer) { Line3D module = this.get(0).get_Strip().get_Module(); surface = new Surface(plane, strp, module.origin(), module.end(), Constants.SWIMACCURACYSVT); surface.hemisphere = Math.signum(this.center().y()); - surface.setLayer(mlayer); + surface.setLayer(layerID); surface.setSector(this.get_Sector()); surface.setError(this.get_Resolution()*this.get_Resolution()); surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); @@ -691,7 +691,7 @@ public Surface measurement(int mlayer) { } surface.setTransformation(this.toGlobal()); - surface.setLayer(mlayer); + surface.setLayer(layerID); surface.setSector(this.get_Sector()); surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); } @@ -700,11 +700,10 @@ public Surface measurement(int mlayer) { /** * - * @return cluster info. about location and number of hits contained in it */ public void printInfo() { String s = " cluster: Detector " + this.get_Detector().getName() +" Detector Type " + this.get_Type().getName() + " ID " + this.get_Id() + " Sector " + this.get_Sector() - + " Layer " + this.get_Layer() + " Radius " + this.getRadius()+ " Size " + this.size() +" centroid "+this.get_Centroid(); + + " Layer " + this.get_Layer() + " Radius " + this.getRadius()+ " Size " + this.size() +" centroid "+this.get_Centroid() + this.size() +" centroidValue "+this.get_CentroidValue(); System.out.println(s); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 8d3067937..e16dcd11a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -355,6 +355,15 @@ public Cross get_MatchedCCross() { public void set_MatchedCCross(Cross _MatchedCCross) { this._MatchedCCross = _MatchedCCross; } + + public void resetCross(SVTGeometry geo) { + this.set_Dir(null); + this.set_DirErr(null); + if(this.get_Detector()==DetectorType.BST) + this.setSVTCrossPosition(null, geo); + else + this.setBMTCrossPosition(null); + } /** * Sets the cross parameters: the position and direction unit vector @@ -382,10 +391,12 @@ private Point3D getBMTCrossPoint(Point3D trackPos) { if(trackPos!=null) { Point3D local = new Point3D(trackPos); + Point3D orig = new Point3D(cluster.origin()); cluster.get_SeedStrip().toLocal().apply(local); + cluster.get_SeedStrip().toLocal().apply(orig); if(this.get_Type()==BMTType.C) { double phi = Math.atan2(local.y(), local.x()); - double phi0 = Math.atan2(cluster.origin().y(), cluster.origin().x()); + double phi0 = Math.atan2(orig.y(), orig.x()); double t = phi-phi0; if(Math.abs(t)>Math.PI) t-=Math.signum(t)*2*Math.PI; if(t<0) @@ -581,66 +592,37 @@ public int get_SVTCosmicsRegion() { int theRegion = 0; if (this.get_Detector()==DetectorType.BST) { - /* - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[6][0] + Constants.MODULERADIUS[7][0]) * 0.5 < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 8; - } else { - theRegion = 1; - } - } - - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[4][0] + Constants.MODULERADIUS[5][0]) * 0.5 < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 7; - } else { - theRegion = 2; - } - } - - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[2][0] + Constants.MODULERADIUS[3][0]) * 0.5 < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 6; - } else { - theRegion = 3; - } - } - - if (this.get_Point0().toVector3D().rho() - (Constants.MODULERADIUS[0][0] + Constants.MODULERADIUS[1][0]) * 0.5 < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 5; - } else { - theRegion = 4; - } - } - */ - - - if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(3) < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 6; - } else { - theRegion = 1; - } - } - - if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(2) < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 5; - } else { - theRegion = 2; - } - } - - if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(1) < 15) { - if (this.get_Point0().y() > 0) { - theRegion = 4; - } else { - theRegion = 3; - } - } + if(this.get_Point0().y()<0) + theRegion = this.get_Region(); + else + theRegion = SVTGeometry.NREGIONS*2+1-this.get_Region(); } - + // RDV check with Veronique +// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(3) < 15) { +// if (this.get_Point0().y() > 0) { +// theRegion = 6; +// } else { +// theRegion = 1; +// } +// } +// +// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(2) < 15) { +// if (this.get_Point0().y() > 0) { +// theRegion = 5; +// } else { +// theRegion = 2; +// } +// } +// +// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(1) < 15) { +// if (this.get_Point0().y() > 0) { +// theRegion = 4; +// } else { +// theRegion = 3; +// } +// } +// } +// return theRegion; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index e4567dda6..db49165ca 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -1,21 +1,21 @@ package org.jlab.rec.cvt.cross; -import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; +import org.jlab.rec.cvt.trajectory.Ray; /** * A class with methods used to find lists of crosses. This is the Pattern @@ -36,12 +36,12 @@ public CrossList findTrackSeeds(List crosses) { /// The principle of Hough Transform in pattern recognition is as follows. /// For every point (rho, z) on a line there exists an infinite number of /// lines that go through this point. Each such line can be parametrized - /// with parameters (r, theta) such that r = rho * cos(theta) + z * sin(theta), + /// with parameters (ir, theta) such that ir = rho * cos(theta) + z * sin(theta), /// where theta is the polar angle of the line which is perpendicular to it - /// and intersects the origin, and r is the distance between that line and + /// and intersects the origin, and ir is the distance between that line and /// the origin, for a given theta. /// Hence a point in (rho, z) parameter space corresponds to a sinusoidal - /// curve in (r, theta) parameter space, which is the so-called Hough- + /// curve in (ir, theta) parameter space, which is the so-called Hough- /// transform space. /// Points that fall on a line in (rho, z) space correspond to sinusoidal /// curves that intersect at a common point in Hough-transform space. @@ -53,15 +53,15 @@ public CrossList findTrackSeeds(List crosses) { /// the Hough transform algorithm makes use of an array, called an accumulator. /// The principle of the accumulator is a counting method. /// The dimensions of the array is equal to the number of parameters in - /// Hough transform space, which is 2 corresponding to the (r, theta) pair + /// Hough transform space, which is 2 corresponding to the (ir, theta) pair /// in our particular case. - /// The bin size in the array are finite intervals in r and theta, which are + /// The bin size in the array are finite intervals in ir and theta, which are /// called accumulator cells. - /// The bin content of cells along the curve of discretized (r, theta) values + /// The bin content of cells along the curve of discretized (ir, theta) values /// get incremented. The cell with the highest count corresponds to the /// intersection of the curves. This is a numerical method to find /// the intersection of any number of curves. - /// Once the accumulator array has been filled with all (r, theta) points + /// Once the accumulator array has been filled with all (ir, theta) points /// peaks and their associated (rho, z) points are determined. /// From these, sets of points belonging to common lines can be /// determined. @@ -78,7 +78,7 @@ public CrossList findTrackSeeds(List crosses) { double ThetaMin = 0.; double ThetaMax = 360.; - // Define the dimension of the r accumulator array + // Define the dimension of the ir accumulator array //int N_t = 180; //int N_r = 180; int N_t = 180; @@ -126,7 +126,7 @@ public CrossList findTrackSeeds(List crosses) { //double theta_j = ThetaMin + (0.5 + j_t)*SizeThetaBin; // r_j corresponding to that theta_j: double r_j = rho * cosTheta_Rz_array[j_t] + z * sinTheta_Rz_array[j_t]; - // this value of r_j falls into the following bin in the r array: + // this value of r_j falls into the following bin in the ir array: int j_r = (int) Math.floor(N_r * (r_j - RMin) / (float) (RMax - RMin)); //System.out.println("check range "+RMin+" [ "+r_j +" --> "+j_r+" ] "+RMax); // increase this accumulator cell: @@ -182,7 +182,7 @@ public CrossList findTrackSeeds(List crosses) { //double theta_j = ThetaMin + (0.5 + j_t)*SizeThetaBin; // r_j corresponding to that theta_j: double r_j = rho * cosTheta_Rz_array[j_t] + z * sinTheta_Rz_array[j_t]; - // this value of r_j falls into the following bin in the r array: + // this value of r_j falls into the following bin in the ir array: int j_r = (int) Math.floor(N_r * (r_j - RMin) / (float) (RMax - RMin)); // match bins: @@ -270,7 +270,9 @@ private boolean regionUniquenessFlag(ArrayList crossList) { public CrossList findCosmicsCandidateCrossLists(List> crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { CrossList crossLists = new CrossList(); - // start finding svt crosses + + + // start finding SVT crosses ArrayList svt_crosses = crosses.get(0); // if there are no svt crosses then return - there is no track if (svt_crosses.size() == 0) { @@ -319,9 +321,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, } } } - // first look for seeds - //CrossList crossLists = this.findTrackSeeds(svt_crosses); - + // instantiate the resulting crosslist CrossList crossListFinal = new CrossList(); ArrayList> newCrossLists = new ArrayList>(); @@ -341,11 +341,10 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, // find the crosses which are closest to the trajectory obtained from the seed for (Cross c : svt_crosses) { - if (c.get_Sector() != p.get_Sector() || c.get_Region() != p.get_Region()) { + if (c.get_Sector() != p.get_Sector() || c.get_Region() != p.get_Region() || p.get_Detector()!=DetectorType.BST) { continue; } - double d = Math.sqrt((c.get_Point0().x() - p.get_Point0().x()) * (c.get_Point0().x() - p.get_Point0().x()) - + (c.get_Point0().y() - p.get_Point0().y()) * (c.get_Point0().y() - p.get_Point0().y())); + double d = c.get_Point0().distance(p.get_Point0()); if (d < doca) { doca = d; closestCross = c; // the closest cross to the trajectory @@ -353,31 +352,12 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, } if (closestCross != null) // if there is a closest point it has to be within the cuts { - if (Math.abs(closestCross.get_Point0().x() - p.get_Point0().x()) < SVTParameters.MAXDISTTOTRAJXY && Math.abs(closestCross.get_Point0().y() - p.get_Point0().y()) < SVTParameters.MAXDISTTOTRAJXY) { + if (Math.abs(closestCross.get_Point0().x() - p.get_Point0().x()) < SVTParameters.MAXDISTTOTRAJXY && + Math.abs(closestCross.get_Point0().y() - p.get_Point0().y()) < SVTParameters.MAXDISTTOTRAJXY) { crossList.add(closestCross); } } - /* - doca = 1000; - closestCross = null; - // find the crosses which are closest to the trajectory obtained from the seed - for(Cross c : bmt_crosses) { - - if(c.get_Sector()!= p.get_Sector() || c.get_Region()!= p.get_Region() || !c.get_DetectorType().equalsIgnoreCase(p.get_DetectorType())) - continue; - double d = Math.sqrt((c.get_Point().x()-p.get_Point0().x())*(c.get_Point().x()-p.get_Point0().x())+ - (c.get_Point().y()-p.get_Point0().y())*(c.get_Point().y()-p.get_Point0().y())); - if(d> crosses, } return crossListFinal; } + + private List X = new ArrayList(); private List Y = new ArrayList(); private List errX = new ArrayList(); @@ -444,7 +426,7 @@ private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_g return projectedCrosses; } - + /** * * @param yxslope the slope for the line equation x = slope*y + intercept @@ -456,74 +438,82 @@ private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_g private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { + Ray xyTrack = new Ray(yxslope, 0, yxinterc, 0, 0, 0, 0, 0); + ArrayList projectedCrosses = new ArrayList(); - //Layer 1-8: - for (int l = 0; l < 2 * NbSVTRegions; l++) { - if (l % 2 != 0) { - continue; - } - - for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { - - double epsilon = 1e-6; -// Vector3D n = svt_geo.findBSTPlaneNormal(s + 1, l + 1); - Vector3D n = svt_geo.getNormal(l+1, s+1); + + + // SVT: Layer 1-8: + for (int ir = 0; ir < NbSVTRegions; ir++) { + int region = ir+1; + int layer = 2*ir+1; + + for (int is = 0; is < SVTGeometry.NSECTORS[ir*2]; is++) { + int sector = is+1; - double dot = (n.x() * yxslope + n.y()); - - if (Math.abs(dot) < epsilon) { - continue; - } - double R = svt_geo.getRegionRadius(l/2+1); - - Vector3D w = new Vector3D(yxinterc - R * n.x(), -R * n.y(), 0); - - double fac = -(n.x() * w.x() + n.y() * w.y() + n.z() * w.z()) / dot; - - Vector3D Delt = new Vector3D(fac * yxslope + yxinterc - R * n.x(), fac - R * n.y(), 0); - - if (Delt.mag() < SVTGeometry.getActiveSensorWidth() / 2) { - double tX = fac * yxslope + yxinterc; - double tY = fac; - Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, s + 1, (int) (l + 2) / 2, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane - cross2D.set_Point0(new Point3D(tX, tY, 0)); + Plane3D plane = svt_geo.getPlane(layer, sector); + Point3D traj = new Point3D(); + if(plane.intersection(xyTrack.toLine(), traj)==1 && svt_geo.isInFiducial(layer, sector, traj)) { + Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, sector, region, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane + cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); projectedCrosses.add(cross2D); } } } //BMTs - - double[] t = new double[4]; - for (int r = 0; r < 3; r++) { - - this.calcBMT2DPoint(yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.C)), t); - - //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D1 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); - cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); - projectedCrosses.add(cross2D1); - if (t[3] != t[1] && t[2] != t[0]) { - - //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D2 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); - cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); - projectedCrosses.add(cross2D2); - } - this.calcBMT2DPoint(yxslope, - yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(r+1, BMTType.Z)), t); - - //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D3 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[1], t[0])), r + 1, -1); - cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); - projectedCrosses.add(cross2D3); - if (t[3] != t[1] && t[2] != t[0]) { - - //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((r + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), r + 1, -1); - Cross cross2D4 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((r + 1) * 2, Math.atan2(t[3], t[2])), r + 1, -1); - cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); - projectedCrosses.add(cross2D4); - } + for (int il = 0; il < bmt_geo.getNLayers(); il++) { + int layer = il+1; + for(int is=0; is trajs = new ArrayList<>(); + int nTraj = bmt_geo.getTileSurface(layer, sector).intersection(xyTrack.toLine(), trajs); + if(nTraj==0) continue; + + for(Point3D traj : trajs) { + Cross cross2D = new Cross(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, bmt_geo.getRegion(layer), -1); + cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); + projectedCrosses.add(cross2D); + } + } } + +// double[] t = new double[4]; +// for (int ir = 0; ir < 3; ir++) { +// +// +// this.calcBMT2DPoint(yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(ir+1, BMTType.C)), t); +// +// //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); +// Cross cross2D1 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[1], t[0])), ir + 1, -1); +// cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); +// projectedCrosses.add(cross2D1); +// System.out.println("C" + ir + " " + cross2D1.get_Point0().toString()); +// if (t[3] != t[1] && t[2] != t[0]) { +// +// //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); +// Cross cross2D2 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[3], t[2])), ir + 1, -1); +// cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); +// System.out.println("C" + ir + " " + cross2D2.get_Point0().toString()); +// projectedCrosses.add(cross2D2); +// } +// this.calcBMT2DPoint(yxslope, +// yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(ir+1, BMTType.Z)), t); +// +// //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); +// Cross cross2D3 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[1], t[0])), ir + 1, -1); +// cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); +// System.out.println("Z" + ir + " " + cross2D3.get_Point0().toString()); +// projectedCrosses.add(cross2D3); +// if (t[3] != t[1] && t[2] != t[0]) { +// +// //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); +// Cross cross2D4 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[3], t[2])), ir + 1, -1); +// cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); +// projectedCrosses.add(cross2D4); +// System.out.println("Z" + ir + " " + cross2D4.get_Point0().toString()); +// } +// } return projectedCrosses; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/LineFitPars.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/LineFitPars.java index a025339de..ccee52f3c 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/LineFitPars.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/LineFitPars.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.fit; +import org.jlab.rec.cvt.trajectory.Ray; import trackfitter.fitter.utilities.ProbChi2perNDF; /** @@ -67,4 +68,13 @@ public double getProb() { int ndf = this.NDF(); return ProbChi2perNDF.prob(chi2, ndf); } + + public Ray getYXRay() { + return new Ray(this._slope, this._slopeErr, this._interc, this._intercErr, 0, 0, 0, 0); + } + + public Ray getYZRay() { + return new Ray(0, 0, 0, 0, this._slope, this._slopeErr, this._interc, this._intercErr); + } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index d66104154..f77760d00 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -9,10 +9,11 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.straight.KFitter; +import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -50,7 +51,8 @@ public boolean processEvent(DataEvent event, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, double zShift, boolean exLayrs, Swim swimmer) { - // make list of crosses consistent with a track candidate + + // make list of crosses consistent with a track candidate using SVT only first StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, BMTGeom, 3); @@ -60,6 +62,7 @@ public boolean processEvent(DataEvent event, return true; } + // refit track based on SVT only and then add BMT and refit again TrackCandListFinder trkcandFinder = new TrackCandListFinder(); List cosmics = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); List trkcands = new ArrayList(); @@ -69,7 +72,6 @@ public boolean processEvent(DataEvent event, if (cosmics.size() == 0) { recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, zShift); - return true; } @@ -123,69 +125,47 @@ public boolean processEvent(DataEvent event, crosses.get(1).removeAll(bmtCrossesRm); crosses.get(1).addAll(bmtCrosses); - org.jlab.clas.tracking.trackrep.Helix hlx = null ; - org.jlab.clas.tracking.kalmanfilter.straight.KFitter kf = null; + Helix hlx = null ; + KFitter kf = null; + // uncomment to initiali KF with MC track parameters +// double[] pars = recUtil.MCtrackPars(event); +// Point3D v = new Point3D(pars[0],pars[1],pars[2]); +// Vector3D p = new Vector3D(pars[3],pars[4],pars[5]); for (int k1 = 0; k1 < cosmics.size(); k1++) { Ray ray = cosmics.get(k1).get_ray(); - - Point3D xp = new Point3D(ray.get_yxinterc(),0,ray.get_yzinterc() ); - Vector3D u = new Vector3D(ray.get_yxslope(), 1, ray.get_yzslope()).asUnit(); - Line3D trL = new Line3D(xp, u); - Point3D docVtx = trL.distance(new Point3D(0,0,0)).origin(); - double xr = cosmics.get(k1).get_ray().get_refPoint().x(); - double yr = cosmics.get(k1).get_ray().get_refPoint().y(); - double zr = cosmics.get(k1).get_ray().get_refPoint().z(); - - double pt = 10000; - double pz = pt*u.z(); - double px = pt*u.x(); - double py = pt*u.y(); - int charge = 1; +// ray = new Ray(v,p); + Matrix cov = new Matrix(5, 5); - cov.set(0, 0,ray.get_yxintercErr()); - cov.set(1, 1,ray.get_yzintercErr()); - cov.set(2, 2,ray.get_yxslopeErr()); - cov.set(3, 3,ray.get_yzslopeErr()); - cov.set(4, 4,1); - kf = new org.jlab.clas.tracking.kalmanfilter.straight.KFitter( ray.get_yxinterc(),ray.get_yzinterc(), - ray.get_yxslope(),ray.get_yzslope(), 10.0, cov, kf, - recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; - kf.filterOn=true; + cov.set(0, 0, ray.get_yxintercErr()); + cov.set(1, 1, ray.get_yzintercErr()); + cov.set(2, 2, ray.get_yxslopeErr()); + cov.set(3, 3, ray.get_yzslopeErr()); + cov.set(4, 4, 1); + kf = new KFitter( ray.get_yxinterc(),ray.get_yzinterc(), + ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, kf, + recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; +// kf.filterOn=false; kf.runFitter(swimmer); - Map traj - = kf.TrjPoints; + Map traj = kf.TrjPoints; List keys = new ArrayList(); traj.forEach((key,value) -> keys.add(key)); - List trkTraj = new ArrayList(); + List trkTraj = new ArrayList(); traj.forEach((key,value) -> trkTraj.add(value)); - - double y_ref = 0; // calc the ref point at the plane y =0 - double x_ref = kf.yx_interc; - double z_ref = kf.yz_interc; - Point3D refPoint = new Point3D(x_ref, y_ref, z_ref); - Vector3D refDir = new Vector3D(kf.yx_slope, 1, kf.yz_slope).asUnit(); - - Ray the_ray = new Ray(refPoint, refDir); - the_ray.set_yxslope(kf.yx_slope); - the_ray.set_yzslope(kf.yz_slope); - the_ray.set_yxinterc(kf.yx_interc); - the_ray.set_yzinterc(kf.yz_interc); - + + Ray the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); cosmics.get(k1).set_ray(the_ray); - - cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray().get_yxslope(), cosmics.get(k1).get_ray().get_yxinterc(), SVTGeom); + cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray(), SVTGeom); double chi2 = cosmics.get(k1).calc_straightTrkChi2(); cosmics.get(k1).set_chi2(chi2); TrajectoryFinder trjFind = new TrajectoryFinder(); - ////Trajectory traj = trjFind.findTrajectory(passedcands.get(ic).get_Id(), trkRay, passedcands.get(ic), svt_geo, bmt_geo); Trajectory ntraj = trjFind.findTrajectory(k1+1, cosmics.get(k1).get_ray(), cosmics.get(k1), SVTGeom, BMTGeom); cosmics.get(k1).set_Trajectory(ntraj.get_Trajectory()); trkcandFinder.upDateCrossesFromTraj(cosmics.get(k1), ntraj, SVTGeom); - + for(int i = 0; i< keys.size(); i++) { double resi = trkTraj.get(i).resi; @@ -203,7 +183,7 @@ public boolean processEvent(DataEvent event, Line3D cln = BMTGeom.getAxis(layer, sector); double r = BMTGeom.getRadiusMidDrift(layer); cl.set_CentroidResidual(resi*r); - cl.setN(cln.distance(refPoint).direction().asUnit()); + cl.setN(cln.distance(ray.get_refPoint()).direction().asUnit()); cl.setS(cl.getL().cross(cl.getN()).asUnit()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 93d12c784..607386d3c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -53,13 +53,15 @@ public void CleanupSpuriousCrosses(List> crosses, List t List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { - double z = SVTGeom.toLocal(c.get_Region()*2, - c.get_Sector(), - c.get_Point()).z(); - - if(z<-0.1 || z>SVTGeometry.getModuleLength()) { +// double z = SVTGeom.toLocal(c.get_Region()*2, +// c.get_Sector(), +// c.get_Point()).z(); +// +// if(z<-0.1 || z>SVTGeometry.getModuleLength()) { +// rmCrosses.add(c); +// } + if(!SVTGeom.isInFiducial(c.get_Cluster1().get_Layer(), c.get_Sector(), c.get_Point())) rmCrosses.add(c); - } } @@ -152,16 +154,17 @@ public List setMeasVecs(StraightTrack trkcand, for (int i = 0; i < trkcand.size(); i++) { //SVT if(trkcand.get(i).get_Detector()==DetectorType.BST) { List cls = new ArrayList(); - int s = trkcand.get(i).get_Cluster1().get_Sector()-1; - int lt = trkcand.get(i).get_Cluster1().get_Layer()-1; - int lb = trkcand.get(i).get_Cluster2().get_Layer()-1; + + int sector = trkcand.get(i).get_Cluster1().get_Sector(); + int layertop = trkcand.get(i).get_Cluster1().get_Layer(); + int layerbot = trkcand.get(i).get_Cluster2().get_Layer(); Ray ray = trkcand.get_ray(); - double yt= tf.getIntersectionTrackWithSVTModule(s, lt, - ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), sgeo)[1]; - double yb= tf.getIntersectionTrackWithSVTModule(s, lb, - ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), sgeo)[1]; - - if(yt>yb) { + Point3D top = new Point3D(); + Point3D bottom = new Point3D(); + sgeo.getPlane(layertop, sector).intersection(ray.toLine(), top); + sgeo.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); + + if(top.y()>bottom.y()) { cls.add(trkcand.get(i).get_Cluster1()); cls.add(trkcand.get(i).get_Cluster2()); } else { @@ -169,82 +172,39 @@ public List setMeasVecs(StraightTrack trkcand, cls.add(trkcand.get(i).get_Cluster1()); } for (int j = 0; j < cls.size(); j++) { - int id = cls.get(j).get_Id(); - double ce = cls.get(j).get_Centroid(); - Point3D endPt1 = cls.get(j).getLine().origin(); - Point3D endPt2 = cls.get(j).getLine().end(); - Strip strp = new Strip(id, ce, endPt1.x(), endPt1.y(), endPt1.z(), - endPt2.x(), endPt2.y(), endPt2.z()); -// Plane3D pln = new Plane3D(endPt1,sgeo.findBSTPlaneNormal(cluster.get(j).get_Sector(), -// cluster.get(j).get_Layer())); - Plane3D pln = new Plane3D(endPt1,cls.get(j).getN()); -// Point3D Or = sgeo.getPlaneModuleOrigin(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); -// Point3D En = sgeo.getPlaneModuleEnd(cluster.get(j).get_Sector(), cluster.get(j).get_Layer()); - Surface meas = new Surface(pln, strp, cls.get(j).origin(), cls.get(j).end(), Constants.SWIMACCURACYSVT); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); - meas.setSector(cls.get(j).get_Sector()); - double err = cls.get(j).get_Resolution(); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //the thickness for multiple scattering. MS is outward the thickness is set for the 1st layer in the superlayer - // air gap ignored - double thickn_ov_X0 = 0; - if(cls.get(j).get_Layer()%2==1) - thickn_ov_X0 = cls.get(j).get(0).get_Strip().getToverX0(); - meas.setl_over_X0(thickn_ov_X0); - //if((int)Constants.getLayersUsed().get(meas.getLayer())<1) - // meas.notUsedInFit=true; - + int mlayer = cls.get(j).get_Layer(); + Surface meas = cls.get(j).measurement(mlayer); + // set SVT material budget according to track direction + if(j==0) meas.setl_over_X0(SVTGeometry.getToverX0()); + else meas.setl_over_X0(0); + // RDV to be tested +// if((int) Constants.getLayersUsed().get(meas.getLayer())<1) +// meas.notUsedInFit=true; + if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + continue; KFSites.add(meas); + clsMap.put(KFSites.size()-1, cls.get(j)); trkcand.clsMap = clsMap; } - } - - // adding the BMT - - if (trkcand.get(i).get_Detector()==DetectorType.BMT) { - int layer = trkcand.get(i).get_Cluster1().get_Layer(); - int sector = trkcand.get(i).get_Cluster1().get_Sector(); - - int id = trkcand.get(i).get_Cluster1().get_Id(); - double ce = trkcand.get(i).get_Cluster1().get_Centroid(); - - if (trkcand.get(i).get_Type()==BMTType.Z) { - Point3D point = trkcand.get(i).get_Cluster1().getLine().origin(); - double phi = bgeo.getPhi(layer, sector, point); - double err = trkcand.get(i).get_Cluster1().get_PhiErr(); - bgeo.toLocal(point, layer, sector); - Strip strp = new Strip(id, ce, point.x(), point.y(), phi); - - Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp, Constants.SWIMACCURACYBMT); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); - meas.setTransformation(bgeo.toGlobal(layer,sector)); - meas.setSector(trkcand.get(i).get_Sector()); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //for multiple scattering - meas.setl_over_X0(bgeo.getToverX0(layer)); + } - KFSites.add(meas); - clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); - } - else if (trkcand.get(i).get_Type()==BMTType.C) { - double z = trkcand.get(i).get_Cluster1().get_Z(); - double err = trkcand.get(i).get_Cluster1().get_ZErr(); - Arc3D arc = trkcand.get(i).get_Cluster1().get_Arc(); - Strip strp = new Strip(id, ce, arc); - - Surface meas = new Surface(bgeo.getTileSurface(layer, sector), strp, Constants.SWIMACCURACYBMT); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y()); - meas.setTransformation(bgeo.toGlobal(layer,sector)); - - meas.setSector(sector); - meas.setError(err*err); // CHECK THIS .... DOES KF take e or e^2? - //for multiple scattering - meas.setl_over_X0(bgeo.getToverX0(layer)); + // adding the BMT + if (trkcand.get(i).get_Detector()==DetectorType.BMT) { + int layer = trkcand.get(i).get_Cluster1().get_Layer(); + int sector = trkcand.get(i).get_Cluster1().get_Sector(); - KFSites.add(meas); - clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); + int id = trkcand.get(i).get_Cluster1().get_Id(); + double ce = trkcand.get(i).get_Cluster1().get_Centroid(); + Surface meas = trkcand.get(i).get_Cluster1().measurement(layer); + meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; + if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + meas.notUsedInFit=true; } + if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + continue; + KFSites.add(meas); + clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); } } for(int i = 0; i< KFSites.size(); i++) { @@ -312,7 +272,7 @@ public List FindClustersOnTrkNew (List allClusters, List trajs = new ArrayList<>(); + int nTraj = cluster.getTile().intersection(ray.toLine(), trajs); + if(nTraj>0) { + Point3D traj = null; + double doca = Double.MAX_VALUE; + for(Point3D t : trajs) { + double d = Math.abs(cluster.residual(t)); + if(d getStraightTracks(CrossList SVTCrosses, List crossesToFit = new ArrayList(); // remove SVT regions + // remove the crosses from the exluded region to fit the track for (Cross crossInTrackToFit : SVTCrosses.get(i)) { - if (crossInTrackToFit.get_Region() != SVTParameters.BSTEXCLUDEDFITREGION) {// remove the crosses from the exluded region to fit the track + if (crossInTrackToFit.get_Region() != SVTParameters.BSTEXCLUDEDFITREGION) { crossesToFit.add(crossInTrackToFit); } } @@ -370,11 +372,11 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List crossesToFitWithBMT = new ArrayList(); //crossesToFitWithBMT.addAll(crossesToFit); - //ArrayList BMTmatches = this.matchTrackToMM(BMTCrosses, cand, bmt_geo); + //ArrayList BMTmatches = this.matchTrackToBMT(BMTCrosses, cand, bmt_geo); //crossesToFitWithBMT.addAll(BMTmatches); ArrayList BMTmatches = new ArrayList(); ArrayList SVTmatches = new ArrayList(); @@ -446,7 +450,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List cands.add(value)); @@ -797,57 +803,98 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, return MeasArray; } - private void resetUnusedCross(Cross cross, SVTGeometry geo) { - - cross.set_Dir(new Vector3D(0, 0, 0)); - - cross.setSVTCrossPosition(null, geo); - } - /** * - * @param MMCrosses the BMT crosses + * @param bmtCrosses the BMT crosses * @param thecand the straight track candidate * @param geo the BMT geometry * @return an arraylist of BMT crosses matched to the track */ - public ArrayList matchTrackToMM(List MMCrosses, StraightTrack thecand, BMTGeometry geo) { - - double matchCutOff = SVTParameters.COSMICSMINRESIDUAL; // ? guess + public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCrosses, BMTGeometry geo) { ArrayList BMTCrossList = new ArrayList(); - StraightTrack thecand2 = thecand; - if (thecand2 == null) { + if (thecand == null) { return BMTCrossList; } - if (MMCrosses == null || MMCrosses.size() == 0) { + if (bmtCrosses == null || bmtCrosses.isEmpty()) { return BMTCrossList; } // for configuration in 3 double SVT layers + 3 double BMT layers //------------------------------------------------------------------------------------------------------ - for (int regionIdx = 0; regionIdx < 3; regionIdx++) { - ArrayList MatchedMMCrossZDet = this.MatchMMCrossZ(regionIdx + 1, thecand2.get_ray(), MMCrosses, Math.toRadians(2), geo); // 2 degrees opening angle - if (MatchedMMCrossZDet.size() > 0) { - BMTCrossList.addAll(MatchedMMCrossZDet); - } - - ArrayList MatchedMMCrossCDet = this.MatchMMCrossC(regionIdx + 1, thecand2.get_ray(), MMCrosses, matchCutOff, geo); - if (MatchedMMCrossCDet.size() > 0) { - BMTCrossList.addAll(MatchedMMCrossCDet); - } + for(int iregion = 0; iregion < 3; iregion++) { + int region = iregion + 1; + + // match Z crosses + List zCross = this.matchTrackToBMT(geo.getLayer(region, BMTType.Z), thecand.get_ray(), bmtCrosses, + Constants.COSMICSMINRESIDUALX/geo.getRadiusMidDrift(geo.getLayer(region, BMTType.Z)), geo); + if(zCross!=null) + BMTCrossList.addAll(zCross); + + // match Z crosses + List cCross = this.matchTrackToBMT(geo.getLayer(region, BMTType.C), thecand.get_ray(), bmtCrosses, Constants.COSMICSMINRESIDUALZ, geo); + if(cCross!=null) + BMTCrossList.addAll(cCross); + +// // match Z crosses +// ArrayList zCrosses = this.MatchMMCrossZ(iregion + 1, thecand.get_ray(), bmtCrosses, Math.toRadians(2), geo); // 2 degrees opening angle +// if (zCrosses.size() > 0) { +// BMTCrossList.addAll(zCrosses); +// } +// +// ArrayList cCrosses = this.MatchMMCrossC(iregion + 1, thecand.get_ray(), bmtCrosses, SVTParameters.COSMICSMINRESIDUAL, geo); +// if (cCrosses.size() > 0) { +// BMTCrossList.addAll(cCrosses); +// } +// +// for (Cross Ccross : cCrosses) { +// for (Cross Zcross : zCrosses) { +// if ((Ccross.get_Cluster1().get_Layer() - Zcross.get_Cluster1().get_Layer()) == 1 && (Ccross.get_Cluster1().get_Sector() == Zcross.get_Cluster1().get_Sector())) { +// Ccross.set_MatchedZCross(Zcross); +// Zcross.set_MatchedCCross(Ccross); +// } +// } +// } + } + return BMTCrossList; + } - for (Cross Ccross : MatchedMMCrossCDet) { - for (Cross Zcross : MatchedMMCrossZDet) { - if ((Ccross.get_Cluster1().get_Layer() - Zcross.get_Cluster1().get_Layer()) == 1 && (Ccross.get_Cluster1().get_Sector() == Zcross.get_Cluster1().get_Sector())) { - Ccross.set_MatchedZCross(Zcross); - Zcross.set_MatchedCCross(Ccross); + private List matchTrackToBMT(int layer, Ray ray, List crosses, double matchCut, BMTGeometry geo) { + + List matched = new ArrayList<>(); + + for(int is=0; is trajs = new ArrayList<>(); + int ntrajs = geo.getTileSurface(layer, sector).intersection(ray.toLine(), trajs); + if(ntrajs==0) continue; + + // find the closests cross-trajectory match + for(Point3D traj : trajs) { + Cross closestCross = null; + double doca = Double.MAX_VALUE; + + // loop over all BMT crosses + for(Cross c : crosses) { + Cluster cluster = c.get_Cluster1(); + // consider only the ones in the selected layer + if(cluster.get_Layer()!=layer || cluster.get_Sector()!=sector) continue; + + double residual = cluster.residual(traj); + if(Math.abs(residual) MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, BMTGeometry geo) { @@ -1073,15 +1120,30 @@ private ArrayList rmStraightTrkClones(boolean removeClones, Array return passedcands; } - private void EliminateStraightTrackOutliers(ArrayList crossesToFit, - CosmicFitter fitTrk, SVTGeometry svt_geo) { - for (int j = 0; j < crossesToFit.size(); j++) { - if (Math.abs(fitTrk.get_ray().get_yxslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yxinterc() - crossesToFit.get(j).get_Point().x()) > SVTParameters.COSMICSMINRESIDUAL - || Math.abs(fitTrk.get_ray().get_yzslope() * crossesToFit.get(j).get_Point().y() + fitTrk.get_ray().get_yzinterc() - crossesToFit.get(j).get_Point().z()) > SVTParameters.COSMICSMINRESIDUALZ) { - resetUnusedCross(crossesToFit.get(j), svt_geo); - crossesToFit.remove(j); + private void EliminateStraightTrackOutliers(ArrayList crosses, CosmicFitter track, SVTGeometry svt_geo) { + ArrayList toKeep = new ArrayList<>(); + + for(int j = 0; j < crosses.size(); j++) { + Cross c = crosses.get(j); + int layer = c.get_Cluster1().get_Layer(); + int sector = c.get_Sector(); + + Point3D traj = new Point3D(); + int ntraj = svt_geo.getPlane(layer, sector).intersection(track.get_ray().toLine(), traj); + + if(ntraj!=1) + c.resetCross(svt_geo); + else if(!svt_geo.isInFiducial(layer, sector, traj)) + c.resetCross(svt_geo); + else { + Vector3D distance = svt_geo.toLocal(layer, sector, c.get_Point().vectorTo(traj)); + if(Math.abs(distance.x())>Constants.COSMICSMINRESIDUALX || + Math.abs(distance.z())>Constants.COSMICSMINRESIDUALZ) c.resetCross(svt_geo); + else + toKeep.add(c); } } + crosses = toKeep; } public void matchClusters(List sVTclusters, TrajectoryFinder tf, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java index db7f0df8a..25aac7a88 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.trajectory; +import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -19,11 +20,40 @@ public class Ray { public double chi2; public Ray(Point3D refPoint, Vector3D dirVec) { - set_refPoint(refPoint); - set_dirVec(dirVec); - + if(dirVec.y()!=0) { + double t = -refPoint.y()/dirVec.y(); + refPoint.translateXYZ(t*dirVec.x(), t*dirVec.y(), t*dirVec.z()); + dirVec = dirVec.multiply(1/dirVec.y()); + this._refPoint = refPoint; + this._dirVec = dirVec.asUnit(); + this._yxinterc = refPoint.x(); + this._yzinterc = refPoint.z(); + this._yxslope = dirVec.x(); + this._yzslope = dirVec.z(); + } + } + + public Ray(double yxSlope, double yxInterc, double yzSlope, double yzInterc) { + this(yxSlope, 0, yxInterc, 0, yzSlope, 0, yzInterc,0); } - + + public Ray(double yxSlope, double yxSlopeErr, double yxInterc, double yxIntercErr, + double yzSlope, double yzSlopeErr, double yzInterc, double yzIntercErr) { + + this._yxslope = yxSlope; + this._yxslopeErr = yxSlopeErr; + this._yxinterc = yxInterc; + this._yxintercErr = yxIntercErr; + this._yzslope = yzSlope; + this._yzslopeErr = yzSlopeErr; + this._yzinterc = yzInterc; + this._yzintercErr = yzIntercErr; + + this._refPoint = new Point3D(yxInterc, 0, yzInterc); + this._dirVec = new Vector3D(yxSlope, 1, yzSlope).asUnit(); + + } + public Point3D get_refPoint() { return _refPoint; } @@ -104,4 +134,7 @@ public void set_yzintercErr(double _yzintercErr) { this._yzintercErr = _yzintercErr; } + public Line3D toLine() { + return new Line3D(this.get_refPoint(), this.get_dirVec()); + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index d8f1fc4ac..8d2ac03af 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -514,8 +514,8 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList if (c.get_Type()==BMTType.C) { //C-detector measuring Z //if(traj.isFinal) { // reset the cross only for final trajectory - c.set_Point(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.get_Point().z())); - c.set_Dir(ray.get_dirVec()); +// c.set_Point(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.get_Point().z())); +// c.set_Dir(ray.get_dirVec()); //} // calculate the hit residuals // CHECK THIS ........ @@ -526,9 +526,9 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList if (c.get_Type()==BMTType.Z) { //Z-detector measuring phi //if(traj.isFinal) { - c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), ZtrackIntersSurf)); - c.set_Dir(ray.get_dirVec()); - //} +// c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), ZtrackIntersSurf)); +// c.set_Dir(ray.get_dirVec()); +// //} // calculate the hit residuals this.setHitResolParams("BMT", c.get_Cluster1().get_Sector(), c.get_Cluster1().get_Layer(), c.get_Cluster1(), @@ -683,53 +683,93 @@ private double[][][] calc_trackIntersBMT(Ray ray, BMTGeometry bmt_geo, int start } } //Layer 1-6: + Line3D line = ray.toLine(); for (int l = start_layer - 1; l < 6; l++) { - double[][] trkIntersCombinedInf = this.getIntersectionTrackWithBMTModules(l, - ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), bmt_geo); - - //hemisphere 1-2 - for (int h = 0; h < 2; h++) { - double[] trkIntersInf = trkIntersCombinedInf[h]; + for(int s=0; s trajs = new ArrayList<>(); + int ntraj = bmt_geo.getTileSurface(layer, sector).intersection(line, trajs); +// System.out.println(layer + " " + sector); + if(ntraj>0) { + for(int i=0; i0) local.negative(); + result[l][h][0] = traj.x(); + result[l][h][1] = traj.y(); + result[l][h][2] = traj.z(); + result[l][h][3] = Math.toDegrees(local.phi()); + result[l][h][4] = Math.toDegrees(local.theta()); + result[l][h][5] = Math.toDegrees(Math.acos(local.x())); + result[l][h][6] = bmt_geo.getStrip(layer, sector, traj); +// System.out.println("New " + local.x() + " " + local.y() + " " + local.z() + " " +// + result[l][h][0] + " " + result[l][h][1] + " " + result[l][h][2] + " " +// + result[l][h][3] + " " + result[l][h][4] + " " + result[l][h][5] + " " + result[l][h][6]); + } + } } +// double[][] trkIntersCombinedInf = this.getIntersectionTrackWithBMTModules(l, +// ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), bmt_geo); +// +// //hemisphere 1-2 +// for (int h = 0; h < 2; h++) { +// double[] trkIntersInf = trkIntersCombinedInf[h]; +// +// if(Double.isNaN(trkIntersInf[0]) || Double.isNaN(trkIntersInf[1]) || Double.isNaN(trkIntersInf[2]) ) +// continue; +// +// Point3D p = new Point3D(trkIntersInf[0], trkIntersInf[1], trkIntersInf[2]); +// +// if (p.toVector3D().mag() == 0 ) { +// continue; +// } +// +// Vector3D n = new Vector3D(Math.cos(Math.atan2(p.y(), p.x())), Math.sin(Math.atan2(p.y(), p.x())), 0); +// Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module +// +// Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module +// +// double norm = Math.sqrt(ray.get_yxslope() * ray.get_yxslope() + ray.get_yzslope() * ray.get_yzslope() + 1); +// +// Vector3D u = new Vector3D(ray.get_yxslope() / norm, 1 / norm, ray.get_yzslope() / norm); +// +// if (p.y() < 0) { +// u = new Vector3D(-ray.get_yxslope() / norm, -1 / norm, -ray.get_yzslope() / norm); +// } +// +// double trkToMPlnAngl = Math.acos(u.dot(ui)); +// +// double zl = u.dot(n); +// double xl = u.dot(ui); +// double yl = u.dot(uj); +// +// double phi = Math.atan2(yl, xl); +// double theta = Math.acos(zl); +// +// result[l][h][0] = p.x(); +// result[l][h][1] = p.y(); +// result[l][h][2] = p.z(); +// result[l][h][3] = Math.toDegrees(phi); +// result[l][h][4] = Math.toDegrees(theta); +// result[l][h][5] = Math.toDegrees(trkToMPlnAngl); +// result[l][h][6] = trkIntersInf[3]; +// System.out.println("Old " + xl + " " + yl + " " + zl + " " +// + result[l][h][0] + " " + result[l][h][1] + " " + result[l][h][2] + " " +// + result[l][h][3] + " " + result[l][h][4] + " " + result[l][h][5] + " " + result[l][h][6]); +// } } return result; } @@ -747,48 +787,26 @@ private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { } } //Layer 1-8: + Line3D line = ray.toLine(); for (int l = 0; l < SVTGeometry.NLAYERS; l++) { for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { - - double[] trkIntersInf = this.getIntersectionTrackWithSVTModule(s, l, ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), svt_geo); - - Point3D p = new Point3D(trkIntersInf[0], trkIntersInf[1], trkIntersInf[2]); - - if (p.toVector3D().mag() == 0) { - continue; - } - // RDV check me - if ((Math.sqrt(p.x() * p.x() + p.y() * p.y()) <= Math.sqrt(0.25 * SVTGeometry.getModuleLength()* SVTGeometry.getActiveSensorWidth() + Math.pow(SVTGeometry.getLayerRadius(l+1),2.0)))) { - - Vector3D n = svt_geo.getNormal(l+1, s+1); - Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module - - Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module - - double norm = Math.sqrt(ray.get_yxslope() * ray.get_yxslope() + ray.get_yzslope() * ray.get_yzslope() + 1); - - Vector3D u = new Vector3D(ray.get_yxslope() / norm, 1 / norm, ray.get_yzslope() / norm); - - if (p.y() < 0) { - u = new Vector3D(-ray.get_yxslope() / norm, -1 / norm, -ray.get_yzslope() / norm); - } - - double trkToMPlnAngl = Math.acos(u.dot(ui)); - - double zl = u.dot(n); - double xl = u.dot(ui); - double yl = u.dot(uj); - - double phi = Math.atan2(yl, xl); - double theta = Math.acos(zl); - - result[l][s][0] = p.x(); - result[l][s][1] = p.y(); - result[l][s][2] = p.z(); - result[l][s][3] = Math.toDegrees(phi); - result[l][s][4] = Math.toDegrees(theta); - result[l][s][5] = Math.toDegrees(trkToMPlnAngl); - result[l][s][6] = trkIntersInf[3]; + int layer = l+1; + int sector = s+1; + + Point3D traj = new Point3D(); + int ntraj = svt_geo.getPlane(layer, sector).intersection(line, traj); + if(ntraj==1 && svt_geo.isInFiducial(layer, sector, traj)) { + Vector3D local = new Vector3D(line.direction()).asUnit(); + local = svt_geo.toLocal(layer, sector, local); + if(traj.y()>0) local.negative(); + local.rotateX(Math.toRadians(90)); + result[l][s][0] = traj.x(); + result[l][s][1] = traj.y(); + result[l][s][2] = traj.z(); + result[l][s][3] = Math.toDegrees(local.phi()); + result[l][s][4] = Math.toDegrees(local.theta()); + result[l][s][5] = Math.toDegrees(Math.acos(local.x())); + result[l][s][6] = svt_geo.calcNearestStrip(traj.x(), traj.y(), traj.z(), layer, sector); } } } @@ -796,6 +814,7 @@ private double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { } + @Deprecated public double[] getIntersectionTrackWithSVTModule(int s, int l, double _yxinterc2, double _yxslope2, double _yzinterc2, double _yzslope2, SVTGeometry geo) { @@ -843,6 +862,7 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, } + @Deprecated private double[][] getIntersectionTrackWithBMTModules(int l, double _yxinterc2, double _yxslope2, double _yzinterc2, double _yzslope2, BMTGeometry geo) { @@ -1004,6 +1024,7 @@ private boolean checkBMTAcceptance(Point3D ipos, int lyer, BMTGeometry geo) { } } + @Deprecated private List getIntersBMT(int lyer, double radius, double x_minus, double y_minus, double z_minus, Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation, BMTGeometry geo) { From ba945df1b5b3e969826cf07c4bee5dbcebf943e7 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 27 Oct 2021 15:04:15 -0400 Subject: [PATCH 197/291] Switch to new libraries functionality. Matrix ops classes. Restructuring of the tracking code to use common abstract classes for cosmics and tracks from the target. --- common-tools/clas-tracking/pom.xml | 6 +- .../clas/tracking/kalmanfilter/AKFitter.java | 186 ++++++++ .../clas/tracking/kalmanfilter/AMeasVecs.java | 251 +++++++++++ .../tracking/kalmanfilter/AStateVecs.java | 228 ++++++++++ .../tracking/kalmanfilter/KFCovMatOps.java | 52 +++ .../kalmanfilter/helical/KFitter.java | 398 ++++------------- .../kalmanfilter/helical/MeasVecs.java | 246 +--------- .../kalmanfilter/helical/StateVecs.java | 339 ++++---------- .../kalmanfilter/straight/KFitter.java | 421 ++++-------------- .../kalmanfilter/straight/MeasVecs.java | 250 +---------- .../kalmanfilter/straight/StateVecs.java | 265 ++++------- .../clas/tracking/utilities/MatrixOps.java | 201 +++++++++ 12 files changed, 1314 insertions(+), 1529 deletions(-) create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/KFCovMatOps.java create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java diff --git a/common-tools/clas-tracking/pom.xml b/common-tools/clas-tracking/pom.xml index 9a10a25cc..cba0d54e4 100644 --- a/common-tools/clas-tracking/pom.xml +++ b/common-tools/clas-tracking/pom.xml @@ -27,7 +27,11 @@
- + + org.ejml + ejml-all + 0.39 + org.jlab.clas swim-tools diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java new file mode 100644 index 000000000..408b27817 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -0,0 +1,186 @@ +package org.jlab.clas.tracking.kalmanfilter; + +import java.util.List; + +import java.util.HashMap; +import java.util.Map; + +import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs.StateVec; +import org.jlab.clas.tracking.trackrep.Helix; + +import org.jlab.clas.tracking.utilities.MatrixOps.*; +import org.jlab.geom.prim.Vector3D; + +public abstract class AKFitter { + + public static int polarity = -1; + public Libr matLib = Libr.EJML; + public boolean setFitFailed = true; + + // AStateVecs sv + // AMeasVecs mv + public boolean filterOn = true; + private double _tarShift; //targetshift + private double _Xb; //beam axis pars + private double _Yb; + private double resiCut = 100;//residual cut for the measurements + + public void setMeasurements(List measSurfaces, AMeasVecs mv) { + mv.setMeasVecs(measSurfaces); + } + public KFCovMatOps mo = new KFCovMatOps(matLib); + + + /** + * @return the resiCut + */ + public double getResiCut() { + return resiCut; + } + + /** + * @param resiCut the resiCut to set + */ + public void setResiCut(double resiCut) { + this.resiCut = resiCut; + } + + public int totNumIter = 5; + + public void runFitterIter(Swim swimmer, int it, AStateVecs sv, AMeasVecs mv) { + for (int k = 0; k < mv.measurements.size() - 1; k++) { + if (sv.trackCov.get(k) == null || mv.measurements.get(k + 1) == null) { + return; + } + sv.transport(k, k + 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k+1), + swimmer); + this.filter(k + 1, swimmer, 1, sv, mv); + } + + for (int k = mv.measurements.size() - 1; k>0 ;k--) { + if (sv.trackCov.get(k) == null || mv.measurements.get(k - 1) == null) { + return; + } + sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), + swimmer); + if(k>1) + this.filter(k - 1, swimmer, -1, sv, mv); + } + } + public abstract void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) ; + + public abstract void setTrajectory(AStateVecs sv, AMeasVecs mv) ; + + + public double chi2 = 0; + public int NDF = 0; + + public double calc_chi2(Swim swimmer, AStateVecs sv, AMeasVecs mv) { + //get the measurement + double m = 0; + //get the projector state + double h = 0; + double chi2 =0; + m=0; + h=0; + int ndf = -5; + StateVec stv = sv.transported(0, 1, sv.trackTraj.get(0), mv.measurements.get(1), swimmer); + double dh = mv.dh(1, stv); + if(mv.measurements.get(1).skip==false) { + chi2 = dh*dh / mv.measurements.get(1).error; + ndf++; + } + for(int k = 1; k< sv.mv.measurements.size()-1; k++) { + if(mv.measurements.get(k+1).skip==false) { + stv = sv.transported(k, k+1, stv, mv.measurements.get(k+1), swimmer); + dh = mv.dh(k+1, stv); + chi2 += dh*dh / mv.measurements.get(k+1).error; + ndf++; + } + } + return chi2; + } + + public abstract void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) ; + + /** + * @return the _Xb + */ + public double getXb() { + return _Xb; + } + + /** + * @param _Xb the _Xb to set + */ + public void setXb(double _Xb) { + this._Xb = _Xb; + } + + /** + * @return the _Yb + */ + public double getYb() { + return _Yb; + } + + /** + * @param _Yb the _Yb to set + */ + public void setYb(double _Yb) { + this._Yb = _Yb; + } + + /** + * @return the _tarShift + */ + public double getTarShift() { + return _tarShift; + } + + /** + * @param _TarShift the _tarShift to set + */ + public void setTarShift(double _TarShift) { + this._tarShift = _TarShift; + } + + /** + * prints the matrix -- used for debugging + * + * @param C matrix + */ + public void printMatrix(double[][] C, String s) { + System.out.println(" "+s); + for (int k = 0; k < 5; k++) { + System.out.println(C[k][0]+" "+C[k][1]+" "+C[k][2]+" "+C[k][3]+" "+C[k][4]); + } + System.out.println(" "); + } + + public class HitOnTrack { + + public int layer; + public double x; + public double y; + public double z; + public double px; + public double py; + public double pz; + public double resi; + public boolean isMeasUsed = true; + + public HitOnTrack(int layer, double x, double y, double z, double px, double py, double pz, double resi) { + this.layer = layer; + this.x = x; + this.y = y; + this.z = z; + this.px = px; + this.py = py; + this.pz = pz; + this.resi = resi; + } + } + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java new file mode 100644 index 000000000..006cb6920 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -0,0 +1,251 @@ +/* + * 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.tracking.kalmanfilter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.Surface; +import org.jlab.clas.tracking.kalmanfilter.Type; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs.StateVec; +import org.jlab.clas.tracking.objects.Strip; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Transformation3D; +import org.jlab.geom.prim.Vector3D; + +/** + * + * @author ziegler + */ + +public abstract class AMeasVecs { + + public List measurements = new ArrayList(); + + public void setMeasVecs(List measSurfaces) { + Collections.sort(measSurfaces); + for(int i = 0; i < measSurfaces.size(); i++) { + MeasVec mvec = new MeasVec(); + mvec.k = i ; + mvec.layer = measSurfaces.get(i).getLayer(); + mvec.sector = measSurfaces.get(i).getSector(); + mvec.surface = measSurfaces.get(i); + if(mvec.surface.getError()!=0) + mvec.error = mvec.surface.getError(); + mvec.l_over_X0 = mvec.surface.getl_over_X0(); + mvec.skip = mvec.surface.notUsedInFit; + mvec.hemisphere = measSurfaces.get(i).hemisphere; + measurements.add(mvec); + } + } + + + public double dh(int k, StateVec stateVec) { + + double value = Double.NaN; + + if (stateVec == null|| this.measurements.get(stateVec.k) == null) { + return value; + } + + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { + Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); + value = p.distance(stateVec.x, stateVec.y, stateVec.z); + } + if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { + double phia = this.measurements.get(stateVec.k).surface.arc.theta(); + value = Math.atan2(stateVec.y, stateVec.x)-phia; + System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + Line3D WL = new Line3D(); + WL.copy(l); + WL.copy(WL.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z))); + + value = WL.length(); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + if(l.direction().z()<0) { + l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); + l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); + } + Line3D WL = new Line3D(); + WL.copy(l); + Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); + WL.copy(WL.distance(svP)); + double sideStrip = -Math.signum(l.direction().cross(WL.direction()). + dot(this.measurements.get(stateVec.k).surface.plane.normal())); + //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); + value = WL.length()*sideStrip; + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z()-this.measurements.get(stateVec.k).surface.strip.getZ(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Arc3D arc = new Arc3D(); + arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); + toLocal.apply(arc); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z()-arc.center().z(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(sv); + value = sv.toVector3D().phi()-this.measurements.get(stateVec.k).surface.strip.getPhi(); + if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + } + } + return value; + } + + + public double getPhiATZ(StateVec stateVec) { + Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; + Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); + double v = (stateVec.z-cyl.baseArc().center().z())/cln.direction().z(); + double x = cyl.baseArc().center().x()+v*cln.direction().x(); + double y = cyl.baseArc().center().y()+v*cln.direction().y(); + Vector3D n = new Point3D(x, y, stateVec.z). + vectorTo(new Point3D(stateVec.x,stateVec.y,stateVec.z)).asUnit(); + return n.phi(); + } + + public double getPhi(StateVec stateVec) { + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + this.measurements.get(stateVec.k).surface.toLocal().apply(sv); + return sv.toVector3D().phi(); + } + + public double h(int k, StateVec stateVec) { + + double value = Double.NaN; + + if (stateVec == null|| this.measurements.get(stateVec.k) == null) { + return value; + } + + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { + Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); + value = p.distance(stateVec.x, stateVec.y, stateVec.z); + } + if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { + double phia = this.measurements.get(stateVec.k).surface.arc.theta(); + value = value = Math.atan2(stateVec.y, stateVec.x); + System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + } + if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || + this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); + if(l.direction().z()<0) { + l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); + l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); + } + Line3D WL = new Line3D(); + WL.copy(l); + Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); + WL.copy(WL.distance(svP)); + double sideStrip = -Math.signum(l.direction().cross(WL.direction()). + dot(this.measurements.get(stateVec.k).surface.plane.normal())); + //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); + value = WL.length()*sideStrip; + + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { + value = stateVec.z; + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(stV); + value = stV.z(); + } + if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { + //value = Math.atan2(stateVec.y, stateVec.x); + value = this.getPhi(stateVec); + } + } + return value; + } + + public double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; + public double sqrt_epsilon = Math.sqrt(2.2*1.e-16); + public double[] Hval = new double[5]; + public abstract double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) ; + public abstract AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) ; + + public class MeasVec implements Comparable { + public Surface surface; + public int layer = -1; + public int sector = -1; + public double error = 1; + public int k = -1; + public boolean skip = false; + // this is for multiple scattering estimates in track + public double l_over_X0; + //this is for energy loss + public double Z_over_A_times_l; + public double hemisphere = 1; + + + @Override + public int compareTo(MeasVec arg) { + int CompLay = this.layer < arg.layer ? -1 : this.layer == arg.layer ? 0 : 1; + return CompLay; + } + } + + /** + * @return the delta_d_a + */ + public double[] getDelta_d_a() { + return delta_d_a; + } + + /** + * @return the Hval + */ + public double[] getHval() { + return Hval; + } + + /** + * @param Hval the Hval to set + */ + public void setHval(double[] Hval) { + this.Hval = Hval; + } + +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java new file mode 100644 index 000000000..fad6b1463 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -0,0 +1,228 @@ +package org.jlab.clas.tracking.kalmanfilter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.jlab.geom.prim.Vector3D; + +import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; +import org.jlab.clas.tracking.trackrep.Helix; + +public abstract class AStateVecs { + + public List X0; + public List Y0; + public List Z0; // reference points + + public Helix util ; + public double units; + public double lightVel; + + public List bfieldPoints = new ArrayList(); + public Map trackTraj = new HashMap(); + public Map trackCov = new HashMap(); + + public boolean straight; + public StateVec StateVec; + public CovMat CovMat; + + AMeasVecs mv = new AMeasVecs() { + @Override + public double[] H(StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public StateVec reset(StateVec SVplus, StateVec stateVec, AStateVecs sv) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + } ; + + public double shift; // target shift + public List Layer; + public List Sector; + + public double[] value = new double[4]; // x,y,z,phi + public double[] swimPars = new double[7]; + public B Bf = new B(0); + + public abstract void init(Helix trk, double[][] cov, AKFitter kf, Swim swimmer); + public abstract void init(double x0, double z0, double tx, double tz, double units, double[][] cov, AKFitter kf) ; + public abstract void setStateVecPosAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer) ; + public abstract StateVec newStateVecAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer, + boolean useSwimmer); + public abstract double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, + boolean useSwimmer) ; + public abstract void tranState(int f, StateVec iVec, Swim swimmer) ; + + public abstract StateVec transported(int i, int f, StateVec iVec, MeasVec mv, + Swim swimmer) ; + + public abstract void transport(int i, int f, StateVec iVec, CovMat icovMat, MeasVec mv, + Swim swimmer) ; + + public abstract void setTrackPars(StateVec kVec, Swim swim); + + public abstract Helix setTrackPars(); + + private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { + int r1 =firstMatrix.length; int c1=firstMatrix[0].length; int c2=secondMatrix[0].length; + double[][] product = new double[r1][c2]; + for(int i = 0; i < r1; i++) { + for (int j = 0; j < c2; j++) { + for (int k = 0; k < c1; k++) { + product[i][j] += firstMatrix[i][k] * secondMatrix[k][j]; + } + } + } + + return product; + } + + public double[][] propagatedMatrix(double[][] firstMatrix, double[][] sMatrix, double[][] secondMatrix){ + double[][] m1 = multiplyMatrices(sMatrix, secondMatrix); + double[][] m2 = multiplyMatrices(firstMatrix,m1); + + return m2; + } + + public double[][] addProcessNoise(double[][] C, double[][] Q){ + double[][] result = new double[5][5]; + for(int i = 0; i<5; i++) { + for(int j = 0; j<5; j++) { + result[i][j] = C[i][j]; + if(Q[i][j]!=0) { + result[i][j] +=Q[i][j]; + } + } + } + + return result; + } + public abstract double[][] Q(StateVec iVec, MeasVec mVec, int dir) ; + + public abstract StateVec reset(StateVec SV, StateVec stateVec) ; + + public void resetArrays(double[] swimPars) { + for(int i = 0; i TrjPoints = new HashMap(); StateVecs sv = new StateVecs(); - MeasVecs mv = new MeasVecs(); - public boolean filterOn = true; - public StateVec finalStateVec; - private double _tarShift; //targetshift - private double _Xb; //beam axis pars - private double _Yb; - private double resiCut = 100;//residual cut for the measurements - - public void setMeasurements(List measSurfaces) { - mv.setMeasVecs(measSurfaces); - } + public StateVecs.StateVec finalStateVec; - public KFitter(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb, double Yb, + public Helix KFHelix; + public KFitter(Helix helix, double[][] cov, DataEvent event, Swim swimmer, double Xb, double Yb, double Zref, List measSurfaces) { - _Xb = Xb; - _Yb = Yb; - _tarShift = Zref; + this.setXb(Xb); + this.setYb(Yb); + this.setTarShift(Zref); this.init(helix, cov, event, swimmer, Xb, Yb, - Zref, mv, measSurfaces); - } - //private Matrix iCov; - public void init(Helix helix, Matrix cov, DataEvent event, Swim swimmer, double Xb, double Yb, - double Zref, MeasVecs mv, List measSurfaces) { - sv.shift = Zref; - //iCov = cov; - mv.setMeasVecs(measSurfaces); - if (sv.Layer != null) { - sv.Layer.clear(); - } else { - sv.Layer = new ArrayList(); - } - if (sv.Sector != null) { - sv.Sector.clear(); - } else { - sv.Sector = new ArrayList(); - } - if (sv.X0 != null) { - sv.X0.clear(); - } else { - sv.X0 = new ArrayList(); - } - if (sv.Y0 != null) { - sv.Y0.clear(); - } else { - sv.Y0 = new ArrayList(); - } - if (sv.Z0 != null) { - sv.Z0.clear(); - } else { - sv.Z0 = new ArrayList(); - } - //take first plane along beam line with n = y-dir; - sv.Layer.add(0); - sv.Sector.add(0); - sv.X0.add(Xb); - sv.Y0.add(Yb); - sv.Z0.add(0.0); - this.NDF = -5; - for (int i = 1; i < mv.measurements.size(); i++) { - sv.Layer.add(mv.measurements.get(i).layer); - sv.Sector.add(mv.measurements.get(i).sector); - if(mv.measurements.get(i).skip==false) { - this.NDF++; - } - Point3D ref = new Point3D(Xb, Yb, 0.0); - sv.X0.add(ref.x()); - sv.Y0.add(ref.y()); - sv.Z0.add(ref.z()); - } - sv.init( helix, cov, this, swimmer); - - } - - /** - * @return the resiCut - */ - public double getResiCut() { - return resiCut; + Zref, sv, mv, measSurfaces); } - - /** - * @param resiCut the resiCut to set - */ - public void setResiCut(double resiCut) { - this.resiCut = resiCut; - } - - public int totNumIter = 5; - double newChisq = Double.POSITIVE_INFINITY; - public void runFitter(Swim swimmer) { - double newchisq = Double.POSITIVE_INFINITY; - this.NDF = sv.X0.size()-5; - + this.runFitter(swimmer, sv, mv); + } + @Override + public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { + double newchisq = Double.POSITIVE_INFINITY; + for (int it = 0; it < totNumIter; it++) { this.chi2 = 0; - for (int k = 0; k < sv.X0.size() - 1; k++) { - if (sv.trackCov.get(k) == null || mv.measurements.get(k + 1) == null) { - return; - } - sv.transport(k, k + 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k+1), - swimmer); - this.filter(k + 1, swimmer, 1); - } - - for (int k = sv.X0.size() - 1; k>0 ;k--) { - if (sv.trackCov.get(k) == null || mv.measurements.get(k - 1) == null) { - return; - } - sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), - swimmer); - if(k>1) - this.filter(k - 1, swimmer, -1); - } - - // chi2 - this.chi2=this.calc_chi2(swimmer); + this.runFitterIter(swimmer, it, sv, mv); + + // chi2 + this.chi2=this.calc_chi2(swimmer, sv, mv); if(this.chi2 TrjPoints = new HashMap(); - public void setTrajectory() { + @Override + public void setTrajectory(AStateVecs sv, AMeasVecs mv) { TrjPoints.clear(); for (int k = 1; k < sv.trackTraj.size(); k++) { int layer = mv.measurements.get(k).layer; @@ -178,41 +88,8 @@ public void setTrajectory() { } } - - public Helix KFHelix; - - - public double chi2 = 0; - public int NDF = 0; - - private double calc_chi2(Swim swimmer) { - //get the measurement - double m = 0; - //get the projector state - double h = 0; - double chi2 =0; - m=0; - h=0; - int ndf = -5; - StateVec stv = sv.transported(0, 1, sv.trackTraj.get(0), mv.measurements.get(1), swimmer); - double dh = mv.dh(1, stv); - if(mv.measurements.get(1).skip==false) { - chi2 = dh*dh / mv.measurements.get(1).error; - ndf++; - } - for(int k = 1; k< sv.X0.size()-1; k++) { - if(mv.measurements.get(k+1).skip==false) { - stv = sv.transported(k, k+1, stv, mv.measurements.get(k+1), swimmer); - dh = mv.dh(k+1, stv); - chi2 += dh*dh / mv.measurements.get(k+1).error; - ndf++; - } - } - return chi2; - } - - private void filter(int k, Swim swimmer, int dir) { - + @Override + public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { if (sv.trackTraj.get(k) != null && sv.trackCov.get(k).covMat != null && mv.measurements.get(k).skip == false && filterOn) { @@ -224,52 +101,19 @@ private void filter(int k, Swim swimmer, int dir) { //get the projector Matrix double[] H = new double[5]; H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), swimmer, dir); - double[][] HTGH = new double[][]{ - {H[0] * H[0] / V, H[0] * H[1] / V, H[0] * H[2] / V, H[0] * H[3] / V, H[0] * H[4] / V}, - {H[1] * H[0] / V, H[1] * H[1] / V, H[1] * H[2] / V, H[1] * H[3] / V, H[1] * H[4] / V}, - {H[2] * H[0] / V, H[2] * H[1] / V, H[2] * H[2] / V, H[2] * H[3] / V, H[2] * H[4] / V}, - {H[3] * H[0] / V, H[3] * H[1] / V, H[3] * H[2] / V, H[3] * H[3] / V, H[3] * H[4] / V}, - {H[4] * H[0] / V, H[4] * H[1] / V, H[4] * H[2] / V, H[4] * H[3] / V, H[4] * H[4] / V} - }; - - Matrix Ci = null; - if (this.isNonsingular(sv.trackCov.get(k).covMat) == false) { - //System.err.println("Covariance Matrix is non-invertible - quit filter!"); - return; - } - try { - Ci = sv.trackCov.get(k).covMat.inverse(); - } catch (Exception e) { - return; - } - Matrix Ca = null; - try { - Ca = Ci.plus(new Matrix(HTGH)); - } catch (Exception e) { - return; - } - if (Ca != null && this.isNonsingular(Ca) == false) { - //System.err.println("Covariance Matrix Ca is non-invertible - quit filter!"); - return; - } - if (Ca != null && this.isNonsingular(Ca) == true) { - if (Ca.inverse() != null) { - Matrix CaInv = Ca.inverse(); + double[][] CaInv = mo.filterCovMat(H, sv.trackCov.get(k).covMat, V); + if (CaInv != null) { sv.trackCov.get(k).covMat = CaInv; - //System.err.println("Error: e"); } else { return; - } - } else { - return; } for (int j = 0; j < 5; j++) { // the gain matrix K[j] = 0; for (int i = 0; i < 5; i++) { - K[j] += H[i] * sv.trackCov.get(k).covMat.get(j, i) / V; + K[j] += H[i] * sv.trackCov.get(k).covMat[j][i] / V; } } if(sv.straight == true) { @@ -313,117 +157,63 @@ private void filter(int k, Swim swimmer, int dir) { sv.trackTraj.get(k).y = fVec.y; sv.trackTraj.get(k).z = fVec.z; } else { - this.NDF--; - mv.measurements.get(k).skip = true; + //this.NDF--; + //mv.measurements.get(k).skip = true; } } } - - /** - * @return the _Xb - */ - public double getXb() { - return _Xb; - } - - /** - * @param _Xb the _Xb to set - */ - public void setXb(double _Xb) { - this._Xb = _Xb; - } - - /** - * @return the _Yb - */ - public double getYb() { - return _Yb; - } - - /** - * @param _Yb the _Yb to set - */ - public void setYb(double _Yb) { - this._Yb = _Yb; - } - - /** - * @return the _tarShift - */ - public double getTarShift() { - return _tarShift; - } - - /** - * @param _TarShift the _tarShift to set - */ - public void setTarShift(double _TarShift) { - this._tarShift = _TarShift; - } - - /** - * prints the matrix -- used for debugging - * - * @param C matrix - */ - public void printMatrix(Matrix C) { - System.out.println(" "); - for (int k = 0; k < 5; k++) { - System.out.println(C.get(k, 0)+" "+C.get(k, 1)+" "+C.get(k, 2)+" "+C.get(k, 3)+" "+C.get(k, 4)); + + public void init(Helix helix, double[][] cov, DataEvent event, Swim swimmer, double Xb, double Yb, + double Zref, StateVecs sv, MeasVecs mv, List measSurfaces) { + sv.shift = Zref; + //iCov = cov; + mv.setMeasVecs(measSurfaces); + if (sv.Layer != null) { + sv.Layer.clear(); + } else { + sv.Layer = new ArrayList(); } - System.out.println(" "); - } - - private boolean isNonsingular(Matrix mat) { - double matDet = mat.det(); - if (Math.abs(matDet) < 1.e-30) { - return false; + if (sv.Sector != null) { + sv.Sector.clear(); } else { - return true; + sv.Sector = new ArrayList(); } - /* - for (int j = 0; j < mat.getColumnDimension(); j++) { - // if (Math.abs(mat.get(j, j)) < 0.00000000001) { - if (Math.abs(mat.get(j, j)) < 0.0000000001) { - return false; - } - } - */ - - } - - private void printStateVec(StateVec sv) { - System.out.println(sv.k+"] "); - System.out.println((float)sv.d_rho+", "+ - (float)sv.phi0+", "+ - (float)sv.kappa+", "+ - (float)sv.dz+", "+ - (float)sv.tanL+" xyz "+new Point3D(sv.x,sv.y,sv.z)+" phi "+Math.toDegrees(Math.atan2(sv.y,sv.x))+" theta "+Math.toDegrees(Math.atan2(sv.y,sv.z-sv.dz))); - System.out.println(" "); - } - - public class HitOnTrack { - - public int layer; - public double x; - public double y; - public double z; - public double px; - public double py; - public double pz; - public double resi; - public boolean isMeasUsed = true; - - HitOnTrack(int layer, double x, double y, double z, double px, double py, double pz, double resi) { - this.layer = layer; - this.x = x; - this.y = y; - this.z = z; - this.px = px; - this.py = py; - this.pz = pz; - this.resi = resi; + if (sv.X0 != null) { + sv.X0.clear(); + } else { + sv.X0 = new ArrayList(); } + if (sv.Y0 != null) { + sv.Y0.clear(); + } else { + sv.Y0 = new ArrayList(); + } + if (sv.Z0 != null) { + sv.Z0.clear(); + } else { + sv.Z0 = new ArrayList(); + } + //take first plane along beam line with n = y-dir; + sv.Layer.add(0); + sv.Sector.add(0); + sv.X0.add(Xb); + sv.Y0.add(Yb); + sv.Z0.add(0.0); + this.NDF = -5; + for (int i = 1; i < mv.measurements.size(); i++) { + sv.Layer.add(mv.measurements.get(i).layer); + sv.Sector.add(mv.measurements.get(i).sector); + if(mv.measurements.get(i).skip==false) { + this.NDF++; + } + Point3D ref = new Point3D(Xb, Yb, 0.0); + sv.X0.add(ref.x()); + sv.Y0.add(ref.y()); + sv.Z0.add(ref.z()); + } + sv.init( helix, cov, this, swimmer); + } + } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index ab5bdb391..66e94a951 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -5,207 +5,20 @@ */ package org.jlab.clas.tracking.kalmanfilter.helical; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.Surface; -import org.jlab.clas.tracking.kalmanfilter.Type; -import org.jlab.clas.tracking.kalmanfilter.helical.StateVecs.StateVec; -import org.jlab.clas.tracking.objects.Strip; -import org.jlab.geom.prim.Arc3D; -import org.jlab.geom.prim.Cylindrical3D; -import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Transformation3D; -import org.jlab.geom.prim.Vector3D; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs; /** * * @author ziegler */ +public class MeasVecs extends AMeasVecs { -public class MeasVecs { - - public List measurements = new ArrayList(); - - public void setMeasVecs(List measSurfaces) { - Collections.sort(measSurfaces); - for(int i = 0; i < measSurfaces.size(); i++) { - MeasVec mvec = new MeasVec(); - mvec.k = i ; - mvec.layer = measSurfaces.get(i).getLayer(); - mvec.sector = measSurfaces.get(i).getSector(); - mvec.surface = measSurfaces.get(i); - if(mvec.surface.getError()!=0) - mvec.error = mvec.surface.getError(); - mvec.l_over_X0 = mvec.surface.getl_over_X0(); - mvec.skip = mvec.surface.notUsedInFit; - mvec.hemisphere = measSurfaces.get(i).hemisphere; - measurements.add(mvec); - } - } - - - public double dh(int k, StateVec stateVec) { - - double value = Double.NaN; - - if (stateVec == null|| this.measurements.get(stateVec.k) == null) { - return value; - } - - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { - Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); - } - if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { - double phia = this.measurements.get(stateVec.k).surface.arc.theta(); - value = Math.atan2(stateVec.y, stateVec.x)-phia; - System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - Line3D WL = new Line3D(); - WL.copy(l); - WL.copy(WL.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z))); - - value = WL.length(); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - if(l.direction().z()<0) { - l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); - l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); - } - Line3D WL = new Line3D(); - WL.copy(l); - Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); - WL.copy(WL.distance(svP)); - double sideStrip = -Math.signum(l.direction().cross(WL.direction()). - dot(this.measurements.get(stateVec.k).surface.plane.normal())); - //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); - value = WL.length()*sideStrip; - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(stV); - value = stV.z()-this.measurements.get(stateVec.k).surface.strip.getZ(); - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Arc3D arc = new Arc3D(); - arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); - toLocal.apply(arc); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(stV); - value = stV.z()-arc.center().z(); - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(sv); - value = sv.toVector3D().phi()-this.measurements.get(stateVec.k).surface.strip.getPhi(); - if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; - } - } - return value; - } - - - public double getPhiATZ(StateVec stateVec) { - Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - double v = (stateVec.z-cyl.baseArc().center().z())/cln.direction().z(); - double x = cyl.baseArc().center().x()+v*cln.direction().x(); - double y = cyl.baseArc().center().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, stateVec.z). - vectorTo(new Point3D(stateVec.x,stateVec.y,stateVec.z)).asUnit(); - return n.phi(); - } - - public double getPhi(StateVec stateVec) { - Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); - this.measurements.get(stateVec.k).surface.toLocal().apply(sv); - return sv.toVector3D().phi(); - } - - public double h(int k, StateVec stateVec) { - - double value = Double.NaN; - - if (stateVec == null|| this.measurements.get(stateVec.k) == null) { - return value; - } - - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { - Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); - } - if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { - double phia = this.measurements.get(stateVec.k).surface.arc.theta(); - value = value = Math.atan2(stateVec.y, stateVec.x); - System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - if(l.direction().z()<0) { - l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); - l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); - } - Line3D WL = new Line3D(); - WL.copy(l); - Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); - WL.copy(WL.distance(svP)); - double sideStrip = -Math.signum(l.direction().cross(WL.direction()). - dot(this.measurements.get(stateVec.k).surface.plane.normal())); - //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); - value = WL.length()*sideStrip; - - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { - value = stateVec.z; - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(stV); - value = stV.z(); - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - //value = Math.atan2(stateVec.y, stateVec.x); - value = this.getPhi(stateVec); - } - } - return value; - } - - private double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; - double sqrt_epsilon = Math.sqrt(2.2*1.e-16); - private double[] Hval = new double[5]; - public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim swimmer, int dir) { - StateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); - StateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); + @Override + public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { + AStateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); + AStateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); delta_d_a[0]=2*sqrt_epsilon*(stateVec.d_rho+1); delta_d_a[1]=2*sqrt_epsilon*(stateVec.phi0+1); delta_d_a[2]=2*sqrt_epsilon*(stateVec.kappa+1); @@ -245,7 +58,8 @@ public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim sw return getHval(); } - private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec stateVec, StateVecs sv) { + @Override + public AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) { SVplus = sv.new StateVec(stateVec.k); SVplus.d_rho = stateVec.d_rho; SVplus.alpha = stateVec.alpha; @@ -257,47 +71,5 @@ private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec s return SVplus; } - - public class MeasVec implements Comparable { - public Surface surface; - public int layer = -1; - public int sector = -1; - public double error = 1; - public int k = -1; - public boolean skip = false; - // this is for multiple scattering estimates in track - public double l_over_X0; - //this is for energy loss - public double Z_over_A_times_l; - public double hemisphere = 1; - - - @Override - public int compareTo(MeasVec arg) { - int CompLay = this.layer < arg.layer ? -1 : this.layer == arg.layer ? 0 : 1; - return CompLay; - } - } - - /** - * @return the delta_d_a - */ - public double[] getDelta_d_a() { - return delta_d_a; - } - - /** - * @return the Hval - */ - public double[] getHval() { - return Hval; - } - - /** - * @param Hval the Hval to set - */ - public void setHval(double[] Hval) { - this.Hval = Hval; - } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 55ebb5fdc..7659aa165 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -1,49 +1,32 @@ +/* + * 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.tracking.kalmanfilter.helical; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import org.jlab.geom.prim.Vector3D; -import org.jlab.geom.prim.Point3D; -import Jama.Matrix; import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.helical.MeasVecs.MeasVec; +import org.jlab.clas.tracking.kalmanfilter.AKFitter; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +/** + * + * @author ziegler + */ +public class StateVecs extends AStateVecs { -public class StateVecs { - - private Helix util ; - public double units; - public double lightVel; - - public boolean straight; - public List bfieldPoints = new ArrayList(); - public Map trackTraj = new HashMap(); - public Map trackCov = new HashMap(); - - public StateVec StateVec; - public CovMat CovMat; - public Matrix F; - MeasVecs mv = new MeasVecs(); - - public List X0; - public List Y0; - public List Z0; // reference points - public double shift; // target shift - public List Layer; - public List Sector; - - double[] value = new double[4]; // x,y,z,phi + double[] swimPars = new double[7]; - B Bf = new B(0); - - public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, - boolean useSwimmer) { + @Override + public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec mv, Swim swim, boolean useSwimmer) { if(swimPars!=null) { this.resetArrays(swimPars); } else { @@ -57,7 +40,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim Point3D ps = new Point3D(0,0,0) ; - StateVec kVec = new StateVec(k); + AStateVecs.StateVec kVec = new AStateVecs.StateVec(k); kVec.phi0 = iVec.phi0; kVec.d_rho = iVec.d_rho; kVec.kappa = iVec.kappa; @@ -114,13 +97,6 @@ else if(mv.surface.cylinder!=null) { Point3D cylInt = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); mv.surface.toGlobal().apply(cylInt); // RDV: should switch to use clas-geometry intersection method, not done now to alwys return a value -// List inters = new ArrayList<>(); -// int ints = mv.surface.cylinder.intersection(toPln, inters); -// if(ints==1) { -// kVec.x = inters.get(0).x(); -// kVec.y = inters.get(0).y(); -// kVec.z = inters.get(0).z(); -// } kVec.x = cylInt.x(); kVec.y = cylInt.y(); kVec.z = cylInt.z(); @@ -133,40 +109,6 @@ else if(mv.surface.cylinder!=null) { return value; } else { if(mv.surface.plane!=null) { - //Update B -// double r0 = mv.surface.finitePlaneCorner1.toVector3D().dot(mv.surface.plane.normal()); -// double stepSize = 5; //mm -// int nSteps = (int) (r0/stepSize); -// -// double dist = 0; -// -// for(int i = 1; i 0) { if (dir >0 ) { Vector3D trkDir = this.P(iVec.k).asUnit(); @@ -429,40 +369,17 @@ private Matrix Q(StateVec iVec, MeasVec mVec, int dir) { //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* // (1 + Math.log(t_ov_X0)/9.); } - Q = new Matrix(new double[][]{ + Q = new double[][]{ {0, 0, 0, 0, 0}, {0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL), 0, 0, 0}, {0, 0, sctRMS*sctRMS * (iVec.kappa * iVec.kappa * iVec.tanL * iVec.tanL), 0, sctRMS*sctRMS * (iVec.kappa * iVec.tanL * (1 + iVec.tanL * iVec.tanL))}, {0, 0, 0, 0, 0}, {0, 0, sctRMS*sctRMS * (iVec.kappa * iVec.tanL * (1 + iVec.tanL * iVec.tanL)), 0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL) * (1 + iVec.tanL * iVec.tanL)} - }); + }; } return Q; } - - private StateVec reset(StateVec SV, StateVec stateVec) { - SV = new StateVec(stateVec.k); - SV.x = stateVec.x; - SV.y = stateVec.y; - SV.z = stateVec.z; - SV.d_rho = stateVec.d_rho; - SV.dz = stateVec.dz; - SV.phi0 = stateVec.phi0; - SV.phi = stateVec.phi; - SV.tanL = stateVec.tanL; - SV.alpha = stateVec.alpha; - SV.kappa = stateVec.kappa; - - return SV; - } - - private void resetArrays(double[] swimPars) { - for(int i = 0; i TrjPoints = new HashMap(); + StateVecs sv = new StateVecs(); + MeasVecs mv = new MeasVecs(); + public StateVecs.StateVec finalStateVec; - public void setMeasurements(List measSurfaces) { - mv.setMeasVecs(measSurfaces); - } - //double x0, double z0,double px,double py,double pz, double units, Matrix cov, KFitter kf - public KFitter(double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf, + public KFitter(double x0, double z0,double tx,double tz, double units, double[][] cov, KFitter kf, List measSurfaces) { this.init(x0, z0, tx, tz, units, cov, kf, measSurfaces); } - //private Matrix iCov; - public void init(double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf, - List measSurfaces) { - mv.setMeasVecs(measSurfaces); - if (sv.Layer != null) { - sv.Layer.clear(); - } else { - sv.Layer = new ArrayList(); - } - if (sv.Sector != null) { - sv.Sector.clear(); - } else { - sv.Sector = new ArrayList(); - } - for(int j =0; j<5; j++) { - mv.delta_d_a[j]=cov.get(j, j); - } - //take first plane along beam line with n = y-dir; - sv.Layer.add(0); - sv.Sector.add(0); - this.NDF = -4; - for (int i = 1; i < mv.measurements.size(); i++) { - sv.Layer.add(mv.measurements.get(i).layer); - sv.Sector.add(mv.measurements.get(i).sector); - if(mv.measurements.get(i).skip==false) { - this.NDF++; - } - Point3D ref = new Point3D(0.0, 0.0, 0.0); - } - sv.init(x0, z0, tx, tz, units, cov, kf); - //double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf - } - - /** - * @return the resiCut - */ - public double getResiCut() { - return resiCut; - } - - /** - * @param resiCut the resiCut to set - */ - public void setResiCut(double resiCut) { - this.resiCut = resiCut; - } - - public int totNumIter = 5; - double newChisq = Double.POSITIVE_INFINITY; - public void runFitter(Swim swimmer) { + this.runFitter(swimmer, sv, mv); + } + + @Override + public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { double newchisq = Double.POSITIVE_INFINITY; this.NDF = sv.Layer.size()-5; for (int it = 0; it < totNumIter; it++) { this.chi2 = 0; - for (int k = 0; k < sv.Layer.size() - 1; k++) { - if (sv.trackCov.get(k) == null || mv.measurements.get(k + 1) == null) { - return; - } - sv.transport(k, k + 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k+1), - swimmer); - this.filter(k + 1, swimmer, 1); - - } - - - // chi2 - //this.chi2=this.calc_chi2(swimmer); - //int k1 = this.getk(swimmer); + this.runFitterIter(swimmer, it, sv, mv); if(sv.trackTraj.get(1)!=null) { finalStateVec = sv.trackTraj.get(1); finalStateVec.x = finalStateVec.x0; @@ -121,73 +62,23 @@ public void runFitter(Swim swimmer) { yz_interc = finalStateVec.z0; - this.setTrajectory(swimmer); + this.setTrajectory(sv, mv); setFitFailed = false; - //if(newchisq-this.chi2<0.0001) - // break; - //newchisq = this.chi2; } else { //this.chi2 =newchisq ; //break; } } - - } - private int getk(Swim swimmer) { - int k = -1; - double chi2 = Double.POSITIVE_INFINITY; - for (int k1 = 1; k1 < sv.trackTraj.size(); k1++) { - double newchi2 = this.calc_chi2(swimmer, k1); - if(newchi2 TrjPoints = new HashMap(); - public void setTrajectory(Swim swimmer) { + @Override + public void setTrajectory(AStateVecs sv, AMeasVecs mv) { TrjPoints.clear(); double c2 = 0; for (int k = 0; k < sv.trackTraj.size()-1; k++) { - StateVec stv = sv.transported(k, k+1, sv.trackTraj.get(k), mv.measurements.get(k+1), swimmer); - sv.setStateVecPosAtMeasSite(k+1, stv, mv.measurements.get(k+1), swimmer); + StateVec stv = sv.transported(k, k+1, sv.trackTraj.get(k), mv.measurements.get(k+1), null); + sv.setStateVecPosAtMeasSite(k+1, stv, mv.measurements.get(k+1), null); double resi = mv.dh(k+1, stv); c2 += resi*resi / mv.measurements.get(k+1).error; int layer = mv.measurements.get(k+1).layer; @@ -207,209 +98,87 @@ public void setTrajectory(Swim swimmer) { this.chi2 = c2; } - public double chi2 = 0; - public int NDF = 0; - - private double calc_chi2(Swim swimmer) { - //get the measurement - double m = 0; - //get the projector state - double h = 0; - double chi2 =0; - m=0; - h=0; - int ndf = -5; - StateVec stv = sv.trackTraj.get(1); - double dh = sv.trackTraj.get(1).resi; - if(mv.measurements.get(1).skip==false) { - chi2 = dh*dh / mv.measurements.get(1).error; - ndf++; - } - for(int k = 2; k< sv.Layer.size(); k++) { - if(mv.measurements.get(k).skip==false) { - stv = sv.trackTraj.get(k); - dh = sv.trackTraj.get(k).resi; - //sv.trackTraj.get(k+1).resi = dh; - chi2 += dh*dh / mv.measurements.get(k).error; - this.printStateVec(sv.trackTraj.get(k)); - ndf++; - } - } - return chi2; - } - - private void filter(int k, Swim swimmer, int dir) { - + @Override + public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { if (sv.trackTraj.get(k) != null && sv.trackCov.get(k).covMat != null && mv.measurements.get(k).skip == false ) { - double[] K = new double[5]; double V = mv.measurements.get(k).error; - + //get the projector Matrix double[] H = new double[5]; H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), swimmer, dir); - double[][] HTGH = new double[][]{ - {H[0] * H[0] / V, H[0] * H[1] / V, H[0] * H[2] / V, H[0] * H[3] / V, H[0] * H[4] / V}, - {H[1] * H[0] / V, H[1] * H[1] / V, H[1] * H[2] / V, H[1] * H[3] / V, H[1] * H[4] / V}, - {H[2] * H[0] / V, H[2] * H[1] / V, H[2] * H[2] / V, H[2] * H[3] / V, H[2] * H[4] / V}, - {H[3] * H[0] / V, H[3] * H[1] / V, H[3] * H[2] / V, H[3] * H[3] / V, H[3] * H[4] / V}, - {H[4] * H[0] / V, H[4] * H[1] / V, H[4] * H[2] / V, H[4] * H[3] / V, H[4] * H[4] / V} - }; - - Matrix Ci = null; - if (this.isNonsingular(sv.trackCov.get(k).covMat) == false) { - //System.err.println("Covariance Matrix is non-invertible - quit filter!"); - return; - } - try { - Ci = sv.trackCov.get(k).covMat.inverse(); - } catch (Exception e) { - return; - } - Matrix Ca = null; - try { - Ca = Ci.plus(new Matrix(HTGH)); - } catch (Exception e) { - return; - } - if (Ca != null && this.isNonsingular(Ca) == false) { - //System.err.println("Covariance Matrix Ca is non-invertible - quit filter!"); - return; - } - if (Ca != null && this.isNonsingular(Ca) == true) { - if (Ca.inverse() != null) { - Matrix CaInv = Ca.inverse(); + double[][] CaInv = mo.filterCovMat(H, sv.trackCov.get(k).covMat, V); + if (CaInv != null) { sv.trackCov.get(k).covMat = CaInv; } else { return; - } - } else { - return; } - for (int j = 0; j < 4; j++) { - // the gain matrix - K[j] = 0; - if(filterOn) { - for (int i = 0; i < 4; i++) { - K[j] += H[i] * sv.trackCov.get(k).covMat.get(j, i) / V; - } + // the gain matrix + K[j] = 0; + if(filterOn) { + for (int i = 0; i < 4; i++) { + K[j] += H[i] * sv.trackCov.get(k).covMat[j][i] / V; + } + } } - } - double x0_filt = sv.trackTraj.get(k).x0; - double z0_filt = sv.trackTraj.get(k).z0; - double tx_filt = sv.trackTraj.get(k).tx; - double tz_filt = sv.trackTraj.get(k).tz; - - double dh =0; - for(int i = 1; i measSurfaces) { + mv.setMeasVecs(measSurfaces); + if (sv.Layer != null) { + sv.Layer.clear(); + } else { + sv.Layer = new ArrayList(); } - System.out.println(" "); - } - - private boolean isNonsingular(Matrix mat) { - double matDet = mat.det(); - if (Math.abs(matDet) < 1.e-30) { - return false; + if (sv.Sector != null) { + sv.Sector.clear(); } else { - return true; + sv.Sector = new ArrayList(); } - /* - for (int j = 0; j < mat.getColumnDimension(); j++) { - // if (Math.abs(mat.get(j, j)) < 0.00000000001) { - if (Math.abs(mat.get(j, j)) < 0.0000000001) { - return false; - } - } - */ - - } - - private void printStateVec(StateVec sv) { - System.out.println(sv.k+"] "); - System.out.println((float)sv.x0+", "+ - (float)sv.z0+", "+ - (float)sv.tx+", "+ - (float)sv.tz+", "+ - " xyz "+new Point3D(sv.x,sv.y,sv.z).toString()); - System.out.println(" "); - } - - public class HitOnTrack { - - public int layer; - public double x; - public double y; - public double z; - public double px; - public double py; - public double pz; - public double resi; - public boolean isMeasUsed = true; - - HitOnTrack(int layer, double x, double y, double z, double px, double py, double pz, double resi) { - this.layer = layer; - this.x = x; - this.y = y; - this.z = z; - this.px = px; - this.py = py; - this.pz = pz; - this.resi = resi; + for(int j =0; j<5; j++) { + mv.delta_d_a[j]=cov[j][j]; } + //take first plane along beam line with n = y-dir; + sv.Layer.add(0); + sv.Sector.add(0); + this.NDF = -4; + for (int i = 1; i < mv.measurements.size(); i++) { + sv.Layer.add(mv.measurements.get(i).layer); + sv.Sector.add(mv.measurements.get(i).sector); + if(mv.measurements.get(i).skip==false) { + this.NDF++; + } + Point3D ref = new Point3D(0.0, 0.0, 0.0); + } + sv.init(x0, z0, tx, tz, units, cov, kf); + //double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java index 9ab21854d..7dbab1c4b 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java @@ -5,212 +5,20 @@ */ package org.jlab.clas.tracking.kalmanfilter.straight; -import org.jlab.clas.tracking.kalmanfilter.straight.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.Surface; -import org.jlab.clas.tracking.kalmanfilter.Type; -import org.jlab.clas.tracking.kalmanfilter.straight.StateVecs.StateVec; -import org.jlab.clas.tracking.objects.Strip; -import org.jlab.geom.prim.Arc3D; -import org.jlab.geom.prim.Cylindrical3D; -import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Transformation3D; -import org.jlab.geom.prim.Vector3D; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs; /** * * @author ziegler */ +public class MeasVecs extends AMeasVecs { -public class MeasVecs { - - public List measurements = new ArrayList(); - - public void setMeasVecs(List measSurfaces) { - Collections.sort(measSurfaces); - for(int i = 0; i < measSurfaces.size(); i++) { - MeasVec mvec = new MeasVec(); - mvec.k = i ; - mvec.layer = measSurfaces.get(i).getLayer(); - mvec.sector = measSurfaces.get(i).getSector(); - mvec.surface = measSurfaces.get(i); - if(mvec.surface.getError()!=0) - mvec.error = mvec.surface.getError(); - mvec.l_over_X0 = mvec.surface.getl_over_X0(); - mvec.skip = mvec.surface.notUsedInFit; - mvec.hemisphere = measSurfaces.get(i).hemisphere; - measurements.add(mvec); - } - } - - - public double dh(int k, StateVec stateVec) { - - double value = Double.NaN; - - if (stateVec == null|| this.measurements.get(stateVec.k) == null) { - return value; - } - - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { - Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); - } - if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { - double phia = this.measurements.get(stateVec.k).surface.arc.theta(); - value = Math.atan2(stateVec.y, stateVec.x)-phia; - System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - Line3D WL = new Line3D(); - WL.copy(l); - WL.copy(WL.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z))); - - value = WL.length(); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - if(l.direction().z()<0) { - l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); - l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); - } - Line3D WL = new Line3D(); - WL.copy(l); - Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); - WL.copy(WL.distance(svP)); - double sideStrip = -Math.signum(l.direction().cross(WL.direction()). - dot(this.measurements.get(stateVec.k).surface.plane.normal())); - //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); - value = WL.length()*sideStrip; - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { - value = stateVec.z-this.measurements.get(stateVec.k).surface.strip.getZ(); - } - - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Arc3D arc = new Arc3D(); - arc.copy(this.measurements.get(stateVec.k).surface.strip.getArc()); - toLocal.apply(arc); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(stV); - value = stV.z()-arc.center().z(); - } - - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - value = this.getPhi(stateVec)-this.measurements.get(stateVec.k).surface.strip.getPhi(); - } - } - return value; - } - - public double getPhiATZ(StateVec stateVec) { - Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - double v = (stateVec.z-cyl.baseArc().center().z())/cln.direction().z(); - double x = cyl.baseArc().center().x()+v*cln.direction().x(); - double y = cyl.baseArc().center().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, stateVec.z). - vectorTo(new Point3D(stateVec.x,stateVec.y,stateVec.z)).asUnit(); - return n.phi(); - } - - public double getPhi(StateVec stateVec) { - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - - double v = (cln.origin().z()-stateVec.z)/cln.direction().z(); - double xs = stateVec.x+v*cln.direction().x(); - double ys = stateVec.y+v*cln.direction().y(); - - Vector3D n = new Point3D(cln.origin().x(), cln.origin().y(), cln.origin().z()). - vectorTo(new Point3D(xs,ys,cln.origin().z())).asUnit(); - return n.phi(); - } - - public double h(int k, StateVec stateVec) { - - double value = Double.NaN; - - if (stateVec == null|| this.measurements.get(stateVec.k) == null) { - return value; - } - - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { - Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); - } - if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { - double phia = this.measurements.get(stateVec.k).surface.arc.theta(); - value = value = Math.atan2(stateVec.y, stateVec.x); - System.err.println("ARC MEAS. NOT FULLY IMPLEMENTED!!!!!!"); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHLINE || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHLINE) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - } - if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHSTRIP || - this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHSTRIP) { - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.XYZ) { - Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, - this.measurements.get(stateVec.k).surface.lineEndPoint2); - //value = l.distance(new Point3D(stateVec.x, stateVec.y, stateVec.z)).length(); - if(l.direction().z()<0) { - l.setEnd(this.measurements.get(stateVec.k).surface.lineEndPoint1); - l.setOrigin(this.measurements.get(stateVec.k).surface.lineEndPoint2); - } - Line3D WL = new Line3D(); - WL.copy(l); - Point3D svP = new Point3D(stateVec.x, stateVec.y, stateVec.z); - WL.copy(WL.distance(svP)); - double sideStrip = -Math.signum(l.direction().cross(WL.direction()). - dot(this.measurements.get(stateVec.k).surface.plane.normal())); - //double sideStrip = Math.signum(l.direction().y()*WL.direction().x()+l.direction().x()*WL.direction().y()); - value = WL.length()*sideStrip; - - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.Z) { - value = stateVec.z; - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.ARC) { - Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); - Point3D stV = new Point3D(stateVec.x, stateVec.y, stateVec.z); - toLocal.apply(stV); - value = stV.z(); - } - if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - //value = Math.atan2(stateVec.y, stateVec.x); - value = this.getPhi(stateVec); - } - } - return value; - } - - public double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; - double sqrt_epsilon = Math.sqrt(2.2*1.e-16); - private double[] Hval = new double[5]; - public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim swimmer, int dir) { - StateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); - StateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); - //delta_d_a[0]=2*sqrt_epsilon*(stateVec.x0+1); - //delta_d_a[1]=2*sqrt_epsilon*(stateVec.z0+1); - //delta_d_a[2]=2*sqrt_epsilon*(stateVec.tx+1); - //delta_d_a[3]=2*sqrt_epsilon*(stateVec.tz+1); + @Override + public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { + AStateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); + AStateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); for(int i = 0; i < getHval().length; i++) getHval()[i] = 0; @@ -241,7 +49,8 @@ public double[] H(StateVecs.StateVec stateVec, StateVecs sv, MeasVec mv, Swim sw return getHval(); } - private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec stateVec, StateVecs sv) { + @Override + public AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) { SVplus = sv.new StateVec(stateVec.k); SVplus.x0 = stateVec.x0; SVplus.z0 = stateVec.z0; @@ -253,46 +62,5 @@ private StateVecs.StateVec reset(StateVecs.StateVec SVplus, StateVecs.StateVec s return SVplus; } - - public class MeasVec implements Comparable { - public Surface surface; - public int layer = -1; - public int sector = -1; - public double error = 1; - public int k = -1; - public boolean skip = false; - // this is for multiple scattering estimates in track - public double l_over_X0; - //this is for energy loss - public double Z_over_A_times_l; - public double hemisphere = 1; - - @Override - public int compareTo(MeasVec arg) { - int CompLay = this.layer < arg.layer ? -1 : this.layer == arg.layer ? 0 : 1; - return CompLay; - } - } - - /** - * @return the delta_d_a - */ - public double[] getDelta_d_a() { - return delta_d_a; - } - - /** - * @return the Hval - */ - public double[] getHval() { - return Hval; - } - - /** - * @param Hval the Hval to set - */ - public void setHval(double[] Hval) { - this.Hval = Hval; - } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index c23378b44..ff2bfd0ea 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -1,50 +1,30 @@ +/* + * 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.tracking.kalmanfilter.straight; -import org.jlab.clas.tracking.kalmanfilter.straight.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.jlab.geom.prim.Vector3D; -import org.jlab.geom.prim.Point3D; -import Jama.Matrix; import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.straight.MeasVecs.MeasVec; +import org.jlab.clas.tracking.kalmanfilter.AKFitter; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; +import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; +import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.trackrep.Helix; -import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +/** + * + * @author ziegler + */ +public class StateVecs extends AStateVecs { -public class StateVecs { - - private Helix util ; - public double units; - public double lightVel; - public List bfieldPoints = new ArrayList(); - public Map trackTraj = new HashMap(); - public Map trackCov = new HashMap(); - - public StateVec StateVec; - public CovMat CovMat; - public Matrix F; - MeasVecs mv = new MeasVecs(); - - //public List X0; - //public List Y0; - //public List Z0; // reference points - public double shift; // target shift - public List Layer; - public List Sector; - - double[] value = new double[4]; // x,y,z,phi - double[] swimPars = new double[7]; - B Bf = new B(0); - - public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, - boolean useSwimmer) { + @Override + public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec mv, Swim swim, boolean useSwimmer) { if(swimPars!=null) { this.resetArrays(swimPars); } else { @@ -134,7 +114,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim } return value; } - + @Override public void setStateVecPosAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer) { double[] pars = this.getStateVecPosAtMeasSite(k, kVec, mv, swimmer, true); @@ -162,13 +142,14 @@ public StateVec newStateVecAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swi // new state: return newVec; } - private void tranState(int f, StateVec iVec, Swim swimmer) { + @Override + public void tranState(int f, StateVec iVec, Swim swimmer) { + } - public StateVec transported(int i, int f, StateVec iVec, MeasVec mv, - Swim swimmer) { - + @Override + public StateVec transported(int i, int f, StateVec iVec, AMeasVecs.MeasVec mv, Swim swimmer) { // transport stateVec... StateVec fVec = new StateVec(f); @@ -186,10 +167,9 @@ public StateVec transported(int i, int f, StateVec iVec, MeasVec mv, return fVec; } - public void transport(int i, int f, StateVec iVec, CovMat icovMat, MeasVec mv, - Swim swimmer) { - - StateVec fVec = this.transported(i, f, iVec, mv, swimmer); + @Override + public void transport(int i, int f, StateVec iVec, CovMat icovMat, AMeasVecs.MeasVec mv, Swim swimmer) { + AStateVecs.StateVec fVec = this.transported(i, f, iVec, mv, swimmer); double[][] FMat = new double[][]{ {1, 0, 0, 0, 0}, @@ -199,30 +179,26 @@ public void transport(int i, int f, StateVec iVec, CovMat icovMat, MeasVec mv, {0, 0, 0, 0, 1} }; - //StateVec = fVec; + this.trackTraj.put(f, fVec); - F = new Matrix(FMat); - Matrix FT = F.transpose(); - Matrix Cpropagated = FT.times(icovMat.covMat).times(F); + //F = new Matrix(); + //F.set(FMat); + + double[][] Cpropagated = propagatedMatrix(FMat, icovMat.covMat, FMat); + if (Cpropagated != null) { CovMat fCov = new CovMat(f); - fCov.covMat = Cpropagated.plus(this.Q(iVec, mv, (int)Math.signum(fVec.y-iVec.y))); + double[][] CPN = addProcessNoise(Cpropagated, this.Q(iVec, mv, f - i)); + + fCov.covMat = CPN; //CovMat = fCov; this.trackCov.put(f, fCov); } } - - private Matrix Q(StateVec iVec, MeasVec mVec, int dir) { - Matrix Q = new Matrix(new double[][]{ - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0} - }); - - // if (iVec.k % 2 == 1 && dir > 0) { + @Override + public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { + double[][] Q = new double[5][5]; if (dir >0 ) { Vector3D trkDir = this.P(iVec.k).asUnit(); Vector3D trkPos = this.X(iVec.k); @@ -252,22 +228,20 @@ private Matrix Q(StateVec iVec, MeasVec mVec, int dir) { double cov_txtx = (1 + tx * tx) * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; double cov_tztz = (1 + tz * tz) * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; double cov_txtz = tx * tz * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; - - Q = new Matrix(new double[][]{ + Q = new double[][]{ {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, cov_txtx, cov_txtz, 0}, {0, 0, cov_txtz, cov_tztz, 0}, {0, 0, 0, 0, 0} - }); - + }; } - return Q; } - private StateVec reset(StateVec SV, StateVec stateVec) { + @Override + public StateVec reset(StateVec SV, StateVec stateVec) { SV = new StateVec(stateVec.k); SV.x = stateVec.x; SV.y = stateVec.y; @@ -281,102 +255,7 @@ private StateVec reset(StateVec SV, StateVec stateVec) { return SV; } - private void resetArrays(double[] swimPars) { - for(int i = 0; i Date: Wed, 27 Oct 2021 15:05:58 -0400 Subject: [PATCH 198/291] Move overlap remover before trajectory making. Switch to matrix arrays and ops instead of JAMA. Switch to new KF. --- .../main/java/org/jlab/rec/cvt/Constants.java | 28 +++ .../jlab/rec/cvt/banks/RecoBankWriter.java | 20 +-- .../org/jlab/rec/cvt/fit/CircleFitter.java | 99 +++++++--- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 28 +-- .../jlab/rec/cvt/fit/StraightTrackFitter.java | 15 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 22 +++ .../rec/cvt/services/CosmicTracksRec.java | 15 +- .../jlab/rec/cvt/services/RecUtilities.java | 170 +++++++++--------- .../rec/cvt/services/TracksFromTargetRec.java | 72 ++++---- .../jlab/rec/cvt/track/TrackListFinder.java | 5 +- .../org/jlab/rec/cvt/trajectory/Helix.java | 12 +- .../org/jlab/rec/cvt/trajectory/StateVec.java | 76 +++----- 12 files changed, 321 insertions(+), 241 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index e9d4584c0..f46f3dd23 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -6,6 +6,8 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.rec.cvt.bmt.BMTConstants; +import org.jlab.clas.tracking.utilities.MatrixOps.*; + public class Constants { public static double PTCUT = 0.075; @@ -304,6 +306,32 @@ public static final boolean isSVTOnly() { public static final void setSVTOnly(boolean sVTOnly) { SVTOnly = sVTOnly; } + + /** + * @return the matLib + */ + private static Libr getMatLib(String matLib) { + String type = matLib; + switch (type) { + case "JAMA": + return Libr.JAMA; + case "JNP": + return Libr.JNP; + case "APA": + return Libr.APA; + case "EJML": + return Libr.EJML; + default: + return Libr.EJML; + } + } + public static Libr kfMatLib; + /** + * @param aMatLib the matLib to set + */ + public static void setMatLib(String aMatLib) { + kfMatLib = getMatLib(aMatLib); + } public static double getSolenoidMagnitude() { float[] b = new float[3]; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 5a9c29305..be4e3b48b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -14,7 +14,7 @@ import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.StateVec; -import Jama.Matrix; +//import Jama.Matrix; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.Constants; @@ -419,16 +419,16 @@ public DataBank fillTracksBank(DataEvent event, List trkcands, double zSh // | d_curvature*d_dca d_curvature*d_phi_at_dca d_curvature*d_curvature 0 0 | // | 0 0 0 d_Z0*d_Z0 | // | 0 0 0 0 d_tandip*d_tandip |X - Matrix covmatrix = helix.get_covmatrix(); + double[][] covmatrix = helix.get_covmatrix(); if (covmatrix != null) { - bank.setFloat("cov_d02", i, (float) covmatrix.get(0, 0)); - bank.setFloat("cov_d0phi0", i, (float) covmatrix.get(0, 1)); - bank.setFloat("cov_d0rho", i, (float) covmatrix.get(0, 2)); - bank.setFloat("cov_phi02", i, (float) covmatrix.get(1, 1)); - bank.setFloat("cov_phi0rho", i, (float) covmatrix.get(1, 2)); - bank.setFloat("cov_rho2", i, (float) covmatrix.get(2, 2)); - bank.setFloat("cov_z02", i, (float) covmatrix.get(3, 3)); - bank.setFloat("cov_tandip2", i, (float) covmatrix.get(4, 4)); + bank.setFloat("cov_d02", i, (float) covmatrix[0][0] ); + bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1] ); + bank.setFloat("cov_d0rho", i, (float) covmatrix[0][2] ); + bank.setFloat("cov_phi02", i, (float) covmatrix[1][1] ); + bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2] ); + bank.setFloat("cov_rho2", i, (float) covmatrix[2][2] ); + bank.setFloat("cov_z02", i, (float) covmatrix[3][3] ); + bank.setFloat("cov_tandip2", i, (float) covmatrix[4][4] ); } else { bank.setFloat("cov_d02", i, -999); bank.setFloat("cov_d0phi0", i, -999); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index 69bdbd993..fc72b61f0 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -5,7 +5,7 @@ import org.jlab.rec.cvt.Constants; -import Jama.Matrix; +//import Jama.Matrix; /** * Circle fit using the Karimaki algorithm. The algorithm returns Gaussian @@ -188,16 +188,19 @@ public boolean fitStatus(List xm, List ym, List wm, int double invV_dd = rhoFit * (rhoFit * S_alphalpha - 2. * u * S_alpha) + u * u * Sw; double[][] array = {{invV_rhorho, invV_rhophi, invV_rhod}, {invV_rhophi, invV_phiphi, invV_phid}, {invV_rhod, invV_phid, invV_dd}}; - Matrix inv_V = new Matrix(array); - Matrix V = inv_V.inverse(); - Matrix result = new Matrix(V.getArray()); - - double V_rhorho = result.get(0, 0); - double V_rhophi = result.get(0, 1); - double V_rhod = result.get(0, 2); - double V_phiphi = result.get(1, 1); - double V_phid = result.get(1, 2); - double V_dd = result.get(2, 2); + //Matrix inv_V = new Matrix(array); + //Matrix V = inv_V.inverse(); + //Matrix result = new Matrix(V.getArray()); + // using this class methods + + double[][] mat3x3= invert3x3Matrix(array); + + double V_rhorho = mat3x3[0][0]; + double V_rhophi = mat3x3[0][1]; + double V_rhod = mat3x3[0][2]; + double V_phiphi = mat3x3[1][1]; + double V_phid = mat3x3[1][2]; + double V_dd = mat3x3[2][2]; // Fill the covariance matrix _covr[0] = V_rhorho; @@ -263,19 +266,23 @@ void propagatePars(double xr, double yr, double x, double y, double cosphi, doub double[][] Varray = {{_covr[0], _covr[1], _covr[2]}, {_covr[1], _covr[3], _covr[4]}, {_covr[2], _covr[4], _covr[5]}}; - Matrix J = new Matrix(Jarray); - Matrix JT = J.transpose(); - Matrix V = new Matrix(Varray); - Matrix Vp = J.times(V.times(JT)); - - Matrix result = new Matrix(Vp.getArray()); - - double Vp_rhorho = result.get(0, 0); - double Vp_rhophi = result.get(0, 1); - double Vp_rhod = result.get(0, 2); - double Vp_phiphi = result.get(1, 1); - double Vp_phid = result.get(1, 2); - double Vp_dd = result.get(2, 2); + // Matrix J = new Matrix(Jarray); +// Matrix JT = J.transpose(); +// Matrix V = new Matrix(Varray); +// Matrix Vp = J.times(V.times(JT)); +// +// Matrix result = new Matrix(Vp.getArray()); + + double[][] JarrayT = this.transpose3x3Matrix(Jarray); + double[][] VJT = this.multiply3x3Matrices(Varray, JarrayT); + double[][] JVJT = this.multiply3x3Matrices(Jarray, VJT); + + double Vp_rhorho = JVJT[0][0]; + double Vp_rhophi = JVJT[0][1]; + double Vp_rhod = JVJT[0][2]; + double Vp_phiphi = JVJT[1][1]; + double Vp_phid = JVJT[1][2]; + double Vp_dd = JVJT[2][2]; //3. Fill the covariance matrix /* @@ -366,4 +373,48 @@ public static void main(String[] args) { boolean circlefitstatusOK = _circlefit.fitStatus(xm, ym, wm, xm.size()); } + + public double[][] transpose3x3Matrix(double[][] theMatrix){ + int c1=3; int c2=3; + double[][] transpMatrix = new double[c2][c1]; + for (int i = 0; i < c1; i++) + for (int j = 0; j < c2; j++) + transpMatrix[i][j] = theMatrix[j][i]; + + return transpMatrix; + } + + public double[][] multiply3x3Matrices(double[][] firstMatrix, double[][] secondMatrix) { + int r1 =3; int c1=3; int c2=3; + double[][] product = new double[r1][c2]; + for(int i = 0; i < r1; i++) { + for (int j = 0; j < c2; j++) { + for (int k = 0; k < c1; k++) { + product[i][j] += firstMatrix[i][k] * secondMatrix[k][j]; + } + } + } + + return product; + } + public double[][] invert3x3Matrix(double[][] m) { + double[][] minv = new double[3][3]; + // computes the inverse of a matrix m + double det = m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) - + m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); + + double invdet = 1 / det; + minv[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * invdet; + minv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * invdet; + minv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invdet; + minv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) * invdet; + minv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invdet; + minv[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * invdet; + minv[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]) * invdet; + minv[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * invdet; + minv[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * invdet; + + return minv; + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index f17052439..0de98a4cd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -5,7 +5,7 @@ import org.jlab.rec.cvt.trajectory.Helix; -import Jama.Matrix; +//import Jama.Matrix; import org.jlab.rec.cvt.svt.SVTGeometry; /** @@ -168,7 +168,7 @@ public FitStatus fit(List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List FindClustersOnTrkNew (List allClusters, List seedCluster, Helix helix, double P, int Q, + public List FindClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, SVTGeometry sgeo, Swim swimmer) { // initialize swimmer starting from the track vertex @@ -334,88 +335,88 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrk (List allClusters, List seedCluster, Helix helix, double P, int Q, - SVTGeometry sgeo, Swim swimmer) { - Map clusMap = new HashMap(); - //Map stripMap = new HashMap(); - Map docaMap = new HashMap(); - Map trajMap = new HashMap(); - int[] Sectors = new int[SVTGeometry.NLAYERS]; - // RDV it is not correct for tilte/shifted geometry - for (int a = 0; a < Sectors.length; a++) { - Point3D I = helix.getPointAtRadius(sgeo.getLayerRadius(a+1)); - int sec = sgeo.getSector(a+1, I); - Sectors[a] = sec; - } - // initialize swimmer starting from the track vertex - double maxPathLength = 1; - swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, - Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), - P, Q, maxPathLength) ; - double[] inters = null; - double path = 0; - // SVT - for (int l = 0; l < SVTGeometry.NLAYERS; l++) { - // reinitilize swimmer from last surface - if(inters!=null) { - double intersPhi = Math.atan2(inters[4], inters[3]); - double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), - P, Q, maxPathLength) ; - } - int layer = l + 1; - int sector = Sectors[l]; - if(sector == -1) - continue; - - Vector3D n = sgeo.getNormal(layer, sector); - Point3D p = sgeo.getModule(layer, sector).origin(); - Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.SwimPlane(n, pm, 1E-3); - if(inters!=null) { - Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); - int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); - //stripMap.put((sector*1000+layer), nearstp); - docaMap.put((sector*1000+layer), sgeo.getDoca(layer, sector, nearstp, trp)); - trajMap.put((sector*1000+layer), trp); - } - } - for(Cluster cls : seedCluster) { - if(cls.get_Detector() == DetectorType.BMT) - continue; - int clsKey = cls.get_Sector()*1000+cls.get_Layer(); - clusMap.put(clsKey, cls); - } - for(Cluster cls : allClusters) { - if(cls.get_Detector() == DetectorType.BMT) - continue; - int clsKey = cls.get_Sector()*1000+cls.get_Layer(); - if(cls.get_AssociatedTrackID()==-1 && trajMap!=null && trajMap.get(clsKey)!=null) { - //double trjCent = stripMap.get(clsKey); - double clsDoca = cls.residual(trajMap.get(clsKey)); - if(clusMap.containsKey(clsKey)) { - //double filldCent = clusMap.get(clsKey).get_Centroid(); - double filldDoca = docaMap.get(clsKey); - if(Math.abs(clsDoca) clustersOnTrack = new ArrayList(); - for(Cluster cl : clusMap.values()) { - clustersOnTrack.add(cl); - } - // RDV can lead to duplicates - for(Cluster cls : seedCluster) { - if(cls.get_Detector() == DetectorType.BMT) - clustersOnTrack.add(cls); - } - return clustersOnTrack; - } +// public List FindClustersOnTrk (List allClusters, List seedCluster, Helix helix, double P, int Q, +// SVTGeometry sgeo, Swim swimmer) { +// Map clusMap = new HashMap(); +// //Map stripMap = new HashMap(); +// Map docaMap = new HashMap(); +// Map trajMap = new HashMap(); +// int[] Sectors = new int[SVTGeometry.NLAYERS]; +// // RDV it is not correct for tilte/shifted geometry +// for (int a = 0; a < Sectors.length; a++) { +// Point3D I = helix.getPointAtRadius(sgeo.getLayerRadius(a+1)); +// int sec = sgeo.getSector(a+1, I); +// Sectors[a] = sec; +// } +// // initialize swimmer starting from the track vertex +// double maxPathLength = 1; +// swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, +// Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), +// P, Q, maxPathLength) ; +// double[] inters = null; +// double path = 0; +// // SVT +// for (int l = 0; l < SVTGeometry.NLAYERS; l++) { +// // reinitilize swimmer from last surface +// if(inters!=null) { +// double intersPhi = Math.atan2(inters[4], inters[3]); +// double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); +// swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), +// P, Q, maxPathLength) ; +// } +// int layer = l + 1; +// int sector = Sectors[l]; +// if(sector == -1) +// continue; +// +// Vector3D n = sgeo.getNormal(layer, sector); +// Point3D p = sgeo.getModule(layer, sector).origin(); +// Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); +// inters = swimmer.SwimPlane(n, pm, 1E-3); +// if(inters!=null) { +// Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); +// int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); +// //stripMap.put((sector*1000+layer), nearstp); +// docaMap.put((sector*1000+layer), sgeo.getDoca(layer, sector, nearstp, trp)); +// trajMap.put((sector*1000+layer), trp); +// } +// } +// for(Cluster cls : seedCluster) { +// if(cls.get_Detector() == DetectorType.BMT) +// continue; +// int clsKey = cls.get_Sector()*1000+cls.get_Layer(); +// clusMap.put(clsKey, cls); +// } +// for(Cluster cls : allClusters) { +// if(cls.get_Detector() == DetectorType.BMT) +// continue; +// int clsKey = cls.get_Sector()*1000+cls.get_Layer(); +// if(cls.get_AssociatedTrackID()==-1 && trajMap!=null && trajMap.get(clsKey)!=null) { +// //double trjCent = stripMap.get(clsKey); +// double clsDoca = cls.residual(trajMap.get(clsKey)); +// if(clusMap.containsKey(clsKey)) { +// //double filldCent = clusMap.get(clsKey).get_Centroid(); +// double filldDoca = docaMap.get(clsKey); +// if(Math.abs(clsDoca) clustersOnTrack = new ArrayList(); +// for(Cluster cl : clusMap.values()) { +// clustersOnTrack.add(cl); +// } +// // RDV can lead to duplicates +// for(Cluster cls : seedCluster) { +// if(cls.get_Detector() == DetectorType.BMT) +// clustersOnTrack.add(cls); +// } +// return clustersOnTrack; +// } public void MatchTrack2Traj(Seed trkcand, Map traj, @@ -535,7 +536,6 @@ public Track OutputTrack(StraightTrack seed, org.jlab.clas.tracking.kalmanfilter public Track OutputTrack(Seed seed) { Track cand = new Track(seed.get_Helix()); - for (Cross c : seed.get_Crosses()) { if (c.get_Detector()==DetectorType.BST) { continue; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index e914e72b0..245e6f0d7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -1,7 +1,5 @@ package org.jlab.rec.cvt.services; -import Jama.Matrix; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.List; import org.jlab.clas.swimtools.Swim; @@ -48,7 +46,6 @@ public boolean processEvent(DataEvent event, Swim swimmer, boolean isSVTonly, boolean exLayrs) { - // get field value and scale double solenoidScale = Constants.getSolenoidScale(); double solenoidValue = Constants.getSolenoidMagnitude(); // already the absolute value @@ -106,7 +103,7 @@ public boolean processEvent(DataEvent event, Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - Matrix cov = seed.get_Helix().get_covmatrix(); + double[][] cov = seed.get_Helix().get_covmatrix(); if(solenoidValue>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue clsOnTrack = recUtil.FindClustersOnTrkNew(SVTclusters, seed.get_Clusters(), fittedTrack.get_helix(), + List clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, seed.get_Clusters(), fittedTrack.get_helix(), fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); if(clsOnTrack.size()>0) { seed.get_Clusters().addAll(clsOnTrack); - } + - //reset pars - v = fittedTrack.get_helix().getVertex(); - p = fittedTrack.get_helix().getPXYZ(solenoidValue); - charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); - if(solenoidValue<0.001) - charge = 1; - v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); - hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, - solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); + //reset pars + v = fittedTrack.get_helix().getVertex(); + p = fittedTrack.get_helix().getPXYZ(solenoidValue); + charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); + if(solenoidValue<0.001) + charge = 1; + v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); + hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, + solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - kf = new KFitter( hlx, cov, event, swimmer, - Constants.getXb(), - Constants.getYb(), - shift, - recUtil.setMeasVecs(seed, swimmer)) ; - //Uncomment to let track be fitted - //kf.filterOn = false; - kf.runFitter(swimmer); - - Track trk = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); + kf = new KFitter( hlx, cov, event, swimmer, + Constants.getXb(), + Constants.getYb(), + shift, + recUtil.setMeasVecs(seed, swimmer)) ; + kf.matLib = Constants.kfMatLib; + //Uncomment to let track be fitted + //kf.filterOn = false; + kf.runFitter(swimmer); + + if(kf.KFHelix!=null) { + fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); + } + } - trkcands.add(trk); + trkcands.add(fittedTrack); trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); - } - //} else { - //trkcands.add(recUtil.OutputTrack(seed)); - //trkcands.get(trkcands.size() - 1).set_TrackingStatus(1); - //} + } else { + //trkcands.add(recUtil.OutputTrack(seed)); + //trkcands.get(trkcands.size() - 1).set_TrackingStatus(1); + } } @@ -171,18 +172,19 @@ public boolean processEvent(DataEvent event, rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, shift); return true; } - + //This last part does ELoss C TrackListFinder trkFinder = new TrackListFinder(); + trkFinder.removeOverlappingTracks(trkcands); List tracks = trkFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); for( int i=0;i 0) { - recUtil.CleanupSpuriousCrosses(crosses, tracks, SVTGeom) ; + recUtil.CleanupSpuriousCrosses(crosses, tracks, SVTGeom) ; rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, tracks, shift); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 237ee3418..f32421ccf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -77,7 +77,7 @@ public List getTracks(List cands, trk.set_Trajectory(traj.get_Trajectory()); //if(trk.passCand == true) - tracks.add(trk); + tracks.add(trk); } } @@ -116,7 +116,6 @@ private void assignTrkPID(Track trk) { public void removeOverlappingTracks(List trkcands) { if(trkcands==null) return; - List selectedTracks =new ArrayList(); List list = new ArrayList(); List rejected = new ArrayList(); @@ -143,7 +142,7 @@ public void removeOverlappingTracks(List trkcands) { } } - if( rejected != null ) + if( rejected != null && selectedTracks!=null) selectedTracks.removeAll(rejected); if(trkcands!=null) trkcands.removeAll(trkcands); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index 78ef7e0b0..f5df51e9c 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -3,7 +3,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import Jama.Matrix; +//import Jama.Matrix; import org.jlab.rec.cvt.Constants; /** @@ -26,7 +26,7 @@ public class Helix { private double _curvature; // track curvature = 1/R, where R is the radius of the circle private double _Z0; // intersect of the helix axis with the z-axis private double _tandip; // tangent of the dip angle - private Matrix _covmatrix = new Matrix(5, 5); + private double[][] _covmatrix = new double[5][5]; //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | // | d_phi_at_dca*d_dca d_phi_at_dca*d_phi_at_dca d_phi_at_dca*d_curvature 0 0 | @@ -35,7 +35,7 @@ public class Helix { // | 0 0 0 0 d_tandip*d_tandip | // - public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, Matrix covmatrix) { + public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double[][] covmatrix) { set_dca(dca); set_phi_at_dca(phi_at_doca); set_curvature(curvature); @@ -94,11 +94,11 @@ public void set_tandip(double tandip) { this._tandip = tandip; } - public Matrix get_covmatrix() { + public double[][] get_covmatrix() { return _covmatrix; } - - public void set_covmatrix(Matrix covmatrix) { + + public void set_covmatrix(double[][] covmatrix) { this._covmatrix = covmatrix; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java index 41fb4d8c0..0c432e7d5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java @@ -1,6 +1,6 @@ package org.jlab.rec.cvt.trajectory; -import Jama.*; + import org.jlab.rec.cvt.Constants; /** @@ -11,7 +11,7 @@ * @author ziegler * */ -public class StateVec extends Matrix implements Comparable { +public class StateVec implements Comparable { /** @@ -29,7 +29,13 @@ public class StateVec extends Matrix implements Comparable { private double _TrkToModuleAngle; private double _CalcCentroidStrip; private double _Path; - + private double _x; + private double _y; + private double _z; + private double _ux; + private double _uy; + private double _uz; + public int get_ID() { return _ID; } @@ -123,7 +129,7 @@ public static long getSerialversionuid() { * Instantiates a new vec. */ public StateVec() { - super(6, 1); + set(0,0,0,0,0,0); } /** @@ -132,12 +138,7 @@ public StateVec() { * @param V the v */ public void set(StateVec V) { - set(0, 0, V.x()); - set(1, 0, V.y()); - set(2, 0, V.z()); - set(3, 0, V.ux()); - set(4, 0, V.uy()); - set(5, 0, V.uz()); + set(V.x(), V.y(), V.z(), V.ux(), V.uy(), V.uz()); } private int _planeIdx; @@ -172,12 +173,12 @@ public void set_planeIdx(int _planeIdx) { * @param uz the z-component of the tangent to the helix at point (x,y,z) */ public void set(double x, double y, double z, double ux, double uy, double uz) { - set(0, 0, x); - set(1, 0, y); - set(2, 0, z); - set(3, 0, ux); - set(4, 0, uy); - set(5, 0, uz); + _x=x; + _y=y; + _z=z; + _ux=ux; + _uy=uy; + _uz=uz; } /** @@ -191,13 +192,7 @@ public void set(double x, double y, double z, double ux, double uy, double uz) { * @param uz the z-component of the tangent to the helix at point (x,y,z) */ public StateVec(double x, double y, double z, double ux, double uy, double uz) { - super(6, 1); - set(0, 0, x); - set(1, 0, y); - set(2, 0, z); - set(3, 0, ux); - set(4, 0, uy); - set(5, 0, uz); + set(x, y, z, ux, uy, uz); } /** @@ -206,29 +201,10 @@ public StateVec(double x, double y, double z, double ux, double uy, double uz) { * @param v the v */ public StateVec(StateVec v) { - super(6, 1); - set(0, 0, v.x()); - set(1, 0, v.y()); - set(2, 0, v.z()); - set(3, 0, v.ux()); - set(4, 0, v.uy()); - set(5, 0, v.uz()); + set(v._x, v._y, v._z, v._ux, v._uy, v._uz); } - /** - * Instantiates a new StateVec. - * - * @param m the m - */ - private StateVec(Matrix m) { //needed since Jama.Matrix cannot be casted into StateVec - super(4, 1); - set(0, 0, m.get(0, 0)); - set(1, 0, m.get(1, 0)); - set(2, 0, m.get(2, 0)); - set(3, 0, m.get(3, 0)); - set(4, 0, m.get(4, 0)); - set(5, 0, m.get(5, 0)); - } + /** * Description of x(). @@ -236,7 +212,7 @@ private StateVec(Matrix m) { //needed since Jama.Matrix cannot be casted into St * @return the x component */ public double x() { - return (get(0, 0)); + return _x; } /** @@ -245,7 +221,7 @@ public double x() { * @return the y component */ public double y() { - return (get(1, 0)); + return _y; } /** @@ -254,7 +230,7 @@ public double y() { * @return the z component */ public double z() { - return (get(2, 0)); + return _z; } /** @@ -263,7 +239,7 @@ public double z() { * @return the ux component */ public double ux() { - return (get(3, 0)); + return _ux; } /** @@ -272,7 +248,7 @@ public double ux() { * @return the uy component */ public double uy() { - return (get(4, 0)); + return _uy; } /** @@ -281,7 +257,7 @@ public double uy() { * @return the uz component */ public double uz() { - return (get(5, 0)); + return _uz; } @Override From eb1f0ef0dec10deb64c44c4a0a6dbdb23df5cfb2 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 28 Oct 2021 18:42:54 +0200 Subject: [PATCH 199/291] CVT: Cellular Automaton updated to account for new geometry; switched CTOF, CND trajectories to use AdaptiveSwimCylinder --- .../java/org/jlab/rec/cvt/cluster/Cluster.java | 2 +- .../main/java/org/jlab/rec/cvt/cross/Cross.java | 13 +++---------- .../jlab/rec/cvt/cross/HelixCrossListFinder.java | 5 ++--- .../rec/cvt/services/TracksFromTargetRec.java | 4 ++-- .../main/java/org/jlab/rec/cvt/track/Cell.java | 13 ++----------- .../java/org/jlab/rec/cvt/track/MakerCA.java | 16 ++-------------- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 4 ++-- .../rec/cvt/trajectory/TrajectoryFinder.java | 14 ++++++++++---- 8 files changed, 24 insertions(+), 47 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index b9eea57b6..f29e6a508 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -277,7 +277,7 @@ else if (this.get_Detector()==DetectorType.BMT) { stEP1 = thehit.get_Strip().get_Line().origin(); stEP2 = thehit.get_Strip().get_Line().end(); // RDV: should remove stuff that is not used or necessary from cluster strips and so on - // for C detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid + // for Z detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid stCent = new Point3D(Math.cos(thehit.get_Strip().get_Phi()),Math.sin(thehit.get_Strip().get_Phi()),0); stCent0 = new Point3D(Math.cos(thehit.get_Strip().get_Phi0()),Math.sin(thehit.get_Strip().get_Phi0()),0); weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index e16dcd11a..70e30ce8e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -673,17 +673,10 @@ public void set_AssociatedTrackID(int associatedTrackID) { } /** - * @return the cCrossRadius + * @return the Cross Radius */ - public double getcCrossRadius() { - return cCrossRadius; - } - - /** - * @param cCrossRadius the cCrossRadius to set - */ - public void setcCrossRadius(double cCrossRadius) { - this.cCrossRadius = cCrossRadius; + public double getRadius() { + return Math.sqrt(this.get_Point().x()*this.get_Point().x()+this.get_Point().y()*this.get_Point().y()); } public static void main(String arg[]) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index 8c3c94713..a8535411b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -6,7 +6,6 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; -import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; @@ -246,8 +245,8 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { } double dzdrsum = avg_tandip*countCrosses; double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = BMTConstants.getCRCRADIUS()[bmt_Ccross.get_Region() - 1]; - System.out.println(bmt_Ccross.get_Point().toString() + " " + bmt_Ccross.getcCrossRadius()); + double r_bmt = bmt_Ccross.getRadius(); + System.out.println(bmt_Ccross.get_Point().toString() + " " + bmt_Ccross.getRadius()); double dzdr_bmt = z_bmt / r_bmt; if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= SVTParameters.dzdrcut) // add this to the track pass = true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 89395d442..fe13b141b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -70,8 +70,8 @@ public boolean processEvent(DataEvent event, } else { TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); - //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA + //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA TrackSeeder trseed2 = new TrackSeeder(); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); @@ -89,7 +89,7 @@ public boolean processEvent(DataEvent event, KFitter kf = null; List trkcands = new ArrayList(); - for (Seed seed : seeds) { + for (Seed seed : seeds) { Point3D v = seed.get_Helix().getVertex(); Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); int charge = (int) (Math.signum(solenoidScale)*seed.get_Helix().get_charge()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java index 6ed8613a3..66b060d11 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java @@ -6,8 +6,7 @@ import javax.vecmath.Point2d; import javax.vecmath.Vector2d; -import org.jlab.detector.base.DetectorType; -import org.jlab.rec.cvt.bmt.BMTConstants; +import org.jlab.rec.cvt.Constants; /** * Base cell for the cellular automaton @@ -79,15 +78,7 @@ public Point2d get_Crs2D( int i, String vw ){ point.set( cross.get_Point().x(), cross.get_Point().y() ); } if( vw.equalsIgnoreCase("ZR")){ - double R = 0.; - if( cross.get_Detector()==DetectorType.BST){ - R = Math.sqrt(cross.get_Point().x()*cross.get_Point().x() + - cross.get_Point().y()*cross.get_Point().y() ); - } - else { - R = BMTConstants.getCRCRADIUS()[cross.get_Region()-1]; - } - point.set( cross.get_Point().z(), R ); + point.set( cross.get_Point().z()-Constants.getZoffset(), cross.getRadius() ); } return point; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 277eb3e26..e3bb10063 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -3,10 +3,8 @@ import javax.vecmath.Vector2d; import org.jlab.detector.base.DetectorType; -import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; /** @@ -40,17 +38,7 @@ public MakerCA(){ this._debug = false; } - - private double getCrossRadius( Cross c ) { // TODO: can this be moved inside the Cross class? - if( c.get_Detector()==DetectorType.BST) - return Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); - - if( c.get_Type()==BMTType.Z ) - return BMTConstants.getCRZRADIUS()[c.get_Region()-1 ]; - return BMTConstants.getCRCRADIUS()[c.get_Region()-1 ]; - } - private boolean checkAngles( Cell cell ) { double xa = cell.get_Crs2D(1, this._plane).x; double ya = cell.get_Crs2D(1, this._plane).y; @@ -64,8 +52,8 @@ private boolean checkAngles( Cell cell ) { // Angle( DR ) = 0.175 * DR + 0.551 // where DR is the difference in radius of the crosses // The angles are in degrees - double R1 = this.getCrossRadius( cell.get_c1() ); - double R2 = this.getCrossRadius( cell.get_c2() ); + double R1 = cell.get_c1().getRadius(); + double R2 = cell.get_c2().getRadius(); double angle = 1.75 * (R2 - R1) + 0.551; // in cm; TODO: create setters and getters for the parameters // if( Math.toDegrees(va.angle(vb)) > this._abCrs ) return false; if( Math.toDegrees(va.angle(vb)) > angle ) return false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 882a31720..dfd9f40b9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -169,8 +169,7 @@ private ArrayList getCrossFromCells( List l ){ // create and run the cellular automaton public List runCAMaker( String plane, int nepochs, ArrayList crs, - org.jlab.rec.cvt.bmt.BMTGeometry bgeom, - Swim swimmer){ + BMTGeometry bgeom, Swim swimmer){ MakerCA camaker = new MakerCA(false); camaker.set_plane( plane ); if( plane.equalsIgnoreCase("XY") ){ @@ -189,6 +188,7 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs, camaker.evolve( nepochs ); return camaker.getNodes(); } + TrackListFinder trkFinder = new TrackListFinder(); public List findSeed(List svt_crosses, List bmt_crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 8d2ac03af..8c6ff11e1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -250,7 +250,8 @@ public Trajectory findTrajectory(Track trk, swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; // swim to CTOF double radius = ctof_geo.getRadius(1); - inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); +// inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); + inters = swimmer.AdaptiveSwimCylinder(0, 0, 0, 0, 0, 1, radius, Constants.SWIMACCURACYCD/10); // update parameters if(inters!=null) { intersPhi = Math.atan2(inters[4], inters[3]); @@ -281,7 +282,8 @@ public Trajectory findTrajectory(Track trk, // swim to CTOF Point3D center = cnd_geo.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); double radius = Math.sqrt(center.x()*center.x()+center.y()*center.y()); - inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); +// inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); + inters = swimmer.AdaptiveSwimCylinder(0, 0, 0, 0, 0, 1, radius, Constants.SWIMACCURACYCD/10); if(inters==null) break; // give up on this track if swimming failed // update parameters intersPhi = Math.atan2(inters[4], inters[3]); @@ -590,9 +592,13 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec /** * * @param detector - * @param superlayer 0,1 (bottom, top) - * @param Cluster + * @param sector + * @param layer + * @param cluster * @param stVec stateVec + * @param svt_geo + * @param bmt_geo + * @param trajFinal */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, StateVec stVec, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal) { From c4e8a36798e4d7510d8daef9a6ee82404e0ac6c6 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Sat, 30 Oct 2021 16:32:13 -0400 Subject: [PATCH 200/291] convert ray parameters to helix parameters for cosmics (for comparison with field-off tracks) --- .../org/jlab/rec/cvt/services/CVTAlignment.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 7e7ecdba8..128db9381 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -265,6 +265,9 @@ public boolean processDataEvent(DataEvent event) { Matrix c = new Matrix(rows,1); Matrix I = new Matrix(rows,1); Matrix q = new Matrix(4, 1); //track parameters, for plotting kinematic dependence. Not used in KFA. + if (track.get_helix() == null) { + track.set_helix(createHelixFromRay(track.get_ray())); + } q.set(0, 0, track.get_helix().get_dca()); q.set(1, 0, track.get_helix().get_phi_at_dca()); @@ -392,6 +395,20 @@ else if(cross.get_DetectorType() == BMTType.C) { return true; } + private Helix createHelixFromRay(Ray ray) { + Vector3D u = ray.get_dirVec(); + Vector3D xref = ray.get_refPoint().toVector3D(); + double phi = Math.atan2(u.y(),u.x()); + Vector3D uT = new Vector3D(Math.cos(phi), Math.sin(phi),0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x(), u.y()); + double d = mscphi.dot(xref); + double curvature = 0; + double Z0 = xref.z()-u.z()*xref.dot(uT)/u.dot(uT); + double tandip = u.z()/Math.hypot(u.x(), u.y()); + return new Helix(d, phi, curvature, Z0, tandip, null); + } + int nAlignables; private Ray getRay(Helix h,double xb, double yb) { From 069320453d47f78d1b24e63cdec8a028b6a51409 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 31 Oct 2021 22:22:30 +0100 Subject: [PATCH 201/291] CVT: - switched back to old adaptive swimming due to problems with new adaptive swimPlane leading to KF failures and loss of tracks, - tuned swimming accuracy to different surfaces, - changed swimPlane, swimRho aand swinGenCylinder to return null array if swimming fails; - rewrote and tested overlap remover --- .../kalmanfilter/helical/StateVecs.java | 5 +- .../java/org/jlab/clas/swimtools/Swim.java | 103 +++++++++++------- .../main/java/org/jlab/rec/cvt/Constants.java | 2 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 27 +---- .../jlab/rec/cvt/services/RecUtilities.java | 18 +-- .../rec/cvt/services/TracksFromTargetRec.java | 60 +++++----- .../java/org/jlab/rec/cvt/track/Track.java | 45 +++++++- .../jlab/rec/cvt/track/TrackListFinder.java | 44 +++++++- .../rec/cvt/trajectory/TrajectoryFinder.java | 50 +++++---- 9 files changed, 217 insertions(+), 137 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index ddef998ac..552198f22 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -171,7 +171,8 @@ else if(mv.surface.cylinder!=null) { mv.surface.plane.point().y()/units, mv.surface.plane.point().z()/units); double accuracy = mv.surface.swimAccuracy/units; - swimPars = swim.AdaptiveSwimPlane(point.x(), point.y(), point.z(), norm.x(), norm.y(), norm.z(), accuracy); + swimPars = swim.SwimPlane(norm,point,accuracy); + // swimPars = swim.AdaptiveSwimPlane(point.x(), point.y(), point.z(), norm.x(), norm.y(), norm.z(), accuracy); if(swimPars==null) return null; for(int j =0; j < 3; j++) { @@ -215,7 +216,7 @@ else if(mv.surface.cylinder!=null) { mv.surface.cylinder.getAxis().end().y()/units, mv.surface.cylinder.getAxis().end().z()/units) ; double accuracy = mv.surface.swimAccuracy/units; - swimPars = swim.AdaptiveSwimCylinder(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z(), r/units, accuracy); + swimPars = swim.SwimGenCylinder(p1, p2, r/units, accuracy); if(swimPars==null) return null; for(int j =0; j < 3; j++) { 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 ee7c4541d..58f63282e 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 @@ -479,12 +479,22 @@ public double[] SwimToCylinder(double Rad) { /** * - * @param radius + * @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 + * @param accuracy in cm + * @return state x,y,z,px,py,pz, pathlength, iBdl at the surface + */ + public double[] SwimRho(double radius, double accuracy) { - double[] value = new double[8]; + double[] value = null; // using adaptive stepsize if(this.SwimUnPhys) @@ -494,17 +504,19 @@ public double[] SwimRho(double radius) { AdaptiveSwimResult result = new AdaptiveSwimResult(false); - PC.CF.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius/100, accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - - 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 - + 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) { e.printStackTrace(); @@ -521,8 +533,20 @@ public double[] SwimRho(double radius) { * @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 + * @param axisPoint2 in cm + * @param radius in cm + * @param accuracy in cm + * @return swam trajectory to the cylinder + */ + public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double radius, double accuracy) { - double[] value = new double[8]; + double[] value = null; double[] p1 = new double[3]; double[] p2 = new double[3]; p1[0] = axisPoint1.x()/100; @@ -542,18 +566,19 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.CF.swimCylinder(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, - p1, p2, radius/100, accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - - - 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 + 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 + } } catch (RungeKuttaException e) { e.printStackTrace(); @@ -564,7 +589,7 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { - double[] value = new double[8]; + double[] value = null; // using adaptive stepsize @@ -580,15 +605,17 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { accuracy/100, _rMax, stepSize, cnuphys.swim.Swimmer.CLAS_Tolerance, result); - 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 - + 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) { e.printStackTrace(); @@ -916,6 +943,7 @@ 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"); double[] value = new double[8]; @@ -959,7 +987,7 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do 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"); double[] value = new double[8]; radius = radius/100; @@ -1003,6 +1031,7 @@ public double[] AdaptiveSwimCylinder(double a1x, double a1y, double a1z, double } public double[] AdaptiveSwimRho(double radius, double accuracy) { + System.out.println("Don't use yet"); double[] value = new double[8]; @@ -1016,7 +1045,7 @@ public double[] AdaptiveSwimRho(double radius, double accuracy) { AdaptiveSwimResult result = new AdaptiveSwimResult(false); PC.AS.swimRho(_charge, _x0, _y0, _z0, _pTot, _theta, _phi, radius, - accuracy, _rMax, stepSize, cnuphys.swim.Swimmer.getEps(), result); + 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 diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 64562519e..b27d83511 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -29,7 +29,7 @@ public class Constants { public static final double DEFAULTSWIMACC = 0.020; // in mm public static final double SWIMACCURACYSVT = 0.010; // in mm - public static final double SWIMACCURACYBMT = 0.050; // in mm + public static final double SWIMACCURACYBMT = 0.020; // in mm public static final double SWIMACCURACYCD = 0.500; // in mm private static boolean isCosmicsData = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 70e30ce8e..ac84f271c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -597,32 +597,7 @@ public int get_SVTCosmicsRegion() { else theRegion = SVTGeometry.NREGIONS*2+1-this.get_Region(); } - // RDV check with Veronique -// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(3) < 15) { -// if (this.get_Point0().y() > 0) { -// theRegion = 6; -// } else { -// theRegion = 1; -// } -// } -// -// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(2) < 15) { -// if (this.get_Point0().y() > 0) { -// theRegion = 5; -// } else { -// theRegion = 2; -// } -// } -// -// if (this.get_Point0().toVector3D().rho() - SVTGeometry.getRegionRadius(1) < 15) { -// if (this.get_Point0().y() > 0) { -// theRegion = 4; -// } else { -// theRegion = 3; -// } -// } -// } -// + return theRegion; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 607386d3c..99c6ee086 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -31,7 +31,6 @@ import java.util.Comparator; import java.util.Map.Entry; import org.jlab.detector.base.DetectorType; -import org.jlab.geom.prim.Arc3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; @@ -53,13 +52,6 @@ public void CleanupSpuriousCrosses(List> crosses, List t List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { -// double z = SVTGeom.toLocal(c.get_Region()*2, -// c.get_Sector(), -// c.get_Point()).z(); -// -// if(z<-0.1 || z>SVTGeometry.getModuleLength()) { -// rmCrosses.add(c); -// } if(!SVTGeom.isInFiducial(c.get_Cluster1().get_Layer(), c.get_Sector(), c.get_Point())) rmCrosses.add(c); } @@ -84,6 +76,7 @@ public void CleanupSpuriousCrosses(List> crosses, List t if(rmFlag==true) rmTrks.add(t); } + // RDV why removing the whole track? trks.removeAll(rmTrks); } } @@ -135,7 +128,6 @@ public List setMeasVecs(Seed trkcand, Swim swim) { - // RDV: switch to cluster.mesurement() public List setMeasVecs(StraightTrack trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { //Collections.sort(trkcand.get_Crosses()); @@ -259,9 +251,9 @@ public List FindClustersOnTrkNew (List allClusters, List FindClustersOnTrk (List allClusters, List Vector3D n = sgeo.getNormal(layer, sector); Point3D p = sgeo.getModule(layer, sector).origin(); Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), 2*Constants.SWIMACCURACYSVT/10); + inters = swimmer.SwimPlane(n, p, Constants.DEFAULTSWIMACC/10); if(inters!=null) { Point3D trp = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); int nearstp = sgeo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index fe13b141b..2c1bae9e4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -74,7 +74,7 @@ public boolean processEvent(DataEvent event, //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA TrackSeeder trseed2 = new TrackSeeder(); trseed2.unUsedHitsOnly = true; - seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); // RDV check for overlaps if(exLayrs==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); } @@ -132,36 +132,33 @@ public boolean processEvent(DataEvent event, fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); if(clsOnTrack.size()>0) { seed.get_Clusters().addAll(clsOnTrack); - } - - //reset pars - v = fittedTrack.get_helix().getVertex(); - p = fittedTrack.get_helix().getPXYZ(solenoidValue); - charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); - if(solenoidValue<0.001) - charge = 1; - v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); - hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, - solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - - kf = new KFitter( hlx, cov, event, swimmer, - Constants.getXb(), - Constants.getYb(), - shift, - recUtil.setMeasVecs(seed, swimmer)) ; - //Uncomment to let track be fitted - //kf.filterOn = false; - kf.runFitter(swimmer); - - Track trk = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); - trkcands.add(trk); - trkcands.get(trkcands.size() - 1).set_TrackingStatus(seed.trkStatus); + //reset pars + v = fittedTrack.get_helix().getVertex(); + p = fittedTrack.get_helix().getPXYZ(solenoidValue); + charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); + if(solenoidValue<0.001) + charge = 1; + v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); + hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, + solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); + + kf = new KFitter( hlx, cov, event, swimmer, + Constants.getXb(), + Constants.getYb(), + shift, + recUtil.setMeasVecs(seed, swimmer)) ; + //Uncomment to let track be fitted + //kf.filterOn = false; + kf.runFitter(swimmer); + + // RDV get rid of added clusters if not true + if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) + fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); + } + fittedTrack.set_TrackingStatus(seed.trkStatus); + trkcands.add(fittedTrack); } - //} else { - //trkcands.add(recUtil.OutputTrack(seed)); - //trkcands.get(trkcands.size() - 1).set_TrackingStatus(1); - //} } @@ -173,6 +170,9 @@ public boolean processEvent(DataEvent event, //This last part does ELoss C TrackListFinder trkFinder = new TrackListFinder(); + trkFinder.removeOverlappingTracks(trkcands); //turn off until debugged + TrackListFinder.checkForOverlaps(trkcands, "KF"); + List tracks = trkFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); for( int i=0;i= this.size() ) ? 1 : -1; return (tr.get_P() > this.get_P()) ? 1 : -1; } + + /** + * Compare this track quality with the given track + * based on NDF and Chi2 + * @param o the other track + * @return true if this track quality is better than the given track + */ + public boolean betterThan(Track o) { + if(this.getNDF()>o.getNDF()) + return true; + else if(this.getNDF()>0 && this.getNDF()==o.getNDF()) { + if(this.getChi2()/this.getNDF() < o.getChi2()/o.getNDF()) + return true; + else return false; + } + else + return false; + } + + /** + * Check track overlaps with the given track + * an overlaps is detected if the tracks share at least two crosses + * @param o the other track + * @return true if this track overlaps with the given track, false otherwise + */ + public boolean overlapWith(Track o) { + int nc = 0; + for(Cross c : this) { + if(c.get_Type()==BMTType.C) continue; //skim BMTC + if(o.contains(c)) nc++; + } + if(nc >1) return true; + else return false; + } public Point3D get_TrackPointAtCTOFRadius() { return _TrackPointAtCTOFRadius; @@ -321,5 +354,13 @@ public double getChi2() { public void setChi2(double _Chi2) { this._Chi2 = _Chi2; } + + public String toString() { + String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, phi=%.3f deg, NDF=%d, chi2=%.3f\n", + this.get_Id(), this.get_Q(), this.get_P(), this.get_Pt(), Math.toDegrees(this.get_helix().get_phi_at_dca()), + this.getNDF(), this.getChi2()); + for(Cross c: this) str = str + c.toString() + "\n"; + return str; + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index b39accb96..d6441bb5a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -63,11 +63,10 @@ public List getTracks(List cands, trk.get_P(), charge, maxPathLength) ; - double[] pointAtCylRad = cvtSwim.AdaptiveSwimRho(Constants.CTOFINNERRADIUS/10, Constants.SWIMACCURACYCD); + double[] pointAtCylRad = cvtSwim.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), Constants.CTOFINNERRADIUS/10, Constants.SWIMACCURACYCD/10); if(pointAtCylRad!=null) { trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); - trk.set_pathLength(pointAtCylRad[6]*10); TrajectoryFinder trjFind = new TrajectoryFinder(); @@ -113,7 +112,44 @@ private void assignTrkPID(Track trk) { } - public void removeOverlappingTracks(List trkcands) { + public void removeOverlappingTracks(List tracks) { + if(tracks==null) + return; + + List selectedTracks = new ArrayList<>(); + for (int i = 0; i < tracks.size(); i++) { + boolean overlap = false; + Track t1 = tracks.get(i); + for(int j=0; j tracks, String msg) { + for (int i = 0; i < tracks.size(); i++) { + Track t1 = tracks.get(i); + for(int j=0; j trkcands) { if(trkcands==null) return; @@ -151,6 +187,7 @@ public void removeOverlappingTracks(List trkcands) { trkcands.addAll(selectedTracks); } + @Deprecated private boolean ListContainsTrack(List selectedTracks, Track selectedTrk) { // not used. Now Track extends Comparables boolean isInList = false; @@ -162,6 +199,7 @@ private boolean ListContainsTrack(List selectedTracks, Track selectedTrk) } + @Deprecated private void getOverlapLists(Track track, List trkcands, List list) { // -------------------------------------------------------------------- // two tracks are considered the same if they share at least 2 crosses diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 8c6ff11e1..91ac30c9d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -138,13 +138,11 @@ public Trajectory findTrajectory(Track trk, if(sector == -1) continue; - Vector3D n = svt_geo.getNormal(layer, sector); - Point3D p = svt_geo.getModule(layer, sector).origin(); - Point3D pcm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - double accuracy = Constants.DEFAULTSWIMACC/10; - inters = swimmer.AdaptiveSwimPlane(pcm.x(), pcm.y(), pcm.z(), n.x(), n.y(), n.z(), accuracy); - if(inters==null) break; // give up on this track if swimming failed - + Vector3D n = svt_geo.getNormal(layer, sector); + Point3D p = svt_geo.getModule(layer, sector).origin(); + Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); + inters = swimmer.SwimPlane(n, pm, Constants.SWIMACCURACYSVT/10); + if(inters==null) break; path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); @@ -201,18 +199,22 @@ public Trajectory findTrajectory(Track trk, // RDV: tried using this to determine the sector but t is giving bogus number //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); double radius = bmt_geo.getRadiusMidDrift(layer)/10; - double accuracy = Constants.SWIMACCURACYBMT/10; - inters = swimmer.AdaptiveSwimRho(radius, accuracy); - if(inters==null) break; // give up on this track if swimming failed + inters = swimmer.SwimRho(radius, Constants.SWIMACCURACYBMT/10); + if(inters==null) break; int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); Line3D axis = bmt_geo.getAxis(layer, sector); - Point3D a1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); - Point3D a2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); - inters = swimmer.AdaptiveSwimCylinder(a1.x(), a1.y(), a1.z(), a2.x(), a2.y(), a2.z(), radius, accuracy); - if(inters==null) break; // give up on this track if swimming failed - + Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); + Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); + // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), + // trk.get_P(), trk.get_Q(), + // 5.0) ; + inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius, Constants.SWIMACCURACYBMT/10); + if(inters==null) break; + double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); path = path + inters[6]; + //if(r>(radius - BMTConstants.LYRTHICKN)/10) { StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); stVec.set_planeIdx(l); // double phiPos = Math.atan2(stVec.y(),stVec.x()); @@ -240,6 +242,10 @@ public Trajectory findTrajectory(Track trk, stVec.set_CalcCentroidStrip(cent); } stateVecs.add(stVec); + //} + //else { + // inters=null; + //} } } // CTOF @@ -250,11 +256,11 @@ public Trajectory findTrajectory(Track trk, swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; // swim to CTOF double radius = ctof_geo.getRadius(1); -// inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); - inters = swimmer.AdaptiveSwimCylinder(0, 0, 0, 0, 0, 1, radius, Constants.SWIMACCURACYCD/10); - // update parameters + inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius, Constants.SWIMACCURACYCD/10); if(inters!=null) { - intersPhi = Math.atan2(inters[4], inters[3]); + // update parameters + double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); + intersPhi = Math.atan2(inters[4], inters[3]); intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); @@ -282,10 +288,10 @@ public Trajectory findTrajectory(Track trk, // swim to CTOF Point3D center = cnd_geo.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); double radius = Math.sqrt(center.x()*center.x()+center.y()*center.y()); -// inters = swimmer.AdaptiveSwimRho(radius, Constants.SWIMACCURACYCD/10); - inters = swimmer.AdaptiveSwimCylinder(0, 0, 0, 0, 0, 1, radius, Constants.SWIMACCURACYCD/10); - if(inters==null) break; // give up on this track if swimming failed + inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius, Constants.SWIMACCURACYCD/10); + if(inters==null) break; // update parameters + double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); intersPhi = Math.atan2(inters[4], inters[3]); intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); path = path + inters[6]; From 8cc26c33473c34bf66048bc6f25ccb324fe74dfd Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 1 Nov 2021 00:37:10 +0100 Subject: [PATCH 202/291] Swmming: set limit to minimum step size --- .../cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java index d1fb8ca36..283504440 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java @@ -695,7 +695,9 @@ private int driver(double yo[], if (decreaseStep) { h = h / 2; if (h < _minStepSize) { - throw (new RungeKuttaException("Step size too small in Runge Kutta driver (A)")); +// throw (new RungeKuttaException("Step size too small in Runge Kutta driver (A)")); + System.out.println("Step size too small in Runge Kutta driver (A)"); + h = _minStepSize; } } else { // accepted this step From 23cbb1e20f15c249cb2c598cb91ae4f5c8c3446b Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 1 Nov 2021 00:45:33 +0100 Subject: [PATCH 203/291] Swmming: set limit to minimum step size --- .../cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java index 283504440..ff6e480fc 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java @@ -695,9 +695,9 @@ private int driver(double yo[], if (decreaseStep) { h = h / 2; if (h < _minStepSize) { + System.out.println("Step size too small in Runge Kutta driver (A)"); + h = _minStepSize; // throw (new RungeKuttaException("Step size too small in Runge Kutta driver (A)")); - System.out.println("Step size too small in Runge Kutta driver (A)"); - h = _minStepSize; } } else { // accepted this step From ddf1b00b3be81cf0866f8b07d070bf888087b589 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 1 Nov 2021 00:48:18 +0100 Subject: [PATCH 204/291] Swmming: removed printout --- .../cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java index ff6e480fc..dc798620a 100755 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java @@ -695,8 +695,7 @@ private int driver(double yo[], if (decreaseStep) { h = h / 2; if (h < _minStepSize) { - System.out.println("Step size too small in Runge Kutta driver (A)"); - h = _minStepSize; + h = _minStepSize; // throw (new RungeKuttaException("Step size too small in Runge Kutta driver (A)")); } } From 6ce239a44f720002506da5ce650d934c062145a1 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Tue, 2 Nov 2021 13:28:09 -0400 Subject: [PATCH 205/291] extended number of elements of matrix A (alignment derivatives), since the cosmics may have up to 24 clusters) From 20ee94d09c332c5f551b046bc5387625732ba4a8 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 2 Nov 2021 22:15:13 +0100 Subject: [PATCH 206/291] CVT: added method to filter good tracks, removed printout from swim-tools methods --- .../java/org/jlab/clas/swimtools/Swim.java | 4 +- .../main/java/org/jlab/rec/cvt/Constants.java | 7 ++-- .../jlab/rec/cvt/track/TrackListFinder.java | 40 +++++++++++++++---- 3 files changed, 38 insertions(+), 13 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 58f63282e..3d6d7b0ce 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 @@ -943,7 +943,7 @@ 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"); +// System.out.println("Don't use yet"); double[] value = new double[8]; @@ -987,7 +987,7 @@ public double[] AdaptiveSwimPlane(double px, double py, double pz, double nx, do 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"); + // System.out.println("Don't use yet"); double[] value = new double[8]; radius = radius/100; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index b27d83511..0901144f9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -7,9 +7,11 @@ public class Constants { - public static double PTCUT = 0.075; - + public static double PTCUT = 0.075; // minimum pt in GeV + public static double NDFCUT = 0; // minimum number of degres of freedom + public static double CHI2CUT = 25; // minimum chi2 per degrees of freedom + /** * BMTConstants used in the reconstruction */ @@ -23,7 +25,6 @@ public class Constants { public static final double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c // selection cuts for helical tracks - public static final double MINRADCURV = 200.00; //in cm public static final double CIRCLEFIT_MAXCHI2 = 100; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index d6441bb5a..838beb482 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -68,18 +68,16 @@ public List getTracks(List cands, trk.set_TrackPointAtCTOFRadius(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); trk.set_TrackDirAtCTOFRadius(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); trk.set_pathLength(pointAtCylRad[6]*10); + } + TrajectoryFinder trjFind = new TrajectoryFinder(); - TrajectoryFinder trjFind = new TrajectoryFinder(); - - Trajectory traj = trjFind.findTrajectory(trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, cvtSwim, "final"); + Trajectory traj = trjFind.findTrajectory(trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, cvtSwim, "final"); - trk.set_Trajectory(traj.get_Trajectory()); + trk.set_Trajectory(traj.get_Trajectory()); - //if(trk.passCand == true) - tracks.add(trk); - } + //if(trk.passCand == true) + tracks.add(trk); } - } return tracks; } @@ -112,6 +110,32 @@ private void assignTrkPID(Track trk) { } + public void removeBadTracks(List trkcands) { + if (trkcands == null) { + return; + } + + int initial_size = trkcands.size(); + + for (int i = 1; i < initial_size + 1; i++) { + if (Double.isNaN(trkcands.get(initial_size - i).getChi2())) { + trkcands.remove(initial_size - i); + continue; + } + if (trkcands.get(initial_size - i).getChi2() > Constants.CHI2CUT * (trkcands.get(initial_size - i).getNDF() + 5)) { + trkcands.remove(initial_size - i); + continue; + } + if (trkcands.get(initial_size - i).getNDF() < Constants.NDFCUT) { + trkcands.remove(initial_size - i); + continue; + } + if (trkcands.get(initial_size - i).get_Pt() < Constants.PTCUT) { + trkcands.remove(initial_size - i); + } + } + } + public void removeOverlappingTracks(List tracks) { if(tracks==null) return; From 39ce372b946b6274d25cf35fe83e1f247f180501 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 4 Nov 2021 23:54:52 +0100 Subject: [PATCH 207/291] CVT: unified fit seed method and improved handling of cross update based on track direction --- .../java/org/jlab/clas/swimtools/Swim.java | 3 + .../org/jlab/rec/cnd/hit/CndHitFinder.java | 8 +- .../org/jlab/rec/cnd/hit/CvtGetHTrack.java | 22 +- .../main/java/org/jlab/rec/cvt/Constants.java | 8 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 10 +- .../rec/cvt/cross/HelixCrossListFinder.java | 170 ++++---- .../jlab/rec/cvt/services/RecUtilities.java | 8 +- .../rec/cvt/services/TracksFromTargetRec.java | 14 +- .../java/org/jlab/rec/cvt/track/Seed.java | 248 ++++++++++- .../rec/cvt/track/StraightTrackSeeder.java | 25 +- .../java/org/jlab/rec/cvt/track/Track.java | 17 + .../jlab/rec/cvt/track/TrackListFinder.java | 14 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 395 ++++++++--------- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 405 +++++++++--------- 14 files changed, 765 insertions(+), 582 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 3d6d7b0ce..f7ae2a318 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 @@ -519,6 +519,7 @@ public double[] SwimRho(double radius, double accuracy) { } } catch (RungeKuttaException e) { + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); e.printStackTrace(); } return value; @@ -581,6 +582,7 @@ public double[] SwimGenCylinder(Point3D axisPoint1, Point3D axisPoint2, double r } } catch (RungeKuttaException e) { + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); e.printStackTrace(); } return value; @@ -618,6 +620,7 @@ public double[] SwimPlane(Vector3D n, Point3D p, double accuracy) { } } catch (RungeKuttaException e) { + System.out.println(_charge + " " + _x0 + " " + _y0 + " " + _z0 + " " + _pTot + " " + _theta + " " + _phi); e.printStackTrace(); } return value; diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CndHitFinder.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CndHitFinder.java index 89febe9b6..ae00fcbfd 100644 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CndHitFinder.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CndHitFinder.java @@ -354,8 +354,12 @@ public double findLength(CndHit hit, List helices, int flag, Calibrati // if(Math.abs(xi-xj)<(3.*incx) && Math.abs(yi-yj)<(3.*incy) && Math.abs(zi-zj)<(3.*incz)) { // CUT are set to x,y,z incertainty double zjAv = zj - ((-1.*ccdb.ZOFFSET[lay-1]) + (ccdb.LENGTH[lay-1]/2.))-(ccdb.ZTARGET[0]*10); - if((flag==0 && Math.abs(xi-xj)<(5.*incx) && Math.abs(yi-yj)<(5.*incy) && zjAv>(ccdb.LENGTH[lay-1]/-2.)-10*Parameters.Zres[0] && zjAv<(ccdb.LENGTH[lay-1]/2.)+10*Parameters.Zres[0]) || - (flag==1 && Math.abs(xi-xj)<(5.*incx) && Math.abs(yi-yj)<(5.*incy) && Math.abs(zi-zj)<(5.*incz))){ // CUT are set to x,y incertainty and zj in the paddle length + if((flag==0 && Math.abs(xi-xj)<(5.*incx) && + Math.abs(yi-yj)<(5.*incy) && + zjAv>(ccdb.LENGTH[lay-1]/-2.)-10*Parameters.Zres[0] && + zjAv<(ccdb.LENGTH[lay-1]/2.)+10*Parameters.Zres[0]) || + (flag==1 && Math.abs(xi-xj)<(5.*incx) && Math.abs(yi-yj)<(5.*incy) && + Math.abs(zi-zj)<(5.*incz))){ // CUT are set to x,y incertainty and zj in the paddle length hit.set_AssociatedTrkId(helices.get(i).get_Id()); hit.set_pathlength(helices.get(i).get_TrkLengths().get(lay-1)); diff --git a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CvtGetHTrack.java b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CvtGetHTrack.java index 80ddefc25..f0449470b 100755 --- a/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CvtGetHTrack.java +++ b/reconstruction/cnd/src/main/java/org/jlab/rec/cnd/hit/CvtGetHTrack.java @@ -65,7 +65,7 @@ public void getCvtHTrack(DataEvent event, CalibrationConstantsLoader ccdb) { indexTrack = id; } - int layer = bank.getByte("layer", i); + int layer = bank.getByte("layer", i); double x = bank.getFloat("x", i); double y = bank.getFloat("y", i); double z = bank.getFloat("z", i); @@ -95,14 +95,14 @@ public void getCvtHTrack(DataEvent event, CalibrationConstantsLoader ccdb) { if((Double.isNaN(uo1)) || (Double.isNaN(ui1)) )continue; //check if the track crosses the paddle. If not then go to the next swimmer intersection Point3D entryPoint = new Point3D((x+ui1*ux)*10,(y+ui1*uy)*10,(z+ui1*uz)*10); - Point3D midPoint = new Point3D(x*10,y*10,z*10); - Point3D exitPoint = new Point3D((x+uo1*ux)*10,(y+uo1*uy)*10,(z+uo1*uz)*10); + Point3D midPoint = new Point3D(x*10,y*10,z*10); + Point3D exitPoint = new Point3D((x+uo1*ux)*10,(y+uo1*uy)*10,(z+uo1*uz)*10); - trk._TrkInters.get(layer - 1).add(entryPoint); - trk._TrkInters.get(layer - 1).add(midPoint); - trk._TrkInters.get(layer - 1).add(exitPoint); + trk._TrkInters.get(layer - 1).set(0, entryPoint); + trk._TrkInters.get(layer - 1).set(1, midPoint); + trk._TrkInters.get(layer - 1).set(2, exitPoint); - trk._TrkLengths.add(path*10); + trk._TrkLengths.set(layer-1, path*10); helices.add(trk); //System.out.println("layer from swimmer "+layer+ " x "+trk._TrkInters.get(layer-1).get(0).x()+ " "+y+" "+z); @@ -233,9 +233,11 @@ public class CVTTrack { private List _TrkLengths = new ArrayList(); //the pathlength of the track from the doca to the beam line to the middle of the CND counter public CVTTrack() { - for (int i = 0; i < 3; i++) { - _TrkInters.add(new ArrayList()); - } + for (int i = 0; i < 3; i++) { + _TrkInters.add(new ArrayList()); + for(int j=0; j<3; j++) _TrkInters.get(i).add(new Point3D(Double.NaN,Double.NaN,Double.NaN)); + _TrkLengths.add(Double.NaN); + } } public Helix get_Helix() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 9b6039141..70eeaab31 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -9,11 +9,6 @@ public class Constants { - public static double PTCUT = 0.075; // minimum pt in GeV - public static double NDFCUT = 0; // minimum number of degres of freedom - public static double CHI2CUT = 25; // minimum chi2 per degrees of freedom - - /** * BMTConstants used in the reconstruction */ @@ -27,6 +22,9 @@ public class Constants { public static final double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c // selection cuts for helical tracks + public static final double PTCUT = 0.075; // minimum pt in GeV + public static final double NDFCUT = 0; // minimum number of degres of freedom + public static final double CHI2CUT = 50; // minimum chi2 per degrees of freedom public static final double CIRCLEFIT_MAXCHI2 = 100; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index f29e6a508..7591adfbb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -345,7 +345,9 @@ else if (this.get_Detector()==DetectorType.BMT) { weightedPhi0 = Math.atan2(weightedY0, weightedX0); this.set_Centroid(weightedStrp); this.set_TotalEnergy(totEn); - + this.set_Phi(weightedPhi); + this.set_Phi0(weightedPhi0); + //setting final variables, including the ones used for alignment //----------------------------------- if (this.get_Detector()==DetectorType.BST) { //SVT @@ -385,9 +387,7 @@ else if (this.get_Detector()==DetectorType.BMT) { //BMT if (this.get_Type()==BMTType.Z) { // Z-detectors this.set_Centroid0(weightedStrp0); - this.set_Phi(weightedPhi); this.set_PhiErr(Math.sqrt(weightedPhiErrSq)); - this.set_Phi0(weightedPhi0); this.set_PhiErr0(Math.sqrt(weightedPhiErrSq0)); this.set_CentroidValue(weightedPhi); this.set_CentroidError(Math.sqrt(weightedPhiErrSq)); @@ -747,8 +747,8 @@ public void set_AssociatedTrackID(int associatedTrackID) { public int compareTo(Cluster arg) { //sort by phi of strip implant of first strip in the cluster, then by layer, then by seed strip number - double this_phi = PhiInRange(this.get(0).get_Strip().get_Line().origin().toVector3D().phi()); - double arg_phi = PhiInRange(arg.get(0).get_Strip().get_Line().origin().toVector3D().phi()); + double this_phi = this.get_Phi0(); + double arg_phi = arg.get_Phi0(); int CompPhi = this_phi < arg_phi ? -1 : this_phi == arg_phi ? 0 : 1; int CompLay = this._Layer < arg._Layer ? -1 : this._Layer == arg._Layer ? 0 : 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index a8535411b..8a3fa6734 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -11,6 +11,7 @@ import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; +import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackSeeder; @@ -55,7 +56,10 @@ public HelixCrossListFinder() { * a track in the cvt */ public List findCandidateCrossLists(List> cvt_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { + SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { + float[] bfield = new float[3]; + swimmer.BfieldLab(0, 0, 0, bfield); + double bz = Math.abs(bfield[2]); // instantiate the crosslist //List seedList = new ArrayList(); @@ -171,33 +175,33 @@ public List findCandidateCrossLists(List clusters = new ArrayList(); - for(Cross c : s ) { - if(c.get_Detector()==DetectorType.BST) { - c.get_Cluster1().set_CentroidError(this.calcCentErr(c, c.get_Cluster1(), svt_geo)); - c.get_Cluster2().set_CentroidError(this.calcCentErr(c, c.get_Cluster2(), svt_geo)); - - clusters.add(c.get_Cluster1()); - clusters.add(c.get_Cluster2()); - } - if(c.get_Detector()==DetectorType.BMT) { - clusters.add(c.get_Cluster1()); - - } - } - - trkSeed.set_Clusters(clusters); + MatchToRegion1( s, theListsByRegion.get(0), svt_geo, bmt_geo, bz); +// org.jlab.rec.cvt.track.Seed trkSeed = new org.jlab.rec.cvt.track.Seed(); +// +// trkSeed.set_Crosses(s); +// List clusters = new ArrayList(); +// for(Cross c : s ) { +// if(c.get_Detector()==DetectorType.BST) { +// c.get_Cluster1().set_CentroidError(this.calcCentErr(c, c.get_Cluster1(), svt_geo)); +// c.get_Cluster2().set_CentroidError(this.calcCentErr(c, c.get_Cluster2(), svt_geo)); +// +// clusters.add(c.get_Cluster1()); +// clusters.add(c.get_Cluster2()); +// } +// if(c.get_Detector()==DetectorType.BMT) { +// clusters.add(c.get_Cluster1()); +// +// } +// } +// +// trkSeed.set_Clusters(clusters); - trkSeed.set_Helix(trk.get_helix()); - seedList.add(trkSeed); + s.set_Helix(trk.get_helix()); + seedList.add(s); } return seedList; @@ -235,7 +239,7 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { return false; double avg_tandip =0; int countCrosses =0; - for(Cross c : trkCand) { + for(Cross c : trkCand.get_Crosses()) { if(c.get_Detector()==DetectorType.BST) { countCrosses++; avg_tandip+=c.get_Point().z()/Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); @@ -334,14 +338,14 @@ private Seed isTrack5(Cross c1, Cross c2, Cross c3, Cross c4, Cross c5) { if (Math.abs(rad245) < SVTParameters.radcut) { return null; } - double[] seed_delta_phi = {phi12, phi13, phi14, phi15}; - double[] seed_radius = {rad123, rad124, rad134, rad234, rad135, rad235, rad245}; +// double[] seed_delta_phi = {phi12, phi13, phi14, phi15}; +// double[] seed_radius = {rad123, rad124, rad134, rad234, rad135, rad235, rad245}; // create the seed - Seed seed = new Seed(seed_delta_phi, seed_radius); - seed.add(c1); - seed.add(c2); - seed.add(c3); - seed.add(c4); + Seed seed = new Seed(); + seed.get_Crosses().add(c1); + seed.get_Crosses().add(c2); + seed.get_Crosses().add(c3); + seed.get_Crosses().add(c4); return seed; } @@ -378,14 +382,14 @@ private Seed isTrack4(Cross c1, Cross c2, Cross c3, Cross c4) { if (Math.abs(rad234) < SVTParameters.radcut) { return null; } - double[] seed_delta_phi = {phi12, phi13, phi14}; - double[] seed_radius = {rad123, rad124, rad134, rad234}; +// double[] seed_delta_phi = {phi12, phi13, phi14}; +// double[] seed_radius = {rad123, rad124, rad134, rad234}; // create the seed - Seed seed = new Seed(seed_delta_phi, seed_radius); - seed.add(c1); - seed.add(c2); - seed.add(c3); - seed.add(c4); + Seed seed = new Seed(); + seed.get_Crosses().add(c1); + seed.get_Crosses().add(c2); + seed.get_Crosses().add(c3); + seed.get_Crosses().add(c4); return seed; } @@ -406,13 +410,13 @@ private Seed isTrack3(Cross c1, Cross c2, Cross c3) { return null; } - double[] seed_delta_phi = {phi12, phi13}; - double[] seed_radius = {rad123}; +// double[] seed_delta_phi = {phi12, phi13}; +// double[] seed_radius = {rad123}; // create the seed - Seed seed = new Seed(seed_delta_phi, seed_radius); - seed.add(c1); - seed.add(c2); - seed.add(c3); + Seed seed = new Seed(); + seed.get_Crosses().add(c1); + seed.get_Crosses().add(c2); + seed.get_Crosses().add(c3); return seed; } @@ -450,11 +454,11 @@ private double radCurvature(Cross c1, Cross c2, Cross c3) { } - private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { + private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, double bz) { if(s==null) return; - Track cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); + Track cand = s.fit(svt_geo, bmt_geo, 3, true, bz); if(cand==null) return; @@ -482,13 +486,13 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_ } } if(cMatch != null) - s.add(cMatch); + s.get_Crosses().add(cMatch); } - private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { + private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, double bz) { - Track cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); + Track cand = s.fit(svt_geo, bmt_geo, 3, true, bz); if(s==null) return; double maxChi2 = Double.POSITIVE_INFINITY; @@ -497,8 +501,8 @@ private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, if(passCcross(s, BMTCrosses.get(i)) == false) { continue; } else { - s.add(BMTCrosses.get(i)); - cand = s.seedFit.fitSeed(s, svt_geo, bmt_geo, 3, true, swimmer); + s.get_Crosses().add(BMTCrosses.get(i)); + cand = s.fit(svt_geo, bmt_geo, 3, true, bz); if(cand==null) continue; double linechi2perndf = cand.get_lineFitChi2PerNDF(); @@ -506,10 +510,10 @@ private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, maxChi2 = linechi2perndf; BestMatch = (Cross) BMTCrosses.get(i).clone(); } - s.remove(s.size()-1); + s.get_Crosses().remove(BMTCrosses.get(i)); } if(BestMatch!=null) - s.add(BestMatch); + s.get_Crosses().add(BestMatch); } } @@ -519,14 +523,14 @@ private boolean ContainsSeed(List CirTrks, Seed cand) { for(int i = 0; i { - - private static final long serialVersionUID = 1L; - final double[] delta_phi; // opening angle between cross 1 and 2 positions wrt the origin - final double[] radius; // the radius of the circle of the seed calculated using 3 crosses belonging to the seed - public TrackSeeder seedFit; - /** - * The constructor of the seed - * - * @param delta_phi - * @param radius - */ - Seed(double[] delta_phi, double[] radius) { - seedFit = new TrackSeeder(); - this.delta_phi = delta_phi; - this.radius = radius; - } - } +// /** +// * A class representing the seed object. The seed of a track is the initial +// * guess of the track and contains the crosses that belong to it +// * +// * @author ziegler +// * +// */ +// private class Seed extends ArrayList { +// +// private static final long serialVersionUID = 1L; +// final double[] delta_phi; // opening angle between cross 1 and 2 positions wrt the origin +// final double[] radius; // the radius of the circle of the seed calculated using 3 crosses belonging to the seed +// public TrackSeeder seedFit; +// /** +// * The constructor of the seed +// * +// * @param delta_phi +// * @param radius +// */ +// Seed(double[] delta_phi, double[] radius) { +// seedFit = new TrackSeeder(); +// this.delta_phi = delta_phi; +// this.radius = radius; +// } +// } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index e1143f316..8cbdd8b31 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -550,8 +550,8 @@ public List reFitSeed(Seed bseed, public List reFit(List seedlist, SVTGeometry SVTGeom, BMTGeometry BMTGeom, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { - trseed = new TrackSeederCA(); - trseed2 = new TrackSeeder(); + trseed = new TrackSeederCA(SVTGeom, BMTGeom, swimmer); + trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); List filtlist = new ArrayList(); if(seedlist==null) return filtlist; @@ -596,10 +596,10 @@ public List reFitSeed(Seed bseed, } } Collections.sort(refi); - seedlist = trseed.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer); + seedlist = trseed.findSeed(refi, refib); trseed2.unUsedHitsOnly = true; - seedlist.addAll( trseed2.findSeed(refi, refib, SVTGeom, BMTGeom, swimmer)); + seedlist.addAll( trseed2.findSeed(refi, refib)); return seedlist; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 5ead3ad15..a0f3d7591 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -62,17 +62,17 @@ public boolean processEvent(DataEvent event, //seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); } else { if(isSVTonly) { - TrackSeeder trseed = new TrackSeeder(); + TrackSeeder trseed = new TrackSeeder(SVTGeom, BMTGeom, swimmer); trseed.unUsedHitsOnly = true; - seeds = trseed.findSeed(crosses.get(0), null, SVTGeom, BMTGeom, swimmer); + seeds = trseed.findSeed(crosses.get(0), null); } else { - TrackSeederCA trseed = new TrackSeederCA(); // cellular automaton seeder - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer); + TrackSeederCA trseed = new TrackSeederCA(SVTGeom, BMTGeom, swimmer); // cellular automaton seeder + seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - TrackSeeder trseed2 = new TrackSeeder(); + TrackSeeder trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); trseed2.unUsedHitsOnly = true; - seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, swimmer)); // RDV check for overlaps + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); // RDV check for overlaps if(exLayrs==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); } @@ -155,7 +155,7 @@ public boolean processEvent(DataEvent event, if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) fittedTrack = recUtil.OutputTrack(seed, kf, SVTGeom, BMTGeom); } - fittedTrack.set_TrackingStatus(seed.trkStatus); + fittedTrack.set_TrackingStatus(seed.get_Status()); trkcands.add(fittedTrack); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index d7c3e6480..ed317b844 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -1,10 +1,17 @@ package org.jlab.rec.cvt.track; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.fit.HelicalTrackFitter; +import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Helix; /** @@ -14,45 +21,102 @@ */ public class Seed implements Comparable{ - public int trkStatus; - + private int status; + private double doca; + private double rho; + private double phi; + private Helix _Helix; + private List _Crosses; + + public Seed() { - // TODO Auto-generated constructor stub } - private Helix _Helix; - private List _Clusters; - private List _Crosses; + public Seed(List crosses) { + this.set_Crosses(crosses); + } + + public Seed(List crosses, double doca, double rho, double phi) { + this.set_Crosses(crosses); + this.set_Doca(doca); + this.set_Rho(rho); + this.set_Phi(phi); + } + + public Seed(List crosses, Helix helix) { + this.set_Crosses(crosses); + this.set_Helix(helix); + } public Helix get_Helix() { return _Helix; } - public void set_Helix(Helix _Helix) { - this._Helix = _Helix; + public final void set_Helix(Helix helix) { + this._Helix = helix; + this.doca = helix.get_dca(); + this.rho = helix.get_curvature(); + this.phi = helix.get_phi_at_dca(); } - public List get_Clusters() { - return _Clusters; + public void set_Status(int trkStatus) { + this.status = trkStatus; + } + + public final void set_Doca(double doca) { + this.doca = doca; + } + + public final void set_Rho(double rho) { + this.rho = rho; + } + + public final void set_Phi(double phi) { + this.phi = phi; + } + + public int get_Status() { + return status; } - public void set_Clusters(List _Clusters) { - this._Clusters = _Clusters; + public double get_Doca() { + return this.doca; + } + + public double get_Rho() { + return this.rho; + } + + public double get_Phi() { + return this.phi; + } + + public List get_Clusters() { + List clusters = new ArrayList(); + for(Cross c : this.get_Crosses()) { + if(c.get_Detector()==DetectorType.BST) { + clusters.add(c.get_Cluster1()); + clusters.add(c.get_Cluster2()); + } else { + clusters.add(c.get_Cluster1()); + } + } + Collections.sort(clusters); + return clusters; } public List get_Crosses() { + Collections.sort(_Crosses); return _Crosses; } - public void set_Crosses(List _Crosses) { + public final void set_Crosses(List _Crosses) { + Collections.sort(_Crosses); this._Crosses = _Crosses; } public String get_IntIdentifier() { - Collections.sort(this.get_Clusters()); - Collections.sort(this.get_Crosses()); - String id = ""; for(Cluster c: this.get_Clusters()) id+=c.get_Id(); @@ -70,8 +134,154 @@ public int compareTo(Seed arg) { } - public double doca; - public double rho; - public double phi; + + public Track fit(SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, + double bfield) { + + List X = new ArrayList<>(); + List Y = new ArrayList<>(); + List Z = new ArrayList<>(); + List Rho = new ArrayList<>(); + List ErrZ = new ArrayList<>(); + List ErrRho = new ArrayList<>(); + List ErrRt = new ArrayList<>(); + List BMTCrossesC = new ArrayList<>(); + List BMTCrossesZ = new ArrayList<>(); + List SVTCrosses = new ArrayList<>(); + + double chisqMax = Double.POSITIVE_INFINITY; + + int svtSz = 0; + int bmtZSz = 0; + int bmtCSz = 0; + + for (Cross c : this.get_Crosses()) { + c.resetCross(svt_geo); + if (c.get_Detector()==DetectorType.BST) { + SVTCrosses.add(c); + } + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { + BMTCrossesC.add(c); + } + else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { + BMTCrossesZ.add(c); + } + } + svtSz = SVTCrosses.size(); + if (BMTCrossesZ != null) { + bmtZSz = BMTCrossesZ.size(); + } + if (BMTCrossesC != null) { + bmtCSz = BMTCrossesC.size(); + } + + int useSVTdipAngEst = 1; + if (bmtCSz >= 2) { + useSVTdipAngEst = 0; + } + ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); + ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); + ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); + ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); + ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); + ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination + ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); + + Track cand = null; + + HelicalTrackFitter fitTrk = new HelicalTrackFitter(); + for (int i = 0; i < fitIter; i++) { + // if(originConstraint==true) { + // X.add(0, (double) 0); + // Y.add(0, (double) 0); + // Z.add(0, (double) 0); + // Rho.add(0, (double) 0); + // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); + // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); + // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); + // } + X.clear(); + Y.clear(); + Z.clear(); + Rho.clear(); + ErrZ.clear(); + ErrRho.clear(); + ErrRt.clear(); + + for (int j = 0; j < SVTCrosses.size(); j++) { + X.add(j, SVTCrosses.get(j).get_Point().x()); + Y.add(j, SVTCrosses.get(j).get_Point().y()); + if (useSVTdipAngEst == 1) { + Z.add(j, SVTCrosses.get(j).get_Point().z()); + Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() + + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); + ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() + + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); + ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); + } + ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() + + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); + } + + if (bmtZSz > 0) { + for (int j = svtSz; j < svtSz + bmtZSz; j++) { + X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); + Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); + ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() + + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); + } + } + if (bmtCSz > 0) { + for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { + Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); + Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); + + ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); + ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); + } + } + X.add((double) Constants.getXb()); + Y.add((double) Constants.getYb()); + + ErrRt.add((double) 0.1); + + fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + + if (fitTrk.get_helix() == null) { + return null; + } + + cand = new Track(fitTrk.get_helix()); + cand.addAll(SVTCrosses); + cand.addAll(BMTCrossesC); + cand.addAll(BMTCrossesZ); + + fitTrk.get_helix().B = bfield; + cand.set_HelicalTrack(fitTrk.get_helix()); + if( X.size()>3 ) { + cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]/(X.size()-3)); + } + else { + cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]*2); // penalize tracks with only 3 crosses + } + + if( Z.size() > 2 ) { + cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]/(Z.size()-2)); + } + else { + cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses + } + cand.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); + cand.setNDF(X.size()+Z.size()); + + if (fitTrk.get_chisq()[0] < chisqMax) { + chisqMax = fitTrk.get_chisq()[0]; + if(chisqMax othercrs) { for (Seed seed : seedScan) { - double d = seed.doca; - double r = seed.rho; - double f = seed.phi; + double d = seed.get_Doca(); + double r = seed.get_Rho(); + double f = seed.get_Phi(); Map matchBMT = new HashMap(); for (Cross c : othercrs ) { @@ -128,11 +128,7 @@ private void FitSeed(List seedcrs) { return; } } - Seed seed = new Seed(); - seed.set_Crosses(seedcrs); - seed.doca = d; - seed.rho = r; - seed.phi = f; + Seed seed = new Seed(seedcrs, d, r, f); seedScan.add(seed); } @@ -314,17 +310,6 @@ public List findSeed(List svt_crosses, List bmt_crosses, Seed seed = new Seed(); seed.set_Crosses(seedcrs); seed.set_Helix(cand.get_helix()); - List clusters = new ArrayList(); - for(Cross c : seed.get_Crosses()) { - c.set_AssociatedTrackID(1111); - if(c.get_Detector()==DetectorType.BST) { - clusters.add(c.get_Cluster1()); - clusters.add(c.get_Cluster2()); - } else { - clusters.add(c.get_Cluster1()); - } - } - seed.set_Clusters(clusters); //match to BMT if (seed != null ) { @@ -341,7 +326,6 @@ public List findSeed(List svt_crosses, List bmt_crosses, if (bcand != null) { seed = new Seed(); seed.set_Crosses(bseed.get_Crosses()); - seed.set_Clusters(bseed.get_Clusters()); seed.set_Helix(bcand.get_helix()); } } @@ -576,7 +560,6 @@ public List findCandUsingMicroMegas(Seed trkCand, BMTTrkSeed.set_Helix(trkCand.get_Helix()); BMTTrkSeed.set_Crosses(matches); - BMTTrkSeed.set_Clusters(trkCand.get_Clusters()); AllSeeds.add(BMTTrkSeed); //if (AllSeeds.size() > 200) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 7a8e69e80..824b1f14c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -257,6 +257,23 @@ public int compareTo(Track tr) { return (tr.get_P() > this.get_P()) ? 1 : -1; } + /** + * Check if track passes basic quality cuts + * @return + */ + public boolean isGood() { + if(Double.isNaN(this.getChi2())) + return false; + else if(this.getChi2() > Constants.CHI2CUT * (this.getNDF() + 5)) + return false; + else if(this.getNDF() < Constants.NDFCUT) + return false; + else if(this.get_Pt() < Constants.PTCUT) + return false; + else + return true; + } + /** * Compare this track quality with the given track * based on NDF and Chi2 diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index df938764a..6e891e242 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -118,19 +118,7 @@ public void removeBadTracks(List trkcands) { int initial_size = trkcands.size(); for (int i = 1; i < initial_size + 1; i++) { - if (Double.isNaN(trkcands.get(initial_size - i).getChi2())) { - trkcands.remove(initial_size - i); - continue; - } - if (trkcands.get(initial_size - i).getChi2() > Constants.CHI2CUT * (trkcands.get(initial_size - i).getNDF() + 5)) { - trkcands.remove(initial_size - i); - continue; - } - if (trkcands.get(initial_size - i).getNDF() < Constants.NDFCUT) { - trkcands.remove(initial_size - i); - continue; - } - if (trkcands.get(initial_size - i).get_Pt() < Constants.PTCUT) { + if (!trkcands.get(initial_size - i).isGood()) { trkcands.remove(initial_size - i); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 925ad396c..ec6cd055a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -6,21 +6,22 @@ import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.fit.CircleFitPars; -import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; public class TrackSeeder { + SVTGeometry sgeo = null; + BMTGeometry bgeo = null; + double bfield; + int NBINS = 36; double[] phiShift = new double[]{0, 65, 90}; // move the bin edge to handle bin boundaries List> scan ; @@ -32,13 +33,19 @@ public class TrackSeeder { List Ws ; public boolean unUsedHitsOnly = false; - public TrackSeeder() { + public TrackSeeder(SVTGeometry sgeo, BMTGeometry bgeo, Swim swimmer) { + this.sgeo = sgeo; + this.bgeo = bgeo; + float[] b = new float[3]; + swimmer.BfieldLab(0, 0, 0, b); + this.bfield = Math.abs(b[2]); + //init lists for scan sortedCrosses = new ArrayList>>(); - for(int b =0; b>() ); + for(int i =0; i>() ); for(int l =0; l<3; l++) { - sortedCrosses.get(b).add(l,new ArrayList() ); + sortedCrosses.get(i).add(l,new ArrayList() ); } } scan = new ArrayList>(); @@ -49,14 +56,15 @@ public TrackSeeder() { Ys = new ArrayList(); Ws = new ArrayList(); } + private void MatchSeed(List othercrs) { if(othercrs==null || othercrs.size()==0) return; for (Seed seed : seedScan) { - double d = seed.doca; - double r = seed.rho; - double f = seed.phi; + double d = seed.get_Doca(); + double r = seed.get_Rho(); + double f = seed.get_Phi(); for (Cross c : othercrs ) { c.set_AssociatedTrackID(22220); @@ -116,12 +124,7 @@ public void FitSeed(List seedcrs) { return; } } - Seed seed = new Seed(); - seed.set_Crosses(seedcrs); - seed.doca = d; - seed.rho = r; - seed.phi = f; - + Seed seed = new Seed(seedcrs, d, r, f); seedScan.add(seed); } @@ -213,10 +216,8 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); - public List findSeed(List bst_crosses, List bmt_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, - Swim swimmer) { - + public List findSeed(List bst_crosses, List bmt_crosses) { + List seedlist = new ArrayList(); List crosses = new ArrayList(); @@ -320,28 +321,16 @@ public List findSeed(List bst_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); Track cand = null; if(seedcrs.size()>=3) - cand = fitSeed(seedcrs, svt_geo, bmt_geo, 5, false, swimmer); + cand = mseed.fit(this.sgeo, this.bgeo, 5, false, this.bfield); if (cand != null) { - Seed seed = new Seed(); - seed.set_Crosses(seedcrs); - seed.set_Helix(cand.get_helix()); - List clusters = new ArrayList(); - for(Cross c : seed.get_Crosses()) { - c.set_AssociatedTrackID(1111); - if(c.get_Detector()==DetectorType.BST) { - clusters.add(c.get_Cluster1()); - clusters.add(c.get_Cluster2()); - } else { - clusters.add(c.get_Cluster1()); - } - } - seed.set_Clusters(clusters); + Seed seed = new Seed(seedcrs, cand.get_helix()); + //match to BMT if (seed != null ) { - List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses, bmt_geo); + List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses); BMTmatches.clear(); if (sameSectorCrosses.size() >= 0) { - BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses, bmt_geo); + BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses); } Seed bestSeed = null; double chi2_Circ = Double.POSITIVE_INFINITY; @@ -349,18 +338,17 @@ public List findSeed(List bst_crosses, List bmt_crosses, for (Seed bseed : BMTmatches) { //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, bmt_geo, 5, false, swimmer); + Track bcand = bseed.fit(this.sgeo, this.bgeo, 5, false, this.bfield); if (bcand != null && bcand.get_circleFitChi2PerNDF() findSeed(List bst_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, BMTGeometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init double jitter = Math.toRadians(10); // 10 degrees jitter for (int i = 0; i < bmt_crosses.size(); i++) { - Point3D pAtBMTSurf =seed.get_Helix().getPointAtRadius(bmt_geo.getRadius(bmt_crosses.get(i).get_Cluster1().get_Layer())); + Point3D pAtBMTSurf =seed.get_Helix().getPointAtRadius(bgeo.getRadius(bmt_crosses.get(i).get_Cluster1().get_Layer())); // the hit parameters double angle = Math.atan2(pAtBMTSurf.y(), pAtBMTSurf.x()); if (angle < 0) { @@ -390,7 +378,7 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) // == bmt_crosses.get(i).get_Sector() - 1) //inDetector(int layer, int sector, Point3D traj) - if (bmt_geo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), pAtBMTSurf)==true){ + if (bgeo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), pAtBMTSurf)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -399,158 +387,157 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c return bmt_crossesInSec; } - private List X = new ArrayList(); - private List Y = new ArrayList(); - private List Z = new ArrayList(); - private List Rho = new ArrayList(); - private List ErrZ = new ArrayList(); - private List ErrRho = new ArrayList(); - private List ErrRt = new ArrayList(); - List BMTCrossesC = new ArrayList(); - List BMTCrossesZ = new ArrayList(); - List SVTCrosses = new ArrayList(); - float b[] = new float[3]; - - public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, - boolean originConstraint, Swim swimmer) { - double chisqMax = Double.POSITIVE_INFINITY; - - Track cand = null; - HelicalTrackFitter fitTrk = new HelicalTrackFitter(); - for (int i = 0; i < fitIter; i++) { - // if(originConstraint==true) { - // X.add(0, (double) 0); - // Y.add(0, (double) 0); - // Z.add(0, (double) 0); - // Rho.add(0, (double) 0); - // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); - // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // } - X.clear(); - Y.clear(); - Z.clear(); - Rho.clear(); - ErrZ.clear(); - ErrRho.clear(); - ErrRt.clear(); - - int svtSz = 0; - int bmtZSz = 0; - int bmtCSz = 0; - - BMTCrossesC.clear(); - BMTCrossesZ.clear(); - SVTCrosses.clear(); - - for (Cross c : VTCrosses) { - if (c.get_Detector()==DetectorType.BST) { - SVTCrosses.add(c); - } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { - BMTCrossesC.add(c); - } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { - BMTCrossesZ.add(c); - } - } - svtSz = SVTCrosses.size(); - if (BMTCrossesZ != null) { - bmtZSz = BMTCrossesZ.size(); - } - if (BMTCrossesC != null) { - bmtCSz = BMTCrossesC.size(); - } - - int useSVTdipAngEst = 1; - if (bmtCSz >= 2) { - useSVTdipAngEst = 0; - } - - ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); - ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); - ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination - ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); - - cand = new Track(null); - cand.addAll(SVTCrosses); - for (int j = 0; j < SVTCrosses.size(); j++) { - X.add(j, SVTCrosses.get(j).get_Point().x()); - Y.add(j, SVTCrosses.get(j).get_Point().y()); - if (useSVTdipAngEst == 1) { - Z.add(j, SVTCrosses.get(j).get_Point().z()); - Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() - + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); - ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); - } - ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - } - - if (bmtZSz > 0) { - for (int j = svtSz; j < svtSz + bmtZSz; j++) { - X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); - Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); - ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() - + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); - } - } - if (bmtCSz > 0) { - for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { - Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - - ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); - ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); - } - } - X.add((double) Constants.getXb()); - Y.add((double) Constants.getYb()); - ErrRt.add((double) 0.1); - - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); - - if (fitTrk.get_helix() == null) { - return null; - } - - cand = new Track(fitTrk.get_helix()); - //cand.addAll(SVTCrosses); - cand.addAll(SVTCrosses); - cand.addAll(BMTCrossesC); - cand.addAll(BMTCrossesZ); - - swimmer.BfieldLab(0, 0, 0, b); - double Bz = Math.abs(b[2]); - fitTrk.get_helix().B = Bz; - cand.set_HelicalTrack(fitTrk.get_helix()); - //if(shift==0) - if (fitTrk.get_chisq()[0] < chisqMax) { - chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) - return null; - if(X.size() > 3) - cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params - if(Z.size() > 2) - cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params - return cand; - } - - - - public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, BMTGeometry bmt_geo) { +// private List X = new ArrayList(); +// private List Y = new ArrayList(); +// private List Z = new ArrayList(); +// private List Rho = new ArrayList(); +// private List ErrZ = new ArrayList(); +// private List ErrRho = new ArrayList(); +// private List ErrRt = new ArrayList(); +// List BMTCrossesC = new ArrayList(); +// List BMTCrossesZ = new ArrayList(); +// List SVTCrosses = new ArrayList(); +// float b[] = new float[3]; +// +// public Track fit(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, +// boolean originConstraint, Swim swimmer) { +// double chisqMax = Double.POSITIVE_INFINITY; +// +// Track cand = null; +// HelicalTrackFitter fitTrk = new HelicalTrackFitter(); +// for (int i = 0; i < fitIter; i++) { +// // if(originConstraint==true) { +// // X.add(0, (double) 0); +// // Y.add(0, (double) 0); +// // Z.add(0, (double) 0); +// // Rho.add(0, (double) 0); +// // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); +// // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); +// // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); +// // } +// X.clear(); +// Y.clear(); +// Z.clear(); +// Rho.clear(); +// ErrZ.clear(); +// ErrRho.clear(); +// ErrRt.clear(); +// +// int svtSz = 0; +// int bmtZSz = 0; +// int bmtCSz = 0; +// +// BMTCrossesC.clear(); +// BMTCrossesZ.clear(); +// SVTCrosses.clear(); +// +// for (Cross c : VTCrosses) { +// if (c.get_Detector()==DetectorType.BST) { +// SVTCrosses.add(c); +// } +// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { +// BMTCrossesC.add(c); +// } +// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { +// BMTCrossesZ.add(c); +// } +// } +// svtSz = SVTCrosses.size(); +// if (BMTCrossesZ != null) { +// bmtZSz = BMTCrossesZ.size(); +// } +// if (BMTCrossesC != null) { +// bmtCSz = BMTCrossesC.size(); +// } +// +// int useSVTdipAngEst = 1; +// if (bmtCSz >= 2) { +// useSVTdipAngEst = 0; +// } +// +// ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); +// ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); +// ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination +// ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); +// +// cand = new Track(null); +// cand.addAll(SVTCrosses); +// for (int j = 0; j < SVTCrosses.size(); j++) { +// X.add(j, SVTCrosses.get(j).get_Point().x()); +// Y.add(j, SVTCrosses.get(j).get_Point().y()); +// if (useSVTdipAngEst == 1) { +// Z.add(j, SVTCrosses.get(j).get_Point().z()); +// Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() +// + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); +// ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() +// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); +// ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); +// } +// ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() +// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); +// } +// +// if (bmtZSz > 0) { +// for (int j = svtSz; j < svtSz + bmtZSz; j++) { +// X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); +// Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); +// ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() +// + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); +// } +// } +// if (bmtCSz > 0) { +// for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { +// Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); +// Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); +// +// ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); +// ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); +// } +// } +// X.add((double) Constants.getXb()); +// Y.add((double) Constants.getYb()); +// ErrRt.add((double) 0.1); +// +// fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); +// +// if (fitTrk.get_helix() == null) { +// return null; +// } +// +// cand = new Track(fitTrk.get_helix()); +// //cand.addAll(SVTCrosses); +// cand.addAll(SVTCrosses); +// cand.addAll(BMTCrossesC); +// cand.addAll(BMTCrossesZ); +// +// swimmer.BfieldLab(0, 0, 0, b); +// double Bz = Math.abs(b[2]); +// fitTrk.get_helix().B = Bz; +// cand.set_HelicalTrack(fitTrk.get_helix()); +// //if(shift==0) +// if (fitTrk.get_chisq()[0] < chisqMax) { +// chisqMax = fitTrk.get_chisq()[0]; +// if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) +// return null; +// if(X.size() > 3) +// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params +// if(Z.size() > 2) +// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params +// return cand; +// } + + + + public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -587,23 +574,22 @@ public List findCandUsingMicroMegas(Seed trkCand, matches.clear(); if (BMTCcrosses.get(0).size() > 0 && i1 < BMTCcrosses.get(0).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1), bgeo)) { matches.add(BMTCcrosses.get(0).get(i1)); } } if (BMTCcrosses.get(1).size() > 0 && i2 < BMTCcrosses.get(1).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2), bgeo)) { matches.add(BMTCcrosses.get(1).get(i2)); } } if (BMTCcrosses.get(2).size() > 0 && i3 < BMTCcrosses.get(2).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3), bgeo)) { matches.add(BMTCcrosses.get(2).get(i3)); } } matches.addAll(trkCand.get_Crosses()); - Collections.sort(matches); if (matches.size() > 0) { Seed BMTTrkSeed = new Seed(); String st = ""; @@ -611,7 +597,6 @@ public List findCandUsingMicroMegas(Seed trkCand, st+=c.get_Id(); BMTTrkSeed.set_Helix(trkCand.get_Helix()); BMTTrkSeed.set_Crosses(matches); - BMTTrkSeed.set_Clusters(trkCand.get_Clusters()); AllSeeds.put(st,BMTTrkSeed); //if (AllSeeds.size() > 200) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index dfd9f40b9..6018a3d0d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -5,21 +5,26 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.fit.LineFitPars; import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.svt.SVTGeometry; public class TrackSeederCA { - - public TrackSeederCA() { - + SVTGeometry sgeo = null; + BMTGeometry bgeo = null; + double bfield; + + + public TrackSeederCA(SVTGeometry sgeo, BMTGeometry bgeo, Swim swimmer) { + this.sgeo = sgeo; + this.bgeo = bgeo; + float[] b = new float[3]; + swimmer.BfieldLab(0, 0, 0, b); + this.bfield = Math.abs(b[2]); } @@ -27,8 +32,7 @@ public TrackSeederCA() { // Retrieve lists of crosses as track candidates // from the output of the cellular automaton // it looks only for the maximum state, TODO: remove found candidate and continue - public List> getCAcandidates( List nodes, SVTGeometry svt_geo, - BMTGeometry bmt_geo, Swim swimmer ) { + public List> getCAcandidates(List nodes) { //System.out.println("\n\n\t ____inside get candidates___"); List> trCands = new ArrayList>(); List> cellCands = new ArrayList>(); @@ -116,7 +120,8 @@ public List> getCAcandidates( List nodes, SVTGeometry svt // System.out.println(" "); if( cand.get(0).get_plane().equalsIgnoreCase("XY")) { if( candlen > 2 ){ - if( fitSeed(getCrossFromCells(cand), svt_geo, bmt_geo, 2, false, swimmer) != null) { + Seed seed = new Seed(getCrossFromCells(cand)); + if(seed.fit(sgeo, bgeo, 2, false, bfield) != null) { cellCands.add(cand); for( Cell n : cand ) { @@ -168,8 +173,7 @@ private ArrayList getCrossFromCells( List l ){ } // create and run the cellular automaton - public List runCAMaker( String plane, int nepochs, ArrayList crs, - BMTGeometry bgeom, Swim swimmer){ + public List runCAMaker( String plane, int nepochs, ArrayList crs){ MakerCA camaker = new MakerCA(false); camaker.set_plane( plane ); if( plane.equalsIgnoreCase("XY") ){ @@ -183,16 +187,15 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs, camaker.set_aCvsR(90.); } - camaker.createCells(crs, bgeom); + camaker.createCells(crs, bgeo); camaker.findNeigbors(); camaker.evolve( nepochs ); return camaker.getNodes(); } TrackListFinder trkFinder = new TrackListFinder(); - public List findSeed(List svt_crosses, List bmt_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { - + public List findSeed(List svt_crosses, List bmt_crosses) { + List seedlist = new ArrayList(); ArrayList crosses = new ArrayList(); @@ -215,51 +218,40 @@ public List findSeed(List svt_crosses, List bmt_crosses, // look for candidates in the XY plane // run the cellular automaton over SVT and BMT_Z crosses - List xynodes = runCAMaker( "XY", 5, crosses, bmt_geo, swimmer); - List> xytracks = getCAcandidates( xynodes, svt_geo, bmt_geo, swimmer); + List xynodes = runCAMaker( "XY", 5, crosses); + List> xytracks = getCAcandidates( xynodes); // System.out.println( " XY tracks " + xytracks ); //// TODO: TEST TEST TEST // test if a first fit to move the SVT crosses helps // for( ArrayList acr : xytracks ) { -// Track xycand = fitSeed(acr, svt_geo, 5, false); +// Track xycand = fit(acr, svt_geo, 5, false); // // update // } - List> seedCrosses = CAonRZ( xytracks, bmtC_crosses, svt_geo, bmt_geo, swimmer); + List> seedCrosses = CAonRZ( xytracks, bmtC_crosses); List cands = new ArrayList(); // System.out.println(seedlist.size()); for (int s = 0; s < seedCrosses.size(); s++) { - Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters - Track cand = fitSeed(seedCrosses.get(s), svt_geo, bmt_geo, 5, false, swimmer); - if (cand != null) { +// Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters +// Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, 5, false, swimmer); + Seed candSeed = new Seed(seedCrosses.get(s)); + Track cand = candSeed.fit(sgeo, bgeo, 5, false, bfield); + if (cand != null && cand.isGood()) { cands.add(cand); } } // for( int i=0;i clusters = new ArrayList(); - Collections.sort(seed.get_Crosses()); - for(Cross c : seed.get_Crosses()) { - if(c.get_Detector()==DetectorType.BST) { - clusters.add(c.get_Cluster1()); - clusters.add(c.get_Cluster2()); - } else { - clusters.add(c.get_Cluster1()); - } - } - seed.set_Clusters(clusters); } for (Seed bseed : seedlist) { for(Cross c : bseed.get_Crosses()) { @@ -326,11 +318,8 @@ private List rmDuplicate( List tracks) { return goodTrks; } - public List> CAonRZ( - List>xytracks , - List> bmtC_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, - Swim swimmer) { + public List> CAonRZ(List> xytracks , + List> bmtC_crosses) { List> seedCrosses = new ArrayList>(); @@ -382,9 +371,9 @@ public List> CAonRZ( // Collections.sort(crsZR); // run the CAmaker - List zrnodes = runCAMaker( "ZR", 5, crsZR, bmt_geo, swimmer); + List zrnodes = runCAMaker( "ZR", 5, crsZR); //System.out.println(zrnodes); - List> zrtracks = getCAcandidates( zrnodes, svt_geo, bmt_geo, swimmer); + List> zrtracks = getCAcandidates( zrnodes); // System.out.println("sector" + sector + " len " + zrtracks.size()); @@ -408,7 +397,7 @@ public List> CAonRZ( List EZ= new ArrayList(); for( Cross c : zrcross ) { - R.add( bmt_geo.getRadiusMidDrift(c.get_Cluster1().get_Layer())); + R.add( bgeo.getRadiusMidDrift(c.get_Cluster1().get_Layer())); Z.add( c.get_Point().z() ); EZ.add( c.get_PointErr().z()); } @@ -430,13 +419,13 @@ public List> CAonRZ( int s1 = c.get_Cluster1().get_Sector(); double c1 = c.get_Cluster1().get_Centroid(); double r1 = SVTGeometry.getLayerRadius(l1); - double nstr1 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r1 - b)/m, l1, s1); + double nstr1 = sgeo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r1 - b)/m, l1, s1); int l2 = c.get_Cluster2().get_Layer(); int s2 = c.get_Cluster2().get_Sector(); double c2 = c.get_Cluster2().get_Centroid(); double r2 = SVTGeometry.getLayerRadius(l2); - double nstr2 = svt_geo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r2 - b)/m, l2, s2); + double nstr2 = sgeo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r2 - b)/m, l2, s2); if( Math.abs( c1 - nstr1 ) < 8 && Math.abs( c2 - nstr2 ) < 8 ) seedCrosses.get(scsize-1).add(c); @@ -467,165 +456,165 @@ public List> CAonRZ( return seedCrosses; } - private List X = new ArrayList(); - private List Y = new ArrayList(); - private List Z = new ArrayList(); - private List Rho = new ArrayList(); - private List ErrZ = new ArrayList(); - private List ErrRho = new ArrayList(); - private List ErrRt = new ArrayList(); - List BMTCrossesC = new ArrayList(); - List BMTCrossesZ = new ArrayList(); - List SVTCrosses = new ArrayList(); - float b[] = new float[3]; - - public Track fitSeed(List VTCrosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, - Swim swimmer) { - double chisqMax = Double.POSITIVE_INFINITY; - Collections.sort(VTCrosses); - Track cand = null; - HelicalTrackFitter fitTrk = new HelicalTrackFitter(); - for (int i = 0; i < fitIter; i++) { - // if(originConstraint==true) { - // X.add(0, (double) 0); - // Y.add(0, (double) 0); - // Z.add(0, (double) 0); - // Rho.add(0, (double) 0); - // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); - // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // } - X.clear(); - Y.clear(); - Z.clear(); - Rho.clear(); - ErrZ.clear(); - ErrRho.clear(); - ErrRt.clear(); - - int svtSz = 0; - int bmtZSz = 0; - int bmtCSz = 0; - - BMTCrossesC.clear(); - BMTCrossesZ.clear(); - SVTCrosses.clear(); - - for (Cross c : VTCrosses) { - if (c.get_Detector()==DetectorType.BST) { - SVTCrosses.add(c); - } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { - BMTCrossesC.add(c); - } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { - BMTCrossesZ.add(c); - } - } - svtSz = SVTCrosses.size(); - if (BMTCrossesZ != null) { - bmtZSz = BMTCrossesZ.size(); - } - if (BMTCrossesC != null) { - bmtCSz = BMTCrossesC.size(); - } - - int useSVTdipAngEst = 1; - if (bmtCSz >= 2) { - useSVTdipAngEst = 0; - } - - ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); - ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); - ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); - ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination - ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); - - cand = new Track(null); - cand.addAll(SVTCrosses); - for (int j = 0; j < SVTCrosses.size(); j++) { - X.add(j, SVTCrosses.get(j).get_Point().x()); - Y.add(j, SVTCrosses.get(j).get_Point().y()); - if (useSVTdipAngEst == 1) { - Z.add(j, SVTCrosses.get(j).get_Point().z()); - Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() - + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); - ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); - } - ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - } - - if (bmtZSz > 0) { - for (int j = svtSz; j < svtSz + bmtZSz; j++) { - X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); - Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); - ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() - + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); - } - } - if (bmtCSz > 0) { - for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { - Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - - ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); - ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); - } - } - X.add((double) Constants.getXb()); - Y.add((double) Constants.getYb()); - - ErrRt.add((double) 0.1); - - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); - - if (fitTrk.get_helix() == null) { - return null; - } - - cand = new Track(fitTrk.get_helix()); - //cand.addAll(SVTCrosses); - cand.addAll(SVTCrosses); - cand.addAll(BMTCrossesC); - cand.addAll(BMTCrossesZ); - - swimmer.BfieldLab(0, 0, 0, b); - double Bz = Math.abs(b[2]); - fitTrk.get_helix().B = Bz; - cand.set_HelicalTrack(fitTrk.get_helix()); - if( X.size()>3 ) { - cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]/(X.size()-3)); - } - else { - cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]*2); // penalize tracks with only 3 crosses - } - - if( Z.size() > 2 ) { - cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]/Z.size()); - } - else { - cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses - } - cand.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); - cand.setNDF(X.size()+Z.size()); - //if(shift==0) - if (fitTrk.get_chisq()[0] < chisqMax) { - chisqMax = fitTrk.get_chisq()[0]; - if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) -// cand=null; - return cand; - } +// private List X = new ArrayList(); +// private List Y = new ArrayList(); +// private List Z = new ArrayList(); +// private List Rho = new ArrayList(); +// private List ErrZ = new ArrayList(); +// private List ErrRho = new ArrayList(); +// private List ErrRt = new ArrayList(); +// List BMTCrossesC = new ArrayList(); +// List BMTCrossesZ = new ArrayList(); +// List SVTCrosses = new ArrayList(); +// float b[] = new float[3]; +// +// public Track fit(List VTCrosses, +// SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, +// Swim swimmer) { +// double chisqMax = Double.POSITIVE_INFINITY; +// Collections.sort(VTCrosses); +// Track cand = null; +// HelicalTrackFitter fitTrk = new HelicalTrackFitter(); +// for (int i = 0; i < fitIter; i++) { +// // if(originConstraint==true) { +// // X.add(0, (double) 0); +// // Y.add(0, (double) 0); +// // Z.add(0, (double) 0); +// // Rho.add(0, (double) 0); +// // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); +// // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); +// // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); +// // } +// X.clear(); +// Y.clear(); +// Z.clear(); +// Rho.clear(); +// ErrZ.clear(); +// ErrRho.clear(); +// ErrRt.clear(); +// +// int svtSz = 0; +// int bmtZSz = 0; +// int bmtCSz = 0; +// +// BMTCrossesC.clear(); +// BMTCrossesZ.clear(); +// SVTCrosses.clear(); +// +// for (Cross c : VTCrosses) { +// if (c.get_Detector()==DetectorType.BST) { +// SVTCrosses.add(c); +// } +// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { +// BMTCrossesC.add(c); +// } +// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { +// BMTCrossesZ.add(c); +// } +// } +// svtSz = SVTCrosses.size(); +// if (BMTCrossesZ != null) { +// bmtZSz = BMTCrossesZ.size(); +// } +// if (BMTCrossesC != null) { +// bmtCSz = BMTCrossesC.size(); +// } +// +// int useSVTdipAngEst = 1; +// if (bmtCSz >= 2) { +// useSVTdipAngEst = 0; +// } +// +// ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); +// ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); +// ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); +// ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination +// ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); +// +// cand = new Track(null); +// cand.addAll(SVTCrosses); +// for (int j = 0; j < SVTCrosses.size(); j++) { +// X.add(j, SVTCrosses.get(j).get_Point().x()); +// Y.add(j, SVTCrosses.get(j).get_Point().y()); +// if (useSVTdipAngEst == 1) { +// Z.add(j, SVTCrosses.get(j).get_Point().z()); +// Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() +// + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); +// ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() +// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); +// ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); +// } +// ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() +// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); +// } +// +// if (bmtZSz > 0) { +// for (int j = svtSz; j < svtSz + bmtZSz; j++) { +// X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); +// Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); +// ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() +// + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); +// } +// } +// if (bmtCSz > 0) { +// for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { +// Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); +// Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); +// +// ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); +// ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); +// } +// } +// X.add((double) Constants.getXb()); +// Y.add((double) Constants.getYb()); +// +// ErrRt.add((double) 0.1); +// +// fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); +// +// if (fitTrk.get_helix() == null) { +// return null; +// } +// +// cand = new Track(fitTrk.get_helix()); +// //cand.addAll(SVTCrosses); +// cand.addAll(SVTCrosses); +// cand.addAll(BMTCrossesC); +// cand.addAll(BMTCrossesZ); +// +// swimmer.BfieldLab(0, 0, 0, b); +// double Bz = Math.abs(b[2]); +// fitTrk.get_helix().B = Bz; +// cand.set_HelicalTrack(fitTrk.get_helix()); +// if( X.size()>3 ) { +// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]/(X.size()-3)); +// } +// else { +// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]*2); // penalize tracks with only 3 crosses +// } +// +// if( Z.size() > 2 ) { +// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]/Z.size()); +// } +// else { +// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses +// } +// cand.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); +// cand.setNDF(X.size()+Z.size()); +// //if(shift==0) +// if (fitTrk.get_chisq()[0] < chisqMax) { +// chisqMax = fitTrk.get_chisq()[0]; +// if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) +//// cand=null; +// return cand; +// } } From b0f46fc43c96192617076df3274df99002f7db4d Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 5 Nov 2021 00:54:14 +0100 Subject: [PATCH 208/291] updated version number in clas-tracking pom --- common-tools/clas-tracking/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-tracking/pom.xml b/common-tools/clas-tracking/pom.xml index cba0d54e4..4a9d7b0ee 100644 --- a/common-tools/clas-tracking/pom.xml +++ b/common-tools/clas-tracking/pom.xml @@ -3,14 +3,14 @@ 4.0.0 org.jlab.clas clas-tracking - 6.6.4-SNAPSHOT + 7.0.0-SNAPSHOT jar org.jlab.clas clas12rec ../../parent/pom.xml - 6.6.4-SNAPSHOT + 7.0.0-SNAPSHOT From de449e10c59150937ff0acae7dd0199350388a01 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 5 Nov 2021 00:56:21 +0100 Subject: [PATCH 209/291] updated version number in clas-tracking pom --- common-tools/clas-tracking/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-tracking/pom.xml b/common-tools/clas-tracking/pom.xml index 4a9d7b0ee..936ffd117 100644 --- a/common-tools/clas-tracking/pom.xml +++ b/common-tools/clas-tracking/pom.xml @@ -35,7 +35,7 @@ org.jlab.clas swim-tools - 6.6.4-SNAPSHOT + 7.0.0-SNAPSHOT jar From e2ba86b89b6b42a82fac8dd1953bd97c51d4d2f0 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 5 Nov 2021 01:00:52 +0100 Subject: [PATCH 210/291] updated cvt pom file --- reconstruction/cvt/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/pom.xml b/reconstruction/cvt/pom.xml index 4859a7ce6..519ce31a8 100644 --- a/reconstruction/cvt/pom.xml +++ b/reconstruction/cvt/pom.xml @@ -127,7 +127,7 @@ org.jlab.clas clas-tracking - 6.6.4-SNAPSHOT + 7.0.0-SNAPSHOT From 9e7a166635c4ce9d1ea6902f3daaf19f14dca5ea Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 5 Nov 2021 01:04:33 +0100 Subject: [PATCH 211/291] updated version number in coat-lib pom --- common-tools/coat-lib/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/coat-lib/pom.xml b/common-tools/coat-lib/pom.xml index 120adda52..db10b2315 100644 --- a/common-tools/coat-lib/pom.xml +++ b/common-tools/coat-lib/pom.xml @@ -166,7 +166,7 @@ org.jlab.clas clas-tracking - 6.6.4-SNAPSHOT + 7.0.0-SNAPSHOT 0 + for (String value : values) { + Constants.getLayersUsed().put(Integer.valueOf(value), 0); // layer excluded --->0 + } } } if (exLys==null) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 57576f0a0..b194d7e2c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -1,11 +1,9 @@ package org.jlab.rec.cvt.services; -//import Jama.Matrix; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.straight.KFitter; -import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.detector.base.DetectorType; import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.geom.base.Detector; @@ -35,7 +33,7 @@ public class CosmicTracksRec { - private RecUtilities recUtil = new RecUtilities(); + private final RecUtilities recUtil = new RecUtilities(); public boolean processEvent(DataEvent event, List SVThits, List BMThits, @@ -44,28 +42,28 @@ public boolean processEvent(DataEvent event, SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, - double zShift, boolean exLayrs, Swim swimmer) { + boolean exLayrs, Swim swimmer) { // make list of crosses consistent with a track candidate using SVT only first StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, BMTGeom, 3); - if (crosslist == null || crosslist.size() == 0) { + if (crosslist == null || crosslist.isEmpty()) { // create the clusters and fitted hits banks - rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, zShift); + rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); return true; } // refit track based on SVT only and then add BMT and refit again TrackCandListFinder trkcandFinder = new TrackCandListFinder(); List cosmics = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); - List trkcands = new ArrayList(); + List trkcands = new ArrayList<>(); //REMOVE THIS //crosses.get(0).addAll(crosses.get(1)); //------------------------ - if (cosmics.size() == 0) { + if (cosmics.isEmpty()) { recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; - rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, zShift); + rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); return true; } @@ -101,8 +99,8 @@ public boolean processEvent(DataEvent event, } recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; //4) --- write out the banks - List bmtCrosses = new ArrayList(); - List bmtCrossesRm = new ArrayList(); + List bmtCrosses = new ArrayList<>(); + List bmtCrossesRm = new ArrayList<>(); KFitter kf = null; @@ -127,9 +125,9 @@ public boolean processEvent(DataEvent event, // kf.filterOn=false; kf.runFitter(swimmer); Map traj = kf.TrjPoints; - List keys = new ArrayList(); + List keys = new ArrayList<>(); traj.forEach((key,value) -> keys.add(key)); - List trkTraj = new ArrayList(); + List trkTraj = new ArrayList<>(); traj.forEach((key,value) -> trkTraj.add(value)); Ray the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); @@ -172,7 +170,7 @@ public boolean processEvent(DataEvent event, //refit adding missing clusters List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmics.get(k1), SVTGeom); if(clsOnTrack.size()>0) { - List pseudoCrosses = new ArrayList(); + List pseudoCrosses = new ArrayList<>(); for(Cluster cl : clsOnTrack) { cl.set_AssociatedTrackID(k1 + 1); //make pseudo-cross @@ -197,9 +195,9 @@ public boolean processEvent(DataEvent event, kf.runFitter(swimmer); Map traj2 = kf.TrjPoints; - List keys2 = new ArrayList(); + List keys2 = new ArrayList<>(); traj2.forEach((key,value) -> keys2.add(key)); - List trkTraj2 = new ArrayList(); + List trkTraj2 = new ArrayList<>(); traj2.forEach((key,value) -> trkTraj2.add(value)); the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); @@ -242,7 +240,7 @@ public boolean processEvent(DataEvent event, } - rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, cosmics, 0); + rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, cosmics); } return true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 11749b1a8..f1bb7291e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -32,8 +32,8 @@ * @author ziegler */ public class TracksFromTargetRec { - private StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); - private RecUtilities recUtil = new RecUtilities(); + private final StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); + private final RecUtilities recUtil = new RecUtilities(); public boolean processEvent(DataEvent event, List SVThits, List BMThits, @@ -42,7 +42,6 @@ public boolean processEvent(DataEvent event, SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, - double shift, Swim swimmer, boolean isSVTonly, boolean exLayrs) { @@ -78,7 +77,7 @@ public boolean processEvent(DataEvent event, } if(seeds ==null || seeds.size() == 0) { recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; - rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, null, shift); + rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, null); return true; } @@ -122,7 +121,7 @@ public boolean processEvent(DataEvent event, kf = new KFitter( hlx, cov, event, swimmer, Constants.getXb(), Constants.getYb(), - shift, + 0, recUtil.setMeasVecs(seed, swimmer)) ; kf.setMatrixLibrary(Constants.kfMatLib); //Uncomment to let track be fitted @@ -166,10 +165,10 @@ public boolean processEvent(DataEvent event, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); kf = new KFitter( hlx, cov, event, swimmer, - Constants.getXb(), - Constants.getYb(), - shift, - recUtil.setMeasVecs(seed, swimmer)) ; + Constants.getXb(), + Constants.getYb(), + 0, + recUtil.setMeasVecs(seed, swimmer)) ; kf.setMatrixLibrary(Constants.kfMatLib); //Uncomment to let track be fitted //kf.filterOn = false; @@ -203,7 +202,8 @@ public boolean processEvent(DataEvent event, if(!trkcands.isEmpty()) { // do a final cleanup TrackListFinder.removeOverlappingTracks(trkcands); - // TrackListFinder.checkForOverlaps(trkcands, "KF"); + if(trkcands.isEmpty()) System.out.println("Error: no tracks left after overlap remover"); + tracks = TrackListFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); // update crosses and clusters on track for(int it = 0; it < tracks.size(); it++) { @@ -225,7 +225,7 @@ public boolean processEvent(DataEvent event, // if (tracks.size() > 0) { // recUtil.CleanupSpuriousCrosses(crosses, tracks, SVTGeom) ; // } - rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, seeds, tracks, shift); + rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, seeds, tracks); return true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 4bed76daf..1aaf6bd1f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -284,10 +284,8 @@ else if(Math.abs(this.get_helix().get_Z0()) > Constants.ZRANGE) public boolean betterThan(Track o) { if(this.getNDF()>o.getNDF()) return true; - else if(this.getNDF()>0 && this.getNDF()==o.getNDF()) { - if(this.getChi2()/this.getNDF() < o.getChi2()/o.getNDF()) - return true; - else return false; + else if(this.getNDF()==o.getNDF()) { + return this.getChi2()/this.getNDF() < o.getChi2()/o.getNDF(); } else return false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index b3f836a80..2064bf7f5 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -58,7 +58,7 @@ public double get_dca() { return _dca; } - public void set_dca(double dca) { + public final void set_dca(double dca) { this._dca = dca; } @@ -66,7 +66,7 @@ public double get_phi_at_dca() { return _phi_at_dca; } - public void set_phi_at_dca(double phi_at_dca) { + public final void set_phi_at_dca(double phi_at_dca) { this._phi_at_dca = phi_at_dca; } @@ -74,7 +74,7 @@ public double get_curvature() { return _curvature; } - public void set_curvature(double curvature) { + public final void set_curvature(double curvature) { this._curvature = curvature; } @@ -82,7 +82,7 @@ public double get_Z0() { return _Z0; } - public void set_Z0(double Z0) { + public final void set_Z0(double Z0) { this._Z0 = Z0; } @@ -90,7 +90,7 @@ public double get_tandip() { return _tandip; } - public void set_tandip(double tandip) { + public final void set_tandip(double tandip) { this._tandip = tandip; } @@ -98,7 +98,7 @@ public double[][] get_covmatrix() { return _covmatrix; } - public void set_covmatrix(double[][] covmatrix) { + public final void set_covmatrix(double[][] covmatrix) { this._covmatrix = covmatrix; } @@ -205,8 +205,7 @@ private double ArcLength(double xcenter, double ycenter, double circrad, double } public int get_charge() { - int charge = 0; - charge = (int) Math.signum(_curvature); + int charge = (int) Math.signum(_curvature); return charge; } From 063fe13c766fe747e5a37a358542a052fb0a7453 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 29 Nov 2021 18:44:18 -0500 Subject: [PATCH 222/291] Fix trkId =0 for BMT clusters. --- .../java/org/jlab/rec/cvt/services/TracksFromTargetRec.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 11749b1a8..5d18229c7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -193,6 +193,9 @@ public boolean processEvent(DataEvent event, for(Cluster c : SVTclusters) { c.set_AssociatedTrackID(-1); } + for(Cluster c : BMTclusters) { + c.set_AssociatedTrackID(-1); + } // if (trkcands.isEmpty()) { // recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; // rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, seeds, null, shift); From fbfee321e4086b9e6c01540461de4093825df346 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 2 Dec 2021 12:27:52 -0500 Subject: [PATCH 223/291] Fix empty trajectories. --- .../rec/cvt/trajectory/TrajectoryFinder.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index ae73814c3..37486c9be 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -118,18 +118,26 @@ public Trajectory findTrajectory(Track trk, // initialize swimmer starting from the track vertex double maxPathLength = 1; - swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().ydca()+Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, - Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - trk.get_P(), trk.get_Q(), maxPathLength) ; + //swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().xdca()+Constants.getXb()) / 10, trk.get_helix().get_Z0() / 10, + // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), + // trk.get_P(), trk.get_Q(), maxPathLength) ; + double pz = trk.get_Pt()*trk.get_helix().get_tandip(); + double px = trk.get_Pt()*Math.cos(trk.get_helix().get_phi_at_dca()); + double py = trk.get_Pt()*Math.sin(trk.get_helix().get_phi_at_dca()); + double x = (trk.get_helix().xdca()+Constants.getXb()) / 10; + double y = (trk.get_helix().xdca()+Constants.getXb()) / 10; + double z = trk.get_helix().get_Z0() / 10; + swimmer.SetSwimParameters(x,y,z,px,py,pz, trk.get_Q()) ; + double[] inters = null; double path = 0; // SVT for (int l = 0; l < SVTGeometry.NLAYERS; l++) { // reinitilize swimmer from last surface if(inters!=null) { - double intersPhi = Math.atan2(inters[4], inters[3]); - double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; + //double intersPhi = Math.atan2(inters[4], inters[3]); + //double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], inters[3], inters[4], inters[5], trk.get_Q()) ; } int layer = l + 1; int sector = Sectors[l]; @@ -139,7 +147,7 @@ public Trajectory findTrajectory(Track trk, Vector3D n = svt_geo.getNormal(layer, sector); Point3D p = svt_geo.getModule(layer, sector).origin(); Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); - inters = swimmer.SwimPlane(n, pm, Constants.SWIMACCURACYSVT/10); + inters = swimmer.SwimPlane(n, pm, Constants.SWIMACCURACYSVT/10); if(inters==null) break; path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); From 40591a9e1d5dfd5909e4eff7c57777da3553636f Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 2 Dec 2021 19:05:13 -0500 Subject: [PATCH 224/291] Fix trajectories. --- .../main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 37486c9be..387ac29b7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -125,7 +125,7 @@ public Trajectory findTrajectory(Track trk, double px = trk.get_Pt()*Math.cos(trk.get_helix().get_phi_at_dca()); double py = trk.get_Pt()*Math.sin(trk.get_helix().get_phi_at_dca()); double x = (trk.get_helix().xdca()+Constants.getXb()) / 10; - double y = (trk.get_helix().xdca()+Constants.getXb()) / 10; + double y = (trk.get_helix().ydca()+Constants.getYb()) / 10; double z = trk.get_helix().get_Z0() / 10; swimmer.SetSwimParameters(x,y,z,px,py,pz, trk.get_Q()) ; From bffd0f4cb75d18d9117ef9c38487717d89fcd368 Mon Sep 17 00:00:00 2001 From: raffaelladevita Date: Wed, 10 Nov 2021 23:14:37 +0100 Subject: [PATCH 225/291] extending the droBanks option to EngineProcessor(recon-util) (#730) Co-authored-by: Nathan Baltzell --- .../org/jlab/clas/reco/EngineProcessor.java | 3 +++ .../jlab/clas/reco/ReconstructionEngine.java | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java index 7d4ba3c61..83ada2ba7 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java @@ -219,6 +219,9 @@ public void processEvent(DataEvent event){ JsonUtils.extend(event, ReconstructionEngine.CONFIG_BANK_NAME, "json", engine.getValue().generateConfig()); } + if (engine.getValue().dropOutputBanks) { + engine.getValue().dropBanks(event); + } engine.getValue().processDataEvent(event); } catch (Exception e){ diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java index bdcfd567e..224437fcc 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java @@ -48,7 +48,7 @@ public abstract class ReconstructionEngine implements Engine { volatile boolean wroteConfig = false; - private boolean dropOutputBanks = false; + volatile boolean dropOutputBanks = false; private final Set outputBanks = new HashSet(); String engineName = "UnknownEngine"; @@ -282,6 +282,15 @@ public Map generateConfig() { return ret; } + public void dropBanks(DataEvent event) { + for (String bankName : this.outputBanks) { + if (event.hasBank(bankName)) { + event.removeBank(bankName); + } + } + } + + @Override public EngineData execute(EngineData input) { @@ -314,18 +323,14 @@ public EngineData execute(EngineData input) { output.setDescription(msg); return output; } - + try { if (!this.wroteConfig) { this.wroteConfig = true; JsonUtils.extend(dataEventHipo, CONFIG_BANK_NAME, "json", this.generateConfig()); } if (this.dropOutputBanks) { - for (String bankName : this.outputBanks) { - if (dataEventHipo.hasBank(bankName)) { - dataEventHipo.removeBank(bankName); - } - } + this.dropBanks(dataEventHipo); } this.processDataEvent(dataEventHipo); output.setData(mt, dataEventHipo.getHipoEvent()); From b716bee6eddf92b25e827fdd35f8a708301fe4cb Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 6 Dec 2021 15:16:19 -0500 Subject: [PATCH 226/291] add line to force the torus and solenoid field to zero in cosmic track reconstruction --- .../main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index b194d7e2c..56df1eac8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -26,6 +26,8 @@ import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; + +import cnuphys.magfield.MagneticFields; /** * * @author ziegler @@ -43,7 +45,8 @@ public boolean processEvent(DataEvent event, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, boolean exLayrs, Swim swimmer) { - + MagneticFields.getInstance().getSolenoid().setScaleFactor(1e-7); + MagneticFields.getInstance().getTorus().setScaleFactor(1e-7); // make list of crosses consistent with a track candidate using SVT only first StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, From 5d0ed5879c86200a44eab2da08d453316cefb32d Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 6 Dec 2021 15:21:37 -0500 Subject: [PATCH 227/291] a few minor changes... default doca cut for non cosmics is 10 mm; require the number of SVT crosses + BMTZ hits to be at least 3; SVT crosses + BMTC clusters must also be at least 3. --- .../jlab/rec/cvt/services/CVTAlignment.java | 68 ++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 56acef838..9dc8053a5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -32,6 +32,7 @@ import Jama.Matrix; //import eu.mihosoft.vrl.v3d.Vector3d; +import cnuphys.magfield.MagneticFields; /** * Service to return reconstructed TRACKS @@ -144,6 +145,9 @@ public void setFieldsConfig(String fieldsConfig) { int gCountBMTZ =0; int debugPrintEventCount = 0; + //check if there are multiple hits in the same BMTC tile (can happen sometimes in cosmic tracks) + //boolean checkClusterAmbiguityBMTC = true; + @Override public boolean processDataEvent(DataEvent event) { int runNum = event.getBank("RUN::config").getInt("run", 0); @@ -238,6 +242,10 @@ public boolean processDataEvent(DataEvent event) { if(countBMTCMath.PI) delta_phi_plus-=2*Math.PI; @@ -721,6 +729,21 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, delta_phi_plus+=2*Math.PI; double delta_phi_minus=extrap_minus.phi()-phi_mid; + while (delta_phi_minus >Math.PI) + delta_phi_minus-=2*Math.PI; + while (delta_phi_minus <-Math.PI) + delta_phi_minus+=2*Math.PI;*/ + /*double phi_n = cl.getN().phi(); + System.out.println("phi_recon="+ phi_n); + System.out.println("phi_+="+ extrap_plus.phi()); + System.out.println("phi_-="+ extrap_minus.phi()); + double delta_phi_plus=extrap_plus.phi()-phi_n; + while (delta_phi_plus >Math.PI) + delta_phi_plus-=2*Math.PI; + while (delta_phi_plus <-Math.PI) + delta_phi_plus+=2*Math.PI; + + double delta_phi_minus=extrap_minus.phi()-phi_n; while (delta_phi_minus >Math.PI) delta_phi_minus-=2*Math.PI; while (delta_phi_minus <-Math.PI) @@ -728,6 +751,13 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, if(Math.abs(delta_phi_plus) Date: Tue, 7 Dec 2021 11:56:35 +0100 Subject: [PATCH 228/291] SVT geometry: fixed signed of ra rotation for inverse transform --- .../detector/geant4/v2/SVT/AlignmentFactory.java | 2 +- .../jlab/detector/geant4/v2/SVT/SVTConstants.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java index c672f84c0..0ac6c5c33 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java @@ -416,7 +416,7 @@ public static void applyInverseShift( Vector3d aPoint, double[] aShift, Vector3d if(Math.abs(ra) >1E-5) { Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); - vecAxis.rotate( aPoint, ra ); + vecAxis.rotate( aPoint, -ra ); } // if ra==0, assume rx,ry,rz are the rotation angles around the 3 axis else if(ra==0) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index e3fc95fdb..000643dbd 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -402,7 +402,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table double ypos = cp.getDouble(ccdbPath+"position/y", 0 ); double zpos = cp.getDouble(ccdbPath+"position/z", 0 ); - double[] myShift = {0, 0, 0, -Math.toRadians(0), 0, 0, 0}; +// double[] myShift = {0, 0, 0, -Math.toRadians(0), 0, 0, 0}; LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { @@ -420,11 +420,11 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table ty += ypos; tz += zpos; LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; - if (layer == 1 || layer == 2 || true) { - for(int j=0; j Date: Tue, 7 Dec 2021 12:02:58 +0100 Subject: [PATCH 229/291] SVT geometry: fixed signed of ra rotation for inverse transform --- .../detector/geant4/v2/SVT/AlignmentFactory.java | 4 ++-- .../jlab/detector/geant4/v2/SVT/SVTConstants.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java index c672f84c0..defe2dc55 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/AlignmentFactory.java @@ -416,7 +416,7 @@ public static void applyInverseShift( Vector3d aPoint, double[] aShift, Vector3d if(Math.abs(ra) >1E-5) { Vector3d vecAxis = new Vector3d( rx, ry, rz ).normalized(); - vecAxis.rotate( aPoint, ra ); + vecAxis.rotate( aPoint, -ra ); } // if ra==0, assume rx,ry,rz are the rotation angles around the 3 axis else if(ra==0) @@ -516,4 +516,4 @@ public static void applyShift( Geant4Basic aVol, double[] aShift, Vector3d aNomi System.out.println("vector "+i+" matrix rotated"); Matrix.matMul( rotMatrix, new Matrix(3, 1, Util.toDoubleArray( vr[i] ) ) ).show(); }*/ } -} \ No newline at end of file +} diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index e3fc95fdb..000643dbd 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -402,7 +402,7 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table double ypos = cp.getDouble(ccdbPath+"position/y", 0 ); double zpos = cp.getDouble(ccdbPath+"position/z", 0 ); - double[] myShift = {0, 0, 0, -Math.toRadians(0), 0, 0, 0}; +// double[] myShift = {0, 0, 0, -Math.toRadians(0), 0, 0, 0}; LAYERSHIFTDATA = new double[NSECTORS[3]][NLAYERS-2][]; for( int i = 0; i < (NTOTALSECTORS-NSECTORS[3])*2; i++ ) // layeralignment tables doesn't cover region 4 { @@ -420,11 +420,11 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table ty += ypos; tz += zpos; LAYERSHIFTDATA[sector-1][layer-1] = new double[]{ tx, ty, tz, rx, ry, rz, ra }; - if (layer == 1 || layer == 2 || true) { - for(int j=0; j Date: Tue, 7 Dec 2021 16:55:39 -0500 Subject: [PATCH 230/291] Functionality to remove or add beam spot constraint in track fitting. --- .../main/java/org/jlab/rec/cvt/Constants.java | 2 ++ .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 2 +- .../org/jlab/rec/cvt/fit/CircleFitter.java | 17 ++++++------ .../jlab/rec/cvt/services/CVTRecNewKF.java | 17 ++++++++++++ .../jlab/rec/cvt/services/RecUtilities.java | 26 +++++++++++++++++++ .../rec/cvt/services/TracksFromTargetRec.java | 6 +++++ 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 2c2996f7a..bd000e435 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -41,6 +41,8 @@ public class Constants { private static boolean SVTOnly = false; public static final boolean trk_comesfrmOrig = true; + + public static boolean beamSpotConstraint = false; public static boolean areConstantsLoaded = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 69177072a..4418a429b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -304,7 +304,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double eyb = dbprovider.getDouble("/geometry/beam/position/y_error", 0); double err = 0; if(Math.sqrt(xb*xb+yb*yb)!=0) err = Math.sqrt((Math.pow(xb*exb,2)+Math.pow(yb*eyb,2))/(xb*xb+yb*yb)); - + //xb= 0.1947; yb= -0.1943; Constants.setXb(xb*10); Constants.setYb(yb*10); Constants.setRbErr(err*10); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index fc72b61f0..f12a3d11c 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -283,16 +283,15 @@ void propagatePars(double xr, double yr, double x, double y, double cosphi, doub double Vp_phiphi = JVJT[1][1]; double Vp_phid = JVJT[1][2]; double Vp_dd = JVJT[2][2]; - //3. Fill the covariance matrix - /* - _covr[0] = Vp_rhorho; - _covr[1] = Vp_rhophi; - _covr[2] = Vp_rhod; - _covr[3] = Vp_phiphi; - _covr[4] = Vp_phid; - _covr[5] = Vp_dd; - */ + if(Constants.beamSpotConstraint) { + _covr[0] = Vp_rhorho; + _covr[1] = Vp_rhophi; + _covr[2] = Vp_rhod; + _covr[3] = Vp_phiphi; + _covr[4] = Vp_phid; + _covr[5] = Vp_dd; + } // new params _phi = Math.atan2(B, C); _dca = A / (1. + U); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index d46eb1043..0577e8570 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -230,6 +230,23 @@ public boolean init() { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); } //svt stand-alone + String beamSpotConst = this.getEngineConfigString("BeamSpotConst"); + + if (beamSpotConst!=null) { + System.out.println("["+this.getName()+"] run with beamSpotConst settings "+beamSpotConst+" config chosen based on yaml"); + Constants.beamSpotConstraint = Boolean.valueOf(beamSpotConst); + } + else { + beamSpotConst = System.getenv("COAT_CVT_BEAMSPOTCONST"); + if (beamSpotConst!=null) { + System.out.println("["+this.getName()+"] run with beamSpotConst settings "+beamSpotConst+" config chosen based on env"); + this.isCosmic= Boolean.valueOf(beamSpotConst); + Constants.beamSpotConstraint = Boolean.valueOf(beamSpotConst); + } + } + if (beamSpotConst==null) { + System.out.println("["+this.getName()+"] run with beamSpotConst settings default = false"); + } String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index b389168c1..1d3136460 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -36,6 +36,8 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.cross.CrossMaker; +import org.jlab.rec.cvt.fit.CircleFitPars; +import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -639,6 +641,30 @@ public List reFitSeed(Seed bseed, seedlist.addAll(trseed.findSeed(refi, refib, SVTGeom, BMTGeom, false)); return seedlist; } + public void reFitCircle(Seed mseed) { + List Xs = new ArrayList() ; + List Ys = new ArrayList() ; + List Ws = new ArrayList() ; + List seedcrs = mseed.get_Crosses(); + for (int j = 0; j < seedcrs.size(); j++) { + if (seedcrs.get(j).get_Type() == BMTType.C) + continue; + + Xs.add(seedcrs.get(j).get_Point().x()); + Ys.add(seedcrs.get(j).get_Point().y()); + Ws.add(1. / (seedcrs.get(j).get_PointErr().x()*seedcrs.get(j).get_PointErr().x() + +seedcrs.get(j).get_PointErr().y()*seedcrs.get(j).get_PointErr().y())); + + } + CircleFitter circlefit = new CircleFitter(); + boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); + CircleFitPars pars = circlefit.getFit(); + if(pars.rho()!=0) { + mseed.get_Helix().set_curvature(pars.rho()); + } + mseed.get_Helix().set_dca(pars.doca()); + mseed.get_Helix().set_phi_at_dca(pars.phi()); + } public List reFit(List seedlist, SVTGeometry SVTGeom, BMTGeometry BMTGeom, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 3f6c2b406..1320ebc71 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -73,6 +73,11 @@ public boolean processEvent(DataEvent event, if(exLayrs==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); } + if(Constants.beamSpotConstraint) { + for(Seed s : seeds) { + recUtil.reFitCircle(s); + } + } } } if(seeds ==null || seeds.size() == 0) { @@ -155,6 +160,7 @@ public boolean processEvent(DataEvent event, } } //reset pars + fittedTrack.get_helix().set_dca(-fittedTrack.get_helix().get_dca()); v = fittedTrack.get_helix().getVertex(); p = fittedTrack.get_helix().getPXYZ(solenoidValue); charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); From efc1122aa681a91d2962504d95faa2b13bee7cce Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Tue, 7 Dec 2021 17:04:46 -0500 Subject: [PATCH 231/291] Functionality to remove or add beam spot constraint in track fitting. Setting def for YAML --- .../cvt/src/main/java/org/jlab/rec/cvt/Constants.java | 2 +- .../cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java | 2 +- .../java/org/jlab/rec/cvt/services/TracksFromTargetRec.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index bd000e435..b83ad7a12 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -42,7 +42,7 @@ public class Constants { public static final boolean trk_comesfrmOrig = true; - public static boolean beamSpotConstraint = false; + public static boolean beamSpotConstraint = true; public static boolean areConstantsLoaded = false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index f12a3d11c..fdd1cf58e 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -284,7 +284,7 @@ void propagatePars(double xr, double yr, double x, double y, double cosphi, doub double Vp_phid = JVJT[1][2]; double Vp_dd = JVJT[2][2]; //3. Fill the covariance matrix - if(Constants.beamSpotConstraint) { + if(Constants.beamSpotConstraint==false) { _covr[0] = Vp_rhorho; _covr[1] = Vp_rhophi; _covr[2] = Vp_rhod; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 1320ebc71..0d46f3162 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -73,7 +73,7 @@ public boolean processEvent(DataEvent event, if(exLayrs==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); } - if(Constants.beamSpotConstraint) { + if(Constants.beamSpotConstraint==false) { for(Seed s : seeds) { recUtil.reFitCircle(s); } From 685535f648f1268894b2a144ddbbda2dc94ae679 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Wed, 8 Dec 2021 13:53:41 -0500 Subject: [PATCH 232/291] changes to beamspot in output for KAA --- .../jlab/rec/cvt/services/CVTAlignment.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 9dc8053a5..1d6941ec5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -293,14 +293,14 @@ public boolean processDataEvent(DataEvent event) { if(useNewFillMatrices) { if(cross.get_Detector() == DetectorType.BST){ Cluster cl1 = cross.get_Cluster1(); - boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,DetectorType.BST,null,debug); + boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,debug,false); i++; if(!ok) { //reject track if there's a cluster with really bad values. if(debug) System.out.println("rejecting track due to problem in an SVT layer"); continue tracksLoop; } Cluster cl2 = cross.get_Cluster2(); - ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,DetectorType.BST,null,debug); + ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,debug,false); i++; if(!ok) { //reject track if there's a cluster with really bad values. if(debug) System.out.println("rejecting track due to problem in an SVT layer"); @@ -310,7 +310,7 @@ public boolean processDataEvent(DataEvent event) { Cluster cl1 = cross.get_Cluster1(); boolean ok = true; if(cl1.get_Type() == BMTType.Z || !skipBMTC){ - ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, cl1.get_Detector(), cl1.get_Type(), this.debug); + ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, this.debug, false); } i++; if(!ok) { //reject track if there's a cluster with really bad values. @@ -369,7 +369,23 @@ else if(cross.get_DetectorType() == BMTType.C) { } if(!isCosmics && includeBeamspot) { - fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); + //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); + + + //pseudo cluster for the beamspot + Cluster cl1 = new Cluster(null, null, 0, 0, 0); + cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); + + Vector3D n = ray.get_dirVec(); + Vector3D l = new Vector3D(0,0,1); + cl1.setN(n); + cl1.setL(l); + cl1.setS(n.cross(l)); + cl1.set_Resolution(0.1); + + fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); + + } As.add(A); @@ -501,6 +517,7 @@ private void fillMisc(DataEvent event, int runNum, int eventNum, List t boolean includeBeamspot = false; private double minCosIncident = Math.cos(75*Math.PI/180); private double spMax = 10; + private final static double indexBeamspot = 102; private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I, double xb, double yb){ // a point along the beam @@ -637,7 +654,7 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix * @return */ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, - Matrix c, Matrix I, DetectorType detector, BMTType bmtType, boolean debug) { + Matrix c, Matrix I, boolean debug, boolean isBeamspot) { int layer = cl.get_Layer(); int sector = cl.get_Sector(); //System.out.println("RLS " + region + " " + layer + " " + sector); @@ -652,6 +669,9 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, System.out.println("prelim phi is " + phi + " sector= ="+cl.get_Sector()); }*/ + + DetectorType detector = cl.get_Detector(); + BMTType bmtType = cl.get_Type(); if(debug) { System.out.println("\n\nNew method " + detector + " layer " + layer + " sector " + sector); @@ -675,7 +695,7 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, //Vector3d e1 = cl.getX Vector3D e = null; Vector3D extrap = null; - if(detector == DetectorType.BST || detector == DetectorType.BMT && bmtType==BMTType.Z) { + if(detector == DetectorType.BST || (detector == DetectorType.BMT && bmtType==BMTType.Z) || isBeamspot) { l = cl.getL(); s = cl.getS(); n = cl.getN(); @@ -878,9 +898,10 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, if(detector == DetectorType.BST) I.set(i, 0, getIndexSVT(layer-1,sector-1)); - if(detector == DetectorType.BMT) + else if(detector == DetectorType.BMT) I.set(i, 0, getIndexBMT(layer-1,sector-1)); - + else + I.set(i, 0, indexBeamspot ); Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); if(!this.useDocaPhiZTandip) { B.set(i,0, -sp.x()); @@ -1627,7 +1648,7 @@ public boolean init() { } - this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (includeBeamspot? 0 : 1)); + this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (includeBeamspot? 1 : 0)); String debug = this.getEngineConfigString("debug"); From 7c85117afedcdacbaaa8abcd30c20632dc37a93a Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Wed, 8 Dec 2021 16:11:06 -0500 Subject: [PATCH 233/291] beamspot resolution to 600 um --- .../src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 1d6941ec5..f2c2f6cbd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -381,7 +381,7 @@ else if(cross.get_DetectorType() == BMTType.C) { cl1.setN(n); cl1.setL(l); cl1.setS(n.cross(l)); - cl1.set_Resolution(0.1); + cl1.set_Resolution(0.6); fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); From 20d6a72704599ceba15c7a5647c43ab3ea525f63 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 8 Dec 2021 17:53:46 -0500 Subject: [PATCH 234/291] Use of measurement plane including beam spot in KF --- .../org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 2 +- .../org/jlab/rec/cvt/services/RecUtilities.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 4418a429b..69177072a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -304,7 +304,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) double eyb = dbprovider.getDouble("/geometry/beam/position/y_error", 0); double err = 0; if(Math.sqrt(xb*xb+yb*yb)!=0) err = Math.sqrt((Math.pow(xb*exb,2)+Math.pow(yb*eyb,2))/(xb*xb+yb*yb)); - //xb= 0.1947; yb= -0.1943; + Constants.setXb(xb*10); Constants.setYb(yb*10); Constants.setRbErr(err*10); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 1d3136460..ffe3c195c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -87,13 +87,14 @@ public void CleanupSpuriousCrosses(List> crosses, List t public List setMeasVecs(Seed trkcand, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); - Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), - new Vector3D(0,0,1)); + Vector3D u = trkcand.get_Helix().getTrackDirectionAtRadius(Math.sqrt(Constants.getXb()*Constants.getXb()+Constants.getYb()*Constants.getYb())); + Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), u); Surface meas0 = new Surface(pln0,new Point3D(Constants.getXb(),Constants.getYb(),0), - new Point3D(Constants.getXb()-300,Constants.getYb(),0), new Point3D(Constants.getXb()+300,Constants.getYb(),0), Constants.DEFAULTSWIMACC); + new Point3D(Constants.getXb()-300,Constants.getYb(),0), new Point3D(Constants.getXb()+300,Constants.getYb(),0), + Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); - meas0.setError(1); + meas0.setError(trkcand.get_Helix().get_covmatrix()[0][0]); KFSites.add(meas0); // SVT measurements @@ -135,8 +136,8 @@ public List setMeasVecs(StraightTrack trkcand, if(trkcand.clsMap!=null) trkcand.clsMap.clear(); //VZ: reset cluster map for second pass tracking with isolated SVT clusters //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList(); - Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), - new Vector3D(0,0,1)); + Vector3D u = trkcand.get_ray().get_dirVec(); + Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), u); Surface meas0 = new Surface(pln0,new Point3D(0,0,0), new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); meas0.setSector(0); From 4e3132d8e26bc75898fd2261512568228996f9bf Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 8 Dec 2021 17:54:31 -0500 Subject: [PATCH 235/291] Use of measurement plane including beam spot in KF --- .../clas/tracking/kalmanfilter/AKFitter.java | 2 +- .../clas/tracking/kalmanfilter/AMeasVecs.java | 7 +++- .../kalmanfilter/helical/StateVecs.java | 37 +++++++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index 567760c2d..8d0375e8f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -66,7 +66,7 @@ public void runFitterIter(Swim swimmer, int it, AStateVecs sv, AMeasVecs mv) { } sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), swimmer); - if(k>1) + //if(k>1) this.filter(k - 1, swimmer, -1, sv, mv); } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java index ffb17ece2..935c2656f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -51,7 +51,9 @@ public double dh(int k, StateVec stateVec) { if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); + p.setZ(0); + value = p.distance(stateVec.x, stateVec.y, 0); + } if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { double phia = this.measurements.get(stateVec.k).surface.arc.theta(); @@ -143,7 +145,8 @@ public double h(int k, StateVec stateVec) { if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - value = p.distance(stateVec.x, stateVec.y, stateVec.z); + p.setZ(0); + value = p.distance(stateVec.x, stateVec.y, 0); } if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { double phia = this.measurements.get(stateVec.k).surface.arc.theta(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index aacc63002..e4ff9388c 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -55,11 +55,34 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec kVec.alpha = Bf.alpha; if(k==0) { - value[0] = x; - value[1] = y; - value[2] = z; - value[3] = 0.0; - return value; + //value[0] = x; + //value[1] = y; + //value[2] = z; + //value[3] = 0.0; + double invKappa = 1. / Math.abs(kVec.kappa); + double px = -invKappa * Math.sin(kVec.phi0 ); + double py = invKappa * Math.cos(kVec.phi0 ); + double pz = invKappa * kVec.tanL; + int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); + double accuracy = mv.surface.swimAccuracy/units; + swim.SetSwimParameters(x/units, y/units, z/units, px, py, pz, ch); + swimPars = swim.SwimRho(50./units, accuracy); + if(swimPars==null) + return null; + swim.SetSwimParameters(swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], -ch); + Vector3D norm = new Vector3D(px,py,pz).asUnit(); + Point3D point = new Point3D(mv.surface.plane.point().x()/units, + mv.surface.plane.point().y()/units, + mv.surface.plane.point().z()/units); + swimPars = swim.SwimPlane(norm,point,accuracy); + if(swimPars==null) + return null; + for(int j =0; j < 3; j++) { + swimPars[j]*=units; + } + kVec.x = swimPars[0]; + kVec.y = swimPars[1]; + kVec.z = swimPars[2]; } if(this.straight) { @@ -73,7 +96,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec int ints = mv.surface.plane.intersection(toPln, inters); kVec.x = inters.x() ; kVec.y = inters.y() ; - kVec.z = inters.z() ; + kVec.z = inters.z() ; } else if(mv.surface.cylinder!=null) { @@ -148,7 +171,7 @@ else if(mv.surface.cylinder!=null) { } kVec.x = swimPars[0]; kVec.y = swimPars[1]; - kVec.z = swimPars[2]; + kVec.z = swimPars[2]; } } From 861b5bef9ba48c6bc4859081694259665b4d9ac0 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 8 Dec 2021 18:19:27 -0500 Subject: [PATCH 236/291] Use of measurement plane including beam spot in KF for 0T events --- .../jlab/clas/tracking/kalmanfilter/helical/StateVecs.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index e4ff9388c..3d09873c4 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -54,11 +54,7 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec Bf.set(); kVec.alpha = Bf.alpha; - if(k==0) { - //value[0] = x; - //value[1] = y; - //value[2] = z; - //value[3] = 0.0; + if(k==0 && this.straight==false) { double invKappa = 1. / Math.abs(kVec.kappa); double px = -invKappa * Math.sin(kVec.phi0 ); double py = invKappa * Math.cos(kVec.phi0 ); From 01ce2c14fc55e17da73f6ba02518063087aaca58 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Wed, 8 Dec 2021 20:44:59 -0500 Subject: [PATCH 237/291] Iterate fit to estimate circle parameters without Beam Spot constraint to improve the seed. --- .../jlab/rec/cvt/services/RecUtilities.java | 46 ++++++++++++------- .../rec/cvt/services/TracksFromTargetRec.java | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index ffe3c195c..7fff3bbe8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -642,29 +642,41 @@ public List reFitSeed(Seed bseed, seedlist.addAll(trseed.findSeed(refi, refib, SVTGeom, BMTGeom, false)); return seedlist; } - public void reFitCircle(Seed mseed) { + public void reFitCircle(Seed mseed,SVTGeometry SVTGeom, BMTGeometry BMTGeom, int iter) { List Xs = new ArrayList() ; List Ys = new ArrayList() ; List Ws = new ArrayList() ; - List seedcrs = mseed.get_Crosses(); - for (int j = 0; j < seedcrs.size(); j++) { - if (seedcrs.get(j).get_Type() == BMTType.C) - continue; + List seedcrs = new ArrayList(); - Xs.add(seedcrs.get(j).get_Point().x()); - Ys.add(seedcrs.get(j).get_Point().y()); - Ws.add(1. / (seedcrs.get(j).get_PointErr().x()*seedcrs.get(j).get_PointErr().x() - +seedcrs.get(j).get_PointErr().y()*seedcrs.get(j).get_PointErr().y())); - - } CircleFitter circlefit = new CircleFitter(); - boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); - CircleFitPars pars = circlefit.getFit(); - if(pars.rho()!=0) { - mseed.get_Helix().set_curvature(pars.rho()); + CircleFitPars pars = null; + for(int i = 0; i< iter; i++) { + Xs.clear(); + Ys.clear(); + Ws.clear(); + seedcrs = mseed.get_Crosses(); + + for (int j = 0; j < seedcrs.size(); j++) { + if (seedcrs.get(j).get_Type() == BMTType.C) + continue; + + Xs.add(seedcrs.get(j).get_Point().x()); + Ys.add(seedcrs.get(j).get_Point().y()); + Ws.add(1. / (seedcrs.get(j).get_PointErr().x()*seedcrs.get(j).get_PointErr().x() + +seedcrs.get(j).get_PointErr().y()*seedcrs.get(j).get_PointErr().y())); + + } + + boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); + pars = circlefit.getFit(); + if(pars.rho()!=0) { + mseed.get_Helix().set_curvature(pars.rho()); + } + mseed.get_Helix().set_dca(-pars.doca()); + mseed.get_Helix().set_phi_at_dca(pars.phi()); + + mseed.update_Crosses(SVTGeom, BMTGeom); } - mseed.get_Helix().set_dca(pars.doca()); - mseed.get_Helix().set_phi_at_dca(pars.phi()); } public List reFit(List seedlist, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 0d46f3162..abff46a31 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -75,7 +75,7 @@ public boolean processEvent(DataEvent event, } if(Constants.beamSpotConstraint==false) { for(Seed s : seeds) { - recUtil.reFitCircle(s); + recUtil.reFitCircle(s,SVTGeom, BMTGeom, 5); } } } From eeb2a60114c1df8cc885df27e0a5f72f0b1a9092 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 10 Dec 2021 22:04:15 +0100 Subject: [PATCH 238/291] merged FittedHit functionality in Hit class to be able to write out all hits, added timing cuts on BMT hits, removed env variable in init, code cleanup --- .../org/jlab/clas/reco/io/EvioHipoEvent4.java | 4 +- etc/bankdefs/clas12/BMT.xml | 1 + etc/bankdefs/clas12/FMT.xml | 1 + etc/bankdefs/hipo4/bmt.json | 6 +- etc/bankdefs/hipo4/bst.json | 6 +- .../main/java/org/jlab/rec/cvt/Constants.java | 99 +++---- .../org/jlab/rec/cvt/banks/HitReader.java | 109 ++++---- .../jlab/rec/cvt/banks/RecoBankWriter.java | 18 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 39 ++- .../jlab/rec/cvt/cluster/ClusterFinder.java | 22 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 2 +- .../java/org/jlab/rec/cvt/hit/FittedHit.java | 151 ---------- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 136 +++++++-- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 24 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 263 +++++++----------- .../rec/cvt/services/CosmicTracksRec.java | 10 +- .../jlab/rec/cvt/services/RecUtilities.java | 6 +- .../rec/cvt/services/TracksFromTargetRec.java | 25 +- .../java/org/jlab/rec/cvt/track/Seed.java | 4 +- .../rec/cvt/track/TrackCandListFinder.java | 8 +- .../org/jlab/rec/cvt/trajectory/StateVec.java | 4 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 7 +- 22 files changed, 436 insertions(+), 509 deletions(-) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java index b583f8f42..8acf2ac71 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java @@ -191,7 +191,7 @@ public void fillHipoEventBMT(Event hipoEvent, EvioDataEvent evioEvent){ hipoADC.putByte("layer", i, (byte) evioBank.getInt("layer",i)); hipoADC.putShort("component", i, (short) evioBank.getInt("strip",i)); hipoADC.putInt("ADC", i, (int) evioBank.getInt("ADC",i)); - hipoADC.putFloat("time", i, (float) 0); + hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); hipoADC.putShort("ped", i, (short) 0); } hipoEvent.write(hipoADC); @@ -207,7 +207,7 @@ public void fillHipoEventFMT(Event hipoEvent, EvioDataEvent evioEvent){ hipoADC.putByte("layer", i, (byte) evioBank.getInt("layer",i)); hipoADC.putShort("component", i, (short) evioBank.getInt("strip",i)); hipoADC.putInt("ADC", i, (int) evioBank.getInt("ADC",i)); - hipoADC.putFloat("time", i, (float) 0); + hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); hipoADC.putShort("ped", i, (short) 0); } hipoEvent.write(hipoADC); diff --git a/etc/bankdefs/clas12/BMT.xml b/etc/bankdefs/clas12/BMT.xml index bb72c0305..66c7212a6 100644 --- a/etc/bankdefs/clas12/BMT.xml +++ b/etc/bankdefs/clas12/BMT.xml @@ -34,6 +34,7 @@ + diff --git a/etc/bankdefs/clas12/FMT.xml b/etc/bankdefs/clas12/FMT.xml index 971a8af9d..415a51ef9 100644 --- a/etc/bankdefs/clas12/FMT.xml +++ b/etc/bankdefs/clas12/FMT.xml @@ -35,6 +35,7 @@ + diff --git a/etc/bankdefs/hipo4/bmt.json b/etc/bankdefs/hipo4/bmt.json index ddee7322c..99a5ea45f 100755 --- a/etc/bankdefs/hipo4/bmt.json +++ b/etc/bankdefs/hipo4/bmt.json @@ -9,10 +9,13 @@ {"name":"sector", "type":"B", "info":"hit sector"}, {"name":"layer", "type":"B", "info":"hit layer"}, {"name":"strip", "type":"I", "info":"hit strip"}, + {"name":"energy", "type":"F", "info":"energy"}, + {"name":"time", "type":"F", "info":"time (ns)"}, {"name":"fitResidual", "type":"F", "info":"fitted hit residual"}, {"name":"trkingStat", "type":"I", "info":"tracking status"}, {"name":"clusterID", "type":"S", "info":"associated cluster ID"}, - {"name":"trkID", "type":"S", "info":"associated track ID"} + {"name":"trkID", "type":"S", "info":"associated track ID"}, + {"name":"status", "type":"B", "info":"status (0=good)"} ] }, { @@ -26,6 +29,7 @@ {"name":"layer", "type":"B", "info":"layer"}, {"name":"size", "type":"S", "info":"cluster size"}, {"name":"ETot", "type":"F", "info":"cluster total energy"}, + {"name":"time", "type":"F", "info":"cluster average time"}, {"name":"seedE", "type":"F", "info":"energy of the seed "}, {"name":"seedStrip", "type":"I", "info":"seed strip"}, {"name":"centroid", "type":"F", "info":"centroid strip number"}, diff --git a/etc/bankdefs/hipo4/bst.json b/etc/bankdefs/hipo4/bst.json index 1f362c16f..0f3210b07 100755 --- a/etc/bankdefs/hipo4/bst.json +++ b/etc/bankdefs/hipo4/bst.json @@ -9,10 +9,13 @@ {"name":"sector", "type":"B", "info":"hit sector"}, {"name":"layer", "type":"B", "info":"hit layer"}, {"name":"strip", "type":"I", "info":"hit strip"}, + {"name":"energy", "type":"F", "info":"energy"}, + {"name":"time", "type":"F", "info":"time (ns)"}, {"name":"fitResidual", "type":"F", "info":"fitted hit residual"}, {"name":"trkingStat", "type":"I", "info":"tracking status"}, {"name":"clusterID", "type":"S", "info":"associated cluster ID"}, - {"name":"trkID", "type":"S", "info":"associated track ID"} + {"name":"trkID", "type":"S", "info":"associated track ID"}, + {"name":"status", "type":"B", "info":"status (0=good)"} ] }, { @@ -26,6 +29,7 @@ {"name":"layer", "type":"B", "info":"layer"}, {"name":"size", "type":"S", "info":"cluster size"}, {"name":"ETot", "type":"F", "info":"cluster total energy"}, + {"name":"time", "type":"F", "info":"cluster time"}, {"name":"seedE", "type":"F", "info":"energy of the seed "}, {"name":"seedStrip", "type":"I", "info":"seed strip"}, {"name":"centroid", "type":"F", "info":"centroid strip number"}, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 2c2996f7a..113660c69 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -22,10 +22,11 @@ public class Constants { public static final double LIGHTVEL = 0.000299792458; // velocity of light (mm/ns) - conversion factor from radius in mm to momentum in GeV/c // selection cuts for helical tracks - public static final double PTCUT = 0.075; // minimum pt in GeV + public static final double PTCUT = 0.125; // minimum pt in GeV + public static final double TANDIP = 2; // max value on dip angle public static final double NDFCUT = 0; // minimum number of degres of freedom public static final double CHI2CUT = 50; // minimum chi2 per degrees of freedom - public static final double ZRANGE = 500; // defines z range as -ZRANGE:+ZRANGE in mm + public static final double ZRANGE = 300; // defines z range as -ZRANGE:+ZRANGE in mm public static final int MINSVTCRSFORCOSMIC = 2; public static final double CIRCLEFIT_MAXCHI2 = 100; @@ -34,13 +35,17 @@ public class Constants { public static final double SWIMACCURACYBMT = 0.020; // in mm public static final double SWIMACCURACYCD = 0.500; // in mm - private static boolean isCosmicsData = false; + public static boolean isCosmicsData = false; public static final double COSMICSMINRESIDUALX = 120; // in mm public static final double COSMICSMINRESIDUALZ = 12; // in mm - private static boolean SVTOnly = false; + public static boolean SVTOnly = false; - public static final boolean trk_comesfrmOrig = true; + public static boolean svtSeeding = true; + + public static boolean BMTTimeCuts = true; + + public static final boolean TRACKSFROMORIGIN = true; public static boolean areConstantsLoaded = false; @@ -57,7 +62,10 @@ public class Constants { private static int _rmReg = 0; - private static Map layersUsed = new HashMap(); + public static boolean excludeLayers = false; + private static final Map layersUsed = new HashMap(); + private static final double[][]BMTPhiZRangeExcld = new double[2][2]; + private static int BMTLayerExcld = -1; public static double getXb() { return _Xb; @@ -107,12 +115,40 @@ public static Map getLayersUsed() { } /** - * @param aLayersUsed the layersUsed to set + * @param layers */ - public static void setLayersUsed(Map aLayersUsed) { - layersUsed = aLayersUsed; + public static void setLayersUsed(String layers) { + //all layers used --> 1 + for(int i = 0; i < 12; i++) + layersUsed.put(i+1, 1); + //Skip layers + if(layers!=null) { + String[] values = layers.split(","); + if(values.length==0) return; + for(String value : values) { + int layer = Integer.valueOf(value); + layersUsed.put(layer, 0); + System.out.println("EXCLUDE CVT LAYER " + layer); + } + excludeLayers=true; + } } + public static void setBMTExclude(String exbmtlys) { + String[] values = exbmtlys.split(","); + int layer = Integer.valueOf(values[0]); + double phi_min = (double) Float.valueOf(values[1]); + double phi_max = (double) Float.valueOf(values[2]); + double z_min = (double) Float.valueOf(values[3]); + double z_max = (double) Float.valueOf(values[4]); + BMTLayerExcld = layer; + BMTPhiZRangeExcld[0][0] = phi_min; + BMTPhiZRangeExcld[0][1] = phi_max; + BMTPhiZRangeExcld[1][0] = z_min; + BMTPhiZRangeExcld[1][1] = z_max; + } + + /** * @return the BMTPhiZRangeExcld */ @@ -120,29 +156,12 @@ public static double[][] getBMTPhiZRangeExcld() { return BMTPhiZRangeExcld; } - /** - * @param aBMTPhiZRangeExcld the BMTPhiZRangeExcld to set - */ - public static void setBMTPhiZRangeExcld(double[][] aBMTPhiZRangeExcld) { - BMTPhiZRangeExcld = aBMTPhiZRangeExcld; - } - /** * @return the BMTLayerExcld */ public static int getBMTLayerExcld() { return BMTLayerExcld; } - - /** - * @param aBMTLayerExcld the BMTLayerExcld to set - */ - public static void setBMTLayerExcld(int aBMTLayerExcld) { - BMTLayerExcld = aBMTLayerExcld; - } - - private static double[][]BMTPhiZRangeExcld = new double[2][2]; - private static int BMTLayerExcld = -1; //public static final boolean DEBUGMODE =false; // for landau inverse calculation @@ -317,34 +336,6 @@ public static void setBMTLayerExcld(int aBMTLayerExcld) { //public static final int CVTCONFIGSTARTREG = 2; // for 3SVT+3BMT - public static synchronized void Load(boolean isCosmics, boolean isSVTonly) { - if (areConstantsLoaded) { - return; - } - - Constants.setCosmicsData(false); - setSVTOnly(isSVTonly); - - areConstantsLoaded = true; - - } - - public static final boolean isCosmicsData() { - return isCosmicsData; - } - - public static final void setCosmicsData(boolean isCosmicsData) { - Constants.isCosmicsData = isCosmicsData; - } - - public static final boolean isSVTOnly() { - return SVTOnly; - } - - public static final void setSVTOnly(boolean sVTOnly) { - SVTOnly = sVTOnly; - } - public static void setMatLib(String matLib) { switch (matLib) { case "JAMA": diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index 98b1e36f1..c62250701 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -13,6 +13,7 @@ import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.utils.groups.IndexedTable; /** * A class to fill in lists of hits corresponding to reconstructed hits @@ -75,7 +76,7 @@ public void set_SVTHits(List _SVTHits) { * Edep for gemc, adc for cosmics) * @param geo the BMT geometry */ - public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo, Swim swim) { + public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo, Swim swim, IndexedTable status, IndexedTable timeCuts) { // return if there is no BMT bank if (event.hasBank("BMT::adc") == false) { @@ -93,36 +94,37 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo int rows = bankDGTZ.rows(); if (event.hasBank("BMT::adc") == true) { - + + double tmin = timeCuts.getDoubleValue("hit_min", 0,0,0); + double tmax = timeCuts.getDoubleValue("hit_max", 0,0,0); + for (int i = 0; i < rows; i++) { //if (bankDGTZ.getInt("ADC", i) < 1) { //continue; // gemc assigns strip value -1 for inefficiencies, we only consider strips with values between 1 to the maximum strip number for a given detector - //} + //} + int sector = bankDGTZ.getByte("sector", i); + int layer = bankDGTZ.getByte("layer", i); + int strip = bankDGTZ.getShort("component", i); double ADCtoEdep = bankDGTZ.getInt("ADC", i); + double time = bankDGTZ.getFloat("time", i); //fix for now... no adc in GEMC if (ADCtoEdep < 1) { continue; } - //timing cut in data - if(event.hasBank("MC::Particle") == false && - bankDGTZ.getFloat("time", i)<50.0) { - continue; - - } + // create the strip object for the BMT - //Strip BmtStrip = new Strip((int) bankDGTZ.getShort("component", i), ADCtoEdep); - Strip BmtStrip = new Strip((int) bankDGTZ.getShort("component", i), ADCtoEdep, (double) bankDGTZ.getFloat("time", i)); - // calculate the strip parameters for the BMT hit - BmtStrip.calc_BMTStripParams(geo,(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect + Strip BmtStrip = new Strip(strip, ADCtoEdep, time); + BmtStrip.setStatus(status.getIntValue("status", sector, layer, strip)); + if(Constants.BMTTimeCuts) { + if(time!=0 && (timetmax)) + BmtStrip.setStatus(2);// calculate the strip parameters for the BMT hit + } + BmtStrip.calc_BMTStripParams(geo, sector, layer, swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect // create the hit object for detector type BMT - Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(bankDGTZ.getByte("layer", i)),(int) bankDGTZ.getByte("sector", i),(int) bankDGTZ.getByte("layer", i), BmtStrip); - // a place holder to set the status of the hit, for simulated data if the strip number is in range and the Edep is above threshold the hit has status 1, useable - hit.set_Status(1); - //if(BmtStrip.get_Edep()==0) - // hit.set_Status(-1); + Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, BmtStrip); hit.set_Id(i+1); // add this hit if(hit.get_Layer()+3!=Constants.getRmReg()) @@ -140,27 +142,19 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo * @param adcConv converter from adc to daq values * @param geo the SVT geometry */ - public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, SVTGeometry geo) { + public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, SVTGeometry geo, IndexedTable status) { if (event.hasBank("BST::adc") == false) { //System.err.println("there is no BST bank "); - _SVTHits = new ArrayList(); + _SVTHits = new ArrayList<>(); return; } - List hits = new ArrayList(); + List hits = new ArrayList<>(); DataBank bankDGTZ = event.getBank("BST::adc"); - - int rows = bankDGTZ.rows();; - - int[] id = new int[rows]; - int[] sector = new int[rows]; - int[] layer = new int[rows]; - int[] strip = new int[rows]; - int[] ADC = new int[rows]; - float[] time = new float[rows]; + int rows = bankDGTZ.rows(); if (event.hasBank("BST::adc") == true) { //bankDGTZ.show(); @@ -170,49 +164,49 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, continue; // ignore hits TDC hits with ADC==-1 } - id[i] = i + 1; - sector[i] = bankDGTZ.getByte("sector", i); - layer[i] = bankDGTZ.getByte("layer", i); - - strip[i] = bankDGTZ.getShort("component", i); - ADC[i] = bankDGTZ.getInt("ADC", i); + int id = i + 1; + int sector = bankDGTZ.getByte("sector", i); + int layer = bankDGTZ.getByte("layer", i); + int strip = bankDGTZ.getShort("component", i); + int ADC = bankDGTZ.getInt("ADC", i); + double time = bankDGTZ.getFloat("time", i); - double angle = geo.getSectorPhi(layer[i], sector[i]); + double angle = geo.getSectorPhi(layer, sector); int hemisphere = (int) Math.signum(Math.sin(angle)); - if (sector[i] == 7 && layer[i] > 6) { + if (sector == 7 && layer > 6) { hemisphere = 1; } - if (sector[i] == 19 && layer[i] > 6) { + if (sector == 19 && layer > 6) { hemisphere = -1; } if (omitHemisphere == -2) { - if (layer[i] == omitLayer) { + if(layer == omitLayer) { continue; } } else { - if (hemisphere == omitHemisphere && layer[i] == omitLayer) { + if (hemisphere == omitHemisphere && layer == omitLayer) { continue; } } // if the strip is out of range skip - if (strip[i] < 1) { + if (strip < 1) { continue; } - if (layer[i] > 6) { + if (layer > 6) { continue; } //if(adcConv.SVTADCtoDAQ(ADC[i], event)<50) // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate - Strip SvtStrip = new Strip(strip[i], adcConv.SVTADCtoDAQ(ADC[i], event), (double) time[i]); + Strip SvtStrip = new Strip(strip, adcConv.SVTADCtoDAQ(ADC, event), time); SvtStrip.set_Pitch(SVTGeometry.getPitch()); // get the strip line - SvtStrip.set_Line(geo.getStrip(layer[i], sector[i], strip[i])); - SvtStrip.set_Module(geo.getModule(layer[i], sector[i])); - SvtStrip.set_Normal(geo.getNormal(layer[i], sector[i])); - if(layer[i]%2==1) { + SvtStrip.set_Line(geo.getStrip(layer, sector, strip)); + SvtStrip.set_Module(geo.getModule(layer, sector)); + SvtStrip.set_Normal(geo.getNormal(layer, sector)); + if(layer%2==1) { SvtStrip.setToverX0(SVTGeometry.getToverX0()); SvtStrip.setZoverA(SVTGeometry.getZoverA()); SvtStrip.setMatT(SVTGeometry.getMaterialThickness()); @@ -220,6 +214,12 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, else { SvtStrip.setToverX0(0); } + // if the hit is useable in the analysis its status is =0 + if (SvtStrip.get_Edep() == 0) { + SvtStrip.setStatus(1); + } +// SvtStrip.setStatus(status.getIntValue("status", sector, layer, strip)); + // BMTGeometry implementation using the geometry package: Charles Platt // Line3d shiftedStrip = geo.getStrip(layer[i]-1, sector[i]-1, strip[i]-1); // @@ -238,17 +238,10 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // create the hit object - Hit hit = new Hit(DetectorType.BST, BMTType.UNDEFINED, sector[i], layer[i], SvtStrip); - // if the hit is useable in the analysis its status is 1 - hit.set_Status(1); - if (SvtStrip.get_Edep() == 0) { - hit.set_Status(-1); - } - //System.out.println("SVT e "+SvtStrip.get_Edep()); - - hit.set_Id(id[i]); + Hit hit = new Hit(DetectorType.BST, BMTType.UNDEFINED, sector, layer, SvtStrip); + hit.set_Id(id); // add this hit - if(SvtStrip.get_Edep()>0 && hit.get_Region()!=Constants.getRmReg()) + if(hit.get_Region()!=Constants.getRmReg()) hits.add(hit); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index cab8e62a0..79a6088ed 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -8,7 +8,6 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.trajectory.Helix; @@ -16,6 +15,7 @@ import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.track.Seed; public class RecoBankWriter { @@ -29,7 +29,7 @@ public class RecoBankWriter { * @return hits bank * */ - public DataBank fillSVTHitsBank(DataEvent event, List hitlist) { + public DataBank fillSVTHitsBank(DataEvent event, List hitlist) { if (hitlist == null) { return null; } @@ -48,12 +48,15 @@ public DataBank fillSVTHitsBank(DataEvent event, List hitlist) { bank.setByte("sector", i, (byte) hitlist.get(i).get_Sector()); bank.setInt("strip", i, hitlist.get(i).get_Strip().get_Strip()); + bank.setFloat("energy", i, (float) hitlist.get(i).get_Strip().get_Edep()); + bank.setFloat("time", i, (float) hitlist.get(i).get_Strip().get_Time()); bank.setFloat("fitResidual", i, (float) hitlist.get(i).get_Residual()); bank.setInt("trkingStat", i, hitlist.get(i).get_TrkgStatus()); bank.setShort("clusterID", i, (short) hitlist.get(i).get_AssociatedClusterID()); bank.setShort("trkID", i, (short) hitlist.get(i).get_AssociatedTrackID()); + bank.setByte("status", i, (byte) hitlist.get(i).get_Strip().getStatus()); } //bank.show(); return bank; @@ -86,6 +89,7 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); bank.setShort("size", i, (short) cluslist.get(i).size()); bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); + bank.setFloat("time", i, (float) cluslist.get(i).get_Time()); bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); @@ -195,7 +199,7 @@ public DataBank fillSVTCrossesBank(DataEvent event, List> cross } - public DataBank fillBMTHitsBank(DataEvent event, List hitlist) { + public DataBank fillBMTHitsBank(DataEvent event, List hitlist) { if (hitlist == null) { return null; } @@ -214,12 +218,15 @@ public DataBank fillBMTHitsBank(DataEvent event, List hitlist) { bank.setByte("sector", i, (byte) hitlist.get(i).get_Sector()); bank.setInt("strip", i, hitlist.get(i).get_Strip().get_Strip()); + bank.setFloat("energy", i, (float) hitlist.get(i).get_Strip().get_Edep()); + bank.setFloat("time", i, (float) hitlist.get(i).get_Strip().get_Time()); bank.setFloat("fitResidual", i, (float) hitlist.get(i).get_Residual()); bank.setInt("trkingStat", i, hitlist.get(i).get_TrkgStatus()); bank.setShort("clusterID", i, (short) hitlist.get(i).get_AssociatedClusterID()); bank.setShort("trkID", i, (short) hitlist.get(i).get_AssociatedTrackID()); + bank.setByte("status", i, (byte) hitlist.get(i).get_Strip().getStatus()); } return bank; @@ -252,6 +259,7 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); bank.setShort("size", i, (short) cluslist.get(i).size()); bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); + bank.setFloat("time", i, (float) cluslist.get(i).get_Time()); bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); bank.setFloat("centroidValue", i, (float) cluslist.get(i).get_CentroidValue()); @@ -674,7 +682,7 @@ public DataBank fillHelicalTracksTrajectoryBank(DataEvent event, List trk } public void appendCVTBanks(DataEvent event, - List sVThits, List bMThits, + List sVThits, List bMThits, List sVTclusters, List bMTclusters, List> crosses, List seeds, List trks) { @@ -707,7 +715,7 @@ public void appendCVTBanks(DataEvent event, } public void appendCVTCosmicsBanks(DataEvent event, - List sVThits, List bMThits, + List sVThits, List bMThits, List sVTclusters, List bMTclusters, List> crosses, List trks) { List svtbanks = new ArrayList<>(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 88841b324..233495743 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -4,7 +4,6 @@ import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import java.util.Collections; @@ -26,7 +25,7 @@ * @author ziegler * */ -public class Cluster extends ArrayList implements Comparable { +public class Cluster extends ArrayList implements Comparable { private static final long serialVersionUID = 9153980362683755204L; @@ -41,6 +40,7 @@ public class Cluster extends ArrayList implements Comparable private double _CentroidError; // for BMT error or Z or phi private double _Resolution; // cluster spatial resolution private double _TotalEnergy; + private double _Time; private double _Phi; // local LC phi and error for BMT-Z private double _PhiErr; private double _Phi0; // local uncorrected phi and error for BMT-Z @@ -55,7 +55,7 @@ public class Cluster extends ArrayList implements Comparable private int _MinStrip; // the min strip number in the cluster private int _MaxStrip; // the max strip number in the cluster - private FittedHit _Seed; // the seed: the strip with largest deposited energy + private Hit _Seed; // the seed: the strip with largest deposited energy private double _SeedResidual; // residual is doca to seed strip from trk intersection with module plane private double _CentroidResidual; // residual is doca to centroid of cluster to trk inters with module plane @@ -199,6 +199,7 @@ public Cylindrical3D getTile() { public void calc_CentroidParams() { // instantiation of variables double totEn = 0.; // cluster total energy + double aveTime = 0.; // cluster average time double weightedStrp = 0; // Lorentz-angle-corrected energy-weighted strip double weightedStrp0 = 0; // uncorrected energy-weighted strip double weightedPhi = 0; // Lorentz-angle-corrected energy-weighted phi of the strip @@ -228,11 +229,12 @@ public void calc_CentroidParams() { if (nbhits != 0) { int min = 1000000; int max = -1; - FittedHit seed = null; - + Hit seed = null; + int totHits = 0; + // looping over the number of hits in the cluster for (int i = 0; i < nbhits; i++) { - FittedHit thehit = this.get(i); + Hit thehit = this.get(i); int strpNb = -1; int strpNb0 = -1; //before LC @@ -246,6 +248,9 @@ public void calc_CentroidParams() { // strip energy double strpEn = thehit.get_Strip().get_Edep(); + // strip time + double strpTime = thehit.get_Strip().get_Time(); + if (this.get_Detector()==DetectorType.BST) { // for the SVT the analysis only uses the centroid strpNb = thehit.get_Strip().get_Strip(); @@ -287,8 +292,10 @@ else if (this.get_Detector()==DetectorType.BMT) { } } - + + totHits++; totEn += strpEn; + aveTime += strpTime; weightedX1 += strpEn * stEP1.x(); weightedY1 += strpEn * stEP1.y(); weightedZ1 += strpEn * stEP1.z(); @@ -327,6 +334,7 @@ else if (this.get_Detector()==DetectorType.BMT) { this.set_MaxStrip(max); this.set_Seed(seed); // calculates the centroid values and associated errors + aveTime /= totHits; weightedStrp /= totEn; weightedStrp0 /= totEn; weightedX1 /= totEn; @@ -346,6 +354,7 @@ else if (this.get_Detector()==DetectorType.BMT) { weightedPhi0 = Math.atan2(weightedY0, weightedX0); this.set_Centroid(weightedStrp); this.set_TotalEnergy(totEn); + this.set_Time(aveTime); this.set_Phi(weightedPhi); this.set_Phi0(weightedPhi0); @@ -599,6 +608,14 @@ public double get_TotalEnergy() { public void set_TotalEnergy(double _TotalEnergy) { this._TotalEnergy = _TotalEnergy; } + + public double get_Time() { + return _Time; + } + + public void set_Time(double _Time) { + this._Time = _Time; + } public int get_MinStrip() { return _MinStrip; @@ -620,11 +637,11 @@ public Strip get_SeedStrip() { return _Seed.get_Strip(); } - public FittedHit get_Seed() { + public Hit get_Seed() { return _Seed; } - public void set_Seed(FittedHit _Seed) { + public void set_Seed(Hit _Seed) { this._Seed = _Seed; } @@ -716,6 +733,7 @@ public void printInfo() { * * @param Z z-coordinate of a point in the local coordinate system of a * module + * @param geo * @return the average resolution for a group of strips in a cluster in the * SVT * @@ -844,7 +862,7 @@ public void update(int trackId, HitOnTrack traj, SVTGeometry sgeo) { this.set_CentroidResidual(traj.resi*this.getTile().baseArc().radius()); } - for (FittedHit hit : this) { + for (Hit hit : this) { hit.set_AssociatedTrackID(trackId); double doca1 = hit.residual(trackPos); hit.set_docaToTrk(doca1); @@ -858,6 +876,7 @@ public void update(int trackId, HitOnTrack traj, SVTGeometry sgeo) { } + @Override public String toString() { String s = "Cluster Id" + this.get_Id() + " " + this.get_Detector() + " " +this.get_Type(); s += " layer " + this.get_Layer() + " sector " + this.get_Sector() + " centroid " + this.get_Centroid() + " phi " + this.get_Phi(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 0bf2fc71c..5e621b440 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -3,7 +3,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Hit; /** @@ -25,7 +26,7 @@ public ClusterFinder() { int nsec = 18; public ArrayList findClusters(List hits2) // the number of strips depends on the layer { - ArrayList clusters = new ArrayList(); + ArrayList clusters = new ArrayList<>(); // a Hit Array is used to identify clusters HitArray = new Hit[nstrip][nlayr][nsec]; @@ -38,6 +39,10 @@ public ArrayList findClusters(List hits2) // the number of strips continue; } + if (hit.get_Strip().getStatus()!=0) { + continue; + } + int w = hit.get_Strip().get_Strip(); int l = hit.get_Layer(); int s = hit.get_Sector(); @@ -61,16 +66,13 @@ public ArrayList findClusters(List hits2) // the number of strips // if there's a hit, it's a cluster candidate if (HitArray[si][l][s] != null || (si < nstrip - 1 && HitArray[si + 1][l][s] != null)) { // vector of hits in the cluster candidate - ArrayList hits = new ArrayList(); + ArrayList hits = new ArrayList<>(); // adding all hits in this and all the subsequent // strip until there's a strip with no hit while ((si < nstrip - 1 && HitArray[si + 1][l][s] != null) || (HitArray[si][l][s] != null && si < nstrip)) { if (HitArray[si][l][s] != null) { // continue clustering skipping over bad hit - FittedHit hitInCls = new FittedHit(HitArray[si][l][s].get_Detector(), HitArray[si][l][s].get_Type(), HitArray[si][l][s].get_Sector(), HitArray[si][l][s].get_Layer(), HitArray[si][l][s].get_Strip()); - hitInCls.set_Id(HitArray[si][l][s].get_Id()); - - hits.add(hitInCls); + hits.add(HitArray[si][l][s]); } si++; } @@ -88,14 +90,14 @@ public ArrayList findClusters(List hits2) // the number of strips } } } - for (FittedHit h : hits) { + for (Hit h : hits) { h.set_AssociatedClusterID(this_cluster.get_Id()); - h.newClustering = true; + h.newClustering = true; //RDV fix me! } this_cluster.calc_CentroidParams(); - for (FittedHit h : this_cluster) { + for (Hit h : this_cluster) { h.newClustering = false; } Collections.sort(this_cluster); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index d8983727d..441d84652 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -615,7 +615,7 @@ public int get_SVTCosmicsRegion() { public int compareTo(Cross arg) { int return_val = 0; - if (Constants.isCosmicsData() == true) { + if(Constants.isCosmicsData) { int RegComp = this.get_SVTCosmicsRegion() < arg.get_SVTCosmicsRegion() ? -1 : this.get_SVTCosmicsRegion() == arg.get_SVTCosmicsRegion() ? 0 : 1; int IDComp = this.get_Id() < arg.get_Id() ? -1 : this.get_Id() == arg.get_Id() ? 0 : 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java deleted file mode 100644 index 595e23450..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/FittedHit.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.jlab.rec.cvt.hit; - -import org.jlab.detector.base.DetectorType; -import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; -import org.jlab.rec.cvt.bmt.BMTType; - -/** - * A hit that is used in a fitted track. - * - * @author ziegler - * - */ -public class FittedHit extends Hit implements Comparable { - - /** - * @param detector SVT (0) or BMT (1) - * @param type - * @param sector (1...) - * @param layer (1...) - * @param strip (1...) - */ - public FittedHit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) { - super(detector, type, sector, layer, strip); - } - - private double _docaToTrk; // 3-D distance of closest approach of the helix to the wire - private double _stripResolutionAtDoca; - private int _TrkgStatus = -1; // TrkgStatusFlag factor (-1: no fit; 0: global helical fit; 1: KF fit) - - public double get_docaToTrk() { - return _docaToTrk; - } - - public void set_docaToTrk(double _docaToTrk) { - this._docaToTrk = _docaToTrk; - } - - public void set_docaToTrk(Point3D traj) { - this.set_docaToTrk(this.residual(traj)); - } - - public double residual(Point3D traj) { - double value = 0; - if(this.get_Detector()==DetectorType.BST) { - Line3D dist = this.get_Strip().get_Line().distance(traj); - double side = -Math.signum(this.get_Strip().get_Line().direction().cross(dist.direction()).dot(this.get_Strip().get_Normal())); - value = dist.length()*side; - } - else { - Point3D local = new Point3D(traj); - this.get_Strip().toLocal().apply(local); - if(this.get_Type()==BMTType.C) - value = local.z()-this.get_Strip().get_Z(); - else { - value = Math.atan2(local.y(),local.x())-this.get_Strip().get_Phi(); - value = (value + 8*Math.PI) % (2*Math.PI); - } - } - return value; - } - - - public double get_stripResolutionAtDoca() { - return _stripResolutionAtDoca; - } - - public void set_stripResolutionAtDoca(double _stripResolutionAtDoca) { - this._stripResolutionAtDoca = _stripResolutionAtDoca; - } - - /** - * - * @return an integer representative of the stage of the pattern recognition - * and subsequent KF fit for that hit. -1: no fit; 0: global helical fit; 1: - * KF fit - */ - public int get_TrkgStatus() { - return _TrkgStatus; - } - - /** - * - * @param trkgStatus is an integer representative of the stage of the - * pattern recognition and subsequent KF fit for that hit. -1: no fit; 0: - * global helical fit; 1: KF fit - */ - public void set_TrkgStatus(int trkgStatus) { - _TrkgStatus = trkgStatus; - } - -// /** -// * -// * @param arg0 the other hit -// * @return an int used to sort a collection of hits by layer number -// */ -// public int compareTo(FittedHit arg) { -// -// //sort by layer, then time, then edep -// int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; -// int CompEdep = this.get_Strip().get_Edep() > arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; -// int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; -// -// int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); -// int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); -// -// return return_val; -// } - - public double _QualityFac; // a quality factor depending on the hit status and goodness of fit - - public double get_QualityFac() { - return _QualityFac; - } - - public void set_QualityFac(double QF) { - _QualityFac = QF; - } - - /** - * - * @return the hit residual = doca to track - */ - public double get_Residual() { - //if (get_docaToTrk() == 0) { - // return Double.NaN; - //} - return get_docaToTrk(); - } - - private int _AssociatedClusterID; // the cluster ID associated with that hit - - public int get_AssociatedClusterID() { - return _AssociatedClusterID; - } - - public void set_AssociatedClusterID(int _AssociatedClusterID) { - this._AssociatedClusterID = _AssociatedClusterID; - } - - private int AssociatedTrackID = -1; // the track ID associated with that hit - - public int get_AssociatedTrackID() { - return AssociatedTrackID; - } - - public void set_AssociatedTrackID(int associatedTrackID) { - AssociatedTrackID = associatedTrackID; - } - -} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index 32ce39ad8..c796b77ae 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -1,6 +1,8 @@ package org.jlab.rec.cvt.hit; import org.jlab.detector.base.DetectorType; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.bmt.BMTType; /** @@ -13,19 +15,27 @@ public class Hit implements Comparable { // class implements Comparable interface to allow for sorting a collection of hits by wire number values - private DetectorType _Detector; // the detector SVT or BMT - private BMTType _Type; // for the BMT, either C or Z + private int _Id; // Hit Id - private int _Sector; // sector[1...24] for SVT, [1..3] for BMT - private int _Layer; // layer [1,...] - private Strip _Strip; // Strip object + private DetectorType _Detector; // the detector SVT or BMT + private BMTType _Type; // for the BMT, either C or Z - private int _Id; // Hit Id - private int _Status; // Status -1 dead, 0 noisy, 1 good + private int _Sector; // sector[1...24] for SVT, [1..3] for BMT + private int _Layer; // layer [1,...] + private Strip _Strip; // Strip object + + private double _docaToTrk; // 3-D distance of closest approach of the helix to the wire + private double _stripResolutionAtDoca; + private int _TrkgStatus = -1; // TrkgStatusFlag factor (-1: no fit; 0: global helical fit; 1: KF fit) + public double _QualityFac; // a quality factor depending on the hit status and goodness of fit + private int _AssociatedClusterID = -1; // the cluster ID associated with that hit + private int AssociatedTrackID = -1; // the track ID associated with that hit + + public boolean newClustering = false; // constructor public Hit(DetectorType detector, BMTType type, int sector, int layer, Strip strip) { - this._Detector = detector; // 0 = SVT, 1 = BMT + this._Detector = detector; // 0 = SVT, 1 = BMT this._Type = type; // set according to BMTType this._Sector = sector; this._Layer = layer; @@ -123,10 +133,10 @@ public int get_Region() { public int get_RegionSlayer() { return (this._Layer + 1) % 2 + 1; } - public boolean newClustering = false; + /** * - * @param arg0 the other hit + * @param arg * @return an int used to sort a collection of hits by wire number. Sorting * by wire is used in clustering. */ @@ -148,10 +158,8 @@ public int compareTo(Hit arg) { return ((CompLyr == 0) ? return_val1 : CompLyr); } } - /** - * - * @return print statement with hit information - */ + + public void printInfo() { String s = " Hit: Detector " + this.get_Detector() + "ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Strip " + this.get_Strip().get_Strip() + " Edep " + this.get_Strip().get_Edep()+ " Time " + this.get_Strip().get_Time(); @@ -164,8 +172,8 @@ public void printInfo() { * @return a boolean comparing 2 hits based on basic descriptors; returns * true if the hits are the same */ - public boolean isSameAs(FittedHit otherHit) { - FittedHit thisHit = (FittedHit) this; + public boolean isSameAs(Hit otherHit) { + Hit thisHit = (Hit) this; boolean cmp = false; if ((thisHit.get_Detector()==otherHit.get_Detector()) && thisHit.get_Sector() == otherHit.get_Sector() @@ -177,12 +185,100 @@ public boolean isSameAs(FittedHit otherHit) { return cmp; } - public int get_Status() { - return _Status; + public double get_docaToTrk() { + return _docaToTrk; + } + + public void set_docaToTrk(double _docaToTrk) { + this._docaToTrk = _docaToTrk; + } + + public void set_docaToTrk(Point3D traj) { + this.set_docaToTrk(this.residual(traj)); + } + + public double residual(Point3D traj) { + double value = 0; + if(this.get_Detector()==DetectorType.BST) { + Line3D dist = this.get_Strip().get_Line().distance(traj); + double side = -Math.signum(this.get_Strip().get_Line().direction().cross(dist.direction()).dot(this.get_Strip().get_Normal())); + value = dist.length()*side; + } + else { + Point3D local = new Point3D(traj); + this.get_Strip().toLocal().apply(local); + if(this.get_Type()==BMTType.C) + value = local.z()-this.get_Strip().get_Z(); + else { + value = Math.atan2(local.y(),local.x())-this.get_Strip().get_Phi(); + if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + value = value*this.get_Strip().get_Tile().baseArc().radius(); + } + } + return value; + } + + + public double get_stripResolutionAtDoca() { + return _stripResolutionAtDoca; + } + + public void set_stripResolutionAtDoca(double _stripResolutionAtDoca) { + this._stripResolutionAtDoca = _stripResolutionAtDoca; + } + + /** + * + * @return an integer representative of the stage of the pattern recognition + * and subsequent KF fit for that hit. -1: no fit; 0: global helical fit; 1: + * KF fit + */ + public int get_TrkgStatus() { + return _TrkgStatus; + } + + /** + * + * @param trkgStatus is an integer representative of the stage of the + * pattern recognition and subsequent KF fit for that hit. -1: no fit; 0: + * global helical fit; 1: KF fit + */ + public void set_TrkgStatus(int trkgStatus) { + _TrkgStatus = trkgStatus; + } + + public double get_QualityFac() { + return _QualityFac; + } + + public void set_QualityFac(double QF) { + _QualityFac = QF; + } + + /** + * + * @return the hit residual = doca to track + */ + public double get_Residual() { + return get_docaToTrk(); + } + + + public int get_AssociatedClusterID() { + return _AssociatedClusterID; + } + + public void set_AssociatedClusterID(int _AssociatedClusterID) { + this._AssociatedClusterID = _AssociatedClusterID; + } + + + public int get_AssociatedTrackID() { + return AssociatedTrackID; } - public void set_Status(int _Status) { - this._Status = _Status; + public void set_AssociatedTrackID(int associatedTrackID) { + AssociatedTrackID = associatedTrackID; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 19c495b0b..53ae27c66 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -20,14 +20,15 @@ public Strip(int strip, double edep, double time) { } - private int _Strip; // strip read from daq - private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value + private int _Strip; // strip read from daq + private double _Edep; // for simulation this corresponds to the energy deposited on the strip, in data it should be an ADC converted value private double _Time; + private int _Status; // 0=good, 1=bad edep, 2=bad tim, 3=dead - private int _LCStrip; // strip number taking into account Lorentz angle correction (for MM Z detectors) - private double _Phi; // for MM Z-detectors, the azimuth angle at the strip midwidth after LC + private int _LCStrip; // strip number taking into account Lorentz angle correction (for MM Z detectors) + private double _Phi; // for MM Z-detectors, the azimuth angle at the strip midwidth after LC private double _PhiErr; - private double _Phi0; // for MM Z-detectors, the azimuth angle at the strip midwidth before LC + private double _Phi0; // for MM Z-detectors, the azimuth angle at the strip midwidth before LC private double _PhiErr0; private double _Z; private double _ZErr; @@ -218,10 +219,23 @@ public void set_Time(double _Time) { this._Time = _Time; } + public int getStatus() { + return _Status; + } + + public void setStatus(int _Status) { + this._Status = _Status; + } + + /** + * * * @param geo the BMT geometry class Sets the Lorentz corrected phi and * strip number for Z detectors, the z position for C detectors + * @param sector + * @param layer + * @param swim */ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swim) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index d46eb1043..6319c3b36 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.services; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -27,10 +28,10 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossMaker; import org.jlab.rec.cvt.hit.ADCConvertor; -import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; +import org.jlab.utils.groups.IndexedTable; /** * Service to return reconstructed TRACKS @@ -41,13 +42,14 @@ */ public class CVTRecNewKF extends ReconstructionEngine { - SVTGeometry SVTGeom; - BMTGeometry BMTGeom; - CTOFGeant4Factory CTOFGeom; - Detector CNDGeom ; - SVTStripFactory svtIdealStripFactory; - CosmicTracksRec strgtTrksRec; - TracksFromTargetRec trksFromTargetRec; + private SVTGeometry SVTGeom = null; + private BMTGeometry BMTGeom = null; + private CTOFGeant4Factory CTOFGeom = null; + private Detector CNDGeom = null; + private SVTStripFactory svtIdealStripFactory = null; + private CosmicTracksRec strgtTrksRec = null; + private TracksFromTargetRec trksFromTargetRec = null; + private int Run = -1; public CVTRecNewKF() { super("CVTTracks", "ziegler", "4.0"); @@ -57,10 +59,16 @@ public CVTRecNewKF() { trksFromTargetRec = new TracksFromTargetRec(); } - private int Run = -1; - public boolean isSVTonly = false; - public boolean isCosmic = false; - public boolean exclLayrs = false; + + @Override + public boolean init() { + + this.loadConfiguration(); + this.initConstantsTables(); + this.loadGeometries(); + this.registerBanks(); + return true; + } public void setRunConditionsParameters(DataEvent event, int iRun, boolean addMisAlignmts, String misAlgnFile) { if (event.hasBank("RUN::config") == false) { @@ -83,7 +91,6 @@ public void setRunConditionsParameters(DataEvent event, int iRun, boolean addMis int newRun = bank.getInt("run", 0); if (Run != newRun) { - Constants.Load(isCosmics, isSVTonly); this.setRun(newRun); Constants.isMC = newRun<100; @@ -111,31 +118,33 @@ public boolean processDataEvent(DataEvent event) { RecoBankWriter rbc = new RecoBankWriter(); + IndexedTable svtStatus = this.getConstantsManager().getConstants(this.getRun(), "/calibration/svt/status"); + IndexedTable bmtStatus = this.getConstantsManager().getConstants(this.getRun(), "/calibration/mvt/bmt_status"); + IndexedTable bmtTime = this.getConstantsManager().getConstants(this.getRun(), "/calibration/mvt/bmt_time"); + HitReader hitRead = new HitReader(); - hitRead.fetch_SVTHits(event, adcConv, -1, -1, SVTGeom); - if(isSVTonly==false) - hitRead.fetch_BMTHits(event, adcConv, BMTGeom, swimmer); + hitRead.fetch_SVTHits(event, adcConv, -1, -1, SVTGeom, svtStatus); + if(Constants.SVTOnly==false) + hitRead.fetch_BMTHits(event, adcConv, BMTGeom, swimmer, bmtStatus, bmtTime); List hits = new ArrayList<>(); //I) get the hits - List svt_hits = hitRead.get_SVTHits(); - if(svt_hits.size()>SVTParameters.MAXSVTHITS) + List SVThits = hitRead.get_SVTHits(); + if(SVThits.size()>SVTParameters.MAXSVTHITS) return true; - if (svt_hits != null && !svt_hits.isEmpty()) { - hits.addAll(svt_hits); + if (SVThits != null && !SVThits.isEmpty()) { + hits.addAll(SVThits); } - List bmt_hits = hitRead.get_BMTHits(); - if (bmt_hits != null && bmt_hits.size() > 0) { - hits.addAll(bmt_hits); + List BMThits = hitRead.get_BMTHits(); + if (BMThits != null && BMThits.size() > 0) { + hits.addAll(BMThits); - if(bmt_hits.size()>BMTConstants.MAXBMTHITS) + if(BMThits.size()>BMTConstants.MAXBMTHITS) return true; } //II) process the hits - List SVThits = new ArrayList<>(); - List BMThits = new ArrayList<>(); //1) exit if hit list is empty if (hits.isEmpty()) { return true; @@ -147,25 +156,22 @@ public boolean processDataEvent(DataEvent event) { //2) find the clusters from these hits ClusterFinder clusFinder = new ClusterFinder(); - clusters.addAll(clusFinder.findClusters(svt_hits)); - if(bmt_hits != null && bmt_hits.size() > 0) { - clusters.addAll(clusFinder.findClusters(bmt_hits)); + clusters.addAll(clusFinder.findClusters(SVThits)); + if(BMThits != null && BMThits.size() > 0) { + clusters.addAll(clusFinder.findClusters(BMThits)); } if (clusters.isEmpty()) { rbc.appendCVTBanks(event, SVThits, BMThits, null, null, null, null, null); return true; } - // fill the fitted hits list. if (!clusters.isEmpty()) { for (int i = 0; i < clusters.size(); i++) { if (clusters.get(i).get_Detector() == DetectorType.BST) { SVTclusters.add(clusters.get(i)); - SVThits.addAll(clusters.get(i)); } if (clusters.get(i).get_Detector() == DetectorType.BMT) { BMTclusters.add(clusters.get(i)); - BMThits.addAll(clusters.get(i)); } } } @@ -177,157 +183,66 @@ public boolean processDataEvent(DataEvent event) { return true; } - if(this.isCosmic) { + if(Constants.isCosmicsData) { // if(this.isSVTonly) { // List> crosses_svtOnly = new ArrayList<>(); // crosses_svtOnly.add(0, crosses.get(0)); // crosses_svtOnly.add(1, new ArrayList<>()); // } strgtTrksRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, this.exclLayrs, swimmer); + crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, swimmer); } else { - trksFromTargetRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, swimmer, - this.isSVTonly, this.exclLayrs); + trksFromTargetRec.processEvent(event,SVThits, BMThits, SVTclusters, BMTclusters, + crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, swimmer); } return true; } - @Override - public boolean init() { + + private void loadConfiguration() { // Load config - String rmReg = this.getEngineConfigString("removeRegion"); + String rmReg = this.getEngineConfigString("removeRegion"); if (rmReg!=null) { System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on yaml"); Constants.setRmReg(Integer.valueOf(rmReg)); } else { - rmReg = System.getenv("COAT_CVT_REMOVEREGION"); - if (rmReg!=null) { - System.out.println("["+this.getName()+"] run with region "+rmReg+"removed config chosen based on env"); - Constants.setRmReg(Integer.valueOf(rmReg)); - } - } - if (rmReg==null) { System.out.println("["+this.getName()+"] run with all region (default) "); } - //svt stand-alone - String svtStAl = this.getEngineConfigString("svtOnly"); + //svt stand-alone + String svtStAl = this.getEngineConfigString("svtOnly"); if (svtStAl!=null) { - System.out.println("["+this.getName()+"] run with SVT only "+svtStAl+" config chosen based on yaml"); - this.isSVTonly= Boolean.valueOf(svtStAl); + Constants.SVTOnly = Boolean.valueOf(svtStAl); + System.out.println("["+this.getName()+"] run with SVT only "+Constants.SVTOnly+" config chosen based on yaml"); } else { - svtStAl = System.getenv("COAT_SVT_ONLY"); - if (svtStAl!=null) { - System.out.println("["+this.getName()+"] run with SVT only "+svtStAl+" config chosen based on env"); - this.isSVTonly= Boolean.valueOf(svtStAl); - } - } - if (svtStAl==null) { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); } - //svt stand-alone - String svtCosmics = this.getEngineConfigString("cosmics"); + String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { - System.out.println("["+this.getName()+"] run with cosmics settings "+svtCosmics+" config chosen based on yaml"); - this.isCosmic= Boolean.valueOf(svtCosmics); - Constants.setCosmicsData(isCosmic); + Constants.isCosmicsData = Boolean.valueOf(svtCosmics); + System.out.println("["+this.getName()+"] run with cosmics settings "+Constants.isCosmicsData+" config chosen based on yaml"); } else { - svtCosmics = System.getenv("COAT_CVT_COSMICS"); - if (svtCosmics!=null) { - System.out.println("["+this.getName()+"] run with cosmics settings "+svtCosmics+" config chosen based on env"); - this.isCosmic= Boolean.valueOf(svtCosmics); - Constants.setCosmicsData(isCosmic); - } - } - if (svtCosmics==null) { - System.out.println("["+this.getName()+"] run with cosmics settings default = false"); + System.out.println("["+this.getName()+"] run with cosmics settings default = false"); } - //all layers used --> 1 - for(int i = 0; i < 12; i++) - Constants.getLayersUsed().put(i+1, 1); //Skip layers - String exLys = this.getEngineConfigString("excludeLayers"); - - if (exLys!=null) { + String exLys = this.getEngineConfigString("excludeLayers"); + if (exLys!=null) System.out.println("["+this.getName()+"] run with layers "+exLys+"excluded in fit config chosen based on yaml"); - String exlys = String.valueOf(exLys); - String[] values = exlys.split(","); - for (String value : values) { - Constants.getLayersUsed().put(Integer.valueOf(value), 0); - } - } - else { - exLys = System.getenv("COAT_CVT_EXCLUDELAYERS"); - if (exLys!=null) { - System.out.println("["+this.getName()+"] run with region "+rmReg+"excluded in fit config chosen based on env"); - String exlys = String.valueOf(exLys); - String[] values = exlys.split(","); - for (String value : values) { - Constants.getLayersUsed().put(Integer.valueOf(value), 0); // layer excluded --->0 - } - } - } - if (exLys==null) { - System.out.println("["+this.getName()+"] run with all layer in fit (default) "); - } - - int exlyrsnb = 0; - for(int ilayrs = 0; ilayrs<12; ilayrs++) { - if((int)Constants.getLayersUsed().get(ilayrs+1)<1) { - System.out.println("EXCLUDE CVT LAYER "+(ilayrs+1)); - exlyrsnb++; - } - } - if(exlyrsnb>0) - exclLayrs = true; + else + System.out.println("["+this.getName()+"] run with all layer in fit (default) "); + Constants.setLayersUsed(exLys); //Skip layers - String exBMTLys = this.getEngineConfigString("excludeBMTLayers"); - + String exBMTLys = this.getEngineConfigString("excludeBMTLayers"); if (exBMTLys!=null) { System.out.println("["+this.getName()+"] run with BMT layers "+exBMTLys+"excluded config chosen based on yaml"); - String exbmtlys = String.valueOf(exBMTLys); - String[] values = exbmtlys.split(","); - int layer = Integer.valueOf(values[0]); - double phi_min = (double) Float.valueOf(values[1]); - double phi_max = (double) Float.valueOf(values[2]); - double z_min = (double) Float.valueOf(values[3]); - double z_max = (double) Float.valueOf(values[4]); - org.jlab.rec.cvt.Constants.setBMTLayerExcld(layer); - double[][]BMTPhiZRangeExcld= new double[2][2]; - BMTPhiZRangeExcld[0][0] = phi_min; - BMTPhiZRangeExcld[0][1] = phi_max; - BMTPhiZRangeExcld[1][0] = z_min; - BMTPhiZRangeExcld[1][1] = z_max; - org.jlab.rec.cvt.Constants.setBMTPhiZRangeExcld(BMTPhiZRangeExcld); - - } - else { - exBMTLys = System.getenv("COAT_CVT_EXCLUDEBMTLAYERS"); - if (exBMTLys!=null) { - System.out.println("["+this.getName()+"] run with region "+exBMTLys+"excluded in fit config chosen based on env"); - String exbmtlys = String.valueOf(exBMTLys); - String[] values = exbmtlys.split(","); - int layer = Integer.valueOf(values[0]); - double phi_min = (double) Float.valueOf(values[1]); - double phi_max = (double) Float.valueOf(values[2]); - double z_min = (double) Float.valueOf(values[3]); - double z_max = (double) Float.valueOf(values[4]); - org.jlab.rec.cvt.Constants.setBMTLayerExcld(layer); - double[][]BMTPhiZRangeExcld= new double[2][2]; - BMTPhiZRangeExcld[0][0] = phi_min; - BMTPhiZRangeExcld[0][1] = phi_max; - BMTPhiZRangeExcld[1][0] = z_min; - BMTPhiZRangeExcld[1][1] = z_max; - org.jlab.rec.cvt.Constants.setBMTPhiZRangeExcld(BMTPhiZRangeExcld); - } + Constants.setBMTExclude(exBMTLys); } //double[][]bmtx = new double[2][2]; @@ -365,30 +280,58 @@ public boolean init() { Constants.setMatLib(matrixLibrary); System.out.println("["+this.getName()+"] run with matLib "+ Constants.kfMatLib.toString() + " library"); + if(this.getEngineConfigString("svtSeeding")!=null) { + Constants.svtSeeding = Boolean.parseBoolean(this.getEngineConfigString("svtSeeding")); + System.out.println("["+this.getName()+"] run SVT-based seeding set to "+ Constants.svtSeeding); + } + + if(this.getEngineConfigString("BMTTimeCuts")!=null) { + Constants.BMTTimeCuts = Boolean.parseBoolean(this.getEngineConfigString("BMTTimeCuts")); + System.out.println("["+this.getName()+"] run BMT timing cuts set to "+ Constants.BMTTimeCuts); + } + } + + private void initConstantsTables() { + String[] tables = new String[]{ + "/calibration/svt/status", + "/calibration/mvt/bmt_time", + "/calibration/mvt/bmt_status" + }; + requireConstants(Arrays.asList(tables)); + this.getConstantsManager().setVariation("default"); + } + + private void loadGeometries() { // Load other geometries - variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); - System.out.println(" CVT YAML VARIATION NAME + "+variationName); - ConstantProvider providerCTOF = GeometryFactory.getConstants(DetectorType.CTOF, 11, variationName); + String variation = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); + System.out.println(" CVT YAML VARIATION NAME + "+variation); + ConstantProvider providerCTOF = GeometryFactory.getConstants(DetectorType.CTOF, 11, variation); CTOFGeom = new CTOFGeant4Factory(providerCTOF); - CNDGeom = GeometryFactory.getDetector(DetectorType.CND, 11, variationName); - // - + CNDGeom = GeometryFactory.getDetector(DetectorType.CND, 11, variation); - System.out.println(" LOADING CVT GEOMETRY...............................variation = "+variationName); - CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variationName)); - System.out.println("SVT LOADING WITH VARIATION "+variationName); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); + System.out.println(" LOADING CVT GEOMETRY...............................variation = "+variation); + CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variation)); + System.out.println("SVT LOADING WITH VARIATION "+variation); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variation); cp = SVTConstants.connect( cp ); cp.disconnect(); SVTStripFactory svtFac = new SVTStripFactory(cp, true); - SVTGeom = new SVTGeometry(svtFac); - - return true; + SVTGeom = new SVTGeometry(svtFac); + } + + private void registerBanks() { + super.registerOutputBank("BMTRec::Hits"); + super.registerOutputBank("BMTRec::Clusters"); + super.registerOutputBank("BSTRec::Crosses"); + super.registerOutputBank("BSTRec::Hits"); + super.registerOutputBank("BSTRec::Clusters"); + super.registerOutputBank("BSTRec::Crosses"); + super.registerOutputBank("CVTRec::Seeds"); + super.registerOutputBank("CVTRec::Tracks"); + super.registerOutputBank("CVTRec::Trajectory"); } - - private String variationName; } \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index b194d7e2c..e5699f8bc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -10,6 +10,7 @@ import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; @@ -18,7 +19,7 @@ import org.jlab.rec.cvt.cross.CrossList; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.fit.CosmicFitter; -import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; @@ -36,13 +37,12 @@ public class CosmicTracksRec { private final RecUtilities recUtil = new RecUtilities(); public boolean processEvent(DataEvent event, - List SVThits, List BMThits, + List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, - RecoBankWriter rbc, - boolean exLayrs, Swim swimmer) { + RecoBankWriter rbc, Swim swimmer) { // make list of crosses consistent with a track candidate using SVT only first StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); @@ -67,7 +67,7 @@ public boolean processEvent(DataEvent event, return true; } - if(exLayrs==true) { + if(Constants.excludeLayers==true) { CosmicFitter fitTrk = new CosmicFitter(); cosmics = recUtil.reFit(cosmics, SVTGeom, fitTrk, trkcandFinder); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index b389168c1..2c1e9d555 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -14,7 +14,7 @@ import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; @@ -474,7 +474,7 @@ public void MatchTrack2Traj(Seed trkcand, Map SVThits, List BMThits, + List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, SVTGeometry SVTGeom, BMTGeometry BMTGeom, CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, - Swim swimmer, - boolean isSVTonly, boolean exLayrs) { + Swim swimmer) { // get field intensity and scale double solenoidScale = Constants.getSolenoidScale(); @@ -53,12 +52,12 @@ public boolean processEvent(DataEvent event, List seeds = null; if(solenoidValue<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(); - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, isSVTonly); - if(exLayrs==true) { + seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, Constants.SVTOnly); + if(Constants.excludeLayers==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed); // RDV can we juts refit? } } else { - if(isSVTonly) { + if(Constants.SVTOnly) { TrackSeeder trseed = new TrackSeeder(SVTGeom, BMTGeom, swimmer); trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null); @@ -67,11 +66,13 @@ public boolean processEvent(DataEvent event, seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - TrackSeeder trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); - trseed2.unUsedHitsOnly = true; - seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); // RDV check for overlaps - if(exLayrs==true) { - seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed,trseed2); + if(Constants.svtSeeding || Constants.excludeLayers) { + TrackSeeder trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); + trseed2.unUsedHitsOnly = true; + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); // RDV check for overlaps + if(Constants.excludeLayers==true) { + seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed, trseed2); + } } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index c70d2903d..12706f152 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -367,6 +367,8 @@ else if(this.getNDF() < Constants.NDFCUT) return false; else if(this.get_Helix().getPt(this.get_Helix().B) < Constants.PTCUT) return false; +// else if(Math.abs(this.get_Helix().get_tandip()) > Constants.TANDIP) +// return false; else if(Math.abs(this.get_Helix().get_Z0()) > Constants.ZRANGE) return false; else @@ -382,7 +384,7 @@ else if(Math.abs(this.get_Helix().get_Z0()) > Constants.ZRANGE) public boolean betterThan(Seed o) { if(this.getNDF()>o.getNDF()) return true; - else if(this.getNDF()>0 && this.getNDF()==o.getNDF()) { + else if(this.getNDF()==o.getNDF()) { if(this.getChi2()/this.getNDF() < o.getChi2()/o.getNDF()) return true; else return false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index eeea3b019..736241fc4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -23,7 +23,7 @@ import org.jlab.rec.cvt.fit.LineFitter; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.fit.LineFitPars; -import org.jlab.rec.cvt.hit.FittedHit; +import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Ray; @@ -157,7 +157,7 @@ public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) HelicalTrackFitter fitTrk = new HelicalTrackFitter(); // sets the index according to assumption that the track comes from the origin or not int shift = 0; - // if(org.jlab.rec.cvt.BMTConstants.trk_comesfrmOrig) + // if(org.jlab.rec.cvt.BMTConstants.TRACKSFROMORIGIN) // shift =1; // interate the fit a number of times set in the constants file @@ -245,7 +245,7 @@ public ArrayList getHelicalTracks(CrossList crossList, HelicalTrackFitter fitTrk = new HelicalTrackFitter(); // sets the index according to assumption that the track comes from the origin or not int shift = 0; - if (Constants.trk_comesfrmOrig) { + if (Constants.TRACKSFROMORIGIN) { shift = 1; } @@ -1169,7 +1169,7 @@ public void matchClusters(List sVTclusters, TrajectoryFinder tf, SVTGeo st, svt_geo, bmt_geo, trajFinal); //System.out.println("trying to associate a cluster ");cls.printInfo(); System.out.println(" to "+st.get_CalcCentroidStrip()+" dStp = "+(st.get_CalcCentroidStrip()-cls.get_Centroid())); cls.set_AssociatedTrackID(k); - for (FittedHit h : cls) { + for (Hit h : cls) { h.set_AssociatedTrackID(k); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java index 0c432e7d5..2dfddb77a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java @@ -264,13 +264,13 @@ public double uz() { public int compareTo(StateVec arg) { int return_val = 0; - if (Constants.isCosmicsData() == false) { + if (Constants.isCosmicsData == false) { int RegComp = this.get_SurfaceLayer() < arg.get_SurfaceLayer() ? -1 : this.get_SurfaceLayer() == arg.get_SurfaceLayer() ? 0 : 1; int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; return_val = ((RegComp == 0) ? IDComp : RegComp); } - if (Constants.isCosmicsData() == true) { + if (Constants.isCosmicsData == true) { int RegComp = this.y() < arg.y() ? -1 : this.y() == arg.y() ? 0 : 1; int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index ae73814c3..e7d39b17d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -23,7 +23,6 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.Track; @@ -619,7 +618,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl // Plane3D pl = new Plane3D(endPt1, svt_geo.findBSTPlaneNormal(sector, layer)); // double d = new Vector3D(stVec.x(), stVec.y(), stVec.z()).dot(pl.normal())-pl.point().toVector3D().dot(pl.normal()); // System.out.println(d+" calc "+l.distance(new Point3D(stVec.x(), stVec.y(), stVec.z())).length()+" d "+doca2Cls); - for (FittedHit hit : cluster) { + for (Hit hit : cluster) { double doca1 = hit.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); double sigma1 = svt_geo.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); hit.set_stripResolutionAtDoca(sigma1); @@ -639,7 +638,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z cluster.set_CentroidResidual(p); cluster.set_SeedResidual(p); - for (FittedHit h1 : cluster) { + for (Hit h1 : cluster) { // calculate the hit residuals h1.set_TrkgStatus(1); h1.set_docaToTrk(p); @@ -660,7 +659,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl double doca2Cls = (phic-phit)*bmt_geo.getRadiusMidDrift(blayer); cluster.set_CentroidResidual(doca2Cls); - for (FittedHit h1 : cluster) { + for (Hit h1 : cluster) { double xh = Math.cos(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double yh = Math.sin(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); double hphic = bmt_geo.getPhi(blayer, bsector, new Point3D(xh,yh,0)); From b9e20e874d33abfbbc7c85f2c0b4686453429d08 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 10 Dec 2021 23:13:45 +0100 Subject: [PATCH 239/291] catch exception from conversion of gemc BMT bank for backward compatibility --- .../org/jlab/clas/reco/io/EvioHipoEvent4.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java index 8acf2ac71..ac7e7227e 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/io/EvioHipoEvent4.java @@ -182,6 +182,7 @@ public void fillHipoEventBST(Event hipoEvent, EvioDataEvent evioEvent){ } } + @SuppressWarnings("empty-statement") public void fillHipoEventBMT(Event hipoEvent, EvioDataEvent evioEvent){ if(evioEvent.hasBank("BMT::dgtz")==true){ EvioDataBank evioBank = (EvioDataBank) evioEvent.getBank("BMT::dgtz"); @@ -191,7 +192,12 @@ public void fillHipoEventBMT(Event hipoEvent, EvioDataEvent evioEvent){ hipoADC.putByte("layer", i, (byte) evioBank.getInt("layer",i)); hipoADC.putShort("component", i, (short) evioBank.getInt("strip",i)); hipoADC.putInt("ADC", i, (int) evioBank.getInt("ADC",i)); - hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); + try { + hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); + } + catch(Exception e) { + hipoADC.putFloat("time", i, 0); + } hipoADC.putShort("ped", i, (short) 0); } hipoEvent.write(hipoADC); @@ -207,7 +213,12 @@ public void fillHipoEventFMT(Event hipoEvent, EvioDataEvent evioEvent){ hipoADC.putByte("layer", i, (byte) evioBank.getInt("layer",i)); hipoADC.putShort("component", i, (short) evioBank.getInt("strip",i)); hipoADC.putInt("ADC", i, (int) evioBank.getInt("ADC",i)); - hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); + try { + hipoADC.putFloat("time", i, (float) evioBank.getDouble("time",i)); + } + catch(Exception e) { + hipoADC.putFloat("time", i, 0); + } hipoADC.putShort("ped", i, (short) 0); } hipoEvent.write(hipoADC); From 98713f9d57b910203f2760665556dddb391875cd Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Sun, 12 Dec 2021 10:37:45 -0500 Subject: [PATCH 240/291] merged with TracTools-Test3Dev --- .../jlab/rec/cvt/banks/RecoBankReader.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 5d19077af..b1f9d1e3c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -15,7 +15,6 @@ import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.hit.FittedHit; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; import org.jlab.rec.cvt.track.StraightTrack; @@ -27,10 +26,10 @@ public class RecoBankReader { private List _cosmics; private List _SVTcrosses; private List _SVTclusters; - private List _SVTHits; + private List _SVTHits; private List _BMTcrosses; private List _BMTclusters; - private List _BMThits; + private List _BMThits; @@ -204,7 +203,7 @@ public void fetch_BMTClusters(DataEvent event) { if(!hasColumn(bank,hitStrg)) continue; int hitId = bank.getShort(hitStrg, i); - for(FittedHit hit : _BMThits) { + for(Hit hit : _BMThits) { if (hit.get_Id() == hitId) { cluster.add(hit); } @@ -443,7 +442,7 @@ public void fetch_SVTClusters(DataEvent event) { if(!hasColumn(bank,hitStrg)) continue; int hitId = bank.getShort(hitStrg, i); - for(FittedHit hit : _SVTHits) { + for(Hit hit : _SVTHits) { if (hit.get_Id() == hitId) { cluster.add(hit); } @@ -459,13 +458,13 @@ public void fetch_SVTClusters(DataEvent event) { private void fetch_SVTHits(DataEvent event) { DataBank bank = event.getBank("BSTRec::Hits"); - _SVTHits = new ArrayList(); + _SVTHits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { int layer = bank.getByte("layer", i); int sector = bank.getByte("sector", i); int strip = bank.getInt("strip", i); int id = bank.getShort("ID", i); - FittedHit hit = new FittedHit(DetectorType.BST, null, sector, layer, new Strip(strip, 0, 0)); + Hit hit = new Hit(DetectorType.BST, null, sector, layer, new Strip(strip, 0, 0)); hit.set_Id(id); hit.set_docaToTrk(bank.getFloat("fitResidual", i)); @@ -481,13 +480,13 @@ private void fetch_SVTHits(DataEvent event) { public void fetch_BMTHits(DataEvent event) { DataBank bank = event.getBank("BSTRec::Hits"); - _BMThits = new ArrayList(); + _BMThits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { int layer = bank.getByte("layer", i); int sector = bank.getByte("sector", i); int strip = bank.getInt("strip", i); int id = bank.getShort("ID", i); - FittedHit hit = new FittedHit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, new Strip(strip, 0, 0)); + Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, new Strip(strip, 0, 0)); @@ -527,4 +526,4 @@ public List get_CrossesBMT() { return _BMTcrosses; } -} \ No newline at end of file +} From aaab47a61f495c23c5f951518a5a27ab6341a2c6 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 13 Dec 2021 17:56:59 +0100 Subject: [PATCH 241/291] Added SVT TDC information from ADC=-1 events, added flag to turn of/on the KF filtering, writing out the covariance matrix for seeds and tracks --- .../kalmanfilter/helical/KFitter.java | 2 + etc/bankdefs/hipo4/cvt.json | 8 +++ .../main/java/org/jlab/rec/cvt/Constants.java | 4 +- .../org/jlab/rec/cvt/banks/HitReader.java | 56 ++++++++++++++++--- .../jlab/rec/cvt/banks/RecoBankWriter.java | 20 +++++++ .../org/jlab/rec/cvt/hit/ADCConvertor.java | 7 +-- .../jlab/rec/cvt/services/CVTRecNewKF.java | 24 ++------ .../rec/cvt/services/TracksFromTargetRec.java | 4 +- .../java/org/jlab/rec/cvt/track/Track.java | 1 + 9 files changed, 93 insertions(+), 33 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 59ed7f577..238dd0753 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -23,6 +23,7 @@ public class KFitter extends AKFitter { StateVecs sv = new StateVecs(); MeasVecs mv = new MeasVecs(); public StateVecs.StateVec finalStateVec; + public double[][] finalCovMat; public Helix KFHelix; public KFitter(Helix helix, double[][] cov, DataEvent event, Swim swimmer, double Xb, double Yb, @@ -49,6 +50,7 @@ public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { if(this.chi2tmax)) BmtStrip.setStatus(2);// calculate the strip parameters for the BMT hit } @@ -158,20 +161,52 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, if (event.hasBank("BST::adc") == true) { //bankDGTZ.show(); + // first get tdcs + Map tdcs = new HashMap<>(); + for (int i = 0; i < rows; i++) { + if(bankDGTZ.getInt("ADC", i) < 0) { + byte sector = bankDGTZ.getByte("sector", i); + byte layer = bankDGTZ.getByte("layer", i); + short strip = bankDGTZ.getShort("component", i); + double time = bankDGTZ.getFloat("time", i); + int key = DetectorDescriptor.generateHashCode(sector, layer, strip); + if(tdcs.containsKey(key)) { + if(time>24; +// int l = (ii&0x00FF0000)>>16; +// int c = (ii&0x0000FFFF); +// System.out.println("\t"+s+"/"+l+"/"+c); +// } +// bankDGTZ.show(); +// } - double angle = geo.getSectorPhi(layer, sector); + double angle = SVTGeometry.getSectorPhi(layer, sector); int hemisphere = (int) Math.signum(Math.sin(angle)); if (sector == 7 && layer > 6) { hemisphere = 1; @@ -200,7 +235,7 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, //if(adcConv.SVTADCtoDAQ(ADC[i], event)<50) // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate - Strip SvtStrip = new Strip(strip, adcConv.SVTADCtoDAQ(ADC, event), time); + Strip SvtStrip = new Strip(strip, adcConv.SVTADCtoDAQ(ADC), time); SvtStrip.set_Pitch(SVTGeometry.getPitch()); // get the strip line SvtStrip.set_Line(geo.getStrip(layer, sector, strip)); @@ -218,6 +253,11 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, if (SvtStrip.get_Edep() == 0) { SvtStrip.setStatus(1); } +// if (Constants.TIMECUTS) { +// if(time > 0 && (time < 150 || time > 350)) { +// SvtStrip.setStatus(2);// calculate the strip parameters for the BMT hit +// } +// } // SvtStrip.setStatus(status.getIntValue("status", sector, layer, strip)); // BMTGeometry implementation using the geometry package: Charles Platt diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 79a6088ed..58efbceac 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -410,6 +410,26 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { bank.setFloat("tandip", i, (float) helix.get_tandip()); bank.setFloat("z0", i, (float) (helix.get_Z0()/10.0)); bank.setFloat("d0", i, (float) (helix.get_dca()/10.0)); + double[][] covmatrix = helix.get_covmatrix(); + if (covmatrix != null) { + bank.setFloat("cov_d02", i, (float) covmatrix[0][0] ); + bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1] ); + bank.setFloat("cov_d0rho", i, (float) covmatrix[0][2] ); + bank.setFloat("cov_phi02", i, (float) covmatrix[1][1] ); + bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2] ); + bank.setFloat("cov_rho2", i, (float) covmatrix[2][2] ); + bank.setFloat("cov_z02", i, (float) covmatrix[3][3] ); + bank.setFloat("cov_tandip2", i, (float) covmatrix[4][4] ); + } else { + bank.setFloat("cov_d02", i, -999); + bank.setFloat("cov_d0phi0", i, -999); + bank.setFloat("cov_d0rho", i, -999); + bank.setFloat("cov_phi02", i, -999); + bank.setFloat("cov_phi0rho", i, -999); + bank.setFloat("cov_rho2", i, -999); + bank.setFloat("cov_z02", i, -999); + bank.setFloat("cov_tandip2", i, -999); + } bank.setFloat("xb", i, (float) (Constants.getXb()/10.0)); bank.setFloat("yb", i, (float) (Constants.getYb()/10.0)); // fills the list of cross ids for crosses belonging to that reconstructed track diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java index 2ad690b08..177217939 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/ADCConvertor.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.hit; import java.util.Random; -import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.svt.SVTParameters; @@ -20,11 +19,11 @@ public double BMTADCtoDAQ(int adc) { /** * - * @param hit Hit object * @param adc ADC value Converts ADC values to DAQ units -- used for BST * test stand analysis + * @return */ - public double SVTADCtoDAQ(int adc, DataEvent event) { + public double SVTADCtoDAQ(int adc) { if (adc == -5) { return 1; // this is for running with Geantinos. Geantinos have adc -5 } @@ -44,7 +43,7 @@ public double SVTADCtoDAQ(int adc, DataEvent event) { random.setSeed(42); int daq = returnRandomInteger(START[adc], END[adc], random); - + double value = (double) daq; /* if(event.hasBank("MC::Particle")==true) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index ad691711f..d3b2495d0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -221,15 +221,10 @@ private void loadConfiguration() { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); } - //svt stand-alone - String beamSpotConst = this.getEngineConfigString("BeamSpotConst"); - if (beamSpotConst!=null) { - System.out.println("["+this.getName()+"] run with beamSpotConst settings "+beamSpotConst+" config chosen based on yaml"); - Constants.beamSpotConstraint = Boolean.valueOf(beamSpotConst); - } - if (beamSpotConst==null) { - System.out.println("["+this.getName()+"] run with beamSpotConst settings default = false"); + if (this.getEngineConfigString("kfFilterOn")!=null) { + Constants.KFFILTERON = Boolean.valueOf(this.getEngineConfigString("kfFilterOn")); } + System.out.println("["+this.getName()+"] run with Kalman-Filter status set to "+Constants.KFFILTERON); String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { @@ -254,14 +249,7 @@ private void loadConfiguration() { System.out.println("["+this.getName()+"] run with BMT layers "+exBMTLys+"excluded config chosen based on yaml"); Constants.setBMTExclude(exBMTLys); } - - //double[][]bmtx = new double[2][2]; - //bmtx[0][0]= Math.toRadians(90); - //bmtx[0][1]= Math.toRadians(115); - //bmtx[1][0] =100; - //bmtx[1][1] =250; - //Constants.setBMTPhiZRangeExcld(bmtx); - //Constants.setBMTLayerExcld(1); + // //new clustering // String newClustering = this.getEngineConfigString("newclustering"); // @@ -296,8 +284,8 @@ private void loadConfiguration() { } if(this.getEngineConfigString("BMTTimeCuts")!=null) { - Constants.BMTTimeCuts = Boolean.parseBoolean(this.getEngineConfigString("BMTTimeCuts")); - System.out.println("["+this.getName()+"] run BMT timing cuts set to "+ Constants.BMTTimeCuts); + Constants.TIMECUTS = Boolean.parseBoolean(this.getEngineConfigString("BMTTimeCuts")); + System.out.println("["+this.getName()+"] run BMT timing cuts set to "+ Constants.TIMECUTS); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 7bf8789d9..5bae6b345 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -119,7 +119,7 @@ public boolean processEvent(DataEvent event, Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); double[][] cov = seed.get_Helix().get_covmatrix(); - + if(solenoidValue>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0 && kf.KFHelix!=null) { Track fittedTrack = new Track(seed, kf); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 1aaf6bd1f..ea9965826 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -66,6 +66,7 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) super(new Helix(kf.KFHelix.getD0(), kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), kf.KFHelix.getTanL())); this.get_helix().B = kf.KFHelix.getB(); + this.get_helix().set_covmatrix(kf.finalCovMat); this.setPXYZ(); this.setNDF(kf.NDF); this.setChi2(kf.chi2); From b95fe5981e61ab83e32837bf5bdb49dff47911ba Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 13 Dec 2021 18:59:08 -0500 Subject: [PATCH 242/291] Transform KF cov mat representation to helix cov mat representation. --- .../main/java/org/jlab/rec/cvt/track/Track.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index ea9965826..283e854ec 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -66,7 +66,20 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) super(new Helix(kf.KFHelix.getD0(), kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), kf.KFHelix.getTanL())); this.get_helix().B = kf.KFHelix.getB(); - this.get_helix().set_covmatrix(kf.finalCovMat); + double c = Constants.LIGHTVEL; + //convert from kf representation to helix repr + double alpha = 1. / (c * Math.abs(kf.KFHelix.getB())); + double[][] kfCov = kf.finalCovMat; + for(int i = 0; i<5; i++) { + for(int j = 0; j<5; j++) { + if(i==2) + kfCov[i][j]/=alpha; + if(j==2) + kfCov[i][j]/=alpha; + + } + } + this.get_helix().set_covmatrix(kfCov); this.setPXYZ(); this.setNDF(kf.NDF); this.setChi2(kf.chi2); From 390250fdd0c3ec9bdbbc327919ff654f9bb3ed13 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 13 Dec 2021 19:20:44 -0500 Subject: [PATCH 243/291] Bank for track 6x6 covariance matrix in track representation (x,y,z,px,py,pz). --- etc/bankdefs/hipo4/cvt.json | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/etc/bankdefs/hipo4/cvt.json b/etc/bankdefs/hipo4/cvt.json index 7a1ff2c60..361055490 100644 --- a/etc/bankdefs/hipo4/cvt.json +++ b/etc/bankdefs/hipo4/cvt.json @@ -88,6 +88,51 @@ {"name":"status", "type":"S", "info":"track status : 1abc (a = nb SVT crosses, b = nb BMT Z clusters, c = nb BMT C clusters, used in fit)"} ] }, + { + "name": "CVTRec::Tracks", + "group": 20500, + "item" : 27, + "info": "reconstructed CVT tracks covariance matrix in track representation", + "entries": [ + {"name":"ID", "type":"S", "info":"ID"}, + {"name":"cov_xx", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_x" }, + {"name":"cov_xy", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_y" }, + {"name":"cov_xz", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_z" }, + {"name":"cov_xpx", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_px" }, + {"name":"cov_xpy", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_py" }, + {"name":"cov_xpz", "type":"F", "info":"helical track fit covariance matrix element : delta_x.delta_pz" }, + {"name":"cov_yx", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_x" }, + {"name":"cov_yy", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_y" }, + {"name":"cov_yz", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_z" }, + {"name":"cov_ypx", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_px" }, + {"name":"cov_ypy", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_py" }, + {"name":"cov_ypz", "type":"F", "info":"helical track fit covariance matrix element : delta_y.delta_pz" }, + {"name":"cov_zx", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_x" }, + {"name":"cov_zy", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_y" }, + {"name":"cov_zz", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_z" }, + {"name":"cov_zpx", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_px" }, + {"name":"cov_zpy", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_py" }, + {"name":"cov_zpz", "type":"F", "info":"helical track fit covariance matrix element : delta_z.delta_pz" }, + {"name":"cov_pxx", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_x" }, + {"name":"cov_pxy", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_y" }, + {"name":"cov_pxz", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_z" }, + {"name":"cov_pxpx", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_px" }, + {"name":"cov_pxpy", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_py" }, + {"name":"cov_pxpz", "type":"F", "info":"helical track fit covariance matrix element : delta_px.delta_pz" }, + {"name":"cov_pyx", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_x" }, + {"name":"cov_pyy", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_y" }, + {"name":"cov_pyz", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_z" }, + {"name":"cov_pypx", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_px" }, + {"name":"cov_pypy", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_py" }, + {"name":"cov_pypz", "type":"F", "info":"helical track fit covariance matrix element : delta_py.delta_pz" }, + {"name":"cov_pzx", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_x" }, + {"name":"cov_pzy", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_y" }, + {"name":"cov_pzz", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_z" }, + {"name":"cov_pzpx", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_px" }, + {"name":"cov_pzpy", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_py" }, + {"name":"cov_pzpz", "type":"F", "info":"helical track fit covariance matrix element : delta_pz.delta_pz" } + ] + }, { "name": "CVTRec::Cosmics", "group": 20500, From fdcdf89a0027f6cdf2319644d782021a566a9dd1 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 13 Dec 2021 19:22:36 -0500 Subject: [PATCH 244/291] Bank for track 6x6 covariance matrix in track representation (x,y,z,px,py,pz). --- etc/bankdefs/hipo4/cvt.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/bankdefs/hipo4/cvt.json b/etc/bankdefs/hipo4/cvt.json index 361055490..32e06dcef 100644 --- a/etc/bankdefs/hipo4/cvt.json +++ b/etc/bankdefs/hipo4/cvt.json @@ -89,7 +89,7 @@ ] }, { - "name": "CVTRec::Tracks", + "name": "CVTRec::TrackCovMats", "group": 20500, "item" : 27, "info": "reconstructed CVT tracks covariance matrix in track representation", From f6d611afca58d640745b95b3a919d9fb29d7dec3 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Mon, 13 Dec 2021 19:42:14 -0500 Subject: [PATCH 245/291] Implemented output bank for track 6x6 covariance matrix in track representation (x,y,z,px,py,pz). --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 44 +++++++ .../jlab/rec/cvt/services/RecUtilities.java | 113 ++++++++++++++++++ .../rec/cvt/services/TracksFromTargetRec.java | 1 + .../java/org/jlab/rec/cvt/track/Track.java | 17 +++ 4 files changed, 175 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 58efbceac..d78bfbba4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -547,6 +547,46 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { return bank; } + + public DataBank fillTracksCovMatBank(DataEvent event, List trkcands) { + if (trkcands == null) { + return null; + } + if (trkcands.isEmpty()) { + return null; + } + + DataBank bank = event.createBank("CVTRec::TrackCovMats", trkcands.size()); + // an array representing the ids of the crosses that belong to the track + List crossIdxArray = new ArrayList<>(); + + for (int i = 0; i < trkcands.size(); i++) { + if(trkcands.get(i)==null || trkcands.get(i).getTrackCovMat()==null) + continue; + bank.setShort("ID", i, (short) trkcands.get(i).get_Id()); + double[][] covmatrix = trkcands.get(i).getTrackCovMat(); + if (covmatrix != null) { + String[][] names = new String[][]{ + {"cov_xx", "cov_xy", "cov_xz", "cov_xpx", "cov_xpy", "cov_xpz"}, + {"cov_yx", "cov_yy", "cov_yz", "cov_ypx", "cov_ypy", "cov_ypz"}, + {"cov_zx", "cov_zy", "cov_zz", "cov_zpx", "cov_zpy", "cov_zpz"}, + {"cov_pxx", "cov_pxy", "cov_pxz", "cov_pxpx", "cov_pxpy", "cov_pxpz"}, + {"cov_pyx", "cov_pyy", "cov_pyz", "cov_pypx", "cov_pypy", "cov_pypz"}, + {"cov_pzx", "cov_pzy", "cov_pzz", "cov_pzpx", "cov_pzpy", "cov_pzpz"} + }; + + for(int r = 0; r<6; r++) { + for(int c = 0; c<6; c++) { + bank.setFloat(names[r][c], i, (float) covmatrix[r][c] ); + } + } + } + } + + //bank.show(); + return bank; + + } /** * @@ -732,6 +772,10 @@ public void appendCVTBanks(DataEvent event, DataBank bank9 = this.fillHelicalTracksTrajectoryBank(event, trks); if (bank9 != null) event.appendBank(bank9); + + DataBank bank10 = this.fillTracksCovMatBank(event, trks); + if (bank10 != null) event.appendBank(bank10); + } public void appendCVTCosmicsBanks(DataEvent event, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index c8ab16878..87bc137ee 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -825,6 +825,119 @@ public double[] MCtrackPars(DataEvent event) { return value; } + public double[][] getCovMatInTrackRep(Track trk) { + double[][] tCov = new double[6][6]; + double [][] hCov = trk.get_helix().get_covmatrix(); + + //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) + // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | + // | d_phi_at_dca*d_dca d_phi_at_dca*d_phi_at_dca d_phi_at_dca*d_curvature 0 0 | + // | d_curvature*d_dca d_curvature*d_phi_at_dca d_curvature*d_curvature 0 0 | + // | 0 0 0 d_Z0*d_Z0 | + // | 0 0 0 0 d_tandip*d_tandip | + // + + + double pt = trk.get_Pt(); + double rho = trk.get_helix().get_curvature(); + double c = Constants.LIGHTVEL; + double Bz = pt/(c*trk.get_helix().radius()); + double d0 = trk.get_helix().get_dca(); + double phi0 = trk.get_helix().get_phi_at_dca(); + double tandip = trk.get_helix().get_tandip(); + + double delxdeld0 = -Math.sin(phi0); + double delxdelphi0 = -d0*Math.cos(phi0); + double delydeld0 = Math.cos(phi0); + double delydelphi0 = -d0*Math.sin(phi0); + + double delzdelz0 = 1; + + double delpxdelphi0 = -pt*Math.sin(phi0); + double delpxdelrho = -pt*Math.cos(phi0)/rho; + double delpydelphi0 = pt*Math.cos(phi0); + double delpydelrho = -pt*Math.sin(phi0)/rho; + + double delpzdelrho = -pt*tandip/rho; + + double delpzdeltandip = pt; + + tCov[0][0] = (hCov[0][0]*delxdeld0+hCov[1][0]*delxdelphi0)*delxdeld0 + +(hCov[0][1]*delxdeld0+hCov[1][1]*delxdelphi0)*delxdelphi0; + tCov[0][1] = (hCov[0][0]*delxdeld0+hCov[1][0]*delxdelphi0)*delydeld0 + +(hCov[0][1]*delxdeld0+hCov[1][1]*delxdelphi0)*delydelphi0; + tCov[0][2] = (hCov[0][3]*delxdeld0+hCov[1][3]*delxdelphi0); + tCov[0][3] = (hCov[0][1]*delxdeld0+hCov[1][1]*delxdelphi0)*delpxdelphi0 + +(hCov[0][2]*delxdeld0+hCov[1][2]*delxdelphi0)*delpxdelrho; + tCov[0][4] = (hCov[0][1]*delxdeld0+hCov[1][1]*delxdelphi0)*delpydelphi0 + +(hCov[0][2]*delxdeld0+hCov[1][2]*delxdelphi0)*delpydelrho; + tCov[0][5] = (hCov[0][2]*delxdeld0+hCov[1][2]*delxdelphi0)*delpzdelrho + +(hCov[0][4]*delxdeld0+hCov[1][4]*delxdelphi0)*delpzdeltandip; + + + tCov[1][0] = (hCov[0][0]*delydeld0+hCov[1][0]*delydelphi0)*delxdeld0 + +(hCov[0][1]*delydeld0+hCov[1][1]*delydelphi0)*delxdelphi0; + tCov[1][1] = (hCov[0][0]*delydeld0+hCov[1][0]*delydelphi0)*delydeld0 + +(hCov[0][1]*delydeld0+hCov[1][1]*delydelphi0)*delydelphi0; + tCov[1][2] = (hCov[0][3]*delydeld0+hCov[1][3]*delydelphi0); + tCov[1][3] = (hCov[0][1]*delydeld0+hCov[1][1]*delydelphi0)*delpxdelphi0 + +(hCov[0][2]*delydeld0+hCov[1][2]*delydelphi0)*delpxdelrho; + tCov[1][4] = (hCov[0][1]*delydeld0+hCov[1][1]*delydelphi0)*delpydelphi0 + +(hCov[0][2]*delydeld0+hCov[1][2]*delydelphi0)*delpydelrho; + tCov[1][5] = (hCov[0][2]*delydeld0+hCov[1][2]*delydelphi0)*delpzdelrho + +(hCov[0][4]*delydeld0+hCov[1][4]*delydelphi0)*delpzdeltandip; + + tCov[2][0] = hCov[2][0]*delxdeld0+hCov[2][1]*delxdelphi0; + tCov[2][1] = hCov[2][0]*delydeld0+hCov[2][1]*delydelphi0; + tCov[2][2] = hCov[2][3]; + tCov[2][3] = hCov[2][1]*delpxdelphi0+hCov[2][2]*delpxdelrho; + tCov[2][4] = hCov[2][1]*delpydelphi0+hCov[2][2]*delpydelrho; + tCov[2][5] = hCov[2][2]*delpzdelrho+hCov[2][4]*delpzdeltandip; + + tCov[3][0] = (hCov[1][0]*delpxdelphi0+hCov[2][0]*delpxdelrho)*delxdeld0 + +(hCov[1][1]*delpxdelphi0+hCov[2][1]*delpxdelrho)*delxdelphi0; + tCov[3][1] = (hCov[1][0]*delpxdelphi0+hCov[2][0]*delpxdelrho)*delydeld0 + +(hCov[1][1]*delpxdelphi0+hCov[2][1]*delpxdelrho)*delydelphi0; + tCov[3][2] = (hCov[1][3]*delpxdelphi0+hCov[2][3]*delpxdelrho); + tCov[3][3] = (hCov[1][1]*delpxdelphi0+hCov[2][1]*delpxdelrho)*delpxdelphi0 + +(hCov[1][2]*delpxdelphi0+hCov[2][2]*delpxdelrho)*delpxdelrho; + tCov[3][4] = (hCov[1][1]*delpxdelphi0+hCov[2][1]*delpxdelrho)*delpydelphi0 + +(hCov[1][2]*delpxdelphi0+hCov[2][2]*delpxdelrho)*delpydelrho; + tCov[3][5] = (hCov[1][2]*delpxdelphi0+hCov[2][2]*delpxdelrho)*delpzdelrho + +(hCov[1][4]*delpxdelphi0+hCov[2][4]*delpxdelrho)*delpzdeltandip; + + tCov[4][0] = (hCov[1][0]*delpydelphi0+hCov[2][0]*delpydelrho)*delxdeld0 + +(hCov[1][1]*delpydelphi0+hCov[2][1]*delpydelrho)*delxdelphi0; + tCov[4][1] = (hCov[1][0]*delpydelphi0+hCov[2][0]*delpydelrho)*delydeld0 + +(hCov[1][1]*delpydelphi0+hCov[2][1]*delpydelrho)*delydelphi0; + tCov[4][2] = (hCov[1][3]*delpydelphi0+hCov[2][3]*delpydelrho); + tCov[4][3] = (hCov[1][1]*delpydelphi0+hCov[2][1]*delpydelrho)*delpxdelphi0 + +(hCov[1][2]*delpydelphi0+hCov[2][2]*delpydelrho)*delpxdelrho; + tCov[4][4] = (hCov[1][1]*delpydelphi0+hCov[2][1]*delpydelrho)*delpydelphi0 + +(hCov[1][2]*delpydelphi0+hCov[2][2]*delpydelrho)*delpydelrho; + tCov[4][5] = (hCov[1][2]*delpydelphi0+hCov[2][2]*delpydelrho)*delpzdelrho + +(hCov[1][4]*delpydelphi0+hCov[2][4]*delpydelrho)*delpzdeltandip; + + tCov[5][0] = (hCov[2][0]*delpzdelrho+hCov[4][0]*delpzdeltandip)*delxdeld0 + +(hCov[2][1]*delpzdelrho+hCov[4][1]*delpzdeltandip)*delxdelphi0; + tCov[5][1] = (hCov[2][0]*delpzdelrho+hCov[4][0]*delpzdeltandip)*delydeld0 + +(hCov[2][1]*delpzdelrho+hCov[4][1]*delpzdeltandip)*delydelphi0; + tCov[5][2] = (hCov[2][3]*delpzdelrho+hCov[4][3]*delpzdeltandip); + tCov[5][3] = (hCov[2][1]*delpzdelrho+hCov[4][1]*delpzdeltandip)*delpxdelphi0 + +(hCov[2][2]*delpzdelrho+hCov[4][2]*delpzdeltandip)*delpxdelrho; + tCov[5][4] = (hCov[2][1]*delpzdelrho+hCov[4][1]*delpzdeltandip)*delpydelphi0 + +(hCov[2][2]*delpzdelrho+hCov[4][2]*delpzdeltandip)*delpydelrho; + tCov[5][5] = (hCov[2][2]*delpzdelrho+hCov[4][2]*delpzdeltandip)*delpzdelrho + +(hCov[2][4]*delpzdelrho+hCov[4][4]*delpzdeltandip)*delpzdeltandip; + + //for (int k = 0; k < 6; k++) { + // System.out.println(tCov[k][0]+" "+tCov[k][1]+" "+tCov[k][2]+" "+tCov[k][3]+" "+tCov[k][4]+" "+tCov[k][5]); + //} + //System.out.println(" "); + + return tCov; + } + } \ No newline at end of file diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 5bae6b345..4835b148b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -221,6 +221,7 @@ public boolean processEvent(DataEvent event, tracks.get(it).set_Id(id); tracks.get(it).update_Crosses(id, SVTGeom, BMTGeom); tracks.get(it).update_Clusters(id, SVTGeom); + tracks.get(it).setTrackCovMat(recUtil.getCovMatInTrackRep(tracks.get(it))); } } for(int det = 0; det<2; det++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 283e854ec..a7f754303 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -400,6 +400,21 @@ public int getStatus() { return 1000+nSVT*100+nBMTZ*10+nBMTC; } + private double[][] trackCovMat; + /** + * @return the trackCovMat + */ + public double[][] getTrackCovMat() { + return trackCovMat; + } + + /** + * @param trackCovMat the trackCovMat to set + */ + public void setTrackCovMat(double[][] trackCovMat) { + this.trackCovMat = trackCovMat; + } + public String toString() { String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, phi=%.3f deg, NDF=%d, chi2=%.3f\n", this.get_Id(), this.get_Q(), this.get_P(), this.get_Pt(), Math.toDegrees(this.get_helix().get_phi_at_dca()), @@ -408,4 +423,6 @@ public String toString() { return str; } + + } From 5e6417bc58ab13e73302afc0e0a5808a8fafb84f Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 14 Dec 2021 17:18:02 +0100 Subject: [PATCH 246/291] added error to SVT cluster bank --- etc/bankdefs/hipo4/bst.json | 1 + .../cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java | 1 + 2 files changed, 2 insertions(+) diff --git a/etc/bankdefs/hipo4/bst.json b/etc/bankdefs/hipo4/bst.json index 0f3210b07..4ccd98ea0 100755 --- a/etc/bankdefs/hipo4/bst.json +++ b/etc/bankdefs/hipo4/bst.json @@ -33,6 +33,7 @@ {"name":"seedE", "type":"F", "info":"energy of the seed "}, {"name":"seedStrip", "type":"I", "info":"seed strip"}, {"name":"centroid", "type":"F", "info":"centroid strip number"}, + {"name":"centroidError", "type":"F", "info":"centroid spatial error"}, {"name":"centroidResidual","type":"F", "info":"centroid residual"}, {"name":"seedResidual", "type":"F", "info":"seed residual"}, {"name":"Hit1_ID", "type":"S", "info":"Index of hit 1 in cluster"}, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 58efbceac..04fe5e2ed 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -93,6 +93,7 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); + bank.setFloat("centroidError", i, (float) cluslist.get(i).get_Resolution()); bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); bank.setShort("trkID", i, (short) cluslist.get(i).get_AssociatedTrackID()); From 15d323042f2cb640bab0b5b0cb8c5f339a506cea Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 14 Dec 2021 19:51:00 +0100 Subject: [PATCH 247/291] recovering beam-spot yaml variable --- .../src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index d3b2495d0..0447b586d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -221,6 +221,11 @@ private void loadConfiguration() { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); } + if (this.getEngineConfigString("BeamSpotConst")!=null) { + Constants.beamSpotConstraint = Boolean.valueOf(this.getEngineConfigString("BeamSpotConst")); + } + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.beamSpotConstraint); + if (this.getEngineConfigString("kfFilterOn")!=null) { Constants.KFFILTERON = Boolean.valueOf(this.getEngineConfigString("kfFilterOn")); } From b46cd25b26684a67b963d0b38c4435c010bd9f46 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 16 Dec 2021 11:38:42 -0500 Subject: [PATCH 248/291] Fix for unit direction vector in trajectory bank --- .../rec/cvt/trajectory/TrajectoryFinder.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 7441261e1..3c58e8d98 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -218,9 +218,10 @@ public Trajectory findTrajectory(Track trk, inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius, Constants.SWIMACCURACYBMT/10); if(inters==null) break; double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); + double Ra = Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5]); path = path + inters[6]; //if(r>(radius - BMTConstants.LYRTHICKN)/10) { - StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); + StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3]/Ra, inters[4]/Ra, inters[5]/Ra); stVec.set_planeIdx(l); // double phiPos = Math.atan2(stVec.y(),stVec.x()); // //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); @@ -265,10 +266,11 @@ public Trajectory findTrajectory(Track trk, if(inters!=null) { // update parameters double r = Math.sqrt(inters[0]*inters[0]+inters[1]*inters[1]); - intersPhi = Math.atan2(inters[4], inters[3]); - intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); + intersPhi = Math.atan2(inters[4], inters[3]); + double Ra = Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5]); + intersTheta = Math.acos(inters[5]/Ra); path = path + inters[6]; - StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); + StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3]/Ra, inters[4]/Ra, inters[5]/Ra); stVec.set_SurfaceDetector(DetectorType.CTOF.getDetectorId()); stVec.set_SurfaceSector(1); stVec.set_SurfaceLayer(1); @@ -283,9 +285,10 @@ public Trajectory findTrajectory(Track trk, // CND if(cnd_geo!=null && inters!=null) { // don't swim to CND if swimming to CTOF failed for(int ilayer=0; ilayer Date: Thu, 16 Dec 2021 11:40:00 -0500 Subject: [PATCH 249/291] Exit fit if track curvature goes to zero. --- .../kalmanfilter/helical/KFitter.java | 4 ++++ .../kalmanfilter/helical/StateVecs.java | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 238dd0753..305a84737 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -49,6 +49,10 @@ public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { this.chi2=this.calc_chi2(swimmer, sv, mv); if(this.chi2 Date: Thu, 16 Dec 2021 11:41:56 -0500 Subject: [PATCH 250/291] Fill empty cross slots with id -1 in track bank. --- .../jlab/rec/cvt/banks/RecoBankWriter.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 9d4661434..18df2b15b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -434,12 +434,19 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { bank.setFloat("xb", i, (float) (Constants.getXb()/10.0)); bank.setFloat("yb", i, (float) (Constants.getYb()/10.0)); // fills the list of cross ids for crosses belonging to that reconstructed track + for (int j = 0; j < 9; j++) { + String hitStrg = "Cross"; + hitStrg += (j + 1); + hitStrg += "_ID"; + bank.setShort(hitStrg, i, (short) -1); + } for (int j = 0; j < seeds.get(i).get_Crosses().size(); j++) { if(j<9) { String hitStrg = "Cross"; hitStrg += (j + 1); hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - bank.setShort(hitStrg, i, (short) seeds.get(i).get_Crosses().get(j).get_Id()); + if(seeds.get(i).get_Crosses().get(j).get_Id()!=0) + bank.setShort(hitStrg, i, (short) seeds.get(i).get_Crosses().get(j).get_Id()); } } bank.setFloat("circlefit_chi2_per_ndf", i, (float) seeds.get(i).get_circleFitChi2PerNDF()); @@ -528,12 +535,20 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { bank.setFloat("pathlength", i, (float) (trkcands.get(i).get_PathToCTOF() / 10.)); // conversion to cm } // fills the list of cross ids for crosses belonging to that reconstructed track + for (int j = 0; j < 9; j++) { + String hitStrg = "Cross"; + hitStrg += (j + 1); + hitStrg += "_ID"; + bank.setShort(hitStrg, i, (short) -1); + + } for (int j = 0; j < trkcands.get(i).size(); j++) { if(j<9) { String hitStrg = "Cross"; hitStrg += (j + 1); hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); + if(trkcands.get(i).get(j).get_Id()!=0) + bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); } } bank.setShort("status", i, (short) ((short) trkcands.get(i).getStatus())); @@ -628,7 +643,12 @@ public DataBank fillStraightTracksBank(DataEvent event, List cosm for (int j = 0; j < cosmics.get(i).size(); j++) { crossIdxArray.add(cosmics.get(i).get(j).get_Id()); } - + for (int j = 0; j < 18; j++) { + String hitStrg = "Cross"; + hitStrg += (j + 1); + hitStrg += "_ID"; + bank.setShort(hitStrg, i, (short) -1); + } for (int j = 0; j < crossIdxArray.size(); j++) { if(j<18) { From d6e2b3ad76e4bf3474dbbf5dfa00704278e68b23 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 16 Dec 2021 13:45:08 -0500 Subject: [PATCH 251/291] Settings for rescaling the seed covariance matrix. --- .../main/java/org/jlab/rec/cvt/Constants.java | 18 ++++++++- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 38 ++++++++++++------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 6e7bcd395..a4e93af4e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -8,7 +8,23 @@ import org.jlab.clas.tracking.utilities.MatrixOps.Libr; public class Constants { - + static double covd0d0S = 1./1000.; + static double covd0phi0S = 1./10.; + static double covd0rhoS = 1./10.; + static double covphi0phi0S = 1./100.; + static double covphi0rhoS = 1./10.; + static double covrho0rhoS = 1./100.; + static double covz0z0S = 1./100.; + static double covtanLtanLS = 1.; + + public static double[][] seedCovMatScaleFac = new double[][]{ + {covd0d0S, covd0phi0S, covd0rhoS,1.0,1.0}, + {covd0phi0S,covphi0phi0S, covphi0rhoS,1.0,1.0}, + {covd0rhoS, covphi0rhoS, covrho0rhoS,1.0,1.0}, + {1.0,1.0,1.0, covz0z0S,1.0}, + {1.0,1.0,1.0,1.0, covtanLtanLS} + }; + /** * BMTConstants used in the reconstruction */ diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index 5ee11a43c..581b9bd32 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.svt.SVTGeometry; @@ -155,7 +156,6 @@ public FitStatus fit(List X, List Y, List Z, List X, List Y, List Z, List Date: Thu, 16 Dec 2021 13:46:44 -0500 Subject: [PATCH 252/291] Settings for rescaling the track covariance matrix from the KFit. --- .../cvt/src/main/java/org/jlab/rec/cvt/track/Track.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index a7f754303..a1f053ea7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -79,7 +79,15 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) } } + + //kfCov[0][0]/=100; + //kfCov[3][3]/=100; + kfCov[1][1]*=10; + kfCov[2][2]*=10; + kfCov[4][4]*=10; + this.get_helix().set_covmatrix(kfCov); + //this.get_helix().set_covmatrix(seed.get_Helix().get_covmatrix()); this.setPXYZ(); this.setNDF(kf.NDF); this.setChi2(kf.chi2); From c53e1dbbc403c57446cb1c76bf31695bf6c4e6a1 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 16 Dec 2021 14:24:37 -0500 Subject: [PATCH 253/291] Settings for rescaling the track covariance matrix from the KFit. --- .../src/main/java/org/jlab/rec/cvt/track/Track.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index a1f053ea7..a3ee4961f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -80,11 +80,11 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) } } - //kfCov[0][0]/=100; - //kfCov[3][3]/=100; - kfCov[1][1]*=10; - kfCov[2][2]*=10; - kfCov[4][4]*=10; + //kfCov[0][0]/=10; + //kfCov[3][3]/=10; + //kfCov[1][1]*=10; + //kfCov[2][2]*=10; + //kfCov[4][4]*=10; this.get_helix().set_covmatrix(kfCov); //this.get_helix().set_covmatrix(seed.get_Helix().get_covmatrix()); From 331de561867a0c60fd774d382c120b84648acf75 Mon Sep 17 00:00:00 2001 From: Veronique Ziegler Date: Thu, 16 Dec 2021 14:26:34 -0500 Subject: [PATCH 254/291] Fix for zero curvature tracks. Fix for BMT layer exclusion to search for clusters on track only for the excluded layer and range defined in YAML. --- .../src/main/java/org/jlab/rec/cvt/cluster/Cluster.java | 1 + .../src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java | 2 ++ .../java/org/jlab/rec/cvt/services/RecUtilities.java | 4 ++-- .../org/jlab/rec/cvt/services/TracksFromTargetRec.java | 8 +++++++- .../src/main/java/org/jlab/rec/cvt/trajectory/Helix.java | 9 ++++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index 233495743..43817a209 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -63,6 +63,7 @@ public class Cluster extends ArrayList implements Comparable { private Vector3D _l; //svt vector along cluster pseudo-strip direction or bmt vector along cluster pseudo-strip direction in the middle of the arc private Vector3D _s; //svt vector perpendicular to cluster pseudo-strip direction in the module plane or bmt vector perpendicular to cluster pseudo-strip in direction tangential to the cluster surface in the middle of the arc private Vector3D _n; //svt vector normal to the cluster module plane or bmt vector normal to the cluster surface in the middle of the arc + public boolean flagForExclusion = false; public Cluster(DetectorType detector, BMTType type, int sector, int layer, int cid) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 9d10e3a75..a55445803 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -48,6 +48,7 @@ public ArrayList> findCrosses(List clusters, SVTGeomet if(cl.get_Layer()==Constants.getBMTLayerExcld() && cl.get_Phi0()>Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][0]) && cl.get_Phi0()<=Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][1]) ) { + cl.flagForExclusion = true; rbmt_Zlayrclus.add(cl); } } @@ -58,6 +59,7 @@ public ArrayList> findCrosses(List clusters, SVTGeomet if(cl.get_Layer()==Constants.getBMTLayerExcld() && cl.get_Z()>Constants.getBMTPhiZRangeExcld()[1][0] && cl.get_Z()<=Constants.getBMTPhiZRangeExcld()[1][1]) { + cl.flagForExclusion = true; rbmt_Clayrclus.add(cl); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 87bc137ee..0cd5e3628 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -428,7 +428,7 @@ public List FindClustersOnTrk(List allClusters, List se // if trajectory is valid, look for missing clusters if(traj!=null && bgeo.inDetector(layer, sector, traj)) { double doca = Double.POSITIVE_INFINITY; - // loop over all clusters in the same sector and layer that are noy associated to s track + // loop over all clusters in the same sector and layer that are not associated to s track for(Cluster cls : allClusters) { if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { double clsDoca = cls.residual(traj); @@ -451,7 +451,7 @@ public List FindClustersOnTrk(List allClusters, List se // if any lost cluster with doca better than the seed is found, save it List clustersOnTrack = new ArrayList<>(); for(Entry entry : clusterMap.entrySet()) { - if(entry.getValue().get_AssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); + if(entry.getValue().get_AssociatedTrackID()==-1 && entry.getValue().flagForExclusion) clustersOnTrack.add(entry.getValue()); } return clustersOnTrack; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 4835b148b..d8303b588 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -226,7 +226,13 @@ public boolean processEvent(DataEvent event, } for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { - if(c.get_AssociatedTrackID()==-1) c.reset(SVTGeom); + if(c.get_AssociatedTrackID()==-1) { + c.reset(SVTGeom); + if(det==1 && c.get_Id()>2000) { //if matched cross failed tracking resol requirements, reset its id + c.set_Id(c.get_Id()-1000); + } + } + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index 2064bf7f5..9617e9969 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -27,6 +27,7 @@ public class Helix { private double _Z0; // intersect of the helix axis with the z-axis private double _tandip; // tangent of the dip angle private double[][] _covmatrix = new double[5][5]; + public boolean failed = false; //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | // | d_phi_at_dca*d_dca d_phi_at_dca*d_phi_at_dca d_phi_at_dca*d_curvature 0 0 | @@ -42,6 +43,9 @@ public Helix(double dca, double phi_at_doca, double curvature, double Z0, double set_Z0(Z0); set_tandip(tandip); set_covmatrix(covmatrix); + if(curvature==0) { + failed = true; + } } @@ -51,6 +55,9 @@ public Helix(double dca, double phi_at_doca, double curvature, double Z0, double set_curvature(curvature); set_Z0(Z0); set_tandip(tandip); + if(curvature==0) { + failed = true; + } } @@ -126,7 +133,7 @@ public double sintheta() { public double radius() { double C = Math.abs(_curvature); if (C == 0) { - System.err.println("Helix Curvature should not be zero"); + System.err.println("Helix Curvature should not be zero "); return 0; } return 1. / C; From 295ee195385d11249322e688d9fee84f0894742b Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 20 Dec 2021 13:05:15 +0100 Subject: [PATCH 255/291] Removed unneccessary check on seed and track IDs in BankWriter --- .../main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 18df2b15b..3c3f66815 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -445,8 +445,7 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { String hitStrg = "Cross"; hitStrg += (j + 1); hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - if(seeds.get(i).get_Crosses().get(j).get_Id()!=0) - bank.setShort(hitStrg, i, (short) seeds.get(i).get_Crosses().get(j).get_Id()); + bank.setShort(hitStrg, i, (short) seeds.get(i).get_Crosses().get(j).get_Id()); } } bank.setFloat("circlefit_chi2_per_ndf", i, (float) seeds.get(i).get_circleFitChi2PerNDF()); @@ -547,8 +546,7 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { String hitStrg = "Cross"; hitStrg += (j + 1); hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - if(trkcands.get(i).get(j).get_Id()!=0) - bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); + bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); } } bank.setShort("status", i, (short) ((short) trkcands.get(i).getStatus())); From 61ec23ddf5d1f85bb5301ec26002c5644d860410 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 20 Dec 2021 13:58:20 +0100 Subject: [PATCH 256/291] check circle fit convergence and propagate fit status; drop seeds whose fit fails with not beam-spot constraint --- .../main/java/org/jlab/rec/cvt/Constants.java | 2 + .../org/jlab/rec/cvt/fit/CircleFitter.java | 4 +- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 2 +- .../jlab/rec/cvt/services/RecUtilities.java | 43 ++++++++++--------- .../rec/cvt/services/TracksFromTargetRec.java | 7 ++- .../java/org/jlab/rec/cvt/track/Seed.java | 5 ++- .../rec/cvt/track/TrackCandListFinder.java | 2 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 4 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 7 +-- .../org/jlab/rec/cvt/trajectory/Helix.java | 9 ---- 10 files changed, 43 insertions(+), 42 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index a4e93af4e..26ab461e9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -55,6 +55,8 @@ public class Constants { public static final double COSMICSMINRESIDUALX = 120; // in mm public static final double COSMICSMINRESIDUALZ = 12; // in mm + public static final int SEEDFITITERATIONS = 5; + public static boolean SVTOnly = false; public static boolean svtSeeding = true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index fdd1cf58e..125bed4f1 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -226,7 +226,9 @@ public boolean fitStatus(List xm, List ym, List wm, int _dca = docaFit + Delta_doca; _xpca = _xx0 + _dca * Math.sin(phiFit); _ypca = _yy0 - _dca * Math.cos(phiFit); - + if(_rho==0 || Double.isNaN(_rho)) + return false; + // corrected chi2 _chi2 = (1. + _rho * _dca) * (1. + _rho * _dca) * (1. - kappa * delta) * _chi2; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index 581b9bd32..5e260d291 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -199,7 +199,7 @@ public FitStatus fit(List X, List Y, List Z, List reFitSeed(Seed bseed, seedlist.addAll(trseed.findSeed(refi, refib, SVTGeom, BMTGeom, false)); return seedlist; } - public void reFitCircle(Seed mseed,SVTGeometry SVTGeom, BMTGeometry BMTGeom, int iter) { - List Xs = new ArrayList() ; - List Ys = new ArrayList() ; - List Ws = new ArrayList() ; - List seedcrs = new ArrayList(); + public boolean reFitCircle(Seed seed,SVTGeometry SVTGeom, BMTGeometry BMTGeom, int iter) { + boolean fitStatus = false; + + List Xs = new ArrayList<>() ; + List Ys = new ArrayList<>() ; + List Ws = new ArrayList<>() ; CircleFitter circlefit = new CircleFitter(); - CircleFitPars pars = null; for(int i = 0; i< iter; i++) { Xs.clear(); Ys.clear(); Ws.clear(); - seedcrs = mseed.get_Crosses(); + List seedCrosses = seed.get_Crosses(); - for (int j = 0; j < seedcrs.size(); j++) { - if (seedcrs.get(j).get_Type() == BMTType.C) + for (int j = 0; j < seedCrosses.size(); j++) { + if (seedCrosses.get(j).get_Type() == BMTType.C) continue; - Xs.add(seedcrs.get(j).get_Point().x()); - Ys.add(seedcrs.get(j).get_Point().y()); - Ws.add(1. / (seedcrs.get(j).get_PointErr().x()*seedcrs.get(j).get_PointErr().x() - +seedcrs.get(j).get_PointErr().y()*seedcrs.get(j).get_PointErr().y())); + Xs.add(seedCrosses.get(j).get_Point().x()); + Ys.add(seedCrosses.get(j).get_Point().y()); + Ws.add(1. / (seedCrosses.get(j).get_PointErr().x()*seedCrosses.get(j).get_PointErr().x() + +seedCrosses.get(j).get_PointErr().y()*seedCrosses.get(j).get_PointErr().y())); } - boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); - pars = circlefit.getFit(); - if(pars.rho()!=0) { - mseed.get_Helix().set_curvature(pars.rho()); - } - mseed.get_Helix().set_dca(-pars.doca()); - mseed.get_Helix().set_phi_at_dca(pars.phi()); + fitStatus = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); - mseed.update_Crosses(SVTGeom, BMTGeom); + if(fitStatus) { + CircleFitPars pars = circlefit.getFit(); + seed.get_Helix().set_curvature(pars.rho()); + seed.get_Helix().set_dca(-pars.doca()); + seed.get_Helix().set_phi_at_dca(pars.phi()); + seed.update_Crosses(SVTGeom, BMTGeom); + } } + return fitStatus; } public List reFit(List seedlist, diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index d8303b588..61826ab68 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -69,15 +69,18 @@ public boolean processEvent(DataEvent event, if(Constants.svtSeeding || Constants.excludeLayers) { TrackSeeder trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); trseed2.unUsedHitsOnly = true; - seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); // RDV check for overlaps + seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); if(Constants.excludeLayers==true) { seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed, trseed2); } } if(Constants.beamSpotConstraint==false) { + List failed = new ArrayList<>(); for(Seed s : seeds) { - recUtil.reFitCircle(s,SVTGeom, BMTGeom, 5); + if(!recUtil.reFitCircle(s,SVTGeom, BMTGeom, Constants.SEEDFITITERATIONS)) + failed.add(s); } + seeds.removeAll(failed); } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index 12706f152..cd5369d47 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -13,6 +13,7 @@ import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.HelicalTrackFitter; +import org.jlab.rec.cvt.fit.HelicalTrackFitter.FitStatus; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Helix; @@ -302,9 +303,9 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { ErrRt.add((double) 0.1); - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + FitStatus fitStatus = fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); - if (fitTrk.get_helix() == null) { + if (fitStatus!=FitStatus.Successful || fitTrk.get_helix() == null) { return false; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 736241fc4..8e55e47ff 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -218,7 +218,7 @@ public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) } /** - * + * Not used * @param crossList the input list of crosses * @return an array list of track candidates in the SVT */ diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index 52699da04..d31e1f903 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -320,7 +320,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { for(Seed mseed : seedScan) { boolean fitStatus = false; if(mseed.get_Crosses().size()>=3) - fitStatus = mseed.fit(this.sgeo, this.bgeo, 5, false, this.bfield); + fitStatus = mseed.fit(this.sgeo, this.bgeo, Constants.SEEDFITITERATIONS, false, this.bfield); if (fitStatus) { List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(mseed, bmtC_crosses); BMTmatches.clear(); @@ -333,7 +333,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { double chi2_Line = Double.POSITIVE_INFINITY; for (Seed bseed : BMTmatches) { //refit using the BMT - fitStatus = bseed.fit(this.sgeo, this.bgeo, 5, false, this.bfield); + fitStatus = bseed.fit(this.sgeo, this.bgeo, Constants.SEEDFITITERATIONS, false, this.bfield); if (fitStatus && bseed.get_circleFitChi2PerNDF() findSeed(List svt_crosses, List bmt_crosses) { //// TODO: TEST TEST TEST // test if a first fit to move the SVT crosses helps // for( ArrayList acr : xytracks ) { -// Track xycand = fit(acr, svt_geo, 5, false); +// Track xycand = fit(acr, svt_geo, Constants.SEEDFITITERATIONS, false); // // update // } @@ -236,9 +237,9 @@ public List findSeed(List svt_crosses, List bmt_crosses) { // System.out.println(seedlist.size()); for (int s = 0; s < seedCrosses.size(); s++) { // Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters -// Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, 5, false, swimmer); +// Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, Constants.SEEDFITITERATIONS, false, swimmer); Seed candSeed = new Seed(seedCrosses.get(s)); - boolean fitStatus = candSeed.fit(sgeo, bgeo, 5, false, bfield); + boolean fitStatus = candSeed.fit(sgeo, bgeo, Constants.SEEDFITITERATIONS, false, bfield); if (fitStatus && candSeed.isGood()) { cands.add(candSeed); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index 9617e9969..298e18f58 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -27,7 +27,6 @@ public class Helix { private double _Z0; // intersect of the helix axis with the z-axis private double _tandip; // tangent of the dip angle private double[][] _covmatrix = new double[5][5]; - public boolean failed = false; //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | // | d_phi_at_dca*d_dca d_phi_at_dca*d_phi_at_dca d_phi_at_dca*d_curvature 0 0 | @@ -43,10 +42,6 @@ public Helix(double dca, double phi_at_doca, double curvature, double Z0, double set_Z0(Z0); set_tandip(tandip); set_covmatrix(covmatrix); - if(curvature==0) { - failed = true; - } - } public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip ) { @@ -55,10 +50,6 @@ public Helix(double dca, double phi_at_doca, double curvature, double Z0, double set_curvature(curvature); set_Z0(Z0); set_tandip(tandip); - if(curvature==0) { - failed = true; - } - } public double get_dca() { From f604591f665e1586a654bc3a091b6b5c1aef5801 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 23 Dec 2021 00:22:19 +0100 Subject: [PATCH 257/291] revert to no-beam-spot constraint for KF, fixed light speed units in KF Helix class, update scaling factor for seeding covariance matrix, fixed bug in multiple-scattering equation, beam spot constraint and timing cuts turned off by default, added yaml variables for turning on/off the KF and intialize from MC, other yaml valiable naming changes --- .../clas/tracking/kalmanfilter/AKFitter.java | 2 +- .../clas/tracking/kalmanfilter/AMeasVecs.java | 4 +- .../kalmanfilter/helical/MeasVecs.java | 6 ++ .../kalmanfilter/helical/StateVecs.java | 59 +++++++++++-------- .../kalmanfilter/straight/StateVecs.java | 2 +- .../jlab/clas/tracking/trackrep/Helix.java | 10 ++-- .../main/java/org/jlab/rec/cvt/Constants.java | 37 ++++++------ .../org/jlab/rec/cvt/banks/HitReader.java | 4 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 20 +++---- .../org/jlab/rec/cvt/fit/CircleFitter.java | 2 +- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 45 +++++++------- .../java/org/jlab/rec/cvt/fit/LineFitter.java | 4 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 15 +++-- .../jlab/rec/cvt/services/RecUtilities.java | 23 ++++---- .../rec/cvt/services/TracksFromTargetRec.java | 14 +++-- .../java/org/jlab/rec/cvt/track/Track.java | 1 - 16 files changed, 134 insertions(+), 114 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index 8d0375e8f..567760c2d 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -66,7 +66,7 @@ public void runFitterIter(Swim swimmer, int it, AStateVecs sv, AMeasVecs mv) { } sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), swimmer); - //if(k>1) + if(k>1) this.filter(k - 1, swimmer, -1, sv, mv); } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java index 935c2656f..a6b0e675e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -51,9 +51,7 @@ public double dh(int k, StateVec stateVec) { if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); - p.setZ(0); - value = p.distance(stateVec.x, stateVec.y, 0); - + value = p.distance(stateVec.x, stateVec.y, stateVec.z); } if( this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHARC) { double phia = this.measurements.get(stateVec.k).surface.arc.theta(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 0454ee23a..21f46ed5e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -19,6 +19,11 @@ public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim delta_d_a[2]=2*sqrt_epsilon*(stateVec.kappa+1); delta_d_a[3]=2*sqrt_epsilon*(stateVec.dz+1); delta_d_a[4]=2*sqrt_epsilon*(stateVec.tanL+1); +// delta_d_a[0]=2*0.2; +// delta_d_a[1]=2*Math.toRadians(0.1); +// delta_d_a[2]=2*0.02*(stateVec.kappa); +// delta_d_a[3]=2*0.2; +// delta_d_a[4]=2*0.01*(stateVec.tanL+1); for(int i = 0; i < getHval().length; i++) getHval()[i] = 0; @@ -48,6 +53,7 @@ public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim SVplus = sv.newStateVecAtMeasSite(stateVec.k, SVplus, mv, swimmer, false); SVminus = sv.newStateVecAtMeasSite(stateVec.k, SVminus, mv, swimmer, false); Hval[i] = (this.h(stateVec.k, SVplus) - this.h(stateVec.k, SVminus)) / getDelta_d_a()[i] ; +// System.out.println(i + " " + getDelta_d_a()[i] + " " + this.h(stateVec.k, SVplus) + " " + this.h(stateVec.k, SVminus) + " " + Hval[i]); } return getHval(); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index f2db7ca02..2947465ea 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -54,31 +54,38 @@ public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec Bf.set(); kVec.alpha = Bf.alpha; - if(k==0 && this.straight==false) { - double invKappa = 1. / Math.abs(kVec.kappa); - double px = -invKappa * Math.sin(kVec.phi0 ); - double py = invKappa * Math.cos(kVec.phi0 ); - double pz = invKappa * kVec.tanL; - int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); - double accuracy = mv.surface.swimAccuracy/units; - swim.SetSwimParameters(x/units, y/units, z/units, px, py, pz, ch); - swimPars = swim.SwimRho(50./units, accuracy); - if(swimPars==null) - return null; - swim.SetSwimParameters(swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], -ch); - Vector3D norm = new Vector3D(px,py,pz).asUnit(); - Point3D point = new Point3D(mv.surface.plane.point().x()/units, - mv.surface.plane.point().y()/units, - mv.surface.plane.point().z()/units); - swimPars = swim.SwimPlane(norm,point,accuracy); - if(swimPars==null) - return null; - for(int j =0; j < 3; j++) { - swimPars[j]*=units; - } - kVec.x = swimPars[0]; - kVec.y = swimPars[1]; - kVec.z = swimPars[2]; +// if(k==0 && this.straight==false) { +// double invKappa = 1. / Math.abs(kVec.kappa); +// double px = -invKappa * Math.sin(kVec.phi0 ); +// double py = invKappa * Math.cos(kVec.phi0 ); +// double pz = invKappa * kVec.tanL; +// int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); +// double accuracy = mv.surface.swimAccuracy/units; +// swim.SetSwimParameters(x/units, y/units, z/units, px, py, pz, ch); +// swimPars = swim.SwimRho(50./units, accuracy); +// if(swimPars==null) +// return null; +// swim.SetSwimParameters(swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], -ch); +// Vector3D norm = new Vector3D(px,py,pz).asUnit(); +// Point3D point = new Point3D(mv.surface.plane.point().x()/units, +// mv.surface.plane.point().y()/units, +// mv.surface.plane.point().z()/units); +// swimPars = swim.SwimPlane(norm,point,accuracy); +// if(swimPars==null) +// return null; +// for(int j =0; j < 3; j++) { +// swimPars[j]*=units; +// } +// kVec.x = swimPars[0]; +// kVec.y = swimPars[1]; +// kVec.z = swimPars[2]; +// } + if(k==0) { + value[0] = x; + value[1] = y; + value[2] = z; + value[3] = 0.0; + return value; } if(this.straight) { @@ -411,7 +418,7 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { t_ov_X0 = t_ov_X0 / cosEntranceAngle; if(t_ov_X0>0) { // Highland-Lynch-Dahl formula - sctRMS = (0.136/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* + sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* (1 + 0.038 * Math.log(t_ov_X0)); //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* // (1 + Math.log(t_ov_X0)/9.); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index 73c0efb81..e1417ea67 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -216,7 +216,7 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { t_ov_X0 = t_ov_X0 / cosEntranceAngle; if(t_ov_X0!=0) { // Highland-Lynch-Dahl formula - sctRMS = (0.136/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* + sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* (1 + 0.038 * Math.log(t_ov_X0)); //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* // (1 + Math.log(t_ov_X0)/9.); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index fe46cb845..a9c49e6f9 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -54,7 +54,7 @@ public Helix(double d0, double phi0, double omega, double z0, double tanL, _yb = yb; this.units = unit; this.setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL*unit.unit); + setLIGHTVEL(LIGHTVEL/unit.unit); this.Update(); } @@ -65,8 +65,8 @@ public Helix(double x0, double y0, double z0, double px0, double py0, double pz0 double pt = Math.sqrt(px0*px0 + py0*py0); this.units = unit; setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL*unit.unit); - _R = pt/(B*LIGHTVEL*unit.unit); + setLIGHTVEL(LIGHTVEL/unit.unit); + _R = pt/(B*LIGHTVEL/unit.unit); _cosphi0 = px0/pt; _sinphi0 = py0/pt; _phi0 = Math.atan2(py0, px0); @@ -627,8 +627,8 @@ public void setLIGHTVEL(double aLIGHTVEL) { LightVel = aLIGHTVEL; } - public static final double LIGHTVEL = 0.0000299792458; // velocity of light (cm/ns) - conversion factor from radius in mm to momentum in GeV/c + public static final double LIGHTVEL = 0.00299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c - private static double LightVel = 0.0000299792458; // velocity of light (cm/ns) - conversion factor from radius in mm to momentum in GeV/c + private static double LightVel = 0.00299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c private static double unitScale = 1; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 26ab461e9..c8071ea24 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -8,22 +8,6 @@ import org.jlab.clas.tracking.utilities.MatrixOps.Libr; public class Constants { - static double covd0d0S = 1./1000.; - static double covd0phi0S = 1./10.; - static double covd0rhoS = 1./10.; - static double covphi0phi0S = 1./100.; - static double covphi0rhoS = 1./10.; - static double covrho0rhoS = 1./100.; - static double covz0z0S = 1./100.; - static double covtanLtanLS = 1.; - - public static double[][] seedCovMatScaleFac = new double[][]{ - {covd0d0S, covd0phi0S, covd0rhoS,1.0,1.0}, - {covd0phi0S,covphi0phi0S, covphi0rhoS,1.0,1.0}, - {covd0rhoS, covphi0rhoS, covrho0rhoS,1.0,1.0}, - {1.0,1.0,1.0, covz0z0S,1.0}, - {1.0,1.0,1.0,1.0, covtanLtanLS} - }; /** * BMTConstants used in the reconstruction @@ -31,6 +15,22 @@ public class Constants { Constants() { } + private static final double COVD0D0 = 1./50.; + private static final double COVD0PHI0 = 1./50.; + private static final double COVD0RHO = 1./50.; + private static final double COVPHI0PHI0 = 1./50.; + private static final double COVPHI0RHO = 1./50.; + private static final double COVRHORHO = 1./50.; + private static final double COVZ0Z0 = 1.; + private static final double CONVTANLTANL = 1.; + + public static double[][] COVMATSCALEFACT = new double[][]{ + {COVD0D0, COVD0PHI0, COVD0RHO,1.0,1.0}, + {COVD0PHI0,COVPHI0PHI0, COVPHI0RHO,1.0,1.0}, + {COVD0RHO, COVPHI0RHO, COVRHORHO,1.0,1.0}, + {1.0,1.0,1.0, COVZ0Z0,1.0}, + {1.0,1.0,1.0,1.0, CONVTANLTANL} + }; // CONSTANTS USED IN RECONSTRUCTION //--------------------------------- public static boolean isMC = true; @@ -61,13 +61,14 @@ public class Constants { public static boolean svtSeeding = true; - public static boolean TIMECUTS = true; + public static boolean TIMECUTS = false; public static boolean KFFILTERON = true; + public static boolean INITFROMMC = false; public static final boolean TRACKSFROMORIGIN = true; - public static boolean beamSpotConstraint = true; + public static boolean BEAMSPOTCONST = false; public static Libr kfMatLib; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index c4597a6d1..d1a8f0637 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -241,8 +241,8 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, SvtStrip.set_Line(geo.getStrip(layer, sector, strip)); SvtStrip.set_Module(geo.getModule(layer, sector)); SvtStrip.set_Normal(geo.getNormal(layer, sector)); - if(layer%2==1) { - SvtStrip.setToverX0(SVTGeometry.getToverX0()); + if(layer%2==0) { + SvtStrip.setToverX0(2*SVTGeometry.getToverX0()); SvtStrip.setZoverA(SVTGeometry.getZoverA()); SvtStrip.setMatT(SVTGeometry.getMaterialThickness()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 3c3f66815..08d314b2f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -413,13 +413,13 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { bank.setFloat("d0", i, (float) (helix.get_dca()/10.0)); double[][] covmatrix = helix.get_covmatrix(); if (covmatrix != null) { - bank.setFloat("cov_d02", i, (float) covmatrix[0][0] ); - bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1] ); + bank.setFloat("cov_d02", i, (float) covmatrix[0][0]/10/10 ); + bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1]/10 ); bank.setFloat("cov_d0rho", i, (float) covmatrix[0][2] ); bank.setFloat("cov_phi02", i, (float) covmatrix[1][1] ); - bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2] ); - bank.setFloat("cov_rho2", i, (float) covmatrix[2][2] ); - bank.setFloat("cov_z02", i, (float) covmatrix[3][3] ); + bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2]*10 ); + bank.setFloat("cov_rho2", i, (float) covmatrix[2][2]*10*10 ); + bank.setFloat("cov_z02", i, (float) covmatrix[3][3]/10/10 ); bank.setFloat("cov_tandip2", i, (float) covmatrix[4][4] ); } else { bank.setFloat("cov_d02", i, -999); @@ -506,13 +506,13 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { // | 0 0 0 0 d_tandip*d_tandip |X double[][] covmatrix = helix.get_covmatrix(); if (covmatrix != null) { - bank.setFloat("cov_d02", i, (float) covmatrix[0][0] ); - bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1] ); + bank.setFloat("cov_d02", i, (float) covmatrix[0][0]/10/10 ); + bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1]/10 ); bank.setFloat("cov_d0rho", i, (float) covmatrix[0][2] ); bank.setFloat("cov_phi02", i, (float) covmatrix[1][1] ); - bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2] ); - bank.setFloat("cov_rho2", i, (float) covmatrix[2][2] ); - bank.setFloat("cov_z02", i, (float) covmatrix[3][3] ); + bank.setFloat("cov_phi0rho", i, (float) covmatrix[1][2]*10 ); + bank.setFloat("cov_rho2", i, (float) covmatrix[2][2]*10*10 ); + bank.setFloat("cov_z02", i, (float) covmatrix[3][3]/10/10 ); bank.setFloat("cov_tandip2", i, (float) covmatrix[4][4] ); } else { bank.setFloat("cov_d02", i, -999); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index 125bed4f1..faf9a9641 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -286,7 +286,7 @@ void propagatePars(double xr, double yr, double x, double y, double cosphi, doub double Vp_phid = JVJT[1][2]; double Vp_dd = JVJT[2][2]; //3. Fill the covariance matrix - if(Constants.beamSpotConstraint==false) { + if(Constants.BEAMSPOTCONST==false) { _covr[0] = Vp_rhorho; _covr[1] = Vp_rhophi; _covr[2] = Vp_rhod; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index 5e260d291..458b18227 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -56,10 +56,10 @@ public enum FitStatus { public HelicalTrackFitter() { } - private List W = new ArrayList(); - private List P0 = new ArrayList(2); - private List P1 = new ArrayList(2); - private List P2 = new ArrayList(2); + private final List W = new ArrayList<>(); + private final List P0 = new ArrayList<>(2); + private final List P1 = new ArrayList<>(2); + private final List P2 = new ArrayList<>(2); public FitStatus fit(List X, List Y, List Z, List Rho, List errRt, List errRho, List ErrZ) { // Initialize the various fitter outputs @@ -183,26 +183,25 @@ public FitStatus fit(List X, List Y, List Z, List w = new ArrayList(); - // fit status + private final List w = new ArrayList<>(); + // fit status public boolean fitStatus(List x, List y, List sigma_x, List sigma_y, int nbpoints) { boolean fitStat = false; if (nbpoints >= 2) { // must have enough points to do the fit diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 0447b586d..0fc5a1b17 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -221,16 +221,21 @@ private void loadConfiguration() { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); } - if (this.getEngineConfigString("BeamSpotConst")!=null) { - Constants.beamSpotConstraint = Boolean.valueOf(this.getEngineConfigString("BeamSpotConst")); + if (this.getEngineConfigString("beamSpotConst")!=null) { + Constants.BEAMSPOTCONST = Boolean.valueOf(this.getEngineConfigString("beamSpotConst")); } - System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.beamSpotConstraint); + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.BEAMSPOTCONST); if (this.getEngineConfigString("kfFilterOn")!=null) { Constants.KFFILTERON = Boolean.valueOf(this.getEngineConfigString("kfFilterOn")); } System.out.println("["+this.getName()+"] run with Kalman-Filter status set to "+Constants.KFFILTERON); + if (this.getEngineConfigString("initFromMC")!=null) { + Constants.INITFROMMC = Boolean.valueOf(this.getEngineConfigString("initFromMC")); + } + System.out.println("["+this.getName()+"] initialize KF from true MC information "+Constants.INITFROMMC); + String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { Constants.isCosmicsData = Boolean.valueOf(svtCosmics); @@ -288,8 +293,8 @@ private void loadConfiguration() { System.out.println("["+this.getName()+"] run SVT-based seeding set to "+ Constants.svtSeeding); } - if(this.getEngineConfigString("BMTTimeCuts")!=null) { - Constants.TIMECUTS = Boolean.parseBoolean(this.getEngineConfigString("BMTTimeCuts")); + if(this.getEngineConfigString("timeCuts")!=null) { + Constants.TIMECUTS = Boolean.parseBoolean(this.getEngineConfigString("timeCuts")); System.out.println("["+this.getName()+"] run BMT timing cuts set to "+ Constants.TIMECUTS); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 2dce358c8..5ee6f7f4f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -86,15 +86,18 @@ public void CleanupSpuriousCrosses(List> crosses, List t public List setMeasVecs(Seed trkcand, Swim swim) { //Collections.sort(trkcand.get_Crosses()); - List KFSites = new ArrayList(); - Vector3D u = trkcand.get_Helix().getTrackDirectionAtRadius(Math.sqrt(Constants.getXb()*Constants.getXb()+Constants.getYb()*Constants.getYb())); - Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), u); - Surface meas0 = new Surface(pln0,new Point3D(Constants.getXb(),Constants.getYb(),0), - new Point3D(Constants.getXb()-300,Constants.getYb(),0), new Point3D(Constants.getXb()+300,Constants.getYb(),0), - Constants.DEFAULTSWIMACC); + List KFSites = new ArrayList<>(); + Vector3D u = new Vector3D(0,0,1); + Point3D p = new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()); + Plane3D pln0 = new Plane3D(p, u); + Surface meas0 = new Surface(pln0, + new Point3D(p), + new Point3D(p.x()-300,p.y(),p.z()), + new Point3D(p.x()+300,p.y(),p.z()), + Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); - meas0.setError(trkcand.get_Helix().get_covmatrix()[0][0]); + meas0.setError(1); KFSites.add(meas0); // SVT measurements @@ -135,7 +138,7 @@ public List setMeasVecs(StraightTrack trkcand, SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { if(trkcand.clsMap!=null) trkcand.clsMap.clear(); //VZ: reset cluster map for second pass tracking with isolated SVT clusters //Collections.sort(trkcand.get_Crosses()); - List KFSites = new ArrayList(); + List KFSites = new ArrayList<>(); Vector3D u = trkcand.get_ray().get_dirVec(); Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), u); Surface meas0 = new Surface(pln0,new Point3D(0,0,0), @@ -145,11 +148,11 @@ public List setMeasVecs(StraightTrack trkcand, meas0.setError(1); meas0.hemisphere = 1; KFSites.add(meas0); - Map clsMap = new HashMap(); + Map clsMap = new HashMap<>(); trkcand.sort(Comparator.comparing(Cross::getY).reversed()); for (int i = 0; i < trkcand.size(); i++) { //SVT if(trkcand.get(i).get_Detector()==DetectorType.BST) { - List cls = new ArrayList(); + List cls = new ArrayList<>(); if(trkcand.get(i).get_Cluster1()!=null && trkcand.get(i).get_Cluster2()!=null) { //VZ: modification for pseudocrosses that contain only one cluster diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 61826ab68..2e08eb809 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -74,7 +74,7 @@ public boolean processEvent(DataEvent event, seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed, trseed2); } } - if(Constants.beamSpotConstraint==false) { + if(Constants.BEAMSPOTCONST==false) { List failed = new ArrayList<>(); for(Seed s : seeds) { if(!recUtil.reFitCircle(s,SVTGeom, BMTGeom, Constants.SEEDFITITERATIONS)) @@ -115,10 +115,12 @@ public boolean processEvent(DataEvent event, v.translateXYZ(Constants.getXb(), Constants.getYb(), 0); - //Uncomment to force to MC truth: - //double[] pars = recUtil.MCtrackPars(event); - //v = new Point3D(pars[0],pars[1],pars[2]); - //p = new Vector3D(pars[3],pars[4],pars[5]); + + double[] pars = recUtil.MCtrackPars(event); + if(Constants.INITFROMMC) { + v = new Point3D(pars[0],pars[1],pars[2]); + p = new Vector3D(pars[3],pars[4],pars[5]); + } Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); double[][] cov = seed.get_Helix().get_covmatrix(); @@ -164,7 +166,7 @@ public boolean processEvent(DataEvent event, } } //reset pars - fittedTrack.get_helix().set_dca(-fittedTrack.get_helix().get_dca()); +// fittedTrack.get_helix().set_dca(-fittedTrack.get_helix().get_dca()); // RDV check v = fittedTrack.get_helix().getVertex(); p = fittedTrack.get_helix().getPXYZ(solenoidValue); charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index a3ee4961f..4b5f3782a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -87,7 +87,6 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) //kfCov[4][4]*=10; this.get_helix().set_covmatrix(kfCov); - //this.get_helix().set_covmatrix(seed.get_Helix().get_covmatrix()); this.setPXYZ(); this.setNDF(kf.NDF); this.setChi2(kf.chi2); From 0613be030b33ca2f9e43ee07c74969ddd290a19a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 4 Jan 2022 15:51:11 +0100 Subject: [PATCH 258/291] clas-tracking: Modifications to KF to correct for anomalies in covariance matrix and residuals observed in MC - Modified transport of covariance matrix, assuming the trajectory can be approximated to a pure helix only in between to adjacent measurements - Helix parameters are redefined at each measurement, shifting the pivot of the helix (pivot transformation) instead of keeping it fixed to the beam spot - Track is swum from one measurement point to the next, instead than from the swam spot to each measurement: significant speed improvement - Multiple scattering accounted for both in forward and backward propagations for helical tracks. Multiple scattering Q matrix transported to measurement point included - Initial covariance matrix scaled to larger values to allow the KF to explore a wider range of parameters values - Restored the beam spot constraint (optional) as DOCA to a line. It can be applied only to the seed fit or to both seed and KF - Redefined measurement errors to be error instead of error^2, to avoid confusion in the future - Fixed discontinuity in covariance matrix transport at phi = +/- 180 deg (responsible for large residuals when px was changing sign - Fixed definition of F matrix for straight tracks in TracksFromTarget - Code cleanup CVT: - Increased SVT material budget by factor 2 - BMT material information consolidated in single table (/geometry/cvt/mvt/material) - Temporarily removed n<5 constraint on BMT cluster size - new yaml variables to control number of KF iterations, beam spot constraint (0- no constraint, 1-seed only, 2- seed and KF) - number of KF iterations encoded in CVTRec::Tracks.status variable - Chi2 in cosmic track bank now non-zero --- .../clas/tracking/kalmanfilter/AKFitter.java | 175 ++-- .../clas/tracking/kalmanfilter/AMeasVecs.java | 56 +- .../tracking/kalmanfilter/AStateVecs.java | 402 ++++++-- .../tracking/kalmanfilter/AStateVector.java | 108 +++ .../tracking/kalmanfilter/KFCovMatOps.java | 20 + .../clas/tracking/kalmanfilter/Surface.java | 18 +- .../jlab/clas/tracking/kalmanfilter/Type.java | 8 +- .../kalmanfilter/helical/KFitter.java | 254 +++-- .../kalmanfilter/helical/MeasVecs.java | 84 +- .../kalmanfilter/helical/StateVecs.java | 864 +++++++----------- .../kalmanfilter/straight/KFitter.java | 130 ++- .../kalmanfilter/straight/MeasVecs.java | 34 +- .../kalmanfilter/straight/StateVecs.java | 260 ++---- .../jlab/clas/tracking/trackrep/Helix.java | 11 + .../org/jlab/clas/tracking/trackrep/Seed.java | 5 - .../clas/tracking/utilities/MatrixOps.java | 44 +- etc/bankdefs/hipo4/cvt.json | 2 +- .../main/java/org/jlab/rec/cvt/Constants.java | 43 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 2 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 9 +- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 28 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 13 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 2 +- .../org/jlab/rec/cvt/fit/CircleFitter.java | 2 +- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 2 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 2 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 14 +- .../rec/cvt/services/CosmicTracksRec.java | 28 +- .../jlab/rec/cvt/services/RecUtilities.java | 14 +- .../rec/cvt/services/TracksFromTargetRec.java | 28 +- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 2 +- .../java/org/jlab/rec/cvt/track/Track.java | 10 +- 32 files changed, 1349 insertions(+), 1325 deletions(-) create mode 100644 common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVector.java diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index 567760c2d..ec7d46efc 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -9,30 +9,55 @@ public abstract class AKFitter { - public static int polarity = -1; - public boolean setFitFailed = true; - - // AStateVecs sv - // AMeasVecs mv - public boolean filterOn = true; - private double _tarShift; //targetshift + // control variables + public static int polarity = -1; //RDV should check that everything works reversing this value + public boolean filterOn = true; + public int totNumIter = 1; + public boolean beamSpotConstraint = false; + + // parameters private double _Xb; //beam axis pars private double _Yb; private double resiCut = 100;//residual cut for the measurements - public KFCovMatOps mo = new KFCovMatOps(Libr.EJML); + // return variables + public boolean setFitFailed = false; + public double chi2; + public int NDF; + public int NDF0; + public int numIter; + + private Swim swimmer; + private KFCovMatOps mo = new KFCovMatOps(Libr.EJML); + + + public AKFitter(boolean filter, int iterations, boolean beamspot, Swim swim, Libr m) { + this.filterOn = filter; + this.totNumIter = iterations; + this.beamSpotConstraint = beamspot; + this.swimmer = swim; + this.setMatrixLibrary(m); + } - public void setMatrixLibrary(Libr ml) { + public final void setMatrixLibrary(Libr ml) { mo = new KFCovMatOps(ml); } - public Libr getMatrixLibrary() { - return mo.getMatrixLibrary(); + public KFCovMatOps getMatrixOps() { + return mo; } public void setMeasurements(List measSurfaces, AMeasVecs mv) { mv.setMeasVecs(measSurfaces); } + + public Swim getSwimmer() { + return swimmer; + } + + public void setSwimmer(Swim swimmer) { + this.swimmer = swimmer; + } /** * @return the resiCut @@ -47,64 +72,58 @@ public double getResiCut() { public void setResiCut(double resiCut) { this.resiCut = resiCut; } - - public int totNumIter = 5; - - public void runFitterIter(Swim swimmer, int it, AStateVecs sv, AMeasVecs mv) { + + public void runFitterIter(AStateVecs sv, AMeasVecs mv) { + this.numIter++; for (int k = 0; k < mv.measurements.size() - 1; k++) { - if (sv.trackCov.get(k) == null || mv.measurements.get(k + 1) == null) { - return; - } - sv.transport(k, k + 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k+1), - swimmer); - this.filter(k + 1, swimmer, 1, sv, mv); +// System.out.println(k); + if (sv.trackTraj.get(k)==null || mv.measurements.get(k + 1) == null) { + return; } + if(k==0) sv.trackTraj.get(0).copyCovMat(sv.initSV.covMat); +// System.out.println("before transport");sv.printlnStateVec(sv.trackTraj.get(k)); + sv.transport(k, k + 1, mv, swimmer); +// System.out.println("after transport:" + mv.dh(k+1, sv.trackTraj.get(k+1)));sv.printlnStateVec(sv.trackTraj.get(k+1)); + this.filter(k + 1, sv, mv); +// System.out.println("after filtering:" + mv.dh(k+1, sv.trackTraj.get(k+1)));sv.printlnStateVec(sv.trackTraj.get(k+1)); + } + for (int k = mv.measurements.size() - 1; k>0 ;k--) { - if (sv.trackCov.get(k) == null || mv.measurements.get(k - 1) == null) { + if (sv.trackTraj.get(k)==null || mv.measurements.get(k - 1) == null) { return; } - sv.transport(k, k - 1, sv.trackTraj.get(k), sv.trackCov.get(k), mv.measurements.get(k-1), - swimmer); - if(k>1) - this.filter(k - 1, swimmer, -1, sv, mv); - } +// System.out.println("before transport");sv.printlnStateVec(sv.trackTraj.get(k)); + sv.transport(k, k - 1, mv, swimmer); +// System.out.println("after transport:" + mv.dh(k-1, sv.trackTraj.get(k-1)));sv.printlnStateVec(sv.trackTraj.get(k-1)); + if(k>1 || this.beamSpotConstraint) + this.filter(k - 1, sv, mv); +// System.out.println("after filtering:" + mv.dh(k-1, sv.trackTraj.get(k-1)));sv.printlnStateVec(sv.trackTraj.get(k-1)); + } } - public abstract void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) ; + + public abstract void runFitter(AStateVecs sv, AMeasVecs mv) ; public abstract void setTrajectory(AStateVecs sv, AMeasVecs mv) ; - public double chi2 = 0; - public int NDF = 0; - - public double calc_chi2(Swim swimmer, AStateVecs sv, AMeasVecs mv) { - //get the measurement - double m = 0; - //get the projector state - double h = 0; - double chi2 =0; - m=0; - h=0; - int ndf = -5; - StateVec stv = sv.transported(0, 1, sv.trackTraj.get(0), mv.measurements.get(1), swimmer); - double dh = mv.dh(1, stv); - if(mv.measurements.get(1).skip==false) { - chi2 = dh*dh / mv.measurements.get(1).error; - ndf++; - } - for(int k = 1; k< sv.Layer.size()-1; k++) { - if(mv.measurements.get(k+1).skip==false) { - stv = sv.transported(k, k+1, stv, mv.measurements.get(k+1), swimmer); - dh = mv.dh(k+1, stv); - chi2 += dh*dh / mv.measurements.get(k+1).error; + public double calc_chi2(AStateVecs sv, AMeasVecs mv) { + double chisq = 0; + int ndf = this.NDF0; + + for(int k = 0; k< mv.measurements.size()-1; k++) { + if(mv.measurements.get(k+1).skip==false && sv.trackTraj.get(k)!=null) { + sv.transport(k, k+1, mv, swimmer); + double dh = mv.dh(k+1, sv.trackTraj.get(k+1)); + double error = mv.measurements.get(k+1).error; + chisq += dh*dh / error/error; ndf++; } } - return chi2; + return chisq; } - public abstract void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) ; + public abstract void filter(int k, AStateVecs sv, AMeasVecs mv) ; /** * @return the _Xb @@ -133,34 +152,8 @@ public double getYb() { public void setYb(double _Yb) { this._Yb = _Yb; } - - /** - * @return the _tarShift - */ - public double getTarShift() { - return _tarShift; - } - - /** - * @param _TarShift the _tarShift to set - */ - public void setTarShift(double _TarShift) { - this._tarShift = _TarShift; - } - - /** - * prints the matrix -- used for debugging - * - * @param C matrix - */ - public void printMatrix(double[][] C, String s) { - System.out.println(" "+s); - for (int k = 0; k < 5; k++) { - System.out.println(C[k][0]+" "+C[k][1]+" "+C[k][2]+" "+C[k][3]+" "+C[k][4]); - } - System.out.println(" "); - } - + + // RDV why not just using state vectors? public class HitOnTrack { public int layer; @@ -183,6 +176,24 @@ public HitOnTrack(int layer, double x, double y, double z, double px, double py, this.pz = pz; this.resi = resi; } + + public HitOnTrack(int layer, StateVec sv, double resi) { + this.layer = layer; + this.x = sv.x; + this.y = sv.y; + this.z = sv.z; + this.px = sv.px; + this.py = sv.py; + this.pz = sv.pz; + this.resi = resi; + } + } + + public void printConfig() { + System.out.println("Kalman Filter configuration:"); + System.out.println("- filter status " + this.filterOn); + System.out.println("- beam spot constraint " + this.beamSpotConstraint); + System.out.println("- number of iterations " + this.totNumIter); + System.out.println("- matrix library " + this.mo.getMatrixLibrary().name()); } - } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java index a6b0e675e..8ae7cdcb6 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -7,11 +7,9 @@ import org.jlab.clas.tracking.kalmanfilter.AStateVecs.StateVec; import org.jlab.clas.tracking.objects.Strip; import org.jlab.geom.prim.Arc3D; -import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Transformation3D; -import org.jlab.geom.prim.Vector3D; /** * @@ -20,9 +18,10 @@ public abstract class AMeasVecs { - public List measurements = new ArrayList(); + public List measurements = new ArrayList<>(); public void setMeasVecs(List measSurfaces) { + measurements = new ArrayList<>(); Collections.sort(measSurfaces); for(int i = 0; i < measSurfaces.size(); i++) { MeasVec mvec = new MeasVec(); @@ -43,11 +42,17 @@ public void setMeasVecs(List measSurfaces) { public double dh(int k, StateVec stateVec) { double value = Double.NaN; - + if (stateVec == null|| this.measurements.get(stateVec.k) == null) { return value; } + if (this.measurements.get(stateVec.k).surface.type == Type.LINE) { + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(sv).length(); + } if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); @@ -108,29 +113,11 @@ public double dh(int k, StateVec stateVec) { Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); toLocal.apply(sv); value = sv.toVector3D().phi()-this.measurements.get(stateVec.k).surface.strip.getPhi(); - if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; } } return value; } - - - public double getPhiATZ(StateVec stateVec) { - Cylindrical3D cyl = this.measurements.get(stateVec.k).surface.cylinder; - Line3D cln = this.measurements.get(stateVec.k).surface.cylinder.getAxis(); - double v = (stateVec.z-cyl.baseArc().center().z())/cln.direction().z(); - double x = cyl.baseArc().center().x()+v*cln.direction().x(); - double y = cyl.baseArc().center().y()+v*cln.direction().y(); - Vector3D n = new Point3D(x, y, stateVec.z). - vectorTo(new Point3D(stateVec.x,stateVec.y,stateVec.z)).asUnit(); - return n.phi(); - } - - public double getPhi(StateVec stateVec) { - Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); - this.measurements.get(stateVec.k).surface.toLocal().apply(sv); - return sv.toVector3D().phi(); - } public double h(int k, StateVec stateVec) { @@ -140,6 +127,12 @@ public double h(int k, StateVec stateVec) { return value; } + if (this.measurements.get(stateVec.k).surface.type == Type.LINE) { + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(sv).length(); + } if( this.measurements.get(stateVec.k).surface.type == Type.PLANEWITHPOINT || this.measurements.get(stateVec.k).surface.type == Type.CYLINDERWITHPOINT) { Point3D p = new Point3D(this.measurements.get(stateVec.k).surface.refPoint); @@ -187,18 +180,27 @@ public double h(int k, StateVec stateVec) { value = stV.z(); } if(this.measurements.get(stateVec.k).surface.strip.type == Strip.Type.PHI) { - //value = Math.atan2(stateVec.y, stateVec.x); - value = this.getPhi(stateVec); + Transformation3D toLocal =this.measurements.get(stateVec.k).surface.toLocal(); + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + toLocal.apply(sv); + value = sv.toVector3D().phi()-this.measurements.get(stateVec.k).surface.strip.getPhi(); + if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; } + if(this.measurements.get(stateVec.k).surface.type == Type.LINE) { + Point3D sv = new Point3D(stateVec.x, stateVec.y, stateVec.z); + Line3D l = new Line3D(this.measurements.get(stateVec.k).surface.lineEndPoint1, + this.measurements.get(stateVec.k).surface.lineEndPoint2); + value = l.distance(sv).length(); + } } return value; } public double[] delta_d_a = new double[5];//{1, Math.toRadians(0.25), 0.05, 1, 0.01}; public double sqrt_epsilon = Math.sqrt(2.2*1.e-16); + public double rollBackAngle = Math.toRadians(0.5); // angular shift applied to the stateVec to move it "before" the surface when swimming public double[] Hval = new double[5]; - public abstract double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) ; - public abstract AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) ; + public abstract double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer) ; public class MeasVec implements Comparable { public Surface surface; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index fad6b1463..d7b84114d 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -1,77 +1,81 @@ package org.jlab.clas.tracking.kalmanfilter; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.jlab.geom.prim.Vector3D; import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; +import org.jlab.clas.tracking.kalmanfilter.helical.KFitter; import org.jlab.clas.tracking.trackrep.Helix; public abstract class AStateVecs { - public List X0; - public List Y0; - public List Z0; // reference points - - public Helix util ; + public Helix util; public double units; public double lightVel; + + public double xref; + public double yref; + public double zref; + + public StateVec initSV; - public List bfieldPoints = new ArrayList(); - public Map trackTraj = new HashMap(); - public Map trackCov = new HashMap(); + public Map trackTraj = new HashMap<>(); public boolean straight; - public StateVec StateVec; - public CovMat CovMat; - - AMeasVecs mv = new AMeasVecs() { - @Override - public double[] H(StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + + public abstract void init(Helix trk, double[][] cov, double xref, double yref, double zref, Swim swimmer); + + public abstract void init(double x0, double z0, double tx, double tz, double units, double[][] cov); + + public abstract boolean setStateVecPosAtMeasSite(StateVec vec, MeasVec mv, Swim swimmer); + + public StateVec newStateVecAtMeasSite(StateVec vec, MeasVec mv, Swim swimmer) { + StateVec newVec = new StateVec(vec); + if(!this.setStateVecPosAtMeasSite(newVec, mv, swimmer)) + return null; + else + return newVec; + } + + public abstract boolean getStateVecPosAtMeasSite(StateVec iVec, MeasVec mv, Swim swim); + + public final void transport(int i, int f, AMeasVecs mv, Swim swimmer) { + // transport state vector + StateVec iVec = this.trackTraj.get(i); + StateVec fVec = this.newStateVecAtMeasSite(iVec, mv.measurements.get(f), swimmer); + if(fVec==null) return; + //transport covariance matrix + double[][] fCov = this.propagateCovMat(iVec, fVec); + double[][] iQ = this.Q(i, f, iVec, mv); + double[][] fQ = this.propagateMatrix(iVec, fVec, iQ); + if (fCov != null) { + fVec.covMat = addProcessNoise(fCov, fQ); } + this.trackTraj.put(f, fVec); + } - @Override - public StateVec reset(StateVec SVplus, StateVec stateVec, AStateVecs sv) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - } ; - - public double shift; // target shift - public List Layer; - public List Sector; - - public double[] value = new double[4]; // x,y,z,phi - public double[] swimPars = new double[7]; - public B Bf = new B(0); - - public abstract void init(Helix trk, double[][] cov, AKFitter kf, Swim swimmer); - public abstract void init(double x0, double z0, double tx, double tz, double units, double[][] cov, AKFitter kf) ; - public abstract void setStateVecPosAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer) ; - public abstract StateVec newStateVecAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer, - boolean useSwimmer); - public abstract double[] getStateVecPosAtMeasSite(int k, StateVec iVec, MeasVec mv, Swim swim, - boolean useSwimmer) ; - public abstract void tranState(int f, StateVec iVec, Swim swimmer) ; - - public abstract StateVec transported(int i, int f, StateVec iVec, MeasVec mv, - Swim swimmer) ; + public final double[][] propagateCovMat(StateVec ivec, StateVec fvec) { + return this.propagateMatrix(ivec, fvec, ivec.covMat); + } - public abstract void transport(int i, int f, StateVec iVec, CovMat icovMat, MeasVec mv, - Swim swimmer) ; + private double[][] propagateMatrix(StateVec ivec, StateVec fvec, double[][] matrix) { + double[][] FMat = this.F(ivec, fvec); + double[][] FMatT = this.transposeMatrix(FMat); - public abstract void setTrackPars(StateVec kVec, Swim swim); + return multiplyMatrices(FMat, matrix, FMatT); + } public abstract Helix setTrackPars(); - + private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { - int r1 =firstMatrix.length; int c1=firstMatrix[0].length; int c2=secondMatrix[0].length; + int r1 = firstMatrix.length; + int c1 = firstMatrix[0].length; + int c2 = secondMatrix[0].length; double[][] product = new double[r1][c2]; - for(int i = 0; i < r1; i++) { + for (int i = 0; i < r1; i++) { for (int j = 0; j < c2; j++) { for (int k = 0; k < c1; k++) { product[i][j] += firstMatrix[i][k] * secondMatrix[k][j]; @@ -81,47 +85,56 @@ private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMat return product; } - - public double[][] propagatedMatrix(double[][] firstMatrix, double[][] sMatrix, double[][] secondMatrix){ - double[][] m1 = multiplyMatrices(sMatrix, secondMatrix); - double[][] m2 = multiplyMatrices(firstMatrix,m1); - + + public double[][] transposeMatrix(double[][] matrix) { + double[][] result = new double[5][5]; + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + result[j][i] = matrix[i][j]; + } + } + return result; + + } + + public double[][] multiplyMatrices(double[][] firstMatrix, double[][] sMatrix, double[][] secondMatrix) { + double[][] m1 = this.multiplyMatrices(sMatrix, secondMatrix); + double[][] m2 = this.multiplyMatrices(firstMatrix, m1); + return m2; } - - public double[][] addProcessNoise(double[][] C, double[][] Q){ + + public double[][] addProcessNoise(double[][] C, double[][] Q) { double[][] result = new double[5][5]; - for(int i = 0; i<5; i++) { - for(int j = 0; j<5; j++) { + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { result[i][j] = C[i][j]; - if(Q[i][j]!=0) { - result[i][j] +=Q[i][j]; + if (Q[i][j] != 0) { + result[i][j] += Q[i][j]; } } } - + return result; } - public abstract double[][] Q(StateVec iVec, MeasVec mVec, int dir) ; - - public abstract StateVec reset(StateVec SV, StateVec stateVec) ; - public void resetArrays(double[] swimPars) { - for(int i = 0; i Math.PI) { + phi -= 2 * Math.signum(phi) * Math.PI; + } + double drho = (xcen - x0) * Math.cos(phi0) + (ycen - y0) * Math.sin(phi0) - this.alpha / kappa; + double dz = this.z - z0 + this.alpha / kappa * tanL * phi; + this.d_rho = drho; + this.phi0 = phi0; + this.kappa = kappa; + this.dz = dz; + this.tanL = tanL; + this.phi = phi; + } + + public void rollBack(double angle) { + this.phi += Math.signum(this.kappa) * angle; + this.updateFromHelix(); + } + + public void toDoca() { + this.phi = 0; + this.updateFromHelix(); + } + + public void pivotTransform() { + this.setPivot(this.x, this.y, this.z); + } + + public final void setPivot(double xPivot, double yPivot, double zPivot) { + x0 = xPivot; + y0 = yPivot; + z0 = zPivot; + this.updateHelix(); + } + + public void updateHelix(double x, double y, double z, double px, double py, double pz, double alpha) { + this.x = x; + this.y = y; + this.z = z; + this.px = px; + this.py = py; + this.pz = pz; + this.alpha = alpha; + this.updateHelix(); + } + + public Helix getOldHelix() { + Helix helix = new Helix(); + this.toOldHelix(helix); + return helix; + } + + public void toOldHelix(Helix helix) { + StateVec vec = new StateVec(0, helix.getXb(), helix.getYb(), 0, this); + vec.updateHelix(); + + helix.setTurningSign((int) Math.signum(vec.kappa) * KFitter.polarity); + helix.setB(1 / vec.alpha / helix.getLIGHTVEL()); + helix.setR(vec.alpha / Math.abs(vec.kappa)); + double hphi0 = vec.phi0 + Math.PI / 2; + if (Math.abs(hphi0) > Math.PI) { + hphi0 -= Math.signum(hphi0) * 2 * Math.PI; + } + helix.setPhi0(hphi0); + helix.setTanL(vec.tanL); + helix.setZ0(z0 + vec.dz); + helix.setOmega(-helix.getTurningSign() / helix.getR()); + helix.setCosphi0(Math.cos(helix.getPhi0())); + helix.setSinphi0(Math.sin(helix.getPhi0())); + helix.setD0(-vec.d_rho); + helix.Update(); + } public double[] get_ELoss() { return _ELoss; @@ -154,15 +324,43 @@ public void set_ELoss(double[] _ELoss) { this._ELoss = _ELoss; } - } - - public class CovMat { + public double getHelixComponent(int i) { + switch (i) { + case 0: + return d_rho; + case 1: + return phi0; + case 2: + return kappa; + case 3: + return dz; + case 4: + return tanL; + default: + return 0; + } + } - public final int k; - public double[][] covMat; + public double getRayComponent(int i) { + switch (i) { + case 0: + return x0; + case 1: + return z0; + case 2: + return tx; + case 3: + return tz; + default: + return 0; + } + } - public CovMat(int k) { - this.k = k; + @Override + public String toString() { + String s = String.format("%d) drho=%.4f phi0=%.4f kappa=%.4f dz=%.4f tanL=%.4f alpha=%.4f\n", this.k, this.d_rho, this.phi0, this.kappa, this.dz, this.tanL, this.alpha); + s += String.format(" phi=%.4f x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", this.phi, this.x, this.y, this.z, this.px, this.py, this.pz); + return s; } } @@ -182,27 +380,27 @@ public class B { public double alpha; float b[] = new float[3]; + public B(int k) { this.k = k; } + public B(int k, double x, double y, double z, Swim swimmer) { this.k = k; this.x = x; this.y = y; this.z = z; - swimmer.BfieldLab(x/units, y/units, z/units + shift/units, b); + swimmer.BfieldLab(x / units, y / units, z / units, b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; - + this.alpha = 1. / (lightVel * Math.abs(b[2])); } - - public void set() { - swimmer.BfieldLab(x/units, y/units, z/units + shift/units, b); + swimmer.BfieldLab(x / units, y / units, z / units, b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; @@ -215,14 +413,16 @@ public void set() { public double muMass = 0.105658369; public double eMass = 0.000510998; public double pMass = 0.938272029; - - public abstract Vector3D P(int kf) ; - public abstract Vector3D X(int kf) ; - public abstract Vector3D X(StateVec kVec, double phi) ; - public abstract Vector3D P0(int kf) ; - public abstract Vector3D X0(int kf) ; + public abstract Vector3D P(int kf); - - public abstract void printlnStateVec(StateVec S) ; -} \ No newline at end of file + public abstract Vector3D X(int kf); + + public abstract Vector3D X(StateVec kVec, double phi); + + public abstract Vector3D P0(int kf); + + public abstract Vector3D X0(int kf); + + public abstract void printlnStateVec(StateVec S); +} diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVector.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVector.java new file mode 100644 index 000000000..d4e8577f3 --- /dev/null +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVector.java @@ -0,0 +1,108 @@ +package org.jlab.clas.tracking.kalmanfilter; + +/** + * + * @author devita + */ +public abstract class AStateVector { + + private final int k; + + // regular stateComponents + public double x; + public double y; + public double z; + public double px; + public double py; + public double pz; + + // reference point + public double x0; + public double y0; + public double z0; + + public double residual; + + public double[] stateComponents; + public double[][] covarianceMatrix; + + + public AStateVector(int k) { + this.k = k; + } + + public AStateVector(AStateVector s) { + this(s.k); + this.copy(s); + } + + public AStateVector(int k, AStateVector s) { + this(k); + this.copy(s); + } + + public AStateVector(int k, double xpivot, double ypivot, double zpivot, AStateVector s) { + this(k); + this.copy(s); + this.setPivot(xpivot, ypivot, zpivot); + } + + public final void copy(AStateVector s) { + this.x0 = s.x0; + this.y0 = s.y0; + this.z0 = s.z0; + this.x = s.x; + this.y = s.y; + this.z = s.z; + this.px = s.px; + this.py = s.py; + this.pz = s.pz; + this.residual = s.residual; + this.copyComponents(s); + this.copyCovMat(s.covarianceMatrix); + } + + public void copyComponents(AStateVector s) { + if(s.stateComponents==null) return; + for(int i=0; i TrjPoints = new HashMap(); - StateVecs sv = new StateVecs(); - MeasVecs mv = new MeasVecs(); - public StateVecs.StateVec finalStateVec; - public double[][] finalCovMat; - + public Map TrjPoints = new HashMap<>(); + private StateVecs sv = new StateVecs(); + private MeasVecs mv = new MeasVecs(); + public StateVecs.StateVec finalStateVec = null; public Helix KFHelix; - public KFitter(Helix helix, double[][] cov, DataEvent event, Swim swimmer, double Xb, double Yb, - double Zref, List measSurfaces) { + + + public KFitter(boolean filter, int iterations, boolean beamspot, Swim swim, Libr mo) { + super(filter, iterations, beamspot, swim, mo); + } + + public final void init(Helix helix, double[][] cov, + double Xb, double Yb, double Zref, + List measSurfaces) { + finalStateVec = null; + KFHelix = null; + this.NDF0 = -5; + this.NDF = -5; + this.chi2 = Double.POSITIVE_INFINITY; + this.numIter = 0; + this.setFitFailed = false; + mv.setMeasVecs(measSurfaces); + for (int i = 1; i < mv.measurements.size(); i++) { + if(mv.measurements.get(i).skip==false) { + this.NDF++; + } + } this.setXb(Xb); this.setYb(Yb); - this.setTarShift(Zref); - this.init(helix, cov, event, swimmer, Xb, Yb, - Zref, sv, mv, measSurfaces); + sv.init( helix, cov, Xb, Yb, Zref, this.getSwimmer()); } - public void runFitter(Swim swimmer) { - this.runFitter(swimmer, sv, mv); + + public void runFitter() { + this.runFitter(sv, mv); } + @Override - public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { - double newchisq = Double.POSITIVE_INFINITY; - + public void runFitter(AStateVecs sv, AMeasVecs mv) { + + StateVecs.StateVec finalSVonPivot = null; + double newchisq = Double.POSITIVE_INFINITY; for (int it = 0; it < totNumIter; it++) { - this.chi2 = 0; - this.runFitterIter(swimmer, it, sv, mv); + this.runFitterIter(sv, mv); // chi2 - this.chi2=this.calc_chi2(swimmer, sv, mv); - if(this.chi2(); + for (int k = 1; k < s.trackTraj.size(); k++) { + int layer = mv.measurements.get(k).layer; + double resi = mv.dh(k, s.trackTraj.get(k)); + TrjPoints.put(layer, new HitOnTrack(layer, s.trackTraj.get(k), resi)); if(mv.measurements.get(k).skip) TrjPoints.get(layer).isMeasUsed = false; //System.out.println(" Traj layer "+layer+" x "+TrjPoints.get(layer).x+" y "+TrjPoints.get(layer).y+" z "+TrjPoints.get(layer).z); @@ -90,22 +104,25 @@ public void setTrajectory(AStateVecs sv, AMeasVecs mv) { } @Override - public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { - if (sv.trackTraj.get(k) != null && sv.trackCov.get(k).covMat != null + public void filter(int k, AStateVecs sv, AMeasVecs mv) { + if (sv.trackTraj.get(k) != null && sv.trackTraj.get(k).covMat != null && mv.measurements.get(k).skip == false && filterOn) { double[] K = new double[5]; - double V = mv.measurements.get(k).error; + double V = mv.measurements.get(k).error*mv.measurements.get(k).error; double dh = mv.dh(k, sv.trackTraj.get(k)); - +// System.out.println(dh); //get the projector Matrix - double[] H = new double[5]; - H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), swimmer, dir); + double[] H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), this.getSwimmer()); +// System.out.println(k + " " + mv.measurements.get(k).layer + " " + H[0] + " " + H[1] + " " + H[2] + " " + H[3] + " " + H[4] + " " +dh ); - double[][] CaInv = mo.filterCovMat(H, sv.trackCov.get(k).covMat, V); + if(sv.straight) { + sv.trackTraj.get(k).covMat[2][2]=0; + } + double[][] CaInv = this.getMatrixOps().filterCovMat(H, sv.trackTraj.get(k).covMat, V); if (CaInv != null) { - sv.trackCov.get(k).covMat = CaInv; + sv.trackTraj.get(k).covMat = CaInv; } else { return; } @@ -114,107 +131,46 @@ public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { // the gain matrix K[j] = 0; for (int i = 0; i < 5; i++) { - K[j] += H[i] * sv.trackCov.get(k).covMat[j][i] / V; + K[j] += H[i] * sv.trackTraj.get(k).covMat[j][i] / V; } } - if(sv.straight == true) { - //for (int i = 0; i < 5; i++) { - K[2] = 0; - //} - } - double drho_filt = sv.trackTraj.get(k).d_rho; - double phi0_filt = sv.trackTraj.get(k).phi0; - double kappa_filt = sv.trackTraj.get(k).kappa; - double dz_filt = sv.trackTraj.get(k).dz; - double tanL_filt = sv.trackTraj.get(k).tanL; + + StateVec fVec = sv.new StateVec(sv.trackTraj.get(k)); if (!Double.isNaN(dh)) { - drho_filt -= K[0] * dh; - phi0_filt -= K[1] * dh; - kappa_filt -= K[2] * dh; - dz_filt -= K[3] * dh; - tanL_filt -= K[4] * dh; +// for (int j = 0; j < 5; j++) { +// for (int i = 0; i < 5; i++) { +// System.out.print(CaInv[j][i] + " "); +// } +// System.out.println(); +// } +// System.out.println(k + " " + CaInv[0][0] + " " + CaInv[1][1] + " " + CaInv[2][2] + " " + CaInv[3][3] + " " + CaInv[4][4] + " " + V ); +// System.out.println(k + " " + H[0] + " " + H[1] + " " + H[2] + " " + H[3] + " " + H[4] + " " +dh ); +// System.out.println(k + " " + K[0] + " " + K[1] + " " + K[2] + " " + K[3] + " " + K[4] + " " +dh ); + fVec.d_rho -= K[0] * dh; + fVec.phi0 -= K[1] * dh; + fVec.kappa -= K[2] * dh; + fVec.dz -= K[3] * dh; + fVec.tanL -= K[4] * dh; } - - StateVec fVec = sv.new StateVec(sv.trackTraj.get(k).k); - fVec.d_rho = drho_filt; - fVec.phi0 = phi0_filt; - fVec.kappa = kappa_filt; - fVec.dz = dz_filt; - fVec.tanL = tanL_filt; - fVec.alpha = sv.trackTraj.get(k).alpha; - sv.setStateVecPosAtMeasSite(k, fVec, mv.measurements.get(k), swimmer); - double dh_filt = mv.dh(k, fVec); - if (Math.abs(dh_filt) < Math.abs(dh) - && Math.abs(dh_filt)/Math.sqrt(V) measSurfaces) { - sv.shift = Zref; - //iCov = cov; - mv.setMeasVecs(measSurfaces); - if (sv.Layer != null) { - sv.Layer.clear(); - } else { - sv.Layer = new ArrayList(); - } - if (sv.Sector != null) { - sv.Sector.clear(); - } else { - sv.Sector = new ArrayList(); - } - if (sv.X0 != null) { - sv.X0.clear(); - } else { - sv.X0 = new ArrayList(); - } - if (sv.Y0 != null) { - sv.Y0.clear(); - } else { - sv.Y0 = new ArrayList(); - } - if (sv.Z0 != null) { - sv.Z0.clear(); - } else { - sv.Z0 = new ArrayList(); - } - //take first plane along beam line with n = y-dir; - sv.Layer.add(0); - sv.Sector.add(0); - sv.X0.add(Xb); - sv.Y0.add(Yb); - sv.Z0.add(0.0); - this.NDF = -5; - for (int i = 1; i < mv.measurements.size(); i++) { - sv.Layer.add(mv.measurements.get(i).layer); - sv.Sector.add(mv.measurements.get(i).sector); - if(mv.measurements.get(i).skip==false) { - this.NDF++; - } - Point3D ref = new Point3D(Xb, Yb, 0.0); - sv.X0.add(ref.x()); - sv.Y0.add(ref.y()); - sv.Z0.add(ref.z()); - } - sv.init( helix, cov, this, swimmer); - - } - } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 21f46ed5e..827be6761 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -11,66 +11,72 @@ public class MeasVecs extends AMeasVecs { @Override - public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { - AStateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); - AStateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); + public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer) { + AStateVecs.StateVec SVplus = sv.new StateVec(stateVec.k); + AStateVecs.StateVec SVminus = sv.new StateVec(stateVec.k); + delta_d_a[0]=2*sqrt_epsilon*(stateVec.d_rho+1); delta_d_a[1]=2*sqrt_epsilon*(stateVec.phi0+1); delta_d_a[2]=2*sqrt_epsilon*(stateVec.kappa+1); delta_d_a[3]=2*sqrt_epsilon*(stateVec.dz+1); delta_d_a[4]=2*sqrt_epsilon*(stateVec.tanL+1); -// delta_d_a[0]=2*0.2; -// delta_d_a[1]=2*Math.toRadians(0.1); -// delta_d_a[2]=2*0.02*(stateVec.kappa); -// delta_d_a[3]=2*0.2; -// delta_d_a[4]=2*0.01*(stateVec.tanL+1); +// delta_d_a[0]=2*Math.sqrt(sv.forwardCov.get(stateVec.k).covMat[0][0]); +// delta_d_a[1]=2*Math.sqrt(sv.forwardCov.get(stateVec.k).covMat[1][1]); +// delta_d_a[2]=2*Math.sqrt(sv.forwardCov.get(stateVec.k).covMat[2][2]); +// delta_d_a[3]=2*Math.sqrt(sv.forwardCov.get(stateVec.k).covMat[3][3]); +// delta_d_a[4]=2*Math.sqrt(sv.forwardCov.get(stateVec.k).covMat[4][4]); +// System.out.println("calculating H"); + + for(int i = 0; i < Hval.length; i++) + Hval[i] = 0; - for(int i = 0; i < getHval().length; i++) - getHval()[i] = 0; for(int i = 0; i < getDelta_d_a().length; i++) { - SVplus = this.reset(SVplus, stateVec, sv); - SVminus = this.reset(SVminus, stateVec, sv); +// System.out.println("initial statevec");sv.printlnStateVec(stateVec); + SVplus.copy(stateVec); + SVminus .copy(stateVec); +// System.out.println("SVplus before shift");sv.printlnStateVec(SVplus); if(i ==0) { - SVplus.d_rho = stateVec.d_rho + getDelta_d_a()[i] / 2.; - SVminus.d_rho = stateVec.d_rho - getDelta_d_a()[i] / 2.; + SVplus.d_rho = SVplus.d_rho + getDelta_d_a()[i] / 2.; + SVminus.d_rho = SVminus.d_rho - getDelta_d_a()[i] / 2.; } if(i ==1) { - SVplus.phi0 = stateVec.phi0 + getDelta_d_a()[i] / 2.; - SVminus.phi0 = stateVec.phi0 - getDelta_d_a()[i] / 2.; + SVplus.phi0 = SVplus.phi0 + getDelta_d_a()[i] / 2.; + if(Math.abs(SVplus.phi0)>Math.PI) SVplus.phi0 -= Math.signum(SVplus.phi0)*2*Math.PI; + SVminus.phi0 = SVminus.phi0 - getDelta_d_a()[i] / 2.; + if(Math.abs(SVminus.phi0)>Math.PI) SVminus.phi0 -= Math.signum(SVminus.phi0)*2*Math.PI; } if(i ==2) { - SVplus.kappa = stateVec.kappa + getDelta_d_a()[i] / 2.; - SVminus.kappa = stateVec.kappa - getDelta_d_a()[i] / 2.; + SVplus.kappa = SVplus.kappa + getDelta_d_a()[i] / 2.; + SVminus.kappa = SVminus.kappa - getDelta_d_a()[i] / 2.; } if(i ==3) { - SVplus.dz = stateVec.dz + getDelta_d_a()[i] / 2.; - SVminus.dz = stateVec.dz - getDelta_d_a()[i] / 2.; + SVplus.dz = SVplus.dz + getDelta_d_a()[i] / 2.; + SVminus.dz = SVminus.dz - getDelta_d_a()[i] / 2.; } if(i ==4) { - SVplus.tanL = stateVec.tanL + getDelta_d_a()[i] / 2.; - SVminus.tanL = stateVec.tanL - getDelta_d_a()[i] / 2.; + SVplus.tanL = SVplus.tanL + getDelta_d_a()[i] / 2.; + SVminus.tanL = SVminus.tanL - getDelta_d_a()[i] / 2.; } - SVplus = sv.newStateVecAtMeasSite(stateVec.k, SVplus, mv, swimmer, false); - SVminus = sv.newStateVecAtMeasSite(stateVec.k, SVminus, mv, swimmer, false); +// System.out.println("after shift " + getDelta_d_a()[i] / 2.);sv.printlnStateVec(SVplus); + SVplus.updateFromHelix(); + SVminus.updateFromHelix(); +// System.out.println("after recalculation " + getDelta_d_a()[i] / 2.);sv.printlnStateVec(SVplus); +// sv.printlnStateVec(SVminus); + // if using swimmer, roll-back by few mm before the measurement surface + if(swimmer!= null && !sv.straight) { + SVplus.rollBack(rollBackAngle); + SVminus.rollBack(rollBackAngle); + } + sv.setStateVecPosAtMeasSite(SVplus, mv, null); + sv.setStateVecPosAtMeasSite(SVminus, mv, null); +// sv.printlnStateVec(SVplus); +// sv.printlnStateVec(SVminus); Hval[i] = (this.h(stateVec.k, SVplus) - this.h(stateVec.k, SVminus)) / getDelta_d_a()[i] ; // System.out.println(i + " " + getDelta_d_a()[i] + " " + this.h(stateVec.k, SVplus) + " " + this.h(stateVec.k, SVminus) + " " + Hval[i]); } +// System.out.println("done with H"); - return getHval(); - } - - @Override - public AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) { - SVplus = sv.new StateVec(stateVec.k); - SVplus.d_rho = stateVec.d_rho; - SVplus.alpha = stateVec.alpha; - SVplus.phi0 = stateVec.phi0; - SVplus.kappa = stateVec.kappa; - SVplus.dz = stateVec.dz; - SVplus.tanL = stateVec.tanL; - SVplus.alpha = stateVec.alpha; - - return SVplus; + return Hval; } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 2947465ea..6ae9208c7 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -1,8 +1,7 @@ package org.jlab.clas.tracking.kalmanfilter.helical; -import org.jlab.clas.pdg.PhysicsConstants; +import java.util.HashMap; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.AKFitter; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.AStateVecs; @@ -18,385 +17,210 @@ public class StateVecs extends AStateVecs { - double[] swimPars = new double[7]; @Override - public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec mv, Swim swim, boolean useSwimmer) { - if(swimPars!=null) { - this.resetArrays(swimPars); - } else { - swimPars = new double[7]; - } - if(value!=null) { - this.resetArrays(value); - } else { - value = new double[4]; + public boolean getStateVecPosAtMeasSite(StateVec sv, AMeasVecs.MeasVec mv, Swim swim) { + double[] swimPars = new double[7]; + Point3D pos = new Point3D(0,0,0); + Vector3D mom = new Vector3D(0,0,0); + + if(mv.surface==null) return false; + + int dir = (int) Math.signum(mv.k-sv.k); + if(dir==0) dir=1; + + if(mv.k==0) { + // Transport from measurement surface to DOCA to reference line + // assumes uniform field + sv.setPivot(this.xref, this.yref, this.zref); + sv.toDoca(); + return true; } + + if(mv.surface.plane==null && mv.surface.cylinder==null) return false; - Point3D ps = new Point3D(0,0,0) ; - - AStateVecs.StateVec kVec = new AStateVecs.StateVec(k); - kVec.phi0 = iVec.phi0; - kVec.d_rho = iVec.d_rho; - kVec.kappa = iVec.kappa; - kVec.dz = iVec.dz; - kVec.tanL = iVec.tanL; - kVec.alpha = iVec.alpha; - - if(mv.surface!=null) { - double x = X0.get(0) + kVec.d_rho * Math.cos(kVec.phi0); - double y = Y0.get(0) + kVec.d_rho * Math.sin(kVec.phi0); - double z = Z0.get(0) + kVec.dz; - - Bf.swimmer = swim; - Bf.x = x; - Bf.y = y; - Bf.z = z; - Bf.set(); - kVec.alpha = Bf.alpha; - -// if(k==0 && this.straight==false) { -// double invKappa = 1. / Math.abs(kVec.kappa); -// double px = -invKappa * Math.sin(kVec.phi0 ); -// double py = invKappa * Math.cos(kVec.phi0 ); -// double pz = invKappa * kVec.tanL; -// int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); -// double accuracy = mv.surface.swimAccuracy/units; -// swim.SetSwimParameters(x/units, y/units, z/units, px, py, pz, ch); -// swimPars = swim.SwimRho(50./units, accuracy); -// if(swimPars==null) -// return null; -// swim.SetSwimParameters(swimPars[0], swimPars[1], swimPars[2], -swimPars[3], -swimPars[4], -swimPars[5], -ch); -// Vector3D norm = new Vector3D(px,py,pz).asUnit(); -// Point3D point = new Point3D(mv.surface.plane.point().x()/units, -// mv.surface.plane.point().y()/units, -// mv.surface.plane.point().z()/units); -// swimPars = swim.SwimPlane(norm,point,accuracy); -// if(swimPars==null) -// return null; -// for(int j =0; j < 3; j++) { -// swimPars[j]*=units; -// } -// kVec.x = swimPars[0]; -// kVec.y = swimPars[1]; -// kVec.z = swimPars[2]; -// } - if(k==0) { - value[0] = x; - value[1] = y; - value[2] = z; - value[3] = 0.0; - return value; + if(this.straight) { + + if(mv.surface.plane!=null) { + Line3D toPln = new Line3D(new Point3D(sv.x,sv.y,sv.z),new Vector3D(sv.px,sv.py,sv.pz).asUnit()); + Point3D inters = new Point3D(); + int ints = mv.surface.plane.intersection(toPln, inters); + sv.x = inters.x(); + sv.y = inters.y(); + sv.z = inters.z(); + } + else if(mv.surface.cylinder!=null) { + Point3D st = new Point3D(sv.x, sv.y, sv.z); + Vector3D stu = new Vector3D(sv.px,sv.py,sv.pz).asUnit(); + mv.surface.toLocal().apply(st); + mv.surface.toLocal().apply(stu); + + double r = mv.surface.cylinder.baseArc().radius(); + double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(stu.x()*stu.x()+stu.y()*stu.y())); + double l = (-(st.x()*stu.x()+st.y()*stu.y())+delta)/(stu.x()*stu.x()+stu.y()*stu.y()); + if(Math.signum(st.y()+l*stu.y())!=mv.hemisphere) { + l = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); + } + Point3D cylInt = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); + mv.surface.toGlobal().apply(cylInt); + // RDV: should switch to use clas-geometry intersection method, not done now to alwys return a value + sv.x = cylInt.x(); + sv.y = cylInt.y(); + sv.z = cylInt.z(); } - - if(this.straight) { - Vector3D u = new Vector3D((Math.signum(kVec.kappa)) * Math.sin(kVec.phi0), - -(Math.signum(kVec.kappa)) * Math.cos(kVec.phi0), - -(Math.signum(kVec.kappa)) * kVec.tanL).asUnit(); - + } else { + if(swim==null) { // applicable only to planes parallel to the z -axis + sv.toOldHelix(util); if(mv.surface.plane!=null) { - Line3D toPln = new Line3D(new Point3D(x,y,z),u); - Point3D inters = new Point3D(); - int ints = mv.surface.plane.intersection(toPln, inters); - kVec.x = inters.x() ; - kVec.y = inters.y() ; - kVec.z = inters.z() ; - + pos = util.getHelixPointAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), + mv.surface.finitePlaneCorner2.x(), mv.surface.finitePlaneCorner2.y(), 10); + mom = util.getMomentumAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), + mv.surface.finitePlaneCorner2.x(), mv.surface.finitePlaneCorner2.y(), 10); + sv.x = pos.x(); + sv.y = pos.y(); + sv.z = pos.z(); + sv.px = mom.x(); + sv.py = mom.y(); + sv.pz = mom.z(); } - else if(mv.surface.cylinder!=null) { - Point3D st = new Point3D(x,y,z); - Vector3D stu = new Vector3D(u.x(),u.y(),u.z()); - mv.surface.toLocal().apply(st); - mv.surface.toLocal().apply(stu); - + else { double r = mv.surface.cylinder.baseArc().radius(); - double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(stu.x()*stu.x()+stu.y()*stu.y())); - double l = (-(st.x()*stu.x()+st.y()*stu.y())+delta)/(stu.x()*stu.x()+stu.y()*stu.y()); - if(Math.signum(st.y()+l*stu.y())!=mv.hemisphere) { - l = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); - } - Point3D cylInt = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); - mv.surface.toGlobal().apply(cylInt); - // RDV: should switch to use clas-geometry intersection method, not done now to alwys return a value - kVec.x = cylInt.x(); - kVec.y = cylInt.y(); - kVec.z = cylInt.z(); + pos = util.getHelixPointAtR(r); + mom = util.getMomentumAtR(r); + sv.x = pos.x(); + sv.y = pos.y(); + sv.z = pos.z(); + sv.px = mom.x(); + sv.py = mom.y(); + sv.pz = mom.z(); } - value[0] = kVec.x; - value[1] = kVec.y; - value[2] = kVec.z; - value[3] = this.calcPhi(kVec); - - return value; - } else { + } + else { + swim.SetSwimParameters(sv.x/units, sv.y/units, sv.z/units, + dir*sv.px, dir*sv.py, dir*sv.pz, + KFitter.polarity*(int) Math.signum(sv.kappa)*dir); if(mv.surface.plane!=null) { - if(useSwimmer=false) { // applicable only to planes parallel to the z -axis - double r0 = mv.surface.finitePlaneCorner1.toVector3D().dot(mv.surface.plane.normal()); - double stepSize = 5; //mm - int nSteps = (int) (r0/stepSize); - - double dist = 0; - - for(int i = 1; iMath.PI) deltaPhi0 -= Math.signum(deltaPhi0)*2*Math.PI; + double dphi0_prm_del_drho = -1. / (fVec.d_rho + iVec.alpha / iVec.kappa) * Math.sin(deltaPhi0); + double dphi0_prm_del_phi0 = (iVec.d_rho + iVec.alpha / iVec.kappa) / (fVec.d_rho + iVec.alpha / iVec.kappa) * Math.cos(deltaPhi0); + double dphi0_prm_del_kappa = (iVec.alpha / (iVec.kappa * iVec.kappa)) / (fVec.d_rho + iVec.alpha / iVec.kappa) * Math.sin(deltaPhi0); + double dphi0_prm_del_dz = 0; + double dphi0_prm_del_tanL = 0; + + double drho_prm_del_drho = Math.cos(deltaPhi0); + double drho_prm_del_phi0 = (iVec.d_rho + iVec.alpha / iVec.kappa) * Math.sin(deltaPhi0); + double drho_prm_del_kappa = (iVec.alpha / (iVec.kappa * iVec.kappa)) * (1 - Math.cos(deltaPhi0)); + double drho_prm_del_dz = 0; + double drho_prm_del_tanL = 0; + + double dkappa_prm_del_drho = 0; + double dkappa_prm_del_phi0 = 0; + double dkappa_prm_del_dkappa = 1; + double dkappa_prm_del_dz = 0; + double dkappa_prm_del_tanL = 0; + + double dz_prm_del_drho = ((iVec.alpha / iVec.kappa) / (fVec.d_rho + iVec.alpha / iVec.kappa)) * iVec.tanL * Math.sin(deltaPhi0); + double dz_prm_del_phi0 = (iVec.alpha / iVec.kappa) * iVec.tanL * (1 - Math.cos(deltaPhi0) * (iVec.d_rho + iVec.alpha / iVec.kappa) / (fVec.d_rho + iVec.alpha / iVec.kappa)); + double dz_prm_del_kappa = (iVec.alpha / (iVec.kappa * iVec.kappa)) * iVec.tanL * (deltaPhi0 - Math.sin(deltaPhi0) * (iVec.alpha / iVec.kappa) / (fVec.d_rho + iVec.alpha / iVec.kappa)); + double dz_prm_del_dz = 1; + double dz_prm_del_tanL = -iVec.alpha * (deltaPhi0) / iVec.kappa; + + double dtanL_prm_del_drho = 0; + double dtanL_prm_del_phi0 = 0; + double dtanL_prm_del_dkappa = 0; + double dtanL_prm_del_dz = 0; + double dtanL_prm_del_tanL = 1; + + FMat = new double[][]{ + {drho_prm_del_drho, drho_prm_del_phi0, drho_prm_del_kappa, drho_prm_del_dz, drho_prm_del_tanL}, + {dphi0_prm_del_drho, dphi0_prm_del_phi0, dphi0_prm_del_kappa, dphi0_prm_del_dz, dphi0_prm_del_tanL}, + {dkappa_prm_del_drho, dkappa_prm_del_phi0, dkappa_prm_del_dkappa, dkappa_prm_del_dz, dkappa_prm_del_tanL}, + {dz_prm_del_drho, dz_prm_del_phi0, dz_prm_del_kappa, dz_prm_del_dz, dz_prm_del_tanL}, + {dtanL_prm_del_drho, dtanL_prm_del_phi0, dtanL_prm_del_dkappa, dtanL_prm_del_dz, dtanL_prm_del_tanL} + }; } + return FMat; } @Override - public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { + public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { double[][] Q = new double[5][5]; // if (iVec.k % 2 == 1 && dir > 0) { - if (dir >0 ) { + int dir = f-i; + double t_ov_X0 = 0; + if(dir>0) { + for(int k=i+1; k<=f; k++) t_ov_X0 += mv.measurements.get(k).l_over_X0; + } + else { + for(int k=i; k>f; k--) t_ov_X0 += mv.measurements.get(k).l_over_X0; + } + + if (t_ov_X0>0) { Vector3D trkDir = this.P(iVec.k).asUnit(); Vector3D trkPos = this.X(iVec.k); double x = trkPos.x(); @@ -410,19 +234,15 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { double pt = Math.abs(1. / iVec.kappa); double pz = pt * iVec.tanL; - double p = Math.sqrt(pt * pt + pz * pz); - double sctRMS = 0; - double t_ov_X0 = mVec.l_over_X0; + double p = Math.sqrt(pt * pt + pz * pz); double mass = piMass; // assume given mass hypothesis double beta = p / Math.sqrt(p * p + mass * mass); // use particle momentum t_ov_X0 = t_ov_X0 / cosEntranceAngle; - if(t_ov_X0>0) { // Highland-Lynch-Dahl formula - sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* - (1 + 0.038 * Math.log(t_ov_X0)); + double sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* + (1 + 0.038 * Math.log(t_ov_X0)); //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* // (1 + Math.log(t_ov_X0)/9.); - } Q = new double[][]{ {0, 0, 0, 0, 0}, {0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL), 0, 0, 0}, @@ -434,113 +254,91 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { return Q; } - private void setHelix(Helix util, double x0, double y0, double z0, double px0, double py0, double pz0, - int q, double B) { - util.setTurningSign(q); - util.setB(B); - double pt = Math.sqrt(px0*px0 + py0*py0); - util.setR(pt/(B*util.getLIGHTVEL())) ; - util.setPhi0(Math.atan2(py0, px0)); - util.setTanL(pz0/pt); - util.setZ0(z0); - util.setOmega((double) -q/util.getR()); - - double S = Math.sin(util.getPhi0()); - double C = Math.cos(util.getPhi0()); - - util.setCosphi0(C); - util.setSinphi0(S); - - if(Math.abs(S)>=Math.abs(C)) { - util.setD0(-(x0-X0.get(0))/S) ; - } else { - util.setD0((y0-Y0.get(0))/C) ; - } - - util.Update(); - } - private void setHelixPars(StateVec kVec, Swim swim) { - double x0 = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) ; - double y0 = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) ; - double z0 = Z0.get(kVec.k) + kVec.dz ; - double invKappa = 1. / Math.abs(kVec.kappa); - double px0 = -invKappa * Math.sin(kVec.phi0 ); - double py0 = invKappa * Math.cos(kVec.phi0 ); - double pz0 = invKappa * kVec.tanL; - - int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); - - double B = 1. / (lightVel * kVec.alpha); - this.setHelix(util, x0,y0,z0,px0,py0,pz0,ch, B); - } +// private void setHelix(Helix util, double x0, double y0, double z0, double px0, double py0, double pz0, +// int q, double B) { +// util.setTurningSign(q); +// util.setB(B); +// double pt = Math.sqrt(px0*px0 + py0*py0); +// util.setR(pt/(B*util.getLIGHTVEL())) ; +// util.setPhi0(Math.atan2(py0, px0)); +// util.setTanL(pz0/pt); +// util.setZ0(z0); +// util.setOmega((double) -q/util.getR()); +// +// double S = Math.sin(util.getPhi0()); +// double C = Math.cos(util.getPhi0()); +// +// util.setCosphi0(C); +// util.setSinphi0(S); +// +// if(Math.abs(S)>=Math.abs(C)) { +// util.setD0(-(x0-X0.get(0))/S) ; +// } else { +// util.setD0((y0-Y0.get(0))/C) ; +// } +// +// util.Update(); +// } +// private void setHelixPars(StateVec kVec, Swim swim) { +// StateVec vec = new StateVec(0, kVec); +// vec.updateHelix(); +// vec.phi = 0; +// vec.updateFromHelix(); +// +// double x0 = X0.get(vec.k) + vec.d_rho * Math.cos(vec.phi0) ; +// double y0 = Y0.get(vec.k) + vec.d_rho * Math.sin(vec.phi0) ; +// double z0 = Z0.get(vec.k) + vec.dz ; +// double invKappa = 1. / Math.abs(vec.kappa); +// double px0 = -invKappa * Math.sin(vec.phi0 ); +// double py0 = invKappa * Math.cos(vec.phi0 ); +// double pz0 = invKappa * vec.tanL; +// +// int ch = (int) KFitter.polarity*(int) Math.signum(vec.kappa); +// +// double B = 1. / (lightVel * vec.alpha); +//// System.out.println(x0 + " " + y0 + " " + z0 + " " + px0 + " " + py0 + " " + pz0); +// this.setHelix(util, x0,y0,z0,px0,py0,pz0,ch, B); +// } - @Override - public void setTrackPars(StateVec kVec, Swim swim) { - - double x0 = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) ; - double y0 = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) ; - double z0 = Z0.get(kVec.k) + kVec.dz ; - double invKappa = 1. / Math.abs(kVec.kappa); - double px0 = -invKappa * Math.sin(kVec.phi0 ); - double py0 = invKappa * Math.cos(kVec.phi0 ); - double pz0 = invKappa * kVec.tanL; - int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); - - swim.SetSwimParameters( - x0/units, - y0/units, - z0/units, - px0, py0, pz0, ch); - } - - private double calcPhi(StateVec kVec) { - double xc = X0.get(kVec.k) + (kVec.d_rho + kVec.alpha / kVec.kappa) * Math.cos(kVec.phi0); - double yc = Y0.get(kVec.k) + (kVec.d_rho + kVec.alpha / kVec.kappa) * Math.sin(kVec.phi0); - double r = Math.abs(kVec.alpha / kVec.kappa); - Vector3D ToPoint = new Vector3D(); - Vector3D ToRef = new Vector3D(X0.get(kVec.k) - xc, Y0.get(kVec.k) - yc, 0); - - ToPoint = new Vector3D(kVec.x - xc, kVec.y - yc, 0); - double phi = ToRef.angle(ToPoint); - phi *= -Math.signum(kVec.kappa); - - return phi; - } - private void iterateHelixAtR(int it, int k, StateVec kVec, Swim swim, - double r, B Bf, Point3D ps) { - for(int i = 0; i < it; i++) { - this.setHelixPars(kVec, swim); - ps = util.getHelixPointAtR(r); - kVec.x = ps.x(); - kVec.y = ps.y(); - kVec.z = ps.z(); - this.tranState(k, kVec, swim); - Bf = new B(kVec.k, kVec.x, kVec.y, kVec.z, swim); - kVec.alpha = Bf.alpha; - this.tranState(k, kVec, swim); - this.setHelixPars(kVec, swim); - kVec.x = ps.x(); - kVec.y = ps.y(); - kVec.z = ps.z(); - this.tranState(k, kVec, swim); - } - } - @Override - public StateVec reset(StateVec SV, StateVec stateVec) { - SV = new StateVec(stateVec.k); - SV.x = stateVec.x; - SV.y = stateVec.y; - SV.z = stateVec.z; - SV.d_rho = stateVec.d_rho; - SV.dz = stateVec.dz; - SV.phi0 = stateVec.phi0; - SV.phi = stateVec.phi; - SV.tanL = stateVec.tanL; - SV.alpha = stateVec.alpha; - SV.kappa = stateVec.kappa; - - return SV; - } +// @Override +// public void setTrackPars(StateVec kVec, Swim swim) { +// +// double x0 = kVec.x0 + kVec.d_rho * Math.cos(kVec.phi0) ; +// double y0 = kVec.y0 + kVec.d_rho * Math.sin(kVec.phi0) ; +// double z0 = kVec.z0 + kVec.dz ; +// double invKappa = 1. / Math.abs(kVec.kappa); +// double px0 = -invKappa * Math.sin(kVec.phi0 ); +// double py0 = invKappa * Math.cos(kVec.phi0 ); +// double pz0 = invKappa * kVec.tanL; +// int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); +//// System.out.println("old pivot " + new Point3D(x0,y0,z0).toString() + new Vector3D(px0,py0,pz0).toString()); +// swim.SetSwimParameters( +// x0/units, +// y0/units, +// z0/units, +// px0, py0, pz0, ch); +// } + + +// private void iterateHelixAtR(int it, int k, StateVec kVec, Swim swim, +// double r, B Bf, Point3D ps) { +// for(int i = 0; i < it; i++) { +// this.setHelixPars(kVec, swim); +// ps = util.getHelixPointAtR(r); +// kVec.x = ps.x(); +// kVec.y = ps.y(); +// kVec.z = ps.z(); +// this.tranState(k, kVec, swim); +// Bf = new B(kVec.k, kVec.x, kVec.y, kVec.z, swim); +// kVec.alpha = Bf.alpha; +// this.tranState(k, kVec, swim); +// this.setHelixPars(kVec, swim); +// kVec.x = ps.x(); +// kVec.y = ps.y(); +// kVec.z = ps.z(); +// this.tranState(k, kVec, swim); +// } +// } @Override public Vector3D P(int kf) { @@ -558,9 +356,9 @@ public Vector3D P(int kf) { @Override public Vector3D X(int kf) { if (this.trackTraj.get(kf) != null) { - double x = X0.get(kf) + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.cos(this.trackTraj.get(kf).phi0) - Math.cos(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); - double y = Y0.get(kf) + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.sin(this.trackTraj.get(kf).phi0) - Math.sin(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); - double z = Z0.get(kf) + this.trackTraj.get(kf).dz - this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * this.trackTraj.get(kf).tanL * this.trackTraj.get(kf).phi; + double x = this.trackTraj.get(kf).x0 + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.cos(this.trackTraj.get(kf).phi0) - Math.cos(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); + double y = this.trackTraj.get(kf).y0 + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0) + this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * (Math.sin(this.trackTraj.get(kf).phi0) - Math.sin(this.trackTraj.get(kf).phi0 + this.trackTraj.get(kf).phi)); + double z = this.trackTraj.get(kf).z0 + this.trackTraj.get(kf).dz - this.trackTraj.get(kf).alpha / this.trackTraj.get(kf).kappa * this.trackTraj.get(kf).tanL * this.trackTraj.get(kf).phi; return new Vector3D(x, y, z); } else { @@ -571,9 +369,9 @@ public Vector3D X(int kf) { @Override public Vector3D X(StateVec kVec, double phi) { if (kVec != null) { - double x = X0.get(kVec.k) + kVec.d_rho * Math.cos(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.cos(kVec.phi0) - Math.cos(kVec.phi0 + phi)); - double y = Y0.get(kVec.k) + kVec.d_rho * Math.sin(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.sin(kVec.phi0) - Math.sin(kVec.phi0 + phi)); - double z = Z0.get(kVec.k) + kVec.dz - kVec.alpha / kVec.kappa * kVec.tanL * phi; + double x = kVec.x0 + kVec.d_rho * Math.cos(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.cos(kVec.phi0) - Math.cos(kVec.phi0 + phi)); + double y = kVec.y0 + kVec.d_rho * Math.sin(kVec.phi0) + kVec.alpha / kVec.kappa * (Math.sin(kVec.phi0) - Math.sin(kVec.phi0 + phi)); + double z = kVec.z0 + kVec.dz - kVec.alpha / kVec.kappa * kVec.tanL * phi; return new Vector3D(x, y, z); } else { @@ -598,9 +396,9 @@ public Vector3D P0(int kf) { @Override public Vector3D X0(int kf) { if (this.trackTraj.get(kf) != null) { - double x = X0.get(kf) + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0); - double y = Y0.get(kf) + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0); - double z = Z0.get(kf) + this.trackTraj.get(kf).dz; + double x = this.trackTraj.get(kf).x0 + this.trackTraj.get(kf).d_rho * Math.cos(this.trackTraj.get(kf).phi0); + double y = this.trackTraj.get(kf).y0 + this.trackTraj.get(kf).d_rho * Math.sin(this.trackTraj.get(kf).phi0); + double z = this.trackTraj.get(kf).z0 + this.trackTraj.get(kf).dz; return new Vector3D(x, y, z); } else { @@ -616,83 +414,81 @@ public Helix setTrackPars() { int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(0).kappa); double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel ; - return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, X0.get(0), Y0.get(0), util.units); + return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, this.xref, this.yref, util.units); } - public StateVec initSV = new StateVec(0); - + + @Override - public void init(Helix trk, double[][] cov, AKFitter kf, - Swim swimmer) { - this.units = trk.getUnitScale(); - this.lightVel = trk.getLIGHTVEL(); - this.util = trk; - //init stateVec - //StateVec initSV = new StateVec(0); - initSV.x = - trk.getD0() * Math.sin(trk.getPhi0()); - initSV.y = trk.getD0() * Math.cos(trk.getPhi0()); - initSV.z = trk.getZ0(); - - double xcen = (1. / trk.getOmega() - trk.getD0()) * Math.sin(trk.getPhi0()); - double ycen = (-1. / trk.getOmega() + trk.getD0()) * Math.cos(trk.getPhi0()); - - B Bf = new B(0, (float)initSV.x, (float)initSV.x, (float)initSV.z, swimmer); + public void init(Helix helix, double[][] cov, double xref, double yref, double zref, Swim swimmer) { + this.trackTraj = new HashMap<>(); + this.units = helix.getUnitScale(); + this.lightVel = helix.getLIGHTVEL(); + this.util = helix; + + this.xref = xref; + this.yref = yref; + this.zref = zref; - if(Math.abs(Bf.Bz)<0.001) + //init stateVec, pivot set to current vertex + initSV = new StateVec(0); + initSV.x0 = helix.getX(); + initSV.y0 = helix.getY(); + initSV.z0 = helix.getZ(); + initSV.x = helix.getX(); + initSV.y = helix.getY(); + initSV.z = helix.getZ(); + initSV.px = helix.getPx(); + initSV.py = helix.getPy(); + initSV.pz = helix.getPz(); +// this.printlnStateVec(initSV); + + if(Math.abs(helix.getB())<0.001) this.straight = true; +// System.out.println(this.straight); + // set bfield according to input helix for consistency + initSV.alpha = 1/(helix.getB()*helix.getLIGHTVEL()); + // set kappa to define the charge + initSV.kappa = initSV.alpha * helix.getOmega(); + // convert from the helix class representation to KF + // kappa = alpha/omega = - q / pt + // drho = - d0 + // phi0 = (phi0 - 90) +// initSV.kappa = initSV.alpha * trk.getOmega(); +// initSV.phi0 = trk.getPhi0()-Math.PI/2; +// initSV.dz = trk.getZ(); +// initSV.tanL = trk.getTanL(); +// initSV.d_rho = -trk.getD0(); + + // recalculate helix parameters from vertex and momentum using chosen pivot + initSV.updateHelix(); - initSV.alpha = Bf.alpha; - initSV.kappa = Bf.alpha * trk.getOmega(); - initSV.phi0 = Math.atan2(ycen, xcen); - if (initSV.kappa < 0) { - initSV.phi0 = Math.atan2(-ycen, -xcen); - } - - initSV.dz = trk.getZ(); - initSV.tanL = trk.getTanL(); - initSV.d_rho = trk.getD0()*(Math.cos(trk.getPhi0())*Math.sin(initSV.phi0) -Math.sin(trk.getPhi0())*Math.cos(initSV.phi0)); - - double x0 = X0.get(0) + initSV.d_rho * Math.cos(initSV.phi0) ; - double y0 = Y0.get(0) + initSV.d_rho * Math.sin(initSV.phi0) ; - double z0 = Z0.get(0) + initSV.dz ; - double invKappa = 1. / Math.abs(initSV.kappa); - double px0 = -invKappa * Math.sin(initSV.phi0 ); - double py0 = invKappa * Math.cos(initSV.phi0 ); - double pz0 = invKappa * initSV.tanL; - - initSV.phi = 0; - - this.trackTraj.put(0, initSV); - CovMat initCM = new CovMat(0); double[][] covKF = new double[5][5]; + //convert from helix to KF representation for(int ic = 0; ic<5; ic++) { for(int ir = 0; ir<5; ir++) { covKF[ic][ir]=cov[ic][ir]; + if(ic==2) + covKF[ic][ir]*=initSV.alpha; + if(ir==2) + covKF[ic][ir]*=initSV.alpha; } } - //convert from helix to KF representation - for(int i = 0; i<5; i++) { - for(int j = 0; j<5; j++) { - if(i==2) - covKF[i][j]*=Bf.alpha; - if(j==2) - covKF[i][j]*=Bf.alpha; - - } - } - //covKF[2][2] = cov[2][2]*600 ; - initCM.covMat = covKF; - this.trackCov.put(0, initCM); + initSV.covMat = covKF; + this.trackTraj.put(0, new StateVec(initSV)); } @Override public void printlnStateVec(StateVec S) { - System.out.println(S.k + ") drho " + S.d_rho + " phi0 " + S.phi0 + " kappa " + S.kappa + " dz " + S.dz + " tanL " + S.tanL + " phi " + S.phi + " x " + S.x + " y " + S.y + " z " + S.z + " alpha " + S.alpha); + String s = String.format("%d) drho=%.4f phi0=%.4f kappa=%.4f dz=%.4f tanL=%.4f alpha=%.4f\n", S.k, S.d_rho, S.phi0, S.kappa, S.dz, S.tanL, S.alpha); + s += String.format(" x0=%.4f y0=%.4f z0=%.4f", S.x0, S.y0, S.z0); + s += String.format(" phi=%.4f x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", S.phi, S.x, S.y, S.z, S.px, S.py, S.pz); + System.out.println(s); } @Override - public void init(double x0, double z0, double tx, double tz, double units, double[][] cov, AKFitter kf) { + public void init(double x0, double z0, double tx, double tz, double units, double[][] cov) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index ee25a0eaa..79509181e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -1,16 +1,14 @@ package org.jlab.clas.tracking.kalmanfilter.straight; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.AKFitter; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.kalmanfilter.AStateVecs.StateVec; import org.jlab.clas.tracking.kalmanfilter.Surface; -import org.jlab.geom.prim.Point3D; +import org.jlab.clas.tracking.utilities.MatrixOps.Libr; /** * @@ -22,29 +20,54 @@ public class KFitter extends AKFitter { public double yz_slope; public double yx_interc; public double yz_interc; - private double resiCut = 100;//residual cut for the measurements - public Map TrjPoints = new HashMap(); - StateVecs sv = new StateVecs(); - MeasVecs mv = new MeasVecs(); + private final double resiCut = 100;//residual cut for the measurements + public Map TrjPoints = new HashMap<>(); + public final StateVecs sv = new StateVecs(); + public final MeasVecs mv = new MeasVecs(); public StateVecs.StateVec finalStateVec; + + public KFitter(boolean filter, int iterations, boolean beamspot, Libr m) { + super(filter, iterations, beamspot, null, m); + } - public KFitter(double x0, double z0,double tx,double tz, double units, double[][] cov, KFitter kf, - List measSurfaces) { - this.init(x0, z0, tx, tz, units, cov, kf, measSurfaces); + public void runFitter() { + this.runFitter(sv, mv); } - public void runFitter(Swim swimmer) { - this.runFitter(swimmer, sv, mv); + + public void init(double x0, double z0,double tx,double tz, double units, double[][] cov, List measSurfaces) { + finalStateVec = null; + this.NDF0 = -45; + this.NDF = -4; + this.chi2 = Double.POSITIVE_INFINITY; + this.numIter = 0; + this.setFitFailed = false; + mv.setMeasVecs(measSurfaces); + for(int j =0; j<5; j++) { + mv.delta_d_a[j]=cov[j][j]; + } + for (int i = 1; i < mv.measurements.size(); i++) { + if(mv.measurements.get(i).skip==false) { + this.NDF++; + } + } + sv.init(x0, z0, tx, tz, units, cov); + //double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf } @Override - public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { - double newchisq = Double.POSITIVE_INFINITY; - this.NDF = sv.Layer.size()-5; - + public void runFitter(AStateVecs sv, AMeasVecs mv) { for (int it = 0; it < totNumIter; it++) { - this.chi2 = 0; - this.runFitterIter(swimmer, it, sv, mv); - if(sv.trackTraj.get(1)!=null) { + this.runFitterIter(sv, mv); + + // chi2 + double newchisq = this.calc_chi2(sv, mv); + // if curvature is 0, fit failed + if(sv.trackTraj.get(1)==null) { + this.setFitFailed = true; + break; + } + else if(newchisq < this.chi2) { + this.chi2 = newchisq; finalStateVec = sv.trackTraj.get(1); finalStateVec.x = finalStateVec.x0; finalStateVec.z = finalStateVec.z0; @@ -53,27 +76,23 @@ public void runFitter(Swim swimmer, AStateVecs sv, AMeasVecs mv) { yz_slope = finalStateVec.tz; yx_interc = finalStateVec.x0; yz_interc = finalStateVec.z0; - - + this.setTrajectory(sv, mv); setFitFailed = false; - } else { - //this.chi2 =newchisq ; - //break; + } + // stop if chi2 got worse + else { + break; } } - } @Override public void setTrajectory(AStateVecs sv, AMeasVecs mv) { - TrjPoints.clear(); - double c2 = 0; + TrjPoints = new HashMap<>(); for (int k = 0; k < sv.trackTraj.size()-1; k++) { - StateVec stv = sv.transported(k, k+1, sv.trackTraj.get(k), mv.measurements.get(k+1), null); - sv.setStateVecPosAtMeasSite(k+1, stv, mv.measurements.get(k+1), null); + StateVec stv = sv.trackTraj.get(k+1); double resi = mv.dh(k+1, stv); - c2 += resi*resi / mv.measurements.get(k+1).error; int layer = mv.measurements.get(k+1).layer; double x = stv.x; double y = stv.y; @@ -88,23 +107,22 @@ public void setTrajectory(AStateVecs sv, AMeasVecs mv) { //System.out.println("interc "+new Point3D(stv.x0,0,stv.z0).toString()+" P "+new Point3D(px,py,pz).toString()); //System.out.println("...reso "+resi+" dl "+stv.dl+" Traj layer "+layer+" x "+TrjPoints.get(layer).x+" y "+TrjPoints.get(layer).y+" z "+TrjPoints.get(layer).z); } - this.chi2 = c2; } @Override - public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { - if (sv.trackTraj.get(k) != null && sv.trackCov.get(k).covMat != null - && mv.measurements.get(k).skip == false ) { + public void filter(int k, AStateVecs sv, AMeasVecs mv) { + if (sv.trackTraj.get(k) != null && sv.trackTraj.get(k).covMat != null + && mv.measurements.get(k).skip == false && this.filterOn) { double[] K = new double[5]; - double V = mv.measurements.get(k).error; + double V = mv.measurements.get(k).error*mv.measurements.get(k).error; //get the projector Matrix double[] H = new double[5]; - H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), swimmer, dir); + H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), null); - double[][] CaInv = mo.filterCovMat(H, sv.trackCov.get(k).covMat, V); + double[][] CaInv = this.getMatrixOps().filterCovMat(H, sv.trackTraj.get(k).covMat, V); if (CaInv != null) { - sv.trackCov.get(k).covMat = CaInv; + sv.trackTraj.get(k).covMat = CaInv; } else { return; } @@ -113,7 +131,7 @@ public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { K[j] = 0; if(filterOn) { for (int i = 0; i < 4; i++) { - K[j] += H[i] * sv.trackCov.get(k).covMat[j][i] / V; + K[j] += H[i] * sv.trackTraj.get(k).covMat[j][i] / V; } } } @@ -137,41 +155,9 @@ public void filter(int k, Swim swimmer, int dir, AStateVecs sv, AMeasVecs mv) { fVec.z0 = z0_filt; fVec.tx = tx_filt; fVec.tz = tz_filt; - sv.setStateVecPosAtMeasSite(k, fVec, mv.measurements.get(k), swimmer); + sv.setStateVecPosAtMeasSite(fVec, mv.measurements.get(k), null); sv.trackTraj.get(k).resi = mv.dh(k, fVec); } } - - public void init(double x0, double z0,double tx,double tz, double units, double[][] cov, AKFitter kf, - List measSurfaces) { - mv.setMeasVecs(measSurfaces); - if (sv.Layer != null) { - sv.Layer.clear(); - } else { - sv.Layer = new ArrayList(); - } - if (sv.Sector != null) { - sv.Sector.clear(); - } else { - sv.Sector = new ArrayList(); - } - for(int j =0; j<5; j++) { - mv.delta_d_a[j]=cov[j][j]; - } - //take first plane along beam line with n = y-dir; - sv.Layer.add(0); - sv.Sector.add(0); - this.NDF = -4; - for (int i = 1; i < mv.measurements.size(); i++) { - sv.Layer.add(mv.measurements.get(i).layer); - sv.Sector.add(mv.measurements.get(i).sector); - if(mv.measurements.get(i).skip==false) { - this.NDF++; - } - Point3D ref = new Point3D(0.0, 0.0, 0.0); - } - sv.init(x0, z0, tx, tz, units, cov, kf); - //double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf - } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java index fe4078a52..a7fe13440 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/MeasVecs.java @@ -11,51 +11,35 @@ public class MeasVecs extends AMeasVecs { @Override - public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer, int dir) { - AStateVecs.StateVec SVplus = null;// = new StateVec(stateVec.k); - AStateVecs.StateVec SVminus = null;// = new StateVec(stateVec.k); + public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim swimmer) { + AStateVecs.StateVec SVplus = sv.new StateVec(stateVec); + AStateVecs.StateVec SVminus = sv.new StateVec(stateVec); for(int i = 0; i < getHval().length; i++) getHval()[i] = 0; for(int i = 0; i < getDelta_d_a().length-1; i++) { - SVplus = this.reset(SVplus, stateVec, sv); - SVminus = this.reset(SVminus, stateVec, sv); if(i ==0) { - SVplus.x0 = stateVec.x0 + getDelta_d_a()[i] / 2.; + SVplus.x0 = stateVec.x0 + getDelta_d_a()[i] / 2.; SVminus.x0 = stateVec.x0 - getDelta_d_a()[i] / 2.; } if(i ==1) { - SVplus.z0 = stateVec.z0 + getDelta_d_a()[i] / 2.; + SVplus.z0 = stateVec.z0 + getDelta_d_a()[i] / 2.; SVminus.z0 = stateVec.z0 - getDelta_d_a()[i] / 2.; } if(i ==2) { - SVplus.tx = stateVec.tx + getDelta_d_a()[i] / 2.; + SVplus.tx = stateVec.tx + getDelta_d_a()[i] / 2.; SVminus.tz = stateVec.tz - getDelta_d_a()[i] / 2.; } if(i ==3) { - SVplus.tz = stateVec.tz + getDelta_d_a()[i] / 2.; + SVplus.tz = stateVec.tz + getDelta_d_a()[i] / 2.; SVminus.tz = stateVec.tz - getDelta_d_a()[i] / 2.; } - SVplus = sv.newStateVecAtMeasSite(stateVec.k, SVplus, mv, swimmer, false); - SVminus = sv.newStateVecAtMeasSite(stateVec.k, SVminus, mv, swimmer, false); + sv.setStateVecPosAtMeasSite(SVplus, mv, swimmer); + sv.setStateVecPosAtMeasSite(SVminus, mv, swimmer); Hval[i] = (this.h(stateVec.k, SVplus) - this.h(stateVec.k, SVminus)) / getDelta_d_a()[i] ; } return getHval(); } - - @Override - public AStateVecs.StateVec reset(AStateVecs.StateVec SVplus, AStateVecs.StateVec stateVec, AStateVecs sv) { - SVplus = sv.new StateVec(stateVec.k); - SVplus.x0 = stateVec.x0; - SVplus.z0 = stateVec.z0; - SVplus.tx = stateVec.tx; - SVplus.tz = stateVec.tz; - SVplus.x = stateVec.x; - SVplus.y = stateVec.y; - SVplus.z = stateVec.z; - - return SVplus; - } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index e1417ea67..ff14bb5bb 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -1,8 +1,7 @@ package org.jlab.clas.tracking.kalmanfilter.straight; -import org.jlab.clas.pdg.PhysicsConstants; +import java.util.HashMap; import org.jlab.clas.swimtools.Swim; -import org.jlab.clas.tracking.kalmanfilter.AKFitter; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs; import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.AStateVecs; @@ -19,154 +18,88 @@ public class StateVecs extends AStateVecs { @Override - public double[] getStateVecPosAtMeasSite(int k, StateVec iVec, AMeasVecs.MeasVec mv, Swim swim, boolean useSwimmer) { - if(swimPars!=null) { - this.resetArrays(swimPars); - } else { - swimPars = new double[7]; - } - if(value!=null) { - this.resetArrays(value); - } else { - value = new double[4]; - } + public boolean getStateVecPosAtMeasSite(StateVec vec, AMeasVecs.MeasVec mv, Swim swim) { + double[] value = new double[4]; Point3D ps = new Point3D(0,0,0) ; - StateVec kVec = new StateVec(k); + if(mv.surface==null) return false; - kVec.x0 = iVec.x0; - kVec.z0 = iVec.z0; - kVec.tx = iVec.tx; - kVec.tz = iVec.tz; - kVec.dl = 0; + double x = vec.x0 ; + double y = 0 ; + double z = vec.z0; + + Point3D ref = new Point3D(x,y,z); + + double tx = vec.tx; + double tz = vec.tz; + + double py = (double) mv.hemisphere/Math.sqrt(1+tx*tx+tz*tz); + double px = tx*py; + double pz = tz*py; + + Vector3D u = new Vector3D(px, py, pz).asUnit(); + + if(mv.k==0) { + vec.x = x; + vec.y = y; + vec.z = z; + vec.dl = 0.0; + return true; + } + else if(mv.hemisphere!=0) { + if(mv.surface.plane!=null) { + Line3D toPln = new Line3D(ref,u); + Point3D inters = new Point3D(); + int ints = mv.surface.plane.intersection(toPln, inters); + vec.x = inters.x() ; + vec.y = inters.y() ; + vec.z = inters.z() ; + vec.dl = ref.distance(inters); - if(mv.surface!=null) { - double x = kVec.x0 ; - double y = 0 ; - double z = kVec.z0; - - Point3D ref = new Point3D(x,y,z); - - double tx = kVec.tx; - double tz = kVec.tz; - - double py = (double) mv.hemisphere/Math.sqrt(1+tx*tx+tz*tz); - double px = tx*py; - double pz = tz*py; - - Vector3D u = new Vector3D(px, py, pz).asUnit(); - - if(k==0) { - value[0] = x; - value[1] = y; - value[2] = z; - value[3] = 0.0; - return value; } - - if(mv.hemisphere!=0) { - if(mv.surface.plane!=null) { - Line3D toPln = new Line3D(ref,u); - Point3D inters = new Point3D(); - int ints = mv.surface.plane.intersection(toPln, inters); - kVec.x = inters.x() ; - kVec.y = inters.y() ; - kVec.z = inters.z() ; - kVec.dl = ref.distance(inters); - - } - if(mv.surface.cylinder!=null) { - mv.surface.toLocal().apply(ref); - mv.surface.toLocal().apply(u); - double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); - double delta = Math.sqrt((ref.x()*u.x()+ref.y()*u.y())*(ref.x()*u.x()+ref.y()*u.y()) - -(-r*r+ref.x()*ref.x()+ref.y()*ref.y())*(u.x()*u.x()+u.y()*u.y())); - double l = (-(ref.x()*u.x()+ref.y()*u.y())+delta)/(u.x()*u.x()+u.y()*u.y()); - if(Math.signum(ref.y()+l*u.y())!=mv.hemisphere) { - l = (-(ref.x()*u.x()+ref.y()*u.y())-delta)/(u.x()*u.x()+u.y()*u.y()); - } - - Point3D cylInt = new Point3D(ref.x()+l*u.x(),ref.y()+l*u.y(),ref.z()+l*u.z()); - mv.surface.toGlobal().apply(cylInt); + if(mv.surface.cylinder!=null) { + mv.surface.toLocal().apply(ref); + mv.surface.toLocal().apply(u); + double r = 0.5*(mv.surface.cylinder.baseArc().radius()+mv.surface.cylinder.highArc().radius()); + double delta = Math.sqrt((ref.x()*u.x()+ref.y()*u.y())*(ref.x()*u.x()+ref.y()*u.y()) + -(-r*r+ref.x()*ref.x()+ref.y()*ref.y())*(u.x()*u.x()+u.y()*u.y())); + double l = (-(ref.x()*u.x()+ref.y()*u.y())+delta)/(u.x()*u.x()+u.y()*u.y()); + if(Math.signum(ref.y()+l*u.y())!=mv.hemisphere) { + l = (-(ref.x()*u.x()+ref.y()*u.y())-delta)/(u.x()*u.x()+u.y()*u.y()); + } + + Point3D cylInt = new Point3D(ref.x()+l*u.x(),ref.y()+l*u.y(),ref.z()+l*u.z()); + mv.surface.toGlobal().apply(cylInt); // mv.surface.toGlobal().apply(ref); // mv.surface.toGlobal().apply(u); - kVec.dl = l; - kVec.x = cylInt.x(); - kVec.y = cylInt.y(); - kVec.z = cylInt.z(); - - } - - value[0] = kVec.x; - value[1] = kVec.y; - value[2] = kVec.z; - value[3] = kVec.dl ; - - return value; + vec.dl = l; + vec.x = cylInt.x(); + vec.y = cylInt.y(); + vec.z = cylInt.z(); + } + return true; } - return value; - } - @Override - public void setStateVecPosAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer) { - - double[] pars = this.getStateVecPosAtMeasSite(k, kVec, mv, swimmer, true); - if (pars == null) { - return; + else { + return false; } - kVec.x = pars[0]; - kVec.y = pars[1]; - kVec.z = pars[2]; - kVec.dl = pars[3]; } - + @Override - public StateVec newStateVecAtMeasSite(int k, StateVec kVec, MeasVec mv, Swim swimmer, boolean useSwimmer) { + public boolean setStateVecPosAtMeasSite(StateVec sv, MeasVec mv, Swim swimmer) { - StateVec newVec = kVec; - double[] pars = this.getStateVecPosAtMeasSite(k, kVec, mv, swimmer, useSwimmer); - if (pars == null) { - return null; + boolean status = this.getStateVecPosAtMeasSite(sv, mv, swimmer); + if (!status) { + return false; } - - newVec.x = pars[0]; - newVec.y = pars[1]; - newVec.z = pars[2]; - newVec.dl = pars[3]; - // new state: - return newVec; - } - - @Override - public void tranState(int f, StateVec iVec, Swim swimmer) { - - } - - @Override - public StateVec transported(int i, int f, StateVec iVec, AMeasVecs.MeasVec mv, Swim swimmer) { - // transport stateVec... - StateVec fVec = new StateVec(f); - - fVec.x0 = iVec.x0; - fVec.z0 = iVec.z0; - fVec.x = iVec.x0; - fVec.y = 0; - fVec.z = iVec.z0; - fVec.tx = iVec.tx; - fVec.tz = iVec.tz; - fVec.dl = 0; - if(f>0) - this.newStateVecAtMeasSite(f, fVec, mv, swimmer, true); - - return fVec; + sv.k = mv.k; + return true; } @Override - public void transport(int i, int f, StateVec iVec, CovMat icovMat, AMeasVecs.MeasVec mv, Swim swimmer) { - AStateVecs.StateVec fVec = this.transported(i, f, iVec, mv, swimmer); - + public double[][] F(StateVec iVec, StateVec fVec) { double[][] FMat = new double[][]{ {1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, @@ -174,27 +107,13 @@ public void transport(int i, int f, StateVec iVec, CovMat icovMat, AMeasVecs.Mea {0, 0, 0, 1, 0}, {0, 0, 0, 0, 1} }; - - - this.trackTraj.put(f, fVec); - //F = new Matrix(); - //F.set(FMat); - - double[][] Cpropagated = propagatedMatrix(FMat, icovMat.covMat, FMat); - - if (Cpropagated != null) { - CovMat fCov = new CovMat(f); - double[][] CPN = addProcessNoise(Cpropagated, this.Q(iVec, mv, f - i)); - - fCov.covMat = CPN; - //CovMat = fCov; - this.trackCov.put(f, fCov); - } + return FMat; } @Override - public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { + public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { double[][] Q = new double[5][5]; + int dir = f-i; if (dir >0 ) { Vector3D trkDir = this.P(iVec.k).asUnit(); Vector3D trkPos = this.X(iVec.k); @@ -210,7 +129,7 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { double p = 1; double sctRMS = 0; - double t_ov_X0 = mVec.l_over_X0; + double t_ov_X0 = mv.measurements.get(i).l_over_X0; double mass = piMass; // assume given mass hypothesis double beta = 1; // use particle momentum t_ov_X0 = t_ov_X0 / cosEntranceAngle; @@ -236,21 +155,6 @@ public double[][] Q(StateVec iVec, AMeasVecs.MeasVec mVec, int dir) { return Q; } - @Override - public StateVec reset(StateVec SV, StateVec stateVec) { - SV = new StateVec(stateVec.k); - SV.x = stateVec.x; - SV.y = stateVec.y; - SV.z = stateVec.z; - SV.x0 = stateVec.x0; - SV.z0 = stateVec.z0; - SV.tx = stateVec.tx; - SV.tz = stateVec.tz; - SV.dl = stateVec.dl; - - return SV; - } - @Override public Vector3D P(int kf) { if (this.trackTraj.get(kf) != null) { @@ -308,16 +212,18 @@ public void printlnStateVec(StateVec S) { } @Override - public void init(Helix trk, double[][] cov, AKFitter kf, Swim swimmer) { + public void init(Helix trk, double[][] cov, double xref, double yref, double zref, Swim swimmer) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - public StateVec initSV = new StateVec(0); + @Override - public void init(double x0, double z0, double tx, double tz, double units, double[][] cov, AKFitter kf) { + public void init(double x0, double z0, double tx, double tz, double units, double[][] cov) { + this.trackTraj = new HashMap<>(); this.units = units; //this.lightVel = 0.0000299792458*units; //init stateVec //StateVec initSV = new StateVec(0); + initSV = new StateVec(0); initSV.x0 = x0; initSV.z0 = z0; initSV.x = x0; @@ -326,31 +232,19 @@ public void init(double x0, double z0, double tx, double tz, double units, doubl initSV.tx = tx; initSV.tz = tz; initSV.dl = 0; - this.trackTraj.put(0, initSV); - CovMat initCM = new CovMat(0); - double[][] covKF = new double[5][5]; - + double[][] covKF = new double[5][5]; for(int ic = 0; ic<5; ic++) { for(int ir = 0; ir<5; ir++) { covKF[ic][ir]=cov[ic][ir]; } } - - initCM.covMat = covKF; - this.trackCov.put(0, initCM); - } - - - @Override - public void setTrackPars(StateVec sv, Swim swim) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + initSV.covMat = covKF; + this.trackTraj.put(0, new StateVec(initSV)); } @Override public Helix setTrackPars() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - - - + } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index a9c49e6f9..9da0009d9 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -39,6 +39,10 @@ public class Helix { public Units units = Units.CM; //default + public Helix() { + + } + public Helix(double d0, double phi0, double omega, double z0, double tanL, int turningSign, double B, double xb, double yb, Units unit) { _d0 = d0; @@ -631,4 +635,11 @@ public void setLIGHTVEL(double aLIGHTVEL) { private static double LightVel = 0.00299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c private static double unitScale = 1; + + @Override + public String toString() { + String s = String.format(" drho=%.4f phi0=%.4f radius=%.4f z0=%.4f tanL=%.4f B=%.4f\n", this._d0, this._phi0, this._R, this._z0, this._tanL, this._B); + s += String.format(" phi=%.4f x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", this.tFlightLen, this._x, this._y, this._z, this._px, this._py, this._pz); + return s; + } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java index a6f4c437e..8ae4c4fdc 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Seed.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.tracking.trackrep; import java.util.ArrayList; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java index 54b2e9319..abf11ce71 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java @@ -80,6 +80,25 @@ public double[][] MatrixAddition(Object obj1, Object obj2) { return result; } + public double[][] MatrixSubtraction(Object obj1, Object obj2) { + double[][] arr1 = this.ConversionToArray(obj1); + double[][] arr2 = this.ConversionToArray(obj2); + double[][] result = null; + if(arr1==null || arr2==null) + return null; + if(arr1.length!=arr2.length || arr1[0].length!=arr2[0].length) + return null; + result = new double[arr1.length][arr1[0].length]; + for(int r = 0; r< arr1.length; r++) { + for(int c = 0; c< arr1[0].length; c++) { + result[r][c] = arr1[r][c]-arr2[r][c]; + } + } + arr1 = null; + arr2 = null; + + return result; + } public double[][] MatrixMultiplication(Object obj1, Object obj2) { double[][] arr1 = this.ConversionToArray(obj1); double[][] arr2 = this.ConversionToArray(obj2); @@ -102,11 +121,11 @@ public double[][] MatrixMultiplication(Object obj1, Object obj2) { } public double[][] MatrixTranspose(Object obj1) { double[][] arr1 = this.ConversionToArray(obj1); - double[][] result = null; if(arr1==null) return null; int r =arr1.length; int c=arr1[0].length; - + double[][] result = new double[c][r]; + for(int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { result[i][j] = arr1[j][j]; @@ -193,4 +212,25 @@ public byte value() { return (byte) this.value; } } + + + /** + * prints the matrix -- used for debugging + * + * @param mat matrix + * @param message + */ + public static void printMatrix(double[][] mat, String message) { + int nrow = mat.length; + int ncol = mat[0].length; + + System.out.println("\t" + message); + for (int ir = 0; ir < nrow; ir++) { + for (int ic = 0; ic < ncol; ic++) { + System.out.print("\t" + mat[ir][ic]); + } + System.out.print("\n"); + } + System.out.println(); + } } diff --git a/etc/bankdefs/hipo4/cvt.json b/etc/bankdefs/hipo4/cvt.json index 32e06dcef..5e5bfa250 100644 --- a/etc/bankdefs/hipo4/cvt.json +++ b/etc/bankdefs/hipo4/cvt.json @@ -85,7 +85,7 @@ {"name":"seedID", "type":"S", "info":"ID of track seed"}, {"name":"xb", "type":"F", "info":"x offset "}, {"name":"yb", "type":"F", "info":"y offset "}, - {"name":"status", "type":"S", "info":"track status : 1abc (a = nb SVT crosses, b = nb BMT Z clusters, c = nb BMT C clusters, used in fit)"} + {"name":"status", "type":"S", "info":"track status : nabc (n = KF iterations a = nb SVT crosses, b = nb BMT Z clusters, c = nb BMT C clusters, used in fit)"} ] }, { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index c8071ea24..fd148eacc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -15,14 +15,14 @@ public class Constants { Constants() { } - private static final double COVD0D0 = 1./50.; - private static final double COVD0PHI0 = 1./50.; - private static final double COVD0RHO = 1./50.; - private static final double COVPHI0PHI0 = 1./50.; - private static final double COVPHI0RHO = 1./50.; - private static final double COVRHORHO = 1./50.; - private static final double COVZ0Z0 = 1.; - private static final double CONVTANLTANL = 1.; + private static final double COVD0D0 = 1.;///50.; + private static final double COVD0PHI0 = 1;//./50.; + private static final double COVD0RHO = 1.;///50.; + private static final double COVPHI0PHI0 = 1.;///50.; + private static final double COVPHI0RHO = 1.;///50.; + private static final double COVRHORHO = 1.;//50.; + private static final double COVZ0Z0 = 10.; + private static final double CONVTANLTANL = 10.; public static double[][] COVMATSCALEFACT = new double[][]{ {COVD0D0, COVD0PHI0, COVD0RHO,1.0,1.0}, @@ -65,10 +65,11 @@ public class Constants { public static boolean KFFILTERON = true; public static boolean INITFROMMC = false; - + public static int KFITERATIONS = 1; + public static final boolean TRACKSFROMORIGIN = true; - public static boolean BEAMSPOTCONST = false; + private static int BEAMSPOTCONST = 0; public static Libr kfMatLib; @@ -77,7 +78,7 @@ public class Constants { private static double _Xb =0; private static double _Yb =0; - private static double _RbErr = 1./Math.sqrt(12.); + private static double _RbErr = 0.3; // mm private static double _Zoffset = 0; @@ -108,10 +109,26 @@ public static double getRbErr() { return _RbErr; } - public static synchronized void setRbErr(double RbErr) { - _RbErr = RbErr; + public static void setRbErr(double value) { + _RbErr = value; + } + + public static int getBEAMSPOTCONST() { + return BEAMSPOTCONST; + } + + public static void setBEAMSPOTCONST(int BEAMSPOTCONST) { + Constants.BEAMSPOTCONST = BEAMSPOTCONST; } + public static boolean seedBeamSpotConstraint() { + return Constants.BEAMSPOTCONST>0; + } + + public static boolean kfBeamSpotConstraint() { + return Constants.BEAMSPOTCONST==2; + } + public static double getZoffset() { return _Zoffset; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 08d314b2f..2c3ab36bf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -625,7 +625,7 @@ public DataBank fillStraightTracksBank(DataEvent event, List cosm bank.setShort("ID", i, (short) cosmics.get(i).get_Id()); - bank.setFloat("chi2", i, (float) cosmics.get(i).get_ray().chi2); + bank.setFloat("chi2", i, (float) cosmics.get(i).get_chi2()); bank.setShort("ndf", i, (short) (cosmics.get(i).size()-2)); bank.setFloat("trkline_yx_slope", i, (float) cosmics.get(i).get_ray().get_yxslope()); bank.setFloat("trkline_yx_interc", i, (float) (cosmics.get(i).get_ray().get_yxinterc()/10.)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index c3460c5aa..54c4a55cc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -2,6 +2,7 @@ import javax.swing.JFrame; import java.util.ArrayList; +import java.util.List; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Cylindrical3D; @@ -14,6 +15,7 @@ import static org.jlab.rec.cvt.bmt.BMTConstants.E_DRIFT_MF; import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.geom.prim.Transformation3D; import org.jlab.groot.data.H1F; import org.jlab.groot.graphics.EmbeddedCanvasTabbed; @@ -911,10 +913,15 @@ public double getThetaLorentz(int layer, int sector, double x, double y, double * @param sector * @return */ + @Deprecated public double LorentzAngleCorr(int layer, int sector) { return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); } + public List getSurfaces() { + List surfaces = new ArrayList<>(); + return surfaces; + } /** * Executable method: implements checks @@ -1047,7 +1054,7 @@ public static void main (String arg[]) { if(BMTGeometry.getDetectorType(layer) == BMTType.Z) { // measure=newGeo.getZstripPhi(region, sector, seed); double residual=Math.atan2(trajs.get(0).y(),trajs.get(0).x())-measure; - if(Math.abs(residual)>2*Math.PI) residual-=Math.signum(residual)*2*Math.PI; + if(Math.abs(residual)>Math.PI) residual-=Math.signum(residual)*2*Math.PI; dgBMT.getH1F("hiz_res" + region).fill(residual); // System.out.println(newGeo.getCylinder(layer, sector).getAxis().distance(hit).length() + " " + newGeo.getRadius(layer)); dgBMT.getH2F("hiz_res_z" + region).fill(trajs.get(0).z(), residual); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 69177072a..439cacf3d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -93,12 +93,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) dbprovider.loadTable("/geometry/cvt/mvt/bmt_strip_L6"); //load material budget: - dbprovider.loadTable("/test/mvt/bmt_mat_l1"); - dbprovider.loadTable("/test/mvt/bmt_mat_l2"); - dbprovider.loadTable("/test/mvt/bmt_mat_l3"); - dbprovider.loadTable("/test/mvt/bmt_mat_l4"); - dbprovider.loadTable("/test/mvt/bmt_mat_l5"); - dbprovider.loadTable("/test/mvt/bmt_mat_l6"); + dbprovider.loadTable("/geometry/cvt/mvt/bmt_material"); //load Lorentz angle table dbprovider.loadTable("/calibration/mvt/lorentz"); @@ -225,19 +220,18 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) //material budget //=============== - for(int il=0; ilBMTConstants.MAXCLUSSIZE && i>BMTConstants.MAXCLUSSIZE-1) - continue; +// if(thehit.newClustering && nbhits>BMTConstants.MAXCLUSSIZE && i>BMTConstants.MAXCLUSSIZE-1) +// continue; // for the BMT the analysis distinguishes between C and Z type detectors if (this.get_Type()==BMTType.C) { // C-detectors @@ -588,7 +587,7 @@ public double residual(Point3D traj) { value = local.z()-this.get_CentroidValue(); else { value = local.toVector3D().phi()-this.get_CentroidValue(); - if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; } } return value; @@ -690,7 +689,7 @@ public Surface measurement(int layerID) { surface.hemisphere = Math.signum(this.center().y()); surface.setLayer(layerID); surface.setSector(this.get_Sector()); - surface.setError(this.get_Resolution()*this.get_Resolution()); + surface.setError(this.get_Resolution()); surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); surface.setZ_over_A_times_l(this.get(0).get_Strip().getZoverA()*this.get(0).get_Strip().getMatT()); surface.setThickness(this.get(0).get_Strip().getMatT()); @@ -700,7 +699,7 @@ public Surface measurement(int layerID) { org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), this.get_CentroidValue()); surface = new Surface(this.get(0).get_Strip().get_Tile(), strp, Constants.SWIMACCURACYBMT); double error = this.get_CentroidError(); - surface.setError(error*error); + surface.setError(error); } else { Point3D point = new Point3D(this.getLine().midpoint()); @@ -708,7 +707,7 @@ public Surface measurement(int layerID) { org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), point.x(), point.y(), this.get_CentroidValue()); surface = new Surface(this.getTile(), strp, Constants.SWIMACCURACYBMT); double error = this.get_CentroidError();///this.getTile().baseArc().radius(); - surface.setError(error*error); + surface.setError(error); } surface.setTransformation(this.toGlobal()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index a55445803..461240e7a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -265,7 +265,7 @@ public ArrayList> sortClusterByDetectorAndIO( } /** - * + * not used * @param crosses the crosses in the list * @return the crosses that have been flagged as being part of a looper * candidate in the SVT diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index faf9a9641..7d74be40c 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -286,7 +286,7 @@ void propagatePars(double xr, double yr, double x, double y, double cosphi, doub double Vp_phid = JVJT[1][2]; double Vp_dd = JVJT[2][2]; //3. Fill the covariance matrix - if(Constants.BEAMSPOTCONST==false) { + if(Constants.seedBeamSpotConstraint()==false) { _covr[0] = Vp_rhorho; _covr[1] = Vp_rhophi; _covr[2] = Vp_rhod; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java index c796b77ae..b36d757be 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Hit.java @@ -211,7 +211,7 @@ public double residual(Point3D traj) { value = local.z()-this.get_Strip().get_Z(); else { value = Math.atan2(local.y(),local.x())-this.get_Strip().get_Phi(); - if(Math.abs(value)>2*Math.PI) value-=Math.signum(value)*2*Math.PI; + if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; value = value*this.get_Strip().get_Tile().baseArc().radius(); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 53ae27c66..ee3449705 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -274,7 +274,7 @@ public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swi // get the strip number after correcting for Lorentz angle int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); this.set_LCStrip(theLorentzCorrectedStrip); - + // RDV use xyz dependent ThetaLorentz double sigma = BMTConstants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh //max phi err diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 0fc5a1b17..6b72c83ff 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -222,9 +222,14 @@ private void loadConfiguration() { } if (this.getEngineConfigString("beamSpotConst")!=null) { - Constants.BEAMSPOTCONST = Boolean.valueOf(this.getEngineConfigString("beamSpotConst")); + Constants.setBEAMSPOTCONST(Integer.valueOf(this.getEngineConfigString("beamSpotConst"))); } - System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.BEAMSPOTCONST); + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getBEAMSPOTCONST()+ " (0=no-constraint, 1=seed only, 2=sed aand KF"); + + if (this.getEngineConfigString("beamSpotRadius")!=null) { + Constants.setRbErr(Double.valueOf(this.getEngineConfigString("beamSpotRadius"))); + } + System.out.println("["+this.getName()+"] run with beam spot size set to "+Constants.getRbErr()); if (this.getEngineConfigString("kfFilterOn")!=null) { Constants.KFFILTERON = Boolean.valueOf(this.getEngineConfigString("kfFilterOn")); @@ -236,6 +241,11 @@ private void loadConfiguration() { } System.out.println("["+this.getName()+"] initialize KF from true MC information "+Constants.INITFROMMC); + if (this.getEngineConfigString("kfIterations")!=null) { + Constants.KFITERATIONS = Integer.valueOf(this.getEngineConfigString("kfIterations")); + } + System.out.println("["+this.getName()+"] number of KF iterations set to "+Constants.KFITERATIONS); + String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { Constants.isCosmicsData = Boolean.valueOf(svtCosmics); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index e5699f8bc..bc35e2855 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -102,7 +102,7 @@ public boolean processEvent(DataEvent event, List bmtCrosses = new ArrayList<>(); List bmtCrossesRm = new ArrayList<>(); - KFitter kf = null; + KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.kfMatLib); // uncomment to initiali KF with MC track parameters // double[] pars = recUtil.MCtrackPars(event); @@ -119,11 +119,10 @@ public boolean processEvent(DataEvent event, cov[2][2]=ray.get_yxslopeErr(); cov[3][3]=ray.get_yzslopeErr(); cov[4][4]=1; - kf = new KFitter( ray.get_yxinterc(),ray.get_yzinterc(), - ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, kf, - recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; -// kf.filterOn=false; - kf.runFitter(swimmer); + kf.init(ray.get_yxinterc(),ray.get_yzinterc(), + ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, + recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; + kf.runFitter(); Map traj = kf.TrjPoints; List keys = new ArrayList<>(); traj.forEach((key,value) -> keys.add(key)); @@ -133,8 +132,8 @@ public boolean processEvent(DataEvent event, Ray the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); cosmics.get(k1).set_ray(the_ray); cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray(), SVTGeom); - double chi2 = cosmics.get(k1).calc_straightTrkChi2(); - cosmics.get(k1).set_chi2(chi2); +// double chi2 = cosmics.get(k1).calc_straightTrkChi2(); + cosmics.get(k1).set_chi2(kf.chi2); // RDV why recalculating chi2 and not just used what given by the last KF iteration? TrajectoryFinder trjFind = new TrajectoryFinder(); @@ -188,11 +187,10 @@ public boolean processEvent(DataEvent event, } cosmics.get(k1).addAll(pseudoCrosses); //VZ check for additional clusters, and only then re-run KF adding new clusters //refit - kf = new KFitter( the_ray.get_yxinterc(),the_ray.get_yzinterc(), - the_ray.get_yxslope(), the_ray.get_yzslope(), 10.0, cov, kf, - recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; - // kf.filterOn=false; - kf.runFitter(swimmer); + kf.init(the_ray.get_yxinterc(),the_ray.get_yzinterc(), + the_ray.get_yxslope(), the_ray.get_yzslope(), 10.0, cov, + recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; + kf.runFitter(); Map traj2 = kf.TrjPoints; List keys2 = new ArrayList<>(); @@ -204,8 +202,8 @@ public boolean processEvent(DataEvent event, cosmics.get(k1).set_ray(the_ray); cosmics.get(k1).removeAll(pseudoCrosses); cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray(), SVTGeom); - chi2 = cosmics.get(k1).calc_straightTrkChi2(); - cosmics.get(k1).set_chi2(chi2); +// chi2 = cosmics.get(k1).calc_straightTrkChi2(); // RDV why recalculating chi2 and not just used what given by the last KF iteration? + cosmics.get(k1).set_chi2(kf.chi2); ntraj = trjFind.findTrajectory(k1+1, cosmics.get(k1).get_ray(), cosmics.get(k1), SVTGeom, BMTGeom); cosmics.get(k1).set_Trajectory(ntraj.get_Trajectory()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 5ee6f7f4f..0c3e2d30e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -88,16 +88,12 @@ public List setMeasVecs(Seed trkcand, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList<>(); Vector3D u = new Vector3D(0,0,1); - Point3D p = new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()); - Plane3D pln0 = new Plane3D(p, u); - Surface meas0 = new Surface(pln0, - new Point3D(p), - new Point3D(p.x()-300,p.y(),p.z()), - new Point3D(p.x()+300,p.y(),p.z()), - Constants.DEFAULTSWIMACC); + Point3D p = new Point3D(Constants.getXb(),Constants.getYb(),0); + Line3D l = new Line3D(p, u); + Surface meas0 = new Surface(l.origin(), l.end(), Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); - meas0.setError(1); + meas0.setError(Constants.getRbErr()); KFSites.add(meas0); // SVT measurements @@ -145,7 +141,7 @@ public List setMeasVecs(StraightTrack trkcand, new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); - meas0.setError(1); + meas0.setError(Constants.getRbErr()); meas0.hemisphere = 1; KFSites.add(meas0); Map clsMap = new HashMap<>(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 2e08eb809..e0db7f03b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -74,7 +74,7 @@ public boolean processEvent(DataEvent event, seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed, trseed2); } } - if(Constants.BEAMSPOTCONST==false) { + if(!Constants.seedBeamSpotConstraint()) { List failed = new ArrayList<>(); for(Seed s : seeds) { if(!recUtil.reFitCircle(s,SVTGeom, BMTGeom, Constants.SEEDFITITERATIONS)) @@ -105,7 +105,7 @@ public boolean processEvent(DataEvent event, // } trkcands.clear(); - KFitter kf = null; + KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.kfMatLib); for (Seed seed : seeds) { Point3D v = seed.get_Helix().getVertex(); Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); @@ -120,6 +120,7 @@ public boolean processEvent(DataEvent event, if(Constants.INITFROMMC) { v = new Point3D(pars[0],pars[1],pars[2]); p = new Vector3D(pars[3],pars[4],pars[5]); + if(solenoidValue<0.001) p.scale(100/p.mag()); } Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); @@ -128,16 +129,8 @@ public boolean processEvent(DataEvent event, if(solenoidValue>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0 && kf.KFHelix!=null) { Track fittedTrack = new Track(seed, kf); for(Cross c : fittedTrack) { @@ -176,15 +169,8 @@ public boolean processEvent(DataEvent event, hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - kf = new KFitter( hlx, cov, event, swimmer, - Constants.getXb(), - Constants.getYb(), - 0, - recUtil.setMeasVecs(seed, swimmer)) ; - kf.setMatrixLibrary(Constants.kfMatLib); - //Uncomment to let track be fitted - //kf.filterOn = false; - kf.runFitter(swimmer); + kf.init(hlx, cov, Constants.getXb(), Constants.getYb(), 0, recUtil.setMeasVecs(seed, swimmer)) ; + kf.runFitter(); // RDV get rid of added clusters if not true if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index 3042cc655..ce65fbc54 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -72,7 +72,7 @@ public static double getModuleLength() { } public static double getToverX0() { - return SVTConstants.SILICONTHK/SVTConstants.SILICONRADLEN; + return 2*SVTConstants.SILICONTHK/SVTConstants.SILICONRADLEN; } public static double getMaterialThickness() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 4b5f3782a..0473a0ae2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -42,6 +42,7 @@ public class Track extends Trajectory implements Comparable { private double _pathToCTOF; // the pathlength from the doca of the track to the z axis to the reference point described above private int _NDF; private double _Chi2; + private int kfIterations; private Map trajs = null; // map of trajectories indexed by layer, to be filled based on the KF results @@ -66,10 +67,11 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) super(new Helix(kf.KFHelix.getD0(), kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), kf.KFHelix.getTanL())); this.get_helix().B = kf.KFHelix.getB(); + this.kfIterations = kf.numIter; double c = Constants.LIGHTVEL; //convert from kf representation to helix repr double alpha = 1. / (c * Math.abs(kf.KFHelix.getB())); - double[][] kfCov = kf.finalCovMat; + double[][] kfCov = kf.finalStateVec.covMat; for(int i = 0; i<5; i++) { for(int j = 0; j<5; j++) { if(i==2) @@ -375,6 +377,10 @@ public double getChi2() { public final void setChi2(double _Chi2) { this._Chi2 = _Chi2; } + + public int getKfIterations() { + return kfIterations; + } public Map getTrajectories() { return trajs; @@ -404,7 +410,7 @@ public int getStatus() { nBMTC++; } } - return 1000+nSVT*100+nBMTZ*10+nBMTC; + return 1000*this.kfIterations+nSVT*100+nBMTZ*10+nBMTC; } private double[][] trackCovMat; From 130b96b544e0b4dda0479dea001235f7b09a456d Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 5 Jan 2022 19:59:21 +0100 Subject: [PATCH 259/291] Straight tracks from target: fixed definition of F matrix and reverted to set K[2]=0 to keep kappa constant, found numerical precision problem affecting derivative calculations, fixed by reverting some of the helical track calculations to the way it was before the last commit including keeping the pivot fixed for this fitting case --- .../tracking/kalmanfilter/AStateVecs.java | 4 +-- .../kalmanfilter/helical/KFitter.java | 6 ++--- .../kalmanfilter/helical/MeasVecs.java | 4 +++ .../kalmanfilter/helical/StateVecs.java | 26 ++++++++++++------- .../jlab/clas/tracking/trackrep/Helix.java | 10 +++---- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index d7b84114d..ef2da967e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -225,8 +225,8 @@ public void scaleCovMat(double scale) { } public void updateFromHelix() { - this.x = x0 + (this.d_rho + this.alpha / this.kappa) * Math.cos(this.phi0) - this.alpha / this.kappa * Math.cos(this.phi0 + this.phi); - this.y = y0 + (this.d_rho + this.alpha / this.kappa) * Math.sin(this.phi0) - this.alpha / this.kappa * Math.sin(this.phi0 + this.phi); + this.x = x0 + this.d_rho * Math.cos(this.phi0) + this.alpha / this.kappa * (Math.cos(this.phi0) - Math.cos(this.phi0 + this.phi)); + this.y = y0 + this.d_rho * Math.sin(this.phi0) + this.alpha / this.kappa * (Math.sin(this.phi0) - Math.sin(this.phi0 + this.phi)); this.z = z0 + this.dz - this.alpha / this.kappa * this.tanL * this.phi; this.px = -Math.sin(this.phi0 + this.phi) / Math.abs(this.kappa); this.py = Math.cos(this.phi0 + this.phi) / Math.abs(this.kappa); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 3845d7e04..046417803 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -117,9 +117,6 @@ public void filter(int k, AStateVecs sv, AMeasVecs mv) { double[] H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), this.getSwimmer()); // System.out.println(k + " " + mv.measurements.get(k).layer + " " + H[0] + " " + H[1] + " " + H[2] + " " + H[3] + " " + H[4] + " " +dh ); - if(sv.straight) { - sv.trackTraj.get(k).covMat[2][2]=0; - } double[][] CaInv = this.getMatrixOps().filterCovMat(H, sv.trackTraj.get(k).covMat, V); if (CaInv != null) { sv.trackTraj.get(k).covMat = CaInv; @@ -134,6 +131,9 @@ public void filter(int k, AStateVecs sv, AMeasVecs mv) { K[j] += H[i] * sv.trackTraj.get(k).covMat[j][i] / V; } } + if(sv.straight) { + K[2] = 0; + } StateVec fVec = sv.new StateVec(sv.trackTraj.get(k)); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java index 827be6761..977ffc483 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/MeasVecs.java @@ -67,6 +67,10 @@ public double[] H(AStateVecs.StateVec stateVec, AStateVecs sv, MeasVec mv, Swim SVplus.rollBack(rollBackAngle); SVminus.rollBack(rollBackAngle); } + else { + SVplus.toDoca(); + SVminus.toDoca(); + } sv.setStateVecPosAtMeasSite(SVplus, mv, null); sv.setStateVecPosAtMeasSite(SVminus, mv, null); // sv.printlnStateVec(SVplus); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 6ae9208c7..d29187fac 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -149,7 +149,7 @@ public boolean setStateVecPosAtMeasSite(StateVec sv, MeasVec mv, Swim swimmer) { } sv.k = mv.k; if(swimmer!=null && !this.straight) sv.alpha = new B(sv.k, sv.x, sv.y, sv.z, swimmer).alpha; - sv.pivotTransform(); + if(!this.straight) sv.pivotTransform(); //for straight tracks, keep the same pivot since F matrix is fixed anyway return true; } @@ -159,7 +159,7 @@ public double[][] F(StateVec iVec, StateVec fVec) { double[][] FMat = new double[][]{ {1, 0, 0, 0, 0}, {0, 1, 0, 0, 0}, - {0, 0, 0, 0, 0}, + {0, 0, 1, 0, 0}, {0, 0, 0, 1, 0}, {0, 0, 0, 0, 1} }; @@ -429,11 +429,22 @@ public void init(Helix helix, double[][] cov, double xref, double yref, double z this.yref = yref; this.zref = zref; - //init stateVec, pivot set to current vertex + if(Math.abs(helix.getB())<0.001) + this.straight = true; + // System.out.println(this.straight); + + //init stateVec, pivot set to current vertex for field-on and to the reference for straight tracks initSV = new StateVec(0); - initSV.x0 = helix.getX(); - initSV.y0 = helix.getY(); - initSV.z0 = helix.getZ(); + if(this.straight) { + initSV.x0 = xref; + initSV.y0 = yref; + initSV.z0 = zref; + } + else { + initSV.x0 = helix.getX(); + initSV.y0 = helix.getY(); + initSV.z0 = helix.getZ(); + } initSV.x = helix.getX(); initSV.y = helix.getY(); initSV.z = helix.getZ(); @@ -442,9 +453,6 @@ public void init(Helix helix, double[][] cov, double xref, double yref, double z initSV.pz = helix.getPz(); // this.printlnStateVec(initSV); - if(Math.abs(helix.getB())<0.001) - this.straight = true; -// System.out.println(this.straight); // set bfield according to input helix for consistency initSV.alpha = 1/(helix.getB()*helix.getLIGHTVEL()); // set kappa to define the charge diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 9da0009d9..48ee8e87a 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -58,7 +58,7 @@ public Helix(double d0, double phi0, double omega, double z0, double tanL, _yb = yb; this.units = unit; this.setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL/unit.unit); + setLIGHTVEL(LIGHTVEL*unit.unit); this.Update(); } @@ -69,8 +69,8 @@ public Helix(double x0, double y0, double z0, double px0, double py0, double pz0 double pt = Math.sqrt(px0*px0 + py0*py0); this.units = unit; setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL/unit.unit); - _R = pt/(B*LIGHTVEL/unit.unit); + setLIGHTVEL(LIGHTVEL*unit.unit); + _R = pt/(B*LIGHTVEL*unit.unit); _cosphi0 = px0/pt; _sinphi0 = py0/pt; _phi0 = Math.atan2(py0, px0); @@ -631,9 +631,9 @@ public void setLIGHTVEL(double aLIGHTVEL) { LightVel = aLIGHTVEL; } - public static final double LIGHTVEL = 0.00299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c + public static final double LIGHTVEL = 0.0000299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c - private static double LightVel = 0.00299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c + private static double LightVel = 0.0000299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c private static double unitScale = 1; @Override From 671f819d42846cbdafd3d2e86c53ef339eaf918b Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 6 Jan 2022 17:24:53 +0100 Subject: [PATCH 260/291] Bug fix: removed overwriting of beam spot error --- .../org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 1 - .../org/jlab/rec/cvt/services/CVTRecNewKF.java | 2 +- .../jlab/rec/cvt/trajectory/TrajectoryFinder.java | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index 439cacf3d..a8a542e95 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -301,7 +301,6 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) Constants.setXb(xb*10); Constants.setYb(yb*10); - Constants.setRbErr(err*10); // target position mm Constants.setZoffset(ztarget*10); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 6b72c83ff..013f8dde4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -224,7 +224,7 @@ private void loadConfiguration() { if (this.getEngineConfigString("beamSpotConst")!=null) { Constants.setBEAMSPOTCONST(Integer.valueOf(this.getEngineConfigString("beamSpotConst"))); } - System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getBEAMSPOTCONST()+ " (0=no-constraint, 1=seed only, 2=sed aand KF"); + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getBEAMSPOTCONST()+ " (0=no-constraint, 1=seed only, 2=seed and KF"); if (this.getEngineConfigString("beamSpotRadius")!=null) { Constants.setRbErr(Double.valueOf(this.getEngineConfigString("beamSpotRadius"))); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 3c58e8d98..6f7ad2bfc 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -361,7 +361,20 @@ private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); stVec.set_TrkToModuleAngle(trkToMPlnAngl); - + + if(layer<=2 && (sector==6 || sector==1)) { + Vector3D vv = svt_geo.toLocal(layer, sector, u); + System.out.println("\nTrack " + u.toString()); + System.out.println(vv.toString()); + vv.rotateX(-Math.PI/2); + vv.rotateY(Math.PI); + System.out.println(vv.toString()); + System.out.println(layer + " " + sector + " " + trkToMPlnAngl + " " + vv.phi() + " " + vv.theta()); + System.out.println(layer + " " + sector + " " + trkToMPlnAngl + " " + PhiTrackIntersPlane + " " + ThetaTrackIntersPlane); + System.out.println(n.toString()); + System.out.println(ui.toString()); + System.out.println(uj.toString()); + } } public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, From 7da4d0906ae7fcfd1e225c17207e1c5a7a9409f6 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 6 Jan 2022 18:05:11 +0100 Subject: [PATCH 261/291] Removed printout --- .../jlab/rec/cvt/trajectory/TrajectoryFinder.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 6f7ad2bfc..f67a9f03e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -362,19 +362,6 @@ private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); stVec.set_TrkToModuleAngle(trkToMPlnAngl); - if(layer<=2 && (sector==6 || sector==1)) { - Vector3D vv = svt_geo.toLocal(layer, sector, u); - System.out.println("\nTrack " + u.toString()); - System.out.println(vv.toString()); - vv.rotateX(-Math.PI/2); - vv.rotateY(Math.PI); - System.out.println(vv.toString()); - System.out.println(layer + " " + sector + " " + trkToMPlnAngl + " " + vv.phi() + " " + vv.theta()); - System.out.println(layer + " " + sector + " " + trkToMPlnAngl + " " + PhiTrackIntersPlane + " " + ThetaTrackIntersPlane); - System.out.println(n.toString()); - System.out.println(ui.toString()); - System.out.println(uj.toString()); - } } public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, From 01f0651e9283eeea30c66a8bca5426326ee4e036 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 8 Jan 2022 00:56:14 +0100 Subject: [PATCH 262/291] Update local angle calculations for BMT and SVT --- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 52 +++++++++++++++++++ .../org/jlab/rec/cvt/svt/SVTGeometry.java | 42 +++++++++++++++ .../rec/cvt/trajectory/TrajectoryFinder.java | 39 ++++++++++---- 3 files changed, 122 insertions(+), 11 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 54c4a55cc..9c75f361a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -918,6 +918,58 @@ public double LorentzAngleCorr(int layer, int sector) { return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); } + /** + * Return track vector for local angle calculations + * + * 1) transform to the geometry service local frame first, + * 2) rotates to bring the track intersection at phi=0. + * + * The y and x components determine the local angle for Z strips + * The x and z components determine the local angle for C strips + * @param layer + * @param sector + * @param trackPos + * @param trackDir + * @return track direction unit vector + **/ + private Vector3D getLocalTrack(int layer, int sector, Point3D trackPos, Vector3D trackDir) { + Vector3D dir = new Vector3D(trackDir).asUnit(); + Point3D pos = new Point3D(trackPos); + this.toLocal(layer, sector).apply(dir); + this.toLocal(layer, sector).apply(pos); + Vector3D n = pos.toVector3D().asUnit(); + dir.rotateZ(-n.phi()); + return dir; + } + + /** + * Returns the local angle of the track for Z detectors + * the angle is positive for tracks going toward positive phi + * @param layer + * @param sector + * @param trakPos + * @param trackDir + * @return local angle + */ + public double getThetaZ(int layer, int sector, Point3D trakPos, Vector3D trackDir) { + Vector3D dir = this.getLocalTrack(layer, sector, trakPos, trackDir); + return Math.atan(dir.y()/dir.x()); + } + + /** + * Returns the local angle of the track for C detectors + * the angle is positive for tracks going at positive z + * @param layer + * @param sector + * @param trakPos + * @param trackDir + * @return local angle + */ + public double getThetaC(int layer, int sector, Point3D trakPos, Vector3D trackDir) { + Vector3D dir = this.getLocalTrack(layer, sector, trakPos, trackDir); + return Math.atan(dir.z()/dir.x()); + } + public List getSurfaces() { List surfaces = new ArrayList<>(); return surfaces; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index ce65fbc54..ff3ce859d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -166,6 +166,48 @@ public double getResidual(int layer, int sector, int strip, Point3D traj) { return dist.length()*side; } + /** + * Return track vector for local angle calculations + * + * 1) transform to the geometry service local frame first: + * y axis pointing toward the center, + * z axis pointing downstream along the module + * x axis given by y.cross(z) + * + * 2) for even layers, it rotates by 180 deg to have the y axis + * pointing outward + * + * 3) rotates by 90 deg around X to have: + * z axis normal to the module pointing inward for odd layers and outward for even ones + * y axis pointing upstream along the module + * x axis given by y.cross(z) along the short side of the module + * + * @param layer + * @param sector + * @param trackDir + * @return + **/ + public Vector3D getLocalTrack(int layer, int sector, Vector3D trackDir) { + Vector3D dir = this.toLocal(layer, sector, trackDir); + if(layer%2==0) dir.rotateZ(Math.PI); // to get the Y axis to point + dir.rotateX(Math.PI/2); + return dir; + } + + /** + * Returns angle of the track with respect to the normal to the module + * in the x-z plane defined above + * + * @param layer + * @param sector + * @param trackDir + * @return + */ + public double getLocalAngle(int layer, int sector, Vector3D trackDir) { + Vector3D dir = this.getLocalTrack(layer, sector, trackDir); + return Math.atan(dir.x()/dir.z()); + } + @Deprecated public int getSector(int layer, Point3D traj) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index f67a9f03e..ff2045f13 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -155,7 +155,11 @@ public Trajectory findTrajectory(Track trk, stVec.set_SurfaceLayer(layer); stVec.set_SurfaceSector(sector); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); - this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); +// this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); + Vector3D localDir = svt_geo.getLocalTrack(layer, sector, dir); + stVec.set_TrkPhiAtSurface(dir.phi()); + stVec.set_TrkThetaAtSurface(dir.theta()); + stVec.set_TrkToModuleAngle(svt_geo.getLocalAngle(layer, sector, dir)); stVec.set_CalcCentroidStrip(svt_geo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); stVec.set_Path(path*10); stVec.set_ID(trk.get_Id()); @@ -232,7 +236,9 @@ public Trajectory findTrajectory(Track trk, stVec.set_ID(trk.get_Id()); stVec.set_Path(path*10); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); - this.fill_HelicalTrkAngleWRTBMTTangentPlane(dir, stVec); + Point3D pos = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); + stVec.set_TrkPhiAtSurface(bmt_geo.getThetaZ(layer, sector, pos, dir)); + stVec.set_TrkThetaAtSurface(bmt_geo.getThetaC(layer, sector, pos, dir)); //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(region, new Point3D(stVec.x(),stVec.y(),stVec.z()))); @@ -336,7 +342,7 @@ private void fill_HelicalTrkAngleWRTBMTTangentPlane(Vector3D trkDir, StateVec st if (stVec.z()<0){ thetaC=-thetaC; //Negative thetaC if track is going to negative z } - + //Fill State Vector stVec.set_TrkPhiAtSurface(thetaZ); //Call "phi" the normal angle for Z detectors stVec.set_TrkThetaAtSurface(thetaC); //Call "theta" the normal angle for C detectors @@ -344,16 +350,17 @@ private void fill_HelicalTrkAngleWRTBMTTangentPlane(Vector3D trkDir, StateVec st private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, Vector3D trkDir, SVTGeometry svt_geo, StateVec stVec) { - Vector3D n = svt_geo.getNormal(layer,sector); - Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module - Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module + Vector3D uz = svt_geo.getNormal(layer,sector); + if(layer%2==1) uz.negative(); + Vector3D ux = new Vector3D(uz.y(), -uz.x(), 0); // longitudinal vector along the local x direction of the module + Vector3D uy = uz.cross(ux); //longitudinal vector along the local z direction of the module Vector3D u = new Vector3D(trkDir.x(), trkDir.y(), trkDir.z()); - double trkToMPlnAngl = Math.acos(u.dot(ui)); + double trkToMPlnAngl = Math.acos(trkDir.dot(ux)); - double zl = u.dot(n); - double xl = u.dot(ui); - double yl = u.dot(uj); + double zl = u.dot(uz); + double xl = u.dot(ux); + double yl = u.dot(uy); double PhiTrackIntersPlane = Math.atan2(yl, xl); double ThetaTrackIntersPlane = Math.acos(zl); @@ -361,7 +368,17 @@ private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); stVec.set_TrkToModuleAngle(trkToMPlnAngl); - +//// if(layer<=2 && (sector==1 || sector ==6)) { +// System.out.println("\n" + layer + " " + sector); +// System.out.println(ux.toString()); +// System.out.println(uy.toString()); +// System.out.println(uz.toString()); +// System.out.println(trkToMPlnAngl + " " + PhiTrackIntersPlane + " " + ThetaTrackIntersPlane); +// Vector3D dir = svt_geo.getLocalTrack(layer, sector, trkDir); +// System.out.println(trkDir.toString()); +// System.out.println(dir.toString()); +// System.out.println(svt_geo.getLocalAngle(layer, sector, trkDir) + " " + dir.phi() + " " + dir.theta()); +//// } } public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList, From 73dfb397f6442f56667e8eaa794436259b92df76 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 9 Jan 2022 01:58:24 +0100 Subject: [PATCH 263/291] CVT cosmic reconstruction - KF: - found and fixed issue with the calculation of the matrix H - fixed problem with filtered state vector not being saved for the next step - corrected formulas in the filtering method - CosmicTracksRec: - initialization of covariance matrix and deltaA array for KF - cleaned-up calculations of residuals and trajectories - fixed bug in filling of measurement array that was causing SVT clusters being missed if two consecutive clusters had the same layer even if in different hemispheres; this was responsible of the spike at 0 in the SVT residuals since these clusters had trackId>0 but 0 residual --- .../clas/tracking/kalmanfilter/AKFitter.java | 1 + .../clas/tracking/kalmanfilter/AMeasVecs.java | 4 + .../tracking/kalmanfilter/AStateVecs.java | 18 ++ .../kalmanfilter/helical/KFitter.java | 3 +- .../kalmanfilter/straight/KFitter.java | 107 ++++---- .../kalmanfilter/straight/MeasVecs.java | 7 +- .../kalmanfilter/straight/StateVecs.java | 46 +--- .../rec/cvt/services/CosmicTracksRec.java | 238 +++++++----------- .../jlab/rec/cvt/services/RecUtilities.java | 10 +- .../org/jlab/rec/cvt/track/StraightTrack.java | 190 +++++++++----- .../rec/cvt/track/TrackCandListFinder.java | 14 +- .../java/org/jlab/rec/cvt/trajectory/Ray.java | 10 + .../rec/cvt/trajectory/TrajectoryFinder.java | 4 +- 13 files changed, 330 insertions(+), 322 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index ec7d46efc..07e30bd29 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -120,6 +120,7 @@ public double calc_chi2(AStateVecs sv, AMeasVecs mv) { ndf++; } } + if(chisq==0) chisq=Double.POSITIVE_INFINITY; return chisq; } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java index 8ae7cdcb6..aa944a966 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -230,6 +230,10 @@ public double[] getDelta_d_a() { return delta_d_a; } + public void setDelta_d_a(double[] values) { + delta_d_a = values; + } + /** * @return the Hval */ diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index ef2da967e..e28a56c89 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -315,6 +315,24 @@ public void toOldHelix(Helix helix) { helix.setD0(-vec.d_rho); helix.Update(); } + + public void updateRay() { + this.dl = this.y/this.py; + this.x0 = this.x -this.dl*this.px; + this.y0 = this.y -this.dl*this.py; + this.z0 = this.z -this.dl*this.pz; + this.tx = this.px/this.py; + this.tz = this.pz/this.py; + } + + public void updateFromRay() { + this.py = 1/Math.sqrt(1+tx*tx+tz*tz); + this.px = tx*py; + this.pz = tz*py; + this.x = this.x0 + this.dl*this.px; + this.y = this.y0 + this.dl*this.py; + this.z = this.z0 + this.dl*this.pz; + } public double[] get_ELoss() { return _ELoss; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 046417803..0287c63bb 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -57,12 +57,11 @@ public void runFitter() { public void runFitter(AStateVecs sv, AMeasVecs mv) { StateVecs.StateVec finalSVonPivot = null; - double newchisq = Double.POSITIVE_INFINITY; for (int it = 0; it < totNumIter; it++) { this.runFitterIter(sv, mv); // chi2 - newchisq = this.calc_chi2(sv, mv); + double newchisq = this.calc_chi2(sv, mv); // if curvature is 0, fit failed if(Double.isNaN(newchisq) || sv.trackTraj.get(0)==null || diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index 79509181e..7792422fe 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -16,11 +16,6 @@ */ public class KFitter extends AKFitter { - public double yx_slope; - public double yz_slope; - public double yx_interc; - public double yz_interc; - private final double resiCut = 100;//residual cut for the measurements public Map TrjPoints = new HashMap<>(); public final StateVecs sv = new StateVecs(); public final MeasVecs mv = new MeasVecs(); @@ -36,7 +31,7 @@ public void runFitter() { public void init(double x0, double z0,double tx,double tz, double units, double[][] cov, List measSurfaces) { finalStateVec = null; - this.NDF0 = -45; + this.NDF0 = -4; this.NDF = -4; this.chi2 = Double.POSITIVE_INFINITY; this.numIter = 0; @@ -51,7 +46,6 @@ public void init(double x0, double z0,double tx,double tz, double units, double[ } } sv.init(x0, z0, tx, tz, units, cov); - //double x0, double z0,double tx,double tz, double units, Matrix cov, KFitter kf } @Override @@ -62,21 +56,12 @@ public void runFitter(AStateVecs sv, AMeasVecs mv) { // chi2 double newchisq = this.calc_chi2(sv, mv); // if curvature is 0, fit failed - if(sv.trackTraj.get(1)==null) { + if(sv.trackTraj.get(0)==null) { this.setFitFailed = true; break; } else if(newchisq < this.chi2) { this.chi2 = newchisq; - finalStateVec = sv.trackTraj.get(1); - finalStateVec.x = finalStateVec.x0; - finalStateVec.z = finalStateVec.z0; - - yx_slope = finalStateVec.tx; - yz_slope = finalStateVec.tz; - yx_interc = finalStateVec.x0; - yz_interc = finalStateVec.z0; - this.setTrajectory(sv, mv); setFitFailed = false; } @@ -85,6 +70,9 @@ else if(newchisq < this.chi2) { break; } } + if(!this.setFitFailed) { + finalStateVec = sv.new StateVec(sv.trackTraj.get(0)); + } } @Override @@ -92,20 +80,16 @@ public void setTrajectory(AStateVecs sv, AMeasVecs mv) { TrjPoints = new HashMap<>(); for (int k = 0; k < sv.trackTraj.size()-1; k++) { StateVec stv = sv.trackTraj.get(k+1); - double resi = mv.dh(k+1, stv); - int layer = mv.measurements.get(k+1).layer; - double x = stv.x; - double y = stv.y; - double z = stv.z; - double tx = stv.tx; - double tz = stv.tz; - double py = 1/Math.sqrt(1+tx*tx+tz*tz); - double px = tx*py; - double pz = tz*py; - //double resi = stv.resi; - TrjPoints.put(layer, new HitOnTrack(layer, x, y, z, px, py, pz,resi)); - //System.out.println("interc "+new Point3D(stv.x0,0,stv.z0).toString()+" P "+new Point3D(px,py,pz).toString()); - //System.out.println("...reso "+resi+" dl "+stv.dl+" Traj layer "+layer+" x "+TrjPoints.get(layer).x+" y "+TrjPoints.get(layer).y+" z "+TrjPoints.get(layer).z); + stv.resi = mv.dh(k+1, stv); + if(Double.isNaN(stv.resi)) { + mv.measurements.get(k+1).skip = true; + } + else { + int layer = mv.measurements.get(k+1).layer; + TrjPoints.put(layer, new HitOnTrack(layer, stv.x, stv.y, stv.z, stv.px, stv.py, stv.pz, stv.resi)); + if(mv.measurements.get(k).skip) + TrjPoints.get(layer).isMeasUsed = false; + } } } @@ -119,6 +103,7 @@ public void filter(int k, AStateVecs sv, AMeasVecs mv) { //get the projector Matrix double[] H = new double[5]; H = mv.H(sv.trackTraj.get(k), sv, mv.measurements.get(k), null); +// System.out.println(k + " " + mv.measurements.get(k).layer + " " + mv.measurements.get(k).surface.type.name() + " " + H[0] + " " + H[1] + " " + H[2] + " " + H[3]); double[][] CaInv = this.getMatrixOps().filterCovMat(H, sv.trackTraj.get(k).covMat, V); if (CaInv != null) { @@ -126,37 +111,41 @@ public void filter(int k, AStateVecs sv, AMeasVecs mv) { } else { return; } + // the gain matrix for (int j = 0; j < 4; j++) { - // the gain matrix - K[j] = 0; - if(filterOn) { - for (int i = 0; i < 4; i++) { - K[j] += H[i] * sv.trackTraj.get(k).covMat[j][i] / V; - } - } - } - double x0_filt = sv.trackTraj.get(k).x0; - double z0_filt = sv.trackTraj.get(k).z0; - double tx_filt = sv.trackTraj.get(k).tx; - double tz_filt = sv.trackTraj.get(k).tz; + K[j] = 0; + for (int i = 0; i < 4; i++) { + K[j] += H[i] * sv.trackTraj.get(k).covMat[j][i] / V; + } + } +// for (int j = 0; j < 5; j++) { +// for (int i = 0; i < 5; i++) { +// System.out.print(CaInv[j][i] + " "); +// } +// System.out.println(); +// } +// System.out.println(k + " " + mv.measurements.get(k).layer + " " + mv.measurements.get(k).surface.type.name() + " " + V); +// System.out.println("\t" + H[0] + " " + H[1] + " " + H[2] + " " + H[3]); +// System.out.println("\t" + sv.trackTraj.get(k).covMat[0][0] + " " + sv.trackTraj.get(k).covMat[1][1] + " " + sv.trackTraj.get(k).covMat[2][2] + " " + sv.trackTraj.get(k).covMat[3][3]); +// System.out.println("\t" + K[0] + " " + K[1] + " " + K[2] + " " + K[3]); - double dh =0; - for(int i = 1; i cosmics = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); + List cosmicCands = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); List trkcands = new ArrayList<>(); //REMOVE THIS //crosses.get(0).addAll(crosses.get(1)); //------------------------ - if (cosmics.isEmpty()) { + if (cosmicCands.isEmpty()) { recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); return true; @@ -69,175 +67,113 @@ public boolean processEvent(DataEvent event, if(Constants.excludeLayers==true) { CosmicFitter fitTrk = new CosmicFitter(); - cosmics = recUtil.reFit(cosmics, SVTGeom, fitTrk, trkcandFinder); + cosmicCands = recUtil.reFit(cosmicCands, SVTGeom, fitTrk, trkcandFinder); } - if (cosmics.size() > 0) { - for (int k1 = 0; k1 < cosmics.size(); k1++) { - cosmics.get(k1).set_Id(k1 + 1); - for (int k2 = 0; k2 < cosmics.get(k1).size(); k2++) { - cosmics.get(k1).get(k2).set_AssociatedTrackID(cosmics.get(k1).get_Id()); // associate crosses - if (cosmics.get(k1).get(k2).get_Cluster1() != null) { - cosmics.get(k1).get(k2).get_Cluster1().set_AssociatedTrackID(cosmics.get(k1).get_Id()); // associate cluster1 in cross + if (cosmicCands.size() > 0) { + for (int k1 = 0; k1 < cosmicCands.size(); k1++) { + cosmicCands.get(k1).set_Id(k1 + 1); + for (int k2 = 0; k2 < cosmicCands.get(k1).size(); k2++) { + cosmicCands.get(k1).get(k2).set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate crosses + if (cosmicCands.get(k1).get(k2).get_Cluster1() != null) { + cosmicCands.get(k1).get(k2).get_Cluster1().set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate cluster1 in cross } - if (cosmics.get(k1).get(k2).get_Cluster2() != null) { - cosmics.get(k1).get(k2).get_Cluster2().set_AssociatedTrackID(cosmics.get(k1).get_Id()); // associate cluster2 in cross - } - if (cosmics.get(k1).get(k2).get_Cluster1() != null) { - for (int k3 = 0; k3 < cosmics.get(k1).get(k2).get_Cluster1().size(); k3++) { //associate hits - cosmics.get(k1).get(k2).get_Cluster1().get(k3).set_AssociatedTrackID(cosmics.get(k1).get_Id()); - } - } - if (cosmics.get(k1).get(k2).get_Cluster2() != null) { - for (int k4 = 0; k4 < cosmics.get(k1).get(k2).get_Cluster2().size(); k4++) { //associate hits - cosmics.get(k1).get(k2).get_Cluster2().get(k4).set_AssociatedTrackID(cosmics.get(k1).get_Id()); - } + if (cosmicCands.get(k1).get(k2).get_Cluster2() != null) { + cosmicCands.get(k1).get(k2).get_Cluster2().set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate cluster2 in cross } } trkcandFinder.matchClusters(SVTclusters, new TrajectoryFinder(), SVTGeom, BMTGeom, true, - cosmics.get(k1).get_Trajectory(), k1 + 1); + cosmicCands.get(k1).get_Trajectory(), k1 + 1); } recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; - //4) --- write out the banks - List bmtCrosses = new ArrayList<>(); - List bmtCrossesRm = new ArrayList<>(); KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.kfMatLib); - // uncomment to initiali KF with MC track parameters -// double[] pars = recUtil.MCtrackPars(event); -// Point3D v = new Point3D(pars[0],pars[1],pars[2]); -// Vector3D p = new Vector3D(pars[3],pars[4],pars[5]); - for (int k1 = 0; k1 < cosmics.size(); k1++) { - Ray ray = cosmics.get(k1).get_ray(); -// ray = new Ray(v,p); - - double[][] cov = new double[5][5]; + List cosmics = new ArrayList<>(); + for (int k1 = 0; k1 < cosmicCands.size(); k1++) { + Ray ray = cosmicCands.get(k1).get_ray(); - cov[0][0]=ray.get_yxintercErr(); - cov[1][1]=ray.get_yzintercErr(); - cov[2][2]=ray.get_yxslopeErr(); - cov[3][3]=ray.get_yzslopeErr(); + if(Constants.INITFROMMC) { + double[] pars = recUtil.MCtrackPars(event); + Point3D v = new Point3D(pars[0],pars[1],pars[2]); + Vector3D p = new Vector3D(pars[3],pars[4],pars[5]); + ray = new Ray(v,p); + } + + double[][] cov = new double[5][5]; + cov[0][0]=1; + cov[1][1]=1; + cov[2][2]=0.001; // ~2deg + cov[3][3]=0.001; cov[4][4]=1; kf.init(ray.get_yxinterc(),ray.get_yzinterc(), ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; + recUtil.setMeasVecs(cosmicCands.get(k1), SVTGeom, BMTGeom, swimmer)); + kf.mv.setDelta_d_a(new double[]{0.1, 0.1, 0.0001, 0.0001, 1}); kf.runFitter(); - Map traj = kf.TrjPoints; - List keys = new ArrayList<>(); - traj.forEach((key,value) -> keys.add(key)); - List trkTraj = new ArrayList<>(); - traj.forEach((key,value) -> trkTraj.add(value)); - - Ray the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); - cosmics.get(k1).set_ray(the_ray); - cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray(), SVTGeom); -// double chi2 = cosmics.get(k1).calc_straightTrkChi2(); - cosmics.get(k1).set_chi2(kf.chi2); // RDV why recalculating chi2 and not just used what given by the last KF iteration? - - TrajectoryFinder trjFind = new TrajectoryFinder(); - - Trajectory ntraj = trjFind.findTrajectory(k1+1, cosmics.get(k1).get_ray(), cosmics.get(k1), SVTGeom, BMTGeom); - cosmics.get(k1).set_Trajectory(ntraj.get_Trajectory()); - trkcandFinder.upDateCrossesFromTraj(cosmics.get(k1), ntraj, SVTGeom); - - - for(int i = 0; i< keys.size(); i++) { - double resi = trkTraj.get(i).resi; - Point3D tj = new Point3D(trkTraj.get(i).x,trkTraj.get(i).y,trkTraj.get(i).z); - Cluster cl = cosmics.get(k1).clsMap.get(keys.get(i)); - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); + if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { + StraightTrack cosmic = cosmicCands.get(k1); + cosmic.update(kf, SVTGeom, BMTGeom); - cosmics.get(k1).clsMap.get(keys.get(i)).setTrakInters(tj); - cl.set_CentroidResidual(resi); - if (cl.get_Detector()==DetectorType.BST) { - cl.update(k1 + 1, trkTraj.get(i), SVTGeom); - } - if (cl.get_Detector()==DetectorType.BMT) { - - if (cl.get_Type()==BMTType.Z) { //Z-detector measuring phi - Line3D cln = BMTGeom.getAxis(layer, sector); - double r = BMTGeom.getRadiusMidDrift(layer); - cl.set_CentroidResidual(resi*r); - cl.setN(cln.distance(ray.get_refPoint()).direction().asUnit()); - cl.setS(cl.getL().cross(cl.getN()).asUnit()); - - } - } - } - //refit adding missing clusters - List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmics.get(k1), SVTGeom); - if(clsOnTrack.size()>0) { - List pseudoCrosses = new ArrayList<>(); - for(Cluster cl : clsOnTrack) { - cl.set_AssociatedTrackID(k1 + 1); - //make pseudo-cross - Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, cl.get_Sector(), cl.get_Region(), -1); - // cluster1 is the inner layer cluster - if(cl.get_Layer()%2==1) { - this_cross.set_Cluster1(cl); - } else { - // cluster2 is the outer layer cluster - this_cross.set_Cluster2(cl); - } - this_cross.set_Point0(cl.getTrakInters()); - this_cross.set_Point(cl.getTrakInters()); - pseudoCrosses.add(this_cross); - } - cosmics.get(k1).addAll(pseudoCrosses); //VZ check for additional clusters, and only then re-run KF adding new clusters - //refit - kf.init(the_ray.get_yxinterc(),the_ray.get_yzinterc(), - the_ray.get_yxslope(), the_ray.get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmics.get(k1), SVTGeom, BMTGeom, swimmer )) ; - kf.runFitter(); - - Map traj2 = kf.TrjPoints; - List keys2 = new ArrayList<>(); - traj2.forEach((key,value) -> keys2.add(key)); - List trkTraj2 = new ArrayList<>(); - traj2.forEach((key,value) -> trkTraj2.add(value)); - - the_ray = new Ray(kf.yx_slope, kf.yx_interc, kf.yz_slope, kf.yz_interc); - cosmics.get(k1).set_ray(the_ray); - cosmics.get(k1).removeAll(pseudoCrosses); - cosmics.get(k1).update_Crosses(cosmics.get(k1).get_ray(), SVTGeom); -// chi2 = cosmics.get(k1).calc_straightTrkChi2(); // RDV why recalculating chi2 and not just used what given by the last KF iteration? - cosmics.get(k1).set_chi2(kf.chi2); - - ntraj = trjFind.findTrajectory(k1+1, cosmics.get(k1).get_ray(), cosmics.get(k1), SVTGeom, BMTGeom); - cosmics.get(k1).set_Trajectory(ntraj.get_Trajectory()); - trkcandFinder.upDateCrossesFromTraj(cosmics.get(k1), ntraj, SVTGeom); - - for(int i = 0; i< keys2.size(); i++) { - double resi = trkTraj2.get(i).resi; - Point3D tj = new Point3D(trkTraj2.get(i).x,trkTraj2.get(i).y,trkTraj2.get(i).z); - Cluster cl = cosmics.get(k1).clsMap.get(keys2.get(i)); - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); - - cosmics.get(k1).clsMap.get(keys2.get(i)).setTrakInters(tj); - cl.set_CentroidResidual(resi); - if (cl.get_Detector()==DetectorType.BST) { - cl.update(k1 + 1, trkTraj2.get(i), SVTGeom); - } - if (cl.get_Detector()==DetectorType.BMT) { - - if (cl.get_Type()==BMTType.Z) { //Z-detector measuring phi - Line3D cln = BMTGeom.getAxis(layer, sector); - double r = BMTGeom.getRadiusMidDrift(layer); - cl.set_CentroidResidual(resi*r); - cl.setN(cln.distance(ray.get_refPoint()).direction().asUnit()); - cl.setS(cl.getL().cross(cl.getN()).asUnit()); - + //refit adding missing clusters + List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmic, SVTGeom); + if(clsOnTrack.size()>0) { + List pseudoCrosses = new ArrayList<>(); + for(Cluster cl : clsOnTrack) { + cl.set_AssociatedTrackID(k1 + 1); + //make pseudo-cross + Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, cl.get_Sector(), cl.get_Region(), -1); + // cluster1 is the inner layer cluster + if(cl.get_Layer()%2==1) { + this_cross.set_Cluster1(cl); + } else { + // cluster2 is the outer layer cluster + this_cross.set_Cluster2(cl); } + this_cross.set_Point0(cl.getTrakInters()); + this_cross.set_Point(cl.getTrakInters()); + pseudoCrosses.add(this_cross); + } + cosmic.addAll(pseudoCrosses); //VZ check for additional clusters, and only then re-run KF adding new clusters + //refit + kf.init(cosmic.get_ray().get_yxinterc(),cosmic.get_ray().get_yzinterc(), + cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), 10.0, cov, + recUtil.setMeasVecs(cosmic, SVTGeom, BMTGeom, swimmer)) ; + kf.runFitter(); + if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { + cosmic.update(kf, SVTGeom, BMTGeom); } } - + cosmics.add(cosmic); } - } + // reset cross and cluster IDs + for(int det = 0; det<2; det++) { + for(Cross c : crosses.get(det)) { + c.set_AssociatedTrackID(-1); + } + } + for(Cluster c : SVTclusters) { + c.set_AssociatedTrackID(-1); + } + for(Cluster c : BMTclusters) { + c.set_AssociatedTrackID(-1); + } + if(!cosmics.isEmpty()) { + for(int k = 0; k < cosmics.size(); k++) { + cosmics.get(k).set_Id(k + 1); + cosmics.get(k).updateCrosses(SVTGeom); + cosmics.get(k).updateClusters(SVTGeom); + } + } + for(int det = 0; det<2; det++) { + for(Cross c : crosses.get(det)) { + if(c.get_AssociatedTrackID()==-1) { + c.reset(SVTGeom); + } + } + } rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, cosmics); } return true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 0c3e2d30e..9514d5bbb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -141,9 +141,10 @@ public List setMeasVecs(StraightTrack trkcand, new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); meas0.setSector(0); meas0.setLayer(0); - meas0.setError(Constants.getRbErr()); + meas0.setError(1); meas0.hemisphere = 1; KFSites.add(meas0); + Map clsMap = new HashMap<>(); trkcand.sort(Comparator.comparing(Cross::getY).reversed()); for (int i = 0; i < trkcand.size(); i++) { //SVT @@ -175,13 +176,15 @@ public List setMeasVecs(StraightTrack trkcand, for (int j = 0; j < cls.size(); j++) { int mlayer = cls.get(j).get_Layer(); Surface meas = cls.get(j).measurement(mlayer); + meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; // set SVT material budget according to track direction if(j==0) meas.setl_over_X0(SVTGeometry.getToverX0()); else meas.setl_over_X0(0); // RDV to be tested // if((int) Constants.getLayersUsed().get(meas.getLayer())<1) // meas.notUsedInFit=true; //VZ: commenting this out prevents the layer exclusion to be employed in tracking - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer() + && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) continue; KFSites.add(meas); @@ -202,7 +205,8 @@ public List setMeasVecs(StraightTrack trkcand, if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { meas.notUsedInFit=true; } - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer() + && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) continue; KFSites.add(meas); clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index 4b8e8b02a..bf3891771 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -1,59 +1,60 @@ package org.jlab.rec.cvt.track; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; +import org.jlab.clas.tracking.kalmanfilter.AKFitter.HitOnTrack; +import org.jlab.clas.tracking.kalmanfilter.straight.KFitter; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.bmt.BMTConstants; +import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Ray; +import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; +import org.jlab.rec.cvt.trajectory.TrajectoryFinder; public class StraightTrack extends Trajectory{ + private double _ndf; + private double _chi2; + public Map clsMap; + public Map trajs = null; + public StraightTrack(Ray ray) { super(ray); } - /** - * - */ - private static final long serialVersionUID = 1L; - - private double _ndf; - private double _chi2; - public Map clsMap; - /** - * updates the crosses in the track position based on the track straight - * line fit parameters - * - * @param fit_yxslope - * @param fit_yzslope - * @param geo - */ - @Deprecated - public void update_Crosses(double fit_yxslope, double fit_yzslope, SVTGeometry geo) { - for (Cross c : this) { - if (c.get_Detector()==DetectorType.BST) //only update for the svt - { - update_Cross(c, fit_yxslope, fit_yzslope, geo); - } - - } + public void update(KFitter kf, SVTGeometry svt, BMTGeometry bmt) { + Ray the_ray = new Ray(kf.finalStateVec.tx, kf.finalStateVec.x0, kf.finalStateVec.tz, kf.finalStateVec.z0); + this.set_ray(the_ray); + this.set_chi2(kf.chi2); + this.trajs = kf.TrjPoints; + this.updateCrosses(svt); + this.updateClusters(svt); + this.findTrajectory(svt, bmt); + } + + + public void updateCrosses(Ray ray, SVTGeometry geo) { + this.set_ray(ray); + this.updateCrosses(geo); } - public void update_Crosses(Ray ray, SVTGeometry geo) { + public void updateCrosses(SVTGeometry geo) { for (Cross c : this) { + c.set_AssociatedTrackID(this.get_Id()); if(c.get_Detector()==DetectorType.BST) - c.updateSVTCross(ray.get_dirVec(), geo); + c.updateSVTCross(this.get_ray().get_dirVec(), geo); else { Cluster cluster = c.get_Cluster1(); List trajs = new ArrayList<>(); - int nTraj = cluster.getTile().intersection(ray.toLine(), trajs); + int nTraj = cluster.getTile().intersection(this.get_ray().toLine(), trajs); if(nTraj>0) { Point3D traj = null; double doca = Double.MAX_VALUE; @@ -64,45 +65,16 @@ public void update_Crosses(Ray ray, SVTGeometry geo) { traj = t; } } - c.updateBMTCross(traj, ray.get_dirVec()); + c.updateBMTCross(traj, this.get_ray().get_dirVec()); } } } } - @Deprecated - public void reset_Crosses() { - for (Cross c : this) { - if (c.get_Detector()==DetectorType.BST) //only update for the svt - { - c.set_Point(c.get_Point0()); - } - - } - } - - /** - * updates the cross position based on the track straight line fit - * parameters - * - * @param cross - * @param fit_yxslope - * @param fit_yzslope - * @param geo - */ - @Deprecated - public void update_Cross(Cross cross, double fit_yxslope, double fit_yzslope, SVTGeometry geo) { - - double x = fit_yxslope / Math.sqrt(fit_yxslope * fit_yxslope + fit_yzslope * fit_yzslope + 1); - double y = 1. / Math.sqrt(fit_yxslope * fit_yxslope + fit_yzslope * fit_yzslope + 1); - double z = fit_yzslope / Math.sqrt(fit_yxslope * fit_yxslope + fit_yzslope * fit_yzslope + 1); - - Vector3D trkDir = new Vector3D(x, y, z); - -// if (trkDir != null) { -// cross.updateSVTCross(trkDir, geo); -// } - + public void updateClusters(SVTGeometry svt) { + for(int key : this.trajs.keySet()) { + this.clsMap.get(key).update(this.get_Id(), this.trajs.get(key), svt); + } } public double get_ndf() { @@ -135,6 +107,98 @@ public boolean containsCross(Cross cross) { return isInTrack; } + + public void findTrajectory(SVTGeometry svt_geo, BMTGeometry bmt_geo) { + Ray ray = this.get_ray(); + ArrayList stateVecs = new ArrayList<>(); + + double[][][] SVTIntersections = TrajectoryFinder.calc_trackIntersSVT(ray, svt_geo); + + for (int l = 0; l < SVTGeometry.NLAYERS; l++) { + for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { + + if (SVTIntersections[l][s][0] != -999) { + + int LayerTrackIntersPlane = (l + 1); + int SectorTrackIntersPlane = (s + 1); + double XtrackIntersPlane = SVTIntersections[l][s][0]; + double YtrackIntersPlane = SVTIntersections[l][s][1]; + double ZtrackIntersPlane = SVTIntersections[l][s][2]; + double PhiTrackIntersPlane = SVTIntersections[l][s][3]; + double ThetaTrackIntersPlane = SVTIntersections[l][s][4]; + double trkToMPlnAngl = SVTIntersections[l][s][5]; + double CalcCentroidStrip = SVTIntersections[l][s][6]; + + StateVec stVec = new StateVec(XtrackIntersPlane, YtrackIntersPlane, ZtrackIntersPlane, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); + stVec.set_ID(this.get_Id()); + stVec.set_SurfaceLayer(LayerTrackIntersPlane); + stVec.set_SurfaceSector(SectorTrackIntersPlane); + stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); + stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); + stVec.set_TrkToModuleAngle(trkToMPlnAngl); + stVec.set_CalcCentroidStrip(CalcCentroidStrip); + if(stateVecs.size()>0 + && stateVecs.get(stateVecs.size()-1).x()==stVec.x() + && stateVecs.get(stateVecs.size()-1).y()==stVec.y() + && stateVecs.get(stateVecs.size()-1).z()==stVec.z()) { + } else { + stateVecs.add(stVec); + } + } + } + } + + double[][][] BMTIntersections = TrajectoryFinder.calc_trackIntersBMT(ray, bmt_geo, BMTConstants.STARTINGLAYR); + + for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { + //hemisphere 1-2 + for (int h = 0; h < 2; h++) { + + if (BMTIntersections[l][h][0] != -999) { + + int LayerTrackIntersSurf = (l + 1); + double XtrackIntersSurf = BMTIntersections[l][h][0]; + double YtrackIntersSurf = BMTIntersections[l][h][1]; + double ZtrackIntersSurf = BMTIntersections[l][h][2]; + //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); + int SectorTrackIntersSurf = bmt_geo.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); + double PhiTrackIntersSurf = BMTIntersections[l][h][3]; + double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; + double trkToMPlnAngl = BMTIntersections[l][h][5]; + double CalcCentroidStrip = BMTIntersections[l][h][6]; + + StateVec stVec = new StateVec(XtrackIntersSurf, YtrackIntersSurf, ZtrackIntersSurf, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); + + stVec.set_ID(this.get_Id()); + stVec.set_SurfaceLayer(LayerTrackIntersSurf); + stVec.set_SurfaceSector(SectorTrackIntersSurf); + stVec.set_TrkPhiAtSurface(PhiTrackIntersSurf); + stVec.set_TrkThetaAtSurface(ThetaTrackIntersSurf); + stVec.set_TrkToModuleAngle(trkToMPlnAngl); + stVec.set_CalcCentroidStrip(CalcCentroidStrip); + if(stateVecs.size()>0 + && stateVecs.get(stateVecs.size()-1).x()==stVec.x() + && stateVecs.get(stateVecs.size()-1).y()==stVec.y() + && stateVecs.get(stateVecs.size()-1).z()==stVec.z()) { + } else { + stateVecs.add(stVec); + } + } + } + } + + //Collections.sort(stateVecs); + + stateVecs.sort(Comparator.comparing(StateVec::y)); + for (int l = 0; l < stateVecs.size(); l++) { + stateVecs.get(l).set_planeIdx(l); + } + this.set_Trajectory(stateVecs); + this.set_SVTIntersections(SVTIntersections); + this.set_BMTIntersections(BMTIntersections); + } + + /** * * @return the chi^2 for the straight track fit diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 8e55e47ff..452edc1ea 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -301,7 +301,7 @@ public ArrayList getHelicalTracks(CrossList crossList, Seed seed = new Seed(crossList.get(i), fitTrk.get_helix()); Track cand = new Track(seed); //cand.setPXYZ(fitTrk.get_helix()); done in Track constructor - //cand.update_Crosses(svt_geo); + //cand.updateCrosses(svt_geo); cand.get_Seed().set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params cand.get_Seed().set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params @@ -376,7 +376,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List Date: Sun, 9 Jan 2022 20:02:23 +0100 Subject: [PATCH 264/291] Added methods to generate measurement surfaces to BMT and SVT geometry classes. Instances of detectors geometry services are now static members of Constants class to facilitate access --- .../detector/geant4/v2/SVT/SVTConstants.java | 15 +- .../clas/tracking/kalmanfilter/AKFitter.java | 2 +- .../kalmanfilter/straight/KFitter.java | 2 +- .../main/java/org/jlab/rec/cvt/Constants.java | 12 ++ .../org/jlab/rec/cvt/banks/HitReader.java | 14 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 34 ++++ .../java/org/jlab/rec/cvt/bmt/BMTType.java | 5 - .../org/jlab/rec/cvt/cluster/Cluster.java | 12 +- .../jlab/rec/cvt/cluster/ClusterFinder.java | 2 - .../java/org/jlab/rec/cvt/cross/Cross.java | 47 +++-- .../org/jlab/rec/cvt/cross/CrossMaker.java | 34 ++-- .../rec/cvt/cross/HelixCrossListFinder.java | 33 ++-- .../cross/StraightTrackCrossListFinder.java | 27 ++- .../jlab/rec/cvt/fit/StraightTrackFitter.java | 2 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 8 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 30 ++- .../rec/cvt/services/CosmicTracksRec.java | 33 ++-- .../jlab/rec/cvt/services/RecUtilities.java | 108 +++++------ .../rec/cvt/services/TracksFromTargetRec.java | 36 ++-- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 72 +++++++ .../java/org/jlab/rec/cvt/track/Cell.java | 1 - .../java/org/jlab/rec/cvt/track/MakerCA.java | 14 +- .../java/org/jlab/rec/cvt/track/Seed.java | 16 +- .../org/jlab/rec/cvt/track/StraightTrack.java | 30 +-- .../rec/cvt/track/StraightTrackSeeder.java | 40 ++-- .../java/org/jlab/rec/cvt/track/Track.java | 11 +- .../rec/cvt/track/TrackCandListFinder.java | 75 ++++---- .../jlab/rec/cvt/track/TrackListFinder.java | 15 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 24 ++- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 14 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 176 +++++++++--------- 31 files changed, 492 insertions(+), 452 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java index 000643dbd..b2b375121 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/SVT/SVTConstants.java @@ -105,12 +105,23 @@ public class SVTConstants public static final double SIDETOL = 1.0; // extra width used in defining the module corners public static final double LENGTHTOL = 10.0; // extra length for track intersection + // tungsten shield + public static double TSHIELDRMIN = 51; + public static double TSHIELDRMAX = 51.051; + public static double TSHIELDLENGTH = 360; + public static double TSHIELDZPOS = -50; + public static double TSHIELDRADLEN = 6.76/19.3 *10; // X0(g/cm2) / density(g/cm3) * 10; + public static double TSHILEDZOVERA = 0.40252; + // faraday cup cage public static double[] FARADAYCAGERMIN = new double[4]; public static double[] FARADAYCAGERMAX = new double[4]; public static double[] FARADAYCAGELENGTH = new double[4]; public static double[] FARADAYCAGEZPOS = new double[4]; public static String[] FARADAYCAGENAME = new String[4]; + public static double[] FARADAYCAGERADLEN = new double[4]; + public static double[] FARADAYCAGEZOVERA = new double[4]; + // region peek supports public static double[] REGIONPEEKRMIN; @@ -118,7 +129,7 @@ public class SVTConstants public static double[] REGIONPEEKLENGTH; // material and radiation length information - public static final double SILICONRADLEN = 9.36 * 10; //check this - converted to mm + public static final double SILICONRADLEN = 9.36 * 10; //converted to mm public static final double ZOVERA = 0.49848; /** @@ -297,6 +308,8 @@ else if( value == "tube" ) // offset by boxNum to reset row for CCDB table FARADAYCAGEZPOS[i] = cp.getDouble( ccdbPath+"material/faradaycage/zpos", i); FARADAYCAGENAME[i] = cp.getString( ccdbPath+"material/faradaycage/name", i); } + FARADAYCAGERADLEN = new double[]{503, 237, 5440, 1000}; // RDV do be checked + FARADAYCAGEZOVERA = new double[]{0.52037, 0.5, 0.5, 0.5}; // calculate derived constants NLAYERS = NMODULES*NREGIONS; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index 07e30bd29..edc2257de 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -120,7 +120,7 @@ public double calc_chi2(AStateVecs sv, AMeasVecs mv) { ndf++; } } - if(chisq==0) chisq=Double.POSITIVE_INFINITY; + if(chisq==0) chisq=Double.NaN; return chisq; } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index 7792422fe..a467d0b91 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -56,7 +56,7 @@ public void runFitter(AStateVecs sv, AMeasVecs mv) { // chi2 double newchisq = this.calc_chi2(sv, mv); // if curvature is 0, fit failed - if(sv.trackTraj.get(0)==null) { + if(Double.isNaN(newchisq) || sv.trackTraj.get(0)==null) { this.setFitFailed = true; break; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index fd148eacc..564f23fc9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -2,10 +2,16 @@ import cnuphys.magfield.MagneticFields; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jlab.clas.swimtools.Swim; +import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.clas.tracking.utilities.MatrixOps.Libr; +import org.jlab.detector.geant4.v2.CTOFGeant4Factory; +import org.jlab.geom.base.Detector; +import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.svt.SVTGeometry; public class Constants { @@ -89,6 +95,12 @@ public class Constants { private static final double[][]BMTPhiZRangeExcld = new double[2][2]; private static int BMTLayerExcld = -1; + public static SVTGeometry SVTGEOMETRY = null; + public static BMTGeometry BMTGEOMETRY = null; + public static CTOFGeant4Factory CTOFGEOMETRY = null; + public static Detector CNDGEOMETRY = null; + public static List CVTSURFACES = null; + public static double getXb() { return _Xb; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index d1a8f0637..b75017623 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -77,9 +77,8 @@ public void set_SVTHits(List _SVTHits) { * @param event the data event * @param adcConv converter from adc to values used in the analysis (i.e. * Edep for gemc, adc for cosmics) - * @param geo the BMT geometry */ - public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo, Swim swim, IndexedTable status, IndexedTable timeCuts) { + public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, Swim swim, IndexedTable status, IndexedTable timeCuts) { // return if there is no BMT bank if (event.hasBank("BMT::adc") == false) { @@ -124,7 +123,7 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo if(time!=0 && (timetmax)) BmtStrip.setStatus(2);// calculate the strip parameters for the BMT hit } - BmtStrip.calc_BMTStripParams(geo, sector, layer, swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect + BmtStrip.calc_BMTStripParams(sector, layer, swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect // create the hit object for detector type BMT Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, BmtStrip); @@ -143,9 +142,8 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, BMTGeometry geo * * @param event the data event * @param adcConv converter from adc to daq values - * @param geo the SVT geometry */ - public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, SVTGeometry geo, IndexedTable status) { + public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, IndexedTable status) { if (event.hasBank("BST::adc") == false) { //System.err.println("there is no BST bank "); @@ -238,9 +236,9 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, Strip SvtStrip = new Strip(strip, adcConv.SVTADCtoDAQ(ADC), time); SvtStrip.set_Pitch(SVTGeometry.getPitch()); // get the strip line - SvtStrip.set_Line(geo.getStrip(layer, sector, strip)); - SvtStrip.set_Module(geo.getModule(layer, sector)); - SvtStrip.set_Normal(geo.getNormal(layer, sector)); + SvtStrip.set_Line(Constants.SVTGEOMETRY.getStrip(layer, sector, strip)); + SvtStrip.set_Module(Constants.SVTGEOMETRY.getModule(layer, sector)); + SvtStrip.set_Normal(Constants.SVTGEOMETRY.getNormal(layer, sector)); if(layer%2==0) { SvtStrip.setToverX0(2*SVTGeometry.getToverX0()); SvtStrip.setZoverA(SVTGeometry.getZoverA()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 9c75f361a..b4472ecb7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -16,6 +16,7 @@ import static org.jlab.rec.cvt.bmt.Lorentz.getLorentzAngle; import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.Surface; +import org.jlab.clas.tracking.objects.Strip; import org.jlab.geom.prim.Transformation3D; import org.jlab.groot.data.H1F; import org.jlab.groot.graphics.EmbeddedCanvasTabbed; @@ -23,6 +24,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.cvt.Constants; + /** * * @author devita @@ -972,8 +974,40 @@ public double getThetaC(int layer, int sector, Point3D trakPos, Vector3D trackDi public List getSurfaces() { List surfaces = new ArrayList<>(); + for(int i=1; i<=NLAYERS; i++) + surfaces.add(this.getSurface(i, 1)); return surfaces; } + + public Surface getSurfaceC(int layer, int sector, int stripId, double centroid, double centroidValue, int hemisphere) { + Surface surface = this.getSurface(layer, sector); + surface.hemisphere = hemisphere; + surface.strip = new Strip(stripId, centroid, centroidValue); + return surface; + } + + public Surface getSurfaceZ(int layer, int sector, int stripId, double centroid, double x, double y, double centroidValue, int hemisphere) { + Surface surface = this.getSurface(layer, sector); + surface.hemisphere = hemisphere; + surface.strip = new Strip(stripId, centroid, x, y, centroidValue); + return surface; + } + + public Surface getSurface(int layer, int sector) { + Surface surface = new Surface(this.getTileSurface(layer, sector), + new Strip(0,0,0), + Constants.SWIMACCURACYBMT); + surface.hemisphere = 0; + surface.setLayer(layer); + surface.setSector(sector); + surface.setError(0); + surface.setl_over_X0(this.getToverX0(layer)); + surface.setZ_over_A_times_l(this.getZoverA(layer)); + surface.setThickness(this.getMaterialThickness(layer)); + surface.notUsedInFit=true; + return surface; + } + /** * Executable method: implements checks diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java index d561324a6..c0797f4b1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTType.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.rec.cvt.bmt; /** diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index d437ed6c6..b05e21bc5 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -5,7 +5,6 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.svt.SVTGeometry; import java.util.Collections; import org.jlab.clas.tracking.kalmanfilter.AKFitter.HitOnTrack; import org.jlab.clas.tracking.kalmanfilter.Surface; @@ -733,12 +732,11 @@ public void printInfo() { * * @param Z z-coordinate of a point in the local coordinate system of a * module - * @param geo * @return the average resolution for a group of strips in a cluster in the * SVT * */ - public double get_ResolutionAlongZ(double Z, SVTGeometry geo) { + public double get_ResolutionAlongZ(double Z) { // returns the total resolution for a group of strips in a cluster // the single strip resolution varies at each point along the strip as a function of Z (due to the graded angle of the strips) and @@ -752,7 +750,7 @@ public double get_ResolutionAlongZ(double Z, SVTGeometry geo) { double res = 0; for (int i = 0; i < nbhits; i++) { - double rstrp = geo.getSingleStripResolution(this.get(i).get_Layer(), this.get(i).get_Strip().get_Strip(), Z); + double rstrp = Constants.SVTGEOMETRY.getSingleStripResolution(this.get(i).get_Layer(), this.get(i).get_Strip().get_Strip(), Z); res += rstrp * rstrp; } return Math.sqrt(res); @@ -842,7 +840,7 @@ public void setN(Vector3D _n) { this._n = _n; } - public void update(int trackId, HitOnTrack traj, SVTGeometry sgeo) { + public void update(int trackId, HitOnTrack traj) { Point3D trackPos = new Point3D(traj.x, traj.y, traj.z); Vector3D trackDir = new Vector3D(traj.px, traj.py, traj.pz).asUnit(); @@ -867,8 +865,8 @@ public void update(int trackId, HitOnTrack traj, SVTGeometry sgeo) { double doca1 = hit.residual(trackPos); hit.set_docaToTrk(doca1); if(this.get_Detector()==DetectorType.BST) { - Point3D local = sgeo.toLocal(this.get_Layer(), this.get_Sector(), trackPos); - double sigma1 = sgeo.getSingleStripResolution(this.get_Layer(), hit.get_Strip().get_Strip(), local.z()); + Point3D local = Constants.SVTGEOMETRY.toLocal(this.get_Layer(), this.get_Sector(), trackPos); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(this.get_Layer(), hit.get_Strip().get_Strip(), local.z()); hit.set_stripResolutionAtDoca(sigma1); } if(traj.isMeasUsed) hit.set_TrkgStatus(1); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 5e621b440..65296ecc6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.jlab.detector.base.DetectorType; -import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Hit; /** diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 441d84652..fc2443971 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -356,18 +356,18 @@ public void set_MatchedCCross(Cross _MatchedCCross) { this._MatchedCCross = _MatchedCCross; } - public void reset(SVTGeometry geo) { + public void reset() { this.set_Dir(null); this.set_DirErr(null); if(this.get_Detector()==DetectorType.BST) - this.updateSVTCross(null, geo); + this.updateSVTCross(null); else this.updateBMTCross(null, null); } - public void update(Point3D trackPos, Vector3D trackDir, SVTGeometry geo) { + public void update(Point3D trackPos, Vector3D trackDir) { if(this.get_Detector()==DetectorType.BST) - this.updateSVTCross(trackDir, geo); + this.updateSVTCross(trackDir); else this.updateBMTCross(trackPos, trackDir); } @@ -438,7 +438,7 @@ private Vector3D getBMTCrossError(Point3D trackPos) { /** * Sets the cross parameters: the position and direction unit vector */ - public void updateSVTCross(Vector3D trackDir, SVTGeometry geo) { + public void updateSVTCross(Vector3D trackDir) { Cluster inlayerclus = this.get_Cluster1(); Cluster outlayerclus = this.get_Cluster2(); @@ -446,8 +446,8 @@ public void updateSVTCross(Vector3D trackDir, SVTGeometry geo) { return; } // RDV: z error is now smaller because resulting from strip resolution instead of +/- 1 strip - Point3D crossPoint = this.getSVTCrossPoint(trackDir, geo); - Vector3D crossError = this.getSVTCrossError(trackDir, geo); + Point3D crossPoint = this.getSVTCrossPoint(trackDir); + Vector3D crossError = this.getSVTCrossError(trackDir); if(crossPoint==null || crossError==null) { return; @@ -467,15 +467,14 @@ public void updateSVTCross(Vector3D trackDir, SVTGeometry geo) { /** * Calculate the cross point from the two strips and the track direction * @param trackDir track direction - * @param geo SVT geometry class * @return */ - public Point3D getSVTCrossPoint(Vector3D trackDir, SVTGeometry geo) { + public Point3D getSVTCrossPoint(Vector3D trackDir) { int layer = this.get_Cluster1().get_Layer(); int sector = this.get_Cluster1().get_Sector(); - Point3D cross = geo.getCross(sector, layer, this.get_Cluster1().getLine(), this.get_Cluster2().getLine(), trackDir); + Point3D cross = Constants.SVTGEOMETRY.getCross(sector, layer, this.get_Cluster1().getLine(), this.get_Cluster2().getLine(), trackDir); return cross; } @@ -483,25 +482,24 @@ public Point3D getSVTCrossPoint(Vector3D trackDir, SVTGeometry geo) { /** * Calculate the cross position error from the two strips and the track direction * @param trackDir track direction - * @param geo VT geometry * @return */ - public Vector3D getSVTCrossError(Vector3D trackDir, SVTGeometry geo) { + public Vector3D getSVTCrossError(Vector3D trackDir) { Vector3D error = null; int layer = this.get_Cluster1().get_Layer(); int sector = this.get_Cluster1().get_Sector(); - Point3D cross = this.getSVTCrossPoint(trackDir, geo); + Point3D cross = this.getSVTCrossPoint(trackDir); if(cross!=null) { // get the strip resolution - Point3D local = geo.toLocal(layer, sector, cross); - double sigma1 = geo.getSingleStripResolution(layer, this.get_Cluster1().get_SeedStrip().get_Strip(), local.z()); - double sigma2 = geo.getSingleStripResolution(layer, this.get_Cluster2().get_SeedStrip().get_Strip(), local.z()); + Point3D local = Constants.SVTGEOMETRY.toLocal(layer, sector, cross); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.get_Cluster1().get_SeedStrip().get_Strip(), local.z()); + double sigma2 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.get_Cluster2().get_SeedStrip().get_Strip(), local.z()); // get the error associated to each strip - Vector3D error1 = this.getSVTCrossDerivative(1, trackDir, geo).multiply(sigma1); - Vector3D error2 = this.getSVTCrossDerivative(2, trackDir, geo).multiply(sigma2); + Vector3D error1 = this.getSVTCrossDerivative(1, trackDir).multiply(sigma1); + Vector3D error2 = this.getSVTCrossDerivative(2, trackDir).multiply(sigma2); if(error1!=null && error2!=null) error = new Vector3D(Math.sqrt(error1.x()*error1.x()+error2.x()*error2.x()), Math.sqrt(error1.y()*error1.y()+error2.y()*error2.y()), @@ -514,17 +512,16 @@ public Vector3D getSVTCrossError(Vector3D trackDir, SVTGeometry geo) { * Calculate the cross derivative for the translation of one strip * useful for the error calculation * @param trackDir track direction - * @param geo VT geometry * @return */ - public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir, SVTGeometry geo) { + public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir) { Vector3D error = null; // check the cluster to be used in the derivative calculation is either 1 or 2 if(icluster<1 || icluster>2) return null; // if the croos position is not well defined, don't do anything - Point3D cross = this.getSVTCrossPoint(trackDir, geo); + Point3D cross = this.getSVTCrossPoint(trackDir); if(cross==null) return null; int layer = this.get_Cluster1().get_Layer(); @@ -551,12 +548,12 @@ public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir, SVTGeomet Point3D crossAPlus = null; Point3D crossAMinus = null; if(clusA.get_Layer()%2 == 1) { - crossAPlus = geo.getCross(sector, layer, stripAPlus, clusB.getLine(), trackDir); - crossAMinus = geo.getCross(sector, layer, stripAMinus, clusB.getLine(), trackDir); + crossAPlus = Constants.SVTGEOMETRY.getCross(sector, layer, stripAPlus, clusB.getLine(), trackDir); + crossAMinus = Constants.SVTGEOMETRY.getCross(sector, layer, stripAMinus, clusB.getLine(), trackDir); } else { - crossAPlus = geo.getCross(sector, layer, clusB.getLine(), stripAPlus, trackDir); - crossAMinus = geo.getCross(sector, layer, clusB.getLine(), stripAMinus, trackDir); + crossAPlus = Constants.SVTGEOMETRY.getCross(sector, layer, clusB.getLine(), stripAPlus, trackDir); + crossAMinus = Constants.SVTGEOMETRY.getCross(sector, layer, clusB.getLine(), stripAMinus, trackDir); } // if at least one is non-null, calculate the derivative diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index 461240e7a..a231f5165 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -27,11 +27,9 @@ public CrossMaker() { /** * * @param clusters clusters - * @param svt_geo svt geometry * @return list of crosses for the SVT and BMT */ - public ArrayList> findCrosses(List clusters, SVTGeometry svt_geo, - BMTGeometry bmt_geo) { + public ArrayList> findCrosses(List clusters) { // instantiate array of clusters that are sorted by detector (SVT, BMT [C, Z]) and inner/outer layers ArrayList> sortedClusters = new ArrayList>(); // fill the sorted list @@ -67,8 +65,8 @@ public ArrayList> findCrosses(List clusters, SVTGeomet bmt_Clayrclus.removeAll(rbmt_Clayrclus); } // arrays of BMT and SVT crosses - ArrayList BMTCrosses = this.findBMTCrosses(bmt_Clayrclus, bmt_Zlayrclus, bmt_geo,1000); - ArrayList SVTCrosses = this.findSVTCrosses(svt_innerlayrclus, svt_outerlayrclus, svt_geo); + ArrayList BMTCrosses = this.findBMTCrosses(bmt_Clayrclus, bmt_Zlayrclus,1000); + ArrayList SVTCrosses = this.findSVTCrosses(svt_innerlayrclus, svt_outerlayrclus); // instantiate the arraylists of sorted Crosses by detector type ArrayList> sortedCrosses = new ArrayList>(); @@ -83,14 +81,12 @@ public ArrayList> findCrosses(List clusters, SVTGeomet * * @param svt_innerlayrclus svt inner layer clusters * @param svt_outerlayrclus svt outer layer clusters - * @param svt_geo svt geometry * @return the list of SVT crosses reconstructed from clusters in the inner * and outer layers in a module */ public ArrayList findSVTCrosses( List svt_innerlayrclus, - List svt_outerlayrclus, - SVTGeometry svt_geo) { + List svt_outerlayrclus) { // instantiate the list of crosses ArrayList crosses = new ArrayList(); int rid = 0; // cross id @@ -125,14 +121,14 @@ public ArrayList findSVTCrosses( this_cross.set_Cluster2(outlayerclus); this_cross.set_Id(rid); // sets the cross parameters (point3D and associated error) from the SVT geometry - this_cross.updateSVTCross(null, svt_geo); + this_cross.updateSVTCross(null); // the uncorrected point obtained from default estimate that the track is at 90 deg wrt the module should not be null if (this_cross.get_Point0() != null) { //pass the cross to the arraylist of crosses this_cross.set_Id(crosses.size() + 1); this_cross.set_Detector(DetectorType.BST); - calcCentErr(this_cross, this_cross.get_Cluster1(), svt_geo); - calcCentErr(this_cross, this_cross.get_Cluster2(), svt_geo); + calcCentErr(this_cross, this_cross.get_Cluster1()); + calcCentErr(this_cross, this_cross.get_Cluster2()); crosses.add(this_cross); } @@ -146,14 +142,14 @@ public ArrayList findSVTCrosses( return crosses; } - private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { - double Z = svt_geo.toLocal(Cluster1.get_Layer(), - Cluster1.get_Sector(), - c.get_Point()).z(); + private void calcCentErr(Cross c, Cluster Cluster1) { + double Z = Constants.SVTGEOMETRY.toLocal(Cluster1.get_Layer(), + Cluster1.get_Sector(), + c.get_Point()).z(); if(Z>SVTGeometry.getModuleLength()) Z=SVTGeometry.getModuleLength(); else if(Z<0) Z=0; - Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z, svt_geo) /(SVTGeometry.getPitch() / Math.sqrt(12.))); - Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z, svt_geo) ); + Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z) /(SVTGeometry.getPitch() / Math.sqrt(12.))); + Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z) ); } /** * @@ -165,7 +161,7 @@ private void calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { public ArrayList findBMTCrosses( ArrayList Clayrclus, ArrayList Zlayrclus, - BMTGeometry bmt_geo, int idx) { + int idx) { //instanciates the list of crosses ArrayList crosses = new ArrayList(); @@ -206,7 +202,7 @@ public ArrayList findBMTCrosses( for (Cross c : crosses) { int rg = 3 + - bmt_geo.getLayer( c.get_Region(), c.get_Type()) ; + Constants.BMTGEOMETRY.getLayer( c.get_Region(), c.get_Type()) ; c.setOrderedRegion(rg); } return crosses; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index e196501c2..1297b2977 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -6,14 +6,12 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; -import org.jlab.rec.cvt.bmt.BMTGeometry; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.track.Seed; -import org.jlab.rec.cvt.track.Track; -import org.jlab.rec.cvt.track.TrackSeeder; /** * A class with methods used to find lists of crosses. This is the Pattern @@ -55,8 +53,7 @@ public HelixCrossListFinder() { * @return the list of crosses determined to be consistent with belonging to * a track in the cvt */ - public List findCandidateCrossLists(List> cvt_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, Swim swimmer) { + public List findCandidateCrossLists(List> cvt_crosses, Swim swimmer) { float[] bfield = new float[3]; swimmer.BfieldLab(0, 0, 0, bfield); double bz = Math.abs(bfield[2]); @@ -175,11 +172,11 @@ public List findCandidateCrossLists(List R1Crosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, double bz) { + private void MatchToRegion1(Seed s, ArrayList R1Crosses, double bz) { if(s==null) return; - boolean fitStatus = s.fit(svt_geo, bmt_geo, 3, true, bz); + boolean fitStatus = s.fit(3, true, bz); if(!fitStatus) return; - Point3D trkAtR1 =s.get_Helix().getPointAtRadius(svt_geo.getRegionRadius(1)); + Point3D trkAtR1 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getRegionRadius(1)); List candMatches = new ArrayList(); for (int i = 0; i < R1Crosses.size(); i++) { if(R1Crosses.get(i)==null) @@ -470,8 +467,8 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_ Math.sqrt(R1Crosses.get(i).get_Point().x()*R1Crosses.get(i).get_Point().x()+R1Crosses.get(i).get_Point().y()*R1Crosses.get(i).get_Point().y()))<2) candMatches.add(R1Crosses.get(i)); } - Point3D trkAtL1 =s.get_Helix().getPointAtRadius(svt_geo.getLayerRadius(1)); - Point3D trkAtL2 =s.get_Helix().getPointAtRadius(svt_geo.getLayerRadius(2)); + Point3D trkAtL1 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(1)); + Point3D trkAtL2 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(2)); double dMin = Double.POSITIVE_INFINITY; Cross cMatch = null; @@ -488,9 +485,9 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, SVTGeometry svt_ } - private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, double bz) { + private void MatchBMTC(Seed s, ArrayList BMTCrosses, double bz) { - boolean fitStatus = s.fit(svt_geo, bmt_geo, 3, true, bz); + boolean fitStatus = s.fit(3, true, bz); if(!fitStatus) return; double maxChi2 = Double.POSITIVE_INFINITY; @@ -500,7 +497,7 @@ private void MatchBMTC(Seed s, ArrayList BMTCrosses, SVTGeometry svt_geo, continue; } else { s.get_Crosses().add(BMTCrosses.get(i)); - fitStatus = s.fit(svt_geo, bmt_geo, 3, true, bz); + fitStatus = s.fit(3, true, bz); if(!fitStatus) continue; double linechi2perndf = s.get_lineFitChi2PerNDF(); @@ -534,15 +531,15 @@ private boolean ContainsSeed(List CirTrks, Seed cand) { return inSeed; } - private double calcCentErr(Cross c, Cluster Cluster1, SVTGeometry svt_geo) { - double Z = svt_geo.toLocal(Cluster1.get_Layer(), + private double calcCentErr(Cross c, Cluster Cluster1) { + double Z = Constants.SVTGEOMETRY.toLocal(Cluster1.get_Layer(), Cluster1.get_Sector(), c.get_Point()).z(); if(Z<0) Z=0; if(Z>SVTGeometry.getActiveSensorLength()) Z=SVTGeometry.getActiveSensorLength(); - return Cluster1.get_ResolutionAlongZ(Z, svt_geo) / (SVTGeometry.getPitch() / Math.sqrt(12.)); + return Cluster1.get_ResolutionAlongZ(Z) / (SVTGeometry.getPitch() / Math.sqrt(12.)); } // /** // * A class representing the seed object. The seed of a track is the initial diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index bad839a7f..10da49c67 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -9,6 +9,7 @@ import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.LineFitPars; @@ -270,8 +271,7 @@ private boolean regionUniquenessFlag(ArrayList crossList) { * @param geo * @return find track guess with svt only */ - public CrossList findCosmicsCandidateCrossLists(List> crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { + public CrossList findCosmicsCandidateCrossLists(List> crosses, int NbSVTRegions) { CrossList crossLists = new CrossList(); @@ -334,7 +334,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, if (crossLists.get(i).size() > 0) { ArrayList crossList = new ArrayList(); // find the trajectory for each crosslist - ArrayList TrajPoints = get_XYTrajectory(crossLists.get(i), svt_geo, bmt_geo, NbSVTRegions); + ArrayList TrajPoints = get_XYTrajectory(crossLists.get(i), NbSVTRegions); Collections.sort(svt_crosses); for (Cross p : TrajPoints) { // loop over the trajectory points obtained from the trajectory function @@ -382,8 +382,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, private List errX = new ArrayList(); private List errY = new ArrayList(); - private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_geo, - BMTGeometry bmt_geo, int NbSVTRegions) { + private ArrayList get_XYTrajectory(List crosses, int NbSVTRegions) { ArrayList projectedCrosses = new ArrayList(); @@ -424,8 +423,7 @@ private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_g double yxslope = linefitparsYX.slope(); double yxinterc = linefitparsYX.intercept(); - projectedCrosses = this.get_CalcHitsOnTrackXY(yxslope, yxinterc, svt_geo, - bmt_geo, NbSVTRegions); + projectedCrosses = this.get_CalcHitsOnTrackXY(yxslope, yxinterc, NbSVTRegions); return projectedCrosses; } @@ -438,8 +436,7 @@ private ArrayList get_XYTrajectory(List crosses, SVTGeometry svt_g * @param geo the SVT geometry * @return calculated crosses on the trajectory in the xy plane */ - private ArrayList get_CalcHitsOnTrackXY(double yxslope, - double yxinterc, SVTGeometry svt_geo, BMTGeometry bmt_geo, int NbSVTRegions) { + private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, int NbSVTRegions) { Ray xyTrack = new Ray(yxslope, 0, yxinterc, 0, 0, 0, 0, 0); @@ -454,9 +451,9 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, for (int is = 0; is < SVTGeometry.NSECTORS[ir*2]; is++) { int sector = is+1; - Plane3D plane = svt_geo.getPlane(layer, sector); + Plane3D plane = Constants.SVTGEOMETRY.getPlane(layer, sector); Point3D traj = new Point3D(); - if(plane.intersection(xyTrack.toLine(), traj)==1 && svt_geo.isInFiducial(layer, sector, traj)) { + if(plane.intersection(xyTrack.toLine(), traj)==1 && Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) { Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, sector, region, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); projectedCrosses.add(cross2D); @@ -464,17 +461,17 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, } } //BMTs - for (int il = 0; il < bmt_geo.getNLayers(); il++) { + for (int il = 0; il < Constants.BMTGEOMETRY.getNLayers(); il++) { int layer = il+1; - for(int is=0; is trajs = new ArrayList<>(); - int nTraj = bmt_geo.getTileSurface(layer, sector).intersection(xyTrack.toLine(), trajs); + int nTraj = Constants.BMTGEOMETRY.getTileSurface(layer, sector).intersection(xyTrack.toLine(), trajs); if(nTraj==0) continue; for(Point3D traj : trajs) { - Cross cross2D = new Cross(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, bmt_geo.getRegion(layer), -1); + Cross cross2D = new Cross(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, Constants.BMTGEOMETRY.getRegion(layer), -1); cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); projectedCrosses.add(cross2D); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java index 56f923d76..cef1f5fc8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/StraightTrackFitter.java @@ -5,11 +5,11 @@ import org.jlab.rec.cvt.trajectory.Helix; -//import Jama.Matrix; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.svt.SVTGeometry; + /** * A fitter which does sequential fit (for r, phi coordinates) to a circle using * CircleFitter and then (for r, z coordinates) to a line using LineFitter. Uses diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index ee3449705..02c23ceb9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -7,6 +7,7 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Transformation3D; import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.bmt.BMTConstants; @@ -231,14 +232,13 @@ public void setStatus(int _Status) { /** * * - * @param geo the BMT geometry class Sets the Lorentz corrected phi and - * strip number for Z detectors, the z position for C detectors * @param sector * @param layer * @param swim */ - public void calc_BMTStripParams(BMTGeometry geo, int sector, int layer, Swim swim) { - + public void calc_BMTStripParams(int sector, int layer, Swim swim) { + BMTGeometry geo = Constants.BMTGEOMETRY; + int region = geo.getRegion(layer); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 this.setToGlobal(geo.toGlobal(layer, sector)); this.setToLocal(geo.toLocal(layer, sector)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 013f8dde4..6b8b3462e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -14,7 +14,6 @@ import org.jlab.detector.geant4.v2.SVT.SVTConstants; import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.base.ConstantProvider; -import org.jlab.geom.base.Detector; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; @@ -42,11 +41,6 @@ */ public class CVTRecNewKF extends ReconstructionEngine { - private SVTGeometry SVTGeom = null; - private BMTGeometry BMTGeom = null; - private CTOFGeant4Factory CTOFGeom = null; - private Detector CNDGeom = null; - private SVTStripFactory svtIdealStripFactory = null; private CosmicTracksRec strgtTrksRec = null; private TracksFromTargetRec trksFromTargetRec = null; private int Run = -1; @@ -54,8 +48,7 @@ public class CVTRecNewKF extends ReconstructionEngine { public CVTRecNewKF() { super("CVTTracks", "ziegler", "4.0"); - BMTGeom = new BMTGeometry(); - strgtTrksRec = new CosmicTracksRec(); + strgtTrksRec = new CosmicTracksRec(); trksFromTargetRec = new TracksFromTargetRec(); } @@ -123,9 +116,9 @@ public boolean processDataEvent(DataEvent event) { IndexedTable bmtTime = this.getConstantsManager().getConstants(this.getRun(), "/calibration/mvt/bmt_time"); HitReader hitRead = new HitReader(); - hitRead.fetch_SVTHits(event, adcConv, -1, -1, SVTGeom, svtStatus); + hitRead.fetch_SVTHits(event, adcConv, -1, -1, svtStatus); if(Constants.SVTOnly==false) - hitRead.fetch_BMTHits(event, adcConv, BMTGeom, swimmer, bmtStatus, bmtTime); + hitRead.fetch_BMTHits(event, adcConv, swimmer, bmtStatus, bmtTime); List hits = new ArrayList<>(); //I) get the hits @@ -177,7 +170,7 @@ public boolean processDataEvent(DataEvent event) { } CrossMaker crossMake = new CrossMaker(); - List> crosses = crossMake.findCrosses(clusters, SVTGeom, BMTGeom); + List> crosses = crossMake.findCrosses(clusters); if(crosses.get(0).size() > SVTParameters.MAXSVTCROSSES ) { rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, null, null, null); return true; @@ -190,10 +183,10 @@ public boolean processDataEvent(DataEvent event) { // crosses_svtOnly.add(1, new ArrayList<>()); // } strgtTrksRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, swimmer); + crosses, rbc, swimmer); } else { trksFromTargetRec.processEvent(event,SVThits, BMThits, SVTclusters, BMTclusters, - crosses, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, rbc, swimmer); + crosses, rbc, swimmer); } return true; } @@ -326,8 +319,8 @@ private void loadGeometries() { String variation = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); System.out.println(" CVT YAML VARIATION NAME + "+variation); ConstantProvider providerCTOF = GeometryFactory.getConstants(DetectorType.CTOF, 11, variation); - CTOFGeom = new CTOFGeant4Factory(providerCTOF); - CNDGeom = GeometryFactory.getDetector(DetectorType.CND, 11, variation); + Constants.CTOFGEOMETRY = new CTOFGeant4Factory(providerCTOF); + Constants.CNDGEOMETRY = GeometryFactory.getDetector(DetectorType.CND, 11, variation); System.out.println(" LOADING CVT GEOMETRY...............................variation = "+variation); CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variation)); @@ -336,7 +329,12 @@ private void loadGeometries() { cp = SVTConstants.connect( cp ); cp.disconnect(); SVTStripFactory svtFac = new SVTStripFactory(cp, true); - SVTGeom = new SVTGeometry(svtFac); + Constants.SVTGEOMETRY = new SVTGeometry(svtFac); + Constants.BMTGEOMETRY = new BMTGeometry(); + + Constants.CVTSURFACES = new ArrayList<>(); + Constants.CVTSURFACES.addAll(Constants.SVTGEOMETRY.getSurfaces()); + Constants.CVTSURFACES.addAll(Constants.BMTGEOMETRY.getSurfaces()); } private void registerBanks() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 90b7ced24..de3ab199d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -11,7 +11,6 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; @@ -19,7 +18,6 @@ import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackCandListFinder; @@ -38,14 +36,11 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, Swim swimmer) { // make list of crosses consistent with a track candidate using SVT only first StraightTrackCrossListFinder crossLister = new StraightTrackCrossListFinder(); - CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, SVTGeom, - BMTGeom, 3); + CrossList crosslist = crossLister.findCosmicsCandidateCrossLists(crosses, 3); if (crosslist == null || crosslist.isEmpty()) { // create the clusters and fitted hits banks rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); @@ -54,20 +49,20 @@ public boolean processEvent(DataEvent event, } // refit track based on SVT only and then add BMT and refit again TrackCandListFinder trkcandFinder = new TrackCandListFinder(); - List cosmicCands = trkcandFinder.getStraightTracks(crosslist, crosses.get(1), SVTGeom, BMTGeom); + List cosmicCands = trkcandFinder.getStraightTracks(crosslist, crosses.get(1)); List trkcands = new ArrayList<>(); //REMOVE THIS //crosses.get(0).addAll(crosses.get(1)); //------------------------ if (cosmicCands.isEmpty()) { - recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; + recUtil.CleanupSpuriousCrosses(crosses, null) ; rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); return true; } if(Constants.excludeLayers==true) { CosmicFitter fitTrk = new CosmicFitter(); - cosmicCands = recUtil.reFit(cosmicCands, SVTGeom, fitTrk, trkcandFinder); + cosmicCands = recUtil.reFit(cosmicCands, fitTrk, trkcandFinder); } if (cosmicCands.size() > 0) { @@ -82,10 +77,10 @@ public boolean processEvent(DataEvent event, cosmicCands.get(k1).get(k2).get_Cluster2().set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate cluster2 in cross } } - trkcandFinder.matchClusters(SVTclusters, new TrajectoryFinder(), SVTGeom, BMTGeom, true, + trkcandFinder.matchClusters(SVTclusters, new TrajectoryFinder(), true, cosmicCands.get(k1).get_Trajectory(), k1 + 1); } - recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; + recUtil.CleanupSpuriousCrosses(crosses, null) ; KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.kfMatLib); @@ -108,15 +103,15 @@ public boolean processEvent(DataEvent event, cov[4][4]=1; kf.init(ray.get_yxinterc(),ray.get_yzinterc(), ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmicCands.get(k1), SVTGeom, BMTGeom, swimmer)); + recUtil.setMeasVecs(cosmicCands.get(k1), swimmer)); kf.mv.setDelta_d_a(new double[]{0.1, 0.1, 0.0001, 0.0001, 1}); kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { StraightTrack cosmic = cosmicCands.get(k1); - cosmic.update(kf, SVTGeom, BMTGeom); + cosmic.update(kf); //refit adding missing clusters - List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmic, SVTGeom); + List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmic); if(clsOnTrack.size()>0) { List pseudoCrosses = new ArrayList<>(); for(Cluster cl : clsOnTrack) { @@ -138,10 +133,10 @@ public boolean processEvent(DataEvent event, //refit kf.init(cosmic.get_ray().get_yxinterc(),cosmic.get_ray().get_yzinterc(), cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmic, SVTGeom, BMTGeom, swimmer)) ; + recUtil.setMeasVecs(cosmic, swimmer)) ; kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { - cosmic.update(kf, SVTGeom, BMTGeom); + cosmic.update(kf); } } cosmics.add(cosmic); @@ -163,14 +158,14 @@ public boolean processEvent(DataEvent event, if(!cosmics.isEmpty()) { for(int k = 0; k < cosmics.size(); k++) { cosmics.get(k).set_Id(k + 1); - cosmics.get(k).updateCrosses(SVTGeom); - cosmics.get(k).updateClusters(SVTGeom); + cosmics.get(k).updateCrosses(); + cosmics.get(k).updateClusters(); } } for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { if(c.get_AssociatedTrackID()==-1) { - c.reset(SVTGeom); + c.reset(); } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 9514d5bbb..399964608 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -50,12 +50,11 @@ */ public class RecUtilities { - public void CleanupSpuriousCrosses(List> crosses, List trks, - SVTGeometry SVTGeom) { + public void CleanupSpuriousCrosses(List> crosses, List trks) { List rmCrosses = new ArrayList(); for(Cross c : crosses.get(0)) { - if(!SVTGeom.isInFiducial(c.get_Cluster1().get_Layer(), c.get_Sector(), c.get_Point())) + if(!Constants.SVTGEOMETRY.isInFiducial(c.get_Cluster1().get_Layer(), c.get_Sector(), c.get_Point())) rmCrosses.add(c); } @@ -130,8 +129,7 @@ public List setMeasVecs(Seed trkcand, Swim swim) { private TrajectoryFinder tf = new TrajectoryFinder(); - public List setMeasVecs(StraightTrack trkcand, - SVTGeometry sgeo, BMTGeometry bgeo, Swim swim) { + public List setMeasVecs(StraightTrack trkcand, Swim swim) { if(trkcand.clsMap!=null) trkcand.clsMap.clear(); //VZ: reset cluster map for second pass tracking with isolated SVT clusters //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList<>(); @@ -159,8 +157,8 @@ public List setMeasVecs(StraightTrack trkcand, Ray ray = trkcand.get_ray(); Point3D top = new Point3D(); Point3D bottom = new Point3D(); - sgeo.getPlane(layertop, sector).intersection(ray.toLine(), top); - sgeo.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); + Constants.SVTGEOMETRY.getPlane(layertop, sector).intersection(ray.toLine(), top); + Constants.SVTGEOMETRY.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); if(top.y()>bottom.y()) { cls.add(trkcand.get(i).get_Cluster1()); @@ -218,8 +216,7 @@ public List setMeasVecs(StraightTrack trkcand, return KFSites; } - public List FindClustersOnTrack(List allClusters, StraightTrack trkcand, - SVTGeometry sgeo) { + public List FindClustersOnTrack(List allClusters, StraightTrack trkcand) { List clustersOnTrack = new ArrayList<>(); Map clusterMap = new HashMap(); trkcand.sort(Comparator.comparing(Cross::getY).reversed()); @@ -234,8 +231,8 @@ public List FindClustersOnTrack(List allClusters, StraightTrac Ray ray = trkcand.get_ray(); Point3D top = new Point3D(); Point3D bottom = new Point3D(); - sgeo.getPlane(layertop, sector).intersection(ray.toLine(), top); - sgeo.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); + Constants.SVTGEOMETRY.getPlane(layertop, sector).intersection(ray.toLine(), top); + Constants.SVTGEOMETRY.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); if(top.y()>bottom.y()) { clsList.add(trkcand.get(i).get_Cluster1()); @@ -261,11 +258,11 @@ public List FindClustersOnTrack(List allClusters, StraightTrac Ray ray = trkcand.get_ray(); Point3D traj = new Point3D(); - sgeo.getPlane(layer, sector).intersection(ray.toLine(), traj); + Constants.SVTGEOMETRY.getPlane(layer, sector).intersection(ray.toLine(), traj); int key = SVTGeometry.getModuleId(layer, sector); - if(traj!=null && sgeo.isInFiducial(layer, sector, traj)) { + if(traj!=null && Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) { double doca = Double.POSITIVE_INFINITY; // loop over all clusters in the same sector and layer that are not associated to s track for(Cluster cls : allClusters) { @@ -297,8 +294,7 @@ public List FindClustersOnTrack(List allClusters, StraightTrac } - public List FindClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, - SVTGeometry sgeo, Swim swimmer) { + public List FindClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, @@ -319,7 +315,7 @@ public List FindClustersOnTrk(List allClusters, List int layer = ilayer + 1; // identify the sector the track may be going through (this doesn't account for misalignments - Point3D helixPoint = helix.getPointAtRadius(sgeo.getLayerRadius(layer)); + Point3D helixPoint = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(layer)); // reinitilize swimmer from last surface if(inters!=null) { @@ -331,7 +327,7 @@ public List FindClustersOnTrk(List allClusters, List // check the angle between the trajectory point and the sector // and skip sectors that are too far (more than the sector angular coverage) - Vector3D n = sgeo.getNormal(layer, sector); + Vector3D n = Constants.SVTGEOMETRY.getNormal(layer, sector); double deltaPhi = Math.acos(helixPoint.toVector3D().asUnit().dot(n)); double buffer = Math.toRadians(1.); if(Math.abs(deltaPhi)>2*Math.PI/SVTGeometry.NSECTORS[ilayer]+buffer) continue; @@ -340,14 +336,14 @@ public List FindClustersOnTrk(List allClusters, List // calculate trajectory Point3D traj = null; - Point3D p = sgeo.getModule(layer, sector).origin(); + Point3D p = Constants.SVTGEOMETRY.getModule(layer, sector).origin(); Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); inters = swimmer.SwimPlane(n, pm, Constants.DEFAULTSWIMACC/10); if(inters!=null) { traj = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); } // if trajectory is valid, look for missing clusters - if(traj!=null && sgeo.isInFiducial(layer, sector, traj)) { + if(traj!=null && Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) { double doca = Double.POSITIVE_INFINITY; //if(clusterMap.containsKey(key)) { // Cluster cluster = clusterMap.get(key); @@ -380,8 +376,7 @@ public List FindClustersOnTrk(List allClusters, List } return clustersOnTrack; } - public List FindClustersOnTrk(List allClusters, List seedCrosses, Helix helix, double P, int Q, - BMTGeometry bgeo, Swim swimmer) { + public List findBMTClustersOnTrk(List allClusters, List seedCrosses, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, @@ -395,13 +390,13 @@ public List FindClustersOnTrk(List allClusters, List se continue; Cluster cluster = cross.get_Cluster1(); cluster.set_AssociatedTrackID(0); - clusterMap.put(BMTGeometry.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); + clusterMap.put(Constants.BMTGEOMETRY.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); } // for each layer for (int ilayer = 0; ilayer < BMTGeometry.NLAYERS; ilayer++) { int layer = ilayer + 1; - double radius = bgeo.getRadiusMidDrift(layer); + double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(layer); // identify the sector the track may be going through (this doesn't account for misalignments Point3D helixPoint = helix.getPointAtRadius(radius); // reinitilize swimmer from last surface @@ -414,7 +409,7 @@ public List FindClustersOnTrk(List allClusters, List se // check the angle between the trajectory point and the sector // and skip sectors that are too far (more than the sector angular coverage) - if(bgeo.inDetector(layer, sector, helixPoint)==false) + if(Constants.BMTGEOMETRY.inDetector(layer, sector, helixPoint)==false) continue; // calculate trajectory @@ -429,7 +424,7 @@ public List FindClustersOnTrk(List allClusters, List se // if trajectory is valid, look for missing clusters - if(traj!=null && bgeo.inDetector(layer, sector, traj)) { + if(traj!=null && Constants.BMTGEOMETRY.inDetector(layer, sector, traj)) { double doca = Double.POSITIVE_INFINITY; // loop over all clusters in the same sector and layer that are not associated to s track for(Cluster cls : allClusters) { @@ -459,18 +454,17 @@ public List FindClustersOnTrk(List allClusters, List se return clustersOnTrack; } - List findCrossesOnBMTTrack(List bmtclsOnTrack, BMTGeometry bmt_geo, CrossMaker cm, int idx) { + List findCrossesOnBMTTrack(List bmtclsOnTrack, CrossMaker cm, int idx) { // fill the sorted list ArrayList> sortedClusters = cm.sortClusterByDetectorAndIO(bmtclsOnTrack); ArrayList bmt_Clayrclus = sortedClusters.get(2); ArrayList bmt_Zlayrclus = sortedClusters.get(3); - ArrayList BMTCrosses = cm.findBMTCrosses(bmt_Clayrclus, bmt_Zlayrclus, bmt_geo, idx); + ArrayList BMTCrosses = cm.findBMTCrosses(bmt_Clayrclus, bmt_Zlayrclus, idx); return BMTCrosses; } public void MatchTrack2Traj(Seed trkcand, Map traj, - SVTGeometry sgeo, BMTGeometry bgeo) { + org.jlab.clas.tracking.kalmanfilter.helical.KFitter.HitOnTrack> traj) { for (int i = 0; i < trkcand.get_Clusters().size(); i++) { //SVT if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { @@ -482,7 +476,7 @@ public void MatchTrack2Traj(Seed trkcand, Map reFit(List seedlist, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - Swim swimmer, StraightTrackSeeder trseed) { + public List reFit(List seedlist, Swim swimmer, StraightTrackSeeder trseed) { List filtlist = new ArrayList(); if(seedlist==null) return filtlist; for (Seed bseed : seedlist) { if(bseed == null) continue; - List fseeds = this.reFitSeed(bseed, SVTGeom, BMTGeom, trseed); + List fseeds = this.reFitSeed(bseed, trseed); if(fseeds!=null) { filtlist.addAll(fseeds); } @@ -613,9 +603,7 @@ public List reFit(List seedlist, return filtlist; } - public List reFitSeed(Seed bseed, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - StraightTrackSeeder trseed) { + public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { List seedlist = new ArrayList(); List refib = new ArrayList(); @@ -635,17 +623,17 @@ public List reFitSeed(Seed bseed, layr2 = c.get_Cluster2().get_Layer(); if((int)Constants.getLayersUsed().get(layr)>0 && (int)Constants.getLayersUsed().get(layr2)>0) { - c.updateSVTCross(null, SVTGeom); + c.updateSVTCross(null); c.isInSeed = false; refi.add(c); } } } Collections.sort(refi); - seedlist.addAll(trseed.findSeed(refi, refib, SVTGeom, BMTGeom, false)); + seedlist.addAll(trseed.findSeed(refi, refib, false)); return seedlist; } - public boolean reFitCircle(Seed seed,SVTGeometry SVTGeom, BMTGeometry BMTGeom, int iter) { + public boolean reFitCircle(Seed seed, int iter) { boolean fitStatus = false; List Xs = new ArrayList<>() ; @@ -677,33 +665,29 @@ public boolean reFitCircle(Seed seed,SVTGeometry SVTGeom, BMTGeometry BMTGeom, i seed.get_Helix().set_curvature(pars.rho()); seed.get_Helix().set_dca(-pars.doca()); seed.get_Helix().set_phi_at_dca(pars.phi()); - seed.update_Crosses(SVTGeom, BMTGeom); + seed.update_Crosses(); } } return fitStatus; } - public List reFit(List seedlist, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { - trseed = new TrackSeederCA(SVTGeom, BMTGeom, swimmer); - trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); + public List reFit(List seedlist, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { + trseed = new TrackSeederCA(swimmer); + trseed2 = new TrackSeeder(swimmer); List filtlist = new ArrayList(); if(seedlist==null) return filtlist; for (Seed bseed : seedlist) { if(bseed == null) continue; - List fseeds = this.reFitSeed(bseed, SVTGeom, BMTGeom, swimmer, trseed, trseed2); + List fseeds = this.reFitSeed(bseed, swimmer, trseed, trseed2); if(fseeds!=null) { filtlist.addAll(fseeds); } } return filtlist; } - public List reFitSeed(Seed bseed, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { + public List reFitSeed(Seed bseed, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { boolean pass = true; List seedlist = new ArrayList(); @@ -724,7 +708,7 @@ public List reFitSeed(Seed bseed, layr2 = c.get_Cluster2().get_Layer(); if((int)Constants.getLayersUsed().get(layr)>0 && (int)Constants.getLayersUsed().get(layr2)>0) { - c.updateSVTCross(null, SVTGeom); + c.updateSVTCross(null); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refi.add(c); @@ -740,8 +724,7 @@ public List reFitSeed(Seed bseed, return seedlist; } - public List reFit(List seedlist, - SVTGeometry SVTGeom, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + public List reFit(List seedlist, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { fitTrk = new CosmicFitter(); trkfindr = new TrackCandListFinder(); List filtlist = new ArrayList(); @@ -750,7 +733,7 @@ public List reFit(List seedlist, for (StraightTrack bseed : seedlist) { if(bseed == null) continue; - List fseeds = this.reFitSeed(bseed, SVTGeom, fitTrk, trkfindr); + List fseeds = this.reFitSeed(bseed, fitTrk, trkfindr); if(fseeds!=null) { filtlist.addAll(fseeds); } @@ -759,8 +742,7 @@ public List reFit(List seedlist, } - public List reFitSeed(StraightTrack cand, - SVTGeometry SVTGeom, CosmicFitter fitTrk,TrackCandListFinder trkfindr) { + public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,TrackCandListFinder trkfindr) { boolean pass = true; List seedlist = new ArrayList(); @@ -781,7 +763,7 @@ public List reFitSeed(StraightTrack cand, layr2 = c.get_Cluster2().get_Layer(); if((int)Constants.getLayersUsed().get(layr)>0 && (int)Constants.getLayersUsed().get(layr2)>0) { - c.updateSVTCross(null, SVTGeom); + c.updateSVTCross(null); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refi.add(c); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index e0db7f03b..67f72fc4b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -39,8 +39,6 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, - SVTGeometry SVTGeom, BMTGeometry BMTGeom, - CTOFGeant4Factory CTOFGeom, Detector CNDGeom, RecoBankWriter rbc, Swim swimmer) { @@ -52,32 +50,32 @@ public boolean processEvent(DataEvent event, List seeds = null; if(solenoidValue<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(); - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), SVTGeom, BMTGeom, Constants.SVTOnly); + seeds = trseed.findSeed(crosses.get(0), crosses.get(1), Constants.SVTOnly); if(Constants.excludeLayers==true) { - seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed); // RDV can we juts refit? + seeds = recUtil.reFit(seeds, swimmer, trseed); // RDV can we juts refit? } } else { if(Constants.SVTOnly) { - TrackSeeder trseed = new TrackSeeder(SVTGeom, BMTGeom, swimmer); + TrackSeeder trseed = new TrackSeeder(swimmer); trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null); } else { - TrackSeederCA trseed = new TrackSeederCA(SVTGeom, BMTGeom, swimmer); // cellular automaton seeder + TrackSeederCA trseed = new TrackSeederCA(swimmer); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA if(Constants.svtSeeding || Constants.excludeLayers) { - TrackSeeder trseed2 = new TrackSeeder(SVTGeom, BMTGeom, swimmer); + TrackSeeder trseed2 = new TrackSeeder(swimmer); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); if(Constants.excludeLayers==true) { - seeds = recUtil.reFit(seeds, SVTGeom, BMTGeom, swimmer, trseed, trseed2); + seeds = recUtil.reFit(seeds, swimmer, trseed, trseed2); } } if(!Constants.seedBeamSpotConstraint()) { List failed = new ArrayList<>(); for(Seed s : seeds) { - if(!recUtil.reFitCircle(s,SVTGeom, BMTGeom, Constants.SEEDFITITERATIONS)) + if(!recUtil.reFitCircle(s, Constants.SEEDFITITERATIONS)) failed.add(s); } seeds.removeAll(failed); @@ -85,7 +83,7 @@ public boolean processEvent(DataEvent event, } } if(seeds ==null || seeds.size() == 0) { - recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; + recUtil.CleanupSpuriousCrosses(crosses, null) ; rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null, null); return true; } @@ -96,7 +94,7 @@ public boolean processEvent(DataEvent event, int id = trkcands.size()+1; seed.setId(id); Track track = new Track(seed); - track.update_Crosses(id, SVTGeom, BMTGeom); + track.update_Crosses(id); trkcands.add(track); } // if(true) { @@ -141,11 +139,11 @@ public boolean processEvent(DataEvent event, } //refit adding missing clusters List clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, seed.get_Clusters(), fittedTrack.get_helix(), - fittedTrack.get_P(), fittedTrack.get_Q(), SVTGeom, swimmer); //VZ: finds missing clusters - List bmtclsOnTrack = recUtil.FindClustersOnTrk(BMTclusters, seed.get_Crosses(), fittedTrack.get_helix(), - fittedTrack.get_P(), fittedTrack.get_Q(), BMTGeom, swimmer); //VZ: finds missing clusters + fittedTrack.get_P(), fittedTrack.get_Q(), swimmer); //VZ: finds missing clusters + List bmtclsOnTrack = recUtil.findBMTClustersOnTrk(BMTclusters, seed.get_Crosses(), fittedTrack.get_helix(), + fittedTrack.get_P(), fittedTrack.get_Q(), swimmer); //VZ: finds missing clusters CrossMaker cm = new CrossMaker(); - List bmtcrsOnTrack = recUtil.findCrossesOnBMTTrack(bmtclsOnTrack, BMTGeom, cm, crosses.get(1).size()+2000); + List bmtcrsOnTrack = recUtil.findCrossesOnBMTTrack(bmtclsOnTrack, cm, crosses.get(1).size()+2000); if(clsOnTrack.size()>0 || bmtcrsOnTrack.size()>0) { //seed.add_Clusters(clsOnTrack); @@ -205,20 +203,20 @@ public boolean processEvent(DataEvent event, TrackListFinder.removeOverlappingTracks(trkcands); if(trkcands.isEmpty()) System.out.println("Error: no tracks left after overlap remover"); - tracks = TrackListFinder.getTracks(trkcands, SVTGeom, BMTGeom, CTOFGeom, CNDGeom, swimmer); + tracks = TrackListFinder.getTracks(trkcands, swimmer); // update crosses and clusters on track for(int it = 0; it < tracks.size(); it++) { int id = it + 1; tracks.get(it).set_Id(id); - tracks.get(it).update_Crosses(id, SVTGeom, BMTGeom); - tracks.get(it).update_Clusters(id, SVTGeom); + tracks.get(it).update_Crosses(id); + tracks.get(it).update_Clusters(id); tracks.get(it).setTrackCovMat(recUtil.getCovMatInTrackRep(tracks.get(it))); } } for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { if(c.get_AssociatedTrackID()==-1) { - c.reset(SVTGeom); + c.reset(); if(det==1 && c.get_Id()>2000) { //if matched cross failed tracking resol requirements, reset its id c.set_Id(c.get_Id()-1000); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index ff3ce859d..db9cb9dd0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -1,13 +1,20 @@ package org.jlab.rec.cvt.svt; import eu.mihosoft.vrl.v3d.Vector3d; +import java.util.ArrayList; +import java.util.List; +import org.jlab.clas.tracking.kalmanfilter.Surface; +import org.jlab.clas.tracking.objects.Strip; import org.jlab.detector.geant4.v2.SVT.SVTConstants; import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; +import org.jlab.geom.prim.Arc3D; +import org.jlab.geom.prim.Cylindrical3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.geometry.prim.Line3d; +import org.jlab.rec.cvt.Constants; public class SVTGeometry { @@ -208,6 +215,71 @@ public double getLocalAngle(int layer, int sector, Vector3D trackDir) { return Math.atan(dir.x()/dir.z()); } + public List getSurfaces() { + List surfaces = new ArrayList<>(); + surfaces.add(this.getShieldSurface()); + surfaces.add(this.getFaradayCageSurfaces(0)); + for(int i=1; i<=NLAYERS; i++) { + surfaces.add(this.getSurface(i, 1)); + } + surfaces.add(this.getFaradayCageSurfaces(1)); + return surfaces; + } + + public Surface getSurface(int layer, int sector, int stripId, double centroid, Line3D stripLine, int hemisphere) { + Surface surface = this.getSurface(layer, sector); + surface.hemisphere = hemisphere; + surface.strip = new Strip(stripId, centroid, stripLine); + return surface; + } + + public Surface getSurface(int layer, int sector) { + Line3D module = this.getModule(layer, sector); + Surface surface = new Surface(this.getPlane(layer, sector), + new Strip(0,0,0), + module.origin(), module.end(), + Constants.SWIMACCURACYSVT); + surface.hemisphere = 0; + surface.setLayer(layer); + surface.setSector(sector); + surface.setError(0); + if(layer%2==0) { + surface.setl_over_X0(SVTGeometry.getToverX0()); + surface.setZ_over_A_times_l(SVTGeometry.getZoverA()); + surface.setThickness(SVTGeometry.getMaterialThickness()); + } + surface.notUsedInFit=true; + return surface; + } + + private Surface getShieldSurface() { + Point3D center = new Point3D(0, 0, Constants.getZoffset()+SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); + Point3D origin = new Point3D(SVTConstants.TSHIELDRMAX, 0, SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); + Vector3D axis = new Vector3D(0,0,1); + Arc3D base = new Arc3D(origin, center, axis, 2*Math.PI); + Cylindrical3D shieldCylinder = new Cylindrical3D(base, SVTConstants.TSHIELDLENGTH); + Surface shieldSurface = new Surface(shieldCylinder, new Strip(0, 0, 0), Constants.DEFAULTSWIMACC); + shieldSurface.setl_over_X0(SVTConstants.TSHIELDRADLEN); + shieldSurface.setZ_over_A_times_l(SVTConstants.TSHILEDZOVERA); + shieldSurface.setThickness(SVTConstants.TSHIELDRMAX-SVTConstants.TSHIELDRMIN); + shieldSurface.notUsedInFit=true; + return shieldSurface; + } + + private Surface getFaradayCageSurfaces(int i) { + Point3D center = new Point3D(0, 0, SVTConstants.FARADAYCAGEZPOS[i]-SVTConstants.FARADAYCAGELENGTH[i]/2); + Point3D origin = new Point3D(SVTConstants.FARADAYCAGERMAX[i], 0, SVTConstants.FARADAYCAGEZPOS[i]-SVTConstants.FARADAYCAGELENGTH[i]/2); + Vector3D axis = new Vector3D(0,0,1); + Arc3D base = new Arc3D(origin, center, axis, 2*Math.PI); + Cylindrical3D fcCylinder = new Cylindrical3D(base, SVTConstants.FARADAYCAGELENGTH[i]); + Surface fcSurface = new Surface(fcCylinder, new Strip(0, 0, 0), Constants.DEFAULTSWIMACC); + fcSurface.setl_over_X0(SVTConstants.FARADAYCAGERADLEN[i]); + fcSurface.setZ_over_A_times_l(SVTConstants.FARADAYCAGEZOVERA[i]); + fcSurface.setThickness(SVTConstants.FARADAYCAGERMAX[i]-SVTConstants.FARADAYCAGERMIN[i]); + fcSurface.notUsedInFit=true; + return fcSurface; + } + @Deprecated public int getSector(int layer, Point3D traj) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java index 66b060d11..7e8be693b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.track; import org.jlab.rec.cvt.cross.Cross; import org.jlab.geom.prim.Vector3D; -//import org.jlab.geom.prim.Point3D; import java.util.*; import javax.vecmath.Point2d; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index e3bb10063..3ee8c810d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -3,8 +3,8 @@ import javax.vecmath.Vector2d; import org.jlab.detector.base.DetectorType; +import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.cross.Cross; /** @@ -82,7 +82,7 @@ private boolean checkAngles( Cell cell ) { return true; } - public void createCells( List crs, BMTGeometry bgeom ){ + public void createCells( List crs){ // this function loops over the crosses and looks for pairs that pass the cuts // Collections.sort(crs); @@ -91,13 +91,13 @@ public void createCells( List crs, BMTGeometry bgeom ){ Cross a = crs.get(ic); int aReg = a.get_Region(); if( a.get_Detector()==DetectorType.BMT) { - aReg = 3 + bgeom.getLayer( aReg , a.get_Type() ); + aReg = 3 + Constants.BMTGEOMETRY.getLayer( aReg , a.get_Type() ); } if( this._debug ) { System.out.println( "\n cross a " + a.get_Id() + " " + a.get_Detector().getName() +a.get_Type().getName() + " sect:" + a.get_Sector() + " reg:" + aReg + " phi:" + a.get_Point().toVector3D().phi() + " in BMT sector:" + - bgeom.getSector(1, a.get_Point().toVector3D().phi())); + Constants.BMTGEOMETRY.getSector(1, a.get_Point().toVector3D().phi())); } @@ -108,13 +108,13 @@ public void createCells( List crs, BMTGeometry bgeom ){ // we skip same region crosses int bReg = b.get_Region(); if( b.get_Detector()==DetectorType.BMT) { - bReg = 3 + bgeom.getLayer( bReg , b.get_Type() ); + bReg = 3 + Constants.BMTGEOMETRY.getLayer( bReg , b.get_Type() ); } if( this._debug ) { System.out.println( " cross b " + b.get_Id() + " " + b.get_Detector().getName() +b.get_Type().getName() + " sect:" + b.get_Sector() + " reg:" + bReg + " phi:" + b.get_Point().toVector3D().phi() + " in BMT sector:" + - bgeom.getSector(1, b.get_Point().toVector3D().phi() )); + Constants.BMTGEOMETRY.getSector(1, b.get_Point().toVector3D().phi() )); } if( bReg <= aReg ) continue; // crosses should be ordered. skip in case they are not @@ -141,7 +141,7 @@ public void createCells( List crs, BMTGeometry bgeom ){ else{ double aphi = a.get_Point().toVector3D().phi() ; //if( ! bgeom.checkIsInSector( aphi, b.get_Sector(), 1, Math.toRadians(10) ) ) { - if(bgeom.getSector(b.get_Region()*2, aphi)==0) { + if(Constants.BMTGEOMETRY.getSector(b.get_Region()*2, aphi)==0) { if( this._debug) System.out.println("cross b and a are not in the same sector"); continue; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index cd5369d47..c6c6e8973 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -7,14 +7,12 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.HelicalTrackFitter; import org.jlab.rec.cvt.fit.HelicalTrackFitter.FitStatus; -import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Helix; /** @@ -194,7 +192,7 @@ public int compareTo(Seed arg) { } - public boolean fit(SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, + public boolean fit(int fitIter, boolean originConstraint, double bfield) { List X = new ArrayList<>(); @@ -216,7 +214,7 @@ public boolean fit(SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolea for (Cross c : this.get_Crosses()) { // reset cross to clear previous track settings on direction and Point - c.reset(svt_geo); + c.reset(); if (c.get_Detector()==DetectorType.BST) { SVTCrosses.add(c); } @@ -292,9 +290,9 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); + Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); + ErrRho.add(j, Constants.BMTGEOMETRY.getThickness()/2 / Math.sqrt(12.)); ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } @@ -331,7 +329,7 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; if(chisqMax trajs = new ArrayList<>(); @@ -71,9 +71,9 @@ public void updateCrosses(SVTGeometry geo) { } } - public void updateClusters(SVTGeometry svt) { + public void updateClusters() { for(int key : this.trajs.keySet()) { - this.clsMap.get(key).update(this.get_Id(), this.trajs.get(key), svt); + this.clsMap.get(key).update(this.get_Id(), this.trajs.get(key)); } } @@ -108,11 +108,11 @@ public boolean containsCross(Cross cross) { } - public void findTrajectory(SVTGeometry svt_geo, BMTGeometry bmt_geo) { + public void findTrajectory() { Ray ray = this.get_ray(); ArrayList stateVecs = new ArrayList<>(); - double[][][] SVTIntersections = TrajectoryFinder.calc_trackIntersSVT(ray, svt_geo); + double[][][] SVTIntersections = TrajectoryFinder.calc_trackIntersSVT(ray); for (int l = 0; l < SVTGeometry.NLAYERS; l++) { for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { @@ -148,7 +148,7 @@ public void findTrajectory(SVTGeometry svt_geo, BMTGeometry bmt_geo) { } } - double[][][] BMTIntersections = TrajectoryFinder.calc_trackIntersBMT(ray, bmt_geo, BMTConstants.STARTINGLAYR); + double[][][] BMTIntersections = TrajectoryFinder.calc_trackIntersBMT(ray, BMTConstants.STARTINGLAYR); for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { //hemisphere 1-2 @@ -161,7 +161,7 @@ public void findTrajectory(SVTGeometry svt_geo, BMTGeometry bmt_geo) { double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); - int SectorTrackIntersSurf = bmt_geo.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); + int SectorTrackIntersSurf = Constants.BMTGEOMETRY.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; double trkToMPlnAngl = BMTIntersections[l][h][5]; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index f22d85039..fb8003cdb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -9,13 +9,11 @@ import org.jlab.geom.prim.Point3D; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.fit.CircleFitPars; import org.jlab.rec.cvt.fit.StraightTrackFitter; -import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; public class StraightTrackSeeder { @@ -219,8 +217,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { List BMTmatches = new ArrayList(); - public List findSeed(List svt_crosses, List bmt_crosses, - SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean isSVTOnly) { + public List findSeed(List svt_crosses, List bmt_crosses, boolean isSVTOnly) { BMTmatches.clear(); seedScan.clear() ; List seedlist = new ArrayList(); @@ -303,7 +300,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, List seedcrs = mseed.get_Crosses(); Track cand = null; if(seedcrs.size()>=3) - cand = fitSeed(seedcrs, svt_geo, bmt_geo, 5, false); + cand = fitSeed(seedcrs, 5, false); if (cand != null) { Seed seed = new Seed(); seed.set_Crosses(seedcrs); @@ -311,16 +308,16 @@ public List findSeed(List svt_crosses, List bmt_crosses, //match to BMT if (seed != null ) { - List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses, bmt_geo); + List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses); BMTmatches.clear(); if (sameSectorCrosses.size() >= 0) { - BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses, bmt_geo); + BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses); } for (Seed bseed : BMTmatches) { Collections.sort(bseed.get_Crosses()); //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), svt_geo, bmt_geo, 5, false); + Track bcand = fitSeed(bseed.get_Crosses(), 5, false); if (bcand != null) { seed = new Seed(); seed.set_Crosses(bseed.get_Crosses()); @@ -338,7 +335,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses, BMTGeometry bmt_geo) { + private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init @@ -353,7 +350,7 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c } //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) // == bmt_crosses.get(i).get_Sector() - 1) - if (bmt_geo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), ref)==true){ + if (Constants.BMTGEOMETRY.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), ref)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -373,7 +370,7 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c List BMTCrossesZ = new ArrayList(); List SVTCrosses = new ArrayList(); - public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, + public Track fitSeed(List VTCrosses, int fitIter, boolean originConstraint) { double chisqMax = Double.POSITIVE_INFINITY; @@ -452,9 +449,9 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); + Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); - ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); + ErrRho.add(j, Constants.BMTGEOMETRY.getThickness()/2 / Math.sqrt(12.)); ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } @@ -477,7 +474,7 @@ public Track fitSeed(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt //if(shift==0) // if(i==0) System.out.println(); // System.out.println(fitTrk.get_chisq()[0] + " " + chisqMax + " " + Constants.CIRCLEFIT_MAXCHI2); - cand.update_Crosses(-1, svt_geo, bmt_geo); + cand.update_Crosses(-1); if (fitTrk.get_chisq()[0] < chisqMax) { chisqMax = fitTrk.get_chisq()[0]; // if(chisqMax VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt - public List findCandUsingMicroMegas(Seed trkCand, - List bmt_crosses, BMTGeometry bmt_geo) { + public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) { List> BMTCcrosses = new ArrayList>(); ArrayList matches = new ArrayList(); @@ -532,17 +528,17 @@ public List findCandUsingMicroMegas(Seed trkCand, matches.clear(); if (BMTCcrosses.get(0).size() > 0 && i1 < BMTCcrosses.get(0).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1))) { matches.add(BMTCcrosses.get(0).get(i1)); } } if (BMTCcrosses.get(1).size() > 0 && i2 < BMTCcrosses.get(1).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2))) { matches.add(BMTCcrosses.get(1).get(i2)); } } if (BMTCcrosses.get(2).size() > 0 && i3 < BMTCcrosses.get(2).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3), bmt_geo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3))) { matches.add(BMTCcrosses.get(2).get(i3)); } } @@ -571,16 +567,16 @@ public List findCandUsingMicroMegas(Seed trkCand, return AllSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = bmt_geo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); + double r_bmt = Constants.BMTGEOMETRY.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); Point3D refPoint = trkCand.get_Crosses().get(0).get_Point(); //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { - if (bmt_geo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x())) != bmt_Ccross.get_Sector()) { + if (Constants.BMTGEOMETRY.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x())) != bmt_Ccross.get_Sector()) { return false; } double dzdr_bmt = z_bmt / r_bmt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 0473a0ae2..dd70c3d0d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -7,7 +7,6 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; @@ -185,10 +184,8 @@ public final void setPXYZ() { /** * Updates the crosses positions based on trajectories or helix - * @param sgeo - * @param bgeo */ - public void update_Crosses(int trackId, SVTGeometry sgeo, BMTGeometry bgeo) { + public void update_Crosses(int trackId) { for (int i = 0; i < this.size(); i++) { Cross cross = this.get(i); cross.set_AssociatedTrackID(trackId); @@ -208,12 +205,12 @@ else if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { // System.out.println("Traj " + cross.get_Cluster1().get_Layer() + " " + helixPos.toString()); // System.out.println("Cross " + cross.get_Detector().getName() + " " + cross.get_Point().toString()); } - cross.update(trackPos, trackDir, sgeo); + cross.update(trackPos, trackDir); } } - public void update_Clusters(int trackId, SVTGeometry sgeo) { + public void update_Clusters(int trackId) { if(this.getTrajectories()!=null) { for (int i = 0; i < this.get_Seed().get_Clusters().size(); i++) { Cluster cluster = this.get_Seed().get_Clusters().get(i); @@ -222,7 +219,7 @@ public void update_Clusters(int trackId, SVTGeometry sgeo) { if(cluster.get_Detector()==DetectorType.BMT) layer += SVTGeometry.NLAYERS; if(this.getTrajectories().get(layer)!=null) // RDV check why it is necessary - cluster.update(trackId, this.getTrajectories().get(layer), sgeo); + cluster.update(trackId, this.getTrajectories().get(layer)); } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 452edc1ea..85668720d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -7,8 +7,6 @@ import java.util.Map; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.geant4.v2.CTOFGeant4Factory; -import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -138,7 +136,7 @@ public class RayMeasurements { * @param list the input list of crosses * @return an array list of track candidates in the SVT */ - public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) { + public void getHelicalTrack(Seed cand) { X.clear(); Y.clear(); Z.clear(); @@ -222,10 +220,7 @@ public void getHelicalTrack(Seed cand, SVTGeometry svt_geo, BMTGeometry bmt_geo) * @param crossList the input list of crosses * @return an array list of track candidates in the SVT */ - public ArrayList getHelicalTracks(CrossList crossList, - SVTGeometry svt_geo, BMTGeometry bmt_geo, - CTOFGeant4Factory ctof_geo, Detector cnd_geo, - Swim swimmer) { + public ArrayList getHelicalTracks(CrossList crossList, Swim swimmer) { X.clear(); Y.clear(); @@ -340,7 +335,7 @@ public ArrayList getHelicalTracks(CrossList crossList, * @param SVTCrossList the input list of crosses * @return an array list of track candidates in the SVT */ - public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo) { + public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses) { ArrayList cands = new ArrayList(); Map candMap= new HashMap(); @@ -376,7 +371,7 @@ public ArrayList getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List getStraightTracks(CrossList SVTCrosses, List hitsOnTrack = new ArrayList(); @@ -807,10 +802,9 @@ public RayMeasurements get_RayMeasurementsArrays(ArrayList arrayList, * * @param bmtCrosses the BMT crosses * @param thecand the straight track candidate - * @param geo the BMT geometry * @return an arraylist of BMT crosses matched to the track */ - public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCrosses, BMTGeometry geo) { + public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCrosses) { ArrayList BMTCrossList = new ArrayList(); if (thecand == null) { @@ -827,13 +821,13 @@ public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCr int region = iregion + 1; // match Z crosses - List zCross = this.matchTrackToBMT(geo.getLayer(region, BMTType.Z), thecand.get_ray(), bmtCrosses, - Constants.COSMICSMINRESIDUALX/geo.getRadiusMidDrift(geo.getLayer(region, BMTType.Z)), geo); + List zCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z), thecand.get_ray(), bmtCrosses, + Constants.COSMICSMINRESIDUALX/Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z))); if(zCross!=null) BMTCrossList.addAll(zCross); // match Z crosses - List cCross = this.matchTrackToBMT(geo.getLayer(region, BMTType.C), thecand.get_ray(), bmtCrosses, Constants.COSMICSMINRESIDUALZ, geo); + List cCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.C), thecand.get_ray(), bmtCrosses, Constants.COSMICSMINRESIDUALZ); if(cCross!=null) BMTCrossList.addAll(cCross); @@ -860,15 +854,15 @@ public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCr return BMTCrossList; } - private List matchTrackToBMT(int layer, Ray ray, List crosses, double matchCut, BMTGeometry geo) { + private List matchTrackToBMT(int layer, Ray ray, List crosses, double matchCut) { List matched = new ArrayList<>(); - for(int is=0; is trajs = new ArrayList<>(); - int ntrajs = geo.getTileSurface(layer, sector).intersection(ray.toLine(), trajs); + int ntrajs = Constants.BMTGEOMETRY.getTileSurface(layer, sector).intersection(ray.toLine(), trajs); if(ntrajs==0) continue; // find the closests cross-trajectory match @@ -898,11 +892,11 @@ private List matchTrackToBMT(int layer, Ray ray, List crosses, dou } @Deprecated - private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff, BMTGeometry geo) { + private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff) { ArrayList matchedMMCrosses = new ArrayList(); - double R = geo.getRadiusMidDrift(geo.getLayer(Region,BMTType.C)); // R for C detector + double R = Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(Region,BMTType.C)); // R for C detector double sx = ray.get_yxslope(); double ix = ray.get_yxinterc(); @@ -943,7 +937,7 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse } double m_z = MMCrosses.get(i).get_Point().z(); //int sector = geo.isInSector(MMCrosses.get(i).get_Region() * 2, phi, Math.toRadians(BMTConstants.isInSectorJitter)); - int sector = geo.getSector(MMCrosses.get(i).get_Region() * 2, phi); + int sector = Constants.BMTGEOMETRY.getSector(MMCrosses.get(i).get_Region() * 2, phi); if (sector != MMCrosses.get(i).get_Sector()) { continue; } @@ -970,11 +964,11 @@ private ArrayList MatchMMCrossC(int Region, Ray ray, List MMCrosse } @Deprecated - private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosses, double matchCutOff, BMTGeometry geo) { + private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosses, double matchCutOff) { ArrayList matchedMMCrosses = new ArrayList(); - double R = geo.getRadiusMidDrift(geo.getLayer(Region,BMTType.Z)); // R for Z detector + double R = Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(Region,BMTType.Z)); // R for Z detector double sx = ray.get_yxslope(); double ix = ray.get_yxinterc(); double sz = ray.get_yzslope(); @@ -1122,7 +1116,7 @@ private ArrayList rmStraightTrkClones(boolean removeClones, Array return passedcands; } - private void EliminateStraightTrackOutliers(ArrayList crosses, CosmicFitter track, SVTGeometry svt_geo) { + private void EliminateStraightTrackOutliers(ArrayList crosses, CosmicFitter track) { ArrayList toKeep = new ArrayList<>(); for(int j = 0; j < crosses.size(); j++) { @@ -1131,16 +1125,16 @@ private void EliminateStraightTrackOutliers(ArrayList crosses, CosmicFitt int sector = c.get_Sector(); Point3D traj = new Point3D(); - int ntraj = svt_geo.getPlane(layer, sector).intersection(track.get_ray().toLine(), traj); + int ntraj = Constants.SVTGEOMETRY.getPlane(layer, sector).intersection(track.get_ray().toLine(), traj); if(ntraj!=1) - c.reset(svt_geo); - else if(!svt_geo.isInFiducial(layer, sector, traj)) - c.reset(svt_geo); + c.reset(); + else if(!Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) + c.reset(); else { - Vector3D distance = svt_geo.toLocal(layer, sector, c.get_Point().vectorTo(traj)); + Vector3D distance = Constants.SVTGEOMETRY.toLocal(layer, sector, c.get_Point().vectorTo(traj)); if(Math.abs(distance.x())>Constants.COSMICSMINRESIDUALX || - Math.abs(distance.z())>Constants.COSMICSMINRESIDUALZ) c.reset(svt_geo); + Math.abs(distance.z())>Constants.COSMICSMINRESIDUALZ) c.reset(); else toKeep.add(c); } @@ -1148,7 +1142,7 @@ else if(!svt_geo.isInFiducial(layer, sector, traj)) crosses = toKeep; } - public void matchClusters(List sVTclusters, TrajectoryFinder tf, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal, + public void matchClusters(List sVTclusters, TrajectoryFinder tf, boolean trajFinal, ArrayList trajectory, int k) { if(trajectory == null) return; @@ -1165,8 +1159,7 @@ public void matchClusters(List sVTclusters, TrajectoryFinder tf, SVTGeo continue; } if (Math.abs(st.get_CalcCentroidStrip() - cls.get_Centroid()) < 4) { - tf.setHitResolParams("SVT", cls.get_Sector(), cls.get_Layer(), cls, - st, svt_geo, bmt_geo, trajFinal); + tf.setHitResolParams("SVT", cls.get_Sector(), cls.get_Layer(), cls, st, trajFinal); //System.out.println("trying to associate a cluster ");cls.printInfo(); System.out.println(" to "+st.get_CalcCentroidStrip()+" dStp = "+(st.get_CalcCentroidStrip()-cls.get_Centroid())); cls.set_AssociatedTrackID(k); for (Hit h : cls) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 598491938..5f5168031 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -4,16 +4,12 @@ import java.util.List; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.geant4.v2.CTOFGeant4Factory; -import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -27,17 +23,10 @@ public TrackListFinder() { /** * * @param cands the list of track candidates - * @param svt_geo the svt geometry - * @param bmt_geo - * @param ctof_geo - * @param cnd_geo * @param cvtSwim * @return the list of selected tracks */ - public static List getTracks(List cands, - SVTGeometry svt_geo, BMTGeometry bmt_geo, - CTOFGeant4Factory ctof_geo, Detector cnd_geo, - Swim cvtSwim) { + public static List getTracks(List cands, Swim cvtSwim) { List tracks = new ArrayList<>(); if (cands.isEmpty()) { System.err.print("Error no tracks found"); @@ -71,7 +60,7 @@ public static List getTracks(List cands, } TrajectoryFinder trjFind = new TrajectoryFinder(); - Trajectory traj = trjFind.findTrajectory(trk, svt_geo, bmt_geo, ctof_geo, cnd_geo, cvtSwim, "final"); + Trajectory traj = trjFind.findTrajectory(trk, cvtSwim, "final"); trk.set_Trajectory(traj.get_Trajectory()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index d31e1f903..f272a7af6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -18,8 +18,8 @@ import org.jlab.rec.cvt.svt.SVTParameters; public class TrackSeeder { - SVTGeometry sgeo = null; - BMTGeometry bgeo = null; + SVTGeometry sgeo = Constants.SVTGEOMETRY; + BMTGeometry bgeo = Constants.BMTGEOMETRY; double bfield; int NBINS = 36; @@ -33,9 +33,7 @@ public class TrackSeeder { List Ws ; public boolean unUsedHitsOnly = false; - public TrackSeeder(SVTGeometry sgeo, BMTGeometry bgeo, Swim swimmer) { - this.sgeo = sgeo; - this.bgeo = bgeo; + public TrackSeeder(Swim swimmer) { float[] b = new float[3]; swimmer.BfieldLab(0, 0, 0, b); this.bfield = Math.abs(b[2]); @@ -320,7 +318,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { for(Seed mseed : seedScan) { boolean fitStatus = false; if(mseed.get_Crosses().size()>=3) - fitStatus = mseed.fit(this.sgeo, this.bgeo, Constants.SEEDFITITERATIONS, false, this.bfield); + fitStatus = mseed.fit(Constants.SEEDFITITERATIONS, false, this.bfield); if (fitStatus) { List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(mseed, bmtC_crosses); BMTmatches.clear(); @@ -333,7 +331,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { double chi2_Line = Double.POSITIVE_INFINITY; for (Seed bseed : BMTmatches) { //refit using the BMT - fitStatus = bseed.fit(this.sgeo, this.bgeo, Constants.SEEDFITITERATIONS, false, this.bfield); + fitStatus = bseed.fit(Constants.SEEDFITITERATIONS, false, this.bfield); if (fitStatus && bseed.get_circleFitChi2PerNDF() findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) matches.clear(); if (BMTCcrosses.get(0).size() > 0 && i1 < BMTCcrosses.get(0).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1), bgeo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(0).get(i1))) { matches.add(BMTCcrosses.get(0).get(i1)); } } if (BMTCcrosses.get(1).size() > 0 && i2 < BMTCcrosses.get(1).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2), bgeo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(1).get(i2))) { matches.add(BMTCcrosses.get(1).get(i2)); } } if (BMTCcrosses.get(2).size() > 0 && i3 < BMTCcrosses.get(2).size()) { - if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3), bgeo)) { + if (this.passCcross(trkCand, BMTCcrosses.get(2).get(i3))) { matches.add(BMTCcrosses.get(2).get(i3)); } } @@ -615,17 +613,17 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) return outputSeeds; } - private boolean passCcross(Seed trkCand, Cross bmt_Ccross, BMTGeometry bmt_geo) { + private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { boolean pass = false; double dzdrsum = trkCand.get_Helix().get_tandip(); double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = bmt_geo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); + double r_bmt = bgeo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); Point3D phiHelixAtSurf = trkCand.get_Helix().getPointAtRadius(r_bmt); //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) // != bmt_Ccross.get_Sector()) - int sector = bmt_geo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); + int sector = bgeo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); if(sector!= bmt_Ccross.get_Sector() || sector ==0){ return false; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index e7f79d999..f1924f82f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -15,14 +15,12 @@ import org.jlab.rec.cvt.svt.SVTGeometry; public class TrackSeederCA { - SVTGeometry sgeo = null; - BMTGeometry bgeo = null; + SVTGeometry sgeo = Constants.SVTGEOMETRY; + BMTGeometry bgeo = Constants.BMTGEOMETRY; double bfield; - public TrackSeederCA(SVTGeometry sgeo, BMTGeometry bgeo, Swim swimmer) { - this.sgeo = sgeo; - this.bgeo = bgeo; + public TrackSeederCA(Swim swimmer) { float[] b = new float[3]; swimmer.BfieldLab(0, 0, 0, b); this.bfield = Math.abs(b[2]); @@ -122,7 +120,7 @@ public List> getCAcandidates(List nodes) { if( cand.get(0).get_plane().equalsIgnoreCase("XY")) { if( candlen > 2 ){ Seed seed = new Seed(getCrossFromCells(cand)); - if(seed.fit(sgeo, bgeo, 2, false, bfield)) { + if(seed.fit(2, false, bfield)) { cellCands.add(cand); for( Cell n : cand ) { @@ -188,7 +186,7 @@ public List runCAMaker( String plane, int nepochs, ArrayList crs){ camaker.set_aCvsR(90.); } - camaker.createCells(crs, bgeo); + camaker.createCells(crs); camaker.findNeigbors(); camaker.evolve( nepochs ); return camaker.getNodes(); @@ -239,7 +237,7 @@ public List findSeed(List svt_crosses, List bmt_crosses) { // Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters // Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, Constants.SEEDFITITERATIONS, false, swimmer); Seed candSeed = new Seed(seedCrosses.get(s)); - boolean fitStatus = candSeed.fit(sgeo, bgeo, Constants.SEEDFITITERATIONS, false, bfield); + boolean fitStatus = candSeed.fit(Constants.SEEDFITITERATIONS, false, bfield); if (fitStatus && candSeed.isGood()) { cands.add(candSeed); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index a334ee8a2..ccb2bc3ba 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -9,10 +9,8 @@ import java.util.Map; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.geant4.v2.CTOFGeant4Factory; import org.jlab.detector.hits.CTOFDetHit; import org.jlab.detector.hits.DetHit; -import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -45,10 +43,7 @@ public TrajectoryFinder() { * @param isFinal * @return a trajectory object */ - public Trajectory findTrajectory(Track trk, - SVTGeometry svt_geo, BMTGeometry bmt_geo, - CTOFGeant4Factory ctof_geo, Detector cnd_geo, - Swim swimmer, String isFinal) { + public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { Helix helix = trk.get_helix(); ArrayList candCrossList = trk; if(helix ==null) @@ -103,9 +98,9 @@ public Trajectory findTrajectory(Track trk, for (int a = 0; a < Sectors.length; a++) { if (Sectors[a] == 0) { - Point3D I = helix.getPointAtRadius(svt_geo.getLayerRadius(a+1)); + Point3D I = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(a+1)); - int sec = svt_geo.getSector(a+1, I); + int sec = Constants.SVTGEOMETRY.getSector(a+1, I); Sectors[a] = sec; } @@ -143,8 +138,8 @@ public Trajectory findTrajectory(Track trk, if(sector == -1) continue; - Vector3D n = svt_geo.getNormal(layer, sector); - Point3D p = svt_geo.getModule(layer, sector).origin(); + Vector3D n = Constants.SVTGEOMETRY.getNormal(layer, sector); + Point3D p = Constants.SVTGEOMETRY.getModule(layer, sector).origin(); Point3D pm = new Point3D(p.x()/10, p.y()/10, p.z()/10); inters = swimmer.SwimPlane(n, pm, Constants.SWIMACCURACYSVT/10); if(inters==null) break; @@ -156,11 +151,11 @@ public Trajectory findTrajectory(Track trk, stVec.set_SurfaceSector(sector); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); // this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); - Vector3D localDir = svt_geo.getLocalTrack(layer, sector, dir); + Vector3D localDir = Constants.SVTGEOMETRY.getLocalTrack(layer, sector, dir); stVec.set_TrkPhiAtSurface(dir.phi()); stVec.set_TrkThetaAtSurface(dir.theta()); - stVec.set_TrkToModuleAngle(svt_geo.getLocalAngle(layer, sector, dir)); - stVec.set_CalcCentroidStrip(svt_geo.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); + stVec.set_TrkToModuleAngle(Constants.SVTGEOMETRY.getLocalAngle(layer, sector, dir)); + stVec.set_CalcCentroidStrip(Constants.SVTGEOMETRY.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); stVec.set_Path(path*10); stVec.set_ID(trk.get_Id()); stateVecs.add(stVec); @@ -194,7 +189,7 @@ public Trajectory findTrajectory(Track trk, inters = null; path = 0; //BMT - for (int l = SVTGeometry.NLAYERS; l < SVTGeometry.NLAYERS + bmt_geo.getNLayers(); l++) { + for (int l = SVTGeometry.NLAYERS; l < SVTGeometry.NLAYERS + Constants.BMTGEOMETRY.getNLayers(); l++) { // re-initilize swimmer from last surface if(inters!=null) { double intersPhi = Math.atan2(inters[4], inters[3]); @@ -203,16 +198,16 @@ public Trajectory findTrajectory(Track trk, } if(inters!=null || l==SVTGeometry.NLAYERS) { // don't swim if previous layers was not reached int layer = l - SVTGeometry.NLAYERS + 1; - int region = bmt_geo.getRegion(layer); + int region = Constants.BMTGEOMETRY.getRegion(layer); // RDV: tried using this to determine the sector but t is giving bogus number //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); - double radius = bmt_geo.getRadiusMidDrift(layer)/10; + double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(layer)/10; inters = swimmer.SwimRho(radius, Constants.SWIMACCURACYBMT/10); if(inters==null) break; - int sector = bmt_geo.getSector(0, Math.atan2(inters[1],inters[0])); + int sector = Constants.BMTGEOMETRY.getSector(0, Math.atan2(inters[1],inters[0])); - Line3D axis = bmt_geo.getAxis(layer, sector); + Line3D axis = Constants.BMTGEOMETRY.getAxis(layer, sector); Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, @@ -237,10 +232,10 @@ public Trajectory findTrajectory(Track trk, stVec.set_Path(path*10); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); Point3D pos = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); - stVec.set_TrkPhiAtSurface(bmt_geo.getThetaZ(layer, sector, pos, dir)); - stVec.set_TrkThetaAtSurface(bmt_geo.getThetaC(layer, sector, pos, dir)); + stVec.set_TrkPhiAtSurface(Constants.BMTGEOMETRY.getThetaZ(layer, sector, pos, dir)); + stVec.set_TrkThetaAtSurface(Constants.BMTGEOMETRY.getThetaC(layer, sector, pos, dir)); //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); - stVec.set_CalcCentroidStrip(bmt_geo.getCstrip(region, + stVec.set_CalcCentroidStrip(Constants.BMTGEOMETRY.getCstrip(region, new Point3D(stVec.x(),stVec.y(),stVec.z()))); stVec.set_Path(path*10); stVec.set_ID(trk.get_Id()); @@ -261,13 +256,13 @@ public Trajectory findTrajectory(Track trk, } } // CTOF - if(ctof_geo!=null && inters!=null) { // don't swim to CTOF if swimming to BMT failed + if(Constants.CTOFGEOMETRY!=null && inters!=null) { // don't swim to CTOF if swimming to BMT failed // reinitialize swimmer based on last BMT layer double intersPhi = Math.atan2(inters[4], inters[3]); double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; // swim to CTOF - double radius = ctof_geo.getRadius(1); + double radius = Constants.CTOFGEOMETRY.getRadius(1); inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius, Constants.SWIMACCURACYCD/10); if(inters!=null) { // update parameters @@ -289,8 +284,8 @@ public Trajectory findTrajectory(Track trk, } } // CND - if(cnd_geo!=null && inters!=null) { // don't swim to CND if swimming to CTOF failed - for(int ilayer=0; ilayer candCrossList, - SVTGeometry svt_geo, BMTGeometry bmt_geo) { + public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList) { Trajectory traj = new Trajectory(ray); traj.set_Id(id); @@ -421,7 +415,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList ArrayList stateVecs = new ArrayList(); - double[][][] SVTIntersections = calc_trackIntersSVT(ray, svt_geo); + double[][][] SVTIntersections = calc_trackIntersSVT(ray); for (int l = 0; l < SVTGeometry.NLAYERS; l++) { for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { @@ -481,7 +475,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList if (clsOnTrk != null && clsOnTrk.get_Layer() == l + 1) { setHitResolParams("SVT", clsOnTrk.get_Sector(), clsOnTrk.get_Layer(), clsOnTrk, - stVec, svt_geo, bmt_geo, traj.isFinal); + stVec, traj.isFinal); } } @@ -489,7 +483,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList } } - double[][][] BMTIntersections = calc_trackIntersBMT(ray, bmt_geo, BMTConstants.STARTINGLAYR); + double[][][] BMTIntersections = calc_trackIntersBMT(ray, BMTConstants.STARTINGLAYR); for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { //hemisphere 1-2 @@ -502,7 +496,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); - int SectorTrackIntersSurf = bmt_geo.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); + int SectorTrackIntersSurf = Constants.BMTGEOMETRY.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; double trkToMPlnAngl = BMTIntersections[l][h][5]; @@ -554,7 +548,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList // calculate the hit residuals // CHECK THIS ........ this.setHitResolParams("BMT", c.get_Sector(), c.get_Cluster1().get_Layer(), c.get_Cluster1(), - stVec, svt_geo, bmt_geo, traj.isFinal); + stVec, traj.isFinal); } if (c.get_Type()==BMTType.Z) { //Z-detector measuring phi @@ -566,7 +560,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList // calculate the hit residuals this.setHitResolParams("BMT", c.get_Cluster1().get_Sector(), c.get_Cluster1().get_Layer(), c.get_Cluster1(), - stVec, svt_geo, bmt_geo, traj.isFinal); + stVec, traj.isFinal); } } @@ -628,12 +622,10 @@ private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sec * @param layer * @param cluster * @param stVec stateVec - * @param svt_geo - * @param bmt_geo * @param trajFinal */ public void setHitResolParams(String detector, int sector, int layer, Cluster cluster, - StateVec stVec, SVTGeometry svt_geo, BMTGeometry bmt_geo, boolean trajFinal) { + StateVec stVec, boolean trajFinal) { if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = cluster.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); @@ -649,7 +641,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl // System.out.println(d+" calc "+l.distance(new Point3D(stVec.x(), stVec.y(), stVec.z())).length()+" d "+doca2Cls); for (Hit hit : cluster) { double doca1 = hit.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); - double sigma1 = svt_geo.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); hit.set_stripResolutionAtDoca(sigma1); hit.set_docaToTrk(doca1); hit.set_TrkgStatus(1); @@ -660,8 +652,8 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } if (detector.equalsIgnoreCase("BMT")) { cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); - Point3D offset = bmt_geo.getOffset(cluster.get_Layer(), cluster.get_Sector()); - Vector3D rotation = bmt_geo.getRotation(cluster.get_Layer(), cluster.get_Sector()); + Point3D offset = Constants.BMTGEOMETRY.getOffset(cluster.get_Layer(), cluster.get_Sector()); + Vector3D rotation = Constants.BMTGEOMETRY.getRotation(cluster.get_Layer(), cluster.get_Sector()); double ce = cluster.get_Centroid(); Point3D p = new Point3D(stVec.x(), stVec.y(), stVec.z()); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z @@ -681,19 +673,19 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi int bsector = cluster.get_Sector(); int blayer = cluster.get_Layer(); - double cxh = Math.cos(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double cyh = Math.sin(cluster.get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double phic = bmt_geo.getPhi(blayer, bsector, new Point3D(cxh,cyh,0)); - double phit = bmt_geo.getPhi(blayer, bsector, p); - double doca2Cls = (phic-phit)*bmt_geo.getRadiusMidDrift(blayer); + double cxh = Math.cos(cluster.get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double cyh = Math.sin(cluster.get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double phic = Constants.BMTGEOMETRY.getPhi(blayer, bsector, new Point3D(cxh,cyh,0)); + double phit = Constants.BMTGEOMETRY.getPhi(blayer, bsector, p); + double doca2Cls = (phic-phit)*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); cluster.set_CentroidResidual(doca2Cls); for (Hit h1 : cluster) { - double xh = Math.cos(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double yh = Math.sin(h1.get_Strip().get_Phi())*bmt_geo.getRadiusMidDrift(blayer); - double hphic = bmt_geo.getPhi(blayer, bsector, new Point3D(xh,yh,0)); - double hphit = bmt_geo.getPhi(blayer, bsector, p); - double doca1 = (hphic-hphit)*bmt_geo.getRadiusMidDrift(blayer); + double xh = Math.cos(h1.get_Strip().get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double yh = Math.sin(h1.get_Strip().get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double hphic = Constants.BMTGEOMETRY.getPhi(blayer, bsector, new Point3D(xh,yh,0)); + double hphit = Constants.BMTGEOMETRY.getPhi(blayer, bsector, p); + double doca1 = (hphic-hphit)*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip().get_Strip()) cluster.set_SeedResidual(doca1); @@ -707,7 +699,7 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl } } - public static double[][][] calc_trackIntersBMT(Ray ray, BMTGeometry bmt_geo, int start_layer) { + public static double[][][] calc_trackIntersBMT(Ray ray, int start_layer) { //[l][hemisphere], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip; hemisphere = [1]top or [0]bottom double[][][] result = new double[6][2][7]; @@ -723,12 +715,12 @@ public static double[][][] calc_trackIntersBMT(Ray ray, BMTGeometry bmt_geo, int //Layer 1-6: Line3D line = ray.toLine(); for (int l = start_layer - 1; l < 6; l++) { - for(int s=0; s trajs = new ArrayList<>(); - int ntraj = bmt_geo.getTileSurface(layer, sector).intersection(line, trajs); + int ntraj = Constants.BMTGEOMETRY.getTileSurface(layer, sector).intersection(line, trajs); // System.out.println(layer + " " + sector); if(ntraj>0) { for(int i=0; i0) local.negative(); local.rotateX(Math.toRadians(90)); result[l][s][0] = traj.x(); @@ -844,7 +836,7 @@ public static double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { result[l][s][3] = Math.toDegrees(local.phi()); result[l][s][4] = Math.toDegrees(local.theta()); result[l][s][5] = Math.toDegrees(Math.acos(local.x())); - result[l][s][6] = svt_geo.calcNearestStrip(traj.x(), traj.y(), traj.z(), layer, sector); + result[l][s][6] = Constants.SVTGEOMETRY.calcNearestStrip(traj.x(), traj.y(), traj.z(), layer, sector); } } } @@ -855,7 +847,7 @@ public static double[][][] calc_trackIntersSVT(Ray ray, SVTGeometry svt_geo) { @Deprecated public double[] getIntersectionTrackWithSVTModule(int s, int l, double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2, SVTGeometry geo) { + double _yzslope2) { // array [][][][] =[x][y][z][stripCentroid] double[] inters = new double[4]; inters[0] = Double.NaN; @@ -871,8 +863,8 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, double z_plus = _yzslope2 * y_plus + _yzinterc2; double z_minus = _yzslope2 * y_minus + _yzinterc2; - Vector3D n = geo.getNormal(l+1, s+1); - Line3D mod = geo.getModule(l+1, s+1); + Vector3D n = Constants.SVTGEOMETRY.getNormal(l+1, s+1); + Line3D mod = Constants.SVTGEOMETRY.getModule(l+1, s+1); Point3D Or = mod.origin(); Point3D En = mod.end(); @@ -887,7 +879,7 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, double y = y_minus+t*u.y(); double z = z_minus+t*u.z(); - double strp = geo.calcNearestStrip(inters[0], inters[1], inters[2], l + 1, s + 1); + double strp = Constants.SVTGEOMETRY.calcNearestStrip(inters[0], inters[1], inters[2], l + 1, s + 1); if (strp>0 && strp<257) { inters[0] = y * _yxslope2 + _yxinterc2; @@ -903,7 +895,7 @@ public double[] getIntersectionTrackWithSVTModule(int s, int l, @Deprecated private double[][] getIntersectionTrackWithBMTModules(int l, double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2, BMTGeometry geo) { + double _yzslope2) { // array [][][][] =[x][y][z][stripCentroid] double[][] inters = new double[2][4]; @@ -922,7 +914,7 @@ private double[][] getIntersectionTrackWithBMTModules(int l, int lyer = l+1; - double radius = geo.getRadiusMidDrift(lyer); + double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(lyer); double y_minus = -300; double y_plus = 350; @@ -935,7 +927,7 @@ private double[][] getIntersectionTrackWithBMTModules(int l, Point3D trkOr = new Point3D(x_plus,y_plus,z_plus); Point3D trkEn = new Point3D(x_minus,y_minus,z_minus); - List intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, null, null,geo); + List intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, null, null); Point3D top = intersNominal.get(0); Point3D bottom = intersNominal.get(1); @@ -947,34 +939,34 @@ private double[][] getIntersectionTrackWithBMTModules(int l, int bottomsec = 0; int topstp = 0; int bottomstp = 0; - if(top.toVector3D().mag()>0 && geo.getSector(lyer, top.toVector3D().phi())>0) { - topsec = geo.getSector(lyer, top.toVector3D().phi()); - trkOr = geo.toLocal(trkOr, lyer, topsec); - trkEn = geo.toLocal(trkEn, lyer, topsec); - intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); + if(top.toVector3D().mag()>0 && Constants.BMTGEOMETRY.getSector(lyer, top.toVector3D().phi())>0) { + topsec = Constants.BMTGEOMETRY.getSector(lyer, top.toVector3D().phi()); + trkOr = Constants.BMTGEOMETRY.toLocal(trkOr, lyer, topsec); + trkEn = Constants.BMTGEOMETRY.toLocal(trkEn, lyer, topsec); + intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation); top = intersNominal.get(0); - topstp = geo.getStrip( l + 1, topsec, top); + topstp = Constants.BMTGEOMETRY.getStrip( l + 1, topsec, top); } - if(bottom.toVector3D().mag()>0 && geo.getSector(lyer, bottom.toVector3D().phi())>0) { - bottomsec = geo.getSector(lyer, bottom.toVector3D().phi()); - trkOr = geo.toLocal(trkOr, lyer, bottomsec); - trkEn = geo.toLocal(trkEn, lyer, bottomsec); - intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation, geo); + if(bottom.toVector3D().mag()>0 && Constants.BMTGEOMETRY.getSector(lyer, bottom.toVector3D().phi())>0) { + bottomsec = Constants.BMTGEOMETRY.getSector(lyer, bottom.toVector3D().phi()); + trkOr = Constants.BMTGEOMETRY.toLocal(trkOr, lyer, bottomsec); + trkEn = Constants.BMTGEOMETRY.toLocal(trkEn, lyer, bottomsec); + intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation); bottom = intersNominal.get(1); - bottomstp = geo.getStrip( l + 1, bottomsec, bottom); + bottomstp = Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, bottom); } if(top.toVector3D().mag()>0) { inters_top[0] = top.x(); inters_top[1] = top.y(); inters_top[2] = top.z(); - inters_top[3] = geo.getStrip( l + 1, bottomsec, top); + inters_top[3] = Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, top); } if(bottom.toVector3D().mag()>0) { inters_bottom[0] = bottom.x(); inters_bottom[1] = bottom.y(); inters_bottom[2] = bottom.z(); - inters_bottom[3]= geo.getStrip( l + 1, bottomsec, bottom); + inters_bottom[3]= Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, bottom); } inters[0] = inters_top; @@ -1004,7 +996,7 @@ public void hitsToArray(List hits2) { } - private List getTrkInMiddleOfBar(int id, double[] inters, CTOFGeant4Factory ctof_geo) { + private List getTrkInMiddleOfBar(int id, double[] inters) { List stateVecs = new ArrayList(); double p = Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5]); @@ -1018,7 +1010,7 @@ private List getTrkInMiddleOfBar(int id, double[] inters, CTOFGeant4Fa Line3d line = new Line3d(new Vector3d(x,y,z), new Vector3d(x+5*ux,y+5*uy, z+5*uz)); - List trkHits = ctof_geo.getIntersections(line); + List trkHits = Constants.CTOFGEOMETRY.getIntersections(line); if (trkHits != null && trkHits.size() > 0) { for (DetHit hit : trkHits) { CTOFDetHit trkHit = new CTOFDetHit(hit); @@ -1053,9 +1045,9 @@ private List getTrkInMiddleOfBar(int id, double[] inters, CTOFGeant4Fa return stateVecs; } - private boolean checkBMTAcceptance(Point3D ipos, int lyer, BMTGeometry geo) { + private boolean checkBMTAcceptance(Point3D ipos, int lyer) { //1 mm tolerance - if(ipos.z()geo.getZmin(lyer)+1.0 ) { + if(ipos.z()Constants.BMTGEOMETRY.getZmin(lyer)+1.0 ) { return true; } else { return false; @@ -1064,7 +1056,7 @@ private boolean checkBMTAcceptance(Point3D ipos, int lyer, BMTGeometry geo) { @Deprecated private List getIntersBMT(int lyer, double radius, double x_minus, double y_minus, double z_minus, - Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation, BMTGeometry geo) { + Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation) { List result = new ArrayList(); Line3D trk = new Line3D(trkOr, trkEn); @@ -1089,16 +1081,16 @@ private List getIntersBMT(int lyer, double radius, double x_minus, doub Point3D ipos = new Point3D(x_minus+tneg*Vx,y_minus+tneg*Vy,z_minus+tneg*Vz); Point3D ineg = new Point3D(x_minus+tpos*Vx,y_minus+tpos*Vy,z_minus+tpos*Vz); - if(this.checkBMTAcceptance(ipos, lyer,geo)) { + if(this.checkBMTAcceptance(ipos, lyer)) { if(offset!=null && rotation!=null) - geo.putInFrame(ipos, offset, rotation, false); + Constants.BMTGEOMETRY.putInFrame(ipos, offset, rotation, false); } else { ipos.set(0,0,0); } - if(this.checkBMTAcceptance(ineg, lyer,geo)) { + if(this.checkBMTAcceptance(ineg, lyer)) { if(offset!=null && rotation!=null) - geo.putInFrame(ineg, offset, rotation, false); + Constants.BMTGEOMETRY.putInFrame(ineg, offset, rotation, false); } else { ineg.set(0,0,0); } From 7c15a374a0f1f76ec55c0e9fcaf56acd34ec9dbe Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Thu, 13 Jan 2022 00:18:40 +0100 Subject: [PATCH 265/291] Updated treatment of multiple scattering: - added radiation length information for SVT passive material in jcsg SVTConstants class. - introduced methods in SVTGeometry and BMTGeometry classes to create Surfaces for both active volumes and passive ones (tungsten shield, SVT faraday cage) - new Measurements class generating collection of measurement surfaces for the KF, with all layers, passive and active, including active layers with no clusters. Handles both tracks-from-target and cosmics - propagated usage throughout the CVT code - update clas-tracking accordingly; updated computation of Q matrix to account for track direction when calculating the material budget in cosmic case; added method to calculate track angle with respect to the normal to the surface --- .../clas/tracking/kalmanfilter/AKFitter.java | 8 +- .../clas/tracking/kalmanfilter/AMeasVecs.java | 7 +- .../tracking/kalmanfilter/AStateVecs.java | 24 + .../clas/tracking/kalmanfilter/Surface.java | 16 +- .../kalmanfilter/helical/KFitter.java | 8 +- .../kalmanfilter/helical/StateVecs.java | 41 +- .../kalmanfilter/straight/KFitter.java | 12 +- .../kalmanfilter/straight/StateVecs.java | 56 +-- .../clas/tracking/utilities/MatrixOps.java | 2 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 23 +- .../org/jlab/rec/cvt/cluster/Cluster.java | 38 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 2 +- .../rec/cvt/services/CosmicTracksRec.java | 7 +- .../jlab/rec/cvt/services/RecUtilities.java | 32 +- .../rec/cvt/services/TracksFromTargetRec.java | 10 +- .../org/jlab/rec/cvt/svt/SVTGeometry.java | 53 +- .../org/jlab/rec/cvt/track/Measurements.java | 461 ++++++++++++++++++ .../org/jlab/rec/cvt/track/StraightTrack.java | 29 +- .../java/org/jlab/rec/cvt/track/Track.java | 13 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 2 +- 20 files changed, 672 insertions(+), 172 deletions(-) create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index edc2257de..f60dd96a4 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -112,8 +112,12 @@ public double calc_chi2(AStateVecs sv, AMeasVecs mv) { int ndf = this.NDF0; for(int k = 0; k< mv.measurements.size()-1; k++) { - if(mv.measurements.get(k+1).skip==false && sv.trackTraj.get(k)!=null) { - sv.transport(k, k+1, mv, swimmer); + if(sv.trackTraj.get(k)==null) { + chisq=Double.NaN; + break; + } + sv.transport(k, k+1, mv, swimmer); + if(!mv.measurements.get(k+1).skip) { double dh = mv.dh(k+1, sv.trackTraj.get(k+1)); double error = mv.measurements.get(k+1).error; chisq += dh*dh / error/error; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java index aa944a966..783d2efb7 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AMeasVecs.java @@ -26,8 +26,7 @@ public void setMeasVecs(List measSurfaces) { for(int i = 0; i < measSurfaces.size(); i++) { MeasVec mvec = new MeasVec(); mvec.k = i ; - mvec.layer = measSurfaces.get(i).getLayer(); - mvec.sector = measSurfaces.get(i).getSector(); + mvec.layer = measSurfaces.get(i).getIndex(); mvec.surface = measSurfaces.get(i); if(mvec.surface.getError()!=0) mvec.error = mvec.surface.getError(); @@ -205,10 +204,10 @@ public double h(int k, StateVec stateVec) { public class MeasVec implements Comparable { public Surface surface; public int layer = -1; - public int sector = -1; public double error = 1; public int k = -1; - public boolean skip = false; + public boolean passive = false; + public boolean skip = false; // this is for multiple scattering estimates in track public double l_over_X0; //this is for energy loss diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index e28a56c89..e41a2ef14 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -9,6 +9,7 @@ import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.helical.KFitter; import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.geom.prim.Point3D; public abstract class AStateVecs { @@ -118,6 +119,29 @@ public double[][] addProcessNoise(double[][] C, double[][] Q) { return result; } + public double getLocalDirAtMeasSite(StateVec vec, MeasVec mv) { + if(mv.surface==null) + return 0; + else if(mv.surface.plane==null && mv.surface.cylinder==null) + return 0; + else { + Point3D pos = new Point3D(vec.x, vec.y, vec.z); + Vector3D dir = new Vector3D(vec.px, vec.py, vec.pz).asUnit(); + if(mv.surface.plane!=null) { + Vector3D norm = mv.surface.plane.normal(); + return Math.abs(norm.dot(dir)); + } + else if(mv.surface.cylinder!=null) { + mv.surface.toLocal().apply(pos); + mv.surface.toLocal().apply(dir); + Vector3D norm = pos.toVector3D().asUnit(); + return Math.abs(norm.dot(dir)); + } + return 0; + } + } + + public abstract double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv); public abstract double[][] F(StateVec ivec, StateVec fvec); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java index 47b8bdebb..54bb789b8 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Surface.java @@ -26,6 +26,7 @@ public class Surface implements Comparable { public Arc3D arc; public Strip strip; private double error; + private int index; private int layer; private int sector; // this is for multiple scattering estimates in track @@ -36,6 +37,7 @@ public class Surface implements Comparable { // this is for swimming public double swimAccuracy; public boolean notUsedInFit = false; + public boolean passive = false; public double hemisphere = 1; public Surface(Plane3D plane3d, Point3D refrPoint, Point3D c1, Point3D c2, double accuracy) { @@ -114,7 +116,9 @@ public Surface(Point3D endPoint1, Point3D endPoint2, double accuracy) { @Override public String toString() { String s = "Surface: "; - s = s + String.format("Type=%s Layer=%d Sector=%d Emisphere=%.1f X0=%.4f Z/AL=%.4f Error=%.4f",this.type.name(),this.getLayer(),this.getSector(),this.hemisphere,this.getl_over_X0(),this.getZ_over_A_times_l(),this.getError()); + s = s + String.format("Type=%s Index=%d Layer=%d Sector=%d Emisphere=%.1f X0=%.4f Z/AL=%.4f Error=%.4f Skip=%b Passive=%b", + this.type.name(), this.getIndex(),this.getLayer(),this.getSector(),this.hemisphere,this.getl_over_X0(), + this.getZ_over_A_times_l(),this.getError(),this.notUsedInFit, this.passive); if(type==Type.PLANEWITHSTRIP) { s = s + "\n\t" + this.plane.toString(); s = s + "\n\t" + this.finitePlaneCorner1.toString(); @@ -145,6 +149,14 @@ public void setError(double error) { this.error = error; } + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + /** * @return the layer */ @@ -224,7 +236,7 @@ public void setTransformation(Transformation3D transform) { @Override public int compareTo(Surface o) { - if (this.layer > o.layer) { + if (this.index > o.index) { return 1; } else { return -1; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 0287c63bb..8a1ac8754 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -95,9 +95,11 @@ public void setTrajectory(AStateVecs s, AMeasVecs mv) { for (int k = 1; k < s.trackTraj.size(); k++) { int layer = mv.measurements.get(k).layer; double resi = mv.dh(k, s.trackTraj.get(k)); - TrjPoints.put(layer, new HitOnTrack(layer, s.trackTraj.get(k), resi)); - if(mv.measurements.get(k).skip) - TrjPoints.get(layer).isMeasUsed = false; + if(!mv.measurements.get(k).surface.passive) { + TrjPoints.put(layer, new HitOnTrack(layer, s.trackTraj.get(k), resi)); + if(mv.measurements.get(k).skip) + TrjPoints.get(layer).isMeasUsed = false; + } //System.out.println(" Traj layer "+layer+" x "+TrjPoints.get(layer).x+" y "+TrjPoints.get(layer).y+" z "+TrjPoints.get(layer).z); } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index d29187fac..60e515857 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -210,39 +210,34 @@ public double[][] F(StateVec iVec, StateVec fVec) { @Override public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { double[][] Q = new double[5][5]; - // if (iVec.k % 2 == 1 && dir > 0) { + int dir = f-i; + double t_ov_X0 = 0; if(dir>0) { - for(int k=i+1; k<=f; k++) t_ov_X0 += mv.measurements.get(k).l_over_X0; + for(int k=i; kf; k--) t_ov_X0 += mv.measurements.get(k).l_over_X0; + for(int k=i; k>f; k--) { + double cosEntranceAngle = this.getLocalDirAtMeasSite(iVec, mv.measurements.get(k)); + t_ov_X0 += mv.measurements.get(k).l_over_X0/cosEntranceAngle; +// System.out.println("From " + i + " to " + f + " including material from surface " + k + " with X0 = " + mv.measurements.get(k).l_over_X0 + " / " + cosEntranceAngle); +// System.out.println(mv.measurements.get(k).surface.toString()); + } } if (t_ov_X0>0) { - Vector3D trkDir = this.P(iVec.k).asUnit(); - Vector3D trkPos = this.X(iVec.k); - double x = trkPos.x(); - double y = trkPos.y(); - double z = trkPos.z(); - double ux = trkDir.x(); - double uy = trkDir.y(); - double uz = trkDir.z(); - - double cosEntranceAngle = Math.abs((x * ux + y * uy + z * uz) / Math.sqrt(x * x + y * y + z * z)); - - double pt = Math.abs(1. / iVec.kappa); - double pz = pt * iVec.tanL; - double p = Math.sqrt(pt * pt + pz * pz); + double p = Math.sqrt(iVec.px*iVec.px + iVec.py*iVec.py + iVec.pz*iVec.pz); + if(this.straight) p = 1; double mass = piMass; // assume given mass hypothesis - double beta = p / Math.sqrt(p * p + mass * mass); // use particle momentum - t_ov_X0 = t_ov_X0 / cosEntranceAngle; + double beta = p / Math.sqrt(p * p + mass * mass); // Highland-Lynch-Dahl formula - double sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* - (1 + 0.038 * Math.log(t_ov_X0)); - //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* - // (1 + Math.log(t_ov_X0)/9.); + double sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)*(1 + 0.038 * Math.log(t_ov_X0)); Q = new double[][]{ {0, 0, 0, 0, 0}, {0, sctRMS*sctRMS * (1 + iVec.tanL * iVec.tanL), 0, 0, 0}, diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index a467d0b91..fc320087a 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -78,14 +78,14 @@ else if(newchisq < this.chi2) { @Override public void setTrajectory(AStateVecs sv, AMeasVecs mv) { TrjPoints = new HashMap<>(); - for (int k = 0; k < sv.trackTraj.size()-1; k++) { - StateVec stv = sv.trackTraj.get(k+1); - stv.resi = mv.dh(k+1, stv); + for (int k = 1; k < sv.trackTraj.size(); k++) { + StateVec stv = sv.trackTraj.get(k); + stv.resi = mv.dh(k, stv); if(Double.isNaN(stv.resi)) { - mv.measurements.get(k+1).skip = true; + mv.measurements.get(k).skip = true; } - else { - int layer = mv.measurements.get(k+1).layer; + else if(!mv.measurements.get(k).surface.passive) { + int layer = mv.measurements.get(k).layer; TrjPoints.put(layer, new HitOnTrack(layer, stv.x, stv.y, stv.z, stv.px, stv.py, stv.pz, stv.resi)); if(mv.measurements.get(k).skip) TrjPoints.get(layer).isMeasUsed = false; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index 6cf3b2454..faca9c9c9 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -92,43 +92,35 @@ public double[][] F(StateVec iVec, StateVec fVec) { @Override public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { double[][] Q = new double[5][5]; - int dir = f-i; - if (dir >0 ) { - Vector3D trkDir = this.P(iVec.k).asUnit(); - Vector3D trkPos = this.X(iVec.k); - double x = trkPos.x(); - double y = trkPos.y(); - double z = trkPos.z(); - double ux = trkDir.x(); - double uy = trkDir.y(); - double uz = trkDir.z(); - double tx = ux/uy; - double tz = uz/uy; - double cosEntranceAngle = Math.abs((x * ux + y * uy + z * uz) / Math.sqrt(x * x + y * y + z * z)); - - double p = 1; - double sctRMS = 0; - double t_ov_X0 = mv.measurements.get(i).l_over_X0; + + int dir = (int) Math.signum(f-i); + if(dir<0) return Q; + + double t_ov_X0 = 0; + // depending on dir, k increases or decreases + for (int k = i; (k-f)*dir <= 0; k += dir) { + int hemisphere = (int) mv.measurements.get(k).surface.hemisphere; + if(dir*hemisphere>0 && k==f) continue; + if(dir*hemisphere<0 && k==i) continue; + double cosEntranceAngle = 1;//this.getLocalDirAtMeasSite(iVec, mv.measurements.get(k)); + t_ov_X0 += mv.measurements.get(k).l_over_X0 / cosEntranceAngle; + } + + if (t_ov_X0>0) { + double p = 1; double mass = piMass; // assume given mass hypothesis - double beta = 1; // use particle momentum - t_ov_X0 = t_ov_X0 / cosEntranceAngle; - if(t_ov_X0!=0) { + double beta = p / Math.sqrt(p * p + mass * mass); // Highland-Lynch-Dahl formula - sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)* - (1 + 0.038 * Math.log(t_ov_X0)); - //sctRMS = ((0.141)/(beta*PhysicsConstants.speedOfLight()*p))*Math.sqrt(t_ov_X0)* - // (1 + Math.log(t_ov_X0)/9.); - } - double cov_txtx = (1 + tx * tx) * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; - double cov_tztz = (1 + tz * tz) * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; - double cov_txtz = tx * tz * (1 + tx * tx + tz * tz) * sctRMS * sctRMS; - + double sctRMS = (0.0136/(beta*p))*Math.sqrt(t_ov_X0)*(1 + 0.038 * Math.log(t_ov_X0)); + double cov_txtx = (1 + iVec.tx * iVec.tx) * (1 + iVec.tx * iVec.tx + iVec.tz * iVec.tz) * sctRMS * sctRMS; + double cov_tztz = (1 + iVec.tz * iVec.tz) * (1 + iVec.tx * iVec.tx + iVec.tz * iVec.tz) * sctRMS * sctRMS; + double cov_txtz = iVec.tx * iVec.tz * (1 + iVec.tx * iVec.tx + iVec.tz * iVec.tz) * sctRMS * sctRMS; Q = new double[][]{ - {0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, cov_txtx, cov_txtz, 0}, {0, 0, cov_txtz, cov_tztz, 0}, - {0, 0, 0, 0, 0} + {0, 0, 0, 0, 0} }; } return Q; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java index abf11ce71..c1ce8072a 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/MatrixOps.java @@ -128,7 +128,7 @@ public double[][] MatrixTranspose(Object obj1) { for(int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { - result[i][j] = arr1[j][j]; + result[i][j] = arr1[j][i]; } } arr1 = null; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index b4472ecb7..80f74f4c7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -975,36 +975,35 @@ public double getThetaC(int layer, int sector, Point3D trakPos, Vector3D trackDi public List getSurfaces() { List surfaces = new ArrayList<>(); for(int i=1; i<=NLAYERS; i++) - surfaces.add(this.getSurface(i, 1)); + surfaces.add(this.getSurface(i, 1, new Strip(0, 0, 0))); return surfaces; } - public Surface getSurfaceC(int layer, int sector, int stripId, double centroid, double centroidValue, int hemisphere) { - Surface surface = this.getSurface(layer, sector); - surface.hemisphere = hemisphere; - surface.strip = new Strip(stripId, centroid, centroidValue); + public Surface getSurfaceC(int layer, int sector, int stripId, double centroid, double centroidValue) { + Strip strip = new Strip(stripId, centroid, centroidValue); + Surface surface = this.getSurface(layer, sector, strip); return surface; } - public Surface getSurfaceZ(int layer, int sector, int stripId, double centroid, double x, double y, double centroidValue, int hemisphere) { - Surface surface = this.getSurface(layer, sector); - surface.hemisphere = hemisphere; - surface.strip = new Strip(stripId, centroid, x, y, centroidValue); + public Surface getSurfaceZ(int layer, int sector, int stripId, double centroid, double x, double y, double centroidValue) { + Strip strip = new Strip(stripId, centroid, x, y, centroidValue); + Surface surface = this.getSurface(layer, sector, strip); return surface; } - public Surface getSurface(int layer, int sector) { + public Surface getSurface(int layer, int sector, Strip strip) { Surface surface = new Surface(this.getTileSurface(layer, sector), - new Strip(0,0,0), + strip, Constants.SWIMACCURACYBMT); surface.hemisphere = 0; surface.setLayer(layer); surface.setSector(sector); + surface.setTransformation(this.toGlobal(layer, sector)); surface.setError(0); surface.setl_over_X0(this.getToverX0(layer)); surface.setZ_over_A_times_l(this.getZoverA(layer)); surface.setThickness(this.getMaterialThickness(layer)); - surface.notUsedInFit=true; + surface.notUsedInFit=false; return surface; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index b05e21bc5..ae9a3b740 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -674,47 +674,33 @@ public void setTrakInters(Point3D _TrakInters) { this._TrakInters = _TrakInters; } - public Surface measurement(int layerID) { + public Surface measurement() { Surface surface = null; + if(this.get_Detector()==DetectorType.BST) { Point3D endPt1 = this.getLine().origin(); Point3D endPt2 = this.getLine().end(); - org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), - endPt1.x(), endPt1.y(), endPt1.z(), - endPt2.x(), endPt2.y(), endPt2.z()); +// org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), +// endPt1.x(), endPt1.y(), endPt1.z(), +// endPt2.x(), endPt2.y(), endPt2.z()); Plane3D plane = new Plane3D(endPt1, this.getN()); - Line3D module = this.get(0).get_Strip().get_Module(); - surface = new Surface(plane, strp, module.origin(), module.end(), Constants.SWIMACCURACYSVT); + surface = Constants.SVTGEOMETRY.getSurface(this.get_Layer(), this.get_Sector(), this.get_Id(), + this.get_Centroid(), this.getLine()); surface.hemisphere = Math.signum(this.center().y()); - surface.setLayer(layerID); - surface.setSector(this.get_Sector()); surface.setError(this.get_Resolution()); - surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); - surface.setZ_over_A_times_l(this.get(0).get_Strip().getZoverA()*this.get(0).get_Strip().getMatT()); - surface.setThickness(this.get(0).get_Strip().getMatT()); } else { if(this.get_Type()==BMTType.C) { - org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), this.get_CentroidValue()); - surface = new Surface(this.get(0).get_Strip().get_Tile(), strp, Constants.SWIMACCURACYBMT); - double error = this.get_CentroidError(); - surface.setError(error); + surface = Constants.BMTGEOMETRY.getSurfaceC(this.get_Layer(), this.get_Sector(), this.get_Id(), + this.get_Centroid(), this.get_CentroidValue()); } else { Point3D point = new Point3D(this.getLine().midpoint()); this.toLocal().apply(point); - org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), point.x(), point.y(), this.get_CentroidValue()); - surface = new Surface(this.getTile(), strp, Constants.SWIMACCURACYBMT); - double error = this.get_CentroidError();///this.getTile().baseArc().radius(); - surface.setError(error); - + surface = Constants.BMTGEOMETRY.getSurfaceZ(this.get_Layer(), this.get_Sector(), this.get_Id(), + this.get_Centroid(), point.x(), point.y(), this.get_CentroidValue()); } - surface.setTransformation(this.toGlobal()); - surface.setLayer(layerID); - surface.setSector(this.get_Sector()); - surface.setl_over_X0(this.get(0).get_Strip().getToverX0()); - surface.setZ_over_A_times_l(this.get(0).get_Strip().getZoverA()*this.get(0).get_Strip().getMatT()); - surface.setThickness(this.get(0).get_Strip().getMatT()); + surface.setError(this.get_CentroidError()); } return surface; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 6b8b3462e..041efdd86 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -217,7 +217,7 @@ private void loadConfiguration() { if (this.getEngineConfigString("beamSpotConst")!=null) { Constants.setBEAMSPOTCONST(Integer.valueOf(this.getEngineConfigString("beamSpotConst"))); } - System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getBEAMSPOTCONST()+ " (0=no-constraint, 1=seed only, 2=seed and KF"); + System.out.println("["+this.getName()+"] run with beamSpotConst set to "+Constants.getBEAMSPOTCONST()+ " (0=no-constraint, 1=seed only, 2=seed and KF)"); if (this.getEngineConfigString("beamSpotRadius")!=null) { Constants.setRbErr(Double.valueOf(this.getEngineConfigString("beamSpotRadius"))); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index de3ab199d..7d9e8391b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -18,6 +18,7 @@ import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.track.Measurements; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.track.TrackCandListFinder; @@ -83,7 +84,7 @@ public boolean processEvent(DataEvent event, recUtil.CleanupSpuriousCrosses(crosses, null) ; KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.kfMatLib); - + Measurements measures = new Measurements(true, null); List cosmics = new ArrayList<>(); for (int k1 = 0; k1 < cosmicCands.size(); k1++) { Ray ray = cosmicCands.get(k1).get_ray(); @@ -103,7 +104,7 @@ public boolean processEvent(DataEvent event, cov[4][4]=1; kf.init(ray.get_yxinterc(),ray.get_yzinterc(), ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmicCands.get(k1), swimmer)); + measures.getMeasurements(cosmicCands.get(k1))); kf.mv.setDelta_d_a(new double[]{0.1, 0.1, 0.0001, 0.0001, 1}); kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { @@ -133,7 +134,7 @@ public boolean processEvent(DataEvent event, //refit kf.init(cosmic.get_ray().get_yxinterc(),cosmic.get_ray().get_yzinterc(), cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), 10.0, cov, - recUtil.setMeasVecs(cosmic, swimmer)) ; + measures.getMeasurements(cosmicCands.get(k1))) ; kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { cosmic.update(kf); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 399964608..0ce31ca7e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -98,37 +98,41 @@ public List setMeasVecs(Seed trkcand, Swim swim) { // SVT measurements for (int i = 0; i < trkcand.get_Clusters().size(); i++) { if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { - int mlayer = trkcand.get_Clusters().get(i).get_Layer(); - Surface meas = trkcand.get_Clusters().get(i).measurement(mlayer); + int layer = trkcand.get_Clusters().get(i).get_Layer(); + Surface meas = trkcand.get_Clusters().get(i).measurement(); + meas.setIndex(layer); if((int)Constants.getLayersUsed().get(meas.getLayer())<1) meas.notUsedInFit=true; - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + if(i>0 && KFSites.get(KFSites.size()-1).getIndex()==meas.getIndex()) continue; KFSites.add(meas); } } - + // adding the BMT double hemisp = Math.signum(trkcand.get_Helix().getPointAtRadius(300).y()); for (int c = 0; c < trkcand.get_Crosses().size(); c++) { - if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { - int mlayer=trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6; - Surface meas = trkcand.get_Crosses().get(c).get_Cluster1().measurement(mlayer); + if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { + int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); + Surface meas = trkcand.get_Crosses().get(c).get_Cluster1().measurement(); + meas.setIndex(layer+SVTGeometry.NLAYERS); + meas.setLayer(layer+SVTGeometry.NLAYERS); meas.hemisphere = hemisp; - if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + if((int)Constants.getLayersUsed().get(layer+SVTGeometry.NLAYERS)<1) { //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); meas.notUsedInFit=true; } - if(c>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer()) + if(c>0 && KFSites.get(KFSites.size()-1).getIndex()==meas.getIndex()) continue; KFSites.add(meas); } } + for(Surface s : KFSites) System.out.println(s.toString()); return KFSites; } private TrajectoryFinder tf = new TrajectoryFinder(); - + // Not used, replaced by Measurements class public List setMeasVecs(StraightTrack trkcand, Swim swim) { if(trkcand.clsMap!=null) trkcand.clsMap.clear(); //VZ: reset cluster map for second pass tracking with isolated SVT clusters //Collections.sort(trkcand.get_Crosses()); @@ -173,7 +177,8 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { } for (int j = 0; j < cls.size(); j++) { int mlayer = cls.get(j).get_Layer(); - Surface meas = cls.get(j).measurement(mlayer); + Surface meas = cls.get(j).measurement(); + meas.setLayer(mlayer); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; // set SVT material budget according to track direction if(j==0) meas.setl_over_X0(SVTGeometry.getToverX0()); @@ -181,7 +186,7 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { // RDV to be tested // if((int) Constants.getLayersUsed().get(meas.getLayer())<1) // meas.notUsedInFit=true; //VZ: commenting this out prevents the layer exclusion to be employed in tracking - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer() + if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==mlayer && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) continue; KFSites.add(meas); @@ -198,7 +203,8 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { int id = trkcand.get(i).get_Cluster1().get_Id(); double ce = trkcand.get(i).get_Cluster1().get_Centroid(); - Surface meas = trkcand.get(i).get_Cluster1().measurement(layer); + Surface meas = trkcand.get(i).get_Cluster1().measurement(); + meas.setLayer(layer); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { meas.notUsedInFit=true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 67f72fc4b..089cc99c6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -6,20 +6,17 @@ import org.jlab.clas.tracking.kalmanfilter.helical.KFitter; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.geant4.v2.CTOFGeant4Factory; -import org.jlab.geom.base.Detector; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.banks.RecoBankWriter; -import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossMaker; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.track.Measurements; import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.StraightTrackSeeder; import org.jlab.rec.cvt.track.Track; @@ -104,6 +101,7 @@ public boolean processEvent(DataEvent event, trkcands.clear(); KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.kfMatLib); + Measurements surfaces = new Measurements(false, swimmer); for (Seed seed : seeds) { Point3D v = seed.get_Helix().getVertex(); Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); @@ -127,7 +125,7 @@ public boolean processEvent(DataEvent event, if(solenoidValue>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0 && kf.KFHelix!=null) { Track fittedTrack = new Track(seed, kf); @@ -167,7 +165,7 @@ public boolean processEvent(DataEvent event, hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); - kf.init(hlx, cov, Constants.getXb(), Constants.getYb(), 0, recUtil.setMeasVecs(seed, swimmer)) ; + kf.init(hlx, cov, Constants.getXb(), Constants.getYb(), 0, surfaces.getMeasurements(seed)) ; kf.runFitter(); // RDV get rid of added clusters if not true diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index db9cb9dd0..ea97b1829 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -23,6 +23,7 @@ public class SVTGeometry { public static final int NLAYERS = 6; public static final int NSTRIPS = SVTConstants.NSTRIPS; public static final int[] NSECTORS = new int[NLAYERS]; + public static final int NPASSIVE = 3; @@ -38,6 +39,11 @@ private void init() { } } + public int getTwinLayer(int layer) { + int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); + rm[1] = 1 - rm[1]; + return 1+SVTConstants.convertRegionModule2Layer(rm[0], rm[1]); + } public static double getLayerRadius(int layer) { int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); @@ -220,23 +226,22 @@ public List getSurfaces() { surfaces.add(this.getShieldSurface()); surfaces.add(this.getFaradayCageSurfaces(0)); for(int i=1; i<=NLAYERS; i++) { - surfaces.add(this.getSurface(i, 1)); + surfaces.add(this.getSurface(i, 1, new Strip(0,0,0))); } surfaces.add(this.getFaradayCageSurfaces(1)); return surfaces; } - public Surface getSurface(int layer, int sector, int stripId, double centroid, Line3D stripLine, int hemisphere) { - Surface surface = this.getSurface(layer, sector); - surface.hemisphere = hemisphere; - surface.strip = new Strip(stripId, centroid, stripLine); + public Surface getSurface(int layer, int sector, int stripId, double centroid, Line3D stripLine) { + Strip strip = new Strip(stripId, centroid, stripLine); + Surface surface = this.getSurface(layer, sector, strip); return surface; } - public Surface getSurface(int layer, int sector) { + public Surface getSurface(int layer, int sector, Strip strip) { Line3D module = this.getModule(layer, sector); Surface surface = new Surface(this.getPlane(layer, sector), - new Strip(0,0,0), + strip, module.origin(), module.end(), Constants.SWIMACCURACYSVT); surface.hemisphere = 0; @@ -248,34 +253,36 @@ public Surface getSurface(int layer, int sector) { surface.setZ_over_A_times_l(SVTGeometry.getZoverA()); surface.setThickness(SVTGeometry.getMaterialThickness()); } - surface.notUsedInFit=true; + surface.notUsedInFit=false; return surface; } - private Surface getShieldSurface() { - Point3D center = new Point3D(0, 0, Constants.getZoffset()+SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); - Point3D origin = new Point3D(SVTConstants.TSHIELDRMAX, 0, SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); + public Surface getShieldSurface() { + Point3D center = new Point3D(0, 0, Constants.getZoffset()+SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); + Point3D origin = new Point3D(SVTConstants.TSHIELDRMAX, 0, Constants.getZoffset()+SVTConstants.TSHIELDZPOS-SVTConstants.TSHIELDLENGTH/2); Vector3D axis = new Vector3D(0,0,1); Arc3D base = new Arc3D(origin, center, axis, 2*Math.PI); Cylindrical3D shieldCylinder = new Cylindrical3D(base, SVTConstants.TSHIELDLENGTH); Surface shieldSurface = new Surface(shieldCylinder, new Strip(0, 0, 0), Constants.DEFAULTSWIMACC); - shieldSurface.setl_over_X0(SVTConstants.TSHIELDRADLEN); shieldSurface.setZ_over_A_times_l(SVTConstants.TSHILEDZOVERA); shieldSurface.setThickness(SVTConstants.TSHIELDRMAX-SVTConstants.TSHIELDRMIN); + shieldSurface.setl_over_X0(shieldSurface.getThickness()/SVTConstants.TSHIELDRADLEN); + shieldSurface.passive=true; shieldSurface.notUsedInFit=true; return shieldSurface; } - private Surface getFaradayCageSurfaces(int i) { + public Surface getFaradayCageSurfaces(int i) { Point3D center = new Point3D(0, 0, SVTConstants.FARADAYCAGEZPOS[i]-SVTConstants.FARADAYCAGELENGTH[i]/2); Point3D origin = new Point3D(SVTConstants.FARADAYCAGERMAX[i], 0, SVTConstants.FARADAYCAGEZPOS[i]-SVTConstants.FARADAYCAGELENGTH[i]/2); Vector3D axis = new Vector3D(0,0,1); Arc3D base = new Arc3D(origin, center, axis, 2*Math.PI); Cylindrical3D fcCylinder = new Cylindrical3D(base, SVTConstants.FARADAYCAGELENGTH[i]); Surface fcSurface = new Surface(fcCylinder, new Strip(0, 0, 0), Constants.DEFAULTSWIMACC); - fcSurface.setl_over_X0(SVTConstants.FARADAYCAGERADLEN[i]); fcSurface.setZ_over_A_times_l(SVTConstants.FARADAYCAGEZOVERA[i]); fcSurface.setThickness(SVTConstants.FARADAYCAGERMAX[i]-SVTConstants.FARADAYCAGERMIN[i]); + fcSurface.setl_over_X0(fcSurface.getThickness()/SVTConstants.FARADAYCAGERADLEN[i]); + fcSurface.passive=true; fcSurface.notUsedInFit=true; return fcSurface; } @@ -285,21 +292,13 @@ public int getSector(int layer, Point3D traj) { int[] rm = SVTConstants.convertLayer2RegionModule(layer-1); int Sect = -1; + double delta = Double.POSITIVE_INFINITY; for (int s = 0; s < SVTConstants.NSECTORS[rm[0]]; s++) { int sector = s + 1; - Line3D module = this.getModule(layer, sector); - Vector3D orig = module.origin().toVector3D().asUnit(); - Vector3D end = module.end().toVector3D().asUnit(); - Vector3D trk = new Vector3D(traj.x(), traj.y(), 0); - orig.unit(); - end.unit(); - trk.unit(); - - double phi1 = Math.acos(orig.dot(trk)); - double phi2 = Math.acos(trk.dot(end)); - double phiRange = Math.acos(orig.dot(end)); - - if (phi1 getMeasurements(Seed seed) { + this.reset(); + this.addClusters(seed); + this.addMissing(seed); + List surfaces = new ArrayList<>(); + for(Surface surf : cvtSurfaces) { + if(surf!=null) { + if(debug) System.out.println(surf.toString()); + surfaces.add(surf); + } + } + return surfaces; + } + + public List getActiveMeasurements(Seed seed) { + List surfaces = this.getMeasurements(seed); + List active = new ArrayList<>(); + for(Surface surf : surfaces) { + if(surf.passive && surf.getIndex()!=0) continue; + active.add(surf); + if(debug) System.out.println(surf.toString()); + } + return active; + } + + public List getMeasurements(StraightTrack cosmic) { + this.reset(); + this.addClusters(cosmic); + this.addMissing(cosmic); + List surfaces = new ArrayList<>(); + for(Surface surf : cvtSurfaces) { + if(surf!=null) { + if(debug) System.out.println(surf.toString()); + if(surf.passive && surf.getIndex()!=0 && !this.isCrossed(cosmic.get_ray(), surf)) { + if(debug) System.out.println("Removing surface " + surf.passive + " " + this.isCrossed(cosmic.get_ray(), surf)); + continue; + } + surfaces.add(surf); + } + } + return surfaces; + } + + public List getActiveMeasurements(StraightTrack cosmic) { + List surfaces = this.getMeasurements(cosmic); + List active = new ArrayList<>(); + for(Surface surf : surfaces) { + if(surf.passive && surf.getIndex()!=0) continue; + active.add(surf); + if(debug) System.out.println(surf.toString()); + } + return active; + } + + private void addClusters(Seed seed) { + int hemisp = (int) Math.signum(seed.get_Helix().getPointAtRadius(300).y()); + this.addClusters(DetectorType.BST, this.getClusterSurfaces(DetectorType.BST, seed.get_Clusters())); + this.addClusters(DetectorType.BMT, this.getClusterSurfaces(DetectorType.BMT, seed.get_Clusters(), hemisp)); + } + + private void addClusters(StraightTrack cosmic) { + this.addClusters(DetectorType.BST, this.getClusterSurfaces(DetectorType.BST, cosmic.getClusters())); + this.addClusters(DetectorType.BMT, this.getClusterSurfaces(DetectorType.BMT, cosmic.getClusters())); + } + + private void addClusters(DetectorType type, List clusters) { + for(Surface cluster : clusters) { + int hemisphere = 0; + if(cosmic) hemisphere = (int) cluster.hemisphere; + int index = CVTLayer.getType(type, cluster.getLayer()).getIndex(hemisphere); + this.add(index, cluster); + } + } + + private List getClusterSurfaces(DetectorType type, List clusters, int hemisphere) { + + List surfaces = this.getClusterSurfaces(type, clusters); + for(Surface surf : surfaces) { + surf.hemisphere = hemisphere; + } + return surfaces; + } + + private List getClusterSurfaces(DetectorType type, List clusters) { + List surfaces = new ArrayList<>(); + + for(Cluster cluster : clusters) { + if(cluster.get_Detector()!=type) continue; + int layer = cluster.get_Layer(); + Surface measure = cluster.measurement(); + measure.hemisphere = Math.signum(cluster.center().y()); + if((int)Constants.getLayersUsed().get(measure.getLayer())<1) + measure.notUsedInFit=true; + surfaces.add(measure); + } + return surfaces; + } + + private void addMissing(Seed seed) { + for(int i=0; i0) { + DetectorType type = CVTLayer.getDetectorType(id); + Surface surface = this.getDetectorSurface(seed, type, layer, 0); + if(surface == null) continue; + surface.notUsedInFit=true; + surface.passive=true; + if(debug) System.out.println("Generating surface for missing index " + i + " detector " + type.getName() + " layer " + layer + " sector " + surface.getSector()); + this.add(i, surface); + } + } + } + } + + private void addMissing(StraightTrack ray) { + for(int i=0; i0) { + DetectorType type = CVTLayer.getDetectorType(id); + Surface surface = this.getDetectorSurface(ray, type, layer, hemisphere); + if(surface == null) continue; + surface.hemisphere=hemisphere; + surface.notUsedInFit=true; + surface.passive=true; + if(debug) System.out.println("Generating surface for missing index " + i + " detector " + type.getName() + " layer " + layer + " sector " + surface.getSector()); + this.add(i, surface); + } + } + } + } + + private Surface getDetectorSurface(Seed seed, DetectorType type, int layer, int hemisphere) { + int sector = this.getSector(seed, type, layer, hemisphere); + if(sector>0) + return this.getDetectorSurface(type, layer, sector); + return null; + } + + + private Surface getDetectorSurface(StraightTrack ray, DetectorType type, int layer, int hemisphere) { + int sector = this.getSector(ray, type, layer, hemisphere); + if(sector>0) + return this.getDetectorSurface(type, layer, sector); + return null; + } + + private Surface getDetectorSurface(DetectorType type, int layer, int sector) { + Surface surface = null; + if(type==DetectorType.BST) + surface = Constants.SVTGEOMETRY.getSurface(layer, sector, new Strip(0, 0, 0)); + else if(type==DetectorType.BMT) + surface = Constants.BMTGEOMETRY.getSurface(layer, sector, new Strip(0, 0, 0)); + return surface; + } + + + private int getSector(Seed seed, DetectorType type, int layer, int hemisphere) { + Helix helix = seed.get_Helix(); + if(type==DetectorType.BST) { + int twinLayer = Constants.SVTGEOMETRY.getTwinLayer(layer); + int twinIndex = CVTLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); + if(cvtSurfaces[twinIndex]!=null) + return cvtSurfaces[twinIndex].getSector(); + Point3D traj = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(layer)); + if(traj!=null && !Double.isNaN(traj.z())) + return Constants.SVTGEOMETRY.getSector(layer, traj); + } + else if(type==DetectorType.BMT) { + Point3D traj = seed.get_Helix().getPointAtRadius(Constants.BMTGEOMETRY.getRadius(layer)); + if(traj!=null && !Double.isNaN(traj.z())) + return Constants.BMTGEOMETRY.getSector(0, traj); + } + return 0; + } + + private int getSector(StraightTrack cosmic, DetectorType type, int layer, int hemisphere) { + + if(type==DetectorType.BST) { + int twinLayer = Constants.SVTGEOMETRY.getTwinLayer(layer); + int twinIndex = CVTLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); + if(cvtSurfaces[twinIndex]!=null) + return cvtSurfaces[twinIndex].getSector(); + + double[][][] trajs = TrajectoryFinder.calc_trackIntersSVT(cosmic.get_ray()); + for(int i=0; i trajs = new ArrayList<>(); + Line3D line = ray.toLine(); + return surface.cylinder.intersection(line, trajs) > 1; + } + + private void reset() { + for(int i=0; i=SVTLAYER1.getId() && layId<=SVTLAYER6.getId()) + return DetectorType.BST; + else if(layId>=BMTLAYER1.getId() && layId<=BMTLAYER6.getId()) + return DetectorType.BMT; + else + return DetectorType.UNDEFINED; + } + + public static CVTLayer getType(String name) { + name = name.trim(); + for (CVTLayer id : CVTLayer.values()) { + if (id.getName().equalsIgnoreCase(name)) { + return id; + } + } + return UNDEFINED; + } + + public static CVTLayer getType(Integer layId) { + + for (CVTLayer id : CVTLayer.values()) { + if (id.getId() == layId) { + return id; + } + } + return UNDEFINED; + } + + public static CVTLayer getType(DetectorType type, int layer) { + for (CVTLayer id : CVTLayer.values()) { + if(id.getLayer() == layer && CVTLayer.getDetectorType(id.getId()) == type) { + return id; + } + } + return UNDEFINED; + } + + } +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index 9d44a2331..bf67a4555 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.track; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -13,6 +14,7 @@ import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.track.Measurements.CVTLayer; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -29,7 +31,22 @@ public StraightTrack(Ray ray) { super(ray); } - + + public List getClusters() { + List clusters = new ArrayList<>(); + for(Cross c : this) { + if(c.get_Detector()==DetectorType.BST) { + if(c.get_Cluster1()!=null) clusters.add(c.get_Cluster1()); + if(c.get_Cluster2()!=null) clusters.add(c.get_Cluster2()); + } else { + clusters.add(c.get_Cluster1()); + } + } + Collections.sort(clusters); + return clusters; + } + + public void update(KFitter kf) { Ray the_ray = new Ray(kf.finalStateVec.tx, kf.finalStateVec.x0, kf.finalStateVec.tz, kf.finalStateVec.z0); this.set_ray(the_ray); @@ -72,9 +89,13 @@ public void updateCrosses() { } public void updateClusters() { - for(int key : this.trajs.keySet()) { - this.clsMap.get(key).update(this.get_Id(), this.trajs.get(key)); - } + for(Cluster cluster: this.getClusters()) { + int hemisphere = (int) Math.signum(cluster.center().y()); + int layer = cluster.get_Layer(); + DetectorType type = cluster.get_Detector(); + int index = CVTLayer.getType(type, layer).getIndex(hemisphere); + cluster.update(this.get_Id(), this.trajs.get(index)); + } } public double get_ndf() { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index dd70c3d0d..9aa19db95 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -9,7 +9,7 @@ import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.track.Measurements.CVTLayer; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -193,8 +193,9 @@ public void update_Crosses(int trackId) { Vector3D trackDir = null; if(this.getTrajectories()!=null && Math.abs(this.get_helix().B)>0.0001) { int layer = cross.get_Cluster1().get_Layer(); - if(cross.get_Detector()==DetectorType.BMT) layer += SVTGeometry.NLAYERS; - HitOnTrack traj = this.getTrajectories().get(layer); + int index = CVTLayer.getType(cross.get_Detector(), layer).getIndex(); + HitOnTrack traj = this.getTrajectories().get(index); + if(traj==null) return; //RDV check why trackPos = new Point3D(traj.x, traj.y, traj.z); trackDir = new Vector3D(traj.px, traj.py, traj.pz).asUnit(); } @@ -216,10 +217,10 @@ public void update_Clusters(int trackId) { Cluster cluster = this.get_Seed().get_Clusters().get(i); int layer = cluster.get_Layer(); - if(cluster.get_Detector()==DetectorType.BMT) layer += SVTGeometry.NLAYERS; + int index = CVTLayer.getType(cluster.get_Detector(), layer).getIndex(); - if(this.getTrajectories().get(layer)!=null) // RDV check why it is necessary - cluster.update(trackId, this.getTrajectories().get(layer)); + if(this.getTrajectories().get(index)!=null) // RDV check why it is necessary + cluster.update(trackId, this.getTrajectories().get(index)); } } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index ccb2bc3ba..44efbc668 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -204,7 +204,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(layer)/10; inters = swimmer.SwimRho(radius, Constants.SWIMACCURACYBMT/10); - if(inters==null) break; + if(inters==null || Double.isNaN(inters[0]) || Double.isNaN(inters[1]) || Double.isNaN(inters[2])) break; int sector = Constants.BMTGEOMETRY.getSector(0, Math.atan2(inters[1],inters[0])); Line3D axis = Constants.BMTGEOMETRY.getAxis(layer, sector); From 2ae33ca0a29f92f0d1cc196dfeb698eb36808164 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 16 Jan 2022 17:31:11 +0100 Subject: [PATCH 266/291] Added subtract method for StateVec --- .../jlab/clas/tracking/kalmanfilter/AStateVecs.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index e41a2ef14..1326c6e40 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -302,6 +302,17 @@ public final void setPivot(double xPivot, double yPivot, double zPivot) { this.updateHelix(); } + public double[] subtractHelix(StateVec vec) { + double[] result = new double[5]; + vec.setPivot(this.x0, this.y0, this.z0); + result[0] = this.d_rho-vec.d_rho; + result[1] = this.phi0-vec.phi0; + result[2] = this.kappa-vec.kappa; + result[3] = this.dz-vec.dz; + result[4] = this.tanL-vec.tanL; + return result; + } + public void updateHelix(double x, double y, double z, double px, double py, double pz, double alpha) { this.x = x; this.y = y; From 79afc6220987091587466a701ffc37670e2cf336 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 16 Jan 2022 21:46:46 +0100 Subject: [PATCH 267/291] Apply exclude-layer option in the KF, disable seed refit because it creates fakes --- .../main/java/org/jlab/rec/cvt/Constants.java | 9 +++---- .../jlab/rec/cvt/services/CVTRecNewKF.java | 4 +-- .../rec/cvt/services/CosmicTracksRec.java | 2 +- .../jlab/rec/cvt/services/RecUtilities.java | 26 +++++++++--------- .../rec/cvt/services/TracksFromTargetRec.java | 27 +++++++------------ .../org/jlab/rec/cvt/track/Measurements.java | 3 ++- .../java/org/jlab/rec/cvt/track/Seed.java | 10 +++++++ .../java/org/jlab/rec/cvt/track/Track.java | 5 ++-- 8 files changed, 45 insertions(+), 41 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 564f23fc9..4ae986cd8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -90,7 +90,7 @@ public class Constants { private static int _rmReg = 0; - public static boolean excludeLayers = false; + public static boolean EXCLUDELAYERS = false; private static final Map layersUsed = new HashMap(); private static final double[][]BMTPhiZRangeExcld = new double[2][2]; private static int BMTLayerExcld = -1; @@ -160,14 +160,14 @@ public static void setRmReg(int _reg) { /** * @return the layersUsed */ - public static Map getLayersUsed() { + public static Map getUsedLayers() { return layersUsed; } /** * @param layers */ - public static void setLayersUsed(String layers) { + public static void setUsedLayers(String layers) { //all layers used --> 1 for(int i = 0; i < 12; i++) layersUsed.put(i+1, 1); @@ -178,9 +178,8 @@ public static void setLayersUsed(String layers) { for(String value : values) { int layer = Integer.valueOf(value); layersUsed.put(layer, 0); - System.out.println("EXCLUDE CVT LAYER " + layer); } - excludeLayers=true; + EXCLUDELAYERS=true; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 041efdd86..3e2f64a1e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -251,10 +251,10 @@ private void loadConfiguration() { //Skip layers String exLys = this.getEngineConfigString("excludeLayers"); if (exLys!=null) - System.out.println("["+this.getName()+"] run with layers "+exLys+"excluded in fit config chosen based on yaml"); + System.out.println("["+this.getName()+"] run with layers "+exLys+" excluded in fit config chosen based on yaml"); else System.out.println("["+this.getName()+"] run with all layer in fit (default) "); - Constants.setLayersUsed(exLys); + Constants.setUsedLayers(exLys); //Skip layers String exBMTLys = this.getEngineConfigString("excludeBMTLayers"); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 7d9e8391b..42608e8bd 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -61,7 +61,7 @@ public boolean processEvent(DataEvent event, return true; } - if(Constants.excludeLayers==true) { + if(Constants.EXCLUDELAYERS==true) { CosmicFitter fitTrk = new CosmicFitter(); cosmicCands = recUtil.reFit(cosmicCands, fitTrk, trkcandFinder); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 0ce31ca7e..8037e9056 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -101,7 +101,7 @@ public List setMeasVecs(Seed trkcand, Swim swim) { int layer = trkcand.get_Clusters().get(i).get_Layer(); Surface meas = trkcand.get_Clusters().get(i).measurement(); meas.setIndex(layer); - if((int)Constants.getLayersUsed().get(meas.getLayer())<1) + if((int)Constants.getUsedLayers().get(meas.getLayer())<1) meas.notUsedInFit=true; if(i>0 && KFSites.get(KFSites.size()-1).getIndex()==meas.getIndex()) continue; @@ -118,7 +118,7 @@ public List setMeasVecs(Seed trkcand, Swim swim) { meas.setIndex(layer+SVTGeometry.NLAYERS); meas.setLayer(layer+SVTGeometry.NLAYERS); meas.hemisphere = hemisp; - if((int)Constants.getLayersUsed().get(layer+SVTGeometry.NLAYERS)<1) { + if((int)Constants.getUsedLayers().get(layer+SVTGeometry.NLAYERS)<1) { //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); meas.notUsedInFit=true; } @@ -184,7 +184,7 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { if(j==0) meas.setl_over_X0(SVTGeometry.getToverX0()); else meas.setl_over_X0(0); // RDV to be tested -// if((int) Constants.getLayersUsed().get(meas.getLayer())<1) +// if((int) Constants.getUsedLayers().get(meas.getLayer())<1) // meas.notUsedInFit=true; //VZ: commenting this out prevents the layer exclusion to be employed in tracking if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==mlayer && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) @@ -206,7 +206,7 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { Surface meas = trkcand.get(i).get_Cluster1().measurement(); meas.setLayer(layer); meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; - if((int)Constants.getLayersUsed().get(meas.getLayer())<1) { + if((int)Constants.getUsedLayers().get(meas.getLayer())<1) { meas.notUsedInFit=true; } if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer() @@ -619,7 +619,7 @@ public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { int layr2 = 0; if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; //System.out.println("refit "+c.printInfo()); refib.add(c); @@ -627,8 +627,8 @@ public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)Constants.getLayersUsed().get(layr)>0 - && (int)Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getUsedLayers().get(layr)>0 + && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); c.isInSeed = false; refi.add(c); @@ -705,15 +705,15 @@ public List reFitSeed(Seed bseed, Swim swimmer, TrackSeederCA trseed, Tr c.set_AssociatedTrackID(-1); if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; refib.add(c); } } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)Constants.getLayersUsed().get(layr)>0 - && (int)Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getUsedLayers().get(layr)>0 + && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); @@ -759,7 +759,7 @@ public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,Tra int layr2 = 0; if(c.get_Detector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; - if((int)Constants.getLayersUsed().get(layr)>0) { + if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; // System.out.println("refit "+c.printInfo()); refib.add(c); @@ -767,8 +767,8 @@ public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,Tra } else { layr = c.get_Cluster1().get_Layer(); layr2 = c.get_Cluster2().get_Layer(); - if((int)Constants.getLayersUsed().get(layr)>0 - && (int)Constants.getLayersUsed().get(layr2)>0) { + if((int)Constants.getUsedLayers().get(layr)>0 + && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); c.isInSeed = false; // System.out.println("refit "+c.printInfo()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 089cc99c6..512692e76 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -48,9 +48,10 @@ public boolean processEvent(DataEvent event, if(solenoidValue<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(); seeds = trseed.findSeed(crosses.get(0), crosses.get(1), Constants.SVTOnly); - if(Constants.excludeLayers==true) { - seeds = recUtil.reFit(seeds, swimmer, trseed); // RDV can we juts refit? - } + // RDV, disabled because it seems to create fake tracks, skipping measurement in KF +// if(Constants.EXCLUDELAYERS==true) { +// seeds = recUtil.reFit(seeds, swimmer, trseed); // RDV can we juts refit? +// } } else { if(Constants.SVTOnly) { TrackSeeder trseed = new TrackSeeder(swimmer); @@ -61,13 +62,14 @@ public boolean processEvent(DataEvent event, seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - if(Constants.svtSeeding || Constants.excludeLayers) { + if(Constants.svtSeeding) { TrackSeeder trseed2 = new TrackSeeder(swimmer); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); - if(Constants.excludeLayers==true) { - seeds = recUtil.reFit(seeds, swimmer, trseed, trseed2); - } + // RDV, disabled because it seems to create fake tracks, skipping measurement in KF +// if(Constants.EXCLUDELAYERS==true) { +// seeds = recUtil.reFit(seeds, swimmer, trseed, trseed2); +// } } if(!Constants.seedBeamSpotConstraint()) { List failed = new ArrayList<>(); @@ -92,12 +94,8 @@ public boolean processEvent(DataEvent event, seed.setId(id); Track track = new Track(seed); track.update_Crosses(id); - trkcands.add(track); + trkcands.add(track); } -// if(true) { -// rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, seeds, trkcands, shift); -// return true; -// } trkcands.clear(); KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.kfMatLib); @@ -189,11 +187,6 @@ public boolean processEvent(DataEvent event, for(Cluster c : BMTclusters) { c.set_AssociatedTrackID(-1); } -// if (trkcands.isEmpty()) { -// recUtil.CleanupSpuriousCrosses(crosses, null, SVTGeom) ; -// rbc.appendCVTBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, seeds, null, shift); -// return true; -// } List tracks = null; if(!trkcands.isEmpty()) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java index c58ed0363..051f260bf 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java @@ -199,9 +199,10 @@ private List getClusterSurfaces(DetectorType type, List cluste for(Cluster cluster : clusters) { if(cluster.get_Detector()!=type) continue; int layer = cluster.get_Layer(); + if(type==DetectorType.BMT) layer += SVTGeometry.NLAYERS; Surface measure = cluster.measurement(); measure.hemisphere = Math.signum(cluster.center().y()); - if((int)Constants.getLayersUsed().get(measure.getLayer())<1) + if((int)Constants.getUsedLayers().get(layer)<1) measure.notUsedInFit=true; surfaces.add(measure); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index c6c6e8973..25885aac0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -427,4 +427,14 @@ public static void removeOverlappingSeeds(List seeds) { seeds.removeAll(seeds); seeds.addAll(selectedSeeds); } + + @Override + public String toString() { + String str = String.format("Track id=%d, q=%d, omega=%.3f mm-1, d0=%.3f mm, phi=%.3f deg, dz=%.3f mm, tanL=%.3f, NDF=%d, chi2=%.3f, seed method=%d\n", + this.getId(), this.get_Helix().get_charge(), this.get_Helix().get_curvature(), this.get_Helix().get_dca(), + Math.toDegrees(this.get_Helix().get_phi_at_dca()), this.get_Helix().get_Z0(), this.get_Helix().get_tandip(), + this.getNDF(), this.getChi2(), this.get_Status()); + for(Cross c: this.get_Crosses()) str = str + c.toString() + "\n"; + return str; + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 9aa19db95..98b1affe2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -426,10 +426,11 @@ public void setTrackCovMat(double[][] trackCovMat) { this.trackCovMat = trackCovMat; } + @Override public String toString() { - String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, phi=%.3f deg, NDF=%d, chi2=%.3f\n", + String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, phi=%.3f deg, NDF=%d, chi2=%.3f, seed method=%d\n", this.get_Id(), this.get_Q(), this.get_P(), this.get_Pt(), Math.toDegrees(this.get_helix().get_phi_at_dca()), - this.getNDF(), this.getChi2()); + this.getNDF(), this.getChi2(), this.get_Seed().get_Status()); for(Cross c: this) str = str + c.toString() + "\n"; return str; } From d218e36be4e931e68bdbdfe0d75e961df91805e8 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 17 Jan 2022 16:23:50 +0100 Subject: [PATCH 268/291] Read beam offset for actual run number with the ConstantManager, beam offsets propagated via the Helix, clean-up of clas-tracking Helix --- .../tracking/kalmanfilter/AStateVecs.java | 49 +- .../kalmanfilter/helical/KFitter.java | 2 +- .../kalmanfilter/helical/StateVecs.java | 67 ++- .../kalmanfilter/straight/KFitter.java | 3 +- .../kalmanfilter/straight/StateVecs.java | 3 +- .../jlab/clas/tracking/trackrep/Helix.java | 506 ++++++------------ .../main/java/org/jlab/rec/cvt/Constants.java | 18 - .../jlab/rec/cvt/banks/RecoBankWriter.java | 8 +- .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 11 - .../rec/cvt/cross/HelixCrossListFinder.java | 16 +- .../org/jlab/rec/cvt/fit/CircleFitter.java | 8 +- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 12 +- .../jlab/rec/cvt/fit/StraightTrackFitter.java | 2 +- .../jlab/rec/cvt/services/CVTRecNewKF.java | 10 +- .../rec/cvt/services/CosmicTracksRec.java | 9 +- .../jlab/rec/cvt/services/RecUtilities.java | 142 ++--- .../rec/cvt/services/TracksFromTargetRec.java | 26 +- .../jlab/rec/cvt/track/EnergyLossCorr.java | 2 +- .../org/jlab/rec/cvt/track/Measurements.java | 18 +- .../java/org/jlab/rec/cvt/track/Seed.java | 19 +- .../rec/cvt/track/StraightTrackSeeder.java | 18 +- .../java/org/jlab/rec/cvt/track/Track.java | 3 +- .../rec/cvt/track/TrackCandListFinder.java | 28 +- .../jlab/rec/cvt/track/TrackListFinder.java | 2 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 22 +- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 12 +- .../org/jlab/rec/cvt/trajectory/Helix.java | 33 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 9 +- 28 files changed, 417 insertions(+), 641 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index 1326c6e40..983f6c712 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -9,12 +9,12 @@ import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.helical.KFitter; import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.geom.prim.Point3D; public abstract class AStateVecs { - public Helix util; - public double units; + public Units units; public double lightVel; public double xref; @@ -29,7 +29,7 @@ public abstract class AStateVecs { public abstract void init(Helix trk, double[][] cov, double xref, double yref, double zref, Swim swimmer); - public abstract void init(double x0, double z0, double tx, double tz, double units, double[][] cov); + public abstract void init(double x0, double z0, double tx, double tz, Units units, double[][] cov); public abstract boolean setStateVecPosAtMeasSite(StateVec vec, MeasVec mv, Swim swimmer); @@ -324,32 +324,23 @@ public void updateHelix(double x, double y, double z, double px, double py, doub this.updateHelix(); } - public Helix getOldHelix() { - Helix helix = new Helix(); - this.toOldHelix(helix); + public Helix getHelix(double xref, double yref) { + StateVec vec = new StateVec(0, xref, yref, 0, this); + + int turningSign = (int) Math.signum(vec.kappa) * KFitter.polarity; + double bfield = 1 / vec.alpha / lightVel; + double R = vec.alpha / Math.abs(vec.kappa); + double phi0 = vec.phi0 + Math.PI / 2; + if (Math.abs(phi0) > Math.PI) phi0 -= Math.signum(phi0) * 2 * Math.PI; + double tanDip = vec.tanL; + double z0 = vec.z0 + vec.dz; + double omega = -turningSign / R; + double d0 = -vec.d_rho; + + Helix helix = new Helix(d0, phi0, omega, z0, tanDip, turningSign, bfield, xref, yref, units); + return helix; } - - public void toOldHelix(Helix helix) { - StateVec vec = new StateVec(0, helix.getXb(), helix.getYb(), 0, this); - vec.updateHelix(); - - helix.setTurningSign((int) Math.signum(vec.kappa) * KFitter.polarity); - helix.setB(1 / vec.alpha / helix.getLIGHTVEL()); - helix.setR(vec.alpha / Math.abs(vec.kappa)); - double hphi0 = vec.phi0 + Math.PI / 2; - if (Math.abs(hphi0) > Math.PI) { - hphi0 -= Math.signum(hphi0) * 2 * Math.PI; - } - helix.setPhi0(hphi0); - helix.setTanL(vec.tanL); - helix.setZ0(z0 + vec.dz); - helix.setOmega(-helix.getTurningSign() / helix.getR()); - helix.setCosphi0(Math.cos(helix.getPhi0())); - helix.setSinphi0(Math.sin(helix.getPhi0())); - helix.setD0(-vec.d_rho); - helix.Update(); - } public void updateRay() { this.dl = this.y/this.py; @@ -444,7 +435,7 @@ public B(int k, double x, double y, double z, Swim swimmer) { this.y = y; this.z = z; - swimmer.BfieldLab(x / units, y / units, z / units, b); + swimmer.BfieldLab(x / units.unit(), y / units.unit(), z / units.unit(), b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; @@ -453,7 +444,7 @@ public B(int k, double x, double y, double z, Swim swimmer) { } public void set() { - swimmer.BfieldLab(x / units, y / units, z / units, b); + swimmer.BfieldLab(x / units.unit(), y / units.unit(), z / units.unit(), b); this.Bx = b[0]; this.By = b[1]; this.Bz = b[2]; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index 8a1ac8754..53b01627e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -85,7 +85,7 @@ else if(newchisq < this.chi2) { finalStateVec = sv.new StateVec(finalSVonPivot); finalStateVec.setPivot(this.getXb(), this.getYb(), 0); finalStateVec.covMat = this.sv.propagateCovMat(finalSVonPivot, finalStateVec); - KFHelix = finalStateVec.getOldHelix(); + KFHelix = finalStateVec.getHelix(this.getXb(), this.getYb()); } } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 60e515857..29bab8f89 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -6,6 +6,7 @@ import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -69,11 +70,11 @@ else if(mv.surface.cylinder!=null) { } } else { if(swim==null) { // applicable only to planes parallel to the z -axis - sv.toOldHelix(util); + Helix helix = sv.getHelix(xref, yref); if(mv.surface.plane!=null) { - pos = util.getHelixPointAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), + pos = helix.getHelixPointAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), mv.surface.finitePlaneCorner2.x(), mv.surface.finitePlaneCorner2.y(), 10); - mom = util.getMomentumAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), + mom = helix.getMomentumAtPlane(mv.surface.finitePlaneCorner1.x(), mv.surface.finitePlaneCorner1.y(), mv.surface.finitePlaneCorner2.x(), mv.surface.finitePlaneCorner2.y(), 10); sv.x = pos.x(); sv.y = pos.y(); @@ -84,8 +85,8 @@ else if(mv.surface.cylinder!=null) { } else { double r = mv.surface.cylinder.baseArc().radius(); - pos = util.getHelixPointAtR(r); - mom = util.getMomentumAtR(r); + pos = helix.getHelixPointAtR(r); + mom = helix.getMomentumAtR(r); sv.x = pos.x(); sv.y = pos.y(); sv.z = pos.z(); @@ -95,42 +96,42 @@ else if(mv.surface.cylinder!=null) { } } else { - swim.SetSwimParameters(sv.x/units, sv.y/units, sv.z/units, + swim.SetSwimParameters(sv.x/units.unit(), sv.y/units.unit(), sv.z/units.unit(), dir*sv.px, dir*sv.py, dir*sv.pz, KFitter.polarity*(int) Math.signum(sv.kappa)*dir); if(mv.surface.plane!=null) { Vector3D norm = mv.surface.plane.normal(); - Point3D point = new Point3D(mv.surface.plane.point().x()/units, - mv.surface.plane.point().y()/units, - mv.surface.plane.point().z()/units); - double accuracy = mv.surface.swimAccuracy/units; + Point3D point = new Point3D(mv.surface.plane.point().x()/units.unit(), + mv.surface.plane.point().y()/units.unit(), + mv.surface.plane.point().z()/units.unit()); + double accuracy = mv.surface.swimAccuracy/units.unit(); swimPars = swim.SwimPlane(norm,point,accuracy); // swimPars = swim.AdaptiveSwimPlane(point.x(), point.y(), point.z(), norm.x(), norm.y(), norm.z(), accuracy); if(swimPars==null) return false; - sv.x = swimPars[0]*units; - sv.y = swimPars[1]*units; - sv.z = swimPars[2]*units; + sv.x = swimPars[0]*units.unit(); + sv.y = swimPars[1]*units.unit(); + sv.z = swimPars[2]*units.unit(); sv.px = swimPars[3]*dir; sv.py = swimPars[4]*dir; sv.pz = swimPars[5]*dir; } else { double r = mv.surface.cylinder.baseArc().radius(); - Point3D p1 = new Point3D(mv.surface.cylinder.getAxis().origin().x()/units, - mv.surface.cylinder.getAxis().origin().y()/units, - mv.surface.cylinder.getAxis().origin().z()/units) ; - Point3D p2 = new Point3D(mv.surface.cylinder.getAxis().end().x()/units, - mv.surface.cylinder.getAxis().end().y()/units, - mv.surface.cylinder.getAxis().end().z()/units) ; - double accuracy = mv.surface.swimAccuracy/units; - swimPars = swim.SwimGenCylinder(p1, p2, r/units, accuracy); + Point3D p1 = new Point3D(mv.surface.cylinder.getAxis().origin().x()/units.unit(), + mv.surface.cylinder.getAxis().origin().y()/units.unit(), + mv.surface.cylinder.getAxis().origin().z()/units.unit()) ; + Point3D p2 = new Point3D(mv.surface.cylinder.getAxis().end().x()/units.unit(), + mv.surface.cylinder.getAxis().end().y()/units.unit(), + mv.surface.cylinder.getAxis().end().z()/units.unit()) ; + double accuracy = mv.surface.swimAccuracy/units.unit(); + swimPars = swim.SwimGenCylinder(p1, p2, r/units.unit(), accuracy); if(swimPars==null) return false; - sv.x = swimPars[0]*units; - sv.y = swimPars[1]*units; - sv.z = swimPars[2]*units; + sv.x = swimPars[0]*units.unit(); + sv.y = swimPars[1]*units.unit(); + sv.z = swimPars[2]*units.unit(); sv.px = swimPars[3]*dir; sv.py = swimPars[4]*dir; sv.pz = swimPars[5]*dir; @@ -254,7 +255,7 @@ public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { // util.setTurningSign(q); // util.setB(B); // double pt = Math.sqrt(px0*px0 + py0*py0); -// util.setR(pt/(B*util.getLIGHTVEL())) ; +// util.setR(pt/(B*util.getLightVelocity())) ; // util.setPhi0(Math.atan2(py0, px0)); // util.setTanL(pz0/pt); // util.setZ0(z0); @@ -272,7 +273,7 @@ public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { // util.setD0((y0-Y0.get(0))/C) ; // } // -// util.Update(); +// util.update(); // } // private void setHelixPars(StateVec kVec, Swim swim) { // StateVec vec = new StateVec(0, kVec); @@ -409,16 +410,15 @@ public Helix setTrackPars() { int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(0).kappa); double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel ; - return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, this.xref, this.yref, util.units); + return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, this.xref, this.yref, this.units); } @Override public void init(Helix helix, double[][] cov, double xref, double yref, double zref, Swim swimmer) { this.trackTraj = new HashMap<>(); - this.units = helix.getUnitScale(); - this.lightVel = helix.getLIGHTVEL(); - this.util = helix; + this.units = helix.getUnits(); + this.lightVel = helix.getLightVelocity(); this.xref = xref; this.yref = yref; @@ -438,7 +438,7 @@ public void init(Helix helix, double[][] cov, double xref, double yref, double z else { initSV.x0 = helix.getX(); initSV.y0 = helix.getY(); - initSV.z0 = helix.getZ(); + initSV.z0 = helix.getZ(); } initSV.x = helix.getX(); initSV.y = helix.getY(); @@ -446,10 +446,9 @@ public void init(Helix helix, double[][] cov, double xref, double yref, double z initSV.px = helix.getPx(); initSV.py = helix.getPy(); initSV.pz = helix.getPz(); -// this.printlnStateVec(initSV); // set bfield according to input helix for consistency - initSV.alpha = 1/(helix.getB()*helix.getLIGHTVEL()); + initSV.alpha = 1/(helix.getB()*helix.getLightVelocity()); // set kappa to define the charge initSV.kappa = initSV.alpha * helix.getOmega(); // convert from the helix class representation to KF @@ -491,7 +490,7 @@ public void printlnStateVec(StateVec S) { @Override - public void init(double x0, double z0, double tx, double tz, double units, double[][] cov) { + public void init(double x0, double z0, double tx, double tz, Units units, double[][] cov) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index fc320087a..ca7922ecd 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -8,6 +8,7 @@ import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.kalmanfilter.AStateVecs.StateVec; import org.jlab.clas.tracking.kalmanfilter.Surface; +import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.clas.tracking.utilities.MatrixOps.Libr; /** @@ -29,7 +30,7 @@ public void runFitter() { this.runFitter(sv, mv); } - public void init(double x0, double z0,double tx,double tz, double units, double[][] cov, List measSurfaces) { + public void init(double x0, double z0,double tx,double tz, Units units, double[][] cov, List measSurfaces) { finalStateVec = null; this.NDF0 = -4; this.NDF = -4; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index faca9c9c9..1892ffbe5 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -6,6 +6,7 @@ import org.jlab.clas.tracking.kalmanfilter.AMeasVecs.MeasVec; import org.jlab.clas.tracking.kalmanfilter.AStateVecs; import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.clas.tracking.trackrep.Helix.Units; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -190,7 +191,7 @@ public void init(Helix trk, double[][] cov, double xref, double yref, double zre } @Override - public void init(double x0, double z0, double tx, double tz, double units, double[][] cov) { + public void init(double x0, double z0, double tx, double tz, Units units, double[][] cov) { this.trackTraj = new HashMap<>(); this.units = units; //this.lightVel = 0.0000299792458*units; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java index 48ee8e87a..1bb78eee3 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Helix.java @@ -19,11 +19,9 @@ public class Helix { private double _omega; private double _z0; private double _tanL; - private int _turningSign; - - private double tFlightLen = 0; + private int _turningSign; private double _R; - + private double _xd; private double _yd; private double _xc; @@ -37,7 +35,9 @@ public class Helix { private double _py; private double _pz; - public Units units = Units.CM; //default + private Units units = Units.CM; //default + + public final static double LIGHTVEL = 0.0000299792458; // velocity of light - conversion factor from radius in cm to momentum in GeV/c public Helix() { @@ -45,38 +45,34 @@ public Helix() { public Helix(double d0, double phi0, double omega, double z0, double tanL, int turningSign, double B, double xb, double yb, Units unit) { - _d0 = d0; - _phi0 = phi0; - _cosphi0 = Math.cos(phi0); - _sinphi0 = Math.sin(phi0); - _omega = omega; - _z0 = z0; - _tanL = tanL; - _turningSign = turningSign; - _B = B; - _xb = xb; - _yb = yb; - this.units = unit; - this.setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL*unit.unit); - this.Update(); + _d0 = d0; + _phi0 = phi0; + _cosphi0 = Math.cos(phi0); + _sinphi0 = Math.sin(phi0); + _omega = omega; + _z0 = z0; + _tanL = tanL; + _turningSign = turningSign; + _B = B; + _xb = xb; + _yb = yb; + units = unit; + this.update(); } public Helix(double x0, double y0, double z0, double px0, double py0, double pz0, int q, double B, double xb, double yb, Units unit) { _turningSign = q; - _B = B; - double pt = Math.sqrt(px0*px0 + py0*py0); - this.units = unit; - setUnitScale(unit.unit); - setLIGHTVEL(LIGHTVEL*unit.unit); - _R = pt/(B*LIGHTVEL*unit.unit); - _cosphi0 = px0/pt; - _sinphi0 = py0/pt; - _phi0 = Math.atan2(py0, px0); - _tanL = pz0/pt; - _z0 = z0; - _omega = (double) -_turningSign/_R; + _B = B; + units = unit; + double pt = Math.sqrt(px0*px0 + py0*py0); + _R = pt/(B*this.getLightVelocity()); + _cosphi0 = px0/pt; + _sinphi0 = py0/pt; + _phi0 = Math.atan2(py0, px0); + _tanL = pz0/pt; + _z0 = z0; + _omega = (double) -_turningSign/_R; double S = Math.sin(_phi0); double C = Math.cos(_phi0); if(Math.abs(S)>=Math.abs(C)) { @@ -86,202 +82,161 @@ public Helix(double x0, double y0, double z0, double px0, double py0, double pz0 } _xb = xb; _yb = yb; - this.Update(); + this.update(); } - public double getPhi(double l) { - return getPhi0() + getOmega()*l; - } - public double getPt(double B) { - return getLIGHTVEL() * getR() * B; - } - public double getX(double l){ - return getXc() + getTurningSign()*getR()*Math.sin(getPhi(l)); + public Units getUnits() { + return this.units; } - public double getY(double l){ - return getYc() - getTurningSign()*getR()*Math.cos(getPhi(l)); - } - public double getZ(double l){ - return getZ0() -l*getTanL(); - } - public double getPx(double B, double l) { - return getPt(B) * Math.cos(getPhi(l)); - } - public double getPy(double B, double l) { - return getPt(B) * Math.sin(getPhi(l)); + + public final double getLightVelocity() { + return LIGHTVEL*units.unit; + } + + public void reset(double d0, double phi0, double omega, double z0, double tanL, double B){ + _d0 = d0; + _phi0 = phi0; + _cosphi0 = Math.cos(phi0); + _sinphi0 = Math.sin(phi0); + _omega = omega; + _z0 = z0; + _tanL = tanL; + _B = B; + this.update(); } - public double getPz(double B) { - return getPt(B)*getTanL(); + + public final void update() { + setR(1./Math.abs(getOmega())); + _xd = -getD0()*getSinphi0()+_xb; + _yd = getD0()*getCosphi0()+_yb; + _xc = -(_turningSign*_R + _d0)*getSinphi0()+_xb; + _yc = (_turningSign*_R + _d0)*getCosphi0()+_yb; + _x = getX(0); + _y = getY(0); + _z = getZ(0); + _px = getPx(getB(), 0); + _py = getPy(getB(), 0); + _pz = getPz(getB()); } - /** - * @return the _B - */ public double getB() { return _B; } - /** - * @param _B the _B to set - */ - public void setB(double _B) { - this._B = _B; - } - - /** - * @return the _d0 - */ public double getD0() { return _d0; } - /** - * @param _d0 the _d0 to set - */ - public void setD0(double _d0) { - this._d0 = _d0; - } - - /** - * @return the _phi0 - */ public double getPhi0() { return _phi0; } - /** - * @param _phi0 the _phi0 to set - */ - public void setPhi0(double _phi0) { - this._phi0 = _phi0; - } - - /** - * @return the _cosphi0 - */ public double getCosphi0() { return _cosphi0; } - /** - * @param _cosphi0 the _cosphi0 to set - */ - public void setCosphi0(double _cosphi0) { - this._cosphi0 = _cosphi0; - } - - /** - * @return the _sinphi0 - */ public double getSinphi0() { return _sinphi0; } - /** - * @param _sinphi0 the _sinphi0 to set - */ - public void setSinphi0(double _sinphi0) { - this._sinphi0 = _sinphi0; - } - - /** - * @return the _omega - */ public double getOmega() { return _omega; } - /** - * @param _omega the _omega to set - */ - public void setOmega(double _omega) { - this._omega = _omega; - } - - /** - * @return the _z0 - */ public double getZ0() { return _z0; } - /** - * @param _z0 the _z0 to set - */ - public void setZ0(double _z0) { - this._z0 = _z0; - } - - /** - * @return the _tanL - */ public double getTanL() { return _tanL; } - /** - * @param _tanL the _tanL to set - */ - public void setTanL(double _tanL) { - this._tanL = _tanL; - } - - /** - * @return the _turningSign - */ public int getTurningSign() { return _turningSign; } - /** - * @param _turningSign the _turningSign to set - */ - public void setTurningSign(int _turningSign) { - this._turningSign = _turningSign; - } - - /** - * @return the _R - */ public double getR() { return _R; } - /** - * @param _R the _R to set - */ public void setR(double _R) { this._R = _R; } - public void Reset(double d0, double phi0, double omega, double z0, double tanL, - double B){ - setD0(d0); - setPhi0(phi0); - setCosphi0(Math.cos(phi0)); - setSinphi0(Math.sin(phi0)); - setOmega(omega); - setZ0(z0); - setTanL(tanL); - setB(B); - - this.Update(); + + public double getXc() { + return _xc; } - public void Update() { - setR(1./Math.abs(getOmega())); - _xd = -getD0()*getSinphi0()+_xb; - _yd = getD0()*getCosphi0()+_yb; - setXc(-(_turningSign*_R + _d0)*getSinphi0()+_xb); - setYc((_turningSign*_R + _d0)*getCosphi0()+_yb); - setX(getX(tFlightLen)); - setY(getY(tFlightLen)); - setZ(getZ(tFlightLen)); - setPx(getPx(getB(), tFlightLen)); - setPy(getPy(getB(), tFlightLen)); - setPz(getPz(getB())); + + public double getYc() { + return _yc; + } + + public double getXb() { + return _xb; + } + + public double getYb() { + return _yb; + } + + public double getPhi(double l) { + return getPhi0() + getOmega()*l; + } + + public double getPt(double B) { + return getLightVelocity() * getR() * B; + } + + public double getX(double l){ + return getXc() + getTurningSign()*getR()*Math.sin(getPhi(l)); + } + + public double getY(double l){ + return getYc() - getTurningSign()*getR()*Math.cos(getPhi(l)); + } + + public double getZ(double l){ + return getZ0() -l*getTanL(); + } + + public double getPx(double B, double l) { + return getPt(B) * Math.cos(getPhi(l)); } + public double getPy(double B, double l) { + return getPt(B) * Math.sin(getPhi(l)); + } + + public double getPz(double B) { + return getPt(B)*getTanL(); + } + + public double getX() { + return this.getX(0); + } + + public double getY() { + return this.getY(0); + } + + public double getZ() { + return this.getZ(0); + } + + public double getPx() { + return this.getPx(this.getB(), 0); + } + + public double getPy() { + return this.getPy(this.getB(), 0); + } + + public double getPz() { + return this.getPz(this.getB()); + } + public double getLAtPlane(double X1, double Y1, double X2, double Y2, double tolerance) { // Find the intersection of the helix circle with the module plane projection in XY which is a line @@ -369,17 +324,13 @@ public Point3D getHelixPointAtPlane(double X1, double Y1, double X2, double Y2, double l = getLAtPlane(X1, Y1, X2, Y2, tolerance); return new Point3D(getX(l),getY(l),getZ(l)); } + public Vector3D getMomentumAtPlane(double X1, double Y1, double X2, double Y2, double tolerance) { double l = getLAtPlane(X1, Y1, X2, Y2, tolerance); return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); } - /** - * - * @param r radius - * @return Computes intersection of helix with circle centered at 0 and of radius R - */ public double getLAtR(double r) { double x; @@ -432,214 +383,59 @@ public double getLAtR(double r) { return dphi/getOmega(); } + public Point3D getHelixPointAtR(double r) { double l = getLAtR( r); return new Point3D(getX(l),getY(l),getZ(l)); } + public Vector3D getMomentumAtR(double r) { double l = getLAtR( r); return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); } + public double getLAtZ(double z) { return (z - getZ0())/getTanL(); } + public Point3D getHelixPointAtZ(double z) { double l = getLAtZ( z); return new Point3D(getX(l),getY(l),z); } + public Vector3D getMomentumAtZ(double z) { double l = getLAtZ( z); return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB())); } - /** - * @return the _x - */ - public double getX() { - return _x; - } - - /** - * @param _x the _x to set - */ - public void setX(double _x) { - this._x = _x; - } - - /** - * @return the _y - */ - public double getY() { - return _y; - } - - /** - * @param _y the _y to set - */ - public void setY(double _y) { - this._y = _y; - } - - /** - * @return the _z - */ - public double getZ() { - return _z; - } - - /** - * @param _z the _z to set - */ - public void setZ(double _z) { - this._z = _z; - } - - /** - * @return the _px - */ - public double getPx() { - return _px; - } - - /** - * @param _px the _px to set - */ - public void setPx(double _px) { - this._px = _px; - } - - /** - * @return the _py - */ - public double getPy() { - return _py; - } - - /** - * @param _py the _py to set - */ - public void setPy(double _py) { - this._py = _py; - } - - /** - * @return the _pz - */ - public double getPz() { - return _pz; - } - - /** - * @param _pz the _pz to set - */ - public void setPz(double _pz) { - this._pz = _pz; - } - - /** - * @return the _xc - */ - public double getXc() { - return _xc; - } - - /** - * @param _xc the _xc to set - */ - public void setXc(double _xc) { - this._xc = _xc; - } - - /** - * @return the _yc - */ - public double getYc() { - return _yc; - } - - /** - * @param _yc the _yc to set - */ - public void setYc(double _yc) { - this._yc = _yc; - } - - /** - * @return the _xb - */ - public double getXb() { - return _xb; - } - - /** - * @param _xb the _xb to set - */ - public void setXb(double _xb) { - this._xb = _xb; - } - - /** - * @return the _yb - */ - public double getYb() { - return _yb; - } - - /** - * @param _yb the _yb to set - */ - public void setYb(double _yb) { - this._yb = _yb; - } - public enum Units { MM (10.0), - CM (1.0); + CM (1.0); private final double unit; + Units(double unit) { this.unit = unit; } - private double unit() { return unit; } - } - - /** - * @return the unitScale - */ - public double getUnitScale() { - return unitScale; - } - - /** - * @param aUnitScale the unitScale to set - */ - public void setUnitScale(double aUnitScale) { - unitScale = aUnitScale; - } - - /** - * @return the LightVel - */ - public double getLIGHTVEL() { - return LightVel; - } - - /** - * @param aLIGHTVEL the LightVel to set - */ - public void setLIGHTVEL(double aLIGHTVEL) { - LightVel = aLIGHTVEL; + + public double unit() { + return unit; + } + + public static Units getUnit(double value) { + for (Units unit : Units.values()) { + if (unit.unit == value) { + return unit; + } + } + return Units.CM; + } } - public static final double LIGHTVEL = 0.0000299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c - - private static double LightVel = 0.0000299792458; // velocity of light (um/ns) - conversion factor from radius in cm to momentum in GeV/c - private static double unitScale = 1; - @Override public String toString() { String s = String.format(" drho=%.4f phi0=%.4f radius=%.4f z0=%.4f tanL=%.4f B=%.4f\n", this._d0, this._phi0, this._R, this._z0, this._tanL, this._B); - s += String.format(" phi=%.4f x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", this.tFlightLen, this._x, this._y, this._z, this._px, this._py, this._pz); + s += String.format(" x0=%.4f y0=%.4f x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", this._xb, this._yb, this._x, this._y, this._z, this._px, this._py, this._pz); return s; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 4ae986cd8..bad3be56e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -82,8 +82,6 @@ public class Constants { public static final double CTOFINNERRADIUS = 250; // 250 mm public static final double CTOFOUTRRADIUS = 250 + 33; // 283 mm - private static double _Xb =0; - private static double _Yb =0; private static double _RbErr = 0.3; // mm private static double _Zoffset = 0; @@ -100,22 +98,6 @@ public class Constants { public static CTOFGeant4Factory CTOFGEOMETRY = null; public static Detector CNDGEOMETRY = null; public static List CVTSURFACES = null; - - public static double getXb() { - return _Xb; - } - - public static synchronized void setXb(double Xb) { - _Xb = Xb; - } - - public static double getYb() { - return _Yb; - } - - public static synchronized void setYb(double Yb) { - _Yb = Yb; - } public static double getRbErr() { return _RbErr; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index 2c3ab36bf..a38c93a4f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -431,8 +431,8 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { bank.setFloat("cov_z02", i, -999); bank.setFloat("cov_tandip2", i, -999); } - bank.setFloat("xb", i, (float) (Constants.getXb()/10.0)); - bank.setFloat("yb", i, (float) (Constants.getYb()/10.0)); + bank.setFloat("xb", i, (float) (helix.getXb()/10.0)); + bank.setFloat("yb", i, (float) (helix.getYb()/10.0)); // fills the list of cross ids for crosses belonging to that reconstructed track for (int j = 0; j < 9; j++) { String hitStrg = "Cross"; @@ -495,8 +495,8 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { bank.setFloat("tandip", i, (float) helix.get_tandip()); bank.setFloat("z0", i, (float) (helix.get_Z0()/10.)); bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); - bank.setFloat("xb", i, (float) (Constants.getXb()/10.0)); - bank.setFloat("yb", i, (float) (Constants.getYb()/10.0)); + bank.setFloat("xb", i, (float) (helix.getXb()/10.0)); + bank.setFloat("yb", i, (float) (helix.getYb()/10.0)); // this is the format of the covariance matrix for helical tracks // cov matrix = // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index a8a542e95..c9708c4c4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -291,17 +291,6 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) } - // beam offset - double xb = dbprovider.getDouble("/geometry/beam/position/x_offset", 0); - double yb = dbprovider.getDouble("/geometry/beam/position/y_offset", 0); - double exb = dbprovider.getDouble("/geometry/beam/position/x_error", 0); - double eyb = dbprovider.getDouble("/geometry/beam/position/y_error", 0); - double err = 0; - if(Math.sqrt(xb*xb+yb*yb)!=0) err = Math.sqrt((Math.pow(xb*exb,2)+Math.pow(yb*eyb,2))/(xb*xb+yb*yb)); - - Constants.setXb(xb*10); - Constants.setYb(yb*10); - // target position mm Constants.setZoffset(ztarget*10); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index 1297b2977..b0701d650 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -53,7 +53,7 @@ public HelixCrossListFinder() { * @return the list of crosses determined to be consistent with belonging to * a track in the cvt */ - public List findCandidateCrossLists(List> cvt_crosses, Swim swimmer) { + public List findCandidateCrossLists(List> cvt_crosses, double xb, double yb, Swim swimmer) { float[] bfield = new float[3]; swimmer.BfieldLab(0, 0, 0, bfield); double bz = Math.abs(bfield[2]); @@ -172,11 +172,11 @@ public List findCandidateCrossLists(List R1Crosses, double bz) { + private void MatchToRegion1(Seed s, ArrayList R1Crosses, double xb, double yb, double bz) { if(s==null) return; - boolean fitStatus = s.fit(3, true, bz); + boolean fitStatus = s.fit(3, xb, yb, bz); if(!fitStatus) return; @@ -485,9 +485,9 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, double bz) { } - private void MatchBMTC(Seed s, ArrayList BMTCrosses, double bz) { + private void MatchBMTC(Seed s, ArrayList BMTCrosses, double xb, double yb, double bz) { - boolean fitStatus = s.fit(3, true, bz); + boolean fitStatus = s.fit(3, xb, yb, bz); if(!fitStatus) return; double maxChi2 = Double.POSITIVE_INFINITY; @@ -497,7 +497,7 @@ private void MatchBMTC(Seed s, ArrayList BMTCrosses, double bz) { continue; } else { s.get_Crosses().add(BMTCrosses.get(i)); - fitStatus = s.fit(3, true, bz); + fitStatus = s.fit(3, xb, yb, bz); if(!fitStatus) continue; double linechi2perndf = s.get_lineFitChi2PerNDF(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java index 7d74be40c..4833ee14e 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitter.java @@ -42,9 +42,9 @@ public class CircleFitter { /** * Constructor Sets the reference point to (0,0) */ - public CircleFitter() { - _xref = Constants.getXb(); - _yref = Constants.getYb(); + public CircleFitter(double xb, double yb) { + _xref = xb; + _yref = yb; _covr = new double[6]; } // Now set the reference point for the fit @@ -370,7 +370,7 @@ public static void main(String[] args) { System.out.println("calculated radius " + CircRad + " --> pt=" + (Constants.LIGHTVEL * 5.14 * CircRad)); - CircleFitter _circlefit = new CircleFitter(); + CircleFitter _circlefit = new CircleFitter(0, 0); boolean circlefitstatusOK = _circlefit.fitStatus(xm, ym, wm, xm.size()); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java index 458b18227..94b5db406 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/HelicalTrackFitter.java @@ -18,8 +18,8 @@ public class HelicalTrackFitter { private Helix _helix; // fit helix private double[] _chisq = new double[2]; // fit chi-squared [0]: circle [1] line - private CircleCalculator _circlecalc = new CircleCalculator(); - private CircleFitter _circlefit = new CircleFitter(); + private CircleCalculator _circlecalc; + private CircleFitter _circlefit; private LineFitter _linefit = new LineFitter(); private CircleCalcPars _circlecalcpars; private CircleFitPars _circlefitpars; @@ -61,7 +61,7 @@ public HelicalTrackFitter() { private final List P1 = new ArrayList<>(2); private final List P2 = new ArrayList<>(2); - public FitStatus fit(List X, List Y, List Z, List Rho, List errRt, List errRho, List ErrZ) { + public FitStatus fit(List X, List Y, List Z, List Rho, List errRt, List errRho, List ErrZ, double xb, double yb) { // Initialize the various fitter outputs _circlefitpars = null; _linefitpars = null; @@ -83,7 +83,7 @@ public FitStatus fit(List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List cosmics = new ArrayList<>(); for (int k1 = 0; k1 < cosmicCands.size(); k1++) { Ray ray = cosmicCands.get(k1).get_ray(); @@ -103,7 +102,7 @@ public boolean processEvent(DataEvent event, cov[3][3]=0.001; cov[4][4]=1; kf.init(ray.get_yxinterc(),ray.get_yzinterc(), - ray.get_yxslope(), ray.get_yzslope(), 10.0, cov, + ray.get_yxslope(), ray.get_yzslope(), Units.MM, cov, measures.getMeasurements(cosmicCands.get(k1))); kf.mv.setDelta_d_a(new double[]{0.1, 0.1, 0.0001, 0.0001, 1}); kf.runFitter(); @@ -133,7 +132,7 @@ public boolean processEvent(DataEvent event, cosmic.addAll(pseudoCrosses); //VZ check for additional clusters, and only then re-run KF adding new clusters //refit kf.init(cosmic.get_ray().get_yxinterc(),cosmic.get_ray().get_yzinterc(), - cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), 10.0, cov, + cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), Units.CM, cov, measures.getMeasurements(cosmicCands.get(k1))) ; kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 8037e9056..96b36d696 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -83,11 +83,11 @@ public void CleanupSpuriousCrosses(List> crosses, List t } } - public List setMeasVecs(Seed trkcand, Swim swim) { + public List setMeasVecs(Seed trkcand, double xb, double yb, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList<>(); Vector3D u = new Vector3D(0,0,1); - Point3D p = new Point3D(Constants.getXb(),Constants.getYb(),0); + Point3D p = new Point3D(xb, yb, 0); Line3D l = new Line3D(p, u); Surface meas0 = new Surface(l.origin(), l.end(), Constants.DEFAULTSWIMACC); meas0.setSector(0); @@ -138,7 +138,7 @@ public List setMeasVecs(StraightTrack trkcand, Swim swim) { //Collections.sort(trkcand.get_Crosses()); List KFSites = new ArrayList<>(); Vector3D u = trkcand.get_ray().get_dirVec(); - Plane3D pln0 = new Plane3D(new Point3D(Constants.getXb(),Constants.getYb(),Constants.getZoffset()), u); + Plane3D pln0 = new Plane3D(new Point3D(0, 0, 0), u); Surface meas0 = new Surface(pln0,new Point3D(0,0,0), new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); meas0.setSector(0); @@ -303,7 +303,8 @@ public List FindClustersOnTrack(List allClusters, StraightTrac public List FindClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; - swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, + Point3D vertex = helix.getVertex(); + swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), P, Q, maxPathLength) ; double[] inters = null; @@ -385,7 +386,8 @@ public List FindClustersOnTrk(List allClusters, List public List findBMTClustersOnTrk(List allClusters, List seedCrosses, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; - swimmer.SetSwimParameters((helix.xdca()+Constants.getXb()) / 10, (helix.ydca()+Constants.getYb()) / 10, helix.get_Z0() / 10, + Point3D vertex = helix.getVertex(); + swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), P, Q, maxPathLength) ; double[] inters = null; @@ -521,66 +523,66 @@ else if (trkcand.get_Crosses().get(c).get_Type()==BMTType.C) { } } - public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { - org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), - kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), - kf.KFHelix.getZ0(), kf.KFHelix.getTanL()); - helix.B = kf.KFHelix.getB(); - Track cand = new Track(helix); - cand.setNDF(kf.NDF); - cand.setChi2(kf.chi2); - - for (Cross c : seed.get_Crosses()) { - if (c.get_Detector()==DetectorType.BST) { - continue; - } - } - - this.MatchTrack2Traj(seed, kf.TrjPoints); - cand.addAll(seed.get_Crosses()); - for(Cluster cl : seed.get_Clusters()) { - - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); - - if(cl.get_Detector()==DetectorType.BMT) { - - layer = layer + 6; - - if(cl.get_Type() == BMTType.C) { - - Line3D cln = cl.getAxis(); - cl.setN(cln.distance(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).direction().asUnit()); - cl.setL(cl.getS().cross(cl.getN()).asUnit()); - - } - - } - //double x = kf.TrjPoints.get(layer).x; - //double y = kf.TrjPoints.get(layer).y; - //double z = kf.TrjPoints.get(layer).z; - //double px = kf.TrjPoints.get(layer).px; - //double py = kf.TrjPoints.get(layer).py; - //double pz = kf.TrjPoints.get(layer).pz; - cl.setTrakInters(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)); - } - - return cand; - - } - public Track OutputTrack(StraightTrack seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { - org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), - kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), - kf.KFHelix.getZ0(), kf.KFHelix.getTanL()); - helix.B = kf.KFHelix.getB(); - Track cand = new Track(helix); - cand.setNDF(kf.NDF); - cand.setChi2(kf.chi2); - cand.addAll(seed); - - return cand; - - } +// public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { +// org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), +// kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), +// kf.KFHelix.getTanL(), kf.KFHelix.getXb(), kf.KFHelix.getYb()); +// helix.B = kf.KFHelix.getB(); +// Track cand = new Track(helix); +// cand.setNDF(kf.NDF); +// cand.setChi2(kf.chi2); +// +// for (Cross c : seed.get_Crosses()) { +// if (c.get_Detector()==DetectorType.BST) { +// continue; +// } +// } +// +// this.MatchTrack2Traj(seed, kf.TrjPoints); +// cand.addAll(seed.get_Crosses()); +// for(Cluster cl : seed.get_Clusters()) { +// +// int layer = cl.get_Layer(); +// int sector = cl.get_Sector(); +// +// if(cl.get_Detector()==DetectorType.BMT) { +// +// layer = layer + 6; +// +// if(cl.get_Type() == BMTType.C) { +// +// Line3D cln = cl.getAxis(); +// cl.setN(cln.distance(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).direction().asUnit()); +// cl.setL(cl.getS().cross(cl.getN()).asUnit()); +// +// } +// +// } +// //double x = kf.TrjPoints.get(layer).x; +// //double y = kf.TrjPoints.get(layer).y; +// //double z = kf.TrjPoints.get(layer).z; +// //double px = kf.TrjPoints.get(layer).px; +// //double py = kf.TrjPoints.get(layer).py; +// //double pz = kf.TrjPoints.get(layer).pz; +// cl.setTrakInters(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)); +// } +// +// return cand; +// +// } +// public Track OutputTrack(StraightTrack seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { +// org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), +// kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), +// kf.KFHelix.getZ0(), kf.KFHelix.getTanL()); +// helix.B = kf.KFHelix.getB(); +// Track cand = new Track(helix); +// cand.setNDF(kf.NDF); +// cand.setChi2(kf.chi2); +// cand.addAll(seed); +// +// return cand; +// +// } // public Track OutputTrack(Seed seed) { // // Track cand = new Track(seed.get_Helix()); @@ -639,14 +641,14 @@ public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { seedlist.addAll(trseed.findSeed(refi, refib, false)); return seedlist; } - public boolean reFitCircle(Seed seed, int iter) { + public boolean reFitCircle(Seed seed, int iter, double xb, double yb) { boolean fitStatus = false; List Xs = new ArrayList<>() ; List Ys = new ArrayList<>() ; List Ws = new ArrayList<>() ; - CircleFitter circlefit = new CircleFitter(); + CircleFitter circlefit = new CircleFitter(xb, yb); for(int i = 0; i< iter; i++) { Xs.clear(); Ys.clear(); @@ -677,9 +679,9 @@ public boolean reFitCircle(Seed seed, int iter) { return fitStatus; } - public List reFit(List seedlist, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { - trseed = new TrackSeederCA(swimmer); - trseed2 = new TrackSeeder(swimmer); + public List reFit(List seedlist, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2, double xb, double yb) { + trseed = new TrackSeederCA(swimmer, xb, yb); + trseed2 = new TrackSeeder(swimmer, xb, yb); List filtlist = new ArrayList(); if(seedlist==null) return filtlist; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 512692e76..30226e87a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -36,6 +36,7 @@ public boolean processEvent(DataEvent event, List SVThits, List BMThits, List SVTclusters, List BMTclusters, List> crosses, + double xb, double yb, RecoBankWriter rbc, Swim swimmer) { @@ -46,7 +47,7 @@ public boolean processEvent(DataEvent event, // make list of crosses consistent with a track candidate List seeds = null; if(solenoidValue<0.001) { - StraightTrackSeeder trseed = new StraightTrackSeeder(); + StraightTrackSeeder trseed = new StraightTrackSeeder(xb, yb); seeds = trseed.findSeed(crosses.get(0), crosses.get(1), Constants.SVTOnly); // RDV, disabled because it seems to create fake tracks, skipping measurement in KF // if(Constants.EXCLUDELAYERS==true) { @@ -54,16 +55,16 @@ public boolean processEvent(DataEvent event, // } } else { if(Constants.SVTOnly) { - TrackSeeder trseed = new TrackSeeder(swimmer); + TrackSeeder trseed = new TrackSeeder(swimmer, xb, yb); trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null); } else { - TrackSeederCA trseed = new TrackSeederCA(swimmer); // cellular automaton seeder + TrackSeederCA trseed = new TrackSeederCA(swimmer, xb, yb); // cellular automaton seeder seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA if(Constants.svtSeeding) { - TrackSeeder trseed2 = new TrackSeeder(swimmer); + TrackSeeder trseed2 = new TrackSeeder(swimmer, xb, yb); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); // RDV, disabled because it seems to create fake tracks, skipping measurement in KF @@ -74,7 +75,7 @@ public boolean processEvent(DataEvent event, if(!Constants.seedBeamSpotConstraint()) { List failed = new ArrayList<>(); for(Seed s : seeds) { - if(!recUtil.reFitCircle(s, Constants.SEEDFITITERATIONS)) + if(!recUtil.reFitCircle(s, Constants.SEEDFITITERATIONS, xb, yb)) failed.add(s); } seeds.removeAll(failed); @@ -99,17 +100,13 @@ public boolean processEvent(DataEvent event, trkcands.clear(); KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.kfMatLib); - Measurements surfaces = new Measurements(false, swimmer); + Measurements surfaces = new Measurements(false, xb, yb); for (Seed seed : seeds) { Point3D v = seed.get_Helix().getVertex(); Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); int charge = (int) (Math.signum(solenoidScale)*seed.get_Helix().get_charge()); if(solenoidValue<0.001) charge = 1; - v.translateXYZ(Constants.getXb(), - Constants.getYb(), - 0); - double[] pars = recUtil.MCtrackPars(event); if(Constants.INITFROMMC) { v = new Point3D(pars[0],pars[1],pars[2]); @@ -117,13 +114,13 @@ public boolean processEvent(DataEvent event, if(solenoidValue<0.001) p.scale(100/p.mag()); } Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, - solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); + solenoidValue, xb , yb, Helix.Units.MM); double[][] cov = seed.get_Helix().get_covmatrix(); if(solenoidValue>0.001 && Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0 && kf.KFHelix!=null) { Track fittedTrack = new Track(seed, kf); @@ -159,11 +156,10 @@ public boolean processEvent(DataEvent event, charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); if(solenoidValue<0.001) charge = 1; - v.translateXYZ(Constants.getXb(),Constants.getYb(), 0); hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, - solenoidValue, Constants.getXb(), Constants.getYb(), Helix.Units.MM); + solenoidValue, xb, yb, Helix.Units.MM); - kf.init(hlx, cov, Constants.getXb(), Constants.getYb(), 0, surfaces.getMeasurements(seed)) ; + kf.init(hlx, cov, xb, yb, 0, surfaces.getMeasurements(seed)) ; kf.runFitter(); // RDV get rid of added clusters if not true diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java index d2a1144dd..97c09df37 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java @@ -50,7 +50,7 @@ public EnergyLossCorr(Track trkcand, Swim bstSwim) { massHypo = trkcand.get_PID(); OrigTrack = new Helix(trkcand.get_helix().get_dca(), trkcand.get_helix().get_phi_at_dca(), trkcand.get_helix().get_curvature(), - trkcand.get_helix().get_Z0(), trkcand.get_helix().get_tandip(), null); + trkcand.get_helix().get_Z0(), trkcand.get_helix().get_tandip(), trkcand.get_helix().getXb(), trkcand.get_helix().getYb(), null); init(trkcand, bstSwim); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java index 051f260bf..560f89769 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java @@ -29,25 +29,23 @@ public class Measurements { BMTGeometry.NLAYERS; private boolean cosmic = false; private Surface[] cvtSurfaces; - private Swim swimmer = null; private boolean debug = false; - public Measurements(boolean cosmic, Swim swimmer) { + public Measurements(boolean cosmic, double xbeam, double ybeam) { this.cosmic = cosmic; - this.swimmer = swimmer; - this.init(); + this.init(xbeam, ybeam); } - private void init() { + private void init(double xbeam, double ybeam) { if(this.cosmic) this.initCosmicSurfaces(); else - this.initTargetSurfaces(); + this.initTargetSurfaces(xbeam, ybeam); } - private void initTargetSurfaces() { + private void initTargetSurfaces(double xbeam, double ybeam) { cvtSurfaces = new Surface[NSURFACES+1]; - this.add(CVTLayer.TARGET.getIndex(), this.getTarget()); + this.add(CVTLayer.TARGET.getIndex(), this.getTarget(xbeam, ybeam)); this.add(CVTLayer.SHIELD.getIndex(), Constants.SVTGEOMETRY.getShieldSurface()); this.add(CVTLayer.INNERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0)); this.add(CVTLayer.OUTERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1)); @@ -85,9 +83,9 @@ private int getIndex(CVTLayer id, int hemisphere) { return id.getIndex(hemisphere); } - private Surface getTarget() { + private Surface getTarget(double xbeam, double ybeam) { Vector3D u = new Vector3D(0,0,1); - Point3D p = new Point3D(Constants.getXb(),Constants.getYb(),0); + Point3D p = new Point3D(xbeam, ybeam, 0); Line3D l = new Line3D(p, u); Surface target = new Surface(l.origin(), l.end(), Constants.DEFAULTSWIMACC); target.setError(Constants.getRbErr()); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index 25885aac0..1830062c7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -192,8 +192,7 @@ public int compareTo(Seed arg) { } - public boolean fit(int fitIter, boolean originConstraint, - double bfield) { + public boolean fit(int fitIter, double xb, double yb, double bfield) { List X = new ArrayList<>(); List Y = new ArrayList<>(); @@ -247,15 +246,6 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { HelicalTrackFitter fitTrk = new HelicalTrackFitter(); for (int i = 0; i < fitIter; i++) { - // if(originConstraint==true) { - // X.add(0, (double) 0); - // Y.add(0, (double) 0); - // Z.add(0, (double) 0); - // Rho.add(0, (double) 0); - // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); - // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); - // } X.clear(); Y.clear(); Z.clear(); @@ -296,12 +286,11 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); } } - X.add((double) Constants.getXb()); - Y.add((double) Constants.getYb()); - + X.add(xb); + Y.add(yb); ErrRt.add((double) 0.1); - FitStatus fitStatus = fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + FitStatus fitStatus = fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); if (fitStatus!=FitStatus.Successful || fitTrk.get_helix() == null) { return false; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index fb8003cdb..09146f691 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -26,8 +26,12 @@ public class StraightTrackSeeder { List Xs ; List Ys ; List Ws ; + double xbeam; + double ybeam; - public StraightTrackSeeder() { + public StraightTrackSeeder(double xb, double yb) { + xbeam = xb; + ybeam = yb; //init lists for scan sortedCrosses = new ArrayList>>(); for(int b =0; b seedcrs) { ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, Constants.getXb()); - Ys.add(0, Constants.getYb()); + Xs.add(0, this.xbeam); + Ys.add(0, this.ybeam); Ws.add(0,0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); @@ -102,7 +106,7 @@ private void FitSeed(List seedcrs) { Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); } - CircleFitter circlefit = new CircleFitter(); + CircleFitter circlefit = new CircleFitter(xbeam, ybeam); boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); CircleFitPars pars = circlefit.getFit(); if(circlefitstatusOK==false ) @@ -255,8 +259,8 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, Constants.getXb()); - Ys.add(0, Constants.getYb()); + Xs.add(0, this.xbeam); + Ys.add(0, this.ybeam); Ws.add(0, 0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) continue; @@ -267,7 +271,7 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo +c.get_PointErr().y()*c.get_PointErr().y())); } - CircleFitter circlefit = new CircleFitter(); + CircleFitter circlefit = new CircleFitter(xbeam, ybeam); circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); CircleFitPars pars = circlefit.getFit(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 98b1affe2..0f1e07823 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -64,7 +64,8 @@ public Track(Seed seed) { public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { super(new Helix(kf.KFHelix.getD0(), kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), - kf.KFHelix.getZ0(), kf.KFHelix.getTanL())); + kf.KFHelix.getZ0(), kf.KFHelix.getTanL(), + kf.KFHelix.getXb(), kf.KFHelix.getYb())); this.get_helix().B = kf.KFHelix.getB(); this.kfIterations = kf.numIter; double c = Constants.LIGHTVEL; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java index 85668720d..a22b7d75f 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java @@ -136,7 +136,7 @@ public class RayMeasurements { * @param list the input list of crosses * @return an array list of track candidates in the SVT */ - public void getHelicalTrack(Seed cand) { + public void getHelicalTrack(Seed cand, double xb, double yb) { X.clear(); Y.clear(); Z.clear(); @@ -172,7 +172,7 @@ public void getHelicalTrack(Seed cand) { Number_Of_Iterations++; fitTrk = new HelicalTrackFitter(); // get the measuerement arrays for the helical track fit - HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(list, shift, ignoreErr, false); + HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(list, xb, yb, shift, ignoreErr, false); X = MeasArrays._X; Y = MeasArrays._Y; @@ -184,12 +184,12 @@ public void getHelicalTrack(Seed cand) { // do the fit to X, Y taking ErrRt uncertainties into account to get the circle fit params, // and do the fit to Rho, Z taking into account the uncertainties in Rho and Z into account to get the linefit params - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); // if the fit failed then use the uncorrected SVT points since the z-correction in resetting the SVT cross points sometimes fails if (fitTrk.get_helix() == null) { //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - MeasArrays = this.get_HelixMeasurementsArrays(list, shift, ignoreErr, true); + MeasArrays = this.get_HelixMeasurementsArrays(list, xb, yb, shift, ignoreErr, true); X = MeasArrays._X; Y = MeasArrays._Y; @@ -199,7 +199,7 @@ public void getHelicalTrack(Seed cand) { ErrRho = MeasArrays._ErrRho; ErrRt = MeasArrays._ErrRt; - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); Number_Of_Iterations = Max_Number_Of_Iterations + 1; //if(fitTrk.get_helix()==null) //System.err.println("Error in Helical Track fitting -- helix not found -- refit FAILED"); @@ -220,7 +220,7 @@ public void getHelicalTrack(Seed cand) { * @param crossList the input list of crosses * @return an array list of track candidates in the SVT */ - public ArrayList getHelicalTracks(CrossList crossList, Swim swimmer) { + public ArrayList getHelicalTracks(CrossList crossList, double xb, double yb, Swim swimmer) { X.clear(); Y.clear(); @@ -258,7 +258,7 @@ public ArrayList getHelicalTracks(CrossList crossList, Swim swimmer) { Number_Of_Iterations++; fitTrk = new HelicalTrackFitter(); // get the measuerement arrays for the helical track fit - HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), shift, ignoreErr, false); + HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), xb, yb, shift, ignoreErr, false); X = MeasArrays._X; Y = MeasArrays._Y; @@ -270,12 +270,12 @@ public ArrayList getHelicalTracks(CrossList crossList, Swim swimmer) { // do the fit to X, Y taking ErrRt uncertainties into account to get the circle fit params, // and do the fit to Rho, Z taking into account the uncertainties in Rho and Z into account to get the linefit params - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); // if the fit failed then use the uncorrected SVT points since the z-correction in resetting the SVT cross points sometimes fails if (fitTrk.get_helix() == null) { //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), shift, ignoreErr, true); + MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), xb, yb, shift, ignoreErr, true); X = MeasArrays._X; Y = MeasArrays._Y; @@ -285,7 +285,7 @@ public ArrayList getHelicalTracks(CrossList crossList, Swim swimmer) { ErrRho = MeasArrays._ErrRho; ErrRt = MeasArrays._ErrRt; - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); + fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); Number_Of_Iterations = Max_Number_Of_Iterations + 1; //if(fitTrk.get_helix()==null) //System.err.println("Error in Helical Track fitting -- helix not found -- refit FAILED"); @@ -552,7 +552,7 @@ public void upDateCrossesFromTraj(StraightTrack cand, Trajectory trj) { } private HelixMeasurements get_HelixMeasurementsArrays(List list, - int shift, boolean ignoreErr, boolean resetSVTMeas) { + double xb, double yb, int shift, boolean ignoreErr, boolean resetSVTMeas) { X.clear(); Y.clear(); Z.clear(); @@ -599,11 +599,9 @@ private HelixMeasurements get_HelixMeasurementsArrays(List list, if (shift == 1) { //X.add(0, (double) 0); //Y.add(0, (double) 0); - double xb = Constants.getXb(); - double yb = Constants.getYb(); double rb = Math.sqrt(xb*xb+yb*yb); - X.add(0, (double) Constants.getXb()); - Y.add(0, (double) Constants.getYb()); + X.add(0, xb); + Y.add(0, yb); //Z.add(0, (double) 0); //Rho.add(0, (double) 0); Rho.add(0, (double) rb); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 5f5168031..88fc7f9a3 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -47,7 +47,7 @@ public static List getTracks(List cands, Swim cvtSwim) { int charge = trk.get_Q(); double maxPathLength = 5.0;//very loose cut - cvtSwim.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().ydca()+Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10 , + cvtSwim.SetSwimParameters((trk.get_helix().xdca()+trk.get_helix().getXb()) / 10, (trk.get_helix().ydca()+trk.get_helix().getYb()) / 10, trk.get_helix().get_Z0() / 10 , Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), trk.get_P(), charge, maxPathLength) ; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java index f272a7af6..e5cb6cd10 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeeder.java @@ -31,9 +31,11 @@ public class TrackSeeder { List Xs ; List Ys ; List Ws ; + double xbeam; + double ybeam; public boolean unUsedHitsOnly = false; - public TrackSeeder(Swim swimmer) { + public TrackSeeder(Swim swimmer, double xb, double yb) { float[] b = new float[3]; swimmer.BfieldLab(0, 0, 0, b); this.bfield = Math.abs(b[2]); @@ -53,6 +55,8 @@ public TrackSeeder(Swim swimmer) { Xs = new ArrayList(); Ys = new ArrayList(); Ws = new ArrayList(); + xbeam = xb; + ybeam = yb; } private void MatchSeed(List othercrs) { @@ -90,8 +94,8 @@ public void FitSeed(List seedcrs) { ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, Constants.getXb()); - Ys.add(0, Constants.getYb()); + Xs.add(0, xbeam); + Ys.add(0, ybeam); Ws.add(0,0.1); for (Cross c : seedcrs ) { if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); @@ -100,7 +104,7 @@ public void FitSeed(List seedcrs) { Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); } - CircleFitter circlefit = new CircleFitter(); + CircleFitter circlefit = new CircleFitter(xbeam, ybeam); boolean circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); CircleFitPars pars = circlefit.getFit(); if(circlefitstatusOK==false ) @@ -274,8 +278,8 @@ public List findSeed(List bst_crosses, List bmt_crosses) { ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, Constants.getXb()); - Ys.add(0, Constants.getYb()); + Xs.add(0, xbeam); + Ys.add(0, ybeam); Ws.add(0, 0.1); for (Cross c : seedcrs ) { // if(c.get_Type()==BMTType.C ) continue; @@ -286,7 +290,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { +c.get_PointErr().y()*c.get_PointErr().y())); } - CircleFitter circlefit = new CircleFitter(); + CircleFitter circlefit = new CircleFitter(xbeam, ybeam); circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); CircleFitPars pars = circlefit.getFit(); @@ -318,7 +322,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { for(Seed mseed : seedScan) { boolean fitStatus = false; if(mseed.get_Crosses().size()>=3) - fitStatus = mseed.fit(Constants.SEEDFITITERATIONS, false, this.bfield); + fitStatus = mseed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); if (fitStatus) { List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(mseed, bmtC_crosses); BMTmatches.clear(); @@ -331,7 +335,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { double chi2_Line = Double.POSITIVE_INFINITY; for (Seed bseed : BMTmatches) { //refit using the BMT - fitStatus = bseed.fit(Constants.SEEDFITITERATIONS, false, this.bfield); + fitStatus = bseed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); if (fitStatus && bseed.get_circleFitChi2PerNDF()> getCAcandidates(List nodes) { if( cand.get(0).get_plane().equalsIgnoreCase("XY")) { if( candlen > 2 ){ Seed seed = new Seed(getCrossFromCells(cand)); - if(seed.fit(2, false, bfield)) { + if(seed.fit(2, xbeam, ybeam, bfield)) { cellCands.add(cand); for( Cell n : cand ) { @@ -237,7 +241,7 @@ public List findSeed(List svt_crosses, List bmt_crosses) { // Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters // Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, Constants.SEEDFITITERATIONS, false, swimmer); Seed candSeed = new Seed(seedCrosses.get(s)); - boolean fitStatus = candSeed.fit(Constants.SEEDFITITERATIONS, false, bfield); + boolean fitStatus = candSeed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); if (fitStatus && candSeed.isGood()) { cands.add(candSeed); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index 298e18f58..d79e74179 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -27,6 +27,8 @@ public class Helix { private double _Z0; // intersect of the helix axis with the z-axis private double _tandip; // tangent of the dip angle private double[][] _covmatrix = new double[5][5]; + private double xb; + private double yb; //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | // | d_phi_at_dca*d_dca d_phi_at_dca*d_phi_at_dca d_phi_at_dca*d_curvature 0 0 | @@ -35,23 +37,38 @@ public class Helix { // | 0 0 0 0 d_tandip*d_tandip | // - public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double[][] covmatrix) { - set_dca(dca); - set_phi_at_dca(phi_at_doca); - set_curvature(curvature); - set_Z0(Z0); - set_tandip(tandip); + public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double xb, double yb, double[][] covmatrix) { + this(dca, phi_at_doca, curvature, Z0, tandip, xb, yb); set_covmatrix(covmatrix); } - public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip ) { + public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double xb, double yb) { set_dca(dca); set_phi_at_dca(phi_at_doca); set_curvature(curvature); set_Z0(Z0); set_tandip(tandip); + setXb(xb); + setYb(yb); + } + + public double getXb() { + return xb; } + public final void setXb(double xb) { + this.xb = xb; + } + + public double getYb() { + return yb; + } + + public final void setYb(double yb) { + this.yb = yb; + } + + public double get_dca() { return _dca; } @@ -149,7 +166,7 @@ public double ydca() { } public Point3D getVertex() { - return new Point3D(this.xdca(),this.ydca(),this.get_Z0()); + return new Point3D(this.xdca()+this.getXb(),this.ydca()+this.getYb(),this.get_Z0()); } public double getPt(double solenoidMag) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 44efbc668..0dd6453ae 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -118,9 +118,10 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { double pz = trk.get_Pt()*trk.get_helix().get_tandip(); double px = trk.get_Pt()*Math.cos(trk.get_helix().get_phi_at_dca()); double py = trk.get_Pt()*Math.sin(trk.get_helix().get_phi_at_dca()); - double x = (trk.get_helix().xdca()+Constants.getXb()) / 10; - double y = (trk.get_helix().ydca()+Constants.getYb()) / 10; - double z = trk.get_helix().get_Z0() / 10; + Point3D vertex = trk.get_helix().getVertex(); + double x = vertex.x()/10; + double y = vertex.y()/10; + double z = vertex.z()/10; swimmer.SetSwimParameters(x,y,z,px,py,pz, trk.get_Q()) ; double[] inters = null; @@ -183,7 +184,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { } // reinitialize from vertex maxPathLength = 1.5; - swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().ydca()+Constants.getYb()) / 10, trk.get_helix().get_Z0() / 10, + swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), trk.get_P(), trk.get_Q(), maxPathLength) ; inters = null; From e981a1d341287e4bf8ca8851b0d8e43cb247b0fb Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Tue, 18 Jan 2022 01:14:25 -0500 Subject: [PATCH 269/291] modified RecoBankReader.java to allow compilation --- .../src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index b1f9d1e3c..e34eac45e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -341,7 +341,7 @@ public void fetch_Tracks(DataEvent event, double zShift) { for(int i = 0; i Date: Tue, 18 Jan 2022 01:16:04 -0500 Subject: [PATCH 270/291] modified CVTAlignment.java to allow compilation --- .../src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index f2c2f6cbd..60f0b2e2b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -430,7 +430,7 @@ private Helix createHelixFromRay(Ray ray) { double curvature = 0; double Z0 = xref.z()-u.z()*xref.dot(uT)/u.dot(uT); double tandip = u.z()/Math.hypot(u.x(), u.y()); - return new Helix(d, phi, curvature, Z0, tandip, null); + return new Helix(d, phi, curvature, Z0, tandip, 0,0); } int nAlignables; From c0ced70288e7eebbea26a812fb3f6f235cde7d1b Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 18 Jan 2022 21:54:11 +0100 Subject: [PATCH 271/291] Disabled reseeding when excludeLayers option is chosen for cosmics. The layer exclusion will happen in the KF --- .../java/org/jlab/rec/cvt/services/CosmicTracksRec.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index bc0bddff2..348c94baa 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -60,10 +60,10 @@ public boolean processEvent(DataEvent event, return true; } - if(Constants.EXCLUDELAYERS==true) { - CosmicFitter fitTrk = new CosmicFitter(); - cosmicCands = recUtil.reFit(cosmicCands, fitTrk, trkcandFinder); - } +// if(Constants.EXCLUDELAYERS==true) { +// CosmicFitter fitTrk = new CosmicFitter(); +// cosmicCands = recUtil.reFit(cosmicCands, fitTrk, trkcandFinder); +// } if (cosmicCands.size() > 0) { for (int k1 = 0; k1 < cosmicCands.size(); k1++) { From 31ed42b790015c46678fe5304bbf6f3de7565817 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 18 Jan 2022 23:00:16 +0100 Subject: [PATCH 272/291] clas-tracking cleanups: removed commented code, fixed warnings, ... --- .../tracking/kalmanfilter/AStateVecs.java | 2 - .../kalmanfilter/helical/StateVecs.java | 96 ------------------- .../kalmanfilter/straight/StateVecs.java | 13 +-- .../org/jlab/clas/tracking/objects/Cross.java | 13 ++- .../jlab/clas/tracking/objects/Segment.java | 13 ++- .../org/jlab/clas/tracking/objects/Strip.java | 14 ++- .../jlab/clas/tracking/objects/TObject.java | 5 - .../tracking/patternrec/CircleHoughTrans.java | 27 +++--- .../tracking/patternrec/LineHoughTrans.java | 27 +++--- .../clas/tracking/trackrep/Trajectory.java | 5 - .../tracking/utilities/OverlapRemover.java | 9 +- .../utilities/SelectEventsToFile.java | 9 +- 12 files changed, 54 insertions(+), 179 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java index 983f6c712..b96c9dcdc 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AStateVecs.java @@ -69,8 +69,6 @@ private double[][] propagateMatrix(StateVec ivec, StateVec fvec, double[][] matr return multiplyMatrices(FMat, matrix, FMatT); } - public abstract Helix setTrackPars(); - private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { int r1 = firstMatrix.length; int c1 = firstMatrix[0].length; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 29bab8f89..c8f71ecdd 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -250,91 +250,6 @@ public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { return Q; } -// private void setHelix(Helix util, double x0, double y0, double z0, double px0, double py0, double pz0, -// int q, double B) { -// util.setTurningSign(q); -// util.setB(B); -// double pt = Math.sqrt(px0*px0 + py0*py0); -// util.setR(pt/(B*util.getLightVelocity())) ; -// util.setPhi0(Math.atan2(py0, px0)); -// util.setTanL(pz0/pt); -// util.setZ0(z0); -// util.setOmega((double) -q/util.getR()); -// -// double S = Math.sin(util.getPhi0()); -// double C = Math.cos(util.getPhi0()); -// -// util.setCosphi0(C); -// util.setSinphi0(S); -// -// if(Math.abs(S)>=Math.abs(C)) { -// util.setD0(-(x0-X0.get(0))/S) ; -// } else { -// util.setD0((y0-Y0.get(0))/C) ; -// } -// -// util.update(); -// } -// private void setHelixPars(StateVec kVec, Swim swim) { -// StateVec vec = new StateVec(0, kVec); -// vec.updateHelix(); -// vec.phi = 0; -// vec.updateFromHelix(); -// -// double x0 = X0.get(vec.k) + vec.d_rho * Math.cos(vec.phi0) ; -// double y0 = Y0.get(vec.k) + vec.d_rho * Math.sin(vec.phi0) ; -// double z0 = Z0.get(vec.k) + vec.dz ; -// double invKappa = 1. / Math.abs(vec.kappa); -// double px0 = -invKappa * Math.sin(vec.phi0 ); -// double py0 = invKappa * Math.cos(vec.phi0 ); -// double pz0 = invKappa * vec.tanL; -// -// int ch = (int) KFitter.polarity*(int) Math.signum(vec.kappa); -// -// double B = 1. / (lightVel * vec.alpha); -//// System.out.println(x0 + " " + y0 + " " + z0 + " " + px0 + " " + py0 + " " + pz0); -// this.setHelix(util, x0,y0,z0,px0,py0,pz0,ch, B); -// } - -// @Override -// public void setTrackPars(StateVec kVec, Swim swim) { -// -// double x0 = kVec.x0 + kVec.d_rho * Math.cos(kVec.phi0) ; -// double y0 = kVec.y0 + kVec.d_rho * Math.sin(kVec.phi0) ; -// double z0 = kVec.z0 + kVec.dz ; -// double invKappa = 1. / Math.abs(kVec.kappa); -// double px0 = -invKappa * Math.sin(kVec.phi0 ); -// double py0 = invKappa * Math.cos(kVec.phi0 ); -// double pz0 = invKappa * kVec.tanL; -// int ch = (int) KFitter.polarity*(int) Math.signum(kVec.kappa); -//// System.out.println("old pivot " + new Point3D(x0,y0,z0).toString() + new Vector3D(px0,py0,pz0).toString()); -// swim.SetSwimParameters( -// x0/units, -// y0/units, -// z0/units, -// px0, py0, pz0, ch); -// } - - -// private void iterateHelixAtR(int it, int k, StateVec kVec, Swim swim, -// double r, B Bf, Point3D ps) { -// for(int i = 0; i < it; i++) { -// this.setHelixPars(kVec, swim); -// ps = util.getHelixPointAtR(r); -// kVec.x = ps.x(); -// kVec.y = ps.y(); -// kVec.z = ps.z(); -// this.tranState(k, kVec, swim); -// Bf = new B(kVec.k, kVec.x, kVec.y, kVec.z, swim); -// kVec.alpha = Bf.alpha; -// this.tranState(k, kVec, swim); -// this.setHelixPars(kVec, swim); -// kVec.x = ps.x(); -// kVec.y = ps.y(); -// kVec.z = ps.z(); -// this.tranState(k, kVec, swim); -// } -// } @Override public Vector3D P(int kf) { @@ -402,17 +317,6 @@ public Vector3D X0(int kf) { } } - @Override - public Helix setTrackPars() { - Vector3D X = this.X0(0); - Vector3D P = this.P0(0); - - int q = KFitter.polarity*(int) Math.signum(this.trackTraj.get(0).kappa); - double B = 1./Math.abs(this.trackTraj.get(0).alpha)/lightVel ; - - return new Helix(X.x(), X.y(), X.z(), P.x(), P.y(), P.z(), q, B, this.xref, this.yref, this.units); - } - @Override public void init(Helix helix, double[][] cov, double xref, double yref, double zref, Swim swimmer) { diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index 1892ffbe5..6ffcf225f 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -179,7 +179,7 @@ public Vector3D X0(int kf) { } @Override -public void printlnStateVec(StateVec S) { + public void printlnStateVec(StateVec S) { String s = String.format("%d) x0=%.4f y0=%.4f z0=%.4f tx=%.4f tz=%.4f dl=%.4f", S.k, S.x0, S.y0, S.z0, S.tx, S.tz, S.dl); s += String.format(" x=%.4f y=%.4f z=%.4f px=%.4f py=%.4f pz=%.4f", S.x, S.y, S.z, S.px, S.py, S.pz); System.out.println(s); @@ -194,9 +194,7 @@ public void init(Helix trk, double[][] cov, double xref, double yref, double zre public void init(double x0, double z0, double tx, double tz, Units units, double[][] cov) { this.trackTraj = new HashMap<>(); this.units = units; - //this.lightVel = 0.0000299792458*units; - //init stateVec - //StateVec initSV = new StateVec(0); + initSV = new StateVec(0); initSV.x0 = x0; initSV.y0 = 0; @@ -214,10 +212,5 @@ public void init(double x0, double z0, double tx, double tz, Units units, double initSV.covMat = covKF; this.trackTraj.put(0, new StateVec(initSV)); } - - @Override - public Helix setTrackPars() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - + } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java index e23984eb3..bd86ec0fe 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Cross.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.tracking.objects; /** @@ -43,6 +38,7 @@ public boolean equals(Object o) { /** * @return the _id */ + @Override public int getId() { return _id; } @@ -50,6 +46,7 @@ public int getId() { /** * @param _id the _id to set */ + @Override public void setId(int _id) { this._id = _id; } @@ -57,6 +54,7 @@ public void setId(int _id) { /** * @return the _x */ + @Override public double getX() { return _x; } @@ -64,6 +62,7 @@ public double getX() { /** * @param _x the _x to set */ + @Override public void setX(double _x) { this._x = _x; } @@ -71,6 +70,7 @@ public void setX(double _x) { /** * @return the _y */ + @Override public double getY() { return _y; } @@ -78,6 +78,7 @@ public double getY() { /** * @param _y the _y to set */ + @Override public void setY(double _y) { this._y = _y; } @@ -85,6 +86,7 @@ public void setY(double _y) { /** * @return the _z */ + @Override public double getZ() { return _z; } @@ -92,6 +94,7 @@ public double getZ() { /** * @param _z the _z to set */ + @Override public void setZ(double _z) { this._z = _z; } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java index 79c39562d..0fe821ba5 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Segment.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.tracking.objects; /** @@ -48,6 +43,7 @@ public boolean equals(Object o) { /** * @return the _id */ + @Override public int getId() { return _id; } @@ -55,6 +51,7 @@ public int getId() { /** * @param _id the _id to set */ + @Override public void setId(int _id) { this._id = _id; } @@ -62,6 +59,7 @@ public void setId(int _id) { /** * @return the _x */ + @Override public double getX() { return _x; } @@ -69,6 +67,7 @@ public double getX() { /** * @param _x the _x to set */ + @Override public void setX(double _x) { this._x = _x; } @@ -76,6 +75,7 @@ public void setX(double _x) { /** * @return the _y */ + @Override public double getY() { return _y; } @@ -83,6 +83,7 @@ public double getY() { /** * @param _y the _y to set */ + @Override public void setY(double _y) { this._y = _y; } @@ -90,6 +91,7 @@ public void setY(double _y) { /** * @return the _z */ + @Override public double getZ() { return _z; } @@ -97,6 +99,7 @@ public double getZ() { /** * @param _z the _z to set */ + @Override public void setZ(double _z) { this._z = _z; } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java index 6d33baabb..7039b974e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/Strip.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.tracking.objects; import org.jlab.geom.prim.Arc3D; @@ -17,6 +12,7 @@ public class Strip extends TObject { /** * @return the _id */ + @Override public int getId() { return _id; } @@ -24,6 +20,7 @@ public int getId() { /** * @param _id the _id to set */ + @Override public void setId(int _id) { this._id = _id; } @@ -31,6 +28,7 @@ public void setId(int _id) { /** * @return the _x */ + @Override public double getX() { return _x; } @@ -38,6 +36,7 @@ public double getX() { /** * @param _x the _x to set */ + @Override public void setX(double _x) { this._x = _x; } @@ -45,6 +44,7 @@ public void setX(double _x) { /** * @return the _y */ + @Override public double getY() { return _y; } @@ -52,6 +52,7 @@ public double getY() { /** * @param _y the _y to set */ + @Override public void setY(double _y) { this._y = _y; } @@ -59,6 +60,7 @@ public void setY(double _y) { /** * @return the _z */ + @Override public double getZ() { return _z; } @@ -66,6 +68,7 @@ public double getZ() { /** * @param _z the _z to set */ + @Override public void setZ(double _z) { this._z = _z; } @@ -303,6 +306,7 @@ public Strip(int id, double centroid, Arc3D arc) { type = Type.ARC; } + @Override public String toString() { String s = String.format("Strip id: %d",super.getId()); if(this.type==Type.XYZ) { diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java index a3b33f4e5..1737f1fda 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/objects/TObject.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.tracking.objects; /** diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java index a54ee20e2..cdd0f8b3e 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/CircleHoughTrans.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.tracking.patternrec; import java.util.ArrayList; @@ -41,7 +36,7 @@ public CircleHoughTrans() { acc = new int[width * height]; results = new int[width * height*3]; } - private Map peaks = new HashMap(); + private Map peaks = new HashMap<>(); public int minAccVal = 4; public void fillAccumulator(ListX, ListY) { @@ -72,14 +67,14 @@ public void fillAccumulator(ListX, ListY) { } List xy; // xy of seed points - private List> set = new ArrayList>(); - public List> CHTSeeds = new ArrayList>(); + private List> set = new ArrayList<>(); + public List> CHTSeeds = new ArrayList<>(); public void findCircles(ListX, ListY, ListL) { - for(int j = 0; j < set.size(); j++) { + for (ArrayList set1 : set) { set.clear(); } - for(int j = 0; j < CHTSeeds.size(); j++) { + for (ArrayList CHTSeed : CHTSeeds) { CHTSeeds.clear(); } fillAccumulator(X, Y); @@ -93,7 +88,7 @@ public void findCircles(ListX, ListY, ListL) { for(Map.Entry entry:sorted.entrySet()){ - xy = new ArrayList((int)entry.getValue()); + xy = new ArrayList<>((int)entry.getValue()); double t; int l; @@ -139,22 +134,22 @@ public void findCircles(ListX, ListY, ListL) { private List> split() { hxy.clear(); - List> newset = new ArrayList>(); + List> newset = new ArrayList<>(); //get list with single hit per layer - List base = new ArrayList(); // xy of seed points + List base = new ArrayList<>(); // xy of seed points base.add(xy.get(0)); for(int i = 1; i < xy.size(); i++) { if(xy.get(i-1).getLayer() != xy.get(i).getLayer()) { base.add(xy.get(i)); } } - List offbase = new ArrayList(); + List offbase = new ArrayList<>(); offbase.addAll(xy); offbase.removeAll(base); //get same layer hits for(Point2D p : offbase) { - hxy.put(p.getLayer(),new ArrayList()); + hxy.put(p.getLayer(),new ArrayList<>()); } for(Point2D p : offbase) { hxy.get(p.getLayer()).add(p); @@ -163,7 +158,7 @@ private List> split() { for (Map.Entry> entry : hxy.entrySet()) { for(Point2D p : entry.getValue()) { - List base2 = new ArrayList(); + List base2 = new ArrayList<>(); base2.addAll(base); for(int k = 0; k < base2.size(); k++) { Point2D bp = base2.get(k); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java index 5b8d04aca..aadd1b4f9 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/patternrec/LineHoughTrans.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.tracking.patternrec; import java.util.ArrayList; @@ -43,7 +38,7 @@ public LineHoughTrans() { acc = new int[n][nTh]; results = new int[n * nTh *3]; } - private Map peaks = new HashMap(); + private Map peaks = new HashMap<>(); public int minAccVal = 4; public void fillAccumulator(ListX, ListY) { @@ -63,14 +58,14 @@ public void fillAccumulator(ListX, ListY) { } List xy; // xy of seed points - private List> set = new ArrayList>(); - public List> LHTSeeds = new ArrayList>(); + private List> set = new ArrayList<>(); + public List> LHTSeeds = new ArrayList<>(); public void findLines(ListX, ListY, ListL) { - for(int j = 0; j < set.size(); j++) { + for (ArrayList set1 : set) { set.clear(); } - for(int j = 0; j < LHTSeeds.size(); j++) { + for (ArrayList LHTSeed : LHTSeeds) { LHTSeeds.clear(); } fillAccumulator(X, Y); @@ -84,7 +79,7 @@ public void findLines(ListX, ListY, ListL) { for(Map.Entry entry:sorted.entrySet()){ - xy = new ArrayList((int)entry.getValue()); + xy = new ArrayList<>((int)entry.getValue()); double t; int l; @@ -126,22 +121,22 @@ public void findLines(ListX, ListY, ListL) { private List> split() { hxy.clear(); - List> newset = new ArrayList>(); + List> newset = new ArrayList<>(); //get list with single hit per layer - List base = new ArrayList(); // xy of seed points + List base = new ArrayList<>(); // xy of seed points base.add(xy.get(0)); for(int i = 1; i < xy.size(); i++) { if(xy.get(i-1).getLayer() != xy.get(i).getLayer()) { base.add(xy.get(i)); } } - List offbase = new ArrayList(); + List offbase = new ArrayList<>(); offbase.addAll(xy); offbase.removeAll(base); //get same layer hits for(Point2D p : offbase) { - hxy.put(p.getLayer(),new ArrayList()); + hxy.put(p.getLayer(),new ArrayList<>()); } for(Point2D p : offbase) { hxy.get(p.getLayer()).add(p); @@ -150,7 +145,7 @@ private List> split() { for (Map.Entry> entry : hxy.entrySet()) { for(Point2D p : entry.getValue()) { - List base2 = new ArrayList(); + List base2 = new ArrayList<>(); base2.addAll(base); for(int k = 0; k < base2.size(); k++) { Point2D bp = base2.get(k); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java index 27a0fbef9..44a953ca4 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/trackrep/Trajectory.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.tracking.trackrep; import java.util.List; diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java index d29050334..38f16d436 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/OverlapRemover.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.tracking.utilities; import java.util.ArrayList; @@ -59,7 +54,7 @@ private boolean equals(List c0, List c1) { } private List findOverlapObjects(List c0, List c1) { - List covrl = new ArrayList(); + List covrl = new ArrayList<>(); c0.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); c1.sort(Comparator.comparing(TObject::getLayer).thenComparing(TObject::getR).thenComparing(TObject::getZ)); @@ -109,7 +104,7 @@ public void flagOverlap(Seed s0, Seed s1) { } public void removeDuplicates(List seeds) { - List dupl = new ArrayList(); + List dupl = new ArrayList<>(); for(int i = 0; i < seeds.size(); i++) { Seed ci = seeds.get(i); seeds.remove(i); //exlude it from list diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java index ac743e951..67d9065f6 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/SelectEventsToFile.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.tracking.utilities; import java.io.BufferedReader; @@ -26,7 +21,7 @@ public class SelectEventsToFile { public static void main(String[] args) throws FileNotFoundException { String[] splited ; BufferedReader reader; - Map evts = new HashMap(); + Map evts = new HashMap<>(); try { reader = new BufferedReader(new FileReader("/Users/ziegler/Desktop/Base/CodeDevel/Validation/hipo4Validation/selEvts.txt")); try { @@ -65,7 +60,7 @@ public static void main(String[] args) throws FileNotFoundException { int run = bank.getInt("run", 0); int evt = bank.getInt("event", 0); - if(evts.get(evt)!=null && evts.get(evt).intValue()==run) { + if(evts.get(evt)!=null && evts.get(evt)==run) { writer.writeEvent(event); System.out.println("PROCESSED EVENT " + event.getBank("RUN::config").getInt("event", 0)); } From 62227fb208adf3d081e5c8f77df61316af67e320 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Wed, 19 Jan 2022 13:45:00 +0100 Subject: [PATCH 273/291] CVT package cleanup: make syntax more uniform, address warnings, remove obsolete/unused methods, removed unused constants moved Measurements class to new folder, changed TrackCandListFinder to StraightTrackCandListFinder since it is used only for straight tracks --- .../main/java/org/jlab/rec/cvt/Constants.java | 54 +- .../org/jlab/rec/cvt/banks/HitReader.java | 52 +- .../jlab/rec/cvt/banks/RecoBankWriter.java | 340 ++--- .../org/jlab/rec/cvt/banks/package-info.java | 8 - .../org/jlab/rec/cvt/bmt/BMTConstants.java | 64 +- .../org/jlab/rec/cvt/bmt/BMTGeometry.java | 463 +------ .../jlab/rec/cvt/bmt/CCDBConstantsLoader.java | 30 +- .../org/jlab/rec/cvt/bmt/package-info.java | 8 - .../org/jlab/rec/cvt/cluster/Cluster.java | 348 ++--- .../jlab/rec/cvt/cluster/ClusterFinder.java | 22 +- .../jlab/rec/cvt/cluster/package-info.java | 8 - .../java/org/jlab/rec/cvt/cross/Cross.java | 208 +-- .../org/jlab/rec/cvt/cross/CrossList.java | 8 +- .../org/jlab/rec/cvt/cross/CrossMaker.java | 154 +-- .../rec/cvt/cross/HelixCrossListFinder.java | 231 ++-- .../cross/StraightTrackCrossListFinder.java | 135 +- .../org/jlab/rec/cvt/cross/package-info.java | 8 - .../org/jlab/rec/cvt/fit/CircleCalcPars.java | 2 + .../jlab/rec/cvt/fit/CircleCalculator.java | 2 +- .../org/jlab/rec/cvt/fit/CircleFitPars.java | 18 +- .../org/jlab/rec/cvt/fit/CircleFitter.java | 25 +- .../org/jlab/rec/cvt/fit/CosmicFitPars.java | 12 +- .../org/jlab/rec/cvt/fit/CosmicFitter.java | 52 +- .../jlab/rec/cvt/fit/HelicalTrackFitPars.java | 12 +- .../jlab/rec/cvt/fit/HelicalTrackFitter.java | 19 +- .../org/jlab/rec/cvt/fit/LineFitPars.java | 4 +- .../jlab/rec/cvt/fit/StraightTrackFitter.java | 14 +- .../org/jlab/rec/cvt/fit/package-info.java | 8 - .../org/jlab/rec/cvt/hit/ADCConvertor.java | 8 +- .../main/java/org/jlab/rec/cvt/hit/Hit.java | 100 +- .../main/java/org/jlab/rec/cvt/hit/Strip.java | 136 +- .../org/jlab/rec/cvt/hit/package-info.java | 8 - .../org/jlab/rec/cvt/measurement/MLayer.java | 130 ++ .../{track => measurement}/Measurements.java | 201 +-- .../java/org/jlab/rec/cvt/package-info.java | 8 - .../jlab/rec/cvt/services/CVTRecNewKF.java | 31 +- .../rec/cvt/services/CosmicTracksRec.java | 67 +- .../jlab/rec/cvt/services/RecUtilities.java | 466 ++----- .../rec/cvt/services/TracksFromTargetRec.java | 123 +- .../jlab/rec/cvt/services/package-info.java | 8 - .../org/jlab/rec/cvt/svt/SVTGeometry.java | 181 --- .../org/jlab/rec/cvt/svt/SVTParameters.java | 37 +- .../org/jlab/rec/cvt/svt/package-info.java | 8 - .../java/org/jlab/rec/cvt/track/Cell.java | 346 ++--- .../jlab/rec/cvt/track/EnergyLossCorr.java | 109 +- .../java/org/jlab/rec/cvt/track/MakerCA.java | 506 +++---- .../java/org/jlab/rec/cvt/track/Seed.java | 181 ++- .../org/jlab/rec/cvt/track/StraightTrack.java | 112 +- .../track/StraightTrackCandListFinder.java | 561 ++++++++ .../rec/cvt/track/StraightTrackSeeder.java | 264 ++-- .../java/org/jlab/rec/cvt/track/Track.java | 122 +- .../rec/cvt/track/TrackCandListFinder.java | 1171 ----------------- .../jlab/rec/cvt/track/TrackListFinder.java | 139 +- .../org/jlab/rec/cvt/track/TrackSeeder.java | 469 ++----- .../org/jlab/rec/cvt/track/TrackSeederCA.java | 807 +++++------- .../org/jlab/rec/cvt/track/package-info.java | 8 - .../org/jlab/rec/cvt/trajectory/Helix.java | 93 +- .../java/org/jlab/rec/cvt/trajectory/Ray.java | 50 +- .../org/jlab/rec/cvt/trajectory/StateVec.java | 54 +- .../jlab/rec/cvt/trajectory/Trajectory.java | 30 +- .../rec/cvt/trajectory/TrajectoryFinder.java | 735 +++-------- .../jlab/rec/cvt/trajectory/package-info.java | 8 - 62 files changed, 3465 insertions(+), 6121 deletions(-) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/package-info.java create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/MLayer.java rename reconstruction/cvt/src/main/java/org/jlab/rec/cvt/{track => measurement}/Measurements.java (63%) delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/package-info.java create mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackCandListFinder.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/package-info.java delete mode 100644 reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/package-info.java diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index bad3be56e..933628224 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -21,22 +21,6 @@ public class Constants { Constants() { } - private static final double COVD0D0 = 1.;///50.; - private static final double COVD0PHI0 = 1;//./50.; - private static final double COVD0RHO = 1.;///50.; - private static final double COVPHI0PHI0 = 1.;///50.; - private static final double COVPHI0RHO = 1.;///50.; - private static final double COVRHORHO = 1.;//50.; - private static final double COVZ0Z0 = 10.; - private static final double CONVTANLTANL = 10.; - - public static double[][] COVMATSCALEFACT = new double[][]{ - {COVD0D0, COVD0PHI0, COVD0RHO,1.0,1.0}, - {COVD0PHI0,COVPHI0PHI0, COVPHI0RHO,1.0,1.0}, - {COVD0RHO, COVPHI0RHO, COVRHORHO,1.0,1.0}, - {1.0,1.0,1.0, COVZ0Z0,1.0}, - {1.0,1.0,1.0,1.0, CONVTANLTANL} - }; // CONSTANTS USED IN RECONSTRUCTION //--------------------------------- public static boolean isMC = true; @@ -57,15 +41,15 @@ public class Constants { public static final double SWIMACCURACYBMT = 0.020; // in mm public static final double SWIMACCURACYCD = 0.500; // in mm - public static boolean isCosmicsData = false; + public static boolean ISCOSMICDATA = false; public static final double COSMICSMINRESIDUALX = 120; // in mm public static final double COSMICSMINRESIDUALZ = 12; // in mm public static final int SEEDFITITERATIONS = 5; - public static boolean SVTOnly = false; + public static boolean SVTONLY = false; - public static boolean svtSeeding = true; + public static boolean SVTSEEDING = true; public static boolean TIMECUTS = false; @@ -77,7 +61,7 @@ public class Constants { private static int BEAMSPOTCONST = 0; - public static Libr kfMatLib; + public static Libr KFMATLIB; public static final double CTOFINNERRADIUS = 250; // 250 mm public static final double CTOFOUTRRADIUS = 250 + 33; // 283 mm @@ -194,6 +178,23 @@ public static int getBMTLayerExcld() { return BMTLayerExcld; } + private static final double COVD0D0 = 1.;///50.; + private static final double COVD0PHI0 = 1;//./50.; + private static final double COVD0RHO = 1.;///50.; + private static final double COVPHI0PHI0 = 1.;///50.; + private static final double COVPHI0RHO = 1.;///50.; + private static final double COVRHORHO = 1.;//50.; + private static final double COVZ0Z0 = 10.; + private static final double CONVTANLTANL = 10.; + + public static double[][] COVMATSCALEFACT = new double[][]{ + {COVD0D0, COVD0PHI0, COVD0RHO,1.0,1.0}, + {COVD0PHI0,COVPHI0PHI0, COVPHI0RHO,1.0,1.0}, + {COVD0RHO, COVPHI0RHO, COVRHORHO,1.0,1.0}, + {1.0,1.0,1.0, COVZ0Z0,1.0}, + {1.0,1.0,1.0,1.0, CONVTANLTANL} + }; + //public static final boolean DEBUGMODE =false; // for landau inverse calculation public static final double f[] = { @@ -365,24 +366,23 @@ public static int getBMTLayerExcld() { 40.157721, 41.622399, 43.202525, 44.912465, 46.769077, 48.792279, 51.005773, 53.437996, 56.123356, 59.103894}; - //public static final int CVTCONFIGSTARTREG = 2; // for 3SVT+3BMT - + public static void setMatLib(String matLib) { switch (matLib) { case "JAMA": - kfMatLib = Libr.JAMA; + KFMATLIB = Libr.JAMA; break; case "JNP": - kfMatLib = Libr.JNP; + KFMATLIB = Libr.JNP; break; case "APA": - kfMatLib = Libr.APA; + KFMATLIB = Libr.APA; break; case "EJML": - kfMatLib = Libr.EJML; + KFMATLIB = Libr.EJML; break; default: - kfMatLib = Libr.EJML; + KFMATLIB = Libr.EJML; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java index b75017623..0533293e1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/HitReader.java @@ -39,7 +39,7 @@ public HitReader() { * * @return a list of BMT hits */ - public List get_BMTHits() { + public List getBMTHits() { return _BMTHits; } @@ -48,7 +48,7 @@ public List get_BMTHits() { * * @param _BMTHits list of BMT hits */ - public void set_BMTHits(List _BMTHits) { + public void setBMTHits(List _BMTHits) { this._BMTHits = _BMTHits; } // the list of SVT hits @@ -58,7 +58,7 @@ public void set_BMTHits(List _BMTHits) { * * @return a list of SVT hits */ - public List get_SVTHits() { + public List getSVTHits() { return _SVTHits; } @@ -67,7 +67,7 @@ public List get_SVTHits() { * * @param _SVTHits list of SVT hits */ - public void set_SVTHits(List _SVTHits) { + public void setSVTHits(List _SVTHits) { this._SVTHits = _SVTHits; } @@ -77,19 +77,22 @@ public void set_SVTHits(List _SVTHits) { * @param event the data event * @param adcConv converter from adc to values used in the analysis (i.e. * Edep for gemc, adc for cosmics) + * @param swim + * @param status + * @param timeCuts */ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, Swim swim, IndexedTable status, IndexedTable timeCuts) { // return if there is no BMT bank if (event.hasBank("BMT::adc") == false) { //System.err.println("there is no BMT bank "); - _BMTHits = new ArrayList(); + _BMTHits = new ArrayList<>(); return; } // instanciates the list of hits - List hits = new ArrayList(); + List hits = new ArrayList<>(); // gets the BMT dgtz bank DataBank bankDGTZ = event.getBank("BMT::adc"); // fills the arrays corresponding to the hit variables @@ -123,17 +126,17 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, Swim swim, Inde if(time!=0 && (timetmax)) BmtStrip.setStatus(2);// calculate the strip parameters for the BMT hit } - BmtStrip.calc_BMTStripParams(sector, layer, swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect + BmtStrip.calcBMTStripParams(sector, layer, swim); // for Z detectors the Lorentz angle shifts the strip measurement; calc_Strip corrects for this effect // create the hit object for detector type BMT Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, BmtStrip); - hit.set_Id(i+1); + hit.setId(i+1); // add this hit - if(hit.get_Layer()+3!=Constants.getRmReg()) + if(hit.getLayer()+3!=Constants.getRmReg()) hits.add(hit); } // fills the list of BMT hits - this.set_BMTHits(hits); + this.setBMTHits(hits); } } @@ -142,6 +145,9 @@ public void fetch_BMTHits(DataEvent event, ADCConvertor adcConv, Swim swim, Inde * * @param event the data event * @param adcConv converter from adc to daq values + * @param omitLayer + * @param omitHemisphere + * @param status */ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, int omitHemisphere, IndexedTable status) { @@ -234,21 +240,13 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // continue; // create the strip object with the adc value converted to daq value used for cluster-centroid estimate Strip SvtStrip = new Strip(strip, adcConv.SVTADCtoDAQ(ADC), time); - SvtStrip.set_Pitch(SVTGeometry.getPitch()); + SvtStrip.setPitch(SVTGeometry.getPitch()); // get the strip line - SvtStrip.set_Line(Constants.SVTGEOMETRY.getStrip(layer, sector, strip)); - SvtStrip.set_Module(Constants.SVTGEOMETRY.getModule(layer, sector)); - SvtStrip.set_Normal(Constants.SVTGEOMETRY.getNormal(layer, sector)); - if(layer%2==0) { - SvtStrip.setToverX0(2*SVTGeometry.getToverX0()); - SvtStrip.setZoverA(SVTGeometry.getZoverA()); - SvtStrip.setMatT(SVTGeometry.getMaterialThickness()); - } - else { - SvtStrip.setToverX0(0); - } + SvtStrip.setLine(Constants.SVTGEOMETRY.getStrip(layer, sector, strip)); + SvtStrip.setModule(Constants.SVTGEOMETRY.getModule(layer, sector)); + SvtStrip.setNormal(Constants.SVTGEOMETRY.getNormal(layer, sector)); // if the hit is useable in the analysis its status is =0 - if (SvtStrip.get_Edep() == 0) { + if (SvtStrip.getEdep() == 0) { SvtStrip.setStatus(1); } // if (Constants.TIMECUTS) { @@ -272,19 +270,19 @@ public void fetch_SVTHits(DataEvent event, ADCConvertor adcConv, int omitLayer, // (-o1.z + e1.z ) ); // Point3D passVals = new Point3D(o1.x, o1.y, o1.z); //switch from Vector3d to Point3D -// SvtStrip.set_ImplantPoint(passVals); +// SvtStrip.setImplantPoint(passVals); // create the hit object Hit hit = new Hit(DetectorType.BST, BMTType.UNDEFINED, sector, layer, SvtStrip); - hit.set_Id(id); + hit.setId(id); // add this hit - if(hit.get_Region()!=Constants.getRmReg()) + if(hit.getRegion()!=Constants.getRmReg()) hits.add(hit); } } // fill the list of SVT hits - this.set_SVTHits(hits); + this.setSVTHits(hits); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java index a38c93a4f..1c32717c9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankWriter.java @@ -42,21 +42,21 @@ public DataBank fillSVTHitsBank(DataEvent event, List hitlist) { for (int i = 0; i < hitlist.size(); i++) { - bank.setShort("ID", i, (short) hitlist.get(i).get_Id()); + bank.setShort("ID", i, (short) hitlist.get(i).getId()); - bank.setByte("layer", i, (byte) hitlist.get(i).get_Layer()); - bank.setByte("sector", i, (byte) hitlist.get(i).get_Sector()); - bank.setInt("strip", i, hitlist.get(i).get_Strip().get_Strip()); + bank.setByte("layer", i, (byte) hitlist.get(i).getLayer()); + bank.setByte("sector", i, (byte) hitlist.get(i).getSector()); + bank.setInt("strip", i, hitlist.get(i).getStrip().getStrip()); - bank.setFloat("energy", i, (float) hitlist.get(i).get_Strip().get_Edep()); - bank.setFloat("time", i, (float) hitlist.get(i).get_Strip().get_Time()); - bank.setFloat("fitResidual", i, (float) hitlist.get(i).get_Residual()); - bank.setInt("trkingStat", i, hitlist.get(i).get_TrkgStatus()); + bank.setFloat("energy", i, (float) hitlist.get(i).getStrip().getEdep()); + bank.setFloat("time", i, (float) hitlist.get(i).getStrip().getTime()); + bank.setFloat("fitResidual", i, (float) hitlist.get(i).getResidual()); + bank.setInt("trkingStat", i, hitlist.get(i).getTrkgStatus()); - bank.setShort("clusterID", i, (short) hitlist.get(i).get_AssociatedClusterID()); - bank.setShort("trkID", i, (short) hitlist.get(i).get_AssociatedTrackID()); + bank.setShort("clusterID", i, (short) hitlist.get(i).getAssociatedClusterID()); + bank.setShort("trkID", i, (short) hitlist.get(i).getAssociatedTrackID()); - bank.setByte("status", i, (byte) hitlist.get(i).get_Strip().getStatus()); + bank.setByte("status", i, (byte) hitlist.get(i).getStrip().getStatus()); } //bank.show(); return bank; @@ -84,23 +84,23 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { for (int j = 0; j < hitIdxArray.length; j++) { hitIdxArray[j] = -1; } - bank.setShort("ID", i, (short) cluslist.get(i).get_Id()); - bank.setByte("sector", i, (byte) cluslist.get(i).get_Sector()); - bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); + bank.setShort("ID", i, (short) cluslist.get(i).getId()); + bank.setByte("sector", i, (byte) cluslist.get(i).getSector()); + bank.setByte("layer", i, (byte) cluslist.get(i).getLayer()); bank.setShort("size", i, (short) cluslist.get(i).size()); - bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); - bank.setFloat("time", i, (float) cluslist.get(i).get_Time()); - bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); - bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); - bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); - bank.setFloat("centroidError", i, (float) cluslist.get(i).get_Resolution()); - bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); - bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); - bank.setShort("trkID", i, (short) cluslist.get(i).get_AssociatedTrackID()); + bank.setFloat("ETot", i, (float) cluslist.get(i).getTotalEnergy()); + bank.setFloat("time", i, (float) cluslist.get(i).getTime()); + bank.setInt("seedStrip", i, cluslist.get(i).getSeedStrip().getStrip()); + bank.setFloat("centroid", i, (float) cluslist.get(i).getCentroid()); + bank.setFloat("seedE", i, (float) cluslist.get(i).getSeedStrip().getEdep()); + bank.setFloat("centroidError", i, (float) cluslist.get(i).getResolution()); + bank.setFloat("centroidResidual", i, (float) cluslist.get(i).getCentroidResidual()); + bank.setFloat("seedResidual", i, (float) cluslist.get(i).getSeedResidual()); + bank.setShort("trkID", i, (short) cluslist.get(i).getAssociatedTrackID()); for (int j = 0; j < cluslist.get(i).size(); j++) { if (j < hitIdxArray.length) { - hitIdxArray[j] = cluslist.get(i).get(j).get_Id(); + hitIdxArray[j] = cluslist.get(i).get(j).getId(); } } @@ -126,7 +126,7 @@ public DataBank fillSVTClustersBank(DataEvent event, List cluslist) { bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); - bank.setFloat("e", i, (float)cluslist.get(i).get_Resolution()); + bank.setFloat("e", i, (float)cluslist.get(i).getResolution()); // cluslist.get(i).printInfo(); // System.out.println("N "+cluslist.get(i).getNFromTraj().toString()+" \n"+ // " L "+cluslist.get(i).getL().toString()+" \n"+ @@ -163,34 +163,34 @@ public DataBank fillSVTCrossesBank(DataEvent event, List> cross int index = 0; int i = 0; for (int j = 0; j < crosses.get(i).size(); j++) { - bank.setShort("ID", index, (short) crosses.get(i).get(j).get_Id()); - bank.setByte("sector", index, (byte) crosses.get(i).get(j).get_Sector()); - bank.setByte("region", index, (byte) crosses.get(i).get(j).get_Region()); - bank.setFloat("x", index, (float) (crosses.get(i).get(j).get_Point().x()/10.)); - bank.setFloat("y", index, (float) (crosses.get(i).get(j).get_Point().y()/10.)); - bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10)); - bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).get_PointErr().x()/10.)); - bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).get_PointErr().y()/10.)); - bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).get_PointErr().z()/10.)); - bank.setShort("trkID", index, (short) crosses.get(i).get(j).get_AssociatedTrackID()); - - if (crosses.get(i).get(j).get_Dir() != null && - !Double.isNaN(crosses.get(i).get(j).get_Dir().x()) && - !Double.isNaN(crosses.get(i).get(j).get_Dir().y()) && - !Double.isNaN(crosses.get(i).get(j).get_Dir().z()) ) { - bank.setFloat("ux", index, (float) crosses.get(i).get(j).get_Dir().x()); - bank.setFloat("uy", index, (float) crosses.get(i).get(j).get_Dir().y()); - bank.setFloat("uz", index, (float) crosses.get(i).get(j).get_Dir().z()); + bank.setShort("ID", index, (short) crosses.get(i).get(j).getId()); + bank.setByte("sector", index, (byte) crosses.get(i).get(j).getSector()); + bank.setByte("region", index, (byte) crosses.get(i).get(j).getRegion()); + bank.setFloat("x", index, (float) (crosses.get(i).get(j).getPoint().x()/10.)); + bank.setFloat("y", index, (float) (crosses.get(i).get(j).getPoint().y()/10.)); + bank.setFloat("z", index, (float) (crosses.get(i).get(j).getPoint().z()/10)); + bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).getPointErr().x()/10.)); + bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).getPointErr().y()/10.)); + bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).getPointErr().z()/10.)); + bank.setShort("trkID", index, (short) crosses.get(i).get(j).getAssociatedTrackID()); + + if (crosses.get(i).get(j).getDir() != null && + !Double.isNaN(crosses.get(i).get(j).getDir().x()) && + !Double.isNaN(crosses.get(i).get(j).getDir().y()) && + !Double.isNaN(crosses.get(i).get(j).getDir().z()) ) { + bank.setFloat("ux", index, (float) crosses.get(i).get(j).getDir().x()); + bank.setFloat("uy", index, (float) crosses.get(i).get(j).getDir().y()); + bank.setFloat("uz", index, (float) crosses.get(i).get(j).getDir().z()); } else { bank.setFloat("ux", index, 0); bank.setFloat("uy", index, 0); bank.setFloat("uz", index, 0); } - if (crosses.get(i).get(j).get_Cluster1() != null) { - bank.setShort("Cluster1_ID", index, (short) crosses.get(i).get(j).get_Cluster1().get_Id()); + if (crosses.get(i).get(j).getCluster1() != null) { + bank.setShort("Cluster1_ID", index, (short) crosses.get(i).get(j).getCluster1().getId()); } - if (crosses.get(i).get(j).get_Cluster2() != null) { - bank.setShort("Cluster2_ID", index, (short) crosses.get(i).get(j).get_Cluster2().get_Id()); + if (crosses.get(i).get(j).getCluster2() != null) { + bank.setShort("Cluster2_ID", index, (short) crosses.get(i).get(j).getCluster2().getId()); } index++; } @@ -213,21 +213,21 @@ public DataBank fillBMTHitsBank(DataEvent event, List hitlist) { for (int i = 0; i < hitlist.size(); i++) { - bank.setShort("ID", i, (short) hitlist.get(i).get_Id()); + bank.setShort("ID", i, (short) hitlist.get(i).getId()); - bank.setByte("layer", i, (byte) hitlist.get(i).get_Layer()); - bank.setByte("sector", i, (byte) hitlist.get(i).get_Sector()); - bank.setInt("strip", i, hitlist.get(i).get_Strip().get_Strip()); + bank.setByte("layer", i, (byte) hitlist.get(i).getLayer()); + bank.setByte("sector", i, (byte) hitlist.get(i).getSector()); + bank.setInt("strip", i, hitlist.get(i).getStrip().getStrip()); - bank.setFloat("energy", i, (float) hitlist.get(i).get_Strip().get_Edep()); - bank.setFloat("time", i, (float) hitlist.get(i).get_Strip().get_Time()); - bank.setFloat("fitResidual", i, (float) hitlist.get(i).get_Residual()); - bank.setInt("trkingStat", i, hitlist.get(i).get_TrkgStatus()); + bank.setFloat("energy", i, (float) hitlist.get(i).getStrip().getEdep()); + bank.setFloat("time", i, (float) hitlist.get(i).getStrip().getTime()); + bank.setFloat("fitResidual", i, (float) hitlist.get(i).getResidual()); + bank.setInt("trkingStat", i, hitlist.get(i).getTrkgStatus()); - bank.setShort("clusterID", i, (short) hitlist.get(i).get_AssociatedClusterID()); - bank.setShort("trkID", i, (short) hitlist.get(i).get_AssociatedTrackID()); + bank.setShort("clusterID", i, (short) hitlist.get(i).getAssociatedClusterID()); + bank.setShort("trkID", i, (short) hitlist.get(i).getAssociatedTrackID()); - bank.setByte("status", i, (byte) hitlist.get(i).get_Strip().getStatus()); + bank.setByte("status", i, (byte) hitlist.get(i).getStrip().getStatus()); } return bank; @@ -255,23 +255,23 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { for (int j = 0; j < hitIdxArray.length; j++) { hitIdxArray[j] = -1; } - bank.setShort("ID", i, (short) cluslist.get(i).get_Id()); - bank.setByte("sector", i, (byte) cluslist.get(i).get_Sector()); - bank.setByte("layer", i, (byte) cluslist.get(i).get_Layer()); + bank.setShort("ID", i, (short) cluslist.get(i).getId()); + bank.setByte("sector", i, (byte) cluslist.get(i).getSector()); + bank.setByte("layer", i, (byte) cluslist.get(i).getLayer()); bank.setShort("size", i, (short) cluslist.get(i).size()); - bank.setFloat("ETot", i, (float) cluslist.get(i).get_TotalEnergy()); - bank.setFloat("time", i, (float) cluslist.get(i).get_Time()); - bank.setInt("seedStrip", i, cluslist.get(i).get_SeedStrip().get_Strip()); - bank.setFloat("centroid", i, (float) cluslist.get(i).get_Centroid()); - bank.setFloat("centroidValue", i, (float) cluslist.get(i).get_CentroidValue()); - bank.setFloat("centroidError", i, (float) cluslist.get(i).get_CentroidError()); - bank.setFloat("centroidResidual", i, (float) cluslist.get(i).get_CentroidResidual()); - bank.setFloat("seedResidual", i, (float) cluslist.get(i).get_SeedResidual()); - bank.setFloat("seedE", i, (float) cluslist.get(i).get_SeedStrip().get_Edep()); - bank.setShort("trkID", i, (short) cluslist.get(i).get_AssociatedTrackID()); + bank.setFloat("ETot", i, (float) cluslist.get(i).getTotalEnergy()); + bank.setFloat("time", i, (float) cluslist.get(i).getTime()); + bank.setInt("seedStrip", i, cluslist.get(i).getSeedStrip().getStrip()); + bank.setFloat("centroid", i, (float) cluslist.get(i).getCentroid()); + bank.setFloat("centroidValue", i, (float) cluslist.get(i).getCentroidValue()); + bank.setFloat("centroidError", i, (float) cluslist.get(i).getCentroidError()); + bank.setFloat("centroidResidual", i, (float) cluslist.get(i).getCentroidResidual()); + bank.setFloat("seedResidual", i, (float) cluslist.get(i).getSeedResidual()); + bank.setFloat("seedE", i, (float) cluslist.get(i).getSeedStrip().getEdep()); + bank.setShort("trkID", i, (short) cluslist.get(i).getAssociatedTrackID()); for (int j = 0; j < cluslist.get(i).size(); j++) { if (j < hitIdxArray.length) { - hitIdxArray[j] = cluslist.get(i).get(j).get_Id(); + hitIdxArray[j] = cluslist.get(i).get(j).getId(); } } @@ -306,8 +306,8 @@ public DataBank fillBMTClustersBank(DataEvent event, List cluslist) { bank.setFloat("nx", i, (float)cluslist.get(i).getN().x()); bank.setFloat("ny", i, (float)cluslist.get(i).getN().y()); bank.setFloat("nz", i, (float)cluslist.get(i).getN().z()); - bank.setFloat("e", i, (float)cluslist.get(i).get_Resolution()); - if(debug && cluslist.get(i).get_AssociatedTrackID()>0 && cluslist.get(i).get_Type()==BMTType.Z) { + bank.setFloat("e", i, (float)cluslist.get(i).getResolution()); + if(debug && cluslist.get(i).getAssociatedTrackID()>0 && cluslist.get(i).getType()==BMTType.Z) { Line3D cln = new Line3D(cluslist.get(i).origin(), cluslist.get(i).end()); System.out.println("Check: N "+cluslist.get(i).getN().toString()+" \n"+ " L "+cluslist.get(i).getL().toString()+" \n"+ @@ -350,34 +350,34 @@ public DataBank fillBMTCrossesBank(DataEvent event, List> cross int index = 0; int i = 1; for (int j = 0; j < crosses.get(i).size(); j++) { - bank.setShort("ID", index, (short) crosses.get(i).get(j).get_Id()); - bank.setByte("sector", index, (byte) crosses.get(i).get(j).get_Sector()); - bank.setByte("region", index, (byte) crosses.get(i).get(j).get_Region()); - bank.setFloat("x", index, (float) (crosses.get(i).get(j).get_Point().x()/10.)); - bank.setFloat("y", index, (float) (crosses.get(i).get(j).get_Point().y()/10.)); - bank.setFloat("z", index, (float) (crosses.get(i).get(j).get_Point().z()/10)); - bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).get_PointErr().x()/10.)); - bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).get_PointErr().y()/10.)); - bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).get_PointErr().z()/10.)); - bank.setShort("trkID", index, (short) crosses.get(i).get(j).get_AssociatedTrackID()); + bank.setShort("ID", index, (short) crosses.get(i).get(j).getId()); + bank.setByte("sector", index, (byte) crosses.get(i).get(j).getSector()); + bank.setByte("region", index, (byte) crosses.get(i).get(j).getRegion()); + bank.setFloat("x", index, (float) (crosses.get(i).get(j).getPoint().x()/10.)); + bank.setFloat("y", index, (float) (crosses.get(i).get(j).getPoint().y()/10.)); + bank.setFloat("z", index, (float) (crosses.get(i).get(j).getPoint().z()/10)); + bank.setFloat("err_x", index, (float) (crosses.get(i).get(j).getPointErr().x()/10.)); + bank.setFloat("err_y", index, (float) (crosses.get(i).get(j).getPointErr().y()/10.)); + bank.setFloat("err_z", index, (float) (crosses.get(i).get(j).getPointErr().z()/10.)); + bank.setShort("trkID", index, (short) crosses.get(i).get(j).getAssociatedTrackID()); - if (crosses.get(i).get(j).get_Dir() != null && - !Double.isNaN(crosses.get(i).get(j).get_Dir().x()) && - !Double.isNaN(crosses.get(i).get(j).get_Dir().y()) && - !Double.isNaN(crosses.get(i).get(j).get_Dir().z()) ) { - bank.setFloat("ux", index, (float) crosses.get(i).get(j).get_Dir().x()); - bank.setFloat("uy", index, (float) crosses.get(i).get(j).get_Dir().y()); - bank.setFloat("uz", index, (float) crosses.get(i).get(j).get_Dir().z()); + if (crosses.get(i).get(j).getDir() != null && + !Double.isNaN(crosses.get(i).get(j).getDir().x()) && + !Double.isNaN(crosses.get(i).get(j).getDir().y()) && + !Double.isNaN(crosses.get(i).get(j).getDir().z()) ) { + bank.setFloat("ux", index, (float) crosses.get(i).get(j).getDir().x()); + bank.setFloat("uy", index, (float) crosses.get(i).get(j).getDir().y()); + bank.setFloat("uz", index, (float) crosses.get(i).get(j).getDir().z()); } else { bank.setFloat("ux", index, 0); bank.setFloat("uy", index, 0); bank.setFloat("uz", index, 0); } - if (crosses.get(i).get(j).get_Cluster1() != null) { - bank.setShort("Cluster1_ID", index, (short) crosses.get(i).get(j).get_Cluster1().get_Id()); + if (crosses.get(i).get(j).getCluster1() != null) { + bank.setShort("Cluster1_ID", index, (short) crosses.get(i).get(j).getCluster1().getId()); } - if (crosses.get(i).get(j).get_Cluster2() != null) { - bank.setShort("Cluster2_ID", index, (short) crosses.get(i).get(j).get_Cluster2().get_Id()); + if (crosses.get(i).get(j).getCluster2() != null) { + bank.setShort("Cluster2_ID", index, (short) crosses.get(i).get(j).getCluster2().getId()); } index++; } @@ -401,17 +401,17 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { for (int i = 0; i < seeds.size(); i++) { if(seeds.get(i)==null) continue; - bank.setByte("fittingMethod", i, (byte) seeds.get(i).get_Status()); + bank.setByte("fittingMethod", i, (byte) seeds.get(i).getStatus()); bank.setShort("ID", i, (short) seeds.get(i).getId()); - Helix helix = seeds.get(i).get_Helix(); - bank.setByte("q", i, (byte) (Math.signum(Constants.getSolenoidScale())*helix.get_charge())); - bank.setFloat("p", i, (float) helix.getPXYZ(seeds.get(i).get_Helix().B).mag()); - bank.setFloat("pt", i, (float) helix.getPt(seeds.get(i).get_Helix().B)); - bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); - bank.setFloat("tandip", i, (float) helix.get_tandip()); - bank.setFloat("z0", i, (float) (helix.get_Z0()/10.0)); - bank.setFloat("d0", i, (float) (helix.get_dca()/10.0)); - double[][] covmatrix = helix.get_covmatrix(); + Helix helix = seeds.get(i).getHelix(); + bank.setByte("q", i, (byte) (Math.signum(Constants.getSolenoidScale())*helix.getCharge())); + bank.setFloat("p", i, (float) helix.getPXYZ(seeds.get(i).getHelix().B).mag()); + bank.setFloat("pt", i, (float) helix.getPt(seeds.get(i).getHelix().B)); + bank.setFloat("phi0", i, (float) helix.getPhiAtDCA()); + bank.setFloat("tandip", i, (float) helix.getTanDip()); + bank.setFloat("z0", i, (float) (helix.getZ0()/10.0)); + bank.setFloat("d0", i, (float) (helix.getDCA()/10.0)); + double[][] covmatrix = helix.getCovMatrix(); if (covmatrix != null) { bank.setFloat("cov_d02", i, (float) covmatrix[0][0]/10/10 ); bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1]/10 ); @@ -440,16 +440,16 @@ public DataBank fillSeedsBank(DataEvent event, List seeds) { hitStrg += "_ID"; bank.setShort(hitStrg, i, (short) -1); } - for (int j = 0; j < seeds.get(i).get_Crosses().size(); j++) { + for (int j = 0; j < seeds.get(i).getCrosses().size(); j++) { if(j<9) { String hitStrg = "Cross"; hitStrg += (j + 1); - hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - bank.setShort(hitStrg, i, (short) seeds.get(i).get_Crosses().get(j).get_Id()); + hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).getId()); + bank.setShort(hitStrg, i, (short) seeds.get(i).getCrosses().get(j).getId()); } } - bank.setFloat("circlefit_chi2_per_ndf", i, (float) seeds.get(i).get_circleFitChi2PerNDF()); - bank.setFloat("linefit_chi2_per_ndf", i, (float) seeds.get(i).get_lineFitChi2PerNDF()); + bank.setFloat("circlefit_chi2_per_ndf", i, (float) seeds.get(i).getCircleFitChi2PerNDF()); + bank.setFloat("linefit_chi2_per_ndf", i, (float) seeds.get(i).getLineFitChi2PerNDF()); bank.setFloat("chi2", i, (float) seeds.get(i).getChi2()); bank.setShort("ndf", i, (short) seeds.get(i).getNDF()); @@ -485,16 +485,16 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { // } else { // bank.setByte("fittingMethod", i, (byte) 0); // } - bank.setByte("fittingMethod", i, (byte) trkcands.get(i).get_Seed().get_Status()); - bank.setShort("ID", i, (short) trkcands.get(i).get_Id()); - bank.setByte("q", i, (byte)trkcands.get(i).get_Q()); - bank.setFloat("p", i, (float) trkcands.get(i).get_P()); - bank.setFloat("pt", i, (float) trkcands.get(i).get_Pt()); - Helix helix = trkcands.get(i).get_helix(); - bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); - bank.setFloat("tandip", i, (float) helix.get_tandip()); - bank.setFloat("z0", i, (float) (helix.get_Z0()/10.)); - bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); + bank.setByte("fittingMethod", i, (byte) trkcands.get(i).getSeed().getStatus()); + bank.setShort("ID", i, (short) trkcands.get(i).getId()); + bank.setByte("q", i, (byte)trkcands.get(i).getQ()); + bank.setFloat("p", i, (float) trkcands.get(i).getP()); + bank.setFloat("pt", i, (float) trkcands.get(i).getPt()); + Helix helix = trkcands.get(i).getHelix(); + bank.setFloat("phi0", i, (float) helix.getPhiAtDCA()); + bank.setFloat("tandip", i, (float) helix.getTanDip()); + bank.setFloat("z0", i, (float) (helix.getZ0()/10.)); + bank.setFloat("d0", i, (float) (helix.getDCA()/10.)); bank.setFloat("xb", i, (float) (helix.getXb()/10.0)); bank.setFloat("yb", i, (float) (helix.getYb()/10.0)); // this is the format of the covariance matrix for helical tracks @@ -504,7 +504,7 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { // | d_curvature*d_dca d_curvature*d_phi_at_dca d_curvature*d_curvature 0 0 | // | 0 0 0 d_Z0*d_Z0 | // | 0 0 0 0 d_tandip*d_tandip |X - double[][] covmatrix = helix.get_covmatrix(); + double[][] covmatrix = helix.getCovMatrix(); if (covmatrix != null) { bank.setFloat("cov_d02", i, (float) covmatrix[0][0]/10/10 ); bank.setFloat("cov_d0phi0", i, (float) covmatrix[0][1]/10 ); @@ -524,14 +524,14 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { bank.setFloat("cov_z02", i, -999); bank.setFloat("cov_tandip2", i, -999); } - if(trkcands.get(i).get_TrackPosAtCTOF()!=null) { - bank.setFloat("c_x", i, (float) (trkcands.get(i).get_TrackPosAtCTOF().x() / 10.)); // convert to cm - bank.setFloat("c_y", i, (float) (trkcands.get(i).get_TrackPosAtCTOF().y() / 10.)); // convert to cm - bank.setFloat("c_z", i, (float) (trkcands.get(i).get_TrackPosAtCTOF().z() / 10.)); // convert to cm - bank.setFloat("c_ux", i, (float) trkcands.get(i).get_TrackDirAtCTOF().x()); - bank.setFloat("c_uy", i, (float) trkcands.get(i).get_TrackDirAtCTOF().y()); - bank.setFloat("c_uz", i, (float) trkcands.get(i).get_TrackDirAtCTOF().z()); - bank.setFloat("pathlength", i, (float) (trkcands.get(i).get_PathToCTOF() / 10.)); // conversion to cm + if(trkcands.get(i).getTrackPosAtCTOF()!=null) { + bank.setFloat("c_x", i, (float) (trkcands.get(i).getTrackPosAtCTOF().x() / 10.)); // convert to cm + bank.setFloat("c_y", i, (float) (trkcands.get(i).getTrackPosAtCTOF().y() / 10.)); // convert to cm + bank.setFloat("c_z", i, (float) (trkcands.get(i).getTrackPosAtCTOF().z() / 10.)); // convert to cm + bank.setFloat("c_ux", i, (float) trkcands.get(i).getTrackDirAtCTOF().x()); + bank.setFloat("c_uy", i, (float) trkcands.get(i).getTrackDirAtCTOF().y()); + bank.setFloat("c_uz", i, (float) trkcands.get(i).getTrackDirAtCTOF().z()); + bank.setFloat("pathlength", i, (float) (trkcands.get(i).getPathToCTOF() / 10.)); // conversion to cm } // fills the list of cross ids for crosses belonging to that reconstructed track for (int j = 0; j < 9; j++) { @@ -545,14 +545,14 @@ public DataBank fillTracksBank(DataEvent event, List trkcands) { if(j<9) { String hitStrg = "Cross"; hitStrg += (j + 1); - hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).get_Id()); - bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).get_Id()); + hitStrg += "_ID"; //System.out.println(" j "+j+" matched id "+trkcands.get(i).get(j).getId()); + bank.setShort(hitStrg, i, (short) trkcands.get(i).get(j).getId()); } } bank.setShort("status", i, (short) ((short) trkcands.get(i).getStatus())); -// bank.setFloat("circlefit_chi2_per_ndf", i, (float) trkcands.get(i).get_circleFitChi2PerNDF()); -// bank.setFloat("linefit_chi2_per_ndf", i, (float) trkcands.get(i).get_lineFitChi2PerNDF()); - bank.setShort("seedID", i, (short) trkcands.get(i).get_Seed().getId()); +// bank.setFloat("circlefit_chi2_per_ndf", i, (float) trkcands.get(i).getCircleFitChi2PerNDF()); +// bank.setFloat("linefit_chi2_per_ndf", i, (float) trkcands.get(i).getLineFitChi2PerNDF()); + bank.setShort("seedID", i, (short) trkcands.get(i).getSeed().getId()); bank.setFloat("chi2", i, (float) trkcands.get(i).getChi2()); bank.setShort("ndf", i, (short) trkcands.get(i).getNDF()); @@ -577,7 +577,7 @@ public DataBank fillTracksCovMatBank(DataEvent event, List trkcands) { for (int i = 0; i < trkcands.size(); i++) { if(trkcands.get(i)==null || trkcands.get(i).getTrackCovMat()==null) continue; - bank.setShort("ID", i, (short) trkcands.get(i).get_Id()); + bank.setShort("ID", i, (short) trkcands.get(i).getId()); double[][] covmatrix = trkcands.get(i).getTrackCovMat(); if (covmatrix != null) { String[][] names = new String[][]{ @@ -624,22 +624,22 @@ public DataBank fillStraightTracksBank(DataEvent event, List cosm List crossIdxArray = new ArrayList<>(); - bank.setShort("ID", i, (short) cosmics.get(i).get_Id()); - bank.setFloat("chi2", i, (float) cosmics.get(i).get_chi2()); + bank.setShort("ID", i, (short) cosmics.get(i).getId()); + bank.setFloat("chi2", i, (float) cosmics.get(i).getchi2()); bank.setShort("ndf", i, (short) (cosmics.get(i).size()-2)); - bank.setFloat("trkline_yx_slope", i, (float) cosmics.get(i).get_ray().get_yxslope()); - bank.setFloat("trkline_yx_interc", i, (float) (cosmics.get(i).get_ray().get_yxinterc()/10.)); - bank.setFloat("trkline_yz_slope", i, (float) cosmics.get(i).get_ray().get_yzslope()); - bank.setFloat("trkline_yz_interc", i, (float) (cosmics.get(i).get_ray().get_yzinterc()/10.)); + bank.setFloat("trkline_yx_slope", i, (float) cosmics.get(i).getRay().getYXSlope()); + bank.setFloat("trkline_yx_interc", i, (float) (cosmics.get(i).getRay().getYXInterc()/10.)); + bank.setFloat("trkline_yz_slope", i, (float) cosmics.get(i).getRay().getYZSlope()); + bank.setFloat("trkline_yz_interc", i, (float) (cosmics.get(i).getRay().getYZInterc()/10.)); // get the cosmics ray unit direction vector - Vector3D u = new Vector3D(cosmics.get(i).get_ray().get_yxslope(), 1, cosmics.get(i).get_ray().get_yzslope()).asUnit(); + Vector3D u = new Vector3D(cosmics.get(i).getRay().getYXSlope(), 1, cosmics.get(i).getRay().getYZSlope()).asUnit(); // calculate the theta and phi components of the ray direction vector in degrees bank.setFloat("theta", i, (float) Math.toDegrees(u.theta())); bank.setFloat("phi", i, (float) Math.toDegrees(u.phi())); // the array of cross ids is filled in order of the SVT cosmic region 1 to 8 starting from the bottom-most double layer for (int j = 0; j < cosmics.get(i).size(); j++) { - crossIdxArray.add(cosmics.get(i).get(j).get_Id()); + crossIdxArray.add(cosmics.get(i).get(j).getId()); } for (int j = 0; j < 18; j++) { String hitStrg = "Cross"; @@ -672,11 +672,11 @@ public DataBank fillStraightTracksTrajectoryBank(DataEvent event, List trk for (int i = 0; i < trks.size(); i++) { if(trks.get(i)==null) continue; - if (trks.get(i).get_Trajectory() == null) { + if (trks.get(i).getTrajectory() == null) { continue; } - for (StateVec stVec : trks.get(i).get_Trajectory()) + for (StateVec stVec : trks.get(i).getTrajectory()) bankSize++; } @@ -735,23 +735,23 @@ public DataBank fillHelicalTracksTrajectoryBank(DataEvent event, List trk for (int i = 0; i < trks.size(); i++) { if(trks.get(i)==null) continue; - if (trks.get(i).get_Trajectory() == null) { + if (trks.get(i).getTrajectory() == null) { continue; } - for (StateVec stVec : trks.get(i).get_Trajectory()) { + for (StateVec stVec : trks.get(i).getTrajectory()) { - bank.setShort("id", k, (short) trks.get(i).get_Id()); - bank.setByte("detector", k, (byte) stVec.get_SurfaceDetector()); - bank.setByte("sector", k, (byte) stVec.get_SurfaceSector()); - bank.setByte("layer", k, (byte) stVec.get_SurfaceLayer()); + bank.setShort("id", k, (short) trks.get(i).getId()); + bank.setByte("detector", k, (byte) stVec.getSurfaceDetector()); + bank.setByte("sector", k, (byte) stVec.getSurfaceSector()); + bank.setByte("layer", k, (byte) stVec.getSurfaceLayer()); bank.setFloat("x", k, (float) (stVec.x()/10.)); bank.setFloat("y", k, (float) (stVec.y()/10.)); bank.setFloat("z", k, (float) (stVec.z()/10.)); - bank.setFloat("phi", k, (float) stVec.get_TrkPhiAtSurface()); - bank.setFloat("theta", k, (float) stVec.get_TrkThetaAtSurface()); - bank.setFloat("langle", k, (float) stVec.get_TrkToModuleAngle()); - bank.setFloat("centroid", k, (float) stVec.get_CalcCentroidStrip()); - bank.setFloat("path", k, (float) stVec.get_Path()/10); + bank.setFloat("phi", k, (float) stVec.getTrkPhiAtSurface()); + bank.setFloat("theta", k, (float) stVec.getTrkThetaAtSurface()); + bank.setFloat("langle", k, (float) stVec.getTrkToModuleAngle()); + bank.setFloat("centroid", k, (float) stVec.getCalcCentroidStrip()); + bank.setFloat("path", k, (float) stVec.getPath()/10); k++; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/package-info.java deleted file mode 100644 index 41ca01a7c..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * A package with classes to read evio dgtz banks and write reconstruction banks - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.banks; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java index 6f23e5e7f..a053a6e24 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTConstants.java @@ -66,22 +66,15 @@ private BMTConstants() { // THE RECONSTRUCTION CONSTANTS - //public static final double SigmaDrift = 0.4; // Max transverse diffusion value (GEMC value) - public static final double SigmaDrift = 0.036; // Max transverse diffusion value (GEMC value) + public static final double SIGMADRIFT = 0.036; // Max transverse diffusion value (GEMC value) - public static final double hDrift = 3.0; // Size of the drift gap + public static final double HDRIFT = 3.0; // Size of the drift gap - public static Point3D[][] shifts = new Point3D[NLAYERS][NSECTORS]; // detector alignment shifts - public static Vector3D[][] rotations = new Vector3D[NLAYERS][NSECTORS]; // detector alignment rotations - public static Line3D[][] axes = new Line3D[NLAYERS][NSECTORS]; // detector axes - public static Transformation3D[][] toLocal = new Transformation3D[NLAYERS][NSECTORS]; - public static Transformation3D[][] toGlobal = new Transformation3D[NLAYERS][NSECTORS]; - public static double[][] Rx= new double[NREGIONS*2][3]; //Angle to rotate the det around x-axis - public static double[][] Ry= new double[NREGIONS*2][3]; //Angle to rotate the det around y-axis - public static double[][] Rz= new double[NREGIONS*2][3]; //Angle to rotate the det around z-axis - public static double[][] Cx= new double[NREGIONS*2][3]; //x-position of Center of detector frame - public static double[][] Cy= new double[NREGIONS*2][3]; //y-position of Center of detector frame - public static double[][] Cz= new double[NREGIONS*2][3]; //z-position of Center of detector frame + public static Point3D[][] SHIFTS = new Point3D[NLAYERS][NSECTORS]; // detector alignment SHIFTS + public static Vector3D[][] ROTATIONS = new Vector3D[NLAYERS][NSECTORS]; // detector alignment ROTATIONS + public static Line3D[][] AXES = new Line3D[NLAYERS][NSECTORS]; // detector AXES + public static Transformation3D[][] TOLOCAL = new Transformation3D[NLAYERS][NSECTORS]; + public static Transformation3D[][] TOGLOBAL = new Transformation3D[NLAYERS][NSECTORS]; public static double[] ThetaL_grid = new double[405]; //Lorentz angle grid public static double[] E_grid = new double[405]; //Electric field value of the grid public static double[] B_grid = new double[405]; //Magnetic field value of the grid @@ -97,19 +90,6 @@ private BMTConstants() { // THE HV CONSTANT public static double[][] E_DRIFT_FF = new double[2*NREGIONS][3]; public static double[][] E_DRIFT_MF = new double[2*NREGIONS][3]; - //private static double ThetaL = 0; // the Lorentz angle for 5-T B-field - - //private static double w_i =25.0; - public static boolean areConstantsLoaded = false; - - // ----- cut based cand select - public static final double phi12cut = 35.; - public static final double phi13cut = 35.; - public static final double phi14cut = 35.; - public static final double radcut = 100.; - public static final double drdzcut = 150.; -// public static final double LYRTHICKN = 0.0; // old LYRTHICKN = 4.; - public static final double isInSectorJitter = 2.0; // 2 deg public static final int STARTINGLAYR = 1; @@ -372,17 +352,17 @@ public static synchronized void setEFF_Z_OVER_A(double[] eFF_Z_OVER_A) { EFF_Z_OVER_A = eFF_Z_OVER_A; } - public static double[] get_T_OVER_X0() { + public static double[] getT_OVER_X0() { return T_OVER_X0; } - public static synchronized void set_T_OVER_X0(double[] t_OVER_X0) { + public static synchronized void setT_OVER_X0(double[] t_OVER_X0) { T_OVER_X0 = t_OVER_X0; } - public static double[] get_Material_T() { + public static double[] getMaterial_T() { return TMAT; } - public static synchronized void set_Material_T(double[] t) { + public static synchronized void setMaterial_T(double[] t) { TMAT = t; } @@ -429,34 +409,16 @@ public static synchronized void setPar_grid() { public static synchronized void setE_drift_FF(double[][] cHV_drift) { for (int i=0; i<2*NREGIONS;i++) { for (int j=0; j<3;j++) { - E_DRIFT_FF[i][j] = 10*cHV_drift[i][j]/hDrift; + E_DRIFT_FF[i][j] = 10*cHV_drift[i][j]/HDRIFT; } } } public static synchronized void setE_drift_MF(double[][] cHV_drift) { for (int i=0; i<2*NREGIONS;i++) { for (int j=0; j<3;j++) { - E_DRIFT_MF[i][j] = 10*cHV_drift[i][j]/hDrift; + E_DRIFT_MF[i][j] = 10*cHV_drift[i][j]/HDRIFT; } } } - public static synchronized void setRx(int layer, int sector, double cRx) { - Rx[layer-1][sector-1] = cRx; - } - public static synchronized void setRy(int layer, int sector, double cRy) { - Ry[layer-1][sector-1] = cRy; - } - public static synchronized void setRz(int layer, int sector, double cRz) { - Rz[layer-1][sector-1] = cRz; - } - public static synchronized void setCx(int layer, int sector, double cCx) { - Cx[layer-1][sector-1] = cCx; - } - public static synchronized void setCy(int layer, int sector, double cCy) { - Cy[layer-1][sector-1] = cCy; - } - public static synchronized void setCz(int layer, int sector, double cCz) { - Cz[layer-1][sector-1] = cCz; - } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 80f74f4c7..50e7b6294 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -122,7 +122,7 @@ public double getRadius(int layer) { * @return radius (=0 if layer is out of range) */ public double getRadiusMidDrift(int layer) { - return this.getRadius(layer) + BMTConstants.hDrift/2; + return this.getRadius(layer) + BMTConstants.HDRIFT/2; } /** @@ -272,7 +272,7 @@ public double getDPhi(int layer, int sector) { */ public double getThickness() { - return BMTConstants.hDrift; + return BMTConstants.HDRIFT; } /** @@ -284,7 +284,7 @@ public double getToverX0(int layer) { if(!(layer>=1 && layer<=BMTConstants.NLAYERS)) throw new IllegalArgumentException("Error: invalid layer="+layer); - return BMTConstants.get_T_OVER_X0()[layer-1]; + return BMTConstants.getT_OVER_X0()[layer-1]; } /** @@ -296,7 +296,7 @@ public double getMaterialThickness(int layer) { if(!(layer>=1 && layer<=BMTConstants.NLAYERS)) throw new IllegalArgumentException("Error: invalid layer="+layer); - return BMTConstants.get_Material_T()[layer-1]; + return BMTConstants.getMaterial_T()[layer-1]; } /** @@ -320,7 +320,7 @@ public double getZoverA(int layer) { public Point3D getOffset(int layer, int sector) { Point3D offset = new Point3D(); if(layer>0 && layer 0 && sector0 && layer 0 && sector this.getNStrips(layer)) { strip = -1; } @@ -880,6 +848,10 @@ public double getThetaLorentz(int layer, int sector) { * Calculate Theta Lorentz based on solenoid scale and drift settings * @param layer * @param sector + * @param x + * @param y + * @param z + * @param swim * @return thetaL in radians */ public double getThetaLorentz(int layer, int sector, double x, double y, double z, Swim swim) { @@ -907,18 +879,6 @@ public double getThetaLorentz(int layer, int sector, double x, double y, double if (Constants.getSolenoidScale()<0) thetaL=-thetaL; return thetaL; } - - - /** - * Calculate Lorentz angle correction - * @param layer - * @param sector - * @return - */ - @Deprecated - public double LorentzAngleCorr(int layer, int sector) { - return (this.getThickness()/2 * Math.tan(this.getThetaLorentz(layer, sector))) / this.getRadius(layer); - } /** * Return track vector for local angle calculations @@ -1185,394 +1145,5 @@ public static void main (String arg[]) { frame.setLocationRelativeTo(null); frame.setVisible(true); } - - - //added methods: -// public int isInDetector(int layer, double angle, double jitter) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// int num_detector = 2; -// //double jitter = Math.toRadians(BMTConstants.isInSectorJitter); -// for (int i = 0; i < 3; i++) { -// -// //angle_i=BMTConstants.getCRCEDGE1()[num_region][i]+BMTConstants.getCRCXPOS()[num_region]/Constants.getCRCRADIUS()[num_region]; -// //angle_f=BMTConstants.getCRCEDGE1()[num_region][i]+(BMTConstants.getCRCXPOS()[num_region]+BMTConstants.getCRCLENGTH()[num_region])/Constants.getCRCRADIUS()[num_region]; -// angle_i = BMTConstants.getCRCEDGE1()[num_region][i]; -// angle_f = BMTConstants.getCRCEDGE2()[num_region][i]; -// if ((angle >= angle_i - jitter && angle <= angle_f + jitter)) { -// num_detector = i; -// } -// } -// -// return num_detector; -// } -// public int isInSector(int layer, double angle, double jitter) { -// //double jitter = Math.toRadians(BMTConstants.isInSectorJitter); -// int value = -1; -// int num_det = this.isInDetector(layer, angle, jitter); -// /* if(num_det == 0) -// value = 2; -// if(num_det ==2) -// value = 3; -// if(num_det == 1) -// value = 1; */ -// value = num_det + 1; -// -// return value; -// } - -// /** -// * -// * @param layer the hit layer -// * @param strip the hit strip -// * @return the z position in mm for the C-detectors -// */ -// public double CRCStrip_GetZ(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = BMTConstants.getCRCGROUP()[num_region][group]; -// double zc = BMTConstants.getCRCZMIN()[num_region]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// zc += BMTConstants.getCRCWIDTH()[num_region][group]; -// if (j >= limit) { //test if we change the width -// group++; -// limit += BMTConstants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// zc += BMTConstants.getCRCWIDTH()[num_region][group]/2.; -// return zc; //in mm -// } - -// public double CRCStrip_GetPitch(int layer, int strip) { -// -// int num_strip = strip - 1; // index of the strip (starts at 0) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CR6C, this function returns the Z position of the strip center -// int group = 0; -// int limit = BMTConstants.getCRCGROUP()[num_region][group]; -// -// if (num_strip > 0) { -// for (int j = 1; j < num_strip + 1; j++) { -// -// if (j >= limit) { //test if we change the width -// group++; -// limit += BMTConstants.getCRCGROUP()[num_region][group]; -// } -// } -// } -// -// return BMTConstants.getCRCWIDTH()[num_region][group]; // -// } - -// /** -// * -// * @param layer the layer 1...6 -// * @param angle the position angle of the hit in the Z detector -// * @return the Z strip as a function of azimuthal angle -// */ -// public int getZStrip(int layer, double angle) { // the angle is the Lorentz uncorrected angle -// double jitter = Math.toRadians(BMTConstants.isInSectorJitter); -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int num_detector = isInDetector(layer, angle, jitter); -// if (num_detector == -1) { -// return -1; -// } -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// if (num_detector == 1) { -// double angle_f = BMTConstants.getCRCEDGE1()[num_region][1] + (BMTConstants.getCRCXPOS()[num_region] + BMTConstants.getCRCLENGTH()[num_region]) / BMTConstants.getCRCRADIUS()[num_region] - 2 * Math.PI; -// if (angle >= 0 && angle <= angle_f) { -// angle += 2 * Math.PI; -// } -// } -// //double strip_calc = ( (angle-BMTConstants.getCRZEDGE1()[num_region][num_detector])*BMTConstants.getCRZRADIUS()[num_region]-BMTConstants.getCRZXPOS()[num_region]-BMTConstants.getCRZWIDTH()[num_region]/2.)/(BMTConstants.getCRZWIDTH()[num_region]+BMTConstants.getCRZSPACING()[num_region]); -// //double strip_calc = ((angle - BMTConstants.getCRZEDGE1()[num_region][num_detector]) * BMTConstants.getCRZRADIUS()[num_region]) / (BMTConstants.getCRZWIDTH()[num_region]); -// double strip_calc = ((angle - BMTConstants.getCRZEDGE1()[num_region][num_detector]) * BMTConstants.getCRZRADIUS()[num_region]) / (BMTConstants.getCRZWIDTH()[num_region])-0.5; -// strip_calc = (int) (Math.round(strip_calc * 1d) / 1d); -// int strip_num = (int) Math.floor(strip_calc); -// -// int value = strip_num + 1; -// //int value = strip_num; -// -// if (value < 1 || value > BMTConstants.getCRZNSTRIPS()[num_region]) { -// value = -1; -// } -// -// return value; -// } - -// public void setLorentzAngle(int layer, int sector) { -// BMTConstants.setThetaL(layer, sector); -// } -//// // Correct strip position before clustering -//// public int getLorentzCorrectedZStrip(int sector, int layer, int theMeasuredZStrip) { -//// -//// double theMeasuredPhi = this.CRZStrip_GetPhi(sector, layer, theMeasuredZStrip); -//// double theLorentzCorrectedAngle = this.LorentzAngleCorr(theMeasuredPhi, layer); -//// -//// return this.getZStrip(layer, theLorentzCorrectedAngle); -//// } -// public double LorentzAngleCorr(double phi, int layer) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //return phi +( BMTConstants.hDrift/2*Math.tan(BMTConstants.getThetaL()) )/Constants.getCRZRADIUS()[num_region]; -// //return phi + (BMTConstants.hDrift * Math.tan(BMTConstants.getThetaL())) / (BMTConstants.getCRZRADIUS()[num_region]); -// return phi + (BMTConstants.hStrip2Det * Math.tan(BMTConstants.getThetaL())) / (BMTConstants.getCRZRADIUS()[num_region]); -// } -// -// /** -// * -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating is the track hit is in the fiducial detector -// */ -// public boolean isInFiducial(int sector, int layer, int axis,double[] x) { -// -// boolean isInFid = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6; -// -// double z_i = CRZ_GetZStrip(layer) - BMTConstants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile lower limit -// double z_f = CRZ_GetZStrip(layer) + BMTConstants.getCRZLENGTH()[num_region] / 2.; // fiducial z-profile upper limit -// -// double R_i = 0; // inner radius init -// double R_f = 0; // outer radius init for a C or Z detector -// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 1) { -// R_i = BMTConstants.getCRZRADIUS()[num_region]; // Z layer -// } -// if (org.jlab.rec.cvt.bmt.OldGeometry.getZorC(layer) == 0) { -// R_i = BMTConstants.getCRCRADIUS()[num_region]; // // C-dtectors -// } -// R_f = R_i + BMTConstants.hDrift; -// -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// double A_i = CRC_GetBeginStrip(sector, layer); -// double A_f = CRC_GetEndStrip(sector, layer); -// angle_i = A_i; -// angle_f = A_f; -// if (A_i > A_f) { // for B-detector -// angle_f = A_i; -// angle_i = A_f; -// } -// // the hit parameters -// double angle = Math.atan2(x[1], x[0]); -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// double R = Math.sqrt(x[0] * x[0] + x[1] * x[1]); -// double z = x[2]; -// -// if ((angle_i - angle) < (angle_f - angle_i) && (R - R_i) < (R_f - R_i) && (z - z_i) < (z_f - z_i)) { -// isInFid = true; -// } -// -// return isInFid; -// } -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the beginning of the strips -// */ -// public double CRC_GetBeginStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the beginning of the strips -// double angle = BMTConstants.getCRCEDGE1()[num_region][num_detector] + BMTConstants.getCRCXPOS()[num_region] / BMTConstants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// -// /** -// * -// * @param sector the sector in CLAS12 1...3 -// * @param layer the layer 1...6 -// * @return the angle to localize the end of the strips -// */ -// public double CRC_GetEndStrip(int sector, int layer) { -// // Sector = num_detector + 1; -// // num_detector = 0 (region A), 1 (region B), 2, (region C) -// -// int num_detector = sector -1; // index of the detector (0...2) -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// -// //For CRC, this function returns the angle to localize the end of the strips -// double angle = BMTConstants.getCRCEDGE2()[num_region][num_detector] + BMTConstants.getCRCXPOS()[num_region] / BMTConstants.getCRCRADIUS()[num_region]; -// if (angle > 2 * Math.PI) { -// angle -= 2 * Math.PI; -// } -// return angle; //in rad -// } -// /** -// * -// * @param angle -// * @param sector -// * @param layer -// * @param x -// * @return a boolean indicating if the given angle is the sector -// */ -// public boolean checkIsInSector( double angle, int sector, int layer, double jitter ) { -// if( layer < 1 || layer > 6 ) { -// System.err.println(" BMT layer has to be 1 <= layer <= 6"); -// return false; -// } -// if( sector < 1 || sector > 3 ) { -// System.err.println(" BMT sector has to be 1 <= layer <= 3"); -// return false; -// } -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// double angle_i = 0; // first angular boundary init -// double angle_f = 0; // second angular boundary for detector A, B, or C init -// angle_i = BMTConstants.getCRCEDGE1()[num_region][sector-1]; -// angle_f = BMTConstants.getCRCEDGE2()[num_region][sector-1]; -// -// -// if (angle < 0) { -// angle += 2 * Math.PI; // from 0 to 2Pi -// } -// -// if( sector == 3 ) { -// if( angle < Math.PI ) { -// if( angle < angle_f + jitter ) return true; -// else return false; -// } -// else { -// if( angle > angle_i - jitter ) return true; -// else return false; -// } -// } -// else { -// if ( (angle >= angle_i - jitter && angle <= angle_f + jitter)) -// return true; -// else -// return false; -// -// } -// } - -// /** -// * -// * @param layer -// * @param trk_z the track z position of intersection with the C-detector -// * @return the C-strip -// */ -// public int getCStrip(int layer, double trk_z) { -// -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// int strip_group = 0; -// int ClosestStrip = -1; -// // get group -// int len = BMTConstants.getCRCGROUP()[num_region].length; -// double[] Z_lowBound = new double[len]; -// double[] Z_uppBound = new double[len]; -// int[] NStrips = new int[len]; -// -// double zi = BMTConstants.getCRCZMIN()[num_region] + BMTConstants.getCRCOFFSET()[num_region]; -// double z = trk_z - zi; -// -// for (int i = 0; i < len; i++) { -// if(i==0) { -// Z_lowBound[i] = 0; -// NStrips[i] = BMTConstants.getCRCGROUP()[num_region][i]; -// } -// else { -// Z_lowBound[i] = Z_uppBound[i - 1]; -// NStrips[i] = NStrips[i - 1] + BMTConstants.getCRCGROUP()[num_region][i]; -// } -// Z_uppBound[i] = Z_lowBound[i] + BMTConstants.getCRCGROUP()[num_region][i] * BMTConstants.getCRCWIDTH()[num_region][i]; -// -// if (z >= Z_lowBound[i] && z <= Z_uppBound[i]) { -// strip_group = i; -// ClosestStrip = 1 + (int) Math.floor((z - Z_lowBound[strip_group]) / BMTConstants.getCRCWIDTH()[num_region][strip_group]); -// if(i>0) ClosestStrip += NStrips[i - 1]; -// //ClosestStrip = (int) (Math.round(((z-Z_lowBound[strip_group])/(BMTConstants.getCRCWIDTH()[num_region][strip_group] + BMTConstants.getCRCSPACING()[num_region]))))+NStrips[i-1]; -// -// len = i; -// } -// } -// return ClosestStrip; -// } -// -// public boolean isInFiducial(double x, double y, double z, int layer) { -// -// boolean isOK = false; -// -// int num_region = (int) (layer + 1) / 2 - 1; -// -// int axis = OldGeometry.getZorC(layer); -// -// double R = 0; -// if (axis == 0) { -// R = BMTConstants.getCRCRADIUS()[num_region]; -// } -// if (axis == 1) { -// R = BMTConstants.getCRZRADIUS()[num_region]; -// } -// -// double CRZLENGTH = BMTConstants.getCRCLENGTH()[num_region]; -// double CRZZMIN = BMTConstants.getCRZZMIN()[num_region]; -// double CRZOFFSET = BMTConstants.getCRZOFFSET()[num_region]; -// -// double z_min = CRZZMIN + CRZOFFSET; -// double z_max = z_min + CRZLENGTH; -// -// double epsilon = 1e-1; -// -// if (Math.abs(x) < R + epsilon && Math.abs(y) < R + epsilon && z > z_min - epsilon && z < z_max + epsilon) { -// isOK = true; -// } -// return isOK; -// } -// -// /** -// * -// * @param layer the layer 1...6 -// * @return the Z position of the strip center -// */ -// private double CRZ_GetZStrip(int layer) { -// int num_region = (int) (layer + 1) / 2 - 1; // region index (0...2) 0=layers 1&2, 1=layers 3&4, 2=layers 5&6 -// //For CRZ, this function returns the Z position of the strip center -// double zc = BMTConstants.getCRZZMIN()[num_region] + BMTConstants.getCRZOFFSET()[num_region] + BMTConstants.getCRZLENGTH()[num_region] / 2.; -// return zc; //in mm -// } - - - public void putInFrame(Point3D cent, Point3D offset, Vector3D rotation, boolean inverse) { - if(inverse==false) { - cent.rotateX(rotation.x()); - cent.rotateY(rotation.y()); - cent.rotateZ(rotation.z()); - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - } else { - cent.translateXYZ(offset.x(),offset.y(),offset.z()); - cent.rotateZ(rotation.z()); - cent.rotateY(rotation.y()); - cent.rotateX(rotation.x()); - } - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java index c9708c4c4..a307b03a0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/CCDBConstantsLoader.java @@ -32,7 +32,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) int NLAYERS = BMTConstants.NLAYERS; double[] CRZRADIUS = new double[NREGIONS]; // the radius of the Z detector in mm int[] CRZNSTRIPS = new int[NREGIONS]; // the number of strips - double[] CRZSPACING = new double[NREGIONS]; // the strip spacing in mm + double[] CRZSPACING = new double[NREGIONS]; // the strip spacing in mm double[] CRZWIDTH = new double[NREGIONS]; // the strip width in mm double[] CRZLENGTH = new double[NREGIONS]; // the strip length in mm double[] CRZZMIN = new double[NREGIONS]; // PCB upstream extremity mm @@ -136,14 +136,6 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) } } } -// for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L4/Group_size"); i++) { -// CRCGROUP[1][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L4/Group_size", i); -// CRCWIDTH[1][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L4/Pitch", i); -// } -// for (int i = 0; i < dbprovider.length("/geometry/cvt/mvt/bmt_strip_L6/Group_size"); i++) { -// CRCGROUP[2][i] = dbprovider.getInteger("/geometry/cvt/mvt/bmt_strip_L6/Group_size", i); -// CRCWIDTH[2][i] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L6/Pitch", i); -// } CRZWIDTH[0] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L2/Pitch", 0); CRZWIDTH[1] = dbprovider.getDouble("/geometry/cvt/mvt/bmt_strip_L3/Pitch", 0); @@ -283,11 +275,11 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) transform.translateXYZ(shift.x(), shift.y(), shift.z()); Line3D axis = new Line3D(new Point3D(0,0,Zmin), new Vector3D(0,0,Zmax)); transform.apply(axis); - BMTConstants.shifts[layer-1][sector-1] = shift; - BMTConstants.rotations[layer-1][sector-1] = rot; - BMTConstants.axes[layer-1][sector-1] = axis; - BMTConstants.toGlobal[layer-1][sector-1] = transform; - BMTConstants.toLocal[layer-1][sector-1] = transform.inverse(); + BMTConstants.SHIFTS[layer-1][sector-1] = shift; + BMTConstants.ROTATIONS[layer-1][sector-1] = rot; + BMTConstants.AXES[layer-1][sector-1] = axis; + BMTConstants.TOGLOBAL[layer-1][sector-1] = transform; + BMTConstants.TOLOCAL[layer-1][sector-1] = transform.inverse(); } @@ -323,7 +315,7 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) BMTConstants.setCRCGRPNMAX(CRCGRPNMAX); BMTConstants.setCRZWIDTH(CRZWIDTH); BMTConstants.setEFF_Z_OVER_A(EFF_Z_OVER_A); - BMTConstants.set_T_OVER_X0(T_OVER_X0); + BMTConstants.setT_OVER_X0(T_OVER_X0); BMTConstants.setTHETAL_grid(THETA_L_grid); BMTConstants.setE_grid(ELEC_grid); BMTConstants.setB_grid(MAG_grid); @@ -332,14 +324,6 @@ public static final synchronized void Load(DatabaseConstantProvider dbprovider) BMTConstants.setE_drift_MF(HV_DRIFT_MF); dbprovider.disconnect(); CSTLOADED = true; - // setDB(dbprovider); } - //public static final synchronized DatabaseConstantProvider getDB() { - // return DB; - //} - - //public static final synchronized void setDB(DatabaseConstantProvider dB) { - // DB = dB; - //} } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/package-info.java deleted file mode 100644 index 528d497a6..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.bmt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java index ae9a3b740..260084c7b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/Cluster.java @@ -81,22 +81,22 @@ public Cluster(DetectorType detector, BMTType type, int sector, int layer, int c * number. */ public Cluster newCluster(Hit hit, int cid) { - return new Cluster(hit.get_Detector(), hit.get_Type(), hit.get_Sector(), hit.get_Layer(), cid); + return new Cluster(hit.getDetector(), hit.getType(), hit.getSector(), hit.getLayer(), cid); } - public DetectorType get_Detector() { + public DetectorType getDetector() { return _Detector; } - public void set_Detector(DetectorType _Detector) { + public void setDetector(DetectorType _Detector) { this._Detector = _Detector; } - public BMTType get_Type() { + public BMTType getType() { return _Type; } - public void set_Type(BMTType type) { + public void setType(BMTType type) { this._Type = type; } @@ -104,7 +104,7 @@ public void set_Type(BMTType type) { * * @return the sector of the cluster */ - public int get_Sector() { + public int getSector() { return _Sector; } @@ -112,7 +112,7 @@ public int get_Sector() { * * @param _Sector sector of the cluster */ - public void set_Sector(int _Sector) { + public void setSector(int _Sector) { this._Sector = _Sector; } @@ -120,7 +120,7 @@ public void set_Sector(int _Sector) { * * @return the layer of the cluster */ - public int get_Layer() { + public int getLayer() { return _Layer; } @@ -128,7 +128,7 @@ public int get_Layer() { * * @param _Layer the layer of the cluster */ - public void set_Layer(int _Layer) { + public void setLayer(int _Layer) { this._Layer = _Layer; } @@ -136,7 +136,7 @@ public void set_Layer(int _Layer) { * * @return the id of the cluster */ - public int get_Id() { + public int getId() { return _Id; } @@ -144,7 +144,7 @@ public int get_Id() { * * @param _Id the id of the cluster */ - public void set_Id(int _Id) { + public void setId(int _Id) { this._Id = _Id; } @@ -152,7 +152,7 @@ public void set_Id(int _Id) { * * @return region (1...4) */ - public int get_Region() { + public int getRegion() { return (int) (this._Layer + 1) / 2; } @@ -160,7 +160,7 @@ public int get_Region() { * * @return superlayer 1 or 2 in region (1...4) */ - public int get_RegionSlayer() { + public int getRegionSlayer() { return (this._Layer + 1) % 2 + 1; } @@ -168,26 +168,26 @@ public int get_RegionSlayer() { * @return the _Radius */ public double getRadius() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return 0; else { - return this.get(0).get_Strip().get_Tile().baseArc().radius(); + return this.get(0).getStrip().getTile().baseArc().radius(); } } public Line3D getAxis() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return new Line3D(); else { - return this.get(0).get_Strip().get_Tile().getAxis(); + return this.get(0).getStrip().getTile().getAxis(); } } public Cylindrical3D getTile() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return null; else { - return this.get(0).get_Strip().get_Tile(); + return this.get(0).getStrip().getTile(); } } /** @@ -222,7 +222,7 @@ public void calc_CentroidParams() { int nbhits = this.size(); //sort for bmt detector - //this.sort(Comparator.comparing(FittedHit.get_Strip()::get_Edep).thenComparing(FittedHit.get_Strip()::get_Edep)); + //this.sort(Comparator.comparing(FittedHit.getStrip()::getEdep).thenComparing(FittedHit.getStrip()::getEdep)); Collections.sort(this); if (nbhits != 0) { @@ -245,48 +245,48 @@ public void calc_CentroidParams() { Point3D stCent0 = null; // strip energy - double strpEn = thehit.get_Strip().get_Edep(); + double strpEn = thehit.getStrip().getEdep(); // strip time - double strpTime = thehit.get_Strip().get_Time(); + double strpTime = thehit.getStrip().getTime(); - if (this.get_Detector()==DetectorType.BST) { + if (this.getDetector()==DetectorType.BST) { // for the SVT the analysis only uses the centroid - strpNb = thehit.get_Strip().get_Strip(); - stEP1 = thehit.get_Strip().get_Line().origin(); - stEP2 = thehit.get_Strip().get_Line().end(); - stCent = thehit.get_Strip().get_Line().midpoint(); - stCent0 = thehit.get_Strip().get_Line().midpoint(); + strpNb = thehit.getStrip().getStrip(); + stEP1 = thehit.getStrip().getLine().origin(); + stEP2 = thehit.getStrip().getLine().end(); + stCent = thehit.getStrip().getLine().midpoint(); + stCent0 = thehit.getStrip().getLine().midpoint(); } - else if (this.get_Detector()==DetectorType.BMT) { + else if (this.getDetector()==DetectorType.BMT) { // if(thehit.newClustering && nbhits>BMTConstants.MAXCLUSSIZE && i>BMTConstants.MAXCLUSSIZE-1) // continue; // for the BMT the analysis distinguishes between C and Z type detectors - if (this.get_Type()==BMTType.C) { // C-detectors - //strpEn = Math.sqrt(thehit.get_Strip().get_Edep()); - strpNb = thehit.get_Strip().get_Strip(); - stEP1 = thehit.get_Strip().get_Arc().origin(); - stEP2 = thehit.get_Strip().get_Arc().end(); - stCent = thehit.get_Strip().get_Arc().center(); - stCent0 = thehit.get_Strip().get_Arc().center(); + if (this.getType()==BMTType.C) { // C-detectors + //strpEn = Math.sqrt(thehit.getStrip().getEdep()); + strpNb = thehit.getStrip().getStrip(); + stEP1 = thehit.getStrip().getArc().origin(); + stEP2 = thehit.getStrip().getArc().end(); + stCent = thehit.getStrip().getArc().center(); + stCent0 = thehit.getStrip().getArc().center(); // for C detector the Z of the centroid is calculated - weightedZ += strpEn * thehit.get_Strip().get_Z(); - weightedZErrSq += (thehit.get_Strip().get_ZErr()) * (thehit.get_Strip().get_ZErr()); + weightedZ += strpEn * thehit.getStrip().getZ(); + weightedZErrSq += (thehit.getStrip().getZErr()) * (thehit.getStrip().getZErr()); } - if (this.get_Type()==BMTType.Z) { // Z-detectors + if (this.getType()==BMTType.Z) { // Z-detectors // for Z detectors Lorentz-correction is applied to the strip - strpNb = thehit.get_Strip().get_LCStrip(); - strpNb0 = thehit.get_Strip().get_Strip(); - stEP1 = thehit.get_Strip().get_Line().origin(); - stEP2 = thehit.get_Strip().get_Line().end(); + strpNb = thehit.getStrip().getLCStrip(); + strpNb0 = thehit.getStrip().getStrip(); + stEP1 = thehit.getStrip().getLine().origin(); + stEP2 = thehit.getStrip().getLine().end(); // RDV: should remove stuff that is not used or necessary from cluster strips and so on // for Z detectors the phi of the centroid is calculated for the uncorrected and the Lorentz-angle-corrected centroid - stCent = new Point3D(Math.cos(thehit.get_Strip().get_Phi()),Math.sin(thehit.get_Strip().get_Phi()),0); - stCent0 = new Point3D(Math.cos(thehit.get_Strip().get_Phi0()),Math.sin(thehit.get_Strip().get_Phi0()),0); - weightedPhiErrSq += (thehit.get_Strip().get_PhiErr()) * (thehit.get_Strip().get_PhiErr()); - weightedPhiErrSq0 += (thehit.get_Strip().get_PhiErr0()) * (thehit.get_Strip().get_PhiErr0()); + stCent = new Point3D(Math.cos(thehit.getStrip().getPhi()),Math.sin(thehit.getStrip().getPhi()),0); + stCent0 = new Point3D(Math.cos(thehit.getStrip().getPhi0()),Math.sin(thehit.getStrip().getPhi0()),0); + weightedPhiErrSq += (thehit.getStrip().getPhiErr()) * (thehit.getStrip().getPhiErr()); + weightedPhiErrSq0 += (thehit.getStrip().getPhiErr0()) * (thehit.getStrip().getPhiErr0()); } @@ -318,7 +318,7 @@ else if (this.get_Detector()==DetectorType.BMT) { max = strpNb; } // getting the seed strip which is defined as the strip with the largest deposited energy - if (seed==null || strpEn >= seed.get_Strip().get_Edep()) { + if (seed==null || strpEn >= seed.getStrip().getEdep()) { seed = thehit; } @@ -329,9 +329,9 @@ else if (this.get_Detector()==DetectorType.BMT) { return; } - this.set_MinStrip(min); - this.set_MaxStrip(max); - this.set_Seed(seed); + this.setMinStrip(min); + this.setMaxStrip(max); + this.setSeed(seed); // calculates the centroid values and associated errors aveTime /= totHits; weightedStrp /= totEn; @@ -351,56 +351,56 @@ else if (this.get_Detector()==DetectorType.BMT) { weightedZ /= totEn; weightedPhi = Math.atan2(weightedYC, weightedXC); weightedPhi0 = Math.atan2(weightedY0, weightedX0); - this.set_Centroid(weightedStrp); - this.set_TotalEnergy(totEn); - this.set_Time(aveTime); - this.set_Phi(weightedPhi); - this.set_Phi0(weightedPhi0); + this.setCentroid(weightedStrp); + this.setTotalEnergy(totEn); + this.setTime(aveTime); + this.setPhi(weightedPhi); + this.setPhi0(weightedPhi0); //setting final variables, including the ones used for alignment //----------------------------------- - if (this.get_Detector()==DetectorType.BST) { //SVT + if (this.getDetector()==DetectorType.BST) { //SVT this.setLine(new Line3D(weightedX1, weightedY1, weightedZ1, weightedX2, weightedY2, weightedZ2)); Vector3D l = new Vector3D(this.getLine().direction().asUnit()); - Vector3D n = this.get(0).get_Strip().get_Normal(); + Vector3D n = this.get(0).getStrip().getNormal(); Vector3D s = l.cross(n).asUnit(); this.setL(l); this.setS(s); this.setN(n); } - else if (this.get_Detector()==DetectorType.BMT) { //BMT + else if (this.getDetector()==DetectorType.BMT) { //BMT // for the BMT the analysis distinguishes between C and Z type detectors - if (this.get_Type()==BMTType.C) { // C-detectors + if (this.getType()==BMTType.C) { // C-detectors Point3D origin = new Point3D(weightedX1, weightedY1, weightedZ1); Point3D center = new Point3D(weightedXC, weightedYC, weightedZC); - Vector3D normal = this.get(0).get_Strip().get_Arc().normal(); - double theta = this.get(0).get_Strip().get_Arc().theta(); - this.set_Arc(new Arc3D(origin,center,normal,theta)); + Vector3D normal = this.get(0).getStrip().getArc().normal(); + double theta = this.get(0).getStrip().getArc().theta(); + this.setArc(new Arc3D(origin,center,normal,theta)); - Vector3D s = this.get_Arc().normal(); - Vector3D n = this.get_Arc().bisect(); + Vector3D s = this.getArc().normal(); + Vector3D n = this.getArc().bisect(); Vector3D l = s.cross(n).asUnit(); this.setL(l); this.setS(s); this.setN(n); - this.set_Z(weightedZ); - this.set_ZErr(Math.sqrt(weightedZErrSq)); - this.set_CentroidValue(weightedZ); - this.set_CentroidError(Math.sqrt(weightedZErrSq)); - this.set_Resolution(Math.sqrt(weightedZErrSq)); + this.setZ(weightedZ); + this.setZErr(Math.sqrt(weightedZErrSq)); + this.setCentroidValue(weightedZ); + this.setCentroidError(Math.sqrt(weightedZErrSq)); + this.setResolution(Math.sqrt(weightedZErrSq)); } - if (this.get_Type()==BMTType.Z) { // Z-detectors + if (this.getType()==BMTType.Z) { // Z-detectors - this.set_Centroid0(weightedStrp0); - this.set_PhiErr(Math.sqrt(weightedPhiErrSq)); - this.set_PhiErr0(Math.sqrt(weightedPhiErrSq0)); - this.set_CentroidValue(weightedPhi); - this.set_CentroidError(Math.sqrt(weightedPhiErrSq)); - this.set_Resolution(this.getTile().baseArc().radius()*Math.sqrt(weightedPhiErrSq)); + this.setCentroid0(weightedStrp0); + this.setPhiErr(Math.sqrt(weightedPhiErrSq)); + this.setPhiErr0(Math.sqrt(weightedPhiErrSq0)); + this.setCentroidValue(weightedPhi); + this.setCentroidError(Math.sqrt(weightedPhiErrSq)); + this.setResolution(this.getTile().baseArc().radius()*Math.sqrt(weightedPhiErrSq)); // for Z detectors Lorentz-correction is applied to the strip this.setLine(new Line3D(weightedX1, weightedY1, weightedZ1, weightedX2, weightedY2, weightedZ2)); @@ -419,162 +419,162 @@ else if (this.get_Detector()==DetectorType.BMT) { //BMT } - public double get_Centroid() { + public double getCentroid() { return _Centroid; } - public void set_Centroid(double _Centroid) { + public void setCentroid(double _Centroid) { this._Centroid = _Centroid; } - public double get_Resolution() { + public double getResolution() { return _Resolution; } - public void set_Resolution(double E) { + public void setResolution(double E) { this._Resolution = E; } - public double get_Centroid0() { + public double getCentroid0() { return _Centroid0; } - public void set_Centroid0(double _Centroid0) { + public void setCentroid0(double _Centroid0) { this._Centroid0 = _Centroid0; } - public double get_Phi() { + public double getPhi() { return _Phi; } - public void set_Phi(double _Phi) { + public void setPhi(double _Phi) { this._Phi = _Phi; } - public double get_Phi0() { + public double getPhi0() { return _Phi0; } - public void set_Phi0(double _Phi0) { + public void setPhi0(double _Phi0) { this._Phi0 = _Phi0; } - public double get_PhiErr() { + public double getPhiErr() { return _PhiErr; } - public void set_PhiErr(double _PhiErr) { + public void setPhiErr(double _PhiErr) { this._PhiErr = _PhiErr; } - public double get_PhiErr0() { + public double getPhiErr0() { return _PhiErr0; } - public void set_PhiErr0(double _PhiErr0) { + public void setPhiErr0(double _PhiErr0) { this._PhiErr0 = _PhiErr0; } - public double get_Z() { + public double getZ() { return _Z; } - public void set_Z(double _Z) { + public void setZ(double _Z) { this._Z = _Z; } - public double get_ZErr() { + public double getZErr() { return _ZErr; } - public void set_ZErr(double _ZErr) { + public void setZErr(double _ZErr) { this._ZErr = _ZErr; } - public void set_CentroidValue(double _CentroidValue) { + public void setCentroidValue(double _CentroidValue) { this._CentroidValue = _CentroidValue; } - public double get_CentroidValue() { + public double getCentroidValue() { return this._CentroidValue; } - public double get_CentroidError() { + public double getCentroidError() { return this._CentroidError; } - public void set_CentroidError(double _CentroidError) { + public void setCentroidError(double _CentroidError) { this._CentroidError = _CentroidError; } /** * @return the _Arc */ - public Arc3D get_Arc() { + public Arc3D getArc() { return _Arc; } /** * @param _Arc the _Arc to set */ - public void set_Arc(Arc3D _Arc) { + public void setArc(Arc3D _Arc) { this._Arc = _Arc; } public Point3D origin() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return this.getLine().origin(); else { - if(this.get_Type()==BMTType.C) - return this.get_Arc().origin(); + if(this.getType()==BMTType.C) + return this.getArc().origin(); else return this.getLine().origin(); } } public Point3D end() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return this.getLine().end(); else { - if(this.get_Type()==BMTType.C) - return this.get_Arc().end(); + if(this.getType()==BMTType.C) + return this.getArc().end(); else return this.getLine().end(); } } public Point3D center() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return this.getLine().midpoint(); else { - if(this.get_Type()==BMTType.C) - return this.get_Arc().point(this.get_Arc().theta()/2); + if(this.getType()==BMTType.C) + return this.getArc().point(this.getArc().theta()/2); else return this.getLine().midpoint(); } } public double theta() { - if(this.get_Detector()==DetectorType.BST) + if(this.getDetector()==DetectorType.BST) return 0; else { - if(this.get_Type()==BMTType.C) - return this.get_Arc().theta(); + if(this.getType()==BMTType.C) + return this.getArc().theta(); else return 0; } } public Transformation3D toLocal() { - return this.get(0).get_Strip().toLocal(); + return this.get(0).getStrip().toLocal(); } public Transformation3D toGlobal() { - return this.get(0).get_Strip().toGlobal(); + return this.get(0).getStrip().toGlobal(); } public double residual(Point3D traj) { double value = 0; - if(this.get_Detector()==DetectorType.BST) { + if(this.getDetector()==DetectorType.BST) { Line3D dist = this.getLine().distance(traj); double side = -Math.signum(this.getLine().direction().cross(dist.direction()).dot(this.getN())); value = dist.length()*side; @@ -582,81 +582,81 @@ public double residual(Point3D traj) { else { Point3D local = new Point3D(traj); this.toLocal().apply(local); - if(this.get_Type()==BMTType.C) - value = local.z()-this.get_CentroidValue(); + if(this.getType()==BMTType.C) + value = local.z()-this.getCentroidValue(); else { - value = local.toVector3D().phi()-this.get_CentroidValue(); + value = local.toVector3D().phi()-this.getCentroidValue(); if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; } } return value; } - public void set_CentroidResidual(Point3D traj) { - this.set_CentroidResidual(this.residual(traj)); + public void setCentroidResidual(Point3D traj) { + this.setCentroidResidual(this.residual(traj)); } - public void set_SeedResidual(Point3D traj) { - this.set_SeedResidual(this.get_Seed().residual(traj)); + public void setSeedResidual(Point3D traj) { + this.setSeedResidual(this.getSeed().residual(traj)); } - public double get_TotalEnergy() { + public double getTotalEnergy() { return _TotalEnergy; } - public void set_TotalEnergy(double _TotalEnergy) { + public void setTotalEnergy(double _TotalEnergy) { this._TotalEnergy = _TotalEnergy; } - public double get_Time() { + public double getTime() { return _Time; } - public void set_Time(double _Time) { + public void setTime(double _Time) { this._Time = _Time; } - public int get_MinStrip() { + public int getMinStrip() { return _MinStrip; } - public void set_MinStrip(int _MinStrip) { + public void setMinStrip(int _MinStrip) { this._MinStrip = _MinStrip; } - public int get_MaxStrip() { + public int getMaxStrip() { return _MaxStrip; } - public void set_MaxStrip(int _MaxStrip) { + public void setMaxStrip(int _MaxStrip) { this._MaxStrip = _MaxStrip; } - public Strip get_SeedStrip() { - return _Seed.get_Strip(); + public Strip getSeedStrip() { + return _Seed.getStrip(); } - public Hit get_Seed() { + public Hit getSeed() { return _Seed; } - public void set_Seed(Hit _Seed) { + public void setSeed(Hit _Seed) { this._Seed = _Seed; } - public double get_SeedResidual() { + public double getSeedResidual() { return _SeedResidual; } - public void set_SeedResidual(double _SeedResidual) { + public void setSeedResidual(double _SeedResidual) { this._SeedResidual = _SeedResidual; } - public double get_CentroidResidual() { + public double getCentroidResidual() { return _CentroidResidual; } - public void set_CentroidResidual(double _CentroidResidual) { + public void setCentroidResidual(double _CentroidResidual) { this._CentroidResidual = _CentroidResidual; } @@ -677,30 +677,30 @@ public void setTrakInters(Point3D _TrakInters) { public Surface measurement() { Surface surface = null; - if(this.get_Detector()==DetectorType.BST) { + if(this.getDetector()==DetectorType.BST) { Point3D endPt1 = this.getLine().origin(); Point3D endPt2 = this.getLine().end(); -// org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.get_Id(), this.get_Centroid(), +// org.jlab.clas.tracking.objects.Strip strp = new org.jlab.clas.tracking.objects.Strip(this.getId(), this.getCentroid(), // endPt1.x(), endPt1.y(), endPt1.z(), // endPt2.x(), endPt2.y(), endPt2.z()); Plane3D plane = new Plane3D(endPt1, this.getN()); - surface = Constants.SVTGEOMETRY.getSurface(this.get_Layer(), this.get_Sector(), this.get_Id(), - this.get_Centroid(), this.getLine()); + surface = Constants.SVTGEOMETRY.getSurface(this.getLayer(), this.getSector(), this.getId(), + this.getCentroid(), this.getLine()); surface.hemisphere = Math.signum(this.center().y()); - surface.setError(this.get_Resolution()); + surface.setError(this.getResolution()); } else { - if(this.get_Type()==BMTType.C) { - surface = Constants.BMTGEOMETRY.getSurfaceC(this.get_Layer(), this.get_Sector(), this.get_Id(), - this.get_Centroid(), this.get_CentroidValue()); + if(this.getType()==BMTType.C) { + surface = Constants.BMTGEOMETRY.getSurfaceC(this.getLayer(), this.getSector(), this.getId(), + this.getCentroid(), this.getCentroidValue()); } else { Point3D point = new Point3D(this.getLine().midpoint()); this.toLocal().apply(point); - surface = Constants.BMTGEOMETRY.getSurfaceZ(this.get_Layer(), this.get_Sector(), this.get_Id(), - this.get_Centroid(), point.x(), point.y(), this.get_CentroidValue()); + surface = Constants.BMTGEOMETRY.getSurfaceZ(this.getLayer(), this.getSector(), this.getId(), + this.getCentroid(), point.x(), point.y(), this.getCentroidValue()); } - surface.setError(this.get_CentroidError()); + surface.setError(this.getCentroidError()); } return surface; } @@ -709,8 +709,8 @@ public Surface measurement() { * */ public void printInfo() { - String s = " cluster: Detector " + this.get_Detector().getName() +" Detector Type " + this.get_Type().getName() + " ID " + this.get_Id() + " Sector " + this.get_Sector() - + " Layer " + this.get_Layer() + " tID " + this.get_AssociatedTrackID()+ " Size " + this.size() +" centroid "+this.get_Centroid() + this.size() +" centroidValue "+this.get_CentroidValue(); + String s = " cluster: Detector " + this.getDetector().getName() +" Detector Type " + this.getType().getName() + " ID " + this.getId() + " Sector " + this.getSector() + + " Layer " + this.getLayer() + " tID " + this.getAssociatedTrackID()+ " Size " + this.size() +" centroid "+this.getCentroid() + this.size() +" centroidValue "+this.getCentroidValue(); System.out.println(s); } @@ -722,7 +722,7 @@ public void printInfo() { * SVT * */ - public double get_ResolutionAlongZ(double Z) { + public double getResolutionAlongZ(double Z) { // returns the total resolution for a group of strips in a cluster // the single strip resolution varies at each point along the strip as a function of Z (due to the graded angle of the strips) and @@ -736,17 +736,17 @@ public double get_ResolutionAlongZ(double Z) { double res = 0; for (int i = 0; i < nbhits; i++) { - double rstrp = Constants.SVTGEOMETRY.getSingleStripResolution(this.get(i).get_Layer(), this.get(i).get_Strip().get_Strip(), Z); + double rstrp = Constants.SVTGEOMETRY.getSingleStripResolution(this.get(i).getLayer(), this.get(i).getStrip().getStrip(), Z); res += rstrp * rstrp; } return Math.sqrt(res); } - public int get_AssociatedTrackID() { + public int getAssociatedTrackID() { return AssociatedTrackID; } - public void set_AssociatedTrackID(int associatedTrackID) { + public void setAssociatedTrackID(int associatedTrackID) { AssociatedTrackID = associatedTrackID; } @@ -754,12 +754,12 @@ public void set_AssociatedTrackID(int associatedTrackID) { public int compareTo(Cluster arg) { //sort by phi of strip implant of first strip in the cluster, then by layer, then by seed strip number - double this_phi = this.get_Phi0(); - double arg_phi = arg.get_Phi0(); + double this_phi = this.getPhi0(); + double arg_phi = arg.getPhi0(); int CompPhi = this_phi < arg_phi ? -1 : this_phi == arg_phi ? 0 : 1; int CompLay = this._Layer < arg._Layer ? -1 : this._Layer == arg._Layer ? 0 : 1; - int CompId = this.get_SeedStrip().get_Strip()< arg.get_SeedStrip().get_Strip() ? -1 : this.get_SeedStrip().get_Strip() == arg.get_SeedStrip().get_Strip() ? 0 : 1; + int CompId = this.getSeedStrip().getStrip()< arg.getSeedStrip().getStrip() ? -1 : this.getSeedStrip().getStrip() == arg.getSeedStrip().getStrip() ? 0 : 1; int return_val1 = ((CompLay == 0) ? CompId : CompLay); int return_val = ((CompPhi == 0) ? return_val1 : CompPhi); @@ -831,39 +831,39 @@ public void update(int trackId, HitOnTrack traj) { Point3D trackPos = new Point3D(traj.x, traj.y, traj.z); Vector3D trackDir = new Vector3D(traj.px, traj.py, traj.pz).asUnit(); - this.set_AssociatedTrackID(trackId); - this.set_CentroidResidual(traj.resi); - this.set_SeedResidual(trackPos); + this.setAssociatedTrackID(trackId); + this.setCentroidResidual(traj.resi); + this.setSeedResidual(trackPos); this.setTrakInters(trackPos); - if(this.get_Detector()==DetectorType.BMT && this.get_Type()==BMTType.C) { + if(this.getDetector()==DetectorType.BMT && this.getType()==BMTType.C) { this.setS(this.getAxis().direction().asUnit()); this.setN(this.getAxis().distance(trackPos).direction().asUnit()); this.setL(this.getS().cross(this.getN()).asUnit()); } - if(this.get_Detector()==DetectorType.BMT && this.get_Type()==BMTType.Z) { - this.set_CentroidResidual(traj.resi*this.getTile().baseArc().radius()); + if(this.getDetector()==DetectorType.BMT && this.getType()==BMTType.Z) { + this.setCentroidResidual(traj.resi*this.getTile().baseArc().radius()); } for (Hit hit : this) { - hit.set_AssociatedTrackID(trackId); + hit.setAssociatedTrackID(trackId); double doca1 = hit.residual(trackPos); - hit.set_docaToTrk(doca1); - if(this.get_Detector()==DetectorType.BST) { - Point3D local = Constants.SVTGEOMETRY.toLocal(this.get_Layer(), this.get_Sector(), trackPos); - double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(this.get_Layer(), hit.get_Strip().get_Strip(), local.z()); - hit.set_stripResolutionAtDoca(sigma1); + hit.setdocaToTrk(doca1); + if(this.getDetector()==DetectorType.BST) { + Point3D local = Constants.SVTGEOMETRY.toLocal(this.getLayer(), this.getSector(), trackPos); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(this.getLayer(), hit.getStrip().getStrip(), local.z()); + hit.setstripResolutionAtDoca(sigma1); } - if(traj.isMeasUsed) hit.set_TrkgStatus(1); + if(traj.isMeasUsed) hit.setTrkgStatus(1); } } @Override public String toString() { - String s = "Cluster Id" + this.get_Id() + " " + this.get_Detector() + " " +this.get_Type(); - s += " layer " + this.get_Layer() + " sector " + this.get_Sector() + " centroid " + this.get_Centroid() + " phi " + this.get_Phi(); + String s = "Cluster Id" + this.getId() + " " + this.getDetector() + " " +this.getType(); + s += " layer " + this.getLayer() + " sector " + this.getSector() + " centroid " + this.getCentroid() + " phi " + this.getPhi(); return s; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java index 65296ecc6..7d46a1894 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cluster/ClusterFinder.java @@ -33,17 +33,17 @@ public ArrayList findClusters(List hits2) // the number of strips // with valid hits for (Hit hit : hits2) { - if (hit.get_Strip().get_Strip() == -1) { + if (hit.getStrip().getStrip() == -1) { continue; } - if (hit.get_Strip().getStatus()!=0) { + if (hit.getStrip().getStatus()!=0) { continue; } - int w = hit.get_Strip().get_Strip(); - int l = hit.get_Layer(); - int s = hit.get_Sector(); + int w = hit.getStrip().getStrip(); + int l = hit.getLayer(); + int s = hit.getSector(); if (w > 0 && w < nstrip) { HitArray[w - 1][l - 1][s - 1] = hit; @@ -76,20 +76,20 @@ public ArrayList findClusters(List hits2) // the number of strips } // define new cluster - Cluster this_cluster = new Cluster(hits.get(0).get_Detector(), hits.get(0).get_Type(), hits.get(0).get_Sector(), l + 1, cid++); - this_cluster.set_Id(clusters.size() + 1); + Cluster this_cluster = new Cluster(hits.get(0).getDetector(), hits.get(0).getType(), hits.get(0).getSector(), l + 1, cid++); + this_cluster.setId(clusters.size() + 1); // add hits to the cluster this_cluster.addAll(hits); if(hits.size()>2) { for(int hi = 1; hiMath.PI) t-=Math.signum(t)*2*Math.PI; if(t<0) cross = cluster.origin(); - else if(t>cluster.get_Arc().theta()) + else if(t>cluster.getArc().theta()) cross = cluster.end(); else { - cross = cluster.get_Arc().point(t); + cross = cluster.getArc().point(t); } } else { @@ -423,25 +421,26 @@ else if(t>cluster.get_Arc().theta()) private Vector3D getBMTCrossError(Point3D trackPos) { - Cluster cluster = this.get_Cluster1(); + Cluster cluster = this.getCluster1(); Point3D cross = this.getBMTCrossPoint(trackPos); Point3D local = new Point3D(cross); - cluster.get_SeedStrip().toLocal().apply(local); + cluster.getSeedStrip().toLocal().apply(local); Vector3D error = new Vector3D(cluster.getS()); - error.scale(cluster.get_Resolution()); + error.scale(cluster.getResolution()); error.setXYZ(Math.abs(error.x()), Math.abs(error.y()), Math.abs(error.z())); return error; } /** * Sets the cross parameters: the position and direction unit vector + * @param trackDir */ public void updateSVTCross(Vector3D trackDir) { - Cluster inlayerclus = this.get_Cluster1(); - Cluster outlayerclus = this.get_Cluster2(); + Cluster inlayerclus = this.getCluster1(); + Cluster outlayerclus = this.getCluster2(); if (inlayerclus == null || outlayerclus == null) { return; } @@ -454,13 +453,13 @@ public void updateSVTCross(Vector3D trackDir) { } if (trackDir == null) { - this.set_Point0(crossPoint); - this.set_PointErr0(crossError.toPoint3D()); + this.setPoint0(crossPoint); + this.setPointErr0(crossError.toPoint3D()); } - this.set_Point(crossPoint); - this.set_Dir(trackDir); - this.set_PointErr(crossError.toPoint3D()); + this.setPoint(crossPoint); + this.setDir(trackDir); + this.setPointErr(crossError.toPoint3D()); } @@ -471,10 +470,10 @@ public void updateSVTCross(Vector3D trackDir) { */ public Point3D getSVTCrossPoint(Vector3D trackDir) { - int layer = this.get_Cluster1().get_Layer(); - int sector = this.get_Cluster1().get_Sector(); + int layer = this.getCluster1().getLayer(); + int sector = this.getCluster1().getSector(); - Point3D cross = Constants.SVTGEOMETRY.getCross(sector, layer, this.get_Cluster1().getLine(), this.get_Cluster2().getLine(), trackDir); + Point3D cross = Constants.SVTGEOMETRY.getCross(sector, layer, this.getCluster1().getLine(), this.getCluster2().getLine(), trackDir); return cross; } @@ -487,15 +486,15 @@ public Point3D getSVTCrossPoint(Vector3D trackDir) { public Vector3D getSVTCrossError(Vector3D trackDir) { Vector3D error = null; - int layer = this.get_Cluster1().get_Layer(); - int sector = this.get_Cluster1().get_Sector(); + int layer = this.getCluster1().getLayer(); + int sector = this.getCluster1().getSector(); Point3D cross = this.getSVTCrossPoint(trackDir); if(cross!=null) { // get the strip resolution Point3D local = Constants.SVTGEOMETRY.toLocal(layer, sector, cross); - double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.get_Cluster1().get_SeedStrip().get_Strip(), local.z()); - double sigma2 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.get_Cluster2().get_SeedStrip().get_Strip(), local.z()); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.getCluster1().getSeedStrip().getStrip(), local.z()); + double sigma2 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, this.getCluster2().getSeedStrip().getStrip(), local.z()); // get the error associated to each strip Vector3D error1 = this.getSVTCrossDerivative(1, trackDir).multiply(sigma1); @@ -524,17 +523,17 @@ public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir) { Point3D cross = this.getSVTCrossPoint(trackDir); if(cross==null) return null; - int layer = this.get_Cluster1().get_Layer(); - int sector = this.get_Cluster1().get_Sector(); + int layer = this.getCluster1().getLayer(); + int sector = this.getCluster1().getSector(); double delta = 1e-3; // 1micron shift // get the clusters - Cluster clusA = this.get_Cluster1(); - Cluster clusB = this.get_Cluster2(); + Cluster clusA = this.getCluster1(); + Cluster clusB = this.getCluster2(); if(icluster==2) { - clusA = this.get_Cluster2(); - clusB = this.get_Cluster1(); + clusA = this.getCluster2(); + clusB = this.getCluster1(); } // shift the selected cluster to the left and right of the line @@ -547,7 +546,7 @@ public Vector3D getSVTCrossDerivative(int icluster, Vector3D trackDir) { // calculate the shifted cross positions Point3D crossAPlus = null; Point3D crossAMinus = null; - if(clusA.get_Layer()%2 == 1) { + if(clusA.getLayer()%2 == 1) { crossAPlus = Constants.SVTGEOMETRY.getCross(sector, layer, stripAPlus, clusB.getLine(), trackDir); crossAMinus = Constants.SVTGEOMETRY.getCross(sector, layer, stripAMinus, clusB.getLine(), trackDir); } @@ -584,22 +583,22 @@ public String toString() { } public String printInfo() { - String s = " cross: " + this.get_Detector() + " ID " + this.get_Id() + " Sector " + this.get_Sector() + " Region " + this.get_Region() - + " Point " + this.get_Point().toString()+ " Point0 " + this.get_Point0().toString() - + " sort "+this.getOrderedRegion()+" cosmic region "+this.get_SVTCosmicsRegion(); + String s = " cross: " + this.getDetector() + " ID " + this.getId() + " Sector " + this.getSector() + " Region " + this.getRegion() + + " Point " + this.getPoint().toString()+ " Point0 " + this.getPoint0().toString() + + " sort "+this.getOrderedRegion()+" cosmic region "+this.getSVTCosmicsRegion(); return s; } - public int get_SVTCosmicsRegion() { + public int getSVTCosmicsRegion() { int theRegion = 0; - if (this.get_Detector()==DetectorType.BST) { - if(this.get_Point0().y()<0) - theRegion = this.get_Region(); + if (this.getDetector()==DetectorType.BST) { + if(this.getPoint0().y()<0) + theRegion = this.getRegion(); else - theRegion = SVTGeometry.NREGIONS*2+1-this.get_Region(); + theRegion = SVTGeometry.NREGIONS*2+1-this.getRegion(); } return theRegion; @@ -607,33 +606,34 @@ public int get_SVTCosmicsRegion() { /** * Sorts crosses + * @param arg */ @Override public int compareTo(Cross arg) { int return_val = 0; - if(Constants.isCosmicsData) { - int RegComp = this.get_SVTCosmicsRegion() < arg.get_SVTCosmicsRegion() ? -1 : this.get_SVTCosmicsRegion() == arg.get_SVTCosmicsRegion() ? 0 : 1; - int IDComp = this.get_Id() < arg.get_Id() ? -1 : this.get_Id() == arg.get_Id() ? 0 : 1; + if(Constants.ISCOSMICDATA) { + int RegComp = this.getSVTCosmicsRegion() < arg.getSVTCosmicsRegion() ? -1 : this.getSVTCosmicsRegion() == arg.getSVTCosmicsRegion() ? 0 : 1; + int IDComp = this.getId() < arg.getId() ? -1 : this.getId() == arg.getId() ? 0 : 1; return_val = ((RegComp == 0) ? IDComp : RegComp); } else { - //int thisreg = (this.get_Detector().equalsIgnoreCase("BMT")) ? 3 + bgeom.getLayer( this.get_Region(), this.get_DetectorType()) : this.get_Region(); - //int argreg = (arg.get_Detector().equalsIgnoreCase("BMT")) ? 3 + bgeom.getLayer( arg.get_Region(), arg.get_DetectorType()) : arg.get_Region(); + //int thisreg = (this.getDetector().equalsIgnoreCase("BMT")) ? 3 + bgeom.getLayer( this.getRegion(), this.getDetectorType()) : this.getRegion(); + //int argreg = (arg.getDetector().equalsIgnoreCase("BMT")) ? 3 + bgeom.getLayer( arg.getRegion(), arg.getDetectorType()) : arg.getRegion(); int thisreg = this.getOrderedRegion(); int argreg = arg.getOrderedRegion(); int RegComp = thisreg < argreg ? -1 : thisreg == argreg ? 0 : 1; -// int RegComp = this.get_Region() < arg.get_Region() ? -1 : this.get_Region() == arg.get_Region() ? 0 : 1; +// int RegComp = this.getRegion() < arg.getRegion() ? -1 : this.getRegion() == arg.getRegion() ? 0 : 1; // check that is not BMTC for phi comparison - if( Double.isNaN(arg.get_Point().x())==false && Double.isNaN(this.get_Point().x())==false ) { - int PhiComp = this.get_Point0().toVector3D().phi() < arg.get_Point0().toVector3D().phi() ? -1 : this.get_Point0().toVector3D().phi() == arg.get_Point0().toVector3D().phi() ? 0 : 1; + if( Double.isNaN(arg.getPoint().x())==false && Double.isNaN(this.getPoint().x())==false ) { + int PhiComp = this.getPoint0().toVector3D().phi() < arg.getPoint0().toVector3D().phi() ? -1 : this.getPoint0().toVector3D().phi() == arg.getPoint0().toVector3D().phi() ? 0 : 1; return_val = ((RegComp == 0) ? PhiComp : RegComp); } else { - int ZComp = this.get_Point0().z() < arg.get_Point0().z() ? -1 : this.get_Point0().z() == arg.get_Point0().z() ? 0 : 1; + int ZComp = this.getPoint0().z() < arg.getPoint0().z() ? -1 : this.getPoint0().z() == arg.getPoint0().z() ? 0 : 1; return_val = ((RegComp == 0) ? ZComp : RegComp); } } @@ -643,11 +643,11 @@ public int compareTo(Cross arg) { private int AssociatedTrackID = -1; // the track ID associated with that hit - public int get_AssociatedTrackID() { + public int getAssociatedTrackID() { return AssociatedTrackID; } - public void set_AssociatedTrackID(int associatedTrackID) { + public void setAssociatedTrackID(int associatedTrackID) { AssociatedTrackID = associatedTrackID; } @@ -655,45 +655,45 @@ public void set_AssociatedTrackID(int associatedTrackID) { * @return the Cross Radius */ public double getRadius() { - return Math.sqrt(this.get_Point().x()*this.get_Point().x()+this.get_Point().y()*this.get_Point().y()); + return Math.sqrt(this.getPoint().x()*this.getPoint().x()+this.getPoint().y()*this.getPoint().y()); } public static void main(String arg[]) { // Geometry geo = new Geometry(); - ArrayList testList = new ArrayList(); + ArrayList testList = new ArrayList<>(); for (int i = 0; i < 5; i++) { Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 1, 1 + i); - c1.set_Point0(new Point3D(-1.2 - i, 66.87, 0)); + c1.setPoint0(new Point3D(-1.2 - i, 66.87, 0)); testList.add(c1); } for (int i = 0; i < 5; i++) { Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 3, 1 + i); - c1.set_Point0(new Point3D(-1.2 + i, 123, 0)); + c1.setPoint0(new Point3D(-1.2 + i, 123, 0)); testList.add(c1); } for (int i = 0; i < 5; i++) { Cross c1 = new Cross(DetectorType.BST, BMTType.UNDEFINED, 1, 2, 1 + i); - c1.set_Point0(new Point3D(-1.2 - i, 95, 0)); + c1.setPoint0(new Point3D(-1.2 - i, 95, 0)); testList.add(c1); } Collections.sort(testList); - ArrayList> theListsByRegion = new ArrayList>(); + ArrayList> theListsByRegion = new ArrayList<>(); - ArrayList theRegionList = new ArrayList(); + ArrayList theRegionList = new ArrayList<>(); if (testList.size() > 0) { theRegionList.add(testList.get(0)); // init } for (int i = 1; i < testList.size(); i++) { Cross c = testList.get(i); - if (testList.get(i - 1).get_Region() != c.get_Region()) { + if (testList.get(i - 1).getRegion() != c.getRegion()) { theListsByRegion.add(theRegionList); // end previous list by region - theRegionList = new ArrayList(); // new region list + theRegionList = new ArrayList<>(); // new region list } theRegionList.add(c); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossList.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossList.java index b425786a2..cb50e4ddb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossList.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossList.java @@ -39,7 +39,7 @@ public boolean Contains(ArrayList arrayList, for (int j = 0; j < array2size; j++) { Cross c2 = arrayList2.get(j); - if ((c1.get_Detector()).equals(c2.get_Detector()) && c1.get_Id() == c2.get_Id()) { + if ((c1.getDetector()).equals(c2.getDetector()) && c1.getId() == c2.getId()) { arrayList2.remove(j); if (array2size > 0) { @@ -49,11 +49,7 @@ public boolean Contains(ArrayList arrayList, } } - if (array2size == 0) { - return true; - } else { - return false; - } + return array2size == 0; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java index a231f5165..82b458894 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/CrossMaker.java @@ -31,7 +31,7 @@ public CrossMaker() { */ public ArrayList> findCrosses(List clusters) { // instantiate array of clusters that are sorted by detector (SVT, BMT [C, Z]) and inner/outer layers - ArrayList> sortedClusters = new ArrayList>(); + ArrayList> sortedClusters = new ArrayList<>(); // fill the sorted list sortedClusters = this.sortClusterByDetectorAndIO(clusters); // array indexes: array index 0 (1) = svt inner (outer) layer clusters, 2 (3) = bmt inner (outer) layers @@ -39,13 +39,13 @@ public ArrayList> findCrosses(List clusters) { ArrayList svt_outerlayrclus = sortedClusters.get(1); ArrayList bmt_Clayrclus = sortedClusters.get(2); ArrayList bmt_Zlayrclus = sortedClusters.get(3); - ArrayList rbmt_Clayrclus = new ArrayList(); - ArrayList rbmt_Zlayrclus = new ArrayList(); + ArrayList rbmt_Clayrclus = new ArrayList<>(); + ArrayList rbmt_Zlayrclus = new ArrayList<>(); for(Cluster cl : bmt_Zlayrclus) { - if(cl.get_Layer()==Constants.getBMTLayerExcld() - && cl.get_Phi0()>Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][0]) - && cl.get_Phi0()<=Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][1]) ) { + if(cl.getLayer()==Constants.getBMTLayerExcld() + && cl.getPhi0()>Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][0]) + && cl.getPhi0()<=Math.toRadians(Constants.getBMTPhiZRangeExcld()[0][1]) ) { cl.flagForExclusion = true; rbmt_Zlayrclus.add(cl); } @@ -54,9 +54,9 @@ public ArrayList> findCrosses(List clusters) { bmt_Zlayrclus.removeAll(rbmt_Zlayrclus); } for(Cluster cl : bmt_Clayrclus) { - if(cl.get_Layer()==Constants.getBMTLayerExcld() - && cl.get_Z()>Constants.getBMTPhiZRangeExcld()[1][0] - && cl.get_Z()<=Constants.getBMTPhiZRangeExcld()[1][1]) { + if(cl.getLayer()==Constants.getBMTLayerExcld() + && cl.getZ()>Constants.getBMTPhiZRangeExcld()[1][0] + && cl.getZ()<=Constants.getBMTPhiZRangeExcld()[1][1]) { cl.flagForExclusion = true; rbmt_Clayrclus.add(cl); } @@ -88,47 +88,47 @@ public ArrayList findSVTCrosses( List svt_innerlayrclus, List svt_outerlayrclus) { // instantiate the list of crosses - ArrayList crosses = new ArrayList(); + ArrayList crosses = new ArrayList<>(); int rid = 0; // cross id //loop over the clusters // inner clusters for (Cluster inlayerclus : svt_innerlayrclus) { - if(inlayerclus.get_TotalEnergy() SVTParameters.sumStpNumMin) - && (inlayerclus.get_MaxStrip() + outlayerclus.get_MaxStrip() < SVTParameters.sumStpNumMax)) { // the intersection is valid + if ((inlayerclus.getMinStrip() + outlayerclus.getMinStrip() > SVTParameters.MINSTRIPSUM) + && (inlayerclus.getMaxStrip() + outlayerclus.getMaxStrip() < SVTParameters.MAXSTRIPSUM)) { // the intersection is valid // define new cross - Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, inlayerclus.get_Sector(), inlayerclus.get_Region(), rid++); + Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, inlayerclus.getSector(), inlayerclus.getRegion(), rid++); // cluster1 is the inner layer cluster - this_cross.set_Cluster1(inlayerclus); + this_cross.setCluster1(inlayerclus); // cluster2 is the outer layer cluster - this_cross.set_Cluster2(outlayerclus); - this_cross.set_Id(rid); + this_cross.setCluster2(outlayerclus); + this_cross.setId(rid); // sets the cross parameters (point3D and associated error) from the SVT geometry this_cross.updateSVTCross(null); // the uncorrected point obtained from default estimate that the track is at 90 deg wrt the module should not be null - if (this_cross.get_Point0() != null) { + if (this_cross.getPoint0() != null) { //pass the cross to the arraylist of crosses - this_cross.set_Id(crosses.size() + 1); - this_cross.set_Detector(DetectorType.BST); - calcCentErr(this_cross, this_cross.get_Cluster1()); - calcCentErr(this_cross, this_cross.get_Cluster2()); + this_cross.setId(crosses.size() + 1); + this_cross.setDetector(DetectorType.BST); + calcCentErr(this_cross, this_cross.getCluster1()); + calcCentErr(this_cross, this_cross.getCluster2()); crosses.add(this_cross); } @@ -136,20 +136,20 @@ public ArrayList findSVTCrosses( } } for (Cross c : crosses) { - int rg = c.get_Region(); + int rg = c.getRegion(); c.setOrderedRegion(rg); } return crosses; } private void calcCentErr(Cross c, Cluster Cluster1) { - double Z = Constants.SVTGEOMETRY.toLocal(Cluster1.get_Layer(), - Cluster1.get_Sector(), - c.get_Point()).z(); + double Z = Constants.SVTGEOMETRY.toLocal(Cluster1.getLayer(), + Cluster1.getSector(), + c.getPoint()).z(); if(Z>SVTGeometry.getModuleLength()) Z=SVTGeometry.getModuleLength(); else if(Z<0) Z=0; - Cluster1.set_CentroidError(Cluster1.get_ResolutionAlongZ(Z) /(SVTGeometry.getPitch() / Math.sqrt(12.))); - Cluster1.set_Resolution(Cluster1.get_ResolutionAlongZ(Z) ); + Cluster1.setCentroidError(Cluster1.getResolutionAlongZ(Z) /(SVTGeometry.getPitch() / Math.sqrt(12.))); + Cluster1.setResolution(Cluster1.getResolutionAlongZ(Z) ); } /** * @@ -163,21 +163,21 @@ public ArrayList findBMTCrosses( ArrayList Zlayrclus, int idx) { //instanciates the list of crosses - ArrayList crosses = new ArrayList(); + ArrayList crosses = new ArrayList<>(); // For BMT start id at last id from existing list int pid = idx; for (Cluster Zlayerclus : Zlayrclus) { - if (Zlayerclus.get_TotalEnergy() < BMTConstants.ETOTCUT) { + if (Zlayerclus.getTotalEnergy() < BMTConstants.ETOTCUT) { continue; } // Z detector --> meas phi // define new cross - Cross this_cross = new Cross(DetectorType.BMT, BMTType.Z, Zlayerclus.get_Sector(), Zlayerclus.get_Region(), pid++); - this_cross.set_Id(pid); - this_cross.set_Cluster1(Zlayerclus); + Cross this_cross = new Cross(DetectorType.BMT, BMTType.Z, Zlayerclus.getSector(), Zlayerclus.getRegion(), pid++); + this_cross.setId(pid); + this_cross.setCluster1(Zlayerclus); this_cross.updateBMTCross(null, null); - if (this_cross.get_Point0() != null) { + if (this_cross.getPoint0() != null) { //make arraylist crosses.add(this_cross); } @@ -185,16 +185,16 @@ public ArrayList findBMTCrosses( } for (Cluster Clayerclus : Clayrclus) { - if (Clayerclus.get_TotalEnergy() < BMTConstants.ETOTCUT) { + if (Clayerclus.getTotalEnergy() < BMTConstants.ETOTCUT) { continue; } // C detector --> meas z // define new cross - Cross this_cross = new Cross(DetectorType.BMT, BMTType.C, Clayerclus.get_Sector(), Clayerclus.get_Region(), pid++); - this_cross.set_Id(pid); - this_cross.set_Cluster1(Clayerclus); + Cross this_cross = new Cross(DetectorType.BMT, BMTType.C, Clayerclus.getSector(), Clayerclus.getRegion(), pid++); + this_cross.setId(pid); + this_cross.setCluster1(Clayerclus); this_cross.updateBMTCross(null, null); - if (this_cross.get_Point0() != null) { + if (this_cross.getPoint0() != null) { //make arraylist crosses.add(this_cross); } @@ -202,7 +202,7 @@ public ArrayList findBMTCrosses( for (Cross c : crosses) { int rg = 3 + - Constants.BMTGEOMETRY.getLayer( c.get_Region(), c.get_Type()) ; + Constants.BMTGEOMETRY.getLayer( c.getRegion(), c.getType()) ; c.setOrderedRegion(rg); } return crosses; @@ -218,33 +218,33 @@ public ArrayList findBMTCrosses( public ArrayList> sortClusterByDetectorAndIO( List clusters) { - ArrayList> sortedClusters = new ArrayList>(); + ArrayList> sortedClusters = new ArrayList<>(); // svt - ArrayList svt_innerlayrclus = new ArrayList(); - ArrayList svt_outerlayrclus = new ArrayList(); + ArrayList svt_innerlayrclus = new ArrayList<>(); + ArrayList svt_outerlayrclus = new ArrayList<>(); // bmt - ArrayList bmt_Clayrclus = new ArrayList(); - ArrayList bmt_Zlayrclus = new ArrayList(); + ArrayList bmt_Clayrclus = new ArrayList<>(); + ArrayList bmt_Zlayrclus = new ArrayList<>(); // Sorting by layer first: for (Cluster theclus : clusters) { - if (theclus.get_Detector() == DetectorType.BMT) { - if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.Z) { + if (theclus.getDetector() == DetectorType.BMT) { + if (BMTGeometry.getDetectorType(theclus.getLayer()) == BMTType.Z) { bmt_Zlayrclus.add(theclus); } - if (BMTGeometry.getDetectorType(theclus.get_Layer()) == BMTType.C) { + if (BMTGeometry.getDetectorType(theclus.getLayer()) == BMTType.C) { bmt_Clayrclus.add(theclus); } } - if (theclus.get_Detector() == DetectorType.BST) { - if (theclus.get_Layer() % 2 == 0) { + if (theclus.getDetector() == DetectorType.BST) { + if (theclus.getLayer() % 2 == 0) { svt_outerlayrclus.add(theclus); } - if (theclus.get_Layer() % 2 == 1) { + if (theclus.getLayer() % 2 == 1) { svt_innerlayrclus.add(theclus); } @@ -259,50 +259,4 @@ public ArrayList> sortClusterByDetectorAndIO( return sortedClusters; } - - /** - * not used - * @param crosses the crosses in the list - * @return the crosses that have been flagged as being part of a looper - * candidate in the SVT - */ - public List crossLooperCands(List> crosses) { - // nb SVT layers - int nlayr = SVTGeometry.NLAYERS; - // list of crosses in a sector - ArrayList>> secList = new ArrayList>>(); - - //initialize - for (int i = 0; i < nlayr; i++) { - secList.add(i, new ArrayList>()); - for (int j = 0; j < SVTGeometry.NSECTORS[i]; j++) { - secList.get(i).add(j, new ArrayList()); - } - } - - // loop over the crosses in the SVT and use a simple counting algorithm for the number of crosses in a given sector - // a looper will have a pattern of multiple hits in the same sector - for (Cross c : crosses.get(0)) { // svt crosses - - int l = c.get_Region() * 2; - int s = c.get_Sector(); - - secList.get(l - 1).get(s - 1).add(c); - } - ArrayList listOfCrossesToRm = new ArrayList(); - - for (int i = 0; i < nlayr; i++) { - for (int j = 0; j < SVTGeometry.NSECTORS[i]; j++) { - //System.out.println(" number of crosses in sector "+(j+1)+" = "+secList.get(i).get(j).size()); - if (secList.get(i).get(j).size() > SVTParameters.MAXNUMCROSSESINMODULE) { - listOfCrossesToRm.addAll(secList.get(i).get(j)); - } - } - - } - //System.out.println(" number of crosses to remove "+listOfCrossesToRm.size()); - return listOfCrossesToRm; - - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java index b0701d650..1aef01d21 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/HelixCrossListFinder.java @@ -6,9 +6,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Point3D; -import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.track.Seed; @@ -49,7 +47,10 @@ public HelixCrossListFinder() { /** * - * @param crosses the list of crosses in the event + * @param cvt_crosses + * @param xb + * @param yb + * @param swimmer * @return the list of crosses determined to be consistent with belonging to * a track in the cvt */ @@ -61,22 +62,22 @@ public List findCandidateCrossLists(List seedList = new ArrayList(); // require crosses to be found in the svt - if (cvt_crosses.size() == 0) { + if (cvt_crosses.isEmpty()) { return null; } List seedList = new ArrayList<>(); //create arrays of crosses for each region - ArrayList> theListsByRegion = new ArrayList>(); - ArrayList> theListsByRegionBMTC = new ArrayList>(); + ArrayList> theListsByRegion = new ArrayList<>(); + ArrayList> theListsByRegionBMTC = new ArrayList<>(); ///// for(int r = 0; r<6; r++) { - theListsByRegion.add(new ArrayList()); + theListsByRegion.add(new ArrayList<>()); if(r<3) - theListsByRegionBMTC.add(new ArrayList()); + theListsByRegionBMTC.add(new ArrayList<>()); } - ArrayList allCrossList = new ArrayList(); + ArrayList allCrossList = new ArrayList<>(); if (cvt_crosses.size() > 0) { // sort the crosses by region and phi if(cvt_crosses.get(0).size() > 0 ) { @@ -90,23 +91,23 @@ public List findCandidateCrossLists(List CirTrks = new ArrayList(); + List CirTrks = new ArrayList<>(); for (int i2 = 0; i2 < theListsByRegion.get(1).size(); i2++) { for (int i3 = 0; i3 < theListsByRegion.get(2).size(); i3++) { for (int i4 = 0; i4 < theListsByRegion.get(3).size(); i4++) { @@ -127,7 +128,6 @@ public List findCandidateCrossLists(List findCandidateCrossLists(List findCandidateCrossLists(List findCandidateCrossLists(List clusters = new ArrayList(); -// for(Cross c : s ) { -// if(c.get_Detector()==DetectorType.BST) { -// c.get_Cluster1().set_CentroidError(this.calcCentErr(c, c.get_Cluster1(), svt_geo)); -// c.get_Cluster2().set_CentroidError(this.calcCentErr(c, c.get_Cluster2(), svt_geo)); -// -// clusters.add(c.get_Cluster1()); -// clusters.add(c.get_Cluster2()); -// } -// if(c.get_Detector()==DetectorType.BMT) { -// clusters.add(c.get_Cluster1()); -// -// } -// } -// -// trkSeed.set_Clusters(clusters); + seedList.add(s); } @@ -234,20 +214,20 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { return false; double avg_tandip =0; int countCrosses =0; - for(Cross c : trkCand.get_Crosses()) { - if(c.get_Detector()==DetectorType.BST) { + for(Cross c : trkCand.getCrosses()) { + if(c.getDetector()==DetectorType.BST) { countCrosses++; - avg_tandip+=c.get_Point().z()/Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); + avg_tandip+=c.getPoint().z()/Math.sqrt(c.getPoint().x()*c.getPoint().x()+c.getPoint().y()*c.getPoint().y()); } if(countCrosses>0) avg_tandip/=countCrosses; } double dzdrsum = avg_tandip*countCrosses; - double z_bmt = bmt_Ccross.get_Point().z(); + double z_bmt = bmt_Ccross.getPoint().z(); double r_bmt = bmt_Ccross.getRadius(); - System.out.println(bmt_Ccross.get_Point().toString() + " " + bmt_Ccross.getRadius()); + System.out.println(bmt_Ccross.getPoint().toString() + " " + bmt_Ccross.getRadius()); double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= SVTParameters.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (countCrosses)) / ((dzdrsum + dzdr_bmt) / (double) (countCrosses + 1))) <= SVTParameters.DZDRCUT) // add this to the track pass = true; return pass; @@ -290,57 +270,57 @@ private Seed isTrack5(Cross c1, Cross c2, Cross c3, Cross c4, Cross c5) { if(c1==null || c2==null || c3==null || c4==null || c5==null) return null; double phi12 = Math.abs(relPhi(c1, c2)); - if (phi12 > SVTParameters.phi12cut) { + if (phi12 > SVTParameters.PHI12CUT) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > SVTParameters.phi13cut) { + if (phi13 > SVTParameters.PHI13CUT) { return null; } double phi14 = Math.abs(relPhi(c1, c4)); - if (phi14 > SVTParameters.phi14cut) { + if (phi14 > SVTParameters.PHI14CUT) { return null; } double phi15 = Math.abs(relPhi(c1, c5)); - if (phi15 > SVTParameters.phi14cut) { + if (phi15 > SVTParameters.PHI14CUT) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < SVTParameters.radcut) { + if (Math.abs(rad123) < SVTParameters.RADCUT) { return null; } double rad124 = radCurvature(c1, c2, c4); - if (Math.abs(rad124) < SVTParameters.radcut) { + if (Math.abs(rad124) < SVTParameters.RADCUT) { return null; } double rad134 = radCurvature(c1, c3, c4); - if (Math.abs(rad134) < SVTParameters.radcut) { + if (Math.abs(rad134) < SVTParameters.RADCUT) { return null; } double rad234 = radCurvature(c2, c3, c4); - if (Math.abs(rad234) < SVTParameters.radcut) { + if (Math.abs(rad234) < SVTParameters.RADCUT) { return null; } double rad135 = radCurvature(c1, c3, c5); - if (Math.abs(rad135) < SVTParameters.radcut) { + if (Math.abs(rad135) < SVTParameters.RADCUT) { return null; } double rad235 = radCurvature(c2, c3, c5); - if (Math.abs(rad235) < SVTParameters.radcut) { + if (Math.abs(rad235) < SVTParameters.RADCUT) { return null; } double rad245 = radCurvature(c2, c4, c5); - if (Math.abs(rad245) < SVTParameters.radcut) { + if (Math.abs(rad245) < SVTParameters.RADCUT) { return null; } // double[] seed_delta_phi = {phi12, phi13, phi14, phi15}; // double[] seed_radius = {rad123, rad124, rad134, rad234, rad135, rad235, rad245}; // create the seed Seed seed = new Seed(); - seed.get_Crosses().add(c1); - seed.get_Crosses().add(c2); - seed.get_Crosses().add(c3); - seed.get_Crosses().add(c4); + seed.getCrosses().add(c1); + seed.getCrosses().add(c2); + seed.getCrosses().add(c3); + seed.getCrosses().add(c4); return seed; } @@ -350,41 +330,41 @@ private Seed isTrack4(Cross c1, Cross c2, Cross c3, Cross c4) { return null; double phi12 = Math.abs(relPhi(c1, c2)); - if (phi12 > SVTParameters.phi12cut) { + if (phi12 > SVTParameters.PHI12CUT) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > SVTParameters.phi13cut) { + if (phi13 > SVTParameters.PHI13CUT) { return null; } double phi14 = Math.abs(relPhi(c1, c4)); - if (phi14 > SVTParameters.phi14cut) { + if (phi14 > SVTParameters.PHI14CUT) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < SVTParameters.radcut) { + if (Math.abs(rad123) < SVTParameters.RADCUT) { return null; } double rad124 = radCurvature(c1, c2, c4); - if (Math.abs(rad124) < SVTParameters.radcut) { + if (Math.abs(rad124) < SVTParameters.RADCUT) { return null; } double rad134 = radCurvature(c1, c3, c4); - if (Math.abs(rad134) < SVTParameters.radcut) { + if (Math.abs(rad134) < SVTParameters.RADCUT) { return null; } double rad234 = radCurvature(c2, c3, c4); - if (Math.abs(rad234) < SVTParameters.radcut) { + if (Math.abs(rad234) < SVTParameters.RADCUT) { return null; } // double[] seed_delta_phi = {phi12, phi13, phi14}; // double[] seed_radius = {rad123, rad124, rad134, rad234}; // create the seed Seed seed = new Seed(); - seed.get_Crosses().add(c1); - seed.get_Crosses().add(c2); - seed.get_Crosses().add(c3); - seed.get_Crosses().add(c4); + seed.getCrosses().add(c1); + seed.getCrosses().add(c2); + seed.getCrosses().add(c3); + seed.getCrosses().add(c4); return seed; } @@ -393,15 +373,15 @@ private Seed isTrack3(Cross c1, Cross c2, Cross c3) { if(c1==null || c2==null || c3==null) return null; double phi12 = Math.abs(relPhi(c1,c2)); - if (phi12 > SVTParameters.phi12cut) { + if (phi12 > SVTParameters.PHI12CUT) { return null; } double phi13 = Math.abs(relPhi(c1, c3)); - if (phi13 > SVTParameters.phi13cut) { + if (phi13 > SVTParameters.PHI13CUT) { return null; } double rad123 = radCurvature(c1, c2, c3); - if (Math.abs(rad123) < SVTParameters.radcut) { + if (Math.abs(rad123) < SVTParameters.RADCUT) { return null; } @@ -409,39 +389,39 @@ private Seed isTrack3(Cross c1, Cross c2, Cross c3) { // double[] seed_radius = {rad123}; // create the seed Seed seed = new Seed(); - seed.get_Crosses().add(c1); - seed.get_Crosses().add(c2); - seed.get_Crosses().add(c3); + seed.getCrosses().add(c1); + seed.getCrosses().add(c2); + seed.getCrosses().add(c3); return seed; } private double relPhi(Cross c1, Cross c2) { //double cos_ZDiff = -1; - double x1 = c1.get_Point().x(); - double y1 = c1.get_Point().y(); - double x2 = c2.get_Point().x(); - double y2 = c2.get_Point().y(); + double x1 = c1.getPoint().x(); + double y1 = c1.getPoint().y(); + double x2 = c2.getPoint().x(); + double y2 = c2.getPoint().y(); double n1 = Math.sqrt(x1*x1+y1*y1); double n2 = Math.sqrt(x2*x2+y2*y2); - //Vector3D bt1 = new Vector3D(c1.get_Point().x(), c1.get_Point().y(),0); - //Vector3D bt2 = new Vector3D(c2.get_Point().x(), c2.get_Point().y(),0); + //Vector3D bt1 = new Vector3D(c1.getPoint().x(), c1.getPoint().y(),0); + //Vector3D bt2 = new Vector3D(c2.getPoint().x(), c2.getPoint().y(),0); //cos_ZDiff = bt1.asUnit().dot(bt2.asUnit()); return Math.toDegrees(Math.acos((x1*x2+y1*y2)/(n1*n2))); } private double radCurvature(Cross c1, Cross c2, Cross c3) { double radiusOfCurv = 0; - if (Math.abs(c2.get_Point().x() - c1.get_Point().x()) > 1.0e-9 && Math.abs(c3.get_Point().x() - c2.get_Point().x()) > 1.0e-9) { + if (Math.abs(c2.getPoint().x() - c1.getPoint().x()) > 1.0e-9 && Math.abs(c3.getPoint().x() - c2.getPoint().x()) > 1.0e-9) { // Find the intersection of the lines joining the innermost to middle and middle to outermost point - double ma = (c2.get_Point().y() - c1.get_Point().y()) / (c2.get_Point().x() - c1.get_Point().x()); - double mb = (c3.get_Point().y() - c2.get_Point().y()) / (c3.get_Point().x() - c2.get_Point().x()); + double ma = (c2.getPoint().y() - c1.getPoint().y()) / (c2.getPoint().x() - c1.getPoint().x()); + double mb = (c3.getPoint().y() - c2.getPoint().y()) / (c3.getPoint().x() - c2.getPoint().x()); if (Math.abs(mb - ma) > 1.0e-9) { - double xcen = 0.5 * (ma * mb * (c1.get_Point().y() - c3.get_Point().y()) + mb * (c1.get_Point().x() + c2.get_Point().x()) - ma * (c2.get_Point().x() + c3.get_Point().x())) / (mb - ma); - double ycen = (-1. / mb) * (xcen - 0.5 * (c2.get_Point().x() + c3.get_Point().x())) + 0.5 * (c2.get_Point().y() + c3.get_Point().y()); + double xcen = 0.5 * (ma * mb * (c1.getPoint().y() - c3.getPoint().y()) + mb * (c1.getPoint().x() + c2.getPoint().x()) - ma * (c2.getPoint().x() + c3.getPoint().x())) / (mb - ma); + double ycen = (-1. / mb) * (xcen - 0.5 * (c2.getPoint().x() + c3.getPoint().x())) + 0.5 * (c2.getPoint().y() + c3.getPoint().y()); - radiusOfCurv = Math.sqrt(Math.pow((c1.get_Point().x() - xcen), 2) + Math.pow((c1.get_Point().y() - ycen), 2)); + radiusOfCurv = Math.sqrt(Math.pow((c1.getPoint().x() - xcen), 2) + Math.pow((c1.getPoint().y() - ycen), 2)); } } @@ -457,31 +437,31 @@ private void MatchToRegion1(Seed s, ArrayList R1Crosses, double xb, doubl if(!fitStatus) return; - Point3D trkAtR1 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getRegionRadius(1)); - List candMatches = new ArrayList(); + Point3D trkAtR1 =s.getHelix().getPointAtRadius(SVTGeometry.getRegionRadius(1)); + List candMatches = new ArrayList<>(); for (int i = 0; i < R1Crosses.size(); i++) { if(R1Crosses.get(i)==null) continue; if(Math.abs(Math.sqrt(trkAtR1.x()*trkAtR1.x()+trkAtR1.y()*trkAtR1.y()) - - Math.sqrt(R1Crosses.get(i).get_Point().x()*R1Crosses.get(i).get_Point().x()+R1Crosses.get(i).get_Point().y()*R1Crosses.get(i).get_Point().y()))<2) + Math.sqrt(R1Crosses.get(i).getPoint().x()*R1Crosses.get(i).getPoint().x()+R1Crosses.get(i).getPoint().y()*R1Crosses.get(i).getPoint().y()))<2) candMatches.add(R1Crosses.get(i)); } - Point3D trkAtL1 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(1)); - Point3D trkAtL2 =s.get_Helix().getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(2)); + Point3D trkAtL1 =s.getHelix().getPointAtRadius(SVTGeometry.getLayerRadius(1)); + Point3D trkAtL2 =s.getHelix().getPointAtRadius(SVTGeometry.getLayerRadius(2)); double dMin = Double.POSITIVE_INFINITY; Cross cMatch = null; for (int i = 0; i < candMatches.size(); i++) {//find cross for which the distance of the track to the 2 clusters in the double layers is minimal - double d = candMatches.get(i).get_Cluster1().residual(trkAtL1) - + candMatches.get(i).get_Cluster1().residual(trkAtL2); + double d = candMatches.get(i).getCluster1().residual(trkAtL1) + + candMatches.get(i).getCluster1().residual(trkAtL2); if(d BMTCrosses, double xb, double yb if(passCcross(s, BMTCrosses.get(i)) == false) { continue; } else { - s.get_Crosses().add(BMTCrosses.get(i)); + s.getCrosses().add(BMTCrosses.get(i)); fitStatus = s.fit(3, xb, yb, bz); if(!fitStatus) continue; - double linechi2perndf = s.get_lineFitChi2PerNDF(); + double linechi2perndf = s.getLineFitChi2PerNDF(); if(linechi2perndf CirTrks, Seed cand) { for(int i = 0; iSVTGeometry.getActiveSensorLength()) - Z=SVTGeometry.getActiveSensorLength(); - return Cluster1.get_ResolutionAlongZ(Z) / (SVTGeometry.getPitch() / Math.sqrt(12.)); - } -// /** -// * A class representing the seed object. The seed of a track is the initial -// * guess of the track and contains the crosses that belong to it -// * -// * @author ziegler -// * -// */ -// private class Seed extends ArrayList { -// -// private static final long serialVersionUID = 1L; -// final double[] delta_phi; // opening angle between cross 1 and 2 positions wrt the origin -// final double[] radius; // the radius of the circle of the seed calculated using 3 crosses belonging to the seed -// public TrackSeeder seedFit; -// /** -// * The constructor of the seed -// * -// * @param delta_phi -// * @param radius -// */ -// Seed(double[] delta_phi, double[] radius) { -// seedFit = new TrackSeeder(); -// this.delta_phi = delta_phi; -// this.radius = radius; -// } -// } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java index 10da49c67..52a212f21 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/StraightTrackCrossListFinder.java @@ -121,8 +121,8 @@ public CrossList findTrackSeeds(List crosses) { // loop over points to fill the accumulator arrays for (int i = 0; i < crosses.size(); i++) { - double rho = crosses.get(i).get_Point().y(); - double z = crosses.get(i).get_Point().x(); + double rho = crosses.get(i).getPoint().y(); + double z = crosses.get(i).getPoint().x(); // fill the accumulator arrays for (int j_t = 0; j_t < N_t; j_t++) { @@ -169,17 +169,17 @@ public CrossList findTrackSeeds(List crosses) { // For a given Maximum value of the accumulator, find the set of points associated with it; // for this, begin again loop over all the points - ArrayList> crossLists = new ArrayList>(); + ArrayList> crossLists = new ArrayList<>(); int index = 0; for (int p = nbPeaksR_Z - 1; p > -1; p--) { // Make a new list - ArrayList crossList = new ArrayList(); + ArrayList crossList = new ArrayList<>(); for (int i = 0; i < crosses.size(); i++) { - double rho = crosses.get(i).get_Point().y(); - double z = crosses.get(i).get_Point().x(); + double rho = crosses.get(i).getPoint().y(); + double z = crosses.get(i).getPoint().x(); for (int j_t = 0; j_t < N_t; j_t++) { // theta_j in the middle of the bin : @@ -226,7 +226,7 @@ public CrossList findTrackSeeds(List crosses) { } } // create the indexed arraylists - ArrayList> newcrossLists = new ArrayList>(); + ArrayList> newcrossLists = new ArrayList<>(); int newListIndex = 0; for (int i = 0; i < crossLists.size(); i++) { if (crossLists.get(i).size() > 0) { @@ -253,12 +253,12 @@ private boolean regionUniquenessFlag(ArrayList crossList) { for (Cross thecross : crossList) { - theRegionsCount[thecross.get_SVTCosmicsRegion() - 1]++; + theRegionsCount[thecross.getSVTCosmicsRegion() - 1]++; - if (crossList.size() == 3 && theRegionsCount[thecross.get_SVTCosmicsRegion() - 1] > 1) { + if (crossList.size() == 3 && theRegionsCount[thecross.getSVTCosmicsRegion() - 1] > 1) { passList = false; } - if (crossList.size() > 3 && theRegionsCount[thecross.get_SVTCosmicsRegion() - 1] > 2) { + if (crossList.size() > 3 && theRegionsCount[thecross.getSVTCosmicsRegion() - 1] > 2) { passList = false; } } @@ -268,7 +268,7 @@ private boolean regionUniquenessFlag(ArrayList crossList) { /** * * @param crosses the list of crosses - * @param geo + * @param NbSVTRegions * @return find track guess with svt only */ public CrossList findCosmicsCandidateCrossLists(List> crosses, int NbSVTRegions) { @@ -278,18 +278,18 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, // start finding SVT crosses ArrayList svt_crosses = crosses.get(0); // if there are no svt crosses then return - there is no track - if (svt_crosses.size() == 0) { + if (svt_crosses.isEmpty()) { return null; } Map svtMap = new HashMap>(); for(Cross c : svt_crosses) { - if(svtMap.containsKey(c.get_Region())==false) { - ArrayList list = new ArrayList(); + if(svtMap.containsKey(c.getRegion())==false) { + ArrayList list = new ArrayList<>(); list.add(c); - svtMap.put(c.get_Region(), list); + svtMap.put(c.getRegion(), list); } else { - ArrayList list = (ArrayList) svtMap.get(c.get_Region()); + ArrayList list = (ArrayList) svtMap.get(c.getRegion()); list.add(c); } } @@ -307,7 +307,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, for(int i1 = 0; i1 list = new ArrayList(); + ArrayList list = new ArrayList<>(); if(svtMap.containsKey(1)==true) { ArrayList list1 = (ArrayList) svtMap.get(1); list.add(list1.get(i1)); @@ -327,14 +327,14 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, // instantiate the resulting crosslist CrossList crossListFinal = new CrossList(); - ArrayList> newCrossLists = new ArrayList>(); + ArrayList> newCrossLists = new ArrayList<>(); // loop over the list of crosslists for (int i = 0; i < crossLists.size(); i++) { if (crossLists.get(i).size() > 0) { - ArrayList crossList = new ArrayList(); + ArrayList crossList = new ArrayList<>(); // find the trajectory for each crosslist - ArrayList TrajPoints = get_XYTrajectory(crossLists.get(i), NbSVTRegions); + ArrayList TrajPoints = getXYTrajectory(crossLists.get(i), NbSVTRegions); Collections.sort(svt_crosses); for (Cross p : TrajPoints) { // loop over the trajectory points obtained from the trajectory function @@ -344,10 +344,10 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, // find the crosses which are closest to the trajectory obtained from the seed for (Cross c : svt_crosses) { - if (c.get_Sector() != p.get_Sector() || c.get_Region() != p.get_Region() || p.get_Detector()!=DetectorType.BST) { + if (c.getSector() != p.getSector() || c.getRegion() != p.getRegion() || p.getDetector()!=DetectorType.BST) { continue; } - double d = c.get_Point0().distance(p.get_Point0()); + double d = c.getPoint0().distance(p.getPoint0()); if (d < doca) { doca = d; closestCross = c; // the closest cross to the trajectory @@ -355,8 +355,8 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, } if (closestCross != null) // if there is a closest point it has to be within the cuts { - if (Math.abs(closestCross.get_Point0().x() - p.get_Point0().x()) < SVTParameters.MAXDISTTOTRAJXY && - Math.abs(closestCross.get_Point0().y() - p.get_Point0().y()) < SVTParameters.MAXDISTTOTRAJXY) { + if (Math.abs(closestCross.getPoint0().x() - p.getPoint0().x()) < SVTParameters.MAXDISTTOTRAJXY && + Math.abs(closestCross.getPoint0().y() - p.getPoint0().y()) < SVTParameters.MAXDISTTOTRAJXY) { crossList.add(closestCross); } @@ -369,7 +369,7 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, //crossListFinal.addAll(newCrossLists); for (int k = 0; k < newCrossLists.size(); k++) { - if (newCrossLists.get(k).size() != 0) { + if (!newCrossLists.get(k).isEmpty()) { crossListFinal.add(newCrossLists.get(k)); } } @@ -377,14 +377,14 @@ public CrossList findCosmicsCandidateCrossLists(List> crosses, } - private List X = new ArrayList(); - private List Y = new ArrayList(); - private List errX = new ArrayList(); - private List errY = new ArrayList(); + private final List X = new ArrayList<>(); + private final List Y = new ArrayList<>(); + private final List errX = new ArrayList<>(); + private final List errY = new ArrayList<>(); - private ArrayList get_XYTrajectory(List crosses, int NbSVTRegions) { + private ArrayList getXYTrajectory(List crosses, int NbSVTRegions) { - ArrayList projectedCrosses = new ArrayList(); + ArrayList projectedCrosses = new ArrayList<>(); List _hitsOnTrack = crosses; @@ -404,10 +404,10 @@ private ArrayList get_XYTrajectory(List crosses, int NbSVTRegions) for (int j = 0; j < _hitsOnTrack.size(); j++) { - X.add(j, _hitsOnTrack.get(j).get_Point().x()); - errX.add(j, _hitsOnTrack.get(j).get_PointErr().x()); - Y.add(j, _hitsOnTrack.get(j).get_Point().y()); - errY.add(j, _hitsOnTrack.get(j).get_PointErr().y()); + X.add(j, _hitsOnTrack.get(j).getPoint().x()); + errX.add(j, _hitsOnTrack.get(j).getPointErr().x()); + Y.add(j, _hitsOnTrack.get(j).getPoint().y()); + errY.add(j, _hitsOnTrack.get(j).getPointErr().y()); } // Fit XY Profile first to correct the cross @@ -423,7 +423,7 @@ private ArrayList get_XYTrajectory(List crosses, int NbSVTRegions) double yxslope = linefitparsYX.slope(); double yxinterc = linefitparsYX.intercept(); - projectedCrosses = this.get_CalcHitsOnTrackXY(yxslope, yxinterc, NbSVTRegions); + projectedCrosses = this.getCalcHitsOnTrackXY(yxslope, yxinterc, NbSVTRegions); return projectedCrosses; } @@ -436,11 +436,11 @@ private ArrayList get_XYTrajectory(List crosses, int NbSVTRegions) * @param geo the SVT geometry * @return calculated crosses on the trajectory in the xy plane */ - private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, int NbSVTRegions) { + private ArrayList getCalcHitsOnTrackXY(double yxslope, double yxinterc, int NbSVTRegions) { Ray xyTrack = new Ray(yxslope, 0, yxinterc, 0, 0, 0, 0, 0); - ArrayList projectedCrosses = new ArrayList(); + ArrayList projectedCrosses = new ArrayList<>(); // SVT: Layer 1-8: @@ -455,7 +455,7 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, Point3D traj = new Point3D(); if(plane.intersection(xyTrack.toLine(), traj)==1 && Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) { Cross cross2D = new Cross(DetectorType.BST, BMTType.UNDEFINED, sector, region, -1); // 2-dimentional cross object corresponding to a point on the trajectory line in the xy plane - cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); + cross2D.setPoint0(new Point3D(traj.x(), traj.y(), 0)); projectedCrosses.add(cross2D); } } @@ -472,68 +472,13 @@ private ArrayList get_CalcHitsOnTrackXY(double yxslope, double yxinterc, for(Point3D traj : trajs) { Cross cross2D = new Cross(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, Constants.BMTGEOMETRY.getRegion(layer), -1); - cross2D.set_Point0(new Point3D(traj.x(), traj.y(), 0)); + cross2D.setPoint0(new Point3D(traj.x(), traj.y(), 0)); projectedCrosses.add(cross2D); } } } - -// double[] t = new double[4]; -// for (int ir = 0; ir < 3; ir++) { -// -// -// this.calcBMT2DPoint(yxslope, yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(ir+1, BMTType.C)), t); -// -// //Cross cross2D1 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); -// Cross cross2D1 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[1], t[0])), ir + 1, -1); -// cross2D1.set_Point0(new Point3D(t[0], t[1], 0)); -// projectedCrosses.add(cross2D1); -// System.out.println("C" + ir + " " + cross2D1.get_Point0().toString()); -// if (t[3] != t[1] && t[2] != t[0]) { -// -// //Cross cross2D2 = new Cross("BMT", BMTType.C, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); -// Cross cross2D2 = new Cross(DetectorType.BMT, BMTType.C, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[3], t[2])), ir + 1, -1); -// cross2D2.set_Point0(new Point3D(t[2], t[3], 0)); -// System.out.println("C" + ir + " " + cross2D2.get_Point0().toString()); -// projectedCrosses.add(cross2D2); -// } -// this.calcBMT2DPoint(yxslope, -// yxinterc, bmt_geo.getRadiusMidDrift(bmt_geo.getLayer(ir+1, BMTType.Z)), t); -// -// //Cross cross2D3 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[1], t[0]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); -// Cross cross2D3 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[1], t[0])), ir + 1, -1); -// cross2D3.set_Point0(new Point3D(t[0], t[1], 0)); -// System.out.println("Z" + ir + " " + cross2D3.get_Point0().toString()); -// projectedCrosses.add(cross2D3); -// if (t[3] != t[1] && t[2] != t[0]) { -// -// //Cross cross2D4 = new Cross("BMT", BMTType.Z, bmt_geo.isInSector((ir + 1) * 2, Math.atan2(t[3], t[2]), Math.toRadians(Constants.isInSectorJitter)), ir + 1, -1); -// Cross cross2D4 = new Cross(DetectorType.BMT, BMTType.Z, bmt_geo.getSector((ir + 1) * 2, Math.atan2(t[3], t[2])), ir + 1, -1); -// cross2D4.set_Point0(new Point3D(t[2], t[3], 0)); -// projectedCrosses.add(cross2D4); -// System.out.println("Z" + ir + " " + cross2D4.get_Point0().toString()); -// } -// } return projectedCrosses; } - private void calcBMT2DPoint(double yxslope, - double yxinterc, double rb, double[] t) { - t[0] = 0; //first point x - t[1] = 0; //first point y - t[2] = 0; //second point x - t[3] = 0; //second point y - - double Delta = yxslope * yxslope * yxinterc * yxinterc - (yxslope * yxslope + 1) * (yxinterc * yxinterc - rb * rb); - if (Delta < 0) { - return; - } - - t[1] = (-yxslope * yxinterc + Math.sqrt(Delta)) / (yxslope * yxslope + 1); - t[3] = (-yxslope * yxinterc - Math.sqrt(Delta)) / (yxslope * yxslope + 1); - t[0] = yxslope * t[1] + yxinterc; - t[2] = yxslope * t[3] + yxinterc; - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/package-info.java deleted file mode 100644 index c1e54250e..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.cross; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalcPars.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalcPars.java index cc0ed9e3b..d0103a321 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalcPars.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalcPars.java @@ -21,6 +21,7 @@ public CircleCalcPars(double xc, double yc, double r) { /** * Returns the x coordinate of the reference point + * @return */ public double xcen() { return _xc; @@ -28,6 +29,7 @@ public double xcen() { /** * Returns the y coordinate of the reference point + * @return */ public double ycen() { return _yc; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalculator.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalculator.java index 572d997f5..03dd7a295 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalculator.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleCalculator.java @@ -59,7 +59,7 @@ public CircleCalcPars getCalc() { private List> SortPoints(List p0, List p1, List p2) { - List> newArray = new ArrayList>(); + List> newArray = new ArrayList<>(); List midpoint = null; List nearestToTarget = null; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitPars.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitPars.java index f6e6ad01c..eeb409fa9 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitPars.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CircleFitPars.java @@ -32,6 +32,7 @@ public CircleFitPars(double xr, double yr, double rho, double phir, double docar /** * Returns the x coordinate of the reference point + * @return */ public double xref() { return _xref; @@ -39,6 +40,7 @@ public double xref() { /** * Returns the y coordinate of the reference point + * @return */ public double yref() { return _yref; @@ -46,6 +48,7 @@ public double yref() { /** * Returns the radius of curvature + * @return */ public double rho() { return _rho; @@ -53,6 +56,7 @@ public double rho() { /** * Returns the phi at the reference point + * @return */ public double phi() { return _phi; @@ -60,6 +64,7 @@ public double phi() { /** * Returns the doca to the reference point + * @return */ public double doca() { return _dca; @@ -67,6 +72,7 @@ public double doca() { /** * Returns the chi^2 of the fit + * @return */ public double chisq() { return _chisq; @@ -74,6 +80,7 @@ public double chisq() { /** * Returns the covariance matrix of the fit + * @return */ public double[] cov() { double[] tmpmat = new double[6]; @@ -81,15 +88,4 @@ public double[] cov() { return tmpmat; } -// public static void main(String[] args) - //{ - //double[] cov = {1.,0.,1.,0.,1.,0.}; - //CirclePars cirf = new CirclePars(0.,0.,0.01,0.3,0.1, 15., cov); - //System.out.println(cirf); - //double[] covmat = cirf.cov(); - //for(int i=0; i xm, List ym, List wm, int NP) { double xl, yl, r2l, wt, wx, wy, wr2; // The local point positions and weight parameters @@ -238,7 +245,7 @@ public boolean fitStatus(List xm, List ym, List wm, int return true; } - void propagatePars(double xr, double yr, double x, double y, double cosphi, double sinphi) { + private void propagatePars(double xr, double yr, double x, double y, double cosphi, double sinphi) { setrefcoords(xr, yr); // evaluate the fit parameters at the reference point //double X = _xpca -_xref; @@ -333,9 +340,9 @@ public CircleFitPars propagatefit(double xp, double yp) { public static void main(String[] args) { //List xm, List ym, List wm; - List xm = new ArrayList(); - List ym = new ArrayList(); - List wm = new ArrayList(); + List xm = new ArrayList<>(); + List ym = new ArrayList<>(); + List wm = new ArrayList<>(); // xm.add((double) 5.); // ym.add((double) 5.); // wm.add((double) 1.); @@ -349,9 +356,9 @@ public static void main(String[] args) { ym.add((double) 46.82); wm.add((double) 1.); - List P0 = new ArrayList(2); - List P1 = new ArrayList(2); - List P2 = new ArrayList(2); + List P0 = new ArrayList<>(2); + List P1 = new ArrayList<>(2); + List P2 = new ArrayList<>(2); // Find the intersection of the lines joining the innermost to middle and middle to outermost point P0.add(xm.get(0)); P1.add(xm.get(1)); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitPars.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitPars.java index 8a2456897..8dc142e72 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitPars.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitPars.java @@ -12,23 +12,23 @@ public class CosmicFitPars { // The constructor public CosmicFitPars(Ray ray, double[] chi2) { - set_ray(ray); - set_chisq(chi2); + setRay(ray); + setChi2(chi2); } - public double[] get_chisq() { + public double[] getChi2() { return _chisq; } - public void set_chisq(double[] chisq) { + public final void setChi2(double[] chisq) { this._chisq = chisq; } - public Ray get_ray() { + public Ray getRay() { return _ray; } - public void set_ray(Ray _ray) { + public final void setRay(Ray _ray) { this._ray = _ray; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java index 618819b4c..e8032d2aa 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/fit/CosmicFitter.java @@ -62,7 +62,7 @@ public FitStatus fit(List X, List Y, List Z, List X, List Y, List Z, List(X.size()), X.size()); + boolean linefitstatusXYOK = _linefitYX.fitStatus(Y, X, errRt, new ArrayList<>(X.size()), X.size()); //Line fit _linefitY_primeZ = new LineFitter(); @@ -109,22 +109,22 @@ public FitStatus fit(List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List(X.size()), X.size()); + boolean linefitstatusXYOK = _linefitYX.fitStatus(Y, X, errRt, new ArrayList<>(X.size()), X.size()); _linefitRhoZ = new LineFitter(); boolean linefitstatusOK = _linefitRhoZ.fitStatus(Rho, Z, errRho, ErrZ, Z.size()); @@ -192,37 +192,37 @@ public FitStatus fit2(List X, List Y, List Z, List X, List Y, List Z, List X, List Y, List Z, List W = new ArrayList(); + private final List W = new ArrayList<>(); public FitStatus fit(List X, List Y, List Z, List Rho, List errRt, List errRho, List ErrZ) { // Initialize the various fitter outputs @@ -75,7 +75,7 @@ public FitStatus fit(List X, List Y, List Z, List(X.size()), X.size()); + boolean xyfitstatusOK = _xyfit.fitStatus(X, Y, W, new ArrayList<>(X.size()), X.size()); double slope = _xyfit.getFit().slope(); double intercept = _xyfit.getFit().intercept(); Line3D line = new Line3D(new Point3D(X.get(0),slope*X.get(0)+intercept,0), new Point3D(X.get(1),slope*X.get(1)+intercept,0)); @@ -146,7 +146,7 @@ public FitStatus fit(List X, List Y, List Z, List arg.get_Strip().get_Edep() ? -1 : this.get_Strip().get_Edep() == arg.get_Strip().get_Edep() ? 0 : 1; - int CompTime = this.get_Strip().get_Time() < arg.get_Strip().get_Time() ? -1 : this.get_Strip().get_Time() == arg.get_Strip().get_Time() ? 0 : 1; + int CompLyr = this.getLayer() < arg.getLayer() ? -1 : this.getLayer() == arg.getLayer() ? 0 : 1; + int CompEdep = this.getStrip().getEdep() > arg.getStrip().getEdep() ? -1 : this.getStrip().getEdep() == arg.getStrip().getEdep() ? 0 : 1; + int CompTime = this.getStrip().getTime() < arg.getStrip().getTime() ? -1 : this.getStrip().getTime() == arg.getStrip().getTime() ? 0 : 1; int return_val1 = ((CompTime == 0) ? CompEdep : CompTime); int return_val = ((CompLyr == 0) ? return_val1 : CompLyr); return return_val; } else { - int CompLyr = this.get_Layer() < arg.get_Layer() ? -1 : this.get_Layer() == arg.get_Layer() ? 0 : 1; - int return_val1 = this.get_Strip().get_Strip() < arg.get_Strip().get_Strip() ? -1 : this.get_Strip().get_Strip() == arg.get_Strip().get_Strip() ? 0 : 1; + int CompLyr = this.getLayer() < arg.getLayer() ? -1 : this.getLayer() == arg.getLayer() ? 0 : 1; + int return_val1 = this.getStrip().getStrip() < arg.getStrip().getStrip() ? -1 : this.getStrip().getStrip() == arg.getStrip().getStrip() ? 0 : 1; return ((CompLyr == 0) ? return_val1 : CompLyr); } } public void printInfo() { - String s = " Hit: Detector " + this.get_Detector() + "ID " + this.get_Id() + " Sector " + this.get_Sector() + " Layer " + this.get_Layer() + " Strip " + this.get_Strip().get_Strip() - + " Edep " + this.get_Strip().get_Edep()+ " Time " + this.get_Strip().get_Time(); + String s = " Hit: Detector " + this.getDetector() + "ID " + this.getId() + " Sector " + this.getSector() + " Layer " + this.getLayer() + " Strip " + this.getStrip().getStrip() + + " Edep " + this.getStrip().getEdep()+ " Time " + this.getStrip().getTime(); System.out.println(s); } @@ -175,55 +175,55 @@ public void printInfo() { public boolean isSameAs(Hit otherHit) { Hit thisHit = (Hit) this; boolean cmp = false; - if ((thisHit.get_Detector()==otherHit.get_Detector()) - && thisHit.get_Sector() == otherHit.get_Sector() - && thisHit.get_Layer() == otherHit.get_Layer() - && thisHit.get_Strip().get_Strip() == otherHit.get_Strip().get_Strip() - && thisHit.get_Strip().get_Edep() == otherHit.get_Strip().get_Edep()) { + if ((thisHit.getDetector()==otherHit.getDetector()) + && thisHit.getSector() == otherHit.getSector() + && thisHit.getLayer() == otherHit.getLayer() + && thisHit.getStrip().getStrip() == otherHit.getStrip().getStrip() + && thisHit.getStrip().getEdep() == otherHit.getStrip().getEdep()) { cmp = true; } return cmp; } - public double get_docaToTrk() { + public double getdocaToTrk() { return _docaToTrk; } - public void set_docaToTrk(double _docaToTrk) { + public void setdocaToTrk(double _docaToTrk) { this._docaToTrk = _docaToTrk; } - public void set_docaToTrk(Point3D traj) { - this.set_docaToTrk(this.residual(traj)); + public void setdocaToTrk(Point3D traj) { + this.setdocaToTrk(this.residual(traj)); } public double residual(Point3D traj) { double value = 0; - if(this.get_Detector()==DetectorType.BST) { - Line3D dist = this.get_Strip().get_Line().distance(traj); - double side = -Math.signum(this.get_Strip().get_Line().direction().cross(dist.direction()).dot(this.get_Strip().get_Normal())); + if(this.getDetector()==DetectorType.BST) { + Line3D dist = this.getStrip().getLine().distance(traj); + double side = -Math.signum(this.getStrip().getLine().direction().cross(dist.direction()).dot(this.getStrip().getNormal())); value = dist.length()*side; } else { Point3D local = new Point3D(traj); - this.get_Strip().toLocal().apply(local); - if(this.get_Type()==BMTType.C) - value = local.z()-this.get_Strip().get_Z(); + this.getStrip().toLocal().apply(local); + if(this.getType()==BMTType.C) + value = local.z()-this.getStrip().getZ(); else { - value = Math.atan2(local.y(),local.x())-this.get_Strip().get_Phi(); + value = Math.atan2(local.y(),local.x())-this.getStrip().getPhi(); if(Math.abs(value)>Math.PI) value-=Math.signum(value)*2*Math.PI; - value = value*this.get_Strip().get_Tile().baseArc().radius(); + value = value*this.getStrip().getTile().baseArc().radius(); } } return value; } - public double get_stripResolutionAtDoca() { + public double getstripResolutionAtDoca() { return _stripResolutionAtDoca; } - public void set_stripResolutionAtDoca(double _stripResolutionAtDoca) { + public void setstripResolutionAtDoca(double _stripResolutionAtDoca) { this._stripResolutionAtDoca = _stripResolutionAtDoca; } @@ -233,7 +233,7 @@ public void set_stripResolutionAtDoca(double _stripResolutionAtDoca) { * and subsequent KF fit for that hit. -1: no fit; 0: global helical fit; 1: * KF fit */ - public int get_TrkgStatus() { + public int getTrkgStatus() { return _TrkgStatus; } @@ -243,15 +243,15 @@ public int get_TrkgStatus() { * pattern recognition and subsequent KF fit for that hit. -1: no fit; 0: * global helical fit; 1: KF fit */ - public void set_TrkgStatus(int trkgStatus) { + public void setTrkgStatus(int trkgStatus) { _TrkgStatus = trkgStatus; } - public double get_QualityFac() { + public double getQualityFac() { return _QualityFac; } - public void set_QualityFac(double QF) { + public void setQualityFac(double QF) { _QualityFac = QF; } @@ -259,25 +259,25 @@ public void set_QualityFac(double QF) { * * @return the hit residual = doca to track */ - public double get_Residual() { - return get_docaToTrk(); + public double getResidual() { + return getdocaToTrk(); } - public int get_AssociatedClusterID() { + public int getAssociatedClusterID() { return _AssociatedClusterID; } - public void set_AssociatedClusterID(int _AssociatedClusterID) { + public void setAssociatedClusterID(int _AssociatedClusterID) { this._AssociatedClusterID = _AssociatedClusterID; } - public int get_AssociatedTrackID() { + public int getAssociatedTrackID() { return AssociatedTrackID; } - public void set_AssociatedTrackID(int associatedTrackID) { + public void setAssociatedTrackID(int associatedTrackID) { AssociatedTrackID = associatedTrackID; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java index 02c23ceb9..3e79a41f7 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/Strip.java @@ -40,92 +40,65 @@ public Strip(int strip, double edep, double time) { private Cylindrical3D _Tile; private Line3D _Module; private Vector3D _Normal; - private double _ToverX0; - private double _ZoverA; - private double _Tmat; private Transformation3D toLocal; private Transformation3D toGlobal; - public int get_Strip() { + public int getStrip() { return _Strip; } - public void set_Strip(int _Strip) { + public void setStrip(int _Strip) { this._Strip = _Strip; } - public double get_Pitch() { + public double getPitch() { return _Pitch; } - public void set_Pitch(double _Pitch) { + public void setPitch(double _Pitch) { this._Pitch = _Pitch; } - public Arc3D get_Arc() { + public Arc3D getArc() { return _Arc; } - public void set_Arc(Arc3D _Arc) { + public void setArc(Arc3D _Arc) { this._Arc = _Arc; } - public Line3D get_Line() { + public Line3D getLine() { return _Line; } - public void set_Line(Line3D _Line) { + public void setLine(Line3D _Line) { this._Line = _Line; } - public Cylindrical3D get_Tile() { + public Cylindrical3D getTile() { return _Tile; } - public void set_Tile(Cylindrical3D _Tile) { + public void setTile(Cylindrical3D _Tile) { this._Tile = _Tile; } - public Line3D get_Module() { + public Line3D getModule() { return _Module; } - public void set_Module(Line3D _Module) { + public void setModule(Line3D _Module) { this._Module = _Module; } - public Vector3D get_Normal() { + public Vector3D getNormal() { return _Normal; } - public void set_Normal(Vector3D _Normal) { + public void setNormal(Vector3D _Normal) { this._Normal = _Normal; } - public double getToverX0() { - return _ToverX0; - } - - public void setToverX0(double _ToverX0) { - this._ToverX0 = _ToverX0; - } - - public double getMatT() { - return _Tmat; - } - - public void setMatT(double t) { - this._Tmat = t; - } - - public double getZoverA() { - return _ZoverA; - } - - public void setZoverA(double value) { - this._ZoverA = value; - } - public Transformation3D toLocal() { return toLocal; } @@ -142,81 +115,81 @@ public void setToGlobal(Transformation3D toGlobal) { this.toGlobal = toGlobal; } - public int get_LCStrip() { + public int getLCStrip() { return _LCStrip; } - public void set_LCStrip(int _LCStrip) { + public void setLCStrip(int _LCStrip) { this._LCStrip = _LCStrip; } - public double get_Phi() { + public double getPhi() { return _Phi; } - public void set_Phi(double _Phi) { + public void setPhi(double _Phi) { this._Phi = _Phi; } - public double get_PhiErr() { + public double getPhiErr() { return _PhiErr; } - public void set_PhiErr(double _PhiErr) { + public void setPhiErr(double _PhiErr) { this._PhiErr = _PhiErr; } - public double get_Phi0() { + public double getPhi0() { return _Phi0; } - public void set_Phi0(double _Phi0) { + public void setPhi0(double _Phi0) { this._Phi0 = _Phi0; } - public double get_PhiErr0() { + public double getPhiErr0() { return _PhiErr0; } - public void set_PhiErr0(double _PhiErr0) { + public void setPhiErr0(double _PhiErr0) { this._PhiErr0 = _PhiErr0; } - public double get_Z() { + public double getZ() { return _Z; } - public void set_Z(double _Z) { + public void setZ(double _Z) { this._Z = _Z; } - public double get_ZErr() { + public double getZErr() { return _ZErr; } - public void set_ZErr(double _ZErr) { + public void setZErr(double _ZErr) { this._ZErr = _ZErr; } - public double get_Edep() { + public double getEdep() { return _Edep; } - public void set_Edep(double _Edep) { + public void setEdep(double _Edep) { this._Edep = _Edep; } /** * @return the _Time */ - public double get_Time() { + public double getTime() { return _Time; } /** * @param _Time the _Time to set */ - public void set_Time(double _Time) { + public void setTime(double _Time) { this._Time = _Time; } @@ -236,53 +209,50 @@ public void setStatus(int _Status) { * @param layer * @param swim */ - public void calc_BMTStripParams(int sector, int layer, Swim swim) { + public void calcBMTStripParams(int sector, int layer, Swim swim) { BMTGeometry geo = Constants.BMTGEOMETRY; int region = geo.getRegion(layer); // region index (1...3) 1=layers 1&2, 2=layers 3&4, 3=layers 5&6 this.setToGlobal(geo.toGlobal(layer, sector)); this.setToLocal(geo.toLocal(layer, sector)); - this.set_Tile(geo.getTileSurface(layer, sector)); - this.set_Pitch(geo.getPitch(layer, this.get_Strip())); - this.setToverX0(geo.getToverX0(layer)); - this.setZoverA(geo.getZoverA(layer)); - this.setMatT(geo.getMaterialThickness(layer)); + this.setTile(geo.getTileSurface(layer, sector)); + this.setPitch(geo.getPitch(layer, this.getStrip())); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { // C-detectors // set z - //double z = geo.CRCStrip_GetZ(layer, this.get_Strip()); - Arc3D arcLine = geo.getCstrip(region, sector, this.get_Strip()); - this.set_Arc(arcLine); - this.set_Normal(arcLine.bisect()); + //double z = geo.CRCStrip_GetZ(layer, this.getStrip()); + Arc3D arcLine = geo.getCstrip(region, sector, this.getStrip()); + this.setArc(arcLine); + this.setNormal(arcLine.bisect()); // max z err - this.set_Z(geo.getCstripZ(geo.getRegion(layer),this.get_Strip())); - this.set_ZErr(geo.getPitch(layer, this.get_Strip()) / Math.sqrt(12.)); + this.setZ(geo.getCstripZ(geo.getRegion(layer),this.getStrip())); + this.setZErr(geo.getPitch(layer, this.getStrip()) / Math.sqrt(12.)); } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { // Z-detectors - Line3D line = geo.getLCZstrip(geo.getRegion(layer), sector, this.get_Strip(), swim); - this.set_Line(line); - this.set_Normal(this.get_Tile().getAxis().distance(line.midpoint()).direction().asUnit()); + Line3D line = geo.getLCZstrip(geo.getRegion(layer), sector, this.getStrip(), swim); + this.setLine(line); + this.setNormal(this.getTile().getAxis().distance(line.midpoint()).direction().asUnit()); // set the phi - Point3D local = geo.getIdealLCZstrip(region, sector, this.get_Strip(), swim).midpoint(); - double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.get_Strip()); + Point3D local = geo.getIdealLCZstrip(region, sector, this.getStrip(), swim).midpoint(); + double theMeasuredPhi = geo.getZstripPhi(geo.getRegion(layer), sector, this.getStrip()); double theLorentzCorrectedAngle = local.toVector3D().phi(); - this.set_Phi(theLorentzCorrectedAngle); - this.set_Phi0(theMeasuredPhi); // uncorrected, can be outside of -pi,pi + this.setPhi(theLorentzCorrectedAngle); + this.setPhi0(theMeasuredPhi); // uncorrected, can be outside of -pi,pi // get the strip number after correcting for Lorentz angle int theLorentzCorrectedStrip = geo.getStrip(layer, sector, line.midpoint()); - this.set_LCStrip(theLorentzCorrectedStrip); + this.setLCStrip(theLorentzCorrectedStrip); // RDV use xyz dependent ThetaLorentz - double sigma = BMTConstants.SigmaDrift / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (hDrift) = total gap from top to mesh + double sigma = BMTConstants.SIGMADRIFT / Math.cos(geo.getThetaLorentz(layer, sector)); // max sigma for drift distance (HDRIFT) = total gap from top to mesh //max phi err double phiErrL = sigma / geo.getRadius(layer); - double phiErr = geo.getPitch(layer, this.get_Strip()) / geo.getRadius(layer) / Math.sqrt(12.); - this.set_PhiErr(Math.sqrt(phiErr * phiErr + phiErrL * phiErrL)); - this.set_PhiErr0(phiErr); + double phiErr = geo.getPitch(layer, this.getStrip()) / geo.getRadius(layer) / Math.sqrt(12.); + this.setPhiErr(Math.sqrt(phiErr * phiErr + phiErrL * phiErrL)); + this.setPhiErr0(phiErr); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/package-info.java deleted file mode 100644 index 41aa0026b..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/hit/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.hit; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/MLayer.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/MLayer.java new file mode 100644 index 000000000..ee72a1f35 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/MLayer.java @@ -0,0 +1,130 @@ +package org.jlab.rec.cvt.measurement; + +import org.jlab.detector.base.DetectorType; + +/** + * + * @author devita + */ +public enum MLayer { + UNDEFINED(99, "Undefined", 0), + TARGET(0, "Target", 0), + SHIELD(1, "Tungsten Shield", 0), + INNERSVTCAGE(2, "Inner SVT Faraday Cage", 0), + SVTLAYER1(3, "SVT Layer 1", 1), + SVTLAYER2(4, "SVT Layer 2", 2), + SVTLAYER3(5, "SVT Layer 3", 3), + SVTLAYER4(6, "SVT Layer 4", 4), + SVTLAYER5(7, "SVT Layer 5", 5), + SVTLAYER6(8, "SVT Layer 6", 6), + OUTERSVTCAGE(9, "Outer SVT Faraday Cage", 0), + BMTLAYER1(10, "BMT Layer 1", 1), + BMTLAYER2(11, "BMT Layer 2", 2), + BMTLAYER3(12, "BMT Layer 3", 3), + BMTLAYER4(13, "BMT Layer 4", 4), + BMTLAYER5(14, "BMT Layer 5", 5), + BMTLAYER6(15, "BMT Layer 6", 6), + COSMICPLANE(16, "Cosmic reference plane", 0); + + private final int id; + private final String name; + private final int layer; + + MLayer() { + id = 99; + name = "UNDEFINED"; + layer = 0; + } + + MLayer(int id, String name, int layer) { + this.id = id; + this.name = name; + this.layer = layer; + } + + public String getName() { + return name; + } + + public int getId() { + return id; + } + + public int getLayer() { + return layer; + } + + public int getIndex() { + return this.getIndex(0); + } + + public int getIndex(int hemisphere) { + switch (hemisphere) { + case 1: + return COSMICPLANE.id - id; + case -1: + return COSMICPLANE.id + id - 1; + default: + return id; + } + } + + public static int getId(int index, int hemisphere) { + switch (hemisphere) { + case 1: + return COSMICPLANE.id - index; + case -1: + return index - COSMICPLANE.id + 1; + default: + return index; + } + } + + public static int getHemisphere(int index) { + if (index < COSMICPLANE.id) { + return 1; + } else { + return -1; + } + } + + public static DetectorType getDetectorType(int layId) { + if (layId >= SVTLAYER1.getId() && layId <= SVTLAYER6.getId()) { + return DetectorType.BST; + } else if (layId >= BMTLAYER1.getId() && layId <= BMTLAYER6.getId()) { + return DetectorType.BMT; + } else { + return DetectorType.UNDEFINED; + } + } + + public static MLayer getType(String name) { + name = name.trim(); + for (MLayer id : MLayer.values()) { + if (id.getName().equalsIgnoreCase(name)) { + return id; + } + } + return UNDEFINED; + } + + public static MLayer getType(Integer layId) { + + for (MLayer id : MLayer.values()) { + if (id.getId() == layId) { + return id; + } + } + return UNDEFINED; + } + + public static MLayer getType(DetectorType type, int layer) { + for (MLayer id : MLayer.values()) { + if (id.getLayer() == layer && MLayer.getDetectorType(id.getId()) == type) { + return id; + } + } + return UNDEFINED; + } + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/Measurements.java similarity index 63% rename from reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java rename to reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/Measurements.java index 560f89769..6844788e2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Measurements.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/measurement/Measurements.java @@ -1,8 +1,7 @@ -package org.jlab.rec.cvt.track; +package org.jlab.rec.cvt.measurement; import java.util.ArrayList; import java.util.List; -import org.jlab.clas.swimtools.Swim; import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.clas.tracking.objects.Strip; import org.jlab.detector.base.DetectorType; @@ -14,6 +13,8 @@ import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.svt.SVTGeometry; +import org.jlab.rec.cvt.track.Seed; +import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -45,21 +46,21 @@ private void init(double xbeam, double ybeam) { private void initTargetSurfaces(double xbeam, double ybeam) { cvtSurfaces = new Surface[NSURFACES+1]; - this.add(CVTLayer.TARGET.getIndex(), this.getTarget(xbeam, ybeam)); - this.add(CVTLayer.SHIELD.getIndex(), Constants.SVTGEOMETRY.getShieldSurface()); - this.add(CVTLayer.INNERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0)); - this.add(CVTLayer.OUTERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1)); + this.add(MLayer.TARGET.getIndex(), this.getTarget(xbeam, ybeam)); + this.add(MLayer.SHIELD.getIndex(), Constants.SVTGEOMETRY.getShieldSurface()); + this.add(MLayer.INNERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0)); + this.add(MLayer.OUTERSVTCAGE.getIndex(), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1)); } private void initCosmicSurfaces() { cvtSurfaces = new Surface[NSURFACES*2+1]; - this.add(CVTLayer.COSMICPLANE.getIndex(1), this.getCosmicPlane()); - this.add(CVTLayer.SHIELD.getIndex(1), Constants.SVTGEOMETRY.getShieldSurface()); - this.add(CVTLayer.INNERSVTCAGE.getIndex(1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0)); - this.add(CVTLayer.OUTERSVTCAGE.getIndex(1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1)); - this.add(CVTLayer.SHIELD.getIndex(-1), Constants.SVTGEOMETRY.getShieldSurface(), -1); - this.add(CVTLayer.INNERSVTCAGE.getIndex(-1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0), -1); - this.add(CVTLayer.OUTERSVTCAGE.getIndex(-1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1), -1); + this.add(MLayer.COSMICPLANE.getIndex(1), this.getCosmicPlane()); + this.add(MLayer.SHIELD.getIndex(1), Constants.SVTGEOMETRY.getShieldSurface()); + this.add(MLayer.INNERSVTCAGE.getIndex(1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0)); + this.add(MLayer.OUTERSVTCAGE.getIndex(1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1)); + this.add(MLayer.SHIELD.getIndex(-1), Constants.SVTGEOMETRY.getShieldSurface(), -1); + this.add(MLayer.INNERSVTCAGE.getIndex(-1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(0), -1); + this.add(MLayer.OUTERSVTCAGE.getIndex(-1), Constants.SVTGEOMETRY.getFaradayCageSurfaces(1), -1); } @@ -76,7 +77,7 @@ private void add(int index, Surface surface, int hemisphere) { this.add(index, surface); } - private int getIndex(CVTLayer id, int hemisphere) { + private int getIndex(MLayer id, int hemisphere) { if(!cosmic) return id.getIndex(0); else @@ -141,8 +142,8 @@ public List getMeasurements(StraightTrack cosmic) { for(Surface surf : cvtSurfaces) { if(surf!=null) { if(debug) System.out.println(surf.toString()); - if(surf.passive && surf.getIndex()!=0 && !this.isCrossed(cosmic.get_ray(), surf)) { - if(debug) System.out.println("Removing surface " + surf.passive + " " + this.isCrossed(cosmic.get_ray(), surf)); + if(surf.passive && surf.getIndex()!=0 && !this.isCrossed(cosmic.getRay(), surf)) { + if(debug) System.out.println("Removing surface " + surf.passive + " " + this.isCrossed(cosmic.getRay(), surf)); continue; } surfaces.add(surf); @@ -163,9 +164,9 @@ public List getActiveMeasurements(StraightTrack cosmic) { } private void addClusters(Seed seed) { - int hemisp = (int) Math.signum(seed.get_Helix().getPointAtRadius(300).y()); - this.addClusters(DetectorType.BST, this.getClusterSurfaces(DetectorType.BST, seed.get_Clusters())); - this.addClusters(DetectorType.BMT, this.getClusterSurfaces(DetectorType.BMT, seed.get_Clusters(), hemisp)); + int hemisp = (int) Math.signum(seed.getHelix().getPointAtRadius(300).y()); + this.addClusters(DetectorType.BST, this.getClusterSurfaces(DetectorType.BST, seed.getClusters())); + this.addClusters(DetectorType.BMT, this.getClusterSurfaces(DetectorType.BMT, seed.getClusters(), hemisp)); } private void addClusters(StraightTrack cosmic) { @@ -177,7 +178,7 @@ private void addClusters(DetectorType type, List clusters) { for(Surface cluster : clusters) { int hemisphere = 0; if(cosmic) hemisphere = (int) cluster.hemisphere; - int index = CVTLayer.getType(type, cluster.getLayer()).getIndex(hemisphere); + int index = MLayer.getType(type, cluster.getLayer()).getIndex(hemisphere); this.add(index, cluster); } } @@ -195,8 +196,8 @@ private List getClusterSurfaces(DetectorType type, List cluste List surfaces = new ArrayList<>(); for(Cluster cluster : clusters) { - if(cluster.get_Detector()!=type) continue; - int layer = cluster.get_Layer(); + if(cluster.getDetector()!=type) continue; + int layer = cluster.getLayer(); if(type==DetectorType.BMT) layer += SVTGeometry.NLAYERS; Surface measure = cluster.measurement(); measure.hemisphere = Math.signum(cluster.center().y()); @@ -210,10 +211,10 @@ private List getClusterSurfaces(DetectorType type, List cluste private void addMissing(Seed seed) { for(int i=0; i0) { - DetectorType type = CVTLayer.getDetectorType(id); + DetectorType type = MLayer.getDetectorType(id); Surface surface = this.getDetectorSurface(seed, type, layer, 0); if(surface == null) continue; surface.notUsedInFit=true; @@ -228,11 +229,11 @@ private void addMissing(Seed seed) { private void addMissing(StraightTrack ray) { for(int i=0; i0) { - DetectorType type = CVTLayer.getDetectorType(id); + DetectorType type = MLayer.getDetectorType(id); Surface surface = this.getDetectorSurface(ray, type, layer, hemisphere); if(surface == null) continue; surface.hemisphere=hemisphere; @@ -271,10 +272,10 @@ else if(type==DetectorType.BMT) private int getSector(Seed seed, DetectorType type, int layer, int hemisphere) { - Helix helix = seed.get_Helix(); + Helix helix = seed.getHelix(); if(type==DetectorType.BST) { int twinLayer = Constants.SVTGEOMETRY.getTwinLayer(layer); - int twinIndex = CVTLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); + int twinIndex = MLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); if(cvtSurfaces[twinIndex]!=null) return cvtSurfaces[twinIndex].getSector(); Point3D traj = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(layer)); @@ -282,7 +283,7 @@ private int getSector(Seed seed, DetectorType type, int layer, int hemisphere) { return Constants.SVTGEOMETRY.getSector(layer, traj); } else if(type==DetectorType.BMT) { - Point3D traj = seed.get_Helix().getPointAtRadius(Constants.BMTGEOMETRY.getRadius(layer)); + Point3D traj = seed.getHelix().getPointAtRadius(Constants.BMTGEOMETRY.getRadius(layer)); if(traj!=null && !Double.isNaN(traj.z())) return Constants.BMTGEOMETRY.getSector(0, traj); } @@ -293,11 +294,11 @@ private int getSector(StraightTrack cosmic, DetectorType type, int layer, int he if(type==DetectorType.BST) { int twinLayer = Constants.SVTGEOMETRY.getTwinLayer(layer); - int twinIndex = CVTLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); + int twinIndex = MLayer.getType(DetectorType.BST, twinLayer).getIndex(hemisphere); if(cvtSurfaces[twinIndex]!=null) return cvtSurfaces[twinIndex].getSector(); - double[][][] trajs = TrajectoryFinder.calc_trackIntersSVT(cosmic.get_ray()); + double[][][] trajs = TrajectoryFinder.calcTrackIntersSVT(cosmic.getRay()); for(int i=0; i=SVTLAYER1.getId() && layId<=SVTLAYER6.getId()) - return DetectorType.BST; - else if(layId>=BMTLAYER1.getId() && layId<=BMTLAYER6.getId()) - return DetectorType.BMT; - else - return DetectorType.UNDEFINED; - } - - public static CVTLayer getType(String name) { - name = name.trim(); - for (CVTLayer id : CVTLayer.values()) { - if (id.getName().equalsIgnoreCase(name)) { - return id; - } - } - return UNDEFINED; - } - - public static CVTLayer getType(Integer layId) { - - for (CVTLayer id : CVTLayer.values()) { - if (id.getId() == layId) { - return id; - } - } - return UNDEFINED; - } - - public static CVTLayer getType(DetectorType type, int layer) { - for (CVTLayer id : CVTLayer.values()) { - if(id.getLayer() == layer && CVTLayer.getDetectorType(id.getId()) == type) { - return id; - } - } - return UNDEFINED; - } - - } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/package-info.java deleted file mode 100644 index d69879a45..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * A package to reconstruct events with tracks going through the central tracking system composed of 4 regions of SVT + 1 region of BMT - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java index 213174d10..55df6200d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTRecNewKF.java @@ -118,19 +118,19 @@ public boolean processDataEvent(DataEvent event) { HitReader hitRead = new HitReader(); hitRead.fetch_SVTHits(event, adcConv, -1, -1, svtStatus); - if(Constants.SVTOnly==false) + if(Constants.SVTONLY==false) hitRead.fetch_BMTHits(event, adcConv, swimmer, bmtStatus, bmtTime); List hits = new ArrayList<>(); //I) get the hits - List SVThits = hitRead.get_SVTHits(); + List SVThits = hitRead.getSVTHits(); if(SVThits.size()>SVTParameters.MAXSVTHITS) return true; if (SVThits != null && !SVThits.isEmpty()) { hits.addAll(SVThits); } - List BMThits = hitRead.get_BMTHits(); + List BMThits = hitRead.getBMTHits(); if (BMThits != null && BMThits.size() > 0) { hits.addAll(BMThits); @@ -161,10 +161,10 @@ public boolean processDataEvent(DataEvent event) { if (!clusters.isEmpty()) { for (int i = 0; i < clusters.size(); i++) { - if (clusters.get(i).get_Detector() == DetectorType.BST) { + if (clusters.get(i).getDetector() == DetectorType.BST) { SVTclusters.add(clusters.get(i)); } - if (clusters.get(i).get_Detector() == DetectorType.BMT) { + if (clusters.get(i).getDetector() == DetectorType.BMT) { BMTclusters.add(clusters.get(i)); } } @@ -177,12 +177,7 @@ public boolean processDataEvent(DataEvent event) { return true; } - if(Constants.isCosmicsData) { -// if(this.isSVTonly) { -// List> crosses_svtOnly = new ArrayList<>(); -// crosses_svtOnly.add(0, crosses.get(0)); -// crosses_svtOnly.add(1, new ArrayList<>()); -// } + if(Constants.ISCOSMICDATA) { strgtTrksRec.processEvent(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, rbc, swimmer); } else { @@ -210,8 +205,8 @@ private void loadConfiguration() { //svt stand-alone String svtStAl = this.getEngineConfigString("svtOnly"); if (svtStAl!=null) { - Constants.SVTOnly = Boolean.valueOf(svtStAl); - System.out.println("["+this.getName()+"] run with SVT only "+Constants.SVTOnly+" config chosen based on yaml"); + Constants.SVTONLY = Boolean.valueOf(svtStAl); + System.out.println("["+this.getName()+"] run with SVT only "+Constants.SVTONLY+" config chosen based on yaml"); } else { System.out.println("["+this.getName()+"] run with both CVT systems (default) "); @@ -244,8 +239,8 @@ private void loadConfiguration() { String svtCosmics = this.getEngineConfigString("cosmics"); if (svtCosmics!=null) { - Constants.isCosmicsData = Boolean.valueOf(svtCosmics); - System.out.println("["+this.getName()+"] run with cosmics settings "+Constants.isCosmicsData+" config chosen based on yaml"); + Constants.ISCOSMICDATA = Boolean.valueOf(svtCosmics); + System.out.println("["+this.getName()+"] run with cosmics settings "+Constants.ISCOSMICDATA+" config chosen based on yaml"); } else { System.out.println("["+this.getName()+"] run with cosmics settings default = false"); @@ -292,11 +287,11 @@ private void loadConfiguration() { matrixLibrary = this.getEngineConfigString("matLib"); } Constants.setMatLib(matrixLibrary); - System.out.println("["+this.getName()+"] run with matLib "+ Constants.kfMatLib.toString() + " library"); + System.out.println("["+this.getName()+"] run with matLib "+ Constants.KFMATLIB.toString() + " library"); if(this.getEngineConfigString("svtSeeding")!=null) { - Constants.svtSeeding = Boolean.parseBoolean(this.getEngineConfigString("svtSeeding")); - System.out.println("["+this.getName()+"] run SVT-based seeding set to "+ Constants.svtSeeding); + Constants.SVTSEEDING = Boolean.parseBoolean(this.getEngineConfigString("svtSeeding")); + System.out.println("["+this.getName()+"] run SVT-based seeding set to "+ Constants.SVTSEEDING); } if(this.getEngineConfigString("timeCuts")!=null) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java index 348c94baa..21f47c4aa 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CosmicTracksRec.java @@ -15,12 +15,10 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.cross.CrossList; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; -import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.track.Measurements; +import org.jlab.rec.cvt.measurement.Measurements; import org.jlab.rec.cvt.track.StraightTrack; -import org.jlab.rec.cvt.track.Track; -import org.jlab.rec.cvt.track.TrackCandListFinder; +import org.jlab.rec.cvt.track.StraightTrackCandListFinder; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; /** @@ -48,12 +46,9 @@ public boolean processEvent(DataEvent event, return true; } // refit track based on SVT only and then add BMT and refit again - TrackCandListFinder trkcandFinder = new TrackCandListFinder(); + StraightTrackCandListFinder trkcandFinder = new StraightTrackCandListFinder(); List cosmicCands = trkcandFinder.getStraightTracks(crosslist, crosses.get(1)); - List trkcands = new ArrayList<>(); - //REMOVE THIS - //crosses.get(0).addAll(crosses.get(1)); - //------------------------ + if (cosmicCands.isEmpty()) { recUtil.CleanupSpuriousCrosses(crosses, null) ; rbc.appendCVTCosmicsBanks(event, SVThits, BMThits, SVTclusters, BMTclusters, crosses, null); @@ -67,29 +62,29 @@ public boolean processEvent(DataEvent event, if (cosmicCands.size() > 0) { for (int k1 = 0; k1 < cosmicCands.size(); k1++) { - cosmicCands.get(k1).set_Id(k1 + 1); + cosmicCands.get(k1).setId(k1 + 1); for (int k2 = 0; k2 < cosmicCands.get(k1).size(); k2++) { - cosmicCands.get(k1).get(k2).set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate crosses - if (cosmicCands.get(k1).get(k2).get_Cluster1() != null) { - cosmicCands.get(k1).get(k2).get_Cluster1().set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate cluster1 in cross + cosmicCands.get(k1).get(k2).setAssociatedTrackID(cosmicCands.get(k1).getId()); // associate crosses + if (cosmicCands.get(k1).get(k2).getCluster1() != null) { + cosmicCands.get(k1).get(k2).getCluster1().setAssociatedTrackID(cosmicCands.get(k1).getId()); // associate cluster1 in cross } - if (cosmicCands.get(k1).get(k2).get_Cluster2() != null) { - cosmicCands.get(k1).get(k2).get_Cluster2().set_AssociatedTrackID(cosmicCands.get(k1).get_Id()); // associate cluster2 in cross + if (cosmicCands.get(k1).get(k2).getCluster2() != null) { + cosmicCands.get(k1).get(k2).getCluster2().setAssociatedTrackID(cosmicCands.get(k1).getId()); // associate cluster2 in cross } } trkcandFinder.matchClusters(SVTclusters, new TrajectoryFinder(), true, - cosmicCands.get(k1).get_Trajectory(), k1 + 1); + cosmicCands.get(k1).getTrajectory(), k1 + 1); } recUtil.CleanupSpuriousCrosses(crosses, null) ; - KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.kfMatLib); + KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), Constants.KFMATLIB); Measurements measures = new Measurements(true, 0, 0); List cosmics = new ArrayList<>(); for (int k1 = 0; k1 < cosmicCands.size(); k1++) { - Ray ray = cosmicCands.get(k1).get_ray(); + Ray ray = cosmicCands.get(k1).getRay(); if(Constants.INITFROMMC) { - double[] pars = recUtil.MCtrackPars(event); + double[] pars = recUtil.mcTrackPars(event); Point3D v = new Point3D(pars[0],pars[1],pars[2]); Vector3D p = new Vector3D(pars[3],pars[4],pars[5]); ray = new Ray(v,p); @@ -101,8 +96,8 @@ public boolean processEvent(DataEvent event, cov[2][2]=0.001; // ~2deg cov[3][3]=0.001; cov[4][4]=1; - kf.init(ray.get_yxinterc(),ray.get_yzinterc(), - ray.get_yxslope(), ray.get_yzslope(), Units.MM, cov, + kf.init(ray.getYXInterc(),ray.getYZInterc(), + ray.getYXSlope(), ray.getYZSlope(), Units.MM, cov, measures.getMeasurements(cosmicCands.get(k1))); kf.mv.setDelta_d_a(new double[]{0.1, 0.1, 0.0001, 0.0001, 1}); kf.runFitter(); @@ -111,28 +106,28 @@ public boolean processEvent(DataEvent event, cosmic.update(kf); //refit adding missing clusters - List clsOnTrack = recUtil.FindClustersOnTrack(SVTclusters, cosmic); + List clsOnTrack = recUtil.findClustersOnTrack(SVTclusters, cosmic); if(clsOnTrack.size()>0) { List pseudoCrosses = new ArrayList<>(); for(Cluster cl : clsOnTrack) { - cl.set_AssociatedTrackID(k1 + 1); + cl.setAssociatedTrackID(k1 + 1); //make pseudo-cross - Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, cl.get_Sector(), cl.get_Region(), -1); + Cross this_cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, cl.getSector(), cl.getRegion(), -1); // cluster1 is the inner layer cluster - if(cl.get_Layer()%2==1) { - this_cross.set_Cluster1(cl); + if(cl.getLayer()%2==1) { + this_cross.setCluster1(cl); } else { // cluster2 is the outer layer cluster - this_cross.set_Cluster2(cl); + this_cross.setCluster2(cl); } - this_cross.set_Point0(cl.getTrakInters()); - this_cross.set_Point(cl.getTrakInters()); + this_cross.setPoint0(cl.getTrakInters()); + this_cross.setPoint(cl.getTrakInters()); pseudoCrosses.add(this_cross); } cosmic.addAll(pseudoCrosses); //VZ check for additional clusters, and only then re-run KF adding new clusters //refit - kf.init(cosmic.get_ray().get_yxinterc(),cosmic.get_ray().get_yzinterc(), - cosmic.get_ray().get_yxslope(), cosmic.get_ray().get_yzslope(), Units.CM, cov, + kf.init(cosmic.getRay().getYXInterc(),cosmic.getRay().getYZInterc(), + cosmic.getRay().getYXSlope(), cosmic.getRay().getYZSlope(), Units.CM, cov, measures.getMeasurements(cosmicCands.get(k1))) ; kf.runFitter(); if (kf.setFitFailed == false && kf.NDF>0 && kf.finalStateVec!=null) { @@ -146,25 +141,25 @@ public boolean processEvent(DataEvent event, // reset cross and cluster IDs for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } } for(Cluster c : SVTclusters) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } for(Cluster c : BMTclusters) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } if(!cosmics.isEmpty()) { for(int k = 0; k < cosmics.size(); k++) { - cosmics.get(k).set_Id(k + 1); + cosmics.get(k).setId(k + 1); cosmics.get(k).updateCrosses(); cosmics.get(k).updateClusters(); } } for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { - if(c.get_AssociatedTrackID()==-1) { + if(c.getAssociatedTrackID()==-1) { c.reset(); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java index 96b36d696..34c246a9c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/RecUtilities.java @@ -6,9 +6,6 @@ import java.util.Map; import java.util.HashMap; import org.jlab.rec.cvt.trajectory.Helix; -import org.jlab.clas.tracking.kalmanfilter.*; - -import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; @@ -18,12 +15,11 @@ import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.Track; import org.jlab.clas.swimtools.Swim; -import org.jlab.geom.prim.Line3D; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.fit.CosmicFitter; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.StraightTrackSeeder; -import org.jlab.rec.cvt.track.TrackCandListFinder; +import org.jlab.rec.cvt.track.StraightTrackCandListFinder; import org.jlab.rec.cvt.track.TrackSeeder; import org.jlab.rec.cvt.track.TrackSeederCA; @@ -40,7 +36,6 @@ import org.jlab.rec.cvt.fit.CircleFitter; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.trajectory.Ray; -import org.jlab.rec.cvt.trajectory.TrajectoryFinder; /** * Service to return reconstructed TRACKS * format @@ -51,28 +46,28 @@ public class RecUtilities { public void CleanupSpuriousCrosses(List> crosses, List trks) { - List rmCrosses = new ArrayList(); + List rmCrosses = new ArrayList<>(); for(Cross c : crosses.get(0)) { - if(!Constants.SVTGEOMETRY.isInFiducial(c.get_Cluster1().get_Layer(), c.get_Sector(), c.get_Point())) + if(!Constants.SVTGEOMETRY.isInFiducial(c.getCluster1().getLayer(), c.getSector(), c.getPoint())) rmCrosses.add(c); } for(int j = 0; j rmTrks = new ArrayList(); + List rmTrks = new ArrayList<>(); for(Track t:trks) { boolean rmFlag=false; for(Cross c: rmCrosses) { - if(c!=null && t!=null && c.get_AssociatedTrackID()==t.get_Id()) + if(c!=null && t!=null && c.getAssociatedTrackID()==t.getId()) rmFlag=true; } if(rmFlag==true) @@ -83,176 +78,35 @@ public void CleanupSpuriousCrosses(List> crosses, List t } } - public List setMeasVecs(Seed trkcand, double xb, double yb, Swim swim) { - //Collections.sort(trkcand.get_Crosses()); - List KFSites = new ArrayList<>(); - Vector3D u = new Vector3D(0,0,1); - Point3D p = new Point3D(xb, yb, 0); - Line3D l = new Line3D(p, u); - Surface meas0 = new Surface(l.origin(), l.end(), Constants.DEFAULTSWIMACC); - meas0.setSector(0); - meas0.setLayer(0); - meas0.setError(Constants.getRbErr()); - KFSites.add(meas0); - - // SVT measurements - for (int i = 0; i < trkcand.get_Clusters().size(); i++) { - if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { - int layer = trkcand.get_Clusters().get(i).get_Layer(); - Surface meas = trkcand.get_Clusters().get(i).measurement(); - meas.setIndex(layer); - if((int)Constants.getUsedLayers().get(meas.getLayer())<1) - meas.notUsedInFit=true; - if(i>0 && KFSites.get(KFSites.size()-1).getIndex()==meas.getIndex()) - continue; - KFSites.add(meas); - } - } - - // adding the BMT - double hemisp = Math.signum(trkcand.get_Helix().getPointAtRadius(300).y()); - for (int c = 0; c < trkcand.get_Crosses().size(); c++) { - if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { - int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); - Surface meas = trkcand.get_Crosses().get(c).get_Cluster1().measurement(); - meas.setIndex(layer+SVTGeometry.NLAYERS); - meas.setLayer(layer+SVTGeometry.NLAYERS); - meas.hemisphere = hemisp; - if((int)Constants.getUsedLayers().get(layer+SVTGeometry.NLAYERS)<1) { - //System.out.println("Exluding layer "+meas.getLayer()+trkcand.get_Crosses().get(c).printInfo()); - meas.notUsedInFit=true; - } - if(c>0 && KFSites.get(KFSites.size()-1).getIndex()==meas.getIndex()) - continue; - KFSites.add(meas); - } - } - for(Surface s : KFSites) System.out.println(s.toString()); - return KFSites; - } - private TrajectoryFinder tf = new TrajectoryFinder(); - - // Not used, replaced by Measurements class - public List setMeasVecs(StraightTrack trkcand, Swim swim) { - if(trkcand.clsMap!=null) trkcand.clsMap.clear(); //VZ: reset cluster map for second pass tracking with isolated SVT clusters - //Collections.sort(trkcand.get_Crosses()); - List KFSites = new ArrayList<>(); - Vector3D u = trkcand.get_ray().get_dirVec(); - Plane3D pln0 = new Plane3D(new Point3D(0, 0, 0), u); - Surface meas0 = new Surface(pln0,new Point3D(0,0,0), - new Point3D(-300,0,0), new Point3D(300,0,0),Constants.DEFAULTSWIMACC); - meas0.setSector(0); - meas0.setLayer(0); - meas0.setError(1); - meas0.hemisphere = 1; - KFSites.add(meas0); - - Map clsMap = new HashMap<>(); - trkcand.sort(Comparator.comparing(Cross::getY).reversed()); - for (int i = 0; i < trkcand.size(); i++) { //SVT - if(trkcand.get(i).get_Detector()==DetectorType.BST) { - List cls = new ArrayList<>(); - - if(trkcand.get(i).get_Cluster1()!=null && - trkcand.get(i).get_Cluster2()!=null) { //VZ: modification for pseudocrosses that contain only one cluster - int sector = trkcand.get(i).get_Cluster1().get_Sector(); - int layertop = trkcand.get(i).get_Cluster1().get_Layer(); - int layerbot = trkcand.get(i).get_Cluster2().get_Layer(); - Ray ray = trkcand.get_ray(); - Point3D top = new Point3D(); - Point3D bottom = new Point3D(); - Constants.SVTGEOMETRY.getPlane(layertop, sector).intersection(ray.toLine(), top); - Constants.SVTGEOMETRY.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); - - if(top.y()>bottom.y()) { - cls.add(trkcand.get(i).get_Cluster1()); - cls.add(trkcand.get(i).get_Cluster2()); - } else { - cls.add(trkcand.get(i).get_Cluster2()); - cls.add(trkcand.get(i).get_Cluster1()); - } - } else { - if(trkcand.get(i).get_Cluster1()!=null) cls.add(trkcand.get(i).get_Cluster1()); - if(trkcand.get(i).get_Cluster2()!=null) cls.add(trkcand.get(i).get_Cluster2()); - } - for (int j = 0; j < cls.size(); j++) { - int mlayer = cls.get(j).get_Layer(); - Surface meas = cls.get(j).measurement(); - meas.setLayer(mlayer); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; - // set SVT material budget according to track direction - if(j==0) meas.setl_over_X0(SVTGeometry.getToverX0()); - else meas.setl_over_X0(0); - // RDV to be tested -// if((int) Constants.getUsedLayers().get(meas.getLayer())<1) -// meas.notUsedInFit=true; //VZ: commenting this out prevents the layer exclusion to be employed in tracking - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==mlayer - && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) - continue; - KFSites.add(meas); - - clsMap.put(KFSites.size()-1, cls.get(j)); - trkcand.clsMap = clsMap; - } - } - - // adding the BMT - if (trkcand.get(i).get_Detector()==DetectorType.BMT) { - int layer = trkcand.get(i).get_Cluster1().get_Layer(); - int sector = trkcand.get(i).get_Cluster1().get_Sector(); - - int id = trkcand.get(i).get_Cluster1().get_Id(); - double ce = trkcand.get(i).get_Cluster1().get_Centroid(); - Surface meas = trkcand.get(i).get_Cluster1().measurement(); - meas.setLayer(layer); - meas.hemisphere = Math.signum(trkcand.get(i).get_Point().y());; - if((int)Constants.getUsedLayers().get(meas.getLayer())<1) { - meas.notUsedInFit=true; - } - if(i>0 && KFSites.get(KFSites.size()-1).getLayer()==meas.getLayer() - && KFSites.get(KFSites.size()-1).hemisphere==meas.hemisphere) - continue; - KFSites.add(meas); - clsMap.put(KFSites.size()-1, trkcand.get(i).get_Cluster1()); - } - } - for(int i = 0; i< KFSites.size(); i++) { - KFSites.get(i).setLayer(i); - } - return KFSites; - } - - public List FindClustersOnTrack(List allClusters, StraightTrack trkcand) { + public List findClustersOnTrack(List allClusters, StraightTrack trkcand) { List clustersOnTrack = new ArrayList<>(); - Map clusterMap = new HashMap(); + Map clusterMap = new HashMap<>(); trkcand.sort(Comparator.comparing(Cross::getY).reversed()); - List clsList = new ArrayList(); - int crsCnt = 0; + List clsList = new ArrayList<>(); for (int i = 0; i < trkcand.size(); i++) { //SVT cluster sorting - if(trkcand.get(i).get_Detector()==DetectorType.BST) { - crsCnt++; - int sector = trkcand.get(i).get_Cluster1().get_Sector(); - int layertop = trkcand.get(i).get_Cluster1().get_Layer(); - int layerbot = trkcand.get(i).get_Cluster2().get_Layer(); - Ray ray = trkcand.get_ray(); + if(trkcand.get(i).getDetector()==DetectorType.BST) { + int sector = trkcand.get(i).getCluster1().getSector(); + int layertop = trkcand.get(i).getCluster1().getLayer(); + int layerbot = trkcand.get(i).getCluster2().getLayer(); + Ray ray = trkcand.getRay(); Point3D top = new Point3D(); Point3D bottom = new Point3D(); Constants.SVTGEOMETRY.getPlane(layertop, sector).intersection(ray.toLine(), top); Constants.SVTGEOMETRY.getPlane(layerbot, sector).intersection(ray.toLine(), bottom); if(top.y()>bottom.y()) { - clsList.add(trkcand.get(i).get_Cluster1()); - clsList.add(trkcand.get(i).get_Cluster2()); + clsList.add(trkcand.get(i).getCluster1()); + clsList.add(trkcand.get(i).getCluster2()); } else { - clsList.add(trkcand.get(i).get_Cluster2()); - clsList.add(trkcand.get(i).get_Cluster1()); + clsList.add(trkcand.get(i).getCluster2()); + clsList.add(trkcand.get(i).getCluster1()); } } } for(Cluster cluster : clsList) { - clusterMap.put(SVTGeometry.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); + clusterMap.put(SVTGeometry.getModuleId(cluster.getLayer(), cluster.getSector()), cluster); } // for each layer @@ -262,7 +116,7 @@ public List FindClustersOnTrack(List allClusters, StraightTrac for(int isector=0; isector FindClustersOnTrack(List allClusters, StraightTrac double doca = Double.POSITIVE_INFINITY; // loop over all clusters in the same sector and layer that are not associated to s track for(Cluster cls : allClusters) { - if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { + if(cls.getAssociatedTrackID()==-1 && cls.getSector()==sector && cls.getLayer()==layer) { double clsDoca = cls.residual(traj); cls.setTrakInters(traj); // save the ones that have better doca - if(Math.abs(clsDoca) FindClustersOnTrack(List allClusters, StraightTrac // if any lost cluster with doca better than the seed is found, save it for(Entry entry : clusterMap.entrySet()) { - if(entry.getValue().get_AssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); + if(entry.getValue().getAssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); } return clustersOnTrack; } - public List FindClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, Swim swimmer) { + public List findClustersOnTrk(List allClusters, List seedCluster, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; Point3D vertex = helix.getVertex(); swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, - Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), + Math.toDegrees(helix.getPhiAtDCA()), Math.toDegrees(Math.acos(helix.cosTheta())), P, Q, maxPathLength) ; double[] inters = null; // load SVT clusters that are in the seed Map clusterMap = new HashMap<>(); for(Cluster cluster : seedCluster) { - if(cluster.get_Detector() == DetectorType.BMT) + if(cluster.getDetector() == DetectorType.BMT) continue; - clusterMap.put(SVTGeometry.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); + clusterMap.put(SVTGeometry.getModuleId(cluster.getLayer(), cluster.getSector()), cluster); } // for each layer @@ -322,7 +176,7 @@ public List FindClustersOnTrk(List allClusters, List int layer = ilayer + 1; // identify the sector the track may be going through (this doesn't account for misalignments - Point3D helixPoint = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(layer)); + Point3D helixPoint = helix.getPointAtRadius(SVTGeometry.getLayerRadius(layer)); // reinitilize swimmer from last surface if(inters!=null) { @@ -358,11 +212,11 @@ public List FindClustersOnTrk(List allClusters, List //} // loop over all clusters in the same sector and layer that are noy associated to s track for(Cluster cls : allClusters) { - if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { + if(cls.getAssociatedTrackID()==-1 && cls.getSector()==sector && cls.getLayer()==layer) { double clsDoca = cls.residual(traj); // save the ones that have better doca - if(Math.abs(clsDoca) FindClustersOnTrk(List allClusters, List // if any lost cluster with doca better than the seed is found, save it List clustersOnTrack = new ArrayList<>(); for(Entry entry : clusterMap.entrySet()) { - if(entry.getValue().get_AssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); + if(entry.getValue().getAssociatedTrackID()==-1) clustersOnTrack.add(entry.getValue()); } return clustersOnTrack; } + public List findBMTClustersOnTrk(List allClusters, List seedCrosses, Helix helix, double P, int Q, Swim swimmer) { // initialize swimmer starting from the track vertex double maxPathLength = 1; Point3D vertex = helix.getVertex(); swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, - Math.toDegrees(helix.get_phi_at_dca()), Math.toDegrees(Math.acos(helix.costheta())), + Math.toDegrees(helix.getPhiAtDCA()), Math.toDegrees(Math.acos(helix.cosTheta())), P, Q, maxPathLength) ; double[] inters = null; // load SVT clusters that are in the seed Map clusterMap = new HashMap<>(); for(Cross cross : seedCrosses) { - if(cross.get_Detector() != DetectorType.BMT) + if(cross.getDetector() != DetectorType.BMT) continue; - Cluster cluster = cross.get_Cluster1(); - cluster.set_AssociatedTrackID(0); - clusterMap.put(Constants.BMTGEOMETRY.getModuleId(cluster.get_Layer(), cluster.get_Sector()), cluster); + Cluster cluster = cross.getCluster1(); + cluster.setAssociatedTrackID(0); + clusterMap.put(BMTGeometry.getModuleId(cluster.getLayer(), cluster.getSector()), cluster); } // for each layer @@ -436,11 +291,11 @@ public List findBMTClustersOnTrk(List allClusters, List double doca = Double.POSITIVE_INFINITY; // loop over all clusters in the same sector and layer that are not associated to s track for(Cluster cls : allClusters) { - if(cls.get_AssociatedTrackID()==-1 && cls.get_Sector()==sector && cls.get_Layer()==layer) { + if(cls.getAssociatedTrackID()==-1 && cls.getSector()==sector && cls.getLayer()==layer) { double clsDoca = cls.residual(traj); // save the ones that have better doca - if(Math.abs(clsDoca) findBMTClustersOnTrk(List allClusters, List // if any lost cluster with doca better than the seed is found, save it List clustersOnTrack = new ArrayList<>(); for(Entry entry : clusterMap.entrySet()) { - if(entry.getValue().get_AssociatedTrackID()==-1 && entry.getValue().flagForExclusion) clustersOnTrack.add(entry.getValue()); + if(entry.getValue().getAssociatedTrackID()==-1 && entry.getValue().flagForExclusion) clustersOnTrack.add(entry.getValue()); } return clustersOnTrack; } @@ -471,133 +326,62 @@ List findCrossesOnBMTTrack(List bmtclsOnTrack, CrossMaker cm, in return BMTCrosses; } - public void MatchTrack2Traj(Seed trkcand, Map traj) { - for (int i = 0; i < trkcand.get_Clusters().size(); i++) { //SVT - if(trkcand.get_Clusters().get(i).get_Detector()==DetectorType.BST) { - Cluster cluster = trkcand.get_Clusters().get(i); - int layer = trkcand.get_Clusters().get(i).get_Layer(); - int sector = trkcand.get_Clusters().get(i).get_Sector(); + for (int i = 0; i < trkcand.getClusters().size(); i++) { //SVT + if(trkcand.getClusters().get(i).getDetector()==DetectorType.BST) { + Cluster cluster = trkcand.getClusters().get(i); + int layer = trkcand.getClusters().get(i).getLayer(); + int sector = trkcand.getClusters().get(i).getSector(); Point3D p = new Point3D(traj.get(layer).x, traj.get(layer).y, traj.get(layer).z); - cluster.set_CentroidResidual(traj.get(layer).resi); - cluster.set_SeedResidual(p); + cluster.setCentroidResidual(traj.get(layer).resi); + cluster.setSeedResidual(p); for (Hit hit : cluster) { double doca1 = hit.residual(p); - double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), traj.get(layer).z); - hit.set_stripResolutionAtDoca(sigma1); - hit.set_docaToTrk(doca1); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, hit.getStrip().getStrip(), traj.get(layer).z); + hit.setstripResolutionAtDoca(sigma1); + hit.setdocaToTrk(doca1); if(traj.get(layer).isMeasUsed) - hit.set_TrkgStatus(1); + hit.setTrkgStatus(1); } } } // adding the cross infos - for (int c = 0; c < trkcand.get_Crosses().size(); c++) { - if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BST) { - int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer(); + for (int c = 0; c < trkcand.getCrosses().size(); c++) { + if (trkcand.getCrosses().get(c).getDetector()==DetectorType.BST) { + int layer = trkcand.getCrosses().get(c).getCluster1().getLayer(); Vector3D d = new Vector3D(traj.get(layer).px, traj.get(layer).py, traj.get(layer).pz).asUnit(); - trkcand.get_Crosses().get(c).updateSVTCross(d); + trkcand.getCrosses().get(c).updateSVTCross(d); } - if (trkcand.get_Crosses().get(c).get_Detector()==DetectorType.BMT) { + if (trkcand.getCrosses().get(c).getDetector()==DetectorType.BMT) { // update cross position - int layer = trkcand.get_Crosses().get(c).get_Cluster1().get_Layer()+6; + int layer = trkcand.getCrosses().get(c).getCluster1().getLayer()+6; Point3D p = new Point3D(traj.get(layer).x, traj.get(layer).y, traj.get(layer).z); Vector3D v = new Vector3D(traj.get(layer).px, traj.get(layer).py, traj.get(layer).pz).asUnit(); - trkcand.get_Crosses().get(c).updateBMTCross(p, v); - trkcand.get_Crosses().get(c).set_Dir(v); - Cluster cluster = trkcand.get_Crosses().get(c).get_Cluster1(); - if (trkcand.get_Crosses().get(c).get_Type()==BMTType.Z) { - cluster.set_CentroidResidual(traj.get(layer).resi*cluster.getTile().baseArc().radius()); + trkcand.getCrosses().get(c).updateBMTCross(p, v); + trkcand.getCrosses().get(c).setDir(v); + Cluster cluster = trkcand.getCrosses().get(c).getCluster1(); + if (trkcand.getCrosses().get(c).getType()==BMTType.Z) { + cluster.setCentroidResidual(traj.get(layer).resi*cluster.getTile().baseArc().radius()); } - else if (trkcand.get_Crosses().get(c).get_Type()==BMTType.C) { - cluster.set_CentroidResidual(traj.get(layer).resi); - cluster.set_SeedResidual(p); + else if (trkcand.getCrosses().get(c).getType()==BMTType.C) { + cluster.setCentroidResidual(traj.get(layer).resi); + cluster.setSeedResidual(p); } for (Hit hit : cluster) { - hit.set_docaToTrk(hit.residual(p)); - if(traj.get(layer).isMeasUsed) hit.set_TrkgStatus(1); + hit.setdocaToTrk(hit.residual(p)); + if(traj.get(layer).isMeasUsed) hit.setTrkgStatus(1); } } } } -// public Track OutputTrack(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { -// org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), -// kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), -// kf.KFHelix.getTanL(), kf.KFHelix.getXb(), kf.KFHelix.getYb()); -// helix.B = kf.KFHelix.getB(); -// Track cand = new Track(helix); -// cand.setNDF(kf.NDF); -// cand.setChi2(kf.chi2); -// -// for (Cross c : seed.get_Crosses()) { -// if (c.get_Detector()==DetectorType.BST) { -// continue; -// } -// } -// -// this.MatchTrack2Traj(seed, kf.TrjPoints); -// cand.addAll(seed.get_Crosses()); -// for(Cluster cl : seed.get_Clusters()) { -// -// int layer = cl.get_Layer(); -// int sector = cl.get_Sector(); -// -// if(cl.get_Detector()==DetectorType.BMT) { -// -// layer = layer + 6; -// -// if(cl.get_Type() == BMTType.C) { -// -// Line3D cln = cl.getAxis(); -// cl.setN(cln.distance(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)).direction().asUnit()); -// cl.setL(cl.getS().cross(cl.getN()).asUnit()); -// -// } -// -// } -// //double x = kf.TrjPoints.get(layer).x; -// //double y = kf.TrjPoints.get(layer).y; -// //double z = kf.TrjPoints.get(layer).z; -// //double px = kf.TrjPoints.get(layer).px; -// //double py = kf.TrjPoints.get(layer).py; -// //double pz = kf.TrjPoints.get(layer).pz; -// cl.setTrakInters(new Point3D(kf.TrjPoints.get(layer).x,kf.TrjPoints.get(layer).y,kf.TrjPoints.get(layer).z)); -// } -// -// return cand; -// -// } -// public Track OutputTrack(StraightTrack seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { -// org.jlab.rec.cvt.trajectory.Helix helix = new org.jlab.rec.cvt.trajectory.Helix(kf.KFHelix.getD0(), -// kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), -// kf.KFHelix.getZ0(), kf.KFHelix.getTanL()); -// helix.B = kf.KFHelix.getB(); -// Track cand = new Track(helix); -// cand.setNDF(kf.NDF); -// cand.setChi2(kf.chi2); -// cand.addAll(seed); -// -// return cand; -// -// } -// public Track OutputTrack(Seed seed) { -// -// Track cand = new Track(seed.get_Helix()); -// for (Cross c : seed.get_Crosses()) { -// if (c.get_Detector()==DetectorType.BST) { -// continue; -// } -// } -// cand.addAll(seed.get_Crosses()); -// return cand; -// -// } public List reFit(List seedlist, Swim swimmer, StraightTrackSeeder trseed) { - List filtlist = new ArrayList(); + List filtlist = new ArrayList<>(); if(seedlist==null) return filtlist; for (Seed bseed : seedlist) { @@ -613,13 +397,12 @@ public List reFit(List seedlist, Swim swimmer, StraightTrackSeeder public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { - List seedlist = new ArrayList(); - List refib = new ArrayList(); - List refi = new ArrayList(); - for(Cross c : bseed.get_Crosses()) { + List refib = new ArrayList<>(); + List refi = new ArrayList<>(); + for(Cross c : bseed.getCrosses()) { int layr = 0; int layr2 = 0; - if(c.get_Detector()==DetectorType.BMT) { + if(c.getDetector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; @@ -627,8 +410,8 @@ public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { refib.add(c); } } else { - layr = c.get_Cluster1().get_Layer(); - layr2 = c.get_Cluster2().get_Layer(); + layr = c.getCluster1().getLayer(); + layr2 = c.getCluster2().getLayer(); if((int)Constants.getUsedLayers().get(layr)>0 && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); @@ -638,9 +421,10 @@ public List reFitSeed(Seed bseed, StraightTrackSeeder trseed) { } } Collections.sort(refi); - seedlist.addAll(trseed.findSeed(refi, refib, false)); + List seedlist = trseed.findSeed(refi, refib, false); return seedlist; } + public boolean reFitCircle(Seed seed, int iter, double xb, double yb) { boolean fitStatus = false; @@ -653,16 +437,16 @@ public boolean reFitCircle(Seed seed, int iter, double xb, double yb) { Xs.clear(); Ys.clear(); Ws.clear(); - List seedCrosses = seed.get_Crosses(); + List seedCrosses = seed.getCrosses(); for (int j = 0; j < seedCrosses.size(); j++) { - if (seedCrosses.get(j).get_Type() == BMTType.C) + if (seedCrosses.get(j).getType() == BMTType.C) continue; - Xs.add(seedCrosses.get(j).get_Point().x()); - Ys.add(seedCrosses.get(j).get_Point().y()); - Ws.add(1. / (seedCrosses.get(j).get_PointErr().x()*seedCrosses.get(j).get_PointErr().x() - +seedCrosses.get(j).get_PointErr().y()*seedCrosses.get(j).get_PointErr().y())); + Xs.add(seedCrosses.get(j).getPoint().x()); + Ys.add(seedCrosses.get(j).getPoint().y()); + Ws.add(1. / (seedCrosses.get(j).getPointErr().x()*seedCrosses.get(j).getPointErr().x() + +seedCrosses.get(j).getPointErr().y()*seedCrosses.get(j).getPointErr().y())); } @@ -670,19 +454,21 @@ public boolean reFitCircle(Seed seed, int iter, double xb, double yb) { if(fitStatus) { CircleFitPars pars = circlefit.getFit(); - seed.get_Helix().set_curvature(pars.rho()); - seed.get_Helix().set_dca(-pars.doca()); - seed.get_Helix().set_phi_at_dca(pars.phi()); + seed.getHelix().setCurvature(pars.rho()); + seed.getHelix().setDCA(-pars.doca()); + seed.getHelix().setPhiAtDCA(pars.phi()); seed.update_Crosses(); } } return fitStatus; } + //RDV: to be checked: causes track crosses to be overwritten + @Deprecated public List reFit(List seedlist, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2, double xb, double yb) { trseed = new TrackSeederCA(swimmer, xb, yb); trseed2 = new TrackSeeder(swimmer, xb, yb); - List filtlist = new ArrayList(); + List filtlist = new ArrayList<>(); if(seedlist==null) return filtlist; for (Seed bseed : seedlist) { @@ -695,25 +481,25 @@ public List reFit(List seedlist, Swim swimmer, TrackSeederCA trseed } return filtlist; } + public List reFitSeed(Seed bseed, Swim swimmer, TrackSeederCA trseed, TrackSeeder trseed2) { boolean pass = true; - List seedlist = new ArrayList(); - List refib = new ArrayList(); - List refi = new ArrayList(); - for(Cross c : bseed.get_Crosses()) { + List refib = new ArrayList<>(); + List refi = new ArrayList<>(); + for(Cross c : bseed.getCrosses()) { int layr = 0; int layr2 = 0; - c.set_AssociatedTrackID(-1); - if(c.get_Detector()==DetectorType.BMT) { + c.setAssociatedTrackID(-1); + if(c.getDetector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; refib.add(c); } } else { - layr = c.get_Cluster1().get_Layer(); - layr2 = c.get_Cluster2().get_Layer(); + layr = c.getCluster1().getLayer(); + layr2 = c.getCluster2().getLayer(); if((int)Constants.getUsedLayers().get(layr)>0 && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); @@ -724,7 +510,7 @@ public List reFitSeed(Seed bseed, Swim swimmer, TrackSeederCA trseed, Tr } } Collections.sort(refi); - seedlist = trseed.findSeed(refi, refib); + List seedlist = trseed.findSeed(refi, refib); trseed2.unUsedHitsOnly = true; seedlist.addAll( trseed2.findSeed(refi, refib)); @@ -732,10 +518,10 @@ public List reFitSeed(Seed bseed, Swim swimmer, TrackSeederCA trseed, Tr return seedlist; } - public List reFit(List seedlist, CosmicFitter fitTrk, TrackCandListFinder trkfindr) { + public List reFit(List seedlist, CosmicFitter fitTrk, StraightTrackCandListFinder trkfindr) { fitTrk = new CosmicFitter(); - trkfindr = new TrackCandListFinder(); - List filtlist = new ArrayList(); + trkfindr = new StraightTrackCandListFinder(); + List filtlist = new ArrayList<>(); if(seedlist==null) return filtlist; for (StraightTrack bseed : seedlist) { @@ -750,16 +536,16 @@ public List reFit(List seedlist, CosmicFitter fitT } - public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,TrackCandListFinder trkfindr) { + public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,StraightTrackCandListFinder trkfindr) { boolean pass = true; - List seedlist = new ArrayList(); - List refib = new ArrayList(); - List refi = new ArrayList(); + List seedlist = new ArrayList<>(); + List refib = new ArrayList<>(); + List refi = new ArrayList<>(); for(Cross c : cand) { int layr = 0; int layr2 = 0; - if(c.get_Detector()==DetectorType.BMT) { + if(c.getDetector()==DetectorType.BMT) { layr = c.getOrderedRegion()+3; if((int)Constants.getUsedLayers().get(layr)>0) { c.isInSeed = false; @@ -767,8 +553,8 @@ public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,Tra refib.add(c); } } else { - layr = c.get_Cluster1().get_Layer(); - layr2 = c.get_Cluster2().get_Layer(); + layr = c.getCluster1().getLayer(); + layr2 = c.getCluster2().getLayer(); if((int)Constants.getUsedLayers().get(layr)>0 && (int)Constants.getUsedLayers().get(layr2)>0) { c.updateSVTCross(null); @@ -779,20 +565,20 @@ public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,Tra } } if(refi.size()>=3) { - TrackCandListFinder.RayMeasurements NewMeasArrays = trkfindr. - get_RayMeasurementsArrays((ArrayList) refi, false, false, true); + StraightTrackCandListFinder.RayMeasurements NewMeasArrays = trkfindr. + getRayMeasurementsArrays((ArrayList) refi, false, false, true); fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); - if(fitTrk.get_ray()!=null) { - cand = new StraightTrack(fitTrk.get_ray()); + if(fitTrk.getray()!=null) { + cand = new StraightTrack(fitTrk.getray()); cand.addAll(refi); //refit with the SVT included to determine the z profile NewMeasArrays = trkfindr. - get_RayMeasurementsArrays((ArrayList) refi, false, false, false); + getRayMeasurementsArrays((ArrayList) refi, false, false, false); fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); - cand = new StraightTrack(fitTrk.get_ray()); + cand = new StraightTrack(fitTrk.getray()); cand.addAll(refi); seedlist.add(cand); } @@ -800,7 +586,7 @@ public List reFitSeed(StraightTrack cand, CosmicFitter fitTrk,Tra return seedlist; } - public double[] MCtrackPars(DataEvent event) { + public double[] mcTrackPars(DataEvent event) { double[] value = new double[6]; if (event.hasBank("MC::Particle") == false) { return value; @@ -821,7 +607,7 @@ public double[] MCtrackPars(DataEvent event) { public double[][] getCovMatInTrackRep(Track trk) { double[][] tCov = new double[6][6]; - double [][] hCov = trk.get_helix().get_covmatrix(); + double [][] hCov = trk.getHelix().getCovMatrix(); //error matrix (assuming that the circle fit and line fit parameters are uncorrelated) // | d_dca*d_dca d_dca*d_phi_at_dca d_dca*d_curvature 0 0 | @@ -832,13 +618,13 @@ public double[][] getCovMatInTrackRep(Track trk) { // - double pt = trk.get_Pt(); - double rho = trk.get_helix().get_curvature(); + double pt = trk.getPt(); + double rho = trk.getHelix().getCurvature(); double c = Constants.LIGHTVEL; - double Bz = pt/(c*trk.get_helix().radius()); - double d0 = trk.get_helix().get_dca(); - double phi0 = trk.get_helix().get_phi_at_dca(); - double tandip = trk.get_helix().get_tandip(); + double Bz = pt/(c*trk.getHelix().radius()); + double d0 = trk.getHelix().getDCA(); + double phi0 = trk.getHelix().getPhiAtDCA(); + double tandip = trk.getHelix().getTanDip(); double delxdeld0 = -Math.sin(phi0); double delxdelphi0 = -d0*Math.cos(phi0); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 30226e87a..fb91df5bb 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -16,7 +16,7 @@ import org.jlab.rec.cvt.cross.CrossMaker; import org.jlab.rec.cvt.cross.StraightTrackCrossListFinder; import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.track.Measurements; +import org.jlab.rec.cvt.measurement.Measurements; import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.StraightTrackSeeder; import org.jlab.rec.cvt.track.Track; @@ -48,13 +48,13 @@ public boolean processEvent(DataEvent event, List seeds = null; if(solenoidValue<0.001) { StraightTrackSeeder trseed = new StraightTrackSeeder(xb, yb); - seeds = trseed.findSeed(crosses.get(0), crosses.get(1), Constants.SVTOnly); + seeds = trseed.findSeed(crosses.get(0), crosses.get(1), Constants.SVTONLY); // RDV, disabled because it seems to create fake tracks, skipping measurement in KF // if(Constants.EXCLUDELAYERS==true) { // seeds = recUtil.reFit(seeds, swimmer, trseed); // RDV can we juts refit? // } } else { - if(Constants.SVTOnly) { + if(Constants.SVTONLY) { TrackSeeder trseed = new TrackSeeder(swimmer, xb, yb); trseed.unUsedHitsOnly = true; seeds = trseed.findSeed(crosses.get(0), null); @@ -63,7 +63,7 @@ public boolean processEvent(DataEvent event, seeds = trseed.findSeed(crosses.get(0), crosses.get(1)); //second seeding algorithm to search for SVT only tracks, and/or tracks missed by the CA - if(Constants.svtSeeding) { + if(Constants.SVTSEEDING) { TrackSeeder trseed2 = new TrackSeeder(swimmer, xb, yb); trseed2.unUsedHitsOnly = true; seeds.addAll( trseed2.findSeed(crosses.get(0), crosses.get(1))); @@ -99,15 +99,15 @@ public boolean processEvent(DataEvent event, } trkcands.clear(); - KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.kfMatLib); + KFitter kf = new KFitter(Constants.KFFILTERON, Constants.KFITERATIONS, Constants.kfBeamSpotConstraint(), swimmer, Constants.KFMATLIB); Measurements surfaces = new Measurements(false, xb, yb); for (Seed seed : seeds) { - Point3D v = seed.get_Helix().getVertex(); - Vector3D p = seed.get_Helix().getPXYZ(solenoidValue); - int charge = (int) (Math.signum(solenoidScale)*seed.get_Helix().get_charge()); + Point3D v = seed.getHelix().getVertex(); + Vector3D p = seed.getHelix().getPXYZ(solenoidValue); + int charge = (int) (Math.signum(solenoidScale)*seed.getHelix().getCharge()); if(solenoidValue<0.001) charge = 1; - double[] pars = recUtil.MCtrackPars(event); + double[] pars = recUtil.mcTrackPars(event); if(Constants.INITFROMMC) { v = new Point3D(pars[0],pars[1],pars[2]); p = new Vector3D(pars[3],pars[4],pars[5]); @@ -115,58 +115,55 @@ public boolean processEvent(DataEvent event, } Helix hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, solenoidValue, xb , yb, Helix.Units.MM); - double[][] cov = seed.get_Helix().get_covmatrix(); + double[][] cov = seed.getHelix().getCovMatrix(); - if(solenoidValue>0.001 && - Constants.LIGHTVEL * seed.get_Helix().radius() *solenoidValue0.001 && Constants.LIGHTVEL * seed.getHelix().radius() *solenoidValue0 && kf.KFHelix!=null) { - Track fittedTrack = new Track(seed, kf); - for(Cross c : fittedTrack) { - if(c.get_Detector()==DetectorType.BST) { - c.get_Cluster1().set_AssociatedTrackID(0); - c.get_Cluster2().set_AssociatedTrackID(0); - } + kf.init(hlx, cov, xb, yb, 0, surfaces.getMeasurements(seed)) ; + kf.runFitter(); + if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) { + Track fittedTrack = new Track(seed, kf); + for(Cross c : fittedTrack) { + if(c.getDetector()==DetectorType.BST) { + c.getCluster1().setAssociatedTrackID(0); + c.getCluster2().setAssociatedTrackID(0); } - //refit adding missing clusters - List clsOnTrack = recUtil.FindClustersOnTrk(SVTclusters, seed.get_Clusters(), fittedTrack.get_helix(), - fittedTrack.get_P(), fittedTrack.get_Q(), swimmer); //VZ: finds missing clusters - List bmtclsOnTrack = recUtil.findBMTClustersOnTrk(BMTclusters, seed.get_Crosses(), fittedTrack.get_helix(), - fittedTrack.get_P(), fittedTrack.get_Q(), swimmer); //VZ: finds missing clusters - CrossMaker cm = new CrossMaker(); - List bmtcrsOnTrack = recUtil.findCrossesOnBMTTrack(bmtclsOnTrack, cm, crosses.get(1).size()+2000); - - if(clsOnTrack.size()>0 || bmtcrsOnTrack.size()>0) { - //seed.add_Clusters(clsOnTrack); - if(clsOnTrack.size()>0) - seed.get_Clusters().addAll(clsOnTrack); //VZ check for additional clusters, and only then re-run KF adding new clusters - if(bmtcrsOnTrack.size()>0) { - seed.get_Crosses().addAll(bmtcrsOnTrack); //VZ check for additional crosses, and only then re-run KF adding new clusters - crosses.get(1).addAll(bmtcrsOnTrack); - for(Cross c : bmtcrsOnTrack) { - seed.get_Clusters().add(c.get_Cluster1()); - } - } - //reset pars -// fittedTrack.get_helix().set_dca(-fittedTrack.get_helix().get_dca()); // RDV check - v = fittedTrack.get_helix().getVertex(); - p = fittedTrack.get_helix().getPXYZ(solenoidValue); - charge = (int) (Math.signum(solenoidScale)*fittedTrack.get_helix().get_charge()); - if(solenoidValue<0.001) - charge = 1; - hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, - solenoidValue, xb, yb, Helix.Units.MM); + } + //refit adding missing clusters + List clsOnTrack = recUtil.findClustersOnTrk(SVTclusters, seed.getClusters(), fittedTrack.getHelix(), + fittedTrack.getP(), fittedTrack.getQ(), swimmer); //VZ: finds missing clusters + List bmtclsOnTrack = recUtil.findBMTClustersOnTrk(BMTclusters, seed.getCrosses(), fittedTrack.getHelix(), + fittedTrack.getP(), fittedTrack.getQ(), swimmer); //VZ: finds missing clusters + CrossMaker cm = new CrossMaker(); + List bmtcrsOnTrack = recUtil.findCrossesOnBMTTrack(bmtclsOnTrack, cm, crosses.get(1).size()+2000); - kf.init(hlx, cov, xb, yb, 0, surfaces.getMeasurements(seed)) ; - kf.runFitter(); - - // RDV get rid of added clusters if not true - if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) - fittedTrack = new Track(seed, kf); + if(clsOnTrack.size()>0 || bmtcrsOnTrack.size()>0) { + if(clsOnTrack.size()>0) + seed.getClusters().addAll(clsOnTrack); //VZ check for additional clusters, and only then re-run KF adding new clusters + if(bmtcrsOnTrack.size()>0) { + seed.getCrosses().addAll(bmtcrsOnTrack); //VZ check for additional crosses, and only then re-run KF adding new clusters + crosses.get(1).addAll(bmtcrsOnTrack); + for(Cross c : bmtcrsOnTrack) { + seed.getClusters().add(c.getCluster1()); + } } - trkcands.add(fittedTrack); + //reset pars + v = fittedTrack.getHelix().getVertex(); + p = fittedTrack.getHelix().getPXYZ(solenoidValue); + charge = (int) (Math.signum(solenoidScale)*fittedTrack.getHelix().getCharge()); + if(solenoidValue<0.001) + charge = 1; + hlx = new Helix(v.x(),v.y(),v.z(),p.x(),p.y(),p.z(), charge, + solenoidValue, xb, yb, Helix.Units.MM); + + kf.init(hlx, cov, xb, yb, 0, surfaces.getMeasurements(seed)) ; + kf.runFitter(); + + // RDV get rid of added clusters if not true + if (kf.setFitFailed == false && kf.NDF>0 && kf.KFHelix!=null) + fittedTrack = new Track(seed, kf); + } + trkcands.add(fittedTrack); } } @@ -174,14 +171,14 @@ public boolean processEvent(DataEvent event, // reset cross and cluster IDs for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } } for(Cluster c : SVTclusters) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } for(Cluster c : BMTclusters) { - c.set_AssociatedTrackID(-1); + c.setAssociatedTrackID(-1); } List tracks = null; @@ -194,7 +191,7 @@ public boolean processEvent(DataEvent event, // update crosses and clusters on track for(int it = 0; it < tracks.size(); it++) { int id = it + 1; - tracks.get(it).set_Id(id); + tracks.get(it).setId(id); tracks.get(it).update_Crosses(id); tracks.get(it).update_Clusters(id); tracks.get(it).setTrackCovMat(recUtil.getCovMatInTrackRep(tracks.get(it))); @@ -202,10 +199,10 @@ public boolean processEvent(DataEvent event, } for(int det = 0; det<2; det++) { for(Cross c : crosses.get(det)) { - if(c.get_AssociatedTrackID()==-1) { + if(c.getAssociatedTrackID()==-1) { c.reset(); - if(det==1 && c.get_Id()>2000) { //if matched cross failed tracking resol requirements, reset its id - c.set_Id(c.get_Id()-1000); + if(det==1 && c.getId()>2000) { //if matched cross failed tracking resol requirements, reset its id + c.setId(c.getId()-1000); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/package-info.java deleted file mode 100644 index a62aced99..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.services; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java index ea97b1829..7b1ef3bb1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTGeometry.java @@ -305,147 +305,6 @@ public int getSector(int layer, Point3D traj) { return Sect; } -// //*** -// public double[] getLocCoord(double s1, double s2) { //2 top, 1 bottom -// -// double[] X = new double[2]; -// double ialpha1 = (s1 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); -// //the active area starts at the first strip -// double interc1 = (s1 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; -// double ialpha2 = (s2 - 1) * SVTConstants.STEREOANGLE / (double) (SVTConstants.NSTRIPS - 1); -// //the active area starts at the first strip -// double interc2 = (s2 - 0.5) * SVTConstants.READOUTPITCH + SVTConstants.STRIPOFFSETWID; -// -// // Equation for strip line is x = mz + b [i.e. z is the direction of the length of the module] -// // ------------------------------------- -// double m1 = -Math.tan(ialpha1); -// double m2 = Math.tan(ialpha2); -// double b1 = SVTConstants.ACTIVESENWID - interc1; -// double b2 = interc2; -// -// double z = (b2 - b1) / (m1 - m2); -// double x = m1 * z + b1; -// X[0] = x; -// X[1] = z; -// -// return X; -// } -// -// public double[] getLocCoordErrs(int lay1, int lay2, double s1, double s2, double z) { -// double[] Xerr = new double[2]; -// -// double sigma1 = getSingleStripResolution(lay1, (int) s1, z); -// double sigma2 = getSingleStripResolution(lay2, (int) s2, z); -// -// Xerr[0] = Math.sqrt(sigma1 * sigma1 + sigma2 * sigma2); -// -// Xerr[1] = (getLocCoord(s1 - 0.5, s2 - 0.5)[1] -// - getLocCoord(s1 + 0.5, s2 + 0.5)[1]); -// -// if (s1 <= 1) { -// Xerr[1] = (getLocCoord(s1, s2 - 0.5)[1] -// - getLocCoord(s1 + 1.5, s2 + 0.5)[1]); -// } -// if (s2 <= 1) { -// Xerr[1] = (getLocCoord(s1 - 0.5, s2)[1] -// - getLocCoord(s1 + 1.5, s2 + 2.5)[1]); -// } -// -// return Xerr; -// -// } - - -// public double[] getCrossPars(int sector, int upperlayer, double s1, double s2, Vector3D trkDir) { -// -// double[] vals = new double[]{Double.NaN, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN}; -// -// // if first iteration trkDir == null -// double s2corr = s2; -// // now use track info -// s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, SVTConstants.MODULELEN); -// double z = getLocCoord(s1, s2corr)[1]; -// //update using the corrected z -// s2corr = this.getCorrectedStrip(sector, upperlayer, s2, trkDir, z); -// double zf = getLocCoord(s1, s2corr)[1]; -// -// if (upperlayer % 2 != 0) // should not happen as is upper layer...but just in case -// { -// s2corr = s2; -// } -// -// double[] LC = getLocCoord(s1, s2corr); -// double[] LCErr = getLocCoordErrs(upperlayer - 1, upperlayer, s1, s2corr, zf); -// -// Point3D crPoint = this.toGlobal(upperlayer-1, sector, new Point3D(LC[0], 0, LC[1])); -// Vector3D crErr = this.toGlobal(upperlayer-1, sector, new Vector3D(LCErr[0], 0, LCErr[1])); -// -// double LCErr_x = LCErr[0]; -// double LCErr_z = LCErr[1]; -// -// // global rotation angle to get the error in the local frame -// int[] rm = SVTConstants.convertLayer2RegionModule(upperlayer-1); -// -// // global rotation angle -// double Glob_rangl = ((double) -(sector - 1) / (double) SVTConstants.NSECTORS[rm[0]]) -// * 2. * Math.PI + SVTConstants.PHI0; -// // angle to rotate to global frame -// double LOCZAXISROTATION = -Math.toRadians(90.); -// double Loc_to_Glob_rangl = Glob_rangl - LOCZAXISROTATION; -// -// double cosRotation = Math.cos(Loc_to_Glob_rangl); -// double sinRotation = Math.sin(Loc_to_Glob_rangl); -// -// double yerr = Math.abs(cosRotation * LCErr_x); -// double xerr = Math.abs(sinRotation * LCErr_x); -// -// // RDV: check because old errors seems to be rotated by 90 deg -//// System.out.println("Cross:\n" + xerr + " " + yerr + " " + LCErr_z); -//// System.out.println(crErr.toString()); -//// System.out.println(crPoint.toString()); -// -// if (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL * 2) { -// return vals; -// } -// // once there is a trk, the cross should be well calculated -// //if the local cross is not in the fiducial volume it is not physical -// else if ((trkDir != null && (LC[0] < -SVTConstants.SIDETOL || LC[0] > SVTConstants.ACTIVESENWID + SVTConstants.SIDETOL)) -// || (trkDir != null && (LC[1] < -SVTConstants.LENGTHTOL || LC[1] > SVTConstants.MODULELEN + SVTConstants.LENGTHTOL))) { -// return vals; -// } -// else { -// vals[0] = crPoint.x(); -// vals[1] = crPoint.y(); -// vals[2] = crPoint.z(); -// vals[3] = Math.abs(crErr.x()); -// vals[4] = Math.abs(crErr.y()); -// vals[5] = Math.abs(crErr.z()); -// } -// -// return vals; -// -// } - -// private double getCorrectedStrip(int sector, int upperlayer, double s2, Vector3D trkDir, double ZalongModule) { -// double s2corr = s2; -// // second iteration: there is a track direction -// if (trkDir != null) { -// double stripCorr = getStripIndexShift(sector, upperlayer, trkDir, s2, ZalongModule); -// if (s2 > 1) { -// s2corr = s2 + stripCorr; -// } -// if (s2 == 1) { -// if (stripCorr >= 0) { -// s2corr = s2 + stripCorr; -// } -// if (stripCorr < 0) { -// s2corr = s2; -// } -// } -// } -// return s2corr; -// } - public int calcNearestStrip(double X, double Y, double Z, int layer, int sect) { Point3D LocPoint = this.toLocal(layer, sect, new Point3D(X,Y,Z)); @@ -597,46 +456,6 @@ public double getXAtZ(int layer, double centroidstrip, double Z) { return X; } - //*** -// public double getStripIndexShift(int sector, int layer, Vector3D trkDir, double s2, double z) { -// -// double tx = trkDir.x(); -// double ty = trkDir.y(); -// Vector3D trkDir_t = new Vector3D(tx,ty,0); -// trkDir_t.unit(); -// Vector3D n = this.getNormal(layer, sector); -// -// if (Math.acos(n.dot(trkDir_t)) > Math.PI / 2) { // flip track dir for y<0 for cosmics: -// trkDir_t.negative(); -// } -// -// double TrkToPlnNormRelatAngl = Math.acos(n.dot(trkDir_t)); -// double sign = Math.signum(n.cross(trkDir_t).z()); -// -// //correction to the pitch to take into account the grading of the angle -- get the upper or lower strip depending on the trkdir -// double pitchcorr = SVTConstants.READOUTPITCH; -// -// if (s2 > 2 && s2 < 255) { -// double pitchToNextStrp = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); -// double pitchToPrevStrp = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); -// pitchcorr = (pitchToNextStrp + pitchToPrevStrp) / 2.; -// } -// if (s2 <= 2) { -// pitchcorr = Math.abs(getXAtZ(layer, (double) s2 + 1, z) - getXAtZ(layer, (double) s2, z)); -// } -// if (s2 == 256) { -// pitchcorr = Math.abs(getXAtZ(layer, (double) s2 - 1, z) - getXAtZ(layer, (double) s2, z)); -// } -// -// double layerGap = SVTConstants.LAYERRADIUS[0][1] // MODULERADIUS[1][0] = 65.447 + LAYRGAP + MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][1] -// - SVTConstants.LAYERRADIUS[0][0]; // MODULERADIUS[0][0] = 65.447 - MODULEPOSFAC * SILICONTHICK = SVTConstants.LAYERRADIUS[0][0] -// -// double shift = sign * layerGap * Math.tan(TrkToPlnNormRelatAngl) / pitchcorr; -// -// return -shift; -// } - //*** - public boolean isInFiducial(int layer, int sector, Point3D traj) { Point3D local = this.toLocal(layer, sector, traj); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java index d28946d0f..517df7c3c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/SVTParameters.java @@ -18,8 +18,8 @@ public class SVTParameters { public static double RESIMAX = 5; // THRESHOLDS - public static int initThresholds = 30; - public static int deltaThresholds = 15; + public static int INITTHRESHOLD = 30; + public static int DELTATHRESHOLD = 15; // RECONSTRUCTION CONSTANTS public static double ETOTCUT = 10.0; @@ -30,17 +30,17 @@ public class SVTParameters { public static final double MINRADCURV = 200.00; //in cm // sum of strip numbers for valid intersection: - //public static int sumStpNumMin = 174; - //public static int sumStpNumMax = 259; - public static int sumStpNumMin = 70; - public static int sumStpNumMax = 350; + //public static int MINSTRIPSUM = 174; + //public static int MAXSTRIPSUM = 259; + public static int MINSTRIPSUM = 70; + public static int MAXSTRIPSUM = 350; // contants for dEdx //------------------ //public static double rho = 2.3296; // g/cm^3 (Si) - static double CaThick = 0.5; - static double RohacellThick = 2.5; - static double Z_eff_roha = Math.pow((7.84 / 100.) * Math.pow(1, 2.94) + (64.5 / 100.) * Math.pow(6, 2.94) + (8.38 / 100.) * Math.pow(7, 2.94) + (19.12 / 100.) * Math.pow(8, 2.94), (1. / 2.94)); + private static final double CaThick = 0.5; + private static final double RohacellThick = 2.5; + private static final double Z_eff_roha = Math.pow((7.84 / 100.) * Math.pow(1, 2.94) + (64.5 / 100.) * Math.pow(6, 2.94) + (8.38 / 100.) * Math.pow(7, 2.94) + (19.12 / 100.) * Math.pow(8, 2.94), (1. / 2.94)); // empirical scaling factor from MC public static double detMatZ_ov_A_timesThickn = (14. * 2 * SVTConstants.SILICONTHK / 28.0855 + (Z_eff_roha * RohacellThick / 12.0588) + 6 * CaThick / 12.0107); @@ -49,11 +49,11 @@ public class SVTParameters { // public static int BSTidCode = 1; // ----- cut based cand select - public static double phi12cut = 35.; - public static double phi13cut = 35.; - public static double phi14cut = 35.; - public static double radcut = 100.; - public static double dzdrcut = 200.;// used to be 150 + public static double PHI12CUT = 35.; + public static double PHI13CUT = 35.; + public static double PHI14CUT = 35.; + public static double RADCUT = 100.; + public static double DZDRCUT = 200.;// used to be 150 //BST misalignments // public static boolean isRadialMisalignmentTest = false; @@ -71,14 +71,11 @@ public class SVTParameters { public static int EMAXREADOUT = 1; // track list cut-off - public static int maxNcands = 200; - public static boolean hasWidthResolution = false; + public static int MAXNCANDS = 200; - public static boolean ignoreErr = false; + public static boolean IGNOREERR = false; - public static boolean removeClones = true; - -// public static final double MODULEPOSFAC = 0.5; // % wrt top of module + public static boolean REMOVECLONES = true; public static final double PIDCUTOFF = 2.6; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/package-info.java deleted file mode 100644 index 68753da87..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/svt/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.svt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java index 7e8be693b..09c028691 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Cell.java @@ -1,4 +1,5 @@ package org.jlab.rec.cvt.track; + import org.jlab.rec.cvt.cross.Cross; import org.jlab.geom.prim.Vector3D; import java.util.*; @@ -8,180 +9,187 @@ import org.jlab.rec.cvt.Constants; /** - * Base cell for the cellular automaton - * A cell is defined by two crosses and its state + * Base cell for the cellular automaton A cell is defined by two crosses and its + * state * * @author fbossu * */ - public class Cell implements Comparable { - private Cross _c1; // first terminal of the cell - private Cross _c2; // last terminal of the cell - private Vector3D _dir; // direction of the cell - private int _state; // state of the cell - private String _plane; // plane can be XY or ZR - private ArrayList nb; // list of neighbor cells - private boolean _used; // has it been used in candidates? - public Cell(){} - - public Cell( Cross a, Cross b ){ - this._c1 = a; - this._c2 = b; - this._dir = a.get_Point().vectorTo(b.get_Point()); - this.nb = new ArrayList(); - this._state = 1; - this._used = false; - } - - public Cell( Cross a, Cross b, String plane ){ - this._c1 = a; - this._c2 = b; - this._dir = a.get_Point().vectorTo(b.get_Point()); - this.nb = new ArrayList(); - this._state = 1; - this._plane = plane; - this._used = false; - } - - @Override - public int compareTo(Cell arg0) { - - return compare( this, arg0 ); - } - - public int compare( Cell c, Cell k ){ - if( c.get_state() == k.get_state()) return 0; - if( c.get_state() < k.get_state() ) return 1; - else return -1; - } - - public double get_length(){ - return this._c1.get_Point().vectorTo(this._c2.get_Point()).mag(); - } - - public Point2d get_Crs2D( int i ){ - return this.get_Crs2D( i, this._plane ); - } - public Point2d get_Crs2D( int i, String vw ){ - if( i < 1 || i > 2){ - System.err.println("ERROR, please select 1 or 2 for the first or second cross"); - return null; - } - Cross cross; - if( i == 1) cross = this._c1; - else cross = this._c2; - - Point2d point = new Point2d(); - if( vw.equalsIgnoreCase("XY")){ - point.set( cross.get_Point().x(), cross.get_Point().y() ); - } - if( vw.equalsIgnoreCase("ZR")){ - point.set( cross.get_Point().z()-Constants.getZoffset(), cross.getRadius() ); - } - return point; - } - - - public Vector2d get_dir2D(){ - return this.get_dir2D(this._plane); - } - public Vector2d get_dir2D(String vw){ - if( vw.equalsIgnoreCase("ZR") ){ - Point2d p1 = get_Crs2D(1, "ZR"); - Vector2d v1 = new Vector2d( p1.x, p1.y); - Point2d p2 = get_Crs2D(2, "ZR"); - Vector2d v2 = new Vector2d( p2.x, p2.y); - - v2.sub(v1); - return v2 ; - } - else if( vw.equalsIgnoreCase("XY") ){ - Vector2d v = new Vector2d(this._dir.x(),this._dir.y()); - v.normalize(); - return v; - } - else { return null; } - } - - @Override - public String toString(){ -// String tmp = (this.nb.size()>0) ? this.nb.get(0) + " " + this.nb.get(nb.size()-1) : ""; - return "c1_Id "+this._c1.get_Id() + " "+this._c1.get_Detector() - +", c2_Id "+this._c2.get_Id() + " "+this._c2.get_Detector() - +", state "+this._state - +", nb "+this.nb.size()+ ", plane " + this._plane + " " ; - } - - public boolean equals( Cell c ){ - if( c.get_c1() == this._c1 && c.get_c2() == this._c2 ) return true; - return false; - } - - public boolean contains( Cross x ){ - if( x.equals(this._c1) || x.equals(this._c2) ) return true; - return false; - } - - public void addNeighbour( Cell b ){ - if( nb == null ){ - this.nb = new ArrayList(); - } - this.nb.add(b); - } - - public List get_neighbors(){ - return this.nb; - } - - public Cross get_c1() { - return _c1; - } - - public void set_c1(Cross _c1) { - this._c1 = _c1; - } - - public Cross get_c2() { - return _c2; - } - - public void set_c2(Cross _c2) { - this._c2 = _c2; - } - - public Vector3D get_dir() { - return _dir; - } - - public void set_dir(Vector3D dir) { - this._dir = dir; - } - - public int get_state() { - return _state; - } - - public void set_state(int _state) { - this._state = _state; - } - - public String get_plane() { - return _plane; - } - - public void set_plane(String _plane) { - this._plane = _plane; - } - - public boolean is_used() { - return _used; - } - - public void set_used(boolean _used) { - this._used = _used; - } - + private Cross _c1; // first terminal of the cell + private Cross _c2; // last terminal of the cell + private Vector3D _dir; // direction of the cell + private int _state; // state of the cell + private String _plane; // plane can be XY or ZR + private ArrayList nb; // list of neighbor cells + private boolean _used; // has it been used in candidates? + + public Cell() { + } + + public Cell(Cross a, Cross b) { + this._c1 = a; + this._c2 = b; + this._dir = a.getPoint().vectorTo(b.getPoint()); + this.nb = new ArrayList<>(); + this._state = 1; + this._used = false; + } + + public Cell(Cross a, Cross b, String plane) { + this._c1 = a; + this._c2 = b; + this._dir = a.getPoint().vectorTo(b.getPoint()); + this.nb = new ArrayList<>(); + this._state = 1; + this._plane = plane; + this._used = false; + } + + @Override + public int compareTo(Cell arg0) { + + return compare(this, arg0); + } + + public int compare(Cell c, Cell k) { + if (c.getState() == k.getState()) { + return 0; + } + if (c.getState() < k.getState()) { + return 1; + } else { + return -1; + } + } + + public double getLength() { + return this._c1.getPoint().vectorTo(this._c2.getPoint()).mag(); + } + + public Point2d getCrs2D(int i) { + return this.getCrs2D(i, this._plane); + } + + public Point2d getCrs2D(int i, String vw) { + if (i < 1 || i > 2) { + System.err.println("ERROR, please select 1 or 2 for the first or second cross"); + return null; + } + Cross cross; + if (i == 1) { + cross = this._c1; + } else { + cross = this._c2; + } + + Point2d point = new Point2d(); + if (vw.equalsIgnoreCase("XY")) { + point.set(cross.getPoint().x(), cross.getPoint().y()); + } + if (vw.equalsIgnoreCase("ZR")) { + point.set(cross.getPoint().z() - Constants.getZoffset(), cross.getRadius()); + } + return point; + } + + public Vector2d getDir2D() { + return this.getDir2D(this._plane); + } + + public Vector2d getDir2D(String vw) { + if (vw.equalsIgnoreCase("ZR")) { + Point2d p1 = getCrs2D(1, "ZR"); + Vector2d v1 = new Vector2d(p1.x, p1.y); + Point2d p2 = getCrs2D(2, "ZR"); + Vector2d v2 = new Vector2d(p2.x, p2.y); + + v2.sub(v1); + return v2; + } else if (vw.equalsIgnoreCase("XY")) { + Vector2d v = new Vector2d(this._dir.x(), this._dir.y()); + v.normalize(); + return v; + } else { + return null; + } + } + + @Override + public String toString() { +// String tmp = (this.nb.size()>0) ? this.nb.get(0) + " " + this.nb.get(nb.size()-1) : ""; + return "c1_Id " + this._c1.getId() + " " + this._c1.getDetector() + + ", c2_Id " + this._c2.getId() + " " + this._c2.getDetector() + + ", state " + this._state + + ", nb " + this.nb.size() + ", plane " + this._plane + " "; + } + + public boolean equals(Cell c) { + return c.getC1() == this._c1 && c.getC2() == this._c2; + } + + public boolean contains(Cross x) { + return x.equals(this._c1) || x.equals(this._c2); + } + + public void addNeighbour(Cell b) { + if (nb == null) { + this.nb = new ArrayList<>(); + } + this.nb.add(b); + } + + public List getNeighbors() { + return this.nb; + } + + public Cross getC1() { + return _c1; + } + + public void setC1(Cross _c1) { + this._c1 = _c1; + } + + public Cross getC2() { + return _c2; + } + + public void setC2(Cross _c2) { + this._c2 = _c2; + } + + public Vector3D getDir() { + return _dir; + } + + public void setDir(Vector3D dir) { + this._dir = dir; + } + + public int getState() { + return _state; + } + + public void getState(int _state) { + this._state = _state; + } + + public String getPlane() { + return _plane; + } + + public void setPlane(String _plane) { + this._plane = _plane; + } + + public boolean isUsed() { + return _used; + } + + public void setUsed(boolean _used) { + this._used = _used; + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java index 97c09df37..6c38f3289 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/EnergyLossCorr.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt.track; +import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.clas.swimtools.Swim; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.svt.SVTParameters; @@ -16,30 +17,19 @@ public class EnergyLossCorr { public static final double C = 0.0002997924580; public String massHypo = "pion"; - /** - * Field instantiated using the torus and the solenoid - */ - - double cosEntAnglesPlanes[]; - + private double cosEntAnglesPlanes[]; private double[][] Points; - //private double[][] CorrPoints; private Track _updatedTrack; - - public Track get_UpdatedTrack() { - return _updatedTrack; - } - - public void set_UpdatedTrack(Track updatedTrack) { - this._updatedTrack = updatedTrack; - } - private Helix OrigTrack; + + private static final double MUMASS = 0.105658369; + /** * The constructor * * @param trkcand the track candidate + * @param bstSwim */ public EnergyLossCorr(Track trkcand, Swim bstSwim) { @@ -47,29 +37,29 @@ public EnergyLossCorr(Track trkcand, Swim bstSwim) { return; } - massHypo = trkcand.get_PID(); + massHypo = trkcand.getPID(); - OrigTrack = new Helix(trkcand.get_helix().get_dca(), trkcand.get_helix().get_phi_at_dca(), trkcand.get_helix().get_curvature(), - trkcand.get_helix().get_Z0(), trkcand.get_helix().get_tandip(), trkcand.get_helix().getXb(), trkcand.get_helix().getYb(), null); + OrigTrack = new Helix(trkcand.getHelix().getDCA(), trkcand.getHelix().getPhiAtDCA(), trkcand.getHelix().getCurvature(), + trkcand.getHelix().getZ0(), trkcand.getHelix().getTanDip(), trkcand.getHelix().getXb(), trkcand.getHelix().getYb(), null); init(trkcand, bstSwim); } public void doCorrection(Track trkcand) { - double B = trkcand.get_helix().B; + double B = trkcand.getHelix().B; double ELossMax = 600; //600Mev double stepSize = 0.001; //1 MeV int nbins = (int) ELossMax; - double pt0 = trkcand.get_Pt() + ELossMax * stepSize;// Assumes the max ELoss is 600 MeV + double pt0 = trkcand.getPt() + ELossMax * stepSize;// Assumes the max ELoss is 600 MeV double pt = pt0; - double curv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / pt; + double curv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.getCurvature()) / pt; for (int j = 0; j < nbins; j++) { - if (Math.abs(this.OrigTrack.get_curvature()) < Math.abs(curv)) { - double correctedCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / (pt + stepSize); - trkcand.get_helix().set_curvature(correctedCurv); + if (Math.abs(this.OrigTrack.getCurvature()) < Math.abs(curv)) { + double correctedCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.getCurvature()) / (pt + stepSize); + trkcand.getHelix().setCurvature(correctedCurv); trkcand.setPXYZ(); return; } @@ -93,22 +83,22 @@ private void init(Track trkcand, Swim bstSwim) { cosEntAnglesPlanes = new double[trkcand.size()]; - Track trkcandcopy = new Track(trkcand.get_helix()); + Track trkcandcopy = new Track(trkcand.getHelix()); trkcandcopy.addAll(trkcand); - this.set_UpdatedTrack(trkcandcopy); + this.setUpdatedTrack(trkcandcopy); for (int m = 0; m < trkcand.size(); m++) { - Points[m][0] = trkcand.get(m).get_Point().x(); - Points[m][1] = trkcand.get(m).get_Point().y(); - Points[m][2] = trkcand.get(m).get_Point().z(); + Points[m][0] = trkcand.get(m).getPoint().x(); + Points[m][1] = trkcand.get(m).getPoint().y(); + Points[m][2] = trkcand.get(m).getPoint().z(); - double x = trkcand.get_helix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).x(); - double ux = trkcand.get_helix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).x(); - double y = trkcand.get_helix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).y(); - double uy = trkcand.get_helix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).y(); - double z = trkcand.get_helix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).z(); - double uz = trkcand.get_helix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).z(); + double x = trkcand.getHelix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).x(); + double ux = trkcand.getHelix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).x(); + double y = trkcand.getHelix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).y(); + double uy = trkcand.getHelix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).y(); + double z = trkcand.getHelix().getPointAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).z(); + double uz = trkcand.getHelix().getTrackDirectionAtRadius(Math.sqrt(Points[m][0] * Points[m][0] + Points[m][1] * Points[m][1])).z(); double cosEntranceAngle = Math.abs((x * ux + y * uy + z * uz) / Math.sqrt(x * x + y * y + z * z)); cosEntAnglesPlanes[m] = cosEntranceAngle; @@ -120,20 +110,20 @@ private void init(Track trkcand, Swim bstSwim) { //? Solve numerically stepping over pt until corr pt matches with fit omega... how much dedx corresponds to obs pt? private double doEnergyLossCorrection(int m, double pt, double B) { - double tanL = this.OrigTrack.get_tandip(); + double tanL = this.OrigTrack.getTanDip(); // pz = pt*tanL double pz = pt * tanL; double p = Math.sqrt(pt * pt + pz * pz); - double mass = MassHypothesis(massHypo); // assume given mass hypothesis + double mass = massHypothesis(massHypo); // assume given mass hypothesis double beta = p / Math.sqrt(p * p + mass * mass); // use particle momentum double gamma = 1. / Math.sqrt(1 - beta * beta); double cosEntranceAngle = cosEntAnglesPlanes[m]; - double s = eMass / mass; + double s = PhysicsConstants.massElectron() / mass; //double Wmax = 2.*mass*beta*beta*gamma*gamma/(1.+2.*s*Math.sqrt(1+beta*gamma*beta*gamma)+s*s); double Wmax = 2. * mass * beta * beta * gamma * gamma / (1. + 2. * s * gamma + s * s); double I = 0.000000172; @@ -147,50 +137,49 @@ private double doEnergyLossCorrection(int m, double pt, double B) { double tmpPtot = p; - double tmpEtot = Math.sqrt(MassHypothesis(massHypo) * MassHypothesis(massHypo) + tmpPtot * tmpPtot); + double tmpEtot = Math.sqrt(massHypothesis(massHypo) * massHypothesis(massHypo) + tmpPtot * tmpPtot); //double tmpEtotCorrected = tmpEtot-dEdx*Constants.LAYRGAP/cosEntranceAngle; double tmpEtotCorrected = tmpEtot - dEdx / cosEntranceAngle; - double tmpPtotCorrSq = tmpEtotCorrected * tmpEtotCorrected - MassHypothesis(massHypo) * MassHypothesis(massHypo); + double tmpPtotCorrSq = tmpEtotCorrected * tmpEtotCorrected - massHypothesis(massHypo) * massHypothesis(massHypo); double newPt = Math.sqrt(tmpPtotCorrSq / (1 + tanL * tanL)); - double newCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.get_curvature()) / newPt; + double newCurv = (Constants.LIGHTVEL * Math.abs(B)) * Math.signum(this.OrigTrack.getCurvature()) / newPt; return newCurv; } + public Track getUpdatedTrack() { + return _updatedTrack; + } + + public void setUpdatedTrack(Track updatedTrack) { + this._updatedTrack = updatedTrack; + } + /** * * @param H a string corresponding to the mass hypothesis - the pion mass * hypothesis is the default value * @return the mass value for the given mass hypothesis in GeV/c^2 */ - public double MassHypothesis(String H) { - double value = piMass; //default + public double massHypothesis(String H) { + double value = PhysicsConstants.massPionCharged(); //default if (H.equals("proton")) { - value = pMass; + value = PhysicsConstants.massProton(); } - if (H.equals("electron")) { - value = eMass; + else if (H.equals("electron")) { + value = PhysicsConstants.massElectron(); } - if (H.equals("pion")) { - value = piMass; + else if (H.equals("kaon")) { + value = PhysicsConstants.massKaonCharged(); } - if (H.equals("kaon")) { - value = KMass; - } - if (H.equals("muon")) { - value = muMass; + else if (H.equals("muon")) { + value = MUMASS; } return value; } - static double piMass = 0.13957018; - static double KMass = 0.493677; - static double muMass = 0.105658369; - static double eMass = 0.000510998; - static double pMass = 0.938272029; - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java index 3ee8c810d..b4c0eadd6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/MakerCA.java @@ -1,4 +1,5 @@ package org.jlab.rec.cvt.track; + import java.util.*; import javax.vecmath.Vector2d; @@ -8,253 +9,288 @@ import org.jlab.rec.cvt.cross.Cross; /** - * Cellular automaton maker. - * It creates the cells from the crosses, finds the neighbors - * And it makes the system evolve + * Cellular automaton maker. It creates the cells from the crosses, finds the + * neighbors And it makes the system evolve * * @author fbossu * */ - public class MakerCA { - private List nodes; - private double _aCvsR; // max angle in degrees between the radius to the first cross and cell segment - private double _abCrs; // max angle in degrees where to look for cross pairs - private double _cosBtwCells; // minimal cosine between cells - private String _plane; // plane, XY (default) or RZ - private boolean _debug; - - public MakerCA( boolean debug ) { - this(); - this._debug = debug; - } - - public MakerCA(){ - this._abCrs = 11.; - this._aCvsR = 15; - this._cosBtwCells = 0.995; - this._plane = "XY"; - this._debug = false; - } - - - private boolean checkAngles( Cell cell ) { - double xa = cell.get_Crs2D(1, this._plane).x; - double ya = cell.get_Crs2D(1, this._plane).y; - double xb = cell.get_Crs2D(2, this._plane).x; - double yb = cell.get_Crs2D(2, this._plane).y; - Vector2d va = new Vector2d(xa,ya); - Vector2d vb = new Vector2d(xb,yb); - - if( this._plane.equalsIgnoreCase("XY")) { - // in XY follow the linear relation obtained from simulations - // Angle( DR ) = 0.175 * DR + 0.551 - // where DR is the difference in radius of the crosses - // The angles are in degrees - double R1 = cell.get_c1().getRadius(); - double R2 = cell.get_c2().getRadius(); - double angle = 1.75 * (R2 - R1) + 0.551; // in cm; TODO: create setters and getters for the parameters + private List nodes; + private double _aCvsR; // max angle in degrees between the radius to the first cross and cell segment + private double _abCrs; // max angle in degrees where to look for cross pairs + private double _cosBtwCells; // minimal cosine between cells + private String _plane; // plane, XY (default) or RZ + private boolean _debug; + + public MakerCA(boolean debug) { + this(); + this._debug = debug; + } + + public MakerCA() { + this._abCrs = 11.; + this._aCvsR = 15; + this._cosBtwCells = 0.995; + this._plane = "XY"; + this._debug = false; + } + + private boolean checkAngles(Cell cell) { + double xa = cell.getCrs2D(1, this._plane).x; + double ya = cell.getCrs2D(1, this._plane).y; + double xb = cell.getCrs2D(2, this._plane).x; + double yb = cell.getCrs2D(2, this._plane).y; + Vector2d va = new Vector2d(xa, ya); + Vector2d vb = new Vector2d(xb, yb); + + if (this._plane.equalsIgnoreCase("XY")) { + // in XY follow the linear relation obtained from simulations + // Angle( DR ) = 0.175 * DR + 0.551 + // where DR is the difference in radius of the crosses + // The angles are in degrees + double R1 = cell.getC1().getRadius(); + double R2 = cell.getC2().getRadius(); + double angle = 1.75 * (R2 - R1) + 0.551; // in cm; TODO: create setters and getters for the parameters // if( Math.toDegrees(va.angle(vb)) > this._abCrs ) return false; - if( Math.toDegrees(va.angle(vb)) > angle ) return false; - - // check then the cell makes a "nice" angle with the radius: TODO needed? - if( va.angle( cell.get_dir2D(this._plane)) > Math.toRadians( this._aCvsR) ) return false; - } - - if( this._plane.equalsIgnoreCase("ZR")) { - // on ZR, make loose selection on SVT - // and tight selections on BMT - if( cell.get_c1().get_Detector()==DetectorType.BST) { - if( cell.get_c2().get_Detector()==DetectorType.BST) { - if( Math.toDegrees(va.angle(vb)) > 30. ) return false; - } - else - if( Math.toDegrees(va.angle(vb)) > 19. ) return false; - } - else { - if( Math.toDegrees(va.angle(vb)) > 3.5 ) return false; - } - - // check then the cell makes a "nice" angle with the radius: TODO needed? - if( va.angle( cell.get_dir2D(this._plane)) > Math.toRadians( this._aCvsR) ) return false; - } - return true; - } - - public void createCells( List crs){ - // this function loops over the crosses and looks for pairs that pass the cuts - // - Collections.sort(crs); - nodes = new ArrayList(); - for( int ic=0;ic angle) { + return false; + } + + // check then the cell makes a "nice" angle with the radius: TODO needed? + if (va.angle(cell.getDir2D(this._plane)) > Math.toRadians(this._aCvsR)) { + return false; + } + } + + if (this._plane.equalsIgnoreCase("ZR")) { + // on ZR, make loose selection on SVT + // and tight selections on BMT + if (cell.getC1().getDetector() == DetectorType.BST) { + if (cell.getC2().getDetector() == DetectorType.BST) { + if (Math.toDegrees(va.angle(vb)) > 30.) { + return false; + } + } else if (Math.toDegrees(va.angle(vb)) > 19.) { + return false; + } + } else { + if (Math.toDegrees(va.angle(vb)) > 3.5) { + return false; + } + } + + // check then the cell makes a "nice" angle with the radius: TODO needed? + if (va.angle(cell.getDir2D(this._plane)) > Math.toRadians(this._aCvsR)) { + return false; + } + } + return true; + } + + public void createCells(List crs) { + // this function loops over the crosses and looks for pairs that pass the cuts + // + Collections.sort(crs); + nodes = new ArrayList<>(); + for (int ic = 0; ic < crs.size(); ic++) { + Cross a = crs.get(ic); + int aReg = a.getRegion(); + if (a.getDetector() == DetectorType.BMT) { + aReg = 3 + Constants.BMTGEOMETRY.getLayer(aReg, a.getType()); + } + + if (this._debug) { + System.out.println("\n cross a " + a.getId() + " " + a.getDetector().getName() + a.getType().getName() + " sect:" + a.getSector() + " reg:" + + aReg + " phi:" + a.getPoint().toVector3D().phi() + " in BMT sector:" + + Constants.BMTGEOMETRY.getSector(1, a.getPoint().toVector3D().phi())); + } + // for(int jc=0;jc 2) continue; - if( this._debug) System.out.println(" bReg <=4 passed Delta region 2 "); - } - if( bReg > 4 && bReg < 7 ) { - if( Math.abs( bReg-aReg) > 3) continue; - if( this._debug) System.out.println(" 4 < bReg < 7 passed Delta region 3 " ); - } - if( bReg >= 7 ) { - if( Math.abs( bReg-aReg) > 4) continue; - if( this._debug) System.out.println(" 7 >= bReg passed Delta region 4 " ); - } - - // stay in the same BMT sector - if( b.get_Detector()==DetectorType.BMT){ - if( a.get_Detector()==DetectorType.BMT){ - if(b.get_Sector() != a.get_Sector() ) continue; - } - else{ - double aphi = a.get_Point().toVector3D().phi() ; - //if( ! bgeom.checkIsInSector( aphi, b.get_Sector(), 1, Math.toRadians(10) ) ) { - if(Constants.BMTGEOMETRY.getSector(b.get_Region()*2, aphi)==0) { - if( this._debug) System.out.println("cross b and a are not in the same sector"); - continue; - } - - } - } - - // create the cell - Cell scell = new Cell( a,b, this._plane); - if( this._debug) System.out.println( " ... create a cell: " + scell); - - // check angular position of the crosses and the cell - if( this.checkAngles(scell) == false ) { - if( this._debug) System.out.println(" +++ angle check not passed +++ "); - continue; - } - - - // when running on ZR - // if both cells are SVT, check that they are "ok" in xy - if( this._plane.equalsIgnoreCase("ZR")){ - if( b.get_Detector()==DetectorType.BST){ - double xaxy = scell.get_Crs2D(1, "XY").x; - double yaxy = scell.get_Crs2D(1, "XY").y; - Vector2d vaxy = new Vector2d(xaxy,yaxy); - if( vaxy.angle( scell.get_dir2D("XY")) > Math.toRadians( this._aCvsR) ) continue; - } - } - - // here a good cell if found. Adding it to the list of cells - nodes.add(scell); - if( this._debug) System.out.println( "adding the cell to the node list\n"); - - } + for (int jc = ic + 1; jc < crs.size(); jc++) { + Cross b = crs.get(jc); + + // we skip same region crosses + int bReg = b.getRegion(); + if (b.getDetector() == DetectorType.BMT) { + bReg = 3 + Constants.BMTGEOMETRY.getLayer(bReg, b.getType()); + } + + if (this._debug) { + System.out.println(" cross b " + b.getId() + " " + b.getDetector().getName() + b.getType().getName() + " sect:" + b.getSector() + " reg:" + + bReg + " phi:" + b.getPoint().toVector3D().phi() + " in BMT sector:" + + Constants.BMTGEOMETRY.getSector(1, b.getPoint().toVector3D().phi())); + } + + if (bReg <= aReg) { + continue; // crosses should be ordered. skip in case they are not + } + // we allow skipping one region maximum + if (bReg <= 4) { + if (Math.abs(bReg - aReg) > 2) { + continue; + } + if (this._debug) { + System.out.println(" bReg <=4 passed Delta region 2 "); + } + } + if (bReg > 4 && bReg < 7) { + if (Math.abs(bReg - aReg) > 3) { + continue; + } + if (this._debug) { + System.out.println(" 4 < bReg < 7 passed Delta region 3 "); + } + } + if (bReg >= 7) { + if (Math.abs(bReg - aReg) > 4) { + continue; + } + if (this._debug) { + System.out.println(" 7 >= bReg passed Delta region 4 "); + } + } + + // stay in the same BMT sector + if (b.getDetector() == DetectorType.BMT) { + if (a.getDetector() == DetectorType.BMT) { + if (b.getSector() != a.getSector()) { + continue; + } + } else { + double aphi = a.getPoint().toVector3D().phi(); + //if( ! bgeom.checkIsInSector( aphi, b.getSector(), 1, Math.toRadians(10) ) ) { + if (Constants.BMTGEOMETRY.getSector(b.getRegion() * 2, aphi) == 0) { + if (this._debug) { + System.out.println("cross b and a are not in the same sector"); + } + continue; + } + + } + } + + // create the cell + Cell scell = new Cell(a, b, this._plane); + if (this._debug) { + System.out.println(" ... create a cell: " + scell); + } + + // check angular position of the crosses and the cell + if (this.checkAngles(scell) == false) { + if (this._debug) { + System.out.println(" +++ angle check not passed +++ "); + } + continue; + } + + // when running on ZR + // if both cells are SVT, check that they are "ok" in xy + if (this._plane.equalsIgnoreCase("ZR")) { + if (b.getDetector() == DetectorType.BST) { + double xaxy = scell.getCrs2D(1, "XY").x; + double yaxy = scell.getCrs2D(1, "XY").y; + Vector2d vaxy = new Vector2d(xaxy, yaxy); + if (vaxy.angle(scell.getDir2D("XY")) > Math.toRadians(this._aCvsR)) { + continue; + } + } + } + + // here a good cell if found. Adding it to the list of cells + nodes.add(scell); + if (this._debug) { + System.out.println("adding the cell to the node list\n"); + } + + } } - } - - - public void findNeigbors(){ - // from the list of cells, it looks for neigbours from "inside-out" - if( nodes == null ){ return; } - for(int ic=0;ic this._cosBtwCells){ - n.addNeighbour(c); - } - } - } + } + + public void findNeigbors() { + // from the list of cells, it looks for neigbours from "inside-out" + if (nodes == null) { + return; + } + for (int ic = 0; ic < nodes.size(); ic++) { + Cell c = nodes.get(ic); + for (int jc = ic + 1; jc < nodes.size(); jc++) { + Cell n = nodes.get(jc); + if (c.getNeighbors().contains(n)) { + continue; + } + if (n.getC1().equals(c.getC2())) { + if (n.getDir2D(this._plane).dot(c.getDir2D(this._plane)) > this._cosBtwCells) { + n.addNeighbour(c); + } + } + } } - } - - public void evolve(int N){ + } + + public void evolve(int N) { int[] states = new int[nodes.size()]; // evolve - for( int i=0; i max ) max = n.get_state(); - } - states[j] = 1 + max ; - j++; - } - // update all cell states at once - for( j=0;j max) { + max = n.getState(); + } + } + states[j] = 1 + max; + j++; + } + // update all cell states at once + for (j = 0; j < nodes.size(); j++) { + nodes.get(j).getState(states[j]); + } } - } - - public double get_aCvsR() { - return _aCvsR; - } - - public void set_aCvsR(double _aCvsR) { - this._aCvsR = _aCvsR; - } - - public double get_abCrs() { - return _abCrs; - } - - public void set_abCrs(double _abCrs) { - this._abCrs = _abCrs; - } - - public double get_cosBtwCells() { - return _cosBtwCells; - } - - public void set_cosBtwCells(double _cosBtwCells) { - this._cosBtwCells = _cosBtwCells; - } - - public String get_plane() { - return _plane; - } - - public void set_plane(String _plane) { - this._plane = _plane; - } - - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } + } + + public double getaCvsR() { + return _aCvsR; + } + + public void setaCvsR(double _aCvsR) { + this._aCvsR = _aCvsR; + } + + public double getabCrs() { + return _abCrs; + } + + public void setabCrs(double _abCrs) { + this._abCrs = _abCrs; + } + + public double getcosBtwCells() { + return _cosBtwCells; + } + + public void setcosBtwCells(double _cosBtwCells) { + this._cosBtwCells = _cosBtwCells; + } + + public String getPlane() { + return _plane; + } + + public void setPlane(String _plane) { + this._plane = _plane; + } + + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = nodes; + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java index 1830062c7..f9083c785 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Seed.java @@ -40,49 +40,49 @@ public Seed() { } public Seed(List crosses) { - this.set_Crosses(crosses); + this.setCrosses(crosses); } public Seed(List crosses, double doca, double rho, double phi) { - this.set_Crosses(crosses); - this.set_Doca(doca); - this.set_Rho(rho); - this.set_Phi(phi); + this.setCrosses(crosses); + this.setDoca(doca); + this.setRho(rho); + this.setPhi(phi); } public Seed(List crosses, Helix helix) { - this.set_Crosses(crosses); - this.set_Helix(helix); + this.setCrosses(crosses); + this.setHelix(helix); } - public Helix get_Helix() { + public Helix getHelix() { return _Helix; } - public final void set_Helix(Helix helix) { + public final void setHelix(Helix helix) { this._Helix = helix; - this.doca = helix.get_dca(); - this.rho = helix.get_curvature(); - this.phi = helix.get_phi_at_dca(); + this.doca = helix.getDCA(); + this.rho = helix.getCurvature(); + this.phi = helix.getPhiAtDCA(); } public void setId(int id) { this.id = id; } - public void set_Status(int trkStatus) { + public void setStatus(int trkStatus) { this.status = trkStatus; } - public final void set_Doca(double doca) { + public final void setDoca(double doca) { this.doca = doca; } - public final void set_Rho(double rho) { + public final void setRho(double rho) { this.rho = rho; } - public final void set_Phi(double phi) { + public final void setPhi(double phi) { this.phi = phi; } @@ -90,37 +90,37 @@ public int getId() { return id; } - public int get_Status() { + public int getStatus() { return status; } - public double get_Doca() { + public double getDoca() { return this.doca; } - public double get_Rho() { + public double getRho() { return this.rho; } - public double get_Phi() { + public double getPhi() { return this.phi; } - private void set_Clusters() { - List clusters = new ArrayList(); - for(Cross c : this.get_Crosses()) { - if(c.get_Detector()==DetectorType.BST) { - clusters.add(c.get_Cluster1()); - clusters.add(c.get_Cluster2()); + private void setClusters() { + List clusters = new ArrayList<>(); + for(Cross c : this.getCrosses()) { + if(c.getDetector()==DetectorType.BST) { + clusters.add(c.getCluster1()); + clusters.add(c.getCluster2()); } else { - clusters.add(c.get_Cluster1()); + clusters.add(c.getCluster1()); } } Collections.sort(clusters); _Clusters = clusters; } - public List get_Clusters() { + public List getClusters() { return _Clusters; } @@ -129,30 +129,30 @@ public void add_Clusters(List clusters) { Collections.sort(_Clusters); } - public List get_Crosses() { + public List getCrosses() { Collections.sort(_Crosses); return _Crosses; } - public final void set_Crosses(List _Crosses) { + public final void setCrosses(List _Crosses) { Collections.sort(_Crosses); this._Crosses = _Crosses; - this.set_Clusters(); + this.setClusters(); } - public double get_circleFitChi2PerNDF() { + public double getCircleFitChi2PerNDF() { return _circleFitChi2PerNDF; } - public void set_circleFitChi2PerNDF(double _circleFitChi2PerNDF) { + public void setCircleFitChi2PerNDF(double _circleFitChi2PerNDF) { this._circleFitChi2PerNDF = _circleFitChi2PerNDF; } - public double get_lineFitChi2PerNDF() { + public double getLineFitChi2PerNDF() { return _lineFitChi2PerNDF; } - public void set_lineFitChi2PerNDF(double _lineFitChi2PerNDF) { + public void setLineFitChi2PerNDF(double _lineFitChi2PerNDF) { this._lineFitChi2PerNDF = _lineFitChi2PerNDF; } @@ -172,23 +172,20 @@ public void setChi2(double _chi2) { this._chi2 = _chi2; } - public String get_IntIdentifier() { + public String getIntIdentifier() { String id = ""; - for(Cluster c: this.get_Clusters()) - id+=c.get_Id(); - for(Cross c: this.get_Crosses()) - id+=c.get_Id(); + for(Cluster c: this.getClusters()) + id+=c.getId(); + for(Cross c: this.getCrosses()) + id+=c.getId(); return id; } @Override public int compareTo(Seed arg) { - - return ( this._Crosses.size() > arg.get_Crosses().size() ) ? -1 : ( this._Crosses.size() == arg.get_Crosses().size() ) ? 0 : 1; -// return Double.parseDouble(this.get_IntIdentifier()) < Double.parseDouble(arg.get_IntIdentifier()) ? -1 : Double.parseDouble(this.get_IntIdentifier()) == Double.parseDouble(arg.get_IntIdentifier()) ? 0 : 1; - + return ( this._Crosses.size() > arg.getCrosses().size() ) ? -1 : ( this._Crosses.size() == arg.getCrosses().size() ) ? 0 : 1; } @@ -211,16 +208,16 @@ public boolean fit(int fitIter, double xb, double yb, double bfield) { int bmtZSz = 0; int bmtCSz = 0; - for (Cross c : this.get_Crosses()) { + for (Cross c : this.getCrosses()) { // reset cross to clear previous track settings on direction and Point c.reset(); - if (c.get_Detector()==DetectorType.BST) { + if (c.getDetector()==DetectorType.BST) { SVTCrosses.add(c); } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { + else if (c.getDetector()==DetectorType.BMT && c.getType()==BMTType.C ) { BMTCrossesC.add(c); } - else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { + else if (c.getDetector()==DetectorType.BMT && c.getType()==BMTType.Z ) { BMTCrossesZ.add(c); } } @@ -255,35 +252,35 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { ErrRt.clear(); for (int j = 0; j < SVTCrosses.size(); j++) { - X.add(j, SVTCrosses.get(j).get_Point().x()); - Y.add(j, SVTCrosses.get(j).get_Point().y()); + X.add(j, SVTCrosses.get(j).getPoint().x()); + Y.add(j, SVTCrosses.get(j).getPoint().y()); if (useSVTdipAngEst == 1) { - Z.add(j, SVTCrosses.get(j).get_Point().z()); - Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() - + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); - ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); + Z.add(j, SVTCrosses.get(j).getPoint().z()); + Rho.add(j, Math.sqrt(SVTCrosses.get(j).getPoint().x() * SVTCrosses.get(j).getPoint().x() + + SVTCrosses.get(j).getPoint().y() * SVTCrosses.get(j).getPoint().y())); + ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).getPointErr().x() * SVTCrosses.get(j).getPointErr().x() + + SVTCrosses.get(j).getPointErr().y() * SVTCrosses.get(j).getPointErr().y())); + ErrZ.add(j, SVTCrosses.get(j).getPointErr().z()); } - ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); + ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).getPointErr().x() * SVTCrosses.get(j).getPointErr().x() + + SVTCrosses.get(j).getPointErr().y() * SVTCrosses.get(j).getPointErr().y())); } if (bmtZSz > 0) { for (int j = svtSz; j < svtSz + bmtZSz; j++) { - X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); - Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); - ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() - + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); + X.add(j, BMTCrossesZ.get(j - svtSz).getPoint().x()); + Y.add(j, BMTCrossesZ.get(j - svtSz).getPoint().y()); + ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).getPointErr().x() * BMTCrossesZ.get(j - svtSz).getPointErr().x() + + BMTCrossesZ.get(j - svtSz).getPointErr().y() * BMTCrossesZ.get(j - svtSz).getPointErr().y())); } } if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { - Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); + Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getPoint().z()); + Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getCluster1().getLayer())); ErrRho.add(j, Constants.BMTGEOMETRY.getThickness()/2 / Math.sqrt(12.)); - ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); + ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getPointErr().z()); } } X.add(xb); @@ -292,31 +289,31 @@ else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { FitStatus fitStatus = fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); - if (fitStatus!=FitStatus.Successful || fitTrk.get_helix() == null) { + if (fitStatus!=FitStatus.Successful || fitTrk.gethelix() == null) { return false; } - fitTrk.get_helix().B = bfield; + fitTrk.gethelix().B = bfield; - this.set_Helix(fitTrk.get_helix()); + this.setHelix(fitTrk.gethelix()); if( X.size()>3 ) { - this.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]/(X.size()-3)); + this.setCircleFitChi2PerNDF(fitTrk.getchisq()[0]/(X.size()-3)); } else { - this.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]*2); // penalize tracks with only 3 crosses + this.setCircleFitChi2PerNDF(fitTrk.getchisq()[0]*2); // penalize tracks with only 3 crosses } if( Z.size() > 2 ) { - this.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]/(Z.size()-2)); + this.setLineFitChi2PerNDF(fitTrk.getchisq()[1]/(Z.size()-2)); } else { - this.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses + this.setLineFitChi2PerNDF(fitTrk.getchisq()[1]*2);// penalize tracks with only 2 crosses } - this.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); + this.setChi2(fitTrk.getchisq()[0]+fitTrk.getchisq()[1]); this.setNDF(X.size()+Z.size()-5); - if (fitTrk.get_chisq()[0] < chisqMax) { - chisqMax = fitTrk.get_chisq()[0]; + if (fitTrk.getchisq()[0] < chisqMax) { + chisqMax = fitTrk.getchisq()[0]; if(chisqMax Constants.CHI2CUT * (this.getNDF() + 5)) return false; else if(this.getNDF() < Constants.NDFCUT) return false; - else if(this.get_Helix().getPt(this.get_Helix().B) < Constants.PTCUT) + else if(this.getHelix().getPt(this.getHelix().B) < Constants.PTCUT) return false; -// else if(Math.abs(this.get_Helix().get_tandip()) > Constants.TANDIP) +// else if(Math.abs(this.getHelix().getTanDip()) > Constants.TANDIP) // return false; - else if(Math.abs(this.get_Helix().get_Z0()) > Constants.ZRANGE) + else if(Math.abs(this.getHelix().getZ0()) > Constants.ZRANGE) return false; else return true; @@ -389,9 +384,9 @@ else if(this.getNDF()==o.getNDF()) { */ public boolean overlapWith(Seed o) { int nc = 0; - for(Cross c : this.get_Crosses()) { - if(c.get_Type()==BMTType.C) continue; //skim BMTC - if(o.get_Crosses().contains(c)) nc++; + for(Cross c : this.getCrosses()) { + if(c.getType()==BMTType.C) continue; //skim BMTC + if(o.getCrosses().contains(c)) nc++; } if(nc >1) return true; else return false; @@ -420,10 +415,10 @@ public static void removeOverlappingSeeds(List seeds) { @Override public String toString() { String str = String.format("Track id=%d, q=%d, omega=%.3f mm-1, d0=%.3f mm, phi=%.3f deg, dz=%.3f mm, tanL=%.3f, NDF=%d, chi2=%.3f, seed method=%d\n", - this.getId(), this.get_Helix().get_charge(), this.get_Helix().get_curvature(), this.get_Helix().get_dca(), - Math.toDegrees(this.get_Helix().get_phi_at_dca()), this.get_Helix().get_Z0(), this.get_Helix().get_tandip(), - this.getNDF(), this.getChi2(), this.get_Status()); - for(Cross c: this.get_Crosses()) str = str + c.toString() + "\n"; + this.getId(), this.getHelix().getCharge(), this.getHelix().getCurvature(), this.getHelix().getDCA(), + Math.toDegrees(this.getHelix().getPhiAtDCA()), this.getHelix().getZ0(), this.getHelix().getTanDip(), + this.getNDF(), this.getChi2(), this.getStatus()); + for(Cross c: this.getCrosses()) str = str + c.toString() + "\n"; return str; } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java index bf67a4555..57e76336a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrack.java @@ -14,7 +14,7 @@ import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; -import org.jlab.rec.cvt.track.Measurements.CVTLayer; +import org.jlab.rec.cvt.measurement.MLayer; import org.jlab.rec.cvt.trajectory.Ray; import org.jlab.rec.cvt.trajectory.StateVec; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -35,11 +35,11 @@ public StraightTrack(Ray ray) { public List getClusters() { List clusters = new ArrayList<>(); for(Cross c : this) { - if(c.get_Detector()==DetectorType.BST) { - if(c.get_Cluster1()!=null) clusters.add(c.get_Cluster1()); - if(c.get_Cluster2()!=null) clusters.add(c.get_Cluster2()); + if(c.getDetector()==DetectorType.BST) { + if(c.getCluster1()!=null) clusters.add(c.getCluster1()); + if(c.getCluster2()!=null) clusters.add(c.getCluster2()); } else { - clusters.add(c.get_Cluster1()); + clusters.add(c.getCluster1()); } } Collections.sort(clusters); @@ -49,8 +49,8 @@ public List getClusters() { public void update(KFitter kf) { Ray the_ray = new Ray(kf.finalStateVec.tx, kf.finalStateVec.x0, kf.finalStateVec.tz, kf.finalStateVec.z0); - this.set_ray(the_ray); - this.set_chi2(kf.chi2); + this.setRay(the_ray); + this.setchi2(kf.chi2); this.trajs = kf.TrjPoints; this.updateCrosses(); this.updateClusters(); @@ -59,19 +59,19 @@ public void update(KFitter kf) { public void updateCrosses(Ray ray) { - this.set_ray(ray); + this.setRay(ray); this.updateCrosses(); } public void updateCrosses() { for (Cross c : this) { - c.set_AssociatedTrackID(this.get_Id()); - if(c.get_Detector()==DetectorType.BST) - c.updateSVTCross(this.get_ray().get_dirVec()); + c.setAssociatedTrackID(this.getId()); + if(c.getDetector()==DetectorType.BST) + c.updateSVTCross(this.getRay().getDirVec()); else { - Cluster cluster = c.get_Cluster1(); + Cluster cluster = c.getCluster1(); List trajs = new ArrayList<>(); - int nTraj = cluster.getTile().intersection(this.get_ray().toLine(), trajs); + int nTraj = cluster.getTile().intersection(this.getRay().toLine(), trajs); if(nTraj>0) { Point3D traj = null; double doca = Double.MAX_VALUE; @@ -82,7 +82,7 @@ public void updateCrosses() { traj = t; } } - c.updateBMTCross(traj, this.get_ray().get_dirVec()); + c.updateBMTCross(traj, this.getRay().getDirVec()); } } } @@ -91,26 +91,26 @@ public void updateCrosses() { public void updateClusters() { for(Cluster cluster: this.getClusters()) { int hemisphere = (int) Math.signum(cluster.center().y()); - int layer = cluster.get_Layer(); - DetectorType type = cluster.get_Detector(); - int index = CVTLayer.getType(type, layer).getIndex(hemisphere); - cluster.update(this.get_Id(), this.trajs.get(index)); + int layer = cluster.getLayer(); + DetectorType type = cluster.getDetector(); + int index = MLayer.getType(type, layer).getIndex(hemisphere); + cluster.update(this.getId(), this.trajs.get(index)); } } - public double get_ndf() { + public double getndf() { return _ndf; } - public void set_ndf(double _ndf) { + public void setndf(double _ndf) { this._ndf = _ndf; } - public double get_chi2() { + public double getchi2() { return _chi2; } - public void set_chi2(double _chi2) { + public void setchi2(double _chi2) { this._chi2 = _chi2; } @@ -119,7 +119,7 @@ public boolean containsCross(Cross cross) { boolean isInTrack = false; for (int i = 0; i < cand.size(); i++) { - if (cand.get(i).get_Id() == cross.get_Id()) { + if (cand.get(i).getId() == cross.getId()) { isInTrack = true; } @@ -130,10 +130,10 @@ public boolean containsCross(Cross cross) { public void findTrajectory() { - Ray ray = this.get_ray(); + Ray ray = this.getRay(); ArrayList stateVecs = new ArrayList<>(); - double[][][] SVTIntersections = TrajectoryFinder.calc_trackIntersSVT(ray); + double[][][] SVTIntersections = TrajectoryFinder.calcTrackIntersSVT(ray); for (int l = 0; l < SVTGeometry.NLAYERS; l++) { for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { @@ -150,14 +150,14 @@ public void findTrajectory() { double trkToMPlnAngl = SVTIntersections[l][s][5]; double CalcCentroidStrip = SVTIntersections[l][s][6]; - StateVec stVec = new StateVec(XtrackIntersPlane, YtrackIntersPlane, ZtrackIntersPlane, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); - stVec.set_ID(this.get_Id()); - stVec.set_SurfaceLayer(LayerTrackIntersPlane); - stVec.set_SurfaceSector(SectorTrackIntersPlane); - stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); - stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); - stVec.set_TrkToModuleAngle(trkToMPlnAngl); - stVec.set_CalcCentroidStrip(CalcCentroidStrip); + StateVec stVec = new StateVec(XtrackIntersPlane, YtrackIntersPlane, ZtrackIntersPlane, ray.getDirVec().x(), ray.getDirVec().y(), ray.getDirVec().z()); + stVec.setID(this.getId()); + stVec.setSurfaceLayer(LayerTrackIntersPlane); + stVec.setSurfaceSector(SectorTrackIntersPlane); + stVec.setTrkPhiAtSurface(PhiTrackIntersPlane); + stVec.setTrkThetaAtSurface(ThetaTrackIntersPlane); + stVec.setTrkToModuleAngle(trkToMPlnAngl); + stVec.setCalcCentroidStrip(CalcCentroidStrip); if(stateVecs.size()>0 && stateVecs.get(stateVecs.size()-1).x()==stVec.x() && stateVecs.get(stateVecs.size()-1).y()==stVec.y() @@ -169,7 +169,7 @@ public void findTrajectory() { } } - double[][][] BMTIntersections = TrajectoryFinder.calc_trackIntersBMT(ray, BMTConstants.STARTINGLAYR); + double[][][] BMTIntersections = TrajectoryFinder.calcTrackIntersBMT(ray, BMTConstants.STARTINGLAYR); for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { //hemisphere 1-2 @@ -181,22 +181,22 @@ public void findTrajectory() { double XtrackIntersSurf = BMTIntersections[l][h][0]; double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; - //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); + //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.ISINSECTORJITTER)); int SectorTrackIntersSurf = Constants.BMTGEOMETRY.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; double trkToMPlnAngl = BMTIntersections[l][h][5]; double CalcCentroidStrip = BMTIntersections[l][h][6]; - StateVec stVec = new StateVec(XtrackIntersSurf, YtrackIntersSurf, ZtrackIntersSurf, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); + StateVec stVec = new StateVec(XtrackIntersSurf, YtrackIntersSurf, ZtrackIntersSurf, ray.getDirVec().x(), ray.getDirVec().y(), ray.getDirVec().z()); - stVec.set_ID(this.get_Id()); - stVec.set_SurfaceLayer(LayerTrackIntersSurf); - stVec.set_SurfaceSector(SectorTrackIntersSurf); - stVec.set_TrkPhiAtSurface(PhiTrackIntersSurf); - stVec.set_TrkThetaAtSurface(ThetaTrackIntersSurf); - stVec.set_TrkToModuleAngle(trkToMPlnAngl); - stVec.set_CalcCentroidStrip(CalcCentroidStrip); + stVec.setID(this.getId()); + stVec.setSurfaceLayer(LayerTrackIntersSurf); + stVec.setSurfaceSector(SectorTrackIntersSurf); + stVec.setTrkPhiAtSurface(PhiTrackIntersSurf); + stVec.setTrkThetaAtSurface(ThetaTrackIntersSurf); + stVec.setTrkToModuleAngle(trkToMPlnAngl); + stVec.setCalcCentroidStrip(CalcCentroidStrip); if(stateVecs.size()>0 && stateVecs.get(stateVecs.size()-1).x()==stVec.x() && stateVecs.get(stateVecs.size()-1).y()==stVec.y() @@ -212,11 +212,11 @@ public void findTrajectory() { stateVecs.sort(Comparator.comparing(StateVec::y)); for (int l = 0; l < stateVecs.size(); l++) { - stateVecs.get(l).set_planeIdx(l); + stateVecs.get(l).setPlaneIdx(l); } - this.set_Trajectory(stateVecs); - this.set_SVTIntersections(SVTIntersections); - this.set_BMTIntersections(BMTIntersections); + this.setTrajectory(stateVecs); + this.setSVTIntersections(SVTIntersections); + this.setBMTIntersections(BMTIntersections); } @@ -224,20 +224,20 @@ public void findTrajectory() { * * @return the chi^2 for the straight track fit */ - public double calc_straightTrkChi2() { + public double calcStraightTrkChi2() { double chi2 = 0; - double yxSl = this.get_ray().get_yxslope(); - double yzSl = this.get_ray().get_yzslope(); - double yxIt = this.get_ray().get_yxinterc(); - double yzIt = this.get_ray().get_yzinterc(); + double yxSl = this.getRay().getYXSlope(); + double yzSl = this.getRay().getYZSlope(); + double yxIt = this.getRay().getYXInterc(); + double yzIt = this.getRay().getYZInterc(); for (Cross c : this) { - double errSq = c.get_PointErr().x() * c.get_PointErr().x() + c.get_PointErr().z() * c.get_PointErr().z(); - double y = c.get_Point().y(); - double x = c.get_Point().x(); - double z = c.get_Point().z(); + double errSq = c.getPointErr().x() * c.getPointErr().x() + c.getPointErr().z() * c.getPointErr().z(); + double y = c.getPoint().y(); + double x = c.getPoint().x(); + double z = c.getPoint().z(); double x_fit = yxSl * y + yxIt; double z_fit = yzSl * y + yzIt; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackCandListFinder.java new file mode 100644 index 000000000..1996f51c1 --- /dev/null +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackCandListFinder.java @@ -0,0 +1,561 @@ +package org.jlab.rec.cvt.track; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.jlab.detector.base.DetectorType; + +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +import org.jlab.rec.cvt.Constants; +import org.jlab.rec.cvt.bmt.BMTType; +import org.jlab.rec.cvt.cluster.Cluster; +import org.jlab.rec.cvt.cross.Cross; +import org.jlab.rec.cvt.cross.CrossList; +import org.jlab.rec.cvt.fit.LineFitter; +import org.jlab.rec.cvt.fit.CosmicFitter; +import org.jlab.rec.cvt.fit.LineFitPars; +import org.jlab.rec.cvt.hit.Hit; +import org.jlab.rec.cvt.svt.SVTParameters; +import org.jlab.rec.cvt.trajectory.Ray; +import org.jlab.rec.cvt.trajectory.StateVec; +import org.jlab.rec.cvt.trajectory.Trajectory; +import org.jlab.rec.cvt.trajectory.TrajectoryFinder; + +/** + * A class with a method implementing an algorithm that finds lists of track + * candidates in the BST + * + * @author ziegler + * + */ +public class StraightTrackCandListFinder { + + private List X; // x coordinate array + private List Y; // y coordinate array (same size as X array) + private List Z; // z coordinate array + private List Rho; // rho (= sqrt(x^2 + y^2) for SVT; detector radius for BMT) coordinate array (same size as Z array) + private List ErrZ; // z uncertainty (same size as Z array) + private List ErrRho; // rho uncertainty (same size as Z array) + private List ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) + private List Y_prime; // y coordinate array + private List ErrY_prime; + + public StraightTrackCandListFinder() { + X = new ArrayList<>(); + Y = new ArrayList<>(); + Z = new ArrayList<>(); + Rho = new ArrayList<>(); + ErrZ = new ArrayList<>(); + ErrRho = new ArrayList<>(); + ErrRt = new ArrayList<>(); + Y_prime = new ArrayList<>(); + ErrY_prime = new ArrayList<>(); + } + + /** + * A class representing the measurement variables used to fit a straight + * track + * + * @author ziegler + * + */ + public class RayMeasurements { + + public List _X; // x coordinate array + public List _Y; // y coordinate array (same size as X array) + public List _Z; // z coordinate array + public List _Y_prime; // y coordinate array (same size as Z array) + public List _ErrZ; // z uncertainty (same size as Z array) + public List _ErrY_prime; // y uncertainty (same size as Z array) + public List _ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) + + RayMeasurements(List X, + List Y, + List Z, + List Y_prime, + List ErrZ, + List ErrY_prime, + List ErrRt) { + this._X = X; + this._Y = Y; + this._Z = Z; + this._Y_prime = Y_prime; + this._ErrZ = ErrZ; + this._ErrY_prime = ErrY_prime; + this._ErrRt = ErrRt; + } + } + + + /** + * + * @param SVTCrosses + * @param BMTCrosses + * @return an array list of track candidates in the SVT + */ + public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses) { + + ArrayList cands = new ArrayList<>(); + Map candMap= new HashMap<>(); + + if (SVTCrosses.isEmpty()) { + System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); + return cands; + } + + CosmicFitter fitTrk = new CosmicFitter(); + for (int i = 0; i < SVTCrosses.size(); i++) { + ArrayList crossesToFit = new ArrayList<>(); + // remove SVT regions + // remove the crosses from the exluded region to fit the track + for (Cross crossInTrackToFit : SVTCrosses.get(i)) { + if (crossInTrackToFit.getRegion() != SVTParameters.BSTEXCLUDEDFITREGION) { + crossesToFit.add(crossInTrackToFit); + } + } + + if (crossesToFit.size() < org.jlab.rec.cvt.Constants.MINSVTCRSFORCOSMIC) { + continue; + } + + //fitTrk = new CosmicFitter(); + RayMeasurements MeasArrays = this.getRayMeasurementsArrays(crossesToFit, false, false, false); + + LineFitter linefitYX = new LineFitter(); + boolean linefitresultYX = linefitYX.fitStatus(MeasArrays._Y, MeasArrays._X, MeasArrays._ErrRt, null, MeasArrays._Y.size()); + + // prelim cross corrections + LineFitPars linefitparsYX = linefitYX.getFit(); + StraightTrack cand = new StraightTrack(null); + cand.addAll(crossesToFit); + if (linefitresultYX && linefitparsYX != null) { + cand.updateCrosses(linefitparsYX.getYXRay()); + } + // update measurements + MeasArrays = this.getRayMeasurementsArrays(crossesToFit, false, false, false); + + // fit SVt crosses + fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); + //create the cand + if (fitTrk.getray() != null) { + //refit + MeasArrays = this.getRayMeasurementsArrays(crossesToFit, false, false, false); + fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); + + cand = new StraightTrack(fitTrk.getray()); + cand.addAll(crossesToFit); + } + if (fitTrk.getray() == null) { + //System.err.println("Error in Track fitting -- ray not found -- trying to refit using the uncorrected crosses..."); + MeasArrays = this.getRayMeasurementsArrays(crossesToFit, false, true, false); + + fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); + //create the cand + //refit + MeasArrays = this.getRayMeasurementsArrays(crossesToFit, false, false, false); + fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); + + cand = new StraightTrack(fitTrk.getray()); + cand.addAll(crossesToFit); + + if (fitTrk.getray() == null) { + continue; + } + //System.err.println("Error in Track fitting -- track not found -- refit FAILED"); + } + cand.updateCrosses(); +// System.out.println(cand.getRay().toLine().origin().toString() + " " +// + Math.toDegrees(cand.getRay().toLine().direction().theta()) + " " +// + Math.toDegrees(cand.getRay().toLine().direction().phi()) + " "); + // eliminate bad residuals + this.eliminateStraightTrackOutliers(crossesToFit, fitTrk); + if (crossesToFit.size() < org.jlab.rec.cvt.Constants.MINSVTCRSFORCOSMIC) { + continue; + } + + fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); + //create the cand + if (fitTrk.getray() != null) { + cand = new StraightTrack(fitTrk.getray()); + cand.addAll(crossesToFit); + cand.updateCrosses(); + + } + + // match to Micromegas + ArrayList crossesToFitWithBMT = new ArrayList<>(); + //crossesToFitWithBMT.addAll(crossesToFit); + + //ArrayList BMTmatches = this.matchTrackToBMT(BMTCrosses, cand, bmt_geo); + //crossesToFitWithBMT.addAll(BMTmatches); + ArrayList BMTmatches = new ArrayList<>(); + ArrayList SVTmatches = new ArrayList<>(); + // reset the arrays + RayMeasurements NewMeasArrays = new RayMeasurements(null, null, null, null, null, null, null); + + //for (int iter = 0; iter < 11; iter++) { + // refit with Micromegas + crossesToFitWithBMT.clear(); + SVTmatches.clear(); + for (Cross c : cand) { + if (c.getDetector()==DetectorType.BST && Constants.SVTGEOMETRY.isInFiducial(c.getRegion()*2-1, c.getSector(), c.getPoint())) { + SVTmatches.add(c); + } + } + BMTmatches.clear(); + BMTmatches = this.matchTrackToBMT(cand, BMTCrosses); + + //crossesToFitWithBMT.addAll(SVTmatches); + crossesToFitWithBMT.addAll(BMTmatches); + + NewMeasArrays = this.getRayMeasurementsArrays(BMTmatches, false, false, true); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + cand.addAll(crossesToFitWithBMT); +// cand.resetCrosses(); + cand.updateCrosses(); + NewMeasArrays = this.getRayMeasurementsArrays(cand, false, false, true); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + crossesToFitWithBMT.clear(); + crossesToFitWithBMT.addAll(cand); + //create the cand + + if (fitTrk.getray() != null) { +// System.out.println(fitTrk.getRay().toLine().origin().toString() + " " +// + Math.toDegrees(fitTrk.getRay().toLine().direction().theta()) + " " +// + Math.toDegrees(fitTrk.getRay().toLine().direction().phi()) + " "); + cand = new StraightTrack(fitTrk.getray()); + cand.addAll(crossesToFitWithBMT); + cand.updateCrosses(); + //refit not using only BMT to fit the z profile + NewMeasArrays = this.getRayMeasurementsArrays(crossesToFitWithBMT, false, false, false); + fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); + cand = new StraightTrack(fitTrk.getray()); + cand.addAll(crossesToFitWithBMT); + cand.updateCrosses(); + cand.setndf(NewMeasArrays._Y.size() + NewMeasArrays._Y_prime.size() - 4); + double chi2 = cand.calcStraightTrkChi2(); + cand.setchi2(chi2); + cand.setId(cands.size() + 1); + String crossNbs = ""; + for(int ic = 0; ic < cand.size(); ic++) + crossNbs+=cand.get(ic).getId()+"."; + candMap.put(crossNbs, cand); + } + //} + candMap.forEach((key,value) -> cands.add(value)); + } + ArrayList passedcands = this.rmStraightTrkClones(true, cands); + return passedcands; + } + + public void updateCrossesFromTraj(StraightTrack cand, Trajectory trj) { + + double[][][] trajPlaneInters = trj.getSVTIntersections(); + ArrayList hitsOnTrack = new ArrayList<>(); + for (Cross c : cand) { + if (c.getDetector()==DetectorType.BST) { + hitsOnTrack.add(c); + } + } + + for (int j = 0; j < hitsOnTrack.size(); j++) { + + int l1 = hitsOnTrack.get(j).getCluster1().getLayer(); + int s = hitsOnTrack.get(j).getCluster1().getSector(); + double s1 = hitsOnTrack.get(j).getCluster1().getCentroid(); + int l2 = hitsOnTrack.get(j).getCluster2().getLayer(); + double s2 = hitsOnTrack.get(j).getCluster2().getCentroid(); + + double trajX1 = trajPlaneInters[l1 - 1][s - 1][0]; + double trajY1 = trajPlaneInters[l1 - 1][s - 1][1]; + double trajZ1 = trajPlaneInters[l1 - 1][s - 1][2]; + double trajX2 = trajPlaneInters[l2 - 1][s - 1][0]; + double trajY2 = trajPlaneInters[l2 - 1][s - 1][1]; + double trajZ2 = trajPlaneInters[l2 - 1][s - 1][2]; + + if (trajX1 == -999 || trajX2 == -999) { + continue; + } + + hitsOnTrack.get(j).setDir(trj.getRay().getDirVec()); + + } + } + + List SVTcrossesInTrk = new ArrayList<>(); + List BMTCdetcrossesInTrk = new ArrayList<>(); + List BMTZdetcrossesInTrk = new ArrayList<>(); + + public RayMeasurements getRayMeasurementsArrays(ArrayList arrayList, + boolean ignoreErr, boolean resetSVTMeas, boolean useBMTCforZonly) { + + X.clear(); + Y.clear(); + Z.clear(); + Y_prime.clear(); + ErrZ.clear(); + ErrY_prime.clear(); + ErrRt.clear(); + SVTcrossesInTrk.clear(); + BMTCdetcrossesInTrk.clear(); + BMTZdetcrossesInTrk.clear(); + + //make lists + for (Cross c : arrayList) { + if (c.getDetector()==DetectorType.BST) { + SVTcrossesInTrk.add(c); + } + if (c.getDetector()==DetectorType.BMT) { // Micromegas + if (c.getType() == BMTType.C) {//C-detector --> only Z defined + BMTCdetcrossesInTrk.add(c); + } + if (c.getType()==BMTType.Z) {//Z-detector --> only phi defined + BMTZdetcrossesInTrk.add(c); + } + } + } + + ((ArrayList) X).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); + ((ArrayList) Y).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); + ((ArrayList) Z).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); + ((ArrayList) ErrZ).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); + ((ArrayList) ErrRt).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); + ((ArrayList) Y_prime).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); + ((ArrayList) ErrY_prime).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); + + for (int j = 0; j < SVTcrossesInTrk.size(); j++) { + + X.add(j, SVTcrossesInTrk.get(j).getPoint().x()); + Y.add(j, SVTcrossesInTrk.get(j).getPoint().y()); + Z.add(j, SVTcrossesInTrk.get(j).getPoint().z()); + Y_prime.add(j, SVTcrossesInTrk.get(j).getPoint().y()); + ErrY_prime.add(j, SVTcrossesInTrk.get(j).getPointErr().y()); + ErrRt.add(j, Math.sqrt(SVTcrossesInTrk.get(j).getPointErr().x() * SVTcrossesInTrk.get(j).getPointErr().x() + + SVTcrossesInTrk.get(j).getPointErr().y() * SVTcrossesInTrk.get(j).getPointErr().y())); + ErrZ.add(j, SVTcrossesInTrk.get(j).getPointErr().z()); + + } + + if (ignoreErr == true) { + for (int j = 0; j < SVTcrossesInTrk.size(); j++) { + ErrRt.add(j, (double) 1); + ErrY_prime.add(j, (double) 1); + ErrZ.add(j, (double) 1); + } + } + + int j0 = SVTcrossesInTrk.size(); + for (int j = j0; j < j0 + BMTZdetcrossesInTrk.size(); j++) { + X.add(j, BMTZdetcrossesInTrk.get(j - j0).getPoint().x()); + Y.add(j, BMTZdetcrossesInTrk.get(j - j0).getPoint().y()); + ErrRt.add(j, Math.sqrt(BMTZdetcrossesInTrk.get(j - j0).getPointErr().x() * BMTZdetcrossesInTrk.get(j - j0).getPointErr().x() + + BMTZdetcrossesInTrk.get(j - j0).getPointErr().y() * BMTZdetcrossesInTrk.get(j - j0).getPointErr().y())); + } + + if (ignoreErr == true) { + for (int j = j0; j < j0 + BMTZdetcrossesInTrk.size(); j++) { + X.add(j, (double) 1); + Y.add(j, (double) 1); + ErrRt.add(j, (double) 1); + } + } + + for (int j = j0; j < j0 + BMTCdetcrossesInTrk.size(); j++) { + Z.add(j, BMTCdetcrossesInTrk.get(j - j0).getPoint().z()); + Y_prime.add(j, BMTCdetcrossesInTrk.get(j - j0).getPoint().y()); + ErrY_prime.add(j, 0.); + ErrZ.add(j, BMTCdetcrossesInTrk.get(j - j0).getPointErr().z()); + } + + if(BMTCdetcrossesInTrk.size()>1 && useBMTCforZonly==true) { + + Z.clear(); + Y_prime.clear(); + ErrZ.clear(); + ErrY_prime.clear(); + for (int j = 0; j < BMTCdetcrossesInTrk.size(); j++) { + Z.add(j, BMTCdetcrossesInTrk.get(j).getPoint().z()); + Y_prime.add(j, BMTCdetcrossesInTrk.get(j).getPoint().y()); + ErrY_prime.add(j, 0.); + ErrZ.add(j, BMTCdetcrossesInTrk.get(j).getPointErr().z()); + + } + } + RayMeasurements MeasArray = new RayMeasurements(X, Y, Z, Y_prime, ErrZ, ErrY_prime, ErrRt); + + return MeasArray; + } + + /** + * + * @param bmtCrosses the BMT crosses + * @param thecand the straight track candidate + * @return an arraylist of BMT crosses matched to the track + */ + public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCrosses) { + + ArrayList BMTCrossList = new ArrayList<>(); + if (thecand == null) { + return BMTCrossList; + } + + if (bmtCrosses == null || bmtCrosses.isEmpty()) { + return BMTCrossList; + } + + // for configuration in 3 double SVT layers + 3 double BMT layers + //------------------------------------------------------------------------------------------------------ + for(int iregion = 0; iregion < 3; iregion++) { + int region = iregion + 1; + + // match Z crosses + List zCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z), thecand.getRay(), bmtCrosses, + Constants.COSMICSMINRESIDUALX/Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z))); + if(zCross!=null) + BMTCrossList.addAll(zCross); + + // match Z crosses + List cCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.C), thecand.getRay(), bmtCrosses, Constants.COSMICSMINRESIDUALZ); + if(cCross!=null) + BMTCrossList.addAll(cCross); + } + return BMTCrossList; + } + + private List matchTrackToBMT(int layer, Ray ray, List crosses, double matchCut) { + + List matched = new ArrayList<>(); + + for(int is=0; is trajs = new ArrayList<>(); + int ntrajs = Constants.BMTGEOMETRY.getTileSurface(layer, sector).intersection(ray.toLine(), trajs); + if(ntrajs==0) continue; + + // find the closests cross-trajectory match + for(Point3D traj : trajs) { + Cross closestCross = null; + double doca = Double.MAX_VALUE; + + // loop over all BMT crosses + for(Cross c : crosses) { + Cluster cluster = c.getCluster1(); + // consider only the ones in the selected layer + if(cluster.getLayer()!=layer || cluster.getSector()!=sector) continue; + + double residual = cluster.residual(traj); + if(Math.abs(residual) rmStraightTrkClones(boolean removeClones, ArrayList cands) { + ArrayList passedcands = new ArrayList<>(); + if (removeClones == false) { + passedcands = cands; + } + + if (removeClones == true) { + if (cands.size() > 0) { + // clean up duplicates: + for (int k = 0; k < cands.size(); k++) { + for (int k2 = 0; k2 < cands.size(); k2++) { + if (k2 == k) { + continue; + } + int overlaps = 0; + for (int k3 = 0; k3 < cands.get(k).size(); k3++) { + if (cands.get(k2).containsCross(cands.get(k).get(k3))) { + overlaps++; + + } + } + if (overlaps > 1) { + if ((cands.get(k2).getchi2()) > (cands.get(k).getchi2())) { + + cands.get(k2).setId(-999); + + } + } + } + } + for (int k = 0; k < cands.size(); k++) { + if (cands.get(k).getId() != -999) { + passedcands.add(cands.get(k)); + + } + } + } + } + + return passedcands; + } + + private void eliminateStraightTrackOutliers(ArrayList crosses, CosmicFitter track) { + ArrayList toKeep = new ArrayList<>(); + + for(int j = 0; j < crosses.size(); j++) { + Cross c = crosses.get(j); + int layer = c.getCluster1().getLayer(); + int sector = c.getSector(); + + Point3D traj = new Point3D(); + int ntraj = Constants.SVTGEOMETRY.getPlane(layer, sector).intersection(track.getray().toLine(), traj); + + if(ntraj!=1) + c.reset(); + else if(!Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) + c.reset(); + else { + Vector3D distance = Constants.SVTGEOMETRY.toLocal(layer, sector, c.getPoint().vectorTo(traj)); + if(Math.abs(distance.x())>Constants.COSMICSMINRESIDUALX || + Math.abs(distance.z())>Constants.COSMICSMINRESIDUALZ) c.reset(); + else + toKeep.add(c); + } + } + crosses = toKeep; + } + + public void matchClusters(List sVTclusters, TrajectoryFinder tf, boolean trajFinal, + ArrayList trajectory, int k) { + if(trajectory == null) + return; + Collections.sort(sVTclusters); + for (StateVec st : trajectory) { + for (Cluster cls : sVTclusters) { + if (cls.getAssociatedTrackID() != -1) { + continue; + } + if (st.getSurfaceSector() != cls.getSector()) { + continue; + } + if (st.getSurfaceLayer() != cls.getLayer()) { + continue; + } + if (Math.abs(st.getCalcCentroidStrip() - cls.getCentroid()) < 4) { + tf.setHitResolParams("SVT", cls.getSector(), cls.getLayer(), cls, st, trajFinal); + //System.out.println("trying to associate a cluster ");cls.printInfo(); System.out.println(" to "+st.getCalcCentroidStrip()+" dStp = "+(st.getCalcCentroidStrip()-cls.getCentroid())); + cls.setAssociatedTrackID(k); + for (Hit h : cls) { + h.setAssociatedTrackID(k); + } + } + } + } + } + +} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java index 09146f691..cf9d51fe0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/StraightTrackSeeder.java @@ -33,46 +33,43 @@ public StraightTrackSeeder(double xb, double yb) { xbeam = xb; ybeam = yb; //init lists for scan - sortedCrosses = new ArrayList>>(); + sortedCrosses = new ArrayList<>(); for(int b =0; b>() ); + sortedCrosses.add(b, new ArrayList<>() ); for(int l =0; l<3; l++) { - sortedCrosses.get(b).add(l,new ArrayList() ); + sortedCrosses.get(b).add(l,new ArrayList<>() ); } } - scan = new ArrayList>(); - seedMap = new HashMap>(); // init seeds; - seedScan = new ArrayList(); + scan = new ArrayList<>(); + seedMap = new HashMap<>(); // init seeds; + seedScan = new ArrayList<>(); //for fitting - Xs = new ArrayList(); - Ys = new ArrayList(); - Ws = new ArrayList(); + Xs = new ArrayList<>(); + Ys = new ArrayList<>(); + Ws = new ArrayList<>(); } private void MatchSeed(List othercrs) { for (Seed seed : seedScan) { - double d = seed.get_Doca(); - double r = seed.get_Rho(); - double f = seed.get_Phi(); + double d = seed.getDoca(); + double r = seed.getRho(); + double f = seed.getPhi(); - Map matchBMT = new HashMap(); + Map matchBMT = new HashMap<>(); for (Cross c : othercrs ) { -// c.set_AssociatedTrackID(22220); if(this.InSamePhiRange(seed, c)== true) { -// c.set_AssociatedTrackID(22221); - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); if(Math.abs(res)<20) { -// c.set_AssociatedTrackID(22222); // add to seed if(matchBMT.containsKey(c.getOrderedRegion())) { Cross cs = (Cross) matchBMT.get(c.getOrderedRegion()); - double xis = cs.get_Point().x(); - double yis = cs.get_Point().y(); + double xis = cs.getPoint().x(); + double yis = cs.getPoint().y(); double ris = Math.sqrt(xis*xis+yis*yis); double fis = Math.atan2(yis,xis) ; if(Math.abs(this.calcResi(r, ris, d, f, fis))>Math.abs(res)) { @@ -86,7 +83,7 @@ private void MatchSeed(List othercrs) { } // add hashmap items to list for (Cross crs : matchBMT.values()) - seed.get_Crosses().add((Cross) crs); + seed.getCrosses().add((Cross) crs); } } private void FitSeed(List seedcrs) { @@ -100,10 +97,10 @@ private void FitSeed(List seedcrs) { Ys.add(0, this.ybeam); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); - Xs.add(c.get_Point().x()); - Ys.add(c.get_Point().y()); - Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); + if(c.getType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); + Xs.add(c.getPoint().x()); + Ys.add(c.getPoint().y()); + Ws.add(1. / (c.getPointErr().x()*c.getPointErr().x()+c.getPointErr().y()*c.getPointErr().y())); } CircleFitter circlefit = new CircleFitter(xbeam, ybeam); @@ -117,8 +114,8 @@ private void FitSeed(List seedcrs) { boolean failed = false; for (Cross c : seedcrs ) { - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; @@ -136,7 +133,7 @@ private void FitSeed(List seedcrs) { /* Finds BMT seeds */ - public void FindSeedCrossList(List crosses) { + public void findSeedCrossList(List crosses) { seedMap.clear(); @@ -144,7 +141,7 @@ public void FindSeedCrossList(List crosses) { scan.get(si1).clear(); for(int i = 0; i< phiShift.length; i++) { - FindSeedCrossesFixedBin(crosses, phiShift[i]); + findSeedCrossesFixedBin(crosses, phiShift[i]); } seedMap.forEach((key,value) -> this.FitSeed(value)); @@ -154,7 +151,7 @@ public void FindSeedCrossList(List crosses) { /* Scans overphase space to find groups of BMT crosses */ - private void FindSeedCrossesFixedBin(List crosses, double phiShift) { + private void findSeedCrossesFixedBin(List crosses, double phiShift) { for(int b =0; b crosses, double phiShift) { } int[][] LPhi = new int[NBINS][3]; for (int i = 0; i < crosses.size(); i++) { - double phi = Math.toDegrees(crosses.get(i).get_Point().toVector3D().phi()); + double phi = Math.toDegrees(crosses.get(i).getPoint().toVector3D().phi()); phi += phiShift; if (phi < 0) { @@ -172,8 +169,8 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { int binIdx = (int) (phi / (360./NBINS) ); if(binIdx>35) binIdx = 35; - sortedCrosses.get(binIdx).get(crosses.get(i).get_Region() - 1).add(crosses.get(i)); - LPhi[binIdx][crosses.get(i).get_Region() - 1]++; + sortedCrosses.get(binIdx).get(crosses.get(i).getRegion() - 1).add(crosses.get(i)); + LPhi[binIdx][crosses.get(i).getRegion() - 1]++; } for (int b = 0; b < NBINS; b++) { @@ -208,7 +205,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { int s = hits.size(); int index = (int) Math.pow(2,s); for(Cross c : hits) { - seedIdx +=c.get_Id()*Math.pow(10, index); + seedIdx +=c.getId()*Math.pow(10, index); index-=4; } seedMap.put(seedIdx, hits); @@ -220,34 +217,34 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { - List BMTmatches = new ArrayList(); + List BMTmatches = new ArrayList<>(); public List findSeed(List svt_crosses, List bmt_crosses, boolean isSVTOnly) { BMTmatches.clear(); seedScan.clear() ; - List seedlist = new ArrayList(); + List seedlist = new ArrayList<>(); - List crosses = new ArrayList(); - List bmtC_crosses = new ArrayList(); + List crosses = new ArrayList<>(); + List bmtC_crosses = new ArrayList<>(); if(isSVTOnly == false ) { for(Cross c : bmt_crosses) { - if(c.get_Type()== BMTType.Z) + if(c.getType()== BMTType.Z) crosses.add(c); - if(c.get_Type()==BMTType.C) + if(c.getType()==BMTType.C) bmtC_crosses.add(c); } } - //this.FindSeedCrossList(crosses); + //this.findSeedCrossList(crosses); //this.MatchSeed(svt_crosses); - this.FindSeedCrossList(svt_crosses); + this.findSeedCrossList(svt_crosses); this.MatchSeed(crosses); for(Seed mseed : seedScan) { - List seedcrs = mseed.get_Crosses(); + List seedcrs = mseed.getCrosses(); // for (Cross c : seedcrs ) { -// if(c.get_Type()==BMTType.C ) continue; -// c.set_AssociatedTrackID(122220); +// if(c.getType()==BMTType.C ) continue; +// c.setAssociatedTrackID(122220); // } // loop until a good circular fit. removing far crosses each time boolean circlefitstatusOK = false; @@ -263,12 +260,12 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo Ys.add(0, this.ybeam); Ws.add(0, 0.1); for (Cross c : seedcrs ) { - if(c.get_Type()==BMTType.C ) continue; -// c.set_AssociatedTrackID(122221); - Xs.add(c.get_Point().x()); - Ys.add(c.get_Point().y()); - Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x() - +c.get_PointErr().y()*c.get_PointErr().y())); + if(c.getType()==BMTType.C ) continue; +// c.setAssociatedTrackID(122221); + Xs.add(c.getPoint().x()); + Ys.add(c.getPoint().y()); + Ws.add(1. / (c.getPointErr().x()*c.getPointErr().x() + +c.getPointErr().y()*c.getPointErr().y())); } CircleFitter circlefit = new CircleFitter(xbeam, ybeam); @@ -282,15 +279,15 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo double r = pars.rho(); double f = pars.phi(); for (Cross c : seedcrs ) { - if(c.get_Type()==BMTType.C ) continue; -// c.set_AssociatedTrackID(122222); - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); + if(c.getType()==BMTType.C ) continue; +// c.setAssociatedTrackID(122222); + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); if(Math.abs(res)>SVTParameters.RESIMAX) { - //System.out.println(" remove detector " + c .get_Detector() + " region " + c.get_Region() + " sector " + c.get_Sector() ); + //System.out.println(" remove detector " + c .getDetector() + " region " + c.getRegion() + " sector " + c.getSector() ); seedcrs.remove(c); break; } @@ -301,37 +298,37 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo for(Seed mseed : seedScan) { - List seedcrs = mseed.get_Crosses(); + List seedcrs = mseed.getCrosses(); Track cand = null; if(seedcrs.size()>=3) cand = fitSeed(seedcrs, 5, false); if (cand != null) { Seed seed = new Seed(); - seed.set_Crosses(seedcrs); - seed.set_Helix(cand.get_helix()); + seed.setCrosses(seedcrs); + seed.setHelix(cand.getHelix()); //match to BMT if (seed != null ) { - List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses); + List sameSectorCrosses = this.findCrossesInSameSectorAsSVTTrk(seed, bmtC_crosses); BMTmatches.clear(); if (sameSectorCrosses.size() >= 0) { BMTmatches = this.findCandUsingMicroMegas(seed, sameSectorCrosses); } for (Seed bseed : BMTmatches) { - Collections.sort(bseed.get_Crosses()); + Collections.sort(bseed.getCrosses()); //refit using the BMT - Track bcand = fitSeed(bseed.get_Crosses(), 5, false); + Track bcand = fitSeed(bseed.getCrosses(), 5, false); if (bcand != null) { seed = new Seed(); - seed.set_Crosses(bseed.get_Crosses()); - seed.set_Helix(bcand.get_helix()); + seed.setCrosses(bseed.getCrosses()); + seed.setHelix(bcand.getHelix()); } } seedlist.add(seed); } else { - // seedlist.add(seed); System.out.println("no BMT matched"+seed.get_Helix().get_Z0()); + // seedlist.add(seed); System.out.println("no BMT matched"+seed.getHelix().getZ0()); } } } @@ -339,22 +336,22 @@ public List findSeed(List svt_crosses, List bmt_crosses, boo } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { - List bmt_crossesInSec = new ArrayList(); + private List findCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { + List bmt_crossesInSec = new ArrayList<>(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init double jitter = Math.toRadians(10); // 10 degrees jitter for (int i = 0; i < bmt_crosses.size(); i++) { - Point3D ref =seed.get_Crosses().get(0).get_Point(); + Point3D ref =seed.getCrosses().get(0).getPoint(); // the hit parameters double angle = Math.atan2(ref.y(), ref.x()); if (angle < 0) { angle += 2 * Math.PI; } - //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) - // == bmt_crosses.get(i).get_Sector() - 1) - if (Constants.BMTGEOMETRY.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), ref)==true){ + //if (bmt_geo.isInDetector(bmt_crosses.get(i).getRegion()*2-1, angle, jitter) + // == bmt_crosses.get(i).getSector() - 1) + if (Constants.BMTGEOMETRY.inDetector(bmt_crosses.get(i).getRegion()*2-1, bmt_crosses.get(i).getSector(), ref)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -363,16 +360,16 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c return bmt_crossesInSec; } - private List X = new ArrayList(); - private List Y = new ArrayList(); - private List Z = new ArrayList(); - private List Rho = new ArrayList(); - private List ErrZ = new ArrayList(); - private List ErrRho = new ArrayList(); - private List ErrRt = new ArrayList(); - List BMTCrossesC = new ArrayList(); - List BMTCrossesZ = new ArrayList(); - List SVTCrosses = new ArrayList(); + private final List X = new ArrayList<>(); + private final List Y = new ArrayList<>(); + private final List Z = new ArrayList<>(); + private final List Rho = new ArrayList<>(); + private final List ErrZ = new ArrayList<>(); + private final List ErrRho = new ArrayList<>(); + private final List ErrRt = new ArrayList<>(); + private final List BMTCrossesC = new ArrayList<>(); + private final List BMTCrossesZ = new ArrayList<>(); + private final List SVTCrosses = new ArrayList<>(); public Track fitSeed(List VTCrosses, int fitIter, boolean originConstraint) { @@ -398,11 +395,11 @@ public Track fitSeed(List VTCrosses, int fitIter, SVTCrosses.clear(); for (Cross c : VTCrosses) { - if (c.get_Detector() == DetectorType.BST) { + if (c.getDetector() == DetectorType.BST) { SVTCrosses.add(c); - } else if (c.get_Detector() == DetectorType.BMT && c.get_Type() == BMTType.C) { + } else if (c.getDetector() == DetectorType.BMT && c.getType() == BMTType.C) { BMTCrossesC.add(c); - } else if (c.get_Detector() == DetectorType.BMT && c.get_Type() == BMTType.Z) { + } else if (c.getDetector() == DetectorType.BMT && c.getType() == BMTType.Z) { BMTCrossesZ.add(c); } } @@ -428,35 +425,35 @@ public Track fitSeed(List VTCrosses, int fitIter, ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); for (int j = 0; j < SVTCrosses.size(); j++) { - X.add(j, SVTCrosses.get(j).get_Point().x()); - Y.add(j, SVTCrosses.get(j).get_Point().y()); + X.add(j, SVTCrosses.get(j).getPoint().x()); + Y.add(j, SVTCrosses.get(j).getPoint().y()); if (useSVTdipAngEst == 1) { - Z.add(j, SVTCrosses.get(j).get_Point().z()); - Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() - + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); - ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); - ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); + Z.add(j, SVTCrosses.get(j).getPoint().z()); + Rho.add(j, Math.sqrt(SVTCrosses.get(j).getPoint().x() * SVTCrosses.get(j).getPoint().x() + + SVTCrosses.get(j).getPoint().y() * SVTCrosses.get(j).getPoint().y())); + ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).getPointErr().x() * SVTCrosses.get(j).getPointErr().x() + + SVTCrosses.get(j).getPointErr().y() * SVTCrosses.get(j).getPointErr().y())); + ErrZ.add(j, SVTCrosses.get(j).getPointErr().z()); } - ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() - + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); + ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).getPointErr().x() * SVTCrosses.get(j).getPointErr().x() + + SVTCrosses.get(j).getPointErr().y() * SVTCrosses.get(j).getPointErr().y())); } if (bmtZSz > 0) { for (int j = svtSz; j < svtSz + bmtZSz; j++) { - X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); - Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); - ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() - + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); + X.add(j, BMTCrossesZ.get(j - svtSz).getPoint().x()); + Y.add(j, BMTCrossesZ.get(j - svtSz).getPoint().y()); + ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).getPointErr().x() * BMTCrossesZ.get(j - svtSz).getPointErr().x() + + BMTCrossesZ.get(j - svtSz).getPointErr().y() * BMTCrossesZ.get(j - svtSz).getPointErr().y())); } } if (bmtCSz > 0) { for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { - Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); - Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); + Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getPoint().z()); + Rho.add(j, Constants.BMTGEOMETRY.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getCluster1().getLayer())); ErrRho.add(j, Constants.BMTGEOMETRY.getThickness()/2 / Math.sqrt(12.)); - ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); + ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).getPointErr().z()); } } //X.add((double) Constants.getXb()); @@ -465,28 +462,28 @@ public Track fitSeed(List VTCrosses, int fitIter, fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); - if (fitTrk.get_helix() == null) { + if (fitTrk.getHelix() == null) { return null; } - fitTrk.get_helix().B = 0; - cand = new Track(fitTrk.get_helix()); + fitTrk.getHelix().B = 0; + cand = new Track(fitTrk.getHelix()); cand.addAll(SVTCrosses); cand.addAll(BMTCrossesZ); cand.addAll(BMTCrossesC); //if(shift==0) // if(i==0) System.out.println(); -// System.out.println(fitTrk.get_chisq()[0] + " " + chisqMax + " " + Constants.CIRCLEFIT_MAXCHI2); +// System.out.println(fitTrk.getChi2()[0] + " " + chisqMax + " " + Constants.CIRCLEFIT_MAXCHI2); cand.update_Crosses(-1); - if (fitTrk.get_chisq()[0] < chisqMax) { - chisqMax = fitTrk.get_chisq()[0]; + if (fitTrk.getChi2()[0] < chisqMax) { + chisqMax = fitTrk.getChi2()[0]; // if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) cand=null; return cand; @@ -495,14 +492,14 @@ public Track fitSeed(List VTCrosses, int fitIter, public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) { - List> BMTCcrosses = new ArrayList>(); + List> BMTCcrosses = new ArrayList<>(); - ArrayList matches = new ArrayList(); - List AllSeeds = new ArrayList(); + ArrayList matches = new ArrayList<>(); + List AllSeeds = new ArrayList<>(); int[] S = new int[3]; for (int r = 0; r < 3; r++) { - BMTCcrosses.add(new ArrayList()); + BMTCcrosses.add(new ArrayList<>()); } //for (int r = 0; r < 3; r++) { // BMTCcrosses.get(r).clear(); @@ -510,8 +507,8 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_Type()==BMTType.C) {// C-detector - BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); + if (bmt_cross.getType()==BMTType.C) {// C-detector + BMTCcrosses.get(bmt_cross.getRegion() - 1).add(bmt_cross); } } @@ -547,13 +544,13 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) } } - matches.addAll(trkCand.get_Crosses()); + matches.addAll(trkCand.getCrosses()); if (matches.size() > 0) { Seed BMTTrkSeed = new Seed(); - BMTTrkSeed.set_Helix(trkCand.get_Helix()); - BMTTrkSeed.set_Crosses(matches); + BMTTrkSeed.setHelix(trkCand.getHelix()); + BMTTrkSeed.setCrosses(matches); AllSeeds.add(BMTTrkSeed); //if (AllSeeds.size() > 200) { @@ -573,18 +570,18 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { boolean pass = false; - double dzdrsum = trkCand.get_Helix().get_tandip(); + double dzdrsum = trkCand.getHelix().getTanDip(); - double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = Constants.BMTGEOMETRY.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); + double z_bmt = bmt_Ccross.getPoint().z(); + double r_bmt = Constants.BMTGEOMETRY.getRadius(bmt_Ccross.getCluster1().getLayer()); - Point3D refPoint = trkCand.get_Crosses().get(0).get_Point(); - //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.get_Sector()) { - if (Constants.BMTGEOMETRY.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(refPoint.y(), refPoint.x())) != bmt_Ccross.get_Sector()) { + Point3D refPoint = trkCand.getCrosses().get(0).getPoint(); + //if (bmt_geo.isInSector(bmt_Ccross.getCluster1().getLayer(), Math.atan2(refPoint.y(), refPoint.x()), Math.toRadians(10)) != bmt_Ccross.getSector()) { + if (Constants.BMTGEOMETRY.getSector(bmt_Ccross.getCluster1().getLayer(), Math.atan2(refPoint.y(), refPoint.x())) != bmt_Ccross.getSector()) { return false; } double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= SVTParameters.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (trkCand.getCrosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.getCrosses().size() + 1))) <= SVTParameters.DZDRCUT) // add this to the track { pass = true; } @@ -592,19 +589,6 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { return pass; } - private void removeDuplicates(List AllSeeds) { - - Collections.sort(AllSeeds); - List Dupl = new ArrayList(); - for(int i = 1; i < AllSeeds.size(); i++) { - if(AllSeeds.get(i-1).get_IntIdentifier().equalsIgnoreCase(AllSeeds.get(i).get_IntIdentifier())) { - Dupl.add(AllSeeds.get(i)); - } - } - AllSeeds.removeAll(Dupl); - - } - private double calcResi(double r, double ri, double d, double f, double fi) { double res = 0.5*r*ri*ri - (1+r*d)*ri*Math.sin(f-fi)+0.5*r*d*d+d; return res; @@ -612,9 +596,9 @@ private double calcResi(double r, double ri, double d, double f, double fi) { private boolean InSamePhiRange(Seed seed, Cross c) { boolean pass = false; - Cross s = seed.get_Crosses().get(0); - double seedPhi = Math.atan2(s.get_Point().y(), s.get_Point().x()); - double crossPhi = Math.atan2(c.get_Point().y(), c.get_Point().x()); + Cross s = seed.getCrosses().get(0); + double seedPhi = Math.atan2(s.getPoint().y(), s.getPoint().x()); + double crossPhi = Math.atan2(c.getPoint().y(), c.getPoint().x()); if(Math.abs(Math.toDegrees(seedPhi-crossPhi))<8) pass = true; return pass; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index 0f1e07823..37cf32fa8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -9,7 +9,7 @@ import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.track.Measurements.CVTLayer; +import org.jlab.rec.cvt.measurement.MLayer; import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Trajectory; @@ -54,19 +54,19 @@ public Track(Helix helix) { } public Track(Seed seed) { - super(seed.get_Helix()); - this.set_Seed(seed); + super(seed.getHelix()); + this.setSeed(seed); this.setPXYZ(); this.setNDF(seed.getNDF()); this.setChi2(seed.getChi2()); - this.addAll(seed.get_Crosses()); + this.addAll(seed.getCrosses()); } public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) { super(new Helix(kf.KFHelix.getD0(), kf.KFHelix.getPhi0(), kf.KFHelix.getOmega(), kf.KFHelix.getZ0(), kf.KFHelix.getTanL(), kf.KFHelix.getXb(), kf.KFHelix.getYb())); - this.get_helix().B = kf.KFHelix.getB(); + this.getHelix().B = kf.KFHelix.getB(); this.kfIterations = kf.numIter; double c = Constants.LIGHTVEL; //convert from kf representation to helix repr @@ -88,12 +88,12 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) //kfCov[2][2]*=10; //kfCov[4][4]*=10; - this.get_helix().set_covmatrix(kfCov); + this.getHelix().setCovMatrix(kfCov); this.setPXYZ(); this.setNDF(kf.NDF); this.setChi2(kf.chi2); - this.set_Seed(seed); - this.addAll(seed.get_Crosses()); + this.setSeed(seed); + this.addAll(seed.getCrosses()); this.setTrajectories(kf.TrjPoints); } @@ -101,7 +101,7 @@ public Track(Seed seed, org.jlab.clas.tracking.kalmanfilter.helical.KFitter kf) * * @return the charge */ - public int get_Q() { + public int getQ() { return _Q; } @@ -110,23 +110,23 @@ public int get_Q() { * * @param _Q the charge */ - public void set_Q(int _Q) { + public void setQ(int _Q) { this._Q = _Q; } - public double get_Pt() { + public double getPt() { return _Pt; } - public void set_Pt(double _Pt) { + public void setPt(double _Pt) { this._Pt = _Pt; } - public double get_Pz() { + public double getPz() { return _Pz; } - public void set_Pz(double _Pz) { + public void setPz(double _Pz) { this._Pz = _Pz; } @@ -138,7 +138,7 @@ public static long getSerialversionuid() { * * @return the total momentum value */ - public double get_P() { + public double getP() { return _P; } @@ -147,15 +147,15 @@ public double get_P() { * * @param _P the total momentum value */ - public void set_P(double _P) { + public void setP(double _P) { this._P = _P; } - public Seed get_Seed() { + public Seed getSeed() { return _seed; } - public final void set_Seed(Seed seed) { + public final void setSeed(Seed seed) { this._seed = seed; } @@ -164,48 +164,49 @@ public final void set_Seed(Seed seed) { * */ public final void setPXYZ() { - Helix helix = this.get_helix(); + Helix helix = this.getHelix(); if (helix != null) { - set_Q(((int) Math.signum(Constants.getSolenoidScale()) * helix.get_charge())); + setQ(((int) Math.signum(Constants.getSolenoidScale()) * helix.getCharge())); double calcPt = 10; if(Math.abs(helix.B)>0.0001) { calcPt = Constants.LIGHTVEL * helix.radius() * helix.B; } else { calcPt = 100; - set_Q(1); + setQ(1); } double calcPz = 0; - calcPz = calcPt * helix.get_tandip(); + calcPz = calcPt * helix.getTanDip(); double calcP = Math.sqrt(calcPt * calcPt + calcPz * calcPz); - set_Pt(calcPt); - set_Pz(calcPz); - set_P(calcP); + setPt(calcPt); + setPz(calcPz); + setP(calcP); } } /** * Updates the crosses positions based on trajectories or helix + * @param trackId */ public void update_Crosses(int trackId) { for (int i = 0; i < this.size(); i++) { Cross cross = this.get(i); - cross.set_AssociatedTrackID(trackId); + cross.setAssociatedTrackID(trackId); Point3D trackPos = null; Vector3D trackDir = null; - if(this.getTrajectories()!=null && Math.abs(this.get_helix().B)>0.0001) { - int layer = cross.get_Cluster1().get_Layer(); - int index = CVTLayer.getType(cross.get_Detector(), layer).getIndex(); + if(this.getTrajectories()!=null && Math.abs(this.getHelix().B)>0.0001) { + int layer = cross.getCluster1().getLayer(); + int index = MLayer.getType(cross.getDetector(), layer).getIndex(); HitOnTrack traj = this.getTrajectories().get(index); if(traj==null) return; //RDV check why trackPos = new Point3D(traj.x, traj.y, traj.z); trackDir = new Vector3D(traj.px, traj.py, traj.pz).asUnit(); } - else if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { - double R = Math.sqrt(cross.get_Point().x() * cross.get_Point().x() + cross.get_Point().y() * cross.get_Point().y()); - trackPos = this.get_helix().getPointAtRadius(R); - trackDir = this.get_helix().getTrackDirectionAtRadius(R); -// System.out.println("Traj " + cross.get_Cluster1().get_Layer() + " " + helixPos.toString()); -// System.out.println("Cross " + cross.get_Detector().getName() + " " + cross.get_Point().toString()); + else if (this.getHelix() != null && this.getHelix().getCurvature() != 0) { + double R = Math.sqrt(cross.getPoint().x() * cross.getPoint().x() + cross.getPoint().y() * cross.getPoint().y()); + trackPos = this.getHelix().getPointAtRadius(R); + trackDir = this.getHelix().getTrackDirectionAtRadius(R); +// System.out.println("Traj " + cross.getCluster1().getLayer() + " " + helixPos.toString()); +// System.out.println("Cross " + cross.getDetector().getName() + " " + cross.getPoint().toString()); } cross.update(trackPos, trackDir); } @@ -214,11 +215,11 @@ else if (this.get_helix() != null && this.get_helix().get_curvature() != 0) { public void update_Clusters(int trackId) { if(this.getTrajectories()!=null) { - for (int i = 0; i < this.get_Seed().get_Clusters().size(); i++) { - Cluster cluster = this.get_Seed().get_Clusters().get(i); + for (int i = 0; i < this.getSeed().getClusters().size(); i++) { + Cluster cluster = this.getSeed().getClusters().get(i); - int layer = cluster.get_Layer(); - int index = CVTLayer.getType(cluster.get_Detector(), layer).getIndex(); + int layer = cluster.getLayer(); + int index = MLayer.getType(cluster.getDetector(), layer).getIndex(); if(this.getTrajectories().get(index)!=null) // RDV check why it is necessary cluster.update(trackId, this.getTrajectories().get(index)); @@ -236,7 +237,7 @@ public boolean containsCross(Cross cross) { boolean isInTrack = false; for (int i = 0; i < cand.size(); i++) { - if (cand.get(i).get_Id() == cross.get_Id()) { + if (cand.get(i).getId() == cross.getId()) { isInTrack = true; } @@ -257,7 +258,7 @@ public boolean equals(Object obj) { return false; } Track other = (Track) obj; - if (this.get_Id() != other.get_Id()) { + if (this.getId() != other.getId()) { return false; } @@ -274,8 +275,7 @@ public int hashCode() { @Override public int compareTo(Track tr) { -// return ( tr.size() >= this.size() ) ? 1 : -1; - return (tr.get_P() > this.get_P()) ? 1 : -1; + return (tr.getP() > this.getP()) ? 1 : -1; } /** @@ -289,9 +289,9 @@ else if(this.getChi2() > Constants.CHI2CUT * (this.getNDF() + 5)) return false; else if(this.getNDF() < Constants.NDFCUT) return false; - else if(this.get_Pt() < Constants.PTCUT) + else if(this.getPt() < Constants.PTCUT) return false; - else if(Math.abs(this.get_helix().get_Z0()) > Constants.ZRANGE) + else if(Math.abs(this.getHelix().getZ0()) > Constants.ZRANGE) return false; else return true; @@ -322,42 +322,42 @@ else if(this.getNDF()==o.getNDF()) { public boolean overlapWith(Track o) { int nc = 0; for(Cross c : this) { - if(c.get_Type()==BMTType.C) continue; //skim BMTC + if(c.getType()==BMTType.C) continue; //skim BMTC if(o.contains(c)) nc++; } if(nc >1) return true; else return false; } - public Point3D get_TrackPosAtCTOF() { + public Point3D getTrackPosAtCTOF() { return _trackPosAtCTOF; } - public void se_TrackPosAtCTOF(Point3D _TrackPointAtCTOFRadius) { + public void setTrackPosAtCTOF(Point3D _TrackPointAtCTOFRadius) { this._trackPosAtCTOF = _TrackPointAtCTOFRadius; } - public Vector3D get_TrackDirAtCTOF() { + public Vector3D getTrackDirAtCTOF() { return _trackDirAtCTOF; } - public void set_TrackDirAtCTOF(Vector3D _TrackDirAtCTOFRadious) { + public void setTrackDirAtCTOF(Vector3D _TrackDirAtCTOFRadious) { this._trackDirAtCTOF = _TrackDirAtCTOFRadious; } - public double get_PathToCTOF() { + public double getPathToCTOF() { return _pathToCTOF; } - public void set_PathToCTOF(double _pathLength) { + public void setPathToCTOF(double _pathLength) { this._pathToCTOF = _pathLength; } - public String get_PID() { + public String getPID() { return _PID; } - public void set_PID(String _PID) { + public void setPID(String _PID) { this._PID = _PID; } @@ -397,15 +397,15 @@ public int getStatus() { // fills the list of cross ids for crosses belonging to that reconstructed track for (int j = 0; j < this.size(); j++) { // counter to get status word - if (this.get(j).get_Detector() == DetectorType.BST) { + if (this.get(j).getDetector() == DetectorType.BST) { nSVT++; } - if (this.get(j).get_Detector() == DetectorType.BMT - && this.get(j).get_Type() == BMTType.Z) { + if (this.get(j).getDetector() == DetectorType.BMT + && this.get(j).getType() == BMTType.Z) { nBMTZ++; } - if (this.get(j).get_Detector() == DetectorType.BMT - && this.get(j).get_Type() == BMTType.C) { + if (this.get(j).getDetector() == DetectorType.BMT + && this.get(j).getType() == BMTType.C) { nBMTC++; } } @@ -430,8 +430,8 @@ public void setTrackCovMat(double[][] trackCovMat) { @Override public String toString() { String str = String.format("Track id=%d, q=%d, p=%.3f GeV pt=%.3f GeV, phi=%.3f deg, NDF=%d, chi2=%.3f, seed method=%d\n", - this.get_Id(), this.get_Q(), this.get_P(), this.get_Pt(), Math.toDegrees(this.get_helix().get_phi_at_dca()), - this.getNDF(), this.getChi2(), this.get_Seed().get_Status()); + this.getId(), this.getQ(), this.getP(), this.getPt(), Math.toDegrees(this.getHelix().getPhiAtDCA()), + this.getNDF(), this.getChi2(), this.getSeed().getStatus()); for(Cross c: this) str = str + c.toString() + "\n"; return str; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java deleted file mode 100644 index a22b7d75f..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackCandListFinder.java +++ /dev/null @@ -1,1171 +0,0 @@ -package org.jlab.rec.cvt.track; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.base.DetectorType; - -import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Vector3D; -import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTConstants; -import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.cluster.Cluster; -import org.jlab.rec.cvt.cross.Cross; -import org.jlab.rec.cvt.cross.CrossList; -import org.jlab.rec.cvt.fit.HelicalTrackFitter; -import org.jlab.rec.cvt.fit.LineFitter; -import org.jlab.rec.cvt.fit.CosmicFitter; -import org.jlab.rec.cvt.fit.LineFitPars; -import org.jlab.rec.cvt.hit.Hit; -import org.jlab.rec.cvt.svt.SVTGeometry; -import org.jlab.rec.cvt.svt.SVTParameters; -import org.jlab.rec.cvt.trajectory.Ray; -import org.jlab.rec.cvt.trajectory.StateVec; -import org.jlab.rec.cvt.trajectory.Trajectory; -import org.jlab.rec.cvt.trajectory.TrajectoryFinder; - -/** - * A class with a method implementing an algorithm that finds lists of track - * candidates in the BST - * - * @author ziegler - * - */ -public class TrackCandListFinder { - - public TrackCandListFinder() { - X = new ArrayList(); - Y = new ArrayList(); - Z = new ArrayList(); - Rho = new ArrayList(); - ErrZ = new ArrayList(); - ErrRho = new ArrayList(); - ErrRt = new ArrayList(); - Y_prime = new ArrayList(); - ErrY_prime = new ArrayList(); - } - - private List X; // x coordinate array - private List Y; // y coordinate array (same size as X array) - private List Z; // z coordinate array - private List Rho; // rho (= sqrt(x^2 + y^2) for SVT; detector radius for BMT) coordinate array (same size as Z array) - private List ErrZ; // z uncertainty (same size as Z array) - private List ErrRho; // rho uncertainty (same size as Z array) - private List ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) - private List Y_prime; // y coordinate array - private List ErrY_prime; - - /** - * A class representing the measurement variables used to fit a helical - * track The track fitting algorithm employs the Karimaki algorithm to - * determine the circle fit paramters: the doca to the z axis, the phi at - * the doca, the curvature; and a linear regression line fitting algorithm - * to determine z at the doca and the helix dip angle - * - * @author ziegler - * - */ - private class HelixMeasurements { - - List _X; // x coordinate array - List _Y; // y coordinate array (same size as X array) - List _Z; // z coordinate array - List _Rho; // rho (= sqrt(x^2 + y^2) for SVT; detector radius for BMT) coordinate array (same size as Z array) - List _ErrZ; // z uncertainty (same size as Z array) - List _ErrRho; // rho uncertainty (same size as Z array) - List _ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) - - HelixMeasurements(List X, - List Y, - List Z, - List Rho, - List ErrZ, - List ErrRho, - List ErrRt) { - this._X = X; - this._Y = Y; - this._Z = Z; - this._Rho = Rho; - this._ErrZ = ErrZ; - this._ErrRho = ErrRho; - this._ErrRt = ErrRt; - } - } - - /** - * A class representing the measurement variables used to fit a straight - * track - * - * @author ziegler - * - */ - public class RayMeasurements { - - public List _X; // x coordinate array - public List _Y; // y coordinate array (same size as X array) - public List _Z; // z coordinate array - public List _Y_prime; // y coordinate array (same size as Z array) - public List _ErrZ; // z uncertainty (same size as Z array) - public List _ErrY_prime; // y uncertainty (same size as Z array) - public List _ErrRt; // sqrt(x^2 + y^2) uncertainty array (same size as X & Y arrays) - - RayMeasurements(List X, - List Y, - List Z, - List Y_prime, - List ErrZ, - List ErrY_prime, - List ErrRt) { - this._X = X; - this._Y = Y; - this._Z = Z; - this._Y_prime = Y_prime; - this._ErrZ = ErrZ; - this._ErrY_prime = ErrY_prime; - this._ErrRt = ErrRt; - } - } - - /** - * NOT Used - * @param list the input list of crosses - * @return an array list of track candidates in the SVT - */ - public void getHelicalTrack(Seed cand, double xb, double yb) { - X.clear(); - Y.clear(); - Z.clear(); - Rho.clear(); - ErrZ.clear(); - ErrRho.clear(); - ErrRt.clear(); - - List list = cand.get_Crosses(); - - if (list.size() == 0) { - //System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); - return; - } - // instantiating the Helical Track fitter - HelicalTrackFitter fitTrk = new HelicalTrackFitter(); - // sets the index according to assumption that the track comes from the origin or not - int shift = 0; - // if(org.jlab.rec.cvt.BMTConstants.TRACKSFROMORIGIN) - // shift =1; - - // interate the fit a number of times set in the constants file - int Max_Number_Of_Iterations = SVTParameters.BSTTRKINGNUMBERITERATIONS; - - // loop over the cross list and do the fits to the crosses - if (list.size() >= org.jlab.rec.cvt.Constants.MINSVTCRSFORCOSMIC) { - // for debugging purposes only sets all errors to 1 - boolean ignoreErr = SVTParameters.ignoreErr; - - int Number_Of_Iterations = 0; - // do till the number of iterations is reached - while (Number_Of_Iterations <= Max_Number_Of_Iterations) { - Number_Of_Iterations++; - fitTrk = new HelicalTrackFitter(); - // get the measuerement arrays for the helical track fit - HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(list, xb, yb, shift, ignoreErr, false); - - X = MeasArrays._X; - Y = MeasArrays._Y; - Z = MeasArrays._Z; - Rho = MeasArrays._Rho; - ErrZ = MeasArrays._ErrZ; - ErrRho = MeasArrays._ErrRho; - ErrRt = MeasArrays._ErrRt; - - // do the fit to X, Y taking ErrRt uncertainties into account to get the circle fit params, - // and do the fit to Rho, Z taking into account the uncertainties in Rho and Z into account to get the linefit params - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); - - // if the fit failed then use the uncorrected SVT points since the z-correction in resetting the SVT cross points sometimes fails - if (fitTrk.get_helix() == null) { - //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - MeasArrays = this.get_HelixMeasurementsArrays(list, xb, yb, shift, ignoreErr, true); - - X = MeasArrays._X; - Y = MeasArrays._Y; - Z = MeasArrays._Z; - Rho = MeasArrays._Rho; - ErrZ = MeasArrays._ErrZ; - ErrRho = MeasArrays._ErrRho; - ErrRt = MeasArrays._ErrRt; - - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); - Number_Of_Iterations = Max_Number_Of_Iterations + 1; - //if(fitTrk.get_helix()==null) - //System.err.println("Error in Helical Track fitting -- helix not found -- refit FAILED"); - } - - // if the fit is successful - if (fitTrk.get_helix() != null && fitTrk.getFit() != null) { - cand.set_Helix(fitTrk.get_helix()); - } - } - } - // remove clones - - } - - /** - * Not used - * @param crossList the input list of crosses - * @return an array list of track candidates in the SVT - */ - public ArrayList getHelicalTracks(CrossList crossList, double xb, double yb, Swim swimmer) { - - X.clear(); - Y.clear(); - Z.clear(); - Rho.clear(); - ErrZ.clear(); - ErrRho.clear(); - ErrRt.clear(); - - ArrayList cands = new ArrayList(); - - if (crossList.size() == 0) { - System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); - return cands; - } - // instantiating the Helical Track fitter - HelicalTrackFitter fitTrk = new HelicalTrackFitter(); - // sets the index according to assumption that the track comes from the origin or not - int shift = 0; - if (Constants.TRACKSFROMORIGIN) { - shift = 1; - } - - // interate the fit a number of times set in the constants file - int Max_Number_Of_Iterations = SVTParameters.BSTTRKINGNUMBERITERATIONS; - - // loop over the cross list and do the fits to the crosses - for (int i = 0; i < crossList.size(); i++) { - // for debugging purposes only sets all errors to 1 - boolean ignoreErr = SVTParameters.ignoreErr; - - int Number_Of_Iterations = 0; - // do till the number of iterations is reached - while (Number_Of_Iterations <= Max_Number_Of_Iterations) { - Number_Of_Iterations++; - fitTrk = new HelicalTrackFitter(); - // get the measuerement arrays for the helical track fit - HelixMeasurements MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), xb, yb, shift, ignoreErr, false); - - X = MeasArrays._X; - Y = MeasArrays._Y; - Z = MeasArrays._Z; - Rho = MeasArrays._Rho; - ErrZ = MeasArrays._ErrZ; - ErrRho = MeasArrays._ErrRho; - ErrRt = MeasArrays._ErrRt; - - // do the fit to X, Y taking ErrRt uncertainties into account to get the circle fit params, - // and do the fit to Rho, Z taking into account the uncertainties in Rho and Z into account to get the linefit params - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); - - // if the fit failed then use the uncorrected SVT points since the z-correction in resetting the SVT cross points sometimes fails - if (fitTrk.get_helix() == null) { - //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - MeasArrays = this.get_HelixMeasurementsArrays(crossList.get(i), xb, yb, shift, ignoreErr, true); - - X = MeasArrays._X; - Y = MeasArrays._Y; - Z = MeasArrays._Z; - Rho = MeasArrays._Rho; - ErrZ = MeasArrays._ErrZ; - ErrRho = MeasArrays._ErrRho; - ErrRt = MeasArrays._ErrRt; - - fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ, xb, yb); - Number_Of_Iterations = Max_Number_Of_Iterations + 1; - //if(fitTrk.get_helix()==null) - //System.err.println("Error in Helical Track fitting -- helix not found -- refit FAILED"); - } - - // if the fit is successful - if (fitTrk.get_helix() != null && fitTrk.getFit() != null) { - Seed seed = new Seed(crossList.get(i), fitTrk.get_helix()); - Track cand = new Track(seed); - //cand.setPXYZ(fitTrk.get_helix()); done in Track constructor - //cand.updateCrosses(svt_geo); - - cand.get_Seed().set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params - cand.get_Seed().set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params - - if (Number_Of_Iterations == Max_Number_Of_Iterations) { - cands.add(cand); // dump the cand - } - } - } - } - // remove clones - ArrayList passedcands = this.rmHelicalTrkClones(SVTParameters.removeClones, cands); - // loop over candidates and set the trajectories - -// for (int ic = 0; ic < passedcands.size(); ic++) { -// Helix trkHelix = passedcands.get(ic).get_helix(); -// if(trkHelix!=null) { -// TrajectoryFinder trjFind = new TrajectoryFinder(); -// -// //Trajectory traj = trjFind.findTrajectory(passedcands.get(ic).get_Id(), trkHelix, passedcands.get(ic), svt_geo, bmt_geo, "final"); -// Trajectory traj = trjFind.findTrajectory(ic+1, passedcands.get(ic), svt_geo, bmt_geo, ctof_geo, cnd_geo, swimmer, "final"); -// -// passedcands.get(ic).set_Trajectory(traj.get_Trajectory()); -// -// passedcands.get(ic).set_Id(ic+1); -// } -// -// } - - return passedcands; - - } - - /** - * - * @param SVTCrossList the input list of crosses - * @return an array list of track candidates in the SVT - */ - public ArrayList getStraightTracks(CrossList SVTCrosses, List BMTCrosses) { - - ArrayList cands = new ArrayList(); - Map candMap= new HashMap(); - - if (SVTCrosses.size() == 0) { - System.err.print("Error in estimating track candidate trajectory: less than 3 crosses found"); - return cands; - } - - CosmicFitter fitTrk = new CosmicFitter(); - for (int i = 0; i < SVTCrosses.size(); i++) { - ArrayList crossesToFit = new ArrayList(); - // remove SVT regions - // remove the crosses from the exluded region to fit the track - for (Cross crossInTrackToFit : SVTCrosses.get(i)) { - if (crossInTrackToFit.get_Region() != SVTParameters.BSTEXCLUDEDFITREGION) { - crossesToFit.add(crossInTrackToFit); - } - } - - if (crossesToFit.size() < org.jlab.rec.cvt.Constants.MINSVTCRSFORCOSMIC) { - continue; - } - - //fitTrk = new CosmicFitter(); - RayMeasurements MeasArrays = this.get_RayMeasurementsArrays(crossesToFit, false, false, false); - - LineFitter linefitYX = new LineFitter(); - boolean linefitresultYX = linefitYX.fitStatus(MeasArrays._Y, MeasArrays._X, MeasArrays._ErrRt, null, MeasArrays._Y.size()); - - // prelim cross corrections - LineFitPars linefitparsYX = linefitYX.getFit(); - StraightTrack cand = new StraightTrack(null); - cand.addAll(crossesToFit); - if (linefitresultYX && linefitparsYX != null) { - cand.updateCrosses(linefitparsYX.getYXRay()); - } - // update measurements - MeasArrays = this.get_RayMeasurementsArrays(crossesToFit, false, false, false); - - // fit SVt crosses - fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); - //create the cand - if (fitTrk.get_ray() != null) { - //refit - MeasArrays = this.get_RayMeasurementsArrays(crossesToFit, false, false, false); - fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); - - cand = new StraightTrack(fitTrk.get_ray()); - cand.addAll(crossesToFit); - } - if (fitTrk.get_ray() == null) { - //System.err.println("Error in Track fitting -- ray not found -- trying to refit using the uncorrected crosses..."); - MeasArrays = this.get_RayMeasurementsArrays(crossesToFit, false, true, false); - - fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); - //create the cand - //refit - MeasArrays = this.get_RayMeasurementsArrays(crossesToFit, false, false, false); - fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); - - cand = new StraightTrack(fitTrk.get_ray()); - cand.addAll(crossesToFit); - - if (fitTrk.get_ray() == null) { - continue; - } - //System.err.println("Error in Track fitting -- track not found -- refit FAILED"); - } - cand.updateCrosses(); -// System.out.println(cand.get_ray().toLine().origin().toString() + " " -// + Math.toDegrees(cand.get_ray().toLine().direction().theta()) + " " -// + Math.toDegrees(cand.get_ray().toLine().direction().phi()) + " "); - // eliminate bad residuals - this.EliminateStraightTrackOutliers(crossesToFit, fitTrk); - if (crossesToFit.size() < org.jlab.rec.cvt.Constants.MINSVTCRSFORCOSMIC) { - continue; - } - - fitTrk.fit(MeasArrays._X, MeasArrays._Y, MeasArrays._Z, MeasArrays._Y_prime, MeasArrays._ErrRt, MeasArrays._ErrY_prime, MeasArrays._ErrZ); - //create the cand - if (fitTrk.get_ray() != null) { - cand = new StraightTrack(fitTrk.get_ray()); - cand.addAll(crossesToFit); - cand.updateCrosses(); - - } - - // match to Micromegas - ArrayList crossesToFitWithBMT = new ArrayList(); - //crossesToFitWithBMT.addAll(crossesToFit); - - //ArrayList BMTmatches = this.matchTrackToBMT(BMTCrosses, cand, bmt_geo); - //crossesToFitWithBMT.addAll(BMTmatches); - ArrayList BMTmatches = new ArrayList(); - ArrayList SVTmatches = new ArrayList(); - // reset the arrays - RayMeasurements NewMeasArrays = new RayMeasurements(null, null, null, null, null, null, null); - - //for (int iter = 0; iter < 11; iter++) { - // refit with Micromegas - crossesToFitWithBMT.clear(); - SVTmatches.clear(); - for (Cross c : cand) { - if (c.get_Detector()==DetectorType.BST && Constants.SVTGEOMETRY.isInFiducial(c.get_Region()*2-1, c.get_Sector(), c.get_Point())) { - SVTmatches.add(c); - } - } - BMTmatches.clear(); - BMTmatches = this.matchTrackToBMT(cand, BMTCrosses); - - //crossesToFitWithBMT.addAll(SVTmatches); - crossesToFitWithBMT.addAll(BMTmatches); - - NewMeasArrays = this.get_RayMeasurementsArrays(BMTmatches, false, false, true); - fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); - cand.addAll(crossesToFitWithBMT); -// cand.reset_Crosses(); - cand.updateCrosses(); - NewMeasArrays = this.get_RayMeasurementsArrays(cand, false, false, true); - fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); - crossesToFitWithBMT.clear(); - crossesToFitWithBMT.addAll(cand); - //create the cand - - if (fitTrk.get_ray() != null) { -// System.out.println(fitTrk.get_ray().toLine().origin().toString() + " " -// + Math.toDegrees(fitTrk.get_ray().toLine().direction().theta()) + " " -// + Math.toDegrees(fitTrk.get_ray().toLine().direction().phi()) + " "); - cand = new StraightTrack(fitTrk.get_ray()); - cand.addAll(crossesToFitWithBMT); - cand.updateCrosses(); - //refit not using only BMT to fit the z profile - NewMeasArrays = this.get_RayMeasurementsArrays(crossesToFitWithBMT, false, false, false); - fitTrk.fit(NewMeasArrays._X, NewMeasArrays._Y, NewMeasArrays._Z, NewMeasArrays._Y_prime, NewMeasArrays._ErrRt, NewMeasArrays._ErrY_prime, NewMeasArrays._ErrZ); - cand = new StraightTrack(fitTrk.get_ray()); - cand.addAll(crossesToFitWithBMT); - cand.updateCrosses(); - cand.set_ndf(NewMeasArrays._Y.size() + NewMeasArrays._Y_prime.size() - 4); - double chi2 = cand.calc_straightTrkChi2(); - cand.set_chi2(chi2); - cand.set_Id(cands.size() + 1); - String crossNbs = ""; - for(int ic = 0; ic < cand.size(); ic++) - crossNbs+=cand.get(ic).get_Id()+"."; - candMap.put(crossNbs, cand); - } - //} - candMap.forEach((key,value) -> cands.add(value)); - } - - //ArrayList passedcands = this.rmStraightTrkClones(org.jlab.rec.cvt.svt.BMTConstants.removeClones, cands); - ArrayList passedcands = this.rmStraightTrkClones(true, cands); - -// for (int ic = 0; ic < passedcands.size(); ic++) { -// -// Ray trkRay = passedcands.get(ic).get_ray(); -// if(trkRay!=null) { -// TrajectoryFinder trjFind = new TrajectoryFinder(); -// -// //Trajectory traj = trjFind.findTrajectory(passedcands.get(ic).get_Id(), trkRay, passedcands.get(ic), svt_geo, bmt_geo); -// Trajectory traj = trjFind.findTrajectory(ic+1, trkRay, passedcands.get(ic), svt_geo, bmt_geo); -// -// passedcands.get(ic).set_Trajectory(traj.get_Trajectory()); -// -// passedcands.get(ic).set_Id(ic+1); -// -// this.upDateCrossesFromTraj(passedcands.get(ic), traj, svt_geo); -// } -// -// } - - return passedcands; - } - - public void upDateCrossesFromTraj(StraightTrack cand, Trajectory trj) { - - double[][][] trajPlaneInters = trj.get_SVTIntersections(); - ArrayList hitsOnTrack = new ArrayList(); - for (Cross c : cand) { - if (c.get_Detector()==DetectorType.BST) { - hitsOnTrack.add(c); - } - } - - for (int j = 0; j < hitsOnTrack.size(); j++) { - - int l1 = hitsOnTrack.get(j).get_Cluster1().get_Layer(); - int s = hitsOnTrack.get(j).get_Cluster1().get_Sector(); - double s1 = hitsOnTrack.get(j).get_Cluster1().get_Centroid(); - int l2 = hitsOnTrack.get(j).get_Cluster2().get_Layer(); - double s2 = hitsOnTrack.get(j).get_Cluster2().get_Centroid(); - - double trajX1 = trajPlaneInters[l1 - 1][s - 1][0]; - double trajY1 = trajPlaneInters[l1 - 1][s - 1][1]; - double trajZ1 = trajPlaneInters[l1 - 1][s - 1][2]; - double trajX2 = trajPlaneInters[l2 - 1][s - 1][0]; - double trajY2 = trajPlaneInters[l2 - 1][s - 1][1]; - double trajZ2 = trajPlaneInters[l2 - 1][s - 1][2]; - - if (trajX1 == -999 || trajX2 == -999) { - continue; - } - - //Point3D Point = geo.recalcCrossFromTrajectoryIntersWithModulePlanes(s, s1, s2, l1, l2, trajX1, trajY1, trajZ1, trajX2, trajY2, trajZ2); - - //set the cross to that point - //System.out.println(" trajX1 "+trajX1+" trajY1 "+trajY1+" trajZ1 "+trajZ1+" trajX2 "+trajX2+" trajY2 "+trajY2+" trajZ2 "+trajZ2); - //hitsOnTrack.get(j).set_Point(Point); - - hitsOnTrack.get(j).set_Dir(trj.get_ray().get_dirVec()); - - } - } - - private HelixMeasurements get_HelixMeasurementsArrays(List list, - double xb, double yb, int shift, boolean ignoreErr, boolean resetSVTMeas) { - X.clear(); - Y.clear(); - Z.clear(); - Rho.clear(); - ErrZ.clear(); - ErrRho.clear(); - ErrRt.clear(); - SVTcrossesInTrk.clear(); - BMTCdetcrossesInTrk.clear(); - BMTZdetcrossesInTrk.clear(); - - //make lists - for (Cross c : list) { - - if (c.get_Detector()==DetectorType.BST) { - SVTcrossesInTrk.add(c); - } - if (c.get_Detector()==DetectorType.BMT) { // Micromegas - if (c.get_Type() == BMTType.C) {//C-detector --> only Z defined - BMTCdetcrossesInTrk.add(c); - } - if (c.get_Type() == BMTType.Z) {//Z-detector --> only phi defined - BMTZdetcrossesInTrk.add(c); - } - } - } - - ((ArrayList) X).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); - ((ArrayList) Y).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); - ((ArrayList) Z).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); - ((ArrayList) ErrZ).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); - ((ArrayList) ErrRt).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size()); - ((ArrayList) Rho).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); - ((ArrayList) ErrRho).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size()); - - ((ArrayList) X).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size() + shift); - ((ArrayList) Y).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size() + shift); - ((ArrayList) Z).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size() ); - ((ArrayList) Rho).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size() + shift); - ((ArrayList) ErrZ).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size() ); - ((ArrayList) ErrRho).ensureCapacity(SVTcrossesInTrk.size() + BMTCdetcrossesInTrk.size() + shift); - ((ArrayList) ErrRt).ensureCapacity(SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size() + shift); - - if (shift == 1) { - //X.add(0, (double) 0); - //Y.add(0, (double) 0); - double rb = Math.sqrt(xb*xb+yb*yb); - X.add(0, xb); - Y.add(0, yb); - //Z.add(0, (double) 0); - //Rho.add(0, (double) 0); - Rho.add(0, (double) rb); - //ErrRt.add(0, org.jlab.rec.cvt.svt.BMTConstants.RHOVTXCONSTRAINT); - ErrRt.add(0, Constants.getRbErr()); - //ErrZ.add(0, org.jlab.rec.cvt.svt.BMTConstants.ZVTXCONSTRAINT); - //ErrRho.add(0, org.jlab.rec.cvt.svt.BMTConstants.RHOVTXCONSTRAINT); - ErrRho.add(0, Constants.getRbErr()); - } - - for (int j = shift; j < shift + SVTcrossesInTrk.size(); j++) { - - X.add(j, SVTcrossesInTrk.get(j - shift).get_Point().x()); - Y.add(j, SVTcrossesInTrk.get(j - shift).get_Point().y()); - Z.add(j, SVTcrossesInTrk.get(j - shift-1).get_Point().z()); - Rho.add(j, Math.sqrt(SVTcrossesInTrk.get(j - shift).get_Point().x() * SVTcrossesInTrk.get(j - shift).get_Point().x() - + SVTcrossesInTrk.get(j - shift).get_Point().y() * SVTcrossesInTrk.get(j - shift).get_Point().y())); - ErrRho.add(j, Math.sqrt(SVTcrossesInTrk.get(j - shift).get_PointErr().x() * SVTcrossesInTrk.get(j - shift).get_PointErr().x() - + SVTcrossesInTrk.get(j - shift).get_PointErr().y() * SVTcrossesInTrk.get(j - shift).get_PointErr().y())); - ErrRt.add(j, Math.sqrt(SVTcrossesInTrk.get(j - shift).get_PointErr().x() * SVTcrossesInTrk.get(j - shift).get_PointErr().x() - + SVTcrossesInTrk.get(j - shift).get_PointErr().y() * SVTcrossesInTrk.get(j - shift).get_PointErr().y())); - ErrZ.add(j, SVTcrossesInTrk.get(j - shift-1).get_PointErr().z()); - - } - - if (ignoreErr == true) { - for (int j = 0; j < shift + SVTcrossesInTrk.size(); j++) { - ErrRt.add(j, (double) 1); - ErrRho.add(j, (double) 1); - ErrZ.add(j, (double) 1); - } - } - int j0 = SVTcrossesInTrk.size(); - for (int j = shift + j0; j < shift + j0 + BMTZdetcrossesInTrk.size(); j++) { - X.add(j, BMTZdetcrossesInTrk.get(j - shift - j0).get_Point().x()); - Y.add(j, BMTZdetcrossesInTrk.get(j - shift - j0).get_Point().y()); - ErrRt.add(j, Math.sqrt(BMTZdetcrossesInTrk.get(j - shift - j0).get_PointErr().x() * BMTZdetcrossesInTrk.get(j - shift - j0).get_PointErr().x() - + BMTZdetcrossesInTrk.get(j - shift - j0).get_PointErr().y() * BMTZdetcrossesInTrk.get(j - shift - j0).get_PointErr().y())); - } - - if (ignoreErr == true) { - for (int j = shift + SVTcrossesInTrk.size(); j < shift + SVTcrossesInTrk.size() + BMTZdetcrossesInTrk.size(); j++) { - X.add(j, (double) 1); - Y.add(j, (double) 1); - ErrRt.add(j, (double) 1); - } - } - - for (int j = shift + j0; j < shift + j0 + BMTCdetcrossesInTrk.size(); j++) { - Z.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().z()); - Rho.add(j, BMTConstants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1] + BMTConstants.hDrift/2); - System.out.println(BMTCdetcrossesInTrk.get(j - shift - j0).get_Point().toString() + " " + BMTConstants.getCRCRADIUS()[BMTCdetcrossesInTrk.get(j - shift - j0).get_Region() - 1]); - ErrRho.add(j, 0.01); // check this error on thickness measurement - ErrZ.add(j, BMTCdetcrossesInTrk.get(j - shift - j0).get_PointErr().z()); - - } - if (resetSVTMeas) { - //System.err.println("Error in Helical Track fitting -- helix not found -- trying to refit using the uncorrected crosses..."); - for (int j = shift; j < shift + j0; j++) { - X.add(j, SVTcrossesInTrk.get(j - shift).get_Point0().x()); - Y.add(j, SVTcrossesInTrk.get(j - shift).get_Point0().y()); - Z.add(j, SVTcrossesInTrk.get(j - shift-1).get_Point0().z()); - ErrRho.add(j, Math.sqrt(SVTcrossesInTrk.get(j - shift).get_PointErr().x() * SVTcrossesInTrk.get(j - shift).get_PointErr().x() - + SVTcrossesInTrk.get(j - shift).get_PointErr().y() * SVTcrossesInTrk.get(j - shift).get_PointErr().y())); - ErrZ.add(j, SVTcrossesInTrk.get(j - shift-1).get_PointErr0().z()); - } - } - // if(BMTConstants.DEBUGMODE) { - // System.out.println(" FIT ARRAYS "); - // for(int i =0; i1 && useBMTCforZonly==true) { - - Z.clear(); - Y_prime.clear(); - ErrZ.clear(); - ErrY_prime.clear(); - for (int j = 0; j < BMTCdetcrossesInTrk.size(); j++) { - Z.add(j, BMTCdetcrossesInTrk.get(j).get_Point().z()); - Y_prime.add(j, BMTCdetcrossesInTrk.get(j).get_Point().y()); - ErrY_prime.add(j, 0.); - ErrZ.add(j, BMTCdetcrossesInTrk.get(j).get_PointErr().z()); - - } - } - RayMeasurements MeasArray = new RayMeasurements(X, Y, Z, Y_prime, ErrZ, ErrY_prime, ErrRt); - - return MeasArray; - } - - /** - * - * @param bmtCrosses the BMT crosses - * @param thecand the straight track candidate - * @return an arraylist of BMT crosses matched to the track - */ - public ArrayList matchTrackToBMT(StraightTrack thecand, List bmtCrosses) { - - ArrayList BMTCrossList = new ArrayList(); - if (thecand == null) { - return BMTCrossList; - } - - if (bmtCrosses == null || bmtCrosses.isEmpty()) { - return BMTCrossList; - } - - // for configuration in 3 double SVT layers + 3 double BMT layers - //------------------------------------------------------------------------------------------------------ - for(int iregion = 0; iregion < 3; iregion++) { - int region = iregion + 1; - - // match Z crosses - List zCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z), thecand.get_ray(), bmtCrosses, - Constants.COSMICSMINRESIDUALX/Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(region, BMTType.Z))); - if(zCross!=null) - BMTCrossList.addAll(zCross); - - // match Z crosses - List cCross = this.matchTrackToBMT(Constants.BMTGEOMETRY.getLayer(region, BMTType.C), thecand.get_ray(), bmtCrosses, Constants.COSMICSMINRESIDUALZ); - if(cCross!=null) - BMTCrossList.addAll(cCross); - -// // match Z crosses -// ArrayList zCrosses = this.MatchMMCrossZ(iregion + 1, thecand.get_ray(), bmtCrosses, Math.toRadians(2), geo); // 2 degrees opening angle -// if (zCrosses.size() > 0) { -// BMTCrossList.addAll(zCrosses); -// } -// -// ArrayList cCrosses = this.MatchMMCrossC(iregion + 1, thecand.get_ray(), bmtCrosses, SVTParameters.COSMICSMINRESIDUAL, geo); -// if (cCrosses.size() > 0) { -// BMTCrossList.addAll(cCrosses); -// } -// -// for (Cross Ccross : cCrosses) { -// for (Cross Zcross : zCrosses) { -// if ((Ccross.get_Cluster1().get_Layer() - Zcross.get_Cluster1().get_Layer()) == 1 && (Ccross.get_Cluster1().get_Sector() == Zcross.get_Cluster1().get_Sector())) { -// Ccross.set_MatchedZCross(Zcross); -// Zcross.set_MatchedCCross(Ccross); -// } -// } -// } - } - return BMTCrossList; - } - - private List matchTrackToBMT(int layer, Ray ray, List crosses, double matchCut) { - - List matched = new ArrayList<>(); - - for(int is=0; is trajs = new ArrayList<>(); - int ntrajs = Constants.BMTGEOMETRY.getTileSurface(layer, sector).intersection(ray.toLine(), trajs); - if(ntrajs==0) continue; - - // find the closests cross-trajectory match - for(Point3D traj : trajs) { - Cross closestCross = null; - double doca = Double.MAX_VALUE; - - // loop over all BMT crosses - for(Cross c : crosses) { - Cluster cluster = c.get_Cluster1(); - // consider only the ones in the selected layer - if(cluster.get_Layer()!=layer || cluster.get_Sector()!=sector) continue; - - double residual = cluster.residual(traj); - if(Math.abs(residual) MatchMMCrossC(int Region, Ray ray, List MMCrosses, double matchCutOff) { - - ArrayList matchedMMCrosses = new ArrayList(); - - double R = Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(Region,BMTType.C)); // R for C detector - - double sx = ray.get_yxslope(); - double ix = ray.get_yxinterc(); - double sz = ray.get_yzslope(); - double iz = ray.get_yzinterc(); - - double D = sx * sx * ix * ix - (1 + sx * sx) * (ix * ix - R * R); - - double[] y = null; - // calculate the y position of the trajectory ray at the radius of the C detector - if (D == 0) { - y = new double[1]; - y[0] = -sx * ix / (1 + sx * sx); - } - - if (D > 0) { - y = new double[2]; - y[0] = (-sx * ix + Math.sqrt(D)) / (1 + sx * sx); - y[1] = (-sx * ix - Math.sqrt(D)) / (1 + sx * sx); - } - - for (int j = 0; j < y.length; j++) { - double x = sx * y[j] + ix; - double phi = Math.atan2(y[j], x); - // calculate the z position of the trajectory at the radius of the C detector - double z = sz * y[j] + iz; - - double doca = 1000; - Cross closestCross = null; - // match the cross z measurement closest to the calculated z - for (int i = 0; i < MMCrosses.size(); i++) { - if (MMCrosses.get(i).get_Region() != Region) { - continue; - } - //if(Double.isNaN(MMCrosses.get(i).get_Point0().z())) - if (MMCrosses.get(i).get_Type()==BMTType.Z) { - continue; - } - double m_z = MMCrosses.get(i).get_Point().z(); - //int sector = geo.isInSector(MMCrosses.get(i).get_Region() * 2, phi, Math.toRadians(BMTConstants.isInSectorJitter)); - int sector = Constants.BMTGEOMETRY.getSector(MMCrosses.get(i).get_Region() * 2, phi); - if (sector != MMCrosses.get(i).get_Sector()) { - continue; - } - double d = Math.abs(z - m_z); - if (d < doca) { - doca = d; - closestCross = (Cross) MMCrosses.get(i).clone(); - - closestCross.set_Point(new Point3D(x, y[j], m_z)); - closestCross.set_PointErr(new Point3D(10, 10, MMCrosses.get(i).get_PointErr().z())); // to do : put in the correct error - } - } - - if (closestCross != null) { - if (doca < matchCutOff * 100) { - //System.out.println(doca+" -->match C "+closestCross.toString()); - matchedMMCrosses.add(closestCross); - } - } - - } - - return matchedMMCrosses; - } - - @Deprecated - private ArrayList MatchMMCrossZ(int Region, Ray ray, List MMCrosses, double matchCutOff) { - - ArrayList matchedMMCrosses = new ArrayList(); - - double R = Constants.BMTGEOMETRY.getRadiusMidDrift(Constants.BMTGEOMETRY.getLayer(Region,BMTType.Z)); // R for Z detector - double sx = ray.get_yxslope(); - double ix = ray.get_yxinterc(); - double sz = ray.get_yzslope(); - double iz = ray.get_yzinterc(); - - double D = sx * sx * ix * ix - (1 + sx * sx) * (ix * ix - R * R); - - double[] y = null; - - if (D == 0) { - y = new double[1]; - y[0] = -sx * ix / (1 + sx * sx); - } - - if (D > 0) { - y = new double[2]; - y[0] = (-sx * ix + Math.sqrt(D)) / (1 + sx * sx); - y[1] = (-sx * ix - Math.sqrt(D)) / (1 + sx * sx); - } - for (int j = 0; j < y.length; j++) { - double x = sx * y[j] + ix; - double z = sz * y[j] + iz; - - double minCosAngMeasToTrk = -1; - Cross closestCross = null; - - for (int i = 0; i < MMCrosses.size(); i++) { - if (MMCrosses.get(i).get_Region() != Region) { - continue; - } - // measuring phi - //if(Double.isNaN(MMCrosses.get(i).get_Point0().x())) - if (MMCrosses.get(i).get_Type()==BMTType.C) { - continue; - } - double m_x = MMCrosses.get(i).get_Point().x(); - double m_y = MMCrosses.get(i).get_Point().y(); - //System.out.println(" lookin to match "+MMCrosses.get(i).printInfo()); - double cosAngMeasToTrk = (x * m_x + y[j] * m_y) / Math.sqrt((x * x + y[j] * y[j]) * (m_x * m_x + m_y * m_y)); // the cosine between the measured (x,y) cross coords and the (x,y) trajectory should be close to 1 - // opening angle must be within about 11 degrees to start the search for nearest point - //System.out.println(" cosAngMeasToTrk "+cosAngMeasToTrk); - if (cosAngMeasToTrk < 0.98) { - continue; - } - - if (Math.acos(cosAngMeasToTrk) < Math.acos(minCosAngMeasToTrk)) { - minCosAngMeasToTrk = cosAngMeasToTrk; - closestCross = (Cross) MMCrosses.get(i).clone(); - closestCross.set_Point(new Point3D(m_x, m_y, z)); - closestCross.set_PointErr(new Point3D(MMCrosses.get(i).get_PointErr().x(), MMCrosses.get(i).get_PointErr().y(), 10.)); // to do : put in the correct error - } - } - if (closestCross != null) { - //if(minCosAngMeasToTrk rmHelicalTrkClones(boolean removeClones, ArrayList cands) { - ArrayList passedcands = new ArrayList(); - if (removeClones == false) { - passedcands = cands; - } - - if (removeClones == true) { - if (cands.size() > 0) { - // clean up duplicates: - for (int k = 0; k < cands.size(); k++) { - for (int k2 = 0; k2 < cands.size(); k2++) { - if (k2 == k) { - continue; - } - int overlaps = 0; - for (int k3 = 0; k3 < cands.get(k).size(); k3++) { - if (cands.get(k2).containsCross(cands.get(k).get(k3))) { - overlaps++; - - } - } - if (overlaps > 1) { - if ((cands.get(k2).get_Seed().get_circleFitChi2PerNDF() + cands.get(k2).get_Seed().get_lineFitChi2PerNDF()) > - (cands.get(k).get_Seed().get_circleFitChi2PerNDF() + cands.get(k).get_Seed().get_lineFitChi2PerNDF())) { - cands.get(k2).set_Id(-999); - - } - } - } - } - for (int k = 0; k < cands.size(); k++) { - if (cands.get(k).get_Id() != -999) { - passedcands.add(cands.get(k)); - - } - } - } - } - - return passedcands; - } - - private ArrayList rmStraightTrkClones(boolean removeClones, ArrayList cands) { - ArrayList passedcands = new ArrayList(); - if (removeClones == false) { - passedcands = cands; - } - - if (removeClones == true) { - if (cands.size() > 0) { - // clean up duplicates: - for (int k = 0; k < cands.size(); k++) { - for (int k2 = 0; k2 < cands.size(); k2++) { - if (k2 == k) { - continue; - } - int overlaps = 0; - for (int k3 = 0; k3 < cands.get(k).size(); k3++) { - if (cands.get(k2).containsCross(cands.get(k).get(k3))) { - overlaps++; - - } - } - if (overlaps > 1) { - if ((cands.get(k2).get_chi2()) > (cands.get(k).get_chi2())) { - - cands.get(k2).set_Id(-999); - - } - } - } - } - for (int k = 0; k < cands.size(); k++) { - if (cands.get(k).get_Id() != -999) { - passedcands.add(cands.get(k)); - - } - } - } - } - - return passedcands; - } - - private void EliminateStraightTrackOutliers(ArrayList crosses, CosmicFitter track) { - ArrayList toKeep = new ArrayList<>(); - - for(int j = 0; j < crosses.size(); j++) { - Cross c = crosses.get(j); - int layer = c.get_Cluster1().get_Layer(); - int sector = c.get_Sector(); - - Point3D traj = new Point3D(); - int ntraj = Constants.SVTGEOMETRY.getPlane(layer, sector).intersection(track.get_ray().toLine(), traj); - - if(ntraj!=1) - c.reset(); - else if(!Constants.SVTGEOMETRY.isInFiducial(layer, sector, traj)) - c.reset(); - else { - Vector3D distance = Constants.SVTGEOMETRY.toLocal(layer, sector, c.get_Point().vectorTo(traj)); - if(Math.abs(distance.x())>Constants.COSMICSMINRESIDUALX || - Math.abs(distance.z())>Constants.COSMICSMINRESIDUALZ) c.reset(); - else - toKeep.add(c); - } - } - crosses = toKeep; - } - - public void matchClusters(List sVTclusters, TrajectoryFinder tf, boolean trajFinal, - ArrayList trajectory, int k) { - if(trajectory == null) - return; - Collections.sort(sVTclusters); - for (StateVec st : trajectory) { - for (Cluster cls : sVTclusters) { - if (cls.get_AssociatedTrackID() != -1) { - continue; - } - if (st.get_SurfaceSector() != cls.get_Sector()) { - continue; - } - if (st.get_SurfaceLayer() != cls.get_Layer()) { - continue; - } - if (Math.abs(st.get_CalcCentroidStrip() - cls.get_Centroid()) < 4) { - tf.setHitResolParams("SVT", cls.get_Sector(), cls.get_Layer(), cls, st, trajFinal); - //System.out.println("trying to associate a cluster ");cls.printInfo(); System.out.println(" to "+st.get_CalcCentroidStrip()+" dStp = "+(st.get_CalcCentroidStrip()-cls.get_Centroid())); - cls.set_AssociatedTrackID(k); - for (Hit h : cls) { - h.set_AssociatedTrackID(k); - } - } - } - } - } - -} diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java index 88fc7f9a3..497e8bc7d 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackListFinder.java @@ -8,8 +8,6 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.rec.cvt.Constants; -import org.jlab.rec.cvt.bmt.BMTType; -import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTParameters; import org.jlab.rec.cvt.trajectory.Trajectory; import org.jlab.rec.cvt.trajectory.TrajectoryFinder; @@ -36,33 +34,33 @@ public static List getTracks(List cands, Swim cvtSwim) { // loop over candidates and set the trajectories for (Track trk : cands) { - if(trk.get_helix()!=null) { + if(trk.getHelix()!=null) { assignTrkPID(trk); //KalFit kf = new KalFit(trk, svt_geo); //kf.runKalFit(trk, svt_geo); //EnergyLossCorr elc = new EnergyLossCorr(trk); - //System.out.println("******* before EL "+trk.get_P()); + //System.out.println("******* before EL "+trk.getP()); //elc.doCorrection(trk, svt_geo); - //System.out.println("******* after EL "+trk.get_P()); + //System.out.println("******* after EL "+trk.getP()); - int charge = trk.get_Q(); + int charge = trk.getQ(); double maxPathLength = 5.0;//very loose cut - cvtSwim.SetSwimParameters((trk.get_helix().xdca()+trk.get_helix().getXb()) / 10, (trk.get_helix().ydca()+trk.get_helix().getYb()) / 10, trk.get_helix().get_Z0() / 10 , - Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - trk.get_P(), charge, + cvtSwim.SetSwimParameters((trk.getHelix().xDCA()+trk.getHelix().getXb()) / 10, (trk.getHelix().yDCA()+trk.getHelix().getYb()) / 10, trk.getHelix().getZ0() / 10 , + Math.toDegrees(trk.getHelix().getPhiAtDCA()), Math.toDegrees(Math.acos(trk.getHelix().cosTheta())), + trk.getP(), charge, maxPathLength) ; double[] pointAtCylRad = cvtSwim.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), Constants.CTOFINNERRADIUS/10, Constants.SWIMACCURACYCD/10); if(pointAtCylRad!=null) { - trk.se_TrackPosAtCTOF(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); - trk.set_TrackDirAtCTOF(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); - trk.set_PathToCTOF(pointAtCylRad[6]*10); + trk.setTrackPosAtCTOF(new Point3D(pointAtCylRad[0]*10, pointAtCylRad[1]*10, pointAtCylRad[2]*10)); + trk.setTrackDirAtCTOF(new Vector3D(pointAtCylRad[3]*10, pointAtCylRad[4]*10, pointAtCylRad[5]*10)); + trk.setPathToCTOF(pointAtCylRad[6]*10); } TrajectoryFinder trjFind = new TrajectoryFinder(); Trajectory traj = trjFind.findTrajectory(trk, cvtSwim, "final"); - trk.set_Trajectory(traj.get_Trajectory()); + trk.setTrajectory(traj.getTrajectory()); //if(trk.passCand == true) tracks.add(trk); @@ -76,25 +74,25 @@ private static void assignTrkPID(Track trk) { int NbHits = 0; double TotE = 0; for (int i = 0; i < trk.size(); i++) { - if (trk.get(i).get_Detector() != DetectorType.BST) { + if (trk.get(i).getDetector() != DetectorType.BST) { continue; } - for (int j = 0; j < trk.get(i).get_Cluster1().size(); j++) { - TotE += trk.get(i).get_Cluster1().get(j).get_Strip().get_Edep(); + for (int j = 0; j < trk.get(i).getCluster1().size(); j++) { + TotE += trk.get(i).getCluster1().get(j).getStrip().getEdep(); NbHits++; } - for (int j = 0; j < trk.get(i).get_Cluster2().size(); j++) { - TotE += trk.get(i).get_Cluster2().get(j).get_Strip().get_Edep(); + for (int j = 0; j < trk.get(i).getCluster2().size(); j++) { + TotE += trk.get(i).getCluster2().get(j).getStrip().getEdep(); NbHits++; } } TotE /= (double) NbHits; if (TotE <= SVTParameters.PIDCUTOFF) { - trk.set_PID("pion"); + trk.setPID("pion"); } if (TotE > SVTParameters.PIDCUTOFF) { - trk.set_PID("proton"); + trk.setPID("proton"); } } @@ -148,106 +146,5 @@ public static void checkForOverlaps(List tracks, String msg) { } } } - - @Deprecated - public void removeOverlappingTracksOld(List trkcands) { - if(trkcands==null) - return; - List selectedTracks =new ArrayList(); - List list = new ArrayList(); - List rejected = new ArrayList(); - for(int i =0; i selectedTracks, Track selectedTrk) { - // not used. Now Track extends Comparables - boolean isInList = false; - for(Track trk : selectedTracks) { - if(trk.get_Id()==selectedTrk.get_Id()) - isInList=true; - } - return isInList; - } - - - @Deprecated - private void getOverlapLists(Track track, List trkcands, List list) { - // -------------------------------------------------------------------- - // two tracks are considered the same if they share at least 2 crosses - // -------------------------------------------------------------------- - - for( Track t : trkcands ) { - int N = 0; - for( Cross c : t ) { - - // do not check on BMTC - if( c.get_Type()==BMTType.C) continue; - - if( track.contains(c) ) { N++; } - } - if( N >= 2 ) list.add( t ); - } - - } - - private static Track FindBestTrack(List trkList) { - // -------------------------------------------------------------------- - // Select the candidate with the highest number of NDF - // if two have the same ndf, get the one with the better chi2/ndf - // -------------------------------------------------------------------- - double bestChi2 = 9999999; - int ndf = 0; - Track bestTrk = null; - - for(int i =0; i=ndf) { - - ndf = trkList.get(i).getNDF(); - if( trkList.get(i).getNDF()==ndf ) { - if(trkList.get(i).getChi2()/(double)trkList.get(i).getNDF()> scan ; - Map> seedMap ; // init seeds; - List>> sortedCrosses; - List seedScan ; - List Xs ; - List Ys ; - List Ws ; - double xbeam; - double ybeam; + private final SVTGeometry sgeo = Constants.SVTGEOMETRY; + private final BMTGeometry bgeo = Constants.BMTGEOMETRY; + private double bfield; + + private final int NBINS = 36; + private final double[] phiShift = new double[]{0, 65, 90}; // move the bin edge to handle bin boundaries + private List> scan ; + private Map> seedMap ; // init seeds; + private List>> sortedCrosses; + private List seedScan ; + private List Xs ; + private List Ys ; + private List Ws ; + private double xbeam; + private double ybeam; public boolean unUsedHitsOnly = false; public TrackSeeder(Swim swimmer, double xb, double yb) { @@ -41,53 +42,51 @@ public TrackSeeder(Swim swimmer, double xb, double yb) { this.bfield = Math.abs(b[2]); //init lists for scan - sortedCrosses = new ArrayList>>(); + sortedCrosses = new ArrayList<>(); for(int i =0; i>() ); + sortedCrosses.add(i, new ArrayList<>() ); for(int l =0; l<3; l++) { - sortedCrosses.get(i).add(l,new ArrayList() ); + sortedCrosses.get(i).add(l,new ArrayList<>() ); } } - scan = new ArrayList>(); - seedMap = new HashMap>(); // init seeds; - seedScan = new ArrayList(); + scan = new ArrayList<>(); + seedMap = new HashMap<>(); // init seeds; + seedScan = new ArrayList<>(); //for fitting - Xs = new ArrayList(); - Ys = new ArrayList(); - Ws = new ArrayList(); + Xs = new ArrayList<>(); + Ys = new ArrayList<>(); + Ws = new ArrayList<>(); xbeam = xb; ybeam = yb; } - private void MatchSeed(List othercrs) { - if(othercrs==null || othercrs.size()==0) + private void matchSeed(List othercrs) { + if(othercrs==null || othercrs.isEmpty()) return; for (Seed seed : seedScan) { - double d = seed.get_Doca(); - double r = seed.get_Rho(); - double f = seed.get_Phi(); + double d = seed.getDoca(); + double r = seed.getRho(); + double f = seed.getPhi(); for (Cross c : othercrs ) { -// c.set_AssociatedTrackID(22220); - if(this.InSamePhiRange(seed, c)== true) { -// c.set_AssociatedTrackID(22221); - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); + if(this.inSamePhiRange(seed, c)== true) { + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; double res = this.calcResi(r, ri, d, f, fi); if(Math.abs(res) seedcrs) { + + public void fitSeed(List seedcrs) { Xs.clear(); Ys.clear(); Ws.clear(); @@ -98,10 +97,10 @@ public void FitSeed(List seedcrs) { Ys.add(0, ybeam); Ws.add(0,0.1); for (Cross c : seedcrs ) { - if(c.get_Type()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); - Xs.add(c.get_Point().x()); - Ys.add(c.get_Point().y()); - Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x()+c.get_PointErr().y()*c.get_PointErr().y())); + if(c.getType()==BMTType.C ) System.err.println("WRONG CROSS TYPE"); + Xs.add(c.getPoint().x()); + Ys.add(c.getPoint().y()); + Ws.add(1. / (c.getPointErr().x()*c.getPointErr().x()+c.getPointErr().y()*c.getPointErr().y())); } CircleFitter circlefit = new CircleFitter(xbeam, ybeam); @@ -115,8 +114,8 @@ public void FitSeed(List seedcrs) { boolean failed = false; for (Cross c : seedcrs ) { - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); double ri = Math.sqrt(xi*xi+yi*yi); double fi = Math.atan2(yi,xi) ; @@ -133,7 +132,7 @@ public void FitSeed(List seedcrs) { /* Finds BMT seeds */ - public void FindSeedCrossList(List crosses) { + public void findSeedCrossList(List crosses) { seedMap.clear(); @@ -141,17 +140,17 @@ public void FindSeedCrossList(List crosses) { scan.get(si1).clear(); for(int i = 0; i< phiShift.length; i++) { - FindSeedCrossesFixedBin(crosses, phiShift[i]); + findSeedCrossesFixedBin(crosses, phiShift[i]); } - seedMap.forEach((key,value) -> this.FitSeed(value)); + seedMap.forEach((key,value) -> this.fitSeed(value)); } /* Scans overphase space to find groups of BMT crosses */ - private void FindSeedCrossesFixedBin(List crosses, double phiShift) { + private void findSeedCrossesFixedBin(List crosses, double phiShift) { for(int b =0; b crosses, double phiShift) { } int[][] LPhi = new int[NBINS][3]; for (int i = 0; i < crosses.size(); i++) { - double phi = Math.toDegrees(crosses.get(i).get_Point().toVector3D().phi()); + double phi = Math.toDegrees(crosses.get(i).getPoint().toVector3D().phi()); phi += phiShift; if (phi < 0) { @@ -169,8 +168,8 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { int binIdx = (int) (phi / (360./NBINS) ); if(binIdx>35) binIdx = 35; - sortedCrosses.get(binIdx).get(crosses.get(i).get_Region() - 1).add(crosses.get(i)); - LPhi[binIdx][crosses.get(i).get_Region() - 1]++; + sortedCrosses.get(binIdx).get(crosses.get(i).getRegion() - 1).add(crosses.get(i)); + LPhi[binIdx][crosses.get(i).getRegion() - 1]++; } for (int b = 0; b < NBINS; b++) { @@ -185,7 +184,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { if(SumLyr!=LPhi[b][0]+LPhi[b][1]+ LPhi[b][2]) { SumLyr = LPhi[b][0]+LPhi[b][1]+ LPhi[b][2]; } - ArrayList hits = new ArrayList(); + ArrayList hits = new ArrayList<>(); for (int la = 0; la < 3; la++) { if (sortedCrosses.get(b).get(la) != null && LPhi[b][la]>0) { if (sortedCrosses.get(b).get(la).get(LPhi[b][la]-1) != null @@ -205,7 +204,7 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { int s = hits.size(); int index = (int) Math.pow(2,s); for(Cross c : hits) { - seedIdx +=c.get_Id()*Math.pow(10, index); + seedIdx +=c.getId()*Math.pow(10, index); index-=4; } seedMap.put(seedIdx, hits); @@ -217,18 +216,18 @@ private void FindSeedCrossesFixedBin(List crosses, double phiShift) { - List BMTmatches = new ArrayList(); + List BMTmatches = new ArrayList<>(); public List findSeed(List bst_crosses, List bmt_crosses) { - List seedlist = new ArrayList(); + List seedlist = new ArrayList<>(); - List crosses = new ArrayList(); - List svt_crosses = new ArrayList(); - List bmtC_crosses = new ArrayList(); + List crosses = new ArrayList<>(); + List svt_crosses = new ArrayList<>(); + List bmtC_crosses = new ArrayList<>(); if(bmt_crosses!=null && bmt_crosses.size()>0) { for(Cross c : bmt_crosses) { - if(c.get_Type()==BMTType.Z) { + if(c.getType()==BMTType.Z) { if(this.unUsedHitsOnly == false) { crosses.add(c); } else { @@ -237,7 +236,7 @@ public List findSeed(List bst_crosses, List bmt_crosses) { } } } - if(c.get_Type()==BMTType.C) { + if(c.getType()==BMTType.C) { if(this.unUsedHitsOnly == false) { bmtC_crosses.add(c); } else { @@ -259,72 +258,65 @@ public List findSeed(List bst_crosses, List bmt_crosses) { } } } - this.FindSeedCrossList(svt_crosses); - this.MatchSeed(crosses); + this.findSeedCrossList(svt_crosses); + this.matchSeed(crosses); for(Seed mseed : seedScan) { - List seedcrs = mseed.get_Crosses(); -// for (Cross c : seedcrs ) { -// if(c.get_Type()==BMTType.C ) continue; -// c.set_AssociatedTrackID(122220); -// } - // loop until a good circular fit. removing far crosses each time - boolean circlefitstatusOK = false; - while( ! circlefitstatusOK && seedcrs.size()>=3 ){ + List seedcrs = mseed.getCrosses(); + + // loop until a good circular fit. removing far crosses each time + boolean circlefitstatusOK = false; + while( ! circlefitstatusOK && seedcrs.size()>=3 ){ - Xs.clear(); - Ys.clear(); - Ws.clear(); - ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); - ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); - ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); - Xs.add(0, xbeam); - Ys.add(0, ybeam); - Ws.add(0, 0.1); - for (Cross c : seedcrs ) { -// if(c.get_Type()==BMTType.C ) continue; -// c.set_AssociatedTrackID(122221); - Xs.add(c.get_Point().x()); - Ys.add(c.get_Point().y()); - Ws.add(1. / (c.get_PointErr().x()*c.get_PointErr().x() - +c.get_PointErr().y()*c.get_PointErr().y())); - } - - CircleFitter circlefit = new CircleFitter(xbeam, ybeam); - circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); - CircleFitPars pars = circlefit.getFit(); + Xs.clear(); + Ys.clear(); + Ws.clear(); + ((ArrayList) Xs).ensureCapacity(seedcrs.size()+1); + ((ArrayList) Ys).ensureCapacity(seedcrs.size()+1); + ((ArrayList) Ws).ensureCapacity(seedcrs.size()+1); + Xs.add(0, xbeam); + Ys.add(0, ybeam); + Ws.add(0, 0.1); + for (Cross c : seedcrs ) { + Xs.add(c.getPoint().x()); + Ys.add(c.getPoint().y()); + Ws.add(1. / (c.getPointErr().x()*c.getPointErr().x() + +c.getPointErr().y()*c.getPointErr().y())); + } - // if not a good fit, check for outliers - if (!circlefitstatusOK || pars.chisq()/(double)(Xs.size()-3)>10) { - //System.out.println(" check circular fit" ); - double d = pars.doca(); - double r = pars.rho(); - double f = pars.phi(); - for (Cross c : seedcrs ) { -// if(c.get_Type()==BMTType.C) continue; -// c.set_AssociatedTrackID(122222); - double xi = c.get_Point().x(); - double yi = c.get_Point().y(); - double ri = Math.sqrt(xi*xi+yi*yi); - double fi = Math.atan2(yi,xi) ; - double res = this.calcResi(r, ri, d, f, fi); - if(Math.abs(res)>SVTParameters.RESIMAX) { - //System.out.println(" remove detector " + c .get_Detector() + " region " + c.get_Region() + " sector " + c.get_Sector() ); - seedcrs.remove(c); - break; + CircleFitter circlefit = new CircleFitter(xbeam, ybeam); + circlefitstatusOK = circlefit.fitStatus(Xs, Ys, Ws, Xs.size()); + CircleFitPars pars = circlefit.getFit(); + + // if not a good fit, check for outliers + if (!circlefitstatusOK || pars.chisq()/(double)(Xs.size()-3)>10) { + //System.out.println(" check circular fit" ); + double d = pars.doca(); + double r = pars.rho(); + double f = pars.phi(); + for (Cross c : seedcrs) { + double xi = c.getPoint().x(); + double yi = c.getPoint().y(); + double ri = Math.sqrt(xi * xi + yi * yi); + double fi = Math.atan2(yi, xi); + double res = this.calcResi(r, ri, d, f, fi); + if (Math.abs(res) > SVTParameters.RESIMAX) { + //System.out.println(" remove detector " + c .getDetector() + " region " + c.getRegion() + " sector " + c.getSector() ); + seedcrs.remove(c); + break; + } } } } - } } for(Seed mseed : seedScan) { boolean fitStatus = false; - if(mseed.get_Crosses().size()>=3) + if(mseed.getCrosses().size()>=3) fitStatus = mseed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); if (fitStatus) { - List sameSectorCrosses = this.FindCrossesInSameSectorAsSVTTrk(mseed, bmtC_crosses); + List sameSectorCrosses = this.findCrossesInSameSectorAsSVTTrk(mseed, bmtC_crosses); BMTmatches.clear(); if (sameSectorCrosses.size() >= 0) { BMTmatches = this.findCandUsingMicroMegas(mseed, sameSectorCrosses); @@ -337,12 +329,12 @@ public List findSeed(List bst_crosses, List bmt_crosses) { //refit using the BMT fitStatus = bseed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); - if (fitStatus && bseed.get_circleFitChi2PerNDF() findSeed(List bst_crosses, List bmt_crosses) { Seed.removeOverlappingSeeds(seedlist); for (Seed bseed : seedlist) { - for(Cross c : bseed.get_Crosses()) { + for(Cross c : bseed.getCrosses()) { c.isInSeed = true; } - bseed.set_Status(2); + bseed.setStatus(2); } return seedlist; } - private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { + private List findCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_crosses) { List bmt_crossesInSec = new ArrayList(); //double angle_i = 0; // first angular boundary init //double angle_f = 0; // second angular boundary for detector A, B, or C init double jitter = Math.toRadians(10); // 10 degrees jitter for (int i = 0; i < bmt_crosses.size(); i++) { - Point3D pAtBMTSurf =seed.get_Helix().getPointAtRadius(bgeo.getRadius(bmt_crosses.get(i).get_Cluster1().get_Layer())); + Point3D pAtBMTSurf =seed.getHelix().getPointAtRadius(bgeo.getRadius(bmt_crosses.get(i).getCluster1().getLayer())); // the hit parameters double angle = Math.atan2(pAtBMTSurf.y(), pAtBMTSurf.x()); if (angle < 0) { angle += 2 * Math.PI; } - //if (bmt_geo.isInDetector(bmt_crosses.get(i).get_Region()*2-1, angle, jitter) - // == bmt_crosses.get(i).get_Sector() - 1) + //if (bmt_geo.isInDetector(bmt_crosses.get(i).getRegion()*2-1, angle, jitter) + // == bmt_crosses.get(i).getSector() - 1) //inDetector(int layer, int sector, Point3D traj) - if (bgeo.inDetector(bmt_crosses.get(i).get_Region()*2-1, bmt_crosses.get(i).get_Sector(), pAtBMTSurf)==true){ + if (bgeo.inDetector(bmt_crosses.get(i).getRegion()*2-1, bmt_crosses.get(i).getSector(), pAtBMTSurf)==true){ bmt_crossesInSec.add(bmt_crosses.get(i)); } @@ -387,165 +379,15 @@ private List FindCrossesInSameSectorAsSVTTrk(Seed seed, List bmt_c return bmt_crossesInSec; } -// private List X = new ArrayList(); -// private List Y = new ArrayList(); -// private List Z = new ArrayList(); -// private List Rho = new ArrayList(); -// private List ErrZ = new ArrayList(); -// private List ErrRho = new ArrayList(); -// private List ErrRt = new ArrayList(); -// List BMTCrossesC = new ArrayList(); -// List BMTCrossesZ = new ArrayList(); -// List SVTCrosses = new ArrayList(); -// float b[] = new float[3]; -// -// public Track fit(List VTCrosses, SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, -// boolean originConstraint, Swim swimmer) { -// double chisqMax = Double.POSITIVE_INFINITY; -// -// Track cand = null; -// HelicalTrackFitter fitTrk = new HelicalTrackFitter(); -// for (int i = 0; i < fitIter; i++) { -// // if(originConstraint==true) { -// // X.add(0, (double) 0); -// // Y.add(0, (double) 0); -// // Z.add(0, (double) 0); -// // Rho.add(0, (double) 0); -// // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); -// // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); -// // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); -// // } -// X.clear(); -// Y.clear(); -// Z.clear(); -// Rho.clear(); -// ErrZ.clear(); -// ErrRho.clear(); -// ErrRt.clear(); -// -// int svtSz = 0; -// int bmtZSz = 0; -// int bmtCSz = 0; -// -// BMTCrossesC.clear(); -// BMTCrossesZ.clear(); -// SVTCrosses.clear(); -// -// for (Cross c : VTCrosses) { -// if (c.get_Detector()==DetectorType.BST) { -// SVTCrosses.add(c); -// } -// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { -// BMTCrossesC.add(c); -// } -// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { -// BMTCrossesZ.add(c); -// } -// } -// svtSz = SVTCrosses.size(); -// if (BMTCrossesZ != null) { -// bmtZSz = BMTCrossesZ.size(); -// } -// if (BMTCrossesC != null) { -// bmtCSz = BMTCrossesC.size(); -// } -// -// int useSVTdipAngEst = 1; -// if (bmtCSz >= 2) { -// useSVTdipAngEst = 0; -// } -// -// ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); -// ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); -// ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination -// ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); -// -// cand = new Track(null); -// cand.addAll(SVTCrosses); -// for (int j = 0; j < SVTCrosses.size(); j++) { -// X.add(j, SVTCrosses.get(j).get_Point().x()); -// Y.add(j, SVTCrosses.get(j).get_Point().y()); -// if (useSVTdipAngEst == 1) { -// Z.add(j, SVTCrosses.get(j).get_Point().z()); -// Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() -// + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); -// ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() -// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); -// ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); -// } -// ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() -// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); -// } -// -// if (bmtZSz > 0) { -// for (int j = svtSz; j < svtSz + bmtZSz; j++) { -// X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); -// Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); -// ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() -// + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); -// } -// } -// if (bmtCSz > 0) { -// for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { -// Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); -// Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); -// -// ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); -// ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); -// } -// } -// X.add((double) Constants.getXb()); -// Y.add((double) Constants.getYb()); -// ErrRt.add((double) 0.1); -// -// fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); -// -// if (fitTrk.get_helix() == null) { -// return null; -// } -// -// cand = new Track(fitTrk.get_helix()); -// //cand.addAll(SVTCrosses); -// cand.addAll(SVTCrosses); -// cand.addAll(BMTCrossesC); -// cand.addAll(BMTCrossesZ); -// -// swimmer.BfieldLab(0, 0, 0, b); -// double Bz = Math.abs(b[2]); -// fitTrk.get_helix().B = Bz; -// cand.setPXYZ(fitTrk.get_helix()); -// //if(shift==0) -// if (fitTrk.get_chisq()[0] < chisqMax) { -// chisqMax = fitTrk.get_chisq()[0]; -// if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) -// return null; -// if(X.size() > 3) -// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0] / (int) (X.size() - 3)); // 3 fit params -// if(Z.size() > 2) -// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1] / (int) (Z.size() - 2)); // 2 fit params -// return cand; -// } - - - public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) { - List> BMTCcrosses = new ArrayList>(); + List> BMTCcrosses = new ArrayList<>(); - ArrayList matches = new ArrayList(); - Map AllSeeds = new HashMap(); + ArrayList matches = new ArrayList<>(); + Map AllSeeds = new HashMap<>(); int[] S = new int[3]; for (int r = 0; r < 3; r++) { - BMTCcrosses.add(new ArrayList()); + BMTCcrosses.add(new ArrayList<>()); } //for (int r = 0; r < 3; r++) { // BMTCcrosses.get(r).clear(); @@ -553,8 +395,8 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) //} for (Cross bmt_cross : bmt_crosses) { - if (bmt_cross.get_Type()==BMTType.C) // C-detector - BMTCcrosses.get(bmt_cross.get_Region() - 1).add(bmt_cross); + if (bmt_cross.getType()==BMTType.C) // C-detector + BMTCcrosses.get(bmt_cross.getRegion() - 1).add(bmt_cross); } AllSeeds.clear(); @@ -589,14 +431,14 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) } } - matches.addAll(trkCand.get_Crosses()); + matches.addAll(trkCand.getCrosses()); if (matches.size() > 0) { Seed BMTTrkSeed = new Seed(); String st = ""; for(Cross c : matches) - st+=c.get_Id(); - BMTTrkSeed.set_Helix(trkCand.get_Helix()); - BMTTrkSeed.set_Crosses(matches); + st+=c.getId(); + BMTTrkSeed.setHelix(trkCand.getHelix()); + BMTTrkSeed.setCrosses(matches); AllSeeds.put(st,BMTTrkSeed); //if (AllSeeds.size() > 200) { @@ -610,7 +452,7 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) } } - List outputSeeds = new ArrayList(); + List outputSeeds = new ArrayList<>(); for(Seed s : AllSeeds.values()) outputSeeds.add(s); @@ -620,19 +462,19 @@ public List findCandUsingMicroMegas(Seed trkCand, List bmt_crosses) private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { boolean pass = false; - double dzdrsum = trkCand.get_Helix().get_tandip(); + double dzdrsum = trkCand.getHelix().getTanDip(); - double z_bmt = bmt_Ccross.get_Point().z(); - double r_bmt = bgeo.getRadius(bmt_Ccross.get_Cluster1().get_Layer()); - Point3D phiHelixAtSurf = trkCand.get_Helix().getPointAtRadius(r_bmt); - //if (bmt_geo.isInSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) - // != bmt_Ccross.get_Sector()) - int sector = bgeo.getSector(bmt_Ccross.get_Cluster1().get_Layer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); - if(sector!= bmt_Ccross.get_Sector() || sector ==0){ + double z_bmt = bmt_Ccross.getPoint().z(); + double r_bmt = bgeo.getRadius(bmt_Ccross.getCluster1().getLayer()); + Point3D phiHelixAtSurf = trkCand.getHelix().getPointAtRadius(r_bmt); + //if (bmt_geo.isInSector(bmt_Ccross.getCluster1().getLayer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x()), Math.toRadians(10)) + // != bmt_Ccross.getSector()) + int sector = bgeo.getSector(bmt_Ccross.getCluster1().getLayer(), Math.atan2(phiHelixAtSurf.y(), phiHelixAtSurf.x())); + if(sector!= bmt_Ccross.getSector() || sector ==0){ return false; } double dzdr_bmt = z_bmt / r_bmt; - if (Math.abs(1 - (dzdrsum / (double) (trkCand.get_Crosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.get_Crosses().size() + 1))) <= SVTParameters.dzdrcut) // add this to the track + if (Math.abs(1 - (dzdrsum / (double) (trkCand.getCrosses().size())) / ((dzdrsum + dzdr_bmt) / (double) (trkCand.getCrosses().size() + 1))) <= SVTParameters.DZDRCUT) // add this to the track { pass = true; } @@ -640,55 +482,12 @@ private boolean passCcross(Seed trkCand, Cross bmt_Ccross) { return pass; } - - /** - * - * @param x1 cross1 x-coordinate - * @param x2 cross2 x-coordinate - * @param x3 cross3 x-coordinate - * @param y1 cross1 y-coordinate - * @param y2 cross2 y-coordinate - * @param y3 cross3 y-coordinate - * @return radius of circle containing 3 crosses in the (x,y) plane - */ - private double calc_radOfCurv(double x1, double x2, double x3, double y1, double y2, double y3) { - double radiusOfCurv = 0; - - if (Math.abs(x2 - x1) > 1.0e-9 && Math.abs(x3 - x2) > 1.0e-9) { - // Find the intersection of the lines joining the innermost to middle and middle to outermost point - double ma = (y2 - y1) / (x2 - x1); - double mb = (y3 - y2) / (x3 - x2); - - if (Math.abs(mb - ma) > 1.0e-9) { - double xcen = 0.5 * (ma * mb * (y1 - y3) + mb * (x1 + x2) - ma * (x2 + x3)) / (mb - ma); - double ycen = (-1. / mb) * (xcen - 0.5 * (x2 + x3)) + 0.5 * (y2 + y3); - - radiusOfCurv = Math.sqrt((x1 - xcen) * (x1 - xcen) + (y1 - ycen) * (y1 - ycen)); - } - } - return radiusOfCurv; - - } - - private void removeDuplicates(List AllSeeds) { - - Collections.sort(AllSeeds); - List Dupl = new ArrayList(); - for(int i = 1; i < AllSeeds.size(); i++) { - if(AllSeeds.get(i-1).get_IntIdentifier().equalsIgnoreCase(AllSeeds.get(i).get_IntIdentifier())) { - Dupl.add(AllSeeds.get(i)); - } - } - AllSeeds.removeAll(Dupl); - - } - private double calcResi(double r, double ri, double d, double f, double fi) { double res = 0.5*r*ri*ri - (1+r*d)*ri*Math.sin(f-fi)+0.5*r*d*d+d; return res; } - private boolean InSamePhiRange(Seed seed, Cross c) { + private boolean inSamePhiRange(Seed seed, Cross c) { return true; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java index 0db57bb1f..a14d34e80 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/TrackSeederCA.java @@ -15,213 +15,222 @@ import org.jlab.rec.cvt.svt.SVTGeometry; public class TrackSeederCA { - SVTGeometry sgeo = Constants.SVTGEOMETRY; - BMTGeometry bgeo = Constants.BMTGEOMETRY; - double xbeam; - double ybeam; - double bfield; - - + + private final SVTGeometry sgeo = Constants.SVTGEOMETRY; + private final BMTGeometry bgeo = Constants.BMTGEOMETRY; + private double xbeam; + private double ybeam; + private double bfield; + public TrackSeederCA(Swim swimmer, double xb, double yb) { float[] b = new float[3]; swimmer.BfieldLab(0, 0, 0, b); - this.bfield = Math.abs(b[2]); - this.xbeam = xb; - this.ybeam = yb; + this.bfield = Math.abs(b[2]); + this.xbeam = xb; + this.ybeam = yb; } - - // Retrieve lists of crosses as track candidates // from the output of the cellular automaton // it looks only for the maximum state, TODO: remove found candidate and continue public List> getCAcandidates(List nodes) { //System.out.println("\n\n\t ____inside get candidates___"); - List> trCands = new ArrayList>(); - List> cellCands = new ArrayList>(); - if( nodes.size() == 0 ) return trCands; - Collections.sort( nodes ); - int mstate = nodes.get(0).get_state(); + List> trCands = new ArrayList<>(); + List> cellCands = new ArrayList<>(); + if (nodes.isEmpty()) { + return trCands; + } + Collections.sort(nodes); + int mstate = nodes.get(0).getState(); // System.out.println( mstate ); - for( Cell cell : nodes ){ - if( cell.get_state() >= mstate-1 ){ - + for (Cell cell : nodes) { + if (cell.getState() >= mstate - 1) { + // if the cell has been already used for one track candidate, then skip it - if( cell.is_used() ) continue; - if( cell.get_plane().equalsIgnoreCase("XY") ) { - if( cell.get_c1().is_usedInXYcand() || cell.get_c2().is_usedInXYcand() ) { continue;} - } + if (cell.isUsed()) { + continue; + } + if (cell.getPlane().equalsIgnoreCase("XY")) { + if (cell.getC1().is_usedInXYcand() || cell.getC2().is_usedInXYcand()) { + continue; + } + } - //if( cell.get_plane().equalsIgnoreCase("ZR") ) { - //if( cell.get_c1().is_usedInZRcand() || cell.get_c2().is_usedInZRcand() ) continue; - //} - - //if( cell.get_plane().equalsIgnoreCase("ZR") ) { - //if( cell.get_c1().is_usedInZRcand() || cell.get_c2().is_usedInZRcand() ) continue; - //} - - int candlen = 1; - ArrayList cand = new ArrayList(); - cand.add( cell ); - Cell neighbour = cell; - while( neighbour.get_neighbors().size() > 0 ){ - Collections.sort(neighbour.get_neighbors()); - int ms = 0; // max state neighbors - double dist = 99999.; - double cos = 0.; - int id = -1; - for( int ic=0; ic < neighbour.get_neighbors().size();ic++ ){ - Cell cn = neighbour.get_neighbors().get(ic); -// if(cn.is_used() ) continue; -// if( cn.get_plane().equalsIgnoreCase("XY") ) { -// if( cn.get_c1().is_usedInXYcand() || cn.get_c2().is_usedInXYcand() ) { continue;} + //if( cell.getPlane().equalsIgnoreCase("ZR") ) { + //if( cell.getC1().is_usedInZRcand() || cell.getC2().is_usedInZRcand() ) continue; + //} + //if( cell.getPlane().equalsIgnoreCase("ZR") ) { + //if( cell.getC1().is_usedInZRcand() || cell.getC2().is_usedInZRcand() ) continue; + //} + int candlen = 1; + ArrayList cand = new ArrayList<>(); + cand.add(cell); + Cell neighbour = cell; + while (neighbour.getNeighbors().size() > 0) { + Collections.sort(neighbour.getNeighbors()); + int ms = 0; // max state neighbors + double dist = 99999.; + double cos = 0.; + int id = -1; + for (int ic = 0; ic < neighbour.getNeighbors().size(); ic++) { + Cell cn = neighbour.getNeighbors().get(ic); +// if(cn.isUsed() ) continue; +// if( cn.getPlane().equalsIgnoreCase("XY") ) { +// if( cn.getC1().is_usedInXYcand() || cn.getC2().is_usedInXYcand() ) { continue;} // } // -// if( cell.get_plane().equalsIgnoreCase("ZR") ) { -// if( cn.get_c1().is_usedInZRcand() || cn.get_c2().is_usedInZRcand() ) continue; +// if( cell.getPlane().equalsIgnoreCase("ZR") ) { +// if( cn.getC1().is_usedInZRcand() || cn.getC2().is_usedInZRcand() ) continue; // } - if( cn.get_state() != neighbour.get_state()-1) continue; - if( cn.get_state() >= ms ){ - ms = cn.get_state(); - if( neighbour.get_plane().equalsIgnoreCase("ZR") && - neighbour.get_c1().get_Detector()==DetectorType.BST){ - if( cn.get_length() < dist ){ - dist = cn.get_length(); - id = ic; - } - } - else { - if( neighbour.get_dir2D().dot( cn.get_dir2D() ) > cos ){ - cos = neighbour.get_dir2D().dot( cn.get_dir2D() ); - id = ic; - } - } - } - else break; // neighbors are sorted, exit if not max state - } - if( id < 0 ) break; - Cell n = neighbour.get_neighbors().get(id); - - // avoid clones. Set the node and its upper cross to "already used" - // TODO: should we assign "used" only if a Good candidate is found? -// n.set_used(true); -// if( n.get_plane().equalsIgnoreCase("XY") ) { -//// n.get_c1().set_usedInXYcand( true ); -// n.get_c2().set_usedInXYcand( true ); + if (cn.getState() != neighbour.getState() - 1) { + continue; + } + if (cn.getState() >= ms) { + ms = cn.getState(); + if (neighbour.getPlane().equalsIgnoreCase("ZR") + && neighbour.getC1().getDetector() == DetectorType.BST) { + if (cn.getLength() < dist) { + dist = cn.getLength(); + id = ic; + } + } else { + if (neighbour.getDir2D().dot(cn.getDir2D()) > cos) { + cos = neighbour.getDir2D().dot(cn.getDir2D()); + id = ic; + } + } + } else { + break; // neighbors are sorted, exit if not max state + } + } + if (id < 0) { + break; + } + Cell n = neighbour.getNeighbors().get(id); + + // avoid clones. Set the node and its upper cross to "already used" + // TODO: should we assign "used" only if a Good candidate is found? +// n.setUsed(true); +// if( n.getPlane().equalsIgnoreCase("XY") ) { +//// n.getC1().setusedInXYcand( true ); +// n.getC2().setusedInXYcand( true ); // } -// if( n.get_plane().equalsIgnoreCase("ZR") ) { -//// n.get_c1().set_usedInZRcand( true ); -// n.get_c2().set_usedInZRcand( true ); +// if( n.getPlane().equalsIgnoreCase("ZR") ) { +//// n.getC1().setusedInZRcand( true ); +// n.getC2().setusedInZRcand( true ); // } - // System.out.println(" - " + n); - cand.add(n); - neighbour = n; - candlen += 1; - } - + cand.add(n); + neighbour = n; + candlen += 1; + } + // System.out.println(" "); - if( cand.get(0).get_plane().equalsIgnoreCase("XY")) { - if( candlen > 2 ){ - Seed seed = new Seed(getCrossFromCells(cand)); - if(seed.fit(2, xbeam, ybeam, bfield)) { - cellCands.add(cand); - - for( Cell n : cand ) { - n.set_used(true); - if( n.get_plane().equalsIgnoreCase("XY") ) { -// n.get_c1().set_usedInXYcand( true ); - n.get_c2().set_usedInXYcand( true ); - } - if( n.get_plane().equalsIgnoreCase("ZR") ) { -// n.get_c1().set_usedInZRcand( true ); - n.get_c2().set_usedInZRcand( true ); - } - } - } - } - } - else { - if( candlen > 0 ){ - cellCands.add(cand); - } - } - - } - else break; // nodes are sorted, if it is different to the max state, exit -// else continue; // nodes are sorted, if it is different to the max state, exit + if (cand.get(0).getPlane().equalsIgnoreCase("XY")) { + if (candlen > 2) { + Seed seed = new Seed(getCrossFromCells(cand)); + if (seed.fit(2, xbeam, ybeam, bfield)) { + cellCands.add(cand); + + for (Cell n : cand) { + n.setUsed(true); + if (n.getPlane().equalsIgnoreCase("XY")) { +// n.getC1().setusedInXYcand( true ); + n.getC2().setusedInXYcand(true); + } + if (n.getPlane().equalsIgnoreCase("ZR")) { +// n.getC1().setusedInZRcand( true ); + n.getC2().setusedInZRcand(true); + } + } + } + } + } else { + if (candlen > 0) { + cellCands.add(cand); + } + } + + } else { + break; // nodes are sorted, if it is different to the max state, exit + }// else continue; // nodes are sorted, if it is different to the max state, exit } - + // System.out.println(" cellCands " + cellCands.size() ); - - for( List candcell : cellCands ){ - if(candcell.size() == 0 ) continue; - trCands.add( getCrossFromCells(candcell)); + for (List candcell : cellCands) { + if (candcell.isEmpty()) { + continue; + } + trCands.add(getCrossFromCells(candcell)); // trCands.add( new ArrayList()); -// trCands.get(trCands.size()-1).add( candcell.get(0).get_c2() ); +// trCands.get(trCands.size()-1).add( candcell.get(0).getC2() ); // for( Cell c : candcell ){ -// trCands.get(trCands.size()-1).add( c.get_c1() ); +// trCands.get(trCands.size()-1).add( c.getC1() ); // } } - return trCands; + return trCands; } - private ArrayList getCrossFromCells( List l ){ - if( l == null ) return null; - ArrayList crs = new ArrayList(); - crs.add( l.get(0).get_c2()); - for( Cell c : l) crs.add(c.get_c1()); - - return crs; + private ArrayList getCrossFromCells(List l) { + if (l == null) { + return null; + } + ArrayList crs = new ArrayList<>(); + crs.add(l.get(0).getC2()); + for (Cell c : l) { + crs.add(c.getC1()); + } + + return crs; } // create and run the cellular automaton - public List runCAMaker( String plane, int nepochs, ArrayList crs){ + public List runCAMaker(String plane, int nepochs, ArrayList crs) { MakerCA camaker = new MakerCA(false); - camaker.set_plane( plane ); - if( plane.equalsIgnoreCase("XY") ){ - camaker.set_cosBtwCells(0.95); // min dot product between neighbours - camaker.set_abCrs(20); // max angle between crosses to form a cell - camaker.set_aCvsR(45); // max angle between the cell and the radius to the first cell + camaker.setPlane(plane); + if (plane.equalsIgnoreCase("XY")) { + camaker.setcosBtwCells(0.95); // min dot product between neighbours + camaker.setabCrs(20); // max angle between crosses to form a cell + camaker.setaCvsR(45); // max angle between the cell and the radius to the first cell } - if( plane.equalsIgnoreCase("ZR") ){ - camaker.set_cosBtwCells(0.9); // it only applies to the BMTC cross only cells - camaker.set_abCrs(30.); - camaker.set_aCvsR(90.); + if (plane.equalsIgnoreCase("ZR")) { + camaker.setcosBtwCells(0.9); // it only applies to the BMTC cross only cells + camaker.setabCrs(30.); + camaker.setaCvsR(90.); } - + camaker.createCells(crs); camaker.findNeigbors(); - camaker.evolve( nepochs ); - return camaker.getNodes(); + camaker.evolve(nepochs); + return camaker.getNodes(); } - + public List findSeed(List svt_crosses, List bmt_crosses) { - - List seedlist = new ArrayList(); - ArrayList crosses = new ArrayList(); - List> bmtC_crosses = new ArrayList>(); - for( int i=0;i<3;i++) bmtC_crosses.add( new ArrayList() ); - + List seedlist = new ArrayList<>(); + + ArrayList crosses = new ArrayList<>(); + List> bmtC_crosses = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + bmtC_crosses.add(new ArrayList<>()); + } + crosses.addAll(svt_crosses); // Collections.sort(crosses); - - for(Cross c : bmt_crosses) { - if(c.get_Type()==BMTType.Z) + for (Cross c : bmt_crosses) { + if (c.getType() == BMTType.Z) { crosses.add(c); - if(c.get_Type()==BMTType.C) { - bmtC_crosses.get(c.get_Sector()-1).add(c); + } + if (c.getType() == BMTType.C) { + bmtC_crosses.get(c.getSector() - 1).add(c); } } - // look for candidates in the XY plane // run the cellular automaton over SVT and BMT_Z crosses - - List xynodes = runCAMaker( "XY", 5, crosses); - List> xytracks = getCAcandidates( xynodes); + List xynodes = runCAMaker("XY", 5, crosses); + List> xytracks = getCAcandidates(xynodes); // System.out.println( " XY tracks " + xytracks ); //// TODO: TEST TEST TEST @@ -230,392 +239,176 @@ public List findSeed(List svt_crosses, List bmt_crosses) { // Track xycand = fit(acr, svt_geo, Constants.SEEDFITITERATIONS, false); // // update // } - - + List> seedCrosses = CAonRZ(xytracks, bmtC_crosses); - List> seedCrosses = CAonRZ( xytracks, bmtC_crosses); - - List cands = new ArrayList(); + List cands = new ArrayList<>(); // System.out.println(seedlist.size()); - for (int s = 0; s < seedCrosses.size(); s++) { + for (int s = 0; s < seedCrosses.size(); s++) { // Collections.sort(seedCrosses.get(s)); // TODO: check why sorting matters // Track cand = fit(seedCrosses.get(s), svt_geo, bmt_geo, Constants.SEEDFITITERATIONS, false, swimmer); - Seed candSeed = new Seed(seedCrosses.get(s)); - boolean fitStatus = candSeed.fit(Constants.SEEDFITITERATIONS, xbeam, ybeam, bfield); - if (fitStatus && candSeed.isGood()) { - cands.add(candSeed); - } - } -// for( int i=0;i rmDuplicate( List tracks) { - List goodTrks = new ArrayList(); - List badTrks = new ArrayList(); - - List sample = new ArrayList(); - List selected = new ArrayList(); - for( int i=0;i= 2 ) { - sample.add(tj); - break; - } - } - } - - } - - // find the best clone - int size = 0; - int itr = 0; - selected.clear(); - for( int j=0;j= size ) { - size = tmpsize; - selected.add(ts); - } - else { - badTrks.add(ts); - } - } - - // add the best clone to the good tracks - goodTrks.addAll( selected); - - // remove the bad one from tracks - tracks.removeAll(badTrks); - - } - goodTrks.removeAll(badTrks); - return goodTrks; - } - - public List> CAonRZ(List> xytracks , - List> bmtC_crosses) { - - List> seedCrosses = new ArrayList>(); - if( bmtC_crosses == null ) return null; + public List> CAonRZ(List> xytracks, + List> bmtC_crosses) { + + List> seedCrosses = new ArrayList<>(); + + if (bmtC_crosses == null) { + return null; + } // System.out.println("not null bmtc"); - // loop over each xytrack to find ZR candidates - // --------------------------------------------- + // loop over each xytrack to find ZR candidates + // --------------------------------------------- // for( List xycross : xytracks ){ // ALERT: this throw a concurrent modification exception - for( int ixy=0; ixy< xytracks.size();ixy++ ){ - List xycross = xytracks.get(ixy); - ArrayList crsZR = new ArrayList(); - // get the SVT crosses - ArrayList svtcrs = new ArrayList(); - - // look for svt crosses and determine the sector from bmt z crosses - //------------------------------------------------------------------ - int sector = -1; - for( Cross c : xycross ){ - if( c.get_Detector()==DetectorType.BST){ - svtcrs.add(c); -// System.out.print( " " + c.get_Id() + " " +c.get_Detector() + " " + c.get_DetectorType() + " ; " ); - } - else { - sector = c.get_Sector()-1; - } - } + for (int ixy = 0; ixy < xytracks.size(); ixy++) { + List xycross = xytracks.get(ixy); + ArrayList crsZR = new ArrayList<>(); + // get the SVT crosses + ArrayList svtcrs = new ArrayList<>(); + + // look for svt crosses and determine the sector from bmt z crosses + //------------------------------------------------------------------ + int sector = -1; + for (Cross c : xycross) { + if (c.getDetector() == DetectorType.BST) { + svtcrs.add(c); +// System.out.print( " " + c.getId() + " " +c.getDetector() + " " + c.getDetectorType() + " ; " ); + } else { + sector = c.getSector() - 1; + } + } // System.out.println(sector); - if( sector < 0 ) continue; - Collections.sort(svtcrs); + if (sector < 0) { + continue; + } + Collections.sort(svtcrs); // Collections.sort(svtcrs,Collections.reverseOrder()); // for( Cross c : svtcrs ){ -// System.out.print( " " + c.get_Id() + " " +c.get_Detector() + " " + c.get_DetectorType() + " ; " ); +// System.out.print( " " + c.getId() + " " +c.getDetector() + " " + c.getDetectorType() + " ; " ); // } // System.out.println(); // crsZR.addAll(svtcrs); - // add all the BMT_C crosses - //-------------------------- + // add all the BMT_C crosses + //-------------------------- // for( Cross c : bmtC_crosses.get(sector) ){ -// System.out.print( " " + c.get_Id() + " " +c.get_Detector() + " " + c.get_DetectorType() + " ; " ); +// System.out.print( " " + c.getId() + " " +c.getDetector() + " " + c.getDetectorType() + " ; " ); // } // System.out.println(); - if( bmtC_crosses.get(sector) == null || bmtC_crosses.get(sector).size() == 0 ) continue; - crsZR.addAll( bmtC_crosses.get(sector) ); + if (bmtC_crosses.get(sector) == null || bmtC_crosses.get(sector).isEmpty()) { + continue; + } + crsZR.addAll(bmtC_crosses.get(sector)); // System.out.println("\n....\t"+crsZR); - // sort + // sort // Collections.sort(crsZR,Collections.reverseOrder()); // Collections.sort(crsZR); - - // run the CAmaker - List zrnodes = runCAMaker( "ZR", 5, crsZR); + // run the CAmaker + List zrnodes = runCAMaker("ZR", 5, crsZR); //System.out.println(zrnodes); - List> zrtracks = getCAcandidates( zrnodes); + List> zrtracks = getCAcandidates(zrnodes); // System.out.println("sector" + sector + " len " + zrtracks.size()); - - // collect crosses for candidates - //-------------------------------- - for( List zrcross : zrtracks ){ - // count svt crosses. If none, skip the candidate // TODO - //int Nsvt = 0; - //for( Cross c : zrcross ){ - //if( c.get_Detector().equalsIgnoreCase("SVT")){ - //Nsvt++; - //} - //} - //if( Nsvt == 0 ) continue; - - - // FIT ZR BMT - // --------------------------- - List R = new ArrayList(); - List Z = new ArrayList(); - List EZ= new ArrayList(); - - for( Cross c : zrcross ) { - R.add( bgeo.getRadiusMidDrift(c.get_Cluster1().get_Layer())); - Z.add( c.get_Point().z() ); - EZ.add( c.get_PointErr().z()); - } - - LineFitter ft = new LineFitter(); - boolean status = ft.fitStatus(Z, R, EZ, null, Z.size()); - if( status == false ) { System.err.println(" BMTC FIT FAILED");} - LineFitPars fpars = ft.getFit(); - if( fpars == null ) continue; - double b = fpars.intercept(); - double m = fpars.slope(); - - - seedCrosses.add( new ArrayList() ); - int scsize = seedCrosses.size(); - // add svt - for( Cross c : svtcrs ){ - int l1 = c.get_Cluster1().get_Layer(); - int s1 = c.get_Cluster1().get_Sector(); - double c1 = c.get_Cluster1().get_Centroid(); - double r1 = SVTGeometry.getLayerRadius(l1); - double nstr1 = sgeo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r1 - b)/m, l1, s1); - - int l2 = c.get_Cluster2().get_Layer(); - int s2 = c.get_Cluster2().get_Sector(); - double c2 = c.get_Cluster2().get_Centroid(); - double r2 = SVTGeometry.getLayerRadius(l2); - double nstr2 = sgeo.calcNearestStrip(c.get_Point().x(),c.get_Point().y(), (r2 - b)/m, l2, s2); - - if( Math.abs( c1 - nstr1 ) < 8 && Math.abs( c2 - nstr2 ) < 8 ) - seedCrosses.get(scsize-1).add(c); - } + // collect crosses for candidates + //-------------------------------- + for (List zrcross : zrtracks) { + // count svt crosses. If none, skip the candidate // TODO + //int Nsvt = 0; + //for( Cross c : zrcross ){ + //if( c.getDetector().equalsIgnoreCase("SVT")){ + //Nsvt++; + //} + //} + //if( Nsvt == 0 ) continue; + + // FIT ZR BMT + // --------------------------- + List R = new ArrayList<>(); + List Z = new ArrayList<>(); + List EZ = new ArrayList<>(); + + for (Cross c : zrcross) { + R.add(bgeo.getRadiusMidDrift(c.getCluster1().getLayer())); + Z.add(c.getPoint().z()); + EZ.add(c.getPointErr().z()); + } + + LineFitter ft = new LineFitter(); + boolean status = ft.fitStatus(Z, R, EZ, null, Z.size()); + if (status == false) { + System.err.println(" BMTC FIT FAILED"); + } + LineFitPars fpars = ft.getFit(); + if (fpars == null) { + continue; + } + double b = fpars.intercept(); + double m = fpars.slope(); + + seedCrosses.add(new ArrayList<>()); + int scsize = seedCrosses.size(); + // add svt + for (Cross c : svtcrs) { + int l1 = c.getCluster1().getLayer(); + int s1 = c.getCluster1().getSector(); + double c1 = c.getCluster1().getCentroid(); + double r1 = SVTGeometry.getLayerRadius(l1); + double nstr1 = sgeo.calcNearestStrip(c.getPoint().x(), c.getPoint().y(), (r1 - b) / m, l1, s1); + + int l2 = c.getCluster2().getLayer(); + int s2 = c.getCluster2().getSector(); + double c2 = c.getCluster2().getCentroid(); + double r2 = SVTGeometry.getLayerRadius(l2); + double nstr2 = sgeo.calcNearestStrip(c.getPoint().x(), c.getPoint().y(), (r2 - b) / m, l2, s2); + + if (Math.abs(c1 - nstr1) < 8 && Math.abs(c2 - nstr2) < 8) { + seedCrosses.get(scsize - 1).add(c); + } + } // for( Cross c : zrcross ){ -// if( c.get_Detector().equalsIgnoreCase("SVT")){ +// if( c.getDetector().equalsIgnoreCase("SVT")){ // seedCrosses.get(scsize-1).add(c); // } // } + // add bmt z + for (Cross c : xycross) { + if (c.getDetector() == DetectorType.BMT) { + seedCrosses.get(scsize - 1).add(c); + } + } - // add bmt z - for( Cross c : xycross ){ - if( c.get_Detector()==DetectorType.BMT){ - seedCrosses.get(scsize-1).add(c); - } - } - - // add bmt c - for( Cross c : zrcross ){ - if( c.get_Detector()==DetectorType.BMT){ - seedCrosses.get(scsize-1).add(c); - } - } + // add bmt c + for (Cross c : zrcross) { + if (c.getDetector() == DetectorType.BMT) { + seedCrosses.get(scsize - 1).add(c); + } + } + } } - } - return seedCrosses; + return seedCrosses; } -// private List X = new ArrayList(); -// private List Y = new ArrayList(); -// private List Z = new ArrayList(); -// private List Rho = new ArrayList(); -// private List ErrZ = new ArrayList(); -// private List ErrRho = new ArrayList(); -// private List ErrRt = new ArrayList(); -// List BMTCrossesC = new ArrayList(); -// List BMTCrossesZ = new ArrayList(); -// List SVTCrosses = new ArrayList(); -// float b[] = new float[3]; -// -// public Track fit(List VTCrosses, -// SVTGeometry svt_geo, BMTGeometry bmt_geo, int fitIter, boolean originConstraint, -// Swim swimmer) { -// double chisqMax = Double.POSITIVE_INFINITY; -// Collections.sort(VTCrosses); -// Track cand = null; -// HelicalTrackFitter fitTrk = new HelicalTrackFitter(); -// for (int i = 0; i < fitIter; i++) { -// // if(originConstraint==true) { -// // X.add(0, (double) 0); -// // Y.add(0, (double) 0); -// // Z.add(0, (double) 0); -// // Rho.add(0, (double) 0); -// // ErrRt.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); -// // ErrZ.add(0, (double) org.jlab.rec.cvt.svt.Constants.ZVTXCONSTRAINT); -// // ErrRho.add(0, (double) org.jlab.rec.cvt.svt.Constants.RHOVTXCONSTRAINT); -// // } -// X.clear(); -// Y.clear(); -// Z.clear(); -// Rho.clear(); -// ErrZ.clear(); -// ErrRho.clear(); -// ErrRt.clear(); -// -// int svtSz = 0; -// int bmtZSz = 0; -// int bmtCSz = 0; -// -// BMTCrossesC.clear(); -// BMTCrossesZ.clear(); -// SVTCrosses.clear(); -// -// for (Cross c : VTCrosses) { -// if (c.get_Detector()==DetectorType.BST) { -// SVTCrosses.add(c); -// } -// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.C ) { -// BMTCrossesC.add(c); -// } -// else if (c.get_Detector()==DetectorType.BMT && c.get_Type()==BMTType.Z ) { -// BMTCrossesZ.add(c); -// } -// } -// svtSz = SVTCrosses.size(); -// if (BMTCrossesZ != null) { -// bmtZSz = BMTCrossesZ.size(); -// } -// if (BMTCrossesC != null) { -// bmtCSz = BMTCrossesC.size(); -// } -// -// int useSVTdipAngEst = 1; -// if (bmtCSz >= 2) { -// useSVTdipAngEst = 0; -// } -// -// ((ArrayList) X).ensureCapacity(svtSz + bmtZSz); -// ((ArrayList) Y).ensureCapacity(svtSz + bmtZSz); -// ((ArrayList) Z).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) Rho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) ErrZ).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); -// ((ArrayList) ErrRho).ensureCapacity(svtSz * useSVTdipAngEst + bmtCSz); // Try: don't use svt in dipdangle fit determination -// ((ArrayList) ErrRt).ensureCapacity(svtSz + bmtZSz); -// -// cand = new Track(null); -// cand.addAll(SVTCrosses); -// for (int j = 0; j < SVTCrosses.size(); j++) { -// X.add(j, SVTCrosses.get(j).get_Point().x()); -// Y.add(j, SVTCrosses.get(j).get_Point().y()); -// if (useSVTdipAngEst == 1) { -// Z.add(j, SVTCrosses.get(j).get_Point().z()); -// Rho.add(j, Math.sqrt(SVTCrosses.get(j).get_Point().x() * SVTCrosses.get(j).get_Point().x() -// + SVTCrosses.get(j).get_Point().y() * SVTCrosses.get(j).get_Point().y())); -// ErrRho.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() -// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); -// ErrZ.add(j, SVTCrosses.get(j).get_PointErr().z()); -// } -// ErrRt.add(j, Math.sqrt(SVTCrosses.get(j).get_PointErr().x() * SVTCrosses.get(j).get_PointErr().x() -// + SVTCrosses.get(j).get_PointErr().y() * SVTCrosses.get(j).get_PointErr().y())); -// } -// -// if (bmtZSz > 0) { -// for (int j = svtSz; j < svtSz + bmtZSz; j++) { -// X.add(j, BMTCrossesZ.get(j - svtSz).get_Point().x()); -// Y.add(j, BMTCrossesZ.get(j - svtSz).get_Point().y()); -// ErrRt.add(j, Math.sqrt(BMTCrossesZ.get(j - svtSz).get_PointErr().x() * BMTCrossesZ.get(j - svtSz).get_PointErr().x() -// + BMTCrossesZ.get(j - svtSz).get_PointErr().y() * BMTCrossesZ.get(j - svtSz).get_PointErr().y())); -// } -// } -// if (bmtCSz > 0) { -// for (int j = svtSz * useSVTdipAngEst; j < svtSz * useSVTdipAngEst + bmtCSz; j++) { -// Z.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Point().z()); -// Rho.add(j, bmt_geo.getRadiusMidDrift(BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_Cluster1().get_Layer())); -// -// ErrRho.add(j, bmt_geo.getThickness()/2 / Math.sqrt(12.)); -// ErrZ.add(j, BMTCrossesC.get(j - svtSz * useSVTdipAngEst).get_PointErr().z()); -// } -// } -// X.add((double) Constants.getXb()); -// Y.add((double) Constants.getYb()); -// -// ErrRt.add((double) 0.1); -// -// fitTrk.fit(X, Y, Z, Rho, ErrRt, ErrRho, ErrZ); -// -// if (fitTrk.get_helix() == null) { -// return null; -// } -// -// cand = new Track(fitTrk.get_helix()); -// //cand.addAll(SVTCrosses); -// cand.addAll(SVTCrosses); -// cand.addAll(BMTCrossesC); -// cand.addAll(BMTCrossesZ); -// -// swimmer.BfieldLab(0, 0, 0, b); -// double Bz = Math.abs(b[2]); -// fitTrk.get_helix().B = Bz; -// cand.setPXYZ(fitTrk.get_helix()); -// if( X.size()>3 ) { -// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]/(X.size()-3)); -// } -// else { -// cand.set_circleFitChi2PerNDF(fitTrk.get_chisq()[0]*2); // penalize tracks with only 3 crosses -// } -// -// if( Z.size() > 2 ) { -// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]/Z.size()); -// } -// else { -// cand.set_lineFitChi2PerNDF(fitTrk.get_chisq()[1]*2);// penalize tracks with only 2 crosses -// } -// cand.setChi2(fitTrk.get_chisq()[0]+fitTrk.get_chisq()[1]); -// cand.setNDF(X.size()+Z.size()); -// //if(shift==0) -// if (fitTrk.get_chisq()[0] < chisqMax) { -// chisqMax = fitTrk.get_chisq()[0]; -// if(chisqMaxConstants.CIRCLEFIT_MAXCHI2) -//// cand=null; -// return cand; -// } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/package-info.java deleted file mode 100644 index d375cd1a6..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.track; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java index d79e74179..bd2569226 100755 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Helix.java @@ -39,15 +39,15 @@ public class Helix { public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double xb, double yb, double[][] covmatrix) { this(dca, phi_at_doca, curvature, Z0, tandip, xb, yb); - set_covmatrix(covmatrix); + setCovMatrix(covmatrix); } public Helix(double dca, double phi_at_doca, double curvature, double Z0, double tandip, double xb, double yb) { - set_dca(dca); - set_phi_at_dca(phi_at_doca); - set_curvature(curvature); - set_Z0(Z0); - set_tandip(tandip); + setDCA(dca); + setPhiAtDCA(phi_at_doca); + setCurvature(curvature); + setZ0(Z0); + setTanDip(tandip); setXb(xb); setYb(yb); } @@ -69,71 +69,71 @@ public final void setYb(double yb) { } - public double get_dca() { + public double getDCA() { return _dca; } - public final void set_dca(double dca) { + public final void setDCA(double dca) { this._dca = dca; } - public double get_phi_at_dca() { + public double getPhiAtDCA() { return _phi_at_dca; } - public final void set_phi_at_dca(double phi_at_dca) { + public final void setPhiAtDCA(double phi_at_dca) { this._phi_at_dca = phi_at_dca; } - public double get_curvature() { + public double getCurvature() { return _curvature; } - public final void set_curvature(double curvature) { + public final void setCurvature(double curvature) { this._curvature = curvature; } - public double get_Z0() { + public double getZ0() { return _Z0; } - public final void set_Z0(double Z0) { + public final void setZ0(double Z0) { this._Z0 = Z0; } - public double get_tandip() { + public double getTanDip() { return _tandip; } - public final void set_tandip(double tandip) { + public final void setTanDip(double tandip) { this._tandip = tandip; } - public double[][] get_covmatrix() { + public double[][] getCovMatrix() { return _covmatrix; } - public final void set_covmatrix(double[][] covmatrix) { + public final void setCovMatrix(double[][] covmatrix) { this._covmatrix = covmatrix; } //tandip = pz/pt // cos(theta) - public double costheta() { - double costh = (this.get_tandip() / Math.sqrt(1 + this.get_tandip() * this.get_tandip())); + public double cosTheta() { + double costh = (this.getTanDip() / Math.sqrt(1 + this.getTanDip() * this.getTanDip())); return costh; } - private double invtandip() { - if (this.get_tandip() == 0) { + private double invTanDip() { + if (this.getTanDip() == 0) { return 0; } - return 1. / this.get_tandip(); + return 1. / this.getTanDip(); } // sin(theta) = pt/p - public double sintheta() { - double sinth = (this.invtandip() / Math.sqrt(1 + this.invtandip() * this.invtandip())); + public double sinTheta() { + double sinth = (this.invTanDip() / Math.sqrt(1 + this.invTanDip() * this.invTanDip())); return sinth; } @@ -148,25 +148,25 @@ public double radius() { } // (x,y) coordinates of the circle center - public double xcen() { - return (radius() - this.get_dca()) * Math.sin(this.get_phi_at_dca()); + public double xCen() { + return (radius() - this.getDCA()) * Math.sin(this.getPhiAtDCA()); } - public double ycen() { - return (-radius() + this.get_dca()) * Math.cos(this.get_phi_at_dca()); + public double yCen() { + return (-radius() + this.getDCA()) * Math.cos(this.getPhiAtDCA()); } // (x,y) coordinates of the dca - public double xdca() { - return -this.get_dca() * Math.sin(this.get_phi_at_dca()); + public double xDCA() { + return -this.getDCA() * Math.sin(this.getPhiAtDCA()); } - public double ydca() { - return this.get_dca() * Math.cos(this.get_phi_at_dca()); + public double yDCA() { + return this.getDCA() * Math.cos(this.getPhiAtDCA()); } public Point3D getVertex() { - return new Point3D(this.xdca()+this.getXb(),this.ydca()+this.getYb(),this.get_Z0()); + return new Point3D(this.xDCA()+this.getXb(),this.yDCA()+this.getYb(),this.getZ0()); } public double getPt(double solenoidMag) { @@ -178,27 +178,27 @@ public double getPt(double solenoidMag) { public Vector3D getPXYZ(double solenoidMag) { double pt = this.getPt(solenoidMag); - double pz = pt*this.get_tandip(); - double px = pt*Math.cos(this.get_phi_at_dca()); - double py = pt*Math.sin(this.get_phi_at_dca()); + double pz = pt*this.getTanDip(); + double px = pt*Math.cos(this.getPhiAtDCA()); + double py = pt*Math.sin(this.getPhiAtDCA()); return new Vector3D(px,py,pz); } - public double getArcLength_dca(Point3D refpoint) { + public double getArcLengthDCA(Point3D refpoint) { //insure that the refpoint is on the helix if (refpoint == null) { return 0; } double refX = radius() * Math.cos(refpoint.toVector3D().phi()); double refY = radius() * Math.sin(refpoint.toVector3D().phi()); - double arclen = ArcLength(xcen(), ycen(), radius(), xcen(), ycen(), refX, refY); + double arclen = arcLength(xCen(), yCen(), radius(), xCen(), yCen(), refX, refY); return arclen; } // this method finds the arclength between 2 points in a circle // this private method is used to get the pathlength from a point on the helical track to the distance of closest approach - private double ArcLength(double xcenter, double ycenter, double circrad, double x1, double y1, double x2, double y2) { + private double arcLength(double xcenter, double ycenter, double circrad, double x1, double y1, double x2, double y2) { // Find the azimuth of the 2 points and dphi double x1toxc = x1 - xcenter; double y1toyc = y1 - ycenter; @@ -219,7 +219,7 @@ private double ArcLength(double xcenter, double ycenter, double circrad, double return arclen; } - public int get_charge() { + public int getCharge() { int charge = (int) Math.signum(_curvature); return charge; @@ -229,7 +229,7 @@ public Point3D getPointAtRadius(double r) { // a method to return a point (as a vector) at a given radial position. double d0 = _dca; double omega = _curvature; - double charge = this.get_charge(); + double charge = this.getCharge(); double phi0 = _phi_at_dca; double tandip = _tandip; double z0 = _Z0; @@ -275,11 +275,11 @@ public Vector3D getTrackDirectionAtRadius(double r) { double alpha = newPathLength * omega; - double sintheta = Math.abs(sintheta()); + double sintheta = Math.abs(sinTheta()); double ux = Math.cos(-alpha + phi0) * sintheta; double uy = Math.sin(-alpha + phi0) * sintheta; - double uz = costheta(); + double uz = cosTheta(); Vector3D trkDir = new Vector3D(ux, uy, uz); @@ -291,9 +291,4 @@ public String toString() { String s = String.format("Helix: Z0=%.4f R=%.4e DCA=%.4f Phi=%.4f Tan=%.4f", this._Z0,this._curvature,this._dca,this._phi_at_dca,this._tandip); return s; } - - public static void main(String arg[]) { - // Helix h = new Helix(0, 0, 1/5., 0, -999, null); - - } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java index 9ea095d61..a6410165b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Ray.java @@ -54,97 +54,97 @@ public Ray(double yxSlope, double yxSlopeErr, double yxInterc, double yxIntercEr } - public Point3D get_refPoint() { + public Point3D getRefPoint() { return _refPoint; } - public void set_refPoint(Point3D _refPoint) { + public void setRefPoint(Point3D _refPoint) { this._refPoint = _refPoint; } - public Vector3D get_dirVec() { + public Vector3D getDirVec() { return _dirVec; } - public void set_dirVec(Vector3D _dirVec) { + public void setDirVec(Vector3D _dirVec) { this._dirVec = _dirVec; } - public double get_yxslope() { + public double getYXSlope() { return _yxslope; } - public void set_yxslope(double _yxslope) { + public void setYXSlope(double _yxslope) { this._yxslope = _yxslope; } - public double get_yzslope() { + public double getYZSlope() { return _yzslope; } - public void set_yzslope(double _yzslope) { + public void setYZSlope(double _yzslope) { this._yzslope = _yzslope; } - public double get_yxinterc() { + public double getYXInterc() { return _yxinterc; } - public void set_yxinterc(double _yxinterc) { + public void setYXInterc(double _yxinterc) { this._yxinterc = _yxinterc; } - public double get_yzinterc() { + public double getYZInterc() { return _yzinterc; } - public void set_yzinterc(double _yzinterc) { + public void setYZInterc(double _yzinterc) { this._yzinterc = _yzinterc; } - public double get_yxslopeErr() { + public double getYXSlopeErr() { return _yxslopeErr; } - public void set_yxslopeErr(double _yxslopeErr) { + public void setYXSlopeErr(double _yxslopeErr) { this._yxslopeErr = _yxslopeErr; } - public double get_yzslopeErr() { + public double getYZSlopeErr() { return _yzslopeErr; } - public void set_yzslopeErr(double _yzslopeErr) { + public void setYZSlopeErr(double _yzslopeErr) { this._yzslopeErr = _yzslopeErr; } - public double get_yxintercErr() { + public double getYXIntercErr() { return _yxintercErr; } - public void set_yxintercErr(double _yxintercErr) { + public void setYXInterErr(double _yxintercErr) { this._yxintercErr = _yxintercErr; } - public double get_yzintercErr() { + public double getYZIntercErr() { return _yzintercErr; } - public void set_yzintercErr(double _yzintercErr) { + public void setYZIntercErr(double _yzintercErr) { this._yzintercErr = _yzintercErr; } public double[][] getCovMat() { double[][] cov = new double[5][5]; - cov[0][0] = this.get_yxintercErr()*this.get_yxintercErr(); - cov[1][1] = this.get_yzintercErr()*this.get_yzintercErr(); - cov[2][2] = this.get_yxslopeErr()*this.get_yxslopeErr(); - cov[3][3] = this.get_yzslopeErr()*this.get_yzslopeErr(); + cov[0][0] = this.getYXIntercErr()*this.getYXIntercErr(); + cov[1][1] = this.getYZIntercErr()*this.getYZIntercErr(); + cov[2][2] = this.getYXSlopeErr()*this.getYXSlopeErr(); + cov[3][3] = this.getYZSlopeErr()*this.getYZSlopeErr(); cov[4][4] = 1; return cov; } public Line3D toLine() { - return new Line3D(this.get_refPoint(), this.get_dirVec()); + return new Line3D(this.getRefPoint(), this.getDirVec()); } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java index 2dfddb77a..59afe9b13 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/StateVec.java @@ -36,88 +36,88 @@ public class StateVec implements Comparable { private double _uy; private double _uz; - public int get_ID() { + public int getID() { return _ID; } - public void set_ID(int _ID) { + public void setID(int _ID) { this._ID = _ID; } - public double get_Path() { + public double getPath() { return _Path; } - public void set_Path(double _Path) { + public void setPath(double _Path) { this._Path = _Path; } - public int get_SurfaceDetector() { + public int getSurfaceDetector() { return _SurfaceDetector; } - public void set_SurfaceDetector(int _SurfaceDetector) { + public void setSurfaceDetector(int _SurfaceDetector) { this._SurfaceDetector = _SurfaceDetector; } - public int get_SurfaceLayer() { + public int getSurfaceLayer() { return _SurfaceLayer; } - public void set_SurfaceLayer(int _SurfaceLayer) { + public void setSurfaceLayer(int _SurfaceLayer) { this._SurfaceLayer = _SurfaceLayer; } - public int get_SurfaceSector() { + public int getSurfaceSector() { return _SurfaceSector; } - public void set_SurfaceSector(int _SurfaceSector) { + public void setSurfaceSector(int _SurfaceSector) { this._SurfaceSector = _SurfaceSector; } - public double get_TrkPhiAtSurface() { + public double getTrkPhiAtSurface() { return _TrkPhiAtSurface; } /** * @return the _SurfaceComponent */ - public int get_SurfaceComponent() { + public int getSurfaceComponent() { return _SurfaceComponent; } /** * @param _SurfaceComponent the _SurfaceComponent to set */ - public void set_SurfaceComponent(int _SurfaceComponent) { + public void setSurfaceComponent(int _SurfaceComponent) { this._SurfaceComponent = _SurfaceComponent; } - public void set_TrkPhiAtSurface(double _TrkPhiAtSurface) { + public void setTrkPhiAtSurface(double _TrkPhiAtSurface) { this._TrkPhiAtSurface = _TrkPhiAtSurface; } - public double get_TrkThetaAtSurface() { + public double getTrkThetaAtSurface() { return _TrkThetaAtSurface; } - public void set_TrkThetaAtSurface(double _TrkThetaAtSurface) { + public void setTrkThetaAtSurface(double _TrkThetaAtSurface) { this._TrkThetaAtSurface = _TrkThetaAtSurface; } - public double get_TrkToModuleAngle() { + public double getTrkToModuleAngle() { return _TrkToModuleAngle; } - public void set_TrkToModuleAngle(double _TrkToModuleAngle) { + public void setTrkToModuleAngle(double _TrkToModuleAngle) { this._TrkToModuleAngle = _TrkToModuleAngle; } - public double get_CalcCentroidStrip() { + public double getCalcCentroidStrip() { return _CalcCentroidStrip; } - public void set_CalcCentroidStrip(double _CalcCentroidStrip) { + public void setCalcCentroidStrip(double _CalcCentroidStrip) { this._CalcCentroidStrip = _CalcCentroidStrip; } @@ -148,7 +148,7 @@ public void set(StateVec V) { * @return the wire plane index in the series of planes used in the * trajectory */ - public int get_planeIdx() { + public int getPlaneIdx() { return _planeIdx; } @@ -158,7 +158,7 @@ public int get_planeIdx() { * @param _planeIdx wire plane index in the series of planes used in the * trajectory */ - public void set_planeIdx(int _planeIdx) { + public void setPlaneIdx(int _planeIdx) { this._planeIdx = _planeIdx; } @@ -264,15 +264,15 @@ public double uz() { public int compareTo(StateVec arg) { int return_val = 0; - if (Constants.isCosmicsData == false) { - int RegComp = this.get_SurfaceLayer() < arg.get_SurfaceLayer() ? -1 : this.get_SurfaceLayer() == arg.get_SurfaceLayer() ? 0 : 1; - int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; + if (Constants.ISCOSMICDATA == false) { + int RegComp = this.getSurfaceLayer() < arg.getSurfaceLayer() ? -1 : this.getSurfaceLayer() == arg.getSurfaceLayer() ? 0 : 1; + int IDComp = this.getID() < arg.getID() ? -1 : this.getID() == arg.getID() ? 0 : 1; return_val = ((RegComp == 0) ? IDComp : RegComp); } - if (Constants.isCosmicsData == true) { + if (Constants.ISCOSMICDATA == true) { int RegComp = this.y() < arg.y() ? -1 : this.y() == arg.y() ? 0 : 1; - int IDComp = this.get_ID() < arg.get_ID() ? -1 : this.get_ID() == arg.get_ID() ? 0 : 1; + int IDComp = this.getID() < arg.getID() ? -1 : this.getID() == arg.getID() ? 0 : 1; return_val = RegComp;//((RegComp == 0) ? IDComp : RegComp); } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Trajectory.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Trajectory.java index 458e6f044..c77c2db5e 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Trajectory.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/Trajectory.java @@ -19,22 +19,22 @@ public Trajectory(Helix helix) { } public Trajectory(Ray ray) { - this.set_ray(ray); + this.setRay(ray); } - public Helix get_helix() { + public Helix getHelix() { return _helix; } - public void set_helix(Helix _helix) { + public void setHelix(Helix _helix) { this._helix = _helix; } - public Ray get_ray() { + public Ray getRay() { return _ray; } - public void set_ray(Ray _ray) { + public void setRay(Ray _ray) { this._ray = _ray; } @@ -46,46 +46,46 @@ public void set_ray(Ray _ray) { private int _Id = -1; private ArrayList _Trajectory; - public int[] get_SVTSector() { + public int[] getSVTSector() { return _Sector; } - public void set_SVTSector(int[] _Sector) { + public void setSVTSector(int[] _Sector) { this._Sector = _Sector; } - public int get_Id() { + public int getId() { return _Id; } - public void set_Id(int _Id) { + public void setId(int _Id) { this._Id = _Id; } - public ArrayList get_Trajectory() { + public ArrayList getTrajectory() { return _Trajectory; } - public void set_Trajectory(ArrayList _Trajectory) { + public void setTrajectory(ArrayList _Trajectory) { this._Trajectory = _Trajectory; } private double[][][] _SVTIntersections; private double[][][] _BMTIntersections; - public double[][][] get_SVTIntersections() { + public double[][][] getSVTIntersections() { return _SVTIntersections; } - public void set_SVTIntersections(double[][][] _SVTIntersections) { + public void setSVTIntersections(double[][][] _SVTIntersections) { this._SVTIntersections = _SVTIntersections; } - public double[][][] get_BMTIntersections() { + public double[][][] getBMTIntersections() { return _BMTIntersections; } - public void set_BMTIntersections(double[][][] _BMTIntersections) { + public void setBMTIntersections(double[][][] _BMTIntersections) { this._BMTIntersections = _BMTIntersections; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java index 0dd6453ae..1336a6991 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/TrajectoryFinder.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.trajectory; -import eu.mihosoft.vrl.v3d.Vector3d; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -9,12 +8,9 @@ import java.util.Map; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -import org.jlab.detector.hits.CTOFDetHit; -import org.jlab.detector.hits.DetHit; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.geometry.prim.Line3d; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.bmt.BMTConstants; import org.jlab.rec.cvt.bmt.BMTGeometry; @@ -40,48 +36,50 @@ public TrajectoryFinder() { /** * + * @param trk + * @param swimmer * @param isFinal * @return a trajectory object */ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { - Helix helix = trk.get_helix(); + Helix helix = trk.getHelix(); ArrayList candCrossList = trk; if(helix ==null) return null; Trajectory traj = new Trajectory(helix); - if (isFinal == "final") { + if ("final".equals(isFinal)) { traj.isFinal = true; } - traj.set_Id(trk.get_Id()); + traj.setId(trk.getId()); - if (candCrossList.size() == 0) { + if (candCrossList.isEmpty()) { System.err.print("Trajectory Error: cross list is empty"); return traj; } - ArrayList SVTCrossList = new ArrayList(); - ArrayList BMTCrossList = new ArrayList(); - Map ClsMap = new HashMap(); + ArrayList SVTCrossList = new ArrayList<>(); + ArrayList BMTCrossList = new ArrayList<>(); + Map ClsMap = new HashMap<>(); for (Cross c : candCrossList) { - if (c.get_Detector()==DetectorType.BST) { + if (c.getDetector()==DetectorType.BST) { String svtSt1 = "1."; - svtSt1+=c.get_Cluster1().get_Sector(); + svtSt1+=c.getCluster1().getSector(); svtSt1 += "."; - svtSt1+=c.get_Cluster1().get_Layer(); - ClsMap.put(svtSt1, c.get_Cluster1().get_Centroid()); + svtSt1+=c.getCluster1().getLayer(); + ClsMap.put(svtSt1, c.getCluster1().getCentroid()); String svtSt2 = "1."; - svtSt2+=c.get_Cluster2().get_Sector(); + svtSt2+=c.getCluster2().getSector(); svtSt2 += "."; - svtSt2+=c.get_Cluster2().get_Layer(); - ClsMap.put(svtSt2, c.get_Cluster2().get_Centroid()); + svtSt2+=c.getCluster2().getLayer(); + ClsMap.put(svtSt2, c.getCluster2().getCentroid()); SVTCrossList.add(c); } else { String bmtSt1 = "2."; - bmtSt1+=c.get_Cluster1().get_Sector(); + bmtSt1+=c.getCluster1().getSector(); bmtSt1 += "."; - bmtSt1+=c.get_Cluster1().get_Layer(); - ClsMap.put(bmtSt1, c.get_Cluster1().get_Centroid()); + bmtSt1+=c.getCluster1().getLayer(); + ClsMap.put(bmtSt1, c.getCluster1().getCentroid()); BMTCrossList.add(c); } } @@ -90,15 +88,15 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { int[] Sectors = new int[SVTGeometry.NLAYERS]; for (int k = 0; k < SVTCrossList.size(); k++) { - int l = SVTCrossList.get(k).get_Region() * 2 - 1; - Sectors[l - 1] = SVTCrossList.get(k).get_Sector(); - Sectors[l] = SVTCrossList.get(k).get_Sector(); + int l = SVTCrossList.get(k).getRegion() * 2 - 1; + Sectors[l - 1] = SVTCrossList.get(k).getSector(); + Sectors[l] = SVTCrossList.get(k).getSector(); } for (int a = 0; a < Sectors.length; a++) { if (Sectors[a] == 0) { - Point3D I = helix.getPointAtRadius(Constants.SVTGEOMETRY.getLayerRadius(a+1)); + Point3D I = helix.getPointAtRadius(SVTGeometry.getLayerRadius(a+1)); int sec = Constants.SVTGEOMETRY.getSector(a+1, I); @@ -106,23 +104,23 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { } } - traj.set_SVTSector(Sectors); + traj.setSVTSector(Sectors); - ArrayList stateVecs = new ArrayList(); + ArrayList stateVecs = new ArrayList<>(); // initialize swimmer starting from the track vertex double maxPathLength = 1; - //swimmer.SetSwimParameters((trk.get_helix().xdca()+Constants.getXb()) / 10, (trk.get_helix().xdca()+Constants.getXb()) / 10, trk.get_helix().get_Z0() / 10, - // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - // trk.get_P(), trk.get_Q(), maxPathLength) ; - double pz = trk.get_Pt()*trk.get_helix().get_tandip(); - double px = trk.get_Pt()*Math.cos(trk.get_helix().get_phi_at_dca()); - double py = trk.get_Pt()*Math.sin(trk.get_helix().get_phi_at_dca()); - Point3D vertex = trk.get_helix().getVertex(); + //swimmer.SetSwimParameters((trk.getHelix().xDCA()+Constants.getXb()) / 10, (trk.getHelix().xDCA()+Constants.getXb()) / 10, trk.getHelix().getZ0() / 10, + // Math.toDegrees(trk.getHelix().getPhiAtDCA()), Math.toDegrees(Math.acos(trk.getHelix().cosTheta())), + // trk.getP(), trk.getQ(), maxPathLength) ; + double pz = trk.getPt()*trk.getHelix().getTanDip(); + double px = trk.getPt()*Math.cos(trk.getHelix().getPhiAtDCA()); + double py = trk.getPt()*Math.sin(trk.getHelix().getPhiAtDCA()); + Point3D vertex = trk.getHelix().getVertex(); double x = vertex.x()/10; double y = vertex.y()/10; double z = vertex.z()/10; - swimmer.SetSwimParameters(x,y,z,px,py,pz, trk.get_Q()) ; + swimmer.SetSwimParameters(x,y,z,px,py,pz, trk.getQ()) ; double[] inters = null; double path = 0; @@ -132,7 +130,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { if(inters!=null) { //double intersPhi = Math.atan2(inters[4], inters[3]); //double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - swimmer.SetSwimParameters(inters[0], inters[1], inters[2], inters[3], inters[4], inters[5], trk.get_Q()) ; + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], inters[3], inters[4], inters[5], trk.getQ()) ; } int layer = l + 1; int sector = Sectors[l]; @@ -146,19 +144,19 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { if(inters==null) break; path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3], inters[4], inters[5]); - stVec.set_planeIdx(l); - stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); - stVec.set_SurfaceLayer(layer); - stVec.set_SurfaceSector(sector); + stVec.setPlaneIdx(l); + stVec.setSurfaceDetector(DetectorType.CVT.getDetectorId()); + stVec.setSurfaceLayer(layer); + stVec.setSurfaceSector(sector); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); // this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); Vector3D localDir = Constants.SVTGEOMETRY.getLocalTrack(layer, sector, dir); - stVec.set_TrkPhiAtSurface(dir.phi()); - stVec.set_TrkThetaAtSurface(dir.theta()); - stVec.set_TrkToModuleAngle(Constants.SVTGEOMETRY.getLocalAngle(layer, sector, dir)); - stVec.set_CalcCentroidStrip(Constants.SVTGEOMETRY.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); - stVec.set_Path(path*10); - stVec.set_ID(trk.get_Id()); + stVec.setTrkPhiAtSurface(dir.phi()); + stVec.setTrkThetaAtSurface(dir.theta()); + stVec.setTrkToModuleAngle(Constants.SVTGEOMETRY.getLocalAngle(layer, sector, dir)); + stVec.setCalcCentroidStrip(Constants.SVTGEOMETRY.calcNearestStrip(inters[0]*10, inters[1]*10, inters[2]*10, layer, sector)); + stVec.setPath(path*10); + stVec.setID(trk.getId()); stateVecs.add(stVec); String svtSt1 = "1."; svtSt1+=sector; @@ -166,27 +164,14 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { svtSt1+=layer; if(ClsMap.get(svtSt1)!=null) { double cent = ClsMap.get(svtSt1); - stVec.set_CalcCentroidStrip(cent); + stVec.setCalcCentroidStrip(cent); } - // loops over the crosses to get the strip resolutions - // for (Cross c : SVTCrossList) { - // if (matchCrossToStateVec(c, stVec, layer, sector) == false) { - // continue; - // } - // Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); - // this.fill_HelicalTrkAngleWRTSVTPlane(sector, layer, dir, svt_geo, stVec); - // // set the cross dir - // c.set_Dir(dir); - // //set z - // c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), stVec.z())); - // } - } // reinitialize from vertex maxPathLength = 1.5; swimmer.SetSwimParameters(vertex.x()/10, vertex.y()/10, vertex.z()/10, - Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - trk.get_P(), trk.get_Q(), maxPathLength) ; + Math.toDegrees(trk.getHelix().getPhiAtDCA()), Math.toDegrees(Math.acos(trk.getHelix().cosTheta())), + trk.getP(), trk.getQ(), maxPathLength) ; inters = null; path = 0; //BMT @@ -195,14 +180,14 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { if(inters!=null) { double intersPhi = Math.atan2(inters[4], inters[3]); double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.getP(), trk.getQ(), maxPathLength) ; } if(inters!=null || l==SVTGeometry.NLAYERS) { // don't swim if previous layers was not reached int layer = l - SVTGeometry.NLAYERS + 1; int region = Constants.BMTGEOMETRY.getRegion(layer); // RDV: tried using this to determine the sector but t is giving bogus number - //Point3D helixTrj = trk.get_helix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); + //Point3D helixTrj = trk.getHelix().getPointAtRadius(bmt_geo.getRadiusMidDrift(layer)); double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(layer)/10; inters = swimmer.SwimRho(radius, Constants.SWIMACCURACYBMT/10); if(inters==null || Double.isNaN(inters[0]) || Double.isNaN(inters[1]) || Double.isNaN(inters[2])) break; @@ -211,9 +196,9 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { Line3D axis = Constants.BMTGEOMETRY.getAxis(layer, sector); Point3D axisP1 = new Point3D(axis.origin().x()/10,axis.origin().y()/10, axis.origin().z()/10); Point3D axisP2 = new Point3D(axis.end().x()/10,axis.end().y()/10, axis.end().z()/10); - // swimmer.SetSwimParameters((trk.get_helix().xdca()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.get_helix().ydca()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.get_helix().get_Z0() / 10, - // Math.toDegrees(trk.get_helix().get_phi_at_dca()), Math.toDegrees(Math.acos(trk.get_helix().costheta())), - // trk.get_P(), trk.get_Q(), + // swimmer.SetSwimParameters((trk.getHelix().xDCA()+org.jlab.rec.cvt.BMTConstants.getXb()) / 10, (trk.getHelix().yDCA()+org.jlab.rec.cvt.BMTConstants.getYb()) / 10, trk.getHelix().getZ0() / 10, + // Math.toDegrees(trk.getHelix().getPhiAtDCA()), Math.toDegrees(Math.acos(trk.getHelix().cosTheta())), + // trk.getP(), trk.getQ(), // 5.0) ; inters = swimmer.SwimGenCylinder(axisP1, axisP2, radius, Constants.SWIMACCURACYBMT/10); if(inters==null) break; @@ -222,24 +207,24 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { path = path + inters[6]; //if(r>(radius - BMTConstants.LYRTHICKN)/10) { StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3]/Ra, inters[4]/Ra, inters[5]/Ra); - stVec.set_planeIdx(l); + stVec.setPlaneIdx(l); // double phiPos = Math.atan2(stVec.y(),stVec.x()); // //int sector = bmt_geo.isInSector(BMTRegIdx+1,phiPos, 0); // int sector = bmt_geo.getSector(layer,phiPos); - stVec.set_SurfaceDetector(DetectorType.CVT.getDetectorId()); - stVec.set_SurfaceSector(sector); - stVec.set_SurfaceLayer(l+1); - stVec.set_ID(trk.get_Id()); - stVec.set_Path(path*10); + stVec.setSurfaceDetector(DetectorType.CVT.getDetectorId()); + stVec.setSurfaceSector(sector); + stVec.setSurfaceLayer(l+1); + stVec.setID(trk.getId()); + stVec.setPath(path*10); Vector3D dir = new Vector3D(inters[3], inters[4], inters[5]).asUnit(); Point3D pos = new Point3D(inters[0]*10, inters[1]*10, inters[2]*10); - stVec.set_TrkPhiAtSurface(Constants.BMTGEOMETRY.getThetaZ(layer, sector, pos, dir)); - stVec.set_TrkThetaAtSurface(Constants.BMTGEOMETRY.getThetaC(layer, sector, pos, dir)); - //stVec.set_CalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); - stVec.set_CalcCentroidStrip(Constants.BMTGEOMETRY.getCstrip(region, + stVec.setTrkPhiAtSurface(Constants.BMTGEOMETRY.getThetaZ(layer, sector, pos, dir)); + stVec.setTrkThetaAtSurface(Constants.BMTGEOMETRY.getThetaC(layer, sector, pos, dir)); + //stVec.setCalcCentroidStrip(bmt_geo.getCStrip(BMTRegIdx+1, stVec.z())); + stVec.setCalcCentroidStrip(Constants.BMTGEOMETRY.getCstrip(region, new Point3D(stVec.x(),stVec.y(),stVec.z()))); - stVec.set_Path(path*10); - stVec.set_ID(trk.get_Id()); + stVec.setPath(path*10); + stVec.setID(trk.getId()); String bmtSt1 = "2."; bmtSt1+=sector; @@ -247,7 +232,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { bmtSt1+=(l+1); if(ClsMap.get(bmtSt1)!=null) { double cent = ClsMap.get(bmtSt1); - stVec.set_CalcCentroidStrip(cent); + stVec.setCalcCentroidStrip(cent); } stateVecs.add(stVec); //} @@ -261,7 +246,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { // reinitialize swimmer based on last BMT layer double intersPhi = Math.atan2(inters[4], inters[3]); double intersTheta = Math.acos(inters[5]/Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5])); - swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.get_P(), trk.get_Q(), maxPathLength) ; + swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), trk.getP(), trk.getQ(), maxPathLength) ; // swim to CTOF double radius = Constants.CTOFGEOMETRY.getRadius(1); inters = swimmer.SwimGenCylinder(new Point3D(0,0,0), new Point3D(0,0,1), radius, Constants.SWIMACCURACYCD/10); @@ -273,14 +258,14 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { intersTheta = Math.acos(inters[5]/Ra); path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3]/Ra, inters[4]/Ra, inters[5]/Ra); - stVec.set_SurfaceDetector(DetectorType.CTOF.getDetectorId()); - stVec.set_SurfaceSector(1); - stVec.set_SurfaceLayer(1); - stVec.set_ID(trk.get_Id()); - stVec.set_TrkPhiAtSurface(intersPhi); - stVec.set_TrkThetaAtSurface(intersTheta); - stVec.set_TrkToModuleAngle(0); - stVec.set_Path(path*10); + stVec.setSurfaceDetector(DetectorType.CTOF.getDetectorId()); + stVec.setSurfaceSector(1); + stVec.setSurfaceLayer(1); + stVec.setID(trk.getId()); + stVec.setTrkPhiAtSurface(intersPhi); + stVec.setTrkThetaAtSurface(intersTheta); + stVec.setTrkToModuleAngle(0); + stVec.setPath(path*10); stateVecs.add(stVec); } } @@ -293,7 +278,7 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { double intersTheta = Math.acos(inters[5]/Ra); swimmer.SetSwimParameters(inters[0], inters[1], inters[2], Math.toDegrees(intersPhi), Math.toDegrees(intersTheta), - trk.get_P(), trk.get_Q(), + trk.getP(), trk.getQ(), maxPathLength) ; // swim to CTOF Point3D center = Constants.CNDGEOMETRY.getSector(0).getSuperlayer(0).getLayer(ilayer).getComponent(0).getMidpoint(); @@ -307,116 +292,66 @@ public Trajectory findTrajectory(Track trk, Swim swimmer, String isFinal) { intersTheta = Math.acos(inters[5]/Ra); path = path + inters[6]; StateVec stVec = new StateVec(inters[0]*10, inters[1]*10, inters[2]*10, inters[3]/Ra, inters[4]/Ra, inters[5]/Ra); - stVec.set_SurfaceDetector(DetectorType.CND.getDetectorId()); - stVec.set_SurfaceSector(1); - stVec.set_SurfaceLayer(ilayer+1); - stVec.set_ID(trk.get_Id()); - stVec.set_TrkPhiAtSurface(intersPhi); - stVec.set_TrkThetaAtSurface(intersTheta); - stVec.set_TrkToModuleAngle(0); - stVec.set_Path(path*10); + stVec.setSurfaceDetector(DetectorType.CND.getDetectorId()); + stVec.setSurfaceSector(1); + stVec.setSurfaceLayer(ilayer+1); + stVec.setID(trk.getId()); + stVec.setTrkPhiAtSurface(intersPhi); + stVec.setTrkThetaAtSurface(intersTheta); + stVec.setTrkToModuleAngle(0); + stVec.setPath(path*10); stateVecs.add(stVec); } } - traj.set_Trajectory(stateVecs); + traj.setTrajectory(stateVecs); traj.addAll(BMTCrossList); return traj; } - private void fill_HelicalTrkAngleWRTBMTTangentPlane(Vector3D trkDir, StateVec stVec){ - double phiPos = Math.atan2(stVec.y(),stVec.x()); - Vector3D trkDirRot = trkDir.clone(); - trkDirRot.rotateZ(Math.PI/2-phiPos); // Bring the track direction vector in phi=0 - double thetaC = Math.abs( Math.toRadians(90) - Math.abs(Math.atan(trkDirRot.y()/trkDirRot.z())) ); - double thetaZ = Math.abs( Math.toRadians(90) - Math.abs(Math.atan(trkDirRot.y()/trkDirRot.x())) ); - if ( (trkDirRot.y()>0 && trkDirRot.x()>0)||(trkDirRot.y()<0 && trkDirRot.x()<0) ){ - thetaZ=-thetaZ; //Negative thetaZ if track is going to negative phi - } - if (stVec.z()<0){ - thetaC=-thetaC; //Negative thetaC if track is going to negative z - } - - //Fill State Vector - stVec.set_TrkPhiAtSurface(thetaZ); //Call "phi" the normal angle for Z detectors - stVec.set_TrkThetaAtSurface(thetaC); //Call "theta" the normal angle for C detectors - } - - private void fill_HelicalTrkAngleWRTSVTPlane(int sector, int layer, - Vector3D trkDir, StateVec stVec) { - Vector3D uz = Constants.SVTGEOMETRY.getNormal(layer,sector); - if(layer%2==1) uz.negative(); - Vector3D ux = new Vector3D(uz.y(), -uz.x(), 0); // longitudinal vector along the local x direction of the module - Vector3D uy = uz.cross(ux); //longitudinal vector along the local z direction of the module - Vector3D u = new Vector3D(trkDir.x(), trkDir.y(), trkDir.z()); - - double trkToMPlnAngl = Math.acos(trkDir.dot(ux)); - - double zl = u.dot(uz); - double xl = u.dot(ux); - double yl = u.dot(uy); - - double PhiTrackIntersPlane = Math.atan2(yl, xl); - double ThetaTrackIntersPlane = Math.acos(zl); - - stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); - stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); - stVec.set_TrkToModuleAngle(trkToMPlnAngl); -//// if(layer<=2 && (sector==1 || sector ==6)) { -// System.out.println("\n" + layer + " " + sector); -// System.out.println(ux.toString()); -// System.out.println(uy.toString()); -// System.out.println(uz.toString()); -// System.out.println(trkToMPlnAngl + " " + PhiTrackIntersPlane + " " + ThetaTrackIntersPlane); -// Vector3D dir = svt_geo.getLocalTrack(layer, sector, trkDir); -// System.out.println(trkDir.toString()); -// System.out.println(dir.toString()); -// System.out.println(svt_geo.getLocalAngle(layer, sector, trkDir) + " " + dir.phi() + " " + dir.theta()); -//// } - } public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList) { Trajectory traj = new Trajectory(ray); - traj.set_Id(id); + traj.setId(id); - if (candCrossList.size() == 0) { + if (candCrossList.isEmpty()) { System.err.print("Trajectory Error: cross list is empty"); return traj; } - ArrayList SVTCrossList = new ArrayList(); - ArrayList BMTCrossList = new ArrayList(); + ArrayList SVTCrossList = new ArrayList<>(); + ArrayList BMTCrossList = new ArrayList<>(); - Map ClsMap = new HashMap(); + Map ClsMap = new HashMap<>(); for (Cross c : candCrossList) { - if (c.get_Detector()==DetectorType.BST) { + if (c.getDetector()==DetectorType.BST) { String svtSt1 = "1."; - svtSt1+=c.get_Cluster1().get_Sector(); + svtSt1+=c.getCluster1().getSector(); svtSt1 += "."; - svtSt1+=c.get_Cluster1().get_Layer(); - ClsMap.put(svtSt1, c.get_Cluster1().get_Centroid()); + svtSt1+=c.getCluster1().getLayer(); + ClsMap.put(svtSt1, c.getCluster1().getCentroid()); String svtSt2 = "1."; - svtSt2+=c.get_Cluster2().get_Sector(); + svtSt2+=c.getCluster2().getSector(); svtSt2 += "."; - svtSt2+=c.get_Cluster2().get_Layer(); - ClsMap.put(svtSt2, c.get_Cluster2().get_Centroid()); + svtSt2+=c.getCluster2().getLayer(); + ClsMap.put(svtSt2, c.getCluster2().getCentroid()); SVTCrossList.add(c); } else { String bmtSt1 = "2."; - bmtSt1+=c.get_Cluster1().get_Sector(); + bmtSt1+=c.getCluster1().getSector(); bmtSt1 += "."; - bmtSt1+=c.get_Cluster1().get_Layer(); - ClsMap.put(bmtSt1, c.get_Cluster1().get_Centroid()); + bmtSt1+=c.getCluster1().getLayer(); + ClsMap.put(bmtSt1, c.getCluster1().getCentroid()); BMTCrossList.add(c); } } traj.addAll(candCrossList); - ArrayList stateVecs = new ArrayList(); + ArrayList stateVecs = new ArrayList<>(); - double[][][] SVTIntersections = calc_trackIntersSVT(ray); + double[][][] SVTIntersections = calcTrackIntersSVT(ray); for (int l = 0; l < SVTGeometry.NLAYERS; l++) { for (int s = 0; s < SVTGeometry.NSECTORS[l]; s++) { @@ -433,21 +368,21 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList double trkToMPlnAngl = SVTIntersections[l][s][5]; double CalcCentroidStrip = SVTIntersections[l][s][6]; - StateVec stVec = new StateVec(XtrackIntersPlane, YtrackIntersPlane, ZtrackIntersPlane, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); - stVec.set_ID(id); - stVec.set_SurfaceLayer(LayerTrackIntersPlane); - stVec.set_SurfaceSector(SectorTrackIntersPlane); - stVec.set_TrkPhiAtSurface(PhiTrackIntersPlane); - stVec.set_TrkThetaAtSurface(ThetaTrackIntersPlane); - stVec.set_TrkToModuleAngle(trkToMPlnAngl); - stVec.set_CalcCentroidStrip(CalcCentroidStrip); + StateVec stVec = new StateVec(XtrackIntersPlane, YtrackIntersPlane, ZtrackIntersPlane, ray.getDirVec().x(), ray.getDirVec().y(), ray.getDirVec().z()); + stVec.setID(id); + stVec.setSurfaceLayer(LayerTrackIntersPlane); + stVec.setSurfaceSector(SectorTrackIntersPlane); + stVec.setTrkPhiAtSurface(PhiTrackIntersPlane); + stVec.setTrkThetaAtSurface(ThetaTrackIntersPlane); + stVec.setTrkToModuleAngle(trkToMPlnAngl); + stVec.setCalcCentroidStrip(CalcCentroidStrip); String svtSt1 = "1."; svtSt1+=SectorTrackIntersPlane; svtSt1 += "."; svtSt1+=LayerTrackIntersPlane; if(ClsMap.get(svtSt1)!=null) { double cent = ClsMap.get(svtSt1); - stVec.set_CalcCentroidStrip(cent); + stVec.setCalcCentroidStrip(cent); } if(stateVecs.size()>0 && stateVecs.get(stateVecs.size()-1).x()==stVec.x() @@ -467,15 +402,15 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList Cluster clsOnTrk = null; if (l % 2 == 0) { - clsOnTrk = c.get_Cluster1(); + clsOnTrk = c.getCluster1(); } if (l % 2 == 1) { - clsOnTrk = c.get_Cluster2(); + clsOnTrk = c.getCluster2(); } - if (clsOnTrk != null && clsOnTrk.get_Layer() == l + 1) { + if (clsOnTrk != null && clsOnTrk.getLayer() == l + 1) { - setHitResolParams("SVT", clsOnTrk.get_Sector(), clsOnTrk.get_Layer(), clsOnTrk, + setHitResolParams("SVT", clsOnTrk.getSector(), clsOnTrk.getLayer(), clsOnTrk, stVec, traj.isFinal); } @@ -484,7 +419,7 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList } } - double[][][] BMTIntersections = calc_trackIntersBMT(ray, BMTConstants.STARTINGLAYR); + double[][][] BMTIntersections = calcTrackIntersBMT(ray, BMTConstants.STARTINGLAYR); for (int l = BMTConstants.STARTINGLAYR - 1; l < 6; l++) { //hemisphere 1-2 @@ -496,29 +431,29 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList double XtrackIntersSurf = BMTIntersections[l][h][0]; double YtrackIntersSurf = BMTIntersections[l][h][1]; double ZtrackIntersSurf = BMTIntersections[l][h][2]; - //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.isInSectorJitter)); + //int SectorTrackIntersSurf = bmt_geo.isInSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf), Math.toRadians(BMTConstants.ISINSECTORJITTER)); int SectorTrackIntersSurf = Constants.BMTGEOMETRY.getSector(LayerTrackIntersSurf, Math.atan2(YtrackIntersSurf, XtrackIntersSurf)); double PhiTrackIntersSurf = BMTIntersections[l][h][3]; double ThetaTrackIntersSurf = BMTIntersections[l][h][4]; double trkToMPlnAngl = BMTIntersections[l][h][5]; double CalcCentroidStrip = BMTIntersections[l][h][6]; - StateVec stVec = new StateVec(XtrackIntersSurf, YtrackIntersSurf, ZtrackIntersSurf, ray.get_dirVec().x(), ray.get_dirVec().y(), ray.get_dirVec().z()); + StateVec stVec = new StateVec(XtrackIntersSurf, YtrackIntersSurf, ZtrackIntersSurf, ray.getDirVec().x(), ray.getDirVec().y(), ray.getDirVec().z()); - stVec.set_ID(id); - stVec.set_SurfaceLayer(LayerTrackIntersSurf); - stVec.set_SurfaceSector(SectorTrackIntersSurf); - stVec.set_TrkPhiAtSurface(PhiTrackIntersSurf); - stVec.set_TrkThetaAtSurface(ThetaTrackIntersSurf); - stVec.set_TrkToModuleAngle(trkToMPlnAngl); - stVec.set_CalcCentroidStrip(CalcCentroidStrip); + stVec.setID(id); + stVec.setSurfaceLayer(LayerTrackIntersSurf); + stVec.setSurfaceSector(SectorTrackIntersSurf); + stVec.setTrkPhiAtSurface(PhiTrackIntersSurf); + stVec.setTrkThetaAtSurface(ThetaTrackIntersSurf); + stVec.setTrkToModuleAngle(trkToMPlnAngl); + stVec.setCalcCentroidStrip(CalcCentroidStrip); String bmtSt1 = "2."; bmtSt1+=SectorTrackIntersSurf; bmtSt1 += "."; bmtSt1+=LayerTrackIntersSurf; if(ClsMap.get(bmtSt1)!=null) { double cent = ClsMap.get(bmtSt1); - stVec.set_CalcCentroidStrip(cent); + stVec.setCalcCentroidStrip(cent); } if(stateVecs.size()>0 && stateVecs.get(stateVecs.size()-1).x()==stVec.x() @@ -532,35 +467,35 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList // for the BMT // loops over the crosses to get the strip resolutions for (Cross c : BMTCrossList) { - if (c.get_Region() != (int) (l / 2) + 1) { + if (c.getRegion() != (int) (l / 2) + 1) { continue; } - if (this.matchCrossToStateVec(c, stVec, l + 1, c.get_Sector()) == false) { + if (this.matchCrossToStateVec(c, stVec, l + 1, c.getSector()) == false) { continue; } - if (c.get_Type()==BMTType.C) { //C-detector measuring Z + if (c.getType()==BMTType.C) { //C-detector measuring Z //if(traj.isFinal) { // reset the cross only for final trajectory -// c.set_Point(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.get_Point().z())); -// c.set_Dir(ray.get_dirVec()); +// c.setPoint(new Point3D(XtrackIntersSurf, YtrackIntersSurf, c.getPoint().z())); +// c.setDir(ray.getDirVec()); //} // calculate the hit residuals // CHECK THIS ........ - this.setHitResolParams("BMT", c.get_Sector(), c.get_Cluster1().get_Layer(), c.get_Cluster1(), + this.setHitResolParams("BMT", c.getSector(), c.getCluster1().getLayer(), c.getCluster1(), stVec, traj.isFinal); } - if (c.get_Type()==BMTType.Z) { //Z-detector measuring phi + if (c.getType()==BMTType.Z) { //Z-detector measuring phi //if(traj.isFinal) { -// c.set_Point(new Point3D(c.get_Point().x(), c.get_Point().y(), ZtrackIntersSurf)); -// c.set_Dir(ray.get_dirVec()); +// c.setPoint(new Point3D(c.getPoint().x(), c.getPoint().y(), ZtrackIntersSurf)); +// c.setDir(ray.getDirVec()); // //} // calculate the hit residuals - this.setHitResolParams("BMT", c.get_Cluster1().get_Sector(), c.get_Cluster1().get_Layer(), c.get_Cluster1(), + this.setHitResolParams("BMT", c.getCluster1().getSector(), c.getCluster1().getLayer(), c.getCluster1(), stVec, traj.isFinal); } @@ -574,41 +509,41 @@ public Trajectory findTrajectory(int id, Ray ray, ArrayList candCrossList stateVecs.sort(Comparator.comparing(StateVec::y)); for (int l = 0; l < stateVecs.size(); l++) { - stateVecs.get(l).set_planeIdx(l); + stateVecs.get(l).setPlaneIdx(l); } - traj.set_Trajectory(stateVecs); - traj.set_SVTIntersections(SVTIntersections); - traj.set_BMTIntersections(BMTIntersections); + traj.setTrajectory(stateVecs); + traj.setSVTIntersections(SVTIntersections); + traj.setBMTIntersections(BMTIntersections); return traj; } private boolean matchCrossToStateVec(Cross c, StateVec stVec, int layer, int sector) { - if (c.get_Detector()==DetectorType.BST) { + if (c.getDetector()==DetectorType.BST) { int l = layer - 1; - if (c.get_Region() != (int) (l / 2) + 1) { + if (c.getRegion() != (int) (l / 2) + 1) { return false; // require same region } - if (c.get_Sector() != sector) { + if (c.getSector() != sector) { return false; // same sector } - double deltaXt = Math.sqrt((stVec.x() - c.get_Point().x()) * (stVec.x() - c.get_Point().x()) + (stVec.y() - c.get_Point().y()) * (stVec.y() - c.get_Point().y())); + double deltaXt = Math.sqrt((stVec.x() - c.getPoint().x()) * (stVec.x() - c.getPoint().x()) + (stVec.y() - c.getPoint().y()) * (stVec.y() - c.getPoint().y())); if (deltaXt > SVTGeometry.getActiveSensorWidth() / 2) { return false; // within 1/2 module width } } - if (c.get_Detector()==DetectorType.BMT) { // BMT + if (c.getDetector()==DetectorType.BMT) { // BMT double Rsv = Math.sqrt(stVec.x()*stVec.x()+stVec.y()*stVec.y()); - double Rcs = Math.sqrt(c.get_Point().x()*c.get_Point().x()+c.get_Point().y()*c.get_Point().y()); + double Rcs = Math.sqrt(c.getPoint().x()*c.getPoint().x()+c.getPoint().y()*c.getPoint().y()); if(Math.abs(Rsv-Rcs)>1.e-01) { return false; } - if(new Vector3D(stVec.x(), stVec.y(), stVec.z()).asUnit().dot(c.get_Point().toVector3D().asUnit())<0.8){ + if(new Vector3D(stVec.x(), stVec.y(), stVec.z()).asUnit().dot(c.getPoint().toVector3D().asUnit())<0.8){ return false; } @@ -631,8 +566,8 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl if (detector.equalsIgnoreCase("SVT") ) { double doca2Cls = cluster.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); double doca2Seed = cluster.get(0).residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); - cluster.set_SeedResidual(doca2Seed); - cluster.set_CentroidResidual(doca2Cls); + cluster.setSeedResidual(doca2Seed); + cluster.setCentroidResidual(doca2Cls); cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); // Point3D endPt1 = cluster.getEndPoint1(); // Point3D endPt2 = cluster.getEndPoint2(); @@ -642,65 +577,65 @@ public void setHitResolParams(String detector, int sector, int layer, Cluster cl // System.out.println(d+" calc "+l.distance(new Point3D(stVec.x(), stVec.y(), stVec.z())).length()+" d "+doca2Cls); for (Hit hit : cluster) { double doca1 = hit.residual(new Point3D(stVec.x(), stVec.y(), stVec.z())); - double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, hit.get_Strip().get_Strip(), stVec.z()); - hit.set_stripResolutionAtDoca(sigma1); - hit.set_docaToTrk(doca1); - hit.set_TrkgStatus(1); + double sigma1 = Constants.SVTGEOMETRY.getSingleStripResolution(layer, hit.getStrip().getStrip(), stVec.z()); + hit.setstripResolutionAtDoca(sigma1); + hit.setdocaToTrk(doca1); + hit.setTrkgStatus(1); if (trajFinal) { - hit.set_TrkgStatus(2); + hit.setTrkgStatus(2); } } } if (detector.equalsIgnoreCase("BMT")) { cluster.setTrakInters(new Point3D(stVec.x(), stVec.y(), stVec.z())); - Point3D offset = Constants.BMTGEOMETRY.getOffset(cluster.get_Layer(), cluster.get_Sector()); - Vector3D rotation = Constants.BMTGEOMETRY.getRotation(cluster.get_Layer(), cluster.get_Sector()); - double ce = cluster.get_Centroid(); + Point3D offset = Constants.BMTGEOMETRY.getOffset(cluster.getLayer(), cluster.getSector()); + Vector3D rotation = Constants.BMTGEOMETRY.getRotation(cluster.getLayer(), cluster.getSector()); + double ce = cluster.getCentroid(); Point3D p = new Point3D(stVec.x(), stVec.y(), stVec.z()); if (BMTGeometry.getDetectorType(layer) == BMTType.C) { //C-detector measuring z - cluster.set_CentroidResidual(p); - cluster.set_SeedResidual(p); + cluster.setCentroidResidual(p); + cluster.setSeedResidual(p); for (Hit h1 : cluster) { // calculate the hit residuals - h1.set_TrkgStatus(1); - h1.set_docaToTrk(p); - h1.set_TrkgStatus(1); + h1.setTrkgStatus(1); + h1.setdocaToTrk(p); + h1.setTrkgStatus(1); if (trajFinal) { - h1.set_TrkgStatus(2); + h1.setTrkgStatus(2); } } } if (BMTGeometry.getDetectorType(layer) == BMTType.Z) { //Z-detector measuring phi - int bsector = cluster.get_Sector(); - int blayer = cluster.get_Layer(); - double cxh = Math.cos(cluster.get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); - double cyh = Math.sin(cluster.get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + int bsector = cluster.getSector(); + int blayer = cluster.getLayer(); + double cxh = Math.cos(cluster.getPhi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double cyh = Math.sin(cluster.getPhi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); double phic = Constants.BMTGEOMETRY.getPhi(blayer, bsector, new Point3D(cxh,cyh,0)); double phit = Constants.BMTGEOMETRY.getPhi(blayer, bsector, p); double doca2Cls = (phic-phit)*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); - cluster.set_CentroidResidual(doca2Cls); + cluster.setCentroidResidual(doca2Cls); for (Hit h1 : cluster) { - double xh = Math.cos(h1.get_Strip().get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); - double yh = Math.sin(h1.get_Strip().get_Phi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double xh = Math.cos(h1.getStrip().getPhi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); + double yh = Math.sin(h1.getStrip().getPhi())*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); double hphic = Constants.BMTGEOMETRY.getPhi(blayer, bsector, new Point3D(xh,yh,0)); double hphit = Constants.BMTGEOMETRY.getPhi(blayer, bsector, p); double doca1 = (hphic-hphit)*Constants.BMTGEOMETRY.getRadiusMidDrift(blayer); - if(h1.get_Strip().get_Strip()==cluster.get_SeedStrip().get_Strip()) - cluster.set_SeedResidual(doca1); + if(h1.getStrip().getStrip()==cluster.getSeedStrip().getStrip()) + cluster.setSeedResidual(doca1); - h1.set_TrkgStatus(1); + h1.setTrkgStatus(1); if (trajFinal) { - h1.set_TrkgStatus(2); + h1.setTrkgStatus(2); } } } } } - public static double[][][] calc_trackIntersBMT(Ray ray, int start_layer) { + public static double[][][] calcTrackIntersBMT(Ray ray, int start_layer) { //[l][hemisphere], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip; hemisphere = [1]top or [0]bottom double[][][] result = new double[6][2][7]; @@ -752,60 +687,11 @@ public static double[][][] calc_trackIntersBMT(Ray ray, int start_layer) { } } } -// double[][] trkIntersCombinedInf = this.getIntersectionTrackWithBMTModules(l, -// ray.get_yxinterc(), ray.get_yxslope(), ray.get_yzinterc(), ray.get_yzslope(), bmt_geo); -// -// //hemisphere 1-2 -// for (int h = 0; h < 2; h++) { -// double[] trkIntersInf = trkIntersCombinedInf[h]; -// -// if(Double.isNaN(trkIntersInf[0]) || Double.isNaN(trkIntersInf[1]) || Double.isNaN(trkIntersInf[2]) ) -// continue; -// -// Point3D p = new Point3D(trkIntersInf[0], trkIntersInf[1], trkIntersInf[2]); -// -// if (p.toVector3D().mag() == 0 ) { -// continue; -// } -// -// Vector3D n = new Vector3D(Math.cos(Math.atan2(p.y(), p.x())), Math.sin(Math.atan2(p.y(), p.x())), 0); -// Vector3D ui = new Vector3D(n.y(), -n.x(), 0); //longitudinal vector along the local x direction of the module -// -// Vector3D uj = ui.cross(n); //longitudinal vector along the local z direction of the module -// -// double norm = Math.sqrt(ray.get_yxslope() * ray.get_yxslope() + ray.get_yzslope() * ray.get_yzslope() + 1); -// -// Vector3D u = new Vector3D(ray.get_yxslope() / norm, 1 / norm, ray.get_yzslope() / norm); -// -// if (p.y() < 0) { -// u = new Vector3D(-ray.get_yxslope() / norm, -1 / norm, -ray.get_yzslope() / norm); -// } -// -// double trkToMPlnAngl = Math.acos(u.dot(ui)); -// -// double zl = u.dot(n); -// double xl = u.dot(ui); -// double yl = u.dot(uj); -// -// double phi = Math.atan2(yl, xl); -// double theta = Math.acos(zl); -// -// result[l][h][0] = p.x(); -// result[l][h][1] = p.y(); -// result[l][h][2] = p.z(); -// result[l][h][3] = Math.toDegrees(phi); -// result[l][h][4] = Math.toDegrees(theta); -// result[l][h][5] = Math.toDegrees(trkToMPlnAngl); -// result[l][h][6] = trkIntersInf[3]; -// System.out.println("Old " + xl + " " + yl + " " + zl + " " -// + result[l][h][0] + " " + result[l][h][1] + " " + result[l][h][2] + " " -// + result[l][h][3] + " " + result[l][h][4] + " " + result[l][h][5] + " " + result[l][h][6]); -// } } return result; } - public static double[][][] calc_trackIntersSVT(Ray ray) { + public static double[][][] calcTrackIntersSVT(Ray ray) { //[l][s], [0,1,2,3,4]=x,y,z,phi,theta,estimated centroid strip double[][][] result = new double[SVTGeometry.NLAYERS][SVTGeometry.NSECTORS[SVTGeometry.NLAYERS-1]][7]; for (int l = 0; l < SVTGeometry.NLAYERS; l++) { @@ -844,136 +730,6 @@ public static double[][][] calc_trackIntersSVT(Ray ray) { return result; } - - @Deprecated - public double[] getIntersectionTrackWithSVTModule(int s, int l, - double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2) { - // array [][][][] =[x][y][z][stripCentroid] - double[] inters = new double[4]; - inters[0] = Double.NaN; - inters[1] = Double.NaN; - inters[2] = Double.NaN; - inters[3] = Double.NaN; - - double y_minus = -300; - double y_plus = 350; - double x_plus = _yxslope2 * y_plus + _yxinterc2; - double x_minus = _yxslope2 * y_minus + _yxinterc2; - - double z_plus = _yzslope2 * y_plus + _yzinterc2; - double z_minus = _yzslope2 * y_minus + _yzinterc2; - - Vector3D n = Constants.SVTGEOMETRY.getNormal(l+1, s+1); - Line3D mod = Constants.SVTGEOMETRY.getModule(l+1, s+1); - Point3D Or = mod.origin(); - Point3D En = mod.end(); - - - Vector3D u = new Vector3D(x_plus-x_minus,y_plus-y_minus,z_plus-z_minus).asUnit(); - - double alpha = (En.y() - Or.y()) / - (En.x() - Or.x()); - double t = (alpha*(x_minus-Or.x()) -(y_minus-Or.y()))/(u.y() - alpha*u.x()); - - double x = x_minus+t*u.x(); - double y = y_minus+t*u.y(); - double z = z_minus+t*u.z(); - - double strp = Constants.SVTGEOMETRY.calcNearestStrip(inters[0], inters[1], inters[2], l + 1, s + 1); - - if (strp>0 && strp<257) { - inters[0] = y * _yxslope2 + _yxinterc2; - inters[1] = y; - inters[2] = y * _yzslope2 + _yzinterc2; - inters[3] = strp; - } - - return inters; - - } - - @Deprecated - private double[][] getIntersectionTrackWithBMTModules(int l, - double _yxinterc2, double _yxslope2, double _yzinterc2, - double _yzslope2) { - - // array [][][][] =[x][y][z][stripCentroid] - double[][] inters = new double[2][4]; - double[] inters_top = new double[4]; - inters_top[0] = Double.NaN; - inters_top[1] = Double.NaN; - inters_top[2] = Double.NaN; - inters_top[3] = 0; - - double[] inters_bottom = new double[4]; - inters_bottom[0] = Double.NaN; - inters_bottom[1] = Double.NaN; - inters_bottom[2] = Double.NaN; - inters_bottom[3] = Double.NaN; - inters_bottom[3]= 0; - - int lyer = l+1; - - double radius = Constants.BMTGEOMETRY.getRadiusMidDrift(lyer); - - double y_minus = -300; - double y_plus = 350; - double x_plus = _yxslope2 * y_plus + _yxinterc2; - double x_minus = _yxslope2 * y_minus + _yxinterc2; - - double z_plus = _yzslope2 * y_plus + _yzinterc2; - double z_minus = _yzslope2 * y_minus + _yzinterc2; - - Point3D trkOr = new Point3D(x_plus,y_plus,z_plus); - Point3D trkEn = new Point3D(x_minus,y_minus,z_minus); - - List intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, null, null); - Point3D top = intersNominal.get(0); - Point3D bottom = intersNominal.get(1); - - Point3D offset = null; - Vector3D rotation = null; - Point3D ioffset = null; - Vector3D irotation = null; - int topsec = 0; - int bottomsec = 0; - int topstp = 0; - int bottomstp = 0; - if(top.toVector3D().mag()>0 && Constants.BMTGEOMETRY.getSector(lyer, top.toVector3D().phi())>0) { - topsec = Constants.BMTGEOMETRY.getSector(lyer, top.toVector3D().phi()); - trkOr = Constants.BMTGEOMETRY.toLocal(trkOr, lyer, topsec); - trkEn = Constants.BMTGEOMETRY.toLocal(trkEn, lyer, topsec); - intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation); - top = intersNominal.get(0); - topstp = Constants.BMTGEOMETRY.getStrip( l + 1, topsec, top); - } - if(bottom.toVector3D().mag()>0 && Constants.BMTGEOMETRY.getSector(lyer, bottom.toVector3D().phi())>0) { - bottomsec = Constants.BMTGEOMETRY.getSector(lyer, bottom.toVector3D().phi()); - trkOr = Constants.BMTGEOMETRY.toLocal(trkOr, lyer, bottomsec); - trkEn = Constants.BMTGEOMETRY.toLocal(trkEn, lyer, bottomsec); - intersNominal = this.getIntersBMT(lyer, radius, x_minus,y_minus, z_minus, trkOr,trkEn, offset, rotation); - bottom = intersNominal.get(1); - bottomstp = Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, bottom); - } - - if(top.toVector3D().mag()>0) { - inters_top[0] = top.x(); - inters_top[1] = top.y(); - inters_top[2] = top.z(); - inters_top[3] = Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, top); - } - if(bottom.toVector3D().mag()>0) { - inters_bottom[0] = bottom.x(); - inters_bottom[1] = bottom.y(); - inters_bottom[2] = bottom.z(); - inters_bottom[3]= Constants.BMTGEOMETRY.getStrip( l + 1, bottomsec, bottom); - } - - inters[0] = inters_top; - inters[1] = inters_bottom; - return inters; - } private Hit[][][] HitArray; @@ -987,148 +743,13 @@ public void hitsToArray(List hits2) { // with valid hits for (Hit hit : hits2) { - int w = hit.get_Strip().get_Strip(); - int l = hit.get_Layer(); - int s = hit.get_Sector(); + int w = hit.getStrip().getStrip(); + int l = hit.getLayer(); + int s = hit.getSector(); HitArray[l - 1][s - 1][w - 1] = hit; } } - - - private List getTrkInMiddleOfBar(int id, double[] inters) { - List stateVecs = new ArrayList(); - - double p = Math.sqrt(inters[3]*inters[3]+inters[4]*inters[4]+inters[5]*inters[5]); - double x = inters[0]; - double y = inters[1]; - double z = inters[2]; - double ux = inters[3]/p; - double uy = inters[4]/p; - double uz = inters[5]/p; - double path = inters[6]; - - Line3d line = new Line3d(new Vector3d(x,y,z), new Vector3d(x+5*ux,y+5*uy, z+5*uz)); - - List trkHits = Constants.CTOFGEOMETRY.getIntersections(line); - if (trkHits != null && trkHits.size() > 0) { - for (DetHit hit : trkHits) { - CTOFDetHit trkHit = new CTOFDetHit(hit); - //track extrp to a line, make sure you pick up the right hit - if(Math.sqrt((trkHit.origin().x-x)*(trkHit.origin().x-x)+ - (trkHit.origin().y-y)*(trkHit.origin().y-y))>3.5*2) //thickness*2 - continue; - int component = trkHit.getPaddle(); - // get the coordinates for the track hit, which is defined - // as the mid-point between its entrance and its exit from - // the bar - path+=trkHit.origin().distance(trkHit.end()); - new Point3D(trkHit.mid().x,trkHit.mid().y, trkHit.mid().z); - Vector3d dir = trkHit.end().minus(trkHit.origin()).normalized(); - - StateVec stVec = new StateVec(trkHit.mid().x*10, trkHit.mid().y*10, trkHit.mid().z*10, - dir.x*p, dir.y*p, dir.z*p); - stVec.set_SurfaceDetector(DetectorType.CTOF.getDetectorId()); - stVec.set_SurfaceSector(1); - stVec.set_SurfaceLayer(1); - stVec.set_ID(id); - stVec.set_SurfaceComponent(component); - stVec.set_CalcCentroidStrip(component); - stVec.set_TrkPhiAtSurface(Math.atan2(dir.y, dir.x)); - stVec.set_TrkThetaAtSurface(Math.acos(dir.z)); - stVec.set_TrkToModuleAngle(0); - stVec.set_Path(path*10); - stateVecs.add(stVec); - - } - } - return stateVecs; - } - - private boolean checkBMTAcceptance(Point3D ipos, int lyer) { - //1 mm tolerance - if(ipos.z()Constants.BMTGEOMETRY.getZmin(lyer)+1.0 ) { - return true; - } else { - return false; - } - } - - @Deprecated - private List getIntersBMT(int lyer, double radius, double x_minus, double y_minus, double z_minus, - Point3D trkOr, Point3D trkEn, Point3D offset, Vector3D rotation) { - - List result = new ArrayList(); - Line3D trk = new Line3D(trkOr, trkEn); - Point3D top = new Point3D(0,0,0); - Point3D bottom = new Point3D(0,0,0); - - double X = x_minus; - double Y = y_minus; - double Vx = trk.direction().asUnit().x(); - double Vy = trk.direction().asUnit().y(); - double Vz = trk.direction().asUnit().z(); - - double Delta = (Vx*X+Vy*Y)*(Vx*X+Vy*Y) - (X*X+Y*Y-radius*radius)*(Vx*Vx+Vy*Vy); - if(Delta<0) { - result.add(top); - result.add(bottom); - return result; - } - double tpos = (-(Vx*X+Vy*Y) + Math.sqrt(Delta))/(Vx*Vx+Vy*Vy); - double tneg = (-(Vx*X+Vy*Y) - Math.sqrt(Delta))/(Vx*Vx+Vy*Vy); - - Point3D ipos = new Point3D(x_minus+tneg*Vx,y_minus+tneg*Vy,z_minus+tneg*Vz); - Point3D ineg = new Point3D(x_minus+tpos*Vx,y_minus+tpos*Vy,z_minus+tpos*Vz); - - if(this.checkBMTAcceptance(ipos, lyer)) { - if(offset!=null && rotation!=null) - Constants.BMTGEOMETRY.putInFrame(ipos, offset, rotation, false); - } else { - ipos.set(0,0,0); - } - if(this.checkBMTAcceptance(ineg, lyer)) { - - if(offset!=null && rotation!=null) - Constants.BMTGEOMETRY.putInFrame(ineg, offset, rotation, false); - } else { - ineg.set(0,0,0); - } - - if(ipos.toVector3D().mag()>0 && ineg.toVector3D().mag()>0) { - if(ipos.y()0 && ineg.toVector3D().mag()==0) { - if(ipos.y()<0) { - bottom.set(ipos.x(), ipos.y(), ipos.z()); - } else { - top.set(ipos.x(), ipos.y(), ipos.z()); - } - } - if(ipos.toVector3D().mag()==0 && ineg.toVector3D().mag()>0) { - if(ineg.y()>0) { - top.set(ineg.x(), ineg.y(), ineg.z()); - } else { - bottom.set(ineg.x(), ineg.y(), ineg.z()); - } - } - } - result.add(top); - result.add(bottom); - return result; - } - } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/package-info.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/package-info.java deleted file mode 100644 index 9e7fb18f3..000000000 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/trajectory/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author ziegler - * - */ -package org.jlab.rec.cvt.trajectory; From a0977ac93a190f480e679e3b90693eb488ad7467 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Wed, 19 Jan 2022 11:19:35 -0500 Subject: [PATCH 274/291] fixed things that broke in the merge --- .../jlab/rec/cvt/banks/RecoBankReader.java | 116 +++++++-------- .../jlab/rec/cvt/services/CVTAlignment.java | 134 +++++++++--------- 2 files changed, 126 insertions(+), 124 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index e34eac45e..4336e46ba 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -55,20 +55,20 @@ public void fetch_SVTCrosses(DataEvent event, double zShift) { int sector = bank.getByte("sector", j); int id = bank.getShort("ID",j); Cross cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, sector, region, j); - cross.set_Id(id); - cross.set_Point(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); - cross.set_PointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); - cross.set_AssociatedTrackID(bank.getShort("trkID",j)); - cross.set_Dir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); + cross.setId(id); + cross.setPoint(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); + cross.setPointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); + cross.setAssociatedTrackID(bank.getShort("trkID",j)); + cross.setDir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); int cluster1id = bank.getShort("Cluster1_ID", j); for (Cluster cluster: _SVTclusters) - if (cluster.get_Id() == cluster1id) - cross.set_Cluster1(cluster); + if (cluster.getId() == cluster1id) + cross.setCluster1(cluster); int cluster2id = bank.getShort("Cluster2_ID", j); for (Cluster cluster: _SVTclusters) - if (cluster.get_Id() == cluster2id) - cross.set_Cluster2(cluster); + if (cluster.getId() == cluster2id) + cross.setCluster2(cluster); _SVTcrosses.add(cross); } @@ -95,22 +95,22 @@ public void fetch_BMTCrosses(DataEvent event, double zShift) { int sector = bank.getByte("sector", j); int id = bank.getShort("ID",j); Cross cross = new Cross(DetectorType.BMT, BMTType.UNDEFINED, sector, region, id); - cross.set_Point(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); - cross.set_PointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); - cross.set_AssociatedTrackID(bank.getShort("trkID",j)); - cross.set_Dir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); + cross.setPoint(new Point3D(10.*bank.getFloat("x", j), 10.*bank.getFloat("y", j),10.*(bank.getFloat("z", j)-zShift))); + cross.setPointErr(new Point3D(10.*bank.getFloat("err_x", j), 10.*bank.getFloat("err_y", j),10.*bank.getFloat("err_z", j))); + cross.setAssociatedTrackID(bank.getShort("trkID",j)); + cross.setDir(new Vector3D(bank.getFloat("ux", j),bank.getFloat("uy", j),bank.getFloat("uz", j))); int cluster1id = bank.getShort("Cluster1_ID", j); for (Cluster cluster: _BMTclusters) { - if (cluster.get_Id() == cluster1id) { - cross.set_Cluster1(cluster); - cross.set_Type(BMTGeometry.getDetectorType(cluster.get_Layer())); + if (cluster.getId() == cluster1id) { + cross.setCluster1(cluster); + cross.setType(BMTGeometry.getDetectorType(cluster.getLayer())); } } //int cluster2id = bank.getShort("Cluster2_ID", j); //for (Cluster cluster: _clusters) - // if (cluster.get_Id() == cluster2id) - // cross.set_Cluster2(cluster); + // if (cluster.getId() == cluster2id) + // cross.setCluster2(cluster); _BMTcrosses.add(cross); } @@ -132,15 +132,15 @@ public void fetch_BMTClusters(DataEvent event) { Cluster cluster = new Cluster(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, id); int size = bank.getInt("size", i); - cluster.set_TotalEnergy(bank.getFloat("ETot", i)); + cluster.setTotalEnergy(bank.getFloat("ETot", i)); - //cluster.set_Seed(bank.getInt("seedStrip", i)); - cluster.set_Centroid(bank.getFloat("centroid",i)); - //cluster.set_SeedEnergy(bank.getFloat("seedE",i)); - //cluster.set_SeedEnergy(bank.getFloat("seedE",i)); - cluster.set_CentroidResidual(bank.getFloat("centroidResidual",i)); - cluster.set_SeedResidual(bank.getFloat("seedResidual",i)); - cluster.set_AssociatedTrackID(bank.getShort("trkID",i)); + //cluster.setSeed(bank.getInt("seedStrip", i)); + cluster.setCentroid(bank.getFloat("centroid",i)); + //cluster.setSeedEnergy(bank.getFloat("seedE",i)); + //cluster.setSeedEnergy(bank.getFloat("seedE",i)); + cluster.setCentroidResidual(bank.getFloat("centroidResidual",i)); + cluster.setSeedResidual(bank.getFloat("seedResidual",i)); + cluster.setAssociatedTrackID(bank.getShort("trkID",i)); cluster.setLine(new Line3D( bank.getFloat("x1", i), bank.getFloat("y1", i), @@ -161,7 +161,7 @@ public void fetch_BMTClusters(DataEvent event) { bank.getFloat("lx", i), bank.getFloat("ly", i), bank.getFloat("lz", i))); - cluster.set_Resolution(bank.getFloat("e", i)); + cluster.setResolution(bank.getFloat("e", i)); Point3D x1 = new Point3D( @@ -188,12 +188,12 @@ public void fetch_BMTClusters(DataEvent event) { Vector3D a = a1.vectorTo(a2).asUnit(); Point3D arccenter = a1.toVector3D().add(a.multiply(a.dot(a1.vectorTo(x1)))).toPoint3D(); - cluster.set_Arc(new Arc3D( + cluster.setArc(new Arc3D( x1, arccenter, a, bank.getFloat("theta", i) )); - cluster.set_Type(BMTGeometry.getDetectorType(layer)); + cluster.setType(BMTGeometry.getDetectorType(layer)); //Since only up to 5 hits per track are written... for (int j = 0; j < 5; j++) { @@ -204,7 +204,7 @@ public void fetch_BMTClusters(DataEvent event) { continue; int hitId = bank.getShort(hitStrg, i); for(Hit hit : _BMThits) { - if (hit.get_Id() == hitId) { + if (hit.getId() == hitId) { cluster.add(hit); } } @@ -251,9 +251,9 @@ public void fetch_Cosmics(DataEvent event, double zShift) { Point3D point = new Point3D(10.*yx_intercs[i], 0, 10.*(yz_intercs[i]-zShift)); Ray ray = new Ray(point, u); StraightTrack track = new StraightTrack(ray); - track.set_Id(ids[i]); - track.set_chi2(chi2s[i]); - track.set_ndf(ndfs[i]); + track.setId(ids[i]); + track.setchi2(chi2s[i]); + track.setndf(ndfs[i]); loopCrossId: for (int j = 0; j < 18; j++) { @@ -265,14 +265,14 @@ public void fetch_Cosmics(DataEvent event, double zShift) { continue; int crossid = bank.getShort(hitStrg, i); for(Cross cross : _SVTcrosses) { - if(cross.get_Id() == crossid) { + if(cross.getId() == crossid) { track.add(cross); continue loopCrossId; } } for(Cross cross : _BMTcrosses) { - if(cross.get_Id() == crossid) { + if(cross.getId() == crossid) { track.add(cross); continue loopCrossId; } @@ -342,7 +342,7 @@ public void fetch_Tracks(DataEvent event, double zShift) { for(int i = 0; i12) { System.out.println("Too many BMT crosses!"); @@ -249,18 +249,18 @@ public boolean processDataEvent(DataEvent event) { //int nCross = nCrossSVT + nCrossBMT; //if(nCross <= 2) // continue; - Ray ray = track.get_ray(); + Ray ray = track.getRay(); if(ray == null) { - ray = getRay(track.get_helix(),reader.getXbeam(),reader.getYbeam()); - //System.out.println("curvature " + track.get_helix().get_curvature()); - //System.out.println("doca " + track.get_helix().get_dca()); - if(Math.abs(track.get_helix().get_curvature())>0.001) { + ray = getRay(track.getHelix()); + //System.out.println("curvature " + track.getHelix().get_curvature()); + //System.out.println("doca " + track.getHelix().get_dca()); + if(Math.abs(track.getHelix().getCurvature())>0.001) { continue; } } //getRay(track); - //System.out.println(ray.get_dirVec().toString()); - //System.out.println(ray.get_refPoint().toString()); + //System.out.println(ray.getDirVec().toString()); + //System.out.println(ray.getRefPoint().toString()); int paramsFromBeamspot = (isCosmics || ! includeBeamspot ? 0:1); @@ -273,14 +273,14 @@ public boolean processDataEvent(DataEvent event) { Matrix c = new Matrix(rows,1); Matrix I = new Matrix(rows,1); Matrix q = new Matrix(4, 1); //track parameters, for plotting kinematic dependence. Not used in KFA. - if (track.get_helix() == null) { - track.set_helix(createHelixFromRay(track.get_ray())); + if (track.getHelix() == null) { + track.setHelix(createHelixFromRay(track.getRay())); } - q.set(0, 0, track.get_helix().get_dca()); - q.set(1, 0, track.get_helix().get_phi_at_dca()); - q.set(2, 0, track.get_helix().get_Z0()); - q.set(3, 0, track.get_helix().get_tandip()); + q.set(0, 0, track.getHelix().getDCA()); + q.set(1, 0, track.getHelix().getPhiAtDCA()); + q.set(2, 0, track.getHelix().getZ0()); + q.set(3, 0, track.getHelix().getTanDip()); if(debug) { System.out.println("track parameters"); @@ -291,15 +291,15 @@ public boolean processDataEvent(DataEvent event) { boolean useNewFillMatrices = true; for(Cross cross : track) { if(useNewFillMatrices) { - if(cross.get_Detector() == DetectorType.BST){ - Cluster cl1 = cross.get_Cluster1(); + if(cross.getDetector() == DetectorType.BST){ + Cluster cl1 = cross.getCluster1(); boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,debug,false); i++; if(!ok) { //reject track if there's a cluster with really bad values. if(debug) System.out.println("rejecting track due to problem in an SVT layer"); continue tracksLoop; } - Cluster cl2 = cross.get_Cluster2(); + Cluster cl2 = cross.getCluster2(); ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,debug,false); i++; if(!ok) { //reject track if there's a cluster with really bad values. @@ -307,14 +307,14 @@ public boolean processDataEvent(DataEvent event) { continue tracksLoop; } } else { - Cluster cl1 = cross.get_Cluster1(); + Cluster cl1 = cross.getCluster1(); boolean ok = true; - if(cl1.get_Type() == BMTType.Z || !skipBMTC){ + if(cl1.getType() == BMTType.Z || !skipBMTC){ ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, this.debug, false); } i++; if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.get_Type().name() + " layer"); + if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); continue tracksLoop; } //} @@ -376,12 +376,12 @@ else if(cross.get_DetectorType() == BMTType.C) { Cluster cl1 = new Cluster(null, null, 0, 0, 0); cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); - Vector3D n = ray.get_dirVec(); + Vector3D n = ray.getDirVec(); Vector3D l = new Vector3D(0,0,1); cl1.setN(n); cl1.setL(l); cl1.setS(n.cross(l)); - cl1.set_Resolution(0.6); + cl1.setResolution(0.6); fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); @@ -400,7 +400,7 @@ else if(cross.get_DetectorType() == BMTType.C) { //c.print(7, 4); //m.print(7, 4); - trackIDs.add(track.get_Id()); + trackIDs.add(track.getId()); } AlignmentBankWriter writer = new AlignmentBankWriter(); writer.write_Matrix(event, "I", Is); @@ -420,8 +420,8 @@ else if(cross.get_DetectorType() == BMTType.C) { } private Helix createHelixFromRay(Ray ray) { - Vector3D u = ray.get_dirVec(); - Vector3D xref = ray.get_refPoint().toVector3D(); + Vector3D u = ray.getDirVec(); + Vector3D xref = ray.getRefPoint().toVector3D(); double phi = Math.atan2(u.y(),u.x()); Vector3D uT = new Vector3D(Math.cos(phi), Math.sin(phi),0); Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); @@ -435,14 +435,16 @@ private Helix createHelixFromRay(Ray ray) { int nAlignables; - private Ray getRay(Helix h,double xb, double yb) { + private Ray getRay(Helix h) { - double d = h.get_dca(); - double z = h.get_Z0(); - double phi = h.get_phi_at_dca(); - double td = h.get_tandip(); + double d = h.getDCA(); + double z = h.getZ0(); + double phi = h.getPhiAtDCA(); + double td = h.getTanDip(); double cd = 1/Math.hypot(td, 1); double sd = td*cd; + double xb = h.getXb(); + double yb = h.getYb(); //Vector3D u = new Vector3D(-cd*Math.sin(phi), cd*Math.cos(phi), sd); //Point3D x = new Point3D(d*Math.cos(phi),d*Math.sin(phi), z); Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); @@ -467,11 +469,11 @@ private Ray getRay(Helix h,double xb, double yb) { private double getDoca(Trajectory track) { if(track instanceof StraightTrack) { - Ray ray = track.get_ray(); - double intercept = ray.get_yxinterc(); - double slope = ray.get_yxslope(); + Ray ray = track.getRay(); + double intercept = ray.getYXInterc(); + double slope = ray.getYXSlope(); return Math.abs(intercept)/Math.hypot(1, slope); - } else return track.get_helix().get_dca(); + } else return track.getHelix().getDCA(); } private void fillMisc(DataEvent event, int runNum, int eventNum, List trackIDs, @@ -521,9 +523,9 @@ private void fillMisc(DataEvent event, int runNum, int eventNum, List t private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I, double xb, double yb){ // a point along the beam - Vector3D xref = ray.get_refPoint().toVector3D(); + Vector3D xref = ray.getRefPoint().toVector3D(); //System.out.println("xref: " + xref.toStlString()); - Vector3D u = ray.get_dirVec(); + Vector3D u = ray.getDirVec(); Vector3D e = new Vector3D(xb,yb,0); Vector3D l = new Vector3D(0,0,1); @@ -655,23 +657,23 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix */ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I, boolean debug, boolean isBeamspot) { - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); + int layer = cl.getLayer(); + int sector = cl.getSector(); //System.out.println("RLS " + region + " " + layer + " " + sector); - //System.out.println("th" + c.get_Phi()); + //System.out.println("th" + c.getPhi()); Vector3D l; Vector3D s; Vector3D n; /*if(detector == DetectorType.BMT && bmtType==BMTType.C) { - Vector3D u = ray.get_dirVec(); + Vector3D u = ray.getdirVec(); double phi = Math.atan2(u.y(),u.x()); - System.out.println("prelim phi is " + phi + " sector= ="+cl.get_Sector()); + System.out.println("prelim phi is " + phi + " sector= ="+cl.getSector()); }*/ - DetectorType detector = cl.get_Detector(); - BMTType bmtType = cl.get_Type(); + DetectorType detector = cl.getDetector(); + BMTType bmtType = cl.getType(); if(debug) { System.out.println("\n\nNew method " + detector + " layer " + layer + " sector " + sector); @@ -681,8 +683,8 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, - Vector3D xref = ray.get_refPoint().toVector3D(); - Vector3D u = ray.get_dirVec(); + Vector3D xref = ray.getRefPoint().toVector3D(); + Vector3D u = ray.getDirVec(); @@ -711,16 +713,16 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, extrap= xref.clone().add(u.multiply(n.dot(e.clone().sub(xref))/udotn)); } else { // BMTC - Vector3D a = cl.get_Arc().normal(); + Vector3D a = cl.getArc().normal(); if(debug) System.out.println("a: " +a); - Vector3D cc = cl.get_Arc().center().toVector3D(); + Vector3D cc = cl.getArc().center().toVector3D(); Vector3D uT = perp(u,a); Vector3D tmp1 = perp(xref.clone().sub(cc),a); - Vector3D endpoint = cl.get_Arc().origin().toVector3D(); + Vector3D endpoint = cl.getArc().origin().toVector3D(); double R = perp(endpoint.clone().sub(cc),a).mag(); if(debug) { @@ -856,7 +858,7 @@ private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, //System.out.println(extrap.toStlString()); - double resolution = cl.get_Resolution(); + double resolution = cl.getResolution(); //System.out.println("resolution: " + resolution + "; z=" + extrap.z-); V.set(i, i, Math.pow(resolution,2)); @@ -961,7 +963,7 @@ Vector3D perp(Vector3D v, Vector3D a) { /* //returns false if there's a problem private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { - int region = cl.get_Region(); + int region = cl.getRegion(); int layer = cl.get_Layer(); int sector = cl.get_Sector(); //System.out.println("RLS " + region + " " + layer + " " + sector); @@ -991,8 +993,8 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Vector3d s = e2.minus(e1); s = s.minus(l.times(s.dot(l))).normalized(); - Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); - Vector3d u = convertVector(ray.get_dirVec()); + Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); + Vector3d u = convertVector(ray.getDirVec()); Vector3d n = l.cross(s); double udotn = u.dot(n); if(Math.abs(udotn)<0.01) { @@ -1004,7 +1006,7 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, //System.out.println(extrap.toStlString()); - double resolution = cl.get_ResolutionAlongZ(extrap.z-SVTConstants.Z0ACTIVE[(layer-1)/2], SVTGeom); + double resolution = cl.getResolutionAlongZ(extrap.z-SVTConstants.Z0ACTIVE[(layer-1)/2], SVTGeom); //System.out.println("resolution: " + resolution + "; z=" + extrap.z-); V.set(i, i, Math.pow(resolution,2)); @@ -1107,7 +1109,7 @@ private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, /* private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { - int region = cl.get_Region(); + int region = cl.getRegion(); int layer = cl.get_Layer(); int sector = cl.get_Sector(); double centroid = cl.get_Centroid(); @@ -1128,8 +1130,8 @@ private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, s = s.minus(l.times(s.dot(l))).normalized(); - Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); - Vector3d u = convertVector(ray.get_dirVec()); + Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); + Vector3d u = convertVector(ray.getDirVec()); Vector3d n = l.cross(s); double udotn = u.dot(n); if(Math.abs(udotn)<0.01) @@ -1241,7 +1243,7 @@ private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix I) { System.out.println("\nOld method BMTC"); - int region = cl.get_Region(); + int region = cl.getRegion(); int layer = cl.get_Layer(); int sector = cl.get_Sector(); //System.out.println(region+" "+layer +" "+sector); @@ -1249,8 +1251,8 @@ private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]) centroid = org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]-.001; - Vector3d xref = convertVector(ray.get_refPoint().toVector3D()); - Vector3d u = convertVector(ray.get_dirVec()); + Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); + Vector3d u = convertVector(ray.getDirVec()); Arc3D arc1 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-1); Arc3D arc2 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-0); From 9e1f7dad20fa4fc160d81c27ef072d4db7e05929 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Wed, 19 Jan 2022 17:58:17 -0500 Subject: [PATCH 275/291] fixed issue with RecoBankReader (units for xb and yb) --- .../src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 4336e46ba..58f5bb04b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -341,7 +341,7 @@ public void fetch_Tracks(DataEvent event, double zShift) { for(int i = 0; i Date: Thu, 20 Jan 2022 17:20:53 +0100 Subject: [PATCH 276/291] Changed default setting to include beam-spot cnstraint on seeding only and 5 KF iterations --- .../cvt/src/main/java/org/jlab/rec/cvt/Constants.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java index 933628224..b1cf3570a 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Constants.java @@ -55,11 +55,11 @@ public class Constants { public static boolean KFFILTERON = true; public static boolean INITFROMMC = false; - public static int KFITERATIONS = 1; + public static int KFITERATIONS = 5; public static final boolean TRACKSFROMORIGIN = true; - private static int BEAMSPOTCONST = 0; + private static int BEAMSPOTCONST = 1; public static Libr KFMATLIB; From 498c432ddc5439ea09d20ea7dd697c49acf94b8f Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Wed, 2 Feb 2022 16:21:58 -0800 Subject: [PATCH 277/291] removed line to set p=1 for straight tracks --- .../org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index c8f71ecdd..7166451f1 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -234,7 +234,7 @@ public double[][] Q(int i, int f, StateVec iVec, AMeasVecs mv) { if (t_ov_X0>0) { double p = Math.sqrt(iVec.px*iVec.px + iVec.py*iVec.py + iVec.pz*iVec.pz); - if(this.straight) p = 1; + //if(this.straight) p = 1; double mass = piMass; // assume given mass hypothesis double beta = p / Math.sqrt(p * p + mass * mass); // Highland-Lynch-Dahl formula From c3c6593b6c48696a625aeee964f69db7c5c766a3 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 28 Mar 2022 10:53:35 -0400 Subject: [PATCH 278/291] added functionality to do get residuals from curved tracks in alignment. (using curved tracks in alignment still is not functional yet.) --- .../jlab/rec/cvt/services/CVTAlignment.java | 205 ++++++++++-------- 1 file changed, 119 insertions(+), 86 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 997dc4bb7..3f308a508 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -289,105 +289,119 @@ public boolean processDataEvent(DataEvent event) { int i = 0; boolean useNewFillMatrices = true; - for(Cross cross : track) { - if(useNewFillMatrices) { - if(cross.getDetector() == DetectorType.BST){ - Cluster cl1 = cross.getCluster1(); - boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - Cluster cl2 = cross.getCluster2(); - ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - } else { - Cluster cl1 = cross.getCluster1(); - boolean ok = true; - if(cl1.getType() == BMTType.Z || !skipBMTC){ - ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, this.debug, false); - } - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); - continue tracksLoop; + if(!curvedTracks) { + for(Cross cross : track) { + if(useNewFillMatrices) { + if(cross.getDetector() == DetectorType.BST){ + Cluster cl1 = cross.getCluster1(); + boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,debug,false); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + Cluster cl2 = cross.getCluster2(); + ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,debug,false); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + } else { + Cluster cl1 = cross.getCluster1(); + boolean ok = true; + if(cl1.getType() == BMTType.Z || !skipBMTC){ + ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, this.debug, false); + } + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); + continue tracksLoop; + } + //} } - //} + continue; } - continue; + + } - /*else { - //System.out.println("cross " +cross.get_Point()); - if(cross.get_Detector()== DetectorType.BST) - { - if(isBMTonly) - continue; - Cluster cl1 = cross.get_Cluster1(); - boolean ok = fillMatricesSVT(i,ray,cl1,A,B,V,m,c,I); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - Cluster cl2 = cross.get_Cluster2(); - ok = fillMatricesSVT(i,ray,cl2,A,B,V,m,c,I); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - } else { - if(isSVTonly) - continue; - Cluster cl = cross.get_Cluster1(); - - - if(cross.get_DetectorType() == BMTType.Z) { - boolean ok = fillMatricesBMTZ(i,ray,cl,A,B,V,m,c,I); + if(!isCosmics && includeBeamspot) { + //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); + + + //pseudo cluster for the beamspot + Cluster cl1 = new Cluster(null, null, 0, 0, 0); + cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); + + Vector3D n = ray.getDirVec(); + Vector3D l = new Vector3D(0,0,1); + cl1.setN(n); + cl1.setL(l); + cl1.setS(n.cross(l)); + cl1.setResolution(0.6); + + fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); + + + } + } else { + Helix helix = track.getHelix(); + //curved tracks + for(Cross cross : track) { + if(useNewFillMatrices) { + if(cross.getDetector() == DetectorType.BST){ + Cluster cl1 = cross.getCluster1(); + boolean ok = fillMatricesNew(i,helix,cl1,A,B,V,m,c,I,debug,false); i++; if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT Z layer"); + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); continue tracksLoop; } - } - else if(cross.get_DetectorType() == BMTType.C) { - boolean ok = fillMatricesBMTC(i,ray,cl,A,B,V,m,c,I); + Cluster cl2 = cross.getCluster2(); + ok = fillMatricesNew(i,helix,cl2,A,B,V,m,c,I,debug,false); + i++; + if(!ok) { //reject track if there's a cluster with really bad values. + if(debug) System.out.println("rejecting track due to problem in an SVT layer"); + continue tracksLoop; + } + } else { + Cluster cl1 = cross.getCluster1(); + boolean ok = true; + if(cl1.getType() == BMTType.Z || !skipBMTC){ + ok = fillMatricesNew(i,helix,cl1,A,B,V,m,c,I, this.debug, false); + } i++; if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT C layer"); + if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); continue tracksLoop; } + //} } - + continue; } - }*/ - - } - if(!isCosmics && includeBeamspot) { - //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); - - - //pseudo cluster for the beamspot - Cluster cl1 = new Cluster(null, null, 0, 0, 0); - cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); - - Vector3D n = ray.getDirVec(); - Vector3D l = new Vector3D(0,0,1); - cl1.setN(n); - cl1.setL(l); - cl1.setS(n.cross(l)); - cl1.setResolution(0.6); - - fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); - - + + + } + if(!isCosmics && includeBeamspot) { + //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); + + + //pseudo cluster for the beamspot + Cluster cl1 = new Cluster(null, null, 0, 0, 0); + cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); + + Vector3D n = ray.getDirVec(); + Vector3D l = new Vector3D(0,0,1); + cl1.setN(n); + cl1.setL(l); + cl1.setS(n.cross(l)); + cl1.setResolution(0.6); + + fillMatricesNew(i, helix, cl1, A,B,V,m,c,I, this.debug, true); + + + } } - As.add(A); Bs.add(B); Vs.add(V); @@ -641,6 +655,16 @@ private boolean fillMatricesBeamspot(int i, Ray ray, Matrix A, Matrix B, Matrix return true; } + + private boolean fillMatricesNew(int i, Helix helix, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, + Matrix c, Matrix I, boolean debug, boolean isBeamspot) { + Vector3D u= helix.getTrackDirectionAtRadius(cl.getRadius()); + Point3D xref = helix.getPointAtRadius(cl.getRadius()); + Ray ray = new Ray(xref, u); + return fillMatricesNew(i, ray, cl, A, B, V, m, + c, I, debug, isBeamspot); + } + /** * generic method that uses any type of cluster. * @param i @@ -1662,6 +1686,15 @@ public boolean init() { System.out.println("["+this.getName()+"] debug false; config chosen based on yaml"); this.debug = false; } + + String curvedTracks=this.getEngineConfigString("curvedTracks"); + if (curvedTracks!=null) { + System.out.println("["+this.getName()+"] curvedTracks "+curvedTracks+" config chosen based on yaml"); + this.curvedTracks = Boolean.parseBoolean(curvedTracks); + } else { + System.out.println("["+this.getName()+"] curvedTracks false; config chosen based on yaml"); + this.curvedTracks = false; + } //MagneticFields.getInstance().getSolenoid().setScaleFactor(1e-7); return true; @@ -1736,6 +1769,6 @@ private void setAlignVars(String alignVars) { private int orderRz; private String variationName; - + private boolean curvedTracks = false; } From 41216be0f48c2470f1d440a6ab6824c2810c04d2 Mon Sep 17 00:00:00 2001 From: Sebouh Paul Date: Mon, 28 Mar 2022 12:48:33 -0400 Subject: [PATCH 279/291] fixed a bug in the previous commit --- .../src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java index 3f308a508..d72fe6548 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTAlignment.java @@ -254,7 +254,7 @@ public boolean processDataEvent(DataEvent event) { ray = getRay(track.getHelix()); //System.out.println("curvature " + track.getHelix().get_curvature()); //System.out.println("doca " + track.getHelix().get_dca()); - if(Math.abs(track.getHelix().getCurvature())>0.001) { + if(Math.abs(track.getHelix().getCurvature())>0.001 && !curvedTracks) { continue; } } From a22f4d952aa74e3c275db91c8343dc1d4c78ac4e Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 6 Aug 2022 17:33:03 +0200 Subject: [PATCH 280/291] merged development into dev-align3, switched cvt alignment service to use existing RecoBankReader class, fixed issues with line-cylinder intersection in straight track KF transport --- .../clas/tracking/kalmanfilter/AKFitter.java | 7 ++ .../kalmanfilter/helical/KFitter.java | 3 +- .../kalmanfilter/helical/StateVecs.java | 15 ++- .../cvt/alignment/AlignmentBankReader.java | 119 +++++++++++++++--- .../jlab/rec/cvt/alignment/CVTAlignment.java | 95 ++------------ .../jlab/rec/cvt/banks/RecoBankReader.java | 40 +++++- .../rec/cvt/services/TracksFromTargetRec.java | 5 +- .../java/org/jlab/rec/cvt/track/Track.java | 6 +- 8 files changed, 176 insertions(+), 114 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java index 35939db47..b83b1c1eb 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/AKFitter.java @@ -322,6 +322,13 @@ public HitOnTrack(int layer, int sector, StateVec sv, double tRes, double fRes, this.filteredResidual = fRes; this.smoothedResidual = sRes; } + + @Override + public String toString() { + String str = String.format("HitOnTrack layer=%d sector=%d x=%.3f y=%.3f z=%.3f px=%.3f py=%.3f pz=%.3f residual=%.3f", + this.layer, this.sector, this.x, this.y, this.z, this.px, this.py, this.pz, this.residual); + return str; + } } public void printConfig() { diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java index c62ff884e..c5b27a939 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/KFitter.java @@ -139,7 +139,8 @@ public void runFitter(AStateVecs sv, AMeasVecs mv) { if(Double.isNaN(newchisq) || sv.smoothed().get(0)==null || sv.smoothed().get(0).kappa==0 || - Double.isNaN(sv.smoothed().get(0).kappa)) { + Double.isNaN(sv.smoothed().get(0).kappa) || + Double.isNaN(sv.smoothed().get(0).dz)) { this.setFitFailed = true; break; } diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 8eaf266b5..ae812ba39 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -41,7 +41,7 @@ public boolean getStateVecPosAtMeasSite(StateVec sv, AMeasVecs.MeasVec mv, Swim if(this.straight) { Point3D st = new Point3D(sv.x, sv.y, sv.z); - Vector3D stu = new Vector3D(sv.px,sv.py,sv.pz).asUnit(); + Vector3D stu = new Vector3D(sv.px*dir,sv.py*dir,sv.pz*dir).asUnit(); if(mv.surface.plane!=null) { Line3D toPln = new Line3D(st, stu); @@ -57,11 +57,16 @@ else if(mv.surface.cylinder!=null) { mv.surface.toLocal().apply(stu); double r = mv.surface.cylinder.baseArc().radius(); double delta = Math.sqrt((st.x()*stu.x()+st.y()*stu.y())*(st.x()*stu.x()+st.y()*stu.y())-(-r*r+st.x()*st.x()+st.y()*st.y())*(stu.x()*stu.x()+stu.y()*stu.y())); - double l = (-(st.x()*stu.x()+st.y()*stu.y())+delta)/(stu.x()*stu.x()+stu.y()*stu.y()); - if(Math.signum(st.y()+l*stu.y())!=mv.hemisphere) { - l = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); - } + double l1 = (-(st.x()*stu.x()+st.y()*stu.y())+delta)/(stu.x()*stu.x()+stu.y()*stu.y()); + double l2 = (-(st.x()*stu.x()+st.y()*stu.y())-delta)/(stu.x()*stu.x()+stu.y()*stu.y()); +// if(Math.signum(st.y()+l*stu.y())!=mv.hemisphere) { + double l = l1; + if(l1>0 && l2<0) l = l1; + else if(l1<0 && l2>0) l = l2; + else if(l1>0 && l2>0) l = l1 < l2 ? l1 : l2; + else return false; Point3D inters = new Point3D(st.x()+l*stu.x(),st.y()+l*stu.y(),st.z()+l*stu.z()); + if(l<0) System.out.println("arghhhhhhhhhh "+ mv.layer + " " + mv.surface.getSector() + " " + st.toString() + " " + stu.toString() + " " + inters.toString()); mv.surface.toGlobal().apply(inters); // RDV: should switch to use clas-geometry intersection method, not done now to alwys return a value sv.x = inters.x(); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index 335448795..bb706aa40 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -1,6 +1,7 @@ package org.jlab.rec.cvt.alignment; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.jlab.detector.base.DetectorType; @@ -10,12 +11,14 @@ import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.cvt.banks.RecoBankReader; import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; +import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.trajectory.Helix; @@ -36,14 +39,14 @@ public void fetch_SVTCrosses(DataEvent event, double zShift) { fetch_SVTClusters(event); } - if (event.hasBank("BSTRec::Crosses") == false) { + if (event.hasBank("BST::Crosses") == false) { //System.err.println("there is no BST bank "); _SVTcrosses = new ArrayList<>(); return; } _SVTcrosses = new ArrayList<>(); - DataBank bank = event.getBank("BSTRec::Crosses"); + DataBank bank = event.getBank("BST::Crosses"); for (int j = 0; j < bank.rows(); j++) { int region = bank.getByte("region", j); @@ -79,14 +82,14 @@ public void fetch_BMTCrosses(DataEvent event, double zShift) { fetch_BMTClusters(event); } - if (event.hasBank("BMTRec::Crosses") == false) { + if (event.hasBank("BMT::Crosses") == false) { //System.err.println("there is no BST bank "); _BMTcrosses = new ArrayList(); return; } _BMTcrosses = new ArrayList(); - DataBank bank = event.getBank("BMTRec::Crosses"); + DataBank bank = event.getBank("BMT::Crosses"); for (int j = 0; j < bank.rows(); j++) { int region = bank.getByte("region", j); @@ -116,11 +119,11 @@ public void fetch_BMTCrosses(DataEvent event, double zShift) { } public void fetch_BMTClusters(DataEvent event) { - _BMTclusters = new ArrayList(); + _BMTclusters = new ArrayList<>(); if (_BMThits == null) { this.fetch_BMTHits(event); } - DataBank bank = event.getBank("BMTRec::Clusters"); + DataBank bank = event.getBank("BMT::Clusters"); for (int i = 0; i < bank.rows(); i++) { @@ -288,6 +291,96 @@ public void fetch_Cosmics(DataEvent event, double zShift) { ArrayList _tracks; + public List getCosmics(DataEvent event) { + + + _SVTclusters = RecoBankReader.readBSTClusterBank(event); + _BMTclusters = RecoBankReader.readBMTClusterBank(event); + + + _SVTcrosses = RecoBankReader.readBSTCrossBank(event); + _BMTcrosses = RecoBankReader.readBMTCrossBank(event); + if(_SVTcrosses!=null) { + for(Cross cross : _SVTcrosses) { + cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); + cross.setCluster2(_SVTclusters.get(cross.getCluster2().getId()-1)); + } + } + if(_BMTcrosses!=null) { + for(Cross cross : _BMTcrosses) { + cross.setCluster1(_BMTclusters.get(cross.getCluster1().getId()-1)); + } + } + + List tracks = RecoBankReader.readCVTCosmicsBank(event); + if(tracks == null) + return null; + + for(StraightTrack track : tracks) { + + List crosses = new ArrayList<>(); + for(Cross cross : _SVTcrosses) { + if(cross.getAssociatedTrackID()==track.getId()) + crosses.add(cross); + } + if(_BMTcrosses!=null) { + for(Cross cross : _BMTcrosses) { + if(cross.getAssociatedTrackID()==track.getId()) + crosses.add(cross); + } + } + track.addAll(crosses); + + } + + return tracks; + } + + public List getTracks(DataEvent event) { + + + _SVTclusters = RecoBankReader.readBSTClusterBank(event); + _BMTclusters = RecoBankReader.readBMTClusterBank(event); + + + _SVTcrosses = RecoBankReader.readBSTCrossBank(event); + _BMTcrosses = RecoBankReader.readBMTCrossBank(event); + if(_SVTcrosses!=null) { + for(Cross cross : _SVTcrosses) { + cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); + cross.setCluster2(_SVTclusters.get(cross.getCluster2().getId()-1)); + } + } + if(_BMTcrosses!=null) { + for(Cross cross : _BMTcrosses) { + cross.setCluster1(_BMTclusters.get(cross.getCluster1().getId()-1)); + } + } + + List tracks = RecoBankReader.readCVTTracksBank(event); + if(tracks == null) + return null; + + for(Track track : tracks) { + + List crosses = new ArrayList<>(); + for(Cross cross : _SVTcrosses) { + if(cross.getAssociatedTrackID()==track.getId()) + crosses.add(cross); + } + if(_BMTcrosses!=null) { + for(Cross cross : _BMTcrosses) { + if(cross.getAssociatedTrackID()==track.getId()) + crosses.add(cross); + } + } + track.addAll(crosses); + + } + + return tracks; + } + public void fetch_Tracks(DataEvent event, double zShift) { if (_SVTcrosses == null) { @@ -296,16 +389,14 @@ public void fetch_Tracks(DataEvent event, double zShift) { if (_BMTcrosses == null) { fetch_BMTCrosses(event, zShift); } - if (event.hasBank("CVTRec::Tracks") == false) { + if (event.hasBank("CVT::Tracks") == false) { //System.err.println("there is no BST bank "); _tracks = new ArrayList<>(); return; } - List hits = new ArrayList<>(); - - DataBank bank = event.getBank("CVTRec::Tracks"); + DataBank bank = event.getBank("CVT::Tracks"); int rows = bank.rows(); @@ -344,7 +435,7 @@ public void fetch_Tracks(DataEvent event, double zShift) { for (int i = 0; i < rows; i++) { // get the cosmics ray unit direction vector - Track track = new Track(new Helix(d0s[i] * 10, phi0s[i], curvatures[i] / 10, (z0s[i] - zShift) * 10, tandips[i], xbs[i] * 10, ybs[i] * 10)); + Track track = new Track(new Helix(d0s[i] * 10, phi0s[i], Math.max(curvatures[i] / 10, 1E-5), (z0s[i] - zShift) * 10, tandips[i], xbs[i] * 10, ybs[i] * 10)); track.setId(ids[i]); track.setChi2(chi2s[i]); track.setNDF(ndfs[i]); @@ -400,7 +491,7 @@ public void fetch_SVTClusters(DataEvent event) { if (_SVTHits == null) { this.fetch_SVTHits(event); } - DataBank bank = event.getBank("BSTRec::Clusters"); + DataBank bank = event.getBank("BST::Clusters"); for (int i = 0; i < bank.rows(); i++) { @@ -462,7 +553,7 @@ public void fetch_SVTClusters(DataEvent event) { } private void fetch_SVTHits(DataEvent event) { - DataBank bank = event.getBank("BSTRec::Hits"); + DataBank bank = event.getBank("BST::Hits"); _SVTHits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { @@ -484,7 +575,7 @@ private void fetch_SVTHits(DataEvent event) { } public void fetch_BMTHits(DataEvent event) { - DataBank bank = event.getBank("BSTRec::Hits"); + DataBank bank = event.getBank("BMT::Hits"); _BMThits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java index a2dd548e8..ca87346b4 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java @@ -5,11 +5,7 @@ import java.util.Optional; import org.jlab.clas.reco.ReconstructionEngine; -//import org.jlab.clas.swimtools.Swim; import org.jlab.detector.base.DetectorType; -//import org.jlab.detector.calib.utils.DatabaseConstantProvider; -//import org.jlab.detector.geant4.v2.SVT.SVTConstants; -//import org.jlab.detector.geant4.v2.SVT.SVTStripFactory; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -17,7 +13,6 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.bmt.BMTType; -//import org.jlab.rec.cvt.bmt.CCDBConstantsLoader; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.svt.SVTGeometry; @@ -27,93 +22,26 @@ import org.jlab.rec.cvt.trajectory.Trajectory; import Jama.Matrix; +import org.jlab.rec.cvt.banks.RecoBankReader; //import eu.mihosoft.vrl.v3d.Vector3d; /** - * Service to return reconstructed TRACKS - * format + * Service to build input information for CVT KAA alignment * - * @author ziegler + * @author spaul * */ public class CVTAlignment extends ReconstructionEngine { - //org.jlab.rec.cvt.bmt.BMTGeometry BMTGeom; - //CTOFGeant4Factory CTOFGeom; - //SVTStripFactory svtIdealStripFactory; - public CVTAlignment() { super("CVTAlignment", "spaul", "4.0"); - - //BMTGeom = new org.jlab.rec.cvt.bmt.BMTGeometry(); - } - String FieldsConfig = ""; - int Run = -1; + private String FieldsConfig = ""; + private int Run = -1; public boolean isSVTonly = false; private Boolean svtTopBottomSep; - /*public void setRunConditionsParameters(DataEvent event, String FieldsConfig, int iRun, boolean addMisAlignmts, String misAlgnFile) { - if (event.hasBank("RUN::config") == false) { - System.err.println("RUN CONDITIONS NOT READ!"); - return; - } - - int Run = iRun; - - boolean isMC = false; - boolean isCosmics = false; - DataBank bank = event.getBank("RUN::config"); - //System.out.println("EVENTNUM "+bank.getInt("event",0)); - if (bank.getByte("type", 0) == 0) { - isMC = true; - } - if (bank.getByte("mode", 0) == 1) { - isCosmics = true; - } - - - - // Load the fields - //----------------- - String newConfig = "SOLENOID" + bank.getFloat("solenoid", 0); - - if (FieldsConfig.equals(newConfig) == false) { - // Load the Constants - - this.setFieldsConfig(newConfig); - } - FieldsConfig = newConfig; - - // Load the constants - //------------------- - int newRun = bank.getInt("run", 0); - - if (Run != newRun) { - boolean align=false; - //Load field scale - double SolenoidScale =(double) bank.getFloat("solenoid", 0); - Constants.setSolenoidscale(SolenoidScale); - if(Math.abs(SolenoidScale)<0.001) - Constants.setCosmicsData(true); - - //System.out.println(" LOADING BMT GEOMETRY...............................variation = "+variationName); - //CCDBConstantsLoader.Load(new DatabaseConstantProvider(newRun, variationName)); - // System.out.println("SVT LOADING WITH VARIATION "+variationName); - // DatabaseConstantProvider cp = new DatabaseConstantProvider(newRun, variationName); - // cp = SVTConstants.connect( cp ); - // cp.disconnect(); - // SVTStripFactory svtFac = new SVTStripFactory(cp, true); - // SVTGeom.setSvtStripFactory(svtFac); - Constants.Load(isCosmics, isSVTonly); - this.setRun(newRun); - - } - - Run = newRun; - this.setRun(Run); - }*/ - + public int getRun() { return Run; } @@ -165,11 +93,9 @@ public boolean processDataEvent(DataEvent event) { List tracks; if(isCosmics) { - reader.fetch_Cosmics(event, shift); - tracks = reader.get_Cosmics(); + tracks = reader.getCosmics(event); } else { - reader.fetch_Tracks(event, shift); - tracks = reader.get_Tracks(); + tracks = reader.getTracks(event); } /*System.out.println(reader.get_ClustersSVT().size()+ " clusters found in SVT"); @@ -189,7 +115,7 @@ public boolean processDataEvent(DataEvent event) { List qs = new ArrayList(); List trackIDs = new ArrayList<>(); - if (tracks.size() < 3) + if (tracks!=null && tracks.size() < 3) tracksLoop : for (Trajectory track : tracks) { if(Math.abs(getDoca(track))>maxDocaCut) @@ -372,7 +298,6 @@ public boolean processDataEvent(DataEvent event) { } //} } - continue; } @@ -423,7 +348,7 @@ public boolean processDataEvent(DataEvent event) { //event.show(); //only include events that have tracks that will be used in alignment - if(As.size() == 0) + if(As.isEmpty()) return false; return true; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 46dde5eda..94708b85b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -19,8 +19,10 @@ import org.jlab.rec.cvt.hit.Strip; import org.jlab.rec.cvt.svt.SVTGeometry; import org.jlab.rec.cvt.track.Seed; +import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.trajectory.Helix; +import org.jlab.rec.cvt.trajectory.Ray; /** * @@ -328,7 +330,7 @@ public static List readBMTCrossBank(DataEvent event) { } } - public static List readCVTSeedsBank(DataEvent event, double xb, double yb) { + public static List readCVTSeedsBank(DataEvent event) { if(!event.hasBank("CVT::Seeds")) return null; @@ -345,8 +347,8 @@ public static List readCVTSeedsBank(DataEvent event, double xb, double yb) double d0 = bank.getFloat("d0", i)*10; int q = bank.getByte("q", i); int type = bank.getByte("fittingMethod", i); -// double xb = bank.getFloat("xb", i); -// double yb = bank.getFloat("yb", i); + double xb = bank.getFloat("xb", i)*10; + double yb = bank.getFloat("yb", i)*10; Helix helix = new Helix( pt, d0, phi0, z0, tandip, q, xb, yb, Constants.getSolenoidMagnitude()); double[][] covmatrix = new double[5][5]; covmatrix[0][0] = bank.getFloat("cov_d02", i)*10*10; @@ -381,7 +383,7 @@ public static List readCVTSeedsBank(DataEvent event, double xb, double yb) } } - public static List readCVTTracksBank(DataEvent event, double xb, double yb) { + public static List readCVTTracksBank(DataEvent event) { if(!event.hasBank("CVT::Tracks")) return null; @@ -397,8 +399,8 @@ public static List readCVTTracksBank(DataEvent event, double xb, double y double z0 = bank.getFloat("z0", i)*10; double d0 = bank.getFloat("d0", i)*10; int q = bank.getByte("q", i); -// double xb = bank.getFloat("xb", i); -// double yb = bank.getFloat("yb", i); + double xb = bank.getFloat("xb", i)*10; + double yb = bank.getFloat("yb", i)*10; Helix helix = new Helix( pt, d0, phi0, z0, tandip, q, xb, yb, Constants.getSolenoidMagnitude()); double[][] covmatrix = new double[5][5]; covmatrix[0][0] = bank.getFloat("cov_d02", i)*10*10; @@ -437,5 +439,31 @@ public static List readCVTTracksBank(DataEvent event, double xb, double y } } + public static List readCVTCosmicsBank(DataEvent event) { + + if(!event.hasBank("CVTRec::Cosmics")) + return null; + else { + List tracks = new ArrayList<>(); + DataBank bank = event.getBank("CVTRec::Cosmics"); + for(int i = 0; i < bank.rows(); i++) { + int tid = bank.getShort("ID", i); + double chi2 = bank.getFloat("chi2", i); + int ndf = bank.getShort("ndf", i); + double yxSlope = bank.getFloat("trkline_yx_slope", i); + double yxInterc = bank.getFloat("trkline_yx_interc", i)*10; + double yzSlope = bank.getFloat("trkline_yz_slope", i); + double yzInterc = bank.getFloat("trkline_yz_interc", i)*10; + + Ray ray = new Ray(yxSlope, yxInterc, yzSlope, yzInterc); + StraightTrack track = new StraightTrack(ray); + track.setId(tid); + track.setChi2(chi2); + track.setNDF(ndf); + tracks.add(track); + } + return tracks; + } + } } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index 11c7fca58..d6534db19 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -241,6 +241,7 @@ public List getTracks(DataEvent event, boolean initFromMc, boolean kfFilt for(int it = 0; it < tracks.size(); it++) { int id = it + 1; tracks.get(it).setId(id); +// System.out.println("Fit " + tracks.get(it).toString()); tracks.get(it).findTrajectory(swimmer, Geometry.getInstance().geOuterSurfaces()); tracks.get(it).update_Crosses(id); tracks.get(it).update_Clusters(id); @@ -338,12 +339,12 @@ public List getSeedsFromBanks(DataEvent event) { CVTcrosses.add(new ArrayList<>()); } - List seeds = RecoBankReader.readCVTSeedsBank(event, xb, yb); + List seeds = RecoBankReader.readCVTSeedsBank(event); if(seeds == null) return null; - List tracks = RecoBankReader.readCVTTracksBank(event, xb, yb); + List tracks = RecoBankReader.readCVTTracksBank(event); if(tracks == null) return null; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java index f74bb85db..6da51b6e0 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/track/Track.java @@ -14,7 +14,6 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.Constants; import org.jlab.rec.cvt.Geometry; -import org.jlab.rec.cvt.bmt.BMTGeometry; import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.measurement.MLayer; @@ -479,6 +478,8 @@ public void findTrajectory(Swim swimmer, List outer) { stVec.setCalcCentroidStrip(Geometry.getInstance().getSVT().calcNearestStrip(traj.x, traj.y, traj.z, traj.layer, traj.sector)); } else if(MLayer.getDetectorType(index) == DetectorType.BMT) { +// System.out.println(pos.toString() + " " + dir.toString()); +// if(Double.isNaN(pos.x())) System.exit(1); Vector3D localDir = Geometry.getInstance().getBMT().getLocalTrack(traj.layer, traj.sector, pos, dir); stVec.setTrkPhiAtSurface(localDir.phi()); stVec.setTrkThetaAtSurface(localDir.theta()); @@ -567,6 +568,9 @@ public String toString() { this.getNDF(), this.getChi2(), this.getSeed().getStatus()); for(Cross c: this) str = str + c.toString() + "\n"; for(Cluster c: this.getSeed().getClusters()) str = str + c.toString() + "\n"; + if(this.trajs!=null) { + for(HitOnTrack h : trajs.values()) str = str + h.toString() + "\n"; + } return str; } From 37bdd015eb659d9f9123abe40450eed8a91eeb16 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 6 Aug 2022 19:39:47 +0200 Subject: [PATCH 281/291] passing bank names to RecoBankReader methods for handling alignment with both tracks from target and cosmics --- .../cvt/alignment/AlignmentBankReader.java | 20 +++---- .../jlab/rec/cvt/banks/RecoBankReader.java | 54 +++++++++---------- .../rec/cvt/services/TracksFromTargetRec.java | 16 +++--- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index bb706aa40..bf73b187c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -294,12 +294,12 @@ public void fetch_Cosmics(DataEvent event, double zShift) { public List getCosmics(DataEvent event) { - _SVTclusters = RecoBankReader.readBSTClusterBank(event); - _BMTclusters = RecoBankReader.readBMTClusterBank(event); + _SVTclusters = RecoBankReader.readBSTClusterBank(event, "BSTRec::Clusters"); + _BMTclusters = RecoBankReader.readBMTClusterBank(event, "BMTRec::Clusters"); - _SVTcrosses = RecoBankReader.readBSTCrossBank(event); - _BMTcrosses = RecoBankReader.readBMTCrossBank(event); + _SVTcrosses = RecoBankReader.readBSTCrossBank(event, "BSTRec::Crosses"); + _BMTcrosses = RecoBankReader.readBMTCrossBank(event, "BMTRec::Crosses"); if(_SVTcrosses!=null) { for(Cross cross : _SVTcrosses) { cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); @@ -312,7 +312,7 @@ public List getCosmics(DataEvent event) { } } - List tracks = RecoBankReader.readCVTCosmicsBank(event); + List tracks = RecoBankReader.readCVTCosmicsBank(event, "CVTRec::Cosmics"); if(tracks == null) return null; @@ -339,12 +339,12 @@ public List getCosmics(DataEvent event) { public List getTracks(DataEvent event) { - _SVTclusters = RecoBankReader.readBSTClusterBank(event); - _BMTclusters = RecoBankReader.readBMTClusterBank(event); + _SVTclusters = RecoBankReader.readBSTClusterBank(event, "BST::Clusters"); + _BMTclusters = RecoBankReader.readBMTClusterBank(event, "BMT::Clusters"); - _SVTcrosses = RecoBankReader.readBSTCrossBank(event); - _BMTcrosses = RecoBankReader.readBMTCrossBank(event); + _SVTcrosses = RecoBankReader.readBSTCrossBank(event, "BST::Crosses"); + _BMTcrosses = RecoBankReader.readBMTCrossBank(event, "BMT::Crosses"); if(_SVTcrosses!=null) { for(Cross cross : _SVTcrosses) { cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); @@ -357,7 +357,7 @@ public List getTracks(DataEvent event) { } } - List tracks = RecoBankReader.readCVTTracksBank(event); + List tracks = RecoBankReader.readCVTTracksBank(event, "CVT::Tracks"); if(tracks == null) return null; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 94708b85b..4c295a026 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -31,14 +31,14 @@ public class RecoBankReader { - public static List readBSTHitBank(DataEvent event) { + public static List readBSTHitBank(DataEvent event, String bankname) { - if(!event.hasBank("BST::Hits")) + if(!event.hasBank(bankname)) return null; else { List hits = new ArrayList<>(); - DataBank bank = event.getBank("BST::Hits"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int sector = bank.getByte("sector", i); @@ -68,14 +68,14 @@ public static List readBSTHitBank(DataEvent event) { } } - public static List readBMTHitBank(DataEvent event) { + public static List readBMTHitBank(DataEvent event, String bankname) { - if(!event.hasBank("BMT::Hits")) + if(!event.hasBank(bankname)) return null; else { List hits = new ArrayList<>(); - DataBank bank = event.getBank("BMT::Hits"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int sector = bank.getByte("sector", i); @@ -101,14 +101,14 @@ public static List readBMTHitBank(DataEvent event) { } } - public static List readBSTClusterBank(DataEvent event) { + public static List readBSTClusterBank(DataEvent event, String bankname) { - if(!event.hasBank("BST::Clusters")) + if(!event.hasBank(bankname)) return null; else { List clusters = new ArrayList<>(); - DataBank bank = event.getBank("BST::Clusters"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int tid = bank.getShort("trkID", i); @@ -157,14 +157,14 @@ public static List readBSTClusterBank(DataEvent event) { } - public static List readBMTClusterBank(DataEvent event) { + public static List readBMTClusterBank(DataEvent event, String bankname) { - if(!event.hasBank("BMT::Clusters")) + if(!event.hasBank(bankname)) return null; else { List clusters = new ArrayList<>(); - DataBank bank = event.getBank("BMT::Clusters"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int tid = bank.getShort("trkID", i); @@ -236,14 +236,14 @@ public static List readBMTClusterBank(DataEvent event) { - public static List readBSTCrossBank(DataEvent event) { + public static List readBSTCrossBank(DataEvent event, String bankname) { - if(!event.hasBank("BST::Crosses")) + if(!event.hasBank(bankname)) return null; else { List crosses = new ArrayList<>(); - DataBank bank = event.getBank("BST::Crosses"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int tid = bank.getShort("trkID", i); @@ -283,14 +283,14 @@ public static List readBSTCrossBank(DataEvent event) { } } - public static List readBMTCrossBank(DataEvent event) { + public static List readBMTCrossBank(DataEvent event, String bankname) { - if(!event.hasBank("BMT::Crosses")) + if(!event.hasBank(bankname)) return null; else { List crosses = new ArrayList<>(); - DataBank bank = event.getBank("BMT::Crosses"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int id = bank.getShort("ID", i); int tid = bank.getShort("trkID", i); @@ -330,14 +330,14 @@ public static List readBMTCrossBank(DataEvent event) { } } - public static List readCVTSeedsBank(DataEvent event) { + public static List readCVTSeedsBank(DataEvent event, String bankname) { - if(!event.hasBank("CVT::Seeds")) + if(!event.hasBank(bankname)) return null; else { List seeds = new ArrayList<>(); - DataBank bank = event.getBank("CVT::Seeds"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int tid = bank.getShort("ID", i); double pt = bank.getFloat("pt", i); @@ -383,14 +383,14 @@ public static List readCVTSeedsBank(DataEvent event) { } } - public static List readCVTTracksBank(DataEvent event) { + public static List readCVTTracksBank(DataEvent event, String bankname) { - if(!event.hasBank("CVT::Tracks")) + if(!event.hasBank(bankname)) return null; else { List tracks = new ArrayList<>(); - DataBank bank = event.getBank("CVT::Tracks"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int tid = bank.getShort("ID", i); double pt = bank.getFloat("pt", i); @@ -439,14 +439,14 @@ public static List readCVTTracksBank(DataEvent event) { } } - public static List readCVTCosmicsBank(DataEvent event) { + public static List readCVTCosmicsBank(DataEvent event, String bankname) { - if(!event.hasBank("CVTRec::Cosmics")) + if(!event.hasBank(bankname)) return null; else { List tracks = new ArrayList<>(); - DataBank bank = event.getBank("CVTRec::Cosmics"); + DataBank bank = event.getBank(bankname); for(int i = 0; i < bank.rows(); i++) { int tid = bank.getShort("ID", i); double chi2 = bank.getFloat("chi2", i); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java index d6534db19..783ca2bc9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/TracksFromTargetRec.java @@ -275,8 +275,8 @@ public List getTracks(DataEvent event, boolean initFromMc, boolean kfFilt public List getSeedsFromBanks(DataEvent event) { - SVThits = RecoBankReader.readBSTHitBank(event); - BMThits = RecoBankReader.readBMTHitBank(event); + SVThits = RecoBankReader.readBSTHitBank(event, "BST::Hits"); + BMThits = RecoBankReader.readBMTHitBank(event, "BMT::Hits"); if(SVThits!= null) { Collections.sort(SVThits); } @@ -288,8 +288,8 @@ public List getSeedsFromBanks(DataEvent event) { } - SVTclusters = RecoBankReader.readBSTClusterBank(event); - BMTclusters = RecoBankReader.readBMTClusterBank(event); + SVTclusters = RecoBankReader.readBSTClusterBank(event, "BST::Clusters"); + BMTclusters = RecoBankReader.readBMTClusterBank(event, "BMT::Clusters"); if(SVThits!=null && SVTclusters!=null) { for(Hit hit : SVThits) { if(hit.getAssociatedClusterID()>0) { @@ -317,8 +317,8 @@ public List getSeedsFromBanks(DataEvent event) { } } - List SVTcrosses = RecoBankReader.readBSTCrossBank(event); - List BMTcrosses = RecoBankReader.readBMTCrossBank(event); + List SVTcrosses = RecoBankReader.readBSTCrossBank(event, "BST::Crosses"); + List BMTcrosses = RecoBankReader.readBMTCrossBank(event, "BMT::Crosses"); if(SVTcrosses!=null) { for(Cross cross : SVTcrosses) { cross.setCluster1(SVTclusters.get(cross.getCluster1().getId()-1)); @@ -339,12 +339,12 @@ public List getSeedsFromBanks(DataEvent event) { CVTcrosses.add(new ArrayList<>()); } - List seeds = RecoBankReader.readCVTSeedsBank(event); + List seeds = RecoBankReader.readCVTSeedsBank(event, "CVT::Seeds"); if(seeds == null) return null; - List tracks = RecoBankReader.readCVTTracksBank(event); + List tracks = RecoBankReader.readCVTTracksBank(event, "CVT::Tracks"); if(tracks == null) return null; From 76b6f39593fe97cfa5b26c0793565db45dd3a990 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 6 Aug 2022 20:40:39 +0200 Subject: [PATCH 282/291] revert cvt alignment to use original bank reader --- .../cvt/alignment/AlignmentBankReader.java | 30 +++++++++---------- .../jlab/rec/cvt/alignment/CVTAlignment.java | 11 +++++-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index bf73b187c..5ca5aa612 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -1,7 +1,6 @@ package org.jlab.rec.cvt.alignment; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.jlab.detector.base.DetectorType; @@ -18,7 +17,6 @@ import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.hit.Hit; import org.jlab.rec.cvt.hit.Strip; -import org.jlab.rec.cvt.track.Seed; import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.trajectory.Helix; @@ -39,14 +37,14 @@ public void fetch_SVTCrosses(DataEvent event, double zShift) { fetch_SVTClusters(event); } - if (event.hasBank("BST::Crosses") == false) { + if (event.hasBank("BSTRec::Crosses") == false) { //System.err.println("there is no BST bank "); _SVTcrosses = new ArrayList<>(); return; } _SVTcrosses = new ArrayList<>(); - DataBank bank = event.getBank("BST::Crosses"); + DataBank bank = event.getBank("BSTRec::Crosses"); for (int j = 0; j < bank.rows(); j++) { int region = bank.getByte("region", j); @@ -82,14 +80,14 @@ public void fetch_BMTCrosses(DataEvent event, double zShift) { fetch_BMTClusters(event); } - if (event.hasBank("BMT::Crosses") == false) { + if (event.hasBank("BMTRec::Crosses") == false) { //System.err.println("there is no BST bank "); _BMTcrosses = new ArrayList(); return; } _BMTcrosses = new ArrayList(); - DataBank bank = event.getBank("BMT::Crosses"); + DataBank bank = event.getBank("BMTRec::Crosses"); for (int j = 0; j < bank.rows(); j++) { int region = bank.getByte("region", j); @@ -123,7 +121,7 @@ public void fetch_BMTClusters(DataEvent event) { if (_BMThits == null) { this.fetch_BMTHits(event); } - DataBank bank = event.getBank("BMT::Clusters"); + DataBank bank = event.getBank("BMTRec::Clusters"); for (int i = 0; i < bank.rows(); i++) { @@ -339,12 +337,12 @@ public List getCosmics(DataEvent event) { public List getTracks(DataEvent event) { - _SVTclusters = RecoBankReader.readBSTClusterBank(event, "BST::Clusters"); + _SVTclusters = RecoBankReader.readBSTClusterBank(event, "BSTRec::Clusters"); _BMTclusters = RecoBankReader.readBMTClusterBank(event, "BMT::Clusters"); - _SVTcrosses = RecoBankReader.readBSTCrossBank(event, "BST::Crosses"); - _BMTcrosses = RecoBankReader.readBMTCrossBank(event, "BMT::Crosses"); + _SVTcrosses = RecoBankReader.readBSTCrossBank(event, "BSTRec::Crosses"); + _BMTcrosses = RecoBankReader.readBMTCrossBank(event, "BMTRec::Crosses"); if(_SVTcrosses!=null) { for(Cross cross : _SVTcrosses) { cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); @@ -357,7 +355,7 @@ public List getTracks(DataEvent event) { } } - List tracks = RecoBankReader.readCVTTracksBank(event, "CVT::Tracks"); + List tracks = RecoBankReader.readCVTTracksBank(event, "CVTRec::Tracks"); if(tracks == null) return null; @@ -389,14 +387,14 @@ public void fetch_Tracks(DataEvent event, double zShift) { if (_BMTcrosses == null) { fetch_BMTCrosses(event, zShift); } - if (event.hasBank("CVT::Tracks") == false) { + if (event.hasBank("CVTRec::Tracks") == false) { //System.err.println("there is no BST bank "); _tracks = new ArrayList<>(); return; } - DataBank bank = event.getBank("CVT::Tracks"); + DataBank bank = event.getBank("CVTRec::Tracks"); int rows = bank.rows(); @@ -491,7 +489,7 @@ public void fetch_SVTClusters(DataEvent event) { if (_SVTHits == null) { this.fetch_SVTHits(event); } - DataBank bank = event.getBank("BST::Clusters"); + DataBank bank = event.getBank("BSTRec::Clusters"); for (int i = 0; i < bank.rows(); i++) { @@ -553,7 +551,7 @@ public void fetch_SVTClusters(DataEvent event) { } private void fetch_SVTHits(DataEvent event) { - DataBank bank = event.getBank("BST::Hits"); + DataBank bank = event.getBank("BSTRec::Hits"); _SVTHits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { @@ -575,7 +573,7 @@ private void fetch_SVTHits(DataEvent event) { } public void fetch_BMTHits(DataEvent event) { - DataBank bank = event.getBank("BMT::Hits"); + DataBank bank = event.getBank("BMTRec::Hits"); _BMThits = new ArrayList(); for (int i = 0; i < bank.rows(); i++) { diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java index ca87346b4..11acd0472 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/CVTAlignment.java @@ -92,10 +92,17 @@ public boolean processDataEvent(DataEvent event) { //reader.fetch_Cosmics(event, SVTGeom, 0); List tracks; +// if(isCosmics) { +// tracks = reader.getCosmics(event); +// } else { +// tracks = reader.getTracks(event); +// } if(isCosmics) { - tracks = reader.getCosmics(event); + reader.fetch_Cosmics(event, shift); + tracks = reader.get_Cosmics(); } else { - tracks = reader.getTracks(event); + reader.fetch_Tracks(event, shift); + tracks = reader.get_Tracks(); } /*System.out.println(reader.get_ClustersSVT().size()+ " clusters found in SVT"); From c3c3ce488f89d92c8f827e1f0061f7811763600b Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 6 Aug 2022 21:23:12 +0200 Subject: [PATCH 283/291] fixing some missing units conversion --- .../jlab/rec/cvt/alignment/AlignmentBankReader.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index 5ca5aa612..ae0551c3c 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -142,8 +142,8 @@ public void fetch_BMTClusters(DataEvent event) { cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); } else { - cluster.setCentroidResidual(bank.getFloat("centroidResidual", i)); - cluster.setSeedResidual(bank.getFloat("seedResidual", i)); + cluster.setCentroidResidual(10*bank.getFloat("centroidResidual", i)); + cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); } cluster.setAssociatedTrackID(bank.getShort("trkID", i)); cluster.setLine(new Line3D( @@ -166,7 +166,7 @@ public void fetch_BMTClusters(DataEvent event) { bank.getFloat("lx", i), bank.getFloat("ly", i), bank.getFloat("lz", i))); - cluster.setResolution(bank.getFloat("e", i)); + cluster.setResolution(10*bank.getFloat("e", i)); Point3D x1 = new Point3D( 10*bank.getFloat("x1", i), @@ -504,8 +504,8 @@ public void fetch_SVTClusters(DataEvent event) { cluster.setCentroid(bank.getFloat("centroid", i)); //cluster.setSeedEnergy(bank.getFloat("seedE",i)); //cluster.setSeedEnergy(bank.getFloat("seedE",i)); - cluster.setCentroidResidual(bank.getFloat("centroidResidual", i)); - cluster.setSeedResidual(bank.getFloat("seedResidual", i)); + cluster.setCentroidResidual(10*bank.getFloat("centroidResidual", i)); + cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); cluster.setAssociatedTrackID(bank.getShort("trkID", i)); cluster.setLine(new Line3D( 10*bank.getFloat("x1", i), From 20f22e67157bf2d016fca9913c8a1e9afb5df73a Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sun, 7 Aug 2022 19:02:40 +0200 Subject: [PATCH 284/291] set straight tracks momentum to 100 GeV for alignment --- .../jlab/clas/tracking/kalmanfilter/helical/StateVecs.java | 3 +-- .../jlab/clas/tracking/kalmanfilter/straight/StateVecs.java | 2 +- .../java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java | 5 +++++ .../java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index ae812ba39..02791b4d8 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -7,7 +7,6 @@ import org.jlab.clas.tracking.kalmanfilter.Surface; import org.jlab.clas.tracking.kalmanfilter.Units; import org.jlab.clas.tracking.trackrep.Helix; -import org.jlab.clas.tracking.utilities.MatrixOps; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -246,7 +245,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); double p = Math.sqrt(vec.px*vec.px + vec.py*vec.py + vec.pz*vec.pz); - if(this.straight) p = 1; + if(this.straight) p = 100; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index d811b23f9..efa42dfb7 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -108,7 +108,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { Surface surf = mv.measurements.get(vec.k).surface; double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); - double p = 1; + double p = 100; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index ae0551c3c..3ddb5bba8 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -22,6 +22,11 @@ import org.jlab.rec.cvt.trajectory.Helix; import org.jlab.rec.cvt.trajectory.Ray; +/** + * + * @author spaul + * + */ public class AlignmentBankReader { private List _cosmics; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java index 755c135dd..dd49313ae 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java @@ -7,6 +7,11 @@ import Jama.Matrix; +/** + * + * @author spaul + * + */ public class AlignmentBankWriter { public void write_Matrix(DataEvent event, String matrixName, List matrices) { From eb4d408479e4c3c5062d5af91c6fc9dff825cfc3 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 12 Aug 2022 20:13:04 -0400 Subject: [PATCH 285/291] add checks on NaNs for cosmic tracks --- .../jlab/clas/tracking/kalmanfilter/straight/KFitter.java | 7 ++++++- .../org/jlab/rec/cvt/alignment/AlignmentBankWriter.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java index 4c212a492..cd95f6c36 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/KFitter.java @@ -53,7 +53,12 @@ public void runFitter(AStateVecs sv, AMeasVecs mv) { // chi2 double newchisq = this.calc_chi2(sv, mv); // if curvature is 0, fit failed - if(Double.isNaN(newchisq) || sv.smoothed().get(0)==null) { + if(Double.isNaN(newchisq) || + sv.smoothed().get(0)==null || + Double.isNaN(sv.smoothed().get(0).x0) || + Double.isNaN(sv.smoothed().get(0).z0) || + Double.isNaN(sv.smoothed().get(0).tx) || + Double.isNaN(sv.smoothed().get(0).tz)) { this.setFitFailed = true; break; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java index dd49313ae..c5f9a7075 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java @@ -29,6 +29,8 @@ public void write_Matrix(DataEvent event, String matrixName, List matric bank.setShort("columns",i,(short) matrices.get(i).getColumnDimension()); for(int j = 0; j Date: Sat, 13 Aug 2022 14:08:11 -0400 Subject: [PATCH 286/291] restored 1 GeV momentum for straight tracks --- .../org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java | 2 +- .../org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 02791b4d8..4fa53e169 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -245,7 +245,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); double p = Math.sqrt(vec.px*vec.px + vec.py*vec.py + vec.pz*vec.pz); - if(this.straight) p = 100; + if(this.straight) p = 1; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index efa42dfb7..d811b23f9 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -108,7 +108,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { Surface surf = mv.measurements.get(vec.k).surface; double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); - double p = 100; + double p = 1; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); From c6906ec7edfbfc9e3ced6791e0ee09959aa8e5d8 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 13 Aug 2022 17:17:33 -0400 Subject: [PATCH 287/291] forcing magnetic field to be zero for cosmics, fix to phi->strip number of BMT-Z --- .../cvt/src/main/java/org/jlab/rec/cvt/Geometry.java | 5 +++++ .../cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java | 2 +- .../src/main/java/org/jlab/rec/cvt/services/CVTEngine.java | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Geometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Geometry.java index 01478066a..fc7954247 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Geometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/Geometry.java @@ -1,5 +1,6 @@ package org.jlab.rec.cvt; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.List; import org.jlab.clas.tracking.kalmanfilter.Surface; @@ -60,6 +61,10 @@ public synchronized static void initialize(String variation, int run, IndexedTab private synchronized void load(String variation, int run, IndexedTable svtLorentz, IndexedTable bmtVoltage) { + if(Constants.getInstance().isCosmics) { + MagneticFields.getInstance().getSolenoid().setScaleFactor(1e-7); + MagneticFields.getInstance().getTorus().setScaleFactor(1e-7); + } // Load target ConstantProvider providerTG = GeometryFactory.getConstants(DetectorType.TARGET, run, variation); this.zTarget = providerTG.getDouble("/geometry/target/position",0)*10; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java index 838f15588..940f1eb9b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/bmt/BMTGeometry.java @@ -787,7 +787,7 @@ public int getZstrip(int region, Point3D localTraj) { // CHECKME double edge = this.getPhi(layer, sector) - this.getDPhi(layer, sector); // 30 150 270 double pitch = this.getZPitch(region,1); - double radius = this.getRadiusMidDrift(layer); + double radius = this.getRadius(layer); double dphi = angle - edge; if(dphi<0) dphi += 2*Math.PI; strip = (int) Math.floor(dphi*radius/pitch) + 1; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTEngine.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTEngine.java index 1e7dff2c7..f521321e2 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTEngine.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/services/CVTEngine.java @@ -169,9 +169,7 @@ public boolean kfBeamSpot() { @Override public boolean processDataEvent(DataEvent event) { - - Swim swimmer = new Swim(); - + int run = this.getRun(event); if(run<=0) return true; @@ -183,6 +181,8 @@ public boolean processDataEvent(DataEvent event) { IndexedTable beamPos = this.getConstantsManager().getConstants(run, "/geometry/beam/position"); Geometry.initialize(this.getConstantsManager().getVariation(), 11, svtLorentz, bmtVoltage); + + Swim swimmer = new Swim(); CVTReconstruction reco = new CVTReconstruction(swimmer); From e6bd110c2edb925dfc5e2fce8987c73a74384fff Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 13 Aug 2022 23:20:26 -0400 Subject: [PATCH 288/291] cvt alignment code cleanup and switch to ejml --- .../cvt/alignment/AlignmentBankReader.java | 541 +--- .../cvt/alignment/AlignmentBankWriter.java | 13 +- .../jlab/rec/cvt/alignment/CVTAlignment.java | 2560 ++++++----------- .../jlab/rec/cvt/banks/RecoBankReader.java | 13 +- .../java/org/jlab/rec/cvt/cross/Cross.java | 2 +- 5 files changed, 943 insertions(+), 2186 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index 3ddb5bba8..92d4814b1 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -4,15 +4,12 @@ import java.util.List; import org.jlab.detector.base.DetectorType; -import org.jlab.geom.prim.Arc3D; import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.cvt.banks.RecoBankReader; import org.jlab.rec.cvt.bmt.BMTGeometry; -import org.jlab.rec.cvt.bmt.BMTType; import org.jlab.rec.cvt.cluster.Cluster; import org.jlab.rec.cvt.cross.Cross; import org.jlab.rec.cvt.hit.Hit; @@ -20,7 +17,6 @@ import org.jlab.rec.cvt.track.StraightTrack; import org.jlab.rec.cvt.track.Track; import org.jlab.rec.cvt.trajectory.Helix; -import org.jlab.rec.cvt.trajectory.Ray; /** * @@ -29,270 +25,10 @@ */ public class AlignmentBankReader { - private List _cosmics; - private List _SVTcrosses; - private List _SVTclusters; - private List _SVTHits; - private List _BMTcrosses; - private List _BMTclusters; - private List _BMThits; - - public void fetch_SVTCrosses(DataEvent event, double zShift) { - if (_SVTclusters == null) { - fetch_SVTClusters(event); - } - - if (event.hasBank("BSTRec::Crosses") == false) { - //System.err.println("there is no BST bank "); - _SVTcrosses = new ArrayList<>(); - - return; - } - _SVTcrosses = new ArrayList<>(); - DataBank bank = event.getBank("BSTRec::Crosses"); - - for (int j = 0; j < bank.rows(); j++) { - int region = bank.getByte("region", j); - int sector = bank.getByte("sector", j); - int id = bank.getShort("ID", j); - Cross cross = new Cross(DetectorType.BST, BMTType.UNDEFINED, sector, region, j); - cross.setId(id); - cross.setPoint(new Point3D(10. * bank.getFloat("x", j), 10. * bank.getFloat("y", j), 10. * (bank.getFloat("z", j) - zShift))); - cross.setPointErr(new Point3D(10. * bank.getFloat("err_x", j), 10. * bank.getFloat("err_y", j), 10. * bank.getFloat("err_z", j))); - cross.setAssociatedTrackID(bank.getShort("trkID", j)); - cross.setDir(new Vector3D(bank.getFloat("ux", j), bank.getFloat("uy", j), bank.getFloat("uz", j))); - - int cluster1id = bank.getShort("Cluster1_ID", j); - for (Cluster cluster : _SVTclusters) { - if (cluster.getId() == cluster1id) { - cross.setCluster1(cluster); - } - } - int cluster2id = bank.getShort("Cluster2_ID", j); - for (Cluster cluster : _SVTclusters) { - if (cluster.getId() == cluster2id) { - cross.setCluster2(cluster); - } - } - - _SVTcrosses.add(cross); - } - - } - - public void fetch_BMTCrosses(DataEvent event, double zShift) { - if (_BMTclusters == null) { - fetch_BMTClusters(event); - } - - if (event.hasBank("BMTRec::Crosses") == false) { - //System.err.println("there is no BST bank "); - _BMTcrosses = new ArrayList(); - - return; - } - _BMTcrosses = new ArrayList(); - DataBank bank = event.getBank("BMTRec::Crosses"); - - for (int j = 0; j < bank.rows(); j++) { - int region = bank.getByte("region", j); - int sector = bank.getByte("sector", j); - int id = bank.getShort("ID", j); - Cross cross = new Cross(DetectorType.BMT, BMTType.UNDEFINED, sector, region, id); - cross.setPoint(new Point3D(10. * bank.getFloat("x", j), 10. * bank.getFloat("y", j), 10. * (bank.getFloat("z", j) - zShift))); - cross.setPointErr(new Point3D(10. * bank.getFloat("err_x", j), 10. * bank.getFloat("err_y", j), 10. * bank.getFloat("err_z", j))); - cross.setAssociatedTrackID(bank.getShort("trkID", j)); - cross.setDir(new Vector3D(bank.getFloat("ux", j), bank.getFloat("uy", j), bank.getFloat("uz", j))); - - int cluster1id = bank.getShort("Cluster1_ID", j); - for (Cluster cluster : _BMTclusters) { - if (cluster.getId() == cluster1id) { - cross.setCluster1(cluster); - cross.setType(BMTGeometry.getDetectorType(cluster.getLayer())); - } - } - //int cluster2id = bank.getShort("Cluster2_ID", j); - //for (Cluster cluster: _clusters) - // if (cluster.getId() == cluster2id) - // cross.setCluster2(cluster); - - _BMTcrosses.add(cross); - } - - } - - public void fetch_BMTClusters(DataEvent event) { - _BMTclusters = new ArrayList<>(); - if (_BMThits == null) { - this.fetch_BMTHits(event); - } - DataBank bank = event.getBank("BMTRec::Clusters"); - - for (int i = 0; i < bank.rows(); i++) { - - int id = bank.getShort("ID", i); - int layer = bank.getByte("layer", i); - int sector = bank.getByte("sector", i); - Cluster cluster = new Cluster(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, id); - - int size = bank.getInt("size", i); - cluster.setTotalEnergy(bank.getFloat("ETot", i)); - - //cluster.setSeed(bank.getInt("seedStrip", i)); - cluster.setCentroid(bank.getFloat("centroid", i)); - //cluster.setSeedEnergy(bank.getFloat("seedE",i)); - //cluster.setSeedEnergy(bank.getFloat("seedE",i)); - if(cluster.getType()==BMTType.C) { - cluster.setCentroidResidual(10*bank.getFloat("centroidResidual", i)); - cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); - } - else { - cluster.setCentroidResidual(10*bank.getFloat("centroidResidual", i)); - cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); - } - cluster.setAssociatedTrackID(bank.getShort("trkID", i)); - cluster.setLine(new Line3D( - 10*bank.getFloat("x1", i), - 10*bank.getFloat("y1", i), - 10*bank.getFloat("z1", i), - 10*bank.getFloat("x2", i), - 10*bank.getFloat("y2", i), - 10*bank.getFloat("z2", i) - )); - cluster.setS(new Vector3D( - bank.getFloat("sx", i), - bank.getFloat("sy", i), - bank.getFloat("sz", i))); - cluster.setN(new Vector3D( - bank.getFloat("nx", i), - bank.getFloat("ny", i), - bank.getFloat("nz", i))); - cluster.setL(new Vector3D( - bank.getFloat("lx", i), - bank.getFloat("ly", i), - bank.getFloat("lz", i))); - cluster.setResolution(10*bank.getFloat("e", i)); - - Point3D x1 = new Point3D( - 10*bank.getFloat("x1", i), - 10*bank.getFloat("y1", i), - 10*bank.getFloat("z1", i)); - /*Point3D x2 = new Point3D( - bank.getFloat("x2", i), - bank.getFloat("y2", i), - bank.getFloat("z2", i)); - Point3D c = new Point3D( - bank.getFloat("cx", i), - bank.getFloat("cy", i), - bank.getFloat("cz", i));*/ - Point3D a1 = new Point3D( - 10*bank.getFloat("ax1", i), - 10*bank.getFloat("ay1", i), - 10*bank.getFloat("az1", i)); - Point3D a2 = new Point3D( - 10*bank.getFloat("ax2", i), - 10*bank.getFloat("ay2", i), - 10*bank.getFloat("az2", i)); - - Vector3D a = a1.vectorTo(a2).asUnit(); - Point3D arccenter = a1.toVector3D().add(a.multiply(a.dot(a1.vectorTo(x1)))).toPoint3D(); - - cluster.setArc(new Arc3D( - x1, - arccenter, a, - bank.getFloat("theta", i) - )); - cluster.setType(BMTGeometry.getDetectorType(layer)); - - //Since only up to 5 hits per track are written... - for (int j = 0; j < 5; j++) { - String hitStrg = "Hit"; - hitStrg += (j + 1); - hitStrg += "_ID"; - if (!hasColumn(bank, hitStrg)) { - continue; - } - int hitId = bank.getShort(hitStrg, i); - for (Hit hit : _BMThits) { - if (hit.getId() == hitId) { - cluster.add(hit); - } - } - } - _BMTclusters.add(cluster); - - } - } - - public void fetch_Cosmics(DataEvent event, double zShift) { - - if (_SVTcrosses == null) { - fetch_SVTCrosses(event, zShift); - } - if (_BMTcrosses == null) { - fetch_BMTCrosses(event, zShift); - } - if (event.hasBank("CVTRec::Cosmics") == false) { - //System.err.println("there is no BST bank "); - _cosmics = new ArrayList<>(); - - return; - } - - DataBank bank = event.getBank("CVTRec::Cosmics"); - - int rows = bank.rows(); - - short ids[] = bank.getShort("ID"); - float chi2s[] = bank.getFloat("chi2"); - short ndfs[] = bank.getShort("ndf"); - float yx_slopes[] = bank.getFloat("trkline_yx_slope"); - float yx_intercs[] = bank.getFloat("trkline_yx_interc"); - float yz_slopes[] = bank.getFloat("trkline_yz_slope"); - float yz_intercs[] = bank.getFloat("trkline_yz_interc"); - - _cosmics = new ArrayList<>(); - - for (int i = 0; i < rows; i++) { - // get the cosmics ray unit direction vector - Vector3D u = new Vector3D(yx_slopes[i], 1, yz_slopes[i]).asUnit(); - Point3D point = new Point3D(10. * yx_intercs[i], 0, 10. * (yz_intercs[i] - zShift)); - Ray ray = new Ray(point, u); - StraightTrack track = new StraightTrack(ray); - track.setId(ids[i]); - track.setChi2(chi2s[i]); - track.setNDF(ndfs[i]); - - loopCrossId: - for (int j = 0; j < 18; j++) { - - String hitStrg = "Cross"; - hitStrg += (j + 1); - hitStrg += "_ID"; - if (!hasColumn(bank, hitStrg)) { - continue; - } - int crossid = bank.getShort(hitStrg, i); - for (Cross cross : _SVTcrosses) { - if (cross.getId() == crossid) { - track.add(cross); - continue loopCrossId; - } - - } - for (Cross cross : _BMTcrosses) { - if (cross.getId() == crossid) { - track.add(cross); - continue loopCrossId; - } - } - } - _cosmics.add(track); - - } - } - - ArrayList _tracks; + private List _SVTcrosses; + private List _SVTclusters; + private List _BMTcrosses; + private List _BMTclusters; public List getCosmics(DataEvent event) { @@ -322,20 +58,24 @@ public List getCosmics(DataEvent event) { for(StraightTrack track : tracks) { List crosses = new ArrayList<>(); - for(Cross cross : _SVTcrosses) { - if(cross.getAssociatedTrackID()==track.getId()) - crosses.add(cross); - } - if(_BMTcrosses!=null) { - for(Cross cross : _BMTcrosses) { - if(cross.getAssociatedTrackID()==track.getId()) - crosses.add(cross); + for(Cross c : track) { + if(_SVTcrosses!=null && c.getDetector()==DetectorType.BST) { + for(Cross cross : _SVTcrosses) { + if(c.getId() == cross.getId()) + crosses.add(cross); + } + } + if(_BMTcrosses!=null && c.getDetector()==DetectorType.BMT) { + for(Cross cross : _BMTcrosses) { + if(c.getId() == cross.getId()) + crosses.add(cross); + } } } + track.clear(); track.addAll(crosses); - } - + return tracks; } @@ -367,16 +107,21 @@ public List getTracks(DataEvent event) { for(Track track : tracks) { List crosses = new ArrayList<>(); - for(Cross cross : _SVTcrosses) { - if(cross.getAssociatedTrackID()==track.getId()) - crosses.add(cross); - } - if(_BMTcrosses!=null) { - for(Cross cross : _BMTcrosses) { - if(cross.getAssociatedTrackID()==track.getId()) - crosses.add(cross); + for(Cross c : track) { + if(_SVTcrosses!=null && c.getDetector()==DetectorType.BST) { + for(Cross cross : _SVTcrosses) { + if(c.getId() == cross.getId()) + crosses.add(cross); + } + } + if(_BMTcrosses!=null && c.getDetector()==DetectorType.BMT) { + for(Cross cross : _BMTcrosses) { + if(c.getId() == cross.getId()) + crosses.add(cross); + } } } + track.clear(); track.addAll(crosses); } @@ -384,229 +129,7 @@ public List getTracks(DataEvent event) { return tracks; } - public void fetch_Tracks(DataEvent event, double zShift) { - - if (_SVTcrosses == null) { - fetch_SVTCrosses(event, zShift); - } - if (_BMTcrosses == null) { - fetch_BMTCrosses(event, zShift); - } - if (event.hasBank("CVTRec::Tracks") == false) { - //System.err.println("there is no BST bank "); - _tracks = new ArrayList<>(); - - return; - } - - DataBank bank = event.getBank("CVTRec::Tracks"); - - int rows = bank.rows(); - - short ids[] = bank.getShort("ID"); - float chi2s[] = bank.getFloat("chi2"); - short ndfs[] = bank.getShort("ndf"); - byte qs[] = bank.getByte("q"); - float ps[] = bank.getFloat("p"); - float pts[] = bank.getFloat("pt"); - float tandips[] = bank.getFloat("tandip"); - float phi0s[] = bank.getFloat("phi0"); - float z0s[] = bank.getFloat("z0"); - float d0s[] = bank.getFloat("d0"); - float xbs[] = bank.getFloat("xb"); - float ybs[] = bank.getFloat("yb"); - if (xbs.length > 0) { - xb = xbs[0] * 10; - yb = ybs[0] * 10; - } - //System.out.println("xb yb from file" + xbs[0] + ybs[0]); - - float curvatures[]; - //try { - // curvatures = bank.getFloat("curvature"); - //}catch(Exception e){ - curvatures = new float[ids.length]; - //} - - /*bank.setFloat("phi0", i, (float) helix.get_phi_at_dca()); - bank.setFloat("tandip", i, (float) helix.get_tandip()); - bank.setFloat("z0", i, (float) (helix.get_Z0()/10.+zShift)); - bank.setFloat("d0", i, (float) (helix.get_dca()/10.)); - bank.setFloat("xb", i, (float) (org.jlab.rec.cvt.Constants.getXb()/10.0)); - bank.setFloat("yb", i, (float) (org.jlab.rec.cvt.Constants.getYb()/10.0));*/ - _tracks = new ArrayList<>(); - - for (int i = 0; i < rows; i++) { - // get the cosmics ray unit direction vector - Track track = new Track(new Helix(d0s[i] * 10, phi0s[i], Math.max(curvatures[i] / 10, 1E-5), (z0s[i] - zShift) * 10, tandips[i], xbs[i] * 10, ybs[i] * 10)); - track.setId(ids[i]); - track.setChi2(chi2s[i]); - track.setNDF(ndfs[i]); - //there are other entries that should be read. add these later. - - loopCrossId: - for (int j = 0; j < 18; j++) { - - String hitStrg = "Cross"; - hitStrg += (j + 1); - hitStrg += "_ID"; - if (!hasColumn(bank, hitStrg)) { - continue; - } - int crossid = bank.getShort(hitStrg, i); - for (Cross cross : _SVTcrosses) { - if (cross.getId() == crossid) { - track.add(cross); - } - } - for (Cross cross : _BMTcrosses) { - if (cross.getId() == crossid) { - track.add(cross); - continue loopCrossId; - } - } - } - _tracks.add(track); - - } - } - private double xb, yb; - - public double getXbeam() { - return xb; - } - - public double getYbeam() { - return yb; - } - - public boolean hasColumn(DataBank bank, String name) { - for (String n : bank.getColumnList()) { - if (name.equalsIgnoreCase(n)) { - return true; - } - } - return false; - } - - public void fetch_SVTClusters(DataEvent event) { - _SVTclusters = new ArrayList(); - if (_SVTHits == null) { - this.fetch_SVTHits(event); - } - DataBank bank = event.getBank("BSTRec::Clusters"); - - for (int i = 0; i < bank.rows(); i++) { - - int id = bank.getShort("ID", i); - int layer = bank.getByte("layer", i); - int sector = bank.getByte("sector", i); - Cluster cluster = new Cluster(DetectorType.BST, null, sector, layer, id); - - int size = bank.getInt("size", i); - cluster.setTotalEnergy(bank.getFloat("ETot", i)); - //cluster.setSeed(bank.getInt("seedStrip", i)); - cluster.setCentroid(bank.getFloat("centroid", i)); - //cluster.setSeedEnergy(bank.getFloat("seedE",i)); - //cluster.setSeedEnergy(bank.getFloat("seedE",i)); - cluster.setCentroidResidual(10*bank.getFloat("centroidResidual", i)); - cluster.setSeedResidual(10*bank.getFloat("seedResidual", i)); - cluster.setAssociatedTrackID(bank.getShort("trkID", i)); - cluster.setLine(new Line3D( - 10*bank.getFloat("x1", i), - 10*bank.getFloat("y1", i), - 10*bank.getFloat("z1", i), - 10*bank.getFloat("x2", i), - 10*bank.getFloat("y2", i), - 10*bank.getFloat("z2", i) - )); - cluster.setS(new Vector3D( - bank.getFloat("sx", i), - bank.getFloat("sy", i), - bank.getFloat("sz", i))); - cluster.setN(new Vector3D( - bank.getFloat("nx", i), - bank.getFloat("ny", i), - bank.getFloat("nz", i))); - cluster.setL(new Vector3D( - bank.getFloat("lx", i), - bank.getFloat("ly", i), - bank.getFloat("lz", i))); - cluster.setResolution(10*bank.getFloat("e", i)); - - //Since only up to 5 hits per track are written... - for (int j = 0; j < 5; j++) { - String hitStrg = "Hit"; - hitStrg += (j + 1); - hitStrg += "_ID"; - if (!hasColumn(bank, hitStrg)) { - continue; - } - int hitId = bank.getShort(hitStrg, i); - for (Hit hit : _SVTHits) { - if (hit.getId() == hitId) { - cluster.add(hit); - } - } - } - _SVTclusters.add(cluster); - - } - - } - - private void fetch_SVTHits(DataEvent event) { - DataBank bank = event.getBank("BSTRec::Hits"); - - _SVTHits = new ArrayList(); - for (int i = 0; i < bank.rows(); i++) { - int layer = bank.getByte("layer", i); - int sector = bank.getByte("sector", i); - int strip = bank.getInt("strip", i); - int id = bank.getShort("ID", i); - Hit hit = new Hit(DetectorType.BST, null, sector, layer, new Strip(strip, 0, 0)); - - hit.setId(id); - hit.setdocaToTrk(bank.getFloat("fitResidual", i)*10); - hit.setTrkgStatus(bank.getInt("trkingStat", i)); - - hit.setAssociatedClusterID(bank.getShort("clusterID", i)); - hit.setAssociatedTrackID(bank.getShort("trkID", i)); - _SVTHits.add(hit); - } - //bank.show(); - } - - public void fetch_BMTHits(DataEvent event) { - DataBank bank = event.getBank("BMTRec::Hits"); - - _BMThits = new ArrayList(); - for (int i = 0; i < bank.rows(); i++) { - int layer = bank.getByte("layer", i); - int sector = bank.getByte("sector", i); - int strip = bank.getInt("strip", i); - int id = bank.getShort("ID", i); - Hit hit = new Hit(DetectorType.BMT, BMTGeometry.getDetectorType(layer), sector, layer, new Strip(strip, 0, 0)); - - hit.setId(id); - hit.setdocaToTrk(bank.getFloat("fitResidual", i)*10); - hit.setTrkgStatus(bank.getInt("trkingStat", i)); - - hit.setAssociatedClusterID(bank.getShort("clusterID", i)); - hit.setAssociatedTrackID(bank.getShort("trkID", i)); - _BMThits.add(hit); - } - //bank.show(); - } - - public List get_Cosmics() { - return _cosmics; - } - - public List get_Tracks() { - return _tracks; - } - + public List get_ClustersSVT() { return _SVTclusters; } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java index c5f9a7075..428d0b81b 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankWriter.java @@ -4,8 +4,7 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; - -import Jama.Matrix; +import org.ejml.simple.SimpleMatrix; /** * @@ -14,7 +13,7 @@ */ public class AlignmentBankWriter { - public void write_Matrix(DataEvent event, String matrixName, List matrices) { + public void write_Matrix(DataEvent event, String matrixName, List matrices) { //System.out.println("attempting to write matrices"); if(event == null) @@ -25,10 +24,10 @@ public void write_Matrix(DataEvent event, String matrixName, List matric System.out.println("matrix list is null"); DataBank bank = event.createBank("Align::" + matrixName, matrices.size()); for(int i = 0; i< matrices.size(); i++) { - bank.setShort("rows",i,(short) matrices.get(i).getRowDimension()); - bank.setShort("columns",i,(short) matrices.get(i).getColumnDimension()); - for(int j = 0; j tracks; -// if(isCosmics) { -// tracks = reader.getCosmics(event); -// } else { -// tracks = reader.getTracks(event); -// } - if(isCosmics) { - reader.fetch_Cosmics(event, shift); - tracks = reader.get_Cosmics(); - } else { - reader.fetch_Tracks(event, shift); - tracks = reader.get_Tracks(); - } - - /*System.out.println(reader.get_ClustersSVT().size()+ " clusters found in SVT"); - System.out.println(reader.get_ClustersBMT().size()+ " clusters found in BMT"); - System.out.println(reader.get_CrossesSVT().size() + " crosses found in SVT"); - System.out.println(reader.get_CrossesBMT().size() + " crosses found in BMT"); - System.out.println(tracks.size() + " tracks found");*/ - - - //System.out.println("H"); - List Is = new ArrayList(); - List As = new ArrayList(); - List Bs = new ArrayList(); - List Vs = new ArrayList(); - List ms = new ArrayList(); - List cs = new ArrayList(); - List qs = new ArrayList(); - List trackIDs = new ArrayList<>(); - - if (tracks!=null && tracks.size() < 3) - tracksLoop : for (Trajectory track : tracks) { - - if(Math.abs(getDoca(track))>maxDocaCut) - continue; - /*System.out.println("track read: "); - System.out.println("track chi2: "+ track.get_chi2()); - System.out.println("ndf: "+ track.get_ndf()); - System.out.println("ncrosses: "+ track.size()); - System.out.println("ray: "+ track.getRay().getRefPoint() + - " + lambda*" + track.getRay().getDirVec()); - System.out.println();*/ - - //System.out.println("BMT crosses"); - int nCrossSVT = 0, nCrossBMT = 0; - int countBMTZ = 0, countBMTC = 0; - for(Cross c : track) { - if(c.getDetector() == DetectorType.BST && !isBMTonly) { - nCrossSVT++; - gCountSVT++; - } - if(c.getDetector() == DetectorType.BMT && !isSVTonly) { - if (c.getCluster1().getType() != BMTType.C || ! skipBMTC) - nCrossBMT++; - if (c.getCluster1().getType() == BMTType.C) { - countBMTC++; - gCountBMTC++; - } - if(c.getCluster1().getType() == BMTType.Z) { - gCountBMTZ++; - countBMTZ++; - } - //System.out.println(c.getSector()+" "+c.getRegion() + " " + c.getCluster1().getCentroid()+" " + c.getId()); - } - if(nCrossBMT>12) { - System.out.println("Too many BMT crosses!"); - return false; - } - } - - - if(nCrossSVT*20.001 && !curvedTracks) { - continue; - } - } - //getRay(track); - //System.out.println(ray.getDirVec().toString()); - //System.out.println(ray.getRefPoint().toString()); - - - int paramsFromBeamspot = (isCosmics || ! includeBeamspot ? 0:1); - int colsA = nAlignVars*((svtTopBottomSep ? 2*nCrossSVT : nCrossSVT) + nCrossBMT + paramsFromBeamspot); - int rows = 2*nCrossSVT+nCrossBMT + paramsFromBeamspot; - Matrix A = new Matrix(rows, colsA);//not sure why there aren't 6 columns - Matrix B = new Matrix(rows, 4); - Matrix V = new Matrix(rows,rows); - Matrix m = new Matrix(rows,1); - Matrix c = new Matrix(rows,1); - Matrix I = new Matrix(rows,1); - Matrix q = new Matrix(4, 1); //track parameters, for plotting kinematic dependence. Not used in KFA. - if (track.getHelix() == null) { - track.setHelix(createHelixFromRay(track.getRay())); - } - - q.set(0, 0, track.getHelix().getDCA()); - q.set(1, 0, track.getHelix().getPhiAtDCA()); - q.set(2, 0, track.getHelix().getZ0()); - q.set(3, 0, track.getHelix().getTanDip()); - - if(debug) { - System.out.println("track parameters"); - q.print(4, 4); - } - - int i = 0; - boolean useNewFillMatrices = true; - if(!curvedTracks) { - for(Cross cross : track) { - if(useNewFillMatrices) { - if(cross.getDetector() == DetectorType.BST){ - Cluster cl1 = cross.getCluster1(); - boolean ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - Cluster cl2 = cross.getCluster2(); - ok = fillMatricesNew(i,ray,cl2,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - } else { - Cluster cl1 = cross.getCluster1(); - boolean ok = true; - if(cl1.getType() == BMTType.Z || !skipBMTC){ - ok = fillMatricesNew(i,ray,cl1,A,B,V,m,c,I, this.debug, false); - } - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); - continue tracksLoop; - } - //} - } - continue; - } - - - } - if(!isCosmics && includeBeamspot) { - //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); - - - //pseudo cluster for the beamspot - Cluster cl1 = new Cluster(null, null, 0, 0, 0); - cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); - - Vector3D n = ray.getDirVec(); - Vector3D l = new Vector3D(0,0,1); - cl1.setN(n); - cl1.setL(l); - cl1.setS(n.cross(l)); - cl1.setResolution(0.6); - - fillMatricesNew(i, ray, cl1, A,B,V,m,c,I, this.debug, true); - - - } - } else { - Helix helix = track.getHelix(); - //curved tracks - for(Cross cross : track) { - if(useNewFillMatrices) { - if(cross.getDetector() == DetectorType.BST){ - Cluster cl1 = cross.getCluster1(); - boolean ok = fillMatricesNew(i,helix,cl1,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - Cluster cl2 = cross.getCluster2(); - ok = fillMatricesNew(i,helix,cl2,A,B,V,m,c,I,debug,false); - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in an SVT layer"); - continue tracksLoop; - } - } else { - Cluster cl1 = cross.getCluster1(); - boolean ok = true; - if(cl1.getType() == BMTType.Z || !skipBMTC){ - ok = fillMatricesNew(i,helix,cl1,A,B,V,m,c,I, this.debug, false); - } - i++; - if(!ok) { //reject track if there's a cluster with really bad values. - if(debug) System.out.println("rejecting track due to problem in a BMT"+ cl1.getType().name() + " layer"); - continue tracksLoop; - } - //} - } - } - - - } - if(!isCosmics && includeBeamspot) { - //fillMatricesBeamspot(i, ray, A,B,V,m,c,I, reader.getXbeam(), reader.getYbeam()); - - - //pseudo cluster for the beamspot - Cluster cl1 = new Cluster(null, null, 0, 0, 0); - cl1.setLine(new Line3D(reader.getXbeam(),reader.getYbeam(),-100, reader.getXbeam(),reader.getYbeam(),100)); - - Vector3D n = ray.getDirVec(); - Vector3D l = new Vector3D(0,0,1); - cl1.setN(n); - cl1.setL(l); - cl1.setS(n.cross(l)); - cl1.setResolution(0.6); - - fillMatricesNew(i, helix, cl1, A,B,V,m,c,I, this.debug, true); - - - } - } - As.add(A); - Bs.add(B); - Vs.add(V); - ms.add(m); - cs.add(c); - Is.add(I); - qs.add(q); - - - //c.print(7, 4); - //m.print(7, 4); - - trackIDs.add(track.getId()); - } - AlignmentBankWriter writer = new AlignmentBankWriter(); - writer.write_Matrix(event, "I", Is); - writer.write_Matrix(event, "A", As); - writer.write_Matrix(event, "B", Bs); - writer.write_Matrix(event, "V", Vs); - writer.write_Matrix(event, "m", ms); - writer.write_Matrix(event, "c", cs); - writer.write_Matrix(event, "q", qs); - fillMisc(event,runNum,eventNum,trackIDs,As,Bs,Vs,ms,cs,Is); - //event.show(); - - //only include events that have tracks that will be used in alignment - if(As.isEmpty()) - return false; - return true; - - } - private Helix createHelixFromRay(Ray ray) { - Vector3D u = ray.getDirVec(); - Vector3D xref = ray.getRefPoint().toVector3D(); - double phi = Math.atan2(u.y(),u.x()); - Vector3D uT = new Vector3D(Math.cos(phi), Math.sin(phi),0); - Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x(), u.y()); - double d = mscphi.dot(xref); - double curvature = 0; - double Z0 = xref.z()-u.z()*xref.dot(uT)/u.dot(uT); - double tandip = u.z()/Math.hypot(u.x(), u.y()); - return new Helix(d, phi, curvature, Z0, tandip, 0,0); - } - - int nAlignables; - - private Ray getRay(Helix h) { - - double d = h.getDCA(); - double z = h.getZ0(); - double phi = h.getPhiAtDCA(); - double td = h.getTanDip(); - double cd = 1/Math.hypot(td, 1); - double sd = td*cd; - double xb = h.getXb(); - double yb = h.getYb(); - //Vector3D u = new Vector3D(-cd*Math.sin(phi), cd*Math.cos(phi), sd); - //Point3D x = new Point3D(d*Math.cos(phi),d*Math.sin(phi), z); - Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); - - - Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); - //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); - - //System.out.println("xb yb from db" + xb + yb); - //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); - //if(u.y() <0) - // u = u.multiply(-1); - //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); - Ray ray = new Ray(x, u); - //System.out.println("doca " + d); - //System.out.println("td " + td); - - return ray; - } - - - - private double getDoca(Trajectory track) { - if(track instanceof StraightTrack) { - Ray ray = track.getRay(); - double intercept = ray.getYXInterc(); - double slope = ray.getYXSlope(); - return Math.abs(intercept)/Math.hypot(1, slope); - } else return track.getHelix().getDCA(); - } - - private void fillMisc(DataEvent event, int runNum, int eventNum, List trackIDs, - List As, List Bs, List Vs, List ms, List cs, - List is) { - DataBank bank = event.createBank("Align::misc", trackIDs.size()); - for(int i = 0; i spMax) { //this can only happen if the angle between the track and the normal is small - //System.out.println("rejecting track"); - return false; - } - int index = nAlignables-1; - - - //Use the same reference point for both inner and outer layer of region - //Vector3d cref = new Vector3d(0,0,0); - - - - //for debugging - /* - double phi1 = Math.atan2(n.y, n.x), phi2 = Math.atan2(cref.y, cref.x); - double dphi = phi1-phi2; - while (dphi < -Math.PI) - dphi += 2*Math.PI; - while (dphi > Math.PI) - dphi -= 2*Math.PI; - System.out.println(layer + " "+phi1 + " " + phi2 + " " + dphi); - */ - - //Vector3D dmdr =sp.cross(extrap); - //dmdr = dmdr.clone().sub(n.cross(u).multiply(n.dot(e.clone().sub(extrap))*sdotu/(udotn*udotn))); - /*A.set(i, (svtTopBottomSep? i : i/2)*6 + 0, -sp.x); - A.set(i, (svtTopBottomSep? i : i/2)*6 + 1, -sp.y); - A.set(i, (svtTopBottomSep? i : i/2)*6 + 2, -sp.z); - A.set(i, (svtTopBottomSep? i : i/2)*6 + 3, dmdr.x); - A.set(i, (svtTopBottomSep? i : i/2)*6 + 4, dmdr.y); - A.set(i, (svtTopBottomSep? i : i/2)*6 + 5, dmdr.z);*/ - - //System.out.println("i = " + i + "; rows = " + A.getRowDimension() + "; cols = " + + A.getColumnDimension()); - Vector3D dmdr = sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e))/udotn)); - if(orderTx >= 0) - A.set(i, i*nAlignVars + orderTx, sp.x()); - if(orderTy >= 0) - A.set(i, i*nAlignVars + orderTy, sp.y()); - if(orderTz >= 0) - A.set(i, i*nAlignVars + orderTz, sp.z()); - if(orderRx >= 0) - A.set(i, i*nAlignVars + orderRx, -dmdr.x()); - if(orderRy >= 0) - A.set(i, i*nAlignVars + orderRy, -dmdr.y()); - if(orderRz >= 0) - A.set(i, i*nAlignVars + orderRz, -dmdr.z()); - - - - I.set(i, 0, index); - - Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); - if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x()); - B.set(i,1, sp.z()); - B.set(i,2, dmdu.x()); - B.set(i,3, dmdu.z()); - } else { - - double phi = Math.atan2(u.y(),u.x()); - Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi),0); - Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x(), u.y()); - double d = mscphi.dot(xref); - B.set(i, 0, -sp.dot(mscphi)); - B.set(i, 1, -sp.dot(mscphi)*n.dot(e.clone().sub(xref))*cosdip/udotn+sp.dot(csphi)*d); - B.set(i, 2, -sp.z()); - B.set(i, 3, -sp.z()*n.dot(e.clone().sub(xref))/udotn); - - - } - //dm.set(i,0, s.dot(e.minus(extrap))); - - double ci = s.dot(extrap); - double mi = s.dot(e); - - - //System.out.println(extrap.toStlString()); - //System.out.println(e.toStlString()); - //System.out.println(extrap.minus(e).toStlString()); - //System.out.println(s.toStlString()); - - //if(Math.abs(ci-mi)>50) - // return false; - c.set(i,0,ci); - m.set(i,0,mi); - - return true; - } - - - private boolean fillMatricesNew(int i, Helix helix, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, - Matrix c, Matrix I, boolean debug, boolean isBeamspot) { - Vector3D u= helix.getTrackDirectionAtRadius(cl.getRadius()); - Point3D xref = helix.getPointAtRadius(cl.getRadius()); - Ray ray = new Ray(xref, u); - return fillMatricesNew(i, ray, cl, A, B, V, m, - c, I, debug, isBeamspot); - } - - /** - * generic method that uses any type of cluster. - * @param i - * @param ray - * @param cl - * @param A - * @param B - * @param V - * @param m - * @param c - * @param I - * @param string - * @return - */ - private boolean fillMatricesNew(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, - Matrix c, Matrix I, boolean debug, boolean isBeamspot) { - int layer = cl.getLayer(); - int sector = cl.getSector(); - //System.out.println("RLS " + region + " " + layer + " " + sector); - //System.out.println("th" + c.getPhi()); - Vector3D l; - Vector3D s; - Vector3D n; - - /*if(detector == DetectorType.BMT && bmtType==BMTType.C) { - Vector3D u = ray.getdirVec(); - double phi = Math.atan2(u.y(),u.x()); - System.out.println("prelim phi is " + phi + " sector= ="+cl.getSector()); - - }*/ - - DetectorType detector = cl.getDetector(); - BMTType bmtType = cl.getType(); - - if(debug) { - System.out.println("\n\nNew method " + detector + " layer " + layer + " sector " + sector); - - } - - - - - Vector3D xref = ray.getRefPoint().toVector3D(); - Vector3D u = ray.getDirVec(); - - - - - - - - - - //Vector3d e1 = cl.getX - Vector3D e = null; - Vector3D extrap = null; - if(detector == DetectorType.BST || (detector == DetectorType.BMT && bmtType==BMTType.Z) || isBeamspot) { - l = cl.getL(); - s = cl.getS(); - n = cl.getN(); - /* - e= new Vector3D(cl.getX1(),cl.getY1(),cl.getZ1()); - e= new Vector3D((cl.getX1()+cl.getX2())/2, - (cl.getY1()+cl.getY2())/2, - (cl.getZ1()+cl.getZ2())/2); - */ - e = cl.getLine().midpoint().toVector3D(); - - double udotn = u.dot(n); - extrap= xref.clone().add(u.multiply(n.dot(e.clone().sub(xref))/udotn)); - } - else { // BMTC - Vector3D a = cl.getArc().normal(); - - if(debug) - System.out.println("a: " +a); - Vector3D cc = cl.getArc().center().toVector3D(); - Vector3D uT = perp(u,a); - - Vector3D tmp1 = perp(xref.clone().sub(cc),a); - - Vector3D endpoint = cl.getArc().origin().toVector3D(); - - double R = perp(endpoint.clone().sub(cc),a).mag(); - if(debug) { - System.out.println("center: " + cc.toStringBrief()); - System.out.println("R: " + R); - } - double AA = uT.mag2(); - - - double BB = 2*tmp1.dot(uT); - double CC = tmp1.mag2()-R*R; - double lambda_plus = (-BB+Math.sqrt(BB*BB-4*AA*CC))/(2*AA); - double lambda_minus = (-BB-Math.sqrt(BB*BB-4*AA*CC))/(2*AA); - Vector3D extrap_plus = xref.clone().add(u.multiply(lambda_plus)); - Vector3D extrap_minus = xref.clone().add(u.multiply(lambda_minus)); - - if(debug) { - System.out.println("extrap is on cylinder: this should be zero: " + (perp(extrap_plus.clone().sub(cc),a).mag()-R)); - } - - /*double phi_mid = cl.get_Arc().origin().midpoint(cl.get_Arc().end()).toVector3D().phi(); - double delta_phi_plus=extrap_plus.phi()-phi_mid; - while (delta_phi_plus >Math.PI) - delta_phi_plus-=2*Math.PI; - while (delta_phi_plus <-Math.PI) - delta_phi_plus+=2*Math.PI; - - double delta_phi_minus=extrap_minus.phi()-phi_mid; - while (delta_phi_minus >Math.PI) - delta_phi_minus-=2*Math.PI; - while (delta_phi_minus <-Math.PI) - delta_phi_minus+=2*Math.PI;*/ - /*double phi_n = cl.getN().phi(); - System.out.println("phi_recon="+ phi_n); - System.out.println("phi_+="+ extrap_plus.phi()); - System.out.println("phi_-="+ extrap_minus.phi()); - double delta_phi_plus=extrap_plus.phi()-phi_n; - while (delta_phi_plus >Math.PI) - delta_phi_plus-=2*Math.PI; - while (delta_phi_plus <-Math.PI) - delta_phi_plus+=2*Math.PI; - - double delta_phi_minus=extrap_minus.phi()-phi_n; - while (delta_phi_minus >Math.PI) - delta_phi_minus-=2*Math.PI; - while (delta_phi_minus <-Math.PI) - delta_phi_minus+=2*Math.PI; - - if(Math.abs(delta_phi_plus) spMax) { //this can only happen if the angle between the track and the normal is small - if(debug) System.out.println("rejecting track: sp.magnitude() > "+spMax); - return false; - } - - - - //Vector3D cref = new Vector3D(0,0,0); - - - - - - //Vector3D dmdr =sp.cross(extrap).add(n.cross(cref).multiply(sdotu/udotn)); - //dmdr = dmdr.sub(n.cross(u).multiply(n.dot(e.clone().sub(extrap))*sdotu/(udotn*udotn))); - Vector3D dmdr =sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e))/udotn)); - - if(orderTx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, sp.x()); - if(orderTy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, sp.y()); - if(orderTz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, sp.z()); - if(orderRx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, -dmdr.x()); - if(orderRy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, -dmdr.y()); - if(orderRz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, -dmdr.z()); - - - if(detector == DetectorType.BST) - I.set(i, 0, getIndexSVT(layer-1,sector-1)); - else if(detector == DetectorType.BMT) - I.set(i, 0, getIndexBMT(layer-1,sector-1)); - else - I.set(i, 0, indexBeamspot ); - Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n)/udotn); - if(!this.useDocaPhiZTandip) { - B.set(i,0, -sp.x()); - B.set(i,1, -sp.z()); - B.set(i,2, -dmdu.x()); - B.set(i,3, -dmdu.z()); - } else { - - double phi = Math.atan2(u.y(),u.x()); - /*if(detector == DetectorType.BMT && bmtType==BMTType.C) { - System.out.println("phi is " + phi); - }*/ - Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi),0); - Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x(), u.y()); - double d = mscphi.dot(xref); - B.set(i, 0, -sp.dot(mscphi)); - B.set(i, 1, -sp.dot(mscphi)*n.dot(e.clone().sub(xref))*cosdip/udotn+sp.dot(csphi)*d); - B.set(i, 2, -sp.z()); - B.set(i, 3, -sp.z()*n.dot(e.clone().sub(xref))/udotn); - - - } - //dm.set(i,0, s.dot(e.minus(extrap))); - - double ci = s.dot(extrap); - double mi = s.dot(e); - - c.set(i,0,ci); - m.set(i,0,mi); - if(debug) { - System.out.println("n.(e-xref): "+ n.dot(e.clone().sub(xref))); - System.out.println("u.n: "+ udotn); - System.out.println("s: " + s.toString()); - System.out.println("sp: " + sp.toString()); - System.out.println("extrap: " + extrap.toString()); - System.out.println("n: " + n.toString()); - System.out.println("e: " + e.toString()); - System.out.println("xref: " + xref.toString()); - System.out.println("u: " + u.toString()); - System.out.println("m: " + mi); - System.out.println("c: " + ci); - } - if(Math.abs(ci-mi)>maxResidualCutSVT && detector == DetectorType.BST || - Math.abs(ci-mi)>maxResidualCutBMTZ && detector == DetectorType.BMT && bmtType==BMTType.Z || - Math.abs(ci-mi)>maxResidualCutBMTC && detector == DetectorType.BMT && bmtType==BMTType.C) { - if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); - return false; - } - return true; - - } - Vector3D perp(Vector3D v, Vector3D a) { - return v.clone().sub(a.multiply(v.dot(a))); - } - - /* - //returns false if there's a problem - private boolean fillMatricesSVT(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, Matrix I) { - int region = cl.getRegion(); - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); - //System.out.println("RLS " + region + " " + layer + " " + sector); - //System.out.println("th" + c.get_Phi()); - double centroid = cl.get_Centroid(); - - // this avoids a certain bug that only occurs if - // there is a single-hit cluster on the last strip, - // in which obtaining the next strip (line2) gives - // an IllegalArgumentException - - - if(centroid == SVTConstants.NSTRIPS) - centroid = SVTConstants.NSTRIPS-.001; - Line3d line1 = SVTGeom.getStripFactory().getShiftedStrip(layer-1, sector-1, (int)Math.floor(centroid)-1); - Line3d line2 = SVTGeom.getStripFactory().getShiftedStrip(layer-1, sector-1, (int)Math.floor(centroid)-0); - - //System.out.println( SVTConstants.getLayerSectorAlignmentData()[0][0][1]); - - - //take the weighted average of the directions of the two lines. - Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); - - Vector3d e1 = line1.origin(); - Vector3d e2 = line2.origin(); - Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); - Vector3d s = e2.minus(e1); - s = s.minus(l.times(s.dot(l))).normalized(); - - Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); - Vector3d u = convertVector(ray.getDirVec()); - Vector3d n = l.cross(s); - double udotn = u.dot(n); - if(Math.abs(udotn)<0.01) { - if(debug) System.out.println("rejecting track: abs(udotn)<0.01"); - return false; - } - double sdotu = s.dot(u); - Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - - - //System.out.println(extrap.toStlString()); - double resolution = cl.getResolutionAlongZ(extrap.z-SVTConstants.Z0ACTIVE[(layer-1)/2], SVTGeom); - //System.out.println("resolution: " + resolution + "; z=" + extrap.z-); - - V.set(i, i, Math.pow(resolution,2)); - - - Vector3d sp = s.minus(n.times(sdotu/udotn)); - if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small - if(debug) System.out.println("rejecting track: sp.magnitude() > 10"); - return false; - } - int index = getIndexSVT(layer-1, sector-1); - - - //Use the same reference point for both inner and outer layer of region - Vector3d cref = getModuleReferencePoint(sector,layer); - - - - - - Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); - dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); - - if(orderTx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTx, -sp.x); - if(orderTy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTy, -sp.y); - if(orderTz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderTz, -sp.z); - if(orderRx >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRx, dmdr.x); - if(orderRy >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRy, dmdr.y); - if(orderRz >= 0) - A.set(i, (svtTopBottomSep? i : i/2)*nAlignVars + orderRz, dmdr.z); - - - - I.set(i, 0, index); - - Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); - if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x); - B.set(i,1, sp.z); - B.set(i,2, dmdu.x); - B.set(i,3, dmdu.z); - } else { - - double phi = Math.atan2(u.y,u.x); - Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); - Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x, u.y); - double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); - //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) - // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) - // .plus(u.times(d*n.dot(csphi)/udotn))) - // ); - B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) - + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z-sdotu*n.z/udotn); - B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); - - - } - //dm.set(i,0, s.dot(e.minus(extrap))); - - double ci = s.dot(extrap); - double mi = s.dot(e); - if(Math.abs(ci-mi)>maxResidualCutSVT) { - if(debug) System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); - return false; - } - c.set(i,0,ci); - m.set(i,0,mi); - - System.out.println("\nold method"); - System.out.println("n.(e-xref): "+ n.dot(e.minus(xref))); - System.out.println("u.n: "+ udotn); - System.out.println("s: " + s.toString()); - System.out.println("sp: " + sp.toString()); - System.out.println("extrap: " + extrap.toString()); - System.out.println("n: " + n.toString()); - System.out.println("e: " + e.toString()); - System.out.println("xref: " + xref.toString()); - System.out.println("u: " + u.toString()); - - - return true; - - }*/ - boolean debug = false; - private int minClustersSVT = 0; - private int minClustersBMTC = 0; - private int minClustersBMTZ = 0; - //private SVTGeometry SVTGeom; - - /* - private boolean fillMatricesBMTZ(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, - Matrix I) { - int region = cl.getRegion(); - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); - double centroid = cl.get_Centroid(); - //Z layer - //if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]) - // centroid = org.jlab.rec.cvt.bmt.Constants.getCRZNSTRIPS()[region-1]-.001; - Line3d line1 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid), null)); - Line3d line2 = convertLine(BMTGeom.getLCZstrip(region, sector, (int)Math.floor(centroid)+1, null)); - - - - Vector3d l = line1.diff().normalized();//.times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); - - Vector3d e1 = line1.origin(); - Vector3d e2 = line2.origin(); - Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); - Vector3d s = e2.minus(e1); - s = s.minus(l.times(s.dot(l))).normalized(); - - - Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); - Vector3d u = convertVector(ray.getDirVec()); - Vector3d n = l.cross(s); - double udotn = u.dot(n); - if(Math.abs(udotn)<0.01) - return false; - double sdotu = s.dot(u); - - Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - //org.jlab.rec.cvt.bmt.Constants. - //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - - //System.out.println(extrap.toStlString()); - double resolution = e1.distance(e2)/Math.sqrt(12); - - - V.set(i, i, Math.pow(resolution,2)); - - - Vector3d sp = s.minus(n.times(sdotu/udotn)); - if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small - System.out.println("rejecting track"); - return false; - } - int index = getIndexBMT(layer-1, sector-1); - - - //Use the same reference point for both inner and outer layer of region - Vector3d cref = getModuleReferencePoint(sector,layer); - - - - - Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); - dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); - - if(orderTx >= 0) - A.set(i, i*nAlignVars + orderTx, -sp.x); - if(orderTy >= 0) - A.set(i, i*nAlignVars + orderTy, -sp.y); - if(orderTz >= 0) - A.set(i, i*nAlignVars + orderTz, -sp.z); - if(orderRx >= 0) - A.set(i, i*nAlignVars + orderRx, dmdr.x); - if(orderRy >= 0) - A.set(i, i*nAlignVars + orderRy, dmdr.y); - if(orderRz >= 0) - A.set(i, i*nAlignVars + orderRz, dmdr.z); - - - - I.set(i, 0, index); - - Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); - if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x); - B.set(i,1, sp.z); - B.set(i,2, dmdu.x); - B.set(i,3, dmdu.z); - } else { - - double phi = Math.atan2(u.y,u.x); - Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); - Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x, u.y); - double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); - //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) - // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) - // .plus(u.times(d*n.dot(csphi)/udotn))) - // ); - B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(e.minus(xref)) - + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z-sdotu*n.z/udotn); - B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(e.minus(xref))); - - - } - //dm.set(i,0, s.dot(e.minus(extrap))); - //c.set(i,0,s.dot(extrap)); - //m.set(i,0,s.dot(e)); - double mi = e1.distance(e2)*centroid; - double ci = mi+s.dot(extrap.minus(e)); - m.set(i, 0, mi); - - c.set(i, 0, ci); - - //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - - System.out.println("\nold method"); - System.out.println("n.(e-xref): "+ n.dot(e.minus(xref))); - System.out.println("u.n: "+ udotn); - System.out.println("s: " + s.toString()); - System.out.println("sp: " + sp.toString()); - System.out.println("extrap: " + extrap.toString()); - System.out.println("n: " + n.toString()); - System.out.println("e: " + e.toString()); - System.out.println("xref: " + xref.toString()); - System.out.println("u: " + u.toString()); - System.out.println("m: " + mi); - System.out.println("c: " + ci); - if(Math.abs(ci-mi)>maxResidualCutBMTZ) - return false; - - return true; - - } - private boolean fillMatricesBMTC(int i, Ray ray, Cluster cl, Matrix A, Matrix B, Matrix V, Matrix m, Matrix c, - Matrix I) { - - System.out.println("\nOld method BMTC"); - int region = cl.getRegion(); - int layer = cl.get_Layer(); - int sector = cl.get_Sector(); - //System.out.println(region+" "+layer +" "+sector); - double centroid = cl.get_Centroid(); - if(centroid == org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]) - centroid = org.jlab.rec.cvt.bmt.Constants.getCRCNSTRIPS()[region-1]-.001; - - Vector3d xref = convertVector(ray.getRefPoint().toVector3D()); - Vector3d u = convertVector(ray.getDirVec()); - - Arc3D arc1 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-1); - Arc3D arc2 = BMTGeom.getCstrip(region, sector, (int)Math.floor(centroid)-0); - - //find the extrapolation point to the cylinder - double R = arc1.radius(); - //cylindrical axis - Vector3d axis = convertVector(arc1.normal()); - Vector3d center = convertVector(arc1.center().toVector3D()); - double a = 1-Math.pow(u.dot(axis),2); - double b = 2*center.minus(xref).dot(u.minus(axis.times(axis.dot(u)))); - double cc = xref.minus(center).minus(axis.times(axis.dot(xref.minus(center)))).magnitudeSq()-R*R; - // two intersections between line and cylinder. Whichever is closest to the midpoint of the strip - // is chosen - double lambda = (-b+Math.sqrt(b*b-4*a*cc))/(2*a); - double lambda_alt = (-b-Math.sqrt(b*b-4*a*cc))/(2*a); - Vector3d extrap1 = xref.plus(u.times(lambda)); - Vector3d extrap2 = xref.plus(u.times(lambda_alt)); - Vector3d midpoint = midpoint(arc1).midpoint(midpoint(arc2)); - Vector3d extrap = null; - if(extrap1.distance(midpoint) > (extrap2.distance(midpoint))) - extrap = extrap2; - else - extrap = extrap1; - - Vector3d s = axis; - Vector3d n = extrap.minus(center); - n = n.minus(axis.times(axis.dot(n))).normalized(); - Vector3d l = s.cross(n); - - - //System.out.printf("s vector %f %f %f\n", s.x,s.y,s.z); - //System.out.printf("n vector %f %f %f\n", n.x,n.y,n.z); - //System.out.printf("l vector %f %f %f\n", l.x,l.y,l.z); - //Vector3d l = line1.diff().normalized().times(1-(centroid%1)).add(line2.diff().normalized().times((centroid%1))).normalized(); - - Vector3d e1 = convertVector(arc1.origin().toVector3D()); - Vector3d e2 = convertVector(arc2.origin().toVector3D()); - Vector3d e = e1.times(1-(centroid%1)).add(e2.times((centroid%1))); - //Vector3d s = e2.minus(e1); - //s = s.minus(l.times(s.dot(l))).normalized(); - - - - double udotn = u.dot(n); - if(Math.abs(udotn)<0.01) - return false; - double sdotu = s.dot(u); - - - //org.jlab.rec.cvt.bmt.Constants. - //Vector3d extrap = xref.plus(u.times(n.dot(e.minus(xref))/udotn)); - - //System.out.println(extrap.toStlString()); - - - double resolution = e1.distance(e2)/Math.sqrt(12); - //fake resolution - resolution = 1; - V.set(i, i, Math.pow(resolution,2)); - - - Vector3d sp = s.minus(n.times(sdotu/udotn)); - if(sp.magnitude() > 10) { //this can only happen if the angle between the track and the normal is small - System.out.println("rejecting track"); - return false; - } - int index = getIndexBMT(layer-1, sector-1); - - - //Use the same reference point for both inner and outer layer of region - Vector3d cref = getModuleReferencePoint(sector,layer); - - Vector3d dmdr =sp.cross(extrap).plus(n.cross(cref).times(sdotu/udotn)); - dmdr = dmdr.minus(n.cross(u).times(n.dot(e.minus(extrap))*sdotu/(udotn*udotn))); - if(orderTx >= 0) - A.set(i, i*nAlignVars + orderTx, -sp.x); - if(orderTy >= 0) - A.set(i, i*nAlignVars + orderTy, -sp.y); - if(orderTz >= 0) - A.set(i, i*nAlignVars + orderTz, -sp.z); - if(orderRx >= 0) - A.set(i, i*nAlignVars + orderRx, dmdr.x); - if(orderRy >= 0) - A.set(i, i*nAlignVars + orderRy, dmdr.y); - if(orderRz >= 0) - A.set(i, i*nAlignVars + orderRz, dmdr.z); - - - - I.set(i, 0, index); - - Vector3d dmdu = sp.times(e.minus(xref).dot(n)/udotn); - if(!this.useDocaPhiZTandip) { - B.set(i,0, sp.x); - B.set(i,1, sp.z); - B.set(i,2, dmdu.x); - B.set(i,3, dmdu.z); - } else { - - double phi = Math.atan2(u.y,u.x); - Vector3d csphi = new Vector3d(Math.cos(phi), Math.sin(phi),0); - Vector3d mscphi = new Vector3d(-Math.sin(phi), Math.cos(phi),0); - double cosdip = Math.hypot(u.x, u.y); - double d = mscphi.dot(xref); - B.set(i, 0, s.dot(mscphi.minus(u.times(n.dot(mscphi)/udotn)))); - //B.set(i, 1, s.dot(csphi.times(-d) - // .plus(mscphi.times(n.dot(e.minus(xref))/udotn)) - // .minus(u.times(mscphi.dot(n)*n.dot(e.minus(xref))/(udotn*udotn))) - // .plus(u.times(d*n.dot(csphi)/udotn))) - // ); - B.set(i, 1, -s.dot(csphi)*d - + cosdip*(s.dot(mscphi)/udotn-sdotu/(udotn*udotn)*n.dot(mscphi))*n.dot(extrap.minus(xref)) - + sdotu/udotn*d*n.dot(csphi)); - B.set(i, 2, s.z-sdotu*n.z/udotn); - B.set(i, 3, (s.z/udotn-n.z*sdotu/(udotn*udotn))*n.dot(extrap.minus(xref))); - - - } - //dm.set(i,0, s.dot(e.minus(extrap))); - double ci = s.dot(extrap); - double mi = s.dot(e); - if(debug) { - System.out.println("m: " + mi); - System.out.println("c: " + ci); - } - - if(Math.abs(ci-mi)>maxResidualCutBMTC) - return false; - c.set(i,0,ci); - m.set(i,0,mi); - - - - return true; - }*/ - - /*private Vector3d midpoint(Arc3D arc1) { - - return convertVector(arc1.point(arc1.theta()/2).toVector3D()); - }*/ - - /*private int getIndex(Cluster c) { - int layer = c.get_Layer()-1; - int sector = c.get_Sector()-1; - int index = -1; - if(c.get_Detector() == DetectorType.BST) { - int region = layer/2; - if (region == 0) - index = sector; - else if (region == 1) - index = SVTGeometry.NSECTORS[0] + sector; - else if (region == 2) - index =SVTGeometry.NSECTORS[0] + - SVTGeometry.NSECTORS[2] + sector; - if(svtTopBottomSep && layer%2==1) { - index += 42; - } - } else if (c.get_Detector() == DetectorType.BMT) { - index = 84+layer*3+sector; - } - - return index; - }*/ - - private int getIndexBMT(int layer, int sector) { - if (layer < 0 || sector < 0) - return -1; - return 84+layer*3+sector; - } - - private int getIndexSVT(int layer, int sect){ - int index = -1; - int region = layer/2; - if (region == 0) - index = sect; - else if (region == 1) - index = SVTGeometry.NSECTORS[0] + sect; - else if (region == 2) - index = SVTGeometry.NSECTORS[0] + - SVTGeometry.NSECTORS[2] + sect; - if(svtTopBottomSep && layer%2==1) { - index += 42; - } - return index; - - } - - /*private Vector3d getModuleReferencePoint(int sector, int layer) { - //return SVTAlignmentFactory.getIdealFiducialCenter((layer-1)/2, sector-1); - return new Vector3d(0,0,0); - }*/ - - @Override - public boolean init() { - if(this.getEngineConfiguration() == null || "null".equals(this.getEngineConfiguration())) { - return true; //prevents init from being run twice. - } - - //svt stand-alone - String svtStAl = this.getEngineConfigString("svtOnly"); - - if (svtStAl!=null) { - System.out.println("["+this.getName()+"] align SVT only "+svtStAl+" config chosen based on yaml"); - this.isSVTonly= Boolean.valueOf(svtStAl); - } - else { - svtStAl = System.getenv("COAT_ALIGN_SVT_ONLY"); - if (svtStAl!=null) { - System.out.println("["+this.getName()+"] align SVT only "+svtStAl+" config chosen based on env"); - this.isSVTonly= Boolean.valueOf(svtStAl); - } - } - if (svtStAl==null) { - System.out.println("["+this.getName()+"] align SVT only (default) "); - this.isSVTonly = true; - } - - String bmtOnly = this.getEngineConfigString("bmtOnly"); - - if (bmtOnly!=null) { - System.out.println("["+this.getName()+"] align BMT only "+bmtOnly+" config chosen based on yaml"); - this.isBMTonly= Boolean.valueOf(bmtOnly); - } - else { - bmtOnly = System.getenv("COAT_ALIGN_SVT_ONLY"); - if (bmtOnly!=null) { - System.out.println("["+this.getName()+"] align BMT only "+bmtOnly+" config chosen based on env"); - this.isBMTonly= Boolean.valueOf(bmtOnly); - } - } - if (bmtOnly==null) { - System.out.println("["+this.getName()+"] not BMT only (default) "); - this.isBMTonly = false; - } - - String skipBMTC = this.getEngineConfigString("skipBMTC"); - - if (skipBMTC!=null) { - System.out.println("["+this.getName()+"] skip BMTC? "+skipBMTC+" config chosen based on yaml"); - this.isBMTonly= Boolean.valueOf(skipBMTC); - } - - - - variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); - System.out.println(" CVT YAML VARIATION NAME + "+variationName); - - System.out.println("SVT LOADING WITH VARIATION "+variationName); - /*DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); - //cp = new HackConstantsProvider(cp); - cp = SVTConstants.connect( cp ); - cp.disconnect(); - CCDBConstantsLoader.Load(new DatabaseConstantProvider(11, variationName)); - xb = org.jlab.rec.cvt.Constants.getXb(); - yb = org.jlab.rec.cvt.Constants.getYb();*/ - //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][0])); - //System.out.println("Check SVT Geom lay1 sec1: " + Arrays.toString(SVTConstants.getLayerSectorAlignmentData()[0][1])); - //SVTStripFactory svtFac = new SVTStripFactory(cp, true); - //SVTGeom = new SVTGeometry(svtFac); - - String svtTopBottomSep = this.getEngineConfigString("svtAlignTopBottomSeparately"); - if (svtTopBottomSep!=null) { - System.out.println("["+this.getName()+"] run with SVT alignment for top and bottom as separate modules "+svtTopBottomSep+" config chosen based on yaml"); - this.svtTopBottomSep= Boolean.valueOf(svtTopBottomSep); - } - else { - svtTopBottomSep = System.getenv("COAT_SVT_TOP_BOTTOM"); - if (svtTopBottomSep!=null) { - System.out.println("["+this.getName()+"] run with SVT alignment for top and bottom as separate modules "+svtTopBottomSep+" config chosen based on env"); - this.svtTopBottomSep= Boolean.valueOf(svtTopBottomSep); - } - } - if (svtTopBottomSep==null) { - System.out.println("["+this.getName()+"] run with SVT top and bottom as separate modules (default) "); - this.svtTopBottomSep = true; - } - - String alignVars = this.getEngineConfigString("alignVariables"); - if (alignVars!=null) { - System.out.println("["+this.getName()+"] obtain alignment derivatives for the following variables "+svtTopBottomSep+" config chosen based on yaml"); - this.setAlignVars(alignVars); - } - else { - alignVars = System.getenv("COAT_ALIGN_VARS"); - if (alignVars!=null) { - System.out.println("["+this.getName()+"] obtain alignment derivatives for the following variables "+svtTopBottomSep+" config chosen based on env"); - this.setAlignVars(alignVars); - } - } - if (alignVars==null) { - System.out.println("["+this.getName()+"] obtain alignment derivatives for all 6 variables (default) "); - this.setAlignVars("Tx Ty Tz Rx Ry Rz"); - } - - String cosmics = this.getEngineConfigString("cosmics"); - - if(cosmics != null) { - System.out.println("["+this.getName()+"] use cosmics bank instead of tracks bank? "+ cosmics ); - this.isCosmics = Boolean.parseBoolean(cosmics); - } - else { - System.out.println("["+this.getName()+"] using tracks bank (default)"); - this.isCosmics = false; - } - - - String maxDocaCut = this.getEngineConfigString("maxDocaCut"); - - if(maxDocaCut != null) { - System.out.println("["+this.getName()+"] max doca cut "+ maxDocaCut + " mm"); - this.maxDocaCut = Double.parseDouble(maxDocaCut); - } - else { - if (isCosmics) { - System.out.println("["+this.getName()+"] no max doca cut set (default for cosmics)"); - this.maxDocaCut = Double.MAX_VALUE; - } else { - System.out.println("["+this.getName()+"] doca cut set to 10 mm (default for field-off tracks)"); - this.maxDocaCut = 10; - } - } - - - String maxResidual = this.getEngineConfigString("maxResidual"); - - if (maxResidual!=null) { - System.out.println("["+this.getName()+"] run with cut on maximum residual "+maxResidual+" config chosen based on yaml"); - this.maxResidualCutBMTZ = this.maxResidualCutBMTC = this.maxResidualCutSVT = Double.valueOf(maxResidual); - } - - if (maxResidual==null) { - System.out.println("["+this.getName()+"] run with maximum residual cut setting default = none"); - this.maxResidualCutBMTC = Double.MAX_VALUE; - this.maxResidualCutBMTZ = Double.MAX_VALUE; - this.maxResidualCutSVT = Double.MAX_VALUE; - } - - maxResidual = this.getEngineConfigString("maxResidualBMTZ"); - - if (maxResidual!=null) { - System.out.println("["+this.getName()+"] run with cut on maximum BMTZ residual "+maxResidual+" config chosen based on yaml"); - this.maxResidualCutBMTZ = Double.valueOf(maxResidual); - } - - maxResidual = this.getEngineConfigString("maxResidualBMTC"); - - if (maxResidual!=null) { - System.out.println("["+this.getName()+"] run with cut on maximum BMTC residual "+maxResidual+" config chosen based on yaml"); - this.maxResidualCutBMTC = Double.valueOf(maxResidual); - } - - maxResidual = this.getEngineConfigString("maxResidualSVT"); - - if (maxResidual!=null) { - System.out.println("["+this.getName()+"] run with cut on maximum SVT residual "+maxResidual+" config chosen based on yaml"); - this.maxResidualCutSVT = Double.valueOf(maxResidual); - } - - String minClusters = this.getEngineConfigString("minClustersSVT"); - - if (minClusters!=null) { - System.out.println("["+this.getName()+"] run with cut on minimum SVT clusters "+minClusters+" config chosen based on yaml"); - this.minClustersSVT = Integer.valueOf(minClusters); - } - - minClusters = this.getEngineConfigString("minClustersBMTZ"); - - if (minClusters!=null) { - System.out.println("["+this.getName()+"] run with cut on minimum BMTZ clusters "+minClusters+" config chosen based on yaml"); - this.minClustersBMTZ = Integer.valueOf(minClusters); - } - - minClusters = this.getEngineConfigString("minClustersBMTC"); - - if (minClusters!=null) { - System.out.println("["+this.getName()+"] run with cut on minimum BMTZ clusters "+minClusters+" config chosen based on yaml"); - this.minClustersBMTC = Integer.valueOf(minClusters); - } - - /*for(int layer = 0; layer<6; layer++) - { - Line3d line = SVTGeometry.getStrip(layer, 0, 0); - System.out.println("debug. Layer" + layer + " (" + line.origin().x + ", "+ line.origin().y + ", "+ line.origin().z+"), " - + " (" + line.end().x + ", "+ line.end().y + ", "+ line.end().z+"), "); - }*/ - - String useBeamspotStr = this.getEngineConfigString("useBeamspot"); - - if (useBeamspotStr!=null) { - System.out.println("["+this.getName()+"] treat beamspot as an additional measurement "+useBeamspotStr+" config chosen based on yaml"); - this.includeBeamspot = Boolean.valueOf(useBeamspotStr); - } else{ - System.out.println("["+this.getName()+"] treat beamspot as an additional measurement false [default]"); - - } - - this.nAlignables = ((this.svtTopBottomSep ? 2*42 : 42) + (this.isSVTonly ? 0: 18) + (includeBeamspot? 1 : 0)); - - - String debug = this.getEngineConfigString("debug"); - - if (debug!=null) { - System.out.println("["+this.getName()+"] debug "+debug+" config chosen based on yaml"); - this.debug = Boolean.parseBoolean(debug); - } else { - System.out.println("["+this.getName()+"] debug false; config chosen based on yaml"); - this.debug = false; - } - - String curvedTracks=this.getEngineConfigString("curvedTracks"); - if (curvedTracks!=null) { - System.out.println("["+this.getName()+"] curvedTracks "+curvedTracks+" config chosen based on yaml"); - this.curvedTracks = Boolean.parseBoolean(curvedTracks); - } else { - System.out.println("["+this.getName()+"] curvedTracks false; config chosen based on yaml"); - this.curvedTracks = false; - } - //MagneticFields.getInstance().getSolenoid().setScaleFactor(1e-7); - - return true; - } - - //double xb, yb; - - double maxResidualCutSVT; - double maxResidualCutBMTC; - double maxResidualCutBMTZ; - - double maxDocaCut; - - - - private void setAlignVars(String alignVars) { - orderTx = -1; - orderTy = -1; - orderTz = -1; - orderRx = -1; - orderRy = -1; - orderRz = -1; - if(alignVars.length() >2 && !alignVars.contains(" ")) { - for(int i = 0;i tracks; + if(isCosmics) { + tracks = reader.getCosmics(event); + } + else { + tracks = reader.getTracks(event); + } + if (tracks==null || tracks.size() > 2) return true; + + + List Is = new ArrayList<>(); + List As = new ArrayList<>(); + List Bs = new ArrayList<>(); + List Vs = new ArrayList<>(); + List ms = new ArrayList<>(); + List cs = new ArrayList<>(); + List qs = new ArrayList<>(); + List trackIDs = new ArrayList<>(); + + + tracksLoop : for (Trajectory track : tracks) { + + if(Math.abs(getDoca(track))>maxDocaCut) + continue; + + int nCrossSVT = 0, nCrossBMT = 0; + int countBMTZ = 0, countBMTC = 0; + for(Cross c : track) { + if (c.getDetector() == DetectorType.BST && !isBMTonly) { + nCrossSVT++; + gCountSVT++; + } + if (c.getDetector() == DetectorType.BMT && !isSVTonly) { + if (c.getCluster1().getType() != BMTType.C || !skipBMTC) { + nCrossBMT++; + } + if (c.getCluster1().getType() == BMTType.C) { + countBMTC++; + gCountBMTC++; + } + if (c.getCluster1().getType() == BMTType.Z) { + gCountBMTZ++; + countBMTZ++; + } + //System.out.println(c.getSector()+" "+c.getRegion() + " " + c.getCluster1().getCentroid()+" " + c.getId()); + } + if (nCrossBMT > 12) { + System.out.println("Too many BMT crosses!"); + return false; + } + } + + + if(nCrossSVT*20.001 && !curvedTracks) { + continue; + } + } + + int paramsFromBeamspot = (isCosmics || ! includeBeamspot ? 0:1); + int cols = nAlignVars*((svtTopBottomSep ? 2*nCrossSVT : nCrossSVT) + nCrossBMT + paramsFromBeamspot); + int rows = 2*nCrossSVT+nCrossBMT + paramsFromBeamspot; + + SimpleMatrix A = new SimpleMatrix(rows, cols);//not sure why there aren't 6 columns + SimpleMatrix B = new SimpleMatrix(rows, 4); + SimpleMatrix V = new SimpleMatrix(rows,rows); + SimpleMatrix m = new SimpleMatrix(rows,1); + SimpleMatrix c = new SimpleMatrix(rows,1); + SimpleMatrix I = new SimpleMatrix(rows,1); + SimpleMatrix q = new SimpleMatrix(4, 1); //track parameters, for plotting kinematic dependence. Not used in KFA. + + if (track.getHelix() == null) { + track.setHelix(createHelixFromRay(track.getRay())); + } + + q.set(0, 0, track.getHelix().getDCA()); + q.set(1, 0, track.getHelix().getPhiAtDCA()); + q.set(2, 0, track.getHelix().getZ0()); + q.set(3, 0, track.getHelix().getTanDip()); + + if(debug) { + System.out.println("track parameters"); + q.print(); + } + + int i = 0; + if(!curvedTracks) { + for (Cross cross : track) { + if (useNewFillMatrices) { + if (cross.getDetector() == DetectorType.BST) { + Cluster cl1 = cross.getCluster1(); + boolean ok = fillMatricesNew(i, ray, cl1, A, B, V, m, c, I, debug, false); + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in an SVT layer"); + } + continue tracksLoop; + } + Cluster cl2 = cross.getCluster2(); + ok = fillMatricesNew(i, ray, cl2, A, B, V, m, c, I, debug, false); + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in an SVT layer"); + } + continue tracksLoop; + } + } else { + Cluster cl1 = cross.getCluster1(); + boolean ok = true; + if (cl1.getType() == BMTType.Z || !skipBMTC) { + ok = fillMatricesNew(i, ray, cl1, A, B, V, m, c, I, this.debug, false); + } + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in a BMT" + cl1.getType().name() + " layer"); + } + continue tracksLoop; + } + //} + } + continue; + } + + } + if (!isCosmics && includeBeamspot) { + + //pseudo cluster for the beamspot + Cluster cl1 = new Cluster(null, null, 0, 0, 0); + cl1.setLine(new Line3D(track.getHelix().getXb(), track.getHelix().getYb(), -100, track.getHelix().getXb(), track.getHelix().getYb(), 100)); + + Vector3D n = ray.getDirVec(); + Vector3D l = new Vector3D(0, 0, 1); + cl1.setN(n); + cl1.setL(l); + cl1.setS(n.cross(l)); + cl1.setResolution(0.6); + + fillMatricesNew(i, ray, cl1, A, B, V, m, c, I, this.debug, true); + + } + } + else { + Helix helix = track.getHelix(); + //curved tracks + for (Cross cross : track) { + if (useNewFillMatrices) { + if (cross.getDetector() == DetectorType.BST) { + Cluster cl1 = cross.getCluster1(); + boolean ok = fillMatricesNew(i, helix, cl1, A, B, V, m, c, I, debug, false); + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in an SVT layer"); + } + continue tracksLoop; + } + Cluster cl2 = cross.getCluster2(); + ok = fillMatricesNew(i, helix, cl2, A, B, V, m, c, I, debug, false); + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in an SVT layer"); + } + continue tracksLoop; + } + } else { + Cluster cl1 = cross.getCluster1(); + boolean ok = true; + if (cl1.getType() == BMTType.Z || !skipBMTC) { + ok = fillMatricesNew(i, helix, cl1, A, B, V, m, c, I, this.debug, false); + } + i++; + if (!ok) { //reject track if there's a cluster with really bad values. + if (debug) { + System.out.println("rejecting track due to problem in a BMT" + cl1.getType().name() + " layer"); + } + continue tracksLoop; + } + //} + } + } + + } + if(!isCosmics && includeBeamspot) { + + //pseudo cluster for the beamspot + Cluster cl1 = new Cluster(null, null, 0, 0, 0); + cl1.setLine(new Line3D(track.getHelix().getXb(), track.getHelix().getYb(), -100, track.getHelix().getXb(), track.getHelix().getYb(), 100)); + + Vector3D n = ray.getDirVec(); + Vector3D l = new Vector3D(0,0,1); + cl1.setN(n); + cl1.setL(l); + cl1.setS(n.cross(l)); + cl1.setResolution(0.6); + + fillMatricesNew(i, helix, cl1, A,B,V,m,c,I, this.debug, true); + + + } + } + As.add(A); + Bs.add(B); + Vs.add(V); + ms.add(m); + cs.add(c); + Is.add(I); + qs.add(q); + trackIDs.add(track.getId()); + } + + //only include events that have tracks that will be used in alignment + if(!As.isEmpty()) { + AlignmentBankWriter writer = new AlignmentBankWriter(); + writer.write_Matrix(event, "I", Is); + writer.write_Matrix(event, "A", As); + writer.write_Matrix(event, "B", Bs); + writer.write_Matrix(event, "V", Vs); + writer.write_Matrix(event, "m", ms); + writer.write_Matrix(event, "c", cs); + writer.write_Matrix(event, "q", qs); + fillMisc(event,runNum,eventNum,trackIDs,As,Bs,Vs,ms,cs,Is); + } + return true; + + } + private Helix createHelixFromRay(Ray ray) { + Vector3D u = ray.getDirVec(); + Vector3D xref = ray.getRefPoint().toVector3D(); + double phi = Math.atan2(u.y(),u.x()); + Vector3D uT = new Vector3D(Math.cos(phi), Math.sin(phi),0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi),0); + double cosdip = Math.hypot(u.x(), u.y()); + double d = mscphi.dot(xref); + double curvature = 0; + double Z0 = xref.z()-u.z()*xref.dot(uT)/u.dot(uT); + double tandip = u.z()/Math.hypot(u.x(), u.y()); + return new Helix(d, phi, curvature, Z0, tandip, 0,0); + } + + + private Ray getRay(Helix h) { + + double d = h.getDCA(); + double z = h.getZ0(); + double phi = h.getPhiAtDCA(); + double td = h.getTanDip(); + double cd = 1/Math.hypot(td, 1); + double sd = td*cd; + double xb = h.getXb(); + double yb = h.getYb(); + //Vector3D u = new Vector3D(-cd*Math.sin(phi), cd*Math.cos(phi), sd); + //Point3D x = new Point3D(d*Math.cos(phi),d*Math.sin(phi), z); + Vector3D u = new Vector3D(cd*Math.cos(phi), cd*Math.sin(phi), sd); + + + Point3D x = new Point3D(-d*Math.sin(phi)+xb,d*Math.cos(phi)+yb, z); + //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + + //System.out.println("xb yb from db" + xb + yb); + //Point3D x = new Point3D(-d*Math.sin(phi),d*Math.cos(phi), z); + //if(u.y() <0) + // u = u.multiply(-1); + //x = x.toVector3D().add(u.multiply(-x.y()/u.y())).toPoint3D(); + Ray ray = new Ray(x, u); + //System.out.println("doca " + d); + //System.out.println("td " + td); + + return ray; + } + + + + private double getDoca(Trajectory track) { + if(track instanceof StraightTrack) { + Ray ray = track.getRay(); + double intercept = ray.getYXInterc(); + double slope = ray.getYXSlope(); + return Math.abs(intercept)/Math.hypot(1, slope); + } else return track.getHelix().getDCA(); + } + + private void fillMisc(DataEvent event, int runNum, int eventNum, List trackIDs, + List As, List Bs, List Vs, + List ms, List cs, List is) { + DataBank bank = event.createBank("Align::misc", trackIDs.size()); + for(int i = 0; i spMax) { //this can only happen if the angle between the track and the normal is small + //System.out.println("rejecting track"); + return false; + } + int index = nAlignables - 1; + + //System.out.println("i = " + i + "; rows = " + A.getRowDimension() + "; cols = " + + A.getColumnDimension()); + Vector3D dmdr = sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e)) / udotn)); + if (orderTx >= 0) { + A.set(i, i * nAlignVars + orderTx, sp.x()); + } + if (orderTy >= 0) { + A.set(i, i * nAlignVars + orderTy, sp.y()); + } + if (orderTz >= 0) { + A.set(i, i * nAlignVars + orderTz, sp.z()); + } + if (orderRx >= 0) { + A.set(i, i * nAlignVars + orderRx, -dmdr.x()); + } + if (orderRy >= 0) { + A.set(i, i * nAlignVars + orderRy, -dmdr.y()); + } + if (orderRz >= 0) { + A.set(i, i * nAlignVars + orderRz, -dmdr.z()); + } + + I.set(i, 0, index); + + Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n) / udotn); + if (!this.useDocaPhiZTandip) { + B.set(i, 0, sp.x()); + B.set(i, 1, sp.z()); + B.set(i, 2, dmdu.x()); + B.set(i, 3, dmdu.z()); + } else { + + double phi = Math.atan2(u.y(), u.x()); + Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi), 0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi), 0); + double cosdip = Math.hypot(u.x(), u.y()); + double d = mscphi.dot(xref); + B.set(i, 0, -sp.dot(mscphi)); + B.set(i, 1, -sp.dot(mscphi) * n.dot(e.clone().sub(xref)) * cosdip / udotn + sp.dot(csphi) * d); + B.set(i, 2, -sp.z()); + B.set(i, 3, -sp.z() * n.dot(e.clone().sub(xref)) / udotn); + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + + double ci = s.dot(extrap); + double mi = s.dot(e); + + c.set(i, 0, ci); + m.set(i, 0, mi); + + return true; + } + + + private boolean fillMatricesNew(int i, Helix helix, Cluster cl, SimpleMatrix A, SimpleMatrix B, SimpleMatrix V, + SimpleMatrix m, SimpleMatrix c, SimpleMatrix I, boolean debug, boolean isBeamspot) { + Vector3D u= helix.getTrackDirectionAtRadius(cl.getRadius()); + Point3D xref = helix.getPointAtRadius(cl.getRadius()); + Ray ray = new Ray(xref, u); + return fillMatricesNew(i, ray, cl, A, B, V, m, c, I, debug, isBeamspot); + } + + /** + * generic method that uses any type of cluster. + * @param i + * @param ray + * @param cl + * @param A + * @param B + * @param V + * @param m + * @param c + * @param I + * @param string + * @return + */ + private boolean fillMatricesNew(int i, Ray ray, Cluster cl, SimpleMatrix A, SimpleMatrix B, SimpleMatrix V, + SimpleMatrix m, SimpleMatrix c, SimpleMatrix I, boolean debug, boolean isBeamspot) { + int layer = cl.getLayer(); + int sector = cl.getSector(); + + Vector3D l; + Vector3D s; + Vector3D n; + + DetectorType detector = cl.getDetector(); + BMTType bmtType = cl.getType(); + + if (debug) { + System.out.println("\n\nNew method " + detector + " layer " + layer + " sector " + sector); + + } + Vector3D xref = ray.getRefPoint().toVector3D(); + Vector3D u = ray.getDirVec(); + + Vector3D e = null; + Vector3D extrap = null; + if (detector == DetectorType.BST || (detector == DetectorType.BMT && bmtType == BMTType.Z) || isBeamspot) { + l = cl.getL(); + s = cl.getS(); + n = cl.getN(); + + e = cl.getLine().midpoint().toVector3D(); + + double udotn = u.dot(n); + extrap = xref.clone().add(u.multiply(n.dot(e.clone().sub(xref)) / udotn)); + } + else { // BMTC + Vector3D a = cl.getArc().normal(); + + if (debug) { + System.out.println("a: " + a); + } + Vector3D cc = cl.getArc().center().toVector3D(); + Vector3D uT = perp(u, a); + + Vector3D tmp1 = perp(xref.clone().sub(cc), a); + + Vector3D endpoint = cl.getArc().origin().toVector3D(); + + double R = perp(endpoint.clone().sub(cc), a).mag(); + if (debug) { + System.out.println("center: " + cc.toStringBrief()); + System.out.println("R: " + R); + } + double AA = uT.mag2(); + + double BB = 2 * tmp1.dot(uT); + double CC = tmp1.mag2() - R * R; + double lambda_plus = (-BB + Math.sqrt(BB * BB - 4 * AA * CC)) / (2 * AA); + double lambda_minus = (-BB - Math.sqrt(BB * BB - 4 * AA * CC)) / (2 * AA); + Vector3D extrap_plus = xref.clone().add(u.multiply(lambda_plus)); + Vector3D extrap_minus = xref.clone().add(u.multiply(lambda_minus)); + + if (debug) { + System.out.println("extrap is on cylinder: this should be zero: " + (perp(extrap_plus.clone().sub(cc), a).mag() - R)); + } + + //choose the extrapolated point that is closer in z to the measured cluster. + if (Math.abs(extrap_plus.clone().sub(cc).z()) < Math.abs(extrap_minus.clone().sub(cc).z())) { + extrap = extrap_plus; + } else { + extrap = extrap_minus; + } + e = extrap.clone().add(endpoint.clone().sub(extrap).projection(a)); + s = a; + n = perp(extrap.clone().sub(cc), a).asUnit(); + l = s.cross(n); + } + + n = n.sub(l.multiply(n.dot(l))).asUnit(); + s = s.sub(l.multiply(s.dot(l))).asUnit(); + + double udotn = u.dot(n); + if (Math.abs(udotn) < minCosIncident) { + if (debug) { + System.out.println("rejecting track: abs(udotn)<" + minCosIncident); + System.out.println("u = " + u.toString()); + System.out.println("n = " + n.toString()); + } + return false; + } + double sdotu = s.dot(u); + + if (debug) { + System.out.println("e: " + e.toString()); + } + + if (detector == DetectorType.BMT && bmtType == BMTType.Z && debug) { + Vector3D diff = xref.clone(); + double check = l.cross(u).dot(diff); + System.out.println("distance between track and strip, phi,r: " + check + " " + u.phi() + " " + e.mag()); + } + + double resolution = cl.getResolution(); + + V.set(i, i, Math.pow(resolution, 2)); + if (debug) { + System.out.println("resolution " + resolution); + } + + Vector3D sp = s.clone().sub(n.multiply(sdotu / udotn)); + if (sp.mag() > spMax) { //this can only happen if the angle between the track and the normal is small + if (debug) { + System.out.println("rejecting track: sp.magnitude() > " + spMax); + } + return false; + } + + Vector3D dmdr = sp.cross(xref).sub(sp.cross(u).multiply(n.dot(xref.clone().sub(e)) / udotn)); + + if (orderTx >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderTx, sp.x()); + } + if (orderTy >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderTy, sp.y()); + } + if (orderTz >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderTz, sp.z()); + } + if (orderRx >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderRx, -dmdr.x()); + } + if (orderRy >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderRy, -dmdr.y()); + } + if (orderRz >= 0) { + A.set(i, (svtTopBottomSep ? i : i / 2) * nAlignVars + orderRz, -dmdr.z()); + } + + if (detector == DetectorType.BST) { + I.set(i, 0, getIndexSVT(layer - 1, sector - 1)); + } else if (detector == DetectorType.BMT) { + I.set(i, 0, getIndexBMT(layer - 1, sector - 1)); + } else { + I.set(i, 0, INDEXBEAMLINE); + } + Vector3D dmdu = sp.multiply(e.clone().sub(xref).dot(n) / udotn); + if (!this.useDocaPhiZTandip) { + B.set(i, 0, -sp.x()); + B.set(i, 1, -sp.z()); + B.set(i, 2, -dmdu.x()); + B.set(i, 3, -dmdu.z()); + } else { + + double phi = Math.atan2(u.y(), u.x()); + /*if(detector == DetectorType.BMT && bmtType==BMTType.C) { + System.out.println("phi is " + phi); + }*/ + Vector3D csphi = new Vector3D(Math.cos(phi), Math.sin(phi), 0); + Vector3D mscphi = new Vector3D(-Math.sin(phi), Math.cos(phi), 0); + double cosdip = Math.hypot(u.x(), u.y()); + double d = mscphi.dot(xref); + B.set(i, 0, -sp.dot(mscphi)); + B.set(i, 1, -sp.dot(mscphi) * n.dot(e.clone().sub(xref)) * cosdip / udotn + sp.dot(csphi) * d); + B.set(i, 2, -sp.z()); + B.set(i, 3, -sp.z() * n.dot(e.clone().sub(xref)) / udotn); + + } + //dm.set(i,0, s.dot(e.minus(extrap))); + + double ci = s.dot(extrap); + double mi = s.dot(e); + + c.set(i, 0, ci); + m.set(i, 0, mi); + if (debug) { + System.out.println("n.(e-xref): " + n.dot(e.clone().sub(xref))); + System.out.println("u.n: " + udotn); + System.out.println("s: " + s.toString()); + System.out.println("sp: " + sp.toString()); + System.out.println("extrap: " + extrap.toString()); + System.out.println("n: " + n.toString()); + System.out.println("e: " + e.toString()); + System.out.println("xref: " + xref.toString()); + System.out.println("u: " + u.toString()); + System.out.println("m: " + mi); + System.out.println("c: " + ci); + } + if (Math.abs(ci - mi) > maxResidualCutSVT && detector == DetectorType.BST + || Math.abs(ci - mi) > maxResidualCutBMTZ && detector == DetectorType.BMT && bmtType == BMTType.Z + || Math.abs(ci - mi) > maxResidualCutBMTC && detector == DetectorType.BMT && bmtType == BMTType.C) { + if (debug) { + System.out.println("rejecting track: Math.abs(ci-mi)>maxResidualCut"); + } + return false; + } + return true; + } + + + Vector3D perp(Vector3D v, Vector3D a) { + return v.clone().sub(a.multiply(v.dot(a))); + } + + private int getIndexBMT(int layer, int sector) { + if (layer < 0 || sector < 0) { + return -1; + } + return NSVTSENSORS+layer*3+sector; + } + + private int getIndexSVT(int layer, int sector){ + int index = -1; + int region = layer/2; + switch (region) { + case 0: + index = sector; + break; + case 1: + index = SVTGeometry.NSECTORS[0] + sector; + break; + case 2: + index = SVTGeometry.NSECTORS[0] + + SVTGeometry.NSECTORS[2] + sector; + break; + default: + break; + } + if(svtTopBottomSep && layer%2==1) { + index += NSVTSENSORS/2; + } + return index; + + } + + + @Override + public boolean init() { + if(this.getEngineConfiguration() == null || "null".equals(this.getEngineConfiguration())) { + return true; //prevents init from being run twice. + } + + if (this.getEngineConfigString("svtOnly")!=null) { + this.isSVTonly= Boolean.valueOf(this.getEngineConfigString("svtOnly")); + } + System.out.println("["+this.getName()+"] align SVT only set to " + this.isSVTonly); + + if (this.getEngineConfigString("bmtOnly")!=null) { + this.isBMTonly= Boolean.valueOf(this.getEngineConfigString("bmtOnly")); + } + System.out.println("["+this.getName()+"] align BMT only set to " + this.isBMTonly); + + if (this.getEngineConfigString("skipBMTC")!=null) { + this.skipBMTC= Boolean.valueOf(this.getEngineConfigString("skipBMTC")); + } + System.out.println("["+this.getName()+"] skip BMTC set to " + this.skipBMTC); + + if (this.getEngineConfigString("svtAlignTopBottomSeparately")!=null) { + this.svtTopBottomSep= Boolean.valueOf(this.getEngineConfigString("svtAlignTopBottomSeparately")); + } + System.out.println("["+this.getName()+"] align SVT top-bottom separately set to " + this.svtTopBottomSep); + + if (this.getEngineConfigString("alignVariables")!=null) { + this.alignVars = this.getEngineConfigString("alignVariables"); + } + System.out.println("["+this.getName()+"] align variables set to " + this.alignVars); + + if (this.getEngineConfigString("cosmics")!=null) { + this.isCosmics= Boolean.valueOf(this.getEngineConfigString("cosmics")); + } + System.out.println("["+this.getName()+"] use cosmics bank set to " + this.isCosmics); + + if(this.getEngineConfigString("maxDocaCut") != null) { + this.maxDocaCut = Double.parseDouble(this.getEngineConfigString("maxDocaCut")); + } + if(isCosmics) this.maxDocaCut = Double.MAX_VALUE; + System.out.println("["+this.getName()+"] track DOCA cut set to " + this.maxDocaCut + " mm"); + + + if (this.getEngineConfigString("maxResidual")!=null) { + this.maxResidualCutBMTZ = this.maxResidualCutBMTC = this.maxResidualCutSVT = Double.valueOf(this.getEngineConfigString("maxResidual")); + } + if (this.getEngineConfigString("maxResidualSVT")!=null) { + this.maxResidualCutSVT = Double.valueOf(this.getEngineConfigString("maxResidualSVT")); + } + if (this.getEngineConfigString("maxResidualBMTZ")!=null) { + this.maxResidualCutBMTZ = Double.valueOf(this.getEngineConfigString("maxResidualBMTZ")); + } + if (this.getEngineConfigString("maxResidualBMTC")!=null) { + this.maxResidualCutBMTC = Double.valueOf(this.getEngineConfigString("maxResidualBMTC")); + } + System.out.println("["+this.getName()+"] max residual for SVT clusters set to " + this.maxResidualCutSVT + " mm"); + System.out.println("["+this.getName()+"] max residual for BMTC clusters set to " + this.maxResidualCutBMTC + " mm"); + System.out.println("["+this.getName()+"] max residual for BMTZ clusters set to " + this.maxResidualCutBMTZ + " mm"); + + if (this.getEngineConfigString("minClustersSVT")!=null) { + this.minClustersSVT = Integer.valueOf(this.getEngineConfigString("minClustersSVT")); + } + if (this.getEngineConfigString("minClustersBMTZ")!=null) { + this.minClustersBMTZ = Integer.valueOf(this.getEngineConfigString("minClustersBMTZ")); + } + if (this.getEngineConfigString("minClustersBMTC")!=null) { + this.minClustersBMTC = Integer.valueOf(this.getEngineConfigString("minClustersBMTC")); + } + System.out.println("["+this.getName()+"] min number of SVT clusters set to " + this.minClustersSVT); + System.out.println("["+this.getName()+"] min number of BMTC clusters set to " + this.minClustersBMTC); + System.out.println("["+this.getName()+"] min number of BMTZ clusters set to " + this.minClustersBMTZ); + + if (this.getEngineConfigString("useBeamspot")!=null) { + this.includeBeamspot = Boolean.valueOf(this.getEngineConfigString("useBeamspot")); + } + System.out.println("["+this.getName()+"] treat beamspot as an additional measurement set to " + this.includeBeamspot); + + if (this.getEngineConfigString("debug")!=null) { + this.debug = Boolean.parseBoolean(this.getEngineConfigString("debug")); + } + + this.nAlignables = ((this.svtTopBottomSep ? NSVTSENSORS : NSVTSENSORS/2) + (this.isSVTonly ? 0: 18) + (includeBeamspot? 1 : 0)); + this.setAlignVars(alignVars); + + return true; + } + + + + private void setAlignVars(String alignVars) { + orderTx = -1; + orderTy = -1; + orderTz = -1; + orderRx = -1; + orderRy = -1; + orderRz = -1; + if (alignVars.length() > 2 && !alignVars.contains(" ")) { + for (int i = 0; i < alignVars.length() / 2; i++) { + String s = alignVars.substring(2 * i, 2 * i + 2); + if (s.equals("Tx")) { + orderTx = i; + } else if (s.equals("Ty")) { + orderTy = i; + } else if (s.equals("Tz")) { + orderTz = i; + } else if (s.equals("Rx")) { + orderRx = i; + } else if (s.equals("Ry")) { + orderRy = i; + } else if (s.equals("Rz")) { + orderRz = i; + } + nAlignVars = i + 1; + } + if (debug) { + System.out.println(nAlignVars + " alignment variables requested"); + } + return; + } + //old version + String split[] = alignVars.split("[ \t]+"); + int i = 0; + for (String s : split) { + if (s.equals("Tx")) { + orderTx = i; + i++; + } else if (s.equals("Ty")) { + orderTy = i; + i++; + } else if (s.equals("Tz")) { + orderTz = i; + i++; + } else if (s.equals("Rx")) { + orderRx = i; + i++; + } else if (s.equals("Ry")) { + orderRy = i; + i++; + } else if (s.equals("Rz")) { + orderRz = i; + i++; + } + } + nAlignVars = i; + if(debug) System.out.println(nAlignVars + " alignment variables requested"); + } + } diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java index 4c295a026..1fc267e26 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/banks/RecoBankReader.java @@ -207,7 +207,7 @@ public static List readBMTClusterBank(DataEvent event, String bankname) Line3D ln = new Line3D(ax1,ay1,az1, ax2,ay2,az2); Point3D origin = new Point3D(x1,y1,z1); Point3D center = ln.distance(origin).origin(); - Vector3D normal = ln.direction(); + Vector3D normal = ln.direction().asUnit(); Arc3D arc = new Arc3D(origin, center, normal, theta); cls.setArc(arc); cls.setCentroidValue(centroidValue*10); @@ -433,6 +433,11 @@ public static List readCVTTracksBank(DataEvent event, String bankname) { track.setPID(pid); track.setKFIterations((int) status/1000); track.setSeed(seed); + for (int j = 0; j < 9; j++) { + int crossId = bank.getShort("Cross"+(j+1)+"_ID", i); + DetectorType det = crossId>1000 ? DetectorType.BMT : DetectorType.BST; + if(crossId>0) track.add(new Cross(det, BMTType.UNDEFINED, 0, 0, crossId)); + } tracks.add(track); } return tracks; @@ -461,6 +466,12 @@ public static List readCVTCosmicsBank(DataEvent event, String ban track.setId(tid); track.setChi2(chi2); track.setNDF(ndf); + + for (int j = 0; j < 18; j++) { + int crossId = bank.getShort("Cross"+(j+1)+"_ID", i); + DetectorType det = crossId>1000 ? DetectorType.BMT : DetectorType.BST; + if(crossId>0) track.add(new Cross(det, BMTType.UNDEFINED, 0, 0, crossId)); + } tracks.add(track); } return tracks; diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java index 8d20c4356..3b9c0e0b9 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/cross/Cross.java @@ -584,7 +584,7 @@ public String toString() { public String printInfo() { String s = " cross: " + this.getDetector() + " " + this.getType() + " ID " + this.getId() + " Sector " + this.getSector() + " Region " + this.getRegion() + " sort "+this.getOrderedRegion()+" cosmic region "+this.getSVTCosmicsRegion(); - if(this.getPoint0()!=null) s += " Point " + this.getPoint().toString(); + if(this.getPoint()!=null) s += " Point " + this.getPoint().toString(); if(this.getPoint0()!=null) s += " Point0 " + this.getPoint0().toString(); if(this.getDir()!=null) s += " Direction "+ this.getDir().toString(); return s; From 7d01474d30ecc6b1bd938eb946f31834b6ac457e Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Sat, 13 Aug 2022 23:22:43 -0400 Subject: [PATCH 289/291] switching again straight track momentum to 100 GeV --- .../org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java | 2 +- .../org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java index 4fa53e169..02791b4d8 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/helical/StateVecs.java @@ -245,7 +245,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); double p = Math.sqrt(vec.px*vec.px + vec.py*vec.py + vec.pz*vec.pz); - if(this.straight) p = 1; + if(this.straight) p = 100; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java index d811b23f9..efa42dfb7 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/straight/StateVecs.java @@ -108,7 +108,7 @@ public double[][] Q(StateVec vec, AMeasVecs mv) { Surface surf = mv.measurements.get(vec.k).surface; double cosEntranceAngle = this.getLocalDirAtMeasSite(vec, mv.measurements.get(vec.k)); - double p = 1; + double p = 100; // Highland-Lynch-Dahl formula double sctRMS = surf.getThetaMS(p, mass, cosEntranceAngle); From f725fa3c64a98889bccbe690d86a00f22c9195dc Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 16 Feb 2024 16:21:09 -0500 Subject: [PATCH 290/291] test: empty commit From 9c4b2154368f7edaeb1b89135676ccf482cafb20 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 16 Feb 2024 17:45:55 -0500 Subject: [PATCH 291/291] fix: some build fixes --- .../cvt/alignment/AlignmentBankReader.java | 46 ++++++------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java index 2b44d3594..858a1aac6 100644 --- a/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java +++ b/reconstruction/cvt/src/main/java/org/jlab/rec/cvt/alignment/AlignmentBankReader.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Collections; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; @@ -25,16 +26,11 @@ */ public class AlignmentBankReader { - private List _SVTcrosses; - private List _SVTclusters; - private List _BMTcrosses; - private List _BMTclusters; - public List getCosmics(DataEvent event) { - SVThits = RecoBankReader.readBSTHitBank(event, "BST::Hits"); - BMThits = RecoBankReader.readBMTHitBank(event, "BMT::Hits"); + var SVThits = RecoBankReader.readBSTHitBank(event, "BST::Hits"); + var BMThits = RecoBankReader.readBMTHitBank(event, "BMT::Hits"); if(SVThits!= null) { Collections.sort(SVThits); } @@ -45,12 +41,12 @@ public List getCosmics(DataEvent event) { Collections.sort(BMThits); } - _SVTclusters = RecoBankReader.readBSTClusterBank(event, SVThits, "BSTRec::Clusters"); - _BMTclusters = RecoBankReader.readBMTClusterBank(event, BMThits, "BMTRec::Clusters"); + var _SVTclusters = RecoBankReader.readBSTClusterBank(event, SVThits, "BSTRec::Clusters"); + var _BMTclusters = RecoBankReader.readBMTClusterBank(event, BMThits, "BMTRec::Clusters"); - _SVTcrosses = RecoBankReader.readBSTCrossBank(event, _SVTclusters, "BSTRec::Crosses"); - _BMTcrosses = RecoBankReader.readBMTCrossBank(event, _BMTclusters, "BMTRec::Crosses"); + var _SVTcrosses = RecoBankReader.readBSTCrossBank(event, _SVTclusters, "BSTRec::Crosses"); + var _BMTcrosses = RecoBankReader.readBMTCrossBank(event, _BMTclusters, "BMTRec::Crosses"); if(_SVTcrosses!=null) { for(Cross cross : _SVTcrosses) { cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); @@ -94,8 +90,8 @@ public List getCosmics(DataEvent event) { public List getTracks(DataEvent event) { - SVThits = RecoBankReader.readBSTHitBank(event, "BST::Hits"); - BMThits = RecoBankReader.readBMTHitBank(event, "BMT::Hits"); + var SVThits = RecoBankReader.readBSTHitBank(event, "BST::Hits"); + var BMThits = RecoBankReader.readBMTHitBank(event, "BMT::Hits"); if(SVThits!= null) { Collections.sort(SVThits); } @@ -106,12 +102,12 @@ public List getTracks(DataEvent event) { Collections.sort(BMThits); } - _SVTclusters = RecoBankReader.readBSTClusterBank(event, SVThits, "BSTRec::Clusters"); - _BMTclusters = RecoBankReader.readBMTClusterBank(event, BMThits, "BMT::Clusters"); + var _SVTclusters = RecoBankReader.readBSTClusterBank(event, SVThits, "BSTRec::Clusters"); + var _BMTclusters = RecoBankReader.readBMTClusterBank(event, BMThits, "BMT::Clusters"); - _SVTcrosses = RecoBankReader.readBSTCrossBank(event, _SVTclusters, "BSTRec::Crosses"); - _BMTcrosses = RecoBankReader.readBMTCrossBank(event, _BMTclusters, "BMTRec::Crosses"); + var _SVTcrosses = RecoBankReader.readBSTCrossBank(event, _SVTclusters, "BSTRec::Crosses"); + var _BMTcrosses = RecoBankReader.readBMTCrossBank(event, _BMTclusters, "BMTRec::Crosses"); if(_SVTcrosses!=null) { for(Cross cross : _SVTcrosses) { cross.setCluster1(_SVTclusters.get(cross.getCluster1().getId()-1)); @@ -157,20 +153,4 @@ public List getTracks(DataEvent event) { } - public List get_ClustersSVT() { - return _SVTclusters; - } - - public List get_ClustersBMT() { - return _BMTclusters; - } - - public List get_CrossesSVT() { - return _SVTcrosses; - } - - public List get_CrossesBMT() { - return _BMTcrosses; - } - }