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 &) | |
TVector3 (Double_t x, Double_t y, Double_t z) | |
~TVector3 () override | |
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 &) |
NewUzVector must be normalized ! | |
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) |
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) | |
TObject copy ctor. | |
virtual | ~TObject () |
TObject destructor. | |
void | AbstractMethod (const char *method) const |
Use this method to implement an "abstract" method that you don't want to leave purely abstract. | |
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 *ptr) |
Operator delete. | |
void | operator delete (void *ptr, void *vp) |
Only called by placement new when throwing an exception. | |
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) |
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 () |
#include <TVector3.h>
typedef Double_t TVector3::Scalar |
Definition at line 26 of file TVector3.h.
|
inline |
Constructors.
Definition at line 247 of file TVector3.h.
Definition at line 253 of file TVector3.h.
|
inline |
Definition at line 256 of file TVector3.h.
|
inline |
Definition at line 259 of file TVector3.h.
|
inline |
Definition at line 250 of file TVector3.h.
|
inlineoverride |
Definition at line 40 of file TVector3.h.
Return the angle w.r.t. another 3-vector.
Definition at line 203 of file TVector3.cxx.
|
static |
|
inlinestaticconstexpr |
Definition at line 188 of file TVector3.h.
|
inline |
Definition at line 371 of file TVector3.h.
Definition at line 335 of file TVector3.h.
|
inlinestatic |
Definition at line 188 of file TVector3.h.
Definition at line 396 of file TVector3.h.
Return deltaR with respect to v.
Definition at line 378 of file TVector3.cxx.
Definition at line 331 of file TVector3.h.
Definition at line 404 of file TVector3.h.
|
inline |
Definition at line 400 of file TVector3.h.
|
inline |
Definition at line 409 of file TVector3.h.
|
inline |
Definition at line 233 of file TVector3.h.
|
inline |
Definition at line 239 of file TVector3.h.
|
inlineoverridevirtual |
Reimplemented from TObject.
Definition at line 188 of file TVector3.h.
|
inline |
Definition at line 86 of file TVector3.h.
|
inline |
Definition at line 339 of file TVector3.h.
Definition at line 302 of file TVector3.h.
Definition at line 277 of file TVector3.h.
Definition at line 263 of file TVector3.h.
Multiplication operator.
Definition at line 189 of file TVector3.cxx.
Definition at line 324 of file TVector3.h.
Definition at line 306 of file TVector3.h.
|
inline |
Definition at line 320 of file TVector3.h.
Definition at line 313 of file TVector3.h.
Definition at line 291 of file TVector3.h.
Definition at line 298 of file TVector3.h.
Definition at line 210 of file TVector3.h.
Definition at line 211 of file TVector3.h.
|
inline |
Definition at line 342 of file TVector3.h.
Double_t TVector3::Perp | ( | ) | const |
Return the transverse component (R in cylindrical coordinate system)
Definition at line 219 of file TVector3.cxx.
Return the transverse component (R in cylindrical coordinate system)
Definition at line 228 of file TVector3.cxx.
|
inline |
Definition at line 353 of file TVector3.h.
Definition at line 358 of file TVector3.h.
Double_t TVector3::Phi | ( | ) | const |
Return the azimuth angle. Returns phi from -pi to pi.
Definition at line 236 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 326 of file TVector3.cxx.
|
inline |
Definition at line 356 of file TVector3.h.
Definition at line 367 of file TVector3.h.
|
inline |
Definition at line 219 of file TVector3.h.
|
inline |
Definition at line 220 of file TVector3.h.
|
inline |
Definition at line 221 of file TVector3.h.
Rotate vector.
Definition at line 296 of file TVector3.cxx.
void TVector3::RotateUz | ( | const TVector3 & | NewUzVector | ) |
NewUzVector must be normalized !
Definition at line 305 of file TVector3.cxx.
void TVector3::RotateX | ( | Double_t | angle | ) |
Rotate vector around X.
Definition at line 263 of file TVector3.cxx.
void TVector3::RotateY | ( | Double_t | angle | ) |
Rotate vector around Y.
Definition at line 274 of file TVector3.cxx.
void TVector3::RotateZ | ( | Double_t | angle | ) |
Rotate vector around Z.
Definition at line 285 of file TVector3.cxx.
|
inline |
Definition at line 376 of file TVector3.h.
Setter with mag, theta, phi.
Definition at line 388 of file TVector3.cxx.
|
inline |
Definition at line 388 of file TVector3.h.
void TVector3::SetPhi | ( | Double_t | ph | ) |
Set phi keeping mag and theta constant (BaBar).
Definition at line 368 of file TVector3.cxx.
Set Pt, Eta and Phi.
Definition at line 338 of file TVector3.cxx.
Set Pt, Theta and Phi.
Definition at line 346 of file TVector3.cxx.
void TVector3::SetTheta | ( | Double_t | th | ) |
Set theta keeping mag and phi constant (BaBar).
Definition at line 356 of file TVector3.cxx.
|
inline |
Definition at line 223 of file TVector3.h.
Definition at line 227 of file TVector3.h.
|
inline |
Definition at line 224 of file TVector3.h.
|
inline |
Definition at line 225 of file TVector3.h.
|
overridevirtual |
Stream an object of class TVector3.
Reimplemented from TObject.
Definition at line 399 of file TVector3.cxx.
|
inline |
Definition at line 188 of file TVector3.h.
Double_t TVector3::Theta | ( | ) | const |
Return the polar angle.
Definition at line 244 of file TVector3.cxx.
Transform this vector with a TRotation.
Definition at line 196 of file TVector3.cxx.
TVector3 TVector3::Unit | ( | ) | const |
Return unit vector parallel to this.
Definition at line 252 of file TVector3.cxx.
|
inline |
Definition at line 213 of file TVector3.h.
|
inline |
Definition at line 216 of file TVector3.h.
|
inline |
Definition at line 413 of file TVector3.h.
|
inline |
Definition at line 214 of file TVector3.h.
|
inline |
Definition at line 217 of file TVector3.h.
|
inline |
Definition at line 215 of file TVector3.h.
|
inline |
Definition at line 218 of file TVector3.h.
|
friend |
Definition at line 191 of file TVector3.h.
|
private |
Definition at line 185 of file TVector3.h.
|
private |
Definition at line 185 of file TVector3.h.
|
private |
Definition at line 185 of file TVector3.h.