ROOT logo
// @(#)root/eve:$Id: TEveVector.h 31517 2009-12-03 11:56:23Z matevz $
// Author: Matevz Tadel 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TEveVector
#define ROOT_TEveVector

#include "TMath.h"

class TVector3;

//==============================================================================
// TEveVector
//==============================================================================

class TEveVector
{
public:
   Float_t fX, fY, fZ; // Components of the vector.

   TEveVector() : fX(0), fY(0), fZ(0) {}
   TEveVector(const Float_t* v)  : fX(v[0]), fY(v[1]), fZ(v[2]) {}
   TEveVector(const Double_t* v) : fX(v[0]), fY(v[1]), fZ(v[2]) {}
   TEveVector(Float_t x, Float_t y, Float_t z) : fX(x), fY(y), fZ(z) {}
   virtual ~TEveVector() {}

   void Dump() const;

   operator const Float_t*() const { return &fX; }
   operator       Float_t*()       { return &fX; }

   TEveVector& operator *=(Float_t s)           { fX *= s;    fY *= s;    fZ *= s;    return *this; }
   TEveVector& operator +=(const TEveVector& v) { fX += v.fX; fY += v.fY; fZ += v.fZ; return *this; }
   TEveVector& operator -=(const TEveVector& v) { fX -= v.fX; fY -= v.fY; fZ -= v.fZ; return *this; }

   TEveVector operator + (const TEveVector &) const;
   TEveVector operator - (const TEveVector &) const;
   TEveVector operator * (Float_t a) const;

   Float_t& operator [] (Int_t indx);
   Float_t  operator [] (Int_t indx) const;

   const Float_t* Arr() const { return &fX; }
   Float_t* Arr()       { return &fX; }

   void Set(const Float_t*  v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
   void Set(const Double_t* v) { fX = v[0]; fY = v[1]; fZ = v[2]; }
   void Set(Float_t  x, Float_t  y, Float_t  z) { fX = x; fY = y; fZ = z; }
   void Set(Double_t x, Double_t y, Double_t z) { fX = x; fY = y; fZ = z; }
   void Set(const TEveVector& v) { fX = v.fX;  fY = v.fY;  fZ = v.fZ;  }
   void Set(const TVector3& v);

   void NegateXYZ() { fX = - fX; fY = -fY; fZ = -fZ; }
   void Normalize(Float_t length=1);

   Float_t Phi()      const;
   Float_t Theta()    const;
   Float_t CosTheta() const;
   Float_t Eta()      const;

   Float_t Mag()  const { return TMath::Sqrt(fX*fX + fY*fY + fZ*fZ);}
   Float_t Mag2() const { return fX*fX + fY*fY + fZ*fZ;}

   Float_t Perp()  const { return TMath::Sqrt(fX*fX + fY*fY);}
   Float_t Perp2() const { return fX*fX + fY*fY;}
   Float_t R()     const { return Perp(); }

   Float_t Distance(const TEveVector& v) const;
   Float_t SquareDistance(const TEveVector& v) const;

   Float_t    Dot(const TEveVector& a) const;
   TEveVector Cross(const TEveVector& a) const;

   TEveVector& Sub(const TEveVector& p, const TEveVector& q);

   TEveVector& Mult(const TEveVector& a, Float_t af);

   TEveVector Orthogonal() const;
   void       OrthoNormBase(TEveVector& a, TEveVector& b) const;

   ClassDef(TEveVector, 1); // Float three-vector; a minimal Float_t copy of TVector3 used to represent points and momenta (also used in VSD).
};

//______________________________________________________________________________
inline Float_t TEveVector::Phi() const
{
   return fX == 0.0 && fY == 0.0 ? 0.0 : TMath::ATan2(fY, fX);
}

//______________________________________________________________________________
inline Float_t TEveVector::Theta() const
{
   return fX == 0.0 && fY == 0.0 && fZ == 0.0 ? 0.0 : TMath::ATan2(Perp(), fZ);
}

//______________________________________________________________________________
inline Float_t TEveVector::CosTheta() const
{
   Float_t ptot = Mag(); return ptot == 0.0 ? 1.0 : fZ/ptot;
}

//______________________________________________________________________________
inline Float_t TEveVector::Distance( const TEveVector& b) const
{
   return TMath::Sqrt((fX - b.fX)*(fX - b.fX) +
                      (fY - b.fY)*(fY - b.fY) +
                      (fZ - b.fZ)*(fZ - b.fZ));
}

//______________________________________________________________________________
inline Float_t TEveVector::SquareDistance(const TEveVector& b) const
{
   return ((fX - b.fX) * (fX - b.fX) +
           (fY - b.fY) * (fY - b.fY) +
           (fZ - b.fZ) * (fZ - b.fZ));
}

//______________________________________________________________________________
inline Float_t TEveVector::Dot(const TEveVector& a) const
{
   return a.fX*fX + a.fY*fY + a.fZ*fZ;
}

//______________________________________________________________________________
inline TEveVector TEveVector::Cross(const TEveVector& a) const
{
   TEveVector r;
   r.fX = fY * a.fZ - fZ * a.fY;
   r.fY = fZ * a.fX - fX * a.fZ;
   r.fZ = fX * a.fY - fY * a.fX;
   return r;
}

//______________________________________________________________________________
inline TEveVector& TEveVector::Sub(const TEveVector& p, const TEveVector& q)
{
   fX = p.fX - q.fX;
   fY = p.fY - q.fY;
   fZ = p.fZ - q.fZ;
   return *this;
}

//______________________________________________________________________________
inline TEveVector& TEveVector::Mult(const TEveVector& a, Float_t af)
{
   fX = a.fX * af;
   fY = a.fY * af;
   fZ = a.fZ * af;
   return *this;
}

//______________________________________________________________________________
inline Float_t& TEveVector::operator [] (Int_t idx)
{
   return (&fX)[idx];
}

//______________________________________________________________________________
inline Float_t TEveVector::operator [] (Int_t idx) const
{
   return (&fX)[idx];
}


//==============================================================================
// TEveVector4
//==============================================================================

class TEveVector4 : public TEveVector
{
public:
   Float_t fT;

