Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTECPhiAltAlgo.cc
0003 // Description: Position n copies inside and outside Z at alternate phi 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/GlobalPhysicalConstants.h"
0013 #include "CLHEP/Units/GlobalSystemOfUnits.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 DDTECPhiAltAlgo : public DDAlgorithm {
0024 public:
0025   //Constructor and Destructor
0026   DDTECPhiAltAlgo();
0027   ~DDTECPhiAltAlgo() 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   double startAngle;  //Start angle
0039   double incrAngle;   //Increment in angle
0040   double radius;      //Radius
0041   double zIn;         //z position for the even ones
0042   double zOut;        //z position for the odd  ones
0043   int number;         //Number of copies
0044   int startCopyNo;    //Start copy number
0045   int incrCopyNo;     //Increment in copy number
0046 
0047   string idNameSpace;  //Namespace of this and ALL sub-parts
0048   string childName;    //Child name
0049 };
0050 
0051 DDTECPhiAltAlgo::DDTECPhiAltAlgo() { LogDebug("TECGeom") << "DDTECPhiAltAlgo info: Creating an instance"; }
0052 
0053 DDTECPhiAltAlgo::~DDTECPhiAltAlgo() {}
0054 
0055 void DDTECPhiAltAlgo::initialize(const DDNumericArguments& nArgs,
0056                                  const DDVectorArguments&,
0057                                  const DDMapArguments&,
0058                                  const DDStringArguments& sArgs,
0059                                  const DDStringVectorArguments&) {
0060   startAngle = nArgs["StartAngle"];
0061   incrAngle = nArgs["IncrAngle"];
0062   radius = nArgs["Radius"];
0063   zIn = nArgs["ZIn"];
0064   zOut = nArgs["ZOut"];
0065   number = int(nArgs["Number"]);
0066   startCopyNo = int(nArgs["StartCopyNo"]);
0067   incrCopyNo = int(nArgs["IncrCopyNo"]);
0068 
0069   LogDebug("TECGeom") << "DDTECPhiAltAlgo debug: Parameters for "
0070                       << "positioning--"
0071                       << "\tStartAngle " << startAngle / CLHEP::deg << "\tIncrAngle " << incrAngle / CLHEP::deg
0072                       << "\tRadius " << radius << "\tZ in/out " << zIn << ", " << zOut << "\tCopy Numbers " << number
0073                       << " Start/Increment " << startCopyNo << ", " << incrCopyNo;
0074 
0075   idNameSpace = DDCurrentNamespace::ns();
0076   childName = sArgs["ChildName"];
0077   DDName parentName = parent().name();
0078   LogDebug("TECGeom") << "DDTECPhiAltAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
0079                       << idNameSpace;
0080 }
0081 
0082 void DDTECPhiAltAlgo::execute(DDCompactView& cpv) {
0083   if (number > 0) {
0084     double theta = 90. * CLHEP::deg;
0085     int copyNo = startCopyNo;
0086 
0087     DDName mother = parent().name();
0088     DDName child(DDSplit(childName).first, DDSplit(childName).second);
0089     for (int i = 0; i < number; i++) {
0090       double phiz = startAngle + i * incrAngle;
0091       double phix = phiz + 90. * CLHEP::deg;
0092       double phideg = phiz / CLHEP::deg;
0093 
0094       DDRotation rotation;
0095       string rotstr = DDSplit(childName).first + to_string(phideg * 10.);
0096       rotation = DDRotation(DDName(rotstr, idNameSpace));
0097       if (!rotation) {
0098         LogDebug("TECGeom") << "DDTECPhiAltAlgo test: Creating a new "
0099                             << "rotation " << rotstr << "\t" << theta / CLHEP::deg << ", " << phix / CLHEP::deg
0100                             << ", 0, 0, " << theta / CLHEP::deg << ", " << phiz / CLHEP::deg;
0101         rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, 0., 0., theta, phiz);
0102       }
0103 
0104       double xpos = radius * cos(phiz);
0105       double ypos = radius * sin(phiz);
0106       double zpos;
0107       if (i % 2 == 0)
0108         zpos = zIn;
0109       else
0110         zpos = zOut;
0111       DDTranslation tran(xpos, ypos, zpos);
0112 
0113       cpv.position(child, mother, copyNo, tran, rotation);
0114       LogDebug("TECGeom") << "DDTECPhiAltAlgo test: " << child << " number " << copyNo << " positioned in " << mother
0115                           << " at " << tran << " with " << rotation;
0116       copyNo += incrCopyNo;
0117     }
0118   }
0119 }
0120 
0121 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTECPhiAltAlgo, "track:DDTECPhiAltAlgo");