CMS 3D CMS Logo

Functions
DDHGCalWaferFullRotated.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 "Geometry/HGCalCommonData/interface/HGCalTypes.h"
#include "Geometry/HGCalCommonData/interface/HGCalCell.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_DDHGCalWaferFullRotated)
 

Function Documentation

◆ algorithm()

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

Definition at line 19 of file DDHGCalWaferFullRotated.cc.

References funct::abs(), cms::DDNamespace::addSolidNS(), cms::DDNamespace::addVolumeNS(), writedatasetfile::args, hgcalTopologyTester_cfi::cell1, HGCalCell::cellPlacementIndex(), HGCalCell::cellUV2Cell(), HGCalCell::cellUV2XY1(), filterCSVwithJSON::copy, MillePedeFileConverter_cfg::e, HGCalGeometryMode::ExtrudedPolygon, mps_fire::i, cuy::ii, dqmdumpme::k, GetRecoTauVFromDQM_MC_cff::kk, MainPageGenerator::l, hgcalTBTopologyTester_cfi::layers, cms::DDNamespace::material(), g4SimHits_cfi::Material, cms::DDNamespace::name(), caHitNtupletGeneratorKernels::nCells, hgcalPerformanceValidation::orient, HGCalTypes::packCellTypeUV(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), diffTwoXMLs::r2, cms::s_executed, pfClustersFromCombinedCaloHF_cfi::scale, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, findQualityFiles::v, cms::DDNamespace::volume(), HGCalTypes::waferFrontBack(), HGCalProperty::waferThick(), and zw().

19  {
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& waferThick = args.value<double>("WaferThickness");
30  const auto& waferTag = args.value<std::string>("WaferTag");
31 #ifdef EDM_ML_DEBUG
32  const auto& waferSepar = args.value<double>("SensorSeparation");
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& layerSizeOff = args.value<std::vector<double> >("LayerSizeOffset");
44  const auto& layerType = args.value<std::vector<int> >("LayerTypes");
45  std::vector<int> copyNumber;
46  copyNumber.resize(materials.size(), 1);
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames.size() << " types of volumes";
49  for (unsigned int i = 0; i < layerNames.size(); ++i)
50  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
51  << " size offset " << layerSizeOff[i] << " filled with " << materials[i] << " type "
52  << 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  int cellType(-1);
63  std::vector<std::string> cellNames;
64  std::vector<int> cellOffset;
65  if (nCells > 0) {
66  cellType = args.value<int>("CellType");
67  cellNames = args.value<std::vector<std::string> >("CellNames");
68  cellOffset = args.value<std::vector<int> >("CellOffset");
69  }
70 #ifdef EDM_ML_DEBUG
71  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells << " Cell Type " << cellType
72  << " NameSpace " << ns.name() << " # of cells " << cellNames.size();
73  std::ostringstream st2;
74  for (unsigned int i = 0; i < cellOffset.size(); ++i)
75  st2 << " [" << i << "] " << cellOffset[i];
76  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset.size() << " types of cells with offsets "
77  << st2.str();
78  for (unsigned int k = 0; k < cellNames.size(); ++k)
79  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames[k];
80 
81  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
82 #endif
83 
84  static constexpr double tol = 0.00001;
85  static const double sqrt3 = std::sqrt(3.0);
86  double rM = 0.5 * waferSize;
87  double RM2 = rM / sqrt3;
88  const int nFine(nCells), nCoarse(nCells);
89  HGCalCell wafer(waferSize, nFine, nCoarse);
90  for (unsigned int k = 0; k < tag.size(); ++k) {
91  // First the mother
92  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
93  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
94  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
95  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
96  std::string parentName = args.parentName() + tag[k] + waferTag;
97  dd4hep::Material matter = ns.material(material);
98  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
99  ns.addSolidNS(ns.prepend(parentName), solid);
100  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
101  ns.addVolumeNS(glogM);
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
104  << material << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
105  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
106  << scale[1] << " and " << xM.size() << " edges";
107  for (unsigned int kk = 0; kk < xM.size(); ++kk)
108  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
109 #endif
110 
111  // Then the layers
112  std::vector<dd4hep::Volume> glogs(materials.size());
113  for (unsigned int ii = 0; ii < copyNumber.size(); ii++) {
114  copyNumber[ii] = 1;
115  }
116  double zi(-0.5 * thick), thickTot(0.0);
117  for (unsigned int l = 0; l < layers.size(); l++) {
118  unsigned int i = layers[l];
119  double r2 = 0.5 * (waferSize - layerSizeOff[i]);
120  double R2 = r2 / sqrt3;
121  std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
122  std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
123  if (copyNumber[i] == 1) {
124  if (layerType[i] > 0) {
125  zw[0] = -0.5 * waferThick;
126  zw[1] = 0.5 * waferThick;
127  } else {
128  zw[0] = -0.5 * layerThick[i];
129  zw[1] = 0.5 * layerThick[i];
130  }
131  std::string layerName = layerNames[i] + tag[k] + waferTag;
132 #ifdef EDM_ML_DEBUG
133  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Layer " << l << ": " << i << ":" << layerName << " "
134  << layerSizeOff[i] << " r " << r2 << ":" << R2;
135 #endif
136  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
137  ns.addSolidNS(ns.prepend(layerName), solid);
138  matter = ns.material(materials[i]);
139  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
140  ns.addVolumeNS(glogs[i]);
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
143  << materials[i] << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
144  << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
145  << scale[1] << " and " << xL.size() << " edges";
146  for (unsigned int kk = 0; kk < xL.size(); ++kk)
147  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
148 #endif
149  }
150  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
151  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber[i]
154  << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
155 #endif
156  ++copyNumber[i];
157  zi += layerThick[i];
158  thickTot += layerThick[i];
159  if ((layerType[i] > 0) && (nCells > 0)) {
160  for (int u = 0; u < 2 * nCells; ++u) {
161  for (int v = 0; v < 2 * nCells; ++v) {
162  if (((v - u) < nCells) && ((u - v) <= nCells)) {
163  int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face[k]), orient[k]);
164  std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType);
165  double yp = xy1.second;
166  double xp = xy1.first;
167  int cell(0);
168  std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType);
169  cell = cell1.first + cellOffset[cell1.second];
170  dd4hep::Position tran(xp, yp, 0);
171  int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
172  glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, tran);
173 #ifdef EDM_ML_DEBUG
174  edm::LogVerbatim("HGCalGeom")
175  << "DDHGCalWaferFullRotated: " << cellNames[cell] << " number " << copy << " positioned in "
176  << glogs[i].name() << " at " << tran << " with no rotation";
177 #endif
178  }
179  }
180  }
181  }
182  }
183  if (std::abs(thickTot - thick) >= tol) {
184  if (thickTot > thick) {
185  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
186  << ": thickness of all its components **** ERROR ****";
187  } else {
188  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
189  << " of the components";
190  }
191  }
192  }
193  return cms::s_executed;
194 }
Log< level::Info, true > LogVerbatim
static int32_t packCellTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:28
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
static int32_t waferFrontBack(int32_t index)
Definition: HGCalTypes.h:126
int32_t waferThick(const int32_t property)
dd4hep::Volume Volume
ii
Definition: cuy.py:589
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ nCells
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:71
Log< level::Warning, false > LogWarning

◆ DD4HEP_OPEN_PLUGIN()

DD4HEP_OPEN_PLUGIN ( dd4hep  ,
ddcms_det_element_DDCMS_hgcal_DDHGCalWaferFullRotated   
)

Definition at line 196 of file DDHGCalWaferFullRotated.cc.