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 //#define EDM_ML_DEBUG
0008 
0009 using namespace angle_units::operators;
0010 
0011 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& context, xml_h element) {
0012   cms::DDNamespace ns(context, element, true);
0013   cms::DDAlgoArguments args(context, element);
0014 
0015   int n = args.value<int>("n");
0016   int startCopyNo = args.find("startCopyNo") ? args.value<int>("startCopyNo") : 1;
0017   int incrCopyNo = args.find("incrCopyNo") ? args.value<int>("incrCopyNo") : 1;
0018   float startAngle = args.value<float>("startAngle");
0019   float stepAngle = args.value<float>("stepAngle");
0020   float zoffset = args.value<float>("zoffset");
0021   std::string rotns = args.value<std::string>("RotNameSpace");
0022   dd4hep::Volume mother = ns.volume(args.parentName());
0023   std::string childName = args.value<std::string>("ChildName");
0024   childName = ns.prepend(childName);
0025   dd4hep::Volume child = ns.volume(childName);
0026 
0027 #ifdef EDM_ML_DEBUG
0028   edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Parameters for positioning:: n " << n << " Start, Step "
0029                                << convertRadToDeg(startAngle) << ", " << convertRadToDeg(stepAngle) << ", zoffset "
0030                                << cms::convert2mm(zoffset) << ", RotNameSpace " << rotns;
0031   edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Parent " << mother.name() << "\tChild " << child.name()
0032                                << " NameSpace " << ns.name();
0033 #endif
0034   double phi = startAngle;
0035   int copyNo = startCopyNo;
0036 
0037   for (int i = 0; i < n; ++i) {
0038     double phitmp = phi;
0039     if (phitmp >= 2._pi)
0040       phitmp -= 2._pi;
0041     dd4hep::Rotation3D rotation = cms::makeRotation3D(90._deg, phitmp, 90._deg, 90._deg + phitmp, 0., 0.);
0042     std::string rotstr = ns.nsName(child.name()) + std::to_string(phitmp * 10.);
0043     auto irot = context.rotations.find(ns.prepend(rotstr));
0044     if (irot != context.rotations.end()) {
0045       rotation = ns.rotation(ns.prepend(rotstr));
0046     }
0047     dd4hep::Position tran(0., 0., zoffset);
0048     mother.placeVolume(child, copyNo, dd4hep::Transform3D(rotation, tran));
0049 #ifdef EDM_ML_DEBUG
0050     edm::LogVerbatim("MuonGeom") << "DDMuonAngular:" << child.name() << " number " << copyNo << " positioned in "
0051                                  << mother.name() << " at (0,0," << cms::convert2mm(zoffset) << ") with " << rotstr
0052                                  << ": " << rotation;
0053 #endif
0054     phi += stepAngle;
0055     copyNo += incrCopyNo;
0056   }
0057   return cms::s_executed;
0058 }
0059 
0060 // first argument is the type from the xml file
0061 DECLARE_DDCMS_DETELEMENT(DDCMS_muon_DDMuonAngular, algorithm)