Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 13:02:57

0001 #include <cmath>
0002 #include <algorithm>
0003 #include <map>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "DataFormats/Math/interface/GeantUnits.h"
0008 #include "DataFormats/GeometryVector/interface/Phi.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/PluginManager/interface/PluginFactory.h"
0011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0012 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0013 #include "DetectorDescription/Core/interface/DDTypes.h"
0014 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0015 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0016 
0017 using namespace geant_units::operators;
0018 
0019 //#define EDM_ML_DEBUG
0020 
0021 class DDTotemAngular : public DDAlgorithm {
0022 public:
0023   //Constructor and Destructor
0024   DDTotemAngular();
0025 
0026   void initialize(const DDNumericArguments& nArgs,
0027                   const DDVectorArguments& vArgs,
0028                   const DDMapArguments& mArgs,
0029                   const DDStringArguments& sArgs,
0030                   const DDStringVectorArguments& vsArgs) override;
0031 
0032   void execute(DDCompactView& cpv) override;
0033 
0034 private:
0035   double startAngle_;  //Start angle
0036   double stepAngle_;   //Step  angle
0037   double zoffset_;     //Offset in z
0038   double roffset_;     //Offset in R
0039   int n_;              //Number of copies
0040   int startCopyNo_;    //Start copy Number
0041   int incrCopyNo_;     //Increment copy Number
0042 
0043   std::string rotns_;        //Namespace for rotation matrix
0044   std::string idNameSpace_;  //Namespace of this and ALL sub-parts
0045   std::string childName_;    //Children name
0046 };
0047 
0048 DDTotemAngular::DDTotemAngular() {
0049 #ifdef EDM_ML_DEBUG
0050   edm::LogVerbatim("ForwardGeom") << "DDTotemAngular: Creating an instance";
0051 #endif
0052 }
0053 
0054 void DDTotemAngular::initialize(const DDNumericArguments& nArgs,
0055                                 const DDVectorArguments&,
0056                                 const DDMapArguments&,
0057                                 const DDStringArguments& sArgs,
0058                                 const DDStringVectorArguments&) {
0059   startAngle_ = nArgs["startAngle"];
0060   stepAngle_ = nArgs["stepAngle"];
0061   zoffset_ = nArgs["zoffset"];
0062   roffset_ = nArgs["roffset"];
0063   n_ = int(nArgs["n"]);
0064   startCopyNo_ = int(nArgs["startCopyNo"]);
0065   incrCopyNo_ = int(nArgs["incrCopyNo"]);
0066 #ifdef EDM_ML_DEBUG
0067   edm::LogVerbatim("ForwardGeom") << "DDTotemAngular: Parameters for positioning-- " << n_ << " copies in steps of "
0068                                   << convertRadToDeg(stepAngle_) << " from " << convertRadToDeg(startAngle_)
0069                                   << " \tZoffset " << zoffset_ << " \tRoffset " << roffset_
0070                                   << "\tStart and inremental copy nos " << startCopyNo_ << ", " << incrCopyNo_;
0071 #endif
0072   rotns_ = sArgs["RotNameSpace"];
0073   idNameSpace_ = DDCurrentNamespace::ns();
0074   childName_ = sArgs["ChildName"];
0075 #ifdef EDM_ML_DEBUG
0076   edm::LogVerbatim("ForwardGeom") << "DDTotemAngular debug: Parent " << parent().name() << "\tChild " << childName_
0077                                   << "\tNameSpace " << idNameSpace_ << "\tRotation Namespace " << rotns_;
0078 #endif
0079 }
0080 
0081 void DDTotemAngular::execute(DDCompactView& cpv) {
0082   double phi = startAngle_;
0083   int copyNo = startCopyNo_;
0084 
0085   for (int ii = 0; ii < n_; ii++) {
0086     Geom::Phi0To2pi<double> phitmp = phi;
0087     DDRotation rotation;
0088     std::string rotstr("NULL");
0089 
0090     rotstr = "RT" + formatAsDegrees(phitmp);
0091     rotation = DDRotation(DDName(rotstr, rotns_));
0092     if (!rotation) {
0093 #ifdef EDM_ML_DEBUG
0094       edm::LogVerbatim("ForwardGeom") << "DDTotemAngular: Creating a new rotation " << DDName(rotstr, rotns_)
0095                                       << "\t90, " << convertRadToDeg(phitmp + 90._deg) << ", 0, 0, 90, "
0096                                       << convertRadToDeg(phitmp);
0097 #endif
0098       rotation = DDrot(DDName(rotstr, rotns_), 90._deg, 90._deg + phitmp, 0., 0., 90._deg, phitmp);
0099     }
0100 
0101     DDTranslation tran(roffset_ * cos(phi), roffset_ * sin(phi), zoffset_);
0102 
0103     DDName parentName = parent().name();
0104     cpv.position(DDName(childName_, idNameSpace_), parentName, copyNo, tran, rotation);
0105 #ifdef EDM_ML_DEBUG
0106     edm::LogVerbatim("ForwardGeom") << "DDTotemAngular: " << DDName(childName_, idNameSpace_) << " number " << copyNo
0107                                     << " positioned in " << parentName << " at " << tran << " with " << rotstr << " "
0108                                     << rotation;
0109 #endif
0110     phi += stepAngle_;
0111     copyNo += incrCopyNo_;
0112   }
0113 }
0114 
0115 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTotemAngular, "forward:DDTotemAngular");