Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-26 22:29:32

0001 /* 
0002    == CMS Forward Pixels Geometry ==
0003    Algorithm for creating rotatuion matrix
0004 */
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0008 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0009 #include "DetectorDescription/Core/interface/DDSplit.h"
0010 #include "DetectorDescription/Core/interface/DDConstant.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0012 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0013 #include "DetectorDescription/Core/interface/DDTransform.h"
0014 #include "CLHEP/Vector/ThreeVector.h"
0015 #include "CLHEP/Vector/Rotation.h"
0016 #include "CLHEP/Vector/RotationInterfaces.h"
0017 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0018 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0019 
0020 #include <cmath>
0021 #include <algorithm>
0022 #include <map>
0023 #include <string>
0024 #include <vector>
0025 
0026 class DDPixFwdRotation : public DDAlgorithm {
0027 public:
0028   DDPixFwdRotation() {}
0029   ~DDPixFwdRotation() override = default;
0030 
0031   void initialize(const DDNumericArguments& nArgs,
0032                   const DDVectorArguments& vArgs,
0033                   const DDMapArguments& mArgs,
0034                   const DDStringArguments& sArgs,
0035                   const DDStringVectorArguments& vsArgs) override;
0036 
0037   void execute(DDCompactView& cpv) override;
0038 
0039 private:
0040   double endcap_;  // +1 for Z Plus endcap disks, -1 for Z Minus endcap disks
0041   std::string rotNameNippleToCover_;
0042   std::string rotNameCoverToNipple_;
0043   std::string rotNameNippleToBody_;
0044   int nBlades_;              // Number of blades
0045   double bladeAngle_;        // Angle of blade rotation around axis perpendicular to beam
0046   double bladeZShift_;       // Shift in Z between the axes of two adjacent blades
0047   double ancorRadius_;       // Distance from beam line to ancor point defining center of "blade frame"
0048   double jX_, jY_, jZ_;      // Coordinates of Nipple ancor points J in blade frame
0049   double kX_, kY_, kZ_;      // Coordinates of Nipple ancor points K in blade frame
0050   std::string rotNS_;        //Namespace of the rotation matrix
0051   std::string idNameSpace_;  //Namespace of this and ALL sub-parts
0052 };
0053 
0054 void DDPixFwdRotation::initialize(const DDNumericArguments& nArgs,
0055                                   const DDVectorArguments& vArgs,
0056                                   const DDMapArguments&,
0057                                   const DDStringArguments& sArgs,
0058                                   const DDStringVectorArguments&) {
0059   // -- Input geometry parameters :  -----------------------------------------------------
0060   endcap_ = nArgs["Endcap"];
0061   rotNameNippleToCover_ = sArgs["NippleToCover"];
0062   rotNameCoverToNipple_ = sArgs["CoverToNipple"];
0063   rotNameNippleToBody_ = sArgs["NippleToBody"];
0064   nBlades_ = static_cast<int>(nArgs["Blades"]);  // Number of blades
0065   bladeAngle_ = nArgs["BladeAngle"];             // Angle of blade rotation around its axis
0066   bladeZShift_ = nArgs["BladeZShift"];           // Shift in Z between the axes of two adjacent blades
0067   ancorRadius_ = nArgs["AncorRadius"];  // Distance from beam line to ancor point defining center of "blade frame"
0068   // Coordinates of Nipple ancor points J and K in "blade frame" :
0069   jX_ = nArgs["JX"];
0070   jY_ = nArgs["JY"];
0071   jZ_ = nArgs["JZ"];
0072   kX_ = nArgs["KX"];
0073   kY_ = nArgs["KY"];
0074   kZ_ = nArgs["KZ"];
0075 
0076   rotNS_ = sArgs["RotationNS"];
0077   idNameSpace_ = DDCurrentNamespace::ns();
0078 
0079   edm::LogVerbatim("PixelGeom") << "DDPixFwdRotation: Initialize with endcap " << endcap_ << " NameSpace "
0080                                 << idNameSpace_ << ":" << rotNS_ << "\n  nBlades " << nBlades_ << " bladeAngle "
0081                                 << bladeAngle_ << " bladeZShift " << bladeZShift_ << " ancorRadius " << ancorRadius_
0082                                 << " jX|jY|jZ " << jX_ << ":" << jY_ << ":" << jZ_ << " kX|kY|kZ " << kX_ << ":" << kY_
0083                                 << ":" << kZ_;
0084 }
0085 
0086 void DDPixFwdRotation::execute(DDCompactView&) {
0087   // -- Compute Nipple parameters if not already computed :
0088   double effBladeAngle = endcap_ * bladeAngle_;
0089 
0090   CLHEP::Hep3Vector jC = CLHEP::Hep3Vector(jX_ * endcap_, jY_ + ancorRadius_, jZ_);
0091   ;  // Point J in the "cover" blade frame
0092   CLHEP::Hep3Vector kB = CLHEP::Hep3Vector(kX_ * endcap_, kY_ + ancorRadius_, kZ_);
0093   ;  // PoinladeZShiftladeZShiftladeZShiftt K in the "body" blade frame
0094 
0095   // Z-shift from "cover" to "body" blade frame:
0096   CLHEP::Hep3Vector tCB(bladeZShift_ * sin(effBladeAngle), 0., bladeZShift_ * cos(effBladeAngle));
0097 
0098   // Rotation from "cover" blade frame into "body" blade frame :
0099   double deltaPhi = endcap_ * (360. / nBlades_) * CLHEP::deg;
0100   CLHEP::HepRotation rCB(CLHEP::Hep3Vector(1. * sin(effBladeAngle), 0., 1. * cos(effBladeAngle)), deltaPhi);
0101 
0102   // Transform vector k into "cover" blade frame :
0103   CLHEP::Hep3Vector kC = rCB * (kB + tCB);
0104 
0105   // Vector JK in the "cover" blade frame:
0106   CLHEP::Hep3Vector jkC = kC - jC;
0107   double jkLength = jkC.mag();
0108   DDConstant JK(DDName("JK", rotNS_), std::make_unique<double>(jkLength));
0109   edm::LogVerbatim("PixelGeom") << "+++++++++++++++ DDPixFwdRotation: JK Length " << jkLength * CLHEP::mm;
0110 
0111   // Position of the center of a nipple in "cover" blade frame :
0112   CLHEP::Hep3Vector nippleTranslation((kC + jC) / 2. - CLHEP::Hep3Vector(0., ancorRadius_, 0.));
0113   edm::LogVerbatim("PixelGeom") << "Child translation : " << nippleTranslation;
0114 
0115   // Rotations from nipple frame to "cover" blade frame and back :
0116   CLHEP::Hep3Vector vZ(0., 0., 1.);
0117   CLHEP::Hep3Vector axis = vZ.cross(jkC);
0118   double angleCover = vZ.angle(jkC);
0119   edm::LogVerbatim("PixelGeom") << " Angle to Cover: " << angleCover;
0120   CLHEP::HepRotation* rpCN = new CLHEP::HepRotation(axis, angleCover);
0121 
0122   DDrot(
0123       DDName(rotNameCoverToNipple_, rotNS_),
0124       std::make_unique<DDRotationMatrix>(
0125           rpCN->xx(), rpCN->xy(), rpCN->xz(), rpCN->yx(), rpCN->yy(), rpCN->yz(), rpCN->zx(), rpCN->zy(), rpCN->zz()));
0126   CLHEP::HepRotation rpNC(axis, -angleCover);
0127   edm::LogVerbatim("PixelGeom") << "DDPixFwdBlades::Defines " << DDName(rotNameCoverToNipple_, rotNS_) << " with "
0128                                 << rpCN;
0129 
0130   DDrot(DDName(rotNameNippleToCover_, rotNS_),
0131         std::make_unique<DDRotationMatrix>(
0132             rpNC.xx(), rpNC.xy(), rpNC.xz(), rpNC.yx(), rpNC.yy(), rpNC.yz(), rpNC.zx(), rpNC.zy(), rpNC.zz()));
0133   edm::LogVerbatim("PixelGeom") << "DDPixFwdBlades::Defines " << DDName(rotNameNippleToCover_, rotNS_) << " with "
0134                                 << rpNC;
0135 
0136   // Rotation from nipple frame to "body" blade frame :
0137   CLHEP::HepRotation rpNB(rpNC * rCB);
0138   DDrot(DDName(rotNameNippleToBody_, rotNS_),
0139         std::make_unique<DDRotationMatrix>(
0140             rpNB.xx(), rpNB.xy(), rpNB.xz(), rpNB.yx(), rpNB.yy(), rpNB.yz(), rpNB.zx(), rpNB.zy(), rpNB.zz()));
0141   edm::LogVerbatim("PixelGeom") << "DDPixFwdBlades::Defines " << DDName(rotNameNippleToBody_, rotNS_) << " with "
0142                                 << rpNB;
0143   edm::LogVerbatim("PixelGeom") << " Angle to body : " << vZ.angle(rpNB * vZ);
0144 }
0145 
0146 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDPixFwdRotation, "track:DDPixFwdRotation");