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  << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar;
38 #endif
39  std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags");
40  std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes");
41  std::vector<int> placementIndex = args.value<std::vector<int>>("PlacementIndex");
42  std::vector<std::string> placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags");
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types";
45  for (unsigned int k = 0; k < tags.size(); ++k) {
46  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
47  edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
48  << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m];
49  }
50  }
51 #endif
52  std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames");
53  std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials");
54  std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness");
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << layerNames.size() << " types of volumes";
57  for (unsigned int i = 0; i < layerNames.size(); ++i)
58  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
59  << " filled with " << materials[i];
60 #endif
61  std::vector<int> layerType = args.value<std::vector<int>>("LayerType");
62 #ifdef EDM_ML_DEBUG
63  std::ostringstream st1;
64  for (unsigned int i = 0; i < layerType.size(); ++i)
65  st1 << " [" << i << "] " << layerType[i];
66  edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str();
67 
68  edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial...";
69 #endif
70 
71  static constexpr double tol = 0.00001;
72 
73  // Loop over all types
74  for (unsigned int k = 0; k < tags.size(); ++k) {
75  for (unsigned int m = 0; m < placementIndex.size(); ++m) {
76  // First the mother
77  std::string mother = parentName + placementIndexTags[m] + tags[k];
78  std::vector<std::pair<double, double>> wxy =
79  HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 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  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
88  ns.addSolidNS(ns.prepend(mother), solid);
89  dd4hep::Material matter = ns.material(material);
90  dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
91  ns.addVolumeNS(glogM);
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
94  << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0]
95  << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1]
96  << ":" << scale[1] << " and " << xM.size() << " edges";
97  for (unsigned int kk = 0; kk < xM.size(); ++kk)
98  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
99 #endif
100 
101  // Then the layers
102  std::vector<dd4hep::Volume> glogs(materials.size());
103  std::vector<int> copyNumber;
104  copyNumber.resize(materials.size(), 1);
105  double zi(-0.5 * thick), thickTot(0.0);
106  for (unsigned int l = 0; l < layerType.size(); l++) {
107  unsigned int i = layerType[l];
108  if (copyNumber[i] == 1) {
109  zw[0] = -0.5 * layerThick[i];
110  zw[1] = 0.5 * layerThick[i];
111  std::string layerName = mother + layerNames[i];
112  solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
113  ns.addSolidNS(ns.prepend(layerName), solid);
114  matter = ns.material(materials[i]);
115  glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
116  ns.addVolumeNS(glogs[i]);
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("HGCalGeom")
119  << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name()
120  << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":"
121  << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
122  << scale[1] << " and " << xM.size() << " edges";
123  for (unsigned int kk = 0; kk < xM.size(); ++kk)
124  edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
125 #endif
126  }
127  dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i]));
128  glogM.placeVolume(glogs[i], copyNumber[i], tran);
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i]
131  << " positioned in " << glogM.name() << " at " << tran << " with no rotation";
132 #endif
133  ++copyNumber[i];
134  zi += layerThick[i];
135  thickTot += layerThick[i];
136  }
137  if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) {
138  if (thickTot > thick) {
139  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
140  << ": thickness of all its components **** ERROR ****";
141  } else {
142  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with "
143  << thickTot << " of the components";
144  }
145  }
146  }
147  }
148  }
149 };
150 
151 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
152  HGCalPassivePartial passivePartialAlgo(ctxt, e);
153  return cms::s_executed;
154 }
155 
156 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassivePartial, algorithm)
Log< level::Info, true > LogVerbatim
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(int part, int orient, int zside, double waferSize, double offset, double xpos, double ypos)
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:71
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