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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
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.io.base.DataEvent;

import org.jlab.io.base.DataEvent;
import org.jlab.rec.dc.Constants;
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
import org.jlab.rec.dc.hit.FittedHit;
import org.jlab.rec.dc.hit.Hit;
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.detector.geant4.v2.DCGeant4Factory;

public class ClusterCleanerUtilities {

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

private List<ArrayList<Hit>> sortedHits;

public ClusterCleanerUtilities() {
Expand Down Expand Up @@ -194,7 +192,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
if((!isExceptionalCluster(newClus) && nLayers >= Constants.DC_MIN_NLAYERS)
|| (isExceptionalCluster(newClus) && nLayers >= Constants.DC_MIN_NLAYERS - 1)) {
//require consistency with line
cf.SetFitArray(newClus, "LC");
cf.SetFitArray(newClus, CoordSys.LC);
cf.Fit(newClus, true);
if ((nLayers == 6 && newClus.get_fitProb() > 0.9) || (nLayers == 5 && newClus.get_fitProb() > 0.85)
|| (nLayers == 4 && newClus.get_fitProb() > 0.75) || (nLayers == 3 && newClus.get_fitProb() > 0.65)) {
Expand All @@ -213,7 +211,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
int newcid = nextClsStartIndex;
for (FittedCluster cluster : splitclusters) {
cluster.set_Id(newcid++);
cf.SetFitArray(cluster, "LC");
cf.SetFitArray(cluster, CoordSys.LC);
cf.Fit(cluster, true);

FittedCluster bestCls = OverlappingClusterResolver(cluster, splitclusters);
Expand All @@ -229,7 +227,7 @@ public List<FittedCluster> ClusterSplitter(FittedCluster clus, int nextClsStartI
List<FittedCluster> selectedClusList2 = new ArrayList<>();
for (FittedCluster cluster : selectedClusList) {
cluster.set_Id(newcid++);
cf.SetFitArray(cluster, "LC");
cf.SetFitArray(cluster, CoordSys.LC);
cf.Fit(cluster, true);

FittedCluster bestCls = OverlappingClusterResolver(cluster, selectedClusList);
Expand Down Expand Up @@ -569,7 +567,7 @@ else if (index == 6) {
}
}

return cf.BestClusterSelector(arrayOfClus, "TSC");
return cf.BestClusterSelector(arrayOfClus, CoordSys.TSC);

}

Expand Down Expand Up @@ -680,7 +678,7 @@ else if (hitsInLayer.size() == 2) {
// for(FittedHit h : c)
// LOGGER.log(Level.INFO, h.printInfo());
//}
FittedCluster BestCluster = cf.BestClusterSelector(clusters, "LC");
FittedCluster BestCluster = cf.BestClusterSelector(clusters, CoordSys.LC);
//LOGGER.log(Level.INFO, " ---> selected cluster : ");
//for(FittedHit h : BestCluster)
// LOGGER.log(Level.INFO, h.printInfo());
Expand Down Expand Up @@ -752,13 +750,14 @@ public FittedCluster OverlappingClusterResolver(FittedCluster thisclus, List<Fit
return overlapingClusters.get(0);

}
/**

/**
* Prunes the input hit list to remove noise candidates; the algorithm finds
* contiguous hits in a layer (column) and removes hits according to the
* number (Nc) of such contiguous hits in a given layer.If Nc=3, keep only
the middle hit If Nc=4, keep only the first and last hit in that column;
if Nc > 4, keep the first 2 and last 2 hits in that column, if Nc > 10
remove all hits in that column.
* the middle hit If Nc=4, keep only the first and last hit in that column;
* if Nc > 4, keep the first 2 and last 2 hits in that column, if Nc > 10
* remove all hits in that column.
*
* @param hits the unfitted hits
* @return
Expand Down Expand Up @@ -971,8 +970,7 @@ else if (hitsInLayer.size() == 2) {
clusters.add(newClus);
}

FittedCluster BestCluster = cf.BestClusterSelector(clusters, "LC");
return BestCluster;
return cf.BestClusterSelector(clusters, CoordSys.LC);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jlab.detector.geant4.v2.DCGeant4Factory;
import org.jlab.io.base.DataEvent;

import org.jlab.io.base.DataEvent;
import org.jlab.io.evio.EvioDataBank;
import org.jlab.io.evio.EvioDataEvent;
import org.jlab.rec.dc.Constants;
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
import org.jlab.rec.dc.hit.Hit;
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
import org.jlab.rec.dc.hit.FittedHit;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.detector.geant4.v2.DCGeant4Factory;

/**
* A hit pruning algorithm to reject noise that gives a pattern of hits that are
Expand Down Expand Up @@ -216,12 +217,12 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane

for (FittedCluster clus : selectedClusList) {

cf.SetFitArray(clus, "LC");
cf.SetFitArray(clus, CoordSys.LC);
cf.Fit(clus, true);
if(!ct.isExceptionalFittedCluster(clus) && clus.get_fitProb()<Constants.HITBASEDTRKGMINFITHI2PROB) {
ct.IsolatedHitsPruner(clus);
//Refit
cf.SetFitArray(clus, "LC");
cf.SetFitArray(clus, CoordSys.LC);
cf.Fit(clus, true);
}
if (clus.get_fitProb() > Constants.HITBASEDTRKGMINFITHI2PROB ){
Expand All @@ -246,7 +247,7 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane
//fhit.set_AssociatedClusterID(clus.get_Id());
}

cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, true);
cf.SetResidualDerivedParams(clus, false, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false, local= false

Expand All @@ -273,7 +274,7 @@ public List<FittedCluster> FindHitBasedClusters(List<Hit> allhits, ClusterCleane
}
clus.removeAll(rmHits);
clus.addAll(addHits);
cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, false);
cf.SetSegmentLineParameters(clus.get(0).get_Z(), clus);
if (clus != null ) {
Expand Down Expand Up @@ -318,7 +319,7 @@ public List<FittedCluster> RecomposeClusters(Map<Integer, ArrayList<FittedHit>>

for (FittedCluster clus : clusters) {
if (clus != null) {
cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, true);
cf.SetResidualDerivedParams(clus, true, false, dcDetector); //calcTimeResidual=false, resetLRAmbig=false
cf.Fit(clus, false);
Expand Down Expand Up @@ -476,7 +477,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
}

}
cf.SetFitArray(Clus2, "TSC");
cf.SetFitArray(Clus2, CoordSys.TSC);
cf.Fit(Clus2, true);

if (Math.abs(clus.get_Chisq() - Clus2.get_Chisq()) < 1) {
Expand All @@ -488,7 +489,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,

for (FittedCluster clus : clusters) {

cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, true);

// update the hits
Expand All @@ -500,7 +501,7 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
double prevChi2 = 999999999;
double trkAngleFinal = 0;
while (Chi2Diff > 0) {
cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, true);
Chi2Diff = prevChi2 - clus.get_Chisq();
if (Chi2Diff > 0) {
Expand All @@ -519,11 +520,11 @@ public List<FittedCluster> FindTimeBasedClusters(DataEvent event,
for (FittedHit fhit : clus) {
fhit.updateHitPositionWithTime(event, trkAngleFinal, fhit.getB(), tab, DcDetector, tde);
}
cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, true);
cf.SetResidualDerivedParams(clus, true, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false

cf.SetFitArray(clus, "TSC");
cf.SetFitArray(clus, CoordSys.TSC);
cf.Fit(clus, false);

cf.SetSegmentLineParameters(clus.get(0).get_Z(), clus);
Expand Down Expand Up @@ -582,7 +583,7 @@ public EvioDataBank getLayerEfficiencies(List<FittedCluster> fclusters, List<Hit

int status = 0;
//fit
cf.SetFitArray(clus, "LC");
cf.SetFitArray(clus, org.jlab.rec.dc.cluster.ClusterFitter.CoordSys.LC);
cf.Fit(clus, true);

for (Hit hit : allhits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jlab.clas.clas.math.FastMath;
import org.jlab.detector.geant4.v2.DCGeant4Factory;

import org.jlab.geom.prim.Line3D;
import org.jlab.geom.prim.Point3D;
Expand All @@ -13,26 +11,38 @@
import org.jlab.rec.dc.track.fit.basefit.LineFitPars;
import org.jlab.rec.dc.track.fit.basefit.LineFitter;
import org.jlab.rec.dc.Constants;
import org.jlab.detector.geant4.v2.DCGeant4Factory;

public class ClusterFitter {

public static enum CoordSys {
LC (1, "LC"),
TSC (2, "TSC"),
LTS (3, "LTS");
public int id;
public String name;
CoordSys(int id, String name) {
this.id = id;
this.name = name;
}
}

private CoordSys coordinateSystem;

/**
* Fits a cluster to a line
*
*/
private LineFitPars FitPars;
private final List<ArrayList<Double>> FitArray = new ArrayList<ArrayList<Double>>();
private final List<Double> x = new ArrayList<Double>();
private final List<Double> y = new ArrayList<Double>();
private final List<Double> ex = new ArrayList<Double>();
private final List<Double> ey = new ArrayList<Double>();
private final List<ArrayList<Double>> FitArray = new ArrayList<>();
private final List<Double> x = new ArrayList<>();
private final List<Double> y = new ArrayList<>();
private final List<Double> ex = new ArrayList<>();
private final List<Double> ey = new ArrayList<>();
private final double stereo = Constants.COS6;

private String CoordinateSystem; // LC= local, TSC = tilted Sector
public ClusterFitter() {
// TODO Auto-generated constructor stub
}

public ClusterFitter() {}

public void reset() {
for(int i =0; i<FitArray.size(); i++)
FitArray.get(i).clear();
Expand All @@ -42,33 +52,24 @@ public void reset() {
ex.clear();
ey.clear();
}
public void SetFitArray(FittedCluster clus, String system) {

public void SetFitArray(FittedCluster clus, CoordSys system) {

Collections.sort(clus);
//for(int i =0; i<FitArray.size(); i++)
// FitArray.get(i).clear();
reset();
//double[][] fitArray = new double[4][clus.size()];
//double[] x = new double[clus.size()];
//double[] y = new double[clus.size()];
//double[] ex = new double[clus.size()];
//double[] ey = new double[clus.size()];


for (int i = 0; i < clus.size(); i++) {
if (system.equals("LC")) {
CoordinateSystem = "LC"; // local coordinate grid Delta_z = 1
if (system.equals(CoordSys.LC)) {
coordinateSystem = CoordSys.LC; // local coordinate grid Delta_z = 1
x.add(i, clus.get(i).get_lX());
ex.add(i, (double) 0);
y.add(i, clus.get(i).get_lY());
ey.add(i, (double) 1);
}
if (system.equals("TSC")) {
CoordinateSystem = "TSC"; // local tilted coordinate system Delta_z ~ cell size
if (system.equals(CoordSys.TSC)) {
coordinateSystem = CoordSys.TSC; // local tilted coordinate system Delta_z ~ cell size
x.add(i, clus.get(i).get_Z());
ex.add(i, (double) 0);
y.add(i, clus.get(i).get_X());
//ey[i]= clus.get(i).get_DocaErr(); //CODEFIX1
ey.add(i, clus.get(i).get_DocaErr() / stereo);
}

Expand All @@ -77,8 +78,8 @@ public void SetFitArray(FittedCluster clus, String system) {
FitArray.add((ArrayList<Double>) ex);
FitArray.add((ArrayList<Double>) y);
FitArray.add((ArrayList<Double>) ey);

}

/**
*
* @param clus fitted cluster
Expand Down Expand Up @@ -148,7 +149,6 @@ public void SetSegmentLineParameters(double x0, FittedCluster clus) {

} else {
System.err.println("Cluster Fit Params not set!!!");

}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ public void SetResidualDerivedParams(FittedCluster clus, boolean calcTimeResidua
}
}
if (resetLRAmbig) {
if ((CoordinateSystem.equals("LC") && Math.abs(residual) < 0.01) || (CoordinateSystem.equals("LTS")
if ((coordinateSystem.equals(CoordSys.LC) && Math.abs(residual) < 0.01) || (coordinateSystem.equals(CoordSys.LTS)
&& clus.get(i).get_Doca() / clus.get(i).get_CellSize() < 0.4)) { // DOCA require to be larger than 40% of cell size for hit-based tracking LR assignment
clus.get(i).set_LeftRightAmb(0);
}
Expand Down Expand Up @@ -241,11 +241,10 @@ public void SetResidualDerivedParams(FittedCluster clus, boolean calcTimeResidua
* @param system coordinate system in which the fit is performed
* @return the fitted cluster with the best fit chi2
*/
public FittedCluster BestClusterSelector(List<FittedCluster> clusters, String system) {
//init
public FittedCluster BestClusterSelector(List<FittedCluster> clusters, CoordSys system) {

FittedCluster BestCluster = null;
double bestChisq = 999999999.;
// double bestClusx0=0;

for (FittedCluster clusCand : clusters) {
if(isBrickWall(clusCand)) {
Expand All @@ -267,13 +266,10 @@ public FittedCluster BestClusterSelector(List<FittedCluster> clusters, String sy
if (chisq < bestChisq) {
bestChisq = chisq;
BestCluster = clusCand;
// bestClusx0 = FitArray[0][0];
}
}
//SetSegmentLineParameters(bestClusx0, BestCluster) ;

return BestCluster;

}

/**
Expand Down Expand Up @@ -320,5 +316,4 @@ private boolean isBrickWall(FittedCluster clusCand) {
return isBW;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jlab.io.base.DataEvent;
import org.jlab.rec.dc.Constants;
import org.jlab.rec.dc.cluster.ClusterFitter;
import org.jlab.rec.dc.cluster.ClusterFitter.CoordSys;
import org.jlab.rec.dc.hit.FittedHit;
import org.jlab.rec.dc.segment.Segment;
import org.jlab.rec.dc.timetodistance.TimeToDistanceEstimator;
Expand Down Expand Up @@ -216,18 +217,18 @@ private void recalcParsSegment(DataEvent event, Segment _Segment1, IndexedTable
fhit.updateHitPositionWithTime(event, trkAngle, fhit.getB(), tab, DcDetector, tde);
}

cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
cf.Fit(_Segment1.get_fittedCluster(), true);
trkAngle = _Segment1.get_fittedCluster().get_clusterLineFitSlope();

for (FittedHit fhit : _Segment1.get_fittedCluster()) {
fhit.updateHitPositionWithTime(event, trkAngle, fhit.getB(), tab, DcDetector, tde);
}
cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
cf.Fit(_Segment1.get_fittedCluster(), true);
cf.SetResidualDerivedParams(_Segment1.get_fittedCluster(), true, false, DcDetector); //calcTimeResidual=false, resetLRAmbig=false

cf.SetFitArray(_Segment1.get_fittedCluster(), "TSC");
cf.SetFitArray(_Segment1.get_fittedCluster(), CoordSys.TSC);
cf.Fit(_Segment1.get_fittedCluster(), false);

cf.SetSegmentLineParameters(_Segment1.get_fittedCluster().get(0).get_Z(), _Segment1.get_fittedCluster());
Expand Down
Loading