Skip to content

Commit fb44e9a

Browse files
raffaelladevitatongtongcao
authored andcommitted
replaced hardcoded geometry calculations in hit definition with info from geometry service
1 parent ca1c727 commit fb44e9a

File tree

6 files changed

+40
-157
lines changed

6 files changed

+40
-157
lines changed

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

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.jlab.rec.ahdc.Hit;
22

3+
import org.jlab.geom.detector.alert.AHDC.AlertDCDetector;
4+
import org.jlab.geom.prim.Line3D;
5+
import org.jlab.geom.prim.Point3D;
36

47
public class Hit implements Comparable<Hit> {
58

@@ -12,6 +15,7 @@ public class Hit implements Comparable<Hit> {
1215
private final double adc;
1316
private final double time;
1417

18+
private Line3D wireLine;
1519
private double phi;
1620
private double radius;
1721
private int nbOfWires;
@@ -31,55 +35,21 @@ public Hit(int _Id, int _Super_layer, int _Layer, int _Wire, double _Doca, doubl
3135
this.doca = _Doca;
3236
this.adc = _ADC;
3337
this.time = _Time;
34-
wirePosition();
3538
this.residual_prefit = 0.0;
3639
this.residual = 0.0;
3740
this.trackId = -1; // not defined yet
3841
}
3942

40-
private void wirePosition() {
41-
final double DR_layer = 4.0;
42-
final double round = 360.0;
43-
44-
double numWires = 32.0;
45-
double R_layer = 47.0;
46-
47-
switch (this.superLayerId) {
48-
case 1:
49-
numWires = 47.0;
50-
R_layer = 32.0;
51-
break;
52-
case 2:
53-
numWires = 56.0;
54-
R_layer = 38.0;
55-
break;
56-
case 3:
57-
numWires = 72.0;
58-
R_layer = 48.0;
59-
break;
60-
case 4:
61-
numWires = 87.0;
62-
R_layer = 58.0;
63-
break;
64-
case 5:
65-
numWires = 99.0;
66-
R_layer = 68.0;
67-
break;
68-
}
69-
70-
R_layer = R_layer + DR_layer * (this.layerId-1);
71-
double alphaW_layer = Math.toRadians(round / (numWires));
72-
//should it be at z = 0? in which case, we need to account for the positive or negative stereo angle...
73-
double wx = -R_layer * Math.sin(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1)));
74-
double wy = -R_layer * Math.cos(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1)));
75-
43+
public void setWirePosition(AlertDCDetector factory) {
44+
7645
//System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy);
77-
78-
this.nbOfWires = (int) numWires;
79-
this.phi = Math.atan2(wy, wx);
80-
this.radius = R_layer;
81-
this.x = wx;
82-
this.y = wy;
46+
wireLine = factory.getSector(1).getSuperlayer(superLayerId).getLayer(layerId).getComponent(wireId).getLine();
47+
Point3D end = wireLine.end();
48+
this.nbOfWires = factory.getSector(1).getSuperlayer(superLayerId).getLayer(layerId).getNumComponents();
49+
this.phi = end.vectorFrom(0, 0, 0).phi();
50+
this.radius = end.distance(0, 0, end.z());
51+
this.x = end.x();
52+
this.y = end.y();
8353
}
8454

