CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDHCalLinearXY.cc
Go to the documentation of this file.
4 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 
8 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
9  cms::DDNamespace ns(ctxt, e, true);
10  cms::DDAlgoArguments args(ctxt, e);
11  // Header section of original DDHCalLinearXY.h
12  int numberX = args.value<int>("NumberX"); //Slices along X
13  int numberY = args.value<int>("NumberY"); //Slices along Y
14  double deltaX = args.value<double>("DeltaX"); //Step along X
15  double deltaY = args.value<double>("DeltaY"); //Step along Y
16  std::vector<double> centre = args.value<std::vector<double> >("Center");
18  std::vector<std::string> childName = args.value<std::vector<std::string> >("Child");
19 
20 #ifdef EDM_ML_DEBUG
21  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Parent " << parent.name() << " \twith " << childName.size()
22  << " children";
23  unsigned int k(0);
24  for (auto const& child : childName) {
25  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Child[" << k << "] = " << child;
26  ++k;
27  }
28  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Number along X/Y " << numberX << "/" << numberY
29  << "\tDelta along X/Y " << cms::convert2mm(deltaX) << "/" << cms::convert2mm(deltaY)
30  << "\tCentre (" << cms::convert2mm(centre[0]) << ", " << cms::convert2mm(centre[1])
31  << "," << cms::convert2mm(centre[2]);
32 #endif
33  double xoff = centre[0] - (numberX - 1) * 0.5 * deltaX;
34  double yoff = centre[1] - (numberY - 1) * 0.5 * deltaY;
35  unsigned int copy = 0;
36  for (int i = 0; i < numberX; ++i) {
37  for (int j = 0; j < numberY; ++j) {
38  unsigned int k = (childName.size() == 1) ? 0 : copy;
39  ++copy;
40  if (k < childName.size() && (childName[k] != " " && childName[k] != "Null")) {
41  std::string child = childName[k];
42  dd4hep::Position tran(xoff + i * deltaX, yoff + j * deltaY, centre[2]);
43  parent.placeVolume(ns.volume(child), copy, tran);
44 #ifdef EDM_ML_DEBUG
45  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: " << child << " number " << copy << " positioned in "
46  << parent.name() << " at (" << cms::convert2mm((xoff + i * deltaX)) << ", "
47  << cms::convert2mm((yoff + j * deltaY)) << ", " << cms::convert2mm(centre[2])
48  << ") with no rotation";
49 #endif
50  } else {
51 #ifdef EDM_ML_DEBUG
52  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: no child placed for [" << copy << "]";
53 #endif
54  }
55  }
56  }
57  return cms::s_executed;
58 }
59 
60 // first argument is the type from the xml file
61 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalLinearXY, algorithm)
Log< level::Info, true > LogVerbatim
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
T value(const std::string &name) const
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
dd4hep::Volume Volume
std::string parentName() const
Access value of rParent child node.