CMS 3D CMS Logo

Functions
DDHGCalWaferF.cc File Reference
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/DDutils.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
#include <string>
#include <vector>
#include <sstream>

Go to the source code of this file.

Functions

static long algorithm (dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
 
 DD4HEP_OPEN_PLUGIN (dd4hep, ddcms_det_element_DDCMS_hgcal_DDHGCalWaferF)
 

Function Documentation

◆ algorithm()

static long algorithm ( dd4hep::Detector &  ,
cms::DDParsingContext ctxt,
xml_h  e 
)
static

Definition at line 20 of file DDHGCalWaferF.cc.

References funct::abs(), cms::DDNamespace::addSolidNS(), cms::DDNamespace::addVolumeNS(), writedatasetfile::args, cms::convert2mm(), filterCSVwithJSON::copy, counter, MillePedeFileConverter_cfg::e, HGCalGeometryMode::ExtrudedPolygon, mps_fire::i, dqmdumpme::k, cmsLHEtoEOSManager::l, hgcalTBTopologyTester_cfi::layers, cms::DDNamespace::material(), g4SimHits_cfi::Material, cms::DDNamespace::name(), caHitNtupletGeneratorKernels::nCells, HGCalTypes::packCellTypeUV(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), dttmaxenums::R, alignCSCRings::r, diffTwoXMLs::r2, idealTransformation::rotation, cms::s_executed, L1EGammaClusterEmuProducer_cfi::scale, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, findQualityFiles::v, cms::DDNamespace::volume(), HGCalProperty::waferThick(), and zw().

20  {
21  cms::DDNamespace ns(ctxt, e, true);
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 "
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& cellTypeX = 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 " << cellTypeX
59  << " NameSpace " << 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  int n2 = nCells / 2;
139  double y0 = (cellTypeX >= 3) ? 0.5 : 0.0;
140  double x0 = (cellTypeX >= 3) ? 0.5 : 1.0;
141  int voff = (cellTypeX >= 3) ? 0 : 1;
142  int uoff = 1 - voff;
143  int cellType = (cellTypeX >= 3) ? (cellTypeX - 3) : cellTypeX;
144  for (int u = 0; u < 2 * nCells; ++u) {
145  for (int v = 0; v < 2 * nCells; ++v) {
146  if (((v - u) < (nCells + uoff)) && (u - v) < (nCells + voff)) {
147 #ifdef EDM_ML_DEBUG
148  counter++;
149 #endif
150  double yp = (u - 0.5 * v - n2 + y0) * 2 * r;
151  double xp = (1.5 * (v - nCells) + x0) * R;
152  int cell(0);
153  if ((u == 0) && (v == 0))
154  cell = 7;
155  else if ((u == 0) && (v == nCells - 1))
156  cell = 8;
157  else if ((u == nCells) && (v == 2 * nCells - 1))
158  cell = 9;
159  else if ((u == 2 * nCells - 1) && (v == 2 * nCells - 1))
160  cell = 10;
161  else if ((u == 2 * nCells - 1) && (v == nCells - 1))
162  cell = 11;
163  else if ((u == nCells) && (v == 0))
164  cell = 12;
165  else if (u == 0)
166  cell = 1;
167  else if ((v - u) == (nCells - 1))
168  cell = 4;
169  else if (v == (2 * nCells - 1))
170  cell = 2;
171  else if (u == (2 * nCells - 1))
172  cell = 5;
173  else if ((u - v) == nCells)
174  cell = 3;
175  else if (v == 0)
176  cell = 6;
177  dd4hep::Position tran(xp, yp, 0);
178  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
179  glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, dd4hep::Transform3D(rotation, tran));
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("HGCalGeom")
182  << "DDHGCalWaferF: " << cellNames[cell] << " number " << copy << " positioned in " << glogs[i].name()
183  << " at (" << cms::convert2mm(xp) << "," << cms::convert2mm(yp) << ",0) with no rotation";
184 #endif
185  }
186  }
187  }
188  }
189  }
190 #ifdef EDM_ML_DEBUG
191  edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWaferF::Counter : " << counter << "\n===============================\n";
192 #endif
193  if (std::abs(thickTot - thick) >= tol) {
194  if (thickTot > thick) {
195  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
196  << ": thickness of all its components **** ERROR ****";
197  } else {
198  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
199  << " of the components";
200  }
201  }
202 
203  return cms::s_executed;
204 }
Log< level::Info, true > LogVerbatim
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Log< level::Error, false > LogError
static constexpr long s_executed
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
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > 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

◆ DD4HEP_OPEN_PLUGIN()

DD4HEP_OPEN_PLUGIN ( dd4hep  ,
ddcms_det_element_DDCMS_hgcal_DDHGCalWaferF   
)

Definition at line 207 of file DDHGCalWaferF.cc.