   TEveVector4()                    : TEveVector(),  fT(0) {}
   TEveVector4(const TEveVector& v) : TEveVector(v), fT(0) {}
   TEveVector4(Float_t x, Float_t y, Float_t z, Float_t t=0) :
      TEveVector(x, y, z), fT(t) {}
   virtual ~TEveVector4() {}

   void Dump() const;

   TEveVector4 operator + (const TEveVector4 & b) const
   { return TEveVector4(fX + b.fX, fY + b.fY, fZ + b.fZ, fT + b.fT); }

   TEveVector4 operator - (const TEveVector4 & b) const
   { return TEveVector4(fX - b.fX, fY - b.fY, fZ - b.fZ, fT - b.fT); }

   TEveVector4 operator * (Float_t a) const
   { return TEveVector4(a*fX, a*fY, a*fZ, a*fT); }

   TEveVector4& operator += (const TEveVector4 & b)
   { fX += b.fX; fY += b.fY; fZ += b.fZ; fT += b.fT; return *this; }

   ClassDef(TEveVector4, 1); // Float four-vector.
};


//==============================================================================
// TEvePathMark
//==============================================================================

class TEvePathMark
{
public:
   enum EType_e   { kReference, kDaughter, kDecay, kCluster2D };

   EType_e     fType; // Mark-type.
   TEveVector  fV;    // Vertex.
   TEveVector  fP;    // Momentum.
   TEveVector  fE;    // Extra, meaning depends on fType.
   Float_t     fTime; // Time.

   TEvePathMark(EType_e type=kReference) :
      fType(type), fV(), fP(), fE(), fTime(0) {}

   TEvePathMark(EType_e type, const TEveVector& v, Float_t time=0) :
      fType(type), fV(v), fP(), fE(), fTime(time) {}

   TEvePathMark(EType_e type, const TEveVector& v, const TEveVector& p, Float_t time=0) :
      fType(type), fV(v), fP(p), fE(), fTime(time) {}

   TEvePathMark(EType_e type, const TEveVector& v, const TEveVector& p, const TEveVector& e, Float_t time=0) :
      fType(type), fV(v), fP(p), fE(e), fTime(time) {}

   virtual ~TEvePathMark() {}

   const char* TypeName();

