Back to index

CCoordinate.C

 
//----------------------------------------------------------------------------- 
//  $Header: /asis/offline/ceres/cool/project/RCS/CCoordinate.C,v 2.1 1996/10/04 08:43:23 voigt Exp messer $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Implementation of coordinate classes. 
// 
//----------------------------------------------------------------------------- 
#include <iostream.h> 
#include <math.h> 
#include <float.h> 
#include "CCoordinate.h" 
 
// 
//  Trivial transformation routines 
// 
 
void transform(CLabCylinderCoord& cyl, const CLabXYZCoord& xyz) 
{ 
   cyl.radius = sqrt(xyz.x*xyz.x + xyz.y*xyz.y); 
   if (cyl.radius == 0) 
      cyl.phi = 0; 
   else 
      cyl.phi    = atan2(xyz.y, xyz.x); 
   cyl.z = xyz.z; 
} 
 
 
void transform(CLabXYZCoord& xyz, const CLabCylinderCoord& cyl) 
{ 
   xyz.x = cyl.radius*cos(double(cyl.phi)); 
   xyz.y = cyl.radius*sin(double(cyl.phi)); 
   xyz.z = cyl.z; 
} 
 
void transform(CEventXYZCoord& xyz, const CEventCoord& polar) 
{ 
   xyz.x = cos(polar.phi) * tan(polar.theta/1000.) * polar.z;  // note mrad->rad!    
   xyz.y = sin(polar.phi) * tan(polar.theta/1000.) * polar.z;  // note mrad->rad!    
   xyz.z = polar.z; 
} 
 
void transform(CEventCoord& polar, const CEventXYZCoord& xyz) 
{ 
   double r = sqrt(xyz.x*xyz.x + xyz.y*xyz.y); 
   if (r == 0.) 
      polar.phi = 0.; 
   else 
      polar.phi = atan2(xyz.y, xyz.x); 
   if (xyz.z == 0.) 
      polar.theta = 0.; 
   else 
      polar.theta = atan2(r, xyz.z) * 1000.;  // note rad->mrad!   
   polar.z = xyz.z; 
} 
 
// 
//  Definition of related == operators 
// 
 
CBoolean CRichPadCoord::operator== (const CRichPadCoord& rxy) const 
{ 
   return (fabs(x-rxy.x) < FLT_EPSILON &&  
           fabs(y-rxy.y) < FLT_EPSILON );  
} 
 
CBoolean CPadCPadCoord::operator== (const CPadCPadCoord& rxy) const 
{ 
   return (fabs(x-rxy.x) < FLT_EPSILON &&  
           fabs(y-rxy.y) < FLT_EPSILON );  
} 
 
CBoolean CRichXYCoord::operator== (const CRichXYCoord& gxy) const 
{ 
   return (fabs(x-gxy.x) < FLT_EPSILON &&  
           fabs(y-gxy.y) < FLT_EPSILON );  
} 
 
CBoolean CRichPolarCoord::operator== (const CRichPolarCoord& gp) const 
{ 
   return (fabs(theta-gp.theta) < FLT_EPSILON && (phi == gp.phi));  
} 
 
CBoolean CLabXYZCoord::operator== (const CLabXYZCoord& sxy) const 
{ 
   return (fabs(x-sxy.x) < FLT_EPSILON &&  
           fabs(z-sxy.z) < FLT_EPSILON &&  
           fabs(y-sxy.y) < FLT_EPSILON );  
} 
 
CBoolean CLabCylinderCoord::operator== (const CLabCylinderCoord& sp) const 
{ 
   return (fabs(radius-sp.radius) < FLT_EPSILON &&  
           (phi == sp.phi)   		        &&  
           fabs(z-sp.z)           < FLT_EPSILON ); 
} 
 
CBoolean CSidcCellCoord::operator== (const CSidcCellCoord& sc) const 
{ 
   return (fabs(anode-sc.anode) < FLT_EPSILON &&  
           fabs(timeBin-sc.timeBin) < FLT_EPSILON );  
} 
 
CBoolean CEventCoord::operator== (const CEventCoord& gp) const 
{ 
   return (fabs(theta-gp.theta) < FLT_EPSILON &&  
           (phi==gp.phi)                      &&  
           fabs(z-gp.z)         < FLT_EPSILON );  
} 
 
