Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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