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, first, mps_fire::i, dqmiolumiharvest::j, dqmdumpme::k, cmsLHEtoEOSManager::l, hgcalTopologyTester_cfi::layers, 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().

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  static const double sqrt3 = std::sqrt(3.0);
74  double r = 0.5 * waferSize;
75  double R = 2.0 * r / sqrt3;
76 
77  // Loop over all types
78  for (unsigned int k = 0; k < tags.size(); ++k) {
79  // First the mother
80  std::string mother = parentName + tags[k];
81  std::vector<std::pair<double, double>> wxy =
82  HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, r, R, 0.0, 0.0);
83  std::vector<double> xM, yM;
84  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
85  xM.emplace_back(wxy[i].first);
86  yM.emplace_back(wxy[i].second);
87  }
88  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
89  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
90 
91  dd4hep::Material matter = ns.material(material);
92  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
93  ns.addSolidNS(ns.prepend(mother), solid);
94  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
95  ns.addVolumeNS(glogM);
96 #ifdef EDM_ML_DEBUG
97  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << material
98  << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
99  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
100  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
101  << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
102  << " orientation " << orientations[k] << " and " << xM.size() << " edges";
103  for (unsigned int j = 0; j < xM.size(); ++j)
104  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xM[j]) << ":" << cms::convert2mm(yM[j]);
105 #endif
106 
107  // Then the layers
108  dd4hep::Rotation3D rotation;
109  wxy = HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, r, R, 0.0, 0.0);
110  std::vector<double> xL, yL;
111  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
112  xL.emplace_back(wxy[i].first);
113  yL.emplace_back(wxy[i].second);
114  }
115  std::vector<dd4hep::Volume> glogs(materials.size());
116  std::vector<int> copyNumber(materials.size(), 1);
117  double zi(-0.5 * thick), thickTot(0.0);
118  for (unsigned int l = 0; l < layers.size(); l++) {
119  unsigned int i = layers[l];
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP:Layer " << l << ":" << i << " T " << layerThick[i] << " Copy "
122  << copyNumber[i];
123 #endif
124  if (copyNumber[i] == 1) {
125  if (layerType[i] > 0) {
126  zw[0] = -0.5 * waferThick;
127  zw[1] = 0.5 * waferThick;
128  } else {
129  zw[0] = -0.5 * layerThick[i];
130  zw[1] = 0.5 * layerThick[i];
131  }
132  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
133  std::string lname = layerNames[i] + tags[k];
134  ns.addSolidNS(ns.prepend(lname), solid);
135  matter = ns.material(materials[i]);
136  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
137  ns.addVolumeNS(glogs[i]);
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
140  << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
141  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
142  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
143  << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
144  << partialTypes[k] << " orientation " << orientations[k] << " and " << xM.size()
145  << " edges";
146  for (unsigned int j = 0; j < xL.size(); ++j)
147  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
148 #endif
149  }
150  if (layerType[i] > 0) {
151  std::string sname = senseName + tags[k];
152  zw[0] = -0.5 * senseT;
153  zw[1] = 0.5 * senseT;
154  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
155  ns.addSolidNS(ns.prepend(sname), solid);
156  dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
157  ns.addVolumeNS(glog);
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
160  << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
161  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
162  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
163  << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
164  << partialTypes[k] << " orientation " << orientations[k] << " and " << xL.size()
165  << " edges";
166  for (unsigned int j = 0; j < xL.size(); ++j)
167  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
168 #endif
169  double zpos = (posSense == 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
170  dd4hep::Position tran(0, 0, zpos);
171  int copy = 10 + senseType;
172  glogs[i].placeVolume(glog, copy, tran);
173 #ifdef EDM_ML_DEBUG
174  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
175  << glogs[i].name() << " at (0, 0," << cms::convert2mm(zpos)
176  << ") with no rotation";
177 #endif
178  }
179  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
180  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
183  << " positioned in " << glogM.name() << " at (0,0,"
184  << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
185 #endif
186  ++copyNumber[i];
187  zi += layerThick[i];
188  thickTot += layerThick[i];
189  }
190  if (std::abs(thickTot - thick) >= tol) {
191  if (thickTot > thick) {
192  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
193  << cms::convert2mm(thickTot) << ": thickness of all its components **** ERROR ****";
194  } else {
195  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
196  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
197  }
198  }
199  }
200 
201  return cms::s_executed;
202 }
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 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_DDHGCalWaferP   
)

Definition at line 205 of file DDHGCalWaferP.cc.