CMS 3D CMS Logo

DDHGCalWafer.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 
8 using namespace cms_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 nsName = static_cast<std::string>(ns.name());
17  // Header section of original DDHGCalWafer.h
18  double waferSize = args.value<double>("WaferSize");
19  int cellType = args.value<int>("CellType");
20  int nColumns = args.value<int>("NColumns");
21  int nBottomY = args.value<int>("NBottomY");
22  std::vector<std::string> childNames = args.value<std::vector<std::string> >("ChildNames");
23  std::vector<int> nCellsRow = args.value<std::vector<int> >("NCellsRow");
24  std::vector<int> angleEdges = args.value<std::vector<int> >("AngleEdges");
25  std::vector<int> detectorType = args.value<std::vector<int> >("DetectorType");
26  std::string parentName = args.parentName();
27  dd4hep::Volume mother = ns.volume(args.parentName());
28 #ifdef EDM_ML_DEBUG
29  edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
30  << " positioned in " << nCellsRow.size() << " rows and " << nColumns
31  << " columns with lowest column at " << nBottomY << " in mother " << parentName
32  << " of size " << waferSize;
33  for (unsigned int k = 0; k < nCellsRow.size(); ++k)
34  edm::LogVerbatim("HGCalGeom") << "[" << k << "] Ncells " << nCellsRow[k] << " Edge rotations " << angleEdges[2 * k]
35  << ":" << angleEdges[2 * k + 1] << " Type of edge cells " << detectorType[2 * k]
36  << ":" << detectorType[2 * k + 1];
37 #endif
38 
39  static const int incAlongX = 2;
40  static const int incAlongY = 6;
41  double dx = 0.5 * waferSize / nColumns;
42  double dy = 0.5 * dx * tan(30._deg);
43  int ny = nBottomY;
44  int kount(0);
45 
46  for (unsigned int ir = 0; ir < nCellsRow.size(); ++ir) {
47  int nx = 1 - nCellsRow[ir];
48  double ypos = dy * ny;
49  for (int ic = 0; ic < nCellsRow[ir]; ++ic) {
50  std::string name(childNames[0]);
51  int irot(0);
52  if (ic == 0) {
53  name = childNames[detectorType[2 * ir]];
54  irot = angleEdges[2 * ir];
55  } else if (ic + 1 == nCellsRow[ir]) {
56  name = childNames[detectorType[2 * ir + 1]];
57  irot = angleEdges[2 * ir + 1];
58  }
59  dd4hep::Rotation3D rotation;
60  if (irot != 0) {
61 #ifdef EDM_ML_DEBUG
62  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating "
63  << "rotation "
64  << "\t90, " << irot << ", 90, " << (irot + 90) << ", 0, 0";
65 #endif
66  double phix = convertDegToRad(irot);
67  double phiy = convertDegToRad(90 + irot);
68  rotation = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);
69  }
70  std::string namx = nsName + name;
71  double xpos = dx * nx;
72  nx += incAlongX;
73  dd4hep::Position tran(xpos, ypos, 0);
74  int copy = cellType * 1000 + kount;
75  mother.placeVolume(ns.volume(namx), copy, dd4hep::Transform3D(rotation, tran));
76  ++kount;
77 #ifdef EDM_ML_DEBUG
78  edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: " << name << " number " << copy << " positioned in " << parentName
79  << " at " << tran << " with " << rotation;
80 #endif
81  }
82  ny += incAlongY;
83  }
84  return 1;
85 }
86 
87 // first argument is the type from the xml file
88 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWafer, algorithm)
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:184
constexpr long double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
T value(const std::string &name) const
dd4hep::Rotation3D makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
std::string_view name() const
Definition: DDNamespace.h:68
Tan< T >::type tan(const T &t)
Definition: Tan.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.
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Definition: DDHGCalWafer.cc:10