Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-17 03:27:09

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDMuonAngular.cc
0003 // Description: Position inside the mother according to (eta,phi)
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/PluginManager/interface/PluginFactory.h"
0014 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0015 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0016 #include "DataFormats/Math/interface/angle_units.h"
0017 #include "DetectorDescription/Core/interface/DDTypes.h"
0018 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0019 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0020 
0021 using namespace angle_units::operators;
0022 
0023 //#define EDM_ML_DEBUG
0024 
0025 class DDMuonAngular : public DDAlgorithm {
0026 public:
0027   //Constructor and Destructor
0028   DDMuonAngular();
0029   ~DDMuonAngular() override;
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 startAngle;  //Start angle
0041   double stepAngle;   //Step  angle
0042   double zoffset;     //Offset in z
0043   int n;              //Mumber of copies
0044   int startCopyNo;    //Start copy Number
0045   int incrCopyNo;     //Increment copy Number
0046 
0047   std::string rotns;        //Namespace for rotation matrix
0048   std::string idNameSpace;  //Namespace of this and ALL sub-parts
0049   std::string childName;    //Children name
0050 };
0051 
0052 DDMuonAngular::DDMuonAngular() {
0053 #ifdef EDM_ML_DEBUG
0054   edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Creating an instance";
0055 #endif
0056 }
0057 
0058 DDMuonAngular::~DDMuonAngular() {}
0059 
0060 void DDMuonAngular::initialize(const DDNumericArguments& nArgs,
0061                                const DDVectorArguments&,
0062                                const DDMapArguments&,
0063                                const DDStringArguments& sArgs,
0064                                const DDStringVectorArguments&) {
0065   startAngle = nArgs["startAngle"];
0066   stepAngle = nArgs["stepAngle"];
0067   zoffset = nArgs["zoffset"];
0068   n = int(nArgs["n"]);
0069   startCopyNo = int(nArgs["startCopyNo"]);
0070   incrCopyNo = int(nArgs["incrCopyNo"]);
0071 #ifdef EDM_ML_DEBUG
0072   edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Parameters for positioning-- " << n << " copies in steps of "
0073                                << convertRadToDeg(stepAngle) << " from " << convertRadToDeg(startAngle) << " \tZoffest "
0074                                << zoffset << "\tStart and inremental copy nos " << startCopyNo << ", " << incrCopyNo;
0075 #endif
0076   rotns = sArgs["RotNameSpace"];
0077   idNameSpace = DDCurrentNamespace::ns();
0078   childName = sArgs["ChildName"];
0079 #ifdef EDM_ML_DEBUG
0080   edm::LogVerbatim("MuonGeom") << "DDMuonAngular debug: Parent " << parent().name() << "\tChild " << childName
0081                                << "\tNameSpace " << idNameSpace << "\tRotation Namespace " << rotns;
0082 #endif
0083 }
0084 
0085 void DDMuonAngular::execute(DDCompactView& cpv) {
0086   double phi = startAngle;
0087   int copyNo = startCopyNo;
0088 
0089   for (int ii = 0; ii < n; ii++) {
0090     double phitmp = phi;
0091     if (phitmp >= 2._pi)
0092       phitmp -= 2._pi;
0093     DDRotation rotation;
0094     std::string rotstr("NULL");
0095 
0096     if (std::abs(phitmp) >= 1.0_deg) {
0097       rotstr = "R" + formatAsDegrees(phitmp);
0098       rotation = DDRotation(DDName(rotstr, rotns));
0099       if (!rotation) {
0100 #ifdef EDM_ML_DEBUG
0101         edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Creating a new rotation " << DDName(rotstr, idNameSpace)
0102                                      << "\t90, " << convertRadToDeg(phitmp) << ", 90, "
0103                                      << convertRadToDeg(phitmp + 90._deg) << ", 0, 0";
0104 #endif
0105         rotation = DDrot(DDName(rotstr, rotns), 90._deg, phitmp, 90._deg, 90._deg + phitmp, 0., 0.);
0106       }
0107     }
0108 
0109     DDTranslation tran(0, 0, zoffset);
0110 
0111     DDName parentName = parent().name();
0112     cpv.position(DDName(childName, idNameSpace), parentName, copyNo, tran, rotation);
0113 #ifdef EDM_ML_DEBUG
0114     edm::LogVerbatim("MuonGeom") << "DDMuonAngular: " << DDName(childName, idNameSpace) << " number " << copyNo
0115                                  << " positioned in " << parentName << " at " << tran << " with " << rotstr << " "
0116                                  << rotation;
0117 #endif
0118     phi += stepAngle;
0119     copyNo += incrCopyNo;
0120   }
0121 }
0122 
0123 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDMuonAngular, "muon:DDMuonAngular");