CMS 3D CMS Logo

DDHGCalPassiveFull.cc
Go to the documentation of this file.
1 // File: DDHGCalPassiveFull.cc
3 // Description: Geometry factory class for the passive part of a full silicon
4 // module
5 // Created by Sunanda Banerjee
7 
8 #include <string>
9 #include <vector>
10 #include <sstream>
11 
12 #include "DD4hep/DetFactoryHelper.h"
17 
18 //#define EDM_ML_DEBUG
19 using namespace angle_units::operators;
20 
22  HGCalPassiveFull() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassiveFull"; }
24  cms::DDNamespace ns(ctxt, e, true);
26 #ifdef EDM_ML_DEBUG
27  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Creating an instance";
28 #endif
29  std::string parentName = args.parentName();
30  std::string material = args.value<std::string>("ModuleMaterial");
31  double thick = args.value<double>("ModuleThickness");
32  double waferSize = args.value<double>("WaferSize");
33  double waferSepar = args.value<double>("SensorSeparation");
34 #ifdef EDM_ML_DEBUG
35  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Module " << parentName << " made of " << material << " T "
36  << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
37  << " Half Separation " << cms::convert2mm(waferSepar);
38 #endif
39  std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames");
40  std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials");
41  std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness");
42  std::vector<int> copyNumber;
43  copyNumber.resize(materials.size(), 1);
44 #ifdef EDM_ML_DEBUG
45  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << layerNames.size() << " types of volumes";
46  for (unsigned int i = 0; i < layerNames.size(); ++i)
47  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
48  << cms::convert2mm(layerThick[i]) << " filled with " << materials[i];
49 #endif
50  std::vector<int> layerType = args.value<std::vector<int>>("LayerType");
51 #ifdef EDM_ML_DEBUG
52  std::ostringstream st1;
53  for (unsigned int i = 0; i < layerType.size(); ++i)
54  st1 << " [" << i << "] " << layerType[i];
55  edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str();
56 
57  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassiveFull...";
58 #endif
59 
60  static constexpr double tol = 0.00001;
61  static const double sqrt3 = std::sqrt(3.0);
62  double rM = 0.5 * (waferSize + waferSepar);
63  double RM2 = rM / sqrt3;
64 
65  // First the mother
66  std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
67  std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
68  std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
69  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
70  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
71  ns.addSolidNS(ns.prepend(parentName), solid);
72  dd4hep::Material matter = ns.material(material);
73  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
74  ns.addVolumeNS(glogM);
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << solid.name() << " extruded polygon made of "
77  << matter.name() << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
78  << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
79  << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
80  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
81  for (unsigned int kk = 0; kk < xM.size(); ++kk)
82  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":" << cms::convert2mm(yM[kk]);
83 #endif
84 
85  // Then the layers
86  std::vector<dd4hep::Volume> glogs(materials.size());
87  double zi(-0.5 * thick), thickTot(0.0);
88  for (unsigned int l = 0; l < layerType.size(); l++) {
89  unsigned int i = layerType[l];
90  if (copyNumber[i] == 1) {
91  zw[0] = -0.5 * layerThick[i];
92  zw[1] = 0.5 * layerThick[i];
93  std::string layerName = parentName + layerNames[i];
94  solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
95  ns.addSolidNS(ns.prepend(layerName), solid);
96  matter = ns.material(materials[i]);
97  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
98  ns.addVolumeNS(glogs[i]);
99 #ifdef EDM_ML_DEBUG
100  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Layer " << i << ":" << l << ":" << solid.name()
101  << " extruded polygon made of " << matter.name() << " z|x|y|s (0) "
102  << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
103  << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
104  << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
105  << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
106  for (unsigned int kk = 0; kk < xM.size(); ++kk)
107  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":"
108  << cms::convert2mm(yM[kk]);
109 #endif
110  }
111  dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
112  glogM.placeVolume(glogs[i], copyNumber[i], tran0);
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << glogs[i].name() << " number " << copyNumber[i]
115  << " positioned in " << glogM.name() << " at (0, 0, "
116  << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
117 #endif
118  ++copyNumber[i];
119  zi += layerThick[i];
120  thickTot += layerThick[i];
121  }
122  if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) {
123  if (thickTot > thick) {
124  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
125  << ": thickness of all its components **** ERROR ****";
126  } else {
127  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
128  << " of the components";
129  }
130  }
131  }
132 };
133 
134 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
135  HGCalPassiveFull passiveFullAlgo(ctxt, e);
136  return cms::s_executed;
137 }
138 
139 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassiveFull, algorithm)
Log< level::Info, true > LogVerbatim
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Log< level::Error, false > LogError
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
HGCalPassiveFull(cms::DDParsingContext &ctxt, xml_h e)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:23
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
dd4hep::Volume Volume
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