SRVector3D.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file SRVector3D.h
3 // \author Christopher Backhouse - bckhouse@caltech.edu
4 ////////////////////////////////////////////////////////////////////////
5 
6 #ifndef SRVECTOR3D_H
7 #define SRVECTOR3D_H
8 
9 #include "TVector3.h"
10 
11 namespace caf
12 {
13  /// A 3-vector with more efficient storage than TVector3
14  class SRVector3D
15  {
16  public:
17  SRVector3D();
18  SRVector3D(float x, float y, float z);
19  /// Easy conversion from TVector3
20  SRVector3D(const TVector3& v);
21  virtual ~SRVector3D();
22 
23  void SetXYZ(float x, float y, float z);
24 
25  /// Easy conversion back to TVector3
26  operator TVector3() const;
27 
28  void SetX(float _x){x = _x;}
29  void SetY(float _y){y = _y;}
30  void SetZ(float _z){z = _z;}
31 
32  float X() const {return x;}
33  float Y() const {return y;}
34  float Z() const {return z;}
35 
36  // The more common TVector3 operations, mostly for use with TTree::Draw
37  //
38  // NB: you need to specify the initial "rec." when using these
39  float Mag2() const {return x*x+y*y+z*z;}
40  float Mag() const {return sqrt(Mag2());}
41  float Dot(const SRVector3D& v) const {return x*v.x + y*v.y + z*v.z;}
42  SRVector3D Unit() const
43  {
44  const float m = Mag();
45  return SRVector3D(x/m, y/m, z/m);
46  }
47 
48  float x;
49  float y;
50  float z;
51  };
52 
53 } // end namespace
54 
55 #endif // SRVECTOR3D_H
56 //////////////////////////////////////////////////////////////////////////////
A 3-vector with more efficient storage than TVector3.
Definition: SRVector3D.h:14
void SetXYZ(float x, float y, float z)
Definition: SRVector3D.cxx:31
void SetX(float _x)
Definition: SRVector3D.h:28
float Mag2() const
Definition: SRVector3D.h:39
T sqrt(T number)
Definition: d0nt_math.hpp:156
float Y() const
Definition: SRVector3D.h:33
void SetZ(float _z)
Definition: SRVector3D.h:30
float X() const
Definition: SRVector3D.h:32
SRVector3D Unit() const
Definition: SRVector3D.h:42
virtual ~SRVector3D()
Definition: SRVector3D.cxx:27
float Z() const
Definition: SRVector3D.h:34
float Dot(const SRVector3D &v) const
Definition: SRVector3D.h:41
This module creates Common Analysis Files.
Definition: FileReducer.h:10
float Mag() const
Definition: SRVector3D.h:40
void SetY(float _y)
Definition: SRVector3D.h:29