Import Geant4 9.5.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 16:46:55 +02:00
parent 89a9605df1
commit b1eb5424d2
10957 changed files with 888481 additions and 160139 deletions
@@ -0,0 +1,264 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
#ifndef HEP_EVALUATOR_H
#define HEP_EVALUATOR_H
#include <string>
namespace HepTool {
/**
* Evaluator of arithmetic expressions with an extendable dictionary.
* Example:
* @code
* #include "CLHEP/Evaluator/Evaluator.h"
* HepTool::Evaluator eval;
* eval.setStdMath();
* double res = eval.evaluate("sin(30*degree)");
* if (eval.status() != HepTool::Evaluator::OK) eval.print_error();
* @endcode
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup evaluator
*/
class Evaluator {
public:
/**
* List of possible statuses.
* Status of the last operation can be obtained with status().
* In case if status() is an ERROR the corresponding error message
* can be printed with print_error().
*
* @see status
* @see error_position
* @see print_error
*/
enum {
OK, /**< Everything OK */
WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */
WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */
WARNING_BLANK_STRING, /**< Empty input string */
ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */
ERROR_SYNTAX_ERROR, /**< Systax error */
ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */
ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */
ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */
ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */
ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */
ERROR_CALCULATION_ERROR /**< Error during calculation */
};
/**
* Constructor.
*/
Evaluator();
/**
* Destructor.
*/
~Evaluator();
/**
* Evaluates the arithmetic expression given as character string.
* The expression may consist of numbers, variables and functions
* separated by arithmetic (+, - , /, *, ^, **) and logical
* operators (==, !=, >, >=, <, <=, &&, ||).
*
* @param expression input expression.
* @return result of the evaluation.
* @see status
* @see error_position
* @see print_error
*/
double evaluate(const char * expression);
/**
* Returns status of the last operation with the evaluator.
*/
int status() const;
/**
* Returns position in the input string where the problem occured.
*/
int error_position() const;
/**
* Prints error message if status() is an ERROR.
*/
void print_error() const;
/**
* get a string defining the error name
*/
std::string error_name() const;
/**
* Adds to the dictionary a variable with given value.
* If a variable with such a name already exist in the dictionary,
* then status will be set to WARNING_EXISTING_VARIABLE.
*
* @param name name of the variable.
* @param value value assigned to the variable.
*/
void setVariable(const char * name, double value);
/**
* Adds to the dictionary a variable with an arithmetic expression
* assigned to it.
* If a variable with such a name already exist in the dictionary,
* then status will be set to WARNING_EXISTING_VARIABLE.
*
* @param name name of the variable.
* @param expression arithmetic expression.
*/
void setVariable(const char * name, const char * expression);
/**
* Adds to the dictionary a function without parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)());
/**
* Adds to the dictionary a function with one parameter.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double));
/**
* Adds to the dictionary a function with two parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double,double));
/**
* Adds to the dictionary a function with three parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name, double (*fun)(double,double,double));
/**
* Adds to the dictionary a function with four parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name,
double (*fun)(double,double,double,double));
/**
* Adds to the dictionary a function with five parameters.
* If such a function already exist in the dictionary,
* then status will be set to WARNING_EXISTING_FUNCTION.
*
* @param name function name.
* @param fun pointer to the real function in the user code.
*/
void setFunction(const char * name,
double (*fun)(double,double,double,double,double));
/**
* Finds the variable in the dictionary.
*
* @param name name of the variable.
* @return true if such a variable exists, false otherwise.
*/
bool findVariable(const char * name) const;
/**
* Finds the function in the dictionary.
*
* @param name name of the function to be unset.
* @param npar number of parameters of the function.
* @return true if such a function exists, false otherwise.
*/
bool findFunction(const char * name, int npar) const;
/**
* Removes the variable from the dictionary.
*
* @param name name of the variable.
*/
void removeVariable(const char * name);
/**
* Removes the function from the dictionary.
*
* @param name name of the function to be unset.
* @param npar number of parameters of the function.
*/
void removeFunction(const char * name, int npar);
/**
* Clear all settings.
*/
void clear();
/**
* Sets standard mathematical functions and constants.
*/
void setStdMath();
/**
* Sets system of units. Default is the SI system of units.
* To set the CGS (Centimeter-Gram-Second) system of units
* one should call:
* setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);
*
* To set system of units accepted in the GEANT4 simulation toolkit
* one should call:
* @code
* setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10,
* 1.0, 1.0, 1.0);
* @endcode
*
* The basic units in GEANT4 are:
* @code
* millimeter (millimeter = 1.)
* nanosecond (nanosecond = 1.)
* Mega electron Volt (MeV = 1.)
* positron charge (eplus = 1.)
* degree Kelvin (kelvin = 1.)
* the amount of substance (mole = 1.)
* luminous intensity (candela = 1.)
* radian (radian = 1.)
* steradian (steradian = 1.)
* @endcode
*/
void setSystemOfUnits(double meter = 1.0,
double kilogram = 1.0,
double second = 1.0,
double ampere = 1.0,
double kelvin = 1.0,
double mole = 1.0,
double candela = 1.0);
private:
void * p; // private data
Evaluator(const Evaluator &); // copy constructor is not allowed
Evaluator & operator=(const Evaluator &); // assignment is not allowed
};
} // namespace HepTool
#endif /* HEP_EVALUATOR_H */
@@ -0,0 +1,186 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
#ifndef HEP_HASH_MAP_SRC
#define HEP_HASH_MAP_SRC
#include <string.h>
#include <utility>
#include "CLHEP/Evaluator/string.icc"
/*
* Simplified hash_map class.
* It provides only basic functions of the standard <hash_map> and
* is intended to be used as a replacement of the standard class where
* full functionality of <hash_map> is not required, but it is essential
* to have highly portable and effective code.
*
* This file should be used exclusively inside *.cc files.
* Usage inside header files can result to a clash with standard <hash_map>.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class K, class T>
class hash_map {
public:
struct Entry { // Hash_map entry
std::pair<const K,T> data;
Entry* next;
Entry(K k, T v, Entry* n) : data(k,v), next(n) {}
};
class hash_map_iterator { // Hash_map iterator
Entry* entry;
public:
hash_map_iterator() : entry(0) {}
hash_map_iterator(Entry & e) : entry(&e) {}
std::pair<const K,T> & operator * () const { return entry->data; }
std::pair<const K,T> * operator ->() const { return &(operator*()); }
bool operator==(hash_map_iterator i) const {
return (entry == i.entry);
}
bool operator!=(hash_map_iterator i) const {
return (entry != i.entry);
}
};
public:
typedef unsigned int size_type;
typedef std::pair<const K,T> value_type;
typedef hash_map_iterator iterator;
typedef hash_map_iterator const_iterator;
private:
Entry** table; // Hash table: pointers to entries
size_type cur_size; // Number of entries
size_type max_size; // Bucket_count - current size of the table
float max_load; // Keep (n) <= (max_size * max_load)
float grow; // When necessary, resize(max_size * grow)
const T default_value; // Default value used by []
size_type hash(const char * key) const {
size_type res = 0;
while(*key) { res = res*31 + *key++; }
return res;
}
size_type hash(const string & key) const {
return hash(key.c_str());
}
bool eq(const char * a, const char * b) const {
return (strcmp(a, b) == 0);
}
bool eq(const string & a, const string & b) const {
return (a == b);
}
public:
// Constructor.
hash_map(const T & dv = T(), size_type n = 107)
: table(0), cur_size(0), max_size(0), default_value(dv)
{
set_load();
resize(n);
}
// Destructor.
~hash_map() {
for(size_type i=0; i<max_size; i++) {
Entry* n = table[i];
while(n) { Entry* p = n; n = p->next; delete p; }
}
delete [] table;
}
// Sets load and grow parameters.
void set_load(float m = 0.7, float g = 1.7) { max_load = m; grow = g; }
// Returns number of elements.
size_type size() const { return cur_size; }
// Returns size of the hash table.
size_type bucket_count() const { return max_size; }
// Resizes the hash table.
void resize(size_type s) {
if (s <= max_size) return;
Entry** tmp = table;
table = new Entry* [s];
for (size_type k=0; k<s; k++) table[k] = 0;
for (size_type i=0; i<max_size; i++) {
Entry* n = tmp[i];
while(n) {
Entry* p = n;
n = p->next;
size_type ii = hash(p->data.first) % s;
p->next = table[ii];
table[ii] = p;
}
}
max_size = s;
delete [] tmp;
}
// Subscripting.
T & operator[](const K & key) {
size_type i = hash(key) % max_size;
for (Entry* p=table[hash(key) % max_size]; p; p=p->next) {
if (eq(key,p->data.first)) return p->data.second;
}
if (cur_size++ >= max_size*max_load) {
resize(size_type(max_size*grow));
i = hash(key) % max_size;
}
table[i] = new Entry(key, default_value, table[i]);
return table[i]->data.second;
}
// Finds element with given key.
iterator find(const K & key) const {
size_type i = hash(key) % max_size;
for (Entry* p=table[i]; p; p=p->next) {
if (eq(key,p->data.first)) return iterator(*p);
}
return end();
}
// Erases element with given key.
size_type erase(const K & key) {
size_type i = hash(key) % max_size;
Entry* p = table[i];
if (p == 0) return 0;
if (eq(key,p->data.first)) {
table[i] = p->next; delete p; cur_size--; return 1;
}
Entry** pp = &table[i];
for (p=p->next; p; p=p->next) {
if (eq(key,p->data.first)) {
*pp = p->next; delete p; cur_size--; return 1;
}else{
pp = &(p->next);
}
}
return 0;
}
// Clears the hash table.
void clear() {
for(size_type i=0; i<max_size; i++) {
for (Entry* p=table[i]; p;) {
Entry* pp = p; p = p->next; delete pp;
}
table[i] = 0;
}
cur_size = 0;
}
// Returns end iterator.
iterator end() const { return iterator(); }
};
#endif /* HEP_HASH_MAP_SRC */
@@ -0,0 +1,45 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
#ifndef HEP_STACK_SRC
#define HEP_STACK_SRC
/*
* Simplified stack class.
* It is intended to be used as a replacement of the standard class where
* full functionality of <stack> is not required, but it is essential
* to have highly portable and effective code.
*
* This file should be used exclusively inside *.cc files.
* Usage inside header files can result to a clash with standard <stack>.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class stack {
private:
int k, max_size;
T * v;
public:
stack() : k(0), max_size(20), v(new T[20]) {}
~stack() { delete [] v; }
int size() const { return k; }
T top () const { return v[k-1]; }
T & top () { return v[k-1]; }
void pop () { k--; }
void push(T a) {
if (k == max_size) {
T * w = v;
max_size *= 2;
v = new T[max_size];
for (int i=0; i<k; i++) v[i] = w[i];
delete [] w;
}
v[k++] = a;
}
};
#endif /* HEP_STACK_SRC */
@@ -0,0 +1,125 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
#ifndef HEP_STRING_SRC
#define HEP_STRING_SRC
#include <iostream>
#include <string.h>
/*
* Simplified string class.
* It provides only few basic functions of the standard <string> and
* is intended to be used as a replacement of the standard class where
* full functionality of <string> is not required, but it is essential
* to have highly portable and effective code.
*
* This file should be used exclusively inside *.cc files.
* Usage inside header files can result to a clash with standard <string>.
*/
struct string {
struct srep {
char* s; // pointer to data
int n; // reference count
srep() : n(1) {}
} *p;
// Default constructor.
string() { p = new srep; p->s = 0; }
// Constructor from character string.
string(const char* s) {
p = new srep; p->s = new char[strlen(s)+1]; strcpy(p->s, s);
}
// Constructor from character substring.
string(const char* s, unsigned int n) {
p = new srep; p->s = new char[n+1]; strncpy(p->s, s, n); *(p->s+n) = '\0';
}
// Copy constructor from string.
string(const string& x) { x.p->n++; p = x.p; }
// Destructor.
~string() { if (--p->n == 0) { delete [] p->s; delete p; } }
// Assignment from character string.
string& operator=(const char* s) {
if (p->n > 1) { // disconnect self
p->n--;
p = new srep;
}else{
delete [] p->s; // free old string
}
p->s = new char[strlen(s)+1];
strcpy(p->s, s);
return *this;
}
// Assignment from string.
string& operator=(const string & x) {
x.p->n++; // protect against "st = st"
if (--p->n == 0) { delete [] p->s; delete p; }
p = x.p;
return *this;
}
// Returns C-style character string.
const char* c_str() const { return p->s; }
};
//
// Concatinations.
//
inline string operator+(char a, const string & b) {
string s; s.p->s = new char[strlen(b.c_str())+2];
s.p->s[0] = a; strcpy(s.p->s+1, b.c_str());
return s;
}
inline string operator+(const char * a, const string & b) {
int lena = strlen(a);
string s; s.p->s = new char[lena+strlen(b.c_str())+1];
strcpy(s.p->s, a); strcpy(s.p->s+lena, b.c_str());
return s;
}
inline string operator+(const string & a, const char * b) {
int lena = strlen(a.c_str());
string s; s.p->s = new char[lena+strlen(b)+1];
strcpy(s.p->s, a.c_str()); strcpy(s.p->s+lena, b);
return s;
}
inline string operator+(const string & a, const string & b) {
int lena = strlen(a.c_str());
string s; s.p->s = new char[lena+strlen(b.c_str())+1];
strcpy(s.p->s, a.c_str()); strcpy(s.p->s+lena, b.c_str());
return s;
}
//
// Comparisons.
//
inline bool operator==(const string & x, const char* s) {
return strcmp(x.p->s, s) == 0;
}
inline bool operator==(const string & x, const string & y) {
return strcmp(x.p->s, y.p->s) == 0;
}
inline bool operator!=(const string & x, const char* s) {
return strcmp(x.p->s, s) != 0;
}
inline bool operator!=(const string & x, const string & y) {
return strcmp(x.p->s, y.p->s) != 0;
}
//
// Output to a stream.
//
std::ostream & operator<<(std::ostream & s, const string & x) {
return s << x.p->s;
}
#endif /* HEP_STRING_SRC */
@@ -0,0 +1,562 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 12.06.01 E.Chernyaev - CLHEP-1.7: initial version
// 14.03.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef BASIC_VECTOR3D_H
#define BASIC_VECTOR3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
namespace HepGeom {
/**
* Base class for Point3D<T>, Vector3D<T> and Normal3D<T>.
* It defines only common functionality for those classes and
* should not be used as separate class.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<class T> class BasicVector3D {
protected:
T v_[3];
/**
* Default constructor.
* It is protected - this class should not be instantiated directly.
*/
BasicVector3D() { v_[0] = 0; v_[1] = 0; v_[2] = 0; }
public:
/**
* Safe indexing of the coordinates when using with matrices, arrays, etc.
*/
enum {
X = 0, /**< index for x-component */
Y = 1, /**< index for y-component */
Z = 2, /**< index for z-component */
NUM_COORDINATES = 3, /**< number of components */
SIZE = NUM_COORDINATES /**< number of components */
};
/**
* Constructor from three numbers. */
BasicVector3D(T x, T y, T z) { v_[0] = x; v_[1] = y; v_[2] = z; }
/**
* Copy constructor.
* Note: BasicVector3D<double> has constructors
* from BasicVector3D<double> (provided by compiler) and
* from BasicVector3D<float> (defined in this file);
* BasicVector3D<float> has only the last one.
*/
BasicVector3D(const BasicVector3D<float> & v) {
v_[0] = v.x(); v_[1] = v.y(); v_[2] = v.z();
}
/**
* Destructor. */
virtual ~BasicVector3D() {}
// -------------------------
// Interface to "good old C"
// -------------------------
/**
* Conversion (cast) to ordinary array. */
operator T * () { return v_; }
/**
* Conversion (cast) to ordinary const array. */
operator const T * () const { return v_; }
/**
* Conversion (cast) to CLHEP::Hep3Vector.
* This operator is needed only for backward compatibility and
* in principle should not exit.
*/
operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
// -----------------------------
// General arithmetic operations
// -----------------------------
/**
* Assignment. */
BasicVector3D<T> & operator= (const BasicVector3D<T> & v) {
v_[0] = v.v_[0]; v_[1] = v.v_[1]; v_[2] = v.v_[2]; return *this;
}
/**
* Addition. */
BasicVector3D<T> & operator+=(const BasicVector3D<T> & v) {
v_[0] += v.v_[0]; v_[1] += v.v_[1]; v_[2] += v.v_[2]; return *this;
}
/**
* Subtraction. */
BasicVector3D<T> & operator-=(const BasicVector3D<T> & v) {
v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2] -= v.v_[2]; return *this;
}
/**
* Multiplication by scalar. */
BasicVector3D<T> & operator*=(double a) {
v_[0] *= a; v_[1] *= a; v_[2] *= a; return *this;
}
/**
* Division by scalar. */
BasicVector3D<T> & operator/=(double a) {
v_[0] /= a; v_[1] /= a; v_[2] /= a; return *this;
}
// ------------
// Subscripting
// ------------
/**
* Gets components by index. */
T operator()(int i) const { return v_[i]; }
/**
* Gets components by index. */
T operator[](int i) const { return v_[i]; }
/**
* Sets components by index. */
T & operator()(int i) { return v_[i]; }
/**
* Sets components by index. */
T & operator[](int i) { return v_[i]; }
// ------------------------------------
// Cartesian coordinate system: x, y, z
// ------------------------------------
/**
* Gets x-component in cartesian coordinate system. */
T x() const { return v_[0]; }
/**
* Gets y-component in cartesian coordinate system. */
T y() const { return v_[1]; }
/**
* Gets z-component in cartesian coordinate system. */
T z() const { return v_[2]; }
/**
* Sets x-component in cartesian coordinate system. */
void setX(T a) { v_[0] = a; }
/**
* Sets y-component in cartesian coordinate system. */
void setY(T a) { v_[1] = a; }
/**
* Sets z-component in cartesian coordinate system. */
void setZ(T a) { v_[2] = a; }
/**
* Sets components in cartesian coordinate system. */
void set(T x, T y, T z) { v_[0] = x; v_[1] = y; v_[2] = z; }
// ------------------------------------------
// Cylindrical coordinate system: rho, phi, z
// ------------------------------------------
/**
* Gets transverse component squared. */
T perp2() const { return x()*x()+y()*y(); }
/**
* Gets transverse component. */
T perp() const { return std::sqrt(perp2()); }
/**
* Gets rho-component in cylindrical coordinate system */
T rho() const { return perp(); }
/**
* Sets transverse component keeping phi and z constant. */
void setPerp(T rh) {
T factor = perp();
if (factor > 0) {
factor = rh/factor; v_[0] *= factor; v_[1] *= factor;
}
}
// ------------------------------------------
// Spherical coordinate system: r, phi, theta
// ------------------------------------------
/**
* Gets magnitude squared of the vector. */
T mag2() const { return x()*x()+y()*y()+z()*z(); }
/**
* Gets magnitude of the vector. */
T mag() const { return std::sqrt(mag2()); }
/**
* Gets r-component in spherical coordinate system */
T r() const { return mag(); }
/**
* Gets azimuth angle. */
T phi() const {
return x() == 0 && y() == 0 ? 0 : std::atan2(y(),x());
}
/**
* Gets polar angle. */
T theta() const {
return x() == 0 && y() == 0 && z() == 0 ? 0 : std::atan2(perp(),z());
}
/**
* Gets cosine of polar angle. */
T cosTheta() const { T ma = mag(); return ma == 0 ? 1 : z()/ma; }
/**
* Gets r-component in spherical coordinate system */
T getR() const { return r(); }
/**
* Gets phi-component in spherical coordinate system */
T getPhi() const { return phi(); }
/**
* Gets theta-component in spherical coordinate system */
T getTheta() const { return theta(); }
/**
* Sets magnitude. */
void setMag(T ma) {
T factor = mag();
if (factor > 0) {
factor = ma/factor; v_[0] *= factor; v_[1] *= factor; v_[2] *= factor;
}
}
/**
* Sets r-component in spherical coordinate system. */
void setR(T ma) { setMag(ma); }
/**
* Sets phi-component in spherical coordinate system. */
void setPhi(T ph) { T xy = perp(); setX(xy*std::cos(ph)); setY(xy*std::sin(ph)); }
/**
* Sets theta-component in spherical coordinate system. */
void setTheta(T th) {
T ma = mag();
T ph = phi();
set(ma*std::sin(th)*std::cos(ph), ma*std::sin(th)*std::sin(ph), ma*std::cos(th));
}
// ---------------
// Pseudo rapidity
// ---------------
/**
* Gets pseudo-rapidity: -std::ln(std::tan(theta/2)) */
T pseudoRapidity() const;
/**
* Gets pseudo-rapidity. */
T eta() const { return pseudoRapidity(); }
/**
* Gets pseudo-rapidity. */
T getEta() const { return pseudoRapidity(); }
/**
* Sets pseudo-rapidity, keeping magnitude and phi fixed. */
void setEta(T a);
// -------------------
// Combine two vectors
// -------------------
/**
* Scalar product. */
T dot(const BasicVector3D<T> & v) const {
return x()*v.x()+y()*v.y()+z()*v.z();
}
/**
* Vector product. */
BasicVector3D<T> cross(const BasicVector3D<T> & v) const {
return BasicVector3D<T>(y()*v.z()-v.y()*z(),
z()*v.x()-v.z()*x(),
x()*v.y()-v.x()*y());
}
/**
* Returns transverse component w.r.t. given axis squared. */
T perp2(const BasicVector3D<T> & v) const {
T tot = v.mag2(), s = dot(v);
return tot > 0 ? mag2()-s*s/tot : mag2();
}
/**
* Returns transverse component w.r.t. given axis. */
T perp(const BasicVector3D<T> & v) const {
return std::sqrt(perp2(v));
}
/**
* Returns angle w.r.t. another vector. */
T angle(const BasicVector3D<T> & v) const;
// ---------------
// Related vectors
// ---------------
/**
* Returns unit vector parallel to this. */
BasicVector3D<T> unit() const {
T len = mag();
return (len > 0) ?
BasicVector3D<T>(x()/len, y()/len, z()/len) : BasicVector3D<T>();
}
/**
* Returns orthogonal vector. */
BasicVector3D<T> orthogonal() const {
T dx = x() < 0 ? -x() : x();
T dy = y() < 0 ? -y() : y();
T dz = z() < 0 ? -z() : z();
if (dx < dy) {
return dx < dz ?
BasicVector3D<T>(0,z(),-y()) : BasicVector3D<T>(y(),-x(),0);
}else{
return dy < dz ?
BasicVector3D<T>(-z(),0,x()) : BasicVector3D<T>(y(),-x(),0);
}
}
// ---------
// Rotations
// ---------
/**
* Rotates around x-axis. */
BasicVector3D<T> & rotateX(T a);
/**
* Rotates around y-axis. */
BasicVector3D<T> & rotateY(T a);
/**
* Rotates around z-axis. */
BasicVector3D<T> & rotateZ(T a);
/**
* Rotates around the axis specified by another vector. */
BasicVector3D<T> & rotate(T a, const BasicVector3D<T> & v);
};
/*************************************************************************
* *
* Non-member functions for BasicVector3D<float> *
* *
*************************************************************************/
/**
* Output to stream.
* @relates BasicVector3D
*/
std::ostream &
operator<<(std::ostream &, const BasicVector3D<float> &);
/**
* Input from stream.
* @relates BasicVector3D
*/
std::istream &
operator>>(std::istream &, BasicVector3D<float> &);
/**
* Unary plus.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator+(const BasicVector3D<float> & v) { return v; }
/**
* Addition of two vectors.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator+(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
return BasicVector3D<float>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
}
/**
* Unary minus.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator-(const BasicVector3D<float> & v) {
return BasicVector3D<float>(-v.x(), -v.y(), -v.z());
}
/**
* Subtraction of two vectors.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator-(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
return BasicVector3D<float>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
}
/**
* Multiplication vector by scalar.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator*(const BasicVector3D<float> & v, double a) {
return BasicVector3D<float>(v.x()*static_cast<float>(a), v.y()*static_cast<float>(a), v.z()*static_cast<float>(a));
}
/**
* Scalar product of two vectors.
* @relates BasicVector3D
*/
inline float
operator*(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
return a.dot(b);
}
/**
* Multiplication scalar by vector.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator*(double a, const BasicVector3D<float> & v) {
return BasicVector3D<float>(static_cast<float>(a)*v.x(), static_cast<float>(a)*v.y(), static_cast<float>(a)*v.z());
}
/**
* Division vector by scalar.
* @relates BasicVector3D
*/
inline BasicVector3D<float>
operator/(const BasicVector3D<float> & v, double a) {
return BasicVector3D<float>(v.x()/static_cast<float>(a), v.y()/static_cast<float>(a), v.z()/static_cast<float>(a));
}
/**
* Comparison of two vectors for equality.
* @relates BasicVector3D
*/
inline bool
operator==(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
}
/**
* Comparison of two vectors for inequality.
* @relates BasicVector3D
*/
inline bool
operator!=(const BasicVector3D<float> & a, const BasicVector3D<float> & b) {
return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
}
/*************************************************************************
* *
* Non-member functions for BasicVector3D<double> *
* *
*************************************************************************/
/**
* Output to stream.
* @relates BasicVector3D
*/
std::ostream &
operator<<(std::ostream &, const BasicVector3D<double> &);
/**
* Input from stream.
* @relates BasicVector3D
*/
std::istream &
operator>>(std::istream &, BasicVector3D<double> &);
/**
* Unary plus.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator+(const BasicVector3D<double> & v) { return v; }
/**
* Addition of two vectors.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator+(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
return BasicVector3D<double>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
}
/**
* Unary minus.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator-(const BasicVector3D<double> & v) {
return BasicVector3D<double>(-v.x(), -v.y(), -v.z());
}
/**
* Subtraction of two vectors.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator-(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
return BasicVector3D<double>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
}
/**
* Multiplication vector by scalar.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator*(const BasicVector3D<double> & v, double a) {
return BasicVector3D<double>(v.x()*a, v.y()*a, v.z()*a);
}
/**
* Scalar product of two vectors.
* @relates BasicVector3D
*/
inline double
operator*(const BasicVector3D<double> & a,const BasicVector3D<double> & b) {
return a.dot(b);
}
/**
* Multiplication scalar by vector.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator*(double a, const BasicVector3D<double> & v) {
return BasicVector3D<double>(a*v.x(), a*v.y(), a*v.z());
}
/**
* Division vector by scalar.
* @relates BasicVector3D
*/
inline BasicVector3D<double>
operator/(const BasicVector3D<double> & v, double a) {
return BasicVector3D<double>(v.x()/a, v.y()/a, v.z()/a);
}
/**
* Comparison of two vectors for equality.
* @relates BasicVector3D
*/
inline bool
operator==(const BasicVector3D<double> & a, const BasicVector3D<double> & b)
{
return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
}
/**
* Comparison of two vectors for inequality.
* @relates BasicVector3D
*/
inline bool
operator!=(const BasicVector3D<double> & a, const BasicVector3D<double> & b)
{
return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
}
} /* namespace HepGeom */
#endif /* BASIC_VECTOR3D_H */
+184
View File
@@ -0,0 +1,184 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 09.09.96 E.Chernyaev - initial version
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
// the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef HEP_NORMAL3D_H
#define HEP_NORMAL3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Geometry/BasicVector3D.h"
namespace HepGeom {
class Transform3D;
/**
* Geometrical 3D Normal.
* This is just a declaration of the class needed to define
* specializations Normal3D<float> and Normal3D<double>.
*
* @ingroup geometry
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class Normal3D : public BasicVector3D<T> {};
/**
* Geometrical 3D Normal with components of float type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Normal3D<float> : public BasicVector3D<float> {
public:
/**
* Default constructor. */
Normal3D() {}
/**
* Constructor from three numbers. */
Normal3D(float x, float y, float z) : BasicVector3D<float>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Normal3D(const float * a)
: BasicVector3D<float>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Normal3D(const Normal3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Normal3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Destructor. */
~Normal3D() {}
/**
* Assignment. */
Normal3D<float> & operator=(const Normal3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Normal3D<float> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Normal3D<float> & transform(const Transform3D & m);
};
/**
* Transformation of Normal<float> by Transform3D.
* @relates Normal3D
*/
Normal3D<float>
operator*(const Transform3D & m, const Normal3D<float> & n);
/**
* Geometrical 3D Normal with components of double type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Normal3D<double> : public BasicVector3D<double> {
public:
/**
* Default constructor. */
Normal3D() {}
/**
* Constructor from three numbers. */
Normal3D(double x, double y, double z) : BasicVector3D<double>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Normal3D(const float * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Constructor from array of doubles. */
explicit Normal3D(const double * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Normal3D(const Normal3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Normal3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<double>. */
Normal3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Destructor. */
~Normal3D() {}
/**
* Constructor from CLHEP::Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
*/
Normal3D(const CLHEP::Hep3Vector & v)
: BasicVector3D<double>(v.x(),v.y(),v.z()) {}
/**
* Conversion (cast) to CLHEP::Hep3Vector.
* This operator is needed only for backward compatibility and
* in principle should not exit.
*/
operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
/**
* Assignment. */
Normal3D<double> & operator=(const Normal3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Normal3D<double> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<double>. */
Normal3D<double> & operator=(const BasicVector3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Normal3D<double> & transform(const Transform3D & m);
};
/**
* Transformation of Normal<double> by Transform3D.
* @relates Normal3D
*/
Normal3D<double>
operator*(const Transform3D & m, const Normal3D<double> & n);
} /* namespace HepGeom */
#endif /* HEP_NORMAL3D_H */
+156
View File
@@ -0,0 +1,156 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 22.09.96 E.Chernyaev - initial version
// 19.10.96 J.Allison - added == and <<.
// 15.04.03 E.Chernyaev - CLHEP-1.9: template version
#ifndef HEP_PLANE3D_H
#define HEP_PLANE3D_H
#include <iosfwd>
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Geometry/Normal3D.h"
#include "CLHEP/Geometry/Transform3D.h"
namespace HepGeom {
/**
* Template class for geometrical plane in 3D.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<class T>
class Plane3D {
protected:
T a_, b_, c_, d_;
public:
/**
* Default constructor - creates plane z=0. */
Plane3D() : a_(0.), b_(0.), c_(1.), d_(0.) {}
/**
* Constructor from four numbers - creates plane a*x+b*y+c*z+d=0. */
Plane3D(T a, T b, T c, T d) : a_(a), b_(b), c_(c), d_(d) {}
/**
* Constructor from normal and point. */
Plane3D(const Normal3D<T> & n, const Point3D<T> & p)
: a_(n.x()), b_(n.y()), c_(n.z()), d_(-n*p) {}
/**
* Constructor from three points. */
Plane3D(const Point3D<T> & p1,
const Point3D<T> & p2,
const Point3D<T> & p3) {
Normal3D<T> n = (p2-p1).cross(p3-p1);
a_ = n.x(); b_ = n.y(); c_ = n.z(); d_ = -n*p1;
}
/** Copy constructor.
* Plane3D<double> has two constructors:
* from Plane3D<double> (provided by compiler) and
* from Plane3D<float> (defined in this file).
* Plane3D<float> has only the last one.
*/
Plane3D(const Plane3D<float> & p)
: a_(p.a_), b_(p.b_), c_(p.c_), d_(p.d_) {}
/**
* Destructor. */
~Plane3D() {};
/**
* Assignment. */
Plane3D<T> & operator=(const Plane3D<T> & p) {
a_ = p.a_; b_ = p.b_; c_ = p.c_; d_ = p.d_; return *this;
}
/**
* Returns the a-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T a() const { return a_; }
/**
* Returns the b-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T b() const { return b_; }
/**
* Returns the c-coefficient in the plane equation: a*x+b*y+c*z+d=0. */
T c() const { return c_; }
/**
* Returns the free member of the plane equation: a*x+b*y+c*z+d=0. */
T d() const { return d_; }
/**
* Returns normal. */
Normal3D<T> normal() const { return Normal3D<T>(a_,b_,c_); }
/**
* Normalization. */
Plane3D<T> & normalize() {
double ll = std::sqrt(a_*a_ + b_*b_ + c_*c_);
if (ll > 0.) { a_ /= ll; b_ /= ll; c_ /= ll, d_ /= ll; }
return *this;
}
/**
* Returns distance to the point. */
T distance(const Point3D<T> & p) const {
return a()*p.x() + b()*p.y() + c()*p.z() + d();
}
/**
* Returns projection of the point to the plane. */
Point3D<T> point(const Point3D<T> & p) const {
T k = distance(p)/(a()*a()+b()*b()+c()*c());
return Point3D<T>(p.x()-a()*k, p.y()-b()*k, p.z()-c()*k);
}
/**
* Returns projection of the origin to the plane. */
Point3D<T> point() const {
T k = -d()/(a()*a()+b()*b()+c()*c());
return Point3D<T>(a()*k, b()*k, c()*k);
}
/**
* Test for equality. */
bool operator == (const Plane3D<T> & p) const {
return a() == p.a() && b() == p.b() && c() == p.c() && d() == p.d();
}
/**
* Test for inequality. */
bool operator != (const Plane3D<T> & p) const {
return a() != p.a() || b() != p.b() || c() != p.c() || d() != p.d();
}
/**
* Transformation by Transform3D. */
Plane3D<T> & transform(const Transform3D & m) {
Normal3D<T> n = normal();
n.transform(m);
d_ = -n*point().transform(m); a_ = n.x(); b_ = n.y(); c_ = n.z();
return *this;
}
};
/**
* Output to the stream.
* @relates Plane3D
*/
std::ostream & operator<<(std::ostream & os, const Plane3D<float> & p);
/**
* Output to the stream.
* @relates Plane3D
*/
std::ostream & operator<<(std::ostream & os, const Plane3D<double> & p);
} /* namespace HepGeom */
#endif /* HEP_PLANE3D_H */
+226
View File
@@ -0,0 +1,226 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 09.09.96 E.Chernyaev - initial version
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
// the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef HEP_POINT3D_H
#define HEP_POINT3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Geometry/BasicVector3D.h"
namespace HepGeom {
class Transform3D;
/**
* Geometrical 3D Point.
* This is just a declaration of the class needed to define
* specializations Point3D<float> and Point3D<double>.
*
* @ingroup geometry
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class Point3D : public BasicVector3D<T> {};
/**
* Geometrical 3D Point with components of float type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Point3D<float> : public BasicVector3D<float> {
public:
/**
* Default constructor. */
Point3D() {}
/**
* Constructor from three numbers. */
Point3D(float x, float y, float z) : BasicVector3D<float>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Point3D(const float * a)
: BasicVector3D<float>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Point3D(const Point3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Point3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Destructor. */
~Point3D() {}
/**
* Assignment. */
Point3D<float> & operator=(const Point3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Point3D<float> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Returns distance to the origin squared. */
float distance2() const { return mag2(); }
/**
* Returns distance to the point squared. */
float distance2(const Point3D<float> & p) const {
float dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
return dx*dx + dy*dy + dz*dz;
}
/**
* Returns distance to the origin. */
float distance() const { return std::sqrt(distance2()); }
/**
* Returns distance to the point. */
float distance(const Point3D<float> & p) const {
return std::sqrt(distance2(p));
}
/**
* Transformation by Transform3D. */
Point3D<float> & transform(const Transform3D & m);
};
/**
* Transformation of Point3D<float> by Transform3D.
* @relates Point3D
*/
Point3D<float>
operator*(const Transform3D & m, const Point3D<float> & p);
/**
* Geometrical 3D Point with components of double type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Point3D<double> : public BasicVector3D<double> {
public:
/**
* Default constructor. */
Point3D() {}
/**
* Constructor from three numbers. */
Point3D(double x, double y, double z) : BasicVector3D<double>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Point3D(const float * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Constructor from array of doubles. */
explicit Point3D(const double * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Point3D(const Point3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Point3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<double>. */
Point3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Destructor. */
~Point3D() {}
/**
* Constructor from CLHEP::Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
*/
Point3D(const CLHEP::Hep3Vector & v)
: BasicVector3D<double>(v.x(),v.y(),v.z()) {}
/**
* Conversion (cast) to CLHEP::Hep3Vector.
* This operator is needed only for backward compatibility and
* in principle should not exit.
*/
operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
/**
* Assignment. */
Point3D<double> & operator=(const Point3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Point3D<double> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<double>. */
Point3D<double> & operator=(const BasicVector3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Returns distance to the origin squared. */
double distance2() const { return mag2(); }
/**
* Returns distance to the point squared. */
double distance2(const Point3D<double> & p) const {
double dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
return dx*dx + dy*dy + dz*dz;
}
/**
* Returns distance to the origin. */
double distance() const { return std::sqrt(distance2()); }
/**
* Returns distance to the point. */
double distance(const Point3D<double> & p) const {
return std::sqrt(distance2(p));
}
/**
* Transformation by Transform3D. */
Point3D<double> & transform(const Transform3D & m);
};
/**
* Transformation of Point3D<double> by Transform3D.
* @relates Point3D
*/
Point3D<double>
operator*(const Transform3D & m, const Point3D<double> & p);
} /* namespace HepGeom */
#endif /* HEP_POINT3D_H */
@@ -0,0 +1,820 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// Hep geometrical 3D Transformation class
//
// Author: Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
//
// ******************************************
// * *
// * Transform *
// * / / \ \ *
// * -------- / \ -------- *
// * / / \ \ *
// * Rotate Translate Reflect Scale *
// * / | \ / | \ / | \ / | \ *
// * X Y Z X Y Z X Y Z X Y Z *
// * *
// ******************************************
//
// Identity transformation:
// Transform3D::Identity - global identity transformation;
// any constructor without parameters, e.g. Transform3D();
// m.setIdentity() - set "m" to identity;
//
// General transformations:
// Transform3D(m,v) - transformation given by Rotation "m"
// and CLHEP::Hep3Vector "v";
// Transform3D(a0,a1,a2, b0,b1,b2) - transformation given by initial
// and transformed positions of three points;
// Rotations:
// Rotate3D(m) - rotation given by CLHEP::HepRotation "m";
// Rotate3D(ang,v) - rotation through the angle "ang" around
// vector "v";
// Rotate3D(ang,p1,p2) - rotation through the angle "ang"
// counterclockwise around the axis given by
// two points p1->p2;
// Rotate3D(a1,a2, b1,b2) - rotation around the origin defined by initial
// and transformed positions of two points;
// RotateX3D(ang) - rotation around X-axis;
// RotateY3D(ang) - rotation around Y-axis;
// RotateZ3D(ang) - rotation around Z-axis;
//
// Translations:
// Translate3D(v) - translation given by CLHEP::Hep3Vector "v";
// Translate3D(dx,dy,dz) - translation on vector (dx,dy,dz);
// TraslateX3D(dx) - translation along X-axis;
// TraslateY3D(dy) - translation along Y-axis;
// TraslateZ3D(dz) - translation along Z-axis;
//
// Reflections:
// Reflect3D(a,b,c,d) - reflection in the plane a*x+b*y+c*z+d=0;
// Reflect3D(normal,p) - reflection in the plane going through "p"
// and whose normal is equal to "normal";
// ReflectX3D(a) - reflect X in the plane x=a (default a=0);
// ReflectY3D(a) - reflect Y in the plane y=a (default a=0);
// ReflectZ3D(a) - reflect Z in the plane z=a (default a=0);
//
// Scalings:
// Scale3D(sx,sy,sz) - general scaling with factors "sx","sy","sz"
// along X, Y and Z;
// Scale3D(s) - scaling with constant factor "s" along all
// directions;
// ScaleX3D(sx) - scale X;
// ScaleY3D(sy) - scale Y;
// ScaleZ3D(sz) - scale Z;
//
// Inverse transformation:
// m.inverse() or - returns inverse transformation;
//
// Compound transformation:
// m3 = m2 * m1 - it is relatively slow in comparison with
// transformation of a vector. Use parenthesis
// to avoid this operation (see example below);
// Transformation of point:
// p2 = m * p1
//
// Transformation of vector:
// v2 = m * v1
//
// Transformation of normal:
// n2 = m * n1
//
// The following table explains how different transformations affect
// point, vector and normal. "+" means affect, "-" means do not affect,
// "*" meas affect but in different way than "+"
//
// Point Vector Normal
// -------------+-------+-------+-------
// Rotation ! + ! + ! +
// Translation ! + ! - ! -
// Reflection ! + ! + ! *
// Scaling ! + ! + ! *
// -------------+-------+-------+-------
//
// Example of the usage:
//
// Transform3D m1, m2, m3;
// HepVector3D v2, v1(0,0,0);
//
// m1 = Rotate3D(angle, Vector3D(1,1,1));
// m2 = Translate3D(dx,dy,dz);
// m3 = m1.inverse();
//
// v2 = m3*(m2*(m1*v1));
//
// History:
// 24.09.96 E.Chernyaev - initial version
//
// 26.02.97 E.Chernyaev
// - added global Identity by request of John Allison
// (to avoid problems with compilation on HP)
// - added getRotation and getTranslation
//
// 29.01.01 E.Chernyaev - added subscripting
// 11.06.01 E.Chernyaev - added getDecomposition
#ifndef HEP_TRANSFROM3D_H
#define HEP_TRANSFROM3D_H
#include "CLHEP/Vector/ThreeVector.h"
namespace HepGeom {
template<class T> class Point3D;
template<class T> class Vector3D;
template<class T> class Normal3D;
class Translate3D;
class Rotate3D;
class Scale3D;
/**
* Class for transformation of 3D geometrical objects.
* It allows different translations, rotations, scalings and reflections.
* Several specialized classes are derived from it:
*
* TranslateX3D, TranslateY3D, TranslateZ3D, Translate3D,<br>
* RotateX3D, RotateY3D, RotateZ3D, Rotate3D, <br>
* ScaleX3D, ScaleY3D, ScaleZ3D, Scale3D, <br>
* ReflectX3D, ReflectY3D, ReflectZ3D, Reflect3D.
*
* The idea behind these classes is to provide some additional constructors
* for Transform3D, they normally should not be used as separate classes.
*
* Example:
* @code
* HepGeom::Transform3D m;
* m = HepGeom::TranslateX3D(10.*cm);
* @endcode
*
* Remark:
* For the reason that the operator* is left associative, the notation
* @code
* v2 = m3*(m2*(m1*v1));
* @endcode
* is much more effective then the notation
* @code
* v2 = m3*m2*m1*v1;
* @endcode
* In the first case three operations Transform3D*Vector3D are executed,
* in the second case two operations Transform3D*Transform3D and one
* Transform3D*Vector3D are performed. Transform3D*Transform3D is
* roughly three times slower than Transform3D*Vector3D.
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class Transform3D {
protected:
double xx_, xy_, xz_, dx_, // 4x3 Transformation Matrix
yx_, yy_, yz_, dy_,
zx_, zy_, zz_, dz_;
// Protected constructor
Transform3D(double XX, double XY, double XZ, double DX,
double YX, double YY, double YZ, double DY,
double ZX, double ZY, double ZZ, double DZ)
: xx_(XX), xy_(XY), xz_(XZ), dx_(DX),
yx_(YX), yy_(YY), yz_(YZ), dy_(DY),
zx_(ZX), zy_(ZY), zz_(ZZ), dz_(DZ) {}
// Set transformation matrix
void setTransform(double XX, double XY, double XZ, double DX,
double YX, double YY, double YZ, double DY,
double ZX, double ZY, double ZZ, double DZ) {
xx_ = XX; xy_ = XY; xz_ = XZ; dx_ = DX;
yx_ = YX; yy_ = YY; yz_ = YZ; dy_ = DY;
zx_ = ZX; zy_ = ZY; zz_ = ZZ; dz_ = DZ;
}
public:
/**
* Global identity transformation. */
static const Transform3D Identity;
// Helper class for implemention of C-style subscripting r[i][j]
class Transform3D_row {
public:
inline Transform3D_row(const Transform3D &, int);
inline double operator [] (int) const;
private:
const Transform3D & rr;
int ii;
};
/**
* Default constructor - sets the Identity transformation. */
Transform3D()
: xx_(1), xy_(0), xz_(0), dx_(0),
yx_(0), yy_(1), yz_(0), dy_(0),
zx_(0), zy_(0), zz_(1), dz_(0) {}
/**
* Constructor: rotation and then translation. */
inline Transform3D(const CLHEP::HepRotation & m, const CLHEP::Hep3Vector & v);
/**
* Constructor: transformation of basis (assumed - no reflection). */
Transform3D(const Point3D<double> & fr0,
const Point3D<double> & fr1,
const Point3D<double> & fr2,
const Point3D<double> & to0,
const Point3D<double> & to1,
const Point3D<double> & to2);
/**
* Copy constructor. */
Transform3D(const Transform3D & m)
: xx_(m.xx_), xy_(m.xy_), xz_(m.xz_), dx_(m.dx_),
yx_(m.yx_), yy_(m.yy_), yz_(m.yz_), dy_(m.dy_),
zx_(m.zx_), zy_(m.zy_), zz_(m.zz_), dz_(m.dz_) {}
/**
* Destructor.
* Virtual for now as some persistency mechanism needs that,
* in future releases this might go away again.
*/
~Transform3D() { /* nop */ }
/**
* Returns object of the helper class for C-style subscripting r[i][j] */
inline const Transform3D_row operator [] (int) const;
/** Fortran-style subscripting: returns (i,j) element of the matrix. */
double operator () (int, int) const;
/**
* Gets xx-element of the transformation matrix. */
double xx() const { return xx_; }
/**
* Gets xy-element of the transformation matrix. */
double xy() const { return xy_; }
/**
* Gets xz-element of the transformation matrix. */
double xz() const { return xz_; }
/**
* Gets yx-element of the transformation matrix. */
double yx() const { return yx_; }
/**
* Gets yy-element of the transformation matrix. */
double yy() const { return yy_; }
/**
* Gets yz-element of the transformation matrix. */
double yz() const { return yz_; }
/**
* Gets zx-element of the transformation matrix. */
double zx() const { return zx_; }
/**
* Gets zy-element of the transformation matrix. */
double zy() const { return zy_; }
/**
* Gets zz-element of the transformation matrix. */
double zz() const { return zz_; }
/**
* Gets dx-element of the transformation matrix. */
double dx() const { return dx_; }
/**
* Gets dy-element of the transformation matrix. */
double dy() const { return dy_; }
/**
* Gets dz-element of the transformation matrix. */
double dz() const { return dz_; }
/**
* Assignment. */
Transform3D & operator=(const Transform3D &m) {
xx_= m.xx_; xy_= m.xy_; xz_= m.xz_; dx_= m.dx_;
yx_= m.yx_; yy_= m.yy_; yz_= m.yz_; dy_= m.dy_;
zx_= m.zx_; zy_= m.zy_; zz_= m.zz_; dz_= m.dz_;
return *this;
}
/**
* Sets the Identity transformation. */
void setIdentity() {
xy_= xz_= dx_= yx_= yz_= dy_= zx_= zy_= dz_= 0; xx_= yy_= zz_= 1;
}
/**
* Returns the inverse transformation. */
Transform3D inverse() const;
/**
* Transformation by another Transform3D. */
Transform3D operator*(const Transform3D & b) const;
/**
* Decomposition of general transformation.
* This function gets decomposition of the transformation
* in three consequentive specific transformations: Scale3D,
* then Rotate3D, then Translate3, i.e.
* @code
* Transform3D = Translate3D * Rotate3D * Scale3D
* @endcode
*
* @param scale output: scaling transformation;
* if there was a reflection, then scale factor for
* z-component (scale(2,2)) will be negative.
* @param rotation output: rotation transformaion.
* @param translation output: translation transformaion.
*/
void getDecomposition(Scale3D & scale,
Rotate3D & rotation,
Translate3D & translation) const;
/**
* Returns true if the difference between corresponding
* matrix elements is less than the tolerance.
*/
bool isNear(const Transform3D & t, double tolerance = 2.2E-14 ) const;
/**
* Extracts the rotation matrix.
* This functions is obsolete - use getDecomposition() instead.
*/
inline CLHEP::HepRotation getRotation() const;
/**
* Extracts the translation vector.
* This functions is obsolete - use getDecomposition() instead.
*/
inline CLHEP::Hep3Vector getTranslation() const;
/**
* Test for equality. */
bool operator == (const Transform3D & transform) const;
/**
* Test for inequality. */
bool operator != (const Transform3D & transform) const {
return ! operator==(transform);
}
};
// R O T A T I O N S
/**
* Constructs a rotation transformation.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = Rotate3D(30.*deg, HepVector3D(1.,1.,1.));
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class Rotate3D : public Transform3D {
public:
/**
* Default constructor: sets the Identity transformation. */
Rotate3D() : Transform3D() {}
/**
* Constructor from CLHEP::HepRotation. */
inline Rotate3D(const CLHEP::HepRotation &m);
/**
* Constructor from angle and axis given by two points.
* @param a angle of rotation
* @param p1 begin point of the axis
* @param p2 end point of the axis
*/
Rotate3D(double a,
const Point3D<double> & p1,
const Point3D<double> & p2);
/**
* Constructor from angle and axis.
* @param a angle of rotation
* @param v axis of rotation
*/
inline Rotate3D(double a, const Vector3D<double> & v);
/**
* Constructor for rotation given by original and rotated position of
* two points. It is assumed that there is no reflection.
* @param fr1 original position of 1st point
* @param fr2 original position of 2nd point
* @param to1 rotated position of 1st point
* @param to2 rotated position of 2nd point
*/
inline Rotate3D(const Point3D<double> & fr1,
const Point3D<double> & fr2,
const Point3D<double> & to1,
const Point3D<double> & to2);
};
/**
* Constructs a rotation around x-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = RotateX3D(30.*deg);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class RotateX3D : public Rotate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
RotateX3D() : Rotate3D() {}
/**
* Constructs a rotation around x-axis by angle a. */
RotateX3D(double a) {
double cosa = std::cos(a), sina = std::sin(a);
setTransform(1,0,0,0, 0,cosa,-sina,0, 0,sina,cosa,0);
}
};
/**
* Constructs a rotation around y-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = RotateY3D(30.*deg);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class RotateY3D : public Rotate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
RotateY3D() : Rotate3D() {}
/**
* Constructs a rotation around y-axis by angle a. */
RotateY3D(double a) {
double cosa = std::cos(a), sina = std::sin(a);
setTransform(cosa,0,sina,0, 0,1,0,0, -sina,0,cosa,0);
}
};
/**
* Constructs a rotation around z-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = RotateZ3D(30.*deg);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class RotateZ3D : public Rotate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
RotateZ3D() : Rotate3D() {}
/**
* Constructs a rotation around z-axis by angle a. */
RotateZ3D(double a) {
double cosa = std::cos(a), sina = std::sin(a);
setTransform(cosa,-sina,0,0, sina,cosa,0,0, 0,0,1,0);
}
};
// T R A N S L A T I O N S
/**
* Constructs a translation transformation.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = Translate3D(10.,20.,30.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class Translate3D : public Transform3D {
public:
/**
* Default constructor: sets the Identity transformation. */
Translate3D() : Transform3D() {}
/**
* Constructor from CLHEP::Hep3Vector. */
inline Translate3D(const CLHEP::Hep3Vector &v);
/**
* Constructor from three numbers. */
Translate3D(double x, double y, double z)
: Transform3D(1,0,0,x, 0,1,0,y, 0,0,1,z) {}
};
/**
* Constructs a translation along x-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = TranslateX3D(10.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class TranslateX3D : public Translate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
TranslateX3D() : Translate3D() {}
/**
* Constructor from a number. */
TranslateX3D(double x) : Translate3D(x, 0, 0) {}
};
/**
* Constructs a translation along y-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = TranslateY3D(10.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class TranslateY3D : public Translate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
TranslateY3D() : Translate3D() {}
/**
* Constructor from a number. */
TranslateY3D(double y) : Translate3D(0, y, 0) {}
};
/**
* Constructs a translation along z-axis.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = TranslateZ3D(10.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class TranslateZ3D : public Translate3D {
public:
/**
* Default constructor: sets the Identity transformation. */
TranslateZ3D() : Translate3D() {}
/**
* Constructor from a number. */
TranslateZ3D(double z) : Translate3D(0, 0, z) {}
};
// R E F L E C T I O N S
/**
* Constructs a reflection transformation.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = Reflect3D(1.,1.,1.,0.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class Reflect3D : public Transform3D {
protected:
Reflect3D(double XX, double XY, double XZ, double DX,
double YX, double YY, double YZ, double DY,
double ZX, double ZY, double ZZ, double DZ)
: Transform3D(XX,XY,XZ,DX, YX,YY,YZ,DY, ZX,ZY,ZZ,DZ) {}
public:
/**
* Default constructor: sets the Identity transformation. */
Reflect3D() : Transform3D() {}
/**
* Constructor from four numbers.
* Sets reflection in a plane a*x+b*y+c*z+d=0
*/
Reflect3D(double a, double b, double c, double d);
/**
* Constructor from a plane given by its normal and origin. */
inline Reflect3D(const Normal3D<double> & normal,
const Point3D<double> & point);
};
/**
* Constructs reflection in a plane x=const.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ReflectX3D(1.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ReflectX3D : public Reflect3D {
public:
/**
* Constructor from a number. */
ReflectX3D(double x=0) : Reflect3D(-1,0,0,x+x, 0,1,0,0, 0,0,1,0) {}
};
/**
* Constructs reflection in a plane y=const.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ReflectY3D(1.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ReflectY3D : public Reflect3D {
public:
/**
* Constructor from a number. */
ReflectY3D(double y=0) : Reflect3D(1,0,0,0, 0,-1,0,y+y, 0,0,1,0) {}
};
/**
* Constructs reflection in a plane z=const.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ReflectZ3D(1.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ReflectZ3D : public Reflect3D {
public:
/**
* Constructor from a number. */
ReflectZ3D(double z=0) : Reflect3D(1,0,0,0, 0,1,0,0, 0,0,-1,z+z) {}
};
// S C A L I N G S
/**
* Constructs a scaling transformation.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = Scale3D(2.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class Scale3D : public Transform3D {
public:
/**
* Default constructor: sets the Identity transformation. */
Scale3D() : Transform3D() {}
/**
* Constructor from three numbers - scale factors in different directions.
*/
Scale3D(double x, double y, double z)
: Transform3D(x,0,0,0, 0,y,0,0, 0,0,z,0) {}
/**
* Constructor from a number: sets uniform scaling in all directions. */
Scale3D(double s)
: Transform3D(s,0,0,0, 0,s,0,0, 0,0,s,0) {}
};
/**
* Constructs a scaling transformation in x-direction.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ScaleX3D(2.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ScaleX3D : public Scale3D {
public:
/**
* Default constructor: sets the Identity transformation. */
ScaleX3D() : Scale3D() {}
/**
* Constructor from a number (scale factor in x-direction). */
ScaleX3D(double x) : Scale3D(x, 1, 1) {}
};
/**
* Constructs a scaling transformation in y-direction.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ScaleY3D(2.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ScaleY3D : public Scale3D {
public:
/**
* Default constructor: sets the Identity transformation. */
ScaleY3D() : Scale3D() {}
/**
* Constructor from a number (scale factor in y-direction). */
ScaleY3D(double y) : Scale3D(1, y, 1) {}
};
/**
* Constructs a scaling transformation in z-direction.
* This class provides additional constructors for Transform3D
* and should not be used as a separate class.
*
* Example of use:
* @code
* Transform3D m;
* m = ScaleZ3D(2.);
* @endcode
*
* @author <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
class ScaleZ3D : public Scale3D {
public:
/**
* Default constructor: sets the Identity transformation. */
ScaleZ3D() : Scale3D() {}
/**
* Constructor from a number (scale factor in z-direction). */
ScaleZ3D(double z) : Scale3D(1, 1, z) {}
};
} /* namespace HepGeom */
#include "CLHEP/Geometry/Transform3D.icc"
#endif /* HEP_TRANSFROM3D_H */
@@ -0,0 +1,87 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Vector/Rotation.h"
#include "CLHEP/Geometry/Point3D.h"
#include "CLHEP/Geometry/Vector3D.h"
#include "CLHEP/Geometry/Normal3D.h"
namespace HepGeom {
// I N L I N E S F O R T R A N S F O R M A T I O N
inline
Transform3D::Transform3D_row::Transform3D_row
(const Transform3D & r, int i) : rr(r), ii(i) {}
inline
double Transform3D::Transform3D_row::operator[](int jj) const {
return rr(ii,jj);
}
inline
const Transform3D::Transform3D_row Transform3D::operator[](int i) const {
return Transform3D_row(*this, i);
}
inline
Transform3D::Transform3D(const CLHEP::HepRotation & m, const CLHEP::Hep3Vector & v) {
xx_= m.xx(); xy_= m.xy(); xz_= m.xz();
yx_= m.yx(); yy_= m.yy(); yz_= m.yz();
zx_= m.zx(); zy_= m.zy(); zz_= m.zz();
dx_= v.x(); dy_= v.y(); dz_= v.z();
}
inline
CLHEP::HepRotation
Transform3D::getRotation() const {
CLHEP::HepRotation m;
return m.rotateAxes(CLHEP::Hep3Vector(xx_,yx_,zx_),
CLHEP::Hep3Vector(xy_,yy_,zy_),
CLHEP::Hep3Vector(xz_,yz_,zz_));
}
inline
CLHEP::Hep3Vector
Transform3D::getTranslation() const {
return CLHEP::Hep3Vector(dx_,dy_,dz_);
}
// I N L I N E S F O R R O T A T I O N
inline
Rotate3D::Rotate3D(const CLHEP::HepRotation & m) {
xx_= m.xx(); xy_= m.xy(); xz_= m.xz();
yx_= m.yx(); yy_= m.yy(); yz_= m.yz();
zx_= m.zx(); zy_= m.zy(); zz_= m.zz();
dx_= 0; dy_= 0; dz_= 0;
}
inline
Rotate3D::Rotate3D(double a, const Vector3D<double> & v) {
*this =
Rotate3D(a, Point3D<double>(0,0,0), Point3D<double>(v.x(),v.y(),v.z()));
}
inline
Rotate3D::Rotate3D(const Point3D<double> & fr1, const Point3D<double> & fr2,
const Point3D<double> & to1, const Point3D<double> & to2)
: Transform3D(Point3D<double>(0,0,0),fr1,fr2,
Point3D<double>(0,0,0),to1,to2) {}
// I N L I N E S F O R T R A N S L A T I O N
inline
Translate3D::Translate3D(const CLHEP::Hep3Vector & v)
: Transform3D(1,0,0,v.x(), 0,1,0,v.y(), 0,0,1,v.z()) {}
// I N L I N E S F O R R E F L E C T I O N
inline
Reflect3D::Reflect3D(const Normal3D<double> & n, const Point3D<double> & p) {
*this = Reflect3D(n.x(), n.y(), n.z(), -n*p);
}
} /* namespace HepGeom */
+184
View File
@@ -0,0 +1,184 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// History:
// 09.09.96 E.Chernyaev - initial version
// 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
// the functionality from CLHEP::Hep3Vector
// 01.04.03 E.Chernyaev - CLHEP-1.9: template version
//
#ifndef HEP_VECTOR3D_H
#define HEP_VECTOR3D_H
#include <iosfwd>
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Geometry/BasicVector3D.h"
namespace HepGeom {
class Transform3D;
/**
* Geometrical 3D Vector.
* This is just a declaration of the class needed to define
* specializations Vector3D<float> and Vector3D<double>.
*
* @ingroup geometry
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
*/
template<class T>
class Vector3D : public BasicVector3D<T> {};
/**
* Geometrical 3D Vector with components of float type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Vector3D<float> : public BasicVector3D<float> {
public:
/**
* Default constructor. */
Vector3D() {}
/**
* Constructor from three numbers. */
Vector3D(float x, float y, float z) : BasicVector3D<float>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Vector3D(const float * a)
: BasicVector3D<float>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Vector3D(const Vector3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Vector3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
/**
* Destructor. */
~Vector3D() {}
/**
* Assignment. */
Vector3D<float> & operator=(const Vector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Vector3D<float> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Vector3D<float> & transform(const Transform3D & m);
};
/**
* Transformation of Vector<float> by Transform3D.
* @relates Vector3D
*/
Vector3D<float>
operator*(const Transform3D & m, const Vector3D<float> & v);
/**
* Geometrical 3D Vector with components of double type.
*
* @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
* @ingroup geometry
*/
template<>
class Vector3D<double> : public BasicVector3D<double> {
public:
/**
* Default constructor. */
Vector3D() {}
/**
* Constructor from three numbers. */
Vector3D(double x, double y, double z) : BasicVector3D<double>(x,y,z) {}
/**
* Constructor from array of floats. */
explicit Vector3D(const float * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Constructor from array of doubles. */
explicit Vector3D(const double * a)
: BasicVector3D<double>(a[0],a[1],a[2]) {}
/**
* Copy constructor. */
Vector3D(const Vector3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<float>. */
Vector3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
/**
* Constructor from BasicVector3D<double>. */
Vector3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
/**
* Destructor. */
~Vector3D() {}
/**
* Constructor from CLHEP::Hep3Vector.
* This constructor is needed only for backward compatibility and
* in principle should be absent.
*/
Vector3D(const CLHEP::Hep3Vector & v)
: BasicVector3D<double>(v.x(),v.y(),v.z()) {}
/**
* Conversion (cast) to CLHEP::Hep3Vector.
* This operator is needed only for backward compatibility and
* in principle should not exit.
*/
operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
/**
* Assignment. */
Vector3D<double> & operator=(const Vector3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<float>. */
Vector3D<double> & operator=(const BasicVector3D<float> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Assignment from BasicVector3D<double>. */
Vector3D<double> & operator=(const BasicVector3D<double> & v) {
set(v.x(),v.y(),v.z()); return *this;
}
/**
* Transformation by Transform3D. */
Vector3D<double> & transform(const Transform3D & m);
};
/**
* Transformation of Vector<double> by Transform3D.
* @relates Vector3D
*/
Vector3D<double>
operator*(const Transform3D & m, const Vector3D<double> & v);
} /* namespace HepGeom */
#endif /* HEP_VECTOR3D_H */
+72
View File
@@ -0,0 +1,72 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// Hep Random
// --- DoubConv ---
// class header file
// -----------------------------------------------------------------------
//
#ifndef DOUBCONV_HH
#define DOUBCONV_HH
#include <string>
#include <vector>
#include <exception>
namespace CLHEP {
class DoubConvException : public std::exception {
public:
DoubConvException(const std::string & w) throw() : msg(w) {}
~DoubConvException() throw() {}
const char* what() const throw() { return msg.c_str(); }
private:
std::string msg;
};
class DoubConv {
public:
// dto2longs(d) returns (in a vector) two unsigned longs string containing the
// representation of its double input. This is byte-ordering
// independant, and depends for complete portability ONLY on adherance
// to the IEEE 754 standard for 64-bit floating point representation.
// The first unsigned long contains the high-order bits in IEEE; thus
// 1.0 will always be 0x3FF00000, 00000000
static std::vector<unsigned long> dto2longs(double d);
// longs2double (v) returns a double containing the value represented by its
// input, which must be a vector containing 2 unsigned longs.
// The input is taken to be the representation according to
// the IEEE 754 standard for a 64-bit floating point number, whose value
// is returned as a double. The byte-ordering of the double result is,
// of course, tailored to the proper byte-ordering for the system.
static double longs2double (const std::vector<unsigned long> & v);
// dtox(d) returns a 16-character string containing the (zero-filled) hex
// representation of its double input. This is byte-ordering
// independant, and depends for complete portability ONLY on adherance
// to the IEEE 754 standard for 64-bit floating point representation.
static std::string d2x(double d);
private:
union DB8 {
unsigned char b[8];
double d;
};
static void fill_byte_order ();
static bool byte_order_known;
static int byte_order[8];
// Meaning of byte_order: The first (high-order in IEEE 754) byte to
// output (or the high-order byte of the first unsigned long)
// is of db.b[byte_order[0]]. Thus the index INTO byte_order
// is a position in the IEEE representation of the double, and the value
// of byte_order[k] is an offset in the memory representation of the
// double.
};
}
#endif // DOUBCONV_HH
+144
View File
@@ -0,0 +1,144 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// Hep Random
// --- DualRand ---
// class header file
// -----------------------------------------------------------------------
//
// Canopy random number generator DualRand
// Re-written as C++ routine for 32-bit ints MF 1/26/98
//
// Exclusive or of a feedback shift register and integer congruence
// random number generator. The feedback shift register uses offsets
// 127 and 97. The integer congruence generator uses a different
// multiplier for each stream. The multipliers are chosen to give
// full period and maximum "potency" for modulo 2^32. The period of
// the combined random number generator is 2^159 - 2^32, and the
// sequences are different for each stream (not just started in a
// different place).
//
// =======================================================================
// Canopy random number generator DualRand.
// Doug Toussaint 5/25/88
// Optimized by GMH 7/26/88
// Optimized by GMH 7/26/88
// Repaired by GMH 12/1/88 to update modular congruence state
// Put into ranlib by GMH 6/23/89
// Re-written as C++ routine for 32-bit ints MF 1/26/98
// Re-written for CLHEP package KLS 6/04/98
// Removed std::pow() from flat method for speed KLS 7/21/98
// Ken Smith - Added conversion operators: 6th Aug 1998
// Mark Fischler methods for distrib. instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// Mark Fischler - methods for vector save/restore 3/7/05
// =======================================================================
#ifndef DualRand_h
#define DualRand_h
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class DualRand: public HepRandomEngine {
public:
DualRand();
DualRand(long seed);
DualRand(std::istream & is);
DualRand(int rowIndex, int colIndex);
virtual ~DualRand();
// let the compiler generate the copy constructors
//DualRand(const DualRand & p);
//DualRand & operator=(const DualRand & p);
double flat();
// Returns a pseudo random number between 0 and 1
// (excluding the end points)
void flatArray(const int size, double * vect);
// Fills an array "vect" of specified size with flat random values.
void setSeed(long seed, int);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, int);
// Sets the state of the algorithm according to the zero-terminated
// array of seeds.
void saveStatus( const char filename[] = "DualRand.conf") const;
// Saves on named file the current engine status.
void restoreStatus( const char filename[] = "DualRand.conf" );
// Reads from named file the last saved engine status and restores it.
void showStatus() const;
// Dumps the current engine status on the screen.
operator float(); // flat value, without worrying about filling bits
operator unsigned int(); // 32-bit flat value, quickest of all
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "DualRand";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 9;
private:
static int numEngines;
// This generator is composed of two others combined:
class Tausworthe {
public:
Tausworthe();
Tausworthe(unsigned int seed);
operator unsigned int();
void put(std::ostream & os) const;
void put(std::vector<unsigned long> & v) const;
void get(std::istream & is);
bool get(std::vector<unsigned long>::const_iterator & iv);
private:
int wordIndex;
unsigned int words[4];
}; // Tausworthe
class IntegerCong {
public:
IntegerCong();
IntegerCong(unsigned int seed, int streamNumber);
operator unsigned int();
void put(std::ostream & os) const;
void put(std::vector<unsigned long> & v) const;
void get(std::istream & is);
bool get(std::vector<unsigned long>::const_iterator & iv);
private:
unsigned int state, multiplier, addend;
}; // IntegerCong
Tausworthe tausworthe;
IntegerCong integerCong;
}; // DualRand
} // namespace CLHEP
#endif // DualRand_h
@@ -0,0 +1,32 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- EngineFactory ---
// class header file
// -----------------------------------------------------------------------
// Class generating new engines from streamed saves.
// =======================================================================
// M Fischler - Created: 12/21/04
// =======================================================================
#ifndef EngineFactory_h
#define EngineFactory_h 1
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
class EngineFactory {
public:
static HepRandomEngine* newEngine(std::istream & is);
static HepRandomEngine* newEngine(std::vector<unsigned long> const & v);
};
} // namespace CLHEP
#endif
@@ -0,0 +1,108 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepJamesRandom ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// HepJamesRandom implements the algorithm by Marsaglia-Zaman RANMAR
// described in "F.James, Comp. Phys. Comm. 60 (1990) 329" and implemented
// in FORTRAN77 as part of the MATHLIB HEP library for pseudo-random
// numbers generation.
// This is the default random engine invoked by each distribution unless
// the user sets a different one.
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Minor corrections: 31st October 1996
// - Added methods for engine status: 19th November 1996
// - setSeed(), setSeeds() now have default dummy argument
// set to zero: 11th July 1997
// J.Marraffino - Added stream operators and related constructor.
// Added automatic seed selection from seed table and
// engine counter: 16th Feb 1998
// Ken Smith - Added conversion operators: 6th Aug 1998
// V. Innocente - changed pointers to indices 3 may 2000
// Mark Fischler - Methods for distrib. instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef HepJamesRandom_h
#define HepJamesRandom_h 1
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class HepJamesRandom: public HepRandomEngine {
public:
HepJamesRandom(std::istream& is);
HepJamesRandom();
HepJamesRandom(long seed);
HepJamesRandom(int rowIndex, int colIndex);
virtual ~HepJamesRandom();
// Constructor and destructor.
double flat();
// Returns a pseudo random number between 0 and 1
// (excluding the end points)
void flatArray (const int size, double* vect);
// Fills the array "vect" of specified size with flat random values.
void setSeed(long seed, int dum=0);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, int dum=0);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. Only the first seed is used.
void saveStatus( const char filename[] = "JamesRand.conf" ) const;
// Saves on file JamesRand.conf the current engine status.
void restoreStatus( const char filename[] = "JamesRand.conf" );
// Reads from file JamesRand.conf the last saved engine status
// and restores it.
void showStatus() const;
// Dumps the engine status on the screen.
operator unsigned int();
// 32-bit flat, but slower than double or float.
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "HepJamesRandom";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 202;
private:
// Members defining the current status of the generator.
double u[97];
double c, cd, cm;
int i97, j97;
static int numEngines;
static int maxIndex;
};
} // namespace CLHEP
#endif
@@ -0,0 +1,98 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- MTwistEngine ---
// class header file
// -----------------------------------------------------------------------
// A "fast, compact, huge-period generator" based on M. Matsumoto and
// T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed
// uniform pseudorandom number generator", to appear in ACM Trans. on
// Modeling and Computer Simulation. It is a twisted GFSR generator
// with a Mersenne-prime period of 2^19937-1, uniform on open interval (0,1)
// For further information, see http://www.math.keio.ac.jp/~matumoto/emt.html
// =======================================================================
// Ken Smith - Started initial draft: 14th Jul 1998
// - Optimized to get std::pow() out of flat() method: 21st Jul
// - Added conversion operators: 6th Aug 1998
// M Fischler - Changes in way powers of two are kept: 16-Sep-1998
// Mark Fischler - Methods for distrib. instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef MTwistEngine_h
#define MTwistEngine_h
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class MTwistEngine : public HepRandomEngine {
public:
MTwistEngine();
MTwistEngine( long seed );
MTwistEngine( int rowIndex, int colIndex );
MTwistEngine( std::istream & is );
virtual ~MTwistEngine();
// Constructors and destructor.
double flat();
// Returns a pseudo random number between 0 and 1 (excluding the end points).
void flatArray(const int size, double* vect);
// Fills an array "vect" of specified size with flat random values.
void setSeed(long seed, int);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, int);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. It is allowed to ignore one or many seeds in this array.
void saveStatus( const char filename[] = "MTwist.conf") const;
// Saves the current engine status in the named file
void restoreStatus( const char filename[] = "MTwist.conf" );
// Reads from named file the the last saved engine status and restores it.
void showStatus() const;
// Dumps the current engine status on the screen.
operator float(); // returns flat, without worrying about filling bits
operator unsigned int(); // 32-bit flat, quickest of all
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "MTwistEngine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 626;
private:
unsigned int mt[624];
int count624;
enum{ NminusM = 227, M = 397, N = 624};
static int numEngines;
static int maxIndex;
}; // MTwistEngine
} // namespace CLHEP
#endif // MTwistEngine_h
@@ -0,0 +1,101 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- NonRandomEngine ---
// class header file
// -----------------------------------------------------------------------
// This class is present EXCLUSIVELY as a means to test distributions (and
// other programs that depend on random numbers) by feeding them a stream
// of "randoms" that the testing program supplies explicitly.
//
// The testing program calls setNextRandom (double) to setup the next
// value to be produced when flat() is done.
//
// To protect against accidental use of this NON-RANDOM engine as a random
// engine, if setNextRandom () is never called, all attempts to generate
// a random will fail and exit.
// =======================================================================
// Mark Fischler - Created: 9/30/99
// Mark Fischler methods for distrib. instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef NonRandomEngine_h
#define NonRandomEngine_h 1
#include "CLHEP/Random/RandomEngine.h"
#include <vector>
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class NonRandomEngine : public HepRandomEngine {
public:
NonRandomEngine();
virtual ~NonRandomEngine();
// Constructors and destructor
void setNextRandom (double r);
// Preset the next random to be delivered
void setRandomSequence (double *s, int n);
// Establish a sequence of n next randoms;
// replaces setNextRandom n times.
void setRandomInterval (double x);
// Establish that if there is no sequence active each
// random should be bumped by this interval (mod 1) compared
// to the last. x should be between 0 and 1.
double flat();
// It returns the previously established setNextRandom and bumps that up
// by the non-zero randomInterval supplied. Thus repeated calls to flat()
// generate an evenly spaced sequence (mod 1).
void flatArray (const int size, double* vect);
// Fills the array "vect" of specified size with flat random values.
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "NonRandomEngine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
private:
bool nextHasBeenSet;
bool sequenceHasBeenSet;
bool intervalHasBeenSet;
double nextRandom;
std::vector<double> sequence;
unsigned int nInSeq;
double randomInterval;
// The following are necessary to fill virtual methods but should never
// be used:
virtual void setSeed(long , int) {};
virtual void setSeeds(const long * , int) {};
virtual void saveStatus( const char * ) const {};
virtual void restoreStatus( const char * ) {};
virtual void showStatus() const {};
};
} // namespace CLHEP
#endif
@@ -0,0 +1,116 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBinomial ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods for shooting binomial distributed random values,
// given a sample size n (default=1) and a probability p (default=0.5).
// Default values are used for operator()().
//
// Valid input values satisfy the relation n*min(p,1-p) > 0. When invalid
// values are presented, the code silently returns -1.0.
// =======================================================================
// John Marraffino - Created: 12th May 1998 Based on the C-Rand package
// by Ernst Stadlober and Franz Niederl of the Technical
// University of Graz, Austria.
// Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandBinomial_h
#define RandBinomial_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandBinomial : public HepRandom {
public:
inline RandBinomial ( HepRandomEngine& anEngine, long n=1,
double p=0.5 );
inline RandBinomial ( HepRandomEngine* anEngine, long n=1,
double p=0.5 );
// These constructors should be used to instantiate a RandBinomial
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandBinomial destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandBinomial destructor.
virtual ~RandBinomial();
// Destructor
// Static methods to shoot random values using the static generator
static inline double shoot();
static double shoot( long n, double p );
static void shootArray ( const int size, double* vect,
long n=1, double p=0.5 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anEngine );
static double shoot( HepRandomEngine* anEngine,
long n, double p );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, long n=1,
double p=0.5 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
double fire( long n, double p );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
long n, double p );
inline double operator()();
inline double operator()( long n, double p );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandBinomial";}
// Provides the name of this distribution class
private:
static double genBinomial( HepRandomEngine *anEngine, long n, double p );
shared_ptr<HepRandomEngine> localEngine;
long defaultN;
double defaultP;
};
} // namespace CLHEP
#include "CLHEP/Random/RandBinomial.icc"
#endif
@@ -0,0 +1,46 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBinomial ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// Gabriele Cosmo - Created: 18th August 1998
// =======================================================================
namespace CLHEP {
inline RandBinomial::RandBinomial(HepRandomEngine & anEngine, long n,
double p )
: HepRandom ( ), localEngine( &anEngine, do_nothing_deleter() ),
defaultN(n), defaultP(p) {}
inline RandBinomial::RandBinomial(HepRandomEngine * anEngine, long n,
double p )
: HepRandom ( ), localEngine( anEngine),
defaultN(n), defaultP(p) {}
inline double RandBinomial::shoot() {
return shoot( 1, 0.5 );
}
inline double RandBinomial::shoot( HepRandomEngine* anEngine ) {
return shoot( anEngine, 1, 0.5 );
}
inline double RandBinomial::operator()() {
return fire( defaultN, defaultP );
}
inline double RandBinomial::operator()( long n, double p ) {
return fire( n, p );
}
inline double RandBinomial::fire() {
return fire( defaultN, defaultP );
}
} // namespace CLHEP
+111
View File
@@ -0,0 +1,111 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBit ---
// class header file
// -----------------------------------------------------------------------
//
// Class defining methods for shooting Flat or Bit random numbers, double or
// integers.
// It provides methods to fill with double flat values arrays of
// specified size, as well as methods for shooting sequences of 0,1 (bits).
// Default boundaries ]0.1[ for operator()().
// This is derived from RandFlat and is a drop-in replacement. However
// the shootBit() and fireBit() methods are stateless (which makes them
// an order of magnitude slower, but allows save/restore engine status
// to work correctly).
// =======================================================================
// M. Fischler - Created: 15th Feb 2000
// M Fischler - put and get to/from streams 12/10/04
// M Fischler - static save/restore to streams streams 12/20/04
// =======================================================================
#ifndef RandBit_h
#define RandBit_h 1
#include "CLHEP/Random/RandFlat.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandBit : public RandFlat {
public:
inline RandBit ( HepRandomEngine& anEngine );
inline RandBit ( HepRandomEngine& anEngine, double width );
inline RandBit ( HepRandomEngine& anEngine, double a, double b );
inline RandBit ( HepRandomEngine* anEngine );
inline RandBit ( HepRandomEngine* anEngine, double width );
inline RandBit ( HepRandomEngine* anEngine, double a, double b );
// These constructors should be used to instantiate a RandBit
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandBit destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandBit destructor.
virtual ~RandBit();
// Destructor
// Other than the Bit routines, constructors, and destructor, everything is
// simply inherited from RandFlat.
static inline int shootBit();
static inline int shootBit( HepRandomEngine* );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline int fireBit();
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
static std::string distributionName() {return "RandBit";}
// Provides the name of this distribution class
static std::ostream& saveFullState ( std::ostream & os )
// Saves to stream the state of the engine and cached data.
{return RandFlat::saveFullState(os);}
static std::istream& restoreFullState ( std::istream & is )
// Restores from stream the state of the engine and cached data.
{return RandFlat::restoreFullState(is);}
static std::ostream& saveDistState ( std::ostream & os )
// Saves to stream the state of the cached data.
{return RandFlat::saveDistState(os);}
static std::istream& restoreDistState ( std::istream & is )
// Restores from stream the state of the cached data.
{return RandFlat::restoreDistState(is);}
private:
// All the engine info, and the default A and B, are in the RandFlat
// base class.
};
} // namespace CLHEP
#include "CLHEP/Random/RandBit.icc"
#endif
+65
View File
@@ -0,0 +1,65 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBit ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// M.Fischler - Created, along same lines as RandGaussQ.icc
// =======================================================================
namespace CLHEP {
inline RandBit::RandBit(HepRandomEngine & anEngine)
: RandFlat (anEngine)
{}
inline RandBit::RandBit(HepRandomEngine & anEngine, double width )
: RandFlat (anEngine, width)
{}
inline RandBit::RandBit(HepRandomEngine & anEngine, double a,
double b )
: RandFlat (anEngine, a, b)
{}
inline RandBit::RandBit(HepRandomEngine * anEngine)
: RandFlat (anEngine)
{}
inline RandBit::RandBit(HepRandomEngine * anEngine, double width )
: RandFlat (anEngine, width)
{}
inline RandBit::RandBit(HepRandomEngine * anEngine, double a,
double b )
: RandFlat (anEngine, a, b)
{}
//---------------------
inline int RandBit::shootBit() {
double x = shoot();
return (x > .5) ? 1 : 0;
}
//---------------------
inline int RandBit::shootBit(HepRandomEngine* engine) {
double x = shoot(engine);
return (x > .5) ? 1 : 0;
}
//---------------------
inline int RandBit::fireBit() {
double x = fire(0,1);
return (x > .5) ? 1 : 0;
}
} // namespace CLHEP
@@ -0,0 +1,146 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBreitWigner ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// Class defining methods for shooting numbers according to the
// Breit-Wigner distribution algorithms (plain or mean^2).
// Default values are set: mean=1, gamma=.2, cut=1.
// Plain algorithm is used for shootArray() and fireArray().
// Plain algorithm with default values is used for operator()().
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Added methods to shoot arrays: 28th July 1997
// J.Marraffino - Added default arguments as attributes and
// operator() with arguments: 16th Feb 1998
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandBreitWigner_h
#define RandBreitWigner_h 1
#include "CLHEP/Random/RandFlat.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class RandBreitWigner : public HepRandom {
public:
inline RandBreitWigner ( HepRandomEngine& anEngine, double a=1.0,
double b=0.2 );
inline RandBreitWigner ( HepRandomEngine* anEngine, double a=1.0,
double b=0.2 );
// These constructors should be used to instantiate a RandBreitWigner
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandBreitWigner destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandBreitWigner destructor.
virtual ~RandBreitWigner();
// Destructor
// Static methods to shoot random values using the static generator
static double shoot( double a=1.0, double b=0.2 );
static double shoot( double a, double b, double c );
static double shootM2( double a=1.0, double b=0.2 );
static double shootM2( double a, double b, double c );
static void shootArray ( const int size, double* vect);
static void shootArray ( const int size, double* vect,
double a, double b );
static void shootArray ( const int size, double* vect,
double a, double b, double c );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static double shoot( HepRandomEngine* anEngine, double a=1.0,
double b=0.2 );
static double shoot( HepRandomEngine* anEngine, double a,
double b, double c );
static double shootM2( HepRandomEngine* anEngine, double a=1.0,
double b=0.2 );
static double shootM2( HepRandomEngine* anEngine, double a,
double b, double c );
static void shootArray ( HepRandomEngine* anEngine,
const int size, double* vect );
static void shootArray ( HepRandomEngine* anEngine,
const int size, double* vect,
double a, double b );
static void shootArray ( HepRandomEngine* anEngine,
const int size, double* vect,
double a, double b, double c );
// Methods using the localEngine to shoot random values, by-passing
// the static generator. These methods respect distribution parameters
// passed by the user at instantiation unless superseded by actual
// arguments in the call.
double fire();
double fire( double a, double b );
double fire( double a, double b, double c );
double fireM2();
double fireM2( double a, double b );
double fireM2( double a, double b, double c );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
double a, double b );
void fireArray ( const int size, double* vect,
double a, double b, double c );
double operator()();
double operator()( double a, double b );
double operator()( double a, double b, double c );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandBreitWigner";}
// Provides the name of this distribution class
private:
shared_ptr<HepRandomEngine> localEngine;
double defaultA;
double defaultB;
};
} // namespace CLHEP
#include "CLHEP/Random/RandBreitWigner.icc"
#endif
@@ -0,0 +1,27 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandBreitWigner ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandBreitWigner::RandBreitWigner(HepRandomEngine & anEngine,
double a, double b )
: HepRandom( ), localEngine(&anEngine, do_nothing_deleter()), defaultA(a),
defaultB(b) {}
inline RandBreitWigner::RandBreitWigner(HepRandomEngine * anEngine,
double a, double b )
: HepRandom( ), localEngine(anEngine), defaultA(a),
defaultB(b) {}
} // namespace CLHEP
@@ -0,0 +1,112 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandChiSquare ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods for shooting Chi^2 distributed random values,
// given a number of degrees of freedom a (default=1.0).
// Default values are used for operator()().
// Valid values of a satisfy a > 1. When invalid values are presented,
// the code silently returns -1.0.
// =======================================================================
// John Marraffino - Created: 12th May 1998 Based on the C-Rand package
// by Ernst Stadlober and Franz Niederl of the Technical
// University of Graz, Austria.
// Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandChiSquare_h
#define RandChiSquare_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandChiSquare : public HepRandom {
public:
inline RandChiSquare ( HepRandomEngine& anEngine, double a=1 );
inline RandChiSquare ( HepRandomEngine* anEngine, double a=1 );
// These constructors should be used to instantiate a RandChiSquare
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandChiSquare destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandChiSquare destructor.
virtual ~RandChiSquare();
// Destructor
// Static methods to shoot random values using the static generator
static inline double shoot();
static double shoot( double a );
static void shootArray ( const int size, double* vect,
double a=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anEngine );
static double shoot( HepRandomEngine* anEngine,
double a );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, double a=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
double fire( double a );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
double a );
inline double operator()();
inline double operator()( double a );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandChiSquare";}
// Provides the name of this distribution class
private:
static double genChiSquare( HepRandomEngine *anEngine, double a );
shared_ptr<HepRandomEngine> localEngine;
double defaultA;
};
} // namespace CLHEP
#include "CLHEP/Random/RandChiSquare.icc"
#endif
@@ -0,0 +1,44 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandChiSquare ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandChiSquare::RandChiSquare(HepRandomEngine & anEngine, double a)
: HepRandom( ), localEngine(&anEngine, do_nothing_deleter()), defaultA(a)
{}
inline RandChiSquare::RandChiSquare(HepRandomEngine * anEngine, double a)
: HepRandom( ), localEngine(anEngine), defaultA(a)
{}
inline double RandChiSquare::fire() {
return fire( defaultA );
}
inline double RandChiSquare::shoot() {
return shoot( 1.0 );
}
inline double RandChiSquare::operator()() {
return fire( defaultA );
}
inline double RandChiSquare::operator()( double a ) {
return fire( a );
}
inline double RandChiSquare::shoot( HepRandomEngine* anEngine ) {
return shoot( anEngine, 1.0 );
}
} // namespace CLHEP
@@ -0,0 +1,107 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandExponential ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// Class defining methods for shooting exponential distributed random
// values, given a mean (default mean = 1).
// Default mean is used for operator()().
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Added methods to shoot arrays: 28th July 1997
// J.Marraffino - Added default mean as attribute and
// operator() with mean: 16th Feb 1998
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandExponential_h
#define RandExponential_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class RandExponential : public HepRandom {
public:
inline RandExponential ( HepRandomEngine& anEngine, double mean=1.0 );
inline RandExponential ( HepRandomEngine* anEngine, double mean=1.0 );
// These constructors should be used to instantiate a RandExponential
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandExponential destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandExponential destructor.
virtual ~RandExponential();
// Destructor
// Static methods to shoot random values using the static generator
static double shoot();
static double shoot( double mean );
static void shootArray ( const int size, double* vect,
double mean=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anEngine );
static inline double shoot( HepRandomEngine* anEngine, double mean );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, double mean=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
inline double fire( double mean );
void fireArray ( const int size, double* vect );
void fireArray ( const int size, double* vect, double mean );
double operator()();
double operator()( double mean );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandExponential";}
// Provides the name of this distribution class
private:
shared_ptr<HepRandomEngine> localEngine;
double defaultMean;
};
} // namespace CLHEP
#include "CLHEP/Random/RandExponential.icc"
#endif
@@ -0,0 +1,48 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandExponential ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
#include <cmath> // for std::log()
namespace CLHEP {
inline RandExponential::RandExponential(HepRandomEngine & anEngine,
double mean )
: HepRandom(), localEngine(&anEngine, do_nothing_deleter()), defaultMean(mean) {}
inline RandExponential::RandExponential(HepRandomEngine * anEngine,
double mean )
: HepRandom(), localEngine(anEngine), defaultMean(mean) {}
//-------------
inline double RandExponential::shoot(HepRandomEngine* anEngine) {
return -std::log(anEngine->flat());
}
inline double RandExponential::shoot(HepRandomEngine* anEngine,
double mean) {
return -std::log(anEngine->flat())*mean;
}
//-------------
inline double RandExponential::fire() {
return -std::log(localEngine->flat())*defaultMean;
}
inline double RandExponential::fire(double mean) {
return -std::log(localEngine->flat())*mean;
}
} // namespace CLHEP
+210
View File
@@ -0,0 +1,210 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandFlat ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// Class defining methods for shooting flat random numbers, double or
// integers.
// It provides methods to fill with double flat values arrays of
// specified size, as well as methods for shooting sequences of 0,1 (bits).
// Default boundaries ]0.1[ for operator()().
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
// Gabriele Cosmo - Added operator() and additional methods to fill
// arrays specifying boundaries: 24th Jul 1997
// J.Marraffino - Added default arguments as attributes and
// operator() with arguments: 16th Feb 1998
// M. Fischler - Moved copy constructor to protected so that
// derived RandBit can get at it.
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandFlat_h
#define RandFlat_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class RandFlat : public HepRandom {
public:
inline RandFlat ( HepRandomEngine& anEngine );
inline RandFlat ( HepRandomEngine& anEngine, double width );
inline RandFlat ( HepRandomEngine& anEngine, double a, double b );
inline RandFlat ( HepRandomEngine* anEngine );
inline RandFlat ( HepRandomEngine* anEngine, double width );
inline RandFlat ( HepRandomEngine* anEngine, double a, double b );
// These constructors should be used to instantiate a RandFlat
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandFlat destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandFlat destructor.
virtual ~RandFlat();
// Destructor
// Static methods to shoot random values using the static generator
static double shoot();
static inline double shoot( double width );
static inline double shoot( double a, double b );
static inline long shootInt( long n );
static inline long shootInt( long m, long n );
static inline int shootBit();
static void shootArray ( const int size, double* vect );
static void shootArray ( const int size, double* vect,
double lx, double dx );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot ( HepRandomEngine* anEngine );
static inline double shoot( HepRandomEngine* anEngine, double width );
static inline double shoot( HepRandomEngine* anEngine,
double a, double b );
static inline long shootInt( HepRandomEngine* anEngine, long n );
static inline long shootInt( HepRandomEngine* anEngine, long m, long n );
static inline int shootBit( HepRandomEngine* );
static inline void shootArray ( HepRandomEngine* anEngine,
const int size, double* vect );
static void shootArray ( HepRandomEngine* anEngine,
const int size, double* vect,
double lx, double dx );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
inline double fire( double width );
inline double fire( double a, double b );
inline long fireInt( long n );
inline long fireInt( long m, long n );
inline int fireBit();
void fireArray (const int size, double* vect);
void fireArray (const int size, double* vect,
double lx, double dx);
double operator()();
double operator()( double width );
double operator()( double a, double b );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandFlat";}
// Provides the name of this distribution class
// Methods overriding the base class static saveEngineStatus ones,
// by adding extra data so that save in one program, then further shootBit()s
// will produce the identical sequence to restore in another program, then
// generating shootBit() randoms there
static void saveEngineStatus( const char filename[] = "Config.conf" );
// Saves to file the current status of the current engine.
static void restoreEngineStatus( const char filename[] = "Config.conf" );
// Restores a saved status (if any) for the current engine.
static std::ostream& saveFullState ( std::ostream & os );
// Saves to stream the state of the engine and cached data.
static std::istream& restoreFullState ( std::istream & is );
// Restores from stream the state of the engine and cached data.
static std::ostream& saveDistState ( std::ostream & os );
// Saves to stream the state of the cached data.
static std::istream& restoreDistState ( std::istream & is );
// Restores from stream the state of the cached data.
protected:
#if 0
// Protected copy constructor. Defining it here disallows use by users.
RandFlat(const RandFlat& d);
#endif // 0
private:
// ShootBits generates an integer random number,
// which is used by fireBit().
// The number is stored in randomInt and firstUnusedBit
inline void fireBits();
static inline void shootBits();
static inline void shootBits(HepRandomEngine*);
// In MSB, the most significant bit of the integer random number
// generated by ShootBits() is set.
// Note:
// the number of significant bits must be chosen so that
// - an unsigned long can hold it
// - and it should be less than the number of bits returned
// by Shoot() which are not affected by precision problems
// on _each_ architecture.
// (Aim: the random generators should be machine-independent).
static const unsigned long MSB;
static const int MSBBits;
// These two are set up in RandFlat.cc and need not be saved/restored
unsigned long randomInt;
unsigned long firstUnusedBit;
static unsigned long staticRandomInt;
static unsigned long staticFirstUnusedBit;
shared_ptr<HepRandomEngine> localEngine;
double defaultWidth;
double defaultA;
double defaultB;
};
} // namespace CLHEP
#include "CLHEP/Random/RandFlat.icc"
#endif
+162
View File
@@ -0,0 +1,162 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandFlat ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// Peter Urban - ShootBit() and related stuff added: 5th Sep 1996
// Gabriele Cosmo - Additional methods to fill arrays specifying
// boundaries: 24th Jul 1997
// - Fixed bug in shootInt(m,n): 25th Sep 1997
// J.Marraffino - Added default arguments as attributes: 16th Feb 1998
// M.Fischler - Corrected initialization of deleteEngine which should
// be true for all constructors taking HepRandomEngine*.
// =======================================================================
namespace CLHEP {
inline RandFlat::RandFlat(HepRandomEngine & anEngine)
: HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
inline RandFlat::RandFlat(HepRandomEngine & anEngine, double width )
: HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
defaultWidth(width), defaultA(0.0), defaultB(width) {}
inline RandFlat::RandFlat(HepRandomEngine & anEngine, double a,
double b )
: HepRandom(), firstUnusedBit(0), localEngine(&anEngine, do_nothing_deleter()),
defaultWidth(b-a), defaultA(a), defaultB(b) {}
inline RandFlat::RandFlat(HepRandomEngine * anEngine)
: HepRandom(), firstUnusedBit(0), localEngine(anEngine),
defaultWidth(1.0), defaultA(0.0), defaultB(1.0) {}
inline RandFlat::RandFlat(HepRandomEngine * anEngine, double width )
: HepRandom(), firstUnusedBit(0), localEngine(anEngine),
defaultWidth(width), defaultA(0.0), defaultB(width) {}
inline RandFlat::RandFlat(HepRandomEngine * anEngine, double a,
double b )
: HepRandom(), firstUnusedBit(0), localEngine(anEngine),
defaultWidth(b-a), defaultA(a), defaultB(b) {}
inline double RandFlat::shoot(double a, double b) {
return (b-a)* shoot() + a;
}
inline double RandFlat::shoot(double width) {
return width * shoot();
}
inline long RandFlat::shootInt(long n) {
return long(shoot()*double(n));
}
inline long RandFlat::shootInt(long m, long n) {
return long(shoot()*double(n-m)) + m;
}
inline void RandFlat::shootBits() {
const double factor= 2.0*MSB; // this should fit into a double!
staticFirstUnusedBit= MSB;
staticRandomInt= (unsigned long)(factor*shoot());
}
inline int RandFlat::shootBit() {
if (staticFirstUnusedBit==0)
shootBits();
unsigned long temp= staticFirstUnusedBit&staticRandomInt;
staticFirstUnusedBit>>= 1;
return temp!=0;
}
//---------------------
inline double RandFlat::shoot(HepRandomEngine* anEngine) {
return anEngine->flat();
}
inline double RandFlat::shoot(HepRandomEngine* anEngine,
double a, double b) {
return (b-a)* anEngine->flat() + a;
}
inline double RandFlat::shoot(HepRandomEngine* anEngine,
double width) {
return width * anEngine->flat();
}
inline long RandFlat::shootInt(HepRandomEngine* anEngine,
long n) {
return long(anEngine->flat()*double(n));
}
inline long RandFlat::shootInt(HepRandomEngine* anEngine,
long m, long n) {
return long(double(n-m)*anEngine->flat()) + m;
}
inline void RandFlat::shootArray(HepRandomEngine* anEngine,
const int size, double* vect) {
anEngine->flatArray(size,vect);
}
inline void RandFlat::shootBits(HepRandomEngine* engine) {
const double factor= 2.0*MSB; // this should fit into a double!
staticFirstUnusedBit= MSB;
staticRandomInt= (unsigned long)(factor*shoot(engine));
}
inline int RandFlat::shootBit(HepRandomEngine* engine) {
if (staticFirstUnusedBit==0)
shootBits(engine);
unsigned long temp= staticFirstUnusedBit&staticRandomInt;
staticFirstUnusedBit>>= 1;
return temp!=0;
}
//---------------------
inline double RandFlat::fire() {
return (defaultB-defaultA)*localEngine->flat()+defaultA;
}
inline double RandFlat::fire(double a, double b) {
return (b-a)* localEngine->flat() + a;
}
inline double RandFlat::fire(double width) {
return width * localEngine->flat();
}
inline long RandFlat::fireInt(long n) {
return long(localEngine->flat()*double(n));
}
inline long RandFlat::fireInt(long m, long n) {
return long(localEngine->flat()*double(n-m)) + m;
}
inline void RandFlat::fireBits() {
const double factor= 2.0*MSB; // this should fit into a double!
firstUnusedBit= MSB;
randomInt= (unsigned long)(factor*localEngine->flat());
}
inline int RandFlat::fireBit() {
if (firstUnusedBit==0)
fireBits();
unsigned long temp= firstUnusedBit&randomInt;
firstUnusedBit>>= 1;
return temp!=0;
}
} // namespace CLHEP
+118
View File
@@ -0,0 +1,118 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGamma ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods for shooting gamma distributed random values,
// given a k (default=1) and specifying also a lambda (default=1).
// Default values are used for operator()().
// Valid input values are k > 0 and lambda > 0. When invalid values are
// presented, the code silently returns -1.0.
// =======================================================================
// John Marraffino - Created: 12th May 1998 Based on the C-Rand package
// by Ernst Stadlober and Franz Niederl of the Technical
// University of Graz, Austria.
// Gabriele Cosmo - Removed useless methods and data: 5th Jan 1999
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandGamma_h
#define RandGamma_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandGamma : public HepRandom {
public:
inline RandGamma ( HepRandomEngine& anEngine, double k=1.0,
double lambda=1.0 );
inline RandGamma ( HepRandomEngine* anEngine, double k=1.0,
double lambda=1.0 );
// These constructors should be used to instantiate a RandGamma
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandGamma destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandGamma destructor.
virtual ~RandGamma();
// Destructor
// Static methods to shoot random values using the static generator
static inline double shoot();
static double shoot( double k, double lambda );
static void shootArray ( const int size, double* vect,
double k=1.0, double lambda=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anEngine );
static double shoot( HepRandomEngine* anEngine,
double k, double lambda );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, double k=1.0,
double lambda=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
double fire( double k, double lambda );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
double k, double lambda );
inline double operator()();
inline double operator()( double k, double lambda );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandGamma";}
// Provides the name of this distribution class
private:
static double genGamma( HepRandomEngine *anEngine, double k,
double lambda );
shared_ptr<HepRandomEngine> localEngine;
double defaultK;
double defaultLambda;
};
} // namespace CLHEP
#include "CLHEP/Random/RandGamma.icc"
#endif
@@ -0,0 +1,46 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGamma ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandGamma::RandGamma(HepRandomEngine & anEngine, double k,
double lambda )
: HepRandom(), localEngine(&anEngine, do_nothing_deleter()),
defaultK(k), defaultLambda(lambda) {}
inline RandGamma::RandGamma(HepRandomEngine * anEngine, double k,
double lambda )
: HepRandom(), localEngine(anEngine),
defaultK(k), defaultLambda(lambda) {}
inline double RandGamma::shoot() {
return shoot( 1.0, 1.0 );
}
inline double RandGamma::shoot( HepRandomEngine* anEngine ) {
return shoot( anEngine, 1.0, 1.0 );
}
inline double RandGamma::operator()() {
return fire( defaultK, defaultLambda );
}
inline double RandGamma::operator()( double k, double lambda ) {
return fire( k, lambda );
}
inline double RandGamma::fire() {
return fire( defaultK, defaultLambda );
}
} // namespace CLHEP
+171
View File
@@ -0,0 +1,171 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGauss ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// Class defining methods for shooting gaussian distributed random values,
// given a mean (default=0) or specifying also a deviation (default=1).
// Gaussian random numbers are generated two at the time, so every
// other time shoot is called the number returned is the one generated the
// time before.
// Default values are used for operator()().
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Minor corrections: 31st October 1996
// - Added methods to shoot arrays: 28th July 1997
// J.Marraffino - Added default arguments as attributes and
// operator() with arguments. Introduced method normal()
// for computation in fire(): 16th Feb 1998
// Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
// M Fischler - put and get to/from streams 12/8/04
// =======================================================================
#ifndef RandGauss_h
#define RandGauss_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandGauss : public HepRandom {
public:
inline RandGauss ( HepRandomEngine& anEngine, double mean=0.0,
double stdDev=1.0 );
inline RandGauss ( HepRandomEngine* anEngine, double mean=0.0,
double stdDev=1.0 );
// These constructors should be used to instantiate a RandGauss
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandGauss destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandGauss destructor.
virtual ~RandGauss();
// Destructor
// Static methods to shoot random values using the static generator
static double shoot();
static inline double shoot( double mean, double stdDev );
static void shootArray ( const int size, double* vect,
double mean=0.0, double stdDev=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static double shoot( HepRandomEngine* anEngine );
static inline double shoot( HepRandomEngine* anEngine,
double mean, double stdDev );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, double mean=0.0,
double stdDev=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
double fire();
inline double fire( double mean, double stdDev );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
double mean, double stdDev );
virtual double operator()();
virtual double operator()( double mean, double stdDev );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandGauss";}
// Provides the name of this distribution class
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
// Methods setFlag(false) and setF(false) if invoked in the client
// code before shoot/fire will force generation of a new couple of
// values.
static bool getFlag() {return set_st;}
static void setFlag( bool val ) {set_st = val;}
bool getF() const {return set;}
void setF( bool val ) {set = val;}
// Methods overriding the base class static saveEngineStatus ones,
// by adding extra data so that save in one program, then further gaussians,
// will produce the identical sequence to restore in another program, then
// generating gaussian randoms there
static void saveEngineStatus( const char filename[] = "Config.conf" );
// Saves to file the current status of the current engine.
static void restoreEngineStatus( const char filename[] = "Config.conf" );
// Restores a saved status (if any) for the current engine.
static std::ostream& saveFullState ( std::ostream & os );
// Saves to stream the state of the engine and cached data.
static std::istream& restoreFullState ( std::istream & is );
// Restores from stream the state of the engine and cached data.
static std::ostream& saveDistState ( std::ostream & os );
// Saves to stream the state of the cached data.
static std::istream& restoreDistState ( std::istream & is );
// Restores from stream the state of the cached data.
protected:
static double getVal() {return nextGauss_st;}
static void setVal( double nextVal ) {nextGauss_st = nextVal;}
double normal();
double defaultMean;
double defaultStdDev;
shared_ptr<HepRandomEngine> localEngine;
private:
bool set;
double nextGauss;
// static data
static bool set_st;
static double nextGauss_st;
};
} // namespace CLHEP
#include "CLHEP/Random/RandGauss.icc"
#endif
@@ -0,0 +1,44 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGauss ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandGauss::RandGauss(HepRandomEngine & anEngine, double mean,
double stdDev )
: HepRandom(), defaultMean(mean), defaultStdDev(stdDev),
localEngine(&anEngine, do_nothing_deleter()), set(false), nextGauss(0.0){}
inline RandGauss::RandGauss(HepRandomEngine * anEngine, double mean,
double stdDev )
: HepRandom(), defaultMean(mean), defaultStdDev(stdDev),
localEngine(anEngine), set(false), nextGauss(0.0) {}
inline double RandGauss::shoot(double mean, double stdDev) {
return shoot()*stdDev + mean;
}
inline double RandGauss::shoot(HepRandomEngine* anEngine,
double mean, double stdDev) {
return shoot(anEngine)*stdDev + mean;
}
inline double RandGauss::fire() {
return normal()*defaultStdDev + defaultMean;
}
inline double RandGauss::fire(double mean, double stdDev) {
return normal()*stdDev + mean;
}
} // namespace CLHEP
+123
View File
@@ -0,0 +1,123 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGaussQ ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods RandGaussQ, which is derived from RandGauss.
// The user interface is identical; but RandGaussQ is faster and a bit less
// accurate.
// =======================================================================
// M. Fischler - Created: 24th Jan 2000
// M Fischler - put and get to/from streams 12/10/04
//
// =======================================================================
#ifndef RandGaussQ_h
#define RandGaussQ_h 1
#include "CLHEP/Random/RandGauss.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandGaussQ : public RandGauss {
public:
inline RandGaussQ ( HepRandomEngine& anEngine, double mean=0.0,
double stdDev=1.0 );
inline RandGaussQ ( HepRandomEngine* anEngine, double mean=0.0,
double stdDev=1.0 );
// These constructors should be used to instantiate a RandGaussQ
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandGaussQ destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandGaussQ destructor.
// Destructor
virtual ~RandGaussQ();
//
// Methods to generate Gaussian-distributed random deviates:
//
// If a fast good engine takes 1 usec, RandGauss::fire() adds 1 usec while
// RandGaussQ::fire() adds only .4 usec.
//
// Static methods to shoot random values using the static generator
static inline double shoot();
static inline double shoot( double mean, double stdDev );
static void shootArray ( const int size, double* vect,
double mean=0.0, double stdDev=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anotherEngine );
static inline double shoot( HepRandomEngine* anotherEngine,
double mean, double stdDev );
static void shootArray ( HepRandomEngine* anotherEngine,
const int size,
double* vect, double mean=0.0,
double stdDev=1.0 );
// Instance methods using the localEngine to instead of the static
// generator, and the default mean and stdDev established at construction
inline double fire();
inline double fire ( double mean, double stdDev );
void fireArray ( const int size, double* vect);
void fireArray ( const int size, double* vect,
double mean, double stdDev );
virtual double operator()();
virtual double operator()( double mean, double stdDev );
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandGaussQ";}
// Provides the name of this distribution class
protected:
static double transformQuick (double r);
static double transformSmall (double r);
private:
// All the engine info, and the default mean and sigma, are in the RandGauss
// base class.
};
} // namespace CLHEP
#include "CLHEP/Random/RandGaussQ.icc"
#endif
@@ -0,0 +1,66 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGaussQ ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// M. Fischler - Created: 24 Janm 2000
//
// M. Fischler - Modified fire() to use local engine, not getTheEngine()
// 12/13/04
// =======================================================================
// Constructors
// ------------
namespace CLHEP {
RandGaussQ::RandGaussQ(HepRandomEngine & anEngine, double mean,
double stdDev )
: RandGauss(anEngine, mean, stdDev) {}
RandGaussQ::RandGaussQ(HepRandomEngine * anEngine, double mean,
double stdDev )
: RandGauss(anEngine, mean, stdDev) {}
// Getting a Gaussian deviate - static methods
// -------------------------------------------
double RandGaussQ::shoot()
{
HepRandomEngine* anEngine = HepRandom::getTheEngine();
return transformQuick (anEngine->flat());
}
double RandGaussQ::shoot( HepRandomEngine* anotherEngine )
{
return transformQuick (anotherEngine->flat());
}
double RandGaussQ::shoot(double mean, double stdDev) {
return shoot()*stdDev + mean;
}
double RandGaussQ::shoot(HepRandomEngine* anotherEngine,
double mean, double stdDev) {
return shoot(anotherEngine)*stdDev + mean;
}
// Getting a Gaussian deviate - instance methods
// ---------------------------------------------
double RandGaussQ::fire() {
return transformQuick(localEngine->flat()) * defaultStdDev + defaultMean;
}
double RandGaussQ::fire(double mean, double stdDev) {
return transformQuick(localEngine->flat()) * stdDev + mean;
}
} // namespace CLHEP
@@ -0,0 +1,148 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGeneral ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods for shooting generally distributed random values,
// given a user-defined probability distribution function.
// =======================================================================
// S.Magni & G.Pieri - Created: 29 April 1998
// G.Cosmo - Added constructor using default engine from the
// static generator: 20 Aug 1998
// S.Magni & G.Pieri - Added linear interpolation: 24 March 1999
// M. Fischler - Added private methods that simplify the implementaion
// prepareTables(), useFlatDistribution(), mapRandom()
// - Added private variable oneOverNbins.
// - Made the warning about shoot() not being static a tad
// more prominent. 14 May 1999
// M Fischler - put and get to/from streams 12/15/04
// =======================================================================
#ifndef RandGeneral_h
#define RandGeneral_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
#include <vector>
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandGeneral : public HepRandom {
public:
RandGeneral ( const double* aProbFunc,
int theProbSize,
int IntType=0 );
RandGeneral ( HepRandomEngine& anEngine,
const double* aProbFunc,
int theProbSize,
int IntType=0 );
RandGeneral ( HepRandomEngine* anEngine,
const double* aProbFunc,
int theProbSize,
int IntType=0 );
// These constructors should be used to instantiate a RandGeneral
// distribution object defining a local engine for it.
// The static generator will be skipped by using the non-static methods
// defined below. In case no engine is specified in the constructor, the
// default engine used by the static generator is applied.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandGeneral destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandGeneral destructor.
// The probability distribution function (Pdf) must be provided by the user
// as an array of positive real number. The array size must also be
// provided. The Pdf doesn't need to be normalized to 1.
// if IntType = 0 ( default value ) a uniform random number is
// generated using the engine. The uniform number is then transformed
// to the user's distribution using the cumulative probability
// distribution constructed from his histogram. The cumulative
// distribution is inverted using a binary search for the nearest
// bin boundary and a linear interpolation within the
// bin. RandGeneral therefore generates a constant density within
// each bin.
// if IntType = 1 no interpolation is performed and the result is a
// discrete distribution.
virtual ~RandGeneral();
// Destructor
// Methods to shoot random values using the static generator
// N.B.: The methods are NOT static since they use nonstatic members
// theIntegralPdf & nBins
/////////////////////
// //
// BIG RED WARNING //
// //
/////////////////////
//
// The above N.B. is telling users that the shoot() methods in this
// class are NOT STATIC. You cannot do
// double x = RandGeneral::shoot();
// It would not make sense to provide a static shoot -- what would
// the default probability function look like?
inline double shoot();
inline void shootArray ( const int size, double* vect);
// Methods to shoot random values using a given engine
// by-passing the static generator.
double shoot( HepRandomEngine* anEngine );
void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
double fire();
void fireArray ( const int size, double* vect);
double operator()();
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandGeneral";}
// Provides the name of this distribution class
private:
shared_ptr<HepRandomEngine> localEngine;
std::vector<double> theIntegralPdf;
int nBins;
double oneOverNbins;
int InterpolationType;
// Private methods to factor out replicated implementation sections
void prepareTable(const double* aProbFunc);
void useFlatDistribution();
double mapRandom(double rand) const;
};
} // namespace CLHEP
#include "CLHEP/Random/RandGeneral.icc"
#endif
@@ -0,0 +1,46 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandGeneral ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// Gabriele Cosmo - Created: 20th August 1998
//
// M. Fischler - Moved fire() and shoot(anEngine) into inline so that
// the use of mapRandom does not cost an extra function call.
// =======================================================================
namespace CLHEP {
inline double RandGeneral::fire()
{
double rand = localEngine->flat();
return mapRandom(rand);
}
inline double RandGeneral::shoot()
{
return fire();
}
inline double RandGeneral::operator() ()
{
return fire();
}
inline double RandGeneral::shoot( HepRandomEngine* anEngine )
{
double rand = anEngine->flat();
return mapRandom(rand);
}
inline void RandGeneral::shootArray( const int size, double* vect )
{
fireArray(size, vect);
}
} // namespace CLHEP
+118
View File
@@ -0,0 +1,118 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandLandau ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// Class defining methods for shooting or firing Landau distributed
// random values.
//
// The Landau distribution is parameterless and describes the fluctuations
// in energy loss of a particle, making certain assumptions. For
// definitions and algorithms, the following papers could be read:
//
// Landau, Jour Phys VIII, No. 4, p. 201 (1944)
// Borsh-Supan, Jour Res. of NBS 65B NO. 4 p. 245 (1961)
// Kolbig & Schorr Comp Phys Comm 31 p. 97 (1984)
//
// The algorithm implemented comes form RANLAN in CERNLIB.
// =======================================================================
// M. Fischler - Created: 5th January 2000
// M Fischler - put and get to/from streams 12/10/04
//
// =======================================================================
#ifndef RandLandau_h
#define RandLandau_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandLandau : public HepRandom {
public:
inline RandLandau ( HepRandomEngine& anEngine );
inline RandLandau ( HepRandomEngine* anEngine );
// These constructors should be used to instantiate a RandLandau
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandLandau destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandLandau destructor.
virtual ~RandLandau();
// Destructor
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
//
// Methods to generate Landau-distributed random deviates.
//
// These deviates are accurate to the actual Landau distribution to
// one part in 10**5 or better.
// Static methods to shoot random values using the static generator
static inline double shoot();
static void shootArray ( const int size, double* vect );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anotherEngine );
static void shootArray ( HepRandomEngine* anotherEngine,
const int size,
double* vect );
// Instance methods using the localEngine to instead of the static
// generator, and the default mean and stdDev established at construction
inline double fire();
void fireArray ( const int size, double* vect);
inline double operator()();
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandLandau";}
// Provides the name of this distribution class
protected:
static double transform (double r);
static double transformSmall (double r);
private:
shared_ptr<HepRandomEngine> localEngine;
};
} // namespace CLHEP
#include "CLHEP/Random/RandLandau.icc"
#endif
@@ -0,0 +1,55 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandLandau ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// M Fischler - Added some inline methods that had been in the .cc file,
// which are shells for calls to transform(r): 30 Sep 1999
// =======================================================================
// Constructors
// ------------
namespace CLHEP {
RandLandau::RandLandau(HepRandomEngine & anEngine )
: HepRandom(), localEngine(&anEngine, do_nothing_deleter())
{}
RandLandau::RandLandau(HepRandomEngine * anEngine )
: HepRandom(), localEngine(anEngine)
{}
// Getting a Landau deviate - static methods
// -------------------------------------------
double RandLandau::shoot()
{
HepRandomEngine* anEngine = HepRandom::getTheEngine();
return transform (anEngine->flat());
}
double RandLandau::shoot( HepRandomEngine* anotherEngine )
{
return transform (anotherEngine->flat());
}
// Getting a Landau deviate - instance methods
// ---------------------------------------------
double RandLandau::fire() {
return transform(localEngine->flat());
}
double RandLandau::operator()() {
return transform(localEngine->flat());
}
} // namespace CLHEP
@@ -0,0 +1,131 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandPoisson ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// Class defining methods for shooting numbers according to the Poisson
// distribution, given a mean (Algorithm taken from "W.H.Press et al.,
// Numerical Recipes in C, Second Edition".
// Default mean value is set to 1, value used for operator()().
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Added not static Shoot() method: 17th May 1996
// - Algorithm now operates on doubles : 31st Oct 1996
// - Added methods to shoot arrays: 28th July 1997
// J.Marraffino - Added default mean as attribute and
// operator() with mean: 16th Feb 1998
// Gabriele Cosmo - Relocated static data from HepRandom: 5th Jan 1999
// M. Fischler - Moved meanMax and defaultMean from private to protected
// to accomodate derived classes RandPoissonQ & RandPoissonT
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandPoisson_h
#define RandPoisson_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandPoisson : public HepRandom {
public:
inline RandPoisson ( HepRandomEngine& anEngine, double m=1.0 );
inline RandPoisson ( HepRandomEngine* anEngine, double m=1.0 );
// These constructors should be used to instantiate a RandPoisson
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandPoisson destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandPoisson destructor.
virtual ~RandPoisson();
// Destructor
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
// Static methods to shoot random values using the static generator
static long shoot( double m=1.0 );
static void shootArray ( const int size, long* vect, double m=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static long shoot( HepRandomEngine* anEngine, double m=1.0 );
static void shootArray ( HepRandomEngine* anEngine,
const int size, long* vect, double m=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
long fire();
long fire( double m );
void fireArray ( const int size, long* vect );
void fireArray ( const int size, long* vect, double m);
double operator()();
double operator()( double m );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandPoisson";}
// Provides the name of this distribution class
protected:
double meanMax;
double defaultMean;
static double getOldMean() {return oldm_st;}
static double getMaxMean() {return meanMax_st;}
static void setOldMean( double val ){oldm_st = val;}
static double* getPStatus() {return status_st;}
static void setPStatus(double sq, double alxm, double g) {
status_st[0] = sq; status_st[1] = alxm; status_st[2] = g;
}
inline HepRandomEngine* getLocalEngine();
private:
shared_ptr<HepRandomEngine> localEngine;
double status[3], oldm;
// static data
static double status_st[3];
static double oldm_st;
static const double meanMax_st;
};
} // namespace CLHEP
#include "CLHEP/Random/RandPoisson.icc"
#endif
@@ -0,0 +1,33 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandPoisson ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandPoisson::RandPoisson(HepRandomEngine & anEngine, double m )
: HepRandom(), meanMax(2.0E9), defaultMean(m),
localEngine(&anEngine, do_nothing_deleter()), oldm(-1.0) {
status[0] = status[1] = status[2] = 0.;
}
inline RandPoisson::RandPoisson(HepRandomEngine * anEngine, double m )
: HepRandom(), meanMax(2.0E9), defaultMean(m),
localEngine(anEngine), oldm(-1.0) {
status[0] = status[1] = status[2] = 0.;
}
inline HepRandomEngine * RandPoisson::getLocalEngine() {
return localEngine.get();
}
} // namespace CLHEP
@@ -0,0 +1,155 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandPoissonQ ---
// class header file
// -----------------------------------------------------------------------
// Class defining RandPoissonQ, which is derived from RandPoison.
// The user interface is identical; but RandGaussQ is much faster in all cases
// and a bit less accurate when mu > 100.
// =======================================================================
// M. Fischler - Created: 4th Feb 2000
// M Fischler - put and get to/from streams 12/10/04
//
// =======================================================================
#ifndef RandPoissonQ_h
#define RandPoissonQ_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Random/RandPoisson.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandPoissonQ : public RandPoisson {
public:
inline RandPoissonQ ( HepRandomEngine& anEngine, double m=1.0 );
inline RandPoissonQ ( HepRandomEngine* anEngine, double m=1.0 );
// These constructors should be used to instantiate a RandPoissonQ
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandPoissonQ destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandPoissonQ destructor.
virtual ~RandPoissonQ();
// Destructor
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
// Methods to generate Poisson-distributed random deviates.
// The method used for mu <= 100 is exact, and 3-7 times faster than
// that used by RandPoisson.
// For mu > 100 then we use a corrected version of a
// (quick) Gaussian approximation. Naively that would be:
//
// Poisson(mu) ~ std::floor( mu + .5 + Gaussian(std::sqrt(mu)) )
//
// but actually, that would give a slightly incorrect sigma and a
// very different skew than a true Poisson. Instead we return
//
// Poisson(mu) ~ std::floor( a0*mu + a1*g + a2*g*g ) )
// (with g a gaussian normal)
//
// where a0, a1, a2 are chosen to give the exctly correct mean, sigma,
// and skew for the Poisson distribution.
// Static methods to shoot random values using the static generator
static long shoot( double m=1.0 );
static void shootArray ( const int size, long* vect, double m=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static long shoot( HepRandomEngine* anEngine, double m=1.0 );
static void shootArray ( HepRandomEngine* anEngine,
const int size, long* vect, double m=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
long fire();
long fire( double m );
void fireArray ( const int size, long* vect );
void fireArray ( const int size, long* vect, double m);
double operator()();
double operator()( double m );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandPoissonQ";}
// Provides the name of this distribution class
// static constants of possible interest to users:
// RandPoisson will never return a deviate greater than this value:
static const double MAXIMUM_POISSON_DEVIATE; // Will be 2.0E9
static inline int tableBoundary();
private:
// constructor helper
void setupForDefaultMu();
// algorithm helper methods - all static since the shoot methods mayneed them
static long poissonDeviateSmall ( HepRandomEngine * e, double mean );
static long poissonDeviateQuick ( HepRandomEngine * e, double mean );
static long poissonDeviateQuick ( HepRandomEngine * e,
double A0, double A1, double A2, double sig );
// All the engine info, and the default mean, are in the
// RandPoisson base class.
// quantities for approximate Poisson by corrected Gaussian
double a0;
double a1;
double a2;
double sigma;
// static data - constants only, so that saveEngineStatus works properly!
// The following MUST MATCH the corresponding values used (in
// poissonTables.cc) when poissonTables.cdat was created.
// poissonTables.cc gets these values by including this header,
// but we must be careful not to change these values,
// and rebuild RandPoissonQ before re-generating poissonTables.cdat.
// (These statics are given values near the start of the .cc file)
static const double FIRST_MU; // lowest mu value in table
static const double LAST_MU; // highest mu value
static const double S; // Spacing between mu values
static const int BELOW; // Starting point for N is at mu - BELOW
static const int ENTRIES; // Number of entries in each mu row
};
} // namespace CLHEP
#include "CLHEP/Random/RandPoissonQ.icc"
#endif
@@ -0,0 +1,32 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandPoissonQ ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// M. Fischler - Created: 1/26/00
// =======================================================================
namespace CLHEP {
inline RandPoissonQ::RandPoissonQ(HepRandomEngine & anEngine, double m )
: RandPoisson(anEngine, m)
{ setupForDefaultMu();
}
inline RandPoissonQ::RandPoissonQ(HepRandomEngine * anEngine, double m )
: RandPoisson(anEngine, m)
{ setupForDefaultMu();
}
inline int RandPoissonQ::tableBoundary() {
return int(LAST_MU + S);
}
} // namespace CLHEP
@@ -0,0 +1,115 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandStudentT ---
// class header file
// -----------------------------------------------------------------------
// Class defining methods for shooting Student's t- distributed random
// values, given a number of degrees of freedom a (default=1.0).
// Default values are used for operator()().
// Valid input values are a > 0. When invalid values are presented, the
// code silently returns DBL_MAX from <float.h> which is the same as
// MAXDOUBLE in <values.h> on systems where the latter exists.
// =======================================================================
// John Marraffino - Created: Based on the C-Rand package
// by Ernst Stadlober and Franz Niederl of the Technical
// University of Graz, Austria : 12th May 1998
// - Removed <values.h> because that won't work
// on NT : 26th Jun 1998
// Gabriele Cosmo - Fixed minor bug on inline definition for shoot()
// methods. Created .icc file : 20th Aug 1998
// - Removed useless methods and data: 5th Jan 1999
// M Fischler - put and get to/from streams 12/10/04
// =======================================================================
#ifndef RandStudentT_h
#define RandStudentT_h 1
#include "CLHEP/Random/Random.h"
#include "CLHEP/Utility/memory.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RandStudentT : public HepRandom {
public:
inline RandStudentT ( HepRandomEngine& anEngine, double a=1.0 );
inline RandStudentT ( HepRandomEngine* anEngine, double a=1.0 );
// These constructors should be used to instantiate a RandStudentT
// distribution object defining a local engine for it.
// The static generator will be skipped using the non-static methods
// defined below.
// If the engine is passed by pointer the corresponding engine object
// will be deleted by the RandStudentT destructor.
// If the engine is passed by reference the corresponding engine object
// will not be deleted by the RandStudentT destructor.
virtual ~RandStudentT();
// Destructor
// Save and restore to/from streams
std::ostream & put ( std::ostream & os ) const;
std::istream & get ( std::istream & is );
// Static methods to shoot random values using the static generator
static inline double shoot();
static double shoot( double a );
static void shootArray ( const int size, double* vect,
double a=1.0 );
// Static methods to shoot random values using a given engine
// by-passing the static generator.
static inline double shoot( HepRandomEngine* anEngine );
static double shoot( HepRandomEngine* anEngine,
double a );
static void shootArray ( HepRandomEngine* anEngine, const int size,
double* vect, double a=1.0 );
// Methods using the localEngine to shoot random values, by-passing
// the static generator.
inline double fire();
double fire( double a );
void fireArray ( const int size, double* vect );
void fireArray ( const int size, double* vect, double a );
double operator()();
double operator()( double a );
std::string name() const;
HepRandomEngine & engine();
static std::string distributionName() {return "RandStudentT";}
// Provides the name of this distribution class
private:
shared_ptr<HepRandomEngine> localEngine;
double defaultA;
};
} // namespace CLHEP
#include "CLHEP/Random/RandStudentT.icc"
#endif
@@ -0,0 +1,37 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RandStudentT ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// =======================================================================
// Gabriele Cosmo - Created: 19th August 1998
// =======================================================================
namespace CLHEP {
inline RandStudentT::RandStudentT(HepRandomEngine & anEngine, double a)
: HepRandom( ), localEngine( &anEngine, do_nothing_deleter() ), defaultA(a)
{}
inline RandStudentT::RandStudentT(HepRandomEngine * anEngine, double a)
: HepRandom( ), localEngine( anEngine ), defaultA(a)
{}
inline double RandStudentT::fire() {
return fire( defaultA );
}
inline double RandStudentT::shoot() {
return shoot( 1.0 );
}
inline double RandStudentT::shoot( HepRandomEngine* anEngine )
{
return shoot( anEngine, 1.0 );
}
} // namespace CLHEP
+169
View File
@@ -0,0 +1,169 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepRandom ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// It's a singleton instantiated by default within the HEP Random module.
// It uses an instantiated HepJamesRandom engine as default algorithm
// for pseudo-random number generation. HepRandom defines a static private
// data member theGenerator and a set of static inlined methods to manipulate
// it. By means of theGenerator the user can change the underlying engine
// algorithm, get and set the seeds and use any kind of defined random
// distribution.
// Distribution classes inherit from HepRandom and define both static and
// not-static interfaces.
// A static table of uncorrelated seeds is available in this class.
// A static method "getTheTableSeeds()" is defined to access a couple of
// seeds at a given index in the table.
// =======================================================================
// Gabriele Cosmo - Created: 5th Sep 1995
// - Minor update: 17th May 1996
// - Poisson now operates on doubles : 31st Oct 1996
// - Added methods for engine status: 19th Nov 1996
// - Fixed default values to setTheSeed() and
// setTheSeeds() static methods: 16th Oct 1997
// - Modified HepRandom to act as a singleton, constructors
// are kept public for backward compatibility. Added table
// of seeds from HepRandomEngine: 19th Mar 1998
// - Relocated Poisson and Gauss data and simplified
// initialisation of static generator: 5th Jan 1999
// =======================================================================
#ifndef HepRandom_h
#define HepRandom_h 1
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class HepRandom {
public:
HepRandom();
HepRandom(long seed);
// Contructors with and without a seed using the default engine
// (JamesRandom).
HepRandom(HepRandomEngine & algorithm);
HepRandom(HepRandomEngine * algorithm);
// Constructor taking an alternative engine as argument. If a pointer is
// given the corresponding object will be deleted by the HepRandom
// destructor.
virtual ~HepRandom();
// Destructor
// implicitly allow compiler-generated copy functions
double flat();
// Returns the flat value ( interval ]0...1[ ).
void flatArray(const int size, double* vect);
// Fills "vect" array of flat random values, given the size.
inline double flat (HepRandomEngine* theNewEngine);
// Returns a flat value, given a defined Random Engine.
inline void flatArray(HepRandomEngine* theNewEngine,
const int size, double* vect);
// Fills "vect" array of flat random values, given the size
// and a defined Random Engine.
virtual double operator()();
// To get a flat random number using the operator ().
virtual std::string name() const;
virtual HepRandomEngine & engine();
virtual std::ostream & put ( std::ostream & os ) const;
virtual std::istream & get ( std::istream & is );
// Save and restore to/from streams
// --------------------------------------------------
// Static member functions using the static generator
// --------------------------------------------------
static void setTheSeed(long seed, int lux=3);
// (Re)Initializes the generator with a seed.
static long getTheSeed();
// Gets the current seed of the current generator.
static void setTheSeeds(const long* seeds, int aux=-1);
// (Re)Initializes the generator with a zero terminated list of seeds.
static const long* getTheSeeds();
// Gets the current array of seeds of the current generator.
static void getTheTableSeeds (long* seeds, int index);
// Gets the array of seeds in the static seedTable at "index" position.
static HepRandom * getTheGenerator();
// Return the current static generator.
static void setTheEngine (HepRandomEngine* theNewEngine);
// To set the underlying algorithm object.
static HepRandomEngine * getTheEngine();
// Returns a pointer to the underlying algorithm object.
static void saveEngineStatus( const char filename[] = "Config.conf" );
// Saves to file the current status of the current engine.
static void restoreEngineStatus( const char filename[] = "Config.conf" );
// Restores a saved status (if any) for the current engine.
static std::ostream& saveFullState ( std::ostream & os );
// Saves to stream the state of the engine and cached data.
static std::istream& restoreFullState ( std::istream & is );
// Restores from stream the state of the engine and cached data.
static std::ostream& saveDistState ( std::ostream & os ) {return os;}
// Saves to stream the state of the cached data.
static std::istream& restoreDistState ( std::istream & is ) {return is;}
// Restores from stream the state of the cached data.
static std::ostream& saveStaticRandomStates ( std::ostream & os );
// Saves to stream the engine and cached data for all distributions.
static std::istream& restoreStaticRandomStates ( std::istream & is );
// Restores from stream the engine and cached data for all distributions.
static void showEngineStatus();
// Dumps the current engine status on screen.
static int createInstance();
// used to initialise the default engine
static std::string distributionName() {return "HepRandomEngine";}
// Provides the name of this distribution class
protected: // -------- Data members ---------
static const long seedTable[215][2];
// Table of seeds
};
std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
std::istream & operator>> (std::istream & is, HepRandom & dist);
} // namespace CLHEP
#include "CLHEP/Random/Random.icc"
#endif
+32
View File
@@ -0,0 +1,32 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepRandom ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Added methods for engine status: 19th November 1996
// - operator()() is now virtual: 28th July 1997
// - Simplified initialisation of static generator: 5th Jan 1999
// =======================================================================
namespace CLHEP {
inline double HepRandom::flat(HepRandomEngine* theNewEngine)
{
return theNewEngine->flat();
}
inline void HepRandom::flatArray(HepRandomEngine* theNewEngine,
const int size, double* vect)
{
theNewEngine->flatArray(size,vect);
}
} // namespace CLHEP
@@ -0,0 +1,180 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepRandomEngine ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// Is the abstract class defining the interface for each random engine. It
// implements the getSeed() and getSeeds() methods which return the initial
// seed value and the initial array of seeds respectively. It defines 7
// pure virtual functions: flat(), flatArray(), setSeed(), setSeeds(),
// saveStatus(), restoreStatus() and showStatus(), which are implemented by
// the concrete random engines each one inheriting from this abstract class.
// Many concrete random engines can be defined and added to the structure,
// simply making them inheriting from HepRandomEngine and defining the six
// functions flat(), flatArray(), setSeed(), setSeeds(), saveStatus(),
// restoreStatus() and showStatus() in such a way that flat() and
// flatArray() return double random values ranging between ]0,1[.
// All the random engines have a default seed value already set but they
// can be instantiated with a different seed value set up by the user.
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Minor corrections: 31st October 1996
// - Added methods for engine status: 19th November 1996
// - Removed default values to setSeed() and
// setSeeds() pure virtual methods: 16th Oct 1997
// - Moved seeds table to HepRandom: 19th Mar 1998
// Ken Smith - Added conversion operators: 6th Aug 1998
// Mark Fischler - Added static twoToMinus_xx constants: 11 Sept 1998
// Mark Fischler - Removed getTableSeeds, which was migrated to HepRandom
// in 1998. 10 Feb 2005.
// =======================================================================
#ifndef HepRandomEngine_h
#define HepRandomEngine_h 1
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class HepRandomEngine {
public:
HepRandomEngine();
virtual ~HepRandomEngine();
// Constructor and destructor
inline bool operator==(const HepRandomEngine& engine);
inline bool operator!=(const HepRandomEngine& engine);
// Overloaded operators, ==, !=
virtual double flat() = 0;
// Should return a pseudo random number between 0 and 1
// (excluding the end points)
virtual void flatArray(const int size, double* vect) = 0;
// Fills an array "vect" of specified size with flat random values.
virtual void setSeed(long seed, int) = 0;
// Should initialise the status of the algorithm according to seed.
virtual void setSeeds(const long * seeds, int) = 0;
// Should initialise the status of the algorithm according to the zero terminated
// array of seeds. It is allowed to ignore one or many seeds in this array.
virtual void saveStatus( const char filename[] = "Config.conf") const = 0;
// Should save on a file specific to the instantiated engine in use
// the current status.
virtual void restoreStatus( const char filename[] = "Config.conf" ) = 0;
// Should read from a file (specific to the instantiated engine in use)
// and restore the last saved engine configuration.
virtual void showStatus() const = 0;
// Should dump the current engine status on the screen.
virtual std::string name() const = 0;
// Engine name.
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
// Save and restore to/from streams
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
// Helpers for EngineFactory which restores anonymous engine from istream
static HepRandomEngine* newEngine(std::istream & is);
// Instantiates on the heap a new engine of type specified by content of is
static HepRandomEngine* newEngine(const std::vector<unsigned long> & v);
// Instantiates on the heap a new engine of type specified by content of v
virtual std::vector<unsigned long> put () const;
virtual bool get (const std::vector<unsigned long> & v);
virtual bool getState (const std::vector<unsigned long> & v);
// Save and restore to/from vectors
long getSeed() const { return theSeed; }
// Gets the current seed.
const long* getSeeds() const { return theSeeds; }
// Gets the current array of seeds.
virtual operator double(); // Returns same as flat()
virtual operator float(); // less precise flat, faster if possible
virtual operator unsigned int(); // 32-bit int flat, faster if possible
// The above three conversion operators permit one to retrieve a pseudo-
// random number as either a double-precision float, a single-precision
// float, or a 32-bit unsigned integer. The usage, presuming an object
// of the respective engine class "e", is as follows:
// Recommended:
// float x;
// x = float( e );
// Reasonable:
// x = e;
// Works, but bad practice:
// x = 1.5 + e;
// Won't compile:
// x = e + 1.5;
protected:
long theSeed;
const long* theSeeds;
static inline double exponent_bit_32();
static inline double mantissa_bit_12();
static inline double mantissa_bit_24();
static inline double mantissa_bit_32();
static inline double twoToMinus_32();
static inline double twoToMinus_48();
static inline double twoToMinus_49();
static inline double twoToMinus_53();
static inline double nearlyTwoToMinus_54();
static bool checkFile (std::istream & file,
const std::string & filename,
const std::string & classname,
const std::string & methodname);
};
std::ostream & operator<< (std::ostream & os, const HepRandomEngine & e);
std::istream & operator>> (std::istream & is, HepRandomEngine & e);
template <class IS, class T>
bool possibleKeywordInput (IS & is, const std::string & key, T & t) {
std::string firstWord;
is >> firstWord;
if (firstWord == key) return true;
std::istringstream reread(firstWord);
reread >> t;
return false;
}
} // namespace CLHEP
#include "CLHEP/Random/RandomEngine.icc"
#endif
@@ -0,0 +1,70 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepRandomEngine ---
// inlined functions implementation file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// - Added == and != operators: 19th November 1996
// - Moved seeds table to HepRandom: 19th March 1998
// =======================================================================
#include <cmath>
namespace CLHEP {
inline bool HepRandomEngine::operator==(const HepRandomEngine& engine) {
return (this==&engine);
}
inline bool HepRandomEngine::operator!=(const HepRandomEngine& engine) {
return (this!=&engine);
}
inline double HepRandomEngine::exponent_bit_32() {
static double exponent_bit_32 = std::pow(2.0, 32.0);
return exponent_bit_32;
}
inline double HepRandomEngine::mantissa_bit_12() {
static double mantissa_bit_12 = std::pow(0.5, 12.0);
return mantissa_bit_12;
}
inline double HepRandomEngine::mantissa_bit_24() {
static double mantissa_bit_24 = std::pow(0.5, 24.0);
return mantissa_bit_24;
}
inline double HepRandomEngine::twoToMinus_32() {
static double twoToMinus_32 = std::ldexp(1.0, -32);
return twoToMinus_32;
}
inline double HepRandomEngine::twoToMinus_48() {
static double twoToMinus_48 = std::ldexp(1.0, -48);
return twoToMinus_48;
}
inline double HepRandomEngine::twoToMinus_49() {
static double twoToMinus_49 = std::ldexp(1.0, -49);
return twoToMinus_49;
}
inline double HepRandomEngine::twoToMinus_53() {
static double twoToMinus_53 = std::ldexp(1.0, -53);
return twoToMinus_53;
}
inline double HepRandomEngine::nearlyTwoToMinus_54() {
static double nearlyTwoToMinus_54 = std::ldexp(1.0, -54)
- std::ldexp(1.0, -100);
return nearlyTwoToMinus_54;
}
} // namespace CLHEP
+63
View File
@@ -0,0 +1,63 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// This file must be included to make use of the HEP Random module
// On some compilers the static instance of the HepRandom generator
// needs to be created explicitly in the client code. The static
// generator is assured to be correctly initialized by including this
// header in the client code.
// =======================================================================
// Gabriele Cosmo - Created: 5th September 1995
// Gabriele Cosmo - Last change: 13th February 1996
// Ken Smith - Added Ranshi and DualRand engines: 4th June 1998
// - Added Ranlux64 and MTwist engines: 14th July 1998
// - Added Hurd160, Hurd288m and TripleRand 6th Aug 1998
// =======================================================================
#ifndef Rndmze_h
#define Rndmze_h 1
// Including Engines ...
#include "CLHEP/Random/DualRand.h"
#include "CLHEP/Random/JamesRandom.h"
#include "CLHEP/Random/MTwistEngine.h"
#include "CLHEP/Random/RanecuEngine.h"
#include "CLHEP/Random/RanluxEngine.h"
#include "CLHEP/Random/Ranlux64Engine.h"
#include "CLHEP/Random/RanshiEngine.h"
// Including distributions ...
#include "CLHEP/Random/RandBinomial.h"
#include "CLHEP/Random/RandBreitWigner.h"
#include "CLHEP/Random/RandChiSquare.h"
#include "CLHEP/Random/RandExponential.h"
#include "CLHEP/Random/RandFlat.h"
#include "CLHEP/Random/RandBit.h"
#include "CLHEP/Random/RandGamma.h"
#include "CLHEP/Random/RandGauss.h"
#include "CLHEP/Random/RandGaussQ.h"
#include "CLHEP/Random/RandGeneral.h"
#include "CLHEP/Random/RandLandau.h"
#include "CLHEP/Random/RandPoissonQ.h"
#include "CLHEP/Random/RandStudentT.h"
namespace CLHEP {
#define HepUniformRand() HepRandom::getTheEngine()->flat()
// On some compilers the static instance of the HepRandom generator
// needs to be created explicitly in the client code (i.e. here).
static int HepRandomGenActive = HepRandom::createInstance();
} // namespace CLHEP
#endif
@@ -0,0 +1,133 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RanecuEngine ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// RANECU Random Engine - algorithm originally written in FORTRAN77
// as part of the MATHLIB HEP library.
// The initialisation is carried out using a Multiplicative Congruential
// generator using formula constants of L'Ecuyer as described in "F.James,
// Comp. Phys. Comm. 60 (1990) 329-344".
// Seeds are taken from a seed table given an index, the getSeed() method
// returns the current index in the seed table, the getSeeds() method
// returns a pointer to the couple of seeds stored in the local table of
// seeds at the current index.
// =======================================================================
// Gabriele Cosmo - Created: 2nd February 1996
// - Minor corrections: 31st October 1996
// - Added methods for engine status: 19th November 1996
// - setSeed() now has default dummy argument
// set to zero: 11th July 1997
// - Added default index to setSeeds(): 16th Oct 1997
// J.Marraffino - Added stream operators and related constructor.
// Added automatic seed selection from seed table and
// engine counter: 16th Feb 1998
// Ken Smith - Added conversion operators: 6th Aug 1998
// Mark Fischler Methods for distrib. instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef RanecuEngine_h
#define RanecuEngine_h 1
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author <Gabriele.Cosmo@cern.ch>
* @ingroup random
*/
class RanecuEngine : public HepRandomEngine {
public:
RanecuEngine(std::istream& is);
RanecuEngine();
RanecuEngine(int index);
virtual ~RanecuEngine();
// Constructors and destructor.
double flat();
// Returns a pseudo random number between 0 and 1
// (excluding the end points)
void flatArray (const int size, double* vect);
// Fills an array "vect" of specified size with flat random values.
void setIndex (long index);
// Sets the state of the algorithm according to "index", the position
// in the local table of seeds.
void setSeed (long index, int dum=0);
// Resets the state of the algorithm according to "index", the position
// in the static table of seeds stored in HepRandom.
void setSeeds (const long* seeds, int index=-1);
// Sets the state of the algorithm according to the array of seeds
// "seeds" containing two seed values to be stored in the local table at
// "index" position.
void saveStatus( const char filename[] = "Ranecu.conf" ) const;
// Saves on file Ranecu.conf the current engine status.
void restoreStatus( const char filename[] = "Ranecu.conf" );
// Reads from file Ranecu.conf the last saved engine status
// and restores it.
void showStatus() const;
// Dumps the engine status on the screen.
operator unsigned int();
// 32-bit int flat, faster in this case
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "RanecuEngine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
protected:
// Suggested L'ecuyer coefficients for portable 32 bits generators.
static const int ecuyer_a = 40014;
static const int ecuyer_b = 53668;
static const int ecuyer_c = 12211;
static const int ecuyer_d = 40692;
static const int ecuyer_e = 52774;
static const int ecuyer_f = 3791;
static const int shift1 = 2147483563;
static const int shift2 = 2147483399;
static const unsigned int VECTOR_STATE_SIZE = 4;
private:
// private method used to mitigate the effects of using a lookup table
void further_randomize (int seq, int col, int index, int modulus);
// Members defining the current state of the generator.
static const int maxSeq = 215;
long table[215][2];
int seq;
static int numEngines;
};
} // namespace CLHEP
#endif
@@ -0,0 +1,121 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- Ranlux64Engine ---
// class header file
// -----------------------------------------------------------------------
// The algorithm for this random engine has been taken from the notes of
// a double-precision ranlux implementation by Martin Luscher, dated
// November 1997.
//
// Like the previous ranlux generator, this one also has "luxury" levels,
// determining how many pseudo-random numbers are discarded for every
// twelve values used. Three levels are given, with the note that Luscher
// himself advocates only the highest two levels for this engine.
// level 0 (p=109): Throw away 109 values for every 12 used
// level 1 (p=202): (default) Throw away 202 values for every 12 used
// level 2 (p=397): Throw away 397 values for every 12 used
//
// The initialization is carried out using a Multiplicative Congruential
// generator using formula constants of L'Ecuyer as described in "F.James,
// Comp. Phys. Comm. 60 (1990) 329-344".
// =======================================================================
// Ken Smith - Created Initial draft: 14th Jul 1998
// - Added conversion operators: 6th Aug 1998
// Mark Fischler
// 9/9/98 - Added update() routine to allow computation of many at once
// - Replaced algorithm with jone exactly matching Luscher:
// 48-bits generated
// skip n-12 instead of n numbers
// - Corrected protection agains overflow
// 12/8/04 - Methods for instance save/restore
// 12/27/04 - methods for anonymous save/restore 12/27/04
//
// =======================================================================
#ifndef Ranlux64Engine_h
#define Ranlux64Engine_h
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class Ranlux64Engine : public HepRandomEngine {
public:
Ranlux64Engine( std::istream& is );
Ranlux64Engine();
Ranlux64Engine( long seed, int lux = 1 );
Ranlux64Engine( int rowIndex, int colIndex, int lux );
virtual ~Ranlux64Engine();
// Constructors and destructor
double flat();
// It returns a pseudo random number between 0 and 1,
// excluding the end points.
void flatArray (const int size, double* vect);
// Fills the array "vect" of specified size with flat random values.
void setSeed(long seed, int lux=1);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, int lux=1);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. Only the first seed is used.
void saveStatus( const char filename[] = "Ranlux64.conf" ) const;
// Saves in named file the current engine status.
void restoreStatus( const char filename[] = "Ranlux64.conf" );
// Reads from named file the last saved engine status and restores it.
void showStatus() const;
// Dumps the engine status on the screen.
int getLuxury() const { return luxury; }
// Gets the luxury level.
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "Ranlux64Engine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 30;
private:
void update();
void advance(int dozens);
int pDiscard; // separate sequence by p-r = p-12 discarded elements
int pDozens; // pDiscard / 12;
int endIters; // pDiscard % 12;
int luxury;
int index;
double randoms[12]; // randoms [i] is the x[n-i] of Luscher's note
double carry;
static int numEngines;
static int maxIndex;
}; // Ranlux64Engine
} // namespace CLHEP
#endif // Ranlux64Engine_h
@@ -0,0 +1,124 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RanluxEngine ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// The algorithm for this random engine has been taken from the original
// implementation in FORTRAN by Fred James as part of the MATHLIB HEP
// library.
// The initialisation is carried out using a Multiplicative Congruential
// generator using formula constants of L'Ecuyer as described in "F.James,
// Comp. Phys. Comm. 60 (1990) 329-344".
// =======================================================================
// Adeyemi Adesanya - Created: 6th November 1995
// Gabriele Cosmo - Adapted & Revised: 22nd November 1995
// Adeyemi Adesanya - Added setSeeds() method: 2nd February 1996
// Gabriele Cosmo - Added flatArray() method: 8th February 1996
// - Added methods for engine status: 19th November 1996
// - Added default luxury value for setSeed()
// and setSeeds(): 21st July 1997
// J.Marraffino - Added stream operators and related constructor.
// Added automatic seed selection from seed table and
// engine counter: 14th Feb 1998
// Ken Smith - Added conversion operators: 6th Aug 1998
// Mark Fischler Methods put, get for instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef RanluxEngine_h
#define RanluxEngine_h 1
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RanluxEngine : public HepRandomEngine {
public:
RanluxEngine( std::istream& is );
RanluxEngine();
RanluxEngine( long seed, int lux = 3 );
RanluxEngine( int rowIndex, int colIndex, int lux );
virtual ~RanluxEngine();
// Constructors and destructor
// Luxury level is set in the same way as the original FORTRAN routine.
// level 0 (p=24): equivalent to the original RCARRY of Marsaglia
// and Zaman, very long period, but fails many tests.
// level 1 (p=48): considerable improvement in quality over level 0,
// now passes the gap test, but still fails spectral test.
// level 2 (p=97): passes all known tests, but theoretically still
// defective.
// level 3 (p=223): DEFAULT VALUE. Any theoretically possible
// correlations have very small chance of being observed.
// level 4 (p=389): highest possible luxury, all 24 bits chaotic.
double flat();
// It returns a pseudo random number between 0 and 1,
// excluding the end points.
void flatArray (const int size, double* vect);
// Fills the array "vect" of specified size with flat random values.
void setSeed(long seed, int lux=3);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, int lux=3);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. Only the first seed is used.
void saveStatus( const char filename[] = "Ranlux.conf" ) const;
// Saves on file Ranlux.conf the current engine status.
void restoreStatus( const char filename[] = "Ranlux.conf" );
// Reads from file Ranlux.conf the last saved engine status
// and restores it.
void showStatus() const;
// Dumps the engine status on the screen.
int getLuxury() const { return luxury; }
// Gets the luxury level.
operator unsigned int(); // 32-bit flat, but slower than double or float
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "RanluxEngine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 31;
private:
int nskip, luxury;
float float_seed_table[24];
int i_lag,j_lag;
float carry;
int count24;
static const int int_modulus = 0x1000000;
static int numEngines;
static int maxIndex;
};
} // namespace CLHEP
#endif
@@ -0,0 +1,115 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- RanshiEngine ---
// class header file
// -----------------------------------------------------------------------
//
//
// The algorithm for this random engine was taken from "F.Gutbrod, Comp.
// Phys. Comm. 87 (1995) 291-306".
//
// The algorithm can be imagined as a physical system as follows: Imagine
// 512 "black balls" each with their own unique spin, and positions char-
// acterized by disrete angles, where the spin is a 32-bit unsigned integer.
// A "red ball" collides based upon the angle determined by the last 8 bits
// of its spin, and the spin of the colliding ball is taken as the output
// random number. The spin of the colliding ball is replaced then with the
// left circular shift of the black ball's spin XOR'd with the red ball's
// spin. The black ball's old spin becomes the red ball's.
//
// To avoid the traps presented, two measures are taken: first, the red
// ball will oscillate between hitting the lower half of the buffer on one
// turn and the upper half on another; second, the red ball's spin is
// incremented by a counter of the number of random numbers produced.
//
// The result is scaled to a double precision floating point number to which
// is added another random double further scaled 2^(53-32) places to the
// right in order to ensure that the remaining bits of the result are not
// left empty due to the mere 32 bits representation used internally.
// =======================================================================
// Ken Smith - Created: 9th June 1998
// - Removed std::pow() from flat method: 21st Jul 1998
// - Added conversion operators: 6th Aug 1998
// Mark Fischler Methods put, get for instance save/restore 12/8/04
// Mark Fischler methods for anonymous save/restore 12/27/04
// =======================================================================
#ifndef HepRanshiEngine_h
#define HepRanshiEngine_h
#include "CLHEP/Random/RandomEngine.h"
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class RanshiEngine: public HepRandomEngine {
public:
RanshiEngine();
RanshiEngine(std::istream &is);
RanshiEngine(long seed);
RanshiEngine(int rowIndex, int colIndex);
virtual ~RanshiEngine();
// Constructors and destructor
double flat();
// Returns a pseudo random number between 0 and 1
void flatArray(const int size, double* vect);
// Fills the array "vect" of specified size with flat random values
void setSeed(long seed, int);
// Sets the state of the algorithm according to seed.
void setSeeds(const long* seeds, int);
// Sets the state of the algorithm according to the zero-terminated
// array of seeds.
void saveStatus(const char filename[] = "RanshiEngine.conf") const;
// Saves on named file the current engine status
void restoreStatus(const char filename[] = "RanshiEngine.conf");
// Reads from named file the last saved engine status
// and restores it.
void showStatus() const;
// Dumps the engine status on the screen
operator float(); // flat value, without worrying about filling bits
operator unsigned int(); // 32-bit flat value, quickest of all
virtual std::ostream & put (std::ostream & os) const;
virtual std::istream & get (std::istream & is);
static std::string beginTag ( );
virtual std::istream & getState ( std::istream & is );
std::string name() const;
static std::string engineName() {return "RanshiEngine";}
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
private:
static int numEngines;
enum {numBuff = 512};
unsigned int halfBuff, numFlats;
unsigned int buffer[numBuff];
unsigned int redSpin;
static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
}; // RanshiEngine
} // namespace CLHEP
#endif // HepRanshiEngine_h
+244
View File
@@ -0,0 +1,244 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// table of seeds
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// Static definition for the table of seeds.
// This table of seeds has been taken from the original FORTRAN77
// implementation of the HEP CERN Library routine RECUSQ.
// Each sequence has a period of 10**9 numbers.
// =======================================================================
// Gabriele Cosmo - Created: 2nd February 1996
// =======================================================================
#ifndef SeedTable_h
#define SeedTable_h 1
namespace CLHEP {
const long HepRandom::seedTable[215][2] = {
{ 9876, 54321 },
{ 1299961164, 253987020 },
{ 669708517, 2079157264 },
{ 190904760, 417696270 },
{ 1289741558, 1376336092 },
{ 1803730167, 324952955 },
{ 489854550, 582847132 },
{ 1348037628, 1661577989 },
{ 350557787, 1155446919 },
{ 591502945, 634133404 },
{ 1901084678, 862916278 },
{ 1988640932, 1785523494 },
{ 1873836227, 508007031 },
{ 1146416592, 967585720 },
{ 1837193353, 1522927634 },
{ 38219936, 921609208 },
{ 349152748, 112892610 },
{ 744459040, 1735807920 },
{ 1983990104, 728277902 },
{ 309164507, 2126677523 },
{ 362993787, 1897782044 },
{ 556776976, 462072869 },
{ 1584900822, 2019394912 },
{ 1249892722, 791083656 },
{ 1686600998, 1983731097 },
{ 1127381380, 198976625 },
{ 1999420861, 1810452455 },
{ 1972906041, 664182577 },
{ 84636481, 1291886301 },
{ 1186362995, 954388413 },
{ 2141621785, 61738584 },
{ 1969581251, 1557880415 },
{ 1150606439, 136325185 },
{ 95187861, 1592224108 },
{ 940517655, 1629971798 },
{ 215350428, 922659102 },
{ 786161212, 1121345074 },
{ 1450830056, 1922787776 },
{ 1696578057, 2025150487 },
{ 1803414346, 1851324780 },
{ 1017898585, 1452594263 },
{ 1184497978, 82122239 },
{ 633338765, 1829684974 },
{ 430889421, 230039326 },
{ 492544653, 76320266 },
{ 389386975, 1314148944 },
{ 1720322786, 709120323 },
{ 1868768216, 1992898523 },
{ 443210610, 811117710 },
{ 1191938868, 1548484733 },
{ 616890172, 159787986 },
{ 935835339, 1231440405 },
{ 1058009367, 1527613300 },
{ 1463148129, 1970575097 },
{ 1795336935, 434768675 },
{ 274019517, 605098487 },
{ 483689317, 217146977 },
{ 2070804364, 340596558 },
{ 930226308, 1602100969 },
{ 989324440, 801809442 },
{ 410606853, 1893139948 },
{ 1583588576, 1219225407 },
{ 2102034391, 1394921405 },
{ 2005037790, 2031006861 },
{ 1244218766, 923231061 },
{ 49312790, 775496649 },
{ 721012176, 321339902 },
{ 1719909107, 1865748178 },
{ 1156177430, 1257110891 },
{ 307561322, 1918244397 },
{ 906041433, 360476981 },
{ 1591375755, 268492659 },
{ 461522398, 227343256 },
{ 2145930725, 2020665454 },
{ 1938419274, 1331283701 },
{ 174405412, 524140103 },
{ 494343653, 18063908 },
{ 1025534808, 181709577 },
{ 2048959776, 1913665637 },
{ 950636517, 794796256 },
{ 1828843197, 1335757744 },
{ 211109723, 983900607 },
{ 825474095, 1046009991 },
{ 374915657, 381856628 },
{ 1241296328, 698149463 },
{ 1260624655, 1024538273 },
{ 900676210, 1628865823 },
{ 697951025, 500570753 },
{ 1007920268, 1708398558 },
{ 264596520, 624727803 },
{ 1977924811, 674673241 },
{ 1440257718, 271184151 },
{ 1928778847, 993535203 },
{ 1307807366, 1801502463 },
{ 1498732610, 300876954 },
{ 1617712402, 1574250679 },
{ 1261800762, 1556667280 },
{ 949929273, 560721070 },
{ 1766170474, 1953522912 },
{ 1849939248, 19435166 },
{ 887262858, 1219627824 },
{ 483086133, 603728993 },
{ 1330541052, 1582596025 },
{ 1850591475, 723593133 },
{ 1431775678, 1558439000 },
{ 922493739, 1356554404 },
{ 1058517206, 948567762 },
{ 709067283, 1350890215 },
{ 1044787723, 2144304941 },
{ 999707003, 513837520 },
{ 2140038663, 1850568788 },
{ 1803100150, 127574047 },
{ 867445693, 1149173981 },
{ 408583729, 914837991 },
{ 1166715497, 602315845 },
{ 430738528, 1743308384 },
{ 1388022681, 1760110496 },
{ 1664028066, 654300326 },
{ 1767741172, 1338181197 },
{ 1625723550, 1742482745 },
{ 464486085, 1507852127 },
{ 754082421, 1187454014 },
{ 1315342834, 425995190 },
{ 960416608, 2004255418 },
{ 1262630671, 671761697 },
{ 59809238, 103525918 },
{ 1205644919, 2107823293 },
{ 1615183160, 1152411412 },
{ 1024474681, 2118672937 },
{ 1703877649, 1235091369 },
{ 1821417852, 1098463802 },
{ 1738806466, 1529062843 },
{ 620780646, 1654833544 },
{ 1070174101, 795158254 },
{ 658537995, 1693620426 },
{ 2055317555, 508053916 },
{ 1647371686, 1282395762 },
{ 29067379, 409683067 },
{ 1763495989, 1917939635 },
{ 1602690753, 810926582 },
{ 885787576, 513818500 },
{ 1853512561, 1195205756 },
{ 1798585498, 1970460256 },
{ 1819261032, 1306536501 },
{ 1133245275, 37901 },
{ 689459799, 1334389069 },
{ 1730609912, 1854586207 },
{ 1556832175, 1228729041 },
{ 251375753, 683687209 },
{ 2083946182, 1763106152 },
{ 2142981854, 1365385561 },
{ 763711891, 1735754548 },
{ 1581256466, 173689858 },
{ 2121337132, 1247108250 },
{ 1004003636, 891894307 },
{ 569816524, 358675254 },
{ 626626425, 116062841 },
{ 632086003, 861268491 },
{ 1008211580, 779404957 },
{ 1134217766, 1766838261 },
{ 1423829292, 1706666192 },
{ 942037869, 1549358884 },
{ 1959429535, 480779114 },
{ 778311037, 1940360875 },
{ 1531372185, 2009078158 },
{ 241935492, 1050047003 },
{ 272453504, 1870883868 },
{ 390441332, 1057903098 },
{ 1230238834, 1548117688 },
{ 1242956379, 1217296445 },
{ 515648357, 1675011378 },
{ 364477932, 355212934 },
{ 2096008713, 1570161804 },
{ 1409752526, 214033983 },
{ 1288158292, 1760636178 },
{ 407562666, 1265144848 },
{ 1071056491, 1582316946 },
{ 1014143949, 911406955 },
{ 203080461, 809380052 },
{ 125647866, 1705464126 },
{ 2015685843, 599230667 },
{ 1425476020, 668203729 },
{ 1673735652, 567931803 },
{ 1714199325, 181737617 },
{ 1389137652, 678147926 },
{ 288547803, 435433694 },
{ 200159281, 654399753 },
{ 1580828223, 1298308945 },
{ 1832286107, 169991953 },
{ 182557704, 1046541065 },
{ 1688025575, 1248944426 },
{ 1508287706, 1220577001 },
{ 36721212, 1377275347 },
{ 1968679856, 1675229747 },
{ 279109231, 1835333261 },
{ 1358617667, 1416978076 },
{ 740626186, 2103913602 },
{ 1882655908, 251341858 },
{ 648016670, 1459615287 },
{ 780255321, 154906988 },
{ 857296483, 203375965 },
{ 1631676846, 681204578 },
{ 1906971307, 1623728832 },
{ 1541899600, 1168449797 },
{ 1267051693, 1020078717 },
{ 1998673940, 1298394942 },
{ 1914117058, 1381290704 },
{ 426068513, 1381618498 },
{ 139365577, 1598767734 },
{ 2129910384, 952266588 },
{ 661788054, 19661356 },
{ 1104640222, 240506063 },
{ 356133630, 1676634527 },
{ 242242374, 1863206182 },
{ 957935844, 1490681416 }
};
} // namespace CLHEP
#endif // SeedTable_h
+82
View File
@@ -0,0 +1,82 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- HepStat ---
// Purely static class containing useful statistics methods
// -----------------------------------------------------------------------
// HepStat is a substitute for using a namespace.
// One would never instantiate a HepStat object;
// usage of any of these methods looks like --
//
// double x = HepStat::erf ( .1 );
//
// A user may wish to improve the readability of algortihm code which uses
// one method many times by lines like using HepStat::erf
//
// and later, x = erf(u); will work.
//
// These methods are implemented in separate .cc files so that
// user code need pull in only the code that is necessary. Time
// (ROUGH estimates in cycles) and table footprint info is provided
// in this header.
// =======================================================================
// M. Fischler - Created: 1/25/00
//
// M. Fischler - Inserted flatToGaussian 1/25/00
// From code of an attempt to speed up RandGauss
// by use of tables and splines. The code was not
// significantly faster than Box-Mueller, so that
// algorithm is left as the RandGauss implementation.
// - Inserted inverseErf
// M. Fischler - Inserted gammln 2/4/00
// M. Fischler - Made constructor private; removed private destructor 4/17/00
// =======================================================================
#ifndef HepStat_h
#define HepStat_h 1
namespace CLHEP {
/**
* @author
* @ingroup random
*/
class HepStat {
private:
HepStat();
// You CANNOT instantiate a HepStat object.
public:
static double flatToGaussian (double r);
// This is defined by the satement that if e() provides a uniform random
// on (0,1) then flatToGaussian(e()) is distributed as a unit normal
// Gaussian. That is, flatToGaussian is the inverse of the c.d.f. of
// a Gaussian.
// Footprint: 30 K // Time: 150 cycles
static double inverseErf (double t);
static double erf (double x);
// defined in flatToGaussian.cc
static double erfQ (double x);
// Quicker, and with less footprint, than erf and gaussianCDF
// but only accurate to 7 digits.
// Footprint: 0 // Time:
static double gammln (double x);
// ln (gamma(x))
};
} // namespace CLHEP
#endif
@@ -0,0 +1,38 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- StaticRandomStates ---
// class header file
// -----------------------------------------------------------------------
//
// It's a holder for methods to save and restore the full states of all
// static random distribution generators, including engine and cached data.
//
// =======================================================================
// Mark Fischler - Created: Dec. 21, 2004
// =======================================================================
#ifndef StaticRandomStates_h
#define StaticRandomStates_h 1
#include <iostream>
namespace CLHEP {
/**
* @author <mf@fnal.gov>
*/
class StaticRandomStates {
public:
static std::ostream & save (std::ostream & os);
static std::istream & restore(std::istream & is);
};
} // namespace CLHEP
#endif
@@ -0,0 +1,32 @@
// $Id:$
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- engineIDulong ---
// function header file
// -----------------------------------------------------------------------
// Class generating new engines from streamed saves.
// =======================================================================
// M Fischler - Created: Mar. 8, 2005
// =======================================================================
#ifndef engineIDulong_h
#define engineIDulong_h 1
namespace CLHEP {
unsigned long crc32ul(const std::string & s);
template <class E>
unsigned long engineIDulong() {
static unsigned long id = crc32ul(E::engineName());
return id;
}
} // namespace CLHEP
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,378 @@
//
// mu = 10
//
0.00004539992976248, 0.00049939922738733, 0.00276939571551158, // 1 - 3
0.01033605067592572, 0.02925268807696107, 0.06708596287903178, // 4 - 6
0.13014142088248296, 0.22022064660169893, 0.33281967875071894, // 7 - 9
0.45792971447185227, 0.58303975019298560, 0.69677614630310680, // 10 - 12
0.79155647639487448, 0.86446442261931111, 0.91654152706533731, // 13 - 15
0.95125959669602145, 0.97295839021519903, 0.98572238640295051, // 16 - 18
0.99281349539614583, 0.99654565802414330, 0.99841173933814209, // 19 - 21
0.99930034948766533, 0.99970426319199401, 0.99987987784605004, // 22 - 24
0.99995305061857331, 0.99998231972758267, 0.99999357707720160, // 25 - 27
0.99999774646594941, 0.99999923553335934, 0.99999974900487998, // 28 - 30
0.99999992016205352, 0.99999997537404495, 0.99999999262779227, // 31 - 33
0.99999999785620053, 0.99999999939396766, 0.99999999983332966, // 34 - 36
0.99999999995537470, 0.99999999998835987, 0.99999999999704015, // 37 - 39
0.99999999999926581, 0.99999999999982225, 0.99999999999995792, // 40 - 42
0.99999999999999023, 0.99999999999999778, 0.99999999999999944, // 43 - 45
0.99999999999999978, 0.99999999999999989, 1.00000000000000000, // 46 - 48
1.00000000000000000, 1.00000000000000000, 1.00000000000000000, // 49 - 51
//
// mu = 15
//
0.00000030590232050, 0.00000489443712803, 0.00003930844818448, // 1 - 3
0.00021137850346676, 0.00085664121077530, 0.00279242933270092, // 4 - 6
0.00763189963751496, 0.01800219314783076, 0.03744649347967288, // 7 - 9
0.06985366069940976, 0.11846441152901509, 0.18475179902393143, // 10 - 12
0.26761103339257686, 0.36321784227947540, 0.46565370894400959, // 13 - 15
0.56808957560854378, 0.66412320060654462, 0.74885875207536889, // 16 - 18
0.81947171163272237, 0.87521878496747518, 0.91702908996853982, // 19 - 21
0.94689359354072877, 0.96725575506722128, 0.98053542562797724, // 22 - 24
0.98883521972844968, 0.99381509618873320, 0.99668810183889678, // 25 - 27
0.99828421608898765, 0.99913927729439345, 0.99958155033167229, // 28 - 30
0.99980268685031171, 0.99990968839158889, 0.99995984536406257, // 31 - 33
0.99998264398791425, 0.99999270220431935, 0.99999701286849296, // 34 - 36
0.99999880897856530, 0.99999953713129730, 0.99999982456000736, // 37 - 39
0.99999993510951124, 0.99999997656557515, 0.99999999173242782, // 40 - 42
0.99999999714916088, 0.99999999903871895, 0.99999999968288644, // 43 - 45
0.99999999989760890, 0.99999999996762712, 0.99999999998997335, // 46 - 48
0.99999999999695655, 0.99999999999909428, 0.99999999999973554, // 49 - 51
//
// mu = 20
//
0.00000000206115362, 0.00000004328422607, 0.00000045551495056, // 1 - 3
0.00000320371978048, 0.00001694474393007, 0.00007190884052843, // 4 - 6
0.00025512249585630, 0.00077859008250736, 0.00208725904913502, // 7 - 9
0.00499541230830759, 0.01081171882665273, 0.02138682158728025, // 10 - 12
0.03901199285499279, 0.06612764095916593, 0.10486428110798471, // 13 - 15
0.15651313463974306, 0.22107420155444102, 0.29702839792467389, // 16 - 18
0.38142194944715491, 0.47025726683924018, 0.55909258423132546, // 19 - 21
0.64369764841426380, 0.72061134312602593, 0.78749281678842775, // 22 - 24
0.84322737817376259, 0.88781502728203043, 0.92211321890377496, // 25 - 27
0.94751928677173392, 0.96566647810599027, 0.97818178247444298, // 28 - 30
0.98652531872007809, 0.99190824533016531, 0.99527257446146977, // 31 - 33
0.99731156181377556, 0.99851096613866130, 0.99919634003859603, // 34 - 36
0.99957710331633753, 0.99978292130430590, 0.99989124656113137, // 37 - 39
0.99994679797488806, 0.99997457368176634, 0.99998812280707283, // 40 - 42
0.99999457477150455, 0.99999757568519365, 0.99999893973687048, // 43 - 45
0.99999954598206020, 0.99999980956692525, 0.99999992173069763, // 46 - 48
0.99999996846560280, 0.99999998754107433, 0.99999999517126292, // 49 - 51
//
// mu = 25
//
0.00000000001388794, 0.00000000036108654, 0.00000000470106900, // 1 - 3
0.00000004086758948, 0.00000026690834249, 0.00000139711210754, // 4 - 6
0.00000610629446193, 0.00002292480287045, 0.00007548264164706, // 7 - 9
0.00022147663824878, 0.00058646162975308, 0.00141597297408103, // 10 - 12
0.00314412160809759, 0.00646748436582174, 0.01240206071890058, // 13 - 15
0.02229302130736532, 0.03774764722684147, 0.06047503828489464, // 16 - 18
0.09204085919885736, 0.13357483408565043, 0.18549230269414177, // 19 - 21
0.24729881294234574, 0.31753348367894113, 0.39387551708828394, // 22 - 24
0.47339846855634937, 0.55292142002441480, 0.62938579643601622, // 25 - 27
0.70018614496527676, 0.76340074186640228, 0.81789608402254499, // 28 - 30
0.86330886915266392, 0.89993208296727589, 0.92854396875994150, // 31 - 33
0.95021963981499125, 0.96615763323782189, 0.97754191425412951, // 34 - 36
0.98544766495989866, 0.99078938840974273, 0.99430368015306114, // 37 - 39
0.99655643127057292, 0.99796440071901782, 0.99882291867538664, // 40 - 42
0.99933394126846331, 0.99963104742722886, 0.99979985774470925, // 43 - 45
0.99989364125442060, 0.99994461055317674, 0.99997172188230232, // 46 - 48
0.99998584236622190, 0.99999304669475231, 0.99999664885901751, // 49 - 51
//
// mu = 30
//
0.00000000000009358, 0.00000000000290086, 0.00000000004501017, // 1 - 3
0.00000000046610320, 0.00000000362430095, 0.00000002257348746, // 4 - 6
0.00000011731942002, 0.00000052337341671, 0.00000204607590427, // 7 - 9
0.00000712175086282, 0.00002234877573845, 0.00006387702539927, // 10 - 12
0.00016769764955133, 0.00040728370528685, 0.00092068239614867, // 13 - 15
0.00194747977787231, 0.00387272486860413, 0.00727021620518971, // 16 - 18
0.01293270176616566, 0.02187346844139086, 0.03528461845422865, // 19 - 21
0.05444340418685407, 0.08056902109497963, 0.11464591271427385, // 22 - 24
0.15724202723839162, 0.20835736466733296, 0.26733660016226524, // 25 - 27
0.33286908404552334, 0.40308245963472844, 0.47571698610631996, // 28 - 30
0.54835151257791148, 0.61864298980848387, 0.68454124971214547, // 31 - 33
0.74444875871547422, 0.79730832548311725, 0.84261652556966837, // 34 - 36
0.88037335897512770, 0.91098700768225682, 0.93515567771420094, // 37 - 39
0.95374696235415790, 0.96769042583412568, 0.97789296008776061, // 40 - 42
0.98518048455464269, 0.99026480395014183, 0.99373138535616401, // 43 - 45
0.99604243962684547, 0.99754964893381159, 0.99851169742761980, // 46 - 48
0.99911297773624996, 0.99948110853745209, 0.99970198701817337, // 49 - 51
//
// mu = 35
//
0.00000000004433782, 0.00000000032030161, 0.00000000193009042, // 5 - 7
0.00000000997903445, 0.00000004519316457, 0.00000018213700396, // 8 - 10
0.00000066144044180, 0.00000218649683492, 0.00000663457798154, // 11 - 13
0.00001861018106857, 0.00004854918878617, 0.00011840687346056, // 14 - 16
0.00027122055868579, 0.00058583696944361, 0.00119759110147270, // 17 - 19
0.00232450660784209, 0.00429660874398852, 0.00758344563756590, // 20 - 22
0.01281250433189355, 0.02076976756239215, 0.03237410977353594, // 23 - 25
0.04862018886913725, 0.07048991072860056, 0.09883955017605298, // 26 - 28
0.13427659948536852, 0.17704545210005967, 0.22694244681719936, // 29 - 31
0.28327776343332478, 0.34489451598221199, 0.41024561717042568, // 32 - 34
0.47751880957005743, 0.54479200196968913, 0.61019649458044223, // 35 - 37
0.67206560921223568, 0.72905032005730863, 0.78019044517468172, // 38 - 40
0.82493805465238323, 0.86313723347481131, 0.89496988249350140, // 41 - 43
0.92088017820638868, 0.94149064070527633, 0.95752100042663335, // 44 - 46
0.96971801325810070, 0.97880089515387425, 0.98542382986954247, // 47 - 49
0.99015449752359119, 0.99346596488142525, 0.99573854051915456, // 50 - 52
0.99726815873685692, 0.99827828397496232, 0.99893299477743802, // 53 - 55
//
// mu = 40
//
0.00000000392593223, 0.00000001620195271, 0.00000006084202718, // 10 - 12
0.00000020964227541, 0.00000066748919306, 0.00000197562324349, // 13 - 15
0.00000546398071130, 0.00001418487438082, 0.00003470462419146, // 16 - 18
0.00008030406821511, 0.00017630289773857, 0.00036830055678549, // 19 - 21
0.00073401038354154, 0.00139893734127980, 0.00255533205038983, // 22 - 24
0.00448265656557320, 0.00756637578986661, 0.01231055921185645, // 25 - 27
0.01933897909628586, 0.02937957893118501, 0.04322868215173557, // 28 - 30
0.06169415311246963, 0.08552056725535230, 0.11530358493395564, // 31 - 33
0.15140421242317181, 0.19387553888107320, 0.24241419769010336, // 34 - 36
0.29634604081124799, 0.35465073607735026, 0.41602409951535269, // 37 - 39
0.47897113893894488, 0.54191817836253708, 0.60332992414165143, // 40 - 42
0.66181730107414127, 0.71622416333692251, 0.76568494721217817, // 43 - 45
0.80965008843462771, 0.84788064601936641, 0.88041729077233555, // 46 - 48
0.90753116139980983, 0.92966493334060518, 0.94737195089324144, // 49 - 51
0.96125980779726983, 0.97194277464652246, 0.98000539113652441, // 52 - 54
0.98597769964763704, 0.99032119674662800, 0.99342369467447866, // 55 - 57
0.99560088620279497, 0.99710239760163377, 0.99812037143135501, // 58 - 60
//
// mu = 45
//
0.00000006567326820, 0.00000020321560857, 0.00000059005344086, // 15 - 17
0.00000161403593809, 0.00000417399218116, 0.00001023704644108, // 18 - 20
0.00002387891852589, 0.00005311150156478, 0.00011290542141704, // 21 - 23
0.00022989352547582, 0.00044924622058604, 0.00084408107178442, // 24 - 26
0.00152744908347393, 0.00266639576962312, 0.00449684580093431, // 27 - 29
0.00733719929779651, 0.01159772954308980, 0.01778237022174135, // 30 - 32
0.02647952117609509, 0.03833927247748656, 0.05403600214109291, // 33 - 35
0.07421751170858680, 0.09944439866795415, 0.13012574767259014, // 36 - 38
0.16645892412544852, 0.20838182003259281, 0.25554507792813014, // 39 - 41
0.30730962927689065, 0.36277164857913402, 0.42081329668613293, // 42 - 44
0.48017407315919997, 0.53953484963226706, 0.59760517444287609, // 45 - 47
0.65320442160196990, 0.70532871581362033, 0.75319796559982988, // 48 - 50
0.79628029040741855, 0.83429410641411439, 0.86719067795837046, // 51 - 53
0.89512172926953126, 0.91839760536216519, 0.93744150398341120, // 54 - 56
0.95274463680405530, 0.96482605745193217, 0.97419957347183672, // 57 - 59
0.98134886535142485, 0.98671083426111594, 0.99066638509613403, // 60 - 62
0.99353734941187288, 0.99558803820882924, 0.99702992876918917, // 63 - 65
//
// mu = 50
//
0.00000047913573003, 0.00000123518722187, 0.00000303530982148, // 20 - 22
0.00000712649754788, 0.00001602038390960, 0.00003454931382985, // 23 - 25
0.00007160717367035, 0.00014287228874825, 0.00027484472407768, // 26 - 28
0.00051050978716595, 0.00091682886145608, 0.00159402731860629, // 29 - 31
0.00268628289465502, 0.00439293223223115, 0.00697876456189197, // 32 - 34
0.01078145916433434, 0.01621388002496630, 0.02375890899806624, // 35 - 37
0.03395489409684995, 0.04737066396367062, 0.06457036892113302, // 38 - 40
0.08607000011796101, 0.11228906255311710, 0.14350223211877911, // 41 - 43
0.17979661533466518, 0.22104023262544481, 0.26686647405964442, // 44 - 46
0.31667760605333961, 0.36966817200407920, 0.42486667820276625, // 47 - 49
0.48119168452795713, 0.53751669085314802, 0.59273728528960967, // 50 - 52
0.64583401070928437, 0.69592526110520381, 0.74230604850883297, // 53 - 55
0.78447040069395035, 0.82211714371637667, 0.85514060250797863, // 56 - 58
0.88360910146625615, 0.90773494804106769, 0.92783982018674394, // 59 - 61
0.94431922358483922, 0.95760906503491605, 0.96815655824926272, // 62 - 64
0.97639678732297108, 0.98273542507197753, 0.98753742336667938, // 65 - 67
0.99112100418362103, 0.99375599007843107, 0.99566540014713401, // 68 - 70
//
// mu = 55
//
0.00000213352061032, 0.00000483888054397, 0.00001056175732670, // 25 - 27
0.00002221946929153, 0.00004511854636528, 0.00008854783047068, // 28 - 30
0.00016816818466391, 0.00030943010339383, 0.00055222402621089, // 31 - 33
0.00095688056423931, 0.00161147202281471, 0.00264011574343318, // 34 - 36
0.00421165476104474, 0.00654772627371058, 0.00992888241046376, // 37 - 39
0.01469717952639773, 0.02125358806080695, 0.03004877024111199, // 40 - 42
0.04156627071532098, 0.05629795736837898, 0.07471256568470150, // 43 - 45
0.09721930918242901, 0.12412954597319016, 0.15562024860067664, // 46 - 48
0.19170334536133821, 0.23220478050085630, 0.27675635915432617, // 49 - 51
0.32480217927081334, 0.37561987362479010, 0.42835521682231320, // 52 - 54
0.48206714044942006, 0.53577906407652687, 0.58853184621029253, // 55 - 57
0.63943365353234705, 0.68770260875153677, 0.73269909243044240, // 58 - 60
0.77394586913610586, 0.81113558583793366, 0.84412646355729692, // 61 - 63
0.87292802347102683, 0.89767936402188842, 0.91862280602646362, // 64 - 66
0.93607567436360961, 0.95040265583440109, 0.96199065555342367, // 67 - 69
0.97122746692365902, 0.97848496157170106, 0.98410696446807167, // 70 - 72
0.98840155001391028, 0.99163719665803529, 0.99404206916380389, // 73 - 75
//
// mu = 60
//
0.00000687626496873, 0.00001417434333349, 0.00002829965629754, // 30 - 32
0.00005478461810514, 0.00010293909411895, 0.00018791758120215, // 33 - 35
0.00033359498763050, 0.00057639066501107, 0.00097011338508767, // 36 - 38
0.00159178083784020, 0.00254819230361332, 0.00398280950227300, // 39 - 41
0.00608224930518961, 0.00908144902364191, 0.01326637886334280, // 42 - 44
0.01897310137202582, 0.02658206471693651, 0.03650679951464611, // 45 - 47
0.04917667372448815, 0.06501401648679071, 0.08440668109369180, // 48 - 50
0.10767787862197310, 0.13505575806700992, 0.16664561896512933, // 51 - 53
0.20240772564224566, 0.24214339972793045, 0.28549140782140475, // 54 - 56
0.33193570220727009, 0.38082443313975994, 0.43139898238026669, // 57 - 59
0.48283072737061250, 0.53426247236095836, 0.58485107399080671, // 60 - 62
0.63380778524549863, 0.68043322453568145, 0.72414457387022779, // 63 - 65
0.76449351171750135, 0.80117436430593192, 0.83402288901198907, // 66 - 68
0.86300688139968662, 0.88821035304116269, 0.90981332873385645, // 69 - 71
0.92806936453049915, 0.94328272769436805, 0.95578686180165751, // 72 - 74
0.96592534891567605, 0.97403613860689087, 0.98043939362627097, // 75 - 77
0.98542894299202166, 0.98926705788875302, 0.99218208186095402, // 78 - 80
//
// mu = 65
//
0.00001769335259280, 0.00003385901520079, 0.00006304701713189, // 35 - 37
0.00011432323674057, 0.00020203255975542, 0.00034821476478018, // 38 - 40
0.00058576084794540, 0.00096235829686589, 0.00154518768209997, // 41 - 43
0.00242620884582590, 0.00372771738314830, 0.00560767415928066, // 44 - 46
0.00826413482120682, 0.01193796339621108, 0.01691293959152935, // 47 - 49
0.02351239780980869, 0.03209169349357183, 0.04302608995326995, // 50 - 52
0.05669408552789261, 0.07345672160997699, 0.09363396874581931, // 53 - 55
0.11747980626999659, 0.14515801053913094, 0.17672087505656484, // 56 - 58
0.21209305080886146, 0.25106239697664584, 0.29327918865841229, // 59 - 61
0.33826429454881912, 0.38542609911134246, 0.43408510381870780, // 62 - 64
0.48350440547462570, 0.53292370713054360, 0.58159423148864453, // 65 - 67
0.62881190437336931, 0.67394644463082687, 0.71646448980089561, // 68 - 70
0.75594553174453083, 0.79209014760842222, 0.82472070359665750, // 71 - 73
0.85377530824371628, 0.87929624475802470, 0.90141438973709198, // 74 - 76
0.92033122425866276, 0.93629998067297571, 0.94960727768490316, // 77 - 79
0.96055631953015996, 0.96945241602943111, 0.97659125889921661, // 80 - 82
0.98225009775941241, 0.98668171855354170, 0.99011094892995122, // 83 - 85
//
// mu = 70
//
0.00003863938607251, 0.00006966088646657, 0.00012262442372470, // 40 - 42
0.00021089698582160, 0.00035459650551422, 0.00058320937775248, // 43 - 45
0.00093882940123421, 0.00147999030653251, 0.00228597463357252, // 46 - 48
0.00346136844383920, 0.00514050245850589, 0.00749129007903926, // 49 - 51
0.01071786132290859, 0.01506132261273268, 0.02079796959929281, // 52 - 54
0.02823436384113001, 0.03769886560346826, 0.04952949280639107, // 55 - 57
0.06405833323103313, 0.08159314064008388, 0.10239714943048309, // 58 - 60
0.12666849301928215, 0.15452085451462536, 0.18596706910614186, // 61 - 63
0.22090730754116022, 0.25912319332946154, 0.30027876263993991, // 64 - 66
0.34392860887832605, 0.38953292584380406, 0.43647854624944321, // 67 - 69
0.48410453796530900, 0.53173052968117485, 0.57868573278132418, // 70 - 72
0.62433662468424722, 0.66811145253636517, 0.70952007347755786, // 73 - 75
0.74816811968933772, 0.78376500435808227, 0.81612580860239547, // 76 - 78
0.84516755600113813, 0.87090074989875821, 0.89341729455917573, // 79 - 81
0.91287603685830199, 0.92948715833316586, 0.94349653789027998, // 82 - 84
0.95517102085454175, 0.96478530094275738, 0.97261087775874677, // 85 - 87
0.97890731887506011, 0.98391585158121841, 0.98785514696808452, // 88 - 90
//
// mu = 75
//
0.00007457087798458, 0.00012800994272557, 0.00021513885262936, // 45 - 47
0.00035417434715669, 0.00057141730735563, 0.00090393204235401, // 48 - 50
0.00140270414485158, 0.00213619253087742, 0.00319410847226085, // 51 - 53
0.00469115933270909, 0.00677039663888721, 0.00960572023822101, // 54 - 56
0.01340302863018591, 0.01839948704066605, 0.02486042464042485, // 57 - 59
0.03307348091130468, 0.04333980124990447, 0.05596232625637962, // 60 - 62
0.07123150973195440, 0.08940910910763866, 0.11071098337601866, // 63 - 65
0.13529006907030328, 0.16322084826835398, 0.19448664587811221, // 66 - 68
0.22897098147711026, 0.26645395495428204, 0.30661428367982324, // 69 - 71
0.34903716613638086, 0.39322766869529502, 0.43862886995445344, // 72 - 74
0.48464360096035725, 0.53065833196626100, 0.57606760598524498, // 75 - 77
0.62029741834139829, 0.66282608406846877, 0.70320139963214323, // 78 - 80
0.74105325797308808, 0.77610127495544434, 0.80815738804906290, // 81 - 83
0.83712375530233274, 0.86298658320703792, 0.88580672547589545, // 84 - 86
0.90570801233827114, 0.92286429411618121, 0.93748612517690000, // 87 - 89
0.94980789292469681, 0.96007603271452746, 0.96853878528856374, // 90 - 92
0.97543776836522378, 0.98100146439478830, 0.98544058356731312, // 93 - 95
//
// mu = 80
//
0.00013078397659141, 0.00021548056648791, 0.00034833796240399, // 50 - 52
0.00055273395612104, 0.00086125621078829, 0.00131832621770272, // 53 - 55
0.00198315531866918, 0.00293291117719268, 0.00426590185582216, // 56 - 58
0.00610450968841455, 0.00859753725803134, 0.01192157401752040, // 59 - 61
0.01628096648898145, 0.02190598903280217, 0.02904887480273325, // 62 - 64
0.03797748201514709, 0.04896653704581028, 0.06228660374964445, // 65 - 67
0.07819116100795391, 0.09690240484125916, 0.11859660059001886, // 68 - 70
0.14338996716002994, 0.17132615484454947, 0.20236636338290451, // 71 - 73
0.23638303027425250, 0.27315780529192601, 0.31238423197744442, // 74 - 76
0.35367520743588482, 0.39657492219790086, 0.44057462964612243, // 77 - 79
0.48513129541647337, 0.52968796118682437, 0.57369454466371417, // 80 - 82
0.61662779683628965, 0.65800924471347078, 0.69742014745364322, // 83 - 85
0.73451276179733505, 0.76901751932635065, 0.80074603199670980, // 86 - 88
0.82959013442430907, 0.85551741750529720, 0.87856389135506441, // 89 - 91
0.89882452770650811, 0.91644247235993737, 0.93159769356718836, // 92 - 94
0.94449575416910414, 0.95535727888650690, 0.96440854948434251, // 95 - 97
0.97187351492585639, 0.97796736426586772, 0.98289168696486684, // 98 - 100
//
// mu = 85
//
0.00021264747685098, 0.00033834572974723, 0.00052913772075048, // 55 - 57
0.00081365209329917, 0.00123061281168951, 0.00183131893140439, // 58 - 60
0.00268231926766715, 0.00386813940836116, 0.00549386056899003, // 61 - 63
0.00768729388094963, 0.01060044749839597, 0.01440995607505656, // 64 - 66
0.01931614136318006, 0.02554040628094867, 0.03332073742815944, // 67 - 69
0.04290520333414372, 0.05454348336283891, 0.06847663550986836, // 70 - 72
0.08492549568344480, 0.10407827807733518, 0.12607809569193898, // 73 - 75
0.15101122232182329, 0.17889695605261496, 0.20967990887232005, // 76 - 78
0.24322543438097305, 0.27931872132066299, 0.31766783869408355, // 79 - 81
0.35791073964150016, 0.39962594184309058, 0.44234632963990006, // 82 - 84
0.48557529348190964, 0.52880425732391922, 0.57153055879567283, // 85 - 87
0.61327464644048957, 0.65359564018832395, 0.69210445444187363, // 88 - 90
0.72847389012578168, 0.76244534103932216, 0.79383200764422368, // 91 - 93
0.82251874593902619, 0.84845888163113481, 0.87166847672407410, // 94 - 96
0.89221863904594745, 0.91022651324552717, 0.92584558780638715, // 97 - 99
0.93925590434853967, 0.95065467340936927, 0.96024769687640410, // 100 - 102
0.96824188309893311, 0.97483902706898129, 0.98023092358296304, // 103 - 105
//
// mu = 90
//
0.00032528901091254, 0.00050224788470280, 0.00076333474767204, // 60 - 62
0.00114233180682093, 0.00168375617703363, 0.00244513419764524, // 63 - 65
0.00349934991849209, 0.00493691681055597, 0.00686797681482089, // 66 - 68
0.00942379152634798, 0.01275746288920941, 0.01704361178431697, // 69 - 71
0.02247675827107302, 0.02926819137951808, 0.03764119110225857, // 72 - 74
0.04782456914342945, 0.06004462279283449, 0.07451573895660363, // 75 - 77
0.09143003057659352, 0.11094652090735108, 0.13318049723353059, // 78 - 80
0.15819372060048253, 0.18598619100820693, 0.21649012194351419, // 81 - 83
0.24956667356011242, 0.28500583600646767, 0.32252965506731440, // 84 - 86
0.36179876803796795, 0.40242198835243714, 0.44396846367405335, // 87 - 89
0.48598175332512594, 0.52799504297619848, 0.56954664812561095, // 90 - 92
0.61019495751090569, 0.64953203110957802, 0.68719518668277502, // 93 - 95
0.72287607091001427, 0.75632689987305102, 0.78736375148823978, // 96 - 98
0.81586698256341317, 0.84177901081357076, 0.86509983623871256, // 99 - 101
0.88588076978586860, 0.90421688762159458, 0.92023873815766577, // 102 - 104
0.93410380112157354, 0.94598814080492311, 0.95607861789455950, // 105 - 107
0.96456593507275834, 0.97163869938792402, 0.97747859652888658, // 108 - 110
//
// mu = 95
//
0.00047336010596951, 0.00071199190148983, 0.00105547706170846, // 65 - 67
0.00154250825903339, 0.00222291949059028, 0.00315971756302367, // 68 - 70
0.00443108637561185, 0.00613221366006082, 0.00837675660481988, // 71 - 73
0.01129773714936934, 0.01504764460520987, 0.01979752738260786, // 74 - 76
0.02573488085435536, 0.03306018708573214, 0.04198203441881924, // 77 - 79
0.05271083817379741, 0.06545129263283397, 0.08039380094898797, // 80 - 82
0.09770524351038590, 0.11751954523728714, 0.13992857695223498, // 83 - 85
0.16497396533952963, 0.19264038274409928, 0.22285083853069834, // 86 - 88
0.25546439875486776, 0.29027662596044190, 0.32702286578854789, // 89 - 91
0.36538432494975748, 0.40499670125752824, 0.44546095662568114, // 92 - 94
0.48635568279562291, 0.52725040896556474, 0.56771914840456961, // 95 - 97
0.60735348084483209, 0.64577451739406622, 0.68264318883019992, // 98 - 100
0.71766842669452691, 0.75061295735899292, 0.78129658886021125, // 101 - 103
0.80959702568172331, 0.83544838623983531, 0.85883771245907947, // 104 - 106
0.87979984444802473, 0.89841108312979856, 0.91478208011839590, // 107 - 109
0.92905038024607245, 0.94137300308361127, 0.95191939199862197, // 110 - 112
0.96086498973903289, 0.96838562500751990, 0.97465282106459239, // 113 - 115
@@ -0,0 +1,140 @@
// -*- C++ -*-
// $Id:$
// ----------------------------------------------------------------------
// HEP coherent Physical Constants
//
// This file has been provided by Geant4 (simulation toolkit for HEP).
//
// The basic units are :
// millimeter
// nanosecond
// Mega electron Volt
// positon charge
// degree Kelvin
// amount of substance (mole)
// luminous intensity (candela)
// radian
// steradian
//
// Below is a non exhaustive list of Physical CONSTANTS,
// computed in the Internal HEP System Of Units.
//
// Most of them are extracted from the Particle Data Book :
// Phys. Rev. D volume 50 3-1 (1994) page 1233
//
// ...with a meaningful (?) name ...
//
// You can add your own constants.
//
// Author: M.Maire
//
// History:
//
// 23.02.96 Created
// 26.03.96 Added constants for standard conditions of temperature
// and pressure; also added Gas threshold.
// 29.04.08 use PDG 2006 values
// 03.11.08 use PDG 2008 values
#ifndef HEP_PHYSICAL_CONSTANTS_H
#define HEP_PHYSICAL_CONSTANTS_H
#include "CLHEP/Units/SystemOfUnits.h"
namespace CLHEP {
//
//
//
static const double pi = 3.14159265358979323846;
static const double twopi = 2*pi;
static const double halfpi = pi/2;
static const double pi2 = pi*pi;
//
//
//
static const double Avogadro = 6.02214179e+23/mole;
//
// c = 299.792458 mm/ns
// c^2 = 898.7404 (mm/ns)^2
//
static const double c_light = 2.99792458e+8 * m/s;
static const double c_squared = c_light * c_light;
//
// h = 4.13566e-12 MeV*ns
// hbar = 6.58212e-13 MeV*ns
// hbarc = 197.32705e-12 MeV*mm
//
static const double h_Planck = 6.62606896e-34 * joule*s;
static const double hbar_Planck = h_Planck/twopi;
static const double hbarc = hbar_Planck * c_light;
static const double hbarc_squared = hbarc * hbarc;
//
//
//
static const double electron_charge = - eplus; // see SystemOfUnits.h
static const double e_squared = eplus * eplus;
//
// amu_c2 - atomic equivalent mass unit
// - AKA, unified atomic mass unit (u)
// amu - atomic mass unit
//
static const double electron_mass_c2 = 0.510998910 * MeV;
static const double proton_mass_c2 = 938.272013 * MeV;
static const double neutron_mass_c2 = 939.56536 * MeV;
static const double amu_c2 = 931.494028 * MeV;
static const double amu = amu_c2/c_squared;
//
// permeability of free space mu0 = 2.01334e-16 Mev*(ns*eplus)^2/mm
// permittivity of free space epsil0 = 5.52636e+10 eplus^2/(MeV*mm)
//
static const double mu0 = 4*pi*1.e-7 * henry/m;
static const double epsilon0 = 1./(c_squared*mu0);
//
// electromagnetic coupling = 1.43996e-12 MeV*mm/(eplus^2)
//
static const double elm_coupling = e_squared/(4*pi*epsilon0);
static const double fine_structure_const = elm_coupling/hbarc;
static const double classic_electr_radius = elm_coupling/electron_mass_c2;
static const double electron_Compton_length = hbarc/electron_mass_c2;
static const double Bohr_radius = electron_Compton_length/fine_structure_const;
static const double alpha_rcl2 = fine_structure_const
*classic_electr_radius
*classic_electr_radius;
static const double twopi_mc2_rcl2 = twopi*electron_mass_c2
*classic_electr_radius
*classic_electr_radius;
//
//
//
static const double k_Boltzmann = 8.617343e-11 * MeV/kelvin;
//
//
//
static const double STP_Temperature = 273.15*kelvin;
static const double STP_Pressure = 1.*atmosphere;
static const double kGasThreshold = 10.*mg/cm3;
//
//
//
static const double universe_mean_density = 1.e-25*g/cm3;
} // namespace CLHEP
#endif /* HEP_PHYSICAL_CONSTANTS_H */
@@ -0,0 +1,288 @@
// -*- C++ -*-
// $Id:$
// ----------------------------------------------------------------------
// HEP coherent system of Units
//
// This file has been provided to CLHEP by Geant4 (simulation toolkit for HEP).
//
// The basic units are :
// millimeter (millimeter)
// nanosecond (nanosecond)
// Mega electron Volt (MeV)
// positron charge (eplus)
// degree Kelvin (kelvin)
// the amount of substance (mole)
// luminous intensity (candela)
// radian (radian)
// steradian (steradian)
//
// Below is a non exhaustive list of derived and pratical units
// (i.e. mostly the SI units).
// You can add your own units.
//
// The SI numerical value of the positron charge is defined here,
// as it is needed for conversion factor : positron charge = e_SI (coulomb)
//
// The others physical constants are defined in the header file :
//PhysicalConstants.h
//
// Authors: M.Maire, S.Giani
//
// History:
//
// 06.02.96 Created.
// 28.03.96 Added miscellaneous constants.
// 05.12.97 E.Tcherniaev: Redefined pascal (to avoid warnings on WinNT)
// 20.05.98 names: meter, second, gram, radian, degree
// (from Brian.Lasiuk@yale.edu (STAR)). Added luminous units.
// 05.08.98 angstrom, picobarn, microsecond, picosecond, petaelectronvolt
// 01.03.01 parsec
// 31.01.06 kilogray, milligray, microgray
// 29.04.08 use PDG 2006 value of e_SI
// 03.11.08 use PDG 2008 value of e_SI
#ifndef HEP_SYSTEM_OF_UNITS_H
#define HEP_SYSTEM_OF_UNITS_H
namespace CLHEP {
//
// Length [L]
//
static const double millimeter = 1.;
static const double millimeter2 = millimeter*millimeter;
static const double millimeter3 = millimeter*millimeter*millimeter;
static const double centimeter = 10.*millimeter;
static const double centimeter2 = centimeter*centimeter;
static const double centimeter3 = centimeter*centimeter*centimeter;
static const double meter = 1000.*millimeter;
static const double meter2 = meter*meter;
static const double meter3 = meter*meter*meter;
static const double kilometer = 1000.*meter;
static const double kilometer2 = kilometer*kilometer;
static const double kilometer3 = kilometer*kilometer*kilometer;
static const double parsec = 3.0856775807e+16*meter;
static const double micrometer = 1.e-6 *meter;
static const double nanometer = 1.e-9 *meter;
static const double angstrom = 1.e-10*meter;
static const double fermi = 1.e-15*meter;
static const double barn = 1.e-28*meter2;
static const double millibarn = 1.e-3 *barn;
static const double microbarn = 1.e-6 *barn;
static const double nanobarn = 1.e-9 *barn;
static const double picobarn = 1.e-12*barn;
// symbols
static const double nm = nanometer;
static const double um = micrometer;
static const double mm = millimeter;
static const double mm2 = millimeter2;
static const double mm3 = millimeter3;
static const double cm = centimeter;
static const double cm2 = centimeter2;
static const double cm3 = centimeter3;
static const double m = meter;
static const double m2 = meter2;
static const double m3 = meter3;
static const double km = kilometer;
static const double km2 = kilometer2;
static const double km3 = kilometer3;
static const double pc = parsec;
//
// Angle
//
static const double radian = 1.;
static const double milliradian = 1.e-3*radian;
static const double degree = (3.14159265358979323846/180.0)*radian;
static const double steradian = 1.;
// symbols
static const double rad = radian;
static const double mrad = milliradian;
static const double sr = steradian;
static const double deg = degree;
//
// Time [T]
//
static const double nanosecond = 1.;
static const double second = 1.e+9 *nanosecond;
static const double millisecond = 1.e-3 *second;
static const double microsecond = 1.e-6 *second;
static const double picosecond = 1.e-12*second;
static const double hertz = 1./second;
static const double kilohertz = 1.e+3*hertz;
static const double megahertz = 1.e+6*hertz;
// symbols
static const double ns = nanosecond;
static const double s = second;
static const double ms = millisecond;
//
// Electric charge [Q]
//
static const double eplus = 1. ;// positron charge
static const double e_SI = 1.602176487e-19;// positron charge in coulomb
static const double coulomb = eplus/e_SI;// coulomb = 6.24150 e+18 * eplus
//
// Energy [E]
//
static const double megaelectronvolt = 1. ;
static const double electronvolt = 1.e-6*megaelectronvolt;
static const double kiloelectronvolt = 1.e-3*megaelectronvolt;
static const double gigaelectronvolt = 1.e+3*megaelectronvolt;
static const double teraelectronvolt = 1.e+6*megaelectronvolt;
static const double petaelectronvolt = 1.e+9*megaelectronvolt;
static const double joule = electronvolt/e_SI;// joule = 6.24150 e+12 * MeV
// symbols
static const double MeV = megaelectronvolt;
static const double eV = electronvolt;
static const double keV = kiloelectronvolt;
static const double GeV = gigaelectronvolt;
static const double TeV = teraelectronvolt;
static const double PeV = petaelectronvolt;
//
// Mass [E][T^2][L^-2]
//
static const double kilogram = joule*second*second/(meter*meter);
static const double gram = 1.e-3*kilogram;
static const double milligram = 1.e-3*gram;
// symbols
static const double kg = kilogram;
static const double g = gram;
static const double mg = milligram;
//
// Power [E][T^-1]
//
static const double watt = joule/second;// watt = 6.24150 e+3 * MeV/ns
//
// Force [E][L^-1]
//
static const double newton = joule/meter;// newton = 6.24150 e+9 * MeV/mm
//
// Pressure [E][L^-3]
//
#define pascal hep_pascal // a trick to avoid warnings
static const double hep_pascal = newton/m2; // pascal = 6.24150 e+3 * MeV/mm3
static const double bar = 100000*pascal; // bar = 6.24150 e+8 * MeV/mm3
static const double atmosphere = 101325*pascal; // atm = 6.32420 e+8 * MeV/mm3
//
// Electric current [Q][T^-1]
//
static const double ampere = coulomb/second; // ampere = 6.24150 e+9 * eplus/ns
static const double milliampere = 1.e-3*ampere;
static const double microampere = 1.e-6*ampere;
static const double nanoampere = 1.e-9*ampere;
//
// Electric potential [E][Q^-1]
//
static const double megavolt = megaelectronvolt/eplus;
static const double kilovolt = 1.e-3*megavolt;
static const double volt = 1.e-6*megavolt;
//
// Electric resistance [E][T][Q^-2]
//
static const double ohm = volt/ampere;// ohm = 1.60217e-16*(MeV/eplus)/(eplus/ns)
//
// Electric capacitance [Q^2][E^-1]
//
static const double farad = coulomb/volt;// farad = 6.24150e+24 * eplus/Megavolt
static const double millifarad = 1.e-3*farad;
static const double microfarad = 1.e-6*farad;
static const double nanofarad = 1.e-9*farad;
static const double picofarad = 1.e-12*farad;
//
// Magnetic Flux [T][E][Q^-1]
//
static const double weber = volt*second;// weber = 1000*megavolt*ns
//
// Magnetic Field [T][E][Q^-1][L^-2]
//
static const double tesla = volt*second/meter2;// tesla =0.001*megavolt*ns/mm2
static const double gauss = 1.e-4*tesla;
static const double kilogauss = 1.e-1*tesla;
//
// Inductance [T^2][E][Q^-2]
//
static const double henry = weber/ampere;// henry = 1.60217e-7*MeV*(ns/eplus)**2
//
// Temperature
//
static const double kelvin = 1.;
//
// Amount of substance
//
static const double mole = 1.;
//
// Activity [T^-1]
//
static const double becquerel = 1./second ;
static const double curie = 3.7e+10 * becquerel;
//
// Absorbed dose [L^2][T^-2]
//
static const double gray = joule/kilogram ;
static const double kilogray = 1.e+3*gray;
static const double milligray = 1.e-3*gray;
static const double microgray = 1.e-6*gray;
//
// Luminous intensity [I]
//
static const double candela = 1.;
//
// Luminous flux [I]
//
static const double lumen = candela*steradian;
//
// Illuminance [I][L^-2]
//
static const double lux = lumen/meter2;
//
// Miscellaneous
//
static const double perCent = 0.01 ;
static const double perThousand = 0.001;
static const double perMillion = 0.000001;
} // namespace CLHEP
#endif /* HEP_SYSTEM_OF_UNITS_H */
+22
View File
@@ -0,0 +1,22 @@
#ifndef HEP_DEFS_H
#define HEP_DEFS_H
#ifdef WIN32
//
// Define DLL export macro for WIN32 systems for
// importing/exporting external symbols to DLLs
//
#if defined G4LIB_BUILD_DLL
#if defined CLHEP_EXPORT
#define DLL_API __declspec( dllexport )
#else
#define DLL_API __declspec( dllimport )
#endif
#else
#define DLL_API
#endif
#else
#define DLL_API
#endif
#endif /* HEP_DEFS_H */
+24
View File
@@ -0,0 +1,24 @@
#ifndef CLHEP_KEYWORDS_H
#define CLHEP_KEYWORDS_H
// ======================================================================
//
// keywords - allow use of C++0X keywords
//
// Author: W. E. Brown; 2010-03-19
//
// ======================================================================
#include "CLHEP/Utility/defs.h"
// C++0X-like keywords: remove once C++0X is here to stay
//#define constexpr const
//#define noexcept throw()
//#define nullptr 0
#endif // CLHEP_KEYWORDS_H
//
// ======================================================================
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,33 @@
#ifndef CLHEP_NONCOPYABLE_H
#define CLHEP_NONCOPYABLE_H
// ======================================================================
//
// noncopyable - classes directly/indirectly inheriting won't be copyable
//
// Author: W. E. Brown; 2010-03-05
//
// ======================================================================
#include "CLHEP/Utility/defs.h"
namespace CLHEP {
class noncopyable
{
protected:
noncopyable () throw () { }
~noncopyable() throw () { }
private:
noncopyable ( noncopyable const & ); // = delete;
noncopyable & operator = ( noncopyable const & ); // = delete;
}; // noncopyable
} // namespace CLHEP
#endif // HEP_NONCOPYABLE_H
//
// ======================================================================
File diff suppressed because it is too large Load Diff
+106
View File
@@ -0,0 +1,106 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
//
// AxisAngle.h - provide HepAxisAngle class
//
// History:
// 23-Jan-1998 WEB Initial draft
// 15-Jun-1998 WEB Added namespace support
// 02-May-2000 WEB No global using
// 27-Jul-2000 MF CLHEP version
//
// ----------------------------------------------------------------------
#ifndef HEP_AXISANGLE_H
#define HEP_AXISANGLE_H
#include <iostream>
#include "CLHEP/Vector/ThreeVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepAxisAngle;
std::ostream & operator<<( std::ostream & os, const HepAxisAngle & aa );
std::istream & operator>>( std::istream & is, HepAxisAngle & aa );
/**
* @author
* @ingroup vector
*/
class HepAxisAngle {
public:
typedef double Scalar;
protected:
typedef HepAxisAngle AA; // just an abbreviation
static Scalar tolerance; // to determine relative nearness
public:
// ---------- Constructors:
inline HepAxisAngle();
inline HepAxisAngle( const Hep3Vector axis, Scalar delta );
// ---------- Destructor, copy constructor, assignment:
// use C++ defaults
// ---------- Accessors:
public:
inline Hep3Vector getAxis() const;
inline Hep3Vector axis() const;
inline AA & setAxis( const Hep3Vector axis );
inline double getDelta() const;
inline double delta() const ;
inline AA & setDelta( Scalar delta );
inline AA & set( const Hep3Vector axis, Scalar delta );
// ---------- Operations:
// comparisons:
inline int compare ( const AA & aa ) const;
inline bool operator==( const AA & aa ) const;
inline bool operator!=( const AA & aa ) const;
inline bool operator< ( const AA & aa ) const;
inline bool operator<=( const AA & aa ) const;
inline bool operator> ( const AA & aa ) const;
inline bool operator>=( const AA & aa ) const;
// relative comparison:
inline static double getTolerance();
inline static double setTolerance( Scalar tol );
protected:
double distance( const HepAxisAngle & aa ) const;
public:
bool isNear ( const AA & aa, Scalar epsilon = tolerance ) const;
double howNear( const AA & aa ) const;
// ---------- I/O:
friend std::ostream & operator<<( std::ostream & os, const AA & aa );
friend std::istream & operator>>( std::istream & is, AA & aa );
private:
Hep3Vector axis_; // Note: After construction, this is always of mag 1
double delta_;
}; // HepAxisAngle
} // namespace CLHEP
#include "CLHEP/Vector/AxisAngle.icc"
#endif // HEP_AXISANGLE_H
@@ -0,0 +1,121 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
//
// AxisAngle.icc
//
// History:
// 23-Jan-1998 WEB Initial draft
// 12-Mar-1998 WEB Gave default constructor proper default values
// 13-Mar-1998 WEB Corrected setDelta; simplified compare()
// 17-Jun-1998 WEB Added namespace support
// 26-Jul-2000 MF CLHEP version
//
// ----------------------------------------------------------------------
namespace CLHEP {
inline HepAxisAngle::HepAxisAngle() :
axis_( Hep3Vector(0,0,1) ), delta_( 0.0 )
{} // HepAxisAngle::HepAxisAngle()
inline HepAxisAngle::HepAxisAngle( const Hep3Vector axis, Scalar delta ) :
axis_( axis.unit() ), delta_( delta )
{} // HepAxisAngle::HepAxisAngle()
inline Hep3Vector HepAxisAngle::getAxis() const {
return axis_;
} // HepAxisAngle::getAxis()
inline Hep3Vector HepAxisAngle::axis() const {
return axis_;
} // HepAxisAngle::axis()
inline HepAxisAngle & HepAxisAngle::setAxis( const Hep3Vector axis ) {
axis_ = axis.unit();
return *this;
} // HepAxisAngle::setAxis()
inline double HepAxisAngle::getDelta() const {
return delta_;
} // HepAxisAngle::getDelta()
inline double HepAxisAngle::delta() const {
return delta_;
} // HepAxisAngle::delta()
inline HepAxisAngle & HepAxisAngle::setDelta( Scalar delta ) {
delta_ = delta;
return *this;
} // HepAxisAngle::setDelta()
inline HepAxisAngle & HepAxisAngle::set( const Hep3Vector axis, Scalar delta ) {
axis_ = axis.unit();
delta_ = delta;
return *this;
} // HepAxisAngle::set()
inline int HepAxisAngle::compare( const AA & aa ) const {
return delta_ < aa.delta_ ? -1
: delta_ > aa.delta_ ? +1
: axis_ < aa.axis_ ? -1
: axis_ > aa.axis_ ? +1
: 0;
} // HepAxisAngle::compare()
inline bool HepAxisAngle::operator==( const AA & aa ) const {
return ( compare( aa ) == 0 );
} // HepAxisAngle::operator==()
inline bool HepAxisAngle::operator!=( const AA & aa ) const {
return ( compare( aa ) != 0 );
} // HepAxisAngle::operator!=()
inline bool HepAxisAngle::operator<( const AA & aa ) const {
return ( compare( aa ) < 0 );
} // HepAxisAngle::operator<()
inline bool HepAxisAngle::operator<=( const AA & aa ) const {
return ( compare( aa ) <= 0 );
} // HepAxisAngle::operator<=()
inline bool HepAxisAngle::operator>( const AA & aa ) const {
return ( compare( aa ) > 0 );
} // HepAxisAngle::operator>()
inline bool HepAxisAngle::operator>=( const AA & aa ) const {
return ( compare( aa ) >= 0 );
} // HepAxisAngle::operator>=()
inline double HepAxisAngle::getTolerance() {
return tolerance;
} // HepAxisAngle::getTolerance()
inline double HepAxisAngle::setTolerance( Scalar tol ) {
Scalar oldTolerance( tolerance );
tolerance = tol;
return oldTolerance;
} // HepAxisAngle::setTolerance()
} // namespace CLHEP
+247
View File
@@ -0,0 +1,247 @@
// -*- C++ -*-
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepBoost class for performing specialized
// Lorentz transformations which are pure boosts on objects of the
// HepLorentzVector class.
//
// HepBoost is a concrete implementation of Hep4RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// LorentzVector.h LorentzRotation.h
// BoostX.h BoostY.h BoostZ.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_BOOST_H
#define HEP_BOOST_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/BoostX.h"
#include "CLHEP/Vector/BoostY.h"
#include "CLHEP/Vector/BoostZ.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepBoost;
inline HepBoost inverseOf ( const HepBoost & lt );
/**
* @author
* @ingroup vector
*/
class HepBoost {
public:
// ---------- Constructors and Assignment:
inline HepBoost();
// Default constructor. Gives a boost of 0.
inline HepBoost(const HepBoost & m);
// Copy constructor.
inline HepBoost & operator = (const HepBoost & m);
// Assignment.
HepBoost & set (double betaX, double betaY, double betaZ);
inline HepBoost (double betaX, double betaY, double betaZ);
// Constructor from three components of beta vector
HepBoost & set (const HepRep4x4Symmetric & m);
inline HepBoost (const HepRep4x4Symmetric & m);
// Constructor from symmetric HepRep4x4
HepBoost & set (Hep3Vector direction, double beta);
inline HepBoost (Hep3Vector direction, double beta);
// Constructor from a three vector direction and the magnitude of beta
HepBoost & set (const Hep3Vector & boost);
inline HepBoost (const Hep3Vector & boost);
// Constructor from a 3-vector of less than unit length
inline HepBoost & set (const HepBoostX & boost);
inline HepBoost & set (const HepBoostY & boost);
inline HepBoost & set (const HepBoostZ & boost);
inline HepBoost (const HepBoostX & boost);
inline HepBoost (const HepBoostY & boost);
inline HepBoost (const HepBoostZ & boost);
// ---------- Accessors:
inline double beta() const;
inline double gamma() const;
inline Hep3Vector boostVector() const;
inline Hep3Vector getDirection() const;
inline Hep3Vector direction() const;
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double xt() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double yt() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
inline double tt() const;
// Elements of the matrix.
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
inline HepLorentzVector col4() const;
// orthosymplectic column vectors
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
inline HepLorentzVector row4() const;
// orthosymplectic row vectors
inline HepRep4x4 rep4x4() const;
// 4x4 representation.
inline HepRep4x4Symmetric rep4x4Symmetric() const;
// Symmetric 4x4 representation.
// ---------- Decomposition:
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
// Find R and B such that L = R*B -- trivial, since R is identity
void decompose (HepBoost & boost, HepRotation & rotation) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
// Find R and B such that L = B*R -- trivial, since R is identity
// ---------- Comparisons:
inline int compare( const HepBoost & b ) const;
// Dictionary-order comparison, in order tt,zt,zz,yt,yz,yy,xt,xz,xy,xx
// Used in operator<, >, <=, >=
inline bool operator == (const HepBoost & b) const;
inline bool operator != (const HepBoost & b) const;
inline bool operator <= (const HepBoost & b) const;
inline bool operator >= (const HepBoost & b) const;
inline bool operator < (const HepBoost & b) const;
inline bool operator > (const HepBoost & b) const;
// Comparisons.
inline bool isIdentity() const;
// Returns true if a null boost.
inline double distance2( const HepBoost & b ) const;
inline double distance2( const HepBoostX & bx ) const;
inline double distance2( const HepBoostY & by ) const;
inline double distance2( const HepBoostZ & bz ) const;
// Defined as the distance2 between the vectors (gamma*betaVector)
double distance2( const HepRotation & r ) const;
double distance2( const HepLorentzRotation & lt ) const;
// Distance between this and other sorts of transformations
inline double howNear( const HepBoost & b ) const;
inline bool isNear( const HepBoost & b,
double epsilon=Hep4RotationInterface::tolerance) const;
double howNear( const HepRotation & r ) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// (beta*gamma)^2
void rectify();
// set as an exact boost, based on the timelike part of the boost matrix.
// ---------- Application:
inline HepLorentzVector operator()( const HepLorentzVector & p ) const;
// Transform a Lorentz Vector.
inline HepLorentzVector operator* ( const HepLorentzVector & p ) const;
// Multiplication with a Lorentz Vector.
// ---------- Operations in the group of 4-Rotations
HepLorentzRotation operator * (const HepBoost & b) const;
HepLorentzRotation operator * (const HepRotation & r) const;
HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
// Product of two Lorentz Rotations (this) * lt - matrix multiplication
// Notice that the product of two pure boosts is no longer a pure boost
inline HepBoost inverse() const;
// Return the inverse.
inline friend HepBoost inverseOf ( const HepBoost & lt );
// global methods to invert.
inline HepBoost & invert();
// Inverts the Boost matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output form is (bx, by, bz)
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
inline HepLorentzVector vectorMultiplication
( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
HepLorentzRotation matrixMultiplication (const HepRep4x4 & m) const;
HepLorentzRotation matrixMultiplication (const HepRep4x4Symmetric & m) const;
inline HepBoost
(double xx, double xy, double xz, double xt,
double yy, double yz, double yt,
double zz, double zt,
double tt);
// Protected constructor.
// DOES NOT CHECK FOR VALIDITY AS A LORENTZ BOOST.
inline void setBoost(double bx, double by, double bz);
HepRep4x4Symmetric rep_;
}; // HepBoost
inline
std::ostream & operator <<
( std::ostream & os, const HepBoost& b ) {return b.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/Boost.icc"
#endif /* HEP_BOOST_H */
+291
View File
@@ -0,0 +1,291 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepBoost class
//
#include <cmath>
namespace CLHEP {
// ---------- Constructors and Assignment:
inline HepBoost::HepBoost() : rep_() {}
inline HepBoost::HepBoost(const HepBoost & m) : rep_(m.rep_) {}
inline HepBoost & HepBoost::operator = (const HepBoost & m) {
rep_ = m.rep_;
return *this;
}
inline HepBoost::HepBoost(double betaX, double betaY, double betaZ)
{
set(betaX, betaY, betaZ);
}
inline HepBoost::HepBoost(const HepRep4x4Symmetric & m) : rep_(m) {}
inline HepBoost::HepBoost(Hep3Vector direction, double beta)
{
double length = direction.mag();
if (length==0) {
std::cerr << "HepBoost::HepBoost() - "
<< "HepBoost constructed using a zero vector as direction"
<< std::endl;
set(0,0,0);
}
set(beta*direction.x()/length,
beta*direction.y()/length,
beta*direction.z()/length);
}
inline HepBoost::HepBoost(const Hep3Vector & boost)
{
set(boost.x(), boost.y(), boost.z());
}
inline HepBoost::HepBoost(const HepBoostX & boost) {set(boost.boostVector());}
inline HepBoost::HepBoost(const HepBoostY & boost) {set(boost.boostVector());}
inline HepBoost::HepBoost(const HepBoostZ & boost) {set(boost.boostVector());}
inline HepBoost & HepBoost::set(const HepBoostX & boost)
{return set(boost.boostVector());}
inline HepBoost & HepBoost::set(const HepBoostY & boost)
{return set(boost.boostVector());}
inline HepBoost & HepBoost::set(const HepBoostZ & boost)
{return set(boost.boostVector());}
// - Protected method:
inline HepBoost::HepBoost (
double xx, double xy, double xz, double xt,
double yy, double yz, double yt,
double zz, double zt,
double tt) :
rep_ ( xx, xy, xz, xt, yy, yz, yt, zz, zt, tt ) {}
// ---------- Accessors:
inline double HepBoost::beta() const {
return std::sqrt( 1.0 - 1.0 / (rep_.tt_ * rep_.tt_) );
}
inline double HepBoost::gamma() const {
return rep_.tt_;
}
inline Hep3Vector HepBoost::boostVector() const {
return (1.0/rep_.tt_) * Hep3Vector( rep_.xt_, rep_.yt_, rep_.zt_ );
}
inline Hep3Vector HepBoost::getDirection() const {
double norm = 1.0/beta();
return (norm*boostVector());
}
inline Hep3Vector HepBoost::direction() const {
return getDirection();
}
inline double HepBoost::xx() const { return rep_.xx_; }
inline double HepBoost::xy() const { return rep_.xy_; }
inline double HepBoost::xz() const { return rep_.xz_; }
inline double HepBoost::xt() const { return rep_.xt_; }
inline double HepBoost::yx() const { return rep_.xy_; }
inline double HepBoost::yy() const { return rep_.yy_; }
inline double HepBoost::yz() const { return rep_.yz_; }
inline double HepBoost::yt() const { return rep_.yt_; }
inline double HepBoost::zx() const { return rep_.xz_; }
inline double HepBoost::zy() const { return rep_.yz_; }
inline double HepBoost::zz() const { return rep_.zz_; }
inline double HepBoost::zt() const { return rep_.zt_; }
inline double HepBoost::tx() const { return rep_.xt_; }
inline double HepBoost::ty() const { return rep_.yt_; }
inline double HepBoost::tz() const { return rep_.zt_; }
inline double HepBoost::tt() const { return rep_.tt_; }
inline HepLorentzVector HepBoost::col1() const {
return HepLorentzVector ( xx(), yx(), zx(), tx() );
}
inline HepLorentzVector HepBoost::col2() const {
return HepLorentzVector ( xy(), yy(), zy(), ty() );
}
inline HepLorentzVector HepBoost::col3() const {
return HepLorentzVector ( xz(), yz(), zz(), tz() );
}
inline HepLorentzVector HepBoost::col4() const {
return HepLorentzVector ( xt(), yt(), zt(), tt() );
}
inline HepLorentzVector HepBoost::row1() const {
return HepLorentzVector ( col1() );
}
inline HepLorentzVector HepBoost::row2() const {
return HepLorentzVector ( col2() );
}
inline HepLorentzVector HepBoost::row3() const {
return HepLorentzVector ( col3() );
}
inline HepLorentzVector HepBoost::row4() const {
return HepLorentzVector ( col4() );
}
inline HepRep4x4 HepBoost::rep4x4() const {
return HepRep4x4( rep_ );
}
inline HepRep4x4Symmetric HepBoost::rep4x4Symmetric() const {
return rep_;
}
inline void HepBoost::setBoost(double bx, double by, double bz) {
set(bx, by, bz);
}
// ---------- Comparisons:
int HepBoost::compare ( const HepBoost & b ) const {
const HepRep4x4Symmetric & s = b.rep4x4Symmetric();
if (rep_.tt_ < s.tt_) return -1; else if (rep_.tt_ > s.tt_) return 1;
else if (rep_.zt_ < s.zt_) return -1; else if (rep_.zt_ > s.zt_) return 1;
else if (rep_.zz_ < s.zz_) return -1; else if (rep_.zz_ > s.zz_) return 1;
else if (rep_.yt_ < s.yt_) return -1; else if (rep_.yt_ > s.yt_) return 1;
else if (rep_.yz_ < s.yz_) return -1; else if (rep_.yz_ > s.yz_) return 1;
else if (rep_.yy_ < s.yy_) return -1; else if (rep_.yy_ > s.yy_) return 1;
else if (rep_.xt_ < s.xt_) return -1; else if (rep_.xt_ > s.xt_) return 1;
else if (rep_.xz_ < s.xz_) return -1; else if (rep_.xz_ > s.xz_) return 1;
else if (rep_.xy_ < s.xy_) return -1; else if (rep_.xy_ > s.xy_) return 1;
else if (rep_.xx_ < s.xx_) return -1; else if (rep_.xx_ > s.xx_) return 1;
else return 0;
}
inline bool
HepBoost::operator == (const HepBoost & b) const {
const HepRep4x4Symmetric & s = b.rep4x4Symmetric();
return (
rep_.xx_==s.xx_ && rep_.xy_==s.xy_ && rep_.xz_==s.xz_ && rep_.xt_==s.xt_
&& rep_.yy_==s.yy_ && rep_.yz_==s.yz_ && rep_.yt_==s.yt_
&& rep_.zz_==s.zz_ && rep_.zt_==s.zt_
&& rep_.tt_==s.tt_
);
}
inline bool
HepBoost::operator != (const HepBoost & r) const {
return ( !(operator==(r)) );
}
inline bool HepBoost::operator <= ( const HepBoost & b ) const
{ return compare(b)<= 0; }
inline bool HepBoost::operator >= ( const HepBoost & b ) const
{ return compare(b)>= 0; }
inline bool HepBoost::operator < ( const HepBoost & b ) const
{ return compare(b)< 0; }
inline bool HepBoost::operator > ( const HepBoost & b ) const
{ return compare(b)> 0; }
inline bool HepBoost::isIdentity() const {
return (xx() == 1.0 && xy() == 0.0 && xz() == 0.0 && xt() == 0.0
&& yy() == 1.0 && yz() == 0.0 && yt() == 0.0
&& zz() == 1.0 && zt() == 0.0
&& tt() == 1.0);
}
inline double HepBoost::distance2( const HepBoost & b ) const {
double bgx = rep_.xt_ - b.rep_.xt_;
double bgy = rep_.yt_ - b.rep_.yt_;
double bgz = rep_.zt_ - b.rep_.zt_;
return bgx*bgx+bgy*bgy+bgz*bgz;
}
inline double HepBoost::distance2( const HepBoostX & bx ) const {
double bgx = rep_.xt_ - bx.beta()*bx.gamma();
double bgy = rep_.yt_;
double bgz = rep_.zt_;
return bgx*bgx+bgy*bgy+bgz*bgz;
}
inline double HepBoost::distance2( const HepBoostY & by ) const {
double bgy = rep_.xt_;
double bgx = rep_.yt_ - by.beta()*by.gamma();
double bgz = rep_.zt_;
return bgx*bgx+bgy*bgy+bgz*bgz;
}
inline double HepBoost::distance2( const HepBoostZ & bz ) const {
double bgz = rep_.xt_;
double bgy = rep_.yt_;
double bgx = rep_.zt_ - bz.beta()*bz.gamma();
return bgx*bgx+bgy*bgy+bgz*bgz;
}
inline double HepBoost::howNear ( const HepBoost & b ) const {
return std::sqrt(distance2(b));
}
inline bool HepBoost::isNear(const HepBoost & b, double epsilon) const{
return (distance2(b) <= epsilon*epsilon);
}
// ---------- Application:
// - Protected method:
inline HepLorentzVector
HepBoost::vectorMultiplication(const HepLorentzVector & p) const {
register double x = p.x();
register double y = p.y();
register double z = p.z();
register double t = p.t();
return HepLorentzVector( rep_.xx_*x + rep_.xy_*y + rep_.xz_*z + rep_.xt_*t,
rep_.xy_*x + rep_.yy_*y + rep_.yz_*z + rep_.yt_*t,
rep_.xz_*x + rep_.yz_*y + rep_.zz_*z + rep_.zt_*t,
rep_.xt_*x + rep_.yt_*y + rep_.zt_*z + rep_.tt_*t);
}
inline HepLorentzVector
HepBoost::operator () (const HepLorentzVector & p) const {
return vectorMultiplication(p);
}
inline HepLorentzVector
HepBoost::operator * (const HepLorentzVector & p) const {
return vectorMultiplication(p);
}
// ---------- Operations in the group of 4-Rotations
inline HepBoost HepBoost::inverse() const {
return HepBoost( xx(), yx(), zx(), -tx(),
yy(), zy(), -ty(),
zz(), -tz(),
tt());
}
inline HepBoost inverseOf ( const HepBoost & lt ) {
return HepBoost( lt.xx(), lt.yx(), lt.zx(), -lt.tx(),
lt.yy(), lt.zy(), -lt.ty(),
lt.zz(), -lt.tz(),
lt.tt());
}
inline HepBoost & HepBoost::invert() {
rep_.xt_ = -rep_.xt_;
rep_.yt_ = -rep_.yt_;
rep_.zt_ = -rep_.zt_;
return *this;
}
// ---------- Tolerance:
inline double HepBoost::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepBoost::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
+221
View File
@@ -0,0 +1,221 @@
// -*- C++ -*-
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepBoostX class for performing specialized
// Lorentz transformations which are pure boosts in the X direction, on
// objects of the HepLorentzVector class.
//
// HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// LorentzVector.h LorentzRotation.h
// Boost.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_BOOSTX_H
#define HEP_BOOSTX_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepBoostX;
inline HepBoostX inverseOf ( const HepBoostX & b );
class HepBoost;
class HepRotation;
/**
* @author
* @ingroup vector
*/
class HepBoostX {
public:
// ---------- Constructors and Assignment:
inline HepBoostX();
// Default constructor. Gives a boost of 0.
inline HepBoostX(const HepBoostX & b);
// Copy constructor.
inline HepBoostX & operator = (const HepBoostX & m);
// Assignment.
HepBoostX & set (double beta);
inline HepBoostX (double beta);
// Constructor from beta
// ---------- Accessors:
inline double beta() const;
inline double gamma() const;
inline Hep3Vector boostVector() const;
inline Hep3Vector getDirection() const;
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double xt() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double yt() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
inline double tt() const;
// Elements of the matrix.
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
inline HepLorentzVector col4() const;
// orthosymplectic column vectors
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
inline HepLorentzVector row4() const;
// orthosymplectic row vectors
HepRep4x4 rep4x4() const;
// 4x4 representation:
HepRep4x4Symmetric rep4x4Symmetric() const;
// Symmetric 4x4 representation.
// ---------- Decomposition:
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
// Find R and B such that L = R*B -- trivial, since R is identity
void decompose ( HepBoost & boost, HepRotation & rotation) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
// Find R and B such that L = B*R -- trivial, since R is identity
// ---------- Comparisons:
inline int compare( const HepBoostX & b ) const;
// Dictionary-order comparison, in order of beta.
// Used in operator<, >, <=, >=
inline bool operator == (const HepBoostX & b) const;
inline bool operator != (const HepBoostX & b) const;
inline bool operator <= (const HepBoostX & b) const;
inline bool operator >= (const HepBoostX & b) const;
inline bool operator < (const HepBoostX & b) const;
inline bool operator > (const HepBoostX & b) const;
// Comparisons.
inline bool isIdentity() const;
// Returns true if a null boost.
inline double distance2( const HepBoostX & b ) const;
double distance2( const HepBoost & b ) const;
// Defined as the distance2 between the vectors (gamma*betaVector)
double distance2( const HepRotation & r ) const;
double distance2( const HepLorentzRotation & lt ) const;
// Decompose lt = B*R; add norm2 to distance2 to between boosts.
inline double howNear( const HepBoostX & b ) const;
inline double howNear( const HepBoost & b ) const;
inline double howNear( const HepRotation & r ) const;
inline double howNear( const HepLorentzRotation & lt ) const;
inline bool isNear( const HepBoostX & b,
double epsilon=Hep4RotationInterface::tolerance) const;
inline bool isNear( const HepBoost & b,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
inline double norm2() const;
// distance2 (IDENTITY), which is beta^2 * gamma^2
void rectify();
// sets according to the stored beta
// ---------- Application:
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Transform a Lorentz Vector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
// ---------- Operations in the group of 4-Rotations
HepBoostX operator * (const HepBoostX & b) const;
HepLorentzRotation operator * (const HepBoost & b) const;
HepLorentzRotation operator * (const HepRotation & r) const;
HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
// Product of two Lorentz Rotations (this) * lt - matrix multiplication
// Notice that the product of two pure boosts in different directions
// is no longer a pure boost.
inline HepBoostX inverse() const;
// Return the inverse.
inline friend HepBoostX inverseOf ( const HepBoostX & b );
// global methods to invert.
inline HepBoostX & invert();
// Inverts the Boost matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output form is BOOSTX (beta=..., gamma=...);
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
inline HepLorentzVector vectorMultiplication
( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
HepLorentzRotation matrixMultiplication (const HepRep4x4 & m) const;
HepLorentzRotation matrixMultiplication (const HepRep4x4Symmetric & m) const;
inline HepBoostX (double beta, double gamma);
double beta_;
double gamma_;
}; // HepBoostX
inline
std::ostream & operator <<
( std::ostream & os, const HepBoostX& b ) {return b.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/BoostX.icc"
#endif /* HEP_BOOSTX_H */
+200
View File
@@ -0,0 +1,200 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepBoostX class
//
#include <cmath>
namespace CLHEP {
// ---------- Constructors and Assignment:
inline HepBoostX::HepBoostX() : beta_(0.0), gamma_(1.0) {}
inline HepBoostX::HepBoostX(const HepBoostX & b) :
beta_ (b.beta_),
gamma_(b.gamma_) {}
inline HepBoostX & HepBoostX::operator = (const HepBoostX & b) {
beta_ = b.beta_;
gamma_ = b.gamma_;
return *this;
}
inline HepBoostX::HepBoostX(double beta) { set(beta); }
// - Protected method:
inline HepBoostX::HepBoostX( double beta, double gamma ) :
beta_(beta), gamma_(gamma) {}
// ---------- Accessors:
inline double HepBoostX::beta() const {
return beta_;
}
inline double HepBoostX::gamma() const {
return gamma_;
}
inline Hep3Vector HepBoostX::boostVector() const {
return Hep3Vector( beta_, 0, 0 );
}
inline Hep3Vector HepBoostX::getDirection() const {
return Hep3Vector(1.0, 0.0, 0.0);
}
inline double HepBoostX::xx() const { return gamma();}
inline double HepBoostX::xy() const { return 0.0;}
inline double HepBoostX::xz() const { return 0.0;}
inline double HepBoostX::xt() const { return beta()*gamma();}
inline double HepBoostX::yx() const { return 0.0;}
inline double HepBoostX::yy() const { return 1.0;}
inline double HepBoostX::yz() const { return 0.0;}
inline double HepBoostX::yt() const { return 0.0;}
inline double HepBoostX::zx() const { return 0.0;}
inline double HepBoostX::zy() const { return 0.0;}
inline double HepBoostX::zz() const { return 1.0;}
inline double HepBoostX::zt() const { return 0.0;}
inline double HepBoostX::tx() const { return beta()*gamma();}
inline double HepBoostX::ty() const { return 0.0;}
inline double HepBoostX::tz() const { return 0.0;}
inline double HepBoostX::tt() const { return gamma();}
inline HepLorentzVector HepBoostX::col1() const {
return HepLorentzVector ( gamma(), 0, 0, beta()*gamma() );
}
inline HepLorentzVector HepBoostX::col2() const {
return HepLorentzVector ( 0, 1, 0, 0 );
}
inline HepLorentzVector HepBoostX::col3() const {
return HepLorentzVector ( 0, 0, 1, 0 );
}
inline HepLorentzVector HepBoostX::col4() const {
return HepLorentzVector ( beta()*gamma(), 0, 0, gamma() );
}
inline HepLorentzVector HepBoostX::row1() const {
return HepLorentzVector ( col1() );
}
inline HepLorentzVector HepBoostX::row2() const {
return HepLorentzVector ( col2() );
}
inline HepLorentzVector HepBoostX::row3() const {
return HepLorentzVector ( col3() );
}
inline HepLorentzVector HepBoostX::row4() const {
return HepLorentzVector ( col4() );
}
// ---------- Comparisons:
inline int HepBoostX::compare( const HepBoostX & b ) const {
if (beta() < b.beta()) {
return -1;
} else if (beta() > b.beta()) {
return 1;
} else {
return 0;
}
}
inline bool HepBoostX::operator == ( const HepBoostX & b ) const {
return beta_ == b.beta_;
}
inline bool HepBoostX::operator != ( const HepBoostX & b ) const {
return beta_ != b.beta_;
}
inline bool HepBoostX::operator <= ( const HepBoostX & b ) const {
return beta_ <= b.beta_;
}
inline bool HepBoostX::operator >= ( const HepBoostX & b ) const {
return beta_ >= b.beta_;
}
inline bool HepBoostX::operator < ( const HepBoostX & b ) const {
return beta_ < b.beta_;
}
inline bool HepBoostX::operator > ( const HepBoostX & b ) const {
return beta_ > b.beta_;
}
inline bool HepBoostX::isIdentity() const {
return ( beta() == 0 );
}
inline double HepBoostX::distance2( const HepBoostX & b ) const {
double d = beta()*gamma() - b.beta()*b.gamma();
return d*d;
}
inline double HepBoostX::howNear(const HepBoostX & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostX::howNear(const HepBoost & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostX::howNear(const HepRotation & r) const {
return std::sqrt(distance2(r)); }
inline double HepBoostX::howNear(const HepLorentzRotation & lt) const {
return std::sqrt(distance2(lt)); }
inline bool HepBoostX::isNear(const HepBoostX & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
inline bool HepBoostX::isNear(const HepBoost & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
// ---------- Properties:
inline double HepBoostX::norm2() const {
register double bg = beta_*gamma_;
return bg*bg;
}
// ---------- Application:
inline HepLorentzVector
HepBoostX::operator * (const HepLorentzVector & p) const {
double bg = beta_*gamma_;
return HepLorentzVector(gamma_*p.x() + bg*p.t(),
p.y(),
p.z(),
gamma_*p.t() + bg*p.x());
}
inline HepLorentzVector
HepBoostX::operator() (const HepLorentzVector & w) const {
return operator*(w);
}
// ---------- Operations in the group of 4-Rotations
inline HepBoostX HepBoostX::inverse() const {
return HepBoostX( -beta(), gamma() );
}
inline HepBoostX inverseOf ( const HepBoostX & b ) {
return HepBoostX( -b.beta(), b.gamma());
}
inline HepBoostX & HepBoostX::invert() {
beta_ = -beta_;
return *this;
}
// ---------- Tolerance:
inline double HepBoostX::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepBoostX::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
+222
View File
@@ -0,0 +1,222 @@
// -*- C++ -*-
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepBoostY class for performing specialized
// Lorentz transformations which are pure boosts in the Y direction, on
// objects of the HepLorentzVector class.
//
// HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// LorentzVector.h LorentzRotation.h
// Boost.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_BOOSTY_H
#define HEP_BOOSTY_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepBoostY;
inline HepBoostY inverseOf ( const HepBoostY & b );
class HepBoost;
class HepRotation;
/**
* @author
* @ingroup vector
*/
class HepBoostY {
public:
// ---------- Constructors and Assignment:
inline HepBoostY();
// Default constructor. Gives a boost of 0.
inline HepBoostY(const HepBoostY & b);
// Copy constructor.
inline HepBoostY & operator = (const HepBoostY & m);
// Assignment.
HepBoostY & set (double beta);
inline HepBoostY (double beta);
// Constructor from beta
// ---------- Accessors:
inline double beta() const;
inline double gamma() const;
inline Hep3Vector boostVector() const;
inline Hep3Vector getDirection() const;
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double xt() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double yt() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
inline double tt() const;
// Elements of the matrix.
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
inline HepLorentzVector col4() const;
// orthosymplectic column vectors
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
inline HepLorentzVector row4() const;
// orthosymplectic row vectors
HepRep4x4 rep4x4() const;
// 4x4 representation:
HepRep4x4Symmetric rep4x4Symmetric() const;
// Symmetric 4x4 representation.
// ---------- Decomposition:
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
// Find R and B such that L = R*B -- trivial, since R is identity
void decompose (HepBoost & boost, HepRotation & rotation) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
// Find R and B such that L = B*R -- trivial, since R is identity
// ---------- Comparisons:
inline int compare( const HepBoostY & b ) const;
// Dictionary-order comparison, in order of beta.
// Used in operator<, >, <=, >=
inline bool operator == (const HepBoostY & b) const;
inline bool operator != (const HepBoostY & b) const;
inline bool operator <= (const HepBoostY & b) const;
inline bool operator >= (const HepBoostY & b) const;
inline bool operator < (const HepBoostY & b) const;
inline bool operator > (const HepBoostY & b) const;
// Comparisons.
inline bool isIdentity() const;
// Returns true if a null boost.
inline double distance2( const HepBoostY & b ) const;
double distance2( const HepBoost & b ) const;
// Defined as the distance2 between the vectors (gamma*betaVector)
double distance2( const HepRotation & r ) const;
double distance2( const HepLorentzRotation & lt ) const;
// Decompose lt = B*R; add norm2 to distance2 to between boosts.
inline double howNear( const HepBoostY & b ) const;
inline double howNear( const HepBoost & b ) const;
inline double howNear( const HepRotation & r ) const;
inline double howNear( const HepLorentzRotation & lt ) const;
inline bool isNear( const HepBoostY & b,
double epsilon=Hep4RotationInterface::tolerance) const;
inline bool isNear( const HepBoost & b,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
inline double norm2() const;
// distance2 (IDENTITY), which is beta^2 * gamma^2
void rectify();
// sets according to the stored beta
// ---------- Application:
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Transform a Lorentz Vector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
// ---------- Operations in the group of 4-Rotations
HepBoostY operator * (const HepBoostY & b) const;
HepLorentzRotation operator * (const HepBoost & b) const;
HepLorentzRotation operator * (const HepRotation & r) const;
HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
// Product of two Lorentz Rotations (this) * lt - matrix multiplication
// Notice that the product of two pure boosts in different directions
// is no longer a pure boost.
inline HepBoostY inverse() const;
// Return the inverse.
inline friend HepBoostY inverseOf ( const HepBoostY & b );
// global methods to invert.
inline HepBoostY & invert();
// Inverts the Boost matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output form is BOOSTY (beta=..., gamma=...);
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
inline HepLorentzVector vectorMultiplication
( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
HepLorentzRotation matrixMultiplication (const HepRep4x4 & m) const;
HepLorentzRotation matrixMultiplication (const HepRep4x4Symmetric & m) const;
inline HepBoostY (double beta, double gamma);
double beta_;
double gamma_;
}; // HepBoostY
inline
std::ostream & operator <<
( std::ostream & os, const HepBoostY& b ) {return b.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/BoostY.icc"
#endif /* HEP_BOOSTY_H */
+199
View File
@@ -0,0 +1,199 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepBoostY class
//
#include <cmath>
namespace CLHEP {
// ---------- Constructors and Assignment:
inline HepBoostY::HepBoostY() : beta_(0.0), gamma_(1.0) {}
inline HepBoostY::HepBoostY(const HepBoostY & b) :
beta_ (b.beta_),
gamma_(b.gamma_) {}
inline HepBoostY & HepBoostY::operator = (const HepBoostY & b) {
beta_ = b.beta_;
gamma_ = b.gamma_;
return *this;
}
inline HepBoostY::HepBoostY(double beta) { set(beta); }
// - Protected method:
inline HepBoostY::HepBoostY( double beta, double gamma ) :
beta_(beta), gamma_(gamma) {}
// ---------- Accessors:
inline double HepBoostY::beta() const {
return beta_;
}
inline double HepBoostY::gamma() const {
return gamma_;
}
inline Hep3Vector HepBoostY::boostVector() const {
return Hep3Vector( 0, beta_, 0 );
}
inline Hep3Vector HepBoostY::getDirection() const {
return Hep3Vector( 0.0, 1.0, 0.0 );
}
inline double HepBoostY::xx() const { return 1.0;}
inline double HepBoostY::xy() const { return 0.0;}
inline double HepBoostY::xz() const { return 0.0;}
inline double HepBoostY::xt() const { return 0.0;}
inline double HepBoostY::yx() const { return 0.0;}
inline double HepBoostY::yy() const { return gamma();}
inline double HepBoostY::yz() const { return 0.0;}
inline double HepBoostY::yt() const { return beta()*gamma();}
inline double HepBoostY::zx() const { return 0.0;}
inline double HepBoostY::zy() const { return 0.0;}
inline double HepBoostY::zz() const { return 1.0;}
inline double HepBoostY::zt() const { return 0.0;}
inline double HepBoostY::tx() const { return 0.0;}
inline double HepBoostY::ty() const { return beta()*gamma();}
inline double HepBoostY::tz() const { return 0.0;}
inline double HepBoostY::tt() const { return gamma();}
inline HepLorentzVector HepBoostY::col1() const {
return HepLorentzVector ( 1, 0, 0, 0 );
}
inline HepLorentzVector HepBoostY::col2() const {
return HepLorentzVector ( 0, gamma(), 0, beta()*gamma() );
}
inline HepLorentzVector HepBoostY::col3() const {
return HepLorentzVector ( 0, 0, 1, 0 );
}
inline HepLorentzVector HepBoostY::col4() const {
return HepLorentzVector ( 0, beta()*gamma(), 0, gamma() );
}
inline HepLorentzVector HepBoostY::row1() const {
return HepLorentzVector ( col1() );
}
inline HepLorentzVector HepBoostY::row2() const {
return HepLorentzVector ( col2() );
}
inline HepLorentzVector HepBoostY::row3() const {
return HepLorentzVector ( col3() );
}
inline HepLorentzVector HepBoostY::row4() const {
return HepLorentzVector ( col4() );
}
// ---------- Comparisons:
inline int HepBoostY::compare( const HepBoostY & b ) const {
if (beta() < b.beta()) {
return -1;
} else if (beta() > b.beta()) {
return 1;
} else {
return 0;
}
}
inline bool HepBoostY::operator == ( const HepBoostY & b ) const {
return beta_ == b.beta_;
}
inline bool HepBoostY::operator != ( const HepBoostY & b ) const {
return beta_ != b.beta_;
}
inline bool HepBoostY::operator <= ( const HepBoostY & b ) const {
return beta_ <= b.beta_;
}
inline bool HepBoostY::operator >= ( const HepBoostY & b ) const {
return beta_ >= b.beta_;
}
inline bool HepBoostY::operator < ( const HepBoostY & b ) const {
return beta_ < b.beta_;
}
inline bool HepBoostY::operator > ( const HepBoostY & b ) const {
return beta_ > b.beta_;
}
inline bool HepBoostY::isIdentity() const {
return ( beta() == 0 );
}
inline double HepBoostY::distance2( const HepBoostY & b ) const {
double d = beta()*gamma() - b.beta()*b.gamma();
return d*d;
}
inline double HepBoostY::howNear(const HepBoostY & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostY::howNear(const HepBoost & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostY::howNear(const HepRotation & r) const {
return std::sqrt(distance2(r)); }
inline double HepBoostY::howNear(const HepLorentzRotation & lt) const {
return std::sqrt(distance2(lt)); }
inline bool HepBoostY::isNear(const HepBoostY & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
inline bool HepBoostY::isNear(const HepBoost & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
// ---------- Properties:
double HepBoostY::norm2() const {
register double bg = beta_*gamma_;
return bg*bg;
}
// ---------- Application:
inline HepLorentzVector
HepBoostY::operator * (const HepLorentzVector & p) const {
double bg = beta_*gamma_;
return HepLorentzVector( p.x(),
gamma_*p.y() + bg*p.t(),
p.z(),
gamma_*p.t() + bg*p.y());
}
HepLorentzVector HepBoostY::operator() (const HepLorentzVector & w) const {
return operator*(w);
}
// ---------- Operations in the group of 4-Rotations
inline HepBoostY HepBoostY::inverse() const {
return HepBoostY( -beta(), gamma() );
}
inline HepBoostY inverseOf ( const HepBoostY & b ) {
return HepBoostY( -b.beta(), b.gamma());
}
inline HepBoostY & HepBoostY::invert() {
beta_ = -beta_;
return *this;
}
// ---------- Tolerance:
inline double HepBoostY::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepBoostY::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
+221
View File
@@ -0,0 +1,221 @@
// -*- C++ -*-
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepBoostZ class for performing specialized
// Lorentz transformations which are pure boosts in the Z direction, on
// objects of the HepLorentzVector class.
//
// HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// LorentzVector.h LorentzRotation.h
// Boost.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_BOOSTZ_H
#define HEP_BOOSTZ_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepBoostZ;
inline HepBoostZ inverseOf ( const HepBoostZ & b );
class HepBoost;
class HepRotation;
/**
* @author
* @ingroup vector
*/
class HepBoostZ {
public:
// ---------- Constructors and Assignment:
inline HepBoostZ();
// Default constructor. Gives a boost of 0.
inline HepBoostZ(const HepBoostZ & b);
// Copy constructor.
inline HepBoostZ & operator = (const HepBoostZ & m);
// Assignment.
HepBoostZ & set (double beta);
inline HepBoostZ (double beta);
// Constructor from beta
// ---------- Accessors:
inline double beta() const;
inline double gamma() const;
inline Hep3Vector boostVector() const;
inline Hep3Vector getDirection() const;
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double xt() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double yt() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
inline double tt() const;
// Elements of the matrix.
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
inline HepLorentzVector col4() const;
// orthosymplectic column vectors
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
inline HepLorentzVector row4() const;
// orthosymplectic row vectors
HepRep4x4 rep4x4() const;
// 4x4 representation:
HepRep4x4Symmetric rep4x4Symmetric() const;
// Symmetric 4x4 representation.
// ---------- Decomposition:
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
// Find R and B such that L = R*B -- trivial, since R is identity
void decompose (HepBoost & boost, HepRotation & rotation) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
// Find R and B such that L = B*R -- trivial, since R is identity
// ---------- Comparisons:
inline int compare( const HepBoostZ & b ) const;
// Dictionary-order comparison, in order of beta.
// Used in operator<, >, <=, >=
inline bool operator == (const HepBoostZ & b) const;
inline bool operator != (const HepBoostZ & b) const;
inline bool operator <= (const HepBoostZ & b) const;
inline bool operator >= (const HepBoostZ & b) const;
inline bool operator < (const HepBoostZ & b) const;
inline bool operator > (const HepBoostZ & b) const;
// Comparisons.
inline bool isIdentity() const;
// Returns true if a null boost.
inline double distance2( const HepBoostZ & b ) const;
double distance2( const HepBoost & b ) const;
// Defined as the distance2 between the vectors (gamma*betaVector)
double distance2( const HepRotation & r ) const;
double distance2( const HepLorentzRotation & lt ) const;
// Decompose lt = B*R; add norm2 to distance2 to between boosts.
inline double howNear( const HepBoostZ & b ) const;
inline double howNear( const HepBoost & b ) const;
inline double howNear( const HepRotation & r ) const;
inline double howNear( const HepLorentzRotation & lt ) const;
inline bool isNear( const HepBoostZ & b,
double epsilon=Hep4RotationInterface::tolerance) const;
inline bool isNear( const HepBoost & b,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
inline double norm2() const;
// distance2 (IDENTITY), which is beta^2 * gamma^2
void rectify();
// sets according to the stored beta
// ---------- Application:
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Transform a Lorentz Vector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
// ---------- Operations in the group of 4-Rotations
HepBoostZ operator * (const HepBoostZ & b) const;
HepLorentzRotation operator * (const HepBoost & b) const;
HepLorentzRotation operator * (const HepRotation & r) const;
HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
// Product of two Lorentz Rotations (this) * lt - matrix multiplication
// Notice that the product of two pure boosts in different directions
// is no longer a pure boost.
inline HepBoostZ inverse() const;
// Return the inverse.
inline friend HepBoostZ inverseOf ( const HepBoostZ & b );
// global methods to invert.
inline HepBoostZ & invert();
// Inverts the Boost matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output form is BOOSTZ (beta=..., gamma=...);
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
inline HepLorentzVector vectorMultiplication
( const HepLorentzVector & w ) const;
// Multiplication with a Lorentz Vector.
HepLorentzRotation matrixMultiplication (const HepRep4x4 & m) const;
HepLorentzRotation matrixMultiplication (const HepRep4x4Symmetric & m) const;
inline HepBoostZ (double beta, double gamma);
double beta_;
double gamma_;
}; // HepBoostZ
inline
std::ostream & operator <<
( std::ostream & os, const HepBoostZ& b ) {return b.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/BoostZ.icc"
#endif /* HEP_BOOSTZ_H */
+199
View File
@@ -0,0 +1,199 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepBoostZ class
//
#include <cmath>
namespace CLHEP {
// ---------- Constructors and Assignment:
inline HepBoostZ::HepBoostZ() : beta_(0.0), gamma_(1.0) {}
inline HepBoostZ::HepBoostZ(const HepBoostZ & b) :
beta_ (b.beta_),
gamma_(b.gamma_) {}
inline HepBoostZ & HepBoostZ::operator = (const HepBoostZ & b) {
beta_ = b.beta_;
gamma_ = b.gamma_;
return *this;
}
inline HepBoostZ::HepBoostZ(double beta) { set(beta); }
// - Protected method:
inline HepBoostZ::HepBoostZ( double beta, double gamma ) :
beta_(beta), gamma_(gamma) {}
// ---------- Accessors:
inline double HepBoostZ::beta() const {
return beta_;
}
inline double HepBoostZ::gamma() const {
return gamma_;
}
inline Hep3Vector HepBoostZ::boostVector() const {
return Hep3Vector( 0, 0, beta_ );
}
inline Hep3Vector HepBoostZ::getDirection() const {
return Hep3Vector( 0.0, 0.0, 1.0 );
}
inline double HepBoostZ::xx() const { return 1.0;}
inline double HepBoostZ::xy() const { return 0.0;}
inline double HepBoostZ::xz() const { return 0.0;}
inline double HepBoostZ::xt() const { return 0.0;}
inline double HepBoostZ::yx() const { return 0.0;}
inline double HepBoostZ::yy() const { return 1.0;}
inline double HepBoostZ::yz() const { return 0.0;}
inline double HepBoostZ::yt() const { return 0.0;}
inline double HepBoostZ::zx() const { return 0.0;}
inline double HepBoostZ::zy() const { return 0.0;}
inline double HepBoostZ::zz() const { return gamma();}
inline double HepBoostZ::zt() const { return beta()*gamma();}
inline double HepBoostZ::tx() const { return 0.0;}
inline double HepBoostZ::ty() const { return 0.0;}
inline double HepBoostZ::tz() const { return beta()*gamma();}
inline double HepBoostZ::tt() const { return gamma();}
inline HepLorentzVector HepBoostZ::col1() const {
return HepLorentzVector ( 1, 0, 0, 0 );
}
inline HepLorentzVector HepBoostZ::col2() const {
return HepLorentzVector ( 0, 1, 0, 0 );
}
inline HepLorentzVector HepBoostZ::col3() const {
return HepLorentzVector ( 0, 0, gamma(), beta()*gamma() );
}
inline HepLorentzVector HepBoostZ::col4() const {
return HepLorentzVector ( 0, 0, beta()*gamma(), gamma() );
}
inline HepLorentzVector HepBoostZ::row1() const {
return HepLorentzVector ( col1() );
}
inline HepLorentzVector HepBoostZ::row2() const {
return HepLorentzVector ( col2() );
}
inline HepLorentzVector HepBoostZ::row3() const {
return HepLorentzVector ( col3() );
}
inline HepLorentzVector HepBoostZ::row4() const {
return HepLorentzVector ( col4() );
}
// ---------- Comparisons:
inline int HepBoostZ::compare( const HepBoostZ & b ) const {
if (beta() < b.beta()) {
return -1;
} else if (beta() > b.beta()) {
return 1;
} else {
return 0;
}
}
inline bool HepBoostZ::operator == ( const HepBoostZ & b ) const {
return beta_ == b.beta_;
}
inline bool HepBoostZ::operator != ( const HepBoostZ & b ) const {
return beta_ != b.beta_;
}
inline bool HepBoostZ::operator <= ( const HepBoostZ & b ) const {
return beta_ <= b.beta_;
}
inline bool HepBoostZ::operator >= ( const HepBoostZ & b ) const {
return beta_ >= b.beta_;
}
inline bool HepBoostZ::operator < ( const HepBoostZ & b ) const {
return beta_ < b.beta_;
}
inline bool HepBoostZ::operator > ( const HepBoostZ & b ) const {
return beta_ > b.beta_;
}
inline bool HepBoostZ::isIdentity() const {
return ( beta() == 0 );
}
inline double HepBoostZ::distance2( const HepBoostZ & b ) const {
double d = beta()*gamma() - b.beta()*b.gamma();
return d*d;
}
inline double HepBoostZ::howNear(const HepBoostZ & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostZ::howNear(const HepBoost & b) const {
return std::sqrt(distance2(b)); }
inline double HepBoostZ::howNear(const HepRotation & r) const {
return std::sqrt(distance2(r)); }
inline double HepBoostZ::howNear(const HepLorentzRotation & lt) const {
return std::sqrt(distance2(lt)); }
inline bool HepBoostZ::isNear(const HepBoostZ & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
inline bool HepBoostZ::isNear(const HepBoost & b,
double epsilon) const {
return (distance2(b) <= epsilon*epsilon);
}
// ---------- Properties:
double HepBoostZ::norm2() const {
register double bg = beta_*gamma_;
return bg*bg;
}
// ---------- Application:
inline HepLorentzVector
HepBoostZ::operator * (const HepLorentzVector & p) const {
double bg = beta_*gamma_;
return HepLorentzVector( p.x(),
p.y(),
gamma_*p.z() + bg*p.t(),
gamma_*p.t() + bg*p.z());
}
HepLorentzVector HepBoostZ::operator() (const HepLorentzVector & w) const {
return operator*(w);
}
// ---------- Operations in the group of 4-Rotations
inline HepBoostZ HepBoostZ::inverse() const {
return HepBoostZ( -beta(), gamma() );
}
inline HepBoostZ & HepBoostZ::invert() {
beta_ = -beta_;
return *this;
}
inline HepBoostZ inverseOf ( const HepBoostZ & b ) {
return HepBoostZ( -b.beta(), b.gamma());
}
// ---------- Tolerance:
inline double HepBoostZ::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepBoostZ::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
@@ -0,0 +1,112 @@
// -*- C++ -*-
// CLASSDOC OFF
// $Id:$
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// ----------------------------------------------------------------------
//
// EulerAngles.h EulerAngles class --
// Support class for PhysicsVectors classes
//
// History:
// 09-Jan-1998 WEB FixedTypes is now found in ZMutility
// 12-Jan-1998 WEB PI is now found in ZMutility
// 15-Jun-1998 WEB Added namespace support
// 02-May-2000 WEB No global using
// 26-Jul-2000 MF CLHEP version
//
// ----------------------------------------------------------------------
#ifndef HEP_EULERANGLES_H
#define HEP_EULERANGLES_H
#include <iostream>
namespace CLHEP {
// Declarations of classes and global methods
class HepEulerAngles;
std::ostream & operator<<(std::ostream & os, const HepEulerAngles & aa);
std::istream & operator>>(std::istream & is, HepEulerAngles & aa);
/**
* @author
* @ingroup vector
*/
class HepEulerAngles {
protected:
typedef HepEulerAngles EA; // just an abbreviation
static double tolerance; // to determine relative nearness
public:
// ---------- Constructors:
inline HepEulerAngles();
inline HepEulerAngles( double phi, double theta, double psi );
// ---------- Destructor, copy constructor, assignment:
// use C++ defaults
// ---------- Accessors:
public:
inline double getPhi() const;
inline double phi() const;
inline EA & setPhi( double phi );
inline double getTheta() const;
inline double theta() const;
inline EA & setTheta( double theta );
inline double getPsi() const;
inline double psi() const;
inline EA & setPsi( double psi );
inline EA & set( double phi, double theta, double psi );
// ---------- Operations:
// comparisons:
inline int compare ( const EA & ea ) const;
inline bool operator==( const EA & ea ) const;
inline bool operator!=( const EA & ea ) const;
inline bool operator< ( const EA & ea ) const;
inline bool operator<=( const EA & ea ) const;
inline bool operator> ( const EA & ea ) const;
inline bool operator>=( const EA & ea ) const;
// relative comparison:
inline static double getTolerance();
inline static double setTolerance( double tol );
bool isNear ( const EA & ea, double epsilon = tolerance ) const;
double howNear( const EA & ea ) const;
// ---------- I/O:
friend std::ostream & operator<<( std::ostream & os, const EA & ea );
friend std::istream & operator>>( std::istream & is, EA & ea );
// ---------- Helper methods:
protected:
double distance( const HepEulerAngles & ex ) const;
// ---------- Data members:
protected:
double phi_;
double theta_;
double psi_;
}; // HepEulerAngles
} // namespace CLHEP
#include "CLHEP/Vector/EulerAngles.icc"
#endif // EULERANGLES_H
@@ -0,0 +1,124 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// ----------------------------------------------------------------------
//
// EulerAngles.icc - Inline methods for EulerAngles class.
//
// History:
// 9-Apr-1997 MF Split off from original angles.hh. Content-free.
// 26-Jan-1998 WEB Fleshed out.
// 12-Mar-1998 WEB Gave default constructor proper default values
// 13-Mar-1998 WEB Simplified compare()
// 17-Jun-1998 WEB Added namespace support
// 27-Jul-2000 MF CLHEP version
//
// ----------------------------------------------------------------------
namespace CLHEP {
inline HepEulerAngles::HepEulerAngles()
: phi_( 0.0 ), theta_( 0.0 ), psi_( 0.0 )
{} // HepEulerAngles::HepEulerAngles()
inline HepEulerAngles::HepEulerAngles (
double phi, double theta, double psi )
: phi_( phi ), theta_( theta ), psi_( psi )
{} // HepEulerAngles::HepEulerAngles()
inline double HepEulerAngles::getPhi() const {
return phi_;
} // HepEulerAngles::getPhi()
inline double HepEulerAngles::phi() const {
return phi_;
} // HepEulerAngles::phi()
inline HepEulerAngles & HepEulerAngles::setPhi( double phi ) {
phi_ = phi;
return *this;
} // HepEulerAngles::setPhi()
inline double HepEulerAngles::getTheta() const {
return theta_;
} // HepEulerAngles::getTheta()
inline double HepEulerAngles::theta() const {
return theta_;
} // HepEulerAngles::theta()
inline HepEulerAngles & HepEulerAngles::setTheta( double theta ) {
theta_ = theta;
return *this;
} // HepEulerAngles::setTheta()
inline double HepEulerAngles::getPsi() const {
return psi_;
} // HepEulerAngles::getPsi()
inline double HepEulerAngles::psi() const {
return psi_;
} // HepEulerAngles::psi()
inline HepEulerAngles & HepEulerAngles::setPsi( double psi ) {
psi_ = psi;
return *this;
} // HepEulerAngles::setPsi()
inline HepEulerAngles &
HepEulerAngles::set( double phi, double theta, double psi ) {
phi_ = phi, theta_ = theta, psi_ = psi;
return *this;
} // HepEulerAngles::set()
inline int HepEulerAngles::compare( const HepEulerAngles & ea ) const {
return phi_ < ea.phi_ ? -1
: phi_ > ea.phi_ ? +1
: theta_ < ea.theta_ ? -1
: theta_ > ea.theta_ ? +1
: psi_ < ea.psi_ ? -1
: psi_ > ea.psi_ ? +1
: 0;
} // HepEulerAngles::compare()
inline bool HepEulerAngles::operator==( const HepEulerAngles & ea ) const {
return ( compare( ea ) == 0 );
} // HepEulerAngles::operator==()
inline bool HepEulerAngles::operator!=( const HepEulerAngles & ea ) const {
return ( compare( ea ) != 0 );
} // HepEulerAngles::operator!=()
inline bool HepEulerAngles::operator<( const HepEulerAngles & ea ) const {
return ( compare( ea ) < 0 );
} // HepEulerAngles::operator<()
inline bool HepEulerAngles::operator<=( const HepEulerAngles & ea ) const {
return ( compare( ea ) <= 0 );
} // HepEulerAngles::operator<=()
inline bool HepEulerAngles::operator>( const HepEulerAngles & ea ) const {
return ( compare( ea ) > 0 );
} // HepEulerAngles::operator>()
inline bool HepEulerAngles::operator>=( const HepEulerAngles & ea ) const {
return ( compare( ea ) >= 0 );
} // HepEulerAngles::operator>=()
inline double HepEulerAngles::getTolerance() {
return tolerance;
} // HepEulerAngles::getTolerance()
inline double HepEulerAngles::setTolerance( double tol ) {
double oldTolerance( tolerance );
tolerance = tol;
return oldTolerance;
} // HepEulerAngles::setTolerance()
} // namespace CLHEP
@@ -0,0 +1,382 @@
// -*- C++ -*-
// CLASSDOC OFF
// $Id:$
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepLorentzRotation class for performing
// Lorentz transformations (rotations and boosts) on objects of the
// HepLorentzVector class.
//
// HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h
// Rotation.h, Boost.h
//
// .SS Author
// Leif Lonnblad, Mark Fischler
#ifndef HEP_LORENTZROTATION_H
#define HEP_LORENTZROTATION_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/Rotation.h"
#include "CLHEP/Vector/Boost.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Global methods
inline HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
HepLorentzRotation operator * (const HepRotation & r,
const HepLorentzRotation & lt);
HepLorentzRotation operator * (const HepRotationX & r,
const HepLorentzRotation & lt);
HepLorentzRotation operator * (const HepRotationY & r,
const HepLorentzRotation & lt);
HepLorentzRotation operator * (const HepRotationZ & r,
const HepLorentzRotation & lt);
/**
* @author
* @ingroup vector
*/
class HepLorentzRotation {
public:
// ---------- Identity HepLorentzRotation:
DLL_API static const HepLorentzRotation IDENTITY;
// ---------- Constructors and Assignment:
inline HepLorentzRotation();
// Default constructor. Gives a unit matrix.
inline HepLorentzRotation (const HepLorentzRotation & r);
// Copy constructor.
inline HepLorentzRotation (const HepRotation & r);
inline explicit HepLorentzRotation (const HepRotationX & r);
inline explicit HepLorentzRotation (const HepRotationY & r);
inline explicit HepLorentzRotation (const HepRotationZ & r);
inline HepLorentzRotation (const HepBoost & b);
inline explicit HepLorentzRotation (const HepBoostX & b);
inline explicit HepLorentzRotation (const HepBoostY & b);
inline explicit HepLorentzRotation (const HepBoostZ & b);
// Constructors from special cases.
inline HepLorentzRotation & operator = (const HepLorentzRotation & m);
inline HepLorentzRotation & operator = (const HepRotation & m);
inline HepLorentzRotation & operator = (const HepBoost & m);
// Assignment.
HepLorentzRotation & set (double bx, double by, double bz);
inline HepLorentzRotation & set (const Hep3Vector & p);
inline HepLorentzRotation & set (const HepRotation & r);
inline HepLorentzRotation & set (const HepRotationX & r);
inline HepLorentzRotation & set (const HepRotationY & r);
inline HepLorentzRotation & set (const HepRotationZ & r);
inline HepLorentzRotation & set (const HepBoost & boost);
inline HepLorentzRotation & set (const HepBoostX & boost);
inline HepLorentzRotation & set (const HepBoostY & boost);
inline HepLorentzRotation & set (const HepBoostZ & boost);
inline HepLorentzRotation (double bx, double by, double bz);
inline HepLorentzRotation (const Hep3Vector & p);
// Other Constructors giving a Lorentz-boost.
HepLorentzRotation & set( const HepBoost & B, const HepRotation & R );
inline HepLorentzRotation ( const HepBoost & B, const HepRotation & R );
// supply B and R: T = B R:
HepLorentzRotation & set( const HepRotation & R, const HepBoost & B );
inline HepLorentzRotation ( const HepRotation & R, const HepBoost & B );
// supply R and B: T = R B:
HepLorentzRotation ( const HepLorentzVector & col1,
const HepLorentzVector & col2,
const HepLorentzVector & col3,
const HepLorentzVector & col4 );
// Construct from four *orthosymplectic* LorentzVectors for the columns:
// NOTE:
// This constructor, and the two set methods below,
// will check that the columns (or rows) form an orthosymplectic
// matrix, and will adjust values so that this relation is
// as exact as possible.
// Orthosymplectic means the dot product USING THE METRIC
// of two different coumns will be 0, and of a column with
// itself will be one.
HepLorentzRotation & set( const HepLorentzVector & col1,
const HepLorentzVector & col2,
const HepLorentzVector & col3,
const HepLorentzVector & col4 );
// supply four *orthosymplectic* HepLorentzVectors for the columns
HepLorentzRotation & setRows( const HepLorentzVector & row1,
const HepLorentzVector & row2,
const HepLorentzVector & row3,
const HepLorentzVector & row4 );
// supply four *orthosymplectic* HepLorentzVectors for the columns
inline HepLorentzRotation & set( const HepRep4x4 & rep );
inline HepLorentzRotation ( const HepRep4x4 & rep );
// supply a HepRep4x4 structure (16 numbers)
// WARNING:
// This constructor and set method will assume the
// HepRep4x4 supplied is in fact an orthosymplectic matrix.
// No checking or correction is done. If you are
// not certain the matrix is orthosymplectic, break it
// into four HepLorentzVector columns and use the form
// HepLorentzRotation (col1, col2, col3, col4)
// ---------- Accessors:
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double xt() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double yt() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
inline double tt() const;
// Elements of the matrix.
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
inline HepLorentzVector col4() const;
// orthosymplectic column vectors
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
inline HepLorentzVector row4() const;
// orthosymplectic row vectors
inline HepRep4x4 rep4x4() const;
// 4x4 representation:
// ------------ Subscripting:
class HepLorentzRotation_row {
public:
inline HepLorentzRotation_row(const HepLorentzRotation &, int);
inline double operator [] (int) const;
private:
const HepLorentzRotation & rr;
int ii;
};
// Helper class for implemention of C-style subscripting r[i][j]
inline const HepLorentzRotation_row operator [] (int) const;
// Returns object of the helper class for C-style subscripting r[i][j]
double operator () (int, int) const;
// Fortran-style subscripting: returns (i,j) element of the matrix.
// ---------- Decomposition:
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
void decompose (HepBoost & boost, HepRotation & rotation) const;
// Find B and R such that L = B*R
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
void decompose (HepRotation & rotation, HepBoost & boost) const;
// Find R and B such that L = R*B
// ---------- Comparisons:
int compare( const HepLorentzRotation & m ) const;
// Dictionary-order comparison, in order tt,tz,...zt,zz,zy,zx,yt,yz,...,xx
// Used in operator<, >, <=, >=
inline bool operator == (const HepLorentzRotation &) const;
inline bool operator != (const HepLorentzRotation &) const;
inline bool operator <= (const HepLorentzRotation &) const;
inline bool operator >= (const HepLorentzRotation &) const;
inline bool operator < (const HepLorentzRotation &) const;
inline bool operator > (const HepLorentzRotation &) const;
inline bool isIdentity() const;
// Returns true if the Identity matrix.
double distance2( const HepBoost & b ) const;
double distance2( const HepRotation & r ) const;
double distance2( const HepLorentzRotation & lt ) const;
// Decomposes L = B*R, returns the sum of distance2 for B and R.
double howNear( const HepBoost & b ) const;
double howNear( const HepRotation & r) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear(const HepBoost & b,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear(const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear(const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// distance2 (IDENTITY), which involves decomposing into B and R and summing
// norm2 for the individual B and R parts.
void rectify();
// non-const but logically moot correction for accumulated roundoff errors
// rectify averages the matrix with the orthotranspose of its actual
// inverse (absent accumulated roundoff errors, the orthotranspose IS
// the inverse)); this removes to first order those errors.
// Then it formally decomposes that, extracts axis and delta for its
// Rotation part, forms a LorentzRotation from a true HepRotation
// with those values of axis and delta, times the true Boost
// with that boost vector.
// ---------- Application:
inline HepLorentzVector vectorMultiplication(const HepLorentzVector&) const;
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
inline HepLorentzVector operator* ( const HepLorentzVector & p ) const;
// Multiplication with a Lorentz Vector.
// ---------- Operations in the group of 4-Rotations
HepLorentzRotation matrixMultiplication(const HepRep4x4 & m) const;
inline HepLorentzRotation operator * (const HepBoost & b) const;
inline HepLorentzRotation operator * (const HepRotation & r) const;
inline HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
// Product of two Lorentz Rotations (this) * lt - matrix multiplication
inline HepLorentzRotation & operator *= (const HepBoost & b);
inline HepLorentzRotation & operator *= (const HepRotation & r);
inline HepLorentzRotation & operator *= (const HepLorentzRotation & lt);
inline HepLorentzRotation & transform (const HepBoost & b);
inline HepLorentzRotation & transform (const HepRotation & r);
inline HepLorentzRotation & transform (const HepLorentzRotation & lt);
// Matrix multiplication.
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
// Here there is an opportunity for speedup by providing specialized forms
// of lt * r and lt * b where r is a RotationX Y or Z or b is a BoostX Y or Z
// These are, in fact, provided below for the transform() methods.
HepLorentzRotation & rotateX(double delta);
// Rotation around the x-axis; equivalent to LT = RotationX(delta) * LT
HepLorentzRotation & rotateY(double delta);
// Rotation around the y-axis; equivalent to LT = RotationY(delta) * LT
HepLorentzRotation & rotateZ(double delta);
// Rotation around the z-axis; equivalent to LT = RotationZ(delta) * LT
inline HepLorentzRotation & rotate(double delta, const Hep3Vector& axis);
inline HepLorentzRotation & rotate(double delta, const Hep3Vector *axis);
// Rotation around specified vector - LT = Rotation(delta,axis)*LT
HepLorentzRotation & boostX(double beta);
// Pure boost along the x-axis; equivalent to LT = BoostX(beta) * LT
HepLorentzRotation & boostY(double beta);
// Pure boost along the y-axis; equivalent to LT = BoostX(beta) * LT
HepLorentzRotation & boostZ(double beta);
// Pure boost along the z-axis; equivalent to LT = BoostX(beta) * LT
inline HepLorentzRotation & boost(double, double, double);
inline HepLorentzRotation & boost(const Hep3Vector &);
// Lorenz boost.
inline HepLorentzRotation inverse() const;
// Return the inverse.
inline HepLorentzRotation & invert();
// Inverts the LorentzRotation matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Aligned six-digit-accurate output of the transformation matrix.
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
friend HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
protected:
inline HepLorentzRotation
(double mxx, double mxy, double mxz, double mxt,
double myx, double myy, double myz, double myt,
double mzx, double mzy, double mzz, double mzt,
double mtx, double mty, double mtz, double mtt);
// Protected constructor.
// DOES NOT CHECK FOR VALIDITY AS A LORENTZ TRANSFORMATION.
inline void setBoost(double, double, double);
// Set elements according to a boost vector.
double mxx, mxy, mxz, mxt,
myx, myy, myz, myt,
mzx, mzy, mzz, mzt,
mtx, mty, mtz, mtt;
// The matrix elements.
}; // HepLorentzRotation
inline std::ostream & operator<<
( std::ostream & os, const HepLorentzRotation& lt )
{return lt.print(os);}
inline bool operator==(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt==r; }
inline bool operator!=(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt!=r; }
inline bool operator<=(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt<=r; }
inline bool operator>=(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt>=r; }
inline bool operator<(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt<r; }
inline bool operator>(const HepRotation &r, const HepLorentzRotation & lt)
{ return lt>r; }
inline bool operator==(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt==b; }
inline bool operator!=(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt!=b; }
inline bool operator<=(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt<=b; }
inline bool operator>=(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt>=b; }
inline bool operator<(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt<b; }
inline bool operator>(const HepBoost &b, const HepLorentzRotation & lt)
{ return lt>b; }
} // namespace CLHEP
#include "CLHEP/Vector/LorentzRotation.icc"
#endif /* HEP_LORENTZROTATION_H */
@@ -0,0 +1,375 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepLorentzRotation class
//
namespace CLHEP {
// ---------- Constructors and Assignment:
inline HepLorentzRotation::HepLorentzRotation() :
mxx(1.0), mxy(0.0), mxz(0.0), mxt(0.0),
myx(0.0), myy(1.0), myz(0.0), myt(0.0),
mzx(0.0), mzy(0.0), mzz(1.0), mzt(0.0),
mtx(0.0), mty(0.0), mtz(0.0), mtt(1.0) {}
inline HepLorentzRotation::HepLorentzRotation(const HepLorentzRotation & r) :
mxx(r.mxx), mxy(r.mxy), mxz(r.mxz), mxt(r.mxt),
myx(r.myx), myy(r.myy), myz(r.myz), myt(r.myt),
mzx(r.mzx), mzy(r.mzy), mzz(r.mzz), mzt(r.mzt),
mtx(r.mtx), mty(r.mty), mtz(r.mtz), mtt(r.mtt) {}
inline HepLorentzRotation::HepLorentzRotation(const HepRotation & r) {
set (r.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepRotationX & r) {
set (r.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepRotationY & r) {
set (r.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepRotationZ & r) {
set (r.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepBoost & b) {
set (b.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepBoostX & b) {
set (b.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepBoostY & b) {
set (b.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(const HepBoostZ & b) {
set (b.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::operator = (const HepLorentzRotation & r) {
mxx = r.mxx; mxy = r.mxy; mxz = r.mxz; mxt = r.mxt;
myx = r.myx; myy = r.myy; myz = r.myz; myt = r.myt;
mzx = r.mzx; mzy = r.mzy; mzz = r.mzz; mzt = r.mzt;
mtx = r.mtx; mty = r.mty; mtz = r.mtz; mtt = r.mtt;
return *this;
}
inline HepLorentzRotation &
HepLorentzRotation::operator = (const HepRotation & m) {
return set (m.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::operator = (const HepBoost & m) {
return set (m.rep4x4());
}
HepLorentzRotation & HepLorentzRotation::set (const Hep3Vector & p) {
return set (p.x(), p.y(), p.z());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepRotation & r) {
return set (r.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepRotationX & r) {
return set (r.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepRotationY & r) {
return set (r.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepRotationZ & r) {
return set (r.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepBoost & boost) {
return set (boost.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepBoostX & boost) {
return set (boost.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepBoostY & boost) {
return set (boost.rep4x4());
}
inline HepLorentzRotation & HepLorentzRotation::set (const HepBoostZ & boost) {
return set (boost.rep4x4());
}
inline HepLorentzRotation::HepLorentzRotation(double bx,
double by,
double bz)
{
set(bx, by, bz);
}
inline HepLorentzRotation::HepLorentzRotation(const Hep3Vector & p)
{
set(p.x(), p.y(), p.z());
}
inline HepLorentzRotation::HepLorentzRotation(
const HepBoost & B, const HepRotation & R)
{
set(B, R);
}
inline HepLorentzRotation::HepLorentzRotation(
const HepRotation & R, const HepBoost & B)
{
set(R, B);
}
inline HepLorentzRotation & HepLorentzRotation::set( const HepRep4x4 & rep ) {
mxx=rep.xx_; mxy=rep.xy_; mxz=rep.xz_; mxt=rep.xt_;
myx=rep.yx_; myy=rep.yy_; myz=rep.yz_; myt=rep.yt_;
mzx=rep.zx_; mzy=rep.zy_; mzz=rep.zz_; mzt=rep.zt_;
mtx=rep.tx_; mty=rep.ty_; mtz=rep.tz_; mtt=rep.tt_;
return *this;
}
inline HepLorentzRotation ::HepLorentzRotation ( const HepRep4x4 & rep ) :
mxx(rep.xx_), mxy(rep.xy_), mxz(rep.xz_), mxt(rep.xt_),
myx(rep.yx_), myy(rep.yy_), myz(rep.yz_), myt(rep.yt_),
mzx(rep.zx_), mzy(rep.zy_), mzz(rep.zz_), mzt(rep.zt_),
mtx(rep.tx_), mty(rep.ty_), mtz(rep.tz_), mtt(rep.tt_) {}
// - Protected methods
inline HepLorentzRotation::HepLorentzRotation(
double rxx, double rxy, double rxz, double rxt,
double ryx, double ryy, double ryz, double ryt,
double rzx, double rzy, double rzz, double rzt,
double rtx, double rty, double rtz, double rtt) :
mxx(rxx), mxy(rxy), mxz(rxz), mxt(rxt),
myx(ryx), myy(ryy), myz(ryz), myt(ryt),
mzx(rzx), mzy(rzy), mzz(rzz), mzt(rzt),
mtx(rtx), mty(rty), mtz(rtz), mtt(rtt) {}
inline void HepLorentzRotation::setBoost
(double bx, double by, double bz) {
set(bx, by, bz);
}
// ---------- Accessors:
inline double HepLorentzRotation::xx() const { return mxx; }
inline double HepLorentzRotation::xy() const { return mxy; }
inline double HepLorentzRotation::xz() const { return mxz; }
inline double HepLorentzRotation::xt() const { return mxt; }
inline double HepLorentzRotation::yx() const { return myx; }
inline double HepLorentzRotation::yy() const { return myy; }
inline double HepLorentzRotation::yz() const { return myz; }
inline double HepLorentzRotation::yt() const { return myt; }
inline double HepLorentzRotation::zx() const { return mzx; }
inline double HepLorentzRotation::zy() const { return mzy; }
inline double HepLorentzRotation::zz() const { return mzz; }
inline double HepLorentzRotation::zt() const { return mzt; }
inline double HepLorentzRotation::tx() const { return mtx; }
inline double HepLorentzRotation::ty() const { return mty; }
inline double HepLorentzRotation::tz() const { return mtz; }
inline double HepLorentzRotation::tt() const { return mtt; }
inline HepLorentzVector HepLorentzRotation::col1() const {
return HepLorentzVector ( mxx, myx, mzx, mtx );
}
inline HepLorentzVector HepLorentzRotation::col2() const {
return HepLorentzVector ( mxy, myy, mzy, mty );
}
inline HepLorentzVector HepLorentzRotation::col3() const {
return HepLorentzVector ( mxz, myz, mzz, mtz );
}
inline HepLorentzVector HepLorentzRotation::col4() const {
return HepLorentzVector ( mxt, myt, mzt, mtt );
}
inline HepLorentzVector HepLorentzRotation::row1() const {
return HepLorentzVector ( mxx, mxy, mxz, mxt );
}
inline HepLorentzVector HepLorentzRotation::row2() const {
return HepLorentzVector ( myx, myy, myz, myt );
}
inline HepLorentzVector HepLorentzRotation::row3() const {
return HepLorentzVector ( mzx, mzy, mzz, mzt );
}
inline HepLorentzVector HepLorentzRotation::row4() const {
return HepLorentzVector ( mtx, mty, mtz, mtt );
}
inline HepRep4x4 HepLorentzRotation::rep4x4() const {
return HepRep4x4( mxx, mxy, mxz, mxt,
myx, myy, myz, myt,
mzx, mzy, mzz, mzt,
mtx, mty, mtz, mtt );
}
// ------------ Subscripting:
inline HepLorentzRotation::HepLorentzRotation_row::HepLorentzRotation_row
(const HepLorentzRotation & r, int i) : rr(r), ii(i) {}
inline double
HepLorentzRotation::HepLorentzRotation_row::operator [] (int jj) const {
return rr(ii,jj);
}
inline const HepLorentzRotation::HepLorentzRotation_row
HepLorentzRotation::operator [] (int i) const {
return HepLorentzRotation_row(*this, i);
}
// ---------- Comparisons:
inline bool
HepLorentzRotation::operator == (const HepLorentzRotation & r) const {
return (mxx == r.xx() && mxy == r.xy() && mxz == r.xz() && mxt == r.xt() &&
myx == r.yx() && myy == r.yy() && myz == r.yz() && myt == r.yt() &&
mzx == r.zx() && mzy == r.zy() && mzz == r.zz() && mzt == r.zt() &&
mtx == r.tx() && mty == r.ty() && mtz == r.tz() && mtt == r.tt());
}
inline bool
HepLorentzRotation::operator != (const HepLorentzRotation & r) const {
return ! operator==(r);
}
inline bool
HepLorentzRotation::operator < ( const HepLorentzRotation & r ) const
{ return compare(r)< 0; }
inline bool
HepLorentzRotation::operator <= ( const HepLorentzRotation & r ) const
{ return compare(r)<=0; }
inline bool
HepLorentzRotation::operator >= ( const HepLorentzRotation & r ) const
{ return compare(r)>=0; }
inline bool
HepLorentzRotation::operator > ( const HepLorentzRotation & r ) const
{ return compare(r)> 0; }
inline bool HepLorentzRotation::isIdentity() const {
return (mxx == 1.0 && mxy == 0.0 && mxz == 0.0 && mxt == 0.0 &&
myx == 0.0 && myy == 1.0 && myz == 0.0 && myt == 0.0 &&
mzx == 0.0 && mzy == 0.0 && mzz == 1.0 && mzt == 0.0 &&
mtx == 0.0 && mty == 0.0 && mtz == 0.0 && mtt == 1.0);
}
// ---------- Properties:
// ---------- Application:
inline HepLorentzVector
HepLorentzRotation::vectorMultiplication(const HepLorentzVector & p) const {
register double x(p.x());
register double y(p.y());
register double z(p.z());
register double t(p.t());
return HepLorentzVector(mxx*x + mxy*y + mxz*z + mxt*t,
myx*x + myy*y + myz*z + myt*t,
mzx*x + mzy*y + mzz*z + mzt*t,
mtx*x + mty*y + mtz*z + mtt*t);
}
inline HepLorentzVector
HepLorentzRotation::operator() (const HepLorentzVector & w) const {
return vectorMultiplication(w);
}
inline HepLorentzVector
HepLorentzRotation::operator * (const HepLorentzVector & p) const {
return vectorMultiplication(p);
}
// ---------- Operations in the group of 4-Rotations
inline HepLorentzRotation
HepLorentzRotation::operator * (const HepBoost & b) const {
return matrixMultiplication(b.rep4x4());
}
inline HepLorentzRotation
HepLorentzRotation::operator * (const HepRotation & r) const {
return matrixMultiplication(r.rep4x4());
}
inline HepLorentzRotation
HepLorentzRotation::operator * (const HepLorentzRotation & lt) const {
return matrixMultiplication(lt.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::operator *= (const HepBoost & b) {
return *this = matrixMultiplication(b.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::operator *= (const HepRotation & r) {
return *this = matrixMultiplication(r.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::operator *= (const HepLorentzRotation & lt) {
return *this = matrixMultiplication(lt.rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::transform (const HepBoost & b) {
return *this = HepLorentzRotation(b).matrixMultiplication(rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::transform (const HepRotation & r) {
return *this = HepLorentzRotation(r).matrixMultiplication(rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::transform (const HepLorentzRotation & lt) {
return *this = lt.matrixMultiplication(rep4x4());
}
inline HepLorentzRotation &
HepLorentzRotation::rotate(double angle, const Hep3Vector & axis) {
return transform(HepRotation().rotate(angle, axis));
}
inline HepLorentzRotation &
HepLorentzRotation::rotate(double angle, const Hep3Vector * axis) {
return transform(HepRotation().rotate(angle, axis));
}
inline HepLorentzRotation &
HepLorentzRotation::boost(double bx, double by, double bz) {
return transform(HepLorentzRotation(bx, by, bz));
}
inline HepLorentzRotation &
HepLorentzRotation::boost(const Hep3Vector & b) {
return transform(HepLorentzRotation(b));
}
inline HepLorentzRotation HepLorentzRotation::inverse() const {
return HepLorentzRotation( mxx, myx, mzx, -mtx,
mxy, myy, mzy, -mty,
mxz, myz, mzz, -mtz,
-mxt, -myt, -mzt, mtt );
}
inline HepLorentzRotation & HepLorentzRotation::invert() {
return *this = inverse();
}
inline HepLorentzRotation inverseOf ( const HepLorentzRotation & lt ) {
return HepLorentzRotation(
HepRep4x4(
lt.mxx, lt.myx, lt.mzx, -lt.mtx,
lt.mxy, lt.myy, lt.mzy, -lt.mty,
lt.mxz, lt.myz, lt.mzz, -lt.mtz,
-lt.mxt, -lt.myt, -lt.mzt, lt.mtt ) );
}
inline double HepLorentzRotation::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepLorentzRotation::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
@@ -0,0 +1,575 @@
// -*- C++ -*-
// CLASSDOC OFF
// $Id:$
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// HepLorentzVector is a Lorentz vector consisting of Hep3Vector and
// double components. Lorentz transformations (rotations and boosts)
// of these vectors are perfomed by multiplying with objects of
// the HepLorenzRotation class.
//
// .SS See Also
// ThreeVector.h, Rotation.h, LorentzRotation.h
//
// .SS Authors
// Leif Lonnblad and Anders Nilsson. Modified by Evgueni Tcherniaev, Mark Fischler
//
#ifndef HEP_LORENTZVECTOR_H
#define HEP_LORENTZVECTOR_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include <iostream>
#include "CLHEP/Vector/ThreeVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepLorentzVector;
class HepLorentzRotation;
class HepRotation;
class HepAxisAngle;
class HepEulerAngles;
class Tcomponent;
HepLorentzVector rotationXOf( const HepLorentzVector & vec, double delta );
HepLorentzVector rotationYOf( const HepLorentzVector & vec, double delta );
HepLorentzVector rotationZOf( const HepLorentzVector & vec, double delta );
HepLorentzVector rotationOf
( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
HepLorentzVector rotationOf
( const HepLorentzVector & vec, const HepAxisAngle & ax );
HepLorentzVector rotationOf
( const HepLorentzVector & vec, const HepEulerAngles & e );
HepLorentzVector rotationOf
( const HepLorentzVector & vec, double phi,
double theta,
double psi );
inline
HepLorentzVector boostXOf( const HepLorentzVector & vec, double beta );
inline
HepLorentzVector boostYOf( const HepLorentzVector & vec, double beta );
inline
HepLorentzVector boostZOf( const HepLorentzVector & vec, double beta );
inline HepLorentzVector boostOf
( const HepLorentzVector & vec, const Hep3Vector & betaVector );
inline HepLorentzVector boostOf
( const HepLorentzVector & vec, const Hep3Vector & axis, double beta );
enum ZMpvMetric_t { TimePositive, TimeNegative };
/**
* @author
* @ingroup vector
*/
class HepLorentzVector {
public:
enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES };
// Safe indexing of the coordinates when using with matrices, arrays, etc.
// (BaBar)
inline HepLorentzVector(double x, double y,
double z, double t);
// Constructor giving the components x, y, z, t.
inline HepLorentzVector(double x, double y, double z);
// Constructor giving the components x, y, z with t-component set to 0.0.
inline HepLorentzVector(double t);
// Constructor giving the t-component with x, y and z set to 0.0.
inline HepLorentzVector();
// Default constructor with x, y, z and t set to 0.0.
inline HepLorentzVector(const Hep3Vector & p, double e);
inline HepLorentzVector(double e, const Hep3Vector & p);
// Constructor giving a 3-Vector and a time component.
inline HepLorentzVector(const HepLorentzVector &);
// Copy constructor.
inline ~HepLorentzVector();
// The destructor.
inline operator const Hep3Vector & () const;
inline operator Hep3Vector & ();
// Conversion (cast) to Hep3Vector.
inline double x() const;
inline double y() const;
inline double z() const;
inline double t() const;
// Get position and time.
inline void setX(double);
inline void setY(double);
inline void setZ(double);
inline void setT(double);
// Set position and time.
inline double px() const;
inline double py() const;
inline double pz() const;
inline double e() const;
// Get momentum and energy.
inline void setPx(double);
inline void setPy(double);
inline void setPz(double);
inline void setE(double);
// Set momentum and energy.
inline Hep3Vector vect() const;
// Get spatial component.
inline void setVect(const Hep3Vector &);
// Set spatial component.
inline double theta() const;
inline double cosTheta() const;
inline double phi() const;
inline double rho() const;
// Get spatial vector components in spherical coordinate system.
inline void setTheta(double);
inline void setPhi(double);
inline void setRho(double);
// Set spatial vector components in spherical coordinate system.
double operator () (int) const;
inline double operator [] (int) const;
// Get components by index.
double & operator () (int);
inline double & operator [] (int);
// Set components by index.
inline HepLorentzVector & operator = (const HepLorentzVector &);
// Assignment.
inline HepLorentzVector operator + (const HepLorentzVector &) const;
inline HepLorentzVector & operator += (const HepLorentzVector &);
// Additions.
inline HepLorentzVector operator - (const HepLorentzVector &) const;
inline HepLorentzVector & operator -= (const HepLorentzVector &);
// Subtractions.
inline HepLorentzVector operator - () const;
// Unary minus.
inline HepLorentzVector & operator *= (double);
HepLorentzVector & operator /= (double);
// Scaling with real numbers.
inline bool operator == (const HepLorentzVector &) const;
inline bool operator != (const HepLorentzVector &) const;
// Comparisons.
inline double perp2() const;
// Transverse component of the spatial vector squared.
inline double perp() const;
// Transverse component of the spatial vector (R in cylindrical system).
inline void setPerp(double);
// Set the transverse component of the spatial vector.
inline double perp2(const Hep3Vector &) const;
// Transverse component of the spatial vector w.r.t. given axis squared.
inline double perp(const Hep3Vector &) const;
// Transverse component of the spatial vector w.r.t. given axis.
inline double angle(const Hep3Vector &) const;
// Angle wrt. another vector.
inline double mag2() const;
// Dot product of 4-vector with itself.
// By default the metric is TimePositive, and mag2() is the same as m2().
inline double m2() const;
// Invariant mass squared.
inline double mag() const;
inline double m() const;
// Invariant mass. If m2() is negative then -std::sqrt(-m2()) is returned.
inline double mt2() const;
// Transverse mass squared.
inline double mt() const;
// Transverse mass.
inline double et2() const;
// Transverse energy squared.
inline double et() const;
// Transverse energy.
inline double dot(const HepLorentzVector &) const;
inline double operator * (const HepLorentzVector &) const;
// Scalar product.
inline double invariantMass2( const HepLorentzVector & w ) const;
// Invariant mass squared of pair of 4-vectors
double invariantMass ( const HepLorentzVector & w ) const;
// Invariant mass of pair of 4-vectors
inline void setVectMag(const Hep3Vector & spatial, double magnitude);
inline void setVectM(const Hep3Vector & spatial, double mass);
// Copy spatial coordinates, and set energy = std::sqrt(mass^2 + spatial^2)
inline double plus() const;
inline double minus() const;
// Returns the positive/negative light-cone component t +/- z.
Hep3Vector boostVector() const;
// Boost needed from rest4Vector in rest frame to form this 4-vector
// Returns the spatial components divided by the time component.
HepLorentzVector & boost(double, double, double);
inline HepLorentzVector & boost(const Hep3Vector &);
// Lorentz boost.
HepLorentzVector & boostX( double beta );
HepLorentzVector & boostY( double beta );
HepLorentzVector & boostZ( double beta );
// Boost along an axis, by magnitue beta (fraction of speed of light)
double rapidity() const;
// Returns the rapidity, i.e. 0.5*ln((E+pz)/(E-pz))
inline double pseudoRapidity() const;
// Returns the pseudo-rapidity, i.e. -ln(std::tan(theta/2))
inline bool isTimelike() const;
// Test if the 4-vector is timelike
inline bool isSpacelike() const;
// Test if the 4-vector is spacelike
inline bool isLightlike(double epsilon=tolerance) const;
// Test for lightlike is within tolerance epsilon
HepLorentzVector & rotateX(double);
// Rotate the spatial component around the x-axis.
HepLorentzVector & rotateY(double);
// Rotate the spatial component around the y-axis.
HepLorentzVector & rotateZ(double);
// Rotate the spatial component around the z-axis.
HepLorentzVector & rotateUz(const Hep3Vector &);
// Rotates the reference frame from Uz to newUz (unit vector).
HepLorentzVector & rotate(double, const Hep3Vector &);
// Rotate the spatial component around specified axis.
inline HepLorentzVector & operator *= (const HepRotation &);
inline HepLorentzVector & transform(const HepRotation &);
// Transformation with HepRotation.
HepLorentzVector & operator *= (const HepLorentzRotation &);
HepLorentzVector & transform(const HepLorentzRotation &);
// Transformation with HepLorenzRotation.
// = = = = = = = = = = = = = = = = = = = = = = = =
//
// Esoteric properties and operations on 4-vectors:
//
// 0 - Flexible metric convention and axial unit 4-vectors
// 1 - Construct and set 4-vectors in various ways
// 2 - Synonyms for accessing coordinates and properties
// 2a - Setting space coordinates in different ways
// 3 - Comparisions (dictionary, near-ness, and geometric)
// 4 - Intrinsic properties
// 4a - Releativistic kinematic properties
// 4b - Methods combining two 4-vectors
// 5 - Properties releative to z axis and to arbitrary directions
// 7 - Rotations and Boosts
//
// = = = = = = = = = = = = = = = = = = = = = = = =
// 0 - Flexible metric convention
static ZMpvMetric_t setMetric( ZMpvMetric_t m );
static ZMpvMetric_t getMetric();
// 1 - Construct and set 4-vectors in various ways
inline void set (double x, double y, double z, double t);
inline void set (double x, double y, double z, Tcomponent t);
inline HepLorentzVector(double x, double y, double z, Tcomponent t);
// Form 4-vector by supplying cartesian coordinate components
inline void set (Tcomponent t, double x, double y, double z);
inline HepLorentzVector(Tcomponent t, double x, double y, double z);
// Deprecated because the 4-doubles form uses x,y,z,t, not t,x,y,z.
inline void set ( double t );
inline void set ( Tcomponent t );
inline explicit HepLorentzVector( Tcomponent t );
// Form 4-vector with zero space components, by supplying t component
inline void set ( const Hep3Vector & v );
inline explicit HepLorentzVector( const Hep3Vector & v );
// Form 4-vector with zero time component, by supplying space 3-vector
inline HepLorentzVector & operator=( const Hep3Vector & v );
// Form 4-vector with zero time component, equal to space 3-vector
inline void set ( const Hep3Vector & v, double t );
inline void set ( double t, const Hep3Vector & v );
// Set using specified space vector and time component
// 2 - Synonyms for accessing coordinates and properties
inline double getX() const;
inline double getY() const;
inline double getZ() const;
inline double getT() const;
// Get position and time.
inline Hep3Vector v() const;
inline Hep3Vector getV() const;
// Get spatial component. Same as vect.
inline void setV(const Hep3Vector &);
// Set spatial component. Same as setVect.
// 2a - Setting space coordinates in different ways
inline void setV( double x, double y, double z );
inline void setRThetaPhi( double r, double theta, double phi);
inline void setREtaPhi( double r, double eta, double phi);
inline void setRhoPhiZ( double rho, double phi, double z );
// 3 - Comparisions (dictionary, near-ness, and geometric)
int compare( const HepLorentzVector & w ) const;
bool operator >( const HepLorentzVector & w ) const;
bool operator <( const HepLorentzVector & w ) const;
bool operator>=( const HepLorentzVector & w ) const;
bool operator<=( const HepLorentzVector & w ) const;
bool isNear ( const HepLorentzVector & w,
double epsilon=tolerance ) const;
double howNear( const HepLorentzVector & w ) const;
// Is near using Euclidean measure t**2 + v**2
bool isNearCM ( const HepLorentzVector & w,
double epsilon=tolerance ) const;
double howNearCM( const HepLorentzVector & w ) const;
// Is near in CM frame: Applicable only for two timelike HepLorentzVectors
// If w1 and w2 are already in their CM frame, then w1.isNearCM(w2)
// is exactly equivalent to w1.isNear(w2).
// If w1 and w2 have T components of zero, w1.isNear(w2) is exactly
// equivalent to w1.getV().isNear(w2.v()).
bool isParallel( const HepLorentzVector & w,
double epsilon=tolerance ) const;
// Test for isParallel is within tolerance epsilon
double howParallel (const HepLorentzVector & w) const;
static double getTolerance();
static double setTolerance( double tol );
// Set the tolerance for HepLorentzVectors to be considered near
// The same tolerance is used for determining isLightlike, and isParallel
double deltaR(const HepLorentzVector & v) const;
// std::sqrt ( (delta eta)^2 + (delta phi)^2 ) of space part
// 4 - Intrinsic properties
double howLightlike() const;
// Close to zero for almost lightlike 4-vectors; up to 1.
inline double euclideanNorm2() const;
// Sum of the squares of time and space components; not Lorentz invariant.
inline double euclideanNorm() const;
// Length considering the metric as (+ + + +); not Lorentz invariant.
// 4a - Relativistic kinematic properties
// All Relativistic kinematic properties are independent of the sense of metric
inline double restMass2() const;
inline double invariantMass2() const;
// Rest mass squared -- same as m2()
inline double restMass() const;
inline double invariantMass() const;
// Same as m(). If m2() is negative then -std::sqrt(-m2()) is returned.
// The following properties are rest-frame related,
// and are applicable only to non-spacelike 4-vectors
HepLorentzVector rest4Vector() const;
// This 4-vector, boosted into its own rest frame: (0, 0, 0, m())
// The following relation holds by definition:
// w.rest4Vector().boost(w.boostVector()) == w
// Beta and gamma of the boost vector
double beta() const;
// Relativistic beta of the boost vector
double gamma() const;
// Relativistic gamma of the boost vector
inline double eta() const;
// Pseudorapidity (of the space part)
inline double eta(const Hep3Vector & ref) const;
// Pseudorapidity (of the space part) w.r.t. specified direction
double rapidity(const Hep3Vector & ref) const;
// Rapidity in specified direction
double coLinearRapidity() const;
// Rapidity, in the relativity textbook sense: atanh (|P|/E)
Hep3Vector findBoostToCM() const;
// Boost needed to get to center-of-mass frame:
// w.findBoostToCM() == - w.boostVector()
// w.boost(w.findBoostToCM()) == w.rest4Vector()
Hep3Vector findBoostToCM( const HepLorentzVector & w ) const;
// Boost needed to get to combined center-of-mass frame:
// w1.findBoostToCM(w2) == w2.findBoostToCM(w1)
// w.findBoostToCM(w) == w.findBoostToCM()
inline double et2(const Hep3Vector &) const;
// Transverse energy w.r.t. given axis squared.
inline double et(const Hep3Vector &) const;
// Transverse energy w.r.t. given axis.
// 4b - Methods combining two 4-vectors
inline double diff2( const HepLorentzVector & w ) const;
// (this - w).dot(this-w); sign depends on metric choice
inline double delta2Euclidean ( const HepLorentzVector & w ) const;
// Euclidean norm of differnce: (delta_T)^2 + (delta_V)^2
// 5 - Properties releative to z axis and to arbitrary directions
double plus( const Hep3Vector & ref ) const;
// t + projection in reference direction
double minus( const Hep3Vector & ref ) const;
// t - projection in reference direction
// 7 - Rotations and boosts
HepLorentzVector & rotate ( const Hep3Vector & axis, double delta );
// Same as rotate (delta, axis)
HepLorentzVector & rotate ( const HepAxisAngle & ax );
HepLorentzVector & rotate ( const HepEulerAngles & e );
HepLorentzVector & rotate ( double phi,
double theta,
double psi );
// Rotate using these HepEuler angles - see Goldstein page 107 for conventions
HepLorentzVector & boost ( const Hep3Vector & axis, double beta );
// Normalizes the Hep3Vector to define a direction, and uses beta to
// define the magnitude of the boost.
friend HepLorentzVector rotationXOf
( const HepLorentzVector & vec, double delta );
friend HepLorentzVector rotationYOf
( const HepLorentzVector & vec, double delta );
friend HepLorentzVector rotationZOf
( const HepLorentzVector & vec, double delta );
friend HepLorentzVector rotationOf
( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
friend HepLorentzVector rotationOf
( const HepLorentzVector & vec, const HepAxisAngle & ax );
friend HepLorentzVector rotationOf
( const HepLorentzVector & vec, const HepEulerAngles & e );
friend HepLorentzVector rotationOf
( const HepLorentzVector & vec, double phi,
double theta,
double psi );
inline friend HepLorentzVector boostXOf
( const HepLorentzVector & vec, double beta );
inline friend HepLorentzVector boostYOf
( const HepLorentzVector & vec, double beta );
inline friend HepLorentzVector boostZOf
( const HepLorentzVector & vec, double beta );
inline friend HepLorentzVector boostOf
( const HepLorentzVector & vec, const Hep3Vector & betaVector );
inline friend HepLorentzVector boostOf
( const HepLorentzVector & vec, const Hep3Vector & axis, double beta );
private:
Hep3Vector pp;
double ee;
DLL_API static double tolerance;
DLL_API static double metric;
}; // HepLorentzVector
// 8 - Axial Unit 4-vectors
static const HepLorentzVector X_HAT4 = HepLorentzVector( 1, 0, 0, 0 );
static const HepLorentzVector Y_HAT4 = HepLorentzVector( 0, 1, 0, 0 );
static const HepLorentzVector Z_HAT4 = HepLorentzVector( 0, 0, 1, 0 );
static const HepLorentzVector T_HAT4 = HepLorentzVector( 0, 0, 0, 1 );
// Global methods
std::ostream & operator << (std::ostream &, const HepLorentzVector &);
// Output to a stream.
std::istream & operator >> (std::istream &, HepLorentzVector &);
// Input from a stream.
typedef HepLorentzVector HepLorentzVectorD;
typedef HepLorentzVector HepLorentzVectorF;
inline HepLorentzVector operator * (const HepLorentzVector &, double a);
inline HepLorentzVector operator * (double a, const HepLorentzVector &);
// Scaling LorentzVector with a real number
HepLorentzVector operator / (const HepLorentzVector &, double a);
// Dividing LorentzVector by a real number
// Tcomponent definition:
// Signature protection for 4-vector constructors taking 4 components
class Tcomponent {
private:
double t_;
public:
explicit Tcomponent(double t) : t_(t) {}
operator double() const { return t_; }
}; // Tcomponent
} // namespace CLHEP
#include "CLHEP/Vector/LorentzVector.icc"
#endif /* HEP_LORENTZVECTOR_H */
@@ -0,0 +1,434 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepLorentzVector class.
//
#include <cmath>
namespace CLHEP {
inline double HepLorentzVector::x() const { return pp.x(); }
inline double HepLorentzVector::y() const { return pp.y(); }
inline double HepLorentzVector::z() const { return pp.z(); }
inline double HepLorentzVector::t() const { return ee; }
inline HepLorentzVector::
HepLorentzVector(double x, double y, double z, double t)
: pp(x, y, z), ee(t) {}
inline HepLorentzVector:: HepLorentzVector(double x, double y, double z)
: pp(x, y, z), ee(0) {}
inline HepLorentzVector:: HepLorentzVector(double t)
: pp(0, 0, 0), ee(t) {}
inline HepLorentzVector:: HepLorentzVector()
: pp(0, 0, 0), ee(0) {}
inline HepLorentzVector::HepLorentzVector(const Hep3Vector & p, double e)
: pp(p), ee(e) {}
inline HepLorentzVector::HepLorentzVector(double e, const Hep3Vector & p)
: pp(p), ee(e) {}
inline HepLorentzVector::HepLorentzVector(const HepLorentzVector & p)
: pp(p.x(), p.y(), p.z()), ee(p.t()) {}
inline HepLorentzVector::~HepLorentzVector() {}
inline HepLorentzVector::operator const Hep3Vector & () const {return pp;}
inline HepLorentzVector::operator Hep3Vector & () { return pp; }
inline void HepLorentzVector::setX(double a) { pp.setX(a); }
inline void HepLorentzVector::setY(double a) { pp.setY(a); }
inline void HepLorentzVector::setZ(double a) { pp.setZ(a); }
inline void HepLorentzVector::setT(double a) { ee = a;}
inline double HepLorentzVector::px() const { return pp.x(); }
inline double HepLorentzVector::py() const { return pp.y(); }
inline double HepLorentzVector::pz() const { return pp.z(); }
inline double HepLorentzVector::e() const { return ee; }
inline void HepLorentzVector::setPx(double a) { pp.setX(a); }
inline void HepLorentzVector::setPy(double a) { pp.setY(a); }
inline void HepLorentzVector::setPz(double a) { pp.setZ(a); }
inline void HepLorentzVector::setE(double a) { ee = a;}
inline Hep3Vector HepLorentzVector::vect() const { return pp; }
inline void HepLorentzVector::setVect(const Hep3Vector &p) { pp = p; }
inline double HepLorentzVector::theta() const { return pp.theta(); }
inline double HepLorentzVector::cosTheta() const { return pp.cosTheta(); }
inline double HepLorentzVector::phi() const { return pp.phi(); }
inline double HepLorentzVector::rho() const { return pp.mag(); }
inline void HepLorentzVector::setTheta(double a) { pp.setTheta(a); }
inline void HepLorentzVector::setPhi(double a) { pp.setPhi(a); }
inline void HepLorentzVector::setRho(double a) { pp.setMag(a); }
double & HepLorentzVector::operator [] (int i) { return (*this)(i); }
double HepLorentzVector::operator [] (int i) const { return (*this)(i); }
inline HepLorentzVector &
HepLorentzVector::operator = (const HepLorentzVector & q) {
pp = q.vect();
ee = q.t();
return *this;
}
inline HepLorentzVector
HepLorentzVector::operator + (const HepLorentzVector & q) const {
return HepLorentzVector(x()+q.x(), y()+q.y(), z()+q.z(), t()+q.t());
}
inline HepLorentzVector &
HepLorentzVector::operator += (const HepLorentzVector & q) {
pp += q.vect();
ee += q.t();
return *this;
}
inline HepLorentzVector
HepLorentzVector::operator - (const HepLorentzVector & q) const {
return HepLorentzVector(x()-q.x(), y()-q.y(), z()-q.z(), t()-q.t());
}
inline HepLorentzVector &
HepLorentzVector::operator -= (const HepLorentzVector & q) {
pp -= q.vect();
ee -= q.t();
return *this;
}
inline HepLorentzVector HepLorentzVector::operator - () const {
return HepLorentzVector(-x(), -y(), -z(), -t());
}
inline HepLorentzVector& HepLorentzVector::operator *= (double a) {
pp *= a;
ee *= a;
return *this;
}
inline bool
HepLorentzVector::operator == (const HepLorentzVector & q) const {
return (vect()==q.vect() && t()==q.t());
}
inline bool
HepLorentzVector::operator != (const HepLorentzVector & q) const {
return (vect()!=q.vect() || t()!=q.t());
}
inline double HepLorentzVector::perp2() const { return pp.perp2(); }
inline double HepLorentzVector::perp() const { return pp.perp(); }
inline void HepLorentzVector::setPerp(double a) { pp.setPerp(a); }
inline double HepLorentzVector::perp2(const Hep3Vector &v) const {
return pp.perp2(v);
}
inline double HepLorentzVector::perp(const Hep3Vector &v) const {
return pp.perp(v);
}
inline double HepLorentzVector::angle(const Hep3Vector &v) const {
return pp.angle(v);
}
inline double HepLorentzVector::mag2() const {
return metric*(t()*t() - pp.mag2());
}
inline double HepLorentzVector::mag() const {
double mm = m2();
return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
}
inline double HepLorentzVector::m2() const {
return t()*t() - pp.mag2();
}
inline double HepLorentzVector::m() const { return mag(); }
inline double HepLorentzVector::mt2() const {
return e()*e() - pz()*pz();
}
inline double HepLorentzVector::mt() const {
double mm = mt2();
return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
}
inline double HepLorentzVector::et2() const {
double pt2 = pp.perp2();
return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+z()*z());
}
inline double HepLorentzVector::et() const {
double etet = et2();
return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
}
inline double HepLorentzVector::et2(const Hep3Vector & v) const {
double pt2 = pp.perp2(v);
double pv = pp.dot(v.unit());
return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+pv*pv);
}
inline double HepLorentzVector::et(const Hep3Vector & v) const {
double etet = et2(v);
return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
}
inline void
HepLorentzVector::setVectMag(const Hep3Vector & spatial, double magnitude) {
setVect(spatial);
setT(std::sqrt(magnitude * magnitude + spatial * spatial));
}
inline void
HepLorentzVector::setVectM(const Hep3Vector & spatial, double mass) {
setVectMag(spatial, mass);
}
inline double HepLorentzVector::dot(const HepLorentzVector & q) const {
return metric*(t()*q.t() - z()*q.z() - y()*q.y() - x()*q.x());
}
inline double
HepLorentzVector::operator * (const HepLorentzVector & q) const {
return dot(q);
}
inline double HepLorentzVector::plus() const {
return t() + z();
}
inline double HepLorentzVector::minus() const {
return t() - z();
}
inline HepLorentzVector & HepLorentzVector::boost(const Hep3Vector & b) {
return boost(b.x(), b.y(), b.z());
}
inline double HepLorentzVector::pseudoRapidity() const {
return pp.pseudoRapidity();
}
inline double HepLorentzVector::eta() const {
return pp.pseudoRapidity();
}
inline double HepLorentzVector::eta( const Hep3Vector & ref ) const {
return pp.eta( ref );
}
inline HepLorentzVector &
HepLorentzVector::operator *= (const HepRotation & m) {
pp.transform(m);
return *this;
}
inline HepLorentzVector &
HepLorentzVector::transform(const HepRotation & m) {
pp.transform(m);
return *this;
}
inline HepLorentzVector operator * (const HepLorentzVector & p, double a) {
return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
}
inline HepLorentzVector operator * (double a, const HepLorentzVector & p) {
return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
}
// The following were added when ZOOM PhysicsVectors was merged in:
inline HepLorentzVector::HepLorentzVector(
double x, double y, double z, Tcomponent t ) :
pp(x, y, z), ee(t) {}
inline void HepLorentzVector::set(
double x, double y, double z, Tcomponent t ) {
pp.set(x,y,z);
ee = t;
}
inline void HepLorentzVector::set(
double x, double y, double z, double t ) {
set (x,y,z,Tcomponent(t));
}
inline HepLorentzVector::HepLorentzVector(
Tcomponent t, double x, double y, double z ) :
pp(x, y, z), ee(t) {}
inline void HepLorentzVector::set(
Tcomponent t, double x, double y, double z ) {
pp.set(x,y,z);
ee = t;
}
inline void HepLorentzVector::set( Tcomponent t ) {
pp.set(0, 0, 0);
ee = t;
}
inline void HepLorentzVector::set( double t ) {
pp.set(0, 0, 0);
ee = t;
}
inline HepLorentzVector::HepLorentzVector( Tcomponent t ) :
pp(0, 0, 0), ee(t) {}
inline void HepLorentzVector::set( const Hep3Vector & v ) {
pp = v;
ee = 0;
}
inline HepLorentzVector::HepLorentzVector( const Hep3Vector & v ) :
pp(v), ee(0) {}
inline void HepLorentzVector::setV(const Hep3Vector & v) {
pp = v;
}
inline HepLorentzVector & HepLorentzVector::operator=(const Hep3Vector & v) {
pp = v;
ee = 0;
return *this;
}
inline double HepLorentzVector::getX() const { return pp.x(); }
inline double HepLorentzVector::getY() const { return pp.y(); }
inline double HepLorentzVector::getZ() const { return pp.z(); }
inline double HepLorentzVector::getT() const { return ee; }
inline Hep3Vector HepLorentzVector::getV() const { return pp; }
inline Hep3Vector HepLorentzVector::v() const { return pp; }
inline void HepLorentzVector::set(double t, const Hep3Vector & v) {
pp = v;
ee = t;
}
inline void HepLorentzVector::set(const Hep3Vector & v, double t) {
pp = v;
ee = t;
}
inline void HepLorentzVector::setV( double x,
double y,
double z ) { pp.set(x, y, z); }
inline void HepLorentzVector::setRThetaPhi
( double r, double theta, double phi )
{ pp.setRThetaPhi( r, theta, phi ); }
inline void HepLorentzVector::setREtaPhi
( double r, double eta, double phi )
{ pp.setREtaPhi( r, eta, phi ); }
inline void HepLorentzVector::setRhoPhiZ
( double rho, double phi, double z )
{ pp.setRhoPhiZ ( rho, phi, z ); }
inline bool HepLorentzVector::isTimelike() const {
return restMass2() > 0;
}
inline bool HepLorentzVector::isSpacelike() const {
return restMass2() < 0;
}
inline bool HepLorentzVector::isLightlike(double epsilon) const {
return std::fabs(restMass2()) < 2.0 * epsilon * ee * ee;
}
inline double HepLorentzVector::diff2( const HepLorentzVector & w ) const {
return metric*( (ee-w.ee)*(ee-w.ee) - (pp-w.pp).mag2() );
}
inline double HepLorentzVector::delta2Euclidean
( const HepLorentzVector & w ) const {
return (ee-w.ee)*(ee-w.ee) + (pp-w.pp).mag2();
}
inline double HepLorentzVector::euclideanNorm2() const {
return ee*ee + pp.mag2();
}
inline double HepLorentzVector::euclideanNorm() const {
return std::sqrt(euclideanNorm2());
}
inline double HepLorentzVector::restMass2() const { return m2(); }
inline double HepLorentzVector::invariantMass2() const { return m2(); }
inline double HepLorentzVector::restMass() const {
// if( t() < 0.0 )
// std::cerr << "HepLorentzVector::restMass() - "
// << "E^2-p^2 < 0 for this particle. Magnitude returned."
// << std::endl;
return t() < 0.0 ? -m() : m();
}
inline double HepLorentzVector::invariantMass() const {
// if( t() < 0.0 )
// std::cerr << "HepLorentzVector::invariantMass() - "
// << "E^2-p^2 < 0 for this particle. Magnitude returned."
// << std::endl;
return t() < 0.0 ? -m() : m();
}
inline double HepLorentzVector::invariantMass2
(const HepLorentzVector & w) const {
return (*this + w).m2();
} /* invariantMass2 */
//-*********
// boostOf()
//-*********
// Each of these is a shell over a boost method.
inline HepLorentzVector boostXOf
(const HepLorentzVector & vec, double beta) {
HepLorentzVector vv (vec);
return vv.boostX (beta);
}
inline HepLorentzVector boostYOf
(const HepLorentzVector & vec, double beta) {
HepLorentzVector vv (vec);
return vv.boostY (beta);
}
inline HepLorentzVector boostZOf
(const HepLorentzVector & vec, double beta) {
HepLorentzVector vv (vec);
return vv.boostZ (beta);
}
inline HepLorentzVector boostOf
(const HepLorentzVector & vec, const Hep3Vector & betaVector ) {
HepLorentzVector vv (vec);
return vv.boost (betaVector);
}
inline HepLorentzVector boostOf
(const HepLorentzVector & vec, const Hep3Vector & axis, double beta) {
HepLorentzVector vv (vec);
return vv.boost (axis, beta);
}
} // namespace CLHEP
+417
View File
@@ -0,0 +1,417 @@
// -*- C++ -*-
// CLASSDOC OFF
// $Id:$
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepRotation class for performing rotations
// on objects of the Hep3Vector (and HepLorentzVector) class.
//
// HepRotation is a concrete implementation of Hep3RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h, LorentzRotation.h
//
// .SS Author
// Leif Lonnblad, Mark Fischler
#ifndef HEP_ROTATION_H
#define HEP_ROTATION_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
#include "CLHEP/Vector/RotationX.h"
#include "CLHEP/Vector/RotationY.h"
#include "CLHEP/Vector/RotationZ.h"
#include "CLHEP/Vector/LorentzVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class HepRotation;
inline HepRotation inverseOf ( const HepRotation & r );
inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r);
inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r);
inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r);
/**
* @author
* @ingroup vector
*/
class HepRotation {
public:
// ---------- Constructors and Assignment:
inline HepRotation();
// Default constructor. Gives a unit matrix.
inline HepRotation(const HepRotation & m);
// Copy constructor.
inline HepRotation(const HepRotationX & m);
inline HepRotation(const HepRotationY & m);
inline HepRotation(const HepRotationZ & m);
// Construct from specialized rotation.
HepRotation & set( const Hep3Vector & axis, double delta );
HepRotation ( const Hep3Vector & axis, double delta );
// Construct from axis and angle.
HepRotation & set( const HepAxisAngle & ax );
HepRotation ( const HepAxisAngle & ax );
// Construct from AxisAngle structure.
HepRotation & set( double phi, double theta, double psi );
HepRotation ( double phi, double theta, double psi );
// Construct from three Euler angles (in radians).
HepRotation & set( const HepEulerAngles & e );
HepRotation ( const HepEulerAngles & e );
// Construct from EulerAngles structure.
HepRotation ( const Hep3Vector & colX,
const Hep3Vector & colY,
const Hep3Vector & colZ );
// Construct from three *orthogonal* unit vector columns.
// NOTE:
// This constructor, and the two set methods below,
// will check that the columns (or rows) form an orthonormal
// matrix, and will adjust values so that this relation is
// as exact as possible.
HepRotation & set( const Hep3Vector & colX,
const Hep3Vector & colY,
const Hep3Vector & colZ );
// supply three *orthogonal* unit vectors for the columns.
HepRotation & setRows( const Hep3Vector & rowX,
const Hep3Vector & rowY,
const Hep3Vector & rowZ );
// supply three *orthogonal* unit vectors for the rows.
inline HepRotation & set(const HepRotationX & r);
inline HepRotation & set(const HepRotationY & r);
inline HepRotation & set(const HepRotationZ & r);
// set from specialized rotation.
inline HepRotation & operator = (const HepRotation & r);
// Assignment.
inline HepRotation & operator = (const HepRotationX & r);
inline HepRotation & operator = (const HepRotationY & r);
inline HepRotation & operator = (const HepRotationZ & r);
// Assignment from specialized rotation.
inline HepRotation &set( const HepRep3x3 & m );
inline HepRotation ( const HepRep3x3 & m );
// WARNING - NO CHECKING IS DONE!
// Constructon directly from from a 3x3 representation,
// which is required to be an orthogonal matrix.
inline ~HepRotation();
// Trivial destructor.
// ---------- Accessors:
inline Hep3Vector colX() const;
inline Hep3Vector colY() const;
inline Hep3Vector colZ() const;
// orthogonal unit-length column vectors
inline Hep3Vector rowX() const;
inline Hep3Vector rowY() const;
inline Hep3Vector rowZ() const;
// orthogonal unit-length row vectors
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
// Elements of the rotation matrix (Geant4).
inline HepRep3x3 rep3x3() const;
// 3x3 representation:
// ------------ Subscripting:
class HepRotation_row {
public:
inline HepRotation_row(const HepRotation &, int);
inline double operator [] (int) const;
private:
const HepRotation & rr;
int ii;
};
// Helper class for implemention of C-style subscripting r[i][j]
inline const HepRotation_row operator [] (int) const;
// Returns object of the helper class for C-style subscripting r[i][j]
// i and j range from 0 to 2.
double operator () (int, int) const;
// Fortran-style subscripting: returns (i,j) element of the rotation matrix.
// Note: i and j still range from 0 to 2. [Rotation.cc]
// ------------ Euler angles:
inline double getPhi () const;
inline double getTheta() const;
inline double getPsi () const;
double phi () const;
double theta() const;
double psi () const;
HepEulerAngles eulerAngles() const;
// ------------ axis & angle of rotation:
inline double getDelta() const;
inline Hep3Vector getAxis () const;
double delta() const;
Hep3Vector axis () const;
HepAxisAngle axisAngle() const;
void getAngleAxis(double & delta, Hep3Vector & axis) const;
// Returns the rotation angle and rotation axis (Geant4). [Rotation.cc]
// ------------- Angles of rotated axes
double phiX() const;
double phiY() const;
double phiZ() const;
double thetaX() const;
double thetaY() const;
double thetaZ() const;
// Return angles (RADS) made by rotated axes against original axes (Geant4).
// [Rotation.cc]
// ---------- Other accessors treating pure rotation as a 4-rotation
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
// orthosymplectic 4-vector columns - T component will be zero
inline HepLorentzVector col4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
// orthosymplectic 4-vector rows - T component will be zero
inline HepLorentzVector row4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline double xt() const;
inline double yt() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
// Will be zero for this pure Rotation
inline double tt() const;
// Will be one for this pure Rotation
inline HepRep4x4 rep4x4() const;
// 4x4 representation.
// --------- Mutators
void setPhi (double phi);
// change Euler angle phi, leaving theta and psi unchanged.
void setTheta (double theta);
// change Euler angle theta, leaving phi and psi unchanged.
void setPsi (double psi);
// change Euler angle psi, leaving theta and phi unchanged.
void setAxis (const Hep3Vector & axis);
// change rotation axis, leaving delta unchanged.
void setDelta (double delta);
// change angle of rotation, leaving rotation axis unchanged.
// ---------- Decomposition:
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
// These are trivial, as the boost vector is 0. [RotationP.cc]
// ---------- Comparisons:
bool isIdentity() const;
// Returns true if the identity matrix (Geant4). [Rotation.cc]
int compare( const HepRotation & r ) const;
// Dictionary-order comparison, in order zz, zy, zx, yz, ... xx
// Used in operator<, >, <=, >=
inline bool operator== ( const HepRotation & r ) const;
inline bool operator!= ( const HepRotation & r ) const;
inline bool operator< ( const HepRotation & r ) const;
inline bool operator> ( const HepRotation & r ) const;
inline bool operator<= ( const HepRotation & r ) const;
inline bool operator>= ( const HepRotation & r ) const;
double distance2( const HepRotation & r ) const;
// 3 - Tr ( this/r ) -- This works with RotationX, Y or Z also
double howNear( const HepRotation & r ) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
double distance2( const HepBoost & lt ) const;
// 3 - Tr ( this ) + |b|^2 / (1-|b|^2)
double distance2( const HepLorentzRotation & lt ) const;
// 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
double howNear( const HepBoost & lt ) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear( const HepBoost & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// distance2 (IDENTITY), which is 3 - Tr ( *this )
void rectify();
// non-const but logically moot correction for accumulated roundoff errors
// rectify averages the matrix with the transpose of its actual
// inverse (absent accumulated roundoff errors, the transpose IS
// the inverse)); this removes to first order those errors.
// Then it formally extracts axis and delta, and forms a true
// HepRotation with those values of axis and delta.
// ---------- Application:
inline Hep3Vector operator() (const Hep3Vector & p) const;
// Rotate a Hep3Vector.
inline Hep3Vector operator * (const Hep3Vector & p) const;
// Multiplication with a Hep3Vector.
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Rotate (the space part of) a HepLorentzVector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a HepLorentzVector.
// ---------- Operations in the group of Rotations
inline HepRotation operator * (const HepRotation & r) const;
// Product of two rotations (this) * r - matrix multiplication
inline HepRotation operator * (const HepRotationX & rx) const;
inline HepRotation operator * (const HepRotationY & ry) const;
inline HepRotation operator * (const HepRotationZ & rz) const;
// Product of two rotations (this) * r - faster when specialized type
inline HepRotation & operator *= (const HepRotation & r);
inline HepRotation & transform (const HepRotation & r);
// Matrix multiplication.
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
inline HepRotation & operator *= (const HepRotationX & r);
inline HepRotation & operator *= (const HepRotationY & r);
inline HepRotation & operator *= (const HepRotationZ & r);
inline HepRotation & transform (const HepRotationX & r);
inline HepRotation & transform (const HepRotationY & r);
inline HepRotation & transform (const HepRotationZ & r);
// Matrix multiplication by specialized matrices
HepRotation & rotateX(double delta);
// Rotation around the x-axis; equivalent to R = RotationX(delta) * R
HepRotation & rotateY(double delta);
// Rotation around the y-axis; equivalent to R = RotationY(delta) * R
HepRotation & rotateZ(double delta);
// Rotation around the z-axis; equivalent to R = RotationZ(delta) * R
HepRotation & rotate(double delta, const Hep3Vector & axis);
inline HepRotation & rotate(double delta, const Hep3Vector * axis);
// Rotation around a specified vector.
// r.rotate(d,a) is equivalent to r = Rotation(d,a) * r
HepRotation & rotateAxes(const Hep3Vector & newX,
const Hep3Vector & newY,
const Hep3Vector & newZ);
// Rotation of local axes defined by 3 orthonormal vectors (Geant4).
// Equivalent to r = Rotation (newX, newY, newZ) * r
inline HepRotation inverse() const;
// Returns the inverse.
inline HepRotation & invert();
// Inverts the Rotation matrix.
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Aligned six-digit-accurate output of the rotation matrix. [RotationIO.cc]
// ---------- Identity Rotation:
DLL_API static const HepRotation IDENTITY;
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
inline HepRotation(double mxx, double mxy, double mxz,
double myx, double myy, double myz,
double mzx, double mzy, double mzz);
// Protected constructor.
// DOES NOT CHECK FOR VALIDITY AS A ROTATION.
friend HepRotation operator* (const HepRotationX & rx, const HepRotation & r);
friend HepRotation operator* (const HepRotationY & ry, const HepRotation & r);
friend HepRotation operator* (const HepRotationZ & rz, const HepRotation & r);
double rxx, rxy, rxz,
ryx, ryy, ryz,
rzx, rzy, rzz;
// The matrix elements.
private:
bool
setCols ( const Hep3Vector & u1, // Vectors assume to be of unit length
const Hep3Vector & u2,
const Hep3Vector & u3,
double u1u2,
Hep3Vector & v1, // Returned vectors
Hep3Vector & v2,
Hep3Vector & v3 ) const;
void setArbitrarily (const Hep3Vector & colX, // assumed to be of unit length
Hep3Vector & v1,
Hep3Vector & v2,
Hep3Vector & v3) const;
}; // HepRotation
inline
std::ostream & operator <<
( std::ostream & os, const HepRotation & r ) {return r.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/Rotation.icc"
#endif /* HEP_ROTATION_H */
+348
View File
@@ -0,0 +1,348 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepRotation class
//
namespace CLHEP {
// Put commonly used accessors as early as possible to avoid inlining misses:
inline double HepRotation::xx() const { return rxx; }
inline double HepRotation::xy() const { return rxy; }
inline double HepRotation::xz() const { return rxz; }
inline double HepRotation::yx() const { return ryx; }
inline double HepRotation::yy() const { return ryy; }
inline double HepRotation::yz() const { return ryz; }
inline double HepRotation::zx() const { return rzx; }
inline double HepRotation::zy() const { return rzy; }
inline double HepRotation::zz() const { return rzz; }
inline HepRep3x3 HepRotation::rep3x3() const {
return HepRep3x3 ( rxx, rxy, rxz,
ryx, ryy, ryz,
rzx, rzy, rzz );
}
inline double HepRotation::xt() const { return 0.0; }
inline double HepRotation::yt() const { return 0.0; }
inline double HepRotation::zt() const { return 0.0; }
inline double HepRotation::tx() const { return 0.0; }
inline double HepRotation::ty() const { return 0.0; }
inline double HepRotation::tz() const { return 0.0; }
inline double HepRotation::tt() const { return 1.0; }
inline HepRep4x4 HepRotation::rep4x4() const {
return HepRep4x4 ( rxx, rxy, rxz, 0.0,
ryx, ryy, ryz, 0.0,
rzx, rzy, rzz, 0.0,
0.0, 0.0, 0.0, 1.0 );
}
// Ctors etc:
inline HepRotation::HepRotation() : rxx(1.0), rxy(0.0), rxz(0.0),
ryx(0.0), ryy(1.0), ryz(0.0),
rzx(0.0), rzy(0.0), rzz(1.0) {}
inline HepRotation::HepRotation(const HepRotation & m) :
rxx(m.rxx), rxy(m.rxy), rxz(m.rxz),
ryx(m.ryx), ryy(m.ryy), ryz(m.ryz),
rzx(m.rzx), rzy(m.rzy), rzz(m.rzz) {}
inline HepRotation::HepRotation
(double mxx, double mxy, double mxz,
double myx, double myy, double myz,
double mzx, double mzy, double mzz) :
rxx(mxx), rxy(mxy), rxz(mxz),
ryx(myx), ryy(myy), ryz(myz),
rzx(mzx), rzy(mzy), rzz(mzz) {}
inline HepRotation::HepRotation ( const HepRep3x3 & m ) :
rxx(m.xx_), rxy(m.xy_), rxz(m.xz_),
ryx(m.yx_), ryy(m.yy_), ryz(m.yz_),
rzx(m.zx_), rzy(m.zy_), rzz(m.zz_) {}
inline HepRotation::HepRotation(const HepRotationX & rx) :
rxx(1.0), rxy(0.0), rxz(0.0),
ryx(0.0), ryy(rx.yy()), ryz(rx.yz()),
rzx(0.0), rzy(rx.zy()), rzz(rx.zz()) {}
inline HepRotation::HepRotation(const HepRotationY & ry) :
rxx(ry.xx()), rxy(0.0), rxz(ry.xz()),
ryx(0.0), ryy(1.0), ryz(0.0),
rzx(ry.zx()), rzy(0.0), rzz(ry.zz()) {}
inline HepRotation::HepRotation(const HepRotationZ & rz) :
rxx(rz.xx()), rxy(rz.xy()), rxz(0.0),
ryx(rz.yx()), ryy(rz.yy()), ryz(0.0),
rzx(0.0), rzy(0.0), rzz(1.0) {}
inline HepRotation::~HepRotation() {}
// More accessors:
inline HepRotation::HepRotation_row::HepRotation_row
(const HepRotation & r, int i) : rr(r), ii(i) {}
inline double HepRotation::HepRotation_row::operator [] (int jj) const {
return rr(ii,jj);
}
inline
const HepRotation::HepRotation_row HepRotation::operator [] (int i) const {
return HepRotation_row(*this, i);
}
inline Hep3Vector HepRotation::colX() const
{ return Hep3Vector ( rxx, ryx, rzx ); }
inline Hep3Vector HepRotation::colY() const
{ return Hep3Vector ( rxy, ryy, rzy ); }
inline Hep3Vector HepRotation::colZ() const
{ return Hep3Vector ( rxz, ryz, rzz ); }
inline Hep3Vector HepRotation::rowX() const
{ return Hep3Vector ( rxx, rxy, rxz ); }
inline Hep3Vector HepRotation::rowY() const
{ return Hep3Vector ( ryx, ryy, ryz ); }
inline Hep3Vector HepRotation::rowZ() const
{ return Hep3Vector ( rzx, rzy, rzz ); }
inline HepLorentzVector HepRotation::col1() const
{ return HepLorentzVector (colX(), 0); }
inline HepLorentzVector HepRotation::col2() const
{ return HepLorentzVector (colY(), 0); }
inline HepLorentzVector HepRotation::col3() const
{ return HepLorentzVector (colZ(), 0); }
inline HepLorentzVector HepRotation::col4() const
{ return HepLorentzVector (0,0,0,1); }
inline HepLorentzVector HepRotation::row1() const
{ return HepLorentzVector (rowX(), 0); }
inline HepLorentzVector HepRotation::row2() const
{ return HepLorentzVector (rowY(), 0); }
inline HepLorentzVector HepRotation::row3() const
{ return HepLorentzVector (rowZ(), 0); }
inline HepLorentzVector HepRotation::row4() const
{ return HepLorentzVector (0,0,0,1); }
inline double HepRotation::getPhi () const { return phi(); }
inline double HepRotation::getTheta() const { return theta(); }
inline double HepRotation::getPsi () const { return psi(); }
inline double HepRotation::getDelta() const { return delta(); }
inline Hep3Vector HepRotation::getAxis () const { return axis(); }
inline HepRotation & HepRotation::operator = (const HepRotation & m) {
rxx = m.rxx;
rxy = m.rxy;
rxz = m.rxz;
ryx = m.ryx;
ryy = m.ryy;
ryz = m.ryz;
rzx = m.rzx;
rzy = m.rzy;
rzz = m.rzz;
return *this;
}
inline HepRotation & HepRotation::set(const HepRep3x3 & m) {
rxx = m.xx_;
rxy = m.xy_;
rxz = m.xz_;
ryx = m.yx_;
ryy = m.yy_;
ryz = m.yz_;
rzx = m.zx_;
rzy = m.zy_;
rzz = m.zz_;
return *this;
}
inline HepRotation & HepRotation::set(const HepRotationX & r) {
return (set (r.rep3x3()));
}
inline HepRotation & HepRotation::set(const HepRotationY & r) {
return (set (r.rep3x3()));
}
inline HepRotation & HepRotation::set(const HepRotationZ & r) {
return (set (r.rep3x3()));
}
inline HepRotation & HepRotation::operator= (const HepRotationX & r) {
return (set (r.rep3x3()));
}
inline HepRotation & HepRotation::operator= (const HepRotationY & r) {
return (set (r.rep3x3()));
}
inline HepRotation & HepRotation::operator= (const HepRotationZ & r) {
return (set (r.rep3x3()));
}
inline Hep3Vector HepRotation::operator * (const Hep3Vector & p) const {
return Hep3Vector(rxx*p.x() + rxy*p.y() + rxz*p.z(),
ryx*p.x() + ryy*p.y() + ryz*p.z(),
rzx*p.x() + rzy*p.y() + rzz*p.z());
// This is identical to the code in the CLHEP 1.6 version
}
inline Hep3Vector HepRotation::operator () (const Hep3Vector & p) const {
register double x = p.x();
register double y = p.y();
register double z = p.z();
return Hep3Vector(rxx*x + rxy*y + rxz*z,
ryx*x + ryy*y + ryz*z,
rzx*x + rzy*y + rzz*z);
}
inline HepLorentzVector
HepRotation::operator () (const HepLorentzVector & w) const {
return HepLorentzVector( operator() (w.vect()), w.t() );
}
inline HepLorentzVector HepRotation::operator *
(const HepLorentzVector & p) const {
return operator()(p);
}
inline HepRotation HepRotation::operator* (const HepRotation & r) const {
return HepRotation(rxx*r.rxx + rxy*r.ryx + rxz*r.rzx,
rxx*r.rxy + rxy*r.ryy + rxz*r.rzy,
rxx*r.rxz + rxy*r.ryz + rxz*r.rzz,
ryx*r.rxx + ryy*r.ryx + ryz*r.rzx,
ryx*r.rxy + ryy*r.ryy + ryz*r.rzy,
ryx*r.rxz + ryy*r.ryz + ryz*r.rzz,
rzx*r.rxx + rzy*r.ryx + rzz*r.rzx,
rzx*r.rxy + rzy*r.ryy + rzz*r.rzy,
rzx*r.rxz + rzy*r.ryz + rzz*r.rzz );
}
inline HepRotation HepRotation::operator * (const HepRotationX & rx) const {
double yy = rx.yy();
double yz = rx.yz();
double zy = -yz;
double zz = yy;
return HepRotation(
rxx, rxy*yy + rxz*zy, rxy*yz + rxz*zz,
ryx, ryy*yy + ryz*zy, ryy*yz + ryz*zz,
rzx, rzy*yy + rzz*zy, rzy*yz + rzz*zz );
}
inline HepRotation HepRotation::operator * (const HepRotationY & ry) const {
double xx = ry.xx();
double xz = ry.xz();
double zx = -xz;
double zz = xx;
return HepRotation(
rxx*xx + rxz*zx, rxy, rxx*xz + rxz*zz,
ryx*xx + ryz*zx, ryy, ryx*xz + ryz*zz,
rzx*xx + rzz*zx, rzy, rzx*xz + rzz*zz );
}
inline HepRotation HepRotation::operator * (const HepRotationZ & rz) const {
double xx = rz.xx();
double xy = rz.xy();
double yx = -xy;
double yy = xx;
return HepRotation(
rxx*xx + rxy*yx, rxx*xy + rxy*yy, rxz,
ryx*xx + ryy*yx, ryx*xy + ryy*yy, ryz,
rzx*xx + rzy*yx, rzx*xy + rzy*yy, rzz );
}
inline HepRotation & HepRotation::operator *= (const HepRotation & r) {
return *this = (*this) * (r);
}
inline HepRotation & HepRotation::operator *= (const HepRotationX & r) {
return *this = (*this) * (r); }
inline HepRotation & HepRotation::operator *= (const HepRotationY & r) {
return *this = (*this) * (r); }
inline HepRotation & HepRotation::operator *= (const HepRotationZ & r) {
return *this = (*this) * (r); }
inline HepRotation & HepRotation::transform(const HepRotation & r) {
return *this = r * (*this);
}
inline HepRotation & HepRotation::transform(const HepRotationX & r) {
return *this = r * (*this); }
inline HepRotation & HepRotation::transform(const HepRotationY & r) {
return *this = r * (*this); }
inline HepRotation & HepRotation::transform(const HepRotationZ & r) {
return *this = r * (*this); }
inline HepRotation HepRotation::inverse() const {
return HepRotation( rxx, ryx, rzx,
rxy, ryy, rzy,
rxz, ryz, rzz );
}
inline HepRotation inverseOf (const HepRotation & r) {
return r.inverse();
}
inline HepRotation & HepRotation::invert() {
return *this=inverse();
}
inline HepRotation & HepRotation::rotate
(double delta, const Hep3Vector * p) {
return rotate(delta, *p);
}
inline bool HepRotation::operator== ( const HepRotation & r ) const {
return ( rxx==r.rxx && rxy==r.rxy && rxz==r.rxz &&
ryx==r.ryx && ryy==r.ryy && ryz==r.ryz &&
rzx==r.rzx && rzy==r.rzy && rzz==r.rzz );
}
inline bool HepRotation::operator!= ( const HepRotation & r ) const {
return ! operator==(r);
}
inline bool HepRotation::operator< ( const HepRotation & r ) const
{ return compare(r)< 0; }
inline bool HepRotation::operator<=( const HepRotation & r ) const
{ return compare(r)<=0; }
inline bool HepRotation::operator>=( const HepRotation & r ) const
{ return compare(r)>=0; }
inline bool HepRotation::operator> ( const HepRotation & r ) const
{ return compare(r)> 0; }
inline double HepRotation::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepRotation::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r){
HepRep3x3 m = r.rep3x3();
double c = rx.yy();
double s = rx.zy();
return HepRotation ( m.xx_, m.xy_, m.xz_,
c*m.yx_-s*m.zx_, c*m.yy_-s*m.zy_, c*m.yz_-s*m.zz_,
s*m.yx_+c*m.zx_, s*m.yy_+c*m.zy_, s*m.yz_+c*m.zz_ );
}
inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r){
HepRep3x3 m = r.rep3x3();
double c = ry.xx();
double s = ry.xz();
return HepRotation ( c*m.xx_+s*m.zx_, c*m.xy_+s*m.zy_, c*m.xz_+s*m.zz_,
m.yx_, m.yy_, m.yz_,
-s*m.xx_+c*m.zx_,-s*m.xy_+c*m.zy_,-s*m.xz_+c*m.zz_ );
}
inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r){
HepRep3x3 m = r.rep3x3();
double c = rz.xx();
double s = rz.yx();
return HepRotation ( c*m.xx_-s*m.yx_, c*m.xy_-s*m.yy_, c*m.xz_-s*m.yz_,
s*m.xx_+c*m.yx_, s*m.xy_+c*m.yy_, s*m.xz_+c*m.yz_,
m.zx_, m.zy_, m.zz_ );
}
} // namespace CLHEP
@@ -0,0 +1,399 @@
// -*- C++ -*-
// CLASSDOC OFF
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This contains the definition of two abstract interface classes:
// Hep4RotationInterface
// Hep3RotationInterface.
// However, these are mostly for defining methods which should be present in
// any 4- or 3-rotation class, however specialized. The actual classes do
// not inherit from these. The virtual function overhead turns out
// to be too steep for that to be practical.
//
// It may be desirable in the future to turn these classes into constraints
// in the Stroustrup sense, so as to enforce this interface, still without
// inheritance. However, they do contain an important static:
// static double tolerance to set criteria for relative nearness.
//
// This file also defines structs
// HepRep3x3;
// HepRep4x4;
// HepRep4x4Symmetric;
// which are used by various Rotation classes.
//
// Hep4RotationInterface
// contains all the methods to get attributes of either a
// HepLorentzRotation or a HepRotation -- any information
// that pertains to a LorentzRotation can also be defined
// for a HepRotation.(For example, the 4x4 representation
// would just have 0's in the space-time entries and 1 in
// the time-time entry.)
//
// Hep3RotationInterface
// inherits from Hep4RotationInterface, and adds methods
// which are well-defined only in the case of a Rotation.
// For example, a 3x3 representation is an attribute only
// if the generic LorentzRotation involves no boost.
//
// In terms of classes in the ZOOM PhysicsVectors package,
// Hep4RotationInterface <--> LorentzTransformationInterface
// Hep3RotationInterface <--> RotationInterface
//
// Hep4RotationInterface defines the required methods for:
// HepLorentzRotation
// HepBoost
// HepBoostX
// HepBoostY
// HepBoostZ
//
// Hep3RotationInterface defines the required methods for:
// HepRotation
// HepRotationX
// HepRotationY
// HepRotationZ
//
// .SS See Also
// Rotation.h, LorentzRotation.h
//
// .SS Author
// Mark Fischler
//
#ifndef HEP_ROTATION_INTERFACES_H
#define HEP_ROTATION_INTERFACES_H
#include "CLHEP/Vector/ThreeVector.h"
#include "CLHEP/Vector/LorentzVector.h"
#include "CLHEP/Vector/AxisAngle.h"
namespace CLHEP {
struct HepRep3x3;
struct HepRep4x4;
struct HepRep4x4Symmetric;
class HepRotation;
class HepRotationX;
class HepRotationY;
class HepRotationZ;
class HepLorentzRotation;
class HepBoost;
class HepBoostX;
class HepBoostY;
class HepBoostZ;
//-******************************
//
// Hep4RotationInterface
//
//-******************************
/**
* @author
* @ingroup vector
*/
class Hep4RotationInterface {
// All attributes of shared by HepLorentzRotation, HepBoost,
// HepBoostX, HepBoostY, HepBoostZ. HepRotation, HepRotationX,
// HepRotationY, HepRotationZ also share this attribute interface.
friend class HepRotation;
friend class HepRotationX;
friend class HepRotationY;
friend class HepRotationZ;
friend class HepLorentzRotation;
friend class HepBoost;
friend class HepBoostX;
friend class HepBoostY;
friend class HepBoostZ;
public:
DLL_API static double tolerance; // to determine relative nearness
// ---------- Accessors:
#ifdef ONLY_IN_CONCRETE_CLASSES
// orthosymplectic 4-vectors:
HepLorentzVector col1() const;
HepLorentzVector col2() const;
HepLorentzVector col3() const;
HepLorentzVector col4() const;
HepLorentzVector row1() const;
HepLorentzVector row2() const;
HepLorentzVector row3() const;
HepLorentzVector row4() const;
// individual elements:
double xx() const ;
double xy() const ;
double xz() const ;
double xt() const ;
double yx() const ;
double yy() const ;
double yz() const ;
double yt() const ;
double zx() const ;
double zy() const ;
double zz() const ;
double zt() const ;
double tx() const ;
double ty() const ;
double tz() const ;
double tt() const ;
// 4x4 representation:
//HepRep4x4 rep4x4() const; JMM Declared here but not defined anywhere!
// ---------- Operations:
// comparisons:
inline int compare( const Hep4RotationInterface & lt ) const;
// Dictionary-order comparisons, utilizing the decompose(b,r) method
// decomposition:
void decompose (HepAxisAngle & rotation, Hep3Vector & boost)const;
// Decompose as T= R * B, where R is pure rotation, B is pure boost.
void decompose (Hep3Vector & boost, HepAxisAngle & rotation)const;
// Decompose as T= B * R, where R is pure rotation, B is pure boost.
bool operator == (const Hep4RotationInterface & r) const;
bool operator != (const Hep4RotationInterface & r) const;
// relative comparison:
double norm2() const ;
double distance2( const Hep4RotationInterface & lt ) const ;
double howNear( const Hep4RotationInterface & lt ) const ;
bool isNear (const Hep4RotationInterface & lt,
double epsilon=tolerance) const ;
void rectify() ;
// non-const but logically const correction for accumulated roundoff errors
// ---------- Apply LorentzTransformations:
HepLorentzVector operator* ( const HepLorentzVector & w ) const ;
HepLorentzVector operator()( const HepLorentzVector & w ) const ;
// Apply to a 4-vector
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
#endif /* ONLY_IN_CONCRETE_CLASSES */
static double getTolerance();
static double setTolerance( double tol );
enum { ToleranceTicks = 100 };
protected:
~Hep4RotationInterface() {} // protect destructor to forbid instatiation
}; // Hep4RotationInterface
//-******************************
//
// Hep3RotationInterface
//
//-******************************
/**
* @author
* @ingroup vector
*/
class Hep3RotationInterface : public Hep4RotationInterface {
// All attributes of HepRotation, HepRotationX, HepRotationY, HepRotationZ
// beyond those available by virtue of being a Hep3RotationInterface.
friend class HepRotation;
friend class HepRotationX;
friend class HepRotationY;
friend class HepRotationZ;
public:
#ifdef ONLY_IN_CONCRETE_CLASSES
// Euler angles:
double getPhi () const ;
double getTheta() const ;
double getPsi () const ;
double phi () const ;
double theta() const ;
double psi () const ;
HepEulerAngles eulerAngles() const ;
// axis & angle of rotation:
double getDelta() const ;
Hep3Vector getAxis () const ;
double delta() const ;
Hep3Vector axis () const ;
HepAxisAngle axisAngle() const ;
// orthogonal unit-length vectors:
Hep3Vector rowX() const;
Hep3Vector rowY() const;
Hep3Vector rowZ() const;
Hep3Vector colX() const;
Hep3Vector colY() const;
Hep3Vector colZ() const;
//HepRep3x3 rep3x3() const; JMM Declared here but not defined anywhere!
// 3x3 representation
// orthosymplectic 4-vectors treating this as a 4-rotation:
HepLorentzVector col1() const;
HepLorentzVector col2() const;
HepLorentzVector col3() const;
HepLorentzVector col4() const;
HepLorentzVector row1() const;
HepLorentzVector row2() const;
HepLorentzVector row3() const;
HepLorentzVector row4() const;
// individual elements treating this as a 4-rotation:
double xt() const;
double yt() const;
double zt() const;
double tx() const;
double ty() const;
double tz() const;
double tt() const;
// ---------- Operations in the Rotation group
HepRotation operator * ( const Hep3RotationInterface & r ) const ;
// ---------- Application
HepLorentzVector operator* ( const HepLorentzVector & w ) const ;
HepLorentzVector operator()( const HepLorentzVector & w ) const ;
// apply to HepLorentzVector
Hep3Vector operator* ( const Hep3Vector & v ) const ;
Hep3Vector operator()( const Hep3Vector & v ) const ;
// apply to Hep3Vector
// ---------- I/O and a helper method
std::ostream & print( std::ostream & os ) const;
#endif /* ONLY_IN_CONCRETE_CLASSES */
private:
~Hep3RotationInterface() {} // private destructor to forbid instatiation
}; // Hep3RotationInterface
//-***************************
// 3x3 and 4x4 representations
//-***************************
struct HepRep3x3 {
// ----- Constructors:
inline HepRep3x3();
inline HepRep3x3( double xx, double xy, double xz
, double yx, double yy, double yz
, double zx, double zy, double zz
);
inline HepRep3x3( const double * array );
// construct from an array of doubles, holding the rotation matrix
// in ROW order (xx, xy, ...)
inline void setToIdentity();
// ----- The data members are public:
double xx_, xy_, xz_,
yx_, yy_, yz_,
zx_, zy_, zz_;
inline void getArray ( double * array ) const;
// fill array with the NINE doubles xx, xy, xz ... zz
}; // HepRep3x3
struct HepRep4x4 {
// ----- Constructors:
inline HepRep4x4();
inline HepRep4x4( double xx, double xy, double xz, double xt
, double yx, double yy, double yz, double yt
, double zx, double zy, double zz, double zt
, double tx, double ty, double tz, double tt
);
inline HepRep4x4( const HepRep4x4Symmetric & rep );
inline HepRep4x4( const double * array );
// construct from an array of doubles, holding the transformation matrix
// in ROW order xx, xy, ...
inline void setToIdentity();
// ----- The data members are public:
double xx_, xy_, xz_, xt_,
yx_, yy_, yz_, yt_,
zx_, zy_, zz_, zt_,
tx_, ty_, tz_, tt_;
inline void getArray ( double * array ) const;
// fill array with the SIXTEEN doubles xx, xy, xz ... tz, tt
inline bool operator==(HepRep4x4 const & r) const;
inline bool operator!=(HepRep4x4 const & r) const;
}; // HepRep4x4
struct HepRep4x4Symmetric {
// ----- Constructors:
inline HepRep4x4Symmetric();
inline HepRep4x4Symmetric
( double xx, double xy, double xz, double xt
, double yy, double yz, double yt
, double zz, double zt
, double tt );
inline HepRep4x4Symmetric( const double * array );
// construct from an array of doubles, holding the transformation matrix
// elements in this order: xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
inline void setToIdentity();
// ----- The data members are public:
double xx_, xy_, xz_, xt_,
yy_, yz_, yt_,
zz_, zt_,
tt_;
inline void getArray ( double * array ) const;
// fill array with the TEN doubles xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
};
} // namespace CLHEP
#include "CLHEP/Vector/RotationInterfaces.icc"
#endif // ROTATION_INTERFACES_H
@@ -0,0 +1,153 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This contains the definitions of the inline member functions of the
// Hep4RotationInterface and Hep3RotationInterface classes, and of the
// HepRep3x3 and HepRep4x4 structs.
//
namespace CLHEP {
//-*********
// HepRep3x3
//-*********
inline HepRep3x3::HepRep3x3() :
xx_(1.0), xy_(0.0), xz_(0.0)
, yx_(0.0), yy_(1.0), yz_(0.0)
, zx_(0.0), zy_(0.0), zz_(1.0)
{}
inline HepRep3x3::HepRep3x3( double xx, double xy, double xz
, double yx, double yy, double yz
, double zx, double zy, double zz
) :
xx_(xx), xy_(xy), xz_(xz)
, yx_(yx), yy_(yy), yz_(yz)
, zx_(zx), zy_(zy), zz_(zz)
{}
inline HepRep3x3::HepRep3x3( const double * array ) {
const double * a = array;
double * r = &xx_;
for ( int i = 0; i < 9; i++ ) { *r++ = *a++; }
}
inline void HepRep3x3::setToIdentity() {
xx_ = 1.0; xy_ = 0.0; xz_ = 0.0;
yx_ = 0.0; yy_ = 1.0; yz_ = 0.0;
zx_ = 0.0; zy_ = 0.0; zz_ = 1.0;
}
inline void HepRep3x3::getArray( double * array ) const {
double * a = array;
const double * r = &xx_;
for ( int i = 0; i < 9; i++ ) { *a++ = *r++; }
}
//-*********
// HepRep4x4
//-*********
inline HepRep4x4::HepRep4x4() :
xx_(1.0), xy_(0.0), xz_(0.0), xt_(0.0)
, yx_(0.0), yy_(1.0), yz_(0.0), yt_(0.0)
, zx_(0.0), zy_(0.0), zz_(1.0), zt_(0.0)
, tx_(0.0), ty_(0.0), tz_(0.0), tt_(1.0)
{}
inline HepRep4x4::HepRep4x4(
double xx, double xy, double xz, double xt
, double yx, double yy, double yz, double yt
, double zx, double zy, double zz, double zt
, double tx, double ty, double tz, double tt
) :
xx_(xx), xy_(xy), xz_(xz), xt_(xt)
, yx_(yx), yy_(yy), yz_(yz), yt_(yt)
, zx_(zx), zy_(zy), zz_(zz), zt_(zt)
, tx_(tx), ty_(ty), tz_(tz), tt_(tt)
{}
inline HepRep4x4::HepRep4x4( const HepRep4x4Symmetric & rep ) :
xx_(rep.xx_), xy_(rep.xy_), xz_(rep.xz_), xt_(rep.xt_)
, yx_(rep.xy_), yy_(rep.yy_), yz_(rep.yz_), yt_(rep.yt_)
, zx_(rep.xz_), zy_(rep.yz_), zz_(rep.zz_), zt_(rep.zt_)
, tx_(rep.xt_), ty_(rep.yt_), tz_(rep.zt_), tt_(rep.tt_)
{}
inline HepRep4x4::HepRep4x4( const double * array ) {
const double * a = array;
double * r = &xx_;
for ( int i = 0; i < 16; i++ ) { *r++ = *a++; }
}
inline void HepRep4x4::setToIdentity() {
xx_ = 1.0; xy_ = 0.0; xz_ = 0.0; xt_ = 0.0;
yx_ = 0.0; yy_ = 1.0; yz_ = 0.0; yt_ = 0.0;
zx_ = 0.0; zy_ = 0.0; zz_ = 1.0; zt_ = 0.0;
tx_ = 0.0; ty_ = 0.0; tz_ = 0.0; tt_ = 1.0;
}
inline void HepRep4x4::getArray( double * array ) const {
double * a = array;
const double * r = &xx_;
for ( int i = 0; i < 16; i++ ) { *a++ = *r++; }
}
inline bool HepRep4x4::operator == (const HepRep4x4 & r) const {
return( xx_ == r.xx_ && xy_ == r.xy_ && xz_ == r.xz_ && xt_ == r.xt_ &&
yx_ == r.yx_ && yy_ == r.yy_ && yz_ == r.yz_ && yt_ == r.yt_ &&
zx_ == r.zx_ && zy_ == r.zy_ && zz_ == r.zz_ && zt_ == r.zt_ &&
tx_ == r.tx_ && ty_ == r.ty_ && tz_ == r.tz_ && tt_ == r.tt_ );
}
inline bool HepRep4x4::operator != (const HepRep4x4 & r) const {
return !(operator== (r));
}
//-******************
// HepRep4x4Symmetric
//-******************
inline HepRep4x4Symmetric::HepRep4x4Symmetric() :
xx_(1.0), xy_(0.0), xz_(0.0), xt_(0.0)
, yy_(1.0), yz_(0.0), yt_(0.0)
, zz_(1.0), zt_(0.0)
, tt_(1.0)
{}
inline HepRep4x4Symmetric::HepRep4x4Symmetric
( double xx, double xy, double xz, double xt
, double yy, double yz, double yt
, double zz, double zt
, double tt ) :
xx_(xx), xy_(xy), xz_(xz), xt_(xt)
, yy_(yy), yz_(yz), yt_(yt)
, zz_(zz), zt_(zt)
, tt_(tt)
{}
inline HepRep4x4Symmetric::HepRep4x4Symmetric( const double * array ) {
const double * a = array;
double * r = &xx_;
for ( int i = 0; i < 10; i++ ) { *r++ = *a++; }
}
inline void HepRep4x4Symmetric::setToIdentity() {
xx_ = 1.0; xy_ = 0.0; xz_ = 0.0; xt_ = 0.0;
yy_ = 1.0; yz_ = 0.0; yt_ = 0.0;
zz_ = 1.0; zt_ = 0.0;
tt_ = 1.0;
}
inline void HepRep4x4Symmetric::getArray( double * array ) const {
double * a = array;
const double * r = &xx_;
for ( int i = 0; i < 10; i++ ) { *a++ = *r++; }
}
} // namespace CLHEP
+284
View File
@@ -0,0 +1,284 @@
// -*- C++ -*-
// CLASSDOC OFF
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepRotationX class for performing rotations
// around the X axis on objects of the Hep3Vector (and HepLorentzVector) class.
//
// HepRotationX is a concrete implementation of Hep3RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h, LorentzRotation.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_ROTATIONX_H
#define HEP_ROTATIONX_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
namespace CLHEP {
class HepRotationX;
class HepRotation;
class HepBoost;
inline HepRotationX inverseOf(const HepRotationX & r);
// Returns the inverse of a RotationX.
/**
* @author
* @ingroup vector
*/
class HepRotationX {
public:
// ---------- Constructors and Assignment:
inline HepRotationX();
// Default constructor. Gives an identity rotation.
HepRotationX(double delta);
// supply angle of rotation
inline HepRotationX(const HepRotationX & orig);
// Copy constructor.
inline HepRotationX & operator = (const HepRotationX & r);
// Assignment from a Rotation, which must be RotationX
HepRotationX & set ( double delta );
// set angle of rotation
inline ~HepRotationX();
// Trivial destructor.
// ---------- Accessors:
inline Hep3Vector colX() const;
inline Hep3Vector colY() const;
inline Hep3Vector colZ() const;
// orthogonal unit-length column vectors
inline Hep3Vector rowX() const;
inline Hep3Vector rowY() const;
inline Hep3Vector rowZ() const;
// orthogonal unit-length row vectors
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
// Elements of the rotation matrix (Geant4).
inline HepRep3x3 rep3x3() const;
// 3x3 representation:
// ------------ Euler angles:
inline double getPhi () const;
inline double getTheta() const;
inline double getPsi () const;
double phi () const;
double theta() const;
double psi () const;
HepEulerAngles eulerAngles() const;
// ------------ axis & angle of rotation:
inline double getDelta() const;
inline Hep3Vector getAxis () const;
inline double delta() const;
inline Hep3Vector axis () const;
inline HepAxisAngle axisAngle() const;
inline void getAngleAxis(double & delta, Hep3Vector & axis) const;
// Returns the rotation angle and rotation axis (Geant4).
// ------------- Angles of rotated axes
double phiX() const;
double phiY() const;
double phiZ() const;
double thetaX() const;
double thetaY() const;
double thetaZ() const;
// Return angles (RADS) made by rotated axes against original axes (Geant4).
// ---------- Other accessors treating pure rotation as a 4-rotation
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
// orthosymplectic 4-vector columns - T component will be zero
inline HepLorentzVector col4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
// orthosymplectic 4-vector rows - T component will be zero
inline HepLorentzVector row4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline double xt() const;
inline double yt() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
// Will be zero for this pure Rotation
inline double tt() const;
// Will be one for this pure Rotation
inline HepRep4x4 rep4x4() const;
// 4x4 representation.
// --------- Mutators
void setDelta (double delta);
// change angle of rotation, leaving rotation axis unchanged.
// ---------- Decomposition:
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepBoost & boost, HepRotation & rotation) const;
// These are trivial, as the boost vector is 0.
// ---------- Comparisons:
inline bool isIdentity() const;
// Returns true if the identity matrix (Geant4).
inline int compare( const HepRotationX & r ) const;
// Dictionary-order comparison, in order of delta
// Used in operator<, >, <=, >=
inline bool operator== ( const HepRotationX & r ) const;
inline bool operator!= ( const HepRotationX & r ) const;
inline bool operator< ( const HepRotationX & r ) const;
inline bool operator> ( const HepRotationX & r ) const;
inline bool operator<= ( const HepRotationX & r ) const;
inline bool operator>= ( const HepRotationX & r ) const;
double distance2( const HepRotationX & r ) const;
// 3 - Tr ( this/r )
double distance2( const HepRotation & r ) const;
// 3 - Tr ( this/r ) -- This works with RotationY or Z also
double howNear( const HepRotationX & r ) const;
double howNear( const HepRotation & r ) const;
bool isNear( const HepRotationX & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
double distance2( const HepBoost & lt ) const;
// 3 - Tr ( this ) + |b|^2 / (1-|b|^2)
double distance2( const HepLorentzRotation & lt ) const;
// 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
double howNear( const HepBoost & lt ) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear( const HepBoost & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// distance2 (IDENTITY), which is 3 - Tr ( *this )
inline void rectify();
// non-const but logically moot correction for accumulated roundoff errors
// ---------- Application:
inline Hep3Vector operator() (const Hep3Vector & p) const;
// Rotate a Hep3Vector.
inline Hep3Vector operator * (const Hep3Vector & p) const;
// Multiplication with a Hep3Vector.
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Rotate (the space part of) a HepLorentzVector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a HepLorentzVector.
// ---------- Operations in the group of Rotations
inline HepRotationX operator * (const HepRotationX & rx) const;
// Product of two X rotations: (this) * rx is known to be RotationX.
inline HepRotationX & operator *= (const HepRotationX & r);
inline HepRotationX & transform (const HepRotationX & r);
// Matrix multiplication.
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
// However, in this special case, they commute: Both just add deltas.
inline HepRotationX inverse() const;
// Returns the inverse.
friend HepRotationX inverseOf(const HepRotationX & r);
// Returns the inverse of a RotationX.
inline HepRotationX & invert();
// Inverts the Rotation matrix (be negating delta).
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output, identifying type of rotation and delta.
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
double d;
// The angle of rotation.
double s;
double c;
// Cache the trig functions, for rapid operations.
inline HepRotationX ( double dd, double ss, double cc );
// Unchecked load-the-data-members
static inline double proper (double delta);
// Put an angle into the range of (-PI, PI]. Useful helper method.
}; // HepRotationX
// ---------- Free-function operations in the group of Rotations
inline
std::ostream & operator <<
( std::ostream & os, const HepRotationX & r ) {return r.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/RotationX.icc"
#endif /* HEP_ROTATIONX_H */
@@ -0,0 +1,208 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepRotationX class
//
#include <cmath>
#include "CLHEP/Units/PhysicalConstants.h"
namespace CLHEP {
inline double HepRotationX::yy() const { return c; }
inline double HepRotationX::yz() const { return -s; }
inline double HepRotationX::zy() const { return s; }
inline double HepRotationX::zz() const { return c; }
inline double HepRotationX::xx() const { return 1.0; }
inline double HepRotationX::xy() const { return 0.0; }
inline double HepRotationX::xz() const { return 0.0; }
inline double HepRotationX::yx() const { return 0.0; }
inline double HepRotationX::zx() const { return 0.0; }
inline HepRep3x3 HepRotationX::rep3x3() const {
return HepRep3x3 ( 1.0, 0.0, 0.0,
0.0, c, -s,
0.0, s, c );
}
inline HepRotationX::HepRotationX() : d(0.0), s(0.0), c(1.0) {}
inline HepRotationX::HepRotationX(const HepRotationX & orig) :
d(orig.d), s(orig.s), c(orig.c)
{}
inline HepRotationX::HepRotationX(double dd, double ss, double cc) :
d(dd), s(ss), c(cc)
{}
inline HepRotationX & HepRotationX::operator= (const HepRotationX & orig) {
d = orig.d;
s = orig.s;
c = orig.c;
return *this;
}
inline HepRotationX::~HepRotationX() {}
inline Hep3Vector HepRotationX::colX() const
{ return Hep3Vector ( 1.0, 0.0, 0.0 ); }
inline Hep3Vector HepRotationX::colY() const
{ return Hep3Vector ( 0.0, c, s ); }
inline Hep3Vector HepRotationX::colZ() const
{ return Hep3Vector ( 0.0, -s, c ); }
inline Hep3Vector HepRotationX::rowX() const
{ return Hep3Vector ( 1.0, 0.0, 0.0 ); }
inline Hep3Vector HepRotationX::rowY() const
{ return Hep3Vector ( 0.0, c, -s ); }
inline Hep3Vector HepRotationX::rowZ() const
{ return Hep3Vector ( 0.0, s, c ); }
inline double HepRotationX::getPhi () const { return phi(); }
inline double HepRotationX::getTheta() const { return theta(); }
inline double HepRotationX::getPsi () const { return psi(); }
inline double HepRotationX::getDelta() const { return d; }
inline Hep3Vector HepRotationX::getAxis () const { return axis(); }
inline double HepRotationX::delta() const { return d; }
inline Hep3Vector HepRotationX::axis() const { return Hep3Vector(1,0,0); }
inline HepAxisAngle HepRotationX::axisAngle() const {
return HepAxisAngle ( axis(), delta() );
}
inline void HepRotationX::getAngleAxis
(double & delta, Hep3Vector & axis) const {
delta = d;
axis = getAxis();
}
inline HepLorentzVector HepRotationX::col1() const
{ return HepLorentzVector (colX(), 0); }
inline HepLorentzVector HepRotationX::col2() const
{ return HepLorentzVector (colY(), 0); }
inline HepLorentzVector HepRotationX::col3() const
{ return HepLorentzVector (colZ(), 0); }
inline HepLorentzVector HepRotationX::col4() const
{ return HepLorentzVector (0,0,0,1); }
inline HepLorentzVector HepRotationX::row1() const
{ return HepLorentzVector (rowX(), 0); }
inline HepLorentzVector HepRotationX::row2() const
{ return HepLorentzVector (rowY(), 0); }
inline HepLorentzVector HepRotationX::row3() const
{ return HepLorentzVector (rowZ(), 0); }
inline HepLorentzVector HepRotationX::row4() const
{ return HepLorentzVector (0,0,0,1); }
inline double HepRotationX::xt() const { return 0.0; }
inline double HepRotationX::yt() const { return 0.0; }
inline double HepRotationX::zt() const { return 0.0; }
inline double HepRotationX::tx() const { return 0.0; }
inline double HepRotationX::ty() const { return 0.0; }
inline double HepRotationX::tz() const { return 0.0; }
inline double HepRotationX::tt() const { return 1.0; }
inline HepRep4x4 HepRotationX::rep4x4() const {
return HepRep4x4 ( 1.0, 0.0, 0.0, 0.0,
0.0, c, -s, 0.0,
0.0, s, c, 0.0,
0.0, 0.0, 0.0, 1.0 );
}
inline bool HepRotationX::isIdentity() const {
return ( d==0 );
}
inline int HepRotationX::compare ( const HepRotationX & r ) const {
if (d > r.d) return 1; else if (d < r.d) return -1; else return 0;
}
inline bool HepRotationX::operator==(const HepRotationX & r) const
{ return (d==r.d); }
inline bool HepRotationX::operator!=(const HepRotationX & r) const
{ return (d!=r.d); }
inline bool HepRotationX::operator>=(const HepRotationX & r) const
{ return (d>=r.d); }
inline bool HepRotationX::operator<=(const HepRotationX & r) const
{ return (d<=r.d); }
inline bool HepRotationX::operator> (const HepRotationX & r) const
{ return (d> r.d); }
inline bool HepRotationX::operator< (const HepRotationX & r) const
{ return (d< r.d); }
inline void HepRotationX::rectify() {
d = proper(d); // Just in case!
s = std::sin(d);
c = std::cos(d);
}
inline Hep3Vector HepRotationX::operator() (const Hep3Vector & p) const {
double x = p.x();
double y = p.y();
double z = p.z();
return Hep3Vector( x,
y * c - z * s,
z * c + y * s );
}
inline Hep3Vector HepRotationX::operator * (const Hep3Vector & p) const {
return operator()(p);
}
inline HepLorentzVector HepRotationX::operator()
( const HepLorentzVector & w ) const {
return HepLorentzVector( operator() (w.vect()) , w.t() );
}
inline HepLorentzVector HepRotationX::operator *
(const HepLorentzVector & p) const {
return operator()(p);
}
inline HepRotationX & HepRotationX::operator *= (const HepRotationX & m) {
return *this = (*this) * (m);
}
inline HepRotationX & HepRotationX::transform(const HepRotationX & m) {
return *this = m * (*this);
}
inline double HepRotationX::proper( double delta ) {
// -PI < d <= PI
if ( std::fabs(delta) < CLHEP::pi ) {
return delta;
} else {
register double x = delta / (CLHEP::twopi);
return (CLHEP::twopi) * ( x + std::floor(.5-x) );
}
} // proper()
inline HepRotationX HepRotationX::operator * ( const HepRotationX & rx ) const {
return HepRotationX ( HepRotationX::proper(d+rx.d),
s*rx.c + c*rx.s,
c*rx.c - s*rx.s );
}
inline HepRotationX HepRotationX::inverse() const {
return HepRotationX( proper(-d), -s, c );
}
inline HepRotationX inverseOf(const HepRotationX & r) {
return r.inverse();
}
inline HepRotationX & HepRotationX::invert() {
return *this=inverse();
}
inline double HepRotationX::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepRotationX::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
+285
View File
@@ -0,0 +1,285 @@
// -*- C++ -*-
// CLASSDOC OFF
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepRotationY class for performing rotations
// around the X axis on objects of the Hep3Vector (and HepLorentzVector) class.
//
// HepRotationY is a concrete implementation of Hep3RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h, LorentzRotation.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_ROTATIONY_H
#define HEP_ROTATIONY_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
namespace CLHEP {
class HepRotationY;
class HepRotation;
class HepBoost;
inline HepRotationY inverseOf(const HepRotationY & r);
// Returns the inverse of a RotationY.
/**
* @author
* @ingroup vector
*/
class HepRotationY {
public:
// ---------- Constructors and Assignment:
inline HepRotationY();
// Default constructor. Gives an identity rotation.
HepRotationY(double delta);
// supply angle of rotation
inline HepRotationY(const HepRotationY & orig);
// Copy constructor.
inline HepRotationY & operator = (const HepRotationY & r);
// Assignment from a Rotation, which must be RotationY
HepRotationY & set ( double delta );
// set angle of rotation
inline ~HepRotationY();
// Trivial destructor.
// ---------- Accessors:
inline Hep3Vector colX() const;
inline Hep3Vector colY() const;
inline Hep3Vector colZ() const;
// orthogonal unit-length column vectors
inline Hep3Vector rowX() const;
inline Hep3Vector rowY() const;
inline Hep3Vector rowZ() const;
// orthogonal unit-length row vectors
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
// Elements of the rotation matrix (Geant4).
inline HepRep3x3 rep3x3() const;
// 3x3 representation:
// ------------ Euler angles:
inline double getPhi () const;
inline double getTheta() const;
inline double getPsi () const;
double phi () const;
double theta() const;
double psi () const;
HepEulerAngles eulerAngles() const;
// ------------ axis & angle of rotation:
inline double getDelta() const;
inline Hep3Vector getAxis () const;
inline double delta() const;
inline Hep3Vector axis () const;
inline HepAxisAngle axisAngle() const;
inline void getAngleAxis(double & delta, Hep3Vector & axis) const;
// Returns the rotation angle and rotation axis (Geant4).
// ------------- Angles of rotated axes
double phiX() const;
double phiY() const;
double phiZ() const;
double thetaX() const;
double thetaY() const;
double thetaZ() const;
// Return angles (RADS) made by rotated axes against original axes (Geant4).
// ---------- Other accessors treating pure rotation as a 4-rotation
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
// orthosymplectic 4-vector columns - T component will be zero
inline HepLorentzVector col4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
// orthosymplectic 4-vector rows - T component will be zero
inline HepLorentzVector row4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline double xt() const;
inline double yt() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
// Will be zero for this pure Rotation
inline double tt() const;
// Will be one for this pure Rotation
inline HepRep4x4 rep4x4() const;
// 4x4 representation.
// --------- Mutators
void setDelta (double delta);
// change angle of rotation, leaving rotation axis unchanged.
// ---------- Decomposition:
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepBoost & boost, HepRotation & rotation) const;
// These are trivial, as the boost vector is 0.
// ---------- Comparisons:
inline bool isIdentity() const;
// Returns true if the identity matrix (Geant4).
inline int compare( const HepRotationY & r ) const;
// Dictionary-order comparison, in order of delta
// Used in operator<, >, <=, >=
inline bool operator== ( const HepRotationY & r ) const;
inline bool operator!= ( const HepRotationY & r ) const;
inline bool operator< ( const HepRotationY & r ) const;
inline bool operator> ( const HepRotationY & r ) const;
inline bool operator<= ( const HepRotationY & r ) const;
inline bool operator>= ( const HepRotationY & r ) const;
double distance2( const HepRotationY & r ) const;
// 3 - Tr ( this/r )
double distance2( const HepRotation & r ) const;
// 3 - Tr ( this/r ) -- This works with RotationY or Z also
double howNear( const HepRotationY & r ) const;
double howNear( const HepRotation & r ) const;
bool isNear( const HepRotationY & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
double distance2( const HepBoost & lt ) const;
// 3 - Tr ( this ) + |b|^2 / (1-|b|^2)
double distance2( const HepLorentzRotation & lt ) const;
// 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
double howNear( const HepBoost & lt ) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear( const HepBoost & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// distance2 (IDENTITY), which is 3 - Tr ( *this )
inline void rectify();
// non-const but logically moot correction for accumulated roundoff errors
// ---------- Application:
inline Hep3Vector operator() (const Hep3Vector & p) const;
// Rotate a Hep3Vector.
inline Hep3Vector operator * (const Hep3Vector & p) const;
// Multiplication with a Hep3Vector.
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Rotate (the space part of) a HepLorentzVector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a HepLorentzVector.
// ---------- Operations in the group of Rotations
inline HepRotationY operator * (const HepRotationY & ry) const;
// Product of two Y rotations (this) * ry is known to be RotationY.
inline HepRotationY & operator *= (const HepRotationY & r);
inline HepRotationY & transform (const HepRotationY & r);
// Matrix multiplication.
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
// However, in this special case, they commute: Both just add deltas.
inline HepRotationY inverse() const;
// Returns the inverse.
friend HepRotationY inverseOf(const HepRotationY & r);
// Returns the inverse of a RotationY.
inline HepRotationY & invert();
// Inverts the Rotation matrix (be negating delta).
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output, identifying type of rotation and delta.
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
double d;
// The angle of rotation.
double s;
double c;
// Cache the trig functions, for rapid operations.
inline HepRotationY ( double dd, double ss, double cc );
// Unchecked load-the-data-members
static inline double proper (double delta);
// Put an angle into the range of (-PI, PI]. Useful helper method.
}; // HepRotationY
// ---------- Free-function operations in the group of Rotations
inline
std::ostream & operator <<
( std::ostream & os, const HepRotationY & r ) {return r.print(os);}
} // namespace CLHEP
#include "CLHEP/Vector/RotationY.icc"
#endif /* HEP_ROTATIONY_H */
@@ -0,0 +1,209 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepRotationY class
//
#include <cmath>
#include "CLHEP/Units/PhysicalConstants.h"
namespace CLHEP {
inline double HepRotationY::xx() const { return c; }
inline double HepRotationY::xz() const { return s; }
inline double HepRotationY::zx() const { return -s; }
inline double HepRotationY::zz() const { return c; }
inline double HepRotationY::yy() const { return 1.0; }
inline double HepRotationY::yx() const { return 0.0; }
inline double HepRotationY::yz() const { return 0.0; }
inline double HepRotationY::xy() const { return 0.0; }
inline double HepRotationY::zy() const { return 0.0; }
inline HepRep3x3 HepRotationY::rep3x3() const {
return HepRep3x3 ( c , 0.0, s,
0.0, 1.0, 0.0,
-s , 0.0, c );
}
inline HepRotationY::HepRotationY() : d(0.0), s(0.0), c(1.0) {}
inline HepRotationY::HepRotationY(const HepRotationY & orig) :
d(orig.d), s(orig.s), c(orig.c)
{}
inline HepRotationY::HepRotationY(double dd, double ss, double cc) :
d(dd), s(ss), c(cc)
{}
inline HepRotationY & HepRotationY::operator= (const HepRotationY & orig) {
d = orig.d;
s = orig.s;
c = orig.c;
return *this;
}
inline HepRotationY::~HepRotationY() {}
inline Hep3Vector HepRotationY::colX() const
{ return Hep3Vector ( c, 0.0, -s ); }
inline Hep3Vector HepRotationY::colY() const
{ return Hep3Vector ( 0.0, 1.0, 0.0 ); }
inline Hep3Vector HepRotationY::colZ() const
{ return Hep3Vector ( s, 0.0, c ); }
inline Hep3Vector HepRotationY::rowX() const
{ return Hep3Vector ( c, 0.0, s ); }
inline Hep3Vector HepRotationY::rowY() const
{ return Hep3Vector ( 0.0, 1.0, 0.0 ); }
inline Hep3Vector HepRotationY::rowZ() const
{ return Hep3Vector ( -s, 0.0, c ); }
inline double HepRotationY::getPhi () const { return phi(); }
inline double HepRotationY::getTheta() const { return theta(); }
inline double HepRotationY::getPsi () const { return psi(); }
inline double HepRotationY::getDelta() const { return d; }
inline Hep3Vector HepRotationY::getAxis () const { return axis(); }
inline double HepRotationY::delta() const { return d; }
inline Hep3Vector HepRotationY::axis() const { return Hep3Vector(0,1,0); }
inline HepAxisAngle HepRotationY::axisAngle() const {
return HepAxisAngle ( axis(), delta() );
}
inline void HepRotationY::getAngleAxis
(double & delta, Hep3Vector & axis) const {
delta = d;
axis = getAxis();
}
inline bool HepRotationY::isIdentity() const {
return ( d==0 );
}
inline int HepRotationY::compare ( const HepRotationY & r ) const {
if (d > r.d) return 1; else if (d < r.d) return -1; else return 0;
}
inline bool HepRotationY::operator==(const HepRotationY & r) const
{ return (d==r.d); }
inline bool HepRotationY::operator!=(const HepRotationY & r) const
{ return (d!=r.d); }
inline bool HepRotationY::operator>=(const HepRotationY & r) const
{ return (d>=r.d); }
inline bool HepRotationY::operator<=(const HepRotationY & r) const
{ return (d<=r.d); }
inline bool HepRotationY::operator> (const HepRotationY & r) const
{ return (d> r.d); }
inline bool HepRotationY::operator< (const HepRotationY & r) const
{ return (d< r.d); }
inline void HepRotationY::rectify() {
d = proper(d); // Just in case!
s = std::sin(d);
c = std::cos(d);
}
inline Hep3Vector HepRotationY::operator() (const Hep3Vector & p) const {
double x = p.x();
double y = p.y();
double z = p.z();
return Hep3Vector( x * c + z * s,
y,
z * c - x * s );
}
inline Hep3Vector HepRotationY::operator * (const Hep3Vector & p) const {
return operator()(p);
}
inline HepLorentzVector HepRotationY::operator()
( const HepLorentzVector & w ) const {
return HepLorentzVector( operator() (w.vect()) , w.t() );
}
inline HepLorentzVector HepRotationY::operator *
(const HepLorentzVector & p) const {
return operator()(p);
}
inline HepRotationY & HepRotationY::operator *= (const HepRotationY & m) {
return *this = (*this) * (m);
}
inline HepRotationY & HepRotationY::transform(const HepRotationY & m) {
return *this = m * (*this);
}
inline double HepRotationY::proper( double delta ) {
// -PI < d <= PI
if ( std::fabs(delta) < CLHEP::pi ) {
return delta;
} else {
register double x = delta / (CLHEP::twopi);
return (CLHEP::twopi) * ( x + std::floor(.5-x) );
}
} // proper()
inline HepRotationY HepRotationY::operator * ( const HepRotationY & ry ) const {
return HepRotationY ( HepRotationY::proper(d+ry.d),
s*ry.c + c*ry.s,
c*ry.c - s*ry.s );
}
inline HepRotationY HepRotationY::inverse() const {
return HepRotationY( proper(-d), -s, c );
}
inline HepRotationY inverseOf(const HepRotationY & r) {
return r.inverse();
}
inline HepRotationY & HepRotationY::invert() {
return *this=inverse();
}
inline HepLorentzVector HepRotationY::col1() const
{ return HepLorentzVector (colX(), 0); }
inline HepLorentzVector HepRotationY::col2() const
{ return HepLorentzVector (colY(), 0); }
inline HepLorentzVector HepRotationY::col3() const
{ return HepLorentzVector (colZ(), 0); }
inline HepLorentzVector HepRotationY::col4() const
{ return HepLorentzVector (0,0,0,1); }
inline HepLorentzVector HepRotationY::row1() const
{ return HepLorentzVector (rowX(), 0); }
inline HepLorentzVector HepRotationY::row2() const
{ return HepLorentzVector (rowY(), 0); }
inline HepLorentzVector HepRotationY::row3() const
{ return HepLorentzVector (rowZ(), 0); }
inline HepLorentzVector HepRotationY::row4() const
{ return HepLorentzVector (0,0,0,1); }
inline double HepRotationY::xt() const { return 0.0; }
inline double HepRotationY::yt() const { return 0.0; }
inline double HepRotationY::zt() const { return 0.0; }
inline double HepRotationY::tx() const { return 0.0; }
inline double HepRotationY::ty() const { return 0.0; }
inline double HepRotationY::tz() const { return 0.0; }
inline double HepRotationY::tt() const { return 1.0; }
inline HepRep4x4 HepRotationY::rep4x4() const {
return HepRep4x4 ( c , 0.0, s, 0.0,
0.0, 1.0, 0.0, 0.0,
-s , 0.0, c, 0.0,
0.0, 0.0, 0.0, 1.0 );
}
inline double HepRotationY::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepRotationY::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
+287
View File
@@ -0,0 +1,287 @@
// -*- C++ -*-
// CLASSDOC OFF
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definition of the HepRotationZ class for performing rotations
// around the X axis on objects of the Hep3Vector (and HepLorentzVector) class.
//
// HepRotationZ is a concrete implementation of Hep3RotationInterface.
//
// .SS See Also
// RotationInterfaces.h
// ThreeVector.h, LorentzVector.h, LorentzRotation.h
//
// .SS Author
// Mark Fischler
#ifndef HEP_ROTATIONZ_H
#define HEP_ROTATIONZ_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include "CLHEP/Vector/RotationInterfaces.h"
namespace CLHEP {
class HepRotationZ;
class HepRotation;
class HepBoost;
inline HepRotationZ inverseOf(const HepRotationZ & r);
// Returns the inverse of a RotationZ.
/**
* @author
* @ingroup vector
*/
class HepRotationZ {
public:
// ---------- Constructors and Assignment:
inline HepRotationZ();
// Default constructor. Gives an identity rotation.
HepRotationZ(double delta);
// supply angle of rotation
inline HepRotationZ(const HepRotationZ & orig);
// Copy constructor.
inline HepRotationZ & operator = (const HepRotationZ & r);
// Assignment from a Rotation, which must be RotationZ
HepRotationZ & set ( double delta );
// set angle of rotation
inline ~HepRotationZ();
// Trivial destructor.
// ---------- Accessors:
inline Hep3Vector colX() const;
inline Hep3Vector colY() const;
inline Hep3Vector colZ() const;
// orthogonal unit-length column vectors
inline Hep3Vector rowX() const;
inline Hep3Vector rowY() const;
inline Hep3Vector rowZ() const;
// orthogonal unit-length row vectors
inline double xx() const;
inline double xy() const;
inline double xz() const;
inline double yx() const;
inline double yy() const;
inline double yz() const;
inline double zx() const;
inline double zy() const;
inline double zz() const;
// Elements of the rotation matrix (Geant4).
inline HepRep3x3 rep3x3() const;
// 3x3 representation:
// ------------ Euler angles:
inline double getPhi () const;
inline double getTheta() const;
inline double getPsi () const;
double phi () const;
double theta() const;
double psi () const;
HepEulerAngles eulerAngles() const;
// ------------ axis & angle of rotation:
inline double getDelta() const;
inline Hep3Vector getAxis () const;
inline double delta() const;
inline Hep3Vector axis () const;
inline HepAxisAngle axisAngle() const;
inline void getAngleAxis(double & delta, Hep3Vector & axis) const;
// Returns the rotation angle and rotation axis (Geant4).
// ------------- Angles of rotated axes
double phiX() const;
double phiY() const;
double phiZ() const;
double thetaX() const;
double thetaY() const;
double thetaZ() const;
// Return angles (RADS) made by rotated axes against original axes (Geant4).
// ---------- Other accessors treating pure rotation as a 4-rotation
inline HepLorentzVector col1() const;
inline HepLorentzVector col2() const;
inline HepLorentzVector col3() const;
// orthosymplectic 4-vector columns - T component will be zero
inline HepLorentzVector col4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline HepLorentzVector row1() const;
inline HepLorentzVector row2() const;
inline HepLorentzVector row3() const;
// orthosymplectic 4-vector rows - T component will be zero
inline HepLorentzVector row4() const;
// Will be (0,0,0,1) for this pure Rotation.
inline double xt() const;
inline double yt() const;
inline double zt() const;
inline double tx() const;
inline double ty() const;
inline double tz() const;
// Will be zero for this pure Rotation
inline double tt() const;
// Will be one for this pure Rotation
inline HepRep4x4 rep4x4() const;
// 4x4 representation.
// --------- Mutators
void setDelta (double delta);
// change angle of rotation, leaving rotation axis unchanged.
// ---------- Decomposition:
void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
void decompose (HepRotation & rotation, HepBoost & boost) const;
void decompose (HepBoost & boost, HepRotation & rotation) const;
// These are trivial, as the boost vector is 0.
// ---------- Comparisons:
inline bool isIdentity() const;
// Returns true if the identity matrix (Geant4).
inline int compare( const HepRotationZ & r ) const;
// Dictionary-order comparison, in order of delta
// Used in operator<, >, <=, >=
inline bool operator== ( const HepRotationZ & r ) const;
inline bool operator!= ( const HepRotationZ & r ) const;
inline bool operator< ( const HepRotationZ & r ) const;
inline bool operator> ( const HepRotationZ & r ) const;
inline bool operator<= ( const HepRotationZ & r ) const;
inline bool operator>= ( const HepRotationZ & r ) const;
double distance2( const HepRotationZ & r ) const;
// 3 - Tr ( this/r )
double distance2( const HepRotation & r ) const;
// 3 - Tr ( this/r ) -- This works with RotationY or Z also
double howNear( const HepRotationZ & r ) const;
double howNear( const HepRotation & r ) const;
bool isNear( const HepRotationZ & r,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepRotation & r,
double epsilon=Hep4RotationInterface::tolerance) const;
double distance2( const HepBoost & lt ) const;
// 3 - Tr ( this ) + |b|^2 / (1-|b|^2)
double distance2( const HepLorentzRotation & lt ) const;
// 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
double howNear( const HepBoost & lt ) const;
double howNear( const HepLorentzRotation & lt ) const;
bool isNear( const HepBoost & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
bool isNear( const HepLorentzRotation & lt,
double epsilon=Hep4RotationInterface::tolerance) const;
// ---------- Properties:
double norm2() const;
// distance2 (IDENTITY), which is 3 - Tr ( *this )
inline void rectify();
// non-const but logically moot correction for accumulated roundoff errors
// ---------- Application:
inline Hep3Vector operator() (const Hep3Vector & p) const;
// Rotate a Hep3Vector.
inline Hep3Vector operator * (const Hep3Vector & p) const;
// Multiplication with a Hep3Vector.
inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
// Rotate (the space part of) a HepLorentzVector.
inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
// Multiplication with a HepLorentzVector.
// ---------- Operations in the group of Rotations
inline HepRotationZ operator * (const HepRotationZ & rz) const;
// Product of two Z rotations: (this) * rz is known to be RotationZ.
// Product of two rotations (this) * b - matrix multiplication
inline HepRotationZ & operator *= (const HepRotationZ & r);
inline HepRotationZ & transform (const HepRotationZ & r);
// Matrix multiplication.
// Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
// However, in this special case, they commute: Both just add deltas.
inline HepRotationZ inverse() const;
// Returns the inverse.
friend HepRotationZ inverseOf(const HepRotationZ & r);
// Returns the inverse of a RotationZ.
inline HepRotationZ & invert();
// Inverts the Rotation matrix (be negating delta).
// ---------- I/O:
std::ostream & print( std::ostream & os ) const;
// Output, identifying type of rotation and delta.
// ---------- Tolerance
static inline double getTolerance();
static inline double setTolerance(double tol);
protected:
double d;
// The angle of rotation.
double s;
double c;
// Cache the trig functions, for rapid operations.
inline HepRotationZ ( double dd, double ss, double cc );
// Unchecked load-the-data-members
static inline double proper (double delta);
// Put an angle into the range of (-PI, PI]. Useful helper method.
}; // HepRotationZ
inline
std::ostream & operator <<
( std::ostream & os, const HepRotationZ & r ) {return r.print(os);}
// ---------- Free-function operations in the group of Rotations
} // namespace CLHEP
#include "CLHEP/Vector/RotationZ.icc"
#endif /* HEP_ROTATIONZ_H */
@@ -0,0 +1,208 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// HepRotationZ class
//
#include <cmath>
#include "CLHEP/Units/PhysicalConstants.h"
namespace CLHEP {
inline double HepRotationZ::xx() const { return c; }
inline double HepRotationZ::xy() const { return -s; }
inline double HepRotationZ::yx() const { return s; }
inline double HepRotationZ::yy() const { return c; }
inline double HepRotationZ::zz() const { return 1.0; }
inline double HepRotationZ::zy() const { return 0.0; }
inline double HepRotationZ::zx() const { return 0.0; }
inline double HepRotationZ::yz() const { return 0.0; }
inline double HepRotationZ::xz() const { return 0.0; }
inline HepRep3x3 HepRotationZ::rep3x3() const {
return HepRep3x3 ( c, -s, 0.0,
s, c, 0.0,
0.0, 0.0, 1.0 );
}
inline HepRotationZ::HepRotationZ() : d(0.0), s(0.0), c(1.0) {}
inline HepRotationZ::HepRotationZ(const HepRotationZ & orig) :
d(orig.d), s(orig.s), c(orig.c)
{}
inline HepRotationZ::HepRotationZ(double dd, double ss, double cc) :
d(dd), s(ss), c(cc)
{}
inline HepRotationZ & HepRotationZ::operator= (const HepRotationZ & orig) {
d = orig.d;
s = orig.s;
c = orig.c;
return *this;
}
inline HepRotationZ::~HepRotationZ() {}
inline Hep3Vector HepRotationZ::colX() const
{ return Hep3Vector ( c, s, 0.0 ); }
inline Hep3Vector HepRotationZ::colY() const
{ return Hep3Vector ( -s, c, 0.0 ); }
inline Hep3Vector HepRotationZ::colZ() const
{ return Hep3Vector ( 0.0, 0.0, 1.0 ); }
inline Hep3Vector HepRotationZ::rowX() const
{ return Hep3Vector ( c, -s, 0.0 ); }
inline Hep3Vector HepRotationZ::rowY() const
{ return Hep3Vector ( s, c, 0.0 ); }
inline Hep3Vector HepRotationZ::rowZ() const
{ return Hep3Vector ( 0.0, 0.0, 1.0 ); }
inline double HepRotationZ::getPhi () const { return phi(); }
inline double HepRotationZ::getTheta() const { return theta(); }
inline double HepRotationZ::getPsi () const { return psi(); }
inline double HepRotationZ::getDelta() const { return d; }
inline Hep3Vector HepRotationZ::getAxis () const { return axis(); }
inline double HepRotationZ::delta() const { return d; }
inline Hep3Vector HepRotationZ::axis() const { return Hep3Vector(0,0,1); }
inline HepAxisAngle HepRotationZ::axisAngle() const {
return HepAxisAngle ( axis(), delta() );
}
inline void HepRotationZ::getAngleAxis
(double & delta, Hep3Vector & axis) const {
delta = d;
axis = getAxis();
}
inline bool HepRotationZ::isIdentity() const {
return ( d==0 );
}
inline int HepRotationZ::compare ( const HepRotationZ & r ) const {
if (d > r.d) return 1; else if (d < r.d) return -1; else return 0;
}
inline bool HepRotationZ::operator==(const HepRotationZ & r) const
{ return (d==r.d); }
inline bool HepRotationZ::operator!=(const HepRotationZ & r) const
{ return (d!=r.d); }
inline bool HepRotationZ::operator>=(const HepRotationZ & r) const
{ return (d>=r.d); }
inline bool HepRotationZ::operator<=(const HepRotationZ & r) const
{ return (d<=r.d); }
inline bool HepRotationZ::operator> (const HepRotationZ & r) const
{ return (d> r.d); }
inline bool HepRotationZ::operator< (const HepRotationZ & r) const
{ return (d< r.d); }
inline void HepRotationZ::rectify() {
d = proper(d); // Just in case!
s = std::sin(d);
c = std::cos(d);
}
inline Hep3Vector HepRotationZ::operator() (const Hep3Vector & p) const {
double x = p.x();
double y = p.y();
double z = p.z();
return Hep3Vector( x * c - y * s,
x * s + y * c,
z );
}
inline Hep3Vector HepRotationZ::operator * (const Hep3Vector & p) const {
return operator()(p);
}
inline HepLorentzVector HepRotationZ::operator()
( const HepLorentzVector & w ) const {
return HepLorentzVector( operator() (w.vect()) , w.t() );
}
inline HepLorentzVector HepRotationZ::operator *
(const HepLorentzVector & p) const {
return operator()(p);
}
inline HepRotationZ & HepRotationZ::operator *= (const HepRotationZ & m) {
return *this = (*this) * (m);
}
inline HepRotationZ & HepRotationZ::transform(const HepRotationZ & m) {
return *this = m * (*this);
}
inline double HepRotationZ::proper( double delta ) {
// -PI < d <= PI
if ( std::fabs(delta) < CLHEP::pi ) {
return delta;
} else {
register double x = delta / (CLHEP::twopi);
return (CLHEP::twopi) * ( x + std::floor(.5-x) );
}
} // proper()
inline HepRotationZ HepRotationZ::operator * ( const HepRotationZ & rz ) const {
return HepRotationZ ( HepRotationZ::proper(d+rz.d),
s*rz.c + c*rz.s,
c*rz.c - s*rz.s );
}
inline HepRotationZ HepRotationZ::inverse() const {
return HepRotationZ( proper(-d), -s, c );
}
inline HepRotationZ inverseOf(const HepRotationZ & r) {
return r.inverse();
}
inline HepRotationZ & HepRotationZ::invert() {
return *this=inverse();
}
inline HepLorentzVector HepRotationZ::col1() const
{ return HepLorentzVector (colX(), 0); }
inline HepLorentzVector HepRotationZ::col2() const
{ return HepLorentzVector (colY(), 0); }
inline HepLorentzVector HepRotationZ::col3() const
{ return HepLorentzVector (colZ(), 0); }
inline HepLorentzVector HepRotationZ::col4() const
{ return HepLorentzVector (0,0,0,1); }
inline HepLorentzVector HepRotationZ::row1() const
{ return HepLorentzVector (rowX(), 0); }
inline HepLorentzVector HepRotationZ::row2() const
{ return HepLorentzVector (rowY(), 0); }
inline HepLorentzVector HepRotationZ::row3() const
{ return HepLorentzVector (rowZ(), 0); }
inline HepLorentzVector HepRotationZ::row4() const
{ return HepLorentzVector (0,0,0,1); }
inline double HepRotationZ::xt() const { return 0.0; }
inline double HepRotationZ::yt() const { return 0.0; }
inline double HepRotationZ::zt() const { return 0.0; }
inline double HepRotationZ::tx() const { return 0.0; }
inline double HepRotationZ::ty() const { return 0.0; }
inline double HepRotationZ::tz() const { return 0.0; }
inline double HepRotationZ::tt() const { return 1.0; }
inline HepRep4x4 HepRotationZ::rep4x4() const {
return HepRep4x4 ( c, -s, 0.0, 0.0,
s, c, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
}
inline double HepRotationZ::getTolerance() {
return Hep4RotationInterface::tolerance;
}
inline double HepRotationZ::setTolerance(double tol) {
return Hep4RotationInterface::setTolerance(tol);
}
} // namespace CLHEP
@@ -0,0 +1,449 @@
// -*- C++ -*-
// CLASSDOC OFF
// $Id:$
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// Hep3Vector is a general 3-vector class defining vectors in three
// dimension using double components. Rotations of these vectors are
// performed by multiplying with an object of the HepRotation class.
//
// .SS See Also
// LorentzVector.h, Rotation.h, LorentzRotation.h
//
// .SS Authors
// Leif Lonnblad and Anders Nilsson; Modified by Evgueni Tcherniaev;
// ZOOM additions by Mark Fischler
//
#ifndef HEP_THREEVECTOR_H
#define HEP_THREEVECTOR_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include <iostream>
#include "CLHEP/Utility/defs.h"
namespace CLHEP {
class HepRotation;
class HepEulerAngles;
class HepAxisAngle;
/**
* @author
* @ingroup vector
*/
class Hep3Vector {
public:
// Basic properties and operations on 3-vectors:
enum { X=0, Y=1, Z=2, NUM_COORDINATES=3, SIZE=NUM_COORDINATES };
// Safe indexing of the coordinates when using with matrices, arrays, etc.
// (BaBar)
Hep3Vector();
explicit Hep3Vector(double x);
Hep3Vector(double x, double y);
Hep3Vector(double x, double y, double z);
// The constructor.
inline Hep3Vector(const Hep3Vector &);
// The copy constructor.
inline ~Hep3Vector();
// The destructor. Not virtual - inheritance from this class is dangerous.
double operator () (int) const;
// Get components by index -- 0-based (Geant4)
inline double operator [] (int) const;
// Get components by index -- 0-based (Geant4)
double & operator () (int);
// Set components by index. 0-based.
inline double & operator [] (int);
// Set components by index. 0-based.
inline double x() const;
inline double y() const;
inline double z() const;
// The components in cartesian coordinate system. Same as getX() etc.
inline void setX(double);
inline void setY(double);
inline void setZ(double);
// Set the components in cartesian coordinate system.
inline void set( double x, double y, double z);
// Set all three components in cartesian coordinate system.
inline double phi() const;
// The azimuth angle.
inline double theta() const;
// The polar angle.
inline double cosTheta() const;
// Cosine of the polar angle.
inline double cos2Theta() const;
// Cosine squared of the polar angle - faster than cosTheta(). (ZOOM)
inline double mag2() const;
// The magnitude squared (r^2 in spherical coordinate system).
inline double mag() const;
// The magnitude (r in spherical coordinate system).
inline void setPhi(double);
// Set phi keeping mag and theta constant (BaBar).
inline void setTheta(double);
// Set theta keeping mag and phi constant (BaBar).
void setMag(double);
// Set magnitude keeping theta and phi constant (BaBar).
inline double perp2() const;
// The transverse component squared (rho^2 in cylindrical coordinate system).
inline double perp() const;
// The transverse component (rho in cylindrical coordinate system).
inline void setPerp(double);
// Set the transverse component keeping phi and z constant.
void setCylTheta(double);
// Set theta while keeping transvers component and phi fixed
inline double perp2(const Hep3Vector &) const;
// The transverse component w.r.t. given axis squared.
inline double perp(const Hep3Vector &) const;
// The transverse component w.r.t. given axis.
inline Hep3Vector & operator = (const Hep3Vector &);
// Assignment.
inline bool operator == (const Hep3Vector &) const;
inline bool operator != (const Hep3Vector &) const;
// Comparisons (Geant4).
bool isNear (const Hep3Vector &, double epsilon=tolerance) const;
// Check for equality within RELATIVE tolerance (default 2.2E-14). (ZOOM)
// |v1 - v2|**2 <= epsilon**2 * |v1.dot(v2)|
double howNear(const Hep3Vector & v ) const;
// std::sqrt ( |v1-v2|**2 / v1.dot(v2) ) with a maximum of 1.
// If v1.dot(v2) is negative, will return 1.
double deltaR(const Hep3Vector & v) const;
// std::sqrt( pseudorapity_difference**2 + deltaPhi **2 )
inline Hep3Vector & operator += (const Hep3Vector &);
// Addition.
inline Hep3Vector & operator -= (const Hep3Vector &);
// Subtraction.
inline Hep3Vector operator - () const;
// Unary minus.
inline Hep3Vector & operator *= (double);
// Scaling with real numbers.
Hep3Vector & operator /= (double);
// Division by (non-zero) real number.
inline Hep3Vector unit() const;
// Vector parallel to this, but of length 1.
inline Hep3Vector orthogonal() const;
// Vector orthogonal to this (Geant4).
inline double dot(const Hep3Vector &) const;
// double product.
inline Hep3Vector cross(const Hep3Vector &) const;
// Cross product.
double angle(const Hep3Vector &) const;
// The angle w.r.t. another 3-vector.
double pseudoRapidity() const;
// Returns the pseudo-rapidity, i.e. -ln(std::tan(theta/2))
void setEta ( double p );
// Set pseudo-rapidity, keeping magnitude and phi fixed. (ZOOM)
void setCylEta ( double p );
// Set pseudo-rapidity, keeping transverse component and phi fixed. (ZOOM)
Hep3Vector & rotateX(double);
// Rotates the Hep3Vector around the x-axis.
Hep3Vector & rotateY(double);
// Rotates the Hep3Vector around the y-axis.
Hep3Vector & rotateZ(double);
// Rotates the Hep3Vector around the z-axis.
Hep3Vector & rotateUz(const Hep3Vector&);
// Rotates reference frame from Uz to newUz (unit vector) (Geant4).
Hep3Vector & rotate(double, const Hep3Vector &);
// Rotates around the axis specified by another Hep3Vector.
// (Uses methods of HepRotation, forcing linking in of Rotation.cc.)
Hep3Vector & operator *= (const HepRotation &);
Hep3Vector & transform(const HepRotation &);
// Transformation with a Rotation matrix.
// = = = = = = = = = = = = = = = = = = = = = = = =
//
// Esoteric properties and operations on 3-vectors:
//
// 1 - Set vectors in various coordinate systems
// 2 - Synonyms for accessing coordinates and properties
// 3 - Comparisions (dictionary, near-ness, and geometric)
// 4 - Intrinsic properties
// 5 - Properties releative to z axis and arbitrary directions
// 6 - Polar and azimuthal angle decomposition and deltaPhi
// 7 - Rotations
//
// = = = = = = = = = = = = = = = = = = = = = = = =
// 1 - Set vectors in various coordinate systems
inline void setRThetaPhi (double r, double theta, double phi);
// Set in spherical coordinates: Angles are measured in RADIANS
inline void setREtaPhi ( double r, double eta, double phi );
// Set in spherical coordinates, but specify peudorapidiy to determine theta.
inline void setRhoPhiZ (double rho, double phi, double z);
// Set in cylindrical coordinates: Phi angle is measured in RADIANS
void setRhoPhiTheta ( double rho, double phi, double theta);
// Set in cylindrical coordinates, but specify theta to determine z.
void setRhoPhiEta ( double rho, double phi, double eta);
// Set in cylindrical coordinates, but specify pseudorapidity to determine z.
// 2 - Synonyms for accessing coordinates and properties
inline double getX() const;
inline double getY() const;
inline double getZ() const;
// x(), y(), and z()
inline double getR () const;
inline double getTheta() const;
inline double getPhi () const;
// mag(), theta(), and phi()
inline double r () const;
// mag()
inline double rho () const;
inline double getRho () const;
// perp()
double eta () const;
double getEta () const;
// pseudoRapidity()
inline void setR ( double s );
// setMag()
inline void setRho ( double s );
// setPerp()
// 3 - Comparisions (dictionary, near-ness, and geometric)
int compare (const Hep3Vector & v) const;
bool operator > (const Hep3Vector & v) const;
bool operator < (const Hep3Vector & v) const;
bool operator>= (const Hep3Vector & v) const;
bool operator<= (const Hep3Vector & v) const;
// dictionary ordering according to z, then y, then x component
inline double diff2 (const Hep3Vector & v) const;
// |v1-v2|**2
static double setTolerance (double tol);
static inline double getTolerance ();
// Set the tolerance used in isNear() for Hep3Vectors
bool isParallel (const Hep3Vector & v, double epsilon=tolerance) const;
// Are the vectors parallel, within the given tolerance?
bool isOrthogonal (const Hep3Vector & v, double epsilon=tolerance) const;
// Are the vectors orthogonal, within the given tolerance?
double howParallel (const Hep3Vector & v) const;
// | v1.cross(v2) / v1.dot(v2) |, to a maximum of 1.
double howOrthogonal (const Hep3Vector & v) const;
// | v1.dot(v2) / v1.cross(v2) |, to a maximum of 1.
enum { ToleranceTicks = 100 };
// 4 - Intrinsic properties
double beta () const;
// relativistic beta (considering v as a velocity vector with c=1)
// Same as mag() but will object if >= 1
double gamma() const;
// relativistic gamma (considering v as a velocity vector with c=1)
double coLinearRapidity() const;
// inverse std::tanh (beta)
// 5 - Properties relative to Z axis and to an arbitrary direction
// Note that the non-esoteric CLHEP provides
// theta(), cosTheta(), cos2Theta, and angle(const Hep3Vector&)
inline double angle() const;
// angle against the Z axis -- synonym for theta()
inline double theta(const Hep3Vector & v2) const;
// synonym for angle(v2)
double cosTheta (const Hep3Vector & v2) const;
double cos2Theta(const Hep3Vector & v2) const;
// cos and cos^2 of the angle between two vectors
inline Hep3Vector project () const;
Hep3Vector project (const Hep3Vector & v2) const;
// projection of a vector along a direction.
inline Hep3Vector perpPart() const;
inline Hep3Vector perpPart (const Hep3Vector & v2) const;
// vector minus its projection along a direction.
double rapidity () const;
// inverse std::tanh(v.z())
double rapidity (const Hep3Vector & v2) const;
// rapidity with respect to specified direction:
// inverse std::tanh (v.dot(u)) where u is a unit in the direction of v2
double eta(const Hep3Vector & v2) const;
// - ln tan of the angle beween the vector and the ref direction.
// 6 - Polar and azimuthal angle decomposition and deltaPhi
// Decomposition of an angle within reference defined by a direction:
double polarAngle (const Hep3Vector & v2) const;
// The reference direction is Z: the polarAngle is std::abs(v.theta()-v2.theta()).
double deltaPhi (const Hep3Vector & v2) const;
// v.phi()-v2.phi(), brought into the range (-PI,PI]
double azimAngle (const Hep3Vector & v2) const;
// The reference direction is Z: the azimAngle is the same as deltaPhi
double polarAngle (const Hep3Vector & v2,
const Hep3Vector & ref) const;
// For arbitrary reference direction,
// polarAngle is std::abs(v.angle(ref) - v2.angle(ref)).
double azimAngle (const Hep3Vector & v2,
const Hep3Vector & ref) const;
// To compute azimangle, project v and v2 into the plane normal to
// the reference direction. Then in that plane take the angle going
// clockwise around the direction from projection of v to that of v2.
// 7 - Rotations
// These mehtods **DO NOT** use anything in the HepRotation class.
// Thus, use of v.rotate(axis,delta) does not force linking in Rotation.cc.
Hep3Vector & rotate (const Hep3Vector & axis, double delta);
// Synonym for rotate (delta, axis)
Hep3Vector & rotate (const HepAxisAngle & ax);
// HepAxisAngle is a struct holding an axis direction and an angle.
Hep3Vector & rotate (const HepEulerAngles & e);
Hep3Vector & rotate (double phi,
double theta,
double psi);
// Rotate via Euler Angles. Our Euler Angles conventions are
// those of Goldstein Classical Mechanics page 107.
protected:
void setSpherical (double r, double theta, double phi);
void setCylindrical (double r, double phi, double z);
double negativeInfinity() const;
protected:
double dx;
double dy;
double dz;
// The components.
DLL_API static double tolerance;
// default tolerance criterion for isNear() to return true.
}; // Hep3Vector
// Global Methods
Hep3Vector rotationXOf (const Hep3Vector & vec, double delta);
Hep3Vector rotationYOf (const Hep3Vector & vec, double delta);
Hep3Vector rotationZOf (const Hep3Vector & vec, double delta);
Hep3Vector rotationOf (const Hep3Vector & vec,
const Hep3Vector & axis, double delta);
Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax);
Hep3Vector rotationOf (const Hep3Vector & vec,
double phi, double theta, double psi);
Hep3Vector rotationOf (const Hep3Vector & vec, const HepEulerAngles & e);
// Return a new vector based on a rotation of the supplied vector
std::ostream & operator << (std::ostream &, const Hep3Vector &);
// Output to a stream.
std::istream & operator >> (std::istream &, Hep3Vector &);
// Input from a stream.
extern DLL_API const Hep3Vector HepXHat, HepYHat, HepZHat;
typedef Hep3Vector HepThreeVectorD;
typedef Hep3Vector HepThreeVectorF;
Hep3Vector operator / (const Hep3Vector &, double a);
// Division of 3-vectors by non-zero real number
inline Hep3Vector operator + (const Hep3Vector &, const Hep3Vector &);
// Addition of 3-vectors.
inline Hep3Vector operator - (const Hep3Vector &, const Hep3Vector &);
// Subtraction of 3-vectors.
inline double operator * (const Hep3Vector &, const Hep3Vector &);
// double product of 3-vectors.
inline Hep3Vector operator * (const Hep3Vector &, double a);
inline Hep3Vector operator * (double a, const Hep3Vector &);
// Scaling of 3-vectors with a real number
} // namespace CLHEP
#include "CLHEP/Vector/ThreeVector.icc"
#endif /* HEP_THREEVECTOR_H */
@@ -0,0 +1,292 @@
// -*- C++ -*-
// $Id:$
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// Hep3Vector class.
//
#include <cmath>
namespace CLHEP {
// ------------------
// Access to elements
// ------------------
// x, y, z
inline double & Hep3Vector::operator[] (int i) { return operator()(i); }
inline double Hep3Vector::operator[] (int i) const { return operator()(i); }
inline double Hep3Vector::x() const { return dx; }
inline double Hep3Vector::y() const { return dy; }
inline double Hep3Vector::z() const { return dz; }
inline double Hep3Vector::getX() const { return dx; }
inline double Hep3Vector::getY() const { return dy; }
inline double Hep3Vector::getZ() const { return dz; }
inline void Hep3Vector::setX(double x) { dx = x; }
inline void Hep3Vector::setY(double y) { dy = y; }
inline void Hep3Vector::setZ(double z) { dz = z; }
inline void Hep3Vector::set(double x, double y, double z) {
dx = x;
dy = y;
dz = z;
}
// --------------
// Global methods
// --------------
inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
}
inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
}
inline Hep3Vector operator * (const Hep3Vector & p, double a) {
return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
}
inline Hep3Vector operator * (double a, const Hep3Vector & p) {
return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
}
inline double operator * (const Hep3Vector & a, const Hep3Vector & b) {
return a.dot(b);
}
// --------------------------
// Set in various coordinates
// --------------------------
inline void Hep3Vector::setRThetaPhi
( double r, double theta, double phi ) {
setSpherical (r, theta, phi);
}
inline void Hep3Vector::setREtaPhi
( double r, double eta, double phi ) {
setSpherical (r, 2*std::atan(std::exp(-eta)), phi);
}
inline void Hep3Vector::setRhoPhiZ
( double rho, double phi, double z) {
setCylindrical (rho, phi, z);
}
// ------------
// Constructors
// ------------
inline Hep3Vector::Hep3Vector()
: dx(0.), dy(0.), dz(0.) {}
inline Hep3Vector::Hep3Vector(double x)
: dx(x), dy(0.), dz(0.) {}
inline Hep3Vector::Hep3Vector(double x, double y)
: dx(x), dy(y), dz(0.) {}
inline Hep3Vector::Hep3Vector(double x, double y, double z)
: dx(x), dy(y), dz(z) {}
inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
: dx(p.dx), dy(p.dy), dz(p.dz) {}
inline Hep3Vector::~Hep3Vector() {}
inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
dx = p.dx;
dy = p.dy;
dz = p.dz;
return *this;
}
// ------------------
// Access to elements
// ------------------
// r, theta, phi
inline double Hep3Vector::mag2() const { return dx*dx + dy*dy + dz*dz; }
inline double Hep3Vector::mag() const { return std::sqrt(mag2()); }
inline double Hep3Vector::r() const { return mag(); }
inline double Hep3Vector::theta() const {
return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : std::atan2(perp(),dz);
}
inline double Hep3Vector::phi() const {
return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
}
inline double Hep3Vector::getR() const { return mag(); }
inline double Hep3Vector::getTheta() const { return theta(); }
inline double Hep3Vector::getPhi() const { return phi(); }
inline double Hep3Vector::angle() const { return theta(); }
inline double Hep3Vector::cosTheta() const {
double ptot = mag();
return ptot == 0.0 ? 1.0 : dz/ptot;
}
inline double Hep3Vector::cos2Theta() const {
double ptot2 = mag2();
return ptot2 == 0.0 ? 1.0 : dz*dz/ptot2;
}
inline void Hep3Vector::setR(double r) { setMag(r); }
inline void Hep3Vector::setTheta(double th) {
double ma = mag();
double ph = phi();
setX(ma*std::sin(th)*std::cos(ph));
setY(ma*std::sin(th)*std::sin(ph));
setZ(ma*std::cos(th));
}
inline void Hep3Vector::setPhi(double ph) {
double xy = perp();
setX(xy*std::cos(ph));
setY(xy*std::sin(ph));
}
// perp, eta,
inline double Hep3Vector::perp2() const { return dx*dx + dy*dy; }
inline double Hep3Vector::perp() const { return std::sqrt(perp2()); }
inline double Hep3Vector::rho() const { return perp(); }
inline double Hep3Vector::eta() const { return pseudoRapidity();}
inline double Hep3Vector::getRho() const { return perp(); }
inline double Hep3Vector::getEta() const { return pseudoRapidity();}
inline void Hep3Vector::setPerp(double r) {
double p = perp();
if (p != 0.0) {
dx *= r/p;
dy *= r/p;
}
}
inline void Hep3Vector::setRho(double rho) { setPerp (rho); }
// ----------
// Comparison
// ----------
inline bool Hep3Vector::operator == (const Hep3Vector& v) const {
return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
}
inline bool Hep3Vector::operator != (const Hep3Vector& v) const {
return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
}
inline double Hep3Vector::getTolerance () {
return tolerance;
}
// ----------
// Arithmetic
// ----------
inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
dx += p.x();
dy += p.y();
dz += p.z();
return *this;
}
inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
dx -= p.x();
dy -= p.y();
dz -= p.z();
return *this;
}
inline Hep3Vector Hep3Vector::operator - () const {
return Hep3Vector(-dx, -dy, -dz);
}
inline Hep3Vector& Hep3Vector::operator *= (double a) {
dx *= a;
dy *= a;
dz *= a;
return *this;
}
// -------------------
// Combine two Vectors
// -------------------
inline double Hep3Vector::diff2(const Hep3Vector & p) const {
return (*this-p).mag2();
}
inline double Hep3Vector::dot(const Hep3Vector & p) const {
return dx*p.x() + dy*p.y() + dz*p.z();
}
inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
return Hep3Vector(dy*p.z()-p.y()*dz, dz*p.x()-p.z()*dx, dx*p.y()-p.x()*dy);
}
inline double Hep3Vector::perp2(const Hep3Vector & p) const {
double tot = p.mag2();
double ss = dot(p);
return tot > 0.0 ? mag2()-ss*ss/tot : mag2();
}
inline double Hep3Vector::perp(const Hep3Vector & p) const {
return std::sqrt(perp2(p));
}
inline Hep3Vector Hep3Vector::perpPart () const {
return Hep3Vector (dx, dy, 0);
}
inline Hep3Vector Hep3Vector::project () const {
return Hep3Vector (0, 0, dz);
}
inline Hep3Vector Hep3Vector::perpPart (const Hep3Vector & v2) const {
return ( *this - project(v2) );
}
inline double Hep3Vector::angle(const Hep3Vector & q) const {
return std::acos(cosTheta(q));
}
inline double Hep3Vector::theta(const Hep3Vector & q) const {
return angle(q);
}
inline double Hep3Vector::azimAngle(const Hep3Vector & v2) const {
return deltaPhi(v2);
}
// ----------
// Properties
// ----------
inline Hep3Vector Hep3Vector::unit() const {
double tot = mag2();
Hep3Vector p(x(),y(),z());
return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : p;
}
inline Hep3Vector Hep3Vector::orthogonal() const {
double x = dx < 0.0 ? -dx : dx;
double y = dy < 0.0 ? -dy : dy;
double z = dz < 0.0 ? -dz : dz;
if (x < y) {
return x < z ? Hep3Vector(0,dz,-dy) : Hep3Vector(dy,-dx,0);
}else{
return y < z ? Hep3Vector(-dz,0,dx) : Hep3Vector(dy,-dx,0);
}
}
} // namespace CLHEP
+215
View File
@@ -0,0 +1,215 @@
// -*- C++ -*-
// CLASSDOC OFF
// ---------------------------------------------------------------------------
// CLASSDOC ON
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// Hep2Vector is a general 2-vector class defining vectors in two
// dimension using double components. It comes from the ZOOM
// PlaneVector class (the PhysicsVectors PlaneVector.h will typedef
// PlaneVector to Hep2Vector).
//
// .SS See Also
// ThreeVector.h
//
// .SS Authors
// John Marraffino and Mark Fischler
//
#ifndef HEP_TWOVECTOR_H
#define HEP_TWOVECTOR_H
#ifdef GNUPRAGMA
#pragma interface
#endif
#include <iostream>
#include "CLHEP/Vector/ThreeVector.h"
namespace CLHEP {
// Declarations of classes and global methods
class Hep2Vector;
std::ostream & operator << (std::ostream &, const Hep2Vector &);
std::istream & operator >> (std::istream &, Hep2Vector &);
inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
inline Hep2Vector operator * (const Hep2Vector & p, double a);
inline Hep2Vector operator * (double a, const Hep2Vector & p);
Hep2Vector operator / (const Hep2Vector & p, double a);
inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
/**
* @author
* @ingroup vector
*/
class Hep2Vector {
public:
enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES };
// Safe indexing of the coordinates when using with matrices, arrays, etc.
inline Hep2Vector( double x = 0.0, double y = 0.0 );
// The constructor.
inline Hep2Vector(const Hep2Vector & p);
// The copy constructor.
explicit Hep2Vector( const Hep3Vector & s);
// "demotion" constructor"
// WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector.
// SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD!
inline ~Hep2Vector();
// The destructor.
inline double x() const;
inline double y() const;
// The components in cartesian coordinate system.
double operator () (int i) const;
inline double operator [] (int i) const;
// Get components by index. 0-based.
double & operator () (int i);
inline double & operator [] (int i);
// Set components by index. 0-based.
inline void setX(double x);
inline void setY(double y);
inline void set (double x, double y);
// Set the components in cartesian coordinate system.
inline double phi() const;
// The azimuth angle.
inline double mag2() const;
// The magnitude squared.
inline double mag() const;
// The magnitude.
inline double r() const;
// r in polar coordinates (r, phi): equal to mag().
inline void setPhi(double phi);
// Set phi keeping mag constant.
inline void setMag(double r);
// Set magnitude keeping phi constant.
inline void setR(double r);
// Set R keeping phi constant. Same as setMag.
inline void setPolar(double r, double phi);
// Set by polar coordinates.
inline Hep2Vector & operator = (const Hep2Vector & p);
// Assignment.
inline bool operator == (const Hep2Vector & v) const;
inline bool operator != (const Hep2Vector & v) const;
// Comparisons.
int compare (const Hep2Vector & v) const;
bool operator > (const Hep2Vector & v) const;
bool operator < (const Hep2Vector & v) const;
bool operator>= (const Hep2Vector & v) const;
bool operator<= (const Hep2Vector & v) const;
// dictionary ordering according to y, then x component
static inline double getTolerance();
static double setTolerance(double tol);
double howNear (const Hep2Vector &p) const;
bool isNear (const Hep2Vector & p, double epsilon=tolerance) const;
double howParallel (const Hep2Vector &p) const;
bool isParallel
(const Hep2Vector & p, double epsilon=tolerance) const;
double howOrthogonal (const Hep2Vector &p) const;
bool isOrthogonal
(const Hep2Vector & p, double epsilon=tolerance) const;
inline Hep2Vector & operator += (const Hep2Vector &p);
// Addition.
inline Hep2Vector & operator -= (const Hep2Vector &p);
// Subtraction.
inline Hep2Vector operator - () const;
// Unary minus.
inline Hep2Vector & operator *= (double a);
// Scaling with real numbers.
inline Hep2Vector unit() const;
// Unit vector parallel to this.
inline Hep2Vector orthogonal() const;
// Vector orthogonal to this.
inline double dot(const Hep2Vector &p) const;
// Scalar product.
inline double angle(const Hep2Vector &) const;
// The angle w.r.t. another 2-vector.
void rotate(double);
// Rotates the Hep2Vector.
operator Hep3Vector () const;
// Cast a Hep2Vector as a Hep3Vector.
// The remaining methods are friends, thus defined at global scope:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
friend std::ostream & operator<< (std::ostream &, const Hep2Vector &);
// Output to a stream.
inline friend double operator * (const Hep2Vector & a,
const Hep2Vector & b);
// Scalar product.
inline friend Hep2Vector operator * (const Hep2Vector & p, double a);
// v*c
inline friend Hep2Vector operator * (double a, const Hep2Vector & p);
// c*v
friend Hep2Vector operator / (const Hep2Vector & p, double a);
// v/c
inline friend Hep2Vector operator + (const Hep2Vector & a,
const Hep2Vector & b);
// v1+v2
inline friend Hep2Vector operator - (const Hep2Vector & a,
const Hep2Vector & b);
// v1-v2
enum { ZMpvToleranceTicks = 100 };
private:
double dx;
double dy;
// The components.
static double tolerance;
// default tolerance criterion for isNear() to return true.
}; // Hep2Vector
static const Hep2Vector X_HAT2(1.0, 0.0);
static const Hep2Vector Y_HAT2(0.0, 1.0);
} // namespace CLHEP
#include "CLHEP/Vector/TwoVector.icc"
#endif /* HEP_TWOVECTOR_H */
@@ -0,0 +1,171 @@
// -*- C++ -*-
// ---------------------------------------------------------------------------
//
// This file is a part of the CLHEP - a Class Library for High Energy Physics.
//
// This is the definitions of the inline member functions of the
// Hep2Vector class.
//
#include <cmath>
namespace CLHEP {
inline double Hep2Vector::x() const {
return dx;
}
inline double Hep2Vector::y() const {
return dy;
}
inline Hep2Vector::Hep2Vector(double x, double y)
: dx(x), dy(y) {}
inline Hep2Vector::Hep2Vector( const Hep3Vector & s)
: dx(s.x()), dy(s.y()) {}
inline void Hep2Vector::setX(double x) {
dx = x;
}
inline void Hep2Vector::setY(double y) {
dy = y;
}
inline void Hep2Vector::set(double x, double y) {
dx = x;
dy = y;
}
double & Hep2Vector::operator[] (int i) { return operator()(i); }
double Hep2Vector::operator[] (int i) const { return operator()(i); }
inline Hep2Vector::Hep2Vector(const Hep2Vector & p)
: dx(p.x()), dy(p.y()) {}
inline Hep2Vector::~Hep2Vector() {}
inline Hep2Vector & Hep2Vector::operator = (const Hep2Vector & p) {
dx = p.x();
dy = p.y();
return *this;
}
inline bool Hep2Vector::operator == (const Hep2Vector& v) const {
return (v.x()==x() && v.y()==y()) ? true : false;
}
inline bool Hep2Vector::operator != (const Hep2Vector& v) const {
return (v.x()!=x() || v.y()!=y()) ? true : false;
}
inline Hep2Vector& Hep2Vector::operator += (const Hep2Vector & p) {
dx += p.x();
dy += p.y();
return *this;
}
inline Hep2Vector& Hep2Vector::operator -= (const Hep2Vector & p) {
dx -= p.x();
dy -= p.y();
return *this;
}
inline Hep2Vector Hep2Vector::operator - () const {
return Hep2Vector(-dx, -dy);
}
inline Hep2Vector& Hep2Vector::operator *= (double a) {
dx *= a;
dy *= a;
return *this;
}
inline double Hep2Vector::dot(const Hep2Vector & p) const {
return dx*p.x() + dy*p.y();
}
inline double Hep2Vector::mag2() const {
return dx*dx + dy*dy;
}
inline double Hep2Vector::mag() const {
return std::sqrt(mag2());
}
inline double Hep2Vector::r() const {
return std::sqrt(mag2());
}
inline Hep2Vector Hep2Vector::unit() const {
double tot = mag2();
Hep2Vector p(*this);
return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : Hep2Vector(1,0);
}
inline Hep2Vector Hep2Vector::orthogonal() const {
double x = std::fabs(dx), y = std::fabs(dy);
if (x < y) {
return Hep2Vector(dy,-dx);
}else{
return Hep2Vector(-dy,dx);
}
}
inline double Hep2Vector::phi() const {
return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
}
inline double Hep2Vector::angle(const Hep2Vector & q) const {
double ptot2 = mag2()*q.mag2();
return ptot2 <= 0.0 ? 0.0 : std::acos(dot(q)/std::sqrt(ptot2));
}
inline void Hep2Vector::setMag(double r){
double ph = phi();
setX( r * std::cos(ph) );
setY( r * std::sin(ph) );
}
inline void Hep2Vector::setR(double r){
setMag(r);
}
inline void Hep2Vector::setPhi(double phi){
double ma = mag();
setX( ma * std::cos(phi) );
setY( ma * std::sin(phi) );
}
inline void Hep2Vector::setPolar(double r, double phi){
setX( r * std::cos(phi) );
setY( r * std::sin(phi) );
}
inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b) {
return Hep2Vector(a.x() + b.x(), a.y() + b.y());
}
inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b) {
return Hep2Vector(a.x() - b.x(), a.y() - b.y());
}
inline Hep2Vector operator * (const Hep2Vector & p, double a) {
return Hep2Vector(a*p.x(), a*p.y());
}
inline Hep2Vector operator * (double a, const Hep2Vector & p) {
return Hep2Vector(a*p.x(), a*p.y());
}
inline double operator * (const Hep2Vector & a, const Hep2Vector & b) {
return a.dot(b);
}
inline double Hep2Vector::getTolerance () {
return tolerance;
}
} // namespace CLHEP