CMS 3D CMS Logo

DDAHcalModuleAlgo.cc
Go to the documentation of this file.
1 /*
2  * DDAHcalModuleAlgo.cc
3  *
4  * Created on: 27-August-2019
5  * Author: Sunanda Banerjee
6  */
7 
9 #include "DD4hep/DetFactoryHelper.h"
14 
15 //#define EDM_ML_DEBUG
16 using namespace cms_units::operators;
17 
18 static long algorithm(dd4hep::Detector& /* description */,
20  xml_h e,
21  dd4hep::SensitiveDetector& /* sens */) {
22  cms::DDNamespace ns(ctxt, e, true);
23  cms::DDAlgoArguments args(ctxt, e);
24 
25  const auto& tile = args.value<std::string>("TileName"); // Scintillator tile
26  const auto& materials = args.value<std::vector<std::string> >("MaterialNames"); // Materials
27  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names
28  const auto& thick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
29  std::vector<int> copyNumber; // Initial copy numbers
30  for (unsigned int i = 0; i < materials.size(); ++i)
31  copyNumber.emplace_back(1);
32 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile;
34  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials.size() << " types of volumes";
35  for (unsigned int i = 0; i < names.size(); ++i)
36  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness " << thick[i]
37  << " filled with " << materials[i] << " first copy number " << copyNumber[i];
38 #endif
39  const auto& layers = args.value<std::vector<int> >("Layers"); // Number of layers in a section
40  const auto& layerThick = args.value<std::vector<double> >("LayerThick"); // Thickness of each section
41  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
42  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer (sensitive?)
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers.size() << " blocks";
45  for (unsigned int i = 0; i < layers.size(); ++i)
46  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick[i] << " with " << layers[i]
47  << " layers";
48  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType.size() << " layers";
49  for (unsigned int i = 0; i < layerType.size(); ++i)
50  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
51  << layerSense[i];
52 #endif
53  const auto& widths = args.value<std::vector<double> >("Widths"); // Width (passive, active)
54  const auto& heights = args.value<std::vector<double> >("Heights"); // Heights (passive, active)
55  const auto& tileN = args.value<std::vector<int> >("TileN"); // # of tiles (along x, y)
56  const auto& tileStep = args.value<std::vector<double> >("TileStep"); // Separation between tiles (x, y)
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths.size() << " sizes for width "
59  << "and height:";
60  for (unsigned int i = 0; i < widths.size(); ++i)
61  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << widths[i] << ":" << heights[i];
62  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN.size() << " tile positioning parameters";
63  for (unsigned int i = 0; i < tileN.size(); ++i)
64  edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN[i] << ":" << tileStep[i];
65 #endif
66  const auto& zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
67  std::string idNameSpace = static_cast<std::string>(ns.name()); // Namespace of this and ALL sub-parts
68 #ifdef EDM_ML_DEBUG
69  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock << " NameSpace " << idNameSpace;
70 #endif
71 
72  // Mother module
74 
75  double zi(zMinBlock);
76  int laymin(0);
77  for (unsigned int i = 0; i < layers.size(); i++) {
78  double zo = zi + layerThick[i];
79  int laymax = laymin + layers[i];
80  double zz = zi;
81  double thickTot(0);
82  for (int ly = laymin; ly < laymax; ++ly) {
83  int ii = layerType[ly];
84  int copy = copyNumber[ii];
85  zz += (0.5 * thick[ii]);
86  thickTot += thick[ii];
87 
88  std::string name = "HGCal" + names[ii] + std::to_string(copy);
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front " << zi
91  << " Back " << zo << " superlayer thickness " << layerThick[i];
92 #endif
93  dd4hep::Material matter = ns.material(materials[ii]);
94  dd4hep::Volume glog;
95  if (layerSense[ly] == 0) {
96  dd4hep::Solid solid = dd4hep::Box(0.5 * widths[0], 0.5 * heights[0], 0.5 * thick[ii]);
97  ns.addSolidNS(ns.prepend(name), solid);
98  glog = dd4hep::Volume(solid.name(), solid, matter);
99 #ifdef EDM_ML_DEBUG
100  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
101  << " of dimensions " << 0.5 * widths[0] << ", " << 0.5 * heights[0] << ", "
102  << 0.5 * thick[ii];
103 #endif
104  } else {
105  dd4hep::Solid solid = dd4hep::Box(0.5 * widths[1], 0.5 * heights[1], 0.5 * thick[ii]);
106  ns.addSolidNS(ns.prepend(name), solid);
107  glog = dd4hep::Volume(solid.name(), solid, matter);
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
110  << " of dimensions " << 0.5 * widths[1] << ", " << 0.5 * heights[1] << ", "
111  << 0.5 * thick[ii];
112 #endif
113  int ncol = tileN[0] / 2;
114  int nrow = tileN[1] / 2;
115 #ifdef EDM_ML_DEBUG
116  int kount(0);
117  edm::LogVerbatim("HGCalGeom") << glog.name() << " Row " << nrow << " Column " << ncol;
118 #endif
119  for (int nr = -nrow; nr <= nrow; ++nr) {
120  int inr = (nr >= 0) ? nr : -nr;
121  double ypos = (nr >= 0) ? (inr - 0.5) * tileStep[1] : -(inr - 0.5) * tileStep[1];
122  for (int nc = -ncol; nc <= ncol; ++nc) {
123  int inc = (nc >= 0) ? nc : -nc;
124  double xpos = (nc >= 0) ? (inc - 0.5) * tileStep[0] : -(inc - 0.5) * tileStep[0];
125  if (nr != 0 && nc != 0) {
126  dd4hep::Position tran(xpos, ypos, 0.0);
127  dd4hep::Rotation3D rotation;
128  int copy = inr * AHCalParameters::kColumn_ + inc;
129  if (nc < 0)
131  if (nr < 0)
133  dd4hep::Volume glog1 = ns.volume(tile);
134  glog.placeVolume(glog1, copy, dd4hep::Transform3D(rotation, tran));
135 #ifdef EDM_ML_DEBUG
136  kount++;
137  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tile << " number " << copy << " positioned in "
138  << glog.name() << " at " << tran << " with " << rotation;
139 #endif
140  }
141  }
142  }
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.name();
145 #endif
146  }
147  dd4hep::Position r1(0, 0, zz);
148  dd4hep::Rotation3D rot;
149  module.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
150  ++copyNumber[ii];
151 #ifdef EDM_ML_DEBUG
152  edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
153  << module.name() << " at " << r1 << " with " << rot;
154 #endif
155  zz += (0.5 * thick[ii]);
156  } // End of loop over layers in a block
157  zi = zo;
158  laymin = laymax;
159  if (fabs(thickTot - layerThick[i]) < 0.00001) {
160  } else if (thickTot > layerThick[i]) {
161  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " is smaller than thickness "
162  << thickTot << " of all its components **** ERROR ****\n";
163  } else if (thickTot < layerThick[i]) {
164  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick[i] << " does not match with "
165  << thickTot << " of the components\n";
166  }
167  } // End of loop over blocks
168 
169  return 1;
170 }
171 
172 // first argument is the type from the xml file
173 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDAHcalModuleAlgo, algorithm)
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:200
static constexpr int kSignRowColumn_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:184
T value(const std::string &name) const
const std::string names[nVars_]
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
dd4hep::Volume Volume
ii
Definition: cuy.py:590
static constexpr int kRowColumn_
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:30
Definition: vlib.h:198
static constexpr int kColumn_
Constants used.
std::string parentName() const
Access value of rParent child node.