CMS 3D CMS Logo

DDHGCalWaferFullRotated.cc
Go to the documentation of this file.
1 // File: DDHGCalWaferFullRotated.cc
3 // Description: Geometry factory class for a full silicon Wafer
4 // Created by Sunanda Banerjee, Pruthvi Suryadevara, Indranil Das
6 #include "DD4hep/DetFactoryHelper.h"
12 
13 #include <string>
14 #include <vector>
15 #include <sstream>
16 
17 //#define EDM_ML_DEBUG
18 
19 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
20 #ifdef EDM_ML_DEBUG
21  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Creating an instance";
22 #endif
23  cms::DDNamespace ns(ctxt, e, true);
25 
26  const auto& material = args.value<std::string>("ModuleMaterial");
27  const auto& thick = args.value<double>("ModuleThickness");
28  const auto& waferSize = args.value<double>("WaferSize");
29  const auto& waferSepar = args.value<double>("SensorSeparation");
30  const auto& waferThick = args.value<double>("WaferThickness");
31  const auto& waferTag = args.value<std::string>("WaferTag");
32 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << args.parentName() << " made of " << material
34  << " T " << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar
35  << " T " << waferThick;
36 #endif
37  const auto& orient = args.value<std::vector<int> >("WaferOrient");
38  const auto& face = args.value<std::vector<int> >("WaferFace");
39  const auto& tag = args.value<std::vector<std::string> >("WaferPlacementIndex");
40  const auto& layerNames = args.value<std::vector<std::string> >("LayerNames");
41  const auto& materials = args.value<std::vector<std::string> >("LayerMaterials");
42  const auto& layerThick = args.value<std::vector<double> >("LayerThickness");
43  const auto& layerType = args.value<std::vector<int> >("LayerTypes");
44  std::vector<int> copyNumber;
45  copyNumber.resize(materials.size(), 1);
46 #ifdef EDM_ML_DEBUG
47  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames.size() << " types of volumes";
48  for (unsigned int i = 0; i < layerNames.size(); ++i)
49  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
50  << " filled with " << materials[i] << " type " << layerType[i];
51 #endif
52  const auto& layers = args.value<std::vector<int> >("Layers");
53 #ifdef EDM_ML_DEBUG
54  std::ostringstream st1;
55  for (unsigned int i = 0; i < layers.size(); ++i)
56  st1 << " [" << i << "] " << layers[i];
57  edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
58 #endif
59  const auto& nCells = args.value<int>("NCells");
60  const auto& cellType = args.value<int>("CellType");
61  const auto& cellNames = args.value<std::vector<std::string> >("CellNames");
62  const auto& cellOffset = args.value<std::vector<int> >("CellOffset");
63 #ifdef EDM_ML_DEBUG
64  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells << " Cell Type " << cellType
65  << " # of cells " << cellNames.size();
66  std::ostringstream st2;
67  for (unsigned int i = 0; i < cellOffset.size(); ++i)
68  st2 << " [" << i << "] " << cellOffset[i];
69  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset.size() << " types of cells with offsets "
70  << st2.str();
71  for (unsigned int k = 0; k < cellNames.size(); ++k)
72  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames[k];
73 
74  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
75 #endif
76 
77  static constexpr double tol = 0.00001;
78  static const double sqrt3 = std::sqrt(3.0);
79  double rM = 0.5 * waferSize;
80  double RM2 = rM / sqrt3;
81  double r2 = 0.5 * waferSize;
82  double R2 = r2 / sqrt3;
83  const int nFine(nCells), nCoarse(nCells);
84  HGCalCell wafer((waferSize + waferSepar), nFine, nCoarse);
85  for (unsigned int k = 0; k < tag.size(); ++k) {
86  // First the mother
87  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
88  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
89  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
90  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
91  std::string parentName = args.parentName() + tag[k] + waferTag;
92  dd4hep::Material matter = ns.material(material);
93  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
94  ns.addSolidNS(ns.prepend(parentName), solid);
95  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
96  ns.addVolumeNS(glogM);
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
99  << material << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
100  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
101  << scale[1] << " and " << xM.size() << " edges";
102  for (unsigned int kk = 0; kk < xM.size(); ++kk)
103  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
104 #endif
105 
106  // Then the layers
107  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
108  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
109  std::vector<dd4hep::Volume> glogs(materials.size());
110  for (unsigned int ii = 0; ii < copyNumber.size(); ii++) {
111  copyNumber[ii] = 1;
112  }
113  double zi(-0.5 * thick), thickTot(0.0);
114  for (unsigned int l = 0; l < layers.size(); l++) {
115  unsigned int i = layers[l];
116  if (copyNumber[i] == 1) {
117  if (layerType[i] > 0) {
118  zw[0] = -0.5 * waferThick;
119  zw[1] = 0.5 * waferThick;
120  } else {
121  zw[0] = -0.5 * layerThick[i];
122  zw[1] = 0.5 * layerThick[i];
123  }
124  std::string layerName = layerNames[i] + tag[k] + waferTag;
125  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
126  ns.addSolidNS(ns.prepend(layerName), solid);
127  matter = ns.material(materials[i]);
128  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
129  ns.addVolumeNS(glogs[i]);
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
132  << materials[i] << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
133  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
134  << scale[1] << " and " << xL.size() << " edges";
135  for (unsigned int kk = 0; kk < xL.size(); ++kk)
136  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
137 #endif
138  }
139  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
140  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber[i]
143  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
144 #endif
145  ++copyNumber[i];
146  zi += layerThick[i];
147  thickTot += layerThick[i];
148  if (layerType[i] > 0) {
149  //int n2 = nCells / 2;
150  for (int u = 0; u < 2 * nCells; ++u) {
151  for (int v = 0; v < 2 * nCells; ++v) {
152  if (((v - u) < nCells) && ((u - v) <= nCells)) {
153  int placeIndex = wafer.cellPlacementIndex(1, face[k], orient[k]);
154  std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType);
155  double yp = xy1.second;
156  double xp = xy1.first;
157  int cell(0);
158  std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType);
159  cell = cell1.first + cellOffset[cell1.second];
160  dd4hep::Position tran(xp, yp, 0);
161  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
162  glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, tran);
163 #ifdef EDM_ML_DEBUG
164  edm::LogVerbatim("HGCalGeom")
165  << "DDHGCalWaferFullRotated: " << cellNames[cell] << " number " << copy << " positioned in "
166  << glogs[i].name() << " at " << tran << " with no rotation";
167 #endif
168  }
169  }
170  }
171  }
172  }
173  if (std::abs(thickTot - thick) >= tol) {
174  if (thickTot > thick) {
175  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
176  << ": thickness of all its components **** ERROR ****";
177  } else {
178  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
179  << " of the components";
180  }
181  }
182  }
183  return cms::s_executed;
184 }
185 
186 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferFullRotated, algorithm);
Log< level::Info, true > LogVerbatim
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
constexpr char const * layerName[numberOfLayers]
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ nCells
Log< level::Error, false > LogError
std::pair< int32_t, int32_t > cellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:94
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
static int32_t cellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient)
Definition: HGCalCell.cc:230
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int32_t waferThick(const int32_t property)
dd4hep::Volume Volume
ii
Definition: cuy.py:589
std::pair< double, double > cellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:13
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
Log< level::Warning, false > LogWarning
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99