Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:17

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/angle_units.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 using namespace angle_units::operators;
0008 
0009 //#define EDM_ML_DEBUG
0010 
0011 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0012   cms::DDNamespace ns(ctxt, e, true);
0013   cms::DDAlgoArguments args(ctxt, e);
0014 
0015   // Header section of original DDGEMAngular.h
0016   float startAngle = args.value<float>("startAngle");
0017   float stepAngle = args.value<float>("stepAngle");
0018   int invert = args.value<int>("invert");
0019   double rPos = args.value<double>("rPosition");
0020   double zoffset = args.value<double>("zoffset");
0021   int n = args.value<int>("n");
0022   int startCopyNo = args.value<int>("startCopyNo");
0023   int incrCopyNo = args.value<int>("incrCopyNo");
0024 #ifdef EDM_ML_DEBUG
0025   edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parameters for positioning-- " << n << " copies in steps of "
0026                                << convertRadToDeg(stepAngle) << " from " << convertRadToDeg(startAngle)
0027                                << " (inversion flag " << invert << ") \trPos " << cms::convert2mm(rPos) << " Zoffest "
0028                                << cms::convert2mm(zoffset) << "\tStart and inremental "
0029                                << "copy nos " << startCopyNo << ", " << incrCopyNo;
0030 #endif
0031   std::string childName = args.value<std::string>("ChildName");
0032   childName = ns.prepend(childName);
0033   std::string parentName = args.parentName();
0034   parentName = ns.prepend(parentName);
0035   dd4hep::Volume parent = ns.volume(parentName);
0036   dd4hep::Volume child = ns.volume(childName);
0037 #ifdef EDM_ML_DEBUG
0038   edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parent " << parentName << "\tChild " << child.name() << "\tNameSpace "
0039                                << ns.name();
0040 #endif
0041 
0042   // Now position child in mother *n* times
0043   double phi = startAngle;
0044   int copyNo = startCopyNo;
0045   double thetax = 90.0_deg;
0046   double thetay = invert == 0 ? 0.0 : 180.0_deg;
0047   for (int ii = 0; ii < n; ii++) {
0048     double phiz = phi;
0049     if (phiz >= 2._pi)
0050       phiz -= 2._pi;
0051     double phix = invert == 0 ? (90.0_deg + phiz) : (-90.0_deg + phiz);
0052 #ifdef EDM_ML_DEBUG
0053     edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Creating a rotation " << convertRadToDeg(thetax) << ", "
0054                                  << convertRadToDeg(phix) << ", " << convertRadToDeg(thetay) << ", 0, "
0055                                  << convertRadToDeg(thetax) << ", " << convertRadToDeg(phiz);
0056 #endif
0057     dd4hep::Rotation3D rotation = cms::makeRotation3D(thetax, phix, thetay, 0., thetax, phiz);
0058     dd4hep::Position tran(rPos * cos(phiz), rPos * sin(phiz), zoffset);
0059     parent.placeVolume(child, copyNo, dd4hep::Transform3D(rotation, tran));
0060 #ifdef EDM_ML_DEBUG
0061     edm::LogVerbatim("MuonGeom") << "DDGEMAngular: " << child.name() << " number " << copyNo << " positioned in "
0062                                  << parentName << " at (" << cms::convert2mm(rPos * cos(phiz)) << ","
0063                                  << cms::convert2mm(rPos * sin(phiz)) << "," << cms::convert2mm(zoffset) << ") with "
0064                                  << rotation;
0065 #endif
0066     phi += stepAngle;
0067     copyNo += incrCopyNo;
0068   }
0069   return cms::s_executed;
0070 }
0071 
0072 // first argument is the type from the xml file
0073 DECLARE_DDCMS_DETELEMENT(DDCMS_muon_DDGEMAngular, algorithm)