Skip to content

Commit e20330f

Browse files
New features for ALERT Kalman filter+optimized parameters (#445)
* Optimization of Kalman Filter: * adjusted number of filtering iterations from 10 to 5; * adjusted step size dx for calculation of ddoca/dx from 10^8 to 10^5; * Added AHDC hits residuals (post-fit and pre-fit) in the output: * residuals in the AHDC::Hits list in the alert.json file; * filling the hits residuals in the RecoBankWriter; * added residual and residual_prefit in ahdc/Hit/Hit.java * added a identification flag to match ahdc/KalmanFilter/Hit.java to ahdc/Hit/Hit.java * Successfully affected the calculated hit residual to the correct AHDC::Hit. * Fixed and improved the calculation of the post-fit residuals: * affecting the track parameters to the KFTrack right after the fit; * redo a forward indicators pass without correction; * * Cleaning the Kalman filter code: - removed all "cylindrical coordinates" vector and measurement functions; - renamed all preexisting vector and measurement function with their original name. - removed many commented printouts. * Attempt to include hit "sign" / left-right disambiguation: * added "virtual wires" located at the distance-of-closest-approach of the actual wire, on each side of the wire; * added hit sign parameter in KalmanFilter/Hit class; * added a new distance function to KalmanFilter/Hit class calculate the distance of a point to the correct virtual wire depending on the sign; * attempt to modify the "h" function to call new distance function * Fix of a parameter modified by mistake. * Added a second definition of BackwardIndicators in AHDC/KalmanFilter to be able to initialize a vertex. * Added a flag setDefinedVertex to AHDC/KalmanFilter and KFitter to define "hit_beam" vertex. * Reset Niter and ddoca step size parameters to 10, 1.e-8 respectively. * Added reading of wire ADC from the AHDC HitReader, and functions to access ADC for AHDC/Hit/Hit and AHDC/KalmanFilter/Hit. Added filtering of two hits on same superlayer/layer based on ADC (largest ADC is kept) and use info to determine the hit sign. * Added an option to build the initial track with just the hits combination and preset fixed parameters in AHDCEngine. Added a function in AHDC/KalmanFilter/Hit.java to calculate the measurement vector if we have a sign. * Substituted call of default hit vector and hit measurement functions with hit vector and measurement functions that handle hit left/right disambiguation. * Started to reintroduce the hit sign. * Save state: back to status quo before revising sign. * Added variable measurement error for hits with sign defined, with tracks on the wrong side. * Implemented varaible measurement error for signed hits: * if track on right side of wire, normal error; * if track on wrong side of wire, inflated error; Ensured reordering of hits by increasing phi; added exception for "rollover" around phi = pi; * fixed once and for all the convention for hit sign: sign >0 if phi_expected state > phi_wire * Tried to introduce a "pull" to the track on the correct sign of a wire by setting the measurement on the correct "virtual wire" with a larger error. * Revert "Tried to introduce a "pull" to the track on the correct sign of a wire by setting the measurement on the correct "virtual wire" with a larger error." This reverts commit 9bf4715. * Fixed the convention for the "virtual wires": wire "minus" ("plus") at +deltaphi (-deltaphi) since wire x, y position depend on -R*sin(phi), -R cos(phi) respectively. * Improved the functions to calculate hit vector: returns doca if sign is 0 or if sign is good. * Added a hit distance function with goodsign as input, and H (measurement matrix) function with goodsign as an input. * Added (commented) calls of functions with sign. * Added a simple handle to disable reading of MC variables. * Rerolled to fitting with no double hit. * Harmonized simulation flag: - one simulation flag is declared in AHDCengine and defined as false; - it is now propagated into KalmanFilter. * Added a check to read MC hits in AHDC_engine. --------- Co-authored-by: Mathieu Ouillon <[email protected]>
1 parent 3f00dfa commit e20330f

File tree

10 files changed

+333
-250
lines changed

10 files changed

+333
-250
lines changed

etc/bankdefs/hipo4/alert.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@
181181
"name": "Doca",
182182
"type": "D",
183183
"info": "distance od closest approch (mm)"
184+
}, {
185+
"name": "residual",
186+
"type": "D",
187+
"info": "residual (mm)"
188+
}, {
189+
"name": "residual_prefit",
190+
"type": "D",
191+
"info": "residual pre-fit (mm)"
184192
}
185193
]
186194
}, {

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
@@ -24,6 +24,8 @@ public DataBank fillAHDCHitsBank(DataEvent event, ArrayList<Hit> hitList) {
2424
bank.setByte("superlayer", i, (byte) hitList.get(i).getSuperLayerId());
2525
bank.setInt("wire", i, hitList.get(i).getWireId());
2626
bank.setDouble("Doca", i, hitList.get(i).getDoca());
27+
bank.setDouble("residual", i, hitList.get(i).getResidual());
28+
bank.setDouble("residual_prefit", i, hitList.get(i).getResidualPrefit());
2729
}
2830

2931
return bank;

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ public class Hit implements Comparable<Hit> {
99
private final int layerId;
1010
private final int wireId;
1111
private final double doca;
12+
private final double adc;
1213

1314
private double phi;
1415
private double radius;
1516
private int nbOfWires;
1617
private boolean use = false;
1718
private double x;
1819
private double y;
20+
private double residual_prefit;
21+
private double residual;
1922

20-
public Hit(int _Id, int _Super_layer, int _Layer, int _Wire, double _Doca) {
23+
//updated constructor with ADC
24+
public Hit(int _Id, int _Super_layer, int _Layer, int _Wire, double _Doca, double _ADC) {
2125
this.id = _Id;
2226
this.superLayerId = _Super_layer;
2327
this.layerId = _Layer;
2428
this.wireId = _Wire;
2529
this.doca = _Doca;
30+
this.adc = _ADC;
2631
wirePosition();
32+
this.residual_prefit = 0.0;
33+
this.residual = 0.0;
2734
}
2835

2936
private void wirePosition() {
@@ -130,4 +137,22 @@ public double getY() {
130137
}
131138

132139
public double getPhi() {return phi;}
140+
141+
public double getADC() {return adc;}
142+
143+
public double getResidual() {
144+
return residual;
145+
}
146+
147+
public double getResidualPrefit() {
148+
return residual_prefit;
149+
}
150+
151+
public void setResidual(double resid) {
152+
this.residual = resid;
153+
}
154+
155+
public void setResidualPrefit(double resid) {
156+
this.residual_prefit = resid;
157+
}
133158
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public void fetch_AHDCHits(DataEvent event) {
3232
int layer = number % 10;
3333
int superlayer = (int) (number % 100) / 10;
3434
int wire = bankDGTZ.getShort("component", i);
35+
double adc = bankDGTZ.getInt("ADC", i);
3536
double doca = bankDGTZ.getShort("ped", i) / 1000.0;
3637

37-
hits.add(new Hit(id, superlayer, layer, wire, doca));
38+
hits.add(new Hit(id, superlayer, layer, wire, doca, adc));
3839
}
3940
}
4041
this.set_AHDCHits(hits);
@@ -75,4 +76,4 @@ public void set_TrueAHDCHits(ArrayList<TrueHit> _TrueAHDCHits) {
7576
this._TrueAHDCHits = _TrueAHDCHits;
7677
}
7778

78-
}
79+
}

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

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ public class Hit implements Comparable<Hit> {
1919
private final double r;
2020
private final double phi;
2121
private final double doca;
22-
private final double adc;
22+
private double adc;
2323
private final double numWires;
2424
private final Line3D line3D;
25-
26-
// Comparison with: common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java
27-
// here, SuperLayer, Layer, Wire, start from 1
28-
// in AlertDCFactory, same variables start from 1
25+
private final Line3D line3D_plus;
26+
private final Line3D line3D_minus;
27+
private int hitidx;
28+
private int hitsign;
29+
30+
// Comparison with: common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java
31+
// here, SuperLayer, Layer, Wire, start from 1
32+
// in AlertDCFactory, same variables start from 1
2933
public Hit(int superLayer, int layer, int wire, int numWire, double r, double doca) {
3034
this.superLayer = superLayer;
3135
this.layer = layer;
@@ -34,6 +38,8 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do
3438
this.doca = doca;
3539
this.numWires = numWire;
3640
this.adc = 0;//placeholder
41+
this.hitidx = -1;
42+
this.hitsign = 0;
3743

3844
final double DR_layer = 4.0;//OK
3945
final double round = 360.0;//OK
@@ -104,42 +110,65 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do
104110
Line3D wireLine = new Line3D(lPoint, rPoint);
105111
//wireLine.show();
106112
this.line3D = wireLine;
107-
}
108-
109-
//hit measurement vector in cylindrical coordinates: r, phi, z
110-
public RealVector get_Vector() {
111-
// final double costhster = Math.cos(thster);
112-
// final double sinthster = Math.cos(thster);
113-
RealVector wire_meas = new ArrayRealVector(new double[]{this.r(), this.phi(), 0});
114-
// Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire: needed?
115-
return wire_meas;//.multiply(stereo_rotation);
113+
114+
//calculate the "virtual" left and right wires accounting for the DOCA
115+
double deltaphi = Math.asin(this.doca/R_layer);
116+
double wx_plus = -R_layer * Math.sin( alphaW_layer * (this.wire-1) - deltaphi );//OK
117+
double wy_plus = -R_layer * Math.cos( alphaW_layer * (this.wire-1) - deltaphi );//OK
118+
119+
double wx_plus_end = -R_layer * Math.sin( alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)) - deltaphi );//OK
120+
double wy_plus_end = -R_layer * Math.cos( alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)) - deltaphi );//OK
121+
122+
line = new Line3D(wx_plus, wy_plus, -zl/2, wx_plus_end, wy_plus_end, zl/2);
123+
lPoint = new Point3D();
124+
rPoint = new Point3D();
125+
lPlane.intersection(line, lPoint);
126+
rPlane.intersection(line, rPoint);
127+
128+
wireLine = new Line3D(lPoint, rPoint);
129+
this.line3D_plus = wireLine;
130+
131+
double wx_minus = -R_layer * Math.sin( alphaW_layer * (this.wire-1) + deltaphi );//OK
132+
double wy_minus = -R_layer * Math.cos( alphaW_layer * (this.wire-1) + deltaphi );//OK
133+
134+
double wx_minus_end = -R_layer * Math.sin( alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)) + deltaphi );//OK
135+
double wy_minus_end = -R_layer * Math.cos( alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)) + deltaphi );//OK
136+
137+
line = new Line3D(wx_minus, wy_minus, -zl/2, wx_minus_end, wy_minus_end, zl/2);
138+
lPoint = new Point3D();
139+
rPoint = new Point3D();
140+
lPlane.intersection(line, lPoint);
141+
rPlane.intersection(line, rPoint);
142+
143+
wireLine = new Line3D(lPoint, rPoint);
144+
this.line3D_minus = wireLine;
145+
116146
}
117147

