Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 13:03:22

0001 #include "DataFormats/Math/interface/angle_units.h"
0002 #include "DD4hep/DetFactoryHelper.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 
0008 //#define EDM_ML_DEBUG
0009 using namespace angle_units::operators;
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   std::string motherName = args.parentName();
0015 
0016   auto const& m_tiltAngle = args.value<double>("tiltAngle");       // Tilt  angle
0017   auto const& m_rMin = args.value<double>("rMin");                 // Inner radius
0018   auto const& m_rMax = args.value<double>("rMax");                 // Outer radius
0019   auto const& m_zoffset = args.value<double>("zoffset");           // Offset in z
0020   auto const& m_xyoffset = args.value<double>("xyoffset");         // Offset in x or y
0021   auto const& m_startCopyNo = args.value<int>("startCopyNo");      // Start copy Number
0022   auto const& m_incrCopyNo = args.value<int>("incrCopyNo");        // Increment copy Number
0023   auto const& m_childName = args.value<std::string>("ChildName");  // Children name
0024 #ifdef EDM_ML_DEBUG
0025   edm::LogVerbatim("HGCalGeom") << "Tilt Angle " << m_tiltAngle << " R " << cms::convert2mm(m_rMin) << ":"
0026                                 << cms::convert2mm(m_rMax) << " Offset " << cms::convert2mm(m_zoffset) << ":"
0027                                 << cms::convert2mm(m_xyoffset) << " Copy " << m_startCopyNo << ":" << m_incrCopyNo
0028                                 << " Child " << m_childName;
0029 
0030   edm::LogVerbatim("HGCalGeom") << "DDHGCalNoTaperEndcap: NameSpace " << ns.name() << "\tParent " << args.parentName();
0031 #endif
0032 
0033   dd4hep::Volume parent = ns.volume(args.parentName());
0034   std::string name = ns.prepend(m_childName);
0035 
0036   const int ix[4] = {1, -1, -1, 1};
0037   const int iy[4] = {1, 1, -1, -1};
0038   int copyNo = m_startCopyNo;
0039   for (int i = 0; i < 4; ++i) {
0040     int xQuadrant = ix[i];
0041     int yQuadrant = iy[i];
0042 #ifdef EDM_ML_DEBUG
0043     edm::LogVerbatim("HGCalGeom") << "Create quarter " << xQuadrant << ":" << yQuadrant;
0044 #endif
0045     double tiltAngle = m_tiltAngle;
0046     double xphi = xQuadrant * tiltAngle;
0047     double yphi = yQuadrant * tiltAngle;
0048     double theta = 90._deg;
0049     double phiX = 0.0;
0050     double phiY = theta;
0051     double phiZ = 3 * theta;
0052     double offsetZ = m_zoffset;
0053     double offsetXY = m_xyoffset;
0054     double offsetX = xQuadrant * 0.5 * offsetXY;
0055     double offsetY = yQuadrant * 0.5 * offsetXY;
0056 
0057 #ifdef EDM_ML_DEBUG
0058     int rowmax(0), column(0);
0059 #endif
0060     while (std::abs(offsetX) < m_rMax) {
0061 #ifdef EDM_ML_DEBUG
0062       column++;
0063       int row(0);
0064 #endif
0065       while (std::abs(offsetY) < m_rMax) {
0066 #ifdef EDM_ML_DEBUG
0067         row++;
0068 #endif
0069         double limit1 = sqrt((offsetX + 0.5 * xQuadrant * offsetXY) * (offsetX + 0.5 * xQuadrant * offsetXY) +
0070                              (offsetY + 0.5 * yQuadrant * offsetXY) * (offsetY + 0.5 * yQuadrant * offsetXY));
0071         double limit2 = sqrt((offsetX - 0.5 * xQuadrant * offsetXY) * (offsetX - 0.5 * xQuadrant * offsetXY) +
0072                              (offsetY - 0.5 * yQuadrant * offsetXY) * (offsetY - 0.5 * yQuadrant * offsetXY));
0073         // Make sure we do not add supermodules in rMin area
0074         if (limit2 > m_rMin && limit1 < m_rMax) {
0075 #ifdef EDM_ML_DEBUG
0076           edm::LogVerbatim("HGCalGeom") << m_childName << " copyNo = " << copyNo << " (" << column << "," << row
0077                                         << "): offsetX,Y = " << cms::convert2mm(offsetX) << ","
0078                                         << cms::convert2mm(offsetY) << " limit=" << cms::convert2mm(limit1) << ":"
0079                                         << cms::convert2mm(limit2) << " rMin, rMax = " << cms::convert2mm(m_rMin) << ","
0080                                         << cms::convert2mm(m_rMax);
0081 #endif
0082 
0083           dd4hep::Rotation3D rotation = (cms::makeRotation3D(theta, phiX, theta + yphi, phiY, -yphi, phiZ) *
0084                                          cms::makeRotation3D(theta + xphi, phiX, 90._deg, 90._deg, xphi, 0.0));
0085 
0086           dd4hep::Position tran(offsetX, offsetY, offsetZ);
0087 #ifdef EDM_ML_DEBUG
0088           edm::LogVerbatim("HGCalGeom") << "Module " << copyNo << ": location = (" << cms::convert2mm(offsetX) << ","
0089                                         << cms::convert2mm(offsetY) << "," << cms::convert2mm(offsetZ) << ") Rotation "
0090                                         << rotation;
0091 #endif
0092           parent.placeVolume(ns.volume(name), copyNo, dd4hep::Transform3D(rotation, tran));
0093 
0094           copyNo += m_incrCopyNo;
0095         } else {
0096 #ifdef EDM_ML_DEBUG
0097           edm::LogVerbatim("HGCalGeom") << " (" << column << "," << row << "): offsetX,Y = " << cms::convert2mm(offsetX)
0098                                         << "," << cms::convert2mm(offsetY)
0099                                         << " is out of limit=" << cms::convert2mm(limit1) << ":"
0100                                         << cms::convert2mm(limit2) << " rMin, rMax = " << cms::convert2mm(m_rMin) << ","
0101                                         << cms::convert2mm(m_rMax);
0102 #endif
0103         }
0104         yphi += yQuadrant * 2. * tiltAngle;
0105         offsetY += yQuadrant * offsetXY;
0106       }
0107 #ifdef EDM_ML_DEBUG
0108       if (row > rowmax)
0109         rowmax = row;
0110 #endif
0111       xphi += xQuadrant * 2. * tiltAngle;
0112       yphi = yQuadrant * tiltAngle;
0113       offsetY = yQuadrant * 0.5 * offsetXY;
0114       offsetX += xQuadrant * offsetXY;
0115     }
0116 #ifdef EDM_ML_DEBUG
0117     edm::LogVerbatim("HGCalGeom") << rowmax << " rows and " << column << " columns in quadrant " << xQuadrant << ":"
0118                                   << yQuadrant;
0119 #endif
0120   }
0121 
0122   return cms::s_executed;
0123 }
0124 
0125 // first argument is the type from the xml file
0126 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalNoTaperEndcap, algorithm)