CMS 3D CMS Logo

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