CMS 3D CMS Logo

DDHCalForwardAlgo.cc
Go to the documentation of this file.
6 #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);
14  // Header section
15  std::string parentName = DDSplit(args.parentName()).first;
16  std::string cellMat = args.value<std::string>("CellMaterial"); //Cell material
17  double cellDx = args.value<double>("CellDx"); //Cell size (x)
18  double cellDy = args.value<double>("CellDy"); //Cell size (y)
19  double cellDz = args.value<double>("CellDz"); //Cell size (z)
20  double startY = args.value<double>("StartY"); //Starting Y for Cell
21  std::vector<std::string> childName = args.value<std::vector<std::string> >("Child"); //Children name
22  std::vector<int> number = args.value<std::vector<int> >("Number"); //Number of cells
23  std::vector<int> size = args.value<std::vector<int> >("Size"); //Number of children
24  std::vector<int> type = args.value<std::vector<int> >("Type"); //First child
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Cell material " << cellMat << "\tCell Size "
27  << cms::convert2mm(cellDx) << ", " << cms::convert2mm(cellDy) << ", "
28  << cms::convert2mm(cellDz) << "\tStarting Y " << cms::convert2mm(startY) << "\tChildren "
29  << childName[0] << ", " << childName[1]
30  << "\n Cell positioning done for " << number.size() << " times";
31  for (unsigned int i = 0; i < number.size(); ++i)
32  edm::LogVerbatim("HCalGeom") << "\t" << i << " Number of children " << size[i] << " occurence " << number[i]
33  << " first child index " << type[i];
34  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo debug: Parent " << args.parentName() << " NameSpace " << ns.name();
35 #endif
36 
37  dd4hep::Volume parent = ns.volume(args.parentName());
38  dd4hep::Material matter = ns.material(cellMat);
39 
40  double ypos = startY;
41  int box = 0;
42  for (unsigned int i = 0; i < number.size(); i++) {
43  double dx = cellDx * size[i];
44  int indx = type[i];
45  for (int j = 0; j < number[i]; j++) {
46  box++;
47  std::string name = parentName + std::to_string(box);
48  dd4hep::Solid solid = dd4hep::Box(ns.prepend(name), dx, cellDy, cellDz);
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.name() << " Box made of " << cellMat << " of Size "
51  << cms::convert2mm(dx) << ", " << cms::convert2mm(cellDy) << ", "
52  << cms::convert2mm(cellDz);
53 #endif
54  dd4hep::Volume glog(solid.name(), solid, matter);
55 
56  parent.placeVolume(glog, box, dd4hep::Position(0.0, ypos, 0.0));
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.name() << " number " << box << " positioned in "
59  << parent.name() << " at (0.0, " << cms::convert2mm(ypos)
60  << ", 0.0) with no rotation";
61 #endif
62 
63  double xpos = -dx + cellDx;
64  ypos += 2 * cellDy;
65  indx = 1 - indx;
66  for (int k = 0; k < size[i]; ++k) {
67  glog.placeVolume(ns.volume(childName[indx]), k + 1, dd4hep::Position(xpos, 0.0, 0.0));
68 #ifdef EDM_ML_DEBUG
69  edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << childName[indx] << " number " << (k + 1)
70  << " positioned in " << glog.name() << " at (" << cms::convert2mm(xpos)
71  << ", 0,0, 0.0) with no rotation";
72 #endif
73  xpos += 2 * cellDx;
74  }
75  }
76  }
77 #ifdef EDM_ML_DEBUG
78  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalForwardAlgo construction";
79 #endif
80  return cms::s_executed;
81 }
82 
83 // first argument is the type from the xml file
84 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalForwardAlgo, algorithm);
size
Write out results.
Log< level::Info, true > LogVerbatim
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
std::string to_string(const V &value)
Definition: OMSAccess.h:71
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
std::string_view name() const
Definition: DDNamespace.h:79
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
dd4hep::Volume Volume
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99