11package 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 ;
38import org .jlab .geom .detector .alert .AHDC .AlertDCDetector ;
49import org .jlab .geom .prim .Line3D ;
510import org .jlab .geom .prim .Point3D ;
11+ import org .jlab .geom .detector .alert .AHDC .AlertDCFactory ;
612
713public 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}
0 commit comments