Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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