CBoolean CEventXYZCoord::operator== (const CEventXYZCoord& a) const 
{ 
   return (fabs(x-a.x) < FLT_EPSILON &&  
           fabs(y-a.y) < FLT_EPSILON &&  
           fabs(z-a.z) < FLT_EPSILON );  
} 
 
 
// 
//  Definition of related output operators 
// 
       
ostream& operator<<(ostream& ost, const CRichPolarCoord& gp) 
{ 
   return ost << '(' << gp.getTheta() << " mrad, " << gp.getPhi() << " rad)"; 
} 
 
ostream& operator<<(ostream& ost, const CRichXYCoord &gxy) 
{ 
   return ost << '(' << gxy.getX() << " mrad, " << gxy.getY() << " mrad)"; 
} 
 
ostream& operator<<(ostream& ost, const CRichPadCoord& rxy) 
{ 
   return ost << '(' << rxy.getX() << " pads, " << rxy.getY() << " pads)"; 
} 
 
ostream& operator<<(ostream& ost, const CPadCPadCoord& pxy) 
{ 
   return ost << '(' << pxy.getX() << " pads, " << pxy.getY() << " pads)"; 
} 
 
ostream& operator<<(ostream& ost, const CLabXYZCoord& sxy) 
{ 
   return ost << '(' << sxy.getX() << " cm, " << sxy.getY() << " cm, " << sxy.getZ() << " cm)"; 
} 
 
ostream& operator<<(ostream& ost, const CLabCylinderCoord& sp) 
{ 
   return ost << '(' << sp.getRadius() << " cm, " << sp.getPhi() << " rad, " << sp.getZ() << " cm)"; 
} 
 
ostream& operator<<(ostream& ost, const CSidcCellCoord& sc) 
{ 
   return ost << '(' << sc.getAnode() << ", " << sc.getTimeBin() << ')'; 
} 
 
ostream& operator<<(ostream& ost, const CEventCoord& gp) 
{ 
   return ost << '(' << gp.getTheta() << " mrad, " << gp.getPhi() << " rad, " << gp.getZ() << " cm)"; 
} 
 
ostream& operator<<(ostream& ost, const CEventXYZCoord& a) 
{ 
   return ost << '(' << a.getX() << ", " << a.getY() << ", " << a.getZ() << ")cm"; 
} 
 
// 
//  Definition of mathematical operations on coordinates 
// 
 
CRichXYCoord CRichXYCoord::operator-= (const CRichXYCoord & xy) 
{ 
   x -= xy.x;   y -= xy.y; 
   return *this; 
} 
 
CRichXYCoord CRichXYCoord::operator+= (const CRichXYCoord & xy) 
{ 
   x += xy.x;   y += xy.y;    
   return *this; 
} 
 
double abs(const CRichXYCoord & xy) 
{ 
   return sqrt(xy.x*xy.x+xy.y*xy.y); 
} 
 
CRichXYCoord operator- (const CRichXYCoord & a, const CRichXYCoord & b) 
{ 
   CRichXYCoord c(a.x - b.x, a.y - b.y); 
   return c; 
} 
 
CRichXYCoord operator+ (const CRichXYCoord & a, const CRichXYCoord & b) 
{ 
   CRichXYCoord c(a.x + b.x, a.y + b.y); 
   return c; 
} 
 
double abs(const CRichPadCoord & pad)  
{ 
   return sqrt(pad.x*pad.x + pad.y*pad.y); 
} 
 
CRichPadCoord CRichPadCoord::operator-= (const CRichPadCoord & xy) 
{ 
   x -= xy.x;   y -= xy.y; 
   return *this; 
} 
 
CRichPadCoord CRichPadCoord::operator+= (const CRichPadCoord & xy) 
{ 
   x += xy.x;   y += xy.y;    
   return *this; 
} 
 
CRichPadCoord operator- (const CRichPadCoord & a, const CRichPadCoord & b) 
{ 
   CRichPadCoord c(a.x - b.x, a.y - b.y); 
   return c; 
} 
 
CRichPadCoord operator+ (const CRichPadCoord & a, const CRichPadCoord & b) 
{ 
   CRichPadCoord c(a.x + b.x, a.y + b.y); 
   return c; 
} 
 
double abs(const CPadCPadCoord & pad)  
{ 
   return sqrt(pad.x*pad.x + pad.y*pad.y); 
} 
 
