Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Public Member Functions | Public Attributes | List of all members
Vec Struct Reference

The Vec class is a straightforward 3-d vector, which also works in pyroot. More...

#include <Vec.hh>

Inheritance diagram for Vec:
JAANET::coord_origin dir_type pos_type

Public Member Functions

 Vec (double x_, double y_, double z_)
 Constructor. More...
 
 Vec ()
 Default constructor. More...
 
double dot (const Vec &v) const
 Get dot product. More...
 
Vec cross (const Vec r) const
 Get cross product. More...
 
Vecoperator+= (const Vec &v)
 Add vector. More...
 
Vecoperator-= (const Vec &v)
 Subtract vector. More...
 
Vecoperator*= (double d)
 Multiply vector. More...
 
Vecoperator/= (double d)
 Divide vector. More...
 
Vec operator- () const
 Negate vector. More...
 
bool operator== (const Vec &v) const
 Check equality with given vector. More...
 
bool operator!= (const Vec &v) const
 Check in-equality with given vector. More...
 
Vecset (double xx, double yy, double zz)
 Set vector. More...
 
Vecset_angles (double theta, double phi)
 Set vector according given zenith and azimuth angles. More...
 
double phi () const
 Get azimuth angle. More...
 
double theta () const
 Get zenith angle. More...
 
double len () const
 Get length. More...
 
double lenxy () const
 Get length of (x,y) component. More...
 
Vecnormalize ()
 Normalise this vector. More...
 
void print (std::ostream &out=std::cout) const
 Print vector. More...
 
const char * __repr__ () const
 Get string representation of this vector. More...
 
Vec __add__ (const Vec &v) const
 Add vector. More...
 
Vec __sub__ (const Vec &v) const
 Subtract vector. More...
 
Vec __mul__ (double d) const
 Multiply vector. More...
 
Vec __rmul__ (double d) const
 Multiply vector. More...
 
Vec __div__ (double d) const
 Divide vector. More...
 
Vecrotate_z (double ang)
 Rotate around z-axis with given angle. More...
 
Vecrotate_x (double ang)
 Rotate around x-axis with given angle. More...
 
Vecrotate_y (double ang)
 Rotate around y-axis with given angle. More...
 

Public Attributes

double x
 
double y
 
double z
 

Detailed Description

The Vec class is a straightforward 3-d vector, which also works in pyroot.

Definition at line 12 of file Vec.hh.

Constructor & Destructor Documentation

◆ Vec() [1/2]

Vec::Vec ( double  x_,
double  y_,
double  z_ 
)
inline

Constructor.

Parameters
x_x position
y_y position
z_z position

Definition at line 23 of file Vec.hh.

23 : x(x_), y(y_), z(z_) {}
double z
Definition: Vec.hh:14
double x
Definition: Vec.hh:14
double y
Definition: Vec.hh:14

◆ Vec() [2/2]

Vec::Vec ( )
inline

Default constructor.

Definition at line 28 of file Vec.hh.

28 :x(0),y(0),z(0) {}

Member Function Documentation

◆ dot()

double Vec::dot ( const Vec v) const
inline

Get dot product.

Parameters
vvector
Returns
dot product

Definition at line 36 of file Vec.hh.

36 { return v.x*x + v.y*y+ v.z*z;}
data_type v[N+1][M+1]
Definition: JPolint.hh:866

◆ cross()

Vec Vec::cross ( const Vec  r) const
inline

Get cross product.

Parameters
rvector
Returns
cross product

Definition at line 44 of file Vec.hh.

44 { return Vec ( y*r.z-z*r.y, z*r.x-x*r.z, x*r.y-y*r.x);}
data_type r[M+1]
Definition: JPolint.hh:868
Vec()
Default constructor.
Definition: Vec.hh:28

◆ operator+=()

Vec& Vec::operator+= ( const Vec v)
inline

Add vector.

Parameters
vvector
Returns
this vector

Definition at line 52 of file Vec.hh.

52 { x+=v.x; y+=v.y; z+=v.z; return *this;}

◆ operator-=()

Vec& Vec::operator-= ( const Vec v)
inline

Subtract vector.

Parameters
vvector
Returns
this vector

Definition at line 60 of file Vec.hh.

60 { x-=v.x; y-=v.y; z-=v.z; return *this;}

◆ operator*=()

Vec& Vec::operator*= ( double  d)
inline

Multiply vector.

Parameters
dfactor
Returns
this vector

Definition at line 68 of file Vec.hh.

68 { x*=d; y*=d; z*=d; return *this;}

◆ operator/=()

Vec& Vec::operator/= ( double  d)
inline

Divide vector.

Parameters
dfactor
Returns
this vector

Definition at line 76 of file Vec.hh.

76 { return operator*=( 1.0 / d ); }
Vec & operator*=(double d)
Multiply vector.
Definition: Vec.hh:68

◆ operator-()

Vec Vec::operator- ( ) const
inline

Negate vector.

Returns
vector

Definition at line 83 of file Vec.hh.

83 { return Vec(-x,-y,-z); }

◆ operator==()

bool Vec::operator== ( const Vec v) const
inline

Check equality with given vector.

Parameters
vvector
Returns
true if (x,y,z) positions of two vectors are equal; else false

Definition at line 91 of file Vec.hh.

91 { return x==v.x && y==v.y && z==v.z ; }

◆ operator!=()

bool Vec::operator!= ( const Vec v) const
inline

Check in-equality with given vector.

Parameters
vvector
Returns
true if one of (x,y,z) positions of two vectors are not equal; else false

Definition at line 99 of file Vec.hh.

99 { return x!=v.x || y!=v.y || z!=v.z ; }

◆ set()