118-
//hit measurement vector in 1 dimension: minimize distance - doca
119-
public RealVector get_Vector_simple() {
148+
//hit measurement vector in 1 dimension: minimize distance - doca
149+
public RealVector get_Vector() {
120150
return new ArrayRealVector(new double[]{this.doca});
121151
}
122152

123-
//hit measurement vector in 1 dimension: minimize distance - doca - adds hit "sign"
124-
public RealVector get_Vector_sign(int sign) {
125-
// Attempt: multiply doca by sign
126-
return new ArrayRealVector(new double[]{sign*this.doca});
153+
//hit measurement vector in 1 dimension with sign: if sign = 0, return doca, otherwise return 0
154+
public RealVector get_Vector(int sign, boolean goodsign) {
155+
if(sign == 0 || goodsign){
156+
return new ArrayRealVector(new double[]{this.doca});
157+
}else{
158+
return new ArrayRealVector(new double[]{0.0});
159+
}
127160
}
128161

129-
public RealMatrix get_MeasurementNoise() {
130-
final double costhster = Math.cos(thster);
131-
final double sinthster = Math.cos(thster);
132-
//dR = 0.1m dphi = pi dz = L/2
133-
Array2DRowRealMatrix wire_noise = new Array2DRowRealMatrix(new double[][]{{0.1, 0.0, 0.0}, {0.0, Math.atan(0.1/this.r), 0.0}, {0.0, 0.0, 150.0/costhster}});//uncertainty matrix in wire coordinates
134-
Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire
135-
wire_noise.multiply(stereo_rotation);
136-
137-
return wire_noise.multiply(wire_noise);
138-
//
162+
public RealMatrix get_MeasurementNoise() {
163+
return new Array2DRowRealMatrix(new double[][]{{0.0225}});
139164
}
140-
141-
public RealMatrix get_MeasurementNoise_simple() {
142-
return new Array2DRowRealMatrix(new double[][]{{0.01}});
165+
166+
public RealMatrix get_MeasurementNoise(boolean goodsign) {
167+
if(goodsign){
168+
return new Array2DRowRealMatrix(new double[][]{{0.0225}});
169+
}else{
170+
return new Array2DRowRealMatrix(new double[][]{{2*this.doca*this.doca}});
171+
}
143172
}
144173

145174
public double doca() {
@@ -151,8 +180,6 @@ public double doca() {
151180
public double phi() {return phi;}//at z = 0;
152181

153182
public double phi(double z) {
154-
// double x_0 = r*sin(phi);
155-
// double y_0 = r*cos(phi);
156183
double x_z = r*Math.sin( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) );
157184
double y_z = r*Math.cos( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) );
158185
return Math.atan2(x_z, y_z);
@@ -161,10 +188,16 @@ public double phi(double z) {
161188
public Line3D line() {return line3D;}
162189

163190
public double distance(Point3D point3D) {
164-
//System.out.println("Calculating distance: ");
165-
//this.line3D.show();
166-
//point3D.show();
167-
//System.out.println(" d = " + this.line3D.distance(point3D).length());
191+
return this.line3D.distance(point3D).length();
192+
}
193+
194+
public double distance(Point3D point3D, int sign, boolean goodsign) {
195+
//if(sign!=0)
196+
//System.out.println(" r " + this.r + " phi " + this.phi + " doca " + this.doca + " sign " + sign + " distance " + this.line3D.distance(point3D).length() + " (sign 0) " + this.line3D_plus.distance(point3D).length() + " (sign+) " + this.line3D_minus.distance(point3D).length() + " (sign-) ");
197+
if(!goodsign){
198+
if(sign>0)return this.line3D_plus.distance(point3D).length();
199+
if(sign<0)return this.line3D_minus.distance(point3D).length();
200+
}
168201
return this.line3D.distance(point3D).length();
169202
}
170203

@@ -211,12 +244,33 @@ public double getADC() {
211244
return adc;
212245
}
213246

247+
public void setADC(double _adc) {
248+
this.adc = _adc;
249+
}
250+
214251
public Line3D getLine3D() {
215252
return line3D;
216253
}
217254

218255
public double getNumWires() {
219256
return numWires;
220257
}
258+
259+
public int getHitIdx() {
260+
return hitidx;
261+
}
262+
263+
public void setHitIdx(int idx) {
264+
this.hitidx = idx;
265+
}
266+
267+
public int getSign() {
268+
return hitsign;
269+
}
270+
271+
public void setSign(int sign) {
272+
this.hitsign = sign;
273+
}
274+
221275
}
222276

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Hit_beam extends Hit {
99
double r,phi;
1010

1111
public Hit_beam(int superLayer, int layer, int wire, int numWire, double doca, double x, double y , double z) {
12-
super(0, 0, 0, 0, Math.hypot(x,y), 0);
12+
super(0, 0, 0, 0, Math.hypot(x,y), 0);
1313
this.x = x;
1414
this.y = y;
1515
this.z = z;

0 commit comments

Comments
 (0)