CPadCPadCoord CPadCPadCoord::operator-= (const CPadCPadCoord & xy) 
{ 
   x -= xy.x;   y -= xy.y; 
   return *this; 
} 
 
CPadCPadCoord CPadCPadCoord::operator+= (const CPadCPadCoord & xy) 
{ 
   x += xy.x;   y += xy.y;    
   return *this; 
} 
 
CPadCPadCoord operator- (const CPadCPadCoord & a, const CPadCPadCoord & b) 
{ 
CPadCPadCoord c(a.x - b.x, a.y - b.y); 
   return c; 
} 
 
CPadCPadCoord operator+ (const CPadCPadCoord & a, const CPadCPadCoord & b) 
{ 
CPadCPadCoord c(a.x + b.x, a.y + b.y); 
   return c; 
} 
 
CLabCylinderCoord CLabCylinderCoord::operator-= (const CLabCylinderCoord & cyl) 
{ 
   CLabXYZCoord xyz, this_xyz; 
   transform(xyz, cyl); 
   transform(this_xyz, *this); 
   this_xyz -= xyz; 
   transform(*this, this_xyz); 
   return *this; 
} 
 
CLabCylinderCoord CLabCylinderCoord::operator+= (const CLabCylinderCoord & cyl) 
{ 
   CLabXYZCoord xyz, this_xyz; 
   transform(xyz, cyl); 
   transform(this_xyz, *this); 
   this_xyz += xyz; 
   transform(*this, this_xyz); 
   return *this; 
} 
 
double abs(const CLabCylinderCoord & cyl) 
{ 
   CLabXYZCoord xyz; 
   transform(xyz, cyl); 
   return abs(xyz); 
} 
 
CLabCylinderCoord operator- (const CLabCylinderCoord & a, const CLabCylinderCoord & b) 
{ 
   CLabXYZCoord a_xyz, b_xyz; 
   CLabCylinderCoord c; 
   transform(a_xyz, a); 
   transform(b_xyz, b); 
   transform(c, a_xyz-b_xyz); 
   return c; 
} 
 
CLabCylinderCoord operator+ (const CLabCylinderCoord & a, const CLabCylinderCoord & b) 
{ 
   CLabXYZCoord a_xyz, b_xyz; 
   CLabCylinderCoord c; 
   transform(a_xyz, a); 
   transform(b_xyz, b); 
   transform(c, a_xyz+b_xyz); 
   return c; 
} 
 
CLabXYZCoord CLabXYZCoord::operator-= (const CLabXYZCoord & xy) 
{ 
   x -= xy.x;   y -= xy.y; z -= xy.z; 
   return *this; 
} 
 
CLabXYZCoord CLabXYZCoord::operator+= (const CLabXYZCoord & xy) 
{ 
   x += xy.x;   y += xy.y; z += xy.z; 
   return *this; 
} 
 
double abs(const CLabXYZCoord & xy) 
{ 
   return sqrt(xy.x*xy.x + xy.y*xy.y + xy.z*xy.z); 
} 
 
CLabXYZCoord operator- (const CLabXYZCoord & a, const CLabXYZCoord & b) 
{ 
   CLabXYZCoord c(a.x - b.x, a.y - b.y, a.z - b.z); 
   return c; 
} 
 
CLabXYZCoord operator+ (const CLabXYZCoord & a, const CLabXYZCoord & b) 
{ 
   CLabXYZCoord c(a.x + b.x, a.y + b.y, a.z + b.z); 
   return c; 
} 
 
double operator* (const CLabXYZCoord & a, const CLabXYZCoord & b) 
{ 
   double c = a.x*b.x + a.y*b.y + a.z*b.z; 
   return c; 
} 
 
CEventXYZCoord operator- (const CEventXYZCoord & a, const CEventXYZCoord & b) 
{ 
   CEventXYZCoord c(a.x - b.x, a.y - b.y, a.z - b.z); 
   return c; 
} 
 
CEventXYZCoord operator+ (const CEventXYZCoord & a, const CEventXYZCoord & b) 
{ 
   CEventXYZCoord c(a.x + b.x, a.y + b.y, a.z + b.z); 
   return c; 
} 
 
double operator* (const CEventXYZCoord & a, const CEventXYZCoord & b) 
{ 
   double c = a.x*b.x + a.y*b.y + a.z*b.z; 
   return c; 
} 
 
 

Back to index