CMS 3D CMS Logo

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