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
@@ -0,0 +1,23 @@
package org.jlab.clas.tracking.utilities;

import org.apache.commons.math3.special.Gamma;

/** Chi-square probability utilities */
public class ProbChi2perNDF {

/**
* Returns the upper-tail probability (survival function, or p-value) of the
* chi-square distribution: P(X >= chi2) for X ~ χ²(ndf).
* @param chi2 the chi-square statistic
* @param ndf the number of degrees of freedom
* @return the probability of observing a chi-square value at least as large as {@code chi2}, in the range [0, 1]
*/
public static double prob(double chi2, int ndf) {
if(ndf <= 0)
return 0.0;
if(chi2 <= 0.0) { // edge cases follow ROOT's `TMath::Prob` conventions
return chi2 < 0.0 ? 0.0 : 1.0;
}
return Gamma.regularizedGammaQ(0.5 * ndf, 0.5 * chi2);
}
}
6 changes: 0 additions & 6 deletions common-tools/coat-libs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
<artifactId>j4ml-clas12</artifactId>
</dependency>

<dependency>
<groupId>org.jlab.plugins</groupId>
<artifactId>trackfitter</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.jlab.clas</groupId>
<artifactId>clas-io</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions reconstruction/cvt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jlab.plugins</groupId>
<artifactId>trackfitter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static double getRCUT() {
return RCUT;
}