   ClassDef(TEvePathMark, 1); // Special-point on track: position/momentum reference, daughter creation or decay (also used in VSD).
};

#endif
 TEveVector.h:1
 TEveVector.h:2
 TEveVector.h:3
 TEveVector.h:4
 TEveVector.h:5
 TEveVector.h:6
 TEveVector.h:7
 TEveVector.h:8
 TEveVector.h:9
 TEveVector.h:10
 TEveVector.h:11
 TEveVector.h:12
 TEveVector.h:13
 TEveVector.h:14
 TEveVector.h:15
 TEveVector.h:16
 TEveVector.h:17
 TEveVector.h:18
 TEveVector.h:19
 TEveVector.h:20
 TEveVector.h:21
 TEveVector.h:22
 TEveVector.h:23
 TEveVector.h:24
 TEveVector.h:25
 TEveVector.h:26
 TEveVector.h:27
 TEveVector.h:28
 TEveVector.h:29
 TEveVector.h:30
 TEveVector.h:31
 TEveVector.h:32
 TEveVector.h:33
 TEveVector.h:34
 TEveVector.h:35
 TEveVector.h:36
 TEveVector.h:37
 TEveVector.h:38
 TEveVector.h:39
 TEveVector.h:40
 TEveVector.h:41
 TEveVector.h:42
 TEveVector.h:43
 TEveVector.h:44
 TEveVector.h:45
 TEveVector.h:46
 TEveVector.h:47
 TEveVector.h:48
 TEveVector.h:49
 TEveVector.h:50
 TEveVector.h:51
 TEveVector.h:52
 TEveVector.h:53
 TEveVector.h:54
 TEveVector.h:55
 TEveVector.h:56
 TEveVector.h:57
 TEveVector.h:58
 TEveVector.h:59
 TEveVector.h:60
 TEveVector.h:61
 TEveVector.h:62
 TEveVector.h:63
 TEveVector.h:64
 TEveVector.h:65
 TEveVector.h:66
 TEveVector.h:67
 TEveVector.h:68
 TEveVector.h:69
 TEveVector.h:70
 TEveVector.h:71
 TEveVector.h:72
 TEveVector.h:73
 TEveVector.h:74
 TEveVector.h:75
 TEveVector.h:76
 TEveVector.h:77
 TEveVector.h:78
 TEveVector.h:79
 TEveVector.h:80
 TEveVector.h:81
 TEveVector.h:82
 TEveVector.h:83
 TEveVector.h:84
 TEveVector.h:85
 TEveVector.h:86
 TEveVector.h:87
 TEveVector.h:88
 TEveVector.h:89
 TEveVector.h:90
 TEveVector.h:91
 TEveVector.h:92
 TEveVector.h:93
 TEveVector.h:94
 TEveVector.h:95
 TEveVector.h:96
 TEveVector.h:97
 TEveVector.h:98
 TEveVector.h:99
 TEveVector.h:100
 TEveVector.h:101
 TEveVector.h:102
 TEveVector.h:103
 TEveVector.h:104
 TEveVector.h:105
 TEveVector.h:106
 TEveVector.h:107
 TEveVector.h:108
 TEveVector.h:109
 TEveVector.h:110
 TEveVector.h:111
 TEveVector.h:112
 TEveVector.h:113
 TEveVector.h:114
 TEveVector.h:115
 TEveVector.h:116
 TEveVector.h:117
 TEveVector.h:118
 TEveVector.h:119
 TEveVector.h:120
 TEveVector.h:121
 TEveVector.h:122
 TEveVector.h:123
 TEveVector.h:124
 TEveVector.h:125
 TEveVector.h:126
 TEveVector.h:127
 TEveVector.h:128
 TEveVector.h:129
 TEveVector.h:130
 TEveVector.h:131
 TEveVector.h:132
 TEveVector.h:133
 TEveVector.h:134
 TEveVector.h:135
 TEveVector.h:136
 TEveVector.h:137
 TEveVector.h:138
 TEveVector.h:139
 TEveVector.h:140
 TEveVector.h:141
 TEveVector.h:142
 TEveVector.h:143
 TEveVector.h:144
 TEveVector.h:145
 TEveVector.h:146
 TEveVector.h:147
 TEveVector.h:148
 TEveVector.h:149
 TEveVector.h:150
 TEveVector.h:151
 TEveVector.h:152
 TEveVector.h:153
 TEveVector.h:154
 TEveVector.h:155
 TEveVector.h:156
 TEveVector.h:157
 TEveVector.h:158
 TEveVector.h:159
 TEveVector.h:160
 TEveVector.h:161
 TEveVector.h:162
 TEveVector.h:163
 TEveVector.h:164
 TEveVector.h:165
 TEveVector.h:166
 TEveVector.h:167
 TEveVector.h:168
 TEveVector.h:169
 TEveVector.h:170
 TEveVector.h:171
 TEveVector.h:172
 TEveVector.h:173
 TEveVector.h:174
 TEveVector.h:175
 TEveVector.h:176
 TEveVector.h:177
 TEveVector.h:178
 TEveVector.h:179
 TEveVector.h:180
 TEveVector.h:181
 TEveVector.h:182
 TEveVector.h:183
 TEveVector.h:184
 TEveVector.h:185
 TEveVector.h:186
 TEveVector.h:187
 TEveVector.h:188
 TEveVector.h:189
 TEveVector.h:190
 TEveVector.h:191
 TEveVector.h:192
 TEveVector.h:193
 TEveVector.h:194
 TEveVector.h:195
 TEveVector.h:196
 TEveVector.h:197
 TEveVector.h:198
 TEveVector.h:199
 TEveVector.h:200
 TEveVector.h:201
 TEveVector.h:202
 TEveVector.h:203
 TEveVector.h:204
 TEveVector.h:205
 TEveVector.h:206
 TEveVector.h:207
 TEveVector.h:208
 TEveVector.h:209
 TEveVector.h:210
 TEveVector.h:211
 TEveVector.h:212
 TEveVector.h:213
 TEveVector.h:214
 TEveVector.h:215
 TEveVector.h:216
 TEveVector.h:217
 TEveVector.h:218
 TEveVector.h:219
 TEveVector.h:220
 TEveVector.h:221
 TEveVector.h:222
 TEveVector.h:223
 TEveVector.h:224
 TEveVector.h:225
 TEveVector.h:226
 TEveVector.h:227
 TEveVector.h:228
 TEveVector.h:229
 TEveVector.h:230
 TEveVector.h:231
 TEveVector.h:232
 TEveVector.h:233
 TEveVector.h:234
 TEveVector.h:235
 TEveVector.h:236
 TEveVector.h:237
 TEveVector.h:238
 TEveVector.h:239