File indexing completed on 2025-01-18 10:10:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef ROOT_Math_GenVector_PositionVector3D
0018 #define ROOT_Math_GenVector_PositionVector3D 1
0019
0020 #include "Math/GenVector/DisplacementVector3Dfwd.h"
0021
0022 #include "Math/GenVector/Cartesian3D.h"
0023
0024 #include "Math/GenVector/GenVectorIO.h"
0025
0026 #include "Math/GenVector/BitReproducible.h"
0027
0028 #include "Math/GenVector/CoordinateSystemTags.h"
0029
0030
0031 #include <cassert>
0032
0033 namespace ROOT {
0034
0035 namespace Math {
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 template <class CoordSystem, class Tag = DefaultCoordinateSystemTag >
0055 class PositionVector3D {
0056
0057 public:
0058
0059 typedef typename CoordSystem::Scalar Scalar;
0060 typedef CoordSystem CoordinateType;
0061 typedef Tag CoordinateSystemTag;
0062
0063
0064
0065
0066
0067
0068
0069 constexpr PositionVector3D() : fCoordinates() { }
0070
0071
0072
0073
0074
0075
0076 constexpr PositionVector3D(const Scalar & a, const Scalar & b, const Scalar & c) :
0077 fCoordinates ( a , b, c) { }
0078
0079
0080
0081
0082
0083 template <class T>
0084 explicit constexpr PositionVector3D( const PositionVector3D<T,Tag> & v) :
0085 fCoordinates ( v.Coordinates() ) { }
0086
0087
0088
0089
0090 template <class T>
0091 explicit constexpr PositionVector3D( const DisplacementVector3D<T,Tag> & p) :
0092 fCoordinates ( p.Coordinates() ) { }
0093
0094
0095
0096
0097
0098 template <class ForeignVector>
0099 explicit constexpr PositionVector3D( const ForeignVector & v) :
0100 fCoordinates ( Cartesian3D<Scalar>( v.x(), v.y(), v.z() ) ) { }
0101
0102 #ifdef LATER
0103
0104
0105
0106
0107
0108
0109
0110
0111 template <class LAVector>
0112 PositionVector3D(const LAVector & v, size_t index0 ) {
0113 fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
0114 }
0115 #endif
0116
0117
0118
0119
0120
0121
0122
0123
0124 template <class OtherCoords>
0125 PositionVector3D & operator=
0126 ( const PositionVector3D<OtherCoords,Tag> & v) {
0127 fCoordinates = v.Coordinates();
0128 return *this;
0129 }
0130
0131
0132
0133
0134 template <class OtherCoords>
0135 PositionVector3D & operator=
0136 ( const DisplacementVector3D<OtherCoords,Tag> & v) {
0137 fCoordinates = v.Coordinates();
0138 return *this;
0139 }
0140
0141
0142
0143
0144
0145 template <class ForeignVector>
0146 PositionVector3D & operator= ( const ForeignVector & v) {
0147 SetXYZ( v.x(), v.y(), v.z() );
0148 return *this;
0149 }
0150
0151 #ifdef LATER
0152
0153
0154
0155
0156
0157
0158
0159
0160 template <class LAVector>
0161 PositionVector3D & assignFrom(const LAVector & v, size_t index0 = 0) {
0162 fCoordinates = CoordSystem ( v[index0], v[index0+1], v[index0+2] );
0163 return *this;
0164 }
0165 #endif
0166
0167
0168
0169
0170 const CoordSystem & Coordinates() const {
0171 return fCoordinates;
0172 }
0173
0174
0175
0176
0177 PositionVector3D<CoordSystem, Tag>& SetCoordinates( const Scalar src[] )
0178 { fCoordinates.SetCoordinates(src); return *this; }
0179
0180
0181
0182
0183 PositionVector3D<CoordSystem, Tag>& SetCoordinates( Scalar a, Scalar b, Scalar c )
0184 { fCoordinates.SetCoordinates(a, b, c); return *this; }
0185
0186
0187
0188
0189 template <class IT>
0190 PositionVector3D<CoordSystem, Tag>& SetCoordinates( IT begin, IT end )
0191 { IT a = begin; IT b = ++begin; IT c = ++begin;
0192 (void)end;
0193 assert (++begin==end);
0194 SetCoordinates (*a,*b,*c);
0195 return *this;
0196 }
0197
0198
0199
0200
0201 void GetCoordinates( Scalar& a, Scalar& b, Scalar& c ) const
0202 { fCoordinates.GetCoordinates(a, b, c); }
0203
0204
0205
0206
0207 void GetCoordinates( Scalar dest[] ) const
0208 { fCoordinates.GetCoordinates(dest); }
0209
0210
0211
0212
0213 template <class IT>
0214 void GetCoordinates( IT begin, IT end ) const
0215 { IT a = begin; IT b = ++begin; IT c = ++begin;
0216 (void)end;
0217 assert (++begin==end);
0218 GetCoordinates (*a,*b,*c);
0219 }
0220
0221
0222
0223
0224 template <class IT>
0225 void GetCoordinates( IT begin ) const {
0226 Scalar a = Scalar(0);
0227 Scalar b = Scalar(0);
0228 Scalar c = Scalar(0);
0229 GetCoordinates(a, b, c);
0230 *begin++ = a;
0231 *begin++ = b;
0232 *begin = c;
0233 }
0234
0235
0236
0237
0238
0239
0240 PositionVector3D<CoordSystem, Tag>& SetXYZ (Scalar a, Scalar b, Scalar c) {
0241 fCoordinates.SetXYZ(a,b,c);
0242 return *this;
0243 }
0244
0245
0246
0247
0248
0249
0250 bool operator==(const PositionVector3D & rhs) const {
0251 return fCoordinates==rhs.fCoordinates;
0252 }
0253 bool operator!= (const PositionVector3D & rhs) const {
0254 return !(operator==(rhs));
0255 }
0256
0257
0258
0259
0260
0261
0262 unsigned int Dimension() const
0263 {
0264 return fDimension;
0265 };
0266
0267
0268
0269
0270 Scalar X() const { return fCoordinates.X(); }
0271
0272
0273
0274
0275 Scalar Y() const { return fCoordinates.Y(); }
0276
0277
0278
0279
0280 Scalar Z() const { return fCoordinates.Z(); }
0281
0282
0283
0284
0285 Scalar R() const { return fCoordinates.R(); }
0286
0287
0288
0289
0290 Scalar Theta() const { return fCoordinates.Theta(); }
0291
0292
0293
0294
0295 Scalar Phi() const { return fCoordinates.Phi(); }
0296
0297
0298
0299
0300 Scalar Eta() const { return fCoordinates.Eta(); }
0301
0302
0303
0304
0305 Scalar Rho() const { return fCoordinates.Rho(); }
0306
0307
0308
0309
0310
0311
0312 Scalar Mag2() const { return fCoordinates.Mag2();}
0313
0314
0315
0316
0317 Scalar Perp2() const { return fCoordinates.Perp2();}
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327 PositionVector3D<CoordSystem, Tag>& SetX (Scalar xx) { fCoordinates.SetX(xx); return *this;}
0328
0329
0330
0331
0332 PositionVector3D<CoordSystem, Tag>& SetY (Scalar yy) { fCoordinates.SetY(yy); return *this;}
0333
0334
0335
0336
0337 PositionVector3D<CoordSystem, Tag>& SetZ (Scalar zz) { fCoordinates.SetZ(zz); return *this;}
0338
0339
0340
0341
0342 PositionVector3D<CoordSystem, Tag>& SetR (Scalar rr) { fCoordinates.SetR(rr); return *this;}
0343
0344
0345
0346
0347 PositionVector3D<CoordSystem, Tag>& SetTheta (Scalar ang) { fCoordinates.SetTheta(ang); return *this;}
0348
0349
0350
0351
0352 PositionVector3D<CoordSystem, Tag>& SetPhi (Scalar ang) { fCoordinates.SetPhi(ang); return *this;}
0353
0354
0355
0356
0357 PositionVector3D<CoordSystem, Tag>& SetRho (Scalar rr) { fCoordinates.SetRho(rr); return *this;}
0358
0359
0360
0361
0362 PositionVector3D<CoordSystem, Tag>& SetEta (Scalar etaval) { fCoordinates.SetEta(etaval); return *this;}
0363
0364
0365
0366
0367
0368
0369
0370
0371 template< class OtherCoords >
0372 Scalar Dot( const DisplacementVector3D<OtherCoords,Tag> & v) const {
0373 return X()*v.x() + Y()*v.y() + Z()*v.z();
0374 }
0375
0376
0377
0378
0379
0380
0381 template< class OtherCoords >
0382 PositionVector3D Cross( const DisplacementVector3D<OtherCoords,Tag> & v) const {
0383 PositionVector3D result;
0384 result.SetXYZ ( Y()*v.z() - v.y()*Z(),
0385 Z()*v.x() - v.z()*X(),
0386 X()*v.y() - v.x()*Y() );
0387 return result;
0388 }
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400 template <class OtherCoords>
0401 PositionVector3D & operator+= (const DisplacementVector3D<OtherCoords,Tag> & v)
0402 {
0403 SetXYZ( X() + v.X(), Y() + v.Y(), Z() + v.Z() );
0404 return *this;
0405 }
0406
0407
0408
0409
0410 template <class OtherCoords>
0411 PositionVector3D & operator-= (const DisplacementVector3D<OtherCoords,Tag> & v)
0412 {
0413 SetXYZ( X() - v.X(), Y() - v.Y(), Z() - v.Z() );
0414 return *this;
0415 }
0416
0417
0418
0419
0420 PositionVector3D & operator *= (Scalar a) {
0421 fCoordinates.Scale(a);
0422 return *this;
0423 }
0424
0425
0426
0427
0428 PositionVector3D & operator /= (Scalar a) {
0429 fCoordinates.Scale(1/a);
0430 return *this;
0431 }
0432
0433
0434
0435
0436
0437
0438 PositionVector3D operator * ( Scalar a ) const {
0439 PositionVector3D tmp(*this);
0440 tmp *= a;
0441 return tmp;
0442 }
0443
0444
0445
0446
0447 PositionVector3D operator / (Scalar a) const {
0448 PositionVector3D tmp(*this);
0449 tmp /= a;
0450 return tmp;
0451 }
0452
0453
0454
0455 Scalar x() const { return fCoordinates.X(); }
0456 Scalar y() const { return fCoordinates.Y(); }
0457 Scalar z() const { return fCoordinates.Z(); }
0458 Scalar r() const { return fCoordinates.R(); }
0459 Scalar theta() const { return fCoordinates.Theta(); }
0460 Scalar phi() const { return fCoordinates.Phi(); }
0461 Scalar eta() const { return fCoordinates.Eta(); }
0462 Scalar rho() const { return fCoordinates.Rho(); }
0463 Scalar mag2() const { return fCoordinates.Mag2(); }
0464 Scalar perp2() const { return fCoordinates.Perp2(); }
0465
0466 private:
0467
0468 CoordSystem fCoordinates;
0469 static constexpr unsigned int fDimension = CoordinateType::Dimension;
0470
0471
0472
0473
0474
0475 template <class OtherCoords, class OtherTag>
0476 explicit constexpr PositionVector3D( const PositionVector3D<OtherCoords, OtherTag> & );
0477
0478 template <class OtherCoords, class OtherTag>
0479 explicit constexpr PositionVector3D( const DisplacementVector3D<OtherCoords, OtherTag> & );
0480
0481 template <class OtherCoords, class OtherTag>
0482 PositionVector3D & operator=( const PositionVector3D<OtherCoords, OtherTag> & );
0483
0484 template <class OtherCoords, class OtherTag>
0485 PositionVector3D & operator=( const DisplacementVector3D<OtherCoords, OtherTag> & );
0486
0487 template <class OtherCoords, class OtherTag>
0488 PositionVector3D & operator+=(const DisplacementVector3D<OtherCoords, OtherTag> & );
0489
0490 template <class OtherCoords, class OtherTag>
0491 PositionVector3D & operator-=(const DisplacementVector3D<OtherCoords, OtherTag> & );
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 };
0508
0509
0510
0511
0512
0513
0514
0515 template <class CoordSystem, class U>
0516 inline
0517 PositionVector3D<CoordSystem>
0518 operator * ( typename PositionVector3D<CoordSystem,U>::Scalar a,
0519 PositionVector3D<CoordSystem,U> v) {
0520 return v *= a;
0521
0522
0523 }
0524
0525
0526
0527
0528
0529
0530
0531
0532 template <class CoordSystem1, class CoordSystem2, class U>
0533 inline
0534 DisplacementVector3D<CoordSystem1,U>
0535 operator-( const PositionVector3D<CoordSystem1,U> & v1,
0536 const PositionVector3D<CoordSystem2,U> & v2) {
0537 return DisplacementVector3D<CoordSystem1,U>( Cartesian3D<typename CoordSystem1::Scalar>(
0538 v1.X()-v2.X(), v1.Y()-v2.Y(),v1.Z()-v2.Z() )
0539 );
0540 }
0541
0542
0543
0544
0545
0546
0547 template <class CoordSystem1, class CoordSystem2, class U>
0548 inline
0549 PositionVector3D<CoordSystem2,U>
0550 operator+( PositionVector3D<CoordSystem2,U> p1,
0551 const DisplacementVector3D<CoordSystem1,U> & v2) {
0552 return p1 += v2;
0553 }
0554
0555
0556
0557
0558
0559
0560 template <class CoordSystem1, class CoordSystem2, class U>
0561 inline
0562 PositionVector3D<CoordSystem2,U>
0563 operator+( DisplacementVector3D<CoordSystem1,U> const & v1,
0564 PositionVector3D<CoordSystem2,U> p2) {
0565 return p2 += v1;
0566 }
0567
0568
0569
0570
0571
0572
0573 template <class CoordSystem1, class CoordSystem2, class U>
0574 inline
0575 PositionVector3D<CoordSystem2,U>
0576 operator-( PositionVector3D<CoordSystem2,U> p1,
0577 DisplacementVector3D<CoordSystem1,U> const & v2) {
0578 return p1 -= v2;
0579 }
0580
0581
0582
0583
0584
0585 template <
0586 class char_t, class traits_t, class T, class U,
0587 typename std::enable_if<std::is_arithmetic<typename PositionVector3D<T, U>::Scalar>::value>::type * = nullptr>
0588 std::basic_ostream<char_t, traits_t> &operator<<(std::basic_ostream<char_t, traits_t> &os,
0589 PositionVector3D<T, U> const &v)
0590 {
0591 if (os) {
0592
0593 typename T::Scalar a = 0;
0594 typename T::Scalar b = 0;
0595 typename T::Scalar c = 0;
0596 v.GetCoordinates(a, b, c);
0597
0598 if (detail::get_manip(os, detail::bitforbit)) {
0599 detail::set_manip(os, detail::bitforbit, '\00');
0600 typedef GenVector_detail::BitReproducible BR;
0601 BR::Output(os, a);
0602 BR::Output(os, b);
0603 BR::Output(os, c);
0604 } else {
0605 os << detail::get_manip(os, detail::open) << a << detail::get_manip(os, detail::sep) << b
0606 << detail::get_manip(os, detail::sep) << c << detail::get_manip(os, detail::close);
0607 }
0608 }
0609 return os;
0610 }
0611
0612 template <
0613 class char_t, class traits_t, class T, class U,
0614 typename std::enable_if<!std::is_arithmetic<typename PositionVector3D<T, U>::Scalar>::value>::type * = nullptr>
0615 std::basic_ostream<char_t, traits_t> &operator<<(std::basic_ostream<char_t, traits_t> &os,
0616 PositionVector3D<T, U> const &v)
0617 {
0618 if (os) {
0619 os << "{ ";
0620 for (std::size_t i = 0; i < PositionVector3D<T, U>::Scalar::Size; ++i) {
0621 os << "(" << v.x()[i] << "," << v.y()[i] << "," << v.z()[i] << ") ";
0622 }
0623 os << "}";
0624 }
0625 return os;
0626 }
0627
0628 template< class char_t, class traits_t, class T, class U >
0629 inline
0630 std::basic_istream<char_t,traits_t> &
0631 operator >> ( std::basic_istream<char_t,traits_t> & is
0632 , PositionVector3D<T,U> & v
0633 )
0634 {
0635 if( !is ) return is;
0636
0637 typename T::Scalar a, b, c;
0638
0639 if( detail::get_manip( is, detail::bitforbit ) ) {
0640 detail::set_manip( is, detail::bitforbit, '\00' );
0641 typedef GenVector_detail::BitReproducible BR;
0642 BR::Input(is, a);
0643 BR::Input(is, b);
0644 BR::Input(is, c);
0645 }
0646 else {
0647 detail::require_delim( is, detail::open ); is >> a;
0648 detail::require_delim( is, detail::sep ); is >> b;
0649 detail::require_delim( is, detail::sep ); is >> c;
0650 detail::require_delim( is, detail::close );
0651 }
0652
0653 if( is )
0654 v.SetCoordinates(a, b, c);
0655 return is;
0656
0657 }
0658
0659
0660
0661
0662 }
0663
0664 }
0665
0666
0667 #endif