Skip to content

Commit e339fa8

Browse files
ftouchtetongtongcao
authored andcommitted
Improvements in the Kalman Filter for the AHDC (#1010)
1 parent 85f7410 commit e339fa8

File tree

12 files changed

+474
-740
lines changed

12 files changed

+474
-740
lines changed

reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Banks/RecoBankWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.jlab.rec.ahdc.Hit.Hit;
99
import org.jlab.rec.ahdc.PreCluster.PreCluster;
1010
import org.jlab.rec.ahdc.Track.Track;
11+
import org.apache.commons.math3.linear.RealVector;
12+
import org.apache.commons.math3.linear.RealMatrix;
1113

1214
import java.util.ArrayList;
1315

reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package org.jlab.rec.ahdc.Hit;
22

3+
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
4+
import org.apache.commons.math3.linear.ArrayRealVector;
5+
import org.apache.commons.math3.linear.RealMatrix;
6+
import org.apache.commons.math3.linear.RealVector;
7+
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
38
import org.jlab.geom.detector.alert.AHDC.AlertDCDetector;
49
import org.jlab.geom.prim.Line3D;
510
import org.jlab.geom.prim.Point3D;
11+
import org.jlab.geom.detector.alert.AHDC.AlertDCFactory;
612

713
public class Hit implements Comparable<Hit> {
814

9-
private final double thster = Math.toRadians(20.0);
1015
private final int id;
1116
private final int superLayerId;
1217
private final int layerId;
@@ -15,7 +20,7 @@ public class Hit implements Comparable<Hit> {
1520
private final double adc;
1621
private final double time;
1722

18-
private Line3D wireLine;
23+
private Line3D wireLine;
1924
private double phi;
2025
private double radius;
2126
private int nbOfWires;
@@ -26,7 +31,7 @@ public class Hit implements Comparable<Hit> {
2631
private double residual;
2732
private int trackId;
2833

29-
//updated constructor with ADC
34+
//updated constructor with ADC
3035
public Hit(int _Id, int _Super_layer, int _Layer, int _Wire, double _Doca, double _ADC, double _Time) {
3136
this.id = _Id;
3237
this.superLayerId = _Super_layer;
@@ -45,7 +50,7 @@ public void setWirePosition(AlertDCDetector factory) {
4550
//System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy);
4651
wireLine = factory.getSector(1).getSuperlayer(superLayerId).getLayer(layerId).getComponent(wireId).getLine();
4752
Point3D end = wireLine.end();
48-
this.nbOfWires = factory.getSector(1).getSuperlayer(superLayerId).getLayer(layerId).getNumComponents();
53+
this.nbOfWires = factory.getSector(1).getSuperlayer(superLayerId).getLayer(layerId).getNumComponents();
4954
this.phi = end.vectorFrom(0, 0, 0).phi();
5055
this.radius = end.distance(0, 0, end.z());
5156
this.x = end.x();
@@ -57,12 +62,27 @@ public String toString() {
5762
return "Hit{" + "_Super_layer=" + superLayerId + ", _Layer=" + layerId + ", _Wire=" + wireId + ", _Doca=" + doca + ", _Phi=" + phi + '}';
5863
}
5964

65+
// Should return
66+
// 0 if equality
67+
// +1 if this is bigger than arg0
68+
// -1 if this is lower than arg0
6069
@Override
6170
public int compareTo(Hit arg0) {
62-
if (this.superLayerId == arg0.superLayerId && this.layerId == arg0.layerId && this.wireId == arg0.wireId) {
63-
return 0;
64-
} else {
65-
return 1;
71+
if (this.superLayerId == arg0.superLayerId && this.layerId == arg0.layerId) { // same layer, so they have the same nbOfWires
72+
if (this.wireId == 1 && arg0.wireId == this.nbOfWires) {
73+
return 1;
74+
}
75+
else if (this.wireId == this.nbOfWires && arg0.wireId == 1) {
76+
return -1;
77+
}
78+
else {
79+
return Integer.compare(this.wireId, arg0.wireId);
80+
}
81+
}
82+
else {
83+
int this_value = 10*this.superLayerId + this.layerId;
84+
int value = 10*arg0.superLayerId + arg0.layerId;
85+
return Integer.compare(this_value, value);
6686
}
6787
}
6888

@@ -86,13 +106,13 @@ public double getDoca() {
86106
return doca;
87107
}
88108

89-
public Line3D getLine() {
90-
return wireLine;
91-
}
92-
93-
public double getRadius() {
94-
return radius;
95-
}
109+
public Line3D getLine() {
110+
return wireLine;
111+
}
112+
113+
public double getRadius() {
114+
return radius;
115+
}
96116

97117
public int getNbOfWires() {
98118
return nbOfWires;
@@ -146,4 +166,38 @@ public void setTrackId(int _trackId) {
146166
this.trackId = _trackId;
147167
}
148168

169+
public RealVector get_Vector() {
170+
return new ArrayRealVector(new double[]{this.doca});
171+
}
172+
173+
public RealMatrix get_MeasurementNoise() {
174+
return new Array2DRowRealMatrix(new double[][]{{0.09}});
175+
}
176+
177+
// a signature for KalmanFilter.Hit_beam
178+
public RealVector get_Vector_beam() {
179+
return null;
180+
}
181+
182+
public double distance(Point3D point3D) {
183+
return this.wireLine.distance(point3D).length();
184+
}
185+
186+
public static void main(String[] args) {
187+
AlertDCDetector factory = (new AlertDCFactory()).createDetectorCLAS(new DatabaseConstantProvider());
188+
System.out.println("Run test: comparison between two hits.");
189+
Hit h1 = new Hit(1,1,1,1,0,0,0);
190+
Hit h2 = new Hit(1,1,1,47,0,0,0);
191+
Hit h3 = new Hit(1,2,1,47,0,0,0);
192+
h1.setWirePosition(factory);
193+
h2.setWirePosition(factory);
194+
System.out.println("h1 : " + h1);
195+
System.out.println("h2 : " + h2);
196+
System.out.println("h3 : " + h3);
197+
System.out.println("numWires : " + h1.getNbOfWires());
198+
System.out.println("h1 compare to h2 : " + h1.compareTo(h2));
199+
System.out.println("h2 compare to h1 : " + h2.compareTo(h1));
200+
System.out.println("h1 compare to h3 : " + h1.compareTo(h3));
201+
}
202+
149203
}

reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) {
3535
}
3636

3737
RawDataBank bankDGTZ = new RawDataBank("AHDC::adc");
38-
bankDGTZ.read(event);
38+
bankDGTZ.read(event);
3939

4040
for (int i = 0; i < bankDGTZ.rows(); i++) {
4141
int id = bankDGTZ.trueIndex(i) + 1;
@@ -82,8 +82,8 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) {
8282
double doca = p0 + p1*Math.pow(time,1.0) + p2*Math.pow(time,2.0) + p3*Math.pow(time,3.0) + p4*Math.pow(time,4.0) + p5*Math.pow(time, 5.0);
8383
if (time < 0) doca = 0;
8484
Hit h = new Hit(id, superlayer, layer, wire, doca, adc, time);
85-
h.setWirePosition(detector);
86-
hits.add(h);
85+
h.setWirePosition(detector);
86+
hits.add(h);
8787
}
8888
}
8989
}

reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java

Lines changed: 0 additions & 181 deletions
This file was deleted.

0 commit comments

Comments
 (0)