8555
@Override
@@ -99,7 +69,7 @@ public int compareTo(Hit arg0) {
9969
public int getId() {
10070
return id;
10171
}
102-
72+
10373
public int getSuperLayerId() {
10474
return superLayerId;
10575
}
@@ -116,7 +86,11 @@ public double getDoca() {
11686
return doca;
11787
}
11888

119-
public double getRadius() {
89+
public Line3D getLine() {
90+
return wireLine;
91+
}
92+
93+
public double getRadius() {
12094
return radius;
12195
}
12296

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HitReader {
1212
private ArrayList<Hit> _AHDCHits;
1313
private ArrayList<TrueHit> _TrueAHDCHits;
1414

15-
public HitReader(DataEvent event, boolean simulation) {
15+
public HitReader(DataEvent event, boolean simulation) {
1616
fetch_AHDCHits(event);
1717
if (simulation) fetch_TrueAHDCHits(event);
1818
}

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

Lines changed: 13 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
public class Hit implements Comparable<Hit> {
1313

14-
private final double thster = Math.toRadians(20.0);
15-
private final double zl = 300.0;//OK
1614
private final int superLayer;
1715
private final int layer;
1816
private final int wire;
@@ -30,118 +28,31 @@ public class Hit implements Comparable<Hit> {
3028
// Comparison with: common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java
3129
// here, SuperLayer, Layer, Wire, start from 1
3230
// in AlertDCFactory, same variables start from 1
33-
public Hit(int superLayer, int layer, int wire, int numWire, double r, double doca) {
31+
public Hit(int superLayer, int layer, int wire, int numWire, Line3D line, double doca) {
3432
this.superLayer = superLayer;
3533
this.layer = layer;
3634
this.wire = wire;
37-
this.r = r;
35+
this.r = line.end().distance(0, 0, line.end().z());
3836
this.doca = doca;
3937
this.numWires = numWire;
4038
this.adc = 0;//placeholder
4139
this.hitidx = -1;
4240
this.hitsign = 0;
4341

44-
final double DR_layer = 4.0;//OK
45-
final double round = 360.0;//OK
46-
final double thster = Math.toRadians(20.0);//OK
47-
48-
double numWires = 32.0;
49-
double R_layer = 47.0;
50-
51-
double zoff1 = -zl/2;//OK
52-
double zoff2 = +zl/2;//OK
53-
Point3D p1 = new Point3D(R_layer, 0, zoff1);
54-
Vector3D n1 = new Vector3D(0, 0, 1);
55-
//n1.rotateY(-thopen);
56-
//n1.rotateZ(thtilt);
57-
Plane3D lPlane = new Plane3D(p1, n1);//OK
58-
59-
Point3D p2 = new Point3D(R_layer, 0, zoff2);
60-
Vector3D n2 = new Vector3D(0, 0, 1);
61-
//n2.rotateY(thopen);
62-
//n2.rotateZ(thtilt);
63-
Plane3D rPlane = new Plane3D(p2, n2);//OK
64-
65-
switch (this.superLayer) {//OK
66-
case 1:
67-
numWires = 47.0;
68-
R_layer = 32.0;
69-
break;
70-
case 2:
71-
numWires = 56.0;
72-
R_layer = 38.0;
73-
break;
74-
case 3:
75-
numWires = 72.0;
76-
R_layer = 48.0;
77-
break;
78-
case 4:
79-
numWires = 87.0;
80-
R_layer = 58.0;
81-
break;
82-
case 5:
83-
numWires = 99.0;
84-
R_layer = 68.0;
85-
break;
86-
}
87-
88-
89-
R_layer = R_layer + DR_layer * (this.layer-1);//OK
90-
double alphaW_layer = Math.toRadians(round / (numWires));//OK
91-
double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1));//OK
92-
double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1));//OK
93-
94-
double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK
95-
double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK
96-
97-
this.phi = Math.atan2( (wy+wy_end)*0.5, (wx+wx_end)*0.5 );
42+
this.phi = line.midpoint().vectorFrom(0,0,0).phi();
9843
//System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end + " phi " + this.phi);
9944

100-
Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2);
101-
Point3D lPoint = new Point3D();
102-
Point3D rPoint = new Point3D();
103-
lPlane.intersection(line, lPoint);
104-
rPlane.intersection(line, rPoint);
105-
//lPoint.setZ(-zl/2);
106-
//rPoint.setZ(zl/2);
107-
//lPoint.show();
108-
//rPoint.show();
109-
// All wire go from left to right
110-
Line3D wireLine = new Line3D(lPoint, rPoint);
111-
//wireLine.show();
112-
this.line3D = wireLine;
45+
this.line3D = line;
11346

11447
//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;
48+
double deltaphi = Math.asin(this.doca/r);
49+
this.line3D_plus = new Line3D();
50+
this.line3D_plus.copy(line);
51+
this.line3D_plus.rotateZ(deltaphi);
52+
53+
this.line3D_minus = new Line3D();
54+
this.line3D_minus.copy(line);
55+
this.line3D_minus.rotateZ(deltaphi);
14556

14657
}
14758

@@ -180,9 +91,7 @@ public double doca() {
18091
public double phi() {return phi;}//at z = 0;
18192

18293
public double phi(double z) {
183-
double x_z = r*Math.sin( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) );
184-
double y_z = r*Math.cos( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) );
185-
return Math.atan2(x_z, y_z);
94+
return this.line3D.lerpPoint((z-line3D.origin().z())/line3D.length()).vectorFrom(0,0,0).phi();
18695
}
18796

18897
public Line3D line() {return line3D;}
@@ -216,10 +125,6 @@ public RealVector get_Vector_beam() {
216125
return null;
217126
}
218127

219-
public double getThster() {
220-
return thster;
221-
}
222-
223128
public int getSuperLayer() {
224129
return superLayer;
225130
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import org.apache.commons.math3.linear.ArrayRealVector;
44
import org.apache.commons.math3.linear.RealVector;
5+
import org.jlab.geom.prim.Line3D;
56

67
public class Hit_beam extends Hit {
78

89
double x,y,z;
910
double r,phi;
1011

1112
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);
13+
super(0, 0, 0, 0, new Line3D(x,y,0,x,y,1), 0);
1314
this.x = x;
1415
this.y = y;
1516
this.z = z;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void propagation(ArrayList<Track> tracks, DataEvent event, boolean IsMC)
9797
//System.out.println(" px " + y[3] + " py " + y[4] +" pz " + y[5] +" vz " + y[2] + " number of hits: " + AHDC_hits.size() + " MC hits? " + sim_hits.size());
9898
track.set_n_hits(AHDC_hits.size());
9999
for (org.jlab.rec.ahdc.Hit.Hit AHDC_hit : AHDC_hits) {
100-
Hit hit = new Hit(AHDC_hit.getSuperLayerId(), AHDC_hit.getLayerId(), AHDC_hit.getWireId(), AHDC_hit.getNbOfWires(), AHDC_hit.getRadius(), AHDC_hit.getDoca());
100+
Hit hit = new Hit(AHDC_hit.getSuperLayerId(), AHDC_hit.getLayerId(), AHDC_hit.getWireId(), AHDC_hit.getNbOfWires(), AHDC_hit.getLine(), AHDC_hit.getDoca());
101101
hit.setADC(AHDC_hit.getADC());
102102
hit.setHitIdx(AHDC_hit.getId());
103103
hit.setSign(0);

reconstruction/alert/src/main/java/org/jlab/service/ahdc/AHDCEngine.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.File;
2828
import java.util.*;
2929
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
30+
import org.jlab.geom.base.Detector;
3031
import org.jlab.geom.detector.alert.AHDC.AlertDCFactory;
3132

3233
/** AHDCEngine reconstruction service.
@@ -60,14 +61,16 @@ public class AHDCEngine extends ReconstructionEngine {
6061
/// \todo better name... mode for what?
6162
private Mode mode = Mode.CV_Track_Finding;
6263

64+
private Detector factory = null;
65+
6366
public AHDCEngine() {
6467
super("ALERT", "ouillon", "1.0.1");
6568
}
6669

6770
@Override
6871
public boolean init() {
6972

70-
(new AlertDCFactory()).createDetectorCLAS(new DatabaseConstantProvider());
73+
factory = (new AlertDCFactory()).createDetectorCLAS(new DatabaseConstantProvider());
7174

7275
simulation = false;
7376
findingMethod = "distance";

0 commit comments

Comments
 (0)