Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/Math/interface/angle_units.h"
0002 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0003 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "DD4hep/DetFactoryHelper.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 using namespace angle_units::operators;
0009 
0010 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0011   cms::DDNamespace ns(ctxt, e, true);
0012   cms::DDAlgoArguments args(ctxt, e);
0013   // Header section of original DDHCalAngular.h
0014   int n = args.value<int>("n");
0015   int startCopyNo = args.value<int>("startCopyNo");
0016   int incrCopyNo = args.value<int>("incrCopyNo");
0017   double rangeAngle = args.value<double>("rangeAngle");  //Angular range
0018   double startAngle = args.value<double>("startAngle");  //Start anle
0019   double shiftX = args.value<double>("shiftX");          //x Shift
0020   double shiftY = args.value<double>("shiftY");          //y Shift
0021   double zoffset = args.value<double>("zoffset");        //z offset
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   // Increment
0028   double dphi = rangeAngle / n;
0029 #ifdef EDM_ML_DEBUG
0030   edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parameters for positioning::"
0031                                << " n " << n << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
0032                                << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(dphi) << " Shift "
0033                                << cms::convert2mm(shiftX) << ":" << cms::convert2mm(shiftY) << "\n Parent "
0034                                << mother.name() << "\tChild " << child.name() << " NameSpace " << ns.name();
0035 #endif
0036   int copy = startCopyNo;
0037   double phix = startAngle;
0038   for (int ii = 0; ii < n; ++ii) {
0039     if (phix >= 2._pi)
0040       phix -= 2._pi;
0041     else if (phix < 0)
0042       phix += 2._pi;
0043     dd4hep::Rotation3D rotation;
0044     if (std::abs(phix) >= 0.1_deg) {
0045 #ifdef EDM_ML_DEBUG
0046       edm::LogVerbatim("HCalGeom") << "DDHCalAngular::Creating a rotation:"
0047                                    << "\t90., " << convertRadToDeg(phix) << ", 90.," << (90.0 + convertRadToDeg(phix))
0048                                    << ", 0, 0";
0049 #endif
0050       rotation = dd4hep::RotationZ(phix);
0051     }
0052 
0053     double xpos = shiftX * cos(phix) - shiftY * sin(phix);
0054     double ypos = shiftX * sin(phix) + shiftY * cos(phix);
0055     dd4hep::Position tran(xpos, ypos, zoffset);
0056     mother.placeVolume(child, copy, dd4hep::Transform3D(rotation, tran));
0057 #ifdef EDM_ML_DEBUG
0058     edm::LogVerbatim("HCalGeom") << "DDHCalAngular:: " << child.name() << " number " << copy << " positioned in "
0059                                  << mother.name() << " at (" << cms::convert2mm(xpos) << ", " << cms::convert2mm(ypos)
0060                                  << ", " << cms::convert2mm(zoffset) << ") with rotation matrix: " << rotation;
0061 #endif
0062     copy += incrCopyNo;
0063     phix += dphi;
0064   }
0065   return cms::s_executed;
0066 }
0067 
0068 // first argument is the type from the xml file
0069 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalAngular, algorithm)