CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDHGCalWaferAlgo.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 
15  // Header section of original DDHGCalWafer.h
16  const auto& cellSize = args.value<double>("CellSize"); // Cell Size
17  const auto& cellType = args.value<int>("CellType"); // Type (1 fine; 2 coarse)
18  const auto& childNames = args.value<std::vector<std::string> >("ChildNames"); // Names of children
19  const auto& positionX = args.value<std::vector<int> >("PositionX"); // Position in X
20  const auto& positionY = args.value<std::vector<int> >("PositionY"); // Position in Y
21  const auto& angles = args.value<std::vector<double> >("Angles"); // Rotation angle
22  const auto& detectorType = args.value<std::vector<int> >("DetectorType"); // Detector type
23 #ifdef EDM_ML_DEBUG
24  edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
25  << " positioned " << positionX.size() << " times with cell size " << cellSize;
26  for (unsigned int k = 0; k < positionX.size(); ++k)
27  edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << cms::convert2mm(positionX[k]) << " y "
28  << cms::convert2mm(positionY[k]) << " angle " << angles[k] << " detector "
29  << detectorType[k];
30 
31  std::string idName = args.parentName(); // Name of the "parent" volume.
32  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << idName << " NameSpace " << ns.name();
33 #endif
34 
35  dd4hep::Volume mother = ns.volume(args.parentName());
36  double dx = 0.5 * cellSize;
37  double dy = 0.5 * dx * tan(30._deg);
38 
39  for (unsigned int k = 0; k < positionX.size(); ++k) {
40  std::string name(childNames[detectorType[k]]);
41  name = ns.prepend(name);
42  dd4hep::Rotation3D rotation;
43  if (angles[k] != 0) {
44  double phi = convertDegToRad(angles[k]);
45 #ifdef EDM_ML_DEBUG
46  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation \t90, " << angles[k] << ", 90, "
47  << (angles[k] + 90) << ", 0, 0";
48 #endif
49  rotation = cms::makeRotation3D(90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
50  }
51  double xpos = dx * positionX[k];
52  double ypos = dy * positionY[k];
53  dd4hep::Position tran(xpos, ypos, 0);
54  int copy = HGCalTypes::packCellType6(cellType, k);
55  mother.placeVolume(ns.volume(name), copy, dd4hep::Transform3D(rotation, tran));
56 #ifdef EDM_ML_DEBUG
57  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << name << " number " << copy << " positioned in " << idName
58  << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with "
59  << rotation;
60 #endif
61  }
62 
63  return cms::s_executed;
64 }
65 
66 // first argument is the type from the xml file
67 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferAlgo, 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
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
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.