CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDHGCalWaferF.cc
Go to the documentation of this file.
1 /*
2  * DDHGCalWaferF.cc
3  *
4  * Created on: 09-Jan-2021
5  */
6 
7 #include "DD4hep/DetFactoryHelper.h"
13 
14 #include <string>
15 #include <vector>
16 #include <sstream>
17 
18 //#define EDM_ML_DEBUG
19 
20 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
21  cms::DDNamespace ns(ctxt, e, true);
22  cms::DDAlgoArguments args(ctxt, e);
23  std::string motherName = args.parentName();
24  const auto& material = args.value<std::string>("ModuleMaterial");
25  const auto& thick = args.value<double>("ModuleThickness");
26  const auto& waferSize = args.value<double>("WaferSize");
27  const auto& waferThick = args.value<double>("WaferThickness");
28 #ifdef EDM_ML_DEBUG
29  const auto& waferSepar = args.value<double>("SensorSeparation");
30  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Module " << motherName << " made of " << material << " T "
31  << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
32  << " Half Separation " << cms::convert2mm(waferSepar) << " T "
33  << cms::convert2mm(waferThick);
34 #endif
35  const auto& layerNames = args.value<std::vector<std::string>>("LayerNames");
36  const auto& materials = args.value<std::vector<std::string>>("LayerMaterials");
37  const auto& layerThick = args.value<std::vector<double>>("LayerThickness");
38  const auto& layerType = args.value<std::vector<int>>("LayerTypes");
39  std::vector<int> copyNumber(materials.size(), 1);
40 #ifdef EDM_ML_DEBUG
41  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << layerNames.size() << " types of volumes";
42  for (unsigned int i = 0; i < layerNames.size(); ++i)
43  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
44  << cms::convert2mm(layerThick[i]) << " filled with " << materials[i] << " type "
45  << layerType[i];
46 #endif
47  const auto& layers = args.value<std::vector<int>>("Layers");
48 #ifdef EDM_ML_DEBUG
49  std::ostringstream st1;
50  for (unsigned int i = 0; i < layers.size(); ++i)
51  st1 << " [" << i << "] " << layers[i];
52  edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
53 #endif
54  const auto& nCells = args.value<int>("NCells");
55  const auto& cellType = args.value<int>("CellType");
56  const auto& cellNames = args.value<std::vector<std::string>>("CellNames");
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cells/Wafer " << nCells << " Cell Type " << cellType << " NameSpace "
59  << ns.name() << " # of cells " << cellNames.size();
60  for (unsigned int k = 0; k < cellNames.size(); ++k)
61  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cell[" << k << "] " << cellNames[k];
62  int counter(0);
63 #endif
64 
65  static constexpr double tol = 0.00001 * dd4hep::mm;
66  static const double sqrt3 = std::sqrt(3.0);
67  double rM = 0.5 * waferSize;
68  double RM2 = rM / sqrt3;
69  double R = waferSize / (3.0 * nCells);
70  double r = 0.5 * R * sqrt3;
71  double r2 = 0.5 * waferSize;
72  double R2 = r2 / sqrt3;
73 
74  // Mother Module
75  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
76  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
77  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
78  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
79 
80  dd4hep::Material matter = ns.material(material);
81  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
82  ns.addSolidNS(ns.prepend(motherName), solid);
83  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
84  ns.addVolumeNS(glogM);
85 #ifdef EDM_ML_DEBUG
86  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << material
87  << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
88  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
89  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
90  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
91  for (unsigned int k = 0; k < xM.size(); ++k)
92  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xM[k]) << ":" << cms::convert2mm(yM[k]);
93 #endif
94 
95  // Then the layers
96  dd4hep::Rotation3D rotation;
97  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
98  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
99  std::vector<dd4hep::Volume> glogs(materials.size());
100  double zi(-0.5 * thick), thickTot(0.0);
101  for (unsigned int l = 0; l < layers.size(); l++) {
102  unsigned int i = layers[l];
103  if (copyNumber[i] == 1) {
104  if (layerType[i] > 0) {
105  zw[0] = -0.5 * waferThick;
106  zw[1] = 0.5 * waferThick;
107  } else {
108  zw[0] = -0.5 * layerThick[i];
109  zw[1] = 0.5 * layerThick[i];
110  }
111  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
112  ns.addSolidNS(ns.prepend(layerNames[i]), solid);
113  matter = ns.material(materials[i]);
114  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
115  ns.addVolumeNS(glogs[i]);
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << materials[i]
118  << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
119  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
120  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
121  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
122  for (unsigned int k = 0; k < xL.size(); ++k)
123  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xL[k]) << ":" << cms::convert2mm(yL[k]);
124 #endif
125  }
126  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
127  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
128 #ifdef EDM_ML_DEBUG
129  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << glogs[i].name() << " number " << copyNumber[i]
130  << " positioned in " << glogM.name() << " at (0,0,"
131  << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
132 #endif
133  ++copyNumber[i];
134  zi += layerThick[i];
135  thickTot += layerThick[i];
136 
137  if (layerType[i] > 0) {
138  for (int u = 0; u < 2 * nCells; ++u) {
139  for (int v = 0; v < 2 * nCells; ++v) {
140  if (((v - u) < nCells) && (u - v) <= nCells) {
141 #ifdef EDM_ML_DEBUG
142  counter++;
143 #endif
144  int n2 = nCells / 2;
145  double yp = (u - 0.5 * v - n2) * 2 * r;
146  double xp = (1.5 * (v - nCells) + 1.0) * R;
147  int cell(0);
148  if ((u == 0) && (v == 0))
149  cell = 7;
150  else if ((u == 0) && (v == nCells - 1))
151  cell = 8;
152  else if ((u == nCells) && (v == 2 * nCells - 1))
153  cell = 9;
154  else if ((u == 2 * nCells - 1) && (v == 2 * nCells - 1))
155  cell = 10;
156  else if ((u == 2 * nCells - 1) && (v == nCells - 1))
157  cell = 11;
158  else if ((u == nCells) && (v == 0))
159  cell = 12;
160  else if (u == 0)
161  cell = 1;
162  else if ((v - u) == (nCells - 1))
163  cell = 4;
164  else if (v == (2 * nCells - 1))
165  cell = 2;
166  else if (u == (2 * nCells - 1))
167  cell = 5;
168  else if ((u - v) == nCells)
169  cell = 3;
170  else if (v == 0)
171  cell = 6;
172  dd4hep::Position tran(xp, yp, 0);
173  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
174  glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, dd4hep::Transform3D(rotation, tran));
175 #ifdef EDM_ML_DEBUG
176  edm::LogVerbatim("HGCalGeom")
177  << "DDHGCalWaferF: " << cellNames[cell] << " number " << copy << " positioned in " << glogs[i].name()
178  << " at (" << cms::convert2mm(xp) << "," << cms::convert2mm(yp) << ",0) with no rotation";
179 #endif
180  }
181  }
182  }
183  }
184  }
185 #ifdef EDM_ML_DEBUG
186  edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWaferF::Counter : " << counter << "\n===============================\n";
187 #endif
188  if (std::abs(thickTot - thick) >= tol) {
189  if (thickTot > thick) {
190  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
191  << ": thickness of all its components **** ERROR ****";
192  } else {
193  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
194  << " of the components";
195  }
196  }
197 
198  return cms::s_executed;
199 }
200 
201 // first argument is the type from the xml file
202 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferF, algorithm)
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
Log< level::Info, true > LogVerbatim
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
T value(const std::string &name) const
Log< level::Error, false > LogError
std::string_view name() const
Definition: DDNamespace.h:79
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
int32_t waferThick(const int32_t property)
Definition: HGCalProperty.cc:9
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
dd4hep::Volume Volume
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ nCells
static std::atomic< unsigned int > counter
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
Log< level::Warning, false > LogWarning
std::string parentName() const
Access value of rParent child node.