CMS 3D CMS Logo

DDHGCalPassivePartial.cc
Go to the documentation of this file.
1 // File: DDHGCalPassivePartial.cc
3 // Description: Geometry factory class for the passive part of a partial
4 // silicon module
5 // Created by Sunanda Banerjee
7 
8 #include <string>
9 #include <vector>
10 #include <sstream>
11 
12 #include "DD4hep/DetFactoryHelper.h"
18 
19 //#define EDM_ML_DEBUG
20 using namespace angle_units::operators;
21 
23  HGCalPassivePartial() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassivePartial"; }
25  cms::DDNamespace ns(ctxt, e, true);
27 #ifdef EDM_ML_DEBUG
28  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Creating an instance";
29 #endif
30  std::string parentName = args.parentName();
31  std::string material = args.value<std::string>("ModuleMaterial");
32  double thick = args.value<double>("ModuleThickness");
33  double waferSize = args.value<double>("WaferSize");
34  double waferSepar = args.value<double>("SensorSeparation");
35 #ifdef EDM_ML_DEBUG
36  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parentName << " made of " << material << " T "
37  << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
38  << " Half Separation " << cms::convert2mm(waferSepar);
39 #endif
40  std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags");
41  std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes");
42  std::vector<int> placementIndex = args.value<std::vector<int>>("PlacementIndex");
43  std::vector<std::string> placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags");
44 #ifdef EDM_ML_DEBUG
45  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types";
46  for (unsigned int k = 0; k < tags.size(); ++k) {
47  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
48  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
49  << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m];
50  }
51  }
52 #endif
53  std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames");
54  std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials");
55  std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness");
56 #ifdef EDM_ML_DEBUG
57  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << 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]) << " filled with " << materials[i];
61 #endif
62  std::vector<int> layerType = args.value<std::vector<int>>("LayerType");
63 #ifdef EDM_ML_DEBUG
64  std::ostringstream st1;
65  for (unsigned int i = 0; i < layerType.size(); ++i)
66  st1 << " [" << i << "] " << layerType[i];
67  edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str();
68 
69  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial...";
70 #endif
71 
72  static constexpr double tol = 0.00001;
73 
74  // Loop over all types
75  for (unsigned int k = 0; k < tags.size(); ++k) {
76  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
77  // First the mother
78  std::string mother = parentName + placementIndexTags[m] + tags[k];
79  std::vector<std::pair<double, double>> wxy =
80  HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 0.0, 0.0, 0.0, false);
81  std::vector<double> xM, yM;
82  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
83  xM.emplace_back(wxy[i].first);
84  yM.emplace_back(wxy[i].second);
85  }
86  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
87  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
88  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
89  ns.addSolidNS(ns.prepend(mother), solid);
90  dd4hep::Material matter = ns.material(material);
91  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
92  ns.addVolumeNS(glogM);
93 #ifdef EDM_ML_DEBUG
94  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
95  << matter.name() << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
96  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
97  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
98  << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size()
99  << " edges";
100  for (unsigned int kk = 0; kk < xM.size(); ++kk)
101  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":"
102  << cms::convert2mm(yM[kk]);
103 #endif
104 
105  // Then the layers
106  std::vector<dd4hep::Volume> glogs(materials.size());
107  std::vector<int> copyNumber;
108  copyNumber.resize(materials.size(), 1);
109  double zi(-0.5 * thick), thickTot(0.0);
110  for (unsigned int l = 0; l < layerType.size(); l++) {
111  unsigned int i = layerType[l];
112  if (copyNumber[i] == 1) {
113  zw[0] = -0.5 * layerThick[i];
114  zw[1] = 0.5 * layerThick[i];
115  std::string layerName = mother + layerNames[i];
116  solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
117  ns.addSolidNS(ns.prepend(layerName), solid);
118  matter = ns.material(materials[i]);
119  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
120  ns.addVolumeNS(glogs[i]);
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("HGCalGeom")
123  << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name()
124  << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
125  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
126  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":" << cms::convert2mm(zy[1]) << ":"
127  << scale[1] << " and " << xM.size() << " edges";
128  for (unsigned int kk = 0; kk < xM.size(); ++kk)
129  edm::LogVerbatim("HGCalGeom")
130  << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":" << cms::convert2mm(yM[kk]);
131 #endif
132  }
133  dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i]));
134  glogM.placeVolume(glogs[i], copyNumber[i], tran);
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i]
137  << " positioned in " << glogM.name() << " at (0, 0, "
138  << cms::convert2mm(zi + 0.5 * layerThick[i]) << " with no rotation";
139 #endif
140  ++copyNumber[i];
141  zi += layerThick[i];
142  thickTot += layerThick[i];
143  }
144  if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) {
145  if (thickTot > thick) {
146  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
147  << ": thickness of all its components **** ERROR ****";
148  } else {
149  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with "
150  << thickTot << " of the components";
151  }
152  }
153  }
154  }
155  }
156 };
157 
158 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
159  HGCalPassivePartial passivePartialAlgo(ctxt, e);
160  return cms::s_executed;
161 }
162 
163 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassivePartial, algorithm)
Log< level::Info, true > LogVerbatim
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Log< level::Error, false > LogError
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
static std::vector< std::pair< double, double > > waferXY(const int &part, const int &orient, const int &zside, const double &waferSize, const double &offset, const double &xpos, const double &ypos, const bool &v17)
U second(std::pair< T, U > const &p)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dd4hep::Volume Volume
HGCalPassivePartial(cms::DDParsingContext &ctxt, xml_h e)
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:84
Log< level::Warning, false > LogWarning
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99