Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:15

0001 #include <iostream>
0002 #include "DataFormats/GeometrySurface/interface/TkRotation.h"
0003 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
0004 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
0005 //#include "CommonReco/RKPropagators/interface/FrameChanger.h"
0006 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0007 
0008 #include <cmath>
0009 
0010 using namespace std;
0011 template <typename T>
0012 void go() {
0013   typedef TkRotation<T> Rotation;
0014   typedef GloballyPositioned<T> Frame;
0015   typedef typename Frame::PositionType Position;
0016   typedef typename Frame::GlobalVector GlobalVector;
0017   typedef typename Frame::GlobalPoint GlobalPoint;
0018   typedef typename Frame::LocalVector LocalVector;
0019   typedef typename Frame::LocalPoint LocalPoint;
0020 
0021   std::cout << "size of Rot     " << sizeof(Rotation) << std::endl;
0022   std::cout << "size of Pos     " << sizeof(Position) << std::endl;
0023   std::cout << "size of Point   " << sizeof(GlobalPoint) << std::endl;
0024   std::cout << "size of Frame   " << sizeof(Frame) << std::endl;
0025 
0026   double a = 0.01;
0027   double ca = cos(a);
0028   double sa = sin(a);
0029 
0030   Rotation r1(ca, sa, 0, -sa, ca, 0, 0, 0, 1);
0031   ;
0032   Frame f1(Position(2, 3, 4), r1);
0033   cout << "f1.position() " << f1.position() << endl;
0034   cout << "f1.rotation() " << endl << f1.rotation() << endl;
0035 
0036   Rotation r2(GlobalVector(0, 1, 0), GlobalVector(0, 0, 1));
0037   Frame f2(Position(5, 6, 7), r2);
0038   cout << "f2.position() " << f2.position() << endl;
0039   cout << "f2.rotation() " << endl << f2.rotation() << endl;
0040 
0041   // transform f2 to f1 so that f1 becomes the "global" frame of f3
0042   // Rotation r3 = r2.multiplyInverse(r1);
0043   // Rotation r3 = r2*r1;
0044 
0045   // Rotation r3 = r1*r2;
0046   // Rotation r3 = r1*r2.transposed();
0047   // Rotation r3 = r1.transposed()*r2;
0048   // Rotation r3 = r1.transposed()*r2.transposed();
0049   // Rotation r3 = r2*r1;
0050   Rotation r3 = r2 * r1.transposed();
0051 
0052   GlobalPoint pos2(f2.position());
0053   LocalPoint lp3 = f1.toLocal(pos2);
0054   Frame f3(GlobalPoint(lp3.basicVector()), r3);
0055   cout << "f3.position() " << f3.position() << endl;
0056   cout << "f3.rotation() " << endl << f3.rotation() << endl;
0057 
0058   // test
0059   GlobalPoint gp(11, 22, 33);
0060   LocalPoint p_in1 = f1.toLocal(gp);
0061   typename Frame::ToLocal ff1(f1);
0062   LocalPoint p_in2 = f2.toLocal(gp);
0063   LocalPoint p_in3 = f3.toLocal(GlobalPoint(p_in1.basicVector()));
0064   cout << "p_in1 " << p_in1 << endl;
0065   cout << "p_in1 " << ff1.toLocal(gp) << endl;
0066   cout << "p_in2 " << p_in2 << endl;
0067   cout << "p_in3 " << p_in3 << endl;
0068 
0069   LocalPoint p_in1_from3(f3.toGlobal(p_in3).basicVector());
0070   cout << "p_in1_from3 + " << p_in1_from3 << endl;
0071 
0072   BoundPlane plane(f2.position(), f2.rotation());
0073 
0074   //     FrameChanger<double> changer;
0075   //     FrameChanger<double>::PlanePtr pp = changer.toFrame( plane, f1);
0076 
0077   /*
0078     FrameChanger changer;
0079     FrameChanger::PlanePtr pp = changer.transformPlane( plane, f1);
0080     
0081     LocalPoint p_in2p = plane.toLocal( gp);
0082     LocalPoint p_in3p = pp->toLocal( GlobalPoint(p_in1.basicVector()));
0083     cout << "p_in2p " << p_in2p << endl;
0084     cout << "p_in3p " << p_in3p << endl;
0085 */
0086 }
0087 
0088 void cyl() {
0089   using T = float;
0090   typedef TkRotation<T> Rotation;
0091   typedef GloballyPositioned<T> Frame;
0092   typedef typename Frame::PositionType Position;
0093   typedef typename Frame::GlobalVector GlobalVector;
0094   typedef typename Frame::GlobalPoint GlobalPoint;
0095   typedef typename Frame::LocalVector LocalVector;
0096   typedef typename Frame::LocalPoint LocalPoint;
0097 
0098   // cylinder
0099   {
0100     std::cout << " Trivial Cylinder" << std::endl;
0101     Rotation ll(GlobalVector(1, 0, 0), GlobalVector(0, 1, 0));
0102     Position p0(0, 0, 0);
0103     Cylinder cyl(5., p0, ll);
0104     Plane t = cyl.fastTangent(GlobalPoint(3., 4., 1.));
0105     std::cout << t.position() << '\n' << t.rotation() << std::endl;
0106     std::cout << t.rotation().x() * cyl.rotation().z().cross((t.position() - cyl.position()).basicVector()).unit()
0107               << std::endl;
0108   }
0109 
0110   {
0111     std::cout << " rotated, displaced Cylinder" << std::endl;
0112     Rotation ll(Basic3DVector<T>(1, 1, 1), .3);
0113     Cylinder cyl(5.f, Position(2, -1, 3), ll);
0114     Plane t = cyl.fastTangent(LocalPoint(3., 4., 1.));
0115     std::cout << t.position() << '\n' << t.rotation() << std::endl;
0116     std::cout << t.rotation().x() * cyl.rotation().z().cross((t.position() - cyl.position()).basicVector()).unit()
0117               << std::endl;
0118   }
0119 }
0120 
0121 int main() {
0122   go<float>();
0123   cyl();
0124   std::cout << std::endl;
0125   go<double>();
0126 }