CMS 3D CMS Logo

Functions
DDHGCalWaferPartialRotated.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 "Geometry/HGCalCommonData/interface/HGCalWaferMask.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_DDHGCalWaferPartialRotated)
 

Function Documentation

◆ algorithm()

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

Definition at line 22 of file DDHGCalWaferPartialRotated.cc.

References funct::abs(), cms::DDNamespace::addSolidNS(), cms::DDNamespace::addVolumeNS(), writedatasetfile::args, HGCalCell::cellOrient(), cms::convert2mm(), filterCSVwithJSON::copy, MillePedeFileConverter_cfg::e, HGCalGeometryMode::ExtrudedPolygon, first, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, cmsLHEtoEOSManager::l, hgcalTopologyTester_cfi::layers, visualization-live-secondInstance_cfg::m, cms::DDNamespace::material(), g4SimHits_cfi::Material, cms::DDNamespace::name(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), dttmaxenums::R, alignCSCRings::r, idealTransformation::rotation, cms::s_executed, L1EGammaClusterEmuProducer_cfi::scale, edm::second(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, triggerMatcherToHLTDebug_cfi::tags, HGCalProperty::waferThick(), HGCalWaferMask::waferXY(), and zw().

22  {
23  cms::DDNamespace ns(ctxt, e, true);
25  std::string parentName = args.parentName();
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") << "DDHGCalWaferPartialRotated: Module " << parentName << " made of " << material
34  << " T " << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
35  << " Half Separation " << cms::convert2mm(waferSepar) << " T "
37 #endif
38  const auto& tags = args.value<std::vector<std::string>>("Tags");
39  const auto& partialTypes = args.value<std::vector<int>>("PartialTypes");
40  const auto& placementIndex = args.value<std::vector<int>>("PlacementIndex");
41  const auto& placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags");
42 #ifdef EDM_ML_DEBUG
43  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << tags.size() << " variations of wafer types";
44  for (unsigned int k = 0; k < tags.size(); ++k) {
45  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
46  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
47  << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m];
48  }
49  }
50 #endif
51  const auto& layerNames = args.value<std::vector<std::string>>("LayerNames");
52  const auto& materials = args.value<std::vector<std::string>>("LayerMaterials");
53  const auto& layerThick = args.value<std::vector<double>>("LayerThickness");
54  const auto& layerType = args.value<std::vector<int>>("LayerTypes");
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << layerNames.size() << " types of volumes";
57  for (unsigned int i = 0; i < layerNames.size(); ++i)
58  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
59  << cms::convert2mm(layerThick[i]) << " filled with " << materials[i] << " type "
60  << layerType[i];
61 #endif
62  const auto& layers = args.value<std::vector<int>>("Layers");
63 #ifdef EDM_ML_DEBUG
64  std::ostringstream st1;
65  for (unsigned int i = 0; i < layers.size(); ++i)
66  st1 << " [" << i << "] " << layers[i];
67  edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
68 #endif
69  const auto& senseName = args.value<std::string>("SenseName");
70  const auto& senseT = args.value<double>("SenseThick");
71  const auto& senseType = args.value<int>("SenseType");
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: NameSpace " << ns.name() << " Sensitive Layer Name "
74  << senseName << " Thickness " << senseT << " Type " << senseType;
75 #endif
76 
77  static constexpr double tol = 0.00001 * dd4hep::mm;
78  static const double sqrt3 = std::sqrt(3.0);
79  double r = 0.5 * waferSize;
80  double R = 2.0 * r / sqrt3;
81 
82  // Loop over all types
83  for (unsigned int k = 0; k < tags.size(); ++k) {
84  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
85  // First the mother
86  std::string mother = parentName + placementIndexTags[m] + waferTag + tags[k];
87  std::vector<std::pair<double, double>> wxy =
88  HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], r, R, 0.0, 0.0);
89  std::vector<double> xM, yM;
90  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
91  xM.emplace_back(wxy[i].first);
92  yM.emplace_back(wxy[i].second);
93  }
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 
97  dd4hep::Material matter = ns.material(material);
98  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
99  ns.addSolidNS(ns.prepend(mother), solid);
100  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
101  ns.addVolumeNS(glogM);
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of "
104  << material << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
105  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
106  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
107  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
108  << " placement index " << placementIndex[m] << " and " << xM.size() << " edges";
109  for (unsigned int j = 0; j < xM.size(); ++j)
110  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xM[j]) << ":" << cms::convert2mm(yM[j]);
111 #endif
112 
113  // Then the layers
114  dd4hep::Rotation3D rotation;
115  wxy = HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], r, R, 0.0, 0.0);
116  std::vector<double> xL, yL;
117  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
118  xL.emplace_back(wxy[i].first);
119  yL.emplace_back(wxy[i].second);
120  }
121  std::vector<dd4hep::Volume> glogs(materials.size());
122  std::vector<int> copyNumber(materials.size(), 1);
123  double zi(-0.5 * thick), thickTot(0.0);
124  for (unsigned int l = 0; l < layers.size(); l++) {
125  unsigned int i = layers[l];
126  if (copyNumber[i] == 1) {
127  if (layerType[i] > 0) {
128  zw[0] = -0.5 * waferThick;
129  zw[1] = 0.5 * waferThick;
130  } else {
131  zw[0] = -0.5 * layerThick[i];
132  zw[1] = 0.5 * layerThick[i];
133  }
134  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
135  std::string lname = layerNames[i] + placementIndexTags[m] + waferTag + tags[k];
136  ns.addSolidNS(ns.prepend(lname), solid);
137  matter = ns.material(materials[i]);
138  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
139  ns.addVolumeNS(glogs[i]);
140 #ifdef EDM_ML_DEBUG
141  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
142  << " extruded polygon made of " << materials[i] << " z|x|y|s (0) "
143  << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
144  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
145  << cms::convert2mm(zw[1]) << ": partial " << partialTypes[k]
146  << " placement index " << placementIndex[m] << cms::convert2mm(zx[1]) << ":"
147  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size()
148  << " edges";
149  for (unsigned int j = 0; j < xL.size(); ++j)
150  edm::LogVerbatim("HGCalGeom")
151  << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
152 #endif
153  }
154  if (layerType[i] > 0) {
155  std::string sname = senseName + placementIndexTags[m] + waferTag + tags[k];
156  zw[0] = -0.5 * senseT;
157  zw[1] = 0.5 * senseT;
158  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
159  ns.addSolidNS(ns.prepend(sname), solid);
160  dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
161  ns.addVolumeNS(glog);
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
164  << " extruded polygon made of " << materials[i] << " z|x|y|s (0) "
165  << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
166  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
167  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
168  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
169  << " placement index " << placementIndex[m] << " and " << xL.size() << " edges";
170  for (unsigned int j = 0; j < xL.size(); ++j)
171  edm::LogVerbatim("HGCalGeom")
172  << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
173 #endif
174  auto posSense = HGCalCell::cellOrient(placementIndex[m]);
175  double zpos = (posSense.second > 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
176  dd4hep::Position tran(0, 0, zpos);
177  int copy = 10 + senseType;
178  glogs[i].placeVolume(glog, copy, tran);
179 #ifdef EDM_ML_DEBUG
180  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glog.name() << " number " << copy
181  << " positioned in " << glogs[i].name() << " at (0, 0," << cms::convert2mm(zpos)
182  << ") with no rotation";
183 #endif
184  }
185  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
186  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
187 #ifdef EDM_ML_DEBUG
188  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glogs[i].name() << " number "
189  << copyNumber[i] << " positioned in " << glogM.name() << " at (0,0,"
190  << cms::convert2mm(zi + 0.5 * layerThick[i]) << " with no rotation";
191 #endif
192  ++copyNumber[i];
193  zi += layerThick[i];
194  thickTot += layerThick[i];
195  }
196  if (std::abs(thickTot - thick) >= tol) {
197  if (thickTot > thick) {
198  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
199  << cms::convert2mm(thickTot)
200  << ": thickness of all its components **** ERROR ****";
201  } else {
202  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
203  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
204  }
205  }
206  }
207  }
208 
209  return cms::s_executed;
210 }
Log< level::Info, true > LogVerbatim
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double delX, double delY, double xpos, double ypos)
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Log< level::Error, false > LogError
U second(std::pair< T, U > const &p)
static std::pair< int32_t, int32_t > cellOrient(int32_t placementIndex)
Definition: HGCalCell.cc:235
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
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_DDHGCalWaferPartialRotated   
)

Definition at line 213 of file DDHGCalWaferPartialRotated.cc.