public static void setRCUT(double r) {
private static void setRCUT(double r) {
RCUT = r;
}

Expand All @@ -281,7 +281,7 @@ public static double getZRANGE() {
return ZRANGE;
}

public static void setZRANGE(double zr) {
private static void setZRANGE(double zr) {
ZRANGE = zr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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;
import org.jlab.clas.tracking.utilities.ProbChi2perNDF;

/**
* A fitter which does sequential fit (for x, y coordinates) and then (for r, z
Expand All @@ -21,7 +21,6 @@ public class CosmicFitter {
private CosmicFitPars _rayfitoutput;

private LineFitPars _linefitparsRhoZ;
private LineFitPars _linefitparsYX;
/**
* Status of the HelicalTrackFit
*/
Expand Down Expand Up @@ -164,7 +163,7 @@ public FitStatus fit2(List<Double> X, List<Double> Y, List<Double> Z, List<Doubl

//Line fits
_linefitYX = new LineFitter();
boolean linefitstatusXYOK = _linefitYX.fitStatus(Y, X, errRt, new ArrayList<>(X.size()), X.size());
_linefitYX.fitStatus(Y, X, errRt, new ArrayList<>(X.size()), X.size());

_linefitRhoZ = new LineFitter();
boolean linefitstatusOK = _linefitRhoZ.fitStatus(Rho, Z, errRho, ErrZ, Z.size());
Expand All @@ -174,7 +173,6 @@ public FitStatus fit2(List<Double> X, List<Double> Y, List<Double> Z, List<Doubl
}
// Get the results of the fits
_linefitparsRhoZ = _linefitRhoZ.getFit();
_linefitparsYX = _linefitYX.getFit();

double fit_tandip = _linefitparsRhoZ.slope();
double fit_Z0 = _linefitparsRhoZ.intercept();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jlab.rec.cvt.fit;

import org.jlab.rec.cvt.trajectory.Ray;
import trackfitter.fitter.utilities.ProbChi2perNDF;
import org.jlab.clas.tracking.utilities.ProbChi2perNDF;

/**
* The fit parameters of a line fit returned by LineFitter
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.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -24,7 +23,7 @@
import org.jlab.rec.cvt.trajectory.Helix;
import org.jlab.rec.cvt.trajectory.StateVec;
import org.jlab.rec.cvt.trajectory.Trajectory;
import trackfitter.fitter.utilities.ProbChi2perNDF;
import org.jlab.clas.tracking.utilities.ProbChi2perNDF;

/**
* A class representing track candidates in the CVT. A track has a trajectory
Expand Down Expand Up @@ -328,9 +327,9 @@ else if(this.getChi2() > Constants.CHI2CUT * (this.getNDF() + 5))
return false;
if(this.getNDF() < Constants.NDFCUT)
return false;
if(this.getHelix().radius() < Constants.getInstance().getRCUT())
if(this.getHelix().radius() < Constants.getRCUT())
return false;
if(Math.abs(Geometry.getInstance().getTargetZOffset()-this.getHelix().getZ0()) > Geometry.getInstance().getTargetHalfLength()+Constants.getInstance().getZRANGE())
if(Math.abs(Geometry.getInstance().getTargetZOffset()-this.getHelix().getZ0()) > Geometry.getInstance().getTargetHalfLength()+Constants.getZRANGE())
return false;
else
return true;
Expand Down
5 changes: 0 additions & 5 deletions reconstruction/dc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@
<artifactId>snr</artifactId>
<version>14.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jlab.plugins</groupId>
<artifactId>trackfitter</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jlab.clas</groupId>
<artifactId>swim-tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.jlab.rec.dc.segment.Segment;
import org.jlab.rec.dc.track.Track;

import trackfitter.fitter.utilities.*;
import org.jlab.clas.tracking.utilities.ProbChi2perNDF;

/**
* A class to fill the reconstructed DC banks
Expand All @@ -36,8 +36,8 @@ public RecoBankWriter(Banks names) {

public void updateListsWithClusterInfo(List<FittedHit> fhits,
List<FittedCluster> clusters) {
ArrayList rmHits = new ArrayList<FittedHit>();
ArrayList addHits = new ArrayList<FittedHit>();
List<FittedHit> rmHits = new ArrayList<>();
List<FittedHit> addHits = new ArrayList<>();
for (int i = 0; i < clusters.size(); i++) {
clusters.get(i).set_Id(i + 1);
for (int j = 0; j < clusters.get(i).size(); j++) {
Expand Down Expand Up @@ -204,8 +204,6 @@ public DataBank fillHBClustersBank(DataEvent event, List<FittedCluster> cluslist
DataBank bank = event.createBank(name, cluslist.size());

int[] hitIdxArray = new int[12];
if(cluslist==null)
return bank;
for (int i = 0; i < cluslist.size(); i++) {
if (cluslist.get(i) == null || cluslist.get(i).get_Id() == -1) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.jlab.rec.dc.segment.Segment;
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
import org.jlab.utils.groups.IndexedTable;
import trackfitter.fitter.LineFitter;
import org.jlab.rec.dc.track.fit.basefit.LineFitter;

/**
* A class with methods used to find lists of crosses. This is the Pattern Recognition step used in track seeding, to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jlab.clas.clas.math.FastMath;
import org.jlab.clas.swimtools.Swim;
import org.jlab.detector.geant4.v2.DCGeant4Factory;
import org.jlab.geom.prim.Line3D;
Expand All @@ -24,8 +23,8 @@
import org.jlab.rec.dc.trajectory.Trajectory;
import org.jlab.rec.dc.trajectory.TrajectoryFinder;

import trackfitter.fitter.LineFitPars;
import trackfitter.fitter.LineFitter;
import org.jlab.rec.dc.track.fit.basefit.LineFitter;
import org.jlab.rec.dc.track.fit.basefit.LineFitPars;

import org.jlab.clas.tracking.kalmanfilter.Surface;
import org.jlab.clas.tracking.kalmanfilter.zReference.KFitter;
Expand Down Expand Up @@ -95,47 +94,47 @@ private boolean PassNSuperlayerTracking(List<Cross> crossesInTrk, Track cand) {
return pass;
}

private double getHitBasedFitChi2ToCrosses(int sector, double x1, double y1, double z1,
double x2, double y2, double z2, double x3,
double y3, double z3, double p, int q, double x,
double y, double z, double tanThX, double tanThY, Swim dcSwim) {
double pz = p / Math.sqrt(tanThX * tanThX + tanThY * tanThY + 1);

dcSwim.SetSwimParameters(x, y, z,
-pz * tanThX, -pz * tanThY, -pz,
-q);
double chi2 = 0; // assume err =1 on points
double[] R = dcSwim.SwimToPlaneTiltSecSys(sector, z3);
if (R == null) {
return Double.POSITIVE_INFINITY;
}

//chi2 += (R[0] - x3) * (R[0] - x3) + (R[1] - y3) * (R[1] - y3);
chi2 += (Math.sqrt(R[0] * R[0] + R[1] * R[1]) - Math.sqrt(x3 * x3 + y3 * y3)) * (Math.sqrt(R[0] * R[0] + R[1] * R[1]) - Math.sqrt(x3 * x3 + y3 * y3));
dcSwim.SetSwimParameters(R[0], R[1], R[2],
R[3], R[4], R[5],
-q);
R = dcSwim.SwimToPlaneTiltSecSys(sector, z2);
if (R == null) {
return Double.POSITIVE_INFINITY;
}

dcSwim.SetSwimParameters(R[0], R[1], R[2],
R[3], R[4], R[5],
-q);
chi2 += (R[0] - x2) * (R[0] - x2) + (R[1] - y2) * (R[1] - y2);
dcSwim.SetSwimParameters(R[0], R[1], R[2],
R[3], R[4], R[5],
-q);
R = dcSwim.SwimToPlaneTiltSecSys(sector, z1);
if (R == null) {
return Double.POSITIVE_INFINITY;
}

chi2 += (R[0] - x1) * (R[0] - x1) + (R[1] - y1) * (R[1] - y1);

return chi2;
}
// private double getHitBasedFitChi2ToCrosses(int sector, double x1, double y1, double z1,
// double x2, double y2, double z2, double x3,
// double y3, double z3, double p, int q, double x,
// double y, double z, double tanThX, double tanThY, Swim dcSwim) {
// double pz = p / Math.sqrt(tanThX * tanThX + tanThY * tanThY + 1);
//
// dcSwim.SetSwimParameters(x, y, z,
// -pz * tanThX, -pz * tanThY, -pz,
// -q);
// double chi2 = 0; // assume err =1 on points
// double[] R = dcSwim.SwimToPlaneTiltSecSys(sector, z3);
// if (R == null) {
// return Double.POSITIVE_INFINITY;
// }
//
// //chi2 += (R[0] - x3) * (R[0] - x3) + (R[1] - y3) * (R[1] - y3);
// chi2 += (Math.sqrt(R[0] * R[0] + R[1] * R[1]) - Math.sqrt(x3 * x3 + y3 * y3)) * (Math.sqrt(R[0] * R[0] + R[1] * R[1]) - Math.sqrt(x3 * x3 + y3 * y3));
// dcSwim.SetSwimParameters(R[0], R[1], R[2],
// R[3], R[4], R[5],
// -q);
// R = dcSwim.SwimToPlaneTiltSecSys(sector, z2);
// if (R == null) {
// return Double.POSITIVE_INFINITY;
// }
//
// dcSwim.SetSwimParameters(R[0], R[1], R[2],
// R[3], R[4], R[5],
// -q);
// chi2 += (R[0] - x2) * (R[0] - x2) + (R[1] - y2) * (R[1] - y2);
// dcSwim.SetSwimParameters(R[0], R[1], R[2],
// R[3], R[4], R[5],
// -q);
// R = dcSwim.SwimToPlaneTiltSecSys(sector, z1);
// if (R == null) {
// return Double.POSITIVE_INFINITY;
// }
//
// chi2 += (R[0] - x1) * (R[0] - x1) + (R[1] - y1) * (R[1] - y1);
//
// return chi2;
// }

/*
** a: parameter a for fitting function f(x) = a*z^2 + b*z + c in xz plane
Expand Down Expand Up @@ -208,7 +207,7 @@ private int calcInitTrkQ(double a, double TORSCALE) {
}

public List<Track> getTrackCandsAI(CrossList crossList, DCGeant4Factory DcDetector, Swim dcSwim, HBTrackStateEstimator hbTSEstimator){
List<Track> cands = new ArrayList();
List<Track> cands = new ArrayList<>();

for (List<Cross> aCrossList : crossList) {
Track cand = new Track();
Expand Down Expand Up @@ -752,24 +751,6 @@ else if(t1.get_FitChi2()/t1.get_FitNDF()==t2.get_FitChi2()/t2.get_FitNDF() && i>
trkcands.addAll(selectedTracks);
}

/**
* @param selectedTracks the list of selected tracks
* @param selectedTrk the selected track
* @return a boolean indicating if the track is in the list
*/
private boolean ListContainsTrack(List<Track> selectedTracks, Track selectedTrk) {
boolean isInList = false;
for (Track trk : selectedTracks) {
if (trk == null) {
continue;
}
if (trk.get_Id() == selectedTrk.get_Id()) {
isInList = true;
}
}
return isInList;
}

/**
* @param track the track
* @param trkcands the list of candidates
Expand Down Expand Up @@ -880,31 +861,31 @@ public void setHitDoubletsInfo(Segment seg) {
}
}

private double calcCurvSign(Track cand) {
double P0x = cand.get(0).get_Point().z();
double P1x = cand.get(1).get_Point().z();
double P2x = cand.get(2).get_Point().z();
double P0y = cand.get(0).get_Point().x();
double P1y = cand.get(1).get_Point().x();
double P2y = cand.get(2).get_Point().x();

if (Math.abs(P1x - P0x) < 1.0e-18 || Math.abs(P2x - P1x) < 1.0e-18) {
return 0.0;
}

// Find the intersection of the lines joining the innermost to middle and middle to outermost point
double ma = (P1y - P0y) / (P1x - P0x);
double mb = (P2y - P1y) / (P2x - P1x);

if (Math.abs(mb - ma) < 1.0e-18) {
return 0.0;
}

double xcen = 0.5 * (ma * mb * (P0y - P2y) + mb * (P0x + P1x) - ma * (P1x + P2x)) / (mb - ma);
double ycen = (-1. / mb) * (xcen - 0.5 * (P1x + P2x)) + 0.5 * (P1y + P2y);

return Math.signum(ycen);
}
// private double calcCurvSign(Track cand) {
// double P0x = cand.get(0).get_Point().z();
// double P1x = cand.get(1).get_Point().z();
// double P2x = cand.get(2).get_Point().z();
// double P0y = cand.get(0).get_Point().x();
// double P1y = cand.get(1).get_Point().x();
// double P2y = cand.get(2).get_Point().x();
//
// if (Math.abs(P1x - P0x) < 1.0e-18 || Math.abs(P2x - P1x) < 1.0e-18) {
// return 0.0;
// }
//
// // Find the intersection of the lines joining the innermost to middle and middle to outermost point
// double ma = (P1y - P0y) / (P1x - P0x);
// double mb = (P2y - P1y) / (P2x - P1x);
//
// if (Math.abs(mb - ma) < 1.0e-18) {
// return 0.0;
// }
//
// double xcen = 0.5 * (ma * mb * (P0y - P2y) + mb * (P0x + P1x) - ma * (P1x + P2x)) / (mb - ma);
// double ycen = (-1. / mb) * (xcen - 0.5 * (P1x + P2x)) + 0.5 * (P1y + P2y);
//
// return Math.signum(ycen);
// }

private List<Track> findStraightTracks(CrossList crossList, DCGeant4Factory DcDetector, double TORSCALE, Swim dcSwim) {

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

import trackfitter.fitter.utilities.ProbChi2perNDF;
import org.jlab.clas.tracking.utilities.ProbChi2perNDF;

/**
* The fit parameters of a line fit returned by LineFitter
Expand Down
Loading
Loading