Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:03

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDPixFwdDiskAlgo.cc
0003 // Description: Position n copies at given z-values
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTypes.h"
0010 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0012 #include "CLHEP/Units/PhysicalConstants.h"
0013 #include "CLHEP/Units/SystemOfUnits.h"
0014 
0015 #include <cmath>
0016 #include <algorithm>
0017 #include <map>
0018 #include <string>
0019 #include <vector>
0020 
0021 using namespace std;
0022 
0023 class DDPixFwdDiskAlgo : public DDAlgorithm {
0024 public:
0025   //Constructor and Destructor
0026   DDPixFwdDiskAlgo();
0027   ~DDPixFwdDiskAlgo() override;
0028 
0029   void initialize(const DDNumericArguments& nArgs,
0030                   const DDVectorArguments& vArgs,
0031                   const DDMapArguments& mArgs,
0032                   const DDStringArguments& sArgs,
0033                   const DDStringVectorArguments& vsArgs) override;
0034 
0035   void execute(DDCompactView& cpv) override;
0036 
0037 private:
0038   string idNameSpace;          //Namespace of this and ALL sub-parts
0039   string childName;            //Child name
0040   string rotName;              //Name of the base rotation matrix
0041   string flagString;           //Flag if a blade is present
0042   int nBlades;                 //Number of blades
0043   int startCopyNo;             //Start Copy number
0044   double bladeAngle;           //Angle of blade rotation aroung y-axis
0045   double zPlane;               //Common shift in z for all blades
0046   vector<double> bladeZShift;  //Shift in Z of individual blades
0047   double anchorR;              //Distance of beam line to anchor point
0048   double bladeTilt;            //Tilt of the blade around x-axis
0049 };
0050 
0051 DDPixFwdDiskAlgo::DDPixFwdDiskAlgo() { LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo info: Creating an instance"; }
0052 
0053 DDPixFwdDiskAlgo::~DDPixFwdDiskAlgo() {}
0054 
0055 void DDPixFwdDiskAlgo::initialize(const DDNumericArguments& nArgs,
0056                                   const DDVectorArguments& vArgs,
0057                                   const DDMapArguments&,
0058                                   const DDStringArguments& sArgs,
0059                                   const DDStringVectorArguments& vsArgs) {
0060   startCopyNo = int(nArgs["StartCopyNo"]);
0061   nBlades = int(nArgs["NumberOfBlades"]);
0062   bladeAngle = nArgs["BladeAngle"];
0063   bladeTilt = nArgs["BladeTilt"];
0064   zPlane = nArgs["BladeCommonZ"];
0065   bladeZShift = vArgs["BladeZShift"];
0066   anchorR = nArgs["AnchorRadius"];
0067 
0068   idNameSpace = DDCurrentNamespace::ns();
0069   childName = sArgs["ChildName"];
0070   rotName = sArgs["RotationName"];
0071   flagString = sArgs["FlagString"];
0072   DDName parentName = parent().name();
0073   LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
0074                           << idNameSpace << "\tRot Name " << rotName << "\tCopyNo (Start/Total) " << startCopyNo << ", "
0075                           << nBlades << "\tAngles " << bladeAngle / CLHEP::deg << ", " << bladeTilt / CLHEP::deg
0076                           << "\tZshifts " << zPlane << "\tAmnchor Radius " << anchorR;
0077 
0078   for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
0079     LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo: Blade " << iBlade << " flag " << flagString[iBlade] << " zshift "
0080                             << bladeZShift[iBlade];
0081   }
0082 }
0083 
0084 void DDPixFwdDiskAlgo::execute(DDCompactView& cpv) {
0085   int copy = startCopyNo;
0086   DDName mother = parent().name();
0087   DDName child(DDSplit(childName).first, DDSplit(childName).second);
0088   string flagSelector = "Y";
0089 
0090   double deltaPhi = (360. / nBlades) * CLHEP::deg;
0091   string rotns = DDSplit(rotName).second;
0092   for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
0093     if (flagString[iBlade] == flagSelector[0]) {
0094       string rotstr = DDSplit(rotName).first + to_string(double(copy));
0095 
0096       double phi = (iBlade + 0.5) * deltaPhi;
0097       //      double phi  = (iBlade+0.5)*deltaPhi - 90.*CLHEP::deg;
0098       double phix = atan2(sin(phi) * cos(bladeAngle), cos(phi) * cos(bladeAngle));
0099       double thetx = acos(-sin(bladeAngle));
0100       double phiy = atan2((cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)),
0101                           (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)));
0102       double thety = acos(cos(bladeAngle) * sin(bladeTilt));
0103       double phiz = atan2((-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)),
0104                           (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)));
0105       double thetz = acos(cos(bladeAngle) * cos(bladeTilt));
0106       DDRotation rot = DDRotation(DDName(rotstr, rotns));
0107       if (!rot) {
0108         LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo test: Creating a new "
0109                                 << "rotation: " << rotstr << "\t" << thetx / CLHEP::deg << ", " << phix / CLHEP::deg
0110                                 << ", " << thety / CLHEP::deg << ", " << phiy / CLHEP::deg << ", " << thetz / CLHEP::deg
0111                                 << ", " << phiz / CLHEP::deg;
0112         LogDebug("TrackerGeom") << "Rotation Matrix (" << phi / CLHEP::deg << ", " << bladeAngle / CLHEP::deg << ", "
0113                                 << bladeTilt / CLHEP::deg << ") " << cos(phi) * cos(bladeAngle) << ", "
0114                                 << (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)) << ", "
0115                                 << (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)) << ", "
0116                                 << sin(phi) * cos(bladeAngle) << ", "
0117                                 << (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)) << ", "
0118                                 << (-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)) << ", "
0119                                 << -sin(bladeAngle) << ", " << cos(bladeAngle) * sin(bladeTilt) << ", "
0120                                 << cos(bladeAngle) * cos(bladeTilt);
0121         rot = DDrot(DDName(rotstr, rotns), thetx, phix, thety, phiy, thetz, phiz);
0122       }
0123       double xpos = anchorR * (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt));
0124       double ypos = anchorR * (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt));
0125       double zpos = anchorR * (cos(bladeAngle) * sin(bladeTilt)) + zPlane + bladeZShift[iBlade];
0126       DDTranslation tran(xpos, ypos, zpos);
0127       cpv.position(child, mother, copy, tran, rot);
0128       LogDebug("TrackerGeom") << "DDPixFwdDiskAlgo test: " << child << " number " << copy << " positioned in " << mother
0129                               << " at " << tran << " with " << rot;
0130     }
0131     copy++;
0132   }
0133 }
0134 
0135 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDPixFwdDiskAlgo, "track:DDPixFwdDiskAlgo");