CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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);
24  cms::DDAlgoArguments args(ctxt, e);
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 #ifdef EDM_ML_DEBUG
30  const auto& waferSepar = args.value<double>("SensorSeparation");
31 #endif
32  const auto& waferThick = args.value<double>("WaferThickness");
33  const auto& waferTag = args.value<std::string>("WaferTag");
34 #ifdef EDM_ML_DEBUG
35  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << args.parentName() << " made of " << material
36  << " T " << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar
37  << " T " << waferThick;
38 #endif
39  const auto& orient = args.value<std::vector<int> >("WaferOrinet");
40  const auto& face = args.value<std::vector<int> >("WaferFace");
41  const auto& tag = args.value<std::vector<std::string> >("WaferPlacementIndex");
42  const auto& layerNames = args.value<std::vector<std::string> >("LayerNames");
43  const auto& materials = args.value<std::vector<std::string> >("LayerMaterials");
44  const auto& layerThick = args.value<std::vector<double> >("LayerThickness");
45  const auto& layerType = args.value<std::vector<int> >("LayerTypes");
46  std::vector<int> copyNumber;
47  copyNumber.resize(materials.size(), 1);
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames.size() << " types of volumes";
50  for (unsigned int i = 0; i < layerNames.size(); ++i)
51  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
52  << " filled with " << materials[i] << " type " << layerType[i];
53 #endif
54  const auto& layers = args.value<std::vector<int> >("Layers");
55 #ifdef EDM_ML_DEBUG
56  std::ostringstream st1;
57  for (unsigned int i = 0; i < layers.size(); ++i)
58  st1 << " [" << i << "] " << layers[i];
59  edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
60 #endif
61  const auto& nCells = args.value<int>("NCells");
62  const auto& cellType = args.value<int>("CellType");
63  const auto& cellNames = args.value<std::vector<std::string> >("CellNames");
64  const auto& cellOffset = args.value<std::vector<int> >("CellOffset");
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells << " Cell Type " << cellType
67  << " # of cells " << cellNames.size();
68  std::ostringstream st2;
69  for (unsigned int i = 0; i < cellOffset.size(); ++i)
70  st2 << " [" << i << "] " << cellOffset[i];
71  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset.size() << " types of cells with offsets "
72  << st2.str();
73  for (unsigned int k = 0; k < cellNames.size(); ++k)
74  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames[k];
75 
76  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
77 #endif
78 
79  static constexpr double tol = 0.00001;
80  static const double sqrt3 = std::sqrt(3.0);
81  double rM = 0.5 * waferSize;
82  double RM2 = rM / sqrt3;
83  double r2 = 0.5 * waferSize;
84  double R2 = r2 / sqrt3;
85  const int nFine(nCells), nCoarse(nCells);
86  HGCalCell wafer(waferSize, nFine, nCoarse);
87  for (unsigned int k = 0; k < tag.size(); ++k) {
88  // First the mother
89  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
90  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
91  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
92  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
93  std::string parentName = args.parentName() + tag[k] + waferTag;
94  dd4hep::Material matter = ns.material(material);
95  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
96  ns.addSolidNS(ns.prepend(parentName), solid);
97  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
98  ns.addVolumeNS(glogM);
99 #ifdef EDM_ML_DEBUG
100  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
101  << material << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
102  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
103  << scale[1] << " and " << xM.size() << " edges";
104  for (unsigned int kk = 0; kk < xM.size(); ++kk)
105  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
106 #endif
107 
108  // Then the layers
109  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
110  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
111  std::vector<dd4hep::Volume> glogs(materials.size());
112  for (unsigned int ii = 0; ii < copyNumber.size(); ii++) {
113  copyNumber[ii] = 1;
114  }
115  double zi(-0.5 * thick), thickTot(0.0);
116  for (unsigned int l = 0; l < layers.size(); l++) {
117  unsigned int i = layers[l];
118  if (copyNumber[i] == 1) {
119  if (layerType[i] > 0) {
120  zw[0] = -0.5 * waferThick;
121  zw[1] = 0.5 * waferThick;
122  } else {
123  zw[0] = -0.5 * layerThick[i];
124  zw[1] = 0.5 * layerThick[i];
125  }
126  std::string layerName = layerNames[i] + tag[k] + waferTag;
127  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
128  ns.addSolidNS(ns.prepend(layerName), solid);
129  matter = ns.material(materials[i]);
130  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
131  ns.addVolumeNS(glogs[i]);
132 #ifdef EDM_ML_DEBUG
133  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
134  << materials[i] << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
135  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
136  << scale[1] << " and " << xL.size() << " edges";
137  for (unsigned int kk = 0; kk < xL.size(); ++kk)
138  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
139 #endif
140  }
141  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
142  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber[i]
145  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
146 #endif
147  ++copyNumber[i];
148  zi += layerThick[i];
149  thickTot += layerThick[i];
150  if (layerType[i] > 0) {
151  //int n2 = nCells / 2;
152  for (int u = 0; u < 2 * nCells; ++u) {
153  for (int v = 0; v < 2 * nCells; ++v) {
154  if (((v - u) < nCells) && ((u - v) <= nCells)) {
155  int placeIndex_ = wafer.HGCalCellPlacementIndex(1, face[k], orient[k]);
156  std::pair<double, double> xy1 = wafer.HGCalCellUV2XY1(u, v, placeIndex_, cellType);
157  double yp = xy1.second;
158  double xp = xy1.first;
159  int cell(0);
160  std::pair<int, int> cell1 = wafer.HGCalCellUV2Cell(u, v, placeIndex_, cellType);
161  cell = cell1.first + cellOffset[cell1.second];
162  dd4hep::Position tran(xp, yp, 0);
163  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
164  glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, tran);
165 #ifdef EDM_ML_DEBUG
166  edm::LogVerbatim("HGCalGeom")
167  << "DDHGCalWaferFullRotated: " << cellNames[cell] << " number " << copy << " positioned in "
168  << glogs[i].name() << " at " << tran << " with no rotation";
169 #endif
170  }
171  }
172  }
173  }
174  }
175  if (std::abs(thickTot - thick) >= tol) {
176  if (thickTot > thick) {
177  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
178  << ": thickness of all its components **** ERROR ****";
179  } else {
180  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
181  << " of the components";
182  }
183  }
184  }
185  return cms::s_executed;
186 }
187 
188 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferFullRotated, 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 char const * layerName[numberOfLayers]
std::pair< int32_t, int32_t > HGCalCellUV2Cell(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:94
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
T value(const std::string &name) const
Log< level::Error, false > LogError
int ii
Definition: cuy.py:589
#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
static int32_t HGCalCellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient)
Definition: HGCalCell.cc:230
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
dd4hep::Volume Volume
std::pair< double, double > HGCalCellUV2XY1(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:13
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ nCells
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.