1 // -*- C++ -*-
2 // CLASSDOC OFF
3 // ---------------------------------------------------------------------------
4 // CLASSDOC ON
5 
6 #ifndef HEP_ROTATION_INTERFACES_H
7 #define HEP_ROTATION_INTERFACES_H
8 
9 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
10 //
11 // This contains the definition of two abstract interface classes:
12 // Hep4RotationInterface
13 // Hep3RotationInterface.
14 // However, these are mostly for defining methods which should be present in
15 // any 4- or 3-rotation class, however specialized.  The actual classes do
16 // not inherit from these.  The virtual function overhead turns out
17 // to be too steep for that to be practical.
18 //
19 // It may be desirable in the future to turn these classes into constraints
20 // in the Stroustrup sense, so as to enforce this interface, still without
21 // inheritance.  However, they do contain an important static:
22 // static double tolerance to set criteria for relative nearness.
23 //
24 // This file also defines structs
25 // HepRep3x3;
26 // HepRep4x4;
27 // HepRep4x4Symmetric;
28 // which are used by various Rotation classes.
29 //
30 // Hep4RotationInterface
31 //	contains all the methods to get attributes of either a
32 // 	HepLorentzRotation or a HepRotation -- any information
33 //	that pertains to a LorentzRotation can also be defined
34 //	for a HepRotation.(For example, the 4x4 representation
35 //	would just have 0's in the space-time entries and 1 in
36 //	the time-time entry.)
37 //
38 // Hep3RotationInterface
39 //	inherits from Hep4RotationInterface,  and adds methods
40 //	which are well-defined only in the case of a Rotation.
41 //	For example, a 3x3 representation is an attribute only
42 //	if the generic LorentzRotation involves no boost.
43 //
44 // In terms of classes in the ZOOM PhysicsVectors package,
45 //	Hep4RotationInterface <--> LorentzTransformationInterface
46 //	Hep3RotationInterface <--> RotationInterface
47 //
48 // Hep4RotationInterface defines the required methods for:
49 //	HepLorentzRotation
50 //	HepBoost
51 //	HepBoostX
52 //	HepBoostY
53 //	HepBoostZ
54 //
55 // Hep3RotationInterface defines the required methods for:
56 //	HepRotation
57 //	HepRotationX
58 //	HepRotationY
59 //	HepRotationZ
60 //
61 // .SS See Also
62 // Rotation.h, LorentzRotation.h
63 //
64 // .SS Author
65 // Mark Fischler
66 //
67 
68 #include "CLHEP/Vector/defs.h"
69 #include "CLHEP/Vector/ThreeVector.h"
70 #include "CLHEP/Vector/LorentzVector.h"
71 #include "CLHEP/Vector/AxisAngle.h"
72 
73 namespace CLHEP {
74 
75 struct HepRep3x3;
76 struct HepRep4x4;
77 struct HepRep4x4Symmetric;
78 
79 class HepRotation;
80 class HepRotationX;
81 class HepRotationY;
82 class HepRotationZ;
83 class HepLorentzRotation;
84 class HepBoost;
85 class HepBoostX;
86 class HepBoostY;
87 class HepBoostZ;
88 
89 
90 //-******************************
91 //
92 // Hep4RotationInterface
93 //
94 //-******************************
95 
96 /**
97  * @author
98  * @ingroup vector
99  */
100 class Hep4RotationInterface  {
101 
102   // All attributes of shared by HepLorentzRotation, HepBoost,
103   // HepBoostX, HepBoostY, HepBoostZ.  HepRotation, HepRotationX,
104   // HepRotationY, HepRotationZ also share this attribute interface.
105 
106   friend class  HepRotation;
107   friend class  HepRotationX;
108   friend class  HepRotationY;
109   friend class  HepRotationZ;
110   friend class  HepLorentzRotation;
111   friend class  HepBoost;
112   friend class  HepBoostX;
113   friend class  HepBoostY;
114   friend class  HepBoostZ;
115 
116 public:
117 
118   static double tolerance;        // to determine relative nearness
119 
120   // ----------  Accessors:
121 
122 #ifdef ONLY_IN_CONCRETE_CLASSES
123   //  orthosymplectic 4-vectors:
124   HepLorentzVector col1() const;
125   HepLorentzVector col2() const;
126   HepLorentzVector col3() const;
127   HepLorentzVector col4() const;
128   HepLorentzVector row1() const;
129   HepLorentzVector row2() const;
130   HepLorentzVector row3() const;
131   HepLorentzVector row4() const;
132 
133   //  individual elements:
134   double xx() const  ;
135   double xy() const  ;
136   double xz() const  ;
137   double xt() const  ;
138   double yx() const  ;
139   double yy() const  ;
140   double yz() const  ;
141   double yt() const  ;
142   double zx() const  ;
143   double zy() const  ;
144   double zz() const  ;
145   double zt() const  ;
146   double tx() const  ;
147   double ty() const  ;
148   double tz() const  ;
149   double tt() const  ;
150 
151   //   4x4 representation:
152 //HepRep4x4 rep4x4() const;	JMM  Declared here but not defined anywhere!
153 
154   // ----------  Operations:
155   //   comparisons:
156 
157   inline int compare( const Hep4RotationInterface & lt ) const;
158   // Dictionary-order comparisons, utilizing the decompose(b,r) method
159 
160   //   decomposition:
161 
162   void decompose (HepAxisAngle & rotation, Hep3Vector & boost)const;
163   // Decompose as T= R * B, where R is pure rotation, B is pure boost.
164 
165   void decompose (Hep3Vector & boost, HepAxisAngle & rotation)const;
166   // Decompose as T= B * R, where R is pure rotation, B is pure boost.
167 
168   bool operator == (const Hep4RotationInterface & r) const;
169   bool operator != (const Hep4RotationInterface & r) const;
170 
171   //   relative comparison:
172 
173   double norm2() const  ;
174   double  distance2( const Hep4RotationInterface & lt ) const  ;
175   double  howNear( const Hep4RotationInterface & lt ) const  ;
176   bool isNear (const Hep4RotationInterface & lt,
177 				   double epsilon=tolerance) const  ;
178 
179   void rectify()  ;
180   // non-const but logically const correction for accumulated roundoff errors
181 
182   // ----------  Apply LorentzTransformations:
183 
184   HepLorentzVector operator* ( const HepLorentzVector & w ) const  ;
185   HepLorentzVector operator()( const HepLorentzVector & w ) const  ;
186   // Apply to a 4-vector
187 
188   // ----------  I/O:
189 
190   std::ostream & print( std::ostream & os ) const;
191 
192 #endif /* ONLY_IN_CONCRETE_CLASSES */
193 
194   static double getTolerance();
195   static double setTolerance( double tol );
196 
197   enum { ToleranceTicks = 100 };
198 
199 protected:
200 
~Hep4RotationInterface()201   ~Hep4RotationInterface() {}	// protect destructor to forbid instatiation
202 
203 };  // Hep4RotationInterface
204 
205 
206 
207 //-******************************
208 //
209 // Hep3RotationInterface
210 //
211 //-******************************
212 
213 /**
214  * @author
215  * @ingroup vector
216  */
217 class Hep3RotationInterface : public Hep4RotationInterface {
218 
219   // All attributes of HepRotation, HepRotationX, HepRotationY, HepRotationZ
220   // beyond those available by virtue of being a Hep3RotationInterface.
221 
222   friend class  HepRotation;
223   friend class  HepRotationX;
224   friend class  HepRotationY;
225   friend class  HepRotationZ;
226 
227 public:
228 
229 #ifdef ONLY_IN_CONCRETE_CLASSES
230 
231   //   Euler angles:
232   double getPhi  () const  ;
233   double getTheta() const  ;
234   double getPsi  () const  ;
235   double    phi  () const  ;
236   double    theta() const  ;
237   double    psi  () const  ;
238   HepEulerAngles eulerAngles() const  ;
239 
240   //   axis & angle of rotation:
241   double  getDelta() const  ;
242   Hep3Vector getAxis () const  ;
243   double     delta() const  ;
244   Hep3Vector    axis () const  ;
245   HepAxisAngle axisAngle() const  ;
246 
247   //   orthogonal unit-length vectors:
248   Hep3Vector rowX() const;
249   Hep3Vector rowY() const;
250   Hep3Vector rowZ() const;
251 
252   Hep3Vector colX() const;
253   Hep3Vector colY() const;
254   Hep3Vector colZ() const;
255 
256 //HepRep3x3 rep3x3() const;	JMM  Declared here but not defined anywhere!
257   //   3x3 representation
258 
259   //  orthosymplectic 4-vectors treating this as a 4-rotation:
260   HepLorentzVector col1() const;
261   HepLorentzVector col2() const;
262   HepLorentzVector col3() const;
263   HepLorentzVector col4() const;
264   HepLorentzVector row1() const;
265   HepLorentzVector row2() const;
266   HepLorentzVector row3() const;
267   HepLorentzVector row4() const;
268 
269   //  individual elements treating this as a 4-rotation:
270   double xt() const;
271   double yt() const;
272   double zt() const;
273   double tx() const;
274   double ty() const;
275   double tz() const;
276   double tt() const;
277 
278   // ---------- Operations in the Rotation group
279 
280   HepRotation operator * ( const Hep3RotationInterface & r ) const  ;
281 
282   // ---------- Application
283 
284   HepLorentzVector operator* ( const HepLorentzVector & w ) const  ;
285   HepLorentzVector operator()( const HepLorentzVector & w ) const  ;
286   //   apply to HepLorentzVector
287 
288   Hep3Vector operator* ( const Hep3Vector & v ) const  ;
289   Hep3Vector operator()( const Hep3Vector & v ) const  ;
290   //   apply to Hep3Vector
291 
292   // ---------- I/O and a helper method
293 
294   std::ostream & print( std::ostream & os ) const;
295 
296 #endif /* ONLY_IN_CONCRETE_CLASSES */
297 
298 private:
299 
~Hep3RotationInterface()300   ~Hep3RotationInterface() {}	// private destructor to forbid instatiation
301 
302 };  // Hep3RotationInterface
303 
304 
305 //-***************************
306 // 3x3 and 4x4 representations
307 //-***************************
308 
309 struct HepRep3x3 {
310 
311   // -----  Constructors:
312 
313   inline HepRep3x3();
314 
315   inline HepRep3x3(  double xx, double xy, double xz
316                    , double yx, double yy, double yz
317                    , double zx, double zy, double zz
318                    );
319 
320   inline HepRep3x3( const double * array );
321   // construct from an array of doubles, holding the rotation matrix
322   // in ROW order (xx, xy, ...)
323 
324   inline void setToIdentity();
325 
326   // -----  The data members are public:
327   double xx_, xy_, xz_,
328             yx_, yy_, yz_,
329             zx_, zy_, zz_;
330 
331   inline void getArray ( double * array ) const;
332   // fill array with the NINE doubles xx, xy, xz ... zz
333 
334 };  // HepRep3x3
335 
336 struct HepRep4x4 {
337 
338   // -----  Constructors:
339   inline HepRep4x4();
340 
341   inline HepRep4x4(  double xx, double xy, double xz, double xt
342                    , double yx, double yy, double yz, double yt
343                    , double zx, double zy, double zz, double zt
344                    , double tx, double ty, double tz, double tt
345                    );
346 
347   inline HepRep4x4( const HepRep4x4Symmetric & rep );
348 
349   inline HepRep4x4( const double * array );
350   // construct from an array of doubles, holding the transformation matrix
351   // in ROW order xx, xy, ...
352 
353   inline void setToIdentity();
354 
355   // -----  The data members are public:
356   double xx_, xy_, xz_, xt_,
357             yx_, yy_, yz_, yt_,
358             zx_, zy_, zz_, zt_,
359             tx_, ty_, tz_, tt_;
360 
361   inline void getArray ( double * array ) const;
362   // fill array with the SIXTEEN doubles xx, xy, xz ... tz, tt
363 
364   inline bool operator==(HepRep4x4 const & r) const;
365   inline bool operator!=(HepRep4x4 const & r) const;
366 
367 
368 };  // HepRep4x4
369 
370 struct HepRep4x4Symmetric {
371 
372   // -----  Constructors:
373 
374   inline HepRep4x4Symmetric();
375 
376   inline HepRep4x4Symmetric
377 	( double xx, double xy, double xz, double xt
378                       , double yy, double yz, double yt
379                                     , double zz, double zt
380                                                   , double tt );
381 
382   inline HepRep4x4Symmetric( const double * array );
383   // construct from an array of doubles, holding the transformation matrix
384   // elements in this order:  xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
385 
386   inline void setToIdentity();
387 
388   // -----  The data members are public:
389   double xx_, xy_, xz_, xt_,
390                  yy_, yz_, yt_,
391                       zz_, zt_,
392                            tt_;
393 
394   inline void getArray ( double * array ) const;
395   // fill array with the TEN doubles xx, xy, xz, xt, yy, yz, yt, zz, zt, tt
396 
397 };
398 
399 }  // namespace CLHEP
400 
401 #include "CLHEP/Vector/RotationInterfaces.icc"
402 
403 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
404 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
405 using namespace CLHEP;
406 #endif
407 
408 #endif // ROTATION_INTERFACES_H
409