44import org .jlab .rec .ahdc .PreCluster .PreCluster ;
55
66import java .util .ArrayList ;
7+ import org .jlab .geom .detector .alert .AHDC .AlertDCFactory ;
8+ import org .jlab .geom .prim .Line3D ;
9+ import org .jlab .geom .prim .Point3D ;
710
811/**
912 * Cluster are compose by 2 PreCluster on layer with a different stereo angle
1013 */
1114public class Cluster {
1215
1316 private int _trackId = -1 ;
14- private double _StereoAngle = 20.0 ;
15- private double _DeltaZ = 300.0 ;
16- private double _Zoffset = 150.0 ;
17-
1817 private double _Radius ;
1918 private double _Phi ;
2019 private double _Z ;
@@ -26,14 +25,46 @@ public class Cluster {
2625 private double _V ;
2726 private ArrayList <PreCluster > _PreClusters_list ;
2827
28+ private static Line3D representativeLine (PreCluster pc ) {
29+ if (pc == null || pc .get_hits_list () == null || pc .get_hits_list ().isEmpty ()) {
30+ return null ;
31+ }
32+ Hit h = pc .get_hits_list ().get (0 );
33+ return h .getLine ();
34+ }
35+ private static double wrapPi (double a ) {
36+ while (a > Math .PI ) a -= 2.0 * Math .PI ;
37+ while (a < -Math .PI ) a += 2.0 * Math .PI ;
38+ return a ;
39+ }
40+ private static double stereoTwistFromLine (Line3D line ) {
41+ if (line == null ) {
42+ return 0.0 ;
43+ }
44+
45+ Point3D p0 = line .origin ();
46+ Point3D p1 = line .end ();
47+
48+ double phi0 = Math .atan2 (p0 .y (), p0 .x ());
49+ double phi1 = Math .atan2 (p1 .y (), p1 .x ());
2950
51+ return wrapPi (phi1 - phi0 );
52+ }
3053 public Cluster (PreCluster precluster , PreCluster other_precluster ) {
3154 this ._PreClusters_list = new ArrayList <>();
3255 _PreClusters_list .add (precluster );
3356 _PreClusters_list .add (other_precluster );
3457 this ._Radius = (precluster .get_Radius () + other_precluster .get_Radius ()) / 2 ;
3558
36- this ._Z = ((other_precluster .get_Phi () - precluster .get_Phi ()) / (Math .toRadians (_StereoAngle ) * Math .pow (-1 , precluster .get_Super_layer ()-1 ) - Math .toRadians (_StereoAngle ) * Math .pow (-1 , other_precluster .get_Super_layer ()-1 ))) * _DeltaZ - _Zoffset ;
59+ Line3D line1 = representativeLine (precluster );
60+ Line3D line2 = representativeLine (other_precluster );
61+ Point3D end1 = line1 .end ();
62+ Point3D start1 = line1 .origin ();
63+ double DeltaZ = end1 .z ()-start1 .z ();
64+ double Zref = end1 .z ();
65+ double StereoAnglep = stereoTwistFromLine (line1 );
66+ double StereoAngleo = stereoTwistFromLine (line2 );
67+ this ._Z = ((precluster .get_Phi () - other_precluster .get_Phi ()) / (StereoAnglep - StereoAngleo )) * DeltaZ + Zref ;
3768
3869 double x1 = -precluster .get_Radius () * Math .sin (precluster .get_Phi ());
3970 double y1 = -precluster .get_Radius () * Math .cos (precluster .get_Phi ());
0 commit comments