CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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, HGCalGeometryMode::ExtrudedPolygon, first, mps_fire::i, dqmiolumiharvest::j, isotrackApplyRegressor::k, cmsLHEtoEOSManager::l, LayerTriplets::layers(), cms::DDNamespace::material(), cms::DDNamespace::name(), cms::DDAlgoArguments::parentName(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), dttmaxenums::R, alignCSCRings::r, idealTransformation::rotation, cms::s_executed, pileupReCalc_HLTpaths::scale, edm::second(), mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, getPayloadData::tags, cms::DDAlgoArguments::value(), 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 "
34  << cms::convert2mm(waferThick);
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  if (copyNumber[i] == 1) {
121  if (layerType[i] > 0) {
122  zw[0] = -0.5 * waferThick;
123  zw[1] = 0.5 * waferThick;
124  } else {
125  zw[0] = -0.5 * layerThick[i];
126  zw[1] = 0.5 * layerThick[i];
127  }
128  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
129  std::string lname = layerNames[i] + tags[k];
130  ns.addSolidNS(ns.prepend(lname), solid);
131  matter = ns.material(materials[i]);
132  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
133  ns.addVolumeNS(glogs[i]);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
136  << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
137  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
138  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ": partial " << partialTypes[k]
139  << " orientation " << orientations[k] << cms::convert2mm(zx[1]) << ":"
140  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
141  for (unsigned int j = 0; j < xL.size(); ++j)
142  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
143 #endif
144  }
145  if (layerType[i] > 0) {
146  std::string sname = senseName + tags[k];
147  zw[0] = -0.5 * senseT;
148  zw[1] = 0.5 * senseT;
149  solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
150  ns.addSolidNS(ns.prepend(sname), solid);
151  dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
152  ns.addVolumeNS(glog);
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
155  << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
156  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
157  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
158  << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
159  << partialTypes[k] << " orientation " << orientations[k] << " and " << xL.size()
160  << " edges";
161  for (unsigned int j = 0; j < xL.size(); ++j)
162  edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
163 #endif
164  double zpos = (posSense == 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
165  dd4hep::Position tran(0, 0, zpos);
166  int copy = 10 + senseType;
167  glogs[i].placeVolume(glog, copy, tran);
168 #ifdef EDM_ML_DEBUG
169  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
170  << glogs[i].name() << " at (0, 0," << cms::convert2mm(zpos)
171  << ") with no rotation";
172 #endif
173  }
174  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
175  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
176 #ifdef EDM_ML_DEBUG
177  edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
178  << " positioned in " << glogM.name() << " at (0,0,"
179  << cms::convert2mm(zi + 0.5 * layerThick[i]) << " with no rotation";
180 #endif
181  ++copyNumber[i];
182  zi += layerThick[i];
183  thickTot += layerThick[i];
184  }
185  if (std::abs(thickTot - thick) >= tol) {
186  if (thickTot > thick) {
187  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
188  << cms::convert2mm(thickTot) << ": thickness of all its components **** ERROR ****";
189  } else {
190  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
191  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
192  }
193  }
194  }
195 
196  return cms::s_executed;
197 }
Log< level::Info, true > LogVerbatim
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
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)
Definition: HGCalProperty.cc:9
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  ,
ddcms_det_element_DDCMS_hgcal_DDHGCalWaferP   
)

Definition at line 200 of file DDHGCalWaferP.cc.