def T_LA(obj): """Convert matrix/vector-like object to TMatrixT/TVectorT object >>> obj = ... >>> res = LinAlg.T_LA ( obj ) """ s = obj.shape assert 1 <= len(s) <= 2, 'Invalid shape of the object %s' % s ## vector if 1 == len(s): l = s[0] v = Ostap.TVectorD(l) for i, p in enumerate(obj): v[i] = p return v ##matrix mget = LinAlgT.mgetter nr, nc = s m = Ostap.TMatrixD(nr, nc) for i in range(nr): for j in range(nc): m[i, j] = mget(obj, i, j) return m
def _closest_points_(line, line1): """Calculate the two closest points between two lines >>> line1 = ... >>> line2 = ... >>> point1 , point2 , flag = line1.closestPoints ( line2 ) The return values is a tuple: - the point onthe fist line - the point on the second line - the flag (true is everything OK) """ _point1 = Ostap.XYZPoint(0, 0, -1.e+10) _point2 = Ostap.XYZPoint(0, 0, -1.e+11) _flag = _GeomFun.closestPoints(line, line1, _point1, _point2) if _flag: _flag = True else: _flag = False return (_point1, _point2, _flag)
def _project_onto_plane_(plane, point): """Project the point into plane >>> point = ... >>> plane = ... >>> result = plane.project ( point ) """ d = plane.Distance(point) return Ostap.XYZPoint(point.X() - plane.A() * d, point.Y() - plane.B() * d, point.Z() - plane.C() * d)
def _intersect_two_planes_(plane, plane1): """Find the intersection line for two planes: >>> plane = ... >>> plane1 = ... >>> line, flag = plane.line(plane1) Return value is a tuple: - the intersection line - the flag (true if intersection exists) """ _line = Ostap.XYZLine() _flag = _GeomFun.intersection(plane, plane1, _line) if _flag: _flag = True else: _flag = False return (_line, _flag)
def _intersect_three_planes_(plane, plane1, plane2): """Find the intersection point for three planes: >>> plane = ... >>> plane1 = ... >>> plane3 = ... >>> point, flag = plane.point(plane1,plane2) Return value is a tuple: - the intersection point - the flag (true if intersection exists) """ _point = Ostap.XYZPoint(0, 0, -1.e+10) _flag = _GeomFun.intersection(plane, plane1, plane2, _point) if _flag: _flag = True else: _flag = False return (_point, _flag)
def _intersect_line_and_plane_(line, plane): """Find the intersection of line and plane >>> line = ... >>> plane = ... >>> ok, point, mu = line.intersect ( plane ) The return value is a tuple: - the point - the parameter along the line - the flag (true if intersection exists) """ _point = Ostap.XYZPoint(0, 0, -1.e+10) _mu = ctypes.c_double(-1.e+10) _flag = _GeomFun.intersection(line, plane, _point, _mu) if _flag: _flag = True else: _flag = False _mu = float(_mu.value) return (_point, _mu, _flag)
def _pl_str_(self): """Self-printout of 3D-plane: (normal,point) >>> plane = ... >>> print plane """ return "Plane3D(%s,%s)" % (self.Normal(), self.project(Ostap.XYZPoint()))
_closest_points_, _closest_point_params_, _closest_point_1_, _closest_point_2_, _closest_point_param_1_, _closest_point_param_2_, _parallel_lines_, ) # ============================================================================= if '__main__' == __name__: from ostap.utils.docme import docme docme(__name__, logger=logger) p1 = Ostap.XYZPoint(0, 1, 2) v1 = Ostap.XYZVector(2, 1, 0) l1 = Ostap.XYZLine(p1, v1) pl1 = Ostap.Plane3D(1, 1, 1, 0) logger.info('3D-point (x,y,z) : %s' % p1) logger.info('3D-vector (x,y,z) : %s' % v1) logger.info('3D-line (point,direction) : %s' % l1) logger.info('3D-plane (point,normal) : %s' % pl1) pnt1 = Ostap.XYZPoint(-1, -2, -3) pnt2 = Ostap.XYZPoint(1, -2, -3) line1 = Ostap.Math.XYZLine(Ostap.XYZPoint(0, 1, 2), Ostap.XYZVector(1, 1, 1)) line2 = Ostap.Math.XYZLine(Ostap.XYZPoint(1, 3, 0), Ostap.XYZVector(1, -1, 2))
## result += y * z * w + y * u * w ## <-- typo in E.Byckling & K.Kajantie result += y * z * v + y * u * w ## <-- correct line result -= x * y * (z + u + v + w) result -= z * u * (x + y + v + w) result -= v * w * (x + y + z + u) ## return result # ============================================================================= if '__main__' == __name__: from ostap.utils.docme import docme docme(__name__, logger=logger) lv0 = Ostap.LorentzVector(2, 1, 0, 3) logger.info('Lorentz-vector ((px,py,pz),E) : %s' % lv0) CLV = Ostap.ComplexLorentzVector lv1 = CLV() lv2 = CLV(lv0) lv3 = CLV(1 + 2j) lv4 = CLV(1, 2, 3, 4) lv5 = CLV(1, 2, 3, 4 + 3j) logger.info('Lorentz-vector ((px,py,pz),E) : %s' % lv1) logger.info('Lorentz-vector ((px,py,pz),E) : %s' % lv2) logger.info('Lorentz-vector ((px,py,pz),E) : %s' % lv3) logger.info('Lorentz-vector ((px,py,pz),E) : %s' % lv4)