CMS 3D CMS Logo

Functions
DDHGCalTBModule.cc File Reference
#include "DataFormats/Math/interface/angle_units.h"
#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/HGCalGeomTools.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "Geometry/HGCalCommonData/interface/HGCalTypes.h"

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_DDHGCalTBModule)
 

Function Documentation

◆ algorithm()

static long algorithm ( dd4hep::Detector &  ,
cms::DDParsingContext ctxt,
xml_h  e 
)
static

Definition at line 17 of file DDHGCalTBModule.cc.

References cms::DDNamespace::addSolidNS(), writedatasetfile::args, cms::convert2mm(), filterCSVwithJSON::copy, PVValHelper::dx, PVValHelper::dy, MillePedeFileConverter_cfg::e, mps_fire::i, versionedElectronIDProducer_cfi::idName, cuy::ii, dqmdumpme::k, hgcalTBTopologyTester_cfi::layers, cms::DDNamespace::material(), g4SimHits_cfi::Material, callgraph::module, Skims_PA_cff::name, cms::DDNamespace::name(), names, EgHLTOffHistBins_cfi::nr, gpuPixelDoublets::ntot, HGCalTypes::packTypeUV(), PixelTestBeamValidation_cfi::Position, cms::DDNamespace::prepend(), HGCalGeomTools::radius(), findQualityFiles::rr, cms::s_executed, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, funct::tan(), cond::impl::to_string(), cms::DDNamespace::volume(), and geometryCSVtoXML::zz.

