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, dqmdumpme::first, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, cmsLHEtoEOSManager::l, hgcalTBTopologyTester_cfi::layers, visualization-live-secondInstance_cfg::m, cms::DDNamespace::material(), g4SimHits_cfi::Material, cms::DDNamespace::name(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), idealTransformation::rotation, cms::s_executed, L1EGammaClusterEmuProducer_cfi::scale, edm::second(), 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& layerSizeOff = args.value<std::vector<double>>("LayerSizeOffset");
55  const auto& layerType = args.value<std::vector<int>>("LayerTypes");
56 #ifdef EDM_ML_DEBUG
57  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << layerNames.size() << " types of volumes";
58  for (unsigned int i = 0; i < layerNames.size(); ++i)
59  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
60  << cms::convert2mm(layerThick[i]) << " size offset "
61  << cms::convert2mm(layerSizeOff[i]) << " filled with " << materials[i] << " type "
62  << layerType[i];
63 #endif
64  const auto& layers = args.value<std::vector<int>>("Layers");
65 #ifdef EDM_ML_DEBUG
66  std::ostringstream st1;
67  for (unsigned int i = 0; i < layers.size(); ++i)
68  st1 << " [" << i << "] " << layers[i];
69  edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
70 #endif
71  const auto& senseName = args.value<std::string>("SenseName");
72  const auto& senseT = args.value<double>("SenseThick");
73  const auto& senseType = args.value<int>("SenseType");
74 #ifdef EDM_ML_DEBUG
75  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: NameSpace " << ns.name() << " Sensitive Layer Name "
76  << senseName << " Thickness " << senseT << " Type " << senseType;
77 #endif
78 
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferPartialRotated...";
81 #endif
82  static constexpr double tol = 0.00001 * dd4hep::mm;
83 
84  // Loop over all types
85  for (unsigned int k = 0; k < tags.size(); ++k) {
86  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
87  // First the mother
88  std::string mother = parentName + placementIndexTags[m] + waferTag + tags[k];
89  std::vector<std::pair<double, double>> wxy =
90  HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], waferSize, 0.0, 0.0, 0.0);
91  std::vector<double> xM, yM;
92  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
93  xM.emplace_back(wxy[i].first);
94  yM.emplace_back(wxy[i].second);
95  }
96  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
97  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
98 
99  dd4hep::Material matter = ns.material(material);
100  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
101  ns.addSolidNS(ns.prepend(mother), solid);
102  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
103  ns.addVolumeNS(glogM);
104 #ifdef EDM_ML_DEBUG
105  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of "
106  << material << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
107  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
108  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
109  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
110  << " placement index " << placementIndex[m] << " and " << xM.size() << " edges";
111  for (unsigned int j = 0; j < xM.size(); ++j)
112  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xM[j]) << ":" << cms::convert2mm(yM[j]);
113 #endif
114 
115  // Then the layers
116  dd4hep::Rotation3D rotation;
117  std::vector<dd4hep::Volume> glogs(materials.size());
118  std::vector<int> copyNumber(materials.size(), 1);
119  double zi(-0.5 * thick), thickTot(0.0);
120  for (unsigned int l = 0; l < layers.size(); l++) {
121  unsigned int i = layers[l];
122  wxy = HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], waferSize, layerSizeOff[i], 0.0, 0.0);
123  std::vector<double> xL, yL;
124  for (unsigned int i0 = 0; i0 < (wxy.size() - 1); ++i0) {
125  xL.emplace_back(wxy[i0].first);
126  yL.emplace_back(wxy[i0].second);
127  }
128 #ifdef EDM_ML_DEBUG
129  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated:Layer " << l << ":" << i << " T " << layerThick[i]
130  << " Size offset " << layerSizeOff[i] << " Copy " << copyNumber[i]
131  << " Partial type " << partialTypes[k];
132 #endif
133  if (copyNumber[i] == 1) {
134  if (layerType[i] > 0) {
135  zw[0] = -0.5 * waferThick;
136  zw[1] = 0.5 * waferThick;
137  } else {
138  zw[0] = -0.5 * layerThick[i];
139  zw[1] = 0.5 * layerThick[i];
140  }
141  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
142  std::string lname = layerNames[i] + placementIndexTags[m] + waferTag + tags[k];
143  ns.addSolidNS(ns.prepend(lname), solid);
144  matter = ns.material(materials[i]);
145  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
146  ns.addVolumeNS(glogs[i]);
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
149  << " extruded polygon made of " << materials[i] << " z|x|y|s (0) "
150  << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
151  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
152  << cms::convert2mm(zw[1]) << ": " << cms::convert2mm(zx[1]) << ":"
153  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
154  << " placement index " << placementIndex[m] << " and " << xM.size() << " edges";
155  for (unsigned int j = 0; j < xL.size(); ++j)
156  edm::LogVerbatim("HGCalGeom")
157  << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
158 #endif
159  }
160  if ((layerType[i] > 0) && (senseType >= 0)) {
161  std::string sname = senseName + placementIndexTags[m] + waferTag + tags[k];
162  zw[0] = -0.5 * senseT;
163  zw[1] = 0.5 * senseT;
164  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
165  ns.addSolidNS(ns.prepend(sname), solid);
166  dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
167  ns.addVolumeNS(glog);
168 #ifdef EDM_ML_DEBUG
169  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
170  << " extruded polygon made of " << materials[i] << " z|x|y|s (0) "
171  << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
172  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
173  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
174  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
175  << " placement index " << placementIndex[m] << " and " << xL.size() << " edges";
176  for (unsigned int j = 0; j < xL.size(); ++j)
177  edm::LogVerbatim("HGCalGeom")
178  << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
179 #endif
180  auto posSense = HGCalCell::cellOrient(placementIndex[m]);
181  double zpos = (posSense.second > 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
182  dd4hep::Position tran(0, 0, zpos);
183  int copy = 10 + senseType;
184  glogs[i].placeVolume(glog, copy, tran);
185 #ifdef EDM_ML_DEBUG
186  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glog.name() << " number " << copy
187  << " positioned in " << glogs[i].name() << " at (0, 0," << cms::convert2mm(zpos)
188  << ") with no rotation";
189 #endif
190  }
191  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
192  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
193 #ifdef EDM_ML_DEBUG
194  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glogs[i].name() << " number "
195  << copyNumber[i] << " positioned in " << glogM.name() << " at (0,0,"
196  << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
197 #endif
198  ++copyNumber[i];
199  zi += layerThick[i];
200  thickTot += layerThick[i];
201  }
202  if (std::abs(thickTot - thick) >= tol) {
203  if (thickTot > thick) {
204  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
205  << cms::convert2mm(thickTot)
206  << ": thickness of all its components **** ERROR ****";
207  } else {
208  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
209  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
210  }
211  }
212  }
213  }
214 
215  return cms::s_executed;
216 }
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:238
static constexpr long s_executed
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 219 of file DDHGCalWaferPartialRotated.cc.