CMS 3D CMS Logo

Functions
DDHGCalWaferP.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 <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_DDHGCalWaferP)
 

Function Documentation

◆ algorithm()

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

Definition at line 21 of file DDHGCalWaferP.cc.

References funct::abs(), cms::DDNamespace::addSolidNS(), cms::DDNamespace::addVolumeNS(), writedatasetfile::args, cms::convert2mm(), filterCSVwithJSON::copy, MillePedeFileConverter_cfg::e, HGCalGeometryMode::ExtrudedPolygon, dqmdumpme::first, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, MainPageGenerator::l, hgcalTBTopologyTester_cfi::layers, 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().

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

Definition at line 202 of file DDHGCalWaferP.cc.