CMS 3D CMS Logo

DDHGCalWaferAlgo.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 using namespace cms_units::operators;
8 
9 static long algorithm(dd4hep::Detector& /* description */,
11  xml_h e,
12  dd4hep::SensitiveDetector& /* sens */) {
13  cms::DDNamespace ns(ctxt, e, true);
14  cms::DDAlgoArguments args(ctxt, e);
15 
16  // Header section of original DDHGCalWafer.h
17  const auto& cellSize = args.value<double>("CellSize"); // Cell Size
18  const auto& cellType = args.value<int>("CellType"); // Type (1 fine; 2 coarse)
19  const auto& childNames = args.value<std::vector<std::string> >("ChildNames"); // Names of children
20  const auto& positionX = args.value<std::vector<int> >("PositionX"); // Position in X
21  const auto& positionY = args.value<std::vector<int> >("PositionY"); // Position in Y
22  const auto& angles = args.value<std::vector<double> >("Angles"); // Rotation angle
23  const auto& detectorType = args.value<std::vector<int> >("DetectorType"); // Detector type
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
26  << " positioned " << positionX.size() << " times with cell size " << cellSize;
27  for (unsigned int k = 0; k < positionX.size(); ++k)
28  edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << positionX[k] << " y " << positionY[k] << " angle "
29  << angles[k] << " detector " << detectorType[k];
30 
31  std::string idName = args.parentName(); // Name of the "parent" volume.
32  std::string idNameSpace = static_cast<std::string>(ns.name()); // Namespace of this and ALL sub-parts
33  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << idName << " NameSpace " << idNameSpace;
34 #endif
35 
36  dd4hep::Volume mother = ns.volume(args.parentName());
37  double dx = 0.5 * cellSize;
38  double dy = 0.5 * dx * tan(30._deg);
39 
40  for (unsigned int k = 0; k < positionX.size(); ++k) {
41  std::string name(childNames[detectorType[k]]);
42  if (strchr(name.c_str(), NAMESPACE_SEP) == nullptr)
43  name = ns.name() + name;
44  dd4hep::Rotation3D rotation;
45  if (angles[k] != 0) {
46  double phi = convertDegToRad(angles[k]);
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation \t90, " << angles[k] << ", 90, "
49  << (angles[k] + 90) << ", 0, 0";
50 #endif
51  rotation = cms::makeRotation3D(90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
52  }
53  double xpos = dx * positionX[k];
54  double ypos = dy * positionY[k];
55  dd4hep::Position tran(xpos, ypos, 0);
56  int copy = cellType * 1000 + k;
57  mother.placeVolume(ns.volume(name), copy, dd4hep::Transform3D(rotation, tran));
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << name << " number " << copy << " positioned in " << idName
60  << " at " << tran << " with " << rotation;
61 #endif
62  }
63 
64  return 1;
65 }
66 
67 // first argument is the type from the xml file
68 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferAlgo, 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
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
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.
#define NAMESPACE_SEP
Definition: DDNamespace.h:79