Skip to content

Commit b315bae

Browse files
ftouchtetongtongcao
authored andcommitted
Implement the electron vertex for AHDC (#1077)
* implement electron vertex for ahdc * convert vz_constraint to mm * test alignement for clas and ahdc * restore alignement at 0 * fix alert engine for ai track and atof matching * fix alignement sign * do not apply vertex shift for simulation * add ahdc geometry verification in the test * make the error on the ahdc distance dependent on adc and time * correct the error formula * correct the chi2 calculation * fix chi2 computation * remove redundancy
1 parent 4ffa25f commit b315bae

4 files changed

Lines changed: 83 additions & 23 deletions

File tree

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,13 @@ public RealVector get_Vector() {
179179
}
180180

181181
public RealMatrix get_MeasurementNoise() {
182-
return new Array2DRowRealMatrix(new double[][]{{0.09}});
182+
double mean_error = 0.471; // mm (no difference between adc and time)
183+
double error_on_adc = (1.15146*raw_adc + 437.63)/(3.21187*raw_adc + 878.855); // mm
184+
double error_on_time = (0.4423*time + 13.7215)/(0.846038*time + 31.9867); // mm
185+
double error = error_on_adc*error_on_time/mean_error; // mm
186+
187+
return new Array2DRowRealMatrix(new double[][]{{Math.pow(error, 2)}}); // mm^2
188+
//return new Array2DRowRealMatrix(new double[][]{{0.09}});
183189
}
184190

185191
// a signature for KalmanFilter.Hit_beam
@@ -206,6 +212,32 @@ public static void main(String[] args) {
206212
System.out.println("h1 compare to h2 : " + h1.compareTo(h2));
207213
System.out.println("h2 compare to h1 : " + h2.compareTo(h1));
208214
System.out.println("h1 compare to h3 : " + h1.compareTo(h3));
215+
216+
System.out.println("/////////////////////////");
217+
System.out.println("Test AHDC geometry");
218+
System.out.println("");
219+
System.out.println("s : sector");
220+
System.out.println("sl : super layer");
221+
System.out.println("l : layer");
222+
System.out.println("c : component");
223+
System.out.println("/////////////////////////");
224+
System.out.println("------------------------------------------------------------------------------");
225+
System.out.println(" | origin | end");
226+
System.out.println("------------------------------------------------------------------------------");
227+
System.out.println("s sl l c | x y z | x y z");
228+
System.out.println("------------------------------------------------------------------------------");
229+
for (int s = 1; s <= factory.getNumSectors(); s++) {
230+
for (int sl = 1; sl <= factory.getSector(s).getNumSuperlayers(); sl++) {
231+
for (int l = 1; l <= factory.getSector(s).getSuperlayer(sl).getNumLayers(); l++) {
232+
for (int c = 1; c <= factory.getSector(s).getSuperlayer(sl).getLayer(l).getNumComponents(); c++) {
233+
Line3D line = factory.getSector(s).getSuperlayer(sl).getLayer(l).getComponent(c).getLine();
234+
Point3D end = line.end();
235+
Point3D origin = line.origin();
236+
System.out.printf("%2d %2d %2d %2d | %7.3f %7.3f %7.3f | %7.3f %7.3f %7.3f\n", s, sl, l, c, origin.x(), origin.y(), origin.z(), end.x(), end.y(), end.z());
237+
}
238+
}
239+
}
240+
}
209241
}
210242

211243
}

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class KFitter {
2929
// masses/energies in MeV
3030
private final double electron_mass_c2 = PhysicsConstants.massElectron() * 1000;
3131
private final double proton_mass_c2 = PhysicsConstants.massProton() * 1000;
32-
private boolean isvertexdefined = false;
32+
private double[] vertex_resolutions = {0.09,1e10}; // default values // dr^2 and dz^2 in mm^2
3333

3434
public KFitter(final RealVector initialStateEstimate, final RealMatrix initialErrorCovariance, final Stepper stepper, final Propagator propagator, final HashMap<String, Material> materialHashMap) {
3535
this.stateEstimation = initialStateEstimate;
@@ -93,15 +93,14 @@ public void correct(Hit hit) {
9393
RealVector h;
9494
// check if the hit is the beamline
9595
if (hit.getRadius() < 1) {
96-
double z_beam_res_sq = 1.e10;//in mm
97-
if(isvertexdefined)z_beam_res_sq = 4.0;//assuming 2. mm resolution
96+
// the diagonal elements are the squared errors in r, phi, z
9897
measurementNoise =
99-
new Array2DRowRealMatrix(
100-
new double[][]{
101-
{0.09, 0.0000, 0.0000},
102-
{0.00, 1e10, 0.0000},
103-
{0.00, 0.0000, z_beam_res_sq}
104-
});//3x3
98+
new Array2DRowRealMatrix(
99+
new double[][]{
100+
{vertex_resolutions[0], 0.0000, 0.0000},
101+
{0.00, 1e10, 0.0000},
102+
{0.00, 0.0000, vertex_resolutions[1]}
103+
});//3x3
105104
measurementMatrix = H_beam(stateEstimation);//6x3
106105
h = h_beam(stateEstimation);//3x1
107106
z = hit.get_Vector_beam();//0!
@@ -274,7 +273,10 @@ public RealVector getStateEstimationVector() {
274273
public RealMatrix getErrorCovarianceMatrix() {
275274
return errorCovariance.copy();
276275
}
277-
278-
public void setVertexDefined(boolean isvtxdef) {isvertexdefined = isvtxdef;}
276+
277+
public void setVertexResolution(double[] res) {
278+
vertex_resolutions[0] = res[0];
279+
vertex_resolutions[1] = res[1];
280+
}
279281

280282
}

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.jlab.clas.pdg.PDGDatabase;
1212
import org.jlab.clas.pdg.PDGParticle;
1313
import org.jlab.clas.tracking.kalmanfilter.Material;
14+
import org.jlab.io.base.DataBank;
1415
import org.jlab.io.base.DataEvent;
1516
import org.jlab.rec.ahdc.Hit.Hit;
1617
import org.jlab.rec.ahdc.Track.Track;
@@ -32,6 +33,9 @@ public class KalmanFilter {
3233

3334
private final int Niter = 40; // number of iterations for the Kalman Filter
3435
private boolean IsVtxDefined = false; // implemented but not used yet
36+
private double[] vertex_resolutions = {0.09, 1e10}; // {error in r squared in mm^2, error in z squared in mm^2}
37+
// mm, CLAS and AHDC don't necessary have the same alignement (ZERO), this parameter may be subject to calibration
38+
private double clas_alignement = -54;
3539

3640
private void propagation(ArrayList<Track> tracks, DataEvent event, final double magfield, boolean IsMC) {
3741

@@ -44,6 +48,30 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
4448
final double tesla = 0.001;
4549
final double[] B = {0.0, 0.0, magfield / 10 * tesla};
4650
HashMap<String, Material> materialHashMap = MaterialMap.generateMaterials();
51+
// Recover the vertex of the electron
52+
if (event.hasBank("REC::Particle")) {
53+
DataBank recBank = event.getBank("REC::Particle");
54+
int row = 0;
55+
while ((!IsVtxDefined) && row < recBank.rows()) {
56+
if (recBank.getInt("pid", row) == 11) {
57+
IsVtxDefined = true;
58+
vz_constraint = 10*recBank.getFloat("vz",row) - (IsMC ? 0 : clas_alignement); // mm
59+
////////////////////////////////////////
60+
/// compute electron resolution here
61+
/// it depends en p and theta
62+
/// the fine tuning will be done later
63+
/// ////////////////////////////////////
64+
//double px = recBank.getFloat("px",row);
65+
//double py = recBank.getFloat("py",row);
66+
//double pz = recBank.getFloat("pz",row);
67+
//double p = Math.sqrt(px*px+py*py+pz*pz);
68+
//double theta = Math.acos(pz/p);
69+
vertex_resolutions[0] = 0.09;
70+
vertex_resolutions[1] = 64;//4 + 1e10*theta + 1e10*p;
71+
}
72+
row++;
73+
}
74+
}
4775

4876
// Loop over tracks
4977
int trackId = 0;
@@ -53,7 +81,7 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
5381
// Initialize state vector
5482
double x0 = 0.0;
5583
double y0 = 0.0;
56-
double z0 = track.get_Z0();
84+
double z0 = IsVtxDefined ? vz_constraint : track.get_Z0();
5785
double px0 = track.get_px();
5886
double py0 = track.get_py();
5987
double pz0 = track.get_pz();
@@ -62,9 +90,6 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
6290
// Read list of hits
6391
ArrayList<Hit> AHDC_hits = track.getHits();
6492
Collections.sort(AHDC_hits); // sorted following the compareTo() method in Hit.java
65-
66-
double zbeam = 0;
67-
if(IsVtxDefined)zbeam = vz_constraint;
6893

6994
// Start propagation
7095
Stepper stepper = new Stepper(y);
@@ -76,7 +101,7 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
76101
RealVector initialStateEstimate = new ArrayRealVector(stepper.y);
77102
RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{50.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 50.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 900.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 100.00, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 100.00, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 900.0}});
78103
KFitter TrackFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator, materialHashMap);
79-
TrackFitter.setVertexDefined(IsVtxDefined);
104+
if (IsVtxDefined) TrackFitter.setVertexResolution(vertex_resolutions);
80105

81106
// Loop over number of iterations
82107
for (int k = 0; k < Niter; k++) {
@@ -94,7 +119,7 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
94119
}
95120
// Backward propagation (first layer to beamline)
96121
{
97-
Hit hit = new Hit_beam(0, 0, zbeam);
122+
Hit hit = new Hit_beam(0, 0, vz_constraint);
98123
TrackFitter.predict(hit, false);
99124
TrackFitter.correct(hit);
100125
}
@@ -136,11 +161,11 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, final double
136161
hit.setTrackId(trackId);
137162
sum_adc += hit.getADC();
138163
sum_residuals += hit.getResidual();
139-
chi2 += Math.pow(hit.getResidual(),2.0);
164+
chi2 += Math.pow(hit.getResidual(),2)/hit.get_MeasurementNoise().getEntry(0,0);
140165
}
141166
track.set_sum_adc(sum_adc);
142167
track.set_sum_residuals(sum_residuals);
143-
track.set_chi2(chi2);
168+
track.set_chi2(chi2/(AHDC_hits.size()-3));
144169
track.set_p_drift_kf(p_drift);
145170
track.set_dEdx_kf(sum_adc/s);
146171
track.set_path_kf(s);

reconstruction/alert/src/main/java/org/jlab/service/alert/ALERTEngine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ public boolean processDataEvent(DataEvent event) {
187187
int matchHitId = -1;
188188

189189
for (int k = 0; k < bank_ATOFHits.rows(); k++) {
190-
int component = bank.getInt("component", k);
190+
int component = bank_ATOFHits.getInt("component", k);
191191
if (component == 10) continue;
192192

193-
int sector = bank.getInt("sector", k);
194-
int layer = bank.getInt("layer", k);
193+
int sector = bank_ATOFHits.getInt("sector", k);
194+
int layer = bank_ATOFHits.getInt("layer", k);
195195

196196
ATOFHit hit = new ATOFHit(sector, layer, component, 0, 0, 0, 0f, ATOF);
197197

@@ -213,6 +213,7 @@ public boolean processDataEvent(DataEvent event) {
213213
System.out.println("Exception in ALERTEngine processDataEvent: " + ex); // TODO: proper logging
214214
}
215215
}
216+
rbc.appendTrackMatchingAIBank(event, matched_ATOF_hit_id);
216217
return true;
217218
}
218219

0 commit comments

Comments
 (0)