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 @@ -69,13 +69,12 @@ public String getName() {
* @return <code>true</code> if we have a torus
*/
public boolean hasTorus() {
for (IMagField field : this) {
if (field instanceof Torus) {
return true;
}
}

return false;
for (int i=0; i<this.size(); i++) {
if (this.get(i) instanceof Torus) {
return true;
}
}
return false;
}

/**
Expand All @@ -84,12 +83,11 @@ public boolean hasTorus() {
* @return <code>true</code> if we have a solenoid
*/
public boolean hasSolenoid() {
for (IMagField field : this) {
if (field instanceof Solenoid) {
for (int i=0; i<this.size(); i++) {
if (this.get(i) instanceof Solenoid) {
return true;
}
}

return false;
}

Expand All @@ -99,8 +97,8 @@ public boolean hasSolenoid() {
* @return <code>true</code> if we have a transverse solenoid
*/
public boolean hasTransverseSolenoid() {
for (IMagField field : this) {
if (field instanceof TransverseSolenoid) {
for (int i=0; i<this.size(); i++) {
if (this.get(i) instanceof TransverseSolenoid) {
return true;
}
}
Expand All @@ -111,35 +109,35 @@ public boolean hasTransverseSolenoid() {
@Override
public float getB1(int index) {
float b = 0f;
for (IMagField field : this) {
b += field.getB1(index);
for (int i=0; i<this.size(); i++) {
b += this.get(i).getB1(index);
}
return b;
}

@Override
public float getB2(int index) {
float b = 0f;
for (IMagField field : this) {
b += field.getB2(index);
for (int i=0; i<this.size(); i++) {
b += this.get(i).getB2(index);
}
return b;
}

@Override
public float getB3(int index) {
float b = 0f;
for (IMagField field : this) {
b += field.getB3(index);
for (int i=0; i<this.size(); i++) {
b += this.get(i).getB3(index);
}
return b;
}

@Override
public float getMaxFieldMagnitude() {
float max = 0;
for (IMagField field : this) {
max = Math.max(max, field.getMaxFieldMagnitude());
for (int i=0; i<this.size(); i++) {
max = Math.max(max, this.get(i).getMaxFieldMagnitude());
}
return max;
}
Expand All @@ -157,16 +155,15 @@ public double getScaleFactor() {
@Override
public void printConfiguration(PrintStream ps) {
ps.println("COMPOSITE FIELD");
for (IMagField field : this) {
field.printConfiguration(ps);

for (int i=0; i<this.size(); i++) {
this.get(i).printConfiguration(ps);
}
}

@Override
public boolean contains(double x, double y, double z) {
for (IMagField field : this) {
if (field.contains(x, y, z)) {
for (int i=0; i<this.size(); i++) {
if (this.get(i).contains(x, y, z)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,33 @@
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;
import org.jlab.geom.prim.Vector3D;
import org.jlab.rec.dc.hit.FittedHit;
import org.jlab.rec.dc.track.fit.basefit.LineFitPars;
import org.jlab.rec.dc.track.fit.basefit.LineFitter;
import org.jlab.rec.dc.Constants;

public class ClusterFitter {


/**
* 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,18 +39,11 @@ public void reset() {
ex.clear();
ey.clear();
}

public void SetFitArray(FittedCluster clus, String 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")) {
Expand All @@ -77,8 +67,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 @@ -242,38 +232,35 @@ public void SetResidualDerivedParams(FittedCluster clus, boolean calcTimeResidua
* @return the fitted cluster with the best fit chi2
*/
public FittedCluster BestClusterSelector(List<FittedCluster> clusters, String system) {
//init

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

for (FittedCluster clusCand : clusters) {
if(isBrickWall(clusCand)) {
for (int i=0; i<clusters.size(); i++) {
if (isBrickWall(clusters.get(i))) {
int LRSum=0;
for(FittedHit hit : clusCand) {
LRSum+=hit.get_LeftRightAmb();
for(int j=0; j<clusters.get(i).size(); j++) {
LRSum += clusters.get(i).get(j).get_LeftRightAmb();
}
if(LRSum!=0)
continue;
}
SetFitArray(clusCand, system); // set the array of measurements according to the system used in the analysis
// set the array of measurements according to the system used in the analysis
SetFitArray(clusters.get(i), system);
// do the fit and get the chisq
Fit(clusCand, true);
Fit(clusters.get(i), true);
if (FitPars == null) {
continue;
}
double chisq = FitPars.chisq();

if (chisq < bestChisq) {
bestChisq = chisq;
BestCluster = clusCand;
// bestClusx0 = FitArray[0][0];
BestCluster = clusters.get(i);
}
}
//SetSegmentLineParameters(bestClusx0, BestCluster) ;

return BestCluster;

}

/**
Expand Down Expand Up @@ -306,19 +293,22 @@ private Point3D get_PointOnLine(double d, double the_slope,
*/
private boolean isBrickWall(FittedCluster clusCand) {
boolean isBW = true;
int sumWireNum = 0;
if(clusCand.size()!=6)
isBW=false;

for(FittedHit hit : clusCand) {
sumWireNum+=hit.get_Wire();
if (clusCand.size() != 6) {
isBW = false;
}
else {
int sumWireNum = 0;
for (int i=0; i<clusCand.size(); i++) {
sumWireNum += clusCand.get(i).get_Wire();
}
for (int i=0; i<clusCand.size(); i++) {
if (clusCand.get(i).get_Wire()*clusCand.size()!=sumWireNum) {
isBW = false;
break;
}
}
}
for(FittedHit hit : clusCand) {
if(hit.get_Wire()*clusCand.size()!=sumWireNum)
isBW = false;
}
return isBW;
}


}