@@ -36,31 +36,39 @@ private static Line3D representativeLine(PreCluster pc) {
3636 Hit h = pc .get_hits_list ().get (0 );
3737 return h .getLine ();
3838 }
39- public static double getStereoAngleDeg ( int superlayerId ) {
40- switch ( superlayerId ) {
41- case 0 : return - 19.1489 ;
42- case 1 : return - 19.2857 ;
43- case 2 : return - 20.0 ;
44- case 3 : return - 20.6897 ;
45- case 4 : return - 20.0 ;
46- default : return - 20 .0 ;
39+ private static double wrapPi ( double a ) {
40+ while ( a > Math . PI ) a -= 2.0 * Math . PI ;
41+ while ( a < - Math . PI ) a += 2.0 * Math . PI ;
42+ return a ;
43+ }
44+ private static double stereoTwistFromLine ( Line3D line ) {
45+ if ( line == null ) {
46+ return 0 .0 ;
4747 }
48- }
4948
49+ Point3D p0 = line .origin ();
50+ Point3D p1 = line .end ();
51+
52+ double phi0 = Math .atan2 (p0 .y (), p0 .x ());
53+ double phi1 = Math .atan2 (p1 .y (), p1 .x ());
54+
55+ return wrapPi (phi1 - phi0 );
56+ }
5057 public Cluster (PreCluster precluster , PreCluster other_precluster ) {
5158 this ._PreClusters_list = new ArrayList <>();
5259 _PreClusters_list .add (precluster );
5360 _PreClusters_list .add (other_precluster );
5461 this ._Radius = (precluster .get_Radius () + other_precluster .get_Radius ()) / 2 ;
5562
5663 Line3D line1 = representativeLine (precluster );
64+ Line3D line2 = representativeLine (other_precluster );
5765 Point3D end1 = line1 .end ();
5866 Point3D start1 = line1 .origin ();
5967 double DeltaZ = end1 .z ()-start1 .z ();
6068 double Zref = end1 .z ();
61- double StereoAnglep = getStereoAngleDeg ( precluster . get_Super_layer () );
62- double StereoAngleo = getStereoAngleDeg ( other_precluster . get_Super_layer () );
63- this ._Z = ((precluster .get_Phi () - other_precluster .get_Phi ()) / (Math . toRadians ( StereoAnglep ) * Math . pow (- 1 , precluster . get_Super_layer ()- 1 ) - Math . toRadians ( StereoAngleo ) * Math . pow (- 1 , other_precluster . get_Super_layer ()- 1 ) )) * DeltaZ + Zref ;
69+ double StereoAnglep = stereoTwistFromLine ( line1 );
70+ double StereoAngleo = stereoTwistFromLine ( line2 );
71+ this ._Z = ((precluster .get_Phi () - other_precluster .get_Phi ()) / (StereoAnglep - StereoAngleo )) * DeltaZ + Zref ;
6472
6573 double x1 = -precluster .get_Radius () * Math .sin (precluster .get_Phi ());
6674 double y1 = -precluster .get_Radius () * Math .cos (precluster .get_Phi ());
0 commit comments