CMS 3D CMS Logo

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