Vec& Vec::set ( double  xx,
double  yy,
double  zz 
)
inline

Set vector.

Parameters
xxx position
yyy position
zzz position
Returns
this vector

Definition at line 109 of file Vec.hh.

109 { x=xx; y=yy; z=zz; return *this;}

◆ set_angles()

Vec& Vec::set_angles ( double  theta,
double  phi 
)
inline

Set vector according given zenith and azimuth angles.

Parameters
thetazenith angle [rad]
phiazimuth angle [rad]
Returns
this vector

Definition at line 118 of file Vec.hh.

119  {
120  x = sin ( theta ) * cos( phi );
121  y = sin ( theta ) * sin( phi );
122  z = cos ( theta );
123  return *this;
124  }
double theta() const
Get zenith angle.
Definition: Vec.hh:138
double phi() const
Get azimuth angle.
Definition: Vec.hh:131

◆ phi()

double Vec::phi ( ) const
inline

Get azimuth angle.

Returns
angle [rad]

Definition at line 131 of file Vec.hh.

131 { return atan2( y,x ); }

◆ theta()

double Vec::theta ( ) const
inline

Get zenith angle.

Returns
angle [rad]

Definition at line 138 of file Vec.hh.

138 { return acos(z); }

◆ len()

double Vec::len ( ) const
inline

Get length.

Returns
length

Definition at line 145 of file Vec.hh.

145 { double l = dot(*this); return (l > 0)? sqrt(l) : 0; }
double dot(const Vec &v) const
Get dot product.
Definition: Vec.hh:36

◆ lenxy()

double Vec::lenxy ( ) const
inline

Get length of (x,y) component.

Returns
length

Definition at line 152 of file Vec.hh.

152 { const double r2 = x*x + y*y; return (r2>0) ? sqrt(r2) :0; }

◆ normalize()

Vec& Vec::normalize ( )
inline

Normalise this vector.

Returns
this vector

Definition at line 159 of file Vec.hh.

159 { return operator/=( len() ); }
double len() const
Get length.
Definition: Vec.hh:145
Vec & operator/=(double d)
Divide vector.
Definition: Vec.hh:76

◆ print()

void Vec::print ( std::ostream &  out = std::cout) const
inline

Print vector.

Parameters
outoutput stream

Definition at line 166 of file Vec.hh.

167  {
168  out << "Vec:" << x << " " << y << " " << z;
169  }

◆ __repr__()

const char* Vec::__repr__ ( ) const
inline

Get string representation of this vector.

Returns
string

Definition at line 176 of file Vec.hh.

177  {
178  static std::string buffer;
179 
180  std::ostringstream s;
181 
182  print(s);
183 
184  buffer = s.str();
185 
186  return buffer.c_str();
187  }
void print(std::ostream &out=std::cout) const
Print vector.
Definition: Vec.hh:166

◆ __add__()

Vec Vec::__add__ ( const Vec v) const
inline

Add vector.

Parameters
vvector
Returns
vector

Definition at line 195 of file Vec.hh.

195 { Vec r=*this; return r+=v; }
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:13

◆ __sub__()

Vec Vec::__sub__ ( const Vec v) const
inline

Subtract vector.

Parameters
vvector
Returns
vector

Definition at line 203 of file Vec.hh.

203 { Vec r=*this; return r-=v; }

◆ __mul__()

Vec Vec::__mul__ ( double  d) const
inline

Multiply vector.

Parameters
dfactor
Returns
vector

Definition at line 211 of file Vec.hh.

211 { Vec r=*this; return r*=d; }

◆ __rmul__()

Vec Vec::__rmul__ ( double  d) const
inline

Multiply vector.

Parameters
dfactor
Returns
vector

Definition at line 219 of file Vec.hh.

219 { return __mul__(d); }
Vec __mul__(double d) const
Multiply vector.
Definition: Vec.hh:211

◆ __div__()

Vec Vec::__div__ ( double  d) const
inline

Divide vector.

Parameters
dfactor
Returns
vector

Definition at line 227 of file Vec.hh.

227 { Vec r=*this; return r/=d; }

◆ rotate_z()

Vec& Vec::rotate_z ( double  ang)
inline

Rotate around z-axis with given angle.

Parameters
angangle [rad]
Returns
this vector

Definition at line 235 of file Vec.hh.

236  {
237  const Vec o = *this;
238  x = o.x *cos(ang) - o.y * sin(ang);
239  y = o.x *sin(ang) + o.y * cos(ang);
240  z = o.z;
241  return *this;
242  }

◆ rotate_x()

Vec& Vec::rotate_x ( double  ang)
inline

Rotate around x-axis with given angle.

Parameters
angangle [rad]
Returns
this vector

Definition at line 250 of file Vec.hh.

251  {
252  const Vec o = *this;
253  x = o.x;
254  y = o.y *cos(ang) + o.z * -sin(ang);
255  z = o.y *sin(ang) + o.z * cos(ang);
256  return *this;
257  }

◆ rotate_y()

Vec& Vec::rotate_y ( double  ang)
inline

Rotate around y-axis with given angle.

Parameters
angangle [rad]
Returns
this vector

Definition at line 265 of file Vec.hh.

266  {
267  const Vec o = *this;
268  x = o.x *cos(ang) + o.z * sin(ang);
269  y = o.y;
270  z = -o.x *sin(ang) + o.z * cos(ang);
271  return *this;
272  }

Member Data Documentation

◆ x

double Vec::x

Definition at line 14 of file Vec.hh.

◆ y

double Vec::y

Definition at line 14 of file Vec.hh.

◆ z

double Vec::z

Definition at line 14 of file Vec.hh.


The documentation for this struct was generated from the following file: