/usr/include/root/Math/GenVector/PositionVector3D.h is in libroot-math-genvector-dev 5.34.30-0ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | // @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005
/**********************************************************************
* *
* Copyright (c) 2005 , LCG ROOT MathLib Team *
* *
* *
**********************************************************************/
// Header file for class PositionVector3D
//
// Created by: Lorenzo Moneta at Mon May 30 15:25:04 2005
//
// Last update: $Id$
//
#ifndef ROOT_Math_GenVector_PositionVector3D
#define ROOT_Math_GenVector_PositionVector3D 1
#ifndef ROOT_Math_GenVector_DisplacementVector3Dfwd
#include "Math/GenVector/DisplacementVector3Dfwd.h"
#endif
#ifndef ROOT_Math_GenVector_Cartesian3D
#include "Math/GenVector/Cartesian3D.h"
#endif
#ifndef ROOT_Math_GenVector_GenVectorIO
#include "Math/GenVector/GenVectorIO.h"
#endif
#ifndef ROOT_Math_GenVector_BitReproducible
#include "Math/GenVector/BitReproducible.h"
#endif
#ifndef ROOT_Math_GenVector_CoordinateSystemTags
#include "Math/GenVector/CoordinateSystemTags.h"
#endif
#include <cassert>
namespace ROOT {
namespace Math {
//__________________________________________________________________________________________
/**
Class describing a generic position vector (point) in 3 dimensions.
This class is templated on the type of Coordinate system.
One example is the XYZPoint which is a vector based on
double precision x,y,z data members by using the
ROOT::Math::Cartesian3D<double> Coordinate system.
The class is having also an extra template parameter, the coordinate system tag,
to be able to identify (tag) vector described in different reference coordinate system,
like global or local coordinate systems.
@ingroup GenVector
*/
template <class CoordSystem, class Tag = DefaultCoordinateSystemTag >
class PositionVector3D {
public:
typedef typename CoordSystem::Scalar Scalar;
typedef CoordSystem CoordinateType;
typedef Tag CoordinateSystemTag;
// ------ ctors ------
/**
Default constructor. Construct an empty object with zero values
*/
PositionVector3D() : fCoordinates() { }
/**
Construct from three values of type <em>Scalar</em>.
In the case of a XYZPoint the values are x,y,z
In the case of a polar vector they are r,theta,phi
*/
PositionVector3D(const Scalar & a, const Scalar & b, const Scalar & c) :
fCoordinates ( a , b, c) { }
/**
Construct from a position vector expressed in different
coordinates, or using a different Scalar type
*/
template <class T>
explicit PositionVector3D( const PositionVector3D<T,Tag> & v) :
fCoordinates ( v.Coordinates() ) { }
/**
Construct from an arbitrary displacement vector
*/
template <class T>
explicit PositionVector3D( const DisplacementVector3D<T,Tag> & p) :
fCoordinates ( p.Coordinates() ) { }
/**
Construct from a foreign 3D vector type, for example, Hep3Vector
Precondition: v must implement methods x(), y() and z()
*/
template <class ForeignVector>
explicit PositionVector3D( const ForeignVector & v) :
fCoordinates ( Cartesian3D<Scalar>( v.x(), v.y(), v.z() ) ) { }
#ifdef LATER
/**
construct from a generic linear algebra vector of at least size 3
implementing operator []. This could be also a C array
\par v LAVector
\par index0 index where coordinates starts (typically zero)
It works for all Coordinates types,
( x= v[index0] for Cartesian and r=v[index0] for Polar )
*/
template <class LAVector>
PositionVector3D(const LAVector & v, size_t index0 ) {
fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
}
#endif
// compiler-generated copy ctor and dtor are fine.
// ------ assignment ------
/**
Assignment operator from a position vector of arbitrary type
*/
template <class OtherCoords>
PositionVector3D & operator=
( const PositionVector3D<OtherCoords,Tag> & v) {
fCoordinates = v.Coordinates();
return *this;
}
/**
Assignment operator from a displacement vector of arbitrary type
*/
template <class OtherCoords>
PositionVector3D & operator=
( const DisplacementVector3D<OtherCoords,Tag> & v) {
fCoordinates = v.Coordinates();
return *this;
}
/**
Assignment from a foreign 3D vector type, for example, Hep3Vector
Precondition: v must implement methods x(), y() and z()
*/
template <class ForeignVector>
PositionVector3D & operator= ( const ForeignVector & v) {
SetXYZ( v.x(), v.y(), v.z() );
return *this;
}
#ifdef LATER
/**
assign from a generic linear algebra vector of at least size 3
implementing operator [].
\par v LAVector
\par index0 index where coordinates starts (typically zero)
It works for all Coordinates types,
( x= v[index0] for Cartesian and r=v[index0] for Polar )
*/
template <class LAVector>
PositionVector3D & assignFrom(const LAVector & v, size_t index0 = 0) {
fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
return *this;
}
#endif
/**
Retrieve a copy of the coordinates object
*/
const CoordSystem & Coordinates() const {
return fCoordinates;
}
/**
Set internal data based on a C-style array of 3 Scalar numbers
*/
PositionVector3D<CoordSystem, Tag>& SetCoordinates( const Scalar src[] )
{ fCoordinates.SetCoordinates(src); return *this; }
/**
Set internal data based on 3 Scalar numbers
*/
PositionVector3D<CoordSystem, Tag>& SetCoordinates( Scalar a, Scalar b, Scalar c )
{ fCoordinates.SetCoordinates(a, b, c); return *this; }
/**
Set internal data based on 3 Scalars at *begin to *end
*/
template <class IT>
#ifndef NDEBUG
PositionVector3D<CoordSystem, Tag>& SetCoordinates( IT begin, IT end )
#else
PositionVector3D<CoordSystem, Tag>& SetCoordinates( IT begin, IT /* end */ )
#endif
{ IT a = begin; IT b = ++begin; IT c = ++begin;
assert (++begin==end);
SetCoordinates (*a,*b,*c);
return *this;
}
/**
get internal data into 3 Scalar numbers
*/
void GetCoordinates( Scalar& a, Scalar& b, Scalar& c ) const
{ fCoordinates.GetCoordinates(a, b, c); }
/**
get internal data into a C-style array of 3 Scalar numbers
*/
void GetCoordinates( Scalar dest[] ) const
{ fCoordinates.GetCoordinates(dest); }
/**
get internal data into 3 Scalars at *begin to *end (3 past begin)
*/
template <class IT>
#ifndef NDEBUG
void GetCoordinates( IT begin, IT end ) const
#else
void GetCoordinates( IT begin, IT /* end */ ) const
#endif
{ IT a = begin; IT b = ++begin; IT c = ++begin;
assert (++begin==end);
GetCoordinates (*a,*b,*c);
}
/**
get internal data into 3 Scalars at *begin
*/
template <class IT>
void GetCoordinates( IT begin ) const {
Scalar a,b,c = 0;
GetCoordinates (a,b,c);
*begin++ = a;
*begin++ = b;
*begin = c;
}
/**
set the values of the vector from the cartesian components (x,y,z)
(if the vector is held in polar or cylindrical eta coordinates,
then (x, y, z) are converted to that form)
*/
PositionVector3D<CoordSystem, Tag>& SetXYZ (Scalar a, Scalar b, Scalar c) {
fCoordinates.SetXYZ(a,b,c);
return *this;
}
// ------------------- Equality -----------------
/**
Exact equality
*/
bool operator==(const PositionVector3D & rhs) const {
return fCoordinates==rhs.fCoordinates;
}
bool operator!= (const PositionVector3D & rhs) const {
return !(operator==(rhs));
}
// ------ Individual element access, in various coordinate systems ------
/**
Cartesian X, converting if necessary from internal coordinate system.
*/
Scalar X() const { return fCoordinates.X(); }
/**
Cartesian Y, converting if necessary from internal coordinate system.
*/
Scalar Y() const { return fCoordinates.Y(); }
/**
Cartesian Z, converting if necessary from internal coordinate system.
*/
Scalar Z() const { return fCoordinates.Z(); }
/**
Polar R, converting if necessary from internal coordinate system.
*/
Scalar R() const { return fCoordinates.R(); }
/**
Polar theta, converting if necessary from internal coordinate system.
*/
Scalar Theta() const { return fCoordinates.Theta(); }
/**
Polar phi, converting if necessary from internal coordinate system.
*/
Scalar Phi() const { return fCoordinates.Phi(); }
/**
Polar eta, converting if necessary from internal coordinate system.
*/
Scalar Eta() const { return fCoordinates.Eta(); }
/**
Cylindrical transverse component rho
*/
Scalar Rho() const { return fCoordinates.Rho(); }
// ----- Other fundamental properties -----
/**
Magnitute squared ( r^2 in spherical coordinate)
*/
Scalar Mag2() const { return fCoordinates.Mag2();}
/**
Transverse component squared (rho^2 in cylindrical coordinates.
*/
Scalar Perp2() const { return fCoordinates.Perp2();}
// It is physically meaningless to speak of the unit vector corresponding
// to a point.
// ------ Setting individual elements present in coordinate system ------
/**
Change X - Cartesian3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetX (Scalar xx) { fCoordinates.SetX(xx); return *this;}
/**
Change Y - Cartesian3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetY (Scalar yy) { fCoordinates.SetY(yy); return *this;}
/**
Change Z - Cartesian3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetZ (Scalar zz) { fCoordinates.SetZ(zz); return *this;}
/**
Change R - Polar3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetR (Scalar rr) { fCoordinates.SetR(rr); return *this;}
/**
Change Theta - Polar3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetTheta (Scalar ang) { fCoordinates.SetTheta(ang); return *this;}
/**
Change Phi - Polar3D or CylindricalEta3D coordinates
*/
PositionVector3D<CoordSystem, Tag>& SetPhi (Scalar ang) { fCoordinates.SetPhi(ang); return *this;}
/**
Change Rho - CylindricalEta3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetRho (Scalar rr) { fCoordinates.SetRho(rr); return *this;}
/**
Change Eta - CylindricalEta3D coordinates only
*/
PositionVector3D<CoordSystem, Tag>& SetEta (Scalar etaval) { fCoordinates.SetEta(etaval); return *this;}
// ------ Operations combining two vectors ------
// need to specialize to exclude those with a different tags
/**
Return the scalar (Dot) product of this with a displacement vector in
any coordinate system, but with the same tag
*/
template< class OtherCoords >
Scalar Dot( const DisplacementVector3D<OtherCoords,Tag> & v) const {
return X()*v.x() + Y()*v.y() + Z()*v.z();
}
/**
Return vector (Cross) product of this point with a displacement, as a
point vector in this coordinate system of the first.
*/
template< class OtherCoords >
PositionVector3D Cross( const DisplacementVector3D<OtherCoords,Tag> & v) const {
PositionVector3D result;
result.SetXYZ ( Y()*v.z() - v.y()*Z(),
Z()*v.x() - v.z()*X(),
X()*v.y() - v.x()*Y() );
return result;
}
// The Dot and Cross products of a pair of point vectors are physically
// meaningless concepts and thus are defined as private methods
// It is physically meaningless to speak of the Unit vector corresponding
// to a point.
/**
Self Addition with a displacement vector.
*/
template <class OtherCoords>
PositionVector3D & operator+= (const DisplacementVector3D<OtherCoords,Tag> & v)
{
SetXYZ( X() + v.X(), Y() + v.Y(), Z() + v.Z() );
return *this;
}
/**
Self Difference with a displacement vector.
*/
template <class OtherCoords>
PositionVector3D & operator-= (const DisplacementVector3D<OtherCoords,Tag> & v)
{
SetXYZ( X() - v.X(), Y() - v.Y(), Z() - v.Z() );
return *this;
}
/**
multiply this vector by a scalar quantity
*/
PositionVector3D & operator *= (Scalar a) {
fCoordinates.Scale(a);
return *this;
}
/**
divide this vector by a scalar quantity
*/
PositionVector3D & operator /= (Scalar a) {
fCoordinates.Scale(1/a);
return *this;
}
// The following methods (v*a and v/a) could instead be free functions.
// They were moved into the class to solve a problem on AIX.
/**
Multiply a vector by a real number
*/
PositionVector3D operator * ( Scalar a ) const {
PositionVector3D tmp(*this);
tmp *= a;
return tmp;
}
/**
Division of a vector with a real number
*/
PositionVector3D operator / (Scalar a) const {
PositionVector3D tmp(*this);
tmp /= a;
return tmp;
}
// Limited backward name compatibility with CLHEP
Scalar x() const { return fCoordinates.X(); }
Scalar y() const { return fCoordinates.Y(); }
Scalar z() const { return fCoordinates.Z(); }
Scalar r() const { return fCoordinates.R(); }
Scalar theta() const { return fCoordinates.Theta(); }
Scalar phi() const { return fCoordinates.Phi(); }
Scalar eta() const { return fCoordinates.Eta(); }
Scalar rho() const { return fCoordinates.Rho(); }
Scalar mag2() const { return fCoordinates.Mag2(); }
Scalar perp2() const { return fCoordinates.Perp2(); }
private:
CoordSystem fCoordinates;
// Prohibited methods
// this should not compile (if from a vector or points with different tag
template <class OtherCoords, class OtherTag>
explicit PositionVector3D( const PositionVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
explicit PositionVector3D( const DisplacementVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
PositionVector3D & operator=( const PositionVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
PositionVector3D & operator=( const DisplacementVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
PositionVector3D & operator+=(const DisplacementVector3D<OtherCoords, OtherTag> & );
template <class OtherCoords, class OtherTag>
PositionVector3D & operator-=(const DisplacementVector3D<OtherCoords, OtherTag> & );
// /**
// Dot product of two position vectors is inappropriate
// */
// template <class T2, class U>
// PositionVector3D Dot( const PositionVector3D<T2,U> & v) const;
// /**
// Cross product of two position vectors is inappropriate
// */
// template <class T2, class U>
// PositionVector3D Cross( const PositionVector3D<T2,U> & v) const;
};
// ---------- PositionVector3D class template ends here ----------------
// ---------------------------------------------------------------------
/**
Multiplication of a position vector by real number a*v
*/
template <class CoordSystem, class U>
inline
PositionVector3D<CoordSystem>
operator * ( typename PositionVector3D<CoordSystem,U>::Scalar a,
PositionVector3D<CoordSystem,U> v) {
return v *= a;
// Note - passing v by value and using operator *= may save one
// copy relative to passing v by const ref and creating a temporary.
}
/**
Difference between two PositionVector3D vectors.
The result is a DisplacementVector3D.
The (coordinate system) type of the returned vector is defined to
be identical to that of the first position vector.
*/
template <class CoordSystem1, class CoordSystem2, class U>
inline
DisplacementVector3D<CoordSystem1,U>
operator-( const PositionVector3D<CoordSystem1,U> & v1,
const PositionVector3D<CoordSystem2,U> & v2) {
return DisplacementVector3D<CoordSystem1,U>( Cartesian3D<typename CoordSystem1::Scalar>(
v1.X()-v2.X(), v1.Y()-v2.Y(),v1.Z()-v2.Z() )
);
}
/**
Addition of a PositionVector3D and a DisplacementVector3D.
The return type is a PositionVector3D,
of the same (coordinate system) type as the input PositionVector3D.
*/
template <class CoordSystem1, class CoordSystem2, class U>
inline
PositionVector3D<CoordSystem2,U>
operator+( PositionVector3D<CoordSystem2,U> p1,
const DisplacementVector3D<CoordSystem1,U> & v2) {
return p1 += v2;
}
/**
Addition of a DisplacementVector3D and a PositionVector3D.
The return type is a PositionVector3D,
of the same (coordinate system) type as the input PositionVector3D.
*/
template <class CoordSystem1, class CoordSystem2, class U>
inline
PositionVector3D<CoordSystem2,U>
operator+( DisplacementVector3D<CoordSystem1,U> const & v1,
PositionVector3D<CoordSystem2,U> p2) {
return p2 += v1;
}
/**
Subtraction of a DisplacementVector3D from a PositionVector3D.
The return type is a PositionVector3D,
of the same (coordinate system) type as the input PositionVector3D.
*/
template <class CoordSystem1, class CoordSystem2, class U>
inline
PositionVector3D<CoordSystem2,U>
operator-( PositionVector3D<CoordSystem2,U> p1,
DisplacementVector3D<CoordSystem1,U> const & v2) {
return p1 -= v2;
}
// Scaling of a position vector with a real number is not physically meaningful
// ------------- I/O to/from streams -------------
template< class char_t, class traits_t, class T, class U >
inline
std::basic_ostream<char_t,traits_t> &
operator << ( std::basic_ostream<char_t,traits_t> & os
, PositionVector3D<T,U> const & v
)
{
if( !os ) return os;
typename T::Scalar a, b, c;
v.GetCoordinates(a, b, c);
if( detail::get_manip( os, detail::bitforbit ) ) {
detail::set_manip( os, detail::bitforbit, '\00' );
typedef GenVector_detail::BitReproducible BR;
BR::Output(os, a);
BR::Output(os, b);
BR::Output(os, c);
}
else {
os << detail::get_manip( os, detail::open ) << a
<< detail::get_manip( os, detail::sep ) << b
<< detail::get_manip( os, detail::sep ) << c
<< detail::get_manip( os, detail::close );
}
return os;
} // op<< <>()
template< class char_t, class traits_t, class T, class U >
inline
std::basic_istream<char_t,traits_t> &
operator >> ( std::basic_istream<char_t,traits_t> & is
, PositionVector3D<T,U> & v
)
{
if( !is ) return is;
typename T::Scalar a, b, c;
if( detail::get_manip( is, detail::bitforbit ) ) {
detail::set_manip( is, detail::bitforbit, '\00' );
typedef GenVector_detail::BitReproducible BR;
BR::Input(is, a);
BR::Input(is, b);
BR::Input(is, c);
}
else {
detail::require_delim( is, detail::open ); is >> a;
detail::require_delim( is, detail::sep ); is >> b;
detail::require_delim( is, detail::sep ); is >> c;
detail::require_delim( is, detail::close );
}
if( is )
v.SetCoordinates(a, b, c);
return is;
} // op>> <>()
} // namespace Math
} // namespace ROOT
#endif /* ROOT_Math_GenVector_PositionVector3D */
|