TVector3 is a legacy class. It is slower and worse for serialization than the recommended superior alternative ROOT::Math::XYZVector.
More details can be found in the documentation of the Physics Vectors package.
TVector3 is a general three vector class, which can be used for the description of different vectors in 3D.
TVector3 has been implemented as a vector of three Double_t variables, representing the cartesian coordinates. By default all components are initialized to zero:
It is also possible (but not recommended) to initialize a TVector3 with a Double_t or Float_t C array.
You can get the basic components either by name or by index using operator():
The member functions SetX(), SetY(), SetZ() and SetXYZ() allow to set the components:
To get information on the TVector3 in spherical (rho,phi,theta) or cylindrical (z,r,theta) coordinates, the
the member functions Mag() (=magnitude=rho in spherical coordinates), Mag2(), Theta(), CosTheta(), Phi(), Perp() (the transverse component=r in cylindrical coordinates), Perp2() can be used:
It is also possible to get the transverse component with respect to another vector:
The pseudo-rapidity ( eta=-ln (tan (theta/2)) ) can be obtained by Eta() or PseudoRapidity():
There are set functions to change one of the non-cartesian coordinates:
The TVector3 class provides the operators to add, subtract, scale and compare vectors:
TVector3 objects can be rotated by objects of the TRotation class using the Transform() member functions,
the operator *= or the operator * of the TRotation class:
transforms v1 from the rotated frame (z' parallel to direction, x' in the theta plane and y' in the xy plane as well as perpendicular to the theta plane) to the (x,y,z) frame.
Definition at line 22 of file TVector3.h.
Public Types | |
| typedef Double_t | Scalar |
Public Types inherited from TObject | |
| enum | { kIsOnHeap = 0x01000000 , kNotDeleted = 0x02000000 , kZombie = 0x04000000 , kInconsistent = 0x08000000 , kBitMask = 0x00ffffff } |
| enum | { kSingleKey = (1ULL << ( 0 )) , kOverwrite = (1ULL << ( 1 )) , kWriteDelete = (1ULL << ( 2 )) } |
| enum | EDeprecatedStatusBits { kObjInCanvas = (1ULL << ( 3 )) } |
| enum | EStatusBits { kCanDelete = (1ULL << ( 0 )) , kMustCleanup = (1ULL << ( 3 )) , kIsReferenced = (1ULL << ( 4 )) , kHasUUID = (1ULL << ( 5 )) , kCannotPick = (1ULL << ( 6 )) , kNoContextMenu = (1ULL << ( 8 )) , kInvalidObject = (1ULL << ( 13 )) } |
Public Member Functions | |
| TVector3 () | |
| Constructors. | |
| TVector3 (const Double_t *) | |
| TVector3 (const Float_t *) | |
| TVector3 (const TVector3 &) noexcept | |
| TVector3 (Double_t x, Double_t y, Double_t z) | |
| ~TVector3 () override=default | |
| Double_t | Angle (const TVector3 &) const |
| Return the angle w.r.t. another 3-vector. | |
| Double_t | CosTheta () const |
| TVector3 | Cross (const TVector3 &) const |
| Double_t | DeltaPhi (const TVector3 &) const |
| Double_t | DeltaR (const TVector3 &) const |
| Return deltaR with respect to v. | |
| Double_t | Dot (const TVector3 &) const |
| Double_t | DrEtaPhi (const TVector3 &) const |
| Double_t | Eta () const |
| TVector2 | EtaPhiVector () const |
| void | GetXYZ (Double_t *carray) const |
| void | GetXYZ (Float_t *carray) const |
| TClass * | IsA () const override |
| Double_t | Mag () const |
| Double_t | Mag2 () const |
| Bool_t | operator!= (const TVector3 &) const |
| Double_t & | operator() (int) |
| Double_t | operator() (int) const |
| TVector3 & | operator*= (const TRotation &) |
| Multiplication operator. | |
| TVector3 & | operator*= (Double_t) |
| TVector3 & | operator+= (const TVector3 &) |
| TVector3 | operator- () const |
| TVector3 & | operator-= (const TVector3 &) |
| TVector3 & | operator= (const TVector3 &) |
| Bool_t | operator== (const TVector3 &) const |
| Double_t & | operator[] (int) |
| Double_t | operator[] (int) const |
| TVector3 | Orthogonal () const |
| Double_t | Perp () const |
| Return the transverse component (R in cylindrical coordinate system) | |
| Double_t | Perp (const TVector3 &) const |
| Return the transverse component (R in cylindrical coordinate system) | |
| Double_t | Perp2 () const |
| Double_t | Perp2 (const TVector3 &) const |
| Double_t | Phi () const |
| Return the azimuth angle. Returns phi from -pi to pi. | |
| void | Print (Option_t *option="") const override |
| Print vector parameters. | |
| Double_t | PseudoRapidity () const |
| Double_t m = Mag(); return 0.5*log( (m+fZ)/(m-fZ) ); guard against Pt=0. | |
| Double_t | Pt () const |
| Double_t | Pt (const TVector3 &) const |
| Double_t | Px () const |
| Double_t | Py () const |
| Double_t | Pz () const |
| void | Rotate (Double_t, const TVector3 &) |
| Rotate vector. | |
| void | RotateUz (const TVector3 &) |
| Express the coordinates of this vector in a new reference frame S' whose z' axis will lie in the direction of NewUzVector (expressed in frame S). | |
| void | RotateX (Double_t) |
| Rotate vector around X. | |
| void | RotateY (Double_t) |
| Rotate vector around Y. | |
| void | RotateZ (Double_t) |
| Rotate vector around Z. | |
| void | SetMag (Double_t) |
| void | SetMagThetaPhi (Double_t mag, Double_t theta, Double_t phi) |
| Setter with mag, theta, phi. | |
| void | SetPerp (Double_t) |
| void | SetPhi (Double_t) |
| Set phi keeping mag and theta constant (BaBar). | |
| void | SetPtEtaPhi (Double_t pt, Double_t eta, Double_t phi) |
| Set Pt, Eta and Phi. | |
| void | SetPtThetaPhi (Double_t pt, Double_t theta, Double_t phi) |
| Set Pt, Theta and Phi. | |
| void | SetTheta (Double_t) |
| Set theta keeping mag and phi constant (BaBar). | |
| void | SetX (Double_t) |
| void | SetXYZ (Double_t x, Double_t y, Double_t z) |
| void | SetY (Double_t) |
| void | SetZ (Double_t) |
| constexpr std::size_t | size () const |
| The length is always 3. For compatibility with the standard library. | |
| void | Streamer (TBuffer &) override |
| Stream an object of class TVector3. | |
| void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
| Double_t | Theta () const |
| Return the polar angle. | |
| TVector3 & | Transform (const TRotation &) |
| Transform this vector with a TRotation. | |
| TVector3 | Unit () const |
| Return unit vector parallel to this. | |
| Double_t | x () const |
| Double_t | X () const |
| TVector2 | XYvector () const |
| Double_t | y () const |
| Double_t | Y () const |
| Double_t | z () const |
| Double_t | Z () const |
Public Member Functions inherited from TObject | |
| TObject () | |
| TObject constructor. | |
| TObject (const TObject &object) noexcept | |
| TObject copy ctor. | |
| virtual | ~TObject () |
| TObject destructor. | |
| void | AbstractMethod (const char *method) const |
| Call this function within a function that you don't want to define as purely virtual, in order not to force all users deriving from that class to implement that maybe (on their side) unused function; but at the same time, emit a run-time warning if they try to call it, telling that it is not implemented in the derived class: action must thus be taken on the user side to override it. | |
| virtual void | AppendPad (Option_t *option="") |
| Append graphics object to current pad. | |
| virtual void | Browse (TBrowser *b) |
| Browse object. May be overridden for another default action. | |
| ULong_t | CheckedHash () |
| Check and record whether this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. | |
| virtual const char * | ClassName () const |
| Returns name of class to which the object belongs. | |
| virtual void | Clear (Option_t *="") |
| virtual TObject * | Clone (const char *newname="") const |
| Make a clone of an object using the Streamer facility. | |
| virtual Int_t | Compare (const TObject *obj) const |
| Compare abstract method. | |
| virtual void | Copy (TObject &object) const |
| Copy this to obj. | |
| virtual void | Delete (Option_t *option="") |
| Delete this object. | |
| virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
| Computes distance from point (px,py) to the object. | |
| virtual void | Draw (Option_t *option="") |
| Default Draw method for all objects. | |
| virtual void | DrawClass () const |
| Draw class inheritance tree of the class to which this object belongs. | |
| virtual TObject * | DrawClone (Option_t *option="") const |
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1). | |
| virtual void | Dump () const |
| Dump contents of object on stdout. | |
| virtual void | Error (const char *method, const char *msgfmt,...) const |
| Issue error message. | |
| virtual void | Execute (const char *method, const char *params, Int_t *error=nullptr) |
| Execute method on this object with the given parameter string, e.g. | |
| virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr) |
| Execute method on this object with parameters stored in the TObjArray. | |
| virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
| Execute action corresponding to an event at (px,py). | |
| virtual void | Fatal (const char *method, const char *msgfmt,...) const |
| Issue fatal error message. | |
| virtual TObject * | FindObject (const char *name) const |
| Must be redefined in derived classes. | |
| virtual TObject * | FindObject (const TObject *obj) const |
| Must be redefined in derived classes. | |
| virtual Option_t * | GetDrawOption () const |
| Get option used by the graphics system to draw this object. | |
| virtual const char * | GetIconName () const |
| Returns mime type name of object. | |
| virtual const char * | GetName () const |
| Returns name of object. | |
| virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
| Returns string containing info about the object at position (px,py). | |
| virtual Option_t * | GetOption () const |
| virtual const char * | GetTitle () const |
| Returns title of object. | |
| virtual UInt_t | GetUniqueID () const |
| Return the unique object id. | |
| virtual Bool_t | HandleTimer (TTimer *timer) |
| Execute action in response of a timer timing out. | |
| virtual ULong_t | Hash () const |
| Return hash value for this object. | |
| Bool_t | HasInconsistentHash () const |
| Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. | |
| virtual void | Info (const char *method, const char *msgfmt,...) const |
| Issue info message. | |
| virtual Bool_t | InheritsFrom (const char *classname) const |
| Returns kTRUE if object inherits from class "classname". | |
| virtual Bool_t | InheritsFrom (const TClass *cl) const |
| Returns kTRUE if object inherits from TClass cl. | |
| virtual void | Inspect () const |
| Dump contents of this object in a graphics canvas. | |
| void | InvertBit (UInt_t f) |
| Bool_t | IsDestructed () const |
| IsDestructed. | |
| virtual Bool_t | IsEqual (const TObject *obj) const |
| Default equal comparison (objects are equal if they have the same address in memory). | |
| virtual Bool_t | IsFolder () const |
| Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). | |
| R__ALWAYS_INLINE Bool_t | IsOnHeap () const |
| virtual Bool_t | IsSortable () const |
| R__ALWAYS_INLINE Bool_t | IsZombie () const |
| virtual void | ls (Option_t *option="") const |
| The ls function lists the contents of a class on stdout. | |
| void | MayNotUse (const char *method) const |
| Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). | |
| virtual Bool_t | Notify () |
| This method must be overridden to handle object notification (the base implementation is no-op). | |
| void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
| Use this method to declare a method obsolete. | |
| void | operator delete (void *, size_t) |
| Operator delete for sized deallocation. | |
| void | operator delete (void *ptr) |
| Operator delete. | |
| void | operator delete (void *ptr, void *vp) |
| Only called by placement new when throwing an exception. | |
| void | operator delete[] (void *, size_t) |
| Operator delete [] for sized deallocation. | |
| void | operator delete[] (void *ptr) |
| Operator delete []. | |
| void | operator delete[] (void *ptr, void *vp) |
| Only called by placement new[] when throwing an exception. | |
| void * | operator new (size_t sz) |
| void * | operator new (size_t sz, void *vp) |
| void * | operator new[] (size_t sz) |
| void * | operator new[] (size_t sz, void *vp) |
| TObject & | operator= (const TObject &rhs) noexcept |
| TObject assignment operator. | |
| virtual void | Paint (Option_t *option="") |
| This method must be overridden if a class wants to paint itself. | |
| virtual void | Pop () |
| Pop on object drawn in a pad to the top of the display list. | |
| virtual Int_t | Read (const char *name) |
| Read contents of object with specified name from the current directory. | |
| virtual void | RecursiveRemove (TObject *obj) |
| Recursively remove this object from a list. | |
| void | ResetBit (UInt_t f) |
| virtual void | SaveAs (const char *filename="", Option_t *option="") const |
| Save this object in the file specified by filename. | |
| virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
| Save a primitive as a C++ statement(s) on output stream "out". | |
| void | SetBit (UInt_t f) |
| void | SetBit (UInt_t f, Bool_t set) |
| Set or unset the user status bits as specified in f. | |
| virtual void | SetDrawOption (Option_t *option="") |
| Set drawing option for object. | |
| virtual void | SetUniqueID (UInt_t uid) |
| Set the unique object id. | |
| void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
| virtual void | SysError (const char *method, const char *msgfmt,...) const |
| Issue system error message. | |
| R__ALWAYS_INLINE Bool_t | TestBit (UInt_t f) const |
| Int_t | TestBits (UInt_t f) const |
| virtual void | UseCurrentStyle () |
| Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. | |
| virtual void | Warning (const char *method, const char *msgfmt,...) const |
| Issue warning message. | |
| virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) |
| Write this object to the current directory. | |
| virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const |
| Write this object to the current directory. | |
Static Public Member Functions | |
| static TClass * | Class () |
| static const char * | Class_Name () |
| static constexpr Version_t | Class_Version () |
| static const char * | DeclFileName () |
Static Public Member Functions inherited from TObject | |
| static TClass * | Class () |
| static const char * | Class_Name () |
| static constexpr Version_t | Class_Version () |
| static const char * | DeclFileName () |
| static Longptr_t | GetDtorOnly () |
| Return destructor only flag. | |
| static Bool_t | GetObjectStat () |
| Get status of object stat flag. | |
| static void | SetDtorOnly (void *obj) |
| Set destructor only flag. | |
| static void | SetObjectStat (Bool_t stat) |
| Turn on/off tracking of objects in the TObjectTable. | |
Private Attributes | |
| Double_t | fX |
| Double_t | fY |
| Double_t | fZ |
Friends | |
| class | TLorentzVector |
Additional Inherited Members | |
Protected Types inherited from TObject | |
| enum | { kOnlyPrepStep = (1ULL << ( 3 )) } |
Protected Member Functions inherited from TObject | |
| virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
| Interface to ErrorHandler (protected). | |
| void | MakeZombie () |
Static Protected Member Functions inherited from TObject | |
| static void | SavePrimitiveConstructor (std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE) |
| Save object constructor in the output stream "out". | |
| static void | SavePrimitiveDraw (std::ostream &out, const char *variable_name, Option_t *option=nullptr) |
| Save invocation of primitive Draw() method Skipped if option contains "nodraw" string. | |
| static TString | SavePrimitiveVector (std::ostream &out, const char *prefix, Int_t len, Double_t *arr, Bool_t empty_line=kFALSE) |
| Save array in the output stream "out" as vector. | |
#include <TVector3.h>
Definition at line 26 of file TVector3.h.
|
inline |
Constructors.
Definition at line 250 of file TVector3.h.
Definition at line 256 of file TVector3.h.
Definition at line 259 of file TVector3.h.
Definition at line 262 of file TVector3.h.
Definition at line 253 of file TVector3.h.
|
overridedefault |
Return the angle w.r.t. another 3-vector.
Definition at line 202 of file TVector3.cxx.
Definition at line 191 of file TVector3.h.
|
inline |
Definition at line 374 of file TVector3.h.
Definition at line 338 of file TVector3.h.
Definition at line 191 of file TVector3.h.
Definition at line 399 of file TVector3.h.
Return deltaR with respect to v.
Definition at line 397 of file TVector3.cxx.
Definition at line 334 of file TVector3.h.
Definition at line 407 of file TVector3.h.
|
inline |
Definition at line 403 of file TVector3.h.
|
inline |
Definition at line 412 of file TVector3.h.
|
inline |
Definition at line 236 of file TVector3.h.
|
inline |
Definition at line 242 of file TVector3.h.
|
inlineoverridevirtual |
Reimplemented from TObject.
Definition at line 191 of file TVector3.h.
|
inline |
Definition at line 89 of file TVector3.h.
|
inline |
Definition at line 342 of file TVector3.h.
Definition at line 305 of file TVector3.h.
Definition at line 280 of file TVector3.h.
Definition at line 266 of file TVector3.h.
Multiplication operator.
Definition at line 188 of file TVector3.cxx.
Definition at line 327 of file TVector3.h.
Definition at line 309 of file TVector3.h.
|
inline |
Definition at line 323 of file TVector3.h.
Definition at line 316 of file TVector3.h.
Definition at line 294 of file TVector3.h.
Definition at line 301 of file TVector3.h.
Definition at line 213 of file TVector3.h.
Definition at line 214 of file TVector3.h.
|
inline |
Definition at line 345 of file TVector3.h.
| Double_t TVector3::Perp | ( | ) | const |
Return the transverse component (R in cylindrical coordinate system)
Definition at line 218 of file TVector3.cxx.
Return the transverse component (R in cylindrical coordinate system)
Definition at line 227 of file TVector3.cxx.
|
inline |
Definition at line 356 of file TVector3.h.
Definition at line 361 of file TVector3.h.
| Double_t TVector3::Phi | ( | ) | const |
Return the azimuth angle. Returns phi from -pi to pi.
Definition at line 235 of file TVector3.cxx.
|
overridevirtual |
| Double_t TVector3::PseudoRapidity | ( | ) | const |
Double_t m = Mag(); return 0.5*log( (m+fZ)/(m-fZ) ); guard against Pt=0.
Definition at line 345 of file TVector3.cxx.
|
inline |
Definition at line 359 of file TVector3.h.
Definition at line 370 of file TVector3.h.
|
inline |
Definition at line 222 of file TVector3.h.
|
inline |
Definition at line 223 of file TVector3.h.
|
inline |
Definition at line 224 of file TVector3.h.
Rotate vector.
Definition at line 295 of file TVector3.cxx.
Express the coordinates of this vector in a new reference frame S' whose z' axis will lie in the direction of NewUzVector (expressed in frame S).
\[ R = \left( \begin{array}{ccc} u1*u3/up & -u2/up & u1 \\ u2*u3/up & u1/up & u2 \\ -up & 0 & u3 \end{array} \right) \]
The columns of the applied rotation matrix represent the coordinates of unit vectors of the new axes in the original coordinate system. The z' axis i.e. third column is NewUzVector=(u1,u2,u3). The y' axis i.e. second column is the cross product of the old and new Z axes: (0,0,1)x(u1,u2,u3) = (-u2,u1,0), which after normalisation becomes (-u2/up,u1/up,0) with up=sqrt(u1*u1+u2*u2). The x' axis i.e. first column is the cross product of new y' and z' axes: (-u2/up,u1/up,0)x(u1,u2,u3) = (u1*u3/up,u2*u3/up,-up). In the special case that z' is parallel to z, the vector is left untouched; if it's antiparallel, the sign of the x and z vector coordinates is inverted.
This function originates from CLHEP / Geant4.
axis=(u2/up, -u1/up, 0) andangle=-arccos(u3), beingaxis the normalized cross-product of(u1,u2,u3)and(0,0,1)`. Definition at line 324 of file TVector3.cxx.
| void TVector3::RotateX | ( | Double_t | angle | ) |
Rotate vector around X.
Definition at line 262 of file TVector3.cxx.
| void TVector3::RotateY | ( | Double_t | angle | ) |
Rotate vector around Y.
Definition at line 273 of file TVector3.cxx.
| void TVector3::RotateZ | ( | Double_t | angle | ) |
Rotate vector around Z.
Definition at line 284 of file TVector3.cxx.
|
inline |
Definition at line 379 of file TVector3.h.
Setter with mag, theta, phi.
Definition at line 407 of file TVector3.cxx.
|
inline |
Definition at line 391 of file TVector3.h.
| void TVector3::SetPhi | ( | Double_t | ph | ) |
Set phi keeping mag and theta constant (BaBar).
Definition at line 387 of file TVector3.cxx.
Set Pt, Eta and Phi.
Definition at line 357 of file TVector3.cxx.
Set Pt, Theta and Phi.
Definition at line 365 of file TVector3.cxx.
| void TVector3::SetTheta | ( | Double_t | th | ) |
Set theta keeping mag and phi constant (BaBar).
Definition at line 375 of file TVector3.cxx.
|
inline |
Definition at line 226 of file TVector3.h.
Definition at line 230 of file TVector3.h.
|
inline |
Definition at line 227 of file TVector3.h.
|
inline |
Definition at line 228 of file TVector3.h.
|
inlineconstexpr |
The length is always 3. For compatibility with the standard library.
Definition at line 44 of file TVector3.h.
|
overridevirtual |
Stream an object of class TVector3.
Reimplemented from TObject.
Definition at line 418 of file TVector3.cxx.
|
inline |
Definition at line 191 of file TVector3.h.
| Double_t TVector3::Theta | ( | ) | const |
Return the polar angle.
Definition at line 243 of file TVector3.cxx.
Transform this vector with a TRotation.
Definition at line 195 of file TVector3.cxx.
| TVector3 TVector3::Unit | ( | ) | const |
Return unit vector parallel to this.
Definition at line 251 of file TVector3.cxx.
|
inline |
Definition at line 216 of file TVector3.h.
|
inline |
Definition at line 219 of file TVector3.h.
|
inline |
Definition at line 416 of file TVector3.h.
|
inline |
Definition at line 217 of file TVector3.h.
|
inline |
Definition at line 220 of file TVector3.h.
|
inline |
Definition at line 218 of file TVector3.h.
|
inline |
Definition at line 221 of file TVector3.h.
|
friend |
Definition at line 194 of file TVector3.h.
|
private |
Definition at line 188 of file TVector3.h.
|
private |
Definition at line 188 of file TVector3.h.
|
private |
Definition at line 188 of file TVector3.h.