Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:43

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHCalAngular.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 "DataFormats/Math/interface/angle_units.h"
0015 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0017 #include "DetectorDescription/Core/interface/DDTypes.h"
0018 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0019 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0020 
0021 //#define EDM_ML_DEBUG
0022 using namespace angle_units::operators;
0023 
0024 class DDHCalAngular : public DDAlgorithm {
0025 public:
0026   //Constructor and Destructor
0027   DDHCalAngular();
0028   ~DDHCalAngular() 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   double startAngle;  //Start angle
0040   double rangeAngle;  //Range angle
0041   double shiftY;      //Shift along Y
0042   double shiftX;      //Shift along X
0043   double zoffset;     //Offset in z
0044   int n;              //Mumber of copies
0045   int startCopyNo;    //Start copy Number
0046   int incrCopyNo;     //Increment copy Number
0047 
0048   std::string rotns;        //Namespace for rotation matrix
0049   std::string idNameSpace;  //Namespace of this and ALL sub-parts
0050   std::string childName;    //Children name
0051 };
0052 
0053 DDHCalAngular::DDHCalAngular() {
0054 #ifdef EDM_ML_DEBUG
0055   edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Creating an instance";
0056 #endif
0057 }
0058 
0059 DDHCalAngular::~DDHCalAngular() {}
0060 
0061 void DDHCalAngular::initialize(const DDNumericArguments& nArgs,
0062                                const DDVectorArguments&,
0063                                const DDMapArguments&,
0064                                const DDStringArguments& sArgs,
0065                                const DDStringVectorArguments&) {
0066   startAngle = nArgs["startAngle"];
0067   rangeAngle = nArgs["rangeAngle"];
0068   shiftX = nArgs["shiftX"];
0069   shiftY = nArgs["shiftY"];
0070   zoffset = nArgs["zoffset"];
0071   n = int(nArgs["n"]);
0072   startCopyNo = int(nArgs["startCopyNo"]);
0073   incrCopyNo = int(nArgs["incrCopyNo"]);
0074 #ifdef EDM_ML_DEBUG
0075   edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parameters for positioning "
0076                                << "-- " << n << " copies in " << convertRadToDeg(rangeAngle) << " from "
0077                                << convertRadToDeg(startAngle) << "\tShifts " << shiftX << ", " << shiftY
0078                                << " along x, y axes; \tZoffest " << zoffset << "\tStart and inremental copy nos "
0079                                << startCopyNo << ", " << incrCopyNo;
0080 #endif
0081   rotns = sArgs["RotNameSpace"];
0082   idNameSpace = DDCurrentNamespace::ns();
0083   childName = sArgs["ChildName"];
0084 #ifdef EDM_ML_DEBUG
0085   DDName parentName = parent().name();
0086   edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parent " << parentName << "\tChild " << childName << "\tNameSpace "
0087                                << idNameSpace << "\tRotation Namespace " << rotns;
0088 #endif
0089 }
0090 
0091 void DDHCalAngular::execute(DDCompactView& cpv) {
0092   double dphi = rangeAngle / n;
0093   double phix = startAngle;
0094   int copyNo = startCopyNo;
0095   double theta = 90._deg;
0096   for (int ii = 0; ii < n; ii++) {
0097     double phiy = phix + 90._deg;
0098     DDRotation rotation;
0099     std::string rotstr("NULL");
0100 
0101     static const double tol = 0.1;
0102     if (std::abs(phix) > tol) {
0103       rotstr = "R" + formatAsDegreesInInteger(phix);
0104       rotation = DDRotation(DDName(rotstr, rotns));
0105       if (!rotation) {
0106 #ifdef EDM_ML_DEBUG
0107         edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Creating a rotation " << DDName(rotstr, idNameSpace) << "\t90, "
0108                                      << convertRadToDeg(phix) << ", 90, " << (90 + convertRadToDeg(phix)) << ", 0, 0";
0109 #endif
0110         rotation = DDrot(DDName(rotstr, rotns), theta, phix, theta, phiy, 0, 0);
0111       }
0112     }
0113 
0114     double xpos = shiftX * cos(phix) - shiftY * sin(phix);
0115     double ypos = shiftX * sin(phix) + shiftY * cos(phix);
0116     DDTranslation tran(xpos, ypos, zoffset);
0117 
0118     DDName parentName = parent().name();
0119     cpv.position(DDName(childName, idNameSpace), parentName, copyNo, tran, rotation);
0120 #ifdef EDM_ML_DEBUG
0121     edm::LogVerbatim("HCalGeom") << "DDHCalAngular: " << DDName(childName, idNameSpace) << " number " << copyNo
0122                                  << " positioned in " << parentName << " at " << tran << " with " << rotation;
0123 #endif
0124     phix += dphi;
0125     copyNo += incrCopyNo;
0126   }
0127 }
0128 
0129 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalAngular, "hcal:DDHCalAngular");