17  {
18  cms::DDNamespace ns(ctxt, e, true);
20  static constexpr double tol2 = 0.00001 * dd4hep::mm;
21 
22  const auto& wafers = args.value<std::vector<std::string> >("WaferName"); // Wafers
23  const auto& covers = args.value<std::vector<std::string> >("CoverName"); // Insensitive layers of hexagonal size
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << wafers.size() << " wafers";
26  unsigned int i(0);
27  for (auto wafer : wafers) {
28  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer;
29  ++i;
30  }
31  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << covers.size() << " covers";
32  i = 0;
33  for (auto cover : covers) {
34  edm::LogVerbatim("HGCalGeom") << "Cover[" << i << "] " << cover;
35  ++i;
36  }
37 #endif
38  const auto& materials = args.value<std::vector<std::string> >("MaterialNames"); // Materials
39  const auto& names = args.value<std::vector<std::string> >("VolumeNames"); // Names
40  const auto& thick = args.value<std::vector<double> >("Thickness"); // Thickness of the material
41  std::vector<int> copyNumber; // Initial copy numbers
42  copyNumber.resize(materials.size(), 1);
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << materials.size() << " types of volumes";
45  for (unsigned int i = 0; i < names.size(); ++i)
46  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness "
47  << cms::convert2mm(thick[i]) << " filled with " << materials[i]
48  << " first copy number " << copyNumber[i];
49 #endif
50  const auto& layers = args.value<std::vector<int> >("Layers"); // Number of layers in a section
51  const auto& layerThick = args.value<std::vector<double> >("LayerThick"); // Thickness of each section
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layers.size() << " blocks";
54  for (unsigned int i = 0; i < layers.size(); ++i)
55  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick[i]) << " with "
56  << layers[i] << " layers";
57 #endif
58  const auto& layerType = args.value<std::vector<int> >("LayerType"); // Type of the layer
59  const auto& layerSense = args.value<std::vector<int> >("LayerSense"); // Content of a layer (sensitive?)
60 #ifdef EDM_ML_DEBUG
61  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layerType.size() << " layers";
62  for (unsigned int i = 0; i < layerType.size(); ++i)
63  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
64  << layerSense[i];
65 #endif
66  const auto& zMinBlock = args.value<double>("zMinBlock"); // Starting z-value of the block
67  const auto& rMaxFine = args.value<double>("rMaxFine"); // Maximum r-value for fine wafer
68  const auto& waferW = args.value<double>("waferW"); // Width of the wafer
69  const auto& waferGap = args.value<double>("waferGap"); // Gap between 2 wafers
70  const auto& absorbW = args.value<double>("absorberW"); // Width of the absorber
71  const auto& absorbH = args.value<double>("absorberH"); // Height of the absorber
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: zStart " << cms::convert2mm(zMinBlock) << " rFineCoarse "
74  << cms::convert2mm(rMaxFine) << " wafer width " << cms::convert2mm(waferW)
75  << " gap among wafers " << cms::convert2mm(waferGap) << " absorber width "
76  << cms::convert2mm(absorbW) << " absorber height " << cms::convert2mm(absorbH);
77 #endif
78  const auto& slopeB = args.value<std::vector<double> >("SlopeBottom"); // Slope at the lower R
79  const auto& slopeT = args.value<std::vector<double> >("SlopeTop"); // Slopes at the larger R
80  const auto& zFront = args.value<std::vector<double> >("ZFront"); // Starting Z values for the slopes
81  const auto& rMaxFront = args.value<std::vector<double> >("RMaxFront"); // Corresponding rMax's
82 #ifdef EDM_ML_DEBUG
83  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Bottom slopes " << slopeB[0] << ":" << slopeB[1] << " and "
84  << slopeT.size() << " slopes for top";
85  for (unsigned int i = 0; i < slopeT.size(); ++i)
86  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << cms::convert2mm(zFront[i]) << " Rmax "
87  << cms::convert2mm(rMaxFront[i]) << " Slope " << slopeT[i];
88 #endif
89  std::string idNameSpace = static_cast<std::string>(ns.name()); // Namespace of this and ALL sub-parts
90  const auto& idName = args.parentName(); // Name of the "parent" volume.
91 #ifdef EDM_ML_DEBUG
92  std::unordered_set<int> copies; // List of copy #'s
93  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: NameSpace " << idNameSpace << " Mother " << idName;
94 #endif
95 
96  // Mother module
97  dd4hep::Volume module = ns.volume(idName);
98 #ifdef EDM_ML_DEBUG
99  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalTBModule...";
100 #endif
101 
102  double zi(zMinBlock);
103  double ww = (waferW + waferGap);
104  double dx = 0.5 * ww;
105  double dy = 3.0 * dx * tan(30._deg);
106  double rr = 2.0 * dx * tan(30._deg);
107  int laymin(0);
108  for (unsigned int i = 0; i < layers.size(); i++) {
109  double zo = zi + layerThick[i];
110  double routF = HGCalGeomTools::radius(zi, zFront, rMaxFront, slopeT);
111  int laymax = laymin + layers[i];
112  double zz = zi;
113  double thickTot(0);
114  for (int ly = laymin; ly < laymax; ++ly) {
115  int ii = layerType[ly];
116  int copy = copyNumber[ii];
117  double rinB = (layerSense[ly] == 0) ? (zo * slopeB[0]) : (zo * slopeB[1]);
118  zz += (0.5 * thick[ii]);
119  thickTot += thick[ii];
120 
121  std::string name = "HGCal" + names[ii] + std::to_string(copy);
122 #ifdef EDM_ML_DEBUG
123  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Layer " << ly << ":" << ii << " Front " << cms::convert2mm(zi)
124  << ", " << cms::convert2mm(routF) << " Back " << cms::convert2mm(zo) << ", "
125  << cms::convert2mm(rinB) << " superlayer thickness "
126  << cms::convert2mm(layerThick[i]);
127 #endif
128 
129  dd4hep::Material matter = ns.material(materials[ii]);
130  dd4hep::Volume glog;
131  if (layerSense[ly] == 0) {
132  dd4hep::Solid solid = dd4hep::Box(absorbW, absorbH, 0.5 * thick[ii]);
133  ns.addSolidNS(ns.prepend(name), solid);
134  glog = dd4hep::Volume(solid.name(), solid, matter);
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << solid.name() << " box of dimension "
137  << cms::convert2mm(absorbW) << ":" << cms::convert2mm(absorbH) << ":"
138  << cms::convert2mm(0.5 * thick[ii]);
139 #endif
140  } else {
141  dd4hep::Solid solid = dd4hep::Tube(rinB, routF, 0.5 * thick[ii], 0.0, 2._pi);
142  ns.addSolidNS(ns.prepend(name), solid);
143  glog = dd4hep::Volume(solid.name(), solid, matter);
144 #ifdef EDM_ML_DEBUG
145  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << solid.name() << " Tubs made of " << materials[ii]
146  << " of dimensions " << cms::convert2mm(rinB) << ", " << cms::convert2mm(routF)
147  << ", " << cms::convert2mm(0.5 * thick[ii]) << ", 0.0, 360.0";
148 #endif
149  int ncol = static_cast<int>(2.0 * routF / ww) + 1;
150  int nrow = static_cast<int>(routF / (ww * tan(30._deg))) + 1;
151 #ifdef EDM_ML_DEBUG
152  int incm(0), inrm(0), kount(0), ntot(0), nin(0), nfine(0), ncoarse(0);
153  edm::LogVerbatim("HGCalGeom") << glog.name() << " rout " << cms::convert2mm(routF) << " Row " << nrow
154  << " Column " << ncol;
155 #endif
156  double xc[6], yc[6];
157  for (int nr = -nrow; nr <= nrow; ++nr) {
158  int inr = (nr >= 0) ? nr : -nr;
159  for (int nc = -ncol; nc <= ncol; ++nc) {
160  int inc = (nc >= 0) ? nc : -nc;
161  if (inr % 2 == inc % 2) {
162  double xpos = nc * dx;
163  double ypos = nr * dy;
164  xc[0] = xpos + dx;
165  yc[0] = ypos - 0.5 * rr;
166  xc[1] = xpos + dx;
167  yc[1] = ypos + 0.5 * rr;
168  xc[2] = xpos;
169  yc[2] = ypos + rr;
170  xc[3] = xpos - dx;
171  yc[3] = ypos + 0.5 * rr;
172  xc[4] = xpos + dx;
173  yc[4] = ypos - 0.5 * rr;
174  xc[5] = xpos;
175  yc[5] = ypos - rr;
176  bool cornerAll(true);
177  for (int k = 0; k < 6; ++k) {
178  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
179  if (rpos < rinB || rpos > routF)
180  cornerAll = false;
181  }
182 #ifdef EDM_ML_DEBUG
183  ++ntot;
184 #endif
185  if (cornerAll) {
186  dd4hep::Volume glog1;
187  if (layerSense[ly] == 1) {
188  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
189  glog1 = (rpos < rMaxFine) ? ns.volume(wafers[0]) : ns.volume(wafers[1]);
190 #ifdef EDM_ML_DEBUG
191  ++nin;
192  if (rpos < rMaxFine)
193  ++nfine;
194  else
195  ++ncoarse;
196 #endif
197  } else {
198  glog1 = ns.volume(covers[layerSense[ly] - 2]);
199  }
200  int copyL = HGCalTypes::packTypeUV(0, nc, nr);
201 #ifdef EDM_ML_DEBUG
202  if (inc > incm)
203  incm = inc;
204  if (inr > inrm)
205  inrm = inr;
206  kount++;
207  copies.insert(copy);
208 #endif
209  dd4hep::Position tran(xpos, ypos, 0.0);
210  glog.placeVolume(glog1, copyL, tran);
211 #ifdef EDM_ML_DEBUG
212  edm::LogVerbatim("HGCalGeom")
213  << "DDHGCalModule: " << glog1.name() << " number " << copyL << " positioned in " << glog.name()
214  << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0)";
215 #endif
216  }
217  }
218  }
219  }
220 #ifdef EDM_ML_DEBUG
221  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: # of columns " << incm << " # of rows " << inrm << " and "
222  << nin << ":" << kount << ":" << ntot << " wafers (" << nfine << ":" << ncoarse
223  << ") for " << glog.name() << " R " << cms::convert2mm(rinB) << ":"
224  << cms::convert2mm(routF);
225 #endif
226  }
227  dd4hep::Position r1(0, 0, zz);
228  module.placeVolume(glog, copy, r1);
229  ++copyNumber[ii];
230 #ifdef EDM_ML_DEBUG
231  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << glog.name() << " number " << copy
232  << " positioned in " << module.name() << " at (0,0," << cms::convert2mm(zz) << ")";
233 #endif
234  zz += (0.5 * thick[ii]);
235  } // End of loop over layers in a block
236  zi = zo;
237  laymin = laymax;
238  if (fabs(thickTot - layerThick[i]) > tol2) {
239  if (thickTot > layerThick[i]) {
240  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
241  << " is smaller than thickness " << cms::convert2mm(thickTot)
242  << " of all its components **** ERROR ****\n";
243  } else {
244  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
245  << " does not match with " << cms::convert2mm(thickTot) << " of the components\n";
246  }
247  }
248  } // End of loop over blocks
249 
250  return cms::s_executed;
251 }
Log< level::Info, true > LogVerbatim
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Log< level::Error, false > LogError
const std::string names[nVars_]
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:19
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
dd4hep::Volume Volume
ii
Definition: cuy.py:589
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
Log< level::Warning, false > LogWarning
__shared__ uint32_t ntot

◆ DD4HEP_OPEN_PLUGIN()

DD4HEP_OPEN_PLUGIN ( dd4hep  ,
ddcms_det_element_DDCMS_hgcal_DDHGCalTBModule   
)

Definition at line 254 of file DDHGCalTBModule.cc.