CMS 3D CMS Logo

DDHGCalNoTaperEndcap.cc
Go to the documentation of this file.
2 #include "DD4hep/DetFactoryHelper.h"
7 
8 //#define EDM_ML_DEBUG
9 using namespace angle_units::operators;
10 
11 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
12  cms::DDNamespace ns(ctxt, e, true);
14  std::string motherName = args.parentName();
15 
16  auto const& m_tiltAngle = args.value<double>("tiltAngle"); // Tilt angle
17  auto const& m_rMin = args.value<double>("rMin"); // Inner radius
18  auto const& m_rMax = args.value<double>("rMax"); // Outer radius
19  auto const& m_zoffset = args.value<double>("zoffset"); // Offset in z
20  auto const& m_xyoffset = args.value<double>("xyoffset"); // Offset in x or y
21  auto const& m_startCopyNo = args.value<int>("startCopyNo"); // Start copy Number
22  auto const& m_incrCopyNo = args.value<int>("incrCopyNo"); // Increment copy Number
23  auto const& m_childName = args.value<std::string>("ChildName"); // Children name
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HGCalGeom") << "Tilt Angle " << m_tiltAngle << " R " << cms::convert2mm(m_rMin) << ":"
26  << cms::convert2mm(m_rMax) << " Offset " << cms::convert2mm(m_zoffset) << ":"
27  << cms::convert2mm(m_xyoffset) << " Copy " << m_startCopyNo << ":" << m_incrCopyNo
28  << " Child " << m_childName;
29 
30  edm::LogVerbatim("HGCalGeom") << "DDHGCalNoTaperEndcap: NameSpace " << ns.name() << "\tParent " << args.parentName();
31 #endif
32 
33  dd4hep::Volume parent = ns.volume(args.parentName());
34  std::string name = ns.prepend(m_childName);
35 
36  const int ix[4] = {1, -1, -1, 1};
37  const int iy[4] = {1, 1, -1, -1};
38  int copyNo = m_startCopyNo;
39  for (int i = 0; i < 4; ++i) {
40  int xQuadrant = ix[i];
41  int yQuadrant = iy[i];
42 #ifdef EDM_ML_DEBUG
43  edm::LogVerbatim("HGCalGeom") << "Create quarter " << xQuadrant << ":" << yQuadrant;
44 #endif
45  double tiltAngle = m_tiltAngle;
46  double xphi = xQuadrant * tiltAngle;
47  double yphi = yQuadrant * tiltAngle;
48  double theta = 90._deg;
49  double phiX = 0.0;
50  double phiY = theta;
51  double phiZ = 3 * theta;
52  double offsetZ = m_zoffset;
53  double offsetXY = m_xyoffset;
54  double offsetX = xQuadrant * 0.5 * offsetXY;
55  double offsetY = yQuadrant * 0.5 * offsetXY;
56 
57 #ifdef EDM_ML_DEBUG
58  int rowmax(0), column(0);
59 #endif
60  while (std::abs(offsetX) < m_rMax) {
61 #ifdef EDM_ML_DEBUG
62  column++;
63  int row(0);
64 #endif
65  while (std::abs(offsetY) < m_rMax) {
66 #ifdef EDM_ML_DEBUG
67  row++;
68 #endif
69  double limit1 = sqrt((offsetX + 0.5 * xQuadrant * offsetXY) * (offsetX + 0.5 * xQuadrant * offsetXY) +
70  (offsetY + 0.5 * yQuadrant * offsetXY) * (offsetY + 0.5 * yQuadrant * offsetXY));
71  double limit2 = sqrt((offsetX - 0.5 * xQuadrant * offsetXY) * (offsetX - 0.5 * xQuadrant * offsetXY) +
72  (offsetY - 0.5 * yQuadrant * offsetXY) * (offsetY - 0.5 * yQuadrant * offsetXY));
73  // Make sure we do not add supermodules in rMin area
74  if (limit2 > m_rMin && limit1 < m_rMax) {
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << m_childName << " copyNo = " << copyNo << " (" << column << "," << row
77  << "): offsetX,Y = " << cms::convert2mm(offsetX) << ","
78  << cms::convert2mm(offsetY) << " limit=" << cms::convert2mm(limit1) << ":"
79  << cms::convert2mm(limit2) << " rMin, rMax = " << cms::convert2mm(m_rMin) << ","
80  << cms::convert2mm(m_rMax);
81 #endif
82 
83  dd4hep::Rotation3D rotation = (cms::makeRotation3D(theta, phiX, theta + yphi, phiY, -yphi, phiZ) *
84  cms::makeRotation3D(theta + xphi, phiX, 90._deg, 90._deg, xphi, 0.0));
85 
86  dd4hep::Position tran(offsetX, offsetY, offsetZ);
87 #ifdef EDM_ML_DEBUG
88  edm::LogVerbatim("HGCalGeom") << "Module " << copyNo << ": location = (" << cms::convert2mm(offsetX) << ","
89  << cms::convert2mm(offsetY) << "," << cms::convert2mm(offsetZ) << ") Rotation "
90  << rotation;
91 #endif
92  parent.placeVolume(ns.volume(name), copyNo, dd4hep::Transform3D(rotation, tran));
93 
94  copyNo += m_incrCopyNo;
95  } else {
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("HGCalGeom") << " (" << column << "," << row << "): offsetX,Y = " << cms::convert2mm(offsetX)
98  << "," << cms::convert2mm(offsetY)
99  << " is out of limit=" << cms::convert2mm(limit1) << ":"
100  << cms::convert2mm(limit2) << " rMin, rMax = " << cms::convert2mm(m_rMin) << ","
101  << cms::convert2mm(m_rMax);
102 #endif
103  }
104  yphi += yQuadrant * 2. * tiltAngle;
105  offsetY += yQuadrant * offsetXY;
106  }
107 #ifdef EDM_ML_DEBUG
108  if (row > rowmax)
109  rowmax = row;
110 #endif
111  xphi += xQuadrant * 2. * tiltAngle;
112  yphi = yQuadrant * tiltAngle;
113  offsetY = yQuadrant * 0.5 * offsetXY;
114  offsetX += xQuadrant * offsetXY;
115  }
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("HGCalGeom") << rowmax << " rows and " << column << " columns in quadrant " << xQuadrant << ":"
118  << yQuadrant;
119 #endif
120  }
121 
122  return cms::s_executed;
123 }
124 
125 // first argument is the type from the xml file
126 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalNoTaperEndcap, algorithm)
Log< level::Info, true > LogVerbatim
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:23
std::string_view name() const
Definition: DDNamespace.h:79
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dd4hep::Volume Volume
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
Geom::Theta< T > theta() const
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99