Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /irt/include/ParametricSurface.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 #include <math.h>
0003 
0004 #include <TObject.h>
0005 #include <TVector3.h>
0006 
0007 #ifndef _IRT_PARAMETRIC_SURFACE_
0008 #define _IRT_PARAMETRIC_SURFACE_
0009 
0010 class ParametricSurface: public TObject {
0011  public:
0012  ParametricSurface(): m_Umin(0.0), m_Umax(0.0), m_Vmin(0.0), m_Vmax(0.0) {};
0013  ParametricSurface(const TVector3 &x0, double umin, double umax, double vmin, double vmax):
0014   m_Center(x0), m_Umin(umin), m_Umax(umax), m_Vmin(vmin), m_Vmax(vmax) {};
0015   ~ParametricSurface() {};
0016 
0017   // 2D parameter ranges (call them U&V);
0018   double Umin( void ) const { return m_Umin; };
0019   double Umax( void ) const { return m_Umax; };
0020   double Vmin( void ) const { return m_Vmin; };
0021   double Vmax( void ) const { return m_Vmax; };
0022   bool IsInside(double u, double v) const {
0023     return (u >= m_Umin && u <= m_Umax && v >= m_Vmin && v <= m_Vmax);
0024   };
0025   void SetUVranges(double umin, double umax, double vmin, double vmax) {
0026     m_Umin = umin; m_Umax = umax; m_Vmin = vmin; m_Vmax = vmax;
0027   };
0028 
0029   virtual TVector3 GetSpacePoint(double u, double v) const = 0;
0030   // There is no check that the point actually belongs to the surface;
0031   // it is assumed that GEANT stepping was done correctly, so the point 
0032   // is more or less close to the 2D surface; for flat and spherical 
0033   // surfaces this is a mute point anyway since this function is implemented 
0034   // in a trivial way;
0035   virtual TVector3 GetNormal(const TVector3 &xx) const = 0;
0036   // Provide a reasonable wrapper; of course simple surfaces 
0037   // can to their own calculations;
0038   virtual TVector3 GetNormal(double u, double v) const {
0039     auto pt = GetSpacePoint(u, v);
0040     return GetNormal(pt);
0041   };
0042   // default, not overriden by all derived classes
0043   virtual TVector3 GetNormal( void ) const {
0044     return TVector3(0.0, 0.0, 0.0);
0045   };
0046   const TVector3 &GetCenter( void ) const { return m_Center; };
0047   virtual double GetDistance(const TVector3 &xx) const = 0;
0048 
0049   // Crossing with the straight line defined by {x0,n0}; 
0050   virtual bool GetCrossing(const TVector3 &x0, const TVector3 &n0, TVector3 *crs, 
0051                bool check_normal = true) const = 0;
0052 
0053   // Introduce only the transformations needed for the current task;
0054   virtual ParametricSurface *_Clone(double angle, const TVector3 &axis) const = 0;
0055   void Shift(const TVector3 &shift) {
0056     m_Center += shift;
0057   };
0058   
0059  protected:
0060   // It looks like surfaces I need typically have m_Center defined;
0061   TVector3 m_Center;
0062 
0063  private:
0064   double m_Umin, m_Umax, m_Vmin, m_Vmax;
0065 
0066 #ifndef DISABLE_ROOT_IO
0067   ClassDef(ParametricSurface, 1);
0068 #endif
0069 };
0070 
0071 class SphericalSurface: public ParametricSurface {
0072  public:
0073  SphericalSurface(): m_Concave(true), m_Radius(0.0) {};
0074  SphericalSurface(const TVector3 &x0, double r0, double umin = 0.0, double umax = M_PI, 
0075           double vmin = 0.0, double vmax = 2*M_PI): 
0076   ParametricSurface(x0, umin, umax, vmin, vmax), m_Concave(true), m_Radius(r0) {};
0077   ~SphericalSurface() {};
0078 
0079   // FIXME: no range check?; 
0080   TVector3 GetSpacePoint(double theta, double phi) const {
0081     TVector3 nn(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta));
0082     return GetCenter() + m_Radius*nn;
0083   };
0084 
0085   TVector3 GetNormal(const TVector3 &xx) const {
0086     return (m_Concave ? -1.0 : 1.0)*(xx - GetCenter()).Unit();
0087   };
0088   double GetRadius( void ) const { return m_Radius; };
0089 
0090   bool GetCrossing(const TVector3 &x0, const TVector3 &n0, TVector3 *crs, bool check_normal = true) const;
0091   double GetDistance(const TVector3 &xx) const;
0092 
0093   void SetConvex( void ) { m_Concave = false; };
0094   ParametricSurface *_Clone(double angle, const TVector3 &axis) const {
0095     auto copy = new SphericalSurface(*this);
0096 
0097     copy->m_Center.Rotate(angle, axis);
0098 
0099     return copy;
0100   };
0101 
0102  private:
0103   bool m_Concave;
0104   double m_Radius;
0105 
0106 #ifndef DISABLE_ROOT_IO
0107   ClassDef(SphericalSurface, 2);
0108 #endif
0109 };
0110 
0111 class LocalCoordinatesXY: public TObject {
0112  public:
0113   LocalCoordinatesXY() {};
0114   ~LocalCoordinatesXY() {};
0115 
0116   virtual double GetLocalX(const TVector3 &xx) const = 0;
0117   virtual double GetLocalY(const TVector3 &xx) const = 0;
0118 
0119 #ifndef DISABLE_ROOT_IO
0120   ClassDef(LocalCoordinatesXY, 1);
0121 #endif
0122 }; 
0123 
0124 // In fact a rectangle in space;
0125 class FlatSurface: public ParametricSurface, public LocalCoordinatesXY {
0126  public:
0127   FlatSurface() {};
0128  FlatSurface(const TVector3 &x0, const TVector3 &nx, const TVector3 &ny, double sx = 0.0, double sy = 0.0):
0129   // FIXME: no orthogonality and / or normalization check?;
0130   ParametricSurface(x0, -sx/2, sx/2, -sy/2, sy/2), m_Nx(nx.Unit()), m_Ny(ny.Unit()) {
0131     m_Nz = nx.Cross(ny).Unit();
0132   };
0133   ~FlatSurface() {};
0134 
0135   TVector3 GetSpacePoint(double x, double y) const {
0136     return GetCenter() + x*m_Nx + y*m_Ny;
0137   };
0138   TVector3 GetNormal(const TVector3 &xx) const {
0139     // Make compiler happy, use 'xx' variable;
0140     return m_Nz + 0.0*xx;
0141   };
0142   TVector3 GetNormal( void ) const {
0143     return m_Nz;
0144   };
0145   // FIXME: well, this calculation assumes orthogonal X&Y vectors were provided;
0146   inline double GetLocalX(const TVector3 &xx) const {
0147     return (xx - GetCenter()).Dot(m_Nx);
0148   };
0149   inline double GetLocalY(const TVector3 &xx) const {
0150     return (xx - GetCenter()).Dot(m_Ny);
0151   };
0152 
0153   bool GetCrossing(const TVector3 &x0, const TVector3 &n0, TVector3 *crs, bool check_normal = true) const;
0154   double GetDistance(const TVector3 &xx) const;
0155   ParametricSurface *_Clone(double angle, const TVector3 &axis) const {
0156     auto copy = new FlatSurface(*this);
0157 
0158     copy->m_Center.Rotate(angle, axis);
0159 
0160     copy->m_Nx.Rotate(angle, axis);
0161     copy->m_Ny.Rotate(angle, axis);
0162     copy->m_Nz.Rotate(angle, axis);
0163 
0164     return copy;
0165   };
0166 
0167  private:
0168   TVector3 m_Nx, m_Ny, m_Nz;
0169 
0170 #ifndef DISABLE_ROOT_IO
0171   ClassDef(FlatSurface, 1);
0172 #endif
0173 };
0174 
0175 #endif