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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public void setFinalStateVec(StateVec finalStateVec) {
private double _totPathLen;
private Point3D _trakOrig;
private Vector3D _pOrig;
private Point3D _Vtx0_TiltedCS;
private Vector3D _pAtOrig_TiltedCS;
private String _trking;
private int _FitNDF;
private double _NDFDAF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ public List<Track> getTrackCandsAI(CrossList crossList, DCGeant4Factory DcDetect
rk.SwimToZ(sector, initSV, dcSwim, measSurfaces.get(0).wireLine[0].end().z(), new float[3]);

KFitter kFZRef = new KFitter(true, 1, 1, dcSwim, Constants.getInstance().Z, Libr.JNP);
Matrix initCMatrix = new Matrix();
initSV.CM = new Matrix();
kFZRef.init(measSurfaces, initSV);

Expand Down Expand Up @@ -534,8 +533,6 @@ public void setTrackPars(Track cand,
return;
}

int status = 99999;

int LR = 0;
for (Cross crs : cand) {
Segment s1 = crs.get_Segment1();
Expand All @@ -550,8 +547,6 @@ public void setTrackPars(Track cand,

}

status = LR;

double xOrFix = Vt[0];
double yOrFix = Vt[1];
double zOrFix = Vt[2];
Expand Down Expand Up @@ -1162,13 +1157,9 @@ private List<Track> findCurvedTracks(CrossList crossList, DCGeant4Factory DcDete
cand.get(0).get_Dir().y() / cand.get(0).get_Dir().z());
cand.set_StateVecAtReg1MiddlePlane(VecAtReg1MiddlePlane);


StateVec fitStateVec = null;
// prefer to initialize the seed with region 2 cross due to higher background in region 1
int crossIdxinList = 1;
if (cand.get(1).isPseudoCross) {
crossIdxinList = 0;
}

final int crossIdxinList = cand.get(1).isPseudoCross ? 0 : 1;

LOGGER.log(Level.FINEST, "Kalman fitter - 2 = " + (System.currentTimeMillis() - startTime));

Expand All @@ -1181,12 +1172,10 @@ private List<Track> findCurvedTracks(CrossList crossList, DCGeant4Factory DcDete

kFZRef.runFitter();

if (kFZRef.finalStateVec == null) {
continue;
} else {
if (kFZRef.finalStateVec != null) {
if (kFZRef.chi2 < Constants.MAXCHI2) {

fitStateVec = new StateVec(kFZRef.finalStateVec.x,
StateVec fitStateVec = new StateVec(kFZRef.finalStateVec.x,
kFZRef.finalStateVec.y, kFZRef.finalStateVec.tx, kFZRef.finalStateVec.ty);
q = (int) Math.signum(kFZRef.finalStateVec.Q);
p = 1. / Math.abs(kFZRef.finalStateVec.Q);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.jlab.clas.swimtools.Swim;
import org.jlab.detector.geant4.v2.DCGeant4Factory;
import org.jlab.rec.dc.track.Track;
Expand All @@ -16,8 +14,6 @@
*/
public class KFitterDoca {

private static final Logger LOGGER = Logger.getLogger(KFitterDoca.class.getName());

public boolean setFitFailed = false;

private StateVecsDoca sv;
Expand All @@ -29,10 +25,8 @@ public class KFitterDoca {
private CovMat initialCovMat;
public List<org.jlab.rec.dc.trajectory.StateVec> kfStateVecsAlongTrajectory;
public int totNumIter = 30;
private double newChisq = Double.POSITIVE_INFINITY;
public boolean filterOn = true;
public double chi2 = 0;
private double chi2kf = 0;
public int NDF = 0;
public int ConvStatus = 1;

Expand Down Expand Up @@ -77,15 +71,13 @@ public final void init(Track trk, DCGeant4Factory DcDetector, int c) {
sv.init(trk, sv.Z[0], this, c);
}
public int interNum = 0;
double initChi2 = Double.POSITIVE_INFINITY;
public void runFitter(int sector) {
this.chi2 = Double.POSITIVE_INFINITY;
double initChi2 = Double.POSITIVE_INFINITY;
this.NDF = mv.ndf;
int svzLength = sv.Z.length;

if(TBT==true) {
this.chi2kf = 0;
// Get the input parameters
for (int k = 0; k < svzLength - 1; k++) {
sv.transport(sector, k, k + 1,
Expand All @@ -106,7 +98,6 @@ public void runFitter(int sector) {
// IntStream.range(1,totNumIter ).parallel().forEach(i -> {
for (int i = 1; i <= totNumIter; i++) {
interNum = i;
this.chi2kf = 0;

if (i > 1) {
//get new state vec at 1st measurement after propagating back from the last filtered state
Expand Down Expand Up @@ -226,7 +217,7 @@ public Matrix filterCovMat(double[] H, Matrix Ci, double V) {

return result_inv;
}
private double KFScale = 4;
private final double KFScale = 4;
private void filter(int k) {
if(Double.isNaN(sv.trackTraj.get(k).x) || Double.isNaN(sv.trackTraj.get(k).y)
|| Double.isNaN(sv.trackTraj.get(k).tx) ||Double.isNaN(sv.trackTraj.get(k).ty )
Expand Down Expand Up @@ -274,8 +265,6 @@ private void filter(int k) {
}
//if(this.interNum>1)
// signMeas = Math.signum(h);
double c2 = ((signMeas*Math.abs(mv.measurements.get(k).doca[0]) - sign*Math.abs(h))
* (signMeas*Math.abs(mv.measurements.get(k).doca[0]) - sign*Math.abs(h)) / V);
//if(signMeas!=Math.signum(h) && this.interNum>1) LOGGER.log(Level.FINEST, sv.trackTraj.get(k).printInfo()+" h "+(float)h);
double x_filt = sv.trackTraj.get(k).x + K[0] * (signMeas*Math.abs(mv.measurements.get(k).doca[0]) - sign*Math.abs(h));
double y_filt = sv.trackTraj.get(k).y + K[1] * (signMeas*Math.abs(mv.measurements.get(k).doca[0]) - sign*Math.abs(h));
Expand Down Expand Up @@ -315,12 +304,8 @@ private void filter(int k) {
tx_filt += K[2] * (signMeas*Math.abs(mv.measurements.get(k).doca[1]) - sign*Math.abs(h));
ty_filt += K[3] * (signMeas*Math.abs(mv.measurements.get(k).doca[1]) - sign*Math.abs(h));
Q_filt += K[4] * (signMeas*Math.abs(mv.measurements.get(k).doca[1]) - sign*Math.abs(h));

c2 += ((signMeas*Math.abs(mv.measurements.get(k).doca[1]) - sign*Math.abs(h))
* (signMeas*Math.abs(mv.measurements.get(k).doca[1]) - sign*Math.abs(h)) / V);
}

chi2kf += c2;
if(filterOn) {
sv.trackTraj.get(k).x = x_filt;
sv.trackTraj.get(k).y = y_filt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.jlab.detector.geant4.v2.DCGeant4Factory;
import org.jlab.geom.prim.Line3D;
import org.jlab.geom.prim.Point3D;
Expand All @@ -13,9 +12,7 @@

public class MeasVecsDoca {

private static final Logger LOGGER = Logger.getLogger(MeasVecsDoca.class.getName());

public List<MeasVec> measurements = new ArrayList<MeasVec>();
public List<MeasVec> measurements = new ArrayList<>();

public int ndf=0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jlab.rec.dc.track.fit;

import java.util.ArrayList;
import org.jlab.jnp.matrix.*;
import org.jlab.clas.swimtools.Swim;

Expand All @@ -21,12 +20,11 @@ public void SwimToZ(int sector, StateVecsDoca.StateVec vec, Swim swim, double z0
swim.Bfield(sector, vec.x, vec.y, vec.z, bf);

vec.B = Math.sqrt(bf[0]*bf[0] + bf[1]*bf[1] + bf[2]*bf[2]);
double s = vec.B;
final double travelSign = Math.signum(z0 - vec.z);
double BatMeas = 0;

while(travelSign * vec.z < travelSign * z0) {
s = travelSign * stepSize;
double s = travelSign * stepSize;
if (travelSign*(vec.z+s) > travelSign*z0) s = travelSign*Math.abs(z0-vec.z);

this.RK4transport(sector, s, swim, vec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.jlab.jnp.matrix.*;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.jlab.clas.clas.math.FastMath;
import org.jlab.clas.pdg.PhysicsConstants;
import org.jlab.clas.swimtools.Swim;
import org.jlab.rec.dc.Constants;
Expand All @@ -16,28 +14,19 @@
*/
public class StateVecsDoca {

private static final Logger LOGGER = Logger.getLogger(StateVecsDoca.class.getName());

private final double Bmax = 2.366498; // averaged

final double speedLight = 0.002997924580;
public double[] Z;
// public List<B> bfieldPoints = new ArrayList<B>();
public Map<Integer, StateVec> trackTraj = new HashMap<Integer, StateVec>();
public Map<Integer, CovMat> trackCov = new HashMap<Integer, CovMat>();
public Map<Integer, StateVec> trackTraj = new HashMap<>();
public Map<Integer, CovMat> trackCov = new HashMap<>();


public StateVec StateVec;
public CovMat CovMat;
public Matrix F = new Matrix();
private final Matrix fMS = new Matrix();
private final Matrix copyMatrix = new Matrix();
private final double[] A = new double[2];
private final double[] dA = new double[4];
private final float[] bf = new float[3];
private final float[] lbf = new float[3];
private Swim dcSwim;
private RungeKuttaDoca rk;
private final Swim dcSwim;
private final RungeKuttaDoca rk;

/**
* State vector representing the track in the sector coordinate system at the measurement layer
Expand Down Expand Up @@ -73,23 +62,15 @@ public Matrix transport(int sector, int i, double Zf, StateVec iVec, CovMat covM
fVec.B = iVec.B;
//fCov.covMat = covMat.covMat;
Matrix5x5.copy(covMat.covMat, fCov.covMat);
double s = 0;
double z = Z[i];
double BatMeas = iVec.B;

while(Math.signum(Zf - Z[i]) *z<Math.signum(Zf - Z[i]) *Zf) {
//LOGGER.log(Level.FINEST, " RK step num "+(j+1)+" = "+(float)s+" nSteps = "+nSteps);
double x = fVec.x;
double y = fVec.y;
z = fVec.z;
double tx = fVec.tx;
double ty = fVec.ty;
double Q = fVec.Q;
double dPath = fVec.deltaPath;
//covMat.covMat = fCov.covMat;
Matrix5x5.copy(fCov.covMat, covMat.covMat);
s= Math.signum(Zf - Z[i]) * stepSize;
// LOGGER.log(Level.FINEST, " from "+(float)Z[i]+" to "+(float)Z[f]+" at "+(float)z+" By is "+bf[1]+" B is "+Math.sqrt(bf[0]*bf[0]+bf[1]*bf[1]+bf[2]*bf[2])/Bmax+" stepSize is "+s);
double s = Math.signum(Zf - Z[i]) * stepSize;
if(Math.signum(Zf - Z[i]) *(z+s)>Math.signum(Zf - Z[i]) *Zf)
s=Math.signum(Zf - Z[i]) *Math.abs(Zf-z);
rk.RK4transport(sector, s, dcSwim, covMat, fVec, fCov);
Expand Down Expand Up @@ -162,25 +143,16 @@ public void transport(int sector, int i, int f, StateVec iVec, CovMat covMat) {
fVec.ty = iVec.ty;
fVec.Q = iVec.Q;
fVec.B = iVec.B;
//fCov.covMat = covMat.covMat;
Matrix5x5.copy(covMat.covMat, fCov.covMat);
double s = 0;
double z = Z[i];
double BatMeas = iVec.B;

while(Math.signum(Z[f] - Z[i]) *z<Math.signum(Z[f] - Z[i]) *Z[f]) {
//LOGGER.log(Level.FINEST, " RK step num "+(j+1)+" = "+(float)s+" nSteps = "+nSteps);
double x = fVec.x;
double y = fVec.y;
z = fVec.z;
double tx = fVec.tx;
double ty = fVec.ty;
double Q = fVec.Q;
double dPath = fVec.deltaPath;
//covMat.covMat = fCov.covMat;
Matrix5x5.copy(fCov.covMat, covMat.covMat);
s= Math.signum(Z[f] - Z[i]) * stepSize;
// LOGGER.log(Level.FINEST, " from "+(float)Z[i]+" to "+(float)Z[f]+" at "+(float)z+" By is "+bf[1]+" B is "+Math.sqrt(bf[0]*bf[0]+bf[1]*bf[1]+bf[2]*bf[2])/Bmax+" stepSize is "+s);
double s = Math.signum(Z[f] - Z[i]) * stepSize;
if(Math.signum(Z[f] - Z[i]) *(z+s)>Math.signum(Z[f] - Z[i]) *Z[f])
s=Math.signum(Z[f] - Z[i]) *Math.abs(Z[f]-z);

Expand Down Expand Up @@ -277,18 +249,9 @@ public void transportFixed(int sector, int i, int f, StateVec iVec, CovMat covMa
if (j == nSteps - 1) {
s = Math.signum(Z[f] - Z[i]) * Math.abs(z - Z[f]);
}
//LOGGER.log(Level.FINEST, " RK step num "+(j+1)+" = "+(float)s+" nSteps = "+nSteps);
double x = fVec.x;
double y = fVec.y;
z = fVec.z;
double tx = fVec.tx;
double ty = fVec.ty;
double Q = fVec.Q;
double dPath = fVec.deltaPath;
covMat.covMat = fCov.covMat;

rk.RK4transport(sector, s, dcSwim, covMat, fVec, fCov);

}

this.trackTraj.put(f, fVec);
Expand Down
Loading